pdf.combined.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* jshint globalstrict: false */
  16. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/build/pdf.combined', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfCombined = {}));
  25. }
  26. }(this, function (exports) {
  27. // Use strict in our context only - users might not want it
  28. 'use strict';
  29. var pdfjsVersion = '1.3.214';
  30. var pdfjsBuild = 'd864bef';
  31. var pdfjsFilePath =
  32. typeof document !== 'undefined' && document.currentScript ?
  33. document.currentScript.src : null;
  34. var pdfjsLibs = {};
  35. (function pdfjsWrapper() {
  36. (function (root, factory) {
  37. {
  38. factory((root.pdfjsCoreArithmeticDecoder = {}));
  39. }
  40. }(this, function (exports) {
  41. /* This class implements the QM Coder decoding as defined in
  42. * JPEG 2000 Part I Final Committee Draft Version 1.0
  43. * Annex C.3 Arithmetic decoding procedure
  44. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  45. *
  46. * The arithmetic decoder is used in conjunction with context models to decode
  47. * JPEG2000 and JBIG2 streams.
  48. */
  49. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  50. // Table C-2
  51. var QeTable = [
  52. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  53. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  54. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  55. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  56. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  57. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  58. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  59. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  60. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  61. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  62. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  63. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  64. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  65. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  66. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  67. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  68. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  69. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  70. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  71. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  72. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  73. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  74. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  75. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  76. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  77. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  78. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  79. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  80. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  81. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  82. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  83. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  84. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  85. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  86. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  87. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  88. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  89. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  90. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  91. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  92. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  93. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  94. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  95. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  96. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  97. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  98. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  99. ];
  100. // C.3.5 Initialisation of the decoder (INITDEC)
  101. function ArithmeticDecoder(data, start, end) {
  102. this.data = data;
  103. this.bp = start;
  104. this.dataEnd = end;
  105. this.chigh = data[start];
  106. this.clow = 0;
  107. this.byteIn();
  108. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  109. this.clow = (this.clow << 7) & 0xFFFF;
  110. this.ct -= 7;
  111. this.a = 0x8000;
  112. }
  113. ArithmeticDecoder.prototype = {
  114. // C.3.4 Compressed data input (BYTEIN)
  115. byteIn: function ArithmeticDecoder_byteIn() {
  116. var data = this.data;
  117. var bp = this.bp;
  118. if (data[bp] === 0xFF) {
  119. var b1 = data[bp + 1];
  120. if (b1 > 0x8F) {
  121. this.clow += 0xFF00;
  122. this.ct = 8;
  123. } else {
  124. bp++;
  125. this.clow += (data[bp] << 9);
  126. this.ct = 7;
  127. this.bp = bp;
  128. }
  129. } else {
  130. bp++;
  131. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  132. this.ct = 8;
  133. this.bp = bp;
  134. }
  135. if (this.clow > 0xFFFF) {
  136. this.chigh += (this.clow >> 16);
  137. this.clow &= 0xFFFF;
  138. }
  139. },
  140. // C.3.2 Decoding a decision (DECODE)
  141. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  142. // contexts are packed into 1 byte:
  143. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  144. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  145. var qeTableIcx = QeTable[cx_index];
  146. var qeIcx = qeTableIcx.qe;
  147. var d;
  148. var a = this.a - qeIcx;
  149. if (this.chigh < qeIcx) {
  150. // exchangeLps
  151. if (a < qeIcx) {
  152. a = qeIcx;
  153. d = cx_mps;
  154. cx_index = qeTableIcx.nmps;
  155. } else {
  156. a = qeIcx;
  157. d = 1 ^ cx_mps;
  158. if (qeTableIcx.switchFlag === 1) {
  159. cx_mps = d;
  160. }
  161. cx_index = qeTableIcx.nlps;
  162. }
  163. } else {
  164. this.chigh -= qeIcx;
  165. if ((a & 0x8000) !== 0) {
  166. this.a = a;
  167. return cx_mps;
  168. }
  169. // exchangeMps
  170. if (a < qeIcx) {
  171. d = 1 ^ cx_mps;
  172. if (qeTableIcx.switchFlag === 1) {
  173. cx_mps = d;
  174. }
  175. cx_index = qeTableIcx.nlps;
  176. } else {
  177. d = cx_mps;
  178. cx_index = qeTableIcx.nmps;
  179. }
  180. }
  181. // C.3.3 renormD;
  182. do {
  183. if (this.ct === 0) {
  184. this.byteIn();
  185. }
  186. a <<= 1;
  187. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  188. this.clow = (this.clow << 1) & 0xFFFF;
  189. this.ct--;
  190. } while ((a & 0x8000) === 0);
  191. this.a = a;
  192. contexts[pos] = cx_index << 1 | cx_mps;
  193. return d;
  194. }
  195. };
  196. return ArithmeticDecoder;
  197. })();
  198. exports.ArithmeticDecoder = ArithmeticDecoder;
  199. }));
  200. (function (root, factory) {
  201. {
  202. factory((root.pdfjsCoreCharsets = {}));
  203. }
  204. }(this, function (exports) {
  205. var ISOAdobeCharset = [
  206. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  207. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  208. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  209. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  210. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  211. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  212. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  213. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  214. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  215. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  216. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  217. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  218. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  219. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  220. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  221. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  222. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  223. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  224. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  225. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  226. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  227. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  228. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  229. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  230. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  231. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  232. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  233. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  234. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  235. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  236. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  237. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  238. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  239. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  240. ];
  241. var ExpertCharset = [
  242. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  243. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  244. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  245. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  246. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  247. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  248. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  249. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  250. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  251. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  252. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  253. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  254. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  255. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  256. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  257. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  258. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  259. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  260. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  261. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  262. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  263. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  264. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  265. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  266. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  267. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  268. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  269. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  270. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  271. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  272. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  273. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  274. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  275. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  276. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  277. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  278. 'Ydieresissmall'
  279. ];
  280. var ExpertSubsetCharset = [
  281. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  282. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  283. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  284. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  285. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  286. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  287. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  288. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  289. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  290. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  291. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  292. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  293. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  294. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  295. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  296. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  297. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  298. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  299. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  300. 'periodinferior', 'commainferior'
  301. ];
  302. exports.ISOAdobeCharset = ISOAdobeCharset;
  303. exports.ExpertCharset = ExpertCharset;
  304. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  305. }));
  306. (function (root, factory) {
  307. {
  308. factory((root.pdfjsCoreGlyphList = {}));
  309. }
  310. }(this, function (exports) {
  311. var GlyphsUnicode = {
  312. A: 0x0041,
  313. AE: 0x00C6,
  314. AEacute: 0x01FC,
  315. AEmacron: 0x01E2,
  316. AEsmall: 0xF7E6,
  317. Aacute: 0x00C1,
  318. Aacutesmall: 0xF7E1,
  319. Abreve: 0x0102,
  320. Abreveacute: 0x1EAE,
  321. Abrevecyrillic: 0x04D0,
  322. Abrevedotbelow: 0x1EB6,
  323. Abrevegrave: 0x1EB0,
  324. Abrevehookabove: 0x1EB2,
  325. Abrevetilde: 0x1EB4,
  326. Acaron: 0x01CD,
  327. Acircle: 0x24B6,
  328. Acircumflex: 0x00C2,
  329. Acircumflexacute: 0x1EA4,
  330. Acircumflexdotbelow: 0x1EAC,
  331. Acircumflexgrave: 0x1EA6,
  332. Acircumflexhookabove: 0x1EA8,
  333. Acircumflexsmall: 0xF7E2,
  334. Acircumflextilde: 0x1EAA,
  335. Acute: 0xF6C9,
  336. Acutesmall: 0xF7B4,
  337. Acyrillic: 0x0410,
  338. Adblgrave: 0x0200,
  339. Adieresis: 0x00C4,
  340. Adieresiscyrillic: 0x04D2,
  341. Adieresismacron: 0x01DE,
  342. Adieresissmall: 0xF7E4,
  343. Adotbelow: 0x1EA0,
  344. Adotmacron: 0x01E0,
  345. Agrave: 0x00C0,
  346. Agravesmall: 0xF7E0,
  347. Ahookabove: 0x1EA2,
  348. Aiecyrillic: 0x04D4,
  349. Ainvertedbreve: 0x0202,
  350. Alpha: 0x0391,
  351. Alphatonos: 0x0386,
  352. Amacron: 0x0100,
  353. Amonospace: 0xFF21,
  354. Aogonek: 0x0104,
  355. Aring: 0x00C5,
  356. Aringacute: 0x01FA,
  357. Aringbelow: 0x1E00,
  358. Aringsmall: 0xF7E5,
  359. Asmall: 0xF761,
  360. Atilde: 0x00C3,
  361. Atildesmall: 0xF7E3,
  362. Aybarmenian: 0x0531,
  363. B: 0x0042,
  364. Bcircle: 0x24B7,
  365. Bdotaccent: 0x1E02,
  366. Bdotbelow: 0x1E04,
  367. Becyrillic: 0x0411,
  368. Benarmenian: 0x0532,
  369. Beta: 0x0392,
  370. Bhook: 0x0181,
  371. Blinebelow: 0x1E06,
  372. Bmonospace: 0xFF22,
  373. Brevesmall: 0xF6F4,
  374. Bsmall: 0xF762,
  375. Btopbar: 0x0182,
  376. C: 0x0043,
  377. Caarmenian: 0x053E,
  378. Cacute: 0x0106,
  379. Caron: 0xF6CA,
  380. Caronsmall: 0xF6F5,
  381. Ccaron: 0x010C,
  382. Ccedilla: 0x00C7,
  383. Ccedillaacute: 0x1E08,
  384. Ccedillasmall: 0xF7E7,
  385. Ccircle: 0x24B8,
  386. Ccircumflex: 0x0108,
  387. Cdot: 0x010A,
  388. Cdotaccent: 0x010A,
  389. Cedillasmall: 0xF7B8,
  390. Chaarmenian: 0x0549,
  391. Cheabkhasiancyrillic: 0x04BC,
  392. Checyrillic: 0x0427,
  393. Chedescenderabkhasiancyrillic: 0x04BE,
  394. Chedescendercyrillic: 0x04B6,
  395. Chedieresiscyrillic: 0x04F4,
  396. Cheharmenian: 0x0543,
  397. Chekhakassiancyrillic: 0x04CB,
  398. Cheverticalstrokecyrillic: 0x04B8,
  399. Chi: 0x03A7,
  400. Chook: 0x0187,
  401. Circumflexsmall: 0xF6F6,
  402. Cmonospace: 0xFF23,
  403. Coarmenian: 0x0551,
  404. Csmall: 0xF763,
  405. D: 0x0044,
  406. DZ: 0x01F1,
  407. DZcaron: 0x01C4,
  408. Daarmenian: 0x0534,
  409. Dafrican: 0x0189,
  410. Dcaron: 0x010E,
  411. Dcedilla: 0x1E10,
  412. Dcircle: 0x24B9,
  413. Dcircumflexbelow: 0x1E12,
  414. Dcroat: 0x0110,
  415. Ddotaccent: 0x1E0A,
  416. Ddotbelow: 0x1E0C,
  417. Decyrillic: 0x0414,
  418. Deicoptic: 0x03EE,
  419. Delta: 0x2206,
  420. Deltagreek: 0x0394,
  421. Dhook: 0x018A,
  422. Dieresis: 0xF6CB,
  423. DieresisAcute: 0xF6CC,
  424. DieresisGrave: 0xF6CD,
  425. Dieresissmall: 0xF7A8,
  426. Digammagreek: 0x03DC,
  427. Djecyrillic: 0x0402,
  428. Dlinebelow: 0x1E0E,
  429. Dmonospace: 0xFF24,
  430. Dotaccentsmall: 0xF6F7,
  431. Dslash: 0x0110,
  432. Dsmall: 0xF764,
  433. Dtopbar: 0x018B,
  434. Dz: 0x01F2,
  435. Dzcaron: 0x01C5,
  436. Dzeabkhasiancyrillic: 0x04E0,
  437. Dzecyrillic: 0x0405,
  438. Dzhecyrillic: 0x040F,
  439. E: 0x0045,
  440. Eacute: 0x00C9,
  441. Eacutesmall: 0xF7E9,
  442. Ebreve: 0x0114,
  443. Ecaron: 0x011A,
  444. Ecedillabreve: 0x1E1C,
  445. Echarmenian: 0x0535,
  446. Ecircle: 0x24BA,
  447. Ecircumflex: 0x00CA,
  448. Ecircumflexacute: 0x1EBE,
  449. Ecircumflexbelow: 0x1E18,
  450. Ecircumflexdotbelow: 0x1EC6,
  451. Ecircumflexgrave: 0x1EC0,
  452. Ecircumflexhookabove: 0x1EC2,
  453. Ecircumflexsmall: 0xF7EA,
  454. Ecircumflextilde: 0x1EC4,
  455. Ecyrillic: 0x0404,
  456. Edblgrave: 0x0204,
  457. Edieresis: 0x00CB,
  458. Edieresissmall: 0xF7EB,
  459. Edot: 0x0116,
  460. Edotaccent: 0x0116,
  461. Edotbelow: 0x1EB8,
  462. Efcyrillic: 0x0424,
  463. Egrave: 0x00C8,
  464. Egravesmall: 0xF7E8,
  465. Eharmenian: 0x0537,
  466. Ehookabove: 0x1EBA,
  467. Eightroman: 0x2167,
  468. Einvertedbreve: 0x0206,
  469. Eiotifiedcyrillic: 0x0464,
  470. Elcyrillic: 0x041B,
  471. Elevenroman: 0x216A,
  472. Emacron: 0x0112,
  473. Emacronacute: 0x1E16,
  474. Emacrongrave: 0x1E14,
  475. Emcyrillic: 0x041C,
  476. Emonospace: 0xFF25,
  477. Encyrillic: 0x041D,
  478. Endescendercyrillic: 0x04A2,
  479. Eng: 0x014A,
  480. Enghecyrillic: 0x04A4,
  481. Enhookcyrillic: 0x04C7,
  482. Eogonek: 0x0118,
  483. Eopen: 0x0190,
  484. Epsilon: 0x0395,
  485. Epsilontonos: 0x0388,
  486. Ercyrillic: 0x0420,
  487. Ereversed: 0x018E,
  488. Ereversedcyrillic: 0x042D,
  489. Escyrillic: 0x0421,
  490. Esdescendercyrillic: 0x04AA,
  491. Esh: 0x01A9,
  492. Esmall: 0xF765,
  493. Eta: 0x0397,
  494. Etarmenian: 0x0538,
  495. Etatonos: 0x0389,
  496. Eth: 0x00D0,
  497. Ethsmall: 0xF7F0,
  498. Etilde: 0x1EBC,
  499. Etildebelow: 0x1E1A,
  500. Euro: 0x20AC,
  501. Ezh: 0x01B7,
  502. Ezhcaron: 0x01EE,
  503. Ezhreversed: 0x01B8,
  504. F: 0x0046,
  505. Fcircle: 0x24BB,
  506. Fdotaccent: 0x1E1E,
  507. Feharmenian: 0x0556,
  508. Feicoptic: 0x03E4,
  509. Fhook: 0x0191,
  510. Fitacyrillic: 0x0472,
  511. Fiveroman: 0x2164,
  512. Fmonospace: 0xFF26,
  513. Fourroman: 0x2163,
  514. Fsmall: 0xF766,
  515. G: 0x0047,
  516. GBsquare: 0x3387,
  517. Gacute: 0x01F4,
  518. Gamma: 0x0393,
  519. Gammaafrican: 0x0194,
  520. Gangiacoptic: 0x03EA,
  521. Gbreve: 0x011E,
  522. Gcaron: 0x01E6,
  523. Gcedilla: 0x0122,
  524. Gcircle: 0x24BC,
  525. Gcircumflex: 0x011C,
  526. Gcommaaccent: 0x0122,
  527. Gdot: 0x0120,
  528. Gdotaccent: 0x0120,
  529. Gecyrillic: 0x0413,
  530. Ghadarmenian: 0x0542,
  531. Ghemiddlehookcyrillic: 0x0494,
  532. Ghestrokecyrillic: 0x0492,
  533. Gheupturncyrillic: 0x0490,
  534. Ghook: 0x0193,
  535. Gimarmenian: 0x0533,
  536. Gjecyrillic: 0x0403,
  537. Gmacron: 0x1E20,
  538. Gmonospace: 0xFF27,
  539. Grave: 0xF6CE,
  540. Gravesmall: 0xF760,
  541. Gsmall: 0xF767,
  542. Gsmallhook: 0x029B,
  543. Gstroke: 0x01E4,
  544. H: 0x0048,
  545. H18533: 0x25CF,
  546. H18543: 0x25AA,
  547. H18551: 0x25AB,
  548. H22073: 0x25A1,
  549. HPsquare: 0x33CB,
  550. Haabkhasiancyrillic: 0x04A8,
  551. Hadescendercyrillic: 0x04B2,
  552. Hardsigncyrillic: 0x042A,
  553. Hbar: 0x0126,
  554. Hbrevebelow: 0x1E2A,
  555. Hcedilla: 0x1E28,
  556. Hcircle: 0x24BD,
  557. Hcircumflex: 0x0124,
  558. Hdieresis: 0x1E26,
  559. Hdotaccent: 0x1E22,
  560. Hdotbelow: 0x1E24,
  561. Hmonospace: 0xFF28,
  562. Hoarmenian: 0x0540,
  563. Horicoptic: 0x03E8,
  564. Hsmall: 0xF768,
  565. Hungarumlaut: 0xF6CF,
  566. Hungarumlautsmall: 0xF6F8,
  567. Hzsquare: 0x3390,
  568. I: 0x0049,
  569. IAcyrillic: 0x042F,
  570. IJ: 0x0132,
  571. IUcyrillic: 0x042E,
  572. Iacute: 0x00CD,
  573. Iacutesmall: 0xF7ED,
  574. Ibreve: 0x012C,
  575. Icaron: 0x01CF,
  576. Icircle: 0x24BE,
  577. Icircumflex: 0x00CE,
  578. Icircumflexsmall: 0xF7EE,
  579. Icyrillic: 0x0406,
  580. Idblgrave: 0x0208,
  581. Idieresis: 0x00CF,
  582. Idieresisacute: 0x1E2E,
  583. Idieresiscyrillic: 0x04E4,
  584. Idieresissmall: 0xF7EF,
  585. Idot: 0x0130,
  586. Idotaccent: 0x0130,
  587. Idotbelow: 0x1ECA,
  588. Iebrevecyrillic: 0x04D6,
  589. Iecyrillic: 0x0415,
  590. Ifraktur: 0x2111,
  591. Igrave: 0x00CC,
  592. Igravesmall: 0xF7EC,
  593. Ihookabove: 0x1EC8,
  594. Iicyrillic: 0x0418,
  595. Iinvertedbreve: 0x020A,
  596. Iishortcyrillic: 0x0419,
  597. Imacron: 0x012A,
  598. Imacroncyrillic: 0x04E2,
  599. Imonospace: 0xFF29,
  600. Iniarmenian: 0x053B,
  601. Iocyrillic: 0x0401,
  602. Iogonek: 0x012E,
  603. Iota: 0x0399,
  604. Iotaafrican: 0x0196,
  605. Iotadieresis: 0x03AA,
  606. Iotatonos: 0x038A,
  607. Ismall: 0xF769,
  608. Istroke: 0x0197,
  609. Itilde: 0x0128,
  610. Itildebelow: 0x1E2C,
  611. Izhitsacyrillic: 0x0474,
  612. Izhitsadblgravecyrillic: 0x0476,
  613. J: 0x004A,
  614. Jaarmenian: 0x0541,
  615. Jcircle: 0x24BF,
  616. Jcircumflex: 0x0134,
  617. Jecyrillic: 0x0408,
  618. Jheharmenian: 0x054B,
  619. Jmonospace: 0xFF2A,
  620. Jsmall: 0xF76A,
  621. K: 0x004B,
  622. KBsquare: 0x3385,
  623. KKsquare: 0x33CD,
  624. Kabashkircyrillic: 0x04A0,
  625. Kacute: 0x1E30,
  626. Kacyrillic: 0x041A,
  627. Kadescendercyrillic: 0x049A,
  628. Kahookcyrillic: 0x04C3,
  629. Kappa: 0x039A,
  630. Kastrokecyrillic: 0x049E,
  631. Kaverticalstrokecyrillic: 0x049C,
  632. Kcaron: 0x01E8,
  633. Kcedilla: 0x0136,
  634. Kcircle: 0x24C0,
  635. Kcommaaccent: 0x0136,
  636. Kdotbelow: 0x1E32,
  637. Keharmenian: 0x0554,
  638. Kenarmenian: 0x053F,
  639. Khacyrillic: 0x0425,
  640. Kheicoptic: 0x03E6,
  641. Khook: 0x0198,
  642. Kjecyrillic: 0x040C,
  643. Klinebelow: 0x1E34,
  644. Kmonospace: 0xFF2B,
  645. Koppacyrillic: 0x0480,
  646. Koppagreek: 0x03DE,
  647. Ksicyrillic: 0x046E,
  648. Ksmall: 0xF76B,
  649. L: 0x004C,
  650. LJ: 0x01C7,
  651. LL: 0xF6BF,
  652. Lacute: 0x0139,
  653. Lambda: 0x039B,
  654. Lcaron: 0x013D,
  655. Lcedilla: 0x013B,
  656. Lcircle: 0x24C1,
  657. Lcircumflexbelow: 0x1E3C,
  658. Lcommaaccent: 0x013B,
  659. Ldot: 0x013F,
  660. Ldotaccent: 0x013F,
  661. Ldotbelow: 0x1E36,
  662. Ldotbelowmacron: 0x1E38,
  663. Liwnarmenian: 0x053C,
  664. Lj: 0x01C8,
  665. Ljecyrillic: 0x0409,
  666. Llinebelow: 0x1E3A,
  667. Lmonospace: 0xFF2C,
  668. Lslash: 0x0141,
  669. Lslashsmall: 0xF6F9,
  670. Lsmall: 0xF76C,
  671. M: 0x004D,
  672. MBsquare: 0x3386,
  673. Macron: 0xF6D0,
  674. Macronsmall: 0xF7AF,
  675. Macute: 0x1E3E,
  676. Mcircle: 0x24C2,
  677. Mdotaccent: 0x1E40,
  678. Mdotbelow: 0x1E42,
  679. Menarmenian: 0x0544,
  680. Mmonospace: 0xFF2D,
  681. Msmall: 0xF76D,
  682. Mturned: 0x019C,
  683. Mu: 0x039C,
  684. N: 0x004E,
  685. NJ: 0x01CA,
  686. Nacute: 0x0143,
  687. Ncaron: 0x0147,
  688. Ncedilla: 0x0145,
  689. Ncircle: 0x24C3,
  690. Ncircumflexbelow: 0x1E4A,
  691. Ncommaaccent: 0x0145,
  692. Ndotaccent: 0x1E44,
  693. Ndotbelow: 0x1E46,
  694. Nhookleft: 0x019D,
  695. Nineroman: 0x2168,
  696. Nj: 0x01CB,
  697. Njecyrillic: 0x040A,
  698. Nlinebelow: 0x1E48,
  699. Nmonospace: 0xFF2E,
  700. Nowarmenian: 0x0546,
  701. Nsmall: 0xF76E,
  702. Ntilde: 0x00D1,
  703. Ntildesmall: 0xF7F1,
  704. Nu: 0x039D,
  705. O: 0x004F,
  706. OE: 0x0152,
  707. OEsmall: 0xF6FA,
  708. Oacute: 0x00D3,
  709. Oacutesmall: 0xF7F3,
  710. Obarredcyrillic: 0x04E8,
  711. Obarreddieresiscyrillic: 0x04EA,
  712. Obreve: 0x014E,
  713. Ocaron: 0x01D1,
  714. Ocenteredtilde: 0x019F,
  715. Ocircle: 0x24C4,
  716. Ocircumflex: 0x00D4,
  717. Ocircumflexacute: 0x1ED0,
  718. Ocircumflexdotbelow: 0x1ED8,
  719. Ocircumflexgrave: 0x1ED2,
  720. Ocircumflexhookabove: 0x1ED4,
  721. Ocircumflexsmall: 0xF7F4,
  722. Ocircumflextilde: 0x1ED6,
  723. Ocyrillic: 0x041E,
  724. Odblacute: 0x0150,
  725. Odblgrave: 0x020C,
  726. Odieresis: 0x00D6,
  727. Odieresiscyrillic: 0x04E6,
  728. Odieresissmall: 0xF7F6,
  729. Odotbelow: 0x1ECC,
  730. Ogoneksmall: 0xF6FB,
  731. Ograve: 0x00D2,
  732. Ogravesmall: 0xF7F2,
  733. Oharmenian: 0x0555,
  734. Ohm: 0x2126,
  735. Ohookabove: 0x1ECE,
  736. Ohorn: 0x01A0,
  737. Ohornacute: 0x1EDA,
  738. Ohorndotbelow: 0x1EE2,
  739. Ohorngrave: 0x1EDC,
  740. Ohornhookabove: 0x1EDE,
  741. Ohorntilde: 0x1EE0,
  742. Ohungarumlaut: 0x0150,
  743. Oi: 0x01A2,
  744. Oinvertedbreve: 0x020E,
  745. Omacron: 0x014C,
  746. Omacronacute: 0x1E52,
  747. Omacrongrave: 0x1E50,
  748. Omega: 0x2126,
  749. Omegacyrillic: 0x0460,
  750. Omegagreek: 0x03A9,
  751. Omegaroundcyrillic: 0x047A,
  752. Omegatitlocyrillic: 0x047C,
  753. Omegatonos: 0x038F,
  754. Omicron: 0x039F,
  755. Omicrontonos: 0x038C,
  756. Omonospace: 0xFF2F,
  757. Oneroman: 0x2160,
  758. Oogonek: 0x01EA,
  759. Oogonekmacron: 0x01EC,
  760. Oopen: 0x0186,
  761. Oslash: 0x00D8,
  762. Oslashacute: 0x01FE,
  763. Oslashsmall: 0xF7F8,
  764. Osmall: 0xF76F,
  765. Ostrokeacute: 0x01FE,
  766. Otcyrillic: 0x047E,
  767. Otilde: 0x00D5,
  768. Otildeacute: 0x1E4C,
  769. Otildedieresis: 0x1E4E,
  770. Otildesmall: 0xF7F5,
  771. P: 0x0050,
  772. Pacute: 0x1E54,
  773. Pcircle: 0x24C5,
  774. Pdotaccent: 0x1E56,
  775. Pecyrillic: 0x041F,
  776. Peharmenian: 0x054A,
  777. Pemiddlehookcyrillic: 0x04A6,
  778. Phi: 0x03A6,
  779. Phook: 0x01A4,
  780. Pi: 0x03A0,
  781. Piwrarmenian: 0x0553,
  782. Pmonospace: 0xFF30,
  783. Psi: 0x03A8,
  784. Psicyrillic: 0x0470,
  785. Psmall: 0xF770,
  786. Q: 0x0051,
  787. Qcircle: 0x24C6,
  788. Qmonospace: 0xFF31,
  789. Qsmall: 0xF771,
  790. R: 0x0052,
  791. Raarmenian: 0x054C,
  792. Racute: 0x0154,
  793. Rcaron: 0x0158,
  794. Rcedilla: 0x0156,
  795. Rcircle: 0x24C7,
  796. Rcommaaccent: 0x0156,
  797. Rdblgrave: 0x0210,
  798. Rdotaccent: 0x1E58,
  799. Rdotbelow: 0x1E5A,
  800. Rdotbelowmacron: 0x1E5C,
  801. Reharmenian: 0x0550,
  802. Rfraktur: 0x211C,
  803. Rho: 0x03A1,
  804. Ringsmall: 0xF6FC,
  805. Rinvertedbreve: 0x0212,
  806. Rlinebelow: 0x1E5E,
  807. Rmonospace: 0xFF32,
  808. Rsmall: 0xF772,
  809. Rsmallinverted: 0x0281,
  810. Rsmallinvertedsuperior: 0x02B6,
  811. S: 0x0053,
  812. SF010000: 0x250C,
  813. SF020000: 0x2514,
  814. SF030000: 0x2510,
  815. SF040000: 0x2518,
  816. SF050000: 0x253C,
  817. SF060000: 0x252C,
  818. SF070000: 0x2534,
  819. SF080000: 0x251C,
  820. SF090000: 0x2524,
  821. SF100000: 0x2500,
  822. SF110000: 0x2502,
  823. SF190000: 0x2561,
  824. SF200000: 0x2562,
  825. SF210000: 0x2556,
  826. SF220000: 0x2555,
  827. SF230000: 0x2563,
  828. SF240000: 0x2551,
  829. SF250000: 0x2557,
  830. SF260000: 0x255D,
  831. SF270000: 0x255C,
  832. SF280000: 0x255B,
  833. SF360000: 0x255E,
  834. SF370000: 0x255F,
  835. SF380000: 0x255A,
  836. SF390000: 0x2554,
  837. SF400000: 0x2569,
  838. SF410000: 0x2566,
  839. SF420000: 0x2560,
  840. SF430000: 0x2550,
  841. SF440000: 0x256C,
  842. SF450000: 0x2567,
  843. SF460000: 0x2568,
  844. SF470000: 0x2564,
  845. SF480000: 0x2565,
  846. SF490000: 0x2559,
  847. SF500000: 0x2558,
  848. SF510000: 0x2552,
  849. SF520000: 0x2553,
  850. SF530000: 0x256B,
  851. SF540000: 0x256A,
  852. Sacute: 0x015A,
  853. Sacutedotaccent: 0x1E64,
  854. Sampigreek: 0x03E0,
  855. Scaron: 0x0160,
  856. Scarondotaccent: 0x1E66,
  857. Scaronsmall: 0xF6FD,
  858. Scedilla: 0x015E,
  859. Schwa: 0x018F,
  860. Schwacyrillic: 0x04D8,
  861. Schwadieresiscyrillic: 0x04DA,
  862. Scircle: 0x24C8,
  863. Scircumflex: 0x015C,
  864. Scommaaccent: 0x0218,
  865. Sdotaccent: 0x1E60,
  866. Sdotbelow: 0x1E62,
  867. Sdotbelowdotaccent: 0x1E68,
  868. Seharmenian: 0x054D,
  869. Sevenroman: 0x2166,
  870. Shaarmenian: 0x0547,
  871. Shacyrillic: 0x0428,
  872. Shchacyrillic: 0x0429,
  873. Sheicoptic: 0x03E2,
  874. Shhacyrillic: 0x04BA,
  875. Shimacoptic: 0x03EC,
  876. Sigma: 0x03A3,
  877. Sixroman: 0x2165,
  878. Smonospace: 0xFF33,
  879. Softsigncyrillic: 0x042C,
  880. Ssmall: 0xF773,
  881. Stigmagreek: 0x03DA,
  882. T: 0x0054,
  883. Tau: 0x03A4,
  884. Tbar: 0x0166,
  885. Tcaron: 0x0164,
  886. Tcedilla: 0x0162,
  887. Tcircle: 0x24C9,
  888. Tcircumflexbelow: 0x1E70,
  889. Tcommaaccent: 0x0162,
  890. Tdotaccent: 0x1E6A,
  891. Tdotbelow: 0x1E6C,
  892. Tecyrillic: 0x0422,
  893. Tedescendercyrillic: 0x04AC,
  894. Tenroman: 0x2169,
  895. Tetsecyrillic: 0x04B4,
  896. Theta: 0x0398,
  897. Thook: 0x01AC,
  898. Thorn: 0x00DE,
  899. Thornsmall: 0xF7FE,
  900. Threeroman: 0x2162,
  901. Tildesmall: 0xF6FE,
  902. Tiwnarmenian: 0x054F,
  903. Tlinebelow: 0x1E6E,
  904. Tmonospace: 0xFF34,
  905. Toarmenian: 0x0539,
  906. Tonefive: 0x01BC,
  907. Tonesix: 0x0184,
  908. Tonetwo: 0x01A7,
  909. Tretroflexhook: 0x01AE,
  910. Tsecyrillic: 0x0426,
  911. Tshecyrillic: 0x040B,
  912. Tsmall: 0xF774,
  913. Twelveroman: 0x216B,
  914. Tworoman: 0x2161,
  915. U: 0x0055,
  916. Uacute: 0x00DA,
  917. Uacutesmall: 0xF7FA,
  918. Ubreve: 0x016C,
  919. Ucaron: 0x01D3,
  920. Ucircle: 0x24CA,
  921. Ucircumflex: 0x00DB,
  922. Ucircumflexbelow: 0x1E76,
  923. Ucircumflexsmall: 0xF7FB,
  924. Ucyrillic: 0x0423,
  925. Udblacute: 0x0170,
  926. Udblgrave: 0x0214,
  927. Udieresis: 0x00DC,
  928. Udieresisacute: 0x01D7,
  929. Udieresisbelow: 0x1E72,
  930. Udieresiscaron: 0x01D9,
  931. Udieresiscyrillic: 0x04F0,
  932. Udieresisgrave: 0x01DB,
  933. Udieresismacron: 0x01D5,
  934. Udieresissmall: 0xF7FC,
  935. Udotbelow: 0x1EE4,
  936. Ugrave: 0x00D9,
  937. Ugravesmall: 0xF7F9,
  938. Uhookabove: 0x1EE6,
  939. Uhorn: 0x01AF,
  940. Uhornacute: 0x1EE8,
  941. Uhorndotbelow: 0x1EF0,
  942. Uhorngrave: 0x1EEA,
  943. Uhornhookabove: 0x1EEC,
  944. Uhorntilde: 0x1EEE,
  945. Uhungarumlaut: 0x0170,
  946. Uhungarumlautcyrillic: 0x04F2,
  947. Uinvertedbreve: 0x0216,
  948. Ukcyrillic: 0x0478,
  949. Umacron: 0x016A,
  950. Umacroncyrillic: 0x04EE,
  951. Umacrondieresis: 0x1E7A,
  952. Umonospace: 0xFF35,
  953. Uogonek: 0x0172,
  954. Upsilon: 0x03A5,
  955. Upsilon1: 0x03D2,
  956. Upsilonacutehooksymbolgreek: 0x03D3,
  957. Upsilonafrican: 0x01B1,
  958. Upsilondieresis: 0x03AB,
  959. Upsilondieresishooksymbolgreek: 0x03D4,
  960. Upsilonhooksymbol: 0x03D2,
  961. Upsilontonos: 0x038E,
  962. Uring: 0x016E,
  963. Ushortcyrillic: 0x040E,
  964. Usmall: 0xF775,
  965. Ustraightcyrillic: 0x04AE,
  966. Ustraightstrokecyrillic: 0x04B0,
  967. Utilde: 0x0168,
  968. Utildeacute: 0x1E78,
  969. Utildebelow: 0x1E74,
  970. V: 0x0056,
  971. Vcircle: 0x24CB,
  972. Vdotbelow: 0x1E7E,
  973. Vecyrillic: 0x0412,
  974. Vewarmenian: 0x054E,
  975. Vhook: 0x01B2,
  976. Vmonospace: 0xFF36,
  977. Voarmenian: 0x0548,
  978. Vsmall: 0xF776,
  979. Vtilde: 0x1E7C,
  980. W: 0x0057,
  981. Wacute: 0x1E82,
  982. Wcircle: 0x24CC,
  983. Wcircumflex: 0x0174,
  984. Wdieresis: 0x1E84,
  985. Wdotaccent: 0x1E86,
  986. Wdotbelow: 0x1E88,
  987. Wgrave: 0x1E80,
  988. Wmonospace: 0xFF37,
  989. Wsmall: 0xF777,
  990. X: 0x0058,
  991. Xcircle: 0x24CD,
  992. Xdieresis: 0x1E8C,
  993. Xdotaccent: 0x1E8A,
  994. Xeharmenian: 0x053D,
  995. Xi: 0x039E,
  996. Xmonospace: 0xFF38,
  997. Xsmall: 0xF778,
  998. Y: 0x0059,
  999. Yacute: 0x00DD,
  1000. Yacutesmall: 0xF7FD,
  1001. Yatcyrillic: 0x0462,
  1002. Ycircle: 0x24CE,
  1003. Ycircumflex: 0x0176,
  1004. Ydieresis: 0x0178,
  1005. Ydieresissmall: 0xF7FF,
  1006. Ydotaccent: 0x1E8E,
  1007. Ydotbelow: 0x1EF4,
  1008. Yericyrillic: 0x042B,
  1009. Yerudieresiscyrillic: 0x04F8,
  1010. Ygrave: 0x1EF2,
  1011. Yhook: 0x01B3,
  1012. Yhookabove: 0x1EF6,
  1013. Yiarmenian: 0x0545,
  1014. Yicyrillic: 0x0407,
  1015. Yiwnarmenian: 0x0552,
  1016. Ymonospace: 0xFF39,
  1017. Ysmall: 0xF779,
  1018. Ytilde: 0x1EF8,
  1019. Yusbigcyrillic: 0x046A,
  1020. Yusbigiotifiedcyrillic: 0x046C,
  1021. Yuslittlecyrillic: 0x0466,
  1022. Yuslittleiotifiedcyrillic: 0x0468,
  1023. Z: 0x005A,
  1024. Zaarmenian: 0x0536,
  1025. Zacute: 0x0179,
  1026. Zcaron: 0x017D,
  1027. Zcaronsmall: 0xF6FF,
  1028. Zcircle: 0x24CF,
  1029. Zcircumflex: 0x1E90,
  1030. Zdot: 0x017B,
  1031. Zdotaccent: 0x017B,
  1032. Zdotbelow: 0x1E92,
  1033. Zecyrillic: 0x0417,
  1034. Zedescendercyrillic: 0x0498,
  1035. Zedieresiscyrillic: 0x04DE,
  1036. Zeta: 0x0396,
  1037. Zhearmenian: 0x053A,
  1038. Zhebrevecyrillic: 0x04C1,
  1039. Zhecyrillic: 0x0416,
  1040. Zhedescendercyrillic: 0x0496,
  1041. Zhedieresiscyrillic: 0x04DC,
  1042. Zlinebelow: 0x1E94,
  1043. Zmonospace: 0xFF3A,
  1044. Zsmall: 0xF77A,
  1045. Zstroke: 0x01B5,
  1046. a: 0x0061,
  1047. aabengali: 0x0986,
  1048. aacute: 0x00E1,
  1049. aadeva: 0x0906,
  1050. aagujarati: 0x0A86,
  1051. aagurmukhi: 0x0A06,
  1052. aamatragurmukhi: 0x0A3E,
  1053. aarusquare: 0x3303,
  1054. aavowelsignbengali: 0x09BE,
  1055. aavowelsigndeva: 0x093E,
  1056. aavowelsigngujarati: 0x0ABE,
  1057. abbreviationmarkarmenian: 0x055F,
  1058. abbreviationsigndeva: 0x0970,
  1059. abengali: 0x0985,
  1060. abopomofo: 0x311A,
  1061. abreve: 0x0103,
  1062. abreveacute: 0x1EAF,
  1063. abrevecyrillic: 0x04D1,
  1064. abrevedotbelow: 0x1EB7,
  1065. abrevegrave: 0x1EB1,
  1066. abrevehookabove: 0x1EB3,
  1067. abrevetilde: 0x1EB5,
  1068. acaron: 0x01CE,
  1069. acircle: 0x24D0,
  1070. acircumflex: 0x00E2,
  1071. acircumflexacute: 0x1EA5,
  1072. acircumflexdotbelow: 0x1EAD,
  1073. acircumflexgrave: 0x1EA7,
  1074. acircumflexhookabove: 0x1EA9,
  1075. acircumflextilde: 0x1EAB,
  1076. acute: 0x00B4,
  1077. acutebelowcmb: 0x0317,
  1078. acutecmb: 0x0301,
  1079. acutecomb: 0x0301,
  1080. acutedeva: 0x0954,
  1081. acutelowmod: 0x02CF,
  1082. acutetonecmb: 0x0341,
  1083. acyrillic: 0x0430,
  1084. adblgrave: 0x0201,
  1085. addakgurmukhi: 0x0A71,
  1086. adeva: 0x0905,
  1087. adieresis: 0x00E4,
  1088. adieresiscyrillic: 0x04D3,
  1089. adieresismacron: 0x01DF,
  1090. adotbelow: 0x1EA1,
  1091. adotmacron: 0x01E1,
  1092. ae: 0x00E6,
  1093. aeacute: 0x01FD,
  1094. aekorean: 0x3150,
  1095. aemacron: 0x01E3,
  1096. afii00208: 0x2015,
  1097. afii08941: 0x20A4,
  1098. afii10017: 0x0410,
  1099. afii10018: 0x0411,
  1100. afii10019: 0x0412,
  1101. afii10020: 0x0413,
  1102. afii10021: 0x0414,
  1103. afii10022: 0x0415,
  1104. afii10023: 0x0401,
  1105. afii10024: 0x0416,
  1106. afii10025: 0x0417,
  1107. afii10026: 0x0418,
  1108. afii10027: 0x0419,
  1109. afii10028: 0x041A,
  1110. afii10029: 0x041B,
  1111. afii10030: 0x041C,
  1112. afii10031: 0x041D,
  1113. afii10032: 0x041E,
  1114. afii10033: 0x041F,
  1115. afii10034: 0x0420,
  1116. afii10035: 0x0421,
  1117. afii10036: 0x0422,
  1118. afii10037: 0x0423,
  1119. afii10038: 0x0424,
  1120. afii10039: 0x0425,
  1121. afii10040: 0x0426,
  1122. afii10041: 0x0427,
  1123. afii10042: 0x0428,
  1124. afii10043: 0x0429,
  1125. afii10044: 0x042A,
  1126. afii10045: 0x042B,
  1127. afii10046: 0x042C,
  1128. afii10047: 0x042D,
  1129. afii10048: 0x042E,
  1130. afii10049: 0x042F,
  1131. afii10050: 0x0490,
  1132. afii10051: 0x0402,
  1133. afii10052: 0x0403,
  1134. afii10053: 0x0404,
  1135. afii10054: 0x0405,
  1136. afii10055: 0x0406,
  1137. afii10056: 0x0407,
  1138. afii10057: 0x0408,
  1139. afii10058: 0x0409,
  1140. afii10059: 0x040A,
  1141. afii10060: 0x040B,
  1142. afii10061: 0x040C,
  1143. afii10062: 0x040E,
  1144. afii10063: 0xF6C4,
  1145. afii10064: 0xF6C5,
  1146. afii10065: 0x0430,
  1147. afii10066: 0x0431,
  1148. afii10067: 0x0432,
  1149. afii10068: 0x0433,
  1150. afii10069: 0x0434,
  1151. afii10070: 0x0435,
  1152. afii10071: 0x0451,
  1153. afii10072: 0x0436,
  1154. afii10073: 0x0437,
  1155. afii10074: 0x0438,
  1156. afii10075: 0x0439,
  1157. afii10076: 0x043A,
  1158. afii10077: 0x043B,
  1159. afii10078: 0x043C,
  1160. afii10079: 0x043D,
  1161. afii10080: 0x043E,
  1162. afii10081: 0x043F,
  1163. afii10082: 0x0440,
  1164. afii10083: 0x0441,
  1165. afii10084: 0x0442,
  1166. afii10085: 0x0443,
  1167. afii10086: 0x0444,
  1168. afii10087: 0x0445,
  1169. afii10088: 0x0446,
  1170. afii10089: 0x0447,
  1171. afii10090: 0x0448,
  1172. afii10091: 0x0449,
  1173. afii10092: 0x044A,
  1174. afii10093: 0x044B,
  1175. afii10094: 0x044C,
  1176. afii10095: 0x044D,
  1177. afii10096: 0x044E,
  1178. afii10097: 0x044F,
  1179. afii10098: 0x0491,
  1180. afii10099: 0x0452,
  1181. afii10100: 0x0453,
  1182. afii10101: 0x0454,
  1183. afii10102: 0x0455,
  1184. afii10103: 0x0456,
  1185. afii10104: 0x0457,
  1186. afii10105: 0x0458,
  1187. afii10106: 0x0459,
  1188. afii10107: 0x045A,
  1189. afii10108: 0x045B,
  1190. afii10109: 0x045C,
  1191. afii10110: 0x045E,
  1192. afii10145: 0x040F,
  1193. afii10146: 0x0462,
  1194. afii10147: 0x0472,
  1195. afii10148: 0x0474,
  1196. afii10192: 0xF6C6,
  1197. afii10193: 0x045F,
  1198. afii10194: 0x0463,
  1199. afii10195: 0x0473,
  1200. afii10196: 0x0475,
  1201. afii10831: 0xF6C7,
  1202. afii10832: 0xF6C8,
  1203. afii10846: 0x04D9,
  1204. afii299: 0x200E,
  1205. afii300: 0x200F,
  1206. afii301: 0x200D,
  1207. afii57381: 0x066A,
  1208. afii57388: 0x060C,
  1209. afii57392: 0x0660,
  1210. afii57393: 0x0661,
  1211. afii57394: 0x0662,
  1212. afii57395: 0x0663,
  1213. afii57396: 0x0664,
  1214. afii57397: 0x0665,
  1215. afii57398: 0x0666,
  1216. afii57399: 0x0667,
  1217. afii57400: 0x0668,
  1218. afii57401: 0x0669,
  1219. afii57403: 0x061B,
  1220. afii57407: 0x061F,
  1221. afii57409: 0x0621,
  1222. afii57410: 0x0622,
  1223. afii57411: 0x0623,
  1224. afii57412: 0x0624,
  1225. afii57413: 0x0625,
  1226. afii57414: 0x0626,
  1227. afii57415: 0x0627,
  1228. afii57416: 0x0628,
  1229. afii57417: 0x0629,
  1230. afii57418: 0x062A,
  1231. afii57419: 0x062B,
  1232. afii57420: 0x062C,
  1233. afii57421: 0x062D,
  1234. afii57422: 0x062E,
  1235. afii57423: 0x062F,
  1236. afii57424: 0x0630,
  1237. afii57425: 0x0631,
  1238. afii57426: 0x0632,
  1239. afii57427: 0x0633,
  1240. afii57428: 0x0634,
  1241. afii57429: 0x0635,
  1242. afii57430: 0x0636,
  1243. afii57431: 0x0637,
  1244. afii57432: 0x0638,
  1245. afii57433: 0x0639,
  1246. afii57434: 0x063A,
  1247. afii57440: 0x0640,
  1248. afii57441: 0x0641,
  1249. afii57442: 0x0642,
  1250. afii57443: 0x0643,
  1251. afii57444: 0x0644,
  1252. afii57445: 0x0645,
  1253. afii57446: 0x0646,
  1254. afii57448: 0x0648,
  1255. afii57449: 0x0649,
  1256. afii57450: 0x064A,
  1257. afii57451: 0x064B,
  1258. afii57452: 0x064C,
  1259. afii57453: 0x064D,
  1260. afii57454: 0x064E,
  1261. afii57455: 0x064F,
  1262. afii57456: 0x0650,
  1263. afii57457: 0x0651,
  1264. afii57458: 0x0652,
  1265. afii57470: 0x0647,
  1266. afii57505: 0x06A4,
  1267. afii57506: 0x067E,
  1268. afii57507: 0x0686,
  1269. afii57508: 0x0698,
  1270. afii57509: 0x06AF,
  1271. afii57511: 0x0679,
  1272. afii57512: 0x0688,
  1273. afii57513: 0x0691,
  1274. afii57514: 0x06BA,
  1275. afii57519: 0x06D2,
  1276. afii57534: 0x06D5,
  1277. afii57636: 0x20AA,
  1278. afii57645: 0x05BE,
  1279. afii57658: 0x05C3,
  1280. afii57664: 0x05D0,
  1281. afii57665: 0x05D1,
  1282. afii57666: 0x05D2,
  1283. afii57667: 0x05D3,
  1284. afii57668: 0x05D4,
  1285. afii57669: 0x05D5,
  1286. afii57670: 0x05D6,
  1287. afii57671: 0x05D7,
  1288. afii57672: 0x05D8,
  1289. afii57673: 0x05D9,
  1290. afii57674: 0x05DA,
  1291. afii57675: 0x05DB,
  1292. afii57676: 0x05DC,
  1293. afii57677: 0x05DD,
  1294. afii57678: 0x05DE,
  1295. afii57679: 0x05DF,
  1296. afii57680: 0x05E0,
  1297. afii57681: 0x05E1,
  1298. afii57682: 0x05E2,
  1299. afii57683: 0x05E3,
  1300. afii57684: 0x05E4,
  1301. afii57685: 0x05E5,
  1302. afii57686: 0x05E6,
  1303. afii57687: 0x05E7,
  1304. afii57688: 0x05E8,
  1305. afii57689: 0x05E9,
  1306. afii57690: 0x05EA,
  1307. afii57694: 0xFB2A,
  1308. afii57695: 0xFB2B,
  1309. afii57700: 0xFB4B,
  1310. afii57705: 0xFB1F,
  1311. afii57716: 0x05F0,
  1312. afii57717: 0x05F1,
  1313. afii57718: 0x05F2,
  1314. afii57723: 0xFB35,
  1315. afii57793: 0x05B4,
  1316. afii57794: 0x05B5,
  1317. afii57795: 0x05B6,
  1318. afii57796: 0x05BB,
  1319. afii57797: 0x05B8,
  1320. afii57798: 0x05B7,
  1321. afii57799: 0x05B0,
  1322. afii57800: 0x05B2,
  1323. afii57801: 0x05B1,
  1324. afii57802: 0x05B3,
  1325. afii57803: 0x05C2,
  1326. afii57804: 0x05C1,
  1327. afii57806: 0x05B9,
  1328. afii57807: 0x05BC,
  1329. afii57839: 0x05BD,
  1330. afii57841: 0x05BF,
  1331. afii57842: 0x05C0,
  1332. afii57929: 0x02BC,
  1333. afii61248: 0x2105,
  1334. afii61289: 0x2113,
  1335. afii61352: 0x2116,
  1336. afii61573: 0x202C,
  1337. afii61574: 0x202D,
  1338. afii61575: 0x202E,
  1339. afii61664: 0x200C,
  1340. afii63167: 0x066D,
  1341. afii64937: 0x02BD,
  1342. agrave: 0x00E0,
  1343. agujarati: 0x0A85,
  1344. agurmukhi: 0x0A05,
  1345. ahiragana: 0x3042,
  1346. ahookabove: 0x1EA3,
  1347. aibengali: 0x0990,
  1348. aibopomofo: 0x311E,
  1349. aideva: 0x0910,
  1350. aiecyrillic: 0x04D5,
  1351. aigujarati: 0x0A90,
  1352. aigurmukhi: 0x0A10,
  1353. aimatragurmukhi: 0x0A48,
  1354. ainarabic: 0x0639,
  1355. ainfinalarabic: 0xFECA,
  1356. aininitialarabic: 0xFECB,
  1357. ainmedialarabic: 0xFECC,
  1358. ainvertedbreve: 0x0203,
  1359. aivowelsignbengali: 0x09C8,
  1360. aivowelsigndeva: 0x0948,
  1361. aivowelsigngujarati: 0x0AC8,
  1362. akatakana: 0x30A2,
  1363. akatakanahalfwidth: 0xFF71,
  1364. akorean: 0x314F,
  1365. alef: 0x05D0,
  1366. alefarabic: 0x0627,
  1367. alefdageshhebrew: 0xFB30,
  1368. aleffinalarabic: 0xFE8E,
  1369. alefhamzaabovearabic: 0x0623,
  1370. alefhamzaabovefinalarabic: 0xFE84,
  1371. alefhamzabelowarabic: 0x0625,
  1372. alefhamzabelowfinalarabic: 0xFE88,
  1373. alefhebrew: 0x05D0,
  1374. aleflamedhebrew: 0xFB4F,
  1375. alefmaddaabovearabic: 0x0622,
  1376. alefmaddaabovefinalarabic: 0xFE82,
  1377. alefmaksuraarabic: 0x0649,
  1378. alefmaksurafinalarabic: 0xFEF0,
  1379. alefmaksurainitialarabic: 0xFEF3,
  1380. alefmaksuramedialarabic: 0xFEF4,
  1381. alefpatahhebrew: 0xFB2E,
  1382. alefqamatshebrew: 0xFB2F,
  1383. aleph: 0x2135,
  1384. allequal: 0x224C,
  1385. alpha: 0x03B1,
  1386. alphatonos: 0x03AC,
  1387. amacron: 0x0101,
  1388. amonospace: 0xFF41,
  1389. ampersand: 0x0026,
  1390. ampersandmonospace: 0xFF06,
  1391. ampersandsmall: 0xF726,
  1392. amsquare: 0x33C2,
  1393. anbopomofo: 0x3122,
  1394. angbopomofo: 0x3124,
  1395. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  1396. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  1397. angkhankhuthai: 0x0E5A,
  1398. angle: 0x2220,
  1399. anglebracketleft: 0x3008,
  1400. anglebracketleftvertical: 0xFE3F,
  1401. anglebracketright: 0x3009,
  1402. anglebracketrightvertical: 0xFE40,
  1403. angleleft: 0x2329,
  1404. angleright: 0x232A,
  1405. angstrom: 0x212B,
  1406. anoteleia: 0x0387,
  1407. anudattadeva: 0x0952,
  1408. anusvarabengali: 0x0982,
  1409. anusvaradeva: 0x0902,
  1410. anusvaragujarati: 0x0A82,
  1411. aogonek: 0x0105,
  1412. apaatosquare: 0x3300,
  1413. aparen: 0x249C,
  1414. apostrophearmenian: 0x055A,
  1415. apostrophemod: 0x02BC,
  1416. apple: 0xF8FF,
  1417. approaches: 0x2250,
  1418. approxequal: 0x2248,
  1419. approxequalorimage: 0x2252,
  1420. approximatelyequal: 0x2245,
  1421. araeaekorean: 0x318E,
  1422. araeakorean: 0x318D,
  1423. arc: 0x2312,
  1424. arighthalfring: 0x1E9A,
  1425. aring: 0x00E5,
  1426. aringacute: 0x01FB,
  1427. aringbelow: 0x1E01,
  1428. arrowboth: 0x2194,
  1429. arrowdashdown: 0x21E3,
  1430. arrowdashleft: 0x21E0,
  1431. arrowdashright: 0x21E2,
  1432. arrowdashup: 0x21E1,
  1433. arrowdblboth: 0x21D4,
  1434. arrowdbldown: 0x21D3,
  1435. arrowdblleft: 0x21D0,
  1436. arrowdblright: 0x21D2,
  1437. arrowdblup: 0x21D1,
  1438. arrowdown: 0x2193,
  1439. arrowdownleft: 0x2199,
  1440. arrowdownright: 0x2198,
  1441. arrowdownwhite: 0x21E9,
  1442. arrowheaddownmod: 0x02C5,
  1443. arrowheadleftmod: 0x02C2,
  1444. arrowheadrightmod: 0x02C3,
  1445. arrowheadupmod: 0x02C4,
  1446. arrowhorizex: 0xF8E7,
  1447. arrowleft: 0x2190,
  1448. arrowleftdbl: 0x21D0,
  1449. arrowleftdblstroke: 0x21CD,
  1450. arrowleftoverright: 0x21C6,
  1451. arrowleftwhite: 0x21E6,
  1452. arrowright: 0x2192,
  1453. arrowrightdblstroke: 0x21CF,
  1454. arrowrightheavy: 0x279E,
  1455. arrowrightoverleft: 0x21C4,
  1456. arrowrightwhite: 0x21E8,
  1457. arrowtableft: 0x21E4,
  1458. arrowtabright: 0x21E5,
  1459. arrowup: 0x2191,
  1460. arrowupdn: 0x2195,
  1461. arrowupdnbse: 0x21A8,
  1462. arrowupdownbase: 0x21A8,
  1463. arrowupleft: 0x2196,
  1464. arrowupleftofdown: 0x21C5,
  1465. arrowupright: 0x2197,
  1466. arrowupwhite: 0x21E7,
  1467. arrowvertex: 0xF8E6,
  1468. asciicircum: 0x005E,
  1469. asciicircummonospace: 0xFF3E,
  1470. asciitilde: 0x007E,
  1471. asciitildemonospace: 0xFF5E,
  1472. ascript: 0x0251,
  1473. ascriptturned: 0x0252,
  1474. asmallhiragana: 0x3041,
  1475. asmallkatakana: 0x30A1,
  1476. asmallkatakanahalfwidth: 0xFF67,
  1477. asterisk: 0x002A,
  1478. asteriskaltonearabic: 0x066D,
  1479. asteriskarabic: 0x066D,
  1480. asteriskmath: 0x2217,
  1481. asteriskmonospace: 0xFF0A,
  1482. asterisksmall: 0xFE61,
  1483. asterism: 0x2042,
  1484. asuperior: 0xF6E9,
  1485. asymptoticallyequal: 0x2243,
  1486. at: 0x0040,
  1487. atilde: 0x00E3,
  1488. atmonospace: 0xFF20,
  1489. atsmall: 0xFE6B,
  1490. aturned: 0x0250,
  1491. aubengali: 0x0994,
  1492. aubopomofo: 0x3120,
  1493. audeva: 0x0914,
  1494. augujarati: 0x0A94,
  1495. augurmukhi: 0x0A14,
  1496. aulengthmarkbengali: 0x09D7,
  1497. aumatragurmukhi: 0x0A4C,
  1498. auvowelsignbengali: 0x09CC,
  1499. auvowelsigndeva: 0x094C,
  1500. auvowelsigngujarati: 0x0ACC,
  1501. avagrahadeva: 0x093D,
  1502. aybarmenian: 0x0561,
  1503. ayin: 0x05E2,
  1504. ayinaltonehebrew: 0xFB20,
  1505. ayinhebrew: 0x05E2,
  1506. b: 0x0062,
  1507. babengali: 0x09AC,
  1508. backslash: 0x005C,
  1509. backslashmonospace: 0xFF3C,
  1510. badeva: 0x092C,
  1511. bagujarati: 0x0AAC,
  1512. bagurmukhi: 0x0A2C,
  1513. bahiragana: 0x3070,
  1514. bahtthai: 0x0E3F,
  1515. bakatakana: 0x30D0,
  1516. bar: 0x007C,
  1517. barmonospace: 0xFF5C,
  1518. bbopomofo: 0x3105,
  1519. bcircle: 0x24D1,
  1520. bdotaccent: 0x1E03,
  1521. bdotbelow: 0x1E05,
  1522. beamedsixteenthnotes: 0x266C,
  1523. because: 0x2235,
  1524. becyrillic: 0x0431,
  1525. beharabic: 0x0628,
  1526. behfinalarabic: 0xFE90,
  1527. behinitialarabic: 0xFE91,
  1528. behiragana: 0x3079,
  1529. behmedialarabic: 0xFE92,
  1530. behmeeminitialarabic: 0xFC9F,
  1531. behmeemisolatedarabic: 0xFC08,
  1532. behnoonfinalarabic: 0xFC6D,
  1533. bekatakana: 0x30D9,
  1534. benarmenian: 0x0562,
  1535. bet: 0x05D1,
  1536. beta: 0x03B2,
  1537. betasymbolgreek: 0x03D0,
  1538. betdagesh: 0xFB31,
  1539. betdageshhebrew: 0xFB31,
  1540. bethebrew: 0x05D1,
  1541. betrafehebrew: 0xFB4C,
  1542. bhabengali: 0x09AD,
  1543. bhadeva: 0x092D,
  1544. bhagujarati: 0x0AAD,
  1545. bhagurmukhi: 0x0A2D,
  1546. bhook: 0x0253,
  1547. bihiragana: 0x3073,
  1548. bikatakana: 0x30D3,
  1549. bilabialclick: 0x0298,
  1550. bindigurmukhi: 0x0A02,
  1551. birusquare: 0x3331,
  1552. blackcircle: 0x25CF,
  1553. blackdiamond: 0x25C6,
  1554. blackdownpointingtriangle: 0x25BC,
  1555. blackleftpointingpointer: 0x25C4,
  1556. blackleftpointingtriangle: 0x25C0,
  1557. blacklenticularbracketleft: 0x3010,
  1558. blacklenticularbracketleftvertical: 0xFE3B,
  1559. blacklenticularbracketright: 0x3011,
  1560. blacklenticularbracketrightvertical: 0xFE3C,
  1561. blacklowerlefttriangle: 0x25E3,
  1562. blacklowerrighttriangle: 0x25E2,
  1563. blackrectangle: 0x25AC,
  1564. blackrightpointingpointer: 0x25BA,
  1565. blackrightpointingtriangle: 0x25B6,
  1566. blacksmallsquare: 0x25AA,
  1567. blacksmilingface: 0x263B,
  1568. blacksquare: 0x25A0,
  1569. blackstar: 0x2605,
  1570. blackupperlefttriangle: 0x25E4,
  1571. blackupperrighttriangle: 0x25E5,
  1572. blackuppointingsmalltriangle: 0x25B4,
  1573. blackuppointingtriangle: 0x25B2,
  1574. blank: 0x2423,
  1575. blinebelow: 0x1E07,
  1576. block: 0x2588,
  1577. bmonospace: 0xFF42,
  1578. bobaimaithai: 0x0E1A,
  1579. bohiragana: 0x307C,
  1580. bokatakana: 0x30DC,
  1581. bparen: 0x249D,
  1582. bqsquare: 0x33C3,
  1583. braceex: 0xF8F4,
  1584. braceleft: 0x007B,
  1585. braceleftbt: 0xF8F3,
  1586. braceleftmid: 0xF8F2,
  1587. braceleftmonospace: 0xFF5B,
  1588. braceleftsmall: 0xFE5B,
  1589. bracelefttp: 0xF8F1,
  1590. braceleftvertical: 0xFE37,
  1591. braceright: 0x007D,
  1592. bracerightbt: 0xF8FE,
  1593. bracerightmid: 0xF8FD,
  1594. bracerightmonospace: 0xFF5D,
  1595. bracerightsmall: 0xFE5C,
  1596. bracerighttp: 0xF8FC,
  1597. bracerightvertical: 0xFE38,
  1598. bracketleft: 0x005B,
  1599. bracketleftbt: 0xF8F0,
  1600. bracketleftex: 0xF8EF,
  1601. bracketleftmonospace: 0xFF3B,
  1602. bracketlefttp: 0xF8EE,
  1603. bracketright: 0x005D,
  1604. bracketrightbt: 0xF8FB,
  1605. bracketrightex: 0xF8FA,
  1606. bracketrightmonospace: 0xFF3D,
  1607. bracketrighttp: 0xF8F9,
  1608. breve: 0x02D8,
  1609. brevebelowcmb: 0x032E,
  1610. brevecmb: 0x0306,
  1611. breveinvertedbelowcmb: 0x032F,
  1612. breveinvertedcmb: 0x0311,
  1613. breveinverteddoublecmb: 0x0361,
  1614. bridgebelowcmb: 0x032A,
  1615. bridgeinvertedbelowcmb: 0x033A,
  1616. brokenbar: 0x00A6,
  1617. bstroke: 0x0180,
  1618. bsuperior: 0xF6EA,
  1619. btopbar: 0x0183,
  1620. buhiragana: 0x3076,
  1621. bukatakana: 0x30D6,
  1622. bullet: 0x2022,
  1623. bulletinverse: 0x25D8,
  1624. bulletoperator: 0x2219,
  1625. bullseye: 0x25CE,
  1626. c: 0x0063,
  1627. caarmenian: 0x056E,
  1628. cabengali: 0x099A,
  1629. cacute: 0x0107,
  1630. cadeva: 0x091A,
  1631. cagujarati: 0x0A9A,
  1632. cagurmukhi: 0x0A1A,
  1633. calsquare: 0x3388,
  1634. candrabindubengali: 0x0981,
  1635. candrabinducmb: 0x0310,
  1636. candrabindudeva: 0x0901,
  1637. candrabindugujarati: 0x0A81,
  1638. capslock: 0x21EA,
  1639. careof: 0x2105,
  1640. caron: 0x02C7,
  1641. caronbelowcmb: 0x032C,
  1642. caroncmb: 0x030C,
  1643. carriagereturn: 0x21B5,
  1644. cbopomofo: 0x3118,
  1645. ccaron: 0x010D,
  1646. ccedilla: 0x00E7,
  1647. ccedillaacute: 0x1E09,
  1648. ccircle: 0x24D2,
  1649. ccircumflex: 0x0109,
  1650. ccurl: 0x0255,
  1651. cdot: 0x010B,
  1652. cdotaccent: 0x010B,
  1653. cdsquare: 0x33C5,
  1654. cedilla: 0x00B8,
  1655. cedillacmb: 0x0327,
  1656. cent: 0x00A2,
  1657. centigrade: 0x2103,
  1658. centinferior: 0xF6DF,
  1659. centmonospace: 0xFFE0,
  1660. centoldstyle: 0xF7A2,
  1661. centsuperior: 0xF6E0,
  1662. chaarmenian: 0x0579,
  1663. chabengali: 0x099B,
  1664. chadeva: 0x091B,
  1665. chagujarati: 0x0A9B,
  1666. chagurmukhi: 0x0A1B,
  1667. chbopomofo: 0x3114,
  1668. cheabkhasiancyrillic: 0x04BD,
  1669. checkmark: 0x2713,
  1670. checyrillic: 0x0447,
  1671. chedescenderabkhasiancyrillic: 0x04BF,
  1672. chedescendercyrillic: 0x04B7,
  1673. chedieresiscyrillic: 0x04F5,
  1674. cheharmenian: 0x0573,
  1675. chekhakassiancyrillic: 0x04CC,
  1676. cheverticalstrokecyrillic: 0x04B9,
  1677. chi: 0x03C7,
  1678. chieuchacirclekorean: 0x3277,
  1679. chieuchaparenkorean: 0x3217,
  1680. chieuchcirclekorean: 0x3269,
  1681. chieuchkorean: 0x314A,
  1682. chieuchparenkorean: 0x3209,
  1683. chochangthai: 0x0E0A,
  1684. chochanthai: 0x0E08,
  1685. chochingthai: 0x0E09,
  1686. chochoethai: 0x0E0C,
  1687. chook: 0x0188,
  1688. cieucacirclekorean: 0x3276,
  1689. cieucaparenkorean: 0x3216,
  1690. cieuccirclekorean: 0x3268,
  1691. cieuckorean: 0x3148,
  1692. cieucparenkorean: 0x3208,
  1693. cieucuparenkorean: 0x321C,
  1694. circle: 0x25CB,
  1695. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  1696. circlemultiply: 0x2297,
  1697. circleot: 0x2299,
  1698. circleplus: 0x2295,
  1699. circlepostalmark: 0x3036,
  1700. circlewithlefthalfblack: 0x25D0,
  1701. circlewithrighthalfblack: 0x25D1,
  1702. circumflex: 0x02C6,
  1703. circumflexbelowcmb: 0x032D,
  1704. circumflexcmb: 0x0302,
  1705. clear: 0x2327,
  1706. clickalveolar: 0x01C2,
  1707. clickdental: 0x01C0,
  1708. clicklateral: 0x01C1,
  1709. clickretroflex: 0x01C3,
  1710. club: 0x2663,
  1711. clubsuitblack: 0x2663,
  1712. clubsuitwhite: 0x2667,
  1713. cmcubedsquare: 0x33A4,
  1714. cmonospace: 0xFF43,
  1715. cmsquaredsquare: 0x33A0,
  1716. coarmenian: 0x0581,
  1717. colon: 0x003A,
  1718. colonmonetary: 0x20A1,
  1719. colonmonospace: 0xFF1A,
  1720. colonsign: 0x20A1,
  1721. colonsmall: 0xFE55,
  1722. colontriangularhalfmod: 0x02D1,
  1723. colontriangularmod: 0x02D0,
  1724. comma: 0x002C,
  1725. commaabovecmb: 0x0313,
  1726. commaaboverightcmb: 0x0315,
  1727. commaaccent: 0xF6C3,
  1728. commaarabic: 0x060C,
  1729. commaarmenian: 0x055D,
  1730. commainferior: 0xF6E1,
  1731. commamonospace: 0xFF0C,
  1732. commareversedabovecmb: 0x0314,
  1733. commareversedmod: 0x02BD,
  1734. commasmall: 0xFE50,
  1735. commasuperior: 0xF6E2,
  1736. commaturnedabovecmb: 0x0312,
  1737. commaturnedmod: 0x02BB,
  1738. compass: 0x263C,
  1739. congruent: 0x2245,
  1740. contourintegral: 0x222E,
  1741. control: 0x2303,
  1742. controlACK: 0x0006,
  1743. controlBEL: 0x0007,
  1744. controlBS: 0x0008,
  1745. controlCAN: 0x0018,
  1746. controlCR: 0x000D,
  1747. controlDC1: 0x0011,
  1748. controlDC2: 0x0012,
  1749. controlDC3: 0x0013,
  1750. controlDC4: 0x0014,
  1751. controlDEL: 0x007F,
  1752. controlDLE: 0x0010,
  1753. controlEM: 0x0019,
  1754. controlENQ: 0x0005,
  1755. controlEOT: 0x0004,
  1756. controlESC: 0x001B,
  1757. controlETB: 0x0017,
  1758. controlETX: 0x0003,
  1759. controlFF: 0x000C,
  1760. controlFS: 0x001C,
  1761. controlGS: 0x001D,
  1762. controlHT: 0x0009,
  1763. controlLF: 0x000A,
  1764. controlNAK: 0x0015,
  1765. controlRS: 0x001E,
  1766. controlSI: 0x000F,
  1767. controlSO: 0x000E,
  1768. controlSOT: 0x0002,
  1769. controlSTX: 0x0001,
  1770. controlSUB: 0x001A,
  1771. controlSYN: 0x0016,
  1772. controlUS: 0x001F,
  1773. controlVT: 0x000B,
  1774. copyright: 0x00A9,
  1775. copyrightsans: 0xF8E9,
  1776. copyrightserif: 0xF6D9,
  1777. cornerbracketleft: 0x300C,
  1778. cornerbracketlefthalfwidth: 0xFF62,
  1779. cornerbracketleftvertical: 0xFE41,
  1780. cornerbracketright: 0x300D,
  1781. cornerbracketrighthalfwidth: 0xFF63,
  1782. cornerbracketrightvertical: 0xFE42,
  1783. corporationsquare: 0x337F,
  1784. cosquare: 0x33C7,
  1785. coverkgsquare: 0x33C6,
  1786. cparen: 0x249E,
  1787. cruzeiro: 0x20A2,
  1788. cstretched: 0x0297,
  1789. curlyand: 0x22CF,
  1790. curlyor: 0x22CE,
  1791. currency: 0x00A4,
  1792. cyrBreve: 0xF6D1,
  1793. cyrFlex: 0xF6D2,
  1794. cyrbreve: 0xF6D4,
  1795. cyrflex: 0xF6D5,
  1796. d: 0x0064,
  1797. daarmenian: 0x0564,
  1798. dabengali: 0x09A6,
  1799. dadarabic: 0x0636,
  1800. dadeva: 0x0926,
  1801. dadfinalarabic: 0xFEBE,
  1802. dadinitialarabic: 0xFEBF,
  1803. dadmedialarabic: 0xFEC0,
  1804. dagesh: 0x05BC,
  1805. dageshhebrew: 0x05BC,
  1806. dagger: 0x2020,
  1807. daggerdbl: 0x2021,
  1808. dagujarati: 0x0AA6,
  1809. dagurmukhi: 0x0A26,
  1810. dahiragana: 0x3060,
  1811. dakatakana: 0x30C0,
  1812. dalarabic: 0x062F,
  1813. dalet: 0x05D3,
  1814. daletdagesh: 0xFB33,
  1815. daletdageshhebrew: 0xFB33,
  1816. dalethebrew: 0x05D3,
  1817. dalfinalarabic: 0xFEAA,
  1818. dammaarabic: 0x064F,
  1819. dammalowarabic: 0x064F,
  1820. dammatanaltonearabic: 0x064C,
  1821. dammatanarabic: 0x064C,
  1822. danda: 0x0964,
  1823. dargahebrew: 0x05A7,
  1824. dargalefthebrew: 0x05A7,
  1825. dasiapneumatacyrilliccmb: 0x0485,
  1826. dblGrave: 0xF6D3,
  1827. dblanglebracketleft: 0x300A,
  1828. dblanglebracketleftvertical: 0xFE3D,
  1829. dblanglebracketright: 0x300B,
  1830. dblanglebracketrightvertical: 0xFE3E,
  1831. dblarchinvertedbelowcmb: 0x032B,
  1832. dblarrowleft: 0x21D4,
  1833. dblarrowright: 0x21D2,
  1834. dbldanda: 0x0965,
  1835. dblgrave: 0xF6D6,
  1836. dblgravecmb: 0x030F,
  1837. dblintegral: 0x222C,
  1838. dbllowline: 0x2017,
  1839. dbllowlinecmb: 0x0333,
  1840. dbloverlinecmb: 0x033F,
  1841. dblprimemod: 0x02BA,
  1842. dblverticalbar: 0x2016,
  1843. dblverticallineabovecmb: 0x030E,
  1844. dbopomofo: 0x3109,
  1845. dbsquare: 0x33C8,
  1846. dcaron: 0x010F,
  1847. dcedilla: 0x1E11,
  1848. dcircle: 0x24D3,
  1849. dcircumflexbelow: 0x1E13,
  1850. dcroat: 0x0111,
  1851. ddabengali: 0x09A1,
  1852. ddadeva: 0x0921,
  1853. ddagujarati: 0x0AA1,
  1854. ddagurmukhi: 0x0A21,
  1855. ddalarabic: 0x0688,
  1856. ddalfinalarabic: 0xFB89,
  1857. dddhadeva: 0x095C,
  1858. ddhabengali: 0x09A2,
  1859. ddhadeva: 0x0922,
  1860. ddhagujarati: 0x0AA2,
  1861. ddhagurmukhi: 0x0A22,
  1862. ddotaccent: 0x1E0B,
  1863. ddotbelow: 0x1E0D,
  1864. decimalseparatorarabic: 0x066B,
  1865. decimalseparatorpersian: 0x066B,
  1866. decyrillic: 0x0434,
  1867. degree: 0x00B0,
  1868. dehihebrew: 0x05AD,
  1869. dehiragana: 0x3067,
  1870. deicoptic: 0x03EF,
  1871. dekatakana: 0x30C7,
  1872. deleteleft: 0x232B,
  1873. deleteright: 0x2326,
  1874. delta: 0x03B4,
  1875. deltaturned: 0x018D,
  1876. denominatorminusonenumeratorbengali: 0x09F8,
  1877. dezh: 0x02A4,
  1878. dhabengali: 0x09A7,
  1879. dhadeva: 0x0927,
  1880. dhagujarati: 0x0AA7,
  1881. dhagurmukhi: 0x0A27,
  1882. dhook: 0x0257,
  1883. dialytikatonos: 0x0385,
  1884. dialytikatonoscmb: 0x0344,
  1885. diamond: 0x2666,
  1886. diamondsuitwhite: 0x2662,
  1887. dieresis: 0x00A8,
  1888. dieresisacute: 0xF6D7,
  1889. dieresisbelowcmb: 0x0324,
  1890. dieresiscmb: 0x0308,
  1891. dieresisgrave: 0xF6D8,
  1892. dieresistonos: 0x0385,
  1893. dihiragana: 0x3062,
  1894. dikatakana: 0x30C2,
  1895. dittomark: 0x3003,
  1896. divide: 0x00F7,
  1897. divides: 0x2223,
  1898. divisionslash: 0x2215,
  1899. djecyrillic: 0x0452,
  1900. dkshade: 0x2593,
  1901. dlinebelow: 0x1E0F,
  1902. dlsquare: 0x3397,
  1903. dmacron: 0x0111,
  1904. dmonospace: 0xFF44,
  1905. dnblock: 0x2584,
  1906. dochadathai: 0x0E0E,
  1907. dodekthai: 0x0E14,
  1908. dohiragana: 0x3069,
  1909. dokatakana: 0x30C9,
  1910. dollar: 0x0024,
  1911. dollarinferior: 0xF6E3,
  1912. dollarmonospace: 0xFF04,
  1913. dollaroldstyle: 0xF724,
  1914. dollarsmall: 0xFE69,
  1915. dollarsuperior: 0xF6E4,
  1916. dong: 0x20AB,
  1917. dorusquare: 0x3326,
  1918. dotaccent: 0x02D9,
  1919. dotaccentcmb: 0x0307,
  1920. dotbelowcmb: 0x0323,
  1921. dotbelowcomb: 0x0323,
  1922. dotkatakana: 0x30FB,
  1923. dotlessi: 0x0131,
  1924. dotlessj: 0xF6BE,
  1925. dotlessjstrokehook: 0x0284,
  1926. dotmath: 0x22C5,
  1927. dottedcircle: 0x25CC,
  1928. doubleyodpatah: 0xFB1F,
  1929. doubleyodpatahhebrew: 0xFB1F,
  1930. downtackbelowcmb: 0x031E,
  1931. downtackmod: 0x02D5,
  1932. dparen: 0x249F,
  1933. dsuperior: 0xF6EB,
  1934. dtail: 0x0256,
  1935. dtopbar: 0x018C,
  1936. duhiragana: 0x3065,
  1937. dukatakana: 0x30C5,
  1938. dz: 0x01F3,
  1939. dzaltone: 0x02A3,
  1940. dzcaron: 0x01C6,
  1941. dzcurl: 0x02A5,
  1942. dzeabkhasiancyrillic: 0x04E1,
  1943. dzecyrillic: 0x0455,
  1944. dzhecyrillic: 0x045F,
  1945. e: 0x0065,
  1946. eacute: 0x00E9,
  1947. earth: 0x2641,
  1948. ebengali: 0x098F,
  1949. ebopomofo: 0x311C,
  1950. ebreve: 0x0115,
  1951. ecandradeva: 0x090D,
  1952. ecandragujarati: 0x0A8D,
  1953. ecandravowelsigndeva: 0x0945,
  1954. ecandravowelsigngujarati: 0x0AC5,
  1955. ecaron: 0x011B,
  1956. ecedillabreve: 0x1E1D,
  1957. echarmenian: 0x0565,
  1958. echyiwnarmenian: 0x0587,
  1959. ecircle: 0x24D4,
  1960. ecircumflex: 0x00EA,
  1961. ecircumflexacute: 0x1EBF,
  1962. ecircumflexbelow: 0x1E19,
  1963. ecircumflexdotbelow: 0x1EC7,
  1964. ecircumflexgrave: 0x1EC1,
  1965. ecircumflexhookabove: 0x1EC3,
  1966. ecircumflextilde: 0x1EC5,
  1967. ecyrillic: 0x0454,
  1968. edblgrave: 0x0205,
  1969. edeva: 0x090F,
  1970. edieresis: 0x00EB,
  1971. edot: 0x0117,
  1972. edotaccent: 0x0117,
  1973. edotbelow: 0x1EB9,
  1974. eegurmukhi: 0x0A0F,
  1975. eematragurmukhi: 0x0A47,
  1976. efcyrillic: 0x0444,
  1977. egrave: 0x00E8,
  1978. egujarati: 0x0A8F,
  1979. eharmenian: 0x0567,
  1980. ehbopomofo: 0x311D,
  1981. ehiragana: 0x3048,
  1982. ehookabove: 0x1EBB,
  1983. eibopomofo: 0x311F,
  1984. eight: 0x0038,
  1985. eightarabic: 0x0668,
  1986. eightbengali: 0x09EE,
  1987. eightcircle: 0x2467,
  1988. eightcircleinversesansserif: 0x2791,
  1989. eightdeva: 0x096E,
  1990. eighteencircle: 0x2471,
  1991. eighteenparen: 0x2485,
  1992. eighteenperiod: 0x2499,
  1993. eightgujarati: 0x0AEE,
  1994. eightgurmukhi: 0x0A6E,
  1995. eighthackarabic: 0x0668,
  1996. eighthangzhou: 0x3028,
  1997. eighthnotebeamed: 0x266B,
  1998. eightideographicparen: 0x3227,
  1999. eightinferior: 0x2088,
  2000. eightmonospace: 0xFF18,
  2001. eightoldstyle: 0xF738,
  2002. eightparen: 0x247B,
  2003. eightperiod: 0x248F,
  2004. eightpersian: 0x06F8,
  2005. eightroman: 0x2177,
  2006. eightsuperior: 0x2078,
  2007. eightthai: 0x0E58,
  2008. einvertedbreve: 0x0207,
  2009. eiotifiedcyrillic: 0x0465,
  2010. ekatakana: 0x30A8,
  2011. ekatakanahalfwidth: 0xFF74,
  2012. ekonkargurmukhi: 0x0A74,
  2013. ekorean: 0x3154,
  2014. elcyrillic: 0x043B,
  2015. element: 0x2208,
  2016. elevencircle: 0x246A,
  2017. elevenparen: 0x247E,
  2018. elevenperiod: 0x2492,
  2019. elevenroman: 0x217A,
  2020. ellipsis: 0x2026,
  2021. ellipsisvertical: 0x22EE,
  2022. emacron: 0x0113,
  2023. emacronacute: 0x1E17,
  2024. emacrongrave: 0x1E15,
  2025. emcyrillic: 0x043C,
  2026. emdash: 0x2014,
  2027. emdashvertical: 0xFE31,
  2028. emonospace: 0xFF45,
  2029. emphasismarkarmenian: 0x055B,
  2030. emptyset: 0x2205,
  2031. enbopomofo: 0x3123,
  2032. encyrillic: 0x043D,
  2033. endash: 0x2013,
  2034. endashvertical: 0xFE32,
  2035. endescendercyrillic: 0x04A3,
  2036. eng: 0x014B,
  2037. engbopomofo: 0x3125,
  2038. enghecyrillic: 0x04A5,
  2039. enhookcyrillic: 0x04C8,
  2040. enspace: 0x2002,
  2041. eogonek: 0x0119,
  2042. eokorean: 0x3153,
  2043. eopen: 0x025B,
  2044. eopenclosed: 0x029A,
  2045. eopenreversed: 0x025C,
  2046. eopenreversedclosed: 0x025E,
  2047. eopenreversedhook: 0x025D,
  2048. eparen: 0x24A0,
  2049. epsilon: 0x03B5,
  2050. epsilontonos: 0x03AD,
  2051. equal: 0x003D,
  2052. equalmonospace: 0xFF1D,
  2053. equalsmall: 0xFE66,
  2054. equalsuperior: 0x207C,
  2055. equivalence: 0x2261,
  2056. erbopomofo: 0x3126,
  2057. ercyrillic: 0x0440,
  2058. ereversed: 0x0258,
  2059. ereversedcyrillic: 0x044D,
  2060. escyrillic: 0x0441,
  2061. esdescendercyrillic: 0x04AB,
  2062. esh: 0x0283,
  2063. eshcurl: 0x0286,
  2064. eshortdeva: 0x090E,
  2065. eshortvowelsigndeva: 0x0946,
  2066. eshreversedloop: 0x01AA,
  2067. eshsquatreversed: 0x0285,
  2068. esmallhiragana: 0x3047,
  2069. esmallkatakana: 0x30A7,
  2070. esmallkatakanahalfwidth: 0xFF6A,
  2071. estimated: 0x212E,
  2072. esuperior: 0xF6EC,
  2073. eta: 0x03B7,
  2074. etarmenian: 0x0568,
  2075. etatonos: 0x03AE,
  2076. eth: 0x00F0,
  2077. etilde: 0x1EBD,
  2078. etildebelow: 0x1E1B,
  2079. etnahtafoukhhebrew: 0x0591,
  2080. etnahtafoukhlefthebrew: 0x0591,
  2081. etnahtahebrew: 0x0591,
  2082. etnahtalefthebrew: 0x0591,
  2083. eturned: 0x01DD,
  2084. eukorean: 0x3161,
  2085. euro: 0x20AC,
  2086. evowelsignbengali: 0x09C7,
  2087. evowelsigndeva: 0x0947,
  2088. evowelsigngujarati: 0x0AC7,
  2089. exclam: 0x0021,
  2090. exclamarmenian: 0x055C,
  2091. exclamdbl: 0x203C,
  2092. exclamdown: 0x00A1,
  2093. exclamdownsmall: 0xF7A1,
  2094. exclammonospace: 0xFF01,
  2095. exclamsmall: 0xF721,
  2096. existential: 0x2203,
  2097. ezh: 0x0292,
  2098. ezhcaron: 0x01EF,
  2099. ezhcurl: 0x0293,
  2100. ezhreversed: 0x01B9,
  2101. ezhtail: 0x01BA,
  2102. f: 0x0066,
  2103. fadeva: 0x095E,
  2104. fagurmukhi: 0x0A5E,
  2105. fahrenheit: 0x2109,
  2106. fathaarabic: 0x064E,
  2107. fathalowarabic: 0x064E,
  2108. fathatanarabic: 0x064B,
  2109. fbopomofo: 0x3108,
  2110. fcircle: 0x24D5,
  2111. fdotaccent: 0x1E1F,
  2112. feharabic: 0x0641,
  2113. feharmenian: 0x0586,
  2114. fehfinalarabic: 0xFED2,
  2115. fehinitialarabic: 0xFED3,
  2116. fehmedialarabic: 0xFED4,
  2117. feicoptic: 0x03E5,
  2118. female: 0x2640,
  2119. ff: 0xFB00,
  2120. ffi: 0xFB03,
  2121. ffl: 0xFB04,
  2122. fi: 0xFB01,
  2123. fifteencircle: 0x246E,
  2124. fifteenparen: 0x2482,
  2125. fifteenperiod: 0x2496,
  2126. figuredash: 0x2012,
  2127. filledbox: 0x25A0,
  2128. filledrect: 0x25AC,
  2129. finalkaf: 0x05DA,
  2130. finalkafdagesh: 0xFB3A,
  2131. finalkafdageshhebrew: 0xFB3A,
  2132. finalkafhebrew: 0x05DA,
  2133. finalmem: 0x05DD,
  2134. finalmemhebrew: 0x05DD,
  2135. finalnun: 0x05DF,
  2136. finalnunhebrew: 0x05DF,
  2137. finalpe: 0x05E3,
  2138. finalpehebrew: 0x05E3,
  2139. finaltsadi: 0x05E5,
  2140. finaltsadihebrew: 0x05E5,
  2141. firsttonechinese: 0x02C9,
  2142. fisheye: 0x25C9,
  2143. fitacyrillic: 0x0473,
  2144. five: 0x0035,
  2145. fivearabic: 0x0665,
  2146. fivebengali: 0x09EB,
  2147. fivecircle: 0x2464,
  2148. fivecircleinversesansserif: 0x278E,
  2149. fivedeva: 0x096B,
  2150. fiveeighths: 0x215D,
  2151. fivegujarati: 0x0AEB,
  2152. fivegurmukhi: 0x0A6B,
  2153. fivehackarabic: 0x0665,
  2154. fivehangzhou: 0x3025,
  2155. fiveideographicparen: 0x3224,
  2156. fiveinferior: 0x2085,
  2157. fivemonospace: 0xFF15,
  2158. fiveoldstyle: 0xF735,
  2159. fiveparen: 0x2478,
  2160. fiveperiod: 0x248C,
  2161. fivepersian: 0x06F5,
  2162. fiveroman: 0x2174,
  2163. fivesuperior: 0x2075,
  2164. fivethai: 0x0E55,
  2165. fl: 0xFB02,
  2166. florin: 0x0192,
  2167. fmonospace: 0xFF46,
  2168. fmsquare: 0x3399,
  2169. fofanthai: 0x0E1F,
  2170. fofathai: 0x0E1D,
  2171. fongmanthai: 0x0E4F,
  2172. forall: 0x2200,
  2173. four: 0x0034,
  2174. fourarabic: 0x0664,
  2175. fourbengali: 0x09EA,
  2176. fourcircle: 0x2463,
  2177. fourcircleinversesansserif: 0x278D,
  2178. fourdeva: 0x096A,
  2179. fourgujarati: 0x0AEA,
  2180. fourgurmukhi: 0x0A6A,
  2181. fourhackarabic: 0x0664,
  2182. fourhangzhou: 0x3024,
  2183. fourideographicparen: 0x3223,
  2184. fourinferior: 0x2084,
  2185. fourmonospace: 0xFF14,
  2186. fournumeratorbengali: 0x09F7,
  2187. fouroldstyle: 0xF734,
  2188. fourparen: 0x2477,
  2189. fourperiod: 0x248B,
  2190. fourpersian: 0x06F4,
  2191. fourroman: 0x2173,
  2192. foursuperior: 0x2074,
  2193. fourteencircle: 0x246D,
  2194. fourteenparen: 0x2481,
  2195. fourteenperiod: 0x2495,
  2196. fourthai: 0x0E54,
  2197. fourthtonechinese: 0x02CB,
  2198. fparen: 0x24A1,
  2199. fraction: 0x2044,
  2200. franc: 0x20A3,
  2201. g: 0x0067,
  2202. gabengali: 0x0997,
  2203. gacute: 0x01F5,
  2204. gadeva: 0x0917,
  2205. gafarabic: 0x06AF,
  2206. gaffinalarabic: 0xFB93,
  2207. gafinitialarabic: 0xFB94,
  2208. gafmedialarabic: 0xFB95,
  2209. gagujarati: 0x0A97,
  2210. gagurmukhi: 0x0A17,
  2211. gahiragana: 0x304C,
  2212. gakatakana: 0x30AC,
  2213. gamma: 0x03B3,
  2214. gammalatinsmall: 0x0263,
  2215. gammasuperior: 0x02E0,
  2216. gangiacoptic: 0x03EB,
  2217. gbopomofo: 0x310D,
  2218. gbreve: 0x011F,
  2219. gcaron: 0x01E7,
  2220. gcedilla: 0x0123,
  2221. gcircle: 0x24D6,
  2222. gcircumflex: 0x011D,
  2223. gcommaaccent: 0x0123,
  2224. gdot: 0x0121,
  2225. gdotaccent: 0x0121,
  2226. gecyrillic: 0x0433,
  2227. gehiragana: 0x3052,
  2228. gekatakana: 0x30B2,
  2229. geometricallyequal: 0x2251,
  2230. gereshaccenthebrew: 0x059C,
  2231. gereshhebrew: 0x05F3,
  2232. gereshmuqdamhebrew: 0x059D,
  2233. germandbls: 0x00DF,
  2234. gershayimaccenthebrew: 0x059E,
  2235. gershayimhebrew: 0x05F4,
  2236. getamark: 0x3013,
  2237. ghabengali: 0x0998,
  2238. ghadarmenian: 0x0572,
  2239. ghadeva: 0x0918,
  2240. ghagujarati: 0x0A98,
  2241. ghagurmukhi: 0x0A18,
  2242. ghainarabic: 0x063A,
  2243. ghainfinalarabic: 0xFECE,
  2244. ghaininitialarabic: 0xFECF,
  2245. ghainmedialarabic: 0xFED0,
  2246. ghemiddlehookcyrillic: 0x0495,
  2247. ghestrokecyrillic: 0x0493,
  2248. gheupturncyrillic: 0x0491,
  2249. ghhadeva: 0x095A,
  2250. ghhagurmukhi: 0x0A5A,
  2251. ghook: 0x0260,
  2252. ghzsquare: 0x3393,
  2253. gihiragana: 0x304E,
  2254. gikatakana: 0x30AE,
  2255. gimarmenian: 0x0563,
  2256. gimel: 0x05D2,
  2257. gimeldagesh: 0xFB32,
  2258. gimeldageshhebrew: 0xFB32,
  2259. gimelhebrew: 0x05D2,
  2260. gjecyrillic: 0x0453,
  2261. glottalinvertedstroke: 0x01BE,
  2262. glottalstop: 0x0294,
  2263. glottalstopinverted: 0x0296,
  2264. glottalstopmod: 0x02C0,
  2265. glottalstopreversed: 0x0295,
  2266. glottalstopreversedmod: 0x02C1,
  2267. glottalstopreversedsuperior: 0x02E4,
  2268. glottalstopstroke: 0x02A1,
  2269. glottalstopstrokereversed: 0x02A2,
  2270. gmacron: 0x1E21,
  2271. gmonospace: 0xFF47,
  2272. gohiragana: 0x3054,
  2273. gokatakana: 0x30B4,
  2274. gparen: 0x24A2,
  2275. gpasquare: 0x33AC,
  2276. gradient: 0x2207,
  2277. grave: 0x0060,
  2278. gravebelowcmb: 0x0316,
  2279. gravecmb: 0x0300,
  2280. gravecomb: 0x0300,
  2281. gravedeva: 0x0953,
  2282. gravelowmod: 0x02CE,
  2283. gravemonospace: 0xFF40,
  2284. gravetonecmb: 0x0340,
  2285. greater: 0x003E,
  2286. greaterequal: 0x2265,
  2287. greaterequalorless: 0x22DB,
  2288. greatermonospace: 0xFF1E,
  2289. greaterorequivalent: 0x2273,
  2290. greaterorless: 0x2277,
  2291. greateroverequal: 0x2267,
  2292. greatersmall: 0xFE65,
  2293. gscript: 0x0261,
  2294. gstroke: 0x01E5,
  2295. guhiragana: 0x3050,
  2296. guillemotleft: 0x00AB,
  2297. guillemotright: 0x00BB,
  2298. guilsinglleft: 0x2039,
  2299. guilsinglright: 0x203A,
  2300. gukatakana: 0x30B0,
  2301. guramusquare: 0x3318,
  2302. gysquare: 0x33C9,
  2303. h: 0x0068,
  2304. haabkhasiancyrillic: 0x04A9,
  2305. haaltonearabic: 0x06C1,
  2306. habengali: 0x09B9,
  2307. hadescendercyrillic: 0x04B3,
  2308. hadeva: 0x0939,
  2309. hagujarati: 0x0AB9,
  2310. hagurmukhi: 0x0A39,
  2311. haharabic: 0x062D,
  2312. hahfinalarabic: 0xFEA2,
  2313. hahinitialarabic: 0xFEA3,
  2314. hahiragana: 0x306F,
  2315. hahmedialarabic: 0xFEA4,
  2316. haitusquare: 0x332A,
  2317. hakatakana: 0x30CF,
  2318. hakatakanahalfwidth: 0xFF8A,
  2319. halantgurmukhi: 0x0A4D,
  2320. hamzaarabic: 0x0621,
  2321. hamzalowarabic: 0x0621,
  2322. hangulfiller: 0x3164,
  2323. hardsigncyrillic: 0x044A,
  2324. harpoonleftbarbup: 0x21BC,
  2325. harpoonrightbarbup: 0x21C0,
  2326. hasquare: 0x33CA,
  2327. hatafpatah: 0x05B2,
  2328. hatafpatah16: 0x05B2,
  2329. hatafpatah23: 0x05B2,
  2330. hatafpatah2f: 0x05B2,
  2331. hatafpatahhebrew: 0x05B2,
  2332. hatafpatahnarrowhebrew: 0x05B2,
  2333. hatafpatahquarterhebrew: 0x05B2,
  2334. hatafpatahwidehebrew: 0x05B2,
  2335. hatafqamats: 0x05B3,
  2336. hatafqamats1b: 0x05B3,
  2337. hatafqamats28: 0x05B3,
  2338. hatafqamats34: 0x05B3,
  2339. hatafqamatshebrew: 0x05B3,
  2340. hatafqamatsnarrowhebrew: 0x05B3,
  2341. hatafqamatsquarterhebrew: 0x05B3,
  2342. hatafqamatswidehebrew: 0x05B3,
  2343. hatafsegol: 0x05B1,
  2344. hatafsegol17: 0x05B1,
  2345. hatafsegol24: 0x05B1,
  2346. hatafsegol30: 0x05B1,
  2347. hatafsegolhebrew: 0x05B1,
  2348. hatafsegolnarrowhebrew: 0x05B1,
  2349. hatafsegolquarterhebrew: 0x05B1,
  2350. hatafsegolwidehebrew: 0x05B1,
  2351. hbar: 0x0127,
  2352. hbopomofo: 0x310F,
  2353. hbrevebelow: 0x1E2B,
  2354. hcedilla: 0x1E29,
  2355. hcircle: 0x24D7,
  2356. hcircumflex: 0x0125,
  2357. hdieresis: 0x1E27,
  2358. hdotaccent: 0x1E23,
  2359. hdotbelow: 0x1E25,
  2360. he: 0x05D4,
  2361. heart: 0x2665,
  2362. heartsuitblack: 0x2665,
  2363. heartsuitwhite: 0x2661,
  2364. hedagesh: 0xFB34,
  2365. hedageshhebrew: 0xFB34,
  2366. hehaltonearabic: 0x06C1,
  2367. heharabic: 0x0647,
  2368. hehebrew: 0x05D4,
  2369. hehfinalaltonearabic: 0xFBA7,
  2370. hehfinalalttwoarabic: 0xFEEA,
  2371. hehfinalarabic: 0xFEEA,
  2372. hehhamzaabovefinalarabic: 0xFBA5,
  2373. hehhamzaaboveisolatedarabic: 0xFBA4,
  2374. hehinitialaltonearabic: 0xFBA8,
  2375. hehinitialarabic: 0xFEEB,
  2376. hehiragana: 0x3078,
  2377. hehmedialaltonearabic: 0xFBA9,
  2378. hehmedialarabic: 0xFEEC,
  2379. heiseierasquare: 0x337B,
  2380. hekatakana: 0x30D8,
  2381. hekatakanahalfwidth: 0xFF8D,
  2382. hekutaarusquare: 0x3336,
  2383. henghook: 0x0267,
  2384. herutusquare: 0x3339,
  2385. het: 0x05D7,
  2386. hethebrew: 0x05D7,
  2387. hhook: 0x0266,
  2388. hhooksuperior: 0x02B1,
  2389. hieuhacirclekorean: 0x327B,
  2390. hieuhaparenkorean: 0x321B,
  2391. hieuhcirclekorean: 0x326D,
  2392. hieuhkorean: 0x314E,
  2393. hieuhparenkorean: 0x320D,
  2394. hihiragana: 0x3072,
  2395. hikatakana: 0x30D2,
  2396. hikatakanahalfwidth: 0xFF8B,
  2397. hiriq: 0x05B4,
  2398. hiriq14: 0x05B4,
  2399. hiriq21: 0x05B4,
  2400. hiriq2d: 0x05B4,
  2401. hiriqhebrew: 0x05B4,
  2402. hiriqnarrowhebrew: 0x05B4,
  2403. hiriqquarterhebrew: 0x05B4,
  2404. hiriqwidehebrew: 0x05B4,
  2405. hlinebelow: 0x1E96,
  2406. hmonospace: 0xFF48,
  2407. hoarmenian: 0x0570,
  2408. hohipthai: 0x0E2B,
  2409. hohiragana: 0x307B,
  2410. hokatakana: 0x30DB,
  2411. hokatakanahalfwidth: 0xFF8E,
  2412. holam: 0x05B9,
  2413. holam19: 0x05B9,
  2414. holam26: 0x05B9,
  2415. holam32: 0x05B9,
  2416. holamhebrew: 0x05B9,
  2417. holamnarrowhebrew: 0x05B9,
  2418. holamquarterhebrew: 0x05B9,
  2419. holamwidehebrew: 0x05B9,
  2420. honokhukthai: 0x0E2E,
  2421. hookabovecomb: 0x0309,
  2422. hookcmb: 0x0309,
  2423. hookpalatalizedbelowcmb: 0x0321,
  2424. hookretroflexbelowcmb: 0x0322,
  2425. hoonsquare: 0x3342,
  2426. horicoptic: 0x03E9,
  2427. horizontalbar: 0x2015,
  2428. horncmb: 0x031B,
  2429. hotsprings: 0x2668,
  2430. house: 0x2302,
  2431. hparen: 0x24A3,
  2432. hsuperior: 0x02B0,
  2433. hturned: 0x0265,
  2434. huhiragana: 0x3075,
  2435. huiitosquare: 0x3333,
  2436. hukatakana: 0x30D5,
  2437. hukatakanahalfwidth: 0xFF8C,
  2438. hungarumlaut: 0x02DD,
  2439. hungarumlautcmb: 0x030B,
  2440. hv: 0x0195,
  2441. hyphen: 0x002D,
  2442. hypheninferior: 0xF6E5,
  2443. hyphenmonospace: 0xFF0D,
  2444. hyphensmall: 0xFE63,
  2445. hyphensuperior: 0xF6E6,
  2446. hyphentwo: 0x2010,
  2447. i: 0x0069,
  2448. iacute: 0x00ED,
  2449. iacyrillic: 0x044F,
  2450. ibengali: 0x0987,
  2451. ibopomofo: 0x3127,
  2452. ibreve: 0x012D,
  2453. icaron: 0x01D0,
  2454. icircle: 0x24D8,
  2455. icircumflex: 0x00EE,
  2456. icyrillic: 0x0456,
  2457. idblgrave: 0x0209,
  2458. ideographearthcircle: 0x328F,
  2459. ideographfirecircle: 0x328B,
  2460. ideographicallianceparen: 0x323F,
  2461. ideographiccallparen: 0x323A,
  2462. ideographiccentrecircle: 0x32A5,
  2463. ideographicclose: 0x3006,
  2464. ideographiccomma: 0x3001,
  2465. ideographiccommaleft: 0xFF64,
  2466. ideographiccongratulationparen: 0x3237,
  2467. ideographiccorrectcircle: 0x32A3,
  2468. ideographicearthparen: 0x322F,
  2469. ideographicenterpriseparen: 0x323D,
  2470. ideographicexcellentcircle: 0x329D,
  2471. ideographicfestivalparen: 0x3240,
  2472. ideographicfinancialcircle: 0x3296,
  2473. ideographicfinancialparen: 0x3236,
  2474. ideographicfireparen: 0x322B,
  2475. ideographichaveparen: 0x3232,
  2476. ideographichighcircle: 0x32A4,
  2477. ideographiciterationmark: 0x3005,
  2478. ideographiclaborcircle: 0x3298,
  2479. ideographiclaborparen: 0x3238,
  2480. ideographicleftcircle: 0x32A7,
  2481. ideographiclowcircle: 0x32A6,
  2482. ideographicmedicinecircle: 0x32A9,
  2483. ideographicmetalparen: 0x322E,
  2484. ideographicmoonparen: 0x322A,
  2485. ideographicnameparen: 0x3234,
  2486. ideographicperiod: 0x3002,
  2487. ideographicprintcircle: 0x329E,
  2488. ideographicreachparen: 0x3243,
  2489. ideographicrepresentparen: 0x3239,
  2490. ideographicresourceparen: 0x323E,
  2491. ideographicrightcircle: 0x32A8,
  2492. ideographicsecretcircle: 0x3299,
  2493. ideographicselfparen: 0x3242,
  2494. ideographicsocietyparen: 0x3233,
  2495. ideographicspace: 0x3000,
  2496. ideographicspecialparen: 0x3235,
  2497. ideographicstockparen: 0x3231,
  2498. ideographicstudyparen: 0x323B,
  2499. ideographicsunparen: 0x3230,
  2500. ideographicsuperviseparen: 0x323C,
  2501. ideographicwaterparen: 0x322C,
  2502. ideographicwoodparen: 0x322D,
  2503. ideographiczero: 0x3007,
  2504. ideographmetalcircle: 0x328E,
  2505. ideographmooncircle: 0x328A,
  2506. ideographnamecircle: 0x3294,
  2507. ideographsuncircle: 0x3290,
  2508. ideographwatercircle: 0x328C,
  2509. ideographwoodcircle: 0x328D,
  2510. ideva: 0x0907,
  2511. idieresis: 0x00EF,
  2512. idieresisacute: 0x1E2F,
  2513. idieresiscyrillic: 0x04E5,
  2514. idotbelow: 0x1ECB,
  2515. iebrevecyrillic: 0x04D7,
  2516. iecyrillic: 0x0435,
  2517. ieungacirclekorean: 0x3275,
  2518. ieungaparenkorean: 0x3215,
  2519. ieungcirclekorean: 0x3267,
  2520. ieungkorean: 0x3147,
  2521. ieungparenkorean: 0x3207,
  2522. igrave: 0x00EC,
  2523. igujarati: 0x0A87,
  2524. igurmukhi: 0x0A07,
  2525. ihiragana: 0x3044,
  2526. ihookabove: 0x1EC9,
  2527. iibengali: 0x0988,
  2528. iicyrillic: 0x0438,
  2529. iideva: 0x0908,
  2530. iigujarati: 0x0A88,
  2531. iigurmukhi: 0x0A08,
  2532. iimatragurmukhi: 0x0A40,
  2533. iinvertedbreve: 0x020B,
  2534. iishortcyrillic: 0x0439,
  2535. iivowelsignbengali: 0x09C0,
  2536. iivowelsigndeva: 0x0940,
  2537. iivowelsigngujarati: 0x0AC0,
  2538. ij: 0x0133,
  2539. ikatakana: 0x30A4,
  2540. ikatakanahalfwidth: 0xFF72,
  2541. ikorean: 0x3163,
  2542. ilde: 0x02DC,
  2543. iluyhebrew: 0x05AC,
  2544. imacron: 0x012B,
  2545. imacroncyrillic: 0x04E3,
  2546. imageorapproximatelyequal: 0x2253,
  2547. imatragurmukhi: 0x0A3F,
  2548. imonospace: 0xFF49,
  2549. increment: 0x2206,
  2550. infinity: 0x221E,
  2551. iniarmenian: 0x056B,
  2552. integral: 0x222B,
  2553. integralbottom: 0x2321,
  2554. integralbt: 0x2321,
  2555. integralex: 0xF8F5,
  2556. integraltop: 0x2320,
  2557. integraltp: 0x2320,
  2558. intersection: 0x2229,
  2559. intisquare: 0x3305,
  2560. invbullet: 0x25D8,
  2561. invcircle: 0x25D9,
  2562. invsmileface: 0x263B,
  2563. iocyrillic: 0x0451,
  2564. iogonek: 0x012F,
  2565. iota: 0x03B9,
  2566. iotadieresis: 0x03CA,
  2567. iotadieresistonos: 0x0390,
  2568. iotalatin: 0x0269,
  2569. iotatonos: 0x03AF,
  2570. iparen: 0x24A4,
  2571. irigurmukhi: 0x0A72,
  2572. ismallhiragana: 0x3043,
  2573. ismallkatakana: 0x30A3,
  2574. ismallkatakanahalfwidth: 0xFF68,
  2575. issharbengali: 0x09FA,
  2576. istroke: 0x0268,
  2577. isuperior: 0xF6ED,
  2578. iterationhiragana: 0x309D,
  2579. iterationkatakana: 0x30FD,
  2580. itilde: 0x0129,
  2581. itildebelow: 0x1E2D,
  2582. iubopomofo: 0x3129,
  2583. iucyrillic: 0x044E,
  2584. ivowelsignbengali: 0x09BF,
  2585. ivowelsigndeva: 0x093F,
  2586. ivowelsigngujarati: 0x0ABF,
  2587. izhitsacyrillic: 0x0475,
  2588. izhitsadblgravecyrillic: 0x0477,
  2589. j: 0x006A,
  2590. jaarmenian: 0x0571,
  2591. jabengali: 0x099C,
  2592. jadeva: 0x091C,
  2593. jagujarati: 0x0A9C,
  2594. jagurmukhi: 0x0A1C,
  2595. jbopomofo: 0x3110,
  2596. jcaron: 0x01F0,
  2597. jcircle: 0x24D9,
  2598. jcircumflex: 0x0135,
  2599. jcrossedtail: 0x029D,
  2600. jdotlessstroke: 0x025F,
  2601. jecyrillic: 0x0458,
  2602. jeemarabic: 0x062C,
  2603. jeemfinalarabic: 0xFE9E,
  2604. jeeminitialarabic: 0xFE9F,
  2605. jeemmedialarabic: 0xFEA0,
  2606. jeharabic: 0x0698,
  2607. jehfinalarabic: 0xFB8B,
  2608. jhabengali: 0x099D,
  2609. jhadeva: 0x091D,
  2610. jhagujarati: 0x0A9D,
  2611. jhagurmukhi: 0x0A1D,
  2612. jheharmenian: 0x057B,
  2613. jis: 0x3004,
  2614. jmonospace: 0xFF4A,
  2615. jparen: 0x24A5,
  2616. jsuperior: 0x02B2,
  2617. k: 0x006B,
  2618. kabashkircyrillic: 0x04A1,
  2619. kabengali: 0x0995,
  2620. kacute: 0x1E31,
  2621. kacyrillic: 0x043A,
  2622. kadescendercyrillic: 0x049B,
  2623. kadeva: 0x0915,
  2624. kaf: 0x05DB,
  2625. kafarabic: 0x0643,
  2626. kafdagesh: 0xFB3B,
  2627. kafdageshhebrew: 0xFB3B,
  2628. kaffinalarabic: 0xFEDA,
  2629. kafhebrew: 0x05DB,
  2630. kafinitialarabic: 0xFEDB,
  2631. kafmedialarabic: 0xFEDC,
  2632. kafrafehebrew: 0xFB4D,
  2633. kagujarati: 0x0A95,
  2634. kagurmukhi: 0x0A15,
  2635. kahiragana: 0x304B,
  2636. kahookcyrillic: 0x04C4,
  2637. kakatakana: 0x30AB,
  2638. kakatakanahalfwidth: 0xFF76,
  2639. kappa: 0x03BA,
  2640. kappasymbolgreek: 0x03F0,
  2641. kapyeounmieumkorean: 0x3171,
  2642. kapyeounphieuphkorean: 0x3184,
  2643. kapyeounpieupkorean: 0x3178,
  2644. kapyeounssangpieupkorean: 0x3179,
  2645. karoriisquare: 0x330D,
  2646. kashidaautoarabic: 0x0640,
  2647. kashidaautonosidebearingarabic: 0x0640,
  2648. kasmallkatakana: 0x30F5,
  2649. kasquare: 0x3384,
  2650. kasraarabic: 0x0650,
  2651. kasratanarabic: 0x064D,
  2652. kastrokecyrillic: 0x049F,
  2653. katahiraprolongmarkhalfwidth: 0xFF70,
  2654. kaverticalstrokecyrillic: 0x049D,
  2655. kbopomofo: 0x310E,
  2656. kcalsquare: 0x3389,
  2657. kcaron: 0x01E9,
  2658. kcedilla: 0x0137,
  2659. kcircle: 0x24DA,
  2660. kcommaaccent: 0x0137,
  2661. kdotbelow: 0x1E33,
  2662. keharmenian: 0x0584,
  2663. kehiragana: 0x3051,
  2664. kekatakana: 0x30B1,
  2665. kekatakanahalfwidth: 0xFF79,
  2666. kenarmenian: 0x056F,
  2667. kesmallkatakana: 0x30F6,
  2668. kgreenlandic: 0x0138,
  2669. khabengali: 0x0996,
  2670. khacyrillic: 0x0445,
  2671. khadeva: 0x0916,
  2672. khagujarati: 0x0A96,
  2673. khagurmukhi: 0x0A16,
  2674. khaharabic: 0x062E,
  2675. khahfinalarabic: 0xFEA6,
  2676. khahinitialarabic: 0xFEA7,
  2677. khahmedialarabic: 0xFEA8,
  2678. kheicoptic: 0x03E7,
  2679. khhadeva: 0x0959,
  2680. khhagurmukhi: 0x0A59,
  2681. khieukhacirclekorean: 0x3278,
  2682. khieukhaparenkorean: 0x3218,
  2683. khieukhcirclekorean: 0x326A,
  2684. khieukhkorean: 0x314B,
  2685. khieukhparenkorean: 0x320A,
  2686. khokhaithai: 0x0E02,
  2687. khokhonthai: 0x0E05,
  2688. khokhuatthai: 0x0E03,
  2689. khokhwaithai: 0x0E04,
  2690. khomutthai: 0x0E5B,
  2691. khook: 0x0199,
  2692. khorakhangthai: 0x0E06,
  2693. khzsquare: 0x3391,
  2694. kihiragana: 0x304D,
  2695. kikatakana: 0x30AD,
  2696. kikatakanahalfwidth: 0xFF77,
  2697. kiroguramusquare: 0x3315,
  2698. kiromeetorusquare: 0x3316,
  2699. kirosquare: 0x3314,
  2700. kiyeokacirclekorean: 0x326E,
  2701. kiyeokaparenkorean: 0x320E,
  2702. kiyeokcirclekorean: 0x3260,
  2703. kiyeokkorean: 0x3131,
  2704. kiyeokparenkorean: 0x3200,
  2705. kiyeoksioskorean: 0x3133,
  2706. kjecyrillic: 0x045C,
  2707. klinebelow: 0x1E35,
  2708. klsquare: 0x3398,
  2709. kmcubedsquare: 0x33A6,
  2710. kmonospace: 0xFF4B,
  2711. kmsquaredsquare: 0x33A2,
  2712. kohiragana: 0x3053,
  2713. kohmsquare: 0x33C0,
  2714. kokaithai: 0x0E01,
  2715. kokatakana: 0x30B3,
  2716. kokatakanahalfwidth: 0xFF7A,
  2717. kooposquare: 0x331E,
  2718. koppacyrillic: 0x0481,
  2719. koreanstandardsymbol: 0x327F,
  2720. koroniscmb: 0x0343,
  2721. kparen: 0x24A6,
  2722. kpasquare: 0x33AA,
  2723. ksicyrillic: 0x046F,
  2724. ktsquare: 0x33CF,
  2725. kturned: 0x029E,
  2726. kuhiragana: 0x304F,
  2727. kukatakana: 0x30AF,
  2728. kukatakanahalfwidth: 0xFF78,
  2729. kvsquare: 0x33B8,
  2730. kwsquare: 0x33BE,
  2731. l: 0x006C,
  2732. labengali: 0x09B2,
  2733. lacute: 0x013A,
  2734. ladeva: 0x0932,
  2735. lagujarati: 0x0AB2,
  2736. lagurmukhi: 0x0A32,
  2737. lakkhangyaothai: 0x0E45,
  2738. lamaleffinalarabic: 0xFEFC,
  2739. lamalefhamzaabovefinalarabic: 0xFEF8,
  2740. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  2741. lamalefhamzabelowfinalarabic: 0xFEFA,
  2742. lamalefhamzabelowisolatedarabic: 0xFEF9,
  2743. lamalefisolatedarabic: 0xFEFB,
  2744. lamalefmaddaabovefinalarabic: 0xFEF6,
  2745. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  2746. lamarabic: 0x0644,
  2747. lambda: 0x03BB,
  2748. lambdastroke: 0x019B,
  2749. lamed: 0x05DC,
  2750. lameddagesh: 0xFB3C,
  2751. lameddageshhebrew: 0xFB3C,
  2752. lamedhebrew: 0x05DC,
  2753. lamfinalarabic: 0xFEDE,
  2754. lamhahinitialarabic: 0xFCCA,
  2755. laminitialarabic: 0xFEDF,
  2756. lamjeeminitialarabic: 0xFCC9,
  2757. lamkhahinitialarabic: 0xFCCB,
  2758. lamlamhehisolatedarabic: 0xFDF2,
  2759. lammedialarabic: 0xFEE0,
  2760. lammeemhahinitialarabic: 0xFD88,
  2761. lammeeminitialarabic: 0xFCCC,
  2762. largecircle: 0x25EF,
  2763. lbar: 0x019A,
  2764. lbelt: 0x026C,
  2765. lbopomofo: 0x310C,
  2766. lcaron: 0x013E,
  2767. lcedilla: 0x013C,
  2768. lcircle: 0x24DB,
  2769. lcircumflexbelow: 0x1E3D,
  2770. lcommaaccent: 0x013C,
  2771. ldot: 0x0140,
  2772. ldotaccent: 0x0140,
  2773. ldotbelow: 0x1E37,
  2774. ldotbelowmacron: 0x1E39,
  2775. leftangleabovecmb: 0x031A,
  2776. lefttackbelowcmb: 0x0318,
  2777. less: 0x003C,
  2778. lessequal: 0x2264,
  2779. lessequalorgreater: 0x22DA,
  2780. lessmonospace: 0xFF1C,
  2781. lessorequivalent: 0x2272,
  2782. lessorgreater: 0x2276,
  2783. lessoverequal: 0x2266,
  2784. lesssmall: 0xFE64,
  2785. lezh: 0x026E,
  2786. lfblock: 0x258C,
  2787. lhookretroflex: 0x026D,
  2788. lira: 0x20A4,
  2789. liwnarmenian: 0x056C,
  2790. lj: 0x01C9,
  2791. ljecyrillic: 0x0459,
  2792. ll: 0xF6C0,
  2793. lladeva: 0x0933,
  2794. llagujarati: 0x0AB3,
  2795. llinebelow: 0x1E3B,
  2796. llladeva: 0x0934,
  2797. llvocalicbengali: 0x09E1,
  2798. llvocalicdeva: 0x0961,
  2799. llvocalicvowelsignbengali: 0x09E3,
  2800. llvocalicvowelsigndeva: 0x0963,
  2801. lmiddletilde: 0x026B,
  2802. lmonospace: 0xFF4C,
  2803. lmsquare: 0x33D0,
  2804. lochulathai: 0x0E2C,
  2805. logicaland: 0x2227,
  2806. logicalnot: 0x00AC,
  2807. logicalnotreversed: 0x2310,
  2808. logicalor: 0x2228,
  2809. lolingthai: 0x0E25,
  2810. longs: 0x017F,
  2811. lowlinecenterline: 0xFE4E,
  2812. lowlinecmb: 0x0332,
  2813. lowlinedashed: 0xFE4D,
  2814. lozenge: 0x25CA,
  2815. lparen: 0x24A7,
  2816. lslash: 0x0142,
  2817. lsquare: 0x2113,
  2818. lsuperior: 0xF6EE,
  2819. ltshade: 0x2591,
  2820. luthai: 0x0E26,
  2821. lvocalicbengali: 0x098C,
  2822. lvocalicdeva: 0x090C,
  2823. lvocalicvowelsignbengali: 0x09E2,
  2824. lvocalicvowelsigndeva: 0x0962,
  2825. lxsquare: 0x33D3,
  2826. m: 0x006D,
  2827. mabengali: 0x09AE,
  2828. macron: 0x00AF,
  2829. macronbelowcmb: 0x0331,
  2830. macroncmb: 0x0304,
  2831. macronlowmod: 0x02CD,
  2832. macronmonospace: 0xFFE3,
  2833. macute: 0x1E3F,
  2834. madeva: 0x092E,
  2835. magujarati: 0x0AAE,
  2836. magurmukhi: 0x0A2E,
  2837. mahapakhhebrew: 0x05A4,
  2838. mahapakhlefthebrew: 0x05A4,
  2839. mahiragana: 0x307E,
  2840. maichattawalowleftthai: 0xF895,
  2841. maichattawalowrightthai: 0xF894,
  2842. maichattawathai: 0x0E4B,
  2843. maichattawaupperleftthai: 0xF893,
  2844. maieklowleftthai: 0xF88C,
  2845. maieklowrightthai: 0xF88B,
  2846. maiekthai: 0x0E48,
  2847. maiekupperleftthai: 0xF88A,
  2848. maihanakatleftthai: 0xF884,
  2849. maihanakatthai: 0x0E31,
  2850. maitaikhuleftthai: 0xF889,
  2851. maitaikhuthai: 0x0E47,
  2852. maitholowleftthai: 0xF88F,
  2853. maitholowrightthai: 0xF88E,
  2854. maithothai: 0x0E49,
  2855. maithoupperleftthai: 0xF88D,
  2856. maitrilowleftthai: 0xF892,
  2857. maitrilowrightthai: 0xF891,
  2858. maitrithai: 0x0E4A,
  2859. maitriupperleftthai: 0xF890,
  2860. maiyamokthai: 0x0E46,
  2861. makatakana: 0x30DE,
  2862. makatakanahalfwidth: 0xFF8F,
  2863. male: 0x2642,
  2864. mansyonsquare: 0x3347,
  2865. maqafhebrew: 0x05BE,
  2866. mars: 0x2642,
  2867. masoracirclehebrew: 0x05AF,
  2868. masquare: 0x3383,
  2869. mbopomofo: 0x3107,
  2870. mbsquare: 0x33D4,
  2871. mcircle: 0x24DC,
  2872. mcubedsquare: 0x33A5,
  2873. mdotaccent: 0x1E41,
  2874. mdotbelow: 0x1E43,
  2875. meemarabic: 0x0645,
  2876. meemfinalarabic: 0xFEE2,
  2877. meeminitialarabic: 0xFEE3,
  2878. meemmedialarabic: 0xFEE4,
  2879. meemmeeminitialarabic: 0xFCD1,
  2880. meemmeemisolatedarabic: 0xFC48,
  2881. meetorusquare: 0x334D,
  2882. mehiragana: 0x3081,
  2883. meizierasquare: 0x337E,
  2884. mekatakana: 0x30E1,
  2885. mekatakanahalfwidth: 0xFF92,
  2886. mem: 0x05DE,
  2887. memdagesh: 0xFB3E,
  2888. memdageshhebrew: 0xFB3E,
  2889. memhebrew: 0x05DE,
  2890. menarmenian: 0x0574,
  2891. merkhahebrew: 0x05A5,
  2892. merkhakefulahebrew: 0x05A6,
  2893. merkhakefulalefthebrew: 0x05A6,
  2894. merkhalefthebrew: 0x05A5,
  2895. mhook: 0x0271,
  2896. mhzsquare: 0x3392,
  2897. middledotkatakanahalfwidth: 0xFF65,
  2898. middot: 0x00B7,
  2899. mieumacirclekorean: 0x3272,
  2900. mieumaparenkorean: 0x3212,
  2901. mieumcirclekorean: 0x3264,
  2902. mieumkorean: 0x3141,
  2903. mieumpansioskorean: 0x3170,
  2904. mieumparenkorean: 0x3204,
  2905. mieumpieupkorean: 0x316E,
  2906. mieumsioskorean: 0x316F,
  2907. mihiragana: 0x307F,
  2908. mikatakana: 0x30DF,
  2909. mikatakanahalfwidth: 0xFF90,
  2910. minus: 0x2212,
  2911. minusbelowcmb: 0x0320,
  2912. minuscircle: 0x2296,
  2913. minusmod: 0x02D7,
  2914. minusplus: 0x2213,
  2915. minute: 0x2032,
  2916. miribaarusquare: 0x334A,
  2917. mirisquare: 0x3349,
  2918. mlonglegturned: 0x0270,
  2919. mlsquare: 0x3396,
  2920. mmcubedsquare: 0x33A3,
  2921. mmonospace: 0xFF4D,
  2922. mmsquaredsquare: 0x339F,
  2923. mohiragana: 0x3082,
  2924. mohmsquare: 0x33C1,
  2925. mokatakana: 0x30E2,
  2926. mokatakanahalfwidth: 0xFF93,
  2927. molsquare: 0x33D6,
  2928. momathai: 0x0E21,
  2929. moverssquare: 0x33A7,
  2930. moverssquaredsquare: 0x33A8,
  2931. mparen: 0x24A8,
  2932. mpasquare: 0x33AB,
  2933. mssquare: 0x33B3,
  2934. msuperior: 0xF6EF,
  2935. mturned: 0x026F,
  2936. mu: 0x00B5,
  2937. mu1: 0x00B5,
  2938. muasquare: 0x3382,
  2939. muchgreater: 0x226B,
  2940. muchless: 0x226A,
  2941. mufsquare: 0x338C,
  2942. mugreek: 0x03BC,
  2943. mugsquare: 0x338D,
  2944. muhiragana: 0x3080,
  2945. mukatakana: 0x30E0,
  2946. mukatakanahalfwidth: 0xFF91,
  2947. mulsquare: 0x3395,
  2948. multiply: 0x00D7,
  2949. mumsquare: 0x339B,
  2950. munahhebrew: 0x05A3,
  2951. munahlefthebrew: 0x05A3,
  2952. musicalnote: 0x266A,
  2953. musicalnotedbl: 0x266B,
  2954. musicflatsign: 0x266D,
  2955. musicsharpsign: 0x266F,
  2956. mussquare: 0x33B2,
  2957. muvsquare: 0x33B6,
  2958. muwsquare: 0x33BC,
  2959. mvmegasquare: 0x33B9,
  2960. mvsquare: 0x33B7,
  2961. mwmegasquare: 0x33BF,
  2962. mwsquare: 0x33BD,
  2963. n: 0x006E,
  2964. nabengali: 0x09A8,
  2965. nabla: 0x2207,
  2966. nacute: 0x0144,
  2967. nadeva: 0x0928,
  2968. nagujarati: 0x0AA8,
  2969. nagurmukhi: 0x0A28,
  2970. nahiragana: 0x306A,
  2971. nakatakana: 0x30CA,
  2972. nakatakanahalfwidth: 0xFF85,
  2973. napostrophe: 0x0149,
  2974. nasquare: 0x3381,
  2975. nbopomofo: 0x310B,
  2976. nbspace: 0x00A0,
  2977. ncaron: 0x0148,
  2978. ncedilla: 0x0146,
  2979. ncircle: 0x24DD,
  2980. ncircumflexbelow: 0x1E4B,
  2981. ncommaaccent: 0x0146,
  2982. ndotaccent: 0x1E45,
  2983. ndotbelow: 0x1E47,
  2984. nehiragana: 0x306D,
  2985. nekatakana: 0x30CD,
  2986. nekatakanahalfwidth: 0xFF88,
  2987. newsheqelsign: 0x20AA,
  2988. nfsquare: 0x338B,
  2989. ngabengali: 0x0999,
  2990. ngadeva: 0x0919,
  2991. ngagujarati: 0x0A99,
  2992. ngagurmukhi: 0x0A19,
  2993. ngonguthai: 0x0E07,
  2994. nhiragana: 0x3093,
  2995. nhookleft: 0x0272,
  2996. nhookretroflex: 0x0273,
  2997. nieunacirclekorean: 0x326F,
  2998. nieunaparenkorean: 0x320F,
  2999. nieuncieuckorean: 0x3135,
  3000. nieuncirclekorean: 0x3261,
  3001. nieunhieuhkorean: 0x3136,
  3002. nieunkorean: 0x3134,
  3003. nieunpansioskorean: 0x3168,
  3004. nieunparenkorean: 0x3201,
  3005. nieunsioskorean: 0x3167,
  3006. nieuntikeutkorean: 0x3166,
  3007. nihiragana: 0x306B,
  3008. nikatakana: 0x30CB,
  3009. nikatakanahalfwidth: 0xFF86,
  3010. nikhahitleftthai: 0xF899,
  3011. nikhahitthai: 0x0E4D,
  3012. nine: 0x0039,
  3013. ninearabic: 0x0669,
  3014. ninebengali: 0x09EF,
  3015. ninecircle: 0x2468,
  3016. ninecircleinversesansserif: 0x2792,
  3017. ninedeva: 0x096F,
  3018. ninegujarati: 0x0AEF,
  3019. ninegurmukhi: 0x0A6F,
  3020. ninehackarabic: 0x0669,
  3021. ninehangzhou: 0x3029,
  3022. nineideographicparen: 0x3228,
  3023. nineinferior: 0x2089,
  3024. ninemonospace: 0xFF19,
  3025. nineoldstyle: 0xF739,
  3026. nineparen: 0x247C,
  3027. nineperiod: 0x2490,
  3028. ninepersian: 0x06F9,
  3029. nineroman: 0x2178,
  3030. ninesuperior: 0x2079,
  3031. nineteencircle: 0x2472,
  3032. nineteenparen: 0x2486,
  3033. nineteenperiod: 0x249A,
  3034. ninethai: 0x0E59,
  3035. nj: 0x01CC,
  3036. njecyrillic: 0x045A,
  3037. nkatakana: 0x30F3,
  3038. nkatakanahalfwidth: 0xFF9D,
  3039. nlegrightlong: 0x019E,
  3040. nlinebelow: 0x1E49,
  3041. nmonospace: 0xFF4E,
  3042. nmsquare: 0x339A,
  3043. nnabengali: 0x09A3,
  3044. nnadeva: 0x0923,
  3045. nnagujarati: 0x0AA3,
  3046. nnagurmukhi: 0x0A23,
  3047. nnnadeva: 0x0929,
  3048. nohiragana: 0x306E,
  3049. nokatakana: 0x30CE,
  3050. nokatakanahalfwidth: 0xFF89,
  3051. nonbreakingspace: 0x00A0,
  3052. nonenthai: 0x0E13,
  3053. nonuthai: 0x0E19,
  3054. noonarabic: 0x0646,
  3055. noonfinalarabic: 0xFEE6,
  3056. noonghunnaarabic: 0x06BA,
  3057. noonghunnafinalarabic: 0xFB9F,
  3058. nooninitialarabic: 0xFEE7,
  3059. noonjeeminitialarabic: 0xFCD2,
  3060. noonjeemisolatedarabic: 0xFC4B,
  3061. noonmedialarabic: 0xFEE8,
  3062. noonmeeminitialarabic: 0xFCD5,
  3063. noonmeemisolatedarabic: 0xFC4E,
  3064. noonnoonfinalarabic: 0xFC8D,
  3065. notcontains: 0x220C,
  3066. notelement: 0x2209,
  3067. notelementof: 0x2209,
  3068. notequal: 0x2260,
  3069. notgreater: 0x226F,
  3070. notgreaternorequal: 0x2271,
  3071. notgreaternorless: 0x2279,
  3072. notidentical: 0x2262,
  3073. notless: 0x226E,
  3074. notlessnorequal: 0x2270,
  3075. notparallel: 0x2226,
  3076. notprecedes: 0x2280,
  3077. notsubset: 0x2284,
  3078. notsucceeds: 0x2281,
  3079. notsuperset: 0x2285,
  3080. nowarmenian: 0x0576,
  3081. nparen: 0x24A9,
  3082. nssquare: 0x33B1,
  3083. nsuperior: 0x207F,
  3084. ntilde: 0x00F1,
  3085. nu: 0x03BD,
  3086. nuhiragana: 0x306C,
  3087. nukatakana: 0x30CC,
  3088. nukatakanahalfwidth: 0xFF87,
  3089. nuktabengali: 0x09BC,
  3090. nuktadeva: 0x093C,
  3091. nuktagujarati: 0x0ABC,
  3092. nuktagurmukhi: 0x0A3C,
  3093. numbersign: 0x0023,
  3094. numbersignmonospace: 0xFF03,
  3095. numbersignsmall: 0xFE5F,
  3096. numeralsigngreek: 0x0374,
  3097. numeralsignlowergreek: 0x0375,
  3098. numero: 0x2116,
  3099. nun: 0x05E0,
  3100. nundagesh: 0xFB40,
  3101. nundageshhebrew: 0xFB40,
  3102. nunhebrew: 0x05E0,
  3103. nvsquare: 0x33B5,
  3104. nwsquare: 0x33BB,
  3105. nyabengali: 0x099E,
  3106. nyadeva: 0x091E,
  3107. nyagujarati: 0x0A9E,
  3108. nyagurmukhi: 0x0A1E,
  3109. o: 0x006F,
  3110. oacute: 0x00F3,
  3111. oangthai: 0x0E2D,
  3112. obarred: 0x0275,
  3113. obarredcyrillic: 0x04E9,
  3114. obarreddieresiscyrillic: 0x04EB,
  3115. obengali: 0x0993,
  3116. obopomofo: 0x311B,
  3117. obreve: 0x014F,
  3118. ocandradeva: 0x0911,
  3119. ocandragujarati: 0x0A91,
  3120. ocandravowelsigndeva: 0x0949,
  3121. ocandravowelsigngujarati: 0x0AC9,
  3122. ocaron: 0x01D2,
  3123. ocircle: 0x24DE,
  3124. ocircumflex: 0x00F4,
  3125. ocircumflexacute: 0x1ED1,
  3126. ocircumflexdotbelow: 0x1ED9,
  3127. ocircumflexgrave: 0x1ED3,
  3128. ocircumflexhookabove: 0x1ED5,
  3129. ocircumflextilde: 0x1ED7,
  3130. ocyrillic: 0x043E,
  3131. odblacute: 0x0151,
  3132. odblgrave: 0x020D,
  3133. odeva: 0x0913,
  3134. odieresis: 0x00F6,
  3135. odieresiscyrillic: 0x04E7,
  3136. odotbelow: 0x1ECD,
  3137. oe: 0x0153,
  3138. oekorean: 0x315A,
  3139. ogonek: 0x02DB,
  3140. ogonekcmb: 0x0328,
  3141. ograve: 0x00F2,
  3142. ogujarati: 0x0A93,
  3143. oharmenian: 0x0585,
  3144. ohiragana: 0x304A,
  3145. ohookabove: 0x1ECF,
  3146. ohorn: 0x01A1,
  3147. ohornacute: 0x1EDB,
  3148. ohorndotbelow: 0x1EE3,
  3149. ohorngrave: 0x1EDD,
  3150. ohornhookabove: 0x1EDF,
  3151. ohorntilde: 0x1EE1,
  3152. ohungarumlaut: 0x0151,
  3153. oi: 0x01A3,
  3154. oinvertedbreve: 0x020F,
  3155. okatakana: 0x30AA,
  3156. okatakanahalfwidth: 0xFF75,
  3157. okorean: 0x3157,
  3158. olehebrew: 0x05AB,
  3159. omacron: 0x014D,
  3160. omacronacute: 0x1E53,
  3161. omacrongrave: 0x1E51,
  3162. omdeva: 0x0950,
  3163. omega: 0x03C9,
  3164. omega1: 0x03D6,
  3165. omegacyrillic: 0x0461,
  3166. omegalatinclosed: 0x0277,
  3167. omegaroundcyrillic: 0x047B,
  3168. omegatitlocyrillic: 0x047D,
  3169. omegatonos: 0x03CE,
  3170. omgujarati: 0x0AD0,
  3171. omicron: 0x03BF,
  3172. omicrontonos: 0x03CC,
  3173. omonospace: 0xFF4F,
  3174. one: 0x0031,
  3175. onearabic: 0x0661,
  3176. onebengali: 0x09E7,
  3177. onecircle: 0x2460,
  3178. onecircleinversesansserif: 0x278A,
  3179. onedeva: 0x0967,
  3180. onedotenleader: 0x2024,
  3181. oneeighth: 0x215B,
  3182. onefitted: 0xF6DC,
  3183. onegujarati: 0x0AE7,
  3184. onegurmukhi: 0x0A67,
  3185. onehackarabic: 0x0661,
  3186. onehalf: 0x00BD,
  3187. onehangzhou: 0x3021,
  3188. oneideographicparen: 0x3220,
  3189. oneinferior: 0x2081,
  3190. onemonospace: 0xFF11,
  3191. onenumeratorbengali: 0x09F4,
  3192. oneoldstyle: 0xF731,
  3193. oneparen: 0x2474,
  3194. oneperiod: 0x2488,
  3195. onepersian: 0x06F1,
  3196. onequarter: 0x00BC,
  3197. oneroman: 0x2170,
  3198. onesuperior: 0x00B9,
  3199. onethai: 0x0E51,
  3200. onethird: 0x2153,
  3201. oogonek: 0x01EB,
  3202. oogonekmacron: 0x01ED,
  3203. oogurmukhi: 0x0A13,
  3204. oomatragurmukhi: 0x0A4B,
  3205. oopen: 0x0254,
  3206. oparen: 0x24AA,
  3207. openbullet: 0x25E6,
  3208. option: 0x2325,
  3209. ordfeminine: 0x00AA,
  3210. ordmasculine: 0x00BA,
  3211. orthogonal: 0x221F,
  3212. oshortdeva: 0x0912,
  3213. oshortvowelsigndeva: 0x094A,
  3214. oslash: 0x00F8,
  3215. oslashacute: 0x01FF,
  3216. osmallhiragana: 0x3049,
  3217. osmallkatakana: 0x30A9,
  3218. osmallkatakanahalfwidth: 0xFF6B,
  3219. ostrokeacute: 0x01FF,
  3220. osuperior: 0xF6F0,
  3221. otcyrillic: 0x047F,
  3222. otilde: 0x00F5,
  3223. otildeacute: 0x1E4D,
  3224. otildedieresis: 0x1E4F,
  3225. oubopomofo: 0x3121,
  3226. overline: 0x203E,
  3227. overlinecenterline: 0xFE4A,
  3228. overlinecmb: 0x0305,
  3229. overlinedashed: 0xFE49,
  3230. overlinedblwavy: 0xFE4C,
  3231. overlinewavy: 0xFE4B,
  3232. overscore: 0x00AF,
  3233. ovowelsignbengali: 0x09CB,
  3234. ovowelsigndeva: 0x094B,
  3235. ovowelsigngujarati: 0x0ACB,
  3236. p: 0x0070,
  3237. paampssquare: 0x3380,
  3238. paasentosquare: 0x332B,
  3239. pabengali: 0x09AA,
  3240. pacute: 0x1E55,
  3241. padeva: 0x092A,
  3242. pagedown: 0x21DF,
  3243. pageup: 0x21DE,
  3244. pagujarati: 0x0AAA,
  3245. pagurmukhi: 0x0A2A,
  3246. pahiragana: 0x3071,
  3247. paiyannoithai: 0x0E2F,
  3248. pakatakana: 0x30D1,
  3249. palatalizationcyrilliccmb: 0x0484,
  3250. palochkacyrillic: 0x04C0,
  3251. pansioskorean: 0x317F,
  3252. paragraph: 0x00B6,
  3253. parallel: 0x2225,
  3254. parenleft: 0x0028,
  3255. parenleftaltonearabic: 0xFD3E,
  3256. parenleftbt: 0xF8ED,
  3257. parenleftex: 0xF8EC,
  3258. parenleftinferior: 0x208D,
  3259. parenleftmonospace: 0xFF08,
  3260. parenleftsmall: 0xFE59,
  3261. parenleftsuperior: 0x207D,
  3262. parenlefttp: 0xF8EB,
  3263. parenleftvertical: 0xFE35,
  3264. parenright: 0x0029,
  3265. parenrightaltonearabic: 0xFD3F,
  3266. parenrightbt: 0xF8F8,
  3267. parenrightex: 0xF8F7,
  3268. parenrightinferior: 0x208E,
  3269. parenrightmonospace: 0xFF09,
  3270. parenrightsmall: 0xFE5A,
  3271. parenrightsuperior: 0x207E,
  3272. parenrighttp: 0xF8F6,
  3273. parenrightvertical: 0xFE36,
  3274. partialdiff: 0x2202,
  3275. paseqhebrew: 0x05C0,
  3276. pashtahebrew: 0x0599,
  3277. pasquare: 0x33A9,
  3278. patah: 0x05B7,
  3279. patah11: 0x05B7,
  3280. patah1d: 0x05B7,
  3281. patah2a: 0x05B7,
  3282. patahhebrew: 0x05B7,
  3283. patahnarrowhebrew: 0x05B7,
  3284. patahquarterhebrew: 0x05B7,
  3285. patahwidehebrew: 0x05B7,
  3286. pazerhebrew: 0x05A1,
  3287. pbopomofo: 0x3106,
  3288. pcircle: 0x24DF,
  3289. pdotaccent: 0x1E57,
  3290. pe: 0x05E4,
  3291. pecyrillic: 0x043F,
  3292. pedagesh: 0xFB44,
  3293. pedageshhebrew: 0xFB44,
  3294. peezisquare: 0x333B,
  3295. pefinaldageshhebrew: 0xFB43,
  3296. peharabic: 0x067E,
  3297. peharmenian: 0x057A,
  3298. pehebrew: 0x05E4,
  3299. pehfinalarabic: 0xFB57,
  3300. pehinitialarabic: 0xFB58,
  3301. pehiragana: 0x307A,
  3302. pehmedialarabic: 0xFB59,
  3303. pekatakana: 0x30DA,
  3304. pemiddlehookcyrillic: 0x04A7,
  3305. perafehebrew: 0xFB4E,
  3306. percent: 0x0025,
  3307. percentarabic: 0x066A,
  3308. percentmonospace: 0xFF05,
  3309. percentsmall: 0xFE6A,
  3310. period: 0x002E,
  3311. periodarmenian: 0x0589,
  3312. periodcentered: 0x00B7,
  3313. periodhalfwidth: 0xFF61,
  3314. periodinferior: 0xF6E7,
  3315. periodmonospace: 0xFF0E,
  3316. periodsmall: 0xFE52,
  3317. periodsuperior: 0xF6E8,
  3318. perispomenigreekcmb: 0x0342,
  3319. perpendicular: 0x22A5,
  3320. perthousand: 0x2030,
  3321. peseta: 0x20A7,
  3322. pfsquare: 0x338A,
  3323. phabengali: 0x09AB,
  3324. phadeva: 0x092B,
  3325. phagujarati: 0x0AAB,
  3326. phagurmukhi: 0x0A2B,
  3327. phi: 0x03C6,
  3328. phi1: 0x03D5,
  3329. phieuphacirclekorean: 0x327A,
  3330. phieuphaparenkorean: 0x321A,
  3331. phieuphcirclekorean: 0x326C,
  3332. phieuphkorean: 0x314D,
  3333. phieuphparenkorean: 0x320C,
  3334. philatin: 0x0278,
  3335. phinthuthai: 0x0E3A,
  3336. phisymbolgreek: 0x03D5,
  3337. phook: 0x01A5,
  3338. phophanthai: 0x0E1E,
  3339. phophungthai: 0x0E1C,
  3340. phosamphaothai: 0x0E20,
  3341. pi: 0x03C0,
  3342. pieupacirclekorean: 0x3273,
  3343. pieupaparenkorean: 0x3213,
  3344. pieupcieuckorean: 0x3176,
  3345. pieupcirclekorean: 0x3265,
  3346. pieupkiyeokkorean: 0x3172,
  3347. pieupkorean: 0x3142,
  3348. pieupparenkorean: 0x3205,
  3349. pieupsioskiyeokkorean: 0x3174,
  3350. pieupsioskorean: 0x3144,
  3351. pieupsiostikeutkorean: 0x3175,
  3352. pieupthieuthkorean: 0x3177,
  3353. pieuptikeutkorean: 0x3173,
  3354. pihiragana: 0x3074,
  3355. pikatakana: 0x30D4,
  3356. pisymbolgreek: 0x03D6,
  3357. piwrarmenian: 0x0583,
  3358. plus: 0x002B,
  3359. plusbelowcmb: 0x031F,
  3360. pluscircle: 0x2295,
  3361. plusminus: 0x00B1,
  3362. plusmod: 0x02D6,
  3363. plusmonospace: 0xFF0B,
  3364. plussmall: 0xFE62,
  3365. plussuperior: 0x207A,
  3366. pmonospace: 0xFF50,
  3367. pmsquare: 0x33D8,
  3368. pohiragana: 0x307D,
  3369. pointingindexdownwhite: 0x261F,
  3370. pointingindexleftwhite: 0x261C,
  3371. pointingindexrightwhite: 0x261E,
  3372. pointingindexupwhite: 0x261D,
  3373. pokatakana: 0x30DD,
  3374. poplathai: 0x0E1B,
  3375. postalmark: 0x3012,
  3376. postalmarkface: 0x3020,
  3377. pparen: 0x24AB,
  3378. precedes: 0x227A,
  3379. prescription: 0x211E,
  3380. primemod: 0x02B9,
  3381. primereversed: 0x2035,
  3382. product: 0x220F,
  3383. projective: 0x2305,
  3384. prolongedkana: 0x30FC,
  3385. propellor: 0x2318,
  3386. propersubset: 0x2282,
  3387. propersuperset: 0x2283,
  3388. proportion: 0x2237,
  3389. proportional: 0x221D,
  3390. psi: 0x03C8,
  3391. psicyrillic: 0x0471,
  3392. psilipneumatacyrilliccmb: 0x0486,
  3393. pssquare: 0x33B0,
  3394. puhiragana: 0x3077,
  3395. pukatakana: 0x30D7,
  3396. pvsquare: 0x33B4,
  3397. pwsquare: 0x33BA,
  3398. q: 0x0071,
  3399. qadeva: 0x0958,
  3400. qadmahebrew: 0x05A8,
  3401. qafarabic: 0x0642,
  3402. qaffinalarabic: 0xFED6,
  3403. qafinitialarabic: 0xFED7,
  3404. qafmedialarabic: 0xFED8,
  3405. qamats: 0x05B8,
  3406. qamats10: 0x05B8,
  3407. qamats1a: 0x05B8,
  3408. qamats1c: 0x05B8,
  3409. qamats27: 0x05B8,
  3410. qamats29: 0x05B8,
  3411. qamats33: 0x05B8,
  3412. qamatsde: 0x05B8,
  3413. qamatshebrew: 0x05B8,
  3414. qamatsnarrowhebrew: 0x05B8,
  3415. qamatsqatanhebrew: 0x05B8,
  3416. qamatsqatannarrowhebrew: 0x05B8,
  3417. qamatsqatanquarterhebrew: 0x05B8,
  3418. qamatsqatanwidehebrew: 0x05B8,
  3419. qamatsquarterhebrew: 0x05B8,
  3420. qamatswidehebrew: 0x05B8,
  3421. qarneyparahebrew: 0x059F,
  3422. qbopomofo: 0x3111,
  3423. qcircle: 0x24E0,
  3424. qhook: 0x02A0,
  3425. qmonospace: 0xFF51,
  3426. qof: 0x05E7,
  3427. qofdagesh: 0xFB47,
  3428. qofdageshhebrew: 0xFB47,
  3429. qofhebrew: 0x05E7,
  3430. qparen: 0x24AC,
  3431. quarternote: 0x2669,
  3432. qubuts: 0x05BB,
  3433. qubuts18: 0x05BB,
  3434. qubuts25: 0x05BB,
  3435. qubuts31: 0x05BB,
  3436. qubutshebrew: 0x05BB,
  3437. qubutsnarrowhebrew: 0x05BB,
  3438. qubutsquarterhebrew: 0x05BB,
  3439. qubutswidehebrew: 0x05BB,
  3440. question: 0x003F,
  3441. questionarabic: 0x061F,
  3442. questionarmenian: 0x055E,
  3443. questiondown: 0x00BF,
  3444. questiondownsmall: 0xF7BF,
  3445. questiongreek: 0x037E,
  3446. questionmonospace: 0xFF1F,
  3447. questionsmall: 0xF73F,
  3448. quotedbl: 0x0022,
  3449. quotedblbase: 0x201E,
  3450. quotedblleft: 0x201C,
  3451. quotedblmonospace: 0xFF02,
  3452. quotedblprime: 0x301E,
  3453. quotedblprimereversed: 0x301D,
  3454. quotedblright: 0x201D,
  3455. quoteleft: 0x2018,
  3456. quoteleftreversed: 0x201B,
  3457. quotereversed: 0x201B,
  3458. quoteright: 0x2019,
  3459. quoterightn: 0x0149,
  3460. quotesinglbase: 0x201A,
  3461. quotesingle: 0x0027,
  3462. quotesinglemonospace: 0xFF07,
  3463. r: 0x0072,
  3464. raarmenian: 0x057C,
  3465. rabengali: 0x09B0,
  3466. racute: 0x0155,
  3467. radeva: 0x0930,
  3468. radical: 0x221A,
  3469. radicalex: 0xF8E5,
  3470. radoverssquare: 0x33AE,
  3471. radoverssquaredsquare: 0x33AF,
  3472. radsquare: 0x33AD,
  3473. rafe: 0x05BF,
  3474. rafehebrew: 0x05BF,
  3475. ragujarati: 0x0AB0,
  3476. ragurmukhi: 0x0A30,
  3477. rahiragana: 0x3089,
  3478. rakatakana: 0x30E9,
  3479. rakatakanahalfwidth: 0xFF97,
  3480. ralowerdiagonalbengali: 0x09F1,
  3481. ramiddlediagonalbengali: 0x09F0,
  3482. ramshorn: 0x0264,
  3483. ratio: 0x2236,
  3484. rbopomofo: 0x3116,
  3485. rcaron: 0x0159,
  3486. rcedilla: 0x0157,
  3487. rcircle: 0x24E1,
  3488. rcommaaccent: 0x0157,
  3489. rdblgrave: 0x0211,
  3490. rdotaccent: 0x1E59,
  3491. rdotbelow: 0x1E5B,
  3492. rdotbelowmacron: 0x1E5D,
  3493. referencemark: 0x203B,
  3494. reflexsubset: 0x2286,
  3495. reflexsuperset: 0x2287,
  3496. registered: 0x00AE,
  3497. registersans: 0xF8E8,
  3498. registerserif: 0xF6DA,
  3499. reharabic: 0x0631,
  3500. reharmenian: 0x0580,
  3501. rehfinalarabic: 0xFEAE,
  3502. rehiragana: 0x308C,
  3503. rekatakana: 0x30EC,
  3504. rekatakanahalfwidth: 0xFF9A,
  3505. resh: 0x05E8,
  3506. reshdageshhebrew: 0xFB48,
  3507. reshhebrew: 0x05E8,
  3508. reversedtilde: 0x223D,
  3509. reviahebrew: 0x0597,
  3510. reviamugrashhebrew: 0x0597,
  3511. revlogicalnot: 0x2310,
  3512. rfishhook: 0x027E,
  3513. rfishhookreversed: 0x027F,
  3514. rhabengali: 0x09DD,
  3515. rhadeva: 0x095D,
  3516. rho: 0x03C1,
  3517. rhook: 0x027D,
  3518. rhookturned: 0x027B,
  3519. rhookturnedsuperior: 0x02B5,
  3520. rhosymbolgreek: 0x03F1,
  3521. rhotichookmod: 0x02DE,
  3522. rieulacirclekorean: 0x3271,
  3523. rieulaparenkorean: 0x3211,
  3524. rieulcirclekorean: 0x3263,
  3525. rieulhieuhkorean: 0x3140,
  3526. rieulkiyeokkorean: 0x313A,
  3527. rieulkiyeoksioskorean: 0x3169,
  3528. rieulkorean: 0x3139,
  3529. rieulmieumkorean: 0x313B,
  3530. rieulpansioskorean: 0x316C,
  3531. rieulparenkorean: 0x3203,
  3532. rieulphieuphkorean: 0x313F,
  3533. rieulpieupkorean: 0x313C,
  3534. rieulpieupsioskorean: 0x316B,
  3535. rieulsioskorean: 0x313D,
  3536. rieulthieuthkorean: 0x313E,
  3537. rieultikeutkorean: 0x316A,
  3538. rieulyeorinhieuhkorean: 0x316D,
  3539. rightangle: 0x221F,
  3540. righttackbelowcmb: 0x0319,
  3541. righttriangle: 0x22BF,
  3542. rihiragana: 0x308A,
  3543. rikatakana: 0x30EA,
  3544. rikatakanahalfwidth: 0xFF98,
  3545. ring: 0x02DA,
  3546. ringbelowcmb: 0x0325,
  3547. ringcmb: 0x030A,
  3548. ringhalfleft: 0x02BF,
  3549. ringhalfleftarmenian: 0x0559,
  3550. ringhalfleftbelowcmb: 0x031C,
  3551. ringhalfleftcentered: 0x02D3,
  3552. ringhalfright: 0x02BE,
  3553. ringhalfrightbelowcmb: 0x0339,
  3554. ringhalfrightcentered: 0x02D2,
  3555. rinvertedbreve: 0x0213,
  3556. rittorusquare: 0x3351,
  3557. rlinebelow: 0x1E5F,
  3558. rlongleg: 0x027C,
  3559. rlonglegturned: 0x027A,
  3560. rmonospace: 0xFF52,
  3561. rohiragana: 0x308D,
  3562. rokatakana: 0x30ED,
  3563. rokatakanahalfwidth: 0xFF9B,
  3564. roruathai: 0x0E23,
  3565. rparen: 0x24AD,
  3566. rrabengali: 0x09DC,
  3567. rradeva: 0x0931,
  3568. rragurmukhi: 0x0A5C,
  3569. rreharabic: 0x0691,
  3570. rrehfinalarabic: 0xFB8D,
  3571. rrvocalicbengali: 0x09E0,
  3572. rrvocalicdeva: 0x0960,
  3573. rrvocalicgujarati: 0x0AE0,
  3574. rrvocalicvowelsignbengali: 0x09C4,
  3575. rrvocalicvowelsigndeva: 0x0944,
  3576. rrvocalicvowelsigngujarati: 0x0AC4,
  3577. rsuperior: 0xF6F1,
  3578. rtblock: 0x2590,
  3579. rturned: 0x0279,
  3580. rturnedsuperior: 0x02B4,
  3581. ruhiragana: 0x308B,
  3582. rukatakana: 0x30EB,
  3583. rukatakanahalfwidth: 0xFF99,
  3584. rupeemarkbengali: 0x09F2,
  3585. rupeesignbengali: 0x09F3,
  3586. rupiah: 0xF6DD,
  3587. ruthai: 0x0E24,
  3588. rvocalicbengali: 0x098B,
  3589. rvocalicdeva: 0x090B,
  3590. rvocalicgujarati: 0x0A8B,
  3591. rvocalicvowelsignbengali: 0x09C3,
  3592. rvocalicvowelsigndeva: 0x0943,
  3593. rvocalicvowelsigngujarati: 0x0AC3,
  3594. s: 0x0073,
  3595. sabengali: 0x09B8,
  3596. sacute: 0x015B,
  3597. sacutedotaccent: 0x1E65,
  3598. sadarabic: 0x0635,
  3599. sadeva: 0x0938,
  3600. sadfinalarabic: 0xFEBA,
  3601. sadinitialarabic: 0xFEBB,
  3602. sadmedialarabic: 0xFEBC,
  3603. sagujarati: 0x0AB8,
  3604. sagurmukhi: 0x0A38,
  3605. sahiragana: 0x3055,
  3606. sakatakana: 0x30B5,
  3607. sakatakanahalfwidth: 0xFF7B,
  3608. sallallahoualayhewasallamarabic: 0xFDFA,
  3609. samekh: 0x05E1,
  3610. samekhdagesh: 0xFB41,
  3611. samekhdageshhebrew: 0xFB41,
  3612. samekhhebrew: 0x05E1,
  3613. saraaathai: 0x0E32,
  3614. saraaethai: 0x0E41,
  3615. saraaimaimalaithai: 0x0E44,
  3616. saraaimaimuanthai: 0x0E43,
  3617. saraamthai: 0x0E33,
  3618. saraathai: 0x0E30,
  3619. saraethai: 0x0E40,
  3620. saraiileftthai: 0xF886,
  3621. saraiithai: 0x0E35,
  3622. saraileftthai: 0xF885,
  3623. saraithai: 0x0E34,
  3624. saraothai: 0x0E42,
  3625. saraueeleftthai: 0xF888,
  3626. saraueethai: 0x0E37,
  3627. saraueleftthai: 0xF887,
  3628. sarauethai: 0x0E36,
  3629. sarauthai: 0x0E38,
  3630. sarauuthai: 0x0E39,
  3631. sbopomofo: 0x3119,
  3632. scaron: 0x0161,
  3633. scarondotaccent: 0x1E67,
  3634. scedilla: 0x015F,
  3635. schwa: 0x0259,
  3636. schwacyrillic: 0x04D9,
  3637. schwadieresiscyrillic: 0x04DB,
  3638. schwahook: 0x025A,
  3639. scircle: 0x24E2,
  3640. scircumflex: 0x015D,
  3641. scommaaccent: 0x0219,
  3642. sdotaccent: 0x1E61,
  3643. sdotbelow: 0x1E63,
  3644. sdotbelowdotaccent: 0x1E69,
  3645. seagullbelowcmb: 0x033C,
  3646. second: 0x2033,
  3647. secondtonechinese: 0x02CA,
  3648. section: 0x00A7,
  3649. seenarabic: 0x0633,
  3650. seenfinalarabic: 0xFEB2,
  3651. seeninitialarabic: 0xFEB3,
  3652. seenmedialarabic: 0xFEB4,
  3653. segol: 0x05B6,
  3654. segol13: 0x05B6,
  3655. segol1f: 0x05B6,
  3656. segol2c: 0x05B6,
  3657. segolhebrew: 0x05B6,
  3658. segolnarrowhebrew: 0x05B6,
  3659. segolquarterhebrew: 0x05B6,
  3660. segoltahebrew: 0x0592,
  3661. segolwidehebrew: 0x05B6,
  3662. seharmenian: 0x057D,
  3663. sehiragana: 0x305B,
  3664. sekatakana: 0x30BB,
  3665. sekatakanahalfwidth: 0xFF7E,
  3666. semicolon: 0x003B,
  3667. semicolonarabic: 0x061B,
  3668. semicolonmonospace: 0xFF1B,
  3669. semicolonsmall: 0xFE54,
  3670. semivoicedmarkkana: 0x309C,
  3671. semivoicedmarkkanahalfwidth: 0xFF9F,
  3672. sentisquare: 0x3322,
  3673. sentosquare: 0x3323,
  3674. seven: 0x0037,
  3675. sevenarabic: 0x0667,
  3676. sevenbengali: 0x09ED,
  3677. sevencircle: 0x2466,
  3678. sevencircleinversesansserif: 0x2790,
  3679. sevendeva: 0x096D,
  3680. seveneighths: 0x215E,
  3681. sevengujarati: 0x0AED,
  3682. sevengurmukhi: 0x0A6D,
  3683. sevenhackarabic: 0x0667,
  3684. sevenhangzhou: 0x3027,
  3685. sevenideographicparen: 0x3226,
  3686. seveninferior: 0x2087,
  3687. sevenmonospace: 0xFF17,
  3688. sevenoldstyle: 0xF737,
  3689. sevenparen: 0x247A,
  3690. sevenperiod: 0x248E,
  3691. sevenpersian: 0x06F7,
  3692. sevenroman: 0x2176,
  3693. sevensuperior: 0x2077,
  3694. seventeencircle: 0x2470,
  3695. seventeenparen: 0x2484,
  3696. seventeenperiod: 0x2498,
  3697. seventhai: 0x0E57,
  3698. sfthyphen: 0x00AD,
  3699. shaarmenian: 0x0577,
  3700. shabengali: 0x09B6,
  3701. shacyrillic: 0x0448,
  3702. shaddaarabic: 0x0651,
  3703. shaddadammaarabic: 0xFC61,
  3704. shaddadammatanarabic: 0xFC5E,
  3705. shaddafathaarabic: 0xFC60,
  3706. shaddakasraarabic: 0xFC62,
  3707. shaddakasratanarabic: 0xFC5F,
  3708. shade: 0x2592,
  3709. shadedark: 0x2593,
  3710. shadelight: 0x2591,
  3711. shademedium: 0x2592,
  3712. shadeva: 0x0936,
  3713. shagujarati: 0x0AB6,
  3714. shagurmukhi: 0x0A36,
  3715. shalshelethebrew: 0x0593,
  3716. shbopomofo: 0x3115,
  3717. shchacyrillic: 0x0449,
  3718. sheenarabic: 0x0634,
  3719. sheenfinalarabic: 0xFEB6,
  3720. sheeninitialarabic: 0xFEB7,
  3721. sheenmedialarabic: 0xFEB8,
  3722. sheicoptic: 0x03E3,
  3723. sheqel: 0x20AA,
  3724. sheqelhebrew: 0x20AA,
  3725. sheva: 0x05B0,
  3726. sheva115: 0x05B0,
  3727. sheva15: 0x05B0,
  3728. sheva22: 0x05B0,
  3729. sheva2e: 0x05B0,
  3730. shevahebrew: 0x05B0,
  3731. shevanarrowhebrew: 0x05B0,
  3732. shevaquarterhebrew: 0x05B0,
  3733. shevawidehebrew: 0x05B0,
  3734. shhacyrillic: 0x04BB,
  3735. shimacoptic: 0x03ED,
  3736. shin: 0x05E9,
  3737. shindagesh: 0xFB49,
  3738. shindageshhebrew: 0xFB49,
  3739. shindageshshindot: 0xFB2C,
  3740. shindageshshindothebrew: 0xFB2C,
  3741. shindageshsindot: 0xFB2D,
  3742. shindageshsindothebrew: 0xFB2D,
  3743. shindothebrew: 0x05C1,
  3744. shinhebrew: 0x05E9,
  3745. shinshindot: 0xFB2A,
  3746. shinshindothebrew: 0xFB2A,
  3747. shinsindot: 0xFB2B,
  3748. shinsindothebrew: 0xFB2B,
  3749. shook: 0x0282,
  3750. sigma: 0x03C3,
  3751. sigma1: 0x03C2,
  3752. sigmafinal: 0x03C2,
  3753. sigmalunatesymbolgreek: 0x03F2,
  3754. sihiragana: 0x3057,
  3755. sikatakana: 0x30B7,
  3756. sikatakanahalfwidth: 0xFF7C,
  3757. siluqhebrew: 0x05BD,
  3758. siluqlefthebrew: 0x05BD,
  3759. similar: 0x223C,
  3760. sindothebrew: 0x05C2,
  3761. siosacirclekorean: 0x3274,
  3762. siosaparenkorean: 0x3214,
  3763. sioscieuckorean: 0x317E,
  3764. sioscirclekorean: 0x3266,
  3765. sioskiyeokkorean: 0x317A,
  3766. sioskorean: 0x3145,
  3767. siosnieunkorean: 0x317B,
  3768. siosparenkorean: 0x3206,
  3769. siospieupkorean: 0x317D,
  3770. siostikeutkorean: 0x317C,
  3771. six: 0x0036,
  3772. sixarabic: 0x0666,
  3773. sixbengali: 0x09EC,
  3774. sixcircle: 0x2465,
  3775. sixcircleinversesansserif: 0x278F,
  3776. sixdeva: 0x096C,
  3777. sixgujarati: 0x0AEC,
  3778. sixgurmukhi: 0x0A6C,
  3779. sixhackarabic: 0x0666,
  3780. sixhangzhou: 0x3026,
  3781. sixideographicparen: 0x3225,
  3782. sixinferior: 0x2086,
  3783. sixmonospace: 0xFF16,
  3784. sixoldstyle: 0xF736,
  3785. sixparen: 0x2479,
  3786. sixperiod: 0x248D,
  3787. sixpersian: 0x06F6,
  3788. sixroman: 0x2175,
  3789. sixsuperior: 0x2076,
  3790. sixteencircle: 0x246F,
  3791. sixteencurrencydenominatorbengali: 0x09F9,
  3792. sixteenparen: 0x2483,
  3793. sixteenperiod: 0x2497,
  3794. sixthai: 0x0E56,
  3795. slash: 0x002F,
  3796. slashmonospace: 0xFF0F,
  3797. slong: 0x017F,
  3798. slongdotaccent: 0x1E9B,
  3799. smileface: 0x263A,
  3800. smonospace: 0xFF53,
  3801. sofpasuqhebrew: 0x05C3,
  3802. softhyphen: 0x00AD,
  3803. softsigncyrillic: 0x044C,
  3804. sohiragana: 0x305D,
  3805. sokatakana: 0x30BD,
  3806. sokatakanahalfwidth: 0xFF7F,
  3807. soliduslongoverlaycmb: 0x0338,
  3808. solidusshortoverlaycmb: 0x0337,
  3809. sorusithai: 0x0E29,
  3810. sosalathai: 0x0E28,
  3811. sosothai: 0x0E0B,
  3812. sosuathai: 0x0E2A,
  3813. space: 0x0020,
  3814. spacehackarabic: 0x0020,
  3815. spade: 0x2660,
  3816. spadesuitblack: 0x2660,
  3817. spadesuitwhite: 0x2664,
  3818. sparen: 0x24AE,
  3819. squarebelowcmb: 0x033B,
  3820. squarecc: 0x33C4,
  3821. squarecm: 0x339D,
  3822. squarediagonalcrosshatchfill: 0x25A9,
  3823. squarehorizontalfill: 0x25A4,
  3824. squarekg: 0x338F,
  3825. squarekm: 0x339E,
  3826. squarekmcapital: 0x33CE,
  3827. squareln: 0x33D1,
  3828. squarelog: 0x33D2,
  3829. squaremg: 0x338E,
  3830. squaremil: 0x33D5,
  3831. squaremm: 0x339C,
  3832. squaremsquared: 0x33A1,
  3833. squareorthogonalcrosshatchfill: 0x25A6,
  3834. squareupperlefttolowerrightfill: 0x25A7,
  3835. squareupperrighttolowerleftfill: 0x25A8,
  3836. squareverticalfill: 0x25A5,
  3837. squarewhitewithsmallblack: 0x25A3,
  3838. srsquare: 0x33DB,
  3839. ssabengali: 0x09B7,
  3840. ssadeva: 0x0937,
  3841. ssagujarati: 0x0AB7,
  3842. ssangcieuckorean: 0x3149,
  3843. ssanghieuhkorean: 0x3185,
  3844. ssangieungkorean: 0x3180,
  3845. ssangkiyeokkorean: 0x3132,
  3846. ssangnieunkorean: 0x3165,
  3847. ssangpieupkorean: 0x3143,
  3848. ssangsioskorean: 0x3146,
  3849. ssangtikeutkorean: 0x3138,
  3850. ssuperior: 0xF6F2,
  3851. sterling: 0x00A3,
  3852. sterlingmonospace: 0xFFE1,
  3853. strokelongoverlaycmb: 0x0336,
  3854. strokeshortoverlaycmb: 0x0335,
  3855. subset: 0x2282,
  3856. subsetnotequal: 0x228A,
  3857. subsetorequal: 0x2286,
  3858. succeeds: 0x227B,
  3859. suchthat: 0x220B,
  3860. suhiragana: 0x3059,
  3861. sukatakana: 0x30B9,
  3862. sukatakanahalfwidth: 0xFF7D,
  3863. sukunarabic: 0x0652,
  3864. summation: 0x2211,
  3865. sun: 0x263C,
  3866. superset: 0x2283,
  3867. supersetnotequal: 0x228B,
  3868. supersetorequal: 0x2287,
  3869. svsquare: 0x33DC,
  3870. syouwaerasquare: 0x337C,
  3871. t: 0x0074,
  3872. tabengali: 0x09A4,
  3873. tackdown: 0x22A4,
  3874. tackleft: 0x22A3,
  3875. tadeva: 0x0924,
  3876. tagujarati: 0x0AA4,
  3877. tagurmukhi: 0x0A24,
  3878. taharabic: 0x0637,
  3879. tahfinalarabic: 0xFEC2,
  3880. tahinitialarabic: 0xFEC3,
  3881. tahiragana: 0x305F,
  3882. tahmedialarabic: 0xFEC4,
  3883. taisyouerasquare: 0x337D,
  3884. takatakana: 0x30BF,
  3885. takatakanahalfwidth: 0xFF80,
  3886. tatweelarabic: 0x0640,
  3887. tau: 0x03C4,
  3888. tav: 0x05EA,
  3889. tavdages: 0xFB4A,
  3890. tavdagesh: 0xFB4A,
  3891. tavdageshhebrew: 0xFB4A,
  3892. tavhebrew: 0x05EA,
  3893. tbar: 0x0167,
  3894. tbopomofo: 0x310A,
  3895. tcaron: 0x0165,
  3896. tccurl: 0x02A8,
  3897. tcedilla: 0x0163,
  3898. tcheharabic: 0x0686,
  3899. tchehfinalarabic: 0xFB7B,
  3900. tchehinitialarabic: 0xFB7C,
  3901. tchehmedialarabic: 0xFB7D,
  3902. tcircle: 0x24E3,
  3903. tcircumflexbelow: 0x1E71,
  3904. tcommaaccent: 0x0163,
  3905. tdieresis: 0x1E97,
  3906. tdotaccent: 0x1E6B,
  3907. tdotbelow: 0x1E6D,
  3908. tecyrillic: 0x0442,
  3909. tedescendercyrillic: 0x04AD,
  3910. teharabic: 0x062A,
  3911. tehfinalarabic: 0xFE96,
  3912. tehhahinitialarabic: 0xFCA2,
  3913. tehhahisolatedarabic: 0xFC0C,
  3914. tehinitialarabic: 0xFE97,
  3915. tehiragana: 0x3066,
  3916. tehjeeminitialarabic: 0xFCA1,
  3917. tehjeemisolatedarabic: 0xFC0B,
  3918. tehmarbutaarabic: 0x0629,
  3919. tehmarbutafinalarabic: 0xFE94,
  3920. tehmedialarabic: 0xFE98,
  3921. tehmeeminitialarabic: 0xFCA4,
  3922. tehmeemisolatedarabic: 0xFC0E,
  3923. tehnoonfinalarabic: 0xFC73,
  3924. tekatakana: 0x30C6,
  3925. tekatakanahalfwidth: 0xFF83,
  3926. telephone: 0x2121,
  3927. telephoneblack: 0x260E,
  3928. telishagedolahebrew: 0x05A0,
  3929. telishaqetanahebrew: 0x05A9,
  3930. tencircle: 0x2469,
  3931. tenideographicparen: 0x3229,
  3932. tenparen: 0x247D,
  3933. tenperiod: 0x2491,
  3934. tenroman: 0x2179,
  3935. tesh: 0x02A7,
  3936. tet: 0x05D8,
  3937. tetdagesh: 0xFB38,
  3938. tetdageshhebrew: 0xFB38,
  3939. tethebrew: 0x05D8,
  3940. tetsecyrillic: 0x04B5,
  3941. tevirhebrew: 0x059B,
  3942. tevirlefthebrew: 0x059B,
  3943. thabengali: 0x09A5,
  3944. thadeva: 0x0925,
  3945. thagujarati: 0x0AA5,
  3946. thagurmukhi: 0x0A25,
  3947. thalarabic: 0x0630,
  3948. thalfinalarabic: 0xFEAC,
  3949. thanthakhatlowleftthai: 0xF898,
  3950. thanthakhatlowrightthai: 0xF897,
  3951. thanthakhatthai: 0x0E4C,
  3952. thanthakhatupperleftthai: 0xF896,
  3953. theharabic: 0x062B,
  3954. thehfinalarabic: 0xFE9A,
  3955. thehinitialarabic: 0xFE9B,
  3956. thehmedialarabic: 0xFE9C,
  3957. thereexists: 0x2203,
  3958. therefore: 0x2234,
  3959. theta: 0x03B8,
  3960. theta1: 0x03D1,
  3961. thetasymbolgreek: 0x03D1,
  3962. thieuthacirclekorean: 0x3279,
  3963. thieuthaparenkorean: 0x3219,
  3964. thieuthcirclekorean: 0x326B,
  3965. thieuthkorean: 0x314C,
  3966. thieuthparenkorean: 0x320B,
  3967. thirteencircle: 0x246C,
  3968. thirteenparen: 0x2480,
  3969. thirteenperiod: 0x2494,
  3970. thonangmonthothai: 0x0E11,
  3971. thook: 0x01AD,
  3972. thophuthaothai: 0x0E12,
  3973. thorn: 0x00FE,
  3974. thothahanthai: 0x0E17,
  3975. thothanthai: 0x0E10,
  3976. thothongthai: 0x0E18,
  3977. thothungthai: 0x0E16,
  3978. thousandcyrillic: 0x0482,
  3979. thousandsseparatorarabic: 0x066C,
  3980. thousandsseparatorpersian: 0x066C,
  3981. three: 0x0033,
  3982. threearabic: 0x0663,
  3983. threebengali: 0x09E9,
  3984. threecircle: 0x2462,
  3985. threecircleinversesansserif: 0x278C,
  3986. threedeva: 0x0969,
  3987. threeeighths: 0x215C,
  3988. threegujarati: 0x0AE9,
  3989. threegurmukhi: 0x0A69,
  3990. threehackarabic: 0x0663,
  3991. threehangzhou: 0x3023,
  3992. threeideographicparen: 0x3222,
  3993. threeinferior: 0x2083,
  3994. threemonospace: 0xFF13,
  3995. threenumeratorbengali: 0x09F6,
  3996. threeoldstyle: 0xF733,
  3997. threeparen: 0x2476,
  3998. threeperiod: 0x248A,
  3999. threepersian: 0x06F3,
  4000. threequarters: 0x00BE,
  4001. threequartersemdash: 0xF6DE,
  4002. threeroman: 0x2172,
  4003. threesuperior: 0x00B3,
  4004. threethai: 0x0E53,
  4005. thzsquare: 0x3394,
  4006. tihiragana: 0x3061,
  4007. tikatakana: 0x30C1,
  4008. tikatakanahalfwidth: 0xFF81,
  4009. tikeutacirclekorean: 0x3270,
  4010. tikeutaparenkorean: 0x3210,
  4011. tikeutcirclekorean: 0x3262,
  4012. tikeutkorean: 0x3137,
  4013. tikeutparenkorean: 0x3202,
  4014. tilde: 0x02DC,
  4015. tildebelowcmb: 0x0330,
  4016. tildecmb: 0x0303,
  4017. tildecomb: 0x0303,
  4018. tildedoublecmb: 0x0360,
  4019. tildeoperator: 0x223C,
  4020. tildeoverlaycmb: 0x0334,
  4021. tildeverticalcmb: 0x033E,
  4022. timescircle: 0x2297,
  4023. tipehahebrew: 0x0596,
  4024. tipehalefthebrew: 0x0596,
  4025. tippigurmukhi: 0x0A70,
  4026. titlocyrilliccmb: 0x0483,
  4027. tiwnarmenian: 0x057F,
  4028. tlinebelow: 0x1E6F,
  4029. tmonospace: 0xFF54,
  4030. toarmenian: 0x0569,
  4031. tohiragana: 0x3068,
  4032. tokatakana: 0x30C8,
  4033. tokatakanahalfwidth: 0xFF84,
  4034. tonebarextrahighmod: 0x02E5,
  4035. tonebarextralowmod: 0x02E9,
  4036. tonebarhighmod: 0x02E6,
  4037. tonebarlowmod: 0x02E8,
  4038. tonebarmidmod: 0x02E7,
  4039. tonefive: 0x01BD,
  4040. tonesix: 0x0185,
  4041. tonetwo: 0x01A8,
  4042. tonos: 0x0384,
  4043. tonsquare: 0x3327,
  4044. topatakthai: 0x0E0F,
  4045. tortoiseshellbracketleft: 0x3014,
  4046. tortoiseshellbracketleftsmall: 0xFE5D,
  4047. tortoiseshellbracketleftvertical: 0xFE39,
  4048. tortoiseshellbracketright: 0x3015,
  4049. tortoiseshellbracketrightsmall: 0xFE5E,
  4050. tortoiseshellbracketrightvertical: 0xFE3A,
  4051. totaothai: 0x0E15,
  4052. tpalatalhook: 0x01AB,
  4053. tparen: 0x24AF,
  4054. trademark: 0x2122,
  4055. trademarksans: 0xF8EA,
  4056. trademarkserif: 0xF6DB,
  4057. tretroflexhook: 0x0288,
  4058. triagdn: 0x25BC,
  4059. triaglf: 0x25C4,
  4060. triagrt: 0x25BA,
  4061. triagup: 0x25B2,
  4062. ts: 0x02A6,
  4063. tsadi: 0x05E6,
  4064. tsadidagesh: 0xFB46,
  4065. tsadidageshhebrew: 0xFB46,
  4066. tsadihebrew: 0x05E6,
  4067. tsecyrillic: 0x0446,
  4068. tsere: 0x05B5,
  4069. tsere12: 0x05B5,
  4070. tsere1e: 0x05B5,
  4071. tsere2b: 0x05B5,
  4072. tserehebrew: 0x05B5,
  4073. tserenarrowhebrew: 0x05B5,
  4074. tserequarterhebrew: 0x05B5,
  4075. tserewidehebrew: 0x05B5,
  4076. tshecyrillic: 0x045B,
  4077. tsuperior: 0xF6F3,
  4078. ttabengali: 0x099F,
  4079. ttadeva: 0x091F,
  4080. ttagujarati: 0x0A9F,
  4081. ttagurmukhi: 0x0A1F,
  4082. tteharabic: 0x0679,
  4083. ttehfinalarabic: 0xFB67,
  4084. ttehinitialarabic: 0xFB68,
  4085. ttehmedialarabic: 0xFB69,
  4086. tthabengali: 0x09A0,
  4087. tthadeva: 0x0920,
  4088. tthagujarati: 0x0AA0,
  4089. tthagurmukhi: 0x0A20,
  4090. tturned: 0x0287,
  4091. tuhiragana: 0x3064,
  4092. tukatakana: 0x30C4,
  4093. tukatakanahalfwidth: 0xFF82,
  4094. tusmallhiragana: 0x3063,
  4095. tusmallkatakana: 0x30C3,
  4096. tusmallkatakanahalfwidth: 0xFF6F,
  4097. twelvecircle: 0x246B,
  4098. twelveparen: 0x247F,
  4099. twelveperiod: 0x2493,
  4100. twelveroman: 0x217B,
  4101. twentycircle: 0x2473,
  4102. twentyhangzhou: 0x5344,
  4103. twentyparen: 0x2487,
  4104. twentyperiod: 0x249B,
  4105. two: 0x0032,
  4106. twoarabic: 0x0662,
  4107. twobengali: 0x09E8,
  4108. twocircle: 0x2461,
  4109. twocircleinversesansserif: 0x278B,
  4110. twodeva: 0x0968,
  4111. twodotenleader: 0x2025,
  4112. twodotleader: 0x2025,
  4113. twodotleadervertical: 0xFE30,
  4114. twogujarati: 0x0AE8,
  4115. twogurmukhi: 0x0A68,
  4116. twohackarabic: 0x0662,
  4117. twohangzhou: 0x3022,
  4118. twoideographicparen: 0x3221,
  4119. twoinferior: 0x2082,
  4120. twomonospace: 0xFF12,
  4121. twonumeratorbengali: 0x09F5,
  4122. twooldstyle: 0xF732,
  4123. twoparen: 0x2475,
  4124. twoperiod: 0x2489,
  4125. twopersian: 0x06F2,
  4126. tworoman: 0x2171,
  4127. twostroke: 0x01BB,
  4128. twosuperior: 0x00B2,
  4129. twothai: 0x0E52,
  4130. twothirds: 0x2154,
  4131. u: 0x0075,
  4132. uacute: 0x00FA,
  4133. ubar: 0x0289,
  4134. ubengali: 0x0989,
  4135. ubopomofo: 0x3128,
  4136. ubreve: 0x016D,
  4137. ucaron: 0x01D4,
  4138. ucircle: 0x24E4,
  4139. ucircumflex: 0x00FB,
  4140. ucircumflexbelow: 0x1E77,
  4141. ucyrillic: 0x0443,
  4142. udattadeva: 0x0951,
  4143. udblacute: 0x0171,
  4144. udblgrave: 0x0215,
  4145. udeva: 0x0909,
  4146. udieresis: 0x00FC,
  4147. udieresisacute: 0x01D8,
  4148. udieresisbelow: 0x1E73,
  4149. udieresiscaron: 0x01DA,
  4150. udieresiscyrillic: 0x04F1,
  4151. udieresisgrave: 0x01DC,
  4152. udieresismacron: 0x01D6,
  4153. udotbelow: 0x1EE5,
  4154. ugrave: 0x00F9,
  4155. ugujarati: 0x0A89,
  4156. ugurmukhi: 0x0A09,
  4157. uhiragana: 0x3046,
  4158. uhookabove: 0x1EE7,
  4159. uhorn: 0x01B0,
  4160. uhornacute: 0x1EE9,
  4161. uhorndotbelow: 0x1EF1,
  4162. uhorngrave: 0x1EEB,
  4163. uhornhookabove: 0x1EED,
  4164. uhorntilde: 0x1EEF,
  4165. uhungarumlaut: 0x0171,
  4166. uhungarumlautcyrillic: 0x04F3,
  4167. uinvertedbreve: 0x0217,
  4168. ukatakana: 0x30A6,
  4169. ukatakanahalfwidth: 0xFF73,
  4170. ukcyrillic: 0x0479,
  4171. ukorean: 0x315C,
  4172. umacron: 0x016B,
  4173. umacroncyrillic: 0x04EF,
  4174. umacrondieresis: 0x1E7B,
  4175. umatragurmukhi: 0x0A41,
  4176. umonospace: 0xFF55,
  4177. underscore: 0x005F,
  4178. underscoredbl: 0x2017,
  4179. underscoremonospace: 0xFF3F,
  4180. underscorevertical: 0xFE33,
  4181. underscorewavy: 0xFE4F,
  4182. union: 0x222A,
  4183. universal: 0x2200,
  4184. uogonek: 0x0173,
  4185. uparen: 0x24B0,
  4186. upblock: 0x2580,
  4187. upperdothebrew: 0x05C4,
  4188. upsilon: 0x03C5,
  4189. upsilondieresis: 0x03CB,
  4190. upsilondieresistonos: 0x03B0,
  4191. upsilonlatin: 0x028A,
  4192. upsilontonos: 0x03CD,
  4193. uptackbelowcmb: 0x031D,
  4194. uptackmod: 0x02D4,
  4195. uragurmukhi: 0x0A73,
  4196. uring: 0x016F,
  4197. ushortcyrillic: 0x045E,
  4198. usmallhiragana: 0x3045,
  4199. usmallkatakana: 0x30A5,
  4200. usmallkatakanahalfwidth: 0xFF69,
  4201. ustraightcyrillic: 0x04AF,
  4202. ustraightstrokecyrillic: 0x04B1,
  4203. utilde: 0x0169,
  4204. utildeacute: 0x1E79,
  4205. utildebelow: 0x1E75,
  4206. uubengali: 0x098A,
  4207. uudeva: 0x090A,
  4208. uugujarati: 0x0A8A,
  4209. uugurmukhi: 0x0A0A,
  4210. uumatragurmukhi: 0x0A42,
  4211. uuvowelsignbengali: 0x09C2,
  4212. uuvowelsigndeva: 0x0942,
  4213. uuvowelsigngujarati: 0x0AC2,
  4214. uvowelsignbengali: 0x09C1,
  4215. uvowelsigndeva: 0x0941,
  4216. uvowelsigngujarati: 0x0AC1,
  4217. v: 0x0076,
  4218. vadeva: 0x0935,
  4219. vagujarati: 0x0AB5,
  4220. vagurmukhi: 0x0A35,
  4221. vakatakana: 0x30F7,
  4222. vav: 0x05D5,
  4223. vavdagesh: 0xFB35,
  4224. vavdagesh65: 0xFB35,
  4225. vavdageshhebrew: 0xFB35,
  4226. vavhebrew: 0x05D5,
  4227. vavholam: 0xFB4B,
  4228. vavholamhebrew: 0xFB4B,
  4229. vavvavhebrew: 0x05F0,
  4230. vavyodhebrew: 0x05F1,
  4231. vcircle: 0x24E5,
  4232. vdotbelow: 0x1E7F,
  4233. vecyrillic: 0x0432,
  4234. veharabic: 0x06A4,
  4235. vehfinalarabic: 0xFB6B,
  4236. vehinitialarabic: 0xFB6C,
  4237. vehmedialarabic: 0xFB6D,
  4238. vekatakana: 0x30F9,
  4239. venus: 0x2640,
  4240. verticalbar: 0x007C,
  4241. verticallineabovecmb: 0x030D,
  4242. verticallinebelowcmb: 0x0329,
  4243. verticallinelowmod: 0x02CC,
  4244. verticallinemod: 0x02C8,
  4245. vewarmenian: 0x057E,
  4246. vhook: 0x028B,
  4247. vikatakana: 0x30F8,
  4248. viramabengali: 0x09CD,
  4249. viramadeva: 0x094D,
  4250. viramagujarati: 0x0ACD,
  4251. visargabengali: 0x0983,
  4252. visargadeva: 0x0903,
  4253. visargagujarati: 0x0A83,
  4254. vmonospace: 0xFF56,
  4255. voarmenian: 0x0578,
  4256. voicediterationhiragana: 0x309E,
  4257. voicediterationkatakana: 0x30FE,
  4258. voicedmarkkana: 0x309B,
  4259. voicedmarkkanahalfwidth: 0xFF9E,
  4260. vokatakana: 0x30FA,
  4261. vparen: 0x24B1,
  4262. vtilde: 0x1E7D,
  4263. vturned: 0x028C,
  4264. vuhiragana: 0x3094,
  4265. vukatakana: 0x30F4,
  4266. w: 0x0077,
  4267. wacute: 0x1E83,
  4268. waekorean: 0x3159,
  4269. wahiragana: 0x308F,
  4270. wakatakana: 0x30EF,
  4271. wakatakanahalfwidth: 0xFF9C,
  4272. wakorean: 0x3158,
  4273. wasmallhiragana: 0x308E,
  4274. wasmallkatakana: 0x30EE,
  4275. wattosquare: 0x3357,
  4276. wavedash: 0x301C,
  4277. wavyunderscorevertical: 0xFE34,
  4278. wawarabic: 0x0648,
  4279. wawfinalarabic: 0xFEEE,
  4280. wawhamzaabovearabic: 0x0624,
  4281. wawhamzaabovefinalarabic: 0xFE86,
  4282. wbsquare: 0x33DD,
  4283. wcircle: 0x24E6,
  4284. wcircumflex: 0x0175,
  4285. wdieresis: 0x1E85,
  4286. wdotaccent: 0x1E87,
  4287. wdotbelow: 0x1E89,
  4288. wehiragana: 0x3091,
  4289. weierstrass: 0x2118,
  4290. wekatakana: 0x30F1,
  4291. wekorean: 0x315E,
  4292. weokorean: 0x315D,
  4293. wgrave: 0x1E81,
  4294. whitebullet: 0x25E6,
  4295. whitecircle: 0x25CB,
  4296. whitecircleinverse: 0x25D9,
  4297. whitecornerbracketleft: 0x300E,
  4298. whitecornerbracketleftvertical: 0xFE43,
  4299. whitecornerbracketright: 0x300F,
  4300. whitecornerbracketrightvertical: 0xFE44,
  4301. whitediamond: 0x25C7,
  4302. whitediamondcontainingblacksmalldiamond: 0x25C8,
  4303. whitedownpointingsmalltriangle: 0x25BF,
  4304. whitedownpointingtriangle: 0x25BD,
  4305. whiteleftpointingsmalltriangle: 0x25C3,
  4306. whiteleftpointingtriangle: 0x25C1,
  4307. whitelenticularbracketleft: 0x3016,
  4308. whitelenticularbracketright: 0x3017,
  4309. whiterightpointingsmalltriangle: 0x25B9,
  4310. whiterightpointingtriangle: 0x25B7,
  4311. whitesmallsquare: 0x25AB,
  4312. whitesmilingface: 0x263A,
  4313. whitesquare: 0x25A1,
  4314. whitestar: 0x2606,
  4315. whitetelephone: 0x260F,
  4316. whitetortoiseshellbracketleft: 0x3018,
  4317. whitetortoiseshellbracketright: 0x3019,
  4318. whiteuppointingsmalltriangle: 0x25B5,
  4319. whiteuppointingtriangle: 0x25B3,
  4320. wihiragana: 0x3090,
  4321. wikatakana: 0x30F0,
  4322. wikorean: 0x315F,
  4323. wmonospace: 0xFF57,
  4324. wohiragana: 0x3092,
  4325. wokatakana: 0x30F2,
  4326. wokatakanahalfwidth: 0xFF66,
  4327. won: 0x20A9,
  4328. wonmonospace: 0xFFE6,
  4329. wowaenthai: 0x0E27,
  4330. wparen: 0x24B2,
  4331. wring: 0x1E98,
  4332. wsuperior: 0x02B7,
  4333. wturned: 0x028D,
  4334. wynn: 0x01BF,
  4335. x: 0x0078,
  4336. xabovecmb: 0x033D,
  4337. xbopomofo: 0x3112,
  4338. xcircle: 0x24E7,
  4339. xdieresis: 0x1E8D,
  4340. xdotaccent: 0x1E8B,
  4341. xeharmenian: 0x056D,
  4342. xi: 0x03BE,
  4343. xmonospace: 0xFF58,
  4344. xparen: 0x24B3,
  4345. xsuperior: 0x02E3,
  4346. y: 0x0079,
  4347. yaadosquare: 0x334E,
  4348. yabengali: 0x09AF,
  4349. yacute: 0x00FD,
  4350. yadeva: 0x092F,
  4351. yaekorean: 0x3152,
  4352. yagujarati: 0x0AAF,
  4353. yagurmukhi: 0x0A2F,
  4354. yahiragana: 0x3084,
  4355. yakatakana: 0x30E4,
  4356. yakatakanahalfwidth: 0xFF94,
  4357. yakorean: 0x3151,
  4358. yamakkanthai: 0x0E4E,
  4359. yasmallhiragana: 0x3083,
  4360. yasmallkatakana: 0x30E3,
  4361. yasmallkatakanahalfwidth: 0xFF6C,
  4362. yatcyrillic: 0x0463,
  4363. ycircle: 0x24E8,
  4364. ycircumflex: 0x0177,
  4365. ydieresis: 0x00FF,
  4366. ydotaccent: 0x1E8F,
  4367. ydotbelow: 0x1EF5,
  4368. yeharabic: 0x064A,
  4369. yehbarreearabic: 0x06D2,
  4370. yehbarreefinalarabic: 0xFBAF,
  4371. yehfinalarabic: 0xFEF2,
  4372. yehhamzaabovearabic: 0x0626,
  4373. yehhamzaabovefinalarabic: 0xFE8A,
  4374. yehhamzaaboveinitialarabic: 0xFE8B,
  4375. yehhamzaabovemedialarabic: 0xFE8C,
  4376. yehinitialarabic: 0xFEF3,
  4377. yehmedialarabic: 0xFEF4,
  4378. yehmeeminitialarabic: 0xFCDD,
  4379. yehmeemisolatedarabic: 0xFC58,
  4380. yehnoonfinalarabic: 0xFC94,
  4381. yehthreedotsbelowarabic: 0x06D1,
  4382. yekorean: 0x3156,
  4383. yen: 0x00A5,
  4384. yenmonospace: 0xFFE5,
  4385. yeokorean: 0x3155,
  4386. yeorinhieuhkorean: 0x3186,
  4387. yerahbenyomohebrew: 0x05AA,
  4388. yerahbenyomolefthebrew: 0x05AA,
  4389. yericyrillic: 0x044B,
  4390. yerudieresiscyrillic: 0x04F9,
  4391. yesieungkorean: 0x3181,
  4392. yesieungpansioskorean: 0x3183,
  4393. yesieungsioskorean: 0x3182,
  4394. yetivhebrew: 0x059A,
  4395. ygrave: 0x1EF3,
  4396. yhook: 0x01B4,
  4397. yhookabove: 0x1EF7,
  4398. yiarmenian: 0x0575,
  4399. yicyrillic: 0x0457,
  4400. yikorean: 0x3162,
  4401. yinyang: 0x262F,
  4402. yiwnarmenian: 0x0582,
  4403. ymonospace: 0xFF59,
  4404. yod: 0x05D9,
  4405. yoddagesh: 0xFB39,
  4406. yoddageshhebrew: 0xFB39,
  4407. yodhebrew: 0x05D9,
  4408. yodyodhebrew: 0x05F2,
  4409. yodyodpatahhebrew: 0xFB1F,
  4410. yohiragana: 0x3088,
  4411. yoikorean: 0x3189,
  4412. yokatakana: 0x30E8,
  4413. yokatakanahalfwidth: 0xFF96,
  4414. yokorean: 0x315B,
  4415. yosmallhiragana: 0x3087,
  4416. yosmallkatakana: 0x30E7,
  4417. yosmallkatakanahalfwidth: 0xFF6E,
  4418. yotgreek: 0x03F3,
  4419. yoyaekorean: 0x3188,
  4420. yoyakorean: 0x3187,
  4421. yoyakthai: 0x0E22,
  4422. yoyingthai: 0x0E0D,
  4423. yparen: 0x24B4,
  4424. ypogegrammeni: 0x037A,
  4425. ypogegrammenigreekcmb: 0x0345,
  4426. yr: 0x01A6,
  4427. yring: 0x1E99,
  4428. ysuperior: 0x02B8,
  4429. ytilde: 0x1EF9,
  4430. yturned: 0x028E,
  4431. yuhiragana: 0x3086,
  4432. yuikorean: 0x318C,
  4433. yukatakana: 0x30E6,
  4434. yukatakanahalfwidth: 0xFF95,
  4435. yukorean: 0x3160,
  4436. yusbigcyrillic: 0x046B,
  4437. yusbigiotifiedcyrillic: 0x046D,
  4438. yuslittlecyrillic: 0x0467,
  4439. yuslittleiotifiedcyrillic: 0x0469,
  4440. yusmallhiragana: 0x3085,
  4441. yusmallkatakana: 0x30E5,
  4442. yusmallkatakanahalfwidth: 0xFF6D,
  4443. yuyekorean: 0x318B,
  4444. yuyeokorean: 0x318A,
  4445. yyabengali: 0x09DF,
  4446. yyadeva: 0x095F,
  4447. z: 0x007A,
  4448. zaarmenian: 0x0566,
  4449. zacute: 0x017A,
  4450. zadeva: 0x095B,
  4451. zagurmukhi: 0x0A5B,
  4452. zaharabic: 0x0638,
  4453. zahfinalarabic: 0xFEC6,
  4454. zahinitialarabic: 0xFEC7,
  4455. zahiragana: 0x3056,
  4456. zahmedialarabic: 0xFEC8,
  4457. zainarabic: 0x0632,
  4458. zainfinalarabic: 0xFEB0,
  4459. zakatakana: 0x30B6,
  4460. zaqefgadolhebrew: 0x0595,
  4461. zaqefqatanhebrew: 0x0594,
  4462. zarqahebrew: 0x0598,
  4463. zayin: 0x05D6,
  4464. zayindagesh: 0xFB36,
  4465. zayindageshhebrew: 0xFB36,
  4466. zayinhebrew: 0x05D6,
  4467. zbopomofo: 0x3117,
  4468. zcaron: 0x017E,
  4469. zcircle: 0x24E9,
  4470. zcircumflex: 0x1E91,
  4471. zcurl: 0x0291,
  4472. zdot: 0x017C,
  4473. zdotaccent: 0x017C,
  4474. zdotbelow: 0x1E93,
  4475. zecyrillic: 0x0437,
  4476. zedescendercyrillic: 0x0499,
  4477. zedieresiscyrillic: 0x04DF,
  4478. zehiragana: 0x305C,
  4479. zekatakana: 0x30BC,
  4480. zero: 0x0030,
  4481. zeroarabic: 0x0660,
  4482. zerobengali: 0x09E6,
  4483. zerodeva: 0x0966,
  4484. zerogujarati: 0x0AE6,
  4485. zerogurmukhi: 0x0A66,
  4486. zerohackarabic: 0x0660,
  4487. zeroinferior: 0x2080,
  4488. zeromonospace: 0xFF10,
  4489. zerooldstyle: 0xF730,
  4490. zeropersian: 0x06F0,
  4491. zerosuperior: 0x2070,
  4492. zerothai: 0x0E50,
  4493. zerowidthjoiner: 0xFEFF,
  4494. zerowidthnonjoiner: 0x200C,
  4495. zerowidthspace: 0x200B,
  4496. zeta: 0x03B6,
  4497. zhbopomofo: 0x3113,
  4498. zhearmenian: 0x056A,
  4499. zhebrevecyrillic: 0x04C2,
  4500. zhecyrillic: 0x0436,
  4501. zhedescendercyrillic: 0x0497,
  4502. zhedieresiscyrillic: 0x04DD,
  4503. zihiragana: 0x3058,
  4504. zikatakana: 0x30B8,
  4505. zinorhebrew: 0x05AE,
  4506. zlinebelow: 0x1E95,
  4507. zmonospace: 0xFF5A,
  4508. zohiragana: 0x305E,
  4509. zokatakana: 0x30BE,
  4510. zparen: 0x24B5,
  4511. zretroflexhook: 0x0290,
  4512. zstroke: 0x01B6,
  4513. zuhiragana: 0x305A,
  4514. zukatakana: 0x30BA,
  4515. '.notdef': 0x0000
  4516. };
  4517. var DingbatsGlyphsUnicode = {
  4518. space: 0x0020,
  4519. a1: 0x2701,
  4520. a2: 0x2702,
  4521. a202: 0x2703,
  4522. a3: 0x2704,
  4523. a4: 0x260E,
  4524. a5: 0x2706,
  4525. a119: 0x2707,
  4526. a118: 0x2708,
  4527. a117: 0x2709,
  4528. a11: 0x261B,
  4529. a12: 0x261E,
  4530. a13: 0x270C,
  4531. a14: 0x270D,
  4532. a15: 0x270E,
  4533. a16: 0x270F,
  4534. a105: 0x2710,
  4535. a17: 0x2711,
  4536. a18: 0x2712,
  4537. a19: 0x2713,
  4538. a20: 0x2714,
  4539. a21: 0x2715,
  4540. a22: 0x2716,
  4541. a23: 0x2717,
  4542. a24: 0x2718,
  4543. a25: 0x2719,
  4544. a26: 0x271A,
  4545. a27: 0x271B,
  4546. a28: 0x271C,
  4547. a6: 0x271D,
  4548. a7: 0x271E,
  4549. a8: 0x271F,
  4550. a9: 0x2720,
  4551. a10: 0x2721,
  4552. a29: 0x2722,
  4553. a30: 0x2723,
  4554. a31: 0x2724,
  4555. a32: 0x2725,
  4556. a33: 0x2726,
  4557. a34: 0x2727,
  4558. a35: 0x2605,
  4559. a36: 0x2729,
  4560. a37: 0x272A,
  4561. a38: 0x272B,
  4562. a39: 0x272C,
  4563. a40: 0x272D,
  4564. a41: 0x272E,
  4565. a42: 0x272F,
  4566. a43: 0x2730,
  4567. a44: 0x2731,
  4568. a45: 0x2732,
  4569. a46: 0x2733,
  4570. a47: 0x2734,
  4571. a48: 0x2735,
  4572. a49: 0x2736,
  4573. a50: 0x2737,
  4574. a51: 0x2738,
  4575. a52: 0x2739,
  4576. a53: 0x273A,
  4577. a54: 0x273B,
  4578. a55: 0x273C,
  4579. a56: 0x273D,
  4580. a57: 0x273E,
  4581. a58: 0x273F,
  4582. a59: 0x2740,
  4583. a60: 0x2741,
  4584. a61: 0x2742,
  4585. a62: 0x2743,
  4586. a63: 0x2744,
  4587. a64: 0x2745,
  4588. a65: 0x2746,
  4589. a66: 0x2747,
  4590. a67: 0x2748,
  4591. a68: 0x2749,
  4592. a69: 0x274A,
  4593. a70: 0x274B,
  4594. a71: 0x25CF,
  4595. a72: 0x274D,
  4596. a73: 0x25A0,
  4597. a74: 0x274F,
  4598. a203: 0x2750,
  4599. a75: 0x2751,
  4600. a204: 0x2752,
  4601. a76: 0x25B2,
  4602. a77: 0x25BC,
  4603. a78: 0x25C6,
  4604. a79: 0x2756,
  4605. a81: 0x25D7,
  4606. a82: 0x2758,
  4607. a83: 0x2759,
  4608. a84: 0x275A,
  4609. a97: 0x275B,
  4610. a98: 0x275C,
  4611. a99: 0x275D,
  4612. a100: 0x275E,
  4613. a101: 0x2761,
  4614. a102: 0x2762,
  4615. a103: 0x2763,
  4616. a104: 0x2764,
  4617. a106: 0x2765,
  4618. a107: 0x2766,
  4619. a108: 0x2767,
  4620. a112: 0x2663,
  4621. a111: 0x2666,
  4622. a110: 0x2665,
  4623. a109: 0x2660,
  4624. a120: 0x2460,
  4625. a121: 0x2461,
  4626. a122: 0x2462,
  4627. a123: 0x2463,
  4628. a124: 0x2464,
  4629. a125: 0x2465,
  4630. a126: 0x2466,
  4631. a127: 0x2467,
  4632. a128: 0x2468,
  4633. a129: 0x2469,
  4634. a130: 0x2776,
  4635. a131: 0x2777,
  4636. a132: 0x2778,
  4637. a133: 0x2779,
  4638. a134: 0x277A,
  4639. a135: 0x277B,
  4640. a136: 0x277C,
  4641. a137: 0x277D,
  4642. a138: 0x277E,
  4643. a139: 0x277F,
  4644. a140: 0x2780,
  4645. a141: 0x2781,
  4646. a142: 0x2782,
  4647. a143: 0x2783,
  4648. a144: 0x2784,
  4649. a145: 0x2785,
  4650. a146: 0x2786,
  4651. a147: 0x2787,
  4652. a148: 0x2788,
  4653. a149: 0x2789,
  4654. a150: 0x278A,
  4655. a151: 0x278B,
  4656. a152: 0x278C,
  4657. a153: 0x278D,
  4658. a154: 0x278E,
  4659. a155: 0x278F,
  4660. a156: 0x2790,
  4661. a157: 0x2791,
  4662. a158: 0x2792,
  4663. a159: 0x2793,
  4664. a160: 0x2794,
  4665. a161: 0x2192,
  4666. a163: 0x2194,
  4667. a164: 0x2195,
  4668. a196: 0x2798,
  4669. a165: 0x2799,
  4670. a192: 0x279A,
  4671. a166: 0x279B,
  4672. a167: 0x279C,
  4673. a168: 0x279D,
  4674. a169: 0x279E,
  4675. a170: 0x279F,
  4676. a171: 0x27A0,
  4677. a172: 0x27A1,
  4678. a173: 0x27A2,
  4679. a162: 0x27A3,
  4680. a174: 0x27A4,
  4681. a175: 0x27A5,
  4682. a176: 0x27A6,
  4683. a177: 0x27A7,
  4684. a178: 0x27A8,
  4685. a179: 0x27A9,
  4686. a193: 0x27AA,
  4687. a180: 0x27AB,
  4688. a199: 0x27AC,
  4689. a181: 0x27AD,
  4690. a200: 0x27AE,
  4691. a182: 0x27AF,
  4692. a201: 0x27B1,
  4693. a183: 0x27B2,
  4694. a184: 0x27B3,
  4695. a197: 0x27B4,
  4696. a185: 0x27B5,
  4697. a194: 0x27B6,
  4698. a198: 0x27B7,
  4699. a186: 0x27B8,
  4700. a195: 0x27B9,
  4701. a187: 0x27BA,
  4702. a188: 0x27BB,
  4703. a189: 0x27BC,
  4704. a190: 0x27BD,
  4705. a191: 0x27BE,
  4706. a89: 0x2768, // 0xF8D7
  4707. a90: 0x2769, // 0xF8D8
  4708. a93: 0x276A, // 0xF8D9
  4709. a94: 0x276B, // 0xF8DA
  4710. a91: 0x276C, // 0xF8DB
  4711. a92: 0x276D, // 0xF8DC
  4712. a205: 0x276E, // 0xF8DD
  4713. a85: 0x276F, // 0xF8DE
  4714. a206: 0x2770, // 0xF8DF
  4715. a86: 0x2771, // 0xF8E0
  4716. a87: 0x2772, // 0xF8E1
  4717. a88: 0x2773, // 0xF8E2
  4718. a95: 0x2774, // 0xF8E3
  4719. a96: 0x2775, // 0xF8E4
  4720. '.notdef': 0x0000
  4721. };
  4722. exports.GlyphsUnicode = GlyphsUnicode;
  4723. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  4724. }));
  4725. (function (root, factory) {
  4726. {
  4727. factory((root.pdfjsCoreJpg = {}));
  4728. }
  4729. }(this, function (exports) {
  4730. /*
  4731. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  4732. version was created by github user notmasteryet
  4733. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  4734. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  4735. - The JFIF specification can be found in the JPEG File Interchange Format
  4736. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  4737. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  4738. in PostScript Level 2, Technical Note #5116
  4739. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  4740. */
  4741. var JpegImage = (function jpegImage() {
  4742. var dctZigZag = new Uint8Array([
  4743. 0,
  4744. 1, 8,
  4745. 16, 9, 2,
  4746. 3, 10, 17, 24,
  4747. 32, 25, 18, 11, 4,
  4748. 5, 12, 19, 26, 33, 40,
  4749. 48, 41, 34, 27, 20, 13, 6,
  4750. 7, 14, 21, 28, 35, 42, 49, 56,
  4751. 57, 50, 43, 36, 29, 22, 15,
  4752. 23, 30, 37, 44, 51, 58,
  4753. 59, 52, 45, 38, 31,
  4754. 39, 46, 53, 60,
  4755. 61, 54, 47,
  4756. 55, 62,
  4757. 63
  4758. ]);
  4759. var dctCos1 = 4017; // cos(pi/16)
  4760. var dctSin1 = 799; // sin(pi/16)
  4761. var dctCos3 = 3406; // cos(3*pi/16)
  4762. var dctSin3 = 2276; // sin(3*pi/16)
  4763. var dctCos6 = 1567; // cos(6*pi/16)
  4764. var dctSin6 = 3784; // sin(6*pi/16)
  4765. var dctSqrt2 = 5793; // sqrt(2)
  4766. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  4767. function constructor() {
  4768. }
  4769. function buildHuffmanTable(codeLengths, values) {
  4770. var k = 0, code = [], i, j, length = 16;
  4771. while (length > 0 && !codeLengths[length - 1]) {
  4772. length--;
  4773. }
  4774. code.push({children: [], index: 0});
  4775. var p = code[0], q;
  4776. for (i = 0; i < length; i++) {
  4777. for (j = 0; j < codeLengths[i]; j++) {
  4778. p = code.pop();
  4779. p.children[p.index] = values[k];
  4780. while (p.index > 0) {
  4781. p = code.pop();
  4782. }
  4783. p.index++;
  4784. code.push(p);
  4785. while (code.length <= i) {
  4786. code.push(q = {children: [], index: 0});
  4787. p.children[p.index] = q.children;
  4788. p = q;
  4789. }
  4790. k++;
  4791. }
  4792. if (i + 1 < length) {
  4793. // p here points to last code
  4794. code.push(q = {children: [], index: 0});
  4795. p.children[p.index] = q.children;
  4796. p = q;
  4797. }
  4798. }
  4799. return code[0].children;
  4800. }
  4801. function getBlockBufferOffset(component, row, col) {
  4802. return 64 * ((component.blocksPerLine + 1) * row + col);
  4803. }
  4804. function decodeScan(data, offset, frame, components, resetInterval,
  4805. spectralStart, spectralEnd, successivePrev, successive) {
  4806. var mcusPerLine = frame.mcusPerLine;
  4807. var progressive = frame.progressive;
  4808. var startOffset = offset, bitsData = 0, bitsCount = 0;
  4809. function readBit() {
  4810. if (bitsCount > 0) {
  4811. bitsCount--;
  4812. return (bitsData >> bitsCount) & 1;
  4813. }
  4814. bitsData = data[offset++];
  4815. if (bitsData === 0xFF) {
  4816. var nextByte = data[offset++];
  4817. if (nextByte) {
  4818. throw 'unexpected marker: ' +
  4819. ((bitsData << 8) | nextByte).toString(16);
  4820. }
  4821. // unstuff 0
  4822. }
  4823. bitsCount = 7;
  4824. return bitsData >>> 7;
  4825. }
  4826. function decodeHuffman(tree) {
  4827. var node = tree;
  4828. while (true) {
  4829. node = node[readBit()];
  4830. if (typeof node === 'number') {
  4831. return node;
  4832. }
  4833. if (typeof node !== 'object') {
  4834. throw 'invalid huffman sequence';
  4835. }
  4836. }
  4837. }
  4838. function receive(length) {
  4839. var n = 0;
  4840. while (length > 0) {
  4841. n = (n << 1) | readBit();
  4842. length--;
  4843. }
  4844. return n;
  4845. }
  4846. function receiveAndExtend(length) {
  4847. if (length === 1) {
  4848. return readBit() === 1 ? 1 : -1;
  4849. }
  4850. var n = receive(length);
  4851. if (n >= 1 << (length - 1)) {
  4852. return n;
  4853. }
  4854. return n + (-1 << length) + 1;
  4855. }
  4856. function decodeBaseline(component, offset) {
  4857. var t = decodeHuffman(component.huffmanTableDC);
  4858. var diff = t === 0 ? 0 : receiveAndExtend(t);
  4859. component.blockData[offset] = (component.pred += diff);
  4860. var k = 1;
  4861. while (k < 64) {
  4862. var rs = decodeHuffman(component.huffmanTableAC);
  4863. var s = rs & 15, r = rs >> 4;
  4864. if (s === 0) {
  4865. if (r < 15) {
  4866. break;
  4867. }
  4868. k += 16;
  4869. continue;
  4870. }
  4871. k += r;
  4872. var z = dctZigZag[k];
  4873. component.blockData[offset + z] = receiveAndExtend(s);
  4874. k++;
  4875. }
  4876. }
  4877. function decodeDCFirst(component, offset) {
  4878. var t = decodeHuffman(component.huffmanTableDC);
  4879. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  4880. component.blockData[offset] = (component.pred += diff);
  4881. }
  4882. function decodeDCSuccessive(component, offset) {
  4883. component.blockData[offset] |= readBit() << successive;
  4884. }
  4885. var eobrun = 0;
  4886. function decodeACFirst(component, offset) {
  4887. if (eobrun > 0) {
  4888. eobrun--;
  4889. return;
  4890. }
  4891. var k = spectralStart, e = spectralEnd;
  4892. while (k <= e) {
  4893. var rs = decodeHuffman(component.huffmanTableAC);
  4894. var s = rs & 15, r = rs >> 4;
  4895. if (s === 0) {
  4896. if (r < 15) {
  4897. eobrun = receive(r) + (1 << r) - 1;
  4898. break;
  4899. }
  4900. k += 16;
  4901. continue;
  4902. }
  4903. k += r;
  4904. var z = dctZigZag[k];
  4905. component.blockData[offset + z] =
  4906. receiveAndExtend(s) * (1 << successive);
  4907. k++;
  4908. }
  4909. }
  4910. var successiveACState = 0, successiveACNextValue;
  4911. function decodeACSuccessive(component, offset) {
  4912. var k = spectralStart;
  4913. var e = spectralEnd;
  4914. var r = 0;
  4915. var s;
  4916. var rs;
  4917. while (k <= e) {
  4918. var z = dctZigZag[k];
  4919. switch (successiveACState) {
  4920. case 0: // initial state
  4921. rs = decodeHuffman(component.huffmanTableAC);
  4922. s = rs & 15;
  4923. r = rs >> 4;
  4924. if (s === 0) {
  4925. if (r < 15) {
  4926. eobrun = receive(r) + (1 << r);
  4927. successiveACState = 4;
  4928. } else {
  4929. r = 16;
  4930. successiveACState = 1;
  4931. }
  4932. } else {
  4933. if (s !== 1) {
  4934. throw 'invalid ACn encoding';
  4935. }
  4936. successiveACNextValue = receiveAndExtend(s);
  4937. successiveACState = r ? 2 : 3;
  4938. }
  4939. continue;
  4940. case 1: // skipping r zero items
  4941. case 2:
  4942. if (component.blockData[offset + z]) {
  4943. component.blockData[offset + z] += (readBit() << successive);
  4944. } else {
  4945. r--;
  4946. if (r === 0) {
  4947. successiveACState = successiveACState === 2 ? 3 : 0;
  4948. }
  4949. }
  4950. break;
  4951. case 3: // set value for a zero item
  4952. if (component.blockData[offset + z]) {
  4953. component.blockData[offset + z] += (readBit() << successive);
  4954. } else {
  4955. component.blockData[offset + z] =
  4956. successiveACNextValue << successive;
  4957. successiveACState = 0;
  4958. }
  4959. break;
  4960. case 4: // eob
  4961. if (component.blockData[offset + z]) {
  4962. component.blockData[offset + z] += (readBit() << successive);
  4963. }
  4964. break;
  4965. }
  4966. k++;
  4967. }
  4968. if (successiveACState === 4) {
  4969. eobrun--;
  4970. if (eobrun === 0) {
  4971. successiveACState = 0;
  4972. }
  4973. }
  4974. }
  4975. function decodeMcu(component, decode, mcu, row, col) {
  4976. var mcuRow = (mcu / mcusPerLine) | 0;
  4977. var mcuCol = mcu % mcusPerLine;
  4978. var blockRow = mcuRow * component.v + row;
  4979. var blockCol = mcuCol * component.h + col;
  4980. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4981. decode(component, offset);
  4982. }
  4983. function decodeBlock(component, decode, mcu) {
  4984. var blockRow = (mcu / component.blocksPerLine) | 0;
  4985. var blockCol = mcu % component.blocksPerLine;
  4986. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4987. decode(component, offset);
  4988. }
  4989. var componentsLength = components.length;
  4990. var component, i, j, k, n;
  4991. var decodeFn;
  4992. if (progressive) {
  4993. if (spectralStart === 0) {
  4994. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  4995. } else {
  4996. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  4997. }
  4998. } else {
  4999. decodeFn = decodeBaseline;
  5000. }
  5001. var mcu = 0, marker;
  5002. var mcuExpected;
  5003. if (componentsLength === 1) {
  5004. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  5005. } else {
  5006. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  5007. }
  5008. if (!resetInterval) {
  5009. resetInterval = mcuExpected;
  5010. }
  5011. var h, v;
  5012. while (mcu < mcuExpected) {
  5013. // reset interval stuff
  5014. for (i = 0; i < componentsLength; i++) {
  5015. components[i].pred = 0;
  5016. }
  5017. eobrun = 0;
  5018. if (componentsLength === 1) {
  5019. component = components[0];
  5020. for (n = 0; n < resetInterval; n++) {
  5021. decodeBlock(component, decodeFn, mcu);
  5022. mcu++;
  5023. }
  5024. } else {
  5025. for (n = 0; n < resetInterval; n++) {
  5026. for (i = 0; i < componentsLength; i++) {
  5027. component = components[i];
  5028. h = component.h;
  5029. v = component.v;
  5030. for (j = 0; j < v; j++) {
  5031. for (k = 0; k < h; k++) {
  5032. decodeMcu(component, decodeFn, mcu, j, k);
  5033. }
  5034. }
  5035. }
  5036. mcu++;
  5037. }
  5038. }
  5039. // find marker
  5040. bitsCount = 0;
  5041. marker = (data[offset] << 8) | data[offset + 1];
  5042. if (marker <= 0xFF00) {
  5043. throw 'marker was not found';
  5044. }
  5045. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  5046. offset += 2;
  5047. } else {
  5048. break;
  5049. }
  5050. }
  5051. return offset - startOffset;
  5052. }
  5053. // A port of poppler's IDCT method which in turn is taken from:
  5054. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  5055. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  5056. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  5057. // 988-991.
  5058. function quantizeAndInverse(component, blockBufferOffset, p) {
  5059. var qt = component.quantizationTable, blockData = component.blockData;
  5060. var v0, v1, v2, v3, v4, v5, v6, v7;
  5061. var p0, p1, p2, p3, p4, p5, p6, p7;
  5062. var t;
  5063. // inverse DCT on rows
  5064. for (var row = 0; row < 64; row += 8) {
  5065. // gather block data
  5066. p0 = blockData[blockBufferOffset + row];
  5067. p1 = blockData[blockBufferOffset + row + 1];
  5068. p2 = blockData[blockBufferOffset + row + 2];
  5069. p3 = blockData[blockBufferOffset + row + 3];
  5070. p4 = blockData[blockBufferOffset + row + 4];
  5071. p5 = blockData[blockBufferOffset + row + 5];
  5072. p6 = blockData[blockBufferOffset + row + 6];
  5073. p7 = blockData[blockBufferOffset + row + 7];
  5074. // dequant p0
  5075. p0 *= qt[row];
  5076. // check for all-zero AC coefficients
  5077. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5078. t = (dctSqrt2 * p0 + 512) >> 10;
  5079. p[row] = t;
  5080. p[row + 1] = t;
  5081. p[row + 2] = t;
  5082. p[row + 3] = t;
  5083. p[row + 4] = t;
  5084. p[row + 5] = t;
  5085. p[row + 6] = t;
  5086. p[row + 7] = t;
  5087. continue;
  5088. }
  5089. // dequant p1 ... p7
  5090. p1 *= qt[row + 1];
  5091. p2 *= qt[row + 2];
  5092. p3 *= qt[row + 3];
  5093. p4 *= qt[row + 4];
  5094. p5 *= qt[row + 5];
  5095. p6 *= qt[row + 6];
  5096. p7 *= qt[row + 7];
  5097. // stage 4
  5098. v0 = (dctSqrt2 * p0 + 128) >> 8;
  5099. v1 = (dctSqrt2 * p4 + 128) >> 8;
  5100. v2 = p2;
  5101. v3 = p6;
  5102. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  5103. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  5104. v5 = p3 << 4;
  5105. v6 = p5 << 4;
  5106. // stage 3
  5107. v0 = (v0 + v1 + 1) >> 1;
  5108. v1 = v0 - v1;
  5109. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  5110. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  5111. v3 = t;
  5112. v4 = (v4 + v6 + 1) >> 1;
  5113. v6 = v4 - v6;
  5114. v7 = (v7 + v5 + 1) >> 1;
  5115. v5 = v7 - v5;
  5116. // stage 2
  5117. v0 = (v0 + v3 + 1) >> 1;
  5118. v3 = v0 - v3;
  5119. v1 = (v1 + v2 + 1) >> 1;
  5120. v2 = v1 - v2;
  5121. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5122. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5123. v7 = t;
  5124. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5125. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5126. v6 = t;
  5127. // stage 1
  5128. p[row] = v0 + v7;
  5129. p[row + 7] = v0 - v7;
  5130. p[row + 1] = v1 + v6;
  5131. p[row + 6] = v1 - v6;
  5132. p[row + 2] = v2 + v5;
  5133. p[row + 5] = v2 - v5;
  5134. p[row + 3] = v3 + v4;
  5135. p[row + 4] = v3 - v4;
  5136. }
  5137. // inverse DCT on columns
  5138. for (var col = 0; col < 8; ++col) {
  5139. p0 = p[col];
  5140. p1 = p[col + 8];
  5141. p2 = p[col + 16];
  5142. p3 = p[col + 24];
  5143. p4 = p[col + 32];
  5144. p5 = p[col + 40];
  5145. p6 = p[col + 48];
  5146. p7 = p[col + 56];
  5147. // check for all-zero AC coefficients
  5148. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5149. t = (dctSqrt2 * p0 + 8192) >> 14;
  5150. // convert to 8 bit
  5151. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  5152. blockData[blockBufferOffset + col] = t;
  5153. blockData[blockBufferOffset + col + 8] = t;
  5154. blockData[blockBufferOffset + col + 16] = t;
  5155. blockData[blockBufferOffset + col + 24] = t;
  5156. blockData[blockBufferOffset + col + 32] = t;
  5157. blockData[blockBufferOffset + col + 40] = t;
  5158. blockData[blockBufferOffset + col + 48] = t;
  5159. blockData[blockBufferOffset + col + 56] = t;
  5160. continue;
  5161. }
  5162. // stage 4
  5163. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  5164. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  5165. v2 = p2;
  5166. v3 = p6;
  5167. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  5168. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  5169. v5 = p3;
  5170. v6 = p5;
  5171. // stage 3
  5172. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  5173. // converting to UInt8 range later.
  5174. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  5175. v1 = v0 - v1;
  5176. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  5177. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  5178. v3 = t;
  5179. v4 = (v4 + v6 + 1) >> 1;
  5180. v6 = v4 - v6;
  5181. v7 = (v7 + v5 + 1) >> 1;
  5182. v5 = v7 - v5;
  5183. // stage 2
  5184. v0 = (v0 + v3 + 1) >> 1;
  5185. v3 = v0 - v3;
  5186. v1 = (v1 + v2 + 1) >> 1;
  5187. v2 = v1 - v2;
  5188. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5189. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5190. v7 = t;
  5191. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5192. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5193. v6 = t;
  5194. // stage 1
  5195. p0 = v0 + v7;
  5196. p7 = v0 - v7;
  5197. p1 = v1 + v6;
  5198. p6 = v1 - v6;
  5199. p2 = v2 + v5;
  5200. p5 = v2 - v5;
  5201. p3 = v3 + v4;
  5202. p4 = v3 - v4;
  5203. // convert to 8-bit integers
  5204. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  5205. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  5206. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  5207. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  5208. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  5209. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  5210. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  5211. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  5212. // store block data
  5213. blockData[blockBufferOffset + col] = p0;
  5214. blockData[blockBufferOffset + col + 8] = p1;
  5215. blockData[blockBufferOffset + col + 16] = p2;
  5216. blockData[blockBufferOffset + col + 24] = p3;
  5217. blockData[blockBufferOffset + col + 32] = p4;
  5218. blockData[blockBufferOffset + col + 40] = p5;
  5219. blockData[blockBufferOffset + col + 48] = p6;
  5220. blockData[blockBufferOffset + col + 56] = p7;
  5221. }
  5222. }
  5223. function buildComponentData(frame, component) {
  5224. var blocksPerLine = component.blocksPerLine;
  5225. var blocksPerColumn = component.blocksPerColumn;
  5226. var computationBuffer = new Int16Array(64);
  5227. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  5228. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  5229. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  5230. quantizeAndInverse(component, offset, computationBuffer);
  5231. }
  5232. }
  5233. return component.blockData;
  5234. }
  5235. function clamp0to255(a) {
  5236. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  5237. }
  5238. constructor.prototype = {
  5239. parse: function parse(data) {
  5240. function readUint16() {
  5241. var value = (data[offset] << 8) | data[offset + 1];
  5242. offset += 2;
  5243. return value;
  5244. }
  5245. function readDataBlock() {
  5246. var length = readUint16();
  5247. var array = data.subarray(offset, offset + length - 2);
  5248. offset += array.length;
  5249. return array;
  5250. }
  5251. function prepareComponents(frame) {
  5252. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  5253. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  5254. for (var i = 0; i < frame.components.length; i++) {
  5255. component = frame.components[i];
  5256. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  5257. component.h / frame.maxH);
  5258. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  5259. component.v / frame.maxV);
  5260. var blocksPerLineForMcu = mcusPerLine * component.h;
  5261. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  5262. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  5263. (blocksPerLineForMcu + 1);
  5264. component.blockData = new Int16Array(blocksBufferSize);
  5265. component.blocksPerLine = blocksPerLine;
  5266. component.blocksPerColumn = blocksPerColumn;
  5267. }
  5268. frame.mcusPerLine = mcusPerLine;
  5269. frame.mcusPerColumn = mcusPerColumn;
  5270. }
  5271. var offset = 0;
  5272. var jfif = null;
  5273. var adobe = null;
  5274. var frame, resetInterval;
  5275. var quantizationTables = [];
  5276. var huffmanTablesAC = [], huffmanTablesDC = [];
  5277. var fileMarker = readUint16();
  5278. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  5279. throw 'SOI not found';
  5280. }
  5281. fileMarker = readUint16();
  5282. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  5283. var i, j, l;
  5284. switch(fileMarker) {
  5285. case 0xFFE0: // APP0 (Application Specific)
  5286. case 0xFFE1: // APP1
  5287. case 0xFFE2: // APP2
  5288. case 0xFFE3: // APP3
  5289. case 0xFFE4: // APP4
  5290. case 0xFFE5: // APP5
  5291. case 0xFFE6: // APP6
  5292. case 0xFFE7: // APP7
  5293. case 0xFFE8: // APP8
  5294. case 0xFFE9: // APP9
  5295. case 0xFFEA: // APP10
  5296. case 0xFFEB: // APP11
  5297. case 0xFFEC: // APP12
  5298. case 0xFFED: // APP13
  5299. case 0xFFEE: // APP14
  5300. case 0xFFEF: // APP15
  5301. case 0xFFFE: // COM (Comment)
  5302. var appData = readDataBlock();
  5303. if (fileMarker === 0xFFE0) {
  5304. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  5305. appData[2] === 0x49 && appData[3] === 0x46 &&
  5306. appData[4] === 0) { // 'JFIF\x00'
  5307. jfif = {
  5308. version: { major: appData[5], minor: appData[6] },
  5309. densityUnits: appData[7],
  5310. xDensity: (appData[8] << 8) | appData[9],
  5311. yDensity: (appData[10] << 8) | appData[11],
  5312. thumbWidth: appData[12],
  5313. thumbHeight: appData[13],
  5314. thumbData: appData.subarray(14, 14 +
  5315. 3 * appData[12] * appData[13])
  5316. };
  5317. }
  5318. }
  5319. // TODO APP1 - Exif
  5320. if (fileMarker === 0xFFEE) {
  5321. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  5322. appData[2] === 0x6F && appData[3] === 0x62 &&
  5323. appData[4] === 0x65) { // 'Adobe'
  5324. adobe = {
  5325. version: (appData[5] << 8) | appData[6],
  5326. flags0: (appData[7] << 8) | appData[8],
  5327. flags1: (appData[9] << 8) | appData[10],
  5328. transformCode: appData[11]
  5329. };
  5330. }
  5331. }
  5332. break;
  5333. case 0xFFDB: // DQT (Define Quantization Tables)
  5334. var quantizationTablesLength = readUint16();
  5335. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  5336. var z;
  5337. while (offset < quantizationTablesEnd) {
  5338. var quantizationTableSpec = data[offset++];
  5339. var tableData = new Uint16Array(64);
  5340. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  5341. for (j = 0; j < 64; j++) {
  5342. z = dctZigZag[j];
  5343. tableData[z] = data[offset++];
  5344. }
  5345. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  5346. for (j = 0; j < 64; j++) {
  5347. z = dctZigZag[j];
  5348. tableData[z] = readUint16();
  5349. }
  5350. } else {
  5351. throw 'DQT: invalid table spec';
  5352. }
  5353. quantizationTables[quantizationTableSpec & 15] = tableData;
  5354. }
  5355. break;
  5356. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  5357. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  5358. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  5359. if (frame) {
  5360. throw 'Only single frame JPEGs supported';
  5361. }
  5362. readUint16(); // skip data length
  5363. frame = {};
  5364. frame.extended = (fileMarker === 0xFFC1);
  5365. frame.progressive = (fileMarker === 0xFFC2);
  5366. frame.precision = data[offset++];
  5367. frame.scanLines = readUint16();
  5368. frame.samplesPerLine = readUint16();
  5369. frame.components = [];
  5370. frame.componentIds = {};
  5371. var componentsCount = data[offset++], componentId;
  5372. var maxH = 0, maxV = 0;
  5373. for (i = 0; i < componentsCount; i++) {
  5374. componentId = data[offset];
  5375. var h = data[offset + 1] >> 4;
  5376. var v = data[offset + 1] & 15;
  5377. if (maxH < h) {
  5378. maxH = h;
  5379. }
  5380. if (maxV < v) {
  5381. maxV = v;
  5382. }
  5383. var qId = data[offset + 2];
  5384. l = frame.components.push({
  5385. h: h,
  5386. v: v,
  5387. quantizationTable: quantizationTables[qId]
  5388. });
  5389. frame.componentIds[componentId] = l - 1;
  5390. offset += 3;
  5391. }
  5392. frame.maxH = maxH;
  5393. frame.maxV = maxV;
  5394. prepareComponents(frame);
  5395. break;
  5396. case 0xFFC4: // DHT (Define Huffman Tables)
  5397. var huffmanLength = readUint16();
  5398. for (i = 2; i < huffmanLength;) {
  5399. var huffmanTableSpec = data[offset++];
  5400. var codeLengths = new Uint8Array(16);
  5401. var codeLengthSum = 0;
  5402. for (j = 0; j < 16; j++, offset++) {
  5403. codeLengthSum += (codeLengths[j] = data[offset]);
  5404. }
  5405. var huffmanValues = new Uint8Array(codeLengthSum);
  5406. for (j = 0; j < codeLengthSum; j++, offset++) {
  5407. huffmanValues[j] = data[offset];
  5408. }
  5409. i += 17 + codeLengthSum;
  5410. ((huffmanTableSpec >> 4) === 0 ?
  5411. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  5412. buildHuffmanTable(codeLengths, huffmanValues);
  5413. }
  5414. break;
  5415. case 0xFFDD: // DRI (Define Restart Interval)
  5416. readUint16(); // skip data length
  5417. resetInterval = readUint16();
  5418. break;
  5419. case 0xFFDA: // SOS (Start of Scan)
  5420. var scanLength = readUint16();
  5421. var selectorsCount = data[offset++];
  5422. var components = [], component;
  5423. for (i = 0; i < selectorsCount; i++) {
  5424. var componentIndex = frame.componentIds[data[offset++]];
  5425. component = frame.components[componentIndex];
  5426. var tableSpec = data[offset++];
  5427. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  5428. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  5429. components.push(component);
  5430. }
  5431. var spectralStart = data[offset++];
  5432. var spectralEnd = data[offset++];
  5433. var successiveApproximation = data[offset++];
  5434. var processed = decodeScan(data, offset,
  5435. frame, components, resetInterval,
  5436. spectralStart, spectralEnd,
  5437. successiveApproximation >> 4, successiveApproximation & 15);
  5438. offset += processed;
  5439. break;
  5440. case 0xFFFF: // Fill bytes
  5441. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  5442. offset--;
  5443. }
  5444. break;
  5445. default:
  5446. if (data[offset - 3] === 0xFF &&
  5447. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  5448. // could be incorrect encoding -- last 0xFF byte of the previous
  5449. // block was eaten by the encoder
  5450. offset -= 3;
  5451. break;
  5452. }
  5453. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  5454. }
  5455. fileMarker = readUint16();
  5456. }
  5457. this.width = frame.samplesPerLine;
  5458. this.height = frame.scanLines;
  5459. this.jfif = jfif;
  5460. this.adobe = adobe;
  5461. this.components = [];
  5462. for (i = 0; i < frame.components.length; i++) {
  5463. component = frame.components[i];
  5464. this.components.push({
  5465. output: buildComponentData(frame, component),
  5466. scaleX: component.h / frame.maxH,
  5467. scaleY: component.v / frame.maxV,
  5468. blocksPerLine: component.blocksPerLine,
  5469. blocksPerColumn: component.blocksPerColumn
  5470. });
  5471. }
  5472. this.numComponents = this.components.length;
  5473. },
  5474. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  5475. var scaleX = this.width / width, scaleY = this.height / height;
  5476. var component, componentScaleX, componentScaleY, blocksPerScanline;
  5477. var x, y, i, j, k;
  5478. var index;
  5479. var offset = 0;
  5480. var output;
  5481. var numComponents = this.components.length;
  5482. var dataLength = width * height * numComponents;
  5483. var data = new Uint8Array(dataLength);
  5484. var xScaleBlockOffset = new Uint32Array(width);
  5485. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  5486. for (i = 0; i < numComponents; i++) {
  5487. component = this.components[i];
  5488. componentScaleX = component.scaleX * scaleX;
  5489. componentScaleY = component.scaleY * scaleY;
  5490. offset = i;
  5491. output = component.output;
  5492. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  5493. // precalculate the xScaleBlockOffset
  5494. for (x = 0; x < width; x++) {
  5495. j = 0 | (x * componentScaleX);
  5496. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  5497. }
  5498. // linearize the blocks of the component
  5499. for (y = 0; y < height; y++) {
  5500. j = 0 | (y * componentScaleY);
  5501. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  5502. for (x = 0; x < width; x++) {
  5503. data[offset] = output[index + xScaleBlockOffset[x]];
  5504. offset += numComponents;
  5505. }
  5506. }
  5507. }
  5508. // decodeTransform contains pairs of multiplier (-256..256) and additive
  5509. var transform = this.decodeTransform;
  5510. if (transform) {
  5511. for (i = 0; i < dataLength;) {
  5512. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  5513. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  5514. }
  5515. }
  5516. }
  5517. return data;
  5518. },
  5519. _isColorConversionNeeded: function isColorConversionNeeded() {
  5520. if (this.adobe && this.adobe.transformCode) {
  5521. // The adobe transform marker overrides any previous setting
  5522. return true;
  5523. } else if (this.numComponents === 3) {
  5524. return true;
  5525. } else {
  5526. return false;
  5527. }
  5528. },
  5529. _convertYccToRgb: function convertYccToRgb(data) {
  5530. var Y, Cb, Cr;
  5531. for (var i = 0, length = data.length; i < length; i += 3) {
  5532. Y = data[i ];
  5533. Cb = data[i + 1];
  5534. Cr = data[i + 2];
  5535. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  5536. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  5537. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  5538. }
  5539. return data;
  5540. },
  5541. _convertYcckToRgb: function convertYcckToRgb(data) {
  5542. var Y, Cb, Cr, k;
  5543. var offset = 0;
  5544. for (var i = 0, length = data.length; i < length; i += 4) {
  5545. Y = data[i];
  5546. Cb = data[i + 1];
  5547. Cr = data[i + 2];
  5548. k = data[i + 3];
  5549. var r = -122.67195406894 +
  5550. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  5551. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  5552. 0.154362151871126) +
  5553. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  5554. 0.00477271405408747 * k + 1.53380253221734) +
  5555. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  5556. 0.48357088451265) +
  5557. k * (-0.000336197177618394 * k + 0.484791561490776);
  5558. var g = 107.268039397724 +
  5559. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  5560. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  5561. 0.176491792462875) +
  5562. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  5563. 0.000770482631801132 * k - 0.151051492775562) +
  5564. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  5565. 0.25802910206845) +
  5566. k * (-0.000318913117588328 * k - 0.213742400323665);
  5567. var b = -20.810012546947 +
  5568. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  5569. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  5570. 0.814272968359295) +
  5571. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  5572. 0.000560833691242812 * k - 0.195152027534049) +
  5573. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  5574. 0.116935020465145) +
  5575. k * (-0.000343531996510555 * k + 0.24165260232407);
  5576. data[offset++] = clamp0to255(r);
  5577. data[offset++] = clamp0to255(g);
  5578. data[offset++] = clamp0to255(b);
  5579. }
  5580. return data;
  5581. },
  5582. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  5583. var Y, Cb, Cr;
  5584. for (var i = 0, length = data.length; i < length; i += 4) {
  5585. Y = data[i];
  5586. Cb = data[i + 1];
  5587. Cr = data[i + 2];
  5588. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  5589. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  5590. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  5591. // K in data[i + 3] is unchanged
  5592. }
  5593. return data;
  5594. },
  5595. _convertCmykToRgb: function convertCmykToRgb(data) {
  5596. var c, m, y, k;
  5597. var offset = 0;
  5598. var min = -255 * 255 * 255;
  5599. var scale = 1 / 255 / 255;
  5600. for (var i = 0, length = data.length; i < length; i += 4) {
  5601. c = data[i];
  5602. m = data[i + 1];
  5603. y = data[i + 2];
  5604. k = data[i + 3];
  5605. var r =
  5606. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  5607. 18.82290502165302 * y + 212.25662451639585 * k -
  5608. 72734.4411664936) +
  5609. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  5610. 17.873870861415444 * k - 1401.7366389350734) +
  5611. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  5612. 4465.541406466231) -
  5613. k * (21.86122147463605 * k + 48317.86113160301);
  5614. var g =
  5615. c * (8.841041422036149 * c + 60.118027045597366 * m +
  5616. 6.871425592049007 * y + 31.159100130055922 * k -
  5617. 20220.756542821975) +
  5618. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  5619. 131.35250912493976 * k - 48691.05921601825) +
  5620. y * (4.444339102852739 * y + 9.8632861493405 * k -
  5621. 6341.191035517494) -
  5622. k * (20.737325471181034 * k + 47890.15695978492);
  5623. var b =
  5624. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  5625. 30.89978309703729 * y - 0.23883238689178934 * k -
  5626. 3616.812083916688) +
  5627. m * (10.49593273432072 * m + 63.02378494754052 * y +
  5628. 50.606957656360734 * k - 28620.90484698408) +
  5629. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  5630. 49363.43385999684) -
  5631. k * (22.33816807309886 * k + 45932.16563550634);
  5632. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  5633. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  5634. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  5635. }
  5636. return data;
  5637. },
  5638. getData: function getData(width, height, forceRGBoutput) {
  5639. if (this.numComponents > 4) {
  5640. throw 'Unsupported color mode';
  5641. }
  5642. // type of data: Uint8Array(width * height * numComponents)
  5643. var data = this._getLinearizedBlockData(width, height);
  5644. if (this.numComponents === 3) {
  5645. return this._convertYccToRgb(data);
  5646. } else if (this.numComponents === 4) {
  5647. if (this._isColorConversionNeeded()) {
  5648. if (forceRGBoutput) {
  5649. return this._convertYcckToRgb(data);
  5650. } else {
  5651. return this._convertYcckToCmyk(data);
  5652. }
  5653. } else if (forceRGBoutput) {
  5654. return this._convertCmykToRgb(data);
  5655. }
  5656. }
  5657. return data;
  5658. }
  5659. };
  5660. return constructor;
  5661. })();
  5662. exports.JpegImage = JpegImage;
  5663. }));
  5664. (function (root, factory) {
  5665. {
  5666. factory((root.pdfjsCoreMetrics = {}));
  5667. }
  5668. }(this, function (exports) {
  5669. // The Metrics object contains glyph widths (in glyph space units).
  5670. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  5671. // space unit corresponds to 1/1000th of text space unit.
  5672. var Metrics = {
  5673. 'Courier': 600,
  5674. 'Courier-Bold': 600,
  5675. 'Courier-BoldOblique': 600,
  5676. 'Courier-Oblique': 600,
  5677. 'Helvetica' : {
  5678. 'space': 278,
  5679. 'exclam': 278,
  5680. 'quotedbl': 355,
  5681. 'numbersign': 556,
  5682. 'dollar': 556,
  5683. 'percent': 889,
  5684. 'ampersand': 667,
  5685. 'quoteright': 222,
  5686. 'parenleft': 333,
  5687. 'parenright': 333,
  5688. 'asterisk': 389,
  5689. 'plus': 584,
  5690. 'comma': 278,
  5691. 'hyphen': 333,
  5692. 'period': 278,
  5693. 'slash': 278,
  5694. 'zero': 556,
  5695. 'one': 556,
  5696. 'two': 556,
  5697. 'three': 556,
  5698. 'four': 556,
  5699. 'five': 556,
  5700. 'six': 556,
  5701. 'seven': 556,
  5702. 'eight': 556,
  5703. 'nine': 556,
  5704. 'colon': 278,
  5705. 'semicolon': 278,
  5706. 'less': 584,
  5707. 'equal': 584,
  5708. 'greater': 584,
  5709. 'question': 556,
  5710. 'at': 1015,
  5711. 'A': 667,
  5712. 'B': 667,
  5713. 'C': 722,
  5714. 'D': 722,
  5715. 'E': 667,
  5716. 'F': 611,
  5717. 'G': 778,
  5718. 'H': 722,
  5719. 'I': 278,
  5720. 'J': 500,
  5721. 'K': 667,
  5722. 'L': 556,
  5723. 'M': 833,
  5724. 'N': 722,
  5725. 'O': 778,
  5726. 'P': 667,
  5727. 'Q': 778,
  5728. 'R': 722,
  5729. 'S': 667,
  5730. 'T': 611,
  5731. 'U': 722,
  5732. 'V': 667,
  5733. 'W': 944,
  5734. 'X': 667,
  5735. 'Y': 667,
  5736. 'Z': 611,
  5737. 'bracketleft': 278,
  5738. 'backslash': 278,
  5739. 'bracketright': 278,
  5740. 'asciicircum': 469,
  5741. 'underscore': 556,
  5742. 'quoteleft': 222,
  5743. 'a': 556,
  5744. 'b': 556,
  5745. 'c': 500,
  5746. 'd': 556,
  5747. 'e': 556,
  5748. 'f': 278,
  5749. 'g': 556,
  5750. 'h': 556,
  5751. 'i': 222,
  5752. 'j': 222,
  5753. 'k': 500,
  5754. 'l': 222,
  5755. 'm': 833,
  5756. 'n': 556,
  5757. 'o': 556,
  5758. 'p': 556,
  5759. 'q': 556,
  5760. 'r': 333,
  5761. 's': 500,
  5762. 't': 278,
  5763. 'u': 556,
  5764. 'v': 500,
  5765. 'w': 722,
  5766. 'x': 500,
  5767. 'y': 500,
  5768. 'z': 500,
  5769. 'braceleft': 334,
  5770. 'bar': 260,
  5771. 'braceright': 334,
  5772. 'asciitilde': 584,
  5773. 'exclamdown': 333,
  5774. 'cent': 556,
  5775. 'sterling': 556,
  5776. 'fraction': 167,
  5777. 'yen': 556,
  5778. 'florin': 556,
  5779. 'section': 556,
  5780. 'currency': 556,
  5781. 'quotesingle': 191,
  5782. 'quotedblleft': 333,
  5783. 'guillemotleft': 556,
  5784. 'guilsinglleft': 333,
  5785. 'guilsinglright': 333,
  5786. 'fi': 500,
  5787. 'fl': 500,
  5788. 'endash': 556,
  5789. 'dagger': 556,
  5790. 'daggerdbl': 556,
  5791. 'periodcentered': 278,
  5792. 'paragraph': 537,
  5793. 'bullet': 350,
  5794. 'quotesinglbase': 222,
  5795. 'quotedblbase': 333,
  5796. 'quotedblright': 333,
  5797. 'guillemotright': 556,
  5798. 'ellipsis': 1000,
  5799. 'perthousand': 1000,
  5800. 'questiondown': 611,
  5801. 'grave': 333,
  5802. 'acute': 333,
  5803. 'circumflex': 333,
  5804. 'tilde': 333,
  5805. 'macron': 333,
  5806. 'breve': 333,
  5807. 'dotaccent': 333,
  5808. 'dieresis': 333,
  5809. 'ring': 333,
  5810. 'cedilla': 333,
  5811. 'hungarumlaut': 333,
  5812. 'ogonek': 333,
  5813. 'caron': 333,
  5814. 'emdash': 1000,
  5815. 'AE': 1000,
  5816. 'ordfeminine': 370,
  5817. 'Lslash': 556,
  5818. 'Oslash': 778,
  5819. 'OE': 1000,
  5820. 'ordmasculine': 365,
  5821. 'ae': 889,
  5822. 'dotlessi': 278,
  5823. 'lslash': 222,
  5824. 'oslash': 611,
  5825. 'oe': 944,
  5826. 'germandbls': 611,
  5827. 'Idieresis': 278,
  5828. 'eacute': 556,
  5829. 'abreve': 556,
  5830. 'uhungarumlaut': 556,
  5831. 'ecaron': 556,
  5832. 'Ydieresis': 667,
  5833. 'divide': 584,
  5834. 'Yacute': 667,
  5835. 'Acircumflex': 667,
  5836. 'aacute': 556,
  5837. 'Ucircumflex': 722,
  5838. 'yacute': 500,
  5839. 'scommaaccent': 500,
  5840. 'ecircumflex': 556,
  5841. 'Uring': 722,
  5842. 'Udieresis': 722,
  5843. 'aogonek': 556,
  5844. 'Uacute': 722,
  5845. 'uogonek': 556,
  5846. 'Edieresis': 667,
  5847. 'Dcroat': 722,
  5848. 'commaaccent': 250,
  5849. 'copyright': 737,
  5850. 'Emacron': 667,
  5851. 'ccaron': 500,
  5852. 'aring': 556,
  5853. 'Ncommaaccent': 722,
  5854. 'lacute': 222,
  5855. 'agrave': 556,
  5856. 'Tcommaaccent': 611,
  5857. 'Cacute': 722,
  5858. 'atilde': 556,
  5859. 'Edotaccent': 667,
  5860. 'scaron': 500,
  5861. 'scedilla': 500,
  5862. 'iacute': 278,
  5863. 'lozenge': 471,
  5864. 'Rcaron': 722,
  5865. 'Gcommaaccent': 778,
  5866. 'ucircumflex': 556,
  5867. 'acircumflex': 556,
  5868. 'Amacron': 667,
  5869. 'rcaron': 333,
  5870. 'ccedilla': 500,
  5871. 'Zdotaccent': 611,
  5872. 'Thorn': 667,
  5873. 'Omacron': 778,
  5874. 'Racute': 722,
  5875. 'Sacute': 667,
  5876. 'dcaron': 643,
  5877. 'Umacron': 722,
  5878. 'uring': 556,
  5879. 'threesuperior': 333,
  5880. 'Ograve': 778,
  5881. 'Agrave': 667,
  5882. 'Abreve': 667,
  5883. 'multiply': 584,
  5884. 'uacute': 556,
  5885. 'Tcaron': 611,
  5886. 'partialdiff': 476,
  5887. 'ydieresis': 500,
  5888. 'Nacute': 722,
  5889. 'icircumflex': 278,
  5890. 'Ecircumflex': 667,
  5891. 'adieresis': 556,
  5892. 'edieresis': 556,
  5893. 'cacute': 500,
  5894. 'nacute': 556,
  5895. 'umacron': 556,
  5896. 'Ncaron': 722,
  5897. 'Iacute': 278,
  5898. 'plusminus': 584,
  5899. 'brokenbar': 260,
  5900. 'registered': 737,
  5901. 'Gbreve': 778,
  5902. 'Idotaccent': 278,
  5903. 'summation': 600,
  5904. 'Egrave': 667,
  5905. 'racute': 333,
  5906. 'omacron': 556,
  5907. 'Zacute': 611,
  5908. 'Zcaron': 611,
  5909. 'greaterequal': 549,
  5910. 'Eth': 722,
  5911. 'Ccedilla': 722,
  5912. 'lcommaaccent': 222,
  5913. 'tcaron': 317,
  5914. 'eogonek': 556,
  5915. 'Uogonek': 722,
  5916. 'Aacute': 667,
  5917. 'Adieresis': 667,
  5918. 'egrave': 556,
  5919. 'zacute': 500,
  5920. 'iogonek': 222,
  5921. 'Oacute': 778,
  5922. 'oacute': 556,
  5923. 'amacron': 556,
  5924. 'sacute': 500,
  5925. 'idieresis': 278,
  5926. 'Ocircumflex': 778,
  5927. 'Ugrave': 722,
  5928. 'Delta': 612,
  5929. 'thorn': 556,
  5930. 'twosuperior': 333,
  5931. 'Odieresis': 778,
  5932. 'mu': 556,
  5933. 'igrave': 278,
  5934. 'ohungarumlaut': 556,
  5935. 'Eogonek': 667,
  5936. 'dcroat': 556,
  5937. 'threequarters': 834,
  5938. 'Scedilla': 667,
  5939. 'lcaron': 299,
  5940. 'Kcommaaccent': 667,
  5941. 'Lacute': 556,
  5942. 'trademark': 1000,
  5943. 'edotaccent': 556,
  5944. 'Igrave': 278,
  5945. 'Imacron': 278,
  5946. 'Lcaron': 556,
  5947. 'onehalf': 834,
  5948. 'lessequal': 549,
  5949. 'ocircumflex': 556,
  5950. 'ntilde': 556,
  5951. 'Uhungarumlaut': 722,
  5952. 'Eacute': 667,
  5953. 'emacron': 556,
  5954. 'gbreve': 556,
  5955. 'onequarter': 834,
  5956. 'Scaron': 667,
  5957. 'Scommaaccent': 667,
  5958. 'Ohungarumlaut': 778,
  5959. 'degree': 400,
  5960. 'ograve': 556,
  5961. 'Ccaron': 722,
  5962. 'ugrave': 556,
  5963. 'radical': 453,
  5964. 'Dcaron': 722,
  5965. 'rcommaaccent': 333,
  5966. 'Ntilde': 722,
  5967. 'otilde': 556,
  5968. 'Rcommaaccent': 722,
  5969. 'Lcommaaccent': 556,
  5970. 'Atilde': 667,
  5971. 'Aogonek': 667,
  5972. 'Aring': 667,
  5973. 'Otilde': 778,
  5974. 'zdotaccent': 500,
  5975. 'Ecaron': 667,
  5976. 'Iogonek': 278,
  5977. 'kcommaaccent': 500,
  5978. 'minus': 584,
  5979. 'Icircumflex': 278,
  5980. 'ncaron': 556,
  5981. 'tcommaaccent': 278,
  5982. 'logicalnot': 584,
  5983. 'odieresis': 556,
  5984. 'udieresis': 556,
  5985. 'notequal': 549,
  5986. 'gcommaaccent': 556,
  5987. 'eth': 556,
  5988. 'zcaron': 500,
  5989. 'ncommaaccent': 556,
  5990. 'onesuperior': 333,
  5991. 'imacron': 278,
  5992. 'Euro': 556
  5993. },
  5994. 'Helvetica-Bold': {
  5995. 'space': 278,
  5996. 'exclam': 333,
  5997. 'quotedbl': 474,
  5998. 'numbersign': 556,
  5999. 'dollar': 556,
  6000. 'percent': 889,
  6001. 'ampersand': 722,
  6002. 'quoteright': 278,
  6003. 'parenleft': 333,
  6004. 'parenright': 333,
  6005. 'asterisk': 389,
  6006. 'plus': 584,
  6007. 'comma': 278,
  6008. 'hyphen': 333,
  6009. 'period': 278,
  6010. 'slash': 278,
  6011. 'zero': 556,
  6012. 'one': 556,
  6013. 'two': 556,
  6014. 'three': 556,
  6015. 'four': 556,
  6016. 'five': 556,
  6017. 'six': 556,
  6018. 'seven': 556,
  6019. 'eight': 556,
  6020. 'nine': 556,
  6021. 'colon': 333,
  6022. 'semicolon': 333,
  6023. 'less': 584,
  6024. 'equal': 584,
  6025. 'greater': 584,
  6026. 'question': 611,
  6027. 'at': 975,
  6028. 'A': 722,
  6029. 'B': 722,
  6030. 'C': 722,
  6031. 'D': 722,
  6032. 'E': 667,
  6033. 'F': 611,
  6034. 'G': 778,
  6035. 'H': 722,
  6036. 'I': 278,
  6037. 'J': 556,
  6038. 'K': 722,
  6039. 'L': 611,
  6040. 'M': 833,
  6041. 'N': 722,
  6042. 'O': 778,
  6043. 'P': 667,
  6044. 'Q': 778,
  6045. 'R': 722,
  6046. 'S': 667,
  6047. 'T': 611,
  6048. 'U': 722,
  6049. 'V': 667,
  6050. 'W': 944,
  6051. 'X': 667,
  6052. 'Y': 667,
  6053. 'Z': 611,
  6054. 'bracketleft': 333,
  6055. 'backslash': 278,
  6056. 'bracketright': 333,
  6057. 'asciicircum': 584,
  6058. 'underscore': 556,
  6059. 'quoteleft': 278,
  6060. 'a': 556,
  6061. 'b': 611,
  6062. 'c': 556,
  6063. 'd': 611,
  6064. 'e': 556,
  6065. 'f': 333,
  6066. 'g': 611,
  6067. 'h': 611,
  6068. 'i': 278,
  6069. 'j': 278,
  6070. 'k': 556,
  6071. 'l': 278,
  6072. 'm': 889,
  6073. 'n': 611,
  6074. 'o': 611,
  6075. 'p': 611,
  6076. 'q': 611,
  6077. 'r': 389,
  6078. 's': 556,
  6079. 't': 333,
  6080. 'u': 611,
  6081. 'v': 556,
  6082. 'w': 778,
  6083. 'x': 556,
  6084. 'y': 556,
  6085. 'z': 500,
  6086. 'braceleft': 389,
  6087. 'bar': 280,
  6088. 'braceright': 389,
  6089. 'asciitilde': 584,
  6090. 'exclamdown': 333,
  6091. 'cent': 556,
  6092. 'sterling': 556,
  6093. 'fraction': 167,
  6094. 'yen': 556,
  6095. 'florin': 556,
  6096. 'section': 556,
  6097. 'currency': 556,
  6098. 'quotesingle': 238,
  6099. 'quotedblleft': 500,
  6100. 'guillemotleft': 556,
  6101. 'guilsinglleft': 333,
  6102. 'guilsinglright': 333,
  6103. 'fi': 611,
  6104. 'fl': 611,
  6105. 'endash': 556,
  6106. 'dagger': 556,
  6107. 'daggerdbl': 556,
  6108. 'periodcentered': 278,
  6109. 'paragraph': 556,
  6110. 'bullet': 350,
  6111. 'quotesinglbase': 278,
  6112. 'quotedblbase': 500,
  6113. 'quotedblright': 500,
  6114. 'guillemotright': 556,
  6115. 'ellipsis': 1000,
  6116. 'perthousand': 1000,
  6117. 'questiondown': 611,
  6118. 'grave': 333,
  6119. 'acute': 333,
  6120. 'circumflex': 333,
  6121. 'tilde': 333,
  6122. 'macron': 333,
  6123. 'breve': 333,
  6124. 'dotaccent': 333,
  6125. 'dieresis': 333,
  6126. 'ring': 333,
  6127. 'cedilla': 333,
  6128. 'hungarumlaut': 333,
  6129. 'ogonek': 333,
  6130. 'caron': 333,
  6131. 'emdash': 1000,
  6132. 'AE': 1000,
  6133. 'ordfeminine': 370,
  6134. 'Lslash': 611,
  6135. 'Oslash': 778,
  6136. 'OE': 1000,
  6137. 'ordmasculine': 365,
  6138. 'ae': 889,
  6139. 'dotlessi': 278,
  6140. 'lslash': 278,
  6141. 'oslash': 611,
  6142. 'oe': 944,
  6143. 'germandbls': 611,
  6144. 'Idieresis': 278,
  6145. 'eacute': 556,
  6146. 'abreve': 556,
  6147. 'uhungarumlaut': 611,
  6148. 'ecaron': 556,
  6149. 'Ydieresis': 667,
  6150. 'divide': 584,
  6151. 'Yacute': 667,
  6152. 'Acircumflex': 722,
  6153. 'aacute': 556,
  6154. 'Ucircumflex': 722,
  6155. 'yacute': 556,
  6156. 'scommaaccent': 556,
  6157. 'ecircumflex': 556,
  6158. 'Uring': 722,
  6159. 'Udieresis': 722,
  6160. 'aogonek': 556,
  6161. 'Uacute': 722,
  6162. 'uogonek': 611,
  6163. 'Edieresis': 667,
  6164. 'Dcroat': 722,
  6165. 'commaaccent': 250,
  6166. 'copyright': 737,
  6167. 'Emacron': 667,
  6168. 'ccaron': 556,
  6169. 'aring': 556,
  6170. 'Ncommaaccent': 722,
  6171. 'lacute': 278,
  6172. 'agrave': 556,
  6173. 'Tcommaaccent': 611,
  6174. 'Cacute': 722,
  6175. 'atilde': 556,
  6176. 'Edotaccent': 667,
  6177. 'scaron': 556,
  6178. 'scedilla': 556,
  6179. 'iacute': 278,
  6180. 'lozenge': 494,
  6181. 'Rcaron': 722,
  6182. 'Gcommaaccent': 778,
  6183. 'ucircumflex': 611,
  6184. 'acircumflex': 556,
  6185. 'Amacron': 722,
  6186. 'rcaron': 389,
  6187. 'ccedilla': 556,
  6188. 'Zdotaccent': 611,
  6189. 'Thorn': 667,
  6190. 'Omacron': 778,
  6191. 'Racute': 722,
  6192. 'Sacute': 667,
  6193. 'dcaron': 743,
  6194. 'Umacron': 722,
  6195. 'uring': 611,
  6196. 'threesuperior': 333,
  6197. 'Ograve': 778,
  6198. 'Agrave': 722,
  6199. 'Abreve': 722,
  6200. 'multiply': 584,
  6201. 'uacute': 611,
  6202. 'Tcaron': 611,
  6203. 'partialdiff': 494,
  6204. 'ydieresis': 556,
  6205. 'Nacute': 722,
  6206. 'icircumflex': 278,
  6207. 'Ecircumflex': 667,
  6208. 'adieresis': 556,
  6209. 'edieresis': 556,
  6210. 'cacute': 556,
  6211. 'nacute': 611,
  6212. 'umacron': 611,
  6213. 'Ncaron': 722,
  6214. 'Iacute': 278,
  6215. 'plusminus': 584,
  6216. 'brokenbar': 280,
  6217. 'registered': 737,
  6218. 'Gbreve': 778,
  6219. 'Idotaccent': 278,
  6220. 'summation': 600,
  6221. 'Egrave': 667,
  6222. 'racute': 389,
  6223. 'omacron': 611,
  6224. 'Zacute': 611,
  6225. 'Zcaron': 611,
  6226. 'greaterequal': 549,
  6227. 'Eth': 722,
  6228. 'Ccedilla': 722,
  6229. 'lcommaaccent': 278,
  6230. 'tcaron': 389,
  6231. 'eogonek': 556,
  6232. 'Uogonek': 722,
  6233. 'Aacute': 722,
  6234. 'Adieresis': 722,
  6235. 'egrave': 556,
  6236. 'zacute': 500,
  6237. 'iogonek': 278,
  6238. 'Oacute': 778,
  6239. 'oacute': 611,
  6240. 'amacron': 556,
  6241. 'sacute': 556,
  6242. 'idieresis': 278,
  6243. 'Ocircumflex': 778,
  6244. 'Ugrave': 722,
  6245. 'Delta': 612,
  6246. 'thorn': 611,
  6247. 'twosuperior': 333,
  6248. 'Odieresis': 778,
  6249. 'mu': 611,
  6250. 'igrave': 278,
  6251. 'ohungarumlaut': 611,
  6252. 'Eogonek': 667,
  6253. 'dcroat': 611,
  6254. 'threequarters': 834,
  6255. 'Scedilla': 667,
  6256. 'lcaron': 400,
  6257. 'Kcommaaccent': 722,
  6258. 'Lacute': 611,
  6259. 'trademark': 1000,
  6260. 'edotaccent': 556,
  6261. 'Igrave': 278,
  6262. 'Imacron': 278,
  6263. 'Lcaron': 611,
  6264. 'onehalf': 834,
  6265. 'lessequal': 549,
  6266. 'ocircumflex': 611,
  6267. 'ntilde': 611,
  6268. 'Uhungarumlaut': 722,
  6269. 'Eacute': 667,
  6270. 'emacron': 556,
  6271. 'gbreve': 611,
  6272. 'onequarter': 834,
  6273. 'Scaron': 667,
  6274. 'Scommaaccent': 667,
  6275. 'Ohungarumlaut': 778,
  6276. 'degree': 400,
  6277. 'ograve': 611,
  6278. 'Ccaron': 722,
  6279. 'ugrave': 611,
  6280. 'radical': 549,
  6281. 'Dcaron': 722,
  6282. 'rcommaaccent': 389,
  6283. 'Ntilde': 722,
  6284. 'otilde': 611,
  6285. 'Rcommaaccent': 722,
  6286. 'Lcommaaccent': 611,
  6287. 'Atilde': 722,
  6288. 'Aogonek': 722,
  6289. 'Aring': 722,
  6290. 'Otilde': 778,
  6291. 'zdotaccent': 500,
  6292. 'Ecaron': 667,
  6293. 'Iogonek': 278,
  6294. 'kcommaaccent': 556,
  6295. 'minus': 584,
  6296. 'Icircumflex': 278,
  6297. 'ncaron': 611,
  6298. 'tcommaaccent': 333,
  6299. 'logicalnot': 584,
  6300. 'odieresis': 611,
  6301. 'udieresis': 611,
  6302. 'notequal': 549,
  6303. 'gcommaaccent': 611,
  6304. 'eth': 611,
  6305. 'zcaron': 500,
  6306. 'ncommaaccent': 611,
  6307. 'onesuperior': 333,
  6308. 'imacron': 278,
  6309. 'Euro': 556
  6310. },
  6311. 'Helvetica-BoldOblique': {
  6312. 'space': 278,
  6313. 'exclam': 333,
  6314. 'quotedbl': 474,
  6315. 'numbersign': 556,
  6316. 'dollar': 556,
  6317. 'percent': 889,
  6318. 'ampersand': 722,
  6319. 'quoteright': 278,
  6320. 'parenleft': 333,
  6321. 'parenright': 333,
  6322. 'asterisk': 389,
  6323. 'plus': 584,
  6324. 'comma': 278,
  6325. 'hyphen': 333,
  6326. 'period': 278,
  6327. 'slash': 278,
  6328. 'zero': 556,
  6329. 'one': 556,
  6330. 'two': 556,
  6331. 'three': 556,
  6332. 'four': 556,
  6333. 'five': 556,
  6334. 'six': 556,
  6335. 'seven': 556,
  6336. 'eight': 556,
  6337. 'nine': 556,
  6338. 'colon': 333,
  6339. 'semicolon': 333,
  6340. 'less': 584,
  6341. 'equal': 584,
  6342. 'greater': 584,
  6343. 'question': 611,
  6344. 'at': 975,
  6345. 'A': 722,
  6346. 'B': 722,
  6347. 'C': 722,
  6348. 'D': 722,
  6349. 'E': 667,
  6350. 'F': 611,
  6351. 'G': 778,
  6352. 'H': 722,
  6353. 'I': 278,
  6354. 'J': 556,
  6355. 'K': 722,
  6356. 'L': 611,
  6357. 'M': 833,
  6358. 'N': 722,
  6359. 'O': 778,
  6360. 'P': 667,
  6361. 'Q': 778,
  6362. 'R': 722,
  6363. 'S': 667,
  6364. 'T': 611,
  6365. 'U': 722,
  6366. 'V': 667,
  6367. 'W': 944,
  6368. 'X': 667,
  6369. 'Y': 667,
  6370. 'Z': 611,
  6371. 'bracketleft': 333,
  6372. 'backslash': 278,
  6373. 'bracketright': 333,
  6374. 'asciicircum': 584,
  6375. 'underscore': 556,
  6376. 'quoteleft': 278,
  6377. 'a': 556,
  6378. 'b': 611,
  6379. 'c': 556,
  6380. 'd': 611,
  6381. 'e': 556,
  6382. 'f': 333,
  6383. 'g': 611,
  6384. 'h': 611,
  6385. 'i': 278,
  6386. 'j': 278,
  6387. 'k': 556,
  6388. 'l': 278,
  6389. 'm': 889,
  6390. 'n': 611,
  6391. 'o': 611,
  6392. 'p': 611,
  6393. 'q': 611,
  6394. 'r': 389,
  6395. 's': 556,
  6396. 't': 333,
  6397. 'u': 611,
  6398. 'v': 556,
  6399. 'w': 778,
  6400. 'x': 556,
  6401. 'y': 556,
  6402. 'z': 500,
  6403. 'braceleft': 389,
  6404. 'bar': 280,
  6405. 'braceright': 389,
  6406. 'asciitilde': 584,
  6407. 'exclamdown': 333,
  6408. 'cent': 556,
  6409. 'sterling': 556,
  6410. 'fraction': 167,
  6411. 'yen': 556,
  6412. 'florin': 556,
  6413. 'section': 556,
  6414. 'currency': 556,
  6415. 'quotesingle': 238,
  6416. 'quotedblleft': 500,
  6417. 'guillemotleft': 556,
  6418. 'guilsinglleft': 333,
  6419. 'guilsinglright': 333,
  6420. 'fi': 611,
  6421. 'fl': 611,
  6422. 'endash': 556,
  6423. 'dagger': 556,
  6424. 'daggerdbl': 556,
  6425. 'periodcentered': 278,
  6426. 'paragraph': 556,
  6427. 'bullet': 350,
  6428. 'quotesinglbase': 278,
  6429. 'quotedblbase': 500,
  6430. 'quotedblright': 500,
  6431. 'guillemotright': 556,
  6432. 'ellipsis': 1000,
  6433. 'perthousand': 1000,
  6434. 'questiondown': 611,
  6435. 'grave': 333,
  6436. 'acute': 333,
  6437. 'circumflex': 333,
  6438. 'tilde': 333,
  6439. 'macron': 333,
  6440. 'breve': 333,
  6441. 'dotaccent': 333,
  6442. 'dieresis': 333,
  6443. 'ring': 333,
  6444. 'cedilla': 333,
  6445. 'hungarumlaut': 333,
  6446. 'ogonek': 333,
  6447. 'caron': 333,
  6448. 'emdash': 1000,
  6449. 'AE': 1000,
  6450. 'ordfeminine': 370,
  6451. 'Lslash': 611,
  6452. 'Oslash': 778,
  6453. 'OE': 1000,
  6454. 'ordmasculine': 365,
  6455. 'ae': 889,
  6456. 'dotlessi': 278,
  6457. 'lslash': 278,
  6458. 'oslash': 611,
  6459. 'oe': 944,
  6460. 'germandbls': 611,
  6461. 'Idieresis': 278,
  6462. 'eacute': 556,
  6463. 'abreve': 556,
  6464. 'uhungarumlaut': 611,
  6465. 'ecaron': 556,
  6466. 'Ydieresis': 667,
  6467. 'divide': 584,
  6468. 'Yacute': 667,
  6469. 'Acircumflex': 722,
  6470. 'aacute': 556,
  6471. 'Ucircumflex': 722,
  6472. 'yacute': 556,
  6473. 'scommaaccent': 556,
  6474. 'ecircumflex': 556,
  6475. 'Uring': 722,
  6476. 'Udieresis': 722,
  6477. 'aogonek': 556,
  6478. 'Uacute': 722,
  6479. 'uogonek': 611,
  6480. 'Edieresis': 667,
  6481. 'Dcroat': 722,
  6482. 'commaaccent': 250,
  6483. 'copyright': 737,
  6484. 'Emacron': 667,
  6485. 'ccaron': 556,
  6486. 'aring': 556,
  6487. 'Ncommaaccent': 722,
  6488. 'lacute': 278,
  6489. 'agrave': 556,
  6490. 'Tcommaaccent': 611,
  6491. 'Cacute': 722,
  6492. 'atilde': 556,
  6493. 'Edotaccent': 667,
  6494. 'scaron': 556,
  6495. 'scedilla': 556,
  6496. 'iacute': 278,
  6497. 'lozenge': 494,
  6498. 'Rcaron': 722,
  6499. 'Gcommaaccent': 778,
  6500. 'ucircumflex': 611,
  6501. 'acircumflex': 556,
  6502. 'Amacron': 722,
  6503. 'rcaron': 389,
  6504. 'ccedilla': 556,
  6505. 'Zdotaccent': 611,
  6506. 'Thorn': 667,
  6507. 'Omacron': 778,
  6508. 'Racute': 722,
  6509. 'Sacute': 667,
  6510. 'dcaron': 743,
  6511. 'Umacron': 722,
  6512. 'uring': 611,
  6513. 'threesuperior': 333,
  6514. 'Ograve': 778,
  6515. 'Agrave': 722,
  6516. 'Abreve': 722,
  6517. 'multiply': 584,
  6518. 'uacute': 611,
  6519. 'Tcaron': 611,
  6520. 'partialdiff': 494,
  6521. 'ydieresis': 556,
  6522. 'Nacute': 722,
  6523. 'icircumflex': 278,
  6524. 'Ecircumflex': 667,
  6525. 'adieresis': 556,
  6526. 'edieresis': 556,
  6527. 'cacute': 556,
  6528. 'nacute': 611,
  6529. 'umacron': 611,
  6530. 'Ncaron': 722,
  6531. 'Iacute': 278,
  6532. 'plusminus': 584,
  6533. 'brokenbar': 280,
  6534. 'registered': 737,
  6535. 'Gbreve': 778,
  6536. 'Idotaccent': 278,
  6537. 'summation': 600,
  6538. 'Egrave': 667,
  6539. 'racute': 389,
  6540. 'omacron': 611,
  6541. 'Zacute': 611,
  6542. 'Zcaron': 611,
  6543. 'greaterequal': 549,
  6544. 'Eth': 722,
  6545. 'Ccedilla': 722,
  6546. 'lcommaaccent': 278,
  6547. 'tcaron': 389,
  6548. 'eogonek': 556,
  6549. 'Uogonek': 722,
  6550. 'Aacute': 722,
  6551. 'Adieresis': 722,
  6552. 'egrave': 556,
  6553. 'zacute': 500,
  6554. 'iogonek': 278,
  6555. 'Oacute': 778,
  6556. 'oacute': 611,
  6557. 'amacron': 556,
  6558. 'sacute': 556,
  6559. 'idieresis': 278,
  6560. 'Ocircumflex': 778,
  6561. 'Ugrave': 722,
  6562. 'Delta': 612,
  6563. 'thorn': 611,
  6564. 'twosuperior': 333,
  6565. 'Odieresis': 778,
  6566. 'mu': 611,
  6567. 'igrave': 278,
  6568. 'ohungarumlaut': 611,
  6569. 'Eogonek': 667,
  6570. 'dcroat': 611,
  6571. 'threequarters': 834,
  6572. 'Scedilla': 667,
  6573. 'lcaron': 400,
  6574. 'Kcommaaccent': 722,
  6575. 'Lacute': 611,
  6576. 'trademark': 1000,
  6577. 'edotaccent': 556,
  6578. 'Igrave': 278,
  6579. 'Imacron': 278,
  6580. 'Lcaron': 611,
  6581. 'onehalf': 834,
  6582. 'lessequal': 549,
  6583. 'ocircumflex': 611,
  6584. 'ntilde': 611,
  6585. 'Uhungarumlaut': 722,
  6586. 'Eacute': 667,
  6587. 'emacron': 556,
  6588. 'gbreve': 611,
  6589. 'onequarter': 834,
  6590. 'Scaron': 667,
  6591. 'Scommaaccent': 667,
  6592. 'Ohungarumlaut': 778,
  6593. 'degree': 400,
  6594. 'ograve': 611,
  6595. 'Ccaron': 722,
  6596. 'ugrave': 611,
  6597. 'radical': 549,
  6598. 'Dcaron': 722,
  6599. 'rcommaaccent': 389,
  6600. 'Ntilde': 722,
  6601. 'otilde': 611,
  6602. 'Rcommaaccent': 722,
  6603. 'Lcommaaccent': 611,
  6604. 'Atilde': 722,
  6605. 'Aogonek': 722,
  6606. 'Aring': 722,
  6607. 'Otilde': 778,
  6608. 'zdotaccent': 500,
  6609. 'Ecaron': 667,
  6610. 'Iogonek': 278,
  6611. 'kcommaaccent': 556,
  6612. 'minus': 584,
  6613. 'Icircumflex': 278,
  6614. 'ncaron': 611,
  6615. 'tcommaaccent': 333,
  6616. 'logicalnot': 584,
  6617. 'odieresis': 611,
  6618. 'udieresis': 611,
  6619. 'notequal': 549,
  6620. 'gcommaaccent': 611,
  6621. 'eth': 611,
  6622. 'zcaron': 500,
  6623. 'ncommaaccent': 611,
  6624. 'onesuperior': 333,
  6625. 'imacron': 278,
  6626. 'Euro': 556
  6627. },
  6628. 'Helvetica-Oblique' : {
  6629. 'space': 278,
  6630. 'exclam': 278,
  6631. 'quotedbl': 355,
  6632. 'numbersign': 556,
  6633. 'dollar': 556,
  6634. 'percent': 889,
  6635. 'ampersand': 667,
  6636. 'quoteright': 222,
  6637. 'parenleft': 333,
  6638. 'parenright': 333,
  6639. 'asterisk': 389,
  6640. 'plus': 584,
  6641. 'comma': 278,
  6642. 'hyphen': 333,
  6643. 'period': 278,
  6644. 'slash': 278,
  6645. 'zero': 556,
  6646. 'one': 556,
  6647. 'two': 556,
  6648. 'three': 556,
  6649. 'four': 556,
  6650. 'five': 556,
  6651. 'six': 556,
  6652. 'seven': 556,
  6653. 'eight': 556,
  6654. 'nine': 556,
  6655. 'colon': 278,
  6656. 'semicolon': 278,
  6657. 'less': 584,
  6658. 'equal': 584,
  6659. 'greater': 584,
  6660. 'question': 556,
  6661. 'at': 1015,
  6662. 'A': 667,
  6663. 'B': 667,
  6664. 'C': 722,
  6665. 'D': 722,
  6666. 'E': 667,
  6667. 'F': 611,
  6668. 'G': 778,
  6669. 'H': 722,
  6670. 'I': 278,
  6671. 'J': 500,
  6672. 'K': 667,
  6673. 'L': 556,
  6674. 'M': 833,
  6675. 'N': 722,
  6676. 'O': 778,
  6677. 'P': 667,
  6678. 'Q': 778,
  6679. 'R': 722,
  6680. 'S': 667,
  6681. 'T': 611,
  6682. 'U': 722,
  6683. 'V': 667,
  6684. 'W': 944,
  6685. 'X': 667,
  6686. 'Y': 667,
  6687. 'Z': 611,
  6688. 'bracketleft': 278,
  6689. 'backslash': 278,
  6690. 'bracketright': 278,
  6691. 'asciicircum': 469,
  6692. 'underscore': 556,
  6693. 'quoteleft': 222,
  6694. 'a': 556,
  6695. 'b': 556,
  6696. 'c': 500,
  6697. 'd': 556,
  6698. 'e': 556,
  6699. 'f': 278,
  6700. 'g': 556,
  6701. 'h': 556,
  6702. 'i': 222,
  6703. 'j': 222,
  6704. 'k': 500,
  6705. 'l': 222,
  6706. 'm': 833,
  6707. 'n': 556,
  6708. 'o': 556,
  6709. 'p': 556,
  6710. 'q': 556,
  6711. 'r': 333,
  6712. 's': 500,
  6713. 't': 278,
  6714. 'u': 556,
  6715. 'v': 500,
  6716. 'w': 722,
  6717. 'x': 500,
  6718. 'y': 500,
  6719. 'z': 500,
  6720. 'braceleft': 334,
  6721. 'bar': 260,
  6722. 'braceright': 334,
  6723. 'asciitilde': 584,
  6724. 'exclamdown': 333,
  6725. 'cent': 556,
  6726. 'sterling': 556,
  6727. 'fraction': 167,
  6728. 'yen': 556,
  6729. 'florin': 556,
  6730. 'section': 556,
  6731. 'currency': 556,
  6732. 'quotesingle': 191,
  6733. 'quotedblleft': 333,
  6734. 'guillemotleft': 556,
  6735. 'guilsinglleft': 333,
  6736. 'guilsinglright': 333,
  6737. 'fi': 500,
  6738. 'fl': 500,
  6739. 'endash': 556,
  6740. 'dagger': 556,
  6741. 'daggerdbl': 556,
  6742. 'periodcentered': 278,
  6743. 'paragraph': 537,
  6744. 'bullet': 350,
  6745. 'quotesinglbase': 222,
  6746. 'quotedblbase': 333,
  6747. 'quotedblright': 333,
  6748. 'guillemotright': 556,
  6749. 'ellipsis': 1000,
  6750. 'perthousand': 1000,
  6751. 'questiondown': 611,
  6752. 'grave': 333,
  6753. 'acute': 333,
  6754. 'circumflex': 333,
  6755. 'tilde': 333,
  6756. 'macron': 333,
  6757. 'breve': 333,
  6758. 'dotaccent': 333,
  6759. 'dieresis': 333,
  6760. 'ring': 333,
  6761. 'cedilla': 333,
  6762. 'hungarumlaut': 333,
  6763. 'ogonek': 333,
  6764. 'caron': 333,
  6765. 'emdash': 1000,
  6766. 'AE': 1000,
  6767. 'ordfeminine': 370,
  6768. 'Lslash': 556,
  6769. 'Oslash': 778,
  6770. 'OE': 1000,
  6771. 'ordmasculine': 365,
  6772. 'ae': 889,
  6773. 'dotlessi': 278,
  6774. 'lslash': 222,
  6775. 'oslash': 611,
  6776. 'oe': 944,
  6777. 'germandbls': 611,
  6778. 'Idieresis': 278,
  6779. 'eacute': 556,
  6780. 'abreve': 556,
  6781. 'uhungarumlaut': 556,
  6782. 'ecaron': 556,
  6783. 'Ydieresis': 667,
  6784. 'divide': 584,
  6785. 'Yacute': 667,
  6786. 'Acircumflex': 667,
  6787. 'aacute': 556,
  6788. 'Ucircumflex': 722,
  6789. 'yacute': 500,
  6790. 'scommaaccent': 500,
  6791. 'ecircumflex': 556,
  6792. 'Uring': 722,
  6793. 'Udieresis': 722,
  6794. 'aogonek': 556,
  6795. 'Uacute': 722,
  6796. 'uogonek': 556,
  6797. 'Edieresis': 667,
  6798. 'Dcroat': 722,
  6799. 'commaaccent': 250,
  6800. 'copyright': 737,
  6801. 'Emacron': 667,
  6802. 'ccaron': 500,
  6803. 'aring': 556,
  6804. 'Ncommaaccent': 722,
  6805. 'lacute': 222,
  6806. 'agrave': 556,
  6807. 'Tcommaaccent': 611,
  6808. 'Cacute': 722,
  6809. 'atilde': 556,
  6810. 'Edotaccent': 667,
  6811. 'scaron': 500,
  6812. 'scedilla': 500,
  6813. 'iacute': 278,
  6814. 'lozenge': 471,
  6815. 'Rcaron': 722,
  6816. 'Gcommaaccent': 778,
  6817. 'ucircumflex': 556,
  6818. 'acircumflex': 556,
  6819. 'Amacron': 667,
  6820. 'rcaron': 333,
  6821. 'ccedilla': 500,
  6822. 'Zdotaccent': 611,
  6823. 'Thorn': 667,
  6824. 'Omacron': 778,
  6825. 'Racute': 722,
  6826. 'Sacute': 667,
  6827. 'dcaron': 643,
  6828. 'Umacron': 722,
  6829. 'uring': 556,
  6830. 'threesuperior': 333,
  6831. 'Ograve': 778,
  6832. 'Agrave': 667,
  6833. 'Abreve': 667,
  6834. 'multiply': 584,
  6835. 'uacute': 556,
  6836. 'Tcaron': 611,
  6837. 'partialdiff': 476,
  6838. 'ydieresis': 500,
  6839. 'Nacute': 722,
  6840. 'icircumflex': 278,
  6841. 'Ecircumflex': 667,
  6842. 'adieresis': 556,
  6843. 'edieresis': 556,
  6844. 'cacute': 500,
  6845. 'nacute': 556,
  6846. 'umacron': 556,
  6847. 'Ncaron': 722,
  6848. 'Iacute': 278,
  6849. 'plusminus': 584,
  6850. 'brokenbar': 260,
  6851. 'registered': 737,
  6852. 'Gbreve': 778,
  6853. 'Idotaccent': 278,
  6854. 'summation': 600,
  6855. 'Egrave': 667,
  6856. 'racute': 333,
  6857. 'omacron': 556,
  6858. 'Zacute': 611,
  6859. 'Zcaron': 611,
  6860. 'greaterequal': 549,
  6861. 'Eth': 722,
  6862. 'Ccedilla': 722,
  6863. 'lcommaaccent': 222,
  6864. 'tcaron': 317,
  6865. 'eogonek': 556,
  6866. 'Uogonek': 722,
  6867. 'Aacute': 667,
  6868. 'Adieresis': 667,
  6869. 'egrave': 556,
  6870. 'zacute': 500,
  6871. 'iogonek': 222,
  6872. 'Oacute': 778,
  6873. 'oacute': 556,
  6874. 'amacron': 556,
  6875. 'sacute': 500,
  6876. 'idieresis': 278,
  6877. 'Ocircumflex': 778,
  6878. 'Ugrave': 722,
  6879. 'Delta': 612,
  6880. 'thorn': 556,
  6881. 'twosuperior': 333,
  6882. 'Odieresis': 778,
  6883. 'mu': 556,
  6884. 'igrave': 278,
  6885. 'ohungarumlaut': 556,
  6886. 'Eogonek': 667,
  6887. 'dcroat': 556,
  6888. 'threequarters': 834,
  6889. 'Scedilla': 667,
  6890. 'lcaron': 299,
  6891. 'Kcommaaccent': 667,
  6892. 'Lacute': 556,
  6893. 'trademark': 1000,
  6894. 'edotaccent': 556,
  6895. 'Igrave': 278,
  6896. 'Imacron': 278,
  6897. 'Lcaron': 556,
  6898. 'onehalf': 834,
  6899. 'lessequal': 549,
  6900. 'ocircumflex': 556,
  6901. 'ntilde': 556,
  6902. 'Uhungarumlaut': 722,
  6903. 'Eacute': 667,
  6904. 'emacron': 556,
  6905. 'gbreve': 556,
  6906. 'onequarter': 834,
  6907. 'Scaron': 667,
  6908. 'Scommaaccent': 667,
  6909. 'Ohungarumlaut': 778,
  6910. 'degree': 400,
  6911. 'ograve': 556,
  6912. 'Ccaron': 722,
  6913. 'ugrave': 556,
  6914. 'radical': 453,
  6915. 'Dcaron': 722,
  6916. 'rcommaaccent': 333,
  6917. 'Ntilde': 722,
  6918. 'otilde': 556,
  6919. 'Rcommaaccent': 722,
  6920. 'Lcommaaccent': 556,
  6921. 'Atilde': 667,
  6922. 'Aogonek': 667,
  6923. 'Aring': 667,
  6924. 'Otilde': 778,
  6925. 'zdotaccent': 500,
  6926. 'Ecaron': 667,
  6927. 'Iogonek': 278,
  6928. 'kcommaaccent': 500,
  6929. 'minus': 584,
  6930. 'Icircumflex': 278,
  6931. 'ncaron': 556,
  6932. 'tcommaaccent': 278,
  6933. 'logicalnot': 584,
  6934. 'odieresis': 556,
  6935. 'udieresis': 556,
  6936. 'notequal': 549,
  6937. 'gcommaaccent': 556,
  6938. 'eth': 556,
  6939. 'zcaron': 500,
  6940. 'ncommaaccent': 556,
  6941. 'onesuperior': 333,
  6942. 'imacron': 278,
  6943. 'Euro': 556
  6944. },
  6945. 'Symbol': {
  6946. 'space': 250,
  6947. 'exclam': 333,
  6948. 'universal': 713,
  6949. 'numbersign': 500,
  6950. 'existential': 549,
  6951. 'percent': 833,
  6952. 'ampersand': 778,
  6953. 'suchthat': 439,
  6954. 'parenleft': 333,
  6955. 'parenright': 333,
  6956. 'asteriskmath': 500,
  6957. 'plus': 549,
  6958. 'comma': 250,
  6959. 'minus': 549,
  6960. 'period': 250,
  6961. 'slash': 278,
  6962. 'zero': 500,
  6963. 'one': 500,
  6964. 'two': 500,
  6965. 'three': 500,
  6966. 'four': 500,
  6967. 'five': 500,
  6968. 'six': 500,
  6969. 'seven': 500,
  6970. 'eight': 500,
  6971. 'nine': 500,
  6972. 'colon': 278,
  6973. 'semicolon': 278,
  6974. 'less': 549,
  6975. 'equal': 549,
  6976. 'greater': 549,
  6977. 'question': 444,
  6978. 'congruent': 549,
  6979. 'Alpha': 722,
  6980. 'Beta': 667,
  6981. 'Chi': 722,
  6982. 'Delta': 612,
  6983. 'Epsilon': 611,
  6984. 'Phi': 763,
  6985. 'Gamma': 603,
  6986. 'Eta': 722,
  6987. 'Iota': 333,
  6988. 'theta1': 631,
  6989. 'Kappa': 722,
  6990. 'Lambda': 686,
  6991. 'Mu': 889,
  6992. 'Nu': 722,
  6993. 'Omicron': 722,
  6994. 'Pi': 768,
  6995. 'Theta': 741,
  6996. 'Rho': 556,
  6997. 'Sigma': 592,
  6998. 'Tau': 611,
  6999. 'Upsilon': 690,
  7000. 'sigma1': 439,
  7001. 'Omega': 768,
  7002. 'Xi': 645,
  7003. 'Psi': 795,
  7004. 'Zeta': 611,
  7005. 'bracketleft': 333,
  7006. 'therefore': 863,
  7007. 'bracketright': 333,
  7008. 'perpendicular': 658,
  7009. 'underscore': 500,
  7010. 'radicalex': 500,
  7011. 'alpha': 631,
  7012. 'beta': 549,
  7013. 'chi': 549,
  7014. 'delta': 494,
  7015. 'epsilon': 439,
  7016. 'phi': 521,
  7017. 'gamma': 411,
  7018. 'eta': 603,
  7019. 'iota': 329,
  7020. 'phi1': 603,
  7021. 'kappa': 549,
  7022. 'lambda': 549,
  7023. 'mu': 576,
  7024. 'nu': 521,
  7025. 'omicron': 549,
  7026. 'pi': 549,
  7027. 'theta': 521,
  7028. 'rho': 549,
  7029. 'sigma': 603,
  7030. 'tau': 439,
  7031. 'upsilon': 576,
  7032. 'omega1': 713,
  7033. 'omega': 686,
  7034. 'xi': 493,
  7035. 'psi': 686,
  7036. 'zeta': 494,
  7037. 'braceleft': 480,
  7038. 'bar': 200,
  7039. 'braceright': 480,
  7040. 'similar': 549,
  7041. 'Euro': 750,
  7042. 'Upsilon1': 620,
  7043. 'minute': 247,
  7044. 'lessequal': 549,
  7045. 'fraction': 167,
  7046. 'infinity': 713,
  7047. 'florin': 500,
  7048. 'club': 753,
  7049. 'diamond': 753,
  7050. 'heart': 753,
  7051. 'spade': 753,
  7052. 'arrowboth': 1042,
  7053. 'arrowleft': 987,
  7054. 'arrowup': 603,
  7055. 'arrowright': 987,
  7056. 'arrowdown': 603,
  7057. 'degree': 400,
  7058. 'plusminus': 549,
  7059. 'second': 411,
  7060. 'greaterequal': 549,
  7061. 'multiply': 549,
  7062. 'proportional': 713,
  7063. 'partialdiff': 494,
  7064. 'bullet': 460,
  7065. 'divide': 549,
  7066. 'notequal': 549,
  7067. 'equivalence': 549,
  7068. 'approxequal': 549,
  7069. 'ellipsis': 1000,
  7070. 'arrowvertex': 603,
  7071. 'arrowhorizex': 1000,
  7072. 'carriagereturn': 658,
  7073. 'aleph': 823,
  7074. 'Ifraktur': 686,
  7075. 'Rfraktur': 795,
  7076. 'weierstrass': 987,
  7077. 'circlemultiply': 768,
  7078. 'circleplus': 768,
  7079. 'emptyset': 823,
  7080. 'intersection': 768,
  7081. 'union': 768,
  7082. 'propersuperset': 713,
  7083. 'reflexsuperset': 713,
  7084. 'notsubset': 713,
  7085. 'propersubset': 713,
  7086. 'reflexsubset': 713,
  7087. 'element': 713,
  7088. 'notelement': 713,
  7089. 'angle': 768,
  7090. 'gradient': 713,
  7091. 'registerserif': 790,
  7092. 'copyrightserif': 790,
  7093. 'trademarkserif': 890,
  7094. 'product': 823,
  7095. 'radical': 549,
  7096. 'dotmath': 250,
  7097. 'logicalnot': 713,
  7098. 'logicaland': 603,
  7099. 'logicalor': 603,
  7100. 'arrowdblboth': 1042,
  7101. 'arrowdblleft': 987,
  7102. 'arrowdblup': 603,
  7103. 'arrowdblright': 987,
  7104. 'arrowdbldown': 603,
  7105. 'lozenge': 494,
  7106. 'angleleft': 329,
  7107. 'registersans': 790,
  7108. 'copyrightsans': 790,
  7109. 'trademarksans': 786,
  7110. 'summation': 713,
  7111. 'parenlefttp': 384,
  7112. 'parenleftex': 384,
  7113. 'parenleftbt': 384,
  7114. 'bracketlefttp': 384,
  7115. 'bracketleftex': 384,
  7116. 'bracketleftbt': 384,
  7117. 'bracelefttp': 494,
  7118. 'braceleftmid': 494,
  7119. 'braceleftbt': 494,
  7120. 'braceex': 494,
  7121. 'angleright': 329,
  7122. 'integral': 274,
  7123. 'integraltp': 686,
  7124. 'integralex': 686,
  7125. 'integralbt': 686,
  7126. 'parenrighttp': 384,
  7127. 'parenrightex': 384,
  7128. 'parenrightbt': 384,
  7129. 'bracketrighttp': 384,
  7130. 'bracketrightex': 384,
  7131. 'bracketrightbt': 384,
  7132. 'bracerighttp': 494,
  7133. 'bracerightmid': 494,
  7134. 'bracerightbt': 494,
  7135. 'apple': 790
  7136. },
  7137. 'Times-Roman': {
  7138. 'space': 250,
  7139. 'exclam': 333,
  7140. 'quotedbl': 408,
  7141. 'numbersign': 500,
  7142. 'dollar': 500,
  7143. 'percent': 833,
  7144. 'ampersand': 778,
  7145. 'quoteright': 333,
  7146. 'parenleft': 333,
  7147. 'parenright': 333,
  7148. 'asterisk': 500,
  7149. 'plus': 564,
  7150. 'comma': 250,
  7151. 'hyphen': 333,
  7152. 'period': 250,
  7153. 'slash': 278,
  7154. 'zero': 500,
  7155. 'one': 500,
  7156. 'two': 500,
  7157. 'three': 500,
  7158. 'four': 500,
  7159. 'five': 500,
  7160. 'six': 500,
  7161. 'seven': 500,
  7162. 'eight': 500,
  7163. 'nine': 500,
  7164. 'colon': 278,
  7165. 'semicolon': 278,
  7166. 'less': 564,
  7167. 'equal': 564,
  7168. 'greater': 564,
  7169. 'question': 444,
  7170. 'at': 921,
  7171. 'A': 722,
  7172. 'B': 667,
  7173. 'C': 667,
  7174. 'D': 722,
  7175. 'E': 611,
  7176. 'F': 556,
  7177. 'G': 722,
  7178. 'H': 722,
  7179. 'I': 333,
  7180. 'J': 389,
  7181. 'K': 722,
  7182. 'L': 611,
  7183. 'M': 889,
  7184. 'N': 722,
  7185. 'O': 722,
  7186. 'P': 556,
  7187. 'Q': 722,
  7188. 'R': 667,
  7189. 'S': 556,
  7190. 'T': 611,
  7191. 'U': 722,
  7192. 'V': 722,
  7193. 'W': 944,
  7194. 'X': 722,
  7195. 'Y': 722,
  7196. 'Z': 611,
  7197. 'bracketleft': 333,
  7198. 'backslash': 278,
  7199. 'bracketright': 333,
  7200. 'asciicircum': 469,
  7201. 'underscore': 500,
  7202. 'quoteleft': 333,
  7203. 'a': 444,
  7204. 'b': 500,
  7205. 'c': 444,
  7206. 'd': 500,
  7207. 'e': 444,
  7208. 'f': 333,
  7209. 'g': 500,
  7210. 'h': 500,
  7211. 'i': 278,
  7212. 'j': 278,
  7213. 'k': 500,
  7214. 'l': 278,
  7215. 'm': 778,
  7216. 'n': 500,
  7217. 'o': 500,
  7218. 'p': 500,
  7219. 'q': 500,
  7220. 'r': 333,
  7221. 's': 389,
  7222. 't': 278,
  7223. 'u': 500,
  7224. 'v': 500,
  7225. 'w': 722,
  7226. 'x': 500,
  7227. 'y': 500,
  7228. 'z': 444,
  7229. 'braceleft': 480,
  7230. 'bar': 200,
  7231. 'braceright': 480,
  7232. 'asciitilde': 541,
  7233. 'exclamdown': 333,
  7234. 'cent': 500,
  7235. 'sterling': 500,
  7236. 'fraction': 167,
  7237. 'yen': 500,
  7238. 'florin': 500,
  7239. 'section': 500,
  7240. 'currency': 500,
  7241. 'quotesingle': 180,
  7242. 'quotedblleft': 444,
  7243. 'guillemotleft': 500,
  7244. 'guilsinglleft': 333,
  7245. 'guilsinglright': 333,
  7246. 'fi': 556,
  7247. 'fl': 556,
  7248. 'endash': 500,
  7249. 'dagger': 500,
  7250. 'daggerdbl': 500,
  7251. 'periodcentered': 250,
  7252. 'paragraph': 453,
  7253. 'bullet': 350,
  7254. 'quotesinglbase': 333,
  7255. 'quotedblbase': 444,
  7256. 'quotedblright': 444,
  7257. 'guillemotright': 500,
  7258. 'ellipsis': 1000,
  7259. 'perthousand': 1000,
  7260. 'questiondown': 444,
  7261. 'grave': 333,
  7262. 'acute': 333,
  7263. 'circumflex': 333,
  7264. 'tilde': 333,
  7265. 'macron': 333,
  7266. 'breve': 333,
  7267. 'dotaccent': 333,
  7268. 'dieresis': 333,
  7269. 'ring': 333,
  7270. 'cedilla': 333,
  7271. 'hungarumlaut': 333,
  7272. 'ogonek': 333,
  7273. 'caron': 333,
  7274. 'emdash': 1000,
  7275. 'AE': 889,
  7276. 'ordfeminine': 276,
  7277. 'Lslash': 611,
  7278. 'Oslash': 722,
  7279. 'OE': 889,
  7280. 'ordmasculine': 310,
  7281. 'ae': 667,
  7282. 'dotlessi': 278,
  7283. 'lslash': 278,
  7284. 'oslash': 500,
  7285. 'oe': 722,
  7286. 'germandbls': 500,
  7287. 'Idieresis': 333,
  7288. 'eacute': 444,
  7289. 'abreve': 444,
  7290. 'uhungarumlaut': 500,
  7291. 'ecaron': 444,
  7292. 'Ydieresis': 722,
  7293. 'divide': 564,
  7294. 'Yacute': 722,
  7295. 'Acircumflex': 722,
  7296. 'aacute': 444,
  7297. 'Ucircumflex': 722,
  7298. 'yacute': 500,
  7299. 'scommaaccent': 389,
  7300. 'ecircumflex': 444,
  7301. 'Uring': 722,
  7302. 'Udieresis': 722,
  7303. 'aogonek': 444,
  7304. 'Uacute': 722,
  7305. 'uogonek': 500,
  7306. 'Edieresis': 611,
  7307. 'Dcroat': 722,
  7308. 'commaaccent': 250,
  7309. 'copyright': 760,
  7310. 'Emacron': 611,
  7311. 'ccaron': 444,
  7312. 'aring': 444,
  7313. 'Ncommaaccent': 722,
  7314. 'lacute': 278,
  7315. 'agrave': 444,
  7316. 'Tcommaaccent': 611,
  7317. 'Cacute': 667,
  7318. 'atilde': 444,
  7319. 'Edotaccent': 611,
  7320. 'scaron': 389,
  7321. 'scedilla': 389,
  7322. 'iacute': 278,
  7323. 'lozenge': 471,
  7324. 'Rcaron': 667,
  7325. 'Gcommaaccent': 722,
  7326. 'ucircumflex': 500,
  7327. 'acircumflex': 444,
  7328. 'Amacron': 722,
  7329. 'rcaron': 333,
  7330. 'ccedilla': 444,
  7331. 'Zdotaccent': 611,
  7332. 'Thorn': 556,
  7333. 'Omacron': 722,
  7334. 'Racute': 667,
  7335. 'Sacute': 556,
  7336. 'dcaron': 588,
  7337. 'Umacron': 722,
  7338. 'uring': 500,
  7339. 'threesuperior': 300,
  7340. 'Ograve': 722,
  7341. 'Agrave': 722,
  7342. 'Abreve': 722,
  7343. 'multiply': 564,
  7344. 'uacute': 500,
  7345. 'Tcaron': 611,
  7346. 'partialdiff': 476,
  7347. 'ydieresis': 500,
  7348. 'Nacute': 722,
  7349. 'icircumflex': 278,
  7350. 'Ecircumflex': 611,
  7351. 'adieresis': 444,
  7352. 'edieresis': 444,
  7353. 'cacute': 444,
  7354. 'nacute': 500,
  7355. 'umacron': 500,
  7356. 'Ncaron': 722,
  7357. 'Iacute': 333,
  7358. 'plusminus': 564,
  7359. 'brokenbar': 200,
  7360. 'registered': 760,
  7361. 'Gbreve': 722,
  7362. 'Idotaccent': 333,
  7363. 'summation': 600,
  7364. 'Egrave': 611,
  7365. 'racute': 333,
  7366. 'omacron': 500,
  7367. 'Zacute': 611,
  7368. 'Zcaron': 611,
  7369. 'greaterequal': 549,
  7370. 'Eth': 722,
  7371. 'Ccedilla': 667,
  7372. 'lcommaaccent': 278,
  7373. 'tcaron': 326,
  7374. 'eogonek': 444,
  7375. 'Uogonek': 722,
  7376. 'Aacute': 722,
  7377. 'Adieresis': 722,
  7378. 'egrave': 444,
  7379. 'zacute': 444,
  7380. 'iogonek': 278,
  7381. 'Oacute': 722,
  7382. 'oacute': 500,
  7383. 'amacron': 444,
  7384. 'sacute': 389,
  7385. 'idieresis': 278,
  7386. 'Ocircumflex': 722,
  7387. 'Ugrave': 722,
  7388. 'Delta': 612,
  7389. 'thorn': 500,
  7390. 'twosuperior': 300,
  7391. 'Odieresis': 722,
  7392. 'mu': 500,
  7393. 'igrave': 278,
  7394. 'ohungarumlaut': 500,
  7395. 'Eogonek': 611,
  7396. 'dcroat': 500,
  7397. 'threequarters': 750,
  7398. 'Scedilla': 556,
  7399. 'lcaron': 344,
  7400. 'Kcommaaccent': 722,
  7401. 'Lacute': 611,
  7402. 'trademark': 980,
  7403. 'edotaccent': 444,
  7404. 'Igrave': 333,
  7405. 'Imacron': 333,
  7406. 'Lcaron': 611,
  7407. 'onehalf': 750,
  7408. 'lessequal': 549,
  7409. 'ocircumflex': 500,
  7410. 'ntilde': 500,
  7411. 'Uhungarumlaut': 722,
  7412. 'Eacute': 611,
  7413. 'emacron': 444,
  7414. 'gbreve': 500,
  7415. 'onequarter': 750,
  7416. 'Scaron': 556,
  7417. 'Scommaaccent': 556,
  7418. 'Ohungarumlaut': 722,
  7419. 'degree': 400,
  7420. 'ograve': 500,
  7421. 'Ccaron': 667,
  7422. 'ugrave': 500,
  7423. 'radical': 453,
  7424. 'Dcaron': 722,
  7425. 'rcommaaccent': 333,
  7426. 'Ntilde': 722,
  7427. 'otilde': 500,
  7428. 'Rcommaaccent': 667,
  7429. 'Lcommaaccent': 611,
  7430. 'Atilde': 722,
  7431. 'Aogonek': 722,
  7432. 'Aring': 722,
  7433. 'Otilde': 722,
  7434. 'zdotaccent': 444,
  7435. 'Ecaron': 611,
  7436. 'Iogonek': 333,
  7437. 'kcommaaccent': 500,
  7438. 'minus': 564,
  7439. 'Icircumflex': 333,
  7440. 'ncaron': 500,
  7441. 'tcommaaccent': 278,
  7442. 'logicalnot': 564,
  7443. 'odieresis': 500,
  7444. 'udieresis': 500,
  7445. 'notequal': 549,
  7446. 'gcommaaccent': 500,
  7447. 'eth': 500,
  7448. 'zcaron': 444,
  7449. 'ncommaaccent': 500,
  7450. 'onesuperior': 300,
  7451. 'imacron': 278,
  7452. 'Euro': 500
  7453. },
  7454. 'Times-Bold': {
  7455. 'space': 250,
  7456. 'exclam': 333,
  7457. 'quotedbl': 555,
  7458. 'numbersign': 500,
  7459. 'dollar': 500,
  7460. 'percent': 1000,
  7461. 'ampersand': 833,
  7462. 'quoteright': 333,
  7463. 'parenleft': 333,
  7464. 'parenright': 333,
  7465. 'asterisk': 500,
  7466. 'plus': 570,
  7467. 'comma': 250,
  7468. 'hyphen': 333,
  7469. 'period': 250,
  7470. 'slash': 278,
  7471. 'zero': 500,
  7472. 'one': 500,
  7473. 'two': 500,
  7474. 'three': 500,
  7475. 'four': 500,
  7476. 'five': 500,
  7477. 'six': 500,
  7478. 'seven': 500,
  7479. 'eight': 500,
  7480. 'nine': 500,
  7481. 'colon': 333,
  7482. 'semicolon': 333,
  7483. 'less': 570,
  7484. 'equal': 570,
  7485. 'greater': 570,
  7486. 'question': 500,
  7487. 'at': 930,
  7488. 'A': 722,
  7489. 'B': 667,
  7490. 'C': 722,
  7491. 'D': 722,
  7492. 'E': 667,
  7493. 'F': 611,
  7494. 'G': 778,
  7495. 'H': 778,
  7496. 'I': 389,
  7497. 'J': 500,
  7498. 'K': 778,
  7499. 'L': 667,
  7500. 'M': 944,
  7501. 'N': 722,
  7502. 'O': 778,
  7503. 'P': 611,
  7504. 'Q': 778,
  7505. 'R': 722,
  7506. 'S': 556,
  7507. 'T': 667,
  7508. 'U': 722,
  7509. 'V': 722,
  7510. 'W': 1000,
  7511. 'X': 722,
  7512. 'Y': 722,
  7513. 'Z': 667,
  7514. 'bracketleft': 333,
  7515. 'backslash': 278,
  7516. 'bracketright': 333,
  7517. 'asciicircum': 581,
  7518. 'underscore': 500,
  7519. 'quoteleft': 333,
  7520. 'a': 500,
  7521. 'b': 556,
  7522. 'c': 444,
  7523. 'd': 556,
  7524. 'e': 444,
  7525. 'f': 333,
  7526. 'g': 500,
  7527. 'h': 556,
  7528. 'i': 278,
  7529. 'j': 333,
  7530. 'k': 556,
  7531. 'l': 278,
  7532. 'm': 833,
  7533. 'n': 556,
  7534. 'o': 500,
  7535. 'p': 556,
  7536. 'q': 556,
  7537. 'r': 444,
  7538. 's': 389,
  7539. 't': 333,
  7540. 'u': 556,
  7541. 'v': 500,
  7542. 'w': 722,
  7543. 'x': 500,
  7544. 'y': 500,
  7545. 'z': 444,
  7546. 'braceleft': 394,
  7547. 'bar': 220,
  7548. 'braceright': 394,
  7549. 'asciitilde': 520,
  7550. 'exclamdown': 333,
  7551. 'cent': 500,
  7552. 'sterling': 500,
  7553. 'fraction': 167,
  7554. 'yen': 500,
  7555. 'florin': 500,
  7556. 'section': 500,
  7557. 'currency': 500,
  7558. 'quotesingle': 278,
  7559. 'quotedblleft': 500,
  7560. 'guillemotleft': 500,
  7561. 'guilsinglleft': 333,
  7562. 'guilsinglright': 333,
  7563. 'fi': 556,
  7564. 'fl': 556,
  7565. 'endash': 500,
  7566. 'dagger': 500,
  7567. 'daggerdbl': 500,
  7568. 'periodcentered': 250,
  7569. 'paragraph': 540,
  7570. 'bullet': 350,
  7571. 'quotesinglbase': 333,
  7572. 'quotedblbase': 500,
  7573. 'quotedblright': 500,
  7574. 'guillemotright': 500,
  7575. 'ellipsis': 1000,
  7576. 'perthousand': 1000,
  7577. 'questiondown': 500,
  7578. 'grave': 333,
  7579. 'acute': 333,
  7580. 'circumflex': 333,
  7581. 'tilde': 333,
  7582. 'macron': 333,
  7583. 'breve': 333,
  7584. 'dotaccent': 333,
  7585. 'dieresis': 333,
  7586. 'ring': 333,
  7587. 'cedilla': 333,
  7588. 'hungarumlaut': 333,
  7589. 'ogonek': 333,
  7590. 'caron': 333,
  7591. 'emdash': 1000,
  7592. 'AE': 1000,
  7593. 'ordfeminine': 300,
  7594. 'Lslash': 667,
  7595. 'Oslash': 778,
  7596. 'OE': 1000,
  7597. 'ordmasculine': 330,
  7598. 'ae': 722,
  7599. 'dotlessi': 278,
  7600. 'lslash': 278,
  7601. 'oslash': 500,
  7602. 'oe': 722,
  7603. 'germandbls': 556,
  7604. 'Idieresis': 389,
  7605. 'eacute': 444,
  7606. 'abreve': 500,
  7607. 'uhungarumlaut': 556,
  7608. 'ecaron': 444,
  7609. 'Ydieresis': 722,
  7610. 'divide': 570,
  7611. 'Yacute': 722,
  7612. 'Acircumflex': 722,
  7613. 'aacute': 500,
  7614. 'Ucircumflex': 722,
  7615. 'yacute': 500,
  7616. 'scommaaccent': 389,
  7617. 'ecircumflex': 444,
  7618. 'Uring': 722,
  7619. 'Udieresis': 722,
  7620. 'aogonek': 500,
  7621. 'Uacute': 722,
  7622. 'uogonek': 556,
  7623. 'Edieresis': 667,
  7624. 'Dcroat': 722,
  7625. 'commaaccent': 250,
  7626. 'copyright': 747,
  7627. 'Emacron': 667,
  7628. 'ccaron': 444,
  7629. 'aring': 500,
  7630. 'Ncommaaccent': 722,
  7631. 'lacute': 278,
  7632. 'agrave': 500,
  7633. 'Tcommaaccent': 667,
  7634. 'Cacute': 722,
  7635. 'atilde': 500,
  7636. 'Edotaccent': 667,
  7637. 'scaron': 389,
  7638. 'scedilla': 389,
  7639. 'iacute': 278,
  7640. 'lozenge': 494,
  7641. 'Rcaron': 722,
  7642. 'Gcommaaccent': 778,
  7643. 'ucircumflex': 556,
  7644. 'acircumflex': 500,
  7645. 'Amacron': 722,
  7646. 'rcaron': 444,
  7647. 'ccedilla': 444,
  7648. 'Zdotaccent': 667,
  7649. 'Thorn': 611,
  7650. 'Omacron': 778,
  7651. 'Racute': 722,
  7652. 'Sacute': 556,
  7653. 'dcaron': 672,
  7654. 'Umacron': 722,
  7655. 'uring': 556,
  7656. 'threesuperior': 300,
  7657. 'Ograve': 778,
  7658. 'Agrave': 722,
  7659. 'Abreve': 722,
  7660. 'multiply': 570,
  7661. 'uacute': 556,
  7662. 'Tcaron': 667,
  7663. 'partialdiff': 494,
  7664. 'ydieresis': 500,
  7665. 'Nacute': 722,
  7666. 'icircumflex': 278,
  7667. 'Ecircumflex': 667,
  7668. 'adieresis': 500,
  7669. 'edieresis': 444,
  7670. 'cacute': 444,
  7671. 'nacute': 556,
  7672. 'umacron': 556,
  7673. 'Ncaron': 722,
  7674. 'Iacute': 389,
  7675. 'plusminus': 570,
  7676. 'brokenbar': 220,
  7677. 'registered': 747,
  7678. 'Gbreve': 778,
  7679. 'Idotaccent': 389,
  7680. 'summation': 600,
  7681. 'Egrave': 667,
  7682. 'racute': 444,
  7683. 'omacron': 500,
  7684. 'Zacute': 667,
  7685. 'Zcaron': 667,
  7686. 'greaterequal': 549,
  7687. 'Eth': 722,
  7688. 'Ccedilla': 722,
  7689. 'lcommaaccent': 278,
  7690. 'tcaron': 416,
  7691. 'eogonek': 444,
  7692. 'Uogonek': 722,
  7693. 'Aacute': 722,
  7694. 'Adieresis': 722,
  7695. 'egrave': 444,
  7696. 'zacute': 444,
  7697. 'iogonek': 278,
  7698. 'Oacute': 778,
  7699. 'oacute': 500,
  7700. 'amacron': 500,
  7701. 'sacute': 389,
  7702. 'idieresis': 278,
  7703. 'Ocircumflex': 778,
  7704. 'Ugrave': 722,
  7705. 'Delta': 612,
  7706. 'thorn': 556,
  7707. 'twosuperior': 300,
  7708. 'Odieresis': 778,
  7709. 'mu': 556,
  7710. 'igrave': 278,
  7711. 'ohungarumlaut': 500,
  7712. 'Eogonek': 667,
  7713. 'dcroat': 556,
  7714. 'threequarters': 750,
  7715. 'Scedilla': 556,
  7716. 'lcaron': 394,
  7717. 'Kcommaaccent': 778,
  7718. 'Lacute': 667,
  7719. 'trademark': 1000,
  7720. 'edotaccent': 444,
  7721. 'Igrave': 389,
  7722. 'Imacron': 389,
  7723. 'Lcaron': 667,
  7724. 'onehalf': 750,
  7725. 'lessequal': 549,
  7726. 'ocircumflex': 500,
  7727. 'ntilde': 556,
  7728. 'Uhungarumlaut': 722,
  7729. 'Eacute': 667,
  7730. 'emacron': 444,
  7731. 'gbreve': 500,
  7732. 'onequarter': 750,
  7733. 'Scaron': 556,
  7734. 'Scommaaccent': 556,
  7735. 'Ohungarumlaut': 778,
  7736. 'degree': 400,
  7737. 'ograve': 500,
  7738. 'Ccaron': 722,
  7739. 'ugrave': 556,
  7740. 'radical': 549,
  7741. 'Dcaron': 722,
  7742. 'rcommaaccent': 444,
  7743. 'Ntilde': 722,
  7744. 'otilde': 500,
  7745. 'Rcommaaccent': 722,
  7746. 'Lcommaaccent': 667,
  7747. 'Atilde': 722,
  7748. 'Aogonek': 722,
  7749. 'Aring': 722,
  7750. 'Otilde': 778,
  7751. 'zdotaccent': 444,
  7752. 'Ecaron': 667,
  7753. 'Iogonek': 389,
  7754. 'kcommaaccent': 556,
  7755. 'minus': 570,
  7756. 'Icircumflex': 389,
  7757. 'ncaron': 556,
  7758. 'tcommaaccent': 333,
  7759. 'logicalnot': 570,
  7760. 'odieresis': 500,
  7761. 'udieresis': 556,
  7762. 'notequal': 549,
  7763. 'gcommaaccent': 500,
  7764. 'eth': 500,
  7765. 'zcaron': 444,
  7766. 'ncommaaccent': 556,
  7767. 'onesuperior': 300,
  7768. 'imacron': 278,
  7769. 'Euro': 500
  7770. },
  7771. 'Times-BoldItalic': {
  7772. 'space': 250,
  7773. 'exclam': 389,
  7774. 'quotedbl': 555,
  7775. 'numbersign': 500,
  7776. 'dollar': 500,
  7777. 'percent': 833,
  7778. 'ampersand': 778,
  7779. 'quoteright': 333,
  7780. 'parenleft': 333,
  7781. 'parenright': 333,
  7782. 'asterisk': 500,
  7783. 'plus': 570,
  7784. 'comma': 250,
  7785. 'hyphen': 333,
  7786. 'period': 250,
  7787. 'slash': 278,
  7788. 'zero': 500,
  7789. 'one': 500,
  7790. 'two': 500,
  7791. 'three': 500,
  7792. 'four': 500,
  7793. 'five': 500,
  7794. 'six': 500,
  7795. 'seven': 500,
  7796. 'eight': 500,
  7797. 'nine': 500,
  7798. 'colon': 333,
  7799. 'semicolon': 333,
  7800. 'less': 570,
  7801. 'equal': 570,
  7802. 'greater': 570,
  7803. 'question': 500,
  7804. 'at': 832,
  7805. 'A': 667,
  7806. 'B': 667,
  7807. 'C': 667,
  7808. 'D': 722,
  7809. 'E': 667,
  7810. 'F': 667,
  7811. 'G': 722,
  7812. 'H': 778,
  7813. 'I': 389,
  7814. 'J': 500,
  7815. 'K': 667,
  7816. 'L': 611,
  7817. 'M': 889,
  7818. 'N': 722,
  7819. 'O': 722,
  7820. 'P': 611,
  7821. 'Q': 722,
  7822. 'R': 667,
  7823. 'S': 556,
  7824. 'T': 611,
  7825. 'U': 722,
  7826. 'V': 667,
  7827. 'W': 889,
  7828. 'X': 667,
  7829. 'Y': 611,
  7830. 'Z': 611,
  7831. 'bracketleft': 333,
  7832. 'backslash': 278,
  7833. 'bracketright': 333,
  7834. 'asciicircum': 570,
  7835. 'underscore': 500,
  7836. 'quoteleft': 333,
  7837. 'a': 500,
  7838. 'b': 500,
  7839. 'c': 444,
  7840. 'd': 500,
  7841. 'e': 444,
  7842. 'f': 333,
  7843. 'g': 500,
  7844. 'h': 556,
  7845. 'i': 278,
  7846. 'j': 278,
  7847. 'k': 500,
  7848. 'l': 278,
  7849. 'm': 778,
  7850. 'n': 556,
  7851. 'o': 500,
  7852. 'p': 500,
  7853. 'q': 500,
  7854. 'r': 389,
  7855. 's': 389,
  7856. 't': 278,
  7857. 'u': 556,
  7858. 'v': 444,
  7859. 'w': 667,
  7860. 'x': 500,
  7861. 'y': 444,
  7862. 'z': 389,
  7863. 'braceleft': 348,
  7864. 'bar': 220,
  7865. 'braceright': 348,
  7866. 'asciitilde': 570,
  7867. 'exclamdown': 389,
  7868. 'cent': 500,
  7869. 'sterling': 500,
  7870. 'fraction': 167,
  7871. 'yen': 500,
  7872. 'florin': 500,
  7873. 'section': 500,
  7874. 'currency': 500,
  7875. 'quotesingle': 278,
  7876. 'quotedblleft': 500,
  7877. 'guillemotleft': 500,
  7878. 'guilsinglleft': 333,
  7879. 'guilsinglright': 333,
  7880. 'fi': 556,
  7881. 'fl': 556,
  7882. 'endash': 500,
  7883. 'dagger': 500,
  7884. 'daggerdbl': 500,
  7885. 'periodcentered': 250,
  7886. 'paragraph': 500,
  7887. 'bullet': 350,
  7888. 'quotesinglbase': 333,
  7889. 'quotedblbase': 500,
  7890. 'quotedblright': 500,
  7891. 'guillemotright': 500,
  7892. 'ellipsis': 1000,
  7893. 'perthousand': 1000,
  7894. 'questiondown': 500,
  7895. 'grave': 333,
  7896. 'acute': 333,
  7897. 'circumflex': 333,
  7898. 'tilde': 333,
  7899. 'macron': 333,
  7900. 'breve': 333,
  7901. 'dotaccent': 333,
  7902. 'dieresis': 333,
  7903. 'ring': 333,
  7904. 'cedilla': 333,
  7905. 'hungarumlaut': 333,
  7906. 'ogonek': 333,
  7907. 'caron': 333,
  7908. 'emdash': 1000,
  7909. 'AE': 944,
  7910. 'ordfeminine': 266,
  7911. 'Lslash': 611,
  7912. 'Oslash': 722,
  7913. 'OE': 944,
  7914. 'ordmasculine': 300,
  7915. 'ae': 722,
  7916. 'dotlessi': 278,
  7917. 'lslash': 278,
  7918. 'oslash': 500,
  7919. 'oe': 722,
  7920. 'germandbls': 500,
  7921. 'Idieresis': 389,
  7922. 'eacute': 444,
  7923. 'abreve': 500,
  7924. 'uhungarumlaut': 556,
  7925. 'ecaron': 444,
  7926. 'Ydieresis': 611,
  7927. 'divide': 570,
  7928. 'Yacute': 611,
  7929. 'Acircumflex': 667,
  7930. 'aacute': 500,
  7931. 'Ucircumflex': 722,
  7932. 'yacute': 444,
  7933. 'scommaaccent': 389,
  7934. 'ecircumflex': 444,
  7935. 'Uring': 722,
  7936. 'Udieresis': 722,
  7937. 'aogonek': 500,
  7938. 'Uacute': 722,
  7939. 'uogonek': 556,
  7940. 'Edieresis': 667,
  7941. 'Dcroat': 722,
  7942. 'commaaccent': 250,
  7943. 'copyright': 747,
  7944. 'Emacron': 667,
  7945. 'ccaron': 444,
  7946. 'aring': 500,
  7947. 'Ncommaaccent': 722,
  7948. 'lacute': 278,
  7949. 'agrave': 500,
  7950. 'Tcommaaccent': 611,
  7951. 'Cacute': 667,
  7952. 'atilde': 500,
  7953. 'Edotaccent': 667,
  7954. 'scaron': 389,
  7955. 'scedilla': 389,
  7956. 'iacute': 278,
  7957. 'lozenge': 494,
  7958. 'Rcaron': 667,
  7959. 'Gcommaaccent': 722,
  7960. 'ucircumflex': 556,
  7961. 'acircumflex': 500,
  7962. 'Amacron': 667,
  7963. 'rcaron': 389,
  7964. 'ccedilla': 444,
  7965. 'Zdotaccent': 611,
  7966. 'Thorn': 611,
  7967. 'Omacron': 722,
  7968. 'Racute': 667,
  7969. 'Sacute': 556,
  7970. 'dcaron': 608,
  7971. 'Umacron': 722,
  7972. 'uring': 556,
  7973. 'threesuperior': 300,
  7974. 'Ograve': 722,
  7975. 'Agrave': 667,
  7976. 'Abreve': 667,
  7977. 'multiply': 570,
  7978. 'uacute': 556,
  7979. 'Tcaron': 611,
  7980. 'partialdiff': 494,
  7981. 'ydieresis': 444,
  7982. 'Nacute': 722,
  7983. 'icircumflex': 278,
  7984. 'Ecircumflex': 667,
  7985. 'adieresis': 500,
  7986. 'edieresis': 444,
  7987. 'cacute': 444,
  7988. 'nacute': 556,
  7989. 'umacron': 556,
  7990. 'Ncaron': 722,
  7991. 'Iacute': 389,
  7992. 'plusminus': 570,
  7993. 'brokenbar': 220,
  7994. 'registered': 747,
  7995. 'Gbreve': 722,
  7996. 'Idotaccent': 389,
  7997. 'summation': 600,
  7998. 'Egrave': 667,
  7999. 'racute': 389,
  8000. 'omacron': 500,
  8001. 'Zacute': 611,
  8002. 'Zcaron': 611,
  8003. 'greaterequal': 549,
  8004. 'Eth': 722,
  8005. 'Ccedilla': 667,
  8006. 'lcommaaccent': 278,
  8007. 'tcaron': 366,
  8008. 'eogonek': 444,
  8009. 'Uogonek': 722,
  8010. 'Aacute': 667,
  8011. 'Adieresis': 667,
  8012. 'egrave': 444,
  8013. 'zacute': 389,
  8014. 'iogonek': 278,
  8015. 'Oacute': 722,
  8016. 'oacute': 500,
  8017. 'amacron': 500,
  8018. 'sacute': 389,
  8019. 'idieresis': 278,
  8020. 'Ocircumflex': 722,
  8021. 'Ugrave': 722,
  8022. 'Delta': 612,
  8023. 'thorn': 500,
  8024. 'twosuperior': 300,
  8025. 'Odieresis': 722,
  8026. 'mu': 576,
  8027. 'igrave': 278,
  8028. 'ohungarumlaut': 500,
  8029. 'Eogonek': 667,
  8030. 'dcroat': 500,
  8031. 'threequarters': 750,
  8032. 'Scedilla': 556,
  8033. 'lcaron': 382,
  8034. 'Kcommaaccent': 667,
  8035. 'Lacute': 611,
  8036. 'trademark': 1000,
  8037. 'edotaccent': 444,
  8038. 'Igrave': 389,
  8039. 'Imacron': 389,
  8040. 'Lcaron': 611,
  8041. 'onehalf': 750,
  8042. 'lessequal': 549,
  8043. 'ocircumflex': 500,
  8044. 'ntilde': 556,
  8045. 'Uhungarumlaut': 722,
  8046. 'Eacute': 667,
  8047. 'emacron': 444,
  8048. 'gbreve': 500,
  8049. 'onequarter': 750,
  8050. 'Scaron': 556,
  8051. 'Scommaaccent': 556,
  8052. 'Ohungarumlaut': 722,
  8053. 'degree': 400,
  8054. 'ograve': 500,
  8055. 'Ccaron': 667,
  8056. 'ugrave': 556,
  8057. 'radical': 549,
  8058. 'Dcaron': 722,
  8059. 'rcommaaccent': 389,
  8060. 'Ntilde': 722,
  8061. 'otilde': 500,
  8062. 'Rcommaaccent': 667,
  8063. 'Lcommaaccent': 611,
  8064. 'Atilde': 667,
  8065. 'Aogonek': 667,
  8066. 'Aring': 667,
  8067. 'Otilde': 722,
  8068. 'zdotaccent': 389,
  8069. 'Ecaron': 667,
  8070. 'Iogonek': 389,
  8071. 'kcommaaccent': 500,
  8072. 'minus': 606,
  8073. 'Icircumflex': 389,
  8074. 'ncaron': 556,
  8075. 'tcommaaccent': 278,
  8076. 'logicalnot': 606,
  8077. 'odieresis': 500,
  8078. 'udieresis': 556,
  8079. 'notequal': 549,
  8080. 'gcommaaccent': 500,
  8081. 'eth': 500,
  8082. 'zcaron': 389,
  8083. 'ncommaaccent': 556,
  8084. 'onesuperior': 300,
  8085. 'imacron': 278,
  8086. 'Euro': 500
  8087. },
  8088. 'Times-Italic': {
  8089. 'space': 250,
  8090. 'exclam': 333,
  8091. 'quotedbl': 420,
  8092. 'numbersign': 500,
  8093. 'dollar': 500,
  8094. 'percent': 833,
  8095. 'ampersand': 778,
  8096. 'quoteright': 333,
  8097. 'parenleft': 333,
  8098. 'parenright': 333,
  8099. 'asterisk': 500,
  8100. 'plus': 675,
  8101. 'comma': 250,
  8102. 'hyphen': 333,
  8103. 'period': 250,
  8104. 'slash': 278,
  8105. 'zero': 500,
  8106. 'one': 500,
  8107. 'two': 500,
  8108. 'three': 500,
  8109. 'four': 500,
  8110. 'five': 500,
  8111. 'six': 500,
  8112. 'seven': 500,
  8113. 'eight': 500,
  8114. 'nine': 500,
  8115. 'colon': 333,
  8116. 'semicolon': 333,
  8117. 'less': 675,
  8118. 'equal': 675,
  8119. 'greater': 675,
  8120. 'question': 500,
  8121. 'at': 920,
  8122. 'A': 611,
  8123. 'B': 611,
  8124. 'C': 667,
  8125. 'D': 722,
  8126. 'E': 611,
  8127. 'F': 611,
  8128. 'G': 722,
  8129. 'H': 722,
  8130. 'I': 333,
  8131. 'J': 444,
  8132. 'K': 667,
  8133. 'L': 556,
  8134. 'M': 833,
  8135. 'N': 667,
  8136. 'O': 722,
  8137. 'P': 611,
  8138. 'Q': 722,
  8139. 'R': 611,
  8140. 'S': 500,
  8141. 'T': 556,
  8142. 'U': 722,
  8143. 'V': 611,
  8144. 'W': 833,
  8145. 'X': 611,
  8146. 'Y': 556,
  8147. 'Z': 556,
  8148. 'bracketleft': 389,
  8149. 'backslash': 278,
  8150. 'bracketright': 389,
  8151. 'asciicircum': 422,
  8152. 'underscore': 500,
  8153. 'quoteleft': 333,
  8154. 'a': 500,
  8155. 'b': 500,
  8156. 'c': 444,
  8157. 'd': 500,
  8158. 'e': 444,
  8159. 'f': 278,
  8160. 'g': 500,
  8161. 'h': 500,
  8162. 'i': 278,
  8163. 'j': 278,
  8164. 'k': 444,
  8165. 'l': 278,
  8166. 'm': 722,
  8167. 'n': 500,
  8168. 'o': 500,
  8169. 'p': 500,
  8170. 'q': 500,
  8171. 'r': 389,
  8172. 's': 389,
  8173. 't': 278,
  8174. 'u': 500,
  8175. 'v': 444,
  8176. 'w': 667,
  8177. 'x': 444,
  8178. 'y': 444,
  8179. 'z': 389,
  8180. 'braceleft': 400,
  8181. 'bar': 275,
  8182. 'braceright': 400,
  8183. 'asciitilde': 541,
  8184. 'exclamdown': 389,
  8185. 'cent': 500,
  8186. 'sterling': 500,
  8187. 'fraction': 167,
  8188. 'yen': 500,
  8189. 'florin': 500,
  8190. 'section': 500,
  8191. 'currency': 500,
  8192. 'quotesingle': 214,
  8193. 'quotedblleft': 556,
  8194. 'guillemotleft': 500,
  8195. 'guilsinglleft': 333,
  8196. 'guilsinglright': 333,
  8197. 'fi': 500,
  8198. 'fl': 500,
  8199. 'endash': 500,
  8200. 'dagger': 500,
  8201. 'daggerdbl': 500,
  8202. 'periodcentered': 250,
  8203. 'paragraph': 523,
  8204. 'bullet': 350,
  8205. 'quotesinglbase': 333,
  8206. 'quotedblbase': 556,
  8207. 'quotedblright': 556,
  8208. 'guillemotright': 500,
  8209. 'ellipsis': 889,
  8210. 'perthousand': 1000,
  8211. 'questiondown': 500,
  8212. 'grave': 333,
  8213. 'acute': 333,
  8214. 'circumflex': 333,
  8215. 'tilde': 333,
  8216. 'macron': 333,
  8217. 'breve': 333,
  8218. 'dotaccent': 333,
  8219. 'dieresis': 333,
  8220. 'ring': 333,
  8221. 'cedilla': 333,
  8222. 'hungarumlaut': 333,
  8223. 'ogonek': 333,
  8224. 'caron': 333,
  8225. 'emdash': 889,
  8226. 'AE': 889,
  8227. 'ordfeminine': 276,
  8228. 'Lslash': 556,
  8229. 'Oslash': 722,
  8230. 'OE': 944,
  8231. 'ordmasculine': 310,
  8232. 'ae': 667,
  8233. 'dotlessi': 278,
  8234. 'lslash': 278,
  8235. 'oslash': 500,
  8236. 'oe': 667,
  8237. 'germandbls': 500,
  8238. 'Idieresis': 333,
  8239. 'eacute': 444,
  8240. 'abreve': 500,
  8241. 'uhungarumlaut': 500,
  8242. 'ecaron': 444,
  8243. 'Ydieresis': 556,
  8244. 'divide': 675,
  8245. 'Yacute': 556,
  8246. 'Acircumflex': 611,
  8247. 'aacute': 500,
  8248. 'Ucircumflex': 722,
  8249. 'yacute': 444,
  8250. 'scommaaccent': 389,
  8251. 'ecircumflex': 444,
  8252. 'Uring': 722,
  8253. 'Udieresis': 722,
  8254. 'aogonek': 500,
  8255. 'Uacute': 722,
  8256. 'uogonek': 500,
  8257. 'Edieresis': 611,
  8258. 'Dcroat': 722,
  8259. 'commaaccent': 250,
  8260. 'copyright': 760,
  8261. 'Emacron': 611,
  8262. 'ccaron': 444,
  8263. 'aring': 500,
  8264. 'Ncommaaccent': 667,
  8265. 'lacute': 278,
  8266. 'agrave': 500,
  8267. 'Tcommaaccent': 556,
  8268. 'Cacute': 667,
  8269. 'atilde': 500,
  8270. 'Edotaccent': 611,
  8271. 'scaron': 389,
  8272. 'scedilla': 389,
  8273. 'iacute': 278,
  8274. 'lozenge': 471,
  8275. 'Rcaron': 611,
  8276. 'Gcommaaccent': 722,
  8277. 'ucircumflex': 500,
  8278. 'acircumflex': 500,
  8279. 'Amacron': 611,
  8280. 'rcaron': 389,
  8281. 'ccedilla': 444,
  8282. 'Zdotaccent': 556,
  8283. 'Thorn': 611,
  8284. 'Omacron': 722,
  8285. 'Racute': 611,
  8286. 'Sacute': 500,
  8287. 'dcaron': 544,
  8288. 'Umacron': 722,
  8289. 'uring': 500,
  8290. 'threesuperior': 300,
  8291. 'Ograve': 722,
  8292. 'Agrave': 611,
  8293. 'Abreve': 611,
  8294. 'multiply': 675,
  8295. 'uacute': 500,
  8296. 'Tcaron': 556,
  8297. 'partialdiff': 476,
  8298. 'ydieresis': 444,
  8299. 'Nacute': 667,
  8300. 'icircumflex': 278,
  8301. 'Ecircumflex': 611,
  8302. 'adieresis': 500,
  8303. 'edieresis': 444,
  8304. 'cacute': 444,
  8305. 'nacute': 500,
  8306. 'umacron': 500,
  8307. 'Ncaron': 667,
  8308. 'Iacute': 333,
  8309. 'plusminus': 675,
  8310. 'brokenbar': 275,
  8311. 'registered': 760,
  8312. 'Gbreve': 722,
  8313. 'Idotaccent': 333,
  8314. 'summation': 600,
  8315. 'Egrave': 611,
  8316. 'racute': 389,
  8317. 'omacron': 500,
  8318. 'Zacute': 556,
  8319. 'Zcaron': 556,
  8320. 'greaterequal': 549,
  8321. 'Eth': 722,
  8322. 'Ccedilla': 667,
  8323. 'lcommaaccent': 278,
  8324. 'tcaron': 300,
  8325. 'eogonek': 444,
  8326. 'Uogonek': 722,
  8327. 'Aacute': 611,
  8328. 'Adieresis': 611,
  8329. 'egrave': 444,
  8330. 'zacute': 389,
  8331. 'iogonek': 278,
  8332. 'Oacute': 722,
  8333. 'oacute': 500,
  8334. 'amacron': 500,
  8335. 'sacute': 389,
  8336. 'idieresis': 278,
  8337. 'Ocircumflex': 722,
  8338. 'Ugrave': 722,
  8339. 'Delta': 612,
  8340. 'thorn': 500,
  8341. 'twosuperior': 300,
  8342. 'Odieresis': 722,
  8343. 'mu': 500,
  8344. 'igrave': 278,
  8345. 'ohungarumlaut': 500,
  8346. 'Eogonek': 611,
  8347. 'dcroat': 500,
  8348. 'threequarters': 750,
  8349. 'Scedilla': 500,
  8350. 'lcaron': 300,
  8351. 'Kcommaaccent': 667,
  8352. 'Lacute': 556,
  8353. 'trademark': 980,
  8354. 'edotaccent': 444,
  8355. 'Igrave': 333,
  8356. 'Imacron': 333,
  8357. 'Lcaron': 611,
  8358. 'onehalf': 750,
  8359. 'lessequal': 549,
  8360. 'ocircumflex': 500,
  8361. 'ntilde': 500,
  8362. 'Uhungarumlaut': 722,
  8363. 'Eacute': 611,
  8364. 'emacron': 444,
  8365. 'gbreve': 500,
  8366. 'onequarter': 750,
  8367. 'Scaron': 500,
  8368. 'Scommaaccent': 500,
  8369. 'Ohungarumlaut': 722,
  8370. 'degree': 400,
  8371. 'ograve': 500,
  8372. 'Ccaron': 667,
  8373. 'ugrave': 500,
  8374. 'radical': 453,
  8375. 'Dcaron': 722,
  8376. 'rcommaaccent': 389,
  8377. 'Ntilde': 667,
  8378. 'otilde': 500,
  8379. 'Rcommaaccent': 611,
  8380. 'Lcommaaccent': 556,
  8381. 'Atilde': 611,
  8382. 'Aogonek': 611,
  8383. 'Aring': 611,
  8384. 'Otilde': 722,
  8385. 'zdotaccent': 389,
  8386. 'Ecaron': 611,
  8387. 'Iogonek': 333,
  8388. 'kcommaaccent': 444,
  8389. 'minus': 675,
  8390. 'Icircumflex': 333,
  8391. 'ncaron': 500,
  8392. 'tcommaaccent': 278,
  8393. 'logicalnot': 675,
  8394. 'odieresis': 500,
  8395. 'udieresis': 500,
  8396. 'notequal': 549,
  8397. 'gcommaaccent': 500,
  8398. 'eth': 500,
  8399. 'zcaron': 389,
  8400. 'ncommaaccent': 500,
  8401. 'onesuperior': 300,
  8402. 'imacron': 278,
  8403. 'Euro': 500
  8404. },
  8405. 'ZapfDingbats': {
  8406. 'space': 278,
  8407. 'a1': 974,
  8408. 'a2': 961,
  8409. 'a202': 974,
  8410. 'a3': 980,
  8411. 'a4': 719,
  8412. 'a5': 789,
  8413. 'a119': 790,
  8414. 'a118': 791,
  8415. 'a117': 690,
  8416. 'a11': 960,
  8417. 'a12': 939,
  8418. 'a13': 549,
  8419. 'a14': 855,
  8420. 'a15': 911,
  8421. 'a16': 933,
  8422. 'a105': 911,
  8423. 'a17': 945,
  8424. 'a18': 974,
  8425. 'a19': 755,
  8426. 'a20': 846,
  8427. 'a21': 762,
  8428. 'a22': 761,
  8429. 'a23': 571,
  8430. 'a24': 677,
  8431. 'a25': 763,
  8432. 'a26': 760,
  8433. 'a27': 759,
  8434. 'a28': 754,
  8435. 'a6': 494,
  8436. 'a7': 552,
  8437. 'a8': 537,
  8438. 'a9': 577,
  8439. 'a10': 692,
  8440. 'a29': 786,
  8441. 'a30': 788,
  8442. 'a31': 788,
  8443. 'a32': 790,
  8444. 'a33': 793,
  8445. 'a34': 794,
  8446. 'a35': 816,
  8447. 'a36': 823,
  8448. 'a37': 789,
  8449. 'a38': 841,
  8450. 'a39': 823,
  8451. 'a40': 833,
  8452. 'a41': 816,
  8453. 'a42': 831,
  8454. 'a43': 923,
  8455. 'a44': 744,
  8456. 'a45': 723,
  8457. 'a46': 749,
  8458. 'a47': 790,
  8459. 'a48': 792,
  8460. 'a49': 695,
  8461. 'a50': 776,
  8462. 'a51': 768,
  8463. 'a52': 792,
  8464. 'a53': 759,
  8465. 'a54': 707,
  8466. 'a55': 708,
  8467. 'a56': 682,
  8468. 'a57': 701,
  8469. 'a58': 826,
  8470. 'a59': 815,
  8471. 'a60': 789,
  8472. 'a61': 789,
  8473. 'a62': 707,
  8474. 'a63': 687,
  8475. 'a64': 696,
  8476. 'a65': 689,
  8477. 'a66': 786,
  8478. 'a67': 787,
  8479. 'a68': 713,
  8480. 'a69': 791,
  8481. 'a70': 785,
  8482. 'a71': 791,
  8483. 'a72': 873,
  8484. 'a73': 761,
  8485. 'a74': 762,
  8486. 'a203': 762,
  8487. 'a75': 759,
  8488. 'a204': 759,
  8489. 'a76': 892,
  8490. 'a77': 892,
  8491. 'a78': 788,
  8492. 'a79': 784,
  8493. 'a81': 438,
  8494. 'a82': 138,
  8495. 'a83': 277,
  8496. 'a84': 415,
  8497. 'a97': 392,
  8498. 'a98': 392,
  8499. 'a99': 668,
  8500. 'a100': 668,
  8501. 'a89': 390,
  8502. 'a90': 390,
  8503. 'a93': 317,
  8504. 'a94': 317,
  8505. 'a91': 276,
  8506. 'a92': 276,
  8507. 'a205': 509,
  8508. 'a85': 509,
  8509. 'a206': 410,
  8510. 'a86': 410,
  8511. 'a87': 234,
  8512. 'a88': 234,
  8513. 'a95': 334,
  8514. 'a96': 334,
  8515. 'a101': 732,
  8516. 'a102': 544,
  8517. 'a103': 544,
  8518. 'a104': 910,
  8519. 'a106': 667,
  8520. 'a107': 760,
  8521. 'a108': 760,
  8522. 'a112': 776,
  8523. 'a111': 595,
  8524. 'a110': 694,
  8525. 'a109': 626,
  8526. 'a120': 788,
  8527. 'a121': 788,
  8528. 'a122': 788,
  8529. 'a123': 788,
  8530. 'a124': 788,
  8531. 'a125': 788,
  8532. 'a126': 788,
  8533. 'a127': 788,
  8534. 'a128': 788,
  8535. 'a129': 788,
  8536. 'a130': 788,
  8537. 'a131': 788,
  8538. 'a132': 788,
  8539. 'a133': 788,
  8540. 'a134': 788,
  8541. 'a135': 788,
  8542. 'a136': 788,
  8543. 'a137': 788,
  8544. 'a138': 788,
  8545. 'a139': 788,
  8546. 'a140': 788,
  8547. 'a141': 788,
  8548. 'a142': 788,
  8549. 'a143': 788,
  8550. 'a144': 788,
  8551. 'a145': 788,
  8552. 'a146': 788,
  8553. 'a147': 788,
  8554. 'a148': 788,
  8555. 'a149': 788,
  8556. 'a150': 788,
  8557. 'a151': 788,
  8558. 'a152': 788,
  8559. 'a153': 788,
  8560. 'a154': 788,
  8561. 'a155': 788,
  8562. 'a156': 788,
  8563. 'a157': 788,
  8564. 'a158': 788,
  8565. 'a159': 788,
  8566. 'a160': 894,
  8567. 'a161': 838,
  8568. 'a163': 1016,
  8569. 'a164': 458,
  8570. 'a196': 748,
  8571. 'a165': 924,
  8572. 'a192': 748,
  8573. 'a166': 918,
  8574. 'a167': 927,
  8575. 'a168': 928,
  8576. 'a169': 928,
  8577. 'a170': 834,
  8578. 'a171': 873,
  8579. 'a172': 828,
  8580. 'a173': 924,
  8581. 'a162': 924,
  8582. 'a174': 917,
  8583. 'a175': 930,
  8584. 'a176': 931,
  8585. 'a177': 463,
  8586. 'a178': 883,
  8587. 'a179': 836,
  8588. 'a193': 836,
  8589. 'a180': 867,
  8590. 'a199': 867,
  8591. 'a181': 696,
  8592. 'a200': 696,
  8593. 'a182': 874,
  8594. 'a201': 874,
  8595. 'a183': 760,
  8596. 'a184': 946,
  8597. 'a197': 771,
  8598. 'a185': 865,
  8599. 'a194': 771,
  8600. 'a198': 888,
  8601. 'a186': 967,
  8602. 'a195': 888,
  8603. 'a187': 831,
  8604. 'a188': 873,
  8605. 'a189': 927,
  8606. 'a190': 970,
  8607. 'a191': 918
  8608. }
  8609. };
  8610. exports.Metrics = Metrics;
  8611. }));
  8612. var NetworkManager = (function NetworkManagerClosure() {
  8613. var OK_RESPONSE = 200;
  8614. var PARTIAL_CONTENT_RESPONSE = 206;
  8615. function NetworkManager(url, args) {
  8616. this.url = url;
  8617. args = args || {};
  8618. this.isHttp = /^https?:/i.test(url);
  8619. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8620. this.withCredentials = args.withCredentials || false;
  8621. this.getXhr = args.getXhr ||
  8622. function NetworkManager_getXhr() {
  8623. return new XMLHttpRequest();
  8624. };
  8625. this.currXhrId = 0;
  8626. this.pendingRequests = {};
  8627. this.loadedRequests = {};
  8628. }
  8629. function getArrayBuffer(xhr) {
  8630. var data = xhr.response;
  8631. if (typeof data !== 'string') {
  8632. return data;
  8633. }
  8634. var length = data.length;
  8635. var array = new Uint8Array(length);
  8636. for (var i = 0; i < length; i++) {
  8637. array[i] = data.charCodeAt(i) & 0xFF;
  8638. }
  8639. return array.buffer;
  8640. }
  8641. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8642. try {
  8643. var x = new XMLHttpRequest();
  8644. // Firefox 37- required .open() to be called before setting responseType.
  8645. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8646. // Even though the URL is not visited, .open() could fail if the URL is
  8647. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8648. // When this error occurs, this feature detection method will mistakenly
  8649. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8650. x.open('GET', 'https://example.com');
  8651. x.responseType = 'moz-chunked-arraybuffer';
  8652. return x.responseType === 'moz-chunked-arraybuffer';
  8653. } catch (e) {
  8654. return false;
  8655. }
  8656. })();
  8657. NetworkManager.prototype = {
  8658. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8659. var args = {
  8660. begin: begin,
  8661. end: end
  8662. };
  8663. for (var prop in listeners) {
  8664. args[prop] = listeners[prop];
  8665. }
  8666. return this.request(args);
  8667. },
  8668. requestFull: function NetworkManager_requestFull(listeners) {
  8669. return this.request(listeners);
  8670. },
  8671. request: function NetworkManager_request(args) {
  8672. var xhr = this.getXhr();
  8673. var xhrId = this.currXhrId++;
  8674. var pendingRequest = this.pendingRequests[xhrId] = {
  8675. xhr: xhr
  8676. };
  8677. xhr.open('GET', this.url);
  8678. xhr.withCredentials = this.withCredentials;
  8679. for (var property in this.httpHeaders) {
  8680. var value = this.httpHeaders[property];
  8681. if (typeof value === 'undefined') {
  8682. continue;
  8683. }
  8684. xhr.setRequestHeader(property, value);
  8685. }
  8686. if (this.isHttp && 'begin' in args && 'end' in args) {
  8687. var rangeStr = args.begin + '-' + (args.end - 1);
  8688. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8689. pendingRequest.expectedStatus = 206;
  8690. } else {
  8691. pendingRequest.expectedStatus = 200;
  8692. }
  8693. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8694. if (useMozChunkedLoading) {
  8695. xhr.responseType = 'moz-chunked-arraybuffer';
  8696. pendingRequest.onProgressiveData = args.onProgressiveData;
  8697. pendingRequest.mozChunked = true;
  8698. } else {
  8699. xhr.responseType = 'arraybuffer';
  8700. }
  8701. if (args.onError) {
  8702. xhr.onerror = function(evt) {
  8703. args.onError(xhr.status);
  8704. };
  8705. }
  8706. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8707. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8708. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8709. pendingRequest.onDone = args.onDone;
  8710. pendingRequest.onError = args.onError;
  8711. pendingRequest.onProgress = args.onProgress;
  8712. xhr.send(null);
  8713. return xhrId;
  8714. },
  8715. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8716. var pendingRequest = this.pendingRequests[xhrId];
  8717. if (!pendingRequest) {
  8718. // Maybe abortRequest was called...
  8719. return;
  8720. }
  8721. if (pendingRequest.mozChunked) {
  8722. var chunk = getArrayBuffer(pendingRequest.xhr);
  8723. pendingRequest.onProgressiveData(chunk);
  8724. }
  8725. var onProgress = pendingRequest.onProgress;
  8726. if (onProgress) {
  8727. onProgress(evt);
  8728. }
  8729. },
  8730. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8731. var pendingRequest = this.pendingRequests[xhrId];
  8732. if (!pendingRequest) {
  8733. // Maybe abortRequest was called...
  8734. return;
  8735. }
  8736. var xhr = pendingRequest.xhr;
  8737. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8738. pendingRequest.onHeadersReceived();
  8739. delete pendingRequest.onHeadersReceived;
  8740. }
  8741. if (xhr.readyState !== 4) {
  8742. return;
  8743. }
  8744. if (!(xhrId in this.pendingRequests)) {
  8745. // The XHR request might have been aborted in onHeadersReceived()
  8746. // callback, in which case we should abort request
  8747. return;
  8748. }
  8749. delete this.pendingRequests[xhrId];
  8750. // success status == 0 can be on ftp, file and other protocols
  8751. if (xhr.status === 0 && this.isHttp) {
  8752. if (pendingRequest.onError) {
  8753. pendingRequest.onError(xhr.status);
  8754. }
  8755. return;
  8756. }
  8757. var xhrStatus = xhr.status || OK_RESPONSE;
  8758. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8759. // "A server MAY ignore the Range header". This means it's possible to
  8760. // get a 200 rather than a 206 response from a range request.
  8761. var ok_response_on_range_request =
  8762. xhrStatus === OK_RESPONSE &&
  8763. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8764. if (!ok_response_on_range_request &&
  8765. xhrStatus !== pendingRequest.expectedStatus) {
  8766. if (pendingRequest.onError) {
  8767. pendingRequest.onError(xhr.status);
  8768. }
  8769. return;
  8770. }
  8771. this.loadedRequests[xhrId] = true;
  8772. var chunk = getArrayBuffer(xhr);
  8773. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8774. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8775. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8776. var begin = parseInt(matches[1], 10);
  8777. pendingRequest.onDone({
  8778. begin: begin,
  8779. chunk: chunk
  8780. });
  8781. } else if (pendingRequest.onProgressiveData) {
  8782. pendingRequest.onDone(null);
  8783. } else if (chunk) {
  8784. pendingRequest.onDone({
  8785. begin: 0,
  8786. chunk: chunk
  8787. });
  8788. } else if (pendingRequest.onError) {
  8789. pendingRequest.onError(xhr.status);
  8790. }
  8791. },
  8792. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8793. for (var xhrId in this.pendingRequests) {
  8794. return true;
  8795. }
  8796. return false;
  8797. },
  8798. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8799. return this.pendingRequests[xhrId].xhr;
  8800. },
  8801. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8802. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8803. },
  8804. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8805. return xhrId in this.pendingRequests;
  8806. },
  8807. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8808. return xhrId in this.loadedRequests;
  8809. },
  8810. abortAllRequests: function NetworkManager_abortAllRequests() {
  8811. for (var xhrId in this.pendingRequests) {
  8812. this.abortRequest(xhrId | 0);
  8813. }
  8814. },
  8815. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8816. var xhr = this.pendingRequests[xhrId].xhr;
  8817. delete this.pendingRequests[xhrId];
  8818. xhr.abort();
  8819. }
  8820. };
  8821. return NetworkManager;
  8822. })();
  8823. (function (root, factory) {
  8824. {
  8825. factory((root.pdfjsCoreNetwork = {}));
  8826. }
  8827. }(this, function (exports) {
  8828. exports.NetworkManager = NetworkManager;
  8829. }));
  8830. (function (root, factory) {
  8831. {
  8832. factory((root.pdfjsSharedGlobal = {}));
  8833. }
  8834. }(this, function (exports) {
  8835. var globalScope = (typeof window !== 'undefined') ? window :
  8836. (typeof global !== 'undefined') ? global :
  8837. (typeof self !== 'undefined') ? self : this;
  8838. var isWorker = (typeof window === 'undefined');
  8839. // The global PDFJS object exposes the API
  8840. // In production, it will be declared outside a global wrapper
  8841. // In development, it will be declared here
  8842. if (!globalScope.PDFJS) {
  8843. globalScope.PDFJS = {};
  8844. }
  8845. if (typeof pdfjsVersion !== 'undefined') {
  8846. globalScope.PDFJS.version = pdfjsVersion;
  8847. }
  8848. if (typeof pdfjsVersion !== 'undefined') {
  8849. globalScope.PDFJS.build = pdfjsBuild;
  8850. }
  8851. globalScope.PDFJS.pdfBug = false;
  8852. exports.globalScope = globalScope;
  8853. exports.isWorker = isWorker;
  8854. exports.PDFJS = globalScope.PDFJS;
  8855. }));
  8856. (function (root, factory) {
  8857. {
  8858. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  8859. }
  8860. }(this, function (exports, sharedGlobal) {
  8861. var PDFJS = sharedGlobal.PDFJS;
  8862. var bidi = PDFJS.bidi = (function bidiClosure() {
  8863. // Character types for symbols from 0000 to 00FF.
  8864. var baseTypes = [
  8865. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  8866. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8867. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  8868. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  8869. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  8870. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8871. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  8872. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8873. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8874. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  8875. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8876. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8877. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  8878. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  8879. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8880. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8881. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8882. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8883. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  8884. ];
  8885. // Character types for symbols from 0600 to 06FF
  8886. var arabicTypes = [
  8887. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8888. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  8889. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8890. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8891. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8892. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8893. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8894. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8895. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  8896. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8897. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8898. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8899. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8900. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8901. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8902. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8903. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8904. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8905. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8906. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  8907. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8908. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  8909. ];
  8910. function isOdd(i) {
  8911. return (i & 1) !== 0;
  8912. }
  8913. function isEven(i) {
  8914. return (i & 1) === 0;
  8915. }
  8916. function findUnequal(arr, start, value) {
  8917. for (var j = start, jj = arr.length; j < jj; ++j) {
  8918. if (arr[j] !== value) {
  8919. return j;
  8920. }
  8921. }
  8922. return j;
  8923. }
  8924. function setValues(arr, start, end, value) {
  8925. for (var j = start; j < end; ++j) {
  8926. arr[j] = value;
  8927. }
  8928. }
  8929. function reverseValues(arr, start, end) {
  8930. for (var i = start, j = end - 1; i < j; ++i, --j) {
  8931. var temp = arr[i];
  8932. arr[i] = arr[j];
  8933. arr[j] = temp;
  8934. }
  8935. }
  8936. function createBidiText(str, isLTR, vertical) {
  8937. return {
  8938. str: str,
  8939. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  8940. };
  8941. }
  8942. // These are used in bidi(), which is called frequently. We re-use them on
  8943. // each call to avoid unnecessary allocations.
  8944. var chars = [];
  8945. var types = [];
  8946. function bidi(str, startLevel, vertical) {
  8947. var isLTR = true;
  8948. var strLength = str.length;
  8949. if (strLength === 0 || vertical) {
  8950. return createBidiText(str, isLTR, vertical);
  8951. }
  8952. // Get types and fill arrays
  8953. chars.length = strLength;
  8954. types.length = strLength;
  8955. var numBidi = 0;
  8956. var i, ii;
  8957. for (i = 0; i < strLength; ++i) {
  8958. chars[i] = str.charAt(i);
  8959. var charCode = str.charCodeAt(i);
  8960. var charType = 'L';
  8961. if (charCode <= 0x00ff) {
  8962. charType = baseTypes[charCode];
  8963. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  8964. charType = 'R';
  8965. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  8966. charType = arabicTypes[charCode & 0xff];
  8967. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  8968. charType = 'AL';
  8969. }
  8970. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  8971. numBidi++;
  8972. }
  8973. types[i] = charType;
  8974. }
  8975. // Detect the bidi method
  8976. // - If there are no rtl characters then no bidi needed
  8977. // - If less than 30% chars are rtl then string is primarily ltr
  8978. // - If more than 30% chars are rtl then string is primarily rtl
  8979. if (numBidi === 0) {
  8980. isLTR = true;
  8981. return createBidiText(str, isLTR);
  8982. }
  8983. if (startLevel === -1) {
  8984. if ((strLength / numBidi) < 0.3) {
  8985. isLTR = true;
  8986. startLevel = 0;
  8987. } else {
  8988. isLTR = false;
  8989. startLevel = 1;
  8990. }
  8991. }
  8992. var levels = [];
  8993. for (i = 0; i < strLength; ++i) {
  8994. levels[i] = startLevel;
  8995. }
  8996. /*
  8997. X1-X10: skip most of this, since we are NOT doing the embeddings.
  8998. */
  8999. var e = (isOdd(startLevel) ? 'R' : 'L');
  9000. var sor = e;
  9001. var eor = sor;
  9002. /*
  9003. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  9004. type of the NSM to the type of the previous character. If the NSM is at the
  9005. start of the level run, it will get the type of sor.
  9006. */
  9007. var lastType = sor;
  9008. for (i = 0; i < strLength; ++i) {
  9009. if (types[i] === 'NSM') {
  9010. types[i] = lastType;
  9011. } else {
  9012. lastType = types[i];
  9013. }
  9014. }
  9015. /*
  9016. W2. Search backwards from each instance of a European number until the
  9017. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  9018. the type of the European number to Arabic number.
  9019. */
  9020. lastType = sor;
  9021. var t;
  9022. for (i = 0; i < strLength; ++i) {
  9023. t = types[i];
  9024. if (t === 'EN') {
  9025. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  9026. } else if (t === 'R' || t === 'L' || t === 'AL') {
  9027. lastType = t;
  9028. }
  9029. }
  9030. /*
  9031. W3. Change all ALs to R.
  9032. */
  9033. for (i = 0; i < strLength; ++i) {
  9034. t = types[i];
  9035. if (t === 'AL') {
  9036. types[i] = 'R';
  9037. }
  9038. }
  9039. /*
  9040. W4. A single European separator between two European numbers changes to a
  9041. European number. A single common separator between two numbers of the same
  9042. type changes to that type:
  9043. */
  9044. for (i = 1; i < strLength - 1; ++i) {
  9045. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  9046. types[i] = 'EN';
  9047. }
  9048. if (types[i] === 'CS' &&
  9049. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  9050. types[i + 1] === types[i - 1]) {
  9051. types[i] = types[i - 1];
  9052. }
  9053. }
  9054. /*
  9055. W5. A sequence of European terminators adjacent to European numbers changes
  9056. to all European numbers:
  9057. */
  9058. for (i = 0; i < strLength; ++i) {
  9059. if (types[i] === 'EN') {
  9060. // do before
  9061. var j;
  9062. for (j = i - 1; j >= 0; --j) {
  9063. if (types[j] !== 'ET') {
  9064. break;
  9065. }
  9066. types[j] = 'EN';
  9067. }
  9068. // do after
  9069. for (j = i + 1; j < strLength; --j) {
  9070. if (types[j] !== 'ET') {
  9071. break;
  9072. }
  9073. types[j] = 'EN';
  9074. }
  9075. }
  9076. }
  9077. /*
  9078. W6. Otherwise, separators and terminators change to Other Neutral:
  9079. */
  9080. for (i = 0; i < strLength; ++i) {
  9081. t = types[i];
  9082. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  9083. types[i] = 'ON';
  9084. }
  9085. }
  9086. /*
  9087. W7. Search backwards from each instance of a European number until the
  9088. first strong type (R, L, or sor) is found. If an L is found, then change
  9089. the type of the European number to L.
  9090. */
  9091. lastType = sor;
  9092. for (i = 0; i < strLength; ++i) {
  9093. t = types[i];
  9094. if (t === 'EN') {
  9095. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  9096. } else if (t === 'R' || t === 'L') {
  9097. lastType = t;
  9098. }
  9099. }
  9100. /*
  9101. N1. A sequence of neutrals takes the direction of the surrounding strong
  9102. text if the text on both sides has the same direction. European and Arabic
  9103. numbers are treated as though they were R. Start-of-level-run (sor) and
  9104. end-of-level-run (eor) are used at level run boundaries.
  9105. */
  9106. for (i = 0; i < strLength; ++i) {
  9107. if (types[i] === 'ON') {
  9108. var end = findUnequal(types, i + 1, 'ON');
  9109. var before = sor;
  9110. if (i > 0) {
  9111. before = types[i - 1];
  9112. }
  9113. var after = eor;
  9114. if (end + 1 < strLength) {
  9115. after = types[end + 1];
  9116. }
  9117. if (before !== 'L') {
  9118. before = 'R';
  9119. }
  9120. if (after !== 'L') {
  9121. after = 'R';
  9122. }
  9123. if (before === after) {
  9124. setValues(types, i, end, before);
  9125. }
  9126. i = end - 1; // reset to end (-1 so next iteration is ok)
  9127. }
  9128. }
  9129. /*
  9130. N2. Any remaining neutrals take the embedding direction.
  9131. */
  9132. for (i = 0; i < strLength; ++i) {
  9133. if (types[i] === 'ON') {
  9134. types[i] = e;
  9135. }
  9136. }
  9137. /*
  9138. I1. For all characters with an even (left-to-right) embedding direction,
  9139. those of type R go up one level and those of type AN or EN go up two
  9140. levels.
  9141. I2. For all characters with an odd (right-to-left) embedding direction,
  9142. those of type L, EN or AN go up one level.
  9143. */
  9144. for (i = 0; i < strLength; ++i) {
  9145. t = types[i];
  9146. if (isEven(levels[i])) {
  9147. if (t === 'R') {
  9148. levels[i] += 1;
  9149. } else if (t === 'AN' || t === 'EN') {
  9150. levels[i] += 2;
  9151. }
  9152. } else { // isOdd
  9153. if (t === 'L' || t === 'AN' || t === 'EN') {
  9154. levels[i] += 1;
  9155. }
  9156. }
  9157. }
  9158. /*
  9159. L1. On each line, reset the embedding level of the following characters to
  9160. the paragraph embedding level:
  9161. segment separators,
  9162. paragraph separators,
  9163. any sequence of whitespace characters preceding a segment separator or
  9164. paragraph separator, and any sequence of white space characters at the end
  9165. of the line.
  9166. */
  9167. // don't bother as text is only single line
  9168. /*
  9169. L2. From the highest level found in the text to the lowest odd level on
  9170. each line, reverse any contiguous sequence of characters that are at that
  9171. level or higher.
  9172. */
  9173. // find highest level & lowest odd level
  9174. var highestLevel = -1;
  9175. var lowestOddLevel = 99;
  9176. var level;
  9177. for (i = 0, ii = levels.length; i < ii; ++i) {
  9178. level = levels[i];
  9179. if (highestLevel < level) {
  9180. highestLevel = level;
  9181. }
  9182. if (lowestOddLevel > level && isOdd(level)) {
  9183. lowestOddLevel = level;
  9184. }
  9185. }
  9186. // now reverse between those limits
  9187. for (level = highestLevel; level >= lowestOddLevel; --level) {
  9188. // find segments to reverse
  9189. var start = -1;
  9190. for (i = 0, ii = levels.length; i < ii; ++i) {
  9191. if (levels[i] < level) {
  9192. if (start >= 0) {
  9193. reverseValues(chars, start, i);
  9194. start = -1;
  9195. }
  9196. } else if (start < 0) {
  9197. start = i;
  9198. }
  9199. }
  9200. if (start >= 0) {
  9201. reverseValues(chars, start, levels.length);
  9202. }
  9203. }
  9204. /*
  9205. L3. Combining marks applied to a right-to-left base character will at this
  9206. point precede their base character. If the rendering engine expects them to
  9207. follow the base characters in the final display process, then the ordering
  9208. of the marks and the base character must be reversed.
  9209. */
  9210. // don't bother for now
  9211. /*
  9212. L4. A character that possesses the mirrored property as specified by
  9213. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  9214. directionality of that character is R.
  9215. */
  9216. // don't mirror as characters are already mirrored in the pdf
  9217. // Finally, return string
  9218. for (i = 0, ii = chars.length; i < ii; ++i) {
  9219. var ch = chars[i];
  9220. if (ch === '<' || ch === '>') {
  9221. chars[i] = '';
  9222. }
  9223. }
  9224. return createBidiText(chars.join(''), isLTR);
  9225. }
  9226. return bidi;
  9227. })();
  9228. exports.bidi = bidi;
  9229. }));
  9230. (function (root, factory) {
  9231. {
  9232. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  9233. }
  9234. }(this, function (exports, sharedGlobal) {
  9235. var PDFJS = sharedGlobal.PDFJS;
  9236. /**
  9237. * Optimised CSS custom property getter/setter.
  9238. * @class
  9239. */
  9240. var CustomStyle = (function CustomStyleClosure() {
  9241. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  9242. // animate-css-transforms-firefox-webkit.html
  9243. // in some versions of IE9 it is critical that ms appear in this list
  9244. // before Moz
  9245. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  9246. var _cache = {};
  9247. function CustomStyle() {}
  9248. CustomStyle.getProp = function get(propName, element) {
  9249. // check cache only when no element is given
  9250. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  9251. return _cache[propName];
  9252. }
  9253. element = element || document.documentElement;
  9254. var style = element.style, prefixed, uPropName;
  9255. // test standard property first
  9256. if (typeof style[propName] === 'string') {
  9257. return (_cache[propName] = propName);
  9258. }
  9259. // capitalize
  9260. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  9261. // test vendor specific properties
  9262. for (var i = 0, l = prefixes.length; i < l; i++) {
  9263. prefixed = prefixes[i] + uPropName;
  9264. if (typeof style[prefixed] === 'string') {
  9265. return (_cache[propName] = prefixed);
  9266. }
  9267. }
  9268. //if all fails then set to undefined
  9269. return (_cache[propName] = 'undefined');
  9270. };
  9271. CustomStyle.setProp = function set(propName, element, str) {
  9272. var prop = this.getProp(propName);
  9273. if (prop !== 'undefined') {
  9274. element.style[prop] = str;
  9275. }
  9276. };
  9277. return CustomStyle;
  9278. })();
  9279. PDFJS.CustomStyle = CustomStyle;
  9280. exports.CustomStyle = CustomStyle;
  9281. }));
  9282. (function (root, factory) {
  9283. {
  9284. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  9285. }
  9286. }(this, function (exports, sharedGlobal) {
  9287. var PDFJS = sharedGlobal.PDFJS;
  9288. var globalScope = sharedGlobal.globalScope;
  9289. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  9290. var TextRenderingMode = {
  9291. FILL: 0,
  9292. STROKE: 1,
  9293. FILL_STROKE: 2,
  9294. INVISIBLE: 3,
  9295. FILL_ADD_TO_PATH: 4,
  9296. STROKE_ADD_TO_PATH: 5,
  9297. FILL_STROKE_ADD_TO_PATH: 6,
  9298. ADD_TO_PATH: 7,
  9299. FILL_STROKE_MASK: 3,
  9300. ADD_TO_PATH_FLAG: 4
  9301. };
  9302. var ImageKind = {
  9303. GRAYSCALE_1BPP: 1,
  9304. RGB_24BPP: 2,
  9305. RGBA_32BPP: 3
  9306. };
  9307. var AnnotationType = {
  9308. TEXT: 1,
  9309. LINK: 2,
  9310. FREETEXT: 3,
  9311. LINE: 4,
  9312. SQUARE: 5,
  9313. CIRCLE: 6,
  9314. POLYGON: 7,
  9315. POLYLINE: 8,
  9316. HIGHLIGHT: 9,
  9317. UNDERLINE: 10,
  9318. SQUIGGLY: 11,
  9319. STRIKEOUT: 12,
  9320. STAMP: 13,
  9321. CARET: 14,
  9322. INK: 15,
  9323. POPUP: 16,
  9324. FILEATTACHMENT: 17,
  9325. SOUND: 18,
  9326. MOVIE: 19,
  9327. WIDGET: 20,
  9328. SCREEN: 21,
  9329. PRINTERMARK: 22,
  9330. TRAPNET: 23,
  9331. WATERMARK: 24,
  9332. THREED: 25,
  9333. REDACT: 26
  9334. };
  9335. var AnnotationFlag = {
  9336. INVISIBLE: 0x01,
  9337. HIDDEN: 0x02,
  9338. PRINT: 0x04,
  9339. NOZOOM: 0x08,
  9340. NOROTATE: 0x10,
  9341. NOVIEW: 0x20,
  9342. READONLY: 0x40,
  9343. LOCKED: 0x80,
  9344. TOGGLENOVIEW: 0x100,
  9345. LOCKEDCONTENTS: 0x200
  9346. };
  9347. var AnnotationBorderStyleType = {
  9348. SOLID: 1,
  9349. DASHED: 2,
  9350. BEVELED: 3,
  9351. INSET: 4,
  9352. UNDERLINE: 5
  9353. };
  9354. var StreamType = {
  9355. UNKNOWN: 0,
  9356. FLATE: 1,
  9357. LZW: 2,
  9358. DCT: 3,
  9359. JPX: 4,
  9360. JBIG: 5,
  9361. A85: 6,
  9362. AHX: 7,
  9363. CCF: 8,
  9364. RL: 9
  9365. };
  9366. var FontType = {
  9367. UNKNOWN: 0,
  9368. TYPE1: 1,
  9369. TYPE1C: 2,
  9370. CIDFONTTYPE0: 3,
  9371. CIDFONTTYPE0C: 4,
  9372. TRUETYPE: 5,
  9373. CIDFONTTYPE2: 6,
  9374. TYPE3: 7,
  9375. OPENTYPE: 8,
  9376. TYPE0: 9,
  9377. MMTYPE1: 10
  9378. };
  9379. PDFJS.VERBOSITY_LEVELS = {
  9380. errors: 0,
  9381. warnings: 1,
  9382. infos: 5
  9383. };
  9384. // All the possible operations for an operator list.
  9385. var OPS = PDFJS.OPS = {
  9386. // Intentionally start from 1 so it is easy to spot bad operators that will be
  9387. // 0's.
  9388. dependency: 1,
  9389. setLineWidth: 2,
  9390. setLineCap: 3,
  9391. setLineJoin: 4,
  9392. setMiterLimit: 5,
  9393. setDash: 6,
  9394. setRenderingIntent: 7,
  9395. setFlatness: 8,
  9396. setGState: 9,
  9397. save: 10,
  9398. restore: 11,
  9399. transform: 12,
  9400. moveTo: 13,
  9401. lineTo: 14,
  9402. curveTo: 15,
  9403. curveTo2: 16,
  9404. curveTo3: 17,
  9405. closePath: 18,
  9406. rectangle: 19,
  9407. stroke: 20,
  9408. closeStroke: 21,
  9409. fill: 22,
  9410. eoFill: 23,
  9411. fillStroke: 24,
  9412. eoFillStroke: 25,
  9413. closeFillStroke: 26,
  9414. closeEOFillStroke: 27,
  9415. endPath: 28,
  9416. clip: 29,
  9417. eoClip: 30,
  9418. beginText: 31,
  9419. endText: 32,
  9420. setCharSpacing: 33,
  9421. setWordSpacing: 34,
  9422. setHScale: 35,
  9423. setLeading: 36,
  9424. setFont: 37,
  9425. setTextRenderingMode: 38,
  9426. setTextRise: 39,
  9427. moveText: 40,
  9428. setLeadingMoveText: 41,
  9429. setTextMatrix: 42,
  9430. nextLine: 43,
  9431. showText: 44,
  9432. showSpacedText: 45,
  9433. nextLineShowText: 46,
  9434. nextLineSetSpacingShowText: 47,
  9435. setCharWidth: 48,
  9436. setCharWidthAndBounds: 49,
  9437. setStrokeColorSpace: 50,
  9438. setFillColorSpace: 51,
  9439. setStrokeColor: 52,
  9440. setStrokeColorN: 53,
  9441. setFillColor: 54,
  9442. setFillColorN: 55,
  9443. setStrokeGray: 56,
  9444. setFillGray: 57,
  9445. setStrokeRGBColor: 58,
  9446. setFillRGBColor: 59,
  9447. setStrokeCMYKColor: 60,
  9448. setFillCMYKColor: 61,
  9449. shadingFill: 62,
  9450. beginInlineImage: 63,
  9451. beginImageData: 64,
  9452. endInlineImage: 65,
  9453. paintXObject: 66,
  9454. markPoint: 67,
  9455. markPointProps: 68,
  9456. beginMarkedContent: 69,
  9457. beginMarkedContentProps: 70,
  9458. endMarkedContent: 71,
  9459. beginCompat: 72,
  9460. endCompat: 73,
  9461. paintFormXObjectBegin: 74,
  9462. paintFormXObjectEnd: 75,
  9463. beginGroup: 76,
  9464. endGroup: 77,
  9465. beginAnnotations: 78,
  9466. endAnnotations: 79,
  9467. beginAnnotation: 80,
  9468. endAnnotation: 81,
  9469. paintJpegXObject: 82,
  9470. paintImageMaskXObject: 83,
  9471. paintImageMaskXObjectGroup: 84,
  9472. paintImageXObject: 85,
  9473. paintInlineImageXObject: 86,
  9474. paintInlineImageXObjectGroup: 87,
  9475. paintImageXObjectRepeat: 88,
  9476. paintImageMaskXObjectRepeat: 89,
  9477. paintSolidColorImageMask: 90,
  9478. constructPath: 91
  9479. };
  9480. // A notice for devs. These are good for things that are helpful to devs, such
  9481. // as warning that Workers were disabled, which is important to devs but not
  9482. // end users.
  9483. function info(msg) {
  9484. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  9485. console.log('Info: ' + msg);
  9486. }
  9487. }
  9488. // Non-fatal warnings.
  9489. function warn(msg) {
  9490. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  9491. console.log('Warning: ' + msg);
  9492. }
  9493. }
  9494. // Deprecated API function -- treated as warnings.
  9495. function deprecated(details) {
  9496. warn('Deprecated API usage: ' + details);
  9497. }
  9498. // Fatal errors that should trigger the fallback UI and halt execution by
  9499. // throwing an exception.
  9500. function error(msg) {
  9501. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  9502. console.log('Error: ' + msg);
  9503. console.log(backtrace());
  9504. }
  9505. throw new Error(msg);
  9506. }
  9507. function backtrace() {
  9508. try {
  9509. throw new Error();
  9510. } catch (e) {
  9511. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  9512. }
  9513. }
  9514. function assert(cond, msg) {
  9515. if (!cond) {
  9516. error(msg);
  9517. }
  9518. }
  9519. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  9520. unknown: 'unknown',
  9521. forms: 'forms',
  9522. javaScript: 'javaScript',
  9523. smask: 'smask',
  9524. shadingPattern: 'shadingPattern',
  9525. font: 'font'
  9526. };
  9527. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  9528. // absolute URL, it will be returned as is.
  9529. function combineUrl(baseUrl, url) {
  9530. if (!url) {
  9531. return baseUrl;
  9532. }
  9533. return new URL(url, baseUrl).href;
  9534. }
  9535. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  9536. function isValidUrl(url, allowRelative) {
  9537. if (!url) {
  9538. return false;
  9539. }
  9540. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  9541. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  9542. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  9543. if (!protocol) {
  9544. return allowRelative;
  9545. }
  9546. protocol = protocol[0].toLowerCase();
  9547. switch (protocol) {
  9548. case 'http':
  9549. case 'https':
  9550. case 'ftp':
  9551. case 'mailto':
  9552. case 'tel':
  9553. return true;
  9554. default:
  9555. return false;
  9556. }
  9557. }
  9558. PDFJS.isValidUrl = isValidUrl;
  9559. function shadow(obj, prop, value) {
  9560. Object.defineProperty(obj, prop, { value: value,
  9561. enumerable: true,
  9562. configurable: true,
  9563. writable: false });
  9564. return value;
  9565. }
  9566. PDFJS.shadow = shadow;
  9567. var LinkTarget = PDFJS.LinkTarget = {
  9568. NONE: 0, // Default value.
  9569. SELF: 1,
  9570. BLANK: 2,
  9571. PARENT: 3,
  9572. TOP: 4,
  9573. };
  9574. var LinkTargetStringMap = [
  9575. '',
  9576. '_self',
  9577. '_blank',
  9578. '_parent',
  9579. '_top'
  9580. ];
  9581. function isExternalLinkTargetSet() {
  9582. if (PDFJS.openExternalLinksInNewWindow) {
  9583. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  9584. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  9585. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  9586. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  9587. }
  9588. // Reset the deprecated parameter, to suppress further warnings.
  9589. PDFJS.openExternalLinksInNewWindow = false;
  9590. }
  9591. switch (PDFJS.externalLinkTarget) {
  9592. case LinkTarget.NONE:
  9593. return false;
  9594. case LinkTarget.SELF:
  9595. case LinkTarget.BLANK:
  9596. case LinkTarget.PARENT:
  9597. case LinkTarget.TOP:
  9598. return true;
  9599. }
  9600. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  9601. // Reset the external link target, to suppress further warnings.
  9602. PDFJS.externalLinkTarget = LinkTarget.NONE;
  9603. return false;
  9604. }
  9605. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  9606. var PasswordResponses = PDFJS.PasswordResponses = {
  9607. NEED_PASSWORD: 1,
  9608. INCORRECT_PASSWORD: 2
  9609. };
  9610. var PasswordException = (function PasswordExceptionClosure() {
  9611. function PasswordException(msg, code) {
  9612. this.name = 'PasswordException';
  9613. this.message = msg;
  9614. this.code = code;
  9615. }
  9616. PasswordException.prototype = new Error();
  9617. PasswordException.constructor = PasswordException;
  9618. return PasswordException;
  9619. })();
  9620. PDFJS.PasswordException = PasswordException;
  9621. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  9622. function UnknownErrorException(msg, details) {
  9623. this.name = 'UnknownErrorException';
  9624. this.message = msg;
  9625. this.details = details;
  9626. }
  9627. UnknownErrorException.prototype = new Error();
  9628. UnknownErrorException.constructor = UnknownErrorException;
  9629. return UnknownErrorException;
  9630. })();
  9631. PDFJS.UnknownErrorException = UnknownErrorException;
  9632. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  9633. function InvalidPDFException(msg) {
  9634. this.name = 'InvalidPDFException';
  9635. this.message = msg;
  9636. }
  9637. InvalidPDFException.prototype = new Error();
  9638. InvalidPDFException.constructor = InvalidPDFException;
  9639. return InvalidPDFException;
  9640. })();
  9641. PDFJS.InvalidPDFException = InvalidPDFException;
  9642. var MissingPDFException = (function MissingPDFExceptionClosure() {
  9643. function MissingPDFException(msg) {
  9644. this.name = 'MissingPDFException';
  9645. this.message = msg;
  9646. }
  9647. MissingPDFException.prototype = new Error();
  9648. MissingPDFException.constructor = MissingPDFException;
  9649. return MissingPDFException;
  9650. })();
  9651. PDFJS.MissingPDFException = MissingPDFException;
  9652. var UnexpectedResponseException =
  9653. (function UnexpectedResponseExceptionClosure() {
  9654. function UnexpectedResponseException(msg, status) {
  9655. this.name = 'UnexpectedResponseException';
  9656. this.message = msg;
  9657. this.status = status;
  9658. }
  9659. UnexpectedResponseException.prototype = new Error();
  9660. UnexpectedResponseException.constructor = UnexpectedResponseException;
  9661. return UnexpectedResponseException;
  9662. })();
  9663. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  9664. var NotImplementedException = (function NotImplementedExceptionClosure() {
  9665. function NotImplementedException(msg) {
  9666. this.message = msg;
  9667. }
  9668. NotImplementedException.prototype = new Error();
  9669. NotImplementedException.prototype.name = 'NotImplementedException';
  9670. NotImplementedException.constructor = NotImplementedException;
  9671. return NotImplementedException;
  9672. })();
  9673. var MissingDataException = (function MissingDataExceptionClosure() {
  9674. function MissingDataException(begin, end) {
  9675. this.begin = begin;
  9676. this.end = end;
  9677. this.message = 'Missing data [' + begin + ', ' + end + ')';
  9678. }
  9679. MissingDataException.prototype = new Error();
  9680. MissingDataException.prototype.name = 'MissingDataException';
  9681. MissingDataException.constructor = MissingDataException;
  9682. return MissingDataException;
  9683. })();
  9684. var XRefParseException = (function XRefParseExceptionClosure() {
  9685. function XRefParseException(msg) {
  9686. this.message = msg;
  9687. }
  9688. XRefParseException.prototype = new Error();
  9689. XRefParseException.prototype.name = 'XRefParseException';
  9690. XRefParseException.constructor = XRefParseException;
  9691. return XRefParseException;
  9692. })();
  9693. var NullCharactersRegExp = /\x00/g;
  9694. function removeNullCharacters(str) {
  9695. if (typeof str !== 'string') {
  9696. warn('The argument for removeNullCharacters must be a string.');
  9697. return str;
  9698. }
  9699. return str.replace(NullCharactersRegExp, '');
  9700. }
  9701. PDFJS.removeNullCharacters = removeNullCharacters;
  9702. function bytesToString(bytes) {
  9703. assert(bytes !== null && typeof bytes === 'object' &&
  9704. bytes.length !== undefined, 'Invalid argument for bytesToString');
  9705. var length = bytes.length;
  9706. var MAX_ARGUMENT_COUNT = 8192;
  9707. if (length < MAX_ARGUMENT_COUNT) {
  9708. return String.fromCharCode.apply(null, bytes);
  9709. }
  9710. var strBuf = [];
  9711. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  9712. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  9713. var chunk = bytes.subarray(i, chunkEnd);
  9714. strBuf.push(String.fromCharCode.apply(null, chunk));
  9715. }
  9716. return strBuf.join('');
  9717. }
  9718. function stringToBytes(str) {
  9719. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  9720. var length = str.length;
  9721. var bytes = new Uint8Array(length);
  9722. for (var i = 0; i < length; ++i) {
  9723. bytes[i] = str.charCodeAt(i) & 0xFF;
  9724. }
  9725. return bytes;
  9726. }
  9727. function string32(value) {
  9728. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  9729. (value >> 8) & 0xff, value & 0xff);
  9730. }
  9731. function log2(x) {
  9732. var n = 1, i = 0;
  9733. while (x > n) {
  9734. n <<= 1;
  9735. i++;
  9736. }
  9737. return i;
  9738. }
  9739. function readInt8(data, start) {
  9740. return (data[start] << 24) >> 24;
  9741. }
  9742. function readUint16(data, offset) {
  9743. return (data[offset] << 8) | data[offset + 1];
  9744. }
  9745. function readUint32(data, offset) {
  9746. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  9747. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  9748. }
  9749. // Lazy test the endianness of the platform
  9750. // NOTE: This will be 'true' for simulated TypedArrays
  9751. function isLittleEndian() {
  9752. var buffer8 = new Uint8Array(2);
  9753. buffer8[0] = 1;
  9754. var buffer16 = new Uint16Array(buffer8.buffer);
  9755. return (buffer16[0] === 1);
  9756. }
  9757. Object.defineProperty(PDFJS, 'isLittleEndian', {
  9758. configurable: true,
  9759. get: function PDFJS_isLittleEndian() {
  9760. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  9761. }
  9762. });
  9763. // Lazy test if the userAgent support CanvasTypedArrays
  9764. function hasCanvasTypedArrays() {
  9765. var canvas = document.createElement('canvas');
  9766. canvas.width = canvas.height = 1;
  9767. var ctx = canvas.getContext('2d');
  9768. var imageData = ctx.createImageData(1, 1);
  9769. return (typeof imageData.data.buffer !== 'undefined');
  9770. }
  9771. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  9772. configurable: true,
  9773. get: function PDFJS_hasCanvasTypedArrays() {
  9774. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  9775. }
  9776. });
  9777. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  9778. function Uint32ArrayView(buffer, length) {
  9779. this.buffer = buffer;
  9780. this.byteLength = buffer.length;
  9781. this.length = length === undefined ? (this.byteLength >> 2) : length;
  9782. ensureUint32ArrayViewProps(this.length);
  9783. }
  9784. Uint32ArrayView.prototype = Object.create(null);
  9785. var uint32ArrayViewSetters = 0;
  9786. function createUint32ArrayProp(index) {
  9787. return {
  9788. get: function () {
  9789. var buffer = this.buffer, offset = index << 2;
  9790. return (buffer[offset] | (buffer[offset + 1] << 8) |
  9791. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  9792. },
  9793. set: function (value) {
  9794. var buffer = this.buffer, offset = index << 2;
  9795. buffer[offset] = value & 255;
  9796. buffer[offset + 1] = (value >> 8) & 255;
  9797. buffer[offset + 2] = (value >> 16) & 255;
  9798. buffer[offset + 3] = (value >>> 24) & 255;
  9799. }
  9800. };
  9801. }
  9802. function ensureUint32ArrayViewProps(length) {
  9803. while (uint32ArrayViewSetters < length) {
  9804. Object.defineProperty(Uint32ArrayView.prototype,
  9805. uint32ArrayViewSetters,
  9806. createUint32ArrayProp(uint32ArrayViewSetters));
  9807. uint32ArrayViewSetters++;
  9808. }
  9809. }
  9810. return Uint32ArrayView;
  9811. })();
  9812. exports.Uint32ArrayView = Uint32ArrayView;
  9813. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  9814. var Util = PDFJS.Util = (function UtilClosure() {
  9815. function Util() {}
  9816. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  9817. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  9818. // creating many intermediate strings.
  9819. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  9820. rgbBuf[1] = r;
  9821. rgbBuf[3] = g;
  9822. rgbBuf[5] = b;
  9823. return rgbBuf.join('');
  9824. };
  9825. // Concatenates two transformation matrices together and returns the result.
  9826. Util.transform = function Util_transform(m1, m2) {
  9827. return [
  9828. m1[0] * m2[0] + m1[2] * m2[1],
  9829. m1[1] * m2[0] + m1[3] * m2[1],
  9830. m1[0] * m2[2] + m1[2] * m2[3],
  9831. m1[1] * m2[2] + m1[3] * m2[3],
  9832. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  9833. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  9834. ];
  9835. };
  9836. // For 2d affine transforms
  9837. Util.applyTransform = function Util_applyTransform(p, m) {
  9838. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  9839. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  9840. return [xt, yt];
  9841. };
  9842. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  9843. var d = m[0] * m[3] - m[1] * m[2];
  9844. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  9845. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  9846. return [xt, yt];
  9847. };
  9848. // Applies the transform to the rectangle and finds the minimum axially
  9849. // aligned bounding box.
  9850. Util.getAxialAlignedBoundingBox =
  9851. function Util_getAxialAlignedBoundingBox(r, m) {
  9852. var p1 = Util.applyTransform(r, m);
  9853. var p2 = Util.applyTransform(r.slice(2, 4), m);
  9854. var p3 = Util.applyTransform([r[0], r[3]], m);
  9855. var p4 = Util.applyTransform([r[2], r[1]], m);
  9856. return [
  9857. Math.min(p1[0], p2[0], p3[0], p4[0]),
  9858. Math.min(p1[1], p2[1], p3[1], p4[1]),
  9859. Math.max(p1[0], p2[0], p3[0], p4[0]),
  9860. Math.max(p1[1], p2[1], p3[1], p4[1])
  9861. ];
  9862. };
  9863. Util.inverseTransform = function Util_inverseTransform(m) {
  9864. var d = m[0] * m[3] - m[1] * m[2];
  9865. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  9866. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  9867. };
  9868. // Apply a generic 3d matrix M on a 3-vector v:
  9869. // | a b c | | X |
  9870. // | d e f | x | Y |
  9871. // | g h i | | Z |
  9872. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  9873. // with v as [X,Y,Z]
  9874. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  9875. return [
  9876. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  9877. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  9878. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  9879. ];
  9880. };
  9881. // This calculation uses Singular Value Decomposition.
  9882. // The SVD can be represented with formula A = USV. We are interested in the
  9883. // matrix S here because it represents the scale values.
  9884. Util.singularValueDecompose2dScale =
  9885. function Util_singularValueDecompose2dScale(m) {
  9886. var transpose = [m[0], m[2], m[1], m[3]];
  9887. // Multiply matrix m with its transpose.
  9888. var a = m[0] * transpose[0] + m[1] * transpose[2];
  9889. var b = m[0] * transpose[1] + m[1] * transpose[3];
  9890. var c = m[2] * transpose[0] + m[3] * transpose[2];
  9891. var d = m[2] * transpose[1] + m[3] * transpose[3];
  9892. // Solve the second degree polynomial to get roots.
  9893. var first = (a + d) / 2;
  9894. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  9895. var sx = first + second || 1;
  9896. var sy = first - second || 1;
  9897. // Scale values are the square roots of the eigenvalues.
  9898. return [Math.sqrt(sx), Math.sqrt(sy)];
  9899. };
  9900. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  9901. // For coordinate systems whose origin lies in the bottom-left, this
  9902. // means normalization to (BL,TR) ordering. For systems with origin in the
  9903. // top-left, this means (TL,BR) ordering.
  9904. Util.normalizeRect = function Util_normalizeRect(rect) {
  9905. var r = rect.slice(0); // clone rect
  9906. if (rect[0] > rect[2]) {
  9907. r[0] = rect[2];
  9908. r[2] = rect[0];
  9909. }
  9910. if (rect[1] > rect[3]) {
  9911. r[1] = rect[3];
  9912. r[3] = rect[1];
  9913. }
  9914. return r;
  9915. };
  9916. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  9917. // intersection of rect1 and rect2. If no intersection, returns 'false'
  9918. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  9919. Util.intersect = function Util_intersect(rect1, rect2) {
  9920. function compare(a, b) {
  9921. return a - b;
  9922. }
  9923. // Order points along the axes
  9924. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  9925. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  9926. result = [];
  9927. rect1 = Util.normalizeRect(rect1);
  9928. rect2 = Util.normalizeRect(rect2);
  9929. // X: first and second points belong to different rectangles?
  9930. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  9931. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  9932. // Intersection must be between second and third points
  9933. result[0] = orderedX[1];
  9934. result[2] = orderedX[2];
  9935. } else {
  9936. return false;
  9937. }
  9938. // Y: first and second points belong to different rectangles?
  9939. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  9940. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  9941. // Intersection must be between second and third points
  9942. result[1] = orderedY[1];
  9943. result[3] = orderedY[2];
  9944. } else {
  9945. return false;
  9946. }
  9947. return result;
  9948. };
  9949. Util.sign = function Util_sign(num) {
  9950. return num < 0 ? -1 : 1;
  9951. };
  9952. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  9953. Array.prototype.push.apply(arr1, arr2);
  9954. };
  9955. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  9956. Array.prototype.unshift.apply(arr1, arr2);
  9957. };
  9958. Util.extendObj = function extendObj(obj1, obj2) {
  9959. for (var key in obj2) {
  9960. obj1[key] = obj2[key];
  9961. }
  9962. };
  9963. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  9964. name) {
  9965. while (dict && !dict.has(name)) {
  9966. dict = dict.get('Parent');
  9967. }
  9968. if (!dict) {
  9969. return null;
  9970. }
  9971. return dict.get(name);
  9972. };
  9973. Util.inherit = function Util_inherit(sub, base, prototype) {
  9974. sub.prototype = Object.create(base.prototype);
  9975. sub.prototype.constructor = sub;
  9976. for (var prop in prototype) {
  9977. sub.prototype[prop] = prototype[prop];
  9978. }
  9979. };
  9980. Util.loadScript = function Util_loadScript(src, callback) {
  9981. var script = document.createElement('script');
  9982. var loaded = false;
  9983. script.setAttribute('src', src);
  9984. if (callback) {
  9985. script.onload = function() {
  9986. if (!loaded) {
  9987. callback();
  9988. }
  9989. loaded = true;
  9990. };
  9991. }
  9992. document.getElementsByTagName('head')[0].appendChild(script);
  9993. };
  9994. return Util;
  9995. })();
  9996. /**
  9997. * PDF page viewport created based on scale, rotation and offset.
  9998. * @class
  9999. * @alias PDFJS.PageViewport
  10000. */
  10001. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  10002. /**
  10003. * @constructor
  10004. * @private
  10005. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  10006. * @param scale {number} scale of the viewport.
  10007. * @param rotation {number} rotations of the viewport in degrees.
  10008. * @param offsetX {number} offset X
  10009. * @param offsetY {number} offset Y
  10010. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  10011. */
  10012. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  10013. this.viewBox = viewBox;
  10014. this.scale = scale;
  10015. this.rotation = rotation;
  10016. this.offsetX = offsetX;
  10017. this.offsetY = offsetY;
  10018. // creating transform to convert pdf coordinate system to the normal
  10019. // canvas like coordinates taking in account scale and rotation
  10020. var centerX = (viewBox[2] + viewBox[0]) / 2;
  10021. var centerY = (viewBox[3] + viewBox[1]) / 2;
  10022. var rotateA, rotateB, rotateC, rotateD;
  10023. rotation = rotation % 360;
  10024. rotation = rotation < 0 ? rotation + 360 : rotation;
  10025. switch (rotation) {
  10026. case 180:
  10027. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  10028. break;
  10029. case 90:
  10030. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  10031. break;
  10032. case 270:
  10033. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  10034. break;
  10035. //case 0:
  10036. default:
  10037. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  10038. break;
  10039. }
  10040. if (dontFlip) {
  10041. rotateC = -rotateC; rotateD = -rotateD;
  10042. }
  10043. var offsetCanvasX, offsetCanvasY;
  10044. var width, height;
  10045. if (rotateA === 0) {
  10046. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  10047. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  10048. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10049. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10050. } else {
  10051. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  10052. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  10053. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10054. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10055. }
  10056. // creating transform for the following operations:
  10057. // translate(-centerX, -centerY), rotate and flip vertically,
  10058. // scale, and translate(offsetCanvasX, offsetCanvasY)
  10059. this.transform = [
  10060. rotateA * scale,
  10061. rotateB * scale,
  10062. rotateC * scale,
  10063. rotateD * scale,
  10064. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  10065. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  10066. ];
  10067. this.width = width;
  10068. this.height = height;
  10069. this.fontScale = scale;
  10070. }
  10071. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  10072. /**
  10073. * Clones viewport with additional properties.
  10074. * @param args {Object} (optional) If specified, may contain the 'scale' or
  10075. * 'rotation' properties to override the corresponding properties in
  10076. * the cloned viewport.
  10077. * @returns {PDFJS.PageViewport} Cloned viewport.
  10078. */
  10079. clone: function PageViewPort_clone(args) {
  10080. args = args || {};
  10081. var scale = 'scale' in args ? args.scale : this.scale;
  10082. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  10083. return new PageViewport(this.viewBox.slice(), scale, rotation,
  10084. this.offsetX, this.offsetY, args.dontFlip);
  10085. },
  10086. /**
  10087. * Converts PDF point to the viewport coordinates. For examples, useful for
  10088. * converting PDF location into canvas pixel coordinates.
  10089. * @param x {number} X coordinate.
  10090. * @param y {number} Y coordinate.
  10091. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10092. * point in the viewport coordinate space.
  10093. * @see {@link convertToPdfPoint}
  10094. * @see {@link convertToViewportRectangle}
  10095. */
  10096. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  10097. return Util.applyTransform([x, y], this.transform);
  10098. },
  10099. /**
  10100. * Converts PDF rectangle to the viewport coordinates.
  10101. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  10102. * @returns {Array} Contains corresponding coordinates of the rectangle
  10103. * in the viewport coordinate space.
  10104. * @see {@link convertToViewportPoint}
  10105. */
  10106. convertToViewportRectangle:
  10107. function PageViewport_convertToViewportRectangle(rect) {
  10108. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  10109. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  10110. return [tl[0], tl[1], br[0], br[1]];
  10111. },
  10112. /**
  10113. * Converts viewport coordinates to the PDF location. For examples, useful
  10114. * for converting canvas pixel location into PDF one.
  10115. * @param x {number} X coordinate.
  10116. * @param y {number} Y coordinate.
  10117. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10118. * point in the PDF coordinate space.
  10119. * @see {@link convertToViewportPoint}
  10120. */
  10121. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  10122. return Util.applyInverseTransform([x, y], this.transform);
  10123. }
  10124. };
  10125. return PageViewport;
  10126. })();
  10127. var PDFStringTranslateTable = [
  10128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10129. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  10130. 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,
  10131. 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,
  10132. 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,
  10133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  10134. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  10135. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  10136. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  10137. ];
  10138. function stringToPDFString(str) {
  10139. var i, n = str.length, strBuf = [];
  10140. if (str[0] === '\xFE' && str[1] === '\xFF') {
  10141. // UTF16BE BOM
  10142. for (i = 2; i < n; i += 2) {
  10143. strBuf.push(String.fromCharCode(
  10144. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  10145. }
  10146. } else {
  10147. for (i = 0; i < n; ++i) {
  10148. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  10149. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  10150. }
  10151. }
  10152. return strBuf.join('');
  10153. }
  10154. function stringToUTF8String(str) {
  10155. return decodeURIComponent(escape(str));
  10156. }
  10157. function utf8StringToString(str) {
  10158. return unescape(encodeURIComponent(str));
  10159. }
  10160. function isEmptyObj(obj) {
  10161. for (var key in obj) {
  10162. return false;
  10163. }
  10164. return true;
  10165. }
  10166. function isBool(v) {
  10167. return typeof v === 'boolean';
  10168. }
  10169. function isInt(v) {
  10170. return typeof v === 'number' && ((v | 0) === v);
  10171. }
  10172. function isNum(v) {
  10173. return typeof v === 'number';
  10174. }
  10175. function isString(v) {
  10176. return typeof v === 'string';
  10177. }
  10178. function isArray(v) {
  10179. return v instanceof Array;
  10180. }
  10181. function isArrayBuffer(v) {
  10182. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  10183. }
  10184. /**
  10185. * Promise Capability object.
  10186. *
  10187. * @typedef {Object} PromiseCapability
  10188. * @property {Promise} promise - A promise object.
  10189. * @property {function} resolve - Fullfills the promise.
  10190. * @property {function} reject - Rejects the promise.
  10191. */
  10192. /**
  10193. * Creates a promise capability object.
  10194. * @alias PDFJS.createPromiseCapability
  10195. *
  10196. * @return {PromiseCapability} A capability object contains:
  10197. * - a Promise, resolve and reject methods.
  10198. */
  10199. function createPromiseCapability() {
  10200. var capability = {};
  10201. capability.promise = new Promise(function (resolve, reject) {
  10202. capability.resolve = resolve;
  10203. capability.reject = reject;
  10204. });
  10205. return capability;
  10206. }
  10207. PDFJS.createPromiseCapability = createPromiseCapability;
  10208. /**
  10209. * Polyfill for Promises:
  10210. * The following promise implementation tries to generally implement the
  10211. * Promise/A+ spec. Some notable differences from other promise libaries are:
  10212. * - There currently isn't a seperate deferred and promise object.
  10213. * - Unhandled rejections eventually show an error if they aren't handled.
  10214. *
  10215. * Based off of the work in:
  10216. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  10217. */
  10218. (function PromiseClosure() {
  10219. if (globalScope.Promise) {
  10220. // Promises existing in the DOM/Worker, checking presence of all/resolve
  10221. if (typeof globalScope.Promise.all !== 'function') {
  10222. globalScope.Promise.all = function (iterable) {
  10223. var count = 0, results = [], resolve, reject;
  10224. var promise = new globalScope.Promise(function (resolve_, reject_) {
  10225. resolve = resolve_;
  10226. reject = reject_;
  10227. });
  10228. iterable.forEach(function (p, i) {
  10229. count++;
  10230. p.then(function (result) {
  10231. results[i] = result;
  10232. count--;
  10233. if (count === 0) {
  10234. resolve(results);
  10235. }
  10236. }, reject);
  10237. });
  10238. if (count === 0) {
  10239. resolve(results);
  10240. }
  10241. return promise;
  10242. };
  10243. }
  10244. if (typeof globalScope.Promise.resolve !== 'function') {
  10245. globalScope.Promise.resolve = function (value) {
  10246. return new globalScope.Promise(function (resolve) { resolve(value); });
  10247. };
  10248. }
  10249. if (typeof globalScope.Promise.reject !== 'function') {
  10250. globalScope.Promise.reject = function (reason) {
  10251. return new globalScope.Promise(function (resolve, reject) {
  10252. reject(reason);
  10253. });
  10254. };
  10255. }
  10256. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  10257. globalScope.Promise.prototype.catch = function (onReject) {
  10258. return globalScope.Promise.prototype.then(undefined, onReject);
  10259. };
  10260. }
  10261. return;
  10262. }
  10263. var STATUS_PENDING = 0;
  10264. var STATUS_RESOLVED = 1;
  10265. var STATUS_REJECTED = 2;
  10266. // In an attempt to avoid silent exceptions, unhandled rejections are
  10267. // tracked and if they aren't handled in a certain amount of time an
  10268. // error is logged.
  10269. var REJECTION_TIMEOUT = 500;
  10270. var HandlerManager = {
  10271. handlers: [],
  10272. running: false,
  10273. unhandledRejections: [],
  10274. pendingRejectionCheck: false,
  10275. scheduleHandlers: function scheduleHandlers(promise) {
  10276. if (promise._status === STATUS_PENDING) {
  10277. return;
  10278. }
  10279. this.handlers = this.handlers.concat(promise._handlers);
  10280. promise._handlers = [];
  10281. if (this.running) {
  10282. return;
  10283. }
  10284. this.running = true;
  10285. setTimeout(this.runHandlers.bind(this), 0);
  10286. },
  10287. runHandlers: function runHandlers() {
  10288. var RUN_TIMEOUT = 1; // ms
  10289. var timeoutAt = Date.now() + RUN_TIMEOUT;
  10290. while (this.handlers.length > 0) {
  10291. var handler = this.handlers.shift();
  10292. var nextStatus = handler.thisPromise._status;
  10293. var nextValue = handler.thisPromise._value;
  10294. try {
  10295. if (nextStatus === STATUS_RESOLVED) {
  10296. if (typeof handler.onResolve === 'function') {
  10297. nextValue = handler.onResolve(nextValue);
  10298. }
  10299. } else if (typeof handler.onReject === 'function') {
  10300. nextValue = handler.onReject(nextValue);
  10301. nextStatus = STATUS_RESOLVED;
  10302. if (handler.thisPromise._unhandledRejection) {
  10303. this.removeUnhandeledRejection(handler.thisPromise);
  10304. }
  10305. }
  10306. } catch (ex) {
  10307. nextStatus = STATUS_REJECTED;
  10308. nextValue = ex;
  10309. }
  10310. handler.nextPromise._updateStatus(nextStatus, nextValue);
  10311. if (Date.now() >= timeoutAt) {
  10312. break;
  10313. }
  10314. }
  10315. if (this.handlers.length > 0) {
  10316. setTimeout(this.runHandlers.bind(this), 0);
  10317. return;
  10318. }
  10319. this.running = false;
  10320. },
  10321. addUnhandledRejection: function addUnhandledRejection(promise) {
  10322. this.unhandledRejections.push({
  10323. promise: promise,
  10324. time: Date.now()
  10325. });
  10326. this.scheduleRejectionCheck();
  10327. },
  10328. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  10329. promise._unhandledRejection = false;
  10330. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10331. if (this.unhandledRejections[i].promise === promise) {
  10332. this.unhandledRejections.splice(i);
  10333. i--;
  10334. }
  10335. }
  10336. },
  10337. scheduleRejectionCheck: function scheduleRejectionCheck() {
  10338. if (this.pendingRejectionCheck) {
  10339. return;
  10340. }
  10341. this.pendingRejectionCheck = true;
  10342. setTimeout(function rejectionCheck() {
  10343. this.pendingRejectionCheck = false;
  10344. var now = Date.now();
  10345. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10346. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  10347. var unhandled = this.unhandledRejections[i].promise._value;
  10348. var msg = 'Unhandled rejection: ' + unhandled;
  10349. if (unhandled.stack) {
  10350. msg += '\n' + unhandled.stack;
  10351. }
  10352. warn(msg);
  10353. this.unhandledRejections.splice(i);
  10354. i--;
  10355. }
  10356. }
  10357. if (this.unhandledRejections.length) {
  10358. this.scheduleRejectionCheck();
  10359. }
  10360. }.bind(this), REJECTION_TIMEOUT);
  10361. }
  10362. };
  10363. function Promise(resolver) {
  10364. this._status = STATUS_PENDING;
  10365. this._handlers = [];
  10366. try {
  10367. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  10368. } catch (e) {
  10369. this._reject(e);
  10370. }
  10371. }
  10372. /**
  10373. * Builds a promise that is resolved when all the passed in promises are
  10374. * resolved.
  10375. * @param {array} array of data and/or promises to wait for.
  10376. * @return {Promise} New dependant promise.
  10377. */
  10378. Promise.all = function Promise_all(promises) {
  10379. var resolveAll, rejectAll;
  10380. var deferred = new Promise(function (resolve, reject) {
  10381. resolveAll = resolve;
  10382. rejectAll = reject;
  10383. });
  10384. var unresolved = promises.length;
  10385. var results = [];
  10386. if (unresolved === 0) {
  10387. resolveAll(results);
  10388. return deferred;
  10389. }
  10390. function reject(reason) {
  10391. if (deferred._status === STATUS_REJECTED) {
  10392. return;
  10393. }
  10394. results = [];
  10395. rejectAll(reason);
  10396. }
  10397. for (var i = 0, ii = promises.length; i < ii; ++i) {
  10398. var promise = promises[i];
  10399. var resolve = (function(i) {
  10400. return function(value) {
  10401. if (deferred._status === STATUS_REJECTED) {
  10402. return;
  10403. }
  10404. results[i] = value;
  10405. unresolved--;
  10406. if (unresolved === 0) {
  10407. resolveAll(results);
  10408. }
  10409. };
  10410. })(i);
  10411. if (Promise.isPromise(promise)) {
  10412. promise.then(resolve, reject);
  10413. } else {
  10414. resolve(promise);
  10415. }
  10416. }
  10417. return deferred;
  10418. };
  10419. /**
  10420. * Checks if the value is likely a promise (has a 'then' function).
  10421. * @return {boolean} true if value is thenable
  10422. */
  10423. Promise.isPromise = function Promise_isPromise(value) {
  10424. return value && typeof value.then === 'function';
  10425. };
  10426. /**
  10427. * Creates resolved promise
  10428. * @param value resolve value
  10429. * @returns {Promise}
  10430. */
  10431. Promise.resolve = function Promise_resolve(value) {
  10432. return new Promise(function (resolve) { resolve(value); });
  10433. };
  10434. /**
  10435. * Creates rejected promise
  10436. * @param reason rejection value
  10437. * @returns {Promise}
  10438. */
  10439. Promise.reject = function Promise_reject(reason) {
  10440. return new Promise(function (resolve, reject) { reject(reason); });
  10441. };
  10442. Promise.prototype = {
  10443. _status: null,
  10444. _value: null,
  10445. _handlers: null,
  10446. _unhandledRejection: null,
  10447. _updateStatus: function Promise__updateStatus(status, value) {
  10448. if (this._status === STATUS_RESOLVED ||
  10449. this._status === STATUS_REJECTED) {
  10450. return;
  10451. }
  10452. if (status === STATUS_RESOLVED &&
  10453. Promise.isPromise(value)) {
  10454. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  10455. this._updateStatus.bind(this, STATUS_REJECTED));
  10456. return;
  10457. }
  10458. this._status = status;
  10459. this._value = value;
  10460. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  10461. this._unhandledRejection = true;
  10462. HandlerManager.addUnhandledRejection(this);
  10463. }
  10464. HandlerManager.scheduleHandlers(this);
  10465. },
  10466. _resolve: function Promise_resolve(value) {
  10467. this._updateStatus(STATUS_RESOLVED, value);
  10468. },
  10469. _reject: function Promise_reject(reason) {
  10470. this._updateStatus(STATUS_REJECTED, reason);
  10471. },
  10472. then: function Promise_then(onResolve, onReject) {
  10473. var nextPromise = new Promise(function (resolve, reject) {
  10474. this.resolve = resolve;
  10475. this.reject = reject;
  10476. });
  10477. this._handlers.push({
  10478. thisPromise: this,
  10479. onResolve: onResolve,
  10480. onReject: onReject,
  10481. nextPromise: nextPromise
  10482. });
  10483. HandlerManager.scheduleHandlers(this);
  10484. return nextPromise;
  10485. },
  10486. catch: function Promise_catch(onReject) {
  10487. return this.then(undefined, onReject);
  10488. }
  10489. };
  10490. globalScope.Promise = Promise;
  10491. })();
  10492. var StatTimer = (function StatTimerClosure() {
  10493. function rpad(str, pad, length) {
  10494. while (str.length < length) {
  10495. str += pad;
  10496. }
  10497. return str;
  10498. }
  10499. function StatTimer() {
  10500. this.started = {};
  10501. this.times = [];
  10502. this.enabled = true;
  10503. }
  10504. StatTimer.prototype = {
  10505. time: function StatTimer_time(name) {
  10506. if (!this.enabled) {
  10507. return;
  10508. }
  10509. if (name in this.started) {
  10510. warn('Timer is already running for ' + name);
  10511. }
  10512. this.started[name] = Date.now();
  10513. },
  10514. timeEnd: function StatTimer_timeEnd(name) {
  10515. if (!this.enabled) {
  10516. return;
  10517. }
  10518. if (!(name in this.started)) {
  10519. warn('Timer has not been started for ' + name);
  10520. }
  10521. this.times.push({
  10522. 'name': name,
  10523. 'start': this.started[name],
  10524. 'end': Date.now()
  10525. });
  10526. // Remove timer from started so it can be called again.
  10527. delete this.started[name];
  10528. },
  10529. toString: function StatTimer_toString() {
  10530. var i, ii;
  10531. var times = this.times;
  10532. var out = '';
  10533. // Find the longest name for padding purposes.
  10534. var longest = 0;
  10535. for (i = 0, ii = times.length; i < ii; ++i) {
  10536. var name = times[i]['name'];
  10537. if (name.length > longest) {
  10538. longest = name.length;
  10539. }
  10540. }
  10541. for (i = 0, ii = times.length; i < ii; ++i) {
  10542. var span = times[i];
  10543. var duration = span.end - span.start;
  10544. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  10545. }
  10546. return out;
  10547. }
  10548. };
  10549. return StatTimer;
  10550. })();
  10551. PDFJS.createBlob = function createBlob(data, contentType) {
  10552. if (typeof Blob !== 'undefined') {
  10553. return new Blob([data], { type: contentType });
  10554. }
  10555. // Blob builder is deprecated in FF14 and removed in FF18.
  10556. var bb = new MozBlobBuilder();
  10557. bb.append(data);
  10558. return bb.getBlob(contentType);
  10559. };
  10560. PDFJS.createObjectURL = (function createObjectURLClosure() {
  10561. // Blob/createObjectURL is not available, falling back to data schema.
  10562. var digits =
  10563. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  10564. return function createObjectURL(data, contentType) {
  10565. if (!PDFJS.disableCreateObjectURL &&
  10566. typeof URL !== 'undefined' && URL.createObjectURL) {
  10567. var blob = PDFJS.createBlob(data, contentType);
  10568. return URL.createObjectURL(blob);
  10569. }
  10570. var buffer = 'data:' + contentType + ';base64,';
  10571. for (var i = 0, ii = data.length; i < ii; i += 3) {
  10572. var b1 = data[i] & 0xFF;
  10573. var b2 = data[i + 1] & 0xFF;
  10574. var b3 = data[i + 2] & 0xFF;
  10575. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  10576. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  10577. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  10578. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  10579. }
  10580. return buffer;
  10581. };
  10582. })();
  10583. function MessageHandler(sourceName, targetName, comObj) {
  10584. this.sourceName = sourceName;
  10585. this.targetName = targetName;
  10586. this.comObj = comObj;
  10587. this.callbackIndex = 1;
  10588. this.postMessageTransfers = true;
  10589. var callbacksCapabilities = this.callbacksCapabilities = {};
  10590. var ah = this.actionHandler = {};
  10591. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  10592. var data = event.data;
  10593. if (data.targetName !== this.sourceName) {
  10594. return;
  10595. }
  10596. if (data.isReply) {
  10597. var callbackId = data.callbackId;
  10598. if (data.callbackId in callbacksCapabilities) {
  10599. var callback = callbacksCapabilities[callbackId];
  10600. delete callbacksCapabilities[callbackId];
  10601. if ('error' in data) {
  10602. callback.reject(data.error);
  10603. } else {
  10604. callback.resolve(data.data);
  10605. }
  10606. } else {
  10607. error('Cannot resolve callback ' + callbackId);
  10608. }
  10609. } else if (data.action in ah) {
  10610. var action = ah[data.action];
  10611. if (data.callbackId) {
  10612. var sourceName = this.sourceName;
  10613. var targetName = data.sourceName;
  10614. Promise.resolve().then(function () {
  10615. return action[0].call(action[1], data.data);
  10616. }).then(function (result) {
  10617. comObj.postMessage({
  10618. sourceName: sourceName,
  10619. targetName: targetName,
  10620. isReply: true,
  10621. callbackId: data.callbackId,
  10622. data: result
  10623. });
  10624. }, function (reason) {
  10625. if (reason instanceof Error) {
  10626. // Serialize error to avoid "DataCloneError"
  10627. reason = reason + '';
  10628. }
  10629. comObj.postMessage({
  10630. sourceName: sourceName,
  10631. targetName: targetName,
  10632. isReply: true,
  10633. callbackId: data.callbackId,
  10634. error: reason
  10635. });
  10636. });
  10637. } else {
  10638. action[0].call(action[1], data.data);
  10639. }
  10640. } else {
  10641. error('Unknown action from worker: ' + data.action);
  10642. }
  10643. }.bind(this);
  10644. comObj.addEventListener('message', this._onComObjOnMessage);
  10645. }
  10646. MessageHandler.prototype = {
  10647. on: function messageHandlerOn(actionName, handler, scope) {
  10648. var ah = this.actionHandler;
  10649. if (ah[actionName]) {
  10650. error('There is already an actionName called "' + actionName + '"');
  10651. }
  10652. ah[actionName] = [handler, scope];
  10653. },
  10654. /**
  10655. * Sends a message to the comObj to invoke the action with the supplied data.
  10656. * @param {String} actionName Action to call.
  10657. * @param {JSON} data JSON data to send.
  10658. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  10659. */
  10660. send: function messageHandlerSend(actionName, data, transfers) {
  10661. var message = {
  10662. sourceName: this.sourceName,
  10663. targetName: this.targetName,
  10664. action: actionName,
  10665. data: data
  10666. };
  10667. this.postMessage(message, transfers);
  10668. },
  10669. /**
  10670. * Sends a message to the comObj to invoke the action with the supplied data.
  10671. * Expects that other side will callback with the response.
  10672. * @param {String} actionName Action to call.
  10673. * @param {JSON} data JSON data to send.
  10674. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  10675. * @returns {Promise} Promise to be resolved with response data.
  10676. */
  10677. sendWithPromise:
  10678. function messageHandlerSendWithPromise(actionName, data, transfers) {
  10679. var callbackId = this.callbackIndex++;
  10680. var message = {
  10681. sourceName: this.sourceName,
  10682. targetName: this.targetName,
  10683. action: actionName,
  10684. data: data,
  10685. callbackId: callbackId
  10686. };
  10687. var capability = createPromiseCapability();
  10688. this.callbacksCapabilities[callbackId] = capability;
  10689. try {
  10690. this.postMessage(message, transfers);
  10691. } catch (e) {
  10692. capability.reject(e);
  10693. }
  10694. return capability.promise;
  10695. },
  10696. /**
  10697. * Sends raw message to the comObj.
  10698. * @private
  10699. * @param message {Object} Raw message.
  10700. * @param transfers List of transfers/ArrayBuffers, or undefined.
  10701. */
  10702. postMessage: function (message, transfers) {
  10703. if (transfers && this.postMessageTransfers) {
  10704. this.comObj.postMessage(message, transfers);
  10705. } else {
  10706. this.comObj.postMessage(message);
  10707. }
  10708. },
  10709. destroy: function () {
  10710. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  10711. }
  10712. };
  10713. function loadJpegStream(id, imageUrl, objs) {
  10714. var img = new Image();
  10715. img.onload = (function loadJpegStream_onloadClosure() {
  10716. objs.resolve(id, img);
  10717. });
  10718. img.onerror = (function loadJpegStream_onerrorClosure() {
  10719. objs.resolve(id, null);
  10720. warn('Error during JPEG image loading');
  10721. });
  10722. img.src = imageUrl;
  10723. }
  10724. // Polyfill from https://github.com/Polymer/URL
  10725. /* Any copyright is dedicated to the Public Domain.
  10726. * http://creativecommons.org/publicdomain/zero/1.0/ */
  10727. (function checkURLConstructor(scope) {
  10728. /* jshint ignore:start */
  10729. // feature detect for URL constructor
  10730. var hasWorkingUrl = false;
  10731. if (typeof URL === 'function' && ('origin' in URL.prototype)) {
  10732. try {
  10733. var u = new URL('b', 'http://a');
  10734. u.pathname = 'c%20d';
  10735. hasWorkingUrl = u.href === 'http://a/c%20d';
  10736. } catch(e) {}
  10737. }
  10738. if (hasWorkingUrl)
  10739. return;
  10740. var relative = Object.create(null);
  10741. relative['ftp'] = 21;
  10742. relative['file'] = 0;
  10743. relative['gopher'] = 70;
  10744. relative['http'] = 80;
  10745. relative['https'] = 443;
  10746. relative['ws'] = 80;
  10747. relative['wss'] = 443;
  10748. var relativePathDotMapping = Object.create(null);
  10749. relativePathDotMapping['%2e'] = '.';
  10750. relativePathDotMapping['.%2e'] = '..';
  10751. relativePathDotMapping['%2e.'] = '..';
  10752. relativePathDotMapping['%2e%2e'] = '..';
  10753. function isRelativeScheme(scheme) {
  10754. return relative[scheme] !== undefined;
  10755. }
  10756. function invalid() {
  10757. clear.call(this);
  10758. this._isInvalid = true;
  10759. }
  10760. function IDNAToASCII(h) {
  10761. if ('' == h) {
  10762. invalid.call(this)
  10763. }
  10764. // XXX
  10765. return h.toLowerCase()
  10766. }
  10767. function percentEscape(c) {
  10768. var unicode = c.charCodeAt(0);
  10769. if (unicode > 0x20 &&
  10770. unicode < 0x7F &&
  10771. // " # < > ? `
  10772. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  10773. ) {
  10774. return c;
  10775. }
  10776. return encodeURIComponent(c);
  10777. }
  10778. function percentEscapeQuery(c) {
  10779. // XXX This actually needs to encode c using encoding and then
  10780. // convert the bytes one-by-one.
  10781. var unicode = c.charCodeAt(0);
  10782. if (unicode > 0x20 &&
  10783. unicode < 0x7F &&
  10784. // " # < > ` (do not escape '?')
  10785. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  10786. ) {
  10787. return c;
  10788. }
  10789. return encodeURIComponent(c);
  10790. }
  10791. var EOF = undefined,
  10792. ALPHA = /[a-zA-Z]/,
  10793. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  10794. function parse(input, stateOverride, base) {
  10795. function err(message) {
  10796. errors.push(message)
  10797. }
  10798. var state = stateOverride || 'scheme start',
  10799. cursor = 0,
  10800. buffer = '',
  10801. seenAt = false,
  10802. seenBracket = false,
  10803. errors = [];
  10804. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  10805. var c = input[cursor];
  10806. switch (state) {
  10807. case 'scheme start':
  10808. if (c && ALPHA.test(c)) {
  10809. buffer += c.toLowerCase(); // ASCII-safe
  10810. state = 'scheme';
  10811. } else if (!stateOverride) {
  10812. buffer = '';
  10813. state = 'no scheme';
  10814. continue;
  10815. } else {
  10816. err('Invalid scheme.');
  10817. break loop;
  10818. }
  10819. break;
  10820. case 'scheme':
  10821. if (c && ALPHANUMERIC.test(c)) {
  10822. buffer += c.toLowerCase(); // ASCII-safe
  10823. } else if (':' == c) {
  10824. this._scheme = buffer;
  10825. buffer = '';
  10826. if (stateOverride) {
  10827. break loop;
  10828. }
  10829. if (isRelativeScheme(this._scheme)) {
  10830. this._isRelative = true;
  10831. }
  10832. if ('file' == this._scheme) {
  10833. state = 'relative';
  10834. } else if (this._isRelative && base && base._scheme == this._scheme) {
  10835. state = 'relative or authority';
  10836. } else if (this._isRelative) {
  10837. state = 'authority first slash';
  10838. } else {
  10839. state = 'scheme data';
  10840. }
  10841. } else if (!stateOverride) {
  10842. buffer = '';
  10843. cursor = 0;
  10844. state = 'no scheme';
  10845. continue;
  10846. } else if (EOF == c) {
  10847. break loop;
  10848. } else {
  10849. err('Code point not allowed in scheme: ' + c)
  10850. break loop;
  10851. }
  10852. break;
  10853. case 'scheme data':
  10854. if ('?' == c) {
  10855. this._query = '?';
  10856. state = 'query';
  10857. } else if ('#' == c) {
  10858. this._fragment = '#';
  10859. state = 'fragment';
  10860. } else {
  10861. // XXX error handling
  10862. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  10863. this._schemeData += percentEscape(c);
  10864. }
  10865. }
  10866. break;
  10867. case 'no scheme':
  10868. if (!base || !(isRelativeScheme(base._scheme))) {
  10869. err('Missing scheme.');
  10870. invalid.call(this);
  10871. } else {
  10872. state = 'relative';
  10873. continue;
  10874. }
  10875. break;
  10876. case 'relative or authority':
  10877. if ('/' == c && '/' == input[cursor+1]) {
  10878. state = 'authority ignore slashes';
  10879. } else {
  10880. err('Expected /, got: ' + c);
  10881. state = 'relative';
  10882. continue
  10883. }
  10884. break;
  10885. case 'relative':
  10886. this._isRelative = true;
  10887. if ('file' != this._scheme)
  10888. this._scheme = base._scheme;
  10889. if (EOF == c) {
  10890. this._host = base._host;
  10891. this._port = base._port;
  10892. this._path = base._path.slice();
  10893. this._query = base._query;
  10894. this._username = base._username;
  10895. this._password = base._password;
  10896. break loop;
  10897. } else if ('/' == c || '\\' == c) {
  10898. if ('\\' == c)
  10899. err('\\ is an invalid code point.');
  10900. state = 'relative slash';
  10901. } else if ('?' == c) {
  10902. this._host = base._host;
  10903. this._port = base._port;
  10904. this._path = base._path.slice();
  10905. this._query = '?';
  10906. this._username = base._username;
  10907. this._password = base._password;
  10908. state = 'query';
  10909. } else if ('#' == c) {
  10910. this._host = base._host;
  10911. this._port = base._port;
  10912. this._path = base._path.slice();
  10913. this._query = base._query;
  10914. this._fragment = '#';
  10915. this._username = base._username;
  10916. this._password = base._password;
  10917. state = 'fragment';
  10918. } else {
  10919. var nextC = input[cursor+1]
  10920. var nextNextC = input[cursor+2]
  10921. if (
  10922. 'file' != this._scheme || !ALPHA.test(c) ||
  10923. (nextC != ':' && nextC != '|') ||
  10924. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  10925. this._host = base._host;
  10926. this._port = base._port;
  10927. this._username = base._username;
  10928. this._password = base._password;
  10929. this._path = base._path.slice();
  10930. this._path.pop();
  10931. }
  10932. state = 'relative path';
  10933. continue;
  10934. }
  10935. break;
  10936. case 'relative slash':
  10937. if ('/' == c || '\\' == c) {
  10938. if ('\\' == c) {
  10939. err('\\ is an invalid code point.');
  10940. }
  10941. if ('file' == this._scheme) {
  10942. state = 'file host';
  10943. } else {
  10944. state = 'authority ignore slashes';
  10945. }
  10946. } else {
  10947. if ('file' != this._scheme) {
  10948. this._host = base._host;
  10949. this._port = base._port;
  10950. this._username = base._username;
  10951. this._password = base._password;
  10952. }
  10953. state = 'relative path';
  10954. continue;
  10955. }
  10956. break;
  10957. case 'authority first slash':
  10958. if ('/' == c) {
  10959. state = 'authority second slash';
  10960. } else {
  10961. err("Expected '/', got: " + c);
  10962. state = 'authority ignore slashes';
  10963. continue;
  10964. }
  10965. break;
  10966. case 'authority second slash':
  10967. state = 'authority ignore slashes';
  10968. if ('/' != c) {
  10969. err("Expected '/', got: " + c);
  10970. continue;
  10971. }
  10972. break;
  10973. case 'authority ignore slashes':
  10974. if ('/' != c && '\\' != c) {
  10975. state = 'authority';
  10976. continue;
  10977. } else {
  10978. err('Expected authority, got: ' + c);
  10979. }
  10980. break;
  10981. case 'authority':
  10982. if ('@' == c) {
  10983. if (seenAt) {
  10984. err('@ already seen.');
  10985. buffer += '%40';
  10986. }
  10987. seenAt = true;
  10988. for (var i = 0; i < buffer.length; i++) {
  10989. var cp = buffer[i];
  10990. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  10991. err('Invalid whitespace in authority.');
  10992. continue;
  10993. }
  10994. // XXX check URL code points
  10995. if (':' == cp && null === this._password) {
  10996. this._password = '';
  10997. continue;
  10998. }
  10999. var tempC = percentEscape(cp);
  11000. (null !== this._password) ? this._password += tempC : this._username += tempC;
  11001. }
  11002. buffer = '';
  11003. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  11004. cursor -= buffer.length;
  11005. buffer = '';
  11006. state = 'host';
  11007. continue;
  11008. } else {
  11009. buffer += c;
  11010. }
  11011. break;
  11012. case 'file host':
  11013. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  11014. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  11015. state = 'relative path';
  11016. } else if (buffer.length == 0) {
  11017. state = 'relative path start';
  11018. } else {
  11019. this._host = IDNAToASCII.call(this, buffer);
  11020. buffer = '';
  11021. state = 'relative path start';
  11022. }
  11023. continue;
  11024. } else if ('\t' == c || '\n' == c || '\r' == c) {
  11025. err('Invalid whitespace in file host.');
  11026. } else {
  11027. buffer += c;
  11028. }
  11029. break;
  11030. case 'host':
  11031. case 'hostname':
  11032. if (':' == c && !seenBracket) {
  11033. // XXX host parsing
  11034. this._host = IDNAToASCII.call(this, buffer);
  11035. buffer = '';
  11036. state = 'port';
  11037. if ('hostname' == stateOverride) {
  11038. break loop;
  11039. }
  11040. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  11041. this._host = IDNAToASCII.call(this, buffer);
  11042. buffer = '';
  11043. state = 'relative path start';
  11044. if (stateOverride) {
  11045. break loop;
  11046. }
  11047. continue;
  11048. } else if ('\t' != c && '\n' != c && '\r' != c) {
  11049. if ('[' == c) {
  11050. seenBracket = true;
  11051. } else if (']' == c) {
  11052. seenBracket = false;
  11053. }
  11054. buffer += c;
  11055. } else {
  11056. err('Invalid code point in host/hostname: ' + c);
  11057. }
  11058. break;
  11059. case 'port':
  11060. if (/[0-9]/.test(c)) {
  11061. buffer += c;
  11062. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  11063. if ('' != buffer) {
  11064. var temp = parseInt(buffer, 10);
  11065. if (temp != relative[this._scheme]) {
  11066. this._port = temp + '';
  11067. }
  11068. buffer = '';
  11069. }
  11070. if (stateOverride) {
  11071. break loop;
  11072. }
  11073. state = 'relative path start';
  11074. continue;
  11075. } else if ('\t' == c || '\n' == c || '\r' == c) {
  11076. err('Invalid code point in port: ' + c);
  11077. } else {
  11078. invalid.call(this);
  11079. }
  11080. break;
  11081. case 'relative path start':
  11082. if ('\\' == c)
  11083. err("'\\' not allowed in path.");
  11084. state = 'relative path';
  11085. if ('/' != c && '\\' != c) {
  11086. continue;
  11087. }
  11088. break;
  11089. case 'relative path':
  11090. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  11091. if ('\\' == c) {
  11092. err('\\ not allowed in relative path.');
  11093. }
  11094. var tmp;
  11095. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  11096. buffer = tmp;
  11097. }
  11098. if ('..' == buffer) {
  11099. this._path.pop();
  11100. if ('/' != c && '\\' != c) {
  11101. this._path.push('');
  11102. }
  11103. } else if ('.' == buffer && '/' != c && '\\' != c) {
  11104. this._path.push('');
  11105. } else if ('.' != buffer) {
  11106. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  11107. buffer = buffer[0] + ':';
  11108. }
  11109. this._path.push(buffer);
  11110. }
  11111. buffer = '';
  11112. if ('?' == c) {
  11113. this._query = '?';
  11114. state = 'query';
  11115. } else if ('#' == c) {
  11116. this._fragment = '#';
  11117. state = 'fragment';
  11118. }
  11119. } else if ('\t' != c && '\n' != c && '\r' != c) {
  11120. buffer += percentEscape(c);
  11121. }
  11122. break;
  11123. case 'query':
  11124. if (!stateOverride && '#' == c) {
  11125. this._fragment = '#';
  11126. state = 'fragment';
  11127. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  11128. this._query += percentEscapeQuery(c);
  11129. }
  11130. break;
  11131. case 'fragment':
  11132. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  11133. this._fragment += c;
  11134. }
  11135. break;
  11136. }
  11137. cursor++;
  11138. }
  11139. }
  11140. function clear() {
  11141. this._scheme = '';
  11142. this._schemeData = '';
  11143. this._username = '';
  11144. this._password = null;
  11145. this._host = '';
  11146. this._port = '';
  11147. this._path = [];
  11148. this._query = '';
  11149. this._fragment = '';
  11150. this._isInvalid = false;
  11151. this._isRelative = false;
  11152. }
  11153. // Does not process domain names or IP addresses.
  11154. // Does not handle encoding for the query parameter.
  11155. function jURL(url, base /* , encoding */) {
  11156. if (base !== undefined && !(base instanceof jURL))
  11157. base = new jURL(String(base));
  11158. this._url = url;
  11159. clear.call(this);
  11160. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  11161. // encoding = encoding || 'utf-8'
  11162. parse.call(this, input, null, base);
  11163. }
  11164. jURL.prototype = {
  11165. toString: function() {
  11166. return this.href;
  11167. },
  11168. get href() {
  11169. if (this._isInvalid)
  11170. return this._url;
  11171. var authority = '';
  11172. if ('' != this._username || null != this._password) {
  11173. authority = this._username +
  11174. (null != this._password ? ':' + this._password : '') + '@';
  11175. }
  11176. return this.protocol +
  11177. (this._isRelative ? '//' + authority + this.host : '') +
  11178. this.pathname + this._query + this._fragment;
  11179. },
  11180. set href(href) {
  11181. clear.call(this);
  11182. parse.call(this, href);
  11183. },
  11184. get protocol() {
  11185. return this._scheme + ':';
  11186. },
  11187. set protocol(protocol) {
  11188. if (this._isInvalid)
  11189. return;
  11190. parse.call(this, protocol + ':', 'scheme start');
  11191. },
  11192. get host() {
  11193. return this._isInvalid ? '' : this._port ?
  11194. this._host + ':' + this._port : this._host;
  11195. },
  11196. set host(host) {
  11197. if (this._isInvalid || !this._isRelative)
  11198. return;
  11199. parse.call(this, host, 'host');
  11200. },
  11201. get hostname() {
  11202. return this._host;
  11203. },
  11204. set hostname(hostname) {
  11205. if (this._isInvalid || !this._isRelative)
  11206. return;
  11207. parse.call(this, hostname, 'hostname');
  11208. },
  11209. get port() {
  11210. return this._port;
  11211. },
  11212. set port(port) {
  11213. if (this._isInvalid || !this._isRelative)
  11214. return;
  11215. parse.call(this, port, 'port');
  11216. },
  11217. get pathname() {
  11218. return this._isInvalid ? '' : this._isRelative ?
  11219. '/' + this._path.join('/') : this._schemeData;
  11220. },
  11221. set pathname(pathname) {
  11222. if (this._isInvalid || !this._isRelative)
  11223. return;
  11224. this._path = [];
  11225. parse.call(this, pathname, 'relative path start');
  11226. },
  11227. get search() {
  11228. return this._isInvalid || !this._query || '?' == this._query ?
  11229. '' : this._query;
  11230. },
  11231. set search(search) {
  11232. if (this._isInvalid || !this._isRelative)
  11233. return;
  11234. this._query = '?';
  11235. if ('?' == search[0])
  11236. search = search.slice(1);
  11237. parse.call(this, search, 'query');
  11238. },
  11239. get hash() {
  11240. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  11241. '' : this._fragment;
  11242. },
  11243. set hash(hash) {
  11244. if (this._isInvalid)
  11245. return;
  11246. this._fragment = '#';
  11247. if ('#' == hash[0])
  11248. hash = hash.slice(1);
  11249. parse.call(this, hash, 'fragment');
  11250. },
  11251. get origin() {
  11252. var host;
  11253. if (this._isInvalid || !this._scheme) {
  11254. return '';
  11255. }
  11256. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  11257. // Gecko throws error for "data://"
  11258. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  11259. // Gecko returns String("") for file: mailto:
  11260. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  11261. switch (this._scheme) {
  11262. case 'data':
  11263. case 'file':
  11264. case 'javascript':
  11265. case 'mailto':
  11266. return 'null';
  11267. }
  11268. host = this.host;
  11269. if (!host) {
  11270. return '';
  11271. }
  11272. return this._scheme + '://' + host;
  11273. }
  11274. };
  11275. // Copy over the static methods
  11276. var OriginalURL = scope.URL;
  11277. if (OriginalURL) {
  11278. jURL.createObjectURL = function(blob) {
  11279. // IE extension allows a second optional options argument.
  11280. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  11281. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  11282. };
  11283. jURL.revokeObjectURL = function(url) {
  11284. OriginalURL.revokeObjectURL(url);
  11285. };
  11286. }
  11287. scope.URL = jURL;
  11288. /* jshint ignore:end */
  11289. })(globalScope);
  11290. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  11291. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  11292. exports.OPS = OPS;
  11293. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  11294. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  11295. exports.AnnotationFlag = AnnotationFlag;
  11296. exports.AnnotationType = AnnotationType;
  11297. exports.FontType = FontType;
  11298. exports.ImageKind = ImageKind;
  11299. exports.InvalidPDFException = InvalidPDFException;
  11300. exports.LinkTarget = LinkTarget;
  11301. exports.LinkTargetStringMap = LinkTargetStringMap;
  11302. exports.MessageHandler = MessageHandler;
  11303. exports.MissingDataException = MissingDataException;
  11304. exports.MissingPDFException = MissingPDFException;
  11305. exports.NotImplementedException = NotImplementedException;
  11306. exports.PasswordException = PasswordException;
  11307. exports.PasswordResponses = PasswordResponses;
  11308. exports.StatTimer = StatTimer;
  11309. exports.StreamType = StreamType;
  11310. exports.TextRenderingMode = TextRenderingMode;
  11311. exports.UnexpectedResponseException = UnexpectedResponseException;
  11312. exports.UnknownErrorException = UnknownErrorException;
  11313. exports.Util = Util;
  11314. exports.XRefParseException = XRefParseException;
  11315. exports.assert = assert;
  11316. exports.bytesToString = bytesToString;
  11317. exports.combineUrl = combineUrl;
  11318. exports.createPromiseCapability = createPromiseCapability;
  11319. exports.deprecated = deprecated;
  11320. exports.error = error;
  11321. exports.info = info;
  11322. exports.isArray = isArray;
  11323. exports.isArrayBuffer = isArrayBuffer;
  11324. exports.isBool = isBool;
  11325. exports.isEmptyObj = isEmptyObj;
  11326. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  11327. exports.isInt = isInt;
  11328. exports.isNum = isNum;
  11329. exports.isString = isString;
  11330. exports.isValidUrl = isValidUrl;
  11331. exports.loadJpegStream = loadJpegStream;
  11332. exports.log2 = log2;
  11333. exports.readInt8 = readInt8;
  11334. exports.readUint16 = readUint16;
  11335. exports.readUint32 = readUint32;
  11336. exports.removeNullCharacters = removeNullCharacters;
  11337. exports.shadow = shadow;
  11338. exports.string32 = string32;
  11339. exports.stringToBytes = stringToBytes;
  11340. exports.stringToPDFString = stringToPDFString;
  11341. exports.stringToUTF8String = stringToUTF8String;
  11342. exports.utf8StringToString = utf8StringToString;
  11343. exports.warn = warn;
  11344. }));
  11345. (function (root, factory) {
  11346. {
  11347. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  11348. }
  11349. }(this, function (exports, sharedUtil) {
  11350. var MissingDataException = sharedUtil.MissingDataException;
  11351. var assert = sharedUtil.assert;
  11352. var createPromiseCapability = sharedUtil.createPromiseCapability;
  11353. var isInt = sharedUtil.isInt;
  11354. var isEmptyObj = sharedUtil.isEmptyObj;
  11355. var ChunkedStream = (function ChunkedStreamClosure() {
  11356. function ChunkedStream(length, chunkSize, manager) {
  11357. this.bytes = new Uint8Array(length);
  11358. this.start = 0;
  11359. this.pos = 0;
  11360. this.end = length;
  11361. this.chunkSize = chunkSize;
  11362. this.loadedChunks = [];
  11363. this.numChunksLoaded = 0;
  11364. this.numChunks = Math.ceil(length / chunkSize);
  11365. this.manager = manager;
  11366. this.progressiveDataLength = 0;
  11367. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  11368. }
  11369. // required methods for a stream. if a particular stream does not
  11370. // implement these, an error should be thrown
  11371. ChunkedStream.prototype = {
  11372. getMissingChunks: function ChunkedStream_getMissingChunks() {
  11373. var chunks = [];
  11374. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  11375. if (!this.loadedChunks[chunk]) {
  11376. chunks.push(chunk);
  11377. }
  11378. }
  11379. return chunks;
  11380. },
  11381. getBaseStreams: function ChunkedStream_getBaseStreams() {
  11382. return [this];
  11383. },
  11384. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  11385. return this.numChunksLoaded === this.numChunks;
  11386. },
  11387. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  11388. var end = begin + chunk.byteLength;
  11389. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  11390. // Using this.length is inaccurate here since this.start can be moved
  11391. // See ChunkedStream.moveStart()
  11392. var length = this.bytes.length;
  11393. assert(end % this.chunkSize === 0 || end === length,
  11394. 'Bad end offset: ' + end);
  11395. this.bytes.set(new Uint8Array(chunk), begin);
  11396. var chunkSize = this.chunkSize;
  11397. var beginChunk = Math.floor(begin / chunkSize);
  11398. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  11399. var curChunk;
  11400. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  11401. if (!this.loadedChunks[curChunk]) {
  11402. this.loadedChunks[curChunk] = true;
  11403. ++this.numChunksLoaded;
  11404. }
  11405. }
  11406. },
  11407. onReceiveProgressiveData:
  11408. function ChunkedStream_onReceiveProgressiveData(data) {
  11409. var position = this.progressiveDataLength;
  11410. var beginChunk = Math.floor(position / this.chunkSize);
  11411. this.bytes.set(new Uint8Array(data), position);
  11412. position += data.byteLength;
  11413. this.progressiveDataLength = position;
  11414. var endChunk = position >= this.end ? this.numChunks :
  11415. Math.floor(position / this.chunkSize);
  11416. var curChunk;
  11417. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  11418. if (!this.loadedChunks[curChunk]) {
  11419. this.loadedChunks[curChunk] = true;
  11420. ++this.numChunksLoaded;
  11421. }
  11422. }
  11423. },
  11424. ensureByte: function ChunkedStream_ensureByte(pos) {
  11425. var chunk = Math.floor(pos / this.chunkSize);
  11426. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  11427. return;
  11428. }
  11429. if (!this.loadedChunks[chunk]) {
  11430. throw new MissingDataException(pos, pos + 1);
  11431. }
  11432. this.lastSuccessfulEnsureByteChunk = chunk;
  11433. },
  11434. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  11435. if (begin >= end) {
  11436. return;
  11437. }
  11438. if (end <= this.progressiveDataLength) {
  11439. return;
  11440. }
  11441. var chunkSize = this.chunkSize;
  11442. var beginChunk = Math.floor(begin / chunkSize);
  11443. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  11444. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11445. if (!this.loadedChunks[chunk]) {
  11446. throw new MissingDataException(begin, end);
  11447. }
  11448. }
  11449. },
  11450. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  11451. var chunk, numChunks = this.numChunks;
  11452. for (var i = 0; i < numChunks; ++i) {
  11453. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  11454. if (!this.loadedChunks[chunk]) {
  11455. return chunk;
  11456. }
  11457. }
  11458. return null;
  11459. },
  11460. hasChunk: function ChunkedStream_hasChunk(chunk) {
  11461. return !!this.loadedChunks[chunk];
  11462. },
  11463. get length() {
  11464. return this.end - this.start;
  11465. },
  11466. get isEmpty() {
  11467. return this.length === 0;
  11468. },
  11469. getByte: function ChunkedStream_getByte() {
  11470. var pos = this.pos;
  11471. if (pos >= this.end) {
  11472. return -1;
  11473. }
  11474. this.ensureByte(pos);
  11475. return this.bytes[this.pos++];
  11476. },
  11477. getUint16: function ChunkedStream_getUint16() {
  11478. var b0 = this.getByte();
  11479. var b1 = this.getByte();
  11480. if (b0 === -1 || b1 === -1) {
  11481. return -1;
  11482. }
  11483. return (b0 << 8) + b1;
  11484. },
  11485. getInt32: function ChunkedStream_getInt32() {
  11486. var b0 = this.getByte();
  11487. var b1 = this.getByte();
  11488. var b2 = this.getByte();
  11489. var b3 = this.getByte();
  11490. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  11491. },
  11492. // returns subarray of original buffer
  11493. // should only be read
  11494. getBytes: function ChunkedStream_getBytes(length) {
  11495. var bytes = this.bytes;
  11496. var pos = this.pos;
  11497. var strEnd = this.end;
  11498. if (!length) {
  11499. this.ensureRange(pos, strEnd);
  11500. return bytes.subarray(pos, strEnd);
  11501. }
  11502. var end = pos + length;
  11503. if (end > strEnd) {
  11504. end = strEnd;
  11505. }
  11506. this.ensureRange(pos, end);
  11507. this.pos = end;
  11508. return bytes.subarray(pos, end);
  11509. },
  11510. peekByte: function ChunkedStream_peekByte() {
  11511. var peekedByte = this.getByte();
  11512. this.pos--;
  11513. return peekedByte;
  11514. },
  11515. peekBytes: function ChunkedStream_peekBytes(length) {
  11516. var bytes = this.getBytes(length);
  11517. this.pos -= bytes.length;
  11518. return bytes;
  11519. },
  11520. getByteRange: function ChunkedStream_getBytes(begin, end) {
  11521. this.ensureRange(begin, end);
  11522. return this.bytes.subarray(begin, end);
  11523. },
  11524. skip: function ChunkedStream_skip(n) {
  11525. if (!n) {
  11526. n = 1;
  11527. }
  11528. this.pos += n;
  11529. },
  11530. reset: function ChunkedStream_reset() {
  11531. this.pos = this.start;
  11532. },
  11533. moveStart: function ChunkedStream_moveStart() {
  11534. this.start = this.pos;
  11535. },
  11536. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  11537. this.ensureRange(start, start + length);
  11538. function ChunkedStreamSubstream() {}
  11539. ChunkedStreamSubstream.prototype = Object.create(this);
  11540. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  11541. var chunkSize = this.chunkSize;
  11542. var beginChunk = Math.floor(this.start / chunkSize);
  11543. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  11544. var missingChunks = [];
  11545. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11546. if (!this.loadedChunks[chunk]) {
  11547. missingChunks.push(chunk);
  11548. }
  11549. }
  11550. return missingChunks;
  11551. };
  11552. var subStream = new ChunkedStreamSubstream();
  11553. subStream.pos = subStream.start = start;
  11554. subStream.end = start + length || this.end;
  11555. subStream.dict = dict;
  11556. return subStream;
  11557. },
  11558. isStream: true
  11559. };
  11560. return ChunkedStream;
  11561. })();
  11562. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  11563. function ChunkedStreamManager(length, chunkSize, url, args) {
  11564. this.stream = new ChunkedStream(length, chunkSize, this);
  11565. this.length = length;
  11566. this.chunkSize = chunkSize;
  11567. this.url = url;
  11568. this.disableAutoFetch = args.disableAutoFetch;
  11569. var msgHandler = this.msgHandler = args.msgHandler;
  11570. if (args.chunkedViewerLoading) {
  11571. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  11572. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  11573. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  11574. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  11575. };
  11576. } else {
  11577. var getXhr = function getXhr() {
  11578. return new XMLHttpRequest();
  11579. };
  11580. this.networkManager = new NetworkManager(this.url, {
  11581. getXhr: getXhr,
  11582. httpHeaders: args.httpHeaders,
  11583. withCredentials: args.withCredentials
  11584. });
  11585. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  11586. this.networkManager.requestRange(begin, end, {
  11587. onDone: this.onReceiveData.bind(this),
  11588. onProgress: this.onProgress.bind(this)
  11589. });
  11590. };
  11591. }
  11592. this.currRequestId = 0;
  11593. this.chunksNeededByRequest = {};
  11594. this.requestsByChunk = {};
  11595. this.promisesByRequest = {};
  11596. this.progressiveDataLength = 0;
  11597. this._loadedStreamCapability = createPromiseCapability();
  11598. if (args.initialData) {
  11599. this.onReceiveData({chunk: args.initialData});
  11600. }
  11601. }
  11602. ChunkedStreamManager.prototype = {
  11603. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  11604. return this._loadedStreamCapability.promise;
  11605. },
  11606. // Get all the chunks that are not yet loaded and groups them into
  11607. // contiguous ranges to load in as few requests as possible
  11608. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  11609. var missingChunks = this.stream.getMissingChunks();
  11610. this._requestChunks(missingChunks);
  11611. return this._loadedStreamCapability.promise;
  11612. },
  11613. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  11614. var requestId = this.currRequestId++;
  11615. var chunksNeeded;
  11616. var i, ii;
  11617. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  11618. for (i = 0, ii = chunks.length; i < ii; i++) {
  11619. if (!this.stream.hasChunk(chunks[i])) {
  11620. chunksNeeded[chunks[i]] = true;
  11621. }
  11622. }
  11623. if (isEmptyObj(chunksNeeded)) {
  11624. return Promise.resolve();
  11625. }
  11626. var capability = createPromiseCapability();
  11627. this.promisesByRequest[requestId] = capability;
  11628. var chunksToRequest = [];
  11629. for (var chunk in chunksNeeded) {
  11630. chunk = chunk | 0;
  11631. if (!(chunk in this.requestsByChunk)) {
  11632. this.requestsByChunk[chunk] = [];
  11633. chunksToRequest.push(chunk);
  11634. }
  11635. this.requestsByChunk[chunk].push(requestId);
  11636. }
  11637. if (!chunksToRequest.length) {
  11638. return capability.promise;
  11639. }
  11640. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11641. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11642. var groupedChunk = groupedChunksToRequest[i];
  11643. var begin = groupedChunk.beginChunk * this.chunkSize;
  11644. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11645. this.sendRequest(begin, end);
  11646. }
  11647. return capability.promise;
  11648. },
  11649. getStream: function ChunkedStreamManager_getStream() {
  11650. return this.stream;
  11651. },
  11652. // Loads any chunks in the requested range that are not yet loaded
  11653. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11654. end = Math.min(end, this.length);
  11655. var beginChunk = this.getBeginChunk(begin);
  11656. var endChunk = this.getEndChunk(end);
  11657. var chunks = [];
  11658. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11659. chunks.push(chunk);
  11660. }
  11661. return this._requestChunks(chunks);
  11662. },
  11663. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11664. ranges = ranges || [];
  11665. var chunksToRequest = [];
  11666. for (var i = 0; i < ranges.length; i++) {
  11667. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11668. var endChunk = this.getEndChunk(ranges[i].end);
  11669. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11670. if (chunksToRequest.indexOf(chunk) < 0) {
  11671. chunksToRequest.push(chunk);
  11672. }
  11673. }
  11674. }
  11675. chunksToRequest.sort(function(a, b) { return a - b; });
  11676. return this._requestChunks(chunksToRequest);
  11677. },
  11678. // Groups a sorted array of chunks into as few contiguous larger
  11679. // chunks as possible
  11680. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11681. var groupedChunks = [];
  11682. var beginChunk = -1;
  11683. var prevChunk = -1;
  11684. for (var i = 0; i < chunks.length; ++i) {
  11685. var chunk = chunks[i];
  11686. if (beginChunk < 0) {
  11687. beginChunk = chunk;
  11688. }
  11689. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11690. groupedChunks.push({ beginChunk: beginChunk,
  11691. endChunk: prevChunk + 1 });
  11692. beginChunk = chunk;
  11693. }
  11694. if (i + 1 === chunks.length) {
  11695. groupedChunks.push({ beginChunk: beginChunk,
  11696. endChunk: chunk + 1 });
  11697. }
  11698. prevChunk = chunk;
  11699. }
  11700. return groupedChunks;
  11701. },
  11702. onProgress: function ChunkedStreamManager_onProgress(args) {
  11703. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11704. args.loaded);
  11705. this.msgHandler.send('DocProgress', {
  11706. loaded: bytesLoaded,
  11707. total: this.length
  11708. });
  11709. },
  11710. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11711. var chunk = args.chunk;
  11712. var isProgressive = args.begin === undefined;
  11713. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11714. var end = begin + chunk.byteLength;
  11715. var beginChunk = Math.floor(begin / this.chunkSize);
  11716. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11717. Math.ceil(end / this.chunkSize);
  11718. if (isProgressive) {
  11719. this.stream.onReceiveProgressiveData(chunk);
  11720. this.progressiveDataLength = end;
  11721. } else {
  11722. this.stream.onReceiveData(begin, chunk);
  11723. }
  11724. if (this.stream.allChunksLoaded()) {
  11725. this._loadedStreamCapability.resolve(this.stream);
  11726. }
  11727. var loadedRequests = [];
  11728. var i, requestId;
  11729. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11730. // The server might return more chunks than requested
  11731. var requestIds = this.requestsByChunk[chunk] || [];
  11732. delete this.requestsByChunk[chunk];
  11733. for (i = 0; i < requestIds.length; ++i) {
  11734. requestId = requestIds[i];
  11735. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11736. if (chunk in chunksNeeded) {
  11737. delete chunksNeeded[chunk];
  11738. }
  11739. if (!isEmptyObj(chunksNeeded)) {
  11740. continue;
  11741. }
  11742. loadedRequests.push(requestId);
  11743. }
  11744. }
  11745. // If there are no pending requests, automatically fetch the next
  11746. // unfetched chunk of the PDF
  11747. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11748. var nextEmptyChunk;
  11749. if (this.stream.numChunksLoaded === 1) {
  11750. // This is a special optimization so that after fetching the first
  11751. // chunk, rather than fetching the second chunk, we fetch the last
  11752. // chunk.
  11753. var lastChunk = this.stream.numChunks - 1;
  11754. if (!this.stream.hasChunk(lastChunk)) {
  11755. nextEmptyChunk = lastChunk;
  11756. }
  11757. } else {
  11758. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11759. }
  11760. if (isInt(nextEmptyChunk)) {
  11761. this._requestChunks([nextEmptyChunk]);
  11762. }
  11763. }
  11764. for (i = 0; i < loadedRequests.length; ++i) {
  11765. requestId = loadedRequests[i];
  11766. var capability = this.promisesByRequest[requestId];
  11767. delete this.promisesByRequest[requestId];
  11768. capability.resolve();
  11769. }
  11770. this.msgHandler.send('DocProgress', {
  11771. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11772. total: this.length
  11773. });
  11774. },
  11775. onError: function ChunkedStreamManager_onError(err) {
  11776. this._loadedStreamCapability.reject(err);
  11777. },
  11778. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11779. var chunk = Math.floor(begin / this.chunkSize);
  11780. return chunk;
  11781. },
  11782. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11783. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11784. return chunk;
  11785. },
  11786. abort: function ChunkedStreamManager_abort() {
  11787. if (this.networkManager) {
  11788. this.networkManager.abortAllRequests();
  11789. }
  11790. for(var requestId in this.promisesByRequest) {
  11791. var capability = this.promisesByRequest[requestId];
  11792. capability.reject(new Error('Request was aborted'));
  11793. }
  11794. }
  11795. };
  11796. return ChunkedStreamManager;
  11797. })();
  11798. exports.ChunkedStream = ChunkedStream;
  11799. exports.ChunkedStreamManager = ChunkedStreamManager;
  11800. }));
  11801. (function (root, factory) {
  11802. {
  11803. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11804. root.pdfjsCoreArithmeticDecoder);
  11805. }
  11806. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11807. var error = sharedUtil.error;
  11808. var log2 = sharedUtil.log2;
  11809. var readInt8 = sharedUtil.readInt8;
  11810. var readUint16 = sharedUtil.readUint16;
  11811. var readUint32 = sharedUtil.readUint32;
  11812. var shadow = sharedUtil.shadow;
  11813. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11814. var Jbig2Image = (function Jbig2ImageClosure() {
  11815. // Utility data structures
  11816. function ContextCache() {}
  11817. ContextCache.prototype = {
  11818. getContexts: function(id) {
  11819. if (id in this) {
  11820. return this[id];
  11821. }
  11822. return (this[id] = new Int8Array(1 << 16));
  11823. }
  11824. };
  11825. function DecodingContext(data, start, end) {
  11826. this.data = data;
  11827. this.start = start;
  11828. this.end = end;
  11829. }
  11830. DecodingContext.prototype = {
  11831. get decoder() {
  11832. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11833. return shadow(this, 'decoder', decoder);
  11834. },
  11835. get contextCache() {
  11836. var cache = new ContextCache();
  11837. return shadow(this, 'contextCache', cache);
  11838. }
  11839. };
  11840. // Annex A. Arithmetic Integer Decoding Procedure
  11841. // A.2 Procedure for decoding values
  11842. function decodeInteger(contextCache, procedure, decoder) {
  11843. var contexts = contextCache.getContexts(procedure);
  11844. var prev = 1;
  11845. function readBits(length) {
  11846. var v = 0;
  11847. for (var i = 0; i < length; i++) {
  11848. var bit = decoder.readBit(contexts, prev);
  11849. prev = (prev < 256 ? (prev << 1) | bit :
  11850. (((prev << 1) | bit) & 511) | 256);
  11851. v = (v << 1) | bit;
  11852. }
  11853. return v >>> 0;
  11854. }
  11855. var sign = readBits(1);
  11856. var value = readBits(1) ?
  11857. (readBits(1) ?
  11858. (readBits(1) ?
  11859. (readBits(1) ?
  11860. (readBits(1) ?
  11861. (readBits(32) + 4436) :
  11862. readBits(12) + 340) :
  11863. readBits(8) + 84) :
  11864. readBits(6) + 20) :
  11865. readBits(4) + 4) :
  11866. readBits(2);
  11867. return (sign === 0 ? value : (value > 0 ? -value : null));
  11868. }
  11869. // A.3 The IAID decoding procedure
  11870. function decodeIAID(contextCache, decoder, codeLength) {
  11871. var contexts = contextCache.getContexts('IAID');
  11872. var prev = 1;
  11873. for (var i = 0; i < codeLength; i++) {
  11874. var bit = decoder.readBit(contexts, prev);
  11875. prev = (prev << 1) | bit;
  11876. }
  11877. if (codeLength < 31) {
  11878. return prev & ((1 << codeLength) - 1);
  11879. }
  11880. return prev & 0x7FFFFFFF;
  11881. }
  11882. // 7.3 Segment types
  11883. var SegmentTypes = [
  11884. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11885. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11886. null, null, null, null, null, 'patternDictionary', null, null, null,
  11887. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11888. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11889. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11890. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11891. 'IntermediateGenericRefinementRegion', null,
  11892. 'ImmediateGenericRefinementRegion',
  11893. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11894. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11895. 'Tables', null, null, null, null, null, null, null, null,
  11896. 'Extension'
  11897. ];
  11898. var CodingTemplates = [
  11899. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11900. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11901. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11902. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11903. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11904. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11905. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11906. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11907. {x: -1, y: 0}],
  11908. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11909. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11910. ];
  11911. var RefinementTemplates = [
  11912. {
  11913. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11914. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11915. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11916. },
  11917. {
  11918. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11919. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11920. {x: 0, y: 1}, {x: 1, y: 1}]
  11921. }
  11922. ];
  11923. // See 6.2.5.7 Decoding the bitmap.
  11924. var ReusedContexts = [
  11925. 0x9B25, // 10011 0110010 0101
  11926. 0x0795, // 0011 110010 101
  11927. 0x00E5, // 001 11001 01
  11928. 0x0195 // 011001 0101
  11929. ];
  11930. var RefinementReusedContexts = [
  11931. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11932. 0x0008 // '0000' + '001000'
  11933. ];
  11934. function decodeBitmapTemplate0(width, height, decodingContext) {
  11935. var decoder = decodingContext.decoder;
  11936. var contexts = decodingContext.contextCache.getContexts('GB');
  11937. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11938. // ...ooooo....
  11939. // ..ooooooo... Context template for current pixel (X)
  11940. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11941. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11942. for (i = 0; i < height; i++) {
  11943. row = bitmap[i] = new Uint8Array(width);
  11944. row1 = (i < 1) ? row : bitmap[i - 1];
  11945. row2 = (i < 2) ? row : bitmap[i - 2];
  11946. // At the beginning of each row:
  11947. // Fill contextLabel with pixels that are above/right of (X)
  11948. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11949. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11950. (row1[3] << 4);
  11951. for (j = 0; j < width; j++) {
  11952. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11953. // At each pixel: Clear contextLabel pixels that are shifted
  11954. // out of the context, then add new ones.
  11955. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11956. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11957. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11958. }
  11959. }
  11960. return bitmap;
  11961. }
  11962. // 6.2 Generic Region Decoding Procedure
  11963. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11964. decodingContext) {
  11965. if (mmr) {
  11966. error('JBIG2 error: MMR encoding is not supported');
  11967. }
  11968. // Use optimized version for the most common case
  11969. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11970. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11971. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11972. return decodeBitmapTemplate0(width, height, decodingContext);
  11973. }
  11974. var useskip = !!skip;
  11975. var template = CodingTemplates[templateIndex].concat(at);
  11976. // Sorting is non-standard, and it is not required. But sorting increases
  11977. // the number of template bits that can be reused from the previous
  11978. // contextLabel in the main loop.
  11979. template.sort(function (a, b) {
  11980. return (a.y - b.y) || (a.x - b.x);
  11981. });
  11982. var templateLength = template.length;
  11983. var templateX = new Int8Array(templateLength);
  11984. var templateY = new Int8Array(templateLength);
  11985. var changingTemplateEntries = [];
  11986. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11987. var c, k;
  11988. for (k = 0; k < templateLength; k++) {
  11989. templateX[k] = template[k].x;
  11990. templateY[k] = template[k].y;
  11991. minX = Math.min(minX, template[k].x);
  11992. maxX = Math.max(maxX, template[k].x);
  11993. minY = Math.min(minY, template[k].y);
  11994. // Check if the template pixel appears in two consecutive context labels,
  11995. // so it can be reused. Otherwise, we add it to the list of changing
  11996. // template entries.
  11997. if (k < templateLength - 1 &&
  11998. template[k].y === template[k + 1].y &&
  11999. template[k].x === template[k + 1].x - 1) {
  12000. reuseMask |= 1 << (templateLength - 1 - k);
  12001. } else {
  12002. changingTemplateEntries.push(k);
  12003. }
  12004. }
  12005. var changingEntriesLength = changingTemplateEntries.length;
  12006. var changingTemplateX = new Int8Array(changingEntriesLength);
  12007. var changingTemplateY = new Int8Array(changingEntriesLength);
  12008. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  12009. for (c = 0; c < changingEntriesLength; c++) {
  12010. k = changingTemplateEntries[c];
  12011. changingTemplateX[c] = template[k].x;
  12012. changingTemplateY[c] = template[k].y;
  12013. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  12014. }
  12015. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  12016. var sbb_left = -minX;
  12017. var sbb_top = -minY;
  12018. var sbb_right = width - maxX;
  12019. var pseudoPixelContext = ReusedContexts[templateIndex];
  12020. var row = new Uint8Array(width);
  12021. var bitmap = [];
  12022. var decoder = decodingContext.decoder;
  12023. var contexts = decodingContext.contextCache.getContexts('GB');
  12024. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  12025. for (var i = 0; i < height; i++) {
  12026. if (prediction) {
  12027. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  12028. ltp ^= sltp;
  12029. if (ltp) {
  12030. bitmap.push(row); // duplicate previous row
  12031. continue;
  12032. }
  12033. }
  12034. row = new Uint8Array(row);
  12035. bitmap.push(row);
  12036. for (j = 0; j < width; j++) {
  12037. if (useskip && skip[i][j]) {
  12038. row[j] = 0;
  12039. continue;
  12040. }
  12041. // Are we in the middle of a scanline, so we can reuse contextLabel
  12042. // bits?
  12043. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  12044. // If yes, we can just shift the bits that are reusable and only
  12045. // fetch the remaining ones.
  12046. contextLabel = (contextLabel << 1) & reuseMask;
  12047. for (k = 0; k < changingEntriesLength; k++) {
  12048. i0 = i + changingTemplateY[k];
  12049. j0 = j + changingTemplateX[k];
  12050. bit = bitmap[i0][j0];
  12051. if (bit) {
  12052. bit = changingTemplateBit[k];
  12053. contextLabel |= bit;
  12054. }
  12055. }
  12056. } else {
  12057. // compute the contextLabel from scratch
  12058. contextLabel = 0;
  12059. shift = templateLength - 1;
  12060. for (k = 0; k < templateLength; k++, shift--) {
  12061. j0 = j + templateX[k];
  12062. if (j0 >= 0 && j0 < width) {
  12063. i0 = i + templateY[k];
  12064. if (i0 >= 0) {
  12065. bit = bitmap[i0][j0];
  12066. if (bit) {
  12067. contextLabel |= bit << shift;
  12068. }
  12069. }
  12070. }
  12071. }
  12072. }
  12073. var pixel = decoder.readBit(contexts, contextLabel);
  12074. row[j] = pixel;
  12075. }
  12076. }
  12077. return bitmap;
  12078. }
  12079. // 6.3.2 Generic Refinement Region Decoding Procedure
  12080. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  12081. offsetX, offsetY, prediction, at,
  12082. decodingContext) {
  12083. var codingTemplate = RefinementTemplates[templateIndex].coding;
  12084. if (templateIndex === 0) {
  12085. codingTemplate = codingTemplate.concat([at[0]]);
  12086. }
  12087. var codingTemplateLength = codingTemplate.length;
  12088. var codingTemplateX = new Int32Array(codingTemplateLength);
  12089. var codingTemplateY = new Int32Array(codingTemplateLength);
  12090. var k;
  12091. for (k = 0; k < codingTemplateLength; k++) {
  12092. codingTemplateX[k] = codingTemplate[k].x;
  12093. codingTemplateY[k] = codingTemplate[k].y;
  12094. }
  12095. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  12096. if (templateIndex === 0) {
  12097. referenceTemplate = referenceTemplate.concat([at[1]]);
  12098. }
  12099. var referenceTemplateLength = referenceTemplate.length;
  12100. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  12101. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  12102. for (k = 0; k < referenceTemplateLength; k++) {
  12103. referenceTemplateX[k] = referenceTemplate[k].x;
  12104. referenceTemplateY[k] = referenceTemplate[k].y;
  12105. }
  12106. var referenceWidth = referenceBitmap[0].length;
  12107. var referenceHeight = referenceBitmap.length;
  12108. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  12109. var bitmap = [];
  12110. var decoder = decodingContext.decoder;
  12111. var contexts = decodingContext.contextCache.getContexts('GR');
  12112. var ltp = 0;
  12113. for (var i = 0; i < height; i++) {
  12114. if (prediction) {
  12115. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  12116. ltp ^= sltp;
  12117. if (ltp) {
  12118. error('JBIG2 error: prediction is not supported');
  12119. }
  12120. }
  12121. var row = new Uint8Array(width);
  12122. bitmap.push(row);
  12123. for (var j = 0; j < width; j++) {
  12124. var i0, j0;
  12125. var contextLabel = 0;
  12126. for (k = 0; k < codingTemplateLength; k++) {
  12127. i0 = i + codingTemplateY[k];
  12128. j0 = j + codingTemplateX[k];
  12129. if (i0 < 0 || j0 < 0 || j0 >= width) {
  12130. contextLabel <<= 1; // out of bound pixel
  12131. } else {
  12132. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  12133. }
  12134. }
  12135. for (k = 0; k < referenceTemplateLength; k++) {
  12136. i0 = i + referenceTemplateY[k] + offsetY;
  12137. j0 = j + referenceTemplateX[k] + offsetX;
  12138. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  12139. j0 >= referenceWidth) {
  12140. contextLabel <<= 1; // out of bound pixel
  12141. } else {
  12142. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  12143. }
  12144. }
  12145. var pixel = decoder.readBit(contexts, contextLabel);
  12146. row[j] = pixel;
  12147. }
  12148. }
  12149. return bitmap;
  12150. }
  12151. // 6.5.5 Decoding the symbol dictionary
  12152. function decodeSymbolDictionary(huffman, refinement, symbols,
  12153. numberOfNewSymbols, numberOfExportedSymbols,
  12154. huffmanTables, templateIndex, at,
  12155. refinementTemplateIndex, refinementAt,
  12156. decodingContext) {
  12157. if (huffman) {
  12158. error('JBIG2 error: huffman is not supported');
  12159. }
  12160. var newSymbols = [];
  12161. var currentHeight = 0;
  12162. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  12163. var decoder = decodingContext.decoder;
  12164. var contextCache = decodingContext.contextCache;
  12165. while (newSymbols.length < numberOfNewSymbols) {
  12166. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  12167. currentHeight += deltaHeight;
  12168. var currentWidth = 0;
  12169. var totalWidth = 0;
  12170. while (true) {
  12171. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  12172. if (deltaWidth === null) {
  12173. break; // OOB
  12174. }
  12175. currentWidth += deltaWidth;
  12176. totalWidth += currentWidth;
  12177. var bitmap;
  12178. if (refinement) {
  12179. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  12180. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  12181. if (numberOfInstances > 1) {
  12182. bitmap = decodeTextRegion(huffman, refinement,
  12183. currentWidth, currentHeight, 0,
  12184. numberOfInstances, 1, //strip size
  12185. symbols.concat(newSymbols),
  12186. symbolCodeLength,
  12187. 0, //transposed
  12188. 0, //ds offset
  12189. 1, //top left 7.4.3.1.1
  12190. 0, //OR operator
  12191. huffmanTables,
  12192. refinementTemplateIndex, refinementAt,
  12193. decodingContext);
  12194. } else {
  12195. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  12196. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  12197. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  12198. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  12199. newSymbols[symbolId - symbols.length]);
  12200. bitmap = decodeRefinement(currentWidth, currentHeight,
  12201. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  12202. decodingContext);
  12203. }
  12204. } else {
  12205. // 6.5.8.1 Direct-coded symbol bitmap
  12206. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  12207. templateIndex, false, null, at, decodingContext);
  12208. }
  12209. newSymbols.push(bitmap);
  12210. }
  12211. }
  12212. // 6.5.10 Exported symbols
  12213. var exportedSymbols = [];
  12214. var flags = [], currentFlag = false;
  12215. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  12216. while (flags.length < totalSymbolsLength) {
  12217. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  12218. while (runLength--) {
  12219. flags.push(currentFlag);
  12220. }
  12221. currentFlag = !currentFlag;
  12222. }
  12223. for (var i = 0, ii = symbols.length; i < ii; i++) {
  12224. if (flags[i]) {
  12225. exportedSymbols.push(symbols[i]);
  12226. }
  12227. }
  12228. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  12229. if (flags[i]) {
  12230. exportedSymbols.push(newSymbols[j]);
  12231. }
  12232. }
  12233. return exportedSymbols;
  12234. }
  12235. function decodeTextRegion(huffman, refinement, width, height,
  12236. defaultPixelValue, numberOfSymbolInstances,
  12237. stripSize, inputSymbols, symbolCodeLength,
  12238. transposed, dsOffset, referenceCorner,
  12239. combinationOperator, huffmanTables,
  12240. refinementTemplateIndex, refinementAt,
  12241. decodingContext) {
  12242. if (huffman) {
  12243. error('JBIG2 error: huffman is not supported');
  12244. }
  12245. // Prepare bitmap
  12246. var bitmap = [];
  12247. var i, row;
  12248. for (i = 0; i < height; i++) {
  12249. row = new Uint8Array(width);
  12250. if (defaultPixelValue) {
  12251. for (var j = 0; j < width; j++) {
  12252. row[j] = defaultPixelValue;
  12253. }
  12254. }
  12255. bitmap.push(row);
  12256. }
  12257. var decoder = decodingContext.decoder;
  12258. var contextCache = decodingContext.contextCache;
  12259. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  12260. var firstS = 0;
  12261. i = 0;
  12262. while (i < numberOfSymbolInstances) {
  12263. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  12264. stripT += deltaT;
  12265. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  12266. firstS += deltaFirstS;
  12267. var currentS = firstS;
  12268. do {
  12269. var currentT = (stripSize === 1 ? 0 :
  12270. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  12271. var t = stripSize * stripT + currentT;
  12272. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  12273. var applyRefinement = (refinement &&
  12274. decodeInteger(contextCache, 'IARI', decoder));
  12275. var symbolBitmap = inputSymbols[symbolId];
  12276. var symbolWidth = symbolBitmap[0].length;
  12277. var symbolHeight = symbolBitmap.length;
  12278. if (applyRefinement) {
  12279. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  12280. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  12281. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  12282. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  12283. symbolWidth += rdw;
  12284. symbolHeight += rdh;
  12285. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  12286. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  12287. (rdh >> 1) + rdy, false, refinementAt,
  12288. decodingContext);
  12289. }
  12290. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  12291. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  12292. var s2, t2, symbolRow;
  12293. if (transposed) {
  12294. // Place Symbol Bitmap from T1,S1
  12295. for (s2 = 0; s2 < symbolHeight; s2++) {
  12296. row = bitmap[offsetS + s2];
  12297. if (!row) {
  12298. continue;
  12299. }
  12300. symbolRow = symbolBitmap[s2];
  12301. // To ignore Parts of Symbol bitmap which goes
  12302. // outside bitmap region
  12303. var maxWidth = Math.min(width - offsetT, symbolWidth);
  12304. switch (combinationOperator) {
  12305. case 0: // OR
  12306. for (t2 = 0; t2 < maxWidth; t2++) {
  12307. row[offsetT + t2] |= symbolRow[t2];
  12308. }
  12309. break;
  12310. case 2: // XOR
  12311. for (t2 = 0; t2 < maxWidth; t2++) {
  12312. row[offsetT + t2] ^= symbolRow[t2];
  12313. }
  12314. break;
  12315. default:
  12316. error('JBIG2 error: operator ' + combinationOperator +
  12317. ' is not supported');
  12318. }
  12319. }
  12320. currentS += symbolHeight - 1;
  12321. } else {
  12322. for (t2 = 0; t2 < symbolHeight; t2++) {
  12323. row = bitmap[offsetT + t2];
  12324. if (!row) {
  12325. continue;
  12326. }
  12327. symbolRow = symbolBitmap[t2];
  12328. switch (combinationOperator) {
  12329. case 0: // OR
  12330. for (s2 = 0; s2 < symbolWidth; s2++) {
  12331. row[offsetS + s2] |= symbolRow[s2];
  12332. }
  12333. break;
  12334. case 2: // XOR
  12335. for (s2 = 0; s2 < symbolWidth; s2++) {
  12336. row[offsetS + s2] ^= symbolRow[s2];
  12337. }
  12338. break;
  12339. default:
  12340. error('JBIG2 error: operator ' + combinationOperator +
  12341. ' is not supported');
  12342. }
  12343. }
  12344. currentS += symbolWidth - 1;
  12345. }
  12346. i++;
  12347. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  12348. if (deltaS === null) {
  12349. break; // OOB
  12350. }
  12351. currentS += deltaS + dsOffset;
  12352. } while (true);
  12353. }
  12354. return bitmap;
  12355. }
  12356. function readSegmentHeader(data, start) {
  12357. var segmentHeader = {};
  12358. segmentHeader.number = readUint32(data, start);
  12359. var flags = data[start + 4];
  12360. var segmentType = flags & 0x3F;
  12361. if (!SegmentTypes[segmentType]) {
  12362. error('JBIG2 error: invalid segment type: ' + segmentType);
  12363. }
  12364. segmentHeader.type = segmentType;
  12365. segmentHeader.typeName = SegmentTypes[segmentType];
  12366. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  12367. var pageAssociationFieldSize = !!(flags & 0x40);
  12368. var referredFlags = data[start + 5];
  12369. var referredToCount = (referredFlags >> 5) & 7;
  12370. var retainBits = [referredFlags & 31];
  12371. var position = start + 6;
  12372. if (referredFlags === 7) {
  12373. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  12374. position += 3;
  12375. var bytes = (referredToCount + 7) >> 3;
  12376. retainBits[0] = data[position++];
  12377. while (--bytes > 0) {
  12378. retainBits.push(data[position++]);
  12379. }
  12380. } else if (referredFlags === 5 || referredFlags === 6) {
  12381. error('JBIG2 error: invalid referred-to flags');
  12382. }
  12383. segmentHeader.retainBits = retainBits;
  12384. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  12385. (segmentHeader.number <= 65536 ? 2 : 4));
  12386. var referredTo = [];
  12387. var i, ii;
  12388. for (i = 0; i < referredToCount; i++) {
  12389. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  12390. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  12391. readUint32(data, position)));
  12392. referredTo.push(number);
  12393. position += referredToSegmentNumberSize;
  12394. }
  12395. segmentHeader.referredTo = referredTo;
  12396. if (!pageAssociationFieldSize) {
  12397. segmentHeader.pageAssociation = data[position++];
  12398. } else {
  12399. segmentHeader.pageAssociation = readUint32(data, position);
  12400. position += 4;
  12401. }
  12402. segmentHeader.length = readUint32(data, position);
  12403. position += 4;
  12404. if (segmentHeader.length === 0xFFFFFFFF) {
  12405. // 7.2.7 Segment data length, unknown segment length
  12406. if (segmentType === 38) { // ImmediateGenericRegion
  12407. var genericRegionInfo = readRegionSegmentInformation(data, position);
  12408. var genericRegionSegmentFlags = data[position +
  12409. RegionSegmentInformationFieldLength];
  12410. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  12411. // searching for the segment end
  12412. var searchPatternLength = 6;
  12413. var searchPattern = new Uint8Array(searchPatternLength);
  12414. if (!genericRegionMmr) {
  12415. searchPattern[0] = 0xFF;
  12416. searchPattern[1] = 0xAC;
  12417. }
  12418. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  12419. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  12420. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  12421. searchPattern[5] = genericRegionInfo.height & 0xFF;
  12422. for (i = position, ii = data.length; i < ii; i++) {
  12423. var j = 0;
  12424. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  12425. j++;
  12426. }
  12427. if (j === searchPatternLength) {
  12428. segmentHeader.length = i + searchPatternLength;
  12429. break;
  12430. }
  12431. }
  12432. if (segmentHeader.length === 0xFFFFFFFF) {
  12433. error('JBIG2 error: segment end was not found');
  12434. }
  12435. } else {
  12436. error('JBIG2 error: invalid unknown segment length');
  12437. }
  12438. }
  12439. segmentHeader.headerEnd = position;
  12440. return segmentHeader;
  12441. }
  12442. function readSegments(header, data, start, end) {
  12443. var segments = [];
  12444. var position = start;
  12445. while (position < end) {
  12446. var segmentHeader = readSegmentHeader(data, position);
  12447. position = segmentHeader.headerEnd;
  12448. var segment = {
  12449. header: segmentHeader,
  12450. data: data
  12451. };
  12452. if (!header.randomAccess) {
  12453. segment.start = position;
  12454. position += segmentHeader.length;
  12455. segment.end = position;
  12456. }
  12457. segments.push(segment);
  12458. if (segmentHeader.type === 51) {
  12459. break; // end of file is found
  12460. }
  12461. }
  12462. if (header.randomAccess) {
  12463. for (var i = 0, ii = segments.length; i < ii; i++) {
  12464. segments[i].start = position;
  12465. position += segments[i].header.length;
  12466. segments[i].end = position;
  12467. }
  12468. }
  12469. return segments;
  12470. }
  12471. // 7.4.1 Region segment information field
  12472. function readRegionSegmentInformation(data, start) {
  12473. return {
  12474. width: readUint32(data, start),
  12475. height: readUint32(data, start + 4),
  12476. x: readUint32(data, start + 8),
  12477. y: readUint32(data, start + 12),
  12478. combinationOperator: data[start + 16] & 7
  12479. };
  12480. }
  12481. var RegionSegmentInformationFieldLength = 17;
  12482. function processSegment(segment, visitor) {
  12483. var header = segment.header;
  12484. var data = segment.data, position = segment.start, end = segment.end;
  12485. var args, at, i, atLength;
  12486. switch (header.type) {
  12487. case 0: // SymbolDictionary
  12488. // 7.4.2 Symbol dictionary segment syntax
  12489. var dictionary = {};
  12490. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  12491. dictionary.huffman = !!(dictionaryFlags & 1);
  12492. dictionary.refinement = !!(dictionaryFlags & 2);
  12493. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  12494. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  12495. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  12496. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  12497. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  12498. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  12499. dictionary.template = (dictionaryFlags >> 10) & 3;
  12500. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  12501. position += 2;
  12502. if (!dictionary.huffman) {
  12503. atLength = dictionary.template === 0 ? 4 : 1;
  12504. at = [];
  12505. for (i = 0; i < atLength; i++) {
  12506. at.push({
  12507. x: readInt8(data, position),
  12508. y: readInt8(data, position + 1)
  12509. });
  12510. position += 2;
  12511. }
  12512. dictionary.at = at;
  12513. }
  12514. if (dictionary.refinement && !dictionary.refinementTemplate) {
  12515. at = [];
  12516. for (i = 0; i < 2; i++) {
  12517. at.push({
  12518. x: readInt8(data, position),
  12519. y: readInt8(data, position + 1)
  12520. });
  12521. position += 2;
  12522. }
  12523. dictionary.refinementAt = at;
  12524. }
  12525. dictionary.numberOfExportedSymbols = readUint32(data, position);
  12526. position += 4;
  12527. dictionary.numberOfNewSymbols = readUint32(data, position);
  12528. position += 4;
  12529. args = [dictionary, header.number, header.referredTo,
  12530. data, position, end];
  12531. break;
  12532. case 6: // ImmediateTextRegion
  12533. case 7: // ImmediateLosslessTextRegion
  12534. var textRegion = {};
  12535. textRegion.info = readRegionSegmentInformation(data, position);
  12536. position += RegionSegmentInformationFieldLength;
  12537. var textRegionSegmentFlags = readUint16(data, position);
  12538. position += 2;
  12539. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  12540. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  12541. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  12542. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  12543. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  12544. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  12545. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  12546. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  12547. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  12548. if (textRegion.huffman) {
  12549. var textRegionHuffmanFlags = readUint16(data, position);
  12550. position += 2;
  12551. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  12552. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  12553. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  12554. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  12555. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  12556. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  12557. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  12558. textRegion.huffmanRefinementSizeSelector =
  12559. !!(textRegionHuffmanFlags & 14);
  12560. }
  12561. if (textRegion.refinement && !textRegion.refinementTemplate) {
  12562. at = [];
  12563. for (i = 0; i < 2; i++) {
  12564. at.push({
  12565. x: readInt8(data, position),
  12566. y: readInt8(data, position + 1)
  12567. });
  12568. position += 2;
  12569. }
  12570. textRegion.refinementAt = at;
  12571. }
  12572. textRegion.numberOfSymbolInstances = readUint32(data, position);
  12573. position += 4;
  12574. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  12575. if (textRegion.huffman) {
  12576. error('JBIG2 error: huffman is not supported');
  12577. }
  12578. args = [textRegion, header.referredTo, data, position, end];
  12579. break;
  12580. case 38: // ImmediateGenericRegion
  12581. case 39: // ImmediateLosslessGenericRegion
  12582. var genericRegion = {};
  12583. genericRegion.info = readRegionSegmentInformation(data, position);
  12584. position += RegionSegmentInformationFieldLength;
  12585. var genericRegionSegmentFlags = data[position++];
  12586. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  12587. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  12588. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  12589. if (!genericRegion.mmr) {
  12590. atLength = genericRegion.template === 0 ? 4 : 1;
  12591. at = [];
  12592. for (i = 0; i < atLength; i++) {
  12593. at.push({
  12594. x: readInt8(data, position),
  12595. y: readInt8(data, position + 1)
  12596. });
  12597. position += 2;
  12598. }
  12599. genericRegion.at = at;
  12600. }
  12601. args = [genericRegion, data, position, end];
  12602. break;
  12603. case 48: // PageInformation
  12604. var pageInfo = {
  12605. width: readUint32(data, position),
  12606. height: readUint32(data, position + 4),
  12607. resolutionX: readUint32(data, position + 8),
  12608. resolutionY: readUint32(data, position + 12)
  12609. };
  12610. if (pageInfo.height === 0xFFFFFFFF) {
  12611. delete pageInfo.height;
  12612. }
  12613. var pageSegmentFlags = data[position + 16];
  12614. var pageStripingInformation = readUint16(data, position + 17);
  12615. pageInfo.lossless = !!(pageSegmentFlags & 1);
  12616. pageInfo.refinement = !!(pageSegmentFlags & 2);
  12617. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  12618. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  12619. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  12620. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  12621. args = [pageInfo];
  12622. break;
  12623. case 49: // EndOfPage
  12624. break;
  12625. case 50: // EndOfStripe
  12626. break;
  12627. case 51: // EndOfFile
  12628. break;
  12629. case 62: // 7.4.15 defines 2 extension types which
  12630. // are comments and can be ignored.
  12631. break;
  12632. default:
  12633. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12634. header.type + ') is not implemented');
  12635. }
  12636. var callbackName = 'on' + header.typeName;
  12637. if (callbackName in visitor) {
  12638. visitor[callbackName].apply(visitor, args);
  12639. }
  12640. }
  12641. function processSegments(segments, visitor) {
  12642. for (var i = 0, ii = segments.length; i < ii; i++) {
  12643. processSegment(segments[i], visitor);
  12644. }
  12645. }
  12646. function parseJbig2(data, start, end) {
  12647. var position = start;
  12648. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12649. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12650. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12651. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12652. error('JBIG2 error: invalid header');
  12653. }
  12654. var header = {};
  12655. position += 8;
  12656. var flags = data[position++];
  12657. header.randomAccess = !(flags & 1);
  12658. if (!(flags & 2)) {
  12659. header.numberOfPages = readUint32(data, position);
  12660. position += 4;
  12661. }
  12662. var segments = readSegments(header, data, position, end);
  12663. error('Not implemented');
  12664. // processSegments(segments, new SimpleSegmentVisitor());
  12665. }
  12666. function parseJbig2Chunks(chunks) {
  12667. var visitor = new SimpleSegmentVisitor();
  12668. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12669. var chunk = chunks[i];
  12670. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12671. processSegments(segments, visitor);
  12672. }
  12673. return visitor.buffer;
  12674. }
  12675. function SimpleSegmentVisitor() {}
  12676. SimpleSegmentVisitor.prototype = {
  12677. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12678. this.currentPageInfo = info;
  12679. var rowSize = (info.width + 7) >> 3;
  12680. var buffer = new Uint8Array(rowSize * info.height);
  12681. // The contents of ArrayBuffers are initialized to 0.
  12682. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12683. if (info.defaultPixelValue) {
  12684. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12685. buffer[i] = 0xFF;
  12686. }
  12687. }
  12688. this.buffer = buffer;
  12689. },
  12690. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12691. var pageInfo = this.currentPageInfo;
  12692. var width = regionInfo.width, height = regionInfo.height;
  12693. var rowSize = (pageInfo.width + 7) >> 3;
  12694. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12695. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12696. var buffer = this.buffer;
  12697. var mask0 = 128 >> (regionInfo.x & 7);
  12698. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12699. var i, j, mask, offset;
  12700. switch (combinationOperator) {
  12701. case 0: // OR
  12702. for (i = 0; i < height; i++) {
  12703. mask = mask0;
  12704. offset = offset0;
  12705. for (j = 0; j < width; j++) {
  12706. if (bitmap[i][j]) {
  12707. buffer[offset] |= mask;
  12708. }
  12709. mask >>= 1;
  12710. if (!mask) {
  12711. mask = 128;
  12712. offset++;
  12713. }
  12714. }
  12715. offset0 += rowSize;
  12716. }
  12717. break;
  12718. case 2: // XOR
  12719. for (i = 0; i < height; i++) {
  12720. mask = mask0;
  12721. offset = offset0;
  12722. for (j = 0; j < width; j++) {
  12723. if (bitmap[i][j]) {
  12724. buffer[offset] ^= mask;
  12725. }
  12726. mask >>= 1;
  12727. if (!mask) {
  12728. mask = 128;
  12729. offset++;
  12730. }
  12731. }
  12732. offset0 += rowSize;
  12733. }
  12734. break;
  12735. default:
  12736. error('JBIG2 error: operator ' + combinationOperator +
  12737. ' is not supported');
  12738. }
  12739. },
  12740. onImmediateGenericRegion:
  12741. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12742. start, end) {
  12743. var regionInfo = region.info;
  12744. var decodingContext = new DecodingContext(data, start, end);
  12745. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12746. region.template, region.prediction, null,
  12747. region.at, decodingContext);
  12748. this.drawBitmap(regionInfo, bitmap);
  12749. },
  12750. onImmediateLosslessGenericRegion:
  12751. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12752. this.onImmediateGenericRegion.apply(this, arguments);
  12753. },
  12754. onSymbolDictionary:
  12755. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12756. currentSegment,
  12757. referredSegments,
  12758. data, start, end) {
  12759. var huffmanTables;
  12760. if (dictionary.huffman) {
  12761. error('JBIG2 error: huffman is not supported');
  12762. }
  12763. // Combines exported symbols from all referred segments
  12764. var symbols = this.symbols;
  12765. if (!symbols) {
  12766. this.symbols = symbols = {};
  12767. }
  12768. var inputSymbols = [];
  12769. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12770. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12771. }
  12772. var decodingContext = new DecodingContext(data, start, end);
  12773. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12774. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12775. dictionary.numberOfExportedSymbols, huffmanTables,
  12776. dictionary.template, dictionary.at,
  12777. dictionary.refinementTemplate, dictionary.refinementAt,
  12778. decodingContext);
  12779. },
  12780. onImmediateTextRegion:
  12781. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12782. referredSegments,
  12783. data, start, end) {
  12784. var regionInfo = region.info;
  12785. var huffmanTables;
  12786. // Combines exported symbols from all referred segments
  12787. var symbols = this.symbols;
  12788. var inputSymbols = [];
  12789. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12790. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12791. }
  12792. var symbolCodeLength = log2(inputSymbols.length);
  12793. var decodingContext = new DecodingContext(data, start, end);
  12794. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12795. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12796. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12797. symbolCodeLength, region.transposed, region.dsOffset,
  12798. region.referenceCorner, region.combinationOperator, huffmanTables,
  12799. region.refinementTemplate, region.refinementAt, decodingContext);
  12800. this.drawBitmap(regionInfo, bitmap);
  12801. },
  12802. onImmediateLosslessTextRegion:
  12803. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12804. this.onImmediateTextRegion.apply(this, arguments);
  12805. }
  12806. };
  12807. function Jbig2Image() {}
  12808. Jbig2Image.prototype = {
  12809. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12810. return parseJbig2Chunks(chunks);
  12811. }
  12812. };
  12813. return Jbig2Image;
  12814. })();
  12815. exports.Jbig2Image = Jbig2Image;
  12816. }));
  12817. (function (root, factory) {
  12818. {
  12819. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12820. root.pdfjsCoreArithmeticDecoder);
  12821. }
  12822. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12823. var info = sharedUtil.info;
  12824. var log2 = sharedUtil.log2;
  12825. var readUint16 = sharedUtil.readUint16;
  12826. var readUint32 = sharedUtil.readUint32;
  12827. var warn = sharedUtil.warn;
  12828. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12829. var JpxImage = (function JpxImageClosure() {
  12830. // Table E.1
  12831. var SubbandsGainLog2 = {
  12832. 'LL': 0,
  12833. 'LH': 1,
  12834. 'HL': 1,
  12835. 'HH': 2
  12836. };
  12837. function JpxImage() {
  12838. this.failOnCorruptedImage = false;
  12839. }
  12840. JpxImage.prototype = {
  12841. parse: function JpxImage_parse(data) {
  12842. var head = readUint16(data, 0);
  12843. // No box header, immediate start of codestream (SOC)
  12844. if (head === 0xFF4F) {
  12845. this.parseCodestream(data, 0, data.length);
  12846. return;
  12847. }
  12848. var position = 0, length = data.length;
  12849. while (position < length) {
  12850. var headerSize = 8;
  12851. var lbox = readUint32(data, position);
  12852. var tbox = readUint32(data, position + 4);
  12853. position += headerSize;
  12854. if (lbox === 1) {
  12855. // XLBox: read UInt64 according to spec.
  12856. // JavaScript's int precision of 53 bit should be sufficient here.
  12857. lbox = readUint32(data, position) * 4294967296 +
  12858. readUint32(data, position + 4);
  12859. position += 8;
  12860. headerSize += 8;
  12861. }
  12862. if (lbox === 0) {
  12863. lbox = length - position + headerSize;
  12864. }
  12865. if (lbox < headerSize) {
  12866. throw new Error('JPX Error: Invalid box field size');
  12867. }
  12868. var dataLength = lbox - headerSize;
  12869. var jumpDataLength = true;
  12870. switch (tbox) {
  12871. case 0x6A703268: // 'jp2h'
  12872. jumpDataLength = false; // parsing child boxes
  12873. break;
  12874. case 0x636F6C72: // 'colr'
  12875. // Colorspaces are not used, the CS from the PDF is used.
  12876. var method = data[position];
  12877. if (method === 1) {
  12878. // enumerated colorspace
  12879. var colorspace = readUint32(data, position + 3);
  12880. switch (colorspace) {
  12881. case 16: // this indicates a sRGB colorspace
  12882. case 17: // this indicates a grayscale colorspace
  12883. case 18: // this indicates a YUV colorspace
  12884. break;
  12885. default:
  12886. warn('Unknown colorspace ' + colorspace);
  12887. break;
  12888. }
  12889. } else if (method === 2) {
  12890. info('ICC profile not supported');
  12891. }
  12892. break;
  12893. case 0x6A703263: // 'jp2c'
  12894. this.parseCodestream(data, position, position + dataLength);
  12895. break;
  12896. case 0x6A502020: // 'jP\024\024'
  12897. if (0x0d0a870a !== readUint32(data, position)) {
  12898. warn('Invalid JP2 signature');
  12899. }
  12900. break;
  12901. // The following header types are valid but currently not used:
  12902. case 0x6A501A1A: // 'jP\032\032'
  12903. case 0x66747970: // 'ftyp'
  12904. case 0x72726571: // 'rreq'
  12905. case 0x72657320: // 'res '
  12906. case 0x69686472: // 'ihdr'
  12907. break;
  12908. default:
  12909. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12910. (tbox >> 16) & 0xFF,
  12911. (tbox >> 8) & 0xFF,
  12912. tbox & 0xFF);
  12913. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12914. break;
  12915. }
  12916. if (jumpDataLength) {
  12917. position += dataLength;
  12918. }
  12919. }
  12920. },
  12921. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12922. var newByte = stream.getByte();
  12923. while (newByte >= 0) {
  12924. var oldByte = newByte;
  12925. newByte = stream.getByte();
  12926. var code = (oldByte << 8) | newByte;
  12927. // Image and tile size (SIZ)
  12928. if (code === 0xFF51) {
  12929. stream.skip(4);
  12930. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12931. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12932. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12933. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12934. stream.skip(16);
  12935. var Csiz = stream.getUint16(); // Byte 36
  12936. this.width = Xsiz - XOsiz;
  12937. this.height = Ysiz - YOsiz;
  12938. this.componentsCount = Csiz;
  12939. // Results are always returned as Uint8Arrays
  12940. this.bitsPerComponent = 8;
  12941. return;
  12942. }
  12943. }
  12944. throw new Error('JPX Error: No size marker found in JPX stream');
  12945. },
  12946. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12947. var context = {};
  12948. try {
  12949. var doNotRecover = false;
  12950. var position = start;
  12951. while (position + 1 < end) {
  12952. var code = readUint16(data, position);
  12953. position += 2;
  12954. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12955. switch (code) {
  12956. case 0xFF4F: // Start of codestream (SOC)
  12957. context.mainHeader = true;
  12958. break;
  12959. case 0xFFD9: // End of codestream (EOC)
  12960. break;
  12961. case 0xFF51: // Image and tile size (SIZ)
  12962. length = readUint16(data, position);
  12963. var siz = {};
  12964. siz.Xsiz = readUint32(data, position + 4);
  12965. siz.Ysiz = readUint32(data, position + 8);
  12966. siz.XOsiz = readUint32(data, position + 12);
  12967. siz.YOsiz = readUint32(data, position + 16);
  12968. siz.XTsiz = readUint32(data, position + 20);
  12969. siz.YTsiz = readUint32(data, position + 24);
  12970. siz.XTOsiz = readUint32(data, position + 28);
  12971. siz.YTOsiz = readUint32(data, position + 32);
  12972. var componentsCount = readUint16(data, position + 36);
  12973. siz.Csiz = componentsCount;
  12974. var components = [];
  12975. j = position + 38;
  12976. for (var i = 0; i < componentsCount; i++) {
  12977. var component = {
  12978. precision: (data[j] & 0x7F) + 1,
  12979. isSigned: !!(data[j] & 0x80),
  12980. XRsiz: data[j + 1],
  12981. YRsiz: data[j + 1]
  12982. };
  12983. calculateComponentDimensions(component, siz);
  12984. components.push(component);
  12985. }
  12986. context.SIZ = siz;
  12987. context.components = components;
  12988. calculateTileGrids(context, components);
  12989. context.QCC = [];
  12990. context.COC = [];
  12991. break;
  12992. case 0xFF5C: // Quantization default (QCD)
  12993. length = readUint16(data, position);
  12994. var qcd = {};
  12995. j = position + 2;
  12996. sqcd = data[j++];
  12997. switch (sqcd & 0x1F) {
  12998. case 0:
  12999. spqcdSize = 8;
  13000. scalarExpounded = true;
  13001. break;
  13002. case 1:
  13003. spqcdSize = 16;
  13004. scalarExpounded = false;
  13005. break;
  13006. case 2:
  13007. spqcdSize = 16;
  13008. scalarExpounded = true;
  13009. break;
  13010. default:
  13011. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  13012. }
  13013. qcd.noQuantization = (spqcdSize === 8);
  13014. qcd.scalarExpounded = scalarExpounded;
  13015. qcd.guardBits = sqcd >> 5;
  13016. spqcds = [];
  13017. while (j < length + position) {
  13018. var spqcd = {};
  13019. if (spqcdSize === 8) {
  13020. spqcd.epsilon = data[j++] >> 3;
  13021. spqcd.mu = 0;
  13022. } else {
  13023. spqcd.epsilon = data[j] >> 3;
  13024. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  13025. j += 2;
  13026. }
  13027. spqcds.push(spqcd);
  13028. }
  13029. qcd.SPqcds = spqcds;
  13030. if (context.mainHeader) {
  13031. context.QCD = qcd;
  13032. } else {
  13033. context.currentTile.QCD = qcd;
  13034. context.currentTile.QCC = [];
  13035. }
  13036. break;
  13037. case 0xFF5D: // Quantization component (QCC)
  13038. length = readUint16(data, position);
  13039. var qcc = {};
  13040. j = position + 2;
  13041. var cqcc;
  13042. if (context.SIZ.Csiz < 257) {
  13043. cqcc = data[j++];
  13044. } else {
  13045. cqcc = readUint16(data, j);
  13046. j += 2;
  13047. }
  13048. sqcd = data[j++];
  13049. switch (sqcd & 0x1F) {
  13050. case 0:
  13051. spqcdSize = 8;
  13052. scalarExpounded = true;
  13053. break;
  13054. case 1:
  13055. spqcdSize = 16;
  13056. scalarExpounded = false;
  13057. break;
  13058. case 2:
  13059. spqcdSize = 16;
  13060. scalarExpounded = true;
  13061. break;
  13062. default:
  13063. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  13064. }
  13065. qcc.noQuantization = (spqcdSize === 8);
  13066. qcc.scalarExpounded = scalarExpounded;
  13067. qcc.guardBits = sqcd >> 5;
  13068. spqcds = [];
  13069. while (j < (length + position)) {
  13070. spqcd = {};
  13071. if (spqcdSize === 8) {
  13072. spqcd.epsilon = data[j++] >> 3;
  13073. spqcd.mu = 0;
  13074. } else {
  13075. spqcd.epsilon = data[j] >> 3;
  13076. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  13077. j += 2;
  13078. }
  13079. spqcds.push(spqcd);
  13080. }
  13081. qcc.SPqcds = spqcds;
  13082. if (context.mainHeader) {
  13083. context.QCC[cqcc] = qcc;
  13084. } else {
  13085. context.currentTile.QCC[cqcc] = qcc;
  13086. }
  13087. break;
  13088. case 0xFF52: // Coding style default (COD)
  13089. length = readUint16(data, position);
  13090. var cod = {};
  13091. j = position + 2;
  13092. var scod = data[j++];
  13093. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  13094. cod.sopMarkerUsed = !!(scod & 2);
  13095. cod.ephMarkerUsed = !!(scod & 4);
  13096. cod.progressionOrder = data[j++];
  13097. cod.layersCount = readUint16(data, j);
  13098. j += 2;
  13099. cod.multipleComponentTransform = data[j++];
  13100. cod.decompositionLevelsCount = data[j++];
  13101. cod.xcb = (data[j++] & 0xF) + 2;
  13102. cod.ycb = (data[j++] & 0xF) + 2;
  13103. var blockStyle = data[j++];
  13104. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  13105. cod.resetContextProbabilities = !!(blockStyle & 2);
  13106. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  13107. cod.verticalyStripe = !!(blockStyle & 8);
  13108. cod.predictableTermination = !!(blockStyle & 16);
  13109. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  13110. cod.reversibleTransformation = data[j++];
  13111. if (cod.entropyCoderWithCustomPrecincts) {
  13112. var precinctsSizes = [];
  13113. while (j < length + position) {
  13114. var precinctsSize = data[j++];
  13115. precinctsSizes.push({
  13116. PPx: precinctsSize & 0xF,
  13117. PPy: precinctsSize >> 4
  13118. });
  13119. }
  13120. cod.precinctsSizes = precinctsSizes;
  13121. }
  13122. var unsupported = [];
  13123. if (cod.selectiveArithmeticCodingBypass) {
  13124. unsupported.push('selectiveArithmeticCodingBypass');
  13125. }
  13126. if (cod.resetContextProbabilities) {
  13127. unsupported.push('resetContextProbabilities');
  13128. }
  13129. if (cod.terminationOnEachCodingPass) {
  13130. unsupported.push('terminationOnEachCodingPass');
  13131. }
  13132. if (cod.verticalyStripe) {
  13133. unsupported.push('verticalyStripe');
  13134. }
  13135. if (cod.predictableTermination) {
  13136. unsupported.push('predictableTermination');
  13137. }
  13138. if (unsupported.length > 0) {
  13139. doNotRecover = true;
  13140. throw new Error('JPX Error: Unsupported COD options (' +
  13141. unsupported.join(', ') + ')');
  13142. }
  13143. if (context.mainHeader) {
  13144. context.COD = cod;
  13145. } else {
  13146. context.currentTile.COD = cod;
  13147. context.currentTile.COC = [];
  13148. }
  13149. break;
  13150. case 0xFF90: // Start of tile-part (SOT)
  13151. length = readUint16(data, position);
  13152. tile = {};
  13153. tile.index = readUint16(data, position + 2);
  13154. tile.length = readUint32(data, position + 4);
  13155. tile.dataEnd = tile.length + position - 2;
  13156. tile.partIndex = data[position + 8];
  13157. tile.partsCount = data[position + 9];
  13158. context.mainHeader = false;
  13159. if (tile.partIndex === 0) {
  13160. // reset component specific settings
  13161. tile.COD = context.COD;
  13162. tile.COC = context.COC.slice(0); // clone of the global COC
  13163. tile.QCD = context.QCD;
  13164. tile.QCC = context.QCC.slice(0); // clone of the global COC
  13165. }
  13166. context.currentTile = tile;
  13167. break;
  13168. case 0xFF93: // Start of data (SOD)
  13169. tile = context.currentTile;
  13170. if (tile.partIndex === 0) {
  13171. initializeTile(context, tile.index);
  13172. buildPackets(context);
  13173. }
  13174. // moving to the end of the data
  13175. length = tile.dataEnd - position;
  13176. parseTilePackets(context, data, position, length);
  13177. break;
  13178. case 0xFF55: // Tile-part lengths, main header (TLM)
  13179. case 0xFF57: // Packet length, main header (PLM)
  13180. case 0xFF58: // Packet length, tile-part header (PLT)
  13181. case 0xFF64: // Comment (COM)
  13182. length = readUint16(data, position);
  13183. // skipping content
  13184. break;
  13185. case 0xFF53: // Coding style component (COC)
  13186. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  13187. 'not implemented');
  13188. default:
  13189. throw new Error('JPX Error: Unknown codestream code: ' +
  13190. code.toString(16));
  13191. }
  13192. position += length;
  13193. }
  13194. } catch (e) {
  13195. if (doNotRecover || this.failOnCorruptedImage) {
  13196. throw e;
  13197. } else {
  13198. warn('Trying to recover from ' + e.message);
  13199. }
  13200. }
  13201. this.tiles = transformComponents(context);
  13202. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  13203. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  13204. this.componentsCount = context.SIZ.Csiz;
  13205. }
  13206. };
  13207. function calculateComponentDimensions(component, siz) {
  13208. // Section B.2 Component mapping
  13209. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  13210. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  13211. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  13212. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  13213. component.width = component.x1 - component.x0;
  13214. component.height = component.y1 - component.y0;
  13215. }
  13216. function calculateTileGrids(context, components) {
  13217. var siz = context.SIZ;
  13218. // Section B.3 Division into tile and tile-components
  13219. var tile, tiles = [];
  13220. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  13221. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  13222. for (var q = 0; q < numYtiles; q++) {
  13223. for (var p = 0; p < numXtiles; p++) {
  13224. tile = {};
  13225. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  13226. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  13227. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  13228. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  13229. tile.width = tile.tx1 - tile.tx0;
  13230. tile.height = tile.ty1 - tile.ty0;
  13231. tile.components = [];
  13232. tiles.push(tile);
  13233. }
  13234. }
  13235. context.tiles = tiles;
  13236. var componentsCount = siz.Csiz;
  13237. for (var i = 0, ii = componentsCount; i < ii; i++) {
  13238. var component = components[i];
  13239. for (var j = 0, jj = tiles.length; j < jj; j++) {
  13240. var tileComponent = {};
  13241. tile = tiles[j];
  13242. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  13243. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  13244. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  13245. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  13246. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  13247. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  13248. tile.components[i] = tileComponent;
  13249. }
  13250. }
  13251. }
  13252. function getBlocksDimensions(context, component, r) {
  13253. var codOrCoc = component.codingStyleParameters;
  13254. var result = {};
  13255. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  13256. result.PPx = 15;
  13257. result.PPy = 15;
  13258. } else {
  13259. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  13260. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  13261. }
  13262. // calculate codeblock size as described in section B.7
  13263. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  13264. Math.min(codOrCoc.xcb, result.PPx));
  13265. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  13266. Math.min(codOrCoc.ycb, result.PPy));
  13267. return result;
  13268. }
  13269. function buildPrecincts(context, resolution, dimensions) {
  13270. // Section B.6 Division resolution to precincts
  13271. var precinctWidth = 1 << dimensions.PPx;
  13272. var precinctHeight = 1 << dimensions.PPy;
  13273. // Jasper introduces codeblock groups for mapping each subband codeblocks
  13274. // to precincts. Precinct partition divides a resolution according to width
  13275. // and height parameters. The subband that belongs to the resolution level
  13276. // has a different size than the level, unless it is the zero resolution.
  13277. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  13278. // The precinct partitioning for a particular subband is derived from a
  13279. // partitioning of its parent LL band (i.e., the LL band at the next higher
  13280. // resolution level)... The LL band associated with each resolution level is
  13281. // divided into precincts... Each of the resulting precinct regions is then
  13282. // mapped into its child subbands (if any) at the next lower resolution
  13283. // level. This is accomplished by using the coordinate transformation
  13284. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  13285. // coordinates of a point in the LL band and child subband, respectively.
  13286. var isZeroRes = resolution.resLevel === 0;
  13287. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  13288. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  13289. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  13290. Math.ceil(resolution.trx1 / precinctWidth) -
  13291. Math.floor(resolution.trx0 / precinctWidth) : 0);
  13292. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  13293. Math.ceil(resolution.try1 / precinctHeight) -
  13294. Math.floor(resolution.try0 / precinctHeight) : 0);
  13295. var numprecincts = numprecinctswide * numprecinctshigh;
  13296. resolution.precinctParameters = {
  13297. precinctWidth: precinctWidth,
  13298. precinctHeight: precinctHeight,
  13299. numprecinctswide: numprecinctswide,
  13300. numprecinctshigh: numprecinctshigh,
  13301. numprecincts: numprecincts,
  13302. precinctWidthInSubband: precinctWidthInSubband,
  13303. precinctHeightInSubband: precinctHeightInSubband
  13304. };
  13305. }
  13306. function buildCodeblocks(context, subband, dimensions) {
  13307. // Section B.7 Division sub-band into code-blocks
  13308. var xcb_ = dimensions.xcb_;
  13309. var ycb_ = dimensions.ycb_;
  13310. var codeblockWidth = 1 << xcb_;
  13311. var codeblockHeight = 1 << ycb_;
  13312. var cbx0 = subband.tbx0 >> xcb_;
  13313. var cby0 = subband.tby0 >> ycb_;
  13314. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  13315. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  13316. var precinctParameters = subband.resolution.precinctParameters;
  13317. var codeblocks = [];
  13318. var precincts = [];
  13319. var i, j, codeblock, precinctNumber;
  13320. for (j = cby0; j < cby1; j++) {
  13321. for (i = cbx0; i < cbx1; i++) {
  13322. codeblock = {
  13323. cbx: i,
  13324. cby: j,
  13325. tbx0: codeblockWidth * i,
  13326. tby0: codeblockHeight * j,
  13327. tbx1: codeblockWidth * (i + 1),
  13328. tby1: codeblockHeight * (j + 1)
  13329. };
  13330. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  13331. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  13332. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  13333. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  13334. // Calculate precinct number for this codeblock, codeblock position
  13335. // should be relative to its subband, use actual dimension and position
  13336. // See comment about codeblock group width and height
  13337. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  13338. precinctParameters.precinctWidthInSubband);
  13339. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  13340. precinctParameters.precinctHeightInSubband);
  13341. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  13342. codeblock.precinctNumber = precinctNumber;
  13343. codeblock.subbandType = subband.type;
  13344. codeblock.Lblock = 3;
  13345. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  13346. codeblock.tby1_ <= codeblock.tby0_) {
  13347. continue;
  13348. }
  13349. codeblocks.push(codeblock);
  13350. // building precinct for the sub-band
  13351. var precinct = precincts[precinctNumber];
  13352. if (precinct !== undefined) {
  13353. if (i < precinct.cbxMin) {
  13354. precinct.cbxMin = i;
  13355. } else if (i > precinct.cbxMax) {
  13356. precinct.cbxMax = i;
  13357. }
  13358. if (j < precinct.cbyMin) {
  13359. precinct.cbxMin = j;
  13360. } else if (j > precinct.cbyMax) {
  13361. precinct.cbyMax = j;
  13362. }
  13363. } else {
  13364. precincts[precinctNumber] = precinct = {
  13365. cbxMin: i,
  13366. cbyMin: j,
  13367. cbxMax: i,
  13368. cbyMax: j
  13369. };
  13370. }
  13371. codeblock.precinct = precinct;
  13372. }
  13373. }
  13374. subband.codeblockParameters = {
  13375. codeblockWidth: xcb_,
  13376. codeblockHeight: ycb_,
  13377. numcodeblockwide: cbx1 - cbx0 + 1,
  13378. numcodeblockhigh: cby1 - cby0 + 1
  13379. };
  13380. subband.codeblocks = codeblocks;
  13381. subband.precincts = precincts;
  13382. }
  13383. function createPacket(resolution, precinctNumber, layerNumber) {
  13384. var precinctCodeblocks = [];
  13385. // Section B.10.8 Order of info in packet
  13386. var subbands = resolution.subbands;
  13387. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  13388. for (var i = 0, ii = subbands.length; i < ii; i++) {
  13389. var subband = subbands[i];
  13390. var codeblocks = subband.codeblocks;
  13391. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  13392. var codeblock = codeblocks[j];
  13393. if (codeblock.precinctNumber !== precinctNumber) {
  13394. continue;
  13395. }
  13396. precinctCodeblocks.push(codeblock);
  13397. }
  13398. }
  13399. return {
  13400. layerNumber: layerNumber,
  13401. codeblocks: precinctCodeblocks
  13402. };
  13403. }
  13404. function LayerResolutionComponentPositionIterator(context) {
  13405. var siz = context.SIZ;
  13406. var tileIndex = context.currentTile.index;
  13407. var tile = context.tiles[tileIndex];
  13408. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13409. var componentsCount = siz.Csiz;
  13410. var maxDecompositionLevelsCount = 0;
  13411. for (var q = 0; q < componentsCount; q++) {
  13412. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  13413. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  13414. }
  13415. var l = 0, r = 0, i = 0, k = 0;
  13416. this.nextPacket = function JpxImage_nextPacket() {
  13417. // Section B.12.1.1 Layer-resolution-component-position
  13418. for (; l < layersCount; l++) {
  13419. for (; r <= maxDecompositionLevelsCount; r++) {
  13420. for (; i < componentsCount; i++) {
  13421. var component = tile.components[i];
  13422. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  13423. continue;
  13424. }
  13425. var resolution = component.resolutions[r];
  13426. var numprecincts = resolution.precinctParameters.numprecincts;
  13427. for (; k < numprecincts;) {
  13428. var packet = createPacket(resolution, k, l);
  13429. k++;
  13430. return packet;
  13431. }
  13432. k = 0;
  13433. }
  13434. i = 0;
  13435. }
  13436. r = 0;
  13437. }
  13438. throw new Error('JPX Error: Out of packets');
  13439. };
  13440. }
  13441. function ResolutionLayerComponentPositionIterator(context) {
  13442. var siz = context.SIZ;
  13443. var tileIndex = context.currentTile.index;
  13444. var tile = context.tiles[tileIndex];
  13445. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13446. var componentsCount = siz.Csiz;
  13447. var maxDecompositionLevelsCount = 0;
  13448. for (var q = 0; q < componentsCount; q++) {
  13449. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  13450. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  13451. }
  13452. var r = 0, l = 0, i = 0, k = 0;
  13453. this.nextPacket = function JpxImage_nextPacket() {
  13454. // Section B.12.1.2 Resolution-layer-component-position
  13455. for (; r <= maxDecompositionLevelsCount; r++) {
  13456. for (; l < layersCount; l++) {
  13457. for (; i < componentsCount; i++) {
  13458. var component = tile.components[i];
  13459. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  13460. continue;
  13461. }
  13462. var resolution = component.resolutions[r];
  13463. var numprecincts = resolution.precinctParameters.numprecincts;
  13464. for (; k < numprecincts;) {
  13465. var packet = createPacket(resolution, k, l);
  13466. k++;
  13467. return packet;
  13468. }
  13469. k = 0;
  13470. }
  13471. i = 0;
  13472. }
  13473. l = 0;
  13474. }
  13475. throw new Error('JPX Error: Out of packets');
  13476. };
  13477. }
  13478. function ResolutionPositionComponentLayerIterator(context) {
  13479. var siz = context.SIZ;
  13480. var tileIndex = context.currentTile.index;
  13481. var tile = context.tiles[tileIndex];
  13482. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13483. var componentsCount = siz.Csiz;
  13484. var l, r, c, p;
  13485. var maxDecompositionLevelsCount = 0;
  13486. for (c = 0; c < componentsCount; c++) {
  13487. var component = tile.components[c];
  13488. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  13489. component.codingStyleParameters.decompositionLevelsCount);
  13490. }
  13491. var maxNumPrecinctsInLevel = new Int32Array(
  13492. maxDecompositionLevelsCount + 1);
  13493. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  13494. var maxNumPrecincts = 0;
  13495. for (c = 0; c < componentsCount; ++c) {
  13496. var resolutions = tile.components[c].resolutions;
  13497. if (r < resolutions.length) {
  13498. maxNumPrecincts = Math.max(maxNumPrecincts,
  13499. resolutions[r].precinctParameters.numprecincts);
  13500. }
  13501. }
  13502. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  13503. }
  13504. l = 0;
  13505. r = 0;
  13506. c = 0;
  13507. p = 0;
  13508. this.nextPacket = function JpxImage_nextPacket() {
  13509. // Section B.12.1.3 Resolution-position-component-layer
  13510. for (; r <= maxDecompositionLevelsCount; r++) {
  13511. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  13512. for (; c < componentsCount; c++) {
  13513. var component = tile.components[c];
  13514. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  13515. continue;
  13516. }
  13517. var resolution = component.resolutions[r];
  13518. var numprecincts = resolution.precinctParameters.numprecincts;
  13519. if (p >= numprecincts) {
  13520. continue;
  13521. }
  13522. for (; l < layersCount;) {
  13523. var packet = createPacket(resolution, p, l);
  13524. l++;
  13525. return packet;
  13526. }
  13527. l = 0;
  13528. }
  13529. c = 0;
  13530. }
  13531. p = 0;
  13532. }
  13533. throw new Error('JPX Error: Out of packets');
  13534. };
  13535. }
  13536. function PositionComponentResolutionLayerIterator(context) {
  13537. var siz = context.SIZ;
  13538. var tileIndex = context.currentTile.index;
  13539. var tile = context.tiles[tileIndex];
  13540. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13541. var componentsCount = siz.Csiz;
  13542. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  13543. var precinctsIterationSizes = precinctsSizes;
  13544. var l = 0, r = 0, c = 0, px = 0, py = 0;
  13545. this.nextPacket = function JpxImage_nextPacket() {
  13546. // Section B.12.1.4 Position-component-resolution-layer
  13547. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  13548. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  13549. for (; c < componentsCount; c++) {
  13550. var component = tile.components[c];
  13551. var decompositionLevelsCount =
  13552. component.codingStyleParameters.decompositionLevelsCount;
  13553. for (; r <= decompositionLevelsCount; r++) {
  13554. var resolution = component.resolutions[r];
  13555. var sizeInImageScale =
  13556. precinctsSizes.components[c].resolutions[r];
  13557. var k = getPrecinctIndexIfExist(
  13558. px,
  13559. py,
  13560. sizeInImageScale,
  13561. precinctsIterationSizes,
  13562. resolution);
  13563. if (k === null) {
  13564. continue;
  13565. }
  13566. for (; l < layersCount;) {
  13567. var packet = createPacket(resolution, k, l);
  13568. l++;
  13569. return packet;
  13570. }
  13571. l = 0;
  13572. }
  13573. r = 0;
  13574. }
  13575. c = 0;
  13576. }
  13577. px = 0;
  13578. }
  13579. throw new Error('JPX Error: Out of packets');
  13580. };
  13581. }
  13582. function ComponentPositionResolutionLayerIterator(context) {
  13583. var siz = context.SIZ;
  13584. var tileIndex = context.currentTile.index;
  13585. var tile = context.tiles[tileIndex];
  13586. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13587. var componentsCount = siz.Csiz;
  13588. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  13589. var l = 0, r = 0, c = 0, px = 0, py = 0;
  13590. this.nextPacket = function JpxImage_nextPacket() {
  13591. // Section B.12.1.5 Component-position-resolution-layer
  13592. for (; c < componentsCount; ++c) {
  13593. var component = tile.components[c];
  13594. var precinctsIterationSizes = precinctsSizes.components[c];
  13595. var decompositionLevelsCount =
  13596. component.codingStyleParameters.decompositionLevelsCount;
  13597. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  13598. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  13599. for (; r <= decompositionLevelsCount; r++) {
  13600. var resolution = component.resolutions[r];
  13601. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  13602. var k = getPrecinctIndexIfExist(
  13603. px,
  13604. py,
  13605. sizeInImageScale,
  13606. precinctsIterationSizes,
  13607. resolution);
  13608. if (k === null) {
  13609. continue;
  13610. }
  13611. for (; l < layersCount;) {
  13612. var packet = createPacket(resolution, k, l);
  13613. l++;
  13614. return packet;
  13615. }
  13616. l = 0;
  13617. }
  13618. r = 0;
  13619. }
  13620. px = 0;
  13621. }
  13622. py = 0;
  13623. }
  13624. throw new Error('JPX Error: Out of packets');
  13625. };
  13626. }
  13627. function getPrecinctIndexIfExist(
  13628. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13629. var posX = pxIndex * precinctIterationSizes.minWidth;
  13630. var posY = pyIndex * precinctIterationSizes.minHeight;
  13631. if (posX % sizeInImageScale.width !== 0 ||
  13632. posY % sizeInImageScale.height !== 0) {
  13633. return null;
  13634. }
  13635. var startPrecinctRowIndex =
  13636. (posY / sizeInImageScale.width) *
  13637. resolution.precinctParameters.numprecinctswide;
  13638. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13639. }
  13640. function getPrecinctSizesInImageScale(tile) {
  13641. var componentsCount = tile.components.length;
  13642. var minWidth = Number.MAX_VALUE;
  13643. var minHeight = Number.MAX_VALUE;
  13644. var maxNumWide = 0;
  13645. var maxNumHigh = 0;
  13646. var sizePerComponent = new Array(componentsCount);
  13647. for (var c = 0; c < componentsCount; c++) {
  13648. var component = tile.components[c];
  13649. var decompositionLevelsCount =
  13650. component.codingStyleParameters.decompositionLevelsCount;
  13651. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13652. var minWidthCurrentComponent = Number.MAX_VALUE;
  13653. var minHeightCurrentComponent = Number.MAX_VALUE;
  13654. var maxNumWideCurrentComponent = 0;
  13655. var maxNumHighCurrentComponent = 0;
  13656. var scale = 1;
  13657. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13658. var resolution = component.resolutions[r];
  13659. var widthCurrentResolution =
  13660. scale * resolution.precinctParameters.precinctWidth;
  13661. var heightCurrentResolution =
  13662. scale * resolution.precinctParameters.precinctHeight;
  13663. minWidthCurrentComponent = Math.min(
  13664. minWidthCurrentComponent,
  13665. widthCurrentResolution);
  13666. minHeightCurrentComponent = Math.min(
  13667. minHeightCurrentComponent,
  13668. heightCurrentResolution);
  13669. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13670. resolution.precinctParameters.numprecinctswide);
  13671. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13672. resolution.precinctParameters.numprecinctshigh);
  13673. sizePerResolution[r] = {
  13674. width: widthCurrentResolution,
  13675. height: heightCurrentResolution
  13676. };
  13677. scale <<= 1;
  13678. }
  13679. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13680. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13681. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13682. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13683. sizePerComponent[c] = {
  13684. resolutions: sizePerResolution,
  13685. minWidth: minWidthCurrentComponent,
  13686. minHeight: minHeightCurrentComponent,
  13687. maxNumWide: maxNumWideCurrentComponent,
  13688. maxNumHigh: maxNumHighCurrentComponent
  13689. };
  13690. }
  13691. return {
  13692. components: sizePerComponent,
  13693. minWidth: minWidth,
  13694. minHeight: minHeight,
  13695. maxNumWide: maxNumWide,
  13696. maxNumHigh: maxNumHigh
  13697. };
  13698. }
  13699. function buildPackets(context) {
  13700. var siz = context.SIZ;
  13701. var tileIndex = context.currentTile.index;
  13702. var tile = context.tiles[tileIndex];
  13703. var componentsCount = siz.Csiz;
  13704. // Creating resolutions and sub-bands for each component
  13705. for (var c = 0; c < componentsCount; c++) {
  13706. var component = tile.components[c];
  13707. var decompositionLevelsCount =
  13708. component.codingStyleParameters.decompositionLevelsCount;
  13709. // Section B.5 Resolution levels and sub-bands
  13710. var resolutions = [];
  13711. var subbands = [];
  13712. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13713. var blocksDimensions = getBlocksDimensions(context, component, r);
  13714. var resolution = {};
  13715. var scale = 1 << (decompositionLevelsCount - r);
  13716. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13717. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13718. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13719. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13720. resolution.resLevel = r;
  13721. buildPrecincts(context, resolution, blocksDimensions);
  13722. resolutions.push(resolution);
  13723. var subband;
  13724. if (r === 0) {
  13725. // one sub-band (LL) with last decomposition
  13726. subband = {};
  13727. subband.type = 'LL';
  13728. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13729. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13730. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13731. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13732. subband.resolution = resolution;
  13733. buildCodeblocks(context, subband, blocksDimensions);
  13734. subbands.push(subband);
  13735. resolution.subbands = [subband];
  13736. } else {
  13737. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13738. var resolutionSubbands = [];
  13739. // three sub-bands (HL, LH and HH) with rest of decompositions
  13740. subband = {};
  13741. subband.type = 'HL';
  13742. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13743. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13744. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13745. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13746. subband.resolution = resolution;
  13747. buildCodeblocks(context, subband, blocksDimensions);
  13748. subbands.push(subband);
  13749. resolutionSubbands.push(subband);
  13750. subband = {};
  13751. subband.type = 'LH';
  13752. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13753. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13754. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13755. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13756. subband.resolution = resolution;
  13757. buildCodeblocks(context, subband, blocksDimensions);
  13758. subbands.push(subband);
  13759. resolutionSubbands.push(subband);
  13760. subband = {};
  13761. subband.type = 'HH';
  13762. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13763. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13764. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13765. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13766. subband.resolution = resolution;
  13767. buildCodeblocks(context, subband, blocksDimensions);
  13768. subbands.push(subband);
  13769. resolutionSubbands.push(subband);
  13770. resolution.subbands = resolutionSubbands;
  13771. }
  13772. }
  13773. component.resolutions = resolutions;
  13774. component.subbands = subbands;
  13775. }
  13776. // Generate the packets sequence
  13777. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13778. switch (progressionOrder) {
  13779. case 0:
  13780. tile.packetsIterator =
  13781. new LayerResolutionComponentPositionIterator(context);
  13782. break;
  13783. case 1:
  13784. tile.packetsIterator =
  13785. new ResolutionLayerComponentPositionIterator(context);
  13786. break;
  13787. case 2:
  13788. tile.packetsIterator =
  13789. new ResolutionPositionComponentLayerIterator(context);
  13790. break;
  13791. case 3:
  13792. tile.packetsIterator =
  13793. new PositionComponentResolutionLayerIterator(context);
  13794. break;
  13795. case 4:
  13796. tile.packetsIterator =
  13797. new ComponentPositionResolutionLayerIterator(context);
  13798. break;
  13799. default:
  13800. throw new Error('JPX Error: Unsupported progression order ' +
  13801. progressionOrder);
  13802. }
  13803. }
  13804. function parseTilePackets(context, data, offset, dataLength) {
  13805. var position = 0;
  13806. var buffer, bufferSize = 0, skipNextBit = false;
  13807. function readBits(count) {
  13808. while (bufferSize < count) {
  13809. var b = data[offset + position];
  13810. position++;
  13811. if (skipNextBit) {
  13812. buffer = (buffer << 7) | b;
  13813. bufferSize += 7;
  13814. skipNextBit = false;
  13815. } else {
  13816. buffer = (buffer << 8) | b;
  13817. bufferSize += 8;
  13818. }
  13819. if (b === 0xFF) {
  13820. skipNextBit = true;
  13821. }
  13822. }
  13823. bufferSize -= count;
  13824. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13825. }
  13826. function skipMarkerIfEqual(value) {
  13827. if (data[offset + position - 1] === 0xFF &&
  13828. data[offset + position] === value) {
  13829. skipBytes(1);
  13830. return true;
  13831. } else if (data[offset + position] === 0xFF &&
  13832. data[offset + position + 1] === value) {
  13833. skipBytes(2);
  13834. return true;
  13835. }
  13836. return false;
  13837. }
  13838. function skipBytes(count) {
  13839. position += count;
  13840. }
  13841. function alignToByte() {
  13842. bufferSize = 0;
  13843. if (skipNextBit) {
  13844. position++;
  13845. skipNextBit = false;
  13846. }
  13847. }
  13848. function readCodingpasses() {
  13849. if (readBits(1) === 0) {
  13850. return 1;
  13851. }
  13852. if (readBits(1) === 0) {
  13853. return 2;
  13854. }
  13855. var value = readBits(2);
  13856. if (value < 3) {
  13857. return value + 3;
  13858. }
  13859. value = readBits(5);
  13860. if (value < 31) {
  13861. return value + 6;
  13862. }
  13863. value = readBits(7);
  13864. return value + 37;
  13865. }
  13866. var tileIndex = context.currentTile.index;
  13867. var tile = context.tiles[tileIndex];
  13868. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13869. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13870. var packetsIterator = tile.packetsIterator;
  13871. while (position < dataLength) {
  13872. alignToByte();
  13873. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13874. // Skip also marker segment length and packet sequence ID
  13875. skipBytes(4);
  13876. }
  13877. var packet = packetsIterator.nextPacket();
  13878. if (!readBits(1)) {
  13879. continue;
  13880. }
  13881. var layerNumber = packet.layerNumber;
  13882. var queue = [], codeblock;
  13883. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13884. codeblock = packet.codeblocks[i];
  13885. var precinct = codeblock.precinct;
  13886. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13887. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13888. var codeblockIncluded = false;
  13889. var firstTimeInclusion = false;
  13890. var valueReady;
  13891. if (codeblock['included'] !== undefined) {
  13892. codeblockIncluded = !!readBits(1);
  13893. } else {
  13894. // reading inclusion tree
  13895. precinct = codeblock.precinct;
  13896. var inclusionTree, zeroBitPlanesTree;
  13897. if (precinct['inclusionTree'] !== undefined) {
  13898. inclusionTree = precinct.inclusionTree;
  13899. } else {
  13900. // building inclusion and zero bit-planes trees
  13901. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13902. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13903. inclusionTree = new InclusionTree(width, height, layerNumber);
  13904. zeroBitPlanesTree = new TagTree(width, height);
  13905. precinct.inclusionTree = inclusionTree;
  13906. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13907. }
  13908. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13909. while (true) {
  13910. if (readBits(1)) {
  13911. valueReady = !inclusionTree.nextLevel();
  13912. if (valueReady) {
  13913. codeblock.included = true;
  13914. codeblockIncluded = firstTimeInclusion = true;
  13915. break;
  13916. }
  13917. } else {
  13918. inclusionTree.incrementValue(layerNumber);
  13919. break;
  13920. }
  13921. }
  13922. }
  13923. }
  13924. if (!codeblockIncluded) {
  13925. continue;
  13926. }
  13927. if (firstTimeInclusion) {
  13928. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13929. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13930. while (true) {
  13931. if (readBits(1)) {
  13932. valueReady = !zeroBitPlanesTree.nextLevel();
  13933. if (valueReady) {
  13934. break;
  13935. }
  13936. } else {
  13937. zeroBitPlanesTree.incrementValue();
  13938. }
  13939. }
  13940. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13941. }
  13942. var codingpasses = readCodingpasses();
  13943. while (readBits(1)) {
  13944. codeblock.Lblock++;
  13945. }
  13946. var codingpassesLog2 = log2(codingpasses);
  13947. // rounding down log2
  13948. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13949. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13950. var codedDataLength = readBits(bits);
  13951. queue.push({
  13952. codeblock: codeblock,
  13953. codingpasses: codingpasses,
  13954. dataLength: codedDataLength
  13955. });
  13956. }
  13957. alignToByte();
  13958. if (ephMarkerUsed) {
  13959. skipMarkerIfEqual(0x92);
  13960. }
  13961. while (queue.length > 0) {
  13962. var packetItem = queue.shift();
  13963. codeblock = packetItem.codeblock;
  13964. if (codeblock['data'] === undefined) {
  13965. codeblock.data = [];
  13966. }
  13967. codeblock.data.push({
  13968. data: data,
  13969. start: offset + position,
  13970. end: offset + position + packetItem.dataLength,
  13971. codingpasses: packetItem.codingpasses
  13972. });
  13973. position += packetItem.dataLength;
  13974. }
  13975. }
  13976. return position;
  13977. }
  13978. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13979. delta, mb, reversible, segmentationSymbolUsed) {
  13980. var x0 = subband.tbx0;
  13981. var y0 = subband.tby0;
  13982. var width = subband.tbx1 - subband.tbx0;
  13983. var codeblocks = subband.codeblocks;
  13984. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13985. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13986. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13987. var codeblock = codeblocks[i];
  13988. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13989. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13990. if (blockWidth === 0 || blockHeight === 0) {
  13991. continue;
  13992. }
  13993. if (codeblock['data'] === undefined) {
  13994. continue;
  13995. }
  13996. var bitModel, currentCodingpassType;
  13997. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  13998. codeblock.zeroBitPlanes, mb);
  13999. currentCodingpassType = 2; // first bit plane starts from cleanup
  14000. // collect data
  14001. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  14002. var j, jj, dataItem;
  14003. for (j = 0, jj = data.length; j < jj; j++) {
  14004. dataItem = data[j];
  14005. totalLength += dataItem.end - dataItem.start;
  14006. codingpasses += dataItem.codingpasses;
  14007. }
  14008. var encodedData = new Uint8Array(totalLength);
  14009. var position = 0;
  14010. for (j = 0, jj = data.length; j < jj; j++) {
  14011. dataItem = data[j];
  14012. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  14013. encodedData.set(chunk, position);
  14014. position += chunk.length;
  14015. }
  14016. // decoding the item
  14017. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  14018. bitModel.setDecoder(decoder);
  14019. for (j = 0; j < codingpasses; j++) {
  14020. switch (currentCodingpassType) {
  14021. case 0:
  14022. bitModel.runSignificancePropogationPass();
  14023. break;
  14024. case 1:
  14025. bitModel.runMagnitudeRefinementPass();
  14026. break;
  14027. case 2:
  14028. bitModel.runCleanupPass();
  14029. if (segmentationSymbolUsed) {
  14030. bitModel.checkSegmentationSymbol();
  14031. }
  14032. break;
  14033. }
  14034. currentCodingpassType = (currentCodingpassType + 1) % 3;
  14035. }
  14036. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  14037. var sign = bitModel.coefficentsSign;
  14038. var magnitude = bitModel.coefficentsMagnitude;
  14039. var bitsDecoded = bitModel.bitsDecoded;
  14040. var magnitudeCorrection = reversible ? 0 : 0.5;
  14041. var k, n, nb;
  14042. position = 0;
  14043. // Do the interleaving of Section F.3.3 here, so we do not need
  14044. // to copy later. LL level is not interleaved, just copied.
  14045. var interleave = (subband.type !== 'LL');
  14046. for (j = 0; j < blockHeight; j++) {
  14047. var row = (offset / width) | 0; // row in the non-interleaved subband
  14048. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  14049. for (k = 0; k < blockWidth; k++) {
  14050. n = magnitude[position];
  14051. if (n !== 0) {
  14052. n = (n + magnitudeCorrection) * delta;
  14053. if (sign[position] !== 0) {
  14054. n = -n;
  14055. }
  14056. nb = bitsDecoded[position];
  14057. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  14058. if (reversible && (nb >= mb)) {
  14059. coefficients[pos] = n;
  14060. } else {
  14061. coefficients[pos] = n * (1 << (mb - nb));
  14062. }
  14063. }
  14064. offset++;
  14065. position++;
  14066. }
  14067. offset += width - blockWidth;
  14068. }
  14069. }
  14070. }
  14071. function transformTile(context, tile, c) {
  14072. var component = tile.components[c];
  14073. var codingStyleParameters = component.codingStyleParameters;
  14074. var quantizationParameters = component.quantizationParameters;
  14075. var decompositionLevelsCount =
  14076. codingStyleParameters.decompositionLevelsCount;
  14077. var spqcds = quantizationParameters.SPqcds;
  14078. var scalarExpounded = quantizationParameters.scalarExpounded;
  14079. var guardBits = quantizationParameters.guardBits;
  14080. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  14081. var precision = context.components[c].precision;
  14082. var reversible = codingStyleParameters.reversibleTransformation;
  14083. var transform = (reversible ? new ReversibleTransform() :
  14084. new IrreversibleTransform());
  14085. var subbandCoefficients = [];
  14086. var b = 0;
  14087. for (var i = 0; i <= decompositionLevelsCount; i++) {
  14088. var resolution = component.resolutions[i];
  14089. var width = resolution.trx1 - resolution.trx0;
  14090. var height = resolution.try1 - resolution.try0;
  14091. // Allocate space for the whole sublevel.
  14092. var coefficients = new Float32Array(width * height);
  14093. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  14094. var mu, epsilon;
  14095. if (!scalarExpounded) {
  14096. // formula E-5
  14097. mu = spqcds[0].mu;
  14098. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  14099. } else {
  14100. mu = spqcds[b].mu;
  14101. epsilon = spqcds[b].epsilon;
  14102. b++;
  14103. }
  14104. var subband = resolution.subbands[j];
  14105. var gainLog2 = SubbandsGainLog2[subband.type];
  14106. // calulate quantization coefficient (Section E.1.1.1)
  14107. var delta = (reversible ? 1 :
  14108. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  14109. var mb = (guardBits + epsilon - 1);
  14110. // In the first resolution level, copyCoefficients will fill the
  14111. // whole array with coefficients. In the succeding passes,
  14112. // copyCoefficients will consecutively fill in the values that belong
  14113. // to the interleaved positions of the HL, LH, and HH coefficients.
  14114. // The LL coefficients will then be interleaved in Transform.iterate().
  14115. copyCoefficients(coefficients, width, height, subband, delta, mb,
  14116. reversible, segmentationSymbolUsed);
  14117. }
  14118. subbandCoefficients.push({
  14119. width: width,
  14120. height: height,
  14121. items: coefficients
  14122. });
  14123. }
  14124. var result = transform.calculate(subbandCoefficients,
  14125. component.tcx0, component.tcy0);
  14126. return {
  14127. left: component.tcx0,
  14128. top: component.tcy0,
  14129. width: result.width,
  14130. height: result.height,
  14131. items: result.items
  14132. };
  14133. }
  14134. function transformComponents(context) {
  14135. var siz = context.SIZ;
  14136. var components = context.components;
  14137. var componentsCount = siz.Csiz;
  14138. var resultImages = [];
  14139. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  14140. var tile = context.tiles[i];
  14141. var transformedTiles = [];
  14142. var c;
  14143. for (c = 0; c < componentsCount; c++) {
  14144. transformedTiles[c] = transformTile(context, tile, c);
  14145. }
  14146. var tile0 = transformedTiles[0];
  14147. var out = new Uint8Array(tile0.items.length * componentsCount);
  14148. var result = {
  14149. left: tile0.left,
  14150. top: tile0.top,
  14151. width: tile0.width,
  14152. height: tile0.height,
  14153. items: out
  14154. };
  14155. // Section G.2.2 Inverse multi component transform
  14156. var shift, offset, max, min, maxK;
  14157. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  14158. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  14159. var fourComponents = componentsCount === 4;
  14160. var y0items = transformedTiles[0].items;
  14161. var y1items = transformedTiles[1].items;
  14162. var y2items = transformedTiles[2].items;
  14163. var y3items = fourComponents ? transformedTiles[3].items : null;
  14164. // HACK: The multiple component transform formulas below assume that
  14165. // all components have the same precision. With this in mind, we
  14166. // compute shift and offset only once.
  14167. shift = components[0].precision - 8;
  14168. offset = (128 << shift) + 0.5;
  14169. max = 255 * (1 << shift);
  14170. maxK = max * 0.5;
  14171. min = -maxK;
  14172. var component0 = tile.components[0];
  14173. var alpha01 = componentsCount - 3;
  14174. jj = y0items.length;
  14175. if (!component0.codingStyleParameters.reversibleTransformation) {
  14176. // inverse irreversible multiple component transform
  14177. for (j = 0; j < jj; j++, pos += alpha01) {
  14178. y0 = y0items[j] + offset;
  14179. y1 = y1items[j];
  14180. y2 = y2items[j];
  14181. r = y0 + 1.402 * y2;
  14182. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  14183. b = y0 + 1.772 * y1;
  14184. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  14185. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  14186. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  14187. }
  14188. } else {
  14189. // inverse reversible multiple component transform
  14190. for (j = 0; j < jj; j++, pos += alpha01) {
  14191. y0 = y0items[j] + offset;
  14192. y1 = y1items[j];
  14193. y2 = y2items[j];
  14194. g = y0 - ((y2 + y1) >> 2);
  14195. r = g + y2;
  14196. b = g + y1;
  14197. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  14198. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  14199. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  14200. }
  14201. }
  14202. if (fourComponents) {
  14203. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  14204. k = y3items[j];
  14205. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  14206. }
  14207. }
  14208. } else { // no multi-component transform
  14209. for (c = 0; c < componentsCount; c++) {
  14210. var items = transformedTiles[c].items;
  14211. shift = components[c].precision - 8;
  14212. offset = (128 << shift) + 0.5;
  14213. max = (127.5 * (1 << shift));
  14214. min = -max;
  14215. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  14216. val = items[j];
  14217. out[pos] = val <= min ? 0 :
  14218. val >= max ? 255 : (val + offset) >> shift;
  14219. pos += componentsCount;
  14220. }
  14221. }
  14222. }
  14223. resultImages.push(result);
  14224. }
  14225. return resultImages;
  14226. }
  14227. function initializeTile(context, tileIndex) {
  14228. var siz = context.SIZ;
  14229. var componentsCount = siz.Csiz;
  14230. var tile = context.tiles[tileIndex];
  14231. for (var c = 0; c < componentsCount; c++) {
  14232. var component = tile.components[c];
  14233. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  14234. context.currentTile.QCC[c] : context.currentTile.QCD);
  14235. component.quantizationParameters = qcdOrQcc;
  14236. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  14237. context.currentTile.COC[c] : context.currentTile.COD);
  14238. component.codingStyleParameters = codOrCoc;
  14239. }
  14240. tile.codingStyleDefaultParameters = context.currentTile.COD;
  14241. }
  14242. // Section B.10.2 Tag trees
  14243. var TagTree = (function TagTreeClosure() {
  14244. function TagTree(width, height) {
  14245. var levelsLength = log2(Math.max(width, height)) + 1;
  14246. this.levels = [];
  14247. for (var i = 0; i < levelsLength; i++) {
  14248. var level = {
  14249. width: width,
  14250. height: height,
  14251. items: []
  14252. };
  14253. this.levels.push(level);
  14254. width = Math.ceil(width / 2);
  14255. height = Math.ceil(height / 2);
  14256. }
  14257. }
  14258. TagTree.prototype = {
  14259. reset: function TagTree_reset(i, j) {
  14260. var currentLevel = 0, value = 0, level;
  14261. while (currentLevel < this.levels.length) {
  14262. level = this.levels[currentLevel];
  14263. var index = i + j * level.width;
  14264. if (level.items[index] !== undefined) {
  14265. value = level.items[index];
  14266. break;
  14267. }
  14268. level.index = index;
  14269. i >>= 1;
  14270. j >>= 1;
  14271. currentLevel++;
  14272. }
  14273. currentLevel--;
  14274. level = this.levels[currentLevel];
  14275. level.items[level.index] = value;
  14276. this.currentLevel = currentLevel;
  14277. delete this.value;
  14278. },
  14279. incrementValue: function TagTree_incrementValue() {
  14280. var level = this.levels[this.currentLevel];
  14281. level.items[level.index]++;
  14282. },
  14283. nextLevel: function TagTree_nextLevel() {
  14284. var currentLevel = this.currentLevel;
  14285. var level = this.levels[currentLevel];
  14286. var value = level.items[level.index];
  14287. currentLevel--;
  14288. if (currentLevel < 0) {
  14289. this.value = value;
  14290. return false;
  14291. }
  14292. this.currentLevel = currentLevel;
  14293. level = this.levels[currentLevel];
  14294. level.items[level.index] = value;
  14295. return true;
  14296. }
  14297. };
  14298. return TagTree;
  14299. })();
  14300. var InclusionTree = (function InclusionTreeClosure() {
  14301. function InclusionTree(width, height, defaultValue) {
  14302. var levelsLength = log2(Math.max(width, height)) + 1;
  14303. this.levels = [];
  14304. for (var i = 0; i < levelsLength; i++) {
  14305. var items = new Uint8Array(width * height);
  14306. for (var j = 0, jj = items.length; j < jj; j++) {
  14307. items[j] = defaultValue;
  14308. }
  14309. var level = {
  14310. width: width,
  14311. height: height,
  14312. items: items
  14313. };
  14314. this.levels.push(level);
  14315. width = Math.ceil(width / 2);
  14316. height = Math.ceil(height / 2);
  14317. }
  14318. }
  14319. InclusionTree.prototype = {
  14320. reset: function InclusionTree_reset(i, j, stopValue) {
  14321. var currentLevel = 0;
  14322. while (currentLevel < this.levels.length) {
  14323. var level = this.levels[currentLevel];
  14324. var index = i + j * level.width;
  14325. level.index = index;
  14326. var value = level.items[index];
  14327. if (value === 0xFF) {
  14328. break;
  14329. }
  14330. if (value > stopValue) {
  14331. this.currentLevel = currentLevel;
  14332. // already know about this one, propagating the value to top levels
  14333. this.propagateValues();
  14334. return false;
  14335. }
  14336. i >>= 1;
  14337. j >>= 1;
  14338. currentLevel++;
  14339. }
  14340. this.currentLevel = currentLevel - 1;
  14341. return true;
  14342. },
  14343. incrementValue: function InclusionTree_incrementValue(stopValue) {
  14344. var level = this.levels[this.currentLevel];
  14345. level.items[level.index] = stopValue + 1;
  14346. this.propagateValues();
  14347. },
  14348. propagateValues: function InclusionTree_propagateValues() {
  14349. var levelIndex = this.currentLevel;
  14350. var level = this.levels[levelIndex];
  14351. var currentValue = level.items[level.index];
  14352. while (--levelIndex >= 0) {
  14353. level = this.levels[levelIndex];
  14354. level.items[level.index] = currentValue;
  14355. }
  14356. },
  14357. nextLevel: function InclusionTree_nextLevel() {
  14358. var currentLevel = this.currentLevel;
  14359. var level = this.levels[currentLevel];
  14360. var value = level.items[level.index];
  14361. level.items[level.index] = 0xFF;
  14362. currentLevel--;
  14363. if (currentLevel < 0) {
  14364. return false;
  14365. }
  14366. this.currentLevel = currentLevel;
  14367. level = this.levels[currentLevel];
  14368. level.items[level.index] = value;
  14369. return true;
  14370. }
  14371. };
  14372. return InclusionTree;
  14373. })();
  14374. // Section D. Coefficient bit modeling
  14375. var BitModel = (function BitModelClosure() {
  14376. var UNIFORM_CONTEXT = 17;
  14377. var RUNLENGTH_CONTEXT = 18;
  14378. // Table D-1
  14379. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  14380. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  14381. var LLAndLHContextsLabel = new Uint8Array([
  14382. 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,
  14383. 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,
  14384. 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
  14385. ]);
  14386. var HLContextLabel = new Uint8Array([
  14387. 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,
  14388. 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,
  14389. 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
  14390. ]);
  14391. var HHContextLabel = new Uint8Array([
  14392. 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,
  14393. 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,
  14394. 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
  14395. ]);
  14396. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  14397. this.width = width;
  14398. this.height = height;
  14399. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  14400. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  14401. var coefficientCount = width * height;
  14402. // coefficients outside the encoding region treated as insignificant
  14403. // add border state cells for significanceState
  14404. this.neighborsSignificance = new Uint8Array(coefficientCount);
  14405. this.coefficentsSign = new Uint8Array(coefficientCount);
  14406. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  14407. mb > 6 ? new Uint16Array(coefficientCount) :
  14408. new Uint8Array(coefficientCount);
  14409. this.processingFlags = new Uint8Array(coefficientCount);
  14410. var bitsDecoded = new Uint8Array(coefficientCount);
  14411. if (zeroBitPlanes !== 0) {
  14412. for (var i = 0; i < coefficientCount; i++) {
  14413. bitsDecoded[i] = zeroBitPlanes;
  14414. }
  14415. }
  14416. this.bitsDecoded = bitsDecoded;
  14417. this.reset();
  14418. }
  14419. BitModel.prototype = {
  14420. setDecoder: function BitModel_setDecoder(decoder) {
  14421. this.decoder = decoder;
  14422. },
  14423. reset: function BitModel_reset() {
  14424. // We have 17 contexts that are accessed via context labels,
  14425. // plus the uniform and runlength context.
  14426. this.contexts = new Int8Array(19);
  14427. // Contexts are packed into 1 byte:
  14428. // highest 7 bits carry the index, lowest bit carries mps
  14429. this.contexts[0] = (4 << 1) | 0;
  14430. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  14431. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  14432. },
  14433. setNeighborsSignificance:
  14434. function BitModel_setNeighborsSignificance(row, column, index) {
  14435. var neighborsSignificance = this.neighborsSignificance;
  14436. var width = this.width, height = this.height;
  14437. var left = (column > 0);
  14438. var right = (column + 1 < width);
  14439. var i;
  14440. if (row > 0) {
  14441. i = index - width;
  14442. if (left) {
  14443. neighborsSignificance[i - 1] += 0x10;
  14444. }
  14445. if (right) {
  14446. neighborsSignificance[i + 1] += 0x10;
  14447. }
  14448. neighborsSignificance[i] += 0x04;
  14449. }
  14450. if (row + 1 < height) {
  14451. i = index + width;
  14452. if (left) {
  14453. neighborsSignificance[i - 1] += 0x10;
  14454. }
  14455. if (right) {
  14456. neighborsSignificance[i + 1] += 0x10;
  14457. }
  14458. neighborsSignificance[i] += 0x04;
  14459. }
  14460. if (left) {
  14461. neighborsSignificance[index - 1] += 0x01;
  14462. }
  14463. if (right) {
  14464. neighborsSignificance[index + 1] += 0x01;
  14465. }
  14466. neighborsSignificance[index] |= 0x80;
  14467. },
  14468. runSignificancePropogationPass:
  14469. function BitModel_runSignificancePropogationPass() {
  14470. var decoder = this.decoder;
  14471. var width = this.width, height = this.height;
  14472. var coefficentsMagnitude = this.coefficentsMagnitude;
  14473. var coefficentsSign = this.coefficentsSign;
  14474. var neighborsSignificance = this.neighborsSignificance;
  14475. var processingFlags = this.processingFlags;
  14476. var contexts = this.contexts;
  14477. var labels = this.contextLabelTable;
  14478. var bitsDecoded = this.bitsDecoded;
  14479. var processedInverseMask = ~1;
  14480. var processedMask = 1;
  14481. var firstMagnitudeBitMask = 2;
  14482. for (var i0 = 0; i0 < height; i0 += 4) {
  14483. for (var j = 0; j < width; j++) {
  14484. var index = i0 * width + j;
  14485. for (var i1 = 0; i1 < 4; i1++, index += width) {
  14486. var i = i0 + i1;
  14487. if (i >= height) {
  14488. break;
  14489. }
  14490. // clear processed flag first
  14491. processingFlags[index] &= processedInverseMask;
  14492. if (coefficentsMagnitude[index] ||
  14493. !neighborsSignificance[index]) {
  14494. continue;
  14495. }
  14496. var contextLabel = labels[neighborsSignificance[index]];
  14497. var decision = decoder.readBit(contexts, contextLabel);
  14498. if (decision) {
  14499. var sign = this.decodeSignBit(i, j, index);
  14500. coefficentsSign[index] = sign;
  14501. coefficentsMagnitude[index] = 1;
  14502. this.setNeighborsSignificance(i, j, index);
  14503. processingFlags[index] |= firstMagnitudeBitMask;
  14504. }
  14505. bitsDecoded[index]++;
  14506. processingFlags[index] |= processedMask;
  14507. }
  14508. }
  14509. }
  14510. },
  14511. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  14512. var width = this.width, height = this.height;
  14513. var coefficentsMagnitude = this.coefficentsMagnitude;
  14514. var coefficentsSign = this.coefficentsSign;
  14515. var contribution, sign0, sign1, significance1;
  14516. var contextLabel, decoded;
  14517. // calculate horizontal contribution
  14518. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  14519. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  14520. sign1 = coefficentsSign[index + 1];
  14521. if (significance1) {
  14522. sign0 = coefficentsSign[index - 1];
  14523. contribution = 1 - sign1 - sign0;
  14524. } else {
  14525. contribution = 1 - sign1 - sign1;
  14526. }
  14527. } else if (significance1) {
  14528. sign0 = coefficentsSign[index - 1];
  14529. contribution = 1 - sign0 - sign0;
  14530. } else {
  14531. contribution = 0;
  14532. }
  14533. var horizontalContribution = 3 * contribution;
  14534. // calculate vertical contribution and combine with the horizontal
  14535. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  14536. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  14537. sign1 = coefficentsSign[index + width];
  14538. if (significance1) {
  14539. sign0 = coefficentsSign[index - width];
  14540. contribution = 1 - sign1 - sign0 + horizontalContribution;
  14541. } else {
  14542. contribution = 1 - sign1 - sign1 + horizontalContribution;
  14543. }
  14544. } else if (significance1) {
  14545. sign0 = coefficentsSign[index - width];
  14546. contribution = 1 - sign0 - sign0 + horizontalContribution;
  14547. } else {
  14548. contribution = horizontalContribution;
  14549. }
  14550. if (contribution >= 0) {
  14551. contextLabel = 9 + contribution;
  14552. decoded = this.decoder.readBit(this.contexts, contextLabel);
  14553. } else {
  14554. contextLabel = 9 - contribution;
  14555. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  14556. }
  14557. return decoded;
  14558. },
  14559. runMagnitudeRefinementPass:
  14560. function BitModel_runMagnitudeRefinementPass() {
  14561. var decoder = this.decoder;
  14562. var width = this.width, height = this.height;
  14563. var coefficentsMagnitude = this.coefficentsMagnitude;
  14564. var neighborsSignificance = this.neighborsSignificance;
  14565. var contexts = this.contexts;
  14566. var bitsDecoded = this.bitsDecoded;
  14567. var processingFlags = this.processingFlags;
  14568. var processedMask = 1;
  14569. var firstMagnitudeBitMask = 2;
  14570. var length = width * height;
  14571. var width4 = width * 4;
  14572. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  14573. indexNext = Math.min(length, index0 + width4);
  14574. for (var j = 0; j < width; j++) {
  14575. for (var index = index0 + j; index < indexNext; index += width) {
  14576. // significant but not those that have just become
  14577. if (!coefficentsMagnitude[index] ||
  14578. (processingFlags[index] & processedMask) !== 0) {
  14579. continue;
  14580. }
  14581. var contextLabel = 16;
  14582. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  14583. processingFlags[index] ^= firstMagnitudeBitMask;
  14584. // first refinement
  14585. var significance = neighborsSignificance[index] & 127;
  14586. contextLabel = significance === 0 ? 15 : 14;
  14587. }
  14588. var bit = decoder.readBit(contexts, contextLabel);
  14589. coefficentsMagnitude[index] =
  14590. (coefficentsMagnitude[index] << 1) | bit;
  14591. bitsDecoded[index]++;
  14592. processingFlags[index] |= processedMask;
  14593. }
  14594. }
  14595. }
  14596. },
  14597. runCleanupPass: function BitModel_runCleanupPass() {
  14598. var decoder = this.decoder;
  14599. var width = this.width, height = this.height;
  14600. var neighborsSignificance = this.neighborsSignificance;
  14601. var coefficentsMagnitude = this.coefficentsMagnitude;
  14602. var coefficentsSign = this.coefficentsSign;
  14603. var contexts = this.contexts;
  14604. var labels = this.contextLabelTable;
  14605. var bitsDecoded = this.bitsDecoded;
  14606. var processingFlags = this.processingFlags;
  14607. var processedMask = 1;
  14608. var firstMagnitudeBitMask = 2;
  14609. var oneRowDown = width;
  14610. var twoRowsDown = width * 2;
  14611. var threeRowsDown = width * 3;
  14612. var iNext;
  14613. for (var i0 = 0; i0 < height; i0 = iNext) {
  14614. iNext = Math.min(i0 + 4, height);
  14615. var indexBase = i0 * width;
  14616. var checkAllEmpty = i0 + 3 < height;
  14617. for (var j = 0; j < width; j++) {
  14618. var index0 = indexBase + j;
  14619. // using the property: labels[neighborsSignificance[index]] === 0
  14620. // when neighborsSignificance[index] === 0
  14621. var allEmpty = (checkAllEmpty &&
  14622. processingFlags[index0] === 0 &&
  14623. processingFlags[index0 + oneRowDown] === 0 &&
  14624. processingFlags[index0 + twoRowsDown] === 0 &&
  14625. processingFlags[index0 + threeRowsDown] === 0 &&
  14626. neighborsSignificance[index0] === 0 &&
  14627. neighborsSignificance[index0 + oneRowDown] === 0 &&
  14628. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14629. neighborsSignificance[index0 + threeRowsDown] === 0);
  14630. var i1 = 0, index = index0;
  14631. var i = i0, sign;
  14632. if (allEmpty) {
  14633. var hasSignificantCoefficent =
  14634. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14635. if (!hasSignificantCoefficent) {
  14636. bitsDecoded[index0]++;
  14637. bitsDecoded[index0 + oneRowDown]++;
  14638. bitsDecoded[index0 + twoRowsDown]++;
  14639. bitsDecoded[index0 + threeRowsDown]++;
  14640. continue; // next column
  14641. }
  14642. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14643. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14644. if (i1 !== 0) {
  14645. i = i0 + i1;
  14646. index += i1 * width;
  14647. }
  14648. sign = this.decodeSignBit(i, j, index);
  14649. coefficentsSign[index] = sign;
  14650. coefficentsMagnitude[index] = 1;
  14651. this.setNeighborsSignificance(i, j, index);
  14652. processingFlags[index] |= firstMagnitudeBitMask;
  14653. index = index0;
  14654. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14655. bitsDecoded[index]++;
  14656. }
  14657. i1++;
  14658. }
  14659. for (i = i0 + i1; i < iNext; i++, index += width) {
  14660. if (coefficentsMagnitude[index] ||
  14661. (processingFlags[index] & processedMask) !== 0) {
  14662. continue;
  14663. }
  14664. var contextLabel = labels[neighborsSignificance[index]];
  14665. var decision = decoder.readBit(contexts, contextLabel);
  14666. if (decision === 1) {
  14667. sign = this.decodeSignBit(i, j, index);
  14668. coefficentsSign[index] = sign;
  14669. coefficentsMagnitude[index] = 1;
  14670. this.setNeighborsSignificance(i, j, index);
  14671. processingFlags[index] |= firstMagnitudeBitMask;
  14672. }
  14673. bitsDecoded[index]++;
  14674. }
  14675. }
  14676. }
  14677. },
  14678. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14679. var decoder = this.decoder;
  14680. var contexts = this.contexts;
  14681. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14682. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14683. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14684. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14685. if (symbol !== 0xA) {
  14686. throw new Error('JPX Error: Invalid segmentation symbol');
  14687. }
  14688. }
  14689. };
  14690. return BitModel;
  14691. })();
  14692. // Section F, Discrete wavelet transformation
  14693. var Transform = (function TransformClosure() {
  14694. function Transform() {}
  14695. Transform.prototype.calculate =
  14696. function transformCalculate(subbands, u0, v0) {
  14697. var ll = subbands[0];
  14698. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14699. ll = this.iterate(ll, subbands[i], u0, v0);
  14700. }
  14701. return ll;
  14702. };
  14703. Transform.prototype.extend = function extend(buffer, offset, size) {
  14704. // Section F.3.7 extending... using max extension of 4
  14705. var i1 = offset - 1, j1 = offset + 1;
  14706. var i2 = offset + size - 2, j2 = offset + size;
  14707. buffer[i1--] = buffer[j1++];
  14708. buffer[j2++] = buffer[i2--];
  14709. buffer[i1--] = buffer[j1++];
  14710. buffer[j2++] = buffer[i2--];
  14711. buffer[i1--] = buffer[j1++];
  14712. buffer[j2++] = buffer[i2--];
  14713. buffer[i1] = buffer[j1];
  14714. buffer[j2] = buffer[i2];
  14715. };
  14716. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14717. u0, v0) {
  14718. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14719. var width = hl_lh_hh.width;
  14720. var height = hl_lh_hh.height;
  14721. var items = hl_lh_hh.items;
  14722. var i, j, k, l, u, v;
  14723. // Interleave LL according to Section F.3.3
  14724. for (k = 0, i = 0; i < llHeight; i++) {
  14725. l = i * 2 * width;
  14726. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14727. items[l] = llItems[k];
  14728. }
  14729. }
  14730. // The LL band is not needed anymore.
  14731. llItems = ll.items = null;
  14732. var bufferPadding = 4;
  14733. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14734. // Section F.3.4 HOR_SR
  14735. if (width === 1) {
  14736. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14737. if ((u0 & 1) !== 0) {
  14738. for (v = 0, k = 0; v < height; v++, k += width) {
  14739. items[k] *= 0.5;
  14740. }
  14741. }
  14742. } else {
  14743. for (v = 0, k = 0; v < height; v++, k += width) {
  14744. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14745. this.extend(rowBuffer, bufferPadding, width);
  14746. this.filter(rowBuffer, bufferPadding, width);
  14747. items.set(
  14748. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14749. k);
  14750. }
  14751. }
  14752. // Accesses to the items array can take long, because it may not fit into
  14753. // CPU cache and has to be fetched from main memory. Since subsequent
  14754. // accesses to the items array are not local when reading columns, we
  14755. // have a cache miss every time. To reduce cache misses, get up to
  14756. // 'numBuffers' items at a time and store them into the individual
  14757. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14758. var numBuffers = 16;
  14759. var colBuffers = [];
  14760. for (i = 0; i < numBuffers; i++) {
  14761. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14762. }
  14763. var b, currentBuffer = 0;
  14764. ll = bufferPadding + height;
  14765. // Section F.3.5 VER_SR
  14766. if (height === 1) {
  14767. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14768. if ((v0 & 1) !== 0) {
  14769. for (u = 0; u < width; u++) {
  14770. items[u] *= 0.5;
  14771. }
  14772. }
  14773. } else {
  14774. for (u = 0; u < width; u++) {
  14775. // if we ran out of buffers, copy several image columns at once
  14776. if (currentBuffer === 0) {
  14777. numBuffers = Math.min(width - u, numBuffers);
  14778. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14779. for (b = 0; b < numBuffers; b++) {
  14780. colBuffers[b][l] = items[k + b];
  14781. }
  14782. }
  14783. currentBuffer = numBuffers;
  14784. }
  14785. currentBuffer--;
  14786. var buffer = colBuffers[currentBuffer];
  14787. this.extend(buffer, bufferPadding, height);
  14788. this.filter(buffer, bufferPadding, height);
  14789. // If this is last buffer in this group of buffers, flush all buffers.
  14790. if (currentBuffer === 0) {
  14791. k = u - numBuffers + 1;
  14792. for (l = bufferPadding; l < ll; k += width, l++) {
  14793. for (b = 0; b < numBuffers; b++) {
  14794. items[k + b] = colBuffers[b][l];
  14795. }
  14796. }
  14797. }
  14798. }
  14799. }
  14800. return {
  14801. width: width,
  14802. height: height,
  14803. items: items
  14804. };
  14805. };
  14806. return Transform;
  14807. })();
  14808. // Section 3.8.2 Irreversible 9-7 filter
  14809. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14810. function IrreversibleTransform() {
  14811. Transform.call(this);
  14812. }
  14813. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14814. IrreversibleTransform.prototype.filter =
  14815. function irreversibleTransformFilter(x, offset, length) {
  14816. var len = length >> 1;
  14817. offset = offset | 0;
  14818. var j, n, current, next;
  14819. var alpha = -1.586134342059924;
  14820. var beta = -0.052980118572961;
  14821. var gamma = 0.882911075530934;
  14822. var delta = 0.443506852043971;
  14823. var K = 1.230174104914001;
  14824. var K_ = 1 / K;
  14825. // step 1 is combined with step 3
  14826. // step 2
  14827. j = offset - 3;
  14828. for (n = len + 4; n--; j += 2) {
  14829. x[j] *= K_;
  14830. }
  14831. // step 1 & 3
  14832. j = offset - 2;
  14833. current = delta * x[j -1];
  14834. for (n = len + 3; n--; j += 2) {
  14835. next = delta * x[j + 1];
  14836. x[j] = K * x[j] - current - next;
  14837. if (n--) {
  14838. j += 2;
  14839. current = delta * x[j + 1];
  14840. x[j] = K * x[j] - current - next;
  14841. } else {
  14842. break;
  14843. }
  14844. }
  14845. // step 4
  14846. j = offset - 1;
  14847. current = gamma * x[j - 1];
  14848. for (n = len + 2; n--; j += 2) {
  14849. next = gamma * x[j + 1];
  14850. x[j] -= current + next;
  14851. if (n--) {
  14852. j += 2;
  14853. current = gamma * x[j + 1];
  14854. x[j] -= current + next;
  14855. } else {
  14856. break;
  14857. }
  14858. }
  14859. // step 5
  14860. j = offset;
  14861. current = beta * x[j - 1];
  14862. for (n = len + 1; n--; j += 2) {
  14863. next = beta * x[j + 1];
  14864. x[j] -= current + next;
  14865. if (n--) {
  14866. j += 2;
  14867. current = beta * x[j + 1];
  14868. x[j] -= current + next;
  14869. } else {
  14870. break;
  14871. }
  14872. }
  14873. // step 6
  14874. if (len !== 0) {
  14875. j = offset + 1;
  14876. current = alpha * x[j - 1];
  14877. for (n = len; n--; j += 2) {
  14878. next = alpha * x[j + 1];
  14879. x[j] -= current + next;
  14880. if (n--) {
  14881. j += 2;
  14882. current = alpha * x[j + 1];
  14883. x[j] -= current + next;
  14884. } else {
  14885. break;
  14886. }
  14887. }
  14888. }
  14889. };
  14890. return IrreversibleTransform;
  14891. })();
  14892. // Section 3.8.1 Reversible 5-3 filter
  14893. var ReversibleTransform = (function ReversibleTransformClosure() {
  14894. function ReversibleTransform() {
  14895. Transform.call(this);
  14896. }
  14897. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14898. ReversibleTransform.prototype.filter =
  14899. function reversibleTransformFilter(x, offset, length) {
  14900. var len = length >> 1;
  14901. offset = offset | 0;
  14902. var j, n;
  14903. for (j = offset, n = len + 1; n--; j += 2) {
  14904. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14905. }
  14906. for (j = offset + 1, n = len; n--; j += 2) {
  14907. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14908. }
  14909. };
  14910. return ReversibleTransform;
  14911. })();
  14912. return JpxImage;
  14913. })();
  14914. exports.JpxImage = JpxImage;
  14915. }));
  14916. (function (root, factory) {
  14917. {
  14918. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14919. }
  14920. }(this, function (exports, sharedUtil) {
  14921. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14922. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14923. // Workaround for missing math precison in JS.
  14924. var MASK_HIGH = 0xffff0000;
  14925. var MASK_LOW = 0xffff;
  14926. function MurmurHash3_64 (seed) {
  14927. var SEED = 0xc3d2e1f0;
  14928. this.h1 = seed ? seed & 0xffffffff : SEED;
  14929. this.h2 = seed ? seed & 0xffffffff : SEED;
  14930. }
  14931. var alwaysUseUint32ArrayView = false;
  14932. // old webkits have issues with non-aligned arrays
  14933. try {
  14934. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14935. } catch (e) {
  14936. alwaysUseUint32ArrayView = true;
  14937. }
  14938. MurmurHash3_64.prototype = {
  14939. update: function MurmurHash3_64_update(input) {
  14940. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14941. var i;
  14942. if (typeof input === 'string') {
  14943. var data = new Uint8Array(input.length * 2);
  14944. var length = 0;
  14945. for (i = 0; i < input.length; i++) {
  14946. var code = input.charCodeAt(i);
  14947. if (code <= 0xff) {
  14948. data[length++] = code;
  14949. }
  14950. else {
  14951. data[length++] = code >>> 8;
  14952. data[length++] = code & 0xff;
  14953. }
  14954. }
  14955. } else if (input instanceof Uint8Array) {
  14956. data = input;
  14957. length = data.length;
  14958. } else if (typeof input === 'object' && ('length' in input)) {
  14959. // processing regular arrays as well, e.g. for IE9
  14960. data = input;
  14961. length = data.length;
  14962. useUint32ArrayView = true;
  14963. } else {
  14964. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14965. 'Input must be a string or array.');
  14966. }
  14967. var blockCounts = length >> 2;
  14968. var tailLength = length - blockCounts * 4;
  14969. // we don't care about endianness here
  14970. var dataUint32 = useUint32ArrayView ?
  14971. new Uint32ArrayView(data, blockCounts) :
  14972. new Uint32Array(data.buffer, 0, blockCounts);
  14973. var k1 = 0;
  14974. var k2 = 0;
  14975. var h1 = this.h1;
  14976. var h2 = this.h2;
  14977. var C1 = 0xcc9e2d51;
  14978. var C2 = 0x1b873593;
  14979. var C1_LOW = C1 & MASK_LOW;
  14980. var C2_LOW = C2 & MASK_LOW;
  14981. for (i = 0; i < blockCounts; i++) {
  14982. if (i & 1) {
  14983. k1 = dataUint32[i];
  14984. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14985. k1 = k1 << 15 | k1 >>> 17;
  14986. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14987. h1 ^= k1;
  14988. h1 = h1 << 13 | h1 >>> 19;
  14989. h1 = h1 * 5 + 0xe6546b64;
  14990. } else {
  14991. k2 = dataUint32[i];
  14992. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14993. k2 = k2 << 15 | k2 >>> 17;
  14994. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14995. h2 ^= k2;
  14996. h2 = h2 << 13 | h2 >>> 19;
  14997. h2 = h2 * 5 + 0xe6546b64;
  14998. }
  14999. }
  15000. k1 = 0;
  15001. switch (tailLength) {
  15002. case 3:
  15003. k1 ^= data[blockCounts * 4 + 2] << 16;
  15004. /* falls through */
  15005. case 2:
  15006. k1 ^= data[blockCounts * 4 + 1] << 8;
  15007. /* falls through */
  15008. case 1:
  15009. k1 ^= data[blockCounts * 4];
  15010. /* falls through */
  15011. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15012. k1 = k1 << 15 | k1 >>> 17;
  15013. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15014. if (blockCounts & 1) {
  15015. h1 ^= k1;
  15016. } else {
  15017. h2 ^= k1;
  15018. }
  15019. }
  15020. this.h1 = h1;
  15021. this.h2 = h2;
  15022. return this;
  15023. },
  15024. hexdigest: function MurmurHash3_64_hexdigest () {
  15025. var h1 = this.h1;
  15026. var h2 = this.h2;
  15027. h1 ^= h2 >>> 1;
  15028. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15029. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15030. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15031. h1 ^= h2 >>> 1;
  15032. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15033. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15034. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15035. h1 ^= h2 >>> 1;
  15036. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15037. var hex = (arr[i] >>> 0).toString(16);
  15038. while (hex.length < 8) {
  15039. hex = '0' + hex;
  15040. }
  15041. str += hex;
  15042. }
  15043. return str;
  15044. }
  15045. };
  15046. return MurmurHash3_64;
  15047. })();
  15048. exports.MurmurHash3_64 = MurmurHash3_64;
  15049. }));
  15050. (function (root, factory) {
  15051. {
  15052. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15053. }
  15054. }(this, function (exports, sharedUtil) {
  15055. var isArray = sharedUtil.isArray;
  15056. var Name = (function NameClosure() {
  15057. function Name(name) {
  15058. this.name = name;
  15059. }
  15060. Name.prototype = {};
  15061. var nameCache = {};
  15062. Name.get = function Name_get(name) {
  15063. var nameValue = nameCache[name];
  15064. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15065. };
  15066. return Name;
  15067. })();
  15068. var Cmd = (function CmdClosure() {
  15069. function Cmd(cmd) {
  15070. this.cmd = cmd;
  15071. }
  15072. Cmd.prototype = {};
  15073. var cmdCache = {};
  15074. Cmd.get = function Cmd_get(cmd) {
  15075. var cmdValue = cmdCache[cmd];
  15076. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15077. };
  15078. return Cmd;
  15079. })();
  15080. var Dict = (function DictClosure() {
  15081. var nonSerializable = function nonSerializableClosure() {
  15082. return nonSerializable; // creating closure on some variable
  15083. };
  15084. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  15085. 'Background': true,
  15086. 'ExtGState': true,
  15087. 'Halftone': true,
  15088. 'Layout': true,
  15089. 'Mask': true,
  15090. 'Pagination': true,
  15091. 'Printing': true
  15092. };
  15093. function isRecursionAllowedFor(dict) {
  15094. if (!isName(dict.Type)) {
  15095. return true;
  15096. }
  15097. var dictType = dict.Type.name;
  15098. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  15099. }
  15100. // xref is optional
  15101. function Dict(xref) {
  15102. // Map should only be used internally, use functions below to access.
  15103. this.map = Object.create(null);
  15104. this.xref = xref;
  15105. this.objId = null;
  15106. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15107. }
  15108. Dict.prototype = {
  15109. assignXref: function Dict_assignXref(newXref) {
  15110. this.xref = newXref;
  15111. },
  15112. // automatically dereferences Ref objects
  15113. get: function Dict_get(key1, key2, key3) {
  15114. var value;
  15115. var xref = this.xref;
  15116. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15117. typeof key2 === 'undefined') {
  15118. return xref ? xref.fetchIfRef(value) : value;
  15119. }
  15120. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15121. typeof key3 === 'undefined') {
  15122. return xref ? xref.fetchIfRef(value) : value;
  15123. }
  15124. value = this.map[key3] || null;
  15125. return xref ? xref.fetchIfRef(value) : value;
  15126. },
  15127. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15128. getAsync: function Dict_getAsync(key1, key2, key3) {
  15129. var value;
  15130. var xref = this.xref;
  15131. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15132. typeof key2 === 'undefined') {
  15133. if (xref) {
  15134. return xref.fetchIfRefAsync(value);
  15135. }
  15136. return Promise.resolve(value);
  15137. }
  15138. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15139. typeof key3 === 'undefined') {
  15140. if (xref) {
  15141. return xref.fetchIfRefAsync(value);
  15142. }
  15143. return Promise.resolve(value);
  15144. }
  15145. value = this.map[key3] || null;
  15146. if (xref) {
  15147. return xref.fetchIfRefAsync(value);
  15148. }
  15149. return Promise.resolve(value);
  15150. },
  15151. // Same as get(), but dereferences all elements if the result is an Array.
  15152. getArray: function Dict_getArray(key1, key2, key3) {
  15153. var value = this.get(key1, key2, key3);
  15154. var xref = this.xref;
  15155. if (!isArray(value) || !xref) {
  15156. return value;
  15157. }
  15158. value = value.slice(); // Ensure that we don't modify the Dict data.
  15159. for (var i = 0, ii = value.length; i < ii; i++) {
  15160. if (!isRef(value[i])) {
  15161. continue;
  15162. }
  15163. value[i] = xref.fetch(value[i]);
  15164. }
  15165. return value;
  15166. },
  15167. // no dereferencing
  15168. getRaw: function Dict_getRaw(key) {
  15169. return this.map[key];
  15170. },
  15171. // creates new map and dereferences all Refs
  15172. getAll: function Dict_getAll() {
  15173. var all = Object.create(null);
  15174. var queue = null;
  15175. var key, obj;
  15176. for (key in this.map) {
  15177. obj = this.get(key);
  15178. if (obj instanceof Dict) {
  15179. if (isRecursionAllowedFor(obj)) {
  15180. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  15181. } else {
  15182. all[key] = this.getRaw(key);
  15183. }
  15184. } else {
  15185. all[key] = obj;
  15186. }
  15187. }
  15188. if (!queue) {
  15189. return all;
  15190. }
  15191. // trying to take cyclic references into the account
  15192. var processed = Object.create(null);
  15193. while (queue.length > 0) {
  15194. var item = queue.shift();
  15195. var itemObj = item.obj;
  15196. var objId = itemObj.objId;
  15197. if (objId && objId in processed) {
  15198. item.target[item.key] = processed[objId];
  15199. continue;
  15200. }
  15201. var dereferenced = Object.create(null);
  15202. for (key in itemObj.map) {
  15203. obj = itemObj.get(key);
  15204. if (obj instanceof Dict) {
  15205. if (isRecursionAllowedFor(obj)) {
  15206. queue.push({target: dereferenced, key: key, obj: obj});
  15207. } else {
  15208. dereferenced[key] = itemObj.getRaw(key);
  15209. }
  15210. } else {
  15211. dereferenced[key] = obj;
  15212. }
  15213. }
  15214. if (objId) {
  15215. processed[objId] = dereferenced;
  15216. }
  15217. item.target[item.key] = dereferenced;
  15218. }
  15219. return all;
  15220. },
  15221. getKeys: function Dict_getKeys() {
  15222. return Object.keys(this.map);
  15223. },
  15224. set: function Dict_set(key, value) {
  15225. this.map[key] = value;
  15226. },
  15227. has: function Dict_has(key) {
  15228. return key in this.map;
  15229. },
  15230. forEach: function Dict_forEach(callback) {
  15231. for (var key in this.map) {
  15232. callback(key, this.get(key));
  15233. }
  15234. }
  15235. };
  15236. Dict.empty = new Dict(null);
  15237. Dict.merge = function Dict_merge(xref, dictArray) {
  15238. var mergedDict = new Dict(xref);
  15239. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15240. var dict = dictArray[i];
  15241. if (!isDict(dict)) {
  15242. continue;
  15243. }
  15244. for (var keyName in dict.map) {
  15245. if (mergedDict.map[keyName]) {
  15246. continue;
  15247. }
  15248. mergedDict.map[keyName] = dict.map[keyName];
  15249. }
  15250. }
  15251. return mergedDict;
  15252. };
  15253. return Dict;
  15254. })();
  15255. var Ref = (function RefClosure() {
  15256. function Ref(num, gen) {
  15257. this.num = num;
  15258. this.gen = gen;
  15259. }
  15260. Ref.prototype = {
  15261. toString: function Ref_toString() {
  15262. // This function is hot, so we make the string as compact as possible.
  15263. // |this.gen| is almost always zero, so we treat that case specially.
  15264. var str = this.num + 'R';
  15265. if (this.gen !== 0) {
  15266. str += this.gen;
  15267. }
  15268. return str;
  15269. }
  15270. };
  15271. return Ref;
  15272. })();
  15273. // The reference is identified by number and generation.
  15274. // This structure stores only one instance of the reference.
  15275. var RefSet = (function RefSetClosure() {
  15276. function RefSet() {
  15277. this.dict = {};
  15278. }
  15279. RefSet.prototype = {
  15280. has: function RefSet_has(ref) {
  15281. return ref.toString() in this.dict;
  15282. },
  15283. put: function RefSet_put(ref) {
  15284. this.dict[ref.toString()] = true;
  15285. },
  15286. remove: function RefSet_remove(ref) {
  15287. delete this.dict[ref.toString()];
  15288. }
  15289. };
  15290. return RefSet;
  15291. })();
  15292. var RefSetCache = (function RefSetCacheClosure() {
  15293. function RefSetCache() {
  15294. this.dict = Object.create(null);
  15295. }
  15296. RefSetCache.prototype = {
  15297. get: function RefSetCache_get(ref) {
  15298. return this.dict[ref.toString()];
  15299. },
  15300. has: function RefSetCache_has(ref) {
  15301. return ref.toString() in this.dict;
  15302. },
  15303. put: function RefSetCache_put(ref, obj) {
  15304. this.dict[ref.toString()] = obj;
  15305. },
  15306. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15307. this.dict[ref.toString()] = this.get(aliasRef);
  15308. },
  15309. forEach: function RefSetCache_forEach(fn, thisArg) {
  15310. for (var i in this.dict) {
  15311. fn.call(thisArg, this.dict[i]);
  15312. }
  15313. },
  15314. clear: function RefSetCache_clear() {
  15315. this.dict = Object.create(null);
  15316. }
  15317. };
  15318. return RefSetCache;
  15319. })();
  15320. function isName(v) {
  15321. return v instanceof Name;
  15322. }
  15323. function isCmd(v, cmd) {
  15324. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15325. }
  15326. function isDict(v, type) {
  15327. if (!(v instanceof Dict)) {
  15328. return false;
  15329. }
  15330. if (!type) {
  15331. return true;
  15332. }
  15333. var dictType = v.get('Type');
  15334. return isName(dictType) && dictType.name === type;
  15335. }
  15336. function isRef(v) {
  15337. return v instanceof Ref;
  15338. }
  15339. function isStream(v) {
  15340. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15341. }
  15342. exports.Cmd = Cmd;
  15343. exports.Dict = Dict;
  15344. exports.Name = Name;
  15345. exports.Ref = Ref;
  15346. exports.RefSet = RefSet;
  15347. exports.RefSetCache = RefSetCache;
  15348. exports.isCmd = isCmd;
  15349. exports.isDict = isDict;
  15350. exports.isName = isName;
  15351. exports.isRef = isRef;
  15352. exports.isStream = isStream;
  15353. }));
  15354. (function (root, factory) {
  15355. {
  15356. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  15357. root.pdfjsDisplayDOMUtils);
  15358. }
  15359. }(this, function (exports, sharedUtil, displayDOMUtils) {
  15360. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  15361. var AnnotationType = sharedUtil.AnnotationType;
  15362. var Util = sharedUtil.Util;
  15363. var isExternalLinkTargetSet = sharedUtil.isExternalLinkTargetSet;
  15364. var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
  15365. var removeNullCharacters = sharedUtil.removeNullCharacters;
  15366. var warn = sharedUtil.warn;
  15367. var CustomStyle = displayDOMUtils.CustomStyle;
  15368. /**
  15369. * @typedef {Object} AnnotationElementParameters
  15370. * @property {Object} data
  15371. * @property {HTMLDivElement} layer
  15372. * @property {PDFPage} page
  15373. * @property {PageViewport} viewport
  15374. * @property {IPDFLinkService} linkService
  15375. */
  15376. /**
  15377. * @class
  15378. * @alias AnnotationElementFactory
  15379. */
  15380. function AnnotationElementFactory() {}
  15381. AnnotationElementFactory.prototype =
  15382. /** @lends AnnotationElementFactory.prototype */ {
  15383. /**
  15384. * @param {AnnotationElementParameters} parameters
  15385. * @returns {AnnotationElement}
  15386. */
  15387. create: function AnnotationElementFactory_create(parameters) {
  15388. var subtype = parameters.data.annotationType;
  15389. switch (subtype) {
  15390. case AnnotationType.LINK:
  15391. return new LinkAnnotationElement(parameters);
  15392. case AnnotationType.TEXT:
  15393. return new TextAnnotationElement(parameters);
  15394. case AnnotationType.WIDGET:
  15395. return new WidgetAnnotationElement(parameters);
  15396. case AnnotationType.POPUP:
  15397. return new PopupAnnotationElement(parameters);
  15398. case AnnotationType.HIGHLIGHT:
  15399. return new HighlightAnnotationElement(parameters);
  15400. case AnnotationType.UNDERLINE:
  15401. return new UnderlineAnnotationElement(parameters);
  15402. case AnnotationType.SQUIGGLY:
  15403. return new SquigglyAnnotationElement(parameters);
  15404. case AnnotationType.STRIKEOUT:
  15405. return new StrikeOutAnnotationElement(parameters);
  15406. default:
  15407. throw new Error('Unimplemented annotation type "' + subtype + '"');
  15408. }
  15409. }
  15410. };
  15411. /**
  15412. * @class
  15413. * @alias AnnotationElement
  15414. */
  15415. var AnnotationElement = (function AnnotationElementClosure() {
  15416. function AnnotationElement(parameters) {
  15417. this.data = parameters.data;
  15418. this.layer = parameters.layer;
  15419. this.page = parameters.page;
  15420. this.viewport = parameters.viewport;
  15421. this.linkService = parameters.linkService;
  15422. this.container = this._createContainer();
  15423. }
  15424. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  15425. /**
  15426. * Create an empty container for the annotation's HTML element.
  15427. *
  15428. * @private
  15429. * @memberof AnnotationElement
  15430. * @returns {HTMLSectionElement}
  15431. */
  15432. _createContainer: function AnnotationElement_createContainer() {
  15433. var data = this.data, page = this.page, viewport = this.viewport;
  15434. var container = document.createElement('section');
  15435. var width = data.rect[2] - data.rect[0];
  15436. var height = data.rect[3] - data.rect[1];
  15437. container.setAttribute('data-annotation-id', data.id);
  15438. // Do *not* modify `data.rect`, since that will corrupt the annotation
  15439. // position on subsequent calls to `_createContainer` (see issue 6804).
  15440. var rect = Util.normalizeRect([
  15441. data.rect[0],
  15442. page.view[3] - data.rect[1] + page.view[1],
  15443. data.rect[2],
  15444. page.view[3] - data.rect[3] + page.view[1]
  15445. ]);
  15446. CustomStyle.setProp('transform', container,
  15447. 'matrix(' + viewport.transform.join(',') + ')');
  15448. CustomStyle.setProp('transformOrigin', container,
  15449. -rect[0] + 'px ' + -rect[1] + 'px');
  15450. if (data.borderStyle.width > 0) {
  15451. container.style.borderWidth = data.borderStyle.width + 'px';
  15452. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  15453. // Underline styles only have a bottom border, so we do not need
  15454. // to adjust for all borders. This yields a similar result as
  15455. // Adobe Acrobat/Reader.
  15456. width = width - 2 * data.borderStyle.width;
  15457. height = height - 2 * data.borderStyle.width;
  15458. }
  15459. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  15460. var verticalRadius = data.borderStyle.verticalCornerRadius;
  15461. if (horizontalRadius > 0 || verticalRadius > 0) {
  15462. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  15463. CustomStyle.setProp('borderRadius', container, radius);
  15464. }
  15465. switch (data.borderStyle.style) {
  15466. case AnnotationBorderStyleType.SOLID:
  15467. container.style.borderStyle = 'solid';
  15468. break;
  15469. case AnnotationBorderStyleType.DASHED:
  15470. container.style.borderStyle = 'dashed';
  15471. break;
  15472. case AnnotationBorderStyleType.BEVELED:
  15473. warn('Unimplemented border style: beveled');
  15474. break;
  15475. case AnnotationBorderStyleType.INSET:
  15476. warn('Unimplemented border style: inset');
  15477. break;
  15478. case AnnotationBorderStyleType.UNDERLINE:
  15479. container.style.borderBottomStyle = 'solid';
  15480. break;
  15481. default:
  15482. break;
  15483. }
  15484. if (data.color) {
  15485. container.style.borderColor =
  15486. Util.makeCssRgb(data.color[0] | 0,
  15487. data.color[1] | 0,
  15488. data.color[2] | 0);
  15489. } else {
  15490. // Transparent (invisible) border, so do not draw it at all.
  15491. container.style.borderWidth = 0;
  15492. }
  15493. }
  15494. container.style.left = rect[0] + 'px';
  15495. container.style.top = rect[1] + 'px';
  15496. container.style.width = width + 'px';
  15497. container.style.height = height + 'px';
  15498. return container;
  15499. },
  15500. /**
  15501. * Render the annotation's HTML element in the empty container.
  15502. *
  15503. * @public
  15504. * @memberof AnnotationElement
  15505. */
  15506. render: function AnnotationElement_render() {
  15507. throw new Error('Abstract method AnnotationElement.render called');
  15508. }
  15509. };
  15510. return AnnotationElement;
  15511. })();
  15512. /**
  15513. * @class
  15514. * @alias LinkAnnotationElement
  15515. */
  15516. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  15517. function LinkAnnotationElement(parameters) {
  15518. AnnotationElement.call(this, parameters);
  15519. }
  15520. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  15521. /**
  15522. * Render the link annotation's HTML element in the empty container.
  15523. *
  15524. * @public
  15525. * @memberof LinkAnnotationElement
  15526. * @returns {HTMLSectionElement}
  15527. */
  15528. render: function LinkAnnotationElement_render() {
  15529. this.container.className = 'linkAnnotation';
  15530. var link = document.createElement('a');
  15531. link.href = link.title = (this.data.url ?
  15532. removeNullCharacters(this.data.url) : '');
  15533. if (this.data.url && isExternalLinkTargetSet()) {
  15534. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  15535. }
  15536. // Strip referrer from the URL.
  15537. if (this.data.url) {
  15538. link.rel = PDFJS.externalLinkRel;
  15539. }
  15540. if (!this.data.url) {
  15541. if (this.data.action) {
  15542. this._bindNamedAction(link, this.data.action);
  15543. } else {
  15544. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  15545. }
  15546. }
  15547. this.container.appendChild(link);
  15548. return this.container;
  15549. },
  15550. /**
  15551. * Bind internal links to the link element.
  15552. *
  15553. * @private
  15554. * @param {Object} link
  15555. * @param {Object} destination
  15556. * @memberof LinkAnnotationElement
  15557. */
  15558. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  15559. var self = this;
  15560. link.href = this.linkService.getDestinationHash(destination);
  15561. link.onclick = function() {
  15562. if (destination) {
  15563. self.linkService.navigateTo(destination);
  15564. }
  15565. return false;
  15566. };
  15567. if (destination) {
  15568. link.className = 'internalLink';
  15569. }
  15570. },
  15571. /**
  15572. * Bind named actions to the link element.
  15573. *
  15574. * @private
  15575. * @param {Object} link
  15576. * @param {Object} action
  15577. * @memberof LinkAnnotationElement
  15578. */
  15579. _bindNamedAction:
  15580. function LinkAnnotationElement_bindNamedAction(link, action) {
  15581. var self = this;
  15582. link.href = this.linkService.getAnchorUrl('');
  15583. link.onclick = function() {
  15584. self.linkService.executeNamedAction(action);
  15585. return false;
  15586. };
  15587. link.className = 'internalLink';
  15588. }
  15589. });
  15590. return LinkAnnotationElement;
  15591. })();
  15592. /**
  15593. * @class
  15594. * @alias TextAnnotationElement
  15595. */
  15596. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  15597. function TextAnnotationElement(parameters) {
  15598. AnnotationElement.call(this, parameters);
  15599. }
  15600. Util.inherit(TextAnnotationElement, AnnotationElement, {
  15601. /**
  15602. * Render the text annotation's HTML element in the empty container.
  15603. *
  15604. * @public
  15605. * @memberof TextAnnotationElement
  15606. * @returns {HTMLSectionElement}
  15607. */
  15608. render: function TextAnnotationElement_render() {
  15609. this.container.className = 'textAnnotation';
  15610. var image = document.createElement('img');
  15611. image.style.height = this.container.style.height;
  15612. image.style.width = this.container.style.width;
  15613. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  15614. this.data.name.toLowerCase() + '.svg';
  15615. image.alt = '[{{type}} Annotation]';
  15616. image.dataset.l10nId = 'text_annotation_type';
  15617. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  15618. if (!this.data.hasPopup) {
  15619. var popupElement = new PopupElement({
  15620. container: this.container,
  15621. trigger: image,
  15622. color: this.data.color,
  15623. title: this.data.title,
  15624. contents: this.data.contents,
  15625. hideWrapper: true
  15626. });
  15627. var popup = popupElement.render();
  15628. // Position the popup next to the Text annotation's container.
  15629. popup.style.left = image.style.width;
  15630. this.container.appendChild(popup);
  15631. }
  15632. this.container.appendChild(image);
  15633. return this.container;
  15634. }
  15635. });
  15636. return TextAnnotationElement;
  15637. })();
  15638. /**
  15639. * @class
  15640. * @alias WidgetAnnotationElement
  15641. */
  15642. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  15643. function WidgetAnnotationElement(parameters) {
  15644. AnnotationElement.call(this, parameters);
  15645. }
  15646. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  15647. /**
  15648. * Render the widget annotation's HTML element in the empty container.
  15649. *
  15650. * @public
  15651. * @memberof WidgetAnnotationElement
  15652. * @returns {HTMLSectionElement}
  15653. */
  15654. render: function WidgetAnnotationElement_render() {
  15655. var content = document.createElement('div');
  15656. content.textContent = this.data.fieldValue;
  15657. var textAlignment = this.data.textAlignment;
  15658. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  15659. content.style.verticalAlign = 'middle';
  15660. content.style.display = 'table-cell';
  15661. var font = (this.data.fontRefName ?
  15662. this.page.commonObjs.getData(this.data.fontRefName) : null);
  15663. this._setTextStyle(content, font);
  15664. this.container.appendChild(content);
  15665. return this.container;
  15666. },
  15667. /**
  15668. * Apply text styles to the text in the element.
  15669. *
  15670. * @private
  15671. * @param {HTMLDivElement} element
  15672. * @param {Object} font
  15673. * @memberof WidgetAnnotationElement
  15674. */
  15675. _setTextStyle:
  15676. function WidgetAnnotationElement_setTextStyle(element, font) {
  15677. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  15678. var style = element.style;
  15679. style.fontSize = this.data.fontSize + 'px';
  15680. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  15681. if (!font) {
  15682. return;
  15683. }
  15684. style.fontWeight = (font.black ?
  15685. (font.bold ? '900' : 'bold') :
  15686. (font.bold ? 'bold' : 'normal'));
  15687. style.fontStyle = (font.italic ? 'italic' : 'normal');
  15688. // Use a reasonable default font if the font doesn't specify a fallback.
  15689. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  15690. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  15691. style.fontFamily = fontFamily + fallbackName;
  15692. }
  15693. });
  15694. return WidgetAnnotationElement;
  15695. })();
  15696. /**
  15697. * @class
  15698. * @alias PopupAnnotationElement
  15699. */
  15700. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  15701. function PopupAnnotationElement(parameters) {
  15702. AnnotationElement.call(this, parameters);
  15703. }
  15704. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  15705. /**
  15706. * Render the popup annotation's HTML element in the empty container.
  15707. *
  15708. * @public
  15709. * @memberof PopupAnnotationElement
  15710. * @returns {HTMLSectionElement}
  15711. */
  15712. render: function PopupAnnotationElement_render() {
  15713. this.container.className = 'popupAnnotation';
  15714. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  15715. var parentElement = this.layer.querySelector(selector);
  15716. if (!parentElement) {
  15717. return this.container;
  15718. }
  15719. var popup = new PopupElement({
  15720. container: this.container,
  15721. trigger: parentElement,
  15722. color: this.data.color,
  15723. title: this.data.title,
  15724. contents: this.data.contents
  15725. });
  15726. // Position the popup next to the parent annotation's container.
  15727. // PDF viewers ignore a popup annotation's rectangle.
  15728. var parentLeft = parseFloat(parentElement.style.left);
  15729. var parentWidth = parseFloat(parentElement.style.width);
  15730. CustomStyle.setProp('transformOrigin', this.container,
  15731. -(parentLeft + parentWidth) + 'px -' +
  15732. parentElement.style.top);
  15733. this.container.style.left = (parentLeft + parentWidth) + 'px';
  15734. this.container.appendChild(popup.render());
  15735. return this.container;
  15736. }
  15737. });
  15738. return PopupAnnotationElement;
  15739. })();
  15740. /**
  15741. * @class
  15742. * @alias PopupElement
  15743. */
  15744. var PopupElement = (function PopupElementClosure() {
  15745. var BACKGROUND_ENLIGHT = 0.7;
  15746. function PopupElement(parameters) {
  15747. this.container = parameters.container;
  15748. this.trigger = parameters.trigger;
  15749. this.color = parameters.color;
  15750. this.title = parameters.title;
  15751. this.contents = parameters.contents;
  15752. this.hideWrapper = parameters.hideWrapper || false;
  15753. this.pinned = false;
  15754. }
  15755. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  15756. /**
  15757. * Render the popup's HTML element.
  15758. *
  15759. * @public
  15760. * @memberof PopupElement
  15761. * @returns {HTMLSectionElement}
  15762. */
  15763. render: function PopupElement_render() {
  15764. var wrapper = document.createElement('div');
  15765. wrapper.className = 'popupWrapper';
  15766. // For Popup annotations we hide the entire section because it contains
  15767. // only the popup. However, for Text annotations without a separate Popup
  15768. // annotation, we cannot hide the entire container as the image would
  15769. // disappear too. In that special case, hiding the wrapper suffices.
  15770. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  15771. this.hideElement.setAttribute('hidden', true);
  15772. var popup = document.createElement('div');
  15773. popup.className = 'popup';
  15774. var color = this.color;
  15775. if (color) {
  15776. // Enlighten the color.
  15777. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  15778. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  15779. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  15780. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  15781. }
  15782. var contents = this._formatContents(this.contents);
  15783. var title = document.createElement('h1');
  15784. title.textContent = this.title;
  15785. // Attach the event listeners to the trigger element.
  15786. this.trigger.addEventListener('click', this._toggle.bind(this));
  15787. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  15788. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  15789. popup.addEventListener('click', this._hide.bind(this, true));
  15790. popup.appendChild(title);
  15791. popup.appendChild(contents);
  15792. wrapper.appendChild(popup);
  15793. return wrapper;
  15794. },
  15795. /**
  15796. * Format the contents of the popup by adding newlines where necessary.
  15797. *
  15798. * @private
  15799. * @param {string} contents
  15800. * @memberof PopupElement
  15801. * @returns {HTMLParagraphElement}
  15802. */
  15803. _formatContents: function PopupElement_formatContents(contents) {
  15804. var p = document.createElement('p');
  15805. var lines = contents.split(/(?:\r\n?|\n)/);
  15806. for (var i = 0, ii = lines.length; i < ii; ++i) {
  15807. var line = lines[i];
  15808. p.appendChild(document.createTextNode(line));
  15809. if (i < (ii - 1)) {
  15810. p.appendChild(document.createElement('br'));
  15811. }
  15812. }
  15813. return p;
  15814. },
  15815. /**
  15816. * Toggle the visibility of the popup.
  15817. *
  15818. * @private
  15819. * @memberof PopupElement
  15820. */
  15821. _toggle: function PopupElement_toggle() {
  15822. if (this.pinned) {
  15823. this._hide(true);
  15824. } else {
  15825. this._show(true);
  15826. }
  15827. },
  15828. /**
  15829. * Show the popup.
  15830. *
  15831. * @private
  15832. * @param {boolean} pin
  15833. * @memberof PopupElement
  15834. */
  15835. _show: function PopupElement_show(pin) {
  15836. if (pin) {
  15837. this.pinned = true;
  15838. }
  15839. if (this.hideElement.hasAttribute('hidden')) {
  15840. this.hideElement.removeAttribute('hidden');
  15841. this.container.style.zIndex += 1;
  15842. }
  15843. },
  15844. /**
  15845. * Hide the popup.
  15846. *
  15847. * @private
  15848. * @param {boolean} unpin
  15849. * @memberof PopupElement
  15850. */
  15851. _hide: function PopupElement_hide(unpin) {
  15852. if (unpin) {
  15853. this.pinned = false;
  15854. }
  15855. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  15856. this.hideElement.setAttribute('hidden', true);
  15857. this.container.style.zIndex -= 1;
  15858. }
  15859. }
  15860. };
  15861. return PopupElement;
  15862. })();
  15863. /**
  15864. * @class
  15865. * @alias HighlightAnnotationElement
  15866. */
  15867. var HighlightAnnotationElement = (
  15868. function HighlightAnnotationElementClosure() {
  15869. function HighlightAnnotationElement(parameters) {
  15870. AnnotationElement.call(this, parameters);
  15871. }
  15872. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  15873. /**
  15874. * Render the highlight annotation's HTML element in the empty container.
  15875. *
  15876. * @public
  15877. * @memberof HighlightAnnotationElement
  15878. * @returns {HTMLSectionElement}
  15879. */
  15880. render: function HighlightAnnotationElement_render() {
  15881. this.container.className = 'highlightAnnotation';
  15882. return this.container;
  15883. }
  15884. });
  15885. return HighlightAnnotationElement;
  15886. })();
  15887. /**
  15888. * @class
  15889. * @alias UnderlineAnnotationElement
  15890. */
  15891. var UnderlineAnnotationElement = (
  15892. function UnderlineAnnotationElementClosure() {
  15893. function UnderlineAnnotationElement(parameters) {
  15894. AnnotationElement.call(this, parameters);
  15895. }
  15896. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  15897. /**
  15898. * Render the underline annotation's HTML element in the empty container.
  15899. *
  15900. * @public
  15901. * @memberof UnderlineAnnotationElement
  15902. * @returns {HTMLSectionElement}
  15903. */
  15904. render: function UnderlineAnnotationElement_render() {
  15905. this.container.className = 'underlineAnnotation';
  15906. return this.container;
  15907. }
  15908. });
  15909. return UnderlineAnnotationElement;
  15910. })();
  15911. /**
  15912. * @class
  15913. * @alias SquigglyAnnotationElement
  15914. */
  15915. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  15916. function SquigglyAnnotationElement(parameters) {
  15917. AnnotationElement.call(this, parameters);
  15918. }
  15919. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  15920. /**
  15921. * Render the squiggly annotation's HTML element in the empty container.
  15922. *
  15923. * @public
  15924. * @memberof SquigglyAnnotationElement
  15925. * @returns {HTMLSectionElement}
  15926. */
  15927. render: function SquigglyAnnotationElement_render() {
  15928. this.container.className = 'squigglyAnnotation';
  15929. return this.container;
  15930. }
  15931. });
  15932. return SquigglyAnnotationElement;
  15933. })();
  15934. /**
  15935. * @class
  15936. * @alias StrikeOutAnnotationElement
  15937. */
  15938. var StrikeOutAnnotationElement = (
  15939. function StrikeOutAnnotationElementClosure() {
  15940. function StrikeOutAnnotationElement(parameters) {
  15941. AnnotationElement.call(this, parameters);
  15942. }
  15943. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  15944. /**
  15945. * Render the strikeout annotation's HTML element in the empty container.
  15946. *
  15947. * @public
  15948. * @memberof StrikeOutAnnotationElement
  15949. * @returns {HTMLSectionElement}
  15950. */
  15951. render: function StrikeOutAnnotationElement_render() {
  15952. this.container.className = 'strikeoutAnnotation';
  15953. return this.container;
  15954. }
  15955. });
  15956. return StrikeOutAnnotationElement;
  15957. })();
  15958. /**
  15959. * @typedef {Object} AnnotationLayerParameters
  15960. * @property {PageViewport} viewport
  15961. * @property {HTMLDivElement} div
  15962. * @property {Array} annotations
  15963. * @property {PDFPage} page
  15964. * @property {IPDFLinkService} linkService
  15965. */
  15966. /**
  15967. * @class
  15968. * @alias AnnotationLayer
  15969. */
  15970. var AnnotationLayer = (function AnnotationLayerClosure() {
  15971. return {
  15972. /**
  15973. * Render a new annotation layer with all annotation elements.
  15974. *
  15975. * @public
  15976. * @param {AnnotationLayerParameters} parameters
  15977. * @memberof AnnotationLayer
  15978. */
  15979. render: function AnnotationLayer_render(parameters) {
  15980. var annotationElementFactory = new AnnotationElementFactory();
  15981. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  15982. var data = parameters.annotations[i];
  15983. if (!data || !data.hasHtml) {
  15984. continue;
  15985. }
  15986. var properties = {
  15987. data: data,
  15988. layer: parameters.div,
  15989. page: parameters.page,
  15990. viewport: parameters.viewport,
  15991. linkService: parameters.linkService
  15992. };
  15993. var element = annotationElementFactory.create(properties);
  15994. parameters.div.appendChild(element.render());
  15995. }
  15996. },
  15997. /**
  15998. * Update the annotation elements on existing annotation layer.
  15999. *
  16000. * @public
  16001. * @param {AnnotationLayerParameters} parameters
  16002. * @memberof AnnotationLayer
  16003. */
  16004. update: function AnnotationLayer_update(parameters) {
  16005. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  16006. var data = parameters.annotations[i];
  16007. var element = parameters.div.querySelector(
  16008. '[data-annotation-id="' + data.id + '"]');
  16009. if (element) {
  16010. CustomStyle.setProp('transform', element,
  16011. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  16012. }
  16013. }
  16014. parameters.div.removeAttribute('hidden');
  16015. }
  16016. };
  16017. })();
  16018. PDFJS.AnnotationLayer = AnnotationLayer;
  16019. exports.AnnotationLayer = AnnotationLayer;
  16020. }));
  16021. (function (root, factory) {
  16022. {
  16023. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  16024. root.pdfjsSharedGlobal);
  16025. }
  16026. }(this, function (exports, sharedUtil, sharedGlobal) {
  16027. var assert = sharedUtil.assert;
  16028. var bytesToString = sharedUtil.bytesToString;
  16029. var string32 = sharedUtil.string32;
  16030. var shadow = sharedUtil.shadow;
  16031. var warn = sharedUtil.warn;
  16032. var PDFJS = sharedGlobal.PDFJS;
  16033. var globalScope = sharedGlobal.globalScope;
  16034. var isWorker = sharedGlobal.isWorker;
  16035. function FontLoader(docId) {
  16036. this.docId = docId;
  16037. this.styleElement = null;
  16038. this.nativeFontFaces = [];
  16039. this.loadTestFontId = 0;
  16040. this.loadingContext = {
  16041. requests: [],
  16042. nextRequestId: 0
  16043. };
  16044. }
  16045. FontLoader.prototype = {
  16046. insertRule: function fontLoaderInsertRule(rule) {
  16047. var styleElement = this.styleElement;
  16048. if (!styleElement) {
  16049. styleElement = this.styleElement = document.createElement('style');
  16050. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  16051. document.documentElement.getElementsByTagName('head')[0].appendChild(
  16052. styleElement);
  16053. }
  16054. var styleSheet = styleElement.sheet;
  16055. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  16056. },
  16057. clear: function fontLoaderClear() {
  16058. var styleElement = this.styleElement;
  16059. if (styleElement) {
  16060. styleElement.parentNode.removeChild(styleElement);
  16061. styleElement = this.styleElement = null;
  16062. }
  16063. this.nativeFontFaces.forEach(function(nativeFontFace) {
  16064. document.fonts.delete(nativeFontFace);
  16065. });
  16066. this.nativeFontFaces.length = 0;
  16067. },
  16068. get loadTestFont() {
  16069. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  16070. // height.
  16071. return shadow(this, 'loadTestFont', atob(
  16072. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  16073. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  16074. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  16075. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  16076. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  16077. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  16078. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  16079. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  16080. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  16081. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  16082. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  16083. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  16084. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  16085. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  16086. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  16087. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  16088. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  16089. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  16090. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  16091. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  16092. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  16093. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  16094. ));
  16095. },
  16096. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  16097. this.nativeFontFaces.push(nativeFontFace);
  16098. document.fonts.add(nativeFontFace);
  16099. },
  16100. bind: function fontLoaderBind(fonts, callback) {
  16101. assert(!isWorker, 'bind() shall be called from main thread');
  16102. var rules = [];
  16103. var fontsToLoad = [];
  16104. var fontLoadPromises = [];
  16105. var getNativeFontPromise = function(nativeFontFace) {
  16106. // Return a promise that is always fulfilled, even when the font fails to
  16107. // load.
  16108. return nativeFontFace.loaded.catch(function(e) {
  16109. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  16110. });
  16111. };
  16112. for (var i = 0, ii = fonts.length; i < ii; i++) {
  16113. var font = fonts[i];
  16114. // Add the font to the DOM only once or skip if the font
  16115. // is already loaded.
  16116. if (font.attached || font.loading === false) {
  16117. continue;
  16118. }
  16119. font.attached = true;
  16120. if (FontLoader.isFontLoadingAPISupported) {
  16121. var nativeFontFace = font.createNativeFontFace();
  16122. if (nativeFontFace) {
  16123. this.addNativeFontFace(nativeFontFace);
  16124. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  16125. }
  16126. } else {
  16127. var rule = font.createFontFaceRule();
  16128. if (rule) {
  16129. this.insertRule(rule);
  16130. rules.push(rule);
  16131. fontsToLoad.push(font);
  16132. }
  16133. }
  16134. }
  16135. var request = this.queueLoadingCallback(callback);
  16136. if (FontLoader.isFontLoadingAPISupported) {
  16137. Promise.all(fontLoadPromises).then(function() {
  16138. request.complete();
  16139. });
  16140. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  16141. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  16142. } else {
  16143. request.complete();
  16144. }
  16145. },
  16146. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  16147. function LoadLoader_completeRequest() {
  16148. assert(!request.end, 'completeRequest() cannot be called twice');
  16149. request.end = Date.now();
  16150. // sending all completed requests in order how they were queued
  16151. while (context.requests.length > 0 && context.requests[0].end) {
  16152. var otherRequest = context.requests.shift();
  16153. setTimeout(otherRequest.callback, 0);
  16154. }
  16155. }
  16156. var context = this.loadingContext;
  16157. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  16158. var request = {
  16159. id: requestId,
  16160. complete: LoadLoader_completeRequest,
  16161. callback: callback,
  16162. started: Date.now()
  16163. };
  16164. context.requests.push(request);
  16165. return request;
  16166. },
  16167. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  16168. fonts,
  16169. request) {
  16170. /** Hack begin */
  16171. // There's currently no event when a font has finished downloading so the
  16172. // following code is a dirty hack to 'guess' when a font is
  16173. // ready. It's assumed fonts are loaded in order, so add a known test
  16174. // font after the desired fonts and then test for the loading of that
  16175. // test font.
  16176. function int32(data, offset) {
  16177. return (data.charCodeAt(offset) << 24) |
  16178. (data.charCodeAt(offset + 1) << 16) |
  16179. (data.charCodeAt(offset + 2) << 8) |
  16180. (data.charCodeAt(offset + 3) & 0xff);
  16181. }
  16182. function spliceString(s, offset, remove, insert) {
  16183. var chunk1 = s.substr(0, offset);
  16184. var chunk2 = s.substr(offset + remove);
  16185. return chunk1 + insert + chunk2;
  16186. }
  16187. var i, ii;
  16188. var canvas = document.createElement('canvas');
  16189. canvas.width = 1;
  16190. canvas.height = 1;
  16191. var ctx = canvas.getContext('2d');
  16192. var called = 0;
  16193. function isFontReady(name, callback) {
  16194. called++;
  16195. // With setTimeout clamping this gives the font ~100ms to load.
  16196. if(called > 30) {
  16197. warn('Load test font never loaded.');
  16198. callback();
  16199. return;
  16200. }
  16201. ctx.font = '30px ' + name;
  16202. ctx.fillText('.', 0, 20);
  16203. var imageData = ctx.getImageData(0, 0, 1, 1);
  16204. if (imageData.data[3] > 0) {
  16205. callback();
  16206. return;
  16207. }
  16208. setTimeout(isFontReady.bind(null, name, callback));
  16209. }
  16210. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  16211. // Chromium seems to cache fonts based on a hash of the actual font data,
  16212. // so the font must be modified for each load test else it will appear to
  16213. // be loaded already.
  16214. // TODO: This could maybe be made faster by avoiding the btoa of the full
  16215. // font by splitting it in chunks before hand and padding the font id.
  16216. var data = this.loadTestFont;
  16217. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  16218. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  16219. loadTestFontId);
  16220. // CFF checksum is important for IE, adjusting it
  16221. var CFF_CHECKSUM_OFFSET = 16;
  16222. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  16223. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  16224. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  16225. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  16226. }
  16227. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  16228. checksum = (checksum - XXXX_VALUE +
  16229. int32(loadTestFontId + 'XXX', i)) | 0;
  16230. }
  16231. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  16232. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  16233. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  16234. url + '}';
  16235. this.insertRule(rule);
  16236. var names = [];
  16237. for (i = 0, ii = fonts.length; i < ii; i++) {
  16238. names.push(fonts[i].loadedName);
  16239. }
  16240. names.push(loadTestFontId);
  16241. var div = document.createElement('div');
  16242. div.setAttribute('style',
  16243. 'visibility: hidden;' +
  16244. 'width: 10px; height: 10px;' +
  16245. 'position: absolute; top: 0px; left: 0px;');
  16246. for (i = 0, ii = names.length; i < ii; ++i) {
  16247. var span = document.createElement('span');
  16248. span.textContent = 'Hi';
  16249. span.style.fontFamily = names[i];
  16250. div.appendChild(span);
  16251. }
  16252. document.body.appendChild(div);
  16253. isFontReady(loadTestFontId, function() {
  16254. document.body.removeChild(div);
  16255. request.complete();
  16256. });
  16257. /** Hack end */
  16258. }
  16259. };
  16260. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  16261. typeof document !== 'undefined' && !!document.fonts);
  16262. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  16263. get: function () {
  16264. var supported = false;
  16265. // User agent string sniffing is bad, but there is no reliable way to tell
  16266. // if font is fully loaded and ready to be used with canvas.
  16267. var userAgent = window.navigator.userAgent;
  16268. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  16269. if (m && m[1] >= 14) {
  16270. supported = true;
  16271. }
  16272. // TODO other browsers
  16273. if (userAgent === 'node') {
  16274. supported = true;
  16275. }
  16276. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  16277. },
  16278. enumerable: true,
  16279. configurable: true
  16280. });
  16281. var FontFaceObject = (function FontFaceObjectClosure() {
  16282. function FontFaceObject(translatedData) {
  16283. this.compiledGlyphs = {};
  16284. // importing translated data
  16285. for (var i in translatedData) {
  16286. this[i] = translatedData[i];
  16287. }
  16288. }
  16289. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  16290. get: function () {
  16291. var evalSupport = false;
  16292. if (PDFJS.isEvalSupported) {
  16293. try {
  16294. /* jshint evil: true */
  16295. new Function('');
  16296. evalSupport = true;
  16297. } catch (e) {}
  16298. }
  16299. return shadow(this, 'isEvalSupported', evalSupport);
  16300. },
  16301. enumerable: true,
  16302. configurable: true
  16303. });
  16304. FontFaceObject.prototype = {
  16305. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  16306. if (!this.data) {
  16307. return null;
  16308. }
  16309. if (PDFJS.disableFontFace) {
  16310. this.disableFontFace = true;
  16311. return null;
  16312. }
  16313. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  16314. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  16315. globalScope['FontInspector'].enabled) {
  16316. globalScope['FontInspector'].fontAdded(this);
  16317. }
  16318. return nativeFontFace;
  16319. },
  16320. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  16321. if (!this.data) {
  16322. return null;
  16323. }
  16324. if (PDFJS.disableFontFace) {
  16325. this.disableFontFace = true;
  16326. return null;
  16327. }
  16328. var data = bytesToString(new Uint8Array(this.data));
  16329. var fontName = this.loadedName;
  16330. // Add the font-face rule to the document
  16331. var url = ('url(data:' + this.mimetype + ';base64,' +
  16332. window.btoa(data) + ');');
  16333. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  16334. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  16335. globalScope['FontInspector'].enabled) {
  16336. globalScope['FontInspector'].fontAdded(this, url);
  16337. }
  16338. return rule;
  16339. },
  16340. getPathGenerator:
  16341. function FontFaceObject_getPathGenerator(objs, character) {
  16342. if (!(character in this.compiledGlyphs)) {
  16343. var cmds = objs.get(this.loadedName + '_path_' + character);
  16344. var current, i, len;
  16345. // If we can, compile cmds into JS for MAXIMUM SPEED
  16346. if (FontFaceObject.isEvalSupported) {
  16347. var args, js = '';
  16348. for (i = 0, len = cmds.length; i < len; i++) {
  16349. current = cmds[i];
  16350. if (current.args !== undefined) {
  16351. args = current.args.join(',');
  16352. } else {
  16353. args = '';
  16354. }
  16355. js += 'c.' + current.cmd + '(' + args + ');\n';
  16356. }
  16357. /* jshint -W054 */
  16358. this.compiledGlyphs[character] = new Function('c', 'size', js);
  16359. } else {
  16360. // But fall back on using Function.prototype.apply() if we're
  16361. // blocked from using eval() for whatever reason (like CSP policies)
  16362. this.compiledGlyphs[character] = function(c, size) {
  16363. for (i = 0, len = cmds.length; i < len; i++) {
  16364. current = cmds[i];
  16365. if (current.cmd === 'scale') {
  16366. current.args = [size, -size];
  16367. }
  16368. c[current.cmd].apply(c, current.args);
  16369. }
  16370. };
  16371. }
  16372. }
  16373. return this.compiledGlyphs[character];
  16374. }
  16375. };
  16376. return FontFaceObject;
  16377. })();
  16378. exports.FontFaceObject = FontFaceObject;
  16379. exports.FontLoader = FontLoader;
  16380. }));
  16381. (function (root, factory) {
  16382. {
  16383. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  16384. }
  16385. }(this, function (exports, sharedUtil) {
  16386. var error = sharedUtil.error;
  16387. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  16388. function fixMetadata(meta) {
  16389. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  16390. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  16391. function(code, d1, d2, d3) {
  16392. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  16393. });
  16394. var chars = '';
  16395. for (var i = 0; i < bytes.length; i += 2) {
  16396. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  16397. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  16398. code !== 38 && false ? String.fromCharCode(code) :
  16399. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  16400. }
  16401. return '>' + chars;
  16402. });
  16403. }
  16404. function Metadata(meta) {
  16405. if (typeof meta === 'string') {
  16406. // Ghostscript produces invalid metadata
  16407. meta = fixMetadata(meta);
  16408. var parser = new DOMParser();
  16409. meta = parser.parseFromString(meta, 'application/xml');
  16410. } else if (!(meta instanceof Document)) {
  16411. error('Metadata: Invalid metadata object');
  16412. }
  16413. this.metaDocument = meta;
  16414. this.metadata = {};
  16415. this.parse();
  16416. }
  16417. Metadata.prototype = {
  16418. parse: function Metadata_parse() {
  16419. var doc = this.metaDocument;
  16420. var rdf = doc.documentElement;
  16421. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  16422. rdf = rdf.firstChild;
  16423. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  16424. rdf = rdf.nextSibling;
  16425. }
  16426. }
  16427. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  16428. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  16429. return;
  16430. }
  16431. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  16432. for (i = 0, length = children.length; i < length; i++) {
  16433. desc = children[i];
  16434. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  16435. continue;
  16436. }
  16437. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  16438. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  16439. entry = desc.childNodes[ii];
  16440. name = entry.nodeName.toLowerCase();
  16441. this.metadata[name] = entry.textContent.trim();
  16442. }
  16443. }
  16444. }
  16445. },
  16446. get: function Metadata_get(name) {
  16447. return this.metadata[name] || null;
  16448. },
  16449. has: function Metadata_has(name) {
  16450. return typeof this.metadata[name] !== 'undefined';
  16451. }
  16452. };
  16453. return Metadata;
  16454. })();
  16455. exports.Metadata = Metadata;
  16456. }));
  16457. (function (root, factory) {
  16458. {
  16459. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  16460. }
  16461. }(this, function (exports, sharedUtil) {
  16462. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  16463. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  16464. var ImageKind = sharedUtil.ImageKind;
  16465. var OPS = sharedUtil.OPS;
  16466. var Util = sharedUtil.Util;
  16467. var isNum = sharedUtil.isNum;
  16468. var isArray = sharedUtil.isArray;
  16469. var warn = sharedUtil.warn;
  16470. var SVG_DEFAULTS = {
  16471. fontStyle: 'normal',
  16472. fontWeight: 'normal',
  16473. fillColor: '#000000'
  16474. };
  16475. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  16476. var PNG_HEADER =
  16477. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  16478. var CHUNK_WRAPPER_SIZE = 12;
  16479. var crcTable = new Int32Array(256);
  16480. for (var i = 0; i < 256; i++) {
  16481. var c = i;
  16482. for (var h = 0; h < 8; h++) {
  16483. if (c & 1) {
  16484. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  16485. } else {
  16486. c = (c >> 1) & 0x7fffffff;
  16487. }
  16488. }
  16489. crcTable[i] = c;
  16490. }
  16491. function crc32(data, start, end) {
  16492. var crc = -1;
  16493. for (var i = start; i < end; i++) {
  16494. var a = (crc ^ data[i]) & 0xff;
  16495. var b = crcTable[a];
  16496. crc = (crc >>> 8) ^ b;
  16497. }
  16498. return crc ^ -1;
  16499. }
  16500. function writePngChunk(type, body, data, offset) {
  16501. var p = offset;
  16502. var len = body.length;
  16503. data[p] = len >> 24 & 0xff;
  16504. data[p + 1] = len >> 16 & 0xff;
  16505. data[p + 2] = len >> 8 & 0xff;
  16506. data[p + 3] = len & 0xff;
  16507. p += 4;
  16508. data[p] = type.charCodeAt(0) & 0xff;
  16509. data[p + 1] = type.charCodeAt(1) & 0xff;
  16510. data[p + 2] = type.charCodeAt(2) & 0xff;
  16511. data[p + 3] = type.charCodeAt(3) & 0xff;
  16512. p += 4;
  16513. data.set(body, p);
  16514. p += body.length;
  16515. var crc = crc32(data, offset + 4, p);
  16516. data[p] = crc >> 24 & 0xff;
  16517. data[p + 1] = crc >> 16 & 0xff;
  16518. data[p + 2] = crc >> 8 & 0xff;
  16519. data[p + 3] = crc & 0xff;
  16520. }
  16521. function adler32(data, start, end) {
  16522. var a = 1;
  16523. var b = 0;
  16524. for (var i = start; i < end; ++i) {
  16525. a = (a + (data[i] & 0xff)) % 65521;
  16526. b = (b + a) % 65521;
  16527. }
  16528. return (b << 16) | a;
  16529. }
  16530. function encode(imgData, kind) {
  16531. var width = imgData.width;
  16532. var height = imgData.height;
  16533. var bitDepth, colorType, lineSize;
  16534. var bytes = imgData.data;
  16535. switch (kind) {
  16536. case ImageKind.GRAYSCALE_1BPP:
  16537. colorType = 0;
  16538. bitDepth = 1;
  16539. lineSize = (width + 7) >> 3;
  16540. break;
  16541. case ImageKind.RGB_24BPP:
  16542. colorType = 2;
  16543. bitDepth = 8;
  16544. lineSize = width * 3;
  16545. break;
  16546. case ImageKind.RGBA_32BPP:
  16547. colorType = 6;
  16548. bitDepth = 8;
  16549. lineSize = width * 4;
  16550. break;
  16551. default:
  16552. throw new Error('invalid format');
  16553. }
  16554. // prefix every row with predictor 0
  16555. var literals = new Uint8Array((1 + lineSize) * height);
  16556. var offsetLiterals = 0, offsetBytes = 0;
  16557. var y, i;
  16558. for (y = 0; y < height; ++y) {
  16559. literals[offsetLiterals++] = 0; // no prediction
  16560. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  16561. offsetLiterals);
  16562. offsetBytes += lineSize;
  16563. offsetLiterals += lineSize;
  16564. }
  16565. if (kind === ImageKind.GRAYSCALE_1BPP) {
  16566. // inverting for B/W
  16567. offsetLiterals = 0;
  16568. for (y = 0; y < height; y++) {
  16569. offsetLiterals++; // skipping predictor
  16570. for (i = 0; i < lineSize; i++) {
  16571. literals[offsetLiterals++] ^= 0xFF;
  16572. }
  16573. }
  16574. }
  16575. var ihdr = new Uint8Array([
  16576. width >> 24 & 0xff,
  16577. width >> 16 & 0xff,
  16578. width >> 8 & 0xff,
  16579. width & 0xff,
  16580. height >> 24 & 0xff,
  16581. height >> 16 & 0xff,
  16582. height >> 8 & 0xff,
  16583. height & 0xff,
  16584. bitDepth, // bit depth
  16585. colorType, // color type
  16586. 0x00, // compression method
  16587. 0x00, // filter method
  16588. 0x00 // interlace method
  16589. ]);
  16590. var len = literals.length;
  16591. var maxBlockLength = 0xFFFF;
  16592. var deflateBlocks = Math.ceil(len / maxBlockLength);
  16593. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  16594. var pi = 0;
  16595. idat[pi++] = 0x78; // compression method and flags
  16596. idat[pi++] = 0x9c; // flags
  16597. var pos = 0;
  16598. while (len > maxBlockLength) {
  16599. // writing non-final DEFLATE blocks type 0 and length of 65535
  16600. idat[pi++] = 0x00;
  16601. idat[pi++] = 0xff;
  16602. idat[pi++] = 0xff;
  16603. idat[pi++] = 0x00;
  16604. idat[pi++] = 0x00;
  16605. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  16606. pi += maxBlockLength;
  16607. pos += maxBlockLength;
  16608. len -= maxBlockLength;
  16609. }
  16610. // writing non-final DEFLATE blocks type 0
  16611. idat[pi++] = 0x01;
  16612. idat[pi++] = len & 0xff;
  16613. idat[pi++] = len >> 8 & 0xff;
  16614. idat[pi++] = (~len & 0xffff) & 0xff;
  16615. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  16616. idat.set(literals.subarray(pos), pi);
  16617. pi += literals.length - pos;
  16618. var adler = adler32(literals, 0, literals.length); // checksum
  16619. idat[pi++] = adler >> 24 & 0xff;
  16620. idat[pi++] = adler >> 16 & 0xff;
  16621. idat[pi++] = adler >> 8 & 0xff;
  16622. idat[pi++] = adler & 0xff;
  16623. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  16624. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  16625. ihdr.length + idat.length;
  16626. var data = new Uint8Array(pngLength);
  16627. var offset = 0;
  16628. data.set(PNG_HEADER, offset);
  16629. offset += PNG_HEADER.length;
  16630. writePngChunk('IHDR', ihdr, data, offset);
  16631. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  16632. writePngChunk('IDATA', idat, data, offset);
  16633. offset += CHUNK_WRAPPER_SIZE + idat.length;
  16634. writePngChunk('IEND', new Uint8Array(0), data, offset);
  16635. return PDFJS.createObjectURL(data, 'image/png');
  16636. }
  16637. return function convertImgDataToPng(imgData) {
  16638. var kind = (imgData.kind === undefined ?
  16639. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  16640. return encode(imgData, kind);
  16641. };
  16642. })();
  16643. var SVGExtraState = (function SVGExtraStateClosure() {
  16644. function SVGExtraState() {
  16645. this.fontSizeScale = 1;
  16646. this.fontWeight = SVG_DEFAULTS.fontWeight;
  16647. this.fontSize = 0;
  16648. this.textMatrix = IDENTITY_MATRIX;
  16649. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16650. this.leading = 0;
  16651. // Current point (in user coordinates)
  16652. this.x = 0;
  16653. this.y = 0;
  16654. // Start of text line (in text coordinates)
  16655. this.lineX = 0;
  16656. this.lineY = 0;
  16657. // Character and word spacing
  16658. this.charSpacing = 0;
  16659. this.wordSpacing = 0;
  16660. this.textHScale = 1;
  16661. this.textRise = 0;
  16662. // Default foreground and background colors
  16663. this.fillColor = SVG_DEFAULTS.fillColor;
  16664. this.strokeColor = '#000000';
  16665. this.fillAlpha = 1;
  16666. this.strokeAlpha = 1;
  16667. this.lineWidth = 1;
  16668. this.lineJoin = '';
  16669. this.lineCap = '';
  16670. this.miterLimit = 0;
  16671. this.dashArray = [];
  16672. this.dashPhase = 0;
  16673. this.dependencies = [];
  16674. // Clipping
  16675. this.clipId = '';
  16676. this.pendingClip = false;
  16677. this.maskId = '';
  16678. }
  16679. SVGExtraState.prototype = {
  16680. clone: function SVGExtraState_clone() {
  16681. return Object.create(this);
  16682. },
  16683. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  16684. this.x = x;
  16685. this.y = y;
  16686. }
  16687. };
  16688. return SVGExtraState;
  16689. })();
  16690. var SVGGraphics = (function SVGGraphicsClosure() {
  16691. function createScratchSVG(width, height) {
  16692. var NS = 'http://www.w3.org/2000/svg';
  16693. var svg = document.createElementNS(NS, 'svg:svg');
  16694. svg.setAttributeNS(null, 'version', '1.1');
  16695. svg.setAttributeNS(null, 'width', width + 'px');
  16696. svg.setAttributeNS(null, 'height', height + 'px');
  16697. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  16698. return svg;
  16699. }
  16700. function opListToTree(opList) {
  16701. var opTree = [];
  16702. var tmp = [];
  16703. var opListLen = opList.length;
  16704. for (var x = 0; x < opListLen; x++) {
  16705. if (opList[x].fn === 'save') {
  16706. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  16707. tmp.push(opTree);
  16708. opTree = opTree[opTree.length - 1].items;
  16709. continue;
  16710. }
  16711. if(opList[x].fn === 'restore') {
  16712. opTree = tmp.pop();
  16713. } else {
  16714. opTree.push(opList[x]);
  16715. }
  16716. }
  16717. return opTree;
  16718. }
  16719. /**
  16720. * Formats float number.
  16721. * @param value {number} number to format.
  16722. * @returns {string}
  16723. */
  16724. function pf(value) {
  16725. if (value === (value | 0)) { // integer number
  16726. return value.toString();
  16727. }
  16728. var s = value.toFixed(10);
  16729. var i = s.length - 1;
  16730. if (s[i] !== '0') {
  16731. return s;
  16732. }
  16733. // removing trailing zeros
  16734. do {
  16735. i--;
  16736. } while (s[i] === '0');
  16737. return s.substr(0, s[i] === '.' ? i : i + 1);
  16738. }
  16739. /**
  16740. * Formats transform matrix. The standard rotation, scale and translate
  16741. * matrices are replaced by their shorter forms, and for identity matrix
  16742. * returns empty string to save the memory.
  16743. * @param m {Array} matrix to format.
  16744. * @returns {string}
  16745. */
  16746. function pm(m) {
  16747. if (m[4] === 0 && m[5] === 0) {
  16748. if (m[1] === 0 && m[2] === 0) {
  16749. if (m[0] === 1 && m[3] === 1) {
  16750. return '';
  16751. }
  16752. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  16753. }
  16754. if (m[0] === m[3] && m[1] === -m[2]) {
  16755. var a = Math.acos(m[0]) * 180 / Math.PI;
  16756. return 'rotate(' + pf(a) + ')';
  16757. }
  16758. } else {
  16759. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  16760. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  16761. }
  16762. }
  16763. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  16764. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  16765. }
  16766. function SVGGraphics(commonObjs, objs) {
  16767. this.current = new SVGExtraState();
  16768. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  16769. this.transformStack = [];
  16770. this.extraStack = [];
  16771. this.commonObjs = commonObjs;
  16772. this.objs = objs;
  16773. this.pendingEOFill = false;
  16774. this.embedFonts = false;
  16775. this.embeddedFonts = {};
  16776. this.cssStyle = null;
  16777. }
  16778. var NS = 'http://www.w3.org/2000/svg';
  16779. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  16780. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  16781. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  16782. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  16783. var clipCount = 0;
  16784. var maskCount = 0;
  16785. SVGGraphics.prototype = {
  16786. save: function SVGGraphics_save() {
  16787. this.transformStack.push(this.transformMatrix);
  16788. var old = this.current;
  16789. this.extraStack.push(old);
  16790. this.current = old.clone();
  16791. },
  16792. restore: function SVGGraphics_restore() {
  16793. this.transformMatrix = this.transformStack.pop();
  16794. this.current = this.extraStack.pop();
  16795. this.tgrp = document.createElementNS(NS, 'svg:g');
  16796. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16797. this.pgrp.appendChild(this.tgrp);
  16798. },
  16799. group: function SVGGraphics_group(items) {
  16800. this.save();
  16801. this.executeOpTree(items);
  16802. this.restore();
  16803. },
  16804. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  16805. var fnArray = operatorList.fnArray;
  16806. var fnArrayLen = fnArray.length;
  16807. var argsArray = operatorList.argsArray;
  16808. var self = this;
  16809. for (var i = 0; i < fnArrayLen; i++) {
  16810. if (OPS.dependency === fnArray[i]) {
  16811. var deps = argsArray[i];
  16812. for (var n = 0, nn = deps.length; n < nn; n++) {
  16813. var obj = deps[n];
  16814. var common = obj.substring(0, 2) === 'g_';
  16815. var promise;
  16816. if (common) {
  16817. promise = new Promise(function(resolve) {
  16818. self.commonObjs.get(obj, resolve);
  16819. });
  16820. } else {
  16821. promise = new Promise(function(resolve) {
  16822. self.objs.get(obj, resolve);
  16823. });
  16824. }
  16825. this.current.dependencies.push(promise);
  16826. }
  16827. }
  16828. }
  16829. return Promise.all(this.current.dependencies);
  16830. },
  16831. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  16832. var transformMatrix = [a, b, c, d, e, f];
  16833. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  16834. transformMatrix);
  16835. this.tgrp = document.createElementNS(NS, 'svg:g');
  16836. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16837. },
  16838. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  16839. this.svg = createScratchSVG(viewport.width, viewport.height);
  16840. this.viewport = viewport;
  16841. return this.loadDependencies(operatorList).then(function () {
  16842. this.transformMatrix = IDENTITY_MATRIX;
  16843. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  16844. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  16845. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  16846. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16847. this.defs = document.createElementNS(NS, 'svg:defs');
  16848. this.pgrp.appendChild(this.defs);
  16849. this.pgrp.appendChild(this.tgrp);
  16850. this.svg.appendChild(this.pgrp);
  16851. var opTree = this.convertOpList(operatorList);
  16852. this.executeOpTree(opTree);
  16853. return this.svg;
  16854. }.bind(this));
  16855. },
  16856. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  16857. var argsArray = operatorList.argsArray;
  16858. var fnArray = operatorList.fnArray;
  16859. var fnArrayLen = fnArray.length;
  16860. var REVOPS = [];
  16861. var opList = [];
  16862. for (var op in OPS) {
  16863. REVOPS[OPS[op]] = op;
  16864. }
  16865. for (var x = 0; x < fnArrayLen; x++) {
  16866. var fnId = fnArray[x];
  16867. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  16868. }
  16869. return opListToTree(opList);
  16870. },
  16871. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  16872. var opTreeLen = opTree.length;
  16873. for(var x = 0; x < opTreeLen; x++) {
  16874. var fn = opTree[x].fn;
  16875. var fnId = opTree[x].fnId;
  16876. var args = opTree[x].args;
  16877. switch (fnId | 0) {
  16878. case OPS.beginText:
  16879. this.beginText();
  16880. break;
  16881. case OPS.setLeading:
  16882. this.setLeading(args);
  16883. break;
  16884. case OPS.setLeadingMoveText:
  16885. this.setLeadingMoveText(args[0], args[1]);
  16886. break;
  16887. case OPS.setFont:
  16888. this.setFont(args);
  16889. break;
  16890. case OPS.showText:
  16891. this.showText(args[0]);
  16892. break;
  16893. case OPS.showSpacedText:
  16894. this.showText(args[0]);
  16895. break;
  16896. case OPS.endText:
  16897. this.endText();
  16898. break;
  16899. case OPS.moveText:
  16900. this.moveText(args[0], args[1]);
  16901. break;
  16902. case OPS.setCharSpacing:
  16903. this.setCharSpacing(args[0]);
  16904. break;
  16905. case OPS.setWordSpacing:
  16906. this.setWordSpacing(args[0]);
  16907. break;
  16908. case OPS.setHScale:
  16909. this.setHScale(args[0]);
  16910. break;
  16911. case OPS.setTextMatrix:
  16912. this.setTextMatrix(args[0], args[1], args[2],
  16913. args[3], args[4], args[5]);
  16914. break;
  16915. case OPS.setLineWidth:
  16916. this.setLineWidth(args[0]);
  16917. break;
  16918. case OPS.setLineJoin:
  16919. this.setLineJoin(args[0]);
  16920. break;
  16921. case OPS.setLineCap:
  16922. this.setLineCap(args[0]);
  16923. break;
  16924. case OPS.setMiterLimit:
  16925. this.setMiterLimit(args[0]);
  16926. break;
  16927. case OPS.setFillRGBColor:
  16928. this.setFillRGBColor(args[0], args[1], args[2]);
  16929. break;
  16930. case OPS.setStrokeRGBColor:
  16931. this.setStrokeRGBColor(args[0], args[1], args[2]);
  16932. break;
  16933. case OPS.setDash:
  16934. this.setDash(args[0], args[1]);
  16935. break;
  16936. case OPS.setGState:
  16937. this.setGState(args[0]);
  16938. break;
  16939. case OPS.fill:
  16940. this.fill();
  16941. break;
  16942. case OPS.eoFill:
  16943. this.eoFill();
  16944. break;
  16945. case OPS.stroke:
  16946. this.stroke();
  16947. break;
  16948. case OPS.fillStroke:
  16949. this.fillStroke();
  16950. break;
  16951. case OPS.eoFillStroke:
  16952. this.eoFillStroke();
  16953. break;
  16954. case OPS.clip:
  16955. this.clip('nonzero');
  16956. break;
  16957. case OPS.eoClip:
  16958. this.clip('evenodd');
  16959. break;
  16960. case OPS.paintSolidColorImageMask:
  16961. this.paintSolidColorImageMask();
  16962. break;
  16963. case OPS.paintJpegXObject:
  16964. this.paintJpegXObject(args[0], args[1], args[2]);
  16965. break;
  16966. case OPS.paintImageXObject:
  16967. this.paintImageXObject(args[0]);
  16968. break;
  16969. case OPS.paintInlineImageXObject:
  16970. this.paintInlineImageXObject(args[0]);
  16971. break;
  16972. case OPS.paintImageMaskXObject:
  16973. this.paintImageMaskXObject(args[0]);
  16974. break;
  16975. case OPS.paintFormXObjectBegin:
  16976. this.paintFormXObjectBegin(args[0], args[1]);
  16977. break;
  16978. case OPS.paintFormXObjectEnd:
  16979. this.paintFormXObjectEnd();
  16980. break;
  16981. case OPS.closePath:
  16982. this.closePath();
  16983. break;
  16984. case OPS.closeStroke:
  16985. this.closeStroke();
  16986. break;
  16987. case OPS.closeFillStroke:
  16988. this.closeFillStroke();
  16989. break;
  16990. case OPS.nextLine:
  16991. this.nextLine();
  16992. break;
  16993. case OPS.transform:
  16994. this.transform(args[0], args[1], args[2], args[3],
  16995. args[4], args[5]);
  16996. break;
  16997. case OPS.constructPath:
  16998. this.constructPath(args[0], args[1]);
  16999. break;
  17000. case OPS.endPath:
  17001. this.endPath();
  17002. break;
  17003. case 92:
  17004. this.group(opTree[x].items);
  17005. break;
  17006. default:
  17007. warn('Unimplemented method '+ fn);
  17008. break;
  17009. }
  17010. }
  17011. },
  17012. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  17013. this.current.wordSpacing = wordSpacing;
  17014. },
  17015. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  17016. this.current.charSpacing = charSpacing;
  17017. },
  17018. nextLine: function SVGGraphics_nextLine() {
  17019. this.moveText(0, this.current.leading);
  17020. },
  17021. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  17022. var current = this.current;
  17023. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  17024. this.current.x = this.current.lineX = 0;
  17025. this.current.y = this.current.lineY = 0;
  17026. current.xcoords = [];
  17027. current.tspan = document.createElementNS(NS, 'svg:tspan');
  17028. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  17029. current.tspan.setAttributeNS(null, 'font-size',
  17030. pf(current.fontSize) + 'px');
  17031. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  17032. current.txtElement = document.createElementNS(NS, 'svg:text');
  17033. current.txtElement.appendChild(current.tspan);
  17034. },
  17035. beginText: function SVGGraphics_beginText() {
  17036. this.current.x = this.current.lineX = 0;
  17037. this.current.y = this.current.lineY = 0;
  17038. this.current.textMatrix = IDENTITY_MATRIX;
  17039. this.current.lineMatrix = IDENTITY_MATRIX;
  17040. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  17041. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  17042. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  17043. this.current.xcoords = [];
  17044. },
  17045. moveText: function SVGGraphics_moveText(x, y) {
  17046. var current = this.current;
  17047. this.current.x = this.current.lineX += x;
  17048. this.current.y = this.current.lineY += y;
  17049. current.xcoords = [];
  17050. current.tspan = document.createElementNS(NS, 'svg:tspan');
  17051. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  17052. current.tspan.setAttributeNS(null, 'font-size',
  17053. pf(current.fontSize) + 'px');
  17054. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  17055. },
  17056. showText: function SVGGraphics_showText(glyphs) {
  17057. var current = this.current;
  17058. var font = current.font;
  17059. var fontSize = current.fontSize;
  17060. if (fontSize === 0) {
  17061. return;
  17062. }
  17063. var charSpacing = current.charSpacing;
  17064. var wordSpacing = current.wordSpacing;
  17065. var fontDirection = current.fontDirection;
  17066. var textHScale = current.textHScale * fontDirection;
  17067. var glyphsLength = glyphs.length;
  17068. var vertical = font.vertical;
  17069. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  17070. var x = 0, i;
  17071. for (i = 0; i < glyphsLength; ++i) {
  17072. var glyph = glyphs[i];
  17073. if (glyph === null) {
  17074. // word break
  17075. x += fontDirection * wordSpacing;
  17076. continue;
  17077. } else if (isNum(glyph)) {
  17078. x += -glyph * fontSize * 0.001;
  17079. continue;
  17080. }
  17081. current.xcoords.push(current.x + x * textHScale);
  17082. var width = glyph.width;
  17083. var character = glyph.fontChar;
  17084. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  17085. x += charWidth;
  17086. current.tspan.textContent += character;
  17087. }
  17088. if (vertical) {
  17089. current.y -= x * textHScale;
  17090. } else {
  17091. current.x += x * textHScale;
  17092. }
  17093. current.tspan.setAttributeNS(null, 'x',
  17094. current.xcoords.map(pf).join(' '));
  17095. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  17096. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  17097. current.tspan.setAttributeNS(null, 'font-size',
  17098. pf(current.fontSize) + 'px');
  17099. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  17100. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  17101. }
  17102. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  17103. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  17104. }
  17105. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  17106. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  17107. }
  17108. current.txtElement.setAttributeNS(null, 'transform',
  17109. pm(current.textMatrix) +
  17110. ' scale(1, -1)' );
  17111. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  17112. current.txtElement.appendChild(current.tspan);
  17113. current.txtgrp.appendChild(current.txtElement);
  17114. this.tgrp.appendChild(current.txtElement);
  17115. },
  17116. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  17117. this.setLeading(-y);
  17118. this.moveText(x, y);
  17119. },
  17120. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  17121. if (!this.cssStyle) {
  17122. this.cssStyle = document.createElementNS(NS, 'svg:style');
  17123. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  17124. this.defs.appendChild(this.cssStyle);
  17125. }
  17126. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  17127. this.cssStyle.textContent +=
  17128. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  17129. ' src: url(' + url + '); }\n';
  17130. },
  17131. setFont: function SVGGraphics_setFont(details) {
  17132. var current = this.current;
  17133. var fontObj = this.commonObjs.get(details[0]);
  17134. var size = details[1];
  17135. this.current.font = fontObj;
  17136. if (this.embedFonts && fontObj.data &&
  17137. !this.embeddedFonts[fontObj.loadedName]) {
  17138. this.addFontStyle(fontObj);
  17139. this.embeddedFonts[fontObj.loadedName] = fontObj;
  17140. }
  17141. current.fontMatrix = (fontObj.fontMatrix ?
  17142. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  17143. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  17144. (fontObj.bold ? 'bold' : 'normal');
  17145. var italic = fontObj.italic ? 'italic' : 'normal';
  17146. if (size < 0) {
  17147. size = -size;
  17148. current.fontDirection = -1;
  17149. } else {
  17150. current.fontDirection = 1;
  17151. }
  17152. current.fontSize = size;
  17153. current.fontFamily = fontObj.loadedName;
  17154. current.fontWeight = bold;
  17155. current.fontStyle = italic;
  17156. current.tspan = document.createElementNS(NS, 'svg:tspan');
  17157. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  17158. current.xcoords = [];
  17159. },
  17160. endText: function SVGGraphics_endText() {
  17161. if (this.current.pendingClip) {
  17162. this.cgrp.appendChild(this.tgrp);
  17163. this.pgrp.appendChild(this.cgrp);
  17164. } else {
  17165. this.pgrp.appendChild(this.tgrp);
  17166. }
  17167. this.tgrp = document.createElementNS(NS, 'svg:g');
  17168. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  17169. },
  17170. // Path properties
  17171. setLineWidth: function SVGGraphics_setLineWidth(width) {
  17172. this.current.lineWidth = width;
  17173. },
  17174. setLineCap: function SVGGraphics_setLineCap(style) {
  17175. this.current.lineCap = LINE_CAP_STYLES[style];
  17176. },
  17177. setLineJoin: function SVGGraphics_setLineJoin(style) {
  17178. this.current.lineJoin = LINE_JOIN_STYLES[style];
  17179. },
  17180. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  17181. this.current.miterLimit = limit;
  17182. },
  17183. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  17184. var color = Util.makeCssRgb(r, g, b);
  17185. this.current.strokeColor = color;
  17186. },
  17187. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  17188. var color = Util.makeCssRgb(r, g, b);
  17189. this.current.fillColor = color;
  17190. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  17191. this.current.xcoords = [];
  17192. },
  17193. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  17194. this.current.dashArray = dashArray;
  17195. this.current.dashPhase = dashPhase;
  17196. },
  17197. constructPath: function SVGGraphics_constructPath(ops, args) {
  17198. var current = this.current;
  17199. var x = current.x, y = current.y;
  17200. current.path = document.createElementNS(NS, 'svg:path');
  17201. var d = [];
  17202. var opLength = ops.length;
  17203. for (var i = 0, j = 0; i < opLength; i++) {
  17204. switch (ops[i] | 0) {
  17205. case OPS.rectangle:
  17206. x = args[j++];
  17207. y = args[j++];
  17208. var width = args[j++];
  17209. var height = args[j++];
  17210. var xw = x + width;
  17211. var yh = y + height;
  17212. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  17213. 'L', pf(x), pf(yh), 'Z');
  17214. break;
  17215. case OPS.moveTo:
  17216. x = args[j++];
  17217. y = args[j++];
  17218. d.push('M', pf(x), pf(y));
  17219. break;
  17220. case OPS.lineTo:
  17221. x = args[j++];
  17222. y = args[j++];
  17223. d.push('L', pf(x) , pf(y));
  17224. break;
  17225. case OPS.curveTo:
  17226. x = args[j + 4];
  17227. y = args[j + 5];
  17228. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  17229. pf(args[j + 3]), pf(x), pf(y));
  17230. j += 6;
  17231. break;
  17232. case OPS.curveTo2:
  17233. x = args[j + 2];
  17234. y = args[j + 3];
  17235. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  17236. pf(args[j + 2]), pf(args[j + 3]));
  17237. j += 4;
  17238. break;
  17239. case OPS.curveTo3:
  17240. x = args[j + 2];
  17241. y = args[j + 3];
  17242. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  17243. pf(x), pf(y));
  17244. j += 4;
  17245. break;
  17246. case OPS.closePath:
  17247. d.push('Z');
  17248. break;
  17249. }
  17250. }
  17251. current.path.setAttributeNS(null, 'd', d.join(' '));
  17252. current.path.setAttributeNS(null, 'stroke-miterlimit',
  17253. pf(current.miterLimit));
  17254. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  17255. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  17256. current.path.setAttributeNS(null, 'stroke-width',
  17257. pf(current.lineWidth) + 'px');
  17258. current.path.setAttributeNS(null, 'stroke-dasharray',
  17259. current.dashArray.map(pf).join(' '));
  17260. current.path.setAttributeNS(null, 'stroke-dashoffset',
  17261. pf(current.dashPhase) + 'px');
  17262. current.path.setAttributeNS(null, 'fill', 'none');
  17263. this.tgrp.appendChild(current.path);
  17264. if (current.pendingClip) {
  17265. this.cgrp.appendChild(this.tgrp);
  17266. this.pgrp.appendChild(this.cgrp);
  17267. } else {
  17268. this.pgrp.appendChild(this.tgrp);
  17269. }
  17270. // Saving a reference in current.element so that it can be addressed
  17271. // in 'fill' and 'stroke'
  17272. current.element = current.path;
  17273. current.setCurrentPoint(x, y);
  17274. },
  17275. endPath: function SVGGraphics_endPath() {
  17276. var current = this.current;
  17277. if (current.pendingClip) {
  17278. this.cgrp.appendChild(this.tgrp);
  17279. this.pgrp.appendChild(this.cgrp);
  17280. } else {
  17281. this.pgrp.appendChild(this.tgrp);
  17282. }
  17283. this.tgrp = document.createElementNS(NS, 'svg:g');
  17284. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  17285. },
  17286. clip: function SVGGraphics_clip(type) {
  17287. var current = this.current;
  17288. // Add current path to clipping path
  17289. current.clipId = 'clippath' + clipCount;
  17290. clipCount++;
  17291. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  17292. this.clippath.setAttributeNS(null, 'id', current.clipId);
  17293. var clipElement = current.element.cloneNode();
  17294. if (type === 'evenodd') {
  17295. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  17296. } else {
  17297. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  17298. }
  17299. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  17300. this.clippath.appendChild(clipElement);
  17301. this.defs.appendChild(this.clippath);
  17302. // Create a new group with that attribute
  17303. current.pendingClip = true;
  17304. this.cgrp = document.createElementNS(NS, 'svg:g');
  17305. this.cgrp.setAttributeNS(null, 'clip-path',
  17306. 'url(#' + current.clipId + ')');
  17307. this.pgrp.appendChild(this.cgrp);
  17308. },
  17309. closePath: function SVGGraphics_closePath() {
  17310. var current = this.current;
  17311. var d = current.path.getAttributeNS(null, 'd');
  17312. d += 'Z';
  17313. current.path.setAttributeNS(null, 'd', d);
  17314. },
  17315. setLeading: function SVGGraphics_setLeading(leading) {
  17316. this.current.leading = -leading;
  17317. },
  17318. setTextRise: function SVGGraphics_setTextRise(textRise) {
  17319. this.current.textRise = textRise;
  17320. },
  17321. setHScale: function SVGGraphics_setHScale(scale) {
  17322. this.current.textHScale = scale / 100;
  17323. },
  17324. setGState: function SVGGraphics_setGState(states) {
  17325. for (var i = 0, ii = states.length; i < ii; i++) {
  17326. var state = states[i];
  17327. var key = state[0];
  17328. var value = state[1];
  17329. switch (key) {
  17330. case 'LW':
  17331. this.setLineWidth(value);
  17332. break;
  17333. case 'LC':
  17334. this.setLineCap(value);
  17335. break;
  17336. case 'LJ':
  17337. this.setLineJoin(value);
  17338. break;
  17339. case 'ML':
  17340. this.setMiterLimit(value);
  17341. break;
  17342. case 'D':
  17343. this.setDash(value[0], value[1]);
  17344. break;
  17345. case 'RI':
  17346. break;
  17347. case 'FL':
  17348. break;
  17349. case 'Font':
  17350. this.setFont(value);
  17351. break;
  17352. case 'CA':
  17353. break;
  17354. case 'ca':
  17355. break;
  17356. case 'BM':
  17357. break;
  17358. case 'SMask':
  17359. break;
  17360. }
  17361. }
  17362. },
  17363. fill: function SVGGraphics_fill() {
  17364. var current = this.current;
  17365. current.element.setAttributeNS(null, 'fill', current.fillColor);
  17366. },
  17367. stroke: function SVGGraphics_stroke() {
  17368. var current = this.current;
  17369. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  17370. current.element.setAttributeNS(null, 'fill', 'none');
  17371. },
  17372. eoFill: function SVGGraphics_eoFill() {
  17373. var current = this.current;
  17374. current.element.setAttributeNS(null, 'fill', current.fillColor);
  17375. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  17376. },
  17377. fillStroke: function SVGGraphics_fillStroke() {
  17378. // Order is important since stroke wants fill to be none.
  17379. // First stroke, then if fill needed, it will be overwritten.
  17380. this.stroke();
  17381. this.fill();
  17382. },
  17383. eoFillStroke: function SVGGraphics_eoFillStroke() {
  17384. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  17385. this.fillStroke();
  17386. },
  17387. closeStroke: function SVGGraphics_closeStroke() {
  17388. this.closePath();
  17389. this.stroke();
  17390. },
  17391. closeFillStroke: function SVGGraphics_closeFillStroke() {
  17392. this.closePath();
  17393. this.fillStroke();
  17394. },
  17395. paintSolidColorImageMask:
  17396. function SVGGraphics_paintSolidColorImageMask() {
  17397. var current = this.current;
  17398. var rect = document.createElementNS(NS, 'svg:rect');
  17399. rect.setAttributeNS(null, 'x', '0');
  17400. rect.setAttributeNS(null, 'y', '0');
  17401. rect.setAttributeNS(null, 'width', '1px');
  17402. rect.setAttributeNS(null, 'height', '1px');
  17403. rect.setAttributeNS(null, 'fill', current.fillColor);
  17404. this.tgrp.appendChild(rect);
  17405. },
  17406. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  17407. var current = this.current;
  17408. var imgObj = this.objs.get(objId);
  17409. var imgEl = document.createElementNS(NS, 'svg:image');
  17410. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  17411. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  17412. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  17413. imgEl.setAttributeNS(null, 'x', '0');
  17414. imgEl.setAttributeNS(null, 'y', pf(-h));
  17415. imgEl.setAttributeNS(null, 'transform',
  17416. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  17417. this.tgrp.appendChild(imgEl);
  17418. if (current.pendingClip) {
  17419. this.cgrp.appendChild(this.tgrp);
  17420. this.pgrp.appendChild(this.cgrp);
  17421. } else {
  17422. this.pgrp.appendChild(this.tgrp);
  17423. }
  17424. },
  17425. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  17426. var imgData = this.objs.get(objId);
  17427. if (!imgData) {
  17428. warn('Dependent image isn\'t ready yet');
  17429. return;
  17430. }
  17431. this.paintInlineImageXObject(imgData);
  17432. },
  17433. paintInlineImageXObject:
  17434. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  17435. var current = this.current;
  17436. var width = imgData.width;
  17437. var height = imgData.height;
  17438. var imgSrc = convertImgDataToPng(imgData);
  17439. var cliprect = document.createElementNS(NS, 'svg:rect');
  17440. cliprect.setAttributeNS(null, 'x', '0');
  17441. cliprect.setAttributeNS(null, 'y', '0');
  17442. cliprect.setAttributeNS(null, 'width', pf(width));
  17443. cliprect.setAttributeNS(null, 'height', pf(height));
  17444. current.element = cliprect;
  17445. this.clip('nonzero');
  17446. var imgEl = document.createElementNS(NS, 'svg:image');
  17447. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  17448. imgEl.setAttributeNS(null, 'x', '0');
  17449. imgEl.setAttributeNS(null, 'y', pf(-height));
  17450. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  17451. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  17452. imgEl.setAttributeNS(null, 'transform',
  17453. 'scale(' + pf(1 / width) + ' ' +
  17454. pf(-1 / height) + ')');
  17455. if (mask) {
  17456. mask.appendChild(imgEl);
  17457. } else {
  17458. this.tgrp.appendChild(imgEl);
  17459. }
  17460. if (current.pendingClip) {
  17461. this.cgrp.appendChild(this.tgrp);
  17462. this.pgrp.appendChild(this.cgrp);
  17463. } else {
  17464. this.pgrp.appendChild(this.tgrp);
  17465. }
  17466. },
  17467. paintImageMaskXObject:
  17468. function SVGGraphics_paintImageMaskXObject(imgData) {
  17469. var current = this.current;
  17470. var width = imgData.width;
  17471. var height = imgData.height;
  17472. var fillColor = current.fillColor;
  17473. current.maskId = 'mask' + maskCount++;
  17474. var mask = document.createElementNS(NS, 'svg:mask');
  17475. mask.setAttributeNS(null, 'id', current.maskId);
  17476. var rect = document.createElementNS(NS, 'svg:rect');
  17477. rect.setAttributeNS(null, 'x', '0');
  17478. rect.setAttributeNS(null, 'y', '0');
  17479. rect.setAttributeNS(null, 'width', pf(width));
  17480. rect.setAttributeNS(null, 'height', pf(height));
  17481. rect.setAttributeNS(null, 'fill', fillColor);
  17482. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  17483. this.defs.appendChild(mask);
  17484. this.tgrp.appendChild(rect);
  17485. this.paintInlineImageXObject(imgData, mask);
  17486. },
  17487. paintFormXObjectBegin:
  17488. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  17489. this.save();
  17490. if (isArray(matrix) && matrix.length === 6) {
  17491. this.transform(matrix[0], matrix[1], matrix[2],
  17492. matrix[3], matrix[4], matrix[5]);
  17493. }
  17494. if (isArray(bbox) && bbox.length === 4) {
  17495. var width = bbox[2] - bbox[0];
  17496. var height = bbox[3] - bbox[1];
  17497. var cliprect = document.createElementNS(NS, 'svg:rect');
  17498. cliprect.setAttributeNS(null, 'x', bbox[0]);
  17499. cliprect.setAttributeNS(null, 'y', bbox[1]);
  17500. cliprect.setAttributeNS(null, 'width', pf(width));
  17501. cliprect.setAttributeNS(null, 'height', pf(height));
  17502. this.current.element = cliprect;
  17503. this.clip('nonzero');
  17504. this.endPath();
  17505. }
  17506. },
  17507. paintFormXObjectEnd:
  17508. function SVGGraphics_paintFormXObjectEnd() {
  17509. this.restore();
  17510. }
  17511. };
  17512. return SVGGraphics;
  17513. })();
  17514. PDFJS.SVGGraphics = SVGGraphics;
  17515. exports.SVGGraphics = SVGGraphics;
  17516. }));
  17517. (function (root, factory) {
  17518. {
  17519. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  17520. root.pdfjsDisplayDOMUtils, root.pdfjsSharedGlobal);
  17521. }
  17522. }(this, function (exports, sharedUtil, displayDOMUtils, sharedGlobal) {
  17523. var Util = sharedUtil.Util;
  17524. var createPromiseCapability = sharedUtil.createPromiseCapability;
  17525. var CustomStyle = displayDOMUtils.CustomStyle;
  17526. var PDFJS = sharedGlobal.PDFJS;
  17527. /**
  17528. * Text layer render parameters.
  17529. *
  17530. * @typedef {Object} TextLayerRenderParameters
  17531. * @property {TextContent} textContent - Text content to render (the object is
  17532. * returned by the page's getTextContent() method).
  17533. * @property {HTMLElement} container - HTML element that will contain text runs.
  17534. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  17535. * layout the text runs.
  17536. * @property {Array} textDivs - (optional) HTML elements that are correspond
  17537. * the text items of the textContent input. This is output and shall be
  17538. * initially be set to empty array.
  17539. * @property {number} timeout - (optional) Delay in milliseconds before
  17540. * rendering of the text runs occurs.
  17541. */
  17542. var renderTextLayer = (function renderTextLayerClosure() {
  17543. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  17544. var NonWhitespaceRegexp = /\S/;
  17545. function isAllWhitespace(str) {
  17546. return !NonWhitespaceRegexp.test(str);
  17547. }
  17548. function appendText(textDivs, viewport, geom, styles) {
  17549. var style = styles[geom.fontName];
  17550. var textDiv = document.createElement('div');
  17551. textDivs.push(textDiv);
  17552. if (isAllWhitespace(geom.str)) {
  17553. textDiv.dataset.isWhitespace = true;
  17554. return;
  17555. }
  17556. var tx = Util.transform(viewport.transform, geom.transform);
  17557. var angle = Math.atan2(tx[1], tx[0]);
  17558. if (style.vertical) {
  17559. angle += Math.PI / 2;
  17560. }
  17561. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  17562. var fontAscent = fontHeight;
  17563. if (style.ascent) {
  17564. fontAscent = style.ascent * fontAscent;
  17565. } else if (style.descent) {
  17566. fontAscent = (1 + style.descent) * fontAscent;
  17567. }
  17568. var left;
  17569. var top;
  17570. if (angle === 0) {
  17571. left = tx[4];
  17572. top = tx[5] - fontAscent;
  17573. } else {
  17574. left = tx[4] + (fontAscent * Math.sin(angle));
  17575. top = tx[5] - (fontAscent * Math.cos(angle));
  17576. }
  17577. textDiv.style.left = left + 'px';
  17578. textDiv.style.top = top + 'px';
  17579. textDiv.style.fontSize = fontHeight + 'px';
  17580. textDiv.style.fontFamily = style.fontFamily;
  17581. textDiv.textContent = geom.str;
  17582. // |fontName| is only used by the Font Inspector. This test will succeed
  17583. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  17584. // not worth the effort to do a more accurate test.
  17585. if (PDFJS.pdfBug) {
  17586. textDiv.dataset.fontName = geom.fontName;
  17587. }
  17588. // Storing into dataset will convert number into string.
  17589. if (angle !== 0) {
  17590. textDiv.dataset.angle = angle * (180 / Math.PI);
  17591. }
  17592. // We don't bother scaling single-char text divs, because it has very
  17593. // little effect on text highlighting. This makes scrolling on docs with
  17594. // lots of such divs a lot faster.
  17595. if (geom.str.length > 1) {
  17596. if (style.vertical) {
  17597. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  17598. } else {
  17599. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  17600. }
  17601. }
  17602. }
  17603. function render(task) {
  17604. if (task._canceled) {
  17605. return;
  17606. }
  17607. var textLayerFrag = task._container;
  17608. var textDivs = task._textDivs;
  17609. var capability = task._capability;
  17610. var textDivsLength = textDivs.length;
  17611. // No point in rendering many divs as it would make the browser
  17612. // unusable even after the divs are rendered.
  17613. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  17614. capability.resolve();
  17615. return;
  17616. }
  17617. var canvas = document.createElement('canvas');
  17618. var ctx = canvas.getContext('2d', {alpha: false});
  17619. var lastFontSize;
  17620. var lastFontFamily;
  17621. for (var i = 0; i < textDivsLength; i++) {
  17622. var textDiv = textDivs[i];
  17623. if (textDiv.dataset.isWhitespace !== undefined) {
  17624. continue;
  17625. }
  17626. var fontSize = textDiv.style.fontSize;
  17627. var fontFamily = textDiv.style.fontFamily;
  17628. // Only build font string and set to context if different from last.
  17629. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  17630. ctx.font = fontSize + ' ' + fontFamily;
  17631. lastFontSize = fontSize;
  17632. lastFontFamily = fontFamily;
  17633. }
  17634. var width = ctx.measureText(textDiv.textContent).width;
  17635. if (width > 0) {
  17636. textLayerFrag.appendChild(textDiv);
  17637. var transform;
  17638. if (textDiv.dataset.canvasWidth !== undefined) {
  17639. // Dataset values come of type string.
  17640. var textScale = textDiv.dataset.canvasWidth / width;
  17641. transform = 'scaleX(' + textScale + ')';
  17642. } else {
  17643. transform = '';
  17644. }
  17645. var rotation = textDiv.dataset.angle;
  17646. if (rotation) {
  17647. transform = 'rotate(' + rotation + 'deg) ' + transform;
  17648. }
  17649. if (transform) {
  17650. CustomStyle.setProp('transform' , textDiv, transform);
  17651. }
  17652. }
  17653. }
  17654. capability.resolve();
  17655. }
  17656. /**
  17657. * Text layer rendering task.
  17658. *
  17659. * @param {TextContent} textContent
  17660. * @param {HTMLElement} container
  17661. * @param {PDFJS.PageViewport} viewport
  17662. * @param {Array} textDivs
  17663. * @private
  17664. */
  17665. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  17666. this._textContent = textContent;
  17667. this._container = container;
  17668. this._viewport = viewport;
  17669. textDivs = textDivs || [];
  17670. this._textDivs = textDivs;
  17671. this._canceled = false;
  17672. this._capability = createPromiseCapability();
  17673. this._renderTimer = null;
  17674. }
  17675. TextLayerRenderTask.prototype = {
  17676. get promise() {
  17677. return this._capability.promise;
  17678. },
  17679. cancel: function TextLayer_cancel() {
  17680. this._canceled = true;
  17681. if (this._renderTimer !== null) {
  17682. clearTimeout(this._renderTimer);
  17683. this._renderTimer = null;
  17684. }
  17685. this._capability.reject('canceled');
  17686. },
  17687. _render: function TextLayer_render(timeout) {
  17688. var textItems = this._textContent.items;
  17689. var styles = this._textContent.styles;
  17690. var textDivs = this._textDivs;
  17691. var viewport = this._viewport;
  17692. for (var i = 0, len = textItems.length; i < len; i++) {
  17693. appendText(textDivs, viewport, textItems[i], styles);
  17694. }
  17695. if (!timeout) { // Render right away
  17696. render(this);
  17697. } else { // Schedule
  17698. var self = this;
  17699. this._renderTimer = setTimeout(function() {
  17700. render(self);
  17701. self._renderTimer = null;
  17702. }, timeout);
  17703. }
  17704. }
  17705. };
  17706. /**
  17707. * Starts rendering of the text layer.
  17708. *
  17709. * @param {TextLayerRenderParameters} renderParameters
  17710. * @returns {TextLayerRenderTask}
  17711. */
  17712. function renderTextLayer(renderParameters) {
  17713. var task = new TextLayerRenderTask(renderParameters.textContent,
  17714. renderParameters.container,
  17715. renderParameters.viewport,
  17716. renderParameters.textDivs);
  17717. task._render(renderParameters.timeout);
  17718. return task;
  17719. }
  17720. return renderTextLayer;
  17721. })();
  17722. PDFJS.renderTextLayer = renderTextLayer;
  17723. exports.renderTextLayer = renderTextLayer;
  17724. }));
  17725. (function (root, factory) {
  17726. {
  17727. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  17728. }
  17729. }(this, function (exports, sharedUtil) {
  17730. var shadow = sharedUtil.shadow;
  17731. var WebGLUtils = (function WebGLUtilsClosure() {
  17732. function loadShader(gl, code, shaderType) {
  17733. var shader = gl.createShader(shaderType);
  17734. gl.shaderSource(shader, code);
  17735. gl.compileShader(shader);
  17736. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  17737. if (!compiled) {
  17738. var errorMsg = gl.getShaderInfoLog(shader);
  17739. throw new Error('Error during shader compilation: ' + errorMsg);
  17740. }
  17741. return shader;
  17742. }
  17743. function createVertexShader(gl, code) {
  17744. return loadShader(gl, code, gl.VERTEX_SHADER);
  17745. }
  17746. function createFragmentShader(gl, code) {
  17747. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  17748. }
  17749. function createProgram(gl, shaders) {
  17750. var program = gl.createProgram();
  17751. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  17752. gl.attachShader(program, shaders[i]);
  17753. }
  17754. gl.linkProgram(program);
  17755. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  17756. if (!linked) {
  17757. var errorMsg = gl.getProgramInfoLog(program);
  17758. throw new Error('Error during program linking: ' + errorMsg);
  17759. }
  17760. return program;
  17761. }
  17762. function createTexture(gl, image, textureId) {
  17763. gl.activeTexture(textureId);
  17764. var texture = gl.createTexture();
  17765. gl.bindTexture(gl.TEXTURE_2D, texture);
  17766. // Set the parameters so we can render any size image.
  17767. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  17768. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  17769. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  17770. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  17771. // Upload the image into the texture.
  17772. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  17773. return texture;
  17774. }
  17775. var currentGL, currentCanvas;
  17776. function generateGL() {
  17777. if (currentGL) {
  17778. return;
  17779. }
  17780. currentCanvas = document.createElement('canvas');
  17781. currentGL = currentCanvas.getContext('webgl',
  17782. { premultipliedalpha: false });
  17783. }
  17784. var smaskVertexShaderCode = '\
  17785. attribute vec2 a_position; \
  17786. attribute vec2 a_texCoord; \
  17787. \
  17788. uniform vec2 u_resolution; \
  17789. \
  17790. varying vec2 v_texCoord; \
  17791. \
  17792. void main() { \
  17793. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  17794. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  17795. \
  17796. v_texCoord = a_texCoord; \
  17797. } ';
  17798. var smaskFragmentShaderCode = '\
  17799. precision mediump float; \
  17800. \
  17801. uniform vec4 u_backdrop; \
  17802. uniform int u_subtype; \
  17803. uniform sampler2D u_image; \
  17804. uniform sampler2D u_mask; \
  17805. \
  17806. varying vec2 v_texCoord; \
  17807. \
  17808. void main() { \
  17809. vec4 imageColor = texture2D(u_image, v_texCoord); \
  17810. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  17811. if (u_backdrop.a > 0.0) { \
  17812. maskColor.rgb = maskColor.rgb * maskColor.a + \
  17813. u_backdrop.rgb * (1.0 - maskColor.a); \
  17814. } \
  17815. float lum; \
  17816. if (u_subtype == 0) { \
  17817. lum = maskColor.a; \
  17818. } else { \
  17819. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  17820. maskColor.b * 0.11; \
  17821. } \
  17822. imageColor.a *= lum; \
  17823. imageColor.rgb *= imageColor.a; \
  17824. gl_FragColor = imageColor; \
  17825. } ';
  17826. var smaskCache = null;
  17827. function initSmaskGL() {
  17828. var canvas, gl;
  17829. generateGL();
  17830. canvas = currentCanvas;
  17831. currentCanvas = null;
  17832. gl = currentGL;
  17833. currentGL = null;
  17834. // setup a GLSL program
  17835. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  17836. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  17837. var program = createProgram(gl, [vertexShader, fragmentShader]);
  17838. gl.useProgram(program);
  17839. var cache = {};
  17840. cache.gl = gl;
  17841. cache.canvas = canvas;
  17842. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  17843. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  17844. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  17845. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  17846. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  17847. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  17848. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  17849. // provide texture coordinates for the rectangle.
  17850. var texCoordBuffer = gl.createBuffer();
  17851. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  17852. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  17853. 0.0, 0.0,
  17854. 1.0, 0.0,
  17855. 0.0, 1.0,
  17856. 0.0, 1.0,
  17857. 1.0, 0.0,
  17858. 1.0, 1.0]), gl.STATIC_DRAW);
  17859. gl.enableVertexAttribArray(texCoordLocation);
  17860. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  17861. gl.uniform1i(texLayerLocation, 0);
  17862. gl.uniform1i(texMaskLocation, 1);
  17863. smaskCache = cache;
  17864. }
  17865. function composeSMask(layer, mask, properties) {
  17866. var width = layer.width, height = layer.height;
  17867. if (!smaskCache) {
  17868. initSmaskGL();
  17869. }
  17870. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  17871. canvas.width = width;
  17872. canvas.height = height;
  17873. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  17874. gl.uniform2f(cache.resolutionLocation, width, height);
  17875. if (properties.backdrop) {
  17876. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  17877. properties.backdrop[1], properties.backdrop[2], 1);
  17878. } else {
  17879. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  17880. }
  17881. gl.uniform1i(cache.subtypeLocation,
  17882. properties.subtype === 'Luminosity' ? 1 : 0);
  17883. // Create a textures
  17884. var texture = createTexture(gl, layer, gl.TEXTURE0);
  17885. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  17886. // Create a buffer and put a single clipspace rectangle in
  17887. // it (2 triangles)
  17888. var buffer = gl.createBuffer();
  17889. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  17890. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  17891. 0, 0,
  17892. width, 0,
  17893. 0, height,
  17894. 0, height,
  17895. width, 0,
  17896. width, height]), gl.STATIC_DRAW);
  17897. gl.enableVertexAttribArray(cache.positionLocation);
  17898. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  17899. // draw
  17900. gl.clearColor(0, 0, 0, 0);
  17901. gl.enable(gl.BLEND);
  17902. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  17903. gl.clear(gl.COLOR_BUFFER_BIT);
  17904. gl.drawArrays(gl.TRIANGLES, 0, 6);
  17905. gl.flush();
  17906. gl.deleteTexture(texture);
  17907. gl.deleteTexture(maskTexture);
  17908. gl.deleteBuffer(buffer);
  17909. return canvas;
  17910. }
  17911. var figuresVertexShaderCode = '\
  17912. attribute vec2 a_position; \
  17913. attribute vec3 a_color; \
  17914. \
  17915. uniform vec2 u_resolution; \
  17916. uniform vec2 u_scale; \
  17917. uniform vec2 u_offset; \
  17918. \
  17919. varying vec4 v_color; \
  17920. \
  17921. void main() { \
  17922. vec2 position = (a_position + u_offset) * u_scale; \
  17923. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  17924. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  17925. \
  17926. v_color = vec4(a_color / 255.0, 1.0); \
  17927. } ';
  17928. var figuresFragmentShaderCode = '\
  17929. precision mediump float; \
  17930. \
  17931. varying vec4 v_color; \
  17932. \
  17933. void main() { \
  17934. gl_FragColor = v_color; \
  17935. } ';
  17936. var figuresCache = null;
  17937. function initFiguresGL() {
  17938. var canvas, gl;
  17939. generateGL();
  17940. canvas = currentCanvas;
  17941. currentCanvas = null;
  17942. gl = currentGL;
  17943. currentGL = null;
  17944. // setup a GLSL program
  17945. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  17946. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  17947. var program = createProgram(gl, [vertexShader, fragmentShader]);
  17948. gl.useProgram(program);
  17949. var cache = {};
  17950. cache.gl = gl;
  17951. cache.canvas = canvas;
  17952. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  17953. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  17954. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  17955. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  17956. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  17957. figuresCache = cache;
  17958. }
  17959. function drawFigures(width, height, backgroundColor, figures, context) {
  17960. if (!figuresCache) {
  17961. initFiguresGL();
  17962. }
  17963. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  17964. canvas.width = width;
  17965. canvas.height = height;
  17966. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  17967. gl.uniform2f(cache.resolutionLocation, width, height);
  17968. // count triangle points
  17969. var count = 0;
  17970. var i, ii, rows;
  17971. for (i = 0, ii = figures.length; i < ii; i++) {
  17972. switch (figures[i].type) {
  17973. case 'lattice':
  17974. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  17975. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  17976. break;
  17977. case 'triangles':
  17978. count += figures[i].coords.length;
  17979. break;
  17980. }
  17981. }
  17982. // transfer data
  17983. var coords = new Float32Array(count * 2);
  17984. var colors = new Uint8Array(count * 3);
  17985. var coordsMap = context.coords, colorsMap = context.colors;
  17986. var pIndex = 0, cIndex = 0;
  17987. for (i = 0, ii = figures.length; i < ii; i++) {
  17988. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  17989. switch (figure.type) {
  17990. case 'lattice':
  17991. var cols = figure.verticesPerRow;
  17992. rows = (ps.length / cols) | 0;
  17993. for (var row = 1; row < rows; row++) {
  17994. var offset = row * cols + 1;
  17995. for (var col = 1; col < cols; col++, offset++) {
  17996. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  17997. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  17998. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  17999. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  18000. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  18001. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  18002. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  18003. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  18004. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  18005. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  18006. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  18007. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  18008. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  18009. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  18010. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  18011. coords[pIndex + 6] = coords[pIndex + 2];
  18012. coords[pIndex + 7] = coords[pIndex + 3];
  18013. coords[pIndex + 8] = coords[pIndex + 4];
  18014. coords[pIndex + 9] = coords[pIndex + 5];
  18015. coords[pIndex + 10] = coordsMap[ps[offset]];
  18016. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  18017. colors[cIndex + 9] = colors[cIndex + 3];
  18018. colors[cIndex + 10] = colors[cIndex + 4];
  18019. colors[cIndex + 11] = colors[cIndex + 5];
  18020. colors[cIndex + 12] = colors[cIndex + 6];
  18021. colors[cIndex + 13] = colors[cIndex + 7];
  18022. colors[cIndex + 14] = colors[cIndex + 8];
  18023. colors[cIndex + 15] = colorsMap[cs[offset]];
  18024. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  18025. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  18026. pIndex += 12;
  18027. cIndex += 18;
  18028. }
  18029. }
  18030. break;
  18031. case 'triangles':
  18032. for (var j = 0, jj = ps.length; j < jj; j++) {
  18033. coords[pIndex] = coordsMap[ps[j]];
  18034. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  18035. colors[cIndex] = colorsMap[cs[j]];
  18036. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  18037. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  18038. pIndex += 2;
  18039. cIndex += 3;
  18040. }
  18041. break;
  18042. }
  18043. }
  18044. // draw
  18045. if (backgroundColor) {
  18046. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  18047. backgroundColor[2] / 255, 1.0);
  18048. } else {
  18049. gl.clearColor(0, 0, 0, 0);
  18050. }
  18051. gl.clear(gl.COLOR_BUFFER_BIT);
  18052. var coordsBuffer = gl.createBuffer();
  18053. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  18054. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  18055. gl.enableVertexAttribArray(cache.positionLocation);
  18056. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  18057. var colorsBuffer = gl.createBuffer();
  18058. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  18059. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  18060. gl.enableVertexAttribArray(cache.colorLocation);
  18061. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  18062. 0, 0);
  18063. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  18064. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  18065. gl.drawArrays(gl.TRIANGLES, 0, count);
  18066. gl.flush();
  18067. gl.deleteBuffer(coordsBuffer);
  18068. gl.deleteBuffer(colorsBuffer);
  18069. return canvas;
  18070. }
  18071. function cleanup() {
  18072. if (smaskCache && smaskCache.canvas) {
  18073. smaskCache.canvas.width = 0;
  18074. smaskCache.canvas.height = 0;
  18075. }
  18076. if (figuresCache && figuresCache.canvas) {
  18077. figuresCache.canvas.width = 0;
  18078. figuresCache.canvas.height = 0;
  18079. }
  18080. smaskCache = null;
  18081. figuresCache = null;
  18082. }
  18083. return {
  18084. get isEnabled() {
  18085. if (PDFJS.disableWebGL) {
  18086. return false;
  18087. }
  18088. var enabled = false;
  18089. try {
  18090. generateGL();
  18091. enabled = !!currentGL;
  18092. } catch (e) { }
  18093. return shadow(this, 'isEnabled', enabled);
  18094. },
  18095. composeSMask: composeSMask,
  18096. drawFigures: drawFigures,
  18097. clear: cleanup
  18098. };
  18099. })();
  18100. exports.WebGLUtils = WebGLUtils;
  18101. }));
  18102. (function (root, factory) {
  18103. {
  18104. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  18105. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  18106. root.pdfjsCoreJpx);
  18107. }
  18108. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  18109. coreJpx) {
  18110. var Util = sharedUtil.Util;
  18111. var error = sharedUtil.error;
  18112. var info = sharedUtil.info;
  18113. var isArray = sharedUtil.isArray;
  18114. var shadow = sharedUtil.shadow;
  18115. var warn = sharedUtil.warn;
  18116. var Dict = corePrimitives.Dict;
  18117. var Jbig2Image = coreJbig2.Jbig2Image;
  18118. var JpegImage = coreJpg.JpegImage;
  18119. var JpxImage = coreJpx.JpxImage;
  18120. var coreParser; // see _setCoreParser below
  18121. var EOF; // = coreParser.EOF;
  18122. var Lexer; // = coreParser.Lexer;
  18123. var coreColorSpace; // see _setCoreColorSpace below
  18124. var ColorSpace; // = coreColorSpace.ColorSpace;
  18125. var Stream = (function StreamClosure() {
  18126. function Stream(arrayBuffer, start, length, dict) {
  18127. this.bytes = (arrayBuffer instanceof Uint8Array ?
  18128. arrayBuffer : new Uint8Array(arrayBuffer));
  18129. this.start = start || 0;
  18130. this.pos = this.start;
  18131. this.end = (start + length) || this.bytes.length;
  18132. this.dict = dict;
  18133. }
  18134. // required methods for a stream. if a particular stream does not
  18135. // implement these, an error should be thrown
  18136. Stream.prototype = {
  18137. get length() {
  18138. return this.end - this.start;
  18139. },
  18140. get isEmpty() {
  18141. return this.length === 0;
  18142. },
  18143. getByte: function Stream_getByte() {
  18144. if (this.pos >= this.end) {
  18145. return -1;
  18146. }
  18147. return this.bytes[this.pos++];
  18148. },
  18149. getUint16: function Stream_getUint16() {
  18150. var b0 = this.getByte();
  18151. var b1 = this.getByte();
  18152. if (b0 === -1 || b1 === -1) {
  18153. return -1;
  18154. }
  18155. return (b0 << 8) + b1;
  18156. },
  18157. getInt32: function Stream_getInt32() {
  18158. var b0 = this.getByte();
  18159. var b1 = this.getByte();
  18160. var b2 = this.getByte();
  18161. var b3 = this.getByte();
  18162. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  18163. },
  18164. // returns subarray of original buffer
  18165. // should only be read
  18166. getBytes: function Stream_getBytes(length) {
  18167. var bytes = this.bytes;
  18168. var pos = this.pos;
  18169. var strEnd = this.end;
  18170. if (!length) {
  18171. return bytes.subarray(pos, strEnd);
  18172. }
  18173. var end = pos + length;
  18174. if (end > strEnd) {
  18175. end = strEnd;
  18176. }
  18177. this.pos = end;
  18178. return bytes.subarray(pos, end);
  18179. },
  18180. peekByte: function Stream_peekByte() {
  18181. var peekedByte = this.getByte();
  18182. this.pos--;
  18183. return peekedByte;
  18184. },
  18185. peekBytes: function Stream_peekBytes(length) {
  18186. var bytes = this.getBytes(length);
  18187. this.pos -= bytes.length;
  18188. return bytes;
  18189. },
  18190. skip: function Stream_skip(n) {
  18191. if (!n) {
  18192. n = 1;
  18193. }
  18194. this.pos += n;
  18195. },
  18196. reset: function Stream_reset() {
  18197. this.pos = this.start;
  18198. },
  18199. moveStart: function Stream_moveStart() {
  18200. this.start = this.pos;
  18201. },
  18202. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  18203. return new Stream(this.bytes.buffer, start, length, dict);
  18204. },
  18205. isStream: true
  18206. };
  18207. return Stream;
  18208. })();
  18209. var StringStream = (function StringStreamClosure() {
  18210. function StringStream(str) {
  18211. var length = str.length;
  18212. var bytes = new Uint8Array(length);
  18213. for (var n = 0; n < length; ++n) {
  18214. bytes[n] = str.charCodeAt(n);
  18215. }
  18216. Stream.call(this, bytes);
  18217. }
  18218. StringStream.prototype = Stream.prototype;
  18219. return StringStream;
  18220. })();
  18221. // super class for the decoding streams
  18222. var DecodeStream = (function DecodeStreamClosure() {
  18223. // Lots of DecodeStreams are created whose buffers are never used. For these
  18224. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  18225. // having special cases that would be required if we used |null| for an empty
  18226. // buffer.
  18227. var emptyBuffer = new Uint8Array(0);
  18228. function DecodeStream(maybeMinBufferLength) {
  18229. this.pos = 0;
  18230. this.bufferLength = 0;
  18231. this.eof = false;
  18232. this.buffer = emptyBuffer;
  18233. this.minBufferLength = 512;
  18234. if (maybeMinBufferLength) {
  18235. // Compute the first power of two that is as big as maybeMinBufferLength.
  18236. while (this.minBufferLength < maybeMinBufferLength) {
  18237. this.minBufferLength *= 2;
  18238. }
  18239. }
  18240. }
  18241. DecodeStream.prototype = {
  18242. get isEmpty() {
  18243. while (!this.eof && this.bufferLength === 0) {
  18244. this.readBlock();
  18245. }
  18246. return this.bufferLength === 0;
  18247. },
  18248. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  18249. var buffer = this.buffer;
  18250. if (requested <= buffer.byteLength) {
  18251. return buffer;
  18252. }
  18253. var size = this.minBufferLength;
  18254. while (size < requested) {
  18255. size *= 2;
  18256. }
  18257. var buffer2 = new Uint8Array(size);
  18258. buffer2.set(buffer);
  18259. return (this.buffer = buffer2);
  18260. },
  18261. getByte: function DecodeStream_getByte() {
  18262. var pos = this.pos;
  18263. while (this.bufferLength <= pos) {
  18264. if (this.eof) {
  18265. return -1;
  18266. }
  18267. this.readBlock();
  18268. }
  18269. return this.buffer[this.pos++];
  18270. },
  18271. getUint16: function DecodeStream_getUint16() {
  18272. var b0 = this.getByte();
  18273. var b1 = this.getByte();
  18274. if (b0 === -1 || b1 === -1) {
  18275. return -1;
  18276. }
  18277. return (b0 << 8) + b1;
  18278. },
  18279. getInt32: function DecodeStream_getInt32() {
  18280. var b0 = this.getByte();
  18281. var b1 = this.getByte();
  18282. var b2 = this.getByte();
  18283. var b3 = this.getByte();
  18284. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  18285. },
  18286. getBytes: function DecodeStream_getBytes(length) {
  18287. var end, pos = this.pos;
  18288. if (length) {
  18289. this.ensureBuffer(pos + length);
  18290. end = pos + length;
  18291. while (!this.eof && this.bufferLength < end) {
  18292. this.readBlock();
  18293. }
  18294. var bufEnd = this.bufferLength;
  18295. if (end > bufEnd) {
  18296. end = bufEnd;
  18297. }
  18298. } else {
  18299. while (!this.eof) {
  18300. this.readBlock();
  18301. }
  18302. end = this.bufferLength;
  18303. }
  18304. this.pos = end;
  18305. return this.buffer.subarray(pos, end);
  18306. },
  18307. peekByte: function DecodeStream_peekByte() {
  18308. var peekedByte = this.getByte();
  18309. this.pos--;
  18310. return peekedByte;
  18311. },
  18312. peekBytes: function DecodeStream_peekBytes(length) {
  18313. var bytes = this.getBytes(length);
  18314. this.pos -= bytes.length;
  18315. return bytes;
  18316. },
  18317. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  18318. var end = start + length;
  18319. while (this.bufferLength <= end && !this.eof) {
  18320. this.readBlock();
  18321. }
  18322. return new Stream(this.buffer, start, length, dict);
  18323. },
  18324. skip: function DecodeStream_skip(n) {
  18325. if (!n) {
  18326. n = 1;
  18327. }
  18328. this.pos += n;
  18329. },
  18330. reset: function DecodeStream_reset() {
  18331. this.pos = 0;
  18332. },
  18333. getBaseStreams: function DecodeStream_getBaseStreams() {
  18334. if (this.str && this.str.getBaseStreams) {
  18335. return this.str.getBaseStreams();
  18336. }
  18337. return [];
  18338. }
  18339. };
  18340. return DecodeStream;
  18341. })();
  18342. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  18343. function StreamsSequenceStream(streams) {
  18344. this.streams = streams;
  18345. DecodeStream.call(this, /* maybeLength = */ null);
  18346. }
  18347. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  18348. StreamsSequenceStream.prototype.readBlock =
  18349. function streamSequenceStreamReadBlock() {
  18350. var streams = this.streams;
  18351. if (streams.length === 0) {
  18352. this.eof = true;
  18353. return;
  18354. }
  18355. var stream = streams.shift();
  18356. var chunk = stream.getBytes();
  18357. var bufferLength = this.bufferLength;
  18358. var newLength = bufferLength + chunk.length;
  18359. var buffer = this.ensureBuffer(newLength);
  18360. buffer.set(chunk, bufferLength);
  18361. this.bufferLength = newLength;
  18362. };
  18363. StreamsSequenceStream.prototype.getBaseStreams =
  18364. function StreamsSequenceStream_getBaseStreams() {
  18365. var baseStreams = [];
  18366. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  18367. var stream = this.streams[i];
  18368. if (stream.getBaseStreams) {
  18369. Util.appendToArray(baseStreams, stream.getBaseStreams());
  18370. }
  18371. }
  18372. return baseStreams;
  18373. };
  18374. return StreamsSequenceStream;
  18375. })();
  18376. var FlateStream = (function FlateStreamClosure() {
  18377. var codeLenCodeMap = new Int32Array([
  18378. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  18379. ]);
  18380. var lengthDecode = new Int32Array([
  18381. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  18382. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  18383. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  18384. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  18385. ]);
  18386. var distDecode = new Int32Array([
  18387. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  18388. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  18389. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  18390. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  18391. ]);
  18392. var fixedLitCodeTab = [new Int32Array([
  18393. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  18394. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  18395. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  18396. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  18397. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  18398. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  18399. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  18400. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  18401. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  18402. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  18403. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  18404. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  18405. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  18406. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  18407. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  18408. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  18409. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  18410. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  18411. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  18412. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  18413. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  18414. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  18415. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  18416. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  18417. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  18418. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  18419. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  18420. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  18421. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  18422. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  18423. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  18424. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  18425. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  18426. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  18427. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  18428. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  18429. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  18430. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  18431. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  18432. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  18433. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  18434. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  18435. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  18436. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  18437. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  18438. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  18439. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  18440. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  18441. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  18442. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  18443. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  18444. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  18445. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  18446. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  18447. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  18448. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  18449. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  18450. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  18451. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  18452. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  18453. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  18454. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  18455. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  18456. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  18457. ]), 9];
  18458. var fixedDistCodeTab = [new Int32Array([
  18459. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  18460. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  18461. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  18462. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  18463. ]), 5];
  18464. function FlateStream(str, maybeLength) {
  18465. this.str = str;
  18466. this.dict = str.dict;
  18467. var cmf = str.getByte();
  18468. var flg = str.getByte();
  18469. if (cmf === -1 || flg === -1) {
  18470. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  18471. }
  18472. if ((cmf & 0x0f) !== 0x08) {
  18473. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  18474. }
  18475. if ((((cmf << 8) + flg) % 31) !== 0) {
  18476. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  18477. }
  18478. if (flg & 0x20) {
  18479. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  18480. }
  18481. this.codeSize = 0;
  18482. this.codeBuf = 0;
  18483. DecodeStream.call(this, maybeLength);
  18484. }
  18485. FlateStream.prototype = Object.create(DecodeStream.prototype);
  18486. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  18487. var str = this.str;
  18488. var codeSize = this.codeSize;
  18489. var codeBuf = this.codeBuf;
  18490. var b;
  18491. while (codeSize < bits) {
  18492. if ((b = str.getByte()) === -1) {
  18493. error('Bad encoding in flate stream');
  18494. }
  18495. codeBuf |= b << codeSize;
  18496. codeSize += 8;
  18497. }
  18498. b = codeBuf & ((1 << bits) - 1);
  18499. this.codeBuf = codeBuf >> bits;
  18500. this.codeSize = codeSize -= bits;
  18501. return b;
  18502. };
  18503. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  18504. var str = this.str;
  18505. var codes = table[0];
  18506. var maxLen = table[1];
  18507. var codeSize = this.codeSize;
  18508. var codeBuf = this.codeBuf;
  18509. var b;
  18510. while (codeSize < maxLen) {
  18511. if ((b = str.getByte()) === -1) {
  18512. // premature end of stream. code might however still be valid.
  18513. // codeSize < codeLen check below guards against incomplete codeVal.
  18514. break;
  18515. }
  18516. codeBuf |= (b << codeSize);
  18517. codeSize += 8;
  18518. }
  18519. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  18520. var codeLen = code >> 16;
  18521. var codeVal = code & 0xffff;
  18522. if (codeLen < 1 || codeSize < codeLen) {
  18523. error('Bad encoding in flate stream');
  18524. }
  18525. this.codeBuf = (codeBuf >> codeLen);
  18526. this.codeSize = (codeSize - codeLen);
  18527. return codeVal;
  18528. };
  18529. FlateStream.prototype.generateHuffmanTable =
  18530. function flateStreamGenerateHuffmanTable(lengths) {
  18531. var n = lengths.length;
  18532. // find max code length
  18533. var maxLen = 0;
  18534. var i;
  18535. for (i = 0; i < n; ++i) {
  18536. if (lengths[i] > maxLen) {
  18537. maxLen = lengths[i];
  18538. }
  18539. }
  18540. // build the table
  18541. var size = 1 << maxLen;
  18542. var codes = new Int32Array(size);
  18543. for (var len = 1, code = 0, skip = 2;
  18544. len <= maxLen;
  18545. ++len, code <<= 1, skip <<= 1) {
  18546. for (var val = 0; val < n; ++val) {
  18547. if (lengths[val] === len) {
  18548. // bit-reverse the code
  18549. var code2 = 0;
  18550. var t = code;
  18551. for (i = 0; i < len; ++i) {
  18552. code2 = (code2 << 1) | (t & 1);
  18553. t >>= 1;
  18554. }
  18555. // fill the table entries
  18556. for (i = code2; i < size; i += skip) {
  18557. codes[i] = (len << 16) | val;
  18558. }
  18559. ++code;
  18560. }
  18561. }
  18562. }
  18563. return [codes, maxLen];
  18564. };
  18565. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  18566. var buffer, len;
  18567. var str = this.str;
  18568. // read block header
  18569. var hdr = this.getBits(3);
  18570. if (hdr & 1) {
  18571. this.eof = true;
  18572. }
  18573. hdr >>= 1;
  18574. if (hdr === 0) { // uncompressed block
  18575. var b;
  18576. if ((b = str.getByte()) === -1) {
  18577. error('Bad block header in flate stream');
  18578. }
  18579. var blockLen = b;
  18580. if ((b = str.getByte()) === -1) {
  18581. error('Bad block header in flate stream');
  18582. }
  18583. blockLen |= (b << 8);
  18584. if ((b = str.getByte()) === -1) {
  18585. error('Bad block header in flate stream');
  18586. }
  18587. var check = b;
  18588. if ((b = str.getByte()) === -1) {
  18589. error('Bad block header in flate stream');
  18590. }
  18591. check |= (b << 8);
  18592. if (check !== (~blockLen & 0xffff) &&
  18593. (blockLen !== 0 || check !== 0)) {
  18594. // Ignoring error for bad "empty" block (see issue 1277)
  18595. error('Bad uncompressed block length in flate stream');
  18596. }
  18597. this.codeBuf = 0;
  18598. this.codeSize = 0;
  18599. var bufferLength = this.bufferLength;
  18600. buffer = this.ensureBuffer(bufferLength + blockLen);
  18601. var end = bufferLength + blockLen;
  18602. this.bufferLength = end;
  18603. if (blockLen === 0) {
  18604. if (str.peekByte() === -1) {
  18605. this.eof = true;
  18606. }
  18607. } else {
  18608. for (var n = bufferLength; n < end; ++n) {
  18609. if ((b = str.getByte()) === -1) {
  18610. this.eof = true;
  18611. break;
  18612. }
  18613. buffer[n] = b;
  18614. }
  18615. }
  18616. return;
  18617. }
  18618. var litCodeTable;
  18619. var distCodeTable;
  18620. if (hdr === 1) { // compressed block, fixed codes
  18621. litCodeTable = fixedLitCodeTab;
  18622. distCodeTable = fixedDistCodeTab;
  18623. } else if (hdr === 2) { // compressed block, dynamic codes
  18624. var numLitCodes = this.getBits(5) + 257;
  18625. var numDistCodes = this.getBits(5) + 1;
  18626. var numCodeLenCodes = this.getBits(4) + 4;
  18627. // build the code lengths code table
  18628. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  18629. var i;
  18630. for (i = 0; i < numCodeLenCodes; ++i) {
  18631. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  18632. }
  18633. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  18634. // build the literal and distance code tables
  18635. len = 0;
  18636. i = 0;
  18637. var codes = numLitCodes + numDistCodes;
  18638. var codeLengths = new Uint8Array(codes);
  18639. var bitsLength, bitsOffset, what;
  18640. while (i < codes) {
  18641. var code = this.getCode(codeLenCodeTab);
  18642. if (code === 16) {
  18643. bitsLength = 2; bitsOffset = 3; what = len;
  18644. } else if (code === 17) {
  18645. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  18646. } else if (code === 18) {
  18647. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  18648. } else {
  18649. codeLengths[i++] = len = code;
  18650. continue;
  18651. }
  18652. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  18653. while (repeatLength-- > 0) {
  18654. codeLengths[i++] = what;
  18655. }
  18656. }
  18657. litCodeTable =
  18658. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  18659. distCodeTable =
  18660. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  18661. } else {
  18662. error('Unknown block type in flate stream');
  18663. }
  18664. buffer = this.buffer;
  18665. var limit = buffer ? buffer.length : 0;
  18666. var pos = this.bufferLength;
  18667. while (true) {
  18668. var code1 = this.getCode(litCodeTable);
  18669. if (code1 < 256) {
  18670. if (pos + 1 >= limit) {
  18671. buffer = this.ensureBuffer(pos + 1);
  18672. limit = buffer.length;
  18673. }
  18674. buffer[pos++] = code1;
  18675. continue;
  18676. }
  18677. if (code1 === 256) {
  18678. this.bufferLength = pos;
  18679. return;
  18680. }
  18681. code1 -= 257;
  18682. code1 = lengthDecode[code1];
  18683. var code2 = code1 >> 16;
  18684. if (code2 > 0) {
  18685. code2 = this.getBits(code2);
  18686. }
  18687. len = (code1 & 0xffff) + code2;
  18688. code1 = this.getCode(distCodeTable);
  18689. code1 = distDecode[code1];
  18690. code2 = code1 >> 16;
  18691. if (code2 > 0) {
  18692. code2 = this.getBits(code2);
  18693. }
  18694. var dist = (code1 & 0xffff) + code2;
  18695. if (pos + len >= limit) {
  18696. buffer = this.ensureBuffer(pos + len);
  18697. limit = buffer.length;
  18698. }
  18699. for (var k = 0; k < len; ++k, ++pos) {
  18700. buffer[pos] = buffer[pos - dist];
  18701. }
  18702. }
  18703. };
  18704. return FlateStream;
  18705. })();
  18706. var PredictorStream = (function PredictorStreamClosure() {
  18707. function PredictorStream(str, maybeLength, params) {
  18708. var predictor = this.predictor = params.get('Predictor') || 1;
  18709. if (predictor <= 1) {
  18710. return str; // no prediction
  18711. }
  18712. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  18713. error('Unsupported predictor: ' + predictor);
  18714. }
  18715. if (predictor === 2) {
  18716. this.readBlock = this.readBlockTiff;
  18717. } else {
  18718. this.readBlock = this.readBlockPng;
  18719. }
  18720. this.str = str;
  18721. this.dict = str.dict;
  18722. var colors = this.colors = params.get('Colors') || 1;
  18723. var bits = this.bits = params.get('BitsPerComponent') || 8;
  18724. var columns = this.columns = params.get('Columns') || 1;
  18725. this.pixBytes = (colors * bits + 7) >> 3;
  18726. this.rowBytes = (columns * colors * bits + 7) >> 3;
  18727. DecodeStream.call(this, maybeLength);
  18728. return this;
  18729. }
  18730. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  18731. PredictorStream.prototype.readBlockTiff =
  18732. function predictorStreamReadBlockTiff() {
  18733. var rowBytes = this.rowBytes;
  18734. var bufferLength = this.bufferLength;
  18735. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18736. var bits = this.bits;
  18737. var colors = this.colors;
  18738. var rawBytes = this.str.getBytes(rowBytes);
  18739. this.eof = !rawBytes.length;
  18740. if (this.eof) {
  18741. return;
  18742. }
  18743. var inbuf = 0, outbuf = 0;
  18744. var inbits = 0, outbits = 0;
  18745. var pos = bufferLength;
  18746. var i;
  18747. if (bits === 1) {
  18748. for (i = 0; i < rowBytes; ++i) {
  18749. var c = rawBytes[i];
  18750. inbuf = (inbuf << 8) | c;
  18751. // bitwise addition is exclusive or
  18752. // first shift inbuf and then add
  18753. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  18754. // truncate inbuf (assumes colors < 16)
  18755. inbuf &= 0xFFFF;
  18756. }
  18757. } else if (bits === 8) {
  18758. for (i = 0; i < colors; ++i) {
  18759. buffer[pos++] = rawBytes[i];
  18760. }
  18761. for (; i < rowBytes; ++i) {
  18762. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  18763. pos++;
  18764. }
  18765. } else {
  18766. var compArray = new Uint8Array(colors + 1);
  18767. var bitMask = (1 << bits) - 1;
  18768. var j = 0, k = bufferLength;
  18769. var columns = this.columns;
  18770. for (i = 0; i < columns; ++i) {
  18771. for (var kk = 0; kk < colors; ++kk) {
  18772. if (inbits < bits) {
  18773. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  18774. inbits += 8;
  18775. }
  18776. compArray[kk] = (compArray[kk] +
  18777. (inbuf >> (inbits - bits))) & bitMask;
  18778. inbits -= bits;
  18779. outbuf = (outbuf << bits) | compArray[kk];
  18780. outbits += bits;
  18781. if (outbits >= 8) {
  18782. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  18783. outbits -= 8;
  18784. }
  18785. }
  18786. }
  18787. if (outbits > 0) {
  18788. buffer[k++] = (outbuf << (8 - outbits)) +
  18789. (inbuf & ((1 << (8 - outbits)) - 1));
  18790. }
  18791. }
  18792. this.bufferLength += rowBytes;
  18793. };
  18794. PredictorStream.prototype.readBlockPng =
  18795. function predictorStreamReadBlockPng() {
  18796. var rowBytes = this.rowBytes;
  18797. var pixBytes = this.pixBytes;
  18798. var predictor = this.str.getByte();
  18799. var rawBytes = this.str.getBytes(rowBytes);
  18800. this.eof = !rawBytes.length;
  18801. if (this.eof) {
  18802. return;
  18803. }
  18804. var bufferLength = this.bufferLength;
  18805. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18806. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  18807. if (prevRow.length === 0) {
  18808. prevRow = new Uint8Array(rowBytes);
  18809. }
  18810. var i, j = bufferLength, up, c;
  18811. switch (predictor) {
  18812. case 0:
  18813. for (i = 0; i < rowBytes; ++i) {
  18814. buffer[j++] = rawBytes[i];
  18815. }
  18816. break;
  18817. case 1:
  18818. for (i = 0; i < pixBytes; ++i) {
  18819. buffer[j++] = rawBytes[i];
  18820. }
  18821. for (; i < rowBytes; ++i) {
  18822. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  18823. j++;
  18824. }
  18825. break;
  18826. case 2:
  18827. for (i = 0; i < rowBytes; ++i) {
  18828. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  18829. }
  18830. break;
  18831. case 3:
  18832. for (i = 0; i < pixBytes; ++i) {
  18833. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  18834. }
  18835. for (; i < rowBytes; ++i) {
  18836. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  18837. rawBytes[i]) & 0xFF;
  18838. j++;
  18839. }
  18840. break;
  18841. case 4:
  18842. // we need to save the up left pixels values. the simplest way
  18843. // is to create a new buffer
  18844. for (i = 0; i < pixBytes; ++i) {
  18845. up = prevRow[i];
  18846. c = rawBytes[i];
  18847. buffer[j++] = up + c;
  18848. }
  18849. for (; i < rowBytes; ++i) {
  18850. up = prevRow[i];
  18851. var upLeft = prevRow[i - pixBytes];
  18852. var left = buffer[j - pixBytes];
  18853. var p = left + up - upLeft;
  18854. var pa = p - left;
  18855. if (pa < 0) {
  18856. pa = -pa;
  18857. }
  18858. var pb = p - up;
  18859. if (pb < 0) {
  18860. pb = -pb;
  18861. }
  18862. var pc = p - upLeft;
  18863. if (pc < 0) {
  18864. pc = -pc;
  18865. }
  18866. c = rawBytes[i];
  18867. if (pa <= pb && pa <= pc) {
  18868. buffer[j++] = left + c;
  18869. } else if (pb <= pc) {
  18870. buffer[j++] = up + c;
  18871. } else {
  18872. buffer[j++] = upLeft + c;
  18873. }
  18874. }
  18875. break;
  18876. default:
  18877. error('Unsupported predictor: ' + predictor);
  18878. }
  18879. this.bufferLength += rowBytes;
  18880. };
  18881. return PredictorStream;
  18882. })();
  18883. /**
  18884. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  18885. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  18886. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  18887. * a library to decode these images and the stream behaves like all the other
  18888. * DecodeStreams.
  18889. */
  18890. var JpegStream = (function JpegStreamClosure() {
  18891. function JpegStream(stream, maybeLength, dict, xref) {
  18892. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  18893. // Note: this seems to mainly affect inline images.
  18894. var ch;
  18895. while ((ch = stream.getByte()) !== -1) {
  18896. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  18897. stream.skip(-1); // Reset the stream position to the SOI.
  18898. break;
  18899. }
  18900. }
  18901. this.stream = stream;
  18902. this.maybeLength = maybeLength;
  18903. this.dict = dict;
  18904. DecodeStream.call(this, maybeLength);
  18905. }
  18906. JpegStream.prototype = Object.create(DecodeStream.prototype);
  18907. Object.defineProperty(JpegStream.prototype, 'bytes', {
  18908. get: function JpegStream_bytes() {
  18909. // If this.maybeLength is null, we'll get the entire stream.
  18910. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18911. },
  18912. configurable: true
  18913. });
  18914. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  18915. if (this.bufferLength) {
  18916. return;
  18917. }
  18918. try {
  18919. var jpegImage = new JpegImage();
  18920. // checking if values needs to be transformed before conversion
  18921. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  18922. var decodeArr = this.dict.get('Decode');
  18923. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  18924. var decodeArrLength = decodeArr.length;
  18925. var transform = new Int32Array(decodeArrLength);
  18926. var transformNeeded = false;
  18927. var maxValue = (1 << bitsPerComponent) - 1;
  18928. for (var i = 0; i < decodeArrLength; i += 2) {
  18929. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  18930. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  18931. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  18932. transformNeeded = true;
  18933. }
  18934. }
  18935. if (transformNeeded) {
  18936. jpegImage.decodeTransform = transform;
  18937. }
  18938. }
  18939. jpegImage.parse(this.bytes);
  18940. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  18941. this.forceRGB);
  18942. this.buffer = data;
  18943. this.bufferLength = data.length;
  18944. this.eof = true;
  18945. } catch (e) {
  18946. error('JPEG error: ' + e);
  18947. }
  18948. };
  18949. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  18950. this.ensureBuffer();
  18951. return this.buffer;
  18952. };
  18953. JpegStream.prototype.getIR = function JpegStream_getIR() {
  18954. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  18955. };
  18956. /**
  18957. * Checks if the image can be decoded and displayed by the browser without any
  18958. * further processing such as color space conversions.
  18959. */
  18960. JpegStream.prototype.isNativelySupported =
  18961. function JpegStream_isNativelySupported(xref, res) {
  18962. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18963. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  18964. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18965. };
  18966. /**
  18967. * Checks if the image can be decoded by the browser.
  18968. */
  18969. JpegStream.prototype.isNativelyDecodable =
  18970. function JpegStream_isNativelyDecodable(xref, res) {
  18971. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18972. return (cs.numComps === 1 || cs.numComps === 3) &&
  18973. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18974. };
  18975. return JpegStream;
  18976. })();
  18977. /**
  18978. * For JPEG 2000's we use a library to decode these images and
  18979. * the stream behaves like all the other DecodeStreams.
  18980. */
  18981. var JpxStream = (function JpxStreamClosure() {
  18982. function JpxStream(stream, maybeLength, dict) {
  18983. this.stream = stream;
  18984. this.maybeLength = maybeLength;
  18985. this.dict = dict;
  18986. DecodeStream.call(this, maybeLength);
  18987. }
  18988. JpxStream.prototype = Object.create(DecodeStream.prototype);
  18989. Object.defineProperty(JpxStream.prototype, 'bytes', {
  18990. get: function JpxStream_bytes() {
  18991. // If this.maybeLength is null, we'll get the entire stream.
  18992. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18993. },
  18994. configurable: true
  18995. });
  18996. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  18997. if (this.bufferLength) {
  18998. return;
  18999. }
  19000. var jpxImage = new JpxImage();
  19001. jpxImage.parse(this.bytes);
  19002. var width = jpxImage.width;
  19003. var height = jpxImage.height;
  19004. var componentsCount = jpxImage.componentsCount;
  19005. var tileCount = jpxImage.tiles.length;
  19006. if (tileCount === 1) {
  19007. this.buffer = jpxImage.tiles[0].items;
  19008. } else {
  19009. var data = new Uint8Array(width * height * componentsCount);
  19010. for (var k = 0; k < tileCount; k++) {
  19011. var tileComponents = jpxImage.tiles[k];
  19012. var tileWidth = tileComponents.width;
  19013. var tileHeight = tileComponents.height;
  19014. var tileLeft = tileComponents.left;
  19015. var tileTop = tileComponents.top;
  19016. var src = tileComponents.items;
  19017. var srcPosition = 0;
  19018. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  19019. var imgRowSize = width * componentsCount;
  19020. var tileRowSize = tileWidth * componentsCount;
  19021. for (var j = 0; j < tileHeight; j++) {
  19022. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  19023. data.set(rowBytes, dataPosition);
  19024. srcPosition += tileRowSize;
  19025. dataPosition += imgRowSize;
  19026. }
  19027. }
  19028. this.buffer = data;
  19029. }
  19030. this.bufferLength = this.buffer.length;
  19031. this.eof = true;
  19032. };
  19033. return JpxStream;
  19034. })();
  19035. /**
  19036. * For JBIG2's we use a library to decode these images and
  19037. * the stream behaves like all the other DecodeStreams.
  19038. */
  19039. var Jbig2Stream = (function Jbig2StreamClosure() {
  19040. function Jbig2Stream(stream, maybeLength, dict) {
  19041. this.stream = stream;
  19042. this.maybeLength = maybeLength;
  19043. this.dict = dict;
  19044. DecodeStream.call(this, maybeLength);
  19045. }
  19046. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  19047. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  19048. get: function Jbig2Stream_bytes() {
  19049. // If this.maybeLength is null, we'll get the entire stream.
  19050. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19051. },
  19052. configurable: true
  19053. });
  19054. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  19055. if (this.bufferLength) {
  19056. return;
  19057. }
  19058. var jbig2Image = new Jbig2Image();
  19059. var chunks = [], xref = this.dict.xref;
  19060. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  19061. // According to the PDF specification, DecodeParms can be either
  19062. // a dictionary, or an array whose elements are dictionaries.
  19063. if (isArray(decodeParams)) {
  19064. if (decodeParams.length > 1) {
  19065. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  19066. 'not supported.');
  19067. }
  19068. decodeParams = xref.fetchIfRef(decodeParams[0]);
  19069. }
  19070. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  19071. var globalsStream = decodeParams.get('JBIG2Globals');
  19072. var globals = globalsStream.getBytes();
  19073. chunks.push({data: globals, start: 0, end: globals.length});
  19074. }
  19075. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  19076. var data = jbig2Image.parseChunks(chunks);
  19077. var dataLength = data.length;
  19078. // JBIG2 had black as 1 and white as 0, inverting the colors
  19079. for (var i = 0; i < dataLength; i++) {
  19080. data[i] ^= 0xFF;
  19081. }
  19082. this.buffer = data;
  19083. this.bufferLength = dataLength;
  19084. this.eof = true;
  19085. };
  19086. return Jbig2Stream;
  19087. })();
  19088. var DecryptStream = (function DecryptStreamClosure() {
  19089. function DecryptStream(str, maybeLength, decrypt) {
  19090. this.str = str;
  19091. this.dict = str.dict;
  19092. this.decrypt = decrypt;
  19093. this.nextChunk = null;
  19094. this.initialized = false;
  19095. DecodeStream.call(this, maybeLength);
  19096. }
  19097. var chunkSize = 512;
  19098. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  19099. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  19100. var chunk;
  19101. if (this.initialized) {
  19102. chunk = this.nextChunk;
  19103. } else {
  19104. chunk = this.str.getBytes(chunkSize);
  19105. this.initialized = true;
  19106. }
  19107. if (!chunk || chunk.length === 0) {
  19108. this.eof = true;
  19109. return;
  19110. }
  19111. this.nextChunk = this.str.getBytes(chunkSize);
  19112. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  19113. var decrypt = this.decrypt;
  19114. chunk = decrypt(chunk, !hasMoreData);
  19115. var bufferLength = this.bufferLength;
  19116. var i, n = chunk.length;
  19117. var buffer = this.ensureBuffer(bufferLength + n);
  19118. for (i = 0; i < n; i++) {
  19119. buffer[bufferLength++] = chunk[i];
  19120. }
  19121. this.bufferLength = bufferLength;
  19122. };
  19123. return DecryptStream;
  19124. })();
  19125. var Ascii85Stream = (function Ascii85StreamClosure() {
  19126. function Ascii85Stream(str, maybeLength) {
  19127. this.str = str;
  19128. this.dict = str.dict;
  19129. this.input = new Uint8Array(5);
  19130. // Most streams increase in size when decoded, but Ascii85 streams
  19131. // typically shrink by ~20%.
  19132. if (maybeLength) {
  19133. maybeLength = 0.8 * maybeLength;
  19134. }
  19135. DecodeStream.call(this, maybeLength);
  19136. }
  19137. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  19138. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  19139. var TILDA_CHAR = 0x7E; // '~'
  19140. var Z_LOWER_CHAR = 0x7A; // 'z'
  19141. var EOF = -1;
  19142. var str = this.str;
  19143. var c = str.getByte();
  19144. while (Lexer.isSpace(c)) {
  19145. c = str.getByte();
  19146. }
  19147. if (c === EOF || c === TILDA_CHAR) {
  19148. this.eof = true;
  19149. return;
  19150. }
  19151. var bufferLength = this.bufferLength, buffer;
  19152. var i;
  19153. // special code for z
  19154. if (c === Z_LOWER_CHAR) {
  19155. buffer = this.ensureBuffer(bufferLength + 4);
  19156. for (i = 0; i < 4; ++i) {
  19157. buffer[bufferLength + i] = 0;
  19158. }
  19159. this.bufferLength += 4;
  19160. } else {
  19161. var input = this.input;
  19162. input[0] = c;
  19163. for (i = 1; i < 5; ++i) {
  19164. c = str.getByte();
  19165. while (Lexer.isSpace(c)) {
  19166. c = str.getByte();
  19167. }
  19168. input[i] = c;
  19169. if (c === EOF || c === TILDA_CHAR) {
  19170. break;
  19171. }
  19172. }
  19173. buffer = this.ensureBuffer(bufferLength + i - 1);
  19174. this.bufferLength += i - 1;
  19175. // partial ending;
  19176. if (i < 5) {
  19177. for (; i < 5; ++i) {
  19178. input[i] = 0x21 + 84;
  19179. }
  19180. this.eof = true;
  19181. }
  19182. var t = 0;
  19183. for (i = 0; i < 5; ++i) {
  19184. t = t * 85 + (input[i] - 0x21);
  19185. }
  19186. for (i = 3; i >= 0; --i) {
  19187. buffer[bufferLength + i] = t & 0xFF;
  19188. t >>= 8;
  19189. }
  19190. }
  19191. };
  19192. return Ascii85Stream;
  19193. })();
  19194. var AsciiHexStream = (function AsciiHexStreamClosure() {
  19195. function AsciiHexStream(str, maybeLength) {
  19196. this.str = str;
  19197. this.dict = str.dict;
  19198. this.firstDigit = -1;
  19199. // Most streams increase in size when decoded, but AsciiHex streams shrink
  19200. // by 50%.
  19201. if (maybeLength) {
  19202. maybeLength = 0.5 * maybeLength;
  19203. }
  19204. DecodeStream.call(this, maybeLength);
  19205. }
  19206. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  19207. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  19208. var UPSTREAM_BLOCK_SIZE = 8000;
  19209. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  19210. if (!bytes.length) {
  19211. this.eof = true;
  19212. return;
  19213. }
  19214. var maxDecodeLength = (bytes.length + 1) >> 1;
  19215. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  19216. var bufferLength = this.bufferLength;
  19217. var firstDigit = this.firstDigit;
  19218. for (var i = 0, ii = bytes.length; i < ii; i++) {
  19219. var ch = bytes[i], digit;
  19220. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  19221. digit = ch & 0x0F;
  19222. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  19223. // 'A'-'Z', 'a'-'z'
  19224. digit = (ch & 0x0F) + 9;
  19225. } else if (ch === 0x3E) { // '>'
  19226. this.eof = true;
  19227. break;
  19228. } else { // probably whitespace
  19229. continue; // ignoring
  19230. }
  19231. if (firstDigit < 0) {
  19232. firstDigit = digit;
  19233. } else {
  19234. buffer[bufferLength++] = (firstDigit << 4) | digit;
  19235. firstDigit = -1;
  19236. }
  19237. }
  19238. if (firstDigit >= 0 && this.eof) {
  19239. // incomplete byte
  19240. buffer[bufferLength++] = (firstDigit << 4);
  19241. firstDigit = -1;
  19242. }
  19243. this.firstDigit = firstDigit;
  19244. this.bufferLength = bufferLength;
  19245. };
  19246. return AsciiHexStream;
  19247. })();
  19248. var RunLengthStream = (function RunLengthStreamClosure() {
  19249. function RunLengthStream(str, maybeLength) {
  19250. this.str = str;
  19251. this.dict = str.dict;
  19252. DecodeStream.call(this, maybeLength);
  19253. }
  19254. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  19255. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  19256. // The repeatHeader has following format. The first byte defines type of run
  19257. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  19258. // (in addition to the second byte from the header), n = 129 through 255 -
  19259. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  19260. var repeatHeader = this.str.getBytes(2);
  19261. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  19262. this.eof = true;
  19263. return;
  19264. }
  19265. var buffer;
  19266. var bufferLength = this.bufferLength;
  19267. var n = repeatHeader[0];
  19268. if (n < 128) {
  19269. // copy n bytes
  19270. buffer = this.ensureBuffer(bufferLength + n + 1);
  19271. buffer[bufferLength++] = repeatHeader[1];
  19272. if (n > 0) {
  19273. var source = this.str.getBytes(n);
  19274. buffer.set(source, bufferLength);
  19275. bufferLength += n;
  19276. }
  19277. } else {
  19278. n = 257 - n;
  19279. var b = repeatHeader[1];
  19280. buffer = this.ensureBuffer(bufferLength + n + 1);
  19281. for (var i = 0; i < n; i++) {
  19282. buffer[bufferLength++] = b;
  19283. }
  19284. }
  19285. this.bufferLength = bufferLength;
  19286. };
  19287. return RunLengthStream;
  19288. })();
  19289. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  19290. var ccittEOL = -2;
  19291. var twoDimPass = 0;
  19292. var twoDimHoriz = 1;
  19293. var twoDimVert0 = 2;
  19294. var twoDimVertR1 = 3;
  19295. var twoDimVertL1 = 4;
  19296. var twoDimVertR2 = 5;
  19297. var twoDimVertL2 = 6;
  19298. var twoDimVertR3 = 7;
  19299. var twoDimVertL3 = 8;
  19300. var twoDimTable = [
  19301. [-1, -1], [-1, -1], // 000000x
  19302. [7, twoDimVertL3], // 0000010
  19303. [7, twoDimVertR3], // 0000011
  19304. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  19305. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  19306. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  19307. [4, twoDimPass], [4, twoDimPass],
  19308. [4, twoDimPass], [4, twoDimPass],
  19309. [4, twoDimPass], [4, twoDimPass],
  19310. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  19311. [3, twoDimHoriz], [3, twoDimHoriz],
  19312. [3, twoDimHoriz], [3, twoDimHoriz],
  19313. [3, twoDimHoriz], [3, twoDimHoriz],
  19314. [3, twoDimHoriz], [3, twoDimHoriz],
  19315. [3, twoDimHoriz], [3, twoDimHoriz],
  19316. [3, twoDimHoriz], [3, twoDimHoriz],
  19317. [3, twoDimHoriz], [3, twoDimHoriz],
  19318. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  19319. [3, twoDimVertL1], [3, twoDimVertL1],
  19320. [3, twoDimVertL1], [3, twoDimVertL1],
  19321. [3, twoDimVertL1], [3, twoDimVertL1],
  19322. [3, twoDimVertL1], [3, twoDimVertL1],
  19323. [3, twoDimVertL1], [3, twoDimVertL1],
  19324. [3, twoDimVertL1], [3, twoDimVertL1],
  19325. [3, twoDimVertL1], [3, twoDimVertL1],
  19326. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  19327. [3, twoDimVertR1], [3, twoDimVertR1],
  19328. [3, twoDimVertR1], [3, twoDimVertR1],
  19329. [3, twoDimVertR1], [3, twoDimVertR1],
  19330. [3, twoDimVertR1], [3, twoDimVertR1],
  19331. [3, twoDimVertR1], [3, twoDimVertR1],
  19332. [3, twoDimVertR1], [3, twoDimVertR1],
  19333. [3, twoDimVertR1], [3, twoDimVertR1],
  19334. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  19335. [1, twoDimVert0], [1, twoDimVert0],
  19336. [1, twoDimVert0], [1, twoDimVert0],
  19337. [1, twoDimVert0], [1, twoDimVert0],
  19338. [1, twoDimVert0], [1, twoDimVert0],
  19339. [1, twoDimVert0], [1, twoDimVert0],
  19340. [1, twoDimVert0], [1, twoDimVert0],
  19341. [1, twoDimVert0], [1, twoDimVert0],
  19342. [1, twoDimVert0], [1, twoDimVert0],
  19343. [1, twoDimVert0], [1, twoDimVert0],
  19344. [1, twoDimVert0], [1, twoDimVert0],
  19345. [1, twoDimVert0], [1, twoDimVert0],
  19346. [1, twoDimVert0], [1, twoDimVert0],
  19347. [1, twoDimVert0], [1, twoDimVert0],
  19348. [1, twoDimVert0], [1, twoDimVert0],
  19349. [1, twoDimVert0], [1, twoDimVert0],
  19350. [1, twoDimVert0], [1, twoDimVert0],
  19351. [1, twoDimVert0], [1, twoDimVert0],
  19352. [1, twoDimVert0], [1, twoDimVert0],
  19353. [1, twoDimVert0], [1, twoDimVert0],
  19354. [1, twoDimVert0], [1, twoDimVert0],
  19355. [1, twoDimVert0], [1, twoDimVert0],
  19356. [1, twoDimVert0], [1, twoDimVert0],
  19357. [1, twoDimVert0], [1, twoDimVert0],
  19358. [1, twoDimVert0], [1, twoDimVert0],
  19359. [1, twoDimVert0], [1, twoDimVert0],
  19360. [1, twoDimVert0], [1, twoDimVert0],
  19361. [1, twoDimVert0], [1, twoDimVert0],
  19362. [1, twoDimVert0], [1, twoDimVert0],
  19363. [1, twoDimVert0], [1, twoDimVert0],
  19364. [1, twoDimVert0], [1, twoDimVert0],
  19365. [1, twoDimVert0], [1, twoDimVert0]
  19366. ];
  19367. var whiteTable1 = [
  19368. [-1, -1], // 00000
  19369. [12, ccittEOL], // 00001
  19370. [-1, -1], [-1, -1], // 0001x
  19371. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  19372. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  19373. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  19374. [11, 1792], [11, 1792], // 1000x
  19375. [12, 1984], // 10010
  19376. [12, 2048], // 10011
  19377. [12, 2112], // 10100
  19378. [12, 2176], // 10101
  19379. [12, 2240], // 10110
  19380. [12, 2304], // 10111
  19381. [11, 1856], [11, 1856], // 1100x
  19382. [11, 1920], [11, 1920], // 1101x
  19383. [12, 2368], // 11100
  19384. [12, 2432], // 11101
  19385. [12, 2496], // 11110
  19386. [12, 2560] // 11111
  19387. ];
  19388. var whiteTable2 = [
  19389. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  19390. [8, 29], [8, 29], // 00000010x
  19391. [8, 30], [8, 30], // 00000011x
  19392. [8, 45], [8, 45], // 00000100x
  19393. [8, 46], [8, 46], // 00000101x
  19394. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  19395. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  19396. [8, 47], [8, 47], // 00001010x
  19397. [8, 48], [8, 48], // 00001011x
  19398. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  19399. [6, 13], [6, 13], [6, 13], [6, 13],
  19400. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  19401. [8, 33], [8, 33], // 00010010x
  19402. [8, 34], [8, 34], // 00010011x
  19403. [8, 35], [8, 35], // 00010100x
  19404. [8, 36], [8, 36], // 00010101x
  19405. [8, 37], [8, 37], // 00010110x
  19406. [8, 38], [8, 38], // 00010111x
  19407. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  19408. [8, 31], [8, 31], // 00011010x
  19409. [8, 32], [8, 32], // 00011011x
  19410. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  19411. [6, 1], [6, 1], [6, 1], [6, 1],
  19412. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  19413. [6, 12], [6, 12], [6, 12], [6, 12],
  19414. [8, 53], [8, 53], // 00100100x
  19415. [8, 54], [8, 54], // 00100101x
  19416. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  19417. [8, 39], [8, 39], // 00101000x
  19418. [8, 40], [8, 40], // 00101001x
  19419. [8, 41], [8, 41], // 00101010x
  19420. [8, 42], [8, 42], // 00101011x
  19421. [8, 43], [8, 43], // 00101100x
  19422. [8, 44], [8, 44], // 00101101x
  19423. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  19424. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  19425. [8, 61], [8, 61], // 00110010x
  19426. [8, 62], [8, 62], // 00110011x
  19427. [8, 63], [8, 63], // 00110100x
  19428. [8, 0], [8, 0], // 00110101x
  19429. [8, 320], [8, 320], // 00110110x
  19430. [8, 384], [8, 384], // 00110111x
  19431. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  19432. [5, 10], [5, 10], [5, 10], [5, 10],
  19433. [5, 10], [5, 10], [5, 10], [5, 10],
  19434. [5, 10], [5, 10], [5, 10], [5, 10],
  19435. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  19436. [5, 11], [5, 11], [5, 11], [5, 11],
  19437. [5, 11], [5, 11], [5, 11], [5, 11],
  19438. [5, 11], [5, 11], [5, 11], [5, 11],
  19439. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  19440. [8, 59], [8, 59], // 01001010x
  19441. [8, 60], [8, 60], // 01001011x
  19442. [9, 1472], // 010011000
  19443. [9, 1536], // 010011001
  19444. [9, 1600], // 010011010
  19445. [9, 1728], // 010011011
  19446. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  19447. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  19448. [8, 49], [8, 49], // 01010010x
  19449. [8, 50], [8, 50], // 01010011x
  19450. [8, 51], [8, 51], // 01010100x
  19451. [8, 52], [8, 52], // 01010101x
  19452. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  19453. [8, 55], [8, 55], // 01011000x
  19454. [8, 56], [8, 56], // 01011001x
  19455. [8, 57], [8, 57], // 01011010x
  19456. [8, 58], [8, 58], // 01011011x
  19457. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  19458. [6, 192], [6, 192], [6, 192], [6, 192],
  19459. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  19460. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  19461. [8, 448], [8, 448], // 01100100x
  19462. [8, 512], [8, 512], // 01100101x
  19463. [9, 704], // 011001100
  19464. [9, 768], // 011001101
  19465. [8, 640], [8, 640], // 01100111x
  19466. [8, 576], [8, 576], // 01101000x
  19467. [9, 832], // 011010010
  19468. [9, 896], // 011010011
  19469. [9, 960], // 011010100
  19470. [9, 1024], // 011010101
  19471. [9, 1088], // 011010110
  19472. [9, 1152], // 011010111
  19473. [9, 1216], // 011011000
  19474. [9, 1280], // 011011001
  19475. [9, 1344], // 011011010
  19476. [9, 1408], // 011011011
  19477. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  19478. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  19479. [4, 2], [4, 2], [4, 2], [4, 2],
  19480. [4, 2], [4, 2], [4, 2], [4, 2],
  19481. [4, 2], [4, 2], [4, 2], [4, 2],
  19482. [4, 2], [4, 2], [4, 2], [4, 2],
  19483. [4, 2], [4, 2], [4, 2], [4, 2],
  19484. [4, 2], [4, 2], [4, 2], [4, 2],
  19485. [4, 2], [4, 2], [4, 2], [4, 2],
  19486. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  19487. [4, 3], [4, 3], [4, 3], [4, 3],
  19488. [4, 3], [4, 3], [4, 3], [4, 3],
  19489. [4, 3], [4, 3], [4, 3], [4, 3],
  19490. [4, 3], [4, 3], [4, 3], [4, 3],
  19491. [4, 3], [4, 3], [4, 3], [4, 3],
  19492. [4, 3], [4, 3], [4, 3], [4, 3],
  19493. [4, 3], [4, 3], [4, 3], [4, 3],
  19494. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  19495. [5, 128], [5, 128], [5, 128], [5, 128],
  19496. [5, 128], [5, 128], [5, 128], [5, 128],
  19497. [5, 128], [5, 128], [5, 128], [5, 128],
  19498. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  19499. [5, 8], [5, 8], [5, 8], [5, 8],
  19500. [5, 8], [5, 8], [5, 8], [5, 8],
  19501. [5, 8], [5, 8], [5, 8], [5, 8],
  19502. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  19503. [5, 9], [5, 9], [5, 9], [5, 9],
  19504. [5, 9], [5, 9], [5, 9], [5, 9],
  19505. [5, 9], [5, 9], [5, 9], [5, 9],
  19506. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  19507. [6, 16], [6, 16], [6, 16], [6, 16],
  19508. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  19509. [6, 17], [6, 17], [6, 17], [6, 17],
  19510. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  19511. [4, 4], [4, 4], [4, 4], [4, 4],
  19512. [4, 4], [4, 4], [4, 4], [4, 4],
  19513. [4, 4], [4, 4], [4, 4], [4, 4],
  19514. [4, 4], [4, 4], [4, 4], [4, 4],
  19515. [4, 4], [4, 4], [4, 4], [4, 4],
  19516. [4, 4], [4, 4], [4, 4], [4, 4],
  19517. [4, 4], [4, 4], [4, 4], [4, 4],
  19518. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  19519. [4, 5], [4, 5], [4, 5], [4, 5],
  19520. [4, 5], [4, 5], [4, 5], [4, 5],
  19521. [4, 5], [4, 5], [4, 5], [4, 5],
  19522. [4, 5], [4, 5], [4, 5], [4, 5],
  19523. [4, 5], [4, 5], [4, 5], [4, 5],
  19524. [4, 5], [4, 5], [4, 5], [4, 5],
  19525. [4, 5], [4, 5], [4, 5], [4, 5],
  19526. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  19527. [6, 14], [6, 14], [6, 14], [6, 14],
  19528. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  19529. [6, 15], [6, 15], [6, 15], [6, 15],
  19530. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  19531. [5, 64], [5, 64], [5, 64], [5, 64],
  19532. [5, 64], [5, 64], [5, 64], [5, 64],
  19533. [5, 64], [5, 64], [5, 64], [5, 64],
  19534. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  19535. [4, 6], [4, 6], [4, 6], [4, 6],
  19536. [4, 6], [4, 6], [4, 6], [4, 6],
  19537. [4, 6], [4, 6], [4, 6], [4, 6],
  19538. [4, 6], [4, 6], [4, 6], [4, 6],
  19539. [4, 6], [4, 6], [4, 6], [4, 6],
  19540. [4, 6], [4, 6], [4, 6], [4, 6],
  19541. [4, 6], [4, 6], [4, 6], [4, 6],
  19542. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  19543. [4, 7], [4, 7], [4, 7], [4, 7],
  19544. [4, 7], [4, 7], [4, 7], [4, 7],
  19545. [4, 7], [4, 7], [4, 7], [4, 7],
  19546. [4, 7], [4, 7], [4, 7], [4, 7],
  19547. [4, 7], [4, 7], [4, 7], [4, 7],
  19548. [4, 7], [4, 7], [4, 7], [4, 7],
  19549. [4, 7], [4, 7], [4, 7], [4, 7]
  19550. ];
  19551. var blackTable1 = [
  19552. [-1, -1], [-1, -1], // 000000000000x
  19553. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  19554. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  19555. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  19556. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  19557. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  19558. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  19559. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  19560. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  19561. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  19562. [12, 1984], [12, 1984], // 000000010010x
  19563. [12, 2048], [12, 2048], // 000000010011x
  19564. [12, 2112], [12, 2112], // 000000010100x
  19565. [12, 2176], [12, 2176], // 000000010101x
  19566. [12, 2240], [12, 2240], // 000000010110x
  19567. [12, 2304], [12, 2304], // 000000010111x
  19568. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  19569. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  19570. [12, 2368], [12, 2368], // 000000011100x
  19571. [12, 2432], [12, 2432], // 000000011101x
  19572. [12, 2496], [12, 2496], // 000000011110x
  19573. [12, 2560], [12, 2560], // 000000011111x
  19574. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  19575. [10, 18], [10, 18], [10, 18], [10, 18],
  19576. [12, 52], [12, 52], // 000000100100x
  19577. [13, 640], // 0000001001010
  19578. [13, 704], // 0000001001011
  19579. [13, 768], // 0000001001100
  19580. [13, 832], // 0000001001101
  19581. [12, 55], [12, 55], // 000000100111x
  19582. [12, 56], [12, 56], // 000000101000x
  19583. [13, 1280], // 0000001010010
  19584. [13, 1344], // 0000001010011
  19585. [13, 1408], // 0000001010100
  19586. [13, 1472], // 0000001010101
  19587. [12, 59], [12, 59], // 000000101011x
  19588. [12, 60], [12, 60], // 000000101100x
  19589. [13, 1536], // 0000001011010
  19590. [13, 1600], // 0000001011011
  19591. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  19592. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  19593. [13, 1664], // 0000001100100
  19594. [13, 1728], // 0000001100101
  19595. [12, 320], [12, 320], // 000000110011x
  19596. [12, 384], [12, 384], // 000000110100x
  19597. [12, 448], [12, 448], // 000000110101x
  19598. [13, 512], // 0000001101100
  19599. [13, 576], // 0000001101101
  19600. [12, 53], [12, 53], // 000000110111x
  19601. [12, 54], [12, 54], // 000000111000x
  19602. [13, 896], // 0000001110010
  19603. [13, 960], // 0000001110011
  19604. [13, 1024], // 0000001110100
  19605. [13, 1088], // 0000001110101
  19606. [13, 1152], // 0000001110110
  19607. [13, 1216], // 0000001110111
  19608. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  19609. [10, 64], [10, 64], [10, 64], [10, 64]
  19610. ];
  19611. var blackTable2 = [
  19612. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  19613. [8, 13], [8, 13], [8, 13], [8, 13],
  19614. [8, 13], [8, 13], [8, 13], [8, 13],
  19615. [8, 13], [8, 13], [8, 13], [8, 13],
  19616. [11, 23], [11, 23], // 00000101000x
  19617. [12, 50], // 000001010010
  19618. [12, 51], // 000001010011
  19619. [12, 44], // 000001010100
  19620. [12, 45], // 000001010101
  19621. [12, 46], // 000001010110
  19622. [12, 47], // 000001010111
  19623. [12, 57], // 000001011000
  19624. [12, 58], // 000001011001
  19625. [12, 61], // 000001011010
  19626. [12, 256], // 000001011011
  19627. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  19628. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  19629. [12, 48], // 000001100100
  19630. [12, 49], // 000001100101
  19631. [12, 62], // 000001100110
  19632. [12, 63], // 000001100111
  19633. [12, 30], // 000001101000
  19634. [12, 31], // 000001101001
  19635. [12, 32], // 000001101010
  19636. [12, 33], // 000001101011
  19637. [12, 40], // 000001101100
  19638. [12, 41], // 000001101101
  19639. [11, 22], [11, 22], // 00000110111x
  19640. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  19641. [8, 14], [8, 14], [8, 14], [8, 14],
  19642. [8, 14], [8, 14], [8, 14], [8, 14],
  19643. [8, 14], [8, 14], [8, 14], [8, 14],
  19644. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  19645. [7, 10], [7, 10], [7, 10], [7, 10],
  19646. [7, 10], [7, 10], [7, 10], [7, 10],
  19647. [7, 10], [7, 10], [7, 10], [7, 10],
  19648. [7, 10], [7, 10], [7, 10], [7, 10],
  19649. [7, 10], [7, 10], [7, 10], [7, 10],
  19650. [7, 10], [7, 10], [7, 10], [7, 10],
  19651. [7, 10], [7, 10], [7, 10], [7, 10],
  19652. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  19653. [7, 11], [7, 11], [7, 11], [7, 11],
  19654. [7, 11], [7, 11], [7, 11], [7, 11],
  19655. [7, 11], [7, 11], [7, 11], [7, 11],
  19656. [7, 11], [7, 11], [7, 11], [7, 11],
  19657. [7, 11], [7, 11], [7, 11], [7, 11],
  19658. [7, 11], [7, 11], [7, 11], [7, 11],
  19659. [7, 11], [7, 11], [7, 11], [7, 11],
  19660. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  19661. [9, 15], [9, 15], [9, 15], [9, 15],
  19662. [12, 128], // 000011001000
  19663. [12, 192], // 000011001001
  19664. [12, 26], // 000011001010
  19665. [12, 27], // 000011001011
  19666. [12, 28], // 000011001100
  19667. [12, 29], // 000011001101
  19668. [11, 19], [11, 19], // 00001100111x
  19669. [11, 20], [11, 20], // 00001101000x
  19670. [12, 34], // 000011010010
  19671. [12, 35], // 000011010011
  19672. [12, 36], // 000011010100
  19673. [12, 37], // 000011010101
  19674. [12, 38], // 000011010110
  19675. [12, 39], // 000011010111
  19676. [11, 21], [11, 21], // 00001101100x
  19677. [12, 42], // 000011011010
  19678. [12, 43], // 000011011011
  19679. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  19680. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  19681. [7, 12], [7, 12], [7, 12], [7, 12],
  19682. [7, 12], [7, 12], [7, 12], [7, 12],
  19683. [7, 12], [7, 12], [7, 12], [7, 12],
  19684. [7, 12], [7, 12], [7, 12], [7, 12],
  19685. [7, 12], [7, 12], [7, 12], [7, 12],
  19686. [7, 12], [7, 12], [7, 12], [7, 12],
  19687. [7, 12], [7, 12], [7, 12], [7, 12]
  19688. ];
  19689. var blackTable3 = [
  19690. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  19691. [6, 9], // 000100
  19692. [6, 8], // 000101
  19693. [5, 7], [5, 7], // 00011x
  19694. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  19695. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  19696. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  19697. [3, 1], [3, 1], [3, 1], [3, 1],
  19698. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  19699. [3, 4], [3, 4], [3, 4], [3, 4],
  19700. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  19701. [2, 3], [2, 3], [2, 3], [2, 3],
  19702. [2, 3], [2, 3], [2, 3], [2, 3],
  19703. [2, 3], [2, 3], [2, 3], [2, 3],
  19704. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  19705. [2, 2], [2, 2], [2, 2], [2, 2],
  19706. [2, 2], [2, 2], [2, 2], [2, 2],
  19707. [2, 2], [2, 2], [2, 2], [2, 2]
  19708. ];
  19709. function CCITTFaxStream(str, maybeLength, params) {
  19710. this.str = str;
  19711. this.dict = str.dict;
  19712. params = params || Dict.empty;
  19713. this.encoding = params.get('K') || 0;
  19714. this.eoline = params.get('EndOfLine') || false;
  19715. this.byteAlign = params.get('EncodedByteAlign') || false;
  19716. this.columns = params.get('Columns') || 1728;
  19717. this.rows = params.get('Rows') || 0;
  19718. var eoblock = params.get('EndOfBlock');
  19719. if (eoblock === null || eoblock === undefined) {
  19720. eoblock = true;
  19721. }
  19722. this.eoblock = eoblock;
  19723. this.black = params.get('BlackIs1') || false;
  19724. this.codingLine = new Uint32Array(this.columns + 1);
  19725. this.refLine = new Uint32Array(this.columns + 2);
  19726. this.codingLine[0] = this.columns;
  19727. this.codingPos = 0;
  19728. this.row = 0;
  19729. this.nextLine2D = this.encoding < 0;
  19730. this.inputBits = 0;
  19731. this.inputBuf = 0;
  19732. this.outputBits = 0;
  19733. var code1;
  19734. while ((code1 = this.lookBits(12)) === 0) {
  19735. this.eatBits(1);
  19736. }
  19737. if (code1 === 1) {
  19738. this.eatBits(12);
  19739. }
  19740. if (this.encoding > 0) {
  19741. this.nextLine2D = !this.lookBits(1);
  19742. this.eatBits(1);
  19743. }
  19744. DecodeStream.call(this, maybeLength);
  19745. }
  19746. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  19747. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  19748. while (!this.eof) {
  19749. var c = this.lookChar();
  19750. this.ensureBuffer(this.bufferLength + 1);
  19751. this.buffer[this.bufferLength++] = c;
  19752. }
  19753. };
  19754. CCITTFaxStream.prototype.addPixels =
  19755. function ccittFaxStreamAddPixels(a1, blackPixels) {
  19756. var codingLine = this.codingLine;
  19757. var codingPos = this.codingPos;
  19758. if (a1 > codingLine[codingPos]) {
  19759. if (a1 > this.columns) {
  19760. info('row is wrong length');
  19761. this.err = true;
  19762. a1 = this.columns;
  19763. }
  19764. if ((codingPos & 1) ^ blackPixels) {
  19765. ++codingPos;
  19766. }
  19767. codingLine[codingPos] = a1;
  19768. }
  19769. this.codingPos = codingPos;
  19770. };
  19771. CCITTFaxStream.prototype.addPixelsNeg =
  19772. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  19773. var codingLine = this.codingLine;
  19774. var codingPos = this.codingPos;
  19775. if (a1 > codingLine[codingPos]) {
  19776. if (a1 > this.columns) {
  19777. info('row is wrong length');
  19778. this.err = true;
  19779. a1 = this.columns;
  19780. }
  19781. if ((codingPos & 1) ^ blackPixels) {
  19782. ++codingPos;
  19783. }
  19784. codingLine[codingPos] = a1;
  19785. } else if (a1 < codingLine[codingPos]) {
  19786. if (a1 < 0) {
  19787. info('invalid code');
  19788. this.err = true;
  19789. a1 = 0;
  19790. }
  19791. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  19792. --codingPos;
  19793. }
  19794. codingLine[codingPos] = a1;
  19795. }
  19796. this.codingPos = codingPos;
  19797. };
  19798. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  19799. var refLine = this.refLine;
  19800. var codingLine = this.codingLine;
  19801. var columns = this.columns;
  19802. var refPos, blackPixels, bits, i;
  19803. if (this.outputBits === 0) {
  19804. if (this.eof) {
  19805. return null;
  19806. }
  19807. this.err = false;
  19808. var code1, code2, code3;
  19809. if (this.nextLine2D) {
  19810. for (i = 0; codingLine[i] < columns; ++i) {
  19811. refLine[i] = codingLine[i];
  19812. }
  19813. refLine[i++] = columns;
  19814. refLine[i] = columns;
  19815. codingLine[0] = 0;
  19816. this.codingPos = 0;
  19817. refPos = 0;
  19818. blackPixels = 0;
  19819. while (codingLine[this.codingPos] < columns) {
  19820. code1 = this.getTwoDimCode();
  19821. switch (code1) {
  19822. case twoDimPass:
  19823. this.addPixels(refLine[refPos + 1], blackPixels);
  19824. if (refLine[refPos + 1] < columns) {
  19825. refPos += 2;
  19826. }
  19827. break;
  19828. case twoDimHoriz:
  19829. code1 = code2 = 0;
  19830. if (blackPixels) {
  19831. do {
  19832. code1 += (code3 = this.getBlackCode());
  19833. } while (code3 >= 64);
  19834. do {
  19835. code2 += (code3 = this.getWhiteCode());
  19836. } while (code3 >= 64);
  19837. } else {
  19838. do {
  19839. code1 += (code3 = this.getWhiteCode());
  19840. } while (code3 >= 64);
  19841. do {
  19842. code2 += (code3 = this.getBlackCode());
  19843. } while (code3 >= 64);
  19844. }
  19845. this.addPixels(codingLine[this.codingPos] +
  19846. code1, blackPixels);
  19847. if (codingLine[this.codingPos] < columns) {
  19848. this.addPixels(codingLine[this.codingPos] + code2,
  19849. blackPixels ^ 1);
  19850. }
  19851. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19852. refLine[refPos] < columns) {
  19853. refPos += 2;
  19854. }
  19855. break;
  19856. case twoDimVertR3:
  19857. this.addPixels(refLine[refPos] + 3, blackPixels);
  19858. blackPixels ^= 1;
  19859. if (codingLine[this.codingPos] < columns) {
  19860. ++refPos;
  19861. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19862. refLine[refPos] < columns) {
  19863. refPos += 2;
  19864. }
  19865. }
  19866. break;
  19867. case twoDimVertR2:
  19868. this.addPixels(refLine[refPos] + 2, blackPixels);
  19869. blackPixels ^= 1;
  19870. if (codingLine[this.codingPos] < columns) {
  19871. ++refPos;
  19872. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19873. refLine[refPos] < columns) {
  19874. refPos += 2;
  19875. }
  19876. }
  19877. break;
  19878. case twoDimVertR1:
  19879. this.addPixels(refLine[refPos] + 1, blackPixels);
  19880. blackPixels ^= 1;
  19881. if (codingLine[this.codingPos] < columns) {
  19882. ++refPos;
  19883. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19884. refLine[refPos] < columns) {
  19885. refPos += 2;
  19886. }
  19887. }
  19888. break;
  19889. case twoDimVert0:
  19890. this.addPixels(refLine[refPos], blackPixels);
  19891. blackPixels ^= 1;
  19892. if (codingLine[this.codingPos] < columns) {
  19893. ++refPos;
  19894. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19895. refLine[refPos] < columns) {
  19896. refPos += 2;
  19897. }
  19898. }
  19899. break;
  19900. case twoDimVertL3:
  19901. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  19902. blackPixels ^= 1;
  19903. if (codingLine[this.codingPos] < columns) {
  19904. if (refPos > 0) {
  19905. --refPos;
  19906. } else {
  19907. ++refPos;
  19908. }
  19909. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19910. refLine[refPos] < columns) {
  19911. refPos += 2;
  19912. }
  19913. }
  19914. break;
  19915. case twoDimVertL2:
  19916. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  19917. blackPixels ^= 1;
  19918. if (codingLine[this.codingPos] < columns) {
  19919. if (refPos > 0) {
  19920. --refPos;
  19921. } else {
  19922. ++refPos;
  19923. }
  19924. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19925. refLine[refPos] < columns) {
  19926. refPos += 2;
  19927. }
  19928. }
  19929. break;
  19930. case twoDimVertL1:
  19931. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  19932. blackPixels ^= 1;
  19933. if (codingLine[this.codingPos] < columns) {
  19934. if (refPos > 0) {
  19935. --refPos;
  19936. } else {
  19937. ++refPos;
  19938. }
  19939. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19940. refLine[refPos] < columns) {
  19941. refPos += 2;
  19942. }
  19943. }
  19944. break;
  19945. case EOF:
  19946. this.addPixels(columns, 0);
  19947. this.eof = true;
  19948. break;
  19949. default:
  19950. info('bad 2d code');
  19951. this.addPixels(columns, 0);
  19952. this.err = true;
  19953. }
  19954. }
  19955. } else {
  19956. codingLine[0] = 0;
  19957. this.codingPos = 0;
  19958. blackPixels = 0;
  19959. while (codingLine[this.codingPos] < columns) {
  19960. code1 = 0;
  19961. if (blackPixels) {
  19962. do {
  19963. code1 += (code3 = this.getBlackCode());
  19964. } while (code3 >= 64);
  19965. } else {
  19966. do {
  19967. code1 += (code3 = this.getWhiteCode());
  19968. } while (code3 >= 64);
  19969. }
  19970. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  19971. blackPixels ^= 1;
  19972. }
  19973. }
  19974. var gotEOL = false;
  19975. if (this.byteAlign) {
  19976. this.inputBits &= ~7;
  19977. }
  19978. if (!this.eoblock && this.row === this.rows - 1) {
  19979. this.eof = true;
  19980. } else {
  19981. code1 = this.lookBits(12);
  19982. if (this.eoline) {
  19983. while (code1 !== EOF && code1 !== 1) {
  19984. this.eatBits(1);
  19985. code1 = this.lookBits(12);
  19986. }
  19987. } else {
  19988. while (code1 === 0) {
  19989. this.eatBits(1);
  19990. code1 = this.lookBits(12);
  19991. }
  19992. }
  19993. if (code1 === 1) {
  19994. this.eatBits(12);
  19995. gotEOL = true;
  19996. } else if (code1 === EOF) {
  19997. this.eof = true;
  19998. }
  19999. }
  20000. if (!this.eof && this.encoding > 0) {
  20001. this.nextLine2D = !this.lookBits(1);
  20002. this.eatBits(1);
  20003. }
  20004. if (this.eoblock && gotEOL && this.byteAlign) {
  20005. code1 = this.lookBits(12);
  20006. if (code1 === 1) {
  20007. this.eatBits(12);
  20008. if (this.encoding > 0) {
  20009. this.lookBits(1);
  20010. this.eatBits(1);
  20011. }
  20012. if (this.encoding >= 0) {
  20013. for (i = 0; i < 4; ++i) {
  20014. code1 = this.lookBits(12);
  20015. if (code1 !== 1) {
  20016. info('bad rtc code: ' + code1);
  20017. }
  20018. this.eatBits(12);
  20019. if (this.encoding > 0) {
  20020. this.lookBits(1);
  20021. this.eatBits(1);
  20022. }
  20023. }
  20024. }
  20025. this.eof = true;
  20026. }
  20027. } else if (this.err && this.eoline) {
  20028. while (true) {
  20029. code1 = this.lookBits(13);
  20030. if (code1 === EOF) {
  20031. this.eof = true;
  20032. return null;
  20033. }
  20034. if ((code1 >> 1) === 1) {
  20035. break;
  20036. }
  20037. this.eatBits(1);
  20038. }
  20039. this.eatBits(12);
  20040. if (this.encoding > 0) {
  20041. this.eatBits(1);
  20042. this.nextLine2D = !(code1 & 1);
  20043. }
  20044. }
  20045. if (codingLine[0] > 0) {
  20046. this.outputBits = codingLine[this.codingPos = 0];
  20047. } else {
  20048. this.outputBits = codingLine[this.codingPos = 1];
  20049. }
  20050. this.row++;
  20051. }
  20052. var c;
  20053. if (this.outputBits >= 8) {
  20054. c = (this.codingPos & 1) ? 0 : 0xFF;
  20055. this.outputBits -= 8;
  20056. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  20057. this.codingPos++;
  20058. this.outputBits = (codingLine[this.codingPos] -
  20059. codingLine[this.codingPos - 1]);
  20060. }
  20061. } else {
  20062. bits = 8;
  20063. c = 0;
  20064. do {
  20065. if (this.outputBits > bits) {
  20066. c <<= bits;
  20067. if (!(this.codingPos & 1)) {
  20068. c |= 0xFF >> (8 - bits);
  20069. }
  20070. this.outputBits -= bits;
  20071. bits = 0;
  20072. } else {
  20073. c <<= this.outputBits;
  20074. if (!(this.codingPos & 1)) {
  20075. c |= 0xFF >> (8 - this.outputBits);
  20076. }
  20077. bits -= this.outputBits;
  20078. this.outputBits = 0;
  20079. if (codingLine[this.codingPos] < columns) {
  20080. this.codingPos++;
  20081. this.outputBits = (codingLine[this.codingPos] -
  20082. codingLine[this.codingPos - 1]);
  20083. } else if (bits > 0) {
  20084. c <<= bits;
  20085. bits = 0;
  20086. }
  20087. }
  20088. } while (bits);
  20089. }
  20090. if (this.black) {
  20091. c ^= 0xFF;
  20092. }
  20093. return c;
  20094. };
  20095. // This functions returns the code found from the table.
  20096. // The start and end parameters set the boundaries for searching the table.
  20097. // The limit parameter is optional. Function returns an array with three
  20098. // values. The first array element indicates whether a valid code is being
  20099. // returned. The second array element is the actual code. The third array
  20100. // element indicates whether EOF was reached.
  20101. CCITTFaxStream.prototype.findTableCode =
  20102. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  20103. var limitValue = limit || 0;
  20104. for (var i = start; i <= end; ++i) {
  20105. var code = this.lookBits(i);
  20106. if (code === EOF) {
  20107. return [true, 1, false];
  20108. }
  20109. if (i < end) {
  20110. code <<= end - i;
  20111. }
  20112. if (!limitValue || code >= limitValue) {
  20113. var p = table[code - limitValue];
  20114. if (p[0] === i) {
  20115. this.eatBits(i);
  20116. return [true, p[1], true];
  20117. }
  20118. }
  20119. }
  20120. return [false, 0, false];
  20121. };
  20122. CCITTFaxStream.prototype.getTwoDimCode =
  20123. function ccittFaxStreamGetTwoDimCode() {
  20124. var code = 0;
  20125. var p;
  20126. if (this.eoblock) {
  20127. code = this.lookBits(7);
  20128. p = twoDimTable[code];
  20129. if (p && p[0] > 0) {
  20130. this.eatBits(p[0]);
  20131. return p[1];
  20132. }
  20133. } else {
  20134. var result = this.findTableCode(1, 7, twoDimTable);
  20135. if (result[0] && result[2]) {
  20136. return result[1];
  20137. }
  20138. }
  20139. info('Bad two dim code');
  20140. return EOF;
  20141. };
  20142. CCITTFaxStream.prototype.getWhiteCode =
  20143. function ccittFaxStreamGetWhiteCode() {
  20144. var code = 0;
  20145. var p;
  20146. if (this.eoblock) {
  20147. code = this.lookBits(12);
  20148. if (code === EOF) {
  20149. return 1;
  20150. }
  20151. if ((code >> 5) === 0) {
  20152. p = whiteTable1[code];
  20153. } else {
  20154. p = whiteTable2[code >> 3];
  20155. }
  20156. if (p[0] > 0) {
  20157. this.eatBits(p[0]);
  20158. return p[1];
  20159. }
  20160. } else {
  20161. var result = this.findTableCode(1, 9, whiteTable2);
  20162. if (result[0]) {
  20163. return result[1];
  20164. }
  20165. result = this.findTableCode(11, 12, whiteTable1);
  20166. if (result[0]) {
  20167. return result[1];
  20168. }
  20169. }
  20170. info('bad white code');
  20171. this.eatBits(1);
  20172. return 1;
  20173. };
  20174. CCITTFaxStream.prototype.getBlackCode =
  20175. function ccittFaxStreamGetBlackCode() {
  20176. var code, p;
  20177. if (this.eoblock) {
  20178. code = this.lookBits(13);
  20179. if (code === EOF) {
  20180. return 1;
  20181. }
  20182. if ((code >> 7) === 0) {
  20183. p = blackTable1[code];
  20184. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  20185. p = blackTable2[(code >> 1) - 64];
  20186. } else {
  20187. p = blackTable3[code >> 7];
  20188. }
  20189. if (p[0] > 0) {
  20190. this.eatBits(p[0]);
  20191. return p[1];
  20192. }
  20193. } else {
  20194. var result = this.findTableCode(2, 6, blackTable3);
  20195. if (result[0]) {
  20196. return result[1];
  20197. }
  20198. result = this.findTableCode(7, 12, blackTable2, 64);
  20199. if (result[0]) {
  20200. return result[1];
  20201. }
  20202. result = this.findTableCode(10, 13, blackTable1);
  20203. if (result[0]) {
  20204. return result[1];
  20205. }
  20206. }
  20207. info('bad black code');
  20208. this.eatBits(1);
  20209. return 1;
  20210. };
  20211. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  20212. var c;
  20213. while (this.inputBits < n) {
  20214. if ((c = this.str.getByte()) === -1) {
  20215. if (this.inputBits === 0) {
  20216. return EOF;
  20217. }
  20218. return ((this.inputBuf << (n - this.inputBits)) &
  20219. (0xFFFF >> (16 - n)));
  20220. }
  20221. this.inputBuf = (this.inputBuf << 8) + c;
  20222. this.inputBits += 8;
  20223. }
  20224. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  20225. };
  20226. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  20227. if ((this.inputBits -= n) < 0) {
  20228. this.inputBits = 0;
  20229. }
  20230. };
  20231. return CCITTFaxStream;
  20232. })();
  20233. var LZWStream = (function LZWStreamClosure() {
  20234. function LZWStream(str, maybeLength, earlyChange) {
  20235. this.str = str;
  20236. this.dict = str.dict;
  20237. this.cachedData = 0;
  20238. this.bitsCached = 0;
  20239. var maxLzwDictionarySize = 4096;
  20240. var lzwState = {
  20241. earlyChange: earlyChange,
  20242. codeLength: 9,
  20243. nextCode: 258,
  20244. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  20245. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  20246. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  20247. currentSequence: new Uint8Array(maxLzwDictionarySize),
  20248. currentSequenceLength: 0
  20249. };
  20250. for (var i = 0; i < 256; ++i) {
  20251. lzwState.dictionaryValues[i] = i;
  20252. lzwState.dictionaryLengths[i] = 1;
  20253. }
  20254. this.lzwState = lzwState;
  20255. DecodeStream.call(this, maybeLength);
  20256. }
  20257. LZWStream.prototype = Object.create(DecodeStream.prototype);
  20258. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  20259. var bitsCached = this.bitsCached;
  20260. var cachedData = this.cachedData;
  20261. while (bitsCached < n) {
  20262. var c = this.str.getByte();
  20263. if (c === -1) {
  20264. this.eof = true;
  20265. return null;
  20266. }
  20267. cachedData = (cachedData << 8) | c;
  20268. bitsCached += 8;
  20269. }
  20270. this.bitsCached = (bitsCached -= n);
  20271. this.cachedData = cachedData;
  20272. this.lastCode = null;
  20273. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  20274. };
  20275. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  20276. var blockSize = 512;
  20277. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  20278. var i, j, q;
  20279. var lzwState = this.lzwState;
  20280. if (!lzwState) {
  20281. return; // eof was found
  20282. }
  20283. var earlyChange = lzwState.earlyChange;
  20284. var nextCode = lzwState.nextCode;
  20285. var dictionaryValues = lzwState.dictionaryValues;
  20286. var dictionaryLengths = lzwState.dictionaryLengths;
  20287. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  20288. var codeLength = lzwState.codeLength;
  20289. var prevCode = lzwState.prevCode;
  20290. var currentSequence = lzwState.currentSequence;
  20291. var currentSequenceLength = lzwState.currentSequenceLength;
  20292. var decodedLength = 0;
  20293. var currentBufferLength = this.bufferLength;
  20294. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  20295. for (i = 0; i < blockSize; i++) {
  20296. var code = this.readBits(codeLength);
  20297. var hasPrev = currentSequenceLength > 0;
  20298. if (code < 256) {
  20299. currentSequence[0] = code;
  20300. currentSequenceLength = 1;
  20301. } else if (code >= 258) {
  20302. if (code < nextCode) {
  20303. currentSequenceLength = dictionaryLengths[code];
  20304. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  20305. currentSequence[j] = dictionaryValues[q];
  20306. q = dictionaryPrevCodes[q];
  20307. }
  20308. } else {
  20309. currentSequence[currentSequenceLength++] = currentSequence[0];
  20310. }
  20311. } else if (code === 256) {
  20312. codeLength = 9;
  20313. nextCode = 258;
  20314. currentSequenceLength = 0;
  20315. continue;
  20316. } else {
  20317. this.eof = true;
  20318. delete this.lzwState;
  20319. break;
  20320. }
  20321. if (hasPrev) {
  20322. dictionaryPrevCodes[nextCode] = prevCode;
  20323. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  20324. dictionaryValues[nextCode] = currentSequence[0];
  20325. nextCode++;
  20326. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  20327. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  20328. 0.6931471805599453 + 1, 12) | 0;
  20329. }
  20330. prevCode = code;
  20331. decodedLength += currentSequenceLength;
  20332. if (estimatedDecodedSize < decodedLength) {
  20333. do {
  20334. estimatedDecodedSize += decodedSizeDelta;
  20335. } while (estimatedDecodedSize < decodedLength);
  20336. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  20337. }
  20338. for (j = 0; j < currentSequenceLength; j++) {
  20339. buffer[currentBufferLength++] = currentSequence[j];
  20340. }
  20341. }
  20342. lzwState.nextCode = nextCode;
  20343. lzwState.codeLength = codeLength;
  20344. lzwState.prevCode = prevCode;
  20345. lzwState.currentSequenceLength = currentSequenceLength;
  20346. this.bufferLength = currentBufferLength;
  20347. };
  20348. return LZWStream;
  20349. })();
  20350. var NullStream = (function NullStreamClosure() {
  20351. function NullStream() {
  20352. Stream.call(this, new Uint8Array(0));
  20353. }
  20354. NullStream.prototype = Stream.prototype;
  20355. return NullStream;
  20356. })();
  20357. // TODO refactor to remove dependency on parser.js
  20358. function _setCoreParser(coreParser_) {
  20359. coreParser = coreParser_;
  20360. EOF = coreParser_.EOF;
  20361. Lexer = coreParser_.Lexer;
  20362. }
  20363. exports._setCoreParser = _setCoreParser;
  20364. // TODO refactor to remove dependency on colorspace.js
  20365. function _setCoreColorSpace(coreColorSpace_) {
  20366. coreColorSpace = coreColorSpace_;
  20367. ColorSpace = coreColorSpace_.ColorSpace;
  20368. }
  20369. exports._setCoreColorSpace = _setCoreColorSpace;
  20370. exports.Ascii85Stream = Ascii85Stream;
  20371. exports.AsciiHexStream = AsciiHexStream;
  20372. exports.CCITTFaxStream = CCITTFaxStream;
  20373. exports.DecryptStream = DecryptStream;
  20374. exports.DecodeStream = DecodeStream;
  20375. exports.FlateStream = FlateStream;
  20376. exports.Jbig2Stream = Jbig2Stream;
  20377. exports.JpegStream = JpegStream;
  20378. exports.JpxStream = JpxStream;
  20379. exports.NullStream = NullStream;
  20380. exports.PredictorStream = PredictorStream;
  20381. exports.RunLengthStream = RunLengthStream;
  20382. exports.Stream = Stream;
  20383. exports.StreamsSequenceStream = StreamsSequenceStream;
  20384. exports.StringStream = StringStream;
  20385. exports.LZWStream = LZWStream;
  20386. }));
  20387. (function (root, factory) {
  20388. {
  20389. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  20390. root.pdfjsDisplayWebGL);
  20391. }
  20392. }(this, function (exports, sharedUtil, displayWebGL) {
  20393. var Util = sharedUtil.Util;
  20394. var info = sharedUtil.info;
  20395. var isArray = sharedUtil.isArray;
  20396. var error = sharedUtil.error;
  20397. var WebGLUtils = displayWebGL.WebGLUtils;
  20398. var ShadingIRs = {};
  20399. ShadingIRs.RadialAxial = {
  20400. fromIR: function RadialAxial_fromIR(raw) {
  20401. var type = raw[1];
  20402. var colorStops = raw[2];
  20403. var p0 = raw[3];
  20404. var p1 = raw[4];
  20405. var r0 = raw[5];
  20406. var r1 = raw[6];
  20407. return {
  20408. type: 'Pattern',
  20409. getPattern: function RadialAxial_getPattern(ctx) {
  20410. var grad;
  20411. if (type === 'axial') {
  20412. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  20413. } else if (type === 'radial') {
  20414. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  20415. }
  20416. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  20417. var c = colorStops[i];
  20418. grad.addColorStop(c[0], c[1]);
  20419. }
  20420. return grad;
  20421. }
  20422. };
  20423. }
  20424. };
  20425. var createMeshCanvas = (function createMeshCanvasClosure() {
  20426. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  20427. // Very basic Gouraud-shaded triangle rasterization algorithm.
  20428. var coords = context.coords, colors = context.colors;
  20429. var bytes = data.data, rowSize = data.width * 4;
  20430. var tmp;
  20431. if (coords[p1 + 1] > coords[p2 + 1]) {
  20432. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  20433. }
  20434. if (coords[p2 + 1] > coords[p3 + 1]) {
  20435. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  20436. }
  20437. if (coords[p1 + 1] > coords[p2 + 1]) {
  20438. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  20439. }
  20440. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  20441. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  20442. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  20443. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  20444. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  20445. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  20446. if (y1 >= y3) {
  20447. return;
  20448. }
  20449. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  20450. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  20451. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  20452. var minY = Math.round(y1), maxY = Math.round(y3);
  20453. var xa, car, cag, cab;
  20454. var xb, cbr, cbg, cbb;
  20455. var k;
  20456. for (var y = minY; y <= maxY; y++) {
  20457. if (y < y2) {
  20458. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  20459. xa = x1 - (x1 - x2) * k;
  20460. car = c1r - (c1r - c2r) * k;
  20461. cag = c1g - (c1g - c2g) * k;
  20462. cab = c1b - (c1b - c2b) * k;
  20463. } else {
  20464. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  20465. xa = x2 - (x2 - x3) * k;
  20466. car = c2r - (c2r - c3r) * k;
  20467. cag = c2g - (c2g - c3g) * k;
  20468. cab = c2b - (c2b - c3b) * k;
  20469. }
  20470. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  20471. xb = x1 - (x1 - x3) * k;
  20472. cbr = c1r - (c1r - c3r) * k;
  20473. cbg = c1g - (c1g - c3g) * k;
  20474. cbb = c1b - (c1b - c3b) * k;
  20475. var x1_ = Math.round(Math.min(xa, xb));
  20476. var x2_ = Math.round(Math.max(xa, xb));
  20477. var j = rowSize * y + x1_ * 4;
  20478. for (var x = x1_; x <= x2_; x++) {
  20479. k = (xa - x) / (xa - xb);
  20480. k = k < 0 ? 0 : k > 1 ? 1 : k;
  20481. bytes[j++] = (car - (car - cbr) * k) | 0;
  20482. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  20483. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  20484. bytes[j++] = 255;
  20485. }
  20486. }
  20487. }
  20488. function drawFigure(data, figure, context) {
  20489. var ps = figure.coords;
  20490. var cs = figure.colors;
  20491. var i, ii;
  20492. switch (figure.type) {
  20493. case 'lattice':
  20494. var verticesPerRow = figure.verticesPerRow;
  20495. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  20496. var cols = verticesPerRow - 1;
  20497. for (i = 0; i < rows; i++) {
  20498. var q = i * verticesPerRow;
  20499. for (var j = 0; j < cols; j++, q++) {
  20500. drawTriangle(data, context,
  20501. ps[q], ps[q + 1], ps[q + verticesPerRow],
  20502. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  20503. drawTriangle(data, context,
  20504. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  20505. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  20506. }
  20507. }
  20508. break;
  20509. case 'triangles':
  20510. for (i = 0, ii = ps.length; i < ii; i += 3) {
  20511. drawTriangle(data, context,
  20512. ps[i], ps[i + 1], ps[i + 2],
  20513. cs[i], cs[i + 1], cs[i + 2]);
  20514. }
  20515. break;
  20516. default:
  20517. error('illigal figure');
  20518. break;
  20519. }
  20520. }
  20521. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  20522. backgroundColor, cachedCanvases) {
  20523. // we will increase scale on some weird factor to let antialiasing take
  20524. // care of "rough" edges
  20525. var EXPECTED_SCALE = 1.1;
  20526. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  20527. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  20528. var offsetX = Math.floor(bounds[0]);
  20529. var offsetY = Math.floor(bounds[1]);
  20530. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  20531. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  20532. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  20533. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  20534. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  20535. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  20536. var scaleX = boundsWidth / width;
  20537. var scaleY = boundsHeight / height;
  20538. var context = {
  20539. coords: coords,
  20540. colors: colors,
  20541. offsetX: -offsetX,
  20542. offsetY: -offsetY,
  20543. scaleX: 1 / scaleX,
  20544. scaleY: 1 / scaleY
  20545. };
  20546. var canvas, tmpCanvas, i, ii;
  20547. if (WebGLUtils.isEnabled) {
  20548. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  20549. figures, context);
  20550. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  20551. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  20552. tmpCanvas.context.drawImage(canvas, 0, 0);
  20553. canvas = tmpCanvas.canvas;
  20554. } else {
  20555. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  20556. var tmpCtx = tmpCanvas.context;
  20557. var data = tmpCtx.createImageData(width, height);
  20558. if (backgroundColor) {
  20559. var bytes = data.data;
  20560. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  20561. bytes[i] = backgroundColor[0];
  20562. bytes[i + 1] = backgroundColor[1];
  20563. bytes[i + 2] = backgroundColor[2];
  20564. bytes[i + 3] = 255;
  20565. }
  20566. }
  20567. for (i = 0; i < figures.length; i++) {
  20568. drawFigure(data, figures[i], context);
  20569. }
  20570. tmpCtx.putImageData(data, 0, 0);
  20571. canvas = tmpCanvas.canvas;
  20572. }
  20573. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  20574. scaleX: scaleX, scaleY: scaleY};
  20575. }
  20576. return createMeshCanvas;
  20577. })();
  20578. ShadingIRs.Mesh = {
  20579. fromIR: function Mesh_fromIR(raw) {
  20580. //var type = raw[1];
  20581. var coords = raw[2];
  20582. var colors = raw[3];
  20583. var figures = raw[4];
  20584. var bounds = raw[5];
  20585. var matrix = raw[6];
  20586. //var bbox = raw[7];
  20587. var background = raw[8];
  20588. return {
  20589. type: 'Pattern',
  20590. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  20591. var scale;
  20592. if (shadingFill) {
  20593. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  20594. } else {
  20595. // Obtain scale from matrix and current transformation matrix.
  20596. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  20597. if (matrix) {
  20598. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  20599. scale = [scale[0] * matrixScale[0],
  20600. scale[1] * matrixScale[1]];
  20601. }
  20602. }
  20603. // Rasterizing on the main thread since sending/queue large canvases
  20604. // might cause OOM.
  20605. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  20606. colors, figures, shadingFill ? null : background,
  20607. owner.cachedCanvases);
  20608. if (!shadingFill) {
  20609. ctx.setTransform.apply(ctx, owner.baseTransform);
  20610. if (matrix) {
  20611. ctx.transform.apply(ctx, matrix);
  20612. }
  20613. }
  20614. ctx.translate(temporaryPatternCanvas.offsetX,
  20615. temporaryPatternCanvas.offsetY);
  20616. ctx.scale(temporaryPatternCanvas.scaleX,
  20617. temporaryPatternCanvas.scaleY);
  20618. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  20619. }
  20620. };
  20621. }
  20622. };
  20623. ShadingIRs.Dummy = {
  20624. fromIR: function Dummy_fromIR() {
  20625. return {
  20626. type: 'Pattern',
  20627. getPattern: function Dummy_fromIR_getPattern() {
  20628. return 'hotpink';
  20629. }
  20630. };
  20631. }
  20632. };
  20633. function getShadingPatternFromIR(raw) {
  20634. var shadingIR = ShadingIRs[raw[0]];
  20635. if (!shadingIR) {
  20636. error('Unknown IR type: ' + raw[0]);
  20637. }
  20638. return shadingIR.fromIR(raw);
  20639. }
  20640. var TilingPattern = (function TilingPatternClosure() {
  20641. var PaintType = {
  20642. COLORED: 1,
  20643. UNCOLORED: 2
  20644. };
  20645. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  20646. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  20647. this.operatorList = IR[2];
  20648. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  20649. this.bbox = IR[4];
  20650. this.xstep = IR[5];
  20651. this.ystep = IR[6];
  20652. this.paintType = IR[7];
  20653. this.tilingType = IR[8];
  20654. this.color = color;
  20655. this.canvasGraphicsFactory = canvasGraphicsFactory;
  20656. this.baseTransform = baseTransform;
  20657. this.type = 'Pattern';
  20658. this.ctx = ctx;
  20659. }
  20660. TilingPattern.prototype = {
  20661. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  20662. var operatorList = this.operatorList;
  20663. var bbox = this.bbox;
  20664. var xstep = this.xstep;
  20665. var ystep = this.ystep;
  20666. var paintType = this.paintType;
  20667. var tilingType = this.tilingType;
  20668. var color = this.color;
  20669. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  20670. info('TilingType: ' + tilingType);
  20671. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  20672. var topLeft = [x0, y0];
  20673. // we want the canvas to be as large as the step size
  20674. var botRight = [x0 + xstep, y0 + ystep];
  20675. var width = botRight[0] - topLeft[0];
  20676. var height = botRight[1] - topLeft[1];
  20677. // Obtain scale from matrix and current transformation matrix.
  20678. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  20679. var curMatrixScale = Util.singularValueDecompose2dScale(
  20680. this.baseTransform);
  20681. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  20682. matrixScale[1] * curMatrixScale[1]];
  20683. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  20684. // Use width and height values that are as close as possible to the end
  20685. // result when the pattern is used. Too low value makes the pattern look
  20686. // blurry. Too large value makes it look too crispy.
  20687. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  20688. MAX_PATTERN_SIZE);
  20689. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  20690. MAX_PATTERN_SIZE);
  20691. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  20692. width, height, true);
  20693. var tmpCtx = tmpCanvas.context;
  20694. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  20695. graphics.groupLevel = owner.groupLevel;
  20696. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  20697. this.setScale(width, height, xstep, ystep);
  20698. this.transformToScale(graphics);
  20699. // transform coordinates to pattern space
  20700. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  20701. graphics.transform.apply(graphics, tmpTranslate);
  20702. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  20703. graphics.executeOperatorList(operatorList);
  20704. return tmpCanvas.canvas;
  20705. },
  20706. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  20707. this.scale = [width / xstep, height / ystep];
  20708. },
  20709. transformToScale: function TilingPattern_transformToScale(graphics) {
  20710. var scale = this.scale;
  20711. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  20712. graphics.transform.apply(graphics, tmpScale);
  20713. },
  20714. scaleToContext: function TilingPattern_scaleToContext() {
  20715. var scale = this.scale;
  20716. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  20717. },
  20718. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  20719. if (bbox && isArray(bbox) && bbox.length === 4) {
  20720. var bboxWidth = x1 - x0;
  20721. var bboxHeight = y1 - y0;
  20722. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  20723. graphics.clip();
  20724. graphics.endPath();
  20725. }
  20726. },
  20727. setFillAndStrokeStyleToContext:
  20728. function setFillAndStrokeStyleToContext(context, paintType, color) {
  20729. switch (paintType) {
  20730. case PaintType.COLORED:
  20731. var ctx = this.ctx;
  20732. context.fillStyle = ctx.fillStyle;
  20733. context.strokeStyle = ctx.strokeStyle;
  20734. break;
  20735. case PaintType.UNCOLORED:
  20736. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  20737. context.fillStyle = cssColor;
  20738. context.strokeStyle = cssColor;
  20739. break;
  20740. default:
  20741. error('Unsupported paint type: ' + paintType);
  20742. }
  20743. },
  20744. getPattern: function TilingPattern_getPattern(ctx, owner) {
  20745. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  20746. ctx = this.ctx;
  20747. ctx.setTransform.apply(ctx, this.baseTransform);
  20748. ctx.transform.apply(ctx, this.matrix);
  20749. this.scaleToContext();
  20750. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  20751. }
  20752. };
  20753. return TilingPattern;
  20754. })();
  20755. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  20756. exports.TilingPattern = TilingPattern;
  20757. }));
  20758. (function (root, factory) {
  20759. {
  20760. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  20761. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  20762. }
  20763. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  20764. var PasswordException = sharedUtil.PasswordException;
  20765. var PasswordResponses = sharedUtil.PasswordResponses;
  20766. var bytesToString = sharedUtil.bytesToString;
  20767. var error = sharedUtil.error;
  20768. var isInt = sharedUtil.isInt;
  20769. var stringToBytes = sharedUtil.stringToBytes;
  20770. var utf8StringToString = sharedUtil.utf8StringToString;
  20771. var warn = sharedUtil.warn;
  20772. var Name = corePrimitives.Name;
  20773. var isName = corePrimitives.isName;
  20774. var isDict = corePrimitives.isDict;
  20775. var DecryptStream = coreStream.DecryptStream;
  20776. var ARCFourCipher = (function ARCFourCipherClosure() {
  20777. function ARCFourCipher(key) {
  20778. this.a = 0;
  20779. this.b = 0;
  20780. var s = new Uint8Array(256);
  20781. var i, j = 0, tmp, keyLength = key.length;
  20782. for (i = 0; i < 256; ++i) {
  20783. s[i] = i;
  20784. }
  20785. for (i = 0; i < 256; ++i) {
  20786. tmp = s[i];
  20787. j = (j + tmp + key[i % keyLength]) & 0xFF;
  20788. s[i] = s[j];
  20789. s[j] = tmp;
  20790. }
  20791. this.s = s;
  20792. }
  20793. ARCFourCipher.prototype = {
  20794. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  20795. var i, n = data.length, tmp, tmp2;
  20796. var a = this.a, b = this.b, s = this.s;
  20797. var output = new Uint8Array(n);
  20798. for (i = 0; i < n; ++i) {
  20799. a = (a + 1) & 0xFF;
  20800. tmp = s[a];
  20801. b = (b + tmp) & 0xFF;
  20802. tmp2 = s[b];
  20803. s[a] = tmp2;
  20804. s[b] = tmp;
  20805. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  20806. }
  20807. this.a = a;
  20808. this.b = b;
  20809. return output;
  20810. }
  20811. };
  20812. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  20813. return ARCFourCipher;
  20814. })();
  20815. var calculateMD5 = (function calculateMD5Closure() {
  20816. var r = new Uint8Array([
  20817. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  20818. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  20819. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  20820. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  20821. var k = new Int32Array([
  20822. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  20823. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  20824. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  20825. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  20826. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  20827. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  20828. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  20829. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  20830. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  20831. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  20832. -145523070, -1120210379, 718787259, -343485551]);
  20833. function hash(data, offset, length) {
  20834. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  20835. // pre-processing
  20836. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  20837. var padded = new Uint8Array(paddedLength);
  20838. var i, j, n;
  20839. for (i = 0; i < length; ++i) {
  20840. padded[i] = data[offset++];
  20841. }
  20842. padded[i++] = 0x80;
  20843. n = paddedLength - 8;
  20844. while (i < n) {
  20845. padded[i++] = 0;
  20846. }
  20847. padded[i++] = (length << 3) & 0xFF;
  20848. padded[i++] = (length >> 5) & 0xFF;
  20849. padded[i++] = (length >> 13) & 0xFF;
  20850. padded[i++] = (length >> 21) & 0xFF;
  20851. padded[i++] = (length >>> 29) & 0xFF;
  20852. padded[i++] = 0;
  20853. padded[i++] = 0;
  20854. padded[i++] = 0;
  20855. var w = new Int32Array(16);
  20856. for (i = 0; i < paddedLength;) {
  20857. for (j = 0; j < 16; ++j, i += 4) {
  20858. w[j] = (padded[i] | (padded[i + 1] << 8) |
  20859. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  20860. }
  20861. var a = h0, b = h1, c = h2, d = h3, f, g;
  20862. for (j = 0; j < 64; ++j) {
  20863. if (j < 16) {
  20864. f = (b & c) | ((~b) & d);
  20865. g = j;
  20866. } else if (j < 32) {
  20867. f = (d & b) | ((~d) & c);
  20868. g = (5 * j + 1) & 15;
  20869. } else if (j < 48) {
  20870. f = b ^ c ^ d;
  20871. g = (3 * j + 5) & 15;
  20872. } else {
  20873. f = c ^ (b | (~d));
  20874. g = (7 * j) & 15;
  20875. }
  20876. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  20877. d = c;
  20878. c = b;
  20879. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  20880. a = tmp;
  20881. }
  20882. h0 = (h0 + a) | 0;
  20883. h1 = (h1 + b) | 0;
  20884. h2 = (h2 + c) | 0;
  20885. h3 = (h3 + d) | 0;
  20886. }
  20887. return new Uint8Array([
  20888. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  20889. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  20890. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  20891. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  20892. ]);
  20893. }
  20894. return hash;
  20895. })();
  20896. var Word64 = (function Word64Closure() {
  20897. function Word64(highInteger, lowInteger) {
  20898. this.high = highInteger | 0;
  20899. this.low = lowInteger | 0;
  20900. }
  20901. Word64.prototype = {
  20902. and: function Word64_and(word) {
  20903. this.high &= word.high;
  20904. this.low &= word.low;
  20905. },
  20906. xor: function Word64_xor(word) {
  20907. this.high ^= word.high;
  20908. this.low ^= word.low;
  20909. },
  20910. or: function Word64_or(word) {
  20911. this.high |= word.high;
  20912. this.low |= word.low;
  20913. },
  20914. shiftRight: function Word64_shiftRight(places) {
  20915. if (places >= 32) {
  20916. this.low = (this.high >>> (places - 32)) | 0;
  20917. this.high = 0;
  20918. } else {
  20919. this.low = (this.low >>> places) | (this.high << (32 - places));
  20920. this.high = (this.high >>> places) | 0;
  20921. }
  20922. },
  20923. shiftLeft: function Word64_shiftLeft(places) {
  20924. if (places >= 32) {
  20925. this.high = this.low << (places - 32);
  20926. this.low = 0;
  20927. } else {
  20928. this.high = (this.high << places) | (this.low >>> (32 - places));
  20929. this.low = this.low << places;
  20930. }
  20931. },
  20932. rotateRight: function Word64_rotateRight(places) {
  20933. var low, high;
  20934. if (places & 32) {
  20935. high = this.low;
  20936. low = this.high;
  20937. } else {
  20938. low = this.low;
  20939. high = this.high;
  20940. }
  20941. places &= 31;
  20942. this.low = (low >>> places) | (high << (32 - places));
  20943. this.high = (high >>> places) | (low << (32 - places));
  20944. },
  20945. not: function Word64_not() {
  20946. this.high = ~this.high;
  20947. this.low = ~this.low;
  20948. },
  20949. add: function Word64_add(word) {
  20950. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  20951. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  20952. if (lowAdd > 0xFFFFFFFF) {
  20953. highAdd += 1;
  20954. }
  20955. this.low = lowAdd | 0;
  20956. this.high = highAdd | 0;
  20957. },
  20958. copyTo: function Word64_copyTo(bytes, offset) {
  20959. bytes[offset] = (this.high >>> 24) & 0xFF;
  20960. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  20961. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  20962. bytes[offset + 3] = this.high & 0xFF;
  20963. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  20964. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  20965. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  20966. bytes[offset + 7] = this.low & 0xFF;
  20967. },
  20968. assign: function Word64_assign(word) {
  20969. this.high = word.high;
  20970. this.low = word.low;
  20971. }
  20972. };
  20973. return Word64;
  20974. })();
  20975. var calculateSHA256 = (function calculateSHA256Closure() {
  20976. function rotr(x, n) {
  20977. return (x >>> n) | (x << 32 - n);
  20978. }
  20979. function ch(x, y, z) {
  20980. return (x & y) ^ (~x & z);
  20981. }
  20982. function maj(x, y, z) {
  20983. return (x & y) ^ (x & z) ^ (y & z);
  20984. }
  20985. function sigma(x) {
  20986. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  20987. }
  20988. function sigmaPrime(x) {
  20989. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  20990. }
  20991. function littleSigma(x) {
  20992. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  20993. }
  20994. function littleSigmaPrime(x) {
  20995. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  20996. }
  20997. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  20998. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  20999. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  21000. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  21001. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  21002. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  21003. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  21004. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  21005. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  21006. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  21007. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  21008. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  21009. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  21010. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  21011. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  21012. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  21013. function hash(data, offset, length) {
  21014. // initial hash values
  21015. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  21016. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  21017. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  21018. // pre-processing
  21019. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  21020. var padded = new Uint8Array(paddedLength);
  21021. var i, j, n;
  21022. for (i = 0; i < length; ++i) {
  21023. padded[i] = data[offset++];
  21024. }
  21025. padded[i++] = 0x80;
  21026. n = paddedLength - 8;
  21027. while (i < n) {
  21028. padded[i++] = 0;
  21029. }
  21030. padded[i++] = 0;
  21031. padded[i++] = 0;
  21032. padded[i++] = 0;
  21033. padded[i++] = (length >>> 29) & 0xFF;
  21034. padded[i++] = (length >> 21) & 0xFF;
  21035. padded[i++] = (length >> 13) & 0xFF;
  21036. padded[i++] = (length >> 5) & 0xFF;
  21037. padded[i++] = (length << 3) & 0xFF;
  21038. var w = new Uint32Array(64);
  21039. // for each 512 bit block
  21040. for (i = 0; i < paddedLength;) {
  21041. for (j = 0; j < 16; ++j) {
  21042. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  21043. (padded[i + 2] << 8) | (padded[i + 3]));
  21044. i += 4;
  21045. }
  21046. for (j = 16; j < 64; ++j) {
  21047. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  21048. littleSigma(w[j - 15]) + w[j - 16] | 0;
  21049. }
  21050. var a = h0, b = h1, c = h2, d = h3, e = h4,
  21051. f = h5, g = h6, h = h7, t1, t2;
  21052. for (j = 0; j < 64; ++j) {
  21053. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  21054. t2 = sigma(a) + maj(a, b, c);
  21055. h = g;
  21056. g = f;
  21057. f = e;
  21058. e = (d + t1) | 0;
  21059. d = c;
  21060. c = b;
  21061. b = a;
  21062. a = (t1 + t2) | 0;
  21063. }
  21064. h0 = (h0 + a) | 0;
  21065. h1 = (h1 + b) | 0;
  21066. h2 = (h2 + c) | 0;
  21067. h3 = (h3 + d) | 0;
  21068. h4 = (h4 + e) | 0;
  21069. h5 = (h5 + f) | 0;
  21070. h6 = (h6 + g) | 0;
  21071. h7 = (h7 + h) | 0;
  21072. }
  21073. return new Uint8Array([
  21074. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  21075. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  21076. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  21077. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  21078. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  21079. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  21080. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  21081. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  21082. ]);
  21083. }
  21084. return hash;
  21085. })();
  21086. var calculateSHA512 = (function calculateSHA512Closure() {
  21087. function ch(result, x, y, z, tmp) {
  21088. result.assign(x);
  21089. result.and(y);
  21090. tmp.assign(x);
  21091. tmp.not();
  21092. tmp.and(z);
  21093. result.xor(tmp);
  21094. }
  21095. function maj(result, x, y, z, tmp) {
  21096. result.assign(x);
  21097. result.and(y);
  21098. tmp.assign(x);
  21099. tmp.and(z);
  21100. result.xor(tmp);
  21101. tmp.assign(y);
  21102. tmp.and(z);
  21103. result.xor(tmp);
  21104. }
  21105. function sigma(result, x, tmp) {
  21106. result.assign(x);
  21107. result.rotateRight(28);
  21108. tmp.assign(x);
  21109. tmp.rotateRight(34);
  21110. result.xor(tmp);
  21111. tmp.assign(x);
  21112. tmp.rotateRight(39);
  21113. result.xor(tmp);
  21114. }
  21115. function sigmaPrime(result, x, tmp) {
  21116. result.assign(x);
  21117. result.rotateRight(14);
  21118. tmp.assign(x);
  21119. tmp.rotateRight(18);
  21120. result.xor(tmp);
  21121. tmp.assign(x);
  21122. tmp.rotateRight(41);
  21123. result.xor(tmp);
  21124. }
  21125. function littleSigma(result, x, tmp) {
  21126. result.assign(x);
  21127. result.rotateRight(1);
  21128. tmp.assign(x);
  21129. tmp.rotateRight(8);
  21130. result.xor(tmp);
  21131. tmp.assign(x);
  21132. tmp.shiftRight(7);
  21133. result.xor(tmp);
  21134. }
  21135. function littleSigmaPrime(result, x, tmp) {
  21136. result.assign(x);
  21137. result.rotateRight(19);
  21138. tmp.assign(x);
  21139. tmp.rotateRight(61);
  21140. result.xor(tmp);
  21141. tmp.assign(x);
  21142. tmp.shiftRight(6);
  21143. result.xor(tmp);
  21144. }
  21145. var k = [
  21146. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  21147. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  21148. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  21149. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  21150. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  21151. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  21152. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  21153. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  21154. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  21155. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  21156. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  21157. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  21158. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  21159. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  21160. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  21161. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  21162. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  21163. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  21164. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  21165. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  21166. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  21167. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  21168. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  21169. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  21170. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  21171. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  21172. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  21173. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  21174. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  21175. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  21176. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  21177. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  21178. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  21179. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  21180. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  21181. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  21182. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  21183. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  21184. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  21185. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  21186. function hash(data, offset, length, mode384) {
  21187. mode384 = !!mode384;
  21188. // initial hash values
  21189. var h0, h1, h2, h3, h4, h5, h6, h7;
  21190. if (!mode384) {
  21191. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  21192. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  21193. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  21194. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  21195. h4 = new Word64(0x510e527f, 0xade682d1);
  21196. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  21197. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  21198. h7 = new Word64(0x5be0cd19, 0x137e2179);
  21199. }
  21200. else {
  21201. // SHA384 is exactly the same
  21202. // except with different starting values and a trimmed result
  21203. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  21204. h1 = new Word64(0x629a292a, 0x367cd507);
  21205. h2 = new Word64(0x9159015a, 0x3070dd17);
  21206. h3 = new Word64(0x152fecd8, 0xf70e5939);
  21207. h4 = new Word64(0x67332667, 0xffc00b31);
  21208. h5 = new Word64(0x8eb44a87, 0x68581511);
  21209. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  21210. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  21211. }
  21212. // pre-processing
  21213. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  21214. var padded = new Uint8Array(paddedLength);
  21215. var i, j, n;
  21216. for (i = 0; i < length; ++i) {
  21217. padded[i] = data[offset++];
  21218. }
  21219. padded[i++] = 0x80;
  21220. n = paddedLength - 16;
  21221. while (i < n) {
  21222. padded[i++] = 0;
  21223. }
  21224. padded[i++] = 0;
  21225. padded[i++] = 0;
  21226. padded[i++] = 0;
  21227. padded[i++] = 0;
  21228. padded[i++] = 0;
  21229. padded[i++] = 0;
  21230. padded[i++] = 0;
  21231. padded[i++] = 0;
  21232. padded[i++] = 0;
  21233. padded[i++] = 0;
  21234. padded[i++] = 0;
  21235. padded[i++] = (length >>> 29) & 0xFF;
  21236. padded[i++] = (length >> 21) & 0xFF;
  21237. padded[i++] = (length >> 13) & 0xFF;
  21238. padded[i++] = (length >> 5) & 0xFF;
  21239. padded[i++] = (length << 3) & 0xFF;
  21240. var w = new Array(80);
  21241. for (i = 0; i < 80; i++) {
  21242. w[i] = new Word64(0, 0);
  21243. }
  21244. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  21245. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  21246. var g = new Word64(0, 0), h = new Word64(0, 0);
  21247. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  21248. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  21249. // for each 1024 bit block
  21250. for (i = 0; i < paddedLength;) {
  21251. for (j = 0; j < 16; ++j) {
  21252. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  21253. (padded[i + 2] << 8) | (padded[i + 3]);
  21254. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  21255. (padded[i + 6]) << 8 | (padded[i + 7]);
  21256. i += 8;
  21257. }
  21258. for (j = 16; j < 80; ++j) {
  21259. tmp3 = w[j];
  21260. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  21261. tmp3.add(w[j - 7]);
  21262. littleSigma(tmp1, w[j - 15], tmp2);
  21263. tmp3.add(tmp1);
  21264. tmp3.add(w[j - 16]);
  21265. }
  21266. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  21267. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  21268. for (j = 0; j < 80; ++j) {
  21269. t1.assign(h);
  21270. sigmaPrime(tmp1, e, tmp2);
  21271. t1.add(tmp1);
  21272. ch(tmp1, e, f, g, tmp2);
  21273. t1.add(tmp1);
  21274. t1.add(k[j]);
  21275. t1.add(w[j]);
  21276. sigma(t2, a, tmp2);
  21277. maj(tmp1, a, b, c, tmp2);
  21278. t2.add(tmp1);
  21279. tmp3 = h;
  21280. h = g;
  21281. g = f;
  21282. f = e;
  21283. d.add(t1);
  21284. e = d;
  21285. d = c;
  21286. c = b;
  21287. b = a;
  21288. tmp3.assign(t1);
  21289. tmp3.add(t2);
  21290. a = tmp3;
  21291. }
  21292. h0.add(a);
  21293. h1.add(b);
  21294. h2.add(c);
  21295. h3.add(d);
  21296. h4.add(e);
  21297. h5.add(f);
  21298. h6.add(g);
  21299. h7.add(h);
  21300. }
  21301. var result;
  21302. if (!mode384) {
  21303. result = new Uint8Array(64);
  21304. h0.copyTo(result,0);
  21305. h1.copyTo(result,8);
  21306. h2.copyTo(result,16);
  21307. h3.copyTo(result,24);
  21308. h4.copyTo(result,32);
  21309. h5.copyTo(result,40);
  21310. h6.copyTo(result,48);
  21311. h7.copyTo(result,56);
  21312. }
  21313. else {
  21314. result = new Uint8Array(48);
  21315. h0.copyTo(result,0);
  21316. h1.copyTo(result,8);
  21317. h2.copyTo(result,16);
  21318. h3.copyTo(result,24);
  21319. h4.copyTo(result,32);
  21320. h5.copyTo(result,40);
  21321. }
  21322. return result;
  21323. }
  21324. return hash;
  21325. })();
  21326. var calculateSHA384 = (function calculateSHA384Closure() {
  21327. function hash(data, offset, length) {
  21328. return calculateSHA512(data, offset, length, true);
  21329. }
  21330. return hash;
  21331. })();
  21332. var NullCipher = (function NullCipherClosure() {
  21333. function NullCipher() {
  21334. }
  21335. NullCipher.prototype = {
  21336. decryptBlock: function NullCipher_decryptBlock(data) {
  21337. return data;
  21338. }
  21339. };
  21340. return NullCipher;
  21341. })();
  21342. var AES128Cipher = (function AES128CipherClosure() {
  21343. var rcon = new Uint8Array([
  21344. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21345. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21346. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21347. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21348. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21349. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21350. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21351. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21352. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21353. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21354. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21355. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21356. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21357. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21358. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21359. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21360. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21361. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21362. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21363. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21364. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21365. 0x74, 0xe8, 0xcb, 0x8d]);
  21366. var s = new Uint8Array([
  21367. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21368. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21369. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21370. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21371. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21372. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21373. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21374. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21375. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21376. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21377. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21378. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21379. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21380. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21381. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21382. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21383. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21384. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21385. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21386. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21387. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21388. 0xb0, 0x54, 0xbb, 0x16]);
  21389. var inv_s = new Uint8Array([
  21390. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21391. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21392. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21393. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21394. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21395. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21396. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21397. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21398. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21399. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21400. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21401. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21402. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21403. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21404. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21405. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21406. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21407. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21408. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21409. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  21410. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  21411. 0x55, 0x21, 0x0c, 0x7d]);
  21412. var mixCol = new Uint8Array(256);
  21413. for (var i = 0; i < 256; i++) {
  21414. if (i < 128) {
  21415. mixCol[i] = i << 1;
  21416. } else {
  21417. mixCol[i] = (i << 1) ^ 0x1b;
  21418. }
  21419. }
  21420. var mix = new Uint32Array([
  21421. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  21422. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  21423. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  21424. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  21425. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  21426. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  21427. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  21428. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  21429. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  21430. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  21431. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  21432. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  21433. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  21434. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  21435. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  21436. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  21437. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  21438. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  21439. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  21440. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  21441. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  21442. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  21443. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  21444. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  21445. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  21446. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  21447. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  21448. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  21449. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  21450. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  21451. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  21452. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  21453. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  21454. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  21455. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  21456. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  21457. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  21458. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  21459. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  21460. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  21461. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  21462. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  21463. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  21464. function expandKey128(cipherKey) {
  21465. var b = 176, result = new Uint8Array(b);
  21466. result.set(cipherKey);
  21467. for (var j = 16, i = 1; j < b; ++i) {
  21468. // RotWord
  21469. var t1 = result[j - 3], t2 = result[j - 2],
  21470. t3 = result[j - 1], t4 = result[j - 4];
  21471. // SubWord
  21472. t1 = s[t1];
  21473. t2 = s[t2];
  21474. t3 = s[t3];
  21475. t4 = s[t4];
  21476. // Rcon
  21477. t1 = t1 ^ rcon[i];
  21478. for (var n = 0; n < 4; ++n) {
  21479. result[j] = (t1 ^= result[j - 16]);
  21480. j++;
  21481. result[j] = (t2 ^= result[j - 16]);
  21482. j++;
  21483. result[j] = (t3 ^= result[j - 16]);
  21484. j++;
  21485. result[j] = (t4 ^= result[j - 16]);
  21486. j++;
  21487. }
  21488. }
  21489. return result;
  21490. }
  21491. function decrypt128(input, key) {
  21492. var state = new Uint8Array(16);
  21493. state.set(input);
  21494. var i, j, k;
  21495. var t, u, v;
  21496. // AddRoundKey
  21497. for (j = 0, k = 160; j < 16; ++j, ++k) {
  21498. state[j] ^= key[k];
  21499. }
  21500. for (i = 9; i >= 1; --i) {
  21501. // InvShiftRows
  21502. t = state[13];
  21503. state[13] = state[9];
  21504. state[9] = state[5];
  21505. state[5] = state[1];
  21506. state[1] = t;
  21507. t = state[14];
  21508. u = state[10];
  21509. state[14] = state[6];
  21510. state[10] = state[2];
  21511. state[6] = t;
  21512. state[2] = u;
  21513. t = state[15];
  21514. u = state[11];
  21515. v = state[7];
  21516. state[15] = state[3];
  21517. state[11] = t;
  21518. state[7] = u;
  21519. state[3] = v;
  21520. // InvSubBytes
  21521. for (j = 0; j < 16; ++j) {
  21522. state[j] = inv_s[state[j]];
  21523. }
  21524. // AddRoundKey
  21525. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21526. state[j] ^= key[k];
  21527. }
  21528. // InvMixColumns
  21529. for (j = 0; j < 16; j += 4) {
  21530. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  21531. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  21532. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  21533. (s3 >>> 24) ^ (s3 << 8));
  21534. state[j] = (t >>> 24) & 0xFF;
  21535. state[j + 1] = (t >> 16) & 0xFF;
  21536. state[j + 2] = (t >> 8) & 0xFF;
  21537. state[j + 3] = t & 0xFF;
  21538. }
  21539. }
  21540. // InvShiftRows
  21541. t = state[13];
  21542. state[13] = state[9];
  21543. state[9] = state[5];
  21544. state[5] = state[1];
  21545. state[1] = t;
  21546. t = state[14];
  21547. u = state[10];
  21548. state[14] = state[6];
  21549. state[10] = state[2];
  21550. state[6] = t;
  21551. state[2] = u;
  21552. t = state[15];
  21553. u = state[11];
  21554. v = state[7];
  21555. state[15] = state[3];
  21556. state[11] = t;
  21557. state[7] = u;
  21558. state[3] = v;
  21559. for (j = 0; j < 16; ++j) {
  21560. // InvSubBytes
  21561. state[j] = inv_s[state[j]];
  21562. // AddRoundKey
  21563. state[j] ^= key[j];
  21564. }
  21565. return state;
  21566. }
  21567. function encrypt128(input, key) {
  21568. var t, u, v, k;
  21569. var state = new Uint8Array(16);
  21570. state.set(input);
  21571. for (j = 0; j < 16; ++j) {
  21572. // AddRoundKey
  21573. state[j] ^= key[j];
  21574. }
  21575. for (i = 1; i < 10; i++) {
  21576. //SubBytes
  21577. for (j = 0; j < 16; ++j) {
  21578. state[j] = s[state[j]];
  21579. }
  21580. //ShiftRows
  21581. v = state[1];
  21582. state[1] = state[5];
  21583. state[5] = state[9];
  21584. state[9] = state[13];
  21585. state[13] = v;
  21586. v = state[2];
  21587. u = state[6];
  21588. state[2] = state[10];
  21589. state[6] = state[14];
  21590. state[10] = v;
  21591. state[14] = u;
  21592. v = state[3];
  21593. u = state[7];
  21594. t = state[11];
  21595. state[3] = state[15];
  21596. state[7] = v;
  21597. state[11] = u;
  21598. state[15] = t;
  21599. //MixColumns
  21600. for (var j = 0; j < 16; j += 4) {
  21601. var s0 = state[j + 0], s1 = state[j + 1];
  21602. var s2 = state[j + 2], s3 = state[j + 3];
  21603. t = s0 ^ s1 ^ s2 ^ s3;
  21604. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  21605. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  21606. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  21607. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  21608. }
  21609. //AddRoundKey
  21610. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21611. state[j] ^= key[k];
  21612. }
  21613. }
  21614. //SubBytes
  21615. for (j = 0; j < 16; ++j) {
  21616. state[j] = s[state[j]];
  21617. }
  21618. //ShiftRows
  21619. v = state[1];
  21620. state[1] = state[5];
  21621. state[5] = state[9];
  21622. state[9] = state[13];
  21623. state[13] = v;
  21624. v = state[2];
  21625. u = state[6];
  21626. state[2] = state[10];
  21627. state[6] = state[14];
  21628. state[10] = v;
  21629. state[14] = u;
  21630. v = state[3];
  21631. u = state[7];
  21632. t = state[11];
  21633. state[3] = state[15];
  21634. state[7] = v;
  21635. state[11] = u;
  21636. state[15] = t;
  21637. //AddRoundKey
  21638. for (j = 0, k = 160; j < 16; ++j, ++k) {
  21639. state[j] ^= key[k];
  21640. }
  21641. return state;
  21642. }
  21643. function AES128Cipher(key) {
  21644. this.key = expandKey128(key);
  21645. this.buffer = new Uint8Array(16);
  21646. this.bufferPosition = 0;
  21647. }
  21648. function decryptBlock2(data, finalize) {
  21649. var i, j, ii, sourceLength = data.length,
  21650. buffer = this.buffer, bufferLength = this.bufferPosition,
  21651. result = [], iv = this.iv;
  21652. for (i = 0; i < sourceLength; ++i) {
  21653. buffer[bufferLength] = data[i];
  21654. ++bufferLength;
  21655. if (bufferLength < 16) {
  21656. continue;
  21657. }
  21658. // buffer is full, decrypting
  21659. var plain = decrypt128(buffer, this.key);
  21660. // xor-ing the IV vector to get plain text
  21661. for (j = 0; j < 16; ++j) {
  21662. plain[j] ^= iv[j];
  21663. }
  21664. iv = buffer;
  21665. result.push(plain);
  21666. buffer = new Uint8Array(16);
  21667. bufferLength = 0;
  21668. }
  21669. // saving incomplete buffer
  21670. this.buffer = buffer;
  21671. this.bufferLength = bufferLength;
  21672. this.iv = iv;
  21673. if (result.length === 0) {
  21674. return new Uint8Array([]);
  21675. }
  21676. // combining plain text blocks into one
  21677. var outputLength = 16 * result.length;
  21678. if (finalize) {
  21679. // undo a padding that is described in RFC 2898
  21680. var lastBlock = result[result.length - 1];
  21681. var psLen = lastBlock[15];
  21682. if (psLen <= 16) {
  21683. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  21684. if (lastBlock[i] !== psLen) {
  21685. // Invalid padding, assume that the block has no padding.
  21686. psLen = 0;
  21687. break;
  21688. }
  21689. }
  21690. outputLength -= psLen;
  21691. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  21692. }
  21693. }
  21694. var output = new Uint8Array(outputLength);
  21695. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21696. output.set(result[i], j);
  21697. }
  21698. return output;
  21699. }
  21700. AES128Cipher.prototype = {
  21701. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  21702. var i, sourceLength = data.length;
  21703. var buffer = this.buffer, bufferLength = this.bufferPosition;
  21704. // waiting for IV values -- they are at the start of the stream
  21705. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  21706. buffer[bufferLength] = data[i];
  21707. }
  21708. if (bufferLength < 16) {
  21709. // need more data
  21710. this.bufferLength = bufferLength;
  21711. return new Uint8Array([]);
  21712. }
  21713. this.iv = buffer;
  21714. this.buffer = new Uint8Array(16);
  21715. this.bufferLength = 0;
  21716. // starting decryption
  21717. this.decryptBlock = decryptBlock2;
  21718. return this.decryptBlock(data.subarray(16), finalize);
  21719. },
  21720. encrypt: function AES128Cipher_encrypt(data, iv) {
  21721. var i, j, ii, sourceLength = data.length,
  21722. buffer = this.buffer, bufferLength = this.bufferPosition,
  21723. result = [];
  21724. if (!iv) {
  21725. iv = new Uint8Array(16);
  21726. }
  21727. for (i = 0; i < sourceLength; ++i) {
  21728. buffer[bufferLength] = data[i];
  21729. ++bufferLength;
  21730. if (bufferLength < 16) {
  21731. continue;
  21732. }
  21733. for (j = 0; j < 16; ++j) {
  21734. buffer[j] ^= iv[j];
  21735. }
  21736. // buffer is full, encrypting
  21737. var cipher = encrypt128(buffer, this.key);
  21738. iv = cipher;
  21739. result.push(cipher);
  21740. buffer = new Uint8Array(16);
  21741. bufferLength = 0;
  21742. }
  21743. // saving incomplete buffer
  21744. this.buffer = buffer;
  21745. this.bufferLength = bufferLength;
  21746. this.iv = iv;
  21747. if (result.length === 0) {
  21748. return new Uint8Array([]);
  21749. }
  21750. // combining plain text blocks into one
  21751. var outputLength = 16 * result.length;
  21752. var output = new Uint8Array(outputLength);
  21753. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21754. output.set(result[i], j);
  21755. }
  21756. return output;
  21757. }
  21758. };
  21759. return AES128Cipher;
  21760. })();
  21761. var AES256Cipher = (function AES256CipherClosure() {
  21762. var rcon = new Uint8Array([
  21763. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21764. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21765. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21766. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21767. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21768. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21769. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21770. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21771. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21772. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21773. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21774. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21775. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21776. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21777. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21778. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21779. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21780. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21781. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21782. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21783. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21784. 0x74, 0xe8, 0xcb, 0x8d]);
  21785. var s = new Uint8Array([
  21786. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21787. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21788. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21789. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21790. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21791. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21792. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21793. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21794. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21795. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21796. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21797. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21798. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21799. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21800. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21801. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21802. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21803. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21804. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21805. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21806. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21807. 0xb0, 0x54, 0xbb, 0x16]);
  21808. var inv_s = new Uint8Array([
  21809. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21810. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21811. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21812. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21813. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21814. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21815. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21816. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21817. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21818. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21819. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21820. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21821. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21822. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21823. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21824. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21825. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21826. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21827. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21828. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  21829. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  21830. 0x55, 0x21, 0x0c, 0x7d]);
  21831. var mixCol = new Uint8Array(256);
  21832. for (var i = 0; i < 256; i++) {
  21833. if (i < 128) {
  21834. mixCol[i] = i << 1;
  21835. } else {
  21836. mixCol[i] = (i << 1) ^ 0x1b;
  21837. }
  21838. }
  21839. var mix = new Uint32Array([
  21840. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  21841. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  21842. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  21843. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  21844. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  21845. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  21846. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  21847. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  21848. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  21849. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  21850. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  21851. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  21852. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  21853. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  21854. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  21855. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  21856. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  21857. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  21858. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  21859. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  21860. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  21861. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  21862. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  21863. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  21864. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  21865. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  21866. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  21867. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  21868. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  21869. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  21870. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  21871. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  21872. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  21873. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  21874. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  21875. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  21876. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  21877. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  21878. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  21879. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  21880. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  21881. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  21882. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  21883. function expandKey256(cipherKey) {
  21884. var b = 240, result = new Uint8Array(b);
  21885. var r = 1;
  21886. result.set(cipherKey);
  21887. for (var j = 32, i = 1; j < b; ++i) {
  21888. if (j % 32 === 16) {
  21889. t1 = s[t1];
  21890. t2 = s[t2];
  21891. t3 = s[t3];
  21892. t4 = s[t4];
  21893. } else if (j % 32 === 0) {
  21894. // RotWord
  21895. var t1 = result[j - 3], t2 = result[j - 2],
  21896. t3 = result[j - 1], t4 = result[j - 4];
  21897. // SubWord
  21898. t1 = s[t1];
  21899. t2 = s[t2];
  21900. t3 = s[t3];
  21901. t4 = s[t4];
  21902. // Rcon
  21903. t1 = t1 ^ r;
  21904. if ((r <<= 1) >= 256) {
  21905. r = (r ^ 0x1b) & 0xFF;
  21906. }
  21907. }
  21908. for (var n = 0; n < 4; ++n) {
  21909. result[j] = (t1 ^= result[j - 32]);
  21910. j++;
  21911. result[j] = (t2 ^= result[j - 32]);
  21912. j++;
  21913. result[j] = (t3 ^= result[j - 32]);
  21914. j++;
  21915. result[j] = (t4 ^= result[j - 32]);
  21916. j++;
  21917. }
  21918. }
  21919. return result;
  21920. }
  21921. function decrypt256(input, key) {
  21922. var state = new Uint8Array(16);
  21923. state.set(input);
  21924. var i, j, k;
  21925. var t, u, v;
  21926. // AddRoundKey
  21927. for (j = 0, k = 224; j < 16; ++j, ++k) {
  21928. state[j] ^= key[k];
  21929. }
  21930. for (i = 13; i >= 1; --i) {
  21931. // InvShiftRows
  21932. t = state[13];
  21933. state[13] = state[9];
  21934. state[9] = state[5];
  21935. state[5] = state[1];
  21936. state[1] = t;
  21937. t = state[14];
  21938. u = state[10];
  21939. state[14] = state[6];
  21940. state[10] = state[2];
  21941. state[6] = t;
  21942. state[2] = u;
  21943. t = state[15];
  21944. u = state[11];
  21945. v = state[7];
  21946. state[15] = state[3];
  21947. state[11] = t;
  21948. state[7] = u;
  21949. state[3] = v;
  21950. // InvSubBytes
  21951. for (j = 0; j < 16; ++j) {
  21952. state[j] = inv_s[state[j]];
  21953. }
  21954. // AddRoundKey
  21955. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21956. state[j] ^= key[k];
  21957. }
  21958. // InvMixColumns
  21959. for (j = 0; j < 16; j += 4) {
  21960. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  21961. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  21962. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  21963. (s3 >>> 24) ^ (s3 << 8));
  21964. state[j] = (t >>> 24) & 0xFF;
  21965. state[j + 1] = (t >> 16) & 0xFF;
  21966. state[j + 2] = (t >> 8) & 0xFF;
  21967. state[j + 3] = t & 0xFF;
  21968. }
  21969. }
  21970. // InvShiftRows
  21971. t = state[13];
  21972. state[13] = state[9];
  21973. state[9] = state[5];
  21974. state[5] = state[1];
  21975. state[1] = t;
  21976. t = state[14];
  21977. u = state[10];
  21978. state[14] = state[6];
  21979. state[10] = state[2];
  21980. state[6] = t;
  21981. state[2] = u;
  21982. t = state[15];
  21983. u = state[11];
  21984. v = state[7];
  21985. state[15] = state[3];
  21986. state[11] = t;
  21987. state[7] = u;
  21988. state[3] = v;
  21989. for (j = 0; j < 16; ++j) {
  21990. // InvSubBytes
  21991. state[j] = inv_s[state[j]];
  21992. // AddRoundKey
  21993. state[j] ^= key[j];
  21994. }
  21995. return state;
  21996. }
  21997. function encrypt256(input, key) {
  21998. var t, u, v, k;
  21999. var state = new Uint8Array(16);
  22000. state.set(input);
  22001. for (j = 0; j < 16; ++j) {
  22002. // AddRoundKey
  22003. state[j] ^= key[j];
  22004. }
  22005. for (i = 1; i < 14; i++) {
  22006. //SubBytes
  22007. for (j = 0; j < 16; ++j) {
  22008. state[j] = s[state[j]];
  22009. }
  22010. //ShiftRows
  22011. v = state[1];
  22012. state[1] = state[5];
  22013. state[5] = state[9];
  22014. state[9] = state[13];
  22015. state[13] = v;
  22016. v = state[2];
  22017. u = state[6];
  22018. state[2] = state[10];
  22019. state[6] = state[14];
  22020. state[10] = v;
  22021. state[14] = u;
  22022. v = state[3];
  22023. u = state[7];
  22024. t = state[11];
  22025. state[3] = state[15];
  22026. state[7] = v;
  22027. state[11] = u;
  22028. state[15] = t;
  22029. //MixColumns
  22030. for (var j = 0; j < 16; j += 4) {
  22031. var s0 = state[j + 0], s1 = state[j + 1];
  22032. var s2 = state[j + 2], s3 = state[j + 3];
  22033. t = s0 ^ s1 ^ s2 ^ s3;
  22034. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22035. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22036. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22037. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22038. }
  22039. //AddRoundKey
  22040. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22041. state[j] ^= key[k];
  22042. }
  22043. }
  22044. //SubBytes
  22045. for (j = 0; j < 16; ++j) {
  22046. state[j] = s[state[j]];
  22047. }
  22048. //ShiftRows
  22049. v = state[1];
  22050. state[1] = state[5];
  22051. state[5] = state[9];
  22052. state[9] = state[13];
  22053. state[13] = v;
  22054. v = state[2];
  22055. u = state[6];
  22056. state[2] = state[10];
  22057. state[6] = state[14];
  22058. state[10] = v;
  22059. state[14] = u;
  22060. v = state[3];
  22061. u = state[7];
  22062. t = state[11];
  22063. state[3] = state[15];
  22064. state[7] = v;
  22065. state[11] = u;
  22066. state[15] = t;
  22067. //AddRoundKey
  22068. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22069. state[j] ^= key[k];
  22070. }
  22071. return state;
  22072. }
  22073. function AES256Cipher(key) {
  22074. this.key = expandKey256(key);
  22075. this.buffer = new Uint8Array(16);
  22076. this.bufferPosition = 0;
  22077. }
  22078. function decryptBlock2(data, finalize) {
  22079. var i, j, ii, sourceLength = data.length,
  22080. buffer = this.buffer, bufferLength = this.bufferPosition,
  22081. result = [], iv = this.iv;
  22082. for (i = 0; i < sourceLength; ++i) {
  22083. buffer[bufferLength] = data[i];
  22084. ++bufferLength;
  22085. if (bufferLength < 16) {
  22086. continue;
  22087. }
  22088. // buffer is full, decrypting
  22089. var plain = decrypt256(buffer, this.key);
  22090. // xor-ing the IV vector to get plain text
  22091. for (j = 0; j < 16; ++j) {
  22092. plain[j] ^= iv[j];
  22093. }
  22094. iv = buffer;
  22095. result.push(plain);
  22096. buffer = new Uint8Array(16);
  22097. bufferLength = 0;
  22098. }
  22099. // saving incomplete buffer
  22100. this.buffer = buffer;
  22101. this.bufferLength = bufferLength;
  22102. this.iv = iv;
  22103. if (result.length === 0) {
  22104. return new Uint8Array([]);
  22105. }
  22106. // combining plain text blocks into one
  22107. var outputLength = 16 * result.length;
  22108. if (finalize) {
  22109. // undo a padding that is described in RFC 2898
  22110. var lastBlock = result[result.length - 1];
  22111. var psLen = lastBlock[15];
  22112. if (psLen <= 16) {
  22113. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22114. if (lastBlock[i] !== psLen) {
  22115. // Invalid padding, assume that the block has no padding.
  22116. psLen = 0;
  22117. break;
  22118. }
  22119. }
  22120. outputLength -= psLen;
  22121. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22122. }
  22123. }
  22124. var output = new Uint8Array(outputLength);
  22125. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22126. output.set(result[i], j);
  22127. }
  22128. return output;
  22129. }
  22130. AES256Cipher.prototype = {
  22131. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  22132. var i, sourceLength = data.length;
  22133. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22134. // if not supplied an IV wait for IV values
  22135. // they are at the start of the stream
  22136. if (iv) {
  22137. this.iv = iv;
  22138. } else {
  22139. for (i = 0; bufferLength < 16 &&
  22140. i < sourceLength; ++i, ++bufferLength) {
  22141. buffer[bufferLength] = data[i];
  22142. }
  22143. if (bufferLength < 16) {
  22144. //need more data
  22145. this.bufferLength = bufferLength;
  22146. return new Uint8Array([]);
  22147. }
  22148. this.iv = buffer;
  22149. data = data.subarray(16);
  22150. }
  22151. this.buffer = new Uint8Array(16);
  22152. this.bufferLength = 0;
  22153. // starting decryption
  22154. this.decryptBlock = decryptBlock2;
  22155. return this.decryptBlock(data, finalize);
  22156. },
  22157. encrypt: function AES256Cipher_encrypt(data, iv) {
  22158. var i, j, ii, sourceLength = data.length,
  22159. buffer = this.buffer, bufferLength = this.bufferPosition,
  22160. result = [];
  22161. if (!iv) {
  22162. iv = new Uint8Array(16);
  22163. }
  22164. for (i = 0; i < sourceLength; ++i) {
  22165. buffer[bufferLength] = data[i];
  22166. ++bufferLength;
  22167. if (bufferLength < 16) {
  22168. continue;
  22169. }
  22170. for (j = 0; j < 16; ++j) {
  22171. buffer[j] ^= iv[j];
  22172. }
  22173. // buffer is full, encrypting
  22174. var cipher = encrypt256(buffer, this.key);
  22175. this.iv = cipher;
  22176. result.push(cipher);
  22177. buffer = new Uint8Array(16);
  22178. bufferLength = 0;
  22179. }
  22180. // saving incomplete buffer
  22181. this.buffer = buffer;
  22182. this.bufferLength = bufferLength;
  22183. this.iv = iv;
  22184. if (result.length === 0) {
  22185. return new Uint8Array([]);
  22186. }
  22187. // combining plain text blocks into one
  22188. var outputLength = 16 * result.length;
  22189. var output = new Uint8Array(outputLength);
  22190. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22191. output.set(result[i], j);
  22192. }
  22193. return output;
  22194. }
  22195. };
  22196. return AES256Cipher;
  22197. })();
  22198. var PDF17 = (function PDF17Closure() {
  22199. function compareByteArrays(array1, array2) {
  22200. if (array1.length !== array2.length) {
  22201. return false;
  22202. }
  22203. for (var i = 0; i < array1.length; i++) {
  22204. if (array1[i] !== array2[i]) {
  22205. return false;
  22206. }
  22207. }
  22208. return true;
  22209. }
  22210. function PDF17() {
  22211. }
  22212. PDF17.prototype = {
  22213. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  22214. ownerValidationSalt,
  22215. userBytes,
  22216. ownerPassword) {
  22217. var hashData = new Uint8Array(password.length + 56);
  22218. hashData.set(password, 0);
  22219. hashData.set(ownerValidationSalt, password.length);
  22220. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22221. var result = calculateSHA256(hashData, 0, hashData.length);
  22222. return compareByteArrays(result, ownerPassword);
  22223. },
  22224. checkUserPassword: function PDF17_checkUserPassword(password,
  22225. userValidationSalt,
  22226. userPassword) {
  22227. var hashData = new Uint8Array(password.length + 8);
  22228. hashData.set(password, 0);
  22229. hashData.set(userValidationSalt, password.length);
  22230. var result = calculateSHA256(hashData, 0, hashData.length);
  22231. return compareByteArrays(result, userPassword);
  22232. },
  22233. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  22234. ownerEncryption) {
  22235. var hashData = new Uint8Array(password.length + 56);
  22236. hashData.set(password, 0);
  22237. hashData.set(ownerKeySalt, password.length);
  22238. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22239. var key = calculateSHA256(hashData, 0, hashData.length);
  22240. var cipher = new AES256Cipher(key);
  22241. return cipher.decryptBlock(ownerEncryption,
  22242. false,
  22243. new Uint8Array(16));
  22244. },
  22245. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  22246. userEncryption) {
  22247. var hashData = new Uint8Array(password.length + 8);
  22248. hashData.set(password, 0);
  22249. hashData.set(userKeySalt, password.length);
  22250. //key is the decryption key for the UE string
  22251. var key = calculateSHA256(hashData, 0, hashData.length);
  22252. var cipher = new AES256Cipher(key);
  22253. return cipher.decryptBlock(userEncryption,
  22254. false,
  22255. new Uint8Array(16));
  22256. }
  22257. };
  22258. return PDF17;
  22259. })();
  22260. var PDF20 = (function PDF20Closure() {
  22261. function concatArrays(array1, array2) {
  22262. var t = new Uint8Array(array1.length + array2.length);
  22263. t.set(array1, 0);
  22264. t.set(array2, array1.length);
  22265. return t;
  22266. }
  22267. function calculatePDF20Hash(password, input, userBytes) {
  22268. //This refers to Algorithm 2.B as defined in ISO 32000-2
  22269. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  22270. var e = [0];
  22271. var i = 0;
  22272. while (i < 64 || e[e.length - 1] > i - 32) {
  22273. var arrayLength = password.length + k.length + userBytes.length;
  22274. var k1 = new Uint8Array(arrayLength * 64);
  22275. var array = concatArrays(password, k);
  22276. array = concatArrays(array, userBytes);
  22277. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  22278. k1.set(array, pos);
  22279. }
  22280. //AES128 CBC NO PADDING with
  22281. //first 16 bytes of k as the key and the second 16 as the iv.
  22282. var cipher = new AES128Cipher(k.subarray(0, 16));
  22283. e = cipher.encrypt(k1, k.subarray(16, 32));
  22284. //Now we have to take the first 16 bytes of an unsigned
  22285. //big endian integer... and compute the remainder
  22286. //modulo 3.... That is a fairly large number and
  22287. //JavaScript isn't going to handle that well...
  22288. //So we're using a trick that allows us to perform
  22289. //modulo math byte by byte
  22290. var remainder = 0;
  22291. for (var z = 0; z < 16; z++) {
  22292. remainder *= (256 % 3);
  22293. remainder %= 3;
  22294. remainder += ((e[z] >>> 0) % 3);
  22295. remainder %= 3;
  22296. }
  22297. if (remainder === 0) {
  22298. k = calculateSHA256(e, 0, e.length);
  22299. }
  22300. else if (remainder === 1) {
  22301. k = calculateSHA384(e, 0, e.length);
  22302. }
  22303. else if (remainder === 2) {
  22304. k = calculateSHA512(e, 0, e.length);
  22305. }
  22306. i++;
  22307. }
  22308. return k.subarray(0, 32);
  22309. }
  22310. function PDF20() {
  22311. }
  22312. function compareByteArrays(array1, array2) {
  22313. if (array1.length !== array2.length) {
  22314. return false;
  22315. }
  22316. for (var i = 0; i < array1.length; i++) {
  22317. if (array1[i] !== array2[i]) {
  22318. return false;
  22319. }
  22320. }
  22321. return true;
  22322. }
  22323. PDF20.prototype = {
  22324. hash: function PDF20_hash(password, concatBytes, userBytes) {
  22325. return calculatePDF20Hash(password, concatBytes, userBytes);
  22326. },
  22327. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  22328. ownerValidationSalt,
  22329. userBytes,
  22330. ownerPassword) {
  22331. var hashData = new Uint8Array(password.length + 56);
  22332. hashData.set(password, 0);
  22333. hashData.set(ownerValidationSalt, password.length);
  22334. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22335. var result = calculatePDF20Hash(password, hashData, userBytes);
  22336. return compareByteArrays(result, ownerPassword);
  22337. },
  22338. checkUserPassword: function PDF20_checkUserPassword(password,
  22339. userValidationSalt,
  22340. userPassword) {
  22341. var hashData = new Uint8Array(password.length + 8);
  22342. hashData.set(password, 0);
  22343. hashData.set(userValidationSalt, password.length);
  22344. var result = calculatePDF20Hash(password, hashData, []);
  22345. return compareByteArrays(result, userPassword);
  22346. },
  22347. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  22348. ownerEncryption) {
  22349. var hashData = new Uint8Array(password.length + 56);
  22350. hashData.set(password, 0);
  22351. hashData.set(ownerKeySalt, password.length);
  22352. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22353. var key = calculatePDF20Hash(password, hashData, userBytes);
  22354. var cipher = new AES256Cipher(key);
  22355. return cipher.decryptBlock(ownerEncryption,
  22356. false,
  22357. new Uint8Array(16));
  22358. },
  22359. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  22360. userEncryption) {
  22361. var hashData = new Uint8Array(password.length + 8);
  22362. hashData.set(password, 0);
  22363. hashData.set(userKeySalt, password.length);
  22364. //key is the decryption key for the UE string
  22365. var key = calculatePDF20Hash(password, hashData, []);
  22366. var cipher = new AES256Cipher(key);
  22367. return cipher.decryptBlock(userEncryption,
  22368. false,
  22369. new Uint8Array(16));
  22370. }
  22371. };
  22372. return PDF20;
  22373. })();
  22374. var CipherTransform = (function CipherTransformClosure() {
  22375. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  22376. this.stringCipherConstructor = stringCipherConstructor;
  22377. this.streamCipherConstructor = streamCipherConstructor;
  22378. }
  22379. CipherTransform.prototype = {
  22380. createStream: function CipherTransform_createStream(stream, length) {
  22381. var cipher = new this.streamCipherConstructor();
  22382. return new DecryptStream(stream, length,
  22383. function cipherTransformDecryptStream(data, finalize) {
  22384. return cipher.decryptBlock(data, finalize);
  22385. }
  22386. );
  22387. },
  22388. decryptString: function CipherTransform_decryptString(s) {
  22389. var cipher = new this.stringCipherConstructor();
  22390. var data = stringToBytes(s);
  22391. data = cipher.decryptBlock(data, true);
  22392. return bytesToString(data);
  22393. }
  22394. };
  22395. return CipherTransform;
  22396. })();
  22397. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  22398. var defaultPasswordBytes = new Uint8Array([
  22399. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  22400. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  22401. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  22402. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  22403. function createEncryptionKey20(revision, password, ownerPassword,
  22404. ownerValidationSalt, ownerKeySalt, uBytes,
  22405. userPassword, userValidationSalt, userKeySalt,
  22406. ownerEncryption, userEncryption, perms) {
  22407. if (password) {
  22408. var passwordLength = Math.min(127, password.length);
  22409. password = password.subarray(0, passwordLength);
  22410. } else {
  22411. password = [];
  22412. }
  22413. var pdfAlgorithm;
  22414. if (revision === 6) {
  22415. pdfAlgorithm = new PDF20();
  22416. } else {
  22417. pdfAlgorithm = new PDF17();
  22418. }
  22419. if (pdfAlgorithm) {
  22420. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  22421. userPassword)) {
  22422. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  22423. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  22424. ownerValidationSalt,
  22425. uBytes,
  22426. ownerPassword)) {
  22427. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  22428. ownerEncryption);
  22429. }
  22430. }
  22431. return null;
  22432. }
  22433. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  22434. flags, revision, keyLength, encryptMetadata) {
  22435. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  22436. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  22437. if (password) {
  22438. n = Math.min(32, password.length);
  22439. for (; i < n; ++i) {
  22440. hashData[i] = password[i];
  22441. }
  22442. }
  22443. j = 0;
  22444. while (i < 32) {
  22445. hashData[i++] = defaultPasswordBytes[j++];
  22446. }
  22447. // as now the padded password in the hashData[0..i]
  22448. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  22449. hashData[i++] = ownerPassword[j];
  22450. }
  22451. hashData[i++] = flags & 0xFF;
  22452. hashData[i++] = (flags >> 8) & 0xFF;
  22453. hashData[i++] = (flags >> 16) & 0xFF;
  22454. hashData[i++] = (flags >>> 24) & 0xFF;
  22455. for (j = 0, n = fileId.length; j < n; ++j) {
  22456. hashData[i++] = fileId[j];
  22457. }
  22458. if (revision >= 4 && !encryptMetadata) {
  22459. hashData[i++] = 0xFF;
  22460. hashData[i++] = 0xFF;
  22461. hashData[i++] = 0xFF;
  22462. hashData[i++] = 0xFF;
  22463. }
  22464. var hash = calculateMD5(hashData, 0, i);
  22465. var keyLengthInBytes = keyLength >> 3;
  22466. if (revision >= 3) {
  22467. for (j = 0; j < 50; ++j) {
  22468. hash = calculateMD5(hash, 0, keyLengthInBytes);
  22469. }
  22470. }
  22471. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  22472. var cipher, checkData;
  22473. if (revision >= 3) {
  22474. for (i = 0; i < 32; ++i) {
  22475. hashData[i] = defaultPasswordBytes[i];
  22476. }
  22477. for (j = 0, n = fileId.length; j < n; ++j) {
  22478. hashData[i++] = fileId[j];
  22479. }
  22480. cipher = new ARCFourCipher(encryptionKey);
  22481. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  22482. n = encryptionKey.length;
  22483. var derivedKey = new Uint8Array(n), k;
  22484. for (j = 1; j <= 19; ++j) {
  22485. for (k = 0; k < n; ++k) {
  22486. derivedKey[k] = encryptionKey[k] ^ j;
  22487. }
  22488. cipher = new ARCFourCipher(derivedKey);
  22489. checkData = cipher.encryptBlock(checkData);
  22490. }
  22491. for (j = 0, n = checkData.length; j < n; ++j) {
  22492. if (userPassword[j] !== checkData[j]) {
  22493. return null;
  22494. }
  22495. }
  22496. } else {
  22497. cipher = new ARCFourCipher(encryptionKey);
  22498. checkData = cipher.encryptBlock(defaultPasswordBytes);
  22499. for (j = 0, n = checkData.length; j < n; ++j) {
  22500. if (userPassword[j] !== checkData[j]) {
  22501. return null;
  22502. }
  22503. }
  22504. }
  22505. return encryptionKey;
  22506. }
  22507. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  22508. var hashData = new Uint8Array(32), i = 0, j, n;
  22509. n = Math.min(32, password.length);
  22510. for (; i < n; ++i) {
  22511. hashData[i] = password[i];
  22512. }
  22513. j = 0;
  22514. while (i < 32) {
  22515. hashData[i++] = defaultPasswordBytes[j++];
  22516. }
  22517. var hash = calculateMD5(hashData, 0, i);
  22518. var keyLengthInBytes = keyLength >> 3;
  22519. if (revision >= 3) {
  22520. for (j = 0; j < 50; ++j) {
  22521. hash = calculateMD5(hash, 0, hash.length);
  22522. }
  22523. }
  22524. var cipher, userPassword;
  22525. if (revision >= 3) {
  22526. userPassword = ownerPassword;
  22527. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  22528. for (j = 19; j >= 0; j--) {
  22529. for (k = 0; k < keyLengthInBytes; ++k) {
  22530. derivedKey[k] = hash[k] ^ j;
  22531. }
  22532. cipher = new ARCFourCipher(derivedKey);
  22533. userPassword = cipher.encryptBlock(userPassword);
  22534. }
  22535. } else {
  22536. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  22537. userPassword = cipher.encryptBlock(ownerPassword);
  22538. }
  22539. return userPassword;
  22540. }
  22541. var identityName = Name.get('Identity');
  22542. function CipherTransformFactory(dict, fileId, password) {
  22543. var filter = dict.get('Filter');
  22544. if (!isName(filter) || filter.name !== 'Standard') {
  22545. error('unknown encryption method');
  22546. }
  22547. this.dict = dict;
  22548. var algorithm = dict.get('V');
  22549. if (!isInt(algorithm) ||
  22550. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  22551. algorithm !== 5)) {
  22552. error('unsupported encryption algorithm');
  22553. }
  22554. this.algorithm = algorithm;
  22555. var keyLength = dict.get('Length');
  22556. if (!keyLength) {
  22557. // Spec asks to rely on encryption dictionary's Length entry, however
  22558. // some PDFs don't have it. Trying to recover.
  22559. if (algorithm <= 3) {
  22560. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  22561. keyLength = 40;
  22562. } else {
  22563. // Trying to find default handler -- it usually has Length.
  22564. var cfDict = dict.get('CF');
  22565. var streamCryptoName = dict.get('StmF');
  22566. if (isDict(cfDict) && isName(streamCryptoName)) {
  22567. var handlerDict = cfDict.get(streamCryptoName.name);
  22568. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  22569. if (keyLength < 40) {
  22570. // Sometimes it's incorrect value of bits, generators specify bytes.
  22571. keyLength <<= 3;
  22572. }
  22573. }
  22574. }
  22575. }
  22576. if (!isInt(keyLength) ||
  22577. keyLength < 40 || (keyLength % 8) !== 0) {
  22578. error('invalid key length');
  22579. }
  22580. // prepare keys
  22581. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  22582. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  22583. var flags = dict.get('P');
  22584. var revision = dict.get('R');
  22585. // meaningful when V is 4 or 5
  22586. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  22587. dict.get('EncryptMetadata') !== false);
  22588. this.encryptMetadata = encryptMetadata;
  22589. var fileIdBytes = stringToBytes(fileId);
  22590. var passwordBytes;
  22591. if (password) {
  22592. if (revision === 6) {
  22593. try {
  22594. password = utf8StringToString(password);
  22595. } catch (ex) {
  22596. warn('CipherTransformFactory: ' +
  22597. 'Unable to convert UTF8 encoded password.');
  22598. }
  22599. }
  22600. passwordBytes = stringToBytes(password);
  22601. }
  22602. var encryptionKey;
  22603. if (algorithm !== 5) {
  22604. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  22605. ownerPassword, userPassword, flags,
  22606. revision, keyLength, encryptMetadata);
  22607. }
  22608. else {
  22609. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  22610. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  22611. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  22612. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  22613. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  22614. var ownerEncryption = stringToBytes(dict.get('OE'));
  22615. var userEncryption = stringToBytes(dict.get('UE'));
  22616. var perms = stringToBytes(dict.get('Perms'));
  22617. encryptionKey =
  22618. createEncryptionKey20(revision, passwordBytes,
  22619. ownerPassword, ownerValidationSalt,
  22620. ownerKeySalt, uBytes,
  22621. userPassword, userValidationSalt,
  22622. userKeySalt, ownerEncryption,
  22623. userEncryption, perms);
  22624. }
  22625. if (!encryptionKey && !password) {
  22626. throw new PasswordException('No password given',
  22627. PasswordResponses.NEED_PASSWORD);
  22628. } else if (!encryptionKey && password) {
  22629. // Attempting use the password as an owner password
  22630. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  22631. revision, keyLength);
  22632. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  22633. ownerPassword, userPassword, flags,
  22634. revision, keyLength, encryptMetadata);
  22635. }
  22636. if (!encryptionKey) {
  22637. throw new PasswordException('Incorrect Password',
  22638. PasswordResponses.INCORRECT_PASSWORD);
  22639. }
  22640. this.encryptionKey = encryptionKey;
  22641. if (algorithm >= 4) {
  22642. this.cf = dict.get('CF');
  22643. this.stmf = dict.get('StmF') || identityName;
  22644. this.strf = dict.get('StrF') || identityName;
  22645. this.eff = dict.get('EFF') || this.stmf;
  22646. }
  22647. }
  22648. function buildObjectKey(num, gen, encryptionKey, isAes) {
  22649. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  22650. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  22651. key[i] = encryptionKey[i];
  22652. }
  22653. key[i++] = num & 0xFF;
  22654. key[i++] = (num >> 8) & 0xFF;
  22655. key[i++] = (num >> 16) & 0xFF;
  22656. key[i++] = gen & 0xFF;
  22657. key[i++] = (gen >> 8) & 0xFF;
  22658. if (isAes) {
  22659. key[i++] = 0x73;
  22660. key[i++] = 0x41;
  22661. key[i++] = 0x6C;
  22662. key[i++] = 0x54;
  22663. }
  22664. var hash = calculateMD5(key, 0, i);
  22665. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  22666. }
  22667. function buildCipherConstructor(cf, name, num, gen, key) {
  22668. var cryptFilter = cf.get(name.name);
  22669. var cfm;
  22670. if (cryptFilter !== null && cryptFilter !== undefined) {
  22671. cfm = cryptFilter.get('CFM');
  22672. }
  22673. if (!cfm || cfm.name === 'None') {
  22674. return function cipherTransformFactoryBuildCipherConstructorNone() {
  22675. return new NullCipher();
  22676. };
  22677. }
  22678. if ('V2' === cfm.name) {
  22679. return function cipherTransformFactoryBuildCipherConstructorV2() {
  22680. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  22681. };
  22682. }
  22683. if ('AESV2' === cfm.name) {
  22684. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  22685. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  22686. };
  22687. }
  22688. if ('AESV3' === cfm.name) {
  22689. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  22690. return new AES256Cipher(key);
  22691. };
  22692. }
  22693. error('Unknown crypto method');
  22694. }
  22695. CipherTransformFactory.prototype = {
  22696. createCipherTransform:
  22697. function CipherTransformFactory_createCipherTransform(num, gen) {
  22698. if (this.algorithm === 4 || this.algorithm === 5) {
  22699. return new CipherTransform(
  22700. buildCipherConstructor(this.cf, this.stmf,
  22701. num, gen, this.encryptionKey),
  22702. buildCipherConstructor(this.cf, this.strf,
  22703. num, gen, this.encryptionKey));
  22704. }
  22705. // algorithms 1 and 2
  22706. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  22707. var cipherConstructor = function buildCipherCipherConstructor() {
  22708. return new ARCFourCipher(key);
  22709. };
  22710. return new CipherTransform(cipherConstructor, cipherConstructor);
  22711. }
  22712. };
  22713. return CipherTransformFactory;
  22714. })();
  22715. exports.AES128Cipher = AES128Cipher;
  22716. exports.AES256Cipher = AES256Cipher;
  22717. exports.ARCFourCipher = ARCFourCipher;
  22718. exports.CipherTransformFactory = CipherTransformFactory;
  22719. exports.PDF17 = PDF17;
  22720. exports.PDF20 = PDF20;
  22721. exports.calculateMD5 = calculateMD5;
  22722. exports.calculateSHA256 = calculateSHA256;
  22723. exports.calculateSHA384 = calculateSHA384;
  22724. exports.calculateSHA512 = calculateSHA512;
  22725. }));
  22726. (function (root, factory) {
  22727. {
  22728. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  22729. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  22730. }
  22731. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  22732. var Util = sharedUtil.Util;
  22733. var bytesToString = sharedUtil.bytesToString;
  22734. var error = sharedUtil.error;
  22735. var Stream = coreStream.Stream;
  22736. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  22737. var coreFonts; // see _setCoreFonts below
  22738. var CFFParser; // = coreFonts.CFFParser;
  22739. var Encodings; // = coreFonts.Encodings;
  22740. var FontRendererFactory = (function FontRendererFactoryClosure() {
  22741. function getLong(data, offset) {
  22742. return (data[offset] << 24) | (data[offset + 1] << 16) |
  22743. (data[offset + 2] << 8) | data[offset + 3];
  22744. }
  22745. function getUshort(data, offset) {
  22746. return (data[offset] << 8) | data[offset + 1];
  22747. }
  22748. function parseCmap(data, start, end) {
  22749. var offset = (getUshort(data, start + 2) === 1 ?
  22750. getLong(data, start + 8) : getLong(data, start + 16));
  22751. var format = getUshort(data, start + offset);
  22752. var length, ranges, p, i;
  22753. if (format === 4) {
  22754. length = getUshort(data, start + offset + 2);
  22755. var segCount = getUshort(data, start + offset + 6) >> 1;
  22756. p = start + offset + 14;
  22757. ranges = [];
  22758. for (i = 0; i < segCount; i++, p += 2) {
  22759. ranges[i] = {end: getUshort(data, p)};
  22760. }
  22761. p += 2;
  22762. for (i = 0; i < segCount; i++, p += 2) {
  22763. ranges[i].start = getUshort(data, p);
  22764. }
  22765. for (i = 0; i < segCount; i++, p += 2) {
  22766. ranges[i].idDelta = getUshort(data, p);
  22767. }
  22768. for (i = 0; i < segCount; i++, p += 2) {
  22769. var idOffset = getUshort(data, p);
  22770. if (idOffset === 0) {
  22771. continue;
  22772. }
  22773. ranges[i].ids = [];
  22774. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  22775. ranges[i].ids[j] = getUshort(data, p + idOffset);
  22776. idOffset += 2;
  22777. }
  22778. }
  22779. return ranges;
  22780. } else if (format === 12) {
  22781. length = getLong(data, start + offset + 4);
  22782. var groups = getLong(data, start + offset + 12);
  22783. p = start + offset + 16;
  22784. ranges = [];
  22785. for (i = 0; i < groups; i++) {
  22786. ranges.push({
  22787. start: getLong(data, p),
  22788. end: getLong(data, p + 4),
  22789. idDelta: getLong(data, p + 8) - getLong(data, p)
  22790. });
  22791. p += 12;
  22792. }
  22793. return ranges;
  22794. }
  22795. error('not supported cmap: ' + format);
  22796. }
  22797. function parseCff(data, start, end) {
  22798. var properties = {};
  22799. var parser = new CFFParser(new Stream(data, start, end - start),
  22800. properties);
  22801. var cff = parser.parse();
  22802. return {
  22803. glyphs: cff.charStrings.objects,
  22804. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  22805. cff.topDict.privateDict.subrsIndex.objects),
  22806. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  22807. };
  22808. }
  22809. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  22810. var itemSize, itemDecode;
  22811. if (isGlyphLocationsLong) {
  22812. itemSize = 4;
  22813. itemDecode = function fontItemDecodeLong(data, offset) {
  22814. return (data[offset] << 24) | (data[offset + 1] << 16) |
  22815. (data[offset + 2] << 8) | data[offset + 3];
  22816. };
  22817. } else {
  22818. itemSize = 2;
  22819. itemDecode = function fontItemDecode(data, offset) {
  22820. return (data[offset] << 9) | (data[offset + 1] << 1);
  22821. };
  22822. }
  22823. var glyphs = [];
  22824. var startOffset = itemDecode(loca, 0);
  22825. for (var j = itemSize; j < loca.length; j += itemSize) {
  22826. var endOffset = itemDecode(loca, j);
  22827. glyphs.push(glyf.subarray(startOffset, endOffset));
  22828. startOffset = endOffset;
  22829. }
  22830. return glyphs;
  22831. }
  22832. function lookupCmap(ranges, unicode) {
  22833. var code = unicode.charCodeAt(0);
  22834. var l = 0, r = ranges.length - 1;
  22835. while (l < r) {
  22836. var c = (l + r + 1) >> 1;
  22837. if (code < ranges[c].start) {
  22838. r = c - 1;
  22839. } else {
  22840. l = c;
  22841. }
  22842. }
  22843. if (ranges[l].start <= code && code <= ranges[l].end) {
  22844. return (ranges[l].idDelta + (ranges[l].ids ?
  22845. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  22846. }
  22847. return 0;
  22848. }
  22849. function compileGlyf(code, cmds, font) {
  22850. function moveTo(x, y) {
  22851. cmds.push({cmd: 'moveTo', args: [x, y]});
  22852. }
  22853. function lineTo(x, y) {
  22854. cmds.push({cmd: 'lineTo', args: [x, y]});
  22855. }
  22856. function quadraticCurveTo(xa, ya, x, y) {
  22857. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  22858. }
  22859. var i = 0;
  22860. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22861. var flags;
  22862. var x = 0, y = 0;
  22863. i += 10;
  22864. if (numberOfContours < 0) {
  22865. // composite glyph
  22866. do {
  22867. flags = (code[i] << 8) | code[i + 1];
  22868. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  22869. i += 4;
  22870. var arg1, arg2;
  22871. if ((flags & 0x01)) {
  22872. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22873. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  22874. i += 4;
  22875. } else {
  22876. arg1 = code[i++]; arg2 = code[i++];
  22877. }
  22878. if ((flags & 0x02)) {
  22879. x = arg1;
  22880. y = arg2;
  22881. } else {
  22882. x = 0; y = 0; // TODO "they are points" ?
  22883. }
  22884. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  22885. if ((flags & 0x08)) {
  22886. scaleX =
  22887. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  22888. i += 2;
  22889. } else if ((flags & 0x40)) {
  22890. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  22891. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  22892. i += 4;
  22893. } else if ((flags & 0x80)) {
  22894. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  22895. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  22896. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  22897. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  22898. i += 8;
  22899. }
  22900. var subglyph = font.glyphs[glyphIndex];
  22901. if (subglyph) {
  22902. cmds.push({cmd: 'save'});
  22903. cmds.push({cmd: 'transform',
  22904. args: [scaleX, scale01, scale10, scaleY, x, y]});
  22905. compileGlyf(subglyph, cmds, font);
  22906. cmds.push({cmd: 'restore'});
  22907. }
  22908. } while ((flags & 0x20));
  22909. } else {
  22910. // simple glyph
  22911. var endPtsOfContours = [];
  22912. var j, jj;
  22913. for (j = 0; j < numberOfContours; j++) {
  22914. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  22915. i += 2;
  22916. }
  22917. var instructionLength = (code[i] << 8) | code[i + 1];
  22918. i += 2 + instructionLength; // skipping the instructions
  22919. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  22920. var points = [];
  22921. while (points.length < numberOfPoints) {
  22922. flags = code[i++];
  22923. var repeat = 1;
  22924. if ((flags & 0x08)) {
  22925. repeat += code[i++];
  22926. }
  22927. while (repeat-- > 0) {
  22928. points.push({flags: flags});
  22929. }
  22930. }
  22931. for (j = 0; j < numberOfPoints; j++) {
  22932. switch (points[j].flags & 0x12) {
  22933. case 0x00:
  22934. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22935. i += 2;
  22936. break;
  22937. case 0x02:
  22938. x -= code[i++];
  22939. break;
  22940. case 0x12:
  22941. x += code[i++];
  22942. break;
  22943. }
  22944. points[j].x = x;
  22945. }
  22946. for (j = 0; j < numberOfPoints; j++) {
  22947. switch (points[j].flags & 0x24) {
  22948. case 0x00:
  22949. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22950. i += 2;
  22951. break;
  22952. case 0x04:
  22953. y -= code[i++];
  22954. break;
  22955. case 0x24:
  22956. y += code[i++];
  22957. break;
  22958. }
  22959. points[j].y = y;
  22960. }
  22961. var startPoint = 0;
  22962. for (i = 0; i < numberOfContours; i++) {
  22963. var endPoint = endPtsOfContours[i];
  22964. // contours might have implicit points, which is located in the middle
  22965. // between two neighboring off-curve points
  22966. var contour = points.slice(startPoint, endPoint + 1);
  22967. if ((contour[0].flags & 1)) {
  22968. contour.push(contour[0]); // using start point at the contour end
  22969. } else if ((contour[contour.length - 1].flags & 1)) {
  22970. // first is off-curve point, trying to use one from the end
  22971. contour.unshift(contour[contour.length - 1]);
  22972. } else {
  22973. // start and end are off-curve points, creating implicit one
  22974. var p = {
  22975. flags: 1,
  22976. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  22977. y: (contour[0].y + contour[contour.length - 1].y) / 2
  22978. };
  22979. contour.unshift(p);
  22980. contour.push(p);
  22981. }
  22982. moveTo(contour[0].x, contour[0].y);
  22983. for (j = 1, jj = contour.length; j < jj; j++) {
  22984. if ((contour[j].flags & 1)) {
  22985. lineTo(contour[j].x, contour[j].y);
  22986. } else if ((contour[j + 1].flags & 1)){
  22987. quadraticCurveTo(contour[j].x, contour[j].y,
  22988. contour[j + 1].x, contour[j + 1].y);
  22989. j++;
  22990. } else {
  22991. quadraticCurveTo(contour[j].x, contour[j].y,
  22992. (contour[j].x + contour[j + 1].x) / 2,
  22993. (contour[j].y + contour[j + 1].y) / 2);
  22994. }
  22995. }
  22996. startPoint = endPoint + 1;
  22997. }
  22998. }
  22999. }
  23000. function compileCharString(code, cmds, font) {
  23001. var stack = [];
  23002. var x = 0, y = 0;
  23003. var stems = 0;
  23004. function moveTo(x, y) {
  23005. cmds.push({cmd: 'moveTo', args: [x, y]});
  23006. }
  23007. function lineTo(x, y) {
  23008. cmds.push({cmd: 'lineTo', args: [x, y]});
  23009. }
  23010. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23011. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  23012. }
  23013. function parse(code) {
  23014. var i = 0;
  23015. while (i < code.length) {
  23016. var stackClean = false;
  23017. var v = code[i++];
  23018. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23019. switch (v) {
  23020. case 1: // hstem
  23021. stems += stack.length >> 1;
  23022. stackClean = true;
  23023. break;
  23024. case 3: // vstem
  23025. stems += stack.length >> 1;
  23026. stackClean = true;
  23027. break;
  23028. case 4: // vmoveto
  23029. y += stack.pop();
  23030. moveTo(x, y);
  23031. stackClean = true;
  23032. break;
  23033. case 5: // rlineto
  23034. while (stack.length > 0) {
  23035. x += stack.shift();
  23036. y += stack.shift();
  23037. lineTo(x, y);
  23038. }
  23039. break;
  23040. case 6: // hlineto
  23041. while (stack.length > 0) {
  23042. x += stack.shift();
  23043. lineTo(x, y);
  23044. if (stack.length === 0) {
  23045. break;
  23046. }
  23047. y += stack.shift();
  23048. lineTo(x, y);
  23049. }
  23050. break;
  23051. case 7: // vlineto
  23052. while (stack.length > 0) {
  23053. y += stack.shift();
  23054. lineTo(x, y);
  23055. if (stack.length === 0) {
  23056. break;
  23057. }
  23058. x += stack.shift();
  23059. lineTo(x, y);
  23060. }
  23061. break;
  23062. case 8: // rrcurveto
  23063. while (stack.length > 0) {
  23064. xa = x + stack.shift(); ya = y + stack.shift();
  23065. xb = xa + stack.shift(); yb = ya + stack.shift();
  23066. x = xb + stack.shift(); y = yb + stack.shift();
  23067. bezierCurveTo(xa, ya, xb, yb, x, y);
  23068. }
  23069. break;
  23070. case 10: // callsubr
  23071. n = stack.pop() + font.subrsBias;
  23072. subrCode = font.subrs[n];
  23073. if (subrCode) {
  23074. parse(subrCode);
  23075. }
  23076. break;
  23077. case 11: // return
  23078. return;
  23079. case 12:
  23080. v = code[i++];
  23081. switch (v) {
  23082. case 34: // flex
  23083. xa = x + stack.shift();
  23084. xb = xa + stack.shift(); y1 = y + stack.shift();
  23085. x = xb + stack.shift();
  23086. bezierCurveTo(xa, y, xb, y1, x, y1);
  23087. xa = x + stack.shift();
  23088. xb = xa + stack.shift();
  23089. x = xb + stack.shift();
  23090. bezierCurveTo(xa, y1, xb, y, x, y);
  23091. break;
  23092. case 35: // flex
  23093. xa = x + stack.shift(); ya = y + stack.shift();
  23094. xb = xa + stack.shift(); yb = ya + stack.shift();
  23095. x = xb + stack.shift(); y = yb + stack.shift();
  23096. bezierCurveTo(xa, ya, xb, yb, x, y);
  23097. xa = x + stack.shift(); ya = y + stack.shift();
  23098. xb = xa + stack.shift(); yb = ya + stack.shift();
  23099. x = xb + stack.shift(); y = yb + stack.shift();
  23100. bezierCurveTo(xa, ya, xb, yb, x, y);
  23101. stack.pop(); // fd
  23102. break;
  23103. case 36: // hflex1
  23104. xa = x + stack.shift(); y1 = y + stack.shift();
  23105. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23106. x = xb + stack.shift();
  23107. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23108. xa = x + stack.shift();
  23109. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23110. x = xb + stack.shift();
  23111. bezierCurveTo(xa, y2, xb, y3, x, y);
  23112. break;
  23113. case 37: // flex1
  23114. var x0 = x, y0 = y;
  23115. xa = x + stack.shift(); ya = y + stack.shift();
  23116. xb = xa + stack.shift(); yb = ya + stack.shift();
  23117. x = xb + stack.shift(); y = yb + stack.shift();
  23118. bezierCurveTo(xa, ya, xb, yb, x, y);
  23119. xa = x + stack.shift(); ya = y + stack.shift();
  23120. xb = xa + stack.shift(); yb = ya + stack.shift();
  23121. x = xb; y = yb;
  23122. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23123. x += stack.shift();
  23124. } else {
  23125. y += stack.shift();
  23126. }
  23127. bezierCurveTo(xa, ya, xb, yb, x, y);
  23128. break;
  23129. default:
  23130. error('unknown operator: 12 ' + v);
  23131. }
  23132. break;
  23133. case 14: // endchar
  23134. if (stack.length >= 4) {
  23135. var achar = stack.pop();
  23136. var bchar = stack.pop();
  23137. y = stack.pop();
  23138. x = stack.pop();
  23139. cmds.push({cmd: 'save'});
  23140. cmds.push({cmd: 'translate', args: [x, y]});
  23141. var gid = lookupCmap(font.cmap, String.fromCharCode(
  23142. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  23143. compileCharString(font.glyphs[gid], cmds, font);
  23144. cmds.push({cmd: 'restore'});
  23145. gid = lookupCmap(font.cmap, String.fromCharCode(
  23146. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  23147. compileCharString(font.glyphs[gid], cmds, font);
  23148. }
  23149. return;
  23150. case 18: // hstemhm
  23151. stems += stack.length >> 1;
  23152. stackClean = true;
  23153. break;
  23154. case 19: // hintmask
  23155. stems += stack.length >> 1;
  23156. i += (stems + 7) >> 3;
  23157. stackClean = true;
  23158. break;
  23159. case 20: // cntrmask
  23160. stems += stack.length >> 1;
  23161. i += (stems + 7) >> 3;
  23162. stackClean = true;
  23163. break;
  23164. case 21: // rmoveto
  23165. y += stack.pop();
  23166. x += stack.pop();
  23167. moveTo(x, y);
  23168. stackClean = true;
  23169. break;
  23170. case 22: // hmoveto
  23171. x += stack.pop();
  23172. moveTo(x, y);
  23173. stackClean = true;
  23174. break;
  23175. case 23: // vstemhm
  23176. stems += stack.length >> 1;
  23177. stackClean = true;
  23178. break;
  23179. case 24: // rcurveline
  23180. while (stack.length > 2) {
  23181. xa = x + stack.shift(); ya = y + stack.shift();
  23182. xb = xa + stack.shift(); yb = ya + stack.shift();
  23183. x = xb + stack.shift(); y = yb + stack.shift();
  23184. bezierCurveTo(xa, ya, xb, yb, x, y);
  23185. }
  23186. x += stack.shift();
  23187. y += stack.shift();
  23188. lineTo(x, y);
  23189. break;
  23190. case 25: // rlinecurve
  23191. while (stack.length > 6) {
  23192. x += stack.shift();
  23193. y += stack.shift();
  23194. lineTo(x, y);
  23195. }
  23196. xa = x + stack.shift(); ya = y + stack.shift();
  23197. xb = xa + stack.shift(); yb = ya + stack.shift();
  23198. x = xb + stack.shift(); y = yb + stack.shift();
  23199. bezierCurveTo(xa, ya, xb, yb, x, y);
  23200. break;
  23201. case 26: // vvcurveto
  23202. if (stack.length % 2) {
  23203. x += stack.shift();
  23204. }
  23205. while (stack.length > 0) {
  23206. xa = x; ya = y + stack.shift();
  23207. xb = xa + stack.shift(); yb = ya + stack.shift();
  23208. x = xb; y = yb + stack.shift();
  23209. bezierCurveTo(xa, ya, xb, yb, x, y);
  23210. }
  23211. break;
  23212. case 27: // hhcurveto
  23213. if (stack.length % 2) {
  23214. y += stack.shift();
  23215. }
  23216. while (stack.length > 0) {
  23217. xa = x + stack.shift(); ya = y;
  23218. xb = xa + stack.shift(); yb = ya + stack.shift();
  23219. x = xb + stack.shift(); y = yb;
  23220. bezierCurveTo(xa, ya, xb, yb, x, y);
  23221. }
  23222. break;
  23223. case 28:
  23224. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23225. i += 2;
  23226. break;
  23227. case 29: // callgsubr
  23228. n = stack.pop() + font.gsubrsBias;
  23229. subrCode = font.gsubrs[n];
  23230. if (subrCode) {
  23231. parse(subrCode);
  23232. }
  23233. break;
  23234. case 30: // vhcurveto
  23235. while (stack.length > 0) {
  23236. xa = x; ya = y + stack.shift();
  23237. xb = xa + stack.shift(); yb = ya + stack.shift();
  23238. x = xb + stack.shift();
  23239. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23240. bezierCurveTo(xa, ya, xb, yb, x, y);
  23241. if (stack.length === 0) {
  23242. break;
  23243. }
  23244. xa = x + stack.shift(); ya = y;
  23245. xb = xa + stack.shift(); yb = ya + stack.shift();
  23246. y = yb + stack.shift();
  23247. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23248. bezierCurveTo(xa, ya, xb, yb, x, y);
  23249. }
  23250. break;
  23251. case 31: // hvcurveto
  23252. while (stack.length > 0) {
  23253. xa = x + stack.shift(); ya = y;
  23254. xb = xa + stack.shift(); yb = ya + stack.shift();
  23255. y = yb + stack.shift();
  23256. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23257. bezierCurveTo(xa, ya, xb, yb, x, y);
  23258. if (stack.length === 0) {
  23259. break;
  23260. }
  23261. xa = x; ya = y + stack.shift();
  23262. xb = xa + stack.shift(); yb = ya + stack.shift();
  23263. x = xb + stack.shift();
  23264. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23265. bezierCurveTo(xa, ya, xb, yb, x, y);
  23266. }
  23267. break;
  23268. default:
  23269. if (v < 32) {
  23270. error('unknown operator: ' + v);
  23271. }
  23272. if (v < 247) {
  23273. stack.push(v - 139);
  23274. } else if (v < 251) {
  23275. stack.push((v - 247) * 256 + code[i++] + 108);
  23276. } else if (v < 255) {
  23277. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23278. } else {
  23279. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23280. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23281. i += 4;
  23282. }
  23283. break;
  23284. }
  23285. if (stackClean) {
  23286. stack.length = 0;
  23287. }
  23288. }
  23289. }
  23290. parse(code);
  23291. }
  23292. var noop = '';
  23293. function CompiledFont(fontMatrix) {
  23294. this.compiledGlyphs = {};
  23295. this.fontMatrix = fontMatrix;
  23296. }
  23297. CompiledFont.prototype = {
  23298. getPathJs: function (unicode) {
  23299. var gid = lookupCmap(this.cmap, unicode);
  23300. var fn = this.compiledGlyphs[gid];
  23301. if (!fn) {
  23302. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  23303. }
  23304. return fn;
  23305. },
  23306. compileGlyph: function (code) {
  23307. if (!code || code.length === 0 || code[0] === 14) {
  23308. return noop;
  23309. }
  23310. var cmds = [];
  23311. cmds.push({cmd: 'save'});
  23312. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  23313. cmds.push({cmd: 'scale', args: ['size', '-size']});
  23314. this.compileGlyphImpl(code, cmds);
  23315. cmds.push({cmd: 'restore'});
  23316. return cmds;
  23317. },
  23318. compileGlyphImpl: function () {
  23319. error('Children classes should implement this.');
  23320. },
  23321. hasBuiltPath: function (unicode) {
  23322. var gid = lookupCmap(this.cmap, unicode);
  23323. return gid in this.compiledGlyphs;
  23324. }
  23325. };
  23326. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23327. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23328. CompiledFont.call(this, fontMatrix);
  23329. this.glyphs = glyphs;
  23330. this.cmap = cmap;
  23331. this.compiledGlyphs = [];
  23332. }
  23333. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23334. compileGlyphImpl: function (code, cmds) {
  23335. compileGlyf(code, cmds, this);
  23336. }
  23337. });
  23338. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23339. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23340. CompiledFont.call(this, fontMatrix);
  23341. this.glyphs = cffInfo.glyphs;
  23342. this.gsubrs = cffInfo.gsubrs || [];
  23343. this.subrs = cffInfo.subrs || [];
  23344. this.cmap = cmap;
  23345. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  23346. this.compiledGlyphs = [];
  23347. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23348. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23349. this.subrsBias = (this.subrs.length < 1240 ?
  23350. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23351. }
  23352. Util.inherit(Type2Compiled, CompiledFont, {
  23353. compileGlyphImpl: function (code, cmds) {
  23354. compileCharString(code, cmds, this);
  23355. }
  23356. });
  23357. return {
  23358. create: function FontRendererFactory_create(font) {
  23359. var data = new Uint8Array(font.data);
  23360. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23361. var numTables = getUshort(data, 4);
  23362. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23363. var tag = bytesToString(data.subarray(p, p + 4));
  23364. var offset = getLong(data, p + 8);
  23365. var length = getLong(data, p + 12);
  23366. switch (tag) {
  23367. case 'cmap':
  23368. cmap = parseCmap(data, offset, offset + length);
  23369. break;
  23370. case 'glyf':
  23371. glyf = data.subarray(offset, offset + length);
  23372. break;
  23373. case 'loca':
  23374. loca = data.subarray(offset, offset + length);
  23375. break;
  23376. case 'head':
  23377. unitsPerEm = getUshort(data, offset + 18);
  23378. indexToLocFormat = getUshort(data, offset + 50);
  23379. break;
  23380. case 'CFF ':
  23381. cff = parseCff(data, offset, offset + length);
  23382. break;
  23383. }
  23384. }
  23385. if (glyf) {
  23386. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23387. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23388. return new TrueTypeCompiled(
  23389. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23390. } else {
  23391. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23392. }
  23393. }
  23394. };
  23395. })();
  23396. // TODO refactor to remove cyclic dependency on fonts.js
  23397. function _setCoreFonts(coreFonts_) {
  23398. coreFonts = coreFonts_;
  23399. Encodings = coreFonts_.Encodings;
  23400. CFFParser = coreFonts_.CFFParser;
  23401. }
  23402. exports._setCoreFonts = _setCoreFonts;
  23403. exports.FontRendererFactory = FontRendererFactory;
  23404. }));
  23405. (function (root, factory) {
  23406. {
  23407. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  23408. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23409. }
  23410. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23411. var MissingDataException = sharedUtil.MissingDataException;
  23412. var StreamType = sharedUtil.StreamType;
  23413. var assert = sharedUtil.assert;
  23414. var error = sharedUtil.error;
  23415. var info = sharedUtil.info;
  23416. var isArray = sharedUtil.isArray;
  23417. var isInt = sharedUtil.isInt;
  23418. var isNum = sharedUtil.isNum;
  23419. var isString = sharedUtil.isString;
  23420. var warn = sharedUtil.warn;
  23421. var Cmd = corePrimitives.Cmd;
  23422. var Dict = corePrimitives.Dict;
  23423. var Name = corePrimitives.Name;
  23424. var Ref = corePrimitives.Ref;
  23425. var isCmd = corePrimitives.isCmd;
  23426. var isDict = corePrimitives.isDict;
  23427. var isName = corePrimitives.isName;
  23428. var Ascii85Stream = coreStream.Ascii85Stream;
  23429. var AsciiHexStream = coreStream.AsciiHexStream;
  23430. var CCITTFaxStream = coreStream.CCITTFaxStream;
  23431. var FlateStream = coreStream.FlateStream;
  23432. var Jbig2Stream = coreStream.Jbig2Stream;
  23433. var JpegStream = coreStream.JpegStream;
  23434. var JpxStream = coreStream.JpxStream;
  23435. var LZWStream = coreStream.LZWStream;
  23436. var NullStream = coreStream.NullStream;
  23437. var PredictorStream = coreStream.PredictorStream;
  23438. var RunLengthStream = coreStream.RunLengthStream;
  23439. var EOF = {};
  23440. function isEOF(v) {
  23441. return (v === EOF);
  23442. }
  23443. var MAX_LENGTH_TO_CACHE = 1000;
  23444. var Parser = (function ParserClosure() {
  23445. function Parser(lexer, allowStreams, xref) {
  23446. this.lexer = lexer;
  23447. this.allowStreams = allowStreams;
  23448. this.xref = xref;
  23449. this.imageCache = {};
  23450. this.refill();
  23451. }
  23452. Parser.prototype = {
  23453. refill: function Parser_refill() {
  23454. this.buf1 = this.lexer.getObj();
  23455. this.buf2 = this.lexer.getObj();
  23456. },
  23457. shift: function Parser_shift() {
  23458. if (isCmd(this.buf2, 'ID')) {
  23459. this.buf1 = this.buf2;
  23460. this.buf2 = null;
  23461. } else {
  23462. this.buf1 = this.buf2;
  23463. this.buf2 = this.lexer.getObj();
  23464. }
  23465. },
  23466. tryShift: function Parser_tryShift() {
  23467. try {
  23468. this.shift();
  23469. return true;
  23470. } catch (e) {
  23471. if (e instanceof MissingDataException) {
  23472. throw e;
  23473. }
  23474. // Upon failure, the caller should reset this.lexer.pos to a known good
  23475. // state and call this.shift() twice to reset the buffers.
  23476. return false;
  23477. }
  23478. },
  23479. getObj: function Parser_getObj(cipherTransform) {
  23480. var buf1 = this.buf1;
  23481. this.shift();
  23482. if (buf1 instanceof Cmd) {
  23483. switch (buf1.cmd) {
  23484. case 'BI': // inline image
  23485. return this.makeInlineImage(cipherTransform);
  23486. case '[': // array
  23487. var array = [];
  23488. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  23489. array.push(this.getObj(cipherTransform));
  23490. }
  23491. if (isEOF(this.buf1)) {
  23492. error('End of file inside array');
  23493. }
  23494. this.shift();
  23495. return array;
  23496. case '<<': // dictionary or stream
  23497. var dict = new Dict(this.xref);
  23498. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  23499. if (!isName(this.buf1)) {
  23500. info('Malformed dictionary: key must be a name object');
  23501. this.shift();
  23502. continue;
  23503. }
  23504. var key = this.buf1.name;
  23505. this.shift();
  23506. if (isEOF(this.buf1)) {
  23507. break;
  23508. }
  23509. dict.set(key, this.getObj(cipherTransform));
  23510. }
  23511. if (isEOF(this.buf1)) {
  23512. error('End of file inside dictionary');
  23513. }
  23514. // Stream objects are not allowed inside content streams or
  23515. // object streams.
  23516. if (isCmd(this.buf2, 'stream')) {
  23517. return (this.allowStreams ?
  23518. this.makeStream(dict, cipherTransform) : dict);
  23519. }
  23520. this.shift();
  23521. return dict;
  23522. default: // simple object
  23523. return buf1;
  23524. }
  23525. }
  23526. if (isInt(buf1)) { // indirect reference or integer
  23527. var num = buf1;
  23528. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  23529. var ref = new Ref(num, this.buf1);
  23530. this.shift();
  23531. this.shift();
  23532. return ref;
  23533. }
  23534. return num;
  23535. }
  23536. if (isString(buf1)) { // string
  23537. var str = buf1;
  23538. if (cipherTransform) {
  23539. str = cipherTransform.decryptString(str);
  23540. }
  23541. return str;
  23542. }
  23543. // simple object
  23544. return buf1;
  23545. },
  23546. /**
  23547. * Find the end of the stream by searching for the /EI\s/.
  23548. * @returns {number} The inline stream length.
  23549. */
  23550. findDefaultInlineStreamEnd:
  23551. function Parser_findDefaultInlineStreamEnd(stream) {
  23552. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  23553. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  23554. while ((ch = stream.getByte()) !== -1) {
  23555. if (state === 0) {
  23556. state = (ch === E) ? 1 : 0;
  23557. } else if (state === 1) {
  23558. state = (ch === I) ? 2 : 0;
  23559. } else {
  23560. assert(state === 2);
  23561. if (ch === SPACE || ch === LF || ch === CR) {
  23562. // Let's check the next five bytes are ASCII... just be sure.
  23563. n = 5;
  23564. followingBytes = stream.peekBytes(n);
  23565. for (i = 0; i < n; i++) {
  23566. ch = followingBytes[i];
  23567. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  23568. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  23569. // it's binary stuff. Resetting the state.
  23570. state = 0;
  23571. break;
  23572. }
  23573. }
  23574. if (state === 2) {
  23575. break; // Finished!
  23576. }
  23577. } else {
  23578. state = 0;
  23579. }
  23580. }
  23581. }
  23582. return ((stream.pos - 4) - startPos);
  23583. },
  23584. /**
  23585. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  23586. * @returns {number} The inline stream length.
  23587. */
  23588. findDCTDecodeInlineStreamEnd:
  23589. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  23590. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  23591. while ((b = stream.getByte()) !== -1) {
  23592. if (b !== 0xFF) { // Not a valid marker.
  23593. continue;
  23594. }
  23595. switch (stream.getByte()) {
  23596. case 0x00: // Byte stuffing.
  23597. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  23598. break;
  23599. case 0xFF: // Fill byte.
  23600. // Avoid skipping a valid marker, resetting the stream position.
  23601. stream.skip(-1);
  23602. break;
  23603. case 0xD9: // EOI
  23604. foundEOI = true;
  23605. break;
  23606. case 0xC0: // SOF0
  23607. case 0xC1: // SOF1
  23608. case 0xC2: // SOF2
  23609. case 0xC3: // SOF3
  23610. case 0xC5: // SOF5
  23611. case 0xC6: // SOF6
  23612. case 0xC7: // SOF7
  23613. case 0xC9: // SOF9
  23614. case 0xCA: // SOF10
  23615. case 0xCB: // SOF11
  23616. case 0xCD: // SOF13
  23617. case 0xCE: // SOF14
  23618. case 0xCF: // SOF15
  23619. case 0xC4: // DHT
  23620. case 0xCC: // DAC
  23621. case 0xDA: // SOS
  23622. case 0xDB: // DQT
  23623. case 0xDC: // DNL
  23624. case 0xDD: // DRI
  23625. case 0xDE: // DHP
  23626. case 0xDF: // EXP
  23627. case 0xE0: // APP0
  23628. case 0xE1: // APP1
  23629. case 0xE2: // APP2
  23630. case 0xE3: // APP3
  23631. case 0xE4: // APP4
  23632. case 0xE5: // APP5
  23633. case 0xE6: // APP6
  23634. case 0xE7: // APP7
  23635. case 0xE8: // APP8
  23636. case 0xE9: // APP9
  23637. case 0xEA: // APP10
  23638. case 0xEB: // APP11
  23639. case 0xEC: // APP12
  23640. case 0xED: // APP13
  23641. case 0xEE: // APP14
  23642. case 0xEF: // APP15
  23643. case 0xFE: // COM
  23644. // The marker should be followed by the length of the segment.
  23645. markerLength = stream.getUint16();
  23646. if (markerLength > 2) {
  23647. // |markerLength| contains the byte length of the marker segment,
  23648. // including its own length (2 bytes) and excluding the marker.
  23649. stream.skip(markerLength - 2); // Jump to the next marker.
  23650. } else {
  23651. // The marker length is invalid, resetting the stream position.
  23652. stream.skip(-2);
  23653. }
  23654. break;
  23655. }
  23656. if (foundEOI) {
  23657. break;
  23658. }
  23659. }
  23660. length = stream.pos - startPos;
  23661. if (b === -1) {
  23662. warn('Inline DCTDecode image stream: ' +
  23663. 'EOI marker not found, searching for /EI/ instead.');
  23664. stream.skip(-length); // Reset the stream position.
  23665. return this.findDefaultInlineStreamEnd(stream);
  23666. }
  23667. this.inlineStreamSkipEI(stream);
  23668. return length;
  23669. },
  23670. /**
  23671. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  23672. * @returns {number} The inline stream length.
  23673. */
  23674. findASCII85DecodeInlineStreamEnd:
  23675. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  23676. var TILDE = 0x7E, GT = 0x3E;
  23677. var startPos = stream.pos, ch, length;
  23678. while ((ch = stream.getByte()) !== -1) {
  23679. if (ch === TILDE && stream.peekByte() === GT) {
  23680. stream.skip();
  23681. break;
  23682. }
  23683. }
  23684. length = stream.pos - startPos;
  23685. if (ch === -1) {
  23686. warn('Inline ASCII85Decode image stream: ' +
  23687. 'EOD marker not found, searching for /EI/ instead.');
  23688. stream.skip(-length); // Reset the stream position.
  23689. return this.findDefaultInlineStreamEnd(stream);
  23690. }
  23691. this.inlineStreamSkipEI(stream);
  23692. return length;
  23693. },
  23694. /**
  23695. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  23696. * @returns {number} The inline stream length.
  23697. */
  23698. findASCIIHexDecodeInlineStreamEnd:
  23699. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  23700. var GT = 0x3E;
  23701. var startPos = stream.pos, ch, length;
  23702. while ((ch = stream.getByte()) !== -1) {
  23703. if (ch === GT) {
  23704. break;
  23705. }
  23706. }
  23707. length = stream.pos - startPos;
  23708. if (ch === -1) {
  23709. warn('Inline ASCIIHexDecode image stream: ' +
  23710. 'EOD marker not found, searching for /EI/ instead.');
  23711. stream.skip(-length); // Reset the stream position.
  23712. return this.findDefaultInlineStreamEnd(stream);
  23713. }
  23714. this.inlineStreamSkipEI(stream);
  23715. return length;
  23716. },
  23717. /**
  23718. * Skip over the /EI/ for streams where we search for an EOD marker.
  23719. */
  23720. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  23721. var E = 0x45, I = 0x49;
  23722. var state = 0, ch;
  23723. while ((ch = stream.getByte()) !== -1) {
  23724. if (state === 0) {
  23725. state = (ch === E) ? 1 : 0;
  23726. } else if (state === 1) {
  23727. state = (ch === I) ? 2 : 0;
  23728. } else if (state === 2) {
  23729. break;
  23730. }
  23731. }
  23732. },
  23733. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  23734. var lexer = this.lexer;
  23735. var stream = lexer.stream;
  23736. // Parse dictionary.
  23737. var dict = new Dict(this.xref);
  23738. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  23739. if (!isName(this.buf1)) {
  23740. error('Dictionary key must be a name object');
  23741. }
  23742. var key = this.buf1.name;
  23743. this.shift();
  23744. if (isEOF(this.buf1)) {
  23745. break;
  23746. }
  23747. dict.set(key, this.getObj(cipherTransform));
  23748. }
  23749. // Extract the name of the first (i.e. the current) image filter.
  23750. var filter = dict.get('Filter', 'F'), filterName;
  23751. if (isName(filter)) {
  23752. filterName = filter.name;
  23753. } else if (isArray(filter) && isName(filter[0])) {
  23754. filterName = filter[0].name;
  23755. }
  23756. // Parse image stream.
  23757. var startPos = stream.pos, length, i, ii;
  23758. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  23759. length = this.findDCTDecodeInlineStreamEnd(stream);
  23760. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  23761. length = this.findASCII85DecodeInlineStreamEnd(stream);
  23762. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  23763. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  23764. } else {
  23765. length = this.findDefaultInlineStreamEnd(stream);
  23766. }
  23767. var imageStream = stream.makeSubStream(startPos, length, dict);
  23768. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  23769. // adler32 checksum.
  23770. var adler32;
  23771. if (length < MAX_LENGTH_TO_CACHE) {
  23772. var imageBytes = imageStream.getBytes();
  23773. imageStream.reset();
  23774. var a = 1;
  23775. var b = 0;
  23776. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  23777. // No modulo required in the loop if imageBytes.length < 5552.
  23778. a += imageBytes[i] & 0xff;
  23779. b += a;
  23780. }
  23781. adler32 = ((b % 65521) << 16) | (a % 65521);
  23782. if (this.imageCache.adler32 === adler32) {
  23783. this.buf2 = Cmd.get('EI');
  23784. this.shift();
  23785. this.imageCache[adler32].reset();
  23786. return this.imageCache[adler32];
  23787. }
  23788. }
  23789. if (cipherTransform) {
  23790. imageStream = cipherTransform.createStream(imageStream, length);
  23791. }
  23792. imageStream = this.filter(imageStream, dict, length);
  23793. imageStream.dict = dict;
  23794. if (adler32 !== undefined) {
  23795. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  23796. this.imageCache[adler32] = imageStream;
  23797. }
  23798. this.buf2 = Cmd.get('EI');
  23799. this.shift();
  23800. return imageStream;
  23801. },
  23802. makeStream: function Parser_makeStream(dict, cipherTransform) {
  23803. var lexer = this.lexer;
  23804. var stream = lexer.stream;
  23805. // get stream start position
  23806. lexer.skipToNextLine();
  23807. var pos = stream.pos - 1;
  23808. // get length
  23809. var length = dict.get('Length');
  23810. if (!isInt(length)) {
  23811. info('Bad ' + length + ' attribute in stream');
  23812. length = 0;
  23813. }
  23814. // skip over the stream data
  23815. stream.pos = pos + length;
  23816. lexer.nextChar();
  23817. // Shift '>>' and check whether the new object marks the end of the stream
  23818. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  23819. this.shift(); // 'stream'
  23820. } else {
  23821. // bad stream length, scanning for endstream
  23822. stream.pos = pos;
  23823. var SCAN_BLOCK_SIZE = 2048;
  23824. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  23825. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  23826. 0x61, 0x6D];
  23827. var skipped = 0, found = false, i, j;
  23828. while (stream.pos < stream.end) {
  23829. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  23830. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  23831. if (scanLength <= 0) {
  23832. break;
  23833. }
  23834. found = false;
  23835. for (i = 0, j = 0; i < scanLength; i++) {
  23836. var b = scanBytes[i];
  23837. if (b !== ENDSTREAM_SIGNATURE[j]) {
  23838. i -= j;
  23839. j = 0;
  23840. } else {
  23841. j++;
  23842. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  23843. i++;
  23844. found = true;
  23845. break;
  23846. }
  23847. }
  23848. }
  23849. if (found) {
  23850. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  23851. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  23852. break;
  23853. }
  23854. skipped += scanLength;
  23855. stream.pos += scanLength;
  23856. }
  23857. if (!found) {
  23858. error('Missing endstream');
  23859. }
  23860. length = skipped;
  23861. lexer.nextChar();
  23862. this.shift();
  23863. this.shift();
  23864. }
  23865. this.shift(); // 'endstream'
  23866. stream = stream.makeSubStream(pos, length, dict);
  23867. if (cipherTransform) {
  23868. stream = cipherTransform.createStream(stream, length);
  23869. }
  23870. stream = this.filter(stream, dict, length);
  23871. stream.dict = dict;
  23872. return stream;
  23873. },
  23874. filter: function Parser_filter(stream, dict, length) {
  23875. var filter = dict.get('Filter', 'F');
  23876. var params = dict.get('DecodeParms', 'DP');
  23877. if (isName(filter)) {
  23878. return this.makeFilter(stream, filter.name, length, params);
  23879. }
  23880. var maybeLength = length;
  23881. if (isArray(filter)) {
  23882. var filterArray = filter;
  23883. var paramsArray = params;
  23884. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  23885. filter = filterArray[i];
  23886. if (!isName(filter)) {
  23887. error('Bad filter name: ' + filter);
  23888. }
  23889. params = null;
  23890. if (isArray(paramsArray) && (i in paramsArray)) {
  23891. params = paramsArray[i];
  23892. }
  23893. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  23894. // after the first stream the length variable is invalid
  23895. maybeLength = null;
  23896. }
  23897. }
  23898. return stream;
  23899. },
  23900. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  23901. if (stream.dict.get('Length') === 0 && !maybeLength) {
  23902. warn('Empty "' + name + '" stream.');
  23903. return new NullStream(stream);
  23904. }
  23905. try {
  23906. if (params && this.xref) {
  23907. params = this.xref.fetchIfRef(params);
  23908. }
  23909. var xrefStreamStats = this.xref.stats.streamTypes;
  23910. if (name === 'FlateDecode' || name === 'Fl') {
  23911. xrefStreamStats[StreamType.FLATE] = true;
  23912. if (params) {
  23913. return new PredictorStream(new FlateStream(stream, maybeLength),
  23914. maybeLength, params);
  23915. }
  23916. return new FlateStream(stream, maybeLength);
  23917. }
  23918. if (name === 'LZWDecode' || name === 'LZW') {
  23919. xrefStreamStats[StreamType.LZW] = true;
  23920. var earlyChange = 1;
  23921. if (params) {
  23922. if (params.has('EarlyChange')) {
  23923. earlyChange = params.get('EarlyChange');
  23924. }
  23925. return new PredictorStream(
  23926. new LZWStream(stream, maybeLength, earlyChange),
  23927. maybeLength, params);
  23928. }
  23929. return new LZWStream(stream, maybeLength, earlyChange);
  23930. }
  23931. if (name === 'DCTDecode' || name === 'DCT') {
  23932. xrefStreamStats[StreamType.DCT] = true;
  23933. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  23934. }
  23935. if (name === 'JPXDecode' || name === 'JPX') {
  23936. xrefStreamStats[StreamType.JPX] = true;
  23937. return new JpxStream(stream, maybeLength, stream.dict);
  23938. }
  23939. if (name === 'ASCII85Decode' || name === 'A85') {
  23940. xrefStreamStats[StreamType.A85] = true;
  23941. return new Ascii85Stream(stream, maybeLength);
  23942. }
  23943. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  23944. xrefStreamStats[StreamType.AHX] = true;
  23945. return new AsciiHexStream(stream, maybeLength);
  23946. }
  23947. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  23948. xrefStreamStats[StreamType.CCF] = true;
  23949. return new CCITTFaxStream(stream, maybeLength, params);
  23950. }
  23951. if (name === 'RunLengthDecode' || name === 'RL') {
  23952. xrefStreamStats[StreamType.RL] = true;
  23953. return new RunLengthStream(stream, maybeLength);
  23954. }
  23955. if (name === 'JBIG2Decode') {
  23956. xrefStreamStats[StreamType.JBIG] = true;
  23957. return new Jbig2Stream(stream, maybeLength, stream.dict);
  23958. }
  23959. warn('filter "' + name + '" not supported yet');
  23960. return stream;
  23961. } catch (ex) {
  23962. if (ex instanceof MissingDataException) {
  23963. throw ex;
  23964. }
  23965. warn('Invalid stream: \"' + ex + '\"');
  23966. return new NullStream(stream);
  23967. }
  23968. }
  23969. };
  23970. return Parser;
  23971. })();
  23972. var Lexer = (function LexerClosure() {
  23973. function Lexer(stream, knownCommands) {
  23974. this.stream = stream;
  23975. this.nextChar();
  23976. // While lexing, we build up many strings one char at a time. Using += for
  23977. // this can result in lots of garbage strings. It's better to build an
  23978. // array of single-char strings and then join() them together at the end.
  23979. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  23980. // purpose uses less memory than using a new array for each string.
  23981. this.strBuf = [];
  23982. // The PDFs might have "glued" commands with other commands, operands or
  23983. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  23984. // commands and their prefixes. The prefixes are built the following way:
  23985. // if there a command that is a prefix of the other valid command or
  23986. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  23987. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  23988. // other commands or literals as a prefix. The knowCommands is optional.
  23989. this.knownCommands = knownCommands;
  23990. }
  23991. Lexer.isSpace = function Lexer_isSpace(ch) {
  23992. // Space is one of the following characters: SPACE, TAB, CR or LF.
  23993. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  23994. };
  23995. // A '1' in this array means the character is white space. A '1' or
  23996. // '2' means the character ends a name or command.
  23997. var specialChars = [
  23998. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  23999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  24000. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  24001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  24002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  24003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  24004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  24005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  24006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  24007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  24008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  24009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  24010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  24011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  24012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  24013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  24014. ];
  24015. function toHexDigit(ch) {
  24016. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  24017. return ch & 0x0F;
  24018. }
  24019. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  24020. // 'A'-'F', 'a'-'f'
  24021. return (ch & 0x0F) + 9;
  24022. }
  24023. return -1;
  24024. }
  24025. Lexer.prototype = {
  24026. nextChar: function Lexer_nextChar() {
  24027. return (this.currentChar = this.stream.getByte());
  24028. },
  24029. peekChar: function Lexer_peekChar() {
  24030. return this.stream.peekByte();
  24031. },
  24032. getNumber: function Lexer_getNumber() {
  24033. var ch = this.currentChar;
  24034. var eNotation = false;
  24035. var divideBy = 0; // different from 0 if it's a floating point value
  24036. var sign = 1;
  24037. if (ch === 0x2D) { // '-'
  24038. sign = -1;
  24039. ch = this.nextChar();
  24040. if (ch === 0x2D) { // '-'
  24041. // Ignore double negative (this is consistent with Adobe Reader).
  24042. ch = this.nextChar();
  24043. }
  24044. } else if (ch === 0x2B) { // '+'
  24045. ch = this.nextChar();
  24046. }
  24047. if (ch === 0x2E) { // '.'
  24048. divideBy = 10;
  24049. ch = this.nextChar();
  24050. }
  24051. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24052. error('Invalid number: ' + String.fromCharCode(ch));
  24053. return 0;
  24054. }
  24055. var baseValue = ch - 0x30; // '0'
  24056. var powerValue = 0;
  24057. var powerValueSign = 1;
  24058. while ((ch = this.nextChar()) >= 0) {
  24059. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  24060. var currentDigit = ch - 0x30; // '0'
  24061. if (eNotation) { // We are after an 'e' or 'E'
  24062. powerValue = powerValue * 10 + currentDigit;
  24063. } else {
  24064. if (divideBy !== 0) { // We are after a point
  24065. divideBy *= 10;
  24066. }
  24067. baseValue = baseValue * 10 + currentDigit;
  24068. }
  24069. } else if (ch === 0x2E) { // '.'
  24070. if (divideBy === 0) {
  24071. divideBy = 1;
  24072. } else {
  24073. // A number can have only one '.'
  24074. break;
  24075. }
  24076. } else if (ch === 0x2D) { // '-'
  24077. // ignore minus signs in the middle of numbers to match
  24078. // Adobe's behavior
  24079. warn('Badly formated number');
  24080. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  24081. // 'E' can be either a scientific notation or the beginning of a new
  24082. // operator
  24083. ch = this.peekChar();
  24084. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  24085. powerValueSign = (ch === 0x2D) ? -1 : 1;
  24086. this.nextChar(); // Consume the sign character
  24087. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24088. // The 'E' must be the beginning of a new operator
  24089. break;
  24090. }
  24091. eNotation = true;
  24092. } else {
  24093. // the last character doesn't belong to us
  24094. break;
  24095. }
  24096. }
  24097. if (divideBy !== 0) {
  24098. baseValue /= divideBy;
  24099. }
  24100. if (eNotation) {
  24101. baseValue *= Math.pow(10, powerValueSign * powerValue);
  24102. }
  24103. return sign * baseValue;
  24104. },
  24105. getString: function Lexer_getString() {
  24106. var numParen = 1;
  24107. var done = false;
  24108. var strBuf = this.strBuf;
  24109. strBuf.length = 0;
  24110. var ch = this.nextChar();
  24111. while (true) {
  24112. var charBuffered = false;
  24113. switch (ch | 0) {
  24114. case -1:
  24115. warn('Unterminated string');
  24116. done = true;
  24117. break;
  24118. case 0x28: // '('
  24119. ++numParen;
  24120. strBuf.push('(');
  24121. break;
  24122. case 0x29: // ')'
  24123. if (--numParen === 0) {
  24124. this.nextChar(); // consume strings ')'
  24125. done = true;
  24126. } else {
  24127. strBuf.push(')');
  24128. }
  24129. break;
  24130. case 0x5C: // '\\'
  24131. ch = this.nextChar();
  24132. switch (ch) {
  24133. case -1:
  24134. warn('Unterminated string');
  24135. done = true;
  24136. break;
  24137. case 0x6E: // 'n'
  24138. strBuf.push('\n');
  24139. break;
  24140. case 0x72: // 'r'
  24141. strBuf.push('\r');
  24142. break;
  24143. case 0x74: // 't'
  24144. strBuf.push('\t');
  24145. break;
  24146. case 0x62: // 'b'
  24147. strBuf.push('\b');
  24148. break;
  24149. case 0x66: // 'f'
  24150. strBuf.push('\f');
  24151. break;
  24152. case 0x5C: // '\'
  24153. case 0x28: // '('
  24154. case 0x29: // ')'
  24155. strBuf.push(String.fromCharCode(ch));
  24156. break;
  24157. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  24158. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  24159. var x = ch & 0x0F;
  24160. ch = this.nextChar();
  24161. charBuffered = true;
  24162. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24163. x = (x << 3) + (ch & 0x0F);
  24164. ch = this.nextChar();
  24165. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24166. charBuffered = false;
  24167. x = (x << 3) + (ch & 0x0F);
  24168. }
  24169. }
  24170. strBuf.push(String.fromCharCode(x));
  24171. break;
  24172. case 0x0D: // CR
  24173. if (this.peekChar() === 0x0A) { // LF
  24174. this.nextChar();
  24175. }
  24176. break;
  24177. case 0x0A: // LF
  24178. break;
  24179. default:
  24180. strBuf.push(String.fromCharCode(ch));
  24181. break;
  24182. }
  24183. break;
  24184. default:
  24185. strBuf.push(String.fromCharCode(ch));
  24186. break;
  24187. }
  24188. if (done) {
  24189. break;
  24190. }
  24191. if (!charBuffered) {
  24192. ch = this.nextChar();
  24193. }
  24194. }
  24195. return strBuf.join('');
  24196. },
  24197. getName: function Lexer_getName() {
  24198. var ch, previousCh;
  24199. var strBuf = this.strBuf;
  24200. strBuf.length = 0;
  24201. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24202. if (ch === 0x23) { // '#'
  24203. ch = this.nextChar();
  24204. if (specialChars[ch]) {
  24205. warn('Lexer_getName: ' +
  24206. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  24207. strBuf.push('#');
  24208. break;
  24209. }
  24210. var x = toHexDigit(ch);
  24211. if (x !== -1) {
  24212. previousCh = ch;
  24213. ch = this.nextChar();
  24214. var x2 = toHexDigit(ch);
  24215. if (x2 === -1) {
  24216. warn('Lexer_getName: Illegal digit (' +
  24217. String.fromCharCode(ch) +') in hexadecimal number.');
  24218. strBuf.push('#', String.fromCharCode(previousCh));
  24219. if (specialChars[ch]) {
  24220. break;
  24221. }
  24222. strBuf.push(String.fromCharCode(ch));
  24223. continue;
  24224. }
  24225. strBuf.push(String.fromCharCode((x << 4) | x2));
  24226. } else {
  24227. strBuf.push('#', String.fromCharCode(ch));
  24228. }
  24229. } else {
  24230. strBuf.push(String.fromCharCode(ch));
  24231. }
  24232. }
  24233. if (strBuf.length > 127) {
  24234. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  24235. }
  24236. return Name.get(strBuf.join(''));
  24237. },
  24238. getHexString: function Lexer_getHexString() {
  24239. var strBuf = this.strBuf;
  24240. strBuf.length = 0;
  24241. var ch = this.currentChar;
  24242. var isFirstHex = true;
  24243. var firstDigit;
  24244. var secondDigit;
  24245. while (true) {
  24246. if (ch < 0) {
  24247. warn('Unterminated hex string');
  24248. break;
  24249. } else if (ch === 0x3E) { // '>'
  24250. this.nextChar();
  24251. break;
  24252. } else if (specialChars[ch] === 1) {
  24253. ch = this.nextChar();
  24254. continue;
  24255. } else {
  24256. if (isFirstHex) {
  24257. firstDigit = toHexDigit(ch);
  24258. if (firstDigit === -1) {
  24259. warn('Ignoring invalid character "' + ch + '" in hex string');
  24260. ch = this.nextChar();
  24261. continue;
  24262. }
  24263. } else {
  24264. secondDigit = toHexDigit(ch);
  24265. if (secondDigit === -1) {
  24266. warn('Ignoring invalid character "' + ch + '" in hex string');
  24267. ch = this.nextChar();
  24268. continue;
  24269. }
  24270. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  24271. }
  24272. isFirstHex = !isFirstHex;
  24273. ch = this.nextChar();
  24274. }
  24275. }
  24276. return strBuf.join('');
  24277. },
  24278. getObj: function Lexer_getObj() {
  24279. // skip whitespace and comments
  24280. var comment = false;
  24281. var ch = this.currentChar;
  24282. while (true) {
  24283. if (ch < 0) {
  24284. return EOF;
  24285. }
  24286. if (comment) {
  24287. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  24288. comment = false;
  24289. }
  24290. } else if (ch === 0x25) { // '%'
  24291. comment = true;
  24292. } else if (specialChars[ch] !== 1) {
  24293. break;
  24294. }
  24295. ch = this.nextChar();
  24296. }
  24297. // start reading token
  24298. switch (ch | 0) {
  24299. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24300. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24301. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24302. return this.getNumber();
  24303. case 0x28: // '('
  24304. return this.getString();
  24305. case 0x2F: // '/'
  24306. return this.getName();
  24307. // array punctuation
  24308. case 0x5B: // '['
  24309. this.nextChar();
  24310. return Cmd.get('[');
  24311. case 0x5D: // ']'
  24312. this.nextChar();
  24313. return Cmd.get(']');
  24314. // hex string or dict punctuation
  24315. case 0x3C: // '<'
  24316. ch = this.nextChar();
  24317. if (ch === 0x3C) {
  24318. // dict punctuation
  24319. this.nextChar();
  24320. return Cmd.get('<<');
  24321. }
  24322. return this.getHexString();
  24323. // dict punctuation
  24324. case 0x3E: // '>'
  24325. ch = this.nextChar();
  24326. if (ch === 0x3E) {
  24327. this.nextChar();
  24328. return Cmd.get('>>');
  24329. }
  24330. return Cmd.get('>');
  24331. case 0x7B: // '{'
  24332. this.nextChar();
  24333. return Cmd.get('{');
  24334. case 0x7D: // '}'
  24335. this.nextChar();
  24336. return Cmd.get('}');
  24337. case 0x29: // ')'
  24338. error('Illegal character: ' + ch);
  24339. break;
  24340. }
  24341. // command
  24342. var str = String.fromCharCode(ch);
  24343. var knownCommands = this.knownCommands;
  24344. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24345. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24346. // stop if known command is found and next character does not make
  24347. // the str a command
  24348. var possibleCommand = str + String.fromCharCode(ch);
  24349. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  24350. break;
  24351. }
  24352. if (str.length === 128) {
  24353. error('Command token too long: ' + str.length);
  24354. }
  24355. str = possibleCommand;
  24356. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24357. }
  24358. if (str === 'true') {
  24359. return true;
  24360. }
  24361. if (str === 'false') {
  24362. return false;
  24363. }
  24364. if (str === 'null') {
  24365. return null;
  24366. }
  24367. return Cmd.get(str);
  24368. },
  24369. skipToNextLine: function Lexer_skipToNextLine() {
  24370. var ch = this.currentChar;
  24371. while (ch >= 0) {
  24372. if (ch === 0x0D) { // CR
  24373. ch = this.nextChar();
  24374. if (ch === 0x0A) { // LF
  24375. this.nextChar();
  24376. }
  24377. break;
  24378. } else if (ch === 0x0A) { // LF
  24379. this.nextChar();
  24380. break;
  24381. }
  24382. ch = this.nextChar();
  24383. }
  24384. }
  24385. };
  24386. return Lexer;
  24387. })();
  24388. var Linearization = {
  24389. create: function LinearizationCreate(stream) {
  24390. function getInt(name, allowZeroValue) {
  24391. var obj = linDict.get(name);
  24392. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  24393. return obj;
  24394. }
  24395. throw new Error('The "' + name + '" parameter in the linearization ' +
  24396. 'dictionary is invalid.');
  24397. }
  24398. function getHints() {
  24399. var hints = linDict.get('H'), hintsLength, item;
  24400. if (isArray(hints) &&
  24401. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  24402. for (var index = 0; index < hintsLength; index++) {
  24403. if (!(isInt(item = hints[index]) && item > 0)) {
  24404. throw new Error('Hint (' + index +
  24405. ') in the linearization dictionary is invalid.');
  24406. }
  24407. }
  24408. return hints;
  24409. }
  24410. throw new Error('Hint array in the linearization dictionary is invalid.');
  24411. }
  24412. var parser = new Parser(new Lexer(stream), false, null);
  24413. var obj1 = parser.getObj();
  24414. var obj2 = parser.getObj();
  24415. var obj3 = parser.getObj();
  24416. var linDict = parser.getObj();
  24417. var obj, length;
  24418. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  24419. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  24420. return null; // No valid linearization dictionary found.
  24421. } else if ((length = getInt('L')) !== stream.length) {
  24422. throw new Error('The "L" parameter in the linearization dictionary ' +
  24423. 'does not equal the stream length.');
  24424. }
  24425. return {
  24426. length: length,
  24427. hints: getHints(),
  24428. objectNumberFirst: getInt('O'),
  24429. endFirst: getInt('E'),
  24430. numPages: getInt('N'),
  24431. mainXRefEntriesOffset: getInt('T'),
  24432. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  24433. };
  24434. }
  24435. };
  24436. exports.EOF = EOF;
  24437. exports.Lexer = Lexer;
  24438. exports.Linearization = Linearization;
  24439. exports.Parser = Parser;
  24440. exports.isEOF = isEOF;
  24441. // TODO refactor to remove dependency on stream.js
  24442. coreStream._setCoreParser(exports);
  24443. }));
  24444. (function (root, factory) {
  24445. {
  24446. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  24447. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  24448. }
  24449. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  24450. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  24451. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  24452. var ImageKind = sharedUtil.ImageKind;
  24453. var OPS = sharedUtil.OPS;
  24454. var TextRenderingMode = sharedUtil.TextRenderingMode;
  24455. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  24456. var Util = sharedUtil.Util;
  24457. var assert = sharedUtil.assert;
  24458. var info = sharedUtil.info;
  24459. var isNum = sharedUtil.isNum;
  24460. var isArray = sharedUtil.isArray;
  24461. var error = sharedUtil.error;
  24462. var shadow = sharedUtil.shadow;
  24463. var warn = sharedUtil.warn;
  24464. var TilingPattern = displayPatternHelper.TilingPattern;
  24465. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  24466. var WebGLUtils = displayWebGL.WebGLUtils;
  24467. // <canvas> contexts store most of the state we need natively.
  24468. // However, PDF needs a bit more state, which we store here.
  24469. // Minimal font size that would be used during canvas fillText operations.
  24470. var MIN_FONT_SIZE = 16;
  24471. // Maximum font size that would be used during canvas fillText operations.
  24472. var MAX_FONT_SIZE = 100;
  24473. var MAX_GROUP_SIZE = 4096;
  24474. // Heuristic value used when enforcing minimum line widths.
  24475. var MIN_WIDTH_FACTOR = 0.65;
  24476. var COMPILE_TYPE3_GLYPHS = true;
  24477. var MAX_SIZE_TO_COMPILE = 1000;
  24478. var FULL_CHUNK_HEIGHT = 16;
  24479. function createScratchCanvas(width, height) {
  24480. var canvas = document.createElement('canvas');
  24481. canvas.width = width;
  24482. canvas.height = height;
  24483. return canvas;
  24484. }
  24485. function addContextCurrentTransform(ctx) {
  24486. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  24487. if (!ctx.mozCurrentTransform) {
  24488. ctx._originalSave = ctx.save;
  24489. ctx._originalRestore = ctx.restore;
  24490. ctx._originalRotate = ctx.rotate;
  24491. ctx._originalScale = ctx.scale;
  24492. ctx._originalTranslate = ctx.translate;
  24493. ctx._originalTransform = ctx.transform;
  24494. ctx._originalSetTransform = ctx.setTransform;
  24495. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  24496. ctx._transformStack = [];
  24497. Object.defineProperty(ctx, 'mozCurrentTransform', {
  24498. get: function getCurrentTransform() {
  24499. return this._transformMatrix;
  24500. }
  24501. });
  24502. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  24503. get: function getCurrentTransformInverse() {
  24504. // Calculation done using WolframAlpha:
  24505. // http://www.wolframalpha.com/input/?
  24506. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  24507. var m = this._transformMatrix;
  24508. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  24509. var ad_bc = a * d - b * c;
  24510. var bc_ad = b * c - a * d;
  24511. return [
  24512. d / ad_bc,
  24513. b / bc_ad,
  24514. c / bc_ad,
  24515. a / ad_bc,
  24516. (d * e - c * f) / bc_ad,
  24517. (b * e - a * f) / ad_bc
  24518. ];
  24519. }
  24520. });
  24521. ctx.save = function ctxSave() {
  24522. var old = this._transformMatrix;
  24523. this._transformStack.push(old);
  24524. this._transformMatrix = old.slice(0, 6);
  24525. this._originalSave();
  24526. };
  24527. ctx.restore = function ctxRestore() {
  24528. var prev = this._transformStack.pop();
  24529. if (prev) {
  24530. this._transformMatrix = prev;
  24531. this._originalRestore();
  24532. }
  24533. };
  24534. ctx.translate = function ctxTranslate(x, y) {
  24535. var m = this._transformMatrix;
  24536. m[4] = m[0] * x + m[2] * y + m[4];
  24537. m[5] = m[1] * x + m[3] * y + m[5];
  24538. this._originalTranslate(x, y);
  24539. };
  24540. ctx.scale = function ctxScale(x, y) {
  24541. var m = this._transformMatrix;
  24542. m[0] = m[0] * x;
  24543. m[1] = m[1] * x;
  24544. m[2] = m[2] * y;
  24545. m[3] = m[3] * y;
  24546. this._originalScale(x, y);
  24547. };
  24548. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  24549. var m = this._transformMatrix;
  24550. this._transformMatrix = [
  24551. m[0] * a + m[2] * b,
  24552. m[1] * a + m[3] * b,
  24553. m[0] * c + m[2] * d,
  24554. m[1] * c + m[3] * d,
  24555. m[0] * e + m[2] * f + m[4],
  24556. m[1] * e + m[3] * f + m[5]
  24557. ];
  24558. ctx._originalTransform(a, b, c, d, e, f);
  24559. };
  24560. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  24561. this._transformMatrix = [a, b, c, d, e, f];
  24562. ctx._originalSetTransform(a, b, c, d, e, f);
  24563. };
  24564. ctx.rotate = function ctxRotate(angle) {
  24565. var cosValue = Math.cos(angle);
  24566. var sinValue = Math.sin(angle);
  24567. var m = this._transformMatrix;
  24568. this._transformMatrix = [
  24569. m[0] * cosValue + m[2] * sinValue,
  24570. m[1] * cosValue + m[3] * sinValue,
  24571. m[0] * (-sinValue) + m[2] * cosValue,
  24572. m[1] * (-sinValue) + m[3] * cosValue,
  24573. m[4],
  24574. m[5]
  24575. ];
  24576. this._originalRotate(angle);
  24577. };
  24578. }
  24579. }
  24580. var CachedCanvases = (function CachedCanvasesClosure() {
  24581. function CachedCanvases() {
  24582. this.cache = Object.create(null);
  24583. }
  24584. CachedCanvases.prototype = {
  24585. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  24586. trackTransform) {
  24587. var canvasEntry;
  24588. if (this.cache[id] !== undefined) {
  24589. canvasEntry = this.cache[id];
  24590. canvasEntry.canvas.width = width;
  24591. canvasEntry.canvas.height = height;
  24592. // reset canvas transform for emulated mozCurrentTransform, if needed
  24593. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  24594. } else {
  24595. var canvas = createScratchCanvas(width, height);
  24596. var ctx = canvas.getContext('2d');
  24597. if (trackTransform) {
  24598. addContextCurrentTransform(ctx);
  24599. }
  24600. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  24601. }
  24602. return canvasEntry;
  24603. },
  24604. clear: function () {
  24605. for (var id in this.cache) {
  24606. var canvasEntry = this.cache[id];
  24607. // Zeroing the width and height causes Firefox to release graphics
  24608. // resources immediately, which can greatly reduce memory consumption.
  24609. canvasEntry.canvas.width = 0;
  24610. canvasEntry.canvas.height = 0;
  24611. delete this.cache[id];
  24612. }
  24613. }
  24614. };
  24615. return CachedCanvases;
  24616. })();
  24617. function compileType3Glyph(imgData) {
  24618. var POINT_TO_PROCESS_LIMIT = 1000;
  24619. var width = imgData.width, height = imgData.height;
  24620. var i, j, j0, width1 = width + 1;
  24621. var points = new Uint8Array(width1 * (height + 1));
  24622. var POINT_TYPES =
  24623. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  24624. // decodes bit-packed mask data
  24625. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  24626. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  24627. for (i = 0, ii = data0.length; i < ii; i++) {
  24628. var mask = 128, elem = data0[i];
  24629. while (mask > 0) {
  24630. data[pos++] = (elem & mask) ? 0 : 255;
  24631. mask >>= 1;
  24632. }
  24633. }
  24634. // finding iteresting points: every point is located between mask pixels,
  24635. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  24636. // will have flags assigned based on neighboring mask pixels:
  24637. // 4 | 8
  24638. // --P--
  24639. // 2 | 1
  24640. // We are interested only in points with the flags:
  24641. // - outside corners: 1, 2, 4, 8;
  24642. // - inside corners: 7, 11, 13, 14;
  24643. // - and, intersections: 5, 10.
  24644. var count = 0;
  24645. pos = 0;
  24646. if (data[pos] !== 0) {
  24647. points[0] = 1;
  24648. ++count;
  24649. }
  24650. for (j = 1; j < width; j++) {
  24651. if (data[pos] !== data[pos + 1]) {
  24652. points[j] = data[pos] ? 2 : 1;
  24653. ++count;
  24654. }
  24655. pos++;
  24656. }
  24657. if (data[pos] !== 0) {
  24658. points[j] = 2;
  24659. ++count;
  24660. }
  24661. for (i = 1; i < height; i++) {
  24662. pos = i * lineSize;
  24663. j0 = i * width1;
  24664. if (data[pos - lineSize] !== data[pos]) {
  24665. points[j0] = data[pos] ? 1 : 8;
  24666. ++count;
  24667. }
  24668. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  24669. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  24670. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  24671. for (j = 1; j < width; j++) {
  24672. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  24673. (data[pos - lineSize + 1] ? 8 : 0);
  24674. if (POINT_TYPES[sum]) {
  24675. points[j0 + j] = POINT_TYPES[sum];
  24676. ++count;
  24677. }
  24678. pos++;
  24679. }
  24680. if (data[pos - lineSize] !== data[pos]) {
  24681. points[j0 + j] = data[pos] ? 2 : 4;
  24682. ++count;
  24683. }
  24684. if (count > POINT_TO_PROCESS_LIMIT) {
  24685. return null;
  24686. }
  24687. }
  24688. pos = lineSize * (height - 1);
  24689. j0 = i * width1;
  24690. if (data[pos] !== 0) {
  24691. points[j0] = 8;
  24692. ++count;
  24693. }
  24694. for (j = 1; j < width; j++) {
  24695. if (data[pos] !== data[pos + 1]) {
  24696. points[j0 + j] = data[pos] ? 4 : 8;
  24697. ++count;
  24698. }
  24699. pos++;
  24700. }
  24701. if (data[pos] !== 0) {
  24702. points[j0 + j] = 4;
  24703. ++count;
  24704. }
  24705. if (count > POINT_TO_PROCESS_LIMIT) {
  24706. return null;
  24707. }
  24708. // building outlines
  24709. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  24710. var outlines = [];
  24711. for (i = 0; count && i <= height; i++) {
  24712. var p = i * width1;
  24713. var end = p + width;
  24714. while (p < end && !points[p]) {
  24715. p++;
  24716. }
  24717. if (p === end) {
  24718. continue;
  24719. }
  24720. var coords = [p % width1, i];
  24721. var type = points[p], p0 = p, pp;
  24722. do {
  24723. var step = steps[type];
  24724. do {
  24725. p += step;
  24726. } while (!points[p]);
  24727. pp = points[p];
  24728. if (pp !== 5 && pp !== 10) {
  24729. // set new direction
  24730. type = pp;
  24731. // delete mark
  24732. points[p] = 0;
  24733. } else { // type is 5 or 10, ie, a crossing
  24734. // set new direction
  24735. type = pp & ((0x33 * type) >> 4);
  24736. // set new type for "future hit"
  24737. points[p] &= (type >> 2 | type << 2);
  24738. }
  24739. coords.push(p % width1);
  24740. coords.push((p / width1) | 0);
  24741. --count;
  24742. } while (p0 !== p);
  24743. outlines.push(coords);
  24744. --i;
  24745. }
  24746. var drawOutline = function(c) {
  24747. c.save();
  24748. // the path shall be painted in [0..1]x[0..1] space
  24749. c.scale(1 / width, -1 / height);
  24750. c.translate(0, -height);
  24751. c.beginPath();
  24752. for (var i = 0, ii = outlines.length; i < ii; i++) {
  24753. var o = outlines[i];
  24754. c.moveTo(o[0], o[1]);
  24755. for (var j = 2, jj = o.length; j < jj; j += 2) {
  24756. c.lineTo(o[j], o[j+1]);
  24757. }
  24758. }
  24759. c.fill();
  24760. c.beginPath();
  24761. c.restore();
  24762. };
  24763. return drawOutline;
  24764. }
  24765. var CanvasExtraState = (function CanvasExtraStateClosure() {
  24766. function CanvasExtraState(old) {
  24767. // Are soft masks and alpha values shapes or opacities?
  24768. this.alphaIsShape = false;
  24769. this.fontSize = 0;
  24770. this.fontSizeScale = 1;
  24771. this.textMatrix = IDENTITY_MATRIX;
  24772. this.textMatrixScale = 1;
  24773. this.fontMatrix = FONT_IDENTITY_MATRIX;
  24774. this.leading = 0;
  24775. // Current point (in user coordinates)
  24776. this.x = 0;
  24777. this.y = 0;
  24778. // Start of text line (in text coordinates)
  24779. this.lineX = 0;
  24780. this.lineY = 0;
  24781. // Character and word spacing
  24782. this.charSpacing = 0;
  24783. this.wordSpacing = 0;
  24784. this.textHScale = 1;
  24785. this.textRenderingMode = TextRenderingMode.FILL;
  24786. this.textRise = 0;
  24787. // Default fore and background colors
  24788. this.fillColor = '#000000';
  24789. this.strokeColor = '#000000';
  24790. this.patternFill = false;
  24791. // Note: fill alpha applies to all non-stroking operations
  24792. this.fillAlpha = 1;
  24793. this.strokeAlpha = 1;
  24794. this.lineWidth = 1;
  24795. this.activeSMask = null; // nonclonable field (see the save method below)
  24796. this.old = old;
  24797. }
  24798. CanvasExtraState.prototype = {
  24799. clone: function CanvasExtraState_clone() {
  24800. return Object.create(this);
  24801. },
  24802. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  24803. this.x = x;
  24804. this.y = y;
  24805. }
  24806. };
  24807. return CanvasExtraState;
  24808. })();
  24809. var CanvasGraphics = (function CanvasGraphicsClosure() {
  24810. // Defines the time the executeOperatorList is going to be executing
  24811. // before it stops and shedules a continue of execution.
  24812. var EXECUTION_TIME = 15;
  24813. // Defines the number of steps before checking the execution time
  24814. var EXECUTION_STEPS = 10;
  24815. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  24816. this.ctx = canvasCtx;
  24817. this.current = new CanvasExtraState();
  24818. this.stateStack = [];
  24819. this.pendingClip = null;
  24820. this.pendingEOFill = false;
  24821. this.res = null;
  24822. this.xobjs = null;
  24823. this.commonObjs = commonObjs;
  24824. this.objs = objs;
  24825. this.imageLayer = imageLayer;
  24826. this.groupStack = [];
  24827. this.processingType3 = null;
  24828. // Patterns are painted relative to the initial page/form transform, see pdf
  24829. // spec 8.7.2 NOTE 1.
  24830. this.baseTransform = null;
  24831. this.baseTransformStack = [];
  24832. this.groupLevel = 0;
  24833. this.smaskStack = [];
  24834. this.smaskCounter = 0;
  24835. this.tempSMask = null;
  24836. this.cachedCanvases = new CachedCanvases();
  24837. if (canvasCtx) {
  24838. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  24839. // the transformation must already be set in canvasCtx._transformMatrix.
  24840. addContextCurrentTransform(canvasCtx);
  24841. }
  24842. this.cachedGetSinglePixelWidth = null;
  24843. }
  24844. function putBinaryImageData(ctx, imgData) {
  24845. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  24846. ctx.putImageData(imgData, 0, 0);
  24847. return;
  24848. }
  24849. // Put the image data to the canvas in chunks, rather than putting the
  24850. // whole image at once. This saves JS memory, because the ImageData object
  24851. // is smaller. It also possibly saves C++ memory within the implementation
  24852. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  24853. // the data passed to putImageData()). |n| shouldn't be too small, however,
  24854. // because too many putImageData() calls will slow things down.
  24855. //
  24856. // Note: as written, if the last chunk is partial, the putImageData() call
  24857. // will (conceptually) put pixels past the bounds of the canvas. But
  24858. // that's ok; any such pixels are ignored.
  24859. var height = imgData.height, width = imgData.width;
  24860. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  24861. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  24862. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  24863. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  24864. var srcPos = 0, destPos;
  24865. var src = imgData.data;
  24866. var dest = chunkImgData.data;
  24867. var i, j, thisChunkHeight, elemsInThisChunk;
  24868. // There are multiple forms in which the pixel data can be passed, and
  24869. // imgData.kind tells us which one this is.
  24870. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  24871. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  24872. var srcLength = src.byteLength;
  24873. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  24874. new Uint32ArrayView(dest);
  24875. var dest32DataLength = dest32.length;
  24876. var fullSrcDiff = (width + 7) >> 3;
  24877. var white = 0xFFFFFFFF;
  24878. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  24879. 0xFF000000 : 0x000000FF;
  24880. for (i = 0; i < totalChunks; i++) {
  24881. thisChunkHeight =
  24882. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  24883. destPos = 0;
  24884. for (j = 0; j < thisChunkHeight; j++) {
  24885. var srcDiff = srcLength - srcPos;
  24886. var k = 0;
  24887. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  24888. var kEndUnrolled = kEnd & ~7;
  24889. var mask = 0;
  24890. var srcByte = 0;
  24891. for (; k < kEndUnrolled; k += 8) {
  24892. srcByte = src[srcPos++];
  24893. dest32[destPos++] = (srcByte & 128) ? white : black;
  24894. dest32[destPos++] = (srcByte & 64) ? white : black;
  24895. dest32[destPos++] = (srcByte & 32) ? white : black;
  24896. dest32[destPos++] = (srcByte & 16) ? white : black;
  24897. dest32[destPos++] = (srcByte & 8) ? white : black;
  24898. dest32[destPos++] = (srcByte & 4) ? white : black;
  24899. dest32[destPos++] = (srcByte & 2) ? white : black;
  24900. dest32[destPos++] = (srcByte & 1) ? white : black;
  24901. }
  24902. for (; k < kEnd; k++) {
  24903. if (mask === 0) {
  24904. srcByte = src[srcPos++];
  24905. mask = 128;
  24906. }
  24907. dest32[destPos++] = (srcByte & mask) ? white : black;
  24908. mask >>= 1;
  24909. }
  24910. }
  24911. // We ran out of input. Make all remaining pixels transparent.
  24912. while (destPos < dest32DataLength) {
  24913. dest32[destPos++] = 0;
  24914. }
  24915. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  24916. }
  24917. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  24918. // RGBA, 32-bits per pixel.
  24919. j = 0;
  24920. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  24921. for (i = 0; i < fullChunks; i++) {
  24922. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  24923. srcPos += elemsInThisChunk;
  24924. ctx.putImageData(chunkImgData, 0, j);
  24925. j += FULL_CHUNK_HEIGHT;
  24926. }
  24927. if (i < totalChunks) {
  24928. elemsInThisChunk = width * partialChunkHeight * 4;
  24929. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  24930. ctx.putImageData(chunkImgData, 0, j);
  24931. }
  24932. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  24933. // RGB, 24-bits per pixel.
  24934. thisChunkHeight = FULL_CHUNK_HEIGHT;
  24935. elemsInThisChunk = width * thisChunkHeight;
  24936. for (i = 0; i < totalChunks; i++) {
  24937. if (i >= fullChunks) {
  24938. thisChunkHeight = partialChunkHeight;
  24939. elemsInThisChunk = width * thisChunkHeight;
  24940. }
  24941. destPos = 0;
  24942. for (j = elemsInThisChunk; j--;) {
  24943. dest[destPos++] = src[srcPos++];
  24944. dest[destPos++] = src[srcPos++];
  24945. dest[destPos++] = src[srcPos++];
  24946. dest[destPos++] = 255;
  24947. }
  24948. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  24949. }
  24950. } else {
  24951. error('bad image kind: ' + imgData.kind);
  24952. }
  24953. }
  24954. function putBinaryImageMask(ctx, imgData) {
  24955. var height = imgData.height, width = imgData.width;
  24956. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  24957. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  24958. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  24959. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  24960. var srcPos = 0;
  24961. var src = imgData.data;
  24962. var dest = chunkImgData.data;
  24963. for (var i = 0; i < totalChunks; i++) {
  24964. var thisChunkHeight =
  24965. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  24966. // Expand the mask so it can be used by the canvas. Any required
  24967. // inversion has already been handled.
  24968. var destPos = 3; // alpha component offset
  24969. for (var j = 0; j < thisChunkHeight; j++) {
  24970. var mask = 0;
  24971. for (var k = 0; k < width; k++) {
  24972. if (!mask) {
  24973. var elem = src[srcPos++];
  24974. mask = 128;
  24975. }
  24976. dest[destPos] = (elem & mask) ? 0 : 255;
  24977. destPos += 4;
  24978. mask >>= 1;
  24979. }
  24980. }
  24981. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  24982. }
  24983. }
  24984. function copyCtxState(sourceCtx, destCtx) {
  24985. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  24986. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  24987. 'globalCompositeOperation', 'font'];
  24988. for (var i = 0, ii = properties.length; i < ii; i++) {
  24989. var property = properties[i];
  24990. if (sourceCtx[property] !== undefined) {
  24991. destCtx[property] = sourceCtx[property];
  24992. }
  24993. }
  24994. if (sourceCtx.setLineDash !== undefined) {
  24995. destCtx.setLineDash(sourceCtx.getLineDash());
  24996. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  24997. } else if (sourceCtx.mozDashOffset !== undefined) {
  24998. destCtx.mozDash = sourceCtx.mozDash;
  24999. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  25000. }
  25001. }
  25002. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  25003. var length = bytes.length;
  25004. for (var i = 3; i < length; i += 4) {
  25005. var alpha = bytes[i];
  25006. if (alpha === 0) {
  25007. bytes[i - 3] = r0;
  25008. bytes[i - 2] = g0;
  25009. bytes[i - 1] = b0;
  25010. } else if (alpha < 255) {
  25011. var alpha_ = 255 - alpha;
  25012. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  25013. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  25014. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  25015. }
  25016. }
  25017. }
  25018. function composeSMaskAlpha(maskData, layerData, transferMap) {
  25019. var length = maskData.length;
  25020. var scale = 1 / 255;
  25021. for (var i = 3; i < length; i += 4) {
  25022. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  25023. layerData[i] = (layerData[i] * alpha * scale) | 0;
  25024. }
  25025. }
  25026. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  25027. var length = maskData.length;
  25028. for (var i = 3; i < length; i += 4) {
  25029. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  25030. (maskData[i - 2] * 152) + // * 0.59 ....
  25031. (maskData[i - 1] * 28); // * 0.11 ....
  25032. layerData[i] = transferMap ?
  25033. (layerData[i] * transferMap[y >> 8]) >> 8 :
  25034. (layerData[i] * y) >> 16;
  25035. }
  25036. }
  25037. function genericComposeSMask(maskCtx, layerCtx, width, height,
  25038. subtype, backdrop, transferMap) {
  25039. var hasBackdrop = !!backdrop;
  25040. var r0 = hasBackdrop ? backdrop[0] : 0;
  25041. var g0 = hasBackdrop ? backdrop[1] : 0;
  25042. var b0 = hasBackdrop ? backdrop[2] : 0;
  25043. var composeFn;
  25044. if (subtype === 'Luminosity') {
  25045. composeFn = composeSMaskLuminosity;
  25046. } else {
  25047. composeFn = composeSMaskAlpha;
  25048. }
  25049. // processing image in chunks to save memory
  25050. var PIXELS_TO_PROCESS = 1048576;
  25051. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  25052. for (var row = 0; row < height; row += chunkSize) {
  25053. var chunkHeight = Math.min(chunkSize, height - row);
  25054. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  25055. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  25056. if (hasBackdrop) {
  25057. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  25058. }
  25059. composeFn(maskData.data, layerData.data, transferMap);
  25060. maskCtx.putImageData(layerData, 0, row);
  25061. }
  25062. }
  25063. function composeSMask(ctx, smask, layerCtx) {
  25064. var mask = smask.canvas;
  25065. var maskCtx = smask.context;
  25066. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  25067. smask.offsetX, smask.offsetY);
  25068. var backdrop = smask.backdrop || null;
  25069. if (!smask.transferMap && WebGLUtils.isEnabled) {
  25070. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  25071. {subtype: smask.subtype, backdrop: backdrop});
  25072. ctx.setTransform(1, 0, 0, 1, 0, 0);
  25073. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  25074. return;
  25075. }
  25076. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  25077. smask.subtype, backdrop, smask.transferMap);
  25078. ctx.drawImage(mask, 0, 0);
  25079. }
  25080. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  25081. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  25082. var NORMAL_CLIP = {};
  25083. var EO_CLIP = {};
  25084. CanvasGraphics.prototype = {
  25085. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  25086. transparency) {
  25087. // For pdfs that use blend modes we have to clear the canvas else certain
  25088. // blend modes can look wrong since we'd be blending with a white
  25089. // backdrop. The problem with a transparent backdrop though is we then
  25090. // don't get sub pixel anti aliasing on text, creating temporary
  25091. // transparent canvas when we have blend modes.
  25092. var width = this.ctx.canvas.width;
  25093. var height = this.ctx.canvas.height;
  25094. this.ctx.save();
  25095. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  25096. this.ctx.fillRect(0, 0, width, height);
  25097. this.ctx.restore();
  25098. if (transparency) {
  25099. var transparentCanvas = this.cachedCanvases.getCanvas(
  25100. 'transparent', width, height, true);
  25101. this.compositeCtx = this.ctx;
  25102. this.transparentCanvas = transparentCanvas.canvas;
  25103. this.ctx = transparentCanvas.context;
  25104. this.ctx.save();
  25105. // The transform can be applied before rendering, transferring it to
  25106. // the new canvas.
  25107. this.ctx.transform.apply(this.ctx,
  25108. this.compositeCtx.mozCurrentTransform);
  25109. }
  25110. this.ctx.save();
  25111. if (transform) {
  25112. this.ctx.transform.apply(this.ctx, transform);
  25113. }
  25114. this.ctx.transform.apply(this.ctx, viewport.transform);
  25115. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  25116. if (this.imageLayer) {
  25117. this.imageLayer.beginLayout();
  25118. }
  25119. },
  25120. executeOperatorList: function CanvasGraphics_executeOperatorList(
  25121. operatorList,
  25122. executionStartIdx, continueCallback,
  25123. stepper) {
  25124. var argsArray = operatorList.argsArray;
  25125. var fnArray = operatorList.fnArray;
  25126. var i = executionStartIdx || 0;
  25127. var argsArrayLen = argsArray.length;
  25128. // Sometimes the OperatorList to execute is empty.
  25129. if (argsArrayLen === i) {
  25130. return i;
  25131. }
  25132. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  25133. typeof continueCallback === 'function');
  25134. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  25135. var steps = 0;
  25136. var commonObjs = this.commonObjs;
  25137. var objs = this.objs;
  25138. var fnId;
  25139. while (true) {
  25140. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  25141. stepper.breakIt(i, continueCallback);
  25142. return i;
  25143. }
  25144. fnId = fnArray[i];
  25145. if (fnId !== OPS.dependency) {
  25146. this[fnId].apply(this, argsArray[i]);
  25147. } else {
  25148. var deps = argsArray[i];
  25149. for (var n = 0, nn = deps.length; n < nn; n++) {
  25150. var depObjId = deps[n];
  25151. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  25152. var objsPool = common ? commonObjs : objs;
  25153. // If the promise isn't resolved yet, add the continueCallback
  25154. // to the promise and bail out.
  25155. if (!objsPool.isResolved(depObjId)) {
  25156. objsPool.get(depObjId, continueCallback);
  25157. return i;
  25158. }
  25159. }
  25160. }
  25161. i++;
  25162. // If the entire operatorList was executed, stop as were done.
  25163. if (i === argsArrayLen) {
  25164. return i;
  25165. }
  25166. // If the execution took longer then a certain amount of time and
  25167. // `continueCallback` is specified, interrupt the execution.
  25168. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  25169. if (Date.now() > endTime) {
  25170. continueCallback();
  25171. return i;
  25172. }
  25173. steps = 0;
  25174. }
  25175. // If the operatorList isn't executed completely yet OR the execution
  25176. // time was short enough, do another execution round.
  25177. }
  25178. },
  25179. endDrawing: function CanvasGraphics_endDrawing() {
  25180. this.ctx.restore();
  25181. if (this.transparentCanvas) {
  25182. this.ctx = this.compositeCtx;
  25183. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  25184. this.transparentCanvas = null;
  25185. }
  25186. this.cachedCanvases.clear();
  25187. WebGLUtils.clear();
  25188. if (this.imageLayer) {
  25189. this.imageLayer.endLayout();
  25190. }
  25191. },
  25192. // Graphics state
  25193. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  25194. this.current.lineWidth = width;
  25195. this.ctx.lineWidth = width;
  25196. },
  25197. setLineCap: function CanvasGraphics_setLineCap(style) {
  25198. this.ctx.lineCap = LINE_CAP_STYLES[style];
  25199. },
  25200. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  25201. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  25202. },
  25203. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  25204. this.ctx.miterLimit = limit;
  25205. },
  25206. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  25207. var ctx = this.ctx;
  25208. if (ctx.setLineDash !== undefined) {
  25209. ctx.setLineDash(dashArray);
  25210. ctx.lineDashOffset = dashPhase;
  25211. } else {
  25212. ctx.mozDash = dashArray;
  25213. ctx.mozDashOffset = dashPhase;
  25214. }
  25215. },
  25216. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  25217. // Maybe if we one day fully support color spaces this will be important
  25218. // for now we can ignore.
  25219. // TODO set rendering intent?
  25220. },
  25221. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  25222. // There's no way to control this with canvas, but we can safely ignore.
  25223. // TODO set flatness?
  25224. },
  25225. setGState: function CanvasGraphics_setGState(states) {
  25226. for (var i = 0, ii = states.length; i < ii; i++) {
  25227. var state = states[i];
  25228. var key = state[0];
  25229. var value = state[1];
  25230. switch (key) {
  25231. case 'LW':
  25232. this.setLineWidth(value);
  25233. break;
  25234. case 'LC':
  25235. this.setLineCap(value);
  25236. break;
  25237. case 'LJ':
  25238. this.setLineJoin(value);
  25239. break;
  25240. case 'ML':
  25241. this.setMiterLimit(value);
  25242. break;
  25243. case 'D':
  25244. this.setDash(value[0], value[1]);
  25245. break;
  25246. case 'RI':
  25247. this.setRenderingIntent(value);
  25248. break;
  25249. case 'FL':
  25250. this.setFlatness(value);
  25251. break;
  25252. case 'Font':
  25253. this.setFont(value[0], value[1]);
  25254. break;
  25255. case 'CA':
  25256. this.current.strokeAlpha = state[1];
  25257. break;
  25258. case 'ca':
  25259. this.current.fillAlpha = state[1];
  25260. this.ctx.globalAlpha = state[1];
  25261. break;
  25262. case 'BM':
  25263. if (value && value.name && (value.name !== 'Normal')) {
  25264. var mode = value.name.replace(/([A-Z])/g,
  25265. function(c) {
  25266. return '-' + c.toLowerCase();
  25267. }
  25268. ).substring(1);
  25269. this.ctx.globalCompositeOperation = mode;
  25270. if (this.ctx.globalCompositeOperation !== mode) {
  25271. warn('globalCompositeOperation "' + mode +
  25272. '" is not supported');
  25273. }
  25274. } else {
  25275. this.ctx.globalCompositeOperation = 'source-over';
  25276. }
  25277. break;
  25278. case 'SMask':
  25279. if (this.current.activeSMask) {
  25280. this.endSMaskGroup();
  25281. }
  25282. this.current.activeSMask = value ? this.tempSMask : null;
  25283. if (this.current.activeSMask) {
  25284. this.beginSMaskGroup();
  25285. }
  25286. this.tempSMask = null;
  25287. break;
  25288. }
  25289. }
  25290. },
  25291. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  25292. var activeSMask = this.current.activeSMask;
  25293. var drawnWidth = activeSMask.canvas.width;
  25294. var drawnHeight = activeSMask.canvas.height;
  25295. var cacheId = 'smaskGroupAt' + this.groupLevel;
  25296. var scratchCanvas = this.cachedCanvases.getCanvas(
  25297. cacheId, drawnWidth, drawnHeight, true);
  25298. var currentCtx = this.ctx;
  25299. var currentTransform = currentCtx.mozCurrentTransform;
  25300. this.ctx.save();
  25301. var groupCtx = scratchCanvas.context;
  25302. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  25303. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  25304. groupCtx.transform.apply(groupCtx, currentTransform);
  25305. copyCtxState(currentCtx, groupCtx);
  25306. this.ctx = groupCtx;
  25307. this.setGState([
  25308. ['BM', 'Normal'],
  25309. ['ca', 1],
  25310. ['CA', 1]
  25311. ]);
  25312. this.groupStack.push(currentCtx);
  25313. this.groupLevel++;
  25314. },
  25315. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  25316. var groupCtx = this.ctx;
  25317. this.groupLevel--;
  25318. this.ctx = this.groupStack.pop();
  25319. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  25320. this.ctx.restore();
  25321. copyCtxState(groupCtx, this.ctx);
  25322. },
  25323. save: function CanvasGraphics_save() {
  25324. this.ctx.save();
  25325. var old = this.current;
  25326. this.stateStack.push(old);
  25327. this.current = old.clone();
  25328. this.current.activeSMask = null;
  25329. },
  25330. restore: function CanvasGraphics_restore() {
  25331. if (this.stateStack.length !== 0) {
  25332. if (this.current.activeSMask !== null) {
  25333. this.endSMaskGroup();
  25334. }
  25335. this.current = this.stateStack.pop();
  25336. this.ctx.restore();
  25337. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  25338. this.pendingClip = null;
  25339. this.cachedGetSinglePixelWidth = null;
  25340. }
  25341. },
  25342. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  25343. this.ctx.transform(a, b, c, d, e, f);
  25344. this.cachedGetSinglePixelWidth = null;
  25345. },
  25346. // Path
  25347. constructPath: function CanvasGraphics_constructPath(ops, args) {
  25348. var ctx = this.ctx;
  25349. var current = this.current;
  25350. var x = current.x, y = current.y;
  25351. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  25352. switch (ops[i] | 0) {
  25353. case OPS.rectangle:
  25354. x = args[j++];
  25355. y = args[j++];
  25356. var width = args[j++];
  25357. var height = args[j++];
  25358. if (width === 0) {
  25359. width = this.getSinglePixelWidth();
  25360. }
  25361. if (height === 0) {
  25362. height = this.getSinglePixelWidth();
  25363. }
  25364. var xw = x + width;
  25365. var yh = y + height;
  25366. this.ctx.moveTo(x, y);
  25367. this.ctx.lineTo(xw, y);
  25368. this.ctx.lineTo(xw, yh);
  25369. this.ctx.lineTo(x, yh);
  25370. this.ctx.lineTo(x, y);
  25371. this.ctx.closePath();
  25372. break;
  25373. case OPS.moveTo:
  25374. x = args[j++];
  25375. y = args[j++];
  25376. ctx.moveTo(x, y);
  25377. break;
  25378. case OPS.lineTo:
  25379. x = args[j++];
  25380. y = args[j++];
  25381. ctx.lineTo(x, y);
  25382. break;
  25383. case OPS.curveTo:
  25384. x = args[j + 4];
  25385. y = args[j + 5];
  25386. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  25387. x, y);
  25388. j += 6;
  25389. break;
  25390. case OPS.curveTo2:
  25391. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  25392. args[j + 2], args[j + 3]);
  25393. x = args[j + 2];
  25394. y = args[j + 3];
  25395. j += 4;
  25396. break;
  25397. case OPS.curveTo3:
  25398. x = args[j + 2];
  25399. y = args[j + 3];
  25400. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  25401. j += 4;
  25402. break;
  25403. case OPS.closePath:
  25404. ctx.closePath();
  25405. break;
  25406. }
  25407. }
  25408. current.setCurrentPoint(x, y);
  25409. },
  25410. closePath: function CanvasGraphics_closePath() {
  25411. this.ctx.closePath();
  25412. },
  25413. stroke: function CanvasGraphics_stroke(consumePath) {
  25414. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  25415. var ctx = this.ctx;
  25416. var strokeColor = this.current.strokeColor;
  25417. // Prevent drawing too thin lines by enforcing a minimum line width.
  25418. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  25419. this.current.lineWidth);
  25420. // For stroke we want to temporarily change the global alpha to the
  25421. // stroking alpha.
  25422. ctx.globalAlpha = this.current.strokeAlpha;
  25423. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  25424. strokeColor.type === 'Pattern') {
  25425. // for patterns, we transform to pattern space, calculate
  25426. // the pattern, call stroke, and restore to user space
  25427. ctx.save();
  25428. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  25429. ctx.stroke();
  25430. ctx.restore();
  25431. } else {
  25432. ctx.stroke();
  25433. }
  25434. if (consumePath) {
  25435. this.consumePath();
  25436. }
  25437. // Restore the global alpha to the fill alpha
  25438. ctx.globalAlpha = this.current.fillAlpha;
  25439. },
  25440. closeStroke: function CanvasGraphics_closeStroke() {
  25441. this.closePath();
  25442. this.stroke();
  25443. },
  25444. fill: function CanvasGraphics_fill(consumePath) {
  25445. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  25446. var ctx = this.ctx;
  25447. var fillColor = this.current.fillColor;
  25448. var isPatternFill = this.current.patternFill;
  25449. var needRestore = false;
  25450. if (isPatternFill) {
  25451. ctx.save();
  25452. if (this.baseTransform) {
  25453. ctx.setTransform.apply(ctx, this.baseTransform);
  25454. }
  25455. ctx.fillStyle = fillColor.getPattern(ctx, this);
  25456. needRestore = true;
  25457. }
  25458. if (this.pendingEOFill) {
  25459. if (ctx.mozFillRule !== undefined) {
  25460. ctx.mozFillRule = 'evenodd';
  25461. ctx.fill();
  25462. ctx.mozFillRule = 'nonzero';
  25463. } else {
  25464. ctx.fill('evenodd');
  25465. }
  25466. this.pendingEOFill = false;
  25467. } else {
  25468. ctx.fill();
  25469. }
  25470. if (needRestore) {
  25471. ctx.restore();
  25472. }
  25473. if (consumePath) {
  25474. this.consumePath();
  25475. }
  25476. },
  25477. eoFill: function CanvasGraphics_eoFill() {
  25478. this.pendingEOFill = true;
  25479. this.fill();
  25480. },
  25481. fillStroke: function CanvasGraphics_fillStroke() {
  25482. this.fill(false);
  25483. this.stroke(false);
  25484. this.consumePath();
  25485. },
  25486. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  25487. this.pendingEOFill = true;
  25488. this.fillStroke();
  25489. },
  25490. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  25491. this.closePath();
  25492. this.fillStroke();
  25493. },
  25494. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  25495. this.pendingEOFill = true;
  25496. this.closePath();
  25497. this.fillStroke();
  25498. },
  25499. endPath: function CanvasGraphics_endPath() {
  25500. this.consumePath();
  25501. },
  25502. // Clipping
  25503. clip: function CanvasGraphics_clip() {
  25504. this.pendingClip = NORMAL_CLIP;
  25505. },
  25506. eoClip: function CanvasGraphics_eoClip() {
  25507. this.pendingClip = EO_CLIP;
  25508. },
  25509. // Text
  25510. beginText: function CanvasGraphics_beginText() {
  25511. this.current.textMatrix = IDENTITY_MATRIX;
  25512. this.current.textMatrixScale = 1;
  25513. this.current.x = this.current.lineX = 0;
  25514. this.current.y = this.current.lineY = 0;
  25515. },
  25516. endText: function CanvasGraphics_endText() {
  25517. var paths = this.pendingTextPaths;
  25518. var ctx = this.ctx;
  25519. if (paths === undefined) {
  25520. ctx.beginPath();
  25521. return;
  25522. }
  25523. ctx.save();
  25524. ctx.beginPath();
  25525. for (var i = 0; i < paths.length; i++) {
  25526. var path = paths[i];
  25527. ctx.setTransform.apply(ctx, path.transform);
  25528. ctx.translate(path.x, path.y);
  25529. path.addToPath(ctx, path.fontSize);
  25530. }
  25531. ctx.restore();
  25532. ctx.clip();
  25533. ctx.beginPath();
  25534. delete this.pendingTextPaths;
  25535. },
  25536. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  25537. this.current.charSpacing = spacing;
  25538. },
  25539. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  25540. this.current.wordSpacing = spacing;
  25541. },
  25542. setHScale: function CanvasGraphics_setHScale(scale) {
  25543. this.current.textHScale = scale / 100;
  25544. },
  25545. setLeading: function CanvasGraphics_setLeading(leading) {
  25546. this.current.leading = -leading;
  25547. },
  25548. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  25549. var fontObj = this.commonObjs.get(fontRefName);
  25550. var current = this.current;
  25551. if (!fontObj) {
  25552. error('Can\'t find font for ' + fontRefName);
  25553. }
  25554. current.fontMatrix = (fontObj.fontMatrix ?
  25555. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  25556. // A valid matrix needs all main diagonal elements to be non-zero
  25557. // This also ensures we bypass FF bugzilla bug #719844.
  25558. if (current.fontMatrix[0] === 0 ||
  25559. current.fontMatrix[3] === 0) {
  25560. warn('Invalid font matrix for font ' + fontRefName);
  25561. }
  25562. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  25563. // and in some docs this can be negative (inverted x-y axes).
  25564. if (size < 0) {
  25565. size = -size;
  25566. current.fontDirection = -1;
  25567. } else {
  25568. current.fontDirection = 1;
  25569. }
  25570. this.current.font = fontObj;
  25571. this.current.fontSize = size;
  25572. if (fontObj.isType3Font) {
  25573. return; // we don't need ctx.font for Type3 fonts
  25574. }
  25575. var name = fontObj.loadedName || 'sans-serif';
  25576. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  25577. (fontObj.bold ? 'bold' : 'normal');
  25578. var italic = fontObj.italic ? 'italic' : 'normal';
  25579. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  25580. // Some font backends cannot handle fonts below certain size.
  25581. // Keeping the font at minimal size and using the fontSizeScale to change
  25582. // the current transformation matrix before the fillText/strokeText.
  25583. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  25584. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  25585. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  25586. this.current.fontSizeScale = size / browserFontSize;
  25587. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  25588. this.ctx.font = rule;
  25589. },
  25590. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  25591. this.current.textRenderingMode = mode;
  25592. },
  25593. setTextRise: function CanvasGraphics_setTextRise(rise) {
  25594. this.current.textRise = rise;
  25595. },
  25596. moveText: function CanvasGraphics_moveText(x, y) {
  25597. this.current.x = this.current.lineX += x;
  25598. this.current.y = this.current.lineY += y;
  25599. },
  25600. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  25601. this.setLeading(-y);
  25602. this.moveText(x, y);
  25603. },
  25604. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  25605. this.current.textMatrix = [a, b, c, d, e, f];
  25606. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  25607. this.current.x = this.current.lineX = 0;
  25608. this.current.y = this.current.lineY = 0;
  25609. },
  25610. nextLine: function CanvasGraphics_nextLine() {
  25611. this.moveText(0, this.current.leading);
  25612. },
  25613. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  25614. var ctx = this.ctx;
  25615. var current = this.current;
  25616. var font = current.font;
  25617. var textRenderingMode = current.textRenderingMode;
  25618. var fontSize = current.fontSize / current.fontSizeScale;
  25619. var fillStrokeMode = textRenderingMode &
  25620. TextRenderingMode.FILL_STROKE_MASK;
  25621. var isAddToPathSet = !!(textRenderingMode &
  25622. TextRenderingMode.ADD_TO_PATH_FLAG);
  25623. var addToPath;
  25624. if (font.disableFontFace || isAddToPathSet) {
  25625. addToPath = font.getPathGenerator(this.commonObjs, character);
  25626. }
  25627. if (font.disableFontFace) {
  25628. ctx.save();
  25629. ctx.translate(x, y);
  25630. ctx.beginPath();
  25631. addToPath(ctx, fontSize);
  25632. if (fillStrokeMode === TextRenderingMode.FILL ||
  25633. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25634. ctx.fill();
  25635. }
  25636. if (fillStrokeMode === TextRenderingMode.STROKE ||
  25637. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25638. ctx.stroke();
  25639. }
  25640. ctx.restore();
  25641. } else {
  25642. if (fillStrokeMode === TextRenderingMode.FILL ||
  25643. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25644. ctx.fillText(character, x, y);
  25645. }
  25646. if (fillStrokeMode === TextRenderingMode.STROKE ||
  25647. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25648. ctx.strokeText(character, x, y);
  25649. }
  25650. }
  25651. if (isAddToPathSet) {
  25652. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  25653. paths.push({
  25654. transform: ctx.mozCurrentTransform,
  25655. x: x,
  25656. y: y,
  25657. fontSize: fontSize,
  25658. addToPath: addToPath
  25659. });
  25660. }
  25661. },
  25662. get isFontSubpixelAAEnabled() {
  25663. // Checks if anti-aliasing is enabled when scaled text is painted.
  25664. // On Windows GDI scaled fonts looks bad.
  25665. var ctx = document.createElement('canvas').getContext('2d');
  25666. ctx.scale(1.5, 1);
  25667. ctx.fillText('I', 0, 10);
  25668. var data = ctx.getImageData(0, 0, 10, 10).data;
  25669. var enabled = false;
  25670. for (var i = 3; i < data.length; i += 4) {
  25671. if (data[i] > 0 && data[i] < 255) {
  25672. enabled = true;
  25673. break;
  25674. }
  25675. }
  25676. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  25677. },
  25678. showText: function CanvasGraphics_showText(glyphs) {
  25679. var current = this.current;
  25680. var font = current.font;
  25681. if (font.isType3Font) {
  25682. return this.showType3Text(glyphs);
  25683. }
  25684. var fontSize = current.fontSize;
  25685. if (fontSize === 0) {
  25686. return;
  25687. }
  25688. var ctx = this.ctx;
  25689. var fontSizeScale = current.fontSizeScale;
  25690. var charSpacing = current.charSpacing;
  25691. var wordSpacing = current.wordSpacing;
  25692. var fontDirection = current.fontDirection;
  25693. var textHScale = current.textHScale * fontDirection;
  25694. var glyphsLength = glyphs.length;
  25695. var vertical = font.vertical;
  25696. var spacingDir = vertical ? 1 : -1;
  25697. var defaultVMetrics = font.defaultVMetrics;
  25698. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  25699. var simpleFillText =
  25700. current.textRenderingMode === TextRenderingMode.FILL &&
  25701. !font.disableFontFace;
  25702. ctx.save();
  25703. ctx.transform.apply(ctx, current.textMatrix);
  25704. ctx.translate(current.x, current.y + current.textRise);
  25705. if (current.patternFill) {
  25706. // TODO: Some shading patterns are not applied correctly to text,
  25707. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  25708. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  25709. }
  25710. if (fontDirection > 0) {
  25711. ctx.scale(textHScale, -1);
  25712. } else {
  25713. ctx.scale(textHScale, 1);
  25714. }
  25715. var lineWidth = current.lineWidth;
  25716. var scale = current.textMatrixScale;
  25717. if (scale === 0 || lineWidth === 0) {
  25718. var fillStrokeMode = current.textRenderingMode &
  25719. TextRenderingMode.FILL_STROKE_MASK;
  25720. if (fillStrokeMode === TextRenderingMode.STROKE ||
  25721. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25722. this.cachedGetSinglePixelWidth = null;
  25723. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  25724. }
  25725. } else {
  25726. lineWidth /= scale;
  25727. }
  25728. if (fontSizeScale !== 1.0) {
  25729. ctx.scale(fontSizeScale, fontSizeScale);
  25730. lineWidth /= fontSizeScale;
  25731. }
  25732. ctx.lineWidth = lineWidth;
  25733. var x = 0, i;
  25734. for (i = 0; i < glyphsLength; ++i) {
  25735. var glyph = glyphs[i];
  25736. if (isNum(glyph)) {
  25737. x += spacingDir * glyph * fontSize / 1000;
  25738. continue;
  25739. }
  25740. var restoreNeeded = false;
  25741. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  25742. var character = glyph.fontChar;
  25743. var accent = glyph.accent;
  25744. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  25745. var width = glyph.width;
  25746. if (vertical) {
  25747. var vmetric, vx, vy;
  25748. vmetric = glyph.vmetric || defaultVMetrics;
  25749. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  25750. vx = -vx * widthAdvanceScale;
  25751. vy = vmetric[2] * widthAdvanceScale;
  25752. width = vmetric ? -vmetric[0] : width;
  25753. scaledX = vx / fontSizeScale;
  25754. scaledY = (x + vy) / fontSizeScale;
  25755. } else {
  25756. scaledX = x / fontSizeScale;
  25757. scaledY = 0;
  25758. }
  25759. if (font.remeasure && width > 0) {
  25760. // Some standard fonts may not have the exact width: rescale per
  25761. // character if measured width is greater than expected glyph width
  25762. // and subpixel-aa is enabled, otherwise just center the glyph.
  25763. var measuredWidth = ctx.measureText(character).width * 1000 /
  25764. fontSize * fontSizeScale;
  25765. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  25766. var characterScaleX = width / measuredWidth;
  25767. restoreNeeded = true;
  25768. ctx.save();
  25769. ctx.scale(characterScaleX, 1);
  25770. scaledX /= characterScaleX;
  25771. } else if (width !== measuredWidth) {
  25772. scaledX += (width - measuredWidth) / 2000 *
  25773. fontSize / fontSizeScale;
  25774. }
  25775. }
  25776. if (simpleFillText && !accent) {
  25777. // common case
  25778. ctx.fillText(character, scaledX, scaledY);
  25779. } else {
  25780. this.paintChar(character, scaledX, scaledY);
  25781. if (accent) {
  25782. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  25783. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  25784. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  25785. }
  25786. }
  25787. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  25788. x += charWidth;
  25789. if (restoreNeeded) {
  25790. ctx.restore();
  25791. }
  25792. }
  25793. if (vertical) {
  25794. current.y -= x * textHScale;
  25795. } else {
  25796. current.x += x * textHScale;
  25797. }
  25798. ctx.restore();
  25799. },
  25800. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  25801. // Type3 fonts - each glyph is a "mini-PDF"
  25802. var ctx = this.ctx;
  25803. var current = this.current;
  25804. var font = current.font;
  25805. var fontSize = current.fontSize;
  25806. var fontDirection = current.fontDirection;
  25807. var spacingDir = font.vertical ? 1 : -1;
  25808. var charSpacing = current.charSpacing;
  25809. var wordSpacing = current.wordSpacing;
  25810. var textHScale = current.textHScale * fontDirection;
  25811. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  25812. var glyphsLength = glyphs.length;
  25813. var isTextInvisible =
  25814. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  25815. var i, glyph, width, spacingLength;
  25816. if (isTextInvisible || fontSize === 0) {
  25817. return;
  25818. }
  25819. this.cachedGetSinglePixelWidth = null;
  25820. ctx.save();
  25821. ctx.transform.apply(ctx, current.textMatrix);
  25822. ctx.translate(current.x, current.y);
  25823. ctx.scale(textHScale, fontDirection);
  25824. for (i = 0; i < glyphsLength; ++i) {
  25825. glyph = glyphs[i];
  25826. if (isNum(glyph)) {
  25827. spacingLength = spacingDir * glyph * fontSize / 1000;
  25828. this.ctx.translate(spacingLength, 0);
  25829. current.x += spacingLength * textHScale;
  25830. continue;
  25831. }
  25832. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  25833. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  25834. if (!operatorList) {
  25835. warn('Type3 character \"' + glyph.operatorListId +
  25836. '\" is not available');
  25837. continue;
  25838. }
  25839. this.processingType3 = glyph;
  25840. this.save();
  25841. ctx.scale(fontSize, fontSize);
  25842. ctx.transform.apply(ctx, fontMatrix);
  25843. this.executeOperatorList(operatorList);
  25844. this.restore();
  25845. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  25846. width = transformed[0] * fontSize + spacing;
  25847. ctx.translate(width, 0);
  25848. current.x += width * textHScale;
  25849. }
  25850. ctx.restore();
  25851. this.processingType3 = null;
  25852. },
  25853. // Type3 fonts
  25854. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  25855. // We can safely ignore this since the width should be the same
  25856. // as the width in the Widths array.
  25857. },
  25858. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  25859. yWidth,
  25860. llx,
  25861. lly,
  25862. urx,
  25863. ury) {
  25864. // TODO According to the spec we're also suppose to ignore any operators
  25865. // that set color or include images while processing this type3 font.
  25866. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  25867. this.clip();
  25868. this.endPath();
  25869. },
  25870. // Color
  25871. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  25872. var pattern;
  25873. if (IR[0] === 'TilingPattern') {
  25874. var color = IR[1];
  25875. var baseTransform = this.baseTransform ||
  25876. this.ctx.mozCurrentTransform.slice();
  25877. var self = this;
  25878. var canvasGraphicsFactory = {
  25879. createCanvasGraphics: function (ctx) {
  25880. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  25881. }
  25882. };
  25883. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  25884. baseTransform);
  25885. } else {
  25886. pattern = getShadingPatternFromIR(IR);
  25887. }
  25888. return pattern;
  25889. },
  25890. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  25891. this.current.strokeColor = this.getColorN_Pattern(arguments);
  25892. },
  25893. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  25894. this.current.fillColor = this.getColorN_Pattern(arguments);
  25895. this.current.patternFill = true;
  25896. },
  25897. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  25898. var color = Util.makeCssRgb(r, g, b);
  25899. this.ctx.strokeStyle = color;
  25900. this.current.strokeColor = color;
  25901. },
  25902. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  25903. var color = Util.makeCssRgb(r, g, b);
  25904. this.ctx.fillStyle = color;
  25905. this.current.fillColor = color;
  25906. this.current.patternFill = false;
  25907. },
  25908. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  25909. var ctx = this.ctx;
  25910. this.save();
  25911. var pattern = getShadingPatternFromIR(patternIR);
  25912. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  25913. var inv = ctx.mozCurrentTransformInverse;
  25914. if (inv) {
  25915. var canvas = ctx.canvas;
  25916. var width = canvas.width;
  25917. var height = canvas.height;
  25918. var bl = Util.applyTransform([0, 0], inv);
  25919. var br = Util.applyTransform([0, height], inv);
  25920. var ul = Util.applyTransform([width, 0], inv);
  25921. var ur = Util.applyTransform([width, height], inv);
  25922. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  25923. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  25924. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  25925. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  25926. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  25927. } else {
  25928. // HACK to draw the gradient onto an infinite rectangle.
  25929. // PDF gradients are drawn across the entire image while
  25930. // Canvas only allows gradients to be drawn in a rectangle
  25931. // The following bug should allow us to remove this.
  25932. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  25933. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  25934. }
  25935. this.restore();
  25936. },
  25937. // Images
  25938. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  25939. error('Should not call beginInlineImage');
  25940. },
  25941. beginImageData: function CanvasGraphics_beginImageData() {
  25942. error('Should not call beginImageData');
  25943. },
  25944. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  25945. bbox) {
  25946. this.save();
  25947. this.baseTransformStack.push(this.baseTransform);
  25948. if (isArray(matrix) && 6 === matrix.length) {
  25949. this.transform.apply(this, matrix);
  25950. }
  25951. this.baseTransform = this.ctx.mozCurrentTransform;
  25952. if (isArray(bbox) && 4 === bbox.length) {
  25953. var width = bbox[2] - bbox[0];
  25954. var height = bbox[3] - bbox[1];
  25955. this.ctx.rect(bbox[0], bbox[1], width, height);
  25956. this.clip();
  25957. this.endPath();
  25958. }
  25959. },
  25960. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  25961. this.restore();
  25962. this.baseTransform = this.baseTransformStack.pop();
  25963. },
  25964. beginGroup: function CanvasGraphics_beginGroup(group) {
  25965. this.save();
  25966. var currentCtx = this.ctx;
  25967. // TODO non-isolated groups - according to Rik at adobe non-isolated
  25968. // group results aren't usually that different and they even have tools
  25969. // that ignore this setting. Notes from Rik on implmenting:
  25970. // - When you encounter an transparency group, create a new canvas with
  25971. // the dimensions of the bbox
  25972. // - copy the content from the previous canvas to the new canvas
  25973. // - draw as usual
  25974. // - remove the backdrop alpha:
  25975. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  25976. // value of your transparency group and 'alphaBackdrop' the alpha of the
  25977. // backdrop
  25978. // - remove background color:
  25979. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  25980. if (!group.isolated) {
  25981. info('TODO: Support non-isolated groups.');
  25982. }
  25983. // TODO knockout - supposedly possible with the clever use of compositing
  25984. // modes.
  25985. if (group.knockout) {
  25986. warn('Knockout groups not supported.');
  25987. }
  25988. var currentTransform = currentCtx.mozCurrentTransform;
  25989. if (group.matrix) {
  25990. currentCtx.transform.apply(currentCtx, group.matrix);
  25991. }
  25992. assert(group.bbox, 'Bounding box is required.');
  25993. // Based on the current transform figure out how big the bounding box
  25994. // will actually be.
  25995. var bounds = Util.getAxialAlignedBoundingBox(
  25996. group.bbox,
  25997. currentCtx.mozCurrentTransform);
  25998. // Clip the bounding box to the current canvas.
  25999. var canvasBounds = [0,
  26000. 0,
  26001. currentCtx.canvas.width,
  26002. currentCtx.canvas.height];
  26003. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  26004. // Use ceil in case we're between sizes so we don't create canvas that is
  26005. // too small and make the canvas at least 1x1 pixels.
  26006. var offsetX = Math.floor(bounds[0]);
  26007. var offsetY = Math.floor(bounds[1]);
  26008. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  26009. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  26010. var scaleX = 1, scaleY = 1;
  26011. if (drawnWidth > MAX_GROUP_SIZE) {
  26012. scaleX = drawnWidth / MAX_GROUP_SIZE;
  26013. drawnWidth = MAX_GROUP_SIZE;
  26014. }
  26015. if (drawnHeight > MAX_GROUP_SIZE) {
  26016. scaleY = drawnHeight / MAX_GROUP_SIZE;
  26017. drawnHeight = MAX_GROUP_SIZE;
  26018. }
  26019. var cacheId = 'groupAt' + this.groupLevel;
  26020. if (group.smask) {
  26021. // Using two cache entries is case if masks are used one after another.
  26022. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  26023. }
  26024. var scratchCanvas = this.cachedCanvases.getCanvas(
  26025. cacheId, drawnWidth, drawnHeight, true);
  26026. var groupCtx = scratchCanvas.context;
  26027. // Since we created a new canvas that is just the size of the bounding box
  26028. // we have to translate the group ctx.
  26029. groupCtx.scale(1 / scaleX, 1 / scaleY);
  26030. groupCtx.translate(-offsetX, -offsetY);
  26031. groupCtx.transform.apply(groupCtx, currentTransform);
  26032. if (group.smask) {
  26033. // Saving state and cached mask to be used in setGState.
  26034. this.smaskStack.push({
  26035. canvas: scratchCanvas.canvas,
  26036. context: groupCtx,
  26037. offsetX: offsetX,
  26038. offsetY: offsetY,
  26039. scaleX: scaleX,
  26040. scaleY: scaleY,
  26041. subtype: group.smask.subtype,
  26042. backdrop: group.smask.backdrop,
  26043. transferMap: group.smask.transferMap || null
  26044. });
  26045. } else {
  26046. // Setup the current ctx so when the group is popped we draw it at the
  26047. // right location.
  26048. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  26049. currentCtx.translate(offsetX, offsetY);
  26050. currentCtx.scale(scaleX, scaleY);
  26051. }
  26052. // The transparency group inherits all off the current graphics state
  26053. // except the blend mode, soft mask, and alpha constants.
  26054. copyCtxState(currentCtx, groupCtx);
  26055. this.ctx = groupCtx;
  26056. this.setGState([
  26057. ['BM', 'Normal'],
  26058. ['ca', 1],
  26059. ['CA', 1]
  26060. ]);
  26061. this.groupStack.push(currentCtx);
  26062. this.groupLevel++;
  26063. },
  26064. endGroup: function CanvasGraphics_endGroup(group) {
  26065. this.groupLevel--;
  26066. var groupCtx = this.ctx;
  26067. this.ctx = this.groupStack.pop();
  26068. // Turn off image smoothing to avoid sub pixel interpolation which can
  26069. // look kind of blurry for some pdfs.
  26070. if (this.ctx.imageSmoothingEnabled !== undefined) {
  26071. this.ctx.imageSmoothingEnabled = false;
  26072. } else {
  26073. this.ctx.mozImageSmoothingEnabled = false;
  26074. }
  26075. if (group.smask) {
  26076. this.tempSMask = this.smaskStack.pop();
  26077. } else {
  26078. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  26079. }
  26080. this.restore();
  26081. },
  26082. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  26083. this.save();
  26084. this.current = new CanvasExtraState();
  26085. if (this.baseTransform) {
  26086. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  26087. }
  26088. },
  26089. endAnnotations: function CanvasGraphics_endAnnotations() {
  26090. this.restore();
  26091. },
  26092. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  26093. matrix) {
  26094. this.save();
  26095. if (isArray(rect) && 4 === rect.length) {
  26096. var width = rect[2] - rect[0];
  26097. var height = rect[3] - rect[1];
  26098. this.ctx.rect(rect[0], rect[1], width, height);
  26099. this.clip();
  26100. this.endPath();
  26101. }
  26102. this.transform.apply(this, transform);
  26103. this.transform.apply(this, matrix);
  26104. },
  26105. endAnnotation: function CanvasGraphics_endAnnotation() {
  26106. this.restore();
  26107. },
  26108. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  26109. var domImage = this.objs.get(objId);
  26110. if (!domImage) {
  26111. warn('Dependent image isn\'t ready yet');
  26112. return;
  26113. }
  26114. this.save();
  26115. var ctx = this.ctx;
  26116. // scale the image to the unit square
  26117. ctx.scale(1 / w, -1 / h);
  26118. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  26119. 0, -h, w, h);
  26120. if (this.imageLayer) {
  26121. var currentTransform = ctx.mozCurrentTransformInverse;
  26122. var position = this.getCanvasPosition(0, 0);
  26123. this.imageLayer.appendImage({
  26124. objId: objId,
  26125. left: position[0],
  26126. top: position[1],
  26127. width: w / currentTransform[0],
  26128. height: h / currentTransform[3]
  26129. });
  26130. }
  26131. this.restore();
  26132. },
  26133. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  26134. var ctx = this.ctx;
  26135. var width = img.width, height = img.height;
  26136. var fillColor = this.current.fillColor;
  26137. var isPatternFill = this.current.patternFill;
  26138. var glyph = this.processingType3;
  26139. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  26140. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  26141. glyph.compiled =
  26142. compileType3Glyph({data: img.data, width: width, height: height});
  26143. } else {
  26144. glyph.compiled = null;
  26145. }
  26146. }
  26147. if (glyph && glyph.compiled) {
  26148. glyph.compiled(ctx);
  26149. return;
  26150. }
  26151. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  26152. width, height);
  26153. var maskCtx = maskCanvas.context;
  26154. maskCtx.save();
  26155. putBinaryImageMask(maskCtx, img);
  26156. maskCtx.globalCompositeOperation = 'source-in';
  26157. maskCtx.fillStyle = isPatternFill ?
  26158. fillColor.getPattern(maskCtx, this) : fillColor;
  26159. maskCtx.fillRect(0, 0, width, height);
  26160. maskCtx.restore();
  26161. this.paintInlineImageXObject(maskCanvas.canvas);
  26162. },
  26163. paintImageMaskXObjectRepeat:
  26164. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  26165. scaleY, positions) {
  26166. var width = imgData.width;
  26167. var height = imgData.height;
  26168. var fillColor = this.current.fillColor;
  26169. var isPatternFill = this.current.patternFill;
  26170. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  26171. width, height);
  26172. var maskCtx = maskCanvas.context;
  26173. maskCtx.save();
  26174. putBinaryImageMask(maskCtx, imgData);
  26175. maskCtx.globalCompositeOperation = 'source-in';
  26176. maskCtx.fillStyle = isPatternFill ?
  26177. fillColor.getPattern(maskCtx, this) : fillColor;
  26178. maskCtx.fillRect(0, 0, width, height);
  26179. maskCtx.restore();
  26180. var ctx = this.ctx;
  26181. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  26182. ctx.save();
  26183. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  26184. ctx.scale(1, -1);
  26185. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  26186. 0, -1, 1, 1);
  26187. ctx.restore();
  26188. }
  26189. },
  26190. paintImageMaskXObjectGroup:
  26191. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  26192. var ctx = this.ctx;
  26193. var fillColor = this.current.fillColor;
  26194. var isPatternFill = this.current.patternFill;
  26195. for (var i = 0, ii = images.length; i < ii; i++) {
  26196. var image = images[i];
  26197. var width = image.width, height = image.height;
  26198. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  26199. width, height);
  26200. var maskCtx = maskCanvas.context;
  26201. maskCtx.save();
  26202. putBinaryImageMask(maskCtx, image);
  26203. maskCtx.globalCompositeOperation = 'source-in';
  26204. maskCtx.fillStyle = isPatternFill ?
  26205. fillColor.getPattern(maskCtx, this) : fillColor;
  26206. maskCtx.fillRect(0, 0, width, height);
  26207. maskCtx.restore();
  26208. ctx.save();
  26209. ctx.transform.apply(ctx, image.transform);
  26210. ctx.scale(1, -1);
  26211. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  26212. 0, -1, 1, 1);
  26213. ctx.restore();
  26214. }
  26215. },
  26216. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  26217. var imgData = this.objs.get(objId);
  26218. if (!imgData) {
  26219. warn('Dependent image isn\'t ready yet');
  26220. return;
  26221. }
  26222. this.paintInlineImageXObject(imgData);
  26223. },
  26224. paintImageXObjectRepeat:
  26225. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  26226. positions) {
  26227. var imgData = this.objs.get(objId);
  26228. if (!imgData) {
  26229. warn('Dependent image isn\'t ready yet');
  26230. return;
  26231. }
  26232. var width = imgData.width;
  26233. var height = imgData.height;
  26234. var map = [];
  26235. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  26236. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  26237. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  26238. }
  26239. this.paintInlineImageXObjectGroup(imgData, map);
  26240. },
  26241. paintInlineImageXObject:
  26242. function CanvasGraphics_paintInlineImageXObject(imgData) {
  26243. var width = imgData.width;
  26244. var height = imgData.height;
  26245. var ctx = this.ctx;
  26246. this.save();
  26247. // scale the image to the unit square
  26248. ctx.scale(1 / width, -1 / height);
  26249. var currentTransform = ctx.mozCurrentTransformInverse;
  26250. var a = currentTransform[0], b = currentTransform[1];
  26251. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  26252. var c = currentTransform[2], d = currentTransform[3];
  26253. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  26254. var imgToPaint, tmpCanvas;
  26255. // instanceof HTMLElement does not work in jsdom node.js module
  26256. if (imgData instanceof HTMLElement || !imgData.data) {
  26257. imgToPaint = imgData;
  26258. } else {
  26259. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  26260. width, height);
  26261. var tmpCtx = tmpCanvas.context;
  26262. putBinaryImageData(tmpCtx, imgData);
  26263. imgToPaint = tmpCanvas.canvas;
  26264. }
  26265. var paintWidth = width, paintHeight = height;
  26266. var tmpCanvasId = 'prescale1';
  26267. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  26268. // pixels during drawImage operation, painting on the temporary canvas(es)
  26269. // that are twice smaller in size
  26270. while ((widthScale > 2 && paintWidth > 1) ||
  26271. (heightScale > 2 && paintHeight > 1)) {
  26272. var newWidth = paintWidth, newHeight = paintHeight;
  26273. if (widthScale > 2 && paintWidth > 1) {
  26274. newWidth = Math.ceil(paintWidth / 2);
  26275. widthScale /= paintWidth / newWidth;
  26276. }
  26277. if (heightScale > 2 && paintHeight > 1) {
  26278. newHeight = Math.ceil(paintHeight / 2);
  26279. heightScale /= paintHeight / newHeight;
  26280. }
  26281. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  26282. newWidth, newHeight);
  26283. tmpCtx = tmpCanvas.context;
  26284. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  26285. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  26286. 0, 0, newWidth, newHeight);
  26287. imgToPaint = tmpCanvas.canvas;
  26288. paintWidth = newWidth;
  26289. paintHeight = newHeight;
  26290. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  26291. }
  26292. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  26293. 0, -height, width, height);
  26294. if (this.imageLayer) {
  26295. var position = this.getCanvasPosition(0, -height);
  26296. this.imageLayer.appendImage({
  26297. imgData: imgData,
  26298. left: position[0],
  26299. top: position[1],
  26300. width: width / currentTransform[0],
  26301. height: height / currentTransform[3]
  26302. });
  26303. }
  26304. this.restore();
  26305. },
  26306. paintInlineImageXObjectGroup:
  26307. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  26308. var ctx = this.ctx;
  26309. var w = imgData.width;
  26310. var h = imgData.height;
  26311. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  26312. var tmpCtx = tmpCanvas.context;
  26313. putBinaryImageData(tmpCtx, imgData);
  26314. for (var i = 0, ii = map.length; i < ii; i++) {
  26315. var entry = map[i];
  26316. ctx.save();
  26317. ctx.transform.apply(ctx, entry.transform);
  26318. ctx.scale(1, -1);
  26319. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  26320. 0, -1, 1, 1);
  26321. if (this.imageLayer) {
  26322. var position = this.getCanvasPosition(entry.x, entry.y);
  26323. this.imageLayer.appendImage({
  26324. imgData: imgData,
  26325. left: position[0],
  26326. top: position[1],
  26327. width: w,
  26328. height: h
  26329. });
  26330. }
  26331. ctx.restore();
  26332. }
  26333. },
  26334. paintSolidColorImageMask:
  26335. function CanvasGraphics_paintSolidColorImageMask() {
  26336. this.ctx.fillRect(0, 0, 1, 1);
  26337. },
  26338. paintXObject: function CanvasGraphics_paintXObject() {
  26339. warn('Unsupported \'paintXObject\' command.');
  26340. },
  26341. // Marked content
  26342. markPoint: function CanvasGraphics_markPoint(tag) {
  26343. // TODO Marked content.
  26344. },
  26345. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  26346. // TODO Marked content.
  26347. },
  26348. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  26349. // TODO Marked content.
  26350. },
  26351. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  26352. tag, properties) {
  26353. // TODO Marked content.
  26354. },
  26355. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  26356. // TODO Marked content.
  26357. },
  26358. // Compatibility
  26359. beginCompat: function CanvasGraphics_beginCompat() {
  26360. // TODO ignore undefined operators (should we do that anyway?)
  26361. },
  26362. endCompat: function CanvasGraphics_endCompat() {
  26363. // TODO stop ignoring undefined operators
  26364. },
  26365. // Helper functions
  26366. consumePath: function CanvasGraphics_consumePath() {
  26367. var ctx = this.ctx;
  26368. if (this.pendingClip) {
  26369. if (this.pendingClip === EO_CLIP) {
  26370. if (ctx.mozFillRule !== undefined) {
  26371. ctx.mozFillRule = 'evenodd';
  26372. ctx.clip();
  26373. ctx.mozFillRule = 'nonzero';
  26374. } else {
  26375. ctx.clip('evenodd');
  26376. }
  26377. } else {
  26378. ctx.clip();
  26379. }
  26380. this.pendingClip = null;
  26381. }
  26382. ctx.beginPath();
  26383. },
  26384. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  26385. if (this.cachedGetSinglePixelWidth === null) {
  26386. var inverse = this.ctx.mozCurrentTransformInverse;
  26387. // max of the current horizontal and vertical scale
  26388. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  26389. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  26390. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  26391. }
  26392. return this.cachedGetSinglePixelWidth;
  26393. },
  26394. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  26395. var transform = this.ctx.mozCurrentTransform;
  26396. return [
  26397. transform[0] * x + transform[2] * y + transform[4],
  26398. transform[1] * x + transform[3] * y + transform[5]
  26399. ];
  26400. }
  26401. };
  26402. for (var op in OPS) {
  26403. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  26404. }
  26405. return CanvasGraphics;
  26406. })();
  26407. exports.CanvasGraphics = CanvasGraphics;
  26408. exports.createScratchCanvas = createScratchCanvas;
  26409. }));
  26410. (function (root, factory) {
  26411. {
  26412. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  26413. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  26414. }
  26415. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  26416. var Util = sharedUtil.Util;
  26417. var assert = sharedUtil.assert;
  26418. var error = sharedUtil.error;
  26419. var isInt = sharedUtil.isInt;
  26420. var isString = sharedUtil.isString;
  26421. var warn = sharedUtil.warn;
  26422. var isName = corePrimitives.isName;
  26423. var isCmd = corePrimitives.isCmd;
  26424. var isStream = corePrimitives.isStream;
  26425. var StringStream = coreStream.StringStream;
  26426. var Lexer = coreParser.Lexer;
  26427. var isEOF = coreParser.isEOF;
  26428. var BUILT_IN_CMAPS = [
  26429. // << Start unicode maps.
  26430. 'Adobe-GB1-UCS2',
  26431. 'Adobe-CNS1-UCS2',
  26432. 'Adobe-Japan1-UCS2',
  26433. 'Adobe-Korea1-UCS2',
  26434. // >> End unicode maps.
  26435. '78-EUC-H',
  26436. '78-EUC-V',
  26437. '78-H',
  26438. '78-RKSJ-H',
  26439. '78-RKSJ-V',
  26440. '78-V',
  26441. '78ms-RKSJ-H',
  26442. '78ms-RKSJ-V',
  26443. '83pv-RKSJ-H',
  26444. '90ms-RKSJ-H',
  26445. '90ms-RKSJ-V',
  26446. '90msp-RKSJ-H',
  26447. '90msp-RKSJ-V',
  26448. '90pv-RKSJ-H',
  26449. '90pv-RKSJ-V',
  26450. 'Add-H',
  26451. 'Add-RKSJ-H',
  26452. 'Add-RKSJ-V',
  26453. 'Add-V',
  26454. 'Adobe-CNS1-0',
  26455. 'Adobe-CNS1-1',
  26456. 'Adobe-CNS1-2',
  26457. 'Adobe-CNS1-3',
  26458. 'Adobe-CNS1-4',
  26459. 'Adobe-CNS1-5',
  26460. 'Adobe-CNS1-6',
  26461. 'Adobe-GB1-0',
  26462. 'Adobe-GB1-1',
  26463. 'Adobe-GB1-2',
  26464. 'Adobe-GB1-3',
  26465. 'Adobe-GB1-4',
  26466. 'Adobe-GB1-5',
  26467. 'Adobe-Japan1-0',
  26468. 'Adobe-Japan1-1',
  26469. 'Adobe-Japan1-2',
  26470. 'Adobe-Japan1-3',
  26471. 'Adobe-Japan1-4',
  26472. 'Adobe-Japan1-5',
  26473. 'Adobe-Japan1-6',
  26474. 'Adobe-Korea1-0',
  26475. 'Adobe-Korea1-1',
  26476. 'Adobe-Korea1-2',
  26477. 'B5-H',
  26478. 'B5-V',
  26479. 'B5pc-H',
  26480. 'B5pc-V',
  26481. 'CNS-EUC-H',
  26482. 'CNS-EUC-V',
  26483. 'CNS1-H',
  26484. 'CNS1-V',
  26485. 'CNS2-H',
  26486. 'CNS2-V',
  26487. 'ETHK-B5-H',
  26488. 'ETHK-B5-V',
  26489. 'ETen-B5-H',
  26490. 'ETen-B5-V',
  26491. 'ETenms-B5-H',
  26492. 'ETenms-B5-V',
  26493. 'EUC-H',
  26494. 'EUC-V',
  26495. 'Ext-H',
  26496. 'Ext-RKSJ-H',
  26497. 'Ext-RKSJ-V',
  26498. 'Ext-V',
  26499. 'GB-EUC-H',
  26500. 'GB-EUC-V',
  26501. 'GB-H',
  26502. 'GB-V',
  26503. 'GBK-EUC-H',
  26504. 'GBK-EUC-V',
  26505. 'GBK2K-H',
  26506. 'GBK2K-V',
  26507. 'GBKp-EUC-H',
  26508. 'GBKp-EUC-V',
  26509. 'GBT-EUC-H',
  26510. 'GBT-EUC-V',
  26511. 'GBT-H',
  26512. 'GBT-V',
  26513. 'GBTpc-EUC-H',
  26514. 'GBTpc-EUC-V',
  26515. 'GBpc-EUC-H',
  26516. 'GBpc-EUC-V',
  26517. 'H',
  26518. 'HKdla-B5-H',
  26519. 'HKdla-B5-V',
  26520. 'HKdlb-B5-H',
  26521. 'HKdlb-B5-V',
  26522. 'HKgccs-B5-H',
  26523. 'HKgccs-B5-V',
  26524. 'HKm314-B5-H',
  26525. 'HKm314-B5-V',
  26526. 'HKm471-B5-H',
  26527. 'HKm471-B5-V',
  26528. 'HKscs-B5-H',
  26529. 'HKscs-B5-V',
  26530. 'Hankaku',
  26531. 'Hiragana',
  26532. 'KSC-EUC-H',
  26533. 'KSC-EUC-V',
  26534. 'KSC-H',
  26535. 'KSC-Johab-H',
  26536. 'KSC-Johab-V',
  26537. 'KSC-V',
  26538. 'KSCms-UHC-H',
  26539. 'KSCms-UHC-HW-H',
  26540. 'KSCms-UHC-HW-V',
  26541. 'KSCms-UHC-V',
  26542. 'KSCpc-EUC-H',
  26543. 'KSCpc-EUC-V',
  26544. 'Katakana',
  26545. 'NWP-H',
  26546. 'NWP-V',
  26547. 'RKSJ-H',
  26548. 'RKSJ-V',
  26549. 'Roman',
  26550. 'UniCNS-UCS2-H',
  26551. 'UniCNS-UCS2-V',
  26552. 'UniCNS-UTF16-H',
  26553. 'UniCNS-UTF16-V',
  26554. 'UniCNS-UTF32-H',
  26555. 'UniCNS-UTF32-V',
  26556. 'UniCNS-UTF8-H',
  26557. 'UniCNS-UTF8-V',
  26558. 'UniGB-UCS2-H',
  26559. 'UniGB-UCS2-V',
  26560. 'UniGB-UTF16-H',
  26561. 'UniGB-UTF16-V',
  26562. 'UniGB-UTF32-H',
  26563. 'UniGB-UTF32-V',
  26564. 'UniGB-UTF8-H',
  26565. 'UniGB-UTF8-V',
  26566. 'UniJIS-UCS2-H',
  26567. 'UniJIS-UCS2-HW-H',
  26568. 'UniJIS-UCS2-HW-V',
  26569. 'UniJIS-UCS2-V',
  26570. 'UniJIS-UTF16-H',
  26571. 'UniJIS-UTF16-V',
  26572. 'UniJIS-UTF32-H',
  26573. 'UniJIS-UTF32-V',
  26574. 'UniJIS-UTF8-H',
  26575. 'UniJIS-UTF8-V',
  26576. 'UniJIS2004-UTF16-H',
  26577. 'UniJIS2004-UTF16-V',
  26578. 'UniJIS2004-UTF32-H',
  26579. 'UniJIS2004-UTF32-V',
  26580. 'UniJIS2004-UTF8-H',
  26581. 'UniJIS2004-UTF8-V',
  26582. 'UniJISPro-UCS2-HW-V',
  26583. 'UniJISPro-UCS2-V',
  26584. 'UniJISPro-UTF8-V',
  26585. 'UniJISX0213-UTF32-H',
  26586. 'UniJISX0213-UTF32-V',
  26587. 'UniJISX02132004-UTF32-H',
  26588. 'UniJISX02132004-UTF32-V',
  26589. 'UniKS-UCS2-H',
  26590. 'UniKS-UCS2-V',
  26591. 'UniKS-UTF16-H',
  26592. 'UniKS-UTF16-V',
  26593. 'UniKS-UTF32-H',
  26594. 'UniKS-UTF32-V',
  26595. 'UniKS-UTF8-H',
  26596. 'UniKS-UTF8-V',
  26597. 'V',
  26598. 'WP-Symbol'];
  26599. // CMap, not to be confused with TrueType's cmap.
  26600. var CMap = (function CMapClosure() {
  26601. function CMap(builtInCMap) {
  26602. // Codespace ranges are stored as follows:
  26603. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  26604. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  26605. this.codespaceRanges = [[], [], [], []];
  26606. this.numCodespaceRanges = 0;
  26607. // Map entries have one of two forms.
  26608. // - cid chars are 16-bit unsigned integers, stored as integers.
  26609. // - bf chars are variable-length byte sequences, stored as strings, with
  26610. // one byte per character.
  26611. this._map = [];
  26612. this.name = '';
  26613. this.vertical = false;
  26614. this.useCMap = null;
  26615. this.builtInCMap = builtInCMap;
  26616. }
  26617. CMap.prototype = {
  26618. addCodespaceRange: function(n, low, high) {
  26619. this.codespaceRanges[n - 1].push(low, high);
  26620. this.numCodespaceRanges++;
  26621. },
  26622. mapCidRange: function(low, high, dstLow) {
  26623. while (low <= high) {
  26624. this._map[low++] = dstLow++;
  26625. }
  26626. },
  26627. mapBfRange: function(low, high, dstLow) {
  26628. var lastByte = dstLow.length - 1;
  26629. while (low <= high) {
  26630. this._map[low++] = dstLow;
  26631. // Only the last byte has to be incremented.
  26632. dstLow = dstLow.substr(0, lastByte) +
  26633. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  26634. }
  26635. },
  26636. mapBfRangeToArray: function(low, high, array) {
  26637. var i = 0, ii = array.length;
  26638. while (low <= high && i < ii) {
  26639. this._map[low] = array[i++];
  26640. ++low;
  26641. }
  26642. },
  26643. // This is used for both bf and cid chars.
  26644. mapOne: function(src, dst) {
  26645. this._map[src] = dst;
  26646. },
  26647. lookup: function(code) {
  26648. return this._map[code];
  26649. },
  26650. contains: function(code) {
  26651. return this._map[code] !== undefined;
  26652. },
  26653. forEach: function(callback) {
  26654. // Most maps have fewer than 65536 entries, and for those we use normal
  26655. // array iteration. But really sparse tables are possible -- e.g. with
  26656. // indices in the *billions*. For such tables we use for..in, which isn't
  26657. // ideal because it stringifies the indices for all present elements, but
  26658. // it does avoid iterating over every undefined entry.
  26659. var map = this._map;
  26660. var length = map.length;
  26661. var i;
  26662. if (length <= 0x10000) {
  26663. for (i = 0; i < length; i++) {
  26664. if (map[i] !== undefined) {
  26665. callback(i, map[i]);
  26666. }
  26667. }
  26668. } else {
  26669. for (i in this._map) {
  26670. callback(i, map[i]);
  26671. }
  26672. }
  26673. },
  26674. charCodeOf: function(value) {
  26675. return this._map.indexOf(value);
  26676. },
  26677. getMap: function() {
  26678. return this._map;
  26679. },
  26680. readCharCode: function(str, offset, out) {
  26681. var c = 0;
  26682. var codespaceRanges = this.codespaceRanges;
  26683. var codespaceRangesLen = this.codespaceRanges.length;
  26684. // 9.7.6.2 CMap Mapping
  26685. // The code length is at most 4.
  26686. for (var n = 0; n < codespaceRangesLen; n++) {
  26687. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  26688. // Check each codespace range to see if it falls within.
  26689. var codespaceRange = codespaceRanges[n];
  26690. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  26691. var low = codespaceRange[k++];
  26692. var high = codespaceRange[k++];
  26693. if (c >= low && c <= high) {
  26694. out.charcode = c;
  26695. out.length = n + 1;
  26696. return;
  26697. }
  26698. }
  26699. }
  26700. out.charcode = 0;
  26701. out.length = 1;
  26702. },
  26703. get length() {
  26704. return this._map.length;
  26705. },
  26706. get isIdentityCMap() {
  26707. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  26708. return false;
  26709. }
  26710. if (this._map.length !== 0x10000) {
  26711. return false;
  26712. }
  26713. for (var i = 0; i < 0x10000; i++) {
  26714. if (this._map[i] !== i) {
  26715. return false;
  26716. }
  26717. }
  26718. return true;
  26719. }
  26720. };
  26721. return CMap;
  26722. })();
  26723. // A special case of CMap, where the _map array implicitly has a length of
  26724. // 65536 and each element is equal to its index.
  26725. var IdentityCMap = (function IdentityCMapClosure() {
  26726. function IdentityCMap(vertical, n) {
  26727. CMap.call(this);
  26728. this.vertical = vertical;
  26729. this.addCodespaceRange(n, 0, 0xffff);
  26730. }
  26731. Util.inherit(IdentityCMap, CMap, {});
  26732. IdentityCMap.prototype = {
  26733. addCodespaceRange: CMap.prototype.addCodespaceRange,
  26734. mapCidRange: function(low, high, dstLow) {
  26735. error('should not call mapCidRange');
  26736. },
  26737. mapBfRange: function(low, high, dstLow) {
  26738. error('should not call mapBfRange');
  26739. },
  26740. mapBfRangeToArray: function(low, high, array) {
  26741. error('should not call mapBfRangeToArray');
  26742. },
  26743. mapOne: function(src, dst) {
  26744. error('should not call mapCidOne');
  26745. },
  26746. lookup: function(code) {
  26747. return (isInt(code) && code <= 0xffff) ? code : undefined;
  26748. },
  26749. contains: function(code) {
  26750. return isInt(code) && code <= 0xffff;
  26751. },
  26752. forEach: function(callback) {
  26753. for (var i = 0; i <= 0xffff; i++) {
  26754. callback(i, i);
  26755. }
  26756. },
  26757. charCodeOf: function(value) {
  26758. return (isInt(value) && value <= 0xffff) ? value : -1;
  26759. },
  26760. getMap: function() {
  26761. // Sometimes identity maps must be instantiated, but it's rare.
  26762. var map = new Array(0x10000);
  26763. for (var i = 0; i <= 0xffff; i++) {
  26764. map[i] = i;
  26765. }
  26766. return map;
  26767. },
  26768. readCharCode: CMap.prototype.readCharCode,
  26769. get length() {
  26770. return 0x10000;
  26771. },
  26772. get isIdentityCMap() {
  26773. error('should not access .isIdentityCMap');
  26774. }
  26775. };
  26776. return IdentityCMap;
  26777. })();
  26778. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  26779. function fetchBinaryData(url) {
  26780. var nonBinaryRequest = PDFJS.disableWorker;
  26781. var request = new XMLHttpRequest();
  26782. request.open('GET', url, false);
  26783. if (!nonBinaryRequest) {
  26784. try {
  26785. request.responseType = 'arraybuffer';
  26786. nonBinaryRequest = request.responseType !== 'arraybuffer';
  26787. } catch (e) {
  26788. nonBinaryRequest = true;
  26789. }
  26790. }
  26791. if (nonBinaryRequest && request.overrideMimeType) {
  26792. request.overrideMimeType('text/plain; charset=x-user-defined');
  26793. }
  26794. request.send(null);
  26795. if (nonBinaryRequest ? !request.responseText : !request.response) {
  26796. error('Unable to get binary cMap at: ' + url);
  26797. }
  26798. if (nonBinaryRequest) {
  26799. var data = Array.prototype.map.call(request.responseText, function (ch) {
  26800. return ch.charCodeAt(0) & 255;
  26801. });
  26802. return new Uint8Array(data);
  26803. }
  26804. return new Uint8Array(request.response);
  26805. }
  26806. function hexToInt(a, size) {
  26807. var n = 0;
  26808. for (var i = 0; i <= size; i++) {
  26809. n = (n << 8) | a[i];
  26810. }
  26811. return n >>> 0;
  26812. }
  26813. function hexToStr(a, size) {
  26814. // This code is hot. Special-case some common values to avoid creating an
  26815. // object with subarray().
  26816. if (size === 1) {
  26817. return String.fromCharCode(a[0], a[1]);
  26818. }
  26819. if (size === 3) {
  26820. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  26821. }
  26822. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  26823. }
  26824. function addHex(a, b, size) {
  26825. var c = 0;
  26826. for (var i = size; i >= 0; i--) {
  26827. c += a[i] + b[i];
  26828. a[i] = c & 255;
  26829. c >>= 8;
  26830. }
  26831. }
  26832. function incHex(a, size) {
  26833. var c = 1;
  26834. for (var i = size; i >= 0 && c > 0; i--) {
  26835. c += a[i];
  26836. a[i] = c & 255;
  26837. c >>= 8;
  26838. }
  26839. }
  26840. var MAX_NUM_SIZE = 16;
  26841. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  26842. function BinaryCMapStream(data) {
  26843. this.buffer = data;
  26844. this.pos = 0;
  26845. this.end = data.length;
  26846. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  26847. }
  26848. BinaryCMapStream.prototype = {
  26849. readByte: function () {
  26850. if (this.pos >= this.end) {
  26851. return -1;
  26852. }
  26853. return this.buffer[this.pos++];
  26854. },
  26855. readNumber: function () {
  26856. var n = 0;
  26857. var last;
  26858. do {
  26859. var b = this.readByte();
  26860. if (b < 0) {
  26861. error('unexpected EOF in bcmap');
  26862. }
  26863. last = !(b & 0x80);
  26864. n = (n << 7) | (b & 0x7F);
  26865. } while (!last);
  26866. return n;
  26867. },
  26868. readSigned: function () {
  26869. var n = this.readNumber();
  26870. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  26871. },
  26872. readHex: function (num, size) {
  26873. num.set(this.buffer.subarray(this.pos,
  26874. this.pos + size + 1));
  26875. this.pos += size + 1;
  26876. },
  26877. readHexNumber: function (num, size) {
  26878. var last;
  26879. var stack = this.tmpBuf, sp = 0;
  26880. do {
  26881. var b = this.readByte();
  26882. if (b < 0) {
  26883. error('unexpected EOF in bcmap');
  26884. }
  26885. last = !(b & 0x80);
  26886. stack[sp++] = b & 0x7F;
  26887. } while (!last);
  26888. var i = size, buffer = 0, bufferSize = 0;
  26889. while (i >= 0) {
  26890. while (bufferSize < 8 && stack.length > 0) {
  26891. buffer = (stack[--sp] << bufferSize) | buffer;
  26892. bufferSize += 7;
  26893. }
  26894. num[i] = buffer & 255;
  26895. i--;
  26896. buffer >>= 8;
  26897. bufferSize -= 8;
  26898. }
  26899. },
  26900. readHexSigned: function (num, size) {
  26901. this.readHexNumber(num, size);
  26902. var sign = num[size] & 1 ? 255 : 0;
  26903. var c = 0;
  26904. for (var i = 0; i <= size; i++) {
  26905. c = ((c & 1) << 8) | num[i];
  26906. num[i] = (c >> 1) ^ sign;
  26907. }
  26908. },
  26909. readString: function () {
  26910. var len = this.readNumber();
  26911. var s = '';
  26912. for (var i = 0; i < len; i++) {
  26913. s += String.fromCharCode(this.readNumber());
  26914. }
  26915. return s;
  26916. }
  26917. };
  26918. function processBinaryCMap(url, cMap, extend) {
  26919. var data = fetchBinaryData(url);
  26920. var stream = new BinaryCMapStream(data);
  26921. var header = stream.readByte();
  26922. cMap.vertical = !!(header & 1);
  26923. var useCMap = null;
  26924. var start = new Uint8Array(MAX_NUM_SIZE);
  26925. var end = new Uint8Array(MAX_NUM_SIZE);
  26926. var char = new Uint8Array(MAX_NUM_SIZE);
  26927. var charCode = new Uint8Array(MAX_NUM_SIZE);
  26928. var tmp = new Uint8Array(MAX_NUM_SIZE);
  26929. var code;
  26930. var b;
  26931. while ((b = stream.readByte()) >= 0) {
  26932. var type = b >> 5;
  26933. if (type === 7) { // metadata, e.g. comment or usecmap
  26934. switch (b & 0x1F) {
  26935. case 0:
  26936. stream.readString(); // skipping comment
  26937. break;
  26938. case 1:
  26939. useCMap = stream.readString();
  26940. break;
  26941. }
  26942. continue;
  26943. }
  26944. var sequence = !!(b & 0x10);
  26945. var dataSize = b & 15;
  26946. assert(dataSize + 1 <= MAX_NUM_SIZE);
  26947. var ucs2DataSize = 1;
  26948. var subitemsCount = stream.readNumber();
  26949. var i;
  26950. switch (type) {
  26951. case 0: // codespacerange
  26952. stream.readHex(start, dataSize);
  26953. stream.readHexNumber(end, dataSize);
  26954. addHex(end, start, dataSize);
  26955. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26956. hexToInt(end, dataSize));
  26957. for (i = 1; i < subitemsCount; i++) {
  26958. incHex(end, dataSize);
  26959. stream.readHexNumber(start, dataSize);
  26960. addHex(start, end, dataSize);
  26961. stream.readHexNumber(end, dataSize);
  26962. addHex(end, start, dataSize);
  26963. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26964. hexToInt(end, dataSize));
  26965. }
  26966. break;
  26967. case 1: // notdefrange
  26968. stream.readHex(start, dataSize);
  26969. stream.readHexNumber(end, dataSize);
  26970. addHex(end, start, dataSize);
  26971. code = stream.readNumber();
  26972. // undefined range, skipping
  26973. for (i = 1; i < subitemsCount; i++) {
  26974. incHex(end, dataSize);
  26975. stream.readHexNumber(start, dataSize);
  26976. addHex(start, end, dataSize);
  26977. stream.readHexNumber(end, dataSize);
  26978. addHex(end, start, dataSize);
  26979. code = stream.readNumber();
  26980. // nop
  26981. }
  26982. break;
  26983. case 2: // cidchar
  26984. stream.readHex(char, dataSize);
  26985. code = stream.readNumber();
  26986. cMap.mapOne(hexToInt(char, dataSize), code);
  26987. for (i = 1; i < subitemsCount; i++) {
  26988. incHex(char, dataSize);
  26989. if (!sequence) {
  26990. stream.readHexNumber(tmp, dataSize);
  26991. addHex(char, tmp, dataSize);
  26992. }
  26993. code = stream.readSigned() + (code + 1);
  26994. cMap.mapOne(hexToInt(char, dataSize), code);
  26995. }
  26996. break;
  26997. case 3: // cidrange
  26998. stream.readHex(start, dataSize);
  26999. stream.readHexNumber(end, dataSize);
  27000. addHex(end, start, dataSize);
  27001. code = stream.readNumber();
  27002. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  27003. code);
  27004. for (i = 1; i < subitemsCount; i++) {
  27005. incHex(end, dataSize);
  27006. if (!sequence) {
  27007. stream.readHexNumber(start, dataSize);
  27008. addHex(start, end, dataSize);
  27009. } else {
  27010. start.set(end);
  27011. }
  27012. stream.readHexNumber(end, dataSize);
  27013. addHex(end, start, dataSize);
  27014. code = stream.readNumber();
  27015. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  27016. code);
  27017. }
  27018. break;
  27019. case 4: // bfchar
  27020. stream.readHex(char, ucs2DataSize);
  27021. stream.readHex(charCode, dataSize);
  27022. cMap.mapOne(hexToInt(char, ucs2DataSize),
  27023. hexToStr(charCode, dataSize));
  27024. for (i = 1; i < subitemsCount; i++) {
  27025. incHex(char, ucs2DataSize);
  27026. if (!sequence) {
  27027. stream.readHexNumber(tmp, ucs2DataSize);
  27028. addHex(char, tmp, ucs2DataSize);
  27029. }
  27030. incHex(charCode, dataSize);
  27031. stream.readHexSigned(tmp, dataSize);
  27032. addHex(charCode, tmp, dataSize);
  27033. cMap.mapOne(hexToInt(char, ucs2DataSize),
  27034. hexToStr(charCode, dataSize));
  27035. }
  27036. break;
  27037. case 5: // bfrange
  27038. stream.readHex(start, ucs2DataSize);
  27039. stream.readHexNumber(end, ucs2DataSize);
  27040. addHex(end, start, ucs2DataSize);
  27041. stream.readHex(charCode, dataSize);
  27042. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  27043. hexToInt(end, ucs2DataSize),
  27044. hexToStr(charCode, dataSize));
  27045. for (i = 1; i < subitemsCount; i++) {
  27046. incHex(end, ucs2DataSize);
  27047. if (!sequence) {
  27048. stream.readHexNumber(start, ucs2DataSize);
  27049. addHex(start, end, ucs2DataSize);
  27050. } else {
  27051. start.set(end);
  27052. }
  27053. stream.readHexNumber(end, ucs2DataSize);
  27054. addHex(end, start, ucs2DataSize);
  27055. stream.readHex(charCode, dataSize);
  27056. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  27057. hexToInt(end, ucs2DataSize),
  27058. hexToStr(charCode, dataSize));
  27059. }
  27060. break;
  27061. default:
  27062. error('Unknown type: ' + type);
  27063. break;
  27064. }
  27065. }
  27066. if (useCMap) {
  27067. extend(useCMap);
  27068. }
  27069. return cMap;
  27070. }
  27071. function BinaryCMapReader() {}
  27072. BinaryCMapReader.prototype = {
  27073. read: processBinaryCMap
  27074. };
  27075. return BinaryCMapReader;
  27076. })();
  27077. var CMapFactory = (function CMapFactoryClosure() {
  27078. function strToInt(str) {
  27079. var a = 0;
  27080. for (var i = 0; i < str.length; i++) {
  27081. a = (a << 8) | str.charCodeAt(i);
  27082. }
  27083. return a >>> 0;
  27084. }
  27085. function expectString(obj) {
  27086. if (!isString(obj)) {
  27087. error('Malformed CMap: expected string.');
  27088. }
  27089. }
  27090. function expectInt(obj) {
  27091. if (!isInt(obj)) {
  27092. error('Malformed CMap: expected int.');
  27093. }
  27094. }
  27095. function parseBfChar(cMap, lexer) {
  27096. while (true) {
  27097. var obj = lexer.getObj();
  27098. if (isEOF(obj)) {
  27099. break;
  27100. }
  27101. if (isCmd(obj, 'endbfchar')) {
  27102. return;
  27103. }
  27104. expectString(obj);
  27105. var src = strToInt(obj);
  27106. obj = lexer.getObj();
  27107. // TODO are /dstName used?
  27108. expectString(obj);
  27109. var dst = obj;
  27110. cMap.mapOne(src, dst);
  27111. }
  27112. }
  27113. function parseBfRange(cMap, lexer) {
  27114. while (true) {
  27115. var obj = lexer.getObj();
  27116. if (isEOF(obj)) {
  27117. break;
  27118. }
  27119. if (isCmd(obj, 'endbfrange')) {
  27120. return;
  27121. }
  27122. expectString(obj);
  27123. var low = strToInt(obj);
  27124. obj = lexer.getObj();
  27125. expectString(obj);
  27126. var high = strToInt(obj);
  27127. obj = lexer.getObj();
  27128. if (isInt(obj) || isString(obj)) {
  27129. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  27130. cMap.mapBfRange(low, high, dstLow);
  27131. } else if (isCmd(obj, '[')) {
  27132. obj = lexer.getObj();
  27133. var array = [];
  27134. while (!isCmd(obj, ']') && !isEOF(obj)) {
  27135. array.push(obj);
  27136. obj = lexer.getObj();
  27137. }
  27138. cMap.mapBfRangeToArray(low, high, array);
  27139. } else {
  27140. break;
  27141. }
  27142. }
  27143. error('Invalid bf range.');
  27144. }
  27145. function parseCidChar(cMap, lexer) {
  27146. while (true) {
  27147. var obj = lexer.getObj();
  27148. if (isEOF(obj)) {
  27149. break;
  27150. }
  27151. if (isCmd(obj, 'endcidchar')) {
  27152. return;
  27153. }
  27154. expectString(obj);
  27155. var src = strToInt(obj);
  27156. obj = lexer.getObj();
  27157. expectInt(obj);
  27158. var dst = obj;
  27159. cMap.mapOne(src, dst);
  27160. }
  27161. }
  27162. function parseCidRange(cMap, lexer) {
  27163. while (true) {
  27164. var obj = lexer.getObj();
  27165. if (isEOF(obj)) {
  27166. break;
  27167. }
  27168. if (isCmd(obj, 'endcidrange')) {
  27169. return;
  27170. }
  27171. expectString(obj);
  27172. var low = strToInt(obj);
  27173. obj = lexer.getObj();
  27174. expectString(obj);
  27175. var high = strToInt(obj);
  27176. obj = lexer.getObj();
  27177. expectInt(obj);
  27178. var dstLow = obj;
  27179. cMap.mapCidRange(low, high, dstLow);
  27180. }
  27181. }
  27182. function parseCodespaceRange(cMap, lexer) {
  27183. while (true) {
  27184. var obj = lexer.getObj();
  27185. if (isEOF(obj)) {
  27186. break;
  27187. }
  27188. if (isCmd(obj, 'endcodespacerange')) {
  27189. return;
  27190. }
  27191. if (!isString(obj)) {
  27192. break;
  27193. }
  27194. var low = strToInt(obj);
  27195. obj = lexer.getObj();
  27196. if (!isString(obj)) {
  27197. break;
  27198. }
  27199. var high = strToInt(obj);
  27200. cMap.addCodespaceRange(obj.length, low, high);
  27201. }
  27202. error('Invalid codespace range.');
  27203. }
  27204. function parseWMode(cMap, lexer) {
  27205. var obj = lexer.getObj();
  27206. if (isInt(obj)) {
  27207. cMap.vertical = !!obj;
  27208. }
  27209. }
  27210. function parseCMapName(cMap, lexer) {
  27211. var obj = lexer.getObj();
  27212. if (isName(obj) && isString(obj.name)) {
  27213. cMap.name = obj.name;
  27214. }
  27215. }
  27216. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  27217. var previous;
  27218. var embededUseCMap;
  27219. objLoop: while (true) {
  27220. var obj = lexer.getObj();
  27221. if (isEOF(obj)) {
  27222. break;
  27223. } else if (isName(obj)) {
  27224. if (obj.name === 'WMode') {
  27225. parseWMode(cMap, lexer);
  27226. } else if (obj.name === 'CMapName') {
  27227. parseCMapName(cMap, lexer);
  27228. }
  27229. previous = obj;
  27230. } else if (isCmd(obj)) {
  27231. switch (obj.cmd) {
  27232. case 'endcmap':
  27233. break objLoop;
  27234. case 'usecmap':
  27235. if (isName(previous)) {
  27236. embededUseCMap = previous.name;
  27237. }
  27238. break;
  27239. case 'begincodespacerange':
  27240. parseCodespaceRange(cMap, lexer);
  27241. break;
  27242. case 'beginbfchar':
  27243. parseBfChar(cMap, lexer);
  27244. break;
  27245. case 'begincidchar':
  27246. parseCidChar(cMap, lexer);
  27247. break;
  27248. case 'beginbfrange':
  27249. parseBfRange(cMap, lexer);
  27250. break;
  27251. case 'begincidrange':
  27252. parseCidRange(cMap, lexer);
  27253. break;
  27254. }
  27255. }
  27256. }
  27257. if (!useCMap && embededUseCMap) {
  27258. // Load the usecmap definition from the file only if there wasn't one
  27259. // specified.
  27260. useCMap = embededUseCMap;
  27261. }
  27262. if (useCMap) {
  27263. extendCMap(cMap, builtInCMapParams, useCMap);
  27264. }
  27265. }
  27266. function extendCMap(cMap, builtInCMapParams, useCMap) {
  27267. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  27268. // If there aren't any code space ranges defined clone all the parent ones
  27269. // into this cMap.
  27270. if (cMap.numCodespaceRanges === 0) {
  27271. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  27272. for (var i = 0; i < useCodespaceRanges.length; i++) {
  27273. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  27274. }
  27275. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  27276. }
  27277. // Merge the map into the current one, making sure not to override
  27278. // any previously defined entries.
  27279. cMap.useCMap.forEach(function(key, value) {
  27280. if (!cMap.contains(key)) {
  27281. cMap.mapOne(key, cMap.useCMap.lookup(key));
  27282. }
  27283. });
  27284. }
  27285. function parseBinaryCMap(name, builtInCMapParams) {
  27286. var url = builtInCMapParams.url + name + '.bcmap';
  27287. var cMap = new CMap(true);
  27288. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  27289. extendCMap(cMap, builtInCMapParams, useCMap);
  27290. });
  27291. return cMap;
  27292. }
  27293. function createBuiltInCMap(name, builtInCMapParams) {
  27294. if (name === 'Identity-H') {
  27295. return new IdentityCMap(false, 2);
  27296. } else if (name === 'Identity-V') {
  27297. return new IdentityCMap(true, 2);
  27298. }
  27299. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  27300. error('Unknown cMap name: ' + name);
  27301. }
  27302. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  27303. if (builtInCMapParams.packed) {
  27304. return parseBinaryCMap(name, builtInCMapParams);
  27305. }
  27306. var request = new XMLHttpRequest();
  27307. var url = builtInCMapParams.url + name;
  27308. request.open('GET', url, false);
  27309. request.send(null);
  27310. if (!request.responseText) {
  27311. error('Unable to get cMap at: ' + url);
  27312. }
  27313. var cMap = new CMap(true);
  27314. var lexer = new Lexer(new StringStream(request.responseText));
  27315. parseCMap(cMap, lexer, builtInCMapParams, null);
  27316. return cMap;
  27317. }
  27318. return {
  27319. create: function (encoding, builtInCMapParams, useCMap) {
  27320. if (isName(encoding)) {
  27321. return createBuiltInCMap(encoding.name, builtInCMapParams);
  27322. } else if (isStream(encoding)) {
  27323. var cMap = new CMap();
  27324. var lexer = new Lexer(encoding);
  27325. try {
  27326. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  27327. } catch (e) {
  27328. warn('Invalid CMap data. ' + e);
  27329. }
  27330. if (cMap.isIdentityCMap) {
  27331. return createBuiltInCMap(cMap.name, builtInCMapParams);
  27332. }
  27333. return cMap;
  27334. }
  27335. error('Encoding required.');
  27336. }
  27337. };
  27338. })();
  27339. exports.CMap = CMap;
  27340. exports.CMapFactory = CMapFactory;
  27341. exports.IdentityCMap = IdentityCMap;
  27342. }));
  27343. (function (root, factory) {
  27344. {
  27345. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  27346. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  27347. root.pdfjsCoreChunkedStream);
  27348. }
  27349. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  27350. coreChunkedStream) {
  27351. var InvalidPDFException = sharedUtil.InvalidPDFException;
  27352. var MissingDataException = sharedUtil.MissingDataException;
  27353. var XRefParseException = sharedUtil.XRefParseException;
  27354. var assert = sharedUtil.assert;
  27355. var bytesToString = sharedUtil.bytesToString;
  27356. var createPromiseCapability = sharedUtil.createPromiseCapability;
  27357. var error = sharedUtil.error;
  27358. var info = sharedUtil.info;
  27359. var isArray = sharedUtil.isArray;
  27360. var isInt = sharedUtil.isInt;
  27361. var isString = sharedUtil.isString;
  27362. var shadow = sharedUtil.shadow;
  27363. var stringToPDFString = sharedUtil.stringToPDFString;
  27364. var stringToUTF8String = sharedUtil.stringToUTF8String;
  27365. var warn = sharedUtil.warn;
  27366. var Ref = corePrimitives.Ref;
  27367. var RefSet = corePrimitives.RefSet;
  27368. var RefSetCache = corePrimitives.RefSetCache;
  27369. var isName = corePrimitives.isName;
  27370. var isCmd = corePrimitives.isCmd;
  27371. var isDict = corePrimitives.isDict;
  27372. var isRef = corePrimitives.isRef;
  27373. var isStream = corePrimitives.isStream;
  27374. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  27375. var Lexer = coreParser.Lexer;
  27376. var Parser = coreParser.Parser;
  27377. var ChunkedStream = coreChunkedStream.ChunkedStream;
  27378. var Catalog = (function CatalogClosure() {
  27379. function Catalog(pdfManager, xref, pageFactory) {
  27380. this.pdfManager = pdfManager;
  27381. this.xref = xref;
  27382. this.catDict = xref.getCatalogObj();
  27383. this.fontCache = new RefSetCache();
  27384. assert(isDict(this.catDict),
  27385. 'catalog object is not a dictionary');
  27386. // TODO refactor to move getPage() to the PDFDocument.
  27387. this.pageFactory = pageFactory;
  27388. this.pagePromises = [];
  27389. }
  27390. Catalog.prototype = {
  27391. get metadata() {
  27392. var streamRef = this.catDict.getRaw('Metadata');
  27393. if (!isRef(streamRef)) {
  27394. return shadow(this, 'metadata', null);
  27395. }
  27396. var encryptMetadata = (!this.xref.encrypt ? false :
  27397. this.xref.encrypt.encryptMetadata);
  27398. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  27399. var metadata;
  27400. if (stream && isDict(stream.dict)) {
  27401. var type = stream.dict.get('Type');
  27402. var subtype = stream.dict.get('Subtype');
  27403. if (isName(type) && isName(subtype) &&
  27404. type.name === 'Metadata' && subtype.name === 'XML') {
  27405. // XXX: This should examine the charset the XML document defines,
  27406. // however since there are currently no real means to decode
  27407. // arbitrary charsets, let's just hope that the author of the PDF
  27408. // was reasonable enough to stick with the XML default charset,
  27409. // which is UTF-8.
  27410. try {
  27411. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  27412. } catch (e) {
  27413. info('Skipping invalid metadata.');
  27414. }
  27415. }
  27416. }
  27417. return shadow(this, 'metadata', metadata);
  27418. },
  27419. get toplevelPagesDict() {
  27420. var pagesObj = this.catDict.get('Pages');
  27421. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  27422. // shadow the prototype getter
  27423. return shadow(this, 'toplevelPagesDict', pagesObj);
  27424. },
  27425. get documentOutline() {
  27426. var obj = null;
  27427. try {
  27428. obj = this.readDocumentOutline();
  27429. } catch (ex) {
  27430. if (ex instanceof MissingDataException) {
  27431. throw ex;
  27432. }
  27433. warn('Unable to read document outline');
  27434. }
  27435. return shadow(this, 'documentOutline', obj);
  27436. },
  27437. readDocumentOutline: function Catalog_readDocumentOutline() {
  27438. var xref = this.xref;
  27439. var obj = this.catDict.get('Outlines');
  27440. var root = { items: [] };
  27441. if (isDict(obj)) {
  27442. obj = obj.getRaw('First');
  27443. var processed = new RefSet();
  27444. if (isRef(obj)) {
  27445. var queue = [{obj: obj, parent: root}];
  27446. // to avoid recursion keeping track of the items
  27447. // in the processed dictionary
  27448. processed.put(obj);
  27449. while (queue.length > 0) {
  27450. var i = queue.shift();
  27451. var outlineDict = xref.fetchIfRef(i.obj);
  27452. if (outlineDict === null) {
  27453. continue;
  27454. }
  27455. if (!outlineDict.has('Title')) {
  27456. error('Invalid outline item');
  27457. }
  27458. var dest = outlineDict.get('A');
  27459. if (dest) {
  27460. dest = dest.get('D');
  27461. } else if (outlineDict.has('Dest')) {
  27462. dest = outlineDict.getRaw('Dest');
  27463. if (isName(dest)) {
  27464. dest = dest.name;
  27465. }
  27466. }
  27467. var title = outlineDict.get('Title');
  27468. var outlineItem = {
  27469. dest: dest,
  27470. title: stringToPDFString(title),
  27471. color: outlineDict.get('C') || [0, 0, 0],
  27472. count: outlineDict.get('Count'),
  27473. bold: !!(outlineDict.get('F') & 2),
  27474. italic: !!(outlineDict.get('F') & 1),
  27475. items: []
  27476. };
  27477. i.parent.items.push(outlineItem);
  27478. obj = outlineDict.getRaw('First');
  27479. if (isRef(obj) && !processed.has(obj)) {
  27480. queue.push({obj: obj, parent: outlineItem});
  27481. processed.put(obj);
  27482. }
  27483. obj = outlineDict.getRaw('Next');
  27484. if (isRef(obj) && !processed.has(obj)) {
  27485. queue.push({obj: obj, parent: i.parent});
  27486. processed.put(obj);
  27487. }
  27488. }
  27489. }
  27490. }
  27491. return (root.items.length > 0 ? root.items : null);
  27492. },
  27493. get numPages() {
  27494. var obj = this.toplevelPagesDict.get('Count');
  27495. assert(
  27496. isInt(obj),
  27497. 'page count in top level pages object is not an integer'
  27498. );
  27499. // shadow the prototype getter
  27500. return shadow(this, 'num', obj);
  27501. },
  27502. get destinations() {
  27503. function fetchDestination(dest) {
  27504. return isDict(dest) ? dest.get('D') : dest;
  27505. }
  27506. var xref = this.xref;
  27507. var dests = {}, nameTreeRef, nameDictionaryRef;
  27508. var obj = this.catDict.get('Names');
  27509. if (obj && obj.has('Dests')) {
  27510. nameTreeRef = obj.getRaw('Dests');
  27511. } else if (this.catDict.has('Dests')) {
  27512. nameDictionaryRef = this.catDict.get('Dests');
  27513. }
  27514. if (nameDictionaryRef) {
  27515. // reading simple destination dictionary
  27516. obj = nameDictionaryRef;
  27517. obj.forEach(function catalogForEach(key, value) {
  27518. if (!value) {
  27519. return;
  27520. }
  27521. dests[key] = fetchDestination(value);
  27522. });
  27523. }
  27524. if (nameTreeRef) {
  27525. var nameTree = new NameTree(nameTreeRef, xref);
  27526. var names = nameTree.getAll();
  27527. for (var name in names) {
  27528. if (!names.hasOwnProperty(name)) {
  27529. continue;
  27530. }
  27531. dests[name] = fetchDestination(names[name]);
  27532. }
  27533. }
  27534. return shadow(this, 'destinations', dests);
  27535. },
  27536. getDestination: function Catalog_getDestination(destinationId) {
  27537. function fetchDestination(dest) {
  27538. return isDict(dest) ? dest.get('D') : dest;
  27539. }
  27540. var xref = this.xref;
  27541. var dest = null, nameTreeRef, nameDictionaryRef;
  27542. var obj = this.catDict.get('Names');
  27543. if (obj && obj.has('Dests')) {
  27544. nameTreeRef = obj.getRaw('Dests');
  27545. } else if (this.catDict.has('Dests')) {
  27546. nameDictionaryRef = this.catDict.get('Dests');
  27547. }
  27548. if (nameDictionaryRef) { // Simple destination dictionary.
  27549. var value = nameDictionaryRef.get(destinationId);
  27550. if (value) {
  27551. dest = fetchDestination(value);
  27552. }
  27553. }
  27554. if (nameTreeRef) {
  27555. var nameTree = new NameTree(nameTreeRef, xref);
  27556. dest = fetchDestination(nameTree.get(destinationId));
  27557. }
  27558. return dest;
  27559. },
  27560. get attachments() {
  27561. var xref = this.xref;
  27562. var attachments = null, nameTreeRef;
  27563. var obj = this.catDict.get('Names');
  27564. if (obj) {
  27565. nameTreeRef = obj.getRaw('EmbeddedFiles');
  27566. }
  27567. if (nameTreeRef) {
  27568. var nameTree = new NameTree(nameTreeRef, xref);
  27569. var names = nameTree.getAll();
  27570. for (var name in names) {
  27571. if (!names.hasOwnProperty(name)) {
  27572. continue;
  27573. }
  27574. var fs = new FileSpec(names[name], xref);
  27575. if (!attachments) {
  27576. attachments = {};
  27577. }
  27578. attachments[stringToPDFString(name)] = fs.serializable;
  27579. }
  27580. }
  27581. return shadow(this, 'attachments', attachments);
  27582. },
  27583. get javaScript() {
  27584. var xref = this.xref;
  27585. var obj = this.catDict.get('Names');
  27586. var javaScript = [];
  27587. function appendIfJavaScriptDict(jsDict) {
  27588. var type = jsDict.get('S');
  27589. if (!isName(type) || type.name !== 'JavaScript') {
  27590. return;
  27591. }
  27592. var js = jsDict.get('JS');
  27593. if (isStream(js)) {
  27594. js = bytesToString(js.getBytes());
  27595. } else if (!isString(js)) {
  27596. return;
  27597. }
  27598. javaScript.push(stringToPDFString(js));
  27599. }
  27600. if (obj && obj.has('JavaScript')) {
  27601. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  27602. var names = nameTree.getAll();
  27603. for (var name in names) {
  27604. if (!names.hasOwnProperty(name)) {
  27605. continue;
  27606. }
  27607. // We don't really use the JavaScript right now. This code is
  27608. // defensive so we don't cause errors on document load.
  27609. var jsDict = names[name];
  27610. if (isDict(jsDict)) {
  27611. appendIfJavaScriptDict(jsDict);
  27612. }
  27613. }
  27614. }
  27615. // Append OpenAction actions to javaScript array
  27616. var openactionDict = this.catDict.get('OpenAction');
  27617. if (isDict(openactionDict, 'Action')) {
  27618. var actionType = openactionDict.get('S');
  27619. if (isName(actionType) && actionType.name === 'Named') {
  27620. // The named Print action is not a part of the PDF 1.7 specification,
  27621. // but is supported by many PDF readers/writers (including Adobe's).
  27622. var action = openactionDict.get('N');
  27623. if (isName(action) && action.name === 'Print') {
  27624. javaScript.push('print({});');
  27625. }
  27626. } else {
  27627. appendIfJavaScriptDict(openactionDict);
  27628. }
  27629. }
  27630. return shadow(this, 'javaScript', javaScript);
  27631. },
  27632. cleanup: function Catalog_cleanup() {
  27633. var promises = [];
  27634. this.fontCache.forEach(function (promise) {
  27635. promises.push(promise);
  27636. });
  27637. return Promise.all(promises).then(function (translatedFonts) {
  27638. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  27639. var font = translatedFonts[i].dict;
  27640. delete font.translated;
  27641. }
  27642. this.fontCache.clear();
  27643. }.bind(this));
  27644. },
  27645. getPage: function Catalog_getPage(pageIndex) {
  27646. if (!(pageIndex in this.pagePromises)) {
  27647. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  27648. function (a) {
  27649. var dict = a[0];
  27650. var ref = a[1];
  27651. return this.pageFactory.createPage(pageIndex, dict, ref,
  27652. this.fontCache);
  27653. }.bind(this)
  27654. );
  27655. }
  27656. return this.pagePromises[pageIndex];
  27657. },
  27658. getPageDict: function Catalog_getPageDict(pageIndex) {
  27659. var capability = createPromiseCapability();
  27660. var nodesToVisit = [this.catDict.getRaw('Pages')];
  27661. var currentPageIndex = 0;
  27662. var xref = this.xref;
  27663. var checkAllKids = false;
  27664. function next() {
  27665. while (nodesToVisit.length) {
  27666. var currentNode = nodesToVisit.pop();
  27667. if (isRef(currentNode)) {
  27668. xref.fetchAsync(currentNode).then(function (obj) {
  27669. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  27670. if (pageIndex === currentPageIndex) {
  27671. capability.resolve([obj, currentNode]);
  27672. } else {
  27673. currentPageIndex++;
  27674. next();
  27675. }
  27676. return;
  27677. }
  27678. nodesToVisit.push(obj);
  27679. next();
  27680. }, capability.reject);
  27681. return;
  27682. }
  27683. // Must be a child page dictionary.
  27684. assert(
  27685. isDict(currentNode),
  27686. 'page dictionary kid reference points to wrong type of object'
  27687. );
  27688. var count = currentNode.get('Count');
  27689. // If the current node doesn't have any children, avoid getting stuck
  27690. // in an empty node further down in the tree (see issue5644.pdf).
  27691. if (count === 0) {
  27692. checkAllKids = true;
  27693. }
  27694. // Skip nodes where the page can't be.
  27695. if (currentPageIndex + count <= pageIndex) {
  27696. currentPageIndex += count;
  27697. continue;
  27698. }
  27699. var kids = currentNode.get('Kids');
  27700. assert(isArray(kids), 'page dictionary kids object is not an array');
  27701. if (!checkAllKids && count === kids.length) {
  27702. // Nodes that don't have the page have been skipped and this is the
  27703. // bottom of the tree which means the page requested must be a
  27704. // descendant of this pages node. Ideally we would just resolve the
  27705. // promise with the page ref here, but there is the case where more
  27706. // pages nodes could link to single a page (see issue 3666 pdf). To
  27707. // handle this push it back on the queue so if it is a pages node it
  27708. // will be descended into.
  27709. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  27710. currentPageIndex = pageIndex;
  27711. continue;
  27712. } else {
  27713. for (var last = kids.length - 1; last >= 0; last--) {
  27714. nodesToVisit.push(kids[last]);
  27715. }
  27716. }
  27717. }
  27718. capability.reject('Page index ' + pageIndex + ' not found.');
  27719. }
  27720. next();
  27721. return capability.promise;
  27722. },
  27723. getPageIndex: function Catalog_getPageIndex(ref) {
  27724. // The page tree nodes have the count of all the leaves below them. To get
  27725. // how many pages are before we just have to walk up the tree and keep
  27726. // adding the count of siblings to the left of the node.
  27727. var xref = this.xref;
  27728. function pagesBeforeRef(kidRef) {
  27729. var total = 0;
  27730. var parentRef;
  27731. return xref.fetchAsync(kidRef).then(function (node) {
  27732. if (!node) {
  27733. return null;
  27734. }
  27735. parentRef = node.getRaw('Parent');
  27736. return node.getAsync('Parent');
  27737. }).then(function (parent) {
  27738. if (!parent) {
  27739. return null;
  27740. }
  27741. return parent.getAsync('Kids');
  27742. }).then(function (kids) {
  27743. if (!kids) {
  27744. return null;
  27745. }
  27746. var kidPromises = [];
  27747. var found = false;
  27748. for (var i = 0; i < kids.length; i++) {
  27749. var kid = kids[i];
  27750. assert(isRef(kid), 'kids must be a ref');
  27751. if (kid.num === kidRef.num) {
  27752. found = true;
  27753. break;
  27754. }
  27755. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  27756. if (kid.has('Count')) {
  27757. var count = kid.get('Count');
  27758. total += count;
  27759. } else { // page leaf node
  27760. total++;
  27761. }
  27762. }));
  27763. }
  27764. if (!found) {
  27765. error('kid ref not found in parents kids');
  27766. }
  27767. return Promise.all(kidPromises).then(function () {
  27768. return [total, parentRef];
  27769. });
  27770. });
  27771. }
  27772. var total = 0;
  27773. function next(ref) {
  27774. return pagesBeforeRef(ref).then(function (args) {
  27775. if (!args) {
  27776. return total;
  27777. }
  27778. var count = args[0];
  27779. var parentRef = args[1];
  27780. total += count;
  27781. return next(parentRef);
  27782. });
  27783. }
  27784. return next(ref);
  27785. }
  27786. };
  27787. return Catalog;
  27788. })();
  27789. var XRef = (function XRefClosure() {
  27790. function XRef(stream, password) {
  27791. this.stream = stream;
  27792. this.entries = [];
  27793. this.xrefstms = {};
  27794. // prepare the XRef cache
  27795. this.cache = [];
  27796. this.password = password;
  27797. this.stats = {
  27798. streamTypes: [],
  27799. fontTypes: []
  27800. };
  27801. }
  27802. XRef.prototype = {
  27803. setStartXRef: function XRef_setStartXRef(startXRef) {
  27804. // Store the starting positions of xref tables as we process them
  27805. // so we can recover from missing data errors
  27806. this.startXRefQueue = [startXRef];
  27807. },
  27808. parse: function XRef_parse(recoveryMode) {
  27809. var trailerDict;
  27810. if (!recoveryMode) {
  27811. trailerDict = this.readXRef();
  27812. } else {
  27813. warn('Indexing all PDF objects');
  27814. trailerDict = this.indexObjects();
  27815. }
  27816. trailerDict.assignXref(this);
  27817. this.trailer = trailerDict;
  27818. var encrypt = trailerDict.get('Encrypt');
  27819. if (encrypt) {
  27820. var ids = trailerDict.get('ID');
  27821. var fileId = (ids && ids.length) ? ids[0] : '';
  27822. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  27823. this.password);
  27824. }
  27825. // get the root dictionary (catalog) object
  27826. if (!(this.root = trailerDict.get('Root'))) {
  27827. error('Invalid root reference');
  27828. }
  27829. },
  27830. processXRefTable: function XRef_processXRefTable(parser) {
  27831. if (!('tableState' in this)) {
  27832. // Stores state of the table as we process it so we can resume
  27833. // from middle of table in case of missing data error
  27834. this.tableState = {
  27835. entryNum: 0,
  27836. streamPos: parser.lexer.stream.pos,
  27837. parserBuf1: parser.buf1,
  27838. parserBuf2: parser.buf2
  27839. };
  27840. }
  27841. var obj = this.readXRefTable(parser);
  27842. // Sanity check
  27843. if (!isCmd(obj, 'trailer')) {
  27844. error('Invalid XRef table: could not find trailer dictionary');
  27845. }
  27846. // Read trailer dictionary, e.g.
  27847. // trailer
  27848. // << /Size 22
  27849. // /Root 20R
  27850. // /Info 10R
  27851. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  27852. // >>
  27853. // The parser goes through the entire stream << ... >> and provides
  27854. // a getter interface for the key-value table
  27855. var dict = parser.getObj();
  27856. // The pdflib PDF generator can generate a nested trailer dictionary
  27857. if (!isDict(dict) && dict.dict) {
  27858. dict = dict.dict;
  27859. }
  27860. if (!isDict(dict)) {
  27861. error('Invalid XRef table: could not parse trailer dictionary');
  27862. }
  27863. delete this.tableState;
  27864. return dict;
  27865. },
  27866. readXRefTable: function XRef_readXRefTable(parser) {
  27867. // Example of cross-reference table:
  27868. // xref
  27869. // 0 1 <-- subsection header (first obj #, obj count)
  27870. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  27871. // 23 2 <-- subsection header ... and so on ...
  27872. // 0000025518 00002 n
  27873. // 0000025635 00000 n
  27874. // trailer
  27875. // ...
  27876. var stream = parser.lexer.stream;
  27877. var tableState = this.tableState;
  27878. stream.pos = tableState.streamPos;
  27879. parser.buf1 = tableState.parserBuf1;
  27880. parser.buf2 = tableState.parserBuf2;
  27881. // Outer loop is over subsection headers
  27882. var obj;
  27883. while (true) {
  27884. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  27885. if (isCmd(obj = parser.getObj(), 'trailer')) {
  27886. break;
  27887. }
  27888. tableState.firstEntryNum = obj;
  27889. tableState.entryCount = parser.getObj();
  27890. }
  27891. var first = tableState.firstEntryNum;
  27892. var count = tableState.entryCount;
  27893. if (!isInt(first) || !isInt(count)) {
  27894. error('Invalid XRef table: wrong types in subsection header');
  27895. }
  27896. // Inner loop is over objects themselves
  27897. for (var i = tableState.entryNum; i < count; i++) {
  27898. tableState.streamPos = stream.pos;
  27899. tableState.entryNum = i;
  27900. tableState.parserBuf1 = parser.buf1;
  27901. tableState.parserBuf2 = parser.buf2;
  27902. var entry = {};
  27903. entry.offset = parser.getObj();
  27904. entry.gen = parser.getObj();
  27905. var type = parser.getObj();
  27906. if (isCmd(type, 'f')) {
  27907. entry.free = true;
  27908. } else if (isCmd(type, 'n')) {
  27909. entry.uncompressed = true;
  27910. }
  27911. // Validate entry obj
  27912. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  27913. !(entry.free || entry.uncompressed)) {
  27914. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  27915. }
  27916. if (!this.entries[i + first]) {
  27917. this.entries[i + first] = entry;
  27918. }
  27919. }
  27920. tableState.entryNum = 0;
  27921. tableState.streamPos = stream.pos;
  27922. tableState.parserBuf1 = parser.buf1;
  27923. tableState.parserBuf2 = parser.buf2;
  27924. delete tableState.firstEntryNum;
  27925. delete tableState.entryCount;
  27926. }
  27927. // Per issue 3248: hp scanners generate bad XRef
  27928. if (first === 1 && this.entries[1] && this.entries[1].free) {
  27929. // shifting the entries
  27930. this.entries.shift();
  27931. }
  27932. // Sanity check: as per spec, first object must be free
  27933. if (this.entries[0] && !this.entries[0].free) {
  27934. error('Invalid XRef table: unexpected first object');
  27935. }
  27936. return obj;
  27937. },
  27938. processXRefStream: function XRef_processXRefStream(stream) {
  27939. if (!('streamState' in this)) {
  27940. // Stores state of the stream as we process it so we can resume
  27941. // from middle of stream in case of missing data error
  27942. var streamParameters = stream.dict;
  27943. var byteWidths = streamParameters.get('W');
  27944. var range = streamParameters.get('Index');
  27945. if (!range) {
  27946. range = [0, streamParameters.get('Size')];
  27947. }
  27948. this.streamState = {
  27949. entryRanges: range,
  27950. byteWidths: byteWidths,
  27951. entryNum: 0,
  27952. streamPos: stream.pos
  27953. };
  27954. }
  27955. this.readXRefStream(stream);
  27956. delete this.streamState;
  27957. return stream.dict;
  27958. },
  27959. readXRefStream: function XRef_readXRefStream(stream) {
  27960. var i, j;
  27961. var streamState = this.streamState;
  27962. stream.pos = streamState.streamPos;
  27963. var byteWidths = streamState.byteWidths;
  27964. var typeFieldWidth = byteWidths[0];
  27965. var offsetFieldWidth = byteWidths[1];
  27966. var generationFieldWidth = byteWidths[2];
  27967. var entryRanges = streamState.entryRanges;
  27968. while (entryRanges.length > 0) {
  27969. var first = entryRanges[0];
  27970. var n = entryRanges[1];
  27971. if (!isInt(first) || !isInt(n)) {
  27972. error('Invalid XRef range fields: ' + first + ', ' + n);
  27973. }
  27974. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  27975. !isInt(generationFieldWidth)) {
  27976. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  27977. }
  27978. for (i = streamState.entryNum; i < n; ++i) {
  27979. streamState.entryNum = i;
  27980. streamState.streamPos = stream.pos;
  27981. var type = 0, offset = 0, generation = 0;
  27982. for (j = 0; j < typeFieldWidth; ++j) {
  27983. type = (type << 8) | stream.getByte();
  27984. }
  27985. // if type field is absent, its default value is 1
  27986. if (typeFieldWidth === 0) {
  27987. type = 1;
  27988. }
  27989. for (j = 0; j < offsetFieldWidth; ++j) {
  27990. offset = (offset << 8) | stream.getByte();
  27991. }
  27992. for (j = 0; j < generationFieldWidth; ++j) {
  27993. generation = (generation << 8) | stream.getByte();
  27994. }
  27995. var entry = {};
  27996. entry.offset = offset;
  27997. entry.gen = generation;
  27998. switch (type) {
  27999. case 0:
  28000. entry.free = true;
  28001. break;
  28002. case 1:
  28003. entry.uncompressed = true;
  28004. break;
  28005. case 2:
  28006. break;
  28007. default:
  28008. error('Invalid XRef entry type: ' + type);
  28009. }
  28010. if (!this.entries[first + i]) {
  28011. this.entries[first + i] = entry;
  28012. }
  28013. }
  28014. streamState.entryNum = 0;
  28015. streamState.streamPos = stream.pos;
  28016. entryRanges.splice(0, 2);
  28017. }
  28018. },
  28019. indexObjects: function XRef_indexObjects() {
  28020. // Simple scan through the PDF content to find objects,
  28021. // trailers and XRef streams.
  28022. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  28023. var PERCENT = 0x25, LT = 0x3C;
  28024. function readToken(data, offset) {
  28025. var token = '', ch = data[offset];
  28026. while (ch !== LF && ch !== CR && ch !== LT) {
  28027. if (++offset >= data.length) {
  28028. break;
  28029. }
  28030. token += String.fromCharCode(ch);
  28031. ch = data[offset];
  28032. }
  28033. return token;
  28034. }
  28035. function skipUntil(data, offset, what) {
  28036. var length = what.length, dataLength = data.length;
  28037. var skipped = 0;
  28038. // finding byte sequence
  28039. while (offset < dataLength) {
  28040. var i = 0;
  28041. while (i < length && data[offset + i] === what[i]) {
  28042. ++i;
  28043. }
  28044. if (i >= length) {
  28045. break; // sequence found
  28046. }
  28047. offset++;
  28048. skipped++;
  28049. }
  28050. return skipped;
  28051. }
  28052. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  28053. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  28054. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  28055. 101, 102]);
  28056. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  28057. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  28058. // Clear out any existing entries, since they may be bogus.
  28059. this.entries.length = 0;
  28060. var stream = this.stream;
  28061. stream.pos = 0;
  28062. var buffer = stream.getBytes();
  28063. var position = stream.start, length = buffer.length;
  28064. var trailers = [], xrefStms = [];
  28065. while (position < length) {
  28066. var ch = buffer[position];
  28067. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  28068. ++position;
  28069. continue;
  28070. }
  28071. if (ch === PERCENT) { // %-comment
  28072. do {
  28073. ++position;
  28074. if (position >= length) {
  28075. break;
  28076. }
  28077. ch = buffer[position];
  28078. } while (ch !== LF && ch !== CR);
  28079. continue;
  28080. }
  28081. var token = readToken(buffer, position);
  28082. var m;
  28083. if (token.indexOf('xref') === 0 &&
  28084. (token.length === 4 || /\s/.test(token[4]))) {
  28085. position += skipUntil(buffer, position, trailerBytes);
  28086. trailers.push(position);
  28087. position += skipUntil(buffer, position, startxrefBytes);
  28088. } else if ((m = objRegExp.exec(token))) {
  28089. if (typeof this.entries[m[1]] === 'undefined') {
  28090. this.entries[m[1]] = {
  28091. offset: position - stream.start,
  28092. gen: m[2] | 0,
  28093. uncompressed: true
  28094. };
  28095. }
  28096. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  28097. var content = buffer.subarray(position, position + contentLength);
  28098. // checking XRef stream suspect
  28099. // (it shall have '/XRef' and next char is not a letter)
  28100. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  28101. if (xrefTagOffset < contentLength &&
  28102. content[xrefTagOffset + 5] < 64) {
  28103. xrefStms.push(position - stream.start);
  28104. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  28105. }
  28106. position += contentLength;
  28107. } else if (token.indexOf('trailer') === 0 &&
  28108. (token.length === 7 || /\s/.test(token[7]))) {
  28109. trailers.push(position);
  28110. position += skipUntil(buffer, position, startxrefBytes);
  28111. } else {
  28112. position += token.length + 1;
  28113. }
  28114. }
  28115. // reading XRef streams
  28116. var i, ii;
  28117. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  28118. this.startXRefQueue.push(xrefStms[i]);
  28119. this.readXRef(/* recoveryMode */ true);
  28120. }
  28121. // finding main trailer
  28122. var dict;
  28123. for (i = 0, ii = trailers.length; i < ii; ++i) {
  28124. stream.pos = trailers[i];
  28125. var parser = new Parser(new Lexer(stream), true, this);
  28126. var obj = parser.getObj();
  28127. if (!isCmd(obj, 'trailer')) {
  28128. continue;
  28129. }
  28130. // read the trailer dictionary
  28131. if (!isDict(dict = parser.getObj())) {
  28132. continue;
  28133. }
  28134. // taking the first one with 'ID'
  28135. if (dict.has('ID')) {
  28136. return dict;
  28137. }
  28138. }
  28139. // no tailer with 'ID', taking last one (if exists)
  28140. if (dict) {
  28141. return dict;
  28142. }
  28143. // nothing helps
  28144. // calling error() would reject worker with an UnknownErrorException.
  28145. throw new InvalidPDFException('Invalid PDF structure');
  28146. },
  28147. readXRef: function XRef_readXRef(recoveryMode) {
  28148. var stream = this.stream;
  28149. try {
  28150. while (this.startXRefQueue.length) {
  28151. var startXRef = this.startXRefQueue[0];
  28152. stream.pos = startXRef + stream.start;
  28153. var parser = new Parser(new Lexer(stream), true, this);
  28154. var obj = parser.getObj();
  28155. var dict;
  28156. // Get dictionary
  28157. if (isCmd(obj, 'xref')) {
  28158. // Parse end-of-file XRef
  28159. dict = this.processXRefTable(parser);
  28160. if (!this.topDict) {
  28161. this.topDict = dict;
  28162. }
  28163. // Recursively get other XRefs 'XRefStm', if any
  28164. obj = dict.get('XRefStm');
  28165. if (isInt(obj)) {
  28166. var pos = obj;
  28167. // ignore previously loaded xref streams
  28168. // (possible infinite recursion)
  28169. if (!(pos in this.xrefstms)) {
  28170. this.xrefstms[pos] = 1;
  28171. this.startXRefQueue.push(pos);
  28172. }
  28173. }
  28174. } else if (isInt(obj)) {
  28175. // Parse in-stream XRef
  28176. if (!isInt(parser.getObj()) ||
  28177. !isCmd(parser.getObj(), 'obj') ||
  28178. !isStream(obj = parser.getObj())) {
  28179. error('Invalid XRef stream');
  28180. }
  28181. dict = this.processXRefStream(obj);
  28182. if (!this.topDict) {
  28183. this.topDict = dict;
  28184. }
  28185. if (!dict) {
  28186. error('Failed to read XRef stream');
  28187. }
  28188. } else {
  28189. error('Invalid XRef stream header');
  28190. }
  28191. // Recursively get previous dictionary, if any
  28192. obj = dict.get('Prev');
  28193. if (isInt(obj)) {
  28194. this.startXRefQueue.push(obj);
  28195. } else if (isRef(obj)) {
  28196. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  28197. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  28198. this.startXRefQueue.push(obj.num);
  28199. }
  28200. this.startXRefQueue.shift();
  28201. }
  28202. return this.topDict;
  28203. } catch (e) {
  28204. if (e instanceof MissingDataException) {
  28205. throw e;
  28206. }
  28207. info('(while reading XRef): ' + e);
  28208. }
  28209. if (recoveryMode) {
  28210. return;
  28211. }
  28212. throw new XRefParseException();
  28213. },
  28214. getEntry: function XRef_getEntry(i) {
  28215. var xrefEntry = this.entries[i];
  28216. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  28217. return xrefEntry;
  28218. }
  28219. return null;
  28220. },
  28221. fetchIfRef: function XRef_fetchIfRef(obj) {
  28222. if (!isRef(obj)) {
  28223. return obj;
  28224. }
  28225. return this.fetch(obj);
  28226. },
  28227. fetch: function XRef_fetch(ref, suppressEncryption) {
  28228. assert(isRef(ref), 'ref object is not a reference');
  28229. var num = ref.num;
  28230. if (num in this.cache) {
  28231. var cacheEntry = this.cache[num];
  28232. return cacheEntry;
  28233. }
  28234. var xrefEntry = this.getEntry(num);
  28235. // the referenced entry can be free
  28236. if (xrefEntry === null) {
  28237. return (this.cache[num] = null);
  28238. }
  28239. if (xrefEntry.uncompressed) {
  28240. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  28241. } else {
  28242. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  28243. }
  28244. if (isDict(xrefEntry)){
  28245. xrefEntry.objId = ref.toString();
  28246. } else if (isStream(xrefEntry)) {
  28247. xrefEntry.dict.objId = ref.toString();
  28248. }
  28249. return xrefEntry;
  28250. },
  28251. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  28252. suppressEncryption) {
  28253. var gen = ref.gen;
  28254. var num = ref.num;
  28255. if (xrefEntry.gen !== gen) {
  28256. error('inconsistent generation in XRef');
  28257. }
  28258. var stream = this.stream.makeSubStream(xrefEntry.offset +
  28259. this.stream.start);
  28260. var parser = new Parser(new Lexer(stream), true, this);
  28261. var obj1 = parser.getObj();
  28262. var obj2 = parser.getObj();
  28263. var obj3 = parser.getObj();
  28264. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  28265. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  28266. !isCmd(obj3)) {
  28267. error('bad XRef entry');
  28268. }
  28269. if (!isCmd(obj3, 'obj')) {
  28270. // some bad PDFs use "obj1234" and really mean 1234
  28271. if (obj3.cmd.indexOf('obj') === 0) {
  28272. num = parseInt(obj3.cmd.substring(3), 10);
  28273. if (!isNaN(num)) {
  28274. return num;
  28275. }
  28276. }
  28277. error('bad XRef entry');
  28278. }
  28279. if (this.encrypt && !suppressEncryption) {
  28280. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  28281. } else {
  28282. xrefEntry = parser.getObj();
  28283. }
  28284. if (!isStream(xrefEntry)) {
  28285. this.cache[num] = xrefEntry;
  28286. }
  28287. return xrefEntry;
  28288. },
  28289. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  28290. suppressEncryption) {
  28291. var tableOffset = xrefEntry.offset;
  28292. var stream = this.fetch(new Ref(tableOffset, 0));
  28293. if (!isStream(stream)) {
  28294. error('bad ObjStm stream');
  28295. }
  28296. var first = stream.dict.get('First');
  28297. var n = stream.dict.get('N');
  28298. if (!isInt(first) || !isInt(n)) {
  28299. error('invalid first and n parameters for ObjStm stream');
  28300. }
  28301. var parser = new Parser(new Lexer(stream), false, this);
  28302. parser.allowStreams = true;
  28303. var i, entries = [], num, nums = [];
  28304. // read the object numbers to populate cache
  28305. for (i = 0; i < n; ++i) {
  28306. num = parser.getObj();
  28307. if (!isInt(num)) {
  28308. error('invalid object number in the ObjStm stream: ' + num);
  28309. }
  28310. nums.push(num);
  28311. var offset = parser.getObj();
  28312. if (!isInt(offset)) {
  28313. error('invalid object offset in the ObjStm stream: ' + offset);
  28314. }
  28315. }
  28316. // read stream objects for cache
  28317. for (i = 0; i < n; ++i) {
  28318. entries.push(parser.getObj());
  28319. num = nums[i];
  28320. var entry = this.entries[num];
  28321. if (entry && entry.offset === tableOffset && entry.gen === i) {
  28322. this.cache[num] = entries[i];
  28323. }
  28324. }
  28325. xrefEntry = entries[xrefEntry.gen];
  28326. if (xrefEntry === undefined) {
  28327. error('bad XRef entry for compressed object');
  28328. }
  28329. return xrefEntry;
  28330. },
  28331. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  28332. if (!isRef(obj)) {
  28333. return Promise.resolve(obj);
  28334. }
  28335. return this.fetchAsync(obj);
  28336. },
  28337. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  28338. var streamManager = this.stream.manager;
  28339. var xref = this;
  28340. return new Promise(function tryFetch(resolve, reject) {
  28341. try {
  28342. resolve(xref.fetch(ref, suppressEncryption));
  28343. } catch (e) {
  28344. if (e instanceof MissingDataException) {
  28345. streamManager.requestRange(e.begin, e.end).then(function () {
  28346. tryFetch(resolve, reject);
  28347. }, reject);
  28348. return;
  28349. }
  28350. reject(e);
  28351. }
  28352. });
  28353. },
  28354. getCatalogObj: function XRef_getCatalogObj() {
  28355. return this.root;
  28356. }
  28357. };
  28358. return XRef;
  28359. })();
  28360. /**
  28361. * A NameTree is like a Dict but has some advantageous properties, see the
  28362. * spec (7.9.6) for more details.
  28363. * TODO: implement all the Dict functions and make this more efficent.
  28364. */
  28365. var NameTree = (function NameTreeClosure() {
  28366. function NameTree(root, xref) {
  28367. this.root = root;
  28368. this.xref = xref;
  28369. }
  28370. NameTree.prototype = {
  28371. getAll: function NameTree_getAll() {
  28372. var dict = {};
  28373. if (!this.root) {
  28374. return dict;
  28375. }
  28376. var xref = this.xref;
  28377. // reading name tree
  28378. var processed = new RefSet();
  28379. processed.put(this.root);
  28380. var queue = [this.root];
  28381. while (queue.length > 0) {
  28382. var i, n;
  28383. var obj = xref.fetchIfRef(queue.shift());
  28384. if (!isDict(obj)) {
  28385. continue;
  28386. }
  28387. if (obj.has('Kids')) {
  28388. var kids = obj.get('Kids');
  28389. for (i = 0, n = kids.length; i < n; i++) {
  28390. var kid = kids[i];
  28391. if (processed.has(kid)) {
  28392. error('invalid destinations');
  28393. }
  28394. queue.push(kid);
  28395. processed.put(kid);
  28396. }
  28397. continue;
  28398. }
  28399. var names = obj.get('Names');
  28400. if (names) {
  28401. for (i = 0, n = names.length; i < n; i += 2) {
  28402. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  28403. }
  28404. }
  28405. }
  28406. return dict;
  28407. },
  28408. get: function NameTree_get(destinationId) {
  28409. if (!this.root) {
  28410. return null;
  28411. }
  28412. var xref = this.xref;
  28413. var kidsOrNames = xref.fetchIfRef(this.root);
  28414. var loopCount = 0;
  28415. var MAX_NAMES_LEVELS = 10;
  28416. var l, r, m;
  28417. // Perform a binary search to quickly find the entry that
  28418. // contains the named destination we are looking for.
  28419. while (kidsOrNames.has('Kids')) {
  28420. loopCount++;
  28421. if (loopCount > MAX_NAMES_LEVELS) {
  28422. warn('Search depth limit for named destionations has been reached.');
  28423. return null;
  28424. }
  28425. var kids = kidsOrNames.get('Kids');
  28426. if (!isArray(kids)) {
  28427. return null;
  28428. }
  28429. l = 0;
  28430. r = kids.length - 1;
  28431. while (l <= r) {
  28432. m = (l + r) >> 1;
  28433. var kid = xref.fetchIfRef(kids[m]);
  28434. var limits = kid.get('Limits');
  28435. if (destinationId < xref.fetchIfRef(limits[0])) {
  28436. r = m - 1;
  28437. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  28438. l = m + 1;
  28439. } else {
  28440. kidsOrNames = xref.fetchIfRef(kids[m]);
  28441. break;
  28442. }
  28443. }
  28444. if (l > r) {
  28445. return null;
  28446. }
  28447. }
  28448. // If we get here, then we have found the right entry. Now
  28449. // go through the named destinations in the Named dictionary
  28450. // until we find the exact destination we're looking for.
  28451. var names = kidsOrNames.get('Names');
  28452. if (isArray(names)) {
  28453. // Perform a binary search to reduce the lookup time.
  28454. l = 0;
  28455. r = names.length - 2;
  28456. while (l <= r) {
  28457. // Check only even indices (0, 2, 4, ...) because the
  28458. // odd indices contain the actual D array.
  28459. m = (l + r) & ~1;
  28460. if (destinationId < xref.fetchIfRef(names[m])) {
  28461. r = m - 2;
  28462. } else if (destinationId > xref.fetchIfRef(names[m])) {
  28463. l = m + 2;
  28464. } else {
  28465. return xref.fetchIfRef(names[m + 1]);
  28466. }
  28467. }
  28468. }
  28469. return null;
  28470. }
  28471. };
  28472. return NameTree;
  28473. })();
  28474. /**
  28475. * "A PDF file can refer to the contents of another file by using a File
  28476. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  28477. * NOTE: Only embedded files are supported (as part of the attachments support)
  28478. * TODO: support the 'URL' file system (with caching if !/V), portable
  28479. * collections attributes and related files (/RF)
  28480. */
  28481. var FileSpec = (function FileSpecClosure() {
  28482. function FileSpec(root, xref) {
  28483. if (!root || !isDict(root)) {
  28484. return;
  28485. }
  28486. this.xref = xref;
  28487. this.root = root;
  28488. if (root.has('FS')) {
  28489. this.fs = root.get('FS');
  28490. }
  28491. this.description = root.has('Desc') ?
  28492. stringToPDFString(root.get('Desc')) :
  28493. '';
  28494. if (root.has('RF')) {
  28495. warn('Related file specifications are not supported');
  28496. }
  28497. this.contentAvailable = true;
  28498. if (!root.has('EF')) {
  28499. this.contentAvailable = false;
  28500. warn('Non-embedded file specifications are not supported');
  28501. }
  28502. }
  28503. function pickPlatformItem(dict) {
  28504. // Look for the filename in this order:
  28505. // UF, F, Unix, Mac, DOS
  28506. if (dict.has('UF')) {
  28507. return dict.get('UF');
  28508. } else if (dict.has('F')) {
  28509. return dict.get('F');
  28510. } else if (dict.has('Unix')) {
  28511. return dict.get('Unix');
  28512. } else if (dict.has('Mac')) {
  28513. return dict.get('Mac');
  28514. } else if (dict.has('DOS')) {
  28515. return dict.get('DOS');
  28516. } else {
  28517. return null;
  28518. }
  28519. }
  28520. FileSpec.prototype = {
  28521. get filename() {
  28522. if (!this._filename && this.root) {
  28523. var filename = pickPlatformItem(this.root) || 'unnamed';
  28524. this._filename = stringToPDFString(filename).
  28525. replace(/\\\\/g, '\\').
  28526. replace(/\\\//g, '/').
  28527. replace(/\\/g, '/');
  28528. }
  28529. return this._filename;
  28530. },
  28531. get content() {
  28532. if (!this.contentAvailable) {
  28533. return null;
  28534. }
  28535. if (!this.contentRef && this.root) {
  28536. this.contentRef = pickPlatformItem(this.root.get('EF'));
  28537. }
  28538. var content = null;
  28539. if (this.contentRef) {
  28540. var xref = this.xref;
  28541. var fileObj = xref.fetchIfRef(this.contentRef);
  28542. if (fileObj && isStream(fileObj)) {
  28543. content = fileObj.getBytes();
  28544. } else {
  28545. warn('Embedded file specification points to non-existing/invalid ' +
  28546. 'content');
  28547. }
  28548. } else {
  28549. warn('Embedded file specification does not have a content');
  28550. }
  28551. return content;
  28552. },
  28553. get serializable() {
  28554. return {
  28555. filename: this.filename,
  28556. content: this.content
  28557. };
  28558. }
  28559. };
  28560. return FileSpec;
  28561. })();
  28562. /**
  28563. * A helper for loading missing data in object graphs. It traverses the graph
  28564. * depth first and queues up any objects that have missing data. Once it has
  28565. * has traversed as many objects that are available it attempts to bundle the
  28566. * missing data requests and then resume from the nodes that weren't ready.
  28567. *
  28568. * NOTE: It provides protection from circular references by keeping track of
  28569. * of loaded references. However, you must be careful not to load any graphs
  28570. * that have references to the catalog or other pages since that will cause the
  28571. * entire PDF document object graph to be traversed.
  28572. */
  28573. var ObjectLoader = (function() {
  28574. function mayHaveChildren(value) {
  28575. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  28576. }
  28577. function addChildren(node, nodesToVisit) {
  28578. var value;
  28579. if (isDict(node) || isStream(node)) {
  28580. var map;
  28581. if (isDict(node)) {
  28582. map = node.map;
  28583. } else {
  28584. map = node.dict.map;
  28585. }
  28586. for (var key in map) {
  28587. value = map[key];
  28588. if (mayHaveChildren(value)) {
  28589. nodesToVisit.push(value);
  28590. }
  28591. }
  28592. } else if (isArray(node)) {
  28593. for (var i = 0, ii = node.length; i < ii; i++) {
  28594. value = node[i];
  28595. if (mayHaveChildren(value)) {
  28596. nodesToVisit.push(value);
  28597. }
  28598. }
  28599. }
  28600. }
  28601. function ObjectLoader(obj, keys, xref) {
  28602. this.obj = obj;
  28603. this.keys = keys;
  28604. this.xref = xref;
  28605. this.refSet = null;
  28606. this.capability = null;
  28607. }
  28608. ObjectLoader.prototype = {
  28609. load: function ObjectLoader_load() {
  28610. var keys = this.keys;
  28611. this.capability = createPromiseCapability();
  28612. // Don't walk the graph if all the data is already loaded.
  28613. if (!(this.xref.stream instanceof ChunkedStream) ||
  28614. this.xref.stream.getMissingChunks().length === 0) {
  28615. this.capability.resolve();
  28616. return this.capability.promise;
  28617. }
  28618. this.refSet = new RefSet();
  28619. // Setup the initial nodes to visit.
  28620. var nodesToVisit = [];
  28621. for (var i = 0; i < keys.length; i++) {
  28622. nodesToVisit.push(this.obj[keys[i]]);
  28623. }
  28624. this._walk(nodesToVisit);
  28625. return this.capability.promise;
  28626. },
  28627. _walk: function ObjectLoader_walk(nodesToVisit) {
  28628. var nodesToRevisit = [];
  28629. var pendingRequests = [];
  28630. // DFS walk of the object graph.
  28631. while (nodesToVisit.length) {
  28632. var currentNode = nodesToVisit.pop();
  28633. // Only references or chunked streams can cause missing data exceptions.
  28634. if (isRef(currentNode)) {
  28635. // Skip nodes that have already been visited.
  28636. if (this.refSet.has(currentNode)) {
  28637. continue;
  28638. }
  28639. try {
  28640. var ref = currentNode;
  28641. this.refSet.put(ref);
  28642. currentNode = this.xref.fetch(currentNode);
  28643. } catch (e) {
  28644. if (!(e instanceof MissingDataException)) {
  28645. throw e;
  28646. }
  28647. nodesToRevisit.push(currentNode);
  28648. pendingRequests.push({ begin: e.begin, end: e.end });
  28649. }
  28650. }
  28651. if (currentNode && currentNode.getBaseStreams) {
  28652. var baseStreams = currentNode.getBaseStreams();
  28653. var foundMissingData = false;
  28654. for (var i = 0; i < baseStreams.length; i++) {
  28655. var stream = baseStreams[i];
  28656. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  28657. foundMissingData = true;
  28658. pendingRequests.push({
  28659. begin: stream.start,
  28660. end: stream.end
  28661. });
  28662. }
  28663. }
  28664. if (foundMissingData) {
  28665. nodesToRevisit.push(currentNode);
  28666. }
  28667. }
  28668. addChildren(currentNode, nodesToVisit);
  28669. }
  28670. if (pendingRequests.length) {
  28671. this.xref.stream.manager.requestRanges(pendingRequests).then(
  28672. function pendingRequestCallback() {
  28673. nodesToVisit = nodesToRevisit;
  28674. for (var i = 0; i < nodesToRevisit.length; i++) {
  28675. var node = nodesToRevisit[i];
  28676. // Remove any reference nodes from the currrent refset so they
  28677. // aren't skipped when we revist them.
  28678. if (isRef(node)) {
  28679. this.refSet.remove(node);
  28680. }
  28681. }
  28682. this._walk(nodesToVisit);
  28683. }.bind(this), this.capability.reject);
  28684. return;
  28685. }
  28686. // Everything is loaded.
  28687. this.refSet = null;
  28688. this.capability.resolve();
  28689. }
  28690. };
  28691. return ObjectLoader;
  28692. })();
  28693. exports.Catalog = Catalog;
  28694. exports.ObjectLoader = ObjectLoader;
  28695. exports.XRef = XRef;
  28696. }));
  28697. (function (root, factory) {
  28698. {
  28699. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  28700. root.pdfjsCoreParser);
  28701. }
  28702. }(this, function (exports, sharedUtil, coreParser) {
  28703. var error = sharedUtil.error;
  28704. var EOF = coreParser.EOF;
  28705. var Lexer = coreParser.Lexer;
  28706. var PostScriptParser = (function PostScriptParserClosure() {
  28707. function PostScriptParser(lexer) {
  28708. this.lexer = lexer;
  28709. this.operators = [];
  28710. this.token = null;
  28711. this.prev = null;
  28712. }
  28713. PostScriptParser.prototype = {
  28714. nextToken: function PostScriptParser_nextToken() {
  28715. this.prev = this.token;
  28716. this.token = this.lexer.getToken();
  28717. },
  28718. accept: function PostScriptParser_accept(type) {
  28719. if (this.token.type === type) {
  28720. this.nextToken();
  28721. return true;
  28722. }
  28723. return false;
  28724. },
  28725. expect: function PostScriptParser_expect(type) {
  28726. if (this.accept(type)) {
  28727. return true;
  28728. }
  28729. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  28730. type + '.');
  28731. },
  28732. parse: function PostScriptParser_parse() {
  28733. this.nextToken();
  28734. this.expect(PostScriptTokenTypes.LBRACE);
  28735. this.parseBlock();
  28736. this.expect(PostScriptTokenTypes.RBRACE);
  28737. return this.operators;
  28738. },
  28739. parseBlock: function PostScriptParser_parseBlock() {
  28740. while (true) {
  28741. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  28742. this.operators.push(this.prev.value);
  28743. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  28744. this.operators.push(this.prev.value);
  28745. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28746. this.parseCondition();
  28747. } else {
  28748. return;
  28749. }
  28750. }
  28751. },
  28752. parseCondition: function PostScriptParser_parseCondition() {
  28753. // Add two place holders that will be updated later
  28754. var conditionLocation = this.operators.length;
  28755. this.operators.push(null, null);
  28756. this.parseBlock();
  28757. this.expect(PostScriptTokenTypes.RBRACE);
  28758. if (this.accept(PostScriptTokenTypes.IF)) {
  28759. // The true block is right after the 'if' so it just falls through on
  28760. // true else it jumps and skips the true block.
  28761. this.operators[conditionLocation] = this.operators.length;
  28762. this.operators[conditionLocation + 1] = 'jz';
  28763. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28764. var jumpLocation = this.operators.length;
  28765. this.operators.push(null, null);
  28766. var endOfTrue = this.operators.length;
  28767. this.parseBlock();
  28768. this.expect(PostScriptTokenTypes.RBRACE);
  28769. this.expect(PostScriptTokenTypes.IFELSE);
  28770. // The jump is added at the end of the true block to skip the false
  28771. // block.
  28772. this.operators[jumpLocation] = this.operators.length;
  28773. this.operators[jumpLocation + 1] = 'j';
  28774. this.operators[conditionLocation] = endOfTrue;
  28775. this.operators[conditionLocation + 1] = 'jz';
  28776. } else {
  28777. error('PS Function: error parsing conditional.');
  28778. }
  28779. }
  28780. };
  28781. return PostScriptParser;
  28782. })();
  28783. var PostScriptTokenTypes = {
  28784. LBRACE: 0,
  28785. RBRACE: 1,
  28786. NUMBER: 2,
  28787. OPERATOR: 3,
  28788. IF: 4,
  28789. IFELSE: 5
  28790. };
  28791. var PostScriptToken = (function PostScriptTokenClosure() {
  28792. function PostScriptToken(type, value) {
  28793. this.type = type;
  28794. this.value = value;
  28795. }
  28796. var opCache = {};
  28797. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  28798. var opValue = opCache[op];
  28799. if (opValue) {
  28800. return opValue;
  28801. }
  28802. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  28803. };
  28804. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  28805. '{');
  28806. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  28807. '}');
  28808. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  28809. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  28810. 'IFELSE');
  28811. return PostScriptToken;
  28812. })();
  28813. var PostScriptLexer = (function PostScriptLexerClosure() {
  28814. function PostScriptLexer(stream) {
  28815. this.stream = stream;
  28816. this.nextChar();
  28817. this.strBuf = [];
  28818. }
  28819. PostScriptLexer.prototype = {
  28820. nextChar: function PostScriptLexer_nextChar() {
  28821. return (this.currentChar = this.stream.getByte());
  28822. },
  28823. getToken: function PostScriptLexer_getToken() {
  28824. var comment = false;
  28825. var ch = this.currentChar;
  28826. // skip comments
  28827. while (true) {
  28828. if (ch < 0) {
  28829. return EOF;
  28830. }
  28831. if (comment) {
  28832. if (ch === 0x0A || ch === 0x0D) {
  28833. comment = false;
  28834. }
  28835. } else if (ch === 0x25) { // '%'
  28836. comment = true;
  28837. } else if (!Lexer.isSpace(ch)) {
  28838. break;
  28839. }
  28840. ch = this.nextChar();
  28841. }
  28842. switch (ch | 0) {
  28843. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28844. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28845. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28846. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  28847. this.getNumber());
  28848. case 0x7B: // '{'
  28849. this.nextChar();
  28850. return PostScriptToken.LBRACE;
  28851. case 0x7D: // '}'
  28852. this.nextChar();
  28853. return PostScriptToken.RBRACE;
  28854. }
  28855. // operator
  28856. var strBuf = this.strBuf;
  28857. strBuf.length = 0;
  28858. strBuf[0] = String.fromCharCode(ch);
  28859. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  28860. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  28861. strBuf.push(String.fromCharCode(ch));
  28862. }
  28863. var str = strBuf.join('');
  28864. switch (str.toLowerCase()) {
  28865. case 'if':
  28866. return PostScriptToken.IF;
  28867. case 'ifelse':
  28868. return PostScriptToken.IFELSE;
  28869. default:
  28870. return PostScriptToken.getOperator(str);
  28871. }
  28872. },
  28873. getNumber: function PostScriptLexer_getNumber() {
  28874. var ch = this.currentChar;
  28875. var strBuf = this.strBuf;
  28876. strBuf.length = 0;
  28877. strBuf[0] = String.fromCharCode(ch);
  28878. while ((ch = this.nextChar()) >= 0) {
  28879. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  28880. ch === 0x2D || ch === 0x2E) { // '-', '.'
  28881. strBuf.push(String.fromCharCode(ch));
  28882. } else {
  28883. break;
  28884. }
  28885. }
  28886. var value = parseFloat(strBuf.join(''));
  28887. if (isNaN(value)) {
  28888. error('Invalid floating point number: ' + value);
  28889. }
  28890. return value;
  28891. }
  28892. };
  28893. return PostScriptLexer;
  28894. })();
  28895. exports.PostScriptLexer = PostScriptLexer;
  28896. exports.PostScriptParser = PostScriptParser;
  28897. }));
  28898. (function (root, factory) {
  28899. {
  28900. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  28901. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  28902. root.pdfjsDisplayMetadata, root.pdfjsSharedGlobal);
  28903. }
  28904. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  28905. displayMetadata, sharedGlobal, amdRequire) {
  28906. var InvalidPDFException = sharedUtil.InvalidPDFException;
  28907. var MessageHandler = sharedUtil.MessageHandler;
  28908. var MissingPDFException = sharedUtil.MissingPDFException;
  28909. var PasswordResponses = sharedUtil.PasswordResponses;
  28910. var PasswordException = sharedUtil.PasswordException;
  28911. var StatTimer = sharedUtil.StatTimer;
  28912. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  28913. var UnknownErrorException = sharedUtil.UnknownErrorException;
  28914. var Util = sharedUtil.Util;
  28915. var createPromiseCapability = sharedUtil.createPromiseCapability;
  28916. var combineUrl = sharedUtil.combineUrl;
  28917. var error = sharedUtil.error;
  28918. var deprecated = sharedUtil.deprecated;
  28919. var info = sharedUtil.info;
  28920. var isArrayBuffer = sharedUtil.isArrayBuffer;
  28921. var loadJpegStream = sharedUtil.loadJpegStream;
  28922. var stringToBytes = sharedUtil.stringToBytes;
  28923. var warn = sharedUtil.warn;
  28924. var FontFaceObject = displayFontLoader.FontFaceObject;
  28925. var FontLoader = displayFontLoader.FontLoader;
  28926. var CanvasGraphics = displayCanvas.CanvasGraphics;
  28927. var createScratchCanvas = displayCanvas.createScratchCanvas;
  28928. var Metadata = displayMetadata.Metadata;
  28929. var PDFJS = sharedGlobal.PDFJS;
  28930. var globalScope = sharedGlobal.globalScope;
  28931. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  28932. /**
  28933. * The maximum allowed image size in total pixels e.g. width * height. Images
  28934. * above this value will not be drawn. Use -1 for no limit.
  28935. * @var {number}
  28936. */
  28937. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  28938. -1 : PDFJS.maxImageSize);
  28939. /**
  28940. * The url of where the predefined Adobe CMaps are located. Include trailing
  28941. * slash.
  28942. * @var {string}
  28943. */
  28944. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  28945. /**
  28946. * Specifies if CMaps are binary packed.
  28947. * @var {boolean}
  28948. */
  28949. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  28950. /**
  28951. * By default fonts are converted to OpenType fonts and loaded via font face
  28952. * rules. If disabled, the font will be rendered using a built in font renderer
  28953. * that constructs the glyphs with primitive path commands.
  28954. * @var {boolean}
  28955. */
  28956. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  28957. false : PDFJS.disableFontFace);
  28958. /**
  28959. * Path for image resources, mainly for annotation icons. Include trailing
  28960. * slash.
  28961. * @var {string}
  28962. */
  28963. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  28964. '' : PDFJS.imageResourcesPath);
  28965. /**
  28966. * Disable the web worker and run all code on the main thread. This will happen
  28967. * automatically if the browser doesn't support workers or sending typed arrays
  28968. * to workers.
  28969. * @var {boolean}
  28970. */
  28971. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  28972. false : PDFJS.disableWorker);
  28973. /**
  28974. * Path and filename of the worker file. Required when the worker is enabled in
  28975. * development mode. If unspecified in the production build, the worker will be
  28976. * loaded based on the location of the pdf.js file. It is recommended that
  28977. * the workerSrc is set in a custom application to prevent issues caused by
  28978. * third-party frameworks and libraries.
  28979. * @var {string}
  28980. */
  28981. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  28982. /**
  28983. * Disable range request loading of PDF files. When enabled and if the server
  28984. * supports partial content requests then the PDF will be fetched in chunks.
  28985. * Enabled (false) by default.
  28986. * @var {boolean}
  28987. */
  28988. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  28989. false : PDFJS.disableRange);
  28990. /**
  28991. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  28992. * in chunks. This default behavior can be disabled.
  28993. * @var {boolean}
  28994. */
  28995. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  28996. false : PDFJS.disableStream);
  28997. /**
  28998. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  28999. * will automatically keep fetching more data even if it isn't needed to display
  29000. * the current page. This default behavior can be disabled.
  29001. *
  29002. * NOTE: It is also necessary to disable streaming, see above,
  29003. * in order for disabling of pre-fetching to work correctly.
  29004. * @var {boolean}
  29005. */
  29006. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  29007. false : PDFJS.disableAutoFetch);
  29008. /**
  29009. * Enables special hooks for debugging PDF.js.
  29010. * @var {boolean}
  29011. */
  29012. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  29013. /**
  29014. * Enables transfer usage in postMessage for ArrayBuffers.
  29015. * @var {boolean}
  29016. */
  29017. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  29018. true : PDFJS.postMessageTransfers);
  29019. /**
  29020. * Disables URL.createObjectURL usage.
  29021. * @var {boolean}
  29022. */
  29023. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  29024. false : PDFJS.disableCreateObjectURL);
  29025. /**
  29026. * Disables WebGL usage.
  29027. * @var {boolean}
  29028. */
  29029. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  29030. true : PDFJS.disableWebGL);
  29031. /**
  29032. * Disables fullscreen support, and by extension Presentation Mode,
  29033. * in browsers which support the fullscreen API.
  29034. * @var {boolean}
  29035. */
  29036. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  29037. false : PDFJS.disableFullscreen);
  29038. /**
  29039. * Enables CSS only zooming.
  29040. * @var {boolean}
  29041. */
  29042. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  29043. false : PDFJS.useOnlyCssZoom);
  29044. /**
  29045. * Controls the logging level.
  29046. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  29047. * - errors
  29048. * - warnings [default]
  29049. * - infos
  29050. * @var {number}
  29051. */
  29052. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  29053. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  29054. /**
  29055. * The maximum supported canvas size in total pixels e.g. width * height.
  29056. * The default value is 4096 * 4096. Use -1 for no limit.
  29057. * @var {number}
  29058. */
  29059. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  29060. 16777216 : PDFJS.maxCanvasPixels);
  29061. /**
  29062. * (Deprecated) Opens external links in a new window if enabled.
  29063. * The default behavior opens external links in the PDF.js window.
  29064. *
  29065. * NOTE: This property has been deprecated, please use
  29066. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  29067. * @var {boolean}
  29068. */
  29069. PDFJS.openExternalLinksInNewWindow = (
  29070. PDFJS.openExternalLinksInNewWindow === undefined ?
  29071. false : PDFJS.openExternalLinksInNewWindow);
  29072. /**
  29073. * Specifies the |target| attribute for external links.
  29074. * The constants from PDFJS.LinkTarget should be used:
  29075. * - NONE [default]
  29076. * - SELF
  29077. * - BLANK
  29078. * - PARENT
  29079. * - TOP
  29080. * @var {number}
  29081. */
  29082. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  29083. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  29084. /**
  29085. * Specifies the |rel| attribute for external links. Defaults to stripping
  29086. * the referrer.
  29087. * @var {string}
  29088. */
  29089. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  29090. 'noreferrer' : PDFJS.externalLinkRel);
  29091. /**
  29092. * Determines if we can eval strings as JS. Primarily used to improve
  29093. * performance for font rendering.
  29094. * @var {boolean}
  29095. */
  29096. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  29097. true : PDFJS.isEvalSupported);
  29098. /**
  29099. * Document initialization / loading parameters object.
  29100. *
  29101. * @typedef {Object} DocumentInitParameters
  29102. * @property {string} url - The URL of the PDF.
  29103. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  29104. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  29105. * use atob() to convert it to a binary string first.
  29106. * @property {Object} httpHeaders - Basic authentication headers.
  29107. * @property {boolean} withCredentials - Indicates whether or not cross-site
  29108. * Access-Control requests should be made using credentials such as cookies
  29109. * or authorization headers. The default is false.
  29110. * @property {string} password - For decrypting password-protected PDFs.
  29111. * @property {TypedArray} initialData - A typed array with the first portion or
  29112. * all of the pdf data. Used by the extension since some data is already
  29113. * loaded before the switch to range requests.
  29114. * @property {number} length - The PDF file length. It's used for progress
  29115. * reports and range requests operations.
  29116. * @property {PDFDataRangeTransport} range
  29117. * @property {number} rangeChunkSize - Optional parameter to specify
  29118. * maximum number of bytes fetched per range request. The default value is
  29119. * 2^16 = 65536.
  29120. * @property {PDFWorker} worker - The worker that will be used for the loading
  29121. * and parsing of the PDF data.
  29122. */
  29123. /**
  29124. * @typedef {Object} PDFDocumentStats
  29125. * @property {Array} streamTypes - Used stream types in the document (an item
  29126. * is set to true if specific stream ID was used in the document).
  29127. * @property {Array} fontTypes - Used font type in the document (an item is set
  29128. * to true if specific font ID was used in the document).
  29129. */
  29130. /**
  29131. * This is the main entry point for loading a PDF and interacting with it.
  29132. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  29133. * is used, which means it must follow the same origin rules that any XHR does
  29134. * e.g. No cross domain requests without CORS.
  29135. *
  29136. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  29137. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  29138. * already populated with data or parameter object.
  29139. *
  29140. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  29141. * if you want to manually serve range requests for data in the PDF.
  29142. *
  29143. * @param {function} passwordCallback (deprecated) It is used to request a
  29144. * password if wrong or no password was provided. The callback receives two
  29145. * parameters: function that needs to be called with new password and reason
  29146. * (see {PasswordResponses}).
  29147. *
  29148. * @param {function} progressCallback (deprecated) It is used to be able to
  29149. * monitor the loading progress of the PDF file (necessary to implement e.g.
  29150. * a loading bar). The callback receives an {Object} with the properties:
  29151. * {number} loaded and {number} total.
  29152. *
  29153. * @return {PDFDocumentLoadingTask}
  29154. */
  29155. PDFJS.getDocument = function getDocument(src,
  29156. pdfDataRangeTransport,
  29157. passwordCallback,
  29158. progressCallback) {
  29159. var task = new PDFDocumentLoadingTask();
  29160. // Support of the obsolete arguments (for compatibility with API v1.0)
  29161. if (arguments.length > 1) {
  29162. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  29163. 'passwordCallback or progressCallback argument');
  29164. }
  29165. if (pdfDataRangeTransport) {
  29166. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  29167. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  29168. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  29169. pdfDataRangeTransport.length = src.length;
  29170. pdfDataRangeTransport.initialData = src.initialData;
  29171. if (!pdfDataRangeTransport.abort) {
  29172. pdfDataRangeTransport.abort = function () {};
  29173. }
  29174. }
  29175. src = Object.create(src);
  29176. src.range = pdfDataRangeTransport;
  29177. }
  29178. task.onPassword = passwordCallback || null;
  29179. task.onProgress = progressCallback || null;
  29180. var source;
  29181. if (typeof src === 'string') {
  29182. source = { url: src };
  29183. } else if (isArrayBuffer(src)) {
  29184. source = { data: src };
  29185. } else if (src instanceof PDFDataRangeTransport) {
  29186. source = { range: src };
  29187. } else {
  29188. if (typeof src !== 'object') {
  29189. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  29190. 'string or a parameter object');
  29191. }
  29192. if (!src.url && !src.data && !src.range) {
  29193. error('Invalid parameter object: need either .data, .range or .url');
  29194. }
  29195. source = src;
  29196. }
  29197. var params = {};
  29198. var rangeTransport = null;
  29199. var worker = null;
  29200. for (var key in source) {
  29201. if (key === 'url' && typeof window !== 'undefined') {
  29202. // The full path is required in the 'url' field.
  29203. params[key] = combineUrl(window.location.href, source[key]);
  29204. continue;
  29205. } else if (key === 'range') {
  29206. rangeTransport = source[key];
  29207. continue;
  29208. } else if (key === 'worker') {
  29209. worker = source[key];
  29210. continue;
  29211. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  29212. // Converting string or array-like data to Uint8Array.
  29213. var pdfBytes = source[key];
  29214. if (typeof pdfBytes === 'string') {
  29215. params[key] = stringToBytes(pdfBytes);
  29216. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  29217. !isNaN(pdfBytes.length)) {
  29218. params[key] = new Uint8Array(pdfBytes);
  29219. } else if (isArrayBuffer(pdfBytes)) {
  29220. params[key] = new Uint8Array(pdfBytes);
  29221. } else {
  29222. error('Invalid PDF binary data: either typed array, string or ' +
  29223. 'array-like object is expected in the data property.');
  29224. }
  29225. continue;
  29226. }
  29227. params[key] = source[key];
  29228. }
  29229. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  29230. if (!worker) {
  29231. // Worker was not provided -- creating and owning our own.
  29232. worker = new PDFWorker();
  29233. task._worker = worker;
  29234. }
  29235. var docId = task.docId;
  29236. worker.promise.then(function () {
  29237. if (task.destroyed) {
  29238. throw new Error('Loading aborted');
  29239. }
  29240. return _fetchDocument(worker, params, rangeTransport, docId).then(
  29241. function (workerId) {
  29242. if (task.destroyed) {
  29243. throw new Error('Loading aborted');
  29244. }
  29245. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  29246. messageHandler.send('Ready', null);
  29247. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  29248. task._transport = transport;
  29249. });
  29250. }).catch(task._capability.reject);
  29251. return task;
  29252. };
  29253. /**
  29254. * Starts fetching of specified PDF document/data.
  29255. * @param {PDFWorker} worker
  29256. * @param {Object} source
  29257. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  29258. * @param {string} docId Unique document id, used as MessageHandler id.
  29259. * @returns {Promise} The promise, which is resolved when worker id of
  29260. * MessageHandler is known.
  29261. * @private
  29262. */
  29263. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  29264. if (worker.destroyed) {
  29265. return Promise.reject(new Error('Worker was destroyed'));
  29266. }
  29267. source.disableAutoFetch = PDFJS.disableAutoFetch;
  29268. source.disableStream = PDFJS.disableStream;
  29269. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  29270. if (pdfDataRangeTransport) {
  29271. source.length = pdfDataRangeTransport.length;
  29272. source.initialData = pdfDataRangeTransport.initialData;
  29273. }
  29274. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  29275. docId: docId,
  29276. source: source,
  29277. disableRange: PDFJS.disableRange,
  29278. maxImageSize: PDFJS.maxImageSize,
  29279. cMapUrl: PDFJS.cMapUrl,
  29280. cMapPacked: PDFJS.cMapPacked,
  29281. disableFontFace: PDFJS.disableFontFace,
  29282. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  29283. verbosity: PDFJS.verbosity
  29284. }).then(function (workerId) {
  29285. if (worker.destroyed) {
  29286. throw new Error('Worker was destroyed');
  29287. }
  29288. return workerId;
  29289. });
  29290. }
  29291. /**
  29292. * PDF document loading operation.
  29293. * @class
  29294. * @alias PDFDocumentLoadingTask
  29295. */
  29296. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  29297. var nextDocumentId = 0;
  29298. /** @constructs PDFDocumentLoadingTask */
  29299. function PDFDocumentLoadingTask() {
  29300. this._capability = createPromiseCapability();
  29301. this._transport = null;
  29302. this._worker = null;
  29303. /**
  29304. * Unique document loading task id -- used in MessageHandlers.
  29305. * @type {string}
  29306. */
  29307. this.docId = 'd' + (nextDocumentId++);
  29308. /**
  29309. * Shows if loading task is destroyed.
  29310. * @type {boolean}
  29311. */
  29312. this.destroyed = false;
  29313. /**
  29314. * Callback to request a password if wrong or no password was provided.
  29315. * The callback receives two parameters: function that needs to be called
  29316. * with new password and reason (see {PasswordResponses}).
  29317. */
  29318. this.onPassword = null;
  29319. /**
  29320. * Callback to be able to monitor the loading progress of the PDF file
  29321. * (necessary to implement e.g. a loading bar). The callback receives
  29322. * an {Object} with the properties: {number} loaded and {number} total.
  29323. */
  29324. this.onProgress = null;
  29325. /**
  29326. * Callback to when unsupported feature is used. The callback receives
  29327. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  29328. */
  29329. this.onUnsupportedFeature = null;
  29330. }
  29331. PDFDocumentLoadingTask.prototype =
  29332. /** @lends PDFDocumentLoadingTask.prototype */ {
  29333. /**
  29334. * @return {Promise}
  29335. */
  29336. get promise() {
  29337. return this._capability.promise;
  29338. },
  29339. /**
  29340. * Aborts all network requests and destroys worker.
  29341. * @return {Promise} A promise that is resolved after destruction activity
  29342. * is completed.
  29343. */
  29344. destroy: function () {
  29345. this.destroyed = true;
  29346. var transportDestroyed = !this._transport ? Promise.resolve() :
  29347. this._transport.destroy();
  29348. return transportDestroyed.then(function () {
  29349. this._transport = null;
  29350. if (this._worker) {
  29351. this._worker.destroy();
  29352. this._worker = null;
  29353. }
  29354. }.bind(this));
  29355. },
  29356. /**
  29357. * Registers callbacks to indicate the document loading completion.
  29358. *
  29359. * @param {function} onFulfilled The callback for the loading completion.
  29360. * @param {function} onRejected The callback for the loading failure.
  29361. * @return {Promise} A promise that is resolved after the onFulfilled or
  29362. * onRejected callback.
  29363. */
  29364. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  29365. return this.promise.then.apply(this.promise, arguments);
  29366. }
  29367. };
  29368. return PDFDocumentLoadingTask;
  29369. })();
  29370. /**
  29371. * Abstract class to support range requests file loading.
  29372. * @class
  29373. * @alias PDFJS.PDFDataRangeTransport
  29374. * @param {number} length
  29375. * @param {Uint8Array} initialData
  29376. */
  29377. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  29378. function PDFDataRangeTransport(length, initialData) {
  29379. this.length = length;
  29380. this.initialData = initialData;
  29381. this._rangeListeners = [];
  29382. this._progressListeners = [];
  29383. this._progressiveReadListeners = [];
  29384. this._readyCapability = createPromiseCapability();
  29385. }
  29386. PDFDataRangeTransport.prototype =
  29387. /** @lends PDFDataRangeTransport.prototype */ {
  29388. addRangeListener:
  29389. function PDFDataRangeTransport_addRangeListener(listener) {
  29390. this._rangeListeners.push(listener);
  29391. },
  29392. addProgressListener:
  29393. function PDFDataRangeTransport_addProgressListener(listener) {
  29394. this._progressListeners.push(listener);
  29395. },
  29396. addProgressiveReadListener:
  29397. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  29398. this._progressiveReadListeners.push(listener);
  29399. },
  29400. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  29401. var listeners = this._rangeListeners;
  29402. for (var i = 0, n = listeners.length; i < n; ++i) {
  29403. listeners[i](begin, chunk);
  29404. }
  29405. },
  29406. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  29407. this._readyCapability.promise.then(function () {
  29408. var listeners = this._progressListeners;
  29409. for (var i = 0, n = listeners.length; i < n; ++i) {
  29410. listeners[i](loaded);
  29411. }
  29412. }.bind(this));
  29413. },
  29414. onDataProgressiveRead:
  29415. function PDFDataRangeTransport_onDataProgress(chunk) {
  29416. this._readyCapability.promise.then(function () {
  29417. var listeners = this._progressiveReadListeners;
  29418. for (var i = 0, n = listeners.length; i < n; ++i) {
  29419. listeners[i](chunk);
  29420. }
  29421. }.bind(this));
  29422. },
  29423. transportReady: function PDFDataRangeTransport_transportReady() {
  29424. this._readyCapability.resolve();
  29425. },
  29426. requestDataRange:
  29427. function PDFDataRangeTransport_requestDataRange(begin, end) {
  29428. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  29429. },
  29430. abort: function PDFDataRangeTransport_abort() {
  29431. }
  29432. };
  29433. return PDFDataRangeTransport;
  29434. })();
  29435. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  29436. /**
  29437. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  29438. * properties that can be read synchronously.
  29439. * @class
  29440. * @alias PDFDocumentProxy
  29441. */
  29442. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  29443. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  29444. this.pdfInfo = pdfInfo;
  29445. this.transport = transport;
  29446. this.loadingTask = loadingTask;
  29447. }
  29448. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  29449. /**
  29450. * @return {number} Total number of pages the PDF contains.
  29451. */
  29452. get numPages() {
  29453. return this.pdfInfo.numPages;
  29454. },
  29455. /**
  29456. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  29457. * unique.
  29458. */
  29459. get fingerprint() {
  29460. return this.pdfInfo.fingerprint;
  29461. },
  29462. /**
  29463. * @param {number} pageNumber The page number to get. The first page is 1.
  29464. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  29465. * object.
  29466. */
  29467. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  29468. return this.transport.getPage(pageNumber);
  29469. },
  29470. /**
  29471. * @param {{num: number, gen: number}} ref The page reference. Must have
  29472. * the 'num' and 'gen' properties.
  29473. * @return {Promise} A promise that is resolved with the page index that is
  29474. * associated with the reference.
  29475. */
  29476. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  29477. return this.transport.getPageIndex(ref);
  29478. },
  29479. /**
  29480. * @return {Promise} A promise that is resolved with a lookup table for
  29481. * mapping named destinations to reference numbers.
  29482. *
  29483. * This can be slow for large documents: use getDestination instead
  29484. */
  29485. getDestinations: function PDFDocumentProxy_getDestinations() {
  29486. return this.transport.getDestinations();
  29487. },
  29488. /**
  29489. * @param {string} id The named destination to get.
  29490. * @return {Promise} A promise that is resolved with all information
  29491. * of the given named destination.
  29492. */
  29493. getDestination: function PDFDocumentProxy_getDestination(id) {
  29494. return this.transport.getDestination(id);
  29495. },
  29496. /**
  29497. * @return {Promise} A promise that is resolved with a lookup table for
  29498. * mapping named attachments to their content.
  29499. */
  29500. getAttachments: function PDFDocumentProxy_getAttachments() {
  29501. return this.transport.getAttachments();
  29502. },
  29503. /**
  29504. * @return {Promise} A promise that is resolved with an array of all the
  29505. * JavaScript strings in the name tree.
  29506. */
  29507. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  29508. return this.transport.getJavaScript();
  29509. },
  29510. /**
  29511. * @return {Promise} A promise that is resolved with an {Array} that is a
  29512. * tree outline (if it has one) of the PDF. The tree is in the format of:
  29513. * [
  29514. * {
  29515. * title: string,
  29516. * bold: boolean,
  29517. * italic: boolean,
  29518. * color: rgb array,
  29519. * dest: dest obj,
  29520. * items: array of more items like this
  29521. * },
  29522. * ...
  29523. * ].
  29524. */
  29525. getOutline: function PDFDocumentProxy_getOutline() {
  29526. return this.transport.getOutline();
  29527. },
  29528. /**
  29529. * @return {Promise} A promise that is resolved with an {Object} that has
  29530. * info and metadata properties. Info is an {Object} filled with anything
  29531. * available in the information dictionary and similarly metadata is a
  29532. * {Metadata} object with information from the metadata section of the PDF.
  29533. */
  29534. getMetadata: function PDFDocumentProxy_getMetadata() {
  29535. return this.transport.getMetadata();
  29536. },
  29537. /**
  29538. * @return {Promise} A promise that is resolved with a TypedArray that has
  29539. * the raw data from the PDF.
  29540. */
  29541. getData: function PDFDocumentProxy_getData() {
  29542. return this.transport.getData();
  29543. },
  29544. /**
  29545. * @return {Promise} A promise that is resolved when the document's data
  29546. * is loaded. It is resolved with an {Object} that contains the length
  29547. * property that indicates size of the PDF data in bytes.
  29548. */
  29549. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  29550. return this.transport.downloadInfoCapability.promise;
  29551. },
  29552. /**
  29553. * @return {Promise} A promise this is resolved with current stats about
  29554. * document structures (see {@link PDFDocumentStats}).
  29555. */
  29556. getStats: function PDFDocumentProxy_getStats() {
  29557. return this.transport.getStats();
  29558. },
  29559. /**
  29560. * Cleans up resources allocated by the document, e.g. created @font-face.
  29561. */
  29562. cleanup: function PDFDocumentProxy_cleanup() {
  29563. this.transport.startCleanup();
  29564. },
  29565. /**
  29566. * Destroys current document instance and terminates worker.
  29567. */
  29568. destroy: function PDFDocumentProxy_destroy() {
  29569. return this.loadingTask.destroy();
  29570. }
  29571. };
  29572. return PDFDocumentProxy;
  29573. })();
  29574. /**
  29575. * Page getTextContent parameters.
  29576. *
  29577. * @typedef {Object} getTextContentParameters
  29578. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  29579. * whitespace with standard spaces (0x20). The default value is `false`.
  29580. */
  29581. /**
  29582. * Page text content.
  29583. *
  29584. * @typedef {Object} TextContent
  29585. * @property {array} items - array of {@link TextItem}
  29586. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  29587. * name.
  29588. */
  29589. /**
  29590. * Page text content part.
  29591. *
  29592. * @typedef {Object} TextItem
  29593. * @property {string} str - text content.
  29594. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  29595. * @property {array} transform - transformation matrix.
  29596. * @property {number} width - width in device space.
  29597. * @property {number} height - height in device space.
  29598. * @property {string} fontName - font name used by pdf.js for converted font.
  29599. */
  29600. /**
  29601. * Text style.
  29602. *
  29603. * @typedef {Object} TextStyle
  29604. * @property {number} ascent - font ascent.
  29605. * @property {number} descent - font descent.
  29606. * @property {boolean} vertical - text is in vertical mode.
  29607. * @property {string} fontFamily - possible font family
  29608. */
  29609. /**
  29610. * Page annotation parameters.
  29611. *
  29612. * @typedef {Object} GetAnnotationsParameters
  29613. * @param {string} intent - Determines the annotations that will be fetched,
  29614. * can be either 'display' (viewable annotations) or 'print'
  29615. * (printable annotations).
  29616. * If the parameter is omitted, all annotations are fetched.
  29617. */
  29618. /**
  29619. * Page render parameters.
  29620. *
  29621. * @typedef {Object} RenderParameters
  29622. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  29623. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  29624. * calling of PDFPage.getViewport method.
  29625. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  29626. * (default value is 'display').
  29627. * @property {Array} transform - (optional) Additional transform, applied
  29628. * just before viewport transform.
  29629. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  29630. * endLayout and appendImage functions.
  29631. * @property {function} continueCallback - (deprecated) A function that will be
  29632. * called each time the rendering is paused. To continue
  29633. * rendering call the function that is the first argument
  29634. * to the callback.
  29635. */
  29636. /**
  29637. * PDF page operator list.
  29638. *
  29639. * @typedef {Object} PDFOperatorList
  29640. * @property {Array} fnArray - Array containing the operator functions.
  29641. * @property {Array} argsArray - Array containing the arguments of the
  29642. * functions.
  29643. */
  29644. /**
  29645. * Proxy to a PDFPage in the worker thread.
  29646. * @class
  29647. * @alias PDFPageProxy
  29648. */
  29649. var PDFPageProxy = (function PDFPageProxyClosure() {
  29650. function PDFPageProxy(pageIndex, pageInfo, transport) {
  29651. this.pageIndex = pageIndex;
  29652. this.pageInfo = pageInfo;
  29653. this.transport = transport;
  29654. this.stats = new StatTimer();
  29655. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  29656. this.commonObjs = transport.commonObjs;
  29657. this.objs = new PDFObjects();
  29658. this.cleanupAfterRender = false;
  29659. this.pendingCleanup = false;
  29660. this.intentStates = {};
  29661. this.destroyed = false;
  29662. }
  29663. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  29664. /**
  29665. * @return {number} Page number of the page. First page is 1.
  29666. */
  29667. get pageNumber() {
  29668. return this.pageIndex + 1;
  29669. },
  29670. /**
  29671. * @return {number} The number of degrees the page is rotated clockwise.
  29672. */
  29673. get rotate() {
  29674. return this.pageInfo.rotate;
  29675. },
  29676. /**
  29677. * @return {Object} The reference that points to this page. It has 'num' and
  29678. * 'gen' properties.
  29679. */
  29680. get ref() {
  29681. return this.pageInfo.ref;
  29682. },
  29683. /**
  29684. * @return {Array} An array of the visible portion of the PDF page in the
  29685. * user space units - [x1, y1, x2, y2].
  29686. */
  29687. get view() {
  29688. return this.pageInfo.view;
  29689. },
  29690. /**
  29691. * @param {number} scale The desired scale of the viewport.
  29692. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  29693. * defaults to the page rotation.
  29694. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  29695. * along with transforms required for rendering.
  29696. */
  29697. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  29698. if (arguments.length < 2) {
  29699. rotate = this.rotate;
  29700. }
  29701. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  29702. },
  29703. /**
  29704. * @param {GetAnnotationsParameters} params - Annotation parameters.
  29705. * @return {Promise} A promise that is resolved with an {Array} of the
  29706. * annotation objects.
  29707. */
  29708. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  29709. var intent = (params && params.intent) || null;
  29710. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  29711. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  29712. intent);
  29713. this.annotationsIntent = intent;
  29714. }
  29715. return this.annotationsPromise;
  29716. },
  29717. /**
  29718. * Begins the process of rendering a page to the desired context.
  29719. * @param {RenderParameters} params Page render parameters.
  29720. * @return {RenderTask} An object that contains the promise, which
  29721. * is resolved when the page finishes rendering.
  29722. */
  29723. render: function PDFPageProxy_render(params) {
  29724. var stats = this.stats;
  29725. stats.time('Overall');
  29726. // If there was a pending destroy cancel it so no cleanup happens during
  29727. // this call to render.
  29728. this.pendingCleanup = false;
  29729. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  29730. if (!this.intentStates[renderingIntent]) {
  29731. this.intentStates[renderingIntent] = {};
  29732. }
  29733. var intentState = this.intentStates[renderingIntent];
  29734. // If there's no displayReadyCapability yet, then the operatorList
  29735. // was never requested before. Make the request and create the promise.
  29736. if (!intentState.displayReadyCapability) {
  29737. intentState.receivingOperatorList = true;
  29738. intentState.displayReadyCapability = createPromiseCapability();
  29739. intentState.operatorList = {
  29740. fnArray: [],
  29741. argsArray: [],
  29742. lastChunk: false
  29743. };
  29744. this.stats.time('Page Request');
  29745. this.transport.messageHandler.send('RenderPageRequest', {
  29746. pageIndex: this.pageNumber - 1,
  29747. intent: renderingIntent
  29748. });
  29749. }
  29750. var internalRenderTask = new InternalRenderTask(complete, params,
  29751. this.objs,
  29752. this.commonObjs,
  29753. intentState.operatorList,
  29754. this.pageNumber);
  29755. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  29756. if (!intentState.renderTasks) {
  29757. intentState.renderTasks = [];
  29758. }
  29759. intentState.renderTasks.push(internalRenderTask);
  29760. var renderTask = internalRenderTask.task;
  29761. // Obsolete parameter support
  29762. if (params.continueCallback) {
  29763. deprecated('render is used with continueCallback parameter');
  29764. renderTask.onContinue = params.continueCallback;
  29765. }
  29766. var self = this;
  29767. intentState.displayReadyCapability.promise.then(
  29768. function pageDisplayReadyPromise(transparency) {
  29769. if (self.pendingCleanup) {
  29770. complete();
  29771. return;
  29772. }
  29773. stats.time('Rendering');
  29774. internalRenderTask.initalizeGraphics(transparency);
  29775. internalRenderTask.operatorListChanged();
  29776. },
  29777. function pageDisplayReadPromiseError(reason) {
  29778. complete(reason);
  29779. }
  29780. );
  29781. function complete(error) {
  29782. var i = intentState.renderTasks.indexOf(internalRenderTask);
  29783. if (i >= 0) {
  29784. intentState.renderTasks.splice(i, 1);
  29785. }
  29786. if (self.cleanupAfterRender) {
  29787. self.pendingCleanup = true;
  29788. }
  29789. self._tryCleanup();
  29790. if (error) {
  29791. internalRenderTask.capability.reject(error);
  29792. } else {
  29793. internalRenderTask.capability.resolve();
  29794. }
  29795. stats.timeEnd('Rendering');
  29796. stats.timeEnd('Overall');
  29797. }
  29798. return renderTask;
  29799. },
  29800. /**
  29801. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  29802. * object that represents page's operator list.
  29803. */
  29804. getOperatorList: function PDFPageProxy_getOperatorList() {
  29805. function operatorListChanged() {
  29806. if (intentState.operatorList.lastChunk) {
  29807. intentState.opListReadCapability.resolve(intentState.operatorList);
  29808. }
  29809. }
  29810. var renderingIntent = 'oplist';
  29811. if (!this.intentStates[renderingIntent]) {
  29812. this.intentStates[renderingIntent] = {};
  29813. }
  29814. var intentState = this.intentStates[renderingIntent];
  29815. if (!intentState.opListReadCapability) {
  29816. var opListTask = {};
  29817. opListTask.operatorListChanged = operatorListChanged;
  29818. intentState.receivingOperatorList = true;
  29819. intentState.opListReadCapability = createPromiseCapability();
  29820. intentState.renderTasks = [];
  29821. intentState.renderTasks.push(opListTask);
  29822. intentState.operatorList = {
  29823. fnArray: [],
  29824. argsArray: [],
  29825. lastChunk: false
  29826. };
  29827. this.transport.messageHandler.send('RenderPageRequest', {
  29828. pageIndex: this.pageIndex,
  29829. intent: renderingIntent
  29830. });
  29831. }
  29832. return intentState.opListReadCapability.promise;
  29833. },
  29834. /**
  29835. * @param {getTextContentParameters} params - getTextContent parameters.
  29836. * @return {Promise} That is resolved a {@link TextContent}
  29837. * object that represent the page text content.
  29838. */
  29839. getTextContent: function PDFPageProxy_getTextContent(params) {
  29840. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  29841. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  29842. pageIndex: this.pageNumber - 1,
  29843. normalizeWhitespace: normalizeWhitespace,
  29844. });
  29845. },
  29846. /**
  29847. * Destroys page object.
  29848. */
  29849. _destroy: function PDFPageProxy_destroy() {
  29850. this.destroyed = true;
  29851. this.transport.pageCache[this.pageIndex] = null;
  29852. var waitOn = [];
  29853. Object.keys(this.intentStates).forEach(function(intent) {
  29854. var intentState = this.intentStates[intent];
  29855. intentState.renderTasks.forEach(function(renderTask) {
  29856. var renderCompleted = renderTask.capability.promise.
  29857. catch(function () {}); // ignoring failures
  29858. waitOn.push(renderCompleted);
  29859. renderTask.cancel();
  29860. });
  29861. }, this);
  29862. this.objs.clear();
  29863. this.annotationsPromise = null;
  29864. this.pendingCleanup = false;
  29865. return Promise.all(waitOn);
  29866. },
  29867. /**
  29868. * Cleans up resources allocated by the page. (deprecated)
  29869. */
  29870. destroy: function() {
  29871. deprecated('page destroy method, use cleanup() instead');
  29872. this.cleanup();
  29873. },
  29874. /**
  29875. * Cleans up resources allocated by the page.
  29876. */
  29877. cleanup: function PDFPageProxy_cleanup() {
  29878. this.pendingCleanup = true;
  29879. this._tryCleanup();
  29880. },
  29881. /**
  29882. * For internal use only. Attempts to clean up if rendering is in a state
  29883. * where that's possible.
  29884. * @ignore
  29885. */
  29886. _tryCleanup: function PDFPageProxy_tryCleanup() {
  29887. if (!this.pendingCleanup ||
  29888. Object.keys(this.intentStates).some(function(intent) {
  29889. var intentState = this.intentStates[intent];
  29890. return (intentState.renderTasks.length !== 0 ||
  29891. intentState.receivingOperatorList);
  29892. }, this)) {
  29893. return;
  29894. }
  29895. Object.keys(this.intentStates).forEach(function(intent) {
  29896. delete this.intentStates[intent];
  29897. }, this);
  29898. this.objs.clear();
  29899. this.annotationsPromise = null;
  29900. this.pendingCleanup = false;
  29901. },
  29902. /**
  29903. * For internal use only.
  29904. * @ignore
  29905. */
  29906. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  29907. intent) {
  29908. var intentState = this.intentStates[intent];
  29909. // TODO Refactor RenderPageRequest to separate rendering
  29910. // and operator list logic
  29911. if (intentState.displayReadyCapability) {
  29912. intentState.displayReadyCapability.resolve(transparency);
  29913. }
  29914. },
  29915. /**
  29916. * For internal use only.
  29917. * @ignore
  29918. */
  29919. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  29920. intent) {
  29921. var intentState = this.intentStates[intent];
  29922. var i, ii;
  29923. // Add the new chunk to the current operator list.
  29924. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  29925. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  29926. intentState.operatorList.argsArray.push(
  29927. operatorListChunk.argsArray[i]);
  29928. }
  29929. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  29930. // Notify all the rendering tasks there are more operators to be consumed.
  29931. for (i = 0; i < intentState.renderTasks.length; i++) {
  29932. intentState.renderTasks[i].operatorListChanged();
  29933. }
  29934. if (operatorListChunk.lastChunk) {
  29935. intentState.receivingOperatorList = false;
  29936. this._tryCleanup();
  29937. }
  29938. }
  29939. };
  29940. return PDFPageProxy;
  29941. })();
  29942. /**
  29943. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  29944. * WorkerTransport for them. If creation of a web worker is not possible,
  29945. * a "fake" worker will be used instead.
  29946. * @class
  29947. */
  29948. var PDFWorker = (function PDFWorkerClosure() {
  29949. var nextFakeWorkerId = 0;
  29950. function getWorkerSrc() {
  29951. if (PDFJS.workerSrc) {
  29952. return PDFJS.workerSrc;
  29953. }
  29954. if (pdfjsFilePath) {
  29955. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  29956. }
  29957. error('No PDFJS.workerSrc specified');
  29958. }
  29959. // Loads worker code into main thread.
  29960. function setupFakeWorkerGlobal() {
  29961. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  29962. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  29963. // In the developer build load worker_loader which in turn loads all the
  29964. // other files and resolves the promise. In production only the
  29965. // pdf.worker.js file is needed.
  29966. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  29967. }
  29968. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  29969. }
  29970. function PDFWorker(name) {
  29971. this.name = name;
  29972. this.destroyed = false;
  29973. this._readyCapability = createPromiseCapability();
  29974. this._port = null;
  29975. this._webWorker = null;
  29976. this._messageHandler = null;
  29977. this._initialize();
  29978. }
  29979. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  29980. get promise() {
  29981. return this._readyCapability.promise;
  29982. },
  29983. get port() {
  29984. return this._port;
  29985. },
  29986. get messageHandler() {
  29987. return this._messageHandler;
  29988. },
  29989. _initialize: function PDFWorker_initialize() {
  29990. // If worker support isn't disabled explicit and the browser has worker
  29991. // support, create a new web worker and test if it/the browser fullfills
  29992. // all requirements to run parts of pdf.js in a web worker.
  29993. // Right now, the requirement is, that an Uint8Array is still an
  29994. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  29995. // Either workers are disabled, not supported or have thrown an exception.
  29996. // Thus, we fallback to a faked worker.
  29997. this._setupFakeWorker();
  29998. },
  29999. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  30000. if (!globalScope.PDFJS.disableWorker) {
  30001. warn('Setting up fake worker.');
  30002. globalScope.PDFJS.disableWorker = true;
  30003. }
  30004. setupFakeWorkerGlobal().then(function () {
  30005. if (this.destroyed) {
  30006. this._readyCapability.reject(new Error('Worker was destroyed'));
  30007. return;
  30008. }
  30009. // If we don't use a worker, just post/sendMessage to the main thread.
  30010. var port = {
  30011. _listeners: [],
  30012. postMessage: function (obj) {
  30013. var e = {data: obj};
  30014. this._listeners.forEach(function (listener) {
  30015. listener.call(this, e);
  30016. }, this);
  30017. },
  30018. addEventListener: function (name, listener) {
  30019. this._listeners.push(listener);
  30020. },
  30021. removeEventListener: function (name, listener) {
  30022. var i = this._listeners.indexOf(listener);
  30023. this._listeners.splice(i, 1);
  30024. },
  30025. terminate: function () {}
  30026. };
  30027. this._port = port;
  30028. // All fake workers use the same port, making id unique.
  30029. var id = 'fake' + (nextFakeWorkerId++);
  30030. // If the main thread is our worker, setup the handling for the
  30031. // messages -- the main thread sends to it self.
  30032. var workerHandler = new MessageHandler(id + '_worker', id, port);
  30033. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  30034. var messageHandler = new MessageHandler(id, id + '_worker', port);
  30035. this._messageHandler = messageHandler;
  30036. this._readyCapability.resolve();
  30037. }.bind(this));
  30038. },
  30039. /**
  30040. * Destroys the worker instance.
  30041. */
  30042. destroy: function PDFWorker_destroy() {
  30043. this.destroyed = true;
  30044. if (this._webWorker) {
  30045. // We need to terminate only web worker created resource.
  30046. this._webWorker.terminate();
  30047. this._webWorker = null;
  30048. }
  30049. this._port = null;
  30050. if (this._messageHandler) {
  30051. this._messageHandler.destroy();
  30052. this._messageHandler = null;
  30053. }
  30054. }
  30055. };
  30056. return PDFWorker;
  30057. })();
  30058. PDFJS.PDFWorker = PDFWorker;
  30059. /**
  30060. * For internal use only.
  30061. * @ignore
  30062. */
  30063. var WorkerTransport = (function WorkerTransportClosure() {
  30064. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  30065. this.messageHandler = messageHandler;
  30066. this.loadingTask = loadingTask;
  30067. this.pdfDataRangeTransport = pdfDataRangeTransport;
  30068. this.commonObjs = new PDFObjects();
  30069. this.fontLoader = new FontLoader(loadingTask.docId);
  30070. this.destroyed = false;
  30071. this.destroyCapability = null;
  30072. this.pageCache = [];
  30073. this.pagePromises = [];
  30074. this.downloadInfoCapability = createPromiseCapability();
  30075. this.setupMessageHandler();
  30076. }
  30077. WorkerTransport.prototype = {
  30078. destroy: function WorkerTransport_destroy() {
  30079. if (this.destroyCapability) {
  30080. return this.destroyCapability.promise;
  30081. }
  30082. this.destroyed = true;
  30083. this.destroyCapability = createPromiseCapability();
  30084. var waitOn = [];
  30085. // We need to wait for all renderings to be completed, e.g.
  30086. // timeout/rAF can take a long time.
  30087. this.pageCache.forEach(function (page) {
  30088. if (page) {
  30089. waitOn.push(page._destroy());
  30090. }
  30091. });
  30092. this.pageCache = [];
  30093. this.pagePromises = [];
  30094. var self = this;
  30095. // We also need to wait for the worker to finish its long running tasks.
  30096. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  30097. waitOn.push(terminated);
  30098. Promise.all(waitOn).then(function () {
  30099. self.fontLoader.clear();
  30100. if (self.pdfDataRangeTransport) {
  30101. self.pdfDataRangeTransport.abort();
  30102. self.pdfDataRangeTransport = null;
  30103. }
  30104. if (self.messageHandler) {
  30105. self.messageHandler.destroy();
  30106. self.messageHandler = null;
  30107. }
  30108. self.destroyCapability.resolve();
  30109. }, this.destroyCapability.reject);
  30110. return this.destroyCapability.promise;
  30111. },
  30112. setupMessageHandler:
  30113. function WorkerTransport_setupMessageHandler() {
  30114. var messageHandler = this.messageHandler;
  30115. function updatePassword(password) {
  30116. messageHandler.send('UpdatePassword', password);
  30117. }
  30118. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  30119. if (pdfDataRangeTransport) {
  30120. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  30121. messageHandler.send('OnDataRange', {
  30122. begin: begin,
  30123. chunk: chunk
  30124. });
  30125. });
  30126. pdfDataRangeTransport.addProgressListener(function(loaded) {
  30127. messageHandler.send('OnDataProgress', {
  30128. loaded: loaded
  30129. });
  30130. });
  30131. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  30132. messageHandler.send('OnDataRange', {
  30133. chunk: chunk
  30134. });
  30135. });
  30136. messageHandler.on('RequestDataRange',
  30137. function transportDataRange(data) {
  30138. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  30139. }, this);
  30140. }
  30141. messageHandler.on('GetDoc', function transportDoc(data) {
  30142. var pdfInfo = data.pdfInfo;
  30143. this.numPages = data.pdfInfo.numPages;
  30144. var loadingTask = this.loadingTask;
  30145. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  30146. this.pdfDocument = pdfDocument;
  30147. loadingTask._capability.resolve(pdfDocument);
  30148. }, this);
  30149. messageHandler.on('NeedPassword',
  30150. function transportNeedPassword(exception) {
  30151. var loadingTask = this.loadingTask;
  30152. if (loadingTask.onPassword) {
  30153. return loadingTask.onPassword(updatePassword,
  30154. PasswordResponses.NEED_PASSWORD);
  30155. }
  30156. loadingTask._capability.reject(
  30157. new PasswordException(exception.message, exception.code));
  30158. }, this);
  30159. messageHandler.on('IncorrectPassword',
  30160. function transportIncorrectPassword(exception) {
  30161. var loadingTask = this.loadingTask;
  30162. if (loadingTask.onPassword) {
  30163. return loadingTask.onPassword(updatePassword,
  30164. PasswordResponses.INCORRECT_PASSWORD);
  30165. }
  30166. loadingTask._capability.reject(
  30167. new PasswordException(exception.message, exception.code));
  30168. }, this);
  30169. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  30170. this.loadingTask._capability.reject(
  30171. new InvalidPDFException(exception.message));
  30172. }, this);
  30173. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  30174. this.loadingTask._capability.reject(
  30175. new MissingPDFException(exception.message));
  30176. }, this);
  30177. messageHandler.on('UnexpectedResponse',
  30178. function transportUnexpectedResponse(exception) {
  30179. this.loadingTask._capability.reject(
  30180. new UnexpectedResponseException(exception.message, exception.status));
  30181. }, this);
  30182. messageHandler.on('UnknownError',
  30183. function transportUnknownError(exception) {
  30184. this.loadingTask._capability.reject(
  30185. new UnknownErrorException(exception.message, exception.details));
  30186. }, this);
  30187. messageHandler.on('DataLoaded', function transportPage(data) {
  30188. this.downloadInfoCapability.resolve(data);
  30189. }, this);
  30190. messageHandler.on('PDFManagerReady', function transportPage(data) {
  30191. if (this.pdfDataRangeTransport) {
  30192. this.pdfDataRangeTransport.transportReady();
  30193. }
  30194. }, this);
  30195. messageHandler.on('StartRenderPage', function transportRender(data) {
  30196. if (this.destroyed) {
  30197. return; // Ignore any pending requests if the worker was terminated.
  30198. }
  30199. var page = this.pageCache[data.pageIndex];
  30200. page.stats.timeEnd('Page Request');
  30201. page._startRenderPage(data.transparency, data.intent);
  30202. }, this);
  30203. messageHandler.on('RenderPageChunk', function transportRender(data) {
  30204. if (this.destroyed) {
  30205. return; // Ignore any pending requests if the worker was terminated.
  30206. }
  30207. var page = this.pageCache[data.pageIndex];
  30208. page._renderPageChunk(data.operatorList, data.intent);
  30209. }, this);
  30210. messageHandler.on('commonobj', function transportObj(data) {
  30211. if (this.destroyed) {
  30212. return; // Ignore any pending requests if the worker was terminated.
  30213. }
  30214. var id = data[0];
  30215. var type = data[1];
  30216. if (this.commonObjs.hasData(id)) {
  30217. return;
  30218. }
  30219. switch (type) {
  30220. case 'Font':
  30221. var exportedData = data[2];
  30222. var font;
  30223. if ('error' in exportedData) {
  30224. var error = exportedData.error;
  30225. warn('Error during font loading: ' + error);
  30226. this.commonObjs.resolve(id, error);
  30227. break;
  30228. } else {
  30229. font = new FontFaceObject(exportedData);
  30230. }
  30231. this.fontLoader.bind(
  30232. [font],
  30233. function fontReady(fontObjs) {
  30234. this.commonObjs.resolve(id, font);
  30235. }.bind(this)
  30236. );
  30237. break;
  30238. case 'FontPath':
  30239. this.commonObjs.resolve(id, data[2]);
  30240. break;
  30241. default:
  30242. error('Got unknown common object type ' + type);
  30243. }
  30244. }, this);
  30245. messageHandler.on('obj', function transportObj(data) {
  30246. if (this.destroyed) {
  30247. return; // Ignore any pending requests if the worker was terminated.
  30248. }
  30249. var id = data[0];
  30250. var pageIndex = data[1];
  30251. var type = data[2];
  30252. var pageProxy = this.pageCache[pageIndex];
  30253. var imageData;
  30254. if (pageProxy.objs.hasData(id)) {
  30255. return;
  30256. }
  30257. switch (type) {
  30258. case 'JpegStream':
  30259. imageData = data[3];
  30260. loadJpegStream(id, imageData, pageProxy.objs);
  30261. break;
  30262. case 'Image':
  30263. imageData = data[3];
  30264. pageProxy.objs.resolve(id, imageData);
  30265. // heuristics that will allow not to store large data
  30266. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  30267. if (imageData && 'data' in imageData &&
  30268. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  30269. pageProxy.cleanupAfterRender = true;
  30270. }
  30271. break;
  30272. default:
  30273. error('Got unknown object type ' + type);
  30274. }
  30275. }, this);
  30276. messageHandler.on('DocProgress', function transportDocProgress(data) {
  30277. if (this.destroyed) {
  30278. return; // Ignore any pending requests if the worker was terminated.
  30279. }
  30280. var loadingTask = this.loadingTask;
  30281. if (loadingTask.onProgress) {
  30282. loadingTask.onProgress({
  30283. loaded: data.loaded,
  30284. total: data.total
  30285. });
  30286. }
  30287. }, this);
  30288. messageHandler.on('PageError', function transportError(data) {
  30289. if (this.destroyed) {
  30290. return; // Ignore any pending requests if the worker was terminated.
  30291. }
  30292. var page = this.pageCache[data.pageNum - 1];
  30293. var intentState = page.intentStates[data.intent];
  30294. if (intentState.displayReadyCapability) {
  30295. intentState.displayReadyCapability.reject(data.error);
  30296. } else {
  30297. error(data.error);
  30298. }
  30299. }, this);
  30300. messageHandler.on('UnsupportedFeature',
  30301. function transportUnsupportedFeature(data) {
  30302. if (this.destroyed) {
  30303. return; // Ignore any pending requests if the worker was terminated.
  30304. }
  30305. var featureId = data.featureId;
  30306. var loadingTask = this.loadingTask;
  30307. if (loadingTask.onUnsupportedFeature) {
  30308. loadingTask.onUnsupportedFeature(featureId);
  30309. }
  30310. PDFJS.UnsupportedManager.notify(featureId);
  30311. }, this);
  30312. messageHandler.on('JpegDecode', function(data) {
  30313. if (this.destroyed) {
  30314. return Promise.reject('Worker was terminated');
  30315. }
  30316. var imageUrl = data[0];
  30317. var components = data[1];
  30318. if (components !== 3 && components !== 1) {
  30319. return Promise.reject(
  30320. new Error('Only 3 components or 1 component can be returned'));
  30321. }
  30322. return new Promise(function (resolve, reject) {
  30323. var img = new Image();
  30324. img.onload = function () {
  30325. var width = img.width;
  30326. var height = img.height;
  30327. var size = width * height;
  30328. var rgbaLength = size * 4;
  30329. var buf = new Uint8Array(size * components);
  30330. var tmpCanvas = createScratchCanvas(width, height);
  30331. var tmpCtx = tmpCanvas.getContext('2d');
  30332. tmpCtx.drawImage(img, 0, 0);
  30333. var data = tmpCtx.getImageData(0, 0, width, height).data;
  30334. var i, j;
  30335. if (components === 3) {
  30336. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  30337. buf[j] = data[i];
  30338. buf[j + 1] = data[i + 1];
  30339. buf[j + 2] = data[i + 2];
  30340. }
  30341. } else if (components === 1) {
  30342. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  30343. buf[j] = data[i];
  30344. }
  30345. }
  30346. resolve({ data: buf, width: width, height: height});
  30347. };
  30348. img.onerror = function () {
  30349. reject(new Error('JpegDecode failed to load image'));
  30350. };
  30351. img.src = imageUrl;
  30352. });
  30353. }, this);
  30354. },
  30355. getData: function WorkerTransport_getData() {
  30356. return this.messageHandler.sendWithPromise('GetData', null);
  30357. },
  30358. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  30359. if (pageNumber <= 0 || pageNumber > this.numPages ||
  30360. (pageNumber|0) !== pageNumber) {
  30361. return Promise.reject(new Error('Invalid page request'));
  30362. }
  30363. var pageIndex = pageNumber - 1;
  30364. if (pageIndex in this.pagePromises) {
  30365. return this.pagePromises[pageIndex];
  30366. }
  30367. var promise = this.messageHandler.sendWithPromise('GetPage', {
  30368. pageIndex: pageIndex
  30369. }).then(function (pageInfo) {
  30370. if (this.destroyed) {
  30371. throw new Error('Transport destroyed');
  30372. }
  30373. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  30374. this.pageCache[pageIndex] = page;
  30375. return page;
  30376. }.bind(this));
  30377. this.pagePromises[pageIndex] = promise;
  30378. return promise;
  30379. },
  30380. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  30381. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  30382. },
  30383. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  30384. return this.messageHandler.sendWithPromise('GetAnnotations', {
  30385. pageIndex: pageIndex,
  30386. intent: intent,
  30387. });
  30388. },
  30389. getDestinations: function WorkerTransport_getDestinations() {
  30390. return this.messageHandler.sendWithPromise('GetDestinations', null);
  30391. },
  30392. getDestination: function WorkerTransport_getDestination(id) {
  30393. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  30394. },
  30395. getAttachments: function WorkerTransport_getAttachments() {
  30396. return this.messageHandler.sendWithPromise('GetAttachments', null);
  30397. },
  30398. getJavaScript: function WorkerTransport_getJavaScript() {
  30399. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  30400. },
  30401. getOutline: function WorkerTransport_getOutline() {
  30402. return this.messageHandler.sendWithPromise('GetOutline', null);
  30403. },
  30404. getMetadata: function WorkerTransport_getMetadata() {
  30405. return this.messageHandler.sendWithPromise('GetMetadata', null).
  30406. then(function transportMetadata(results) {
  30407. return {
  30408. info: results[0],
  30409. metadata: (results[1] ? new Metadata(results[1]) : null)
  30410. };
  30411. });
  30412. },
  30413. getStats: function WorkerTransport_getStats() {
  30414. return this.messageHandler.sendWithPromise('GetStats', null);
  30415. },
  30416. startCleanup: function WorkerTransport_startCleanup() {
  30417. this.messageHandler.sendWithPromise('Cleanup', null).
  30418. then(function endCleanup() {
  30419. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  30420. var page = this.pageCache[i];
  30421. if (page) {
  30422. page.cleanup();
  30423. }
  30424. }
  30425. this.commonObjs.clear();
  30426. this.fontLoader.clear();
  30427. }.bind(this));
  30428. }
  30429. };
  30430. return WorkerTransport;
  30431. })();
  30432. /**
  30433. * A PDF document and page is built of many objects. E.g. there are objects
  30434. * for fonts, images, rendering code and such. These objects might get processed
  30435. * inside of a worker. The `PDFObjects` implements some basic functions to
  30436. * manage these objects.
  30437. * @ignore
  30438. */
  30439. var PDFObjects = (function PDFObjectsClosure() {
  30440. function PDFObjects() {
  30441. this.objs = {};
  30442. }
  30443. PDFObjects.prototype = {
  30444. /**
  30445. * Internal function.
  30446. * Ensures there is an object defined for `objId`.
  30447. */
  30448. ensureObj: function PDFObjects_ensureObj(objId) {
  30449. if (this.objs[objId]) {
  30450. return this.objs[objId];
  30451. }
  30452. var obj = {
  30453. capability: createPromiseCapability(),
  30454. data: null,
  30455. resolved: false
  30456. };
  30457. this.objs[objId] = obj;
  30458. return obj;
  30459. },
  30460. /**
  30461. * If called *without* callback, this returns the data of `objId` but the
  30462. * object needs to be resolved. If it isn't, this function throws.
  30463. *
  30464. * If called *with* a callback, the callback is called with the data of the
  30465. * object once the object is resolved. That means, if you call this
  30466. * function and the object is already resolved, the callback gets called
  30467. * right away.
  30468. */
  30469. get: function PDFObjects_get(objId, callback) {
  30470. // If there is a callback, then the get can be async and the object is
  30471. // not required to be resolved right now
  30472. if (callback) {
  30473. this.ensureObj(objId).capability.promise.then(callback);
  30474. return null;
  30475. }
  30476. // If there isn't a callback, the user expects to get the resolved data
  30477. // directly.
  30478. var obj = this.objs[objId];
  30479. // If there isn't an object yet or the object isn't resolved, then the
  30480. // data isn't ready yet!
  30481. if (!obj || !obj.resolved) {
  30482. error('Requesting object that isn\'t resolved yet ' + objId);
  30483. }
  30484. return obj.data;
  30485. },
  30486. /**
  30487. * Resolves the object `objId` with optional `data`.
  30488. */
  30489. resolve: function PDFObjects_resolve(objId, data) {
  30490. var obj = this.ensureObj(objId);
  30491. obj.resolved = true;
  30492. obj.data = data;
  30493. obj.capability.resolve(data);
  30494. },
  30495. isResolved: function PDFObjects_isResolved(objId) {
  30496. var objs = this.objs;
  30497. if (!objs[objId]) {
  30498. return false;
  30499. } else {
  30500. return objs[objId].resolved;
  30501. }
  30502. },
  30503. hasData: function PDFObjects_hasData(objId) {
  30504. return this.isResolved(objId);
  30505. },
  30506. /**
  30507. * Returns the data of `objId` if object exists, null otherwise.
  30508. */
  30509. getData: function PDFObjects_getData(objId) {
  30510. var objs = this.objs;
  30511. if (!objs[objId] || !objs[objId].resolved) {
  30512. return null;
  30513. } else {
  30514. return objs[objId].data;
  30515. }
  30516. },
  30517. clear: function PDFObjects_clear() {
  30518. this.objs = {};
  30519. }
  30520. };
  30521. return PDFObjects;
  30522. })();
  30523. /**
  30524. * Allows controlling of the rendering tasks.
  30525. * @class
  30526. * @alias RenderTask
  30527. */
  30528. var RenderTask = (function RenderTaskClosure() {
  30529. function RenderTask(internalRenderTask) {
  30530. this._internalRenderTask = internalRenderTask;
  30531. /**
  30532. * Callback for incremental rendering -- a function that will be called
  30533. * each time the rendering is paused. To continue rendering call the
  30534. * function that is the first argument to the callback.
  30535. * @type {function}
  30536. */
  30537. this.onContinue = null;
  30538. }
  30539. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  30540. /**
  30541. * Promise for rendering task completion.
  30542. * @return {Promise}
  30543. */
  30544. get promise() {
  30545. return this._internalRenderTask.capability.promise;
  30546. },
  30547. /**
  30548. * Cancels the rendering task. If the task is currently rendering it will
  30549. * not be cancelled until graphics pauses with a timeout. The promise that
  30550. * this object extends will resolved when cancelled.
  30551. */
  30552. cancel: function RenderTask_cancel() {
  30553. this._internalRenderTask.cancel();
  30554. },
  30555. /**
  30556. * Registers callbacks to indicate the rendering task completion.
  30557. *
  30558. * @param {function} onFulfilled The callback for the rendering completion.
  30559. * @param {function} onRejected The callback for the rendering failure.
  30560. * @return {Promise} A promise that is resolved after the onFulfilled or
  30561. * onRejected callback.
  30562. */
  30563. then: function RenderTask_then(onFulfilled, onRejected) {
  30564. return this.promise.then.apply(this.promise, arguments);
  30565. }
  30566. };
  30567. return RenderTask;
  30568. })();
  30569. /**
  30570. * For internal use only.
  30571. * @ignore
  30572. */
  30573. var InternalRenderTask = (function InternalRenderTaskClosure() {
  30574. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  30575. pageNumber) {
  30576. this.callback = callback;
  30577. this.params = params;
  30578. this.objs = objs;
  30579. this.commonObjs = commonObjs;
  30580. this.operatorListIdx = null;
  30581. this.operatorList = operatorList;
  30582. this.pageNumber = pageNumber;
  30583. this.running = false;
  30584. this.graphicsReadyCallback = null;
  30585. this.graphicsReady = false;
  30586. this.useRequestAnimationFrame = false;
  30587. this.cancelled = false;
  30588. this.capability = createPromiseCapability();
  30589. this.task = new RenderTask(this);
  30590. // caching this-bound methods
  30591. this._continueBound = this._continue.bind(this);
  30592. this._scheduleNextBound = this._scheduleNext.bind(this);
  30593. this._nextBound = this._next.bind(this);
  30594. }
  30595. InternalRenderTask.prototype = {
  30596. initalizeGraphics:
  30597. function InternalRenderTask_initalizeGraphics(transparency) {
  30598. if (this.cancelled) {
  30599. return;
  30600. }
  30601. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  30602. globalScope.StepperManager.enabled) {
  30603. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  30604. this.stepper.init(this.operatorList);
  30605. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  30606. }
  30607. var params = this.params;
  30608. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  30609. this.objs, params.imageLayer);
  30610. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  30611. this.operatorListIdx = 0;
  30612. this.graphicsReady = true;
  30613. if (this.graphicsReadyCallback) {
  30614. this.graphicsReadyCallback();
  30615. }
  30616. },
  30617. cancel: function InternalRenderTask_cancel() {
  30618. this.running = false;
  30619. this.cancelled = true;
  30620. this.callback('cancelled');
  30621. },
  30622. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  30623. if (!this.graphicsReady) {
  30624. if (!this.graphicsReadyCallback) {
  30625. this.graphicsReadyCallback = this._continueBound;
  30626. }
  30627. return;
  30628. }
  30629. if (this.stepper) {
  30630. this.stepper.updateOperatorList(this.operatorList);
  30631. }
  30632. if (this.running) {
  30633. return;
  30634. }
  30635. this._continue();
  30636. },
  30637. _continue: function InternalRenderTask__continue() {
  30638. this.running = true;
  30639. if (this.cancelled) {
  30640. return;
  30641. }
  30642. if (this.task.onContinue) {
  30643. this.task.onContinue.call(this.task, this._scheduleNextBound);
  30644. } else {
  30645. this._scheduleNext();
  30646. }
  30647. },
  30648. _scheduleNext: function InternalRenderTask__scheduleNext() {
  30649. if (this.useRequestAnimationFrame) {
  30650. window.requestAnimationFrame(this._nextBound);
  30651. } else {
  30652. Promise.resolve(undefined).then(this._nextBound);
  30653. }
  30654. },
  30655. _next: function InternalRenderTask__next() {
  30656. if (this.cancelled) {
  30657. return;
  30658. }
  30659. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  30660. this.operatorListIdx,
  30661. this._continueBound,
  30662. this.stepper);
  30663. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  30664. this.running = false;
  30665. if (this.operatorList.lastChunk) {
  30666. this.gfx.endDrawing();
  30667. this.callback();
  30668. }
  30669. }
  30670. }
  30671. };
  30672. return InternalRenderTask;
  30673. })();
  30674. /**
  30675. * (Deprecated) Global observer of unsupported feature usages. Use
  30676. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  30677. */
  30678. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  30679. var listeners = [];
  30680. return {
  30681. listen: function (cb) {
  30682. deprecated('Global UnsupportedManager.listen is used: ' +
  30683. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  30684. listeners.push(cb);
  30685. },
  30686. notify: function (featureId) {
  30687. for (var i = 0, ii = listeners.length; i < ii; i++) {
  30688. listeners[i](featureId);
  30689. }
  30690. }
  30691. };
  30692. })();
  30693. exports.getDocument = PDFJS.getDocument;
  30694. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  30695. exports.PDFDocumentProxy = PDFDocumentProxy;
  30696. exports.PDFPageProxy = PDFPageProxy;
  30697. }));
  30698. (function (root, factory) {
  30699. {
  30700. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  30701. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  30702. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  30703. root.pdfjsCoreFontRenderer);
  30704. }
  30705. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  30706. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  30707. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30708. var FontType = sharedUtil.FontType;
  30709. var Util = sharedUtil.Util;
  30710. var assert = sharedUtil.assert;
  30711. var bytesToString = sharedUtil.bytesToString;
  30712. var error = sharedUtil.error;
  30713. var info = sharedUtil.info;
  30714. var isArray = sharedUtil.isArray;
  30715. var isInt = sharedUtil.isInt;
  30716. var isNum = sharedUtil.isNum;
  30717. var readUint32 = sharedUtil.readUint32;
  30718. var shadow = sharedUtil.shadow;
  30719. var stringToBytes = sharedUtil.stringToBytes;
  30720. var string32 = sharedUtil.string32;
  30721. var warn = sharedUtil.warn;
  30722. var Name = corePrimitives.Name;
  30723. var Stream = coreStream.Stream;
  30724. var Lexer = coreParser.Lexer;
  30725. var CMapFactory = coreCMap.CMapFactory;
  30726. var IdentityCMap = coreCMap.IdentityCMap;
  30727. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  30728. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  30729. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  30730. var ExpertCharset = coreCharsets.ExpertCharset;
  30731. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  30732. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30733. // Unicode Private Use Area
  30734. var PRIVATE_USE_OFFSET_START = 0xE000;
  30735. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30736. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30737. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30738. // except for Type 3 fonts
  30739. var PDF_GLYPH_SPACE_UNITS = 1000;
  30740. // Hinting is currently disabled due to unknown problems on windows
  30741. // in tracemonkey and various other pdfs with type1 fonts.
  30742. var HINTING_ENABLED = false;
  30743. // Accented charactars are not displayed properly on windows, using this flag
  30744. // to control analysis of seac charstrings.
  30745. var SEAC_ANALYSIS_ENABLED = false;
  30746. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  30747. var MAX_SUBR_NESTING = 10;
  30748. var FontFlags = {
  30749. FixedPitch: 1,
  30750. Serif: 2,
  30751. Symbolic: 4,
  30752. Script: 8,
  30753. Nonsymbolic: 32,
  30754. Italic: 64,
  30755. AllCap: 65536,
  30756. SmallCap: 131072,
  30757. ForceBold: 262144
  30758. };
  30759. var Encodings = {
  30760. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30761. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30762. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  30763. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  30764. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  30765. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  30766. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  30767. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  30768. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  30769. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  30770. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  30771. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  30772. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  30773. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  30774. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  30775. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  30776. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  30777. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  30778. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  30779. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30780. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  30781. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  30782. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  30783. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  30784. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  30785. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  30786. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  30787. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  30788. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  30789. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  30790. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  30791. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  30792. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  30793. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  30794. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  30795. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  30796. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  30797. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  30798. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  30799. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  30800. 'Ydieresissmall'],
  30801. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30802. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30803. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  30804. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  30805. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  30806. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  30807. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  30808. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  30809. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  30810. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  30811. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  30812. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  30813. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  30814. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  30815. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  30816. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  30817. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  30818. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  30819. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  30820. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  30821. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  30822. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  30823. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  30824. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  30825. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  30826. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  30827. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  30828. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  30829. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  30830. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  30831. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  30832. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  30833. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  30834. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  30835. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  30836. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  30837. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  30838. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  30839. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  30840. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  30841. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30842. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30843. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30844. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30845. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30846. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30847. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30848. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30849. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30850. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30851. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30852. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  30853. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  30854. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  30855. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30856. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  30857. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  30858. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  30859. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  30860. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  30861. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  30862. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  30863. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  30864. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  30865. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  30866. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  30867. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  30868. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  30869. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  30870. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  30871. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  30872. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  30873. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  30874. 'ogonek', 'caron'],
  30875. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30876. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30877. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30878. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  30879. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30880. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30881. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30882. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30883. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30884. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  30885. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  30886. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30887. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30888. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  30889. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  30890. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  30891. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  30892. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  30893. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  30894. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  30895. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  30896. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  30897. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  30898. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  30899. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  30900. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30901. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30902. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30903. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30904. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30905. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30906. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30907. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30908. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30909. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30910. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30911. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30912. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  30913. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  30914. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  30915. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  30916. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  30917. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  30918. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  30919. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  30920. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  30921. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  30922. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  30923. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  30924. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  30925. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  30926. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  30927. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  30928. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  30929. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  30930. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  30931. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  30932. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  30933. 'ydieresis'],
  30934. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30935. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30936. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  30937. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  30938. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  30939. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  30940. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  30941. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  30942. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  30943. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  30944. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  30945. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  30946. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  30947. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  30948. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  30949. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30950. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  30951. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  30952. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  30953. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  30954. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  30955. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  30956. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  30957. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  30958. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  30959. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  30960. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  30961. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  30962. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  30963. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  30964. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  30965. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  30966. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  30967. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  30968. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  30969. 'bracerightbt'],
  30970. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30971. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30972. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  30973. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  30974. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  30975. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  30976. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  30977. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  30978. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  30979. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  30980. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  30981. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  30982. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  30983. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  30984. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  30985. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  30986. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  30987. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  30988. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  30989. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  30990. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  30991. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  30992. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  30993. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  30994. };
  30995. /**
  30996. * Hold a map of decoded fonts and of the standard fourteen Type1
  30997. * fonts and their acronyms.
  30998. */
  30999. var stdFontMap = {
  31000. 'ArialNarrow': 'Helvetica',
  31001. 'ArialNarrow-Bold': 'Helvetica-Bold',
  31002. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  31003. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  31004. 'ArialBlack': 'Helvetica',
  31005. 'ArialBlack-Bold': 'Helvetica-Bold',
  31006. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  31007. 'ArialBlack-Italic': 'Helvetica-Oblique',
  31008. 'Arial': 'Helvetica',
  31009. 'Arial-Bold': 'Helvetica-Bold',
  31010. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  31011. 'Arial-Italic': 'Helvetica-Oblique',
  31012. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  31013. 'Arial-BoldMT': 'Helvetica-Bold',
  31014. 'Arial-ItalicMT': 'Helvetica-Oblique',
  31015. 'ArialMT': 'Helvetica',
  31016. 'Courier-Bold': 'Courier-Bold',
  31017. 'Courier-BoldItalic': 'Courier-BoldOblique',
  31018. 'Courier-Italic': 'Courier-Oblique',
  31019. 'CourierNew': 'Courier',
  31020. 'CourierNew-Bold': 'Courier-Bold',
  31021. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  31022. 'CourierNew-Italic': 'Courier-Oblique',
  31023. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  31024. 'CourierNewPS-BoldMT': 'Courier-Bold',
  31025. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  31026. 'CourierNewPSMT': 'Courier',
  31027. 'Helvetica': 'Helvetica',
  31028. 'Helvetica-Bold': 'Helvetica-Bold',
  31029. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  31030. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  31031. 'Helvetica-Italic': 'Helvetica-Oblique',
  31032. 'Helvetica-Oblique':'Helvetica-Oblique',
  31033. 'Symbol-Bold': 'Symbol',
  31034. 'Symbol-BoldItalic': 'Symbol',
  31035. 'Symbol-Italic': 'Symbol',
  31036. 'TimesNewRoman': 'Times-Roman',
  31037. 'TimesNewRoman-Bold': 'Times-Bold',
  31038. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  31039. 'TimesNewRoman-Italic': 'Times-Italic',
  31040. 'TimesNewRomanPS': 'Times-Roman',
  31041. 'TimesNewRomanPS-Bold': 'Times-Bold',
  31042. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  31043. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  31044. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  31045. 'TimesNewRomanPS-Italic': 'Times-Italic',
  31046. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  31047. 'TimesNewRomanPSMT': 'Times-Roman',
  31048. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  31049. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  31050. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  31051. };
  31052. /**
  31053. * Holds the map of the non-standard fonts that might be included as a standard
  31054. * fonts without glyph data.
  31055. */
  31056. var nonStdFontMap = {
  31057. 'CenturyGothic': 'Helvetica',
  31058. 'CenturyGothic-Bold': 'Helvetica-Bold',
  31059. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  31060. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  31061. 'ComicSansMS': 'Comic Sans MS',
  31062. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  31063. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  31064. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  31065. 'LucidaConsole': 'Courier',
  31066. 'LucidaConsole-Bold': 'Courier-Bold',
  31067. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  31068. 'LucidaConsole-Italic': 'Courier-Oblique',
  31069. 'MS-Gothic': 'MS Gothic',
  31070. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  31071. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  31072. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  31073. 'MS-Mincho': 'MS Mincho',
  31074. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  31075. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  31076. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  31077. 'MS-PGothic': 'MS PGothic',
  31078. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  31079. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  31080. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  31081. 'MS-PMincho': 'MS PMincho',
  31082. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  31083. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  31084. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  31085. 'Wingdings': 'ZapfDingbats'
  31086. };
  31087. var serifFonts = {
  31088. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  31089. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  31090. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  31091. 'Arno': true, 'Aster': true, 'Aurora': true,
  31092. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  31093. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  31094. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  31095. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  31096. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  31097. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  31098. 'Cartier': true, 'Caslon': true, 'Catull': true,
  31099. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  31100. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  31101. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  31102. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  31103. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  31104. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  31105. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  31106. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  31107. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  31108. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  31109. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  31110. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  31111. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  31112. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  31113. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  31114. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  31115. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  31116. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  31117. 'Miller': true, 'Minion': true, 'Modern': true,
  31118. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  31119. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  31120. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  31121. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  31122. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  31123. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  31124. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  31125. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  31126. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  31127. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  31128. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  31129. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  31130. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  31131. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  31132. };
  31133. var symbolsFonts = {
  31134. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  31135. };
  31136. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  31137. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  31138. // glyphs, but common for some set of the standard fonts.
  31139. var GlyphMapForStandardFonts = {
  31140. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  31141. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  31142. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  31143. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  31144. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  31145. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  31146. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  31147. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  31148. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  31149. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  31150. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  31151. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  31152. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  31153. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  31154. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  31155. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  31156. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  31157. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  31158. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  31159. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  31160. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  31161. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  31162. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  31163. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  31164. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  31165. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  31166. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  31167. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  31168. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  31169. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  31170. '298': 380, '305': 963,
  31171. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  31172. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  31173. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  31174. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  31175. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  31176. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  31177. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  31178. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  31179. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  31180. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  31181. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  31182. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  31183. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  31184. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  31185. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  31186. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  31187. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  31188. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  31189. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  31190. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  31191. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  31192. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  31193. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  31194. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  31195. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  31196. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  31197. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  31198. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  31199. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  31200. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  31201. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  31202. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  31203. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  31204. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  31205. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  31206. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  31207. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  31208. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  31209. };
  31210. // The glyph map for ArialBlack differs slightly from the glyph map used for
  31211. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  31212. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  31213. var SupplementalGlyphMapForArialBlack = {
  31214. '227': 322, '264': 261, '291': 346,
  31215. };
  31216. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  31217. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  31218. // to the similar equivalents in the normal characters range.
  31219. var SpecialPUASymbols = {
  31220. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  31221. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  31222. '63720': 0x00AE, // registersans (0xF8E8) => registered
  31223. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  31224. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  31225. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  31226. '63729': 0x23A7, // bracelefttp (0xF8F1)
  31227. '63730': 0x23A8, // braceleftmid (0xF8F2)
  31228. '63731': 0x23A9, // braceleftbt (0xF8F3)
  31229. '63740': 0x23AB, // bracerighttp (0xF8FC)
  31230. '63741': 0x23AC, // bracerightmid (0xF8FD)
  31231. '63742': 0x23AD, // bracerightbt (0xF8FE)
  31232. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  31233. '63727': 0x23A2, // bracketleftex (0xF8EF)
  31234. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  31235. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  31236. '63738': 0x23A5, // bracketrightex (0xF8FA)
  31237. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  31238. '63723': 0x239B, // parenlefttp (0xF8EB)
  31239. '63724': 0x239C, // parenleftex (0xF8EC)
  31240. '63725': 0x239D, // parenleftbt (0xF8ED)
  31241. '63734': 0x239E, // parenrighttp (0xF8F6)
  31242. '63735': 0x239F, // parenrightex (0xF8F7)
  31243. '63736': 0x23A0, // parenrightbt (0xF8F8)
  31244. };
  31245. function mapSpecialUnicodeValues(code) {
  31246. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  31247. return 0;
  31248. } else if (code >= 0xF600 && code <= 0xF8FF) {
  31249. return (SpecialPUASymbols[code] || code);
  31250. }
  31251. return code;
  31252. }
  31253. var UnicodeRanges = [
  31254. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  31255. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  31256. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  31257. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  31258. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  31259. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  31260. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  31261. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  31262. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  31263. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  31264. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  31265. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  31266. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  31267. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  31268. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  31269. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  31270. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  31271. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  31272. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  31273. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  31274. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  31275. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  31276. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  31277. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  31278. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  31279. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  31280. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  31281. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  31282. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  31283. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  31284. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  31285. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  31286. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  31287. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  31288. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  31289. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  31290. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  31291. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  31292. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  31293. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  31294. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  31295. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  31296. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  31297. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  31298. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  31299. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  31300. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  31301. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  31302. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  31303. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  31304. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  31305. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  31306. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  31307. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  31308. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  31309. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  31310. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  31311. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  31312. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  31313. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  31314. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  31315. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  31316. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  31317. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  31318. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  31319. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  31320. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  31321. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  31322. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  31323. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  31324. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  31325. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  31326. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  31327. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  31328. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  31329. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  31330. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  31331. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  31332. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  31333. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  31334. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  31335. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  31336. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  31337. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  31338. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  31339. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  31340. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  31341. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  31342. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  31343. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  31344. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  31345. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  31346. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  31347. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  31348. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  31349. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  31350. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  31351. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  31352. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  31353. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  31354. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  31355. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  31356. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  31357. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  31358. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  31359. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  31360. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  31361. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  31362. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  31363. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  31364. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  31365. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  31366. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  31367. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  31368. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  31369. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  31370. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  31371. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  31372. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  31373. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  31374. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  31375. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  31376. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  31377. ];
  31378. var MacStandardGlyphOrdering = [
  31379. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  31380. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  31381. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  31382. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  31383. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  31384. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  31385. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  31386. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  31387. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  31388. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  31389. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  31390. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  31391. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  31392. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  31393. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  31394. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  31395. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  31396. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  31397. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  31398. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  31399. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  31400. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  31401. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  31402. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  31403. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  31404. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  31405. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  31406. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  31407. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  31408. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  31409. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  31410. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  31411. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  31412. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  31413. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  31414. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  31415. function getUnicodeRangeFor(value) {
  31416. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  31417. var range = UnicodeRanges[i];
  31418. if (value >= range.begin && value < range.end) {
  31419. return i;
  31420. }
  31421. }
  31422. return -1;
  31423. }
  31424. function isRTLRangeFor(value) {
  31425. var range = UnicodeRanges[13];
  31426. if (value >= range.begin && value < range.end) {
  31427. return true;
  31428. }
  31429. range = UnicodeRanges[11];
  31430. if (value >= range.begin && value < range.end) {
  31431. return true;
  31432. }
  31433. return false;
  31434. }
  31435. // The normalization table is obtained by filtering the Unicode characters
  31436. // database with <compat> entries.
  31437. var NormalizedUnicodes = {
  31438. '\u00A8': '\u0020\u0308',
  31439. '\u00AF': '\u0020\u0304',
  31440. '\u00B4': '\u0020\u0301',
  31441. '\u00B5': '\u03BC',
  31442. '\u00B8': '\u0020\u0327',
  31443. '\u0132': '\u0049\u004A',
  31444. '\u0133': '\u0069\u006A',
  31445. '\u013F': '\u004C\u00B7',
  31446. '\u0140': '\u006C\u00B7',
  31447. '\u0149': '\u02BC\u006E',
  31448. '\u017F': '\u0073',
  31449. '\u01C4': '\u0044\u017D',
  31450. '\u01C5': '\u0044\u017E',
  31451. '\u01C6': '\u0064\u017E',
  31452. '\u01C7': '\u004C\u004A',
  31453. '\u01C8': '\u004C\u006A',
  31454. '\u01C9': '\u006C\u006A',
  31455. '\u01CA': '\u004E\u004A',
  31456. '\u01CB': '\u004E\u006A',
  31457. '\u01CC': '\u006E\u006A',
  31458. '\u01F1': '\u0044\u005A',
  31459. '\u01F2': '\u0044\u007A',
  31460. '\u01F3': '\u0064\u007A',
  31461. '\u02D8': '\u0020\u0306',
  31462. '\u02D9': '\u0020\u0307',
  31463. '\u02DA': '\u0020\u030A',
  31464. '\u02DB': '\u0020\u0328',
  31465. '\u02DC': '\u0020\u0303',
  31466. '\u02DD': '\u0020\u030B',
  31467. '\u037A': '\u0020\u0345',
  31468. '\u0384': '\u0020\u0301',
  31469. '\u03D0': '\u03B2',
  31470. '\u03D1': '\u03B8',
  31471. '\u03D2': '\u03A5',
  31472. '\u03D5': '\u03C6',
  31473. '\u03D6': '\u03C0',
  31474. '\u03F0': '\u03BA',
  31475. '\u03F1': '\u03C1',
  31476. '\u03F2': '\u03C2',
  31477. '\u03F4': '\u0398',
  31478. '\u03F5': '\u03B5',
  31479. '\u03F9': '\u03A3',
  31480. '\u0587': '\u0565\u0582',
  31481. '\u0675': '\u0627\u0674',
  31482. '\u0676': '\u0648\u0674',
  31483. '\u0677': '\u06C7\u0674',
  31484. '\u0678': '\u064A\u0674',
  31485. '\u0E33': '\u0E4D\u0E32',
  31486. '\u0EB3': '\u0ECD\u0EB2',
  31487. '\u0EDC': '\u0EAB\u0E99',
  31488. '\u0EDD': '\u0EAB\u0EA1',
  31489. '\u0F77': '\u0FB2\u0F81',
  31490. '\u0F79': '\u0FB3\u0F81',
  31491. '\u1E9A': '\u0061\u02BE',
  31492. '\u1FBD': '\u0020\u0313',
  31493. '\u1FBF': '\u0020\u0313',
  31494. '\u1FC0': '\u0020\u0342',
  31495. '\u1FFE': '\u0020\u0314',
  31496. '\u2002': '\u0020',
  31497. '\u2003': '\u0020',
  31498. '\u2004': '\u0020',
  31499. '\u2005': '\u0020',
  31500. '\u2006': '\u0020',
  31501. '\u2008': '\u0020',
  31502. '\u2009': '\u0020',
  31503. '\u200A': '\u0020',
  31504. '\u2017': '\u0020\u0333',
  31505. '\u2024': '\u002E',
  31506. '\u2025': '\u002E\u002E',
  31507. '\u2026': '\u002E\u002E\u002E',
  31508. '\u2033': '\u2032\u2032',
  31509. '\u2034': '\u2032\u2032\u2032',
  31510. '\u2036': '\u2035\u2035',
  31511. '\u2037': '\u2035\u2035\u2035',
  31512. '\u203C': '\u0021\u0021',
  31513. '\u203E': '\u0020\u0305',
  31514. '\u2047': '\u003F\u003F',
  31515. '\u2048': '\u003F\u0021',
  31516. '\u2049': '\u0021\u003F',
  31517. '\u2057': '\u2032\u2032\u2032\u2032',
  31518. '\u205F': '\u0020',
  31519. '\u20A8': '\u0052\u0073',
  31520. '\u2100': '\u0061\u002F\u0063',
  31521. '\u2101': '\u0061\u002F\u0073',
  31522. '\u2103': '\u00B0\u0043',
  31523. '\u2105': '\u0063\u002F\u006F',
  31524. '\u2106': '\u0063\u002F\u0075',
  31525. '\u2107': '\u0190',
  31526. '\u2109': '\u00B0\u0046',
  31527. '\u2116': '\u004E\u006F',
  31528. '\u2121': '\u0054\u0045\u004C',
  31529. '\u2135': '\u05D0',
  31530. '\u2136': '\u05D1',
  31531. '\u2137': '\u05D2',
  31532. '\u2138': '\u05D3',
  31533. '\u213B': '\u0046\u0041\u0058',
  31534. '\u2160': '\u0049',
  31535. '\u2161': '\u0049\u0049',
  31536. '\u2162': '\u0049\u0049\u0049',
  31537. '\u2163': '\u0049\u0056',
  31538. '\u2164': '\u0056',
  31539. '\u2165': '\u0056\u0049',
  31540. '\u2166': '\u0056\u0049\u0049',
  31541. '\u2167': '\u0056\u0049\u0049\u0049',
  31542. '\u2168': '\u0049\u0058',
  31543. '\u2169': '\u0058',
  31544. '\u216A': '\u0058\u0049',
  31545. '\u216B': '\u0058\u0049\u0049',
  31546. '\u216C': '\u004C',
  31547. '\u216D': '\u0043',
  31548. '\u216E': '\u0044',
  31549. '\u216F': '\u004D',
  31550. '\u2170': '\u0069',
  31551. '\u2171': '\u0069\u0069',
  31552. '\u2172': '\u0069\u0069\u0069',
  31553. '\u2173': '\u0069\u0076',
  31554. '\u2174': '\u0076',
  31555. '\u2175': '\u0076\u0069',
  31556. '\u2176': '\u0076\u0069\u0069',
  31557. '\u2177': '\u0076\u0069\u0069\u0069',
  31558. '\u2178': '\u0069\u0078',
  31559. '\u2179': '\u0078',
  31560. '\u217A': '\u0078\u0069',
  31561. '\u217B': '\u0078\u0069\u0069',
  31562. '\u217C': '\u006C',
  31563. '\u217D': '\u0063',
  31564. '\u217E': '\u0064',
  31565. '\u217F': '\u006D',
  31566. '\u222C': '\u222B\u222B',
  31567. '\u222D': '\u222B\u222B\u222B',
  31568. '\u222F': '\u222E\u222E',
  31569. '\u2230': '\u222E\u222E\u222E',
  31570. '\u2474': '\u0028\u0031\u0029',
  31571. '\u2475': '\u0028\u0032\u0029',
  31572. '\u2476': '\u0028\u0033\u0029',
  31573. '\u2477': '\u0028\u0034\u0029',
  31574. '\u2478': '\u0028\u0035\u0029',
  31575. '\u2479': '\u0028\u0036\u0029',
  31576. '\u247A': '\u0028\u0037\u0029',
  31577. '\u247B': '\u0028\u0038\u0029',
  31578. '\u247C': '\u0028\u0039\u0029',
  31579. '\u247D': '\u0028\u0031\u0030\u0029',
  31580. '\u247E': '\u0028\u0031\u0031\u0029',
  31581. '\u247F': '\u0028\u0031\u0032\u0029',
  31582. '\u2480': '\u0028\u0031\u0033\u0029',
  31583. '\u2481': '\u0028\u0031\u0034\u0029',
  31584. '\u2482': '\u0028\u0031\u0035\u0029',
  31585. '\u2483': '\u0028\u0031\u0036\u0029',
  31586. '\u2484': '\u0028\u0031\u0037\u0029',
  31587. '\u2485': '\u0028\u0031\u0038\u0029',
  31588. '\u2486': '\u0028\u0031\u0039\u0029',
  31589. '\u2487': '\u0028\u0032\u0030\u0029',
  31590. '\u2488': '\u0031\u002E',
  31591. '\u2489': '\u0032\u002E',
  31592. '\u248A': '\u0033\u002E',
  31593. '\u248B': '\u0034\u002E',
  31594. '\u248C': '\u0035\u002E',
  31595. '\u248D': '\u0036\u002E',
  31596. '\u248E': '\u0037\u002E',
  31597. '\u248F': '\u0038\u002E',
  31598. '\u2490': '\u0039\u002E',
  31599. '\u2491': '\u0031\u0030\u002E',
  31600. '\u2492': '\u0031\u0031\u002E',
  31601. '\u2493': '\u0031\u0032\u002E',
  31602. '\u2494': '\u0031\u0033\u002E',
  31603. '\u2495': '\u0031\u0034\u002E',
  31604. '\u2496': '\u0031\u0035\u002E',
  31605. '\u2497': '\u0031\u0036\u002E',
  31606. '\u2498': '\u0031\u0037\u002E',
  31607. '\u2499': '\u0031\u0038\u002E',
  31608. '\u249A': '\u0031\u0039\u002E',
  31609. '\u249B': '\u0032\u0030\u002E',
  31610. '\u249C': '\u0028\u0061\u0029',
  31611. '\u249D': '\u0028\u0062\u0029',
  31612. '\u249E': '\u0028\u0063\u0029',
  31613. '\u249F': '\u0028\u0064\u0029',
  31614. '\u24A0': '\u0028\u0065\u0029',
  31615. '\u24A1': '\u0028\u0066\u0029',
  31616. '\u24A2': '\u0028\u0067\u0029',
  31617. '\u24A3': '\u0028\u0068\u0029',
  31618. '\u24A4': '\u0028\u0069\u0029',
  31619. '\u24A5': '\u0028\u006A\u0029',
  31620. '\u24A6': '\u0028\u006B\u0029',
  31621. '\u24A7': '\u0028\u006C\u0029',
  31622. '\u24A8': '\u0028\u006D\u0029',
  31623. '\u24A9': '\u0028\u006E\u0029',
  31624. '\u24AA': '\u0028\u006F\u0029',
  31625. '\u24AB': '\u0028\u0070\u0029',
  31626. '\u24AC': '\u0028\u0071\u0029',
  31627. '\u24AD': '\u0028\u0072\u0029',
  31628. '\u24AE': '\u0028\u0073\u0029',
  31629. '\u24AF': '\u0028\u0074\u0029',
  31630. '\u24B0': '\u0028\u0075\u0029',
  31631. '\u24B1': '\u0028\u0076\u0029',
  31632. '\u24B2': '\u0028\u0077\u0029',
  31633. '\u24B3': '\u0028\u0078\u0029',
  31634. '\u24B4': '\u0028\u0079\u0029',
  31635. '\u24B5': '\u0028\u007A\u0029',
  31636. '\u2A0C': '\u222B\u222B\u222B\u222B',
  31637. '\u2A74': '\u003A\u003A\u003D',
  31638. '\u2A75': '\u003D\u003D',
  31639. '\u2A76': '\u003D\u003D\u003D',
  31640. '\u2E9F': '\u6BCD',
  31641. '\u2EF3': '\u9F9F',
  31642. '\u2F00': '\u4E00',
  31643. '\u2F01': '\u4E28',
  31644. '\u2F02': '\u4E36',
  31645. '\u2F03': '\u4E3F',
  31646. '\u2F04': '\u4E59',
  31647. '\u2F05': '\u4E85',
  31648. '\u2F06': '\u4E8C',
  31649. '\u2F07': '\u4EA0',
  31650. '\u2F08': '\u4EBA',
  31651. '\u2F09': '\u513F',
  31652. '\u2F0A': '\u5165',
  31653. '\u2F0B': '\u516B',
  31654. '\u2F0C': '\u5182',
  31655. '\u2F0D': '\u5196',
  31656. '\u2F0E': '\u51AB',
  31657. '\u2F0F': '\u51E0',
  31658. '\u2F10': '\u51F5',
  31659. '\u2F11': '\u5200',
  31660. '\u2F12': '\u529B',
  31661. '\u2F13': '\u52F9',
  31662. '\u2F14': '\u5315',
  31663. '\u2F15': '\u531A',
  31664. '\u2F16': '\u5338',
  31665. '\u2F17': '\u5341',
  31666. '\u2F18': '\u535C',
  31667. '\u2F19': '\u5369',
  31668. '\u2F1A': '\u5382',
  31669. '\u2F1B': '\u53B6',
  31670. '\u2F1C': '\u53C8',
  31671. '\u2F1D': '\u53E3',
  31672. '\u2F1E': '\u56D7',
  31673. '\u2F1F': '\u571F',
  31674. '\u2F20': '\u58EB',
  31675. '\u2F21': '\u5902',
  31676. '\u2F22': '\u590A',
  31677. '\u2F23': '\u5915',
  31678. '\u2F24': '\u5927',
  31679. '\u2F25': '\u5973',
  31680. '\u2F26': '\u5B50',
  31681. '\u2F27': '\u5B80',
  31682. '\u2F28': '\u5BF8',
  31683. '\u2F29': '\u5C0F',
  31684. '\u2F2A': '\u5C22',
  31685. '\u2F2B': '\u5C38',
  31686. '\u2F2C': '\u5C6E',
  31687. '\u2F2D': '\u5C71',
  31688. '\u2F2E': '\u5DDB',
  31689. '\u2F2F': '\u5DE5',
  31690. '\u2F30': '\u5DF1',
  31691. '\u2F31': '\u5DFE',
  31692. '\u2F32': '\u5E72',
  31693. '\u2F33': '\u5E7A',
  31694. '\u2F34': '\u5E7F',
  31695. '\u2F35': '\u5EF4',
  31696. '\u2F36': '\u5EFE',
  31697. '\u2F37': '\u5F0B',
  31698. '\u2F38': '\u5F13',
  31699. '\u2F39': '\u5F50',
  31700. '\u2F3A': '\u5F61',
  31701. '\u2F3B': '\u5F73',
  31702. '\u2F3C': '\u5FC3',
  31703. '\u2F3D': '\u6208',
  31704. '\u2F3E': '\u6236',
  31705. '\u2F3F': '\u624B',
  31706. '\u2F40': '\u652F',
  31707. '\u2F41': '\u6534',
  31708. '\u2F42': '\u6587',
  31709. '\u2F43': '\u6597',
  31710. '\u2F44': '\u65A4',
  31711. '\u2F45': '\u65B9',
  31712. '\u2F46': '\u65E0',
  31713. '\u2F47': '\u65E5',
  31714. '\u2F48': '\u66F0',
  31715. '\u2F49': '\u6708',
  31716. '\u2F4A': '\u6728',
  31717. '\u2F4B': '\u6B20',
  31718. '\u2F4C': '\u6B62',
  31719. '\u2F4D': '\u6B79',
  31720. '\u2F4E': '\u6BB3',
  31721. '\u2F4F': '\u6BCB',
  31722. '\u2F50': '\u6BD4',
  31723. '\u2F51': '\u6BDB',
  31724. '\u2F52': '\u6C0F',
  31725. '\u2F53': '\u6C14',
  31726. '\u2F54': '\u6C34',
  31727. '\u2F55': '\u706B',
  31728. '\u2F56': '\u722A',
  31729. '\u2F57': '\u7236',
  31730. '\u2F58': '\u723B',
  31731. '\u2F59': '\u723F',
  31732. '\u2F5A': '\u7247',
  31733. '\u2F5B': '\u7259',
  31734. '\u2F5C': '\u725B',
  31735. '\u2F5D': '\u72AC',
  31736. '\u2F5E': '\u7384',
  31737. '\u2F5F': '\u7389',
  31738. '\u2F60': '\u74DC',
  31739. '\u2F61': '\u74E6',
  31740. '\u2F62': '\u7518',
  31741. '\u2F63': '\u751F',
  31742. '\u2F64': '\u7528',
  31743. '\u2F65': '\u7530',
  31744. '\u2F66': '\u758B',
  31745. '\u2F67': '\u7592',
  31746. '\u2F68': '\u7676',
  31747. '\u2F69': '\u767D',
  31748. '\u2F6A': '\u76AE',
  31749. '\u2F6B': '\u76BF',
  31750. '\u2F6C': '\u76EE',
  31751. '\u2F6D': '\u77DB',
  31752. '\u2F6E': '\u77E2',
  31753. '\u2F6F': '\u77F3',
  31754. '\u2F70': '\u793A',
  31755. '\u2F71': '\u79B8',
  31756. '\u2F72': '\u79BE',
  31757. '\u2F73': '\u7A74',
  31758. '\u2F74': '\u7ACB',
  31759. '\u2F75': '\u7AF9',
  31760. '\u2F76': '\u7C73',
  31761. '\u2F77': '\u7CF8',
  31762. '\u2F78': '\u7F36',
  31763. '\u2F79': '\u7F51',
  31764. '\u2F7A': '\u7F8A',
  31765. '\u2F7B': '\u7FBD',
  31766. '\u2F7C': '\u8001',
  31767. '\u2F7D': '\u800C',
  31768. '\u2F7E': '\u8012',
  31769. '\u2F7F': '\u8033',
  31770. '\u2F80': '\u807F',
  31771. '\u2F81': '\u8089',
  31772. '\u2F82': '\u81E3',
  31773. '\u2F83': '\u81EA',
  31774. '\u2F84': '\u81F3',
  31775. '\u2F85': '\u81FC',
  31776. '\u2F86': '\u820C',
  31777. '\u2F87': '\u821B',
  31778. '\u2F88': '\u821F',
  31779. '\u2F89': '\u826E',
  31780. '\u2F8A': '\u8272',
  31781. '\u2F8B': '\u8278',
  31782. '\u2F8C': '\u864D',
  31783. '\u2F8D': '\u866B',
  31784. '\u2F8E': '\u8840',
  31785. '\u2F8F': '\u884C',
  31786. '\u2F90': '\u8863',
  31787. '\u2F91': '\u897E',
  31788. '\u2F92': '\u898B',
  31789. '\u2F93': '\u89D2',
  31790. '\u2F94': '\u8A00',
  31791. '\u2F95': '\u8C37',
  31792. '\u2F96': '\u8C46',
  31793. '\u2F97': '\u8C55',
  31794. '\u2F98': '\u8C78',
  31795. '\u2F99': '\u8C9D',
  31796. '\u2F9A': '\u8D64',
  31797. '\u2F9B': '\u8D70',
  31798. '\u2F9C': '\u8DB3',
  31799. '\u2F9D': '\u8EAB',
  31800. '\u2F9E': '\u8ECA',
  31801. '\u2F9F': '\u8F9B',
  31802. '\u2FA0': '\u8FB0',
  31803. '\u2FA1': '\u8FB5',
  31804. '\u2FA2': '\u9091',
  31805. '\u2FA3': '\u9149',
  31806. '\u2FA4': '\u91C6',
  31807. '\u2FA5': '\u91CC',
  31808. '\u2FA6': '\u91D1',
  31809. '\u2FA7': '\u9577',
  31810. '\u2FA8': '\u9580',
  31811. '\u2FA9': '\u961C',
  31812. '\u2FAA': '\u96B6',
  31813. '\u2FAB': '\u96B9',
  31814. '\u2FAC': '\u96E8',
  31815. '\u2FAD': '\u9751',
  31816. '\u2FAE': '\u975E',
  31817. '\u2FAF': '\u9762',
  31818. '\u2FB0': '\u9769',
  31819. '\u2FB1': '\u97CB',
  31820. '\u2FB2': '\u97ED',
  31821. '\u2FB3': '\u97F3',
  31822. '\u2FB4': '\u9801',
  31823. '\u2FB5': '\u98A8',
  31824. '\u2FB6': '\u98DB',
  31825. '\u2FB7': '\u98DF',
  31826. '\u2FB8': '\u9996',
  31827. '\u2FB9': '\u9999',
  31828. '\u2FBA': '\u99AC',
  31829. '\u2FBB': '\u9AA8',
  31830. '\u2FBC': '\u9AD8',
  31831. '\u2FBD': '\u9ADF',
  31832. '\u2FBE': '\u9B25',
  31833. '\u2FBF': '\u9B2F',
  31834. '\u2FC0': '\u9B32',
  31835. '\u2FC1': '\u9B3C',
  31836. '\u2FC2': '\u9B5A',
  31837. '\u2FC3': '\u9CE5',
  31838. '\u2FC4': '\u9E75',
  31839. '\u2FC5': '\u9E7F',
  31840. '\u2FC6': '\u9EA5',
  31841. '\u2FC7': '\u9EBB',
  31842. '\u2FC8': '\u9EC3',
  31843. '\u2FC9': '\u9ECD',
  31844. '\u2FCA': '\u9ED1',
  31845. '\u2FCB': '\u9EF9',
  31846. '\u2FCC': '\u9EFD',
  31847. '\u2FCD': '\u9F0E',
  31848. '\u2FCE': '\u9F13',
  31849. '\u2FCF': '\u9F20',
  31850. '\u2FD0': '\u9F3B',
  31851. '\u2FD1': '\u9F4A',
  31852. '\u2FD2': '\u9F52',
  31853. '\u2FD3': '\u9F8D',
  31854. '\u2FD4': '\u9F9C',
  31855. '\u2FD5': '\u9FA0',
  31856. '\u3036': '\u3012',
  31857. '\u3038': '\u5341',
  31858. '\u3039': '\u5344',
  31859. '\u303A': '\u5345',
  31860. '\u309B': '\u0020\u3099',
  31861. '\u309C': '\u0020\u309A',
  31862. '\u3131': '\u1100',
  31863. '\u3132': '\u1101',
  31864. '\u3133': '\u11AA',
  31865. '\u3134': '\u1102',
  31866. '\u3135': '\u11AC',
  31867. '\u3136': '\u11AD',
  31868. '\u3137': '\u1103',
  31869. '\u3138': '\u1104',
  31870. '\u3139': '\u1105',
  31871. '\u313A': '\u11B0',
  31872. '\u313B': '\u11B1',
  31873. '\u313C': '\u11B2',
  31874. '\u313D': '\u11B3',
  31875. '\u313E': '\u11B4',
  31876. '\u313F': '\u11B5',
  31877. '\u3140': '\u111A',
  31878. '\u3141': '\u1106',
  31879. '\u3142': '\u1107',
  31880. '\u3143': '\u1108',
  31881. '\u3144': '\u1121',
  31882. '\u3145': '\u1109',
  31883. '\u3146': '\u110A',
  31884. '\u3147': '\u110B',
  31885. '\u3148': '\u110C',
  31886. '\u3149': '\u110D',
  31887. '\u314A': '\u110E',
  31888. '\u314B': '\u110F',
  31889. '\u314C': '\u1110',
  31890. '\u314D': '\u1111',
  31891. '\u314E': '\u1112',
  31892. '\u314F': '\u1161',
  31893. '\u3150': '\u1162',
  31894. '\u3151': '\u1163',
  31895. '\u3152': '\u1164',
  31896. '\u3153': '\u1165',
  31897. '\u3154': '\u1166',
  31898. '\u3155': '\u1167',
  31899. '\u3156': '\u1168',
  31900. '\u3157': '\u1169',
  31901. '\u3158': '\u116A',
  31902. '\u3159': '\u116B',
  31903. '\u315A': '\u116C',
  31904. '\u315B': '\u116D',
  31905. '\u315C': '\u116E',
  31906. '\u315D': '\u116F',
  31907. '\u315E': '\u1170',
  31908. '\u315F': '\u1171',
  31909. '\u3160': '\u1172',
  31910. '\u3161': '\u1173',
  31911. '\u3162': '\u1174',
  31912. '\u3163': '\u1175',
  31913. '\u3164': '\u1160',
  31914. '\u3165': '\u1114',
  31915. '\u3166': '\u1115',
  31916. '\u3167': '\u11C7',
  31917. '\u3168': '\u11C8',
  31918. '\u3169': '\u11CC',
  31919. '\u316A': '\u11CE',
  31920. '\u316B': '\u11D3',
  31921. '\u316C': '\u11D7',
  31922. '\u316D': '\u11D9',
  31923. '\u316E': '\u111C',
  31924. '\u316F': '\u11DD',
  31925. '\u3170': '\u11DF',
  31926. '\u3171': '\u111D',
  31927. '\u3172': '\u111E',
  31928. '\u3173': '\u1120',
  31929. '\u3174': '\u1122',
  31930. '\u3175': '\u1123',
  31931. '\u3176': '\u1127',
  31932. '\u3177': '\u1129',
  31933. '\u3178': '\u112B',
  31934. '\u3179': '\u112C',
  31935. '\u317A': '\u112D',
  31936. '\u317B': '\u112E',
  31937. '\u317C': '\u112F',
  31938. '\u317D': '\u1132',
  31939. '\u317E': '\u1136',
  31940. '\u317F': '\u1140',
  31941. '\u3180': '\u1147',
  31942. '\u3181': '\u114C',
  31943. '\u3182': '\u11F1',
  31944. '\u3183': '\u11F2',
  31945. '\u3184': '\u1157',
  31946. '\u3185': '\u1158',
  31947. '\u3186': '\u1159',
  31948. '\u3187': '\u1184',
  31949. '\u3188': '\u1185',
  31950. '\u3189': '\u1188',
  31951. '\u318A': '\u1191',
  31952. '\u318B': '\u1192',
  31953. '\u318C': '\u1194',
  31954. '\u318D': '\u119E',
  31955. '\u318E': '\u11A1',
  31956. '\u3200': '\u0028\u1100\u0029',
  31957. '\u3201': '\u0028\u1102\u0029',
  31958. '\u3202': '\u0028\u1103\u0029',
  31959. '\u3203': '\u0028\u1105\u0029',
  31960. '\u3204': '\u0028\u1106\u0029',
  31961. '\u3205': '\u0028\u1107\u0029',
  31962. '\u3206': '\u0028\u1109\u0029',
  31963. '\u3207': '\u0028\u110B\u0029',
  31964. '\u3208': '\u0028\u110C\u0029',
  31965. '\u3209': '\u0028\u110E\u0029',
  31966. '\u320A': '\u0028\u110F\u0029',
  31967. '\u320B': '\u0028\u1110\u0029',
  31968. '\u320C': '\u0028\u1111\u0029',
  31969. '\u320D': '\u0028\u1112\u0029',
  31970. '\u320E': '\u0028\u1100\u1161\u0029',
  31971. '\u320F': '\u0028\u1102\u1161\u0029',
  31972. '\u3210': '\u0028\u1103\u1161\u0029',
  31973. '\u3211': '\u0028\u1105\u1161\u0029',
  31974. '\u3212': '\u0028\u1106\u1161\u0029',
  31975. '\u3213': '\u0028\u1107\u1161\u0029',
  31976. '\u3214': '\u0028\u1109\u1161\u0029',
  31977. '\u3215': '\u0028\u110B\u1161\u0029',
  31978. '\u3216': '\u0028\u110C\u1161\u0029',
  31979. '\u3217': '\u0028\u110E\u1161\u0029',
  31980. '\u3218': '\u0028\u110F\u1161\u0029',
  31981. '\u3219': '\u0028\u1110\u1161\u0029',
  31982. '\u321A': '\u0028\u1111\u1161\u0029',
  31983. '\u321B': '\u0028\u1112\u1161\u0029',
  31984. '\u321C': '\u0028\u110C\u116E\u0029',
  31985. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  31986. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  31987. '\u3220': '\u0028\u4E00\u0029',
  31988. '\u3221': '\u0028\u4E8C\u0029',
  31989. '\u3222': '\u0028\u4E09\u0029',
  31990. '\u3223': '\u0028\u56DB\u0029',
  31991. '\u3224': '\u0028\u4E94\u0029',
  31992. '\u3225': '\u0028\u516D\u0029',
  31993. '\u3226': '\u0028\u4E03\u0029',
  31994. '\u3227': '\u0028\u516B\u0029',
  31995. '\u3228': '\u0028\u4E5D\u0029',
  31996. '\u3229': '\u0028\u5341\u0029',
  31997. '\u322A': '\u0028\u6708\u0029',
  31998. '\u322B': '\u0028\u706B\u0029',
  31999. '\u322C': '\u0028\u6C34\u0029',
  32000. '\u322D': '\u0028\u6728\u0029',
  32001. '\u322E': '\u0028\u91D1\u0029',
  32002. '\u322F': '\u0028\u571F\u0029',
  32003. '\u3230': '\u0028\u65E5\u0029',
  32004. '\u3231': '\u0028\u682A\u0029',
  32005. '\u3232': '\u0028\u6709\u0029',
  32006. '\u3233': '\u0028\u793E\u0029',
  32007. '\u3234': '\u0028\u540D\u0029',
  32008. '\u3235': '\u0028\u7279\u0029',
  32009. '\u3236': '\u0028\u8CA1\u0029',
  32010. '\u3237': '\u0028\u795D\u0029',
  32011. '\u3238': '\u0028\u52B4\u0029',
  32012. '\u3239': '\u0028\u4EE3\u0029',
  32013. '\u323A': '\u0028\u547C\u0029',
  32014. '\u323B': '\u0028\u5B66\u0029',
  32015. '\u323C': '\u0028\u76E3\u0029',
  32016. '\u323D': '\u0028\u4F01\u0029',
  32017. '\u323E': '\u0028\u8CC7\u0029',
  32018. '\u323F': '\u0028\u5354\u0029',
  32019. '\u3240': '\u0028\u796D\u0029',
  32020. '\u3241': '\u0028\u4F11\u0029',
  32021. '\u3242': '\u0028\u81EA\u0029',
  32022. '\u3243': '\u0028\u81F3\u0029',
  32023. '\u32C0': '\u0031\u6708',
  32024. '\u32C1': '\u0032\u6708',
  32025. '\u32C2': '\u0033\u6708',
  32026. '\u32C3': '\u0034\u6708',
  32027. '\u32C4': '\u0035\u6708',
  32028. '\u32C5': '\u0036\u6708',
  32029. '\u32C6': '\u0037\u6708',
  32030. '\u32C7': '\u0038\u6708',
  32031. '\u32C8': '\u0039\u6708',
  32032. '\u32C9': '\u0031\u0030\u6708',
  32033. '\u32CA': '\u0031\u0031\u6708',
  32034. '\u32CB': '\u0031\u0032\u6708',
  32035. '\u3358': '\u0030\u70B9',
  32036. '\u3359': '\u0031\u70B9',
  32037. '\u335A': '\u0032\u70B9',
  32038. '\u335B': '\u0033\u70B9',
  32039. '\u335C': '\u0034\u70B9',
  32040. '\u335D': '\u0035\u70B9',
  32041. '\u335E': '\u0036\u70B9',
  32042. '\u335F': '\u0037\u70B9',
  32043. '\u3360': '\u0038\u70B9',
  32044. '\u3361': '\u0039\u70B9',
  32045. '\u3362': '\u0031\u0030\u70B9',
  32046. '\u3363': '\u0031\u0031\u70B9',
  32047. '\u3364': '\u0031\u0032\u70B9',
  32048. '\u3365': '\u0031\u0033\u70B9',
  32049. '\u3366': '\u0031\u0034\u70B9',
  32050. '\u3367': '\u0031\u0035\u70B9',
  32051. '\u3368': '\u0031\u0036\u70B9',
  32052. '\u3369': '\u0031\u0037\u70B9',
  32053. '\u336A': '\u0031\u0038\u70B9',
  32054. '\u336B': '\u0031\u0039\u70B9',
  32055. '\u336C': '\u0032\u0030\u70B9',
  32056. '\u336D': '\u0032\u0031\u70B9',
  32057. '\u336E': '\u0032\u0032\u70B9',
  32058. '\u336F': '\u0032\u0033\u70B9',
  32059. '\u3370': '\u0032\u0034\u70B9',
  32060. '\u33E0': '\u0031\u65E5',
  32061. '\u33E1': '\u0032\u65E5',
  32062. '\u33E2': '\u0033\u65E5',
  32063. '\u33E3': '\u0034\u65E5',
  32064. '\u33E4': '\u0035\u65E5',
  32065. '\u33E5': '\u0036\u65E5',
  32066. '\u33E6': '\u0037\u65E5',
  32067. '\u33E7': '\u0038\u65E5',
  32068. '\u33E8': '\u0039\u65E5',
  32069. '\u33E9': '\u0031\u0030\u65E5',
  32070. '\u33EA': '\u0031\u0031\u65E5',
  32071. '\u33EB': '\u0031\u0032\u65E5',
  32072. '\u33EC': '\u0031\u0033\u65E5',
  32073. '\u33ED': '\u0031\u0034\u65E5',
  32074. '\u33EE': '\u0031\u0035\u65E5',
  32075. '\u33EF': '\u0031\u0036\u65E5',
  32076. '\u33F0': '\u0031\u0037\u65E5',
  32077. '\u33F1': '\u0031\u0038\u65E5',
  32078. '\u33F2': '\u0031\u0039\u65E5',
  32079. '\u33F3': '\u0032\u0030\u65E5',
  32080. '\u33F4': '\u0032\u0031\u65E5',
  32081. '\u33F5': '\u0032\u0032\u65E5',
  32082. '\u33F6': '\u0032\u0033\u65E5',
  32083. '\u33F7': '\u0032\u0034\u65E5',
  32084. '\u33F8': '\u0032\u0035\u65E5',
  32085. '\u33F9': '\u0032\u0036\u65E5',
  32086. '\u33FA': '\u0032\u0037\u65E5',
  32087. '\u33FB': '\u0032\u0038\u65E5',
  32088. '\u33FC': '\u0032\u0039\u65E5',
  32089. '\u33FD': '\u0033\u0030\u65E5',
  32090. '\u33FE': '\u0033\u0031\u65E5',
  32091. '\uFB00': '\u0066\u0066',
  32092. '\uFB01': '\u0066\u0069',
  32093. '\uFB02': '\u0066\u006C',
  32094. '\uFB03': '\u0066\u0066\u0069',
  32095. '\uFB04': '\u0066\u0066\u006C',
  32096. '\uFB05': '\u017F\u0074',
  32097. '\uFB06': '\u0073\u0074',
  32098. '\uFB13': '\u0574\u0576',
  32099. '\uFB14': '\u0574\u0565',
  32100. '\uFB15': '\u0574\u056B',
  32101. '\uFB16': '\u057E\u0576',
  32102. '\uFB17': '\u0574\u056D',
  32103. '\uFB4F': '\u05D0\u05DC',
  32104. '\uFB50': '\u0671',
  32105. '\uFB51': '\u0671',
  32106. '\uFB52': '\u067B',
  32107. '\uFB53': '\u067B',
  32108. '\uFB54': '\u067B',
  32109. '\uFB55': '\u067B',
  32110. '\uFB56': '\u067E',
  32111. '\uFB57': '\u067E',
  32112. '\uFB58': '\u067E',
  32113. '\uFB59': '\u067E',
  32114. '\uFB5A': '\u0680',
  32115. '\uFB5B': '\u0680',
  32116. '\uFB5C': '\u0680',
  32117. '\uFB5D': '\u0680',
  32118. '\uFB5E': '\u067A',
  32119. '\uFB5F': '\u067A',
  32120. '\uFB60': '\u067A',
  32121. '\uFB61': '\u067A',
  32122. '\uFB62': '\u067F',
  32123. '\uFB63': '\u067F',
  32124. '\uFB64': '\u067F',
  32125. '\uFB65': '\u067F',
  32126. '\uFB66': '\u0679',
  32127. '\uFB67': '\u0679',
  32128. '\uFB68': '\u0679',
  32129. '\uFB69': '\u0679',
  32130. '\uFB6A': '\u06A4',
  32131. '\uFB6B': '\u06A4',
  32132. '\uFB6C': '\u06A4',
  32133. '\uFB6D': '\u06A4',
  32134. '\uFB6E': '\u06A6',
  32135. '\uFB6F': '\u06A6',
  32136. '\uFB70': '\u06A6',
  32137. '\uFB71': '\u06A6',
  32138. '\uFB72': '\u0684',
  32139. '\uFB73': '\u0684',
  32140. '\uFB74': '\u0684',
  32141. '\uFB75': '\u0684',
  32142. '\uFB76': '\u0683',
  32143. '\uFB77': '\u0683',
  32144. '\uFB78': '\u0683',
  32145. '\uFB79': '\u0683',
  32146. '\uFB7A': '\u0686',
  32147. '\uFB7B': '\u0686',
  32148. '\uFB7C': '\u0686',
  32149. '\uFB7D': '\u0686',
  32150. '\uFB7E': '\u0687',
  32151. '\uFB7F': '\u0687',
  32152. '\uFB80': '\u0687',
  32153. '\uFB81': '\u0687',
  32154. '\uFB82': '\u068D',
  32155. '\uFB83': '\u068D',
  32156. '\uFB84': '\u068C',
  32157. '\uFB85': '\u068C',
  32158. '\uFB86': '\u068E',
  32159. '\uFB87': '\u068E',
  32160. '\uFB88': '\u0688',
  32161. '\uFB89': '\u0688',
  32162. '\uFB8A': '\u0698',
  32163. '\uFB8B': '\u0698',
  32164. '\uFB8C': '\u0691',
  32165. '\uFB8D': '\u0691',
  32166. '\uFB8E': '\u06A9',
  32167. '\uFB8F': '\u06A9',
  32168. '\uFB90': '\u06A9',
  32169. '\uFB91': '\u06A9',
  32170. '\uFB92': '\u06AF',
  32171. '\uFB93': '\u06AF',
  32172. '\uFB94': '\u06AF',
  32173. '\uFB95': '\u06AF',
  32174. '\uFB96': '\u06B3',
  32175. '\uFB97': '\u06B3',
  32176. '\uFB98': '\u06B3',
  32177. '\uFB99': '\u06B3',
  32178. '\uFB9A': '\u06B1',
  32179. '\uFB9B': '\u06B1',
  32180. '\uFB9C': '\u06B1',
  32181. '\uFB9D': '\u06B1',
  32182. '\uFB9E': '\u06BA',
  32183. '\uFB9F': '\u06BA',
  32184. '\uFBA0': '\u06BB',
  32185. '\uFBA1': '\u06BB',
  32186. '\uFBA2': '\u06BB',
  32187. '\uFBA3': '\u06BB',
  32188. '\uFBA4': '\u06C0',
  32189. '\uFBA5': '\u06C0',
  32190. '\uFBA6': '\u06C1',
  32191. '\uFBA7': '\u06C1',
  32192. '\uFBA8': '\u06C1',
  32193. '\uFBA9': '\u06C1',
  32194. '\uFBAA': '\u06BE',
  32195. '\uFBAB': '\u06BE',
  32196. '\uFBAC': '\u06BE',
  32197. '\uFBAD': '\u06BE',
  32198. '\uFBAE': '\u06D2',
  32199. '\uFBAF': '\u06D2',
  32200. '\uFBB0': '\u06D3',
  32201. '\uFBB1': '\u06D3',
  32202. '\uFBD3': '\u06AD',
  32203. '\uFBD4': '\u06AD',
  32204. '\uFBD5': '\u06AD',
  32205. '\uFBD6': '\u06AD',
  32206. '\uFBD7': '\u06C7',
  32207. '\uFBD8': '\u06C7',
  32208. '\uFBD9': '\u06C6',
  32209. '\uFBDA': '\u06C6',
  32210. '\uFBDB': '\u06C8',
  32211. '\uFBDC': '\u06C8',
  32212. '\uFBDD': '\u0677',
  32213. '\uFBDE': '\u06CB',
  32214. '\uFBDF': '\u06CB',
  32215. '\uFBE0': '\u06C5',
  32216. '\uFBE1': '\u06C5',
  32217. '\uFBE2': '\u06C9',
  32218. '\uFBE3': '\u06C9',
  32219. '\uFBE4': '\u06D0',
  32220. '\uFBE5': '\u06D0',
  32221. '\uFBE6': '\u06D0',
  32222. '\uFBE7': '\u06D0',
  32223. '\uFBE8': '\u0649',
  32224. '\uFBE9': '\u0649',
  32225. '\uFBEA': '\u0626\u0627',
  32226. '\uFBEB': '\u0626\u0627',
  32227. '\uFBEC': '\u0626\u06D5',
  32228. '\uFBED': '\u0626\u06D5',
  32229. '\uFBEE': '\u0626\u0648',
  32230. '\uFBEF': '\u0626\u0648',
  32231. '\uFBF0': '\u0626\u06C7',
  32232. '\uFBF1': '\u0626\u06C7',
  32233. '\uFBF2': '\u0626\u06C6',
  32234. '\uFBF3': '\u0626\u06C6',
  32235. '\uFBF4': '\u0626\u06C8',
  32236. '\uFBF5': '\u0626\u06C8',
  32237. '\uFBF6': '\u0626\u06D0',
  32238. '\uFBF7': '\u0626\u06D0',
  32239. '\uFBF8': '\u0626\u06D0',
  32240. '\uFBF9': '\u0626\u0649',
  32241. '\uFBFA': '\u0626\u0649',
  32242. '\uFBFB': '\u0626\u0649',
  32243. '\uFBFC': '\u06CC',
  32244. '\uFBFD': '\u06CC',
  32245. '\uFBFE': '\u06CC',
  32246. '\uFBFF': '\u06CC',
  32247. '\uFC00': '\u0626\u062C',
  32248. '\uFC01': '\u0626\u062D',
  32249. '\uFC02': '\u0626\u0645',
  32250. '\uFC03': '\u0626\u0649',
  32251. '\uFC04': '\u0626\u064A',
  32252. '\uFC05': '\u0628\u062C',
  32253. '\uFC06': '\u0628\u062D',
  32254. '\uFC07': '\u0628\u062E',
  32255. '\uFC08': '\u0628\u0645',
  32256. '\uFC09': '\u0628\u0649',
  32257. '\uFC0A': '\u0628\u064A',
  32258. '\uFC0B': '\u062A\u062C',
  32259. '\uFC0C': '\u062A\u062D',
  32260. '\uFC0D': '\u062A\u062E',
  32261. '\uFC0E': '\u062A\u0645',
  32262. '\uFC0F': '\u062A\u0649',
  32263. '\uFC10': '\u062A\u064A',
  32264. '\uFC11': '\u062B\u062C',
  32265. '\uFC12': '\u062B\u0645',
  32266. '\uFC13': '\u062B\u0649',
  32267. '\uFC14': '\u062B\u064A',
  32268. '\uFC15': '\u062C\u062D',
  32269. '\uFC16': '\u062C\u0645',
  32270. '\uFC17': '\u062D\u062C',
  32271. '\uFC18': '\u062D\u0645',
  32272. '\uFC19': '\u062E\u062C',
  32273. '\uFC1A': '\u062E\u062D',
  32274. '\uFC1B': '\u062E\u0645',
  32275. '\uFC1C': '\u0633\u062C',
  32276. '\uFC1D': '\u0633\u062D',
  32277. '\uFC1E': '\u0633\u062E',
  32278. '\uFC1F': '\u0633\u0645',
  32279. '\uFC20': '\u0635\u062D',
  32280. '\uFC21': '\u0635\u0645',
  32281. '\uFC22': '\u0636\u062C',
  32282. '\uFC23': '\u0636\u062D',
  32283. '\uFC24': '\u0636\u062E',
  32284. '\uFC25': '\u0636\u0645',
  32285. '\uFC26': '\u0637\u062D',
  32286. '\uFC27': '\u0637\u0645',
  32287. '\uFC28': '\u0638\u0645',
  32288. '\uFC29': '\u0639\u062C',
  32289. '\uFC2A': '\u0639\u0645',
  32290. '\uFC2B': '\u063A\u062C',
  32291. '\uFC2C': '\u063A\u0645',
  32292. '\uFC2D': '\u0641\u062C',
  32293. '\uFC2E': '\u0641\u062D',
  32294. '\uFC2F': '\u0641\u062E',
  32295. '\uFC30': '\u0641\u0645',
  32296. '\uFC31': '\u0641\u0649',
  32297. '\uFC32': '\u0641\u064A',
  32298. '\uFC33': '\u0642\u062D',
  32299. '\uFC34': '\u0642\u0645',
  32300. '\uFC35': '\u0642\u0649',
  32301. '\uFC36': '\u0642\u064A',
  32302. '\uFC37': '\u0643\u0627',
  32303. '\uFC38': '\u0643\u062C',
  32304. '\uFC39': '\u0643\u062D',
  32305. '\uFC3A': '\u0643\u062E',
  32306. '\uFC3B': '\u0643\u0644',
  32307. '\uFC3C': '\u0643\u0645',
  32308. '\uFC3D': '\u0643\u0649',
  32309. '\uFC3E': '\u0643\u064A',
  32310. '\uFC3F': '\u0644\u062C',
  32311. '\uFC40': '\u0644\u062D',
  32312. '\uFC41': '\u0644\u062E',
  32313. '\uFC42': '\u0644\u0645',
  32314. '\uFC43': '\u0644\u0649',
  32315. '\uFC44': '\u0644\u064A',
  32316. '\uFC45': '\u0645\u062C',
  32317. '\uFC46': '\u0645\u062D',
  32318. '\uFC47': '\u0645\u062E',
  32319. '\uFC48': '\u0645\u0645',
  32320. '\uFC49': '\u0645\u0649',
  32321. '\uFC4A': '\u0645\u064A',
  32322. '\uFC4B': '\u0646\u062C',
  32323. '\uFC4C': '\u0646\u062D',
  32324. '\uFC4D': '\u0646\u062E',
  32325. '\uFC4E': '\u0646\u0645',
  32326. '\uFC4F': '\u0646\u0649',
  32327. '\uFC50': '\u0646\u064A',
  32328. '\uFC51': '\u0647\u062C',
  32329. '\uFC52': '\u0647\u0645',
  32330. '\uFC53': '\u0647\u0649',
  32331. '\uFC54': '\u0647\u064A',
  32332. '\uFC55': '\u064A\u062C',
  32333. '\uFC56': '\u064A\u062D',
  32334. '\uFC57': '\u064A\u062E',
  32335. '\uFC58': '\u064A\u0645',
  32336. '\uFC59': '\u064A\u0649',
  32337. '\uFC5A': '\u064A\u064A',
  32338. '\uFC5B': '\u0630\u0670',
  32339. '\uFC5C': '\u0631\u0670',
  32340. '\uFC5D': '\u0649\u0670',
  32341. '\uFC5E': '\u0020\u064C\u0651',
  32342. '\uFC5F': '\u0020\u064D\u0651',
  32343. '\uFC60': '\u0020\u064E\u0651',
  32344. '\uFC61': '\u0020\u064F\u0651',
  32345. '\uFC62': '\u0020\u0650\u0651',
  32346. '\uFC63': '\u0020\u0651\u0670',
  32347. '\uFC64': '\u0626\u0631',
  32348. '\uFC65': '\u0626\u0632',
  32349. '\uFC66': '\u0626\u0645',
  32350. '\uFC67': '\u0626\u0646',
  32351. '\uFC68': '\u0626\u0649',
  32352. '\uFC69': '\u0626\u064A',
  32353. '\uFC6A': '\u0628\u0631',
  32354. '\uFC6B': '\u0628\u0632',
  32355. '\uFC6C': '\u0628\u0645',
  32356. '\uFC6D': '\u0628\u0646',
  32357. '\uFC6E': '\u0628\u0649',
  32358. '\uFC6F': '\u0628\u064A',
  32359. '\uFC70': '\u062A\u0631',
  32360. '\uFC71': '\u062A\u0632',
  32361. '\uFC72': '\u062A\u0645',
  32362. '\uFC73': '\u062A\u0646',
  32363. '\uFC74': '\u062A\u0649',
  32364. '\uFC75': '\u062A\u064A',
  32365. '\uFC76': '\u062B\u0631',
  32366. '\uFC77': '\u062B\u0632',
  32367. '\uFC78': '\u062B\u0645',
  32368. '\uFC79': '\u062B\u0646',
  32369. '\uFC7A': '\u062B\u0649',
  32370. '\uFC7B': '\u062B\u064A',
  32371. '\uFC7C': '\u0641\u0649',
  32372. '\uFC7D': '\u0641\u064A',
  32373. '\uFC7E': '\u0642\u0649',
  32374. '\uFC7F': '\u0642\u064A',
  32375. '\uFC80': '\u0643\u0627',
  32376. '\uFC81': '\u0643\u0644',
  32377. '\uFC82': '\u0643\u0645',
  32378. '\uFC83': '\u0643\u0649',
  32379. '\uFC84': '\u0643\u064A',
  32380. '\uFC85': '\u0644\u0645',
  32381. '\uFC86': '\u0644\u0649',
  32382. '\uFC87': '\u0644\u064A',
  32383. '\uFC88': '\u0645\u0627',
  32384. '\uFC89': '\u0645\u0645',
  32385. '\uFC8A': '\u0646\u0631',
  32386. '\uFC8B': '\u0646\u0632',
  32387. '\uFC8C': '\u0646\u0645',
  32388. '\uFC8D': '\u0646\u0646',
  32389. '\uFC8E': '\u0646\u0649',
  32390. '\uFC8F': '\u0646\u064A',
  32391. '\uFC90': '\u0649\u0670',
  32392. '\uFC91': '\u064A\u0631',
  32393. '\uFC92': '\u064A\u0632',
  32394. '\uFC93': '\u064A\u0645',
  32395. '\uFC94': '\u064A\u0646',
  32396. '\uFC95': '\u064A\u0649',
  32397. '\uFC96': '\u064A\u064A',
  32398. '\uFC97': '\u0626\u062C',
  32399. '\uFC98': '\u0626\u062D',
  32400. '\uFC99': '\u0626\u062E',
  32401. '\uFC9A': '\u0626\u0645',
  32402. '\uFC9B': '\u0626\u0647',
  32403. '\uFC9C': '\u0628\u062C',
  32404. '\uFC9D': '\u0628\u062D',
  32405. '\uFC9E': '\u0628\u062E',
  32406. '\uFC9F': '\u0628\u0645',
  32407. '\uFCA0': '\u0628\u0647',
  32408. '\uFCA1': '\u062A\u062C',
  32409. '\uFCA2': '\u062A\u062D',
  32410. '\uFCA3': '\u062A\u062E',
  32411. '\uFCA4': '\u062A\u0645',
  32412. '\uFCA5': '\u062A\u0647',
  32413. '\uFCA6': '\u062B\u0645',
  32414. '\uFCA7': '\u062C\u062D',
  32415. '\uFCA8': '\u062C\u0645',
  32416. '\uFCA9': '\u062D\u062C',
  32417. '\uFCAA': '\u062D\u0645',
  32418. '\uFCAB': '\u062E\u062C',
  32419. '\uFCAC': '\u062E\u0645',
  32420. '\uFCAD': '\u0633\u062C',
  32421. '\uFCAE': '\u0633\u062D',
  32422. '\uFCAF': '\u0633\u062E',
  32423. '\uFCB0': '\u0633\u0645',
  32424. '\uFCB1': '\u0635\u062D',
  32425. '\uFCB2': '\u0635\u062E',
  32426. '\uFCB3': '\u0635\u0645',
  32427. '\uFCB4': '\u0636\u062C',
  32428. '\uFCB5': '\u0636\u062D',
  32429. '\uFCB6': '\u0636\u062E',
  32430. '\uFCB7': '\u0636\u0645',
  32431. '\uFCB8': '\u0637\u062D',
  32432. '\uFCB9': '\u0638\u0645',
  32433. '\uFCBA': '\u0639\u062C',
  32434. '\uFCBB': '\u0639\u0645',
  32435. '\uFCBC': '\u063A\u062C',
  32436. '\uFCBD': '\u063A\u0645',
  32437. '\uFCBE': '\u0641\u062C',
  32438. '\uFCBF': '\u0641\u062D',
  32439. '\uFCC0': '\u0641\u062E',
  32440. '\uFCC1': '\u0641\u0645',
  32441. '\uFCC2': '\u0642\u062D',
  32442. '\uFCC3': '\u0642\u0645',
  32443. '\uFCC4': '\u0643\u062C',
  32444. '\uFCC5': '\u0643\u062D',
  32445. '\uFCC6': '\u0643\u062E',
  32446. '\uFCC7': '\u0643\u0644',
  32447. '\uFCC8': '\u0643\u0645',
  32448. '\uFCC9': '\u0644\u062C',
  32449. '\uFCCA': '\u0644\u062D',
  32450. '\uFCCB': '\u0644\u062E',
  32451. '\uFCCC': '\u0644\u0645',
  32452. '\uFCCD': '\u0644\u0647',
  32453. '\uFCCE': '\u0645\u062C',
  32454. '\uFCCF': '\u0645\u062D',
  32455. '\uFCD0': '\u0645\u062E',
  32456. '\uFCD1': '\u0645\u0645',
  32457. '\uFCD2': '\u0646\u062C',
  32458. '\uFCD3': '\u0646\u062D',
  32459. '\uFCD4': '\u0646\u062E',
  32460. '\uFCD5': '\u0646\u0645',
  32461. '\uFCD6': '\u0646\u0647',
  32462. '\uFCD7': '\u0647\u062C',
  32463. '\uFCD8': '\u0647\u0645',
  32464. '\uFCD9': '\u0647\u0670',
  32465. '\uFCDA': '\u064A\u062C',
  32466. '\uFCDB': '\u064A\u062D',
  32467. '\uFCDC': '\u064A\u062E',
  32468. '\uFCDD': '\u064A\u0645',
  32469. '\uFCDE': '\u064A\u0647',
  32470. '\uFCDF': '\u0626\u0645',
  32471. '\uFCE0': '\u0626\u0647',
  32472. '\uFCE1': '\u0628\u0645',
  32473. '\uFCE2': '\u0628\u0647',
  32474. '\uFCE3': '\u062A\u0645',
  32475. '\uFCE4': '\u062A\u0647',
  32476. '\uFCE5': '\u062B\u0645',
  32477. '\uFCE6': '\u062B\u0647',
  32478. '\uFCE7': '\u0633\u0645',
  32479. '\uFCE8': '\u0633\u0647',
  32480. '\uFCE9': '\u0634\u0645',
  32481. '\uFCEA': '\u0634\u0647',
  32482. '\uFCEB': '\u0643\u0644',
  32483. '\uFCEC': '\u0643\u0645',
  32484. '\uFCED': '\u0644\u0645',
  32485. '\uFCEE': '\u0646\u0645',
  32486. '\uFCEF': '\u0646\u0647',
  32487. '\uFCF0': '\u064A\u0645',
  32488. '\uFCF1': '\u064A\u0647',
  32489. '\uFCF2': '\u0640\u064E\u0651',
  32490. '\uFCF3': '\u0640\u064F\u0651',
  32491. '\uFCF4': '\u0640\u0650\u0651',
  32492. '\uFCF5': '\u0637\u0649',
  32493. '\uFCF6': '\u0637\u064A',
  32494. '\uFCF7': '\u0639\u0649',
  32495. '\uFCF8': '\u0639\u064A',
  32496. '\uFCF9': '\u063A\u0649',
  32497. '\uFCFA': '\u063A\u064A',
  32498. '\uFCFB': '\u0633\u0649',
  32499. '\uFCFC': '\u0633\u064A',
  32500. '\uFCFD': '\u0634\u0649',
  32501. '\uFCFE': '\u0634\u064A',
  32502. '\uFCFF': '\u062D\u0649',
  32503. '\uFD00': '\u062D\u064A',
  32504. '\uFD01': '\u062C\u0649',
  32505. '\uFD02': '\u062C\u064A',
  32506. '\uFD03': '\u062E\u0649',
  32507. '\uFD04': '\u062E\u064A',
  32508. '\uFD05': '\u0635\u0649',
  32509. '\uFD06': '\u0635\u064A',
  32510. '\uFD07': '\u0636\u0649',
  32511. '\uFD08': '\u0636\u064A',
  32512. '\uFD09': '\u0634\u062C',
  32513. '\uFD0A': '\u0634\u062D',
  32514. '\uFD0B': '\u0634\u062E',
  32515. '\uFD0C': '\u0634\u0645',
  32516. '\uFD0D': '\u0634\u0631',
  32517. '\uFD0E': '\u0633\u0631',
  32518. '\uFD0F': '\u0635\u0631',
  32519. '\uFD10': '\u0636\u0631',
  32520. '\uFD11': '\u0637\u0649',
  32521. '\uFD12': '\u0637\u064A',
  32522. '\uFD13': '\u0639\u0649',
  32523. '\uFD14': '\u0639\u064A',
  32524. '\uFD15': '\u063A\u0649',
  32525. '\uFD16': '\u063A\u064A',
  32526. '\uFD17': '\u0633\u0649',
  32527. '\uFD18': '\u0633\u064A',
  32528. '\uFD19': '\u0634\u0649',
  32529. '\uFD1A': '\u0634\u064A',
  32530. '\uFD1B': '\u062D\u0649',
  32531. '\uFD1C': '\u062D\u064A',
  32532. '\uFD1D': '\u062C\u0649',
  32533. '\uFD1E': '\u062C\u064A',
  32534. '\uFD1F': '\u062E\u0649',
  32535. '\uFD20': '\u062E\u064A',
  32536. '\uFD21': '\u0635\u0649',
  32537. '\uFD22': '\u0635\u064A',
  32538. '\uFD23': '\u0636\u0649',
  32539. '\uFD24': '\u0636\u064A',
  32540. '\uFD25': '\u0634\u062C',
  32541. '\uFD26': '\u0634\u062D',
  32542. '\uFD27': '\u0634\u062E',
  32543. '\uFD28': '\u0634\u0645',
  32544. '\uFD29': '\u0634\u0631',
  32545. '\uFD2A': '\u0633\u0631',
  32546. '\uFD2B': '\u0635\u0631',
  32547. '\uFD2C': '\u0636\u0631',
  32548. '\uFD2D': '\u0634\u062C',
  32549. '\uFD2E': '\u0634\u062D',
  32550. '\uFD2F': '\u0634\u062E',
  32551. '\uFD30': '\u0634\u0645',
  32552. '\uFD31': '\u0633\u0647',
  32553. '\uFD32': '\u0634\u0647',
  32554. '\uFD33': '\u0637\u0645',
  32555. '\uFD34': '\u0633\u062C',
  32556. '\uFD35': '\u0633\u062D',
  32557. '\uFD36': '\u0633\u062E',
  32558. '\uFD37': '\u0634\u062C',
  32559. '\uFD38': '\u0634\u062D',
  32560. '\uFD39': '\u0634\u062E',
  32561. '\uFD3A': '\u0637\u0645',
  32562. '\uFD3B': '\u0638\u0645',
  32563. '\uFD3C': '\u0627\u064B',
  32564. '\uFD3D': '\u0627\u064B',
  32565. '\uFD50': '\u062A\u062C\u0645',
  32566. '\uFD51': '\u062A\u062D\u062C',
  32567. '\uFD52': '\u062A\u062D\u062C',
  32568. '\uFD53': '\u062A\u062D\u0645',
  32569. '\uFD54': '\u062A\u062E\u0645',
  32570. '\uFD55': '\u062A\u0645\u062C',
  32571. '\uFD56': '\u062A\u0645\u062D',
  32572. '\uFD57': '\u062A\u0645\u062E',
  32573. '\uFD58': '\u062C\u0645\u062D',
  32574. '\uFD59': '\u062C\u0645\u062D',
  32575. '\uFD5A': '\u062D\u0645\u064A',
  32576. '\uFD5B': '\u062D\u0645\u0649',
  32577. '\uFD5C': '\u0633\u062D\u062C',
  32578. '\uFD5D': '\u0633\u062C\u062D',
  32579. '\uFD5E': '\u0633\u062C\u0649',
  32580. '\uFD5F': '\u0633\u0645\u062D',
  32581. '\uFD60': '\u0633\u0645\u062D',
  32582. '\uFD61': '\u0633\u0645\u062C',
  32583. '\uFD62': '\u0633\u0645\u0645',
  32584. '\uFD63': '\u0633\u0645\u0645',
  32585. '\uFD64': '\u0635\u062D\u062D',
  32586. '\uFD65': '\u0635\u062D\u062D',
  32587. '\uFD66': '\u0635\u0645\u0645',
  32588. '\uFD67': '\u0634\u062D\u0645',
  32589. '\uFD68': '\u0634\u062D\u0645',
  32590. '\uFD69': '\u0634\u062C\u064A',
  32591. '\uFD6A': '\u0634\u0645\u062E',
  32592. '\uFD6B': '\u0634\u0645\u062E',
  32593. '\uFD6C': '\u0634\u0645\u0645',
  32594. '\uFD6D': '\u0634\u0645\u0645',
  32595. '\uFD6E': '\u0636\u062D\u0649',
  32596. '\uFD6F': '\u0636\u062E\u0645',
  32597. '\uFD70': '\u0636\u062E\u0645',
  32598. '\uFD71': '\u0637\u0645\u062D',
  32599. '\uFD72': '\u0637\u0645\u062D',
  32600. '\uFD73': '\u0637\u0645\u0645',
  32601. '\uFD74': '\u0637\u0645\u064A',
  32602. '\uFD75': '\u0639\u062C\u0645',
  32603. '\uFD76': '\u0639\u0645\u0645',
  32604. '\uFD77': '\u0639\u0645\u0645',
  32605. '\uFD78': '\u0639\u0645\u0649',
  32606. '\uFD79': '\u063A\u0645\u0645',
  32607. '\uFD7A': '\u063A\u0645\u064A',
  32608. '\uFD7B': '\u063A\u0645\u0649',
  32609. '\uFD7C': '\u0641\u062E\u0645',
  32610. '\uFD7D': '\u0641\u062E\u0645',
  32611. '\uFD7E': '\u0642\u0645\u062D',
  32612. '\uFD7F': '\u0642\u0645\u0645',
  32613. '\uFD80': '\u0644\u062D\u0645',
  32614. '\uFD81': '\u0644\u062D\u064A',
  32615. '\uFD82': '\u0644\u062D\u0649',
  32616. '\uFD83': '\u0644\u062C\u062C',
  32617. '\uFD84': '\u0644\u062C\u062C',
  32618. '\uFD85': '\u0644\u062E\u0645',
  32619. '\uFD86': '\u0644\u062E\u0645',
  32620. '\uFD87': '\u0644\u0645\u062D',
  32621. '\uFD88': '\u0644\u0645\u062D',
  32622. '\uFD89': '\u0645\u062D\u062C',
  32623. '\uFD8A': '\u0645\u062D\u0645',
  32624. '\uFD8B': '\u0645\u062D\u064A',
  32625. '\uFD8C': '\u0645\u062C\u062D',
  32626. '\uFD8D': '\u0645\u062C\u0645',
  32627. '\uFD8E': '\u0645\u062E\u062C',
  32628. '\uFD8F': '\u0645\u062E\u0645',
  32629. '\uFD92': '\u0645\u062C\u062E',
  32630. '\uFD93': '\u0647\u0645\u062C',
  32631. '\uFD94': '\u0647\u0645\u0645',
  32632. '\uFD95': '\u0646\u062D\u0645',
  32633. '\uFD96': '\u0646\u062D\u0649',
  32634. '\uFD97': '\u0646\u062C\u0645',
  32635. '\uFD98': '\u0646\u062C\u0645',
  32636. '\uFD99': '\u0646\u062C\u0649',
  32637. '\uFD9A': '\u0646\u0645\u064A',
  32638. '\uFD9B': '\u0646\u0645\u0649',
  32639. '\uFD9C': '\u064A\u0645\u0645',
  32640. '\uFD9D': '\u064A\u0645\u0645',
  32641. '\uFD9E': '\u0628\u062E\u064A',
  32642. '\uFD9F': '\u062A\u062C\u064A',
  32643. '\uFDA0': '\u062A\u062C\u0649',
  32644. '\uFDA1': '\u062A\u062E\u064A',
  32645. '\uFDA2': '\u062A\u062E\u0649',
  32646. '\uFDA3': '\u062A\u0645\u064A',
  32647. '\uFDA4': '\u062A\u0645\u0649',
  32648. '\uFDA5': '\u062C\u0645\u064A',
  32649. '\uFDA6': '\u062C\u062D\u0649',
  32650. '\uFDA7': '\u062C\u0645\u0649',
  32651. '\uFDA8': '\u0633\u062E\u0649',
  32652. '\uFDA9': '\u0635\u062D\u064A',
  32653. '\uFDAA': '\u0634\u062D\u064A',
  32654. '\uFDAB': '\u0636\u062D\u064A',
  32655. '\uFDAC': '\u0644\u062C\u064A',
  32656. '\uFDAD': '\u0644\u0645\u064A',
  32657. '\uFDAE': '\u064A\u062D\u064A',
  32658. '\uFDAF': '\u064A\u062C\u064A',
  32659. '\uFDB0': '\u064A\u0645\u064A',
  32660. '\uFDB1': '\u0645\u0645\u064A',
  32661. '\uFDB2': '\u0642\u0645\u064A',
  32662. '\uFDB3': '\u0646\u062D\u064A',
  32663. '\uFDB4': '\u0642\u0645\u062D',
  32664. '\uFDB5': '\u0644\u062D\u0645',
  32665. '\uFDB6': '\u0639\u0645\u064A',
  32666. '\uFDB7': '\u0643\u0645\u064A',
  32667. '\uFDB8': '\u0646\u062C\u062D',
  32668. '\uFDB9': '\u0645\u062E\u064A',
  32669. '\uFDBA': '\u0644\u062C\u0645',
  32670. '\uFDBB': '\u0643\u0645\u0645',
  32671. '\uFDBC': '\u0644\u062C\u0645',
  32672. '\uFDBD': '\u0646\u062C\u062D',
  32673. '\uFDBE': '\u062C\u062D\u064A',
  32674. '\uFDBF': '\u062D\u062C\u064A',
  32675. '\uFDC0': '\u0645\u062C\u064A',
  32676. '\uFDC1': '\u0641\u0645\u064A',
  32677. '\uFDC2': '\u0628\u062D\u064A',
  32678. '\uFDC3': '\u0643\u0645\u0645',
  32679. '\uFDC4': '\u0639\u062C\u0645',
  32680. '\uFDC5': '\u0635\u0645\u0645',
  32681. '\uFDC6': '\u0633\u062E\u064A',
  32682. '\uFDC7': '\u0646\u062C\u064A',
  32683. '\uFE49': '\u203E',
  32684. '\uFE4A': '\u203E',
  32685. '\uFE4B': '\u203E',
  32686. '\uFE4C': '\u203E',
  32687. '\uFE4D': '\u005F',
  32688. '\uFE4E': '\u005F',
  32689. '\uFE4F': '\u005F',
  32690. '\uFE80': '\u0621',
  32691. '\uFE81': '\u0622',
  32692. '\uFE82': '\u0622',
  32693. '\uFE83': '\u0623',
  32694. '\uFE84': '\u0623',
  32695. '\uFE85': '\u0624',
  32696. '\uFE86': '\u0624',
  32697. '\uFE87': '\u0625',
  32698. '\uFE88': '\u0625',
  32699. '\uFE89': '\u0626',
  32700. '\uFE8A': '\u0626',
  32701. '\uFE8B': '\u0626',
  32702. '\uFE8C': '\u0626',
  32703. '\uFE8D': '\u0627',
  32704. '\uFE8E': '\u0627',
  32705. '\uFE8F': '\u0628',
  32706. '\uFE90': '\u0628',
  32707. '\uFE91': '\u0628',
  32708. '\uFE92': '\u0628',
  32709. '\uFE93': '\u0629',
  32710. '\uFE94': '\u0629',
  32711. '\uFE95': '\u062A',
  32712. '\uFE96': '\u062A',
  32713. '\uFE97': '\u062A',
  32714. '\uFE98': '\u062A',
  32715. '\uFE99': '\u062B',
  32716. '\uFE9A': '\u062B',
  32717. '\uFE9B': '\u062B',
  32718. '\uFE9C': '\u062B',
  32719. '\uFE9D': '\u062C',
  32720. '\uFE9E': '\u062C',
  32721. '\uFE9F': '\u062C',
  32722. '\uFEA0': '\u062C',
  32723. '\uFEA1': '\u062D',
  32724. '\uFEA2': '\u062D',
  32725. '\uFEA3': '\u062D',
  32726. '\uFEA4': '\u062D',
  32727. '\uFEA5': '\u062E',
  32728. '\uFEA6': '\u062E',
  32729. '\uFEA7': '\u062E',
  32730. '\uFEA8': '\u062E',
  32731. '\uFEA9': '\u062F',
  32732. '\uFEAA': '\u062F',
  32733. '\uFEAB': '\u0630',
  32734. '\uFEAC': '\u0630',
  32735. '\uFEAD': '\u0631',
  32736. '\uFEAE': '\u0631',
  32737. '\uFEAF': '\u0632',
  32738. '\uFEB0': '\u0632',
  32739. '\uFEB1': '\u0633',
  32740. '\uFEB2': '\u0633',
  32741. '\uFEB3': '\u0633',
  32742. '\uFEB4': '\u0633',
  32743. '\uFEB5': '\u0634',
  32744. '\uFEB6': '\u0634',
  32745. '\uFEB7': '\u0634',
  32746. '\uFEB8': '\u0634',
  32747. '\uFEB9': '\u0635',
  32748. '\uFEBA': '\u0635',
  32749. '\uFEBB': '\u0635',
  32750. '\uFEBC': '\u0635',
  32751. '\uFEBD': '\u0636',
  32752. '\uFEBE': '\u0636',
  32753. '\uFEBF': '\u0636',
  32754. '\uFEC0': '\u0636',
  32755. '\uFEC1': '\u0637',
  32756. '\uFEC2': '\u0637',
  32757. '\uFEC3': '\u0637',
  32758. '\uFEC4': '\u0637',
  32759. '\uFEC5': '\u0638',
  32760. '\uFEC6': '\u0638',
  32761. '\uFEC7': '\u0638',
  32762. '\uFEC8': '\u0638',
  32763. '\uFEC9': '\u0639',
  32764. '\uFECA': '\u0639',
  32765. '\uFECB': '\u0639',
  32766. '\uFECC': '\u0639',
  32767. '\uFECD': '\u063A',
  32768. '\uFECE': '\u063A',
  32769. '\uFECF': '\u063A',
  32770. '\uFED0': '\u063A',
  32771. '\uFED1': '\u0641',
  32772. '\uFED2': '\u0641',
  32773. '\uFED3': '\u0641',
  32774. '\uFED4': '\u0641',
  32775. '\uFED5': '\u0642',
  32776. '\uFED6': '\u0642',
  32777. '\uFED7': '\u0642',
  32778. '\uFED8': '\u0642',
  32779. '\uFED9': '\u0643',
  32780. '\uFEDA': '\u0643',
  32781. '\uFEDB': '\u0643',
  32782. '\uFEDC': '\u0643',
  32783. '\uFEDD': '\u0644',
  32784. '\uFEDE': '\u0644',
  32785. '\uFEDF': '\u0644',
  32786. '\uFEE0': '\u0644',
  32787. '\uFEE1': '\u0645',
  32788. '\uFEE2': '\u0645',
  32789. '\uFEE3': '\u0645',
  32790. '\uFEE4': '\u0645',
  32791. '\uFEE5': '\u0646',
  32792. '\uFEE6': '\u0646',
  32793. '\uFEE7': '\u0646',
  32794. '\uFEE8': '\u0646',
  32795. '\uFEE9': '\u0647',
  32796. '\uFEEA': '\u0647',
  32797. '\uFEEB': '\u0647',
  32798. '\uFEEC': '\u0647',
  32799. '\uFEED': '\u0648',
  32800. '\uFEEE': '\u0648',
  32801. '\uFEEF': '\u0649',
  32802. '\uFEF0': '\u0649',
  32803. '\uFEF1': '\u064A',
  32804. '\uFEF2': '\u064A',
  32805. '\uFEF3': '\u064A',
  32806. '\uFEF4': '\u064A',
  32807. '\uFEF5': '\u0644\u0622',
  32808. '\uFEF6': '\u0644\u0622',
  32809. '\uFEF7': '\u0644\u0623',
  32810. '\uFEF8': '\u0644\u0623',
  32811. '\uFEF9': '\u0644\u0625',
  32812. '\uFEFA': '\u0644\u0625',
  32813. '\uFEFB': '\u0644\u0627',
  32814. '\uFEFC': '\u0644\u0627'
  32815. };
  32816. function reverseIfRtl(chars) {
  32817. var charsLength = chars.length;
  32818. //reverse an arabic ligature
  32819. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  32820. return chars;
  32821. }
  32822. var s = '';
  32823. for (var ii = charsLength - 1; ii >= 0; ii--) {
  32824. s += chars[ii];
  32825. }
  32826. return s;
  32827. }
  32828. function adjustWidths(properties) {
  32829. if (!properties.fontMatrix) {
  32830. return;
  32831. }
  32832. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  32833. return;
  32834. }
  32835. // adjusting width to fontMatrix scale
  32836. var scale = 0.001 / properties.fontMatrix[0];
  32837. var glyphsWidths = properties.widths;
  32838. for (var glyph in glyphsWidths) {
  32839. glyphsWidths[glyph] *= scale;
  32840. }
  32841. properties.defaultWidth *= scale;
  32842. }
  32843. function getFontType(type, subtype) {
  32844. switch (type) {
  32845. case 'Type1':
  32846. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  32847. case 'CIDFontType0':
  32848. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  32849. FontType.CIDFONTTYPE0;
  32850. case 'OpenType':
  32851. return FontType.OPENTYPE;
  32852. case 'TrueType':
  32853. return FontType.TRUETYPE;
  32854. case 'CIDFontType2':
  32855. return FontType.CIDFONTTYPE2;
  32856. case 'MMType1':
  32857. return FontType.MMTYPE1;
  32858. case 'Type0':
  32859. return FontType.TYPE0;
  32860. default:
  32861. return FontType.UNKNOWN;
  32862. }
  32863. }
  32864. var Glyph = (function GlyphClosure() {
  32865. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  32866. isSpace) {
  32867. this.fontChar = fontChar;
  32868. this.unicode = unicode;
  32869. this.accent = accent;
  32870. this.width = width;
  32871. this.vmetric = vmetric;
  32872. this.operatorListId = operatorListId;
  32873. this.isSpace = isSpace;
  32874. }
  32875. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  32876. vmetric, operatorListId, isSpace) {
  32877. return this.fontChar === fontChar &&
  32878. this.unicode === unicode &&
  32879. this.accent === accent &&
  32880. this.width === width &&
  32881. this.vmetric === vmetric &&
  32882. this.operatorListId === operatorListId &&
  32883. this.isSpace === isSpace;
  32884. };
  32885. return Glyph;
  32886. })();
  32887. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  32888. function ToUnicodeMap(cmap) {
  32889. // The elements of this._map can be integers or strings, depending on how
  32890. // |cmap| was created.
  32891. this._map = cmap;
  32892. }
  32893. ToUnicodeMap.prototype = {
  32894. get length() {
  32895. return this._map.length;
  32896. },
  32897. forEach: function(callback) {
  32898. for (var charCode in this._map) {
  32899. callback(charCode, this._map[charCode].charCodeAt(0));
  32900. }
  32901. },
  32902. has: function(i) {
  32903. return this._map[i] !== undefined;
  32904. },
  32905. get: function(i) {
  32906. return this._map[i];
  32907. },
  32908. charCodeOf: function(v) {
  32909. return this._map.indexOf(v);
  32910. }
  32911. };
  32912. return ToUnicodeMap;
  32913. })();
  32914. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  32915. function IdentityToUnicodeMap(firstChar, lastChar) {
  32916. this.firstChar = firstChar;
  32917. this.lastChar = lastChar;
  32918. }
  32919. IdentityToUnicodeMap.prototype = {
  32920. get length() {
  32921. return (this.lastChar + 1) - this.firstChar;
  32922. },
  32923. forEach: function (callback) {
  32924. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  32925. callback(i, i);
  32926. }
  32927. },
  32928. has: function (i) {
  32929. return this.firstChar <= i && i <= this.lastChar;
  32930. },
  32931. get: function (i) {
  32932. if (this.firstChar <= i && i <= this.lastChar) {
  32933. return String.fromCharCode(i);
  32934. }
  32935. return undefined;
  32936. },
  32937. charCodeOf: function (v) {
  32938. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  32939. }
  32940. };
  32941. return IdentityToUnicodeMap;
  32942. })();
  32943. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  32944. function writeInt16(dest, offset, num) {
  32945. dest[offset] = (num >> 8) & 0xFF;
  32946. dest[offset + 1] = num & 0xFF;
  32947. }
  32948. function writeInt32(dest, offset, num) {
  32949. dest[offset] = (num >> 24) & 0xFF;
  32950. dest[offset + 1] = (num >> 16) & 0xFF;
  32951. dest[offset + 2] = (num >> 8) & 0xFF;
  32952. dest[offset + 3] = num & 0xFF;
  32953. }
  32954. function writeData(dest, offset, data) {
  32955. var i, ii;
  32956. if (data instanceof Uint8Array) {
  32957. dest.set(data, offset);
  32958. } else if (typeof data === 'string') {
  32959. for (i = 0, ii = data.length; i < ii; i++) {
  32960. dest[offset++] = data.charCodeAt(i) & 0xFF;
  32961. }
  32962. } else {
  32963. // treating everything else as array
  32964. for (i = 0, ii = data.length; i < ii; i++) {
  32965. dest[offset++] = data[i] & 0xFF;
  32966. }
  32967. }
  32968. }
  32969. function OpenTypeFileBuilder(sfnt) {
  32970. this.sfnt = sfnt;
  32971. this.tables = Object.create(null);
  32972. }
  32973. OpenTypeFileBuilder.getSearchParams =
  32974. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  32975. var maxPower2 = 1, log2 = 0;
  32976. while ((maxPower2 ^ entriesCount) > maxPower2) {
  32977. maxPower2 <<= 1;
  32978. log2++;
  32979. }
  32980. var searchRange = maxPower2 * entrySize;
  32981. return {
  32982. range: searchRange,
  32983. entry: log2,
  32984. rangeShift: entrySize * entriesCount - searchRange
  32985. };
  32986. };
  32987. var OTF_HEADER_SIZE = 12;
  32988. var OTF_TABLE_ENTRY_SIZE = 16;
  32989. OpenTypeFileBuilder.prototype = {
  32990. toArray: function OpenTypeFileBuilder_toArray() {
  32991. var sfnt = this.sfnt;
  32992. // Tables needs to be written by ascendant alphabetic order
  32993. var tables = this.tables;
  32994. var tablesNames = Object.keys(tables);
  32995. tablesNames.sort();
  32996. var numTables = tablesNames.length;
  32997. var i, j, jj, table, tableName;
  32998. // layout the tables data
  32999. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  33000. var tableOffsets = [offset];
  33001. for (i = 0; i < numTables; i++) {
  33002. table = tables[tablesNames[i]];
  33003. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  33004. offset += paddedLength;
  33005. tableOffsets.push(offset);
  33006. }
  33007. var file = new Uint8Array(offset);
  33008. // write the table data first (mostly for checksum)
  33009. for (i = 0; i < numTables; i++) {
  33010. table = tables[tablesNames[i]];
  33011. writeData(file, tableOffsets[i], table);
  33012. }
  33013. // sfnt version (4 bytes)
  33014. if (sfnt === 'true') {
  33015. // Windows hates the Mac TrueType sfnt version number
  33016. sfnt = string32(0x00010000);
  33017. }
  33018. file[0] = sfnt.charCodeAt(0) & 0xFF;
  33019. file[1] = sfnt.charCodeAt(1) & 0xFF;
  33020. file[2] = sfnt.charCodeAt(2) & 0xFF;
  33021. file[3] = sfnt.charCodeAt(3) & 0xFF;
  33022. // numTables (2 bytes)
  33023. writeInt16(file, 4, numTables);
  33024. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  33025. // searchRange (2 bytes)
  33026. writeInt16(file, 6, searchParams.range);
  33027. // entrySelector (2 bytes)
  33028. writeInt16(file, 8, searchParams.entry);
  33029. // rangeShift (2 bytes)
  33030. writeInt16(file, 10, searchParams.rangeShift);
  33031. offset = OTF_HEADER_SIZE;
  33032. // writing table entries
  33033. for (i = 0; i < numTables; i++) {
  33034. tableName = tablesNames[i];
  33035. file[offset] = tableName.charCodeAt(0) & 0xFF;
  33036. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  33037. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  33038. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  33039. // checksum
  33040. var checksum = 0;
  33041. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  33042. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  33043. (file[j + 2] << 8) + file[j + 3];
  33044. checksum = (checksum + quad) | 0;
  33045. }
  33046. writeInt32(file, offset + 4, checksum);
  33047. // offset
  33048. writeInt32(file, offset + 8, tableOffsets[i]);
  33049. // length
  33050. writeInt32(file, offset + 12, tables[tableName].length);
  33051. offset += OTF_TABLE_ENTRY_SIZE;
  33052. }
  33053. return file;
  33054. },
  33055. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  33056. if (tag in this.tables) {
  33057. throw new Error('Table ' + tag + ' already exists');
  33058. }
  33059. this.tables[tag] = data;
  33060. }
  33061. };
  33062. return OpenTypeFileBuilder;
  33063. })();
  33064. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  33065. // issues when they are painted on the canvas, e.g. complex-script shaping or
  33066. // control/whitespace characters. The ranges are listed in pairs: the first item
  33067. // is a code of the first problematic code, the second one is the next
  33068. // non-problematic code. The ranges must be in sorted order.
  33069. var ProblematicCharRanges = new Int32Array([
  33070. // Control characters.
  33071. 0x0000, 0x0020,
  33072. 0x007F, 0x00A1,
  33073. 0x00AD, 0x00AE,
  33074. // Chars that is used in complex-script shaping.
  33075. 0x0600, 0x0780,
  33076. 0x08A0, 0x10A0,
  33077. 0x1780, 0x1800,
  33078. // General punctuation chars.
  33079. 0x2000, 0x2010,
  33080. 0x2011, 0x2012,
  33081. 0x2028, 0x2030,
  33082. 0x205F, 0x2070,
  33083. 0x25CC, 0x25CD,
  33084. // Chars that is used in complex-script shaping.
  33085. 0xAA60, 0xAA80,
  33086. // Specials Unicode block.
  33087. 0xFFF0, 0x10000
  33088. ]);
  33089. /**
  33090. * 'Font' is the class the outside world should use, it encapsulate all the font
  33091. * decoding logics whatever type it is (assuming the font type is supported).
  33092. *
  33093. * For example to read a Type1 font and to attach it to the document:
  33094. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  33095. * type1Font.bind();
  33096. */
  33097. var Font = (function FontClosure() {
  33098. function Font(name, file, properties) {
  33099. var charCode, glyphName, fontChar;
  33100. this.name = name;
  33101. this.loadedName = properties.loadedName;
  33102. this.isType3Font = properties.isType3Font;
  33103. this.sizes = [];
  33104. this.glyphCache = {};
  33105. var names = name.split('+');
  33106. names = names.length > 1 ? names[1] : names[0];
  33107. names = names.split(/[-,_]/g)[0];
  33108. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  33109. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  33110. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  33111. var type = properties.type;
  33112. var subtype = properties.subtype;
  33113. this.type = type;
  33114. this.fallbackName = (this.isMonospace ? 'monospace' :
  33115. (this.isSerifFont ? 'serif' : 'sans-serif'));
  33116. this.differences = properties.differences;
  33117. this.widths = properties.widths;
  33118. this.defaultWidth = properties.defaultWidth;
  33119. this.composite = properties.composite;
  33120. this.wideChars = properties.wideChars;
  33121. this.cMap = properties.cMap;
  33122. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  33123. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  33124. this.fontMatrix = properties.fontMatrix;
  33125. this.bbox = properties.bbox;
  33126. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  33127. this.toFontChar = [];
  33128. if (properties.type === 'Type3') {
  33129. for (charCode = 0; charCode < 256; charCode++) {
  33130. this.toFontChar[charCode] = (this.differences[charCode] ||
  33131. properties.defaultEncoding[charCode]);
  33132. }
  33133. this.fontType = FontType.TYPE3;
  33134. return;
  33135. }
  33136. this.cidEncoding = properties.cidEncoding;
  33137. this.vertical = properties.vertical;
  33138. if (this.vertical) {
  33139. this.vmetrics = properties.vmetrics;
  33140. this.defaultVMetrics = properties.defaultVMetrics;
  33141. }
  33142. if (!file || file.isEmpty) {
  33143. if (file) {
  33144. // Some bad PDF generators will include empty font files,
  33145. // attempting to recover by assuming that no file exists.
  33146. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  33147. }
  33148. this.missingFile = true;
  33149. // The file data is not specified. Trying to fix the font name
  33150. // to be used with the canvas.font.
  33151. var fontName = name.replace(/[,_]/g, '-');
  33152. var isStandardFont = !!stdFontMap[fontName] ||
  33153. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  33154. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  33155. this.bold = (fontName.search(/bold/gi) !== -1);
  33156. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  33157. (fontName.search(/italic/gi) !== -1));
  33158. // Use 'name' instead of 'fontName' here because the original
  33159. // name ArialBlack for example will be replaced by Helvetica.
  33160. this.black = (name.search(/Black/g) !== -1);
  33161. // if at least one width is present, remeasure all chars when exists
  33162. this.remeasure = Object.keys(this.widths).length > 0;
  33163. if (isStandardFont && type === 'CIDFontType2' &&
  33164. properties.cidEncoding.indexOf('Identity-') === 0) {
  33165. // Standard fonts might be embedded as CID font without glyph mapping.
  33166. // Building one based on GlyphMapForStandardFonts.
  33167. var map = [];
  33168. for (charCode in GlyphMapForStandardFonts) {
  33169. map[+charCode] = GlyphMapForStandardFonts[charCode];
  33170. }
  33171. if (/ArialBlack/i.test(name)) {
  33172. for (charCode in SupplementalGlyphMapForArialBlack) {
  33173. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  33174. }
  33175. }
  33176. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  33177. if (!isIdentityUnicode) {
  33178. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  33179. map[+charCode] = unicodeCharCode;
  33180. });
  33181. }
  33182. this.toFontChar = map;
  33183. this.toUnicode = new ToUnicodeMap(map);
  33184. } else if (/Symbol/i.test(fontName)) {
  33185. var symbols = Encodings.SymbolSetEncoding;
  33186. for (charCode in symbols) {
  33187. fontChar = GlyphsUnicode[symbols[charCode]];
  33188. if (!fontChar) {
  33189. continue;
  33190. }
  33191. this.toFontChar[charCode] = fontChar;
  33192. }
  33193. for (charCode in properties.differences) {
  33194. fontChar = GlyphsUnicode[properties.differences[charCode]];
  33195. if (!fontChar) {
  33196. continue;
  33197. }
  33198. this.toFontChar[charCode] = fontChar;
  33199. }
  33200. } else if (/Dingbats/i.test(fontName)) {
  33201. if (/Wingdings/i.test(name)) {
  33202. warn('Wingdings font without embedded font file, ' +
  33203. 'falling back to the ZapfDingbats encoding.');
  33204. }
  33205. var dingbats = Encodings.ZapfDingbatsEncoding;
  33206. for (charCode in dingbats) {
  33207. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  33208. if (!fontChar) {
  33209. continue;
  33210. }
  33211. this.toFontChar[charCode] = fontChar;
  33212. }
  33213. for (charCode in properties.differences) {
  33214. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  33215. if (!fontChar) {
  33216. continue;
  33217. }
  33218. this.toFontChar[charCode] = fontChar;
  33219. }
  33220. } else if (isStandardFont) {
  33221. this.toFontChar = [];
  33222. for (charCode in properties.defaultEncoding) {
  33223. glyphName = (properties.differences[charCode] ||
  33224. properties.defaultEncoding[charCode]);
  33225. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  33226. }
  33227. } else {
  33228. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  33229. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  33230. if (notCidFont) {
  33231. glyphName = (properties.differences[charCode] ||
  33232. properties.defaultEncoding[charCode]);
  33233. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  33234. }
  33235. this.toFontChar[charCode] = unicodeCharCode;
  33236. }.bind(this));
  33237. }
  33238. this.loadedName = fontName.split('-')[0];
  33239. this.loading = false;
  33240. this.fontType = getFontType(type, subtype);
  33241. return;
  33242. }
  33243. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  33244. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  33245. // Some TrueType fonts by mistake claim Type1C
  33246. if (isTrueTypeFile(file)) {
  33247. subtype = 'TrueType';
  33248. } else {
  33249. type = 'Type1';
  33250. }
  33251. }
  33252. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  33253. type = 'CIDFontType0';
  33254. }
  33255. if (subtype === 'OpenType') {
  33256. type = 'OpenType';
  33257. }
  33258. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  33259. if (type === 'CIDFontType0') {
  33260. if (isType1File(file)) {
  33261. subtype = 'CIDFontType0';
  33262. } else if (isOpenTypeFile(file)) {
  33263. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  33264. type = subtype = 'OpenType';
  33265. } else {
  33266. subtype = 'CIDFontType0C';
  33267. }
  33268. }
  33269. var data;
  33270. switch (type) {
  33271. case 'MMType1':
  33272. info('MMType1 font (' + name + '), falling back to Type1.');
  33273. /* falls through */
  33274. case 'Type1':
  33275. case 'CIDFontType0':
  33276. this.mimetype = 'font/opentype';
  33277. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  33278. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  33279. adjustWidths(properties);
  33280. // Wrap the CFF data inside an OTF font file
  33281. data = this.convert(name, cff, properties);
  33282. break;
  33283. case 'OpenType':
  33284. case 'TrueType':
  33285. case 'CIDFontType2':
  33286. this.mimetype = 'font/opentype';
  33287. // Repair the TrueType file. It is can be damaged in the point of
  33288. // view of the sanitizer
  33289. data = this.checkAndRepair(name, file, properties);
  33290. if (this.isOpenType) {
  33291. adjustWidths(properties);
  33292. type = 'OpenType';
  33293. }
  33294. break;
  33295. default:
  33296. error('Font ' + type + ' is not supported');
  33297. break;
  33298. }
  33299. this.data = data;
  33300. this.fontType = getFontType(type, subtype);
  33301. // Transfer some properties again that could change during font conversion
  33302. this.fontMatrix = properties.fontMatrix;
  33303. this.widths = properties.widths;
  33304. this.defaultWidth = properties.defaultWidth;
  33305. this.encoding = properties.baseEncoding;
  33306. this.seacMap = properties.seacMap;
  33307. this.loading = true;
  33308. }
  33309. Font.getFontID = (function () {
  33310. var ID = 1;
  33311. return function Font_getFontID() {
  33312. return String(ID++);
  33313. };
  33314. })();
  33315. function int16(b0, b1) {
  33316. return (b0 << 8) + b1;
  33317. }
  33318. function int32(b0, b1, b2, b3) {
  33319. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  33320. }
  33321. function string16(value) {
  33322. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  33323. }
  33324. function safeString16(value) {
  33325. // clamp value to the 16-bit int range
  33326. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  33327. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  33328. }
  33329. function isTrueTypeFile(file) {
  33330. var header = file.peekBytes(4);
  33331. return readUint32(header, 0) === 0x00010000;
  33332. }
  33333. function isOpenTypeFile(file) {
  33334. var header = file.peekBytes(4);
  33335. return bytesToString(header) === 'OTTO';
  33336. }
  33337. function isType1File(file) {
  33338. var header = file.peekBytes(2);
  33339. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  33340. if (header[0] === 0x25 && header[1] === 0x21) {
  33341. return true;
  33342. }
  33343. // ... obviously some fonts violate that part of the specification,
  33344. // please refer to the comment in |Type1Font| below.
  33345. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  33346. return true;
  33347. }
  33348. return false;
  33349. }
  33350. /**
  33351. * Helper function for |adjustMapping|.
  33352. * @return {boolean}
  33353. */
  33354. function isProblematicUnicodeLocation(code) {
  33355. // Using binary search to find a range start.
  33356. var i = 0, j = ProblematicCharRanges.length - 1;
  33357. while (i < j) {
  33358. var c = (i + j + 1) >> 1;
  33359. if (code < ProblematicCharRanges[c]) {
  33360. j = c - 1;
  33361. } else {
  33362. i = c;
  33363. }
  33364. }
  33365. // Even index means code in problematic range.
  33366. return !(i & 1);
  33367. }
  33368. /**
  33369. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  33370. * with their unicode value. It also moves char codes that are in known
  33371. * problematic locations.
  33372. * @return {Object} Two properties:
  33373. * 'toFontChar' - maps original char codes(the value that will be read
  33374. * from commands such as show text) to the char codes that will be used in the
  33375. * font that we build
  33376. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  33377. */
  33378. function adjustMapping(charCodeToGlyphId, properties) {
  33379. var toUnicode = properties.toUnicode;
  33380. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  33381. var isIdentityUnicode =
  33382. properties.toUnicode instanceof IdentityToUnicodeMap;
  33383. var newMap = Object.create(null);
  33384. var toFontChar = [];
  33385. var usedFontCharCodes = [];
  33386. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  33387. for (var originalCharCode in charCodeToGlyphId) {
  33388. originalCharCode |= 0;
  33389. var glyphId = charCodeToGlyphId[originalCharCode];
  33390. var fontCharCode = originalCharCode;
  33391. // First try to map the value to a unicode position if a non identity map
  33392. // was created.
  33393. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  33394. var unicode = toUnicode.get(fontCharCode);
  33395. // TODO: Try to map ligatures to the correct spot.
  33396. if (unicode.length === 1) {
  33397. fontCharCode = unicode.charCodeAt(0);
  33398. }
  33399. }
  33400. // Try to move control characters, special characters and already mapped
  33401. // characters to the private use area since they will not be drawn by
  33402. // canvas if left in their current position. Also, move characters if the
  33403. // font was symbolic and there is only an identity unicode map since the
  33404. // characters probably aren't in the correct position (fixes an issue
  33405. // with firefox and thuluthfont).
  33406. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  33407. isProblematicUnicodeLocation(fontCharCode) ||
  33408. (isSymbolic && isIdentityUnicode)) &&
  33409. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  33410. // Loop to try and find a free spot in the private use area.
  33411. do {
  33412. fontCharCode = nextAvailableFontCharCode++;
  33413. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  33414. fontCharCode = 0xF020;
  33415. nextAvailableFontCharCode = fontCharCode + 1;
  33416. }
  33417. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  33418. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  33419. }
  33420. newMap[fontCharCode] = glyphId;
  33421. toFontChar[originalCharCode] = fontCharCode;
  33422. usedFontCharCodes[fontCharCode] = true;
  33423. }
  33424. return {
  33425. toFontChar: toFontChar,
  33426. charCodeToGlyphId: newMap,
  33427. nextAvailableFontCharCode: nextAvailableFontCharCode
  33428. };
  33429. }
  33430. function getRanges(glyphs, numGlyphs) {
  33431. // Array.sort() sorts by characters, not numerically, so convert to an
  33432. // array of characters.
  33433. var codes = [];
  33434. for (var charCode in glyphs) {
  33435. // Remove an invalid glyph ID mappings to make OTS happy.
  33436. if (glyphs[charCode] >= numGlyphs) {
  33437. continue;
  33438. }
  33439. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  33440. }
  33441. codes.sort(function fontGetRangesSort(a, b) {
  33442. return a.fontCharCode - b.fontCharCode;
  33443. });
  33444. // Split the sorted codes into ranges.
  33445. var ranges = [];
  33446. var length = codes.length;
  33447. for (var n = 0; n < length; ) {
  33448. var start = codes[n].fontCharCode;
  33449. var codeIndices = [codes[n].glyphId];
  33450. ++n;
  33451. var end = start;
  33452. while (n < length && end + 1 === codes[n].fontCharCode) {
  33453. codeIndices.push(codes[n].glyphId);
  33454. ++end;
  33455. ++n;
  33456. if (end === 0xFFFF) {
  33457. break;
  33458. }
  33459. }
  33460. ranges.push([start, end, codeIndices]);
  33461. }
  33462. return ranges;
  33463. }
  33464. function createCmapTable(glyphs, numGlyphs) {
  33465. var ranges = getRanges(glyphs, numGlyphs);
  33466. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  33467. var cmap = '\x00\x00' + // version
  33468. string16(numTables) + // numTables
  33469. '\x00\x03' + // platformID
  33470. '\x00\x01' + // encodingID
  33471. string32(4 + numTables * 8); // start of the table record
  33472. var i, ii, j, jj;
  33473. for (i = ranges.length - 1; i >= 0; --i) {
  33474. if (ranges[i][0] <= 0xFFFF) { break; }
  33475. }
  33476. var bmpLength = i + 1;
  33477. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  33478. ranges[i][1] = 0xFFFE;
  33479. }
  33480. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  33481. var segCount = bmpLength + trailingRangesCount;
  33482. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  33483. // Fill up the 4 parallel arrays describing the segments.
  33484. var startCount = '';
  33485. var endCount = '';
  33486. var idDeltas = '';
  33487. var idRangeOffsets = '';
  33488. var glyphsIds = '';
  33489. var bias = 0;
  33490. var range, start, end, codes;
  33491. for (i = 0, ii = bmpLength; i < ii; i++) {
  33492. range = ranges[i];
  33493. start = range[0];
  33494. end = range[1];
  33495. startCount += string16(start);
  33496. endCount += string16(end);
  33497. codes = range[2];
  33498. var contiguous = true;
  33499. for (j = 1, jj = codes.length; j < jj; ++j) {
  33500. if (codes[j] !== codes[j - 1] + 1) {
  33501. contiguous = false;
  33502. break;
  33503. }
  33504. }
  33505. if (!contiguous) {
  33506. var offset = (segCount - i) * 2 + bias * 2;
  33507. bias += (end - start + 1);
  33508. idDeltas += string16(0);
  33509. idRangeOffsets += string16(offset);
  33510. for (j = 0, jj = codes.length; j < jj; ++j) {
  33511. glyphsIds += string16(codes[j]);
  33512. }
  33513. } else {
  33514. var startCode = codes[0];
  33515. idDeltas += string16((startCode - start) & 0xFFFF);
  33516. idRangeOffsets += string16(0);
  33517. }
  33518. }
  33519. if (trailingRangesCount > 0) {
  33520. endCount += '\xFF\xFF';
  33521. startCount += '\xFF\xFF';
  33522. idDeltas += '\x00\x01';
  33523. idRangeOffsets += '\x00\x00';
  33524. }
  33525. var format314 = '\x00\x00' + // language
  33526. string16(2 * segCount) +
  33527. string16(searchParams.range) +
  33528. string16(searchParams.entry) +
  33529. string16(searchParams.rangeShift) +
  33530. endCount + '\x00\x00' + startCount +
  33531. idDeltas + idRangeOffsets + glyphsIds;
  33532. var format31012 = '';
  33533. var header31012 = '';
  33534. if (numTables > 1) {
  33535. cmap += '\x00\x03' + // platformID
  33536. '\x00\x0A' + // encodingID
  33537. string32(4 + numTables * 8 +
  33538. 4 + format314.length); // start of the table record
  33539. format31012 = '';
  33540. for (i = 0, ii = ranges.length; i < ii; i++) {
  33541. range = ranges[i];
  33542. start = range[0];
  33543. codes = range[2];
  33544. var code = codes[0];
  33545. for (j = 1, jj = codes.length; j < jj; ++j) {
  33546. if (codes[j] !== codes[j - 1] + 1) {
  33547. end = range[0] + j - 1;
  33548. format31012 += string32(start) + // startCharCode
  33549. string32(end) + // endCharCode
  33550. string32(code); // startGlyphID
  33551. start = end + 1;
  33552. code = codes[j];
  33553. }
  33554. }
  33555. format31012 += string32(start) + // startCharCode
  33556. string32(range[1]) + // endCharCode
  33557. string32(code); // startGlyphID
  33558. }
  33559. header31012 = '\x00\x0C' + // format
  33560. '\x00\x00' + // reserved
  33561. string32(format31012.length + 16) + // length
  33562. '\x00\x00\x00\x00' + // language
  33563. string32(format31012.length / 12); // nGroups
  33564. }
  33565. return cmap + '\x00\x04' + // format
  33566. string16(format314.length + 4) + // length
  33567. format314 + header31012 + format31012;
  33568. }
  33569. function validateOS2Table(os2) {
  33570. var stream = new Stream(os2.data);
  33571. var version = stream.getUint16();
  33572. // TODO verify all OS/2 tables fields, but currently we validate only those
  33573. // that give us issues
  33574. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  33575. var selection = stream.getUint16();
  33576. if (version < 4 && (selection & 0x0300)) {
  33577. return false;
  33578. }
  33579. var firstChar = stream.getUint16();
  33580. var lastChar = stream.getUint16();
  33581. if (firstChar > lastChar) {
  33582. return false;
  33583. }
  33584. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  33585. var usWinAscent = stream.getUint16();
  33586. if (usWinAscent === 0) { // makes font unreadable by windows
  33587. return false;
  33588. }
  33589. // OS/2 appears to be valid, resetting some fields
  33590. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  33591. return true;
  33592. }
  33593. function createOS2Table(properties, charstrings, override) {
  33594. override = override || {
  33595. unitsPerEm: 0,
  33596. yMax: 0,
  33597. yMin: 0,
  33598. ascent: 0,
  33599. descent: 0
  33600. };
  33601. var ulUnicodeRange1 = 0;
  33602. var ulUnicodeRange2 = 0;
  33603. var ulUnicodeRange3 = 0;
  33604. var ulUnicodeRange4 = 0;
  33605. var firstCharIndex = null;
  33606. var lastCharIndex = 0;
  33607. if (charstrings) {
  33608. for (var code in charstrings) {
  33609. code |= 0;
  33610. if (firstCharIndex > code || !firstCharIndex) {
  33611. firstCharIndex = code;
  33612. }
  33613. if (lastCharIndex < code) {
  33614. lastCharIndex = code;
  33615. }
  33616. var position = getUnicodeRangeFor(code);
  33617. if (position < 32) {
  33618. ulUnicodeRange1 |= 1 << position;
  33619. } else if (position < 64) {
  33620. ulUnicodeRange2 |= 1 << position - 32;
  33621. } else if (position < 96) {
  33622. ulUnicodeRange3 |= 1 << position - 64;
  33623. } else if (position < 123) {
  33624. ulUnicodeRange4 |= 1 << position - 96;
  33625. } else {
  33626. error('Unicode ranges Bits > 123 are reserved for internal usage');
  33627. }
  33628. }
  33629. } else {
  33630. // TODO
  33631. firstCharIndex = 0;
  33632. lastCharIndex = 255;
  33633. }
  33634. var bbox = properties.bbox || [0, 0, 0, 0];
  33635. var unitsPerEm = (override.unitsPerEm ||
  33636. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  33637. // if the font units differ to the PDF glyph space units
  33638. // then scale up the values
  33639. var scale = (properties.ascentScaled ? 1.0 :
  33640. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  33641. var typoAscent = (override.ascent ||
  33642. Math.round(scale * (properties.ascent || bbox[3])));
  33643. var typoDescent = (override.descent ||
  33644. Math.round(scale * (properties.descent || bbox[1])));
  33645. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  33646. typoDescent = -typoDescent; // fixing incorrect descent
  33647. }
  33648. var winAscent = override.yMax || typoAscent;
  33649. var winDescent = -override.yMin || -typoDescent;
  33650. return '\x00\x03' + // version
  33651. '\x02\x24' + // xAvgCharWidth
  33652. '\x01\xF4' + // usWeightClass
  33653. '\x00\x05' + // usWidthClass
  33654. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  33655. '\x02\x8A' + // ySubscriptXSize
  33656. '\x02\xBB' + // ySubscriptYSize
  33657. '\x00\x00' + // ySubscriptXOffset
  33658. '\x00\x8C' + // ySubscriptYOffset
  33659. '\x02\x8A' + // ySuperScriptXSize
  33660. '\x02\xBB' + // ySuperScriptYSize
  33661. '\x00\x00' + // ySuperScriptXOffset
  33662. '\x01\xDF' + // ySuperScriptYOffset
  33663. '\x00\x31' + // yStrikeOutSize
  33664. '\x01\x02' + // yStrikeOutPosition
  33665. '\x00\x00' + // sFamilyClass
  33666. '\x00\x00\x06' +
  33667. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  33668. '\x00\x00\x00\x00\x00\x00' + // Panose
  33669. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  33670. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  33671. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  33672. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  33673. '\x2A\x32\x31\x2A' + // achVendID
  33674. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  33675. string16(firstCharIndex ||
  33676. properties.firstChar) + // usFirstCharIndex
  33677. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  33678. string16(typoAscent) + // sTypoAscender
  33679. string16(typoDescent) + // sTypoDescender
  33680. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  33681. string16(winAscent) + // usWinAscent
  33682. string16(winDescent) + // usWinDescent
  33683. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  33684. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  33685. string16(properties.xHeight) + // sxHeight
  33686. string16(properties.capHeight) + // sCapHeight
  33687. string16(0) + // usDefaultChar
  33688. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  33689. '\x00\x03'; // usMaxContext
  33690. }
  33691. function createPostTable(properties) {
  33692. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  33693. return ('\x00\x03\x00\x00' + // Version number
  33694. string32(angle) + // italicAngle
  33695. '\x00\x00' + // underlinePosition
  33696. '\x00\x00' + // underlineThickness
  33697. string32(properties.fixedPitch) + // isFixedPitch
  33698. '\x00\x00\x00\x00' + // minMemType42
  33699. '\x00\x00\x00\x00' + // maxMemType42
  33700. '\x00\x00\x00\x00' + // minMemType1
  33701. '\x00\x00\x00\x00'); // maxMemType1
  33702. }
  33703. function createNameTable(name, proto) {
  33704. if (!proto) {
  33705. proto = [[], []]; // no strings and unicode strings
  33706. }
  33707. var strings = [
  33708. proto[0][0] || 'Original licence', // 0.Copyright
  33709. proto[0][1] || name, // 1.Font family
  33710. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  33711. proto[0][3] || 'uniqueID', // 3.Unique ID
  33712. proto[0][4] || name, // 4.Full font name
  33713. proto[0][5] || 'Version 0.11', // 5.Version
  33714. proto[0][6] || '', // 6.Postscript name
  33715. proto[0][7] || 'Unknown', // 7.Trademark
  33716. proto[0][8] || 'Unknown', // 8.Manufacturer
  33717. proto[0][9] || 'Unknown' // 9.Designer
  33718. ];
  33719. // Mac want 1-byte per character strings while Windows want
  33720. // 2-bytes per character, so duplicate the names table
  33721. var stringsUnicode = [];
  33722. var i, ii, j, jj, str;
  33723. for (i = 0, ii = strings.length; i < ii; i++) {
  33724. str = proto[1][i] || strings[i];
  33725. var strBufUnicode = [];
  33726. for (j = 0, jj = str.length; j < jj; j++) {
  33727. strBufUnicode.push(string16(str.charCodeAt(j)));
  33728. }
  33729. stringsUnicode.push(strBufUnicode.join(''));
  33730. }
  33731. var names = [strings, stringsUnicode];
  33732. var platforms = ['\x00\x01', '\x00\x03'];
  33733. var encodings = ['\x00\x00', '\x00\x01'];
  33734. var languages = ['\x00\x00', '\x04\x09'];
  33735. var namesRecordCount = strings.length * platforms.length;
  33736. var nameTable =
  33737. '\x00\x00' + // format
  33738. string16(namesRecordCount) + // Number of names Record
  33739. string16(namesRecordCount * 12 + 6); // Storage
  33740. // Build the name records field
  33741. var strOffset = 0;
  33742. for (i = 0, ii = platforms.length; i < ii; i++) {
  33743. var strs = names[i];
  33744. for (j = 0, jj = strs.length; j < jj; j++) {
  33745. str = strs[j];
  33746. var nameRecord =
  33747. platforms[i] + // platform ID
  33748. encodings[i] + // encoding ID
  33749. languages[i] + // language ID
  33750. string16(j) + // name ID
  33751. string16(str.length) +
  33752. string16(strOffset);
  33753. nameTable += nameRecord;
  33754. strOffset += str.length;
  33755. }
  33756. }
  33757. nameTable += strings.join('') + stringsUnicode.join('');
  33758. return nameTable;
  33759. }
  33760. Font.prototype = {
  33761. name: null,
  33762. font: null,
  33763. mimetype: null,
  33764. encoding: null,
  33765. get renderer() {
  33766. var renderer = FontRendererFactory.create(this);
  33767. return shadow(this, 'renderer', renderer);
  33768. },
  33769. exportData: function Font_exportData() {
  33770. var data = {};
  33771. for (var i in this) {
  33772. if (this.hasOwnProperty(i)) {
  33773. data[i] = this[i];
  33774. }
  33775. }
  33776. return data;
  33777. },
  33778. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  33779. function readTableEntry(file) {
  33780. var tag = bytesToString(file.getBytes(4));
  33781. var checksum = file.getInt32();
  33782. var offset = file.getInt32() >>> 0;
  33783. var length = file.getInt32() >>> 0;
  33784. // Read the table associated data
  33785. var previousPosition = file.pos;
  33786. file.pos = file.start ? file.start : 0;
  33787. file.skip(offset);
  33788. var data = file.getBytes(length);
  33789. file.pos = previousPosition;
  33790. if (tag === 'head') {
  33791. // clearing checksum adjustment
  33792. data[8] = data[9] = data[10] = data[11] = 0;
  33793. data[17] |= 0x20; //Set font optimized for cleartype flag
  33794. }
  33795. return {
  33796. tag: tag,
  33797. checksum: checksum,
  33798. length: length,
  33799. offset: offset,
  33800. data: data
  33801. };
  33802. }
  33803. function readOpenTypeHeader(ttf) {
  33804. return {
  33805. version: bytesToString(ttf.getBytes(4)),
  33806. numTables: ttf.getUint16(),
  33807. searchRange: ttf.getUint16(),
  33808. entrySelector: ttf.getUint16(),
  33809. rangeShift: ttf.getUint16()
  33810. };
  33811. }
  33812. /**
  33813. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  33814. * PDF spec
  33815. */
  33816. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  33817. if (!cmap) {
  33818. warn('No cmap table available.');
  33819. return {
  33820. platformId: -1,
  33821. encodingId: -1,
  33822. mappings: [],
  33823. hasShortCmap: false
  33824. };
  33825. }
  33826. var segment;
  33827. var start = (font.start ? font.start : 0) + cmap.offset;
  33828. font.pos = start;
  33829. var version = font.getUint16();
  33830. var numTables = font.getUint16();
  33831. var potentialTable;
  33832. var canBreak = false;
  33833. // There's an order of preference in terms of which cmap subtable to
  33834. // use:
  33835. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  33836. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  33837. // The following takes advantage of the fact that the tables are sorted
  33838. // to work.
  33839. for (var i = 0; i < numTables; i++) {
  33840. var platformId = font.getUint16();
  33841. var encodingId = font.getUint16();
  33842. var offset = font.getInt32() >>> 0;
  33843. var useTable = false;
  33844. if (platformId === 0 && encodingId === 0) {
  33845. useTable = true;
  33846. // Continue the loop since there still may be a higher priority
  33847. // table.
  33848. } else if (platformId === 1 && encodingId === 0) {
  33849. useTable = true;
  33850. // Continue the loop since there still may be a higher priority
  33851. // table.
  33852. } else if (platformId === 3 && encodingId === 1 &&
  33853. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  33854. useTable = true;
  33855. if (!isSymbolicFont) {
  33856. canBreak = true;
  33857. }
  33858. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  33859. useTable = true;
  33860. canBreak = true;
  33861. }
  33862. if (useTable) {
  33863. potentialTable = {
  33864. platformId: platformId,
  33865. encodingId: encodingId,
  33866. offset: offset
  33867. };
  33868. }
  33869. if (canBreak) {
  33870. break;
  33871. }
  33872. }
  33873. if (potentialTable) {
  33874. font.pos = start + potentialTable.offset;
  33875. }
  33876. if (!potentialTable || font.peekByte() === -1) {
  33877. warn('Could not find a preferred cmap table.');
  33878. return {
  33879. platformId: -1,
  33880. encodingId: -1,
  33881. mappings: [],
  33882. hasShortCmap: false
  33883. };
  33884. }
  33885. var format = font.getUint16();
  33886. var length = font.getUint16();
  33887. var language = font.getUint16();
  33888. var hasShortCmap = false;
  33889. var mappings = [];
  33890. var j, glyphId;
  33891. // TODO(mack): refactor this cmap subtable reading logic out
  33892. if (format === 0) {
  33893. for (j = 0; j < 256; j++) {
  33894. var index = font.getByte();
  33895. if (!index) {
  33896. continue;
  33897. }
  33898. mappings.push({
  33899. charCode: j,
  33900. glyphId: index
  33901. });
  33902. }
  33903. hasShortCmap = true;
  33904. } else if (format === 4) {
  33905. // re-creating the table in format 4 since the encoding
  33906. // might be changed
  33907. var segCount = (font.getUint16() >> 1);
  33908. font.getBytes(6); // skipping range fields
  33909. var segIndex, segments = [];
  33910. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33911. segments.push({ end: font.getUint16() });
  33912. }
  33913. font.getUint16();
  33914. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33915. segments[segIndex].start = font.getUint16();
  33916. }
  33917. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33918. segments[segIndex].delta = font.getUint16();
  33919. }
  33920. var offsetsCount = 0;
  33921. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33922. segment = segments[segIndex];
  33923. var rangeOffset = font.getUint16();
  33924. if (!rangeOffset) {
  33925. segment.offsetIndex = -1;
  33926. continue;
  33927. }
  33928. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  33929. segment.offsetIndex = offsetIndex;
  33930. offsetsCount = Math.max(offsetsCount, offsetIndex +
  33931. segment.end - segment.start + 1);
  33932. }
  33933. var offsets = [];
  33934. for (j = 0; j < offsetsCount; j++) {
  33935. offsets.push(font.getUint16());
  33936. }
  33937. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33938. segment = segments[segIndex];
  33939. start = segment.start;
  33940. var end = segment.end;
  33941. var delta = segment.delta;
  33942. offsetIndex = segment.offsetIndex;
  33943. for (j = start; j <= end; j++) {
  33944. if (j === 0xFFFF) {
  33945. continue;
  33946. }
  33947. glyphId = (offsetIndex < 0 ?
  33948. j : offsets[offsetIndex + j - start]);
  33949. glyphId = (glyphId + delta) & 0xFFFF;
  33950. if (glyphId === 0) {
  33951. continue;
  33952. }
  33953. mappings.push({
  33954. charCode: j,
  33955. glyphId: glyphId
  33956. });
  33957. }
  33958. }
  33959. } else if (format === 6) {
  33960. // Format 6 is a 2-bytes dense mapping, which means the font data
  33961. // lives glue together even if they are pretty far in the unicode
  33962. // table. (This looks weird, so I can have missed something), this
  33963. // works on Linux but seems to fails on Mac so let's rewrite the
  33964. // cmap table to a 3-1-4 style
  33965. var firstCode = font.getUint16();
  33966. var entryCount = font.getUint16();
  33967. for (j = 0; j < entryCount; j++) {
  33968. glyphId = font.getUint16();
  33969. var charCode = firstCode + j;
  33970. mappings.push({
  33971. charCode: charCode,
  33972. glyphId: glyphId
  33973. });
  33974. }
  33975. } else {
  33976. warn('cmap table has unsupported format: ' + format);
  33977. return {
  33978. platformId: -1,
  33979. encodingId: -1,
  33980. mappings: [],
  33981. hasShortCmap: false
  33982. };
  33983. }
  33984. // removing duplicate entries
  33985. mappings.sort(function (a, b) {
  33986. return a.charCode - b.charCode;
  33987. });
  33988. for (i = 1; i < mappings.length; i++) {
  33989. if (mappings[i - 1].charCode === mappings[i].charCode) {
  33990. mappings.splice(i, 1);
  33991. i--;
  33992. }
  33993. }
  33994. return {
  33995. platformId: potentialTable.platformId,
  33996. encodingId: potentialTable.encodingId,
  33997. mappings: mappings,
  33998. hasShortCmap: hasShortCmap
  33999. };
  34000. }
  34001. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  34002. if (!header) {
  34003. if (metrics) {
  34004. metrics.data = null;
  34005. }
  34006. return;
  34007. }
  34008. font.pos = (font.start ? font.start : 0) + header.offset;
  34009. font.pos += header.length - 2;
  34010. var numOfMetrics = font.getUint16();
  34011. if (numOfMetrics > numGlyphs) {
  34012. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  34013. 'greater than the numGlyphs (' + numGlyphs + ')');
  34014. // Reduce numOfMetrics if it is greater than numGlyphs
  34015. numOfMetrics = numGlyphs;
  34016. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  34017. header.data[35] = numOfMetrics & 0x00ff;
  34018. }
  34019. var numOfSidebearings = numGlyphs - numOfMetrics;
  34020. var numMissing = numOfSidebearings -
  34021. ((metrics.length - numOfMetrics * 4) >> 1);
  34022. if (numMissing > 0) {
  34023. // For each missing glyph, we set both the width and lsb to 0 (zero).
  34024. // Since we need to add two properties for each glyph, this explains
  34025. // the use of |numMissing * 2| when initializing the typed array.
  34026. var entries = new Uint8Array(metrics.length + numMissing * 2);
  34027. entries.set(metrics.data);
  34028. metrics.data = entries;
  34029. }
  34030. }
  34031. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  34032. hintsValid) {
  34033. if (sourceEnd - sourceStart <= 12) {
  34034. // glyph with data less than 12 is invalid one
  34035. return 0;
  34036. }
  34037. var glyf = source.subarray(sourceStart, sourceEnd);
  34038. var contoursCount = (glyf[0] << 8) | glyf[1];
  34039. if (contoursCount & 0x8000) {
  34040. // complex glyph, writing as is
  34041. dest.set(glyf, destStart);
  34042. return glyf.length;
  34043. }
  34044. var i, j = 10, flagsCount = 0;
  34045. for (i = 0; i < contoursCount; i++) {
  34046. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  34047. flagsCount = endPoint + 1;
  34048. j += 2;
  34049. }
  34050. // skipping instructions
  34051. var instructionsStart = j;
  34052. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  34053. j += 2 + instructionsLength;
  34054. var instructionsEnd = j;
  34055. // validating flags
  34056. var coordinatesLength = 0;
  34057. for (i = 0; i < flagsCount; i++) {
  34058. var flag = glyf[j++];
  34059. if (flag & 0xC0) {
  34060. // reserved flags must be zero, cleaning up
  34061. glyf[j - 1] = flag & 0x3F;
  34062. }
  34063. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  34064. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  34065. coordinatesLength += xyLength;
  34066. if (flag & 8) {
  34067. var repeat = glyf[j++];
  34068. i += repeat;
  34069. coordinatesLength += repeat * xyLength;
  34070. }
  34071. }
  34072. // glyph without coordinates will be rejected
  34073. if (coordinatesLength === 0) {
  34074. return 0;
  34075. }
  34076. var glyphDataLength = j + coordinatesLength;
  34077. if (glyphDataLength > glyf.length) {
  34078. // not enough data for coordinates
  34079. return 0;
  34080. }
  34081. if (!hintsValid && instructionsLength > 0) {
  34082. dest.set(glyf.subarray(0, instructionsStart), destStart);
  34083. dest.set([0, 0], destStart + instructionsStart);
  34084. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  34085. destStart + instructionsStart + 2);
  34086. glyphDataLength -= instructionsLength;
  34087. if (glyf.length - glyphDataLength > 3) {
  34088. glyphDataLength = (glyphDataLength + 3) & ~3;
  34089. }
  34090. return glyphDataLength;
  34091. }
  34092. if (glyf.length - glyphDataLength > 3) {
  34093. // truncating and aligning to 4 bytes the long glyph data
  34094. glyphDataLength = (glyphDataLength + 3) & ~3;
  34095. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  34096. return glyphDataLength;
  34097. }
  34098. // glyph data is fine
  34099. dest.set(glyf, destStart);
  34100. return glyf.length;
  34101. }
  34102. function sanitizeHead(head, numGlyphs, locaLength) {
  34103. var data = head.data;
  34104. // Validate version:
  34105. // Should always be 0x00010000
  34106. var version = int32(data[0], data[1], data[2], data[3]);
  34107. if (version >> 16 !== 1) {
  34108. info('Attempting to fix invalid version in head table: ' + version);
  34109. data[0] = 0;
  34110. data[1] = 1;
  34111. data[2] = 0;
  34112. data[3] = 0;
  34113. }
  34114. var indexToLocFormat = int16(data[50], data[51]);
  34115. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  34116. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  34117. indexToLocFormat);
  34118. // The value of indexToLocFormat should be 0 if the loca table
  34119. // consists of short offsets, and should be 1 if the loca table
  34120. // consists of long offsets.
  34121. //
  34122. // The number of entries in the loca table should be numGlyphs + 1.
  34123. //
  34124. // Using this information, we can work backwards to deduce if the
  34125. // size of each offset in the loca table, and thus figure out the
  34126. // appropriate value for indexToLocFormat.
  34127. var numGlyphsPlusOne = numGlyphs + 1;
  34128. if (locaLength === numGlyphsPlusOne << 1) {
  34129. // 0x0000 indicates the loca table consists of short offsets
  34130. data[50] = 0;
  34131. data[51] = 0;
  34132. } else if (locaLength === numGlyphsPlusOne << 2) {
  34133. // 0x0001 indicates the loca table consists of long offsets
  34134. data[50] = 0;
  34135. data[51] = 1;
  34136. } else {
  34137. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  34138. }
  34139. }
  34140. }
  34141. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  34142. isGlyphLocationsLong, hintsValid,
  34143. dupFirstEntry) {
  34144. var itemSize, itemDecode, itemEncode;
  34145. if (isGlyphLocationsLong) {
  34146. itemSize = 4;
  34147. itemDecode = function fontItemDecodeLong(data, offset) {
  34148. return (data[offset] << 24) | (data[offset + 1] << 16) |
  34149. (data[offset + 2] << 8) | data[offset + 3];
  34150. };
  34151. itemEncode = function fontItemEncodeLong(data, offset, value) {
  34152. data[offset] = (value >>> 24) & 0xFF;
  34153. data[offset + 1] = (value >> 16) & 0xFF;
  34154. data[offset + 2] = (value >> 8) & 0xFF;
  34155. data[offset + 3] = value & 0xFF;
  34156. };
  34157. } else {
  34158. itemSize = 2;
  34159. itemDecode = function fontItemDecode(data, offset) {
  34160. return (data[offset] << 9) | (data[offset + 1] << 1);
  34161. };
  34162. itemEncode = function fontItemEncode(data, offset, value) {
  34163. data[offset] = (value >> 9) & 0xFF;
  34164. data[offset + 1] = (value >> 1) & 0xFF;
  34165. };
  34166. }
  34167. var locaData = loca.data;
  34168. var locaDataSize = itemSize * (1 + numGlyphs);
  34169. // is loca.data too short or long?
  34170. if (locaData.length !== locaDataSize) {
  34171. locaData = new Uint8Array(locaDataSize);
  34172. locaData.set(loca.data.subarray(0, locaDataSize));
  34173. loca.data = locaData;
  34174. }
  34175. // removing the invalid glyphs
  34176. var oldGlyfData = glyf.data;
  34177. var oldGlyfDataLength = oldGlyfData.length;
  34178. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  34179. var startOffset = itemDecode(locaData, 0);
  34180. var writeOffset = 0;
  34181. var missingGlyphData = {};
  34182. itemEncode(locaData, 0, writeOffset);
  34183. var i, j;
  34184. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  34185. var endOffset = itemDecode(locaData, j);
  34186. if (endOffset > oldGlyfDataLength &&
  34187. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  34188. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  34189. // the glyf table size, which makes last glyph out of range.
  34190. endOffset = oldGlyfDataLength;
  34191. }
  34192. if (endOffset > oldGlyfDataLength) {
  34193. // glyph end offset points outside glyf data, rejecting the glyph
  34194. itemEncode(locaData, j, writeOffset);
  34195. startOffset = endOffset;
  34196. continue;
  34197. }
  34198. if (startOffset === endOffset) {
  34199. missingGlyphData[i] = true;
  34200. }
  34201. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  34202. newGlyfData, writeOffset, hintsValid);
  34203. writeOffset += newLength;
  34204. itemEncode(locaData, j, writeOffset);
  34205. startOffset = endOffset;
  34206. }
  34207. if (writeOffset === 0) {
  34208. // glyf table cannot be empty -- redoing the glyf and loca tables
  34209. // to have single glyph with one point
  34210. var simpleGlyph = new Uint8Array(
  34211. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  34212. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  34213. itemEncode(locaData, j, simpleGlyph.length);
  34214. }
  34215. glyf.data = simpleGlyph;
  34216. return missingGlyphData;
  34217. }
  34218. if (dupFirstEntry) {
  34219. var firstEntryLength = itemDecode(locaData, itemSize);
  34220. if (newGlyfData.length > firstEntryLength + writeOffset) {
  34221. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  34222. } else {
  34223. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  34224. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  34225. }
  34226. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  34227. itemEncode(loca.data, locaData.length - itemSize,
  34228. writeOffset + firstEntryLength);
  34229. } else {
  34230. glyf.data = newGlyfData.subarray(0, writeOffset);
  34231. }
  34232. return missingGlyphData;
  34233. }
  34234. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  34235. var start = (font.start ? font.start : 0) + post.offset;
  34236. font.pos = start;
  34237. var length = post.length, end = start + length;
  34238. var version = font.getInt32();
  34239. // skip rest to the tables
  34240. font.getBytes(28);
  34241. var glyphNames;
  34242. var valid = true;
  34243. var i;
  34244. switch (version) {
  34245. case 0x00010000:
  34246. glyphNames = MacStandardGlyphOrdering;
  34247. break;
  34248. case 0x00020000:
  34249. var numGlyphs = font.getUint16();
  34250. if (numGlyphs !== maxpNumGlyphs) {
  34251. valid = false;
  34252. break;
  34253. }
  34254. var glyphNameIndexes = [];
  34255. for (i = 0; i < numGlyphs; ++i) {
  34256. var index = font.getUint16();
  34257. if (index >= 32768) {
  34258. valid = false;
  34259. break;
  34260. }
  34261. glyphNameIndexes.push(index);
  34262. }
  34263. if (!valid) {
  34264. break;
  34265. }
  34266. var customNames = [];
  34267. var strBuf = [];
  34268. while (font.pos < end) {
  34269. var stringLength = font.getByte();
  34270. strBuf.length = stringLength;
  34271. for (i = 0; i < stringLength; ++i) {
  34272. strBuf[i] = String.fromCharCode(font.getByte());
  34273. }
  34274. customNames.push(strBuf.join(''));
  34275. }
  34276. glyphNames = [];
  34277. for (i = 0; i < numGlyphs; ++i) {
  34278. var j = glyphNameIndexes[i];
  34279. if (j < 258) {
  34280. glyphNames.push(MacStandardGlyphOrdering[j]);
  34281. continue;
  34282. }
  34283. glyphNames.push(customNames[j - 258]);
  34284. }
  34285. break;
  34286. case 0x00030000:
  34287. break;
  34288. default:
  34289. warn('Unknown/unsupported post table version ' + version);
  34290. valid = false;
  34291. if (properties.defaultEncoding) {
  34292. glyphNames = properties.defaultEncoding;
  34293. }
  34294. break;
  34295. }
  34296. properties.glyphNames = glyphNames;
  34297. return valid;
  34298. }
  34299. function readNameTable(nameTable) {
  34300. var start = (font.start ? font.start : 0) + nameTable.offset;
  34301. font.pos = start;
  34302. var names = [[], []];
  34303. var length = nameTable.length, end = start + length;
  34304. var format = font.getUint16();
  34305. var FORMAT_0_HEADER_LENGTH = 6;
  34306. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  34307. // unsupported name table format or table "too" small
  34308. return names;
  34309. }
  34310. var numRecords = font.getUint16();
  34311. var stringsStart = font.getUint16();
  34312. var records = [];
  34313. var NAME_RECORD_LENGTH = 12;
  34314. var i, ii;
  34315. for (i = 0; i < numRecords &&
  34316. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  34317. var r = {
  34318. platform: font.getUint16(),
  34319. encoding: font.getUint16(),
  34320. language: font.getUint16(),
  34321. name: font.getUint16(),
  34322. length: font.getUint16(),
  34323. offset: font.getUint16()
  34324. };
  34325. // using only Macintosh and Windows platform/encoding names
  34326. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  34327. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  34328. records.push(r);
  34329. }
  34330. }
  34331. for (i = 0, ii = records.length; i < ii; i++) {
  34332. var record = records[i];
  34333. var pos = start + stringsStart + record.offset;
  34334. if (pos + record.length > end) {
  34335. continue; // outside of name table, ignoring
  34336. }
  34337. font.pos = pos;
  34338. var nameIndex = record.name;
  34339. if (record.encoding) {
  34340. // unicode
  34341. var str = '';
  34342. for (var j = 0, jj = record.length; j < jj; j += 2) {
  34343. str += String.fromCharCode(font.getUint16());
  34344. }
  34345. names[1][nameIndex] = str;
  34346. } else {
  34347. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  34348. }
  34349. }
  34350. return names;
  34351. }
  34352. var TTOpsStackDeltas = [
  34353. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  34354. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  34355. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  34356. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  34357. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  34358. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  34359. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34360. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  34361. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  34362. // 0xC0-DF == -1 and 0xE0-FF == -2
  34363. function sanitizeTTProgram(table, ttContext) {
  34364. var data = table.data;
  34365. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  34366. var stack = [];
  34367. var callstack = [];
  34368. var functionsCalled = [];
  34369. var tooComplexToFollowFunctions =
  34370. ttContext.tooComplexToFollowFunctions;
  34371. var inFDEF = false, ifLevel = 0, inELSE = 0;
  34372. for (var ii = data.length; i < ii;) {
  34373. var op = data[i++];
  34374. // The TrueType instruction set docs can be found at
  34375. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  34376. if (op === 0x40) { // NPUSHB - pushes n bytes
  34377. n = data[i++];
  34378. if (inFDEF || inELSE) {
  34379. i += n;
  34380. } else {
  34381. for (j = 0; j < n; j++) {
  34382. stack.push(data[i++]);
  34383. }
  34384. }
  34385. } else if (op === 0x41) { // NPUSHW - pushes n words
  34386. n = data[i++];
  34387. if (inFDEF || inELSE) {
  34388. i += n * 2;
  34389. } else {
  34390. for (j = 0; j < n; j++) {
  34391. b = data[i++];
  34392. stack.push((b << 8) | data[i++]);
  34393. }
  34394. }
  34395. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  34396. n = op - 0xB0 + 1;
  34397. if (inFDEF || inELSE) {
  34398. i += n;
  34399. } else {
  34400. for (j = 0; j < n; j++) {
  34401. stack.push(data[i++]);
  34402. }
  34403. }
  34404. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  34405. n = op - 0xB8 + 1;
  34406. if (inFDEF || inELSE) {
  34407. i += n * 2;
  34408. } else {
  34409. for (j = 0; j < n; j++) {
  34410. b = data[i++];
  34411. stack.push((b << 8) | data[i++]);
  34412. }
  34413. }
  34414. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  34415. if (!inFDEF && !inELSE) {
  34416. // collecting inforamtion about which functions are used
  34417. funcId = stack[stack.length - 1];
  34418. ttContext.functionsUsed[funcId] = true;
  34419. if (funcId in ttContext.functionsStackDeltas) {
  34420. stack.length += ttContext.functionsStackDeltas[funcId];
  34421. } else if (funcId in ttContext.functionsDefined &&
  34422. functionsCalled.indexOf(funcId) < 0) {
  34423. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  34424. functionsCalled.push(funcId);
  34425. pc = ttContext.functionsDefined[funcId];
  34426. if (!pc) {
  34427. warn('TT: CALL non-existent function');
  34428. ttContext.hintsValid = false;
  34429. return;
  34430. }
  34431. data = pc.data;
  34432. i = pc.i;
  34433. }
  34434. }
  34435. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  34436. if (inFDEF || inELSE) {
  34437. warn('TT: nested FDEFs not allowed');
  34438. tooComplexToFollowFunctions = true;
  34439. }
  34440. inFDEF = true;
  34441. // collecting inforamtion about which functions are defined
  34442. lastDeff = i;
  34443. funcId = stack.pop();
  34444. ttContext.functionsDefined[funcId] = {data: data, i: i};
  34445. } else if (op === 0x2D) { // ENDF - end of function
  34446. if (inFDEF) {
  34447. inFDEF = false;
  34448. lastEndf = i;
  34449. } else {
  34450. pc = callstack.pop();
  34451. if (!pc) {
  34452. warn('TT: ENDF bad stack');
  34453. ttContext.hintsValid = false;
  34454. return;
  34455. }
  34456. funcId = functionsCalled.pop();
  34457. data = pc.data;
  34458. i = pc.i;
  34459. ttContext.functionsStackDeltas[funcId] =
  34460. stack.length - pc.stackTop;
  34461. }
  34462. } else if (op === 0x89) { // IDEF - instruction definition
  34463. if (inFDEF || inELSE) {
  34464. warn('TT: nested IDEFs not allowed');
  34465. tooComplexToFollowFunctions = true;
  34466. }
  34467. inFDEF = true;
  34468. // recording it as a function to track ENDF
  34469. lastDeff = i;
  34470. } else if (op === 0x58) { // IF
  34471. ++ifLevel;
  34472. } else if (op === 0x1B) { // ELSE
  34473. inELSE = ifLevel;
  34474. } else if (op === 0x59) { // EIF
  34475. if (inELSE === ifLevel) {
  34476. inELSE = 0;
  34477. }
  34478. --ifLevel;
  34479. } else if (op === 0x1C) { // JMPR
  34480. if (!inFDEF && !inELSE) {
  34481. var offset = stack[stack.length - 1];
  34482. // only jumping forward to prevent infinite loop
  34483. if (offset > 0) {
  34484. i += offset - 1;
  34485. }
  34486. }
  34487. }
  34488. // Adjusting stack not extactly, but just enough to get function id
  34489. if (!inFDEF && !inELSE) {
  34490. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  34491. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  34492. if (op >= 0x71 && op <= 0x75) {
  34493. n = stack.pop();
  34494. if (n === n) {
  34495. stackDelta = -n * 2;
  34496. }
  34497. }
  34498. while (stackDelta < 0 && stack.length > 0) {
  34499. stack.pop();
  34500. stackDelta++;
  34501. }
  34502. while (stackDelta > 0) {
  34503. stack.push(NaN); // pushing any number into stack
  34504. stackDelta--;
  34505. }
  34506. }
  34507. }
  34508. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  34509. var content = [data];
  34510. if (i > data.length) {
  34511. content.push(new Uint8Array(i - data.length));
  34512. }
  34513. if (lastDeff > lastEndf) {
  34514. warn('TT: complementing a missing function tail');
  34515. // new function definition started, but not finished
  34516. // complete function by [CLEAR, ENDF]
  34517. content.push(new Uint8Array([0x22, 0x2D]));
  34518. }
  34519. foldTTTable(table, content);
  34520. }
  34521. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  34522. if (ttContext.tooComplexToFollowFunctions) {
  34523. return;
  34524. }
  34525. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  34526. warn('TT: more functions defined than expected');
  34527. ttContext.hintsValid = false;
  34528. return;
  34529. }
  34530. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  34531. if (j > maxFunctionDefs) {
  34532. warn('TT: invalid function id: ' + j);
  34533. ttContext.hintsValid = false;
  34534. return;
  34535. }
  34536. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  34537. warn('TT: undefined function: ' + j);
  34538. ttContext.hintsValid = false;
  34539. return;
  34540. }
  34541. }
  34542. }
  34543. function foldTTTable(table, content) {
  34544. if (content.length > 1) {
  34545. // concatenating the content items
  34546. var newLength = 0;
  34547. var j, jj;
  34548. for (j = 0, jj = content.length; j < jj; j++) {
  34549. newLength += content[j].length;
  34550. }
  34551. newLength = (newLength + 3) & ~3;
  34552. var result = new Uint8Array(newLength);
  34553. var pos = 0;
  34554. for (j = 0, jj = content.length; j < jj; j++) {
  34555. result.set(content[j], pos);
  34556. pos += content[j].length;
  34557. }
  34558. table.data = result;
  34559. table.length = newLength;
  34560. }
  34561. }
  34562. function sanitizeTTPrograms(fpgm, prep, cvt) {
  34563. var ttContext = {
  34564. functionsDefined: [],
  34565. functionsUsed: [],
  34566. functionsStackDeltas: [],
  34567. tooComplexToFollowFunctions: false,
  34568. hintsValid: true
  34569. };
  34570. if (fpgm) {
  34571. sanitizeTTProgram(fpgm, ttContext);
  34572. }
  34573. if (prep) {
  34574. sanitizeTTProgram(prep, ttContext);
  34575. }
  34576. if (fpgm) {
  34577. checkInvalidFunctions(ttContext, maxFunctionDefs);
  34578. }
  34579. if (cvt && (cvt.length & 1)) {
  34580. var cvtData = new Uint8Array(cvt.length + 1);
  34581. cvtData.set(cvt.data);
  34582. cvt.data = cvtData;
  34583. }
  34584. return ttContext.hintsValid;
  34585. }
  34586. // The following steps modify the original font data, making copy
  34587. font = new Stream(new Uint8Array(font.getBytes()));
  34588. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  34589. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  34590. var header = readOpenTypeHeader(font);
  34591. var numTables = header.numTables;
  34592. var cff, cffFile;
  34593. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  34594. hmtx: null, maxp: null, name: null, post: null };
  34595. var table;
  34596. for (var i = 0; i < numTables; i++) {
  34597. table = readTableEntry(font);
  34598. if (VALID_TABLES.indexOf(table.tag) < 0) {
  34599. continue; // skipping table if it's not a required or optional table
  34600. }
  34601. if (table.length === 0) {
  34602. continue; // skipping empty tables
  34603. }
  34604. tables[table.tag] = table;
  34605. }
  34606. var isTrueType = !tables['CFF '];
  34607. if (!isTrueType) {
  34608. // OpenType font
  34609. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  34610. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  34611. // no major tables: throwing everything at CFFFont
  34612. cffFile = new Stream(tables['CFF '].data);
  34613. cff = new CFFFont(cffFile, properties);
  34614. adjustWidths(properties);
  34615. return this.convert(name, cff, properties);
  34616. }
  34617. delete tables.glyf;
  34618. delete tables.loca;
  34619. delete tables.fpgm;
  34620. delete tables.prep;
  34621. delete tables['cvt '];
  34622. this.isOpenType = true;
  34623. } else {
  34624. if (!tables.glyf || !tables.loca) {
  34625. error('Required "glyf" or "loca" tables are not found');
  34626. }
  34627. this.isOpenType = false;
  34628. }
  34629. if (!tables.maxp) {
  34630. error('Required "maxp" table is not found');
  34631. }
  34632. font.pos = (font.start || 0) + tables.maxp.offset;
  34633. var version = font.getInt32();
  34634. var numGlyphs = font.getUint16();
  34635. var maxFunctionDefs = 0;
  34636. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  34637. // maxZones can be invalid
  34638. font.pos += 8;
  34639. var maxZones = font.getUint16();
  34640. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  34641. tables.maxp.data[14] = 0;
  34642. tables.maxp.data[15] = 2;
  34643. }
  34644. font.pos += 4;
  34645. maxFunctionDefs = font.getUint16();
  34646. }
  34647. var dupFirstEntry = false;
  34648. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  34649. properties.toUnicode.get(0) > '\u0000') {
  34650. // oracle's defect (see 3427), duplicating first entry
  34651. dupFirstEntry = true;
  34652. numGlyphs++;
  34653. tables.maxp.data[4] = numGlyphs >> 8;
  34654. tables.maxp.data[5] = numGlyphs & 255;
  34655. }
  34656. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  34657. tables['cvt '], maxFunctionDefs);
  34658. if (!hintsValid) {
  34659. delete tables.fpgm;
  34660. delete tables.prep;
  34661. delete tables['cvt '];
  34662. }
  34663. // Ensure the hmtx table contains the advance width and
  34664. // sidebearings information for numGlyphs in the maxp table
  34665. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  34666. if (!tables.head) {
  34667. error('Required "head" table is not found');
  34668. }
  34669. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  34670. var missingGlyphs = {};
  34671. if (isTrueType) {
  34672. var isGlyphLocationsLong = int16(tables.head.data[50],
  34673. tables.head.data[51]);
  34674. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  34675. numGlyphs, isGlyphLocationsLong,
  34676. hintsValid, dupFirstEntry);
  34677. }
  34678. if (!tables.hhea) {
  34679. error('Required "hhea" table is not found');
  34680. }
  34681. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  34682. // Sometimes it's 0. That needs to be fixed
  34683. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  34684. tables.hhea.data[10] = 0xFF;
  34685. tables.hhea.data[11] = 0xFF;
  34686. }
  34687. // Extract some more font properties from the OpenType head and
  34688. // hhea tables; yMin and descent value are always negative.
  34689. var metricsOverride = {
  34690. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  34691. yMax: int16(tables.head.data[42], tables.head.data[43]),
  34692. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  34693. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  34694. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  34695. };
  34696. // PDF FontDescriptor metrics lie -- using data from actual font.
  34697. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  34698. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  34699. // The 'post' table has glyphs names.
  34700. if (tables.post) {
  34701. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  34702. if (!valid) {
  34703. tables.post = null;
  34704. }
  34705. }
  34706. var charCodeToGlyphId = [], charCode;
  34707. var toUnicode = properties.toUnicode, widths = properties.widths;
  34708. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  34709. toUnicode.length === 0x10000);
  34710. // Helper function to try to skip mapping of empty glyphs.
  34711. // Note: In some cases, just relying on the glyph data doesn't work,
  34712. // hence we also use a few heuristics to fix various PDF files.
  34713. function hasGlyph(glyphId, charCode, widthCode) {
  34714. if (!missingGlyphs[glyphId]) {
  34715. return true;
  34716. }
  34717. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  34718. return true;
  34719. }
  34720. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  34721. return true;
  34722. }
  34723. return false;
  34724. }
  34725. if (properties.type === 'CIDFontType2') {
  34726. var cidToGidMap = properties.cidToGidMap || [];
  34727. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  34728. properties.cMap.forEach(function(charCode, cid) {
  34729. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34730. var glyphId = -1;
  34731. if (isCidToGidMapEmpty) {
  34732. glyphId = charCode;
  34733. } else if (cidToGidMap[cid] !== undefined) {
  34734. glyphId = cidToGidMap[cid];
  34735. }
  34736. if (glyphId >= 0 && glyphId < numGlyphs &&
  34737. hasGlyph(glyphId, charCode, cid)) {
  34738. charCodeToGlyphId[charCode] = glyphId;
  34739. }
  34740. });
  34741. if (dupFirstEntry) {
  34742. charCodeToGlyphId[0] = numGlyphs - 1;
  34743. }
  34744. } else {
  34745. // Most of the following logic in this code branch is based on the
  34746. // 9.6.6.4 of the PDF spec.
  34747. var hasEncoding =
  34748. properties.differences.length > 0 || !!properties.baseEncodingName;
  34749. var cmapTable =
  34750. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  34751. var cmapPlatformId = cmapTable.platformId;
  34752. var cmapEncodingId = cmapTable.encodingId;
  34753. var cmapMappings = cmapTable.mappings;
  34754. var cmapMappingsLength = cmapMappings.length;
  34755. // The spec seems to imply that if the font is symbolic the encoding
  34756. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  34757. // where the the font is symbolic and it has an encoding.
  34758. if (hasEncoding &&
  34759. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  34760. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  34761. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  34762. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  34763. // When no preferred cmap table was found and |baseEncodingName| is
  34764. // one of the predefined encodings, we seem to obtain a better
  34765. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  34766. // TODO: Note that this is a hack which should be removed as soon as
  34767. // we have proper support for more exotic cmap tables.
  34768. var baseEncoding = [];
  34769. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  34770. properties.baseEncodingName === 'WinAnsiEncoding') {
  34771. baseEncoding = Encodings[properties.baseEncodingName];
  34772. }
  34773. for (charCode = 0; charCode < 256; charCode++) {
  34774. var glyphName;
  34775. if (this.differences && charCode in this.differences) {
  34776. glyphName = this.differences[charCode];
  34777. } else if (charCode in baseEncoding &&
  34778. baseEncoding[charCode] !== '') {
  34779. glyphName = baseEncoding[charCode];
  34780. } else {
  34781. glyphName = Encodings.StandardEncoding[charCode];
  34782. }
  34783. if (!glyphName) {
  34784. continue;
  34785. }
  34786. var unicodeOrCharCode, isUnicode = false;
  34787. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  34788. unicodeOrCharCode = GlyphsUnicode[glyphName];
  34789. isUnicode = true;
  34790. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  34791. // TODO: the encoding needs to be updated with mac os table.
  34792. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  34793. }
  34794. var found = false;
  34795. for (i = 0; i < cmapMappingsLength; ++i) {
  34796. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  34797. continue;
  34798. }
  34799. var code = isUnicode ? charCode : unicodeOrCharCode;
  34800. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  34801. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34802. found = true;
  34803. break;
  34804. }
  34805. }
  34806. if (!found && properties.glyphNames) {
  34807. // Try to map using the post table.
  34808. var glyphId = properties.glyphNames.indexOf(glyphName);
  34809. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  34810. charCodeToGlyphId[charCode] = glyphId;
  34811. } else {
  34812. charCodeToGlyphId[charCode] = 0; // notdef
  34813. }
  34814. }
  34815. }
  34816. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  34817. // Default Unicode semantics, use the charcodes as is.
  34818. for (i = 0; i < cmapMappingsLength; ++i) {
  34819. charCodeToGlyphId[cmapMappings[i].charCode] =
  34820. cmapMappings[i].glyphId;
  34821. }
  34822. } else {
  34823. // For (3, 0) cmap tables:
  34824. // The charcode key being stored in charCodeToGlyphId is the lower
  34825. // byte of the two-byte charcodes of the cmap table since according to
  34826. // the spec: 'each byte from the string shall be prepended with the
  34827. // high byte of the range [of charcodes in the cmap table], to form
  34828. // a two-byte character, which shall be used to select the
  34829. // associated glyph description from the subtable'.
  34830. //
  34831. // For (1, 0) cmap tables:
  34832. // 'single bytes from the string shall be used to look up the
  34833. // associated glyph descriptions from the subtable'. This means
  34834. // charcodes in the cmap will be single bytes, so no-op since
  34835. // glyph.charCode & 0xFF === glyph.charCode
  34836. for (i = 0; i < cmapMappingsLength; ++i) {
  34837. charCode = cmapMappings[i].charCode & 0xFF;
  34838. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34839. }
  34840. }
  34841. }
  34842. if (charCodeToGlyphId.length === 0) {
  34843. // defines at least one glyph
  34844. charCodeToGlyphId[0] = 0;
  34845. }
  34846. // Converting glyphs and ids into font's cmap table
  34847. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  34848. this.toFontChar = newMapping.toFontChar;
  34849. tables.cmap = {
  34850. tag: 'cmap',
  34851. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  34852. };
  34853. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  34854. tables['OS/2'] = {
  34855. tag: 'OS/2',
  34856. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  34857. metricsOverride)
  34858. };
  34859. }
  34860. // Rewrite the 'post' table if needed
  34861. if (!tables.post) {
  34862. tables.post = {
  34863. tag: 'post',
  34864. data: createPostTable(properties)
  34865. };
  34866. }
  34867. if (!isTrueType) {
  34868. try {
  34869. // Trying to repair CFF file
  34870. cffFile = new Stream(tables['CFF '].data);
  34871. var parser = new CFFParser(cffFile, properties);
  34872. cff = parser.parse();
  34873. var compiler = new CFFCompiler(cff);
  34874. tables['CFF '].data = compiler.compile();
  34875. } catch (e) {
  34876. warn('Failed to compile font ' + properties.loadedName);
  34877. }
  34878. }
  34879. // Re-creating 'name' table
  34880. if (!tables.name) {
  34881. tables.name = {
  34882. tag: 'name',
  34883. data: createNameTable(this.name)
  34884. };
  34885. } else {
  34886. // ... using existing 'name' table as prototype
  34887. var namePrototype = readNameTable(tables.name);
  34888. tables.name.data = createNameTable(name, namePrototype);
  34889. }
  34890. var builder = new OpenTypeFileBuilder(header.version);
  34891. for (var tableTag in tables) {
  34892. builder.addTable(tableTag, tables[tableTag].data);
  34893. }
  34894. return builder.toArray();
  34895. },
  34896. convert: function Font_convert(fontName, font, properties) {
  34897. // TODO: Check the charstring widths to determine this.
  34898. properties.fixedPitch = false;
  34899. var mapping = font.getGlyphMapping(properties);
  34900. var newMapping = adjustMapping(mapping, properties);
  34901. this.toFontChar = newMapping.toFontChar;
  34902. var numGlyphs = font.numGlyphs;
  34903. function getCharCodes(charCodeToGlyphId, glyphId) {
  34904. var charCodes = null;
  34905. for (var charCode in charCodeToGlyphId) {
  34906. if (glyphId === charCodeToGlyphId[charCode]) {
  34907. if (!charCodes) {
  34908. charCodes = [];
  34909. }
  34910. charCodes.push(charCode | 0);
  34911. }
  34912. }
  34913. return charCodes;
  34914. }
  34915. function createCharCode(charCodeToGlyphId, glyphId) {
  34916. for (var charCode in charCodeToGlyphId) {
  34917. if (glyphId === charCodeToGlyphId[charCode]) {
  34918. return charCode | 0;
  34919. }
  34920. }
  34921. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  34922. glyphId;
  34923. return newMapping.nextAvailableFontCharCode++;
  34924. }
  34925. var seacs = font.seacs;
  34926. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  34927. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  34928. var charset = font.getCharset();
  34929. var seacMap = Object.create(null);
  34930. for (var glyphId in seacs) {
  34931. glyphId |= 0;
  34932. var seac = seacs[glyphId];
  34933. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  34934. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  34935. var baseGlyphId = charset.indexOf(baseGlyphName);
  34936. var accentGlyphId = charset.indexOf(accentGlyphName);
  34937. if (baseGlyphId < 0 || accentGlyphId < 0) {
  34938. continue;
  34939. }
  34940. var accentOffset = {
  34941. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  34942. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  34943. };
  34944. var charCodes = getCharCodes(mapping, glyphId);
  34945. if (!charCodes) {
  34946. // There's no point in mapping it if the char code was never mapped
  34947. // to begin with.
  34948. continue;
  34949. }
  34950. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  34951. var charCode = charCodes[i];
  34952. // Find a fontCharCode that maps to the base and accent glyphs.
  34953. // If one doesn't exists, create it.
  34954. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  34955. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  34956. baseGlyphId);
  34957. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  34958. accentGlyphId);
  34959. seacMap[charCode] = {
  34960. baseFontCharCode: baseFontCharCode,
  34961. accentFontCharCode: accentFontCharCode,
  34962. accentOffset: accentOffset
  34963. };
  34964. }
  34965. }
  34966. properties.seacMap = seacMap;
  34967. }
  34968. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  34969. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  34970. // PostScript Font Program
  34971. builder.addTable('CFF ', font.data);
  34972. // OS/2 and Windows Specific metrics
  34973. builder.addTable('OS/2', createOS2Table(properties,
  34974. newMapping.charCodeToGlyphId));
  34975. // Character to glyphs mapping
  34976. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  34977. numGlyphs));
  34978. // Font header
  34979. builder.addTable('head',
  34980. '\x00\x01\x00\x00' + // Version number
  34981. '\x00\x00\x10\x00' + // fontRevision
  34982. '\x00\x00\x00\x00' + // checksumAdjustement
  34983. '\x5F\x0F\x3C\xF5' + // magicNumber
  34984. '\x00\x00' + // Flags
  34985. safeString16(unitsPerEm) + // unitsPerEM
  34986. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  34987. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  34988. '\x00\x00' + // xMin
  34989. safeString16(properties.descent) + // yMin
  34990. '\x0F\xFF' + // xMax
  34991. safeString16(properties.ascent) + // yMax
  34992. string16(properties.italicAngle ? 2 : 0) + // macStyle
  34993. '\x00\x11' + // lowestRecPPEM
  34994. '\x00\x00' + // fontDirectionHint
  34995. '\x00\x00' + // indexToLocFormat
  34996. '\x00\x00'); // glyphDataFormat
  34997. // Horizontal header
  34998. builder.addTable('hhea',
  34999. '\x00\x01\x00\x00' + // Version number
  35000. safeString16(properties.ascent) + // Typographic Ascent
  35001. safeString16(properties.descent) + // Typographic Descent
  35002. '\x00\x00' + // Line Gap
  35003. '\xFF\xFF' + // advanceWidthMax
  35004. '\x00\x00' + // minLeftSidebearing
  35005. '\x00\x00' + // minRightSidebearing
  35006. '\x00\x00' + // xMaxExtent
  35007. safeString16(properties.capHeight) + // caretSlopeRise
  35008. safeString16(Math.tan(properties.italicAngle) *
  35009. properties.xHeight) + // caretSlopeRun
  35010. '\x00\x00' + // caretOffset
  35011. '\x00\x00' + // -reserved-
  35012. '\x00\x00' + // -reserved-
  35013. '\x00\x00' + // -reserved-
  35014. '\x00\x00' + // -reserved-
  35015. '\x00\x00' + // metricDataFormat
  35016. string16(numGlyphs)); // Number of HMetrics
  35017. // Horizontal metrics
  35018. builder.addTable('hmtx', (function fontFieldsHmtx() {
  35019. var charstrings = font.charstrings;
  35020. var cffWidths = font.cff ? font.cff.widths : null;
  35021. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  35022. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  35023. var width = 0;
  35024. if (charstrings) {
  35025. var charstring = charstrings[i - 1];
  35026. width = 'width' in charstring ? charstring.width : 0;
  35027. } else if (cffWidths) {
  35028. width = Math.ceil(cffWidths[i] || 0);
  35029. }
  35030. hmtx += string16(width) + string16(0);
  35031. }
  35032. return hmtx;
  35033. })());
  35034. // Maximum profile
  35035. builder.addTable('maxp',
  35036. '\x00\x00\x50\x00' + // Version number
  35037. string16(numGlyphs)); // Num of glyphs
  35038. // Naming tables
  35039. builder.addTable('name', createNameTable(fontName));
  35040. // PostScript informations
  35041. builder.addTable('post', createPostTable(properties));
  35042. return builder.toArray();
  35043. },
  35044. /**
  35045. * Builds a char code to unicode map based on section 9.10 of the spec.
  35046. * @param {Object} properties Font properties object.
  35047. * @return {Object} A ToUnicodeMap object.
  35048. */
  35049. buildToUnicode: function Font_buildToUnicode(properties) {
  35050. // Section 9.10.2 Mapping Character Codes to Unicode Values
  35051. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  35052. return properties.toUnicode;
  35053. }
  35054. // According to the spec if the font is a simple font we should only map
  35055. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  35056. // the differences array only contains adobe standard or symbol set names,
  35057. // in pratice it seems better to always try to create a toUnicode
  35058. // map based of the default encoding.
  35059. var toUnicode, charcode;
  35060. if (!properties.composite /* is simple font */) {
  35061. toUnicode = [];
  35062. var encoding = properties.defaultEncoding.slice();
  35063. var baseEncodingName = properties.baseEncodingName;
  35064. // Merge in the differences array.
  35065. var differences = properties.differences;
  35066. for (charcode in differences) {
  35067. encoding[charcode] = differences[charcode];
  35068. }
  35069. for (charcode in encoding) {
  35070. // a) Map the character code to a character name.
  35071. var glyphName = encoding[charcode];
  35072. // b) Look up the character name in the Adobe Glyph List (see the
  35073. // Bibliography) to obtain the corresponding Unicode value.
  35074. if (glyphName === '') {
  35075. continue;
  35076. } else if (GlyphsUnicode[glyphName] === undefined) {
  35077. // (undocumented) c) Few heuristics to recognize unknown glyphs
  35078. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  35079. var code = 0;
  35080. switch (glyphName[0]) {
  35081. case 'G': // Gxx glyph
  35082. if (glyphName.length === 3) {
  35083. code = parseInt(glyphName.substr(1), 16);
  35084. }
  35085. break;
  35086. case 'g': // g00xx glyph
  35087. if (glyphName.length === 5) {
  35088. code = parseInt(glyphName.substr(1), 16);
  35089. }
  35090. break;
  35091. case 'C': // Cddd glyph
  35092. case 'c': // cddd glyph
  35093. if (glyphName.length >= 3) {
  35094. code = +glyphName.substr(1);
  35095. }
  35096. break;
  35097. }
  35098. if (code) {
  35099. // If |baseEncodingName| is one the predefined encodings,
  35100. // and |code| equals |charcode|, using the glyph defined in the
  35101. // baseEncoding seems to yield a better |toUnicode| mapping
  35102. // (fixes issue 5070).
  35103. if (baseEncodingName && code === +charcode) {
  35104. var baseEncoding = Encodings[baseEncodingName];
  35105. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  35106. toUnicode[charcode] =
  35107. String.fromCharCode(GlyphsUnicode[glyphName]);
  35108. continue;
  35109. }
  35110. }
  35111. toUnicode[charcode] = String.fromCharCode(code);
  35112. }
  35113. continue;
  35114. }
  35115. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  35116. }
  35117. return new ToUnicodeMap(toUnicode);
  35118. }
  35119. // If the font is a composite font that uses one of the predefined CMaps
  35120. // listed in Table 118 (except Identity–H and Identity–V) or whose
  35121. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  35122. // Adobe-Korea1 character collection:
  35123. if (properties.composite && (
  35124. (properties.cMap.builtInCMap &&
  35125. !(properties.cMap instanceof IdentityCMap)) ||
  35126. (properties.cidSystemInfo.registry === 'Adobe' &&
  35127. (properties.cidSystemInfo.ordering === 'GB1' ||
  35128. properties.cidSystemInfo.ordering === 'CNS1' ||
  35129. properties.cidSystemInfo.ordering === 'Japan1' ||
  35130. properties.cidSystemInfo.ordering === 'Korea1')))) {
  35131. // Then:
  35132. // a) Map the character code to a character identifier (CID) according
  35133. // to the font’s CMap.
  35134. // b) Obtain the registry and ordering of the character collection used
  35135. // by the font’s CMap (for example, Adobe and Japan1) from its
  35136. // CIDSystemInfo dictionary.
  35137. var registry = properties.cidSystemInfo.registry;
  35138. var ordering = properties.cidSystemInfo.ordering;
  35139. // c) Construct a second CMap name by concatenating the registry and
  35140. // ordering obtained in step (b) in the format registry–ordering–UCS2
  35141. // (for example, Adobe–Japan1–UCS2).
  35142. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  35143. // d) Obtain the CMap with the name constructed in step (c) (available
  35144. // from the ASN Web site; see the Bibliography).
  35145. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  35146. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35147. var cMap = properties.cMap;
  35148. toUnicode = [];
  35149. cMap.forEach(function(charcode, cid) {
  35150. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  35151. // e) Map the CID obtained in step (a) according to the CMap obtained
  35152. // in step (d), producing a Unicode value.
  35153. var ucs2 = ucs2CMap.lookup(cid);
  35154. if (ucs2) {
  35155. toUnicode[charcode] =
  35156. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  35157. ucs2.charCodeAt(1));
  35158. }
  35159. });
  35160. return new ToUnicodeMap(toUnicode);
  35161. }
  35162. // The viewer's choice, just use an identity map.
  35163. return new IdentityToUnicodeMap(properties.firstChar,
  35164. properties.lastChar);
  35165. },
  35166. get spaceWidth() {
  35167. if ('_shadowWidth' in this) {
  35168. return this._shadowWidth;
  35169. }
  35170. // trying to estimate space character width
  35171. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  35172. var width;
  35173. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  35174. var glyphName = possibleSpaceReplacements[i];
  35175. // if possible, getting width by glyph name
  35176. if (glyphName in this.widths) {
  35177. width = this.widths[glyphName];
  35178. break;
  35179. }
  35180. var glyphUnicode = GlyphsUnicode[glyphName];
  35181. // finding the charcode via unicodeToCID map
  35182. var charcode = 0;
  35183. if (this.composite) {
  35184. if (this.cMap.contains(glyphUnicode)) {
  35185. charcode = this.cMap.lookup(glyphUnicode);
  35186. }
  35187. }
  35188. // ... via toUnicode map
  35189. if (!charcode && this.toUnicode) {
  35190. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  35191. }
  35192. // setting it to unicode if negative or undefined
  35193. if (charcode <= 0) {
  35194. charcode = glyphUnicode;
  35195. }
  35196. // trying to get width via charcode
  35197. width = this.widths[charcode];
  35198. if (width) {
  35199. break; // the non-zero width found
  35200. }
  35201. }
  35202. width = width || this.defaultWidth;
  35203. // Do not shadow the property here. See discussion:
  35204. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  35205. this._shadowWidth = width;
  35206. return width;
  35207. },
  35208. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  35209. var fontCharCode, width, operatorListId;
  35210. var widthCode = charcode;
  35211. if (this.cMap && this.cMap.contains(charcode)) {
  35212. widthCode = this.cMap.lookup(charcode);
  35213. }
  35214. width = this.widths[widthCode];
  35215. width = isNum(width) ? width : this.defaultWidth;
  35216. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  35217. var unicode = this.toUnicode.get(charcode) || charcode;
  35218. if (typeof unicode === 'number') {
  35219. unicode = String.fromCharCode(unicode);
  35220. }
  35221. // First try the toFontChar map, if it's not there then try falling
  35222. // back to the char code.
  35223. fontCharCode = this.toFontChar[charcode] || charcode;
  35224. if (this.missingFile) {
  35225. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  35226. }
  35227. if (this.isType3Font) {
  35228. // Font char code in this case is actually a glyph name.
  35229. operatorListId = fontCharCode;
  35230. }
  35231. var accent = null;
  35232. if (this.seacMap && this.seacMap[charcode]) {
  35233. var seac = this.seacMap[charcode];
  35234. fontCharCode = seac.baseFontCharCode;
  35235. accent = {
  35236. fontChar: String.fromCharCode(seac.accentFontCharCode),
  35237. offset: seac.accentOffset
  35238. };
  35239. }
  35240. var fontChar = String.fromCharCode(fontCharCode);
  35241. var glyph = this.glyphCache[charcode];
  35242. if (!glyph ||
  35243. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  35244. operatorListId, isSpace)) {
  35245. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  35246. operatorListId, isSpace);
  35247. this.glyphCache[charcode] = glyph;
  35248. }
  35249. return glyph;
  35250. },
  35251. charsToGlyphs: function Font_charsToGlyphs(chars) {
  35252. var charsCache = this.charsCache;
  35253. var glyphs, glyph, charcode;
  35254. // if we translated this string before, just grab it from the cache
  35255. if (charsCache) {
  35256. glyphs = charsCache[chars];
  35257. if (glyphs) {
  35258. return glyphs;
  35259. }
  35260. }
  35261. // lazily create the translation cache
  35262. if (!charsCache) {
  35263. charsCache = this.charsCache = Object.create(null);
  35264. }
  35265. glyphs = [];
  35266. var charsCacheKey = chars;
  35267. var i = 0, ii;
  35268. if (this.cMap) {
  35269. // composite fonts have multi-byte strings convert the string from
  35270. // single-byte to multi-byte
  35271. var c = {};
  35272. while (i < chars.length) {
  35273. this.cMap.readCharCode(chars, i, c);
  35274. charcode = c.charcode;
  35275. var length = c.length;
  35276. i += length;
  35277. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  35278. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  35279. glyph = this.charToGlyph(charcode, isSpace);
  35280. glyphs.push(glyph);
  35281. }
  35282. } else {
  35283. for (i = 0, ii = chars.length; i < ii; ++i) {
  35284. charcode = chars.charCodeAt(i);
  35285. glyph = this.charToGlyph(charcode, charcode === 0x20);
  35286. glyphs.push(glyph);
  35287. }
  35288. }
  35289. // Enter the translated string into the cache
  35290. return (charsCache[charsCacheKey] = glyphs);
  35291. }
  35292. };
  35293. return Font;
  35294. })();
  35295. var ErrorFont = (function ErrorFontClosure() {
  35296. function ErrorFont(error) {
  35297. this.error = error;
  35298. this.loadedName = 'g_font_error';
  35299. this.loading = false;
  35300. }
  35301. ErrorFont.prototype = {
  35302. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  35303. return [];
  35304. },
  35305. exportData: function ErrorFont_exportData() {
  35306. return {error: this.error};
  35307. }
  35308. };
  35309. return ErrorFont;
  35310. })();
  35311. /**
  35312. * Shared logic for building a char code to glyph id mapping for Type1 and
  35313. * simple CFF fonts. See section 9.6.6.2 of the spec.
  35314. * @param {Object} properties Font properties object.
  35315. * @param {Object} builtInEncoding The encoding contained within the actual font
  35316. * data.
  35317. * @param {Array} Array of glyph names where the index is the glyph ID.
  35318. * @returns {Object} A char code to glyph ID map.
  35319. */
  35320. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  35321. var charCodeToGlyphId = Object.create(null);
  35322. var glyphId, charCode, baseEncoding;
  35323. if (properties.baseEncodingName) {
  35324. // If a valid base encoding name was used, the mapping is initialized with
  35325. // that.
  35326. baseEncoding = Encodings[properties.baseEncodingName];
  35327. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  35328. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  35329. if (glyphId >= 0) {
  35330. charCodeToGlyphId[charCode] = glyphId;
  35331. } else {
  35332. charCodeToGlyphId[charCode] = 0; // notdef
  35333. }
  35334. }
  35335. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  35336. // For a symbolic font the encoding should be the fonts built-in
  35337. // encoding.
  35338. for (charCode in builtInEncoding) {
  35339. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  35340. }
  35341. } else {
  35342. // For non-symbolic fonts that don't have a base encoding the standard
  35343. // encoding should be used.
  35344. baseEncoding = Encodings.StandardEncoding;
  35345. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  35346. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  35347. if (glyphId >= 0) {
  35348. charCodeToGlyphId[charCode] = glyphId;
  35349. } else {
  35350. charCodeToGlyphId[charCode] = 0; // notdef
  35351. }
  35352. }
  35353. }
  35354. // Lastly, merge in the differences.
  35355. var differences = properties.differences;
  35356. if (differences) {
  35357. for (charCode in differences) {
  35358. var glyphName = differences[charCode];
  35359. glyphId = glyphNames.indexOf(glyphName);
  35360. if (glyphId >= 0) {
  35361. charCodeToGlyphId[charCode] = glyphId;
  35362. } else {
  35363. charCodeToGlyphId[charCode] = 0; // notdef
  35364. }
  35365. }
  35366. }
  35367. return charCodeToGlyphId;
  35368. }
  35369. /*
  35370. * CharStrings are encoded following the the CharString Encoding sequence
  35371. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  35372. * The value in a byte indicates a command, a number, or subsequent bytes
  35373. * that are to be interpreted in a special way.
  35374. *
  35375. * CharString Number Encoding:
  35376. * A CharString byte containing the values from 32 through 255 inclusive
  35377. * indicate an integer. These values are decoded in four ranges.
  35378. *
  35379. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  35380. * indicate the integer v - 139. Thus, the integer values from -107 through
  35381. * 107 inclusive may be encoded in single byte.
  35382. *
  35383. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  35384. * indicates an integer involving the next byte, w, according to the formula:
  35385. * [(v - 247) x 256] + w + 108
  35386. *
  35387. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  35388. * indicates an integer involving the next byte, w, according to the formula:
  35389. * -[(v - 251) * 256] - w - 108
  35390. *
  35391. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  35392. * are a two complement signed integer. The first of these bytes contains the
  35393. * highest order bits, the second byte contains the next higher order bits
  35394. * and the fourth byte contain the lowest order bits.
  35395. *
  35396. *
  35397. * CharString Command Encoding:
  35398. * CharStrings commands are encoded in 1 or 2 bytes.
  35399. *
  35400. * Single byte commands are encoded in 1 byte that contains a value between
  35401. * 0 and 31 inclusive.
  35402. * If a command byte contains the value 12, then the value in the next byte
  35403. * indicates a command. This "escape" mechanism allows many extra commands
  35404. * to be encoded and this encoding technique helps to minimize the length of
  35405. * the charStrings.
  35406. */
  35407. var Type1CharString = (function Type1CharStringClosure() {
  35408. var COMMAND_MAP = {
  35409. 'hstem': [1],
  35410. 'vstem': [3],
  35411. 'vmoveto': [4],
  35412. 'rlineto': [5],
  35413. 'hlineto': [6],
  35414. 'vlineto': [7],
  35415. 'rrcurveto': [8],
  35416. 'callsubr': [10],
  35417. 'flex': [12, 35],
  35418. 'drop' : [12, 18],
  35419. 'endchar': [14],
  35420. 'rmoveto': [21],
  35421. 'hmoveto': [22],
  35422. 'vhcurveto': [30],
  35423. 'hvcurveto': [31]
  35424. };
  35425. function Type1CharString() {
  35426. this.width = 0;
  35427. this.lsb = 0;
  35428. this.flexing = false;
  35429. this.output = [];
  35430. this.stack = [];
  35431. }
  35432. Type1CharString.prototype = {
  35433. convert: function Type1CharString_convert(encoded, subrs) {
  35434. var count = encoded.length;
  35435. var error = false;
  35436. var wx, sbx, subrNumber;
  35437. for (var i = 0; i < count; i++) {
  35438. var value = encoded[i];
  35439. if (value < 32) {
  35440. if (value === 12) {
  35441. value = (value << 8) + encoded[++i];
  35442. }
  35443. switch (value) {
  35444. case 1: // hstem
  35445. if (!HINTING_ENABLED) {
  35446. this.stack = [];
  35447. break;
  35448. }
  35449. error = this.executeCommand(2, COMMAND_MAP.hstem);
  35450. break;
  35451. case 3: // vstem
  35452. if (!HINTING_ENABLED) {
  35453. this.stack = [];
  35454. break;
  35455. }
  35456. error = this.executeCommand(2, COMMAND_MAP.vstem);
  35457. break;
  35458. case 4: // vmoveto
  35459. if (this.flexing) {
  35460. if (this.stack.length < 1) {
  35461. error = true;
  35462. break;
  35463. }
  35464. // Add the dx for flex and but also swap the values so they are
  35465. // the right order.
  35466. var dy = this.stack.pop();
  35467. this.stack.push(0, dy);
  35468. break;
  35469. }
  35470. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  35471. break;
  35472. case 5: // rlineto
  35473. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  35474. break;
  35475. case 6: // hlineto
  35476. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  35477. break;
  35478. case 7: // vlineto
  35479. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  35480. break;
  35481. case 8: // rrcurveto
  35482. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  35483. break;
  35484. case 9: // closepath
  35485. // closepath is a Type1 command that does not take argument and is
  35486. // useless in Type2 and it can simply be ignored.
  35487. this.stack = [];
  35488. break;
  35489. case 10: // callsubr
  35490. if (this.stack.length < 1) {
  35491. error = true;
  35492. break;
  35493. }
  35494. subrNumber = this.stack.pop();
  35495. error = this.convert(subrs[subrNumber], subrs);
  35496. break;
  35497. case 11: // return
  35498. return error;
  35499. case 13: // hsbw
  35500. if (this.stack.length < 2) {
  35501. error = true;
  35502. break;
  35503. }
  35504. // To convert to type2 we have to move the width value to the
  35505. // first part of the charstring and then use hmoveto with lsb.
  35506. wx = this.stack.pop();
  35507. sbx = this.stack.pop();
  35508. this.lsb = sbx;
  35509. this.width = wx;
  35510. this.stack.push(wx, sbx);
  35511. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  35512. break;
  35513. case 14: // endchar
  35514. this.output.push(COMMAND_MAP.endchar[0]);
  35515. break;
  35516. case 21: // rmoveto
  35517. if (this.flexing) {
  35518. break;
  35519. }
  35520. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  35521. break;
  35522. case 22: // hmoveto
  35523. if (this.flexing) {
  35524. // Add the dy for flex.
  35525. this.stack.push(0);
  35526. break;
  35527. }
  35528. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  35529. break;
  35530. case 30: // vhcurveto
  35531. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  35532. break;
  35533. case 31: // hvcurveto
  35534. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  35535. break;
  35536. case (12 << 8) + 0: // dotsection
  35537. // dotsection is a Type1 command to specify some hinting feature
  35538. // for dots that do not take a parameter and it can safely be
  35539. // ignored for Type2.
  35540. this.stack = [];
  35541. break;
  35542. case (12 << 8) + 1: // vstem3
  35543. if (!HINTING_ENABLED) {
  35544. this.stack = [];
  35545. break;
  35546. }
  35547. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  35548. // multiple parameters, so instead of returning [vh]stem3 take a
  35549. // shortcut and return [vhstem] instead.
  35550. error = this.executeCommand(2, COMMAND_MAP.vstem);
  35551. break;
  35552. case (12 << 8) + 2: // hstem3
  35553. if (!HINTING_ENABLED) {
  35554. this.stack = [];
  35555. break;
  35556. }
  35557. // See vstem3.
  35558. error = this.executeCommand(2, COMMAND_MAP.hstem);
  35559. break;
  35560. case (12 << 8) + 6: // seac
  35561. // seac is like type 2's special endchar but it doesn't use the
  35562. // first argument asb, so remove it.
  35563. if (SEAC_ANALYSIS_ENABLED) {
  35564. this.seac = this.stack.splice(-4, 4);
  35565. error = this.executeCommand(0, COMMAND_MAP.endchar);
  35566. } else {
  35567. error = this.executeCommand(4, COMMAND_MAP.endchar);
  35568. }
  35569. break;
  35570. case (12 << 8) + 7: // sbw
  35571. if (this.stack.length < 4) {
  35572. error = true;
  35573. break;
  35574. }
  35575. // To convert to type2 we have to move the width value to the
  35576. // first part of the charstring and then use rmoveto with
  35577. // (dx, dy). The height argument will not be used for vmtx and
  35578. // vhea tables reconstruction -- ignoring it.
  35579. var wy = this.stack.pop();
  35580. wx = this.stack.pop();
  35581. var sby = this.stack.pop();
  35582. sbx = this.stack.pop();
  35583. this.lsb = sbx;
  35584. this.width = wx;
  35585. this.stack.push(wx, sbx, sby);
  35586. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  35587. break;
  35588. case (12 << 8) + 12: // div
  35589. if (this.stack.length < 2) {
  35590. error = true;
  35591. break;
  35592. }
  35593. var num2 = this.stack.pop();
  35594. var num1 = this.stack.pop();
  35595. this.stack.push(num1 / num2);
  35596. break;
  35597. case (12 << 8) + 16: // callothersubr
  35598. if (this.stack.length < 2) {
  35599. error = true;
  35600. break;
  35601. }
  35602. subrNumber = this.stack.pop();
  35603. var numArgs = this.stack.pop();
  35604. if (subrNumber === 0 && numArgs === 3) {
  35605. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  35606. this.stack.push(
  35607. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  35608. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  35609. flexArgs[4], // bcp2x
  35610. flexArgs[5], // bcp2y
  35611. flexArgs[6], // p2x
  35612. flexArgs[7], // p2y
  35613. flexArgs[8], // bcp3x
  35614. flexArgs[9], // bcp3y
  35615. flexArgs[10], // bcp4x
  35616. flexArgs[11], // bcp4y
  35617. flexArgs[12], // p3x
  35618. flexArgs[13], // p3y
  35619. flexArgs[14] // flexDepth
  35620. // 15 = finalx unused by flex
  35621. // 16 = finaly unused by flex
  35622. );
  35623. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  35624. this.flexing = false;
  35625. this.stack.push(flexArgs[15], flexArgs[16]);
  35626. } else if (subrNumber === 1 && numArgs === 0) {
  35627. this.flexing = true;
  35628. }
  35629. break;
  35630. case (12 << 8) + 17: // pop
  35631. // Ignore this since it is only used with othersubr.
  35632. break;
  35633. case (12 << 8) + 33: // setcurrentpoint
  35634. // Ignore for now.
  35635. this.stack = [];
  35636. break;
  35637. default:
  35638. warn('Unknown type 1 charstring command of "' + value + '"');
  35639. break;
  35640. }
  35641. if (error) {
  35642. break;
  35643. }
  35644. continue;
  35645. } else if (value <= 246) {
  35646. value = value - 139;
  35647. } else if (value <= 250) {
  35648. value = ((value - 247) * 256) + encoded[++i] + 108;
  35649. } else if (value <= 254) {
  35650. value = -((value - 251) * 256) - encoded[++i] - 108;
  35651. } else {
  35652. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  35653. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  35654. }
  35655. this.stack.push(value);
  35656. }
  35657. return error;
  35658. },
  35659. executeCommand: function(howManyArgs, command, keepStack) {
  35660. var stackLength = this.stack.length;
  35661. if (howManyArgs > stackLength) {
  35662. return true;
  35663. }
  35664. var start = stackLength - howManyArgs;
  35665. for (var i = start; i < stackLength; i++) {
  35666. var value = this.stack[i];
  35667. if (value === (value | 0)) { // int
  35668. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  35669. } else { // fixed point
  35670. value = (65536 * value) | 0;
  35671. this.output.push(255,
  35672. (value >> 24) & 0xFF,
  35673. (value >> 16) & 0xFF,
  35674. (value >> 8) & 0xFF,
  35675. value & 0xFF);
  35676. }
  35677. }
  35678. this.output.push.apply(this.output, command);
  35679. if (keepStack) {
  35680. this.stack.splice(start, howManyArgs);
  35681. } else {
  35682. this.stack.length = 0;
  35683. }
  35684. return false;
  35685. }
  35686. };
  35687. return Type1CharString;
  35688. })();
  35689. /*
  35690. * Type1Parser encapsulate the needed code for parsing a Type1 font
  35691. * program. Some of its logic depends on the Type2 charstrings
  35692. * structure.
  35693. * Note: this doesn't really parse the font since that would require evaluation
  35694. * of PostScript, but it is possible in most cases to extract what we need
  35695. * without a full parse.
  35696. */
  35697. var Type1Parser = (function Type1ParserClosure() {
  35698. /*
  35699. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  35700. * of Plaintext Bytes. The function took a key as a parameter which can be
  35701. * for decrypting the eexec block of for decoding charStrings.
  35702. */
  35703. var EEXEC_ENCRYPT_KEY = 55665;
  35704. var CHAR_STRS_ENCRYPT_KEY = 4330;
  35705. function isHexDigit(code) {
  35706. return code >= 48 && code <= 57 || // '0'-'9'
  35707. code >= 65 && code <= 70 || // 'A'-'F'
  35708. code >= 97 && code <= 102; // 'a'-'f'
  35709. }
  35710. function decrypt(data, key, discardNumber) {
  35711. var r = key | 0, c1 = 52845, c2 = 22719;
  35712. var count = data.length;
  35713. var decrypted = new Uint8Array(count);
  35714. for (var i = 0; i < count; i++) {
  35715. var value = data[i];
  35716. decrypted[i] = value ^ (r >> 8);
  35717. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  35718. }
  35719. return Array.prototype.slice.call(decrypted, discardNumber);
  35720. }
  35721. function decryptAscii(data, key, discardNumber) {
  35722. var r = key | 0, c1 = 52845, c2 = 22719;
  35723. var count = data.length, maybeLength = count >>> 1;
  35724. var decrypted = new Uint8Array(maybeLength);
  35725. var i, j;
  35726. for (i = 0, j = 0; i < count; i++) {
  35727. var digit1 = data[i];
  35728. if (!isHexDigit(digit1)) {
  35729. continue;
  35730. }
  35731. i++;
  35732. var digit2;
  35733. while (i < count && !isHexDigit(digit2 = data[i])) {
  35734. i++;
  35735. }
  35736. if (i < count) {
  35737. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  35738. decrypted[j++] = value ^ (r >> 8);
  35739. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  35740. }
  35741. }
  35742. return Array.prototype.slice.call(decrypted, discardNumber, j);
  35743. }
  35744. function isSpecial(c) {
  35745. return c === 0x2F || // '/'
  35746. c === 0x5B || c === 0x5D || // '[', ']'
  35747. c === 0x7B || c === 0x7D || // '{', '}'
  35748. c === 0x28 || c === 0x29; // '(', ')'
  35749. }
  35750. function Type1Parser(stream, encrypted) {
  35751. if (encrypted) {
  35752. var data = stream.getBytes();
  35753. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  35754. isHexDigit(data[2]) && isHexDigit(data[3]));
  35755. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  35756. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  35757. }
  35758. this.stream = stream;
  35759. this.nextChar();
  35760. }
  35761. Type1Parser.prototype = {
  35762. readNumberArray: function Type1Parser_readNumberArray() {
  35763. this.getToken(); // read '[' or '{' (arrays can start with either)
  35764. var array = [];
  35765. while (true) {
  35766. var token = this.getToken();
  35767. if (token === null || token === ']' || token === '}') {
  35768. break;
  35769. }
  35770. array.push(parseFloat(token || 0));
  35771. }
  35772. return array;
  35773. },
  35774. readNumber: function Type1Parser_readNumber() {
  35775. var token = this.getToken();
  35776. return parseFloat(token || 0);
  35777. },
  35778. readInt: function Type1Parser_readInt() {
  35779. // Use '| 0' to prevent setting a double into length such as the double
  35780. // does not flow into the loop variable.
  35781. var token = this.getToken();
  35782. return parseInt(token || 0, 10) | 0;
  35783. },
  35784. readBoolean: function Type1Parser_readBoolean() {
  35785. var token = this.getToken();
  35786. // Use 1 and 0 since that's what type2 charstrings use.
  35787. return token === 'true' ? 1 : 0;
  35788. },
  35789. nextChar : function Type1_nextChar() {
  35790. return (this.currentChar = this.stream.getByte());
  35791. },
  35792. getToken: function Type1Parser_getToken() {
  35793. // Eat whitespace and comments.
  35794. var comment = false;
  35795. var ch = this.currentChar;
  35796. while (true) {
  35797. if (ch === -1) {
  35798. return null;
  35799. }
  35800. if (comment) {
  35801. if (ch === 0x0A || ch === 0x0D) {
  35802. comment = false;
  35803. }
  35804. } else if (ch === 0x25) { // '%'
  35805. comment = true;
  35806. } else if (!Lexer.isSpace(ch)) {
  35807. break;
  35808. }
  35809. ch = this.nextChar();
  35810. }
  35811. if (isSpecial(ch)) {
  35812. this.nextChar();
  35813. return String.fromCharCode(ch);
  35814. }
  35815. var token = '';
  35816. do {
  35817. token += String.fromCharCode(ch);
  35818. ch = this.nextChar();
  35819. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  35820. return token;
  35821. },
  35822. /*
  35823. * Returns an object containing a Subrs array and a CharStrings
  35824. * array extracted from and eexec encrypted block of data
  35825. */
  35826. extractFontProgram: function Type1Parser_extractFontProgram() {
  35827. var stream = this.stream;
  35828. var subrs = [], charstrings = [];
  35829. var program = {
  35830. subrs: [],
  35831. charstrings: [],
  35832. properties: {
  35833. 'privateData': {
  35834. 'lenIV': 4
  35835. }
  35836. }
  35837. };
  35838. var token, length, data, lenIV, encoded;
  35839. while ((token = this.getToken()) !== null) {
  35840. if (token !== '/') {
  35841. continue;
  35842. }
  35843. token = this.getToken();
  35844. switch (token) {
  35845. case 'CharStrings':
  35846. // The number immediately following CharStrings must be greater or
  35847. // equal to the number of CharStrings.
  35848. this.getToken();
  35849. this.getToken(); // read in 'dict'
  35850. this.getToken(); // read in 'dup'
  35851. this.getToken(); // read in 'begin'
  35852. while(true) {
  35853. token = this.getToken();
  35854. if (token === null || token === 'end') {
  35855. break;
  35856. }
  35857. if (token !== '/') {
  35858. continue;
  35859. }
  35860. var glyph = this.getToken();
  35861. length = this.readInt();
  35862. this.getToken(); // read in 'RD' or '-|'
  35863. data = stream.makeSubStream(stream.pos, length);
  35864. lenIV = program.properties.privateData['lenIV'];
  35865. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35866. // Skip past the required space and binary data.
  35867. stream.skip(length);
  35868. this.nextChar();
  35869. token = this.getToken(); // read in 'ND' or '|-'
  35870. if (token === 'noaccess') {
  35871. this.getToken(); // read in 'def'
  35872. }
  35873. charstrings.push({
  35874. glyph: glyph,
  35875. encoded: encoded
  35876. });
  35877. }
  35878. break;
  35879. case 'Subrs':
  35880. var num = this.readInt();
  35881. this.getToken(); // read in 'array'
  35882. while ((token = this.getToken()) === 'dup') {
  35883. var index = this.readInt();
  35884. length = this.readInt();
  35885. this.getToken(); // read in 'RD' or '-|'
  35886. data = stream.makeSubStream(stream.pos, length);
  35887. lenIV = program.properties.privateData['lenIV'];
  35888. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35889. // Skip past the required space and binary data.
  35890. stream.skip(length);
  35891. this.nextChar();
  35892. token = this.getToken(); // read in 'NP' or '|'
  35893. if (token === 'noaccess') {
  35894. this.getToken(); // read in 'put'
  35895. }
  35896. subrs[index] = encoded;
  35897. }
  35898. break;
  35899. case 'BlueValues':
  35900. case 'OtherBlues':
  35901. case 'FamilyBlues':
  35902. case 'FamilyOtherBlues':
  35903. var blueArray = this.readNumberArray();
  35904. // *Blue* values may contain invalid data: disables reading of
  35905. // those values when hinting is disabled.
  35906. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  35907. HINTING_ENABLED) {
  35908. program.properties.privateData[token] = blueArray;
  35909. }
  35910. break;
  35911. case 'StemSnapH':
  35912. case 'StemSnapV':
  35913. program.properties.privateData[token] = this.readNumberArray();
  35914. break;
  35915. case 'StdHW':
  35916. case 'StdVW':
  35917. program.properties.privateData[token] =
  35918. this.readNumberArray()[0];
  35919. break;
  35920. case 'BlueShift':
  35921. case 'lenIV':
  35922. case 'BlueFuzz':
  35923. case 'BlueScale':
  35924. case 'LanguageGroup':
  35925. case 'ExpansionFactor':
  35926. program.properties.privateData[token] = this.readNumber();
  35927. break;
  35928. case 'ForceBold':
  35929. program.properties.privateData[token] = this.readBoolean();
  35930. break;
  35931. }
  35932. }
  35933. for (var i = 0; i < charstrings.length; i++) {
  35934. glyph = charstrings[i].glyph;
  35935. encoded = charstrings[i].encoded;
  35936. var charString = new Type1CharString();
  35937. var error = charString.convert(encoded, subrs);
  35938. var output = charString.output;
  35939. if (error) {
  35940. // It seems when FreeType encounters an error while evaluating a glyph
  35941. // that it completely ignores the glyph so we'll mimic that behaviour
  35942. // here and put an endchar to make the validator happy.
  35943. output = [14];
  35944. }
  35945. program.charstrings.push({
  35946. glyphName: glyph,
  35947. charstring: output,
  35948. width: charString.width,
  35949. lsb: charString.lsb,
  35950. seac: charString.seac
  35951. });
  35952. }
  35953. return program;
  35954. },
  35955. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  35956. var token;
  35957. while ((token = this.getToken()) !== null) {
  35958. if (token !== '/') {
  35959. continue;
  35960. }
  35961. token = this.getToken();
  35962. switch (token) {
  35963. case 'FontMatrix':
  35964. var matrix = this.readNumberArray();
  35965. properties.fontMatrix = matrix;
  35966. break;
  35967. case 'Encoding':
  35968. var encodingArg = this.getToken();
  35969. var encoding;
  35970. if (!/^\d+$/.test(encodingArg)) {
  35971. // encoding name is specified
  35972. encoding = Encodings[encodingArg];
  35973. } else {
  35974. encoding = [];
  35975. var size = parseInt(encodingArg, 10) | 0;
  35976. this.getToken(); // read in 'array'
  35977. for (var j = 0; j < size; j++) {
  35978. token = this.getToken();
  35979. // skipping till first dup or def (e.g. ignoring for statement)
  35980. while (token !== 'dup' && token !== 'def') {
  35981. token = this.getToken();
  35982. if (token === null) {
  35983. return; // invalid header
  35984. }
  35985. }
  35986. if (token === 'def') {
  35987. break; // read all array data
  35988. }
  35989. var index = this.readInt();
  35990. this.getToken(); // read in '/'
  35991. var glyph = this.getToken();
  35992. encoding[index] = glyph;
  35993. this.getToken(); // read the in 'put'
  35994. }
  35995. }
  35996. properties.builtInEncoding = encoding;
  35997. break;
  35998. case 'FontBBox':
  35999. var fontBBox = this.readNumberArray();
  36000. // adjusting ascent/descent
  36001. properties.ascent = fontBBox[3];
  36002. properties.descent = fontBBox[1];
  36003. properties.ascentScaled = true;
  36004. break;
  36005. }
  36006. }
  36007. }
  36008. };
  36009. return Type1Parser;
  36010. })();
  36011. /**
  36012. * The CFF class takes a Type1 file and wrap it into a
  36013. * 'Compact Font Format' which itself embed Type2 charstrings.
  36014. */
  36015. var CFFStandardStrings = [
  36016. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  36017. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  36018. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  36019. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  36020. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  36021. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  36022. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  36023. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  36024. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  36025. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  36026. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  36027. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  36028. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  36029. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  36030. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  36031. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  36032. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  36033. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  36034. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  36035. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  36036. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  36037. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  36038. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  36039. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  36040. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  36041. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  36042. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  36043. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  36044. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  36045. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  36046. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  36047. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  36048. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  36049. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  36050. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  36051. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  36052. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  36053. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  36054. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  36055. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  36056. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  36057. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  36058. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  36059. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  36060. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  36061. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  36062. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  36063. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  36064. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  36065. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  36066. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  36067. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  36068. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  36069. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  36070. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  36071. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  36072. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  36073. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  36074. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  36075. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  36076. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  36077. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  36078. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  36079. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  36080. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  36081. ];
  36082. // Type1Font is also a CIDFontType0.
  36083. var Type1Font = function Type1Font(name, file, properties) {
  36084. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  36085. // Also, length1 and length2 might be off by 6 bytes as well.
  36086. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  36087. var PFB_HEADER_SIZE = 6;
  36088. var headerBlockLength = properties.length1;
  36089. var eexecBlockLength = properties.length2;
  36090. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  36091. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  36092. if (pfbHeaderPresent) {
  36093. file.skip(PFB_HEADER_SIZE);
  36094. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  36095. (pfbHeader[3] << 8) | pfbHeader[2];
  36096. }
  36097. // Get the data block containing glyphs and subrs informations
  36098. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  36099. var headerBlockParser = new Type1Parser(headerBlock);
  36100. headerBlockParser.extractFontHeader(properties);
  36101. if (pfbHeaderPresent) {
  36102. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  36103. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  36104. (pfbHeader[3] << 8) | pfbHeader[2];
  36105. }
  36106. // Decrypt the data blocks and retrieve it's content
  36107. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  36108. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  36109. var data = eexecBlockParser.extractFontProgram();
  36110. for (var info in data.properties) {
  36111. properties[info] = data.properties[info];
  36112. }
  36113. var charstrings = data.charstrings;
  36114. var type2Charstrings = this.getType2Charstrings(charstrings);
  36115. var subrs = this.getType2Subrs(data.subrs);
  36116. this.charstrings = charstrings;
  36117. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  36118. subrs, properties);
  36119. this.seacs = this.getSeacs(data.charstrings);
  36120. };
  36121. Type1Font.prototype = {
  36122. get numGlyphs() {
  36123. return this.charstrings.length + 1;
  36124. },
  36125. getCharset: function Type1Font_getCharset() {
  36126. var charset = ['.notdef'];
  36127. var charstrings = this.charstrings;
  36128. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  36129. charset.push(charstrings[glyphId].glyphName);
  36130. }
  36131. return charset;
  36132. },
  36133. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  36134. var charstrings = this.charstrings;
  36135. var glyphNames = ['.notdef'], glyphId;
  36136. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  36137. glyphNames.push(charstrings[glyphId].glyphName);
  36138. }
  36139. var encoding = properties.builtInEncoding;
  36140. if (encoding) {
  36141. var builtInEncoding = {};
  36142. for (var charCode in encoding) {
  36143. glyphId = glyphNames.indexOf(encoding[charCode]);
  36144. if (glyphId >= 0) {
  36145. builtInEncoding[charCode] = glyphId;
  36146. }
  36147. }
  36148. }
  36149. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  36150. },
  36151. getSeacs: function Type1Font_getSeacs(charstrings) {
  36152. var i, ii;
  36153. var seacMap = [];
  36154. for (i = 0, ii = charstrings.length; i < ii; i++) {
  36155. var charstring = charstrings[i];
  36156. if (charstring.seac) {
  36157. // Offset by 1 for .notdef
  36158. seacMap[i + 1] = charstring.seac;
  36159. }
  36160. }
  36161. return seacMap;
  36162. },
  36163. getType2Charstrings: function Type1Font_getType2Charstrings(
  36164. type1Charstrings) {
  36165. var type2Charstrings = [];
  36166. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  36167. type2Charstrings.push(type1Charstrings[i].charstring);
  36168. }
  36169. return type2Charstrings;
  36170. },
  36171. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  36172. var bias = 0;
  36173. var count = type1Subrs.length;
  36174. if (count < 1133) {
  36175. bias = 107;
  36176. } else if (count < 33769) {
  36177. bias = 1131;
  36178. } else {
  36179. bias = 32768;
  36180. }
  36181. // Add a bunch of empty subrs to deal with the Type2 bias
  36182. var type2Subrs = [];
  36183. var i;
  36184. for (i = 0; i < bias; i++) {
  36185. type2Subrs.push([0x0B]);
  36186. }
  36187. for (i = 0; i < count; i++) {
  36188. type2Subrs.push(type1Subrs[i]);
  36189. }
  36190. return type2Subrs;
  36191. },
  36192. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  36193. var cff = new CFF();
  36194. cff.header = new CFFHeader(1, 0, 4, 4);
  36195. cff.names = [name];
  36196. var topDict = new CFFTopDict();
  36197. // CFF strings IDs 0...390 are predefined names, so refering
  36198. // to entries in our own String INDEX starts at SID 391.
  36199. topDict.setByName('version', 391);
  36200. topDict.setByName('Notice', 392);
  36201. topDict.setByName('FullName', 393);
  36202. topDict.setByName('FamilyName', 394);
  36203. topDict.setByName('Weight', 395);
  36204. topDict.setByName('Encoding', null); // placeholder
  36205. topDict.setByName('FontMatrix', properties.fontMatrix);
  36206. topDict.setByName('FontBBox', properties.bbox);
  36207. topDict.setByName('charset', null); // placeholder
  36208. topDict.setByName('CharStrings', null); // placeholder
  36209. topDict.setByName('Private', null); // placeholder
  36210. cff.topDict = topDict;
  36211. var strings = new CFFStrings();
  36212. strings.add('Version 0.11'); // Version
  36213. strings.add('See original notice'); // Notice
  36214. strings.add(name); // FullName
  36215. strings.add(name); // FamilyName
  36216. strings.add('Medium'); // Weight
  36217. cff.strings = strings;
  36218. cff.globalSubrIndex = new CFFIndex();
  36219. var count = glyphs.length;
  36220. var charsetArray = [0];
  36221. var i, ii;
  36222. for (i = 0; i < count; i++) {
  36223. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  36224. // TODO: Insert the string and correctly map it. Previously it was
  36225. // thought mapping names that aren't in the standard strings to .notdef
  36226. // was fine, however in issue818 when mapping them all to .notdef the
  36227. // adieresis glyph no longer worked.
  36228. if (index === -1) {
  36229. index = 0;
  36230. }
  36231. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  36232. }
  36233. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  36234. var charStringsIndex = new CFFIndex();
  36235. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  36236. for (i = 0; i < count; i++) {
  36237. charStringsIndex.add(glyphs[i]);
  36238. }
  36239. cff.charStrings = charStringsIndex;
  36240. var privateDict = new CFFPrivateDict();
  36241. privateDict.setByName('Subrs', null); // placeholder
  36242. var fields = [
  36243. 'BlueValues',
  36244. 'OtherBlues',
  36245. 'FamilyBlues',
  36246. 'FamilyOtherBlues',
  36247. 'StemSnapH',
  36248. 'StemSnapV',
  36249. 'BlueShift',
  36250. 'BlueFuzz',
  36251. 'BlueScale',
  36252. 'LanguageGroup',
  36253. 'ExpansionFactor',
  36254. 'ForceBold',
  36255. 'StdHW',
  36256. 'StdVW'
  36257. ];
  36258. for (i = 0, ii = fields.length; i < ii; i++) {
  36259. var field = fields[i];
  36260. if (!properties.privateData.hasOwnProperty(field)) {
  36261. continue;
  36262. }
  36263. var value = properties.privateData[field];
  36264. if (isArray(value)) {
  36265. // All of the private dictionary array data in CFF must be stored as
  36266. // "delta-encoded" numbers.
  36267. for (var j = value.length - 1; j > 0; j--) {
  36268. value[j] -= value[j - 1]; // ... difference from previous value
  36269. }
  36270. }
  36271. privateDict.setByName(field, value);
  36272. }
  36273. cff.topDict.privateDict = privateDict;
  36274. var subrIndex = new CFFIndex();
  36275. for (i = 0, ii = subrs.length; i < ii; i++) {
  36276. subrIndex.add(subrs[i]);
  36277. }
  36278. privateDict.subrsIndex = subrIndex;
  36279. var compiler = new CFFCompiler(cff);
  36280. return compiler.compile();
  36281. }
  36282. };
  36283. var CFFFont = (function CFFFontClosure() {
  36284. function CFFFont(file, properties) {
  36285. this.properties = properties;
  36286. var parser = new CFFParser(file, properties);
  36287. this.cff = parser.parse();
  36288. var compiler = new CFFCompiler(this.cff);
  36289. this.seacs = this.cff.seacs;
  36290. try {
  36291. this.data = compiler.compile();
  36292. } catch (e) {
  36293. warn('Failed to compile font ' + properties.loadedName);
  36294. // There may have just been an issue with the compiler, set the data
  36295. // anyway and hope the font loaded.
  36296. this.data = file;
  36297. }
  36298. }
  36299. CFFFont.prototype = {
  36300. get numGlyphs() {
  36301. return this.cff.charStrings.count;
  36302. },
  36303. getCharset: function CFFFont_getCharset() {
  36304. return this.cff.charset.charset;
  36305. },
  36306. getGlyphMapping: function CFFFont_getGlyphMapping() {
  36307. var cff = this.cff;
  36308. var properties = this.properties;
  36309. var charsets = cff.charset.charset;
  36310. var charCodeToGlyphId;
  36311. var glyphId;
  36312. if (properties.composite) {
  36313. charCodeToGlyphId = Object.create(null);
  36314. if (cff.isCIDFont) {
  36315. // If the font is actually a CID font then we should use the charset
  36316. // to map CIDs to GIDs.
  36317. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  36318. var cid = charsets[glyphId];
  36319. var charCode = properties.cMap.charCodeOf(cid);
  36320. charCodeToGlyphId[charCode] = glyphId;
  36321. }
  36322. } else {
  36323. // If it is NOT actually a CID font then CIDs should be mapped
  36324. // directly to GIDs.
  36325. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  36326. charCodeToGlyphId[glyphId] = glyphId;
  36327. }
  36328. }
  36329. return charCodeToGlyphId;
  36330. }
  36331. var encoding = cff.encoding ? cff.encoding.encoding : null;
  36332. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  36333. return charCodeToGlyphId;
  36334. }
  36335. };
  36336. return CFFFont;
  36337. })();
  36338. var CFFParser = (function CFFParserClosure() {
  36339. var CharstringValidationData = [
  36340. null,
  36341. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  36342. null,
  36343. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  36344. { id: 'vmoveto', min: 1, stackClearing: true },
  36345. { id: 'rlineto', min: 2, resetStack: true },
  36346. { id: 'hlineto', min: 1, resetStack: true },
  36347. { id: 'vlineto', min: 1, resetStack: true },
  36348. { id: 'rrcurveto', min: 6, resetStack: true },
  36349. null,
  36350. { id: 'callsubr', min: 1, undefStack: true },
  36351. { id: 'return', min: 0, undefStack: true },
  36352. null, // 12
  36353. null,
  36354. { id: 'endchar', min: 0, stackClearing: true },
  36355. null,
  36356. null,
  36357. null,
  36358. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  36359. { id: 'hintmask', min: 0, stackClearing: true },
  36360. { id: 'cntrmask', min: 0, stackClearing: true },
  36361. { id: 'rmoveto', min: 2, stackClearing: true },
  36362. { id: 'hmoveto', min: 1, stackClearing: true },
  36363. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  36364. { id: 'rcurveline', min: 8, resetStack: true },
  36365. { id: 'rlinecurve', min: 8, resetStack: true },
  36366. { id: 'vvcurveto', min: 4, resetStack: true },
  36367. { id: 'hhcurveto', min: 4, resetStack: true },
  36368. null, // shortint
  36369. { id: 'callgsubr', min: 1, undefStack: true },
  36370. { id: 'vhcurveto', min: 4, resetStack: true },
  36371. { id: 'hvcurveto', min: 4, resetStack: true }
  36372. ];
  36373. var CharstringValidationData12 = [
  36374. null,
  36375. null,
  36376. null,
  36377. { id: 'and', min: 2, stackDelta: -1 },
  36378. { id: 'or', min: 2, stackDelta: -1 },
  36379. { id: 'not', min: 1, stackDelta: 0 },
  36380. null,
  36381. null,
  36382. null,
  36383. { id: 'abs', min: 1, stackDelta: 0 },
  36384. { id: 'add', min: 2, stackDelta: -1,
  36385. stackFn: function stack_div(stack, index) {
  36386. stack[index - 2] = stack[index - 2] + stack[index - 1];
  36387. }
  36388. },
  36389. { id: 'sub', min: 2, stackDelta: -1,
  36390. stackFn: function stack_div(stack, index) {
  36391. stack[index - 2] = stack[index - 2] - stack[index - 1];
  36392. }
  36393. },
  36394. { id: 'div', min: 2, stackDelta: -1,
  36395. stackFn: function stack_div(stack, index) {
  36396. stack[index - 2] = stack[index - 2] / stack[index - 1];
  36397. }
  36398. },
  36399. null,
  36400. { id: 'neg', min: 1, stackDelta: 0,
  36401. stackFn: function stack_div(stack, index) {
  36402. stack[index - 1] = -stack[index - 1];
  36403. }
  36404. },
  36405. { id: 'eq', min: 2, stackDelta: -1 },
  36406. null,
  36407. null,
  36408. { id: 'drop', min: 1, stackDelta: -1 },
  36409. null,
  36410. { id: 'put', min: 2, stackDelta: -2 },
  36411. { id: 'get', min: 1, stackDelta: 0 },
  36412. { id: 'ifelse', min: 4, stackDelta: -3 },
  36413. { id: 'random', min: 0, stackDelta: 1 },
  36414. { id: 'mul', min: 2, stackDelta: -1,
  36415. stackFn: function stack_div(stack, index) {
  36416. stack[index - 2] = stack[index - 2] * stack[index - 1];
  36417. }
  36418. },
  36419. null,
  36420. { id: 'sqrt', min: 1, stackDelta: 0 },
  36421. { id: 'dup', min: 1, stackDelta: 1 },
  36422. { id: 'exch', min: 2, stackDelta: 0 },
  36423. { id: 'index', min: 2, stackDelta: 0 },
  36424. { id: 'roll', min: 3, stackDelta: -2 },
  36425. null,
  36426. null,
  36427. null,
  36428. { id: 'hflex', min: 7, resetStack: true },
  36429. { id: 'flex', min: 13, resetStack: true },
  36430. { id: 'hflex1', min: 9, resetStack: true },
  36431. { id: 'flex1', min: 11, resetStack: true }
  36432. ];
  36433. function CFFParser(file, properties) {
  36434. this.bytes = file.getBytes();
  36435. this.properties = properties;
  36436. }
  36437. CFFParser.prototype = {
  36438. parse: function CFFParser_parse() {
  36439. var properties = this.properties;
  36440. var cff = new CFF();
  36441. this.cff = cff;
  36442. // The first five sections must be in order, all the others are reached
  36443. // via offsets contained in one of the below.
  36444. var header = this.parseHeader();
  36445. var nameIndex = this.parseIndex(header.endPos);
  36446. var topDictIndex = this.parseIndex(nameIndex.endPos);
  36447. var stringIndex = this.parseIndex(topDictIndex.endPos);
  36448. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  36449. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  36450. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  36451. cff.header = header.obj;
  36452. cff.names = this.parseNameIndex(nameIndex.obj);
  36453. cff.strings = this.parseStringIndex(stringIndex.obj);
  36454. cff.topDict = topDict;
  36455. cff.globalSubrIndex = globalSubrIndex.obj;
  36456. this.parsePrivateDict(cff.topDict);
  36457. cff.isCIDFont = topDict.hasName('ROS');
  36458. var charStringOffset = topDict.getByName('CharStrings');
  36459. var charStringIndex = this.parseIndex(charStringOffset).obj;
  36460. var fontMatrix = topDict.getByName('FontMatrix');
  36461. if (fontMatrix) {
  36462. properties.fontMatrix = fontMatrix;
  36463. }
  36464. var fontBBox = topDict.getByName('FontBBox');
  36465. if (fontBBox) {
  36466. // adjusting ascent/descent
  36467. properties.ascent = fontBBox[3];
  36468. properties.descent = fontBBox[1];
  36469. properties.ascentScaled = true;
  36470. }
  36471. var charset, encoding;
  36472. if (cff.isCIDFont) {
  36473. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  36474. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  36475. var dictRaw = fdArrayIndex.get(i);
  36476. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  36477. cff.strings);
  36478. this.parsePrivateDict(fontDict);
  36479. cff.fdArray.push(fontDict);
  36480. }
  36481. // cid fonts don't have an encoding
  36482. encoding = null;
  36483. charset = this.parseCharsets(topDict.getByName('charset'),
  36484. charStringIndex.count, cff.strings, true);
  36485. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  36486. charStringIndex.count);
  36487. } else {
  36488. charset = this.parseCharsets(topDict.getByName('charset'),
  36489. charStringIndex.count, cff.strings, false);
  36490. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  36491. properties,
  36492. cff.strings, charset.charset);
  36493. }
  36494. cff.charset = charset;
  36495. cff.encoding = encoding;
  36496. var charStringsAndSeacs = this.parseCharStrings(
  36497. charStringIndex,
  36498. topDict.privateDict.subrsIndex,
  36499. globalSubrIndex.obj,
  36500. cff.fdSelect,
  36501. cff.fdArray);
  36502. cff.charStrings = charStringsAndSeacs.charStrings;
  36503. cff.seacs = charStringsAndSeacs.seacs;
  36504. cff.widths = charStringsAndSeacs.widths;
  36505. return cff;
  36506. },
  36507. parseHeader: function CFFParser_parseHeader() {
  36508. var bytes = this.bytes;
  36509. var bytesLength = bytes.length;
  36510. var offset = 0;
  36511. // Prevent an infinite loop, by checking that the offset is within the
  36512. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  36513. while (offset < bytesLength && bytes[offset] !== 1) {
  36514. ++offset;
  36515. }
  36516. if (offset >= bytesLength) {
  36517. error('Invalid CFF header');
  36518. } else if (offset !== 0) {
  36519. info('cff data is shifted');
  36520. bytes = bytes.subarray(offset);
  36521. this.bytes = bytes;
  36522. }
  36523. var major = bytes[0];
  36524. var minor = bytes[1];
  36525. var hdrSize = bytes[2];
  36526. var offSize = bytes[3];
  36527. var header = new CFFHeader(major, minor, hdrSize, offSize);
  36528. return { obj: header, endPos: hdrSize };
  36529. },
  36530. parseDict: function CFFParser_parseDict(dict) {
  36531. var pos = 0;
  36532. function parseOperand() {
  36533. var value = dict[pos++];
  36534. if (value === 30) {
  36535. return parseFloatOperand(pos);
  36536. } else if (value === 28) {
  36537. value = dict[pos++];
  36538. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  36539. return value;
  36540. } else if (value === 29) {
  36541. value = dict[pos++];
  36542. value = (value << 8) | dict[pos++];
  36543. value = (value << 8) | dict[pos++];
  36544. value = (value << 8) | dict[pos++];
  36545. return value;
  36546. } else if (value >= 32 && value <= 246) {
  36547. return value - 139;
  36548. } else if (value >= 247 && value <= 250) {
  36549. return ((value - 247) * 256) + dict[pos++] + 108;
  36550. } else if (value >= 251 && value <= 254) {
  36551. return -((value - 251) * 256) - dict[pos++] - 108;
  36552. } else {
  36553. error('255 is not a valid DICT command');
  36554. }
  36555. return -1;
  36556. }
  36557. function parseFloatOperand() {
  36558. var str = '';
  36559. var eof = 15;
  36560. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  36561. '9', '.', 'E', 'E-', null, '-'];
  36562. var length = dict.length;
  36563. while (pos < length) {
  36564. var b = dict[pos++];
  36565. var b1 = b >> 4;
  36566. var b2 = b & 15;
  36567. if (b1 === eof) {
  36568. break;
  36569. }
  36570. str += lookup[b1];
  36571. if (b2 === eof) {
  36572. break;
  36573. }
  36574. str += lookup[b2];
  36575. }
  36576. return parseFloat(str);
  36577. }
  36578. var operands = [];
  36579. var entries = [];
  36580. pos = 0;
  36581. var end = dict.length;
  36582. while (pos < end) {
  36583. var b = dict[pos];
  36584. if (b <= 21) {
  36585. if (b === 12) {
  36586. b = (b << 8) | dict[++pos];
  36587. }
  36588. entries.push([b, operands]);
  36589. operands = [];
  36590. ++pos;
  36591. } else {
  36592. operands.push(parseOperand());
  36593. }
  36594. }
  36595. return entries;
  36596. },
  36597. parseIndex: function CFFParser_parseIndex(pos) {
  36598. var cffIndex = new CFFIndex();
  36599. var bytes = this.bytes;
  36600. var count = (bytes[pos++] << 8) | bytes[pos++];
  36601. var offsets = [];
  36602. var end = pos;
  36603. var i, ii;
  36604. if (count !== 0) {
  36605. var offsetSize = bytes[pos++];
  36606. // add 1 for offset to determine size of last object
  36607. var startPos = pos + ((count + 1) * offsetSize) - 1;
  36608. for (i = 0, ii = count + 1; i < ii; ++i) {
  36609. var offset = 0;
  36610. for (var j = 0; j < offsetSize; ++j) {
  36611. offset <<= 8;
  36612. offset += bytes[pos++];
  36613. }
  36614. offsets.push(startPos + offset);
  36615. }
  36616. end = offsets[count];
  36617. }
  36618. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  36619. var offsetStart = offsets[i];
  36620. var offsetEnd = offsets[i + 1];
  36621. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  36622. }
  36623. return {obj: cffIndex, endPos: end};
  36624. },
  36625. parseNameIndex: function CFFParser_parseNameIndex(index) {
  36626. var names = [];
  36627. for (var i = 0, ii = index.count; i < ii; ++i) {
  36628. var name = index.get(i);
  36629. // OTS doesn't allow names to be over 127 characters.
  36630. var length = Math.min(name.length, 127);
  36631. var data = [];
  36632. // OTS also only permits certain characters in the name.
  36633. for (var j = 0; j < length; ++j) {
  36634. var c = name[j];
  36635. if (j === 0 && c === 0) {
  36636. data[j] = c;
  36637. continue;
  36638. }
  36639. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  36640. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  36641. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  36642. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  36643. data[j] = 95;
  36644. continue;
  36645. }
  36646. data[j] = c;
  36647. }
  36648. names.push(bytesToString(data));
  36649. }
  36650. return names;
  36651. },
  36652. parseStringIndex: function CFFParser_parseStringIndex(index) {
  36653. var strings = new CFFStrings();
  36654. for (var i = 0, ii = index.count; i < ii; ++i) {
  36655. var data = index.get(i);
  36656. strings.add(bytesToString(data));
  36657. }
  36658. return strings;
  36659. },
  36660. createDict: function CFFParser_createDict(Type, dict, strings) {
  36661. var cffDict = new Type(strings);
  36662. for (var i = 0, ii = dict.length; i < ii; ++i) {
  36663. var pair = dict[i];
  36664. var key = pair[0];
  36665. var value = pair[1];
  36666. cffDict.setByKey(key, value);
  36667. }
  36668. return cffDict;
  36669. },
  36670. parseCharString: function CFFParser_parseCharString(state, data,
  36671. localSubrIndex,
  36672. globalSubrIndex) {
  36673. if (state.callDepth > MAX_SUBR_NESTING) {
  36674. return false;
  36675. }
  36676. var stackSize = state.stackSize;
  36677. var stack = state.stack;
  36678. var length = data.length;
  36679. for (var j = 0; j < length;) {
  36680. var value = data[j++];
  36681. var validationCommand = null;
  36682. if (value === 12) {
  36683. var q = data[j++];
  36684. if (q === 0) {
  36685. // The CFF specification state that the 'dotsection' command
  36686. // (12, 0) is deprecated and treated as a no-op, but all Type2
  36687. // charstrings processors should support them. Unfortunately
  36688. // the font sanitizer don't. As a workaround the sequence (12, 0)
  36689. // is replaced by a useless (0, hmoveto).
  36690. data[j - 2] = 139;
  36691. data[j - 1] = 22;
  36692. stackSize = 0;
  36693. } else {
  36694. validationCommand = CharstringValidationData12[q];
  36695. }
  36696. } else if (value === 28) { // number (16 bit)
  36697. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  36698. j += 2;
  36699. stackSize++;
  36700. } else if (value === 14) {
  36701. if (stackSize >= 4) {
  36702. stackSize -= 4;
  36703. if (SEAC_ANALYSIS_ENABLED) {
  36704. state.seac = stack.slice(stackSize, stackSize + 4);
  36705. return false;
  36706. }
  36707. }
  36708. validationCommand = CharstringValidationData[value];
  36709. } else if (value >= 32 && value <= 246) { // number
  36710. stack[stackSize] = value - 139;
  36711. stackSize++;
  36712. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  36713. stack[stackSize] = (value < 251 ?
  36714. ((value - 247) << 8) + data[j] + 108 :
  36715. -((value - 251) << 8) - data[j] - 108);
  36716. j++;
  36717. stackSize++;
  36718. } else if (value === 255) { // number (32 bit)
  36719. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  36720. (data[j + 2] << 8) | data[j + 3]) / 65536;
  36721. j += 4;
  36722. stackSize++;
  36723. } else if (value === 19 || value === 20) {
  36724. state.hints += stackSize >> 1;
  36725. // skipping right amount of hints flag data
  36726. j += (state.hints + 7) >> 3;
  36727. stackSize %= 2;
  36728. validationCommand = CharstringValidationData[value];
  36729. } else if (value === 10 || value === 29) {
  36730. var subrsIndex;
  36731. if (value === 10) {
  36732. subrsIndex = localSubrIndex;
  36733. } else {
  36734. subrsIndex = globalSubrIndex;
  36735. }
  36736. if (!subrsIndex) {
  36737. validationCommand = CharstringValidationData[value];
  36738. warn('Missing subrsIndex for ' + validationCommand.id);
  36739. return false;
  36740. }
  36741. var bias = 32768;
  36742. if (subrsIndex.count < 1240) {
  36743. bias = 107;
  36744. } else if (subrsIndex.count < 33900) {
  36745. bias = 1131;
  36746. }
  36747. var subrNumber = stack[--stackSize] + bias;
  36748. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  36749. validationCommand = CharstringValidationData[value];
  36750. warn('Out of bounds subrIndex for ' + validationCommand.id);
  36751. return false;
  36752. }
  36753. state.stackSize = stackSize;
  36754. state.callDepth++;
  36755. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  36756. localSubrIndex, globalSubrIndex);
  36757. if (!valid) {
  36758. return false;
  36759. }
  36760. state.callDepth--;
  36761. stackSize = state.stackSize;
  36762. continue;
  36763. } else if (value === 11) {
  36764. state.stackSize = stackSize;
  36765. return true;
  36766. } else {
  36767. validationCommand = CharstringValidationData[value];
  36768. }
  36769. if (validationCommand) {
  36770. if (validationCommand.stem) {
  36771. state.hints += stackSize >> 1;
  36772. }
  36773. if ('min' in validationCommand) {
  36774. if (!state.undefStack && stackSize < validationCommand.min) {
  36775. warn('Not enough parameters for ' + validationCommand.id +
  36776. '; actual: ' + stackSize +
  36777. ', expected: ' + validationCommand.min);
  36778. return false;
  36779. }
  36780. }
  36781. if (state.firstStackClearing && validationCommand.stackClearing) {
  36782. state.firstStackClearing = false;
  36783. // the optional character width can be found before the first
  36784. // stack-clearing command arguments
  36785. stackSize -= validationCommand.min;
  36786. if (stackSize >= 2 && validationCommand.stem) {
  36787. // there are even amount of arguments for stem commands
  36788. stackSize %= 2;
  36789. } else if (stackSize > 1) {
  36790. warn('Found too many parameters for stack-clearing command');
  36791. }
  36792. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  36793. state.width = stack[stackSize - 1];
  36794. }
  36795. }
  36796. if ('stackDelta' in validationCommand) {
  36797. if ('stackFn' in validationCommand) {
  36798. validationCommand.stackFn(stack, stackSize);
  36799. }
  36800. stackSize += validationCommand.stackDelta;
  36801. } else if (validationCommand.stackClearing) {
  36802. stackSize = 0;
  36803. } else if (validationCommand.resetStack) {
  36804. stackSize = 0;
  36805. state.undefStack = false;
  36806. } else if (validationCommand.undefStack) {
  36807. stackSize = 0;
  36808. state.undefStack = true;
  36809. state.firstStackClearing = false;
  36810. }
  36811. }
  36812. }
  36813. state.stackSize = stackSize;
  36814. return true;
  36815. },
  36816. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  36817. localSubrIndex,
  36818. globalSubrIndex,
  36819. fdSelect,
  36820. fdArray) {
  36821. var seacs = [];
  36822. var widths = [];
  36823. var count = charStrings.count;
  36824. for (var i = 0; i < count; i++) {
  36825. var charstring = charStrings.get(i);
  36826. var state = {
  36827. callDepth: 0,
  36828. stackSize: 0,
  36829. stack: [],
  36830. undefStack: true,
  36831. hints: 0,
  36832. firstStackClearing: true,
  36833. seac: null,
  36834. width: null
  36835. };
  36836. var valid = true;
  36837. var localSubrToUse = null;
  36838. if (fdSelect && fdArray.length) {
  36839. var fdIndex = fdSelect.getFDIndex(i);
  36840. if (fdIndex === -1) {
  36841. warn('Glyph index is not in fd select.');
  36842. valid = false;
  36843. }
  36844. if (fdIndex >= fdArray.length) {
  36845. warn('Invalid fd index for glyph index.');
  36846. valid = false;
  36847. }
  36848. if (valid) {
  36849. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  36850. }
  36851. } else if (localSubrIndex) {
  36852. localSubrToUse = localSubrIndex;
  36853. }
  36854. if (valid) {
  36855. valid = this.parseCharString(state, charstring, localSubrToUse,
  36856. globalSubrIndex);
  36857. }
  36858. if (state.width !== null) {
  36859. widths[i] = state.width;
  36860. }
  36861. if (state.seac !== null) {
  36862. seacs[i] = state.seac;
  36863. }
  36864. if (!valid) {
  36865. // resetting invalid charstring to single 'endchar'
  36866. charStrings.set(i, new Uint8Array([14]));
  36867. }
  36868. }
  36869. return { charStrings: charStrings, seacs: seacs, widths: widths };
  36870. },
  36871. emptyPrivateDictionary:
  36872. function CFFParser_emptyPrivateDictionary(parentDict) {
  36873. var privateDict = this.createDict(CFFPrivateDict, [],
  36874. parentDict.strings);
  36875. parentDict.setByKey(18, [0, 0]);
  36876. parentDict.privateDict = privateDict;
  36877. },
  36878. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  36879. // no private dict, do nothing
  36880. if (!parentDict.hasName('Private')) {
  36881. this.emptyPrivateDictionary(parentDict);
  36882. return;
  36883. }
  36884. var privateOffset = parentDict.getByName('Private');
  36885. // make sure the params are formatted correctly
  36886. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  36887. parentDict.removeByName('Private');
  36888. return;
  36889. }
  36890. var size = privateOffset[0];
  36891. var offset = privateOffset[1];
  36892. // remove empty dicts or ones that refer to invalid location
  36893. if (size === 0 || offset >= this.bytes.length) {
  36894. this.emptyPrivateDictionary(parentDict);
  36895. return;
  36896. }
  36897. var privateDictEnd = offset + size;
  36898. var dictData = this.bytes.subarray(offset, privateDictEnd);
  36899. var dict = this.parseDict(dictData);
  36900. var privateDict = this.createDict(CFFPrivateDict, dict,
  36901. parentDict.strings);
  36902. parentDict.privateDict = privateDict;
  36903. // Parse the Subrs index also since it's relative to the private dict.
  36904. if (!privateDict.getByName('Subrs')) {
  36905. return;
  36906. }
  36907. var subrsOffset = privateDict.getByName('Subrs');
  36908. var relativeOffset = offset + subrsOffset;
  36909. // Validate the offset.
  36910. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  36911. this.emptyPrivateDictionary(parentDict);
  36912. return;
  36913. }
  36914. var subrsIndex = this.parseIndex(relativeOffset);
  36915. privateDict.subrsIndex = subrsIndex.obj;
  36916. },
  36917. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  36918. if (pos === 0) {
  36919. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  36920. ISOAdobeCharset);
  36921. } else if (pos === 1) {
  36922. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  36923. ExpertCharset);
  36924. } else if (pos === 2) {
  36925. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  36926. ExpertSubsetCharset);
  36927. }
  36928. var bytes = this.bytes;
  36929. var start = pos;
  36930. var format = bytes[pos++];
  36931. var charset = ['.notdef'];
  36932. var id, count, i;
  36933. // subtract 1 for the .notdef glyph
  36934. length -= 1;
  36935. switch (format) {
  36936. case 0:
  36937. for (i = 0; i < length; i++) {
  36938. id = (bytes[pos++] << 8) | bytes[pos++];
  36939. charset.push(cid ? id : strings.get(id));
  36940. }
  36941. break;
  36942. case 1:
  36943. while (charset.length <= length) {
  36944. id = (bytes[pos++] << 8) | bytes[pos++];
  36945. count = bytes[pos++];
  36946. for (i = 0; i <= count; i++) {
  36947. charset.push(cid ? id++ : strings.get(id++));
  36948. }
  36949. }
  36950. break;
  36951. case 2:
  36952. while (charset.length <= length) {
  36953. id = (bytes[pos++] << 8) | bytes[pos++];
  36954. count = (bytes[pos++] << 8) | bytes[pos++];
  36955. for (i = 0; i <= count; i++) {
  36956. charset.push(cid ? id++ : strings.get(id++));
  36957. }
  36958. }
  36959. break;
  36960. default:
  36961. error('Unknown charset format');
  36962. }
  36963. // Raw won't be needed if we actually compile the charset.
  36964. var end = pos;
  36965. var raw = bytes.subarray(start, end);
  36966. return new CFFCharset(false, format, charset, raw);
  36967. },
  36968. parseEncoding: function CFFParser_parseEncoding(pos,
  36969. properties,
  36970. strings,
  36971. charset) {
  36972. var encoding = {};
  36973. var bytes = this.bytes;
  36974. var predefined = false;
  36975. var hasSupplement = false;
  36976. var format, i, ii;
  36977. var raw = null;
  36978. function readSupplement() {
  36979. var supplementsCount = bytes[pos++];
  36980. for (i = 0; i < supplementsCount; i++) {
  36981. var code = bytes[pos++];
  36982. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  36983. encoding[code] = charset.indexOf(strings.get(sid));
  36984. }
  36985. }
  36986. if (pos === 0 || pos === 1) {
  36987. predefined = true;
  36988. format = pos;
  36989. var baseEncoding = pos ? Encodings.ExpertEncoding :
  36990. Encodings.StandardEncoding;
  36991. for (i = 0, ii = charset.length; i < ii; i++) {
  36992. var index = baseEncoding.indexOf(charset[i]);
  36993. if (index !== -1) {
  36994. encoding[index] = i;
  36995. }
  36996. }
  36997. } else {
  36998. var dataStart = pos;
  36999. format = bytes[pos++];
  37000. switch (format & 0x7f) {
  37001. case 0:
  37002. var glyphsCount = bytes[pos++];
  37003. for (i = 1; i <= glyphsCount; i++) {
  37004. encoding[bytes[pos++]] = i;
  37005. }
  37006. break;
  37007. case 1:
  37008. var rangesCount = bytes[pos++];
  37009. var gid = 1;
  37010. for (i = 0; i < rangesCount; i++) {
  37011. var start = bytes[pos++];
  37012. var left = bytes[pos++];
  37013. for (var j = start; j <= start + left; j++) {
  37014. encoding[j] = gid++;
  37015. }
  37016. }
  37017. break;
  37018. default:
  37019. error('Unknow encoding format: ' + format + ' in CFF');
  37020. break;
  37021. }
  37022. var dataEnd = pos;
  37023. if (format & 0x80) {
  37024. // The font sanitizer does not support CFF encoding with a
  37025. // supplement, since the encoding is not really used to map
  37026. // between gid to glyph, let's overwrite what is declared in
  37027. // the top dictionary to let the sanitizer think the font use
  37028. // StandardEncoding, that's a lie but that's ok.
  37029. bytes[dataStart] &= 0x7f;
  37030. readSupplement();
  37031. hasSupplement = true;
  37032. }
  37033. raw = bytes.subarray(dataStart, dataEnd);
  37034. }
  37035. format = format & 0x7f;
  37036. return new CFFEncoding(predefined, format, encoding, raw);
  37037. },
  37038. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  37039. var start = pos;
  37040. var bytes = this.bytes;
  37041. var format = bytes[pos++];
  37042. var fdSelect = [];
  37043. var i;
  37044. switch (format) {
  37045. case 0:
  37046. for (i = 0; i < length; ++i) {
  37047. var id = bytes[pos++];
  37048. fdSelect.push(id);
  37049. }
  37050. break;
  37051. case 3:
  37052. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  37053. for (i = 0; i < rangesCount; ++i) {
  37054. var first = (bytes[pos++] << 8) | bytes[pos++];
  37055. var fdIndex = bytes[pos++];
  37056. var next = (bytes[pos] << 8) | bytes[pos + 1];
  37057. for (var j = first; j < next; ++j) {
  37058. fdSelect.push(fdIndex);
  37059. }
  37060. }
  37061. // Advance past the sentinel(next).
  37062. pos += 2;
  37063. break;
  37064. default:
  37065. error('Unknown fdselect format ' + format);
  37066. break;
  37067. }
  37068. var end = pos;
  37069. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  37070. }
  37071. };
  37072. return CFFParser;
  37073. })();
  37074. // Compact Font Format
  37075. var CFF = (function CFFClosure() {
  37076. function CFF() {
  37077. this.header = null;
  37078. this.names = [];
  37079. this.topDict = null;
  37080. this.strings = new CFFStrings();
  37081. this.globalSubrIndex = null;
  37082. // The following could really be per font, but since we only have one font
  37083. // store them here.
  37084. this.encoding = null;
  37085. this.charset = null;
  37086. this.charStrings = null;
  37087. this.fdArray = [];
  37088. this.fdSelect = null;
  37089. this.isCIDFont = false;
  37090. }
  37091. return CFF;
  37092. })();
  37093. var CFFHeader = (function CFFHeaderClosure() {
  37094. function CFFHeader(major, minor, hdrSize, offSize) {
  37095. this.major = major;
  37096. this.minor = minor;
  37097. this.hdrSize = hdrSize;
  37098. this.offSize = offSize;
  37099. }
  37100. return CFFHeader;
  37101. })();
  37102. var CFFStrings = (function CFFStringsClosure() {
  37103. function CFFStrings() {
  37104. this.strings = [];
  37105. }
  37106. CFFStrings.prototype = {
  37107. get: function CFFStrings_get(index) {
  37108. if (index >= 0 && index <= 390) {
  37109. return CFFStandardStrings[index];
  37110. }
  37111. if (index - 391 <= this.strings.length) {
  37112. return this.strings[index - 391];
  37113. }
  37114. return CFFStandardStrings[0];
  37115. },
  37116. add: function CFFStrings_add(value) {
  37117. this.strings.push(value);
  37118. },
  37119. get count() {
  37120. return this.strings.length;
  37121. }
  37122. };
  37123. return CFFStrings;
  37124. })();
  37125. var CFFIndex = (function CFFIndexClosure() {
  37126. function CFFIndex() {
  37127. this.objects = [];
  37128. this.length = 0;
  37129. }
  37130. CFFIndex.prototype = {
  37131. add: function CFFIndex_add(data) {
  37132. this.length += data.length;
  37133. this.objects.push(data);
  37134. },
  37135. set: function CFFIndex_set(index, data) {
  37136. this.length += data.length - this.objects[index].length;
  37137. this.objects[index] = data;
  37138. },
  37139. get: function CFFIndex_get(index) {
  37140. return this.objects[index];
  37141. },
  37142. get count() {
  37143. return this.objects.length;
  37144. }
  37145. };
  37146. return CFFIndex;
  37147. })();
  37148. var CFFDict = (function CFFDictClosure() {
  37149. function CFFDict(tables, strings) {
  37150. this.keyToNameMap = tables.keyToNameMap;
  37151. this.nameToKeyMap = tables.nameToKeyMap;
  37152. this.defaults = tables.defaults;
  37153. this.types = tables.types;
  37154. this.opcodes = tables.opcodes;
  37155. this.order = tables.order;
  37156. this.strings = strings;
  37157. this.values = {};
  37158. }
  37159. CFFDict.prototype = {
  37160. // value should always be an array
  37161. setByKey: function CFFDict_setByKey(key, value) {
  37162. if (!(key in this.keyToNameMap)) {
  37163. return false;
  37164. }
  37165. // ignore empty values
  37166. if (value.length === 0) {
  37167. return true;
  37168. }
  37169. var type = this.types[key];
  37170. // remove the array wrapping these types of values
  37171. if (type === 'num' || type === 'sid' || type === 'offset') {
  37172. value = value[0];
  37173. }
  37174. this.values[key] = value;
  37175. return true;
  37176. },
  37177. setByName: function CFFDict_setByName(name, value) {
  37178. if (!(name in this.nameToKeyMap)) {
  37179. error('Invalid dictionary name "' + name + '"');
  37180. }
  37181. this.values[this.nameToKeyMap[name]] = value;
  37182. },
  37183. hasName: function CFFDict_hasName(name) {
  37184. return this.nameToKeyMap[name] in this.values;
  37185. },
  37186. getByName: function CFFDict_getByName(name) {
  37187. if (!(name in this.nameToKeyMap)) {
  37188. error('Invalid dictionary name "' + name + '"');
  37189. }
  37190. var key = this.nameToKeyMap[name];
  37191. if (!(key in this.values)) {
  37192. return this.defaults[key];
  37193. }
  37194. return this.values[key];
  37195. },
  37196. removeByName: function CFFDict_removeByName(name) {
  37197. delete this.values[this.nameToKeyMap[name]];
  37198. }
  37199. };
  37200. CFFDict.createTables = function CFFDict_createTables(layout) {
  37201. var tables = {
  37202. keyToNameMap: {},
  37203. nameToKeyMap: {},
  37204. defaults: {},
  37205. types: {},
  37206. opcodes: {},
  37207. order: []
  37208. };
  37209. for (var i = 0, ii = layout.length; i < ii; ++i) {
  37210. var entry = layout[i];
  37211. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  37212. tables.keyToNameMap[key] = entry[1];
  37213. tables.nameToKeyMap[entry[1]] = key;
  37214. tables.types[key] = entry[2];
  37215. tables.defaults[key] = entry[3];
  37216. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  37217. tables.order.push(key);
  37218. }
  37219. return tables;
  37220. };
  37221. return CFFDict;
  37222. })();
  37223. var CFFTopDict = (function CFFTopDictClosure() {
  37224. var layout = [
  37225. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  37226. [[12, 20], 'SyntheticBase', 'num', null],
  37227. [0, 'version', 'sid', null],
  37228. [1, 'Notice', 'sid', null],
  37229. [[12, 0], 'Copyright', 'sid', null],
  37230. [2, 'FullName', 'sid', null],
  37231. [3, 'FamilyName', 'sid', null],
  37232. [4, 'Weight', 'sid', null],
  37233. [[12, 1], 'isFixedPitch', 'num', 0],
  37234. [[12, 2], 'ItalicAngle', 'num', 0],
  37235. [[12, 3], 'UnderlinePosition', 'num', -100],
  37236. [[12, 4], 'UnderlineThickness', 'num', 50],
  37237. [[12, 5], 'PaintType', 'num', 0],
  37238. [[12, 6], 'CharstringType', 'num', 2],
  37239. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  37240. [0.001, 0, 0, 0.001, 0, 0]],
  37241. [13, 'UniqueID', 'num', null],
  37242. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  37243. [[12, 8], 'StrokeWidth', 'num', 0],
  37244. [14, 'XUID', 'array', null],
  37245. [15, 'charset', 'offset', 0],
  37246. [16, 'Encoding', 'offset', 0],
  37247. [17, 'CharStrings', 'offset', 0],
  37248. [18, 'Private', ['offset', 'offset'], null],
  37249. [[12, 21], 'PostScript', 'sid', null],
  37250. [[12, 22], 'BaseFontName', 'sid', null],
  37251. [[12, 23], 'BaseFontBlend', 'delta', null],
  37252. [[12, 31], 'CIDFontVersion', 'num', 0],
  37253. [[12, 32], 'CIDFontRevision', 'num', 0],
  37254. [[12, 33], 'CIDFontType', 'num', 0],
  37255. [[12, 34], 'CIDCount', 'num', 8720],
  37256. [[12, 35], 'UIDBase', 'num', null],
  37257. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  37258. // before FDArray.
  37259. [[12, 37], 'FDSelect', 'offset', null],
  37260. [[12, 36], 'FDArray', 'offset', null],
  37261. [[12, 38], 'FontName', 'sid', null]
  37262. ];
  37263. var tables = null;
  37264. function CFFTopDict(strings) {
  37265. if (tables === null) {
  37266. tables = CFFDict.createTables(layout);
  37267. }
  37268. CFFDict.call(this, tables, strings);
  37269. this.privateDict = null;
  37270. }
  37271. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  37272. return CFFTopDict;
  37273. })();
  37274. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  37275. var layout = [
  37276. [6, 'BlueValues', 'delta', null],
  37277. [7, 'OtherBlues', 'delta', null],
  37278. [8, 'FamilyBlues', 'delta', null],
  37279. [9, 'FamilyOtherBlues', 'delta', null],
  37280. [[12, 9], 'BlueScale', 'num', 0.039625],
  37281. [[12, 10], 'BlueShift', 'num', 7],
  37282. [[12, 11], 'BlueFuzz', 'num', 1],
  37283. [10, 'StdHW', 'num', null],
  37284. [11, 'StdVW', 'num', null],
  37285. [[12, 12], 'StemSnapH', 'delta', null],
  37286. [[12, 13], 'StemSnapV', 'delta', null],
  37287. [[12, 14], 'ForceBold', 'num', 0],
  37288. [[12, 17], 'LanguageGroup', 'num', 0],
  37289. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  37290. [[12, 19], 'initialRandomSeed', 'num', 0],
  37291. [20, 'defaultWidthX', 'num', 0],
  37292. [21, 'nominalWidthX', 'num', 0],
  37293. [19, 'Subrs', 'offset', null]
  37294. ];
  37295. var tables = null;
  37296. function CFFPrivateDict(strings) {
  37297. if (tables === null) {
  37298. tables = CFFDict.createTables(layout);
  37299. }
  37300. CFFDict.call(this, tables, strings);
  37301. this.subrsIndex = null;
  37302. }
  37303. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  37304. return CFFPrivateDict;
  37305. })();
  37306. var CFFCharsetPredefinedTypes = {
  37307. ISO_ADOBE: 0,
  37308. EXPERT: 1,
  37309. EXPERT_SUBSET: 2
  37310. };
  37311. var CFFCharset = (function CFFCharsetClosure() {
  37312. function CFFCharset(predefined, format, charset, raw) {
  37313. this.predefined = predefined;
  37314. this.format = format;
  37315. this.charset = charset;
  37316. this.raw = raw;
  37317. }
  37318. return CFFCharset;
  37319. })();
  37320. var CFFEncoding = (function CFFEncodingClosure() {
  37321. function CFFEncoding(predefined, format, encoding, raw) {
  37322. this.predefined = predefined;
  37323. this.format = format;
  37324. this.encoding = encoding;
  37325. this.raw = raw;
  37326. }
  37327. return CFFEncoding;
  37328. })();
  37329. var CFFFDSelect = (function CFFFDSelectClosure() {
  37330. function CFFFDSelect(fdSelect, raw) {
  37331. this.fdSelect = fdSelect;
  37332. this.raw = raw;
  37333. }
  37334. CFFFDSelect.prototype = {
  37335. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  37336. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  37337. return -1;
  37338. }
  37339. return this.fdSelect[glyphIndex];
  37340. }
  37341. };
  37342. return CFFFDSelect;
  37343. })();
  37344. // Helper class to keep track of where an offset is within the data and helps
  37345. // filling in that offset once it's known.
  37346. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  37347. function CFFOffsetTracker() {
  37348. this.offsets = {};
  37349. }
  37350. CFFOffsetTracker.prototype = {
  37351. isTracking: function CFFOffsetTracker_isTracking(key) {
  37352. return key in this.offsets;
  37353. },
  37354. track: function CFFOffsetTracker_track(key, location) {
  37355. if (key in this.offsets) {
  37356. error('Already tracking location of ' + key);
  37357. }
  37358. this.offsets[key] = location;
  37359. },
  37360. offset: function CFFOffsetTracker_offset(value) {
  37361. for (var key in this.offsets) {
  37362. this.offsets[key] += value;
  37363. }
  37364. },
  37365. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  37366. values,
  37367. output) {
  37368. if (!(key in this.offsets)) {
  37369. error('Not tracking location of ' + key);
  37370. }
  37371. var data = output.data;
  37372. var dataOffset = this.offsets[key];
  37373. var size = 5;
  37374. for (var i = 0, ii = values.length; i < ii; ++i) {
  37375. var offset0 = i * size + dataOffset;
  37376. var offset1 = offset0 + 1;
  37377. var offset2 = offset0 + 2;
  37378. var offset3 = offset0 + 3;
  37379. var offset4 = offset0 + 4;
  37380. // It's easy to screw up offsets so perform this sanity check.
  37381. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  37382. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  37383. error('writing to an offset that is not empty');
  37384. }
  37385. var value = values[i];
  37386. data[offset0] = 0x1d;
  37387. data[offset1] = (value >> 24) & 0xFF;
  37388. data[offset2] = (value >> 16) & 0xFF;
  37389. data[offset3] = (value >> 8) & 0xFF;
  37390. data[offset4] = value & 0xFF;
  37391. }
  37392. }
  37393. };
  37394. return CFFOffsetTracker;
  37395. })();
  37396. // Takes a CFF and converts it to the binary representation.
  37397. var CFFCompiler = (function CFFCompilerClosure() {
  37398. function CFFCompiler(cff) {
  37399. this.cff = cff;
  37400. }
  37401. CFFCompiler.prototype = {
  37402. compile: function CFFCompiler_compile() {
  37403. var cff = this.cff;
  37404. var output = {
  37405. data: [],
  37406. length: 0,
  37407. add: function CFFCompiler_add(data) {
  37408. this.data = this.data.concat(data);
  37409. this.length = this.data.length;
  37410. }
  37411. };
  37412. // Compile the five entries that must be in order.
  37413. var header = this.compileHeader(cff.header);
  37414. output.add(header);
  37415. var nameIndex = this.compileNameIndex(cff.names);
  37416. output.add(nameIndex);
  37417. if (cff.isCIDFont) {
  37418. // The spec is unclear on how font matrices should relate to each other
  37419. // when there is one in the main top dict and the sub top dicts.
  37420. // Windows handles this differently than linux and osx so we have to
  37421. // normalize to work on all.
  37422. // Rules based off of some mailing list discussions:
  37423. // - If main font has a matrix and subfont doesn't, use the main matrix.
  37424. // - If no main font matrix and there is a subfont matrix, use the
  37425. // subfont matrix.
  37426. // - If both have matrices, concat together.
  37427. // - If neither have matrices, use default.
  37428. // To make this work on all platforms we move the top matrix into each
  37429. // sub top dict and concat if necessary.
  37430. if (cff.topDict.hasName('FontMatrix')) {
  37431. var base = cff.topDict.getByName('FontMatrix');
  37432. cff.topDict.removeByName('FontMatrix');
  37433. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  37434. var subDict = cff.fdArray[i];
  37435. var matrix = base.slice(0);
  37436. if (subDict.hasName('FontMatrix')) {
  37437. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  37438. }
  37439. subDict.setByName('FontMatrix', matrix);
  37440. }
  37441. }
  37442. }
  37443. var compiled = this.compileTopDicts([cff.topDict],
  37444. output.length,
  37445. cff.isCIDFont);
  37446. output.add(compiled.output);
  37447. var topDictTracker = compiled.trackers[0];
  37448. var stringIndex = this.compileStringIndex(cff.strings.strings);
  37449. output.add(stringIndex);
  37450. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  37451. output.add(globalSubrIndex);
  37452. // Now start on the other entries that have no specfic order.
  37453. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  37454. if (cff.encoding.predefined) {
  37455. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  37456. output);
  37457. } else {
  37458. var encoding = this.compileEncoding(cff.encoding);
  37459. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  37460. output.add(encoding);
  37461. }
  37462. }
  37463. if (cff.charset && cff.topDict.hasName('charset')) {
  37464. if (cff.charset.predefined) {
  37465. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  37466. output);
  37467. } else {
  37468. var charset = this.compileCharset(cff.charset);
  37469. topDictTracker.setEntryLocation('charset', [output.length], output);
  37470. output.add(charset);
  37471. }
  37472. }
  37473. var charStrings = this.compileCharStrings(cff.charStrings);
  37474. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  37475. output.add(charStrings);
  37476. if (cff.isCIDFont) {
  37477. // For some reason FDSelect must be in front of FDArray on windows. OSX
  37478. // and linux don't seem to care.
  37479. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  37480. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  37481. output.add(fdSelect);
  37482. // It is unclear if the sub font dictionary can have CID related
  37483. // dictionary keys, but the sanitizer doesn't like them so remove them.
  37484. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  37485. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  37486. output.add(compiled.output);
  37487. var fontDictTrackers = compiled.trackers;
  37488. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  37489. }
  37490. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  37491. // If the font data ends with INDEX whose object data is zero-length,
  37492. // the sanitizer will bail out. Add a dummy byte to avoid that.
  37493. output.add([0]);
  37494. return output.data;
  37495. },
  37496. encodeNumber: function CFFCompiler_encodeNumber(value) {
  37497. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  37498. return this.encodeInteger(value);
  37499. } else {
  37500. return this.encodeFloat(value);
  37501. }
  37502. },
  37503. encodeFloat: function CFFCompiler_encodeFloat(num) {
  37504. var value = num.toString();
  37505. // rounding inaccurate doubles
  37506. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  37507. if (m) {
  37508. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  37509. value = (Math.round(num * epsilon) / epsilon).toString();
  37510. }
  37511. var nibbles = '';
  37512. var i, ii;
  37513. for (i = 0, ii = value.length; i < ii; ++i) {
  37514. var a = value[i];
  37515. if (a === 'e') {
  37516. nibbles += value[++i] === '-' ? 'c' : 'b';
  37517. } else if (a === '.') {
  37518. nibbles += 'a';
  37519. } else if (a === '-') {
  37520. nibbles += 'e';
  37521. } else {
  37522. nibbles += a;
  37523. }
  37524. }
  37525. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  37526. var out = [30];
  37527. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  37528. out.push(parseInt(nibbles.substr(i, 2), 16));
  37529. }
  37530. return out;
  37531. },
  37532. encodeInteger: function CFFCompiler_encodeInteger(value) {
  37533. var code;
  37534. if (value >= -107 && value <= 107) {
  37535. code = [value + 139];
  37536. } else if (value >= 108 && value <= 1131) {
  37537. value = [value - 108];
  37538. code = [(value >> 8) + 247, value & 0xFF];
  37539. } else if (value >= -1131 && value <= -108) {
  37540. value = -value - 108;
  37541. code = [(value >> 8) + 251, value & 0xFF];
  37542. } else if (value >= -32768 && value <= 32767) {
  37543. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  37544. } else {
  37545. code = [0x1d,
  37546. (value >> 24) & 0xFF,
  37547. (value >> 16) & 0xFF,
  37548. (value >> 8) & 0xFF,
  37549. value & 0xFF];
  37550. }
  37551. return code;
  37552. },
  37553. compileHeader: function CFFCompiler_compileHeader(header) {
  37554. return [
  37555. header.major,
  37556. header.minor,
  37557. header.hdrSize,
  37558. header.offSize
  37559. ];
  37560. },
  37561. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  37562. var nameIndex = new CFFIndex();
  37563. for (var i = 0, ii = names.length; i < ii; ++i) {
  37564. nameIndex.add(stringToBytes(names[i]));
  37565. }
  37566. return this.compileIndex(nameIndex);
  37567. },
  37568. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  37569. length,
  37570. removeCidKeys) {
  37571. var fontDictTrackers = [];
  37572. var fdArrayIndex = new CFFIndex();
  37573. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  37574. var fontDict = dicts[i];
  37575. if (removeCidKeys) {
  37576. fontDict.removeByName('CIDFontVersion');
  37577. fontDict.removeByName('CIDFontRevision');
  37578. fontDict.removeByName('CIDFontType');
  37579. fontDict.removeByName('CIDCount');
  37580. fontDict.removeByName('UIDBase');
  37581. }
  37582. var fontDictTracker = new CFFOffsetTracker();
  37583. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  37584. fontDictTrackers.push(fontDictTracker);
  37585. fdArrayIndex.add(fontDictData);
  37586. fontDictTracker.offset(length);
  37587. }
  37588. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  37589. return {
  37590. trackers: fontDictTrackers,
  37591. output: fdArrayIndex
  37592. };
  37593. },
  37594. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  37595. trackers,
  37596. output) {
  37597. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  37598. var fontDict = dicts[i];
  37599. assert(fontDict.privateDict && fontDict.hasName('Private'),
  37600. 'There must be an private dictionary.');
  37601. var privateDict = fontDict.privateDict;
  37602. var privateDictTracker = new CFFOffsetTracker();
  37603. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  37604. var outputLength = output.length;
  37605. privateDictTracker.offset(outputLength);
  37606. if (!privateDictData.length) {
  37607. // The private dictionary was empty, set the output length to zero to
  37608. // ensure the offset length isn't out of bounds in the eyes of the
  37609. // sanitizer.
  37610. outputLength = 0;
  37611. }
  37612. trackers[i].setEntryLocation('Private',
  37613. [privateDictData.length, outputLength],
  37614. output);
  37615. output.add(privateDictData);
  37616. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  37617. var subrs = this.compileIndex(privateDict.subrsIndex);
  37618. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  37619. output);
  37620. output.add(subrs);
  37621. }
  37622. }
  37623. },
  37624. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  37625. var out = [];
  37626. // The dictionary keys must be in a certain order.
  37627. var order = dict.order;
  37628. for (var i = 0; i < order.length; ++i) {
  37629. var key = order[i];
  37630. if (!(key in dict.values)) {
  37631. continue;
  37632. }
  37633. var values = dict.values[key];
  37634. var types = dict.types[key];
  37635. if (!isArray(types)) {
  37636. types = [types];
  37637. }
  37638. if (!isArray(values)) {
  37639. values = [values];
  37640. }
  37641. // Remove any empty dict values.
  37642. if (values.length === 0) {
  37643. continue;
  37644. }
  37645. for (var j = 0, jj = types.length; j < jj; ++j) {
  37646. var type = types[j];
  37647. var value = values[j];
  37648. switch (type) {
  37649. case 'num':
  37650. case 'sid':
  37651. out = out.concat(this.encodeNumber(value));
  37652. break;
  37653. case 'offset':
  37654. // For offsets we just insert a 32bit integer so we don't have to
  37655. // deal with figuring out the length of the offset when it gets
  37656. // replaced later on by the compiler.
  37657. var name = dict.keyToNameMap[key];
  37658. // Some offsets have the offset and the length, so just record the
  37659. // position of the first one.
  37660. if (!offsetTracker.isTracking(name)) {
  37661. offsetTracker.track(name, out.length);
  37662. }
  37663. out = out.concat([0x1d, 0, 0, 0, 0]);
  37664. break;
  37665. case 'array':
  37666. case 'delta':
  37667. out = out.concat(this.encodeNumber(value));
  37668. for (var k = 1, kk = values.length; k < kk; ++k) {
  37669. out = out.concat(this.encodeNumber(values[k]));
  37670. }
  37671. break;
  37672. default:
  37673. error('Unknown data type of ' + type);
  37674. break;
  37675. }
  37676. }
  37677. out = out.concat(dict.opcodes[key]);
  37678. }
  37679. return out;
  37680. },
  37681. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  37682. var stringIndex = new CFFIndex();
  37683. for (var i = 0, ii = strings.length; i < ii; ++i) {
  37684. stringIndex.add(stringToBytes(strings[i]));
  37685. }
  37686. return this.compileIndex(stringIndex);
  37687. },
  37688. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  37689. var globalSubrIndex = this.cff.globalSubrIndex;
  37690. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  37691. },
  37692. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  37693. return this.compileIndex(charStrings);
  37694. },
  37695. compileCharset: function CFFCompiler_compileCharset(charset) {
  37696. return this.compileTypedArray(charset.raw);
  37697. },
  37698. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  37699. return this.compileTypedArray(encoding.raw);
  37700. },
  37701. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  37702. return this.compileTypedArray(fdSelect);
  37703. },
  37704. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  37705. var out = [];
  37706. for (var i = 0, ii = data.length; i < ii; ++i) {
  37707. out[i] = data[i];
  37708. }
  37709. return out;
  37710. },
  37711. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  37712. trackers = trackers || [];
  37713. var objects = index.objects;
  37714. // First 2 bytes contains the number of objects contained into this index
  37715. var count = objects.length;
  37716. // If there is no object, just create an index. This technically
  37717. // should just be [0, 0] but OTS has an issue with that.
  37718. if (count === 0) {
  37719. return [0, 0, 0];
  37720. }
  37721. var data = [(count >> 8) & 0xFF, count & 0xff];
  37722. var lastOffset = 1, i;
  37723. for (i = 0; i < count; ++i) {
  37724. lastOffset += objects[i].length;
  37725. }
  37726. var offsetSize;
  37727. if (lastOffset < 0x100) {
  37728. offsetSize = 1;
  37729. } else if (lastOffset < 0x10000) {
  37730. offsetSize = 2;
  37731. } else if (lastOffset < 0x1000000) {
  37732. offsetSize = 3;
  37733. } else {
  37734. offsetSize = 4;
  37735. }
  37736. // Next byte contains the offset size use to reference object in the file
  37737. data.push(offsetSize);
  37738. // Add another offset after this one because we need a new offset
  37739. var relativeOffset = 1;
  37740. for (i = 0; i < count + 1; i++) {
  37741. if (offsetSize === 1) {
  37742. data.push(relativeOffset & 0xFF);
  37743. } else if (offsetSize === 2) {
  37744. data.push((relativeOffset >> 8) & 0xFF,
  37745. relativeOffset & 0xFF);
  37746. } else if (offsetSize === 3) {
  37747. data.push((relativeOffset >> 16) & 0xFF,
  37748. (relativeOffset >> 8) & 0xFF,
  37749. relativeOffset & 0xFF);
  37750. } else {
  37751. data.push((relativeOffset >>> 24) & 0xFF,
  37752. (relativeOffset >> 16) & 0xFF,
  37753. (relativeOffset >> 8) & 0xFF,
  37754. relativeOffset & 0xFF);
  37755. }
  37756. if (objects[i]) {
  37757. relativeOffset += objects[i].length;
  37758. }
  37759. }
  37760. for (i = 0; i < count; i++) {
  37761. // Notify the tracker where the object will be offset in the data.
  37762. if (trackers[i]) {
  37763. trackers[i].offset(data.length);
  37764. }
  37765. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  37766. data.push(objects[i][j]);
  37767. }
  37768. }
  37769. return data;
  37770. }
  37771. };
  37772. return CFFCompiler;
  37773. })();
  37774. function _enableSeacAnalysis(enabled) {
  37775. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  37776. }
  37777. // Workaround for seac on Windows.
  37778. (function checkSeacSupport() {
  37779. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  37780. SEAC_ANALYSIS_ENABLED = true;
  37781. }
  37782. })();
  37783. // Workaround for Private Use Area characters in Chrome on Windows
  37784. // http://code.google.com/p/chromium/issues/detail?id=122465
  37785. // https://github.com/mozilla/pdf.js/issues/1689
  37786. (function checkChromeWindows() {
  37787. if (typeof navigator !== 'undefined' &&
  37788. /Windows.*Chrome/.test(navigator.userAgent)) {
  37789. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  37790. }
  37791. })();
  37792. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  37793. exports.CFFCompiler = CFFCompiler;
  37794. exports.CFFIndex = CFFIndex;
  37795. exports.CFFParser = CFFParser;
  37796. exports.CFFStrings = CFFStrings;
  37797. exports.Encodings = Encodings;
  37798. exports.ErrorFont = ErrorFont;
  37799. exports.FontFlags = FontFlags;
  37800. exports.Font = Font;
  37801. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  37802. exports.NormalizedUnicodes = NormalizedUnicodes;
  37803. exports.ToUnicodeMap = ToUnicodeMap;
  37804. exports.Type1Parser = Type1Parser;
  37805. exports.getFontType = getFontType;
  37806. exports.reverseIfRtl = reverseIfRtl;
  37807. exports.serifFonts = serifFonts;
  37808. exports.symbolsFonts = symbolsFonts;
  37809. exports.stdFontMap = stdFontMap;
  37810. exports._enableSeacAnalysis = _enableSeacAnalysis;
  37811. // TODO refactor to remove cyclic dependency on font_renderer.js
  37812. coreFontRenderer._setCoreFonts(exports);
  37813. }));
  37814. (function (root, factory) {
  37815. {
  37816. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  37817. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  37818. }
  37819. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  37820. var error = sharedUtil.error;
  37821. var info = sharedUtil.info;
  37822. var isArray = sharedUtil.isArray;
  37823. var isBool = sharedUtil.isBool;
  37824. var isDict = corePrimitives.isDict;
  37825. var isStream = corePrimitives.isStream;
  37826. var PostScriptLexer = corePsParser.PostScriptLexer;
  37827. var PostScriptParser = corePsParser.PostScriptParser;
  37828. var PDFFunction = (function PDFFunctionClosure() {
  37829. var CONSTRUCT_SAMPLED = 0;
  37830. var CONSTRUCT_INTERPOLATED = 2;
  37831. var CONSTRUCT_STICHED = 3;
  37832. var CONSTRUCT_POSTSCRIPT = 4;
  37833. return {
  37834. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  37835. str) {
  37836. var i, ii;
  37837. var length = 1;
  37838. for (i = 0, ii = size.length; i < ii; i++) {
  37839. length *= size[i];
  37840. }
  37841. length *= outputSize;
  37842. var array = new Array(length);
  37843. var codeSize = 0;
  37844. var codeBuf = 0;
  37845. // 32 is a valid bps so shifting won't work
  37846. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  37847. var strBytes = str.getBytes((length * bps + 7) / 8);
  37848. var strIdx = 0;
  37849. for (i = 0; i < length; i++) {
  37850. while (codeSize < bps) {
  37851. codeBuf <<= 8;
  37852. codeBuf |= strBytes[strIdx++];
  37853. codeSize += 8;
  37854. }
  37855. codeSize -= bps;
  37856. array[i] = (codeBuf >> codeSize) * sampleMul;
  37857. codeBuf &= (1 << codeSize) - 1;
  37858. }
  37859. return array;
  37860. },
  37861. getIR: function PDFFunction_getIR(xref, fn) {
  37862. var dict = fn.dict;
  37863. if (!dict) {
  37864. dict = fn;
  37865. }
  37866. var types = [this.constructSampled,
  37867. null,
  37868. this.constructInterpolated,
  37869. this.constructStiched,
  37870. this.constructPostScript];
  37871. var typeNum = dict.get('FunctionType');
  37872. var typeFn = types[typeNum];
  37873. if (!typeFn) {
  37874. error('Unknown type of function');
  37875. }
  37876. return typeFn.call(this, fn, dict, xref);
  37877. },
  37878. fromIR: function PDFFunction_fromIR(IR) {
  37879. var type = IR[0];
  37880. switch (type) {
  37881. case CONSTRUCT_SAMPLED:
  37882. return this.constructSampledFromIR(IR);
  37883. case CONSTRUCT_INTERPOLATED:
  37884. return this.constructInterpolatedFromIR(IR);
  37885. case CONSTRUCT_STICHED:
  37886. return this.constructStichedFromIR(IR);
  37887. //case CONSTRUCT_POSTSCRIPT:
  37888. default:
  37889. return this.constructPostScriptFromIR(IR);
  37890. }
  37891. },
  37892. parse: function PDFFunction_parse(xref, fn) {
  37893. var IR = this.getIR(xref, fn);
  37894. return this.fromIR(IR);
  37895. },
  37896. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  37897. if (!isArray(fnObj)) {
  37898. // not an array -- parsing as regular function
  37899. return this.parse(xref, fnObj);
  37900. }
  37901. var fnArray = [];
  37902. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  37903. var obj = xref.fetchIfRef(fnObj[j]);
  37904. fnArray.push(PDFFunction.parse(xref, obj));
  37905. }
  37906. return function (src, srcOffset, dest, destOffset) {
  37907. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  37908. fnArray[i](src, srcOffset, dest, destOffset + i);
  37909. }
  37910. };
  37911. },
  37912. constructSampled: function PDFFunction_constructSampled(str, dict) {
  37913. function toMultiArray(arr) {
  37914. var inputLength = arr.length;
  37915. var out = [];
  37916. var index = 0;
  37917. for (var i = 0; i < inputLength; i += 2) {
  37918. out[index] = [arr[i], arr[i + 1]];
  37919. ++index;
  37920. }
  37921. return out;
  37922. }
  37923. var domain = dict.get('Domain');
  37924. var range = dict.get('Range');
  37925. if (!domain || !range) {
  37926. error('No domain or range');
  37927. }
  37928. var inputSize = domain.length / 2;
  37929. var outputSize = range.length / 2;
  37930. domain = toMultiArray(domain);
  37931. range = toMultiArray(range);
  37932. var size = dict.get('Size');
  37933. var bps = dict.get('BitsPerSample');
  37934. var order = dict.get('Order') || 1;
  37935. if (order !== 1) {
  37936. // No description how cubic spline interpolation works in PDF32000:2008
  37937. // As in poppler, ignoring order, linear interpolation may work as good
  37938. info('No support for cubic spline interpolation: ' + order);
  37939. }
  37940. var encode = dict.get('Encode');
  37941. if (!encode) {
  37942. encode = [];
  37943. for (var i = 0; i < inputSize; ++i) {
  37944. encode.push(0);
  37945. encode.push(size[i] - 1);
  37946. }
  37947. }
  37948. encode = toMultiArray(encode);
  37949. var decode = dict.get('Decode');
  37950. if (!decode) {
  37951. decode = range;
  37952. } else {
  37953. decode = toMultiArray(decode);
  37954. }
  37955. var samples = this.getSampleArray(size, outputSize, bps, str);
  37956. return [
  37957. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  37958. outputSize, Math.pow(2, bps) - 1, range
  37959. ];
  37960. },
  37961. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  37962. // See chapter 3, page 109 of the PDF reference
  37963. function interpolate(x, xmin, xmax, ymin, ymax) {
  37964. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  37965. }
  37966. return function constructSampledFromIRResult(src, srcOffset,
  37967. dest, destOffset) {
  37968. // See chapter 3, page 110 of the PDF reference.
  37969. var m = IR[1];
  37970. var domain = IR[2];
  37971. var encode = IR[3];
  37972. var decode = IR[4];
  37973. var samples = IR[5];
  37974. var size = IR[6];
  37975. var n = IR[7];
  37976. //var mask = IR[8];
  37977. var range = IR[9];
  37978. // Building the cube vertices: its part and sample index
  37979. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  37980. var cubeVertices = 1 << m;
  37981. var cubeN = new Float64Array(cubeVertices);
  37982. var cubeVertex = new Uint32Array(cubeVertices);
  37983. var i, j;
  37984. for (j = 0; j < cubeVertices; j++) {
  37985. cubeN[j] = 1;
  37986. }
  37987. var k = n, pos = 1;
  37988. // Map x_i to y_j for 0 <= i < m using the sampled function.
  37989. for (i = 0; i < m; ++i) {
  37990. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  37991. var domain_2i = domain[i][0];
  37992. var domain_2i_1 = domain[i][1];
  37993. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  37994. domain_2i_1);
  37995. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  37996. // Encode_2i, Encode_2i+1)
  37997. var e = interpolate(xi, domain_2i, domain_2i_1,
  37998. encode[i][0], encode[i][1]);
  37999. // e_i' = min(max(e_i, 0), Size_i - 1)
  38000. var size_i = size[i];
  38001. e = Math.min(Math.max(e, 0), size_i - 1);
  38002. // Adjusting the cube: N and vertex sample index
  38003. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  38004. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  38005. var n1 = e - e0; // (e - e0) / (e1 - e0);
  38006. var offset0 = e0 * k;
  38007. var offset1 = offset0 + k; // e1 * k
  38008. for (j = 0; j < cubeVertices; j++) {
  38009. if (j & pos) {
  38010. cubeN[j] *= n1;
  38011. cubeVertex[j] += offset1;
  38012. } else {
  38013. cubeN[j] *= n0;
  38014. cubeVertex[j] += offset0;
  38015. }
  38016. }
  38017. k *= size_i;
  38018. pos <<= 1;
  38019. }
  38020. for (j = 0; j < n; ++j) {
  38021. // Sum all cube vertices' samples portions
  38022. var rj = 0;
  38023. for (i = 0; i < cubeVertices; i++) {
  38024. rj += samples[cubeVertex[i] + j] * cubeN[i];
  38025. }
  38026. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  38027. // Decode_2j, Decode_2j+1)
  38028. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  38029. // y_j = min(max(r_j, range_2j), range_2j+1)
  38030. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  38031. range[j][1]);
  38032. }
  38033. };
  38034. },
  38035. constructInterpolated: function PDFFunction_constructInterpolated(str,
  38036. dict) {
  38037. var c0 = dict.get('C0') || [0];
  38038. var c1 = dict.get('C1') || [1];
  38039. var n = dict.get('N');
  38040. if (!isArray(c0) || !isArray(c1)) {
  38041. error('Illegal dictionary for interpolated function');
  38042. }
  38043. var length = c0.length;
  38044. var diff = [];
  38045. for (var i = 0; i < length; ++i) {
  38046. diff.push(c1[i] - c0[i]);
  38047. }
  38048. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  38049. },
  38050. constructInterpolatedFromIR:
  38051. function PDFFunction_constructInterpolatedFromIR(IR) {
  38052. var c0 = IR[1];
  38053. var diff = IR[2];
  38054. var n = IR[3];
  38055. var length = diff.length;
  38056. return function constructInterpolatedFromIRResult(src, srcOffset,
  38057. dest, destOffset) {
  38058. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  38059. for (var j = 0; j < length; ++j) {
  38060. dest[destOffset + j] = c0[j] + (x * diff[j]);
  38061. }
  38062. };
  38063. },
  38064. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  38065. var domain = dict.get('Domain');
  38066. if (!domain) {
  38067. error('No domain');
  38068. }
  38069. var inputSize = domain.length / 2;
  38070. if (inputSize !== 1) {
  38071. error('Bad domain for stiched function');
  38072. }
  38073. var fnRefs = dict.get('Functions');
  38074. var fns = [];
  38075. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  38076. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  38077. }
  38078. var bounds = dict.get('Bounds');
  38079. var encode = dict.get('Encode');
  38080. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  38081. },
  38082. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  38083. var domain = IR[1];
  38084. var bounds = IR[2];
  38085. var encode = IR[3];
  38086. var fnsIR = IR[4];
  38087. var fns = [];
  38088. var tmpBuf = new Float32Array(1);
  38089. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  38090. fns.push(PDFFunction.fromIR(fnsIR[i]));
  38091. }
  38092. return function constructStichedFromIRResult(src, srcOffset,
  38093. dest, destOffset) {
  38094. var clip = function constructStichedFromIRClip(v, min, max) {
  38095. if (v > max) {
  38096. v = max;
  38097. } else if (v < min) {
  38098. v = min;
  38099. }
  38100. return v;
  38101. };
  38102. // clip to domain
  38103. var v = clip(src[srcOffset], domain[0], domain[1]);
  38104. // calulate which bound the value is in
  38105. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  38106. if (v < bounds[i]) {
  38107. break;
  38108. }
  38109. }
  38110. // encode value into domain of function
  38111. var dmin = domain[0];
  38112. if (i > 0) {
  38113. dmin = bounds[i - 1];
  38114. }
  38115. var dmax = domain[1];
  38116. if (i < bounds.length) {
  38117. dmax = bounds[i];
  38118. }
  38119. var rmin = encode[2 * i];
  38120. var rmax = encode[2 * i + 1];
  38121. // Prevent the value from becoming NaN as a result
  38122. // of division by zero (fixes issue6113.pdf).
  38123. tmpBuf[0] = dmin === dmax ? rmin :
  38124. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  38125. // call the appropriate function
  38126. fns[i](tmpBuf, 0, dest, destOffset);
  38127. };
  38128. },
  38129. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  38130. xref) {
  38131. var domain = dict.get('Domain');
  38132. var range = dict.get('Range');
  38133. if (!domain) {
  38134. error('No domain.');
  38135. }
  38136. if (!range) {
  38137. error('No range.');
  38138. }
  38139. var lexer = new PostScriptLexer(fn);
  38140. var parser = new PostScriptParser(lexer);
  38141. var code = parser.parse();
  38142. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  38143. },
  38144. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  38145. IR) {
  38146. var domain = IR[1];
  38147. var range = IR[2];
  38148. var code = IR[3];
  38149. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  38150. if (compiled) {
  38151. // Compiled function consists of simple expressions such as addition,
  38152. // subtraction, Math.max, and also contains 'var' and 'return'
  38153. // statements. See the generation in the PostScriptCompiler below.
  38154. /*jshint -W054 */
  38155. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  38156. }
  38157. info('Unable to compile PS function');
  38158. var numOutputs = range.length >> 1;
  38159. var numInputs = domain.length >> 1;
  38160. var evaluator = new PostScriptEvaluator(code);
  38161. // Cache the values for a big speed up, the cache size is limited though
  38162. // since the number of possible values can be huge from a PS function.
  38163. var cache = {};
  38164. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  38165. // seen in our tests.
  38166. var MAX_CACHE_SIZE = 2048 * 4;
  38167. var cache_available = MAX_CACHE_SIZE;
  38168. var tmpBuf = new Float32Array(numInputs);
  38169. return function constructPostScriptFromIRResult(src, srcOffset,
  38170. dest, destOffset) {
  38171. var i, value;
  38172. var key = '';
  38173. var input = tmpBuf;
  38174. for (i = 0; i < numInputs; i++) {
  38175. value = src[srcOffset + i];
  38176. input[i] = value;
  38177. key += value + '_';
  38178. }
  38179. var cachedValue = cache[key];
  38180. if (cachedValue !== undefined) {
  38181. dest.set(cachedValue, destOffset);
  38182. return;
  38183. }
  38184. var output = new Float32Array(numOutputs);
  38185. var stack = evaluator.execute(input);
  38186. var stackIndex = stack.length - numOutputs;
  38187. for (i = 0; i < numOutputs; i++) {
  38188. value = stack[stackIndex + i];
  38189. var bound = range[i * 2];
  38190. if (value < bound) {
  38191. value = bound;
  38192. } else {
  38193. bound = range[i * 2 +1];
  38194. if (value > bound) {
  38195. value = bound;
  38196. }
  38197. }
  38198. output[i] = value;
  38199. }
  38200. if (cache_available > 0) {
  38201. cache_available--;
  38202. cache[key] = output;
  38203. }
  38204. dest.set(output, destOffset);
  38205. };
  38206. }
  38207. };
  38208. })();
  38209. function isPDFFunction(v) {
  38210. var fnDict;
  38211. if (typeof v !== 'object') {
  38212. return false;
  38213. } else if (isDict(v)) {
  38214. fnDict = v;
  38215. } else if (isStream(v)) {
  38216. fnDict = v.dict;
  38217. } else {
  38218. return false;
  38219. }
  38220. return fnDict.has('FunctionType');
  38221. }
  38222. var PostScriptStack = (function PostScriptStackClosure() {
  38223. var MAX_STACK_SIZE = 100;
  38224. function PostScriptStack(initialStack) {
  38225. this.stack = !initialStack ? [] :
  38226. Array.prototype.slice.call(initialStack, 0);
  38227. }
  38228. PostScriptStack.prototype = {
  38229. push: function PostScriptStack_push(value) {
  38230. if (this.stack.length >= MAX_STACK_SIZE) {
  38231. error('PostScript function stack overflow.');
  38232. }
  38233. this.stack.push(value);
  38234. },
  38235. pop: function PostScriptStack_pop() {
  38236. if (this.stack.length <= 0) {
  38237. error('PostScript function stack underflow.');
  38238. }
  38239. return this.stack.pop();
  38240. },
  38241. copy: function PostScriptStack_copy(n) {
  38242. if (this.stack.length + n >= MAX_STACK_SIZE) {
  38243. error('PostScript function stack overflow.');
  38244. }
  38245. var stack = this.stack;
  38246. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  38247. stack.push(stack[i]);
  38248. }
  38249. },
  38250. index: function PostScriptStack_index(n) {
  38251. this.push(this.stack[this.stack.length - n - 1]);
  38252. },
  38253. // rotate the last n stack elements p times
  38254. roll: function PostScriptStack_roll(n, p) {
  38255. var stack = this.stack;
  38256. var l = stack.length - n;
  38257. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  38258. for (i = l, j = r; i < j; i++, j--) {
  38259. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  38260. }
  38261. for (i = l, j = c - 1; i < j; i++, j--) {
  38262. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  38263. }
  38264. for (i = c, j = r; i < j; i++, j--) {
  38265. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  38266. }
  38267. }
  38268. };
  38269. return PostScriptStack;
  38270. })();
  38271. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  38272. function PostScriptEvaluator(operators) {
  38273. this.operators = operators;
  38274. }
  38275. PostScriptEvaluator.prototype = {
  38276. execute: function PostScriptEvaluator_execute(initialStack) {
  38277. var stack = new PostScriptStack(initialStack);
  38278. var counter = 0;
  38279. var operators = this.operators;
  38280. var length = operators.length;
  38281. var operator, a, b;
  38282. while (counter < length) {
  38283. operator = operators[counter++];
  38284. if (typeof operator === 'number') {
  38285. // Operator is really an operand and should be pushed to the stack.
  38286. stack.push(operator);
  38287. continue;
  38288. }
  38289. switch (operator) {
  38290. // non standard ps operators
  38291. case 'jz': // jump if false
  38292. b = stack.pop();
  38293. a = stack.pop();
  38294. if (!a) {
  38295. counter = b;
  38296. }
  38297. break;
  38298. case 'j': // jump
  38299. a = stack.pop();
  38300. counter = a;
  38301. break;
  38302. // all ps operators in alphabetical order (excluding if/ifelse)
  38303. case 'abs':
  38304. a = stack.pop();
  38305. stack.push(Math.abs(a));
  38306. break;
  38307. case 'add':
  38308. b = stack.pop();
  38309. a = stack.pop();
  38310. stack.push(a + b);
  38311. break;
  38312. case 'and':
  38313. b = stack.pop();
  38314. a = stack.pop();
  38315. if (isBool(a) && isBool(b)) {
  38316. stack.push(a && b);
  38317. } else {
  38318. stack.push(a & b);
  38319. }
  38320. break;
  38321. case 'atan':
  38322. a = stack.pop();
  38323. stack.push(Math.atan(a));
  38324. break;
  38325. case 'bitshift':
  38326. b = stack.pop();
  38327. a = stack.pop();
  38328. if (a > 0) {
  38329. stack.push(a << b);
  38330. } else {
  38331. stack.push(a >> b);
  38332. }
  38333. break;
  38334. case 'ceiling':
  38335. a = stack.pop();
  38336. stack.push(Math.ceil(a));
  38337. break;
  38338. case 'copy':
  38339. a = stack.pop();
  38340. stack.copy(a);
  38341. break;
  38342. case 'cos':
  38343. a = stack.pop();
  38344. stack.push(Math.cos(a));
  38345. break;
  38346. case 'cvi':
  38347. a = stack.pop() | 0;
  38348. stack.push(a);
  38349. break;
  38350. case 'cvr':
  38351. // noop
  38352. break;
  38353. case 'div':
  38354. b = stack.pop();
  38355. a = stack.pop();
  38356. stack.push(a / b);
  38357. break;
  38358. case 'dup':
  38359. stack.copy(1);
  38360. break;
  38361. case 'eq':
  38362. b = stack.pop();
  38363. a = stack.pop();
  38364. stack.push(a === b);
  38365. break;
  38366. case 'exch':
  38367. stack.roll(2, 1);
  38368. break;
  38369. case 'exp':
  38370. b = stack.pop();
  38371. a = stack.pop();
  38372. stack.push(Math.pow(a, b));
  38373. break;
  38374. case 'false':
  38375. stack.push(false);
  38376. break;
  38377. case 'floor':
  38378. a = stack.pop();
  38379. stack.push(Math.floor(a));
  38380. break;
  38381. case 'ge':
  38382. b = stack.pop();
  38383. a = stack.pop();
  38384. stack.push(a >= b);
  38385. break;
  38386. case 'gt':
  38387. b = stack.pop();
  38388. a = stack.pop();
  38389. stack.push(a > b);
  38390. break;
  38391. case 'idiv':
  38392. b = stack.pop();
  38393. a = stack.pop();
  38394. stack.push((a / b) | 0);
  38395. break;
  38396. case 'index':
  38397. a = stack.pop();
  38398. stack.index(a);
  38399. break;
  38400. case 'le':
  38401. b = stack.pop();
  38402. a = stack.pop();
  38403. stack.push(a <= b);
  38404. break;
  38405. case 'ln':
  38406. a = stack.pop();
  38407. stack.push(Math.log(a));
  38408. break;
  38409. case 'log':
  38410. a = stack.pop();
  38411. stack.push(Math.log(a) / Math.LN10);
  38412. break;
  38413. case 'lt':
  38414. b = stack.pop();
  38415. a = stack.pop();
  38416. stack.push(a < b);
  38417. break;
  38418. case 'mod':
  38419. b = stack.pop();
  38420. a = stack.pop();
  38421. stack.push(a % b);
  38422. break;
  38423. case 'mul':
  38424. b = stack.pop();
  38425. a = stack.pop();
  38426. stack.push(a * b);
  38427. break;
  38428. case 'ne':
  38429. b = stack.pop();
  38430. a = stack.pop();
  38431. stack.push(a !== b);
  38432. break;
  38433. case 'neg':
  38434. a = stack.pop();
  38435. stack.push(-a);
  38436. break;
  38437. case 'not':
  38438. a = stack.pop();
  38439. if (isBool(a)) {
  38440. stack.push(!a);
  38441. } else {
  38442. stack.push(~a);
  38443. }
  38444. break;
  38445. case 'or':
  38446. b = stack.pop();
  38447. a = stack.pop();
  38448. if (isBool(a) && isBool(b)) {
  38449. stack.push(a || b);
  38450. } else {
  38451. stack.push(a | b);
  38452. }
  38453. break;
  38454. case 'pop':
  38455. stack.pop();
  38456. break;
  38457. case 'roll':
  38458. b = stack.pop();
  38459. a = stack.pop();
  38460. stack.roll(a, b);
  38461. break;
  38462. case 'round':
  38463. a = stack.pop();
  38464. stack.push(Math.round(a));
  38465. break;
  38466. case 'sin':
  38467. a = stack.pop();
  38468. stack.push(Math.sin(a));
  38469. break;
  38470. case 'sqrt':
  38471. a = stack.pop();
  38472. stack.push(Math.sqrt(a));
  38473. break;
  38474. case 'sub':
  38475. b = stack.pop();
  38476. a = stack.pop();
  38477. stack.push(a - b);
  38478. break;
  38479. case 'true':
  38480. stack.push(true);
  38481. break;
  38482. case 'truncate':
  38483. a = stack.pop();
  38484. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  38485. stack.push(a);
  38486. break;
  38487. case 'xor':
  38488. b = stack.pop();
  38489. a = stack.pop();
  38490. if (isBool(a) && isBool(b)) {
  38491. stack.push(a !== b);
  38492. } else {
  38493. stack.push(a ^ b);
  38494. }
  38495. break;
  38496. default:
  38497. error('Unknown operator ' + operator);
  38498. break;
  38499. }
  38500. }
  38501. return stack.stack;
  38502. }
  38503. };
  38504. return PostScriptEvaluator;
  38505. })();
  38506. // Most of the PDFs functions consist of simple operations such as:
  38507. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  38508. //
  38509. // We can compile most of such programs, and at the same moment, we can
  38510. // optimize some expressions using basic math properties. Keeping track of
  38511. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  38512. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  38513. function AstNode(type) {
  38514. this.type = type;
  38515. }
  38516. AstNode.prototype.visit = function (visitor) {
  38517. throw new Error('abstract method');
  38518. };
  38519. function AstArgument(index, min, max) {
  38520. AstNode.call(this, 'args');
  38521. this.index = index;
  38522. this.min = min;
  38523. this.max = max;
  38524. }
  38525. AstArgument.prototype = Object.create(AstNode.prototype);
  38526. AstArgument.prototype.visit = function (visitor) {
  38527. visitor.visitArgument(this);
  38528. };
  38529. function AstLiteral(number) {
  38530. AstNode.call(this, 'literal');
  38531. this.number = number;
  38532. this.min = number;
  38533. this.max = number;
  38534. }
  38535. AstLiteral.prototype = Object.create(AstNode.prototype);
  38536. AstLiteral.prototype.visit = function (visitor) {
  38537. visitor.visitLiteral(this);
  38538. };
  38539. function AstBinaryOperation(op, arg1, arg2, min, max) {
  38540. AstNode.call(this, 'binary');
  38541. this.op = op;
  38542. this.arg1 = arg1;
  38543. this.arg2 = arg2;
  38544. this.min = min;
  38545. this.max = max;
  38546. }
  38547. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  38548. AstBinaryOperation.prototype.visit = function (visitor) {
  38549. visitor.visitBinaryOperation(this);
  38550. };
  38551. function AstMin(arg, max) {
  38552. AstNode.call(this, 'max');
  38553. this.arg = arg;
  38554. this.min = arg.min;
  38555. this.max = max;
  38556. }
  38557. AstMin.prototype = Object.create(AstNode.prototype);
  38558. AstMin.prototype.visit = function (visitor) {
  38559. visitor.visitMin(this);
  38560. };
  38561. function AstVariable(index, min, max) {
  38562. AstNode.call(this, 'var');
  38563. this.index = index;
  38564. this.min = min;
  38565. this.max = max;
  38566. }
  38567. AstVariable.prototype = Object.create(AstNode.prototype);
  38568. AstVariable.prototype.visit = function (visitor) {
  38569. visitor.visitVariable(this);
  38570. };
  38571. function AstVariableDefinition(variable, arg) {
  38572. AstNode.call(this, 'definition');
  38573. this.variable = variable;
  38574. this.arg = arg;
  38575. }
  38576. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  38577. AstVariableDefinition.prototype.visit = function (visitor) {
  38578. visitor.visitVariableDefinition(this);
  38579. };
  38580. function ExpressionBuilderVisitor() {
  38581. this.parts = [];
  38582. }
  38583. ExpressionBuilderVisitor.prototype = {
  38584. visitArgument: function (arg) {
  38585. this.parts.push('Math.max(', arg.min, ', Math.min(',
  38586. arg.max, ', src[srcOffset + ', arg.index, ']))');
  38587. },
  38588. visitVariable: function (variable) {
  38589. this.parts.push('v', variable.index);
  38590. },
  38591. visitLiteral: function (literal) {
  38592. this.parts.push(literal.number);
  38593. },
  38594. visitBinaryOperation: function (operation) {
  38595. this.parts.push('(');
  38596. operation.arg1.visit(this);
  38597. this.parts.push(' ', operation.op, ' ');
  38598. operation.arg2.visit(this);
  38599. this.parts.push(')');
  38600. },
  38601. visitVariableDefinition: function (definition) {
  38602. this.parts.push('var ');
  38603. definition.variable.visit(this);
  38604. this.parts.push(' = ');
  38605. definition.arg.visit(this);
  38606. this.parts.push(';');
  38607. },
  38608. visitMin: function (max) {
  38609. this.parts.push('Math.min(');
  38610. max.arg.visit(this);
  38611. this.parts.push(', ', max.max, ')');
  38612. },
  38613. toString: function () {
  38614. return this.parts.join('');
  38615. }
  38616. };
  38617. function buildAddOperation(num1, num2) {
  38618. if (num2.type === 'literal' && num2.number === 0) {
  38619. // optimization: second operand is 0
  38620. return num1;
  38621. }
  38622. if (num1.type === 'literal' && num1.number === 0) {
  38623. // optimization: first operand is 0
  38624. return num2;
  38625. }
  38626. if (num2.type === 'literal' && num1.type === 'literal') {
  38627. // optimization: operands operand are literals
  38628. return new AstLiteral(num1.number + num2.number);
  38629. }
  38630. return new AstBinaryOperation('+', num1, num2,
  38631. num1.min + num2.min, num1.max + num2.max);
  38632. }
  38633. function buildMulOperation(num1, num2) {
  38634. if (num2.type === 'literal') {
  38635. // optimization: second operands is a literal...
  38636. if (num2.number === 0) {
  38637. return new AstLiteral(0); // and it's 0
  38638. } else if (num2.number === 1) {
  38639. return num1; // and it's 1
  38640. } else if (num1.type === 'literal') {
  38641. // ... and first operands is a literal too
  38642. return new AstLiteral(num1.number * num2.number);
  38643. }
  38644. }
  38645. if (num1.type === 'literal') {
  38646. // optimization: first operands is a literal...
  38647. if (num1.number === 0) {
  38648. return new AstLiteral(0); // and it's 0
  38649. } else if (num1.number === 1) {
  38650. return num2; // and it's 1
  38651. }
  38652. }
  38653. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  38654. num1.max * num2.min, num1.max * num2.max);
  38655. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  38656. num1.max * num2.min, num1.max * num2.max);
  38657. return new AstBinaryOperation('*', num1, num2, min, max);
  38658. }
  38659. function buildSubOperation(num1, num2) {
  38660. if (num2.type === 'literal') {
  38661. // optimization: second operands is a literal...
  38662. if (num2.number === 0) {
  38663. return num1; // ... and it's 0
  38664. } else if (num1.type === 'literal') {
  38665. // ... and first operands is a literal too
  38666. return new AstLiteral(num1.number - num2.number);
  38667. }
  38668. }
  38669. if (num2.type === 'binary' && num2.op === '-' &&
  38670. num1.type === 'literal' && num1.number === 1 &&
  38671. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  38672. // optimization for case: 1 - (1 - x)
  38673. return num2.arg2;
  38674. }
  38675. return new AstBinaryOperation('-', num1, num2,
  38676. num1.min - num2.max, num1.max - num2.min);
  38677. }
  38678. function buildMinOperation(num1, max) {
  38679. if (num1.min >= max) {
  38680. // optimization: num1 min value is not less than required max
  38681. return new AstLiteral(max); // just returning max
  38682. } else if (num1.max <= max) {
  38683. // optimization: num1 max value is not greater than required max
  38684. return num1; // just returning an argument
  38685. }
  38686. return new AstMin(num1, max);
  38687. }
  38688. function PostScriptCompiler() {}
  38689. PostScriptCompiler.prototype = {
  38690. compile: function PostScriptCompiler_compile(code, domain, range) {
  38691. var stack = [];
  38692. var i, ii;
  38693. var instructions = [];
  38694. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  38695. var lastRegister = 0;
  38696. var n, j;
  38697. var num1, num2, ast1, ast2, tmpVar, item;
  38698. for (i = 0; i < inputSize; i++) {
  38699. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  38700. }
  38701. for (i = 0, ii = code.length; i < ii; i++) {
  38702. item = code[i];
  38703. if (typeof item === 'number') {
  38704. stack.push(new AstLiteral(item));
  38705. continue;
  38706. }
  38707. switch (item) {
  38708. case 'add':
  38709. if (stack.length < 2) {
  38710. return null;
  38711. }
  38712. num2 = stack.pop();
  38713. num1 = stack.pop();
  38714. stack.push(buildAddOperation(num1, num2));
  38715. break;
  38716. case 'cvr':
  38717. if (stack.length < 1) {
  38718. return null;
  38719. }
  38720. break;
  38721. case 'mul':
  38722. if (stack.length < 2) {
  38723. return null;
  38724. }
  38725. num2 = stack.pop();
  38726. num1 = stack.pop();
  38727. stack.push(buildMulOperation(num1, num2));
  38728. break;
  38729. case 'sub':
  38730. if (stack.length < 2) {
  38731. return null;
  38732. }
  38733. num2 = stack.pop();
  38734. num1 = stack.pop();
  38735. stack.push(buildSubOperation(num1, num2));
  38736. break;
  38737. case 'exch':
  38738. if (stack.length < 2) {
  38739. return null;
  38740. }
  38741. ast1 = stack.pop(); ast2 = stack.pop();
  38742. stack.push(ast1, ast2);
  38743. break;
  38744. case 'pop':
  38745. if (stack.length < 1) {
  38746. return null;
  38747. }
  38748. stack.pop();
  38749. break;
  38750. case 'index':
  38751. if (stack.length < 1) {
  38752. return null;
  38753. }
  38754. num1 = stack.pop();
  38755. if (num1.type !== 'literal') {
  38756. return null;
  38757. }
  38758. n = num1.number;
  38759. if (n < 0 || (n|0) !== n || stack.length < n) {
  38760. return null;
  38761. }
  38762. ast1 = stack[stack.length - n - 1];
  38763. if (ast1.type === 'literal' || ast1.type === 'var') {
  38764. stack.push(ast1);
  38765. break;
  38766. }
  38767. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  38768. stack[stack.length - n - 1] = tmpVar;
  38769. stack.push(tmpVar);
  38770. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  38771. break;
  38772. case 'dup':
  38773. if (stack.length < 1) {
  38774. return null;
  38775. }
  38776. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  38777. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  38778. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  38779. // special case of the commands sequence for the min operation
  38780. num1 = stack.pop();
  38781. stack.push(buildMinOperation(num1, code[i + 1]));
  38782. i += 6;
  38783. break;
  38784. }
  38785. ast1 = stack[stack.length - 1];
  38786. if (ast1.type === 'literal' || ast1.type === 'var') {
  38787. // we don't have to save into intermediate variable a literal or
  38788. // variable.
  38789. stack.push(ast1);
  38790. break;
  38791. }
  38792. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  38793. stack[stack.length - 1] = tmpVar;
  38794. stack.push(tmpVar);
  38795. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  38796. break;
  38797. case 'roll':
  38798. if (stack.length < 2) {
  38799. return null;
  38800. }
  38801. num2 = stack.pop();
  38802. num1 = stack.pop();
  38803. if (num2.type !== 'literal' || num1.type !== 'literal') {
  38804. // both roll operands must be numbers
  38805. return null;
  38806. }
  38807. j = num2.number;
  38808. n = num1.number;
  38809. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  38810. // ... and integers
  38811. return null;
  38812. }
  38813. j = ((j % n) + n) % n;
  38814. if (j === 0) {
  38815. break; // just skipping -- there are nothing to rotate
  38816. }
  38817. Array.prototype.push.apply(stack,
  38818. stack.splice(stack.length - n, n - j));
  38819. break;
  38820. default:
  38821. return null; // unsupported operator
  38822. }
  38823. }
  38824. if (stack.length !== outputSize) {
  38825. return null;
  38826. }
  38827. var result = [];
  38828. instructions.forEach(function (instruction) {
  38829. var statementBuilder = new ExpressionBuilderVisitor();
  38830. instruction.visit(statementBuilder);
  38831. result.push(statementBuilder.toString());
  38832. });
  38833. stack.forEach(function (expr, i) {
  38834. var statementBuilder = new ExpressionBuilderVisitor();
  38835. expr.visit(statementBuilder);
  38836. var min = range[i * 2], max = range[i * 2 + 1];
  38837. var out = [statementBuilder.toString()];
  38838. if (min > expr.min) {
  38839. out.unshift('Math.max(', min, ', ');
  38840. out.push(')');
  38841. }
  38842. if (max < expr.max) {
  38843. out.unshift('Math.min(', max, ', ');
  38844. out.push(')');
  38845. }
  38846. out.unshift('dest[destOffset + ', i, '] = ');
  38847. out.push(';');
  38848. result.push(out.join(''));
  38849. });
  38850. return result.join('\n');
  38851. }
  38852. };
  38853. return PostScriptCompiler;
  38854. })();
  38855. exports.isPDFFunction = isPDFFunction;
  38856. exports.PDFFunction = PDFFunction;
  38857. exports.PostScriptEvaluator = PostScriptEvaluator;
  38858. exports.PostScriptCompiler = PostScriptCompiler;
  38859. }));
  38860. (function (root, factory) {
  38861. {
  38862. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38863. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  38864. }
  38865. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  38866. coreStream) {
  38867. var error = sharedUtil.error;
  38868. var info = sharedUtil.info;
  38869. var isArray = sharedUtil.isArray;
  38870. var isString = sharedUtil.isString;
  38871. var shadow = sharedUtil.shadow;
  38872. var warn = sharedUtil.warn;
  38873. var isDict = corePrimitives.isDict;
  38874. var isName = corePrimitives.isName;
  38875. var isStream = corePrimitives.isStream;
  38876. var PDFFunction = coreFunction.PDFFunction;
  38877. var coreImage; // see _setCoreImage below
  38878. var PDFImage; // = coreImage.PDFImage;
  38879. var ColorSpace = (function ColorSpaceClosure() {
  38880. // Constructor should define this.numComps, this.defaultColor, this.name
  38881. function ColorSpace() {
  38882. error('should not call ColorSpace constructor');
  38883. }
  38884. ColorSpace.prototype = {
  38885. /**
  38886. * Converts the color value to the RGB color. The color components are
  38887. * located in the src array starting from the srcOffset. Returns the array
  38888. * of the rgb components, each value ranging from [0,255].
  38889. */
  38890. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38891. var rgb = new Uint8Array(3);
  38892. this.getRgbItem(src, srcOffset, rgb, 0);
  38893. return rgb;
  38894. },
  38895. /**
  38896. * Converts the color value to the RGB color, similar to the getRgb method.
  38897. * The result placed into the dest array starting from the destOffset.
  38898. */
  38899. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38900. dest, destOffset) {
  38901. error('Should not call ColorSpace.getRgbItem');
  38902. },
  38903. /**
  38904. * Converts the specified number of the color values to the RGB colors.
  38905. * The colors are located in the src array starting from the srcOffset.
  38906. * The result is placed into the dest array starting from the destOffset.
  38907. * The src array items shall be in [0,2^bits) range, the dest array items
  38908. * will be in [0,255] range. alpha01 indicates how many alpha components
  38909. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38910. * array).
  38911. */
  38912. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38913. dest, destOffset, bits,
  38914. alpha01) {
  38915. error('Should not call ColorSpace.getRgbBuffer');
  38916. },
  38917. /**
  38918. * Determines the number of bytes required to store the result of the
  38919. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38920. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38921. */
  38922. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38923. alpha01) {
  38924. error('Should not call ColorSpace.getOutputLength');
  38925. },
  38926. /**
  38927. * Returns true if source data will be equal the result/output data.
  38928. */
  38929. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38930. return false;
  38931. },
  38932. /**
  38933. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38934. * how many alpha components there are in the dest array; it will be either
  38935. * 0 (RGB array) or 1 (RGBA array).
  38936. */
  38937. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38938. originalHeight, width, height,
  38939. actualHeight, bpc, comps, alpha01) {
  38940. var count = originalWidth * originalHeight;
  38941. var rgbBuf = null;
  38942. var numComponentColors = 1 << bpc;
  38943. var needsResizing = originalHeight !== height || originalWidth !== width;
  38944. var i, ii;
  38945. if (this.isPassthrough(bpc)) {
  38946. rgbBuf = comps;
  38947. } else if (this.numComps === 1 && count > numComponentColors &&
  38948. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38949. // Optimization: create a color map when there is just one component and
  38950. // we are converting more colors than the size of the color map. We
  38951. // don't build the map if the colorspace is gray or rgb since those
  38952. // methods are faster than building a map. This mainly offers big speed
  38953. // ups for indexed and alternate colorspaces.
  38954. //
  38955. // TODO it may be worth while to cache the color map. While running
  38956. // testing I never hit a cache so I will leave that out for now (perhaps
  38957. // we are reparsing colorspaces too much?).
  38958. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38959. new Uint16Array(numComponentColors);
  38960. var key;
  38961. for (i = 0; i < numComponentColors; i++) {
  38962. allColors[i] = i;
  38963. }
  38964. var colorMap = new Uint8Array(numComponentColors * 3);
  38965. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38966. /* alpha01 = */ 0);
  38967. var destPos, rgbPos;
  38968. if (!needsResizing) {
  38969. // Fill in the RGB values directly into |dest|.
  38970. destPos = 0;
  38971. for (i = 0; i < count; ++i) {
  38972. key = comps[i] * 3;
  38973. dest[destPos++] = colorMap[key];
  38974. dest[destPos++] = colorMap[key + 1];
  38975. dest[destPos++] = colorMap[key + 2];
  38976. destPos += alpha01;
  38977. }
  38978. } else {
  38979. rgbBuf = new Uint8Array(count * 3);
  38980. rgbPos = 0;
  38981. for (i = 0; i < count; ++i) {
  38982. key = comps[i] * 3;
  38983. rgbBuf[rgbPos++] = colorMap[key];
  38984. rgbBuf[rgbPos++] = colorMap[key + 1];
  38985. rgbBuf[rgbPos++] = colorMap[key + 2];
  38986. }
  38987. }
  38988. } else {
  38989. if (!needsResizing) {
  38990. // Fill in the RGB values directly into |dest|.
  38991. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38992. alpha01);
  38993. } else {
  38994. rgbBuf = new Uint8Array(count * 3);
  38995. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38996. /* alpha01 = */ 0);
  38997. }
  38998. }
  38999. if (rgbBuf) {
  39000. if (needsResizing) {
  39001. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  39002. height, dest, alpha01);
  39003. } else {
  39004. rgbPos = 0;
  39005. destPos = 0;
  39006. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  39007. dest[destPos++] = rgbBuf[rgbPos++];
  39008. dest[destPos++] = rgbBuf[rgbPos++];
  39009. dest[destPos++] = rgbBuf[rgbPos++];
  39010. destPos += alpha01;
  39011. }
  39012. }
  39013. }
  39014. },
  39015. /**
  39016. * True if the colorspace has components in the default range of [0, 1].
  39017. * This should be true for all colorspaces except for lab color spaces
  39018. * which are [0,100], [-128, 127], [-128, 127].
  39019. */
  39020. usesZeroToOneRange: true
  39021. };
  39022. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  39023. var IR = ColorSpace.parseToIR(cs, xref, res);
  39024. if (IR instanceof AlternateCS) {
  39025. return IR;
  39026. }
  39027. return ColorSpace.fromIR(IR);
  39028. };
  39029. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  39030. var name = isArray(IR) ? IR[0] : IR;
  39031. var whitePoint, blackPoint, gamma;
  39032. switch (name) {
  39033. case 'DeviceGrayCS':
  39034. return this.singletons.gray;
  39035. case 'DeviceRgbCS':
  39036. return this.singletons.rgb;
  39037. case 'DeviceCmykCS':
  39038. return this.singletons.cmyk;
  39039. case 'CalGrayCS':
  39040. whitePoint = IR[1].WhitePoint;
  39041. blackPoint = IR[1].BlackPoint;
  39042. gamma = IR[1].Gamma;
  39043. return new CalGrayCS(whitePoint, blackPoint, gamma);
  39044. case 'CalRGBCS':
  39045. whitePoint = IR[1].WhitePoint;
  39046. blackPoint = IR[1].BlackPoint;
  39047. gamma = IR[1].Gamma;
  39048. var matrix = IR[1].Matrix;
  39049. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  39050. case 'PatternCS':
  39051. var basePatternCS = IR[1];
  39052. if (basePatternCS) {
  39053. basePatternCS = ColorSpace.fromIR(basePatternCS);
  39054. }
  39055. return new PatternCS(basePatternCS);
  39056. case 'IndexedCS':
  39057. var baseIndexedCS = IR[1];
  39058. var hiVal = IR[2];
  39059. var lookup = IR[3];
  39060. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  39061. case 'AlternateCS':
  39062. var numComps = IR[1];
  39063. var alt = IR[2];
  39064. var tintFnIR = IR[3];
  39065. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  39066. PDFFunction.fromIR(tintFnIR));
  39067. case 'LabCS':
  39068. whitePoint = IR[1].WhitePoint;
  39069. blackPoint = IR[1].BlackPoint;
  39070. var range = IR[1].Range;
  39071. return new LabCS(whitePoint, blackPoint, range);
  39072. default:
  39073. error('Unknown name ' + name);
  39074. }
  39075. return null;
  39076. };
  39077. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  39078. if (isName(cs)) {
  39079. var colorSpaces = res.get('ColorSpace');
  39080. if (isDict(colorSpaces)) {
  39081. var refcs = colorSpaces.get(cs.name);
  39082. if (refcs) {
  39083. cs = refcs;
  39084. }
  39085. }
  39086. }
  39087. cs = xref.fetchIfRef(cs);
  39088. var mode;
  39089. if (isName(cs)) {
  39090. mode = cs.name;
  39091. this.mode = mode;
  39092. switch (mode) {
  39093. case 'DeviceGray':
  39094. case 'G':
  39095. return 'DeviceGrayCS';
  39096. case 'DeviceRGB':
  39097. case 'RGB':
  39098. return 'DeviceRgbCS';
  39099. case 'DeviceCMYK':
  39100. case 'CMYK':
  39101. return 'DeviceCmykCS';
  39102. case 'Pattern':
  39103. return ['PatternCS', null];
  39104. default:
  39105. error('unrecognized colorspace ' + mode);
  39106. }
  39107. } else if (isArray(cs)) {
  39108. mode = xref.fetchIfRef(cs[0]).name;
  39109. this.mode = mode;
  39110. var numComps, params, alt;
  39111. switch (mode) {
  39112. case 'DeviceGray':
  39113. case 'G':
  39114. return 'DeviceGrayCS';
  39115. case 'DeviceRGB':
  39116. case 'RGB':
  39117. return 'DeviceRgbCS';
  39118. case 'DeviceCMYK':
  39119. case 'CMYK':
  39120. return 'DeviceCmykCS';
  39121. case 'CalGray':
  39122. params = xref.fetchIfRef(cs[1]).getAll();
  39123. return ['CalGrayCS', params];
  39124. case 'CalRGB':
  39125. params = xref.fetchIfRef(cs[1]).getAll();
  39126. return ['CalRGBCS', params];
  39127. case 'ICCBased':
  39128. var stream = xref.fetchIfRef(cs[1]);
  39129. var dict = stream.dict;
  39130. numComps = dict.get('N');
  39131. alt = dict.get('Alternate');
  39132. if (alt) {
  39133. var altIR = ColorSpace.parseToIR(alt, xref, res);
  39134. // Parse the /Alternate CS to ensure that the number of components
  39135. // are correct, and also (indirectly) that it is not a PatternCS.
  39136. var altCS = ColorSpace.fromIR(altIR);
  39137. if (altCS.numComps === numComps) {
  39138. return altIR;
  39139. }
  39140. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  39141. }
  39142. if (numComps === 1) {
  39143. return 'DeviceGrayCS';
  39144. } else if (numComps === 3) {
  39145. return 'DeviceRgbCS';
  39146. } else if (numComps === 4) {
  39147. return 'DeviceCmykCS';
  39148. }
  39149. break;
  39150. case 'Pattern':
  39151. var basePatternCS = cs[1] || null;
  39152. if (basePatternCS) {
  39153. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  39154. }
  39155. return ['PatternCS', basePatternCS];
  39156. case 'Indexed':
  39157. case 'I':
  39158. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  39159. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  39160. var lookup = xref.fetchIfRef(cs[3]);
  39161. if (isStream(lookup)) {
  39162. lookup = lookup.getBytes();
  39163. }
  39164. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  39165. case 'Separation':
  39166. case 'DeviceN':
  39167. var name = xref.fetchIfRef(cs[1]);
  39168. numComps = 1;
  39169. if (isName(name)) {
  39170. numComps = 1;
  39171. } else if (isArray(name)) {
  39172. numComps = name.length;
  39173. }
  39174. alt = ColorSpace.parseToIR(cs[2], xref, res);
  39175. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  39176. return ['AlternateCS', numComps, alt, tintFnIR];
  39177. case 'Lab':
  39178. params = xref.fetchIfRef(cs[1]).getAll();
  39179. return ['LabCS', params];
  39180. default:
  39181. error('unimplemented color space object "' + mode + '"');
  39182. }
  39183. } else {
  39184. error('unrecognized color space object: "' + cs + '"');
  39185. }
  39186. return null;
  39187. };
  39188. /**
  39189. * Checks if a decode map matches the default decode map for a color space.
  39190. * This handles the general decode maps where there are two values per
  39191. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  39192. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  39193. * slightly different.
  39194. * @param {Array} decode Decode map (usually from an image).
  39195. * @param {Number} n Number of components the color space has.
  39196. */
  39197. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  39198. if (!isArray(decode)) {
  39199. return true;
  39200. }
  39201. if (n * 2 !== decode.length) {
  39202. warn('The decode map is not the correct length');
  39203. return true;
  39204. }
  39205. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  39206. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  39207. return false;
  39208. }
  39209. }
  39210. return true;
  39211. };
  39212. ColorSpace.singletons = {
  39213. get gray() {
  39214. return shadow(this, 'gray', new DeviceGrayCS());
  39215. },
  39216. get rgb() {
  39217. return shadow(this, 'rgb', new DeviceRgbCS());
  39218. },
  39219. get cmyk() {
  39220. return shadow(this, 'cmyk', new DeviceCmykCS());
  39221. }
  39222. };
  39223. return ColorSpace;
  39224. })();
  39225. /**
  39226. * Alternate color space handles both Separation and DeviceN color spaces. A
  39227. * Separation color space is actually just a DeviceN with one color component.
  39228. * Both color spaces use a tinting function to convert colors to a base color
  39229. * space.
  39230. */
  39231. var AlternateCS = (function AlternateCSClosure() {
  39232. function AlternateCS(numComps, base, tintFn) {
  39233. this.name = 'Alternate';
  39234. this.numComps = numComps;
  39235. this.defaultColor = new Float32Array(numComps);
  39236. for (var i = 0; i < numComps; ++i) {
  39237. this.defaultColor[i] = 1;
  39238. }
  39239. this.base = base;
  39240. this.tintFn = tintFn;
  39241. this.tmpBuf = new Float32Array(base.numComps);
  39242. }
  39243. AlternateCS.prototype = {
  39244. getRgb: ColorSpace.prototype.getRgb,
  39245. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  39246. dest, destOffset) {
  39247. var tmpBuf = this.tmpBuf;
  39248. this.tintFn(src, srcOffset, tmpBuf, 0);
  39249. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  39250. },
  39251. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  39252. dest, destOffset, bits,
  39253. alpha01) {
  39254. var tintFn = this.tintFn;
  39255. var base = this.base;
  39256. var scale = 1 / ((1 << bits) - 1);
  39257. var baseNumComps = base.numComps;
  39258. var usesZeroToOneRange = base.usesZeroToOneRange;
  39259. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  39260. alpha01 === 0;
  39261. var pos = isPassthrough ? destOffset : 0;
  39262. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  39263. var numComps = this.numComps;
  39264. var scaled = new Float32Array(numComps);
  39265. var tinted = new Float32Array(baseNumComps);
  39266. var i, j;
  39267. if (usesZeroToOneRange) {
  39268. for (i = 0; i < count; i++) {
  39269. for (j = 0; j < numComps; j++) {
  39270. scaled[j] = src[srcOffset++] * scale;
  39271. }
  39272. tintFn(scaled, 0, tinted, 0);
  39273. for (j = 0; j < baseNumComps; j++) {
  39274. baseBuf[pos++] = tinted[j] * 255;
  39275. }
  39276. }
  39277. } else {
  39278. for (i = 0; i < count; i++) {
  39279. for (j = 0; j < numComps; j++) {
  39280. scaled[j] = src[srcOffset++] * scale;
  39281. }
  39282. tintFn(scaled, 0, tinted, 0);
  39283. base.getRgbItem(tinted, 0, baseBuf, pos);
  39284. pos += baseNumComps;
  39285. }
  39286. }
  39287. if (!isPassthrough) {
  39288. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  39289. }
  39290. },
  39291. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  39292. alpha01) {
  39293. return this.base.getOutputLength(inputLength *
  39294. this.base.numComps / this.numComps,
  39295. alpha01);
  39296. },
  39297. isPassthrough: ColorSpace.prototype.isPassthrough,
  39298. fillRgb: ColorSpace.prototype.fillRgb,
  39299. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  39300. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39301. },
  39302. usesZeroToOneRange: true
  39303. };
  39304. return AlternateCS;
  39305. })();
  39306. var PatternCS = (function PatternCSClosure() {
  39307. function PatternCS(baseCS) {
  39308. this.name = 'Pattern';
  39309. this.base = baseCS;
  39310. }
  39311. PatternCS.prototype = {};
  39312. return PatternCS;
  39313. })();
  39314. var IndexedCS = (function IndexedCSClosure() {
  39315. function IndexedCS(base, highVal, lookup) {
  39316. this.name = 'Indexed';
  39317. this.numComps = 1;
  39318. this.defaultColor = new Uint8Array([0]);
  39319. this.base = base;
  39320. this.highVal = highVal;
  39321. var baseNumComps = base.numComps;
  39322. var length = baseNumComps * highVal;
  39323. var lookupArray;
  39324. if (isStream(lookup)) {
  39325. lookupArray = new Uint8Array(length);
  39326. var bytes = lookup.getBytes(length);
  39327. lookupArray.set(bytes);
  39328. } else if (isString(lookup)) {
  39329. lookupArray = new Uint8Array(length);
  39330. for (var i = 0; i < length; ++i) {
  39331. lookupArray[i] = lookup.charCodeAt(i);
  39332. }
  39333. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  39334. lookupArray = lookup;
  39335. } else {
  39336. error('Unrecognized lookup table: ' + lookup);
  39337. }
  39338. this.lookup = lookupArray;
  39339. }
  39340. IndexedCS.prototype = {
  39341. getRgb: ColorSpace.prototype.getRgb,
  39342. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  39343. dest, destOffset) {
  39344. var numComps = this.base.numComps;
  39345. var start = src[srcOffset] * numComps;
  39346. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  39347. },
  39348. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  39349. dest, destOffset, bits,
  39350. alpha01) {
  39351. var base = this.base;
  39352. var numComps = base.numComps;
  39353. var outputDelta = base.getOutputLength(numComps, alpha01);
  39354. var lookup = this.lookup;
  39355. for (var i = 0; i < count; ++i) {
  39356. var lookupPos = src[srcOffset++] * numComps;
  39357. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  39358. destOffset += outputDelta;
  39359. }
  39360. },
  39361. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  39362. return this.base.getOutputLength(inputLength * this.base.numComps,
  39363. alpha01);
  39364. },
  39365. isPassthrough: ColorSpace.prototype.isPassthrough,
  39366. fillRgb: ColorSpace.prototype.fillRgb,
  39367. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  39368. // indexed color maps shouldn't be changed
  39369. return true;
  39370. },
  39371. usesZeroToOneRange: true
  39372. };
  39373. return IndexedCS;
  39374. })();
  39375. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  39376. function DeviceGrayCS() {
  39377. this.name = 'DeviceGray';
  39378. this.numComps = 1;
  39379. this.defaultColor = new Float32Array([0]);
  39380. }
  39381. DeviceGrayCS.prototype = {
  39382. getRgb: ColorSpace.prototype.getRgb,
  39383. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  39384. dest, destOffset) {
  39385. var c = (src[srcOffset] * 255) | 0;
  39386. c = c < 0 ? 0 : c > 255 ? 255 : c;
  39387. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  39388. },
  39389. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  39390. dest, destOffset, bits,
  39391. alpha01) {
  39392. var scale = 255 / ((1 << bits) - 1);
  39393. var j = srcOffset, q = destOffset;
  39394. for (var i = 0; i < count; ++i) {
  39395. var c = (scale * src[j++]) | 0;
  39396. dest[q++] = c;
  39397. dest[q++] = c;
  39398. dest[q++] = c;
  39399. q += alpha01;
  39400. }
  39401. },
  39402. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  39403. alpha01) {
  39404. return inputLength * (3 + alpha01);
  39405. },
  39406. isPassthrough: ColorSpace.prototype.isPassthrough,
  39407. fillRgb: ColorSpace.prototype.fillRgb,
  39408. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  39409. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39410. },
  39411. usesZeroToOneRange: true
  39412. };
  39413. return DeviceGrayCS;
  39414. })();
  39415. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  39416. function DeviceRgbCS() {
  39417. this.name = 'DeviceRGB';
  39418. this.numComps = 3;
  39419. this.defaultColor = new Float32Array([0, 0, 0]);
  39420. }
  39421. DeviceRgbCS.prototype = {
  39422. getRgb: ColorSpace.prototype.getRgb,
  39423. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  39424. dest, destOffset) {
  39425. var r = (src[srcOffset] * 255) | 0;
  39426. var g = (src[srcOffset + 1] * 255) | 0;
  39427. var b = (src[srcOffset + 2] * 255) | 0;
  39428. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  39429. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  39430. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  39431. },
  39432. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  39433. dest, destOffset, bits,
  39434. alpha01) {
  39435. if (bits === 8 && alpha01 === 0) {
  39436. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  39437. return;
  39438. }
  39439. var scale = 255 / ((1 << bits) - 1);
  39440. var j = srcOffset, q = destOffset;
  39441. for (var i = 0; i < count; ++i) {
  39442. dest[q++] = (scale * src[j++]) | 0;
  39443. dest[q++] = (scale * src[j++]) | 0;
  39444. dest[q++] = (scale * src[j++]) | 0;
  39445. q += alpha01;
  39446. }
  39447. },
  39448. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  39449. alpha01) {
  39450. return (inputLength * (3 + alpha01) / 3) | 0;
  39451. },
  39452. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  39453. return bits === 8;
  39454. },
  39455. fillRgb: ColorSpace.prototype.fillRgb,
  39456. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  39457. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39458. },
  39459. usesZeroToOneRange: true
  39460. };
  39461. return DeviceRgbCS;
  39462. })();
  39463. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  39464. // The coefficients below was found using numerical analysis: the method of
  39465. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  39466. // where color_value is the tabular value from the table of sampled RGB colors
  39467. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  39468. // CMYK color conversion using the estimation below:
  39469. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  39470. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  39471. var c = src[srcOffset + 0] * srcScale;
  39472. var m = src[srcOffset + 1] * srcScale;
  39473. var y = src[srcOffset + 2] * srcScale;
  39474. var k = src[srcOffset + 3] * srcScale;
  39475. var r =
  39476. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  39477. 18.82290502165302 * y + 212.25662451639585 * k +
  39478. -285.2331026137004) +
  39479. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  39480. -17.873870861415444 * k - 5.497006427196366) +
  39481. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39482. 17.5119270841813) +
  39483. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  39484. var g =
  39485. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  39486. 6.871425592049007 * y + 31.159100130055922 * k +
  39487. -79.2970844816548) +
  39488. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39489. 131.35250912493976 * k - 190.9453302588951) +
  39490. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  39491. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  39492. var b =
  39493. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39494. 30.89978309703729 * y - 0.23883238689178934 * k +
  39495. -14.183576799673286) +
  39496. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39497. 50.606957656360734 * k - 112.23884253719248) +
  39498. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  39499. -193.58209356861505) +
  39500. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  39501. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  39502. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  39503. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  39504. }
  39505. function DeviceCmykCS() {
  39506. this.name = 'DeviceCMYK';
  39507. this.numComps = 4;
  39508. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  39509. }
  39510. DeviceCmykCS.prototype = {
  39511. getRgb: ColorSpace.prototype.getRgb,
  39512. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  39513. dest, destOffset) {
  39514. convertToRgb(src, srcOffset, 1, dest, destOffset);
  39515. },
  39516. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  39517. dest, destOffset, bits,
  39518. alpha01) {
  39519. var scale = 1 / ((1 << bits) - 1);
  39520. for (var i = 0; i < count; i++) {
  39521. convertToRgb(src, srcOffset, scale, dest, destOffset);
  39522. srcOffset += 4;
  39523. destOffset += 3 + alpha01;
  39524. }
  39525. },
  39526. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  39527. alpha01) {
  39528. return (inputLength / 4 * (3 + alpha01)) | 0;
  39529. },
  39530. isPassthrough: ColorSpace.prototype.isPassthrough,
  39531. fillRgb: ColorSpace.prototype.fillRgb,
  39532. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  39533. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39534. },
  39535. usesZeroToOneRange: true
  39536. };
  39537. return DeviceCmykCS;
  39538. })();
  39539. //
  39540. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  39541. //
  39542. var CalGrayCS = (function CalGrayCSClosure() {
  39543. function CalGrayCS(whitePoint, blackPoint, gamma) {
  39544. this.name = 'CalGray';
  39545. this.numComps = 1;
  39546. this.defaultColor = new Float32Array([0]);
  39547. if (!whitePoint) {
  39548. error('WhitePoint missing - required for color space CalGray');
  39549. }
  39550. blackPoint = blackPoint || [0, 0, 0];
  39551. gamma = gamma || 1;
  39552. // Translate arguments to spec variables.
  39553. this.XW = whitePoint[0];
  39554. this.YW = whitePoint[1];
  39555. this.ZW = whitePoint[2];
  39556. this.XB = blackPoint[0];
  39557. this.YB = blackPoint[1];
  39558. this.ZB = blackPoint[2];
  39559. this.G = gamma;
  39560. // Validate variables as per spec.
  39561. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39562. error('Invalid WhitePoint components for ' + this.name +
  39563. ', no fallback available');
  39564. }
  39565. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39566. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  39567. this.XB = this.YB = this.ZB = 0;
  39568. }
  39569. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  39570. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  39571. ', ZB: ' + this.ZB + ', only default values are supported.');
  39572. }
  39573. if (this.G < 1) {
  39574. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  39575. ', falling back to default');
  39576. this.G = 1;
  39577. }
  39578. }
  39579. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39580. // A represents a gray component of a calibrated gray space.
  39581. // A <---> AG in the spec
  39582. var A = src[srcOffset] * scale;
  39583. var AG = Math.pow(A, cs.G);
  39584. // Computes L as per spec. ( = cs.YW * AG )
  39585. // Except if other than default BlackPoint values are used.
  39586. var L = cs.YW * AG;
  39587. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  39588. // Convert values to rgb range [0, 255].
  39589. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  39590. dest[destOffset] = val;
  39591. dest[destOffset + 1] = val;
  39592. dest[destOffset + 2] = val;
  39593. }
  39594. CalGrayCS.prototype = {
  39595. getRgb: ColorSpace.prototype.getRgb,
  39596. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  39597. dest, destOffset) {
  39598. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39599. },
  39600. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  39601. dest, destOffset, bits,
  39602. alpha01) {
  39603. var scale = 1 / ((1 << bits) - 1);
  39604. for (var i = 0; i < count; ++i) {
  39605. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39606. srcOffset += 1;
  39607. destOffset += 3 + alpha01;
  39608. }
  39609. },
  39610. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  39611. return inputLength * (3 + alpha01);
  39612. },
  39613. isPassthrough: ColorSpace.prototype.isPassthrough,
  39614. fillRgb: ColorSpace.prototype.fillRgb,
  39615. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  39616. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39617. },
  39618. usesZeroToOneRange: true
  39619. };
  39620. return CalGrayCS;
  39621. })();
  39622. //
  39623. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  39624. //
  39625. var CalRGBCS = (function CalRGBCSClosure() {
  39626. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  39627. // matrices.
  39628. var BRADFORD_SCALE_MATRIX = new Float32Array([
  39629. 0.8951, 0.2664, -0.1614,
  39630. -0.7502, 1.7135, 0.0367,
  39631. 0.0389, -0.0685, 1.0296]);
  39632. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  39633. 0.9869929, -0.1470543, 0.1599627,
  39634. 0.4323053, 0.5183603, 0.0492912,
  39635. -0.0085287, 0.0400428, 0.9684867]);
  39636. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  39637. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  39638. 3.2404542, -1.5371385, -0.4985314,
  39639. -0.9692660, 1.8760108, 0.0415560,
  39640. 0.0556434, -0.2040259, 1.0572252]);
  39641. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  39642. var tempNormalizeMatrix = new Float32Array(3);
  39643. var tempConvertMatrix1 = new Float32Array(3);
  39644. var tempConvertMatrix2 = new Float32Array(3);
  39645. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  39646. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  39647. this.name = 'CalRGB';
  39648. this.numComps = 3;
  39649. this.defaultColor = new Float32Array(3);
  39650. if (!whitePoint) {
  39651. error('WhitePoint missing - required for color space CalRGB');
  39652. }
  39653. blackPoint = blackPoint || new Float32Array(3);
  39654. gamma = gamma || new Float32Array([1, 1, 1]);
  39655. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  39656. // Translate arguments to spec variables.
  39657. var XW = whitePoint[0];
  39658. var YW = whitePoint[1];
  39659. var ZW = whitePoint[2];
  39660. this.whitePoint = whitePoint;
  39661. var XB = blackPoint[0];
  39662. var YB = blackPoint[1];
  39663. var ZB = blackPoint[2];
  39664. this.blackPoint = blackPoint;
  39665. this.GR = gamma[0];
  39666. this.GG = gamma[1];
  39667. this.GB = gamma[2];
  39668. this.MXA = matrix[0];
  39669. this.MYA = matrix[1];
  39670. this.MZA = matrix[2];
  39671. this.MXB = matrix[3];
  39672. this.MYB = matrix[4];
  39673. this.MZB = matrix[5];
  39674. this.MXC = matrix[6];
  39675. this.MYC = matrix[7];
  39676. this.MZC = matrix[8];
  39677. // Validate variables as per spec.
  39678. if (XW < 0 || ZW < 0 || YW !== 1) {
  39679. error('Invalid WhitePoint components for ' + this.name +
  39680. ', no fallback available');
  39681. }
  39682. if (XB < 0 || YB < 0 || ZB < 0) {
  39683. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  39684. ', ' + ZB + '], falling back to default');
  39685. this.blackPoint = new Float32Array(3);
  39686. }
  39687. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  39688. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  39689. '] for ' + this.name + ', falling back to default');
  39690. this.GR = this.GG = this.GB = 1;
  39691. }
  39692. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  39693. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  39694. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  39695. info('Invalid Matrix for ' + this.name + ' [' +
  39696. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  39697. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  39698. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  39699. '], falling back to default');
  39700. this.MXA = this.MYB = this.MZC = 1;
  39701. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  39702. }
  39703. }
  39704. function matrixProduct(a, b, result) {
  39705. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  39706. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  39707. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  39708. }
  39709. function convertToFlat(sourceWhitePoint, LMS, result) {
  39710. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  39711. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  39712. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  39713. }
  39714. function convertToD65(sourceWhitePoint, LMS, result) {
  39715. var D65X = 0.95047;
  39716. var D65Y = 1;
  39717. var D65Z = 1.08883;
  39718. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  39719. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  39720. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  39721. }
  39722. function sRGBTransferFunction(color) {
  39723. // See http://en.wikipedia.org/wiki/SRGB.
  39724. if (color <= 0.0031308){
  39725. return adjustToRange(0, 1, 12.92 * color);
  39726. }
  39727. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  39728. }
  39729. function adjustToRange(min, max, value) {
  39730. return Math.max(min, Math.min(max, value));
  39731. }
  39732. function decodeL(L) {
  39733. if (L < 0) {
  39734. return -decodeL(-L);
  39735. }
  39736. if (L > 8.0) {
  39737. return Math.pow(((L + 16) / 116), 3);
  39738. }
  39739. return L * DECODE_L_CONSTANT;
  39740. }
  39741. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  39742. // In case the blackPoint is already the default blackPoint then there is
  39743. // no need to do compensation.
  39744. if (sourceBlackPoint[0] === 0 &&
  39745. sourceBlackPoint[1] === 0 &&
  39746. sourceBlackPoint[2] === 0) {
  39747. result[0] = XYZ_Flat[0];
  39748. result[1] = XYZ_Flat[1];
  39749. result[2] = XYZ_Flat[2];
  39750. return;
  39751. }
  39752. // For the blackPoint calculation details, please see
  39753. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39754. // AdobeBPC.pdf.
  39755. // The destination blackPoint is the default blackPoint [0, 0, 0].
  39756. var zeroDecodeL = decodeL(0);
  39757. var X_DST = zeroDecodeL;
  39758. var X_SRC = decodeL(sourceBlackPoint[0]);
  39759. var Y_DST = zeroDecodeL;
  39760. var Y_SRC = decodeL(sourceBlackPoint[1]);
  39761. var Z_DST = zeroDecodeL;
  39762. var Z_SRC = decodeL(sourceBlackPoint[2]);
  39763. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  39764. var X_Offset = 1 - X_Scale;
  39765. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  39766. var Y_Offset = 1 - Y_Scale;
  39767. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  39768. var Z_Offset = 1 - Z_Scale;
  39769. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  39770. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  39771. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  39772. }
  39773. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  39774. // In case the whitePoint is already flat then there is no need to do
  39775. // normalization.
  39776. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  39777. result[0] = XYZ_In[0];
  39778. result[1] = XYZ_In[1];
  39779. result[2] = XYZ_In[2];
  39780. return;
  39781. }
  39782. var LMS = result;
  39783. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39784. var LMS_Flat = tempNormalizeMatrix;
  39785. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  39786. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  39787. }
  39788. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  39789. var LMS = result;
  39790. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39791. var LMS_D65 = tempNormalizeMatrix;
  39792. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  39793. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  39794. }
  39795. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39796. // A, B and C represent a red, green and blue components of a calibrated
  39797. // rgb space.
  39798. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  39799. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  39800. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  39801. // A <---> AGR in the spec
  39802. // B <---> BGG in the spec
  39803. // C <---> CGB in the spec
  39804. var AGR = Math.pow(A, cs.GR);
  39805. var BGG = Math.pow(B, cs.GG);
  39806. var CGB = Math.pow(C, cs.GB);
  39807. // Computes intermediate variables L, M, N as per spec.
  39808. // To decode X, Y, Z values map L, M, N directly to them.
  39809. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  39810. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  39811. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  39812. // The following calculations are based on this document:
  39813. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39814. // AdobeBPC.pdf.
  39815. var XYZ = tempConvertMatrix1;
  39816. XYZ[0] = X;
  39817. XYZ[1] = Y;
  39818. XYZ[2] = Z;
  39819. var XYZ_Flat = tempConvertMatrix2;
  39820. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  39821. var XYZ_Black = tempConvertMatrix1;
  39822. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  39823. var XYZ_D65 = tempConvertMatrix2;
  39824. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  39825. var SRGB = tempConvertMatrix1;
  39826. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  39827. var sR = sRGBTransferFunction(SRGB[0]);
  39828. var sG = sRGBTransferFunction(SRGB[1]);
  39829. var sB = sRGBTransferFunction(SRGB[2]);
  39830. // Convert the values to rgb range [0, 255].
  39831. dest[destOffset] = Math.round(sR * 255);
  39832. dest[destOffset + 1] = Math.round(sG * 255);
  39833. dest[destOffset + 2] = Math.round(sB * 255);
  39834. }
  39835. CalRGBCS.prototype = {
  39836. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39837. var rgb = new Uint8Array(3);
  39838. this.getRgbItem(src, srcOffset, rgb, 0);
  39839. return rgb;
  39840. },
  39841. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39842. dest, destOffset) {
  39843. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39844. },
  39845. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39846. dest, destOffset, bits,
  39847. alpha01) {
  39848. var scale = 1 / ((1 << bits) - 1);
  39849. for (var i = 0; i < count; ++i) {
  39850. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39851. srcOffset += 3;
  39852. destOffset += 3 + alpha01;
  39853. }
  39854. },
  39855. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39856. return (inputLength * (3 + alpha01) / 3) | 0;
  39857. },
  39858. isPassthrough: ColorSpace.prototype.isPassthrough,
  39859. fillRgb: ColorSpace.prototype.fillRgb,
  39860. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39861. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39862. },
  39863. usesZeroToOneRange: true
  39864. };
  39865. return CalRGBCS;
  39866. })();
  39867. //
  39868. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39869. //
  39870. var LabCS = (function LabCSClosure() {
  39871. function LabCS(whitePoint, blackPoint, range) {
  39872. this.name = 'Lab';
  39873. this.numComps = 3;
  39874. this.defaultColor = new Float32Array([0, 0, 0]);
  39875. if (!whitePoint) {
  39876. error('WhitePoint missing - required for color space Lab');
  39877. }
  39878. blackPoint = blackPoint || [0, 0, 0];
  39879. range = range || [-100, 100, -100, 100];
  39880. // Translate args to spec variables
  39881. this.XW = whitePoint[0];
  39882. this.YW = whitePoint[1];
  39883. this.ZW = whitePoint[2];
  39884. this.amin = range[0];
  39885. this.amax = range[1];
  39886. this.bmin = range[2];
  39887. this.bmax = range[3];
  39888. // These are here just for completeness - the spec doesn't offer any
  39889. // formulas that use BlackPoint in Lab
  39890. this.XB = blackPoint[0];
  39891. this.YB = blackPoint[1];
  39892. this.ZB = blackPoint[2];
  39893. // Validate vars as per spec
  39894. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39895. error('Invalid WhitePoint components, no fallback available');
  39896. }
  39897. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39898. info('Invalid BlackPoint, falling back to default');
  39899. this.XB = this.YB = this.ZB = 0;
  39900. }
  39901. if (this.amin > this.amax || this.bmin > this.bmax) {
  39902. info('Invalid Range, falling back to defaults');
  39903. this.amin = -100;
  39904. this.amax = 100;
  39905. this.bmin = -100;
  39906. this.bmax = 100;
  39907. }
  39908. }
  39909. // Function g(x) from spec
  39910. function fn_g(x) {
  39911. if (x >= 6 / 29) {
  39912. return x * x * x;
  39913. } else {
  39914. return (108 / 841) * (x - 4 / 29);
  39915. }
  39916. }
  39917. function decode(value, high1, low2, high2) {
  39918. return low2 + (value) * (high2 - low2) / (high1);
  39919. }
  39920. // If decoding is needed maxVal should be 2^bits per component - 1.
  39921. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39922. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39923. // not the usual [0, 1]. If a command like setFillColor is used the src
  39924. // values will already be within the correct range. However, if we are
  39925. // converting an image we have to map the values to the correct range given
  39926. // above.
  39927. // Ls,as,bs <---> L*,a*,b* in the spec
  39928. var Ls = src[srcOffset];
  39929. var as = src[srcOffset + 1];
  39930. var bs = src[srcOffset + 2];
  39931. if (maxVal !== false) {
  39932. Ls = decode(Ls, maxVal, 0, 100);
  39933. as = decode(as, maxVal, cs.amin, cs.amax);
  39934. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39935. }
  39936. // Adjust limits of 'as' and 'bs'
  39937. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39938. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39939. // Computes intermediate variables X,Y,Z as per spec
  39940. var M = (Ls + 16) / 116;
  39941. var L = M + (as / 500);
  39942. var N = M - (bs / 200);
  39943. var X = cs.XW * fn_g(L);
  39944. var Y = cs.YW * fn_g(M);
  39945. var Z = cs.ZW * fn_g(N);
  39946. var r, g, b;
  39947. // Using different conversions for D50 and D65 white points,
  39948. // per http://www.color.org/srgb.pdf
  39949. if (cs.ZW < 1) {
  39950. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39951. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39952. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39953. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39954. } else {
  39955. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39956. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39957. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39958. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39959. }
  39960. // clamp color values to [0,1] range then convert to [0,255] range.
  39961. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39962. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39963. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39964. }
  39965. LabCS.prototype = {
  39966. getRgb: ColorSpace.prototype.getRgb,
  39967. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39968. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39969. },
  39970. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39971. dest, destOffset, bits,
  39972. alpha01) {
  39973. var maxVal = (1 << bits) - 1;
  39974. for (var i = 0; i < count; i++) {
  39975. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39976. srcOffset += 3;
  39977. destOffset += 3 + alpha01;
  39978. }
  39979. },
  39980. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39981. return (inputLength * (3 + alpha01) / 3) | 0;
  39982. },
  39983. isPassthrough: ColorSpace.prototype.isPassthrough,
  39984. fillRgb: ColorSpace.prototype.fillRgb,
  39985. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39986. // XXX: Decoding is handled with the lab conversion because of the strange
  39987. // ranges that are used.
  39988. return true;
  39989. },
  39990. usesZeroToOneRange: false
  39991. };
  39992. return LabCS;
  39993. })();
  39994. // TODO refactor to remove dependency on image.js
  39995. function _setCoreImage(coreImage_) {
  39996. coreImage = coreImage_;
  39997. PDFImage = coreImage_.PDFImage;
  39998. }
  39999. exports._setCoreImage = _setCoreImage;
  40000. exports.ColorSpace = ColorSpace;
  40001. // TODO refactor to remove dependency on colorspace.js
  40002. coreStream._setCoreColorSpace(exports);
  40003. }));
  40004. (function (root, factory) {
  40005. {
  40006. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  40007. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  40008. root.pdfjsCoreJpx);
  40009. }
  40010. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  40011. coreStream, coreJpx) {
  40012. var ImageKind = sharedUtil.ImageKind;
  40013. var assert = sharedUtil.assert;
  40014. var error = sharedUtil.error;
  40015. var info = sharedUtil.info;
  40016. var isArray = sharedUtil.isArray;
  40017. var warn = sharedUtil.warn;
  40018. var Name = corePrimitives.Name;
  40019. var isStream = corePrimitives.isStream;
  40020. var ColorSpace = coreColorSpace.ColorSpace;
  40021. var DecodeStream = coreStream.DecodeStream;
  40022. var Stream = coreStream.Stream;
  40023. var JpegStream = coreStream.JpegStream;
  40024. var JpxImage = coreJpx.JpxImage;
  40025. var PDFImage = (function PDFImageClosure() {
  40026. /**
  40027. * Decode the image in the main thread if it supported. Resovles the promise
  40028. * when the image data is ready.
  40029. */
  40030. function handleImageData(handler, xref, res, image) {
  40031. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  40032. // For natively supported jpegs send them to the main thread for decoding.
  40033. var dict = image.dict;
  40034. var colorSpace = dict.get('ColorSpace', 'CS');
  40035. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  40036. var numComps = colorSpace.numComps;
  40037. var decodePromise = handler.sendWithPromise('JpegDecode',
  40038. [image.getIR(), numComps]);
  40039. return decodePromise.then(function (message) {
  40040. var data = message.data;
  40041. return new Stream(data, 0, data.length, image.dict);
  40042. });
  40043. } else {
  40044. return Promise.resolve(image);
  40045. }
  40046. }
  40047. /**
  40048. * Decode and clamp a value. The formula is different from the spec because we
  40049. * don't decode to float range [0,1], we decode it in the [0,max] range.
  40050. */
  40051. function decodeAndClamp(value, addend, coefficient, max) {
  40052. value = addend + value * coefficient;
  40053. // Clamp the value to the range
  40054. return (value < 0 ? 0 : (value > max ? max : value));
  40055. }
  40056. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  40057. this.image = image;
  40058. var dict = image.dict;
  40059. if (dict.has('Filter')) {
  40060. var filter = dict.get('Filter').name;
  40061. if (filter === 'JPXDecode') {
  40062. var jpxImage = new JpxImage();
  40063. jpxImage.parseImageProperties(image.stream);
  40064. image.stream.reset();
  40065. image.bitsPerComponent = jpxImage.bitsPerComponent;
  40066. image.numComps = jpxImage.componentsCount;
  40067. } else if (filter === 'JBIG2Decode') {
  40068. image.bitsPerComponent = 1;
  40069. image.numComps = 1;
  40070. }
  40071. }
  40072. // TODO cache rendered images?
  40073. this.width = dict.get('Width', 'W');
  40074. this.height = dict.get('Height', 'H');
  40075. if (this.width < 1 || this.height < 1) {
  40076. error('Invalid image width: ' + this.width + ' or height: ' +
  40077. this.height);
  40078. }
  40079. this.interpolate = dict.get('Interpolate', 'I') || false;
  40080. this.imageMask = dict.get('ImageMask', 'IM') || false;
  40081. this.matte = dict.get('Matte') || false;
  40082. var bitsPerComponent = image.bitsPerComponent;
  40083. if (!bitsPerComponent) {
  40084. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  40085. if (!bitsPerComponent) {
  40086. if (this.imageMask) {
  40087. bitsPerComponent = 1;
  40088. } else {
  40089. error('Bits per component missing in image: ' + this.imageMask);
  40090. }
  40091. }
  40092. }
  40093. this.bpc = bitsPerComponent;
  40094. if (!this.imageMask) {
  40095. var colorSpace = dict.get('ColorSpace', 'CS');
  40096. if (!colorSpace) {
  40097. info('JPX images (which do not require color spaces)');
  40098. switch (image.numComps) {
  40099. case 1:
  40100. colorSpace = Name.get('DeviceGray');
  40101. break;
  40102. case 3:
  40103. colorSpace = Name.get('DeviceRGB');
  40104. break;
  40105. case 4:
  40106. colorSpace = Name.get('DeviceCMYK');
  40107. break;
  40108. default:
  40109. error('JPX images with ' + this.numComps +
  40110. ' color components not supported.');
  40111. }
  40112. }
  40113. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  40114. this.numComps = this.colorSpace.numComps;
  40115. }
  40116. this.decode = dict.get('Decode', 'D');
  40117. this.needsDecode = false;
  40118. if (this.decode &&
  40119. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  40120. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  40121. this.needsDecode = true;
  40122. // Do some preprocessing to avoid more math.
  40123. var max = (1 << bitsPerComponent) - 1;
  40124. this.decodeCoefficients = [];
  40125. this.decodeAddends = [];
  40126. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  40127. var dmin = this.decode[i];
  40128. var dmax = this.decode[i + 1];
  40129. this.decodeCoefficients[j] = dmax - dmin;
  40130. this.decodeAddends[j] = max * dmin;
  40131. }
  40132. }
  40133. if (smask) {
  40134. this.smask = new PDFImage(xref, res, smask, false);
  40135. } else if (mask) {
  40136. if (isStream(mask)) {
  40137. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  40138. if (!imageMask) {
  40139. warn('Ignoring /Mask in image without /ImageMask.');
  40140. } else {
  40141. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  40142. }
  40143. } else {
  40144. // Color key mask (just an array).
  40145. this.mask = mask;
  40146. }
  40147. }
  40148. }
  40149. /**
  40150. * Handles processing of image data and returns the Promise that is resolved
  40151. * with a PDFImage when the image is ready to be used.
  40152. */
  40153. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  40154. res, image, inline) {
  40155. var imagePromise = handleImageData(handler, xref, res, image);
  40156. var smaskPromise;
  40157. var maskPromise;
  40158. var smask = image.dict.get('SMask');
  40159. var mask = image.dict.get('Mask');
  40160. if (smask) {
  40161. smaskPromise = handleImageData(handler, xref, res, smask);
  40162. maskPromise = Promise.resolve(null);
  40163. } else {
  40164. smaskPromise = Promise.resolve(null);
  40165. if (mask) {
  40166. if (isStream(mask)) {
  40167. maskPromise = handleImageData(handler, xref, res, mask);
  40168. } else if (isArray(mask)) {
  40169. maskPromise = Promise.resolve(mask);
  40170. } else {
  40171. warn('Unsupported mask format.');
  40172. maskPromise = Promise.resolve(null);
  40173. }
  40174. } else {
  40175. maskPromise = Promise.resolve(null);
  40176. }
  40177. }
  40178. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  40179. function(results) {
  40180. var imageData = results[0];
  40181. var smaskData = results[1];
  40182. var maskData = results[2];
  40183. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  40184. });
  40185. };
  40186. /**
  40187. * Resize an image using the nearest neighbor algorithm. Currently only
  40188. * supports one and three component images.
  40189. * @param {TypedArray} pixels The original image with one component.
  40190. * @param {Number} bpc Number of bits per component.
  40191. * @param {Number} components Number of color components, 1 or 3 is supported.
  40192. * @param {Number} w1 Original width.
  40193. * @param {Number} h1 Original height.
  40194. * @param {Number} w2 New width.
  40195. * @param {Number} h2 New height.
  40196. * @param {TypedArray} dest (Optional) The destination buffer.
  40197. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  40198. * @return {TypedArray} Resized image data.
  40199. */
  40200. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  40201. w1, h1, w2, h2, dest, alpha01) {
  40202. if (components !== 1 && components !== 3) {
  40203. error('Unsupported component count for resizing.');
  40204. }
  40205. var length = w2 * h2 * components;
  40206. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  40207. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40208. var xRatio = w1 / w2;
  40209. var yRatio = h1 / h2;
  40210. var i, j, py, newIndex = 0, oldIndex;
  40211. var xScaled = new Uint16Array(w2);
  40212. var w1Scanline = w1 * components;
  40213. if (alpha01 !== 1) {
  40214. alpha01 = 0;
  40215. }
  40216. for (j = 0; j < w2; j++) {
  40217. xScaled[j] = Math.floor(j * xRatio) * components;
  40218. }
  40219. if (components === 1) {
  40220. for (i = 0; i < h2; i++) {
  40221. py = Math.floor(i * yRatio) * w1Scanline;
  40222. for (j = 0; j < w2; j++) {
  40223. oldIndex = py + xScaled[j];
  40224. temp[newIndex++] = pixels[oldIndex];
  40225. }
  40226. }
  40227. } else if (components === 3) {
  40228. for (i = 0; i < h2; i++) {
  40229. py = Math.floor(i * yRatio) * w1Scanline;
  40230. for (j = 0; j < w2; j++) {
  40231. oldIndex = py + xScaled[j];
  40232. temp[newIndex++] = pixels[oldIndex++];
  40233. temp[newIndex++] = pixels[oldIndex++];
  40234. temp[newIndex++] = pixels[oldIndex++];
  40235. newIndex += alpha01;
  40236. }
  40237. }
  40238. }
  40239. return temp;
  40240. };
  40241. PDFImage.createMask =
  40242. function PDFImage_createMask(imgArray, width, height,
  40243. imageIsFromDecodeStream, inverseDecode) {
  40244. // |imgArray| might not contain full data for every pixel of the mask, so
  40245. // we need to distinguish between |computedLength| and |actualLength|.
  40246. // In particular, if inverseDecode is true, then the array we return must
  40247. // have a length of |computedLength|.
  40248. var computedLength = ((width + 7) >> 3) * height;
  40249. var actualLength = imgArray.byteLength;
  40250. var haveFullData = computedLength === actualLength;
  40251. var data, i;
  40252. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  40253. // imgArray came from a DecodeStream and its data is in an appropriate
  40254. // form, so we can just transfer it.
  40255. data = imgArray;
  40256. } else if (!inverseDecode) {
  40257. data = new Uint8Array(actualLength);
  40258. data.set(imgArray);
  40259. } else {
  40260. data = new Uint8Array(computedLength);
  40261. data.set(imgArray);
  40262. for (i = actualLength; i < computedLength; i++) {
  40263. data[i] = 0xff;
  40264. }
  40265. }
  40266. // If necessary, invert the original mask data (but not any extra we might
  40267. // have added above). It's safe to modify the array -- whether it's the
  40268. // original or a copy, we're about to transfer it anyway, so nothing else
  40269. // in this thread can be relying on its contents.
  40270. if (inverseDecode) {
  40271. for (i = 0; i < actualLength; i++) {
  40272. data[i] = ~data[i];
  40273. }
  40274. }
  40275. return {data: data, width: width, height: height};
  40276. };
  40277. PDFImage.prototype = {
  40278. get drawWidth() {
  40279. return Math.max(this.width,
  40280. this.smask && this.smask.width || 0,
  40281. this.mask && this.mask.width || 0);
  40282. },
  40283. get drawHeight() {
  40284. return Math.max(this.height,
  40285. this.smask && this.smask.height || 0,
  40286. this.mask && this.mask.height || 0);
  40287. },
  40288. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  40289. var bpc = this.bpc;
  40290. var numComps = this.numComps;
  40291. var decodeAddends = this.decodeAddends;
  40292. var decodeCoefficients = this.decodeCoefficients;
  40293. var max = (1 << bpc) - 1;
  40294. var i, ii;
  40295. if (bpc === 1) {
  40296. // If the buffer needed decode that means it just needs to be inverted.
  40297. for (i = 0, ii = buffer.length; i < ii; i++) {
  40298. buffer[i] = +!(buffer[i]);
  40299. }
  40300. return;
  40301. }
  40302. var index = 0;
  40303. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  40304. for (var j = 0; j < numComps; j++) {
  40305. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  40306. decodeCoefficients[j], max);
  40307. index++;
  40308. }
  40309. }
  40310. },
  40311. getComponents: function PDFImage_getComponents(buffer) {
  40312. var bpc = this.bpc;
  40313. // This image doesn't require any extra work.
  40314. if (bpc === 8) {
  40315. return buffer;
  40316. }
  40317. var width = this.width;
  40318. var height = this.height;
  40319. var numComps = this.numComps;
  40320. var length = width * height * numComps;
  40321. var bufferPos = 0;
  40322. var output = (bpc <= 8 ? new Uint8Array(length) :
  40323. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40324. var rowComps = width * numComps;
  40325. var max = (1 << bpc) - 1;
  40326. var i = 0, ii, buf;
  40327. if (bpc === 1) {
  40328. // Optimization for reading 1 bpc images.
  40329. var mask, loop1End, loop2End;
  40330. for (var j = 0; j < height; j++) {
  40331. loop1End = i + (rowComps & ~7);
  40332. loop2End = i + rowComps;
  40333. // unroll loop for all full bytes
  40334. while (i < loop1End) {
  40335. buf = buffer[bufferPos++];
  40336. output[i] = (buf >> 7) & 1;
  40337. output[i + 1] = (buf >> 6) & 1;
  40338. output[i + 2] = (buf >> 5) & 1;
  40339. output[i + 3] = (buf >> 4) & 1;
  40340. output[i + 4] = (buf >> 3) & 1;
  40341. output[i + 5] = (buf >> 2) & 1;
  40342. output[i + 6] = (buf >> 1) & 1;
  40343. output[i + 7] = buf & 1;
  40344. i += 8;
  40345. }
  40346. // handle remaing bits
  40347. if (i < loop2End) {
  40348. buf = buffer[bufferPos++];
  40349. mask = 128;
  40350. while (i < loop2End) {
  40351. output[i++] = +!!(buf & mask);
  40352. mask >>= 1;
  40353. }
  40354. }
  40355. }
  40356. } else {
  40357. // The general case that handles all other bpc values.
  40358. var bits = 0;
  40359. buf = 0;
  40360. for (i = 0, ii = length; i < ii; ++i) {
  40361. if (i % rowComps === 0) {
  40362. buf = 0;
  40363. bits = 0;
  40364. }
  40365. while (bits < bpc) {
  40366. buf = (buf << 8) | buffer[bufferPos++];
  40367. bits += 8;
  40368. }
  40369. var remainingBits = bits - bpc;
  40370. var value = buf >> remainingBits;
  40371. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  40372. buf = buf & ((1 << remainingBits) - 1);
  40373. bits = remainingBits;
  40374. }
  40375. }
  40376. return output;
  40377. },
  40378. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  40379. actualHeight, image) {
  40380. var smask = this.smask;
  40381. var mask = this.mask;
  40382. var alphaBuf, sw, sh, i, ii, j;
  40383. if (smask) {
  40384. sw = smask.width;
  40385. sh = smask.height;
  40386. alphaBuf = new Uint8Array(sw * sh);
  40387. smask.fillGrayBuffer(alphaBuf);
  40388. if (sw !== width || sh !== height) {
  40389. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  40390. height);
  40391. }
  40392. } else if (mask) {
  40393. if (mask instanceof PDFImage) {
  40394. sw = mask.width;
  40395. sh = mask.height;
  40396. alphaBuf = new Uint8Array(sw * sh);
  40397. mask.numComps = 1;
  40398. mask.fillGrayBuffer(alphaBuf);
  40399. // Need to invert values in rgbaBuf
  40400. for (i = 0, ii = sw * sh; i < ii; ++i) {
  40401. alphaBuf[i] = 255 - alphaBuf[i];
  40402. }
  40403. if (sw !== width || sh !== height) {
  40404. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  40405. height);
  40406. }
  40407. } else if (isArray(mask)) {
  40408. // Color key mask: if any of the compontents are outside the range
  40409. // then they should be painted.
  40410. alphaBuf = new Uint8Array(width * height);
  40411. var numComps = this.numComps;
  40412. for (i = 0, ii = width * height; i < ii; ++i) {
  40413. var opacity = 0;
  40414. var imageOffset = i * numComps;
  40415. for (j = 0; j < numComps; ++j) {
  40416. var color = image[imageOffset + j];
  40417. var maskOffset = j * 2;
  40418. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  40419. opacity = 255;
  40420. break;
  40421. }
  40422. }
  40423. alphaBuf[i] = opacity;
  40424. }
  40425. } else {
  40426. error('Unknown mask format.');
  40427. }
  40428. }
  40429. if (alphaBuf) {
  40430. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40431. rgbaBuf[j] = alphaBuf[i];
  40432. }
  40433. } else {
  40434. // No mask.
  40435. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40436. rgbaBuf[j] = 255;
  40437. }
  40438. }
  40439. },
  40440. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  40441. var matte = this.smask && this.smask.matte;
  40442. if (!matte) {
  40443. return;
  40444. }
  40445. var matteRgb = this.colorSpace.getRgb(matte, 0);
  40446. var matteR = matteRgb[0];
  40447. var matteG = matteRgb[1];
  40448. var matteB = matteRgb[2];
  40449. var length = width * height * 4;
  40450. var r, g, b;
  40451. for (var i = 0; i < length; i += 4) {
  40452. var alpha = buffer[i + 3];
  40453. if (alpha === 0) {
  40454. // according formula we have to get Infinity in all components
  40455. // making it white (typical paper color) should be okay
  40456. buffer[i] = 255;
  40457. buffer[i + 1] = 255;
  40458. buffer[i + 2] = 255;
  40459. continue;
  40460. }
  40461. var k = 255 / alpha;
  40462. r = (buffer[i] - matteR) * k + matteR;
  40463. g = (buffer[i + 1] - matteG) * k + matteG;
  40464. b = (buffer[i + 2] - matteB) * k + matteB;
  40465. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  40466. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  40467. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  40468. }
  40469. },
  40470. createImageData: function PDFImage_createImageData(forceRGBA) {
  40471. var drawWidth = this.drawWidth;
  40472. var drawHeight = this.drawHeight;
  40473. var imgData = { // other fields are filled in below
  40474. width: drawWidth,
  40475. height: drawHeight
  40476. };
  40477. var numComps = this.numComps;
  40478. var originalWidth = this.width;
  40479. var originalHeight = this.height;
  40480. var bpc = this.bpc;
  40481. // Rows start at byte boundary.
  40482. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  40483. var imgArray;
  40484. if (!forceRGBA) {
  40485. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  40486. // without any complications, we pass a same-sized copy to the main
  40487. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  40488. // of memory for many scanned documents. It's also much faster.
  40489. //
  40490. // Similarly, if it is a 24-bit-per pixel RGB image without any
  40491. // complications, we avoid expanding by 1.333x to RGBA form.
  40492. var kind;
  40493. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  40494. kind = ImageKind.GRAYSCALE_1BPP;
  40495. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  40496. !this.needsDecode) {
  40497. kind = ImageKind.RGB_24BPP;
  40498. }
  40499. if (kind && !this.smask && !this.mask &&
  40500. drawWidth === originalWidth && drawHeight === originalHeight) {
  40501. imgData.kind = kind;
  40502. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40503. // If imgArray came from a DecodeStream, we're safe to transfer it
  40504. // (and thus neuter it) because it will constitute the entire
  40505. // DecodeStream's data. But if it came from a Stream, we need to
  40506. // copy it because it'll only be a portion of the Stream's data, and
  40507. // the rest will be read later on.
  40508. if (this.image instanceof DecodeStream) {
  40509. imgData.data = imgArray;
  40510. } else {
  40511. var newArray = new Uint8Array(imgArray.length);
  40512. newArray.set(imgArray);
  40513. imgData.data = newArray;
  40514. }
  40515. if (this.needsDecode) {
  40516. // Invert the buffer (which must be grayscale if we reached here).
  40517. assert(kind === ImageKind.GRAYSCALE_1BPP);
  40518. var buffer = imgData.data;
  40519. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40520. buffer[i] ^= 0xff;
  40521. }
  40522. }
  40523. return imgData;
  40524. }
  40525. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  40526. (this.colorSpace.name === 'DeviceGray' ||
  40527. this.colorSpace.name === 'DeviceRGB' ||
  40528. this.colorSpace.name === 'DeviceCMYK')) {
  40529. imgData.kind = ImageKind.RGB_24BPP;
  40530. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  40531. drawWidth, drawHeight, true);
  40532. return imgData;
  40533. }
  40534. }
  40535. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40536. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  40537. var actualHeight = 0 | (imgArray.length / rowBytes *
  40538. drawHeight / originalHeight);
  40539. var comps = this.getComponents(imgArray);
  40540. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  40541. // more compact RGB_24BPP form if allowable.
  40542. var alpha01, maybeUndoPreblend;
  40543. if (!forceRGBA && !this.smask && !this.mask) {
  40544. imgData.kind = ImageKind.RGB_24BPP;
  40545. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  40546. alpha01 = 0;
  40547. maybeUndoPreblend = false;
  40548. } else {
  40549. imgData.kind = ImageKind.RGBA_32BPP;
  40550. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  40551. alpha01 = 1;
  40552. maybeUndoPreblend = true;
  40553. // Color key masking (opacity) must be performed before decoding.
  40554. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  40555. comps);
  40556. }
  40557. if (this.needsDecode) {
  40558. this.decodeBuffer(comps);
  40559. }
  40560. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  40561. drawWidth, drawHeight, actualHeight, bpc, comps,
  40562. alpha01);
  40563. if (maybeUndoPreblend) {
  40564. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  40565. }
  40566. return imgData;
  40567. },
  40568. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  40569. var numComps = this.numComps;
  40570. if (numComps !== 1) {
  40571. error('Reading gray scale from a color image: ' + numComps);
  40572. }
  40573. var width = this.width;
  40574. var height = this.height;
  40575. var bpc = this.bpc;
  40576. // rows start at byte boundary
  40577. var rowBytes = (width * numComps * bpc + 7) >> 3;
  40578. var imgArray = this.getImageBytes(height * rowBytes);
  40579. var comps = this.getComponents(imgArray);
  40580. var i, length;
  40581. if (bpc === 1) {
  40582. // inline decoding (= inversion) for 1 bpc images
  40583. length = width * height;
  40584. if (this.needsDecode) {
  40585. // invert and scale to {0, 255}
  40586. for (i = 0; i < length; ++i) {
  40587. buffer[i] = (comps[i] - 1) & 255;
  40588. }
  40589. } else {
  40590. // scale to {0, 255}
  40591. for (i = 0; i < length; ++i) {
  40592. buffer[i] = (-comps[i]) & 255;
  40593. }
  40594. }
  40595. return;
  40596. }
  40597. if (this.needsDecode) {
  40598. this.decodeBuffer(comps);
  40599. }
  40600. length = width * height;
  40601. // we aren't using a colorspace so we need to scale the value
  40602. var scale = 255 / ((1 << bpc) - 1);
  40603. for (i = 0; i < length; ++i) {
  40604. buffer[i] = (scale * comps[i]) | 0;
  40605. }
  40606. },
  40607. getImageBytes: function PDFImage_getImageBytes(length,
  40608. drawWidth, drawHeight,
  40609. forceRGB) {
  40610. this.image.reset();
  40611. this.image.drawWidth = drawWidth || this.width;
  40612. this.image.drawHeight = drawHeight || this.height;
  40613. this.image.forceRGB = !!forceRGB;
  40614. return this.image.getBytes(length);
  40615. }
  40616. };
  40617. return PDFImage;
  40618. })();
  40619. exports.PDFImage = PDFImage;
  40620. // TODO refactor to remove dependency on colorspace.js
  40621. coreColorSpace._setCoreImage(exports);
  40622. }));
  40623. (function (root, factory) {
  40624. {
  40625. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  40626. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  40627. root.pdfjsCoreColorSpace);
  40628. }
  40629. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  40630. coreColorSpace) {
  40631. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  40632. var MissingDataException = sharedUtil.MissingDataException;
  40633. var Util = sharedUtil.Util;
  40634. var assert = sharedUtil.assert;
  40635. var error = sharedUtil.error;
  40636. var info = sharedUtil.info;
  40637. var warn = sharedUtil.warn;
  40638. var isStream = corePrimitives.isStream;
  40639. var PDFFunction = coreFunction.PDFFunction;
  40640. var ColorSpace = coreColorSpace.ColorSpace;
  40641. var ShadingType = {
  40642. FUNCTION_BASED: 1,
  40643. AXIAL: 2,
  40644. RADIAL: 3,
  40645. FREE_FORM_MESH: 4,
  40646. LATTICE_FORM_MESH: 5,
  40647. COONS_PATCH_MESH: 6,
  40648. TENSOR_PATCH_MESH: 7
  40649. };
  40650. var Pattern = (function PatternClosure() {
  40651. // Constructor should define this.getPattern
  40652. function Pattern() {
  40653. error('should not call Pattern constructor');
  40654. }
  40655. Pattern.prototype = {
  40656. // Input: current Canvas context
  40657. // Output: the appropriate fillStyle or strokeStyle
  40658. getPattern: function Pattern_getPattern(ctx) {
  40659. error('Should not call Pattern.getStyle: ' + ctx);
  40660. }
  40661. };
  40662. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  40663. res, handler) {
  40664. var dict = isStream(shading) ? shading.dict : shading;
  40665. var type = dict.get('ShadingType');
  40666. try {
  40667. switch (type) {
  40668. case ShadingType.AXIAL:
  40669. case ShadingType.RADIAL:
  40670. // Both radial and axial shadings are handled by RadialAxial shading.
  40671. return new Shadings.RadialAxial(dict, matrix, xref, res);
  40672. case ShadingType.FREE_FORM_MESH:
  40673. case ShadingType.LATTICE_FORM_MESH:
  40674. case ShadingType.COONS_PATCH_MESH:
  40675. case ShadingType.TENSOR_PATCH_MESH:
  40676. return new Shadings.Mesh(shading, matrix, xref, res);
  40677. default:
  40678. throw new Error('Unsupported ShadingType: ' + type);
  40679. }
  40680. } catch (ex) {
  40681. if (ex instanceof MissingDataException) {
  40682. throw ex;
  40683. }
  40684. handler.send('UnsupportedFeature',
  40685. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  40686. warn(ex);
  40687. return new Shadings.Dummy();
  40688. }
  40689. };
  40690. return Pattern;
  40691. })();
  40692. var Shadings = {};
  40693. // A small number to offset the first/last color stops so we can insert ones to
  40694. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  40695. Shadings.SMALL_NUMBER = 1e-6;
  40696. // Radial and axial shading have very similar implementations
  40697. // If needed, the implementations can be broken into two classes
  40698. Shadings.RadialAxial = (function RadialAxialClosure() {
  40699. function RadialAxial(dict, matrix, xref, res) {
  40700. this.matrix = matrix;
  40701. this.coordsArr = dict.get('Coords');
  40702. this.shadingType = dict.get('ShadingType');
  40703. this.type = 'Pattern';
  40704. var cs = dict.get('ColorSpace', 'CS');
  40705. cs = ColorSpace.parse(cs, xref, res);
  40706. this.cs = cs;
  40707. var t0 = 0.0, t1 = 1.0;
  40708. if (dict.has('Domain')) {
  40709. var domainArr = dict.get('Domain');
  40710. t0 = domainArr[0];
  40711. t1 = domainArr[1];
  40712. }
  40713. var extendStart = false, extendEnd = false;
  40714. if (dict.has('Extend')) {
  40715. var extendArr = dict.get('Extend');
  40716. extendStart = extendArr[0];
  40717. extendEnd = extendArr[1];
  40718. }
  40719. if (this.shadingType === ShadingType.RADIAL &&
  40720. (!extendStart || !extendEnd)) {
  40721. // Radial gradient only currently works if either circle is fully within
  40722. // the other circle.
  40723. var x1 = this.coordsArr[0];
  40724. var y1 = this.coordsArr[1];
  40725. var r1 = this.coordsArr[2];
  40726. var x2 = this.coordsArr[3];
  40727. var y2 = this.coordsArr[4];
  40728. var r2 = this.coordsArr[5];
  40729. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  40730. if (r1 <= r2 + distance &&
  40731. r2 <= r1 + distance) {
  40732. warn('Unsupported radial gradient.');
  40733. }
  40734. }
  40735. this.extendStart = extendStart;
  40736. this.extendEnd = extendEnd;
  40737. var fnObj = dict.get('Function');
  40738. var fn = PDFFunction.parseArray(xref, fnObj);
  40739. // 10 samples seems good enough for now, but probably won't work
  40740. // if there are sharp color changes. Ideally, we would implement
  40741. // the spec faithfully and add lossless optimizations.
  40742. var diff = t1 - t0;
  40743. var step = diff / 10;
  40744. var colorStops = this.colorStops = [];
  40745. // Protect against bad domains so we don't end up in an infinte loop below.
  40746. if (t0 >= t1 || step <= 0) {
  40747. // Acrobat doesn't seem to handle these cases so we'll ignore for
  40748. // now.
  40749. info('Bad shading domain.');
  40750. return;
  40751. }
  40752. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  40753. var rgbColor;
  40754. for (var i = t0; i <= t1; i += step) {
  40755. ratio[0] = i;
  40756. fn(ratio, 0, color, 0);
  40757. rgbColor = cs.getRgb(color, 0);
  40758. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  40759. colorStops.push([(i - t0) / diff, cssColor]);
  40760. }
  40761. var background = 'transparent';
  40762. if (dict.has('Background')) {
  40763. rgbColor = cs.getRgb(dict.get('Background'), 0);
  40764. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  40765. }
  40766. if (!extendStart) {
  40767. // Insert a color stop at the front and offset the first real color stop
  40768. // so it doesn't conflict with the one we insert.
  40769. colorStops.unshift([0, background]);
  40770. colorStops[1][0] += Shadings.SMALL_NUMBER;
  40771. }
  40772. if (!extendEnd) {
  40773. // Same idea as above in extendStart but for the end.
  40774. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  40775. colorStops.push([1, background]);
  40776. }
  40777. this.colorStops = colorStops;
  40778. }
  40779. RadialAxial.prototype = {
  40780. getIR: function RadialAxial_getIR() {
  40781. var coordsArr = this.coordsArr;
  40782. var shadingType = this.shadingType;
  40783. var type, p0, p1, r0, r1;
  40784. if (shadingType === ShadingType.AXIAL) {
  40785. p0 = [coordsArr[0], coordsArr[1]];
  40786. p1 = [coordsArr[2], coordsArr[3]];
  40787. r0 = null;
  40788. r1 = null;
  40789. type = 'axial';
  40790. } else if (shadingType === ShadingType.RADIAL) {
  40791. p0 = [coordsArr[0], coordsArr[1]];
  40792. p1 = [coordsArr[3], coordsArr[4]];
  40793. r0 = coordsArr[2];
  40794. r1 = coordsArr[5];
  40795. type = 'radial';
  40796. } else {
  40797. error('getPattern type unknown: ' + shadingType);
  40798. }
  40799. var matrix = this.matrix;
  40800. if (matrix) {
  40801. p0 = Util.applyTransform(p0, matrix);
  40802. p1 = Util.applyTransform(p1, matrix);
  40803. if (shadingType === ShadingType.RADIAL) {
  40804. var scale = Util.singularValueDecompose2dScale(matrix);
  40805. r0 *= scale[0];
  40806. r1 *= scale[1];
  40807. }
  40808. }
  40809. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  40810. }
  40811. };
  40812. return RadialAxial;
  40813. })();
  40814. // All mesh shading. For now, they will be presented as set of the triangles
  40815. // to be drawn on the canvas and rgb color for each vertex.
  40816. Shadings.Mesh = (function MeshClosure() {
  40817. function MeshStreamReader(stream, context) {
  40818. this.stream = stream;
  40819. this.context = context;
  40820. this.buffer = 0;
  40821. this.bufferLength = 0;
  40822. var numComps = context.numComps;
  40823. this.tmpCompsBuf = new Float32Array(numComps);
  40824. var csNumComps = context.colorSpace.numComps;
  40825. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  40826. this.tmpCompsBuf;
  40827. }
  40828. MeshStreamReader.prototype = {
  40829. get hasData() {
  40830. if (this.stream.end) {
  40831. return this.stream.pos < this.stream.end;
  40832. }
  40833. if (this.bufferLength > 0) {
  40834. return true;
  40835. }
  40836. var nextByte = this.stream.getByte();
  40837. if (nextByte < 0) {
  40838. return false;
  40839. }
  40840. this.buffer = nextByte;
  40841. this.bufferLength = 8;
  40842. return true;
  40843. },
  40844. readBits: function MeshStreamReader_readBits(n) {
  40845. var buffer = this.buffer;
  40846. var bufferLength = this.bufferLength;
  40847. if (n === 32) {
  40848. if (bufferLength === 0) {
  40849. return ((this.stream.getByte() << 24) |
  40850. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  40851. this.stream.getByte()) >>> 0;
  40852. }
  40853. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  40854. (this.stream.getByte() << 8) | this.stream.getByte();
  40855. var nextByte = this.stream.getByte();
  40856. this.buffer = nextByte & ((1 << bufferLength) - 1);
  40857. return ((buffer << (8 - bufferLength)) |
  40858. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  40859. }
  40860. if (n === 8 && bufferLength === 0) {
  40861. return this.stream.getByte();
  40862. }
  40863. while (bufferLength < n) {
  40864. buffer = (buffer << 8) | this.stream.getByte();
  40865. bufferLength += 8;
  40866. }
  40867. bufferLength -= n;
  40868. this.bufferLength = bufferLength;
  40869. this.buffer = buffer & ((1 << bufferLength) - 1);
  40870. return buffer >> bufferLength;
  40871. },
  40872. align: function MeshStreamReader_align() {
  40873. this.buffer = 0;
  40874. this.bufferLength = 0;
  40875. },
  40876. readFlag: function MeshStreamReader_readFlag() {
  40877. return this.readBits(this.context.bitsPerFlag);
  40878. },
  40879. readCoordinate: function MeshStreamReader_readCoordinate() {
  40880. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  40881. var xi = this.readBits(bitsPerCoordinate);
  40882. var yi = this.readBits(bitsPerCoordinate);
  40883. var decode = this.context.decode;
  40884. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  40885. 2.3283064365386963e-10; // 2 ^ -32
  40886. return [
  40887. xi * scale * (decode[1] - decode[0]) + decode[0],
  40888. yi * scale * (decode[3] - decode[2]) + decode[2]
  40889. ];
  40890. },
  40891. readComponents: function MeshStreamReader_readComponents() {
  40892. var numComps = this.context.numComps;
  40893. var bitsPerComponent = this.context.bitsPerComponent;
  40894. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  40895. 2.3283064365386963e-10; // 2 ^ -32
  40896. var decode = this.context.decode;
  40897. var components = this.tmpCompsBuf;
  40898. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  40899. var ci = this.readBits(bitsPerComponent);
  40900. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  40901. }
  40902. var color = this.tmpCsCompsBuf;
  40903. if (this.context.colorFn) {
  40904. this.context.colorFn(components, 0, color, 0);
  40905. }
  40906. return this.context.colorSpace.getRgb(color, 0);
  40907. }
  40908. };
  40909. function decodeType4Shading(mesh, reader) {
  40910. var coords = mesh.coords;
  40911. var colors = mesh.colors;
  40912. var operators = [];
  40913. var ps = []; // not maintaining cs since that will match ps
  40914. var verticesLeft = 0; // assuming we have all data to start a new triangle
  40915. while (reader.hasData) {
  40916. var f = reader.readFlag();
  40917. var coord = reader.readCoordinate();
  40918. var color = reader.readComponents();
  40919. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  40920. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  40921. switch (f) {
  40922. case 0:
  40923. verticesLeft = 3;
  40924. break;
  40925. case 1:
  40926. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  40927. verticesLeft = 1;
  40928. break;
  40929. case 2:
  40930. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  40931. verticesLeft = 1;
  40932. break;
  40933. }
  40934. operators.push(f);
  40935. }
  40936. ps.push(coords.length);
  40937. coords.push(coord);
  40938. colors.push(color);
  40939. verticesLeft--;
  40940. reader.align();
  40941. }
  40942. mesh.figures.push({
  40943. type: 'triangles',
  40944. coords: new Int32Array(ps),
  40945. colors: new Int32Array(ps),
  40946. });
  40947. }
  40948. function decodeType5Shading(mesh, reader, verticesPerRow) {
  40949. var coords = mesh.coords;
  40950. var colors = mesh.colors;
  40951. var ps = []; // not maintaining cs since that will match ps
  40952. while (reader.hasData) {
  40953. var coord = reader.readCoordinate();
  40954. var color = reader.readComponents();
  40955. ps.push(coords.length);
  40956. coords.push(coord);
  40957. colors.push(color);
  40958. }
  40959. mesh.figures.push({
  40960. type: 'lattice',
  40961. coords: new Int32Array(ps),
  40962. colors: new Int32Array(ps),
  40963. verticesPerRow: verticesPerRow
  40964. });
  40965. }
  40966. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  40967. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  40968. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  40969. var getB = (function getBClosure() {
  40970. function buildB(count) {
  40971. var lut = [];
  40972. for (var i = 0; i <= count; i++) {
  40973. var t = i / count, t_ = 1 - t;
  40974. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  40975. 3 * t * t * t_, t * t * t]));
  40976. }
  40977. return lut;
  40978. }
  40979. var cache = [];
  40980. return function getB(count) {
  40981. if (!cache[count]) {
  40982. cache[count] = buildB(count);
  40983. }
  40984. return cache[count];
  40985. };
  40986. })();
  40987. function buildFigureFromPatch(mesh, index) {
  40988. var figure = mesh.figures[index];
  40989. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  40990. var coords = mesh.coords, colors = mesh.colors;
  40991. var pi = figure.coords;
  40992. var ci = figure.colors;
  40993. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  40994. coords[pi[12]][0], coords[pi[15]][0]);
  40995. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  40996. coords[pi[12]][1], coords[pi[15]][1]);
  40997. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  40998. coords[pi[12]][0], coords[pi[15]][0]);
  40999. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  41000. coords[pi[12]][1], coords[pi[15]][1]);
  41001. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  41002. (mesh.bounds[2] - mesh.bounds[0]));
  41003. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41004. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  41005. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  41006. (mesh.bounds[3] - mesh.bounds[1]));
  41007. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41008. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  41009. var verticesPerRow = splitXBy + 1;
  41010. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  41011. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  41012. var k = 0;
  41013. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  41014. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  41015. c2 = colors[ci[2]], c3 = colors[ci[3]];
  41016. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  41017. for (var row = 0; row <= splitYBy; row++) {
  41018. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  41019. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  41020. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  41021. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  41022. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  41023. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  41024. for (var col = 0; col <= splitXBy; col++, k++) {
  41025. if ((row === 0 || row === splitYBy) &&
  41026. (col === 0 || col === splitXBy)) {
  41027. continue;
  41028. }
  41029. var x = 0, y = 0;
  41030. var q = 0;
  41031. for (var i = 0; i <= 3; i++) {
  41032. for (var j = 0; j <= 3; j++, q++) {
  41033. var m = bRow[row][i] * bCol[col][j];
  41034. x += coords[pi[q]][0] * m;
  41035. y += coords[pi[q]][1] * m;
  41036. }
  41037. }
  41038. figureCoords[k] = coords.length;
  41039. coords.push([x, y]);
  41040. figureColors[k] = colors.length;
  41041. var newColor = new Uint8Array(3);
  41042. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  41043. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  41044. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  41045. colors.push(newColor);
  41046. }
  41047. }
  41048. figureCoords[0] = pi[0];
  41049. figureColors[0] = ci[0];
  41050. figureCoords[splitXBy] = pi[3];
  41051. figureColors[splitXBy] = ci[1];
  41052. figureCoords[verticesPerRow * splitYBy] = pi[12];
  41053. figureColors[verticesPerRow * splitYBy] = ci[2];
  41054. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  41055. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  41056. mesh.figures[index] = {
  41057. type: 'lattice',
  41058. coords: figureCoords,
  41059. colors: figureColors,
  41060. verticesPerRow: verticesPerRow
  41061. };
  41062. }
  41063. function decodeType6Shading(mesh, reader) {
  41064. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  41065. var coords = mesh.coords;
  41066. var colors = mesh.colors;
  41067. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41068. var cs = new Int32Array(4); // c00, c30, c03, c33
  41069. while (reader.hasData) {
  41070. var f = reader.readFlag();
  41071. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  41072. var i, ii;
  41073. var pi = coords.length;
  41074. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  41075. coords.push(reader.readCoordinate());
  41076. }
  41077. var ci = colors.length;
  41078. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41079. colors.push(reader.readComponents());
  41080. }
  41081. var tmp1, tmp2, tmp3, tmp4;
  41082. switch (f) {
  41083. case 0:
  41084. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41085. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  41086. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  41087. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41088. cs[2] = ci + 1; cs[3] = ci + 2;
  41089. cs[0] = ci; cs[1] = ci + 3;
  41090. break;
  41091. case 1:
  41092. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41093. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41094. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41095. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41096. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41097. tmp1 = cs[2]; tmp2 = cs[3];
  41098. cs[2] = tmp2; cs[3] = ci;
  41099. cs[0] = tmp1; cs[1] = ci + 1;
  41100. break;
  41101. case 2:
  41102. tmp1 = ps[15];
  41103. tmp2 = ps[11];
  41104. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41105. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41106. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41107. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41108. tmp1 = cs[3];
  41109. cs[2] = cs[1]; cs[3] = ci;
  41110. cs[0] = tmp1; cs[1] = ci + 1;
  41111. break;
  41112. case 3:
  41113. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41114. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41115. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  41116. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41117. cs[2] = cs[0]; cs[3] = ci;
  41118. cs[0] = cs[1]; cs[1] = ci + 1;
  41119. break;
  41120. }
  41121. // set p11, p12, p21, p22
  41122. ps[5] = coords.length;
  41123. coords.push([
  41124. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  41125. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  41126. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41127. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  41128. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  41129. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  41130. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41131. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  41132. ]);
  41133. ps[6] = coords.length;
  41134. coords.push([
  41135. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  41136. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  41137. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41138. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  41139. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  41140. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  41141. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41142. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  41143. ]);
  41144. ps[9] = coords.length;
  41145. coords.push([
  41146. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  41147. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  41148. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41149. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  41150. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  41151. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  41152. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41153. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  41154. ]);
  41155. ps[10] = coords.length;
  41156. coords.push([
  41157. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  41158. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  41159. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41160. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  41161. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  41162. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  41163. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41164. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  41165. ]);
  41166. mesh.figures.push({
  41167. type: 'patch',
  41168. coords: new Int32Array(ps), // making copies of ps and cs
  41169. colors: new Int32Array(cs)
  41170. });
  41171. }
  41172. }
  41173. function decodeType7Shading(mesh, reader) {
  41174. var coords = mesh.coords;
  41175. var colors = mesh.colors;
  41176. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41177. var cs = new Int32Array(4); // c00, c30, c03, c33
  41178. while (reader.hasData) {
  41179. var f = reader.readFlag();
  41180. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  41181. var i, ii;
  41182. var pi = coords.length;
  41183. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  41184. coords.push(reader.readCoordinate());
  41185. }
  41186. var ci = colors.length;
  41187. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41188. colors.push(reader.readComponents());
  41189. }
  41190. var tmp1, tmp2, tmp3, tmp4;
  41191. switch (f) {
  41192. case 0:
  41193. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41194. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  41195. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  41196. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41197. cs[2] = ci + 1; cs[3] = ci + 2;
  41198. cs[0] = ci; cs[1] = ci + 3;
  41199. break;
  41200. case 1:
  41201. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41202. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41203. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41204. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41205. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41206. tmp1 = cs[2]; tmp2 = cs[3];
  41207. cs[2] = tmp2; cs[3] = ci;
  41208. cs[0] = tmp1; cs[1] = ci + 1;
  41209. break;
  41210. case 2:
  41211. tmp1 = ps[15];
  41212. tmp2 = ps[11];
  41213. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41214. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41215. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41216. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41217. tmp1 = cs[3];
  41218. cs[2] = cs[1]; cs[3] = ci;
  41219. cs[0] = tmp1; cs[1] = ci + 1;
  41220. break;
  41221. case 3:
  41222. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41223. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41224. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41225. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41226. cs[2] = cs[0]; cs[3] = ci;
  41227. cs[0] = cs[1]; cs[1] = ci + 1;
  41228. break;
  41229. }
  41230. mesh.figures.push({
  41231. type: 'patch',
  41232. coords: new Int32Array(ps), // making copies of ps and cs
  41233. colors: new Int32Array(cs)
  41234. });
  41235. }
  41236. }
  41237. function updateBounds(mesh) {
  41238. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  41239. maxX = minX, maxY = minY;
  41240. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  41241. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  41242. minX = minX > x ? x : minX;
  41243. minY = minY > y ? y : minY;
  41244. maxX = maxX < x ? x : maxX;
  41245. maxY = maxY < y ? y : maxY;
  41246. }
  41247. mesh.bounds = [minX, minY, maxX, maxY];
  41248. }
  41249. function packData(mesh) {
  41250. var i, ii, j, jj;
  41251. var coords = mesh.coords;
  41252. var coordsPacked = new Float32Array(coords.length * 2);
  41253. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  41254. var xy = coords[i];
  41255. coordsPacked[j++] = xy[0];
  41256. coordsPacked[j++] = xy[1];
  41257. }
  41258. mesh.coords = coordsPacked;
  41259. var colors = mesh.colors;
  41260. var colorsPacked = new Uint8Array(colors.length * 3);
  41261. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  41262. var c = colors[i];
  41263. colorsPacked[j++] = c[0];
  41264. colorsPacked[j++] = c[1];
  41265. colorsPacked[j++] = c[2];
  41266. }
  41267. mesh.colors = colorsPacked;
  41268. var figures = mesh.figures;
  41269. for (i = 0, ii = figures.length; i < ii; i++) {
  41270. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  41271. for (j = 0, jj = ps.length; j < jj; j++) {
  41272. ps[j] *= 2;
  41273. cs[j] *= 3;
  41274. }
  41275. }
  41276. }
  41277. function Mesh(stream, matrix, xref, res) {
  41278. assert(isStream(stream), 'Mesh data is not a stream');
  41279. var dict = stream.dict;
  41280. this.matrix = matrix;
  41281. this.shadingType = dict.get('ShadingType');
  41282. this.type = 'Pattern';
  41283. this.bbox = dict.get('BBox');
  41284. var cs = dict.get('ColorSpace', 'CS');
  41285. cs = ColorSpace.parse(cs, xref, res);
  41286. this.cs = cs;
  41287. this.background = dict.has('Background') ?
  41288. cs.getRgb(dict.get('Background'), 0) : null;
  41289. var fnObj = dict.get('Function');
  41290. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  41291. this.coords = [];
  41292. this.colors = [];
  41293. this.figures = [];
  41294. var decodeContext = {
  41295. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  41296. bitsPerComponent: dict.get('BitsPerComponent'),
  41297. bitsPerFlag: dict.get('BitsPerFlag'),
  41298. decode: dict.get('Decode'),
  41299. colorFn: fn,
  41300. colorSpace: cs,
  41301. numComps: fn ? 1 : cs.numComps
  41302. };
  41303. var reader = new MeshStreamReader(stream, decodeContext);
  41304. var patchMesh = false;
  41305. switch (this.shadingType) {
  41306. case ShadingType.FREE_FORM_MESH:
  41307. decodeType4Shading(this, reader);
  41308. break;
  41309. case ShadingType.LATTICE_FORM_MESH:
  41310. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  41311. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  41312. decodeType5Shading(this, reader, verticesPerRow);
  41313. break;
  41314. case ShadingType.COONS_PATCH_MESH:
  41315. decodeType6Shading(this, reader);
  41316. patchMesh = true;
  41317. break;
  41318. case ShadingType.TENSOR_PATCH_MESH:
  41319. decodeType7Shading(this, reader);
  41320. patchMesh = true;
  41321. break;
  41322. default:
  41323. error('Unsupported mesh type.');
  41324. break;
  41325. }
  41326. if (patchMesh) {
  41327. // dirty bounds calculation for determining, how dense shall be triangles
  41328. updateBounds(this);
  41329. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  41330. buildFigureFromPatch(this, i);
  41331. }
  41332. }
  41333. // calculate bounds
  41334. updateBounds(this);
  41335. packData(this);
  41336. }
  41337. Mesh.prototype = {
  41338. getIR: function Mesh_getIR() {
  41339. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  41340. this.bounds, this.matrix, this.bbox, this.background];
  41341. }
  41342. };
  41343. return Mesh;
  41344. })();
  41345. Shadings.Dummy = (function DummyClosure() {
  41346. function Dummy() {
  41347. this.type = 'Pattern';
  41348. }
  41349. Dummy.prototype = {
  41350. getIR: function Dummy_getIR() {
  41351. return ['Dummy'];
  41352. }
  41353. };
  41354. return Dummy;
  41355. })();
  41356. function getTilingPatternIR(operatorList, dict, args) {
  41357. var matrix = dict.get('Matrix');
  41358. var bbox = dict.get('BBox');
  41359. var xstep = dict.get('XStep');
  41360. var ystep = dict.get('YStep');
  41361. var paintType = dict.get('PaintType');
  41362. var tilingType = dict.get('TilingType');
  41363. return [
  41364. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  41365. paintType, tilingType
  41366. ];
  41367. }
  41368. exports.Pattern = Pattern;
  41369. exports.getTilingPatternIR = getTilingPatternIR;
  41370. }));
  41371. (function (root, factory) {
  41372. {
  41373. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  41374. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  41375. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  41376. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  41377. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  41378. }
  41379. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  41380. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  41381. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  41382. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  41383. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  41384. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41385. var ImageKind = sharedUtil.ImageKind;
  41386. var OPS = sharedUtil.OPS;
  41387. var TextRenderingMode = sharedUtil.TextRenderingMode;
  41388. var Util = sharedUtil.Util;
  41389. var assert = sharedUtil.assert;
  41390. var createPromiseCapability = sharedUtil.createPromiseCapability;
  41391. var error = sharedUtil.error;
  41392. var info = sharedUtil.info;
  41393. var isArray = sharedUtil.isArray;
  41394. var isNum = sharedUtil.isNum;
  41395. var isString = sharedUtil.isString;
  41396. var warn = sharedUtil.warn;
  41397. var Dict = corePrimitives.Dict;
  41398. var Name = corePrimitives.Name;
  41399. var isCmd = corePrimitives.isCmd;
  41400. var isDict = corePrimitives.isDict;
  41401. var isName = corePrimitives.isName;
  41402. var isRef = corePrimitives.isRef;
  41403. var isStream = corePrimitives.isStream;
  41404. var DecodeStream = coreStream.DecodeStream;
  41405. var JpegStream = coreStream.JpegStream;
  41406. var Lexer = coreParser.Lexer;
  41407. var Parser = coreParser.Parser;
  41408. var isEOF = coreParser.isEOF;
  41409. var PDFImage = coreImage.PDFImage;
  41410. var ColorSpace = coreColorSpace.ColorSpace;
  41411. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  41412. var Encodings = coreFonts.Encodings;
  41413. var ErrorFont = coreFonts.ErrorFont;
  41414. var FontFlags = coreFonts.FontFlags;
  41415. var Font = coreFonts.Font;
  41416. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  41417. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  41418. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  41419. var getFontType = coreFonts.getFontType;
  41420. var reverseIfRtl = coreFonts.reverseIfRtl;
  41421. var serifFonts = coreFonts.serifFonts;
  41422. var symbolsFonts = coreFonts.symbolsFonts;
  41423. var stdFontMap = coreFonts.stdFontMap;
  41424. var isPDFFunction = coreFunction.isPDFFunction;
  41425. var PDFFunction = coreFunction.PDFFunction;
  41426. var Pattern = corePattern.Pattern;
  41427. var getTilingPatternIR = corePattern.getTilingPatternIR;
  41428. var CMapFactory = coreCMap.CMapFactory;
  41429. var IdentityCMap = coreCMap.IdentityCMap;
  41430. var Metrics = coreMetrics.Metrics;
  41431. var bidi = coreBidi.bidi;
  41432. var PartialEvaluator = (function PartialEvaluatorClosure() {
  41433. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  41434. uniquePrefix, idCounters, fontCache) {
  41435. this.pdfManager = pdfManager;
  41436. this.xref = xref;
  41437. this.handler = handler;
  41438. this.pageIndex = pageIndex;
  41439. this.uniquePrefix = uniquePrefix;
  41440. this.idCounters = idCounters;
  41441. this.fontCache = fontCache;
  41442. }
  41443. // Trying to minimize Date.now() usage and check every 100 time
  41444. var TIME_SLOT_DURATION_MS = 20;
  41445. var CHECK_TIME_EVERY = 100;
  41446. function TimeSlotManager() {
  41447. this.reset();
  41448. }
  41449. TimeSlotManager.prototype = {
  41450. check: function TimeSlotManager_check() {
  41451. if (++this.checked < CHECK_TIME_EVERY) {
  41452. return false;
  41453. }
  41454. this.checked = 0;
  41455. return this.endTime <= Date.now();
  41456. },
  41457. reset: function TimeSlotManager_reset() {
  41458. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  41459. this.checked = 0;
  41460. }
  41461. };
  41462. var deferred = Promise.resolve();
  41463. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  41464. PartialEvaluator.prototype = {
  41465. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  41466. if (!isDict(resources)) {
  41467. return false;
  41468. }
  41469. var processed = Object.create(null);
  41470. if (resources.objId) {
  41471. processed[resources.objId] = true;
  41472. }
  41473. var nodes = [resources];
  41474. while (nodes.length) {
  41475. var key;
  41476. var node = nodes.shift();
  41477. // First check the current resources for blend modes.
  41478. var graphicStates = node.get('ExtGState');
  41479. if (isDict(graphicStates)) {
  41480. graphicStates = graphicStates.getAll();
  41481. for (key in graphicStates) {
  41482. var graphicState = graphicStates[key];
  41483. var bm = graphicState['BM'];
  41484. if (isName(bm) && bm.name !== 'Normal') {
  41485. return true;
  41486. }
  41487. }
  41488. }
  41489. // Descend into the XObjects to look for more resources and blend modes.
  41490. var xObjects = node.get('XObject');
  41491. if (!isDict(xObjects)) {
  41492. continue;
  41493. }
  41494. xObjects = xObjects.getAll();
  41495. for (key in xObjects) {
  41496. var xObject = xObjects[key];
  41497. if (!isStream(xObject)) {
  41498. continue;
  41499. }
  41500. if (xObject.dict.objId) {
  41501. if (processed[xObject.dict.objId]) {
  41502. // stream has objId and is processed already
  41503. continue;
  41504. }
  41505. processed[xObject.dict.objId] = true;
  41506. }
  41507. var xResources = xObject.dict.get('Resources');
  41508. // Checking objId to detect an infinite loop.
  41509. if (isDict(xResources) &&
  41510. (!xResources.objId || !processed[xResources.objId])) {
  41511. nodes.push(xResources);
  41512. if (xResources.objId) {
  41513. processed[xResources.objId] = true;
  41514. }
  41515. }
  41516. }
  41517. }
  41518. return false;
  41519. },
  41520. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  41521. xobj, smask,
  41522. operatorList,
  41523. task,
  41524. initialState) {
  41525. var matrix = xobj.dict.getArray('Matrix');
  41526. var bbox = xobj.dict.getArray('BBox');
  41527. var group = xobj.dict.get('Group');
  41528. if (group) {
  41529. var groupOptions = {
  41530. matrix: matrix,
  41531. bbox: bbox,
  41532. smask: smask,
  41533. isolated: false,
  41534. knockout: false
  41535. };
  41536. var groupSubtype = group.get('S');
  41537. var colorSpace;
  41538. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  41539. groupOptions.isolated = (group.get('I') || false);
  41540. groupOptions.knockout = (group.get('K') || false);
  41541. colorSpace = (group.has('CS') ?
  41542. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  41543. }
  41544. if (smask && smask.backdrop) {
  41545. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  41546. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  41547. }
  41548. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  41549. }
  41550. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  41551. return this.getOperatorList(xobj, task,
  41552. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  41553. then(function () {
  41554. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  41555. if (group) {
  41556. operatorList.addOp(OPS.endGroup, [groupOptions]);
  41557. }
  41558. });
  41559. },
  41560. buildPaintImageXObject:
  41561. function PartialEvaluator_buildPaintImageXObject(resources, image,
  41562. inline, operatorList,
  41563. cacheKey, imageCache) {
  41564. var self = this;
  41565. var dict = image.dict;
  41566. var w = dict.get('Width', 'W');
  41567. var h = dict.get('Height', 'H');
  41568. if (!(w && isNum(w)) || !(h && isNum(h))) {
  41569. warn('Image dimensions are missing, or not numbers.');
  41570. return;
  41571. }
  41572. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  41573. warn('Image exceeded maximum allowed size and was removed.');
  41574. return;
  41575. }
  41576. var imageMask = (dict.get('ImageMask', 'IM') || false);
  41577. var imgData, args;
  41578. if (imageMask) {
  41579. // This depends on a tmpCanvas being filled with the
  41580. // current fillStyle, such that processing the pixel
  41581. // data can't be done here. Instead of creating a
  41582. // complete PDFImage, only read the information needed
  41583. // for later.
  41584. var width = dict.get('Width', 'W');
  41585. var height = dict.get('Height', 'H');
  41586. var bitStrideLength = (width + 7) >> 3;
  41587. var imgArray = image.getBytes(bitStrideLength * height);
  41588. var decode = dict.get('Decode', 'D');
  41589. var inverseDecode = (!!decode && decode[0] > 0);
  41590. imgData = PDFImage.createMask(imgArray, width, height,
  41591. image instanceof DecodeStream,
  41592. inverseDecode);
  41593. imgData.cached = true;
  41594. args = [imgData];
  41595. operatorList.addOp(OPS.paintImageMaskXObject, args);
  41596. if (cacheKey) {
  41597. imageCache[cacheKey] = {
  41598. fn: OPS.paintImageMaskXObject,
  41599. args: args
  41600. };
  41601. }
  41602. return;
  41603. }
  41604. var softMask = (dict.get('SMask', 'SM') || false);
  41605. var mask = (dict.get('Mask') || false);
  41606. var SMALL_IMAGE_DIMENSIONS = 200;
  41607. // Inlining small images into the queue as RGB data
  41608. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  41609. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  41610. var imageObj = new PDFImage(this.xref, resources, image,
  41611. inline, null, null);
  41612. // We force the use of RGBA_32BPP images here, because we can't handle
  41613. // any other kind.
  41614. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  41615. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  41616. return;
  41617. }
  41618. // If there is no imageMask, create the PDFImage and a lot
  41619. // of image processing can be done here.
  41620. var uniquePrefix = (this.uniquePrefix || '');
  41621. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  41622. operatorList.addDependency(objId);
  41623. args = [objId, w, h];
  41624. if (!softMask && !mask && image instanceof JpegStream &&
  41625. image.isNativelySupported(this.xref, resources)) {
  41626. // These JPEGs don't need any more processing so we can just send it.
  41627. operatorList.addOp(OPS.paintJpegXObject, args);
  41628. this.handler.send('obj',
  41629. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  41630. return;
  41631. }
  41632. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  41633. then(function(imageObj) {
  41634. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  41635. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  41636. [imgData.data.buffer]);
  41637. }).then(undefined, function (reason) {
  41638. warn('Unable to decode image: ' + reason);
  41639. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  41640. });
  41641. operatorList.addOp(OPS.paintImageXObject, args);
  41642. if (cacheKey) {
  41643. imageCache[cacheKey] = {
  41644. fn: OPS.paintImageXObject,
  41645. args: args
  41646. };
  41647. }
  41648. },
  41649. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  41650. operatorList, task,
  41651. stateManager) {
  41652. var smaskContent = smask.get('G');
  41653. var smaskOptions = {
  41654. subtype: smask.get('S').name,
  41655. backdrop: smask.get('BC')
  41656. };
  41657. // The SMask might have a alpha/luminosity value transfer function --
  41658. // we will build a map of integer values in range 0..255 to be fast.
  41659. var transferObj = smask.get('TR');
  41660. if (isPDFFunction(transferObj)) {
  41661. var transferFn = PDFFunction.parse(this.xref, transferObj);
  41662. var transferMap = new Uint8Array(256);
  41663. var tmp = new Float32Array(1);
  41664. for (var i = 0; i < 255; i++) {
  41665. tmp[0] = i / 255;
  41666. transferFn(tmp, 0, tmp, 0);
  41667. transferMap[i] = (tmp[0] * 255) | 0;
  41668. }
  41669. smaskOptions.transferMap = transferMap;
  41670. }
  41671. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  41672. operatorList, task, stateManager.state.clone());
  41673. },
  41674. handleTilingType:
  41675. function PartialEvaluator_handleTilingType(fn, args, resources,
  41676. pattern, patternDict,
  41677. operatorList, task) {
  41678. // Create an IR of the pattern code.
  41679. var tilingOpList = new OperatorList();
  41680. // Merge the available resources, to prevent issues when the patternDict
  41681. // is missing some /Resources entries (fixes issue6541.pdf).
  41682. var resourcesArray = [patternDict.get('Resources'), resources];
  41683. var patternResources = Dict.merge(this.xref, resourcesArray);
  41684. return this.getOperatorList(pattern, task, patternResources,
  41685. tilingOpList).then(function () {
  41686. // Add the dependencies to the parent operator list so they are
  41687. // resolved before sub operator list is executed synchronously.
  41688. operatorList.addDependencies(tilingOpList.dependencies);
  41689. operatorList.addOp(fn, getTilingPatternIR({
  41690. fnArray: tilingOpList.fnArray,
  41691. argsArray: tilingOpList.argsArray
  41692. }, patternDict, args));
  41693. });
  41694. },
  41695. handleSetFont:
  41696. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  41697. operatorList, task, state) {
  41698. // TODO(mack): Not needed?
  41699. var fontName;
  41700. if (fontArgs) {
  41701. fontArgs = fontArgs.slice();
  41702. fontName = fontArgs[0].name;
  41703. }
  41704. var self = this;
  41705. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  41706. function (translated) {
  41707. if (!translated.font.isType3Font) {
  41708. return translated;
  41709. }
  41710. return translated.loadType3Data(self, resources, operatorList, task).
  41711. then(function () {
  41712. return translated;
  41713. }, function (reason) {
  41714. // Error in the font data -- sending unsupported feature notification.
  41715. self.handler.send('UnsupportedFeature',
  41716. {featureId: UNSUPPORTED_FEATURES.font});
  41717. return new TranslatedFont('g_font_error',
  41718. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  41719. });
  41720. }).then(function (translated) {
  41721. state.font = translated.font;
  41722. translated.send(self.handler);
  41723. return translated.loadedName;
  41724. });
  41725. },
  41726. handleText: function PartialEvaluator_handleText(chars, state) {
  41727. var font = state.font;
  41728. var glyphs = font.charsToGlyphs(chars);
  41729. var isAddToPathSet = !!(state.textRenderingMode &
  41730. TextRenderingMode.ADD_TO_PATH_FLAG);
  41731. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  41732. var buildPath = function (fontChar) {
  41733. if (!font.renderer.hasBuiltPath(fontChar)) {
  41734. var path = font.renderer.getPathJs(fontChar);
  41735. this.handler.send('commonobj', [
  41736. font.loadedName + '_path_' + fontChar,
  41737. 'FontPath',
  41738. path
  41739. ]);
  41740. }
  41741. }.bind(this);
  41742. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  41743. var glyph = glyphs[i];
  41744. buildPath(glyph.fontChar);
  41745. // If the glyph has an accent we need to build a path for its
  41746. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  41747. var accent = glyph.accent;
  41748. if (accent && accent.fontChar) {
  41749. buildPath(accent.fontChar);
  41750. }
  41751. }
  41752. }
  41753. return glyphs;
  41754. },
  41755. setGState: function PartialEvaluator_setGState(resources, gState,
  41756. operatorList, task,
  41757. xref, stateManager) {
  41758. // This array holds the converted/processed state data.
  41759. var gStateObj = [];
  41760. var gStateMap = gState.map;
  41761. var self = this;
  41762. var promise = Promise.resolve();
  41763. for (var key in gStateMap) {
  41764. var value = gStateMap[key];
  41765. switch (key) {
  41766. case 'Type':
  41767. break;
  41768. case 'LW':
  41769. case 'LC':
  41770. case 'LJ':
  41771. case 'ML':
  41772. case 'D':
  41773. case 'RI':
  41774. case 'FL':
  41775. case 'CA':
  41776. case 'ca':
  41777. gStateObj.push([key, value]);
  41778. break;
  41779. case 'Font':
  41780. promise = promise.then(function () {
  41781. return self.handleSetFont(resources, null, value[0], operatorList,
  41782. task, stateManager.state).
  41783. then(function (loadedName) {
  41784. operatorList.addDependency(loadedName);
  41785. gStateObj.push([key, [loadedName, value[1]]]);
  41786. });
  41787. });
  41788. break;
  41789. case 'BM':
  41790. gStateObj.push([key, value]);
  41791. break;
  41792. case 'SMask':
  41793. if (isName(value) && value.name === 'None') {
  41794. gStateObj.push([key, false]);
  41795. break;
  41796. }
  41797. var dict = xref.fetchIfRef(value);
  41798. if (isDict(dict)) {
  41799. promise = promise.then(function () {
  41800. return self.handleSMask(dict, resources, operatorList,
  41801. task, stateManager);
  41802. });
  41803. gStateObj.push([key, true]);
  41804. } else {
  41805. warn('Unsupported SMask type');
  41806. }
  41807. break;
  41808. // Only generate info log messages for the following since
  41809. // they are unlikely to have a big impact on the rendering.
  41810. case 'OP':
  41811. case 'op':
  41812. case 'OPM':
  41813. case 'BG':
  41814. case 'BG2':
  41815. case 'UCR':
  41816. case 'UCR2':
  41817. case 'TR':
  41818. case 'TR2':
  41819. case 'HT':
  41820. case 'SM':
  41821. case 'SA':
  41822. case 'AIS':
  41823. case 'TK':
  41824. // TODO implement these operators.
  41825. info('graphic state operator ' + key);
  41826. break;
  41827. default:
  41828. info('Unknown graphic state operator ' + key);
  41829. break;
  41830. }
  41831. }
  41832. return promise.then(function () {
  41833. if (gStateObj.length >= 0) {
  41834. operatorList.addOp(OPS.setGState, [gStateObj]);
  41835. }
  41836. });
  41837. },
  41838. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  41839. resources) {
  41840. function errorFont() {
  41841. return Promise.resolve(new TranslatedFont('g_font_error',
  41842. new ErrorFont('Font ' + fontName + ' is not available'), font));
  41843. }
  41844. var fontRef;
  41845. if (font) { // Loading by ref.
  41846. assert(isRef(font));
  41847. fontRef = font;
  41848. } else { // Loading by name.
  41849. var fontRes = resources.get('Font');
  41850. if (fontRes) {
  41851. fontRef = fontRes.getRaw(fontName);
  41852. } else {
  41853. warn('fontRes not available');
  41854. return errorFont();
  41855. }
  41856. }
  41857. if (!fontRef) {
  41858. warn('fontRef not available');
  41859. return errorFont();
  41860. }
  41861. if (this.fontCache.has(fontRef)) {
  41862. return this.fontCache.get(fontRef);
  41863. }
  41864. font = xref.fetchIfRef(fontRef);
  41865. if (!isDict(font)) {
  41866. return errorFont();
  41867. }
  41868. // We are holding font.translated references just for fontRef that are not
  41869. // dictionaries (Dict). See explanation below.
  41870. if (font.translated) {
  41871. return font.translated;
  41872. }
  41873. var fontCapability = createPromiseCapability();
  41874. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  41875. var descriptor = preEvaluatedFont.descriptor;
  41876. var fontID = fontRef.num + '_' + fontRef.gen;
  41877. if (isDict(descriptor)) {
  41878. if (!descriptor.fontAliases) {
  41879. descriptor.fontAliases = Object.create(null);
  41880. }
  41881. var fontAliases = descriptor.fontAliases;
  41882. var hash = preEvaluatedFont.hash;
  41883. if (fontAliases[hash]) {
  41884. var aliasFontRef = fontAliases[hash].aliasRef;
  41885. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  41886. this.fontCache.putAlias(fontRef, aliasFontRef);
  41887. return this.fontCache.get(fontRef);
  41888. }
  41889. }
  41890. if (!fontAliases[hash]) {
  41891. fontAliases[hash] = {
  41892. fontID: Font.getFontID()
  41893. };
  41894. }
  41895. fontAliases[hash].aliasRef = fontRef;
  41896. fontID = fontAliases[hash].fontID;
  41897. }
  41898. // Workaround for bad PDF generators that don't reference fonts
  41899. // properly, i.e. by not using an object identifier.
  41900. // Check if the fontRef is a Dict (as opposed to a standard object),
  41901. // in which case we don't cache the font and instead reference it by
  41902. // fontName in font.loadedName below.
  41903. var fontRefIsDict = isDict(fontRef);
  41904. if (!fontRefIsDict) {
  41905. this.fontCache.put(fontRef, fontCapability.promise);
  41906. }
  41907. // Keep track of each font we translated so the caller can
  41908. // load them asynchronously before calling display on a page.
  41909. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  41910. fontName.replace(/\W/g, '') : fontID);
  41911. font.translated = fontCapability.promise;
  41912. // TODO move promises into translate font
  41913. var translatedPromise;
  41914. try {
  41915. translatedPromise = Promise.resolve(
  41916. this.translateFont(preEvaluatedFont, xref));
  41917. } catch (e) {
  41918. translatedPromise = Promise.reject(e);
  41919. }
  41920. var self = this;
  41921. translatedPromise.then(function (translatedFont) {
  41922. if (translatedFont.fontType !== undefined) {
  41923. var xrefFontStats = xref.stats.fontTypes;
  41924. xrefFontStats[translatedFont.fontType] = true;
  41925. }
  41926. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41927. translatedFont, font));
  41928. }, function (reason) {
  41929. // TODO fontCapability.reject?
  41930. // Error in the font data -- sending unsupported feature notification.
  41931. self.handler.send('UnsupportedFeature',
  41932. {featureId: UNSUPPORTED_FEATURES.font});
  41933. try {
  41934. // error, but it's still nice to have font type reported
  41935. var descriptor = preEvaluatedFont.descriptor;
  41936. var fontFile3 = descriptor && descriptor.get('FontFile3');
  41937. var subtype = fontFile3 && fontFile3.get('Subtype');
  41938. var fontType = getFontType(preEvaluatedFont.type,
  41939. subtype && subtype.name);
  41940. var xrefFontStats = xref.stats.fontTypes;
  41941. xrefFontStats[fontType] = true;
  41942. } catch (ex) { }
  41943. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41944. new ErrorFont(reason instanceof Error ? reason.message : reason),
  41945. font));
  41946. });
  41947. return fontCapability.promise;
  41948. },
  41949. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  41950. var lastIndex = operatorList.length - 1;
  41951. if (!args) {
  41952. args = [];
  41953. }
  41954. if (lastIndex < 0 ||
  41955. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  41956. operatorList.addOp(OPS.constructPath, [[fn], args]);
  41957. } else {
  41958. var opArgs = operatorList.argsArray[lastIndex];
  41959. opArgs[0].push(fn);
  41960. Array.prototype.push.apply(opArgs[1], args);
  41961. }
  41962. },
  41963. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  41964. cs, patterns, resources, task, xref) {
  41965. // compile tiling patterns
  41966. var patternName = args[args.length - 1];
  41967. // SCN/scn applies patterns along with normal colors
  41968. var pattern;
  41969. if (isName(patternName) &&
  41970. (pattern = patterns.get(patternName.name))) {
  41971. var dict = (isStream(pattern) ? pattern.dict : pattern);
  41972. var typeNum = dict.get('PatternType');
  41973. if (typeNum === TILING_PATTERN) {
  41974. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  41975. return this.handleTilingType(fn, color, resources, pattern,
  41976. dict, operatorList, task);
  41977. } else if (typeNum === SHADING_PATTERN) {
  41978. var shading = dict.get('Shading');
  41979. var matrix = dict.get('Matrix');
  41980. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  41981. this.handler);
  41982. operatorList.addOp(fn, pattern.getIR());
  41983. return Promise.resolve();
  41984. } else {
  41985. return Promise.reject('Unknown PatternType: ' + typeNum);
  41986. }
  41987. }
  41988. // TODO shall we fail here?
  41989. operatorList.addOp(fn, args);
  41990. return Promise.resolve();
  41991. },
  41992. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  41993. task,
  41994. resources,
  41995. operatorList,
  41996. initialState) {
  41997. var self = this;
  41998. var xref = this.xref;
  41999. var imageCache = {};
  42000. assert(operatorList);
  42001. resources = (resources || Dict.empty);
  42002. var xobjs = (resources.get('XObject') || Dict.empty);
  42003. var patterns = (resources.get('Pattern') || Dict.empty);
  42004. var stateManager = new StateManager(initialState || new EvalState());
  42005. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42006. var timeSlotManager = new TimeSlotManager();
  42007. return new Promise(function next(resolve, reject) {
  42008. task.ensureNotTerminated();
  42009. timeSlotManager.reset();
  42010. var stop, operation = {}, i, ii, cs;
  42011. while (!(stop = timeSlotManager.check())) {
  42012. // The arguments parsed by read() are used beyond this loop, so we
  42013. // cannot reuse the same array on each iteration. Therefore we pass
  42014. // in |null| as the initial value (see the comment on
  42015. // EvaluatorPreprocessor_read() for why).
  42016. operation.args = null;
  42017. if (!(preprocessor.read(operation))) {
  42018. break;
  42019. }
  42020. var args = operation.args;
  42021. var fn = operation.fn;
  42022. switch (fn | 0) {
  42023. case OPS.paintXObject:
  42024. if (args[0].code) {
  42025. break;
  42026. }
  42027. // eagerly compile XForm objects
  42028. var name = args[0].name;
  42029. if (!name) {
  42030. warn('XObject must be referred to by name.');
  42031. continue;
  42032. }
  42033. if (imageCache[name] !== undefined) {
  42034. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  42035. args = null;
  42036. continue;
  42037. }
  42038. var xobj = xobjs.get(name);
  42039. if (xobj) {
  42040. assert(isStream(xobj), 'XObject should be a stream');
  42041. var type = xobj.dict.get('Subtype');
  42042. assert(isName(type),
  42043. 'XObject should have a Name subtype');
  42044. if (type.name === 'Form') {
  42045. stateManager.save();
  42046. return self.buildFormXObject(resources, xobj, null,
  42047. operatorList, task,
  42048. stateManager.state.clone()).
  42049. then(function () {
  42050. stateManager.restore();
  42051. next(resolve, reject);
  42052. }, reject);
  42053. } else if (type.name === 'Image') {
  42054. self.buildPaintImageXObject(resources, xobj, false,
  42055. operatorList, name, imageCache);
  42056. args = null;
  42057. continue;
  42058. } else if (type.name === 'PS') {
  42059. // PostScript XObjects are unused when viewing documents.
  42060. // See section 4.7.1 of Adobe's PDF reference.
  42061. info('Ignored XObject subtype PS');
  42062. continue;
  42063. } else {
  42064. error('Unhandled XObject subtype ' + type.name);
  42065. }
  42066. }
  42067. break;
  42068. case OPS.setFont:
  42069. var fontSize = args[1];
  42070. // eagerly collect all fonts
  42071. return self.handleSetFont(resources, args, null, operatorList,
  42072. task, stateManager.state).
  42073. then(function (loadedName) {
  42074. operatorList.addDependency(loadedName);
  42075. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  42076. next(resolve, reject);
  42077. }, reject);
  42078. case OPS.endInlineImage:
  42079. var cacheKey = args[0].cacheKey;
  42080. if (cacheKey) {
  42081. var cacheEntry = imageCache[cacheKey];
  42082. if (cacheEntry !== undefined) {
  42083. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  42084. args = null;
  42085. continue;
  42086. }
  42087. }
  42088. self.buildPaintImageXObject(resources, args[0], true,
  42089. operatorList, cacheKey, imageCache);
  42090. args = null;
  42091. continue;
  42092. case OPS.showText:
  42093. args[0] = self.handleText(args[0], stateManager.state);
  42094. break;
  42095. case OPS.showSpacedText:
  42096. var arr = args[0];
  42097. var combinedGlyphs = [];
  42098. var arrLength = arr.length;
  42099. var state = stateManager.state;
  42100. for (i = 0; i < arrLength; ++i) {
  42101. var arrItem = arr[i];
  42102. if (isString(arrItem)) {
  42103. Array.prototype.push.apply(combinedGlyphs,
  42104. self.handleText(arrItem, state));
  42105. } else if (isNum(arrItem)) {
  42106. combinedGlyphs.push(arrItem);
  42107. }
  42108. }
  42109. args[0] = combinedGlyphs;
  42110. fn = OPS.showText;
  42111. break;
  42112. case OPS.nextLineShowText:
  42113. operatorList.addOp(OPS.nextLine);
  42114. args[0] = self.handleText(args[0], stateManager.state);
  42115. fn = OPS.showText;
  42116. break;
  42117. case OPS.nextLineSetSpacingShowText:
  42118. operatorList.addOp(OPS.nextLine);
  42119. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  42120. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  42121. args[0] = self.handleText(args[0], stateManager.state);
  42122. fn = OPS.showText;
  42123. break;
  42124. case OPS.setTextRenderingMode:
  42125. stateManager.state.textRenderingMode = args[0];
  42126. break;
  42127. case OPS.setFillColorSpace:
  42128. stateManager.state.fillColorSpace =
  42129. ColorSpace.parse(args[0], xref, resources);
  42130. continue;
  42131. case OPS.setStrokeColorSpace:
  42132. stateManager.state.strokeColorSpace =
  42133. ColorSpace.parse(args[0], xref, resources);
  42134. continue;
  42135. case OPS.setFillColor:
  42136. cs = stateManager.state.fillColorSpace;
  42137. args = cs.getRgb(args, 0);
  42138. fn = OPS.setFillRGBColor;
  42139. break;
  42140. case OPS.setStrokeColor:
  42141. cs = stateManager.state.strokeColorSpace;
  42142. args = cs.getRgb(args, 0);
  42143. fn = OPS.setStrokeRGBColor;
  42144. break;
  42145. case OPS.setFillGray:
  42146. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  42147. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42148. fn = OPS.setFillRGBColor;
  42149. break;
  42150. case OPS.setStrokeGray:
  42151. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  42152. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42153. fn = OPS.setStrokeRGBColor;
  42154. break;
  42155. case OPS.setFillCMYKColor:
  42156. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  42157. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42158. fn = OPS.setFillRGBColor;
  42159. break;
  42160. case OPS.setStrokeCMYKColor:
  42161. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  42162. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42163. fn = OPS.setStrokeRGBColor;
  42164. break;
  42165. case OPS.setFillRGBColor:
  42166. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  42167. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42168. break;
  42169. case OPS.setStrokeRGBColor:
  42170. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  42171. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42172. break;
  42173. case OPS.setFillColorN:
  42174. cs = stateManager.state.fillColorSpace;
  42175. if (cs.name === 'Pattern') {
  42176. return self.handleColorN(operatorList, OPS.setFillColorN,
  42177. args, cs, patterns, resources, task, xref).then(function() {
  42178. next(resolve, reject);
  42179. }, reject);
  42180. }
  42181. args = cs.getRgb(args, 0);
  42182. fn = OPS.setFillRGBColor;
  42183. break;
  42184. case OPS.setStrokeColorN:
  42185. cs = stateManager.state.strokeColorSpace;
  42186. if (cs.name === 'Pattern') {
  42187. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  42188. args, cs, patterns, resources, task, xref).then(function() {
  42189. next(resolve, reject);
  42190. }, reject);
  42191. }
  42192. args = cs.getRgb(args, 0);
  42193. fn = OPS.setStrokeRGBColor;
  42194. break;
  42195. case OPS.shadingFill:
  42196. var shadingRes = resources.get('Shading');
  42197. if (!shadingRes) {
  42198. error('No shading resource found');
  42199. }
  42200. var shading = shadingRes.get(args[0].name);
  42201. if (!shading) {
  42202. error('No shading object found');
  42203. }
  42204. var shadingFill = Pattern.parseShading(shading, null, xref,
  42205. resources, self.handler);
  42206. var patternIR = shadingFill.getIR();
  42207. args = [patternIR];
  42208. fn = OPS.shadingFill;
  42209. break;
  42210. case OPS.setGState:
  42211. var dictName = args[0];
  42212. var extGState = resources.get('ExtGState');
  42213. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42214. break;
  42215. }
  42216. var gState = extGState.get(dictName.name);
  42217. return self.setGState(resources, gState, operatorList, task,
  42218. xref, stateManager).then(function() {
  42219. next(resolve, reject);
  42220. }, reject);
  42221. case OPS.moveTo:
  42222. case OPS.lineTo:
  42223. case OPS.curveTo:
  42224. case OPS.curveTo2:
  42225. case OPS.curveTo3:
  42226. case OPS.closePath:
  42227. self.buildPath(operatorList, fn, args);
  42228. continue;
  42229. case OPS.rectangle:
  42230. self.buildPath(operatorList, fn, args);
  42231. continue;
  42232. case OPS.markPoint:
  42233. case OPS.markPointProps:
  42234. case OPS.beginMarkedContent:
  42235. case OPS.beginMarkedContentProps:
  42236. case OPS.endMarkedContent:
  42237. case OPS.beginCompat:
  42238. case OPS.endCompat:
  42239. // Ignore operators where the corresponding handlers are known to
  42240. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  42241. // serialization errors and is also a bit more efficient.
  42242. // We could also try to serialize all objects in a general way,
  42243. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  42244. // but doing so is meaningless without knowing the semantics.
  42245. continue;
  42246. default:
  42247. // Note: Let's hope that the ignored operator does not have any
  42248. // non-serializable arguments, otherwise postMessage will throw
  42249. // "An object could not be cloned.".
  42250. }
  42251. operatorList.addOp(fn, args);
  42252. }
  42253. if (stop) {
  42254. deferred.then(function () {
  42255. next(resolve, reject);
  42256. }, reject);
  42257. return;
  42258. }
  42259. // Some PDFs don't close all restores inside object/form.
  42260. // Closing those for them.
  42261. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  42262. operatorList.addOp(OPS.restore, []);
  42263. }
  42264. resolve();
  42265. });
  42266. },
  42267. getTextContent:
  42268. function PartialEvaluator_getTextContent(stream, task, resources,
  42269. stateManager,
  42270. normalizeWhitespace) {
  42271. stateManager = (stateManager || new StateManager(new TextState()));
  42272. var WhitespaceRegexp = /\s/g;
  42273. var textContent = {
  42274. items: [],
  42275. styles: Object.create(null)
  42276. };
  42277. var textContentItem = {
  42278. initialized: false,
  42279. str: [],
  42280. width: 0,
  42281. height: 0,
  42282. vertical: false,
  42283. lastAdvanceWidth: 0,
  42284. lastAdvanceHeight: 0,
  42285. textAdvanceScale: 0,
  42286. spaceWidth: 0,
  42287. fakeSpaceMin: Infinity,
  42288. fakeMultiSpaceMin: Infinity,
  42289. fakeMultiSpaceMax: -0,
  42290. textRunBreakAllowed: false,
  42291. transform: null,
  42292. fontName: null
  42293. };
  42294. var SPACE_FACTOR = 0.3;
  42295. var MULTI_SPACE_FACTOR = 1.5;
  42296. var MULTI_SPACE_FACTOR_MAX = 4;
  42297. var self = this;
  42298. var xref = this.xref;
  42299. resources = (xref.fetchIfRef(resources) || Dict.empty);
  42300. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  42301. var xobjs = null;
  42302. var xobjsCache = {};
  42303. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42304. var textState;
  42305. function ensureTextContentItem() {
  42306. if (textContentItem.initialized) {
  42307. return textContentItem;
  42308. }
  42309. var font = textState.font;
  42310. if (!(font.loadedName in textContent.styles)) {
  42311. textContent.styles[font.loadedName] = {
  42312. fontFamily: font.fallbackName,
  42313. ascent: font.ascent,
  42314. descent: font.descent,
  42315. vertical: font.vertical
  42316. };
  42317. }
  42318. textContentItem.fontName = font.loadedName;
  42319. // 9.4.4 Text Space Details
  42320. var tsm = [textState.fontSize * textState.textHScale, 0,
  42321. 0, textState.fontSize,
  42322. 0, textState.textRise];
  42323. if (font.isType3Font &&
  42324. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  42325. textState.fontSize === 1) {
  42326. var glyphHeight = font.bbox[3] - font.bbox[1];
  42327. if (glyphHeight > 0) {
  42328. glyphHeight = glyphHeight * textState.fontMatrix[3];
  42329. tsm[3] *= glyphHeight;
  42330. }
  42331. }
  42332. var trm = Util.transform(textState.ctm,
  42333. Util.transform(textState.textMatrix, tsm));
  42334. textContentItem.transform = trm;
  42335. if (!font.vertical) {
  42336. textContentItem.width = 0;
  42337. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  42338. textContentItem.vertical = false;
  42339. } else {
  42340. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  42341. textContentItem.height = 0;
  42342. textContentItem.vertical = true;
  42343. }
  42344. var a = textState.textLineMatrix[0];
  42345. var b = textState.textLineMatrix[1];
  42346. var scaleLineX = Math.sqrt(a * a + b * b);
  42347. a = textState.ctm[0];
  42348. b = textState.ctm[1];
  42349. var scaleCtmX = Math.sqrt(a * a + b * b);
  42350. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  42351. textContentItem.lastAdvanceWidth = 0;
  42352. textContentItem.lastAdvanceHeight = 0;
  42353. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  42354. if (spaceWidth) {
  42355. textContentItem.spaceWidth = spaceWidth;
  42356. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  42357. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  42358. textContentItem.fakeMultiSpaceMax =
  42359. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  42360. // It's okay for monospace fonts to fake as much space as needed.
  42361. textContentItem.textRunBreakAllowed = !font.isMonospace;
  42362. } else {
  42363. textContentItem.spaceWidth = 0;
  42364. textContentItem.fakeSpaceMin = Infinity;
  42365. textContentItem.fakeMultiSpaceMin = Infinity;
  42366. textContentItem.fakeMultiSpaceMax = 0;
  42367. textContentItem.textRunBreakAllowed = false;
  42368. }
  42369. textContentItem.initialized = true;
  42370. return textContentItem;
  42371. }
  42372. function replaceWhitespace(str) {
  42373. // Replaces all whitespaces with standard spaces (0x20), to avoid
  42374. // alignment issues between the textLayer and the canvas if the text
  42375. // contains e.g. tabs (fixes issue6612.pdf).
  42376. var i = 0, ii = str.length, code;
  42377. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  42378. i++;
  42379. }
  42380. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  42381. }
  42382. function runBidiTransform(textChunk) {
  42383. var str = textChunk.str.join('');
  42384. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  42385. return {
  42386. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  42387. bidiResult.str),
  42388. dir: bidiResult.dir,
  42389. width: textChunk.width,
  42390. height: textChunk.height,
  42391. transform: textChunk.transform,
  42392. fontName: textChunk.fontName
  42393. };
  42394. }
  42395. function handleSetFont(fontName, fontRef) {
  42396. return self.loadFont(fontName, fontRef, xref, resources).
  42397. then(function (translated) {
  42398. textState.font = translated.font;
  42399. textState.fontMatrix = translated.font.fontMatrix ||
  42400. FONT_IDENTITY_MATRIX;
  42401. });
  42402. }
  42403. function buildTextContentItem(chars) {
  42404. var font = textState.font;
  42405. var textChunk = ensureTextContentItem();
  42406. var width = 0;
  42407. var height = 0;
  42408. var glyphs = font.charsToGlyphs(chars);
  42409. var defaultVMetrics = font.defaultVMetrics;
  42410. for (var i = 0; i < glyphs.length; i++) {
  42411. var glyph = glyphs[i];
  42412. var vMetricX = null;
  42413. var vMetricY = null;
  42414. var glyphWidth = null;
  42415. if (font.vertical) {
  42416. if (glyph.vmetric) {
  42417. glyphWidth = glyph.vmetric[0];
  42418. vMetricX = glyph.vmetric[1];
  42419. vMetricY = glyph.vmetric[2];
  42420. } else {
  42421. glyphWidth = glyph.width;
  42422. vMetricX = glyph.width * 0.5;
  42423. vMetricY = defaultVMetrics[2];
  42424. }
  42425. } else {
  42426. glyphWidth = glyph.width;
  42427. }
  42428. var glyphUnicode = glyph.unicode;
  42429. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  42430. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  42431. }
  42432. glyphUnicode = reverseIfRtl(glyphUnicode);
  42433. // The following will calculate the x and y of the individual glyphs.
  42434. // if (font.vertical) {
  42435. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  42436. // textState.fontMatrix[0];
  42437. // tsm[5] -= vMetricY * textState.fontSize *
  42438. // textState.fontMatrix[0];
  42439. // }
  42440. // var trm = Util.transform(textState.textMatrix, tsm);
  42441. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  42442. // var x = pt[0];
  42443. // var y = pt[1];
  42444. var charSpacing = textState.charSpacing;
  42445. if (glyph.isSpace) {
  42446. var wordSpacing = textState.wordSpacing;
  42447. charSpacing += wordSpacing;
  42448. if (wordSpacing > 0) {
  42449. addFakeSpaces(wordSpacing, textChunk.str);
  42450. }
  42451. }
  42452. var tx = 0;
  42453. var ty = 0;
  42454. if (!font.vertical) {
  42455. var w0 = glyphWidth * textState.fontMatrix[0];
  42456. tx = (w0 * textState.fontSize + charSpacing) *
  42457. textState.textHScale;
  42458. width += tx;
  42459. } else {
  42460. var w1 = glyphWidth * textState.fontMatrix[0];
  42461. ty = w1 * textState.fontSize + charSpacing;
  42462. height += ty;
  42463. }
  42464. textState.translateTextMatrix(tx, ty);
  42465. textChunk.str.push(glyphUnicode);
  42466. }
  42467. if (!font.vertical) {
  42468. textChunk.lastAdvanceWidth = width;
  42469. textChunk.width += width * textChunk.textAdvanceScale;
  42470. } else {
  42471. textChunk.lastAdvanceHeight = height;
  42472. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  42473. }
  42474. return textChunk;
  42475. }
  42476. function addFakeSpaces(width, strBuf) {
  42477. if (width < textContentItem.fakeSpaceMin) {
  42478. return;
  42479. }
  42480. if (width < textContentItem.fakeMultiSpaceMin) {
  42481. strBuf.push(' ');
  42482. return;
  42483. }
  42484. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  42485. while (fakeSpaces-- > 0) {
  42486. strBuf.push(' ');
  42487. }
  42488. }
  42489. function flushTextContentItem() {
  42490. if (!textContentItem.initialized) {
  42491. return;
  42492. }
  42493. textContent.items.push(runBidiTransform(textContentItem));
  42494. textContentItem.initialized = false;
  42495. textContentItem.str.length = 0;
  42496. }
  42497. var timeSlotManager = new TimeSlotManager();
  42498. return new Promise(function next(resolve, reject) {
  42499. task.ensureNotTerminated();
  42500. timeSlotManager.reset();
  42501. var stop, operation = {}, args = [];
  42502. while (!(stop = timeSlotManager.check())) {
  42503. // The arguments parsed by read() are not used beyond this loop, so
  42504. // we can reuse the same array on every iteration, thus avoiding
  42505. // unnecessary allocations.
  42506. args.length = 0;
  42507. operation.args = args;
  42508. if (!(preprocessor.read(operation))) {
  42509. break;
  42510. }
  42511. textState = stateManager.state;
  42512. var fn = operation.fn;
  42513. args = operation.args;
  42514. var advance;
  42515. switch (fn | 0) {
  42516. case OPS.setFont:
  42517. flushTextContentItem();
  42518. textState.fontSize = args[1];
  42519. return handleSetFont(args[0].name).then(function() {
  42520. next(resolve, reject);
  42521. }, reject);
  42522. case OPS.setTextRise:
  42523. flushTextContentItem();
  42524. textState.textRise = args[0];
  42525. break;
  42526. case OPS.setHScale:
  42527. flushTextContentItem();
  42528. textState.textHScale = args[0] / 100;
  42529. break;
  42530. case OPS.setLeading:
  42531. flushTextContentItem();
  42532. textState.leading = args[0];
  42533. break;
  42534. case OPS.moveText:
  42535. // Optimization to treat same line movement as advance
  42536. var isSameTextLine = !textState.font ? false :
  42537. ((textState.font.vertical ? args[0] : args[1]) === 0);
  42538. advance = args[0] - args[1];
  42539. if (isSameTextLine && textContentItem.initialized &&
  42540. advance > 0 &&
  42541. advance <= textContentItem.fakeMultiSpaceMax) {
  42542. textState.translateTextLineMatrix(args[0], args[1]);
  42543. textContentItem.width +=
  42544. (args[0] - textContentItem.lastAdvanceWidth);
  42545. textContentItem.height +=
  42546. (args[1] - textContentItem.lastAdvanceHeight);
  42547. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  42548. (args[1] - textContentItem.lastAdvanceHeight);
  42549. addFakeSpaces(diff, textContentItem.str);
  42550. break;
  42551. }
  42552. flushTextContentItem();
  42553. textState.translateTextLineMatrix(args[0], args[1]);
  42554. textState.textMatrix = textState.textLineMatrix.slice();
  42555. break;
  42556. case OPS.setLeadingMoveText:
  42557. flushTextContentItem();
  42558. textState.leading = -args[1];
  42559. textState.translateTextLineMatrix(args[0], args[1]);
  42560. textState.textMatrix = textState.textLineMatrix.slice();
  42561. break;
  42562. case OPS.nextLine:
  42563. flushTextContentItem();
  42564. textState.carriageReturn();
  42565. break;
  42566. case OPS.setTextMatrix:
  42567. flushTextContentItem();
  42568. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  42569. args[4], args[5]);
  42570. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  42571. args[4], args[5]);
  42572. break;
  42573. case OPS.setCharSpacing:
  42574. textState.charSpacing = args[0];
  42575. break;
  42576. case OPS.setWordSpacing:
  42577. textState.wordSpacing = args[0];
  42578. break;
  42579. case OPS.beginText:
  42580. flushTextContentItem();
  42581. textState.textMatrix = IDENTITY_MATRIX.slice();
  42582. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  42583. break;
  42584. case OPS.showSpacedText:
  42585. var items = args[0];
  42586. var offset;
  42587. for (var j = 0, jj = items.length; j < jj; j++) {
  42588. if (typeof items[j] === 'string') {
  42589. buildTextContentItem(items[j]);
  42590. } else {
  42591. ensureTextContentItem();
  42592. // PDF Specification 5.3.2 states:
  42593. // The number is expressed in thousandths of a unit of text
  42594. // space.
  42595. // This amount is subtracted from the current horizontal or
  42596. // vertical coordinate, depending on the writing mode.
  42597. // In the default coordinate system, a positive adjustment
  42598. // has the effect of moving the next glyph painted either to
  42599. // the left or down by the given amount.
  42600. advance = items[j] * textState.fontSize / 1000;
  42601. var breakTextRun = false;
  42602. if (textState.font.vertical) {
  42603. offset = advance *
  42604. (textState.textHScale * textState.textMatrix[2] +
  42605. textState.textMatrix[3]);
  42606. textState.translateTextMatrix(0, advance);
  42607. breakTextRun = textContentItem.textRunBreakAllowed &&
  42608. advance > textContentItem.fakeMultiSpaceMax;
  42609. if (!breakTextRun) {
  42610. // Value needs to be added to height to paint down.
  42611. textContentItem.height += offset;
  42612. }
  42613. } else {
  42614. advance = -advance;
  42615. offset = advance * (
  42616. textState.textHScale * textState.textMatrix[0] +
  42617. textState.textMatrix[1]);
  42618. textState.translateTextMatrix(advance, 0);
  42619. breakTextRun = textContentItem.textRunBreakAllowed &&
  42620. advance > textContentItem.fakeMultiSpaceMax;
  42621. if (!breakTextRun) {
  42622. // Value needs to be subtracted from width to paint left.
  42623. textContentItem.width += offset;
  42624. }
  42625. }
  42626. if (breakTextRun) {
  42627. flushTextContentItem();
  42628. } else if (advance > 0) {
  42629. addFakeSpaces(advance, textContentItem.str);
  42630. }
  42631. }
  42632. }
  42633. break;
  42634. case OPS.showText:
  42635. buildTextContentItem(args[0]);
  42636. break;
  42637. case OPS.nextLineShowText:
  42638. flushTextContentItem();
  42639. textState.carriageReturn();
  42640. buildTextContentItem(args[0]);
  42641. break;
  42642. case OPS.nextLineSetSpacingShowText:
  42643. flushTextContentItem();
  42644. textState.wordSpacing = args[0];
  42645. textState.charSpacing = args[1];
  42646. textState.carriageReturn();
  42647. buildTextContentItem(args[2]);
  42648. break;
  42649. case OPS.paintXObject:
  42650. flushTextContentItem();
  42651. if (args[0].code) {
  42652. break;
  42653. }
  42654. if (!xobjs) {
  42655. xobjs = (resources.get('XObject') || Dict.empty);
  42656. }
  42657. var name = args[0].name;
  42658. if (xobjsCache.key === name) {
  42659. if (xobjsCache.texts) {
  42660. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  42661. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  42662. }
  42663. break;
  42664. }
  42665. var xobj = xobjs.get(name);
  42666. if (!xobj) {
  42667. break;
  42668. }
  42669. assert(isStream(xobj), 'XObject should be a stream');
  42670. var type = xobj.dict.get('Subtype');
  42671. assert(isName(type),
  42672. 'XObject should have a Name subtype');
  42673. if ('Form' !== type.name) {
  42674. xobjsCache.key = name;
  42675. xobjsCache.texts = null;
  42676. break;
  42677. }
  42678. stateManager.save();
  42679. var matrix = xobj.dict.get('Matrix');
  42680. if (isArray(matrix) && matrix.length === 6) {
  42681. stateManager.transform(matrix);
  42682. }
  42683. return self.getTextContent(xobj, task,
  42684. xobj.dict.get('Resources') || resources, stateManager,
  42685. normalizeWhitespace).then(function (formTextContent) {
  42686. Util.appendToArray(textContent.items, formTextContent.items);
  42687. Util.extendObj(textContent.styles, formTextContent.styles);
  42688. stateManager.restore();
  42689. xobjsCache.key = name;
  42690. xobjsCache.texts = formTextContent;
  42691. next(resolve, reject);
  42692. }, reject);
  42693. case OPS.setGState:
  42694. flushTextContentItem();
  42695. var dictName = args[0];
  42696. var extGState = resources.get('ExtGState');
  42697. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42698. break;
  42699. }
  42700. var gsStateMap = extGState.get(dictName.name);
  42701. var gsStateFont = null;
  42702. for (var key in gsStateMap) {
  42703. if (key === 'Font') {
  42704. assert(!gsStateFont);
  42705. gsStateFont = gsStateMap[key];
  42706. }
  42707. }
  42708. if (gsStateFont) {
  42709. textState.fontSize = gsStateFont[1];
  42710. return handleSetFont(gsStateFont[0]).then(function() {
  42711. next(resolve, reject);
  42712. }, reject);
  42713. }
  42714. break;
  42715. } // switch
  42716. } // while
  42717. if (stop) {
  42718. deferred.then(function () {
  42719. next(resolve, reject);
  42720. }, reject);
  42721. return;
  42722. }
  42723. flushTextContentItem();
  42724. resolve(textContent);
  42725. });
  42726. },
  42727. extractDataStructures: function
  42728. partialEvaluatorExtractDataStructures(dict, baseDict,
  42729. xref, properties) {
  42730. // 9.10.2
  42731. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  42732. if (toUnicode) {
  42733. properties.toUnicode = this.readToUnicode(toUnicode);
  42734. }
  42735. if (properties.composite) {
  42736. // CIDSystemInfo helps to match CID to glyphs
  42737. var cidSystemInfo = dict.get('CIDSystemInfo');
  42738. if (isDict(cidSystemInfo)) {
  42739. properties.cidSystemInfo = {
  42740. registry: cidSystemInfo.get('Registry'),
  42741. ordering: cidSystemInfo.get('Ordering'),
  42742. supplement: cidSystemInfo.get('Supplement')
  42743. };
  42744. }
  42745. var cidToGidMap = dict.get('CIDToGIDMap');
  42746. if (isStream(cidToGidMap)) {
  42747. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  42748. }
  42749. }
  42750. // Based on 9.6.6 of the spec the encoding can come from multiple places
  42751. // and depends on the font type. The base encoding and differences are
  42752. // read here, but the encoding that is actually used is chosen during
  42753. // glyph mapping in the font.
  42754. // TODO: Loading the built in encoding in the font would allow the
  42755. // differences to be merged in here not require us to hold on to it.
  42756. var differences = [];
  42757. var baseEncodingName = null;
  42758. var encoding;
  42759. if (dict.has('Encoding')) {
  42760. encoding = dict.get('Encoding');
  42761. if (isDict(encoding)) {
  42762. baseEncodingName = encoding.get('BaseEncoding');
  42763. baseEncodingName = (isName(baseEncodingName) ?
  42764. baseEncodingName.name : null);
  42765. // Load the differences between the base and original
  42766. if (encoding.has('Differences')) {
  42767. var diffEncoding = encoding.get('Differences');
  42768. var index = 0;
  42769. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  42770. var data = diffEncoding[j];
  42771. if (isNum(data)) {
  42772. index = data;
  42773. } else if (isName(data)) {
  42774. differences[index++] = data.name;
  42775. } else if (isRef(data)) {
  42776. diffEncoding[j--] = xref.fetch(data);
  42777. continue;
  42778. } else {
  42779. error('Invalid entry in \'Differences\' array: ' + data);
  42780. }
  42781. }
  42782. }
  42783. } else if (isName(encoding)) {
  42784. baseEncodingName = encoding.name;
  42785. } else {
  42786. error('Encoding is not a Name nor a Dict');
  42787. }
  42788. // According to table 114 if the encoding is a named encoding it must be
  42789. // one of these predefined encodings.
  42790. if ((baseEncodingName !== 'MacRomanEncoding' &&
  42791. baseEncodingName !== 'MacExpertEncoding' &&
  42792. baseEncodingName !== 'WinAnsiEncoding')) {
  42793. baseEncodingName = null;
  42794. }
  42795. }
  42796. if (baseEncodingName) {
  42797. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  42798. } else {
  42799. encoding = (properties.type === 'TrueType' ?
  42800. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  42801. // The Symbolic attribute can be misused for regular fonts
  42802. // Heuristic: we have to check if the font is a standard one also
  42803. if (!!(properties.flags & FontFlags.Symbolic)) {
  42804. encoding = Encodings.MacRomanEncoding;
  42805. if (!properties.file) {
  42806. if (/Symbol/i.test(properties.name)) {
  42807. encoding = Encodings.SymbolSetEncoding;
  42808. } else if (/Dingbats/i.test(properties.name)) {
  42809. encoding = Encodings.ZapfDingbatsEncoding;
  42810. }
  42811. }
  42812. }
  42813. properties.defaultEncoding = encoding;
  42814. }
  42815. properties.differences = differences;
  42816. properties.baseEncodingName = baseEncodingName;
  42817. properties.dict = dict;
  42818. },
  42819. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  42820. var cmap, cmapObj = toUnicode;
  42821. if (isName(cmapObj)) {
  42822. cmap = CMapFactory.create(cmapObj,
  42823. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42824. if (cmap instanceof IdentityCMap) {
  42825. return new IdentityToUnicodeMap(0, 0xFFFF);
  42826. }
  42827. return new ToUnicodeMap(cmap.getMap());
  42828. } else if (isStream(cmapObj)) {
  42829. cmap = CMapFactory.create(cmapObj,
  42830. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42831. if (cmap instanceof IdentityCMap) {
  42832. return new IdentityToUnicodeMap(0, 0xFFFF);
  42833. }
  42834. var map = new Array(cmap.length);
  42835. // Convert UTF-16BE
  42836. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  42837. // to iterate over all keys.
  42838. cmap.forEach(function(charCode, token) {
  42839. var str = [];
  42840. for (var k = 0; k < token.length; k += 2) {
  42841. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42842. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  42843. str.push(w1);
  42844. continue;
  42845. }
  42846. k += 2;
  42847. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42848. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  42849. }
  42850. map[charCode] = String.fromCharCode.apply(String, str);
  42851. });
  42852. return new ToUnicodeMap(map);
  42853. }
  42854. return null;
  42855. },
  42856. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  42857. // Extract the encoding from the CIDToGIDMap
  42858. var glyphsData = cidToGidStream.getBytes();
  42859. // Set encoding 0 to later verify the font has an encoding
  42860. var result = [];
  42861. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  42862. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  42863. if (glyphID === 0) {
  42864. continue;
  42865. }
  42866. var code = j >> 1;
  42867. result[code] = glyphID;
  42868. }
  42869. return result;
  42870. },
  42871. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  42872. descriptor,
  42873. properties) {
  42874. var glyphsWidths = [];
  42875. var defaultWidth = 0;
  42876. var glyphsVMetrics = [];
  42877. var defaultVMetrics;
  42878. var i, ii, j, jj, start, code, widths;
  42879. if (properties.composite) {
  42880. defaultWidth = dict.get('DW') || 1000;
  42881. widths = dict.get('W');
  42882. if (widths) {
  42883. for (i = 0, ii = widths.length; i < ii; i++) {
  42884. start = widths[i++];
  42885. code = xref.fetchIfRef(widths[i]);
  42886. if (isArray(code)) {
  42887. for (j = 0, jj = code.length; j < jj; j++) {
  42888. glyphsWidths[start++] = code[j];
  42889. }
  42890. } else {
  42891. var width = widths[++i];
  42892. for (j = start; j <= code; j++) {
  42893. glyphsWidths[j] = width;
  42894. }
  42895. }
  42896. }
  42897. }
  42898. if (properties.vertical) {
  42899. var vmetrics = (dict.get('DW2') || [880, -1000]);
  42900. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  42901. vmetrics = dict.get('W2');
  42902. if (vmetrics) {
  42903. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  42904. start = vmetrics[i++];
  42905. code = xref.fetchIfRef(vmetrics[i]);
  42906. if (isArray(code)) {
  42907. for (j = 0, jj = code.length; j < jj; j++) {
  42908. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  42909. }
  42910. } else {
  42911. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  42912. for (j = start; j <= code; j++) {
  42913. glyphsVMetrics[j] = vmetric;
  42914. }
  42915. }
  42916. }
  42917. }
  42918. }
  42919. } else {
  42920. var firstChar = properties.firstChar;
  42921. widths = dict.get('Widths');
  42922. if (widths) {
  42923. j = firstChar;
  42924. for (i = 0, ii = widths.length; i < ii; i++) {
  42925. glyphsWidths[j++] = widths[i];
  42926. }
  42927. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  42928. } else {
  42929. // Trying get the BaseFont metrics (see comment above).
  42930. var baseFontName = dict.get('BaseFont');
  42931. if (isName(baseFontName)) {
  42932. var metrics = this.getBaseFontMetrics(baseFontName.name);
  42933. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  42934. properties);
  42935. defaultWidth = metrics.defaultWidth;
  42936. }
  42937. }
  42938. }
  42939. // Heuristic: detection of monospace font by checking all non-zero widths
  42940. var isMonospace = true;
  42941. var firstWidth = defaultWidth;
  42942. for (var glyph in glyphsWidths) {
  42943. var glyphWidth = glyphsWidths[glyph];
  42944. if (!glyphWidth) {
  42945. continue;
  42946. }
  42947. if (!firstWidth) {
  42948. firstWidth = glyphWidth;
  42949. continue;
  42950. }
  42951. if (firstWidth !== glyphWidth) {
  42952. isMonospace = false;
  42953. break;
  42954. }
  42955. }
  42956. if (isMonospace) {
  42957. properties.flags |= FontFlags.FixedPitch;
  42958. }
  42959. properties.defaultWidth = defaultWidth;
  42960. properties.widths = glyphsWidths;
  42961. properties.defaultVMetrics = defaultVMetrics;
  42962. properties.vmetrics = glyphsVMetrics;
  42963. },
  42964. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  42965. // Simulating descriptor flags attribute
  42966. var fontNameWoStyle = baseFontName.split('-')[0];
  42967. return (fontNameWoStyle in serifFonts) ||
  42968. (fontNameWoStyle.search(/serif/gi) !== -1);
  42969. },
  42970. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  42971. var defaultWidth = 0;
  42972. var widths = [];
  42973. var monospace = false;
  42974. var lookupName = (stdFontMap[name] || name);
  42975. if (!(lookupName in Metrics)) {
  42976. // Use default fonts for looking up font metrics if the passed
  42977. // font is not a base font
  42978. if (this.isSerifFont(name)) {
  42979. lookupName = 'Times-Roman';
  42980. } else {
  42981. lookupName = 'Helvetica';
  42982. }
  42983. }
  42984. var glyphWidths = Metrics[lookupName];
  42985. if (isNum(glyphWidths)) {
  42986. defaultWidth = glyphWidths;
  42987. monospace = true;
  42988. } else {
  42989. widths = glyphWidths;
  42990. }
  42991. return {
  42992. defaultWidth: defaultWidth,
  42993. monospace: monospace,
  42994. widths: widths
  42995. };
  42996. },
  42997. buildCharCodeToWidth:
  42998. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  42999. properties) {
  43000. var widths = Object.create(null);
  43001. var differences = properties.differences;
  43002. var encoding = properties.defaultEncoding;
  43003. for (var charCode = 0; charCode < 256; charCode++) {
  43004. if (charCode in differences &&
  43005. widthsByGlyphName[differences[charCode]]) {
  43006. widths[charCode] = widthsByGlyphName[differences[charCode]];
  43007. continue;
  43008. }
  43009. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  43010. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  43011. continue;
  43012. }
  43013. }
  43014. return widths;
  43015. },
  43016. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  43017. var baseDict = dict;
  43018. var type = dict.get('Subtype');
  43019. assert(isName(type), 'invalid font Subtype');
  43020. var composite = false;
  43021. var uint8array;
  43022. if (type.name === 'Type0') {
  43023. // If font is a composite
  43024. // - get the descendant font
  43025. // - set the type according to the descendant font
  43026. // - get the FontDescriptor from the descendant font
  43027. var df = dict.get('DescendantFonts');
  43028. if (!df) {
  43029. error('Descendant fonts are not specified');
  43030. }
  43031. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  43032. type = dict.get('Subtype');
  43033. assert(isName(type), 'invalid font Subtype');
  43034. composite = true;
  43035. }
  43036. var descriptor = dict.get('FontDescriptor');
  43037. if (descriptor) {
  43038. var hash = new MurmurHash3_64();
  43039. var encoding = baseDict.getRaw('Encoding');
  43040. if (isName(encoding)) {
  43041. hash.update(encoding.name);
  43042. } else if (isRef(encoding)) {
  43043. hash.update(encoding.num + '_' + encoding.gen);
  43044. } else if (isDict(encoding)) {
  43045. var keys = encoding.getKeys();
  43046. for (var i = 0, ii = keys.length; i < ii; i++) {
  43047. var entry = encoding.getRaw(keys[i]);
  43048. if (isName(entry)) {
  43049. hash.update(entry.name);
  43050. } else if (isRef(entry)) {
  43051. hash.update(entry.num + '_' + entry.gen);
  43052. } else if (isArray(entry)) { // 'Differences' entry.
  43053. // Ideally we should check the contents of the array, but to avoid
  43054. // parsing it here and then again in |extractDataStructures|,
  43055. // we only use the array length for now (fixes bug1157493.pdf).
  43056. hash.update(entry.length.toString());
  43057. }
  43058. }
  43059. }
  43060. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  43061. if (isStream(toUnicode)) {
  43062. var stream = toUnicode.str || toUnicode;
  43063. uint8array = stream.buffer ?
  43064. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  43065. new Uint8Array(stream.bytes.buffer,
  43066. stream.start, stream.end - stream.start);
  43067. hash.update(uint8array);
  43068. } else if (isName(toUnicode)) {
  43069. hash.update(toUnicode.name);
  43070. }
  43071. var widths = dict.get('Widths') || baseDict.get('Widths');
  43072. if (widths) {
  43073. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  43074. hash.update(uint8array);
  43075. }
  43076. }
  43077. return {
  43078. descriptor: descriptor,
  43079. dict: dict,
  43080. baseDict: baseDict,
  43081. composite: composite,
  43082. type: type.name,
  43083. hash: hash ? hash.hexdigest() : ''
  43084. };
  43085. },
  43086. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  43087. xref) {
  43088. var baseDict = preEvaluatedFont.baseDict;
  43089. var dict = preEvaluatedFont.dict;
  43090. var composite = preEvaluatedFont.composite;
  43091. var descriptor = preEvaluatedFont.descriptor;
  43092. var type = preEvaluatedFont.type;
  43093. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  43094. var properties;
  43095. if (!descriptor) {
  43096. if (type === 'Type3') {
  43097. // FontDescriptor is only required for Type3 fonts when the document
  43098. // is a tagged pdf. Create a barbebones one to get by.
  43099. descriptor = new Dict(null);
  43100. descriptor.set('FontName', Name.get(type));
  43101. descriptor.set('FontBBox', dict.get('FontBBox'));
  43102. } else {
  43103. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  43104. // FontDescriptor was not required.
  43105. // This case is here for compatibility.
  43106. var baseFontName = dict.get('BaseFont');
  43107. if (!isName(baseFontName)) {
  43108. error('Base font is not specified');
  43109. }
  43110. // Using base font name as a font name.
  43111. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  43112. var metrics = this.getBaseFontMetrics(baseFontName);
  43113. // Simulating descriptor flags attribute
  43114. var fontNameWoStyle = baseFontName.split('-')[0];
  43115. var flags =
  43116. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  43117. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  43118. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  43119. FontFlags.Nonsymbolic);
  43120. properties = {
  43121. type: type,
  43122. name: baseFontName,
  43123. widths: metrics.widths,
  43124. defaultWidth: metrics.defaultWidth,
  43125. flags: flags,
  43126. firstChar: 0,
  43127. lastChar: maxCharIndex
  43128. };
  43129. this.extractDataStructures(dict, dict, xref, properties);
  43130. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  43131. properties);
  43132. return new Font(baseFontName, null, properties);
  43133. }
  43134. }
  43135. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  43136. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  43137. // to ignore this rule when a variant of a standart font is used.
  43138. // TODO Fill the width array depending on which of the base font this is
  43139. // a variant.
  43140. var firstChar = (dict.get('FirstChar') || 0);
  43141. var lastChar = (dict.get('LastChar') || maxCharIndex);
  43142. var fontName = descriptor.get('FontName');
  43143. var baseFont = dict.get('BaseFont');
  43144. // Some bad PDFs have a string as the font name.
  43145. if (isString(fontName)) {
  43146. fontName = Name.get(fontName);
  43147. }
  43148. if (isString(baseFont)) {
  43149. baseFont = Name.get(baseFont);
  43150. }
  43151. if (type !== 'Type3') {
  43152. var fontNameStr = fontName && fontName.name;
  43153. var baseFontStr = baseFont && baseFont.name;
  43154. if (fontNameStr !== baseFontStr) {
  43155. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  43156. '" but should be the same as the Font\'s BaseFont "' +
  43157. baseFontStr + '"');
  43158. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  43159. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  43160. if (fontNameStr && baseFontStr &&
  43161. baseFontStr.indexOf(fontNameStr) === 0) {
  43162. fontName = baseFont;
  43163. }
  43164. }
  43165. }
  43166. fontName = (fontName || baseFont);
  43167. assert(isName(fontName), 'invalid font name');
  43168. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  43169. if (fontFile) {
  43170. if (fontFile.dict) {
  43171. var subtype = fontFile.dict.get('Subtype');
  43172. if (subtype) {
  43173. subtype = subtype.name;
  43174. }
  43175. var length1 = fontFile.dict.get('Length1');
  43176. var length2 = fontFile.dict.get('Length2');
  43177. }
  43178. }
  43179. properties = {
  43180. type: type,
  43181. name: fontName.name,
  43182. subtype: subtype,
  43183. file: fontFile,
  43184. length1: length1,
  43185. length2: length2,
  43186. loadedName: baseDict.loadedName,
  43187. composite: composite,
  43188. wideChars: composite,
  43189. fixedPitch: false,
  43190. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  43191. firstChar: firstChar || 0,
  43192. lastChar: (lastChar || maxCharIndex),
  43193. bbox: descriptor.get('FontBBox'),
  43194. ascent: descriptor.get('Ascent'),
  43195. descent: descriptor.get('Descent'),
  43196. xHeight: descriptor.get('XHeight'),
  43197. capHeight: descriptor.get('CapHeight'),
  43198. flags: descriptor.get('Flags'),
  43199. italicAngle: descriptor.get('ItalicAngle'),
  43200. coded: false
  43201. };
  43202. if (composite) {
  43203. var cidEncoding = baseDict.get('Encoding');
  43204. if (isName(cidEncoding)) {
  43205. properties.cidEncoding = cidEncoding.name;
  43206. }
  43207. properties.cMap = CMapFactory.create(cidEncoding,
  43208. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43209. properties.vertical = properties.cMap.vertical;
  43210. }
  43211. this.extractDataStructures(dict, baseDict, xref, properties);
  43212. this.extractWidths(dict, xref, descriptor, properties);
  43213. if (type === 'Type3') {
  43214. properties.isType3Font = true;
  43215. }
  43216. return new Font(fontName.name, fontFile, properties);
  43217. }
  43218. };
  43219. return PartialEvaluator;
  43220. })();
  43221. var TranslatedFont = (function TranslatedFontClosure() {
  43222. function TranslatedFont(loadedName, font, dict) {
  43223. this.loadedName = loadedName;
  43224. this.font = font;
  43225. this.dict = dict;
  43226. this.type3Loaded = null;
  43227. this.sent = false;
  43228. }
  43229. TranslatedFont.prototype = {
  43230. send: function (handler) {
  43231. if (this.sent) {
  43232. return;
  43233. }
  43234. var fontData = this.font.exportData();
  43235. handler.send('commonobj', [
  43236. this.loadedName,
  43237. 'Font',
  43238. fontData
  43239. ]);
  43240. this.sent = true;
  43241. },
  43242. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  43243. assert(this.font.isType3Font);
  43244. if (this.type3Loaded) {
  43245. return this.type3Loaded;
  43246. }
  43247. var translatedFont = this.font;
  43248. var loadCharProcsPromise = Promise.resolve();
  43249. var charProcs = this.dict.get('CharProcs').getAll();
  43250. var fontResources = this.dict.get('Resources') || resources;
  43251. var charProcKeys = Object.keys(charProcs);
  43252. var charProcOperatorList = {};
  43253. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  43254. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  43255. var glyphStream = charProcs[key];
  43256. var operatorList = new OperatorList();
  43257. return evaluator.getOperatorList(glyphStream, task, fontResources,
  43258. operatorList).then(function () {
  43259. charProcOperatorList[key] = operatorList.getIR();
  43260. // Add the dependencies to the parent operator list so they are
  43261. // resolved before sub operator list is executed synchronously.
  43262. parentOperatorList.addDependencies(operatorList.dependencies);
  43263. }, function (reason) {
  43264. warn('Type3 font resource \"' + key + '\" is not available');
  43265. var operatorList = new OperatorList();
  43266. charProcOperatorList[key] = operatorList.getIR();
  43267. });
  43268. }.bind(this, charProcKeys[i]));
  43269. }
  43270. this.type3Loaded = loadCharProcsPromise.then(function () {
  43271. translatedFont.charProcOperatorList = charProcOperatorList;
  43272. });
  43273. return this.type3Loaded;
  43274. }
  43275. };
  43276. return TranslatedFont;
  43277. })();
  43278. var OperatorList = (function OperatorListClosure() {
  43279. var CHUNK_SIZE = 1000;
  43280. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  43281. function getTransfers(queue) {
  43282. var transfers = [];
  43283. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43284. for (var i = 0, ii = queue.length; i < ii; i++) {
  43285. switch (fnArray[i]) {
  43286. case OPS.paintInlineImageXObject:
  43287. case OPS.paintInlineImageXObjectGroup:
  43288. case OPS.paintImageMaskXObject:
  43289. var arg = argsArray[i][0]; // first param in imgData
  43290. if (!arg.cached) {
  43291. transfers.push(arg.data.buffer);
  43292. }
  43293. break;
  43294. }
  43295. }
  43296. return transfers;
  43297. }
  43298. function OperatorList(intent, messageHandler, pageIndex) {
  43299. this.messageHandler = messageHandler;
  43300. this.fnArray = [];
  43301. this.argsArray = [];
  43302. this.dependencies = {};
  43303. this._totalLength = 0;
  43304. this.pageIndex = pageIndex;
  43305. this.intent = intent;
  43306. }
  43307. OperatorList.prototype = {
  43308. get length() {
  43309. return this.argsArray.length;
  43310. },
  43311. /**
  43312. * @returns {number} The total length of the entire operator list,
  43313. * since `this.length === 0` after flushing.
  43314. */
  43315. get totalLength() {
  43316. return (this._totalLength + this.length);
  43317. },
  43318. addOp: function(fn, args) {
  43319. this.fnArray.push(fn);
  43320. this.argsArray.push(args);
  43321. if (this.messageHandler) {
  43322. if (this.fnArray.length >= CHUNK_SIZE) {
  43323. this.flush();
  43324. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  43325. (fn === OPS.restore || fn === OPS.endText)) {
  43326. // heuristic to flush on boundary of restore or endText
  43327. this.flush();
  43328. }
  43329. }
  43330. },
  43331. addDependency: function(dependency) {
  43332. if (dependency in this.dependencies) {
  43333. return;
  43334. }
  43335. this.dependencies[dependency] = true;
  43336. this.addOp(OPS.dependency, [dependency]);
  43337. },
  43338. addDependencies: function(dependencies) {
  43339. for (var key in dependencies) {
  43340. this.addDependency(key);
  43341. }
  43342. },
  43343. addOpList: function(opList) {
  43344. Util.extendObj(this.dependencies, opList.dependencies);
  43345. for (var i = 0, ii = opList.length; i < ii; i++) {
  43346. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  43347. }
  43348. },
  43349. getIR: function() {
  43350. return {
  43351. fnArray: this.fnArray,
  43352. argsArray: this.argsArray,
  43353. length: this.length
  43354. };
  43355. },
  43356. flush: function(lastChunk) {
  43357. if (this.intent !== 'oplist') {
  43358. new QueueOptimizer().optimize(this);
  43359. }
  43360. var transfers = getTransfers(this);
  43361. var length = this.length;
  43362. this._totalLength += length;
  43363. this.messageHandler.send('RenderPageChunk', {
  43364. operatorList: {
  43365. fnArray: this.fnArray,
  43366. argsArray: this.argsArray,
  43367. lastChunk: lastChunk,
  43368. length: length
  43369. },
  43370. pageIndex: this.pageIndex,
  43371. intent: this.intent
  43372. }, transfers);
  43373. this.dependencies = {};
  43374. this.fnArray.length = 0;
  43375. this.argsArray.length = 0;
  43376. }
  43377. };
  43378. return OperatorList;
  43379. })();
  43380. var StateManager = (function StateManagerClosure() {
  43381. function StateManager(initialState) {
  43382. this.state = initialState;
  43383. this.stateStack = [];
  43384. }
  43385. StateManager.prototype = {
  43386. save: function () {
  43387. var old = this.state;
  43388. this.stateStack.push(this.state);
  43389. this.state = old.clone();
  43390. },
  43391. restore: function () {
  43392. var prev = this.stateStack.pop();
  43393. if (prev) {
  43394. this.state = prev;
  43395. }
  43396. },
  43397. transform: function (args) {
  43398. this.state.ctm = Util.transform(this.state.ctm, args);
  43399. }
  43400. };
  43401. return StateManager;
  43402. })();
  43403. var TextState = (function TextStateClosure() {
  43404. function TextState() {
  43405. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43406. this.fontSize = 0;
  43407. this.font = null;
  43408. this.fontMatrix = FONT_IDENTITY_MATRIX;
  43409. this.textMatrix = IDENTITY_MATRIX.slice();
  43410. this.textLineMatrix = IDENTITY_MATRIX.slice();
  43411. this.charSpacing = 0;
  43412. this.wordSpacing = 0;
  43413. this.leading = 0;
  43414. this.textHScale = 1;
  43415. this.textRise = 0;
  43416. }
  43417. TextState.prototype = {
  43418. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43419. var m = this.textMatrix;
  43420. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43421. },
  43422. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43423. var m = this.textLineMatrix;
  43424. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43425. },
  43426. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  43427. var m = this.textMatrix;
  43428. m[4] = m[0] * x + m[2] * y + m[4];
  43429. m[5] = m[1] * x + m[3] * y + m[5];
  43430. },
  43431. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  43432. var m = this.textLineMatrix;
  43433. m[4] = m[0] * x + m[2] * y + m[4];
  43434. m[5] = m[1] * x + m[3] * y + m[5];
  43435. },
  43436. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  43437. // 9.4.4 Text Space Details
  43438. var tsm = [this.fontSize * this.textHScale, 0,
  43439. 0, this.fontSize,
  43440. 0, this.textRise];
  43441. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  43442. },
  43443. carriageReturn: function TextState_carriageReturn() {
  43444. this.translateTextLineMatrix(0, -this.leading);
  43445. this.textMatrix = this.textLineMatrix.slice();
  43446. },
  43447. clone: function TextState_clone() {
  43448. var clone = Object.create(this);
  43449. clone.textMatrix = this.textMatrix.slice();
  43450. clone.textLineMatrix = this.textLineMatrix.slice();
  43451. clone.fontMatrix = this.fontMatrix.slice();
  43452. return clone;
  43453. }
  43454. };
  43455. return TextState;
  43456. })();
  43457. var EvalState = (function EvalStateClosure() {
  43458. function EvalState() {
  43459. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43460. this.font = null;
  43461. this.textRenderingMode = TextRenderingMode.FILL;
  43462. this.fillColorSpace = ColorSpace.singletons.gray;
  43463. this.strokeColorSpace = ColorSpace.singletons.gray;
  43464. }
  43465. EvalState.prototype = {
  43466. clone: function CanvasExtraState_clone() {
  43467. return Object.create(this);
  43468. },
  43469. };
  43470. return EvalState;
  43471. })();
  43472. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  43473. // Specifies properties for each command
  43474. //
  43475. // If variableArgs === true: [0, `numArgs`] expected
  43476. // If variableArgs === false: exactly `numArgs` expected
  43477. var OP_MAP = {
  43478. // Graphic state
  43479. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  43480. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  43481. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  43482. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  43483. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  43484. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  43485. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  43486. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  43487. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  43488. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  43489. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  43490. // Path
  43491. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  43492. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  43493. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  43494. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  43495. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  43496. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  43497. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  43498. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  43499. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  43500. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  43501. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  43502. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  43503. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  43504. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  43505. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  43506. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  43507. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  43508. // Clipping
  43509. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  43510. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  43511. // Text
  43512. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  43513. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  43514. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  43515. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  43516. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  43517. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  43518. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  43519. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  43520. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  43521. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  43522. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  43523. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  43524. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  43525. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  43526. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  43527. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  43528. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  43529. variableArgs: false },
  43530. // Type3 fonts
  43531. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  43532. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  43533. // Color
  43534. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  43535. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  43536. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  43537. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  43538. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  43539. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  43540. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  43541. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  43542. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  43543. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  43544. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  43545. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  43546. // Shading
  43547. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  43548. // Images
  43549. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  43550. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  43551. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  43552. // XObjects
  43553. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  43554. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  43555. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  43556. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  43557. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  43558. variableArgs: false },
  43559. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  43560. // Compatibility
  43561. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  43562. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  43563. // (reserved partial commands for the lexer)
  43564. BM: null,
  43565. BD: null,
  43566. 'true': null,
  43567. fa: null,
  43568. fal: null,
  43569. fals: null,
  43570. 'false': null,
  43571. nu: null,
  43572. nul: null,
  43573. 'null': null
  43574. };
  43575. function EvaluatorPreprocessor(stream, xref, stateManager) {
  43576. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  43577. // dictionary
  43578. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  43579. this.stateManager = stateManager;
  43580. this.nonProcessedArgs = [];
  43581. }
  43582. EvaluatorPreprocessor.prototype = {
  43583. get savedStatesDepth() {
  43584. return this.stateManager.stateStack.length;
  43585. },
  43586. // |operation| is an object with two fields:
  43587. //
  43588. // - |fn| is an out param.
  43589. //
  43590. // - |args| is an inout param. On entry, it should have one of two values.
  43591. //
  43592. // - An empty array. This indicates that the caller is providing the
  43593. // array in which the args will be stored in. The caller should use
  43594. // this value if it can reuse a single array for each call to read().
  43595. //
  43596. // - |null|. This indicates that the caller needs this function to create
  43597. // the array in which any args are stored in. If there are zero args,
  43598. // this function will leave |operation.args| as |null| (thus avoiding
  43599. // allocations that would occur if we used an empty array to represent
  43600. // zero arguments). Otherwise, it will replace |null| with a new array
  43601. // containing the arguments. The caller should use this value if it
  43602. // cannot reuse an array for each call to read().
  43603. //
  43604. // These two modes are present because this function is very hot and so
  43605. // avoiding allocations where possible is worthwhile.
  43606. //
  43607. read: function EvaluatorPreprocessor_read(operation) {
  43608. var args = operation.args;
  43609. while (true) {
  43610. var obj = this.parser.getObj();
  43611. if (isCmd(obj)) {
  43612. var cmd = obj.cmd;
  43613. // Check that the command is valid
  43614. var opSpec = OP_MAP[cmd];
  43615. if (!opSpec) {
  43616. warn('Unknown command "' + cmd + '"');
  43617. continue;
  43618. }
  43619. var fn = opSpec.id;
  43620. var numArgs = opSpec.numArgs;
  43621. var argsLength = args !== null ? args.length : 0;
  43622. if (!opSpec.variableArgs) {
  43623. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  43624. if (argsLength !== numArgs) {
  43625. var nonProcessedArgs = this.nonProcessedArgs;
  43626. while (argsLength > numArgs) {
  43627. nonProcessedArgs.push(args.shift());
  43628. argsLength--;
  43629. }
  43630. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  43631. if (!args) {
  43632. args = [];
  43633. }
  43634. args.unshift(nonProcessedArgs.pop());
  43635. argsLength++;
  43636. }
  43637. }
  43638. if (argsLength < numArgs) {
  43639. // If we receive too few args, it's not possible to possible
  43640. // to execute the command, so skip the command
  43641. info('Command ' + fn + ': because expected ' +
  43642. numArgs + ' args, but received ' + argsLength +
  43643. ' args; skipping');
  43644. args = null;
  43645. continue;
  43646. }
  43647. } else if (argsLength > numArgs) {
  43648. info('Command ' + fn + ': expected [0,' + numArgs +
  43649. '] args, but received ' + argsLength + ' args');
  43650. }
  43651. // TODO figure out how to type-check vararg functions
  43652. this.preprocessCommand(fn, args);
  43653. operation.fn = fn;
  43654. operation.args = args;
  43655. return true;
  43656. } else {
  43657. if (isEOF(obj)) {
  43658. return false; // no more commands
  43659. }
  43660. // argument
  43661. if (obj !== null) {
  43662. if (!args) {
  43663. args = [];
  43664. }
  43665. args.push((obj instanceof Dict ? obj.getAll() : obj));
  43666. assert(args.length <= 33, 'Too many arguments');
  43667. }
  43668. }
  43669. }
  43670. },
  43671. preprocessCommand:
  43672. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  43673. switch (fn | 0) {
  43674. case OPS.save:
  43675. this.stateManager.save();
  43676. break;
  43677. case OPS.restore:
  43678. this.stateManager.restore();
  43679. break;
  43680. case OPS.transform:
  43681. this.stateManager.transform(args);
  43682. break;
  43683. }
  43684. }
  43685. };
  43686. return EvaluatorPreprocessor;
  43687. })();
  43688. var QueueOptimizer = (function QueueOptimizerClosure() {
  43689. function addState(parentState, pattern, fn) {
  43690. var state = parentState;
  43691. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  43692. var item = pattern[i];
  43693. state = (state[item] || (state[item] = []));
  43694. }
  43695. state[pattern[pattern.length - 1]] = fn;
  43696. }
  43697. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  43698. argsArray) {
  43699. // Handles special case of mainly LaTeX documents which use image masks to
  43700. // draw lines with the current fill style.
  43701. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  43702. // have been found at iFirstSave.
  43703. var iFirstPIMXO = iFirstSave + 2;
  43704. for (var i = 0; i < count; i++) {
  43705. var arg = argsArray[iFirstPIMXO + 4 * i];
  43706. var imageMask = arg.length === 1 && arg[0];
  43707. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  43708. (!imageMask.data.length ||
  43709. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  43710. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  43711. continue;
  43712. }
  43713. break;
  43714. }
  43715. return count - i;
  43716. }
  43717. var InitialState = [];
  43718. // This replaces (save, transform, paintInlineImageXObject, restore)+
  43719. // sequences with one |paintInlineImageXObjectGroup| operation.
  43720. addState(InitialState,
  43721. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  43722. function foundInlineImageGroup(context) {
  43723. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  43724. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  43725. var MAX_WIDTH = 1000;
  43726. var IMAGE_PADDING = 1;
  43727. var fnArray = context.fnArray, argsArray = context.argsArray;
  43728. var curr = context.iCurr;
  43729. var iFirstSave = curr - 3;
  43730. var iFirstTransform = curr - 2;
  43731. var iFirstPIIXO = curr - 1;
  43732. // Look for the quartets.
  43733. var i = iFirstSave + 4;
  43734. var ii = fnArray.length;
  43735. while (i + 3 < ii) {
  43736. if (fnArray[i] !== OPS.save ||
  43737. fnArray[i + 1] !== OPS.transform ||
  43738. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  43739. fnArray[i + 3] !== OPS.restore) {
  43740. break; // ops don't match
  43741. }
  43742. i += 4;
  43743. }
  43744. // At this point, i is the index of the first op past the last valid
  43745. // quartet.
  43746. var count = Math.min((i - iFirstSave) / 4,
  43747. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  43748. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  43749. return i;
  43750. }
  43751. // assuming that heights of those image is too small (~1 pixel)
  43752. // packing as much as possible by lines
  43753. var maxX = 0;
  43754. var map = [], maxLineHeight = 0;
  43755. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  43756. var q;
  43757. for (q = 0; q < count; q++) {
  43758. var transform = argsArray[iFirstTransform + (q << 2)];
  43759. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  43760. if (currentX + img.width > MAX_WIDTH) {
  43761. // starting new line
  43762. maxX = Math.max(maxX, currentX);
  43763. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  43764. currentX = 0;
  43765. maxLineHeight = 0;
  43766. }
  43767. map.push({
  43768. transform: transform,
  43769. x: currentX, y: currentY,
  43770. w: img.width, h: img.height
  43771. });
  43772. currentX += img.width + 2 * IMAGE_PADDING;
  43773. maxLineHeight = Math.max(maxLineHeight, img.height);
  43774. }
  43775. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  43776. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  43777. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  43778. var imgRowSize = imgWidth << 2;
  43779. for (q = 0; q < count; q++) {
  43780. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  43781. // Copy image by lines and extends pixels into padding.
  43782. var rowSize = map[q].w << 2;
  43783. var dataOffset = 0;
  43784. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  43785. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  43786. for (var k = 0, kk = map[q].h; k < kk; k++) {
  43787. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  43788. dataOffset += rowSize;
  43789. offset += imgRowSize;
  43790. }
  43791. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  43792. while (offset >= 0) {
  43793. data[offset - 4] = data[offset];
  43794. data[offset - 3] = data[offset + 1];
  43795. data[offset - 2] = data[offset + 2];
  43796. data[offset - 1] = data[offset + 3];
  43797. data[offset + rowSize] = data[offset + rowSize - 4];
  43798. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  43799. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  43800. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  43801. offset -= imgRowSize;
  43802. }
  43803. }
  43804. // Replace queue items.
  43805. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  43806. argsArray.splice(iFirstSave, count * 4,
  43807. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  43808. data: imgData }, map]);
  43809. return iFirstSave + 1;
  43810. });
  43811. // This replaces (save, transform, paintImageMaskXObject, restore)+
  43812. // sequences with one |paintImageMaskXObjectGroup| or one
  43813. // |paintImageMaskXObjectRepeat| operation.
  43814. addState(InitialState,
  43815. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  43816. function foundImageMaskGroup(context) {
  43817. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  43818. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  43819. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  43820. var fnArray = context.fnArray, argsArray = context.argsArray;
  43821. var curr = context.iCurr;
  43822. var iFirstSave = curr - 3;
  43823. var iFirstTransform = curr - 2;
  43824. var iFirstPIMXO = curr - 1;
  43825. // Look for the quartets.
  43826. var i = iFirstSave + 4;
  43827. var ii = fnArray.length;
  43828. while (i + 3 < ii) {
  43829. if (fnArray[i] !== OPS.save ||
  43830. fnArray[i + 1] !== OPS.transform ||
  43831. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  43832. fnArray[i + 3] !== OPS.restore) {
  43833. break; // ops don't match
  43834. }
  43835. i += 4;
  43836. }
  43837. // At this point, i is the index of the first op past the last valid
  43838. // quartet.
  43839. var count = (i - iFirstSave) / 4;
  43840. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  43841. argsArray);
  43842. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  43843. return i;
  43844. }
  43845. var q;
  43846. var isSameImage = false;
  43847. var iTransform, transformArgs;
  43848. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  43849. if (argsArray[iFirstTransform][1] === 0 &&
  43850. argsArray[iFirstTransform][2] === 0) {
  43851. isSameImage = true;
  43852. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43853. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43854. iTransform = iFirstTransform + 4;
  43855. var iPIMXO = iFirstPIMXO + 4;
  43856. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  43857. transformArgs = argsArray[iTransform];
  43858. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  43859. transformArgs[0] !== firstTransformArg0 ||
  43860. transformArgs[1] !== 0 ||
  43861. transformArgs[2] !== 0 ||
  43862. transformArgs[3] !== firstTransformArg3) {
  43863. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  43864. isSameImage = false;
  43865. } else {
  43866. count = q;
  43867. }
  43868. break; // different image or transform
  43869. }
  43870. }
  43871. }
  43872. if (isSameImage) {
  43873. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  43874. var positions = new Float32Array(count * 2);
  43875. iTransform = iFirstTransform;
  43876. for (q = 0; q < count; q++, iTransform += 4) {
  43877. transformArgs = argsArray[iTransform];
  43878. positions[(q << 1)] = transformArgs[4];
  43879. positions[(q << 1) + 1] = transformArgs[5];
  43880. }
  43881. // Replace queue items.
  43882. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  43883. argsArray.splice(iFirstSave, count * 4,
  43884. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  43885. } else {
  43886. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  43887. var images = [];
  43888. for (q = 0; q < count; q++) {
  43889. transformArgs = argsArray[iFirstTransform + (q << 2)];
  43890. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  43891. images.push({ data: maskParams.data, width: maskParams.width,
  43892. height: maskParams.height,
  43893. transform: transformArgs });
  43894. }
  43895. // Replace queue items.
  43896. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  43897. argsArray.splice(iFirstSave, count * 4, [images]);
  43898. }
  43899. return iFirstSave + 1;
  43900. });
  43901. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  43902. // with one paintImageXObjectRepeat operation, if the |transform| and
  43903. // |paintImageXObjectRepeat| ops are appropriate.
  43904. addState(InitialState,
  43905. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  43906. function (context) {
  43907. var MIN_IMAGES_IN_BLOCK = 3;
  43908. var MAX_IMAGES_IN_BLOCK = 1000;
  43909. var fnArray = context.fnArray, argsArray = context.argsArray;
  43910. var curr = context.iCurr;
  43911. var iFirstSave = curr - 3;
  43912. var iFirstTransform = curr - 2;
  43913. var iFirstPIXO = curr - 1;
  43914. var iFirstRestore = curr;
  43915. if (argsArray[iFirstTransform][1] !== 0 ||
  43916. argsArray[iFirstTransform][2] !== 0) {
  43917. return iFirstRestore + 1; // transform has the wrong form
  43918. }
  43919. // Look for the quartets.
  43920. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  43921. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43922. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43923. var i = iFirstSave + 4;
  43924. var ii = fnArray.length;
  43925. while (i + 3 < ii) {
  43926. if (fnArray[i] !== OPS.save ||
  43927. fnArray[i + 1] !== OPS.transform ||
  43928. fnArray[i + 2] !== OPS.paintImageXObject ||
  43929. fnArray[i + 3] !== OPS.restore) {
  43930. break; // ops don't match
  43931. }
  43932. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  43933. argsArray[i + 1][1] !== 0 ||
  43934. argsArray[i + 1][2] !== 0 ||
  43935. argsArray[i + 1][3] !== firstTransformArg3) {
  43936. break; // transforms don't match
  43937. }
  43938. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  43939. break; // images don't match
  43940. }
  43941. i += 4;
  43942. }
  43943. // At this point, i is the index of the first op past the last valid
  43944. // quartet.
  43945. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  43946. if (count < MIN_IMAGES_IN_BLOCK) {
  43947. return i;
  43948. }
  43949. // Extract the (x,y) positions from all of the matching transforms.
  43950. var positions = new Float32Array(count * 2);
  43951. var iTransform = iFirstTransform;
  43952. for (var q = 0; q < count; q++, iTransform += 4) {
  43953. var transformArgs = argsArray[iTransform];
  43954. positions[(q << 1)] = transformArgs[4];
  43955. positions[(q << 1) + 1] = transformArgs[5];
  43956. }
  43957. // Replace queue items.
  43958. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  43959. positions];
  43960. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  43961. argsArray.splice(iFirstSave, count * 4, args);
  43962. return iFirstSave + 1;
  43963. });
  43964. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  43965. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  43966. // sequences, if the font for each one is the same.
  43967. addState(InitialState,
  43968. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  43969. function (context) {
  43970. var MIN_CHARS_IN_BLOCK = 3;
  43971. var MAX_CHARS_IN_BLOCK = 1000;
  43972. var fnArray = context.fnArray, argsArray = context.argsArray;
  43973. var curr = context.iCurr;
  43974. var iFirstBeginText = curr - 4;
  43975. var iFirstSetFont = curr - 3;
  43976. var iFirstSetTextMatrix = curr - 2;
  43977. var iFirstShowText = curr - 1;
  43978. var iFirstEndText = curr;
  43979. // Look for the quintets.
  43980. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  43981. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  43982. var i = iFirstBeginText + 5;
  43983. var ii = fnArray.length;
  43984. while (i + 4 < ii) {
  43985. if (fnArray[i] !== OPS.beginText ||
  43986. fnArray[i + 1] !== OPS.setFont ||
  43987. fnArray[i + 2] !== OPS.setTextMatrix ||
  43988. fnArray[i + 3] !== OPS.showText ||
  43989. fnArray[i + 4] !== OPS.endText) {
  43990. break; // ops don't match
  43991. }
  43992. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  43993. argsArray[i + 1][1] !== firstSetFontArg1) {
  43994. break; // fonts don't match
  43995. }
  43996. i += 5;
  43997. }
  43998. // At this point, i is the index of the first op past the last valid
  43999. // quintet.
  44000. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  44001. if (count < MIN_CHARS_IN_BLOCK) {
  44002. return i;
  44003. }
  44004. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  44005. // showText, endText), include that as well. (E.g. <something> might be
  44006. // |dependency|.)
  44007. var iFirst = iFirstBeginText;
  44008. if (iFirstBeginText >= 4 &&
  44009. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  44010. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  44011. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  44012. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  44013. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  44014. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  44015. count++;
  44016. iFirst -= 5;
  44017. }
  44018. // Remove (endText, beginText, setFont) trios.
  44019. var iEndText = iFirst + 4;
  44020. for (var q = 1; q < count; q++) {
  44021. fnArray.splice(iEndText, 3);
  44022. argsArray.splice(iEndText, 3);
  44023. iEndText += 2;
  44024. }
  44025. return iEndText + 1;
  44026. });
  44027. function QueueOptimizer() {}
  44028. QueueOptimizer.prototype = {
  44029. optimize: function QueueOptimizer_optimize(queue) {
  44030. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44031. var context = {
  44032. iCurr: 0,
  44033. fnArray: fnArray,
  44034. argsArray: argsArray
  44035. };
  44036. var state;
  44037. var i = 0, ii = fnArray.length;
  44038. while (i < ii) {
  44039. state = (state || InitialState)[fnArray[i]];
  44040. if (typeof state === 'function') { // we found some handler
  44041. context.iCurr = i;
  44042. // state() returns the index of the first non-matching op (if we
  44043. // didn't match) or the first op past the modified ops (if we did
  44044. // match and replace).
  44045. i = state(context);
  44046. state = undefined; // reset the state machine
  44047. ii = context.fnArray.length;
  44048. } else {
  44049. i++;
  44050. }
  44051. }
  44052. }
  44053. };
  44054. return QueueOptimizer;
  44055. })();
  44056. exports.OperatorList = OperatorList;
  44057. exports.PartialEvaluator = PartialEvaluator;
  44058. }));
  44059. (function (root, factory) {
  44060. {
  44061. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  44062. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  44063. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  44064. }
  44065. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  44066. coreColorSpace, coreObj, coreEvaluator) {
  44067. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  44068. var AnnotationFlag = sharedUtil.AnnotationFlag;
  44069. var AnnotationType = sharedUtil.AnnotationType;
  44070. var OPS = sharedUtil.OPS;
  44071. var Util = sharedUtil.Util;
  44072. var isArray = sharedUtil.isArray;
  44073. var isInt = sharedUtil.isInt;
  44074. var isValidUrl = sharedUtil.isValidUrl;
  44075. var stringToBytes = sharedUtil.stringToBytes;
  44076. var stringToPDFString = sharedUtil.stringToPDFString;
  44077. var stringToUTF8String = sharedUtil.stringToUTF8String;
  44078. var warn = sharedUtil.warn;
  44079. var Dict = corePrimitives.Dict;
  44080. var isDict = corePrimitives.isDict;
  44081. var isName = corePrimitives.isName;
  44082. var Stream = coreStream.Stream;
  44083. var ColorSpace = coreColorSpace.ColorSpace;
  44084. var ObjectLoader = coreObj.ObjectLoader;
  44085. var OperatorList = coreEvaluator.OperatorList;
  44086. /**
  44087. * @class
  44088. * @alias AnnotationFactory
  44089. */
  44090. function AnnotationFactory() {}
  44091. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  44092. /**
  44093. * @param {XRef} xref
  44094. * @param {Object} ref
  44095. * @returns {Annotation}
  44096. */
  44097. create: function AnnotationFactory_create(xref, ref) {
  44098. var dict = xref.fetchIfRef(ref);
  44099. if (!isDict(dict)) {
  44100. return;
  44101. }
  44102. // Determine the annotation's subtype.
  44103. var subtype = dict.get('Subtype');
  44104. subtype = isName(subtype) ? subtype.name : '';
  44105. // Return the right annotation object based on the subtype and field type.
  44106. var parameters = {
  44107. dict: dict,
  44108. ref: ref
  44109. };
  44110. switch (subtype) {
  44111. case 'Link':
  44112. return new LinkAnnotation(parameters);
  44113. case 'Text':
  44114. return new TextAnnotation(parameters);
  44115. case 'Widget':
  44116. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44117. if (isName(fieldType) && fieldType.name === 'Tx') {
  44118. return new TextWidgetAnnotation(parameters);
  44119. }
  44120. return new WidgetAnnotation(parameters);
  44121. case 'Popup':
  44122. return new PopupAnnotation(parameters);
  44123. case 'Highlight':
  44124. return new HighlightAnnotation(parameters);
  44125. case 'Underline':
  44126. return new UnderlineAnnotation(parameters);
  44127. case 'Squiggly':
  44128. return new SquigglyAnnotation(parameters);
  44129. case 'StrikeOut':
  44130. return new StrikeOutAnnotation(parameters);
  44131. default:
  44132. warn('Unimplemented annotation type "' + subtype + '", ' +
  44133. 'falling back to base annotation');
  44134. return new Annotation(parameters);
  44135. }
  44136. }
  44137. };
  44138. var Annotation = (function AnnotationClosure() {
  44139. // 12.5.5: Algorithm: Appearance streams
  44140. function getTransformMatrix(rect, bbox, matrix) {
  44141. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  44142. var minX = bounds[0];
  44143. var minY = bounds[1];
  44144. var maxX = bounds[2];
  44145. var maxY = bounds[3];
  44146. if (minX === maxX || minY === maxY) {
  44147. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  44148. // just apply the transform for rect
  44149. return [1, 0, 0, 1, rect[0], rect[1]];
  44150. }
  44151. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  44152. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  44153. return [
  44154. xRatio,
  44155. 0,
  44156. 0,
  44157. yRatio,
  44158. rect[0] - minX * xRatio,
  44159. rect[1] - minY * yRatio
  44160. ];
  44161. }
  44162. function getDefaultAppearance(dict) {
  44163. var appearanceState = dict.get('AP');
  44164. if (!isDict(appearanceState)) {
  44165. return;
  44166. }
  44167. var appearance;
  44168. var appearances = appearanceState.get('N');
  44169. if (isDict(appearances)) {
  44170. var as = dict.get('AS');
  44171. if (as && appearances.has(as.name)) {
  44172. appearance = appearances.get(as.name);
  44173. }
  44174. } else {
  44175. appearance = appearances;
  44176. }
  44177. return appearance;
  44178. }
  44179. function Annotation(params) {
  44180. var dict = params.dict;
  44181. this.setFlags(dict.get('F'));
  44182. this.setRectangle(dict.get('Rect'));
  44183. this.setColor(dict.get('C'));
  44184. this.setBorderStyle(dict);
  44185. this.appearance = getDefaultAppearance(dict);
  44186. // Expose public properties using a data object.
  44187. this.data = {};
  44188. this.data.id = params.ref.toString();
  44189. this.data.subtype = dict.get('Subtype').name;
  44190. this.data.annotationFlags = this.flags;
  44191. this.data.rect = this.rectangle;
  44192. this.data.color = this.color;
  44193. this.data.borderStyle = this.borderStyle;
  44194. this.data.hasAppearance = !!this.appearance;
  44195. }
  44196. Annotation.prototype = {
  44197. /**
  44198. * @return {boolean}
  44199. */
  44200. get viewable() {
  44201. if (this.flags) {
  44202. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44203. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  44204. !this.hasFlag(AnnotationFlag.NOVIEW);
  44205. }
  44206. return true;
  44207. },
  44208. /**
  44209. * @return {boolean}
  44210. */
  44211. get printable() {
  44212. if (this.flags) {
  44213. return this.hasFlag(AnnotationFlag.PRINT) &&
  44214. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44215. !this.hasFlag(AnnotationFlag.HIDDEN);
  44216. }
  44217. return false;
  44218. },
  44219. /**
  44220. * Set the flags.
  44221. *
  44222. * @public
  44223. * @memberof Annotation
  44224. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  44225. * characteristics
  44226. * @see {@link shared/util.js}
  44227. */
  44228. setFlags: function Annotation_setFlags(flags) {
  44229. if (isInt(flags)) {
  44230. this.flags = flags;
  44231. } else {
  44232. this.flags = 0;
  44233. }
  44234. },
  44235. /**
  44236. * Check if a provided flag is set.
  44237. *
  44238. * @public
  44239. * @memberof Annotation
  44240. * @param {number} flag - Hexadecimal representation for an annotation
  44241. * characteristic
  44242. * @return {boolean}
  44243. * @see {@link shared/util.js}
  44244. */
  44245. hasFlag: function Annotation_hasFlag(flag) {
  44246. if (this.flags) {
  44247. return (this.flags & flag) > 0;
  44248. }
  44249. return false;
  44250. },
  44251. /**
  44252. * Set the rectangle.
  44253. *
  44254. * @public
  44255. * @memberof Annotation
  44256. * @param {Array} rectangle - The rectangle array with exactly four entries
  44257. */
  44258. setRectangle: function Annotation_setRectangle(rectangle) {
  44259. if (isArray(rectangle) && rectangle.length === 4) {
  44260. this.rectangle = Util.normalizeRect(rectangle);
  44261. } else {
  44262. this.rectangle = [0, 0, 0, 0];
  44263. }
  44264. },
  44265. /**
  44266. * Set the color and take care of color space conversion.
  44267. *
  44268. * @public
  44269. * @memberof Annotation
  44270. * @param {Array} color - The color array containing either 0
  44271. * (transparent), 1 (grayscale), 3 (RGB) or
  44272. * 4 (CMYK) elements
  44273. */
  44274. setColor: function Annotation_setColor(color) {
  44275. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  44276. if (!isArray(color)) {
  44277. this.color = rgbColor;
  44278. return;
  44279. }
  44280. switch (color.length) {
  44281. case 0: // Transparent, which we indicate with a null value
  44282. this.color = null;
  44283. break;
  44284. case 1: // Convert grayscale to RGB
  44285. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  44286. this.color = rgbColor;
  44287. break;
  44288. case 3: // Convert RGB percentages to RGB
  44289. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  44290. this.color = rgbColor;
  44291. break;
  44292. case 4: // Convert CMYK to RGB
  44293. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  44294. this.color = rgbColor;
  44295. break;
  44296. default:
  44297. this.color = rgbColor;
  44298. break;
  44299. }
  44300. },
  44301. /**
  44302. * Set the border style (as AnnotationBorderStyle object).
  44303. *
  44304. * @public
  44305. * @memberof Annotation
  44306. * @param {Dict} borderStyle - The border style dictionary
  44307. */
  44308. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  44309. this.borderStyle = new AnnotationBorderStyle();
  44310. if (!isDict(borderStyle)) {
  44311. return;
  44312. }
  44313. if (borderStyle.has('BS')) {
  44314. var dict = borderStyle.get('BS');
  44315. var dictType;
  44316. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  44317. dictType.name === 'Border')) {
  44318. this.borderStyle.setWidth(dict.get('W'));
  44319. this.borderStyle.setStyle(dict.get('S'));
  44320. this.borderStyle.setDashArray(dict.get('D'));
  44321. }
  44322. } else if (borderStyle.has('Border')) {
  44323. var array = borderStyle.get('Border');
  44324. if (isArray(array) && array.length >= 3) {
  44325. this.borderStyle.setHorizontalCornerRadius(array[0]);
  44326. this.borderStyle.setVerticalCornerRadius(array[1]);
  44327. this.borderStyle.setWidth(array[2]);
  44328. if (array.length === 4) { // Dash array available
  44329. this.borderStyle.setDashArray(array[3]);
  44330. }
  44331. }
  44332. } else {
  44333. // There are no border entries in the dictionary. According to the
  44334. // specification, we should draw a solid border of width 1 in that
  44335. // case, but Adobe Reader did not implement that part of the
  44336. // specification and instead draws no border at all, so we do the same.
  44337. // See also https://github.com/mozilla/pdf.js/issues/6179.
  44338. this.borderStyle.setWidth(0);
  44339. }
  44340. },
  44341. loadResources: function Annotation_loadResources(keys) {
  44342. return new Promise(function (resolve, reject) {
  44343. this.appearance.dict.getAsync('Resources').then(function (resources) {
  44344. if (!resources) {
  44345. resolve();
  44346. return;
  44347. }
  44348. var objectLoader = new ObjectLoader(resources.map,
  44349. keys,
  44350. resources.xref);
  44351. objectLoader.load().then(function() {
  44352. resolve(resources);
  44353. }, reject);
  44354. }, reject);
  44355. }.bind(this));
  44356. },
  44357. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  44358. if (!this.appearance) {
  44359. return Promise.resolve(new OperatorList());
  44360. }
  44361. var data = this.data;
  44362. var appearanceDict = this.appearance.dict;
  44363. var resourcesPromise = this.loadResources([
  44364. 'ExtGState',
  44365. 'ColorSpace',
  44366. 'Pattern',
  44367. 'Shading',
  44368. 'XObject',
  44369. 'Font'
  44370. // ProcSet
  44371. // Properties
  44372. ]);
  44373. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  44374. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  44375. var transform = getTransformMatrix(data.rect, bbox, matrix);
  44376. var self = this;
  44377. return resourcesPromise.then(function(resources) {
  44378. var opList = new OperatorList();
  44379. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  44380. return evaluator.getOperatorList(self.appearance, task,
  44381. resources, opList).
  44382. then(function () {
  44383. opList.addOp(OPS.endAnnotation, []);
  44384. self.appearance.reset();
  44385. return opList;
  44386. });
  44387. });
  44388. }
  44389. };
  44390. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  44391. annotations, opList, partialEvaluator, task, intent) {
  44392. var annotationPromises = [];
  44393. for (var i = 0, n = annotations.length; i < n; ++i) {
  44394. if ((intent === 'display' && annotations[i].viewable) ||
  44395. (intent === 'print' && annotations[i].printable)) {
  44396. annotationPromises.push(
  44397. annotations[i].getOperatorList(partialEvaluator, task));
  44398. }
  44399. }
  44400. return Promise.all(annotationPromises).then(function(operatorLists) {
  44401. opList.addOp(OPS.beginAnnotations, []);
  44402. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  44403. opList.addOpList(operatorLists[i]);
  44404. }
  44405. opList.addOp(OPS.endAnnotations, []);
  44406. });
  44407. };
  44408. return Annotation;
  44409. })();
  44410. /**
  44411. * Contains all data regarding an annotation's border style.
  44412. *
  44413. * @class
  44414. */
  44415. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  44416. /**
  44417. * @constructor
  44418. * @private
  44419. */
  44420. function AnnotationBorderStyle() {
  44421. this.width = 1;
  44422. this.style = AnnotationBorderStyleType.SOLID;
  44423. this.dashArray = [3];
  44424. this.horizontalCornerRadius = 0;
  44425. this.verticalCornerRadius = 0;
  44426. }
  44427. AnnotationBorderStyle.prototype = {
  44428. /**
  44429. * Set the width.
  44430. *
  44431. * @public
  44432. * @memberof AnnotationBorderStyle
  44433. * @param {integer} width - The width
  44434. */
  44435. setWidth: function AnnotationBorderStyle_setWidth(width) {
  44436. if (width === (width | 0)) {
  44437. this.width = width;
  44438. }
  44439. },
  44440. /**
  44441. * Set the style.
  44442. *
  44443. * @public
  44444. * @memberof AnnotationBorderStyle
  44445. * @param {Object} style - The style object
  44446. * @see {@link shared/util.js}
  44447. */
  44448. setStyle: function AnnotationBorderStyle_setStyle(style) {
  44449. if (!style) {
  44450. return;
  44451. }
  44452. switch (style.name) {
  44453. case 'S':
  44454. this.style = AnnotationBorderStyleType.SOLID;
  44455. break;
  44456. case 'D':
  44457. this.style = AnnotationBorderStyleType.DASHED;
  44458. break;
  44459. case 'B':
  44460. this.style = AnnotationBorderStyleType.BEVELED;
  44461. break;
  44462. case 'I':
  44463. this.style = AnnotationBorderStyleType.INSET;
  44464. break;
  44465. case 'U':
  44466. this.style = AnnotationBorderStyleType.UNDERLINE;
  44467. break;
  44468. default:
  44469. break;
  44470. }
  44471. },
  44472. /**
  44473. * Set the dash array.
  44474. *
  44475. * @public
  44476. * @memberof AnnotationBorderStyle
  44477. * @param {Array} dashArray - The dash array with at least one element
  44478. */
  44479. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  44480. // We validate the dash array, but we do not use it because CSS does not
  44481. // allow us to change spacing of dashes. For more information, visit
  44482. // http://www.w3.org/TR/css3-background/#the-border-style.
  44483. if (isArray(dashArray) && dashArray.length > 0) {
  44484. // According to the PDF specification: the elements in a dashArray
  44485. // shall be numbers that are nonnegative and not all equal to zero.
  44486. var isValid = true;
  44487. var allZeros = true;
  44488. for (var i = 0, len = dashArray.length; i < len; i++) {
  44489. var element = dashArray[i];
  44490. var validNumber = (+element >= 0);
  44491. if (!validNumber) {
  44492. isValid = false;
  44493. break;
  44494. } else if (element > 0) {
  44495. allZeros = false;
  44496. }
  44497. }
  44498. if (isValid && !allZeros) {
  44499. this.dashArray = dashArray;
  44500. } else {
  44501. this.width = 0; // Adobe behavior when the array is invalid.
  44502. }
  44503. } else if (dashArray) {
  44504. this.width = 0; // Adobe behavior when the array is invalid.
  44505. }
  44506. },
  44507. /**
  44508. * Set the horizontal corner radius (from a Border dictionary).
  44509. *
  44510. * @public
  44511. * @memberof AnnotationBorderStyle
  44512. * @param {integer} radius - The horizontal corner radius
  44513. */
  44514. setHorizontalCornerRadius:
  44515. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  44516. if (radius === (radius | 0)) {
  44517. this.horizontalCornerRadius = radius;
  44518. }
  44519. },
  44520. /**
  44521. * Set the vertical corner radius (from a Border dictionary).
  44522. *
  44523. * @public
  44524. * @memberof AnnotationBorderStyle
  44525. * @param {integer} radius - The vertical corner radius
  44526. */
  44527. setVerticalCornerRadius:
  44528. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  44529. if (radius === (radius | 0)) {
  44530. this.verticalCornerRadius = radius;
  44531. }
  44532. }
  44533. };
  44534. return AnnotationBorderStyle;
  44535. })();
  44536. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  44537. function WidgetAnnotation(params) {
  44538. Annotation.call(this, params);
  44539. var dict = params.dict;
  44540. var data = this.data;
  44541. data.annotationType = AnnotationType.WIDGET;
  44542. data.fieldValue = stringToPDFString(
  44543. Util.getInheritableProperty(dict, 'V') || '');
  44544. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  44545. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  44546. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44547. data.fieldType = isName(fieldType) ? fieldType.name : '';
  44548. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  44549. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  44550. // Hide unsupported Widget signatures.
  44551. if (data.fieldType === 'Sig') {
  44552. warn('unimplemented annotation type: Widget signature');
  44553. this.setFlags(AnnotationFlag.HIDDEN);
  44554. }
  44555. // Building the full field name by collecting the field and
  44556. // its ancestors 'T' data and joining them using '.'.
  44557. var fieldName = [];
  44558. var namedItem = dict;
  44559. var ref = params.ref;
  44560. while (namedItem) {
  44561. var parent = namedItem.get('Parent');
  44562. var parentRef = namedItem.getRaw('Parent');
  44563. var name = namedItem.get('T');
  44564. if (name) {
  44565. fieldName.unshift(stringToPDFString(name));
  44566. } else if (parent && ref) {
  44567. // The field name is absent, that means more than one field
  44568. // with the same name may exist. Replacing the empty name
  44569. // with the '`' plus index in the parent's 'Kids' array.
  44570. // This is not in the PDF spec but necessary to id the
  44571. // the input controls.
  44572. var kids = parent.get('Kids');
  44573. var j, jj;
  44574. for (j = 0, jj = kids.length; j < jj; j++) {
  44575. var kidRef = kids[j];
  44576. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  44577. break;
  44578. }
  44579. }
  44580. fieldName.unshift('`' + j);
  44581. }
  44582. namedItem = parent;
  44583. ref = parentRef;
  44584. }
  44585. data.fullName = fieldName.join('.');
  44586. }
  44587. Util.inherit(WidgetAnnotation, Annotation, {});
  44588. return WidgetAnnotation;
  44589. })();
  44590. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  44591. function TextWidgetAnnotation(params) {
  44592. WidgetAnnotation.call(this, params);
  44593. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  44594. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  44595. }
  44596. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  44597. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  44598. task) {
  44599. if (this.appearance) {
  44600. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  44601. }
  44602. var opList = new OperatorList();
  44603. var data = this.data;
  44604. // Even if there is an appearance stream, ignore it. This is the
  44605. // behaviour used by Adobe Reader.
  44606. if (!data.defaultAppearance) {
  44607. return Promise.resolve(opList);
  44608. }
  44609. var stream = new Stream(stringToBytes(data.defaultAppearance));
  44610. return evaluator.getOperatorList(stream, task,
  44611. this.fieldResources, opList).
  44612. then(function () {
  44613. return opList;
  44614. });
  44615. }
  44616. });
  44617. return TextWidgetAnnotation;
  44618. })();
  44619. var TextAnnotation = (function TextAnnotationClosure() {
  44620. var DEFAULT_ICON_SIZE = 22; // px
  44621. function TextAnnotation(parameters) {
  44622. Annotation.call(this, parameters);
  44623. this.data.annotationType = AnnotationType.TEXT;
  44624. this.data.hasHtml = true;
  44625. var dict = parameters.dict;
  44626. if (this.data.hasAppearance) {
  44627. this.data.name = 'NoIcon';
  44628. } else {
  44629. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  44630. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  44631. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  44632. }
  44633. if (!dict.has('C')) {
  44634. // Fall back to the default background color.
  44635. this.data.color = null;
  44636. }
  44637. this.data.hasPopup = dict.has('Popup');
  44638. if (!this.data.hasPopup) {
  44639. // There is no associated Popup annotation, so the Text annotation
  44640. // must create its own popup.
  44641. this.data.title = stringToPDFString(dict.get('T') || '');
  44642. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  44643. this.data.hasHtml = (this.data.title || this.data.contents);
  44644. }
  44645. }
  44646. Util.inherit(TextAnnotation, Annotation, {});
  44647. return TextAnnotation;
  44648. })();
  44649. var LinkAnnotation = (function LinkAnnotationClosure() {
  44650. function LinkAnnotation(params) {
  44651. Annotation.call(this, params);
  44652. var dict = params.dict;
  44653. var data = this.data;
  44654. data.annotationType = AnnotationType.LINK;
  44655. data.hasHtml = true;
  44656. var action = dict.get('A');
  44657. if (action && isDict(action)) {
  44658. var linkType = action.get('S').name;
  44659. if (linkType === 'URI') {
  44660. var url = action.get('URI');
  44661. if (isName(url)) {
  44662. // Some bad PDFs do not put parentheses around relative URLs.
  44663. url = '/' + url.name;
  44664. } else if (url) {
  44665. url = addDefaultProtocolToUrl(url);
  44666. }
  44667. // TODO: pdf spec mentions urls can be relative to a Base
  44668. // entry in the dictionary.
  44669. if (!isValidUrl(url, false)) {
  44670. url = '';
  44671. }
  44672. // According to ISO 32000-1:2008, section 12.6.4.7,
  44673. // URI should to be encoded in 7-bit ASCII.
  44674. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  44675. try {
  44676. data.url = stringToUTF8String(url);
  44677. } catch (e) {
  44678. // Fall back to a simple copy.
  44679. data.url = url;
  44680. }
  44681. } else if (linkType === 'GoTo') {
  44682. data.dest = action.get('D');
  44683. } else if (linkType === 'GoToR') {
  44684. var urlDict = action.get('F');
  44685. if (isDict(urlDict)) {
  44686. // We assume that the 'url' is a Filspec dictionary
  44687. // and fetch the url without checking any further
  44688. url = urlDict.get('F') || '';
  44689. }
  44690. // TODO: pdf reference says that GoToR
  44691. // can also have 'NewWindow' attribute
  44692. if (!isValidUrl(url, false)) {
  44693. url = '';
  44694. }
  44695. data.url = url;
  44696. data.dest = action.get('D');
  44697. } else if (linkType === 'Named') {
  44698. data.action = action.get('N').name;
  44699. } else {
  44700. warn('unrecognized link type: ' + linkType);
  44701. }
  44702. } else if (dict.has('Dest')) {
  44703. // simple destination link
  44704. var dest = dict.get('Dest');
  44705. data.dest = isName(dest) ? dest.name : dest;
  44706. }
  44707. }
  44708. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  44709. function addDefaultProtocolToUrl(url) {
  44710. if (url && url.indexOf('www.') === 0) {
  44711. return ('http://' + url);
  44712. }
  44713. return url;
  44714. }
  44715. Util.inherit(LinkAnnotation, Annotation, {});
  44716. return LinkAnnotation;
  44717. })();
  44718. var PopupAnnotation = (function PopupAnnotationClosure() {
  44719. function PopupAnnotation(parameters) {
  44720. Annotation.call(this, parameters);
  44721. this.data.annotationType = AnnotationType.POPUP;
  44722. var dict = parameters.dict;
  44723. var parentItem = dict.get('Parent');
  44724. if (!parentItem) {
  44725. warn('Popup annotation has a missing or invalid parent annotation.');
  44726. return;
  44727. }
  44728. this.data.parentId = dict.getRaw('Parent').toString();
  44729. this.data.title = stringToPDFString(parentItem.get('T') || '');
  44730. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  44731. if (!parentItem.has('C')) {
  44732. // Fall back to the default background color.
  44733. this.data.color = null;
  44734. } else {
  44735. this.setColor(parentItem.get('C'));
  44736. this.data.color = this.color;
  44737. }
  44738. this.data.hasHtml = (this.data.title || this.data.contents);
  44739. }
  44740. Util.inherit(PopupAnnotation, Annotation, {});
  44741. return PopupAnnotation;
  44742. })();
  44743. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  44744. function HighlightAnnotation(parameters) {
  44745. Annotation.call(this, parameters);
  44746. this.data.annotationType = AnnotationType.HIGHLIGHT;
  44747. this.data.hasHtml = true;
  44748. // PDF viewers completely ignore any border styles.
  44749. this.data.borderStyle.setWidth(0);
  44750. }
  44751. Util.inherit(HighlightAnnotation, Annotation, {});
  44752. return HighlightAnnotation;
  44753. })();
  44754. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  44755. function UnderlineAnnotation(parameters) {
  44756. Annotation.call(this, parameters);
  44757. this.data.annotationType = AnnotationType.UNDERLINE;
  44758. this.data.hasHtml = true;
  44759. // PDF viewers completely ignore any border styles.
  44760. this.data.borderStyle.setWidth(0);
  44761. }
  44762. Util.inherit(UnderlineAnnotation, Annotation, {});
  44763. return UnderlineAnnotation;
  44764. })();
  44765. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  44766. function SquigglyAnnotation(parameters) {
  44767. Annotation.call(this, parameters);
  44768. this.data.annotationType = AnnotationType.SQUIGGLY;
  44769. this.data.hasHtml = true;
  44770. // PDF viewers completely ignore any border styles.
  44771. this.data.borderStyle.setWidth(0);
  44772. }
  44773. Util.inherit(SquigglyAnnotation, Annotation, {});
  44774. return SquigglyAnnotation;
  44775. })();
  44776. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  44777. function StrikeOutAnnotation(parameters) {
  44778. Annotation.call(this, parameters);
  44779. this.data.annotationType = AnnotationType.STRIKEOUT;
  44780. this.data.hasHtml = true;
  44781. // PDF viewers completely ignore any border styles.
  44782. this.data.borderStyle.setWidth(0);
  44783. }
  44784. Util.inherit(StrikeOutAnnotation, Annotation, {});
  44785. return StrikeOutAnnotation;
  44786. })();
  44787. exports.Annotation = Annotation;
  44788. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  44789. exports.AnnotationFactory = AnnotationFactory;
  44790. }));
  44791. (function (root, factory) {
  44792. {
  44793. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  44794. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  44795. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  44796. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  44797. }
  44798. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  44799. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  44800. var MissingDataException = sharedUtil.MissingDataException;
  44801. var Util = sharedUtil.Util;
  44802. var assert = sharedUtil.assert;
  44803. var error = sharedUtil.error;
  44804. var info = sharedUtil.info;
  44805. var isArray = sharedUtil.isArray;
  44806. var isArrayBuffer = sharedUtil.isArrayBuffer;
  44807. var isString = sharedUtil.isString;
  44808. var shadow = sharedUtil.shadow;
  44809. var stringToBytes = sharedUtil.stringToBytes;
  44810. var stringToPDFString = sharedUtil.stringToPDFString;
  44811. var warn = sharedUtil.warn;
  44812. var Dict = corePrimitives.Dict;
  44813. var isDict = corePrimitives.isDict;
  44814. var isName = corePrimitives.isName;
  44815. var isStream = corePrimitives.isStream;
  44816. var NullStream = coreStream.NullStream;
  44817. var Stream = coreStream.Stream;
  44818. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  44819. var Catalog = coreObj.Catalog;
  44820. var ObjectLoader = coreObj.ObjectLoader;
  44821. var XRef = coreObj.XRef;
  44822. var Lexer = coreParser.Lexer;
  44823. var Linearization = coreParser.Linearization;
  44824. var calculateMD5 = coreCrypto.calculateMD5;
  44825. var OperatorList = coreEvaluator.OperatorList;
  44826. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  44827. var Annotation = coreAnnotation.Annotation;
  44828. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  44829. var Page = (function PageClosure() {
  44830. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  44831. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  44832. this.pdfManager = pdfManager;
  44833. this.pageIndex = pageIndex;
  44834. this.pageDict = pageDict;
  44835. this.xref = xref;
  44836. this.ref = ref;
  44837. this.fontCache = fontCache;
  44838. this.idCounters = {
  44839. obj: 0
  44840. };
  44841. this.resourcesPromise = null;
  44842. }
  44843. Page.prototype = {
  44844. getPageProp: function Page_getPageProp(key) {
  44845. return this.pageDict.get(key);
  44846. },
  44847. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  44848. var dict = this.pageDict, valueArray = null, loopCount = 0;
  44849. var MAX_LOOP_COUNT = 100;
  44850. // Always walk up the entire parent chain, to be able to find
  44851. // e.g. \Resources placed on multiple levels of the tree.
  44852. while (dict) {
  44853. var value = dict.get(key);
  44854. if (value) {
  44855. if (!valueArray) {
  44856. valueArray = [];
  44857. }
  44858. valueArray.push(value);
  44859. }
  44860. if (++loopCount > MAX_LOOP_COUNT) {
  44861. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  44862. break;
  44863. }
  44864. dict = dict.get('Parent');
  44865. }
  44866. if (!valueArray) {
  44867. return Dict.empty;
  44868. }
  44869. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  44870. loopCount > MAX_LOOP_COUNT) {
  44871. return valueArray[0];
  44872. }
  44873. return Dict.merge(this.xref, valueArray);
  44874. },
  44875. get content() {
  44876. return this.getPageProp('Contents');
  44877. },
  44878. get resources() {
  44879. // For robustness: The spec states that a \Resources entry has to be
  44880. // present, but can be empty. Some document omit it still, in this case
  44881. // we return an empty dictionary.
  44882. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  44883. },
  44884. get mediaBox() {
  44885. var obj = this.getInheritedPageProp('MediaBox');
  44886. // Reset invalid media box to letter size.
  44887. if (!isArray(obj) || obj.length !== 4) {
  44888. obj = LETTER_SIZE_MEDIABOX;
  44889. }
  44890. return shadow(this, 'mediaBox', obj);
  44891. },
  44892. get view() {
  44893. var mediaBox = this.mediaBox;
  44894. var cropBox = this.getInheritedPageProp('CropBox');
  44895. if (!isArray(cropBox) || cropBox.length !== 4) {
  44896. return shadow(this, 'view', mediaBox);
  44897. }
  44898. // From the spec, 6th ed., p.963:
  44899. // "The crop, bleed, trim, and art boxes should not ordinarily
  44900. // extend beyond the boundaries of the media box. If they do, they are
  44901. // effectively reduced to their intersection with the media box."
  44902. cropBox = Util.intersect(cropBox, mediaBox);
  44903. if (!cropBox) {
  44904. return shadow(this, 'view', mediaBox);
  44905. }
  44906. return shadow(this, 'view', cropBox);
  44907. },
  44908. get rotate() {
  44909. var rotate = this.getInheritedPageProp('Rotate') || 0;
  44910. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  44911. if (rotate % 90 !== 0) {
  44912. rotate = 0;
  44913. } else if (rotate >= 360) {
  44914. rotate = rotate % 360;
  44915. } else if (rotate < 0) {
  44916. // The spec doesn't cover negatives, assume its counterclockwise
  44917. // rotation. The following is the other implementation of modulo.
  44918. rotate = ((rotate % 360) + 360) % 360;
  44919. }
  44920. return shadow(this, 'rotate', rotate);
  44921. },
  44922. getContentStream: function Page_getContentStream() {
  44923. var content = this.content;
  44924. var stream;
  44925. if (isArray(content)) {
  44926. // fetching items
  44927. var xref = this.xref;
  44928. var i, n = content.length;
  44929. var streams = [];
  44930. for (i = 0; i < n; ++i) {
  44931. streams.push(xref.fetchIfRef(content[i]));
  44932. }
  44933. stream = new StreamsSequenceStream(streams);
  44934. } else if (isStream(content)) {
  44935. stream = content;
  44936. } else {
  44937. // replacing non-existent page content with empty one
  44938. stream = new NullStream();
  44939. }
  44940. return stream;
  44941. },
  44942. loadResources: function Page_loadResources(keys) {
  44943. if (!this.resourcesPromise) {
  44944. // TODO: add async getInheritedPageProp and remove this.
  44945. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  44946. }
  44947. return this.resourcesPromise.then(function resourceSuccess() {
  44948. var objectLoader = new ObjectLoader(this.resources.map,
  44949. keys,
  44950. this.xref);
  44951. return objectLoader.load();
  44952. }.bind(this));
  44953. },
  44954. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  44955. var self = this;
  44956. var pdfManager = this.pdfManager;
  44957. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44958. []);
  44959. var resourcesPromise = this.loadResources([
  44960. 'ExtGState',
  44961. 'ColorSpace',
  44962. 'Pattern',
  44963. 'Shading',
  44964. 'XObject',
  44965. 'Font'
  44966. // ProcSet
  44967. // Properties
  44968. ]);
  44969. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  44970. handler, this.pageIndex,
  44971. 'p' + this.pageIndex + '_',
  44972. this.idCounters,
  44973. this.fontCache);
  44974. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  44975. var pageListPromise = dataPromises.then(function(data) {
  44976. var contentStream = data[0];
  44977. var opList = new OperatorList(intent, handler, self.pageIndex);
  44978. handler.send('StartRenderPage', {
  44979. transparency: partialEvaluator.hasBlendModes(self.resources),
  44980. pageIndex: self.pageIndex,
  44981. intent: intent
  44982. });
  44983. return partialEvaluator.getOperatorList(contentStream, task,
  44984. self.resources, opList).then(function () {
  44985. return opList;
  44986. });
  44987. });
  44988. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  44989. return Promise.all([pageListPromise, annotationsPromise]).then(
  44990. function(datas) {
  44991. var pageOpList = datas[0];
  44992. var annotations = datas[1];
  44993. if (annotations.length === 0) {
  44994. pageOpList.flush(true);
  44995. return pageOpList;
  44996. }
  44997. var annotationsReadyPromise = Annotation.appendToOperatorList(
  44998. annotations, pageOpList, partialEvaluator, task, intent);
  44999. return annotationsReadyPromise.then(function () {
  45000. pageOpList.flush(true);
  45001. return pageOpList;
  45002. });
  45003. });
  45004. },
  45005. extractTextContent: function Page_extractTextContent(task,
  45006. normalizeWhitespace) {
  45007. var handler = {
  45008. on: function nullHandlerOn() {},
  45009. send: function nullHandlerSend() {}
  45010. };
  45011. var self = this;
  45012. var pdfManager = this.pdfManager;
  45013. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45014. []);
  45015. var resourcesPromise = this.loadResources([
  45016. 'ExtGState',
  45017. 'XObject',
  45018. 'Font'
  45019. ]);
  45020. var dataPromises = Promise.all([contentStreamPromise,
  45021. resourcesPromise]);
  45022. return dataPromises.then(function(data) {
  45023. var contentStream = data[0];
  45024. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  45025. handler, self.pageIndex,
  45026. 'p' + self.pageIndex + '_',
  45027. self.idCounters,
  45028. self.fontCache);
  45029. return partialEvaluator.getTextContent(contentStream,
  45030. task,
  45031. self.resources,
  45032. /* stateManager = */ null,
  45033. normalizeWhitespace);
  45034. });
  45035. },
  45036. getAnnotationsData: function Page_getAnnotationsData(intent) {
  45037. var annotations = this.annotations;
  45038. var annotationsData = [];
  45039. for (var i = 0, n = annotations.length; i < n; ++i) {
  45040. if (intent) {
  45041. if (!(intent === 'display' && annotations[i].viewable) &&
  45042. !(intent === 'print' && annotations[i].printable)) {
  45043. continue;
  45044. }
  45045. }
  45046. annotationsData.push(annotations[i].data);
  45047. }
  45048. return annotationsData;
  45049. },
  45050. get annotations() {
  45051. var annotations = [];
  45052. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  45053. var annotationFactory = new AnnotationFactory();
  45054. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  45055. var annotationRef = annotationRefs[i];
  45056. var annotation = annotationFactory.create(this.xref, annotationRef);
  45057. if (annotation) {
  45058. annotations.push(annotation);
  45059. }
  45060. }
  45061. return shadow(this, 'annotations', annotations);
  45062. }
  45063. };
  45064. return Page;
  45065. })();
  45066. /**
  45067. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  45068. * `PDFDoc`, this one doesn't have any job management code.
  45069. * Right now there exists one PDFDocument on the main thread + one object
  45070. * for each worker. If there is no worker support enabled, there are two
  45071. * `PDFDocument` objects on the main thread created.
  45072. */
  45073. var PDFDocument = (function PDFDocumentClosure() {
  45074. var FINGERPRINT_FIRST_BYTES = 1024;
  45075. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  45076. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  45077. function PDFDocument(pdfManager, arg, password) {
  45078. if (isStream(arg)) {
  45079. init.call(this, pdfManager, arg, password);
  45080. } else if (isArrayBuffer(arg)) {
  45081. init.call(this, pdfManager, new Stream(arg), password);
  45082. } else {
  45083. error('PDFDocument: Unknown argument type');
  45084. }
  45085. }
  45086. function init(pdfManager, stream, password) {
  45087. assert(stream.length > 0, 'stream must have data');
  45088. this.pdfManager = pdfManager;
  45089. this.stream = stream;
  45090. var xref = new XRef(this.stream, password, pdfManager);
  45091. this.xref = xref;
  45092. }
  45093. function find(stream, needle, limit, backwards) {
  45094. var pos = stream.pos;
  45095. var end = stream.end;
  45096. var strBuf = [];
  45097. if (pos + limit > end) {
  45098. limit = end - pos;
  45099. }
  45100. for (var n = 0; n < limit; ++n) {
  45101. strBuf.push(String.fromCharCode(stream.getByte()));
  45102. }
  45103. var str = strBuf.join('');
  45104. stream.pos = pos;
  45105. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  45106. if (index === -1) {
  45107. return false; /* not found */
  45108. }
  45109. stream.pos += index;
  45110. return true; /* found */
  45111. }
  45112. var DocumentInfoValidators = {
  45113. get entries() {
  45114. // Lazily build this since all the validation functions below are not
  45115. // defined until after this file loads.
  45116. return shadow(this, 'entries', {
  45117. Title: isString,
  45118. Author: isString,
  45119. Subject: isString,
  45120. Keywords: isString,
  45121. Creator: isString,
  45122. Producer: isString,
  45123. CreationDate: isString,
  45124. ModDate: isString,
  45125. Trapped: isName
  45126. });
  45127. }
  45128. };
  45129. PDFDocument.prototype = {
  45130. parse: function PDFDocument_parse(recoveryMode) {
  45131. this.setup(recoveryMode);
  45132. var version = this.catalog.catDict.get('Version');
  45133. if (isName(version)) {
  45134. this.pdfFormatVersion = version.name;
  45135. }
  45136. try {
  45137. // checking if AcroForm is present
  45138. this.acroForm = this.catalog.catDict.get('AcroForm');
  45139. if (this.acroForm) {
  45140. this.xfa = this.acroForm.get('XFA');
  45141. var fields = this.acroForm.get('Fields');
  45142. if ((!fields || !isArray(fields) || fields.length === 0) &&
  45143. !this.xfa) {
  45144. // no fields and no XFA -- not a form (?)
  45145. this.acroForm = null;
  45146. }
  45147. }
  45148. } catch (ex) {
  45149. info('Something wrong with AcroForm entry');
  45150. this.acroForm = null;
  45151. }
  45152. },
  45153. get linearization() {
  45154. var linearization = null;
  45155. if (this.stream.length) {
  45156. try {
  45157. linearization = Linearization.create(this.stream);
  45158. } catch (err) {
  45159. if (err instanceof MissingDataException) {
  45160. throw err;
  45161. }
  45162. info(err);
  45163. }
  45164. }
  45165. // shadow the prototype getter with a data property
  45166. return shadow(this, 'linearization', linearization);
  45167. },
  45168. get startXRef() {
  45169. var stream = this.stream;
  45170. var startXRef = 0;
  45171. var linearization = this.linearization;
  45172. if (linearization) {
  45173. // Find end of first obj.
  45174. stream.reset();
  45175. if (find(stream, 'endobj', 1024)) {
  45176. startXRef = stream.pos + 6;
  45177. }
  45178. } else {
  45179. // Find startxref by jumping backward from the end of the file.
  45180. var step = 1024;
  45181. var found = false, pos = stream.end;
  45182. while (!found && pos > 0) {
  45183. pos -= step - 'startxref'.length;
  45184. if (pos < 0) {
  45185. pos = 0;
  45186. }
  45187. stream.pos = pos;
  45188. found = find(stream, 'startxref', step, true);
  45189. }
  45190. if (found) {
  45191. stream.skip(9);
  45192. var ch;
  45193. do {
  45194. ch = stream.getByte();
  45195. } while (Lexer.isSpace(ch));
  45196. var str = '';
  45197. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  45198. str += String.fromCharCode(ch);
  45199. ch = stream.getByte();
  45200. }
  45201. startXRef = parseInt(str, 10);
  45202. if (isNaN(startXRef)) {
  45203. startXRef = 0;
  45204. }
  45205. }
  45206. }
  45207. // shadow the prototype getter with a data property
  45208. return shadow(this, 'startXRef', startXRef);
  45209. },
  45210. get mainXRefEntriesOffset() {
  45211. var mainXRefEntriesOffset = 0;
  45212. var linearization = this.linearization;
  45213. if (linearization) {
  45214. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  45215. }
  45216. // shadow the prototype getter with a data property
  45217. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  45218. },
  45219. // Find the header, remove leading garbage and setup the stream
  45220. // starting from the header.
  45221. checkHeader: function PDFDocument_checkHeader() {
  45222. var stream = this.stream;
  45223. stream.reset();
  45224. if (find(stream, '%PDF-', 1024)) {
  45225. // Found the header, trim off any garbage before it.
  45226. stream.moveStart();
  45227. // Reading file format version
  45228. var MAX_VERSION_LENGTH = 12;
  45229. var version = '', ch;
  45230. while ((ch = stream.getByte()) > 0x20) { // SPACE
  45231. if (version.length >= MAX_VERSION_LENGTH) {
  45232. break;
  45233. }
  45234. version += String.fromCharCode(ch);
  45235. }
  45236. if (!this.pdfFormatVersion) {
  45237. // removing "%PDF-"-prefix
  45238. this.pdfFormatVersion = version.substring(5);
  45239. }
  45240. return;
  45241. }
  45242. // May not be a PDF file, continue anyway.
  45243. },
  45244. parseStartXRef: function PDFDocument_parseStartXRef() {
  45245. var startXRef = this.startXRef;
  45246. this.xref.setStartXRef(startXRef);
  45247. },
  45248. setup: function PDFDocument_setup(recoveryMode) {
  45249. this.xref.parse(recoveryMode);
  45250. var self = this;
  45251. var pageFactory = {
  45252. createPage: function (pageIndex, dict, ref, fontCache) {
  45253. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  45254. fontCache);
  45255. }
  45256. };
  45257. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  45258. },
  45259. get numPages() {
  45260. var linearization = this.linearization;
  45261. var num = linearization ? linearization.numPages : this.catalog.numPages;
  45262. // shadow the prototype getter
  45263. return shadow(this, 'numPages', num);
  45264. },
  45265. get documentInfo() {
  45266. var docInfo = {
  45267. PDFFormatVersion: this.pdfFormatVersion,
  45268. IsAcroFormPresent: !!this.acroForm,
  45269. IsXFAPresent: !!this.xfa
  45270. };
  45271. var infoDict;
  45272. try {
  45273. infoDict = this.xref.trailer.get('Info');
  45274. } catch (err) {
  45275. info('The document information dictionary is invalid.');
  45276. }
  45277. if (infoDict) {
  45278. var validEntries = DocumentInfoValidators.entries;
  45279. // Only fill the document info with valid entries from the spec.
  45280. for (var key in validEntries) {
  45281. if (infoDict.has(key)) {
  45282. var value = infoDict.get(key);
  45283. // Make sure the value conforms to the spec.
  45284. if (validEntries[key](value)) {
  45285. docInfo[key] = (typeof value !== 'string' ?
  45286. value : stringToPDFString(value));
  45287. } else {
  45288. info('Bad value in document info for "' + key + '"');
  45289. }
  45290. }
  45291. }
  45292. }
  45293. return shadow(this, 'documentInfo', docInfo);
  45294. },
  45295. get fingerprint() {
  45296. var xref = this.xref, hash, fileID = '';
  45297. var idArray = xref.trailer.get('ID');
  45298. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  45299. idArray[0] !== EMPTY_FINGERPRINT) {
  45300. hash = stringToBytes(idArray[0]);
  45301. } else {
  45302. if (this.stream.ensureRange) {
  45303. this.stream.ensureRange(0,
  45304. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  45305. }
  45306. hash = calculateMD5(this.stream.bytes.subarray(0,
  45307. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  45308. }
  45309. for (var i = 0, n = hash.length; i < n; i++) {
  45310. var hex = hash[i].toString(16);
  45311. fileID += hex.length === 1 ? '0' + hex : hex;
  45312. }
  45313. return shadow(this, 'fingerprint', fileID);
  45314. },
  45315. getPage: function PDFDocument_getPage(pageIndex) {
  45316. return this.catalog.getPage(pageIndex);
  45317. },
  45318. cleanup: function PDFDocument_cleanup() {
  45319. return this.catalog.cleanup();
  45320. }
  45321. };
  45322. return PDFDocument;
  45323. })();
  45324. exports.Page = Page;
  45325. exports.PDFDocument = PDFDocument;
  45326. }));
  45327. (function (root, factory) {
  45328. {
  45329. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  45330. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  45331. root.pdfjsCoreDocument);
  45332. }
  45333. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  45334. coreDocument) {
  45335. var NotImplementedException = sharedUtil.NotImplementedException;
  45336. var MissingDataException = sharedUtil.MissingDataException;
  45337. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45338. var Util = sharedUtil.Util;
  45339. var Stream = coreStream.Stream;
  45340. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  45341. var PDFDocument = coreDocument.PDFDocument;
  45342. var BasePdfManager = (function BasePdfManagerClosure() {
  45343. function BasePdfManager() {
  45344. throw new Error('Cannot initialize BaseManagerManager');
  45345. }
  45346. BasePdfManager.prototype = {
  45347. get docId() {
  45348. return this._docId;
  45349. },
  45350. onLoadedStream: function BasePdfManager_onLoadedStream() {
  45351. throw new NotImplementedException();
  45352. },
  45353. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  45354. return this.ensure(this.pdfDocument, prop, args);
  45355. },
  45356. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  45357. return this.ensure(this.pdfDocument.xref, prop, args);
  45358. },
  45359. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  45360. return this.ensure(this.pdfDocument.catalog, prop, args);
  45361. },
  45362. getPage: function BasePdfManager_getPage(pageIndex) {
  45363. return this.pdfDocument.getPage(pageIndex);
  45364. },
  45365. cleanup: function BasePdfManager_cleanup() {
  45366. return this.pdfDocument.cleanup();
  45367. },
  45368. ensure: function BasePdfManager_ensure(obj, prop, args) {
  45369. return new NotImplementedException();
  45370. },
  45371. requestRange: function BasePdfManager_requestRange(begin, end) {
  45372. return new NotImplementedException();
  45373. },
  45374. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  45375. return new NotImplementedException();
  45376. },
  45377. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  45378. return new NotImplementedException();
  45379. },
  45380. updatePassword: function BasePdfManager_updatePassword(password) {
  45381. this.pdfDocument.xref.password = this.password = password;
  45382. if (this._passwordChangedCapability) {
  45383. this._passwordChangedCapability.resolve();
  45384. }
  45385. },
  45386. passwordChanged: function BasePdfManager_passwordChanged() {
  45387. this._passwordChangedCapability = createPromiseCapability();
  45388. return this._passwordChangedCapability.promise;
  45389. },
  45390. terminate: function BasePdfManager_terminate() {
  45391. return new NotImplementedException();
  45392. }
  45393. };
  45394. return BasePdfManager;
  45395. })();
  45396. var LocalPdfManager = (function LocalPdfManagerClosure() {
  45397. function LocalPdfManager(docId, data, password) {
  45398. this._docId = docId;
  45399. var stream = new Stream(data);
  45400. this.pdfDocument = new PDFDocument(this, stream, password);
  45401. this._loadedStreamCapability = createPromiseCapability();
  45402. this._loadedStreamCapability.resolve(stream);
  45403. }
  45404. Util.inherit(LocalPdfManager, BasePdfManager, {
  45405. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  45406. return new Promise(function (resolve, reject) {
  45407. try {
  45408. var value = obj[prop];
  45409. var result;
  45410. if (typeof value === 'function') {
  45411. result = value.apply(obj, args);
  45412. } else {
  45413. result = value;
  45414. }
  45415. resolve(result);
  45416. } catch (e) {
  45417. reject(e);
  45418. }
  45419. });
  45420. },
  45421. requestRange: function LocalPdfManager_requestRange(begin, end) {
  45422. return Promise.resolve();
  45423. },
  45424. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  45425. return;
  45426. },
  45427. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  45428. return this._loadedStreamCapability.promise;
  45429. },
  45430. terminate: function LocalPdfManager_terminate() {
  45431. return;
  45432. }
  45433. });
  45434. return LocalPdfManager;
  45435. })();
  45436. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  45437. function NetworkPdfManager(docId, args, msgHandler) {
  45438. this._docId = docId;
  45439. this.msgHandler = msgHandler;
  45440. var params = {
  45441. msgHandler: msgHandler,
  45442. httpHeaders: args.httpHeaders,
  45443. withCredentials: args.withCredentials,
  45444. chunkedViewerLoading: args.chunkedViewerLoading,
  45445. disableAutoFetch: args.disableAutoFetch,
  45446. initialData: args.initialData
  45447. };
  45448. this.streamManager = new ChunkedStreamManager(args.length,
  45449. args.rangeChunkSize,
  45450. args.url, params);
  45451. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  45452. args.password);
  45453. }
  45454. Util.inherit(NetworkPdfManager, BasePdfManager, {
  45455. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  45456. var pdfManager = this;
  45457. return new Promise(function (resolve, reject) {
  45458. function ensureHelper() {
  45459. try {
  45460. var result;
  45461. var value = obj[prop];
  45462. if (typeof value === 'function') {
  45463. result = value.apply(obj, args);
  45464. } else {
  45465. result = value;
  45466. }
  45467. resolve(result);
  45468. } catch(e) {
  45469. if (!(e instanceof MissingDataException)) {
  45470. reject(e);
  45471. return;
  45472. }
  45473. pdfManager.streamManager.requestRange(e.begin, e.end).
  45474. then(ensureHelper, reject);
  45475. }
  45476. }
  45477. ensureHelper();
  45478. });
  45479. },
  45480. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  45481. return this.streamManager.requestRange(begin, end);
  45482. },
  45483. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  45484. this.streamManager.requestAllChunks();
  45485. },
  45486. sendProgressiveData:
  45487. function NetworkPdfManager_sendProgressiveData(chunk) {
  45488. this.streamManager.onReceiveData({ chunk: chunk });
  45489. },
  45490. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  45491. return this.streamManager.onLoadedStream();
  45492. },
  45493. terminate: function NetworkPdfManager_terminate() {
  45494. this.streamManager.abort();
  45495. }
  45496. });
  45497. return NetworkPdfManager;
  45498. })();
  45499. exports.LocalPdfManager = LocalPdfManager;
  45500. exports.NetworkPdfManager = NetworkPdfManager;
  45501. }));
  45502. (function (root, factory) {
  45503. {
  45504. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  45505. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  45506. root.pdfjsSharedGlobal);
  45507. }
  45508. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  45509. sharedGlobal) {
  45510. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  45511. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45512. var MessageHandler = sharedUtil.MessageHandler;
  45513. var MissingPDFException = sharedUtil.MissingPDFException;
  45514. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  45515. var PasswordException = sharedUtil.PasswordException;
  45516. var PasswordResponses = sharedUtil.PasswordResponses;
  45517. var UnknownErrorException = sharedUtil.UnknownErrorException;
  45518. var XRefParseException = sharedUtil.XRefParseException;
  45519. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45520. var error = sharedUtil.error;
  45521. var info = sharedUtil.info;
  45522. var isInt = sharedUtil.isInt;
  45523. var warn = sharedUtil.warn;
  45524. var Ref = corePrimitives.Ref;
  45525. var LocalPdfManager = corePdfManager.LocalPdfManager;
  45526. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  45527. var globalScope = sharedGlobal.globalScope;
  45528. var PDFJS = sharedGlobal.PDFJS;
  45529. var WorkerTask = (function WorkerTaskClosure() {
  45530. function WorkerTask(name) {
  45531. this.name = name;
  45532. this.terminated = false;
  45533. this._capability = createPromiseCapability();
  45534. }
  45535. WorkerTask.prototype = {
  45536. get finished() {
  45537. return this._capability.promise;
  45538. },
  45539. finish: function () {
  45540. this._capability.resolve();
  45541. },
  45542. terminate: function () {
  45543. this.terminated = true;
  45544. },
  45545. ensureNotTerminated: function () {
  45546. if (this.terminated) {
  45547. throw new Error('Worker task was terminated');
  45548. }
  45549. }
  45550. };
  45551. return WorkerTask;
  45552. })();
  45553. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  45554. setup: function wphSetup(handler, port) {
  45555. var testMessageProcessed = false;
  45556. handler.on('test', function wphSetupTest(data) {
  45557. if (testMessageProcessed) {
  45558. return; // we already processed 'test' message once
  45559. }
  45560. testMessageProcessed = true;
  45561. // check if Uint8Array can be sent to worker
  45562. if (!(data instanceof Uint8Array)) {
  45563. handler.send('test', 'main', false);
  45564. return;
  45565. }
  45566. // making sure postMessage transfers are working
  45567. var supportTransfers = data[0] === 255;
  45568. handler.postMessageTransfers = supportTransfers;
  45569. // check if the response property is supported by xhr
  45570. var xhr = new XMLHttpRequest();
  45571. var responseExists = 'response' in xhr;
  45572. // check if the property is actually implemented
  45573. try {
  45574. var dummy = xhr.responseType;
  45575. } catch (e) {
  45576. responseExists = false;
  45577. }
  45578. if (!responseExists) {
  45579. handler.send('test', false);
  45580. return;
  45581. }
  45582. handler.send('test', {
  45583. supportTypedArray: true,
  45584. supportTransfers: supportTransfers
  45585. });
  45586. });
  45587. handler.on('GetDocRequest', function wphSetupDoc(data) {
  45588. return WorkerMessageHandler.createDocumentHandler(data, port);
  45589. });
  45590. },
  45591. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  45592. // This context is actually holds references on pdfManager and handler,
  45593. // until the latter is destroyed.
  45594. var pdfManager;
  45595. var terminated = false;
  45596. var cancelXHRs = null;
  45597. var WorkerTasks = [];
  45598. var docId = docParams.docId;
  45599. var workerHandlerName = docParams.docId + '_worker';
  45600. var handler = new MessageHandler(workerHandlerName, docId, port);
  45601. function ensureNotTerminated() {
  45602. if (terminated) {
  45603. throw new Error('Worker was terminated');
  45604. }
  45605. }
  45606. function startWorkerTask(task) {
  45607. WorkerTasks.push(task);
  45608. }
  45609. function finishWorkerTask(task) {
  45610. task.finish();
  45611. var i = WorkerTasks.indexOf(task);
  45612. WorkerTasks.splice(i, 1);
  45613. }
  45614. function loadDocument(recoveryMode) {
  45615. var loadDocumentCapability = createPromiseCapability();
  45616. var parseSuccess = function parseSuccess() {
  45617. var numPagesPromise = pdfManager.ensureDoc('numPages');
  45618. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  45619. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  45620. Promise.all([numPagesPromise, fingerprintPromise,
  45621. encryptedPromise]).then(function onDocReady(results) {
  45622. var doc = {
  45623. numPages: results[0],
  45624. fingerprint: results[1],
  45625. encrypted: !!results[2],
  45626. };
  45627. loadDocumentCapability.resolve(doc);
  45628. },
  45629. parseFailure);
  45630. };
  45631. var parseFailure = function parseFailure(e) {
  45632. loadDocumentCapability.reject(e);
  45633. };
  45634. pdfManager.ensureDoc('checkHeader', []).then(function() {
  45635. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  45636. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  45637. parseSuccess, parseFailure);
  45638. }, parseFailure);
  45639. }, parseFailure);
  45640. return loadDocumentCapability.promise;
  45641. }
  45642. function getPdfManager(data) {
  45643. var pdfManagerCapability = createPromiseCapability();
  45644. var pdfManager;
  45645. var source = data.source;
  45646. var disableRange = data.disableRange;
  45647. if (source.data) {
  45648. try {
  45649. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  45650. pdfManagerCapability.resolve(pdfManager);
  45651. } catch (ex) {
  45652. pdfManagerCapability.reject(ex);
  45653. }
  45654. return pdfManagerCapability.promise;
  45655. } else if (source.chunkedViewerLoading) {
  45656. try {
  45657. pdfManager = new NetworkPdfManager(docId, source, handler);
  45658. pdfManagerCapability.resolve(pdfManager);
  45659. } catch (ex) {
  45660. pdfManagerCapability.reject(ex);
  45661. }
  45662. return pdfManagerCapability.promise;
  45663. }
  45664. var networkManager = new NetworkManager(source.url, {
  45665. httpHeaders: source.httpHeaders,
  45666. withCredentials: source.withCredentials
  45667. });
  45668. var cachedChunks = [];
  45669. var fullRequestXhrId = networkManager.requestFull({
  45670. onHeadersReceived: function onHeadersReceived() {
  45671. if (disableRange) {
  45672. return;
  45673. }
  45674. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  45675. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  45676. return;
  45677. }
  45678. var contentEncoding =
  45679. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  45680. if (contentEncoding !== 'identity') {
  45681. return;
  45682. }
  45683. var length = fullRequestXhr.getResponseHeader('Content-Length');
  45684. length = parseInt(length, 10);
  45685. if (!isInt(length)) {
  45686. return;
  45687. }
  45688. source.length = length;
  45689. if (length <= 2 * source.rangeChunkSize) {
  45690. // The file size is smaller than the size of two chunks, so it does
  45691. // not make any sense to abort the request and retry with a range
  45692. // request.
  45693. return;
  45694. }
  45695. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  45696. // We can continue fetching when progressive loading is enabled,
  45697. // and we don't need the autoFetch feature.
  45698. source.disableAutoFetch = true;
  45699. } else {
  45700. // NOTE: by cancelling the full request, and then issuing range
  45701. // requests, there will be an issue for sites where you can only
  45702. // request the pdf once. However, if this is the case, then the
  45703. // server should not be returning that it can support range
  45704. // requests.
  45705. networkManager.abortRequest(fullRequestXhrId);
  45706. }
  45707. try {
  45708. pdfManager = new NetworkPdfManager(docId, source, handler);
  45709. pdfManagerCapability.resolve(pdfManager);
  45710. } catch (ex) {
  45711. pdfManagerCapability.reject(ex);
  45712. }
  45713. cancelXHRs = null;
  45714. },
  45715. onProgressiveData: source.disableStream ? null :
  45716. function onProgressiveData(chunk) {
  45717. if (!pdfManager) {
  45718. cachedChunks.push(chunk);
  45719. return;
  45720. }
  45721. pdfManager.sendProgressiveData(chunk);
  45722. },
  45723. onDone: function onDone(args) {
  45724. if (pdfManager) {
  45725. return; // already processed
  45726. }
  45727. var pdfFile;
  45728. if (args === null) {
  45729. // TODO add some streaming manager, e.g. for unknown length files.
  45730. // The data was returned in the onProgressiveData, combining...
  45731. var pdfFileLength = 0, pos = 0;
  45732. cachedChunks.forEach(function (chunk) {
  45733. pdfFileLength += chunk.byteLength;
  45734. });
  45735. if (source.length && pdfFileLength !== source.length) {
  45736. warn('reported HTTP length is different from actual');
  45737. }
  45738. var pdfFileArray = new Uint8Array(pdfFileLength);
  45739. cachedChunks.forEach(function (chunk) {
  45740. pdfFileArray.set(new Uint8Array(chunk), pos);
  45741. pos += chunk.byteLength;
  45742. });
  45743. pdfFile = pdfFileArray.buffer;
  45744. } else {
  45745. pdfFile = args.chunk;
  45746. }
  45747. // the data is array, instantiating directly from it
  45748. try {
  45749. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  45750. pdfManagerCapability.resolve(pdfManager);
  45751. } catch (ex) {
  45752. pdfManagerCapability.reject(ex);
  45753. }
  45754. cancelXHRs = null;
  45755. },
  45756. onError: function onError(status) {
  45757. var exception;
  45758. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  45759. exception = new MissingPDFException('Missing PDF "' +
  45760. source.url + '".');
  45761. handler.send('MissingPDF', exception);
  45762. } else {
  45763. exception = new UnexpectedResponseException(
  45764. 'Unexpected server response (' + status +
  45765. ') while retrieving PDF "' + source.url + '".', status);
  45766. handler.send('UnexpectedResponse', exception);
  45767. }
  45768. cancelXHRs = null;
  45769. },
  45770. onProgress: function onProgress(evt) {
  45771. handler.send('DocProgress', {
  45772. loaded: evt.loaded,
  45773. total: evt.lengthComputable ? evt.total : source.length
  45774. });
  45775. }
  45776. });
  45777. cancelXHRs = function () {
  45778. networkManager.abortRequest(fullRequestXhrId);
  45779. };
  45780. return pdfManagerCapability.promise;
  45781. }
  45782. var setupDoc = function(data) {
  45783. var onSuccess = function(doc) {
  45784. ensureNotTerminated();
  45785. handler.send('GetDoc', { pdfInfo: doc });
  45786. };
  45787. var onFailure = function(e) {
  45788. if (e instanceof PasswordException) {
  45789. if (e.code === PasswordResponses.NEED_PASSWORD) {
  45790. handler.send('NeedPassword', e);
  45791. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  45792. handler.send('IncorrectPassword', e);
  45793. }
  45794. } else if (e instanceof InvalidPDFException) {
  45795. handler.send('InvalidPDF', e);
  45796. } else if (e instanceof MissingPDFException) {
  45797. handler.send('MissingPDF', e);
  45798. } else if (e instanceof UnexpectedResponseException) {
  45799. handler.send('UnexpectedResponse', e);
  45800. } else {
  45801. handler.send('UnknownError',
  45802. new UnknownErrorException(e.message, e.toString()));
  45803. }
  45804. };
  45805. ensureNotTerminated();
  45806. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  45807. -1 : data.maxImageSize;
  45808. PDFJS.disableFontFace = data.disableFontFace;
  45809. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  45810. PDFJS.verbosity = data.verbosity;
  45811. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  45812. null : data.cMapUrl;
  45813. PDFJS.cMapPacked = data.cMapPacked === true;
  45814. getPdfManager(data).then(function (newPdfManager) {
  45815. if (terminated) {
  45816. // We were in a process of setting up the manager, but it got
  45817. // terminated in the middle.
  45818. newPdfManager.terminate();
  45819. throw new Error('Worker was terminated');
  45820. }
  45821. pdfManager = newPdfManager;
  45822. handler.send('PDFManagerReady', null);
  45823. pdfManager.onLoadedStream().then(function(stream) {
  45824. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  45825. });
  45826. }).then(function pdfManagerReady() {
  45827. ensureNotTerminated();
  45828. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  45829. ensureNotTerminated();
  45830. // Try again with recoveryMode == true
  45831. if (!(ex instanceof XRefParseException)) {
  45832. if (ex instanceof PasswordException) {
  45833. // after password exception prepare to receive a new password
  45834. // to repeat loading
  45835. pdfManager.passwordChanged().then(pdfManagerReady);
  45836. }
  45837. onFailure(ex);
  45838. return;
  45839. }
  45840. pdfManager.requestLoadedStream();
  45841. pdfManager.onLoadedStream().then(function() {
  45842. ensureNotTerminated();
  45843. loadDocument(true).then(onSuccess, onFailure);
  45844. });
  45845. }, onFailure);
  45846. }, onFailure);
  45847. };
  45848. handler.on('GetPage', function wphSetupGetPage(data) {
  45849. return pdfManager.getPage(data.pageIndex).then(function(page) {
  45850. var rotatePromise = pdfManager.ensure(page, 'rotate');
  45851. var refPromise = pdfManager.ensure(page, 'ref');
  45852. var viewPromise = pdfManager.ensure(page, 'view');
  45853. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  45854. function(results) {
  45855. return {
  45856. rotate: results[0],
  45857. ref: results[1],
  45858. view: results[2]
  45859. };
  45860. });
  45861. });
  45862. });
  45863. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  45864. var ref = new Ref(data.ref.num, data.ref.gen);
  45865. var catalog = pdfManager.pdfDocument.catalog;
  45866. return catalog.getPageIndex(ref);
  45867. });
  45868. handler.on('GetDestinations',
  45869. function wphSetupGetDestinations(data) {
  45870. return pdfManager.ensureCatalog('destinations');
  45871. }
  45872. );
  45873. handler.on('GetDestination',
  45874. function wphSetupGetDestination(data) {
  45875. return pdfManager.ensureCatalog('getDestination', [data.id]);
  45876. }
  45877. );
  45878. handler.on('GetAttachments',
  45879. function wphSetupGetAttachments(data) {
  45880. return pdfManager.ensureCatalog('attachments');
  45881. }
  45882. );
  45883. handler.on('GetJavaScript',
  45884. function wphSetupGetJavaScript(data) {
  45885. return pdfManager.ensureCatalog('javaScript');
  45886. }
  45887. );
  45888. handler.on('GetOutline',
  45889. function wphSetupGetOutline(data) {
  45890. return pdfManager.ensureCatalog('documentOutline');
  45891. }
  45892. );
  45893. handler.on('GetMetadata',
  45894. function wphSetupGetMetadata(data) {
  45895. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  45896. pdfManager.ensureCatalog('metadata')]);
  45897. }
  45898. );
  45899. handler.on('GetData', function wphSetupGetData(data) {
  45900. pdfManager.requestLoadedStream();
  45901. return pdfManager.onLoadedStream().then(function(stream) {
  45902. return stream.bytes;
  45903. });
  45904. });
  45905. handler.on('GetStats',
  45906. function wphSetupGetStats(data) {
  45907. return pdfManager.pdfDocument.xref.stats;
  45908. }
  45909. );
  45910. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  45911. pdfManager.updatePassword(data);
  45912. });
  45913. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  45914. return pdfManager.getPage(data.pageIndex).then(function(page) {
  45915. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  45916. });
  45917. });
  45918. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  45919. var pageIndex = data.pageIndex;
  45920. pdfManager.getPage(pageIndex).then(function(page) {
  45921. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  45922. startWorkerTask(task);
  45923. var pageNum = pageIndex + 1;
  45924. var start = Date.now();
  45925. // Pre compile the pdf page and fetch the fonts/images.
  45926. page.getOperatorList(handler, task, data.intent).then(
  45927. function(operatorList) {
  45928. finishWorkerTask(task);
  45929. info('page=' + pageNum + ' - getOperatorList: time=' +
  45930. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  45931. }, function(e) {
  45932. finishWorkerTask(task);
  45933. if (task.terminated) {
  45934. return; // ignoring errors from the terminated thread
  45935. }
  45936. // For compatibility with older behavior, generating unknown
  45937. // unsupported feature notification on errors.
  45938. handler.send('UnsupportedFeature',
  45939. {featureId: UNSUPPORTED_FEATURES.unknown});
  45940. var minimumStackMessage =
  45941. 'worker.js: while trying to getPage() and getOperatorList()';
  45942. var wrappedException;
  45943. // Turn the error into an obj that can be serialized
  45944. if (typeof e === 'string') {
  45945. wrappedException = {
  45946. message: e,
  45947. stack: minimumStackMessage
  45948. };
  45949. } else if (typeof e === 'object') {
  45950. wrappedException = {
  45951. message: e.message || e.toString(),
  45952. stack: e.stack || minimumStackMessage
  45953. };
  45954. } else {
  45955. wrappedException = {
  45956. message: 'Unknown exception type: ' + (typeof e),
  45957. stack: minimumStackMessage
  45958. };
  45959. }
  45960. handler.send('PageError', {
  45961. pageNum: pageNum,
  45962. error: wrappedException,
  45963. intent: data.intent
  45964. });
  45965. });
  45966. });
  45967. }, this);
  45968. handler.on('GetTextContent', function wphExtractText(data) {
  45969. var pageIndex = data.pageIndex;
  45970. var normalizeWhitespace = data.normalizeWhitespace;
  45971. return pdfManager.getPage(pageIndex).then(function(page) {
  45972. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  45973. startWorkerTask(task);
  45974. var pageNum = pageIndex + 1;
  45975. var start = Date.now();
  45976. return page.extractTextContent(task, normalizeWhitespace).then(
  45977. function(textContent) {
  45978. finishWorkerTask(task);
  45979. info('text indexing: page=' + pageNum + ' - time=' +
  45980. (Date.now() - start) + 'ms');
  45981. return textContent;
  45982. }, function (reason) {
  45983. finishWorkerTask(task);
  45984. if (task.terminated) {
  45985. return; // ignoring errors from the terminated thread
  45986. }
  45987. throw reason;
  45988. });
  45989. });
  45990. });
  45991. handler.on('Cleanup', function wphCleanup(data) {
  45992. return pdfManager.cleanup();
  45993. });
  45994. handler.on('Terminate', function wphTerminate(data) {
  45995. terminated = true;
  45996. if (pdfManager) {
  45997. pdfManager.terminate();
  45998. pdfManager = null;
  45999. }
  46000. if (cancelXHRs) {
  46001. cancelXHRs();
  46002. }
  46003. var waitOn = [];
  46004. WorkerTasks.forEach(function (task) {
  46005. waitOn.push(task.finished);
  46006. task.terminate();
  46007. });
  46008. return Promise.all(waitOn).then(function () {
  46009. // Notice that even if we destroying handler, resolved response promise
  46010. // must be sent back.
  46011. handler.destroy();
  46012. handler = null;
  46013. });
  46014. });
  46015. handler.on('Ready', function wphReady(data) {
  46016. setupDoc(docParams);
  46017. docParams = null; // we don't need docParams anymore -- saving memory.
  46018. });
  46019. return workerHandlerName;
  46020. }
  46021. };
  46022. function initializeWorker() {
  46023. if (!('console' in globalScope)) {
  46024. var consoleTimer = {};
  46025. var workerConsole = {
  46026. log: function log() {
  46027. var args = Array.prototype.slice.call(arguments);
  46028. globalScope.postMessage({
  46029. targetName: 'main',
  46030. action: 'console_log',
  46031. data: args
  46032. });
  46033. },
  46034. error: function error() {
  46035. var args = Array.prototype.slice.call(arguments);
  46036. globalScope.postMessage({
  46037. targetName: 'main',
  46038. action: 'console_error',
  46039. data: args
  46040. });
  46041. throw 'pdf.js execution error';
  46042. },
  46043. time: function time(name) {
  46044. consoleTimer[name] = Date.now();
  46045. },
  46046. timeEnd: function timeEnd(name) {
  46047. var time = consoleTimer[name];
  46048. if (!time) {
  46049. error('Unknown timer name ' + name);
  46050. }
  46051. this.log('Timer:', name, Date.now() - time);
  46052. }
  46053. };
  46054. globalScope.console = workerConsole;
  46055. }
  46056. var handler = new MessageHandler('worker', 'main', self);
  46057. WorkerMessageHandler.setup(handler, self);
  46058. handler.send('ready', null);
  46059. }
  46060. // Worker thread (and not node.js)?
  46061. if (typeof window === 'undefined' &&
  46062. !(typeof module !== 'undefined' && module.require)) {
  46063. initializeWorker();
  46064. }
  46065. exports.WorkerTask = WorkerTask;
  46066. exports.WorkerMessageHandler = WorkerMessageHandler;
  46067. }));
  46068. }).call(pdfjsLibs);
  46069. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  46070. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  46071. exports.PDFDataRangeTransport =
  46072. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  46073. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  46074. exports.AnnotationLayer =
  46075. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  46076. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  46077. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  46078. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  46079. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  46080. exports.UnexpectedResponseException =
  46081. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  46082. }));