pdf.combined.js 1.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014
  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.5.415';
  30. var pdfjsBuild = '8522625';
  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.pdfjsCoreBidi = {}));
  203. }
  204. }(this, function (exports) {
  205. // Character types for symbols from 0000 to 00FF.
  206. var baseTypes = [
  207. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  208. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  209. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  210. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  211. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  212. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  213. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  214. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  215. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  216. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  217. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  218. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  219. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  220. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  221. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  222. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  223. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  224. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  225. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  226. ];
  227. // Character types for symbols from 0600 to 06FF
  228. var arabicTypes = [
  229. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  230. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  231. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  232. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  233. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  234. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  235. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  236. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  237. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  238. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  239. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  240. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  241. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  242. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  243. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  244. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  245. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  246. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  247. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  248. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  249. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  250. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  251. ];
  252. function isOdd(i) {
  253. return (i & 1) !== 0;
  254. }
  255. function isEven(i) {
  256. return (i & 1) === 0;
  257. }
  258. function findUnequal(arr, start, value) {
  259. for (var j = start, jj = arr.length; j < jj; ++j) {
  260. if (arr[j] !== value) {
  261. return j;
  262. }
  263. }
  264. return j;
  265. }
  266. function setValues(arr, start, end, value) {
  267. for (var j = start; j < end; ++j) {
  268. arr[j] = value;
  269. }
  270. }
  271. function reverseValues(arr, start, end) {
  272. for (var i = start, j = end - 1; i < j; ++i, --j) {
  273. var temp = arr[i];
  274. arr[i] = arr[j];
  275. arr[j] = temp;
  276. }
  277. }
  278. function createBidiText(str, isLTR, vertical) {
  279. return {
  280. str: str,
  281. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  282. };
  283. }
  284. // These are used in bidi(), which is called frequently. We re-use them on
  285. // each call to avoid unnecessary allocations.
  286. var chars = [];
  287. var types = [];
  288. function bidi(str, startLevel, vertical) {
  289. var isLTR = true;
  290. var strLength = str.length;
  291. if (strLength === 0 || vertical) {
  292. return createBidiText(str, isLTR, vertical);
  293. }
  294. // Get types and fill arrays
  295. chars.length = strLength;
  296. types.length = strLength;
  297. var numBidi = 0;
  298. var i, ii;
  299. for (i = 0; i < strLength; ++i) {
  300. chars[i] = str.charAt(i);
  301. var charCode = str.charCodeAt(i);
  302. var charType = 'L';
  303. if (charCode <= 0x00ff) {
  304. charType = baseTypes[charCode];
  305. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  306. charType = 'R';
  307. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  308. charType = arabicTypes[charCode & 0xff];
  309. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  310. charType = 'AL';
  311. }
  312. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  313. numBidi++;
  314. }
  315. types[i] = charType;
  316. }
  317. // Detect the bidi method
  318. // - If there are no rtl characters then no bidi needed
  319. // - If less than 30% chars are rtl then string is primarily ltr
  320. // - If more than 30% chars are rtl then string is primarily rtl
  321. if (numBidi === 0) {
  322. isLTR = true;
  323. return createBidiText(str, isLTR);
  324. }
  325. if (startLevel === -1) {
  326. if ((strLength / numBidi) < 0.3) {
  327. isLTR = true;
  328. startLevel = 0;
  329. } else {
  330. isLTR = false;
  331. startLevel = 1;
  332. }
  333. }
  334. var levels = [];
  335. for (i = 0; i < strLength; ++i) {
  336. levels[i] = startLevel;
  337. }
  338. /*
  339. X1-X10: skip most of this, since we are NOT doing the embeddings.
  340. */
  341. var e = (isOdd(startLevel) ? 'R' : 'L');
  342. var sor = e;
  343. var eor = sor;
  344. /*
  345. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  346. type of the NSM to the type of the previous character. If the NSM is at the
  347. start of the level run, it will get the type of sor.
  348. */
  349. var lastType = sor;
  350. for (i = 0; i < strLength; ++i) {
  351. if (types[i] === 'NSM') {
  352. types[i] = lastType;
  353. } else {
  354. lastType = types[i];
  355. }
  356. }
  357. /*
  358. W2. Search backwards from each instance of a European number until the
  359. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  360. the type of the European number to Arabic number.
  361. */
  362. lastType = sor;
  363. var t;
  364. for (i = 0; i < strLength; ++i) {
  365. t = types[i];
  366. if (t === 'EN') {
  367. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  368. } else if (t === 'R' || t === 'L' || t === 'AL') {
  369. lastType = t;
  370. }
  371. }
  372. /*
  373. W3. Change all ALs to R.
  374. */
  375. for (i = 0; i < strLength; ++i) {
  376. t = types[i];
  377. if (t === 'AL') {
  378. types[i] = 'R';
  379. }
  380. }
  381. /*
  382. W4. A single European separator between two European numbers changes to a
  383. European number. A single common separator between two numbers of the same
  384. type changes to that type:
  385. */
  386. for (i = 1; i < strLength - 1; ++i) {
  387. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  388. types[i] = 'EN';
  389. }
  390. if (types[i] === 'CS' &&
  391. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  392. types[i + 1] === types[i - 1]) {
  393. types[i] = types[i - 1];
  394. }
  395. }
  396. /*
  397. W5. A sequence of European terminators adjacent to European numbers changes
  398. to all European numbers:
  399. */
  400. for (i = 0; i < strLength; ++i) {
  401. if (types[i] === 'EN') {
  402. // do before
  403. var j;
  404. for (j = i - 1; j >= 0; --j) {
  405. if (types[j] !== 'ET') {
  406. break;
  407. }
  408. types[j] = 'EN';
  409. }
  410. // do after
  411. for (j = i + 1; j < strLength; ++j) {
  412. if (types[j] !== 'ET') {
  413. break;
  414. }
  415. types[j] = 'EN';
  416. }
  417. }
  418. }
  419. /*
  420. W6. Otherwise, separators and terminators change to Other Neutral:
  421. */
  422. for (i = 0; i < strLength; ++i) {
  423. t = types[i];
  424. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  425. types[i] = 'ON';
  426. }
  427. }
  428. /*
  429. W7. Search backwards from each instance of a European number until the
  430. first strong type (R, L, or sor) is found. If an L is found, then change
  431. the type of the European number to L.
  432. */
  433. lastType = sor;
  434. for (i = 0; i < strLength; ++i) {
  435. t = types[i];
  436. if (t === 'EN') {
  437. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  438. } else if (t === 'R' || t === 'L') {
  439. lastType = t;
  440. }
  441. }
  442. /*
  443. N1. A sequence of neutrals takes the direction of the surrounding strong
  444. text if the text on both sides has the same direction. European and Arabic
  445. numbers are treated as though they were R. Start-of-level-run (sor) and
  446. end-of-level-run (eor) are used at level run boundaries.
  447. */
  448. for (i = 0; i < strLength; ++i) {
  449. if (types[i] === 'ON') {
  450. var end = findUnequal(types, i + 1, 'ON');
  451. var before = sor;
  452. if (i > 0) {
  453. before = types[i - 1];
  454. }
  455. var after = eor;
  456. if (end + 1 < strLength) {
  457. after = types[end + 1];
  458. }
  459. if (before !== 'L') {
  460. before = 'R';
  461. }
  462. if (after !== 'L') {
  463. after = 'R';
  464. }
  465. if (before === after) {
  466. setValues(types, i, end, before);
  467. }
  468. i = end - 1; // reset to end (-1 so next iteration is ok)
  469. }
  470. }
  471. /*
  472. N2. Any remaining neutrals take the embedding direction.
  473. */
  474. for (i = 0; i < strLength; ++i) {
  475. if (types[i] === 'ON') {
  476. types[i] = e;
  477. }
  478. }
  479. /*
  480. I1. For all characters with an even (left-to-right) embedding direction,
  481. those of type R go up one level and those of type AN or EN go up two
  482. levels.
  483. I2. For all characters with an odd (right-to-left) embedding direction,
  484. those of type L, EN or AN go up one level.
  485. */
  486. for (i = 0; i < strLength; ++i) {
  487. t = types[i];
  488. if (isEven(levels[i])) {
  489. if (t === 'R') {
  490. levels[i] += 1;
  491. } else if (t === 'AN' || t === 'EN') {
  492. levels[i] += 2;
  493. }
  494. } else { // isOdd
  495. if (t === 'L' || t === 'AN' || t === 'EN') {
  496. levels[i] += 1;
  497. }
  498. }
  499. }
  500. /*
  501. L1. On each line, reset the embedding level of the following characters to
  502. the paragraph embedding level:
  503. segment separators,
  504. paragraph separators,
  505. any sequence of whitespace characters preceding a segment separator or
  506. paragraph separator, and any sequence of white space characters at the end
  507. of the line.
  508. */
  509. // don't bother as text is only single line
  510. /*
  511. L2. From the highest level found in the text to the lowest odd level on
  512. each line, reverse any contiguous sequence of characters that are at that
  513. level or higher.
  514. */
  515. // find highest level & lowest odd level
  516. var highestLevel = -1;
  517. var lowestOddLevel = 99;
  518. var level;
  519. for (i = 0, ii = levels.length; i < ii; ++i) {
  520. level = levels[i];
  521. if (highestLevel < level) {
  522. highestLevel = level;
  523. }
  524. if (lowestOddLevel > level && isOdd(level)) {
  525. lowestOddLevel = level;
  526. }
  527. }
  528. // now reverse between those limits
  529. for (level = highestLevel; level >= lowestOddLevel; --level) {
  530. // find segments to reverse
  531. var start = -1;
  532. for (i = 0, ii = levels.length; i < ii; ++i) {
  533. if (levels[i] < level) {
  534. if (start >= 0) {
  535. reverseValues(chars, start, i);
  536. start = -1;
  537. }
  538. } else if (start < 0) {
  539. start = i;
  540. }
  541. }
  542. if (start >= 0) {
  543. reverseValues(chars, start, levels.length);
  544. }
  545. }
  546. /*
  547. L3. Combining marks applied to a right-to-left base character will at this
  548. point precede their base character. If the rendering engine expects them to
  549. follow the base characters in the final display process, then the ordering
  550. of the marks and the base character must be reversed.
  551. */
  552. // don't bother for now
  553. /*
  554. L4. A character that possesses the mirrored property as specified by
  555. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  556. directionality of that character is R.
  557. */
  558. // don't mirror as characters are already mirrored in the pdf
  559. // Finally, return string
  560. for (i = 0, ii = chars.length; i < ii; ++i) {
  561. var ch = chars[i];
  562. if (ch === '<' || ch === '>') {
  563. chars[i] = '';
  564. }
  565. }
  566. return createBidiText(chars.join(''), isLTR);
  567. }
  568. exports.bidi = bidi;
  569. }));
  570. (function (root, factory) {
  571. {
  572. factory((root.pdfjsCoreCharsets = {}));
  573. }
  574. }(this, function (exports) {
  575. var ISOAdobeCharset = [
  576. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  577. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  578. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  579. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  580. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  581. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  582. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  583. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  584. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  585. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  586. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  587. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  588. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  589. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  590. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  591. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  592. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  593. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  594. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  595. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  596. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  597. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  598. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  599. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  600. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  601. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  602. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  603. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  604. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  605. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  606. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  607. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  608. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  609. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  610. ];
  611. var ExpertCharset = [
  612. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  613. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  614. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  615. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  616. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  617. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  618. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  619. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  620. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  621. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  622. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  623. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  624. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  625. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  626. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  627. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  628. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  629. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  630. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  631. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  632. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  633. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  634. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  635. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  636. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  637. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  638. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  639. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  640. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  641. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  642. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  643. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  644. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  645. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  646. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  647. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  648. 'Ydieresissmall'
  649. ];
  650. var ExpertSubsetCharset = [
  651. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  652. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  653. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  654. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  655. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  656. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  657. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  658. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  659. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  660. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  661. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  662. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  663. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  664. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  665. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  666. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  667. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  668. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  669. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  670. 'periodinferior', 'commainferior'
  671. ];
  672. exports.ISOAdobeCharset = ISOAdobeCharset;
  673. exports.ExpertCharset = ExpertCharset;
  674. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  675. }));
  676. (function (root, factory) {
  677. {
  678. factory((root.pdfjsCoreEncodings = {}));
  679. }
  680. }(this, function (exports) {
  681. var ExpertEncoding = [
  682. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  683. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  684. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  685. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  686. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  687. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  688. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  689. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  690. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  691. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  692. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  693. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  694. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  695. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  696. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  697. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  698. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  699. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  700. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  701. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  702. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  703. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  704. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  705. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  706. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  707. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  708. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  709. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  710. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  711. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  712. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  713. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  714. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  715. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  716. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  717. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  718. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  719. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  720. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  721. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  722. 'Ydieresissmall'];
  723. var MacExpertEncoding = [
  724. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  725. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  726. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  727. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  728. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  729. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  730. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  731. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  732. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  733. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  734. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  735. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  736. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  737. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  738. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  739. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  740. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  741. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  742. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  743. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  744. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  745. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  746. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  747. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  748. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  749. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  750. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  751. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  752. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  753. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  754. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  755. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  756. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  757. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  758. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  759. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  760. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  761. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  762. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  763. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'];
  764. var MacRomanEncoding = [
  765. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  766. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  767. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  768. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  769. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  770. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  771. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  772. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  773. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  774. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  775. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  776. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  777. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  778. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  779. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  780. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  781. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  782. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  783. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  784. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  785. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  786. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  787. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  788. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  789. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  790. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  791. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  792. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  793. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  794. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  795. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  796. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  797. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  798. 'ogonek', 'caron'];
  799. var StandardEncoding = [
  800. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  801. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  802. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  803. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  804. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  805. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  806. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  807. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  808. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  809. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  810. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  811. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  812. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  813. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  814. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  815. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  816. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  817. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  818. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  819. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  820. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  821. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  822. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  823. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  824. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'];
  825. var WinAnsiEncoding = [
  826. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  827. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  828. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  829. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  830. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  831. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  832. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  833. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  834. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  835. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  836. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  837. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  838. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  839. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  840. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  841. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  842. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  843. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  844. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  845. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  846. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  847. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  848. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  849. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  850. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  851. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  852. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  853. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  854. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  855. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  856. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  857. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  858. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  859. 'ydieresis'];
  860. var SymbolSetEncoding = [
  861. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  862. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  863. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  864. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  865. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  866. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  867. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  868. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  869. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  870. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  871. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  872. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  873. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  874. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  875. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  876. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  877. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  878. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  879. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  880. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  881. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  882. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  883. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  884. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  885. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  886. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  887. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  888. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  889. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  890. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  891. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  892. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  893. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  894. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  895. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  896. 'bracerightbt'];
  897. var ZapfDingbatsEncoding = [
  898. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  899. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  900. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  901. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  902. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  903. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  904. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  905. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  906. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  907. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  908. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  909. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  910. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  911. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  912. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  913. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  914. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  915. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  916. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  917. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  918. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  919. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  920. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  921. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191'];
  922. function getEncoding(encodingName) {
  923. switch (encodingName) {
  924. case 'WinAnsiEncoding':
  925. return WinAnsiEncoding;
  926. case 'StandardEncoding':
  927. return StandardEncoding;
  928. case 'MacRomanEncoding':
  929. return MacRomanEncoding;
  930. case 'SymbolSetEncoding':
  931. return SymbolSetEncoding;
  932. case 'ZapfDingbatsEncoding':
  933. return ZapfDingbatsEncoding;
  934. case 'ExpertEncoding':
  935. return ExpertEncoding;
  936. case 'MacExpertEncoding':
  937. return MacExpertEncoding;
  938. default:
  939. return null;
  940. }
  941. }
  942. exports.WinAnsiEncoding = WinAnsiEncoding;
  943. exports.StandardEncoding = StandardEncoding;
  944. exports.MacRomanEncoding = MacRomanEncoding;
  945. exports.SymbolSetEncoding = SymbolSetEncoding;
  946. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  947. exports.ExpertEncoding = ExpertEncoding;
  948. exports.getEncoding = getEncoding;
  949. }));
  950. (function (root, factory) {
  951. {
  952. factory((root.pdfjsCoreJpg = {}));
  953. }
  954. }(this, function (exports) {
  955. /*
  956. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  957. version was created by github user notmasteryet
  958. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  959. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  960. - The JFIF specification can be found in the JPEG File Interchange Format
  961. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  962. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  963. in PostScript Level 2, Technical Note #5116
  964. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  965. */
  966. var JpegImage = (function jpegImage() {
  967. var dctZigZag = new Uint8Array([
  968. 0,
  969. 1, 8,
  970. 16, 9, 2,
  971. 3, 10, 17, 24,
  972. 32, 25, 18, 11, 4,
  973. 5, 12, 19, 26, 33, 40,
  974. 48, 41, 34, 27, 20, 13, 6,
  975. 7, 14, 21, 28, 35, 42, 49, 56,
  976. 57, 50, 43, 36, 29, 22, 15,
  977. 23, 30, 37, 44, 51, 58,
  978. 59, 52, 45, 38, 31,
  979. 39, 46, 53, 60,
  980. 61, 54, 47,
  981. 55, 62,
  982. 63
  983. ]);
  984. var dctCos1 = 4017; // cos(pi/16)
  985. var dctSin1 = 799; // sin(pi/16)
  986. var dctCos3 = 3406; // cos(3*pi/16)
  987. var dctSin3 = 2276; // sin(3*pi/16)
  988. var dctCos6 = 1567; // cos(6*pi/16)
  989. var dctSin6 = 3784; // sin(6*pi/16)
  990. var dctSqrt2 = 5793; // sqrt(2)
  991. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  992. function constructor() {
  993. }
  994. function buildHuffmanTable(codeLengths, values) {
  995. var k = 0, code = [], i, j, length = 16;
  996. while (length > 0 && !codeLengths[length - 1]) {
  997. length--;
  998. }
  999. code.push({children: [], index: 0});
  1000. var p = code[0], q;
  1001. for (i = 0; i < length; i++) {
  1002. for (j = 0; j < codeLengths[i]; j++) {
  1003. p = code.pop();
  1004. p.children[p.index] = values[k];
  1005. while (p.index > 0) {
  1006. p = code.pop();
  1007. }
  1008. p.index++;
  1009. code.push(p);
  1010. while (code.length <= i) {
  1011. code.push(q = {children: [], index: 0});
  1012. p.children[p.index] = q.children;
  1013. p = q;
  1014. }
  1015. k++;
  1016. }
  1017. if (i + 1 < length) {
  1018. // p here points to last code
  1019. code.push(q = {children: [], index: 0});
  1020. p.children[p.index] = q.children;
  1021. p = q;
  1022. }
  1023. }
  1024. return code[0].children;
  1025. }
  1026. function getBlockBufferOffset(component, row, col) {
  1027. return 64 * ((component.blocksPerLine + 1) * row + col);
  1028. }
  1029. function decodeScan(data, offset, frame, components, resetInterval,
  1030. spectralStart, spectralEnd, successivePrev, successive) {
  1031. var mcusPerLine = frame.mcusPerLine;
  1032. var progressive = frame.progressive;
  1033. var startOffset = offset, bitsData = 0, bitsCount = 0;
  1034. function readBit() {
  1035. if (bitsCount > 0) {
  1036. bitsCount--;
  1037. return (bitsData >> bitsCount) & 1;
  1038. }
  1039. bitsData = data[offset++];
  1040. if (bitsData === 0xFF) {
  1041. var nextByte = data[offset++];
  1042. if (nextByte) {
  1043. throw 'unexpected marker: ' +
  1044. ((bitsData << 8) | nextByte).toString(16);
  1045. }
  1046. // unstuff 0
  1047. }
  1048. bitsCount = 7;
  1049. return bitsData >>> 7;
  1050. }
  1051. function decodeHuffman(tree) {
  1052. var node = tree;
  1053. while (true) {
  1054. node = node[readBit()];
  1055. if (typeof node === 'number') {
  1056. return node;
  1057. }
  1058. if (typeof node !== 'object') {
  1059. throw 'invalid huffman sequence';
  1060. }
  1061. }
  1062. }
  1063. function receive(length) {
  1064. var n = 0;
  1065. while (length > 0) {
  1066. n = (n << 1) | readBit();
  1067. length--;
  1068. }
  1069. return n;
  1070. }
  1071. function receiveAndExtend(length) {
  1072. if (length === 1) {
  1073. return readBit() === 1 ? 1 : -1;
  1074. }
  1075. var n = receive(length);
  1076. if (n >= 1 << (length - 1)) {
  1077. return n;
  1078. }
  1079. return n + (-1 << length) + 1;
  1080. }
  1081. function decodeBaseline(component, offset) {
  1082. var t = decodeHuffman(component.huffmanTableDC);
  1083. var diff = t === 0 ? 0 : receiveAndExtend(t);
  1084. component.blockData[offset] = (component.pred += diff);
  1085. var k = 1;
  1086. while (k < 64) {
  1087. var rs = decodeHuffman(component.huffmanTableAC);
  1088. var s = rs & 15, r = rs >> 4;
  1089. if (s === 0) {
  1090. if (r < 15) {
  1091. break;
  1092. }
  1093. k += 16;
  1094. continue;
  1095. }
  1096. k += r;
  1097. var z = dctZigZag[k];
  1098. component.blockData[offset + z] = receiveAndExtend(s);
  1099. k++;
  1100. }
  1101. }
  1102. function decodeDCFirst(component, offset) {
  1103. var t = decodeHuffman(component.huffmanTableDC);
  1104. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  1105. component.blockData[offset] = (component.pred += diff);
  1106. }
  1107. function decodeDCSuccessive(component, offset) {
  1108. component.blockData[offset] |= readBit() << successive;
  1109. }
  1110. var eobrun = 0;
  1111. function decodeACFirst(component, offset) {
  1112. if (eobrun > 0) {
  1113. eobrun--;
  1114. return;
  1115. }
  1116. var k = spectralStart, e = spectralEnd;
  1117. while (k <= e) {
  1118. var rs = decodeHuffman(component.huffmanTableAC);
  1119. var s = rs & 15, r = rs >> 4;
  1120. if (s === 0) {
  1121. if (r < 15) {
  1122. eobrun = receive(r) + (1 << r) - 1;
  1123. break;
  1124. }
  1125. k += 16;
  1126. continue;
  1127. }
  1128. k += r;
  1129. var z = dctZigZag[k];
  1130. component.blockData[offset + z] =
  1131. receiveAndExtend(s) * (1 << successive);
  1132. k++;
  1133. }
  1134. }
  1135. var successiveACState = 0, successiveACNextValue;
  1136. function decodeACSuccessive(component, offset) {
  1137. var k = spectralStart;
  1138. var e = spectralEnd;
  1139. var r = 0;
  1140. var s;
  1141. var rs;
  1142. while (k <= e) {
  1143. var z = dctZigZag[k];
  1144. switch (successiveACState) {
  1145. case 0: // initial state
  1146. rs = decodeHuffman(component.huffmanTableAC);
  1147. s = rs & 15;
  1148. r = rs >> 4;
  1149. if (s === 0) {
  1150. if (r < 15) {
  1151. eobrun = receive(r) + (1 << r);
  1152. successiveACState = 4;
  1153. } else {
  1154. r = 16;
  1155. successiveACState = 1;
  1156. }
  1157. } else {
  1158. if (s !== 1) {
  1159. throw 'invalid ACn encoding';
  1160. }
  1161. successiveACNextValue = receiveAndExtend(s);
  1162. successiveACState = r ? 2 : 3;
  1163. }
  1164. continue;
  1165. case 1: // skipping r zero items
  1166. case 2:
  1167. if (component.blockData[offset + z]) {
  1168. component.blockData[offset + z] += (readBit() << successive);
  1169. } else {
  1170. r--;
  1171. if (r === 0) {
  1172. successiveACState = successiveACState === 2 ? 3 : 0;
  1173. }
  1174. }
  1175. break;
  1176. case 3: // set value for a zero item
  1177. if (component.blockData[offset + z]) {
  1178. component.blockData[offset + z] += (readBit() << successive);
  1179. } else {
  1180. component.blockData[offset + z] =
  1181. successiveACNextValue << successive;
  1182. successiveACState = 0;
  1183. }
  1184. break;
  1185. case 4: // eob
  1186. if (component.blockData[offset + z]) {
  1187. component.blockData[offset + z] += (readBit() << successive);
  1188. }
  1189. break;
  1190. }
  1191. k++;
  1192. }
  1193. if (successiveACState === 4) {
  1194. eobrun--;
  1195. if (eobrun === 0) {
  1196. successiveACState = 0;
  1197. }
  1198. }
  1199. }
  1200. function decodeMcu(component, decode, mcu, row, col) {
  1201. var mcuRow = (mcu / mcusPerLine) | 0;
  1202. var mcuCol = mcu % mcusPerLine;
  1203. var blockRow = mcuRow * component.v + row;
  1204. var blockCol = mcuCol * component.h + col;
  1205. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1206. decode(component, offset);
  1207. }
  1208. function decodeBlock(component, decode, mcu) {
  1209. var blockRow = (mcu / component.blocksPerLine) | 0;
  1210. var blockCol = mcu % component.blocksPerLine;
  1211. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1212. decode(component, offset);
  1213. }
  1214. var componentsLength = components.length;
  1215. var component, i, j, k, n;
  1216. var decodeFn;
  1217. if (progressive) {
  1218. if (spectralStart === 0) {
  1219. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  1220. } else {
  1221. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  1222. }
  1223. } else {
  1224. decodeFn = decodeBaseline;
  1225. }
  1226. var mcu = 0, marker;
  1227. var mcuExpected;
  1228. if (componentsLength === 1) {
  1229. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  1230. } else {
  1231. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  1232. }
  1233. if (!resetInterval) {
  1234. resetInterval = mcuExpected;
  1235. }
  1236. var h, v;
  1237. while (mcu < mcuExpected) {
  1238. // reset interval stuff
  1239. for (i = 0; i < componentsLength; i++) {
  1240. components[i].pred = 0;
  1241. }
  1242. eobrun = 0;
  1243. if (componentsLength === 1) {
  1244. component = components[0];
  1245. for (n = 0; n < resetInterval; n++) {
  1246. decodeBlock(component, decodeFn, mcu);
  1247. mcu++;
  1248. }
  1249. } else {
  1250. for (n = 0; n < resetInterval; n++) {
  1251. for (i = 0; i < componentsLength; i++) {
  1252. component = components[i];
  1253. h = component.h;
  1254. v = component.v;
  1255. for (j = 0; j < v; j++) {
  1256. for (k = 0; k < h; k++) {
  1257. decodeMcu(component, decodeFn, mcu, j, k);
  1258. }
  1259. }
  1260. }
  1261. mcu++;
  1262. }
  1263. }
  1264. // find marker
  1265. bitsCount = 0;
  1266. marker = (data[offset] << 8) | data[offset + 1];
  1267. if (marker <= 0xFF00) {
  1268. throw 'marker was not found';
  1269. }
  1270. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  1271. offset += 2;
  1272. } else {
  1273. break;
  1274. }
  1275. }
  1276. return offset - startOffset;
  1277. }
  1278. // A port of poppler's IDCT method which in turn is taken from:
  1279. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  1280. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  1281. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  1282. // 988-991.
  1283. function quantizeAndInverse(component, blockBufferOffset, p) {
  1284. var qt = component.quantizationTable, blockData = component.blockData;
  1285. var v0, v1, v2, v3, v4, v5, v6, v7;
  1286. var p0, p1, p2, p3, p4, p5, p6, p7;
  1287. var t;
  1288. // inverse DCT on rows
  1289. for (var row = 0; row < 64; row += 8) {
  1290. // gather block data
  1291. p0 = blockData[blockBufferOffset + row];
  1292. p1 = blockData[blockBufferOffset + row + 1];
  1293. p2 = blockData[blockBufferOffset + row + 2];
  1294. p3 = blockData[blockBufferOffset + row + 3];
  1295. p4 = blockData[blockBufferOffset + row + 4];
  1296. p5 = blockData[blockBufferOffset + row + 5];
  1297. p6 = blockData[blockBufferOffset + row + 6];
  1298. p7 = blockData[blockBufferOffset + row + 7];
  1299. // dequant p0
  1300. p0 *= qt[row];
  1301. // check for all-zero AC coefficients
  1302. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  1303. t = (dctSqrt2 * p0 + 512) >> 10;
  1304. p[row] = t;
  1305. p[row + 1] = t;
  1306. p[row + 2] = t;
  1307. p[row + 3] = t;
  1308. p[row + 4] = t;
  1309. p[row + 5] = t;
  1310. p[row + 6] = t;
  1311. p[row + 7] = t;
  1312. continue;
  1313. }
  1314. // dequant p1 ... p7
  1315. p1 *= qt[row + 1];
  1316. p2 *= qt[row + 2];
  1317. p3 *= qt[row + 3];
  1318. p4 *= qt[row + 4];
  1319. p5 *= qt[row + 5];
  1320. p6 *= qt[row + 6];
  1321. p7 *= qt[row + 7];
  1322. // stage 4
  1323. v0 = (dctSqrt2 * p0 + 128) >> 8;
  1324. v1 = (dctSqrt2 * p4 + 128) >> 8;
  1325. v2 = p2;
  1326. v3 = p6;
  1327. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  1328. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  1329. v5 = p3 << 4;
  1330. v6 = p5 << 4;
  1331. // stage 3
  1332. v0 = (v0 + v1 + 1) >> 1;
  1333. v1 = v0 - v1;
  1334. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  1335. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  1336. v3 = t;
  1337. v4 = (v4 + v6 + 1) >> 1;
  1338. v6 = v4 - v6;
  1339. v7 = (v7 + v5 + 1) >> 1;
  1340. v5 = v7 - v5;
  1341. // stage 2
  1342. v0 = (v0 + v3 + 1) >> 1;
  1343. v3 = v0 - v3;
  1344. v1 = (v1 + v2 + 1) >> 1;
  1345. v2 = v1 - v2;
  1346. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  1347. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  1348. v7 = t;
  1349. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  1350. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  1351. v6 = t;
  1352. // stage 1
  1353. p[row] = v0 + v7;
  1354. p[row + 7] = v0 - v7;
  1355. p[row + 1] = v1 + v6;
  1356. p[row + 6] = v1 - v6;
  1357. p[row + 2] = v2 + v5;
  1358. p[row + 5] = v2 - v5;
  1359. p[row + 3] = v3 + v4;
  1360. p[row + 4] = v3 - v4;
  1361. }
  1362. // inverse DCT on columns
  1363. for (var col = 0; col < 8; ++col) {
  1364. p0 = p[col];
  1365. p1 = p[col + 8];
  1366. p2 = p[col + 16];
  1367. p3 = p[col + 24];
  1368. p4 = p[col + 32];
  1369. p5 = p[col + 40];
  1370. p6 = p[col + 48];
  1371. p7 = p[col + 56];
  1372. // check for all-zero AC coefficients
  1373. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  1374. t = (dctSqrt2 * p0 + 8192) >> 14;
  1375. // convert to 8 bit
  1376. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  1377. blockData[blockBufferOffset + col] = t;
  1378. blockData[blockBufferOffset + col + 8] = t;
  1379. blockData[blockBufferOffset + col + 16] = t;
  1380. blockData[blockBufferOffset + col + 24] = t;
  1381. blockData[blockBufferOffset + col + 32] = t;
  1382. blockData[blockBufferOffset + col + 40] = t;
  1383. blockData[blockBufferOffset + col + 48] = t;
  1384. blockData[blockBufferOffset + col + 56] = t;
  1385. continue;
  1386. }
  1387. // stage 4
  1388. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  1389. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  1390. v2 = p2;
  1391. v3 = p6;
  1392. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  1393. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  1394. v5 = p3;
  1395. v6 = p5;
  1396. // stage 3
  1397. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  1398. // converting to UInt8 range later.
  1399. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  1400. v1 = v0 - v1;
  1401. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  1402. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  1403. v3 = t;
  1404. v4 = (v4 + v6 + 1) >> 1;
  1405. v6 = v4 - v6;
  1406. v7 = (v7 + v5 + 1) >> 1;
  1407. v5 = v7 - v5;
  1408. // stage 2
  1409. v0 = (v0 + v3 + 1) >> 1;
  1410. v3 = v0 - v3;
  1411. v1 = (v1 + v2 + 1) >> 1;
  1412. v2 = v1 - v2;
  1413. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  1414. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  1415. v7 = t;
  1416. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  1417. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  1418. v6 = t;
  1419. // stage 1
  1420. p0 = v0 + v7;
  1421. p7 = v0 - v7;
  1422. p1 = v1 + v6;
  1423. p6 = v1 - v6;
  1424. p2 = v2 + v5;
  1425. p5 = v2 - v5;
  1426. p3 = v3 + v4;
  1427. p4 = v3 - v4;
  1428. // convert to 8-bit integers
  1429. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  1430. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  1431. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  1432. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  1433. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  1434. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  1435. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  1436. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  1437. // store block data
  1438. blockData[blockBufferOffset + col] = p0;
  1439. blockData[blockBufferOffset + col + 8] = p1;
  1440. blockData[blockBufferOffset + col + 16] = p2;
  1441. blockData[blockBufferOffset + col + 24] = p3;
  1442. blockData[blockBufferOffset + col + 32] = p4;
  1443. blockData[blockBufferOffset + col + 40] = p5;
  1444. blockData[blockBufferOffset + col + 48] = p6;
  1445. blockData[blockBufferOffset + col + 56] = p7;
  1446. }
  1447. }
  1448. function buildComponentData(frame, component) {
  1449. var blocksPerLine = component.blocksPerLine;
  1450. var blocksPerColumn = component.blocksPerColumn;
  1451. var computationBuffer = new Int16Array(64);
  1452. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  1453. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  1454. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1455. quantizeAndInverse(component, offset, computationBuffer);
  1456. }
  1457. }
  1458. return component.blockData;
  1459. }
  1460. function clamp0to255(a) {
  1461. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  1462. }
  1463. constructor.prototype = {
  1464. parse: function parse(data) {
  1465. function readUint16() {
  1466. var value = (data[offset] << 8) | data[offset + 1];
  1467. offset += 2;
  1468. return value;
  1469. }
  1470. function readDataBlock() {
  1471. var length = readUint16();
  1472. var array = data.subarray(offset, offset + length - 2);
  1473. offset += array.length;
  1474. return array;
  1475. }
  1476. function prepareComponents(frame) {
  1477. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  1478. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  1479. for (var i = 0; i < frame.components.length; i++) {
  1480. component = frame.components[i];
  1481. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  1482. component.h / frame.maxH);
  1483. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  1484. component.v / frame.maxV);
  1485. var blocksPerLineForMcu = mcusPerLine * component.h;
  1486. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  1487. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  1488. (blocksPerLineForMcu + 1);
  1489. component.blockData = new Int16Array(blocksBufferSize);
  1490. component.blocksPerLine = blocksPerLine;
  1491. component.blocksPerColumn = blocksPerColumn;
  1492. }
  1493. frame.mcusPerLine = mcusPerLine;
  1494. frame.mcusPerColumn = mcusPerColumn;
  1495. }
  1496. var offset = 0;
  1497. var jfif = null;
  1498. var adobe = null;
  1499. var frame, resetInterval;
  1500. var quantizationTables = [];
  1501. var huffmanTablesAC = [], huffmanTablesDC = [];
  1502. var fileMarker = readUint16();
  1503. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  1504. throw 'SOI not found';
  1505. }
  1506. fileMarker = readUint16();
  1507. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  1508. var i, j, l;
  1509. switch(fileMarker) {
  1510. case 0xFFE0: // APP0 (Application Specific)
  1511. case 0xFFE1: // APP1
  1512. case 0xFFE2: // APP2
  1513. case 0xFFE3: // APP3
  1514. case 0xFFE4: // APP4
  1515. case 0xFFE5: // APP5
  1516. case 0xFFE6: // APP6
  1517. case 0xFFE7: // APP7
  1518. case 0xFFE8: // APP8
  1519. case 0xFFE9: // APP9
  1520. case 0xFFEA: // APP10
  1521. case 0xFFEB: // APP11
  1522. case 0xFFEC: // APP12
  1523. case 0xFFED: // APP13
  1524. case 0xFFEE: // APP14
  1525. case 0xFFEF: // APP15
  1526. case 0xFFFE: // COM (Comment)
  1527. var appData = readDataBlock();
  1528. if (fileMarker === 0xFFE0) {
  1529. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  1530. appData[2] === 0x49 && appData[3] === 0x46 &&
  1531. appData[4] === 0) { // 'JFIF\x00'
  1532. jfif = {
  1533. version: { major: appData[5], minor: appData[6] },
  1534. densityUnits: appData[7],
  1535. xDensity: (appData[8] << 8) | appData[9],
  1536. yDensity: (appData[10] << 8) | appData[11],
  1537. thumbWidth: appData[12],
  1538. thumbHeight: appData[13],
  1539. thumbData: appData.subarray(14, 14 +
  1540. 3 * appData[12] * appData[13])
  1541. };
  1542. }
  1543. }
  1544. // TODO APP1 - Exif
  1545. if (fileMarker === 0xFFEE) {
  1546. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  1547. appData[2] === 0x6F && appData[3] === 0x62 &&
  1548. appData[4] === 0x65) { // 'Adobe'
  1549. adobe = {
  1550. version: (appData[5] << 8) | appData[6],
  1551. flags0: (appData[7] << 8) | appData[8],
  1552. flags1: (appData[9] << 8) | appData[10],
  1553. transformCode: appData[11]
  1554. };
  1555. }
  1556. }
  1557. break;
  1558. case 0xFFDB: // DQT (Define Quantization Tables)
  1559. var quantizationTablesLength = readUint16();
  1560. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  1561. var z;
  1562. while (offset < quantizationTablesEnd) {
  1563. var quantizationTableSpec = data[offset++];
  1564. var tableData = new Uint16Array(64);
  1565. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  1566. for (j = 0; j < 64; j++) {
  1567. z = dctZigZag[j];
  1568. tableData[z] = data[offset++];
  1569. }
  1570. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  1571. for (j = 0; j < 64; j++) {
  1572. z = dctZigZag[j];
  1573. tableData[z] = readUint16();
  1574. }
  1575. } else {
  1576. throw 'DQT: invalid table spec';
  1577. }
  1578. quantizationTables[quantizationTableSpec & 15] = tableData;
  1579. }
  1580. break;
  1581. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  1582. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  1583. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  1584. if (frame) {
  1585. throw 'Only single frame JPEGs supported';
  1586. }
  1587. readUint16(); // skip data length
  1588. frame = {};
  1589. frame.extended = (fileMarker === 0xFFC1);
  1590. frame.progressive = (fileMarker === 0xFFC2);
  1591. frame.precision = data[offset++];
  1592. frame.scanLines = readUint16();
  1593. frame.samplesPerLine = readUint16();
  1594. frame.components = [];
  1595. frame.componentIds = {};
  1596. var componentsCount = data[offset++], componentId;
  1597. var maxH = 0, maxV = 0;
  1598. for (i = 0; i < componentsCount; i++) {
  1599. componentId = data[offset];
  1600. var h = data[offset + 1] >> 4;
  1601. var v = data[offset + 1] & 15;
  1602. if (maxH < h) {
  1603. maxH = h;
  1604. }
  1605. if (maxV < v) {
  1606. maxV = v;
  1607. }
  1608. var qId = data[offset + 2];
  1609. l = frame.components.push({
  1610. h: h,
  1611. v: v,
  1612. quantizationTable: quantizationTables[qId]
  1613. });
  1614. frame.componentIds[componentId] = l - 1;
  1615. offset += 3;
  1616. }
  1617. frame.maxH = maxH;
  1618. frame.maxV = maxV;
  1619. prepareComponents(frame);
  1620. break;
  1621. case 0xFFC4: // DHT (Define Huffman Tables)
  1622. var huffmanLength = readUint16();
  1623. for (i = 2; i < huffmanLength;) {
  1624. var huffmanTableSpec = data[offset++];
  1625. var codeLengths = new Uint8Array(16);
  1626. var codeLengthSum = 0;
  1627. for (j = 0; j < 16; j++, offset++) {
  1628. codeLengthSum += (codeLengths[j] = data[offset]);
  1629. }
  1630. var huffmanValues = new Uint8Array(codeLengthSum);
  1631. for (j = 0; j < codeLengthSum; j++, offset++) {
  1632. huffmanValues[j] = data[offset];
  1633. }
  1634. i += 17 + codeLengthSum;
  1635. ((huffmanTableSpec >> 4) === 0 ?
  1636. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  1637. buildHuffmanTable(codeLengths, huffmanValues);
  1638. }
  1639. break;
  1640. case 0xFFDD: // DRI (Define Restart Interval)
  1641. readUint16(); // skip data length
  1642. resetInterval = readUint16();
  1643. break;
  1644. case 0xFFDA: // SOS (Start of Scan)
  1645. var scanLength = readUint16();
  1646. var selectorsCount = data[offset++];
  1647. var components = [], component;
  1648. for (i = 0; i < selectorsCount; i++) {
  1649. var componentIndex = frame.componentIds[data[offset++]];
  1650. component = frame.components[componentIndex];
  1651. var tableSpec = data[offset++];
  1652. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  1653. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  1654. components.push(component);
  1655. }
  1656. var spectralStart = data[offset++];
  1657. var spectralEnd = data[offset++];
  1658. var successiveApproximation = data[offset++];
  1659. var processed = decodeScan(data, offset,
  1660. frame, components, resetInterval,
  1661. spectralStart, spectralEnd,
  1662. successiveApproximation >> 4, successiveApproximation & 15);
  1663. offset += processed;
  1664. break;
  1665. case 0xFFFF: // Fill bytes
  1666. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  1667. offset--;
  1668. }
  1669. break;
  1670. default:
  1671. if (data[offset - 3] === 0xFF &&
  1672. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  1673. // could be incorrect encoding -- last 0xFF byte of the previous
  1674. // block was eaten by the encoder
  1675. offset -= 3;
  1676. break;
  1677. }
  1678. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  1679. }
  1680. fileMarker = readUint16();
  1681. }
  1682. this.width = frame.samplesPerLine;
  1683. this.height = frame.scanLines;
  1684. this.jfif = jfif;
  1685. this.adobe = adobe;
  1686. this.components = [];
  1687. for (i = 0; i < frame.components.length; i++) {
  1688. component = frame.components[i];
  1689. this.components.push({
  1690. output: buildComponentData(frame, component),
  1691. scaleX: component.h / frame.maxH,
  1692. scaleY: component.v / frame.maxV,
  1693. blocksPerLine: component.blocksPerLine,
  1694. blocksPerColumn: component.blocksPerColumn
  1695. });
  1696. }
  1697. this.numComponents = this.components.length;
  1698. },
  1699. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  1700. var scaleX = this.width / width, scaleY = this.height / height;
  1701. var component, componentScaleX, componentScaleY, blocksPerScanline;
  1702. var x, y, i, j, k;
  1703. var index;
  1704. var offset = 0;
  1705. var output;
  1706. var numComponents = this.components.length;
  1707. var dataLength = width * height * numComponents;
  1708. var data = new Uint8Array(dataLength);
  1709. var xScaleBlockOffset = new Uint32Array(width);
  1710. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  1711. for (i = 0; i < numComponents; i++) {
  1712. component = this.components[i];
  1713. componentScaleX = component.scaleX * scaleX;
  1714. componentScaleY = component.scaleY * scaleY;
  1715. offset = i;
  1716. output = component.output;
  1717. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  1718. // precalculate the xScaleBlockOffset
  1719. for (x = 0; x < width; x++) {
  1720. j = 0 | (x * componentScaleX);
  1721. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  1722. }
  1723. // linearize the blocks of the component
  1724. for (y = 0; y < height; y++) {
  1725. j = 0 | (y * componentScaleY);
  1726. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  1727. for (x = 0; x < width; x++) {
  1728. data[offset] = output[index + xScaleBlockOffset[x]];
  1729. offset += numComponents;
  1730. }
  1731. }
  1732. }
  1733. // decodeTransform contains pairs of multiplier (-256..256) and additive
  1734. var transform = this.decodeTransform;
  1735. if (transform) {
  1736. for (i = 0; i < dataLength;) {
  1737. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  1738. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  1739. }
  1740. }
  1741. }
  1742. return data;
  1743. },
  1744. _isColorConversionNeeded: function isColorConversionNeeded() {
  1745. if (this.adobe && this.adobe.transformCode) {
  1746. // The adobe transform marker overrides any previous setting
  1747. return true;
  1748. } else if (this.numComponents === 3) {
  1749. return true;
  1750. } else {
  1751. return false;
  1752. }
  1753. },
  1754. _convertYccToRgb: function convertYccToRgb(data) {
  1755. var Y, Cb, Cr;
  1756. for (var i = 0, length = data.length; i < length; i += 3) {
  1757. Y = data[i ];
  1758. Cb = data[i + 1];
  1759. Cr = data[i + 2];
  1760. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  1761. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  1762. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  1763. }
  1764. return data;
  1765. },
  1766. _convertYcckToRgb: function convertYcckToRgb(data) {
  1767. var Y, Cb, Cr, k;
  1768. var offset = 0;
  1769. for (var i = 0, length = data.length; i < length; i += 4) {
  1770. Y = data[i];
  1771. Cb = data[i + 1];
  1772. Cr = data[i + 2];
  1773. k = data[i + 3];
  1774. var r = -122.67195406894 +
  1775. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  1776. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  1777. 0.154362151871126) +
  1778. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  1779. 0.00477271405408747 * k + 1.53380253221734) +
  1780. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  1781. 0.48357088451265) +
  1782. k * (-0.000336197177618394 * k + 0.484791561490776);
  1783. var g = 107.268039397724 +
  1784. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  1785. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  1786. 0.176491792462875) +
  1787. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  1788. 0.000770482631801132 * k - 0.151051492775562) +
  1789. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  1790. 0.25802910206845) +
  1791. k * (-0.000318913117588328 * k - 0.213742400323665);
  1792. var b = -20.810012546947 +
  1793. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  1794. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  1795. 0.814272968359295) +
  1796. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  1797. 0.000560833691242812 * k - 0.195152027534049) +
  1798. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  1799. 0.116935020465145) +
  1800. k * (-0.000343531996510555 * k + 0.24165260232407);
  1801. data[offset++] = clamp0to255(r);
  1802. data[offset++] = clamp0to255(g);
  1803. data[offset++] = clamp0to255(b);
  1804. }
  1805. return data;
  1806. },
  1807. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  1808. var Y, Cb, Cr;
  1809. for (var i = 0, length = data.length; i < length; i += 4) {
  1810. Y = data[i];
  1811. Cb = data[i + 1];
  1812. Cr = data[i + 2];
  1813. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  1814. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  1815. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  1816. // K in data[i + 3] is unchanged
  1817. }
  1818. return data;
  1819. },
  1820. _convertCmykToRgb: function convertCmykToRgb(data) {
  1821. var c, m, y, k;
  1822. var offset = 0;
  1823. var min = -255 * 255 * 255;
  1824. var scale = 1 / 255 / 255;
  1825. for (var i = 0, length = data.length; i < length; i += 4) {
  1826. c = data[i];
  1827. m = data[i + 1];
  1828. y = data[i + 2];
  1829. k = data[i + 3];
  1830. var r =
  1831. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  1832. 18.82290502165302 * y + 212.25662451639585 * k -
  1833. 72734.4411664936) +
  1834. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  1835. 17.873870861415444 * k - 1401.7366389350734) +
  1836. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  1837. 4465.541406466231) -
  1838. k * (21.86122147463605 * k + 48317.86113160301);
  1839. var g =
  1840. c * (8.841041422036149 * c + 60.118027045597366 * m +
  1841. 6.871425592049007 * y + 31.159100130055922 * k -
  1842. 20220.756542821975) +
  1843. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  1844. 131.35250912493976 * k - 48691.05921601825) +
  1845. y * (4.444339102852739 * y + 9.8632861493405 * k -
  1846. 6341.191035517494) -
  1847. k * (20.737325471181034 * k + 47890.15695978492);
  1848. var b =
  1849. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  1850. 30.89978309703729 * y - 0.23883238689178934 * k -
  1851. 3616.812083916688) +
  1852. m * (10.49593273432072 * m + 63.02378494754052 * y +
  1853. 50.606957656360734 * k - 28620.90484698408) +
  1854. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  1855. 49363.43385999684) -
  1856. k * (22.33816807309886 * k + 45932.16563550634);
  1857. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  1858. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  1859. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  1860. }
  1861. return data;
  1862. },
  1863. getData: function getData(width, height, forceRGBoutput) {
  1864. if (this.numComponents > 4) {
  1865. throw 'Unsupported color mode';
  1866. }
  1867. // type of data: Uint8Array(width * height * numComponents)
  1868. var data = this._getLinearizedBlockData(width, height);
  1869. if (this.numComponents === 1 && forceRGBoutput) {
  1870. var dataLength = data.length;
  1871. var rgbData = new Uint8Array(dataLength * 3);
  1872. var offset = 0;
  1873. for (var i = 0; i < dataLength; i++) {
  1874. var grayColor = data[i];
  1875. rgbData[offset++] = grayColor;
  1876. rgbData[offset++] = grayColor;
  1877. rgbData[offset++] = grayColor;
  1878. }
  1879. return rgbData;
  1880. } else if (this.numComponents === 3) {
  1881. return this._convertYccToRgb(data);
  1882. } else if (this.numComponents === 4) {
  1883. if (this._isColorConversionNeeded()) {
  1884. if (forceRGBoutput) {
  1885. return this._convertYcckToRgb(data);
  1886. } else {
  1887. return this._convertYcckToCmyk(data);
  1888. }
  1889. } else if (forceRGBoutput) {
  1890. return this._convertCmykToRgb(data);
  1891. }
  1892. }
  1893. return data;
  1894. }
  1895. };
  1896. return constructor;
  1897. })();
  1898. exports.JpegImage = JpegImage;
  1899. }));
  1900. (function (root, factory) {
  1901. {
  1902. factory((root.pdfjsSharedUtil = {}));
  1903. }
  1904. }(this, function (exports) {
  1905. var globalScope = (typeof window !== 'undefined') ? window :
  1906. (typeof global !== 'undefined') ? global :
  1907. (typeof self !== 'undefined') ? self : this;
  1908. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  1909. var TextRenderingMode = {
  1910. FILL: 0,
  1911. STROKE: 1,
  1912. FILL_STROKE: 2,
  1913. INVISIBLE: 3,
  1914. FILL_ADD_TO_PATH: 4,
  1915. STROKE_ADD_TO_PATH: 5,
  1916. FILL_STROKE_ADD_TO_PATH: 6,
  1917. ADD_TO_PATH: 7,
  1918. FILL_STROKE_MASK: 3,
  1919. ADD_TO_PATH_FLAG: 4
  1920. };
  1921. var ImageKind = {
  1922. GRAYSCALE_1BPP: 1,
  1923. RGB_24BPP: 2,
  1924. RGBA_32BPP: 3
  1925. };
  1926. var AnnotationType = {
  1927. TEXT: 1,
  1928. LINK: 2,
  1929. FREETEXT: 3,
  1930. LINE: 4,
  1931. SQUARE: 5,
  1932. CIRCLE: 6,
  1933. POLYGON: 7,
  1934. POLYLINE: 8,
  1935. HIGHLIGHT: 9,
  1936. UNDERLINE: 10,
  1937. SQUIGGLY: 11,
  1938. STRIKEOUT: 12,
  1939. STAMP: 13,
  1940. CARET: 14,
  1941. INK: 15,
  1942. POPUP: 16,
  1943. FILEATTACHMENT: 17,
  1944. SOUND: 18,
  1945. MOVIE: 19,
  1946. WIDGET: 20,
  1947. SCREEN: 21,
  1948. PRINTERMARK: 22,
  1949. TRAPNET: 23,
  1950. WATERMARK: 24,
  1951. THREED: 25,
  1952. REDACT: 26
  1953. };
  1954. var AnnotationFlag = {
  1955. INVISIBLE: 0x01,
  1956. HIDDEN: 0x02,
  1957. PRINT: 0x04,
  1958. NOZOOM: 0x08,
  1959. NOROTATE: 0x10,
  1960. NOVIEW: 0x20,
  1961. READONLY: 0x40,
  1962. LOCKED: 0x80,
  1963. TOGGLENOVIEW: 0x100,
  1964. LOCKEDCONTENTS: 0x200
  1965. };
  1966. var AnnotationBorderStyleType = {
  1967. SOLID: 1,
  1968. DASHED: 2,
  1969. BEVELED: 3,
  1970. INSET: 4,
  1971. UNDERLINE: 5
  1972. };
  1973. var StreamType = {
  1974. UNKNOWN: 0,
  1975. FLATE: 1,
  1976. LZW: 2,
  1977. DCT: 3,
  1978. JPX: 4,
  1979. JBIG: 5,
  1980. A85: 6,
  1981. AHX: 7,
  1982. CCF: 8,
  1983. RL: 9
  1984. };
  1985. var FontType = {
  1986. UNKNOWN: 0,
  1987. TYPE1: 1,
  1988. TYPE1C: 2,
  1989. CIDFONTTYPE0: 3,
  1990. CIDFONTTYPE0C: 4,
  1991. TRUETYPE: 5,
  1992. CIDFONTTYPE2: 6,
  1993. TYPE3: 7,
  1994. OPENTYPE: 8,
  1995. TYPE0: 9,
  1996. MMTYPE1: 10
  1997. };
  1998. var VERBOSITY_LEVELS = {
  1999. errors: 0,
  2000. warnings: 1,
  2001. infos: 5
  2002. };
  2003. // All the possible operations for an operator list.
  2004. var OPS = {
  2005. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2006. // 0's.
  2007. dependency: 1,
  2008. setLineWidth: 2,
  2009. setLineCap: 3,
  2010. setLineJoin: 4,
  2011. setMiterLimit: 5,
  2012. setDash: 6,
  2013. setRenderingIntent: 7,
  2014. setFlatness: 8,
  2015. setGState: 9,
  2016. save: 10,
  2017. restore: 11,
  2018. transform: 12,
  2019. moveTo: 13,
  2020. lineTo: 14,
  2021. curveTo: 15,
  2022. curveTo2: 16,
  2023. curveTo3: 17,
  2024. closePath: 18,
  2025. rectangle: 19,
  2026. stroke: 20,
  2027. closeStroke: 21,
  2028. fill: 22,
  2029. eoFill: 23,
  2030. fillStroke: 24,
  2031. eoFillStroke: 25,
  2032. closeFillStroke: 26,
  2033. closeEOFillStroke: 27,
  2034. endPath: 28,
  2035. clip: 29,
  2036. eoClip: 30,
  2037. beginText: 31,
  2038. endText: 32,
  2039. setCharSpacing: 33,
  2040. setWordSpacing: 34,
  2041. setHScale: 35,
  2042. setLeading: 36,
  2043. setFont: 37,
  2044. setTextRenderingMode: 38,
  2045. setTextRise: 39,
  2046. moveText: 40,
  2047. setLeadingMoveText: 41,
  2048. setTextMatrix: 42,
  2049. nextLine: 43,
  2050. showText: 44,
  2051. showSpacedText: 45,
  2052. nextLineShowText: 46,
  2053. nextLineSetSpacingShowText: 47,
  2054. setCharWidth: 48,
  2055. setCharWidthAndBounds: 49,
  2056. setStrokeColorSpace: 50,
  2057. setFillColorSpace: 51,
  2058. setStrokeColor: 52,
  2059. setStrokeColorN: 53,
  2060. setFillColor: 54,
  2061. setFillColorN: 55,
  2062. setStrokeGray: 56,
  2063. setFillGray: 57,
  2064. setStrokeRGBColor: 58,
  2065. setFillRGBColor: 59,
  2066. setStrokeCMYKColor: 60,
  2067. setFillCMYKColor: 61,
  2068. shadingFill: 62,
  2069. beginInlineImage: 63,
  2070. beginImageData: 64,
  2071. endInlineImage: 65,
  2072. paintXObject: 66,
  2073. markPoint: 67,
  2074. markPointProps: 68,
  2075. beginMarkedContent: 69,
  2076. beginMarkedContentProps: 70,
  2077. endMarkedContent: 71,
  2078. beginCompat: 72,
  2079. endCompat: 73,
  2080. paintFormXObjectBegin: 74,
  2081. paintFormXObjectEnd: 75,
  2082. beginGroup: 76,
  2083. endGroup: 77,
  2084. beginAnnotations: 78,
  2085. endAnnotations: 79,
  2086. beginAnnotation: 80,
  2087. endAnnotation: 81,
  2088. paintJpegXObject: 82,
  2089. paintImageMaskXObject: 83,
  2090. paintImageMaskXObjectGroup: 84,
  2091. paintImageXObject: 85,
  2092. paintInlineImageXObject: 86,
  2093. paintInlineImageXObjectGroup: 87,
  2094. paintImageXObjectRepeat: 88,
  2095. paintImageMaskXObjectRepeat: 89,
  2096. paintSolidColorImageMask: 90,
  2097. constructPath: 91
  2098. };
  2099. var verbosity = VERBOSITY_LEVELS.warnings;
  2100. function setVerbosityLevel(level) {
  2101. verbosity = level;
  2102. }
  2103. function getVerbosityLevel() {
  2104. return verbosity;
  2105. }
  2106. // A notice for devs. These are good for things that are helpful to devs, such
  2107. // as warning that Workers were disabled, which is important to devs but not
  2108. // end users.
  2109. function info(msg) {
  2110. if (verbosity >= VERBOSITY_LEVELS.infos) {
  2111. console.log('Info: ' + msg);
  2112. }
  2113. }
  2114. // Non-fatal warnings.
  2115. function warn(msg) {
  2116. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  2117. console.log('Warning: ' + msg);
  2118. }
  2119. }
  2120. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2121. function deprecated(details) {
  2122. console.log('Deprecated API usage: ' + details);
  2123. }
  2124. // Fatal errors that should trigger the fallback UI and halt execution by
  2125. // throwing an exception.
  2126. function error(msg) {
  2127. if (verbosity >= VERBOSITY_LEVELS.errors) {
  2128. console.log('Error: ' + msg);
  2129. console.log(backtrace());
  2130. }
  2131. throw new Error(msg);
  2132. }
  2133. function backtrace() {
  2134. try {
  2135. throw new Error();
  2136. } catch (e) {
  2137. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2138. }
  2139. }
  2140. function assert(cond, msg) {
  2141. if (!cond) {
  2142. error(msg);
  2143. }
  2144. }
  2145. var UNSUPPORTED_FEATURES = {
  2146. unknown: 'unknown',
  2147. forms: 'forms',
  2148. javaScript: 'javaScript',
  2149. smask: 'smask',
  2150. shadingPattern: 'shadingPattern',
  2151. font: 'font'
  2152. };
  2153. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2154. function isSameOrigin(baseUrl, otherUrl) {
  2155. try {
  2156. var base = new URL(baseUrl);
  2157. if (!base.origin || base.origin === 'null') {
  2158. return false; // non-HTTP url
  2159. }
  2160. } catch (e) {
  2161. return false;
  2162. }
  2163. var other = new URL(otherUrl, base);
  2164. return base.origin === other.origin;
  2165. }
  2166. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2167. function isValidUrl(url, allowRelative) {
  2168. if (!url || typeof url !== 'string') {
  2169. return false;
  2170. }
  2171. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2172. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2173. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2174. if (!protocol) {
  2175. return allowRelative;
  2176. }
  2177. protocol = protocol[0].toLowerCase();
  2178. switch (protocol) {
  2179. case 'http':
  2180. case 'https':
  2181. case 'ftp':
  2182. case 'mailto':
  2183. case 'tel':
  2184. return true;
  2185. default:
  2186. return false;
  2187. }
  2188. }
  2189. function shadow(obj, prop, value) {
  2190. Object.defineProperty(obj, prop, { value: value,
  2191. enumerable: true,
  2192. configurable: true,
  2193. writable: false });
  2194. return value;
  2195. }
  2196. function getLookupTableFactory(initializer) {
  2197. var lookup;
  2198. return function () {
  2199. if (initializer) {
  2200. lookup = Object.create(null);
  2201. initializer(lookup);
  2202. initializer = null;
  2203. }
  2204. return lookup;
  2205. };
  2206. }
  2207. var PasswordResponses = {
  2208. NEED_PASSWORD: 1,
  2209. INCORRECT_PASSWORD: 2
  2210. };
  2211. var PasswordException = (function PasswordExceptionClosure() {
  2212. function PasswordException(msg, code) {
  2213. this.name = 'PasswordException';
  2214. this.message = msg;
  2215. this.code = code;
  2216. }
  2217. PasswordException.prototype = new Error();
  2218. PasswordException.constructor = PasswordException;
  2219. return PasswordException;
  2220. })();
  2221. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2222. function UnknownErrorException(msg, details) {
  2223. this.name = 'UnknownErrorException';
  2224. this.message = msg;
  2225. this.details = details;
  2226. }
  2227. UnknownErrorException.prototype = new Error();
  2228. UnknownErrorException.constructor = UnknownErrorException;
  2229. return UnknownErrorException;
  2230. })();
  2231. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2232. function InvalidPDFException(msg) {
  2233. this.name = 'InvalidPDFException';
  2234. this.message = msg;
  2235. }
  2236. InvalidPDFException.prototype = new Error();
  2237. InvalidPDFException.constructor = InvalidPDFException;
  2238. return InvalidPDFException;
  2239. })();
  2240. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2241. function MissingPDFException(msg) {
  2242. this.name = 'MissingPDFException';
  2243. this.message = msg;
  2244. }
  2245. MissingPDFException.prototype = new Error();
  2246. MissingPDFException.constructor = MissingPDFException;
  2247. return MissingPDFException;
  2248. })();
  2249. var UnexpectedResponseException =
  2250. (function UnexpectedResponseExceptionClosure() {
  2251. function UnexpectedResponseException(msg, status) {
  2252. this.name = 'UnexpectedResponseException';
  2253. this.message = msg;
  2254. this.status = status;
  2255. }
  2256. UnexpectedResponseException.prototype = new Error();
  2257. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2258. return UnexpectedResponseException;
  2259. })();
  2260. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2261. function NotImplementedException(msg) {
  2262. this.message = msg;
  2263. }
  2264. NotImplementedException.prototype = new Error();
  2265. NotImplementedException.prototype.name = 'NotImplementedException';
  2266. NotImplementedException.constructor = NotImplementedException;
  2267. return NotImplementedException;
  2268. })();
  2269. var MissingDataException = (function MissingDataExceptionClosure() {
  2270. function MissingDataException(begin, end) {
  2271. this.begin = begin;
  2272. this.end = end;
  2273. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2274. }
  2275. MissingDataException.prototype = new Error();
  2276. MissingDataException.prototype.name = 'MissingDataException';
  2277. MissingDataException.constructor = MissingDataException;
  2278. return MissingDataException;
  2279. })();
  2280. var XRefParseException = (function XRefParseExceptionClosure() {
  2281. function XRefParseException(msg) {
  2282. this.message = msg;
  2283. }
  2284. XRefParseException.prototype = new Error();
  2285. XRefParseException.prototype.name = 'XRefParseException';
  2286. XRefParseException.constructor = XRefParseException;
  2287. return XRefParseException;
  2288. })();
  2289. var NullCharactersRegExp = /\x00/g;
  2290. function removeNullCharacters(str) {
  2291. if (typeof str !== 'string') {
  2292. warn('The argument for removeNullCharacters must be a string.');
  2293. return str;
  2294. }
  2295. return str.replace(NullCharactersRegExp, '');
  2296. }
  2297. function bytesToString(bytes) {
  2298. assert(bytes !== null && typeof bytes === 'object' &&
  2299. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2300. var length = bytes.length;
  2301. var MAX_ARGUMENT_COUNT = 8192;
  2302. if (length < MAX_ARGUMENT_COUNT) {
  2303. return String.fromCharCode.apply(null, bytes);
  2304. }
  2305. var strBuf = [];
  2306. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2307. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2308. var chunk = bytes.subarray(i, chunkEnd);
  2309. strBuf.push(String.fromCharCode.apply(null, chunk));
  2310. }
  2311. return strBuf.join('');
  2312. }
  2313. function stringToBytes(str) {
  2314. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2315. var length = str.length;
  2316. var bytes = new Uint8Array(length);
  2317. for (var i = 0; i < length; ++i) {
  2318. bytes[i] = str.charCodeAt(i) & 0xFF;
  2319. }
  2320. return bytes;
  2321. }
  2322. /**
  2323. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  2324. * @param {Array|Uint8Array|string} arr
  2325. * @returns {number}
  2326. */
  2327. function arrayByteLength(arr) {
  2328. if (arr.length !== undefined) {
  2329. return arr.length;
  2330. }
  2331. assert(arr.byteLength !== undefined);
  2332. return arr.byteLength;
  2333. }
  2334. /**
  2335. * Combines array items (arrays) into single Uint8Array object.
  2336. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  2337. * @returns {Uint8Array}
  2338. */
  2339. function arraysToBytes(arr) {
  2340. // Shortcut: if first and only item is Uint8Array, return it.
  2341. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  2342. return arr[0];
  2343. }
  2344. var resultLength = 0;
  2345. var i, ii = arr.length;
  2346. var item, itemLength ;
  2347. for (i = 0; i < ii; i++) {
  2348. item = arr[i];
  2349. itemLength = arrayByteLength(item);
  2350. resultLength += itemLength;
  2351. }
  2352. var pos = 0;
  2353. var data = new Uint8Array(resultLength);
  2354. for (i = 0; i < ii; i++) {
  2355. item = arr[i];
  2356. if (!(item instanceof Uint8Array)) {
  2357. if (typeof item === 'string') {
  2358. item = stringToBytes(item);
  2359. } else {
  2360. item = new Uint8Array(item);
  2361. }
  2362. }
  2363. itemLength = item.byteLength;
  2364. data.set(item, pos);
  2365. pos += itemLength;
  2366. }
  2367. return data;
  2368. }
  2369. function string32(value) {
  2370. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2371. (value >> 8) & 0xff, value & 0xff);
  2372. }
  2373. function log2(x) {
  2374. var n = 1, i = 0;
  2375. while (x > n) {
  2376. n <<= 1;
  2377. i++;
  2378. }
  2379. return i;
  2380. }
  2381. function readInt8(data, start) {
  2382. return (data[start] << 24) >> 24;
  2383. }
  2384. function readUint16(data, offset) {
  2385. return (data[offset] << 8) | data[offset + 1];
  2386. }
  2387. function readUint32(data, offset) {
  2388. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2389. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2390. }
  2391. // Lazy test the endianness of the platform
  2392. // NOTE: This will be 'true' for simulated TypedArrays
  2393. function isLittleEndian() {
  2394. var buffer8 = new Uint8Array(2);
  2395. buffer8[0] = 1;
  2396. var buffer16 = new Uint16Array(buffer8.buffer);
  2397. return (buffer16[0] === 1);
  2398. }
  2399. // Checks if it's possible to eval JS expressions.
  2400. function isEvalSupported() {
  2401. try {
  2402. /* jshint evil: true */
  2403. new Function('');
  2404. return true;
  2405. } catch (e) {
  2406. return false;
  2407. }
  2408. }
  2409. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2410. function Uint32ArrayView(buffer, length) {
  2411. this.buffer = buffer;
  2412. this.byteLength = buffer.length;
  2413. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2414. ensureUint32ArrayViewProps(this.length);
  2415. }
  2416. Uint32ArrayView.prototype = Object.create(null);
  2417. var uint32ArrayViewSetters = 0;
  2418. function createUint32ArrayProp(index) {
  2419. return {
  2420. get: function () {
  2421. var buffer = this.buffer, offset = index << 2;
  2422. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2423. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2424. },
  2425. set: function (value) {
  2426. var buffer = this.buffer, offset = index << 2;
  2427. buffer[offset] = value & 255;
  2428. buffer[offset + 1] = (value >> 8) & 255;
  2429. buffer[offset + 2] = (value >> 16) & 255;
  2430. buffer[offset + 3] = (value >>> 24) & 255;
  2431. }
  2432. };
  2433. }
  2434. function ensureUint32ArrayViewProps(length) {
  2435. while (uint32ArrayViewSetters < length) {
  2436. Object.defineProperty(Uint32ArrayView.prototype,
  2437. uint32ArrayViewSetters,
  2438. createUint32ArrayProp(uint32ArrayViewSetters));
  2439. uint32ArrayViewSetters++;
  2440. }
  2441. }
  2442. return Uint32ArrayView;
  2443. })();
  2444. exports.Uint32ArrayView = Uint32ArrayView;
  2445. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2446. var Util = (function UtilClosure() {
  2447. function Util() {}
  2448. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2449. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2450. // creating many intermediate strings.
  2451. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2452. rgbBuf[1] = r;
  2453. rgbBuf[3] = g;
  2454. rgbBuf[5] = b;
  2455. return rgbBuf.join('');
  2456. };
  2457. // Concatenates two transformation matrices together and returns the result.
  2458. Util.transform = function Util_transform(m1, m2) {
  2459. return [
  2460. m1[0] * m2[0] + m1[2] * m2[1],
  2461. m1[1] * m2[0] + m1[3] * m2[1],
  2462. m1[0] * m2[2] + m1[2] * m2[3],
  2463. m1[1] * m2[2] + m1[3] * m2[3],
  2464. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2465. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2466. ];
  2467. };
  2468. // For 2d affine transforms
  2469. Util.applyTransform = function Util_applyTransform(p, m) {
  2470. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2471. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2472. return [xt, yt];
  2473. };
  2474. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2475. var d = m[0] * m[3] - m[1] * m[2];
  2476. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2477. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2478. return [xt, yt];
  2479. };
  2480. // Applies the transform to the rectangle and finds the minimum axially
  2481. // aligned bounding box.
  2482. Util.getAxialAlignedBoundingBox =
  2483. function Util_getAxialAlignedBoundingBox(r, m) {
  2484. var p1 = Util.applyTransform(r, m);
  2485. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2486. var p3 = Util.applyTransform([r[0], r[3]], m);
  2487. var p4 = Util.applyTransform([r[2], r[1]], m);
  2488. return [
  2489. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2490. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2491. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2492. Math.max(p1[1], p2[1], p3[1], p4[1])
  2493. ];
  2494. };
  2495. Util.inverseTransform = function Util_inverseTransform(m) {
  2496. var d = m[0] * m[3] - m[1] * m[2];
  2497. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2498. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2499. };
  2500. // Apply a generic 3d matrix M on a 3-vector v:
  2501. // | a b c | | X |
  2502. // | d e f | x | Y |
  2503. // | g h i | | Z |
  2504. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2505. // with v as [X,Y,Z]
  2506. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2507. return [
  2508. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2509. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2510. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2511. ];
  2512. };
  2513. // This calculation uses Singular Value Decomposition.
  2514. // The SVD can be represented with formula A = USV. We are interested in the
  2515. // matrix S here because it represents the scale values.
  2516. Util.singularValueDecompose2dScale =
  2517. function Util_singularValueDecompose2dScale(m) {
  2518. var transpose = [m[0], m[2], m[1], m[3]];
  2519. // Multiply matrix m with its transpose.
  2520. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2521. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2522. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2523. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2524. // Solve the second degree polynomial to get roots.
  2525. var first = (a + d) / 2;
  2526. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2527. var sx = first + second || 1;
  2528. var sy = first - second || 1;
  2529. // Scale values are the square roots of the eigenvalues.
  2530. return [Math.sqrt(sx), Math.sqrt(sy)];
  2531. };
  2532. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2533. // For coordinate systems whose origin lies in the bottom-left, this
  2534. // means normalization to (BL,TR) ordering. For systems with origin in the
  2535. // top-left, this means (TL,BR) ordering.
  2536. Util.normalizeRect = function Util_normalizeRect(rect) {
  2537. var r = rect.slice(0); // clone rect
  2538. if (rect[0] > rect[2]) {
  2539. r[0] = rect[2];
  2540. r[2] = rect[0];
  2541. }
  2542. if (rect[1] > rect[3]) {
  2543. r[1] = rect[3];
  2544. r[3] = rect[1];
  2545. }
  2546. return r;
  2547. };
  2548. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2549. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2550. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2551. Util.intersect = function Util_intersect(rect1, rect2) {
  2552. function compare(a, b) {
  2553. return a - b;
  2554. }
  2555. // Order points along the axes
  2556. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2557. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2558. result = [];
  2559. rect1 = Util.normalizeRect(rect1);
  2560. rect2 = Util.normalizeRect(rect2);
  2561. // X: first and second points belong to different rectangles?
  2562. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2563. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2564. // Intersection must be between second and third points
  2565. result[0] = orderedX[1];
  2566. result[2] = orderedX[2];
  2567. } else {
  2568. return false;
  2569. }
  2570. // Y: first and second points belong to different rectangles?
  2571. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2572. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2573. // Intersection must be between second and third points
  2574. result[1] = orderedY[1];
  2575. result[3] = orderedY[2];
  2576. } else {
  2577. return false;
  2578. }
  2579. return result;
  2580. };
  2581. Util.sign = function Util_sign(num) {
  2582. return num < 0 ? -1 : 1;
  2583. };
  2584. var ROMAN_NUMBER_MAP = [
  2585. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2586. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2587. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2588. ];
  2589. /**
  2590. * Converts positive integers to (upper case) Roman numerals.
  2591. * @param {integer} number - The number that should be converted.
  2592. * @param {boolean} lowerCase - Indicates if the result should be converted
  2593. * to lower case letters. The default is false.
  2594. * @return {string} The resulting Roman number.
  2595. */
  2596. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2597. assert(isInt(number) && number > 0,
  2598. 'The number should be a positive integer.');
  2599. var pos, romanBuf = [];
  2600. // Thousands
  2601. while (number >= 1000) {
  2602. number -= 1000;
  2603. romanBuf.push('M');
  2604. }
  2605. // Hundreds
  2606. pos = (number / 100) | 0;
  2607. number %= 100;
  2608. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2609. // Tens
  2610. pos = (number / 10) | 0;
  2611. number %= 10;
  2612. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2613. // Ones
  2614. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2615. var romanStr = romanBuf.join('');
  2616. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2617. };
  2618. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2619. Array.prototype.push.apply(arr1, arr2);
  2620. };
  2621. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2622. Array.prototype.unshift.apply(arr1, arr2);
  2623. };
  2624. Util.extendObj = function extendObj(obj1, obj2) {
  2625. for (var key in obj2) {
  2626. obj1[key] = obj2[key];
  2627. }
  2628. };
  2629. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2630. name) {
  2631. while (dict && !dict.has(name)) {
  2632. dict = dict.get('Parent');
  2633. }
  2634. if (!dict) {
  2635. return null;
  2636. }
  2637. return dict.get(name);
  2638. };
  2639. Util.inherit = function Util_inherit(sub, base, prototype) {
  2640. sub.prototype = Object.create(base.prototype);
  2641. sub.prototype.constructor = sub;
  2642. for (var prop in prototype) {
  2643. sub.prototype[prop] = prototype[prop];
  2644. }
  2645. };
  2646. Util.loadScript = function Util_loadScript(src, callback) {
  2647. var script = document.createElement('script');
  2648. var loaded = false;
  2649. script.setAttribute('src', src);
  2650. if (callback) {
  2651. script.onload = function() {
  2652. if (!loaded) {
  2653. callback();
  2654. }
  2655. loaded = true;
  2656. };
  2657. }
  2658. document.getElementsByTagName('head')[0].appendChild(script);
  2659. };
  2660. return Util;
  2661. })();
  2662. /**
  2663. * PDF page viewport created based on scale, rotation and offset.
  2664. * @class
  2665. * @alias PageViewport
  2666. */
  2667. var PageViewport = (function PageViewportClosure() {
  2668. /**
  2669. * @constructor
  2670. * @private
  2671. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  2672. * @param scale {number} scale of the viewport.
  2673. * @param rotation {number} rotations of the viewport in degrees.
  2674. * @param offsetX {number} offset X
  2675. * @param offsetY {number} offset Y
  2676. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  2677. */
  2678. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  2679. this.viewBox = viewBox;
  2680. this.scale = scale;
  2681. this.rotation = rotation;
  2682. this.offsetX = offsetX;
  2683. this.offsetY = offsetY;
  2684. // creating transform to convert pdf coordinate system to the normal
  2685. // canvas like coordinates taking in account scale and rotation
  2686. var centerX = (viewBox[2] + viewBox[0]) / 2;
  2687. var centerY = (viewBox[3] + viewBox[1]) / 2;
  2688. var rotateA, rotateB, rotateC, rotateD;
  2689. rotation = rotation % 360;
  2690. rotation = rotation < 0 ? rotation + 360 : rotation;
  2691. switch (rotation) {
  2692. case 180:
  2693. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  2694. break;
  2695. case 90:
  2696. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  2697. break;
  2698. case 270:
  2699. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  2700. break;
  2701. //case 0:
  2702. default:
  2703. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  2704. break;
  2705. }
  2706. if (dontFlip) {
  2707. rotateC = -rotateC; rotateD = -rotateD;
  2708. }
  2709. var offsetCanvasX, offsetCanvasY;
  2710. var width, height;
  2711. if (rotateA === 0) {
  2712. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2713. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2714. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2715. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2716. } else {
  2717. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2718. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2719. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2720. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2721. }
  2722. // creating transform for the following operations:
  2723. // translate(-centerX, -centerY), rotate and flip vertically,
  2724. // scale, and translate(offsetCanvasX, offsetCanvasY)
  2725. this.transform = [
  2726. rotateA * scale,
  2727. rotateB * scale,
  2728. rotateC * scale,
  2729. rotateD * scale,
  2730. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  2731. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  2732. ];
  2733. this.width = width;
  2734. this.height = height;
  2735. this.fontScale = scale;
  2736. }
  2737. PageViewport.prototype = /** @lends PageViewport.prototype */ {
  2738. /**
  2739. * Clones viewport with additional properties.
  2740. * @param args {Object} (optional) If specified, may contain the 'scale' or
  2741. * 'rotation' properties to override the corresponding properties in
  2742. * the cloned viewport.
  2743. * @returns {PageViewport} Cloned viewport.
  2744. */
  2745. clone: function PageViewPort_clone(args) {
  2746. args = args || {};
  2747. var scale = 'scale' in args ? args.scale : this.scale;
  2748. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  2749. return new PageViewport(this.viewBox.slice(), scale, rotation,
  2750. this.offsetX, this.offsetY, args.dontFlip);
  2751. },
  2752. /**
  2753. * Converts PDF point to the viewport coordinates. For examples, useful for
  2754. * converting PDF location into canvas pixel coordinates.
  2755. * @param x {number} X coordinate.
  2756. * @param y {number} Y coordinate.
  2757. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2758. * point in the viewport coordinate space.
  2759. * @see {@link convertToPdfPoint}
  2760. * @see {@link convertToViewportRectangle}
  2761. */
  2762. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  2763. return Util.applyTransform([x, y], this.transform);
  2764. },
  2765. /**
  2766. * Converts PDF rectangle to the viewport coordinates.
  2767. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  2768. * @returns {Array} Contains corresponding coordinates of the rectangle
  2769. * in the viewport coordinate space.
  2770. * @see {@link convertToViewportPoint}
  2771. */
  2772. convertToViewportRectangle:
  2773. function PageViewport_convertToViewportRectangle(rect) {
  2774. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  2775. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  2776. return [tl[0], tl[1], br[0], br[1]];
  2777. },
  2778. /**
  2779. * Converts viewport coordinates to the PDF location. For examples, useful
  2780. * for converting canvas pixel location into PDF one.
  2781. * @param x {number} X coordinate.
  2782. * @param y {number} Y coordinate.
  2783. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2784. * point in the PDF coordinate space.
  2785. * @see {@link convertToViewportPoint}
  2786. */
  2787. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  2788. return Util.applyInverseTransform([x, y], this.transform);
  2789. }
  2790. };
  2791. return PageViewport;
  2792. })();
  2793. var PDFStringTranslateTable = [
  2794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2795. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  2796. 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,
  2797. 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,
  2798. 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,
  2799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  2800. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  2801. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  2802. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  2803. ];
  2804. function stringToPDFString(str) {
  2805. var i, n = str.length, strBuf = [];
  2806. if (str[0] === '\xFE' && str[1] === '\xFF') {
  2807. // UTF16BE BOM
  2808. for (i = 2; i < n; i += 2) {
  2809. strBuf.push(String.fromCharCode(
  2810. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  2811. }
  2812. } else {
  2813. for (i = 0; i < n; ++i) {
  2814. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  2815. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  2816. }
  2817. }
  2818. return strBuf.join('');
  2819. }
  2820. function stringToUTF8String(str) {
  2821. return decodeURIComponent(escape(str));
  2822. }
  2823. function utf8StringToString(str) {
  2824. return unescape(encodeURIComponent(str));
  2825. }
  2826. function isEmptyObj(obj) {
  2827. for (var key in obj) {
  2828. return false;
  2829. }
  2830. return true;
  2831. }
  2832. function isBool(v) {
  2833. return typeof v === 'boolean';
  2834. }
  2835. function isInt(v) {
  2836. return typeof v === 'number' && ((v | 0) === v);
  2837. }
  2838. function isNum(v) {
  2839. return typeof v === 'number';
  2840. }
  2841. function isString(v) {
  2842. return typeof v === 'string';
  2843. }
  2844. function isArray(v) {
  2845. return v instanceof Array;
  2846. }
  2847. function isArrayBuffer(v) {
  2848. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  2849. }
  2850. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  2851. function isSpace(ch) {
  2852. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  2853. }
  2854. /**
  2855. * Promise Capability object.
  2856. *
  2857. * @typedef {Object} PromiseCapability
  2858. * @property {Promise} promise - A promise object.
  2859. * @property {function} resolve - Fulfills the promise.
  2860. * @property {function} reject - Rejects the promise.
  2861. */
  2862. /**
  2863. * Creates a promise capability object.
  2864. * @alias createPromiseCapability
  2865. *
  2866. * @return {PromiseCapability} A capability object contains:
  2867. * - a Promise, resolve and reject methods.
  2868. */
  2869. function createPromiseCapability() {
  2870. var capability = {};
  2871. capability.promise = new Promise(function (resolve, reject) {
  2872. capability.resolve = resolve;
  2873. capability.reject = reject;
  2874. });
  2875. return capability;
  2876. }
  2877. /**
  2878. * Polyfill for Promises:
  2879. * The following promise implementation tries to generally implement the
  2880. * Promise/A+ spec. Some notable differences from other promise libraries are:
  2881. * - There currently isn't a separate deferred and promise object.
  2882. * - Unhandled rejections eventually show an error if they aren't handled.
  2883. *
  2884. * Based off of the work in:
  2885. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  2886. */
  2887. (function PromiseClosure() {
  2888. if (globalScope.Promise) {
  2889. // Promises existing in the DOM/Worker, checking presence of all/resolve
  2890. if (typeof globalScope.Promise.all !== 'function') {
  2891. globalScope.Promise.all = function (iterable) {
  2892. var count = 0, results = [], resolve, reject;
  2893. var promise = new globalScope.Promise(function (resolve_, reject_) {
  2894. resolve = resolve_;
  2895. reject = reject_;
  2896. });
  2897. iterable.forEach(function (p, i) {
  2898. count++;
  2899. p.then(function (result) {
  2900. results[i] = result;
  2901. count--;
  2902. if (count === 0) {
  2903. resolve(results);
  2904. }
  2905. }, reject);
  2906. });
  2907. if (count === 0) {
  2908. resolve(results);
  2909. }
  2910. return promise;
  2911. };
  2912. }
  2913. if (typeof globalScope.Promise.resolve !== 'function') {
  2914. globalScope.Promise.resolve = function (value) {
  2915. return new globalScope.Promise(function (resolve) { resolve(value); });
  2916. };
  2917. }
  2918. if (typeof globalScope.Promise.reject !== 'function') {
  2919. globalScope.Promise.reject = function (reason) {
  2920. return new globalScope.Promise(function (resolve, reject) {
  2921. reject(reason);
  2922. });
  2923. };
  2924. }
  2925. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  2926. globalScope.Promise.prototype.catch = function (onReject) {
  2927. return globalScope.Promise.prototype.then(undefined, onReject);
  2928. };
  2929. }
  2930. return;
  2931. }
  2932. var STATUS_PENDING = 0;
  2933. var STATUS_RESOLVED = 1;
  2934. var STATUS_REJECTED = 2;
  2935. // In an attempt to avoid silent exceptions, unhandled rejections are
  2936. // tracked and if they aren't handled in a certain amount of time an
  2937. // error is logged.
  2938. var REJECTION_TIMEOUT = 500;
  2939. var HandlerManager = {
  2940. handlers: [],
  2941. running: false,
  2942. unhandledRejections: [],
  2943. pendingRejectionCheck: false,
  2944. scheduleHandlers: function scheduleHandlers(promise) {
  2945. if (promise._status === STATUS_PENDING) {
  2946. return;
  2947. }
  2948. this.handlers = this.handlers.concat(promise._handlers);
  2949. promise._handlers = [];
  2950. if (this.running) {
  2951. return;
  2952. }
  2953. this.running = true;
  2954. setTimeout(this.runHandlers.bind(this), 0);
  2955. },
  2956. runHandlers: function runHandlers() {
  2957. var RUN_TIMEOUT = 1; // ms
  2958. var timeoutAt = Date.now() + RUN_TIMEOUT;
  2959. while (this.handlers.length > 0) {
  2960. var handler = this.handlers.shift();
  2961. var nextStatus = handler.thisPromise._status;
  2962. var nextValue = handler.thisPromise._value;
  2963. try {
  2964. if (nextStatus === STATUS_RESOLVED) {
  2965. if (typeof handler.onResolve === 'function') {
  2966. nextValue = handler.onResolve(nextValue);
  2967. }
  2968. } else if (typeof handler.onReject === 'function') {
  2969. nextValue = handler.onReject(nextValue);
  2970. nextStatus = STATUS_RESOLVED;
  2971. if (handler.thisPromise._unhandledRejection) {
  2972. this.removeUnhandeledRejection(handler.thisPromise);
  2973. }
  2974. }
  2975. } catch (ex) {
  2976. nextStatus = STATUS_REJECTED;
  2977. nextValue = ex;
  2978. }
  2979. handler.nextPromise._updateStatus(nextStatus, nextValue);
  2980. if (Date.now() >= timeoutAt) {
  2981. break;
  2982. }
  2983. }
  2984. if (this.handlers.length > 0) {
  2985. setTimeout(this.runHandlers.bind(this), 0);
  2986. return;
  2987. }
  2988. this.running = false;
  2989. },
  2990. addUnhandledRejection: function addUnhandledRejection(promise) {
  2991. this.unhandledRejections.push({
  2992. promise: promise,
  2993. time: Date.now()
  2994. });
  2995. this.scheduleRejectionCheck();
  2996. },
  2997. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  2998. promise._unhandledRejection = false;
  2999. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3000. if (this.unhandledRejections[i].promise === promise) {
  3001. this.unhandledRejections.splice(i);
  3002. i--;
  3003. }
  3004. }
  3005. },
  3006. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3007. if (this.pendingRejectionCheck) {
  3008. return;
  3009. }
  3010. this.pendingRejectionCheck = true;
  3011. setTimeout(function rejectionCheck() {
  3012. this.pendingRejectionCheck = false;
  3013. var now = Date.now();
  3014. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3015. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3016. var unhandled = this.unhandledRejections[i].promise._value;
  3017. var msg = 'Unhandled rejection: ' + unhandled;
  3018. if (unhandled.stack) {
  3019. msg += '\n' + unhandled.stack;
  3020. }
  3021. warn(msg);
  3022. this.unhandledRejections.splice(i);
  3023. i--;
  3024. }
  3025. }
  3026. if (this.unhandledRejections.length) {
  3027. this.scheduleRejectionCheck();
  3028. }
  3029. }.bind(this), REJECTION_TIMEOUT);
  3030. }
  3031. };
  3032. function Promise(resolver) {
  3033. this._status = STATUS_PENDING;
  3034. this._handlers = [];
  3035. try {
  3036. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3037. } catch (e) {
  3038. this._reject(e);
  3039. }
  3040. }
  3041. /**
  3042. * Builds a promise that is resolved when all the passed in promises are
  3043. * resolved.
  3044. * @param {array} promises array of data and/or promises to wait for.
  3045. * @return {Promise} New dependent promise.
  3046. */
  3047. Promise.all = function Promise_all(promises) {
  3048. var resolveAll, rejectAll;
  3049. var deferred = new Promise(function (resolve, reject) {
  3050. resolveAll = resolve;
  3051. rejectAll = reject;
  3052. });
  3053. var unresolved = promises.length;
  3054. var results = [];
  3055. if (unresolved === 0) {
  3056. resolveAll(results);
  3057. return deferred;
  3058. }
  3059. function reject(reason) {
  3060. if (deferred._status === STATUS_REJECTED) {
  3061. return;
  3062. }
  3063. results = [];
  3064. rejectAll(reason);
  3065. }
  3066. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3067. var promise = promises[i];
  3068. var resolve = (function(i) {
  3069. return function(value) {
  3070. if (deferred._status === STATUS_REJECTED) {
  3071. return;
  3072. }
  3073. results[i] = value;
  3074. unresolved--;
  3075. if (unresolved === 0) {
  3076. resolveAll(results);
  3077. }
  3078. };
  3079. })(i);
  3080. if (Promise.isPromise(promise)) {
  3081. promise.then(resolve, reject);
  3082. } else {
  3083. resolve(promise);
  3084. }
  3085. }
  3086. return deferred;
  3087. };
  3088. /**
  3089. * Checks if the value is likely a promise (has a 'then' function).
  3090. * @return {boolean} true if value is thenable
  3091. */
  3092. Promise.isPromise = function Promise_isPromise(value) {
  3093. return value && typeof value.then === 'function';
  3094. };
  3095. /**
  3096. * Creates resolved promise
  3097. * @param value resolve value
  3098. * @returns {Promise}
  3099. */
  3100. Promise.resolve = function Promise_resolve(value) {
  3101. return new Promise(function (resolve) { resolve(value); });
  3102. };
  3103. /**
  3104. * Creates rejected promise
  3105. * @param reason rejection value
  3106. * @returns {Promise}
  3107. */
  3108. Promise.reject = function Promise_reject(reason) {
  3109. return new Promise(function (resolve, reject) { reject(reason); });
  3110. };
  3111. Promise.prototype = {
  3112. _status: null,
  3113. _value: null,
  3114. _handlers: null,
  3115. _unhandledRejection: null,
  3116. _updateStatus: function Promise__updateStatus(status, value) {
  3117. if (this._status === STATUS_RESOLVED ||
  3118. this._status === STATUS_REJECTED) {
  3119. return;
  3120. }
  3121. if (status === STATUS_RESOLVED &&
  3122. Promise.isPromise(value)) {
  3123. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3124. this._updateStatus.bind(this, STATUS_REJECTED));
  3125. return;
  3126. }
  3127. this._status = status;
  3128. this._value = value;
  3129. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3130. this._unhandledRejection = true;
  3131. HandlerManager.addUnhandledRejection(this);
  3132. }
  3133. HandlerManager.scheduleHandlers(this);
  3134. },
  3135. _resolve: function Promise_resolve(value) {
  3136. this._updateStatus(STATUS_RESOLVED, value);
  3137. },
  3138. _reject: function Promise_reject(reason) {
  3139. this._updateStatus(STATUS_REJECTED, reason);
  3140. },
  3141. then: function Promise_then(onResolve, onReject) {
  3142. var nextPromise = new Promise(function (resolve, reject) {
  3143. this.resolve = resolve;
  3144. this.reject = reject;
  3145. });
  3146. this._handlers.push({
  3147. thisPromise: this,
  3148. onResolve: onResolve,
  3149. onReject: onReject,
  3150. nextPromise: nextPromise
  3151. });
  3152. HandlerManager.scheduleHandlers(this);
  3153. return nextPromise;
  3154. },
  3155. catch: function Promise_catch(onReject) {
  3156. return this.then(undefined, onReject);
  3157. }
  3158. };
  3159. globalScope.Promise = Promise;
  3160. })();
  3161. var StatTimer = (function StatTimerClosure() {
  3162. function rpad(str, pad, length) {
  3163. while (str.length < length) {
  3164. str += pad;
  3165. }
  3166. return str;
  3167. }
  3168. function StatTimer() {
  3169. this.started = Object.create(null);
  3170. this.times = [];
  3171. this.enabled = true;
  3172. }
  3173. StatTimer.prototype = {
  3174. time: function StatTimer_time(name) {
  3175. if (!this.enabled) {
  3176. return;
  3177. }
  3178. if (name in this.started) {
  3179. warn('Timer is already running for ' + name);
  3180. }
  3181. this.started[name] = Date.now();
  3182. },
  3183. timeEnd: function StatTimer_timeEnd(name) {
  3184. if (!this.enabled) {
  3185. return;
  3186. }
  3187. if (!(name in this.started)) {
  3188. warn('Timer has not been started for ' + name);
  3189. }
  3190. this.times.push({
  3191. 'name': name,
  3192. 'start': this.started[name],
  3193. 'end': Date.now()
  3194. });
  3195. // Remove timer from started so it can be called again.
  3196. delete this.started[name];
  3197. },
  3198. toString: function StatTimer_toString() {
  3199. var i, ii;
  3200. var times = this.times;
  3201. var out = '';
  3202. // Find the longest name for padding purposes.
  3203. var longest = 0;
  3204. for (i = 0, ii = times.length; i < ii; ++i) {
  3205. var name = times[i]['name'];
  3206. if (name.length > longest) {
  3207. longest = name.length;
  3208. }
  3209. }
  3210. for (i = 0, ii = times.length; i < ii; ++i) {
  3211. var span = times[i];
  3212. var duration = span.end - span.start;
  3213. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3214. }
  3215. return out;
  3216. }
  3217. };
  3218. return StatTimer;
  3219. })();
  3220. var createBlob = function createBlob(data, contentType) {
  3221. if (typeof Blob !== 'undefined') {
  3222. return new Blob([data], { type: contentType });
  3223. }
  3224. warn('The "Blob" constructor is not supported.');
  3225. };
  3226. var createObjectURL = (function createObjectURLClosure() {
  3227. // Blob/createObjectURL is not available, falling back to data schema.
  3228. var digits =
  3229. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3230. return function createObjectURL(data, contentType, forceDataSchema) {
  3231. if (!forceDataSchema &&
  3232. typeof URL !== 'undefined' && URL.createObjectURL) {
  3233. var blob = createBlob(data, contentType);
  3234. return URL.createObjectURL(blob);
  3235. }
  3236. var buffer = 'data:' + contentType + ';base64,';
  3237. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3238. var b1 = data[i] & 0xFF;
  3239. var b2 = data[i + 1] & 0xFF;
  3240. var b3 = data[i + 2] & 0xFF;
  3241. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3242. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3243. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3244. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3245. }
  3246. return buffer;
  3247. };
  3248. })();
  3249. function MessageHandler(sourceName, targetName, comObj) {
  3250. this.sourceName = sourceName;
  3251. this.targetName = targetName;
  3252. this.comObj = comObj;
  3253. this.callbackIndex = 1;
  3254. this.postMessageTransfers = true;
  3255. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3256. var ah = this.actionHandler = Object.create(null);
  3257. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3258. var data = event.data;
  3259. if (data.targetName !== this.sourceName) {
  3260. return;
  3261. }
  3262. if (data.isReply) {
  3263. var callbackId = data.callbackId;
  3264. if (data.callbackId in callbacksCapabilities) {
  3265. var callback = callbacksCapabilities[callbackId];
  3266. delete callbacksCapabilities[callbackId];
  3267. if ('error' in data) {
  3268. callback.reject(data.error);
  3269. } else {
  3270. callback.resolve(data.data);
  3271. }
  3272. } else {
  3273. error('Cannot resolve callback ' + callbackId);
  3274. }
  3275. } else if (data.action in ah) {
  3276. var action = ah[data.action];
  3277. if (data.callbackId) {
  3278. var sourceName = this.sourceName;
  3279. var targetName = data.sourceName;
  3280. Promise.resolve().then(function () {
  3281. return action[0].call(action[1], data.data);
  3282. }).then(function (result) {
  3283. comObj.postMessage({
  3284. sourceName: sourceName,
  3285. targetName: targetName,
  3286. isReply: true,
  3287. callbackId: data.callbackId,
  3288. data: result
  3289. });
  3290. }, function (reason) {
  3291. if (reason instanceof Error) {
  3292. // Serialize error to avoid "DataCloneError"
  3293. reason = reason + '';
  3294. }
  3295. comObj.postMessage({
  3296. sourceName: sourceName,
  3297. targetName: targetName,
  3298. isReply: true,
  3299. callbackId: data.callbackId,
  3300. error: reason
  3301. });
  3302. });
  3303. } else {
  3304. action[0].call(action[1], data.data);
  3305. }
  3306. } else {
  3307. error('Unknown action from worker: ' + data.action);
  3308. }
  3309. }.bind(this);
  3310. comObj.addEventListener('message', this._onComObjOnMessage);
  3311. }
  3312. MessageHandler.prototype = {
  3313. on: function messageHandlerOn(actionName, handler, scope) {
  3314. var ah = this.actionHandler;
  3315. if (ah[actionName]) {
  3316. error('There is already an actionName called "' + actionName + '"');
  3317. }
  3318. ah[actionName] = [handler, scope];
  3319. },
  3320. /**
  3321. * Sends a message to the comObj to invoke the action with the supplied data.
  3322. * @param {String} actionName Action to call.
  3323. * @param {JSON} data JSON data to send.
  3324. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3325. */
  3326. send: function messageHandlerSend(actionName, data, transfers) {
  3327. var message = {
  3328. sourceName: this.sourceName,
  3329. targetName: this.targetName,
  3330. action: actionName,
  3331. data: data
  3332. };
  3333. this.postMessage(message, transfers);
  3334. },
  3335. /**
  3336. * Sends a message to the comObj to invoke the action with the supplied data.
  3337. * Expects that other side will callback with the response.
  3338. * @param {String} actionName Action to call.
  3339. * @param {JSON} data JSON data to send.
  3340. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3341. * @returns {Promise} Promise to be resolved with response data.
  3342. */
  3343. sendWithPromise:
  3344. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3345. var callbackId = this.callbackIndex++;
  3346. var message = {
  3347. sourceName: this.sourceName,
  3348. targetName: this.targetName,
  3349. action: actionName,
  3350. data: data,
  3351. callbackId: callbackId
  3352. };
  3353. var capability = createPromiseCapability();
  3354. this.callbacksCapabilities[callbackId] = capability;
  3355. try {
  3356. this.postMessage(message, transfers);
  3357. } catch (e) {
  3358. capability.reject(e);
  3359. }
  3360. return capability.promise;
  3361. },
  3362. /**
  3363. * Sends raw message to the comObj.
  3364. * @private
  3365. * @param message {Object} Raw message.
  3366. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3367. */
  3368. postMessage: function (message, transfers) {
  3369. if (transfers && this.postMessageTransfers) {
  3370. this.comObj.postMessage(message, transfers);
  3371. } else {
  3372. this.comObj.postMessage(message);
  3373. }
  3374. },
  3375. destroy: function () {
  3376. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3377. }
  3378. };
  3379. function loadJpegStream(id, imageUrl, objs) {
  3380. var img = new Image();
  3381. img.onload = (function loadJpegStream_onloadClosure() {
  3382. objs.resolve(id, img);
  3383. });
  3384. img.onerror = (function loadJpegStream_onerrorClosure() {
  3385. objs.resolve(id, null);
  3386. warn('Error during JPEG image loading');
  3387. });
  3388. img.src = imageUrl;
  3389. }
  3390. // Polyfill from https://github.com/Polymer/URL
  3391. /* Any copyright is dedicated to the Public Domain.
  3392. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3393. (function checkURLConstructor(scope) {
  3394. /* jshint ignore:start */
  3395. // feature detect for URL constructor
  3396. var hasWorkingUrl = false;
  3397. try {
  3398. if (typeof URL === 'function' &&
  3399. typeof URL.prototype === 'object' &&
  3400. ('origin' in URL.prototype)) {
  3401. var u = new URL('b', 'http://a');
  3402. u.pathname = 'c%20d';
  3403. hasWorkingUrl = u.href === 'http://a/c%20d';
  3404. }
  3405. } catch(e) { }
  3406. if (hasWorkingUrl)
  3407. return;
  3408. var relative = Object.create(null);
  3409. relative['ftp'] = 21;
  3410. relative['file'] = 0;
  3411. relative['gopher'] = 70;
  3412. relative['http'] = 80;
  3413. relative['https'] = 443;
  3414. relative['ws'] = 80;
  3415. relative['wss'] = 443;
  3416. var relativePathDotMapping = Object.create(null);
  3417. relativePathDotMapping['%2e'] = '.';
  3418. relativePathDotMapping['.%2e'] = '..';
  3419. relativePathDotMapping['%2e.'] = '..';
  3420. relativePathDotMapping['%2e%2e'] = '..';
  3421. function isRelativeScheme(scheme) {
  3422. return relative[scheme] !== undefined;
  3423. }
  3424. function invalid() {
  3425. clear.call(this);
  3426. this._isInvalid = true;
  3427. }
  3428. function IDNAToASCII(h) {
  3429. if ('' == h) {
  3430. invalid.call(this)
  3431. }
  3432. // XXX
  3433. return h.toLowerCase()
  3434. }
  3435. function percentEscape(c) {
  3436. var unicode = c.charCodeAt(0);
  3437. if (unicode > 0x20 &&
  3438. unicode < 0x7F &&
  3439. // " # < > ? `
  3440. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3441. ) {
  3442. return c;
  3443. }
  3444. return encodeURIComponent(c);
  3445. }
  3446. function percentEscapeQuery(c) {
  3447. // XXX This actually needs to encode c using encoding and then
  3448. // convert the bytes one-by-one.
  3449. var unicode = c.charCodeAt(0);
  3450. if (unicode > 0x20 &&
  3451. unicode < 0x7F &&
  3452. // " # < > ` (do not escape '?')
  3453. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3454. ) {
  3455. return c;
  3456. }
  3457. return encodeURIComponent(c);
  3458. }
  3459. var EOF = undefined,
  3460. ALPHA = /[a-zA-Z]/,
  3461. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3462. function parse(input, stateOverride, base) {
  3463. function err(message) {
  3464. errors.push(message)
  3465. }
  3466. var state = stateOverride || 'scheme start',
  3467. cursor = 0,
  3468. buffer = '',
  3469. seenAt = false,
  3470. seenBracket = false,
  3471. errors = [];
  3472. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3473. var c = input[cursor];
  3474. switch (state) {
  3475. case 'scheme start':
  3476. if (c && ALPHA.test(c)) {
  3477. buffer += c.toLowerCase(); // ASCII-safe
  3478. state = 'scheme';
  3479. } else if (!stateOverride) {
  3480. buffer = '';
  3481. state = 'no scheme';
  3482. continue;
  3483. } else {
  3484. err('Invalid scheme.');
  3485. break loop;
  3486. }
  3487. break;
  3488. case 'scheme':
  3489. if (c && ALPHANUMERIC.test(c)) {
  3490. buffer += c.toLowerCase(); // ASCII-safe
  3491. } else if (':' == c) {
  3492. this._scheme = buffer;
  3493. buffer = '';
  3494. if (stateOverride) {
  3495. break loop;
  3496. }
  3497. if (isRelativeScheme(this._scheme)) {
  3498. this._isRelative = true;
  3499. }
  3500. if ('file' == this._scheme) {
  3501. state = 'relative';
  3502. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3503. state = 'relative or authority';
  3504. } else if (this._isRelative) {
  3505. state = 'authority first slash';
  3506. } else {
  3507. state = 'scheme data';
  3508. }
  3509. } else if (!stateOverride) {
  3510. buffer = '';
  3511. cursor = 0;
  3512. state = 'no scheme';
  3513. continue;
  3514. } else if (EOF == c) {
  3515. break loop;
  3516. } else {
  3517. err('Code point not allowed in scheme: ' + c)
  3518. break loop;
  3519. }
  3520. break;
  3521. case 'scheme data':
  3522. if ('?' == c) {
  3523. this._query = '?';
  3524. state = 'query';
  3525. } else if ('#' == c) {
  3526. this._fragment = '#';
  3527. state = 'fragment';
  3528. } else {
  3529. // XXX error handling
  3530. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3531. this._schemeData += percentEscape(c);
  3532. }
  3533. }
  3534. break;
  3535. case 'no scheme':
  3536. if (!base || !(isRelativeScheme(base._scheme))) {
  3537. err('Missing scheme.');
  3538. invalid.call(this);
  3539. } else {
  3540. state = 'relative';
  3541. continue;
  3542. }
  3543. break;
  3544. case 'relative or authority':
  3545. if ('/' == c && '/' == input[cursor+1]) {
  3546. state = 'authority ignore slashes';
  3547. } else {
  3548. err('Expected /, got: ' + c);
  3549. state = 'relative';
  3550. continue
  3551. }
  3552. break;
  3553. case 'relative':
  3554. this._isRelative = true;
  3555. if ('file' != this._scheme)
  3556. this._scheme = base._scheme;
  3557. if (EOF == c) {
  3558. this._host = base._host;
  3559. this._port = base._port;
  3560. this._path = base._path.slice();
  3561. this._query = base._query;
  3562. this._username = base._username;
  3563. this._password = base._password;
  3564. break loop;
  3565. } else if ('/' == c || '\\' == c) {
  3566. if ('\\' == c)
  3567. err('\\ is an invalid code point.');
  3568. state = 'relative slash';
  3569. } else if ('?' == c) {
  3570. this._host = base._host;
  3571. this._port = base._port;
  3572. this._path = base._path.slice();
  3573. this._query = '?';
  3574. this._username = base._username;
  3575. this._password = base._password;
  3576. state = 'query';
  3577. } else if ('#' == c) {
  3578. this._host = base._host;
  3579. this._port = base._port;
  3580. this._path = base._path.slice();
  3581. this._query = base._query;
  3582. this._fragment = '#';
  3583. this._username = base._username;
  3584. this._password = base._password;
  3585. state = 'fragment';
  3586. } else {
  3587. var nextC = input[cursor+1]
  3588. var nextNextC = input[cursor+2]
  3589. if (
  3590. 'file' != this._scheme || !ALPHA.test(c) ||
  3591. (nextC != ':' && nextC != '|') ||
  3592. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3593. this._host = base._host;
  3594. this._port = base._port;
  3595. this._username = base._username;
  3596. this._password = base._password;
  3597. this._path = base._path.slice();
  3598. this._path.pop();
  3599. }
  3600. state = 'relative path';
  3601. continue;
  3602. }
  3603. break;
  3604. case 'relative slash':
  3605. if ('/' == c || '\\' == c) {
  3606. if ('\\' == c) {
  3607. err('\\ is an invalid code point.');
  3608. }
  3609. if ('file' == this._scheme) {
  3610. state = 'file host';
  3611. } else {
  3612. state = 'authority ignore slashes';
  3613. }
  3614. } else {
  3615. if ('file' != this._scheme) {
  3616. this._host = base._host;
  3617. this._port = base._port;
  3618. this._username = base._username;
  3619. this._password = base._password;
  3620. }
  3621. state = 'relative path';
  3622. continue;
  3623. }
  3624. break;
  3625. case 'authority first slash':
  3626. if ('/' == c) {
  3627. state = 'authority second slash';
  3628. } else {
  3629. err("Expected '/', got: " + c);
  3630. state = 'authority ignore slashes';
  3631. continue;
  3632. }
  3633. break;
  3634. case 'authority second slash':
  3635. state = 'authority ignore slashes';
  3636. if ('/' != c) {
  3637. err("Expected '/', got: " + c);
  3638. continue;
  3639. }
  3640. break;
  3641. case 'authority ignore slashes':
  3642. if ('/' != c && '\\' != c) {
  3643. state = 'authority';
  3644. continue;
  3645. } else {
  3646. err('Expected authority, got: ' + c);
  3647. }
  3648. break;
  3649. case 'authority':
  3650. if ('@' == c) {
  3651. if (seenAt) {
  3652. err('@ already seen.');
  3653. buffer += '%40';
  3654. }
  3655. seenAt = true;
  3656. for (var i = 0; i < buffer.length; i++) {
  3657. var cp = buffer[i];
  3658. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3659. err('Invalid whitespace in authority.');
  3660. continue;
  3661. }
  3662. // XXX check URL code points
  3663. if (':' == cp && null === this._password) {
  3664. this._password = '';
  3665. continue;
  3666. }
  3667. var tempC = percentEscape(cp);
  3668. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3669. }
  3670. buffer = '';
  3671. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3672. cursor -= buffer.length;
  3673. buffer = '';
  3674. state = 'host';
  3675. continue;
  3676. } else {
  3677. buffer += c;
  3678. }
  3679. break;
  3680. case 'file host':
  3681. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3682. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  3683. state = 'relative path';
  3684. } else if (buffer.length == 0) {
  3685. state = 'relative path start';
  3686. } else {
  3687. this._host = IDNAToASCII.call(this, buffer);
  3688. buffer = '';
  3689. state = 'relative path start';
  3690. }
  3691. continue;
  3692. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3693. err('Invalid whitespace in file host.');
  3694. } else {
  3695. buffer += c;
  3696. }
  3697. break;
  3698. case 'host':
  3699. case 'hostname':
  3700. if (':' == c && !seenBracket) {
  3701. // XXX host parsing
  3702. this._host = IDNAToASCII.call(this, buffer);
  3703. buffer = '';
  3704. state = 'port';
  3705. if ('hostname' == stateOverride) {
  3706. break loop;
  3707. }
  3708. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3709. this._host = IDNAToASCII.call(this, buffer);
  3710. buffer = '';
  3711. state = 'relative path start';
  3712. if (stateOverride) {
  3713. break loop;
  3714. }
  3715. continue;
  3716. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3717. if ('[' == c) {
  3718. seenBracket = true;
  3719. } else if (']' == c) {
  3720. seenBracket = false;
  3721. }
  3722. buffer += c;
  3723. } else {
  3724. err('Invalid code point in host/hostname: ' + c);
  3725. }
  3726. break;
  3727. case 'port':
  3728. if (/[0-9]/.test(c)) {
  3729. buffer += c;
  3730. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  3731. if ('' != buffer) {
  3732. var temp = parseInt(buffer, 10);
  3733. if (temp != relative[this._scheme]) {
  3734. this._port = temp + '';
  3735. }
  3736. buffer = '';
  3737. }
  3738. if (stateOverride) {
  3739. break loop;
  3740. }
  3741. state = 'relative path start';
  3742. continue;
  3743. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3744. err('Invalid code point in port: ' + c);
  3745. } else {
  3746. invalid.call(this);
  3747. }
  3748. break;
  3749. case 'relative path start':
  3750. if ('\\' == c)
  3751. err("'\\' not allowed in path.");
  3752. state = 'relative path';
  3753. if ('/' != c && '\\' != c) {
  3754. continue;
  3755. }
  3756. break;
  3757. case 'relative path':
  3758. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  3759. if ('\\' == c) {
  3760. err('\\ not allowed in relative path.');
  3761. }
  3762. var tmp;
  3763. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  3764. buffer = tmp;
  3765. }
  3766. if ('..' == buffer) {
  3767. this._path.pop();
  3768. if ('/' != c && '\\' != c) {
  3769. this._path.push('');
  3770. }
  3771. } else if ('.' == buffer && '/' != c && '\\' != c) {
  3772. this._path.push('');
  3773. } else if ('.' != buffer) {
  3774. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  3775. buffer = buffer[0] + ':';
  3776. }
  3777. this._path.push(buffer);
  3778. }
  3779. buffer = '';
  3780. if ('?' == c) {
  3781. this._query = '?';
  3782. state = 'query';
  3783. } else if ('#' == c) {
  3784. this._fragment = '#';
  3785. state = 'fragment';
  3786. }
  3787. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3788. buffer += percentEscape(c);
  3789. }
  3790. break;
  3791. case 'query':
  3792. if (!stateOverride && '#' == c) {
  3793. this._fragment = '#';
  3794. state = 'fragment';
  3795. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3796. this._query += percentEscapeQuery(c);
  3797. }
  3798. break;
  3799. case 'fragment':
  3800. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3801. this._fragment += c;
  3802. }
  3803. break;
  3804. }
  3805. cursor++;
  3806. }
  3807. }
  3808. function clear() {
  3809. this._scheme = '';
  3810. this._schemeData = '';
  3811. this._username = '';
  3812. this._password = null;
  3813. this._host = '';
  3814. this._port = '';
  3815. this._path = [];
  3816. this._query = '';
  3817. this._fragment = '';
  3818. this._isInvalid = false;
  3819. this._isRelative = false;
  3820. }
  3821. // Does not process domain names or IP addresses.
  3822. // Does not handle encoding for the query parameter.
  3823. function jURL(url, base /* , encoding */) {
  3824. if (base !== undefined && !(base instanceof jURL))
  3825. base = new jURL(String(base));
  3826. this._url = url;
  3827. clear.call(this);
  3828. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  3829. // encoding = encoding || 'utf-8'
  3830. parse.call(this, input, null, base);
  3831. }
  3832. jURL.prototype = {
  3833. toString: function() {
  3834. return this.href;
  3835. },
  3836. get href() {
  3837. if (this._isInvalid)
  3838. return this._url;
  3839. var authority = '';
  3840. if ('' != this._username || null != this._password) {
  3841. authority = this._username +
  3842. (null != this._password ? ':' + this._password : '') + '@';
  3843. }
  3844. return this.protocol +
  3845. (this._isRelative ? '//' + authority + this.host : '') +
  3846. this.pathname + this._query + this._fragment;
  3847. },
  3848. set href(href) {
  3849. clear.call(this);
  3850. parse.call(this, href);
  3851. },
  3852. get protocol() {
  3853. return this._scheme + ':';
  3854. },
  3855. set protocol(protocol) {
  3856. if (this._isInvalid)
  3857. return;
  3858. parse.call(this, protocol + ':', 'scheme start');
  3859. },
  3860. get host() {
  3861. return this._isInvalid ? '' : this._port ?
  3862. this._host + ':' + this._port : this._host;
  3863. },
  3864. set host(host) {
  3865. if (this._isInvalid || !this._isRelative)
  3866. return;
  3867. parse.call(this, host, 'host');
  3868. },
  3869. get hostname() {
  3870. return this._host;
  3871. },
  3872. set hostname(hostname) {
  3873. if (this._isInvalid || !this._isRelative)
  3874. return;
  3875. parse.call(this, hostname, 'hostname');
  3876. },
  3877. get port() {
  3878. return this._port;
  3879. },
  3880. set port(port) {
  3881. if (this._isInvalid || !this._isRelative)
  3882. return;
  3883. parse.call(this, port, 'port');
  3884. },
  3885. get pathname() {
  3886. return this._isInvalid ? '' : this._isRelative ?
  3887. '/' + this._path.join('/') : this._schemeData;
  3888. },
  3889. set pathname(pathname) {
  3890. if (this._isInvalid || !this._isRelative)
  3891. return;
  3892. this._path = [];
  3893. parse.call(this, pathname, 'relative path start');
  3894. },
  3895. get search() {
  3896. return this._isInvalid || !this._query || '?' == this._query ?
  3897. '' : this._query;
  3898. },
  3899. set search(search) {
  3900. if (this._isInvalid || !this._isRelative)
  3901. return;
  3902. this._query = '?';
  3903. if ('?' == search[0])
  3904. search = search.slice(1);
  3905. parse.call(this, search, 'query');
  3906. },
  3907. get hash() {
  3908. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  3909. '' : this._fragment;
  3910. },
  3911. set hash(hash) {
  3912. if (this._isInvalid)
  3913. return;
  3914. this._fragment = '#';
  3915. if ('#' == hash[0])
  3916. hash = hash.slice(1);
  3917. parse.call(this, hash, 'fragment');
  3918. },
  3919. get origin() {
  3920. var host;
  3921. if (this._isInvalid || !this._scheme) {
  3922. return '';
  3923. }
  3924. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  3925. // Gecko throws error for "data://"
  3926. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  3927. // Gecko returns String("") for file: mailto:
  3928. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  3929. switch (this._scheme) {
  3930. case 'data':
  3931. case 'file':
  3932. case 'javascript':
  3933. case 'mailto':
  3934. return 'null';
  3935. }
  3936. host = this.host;
  3937. if (!host) {
  3938. return '';
  3939. }
  3940. return this._scheme + '://' + host;
  3941. }
  3942. };
  3943. // Copy over the static methods
  3944. var OriginalURL = scope.URL;
  3945. if (OriginalURL) {
  3946. jURL.createObjectURL = function(blob) {
  3947. // IE extension allows a second optional options argument.
  3948. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  3949. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  3950. };
  3951. jURL.revokeObjectURL = function(url) {
  3952. OriginalURL.revokeObjectURL(url);
  3953. };
  3954. }
  3955. scope.URL = jURL;
  3956. /* jshint ignore:end */
  3957. })(globalScope);
  3958. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  3959. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  3960. exports.OPS = OPS;
  3961. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  3962. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  3963. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  3964. exports.AnnotationFlag = AnnotationFlag;
  3965. exports.AnnotationType = AnnotationType;
  3966. exports.FontType = FontType;
  3967. exports.ImageKind = ImageKind;
  3968. exports.InvalidPDFException = InvalidPDFException;
  3969. exports.MessageHandler = MessageHandler;
  3970. exports.MissingDataException = MissingDataException;
  3971. exports.MissingPDFException = MissingPDFException;
  3972. exports.NotImplementedException = NotImplementedException;
  3973. exports.PageViewport = PageViewport;
  3974. exports.PasswordException = PasswordException;
  3975. exports.PasswordResponses = PasswordResponses;
  3976. exports.StatTimer = StatTimer;
  3977. exports.StreamType = StreamType;
  3978. exports.TextRenderingMode = TextRenderingMode;
  3979. exports.UnexpectedResponseException = UnexpectedResponseException;
  3980. exports.UnknownErrorException = UnknownErrorException;
  3981. exports.Util = Util;
  3982. exports.XRefParseException = XRefParseException;
  3983. exports.arrayByteLength = arrayByteLength;
  3984. exports.arraysToBytes = arraysToBytes;
  3985. exports.assert = assert;
  3986. exports.bytesToString = bytesToString;
  3987. exports.createBlob = createBlob;
  3988. exports.createPromiseCapability = createPromiseCapability;
  3989. exports.createObjectURL = createObjectURL;
  3990. exports.deprecated = deprecated;
  3991. exports.error = error;
  3992. exports.getLookupTableFactory = getLookupTableFactory;
  3993. exports.getVerbosityLevel = getVerbosityLevel;
  3994. exports.globalScope = globalScope;
  3995. exports.info = info;
  3996. exports.isArray = isArray;
  3997. exports.isArrayBuffer = isArrayBuffer;
  3998. exports.isBool = isBool;
  3999. exports.isEmptyObj = isEmptyObj;
  4000. exports.isInt = isInt;
  4001. exports.isNum = isNum;
  4002. exports.isString = isString;
  4003. exports.isSpace = isSpace;
  4004. exports.isSameOrigin = isSameOrigin;
  4005. exports.isValidUrl = isValidUrl;
  4006. exports.isLittleEndian = isLittleEndian;
  4007. exports.isEvalSupported = isEvalSupported;
  4008. exports.loadJpegStream = loadJpegStream;
  4009. exports.log2 = log2;
  4010. exports.readInt8 = readInt8;
  4011. exports.readUint16 = readUint16;
  4012. exports.readUint32 = readUint32;
  4013. exports.removeNullCharacters = removeNullCharacters;
  4014. exports.setVerbosityLevel = setVerbosityLevel;
  4015. exports.shadow = shadow;
  4016. exports.string32 = string32;
  4017. exports.stringToBytes = stringToBytes;
  4018. exports.stringToPDFString = stringToPDFString;
  4019. exports.stringToUTF8String = stringToUTF8String;
  4020. exports.utf8StringToString = utf8StringToString;
  4021. exports.warn = warn;
  4022. }));
  4023. (function (root, factory) {
  4024. {
  4025. factory((root.pdfjsCoreCFFParser = {}), root.pdfjsSharedUtil,
  4026. root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  4027. }
  4028. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  4029. var error = sharedUtil.error;
  4030. var info = sharedUtil.info;
  4031. var bytesToString = sharedUtil.bytesToString;
  4032. var warn = sharedUtil.warn;
  4033. var isArray = sharedUtil.isArray;
  4034. var Util = sharedUtil.Util;
  4035. var stringToBytes = sharedUtil.stringToBytes;
  4036. var assert = sharedUtil.assert;
  4037. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  4038. var ExpertCharset = coreCharsets.ExpertCharset;
  4039. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  4040. var StandardEncoding = coreEncodings.StandardEncoding;
  4041. var ExpertEncoding = coreEncodings.ExpertEncoding;
  4042. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  4043. var MAX_SUBR_NESTING = 10;
  4044. /**
  4045. * The CFF class takes a Type1 file and wrap it into a
  4046. * 'Compact Font Format' which itself embed Type2 charstrings.
  4047. */
  4048. var CFFStandardStrings = [
  4049. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  4050. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  4051. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  4052. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  4053. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  4054. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  4055. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  4056. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  4057. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  4058. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4059. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4060. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4061. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4062. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  4063. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  4064. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  4065. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  4066. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  4067. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  4068. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  4069. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  4070. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  4071. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  4072. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  4073. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  4074. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  4075. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  4076. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  4077. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  4078. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  4079. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  4080. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  4081. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  4082. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4083. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  4084. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  4085. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  4086. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  4087. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  4088. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4089. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  4090. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  4091. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  4092. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  4093. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  4094. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  4095. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  4096. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  4097. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  4098. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  4099. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  4100. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  4101. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  4102. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  4103. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  4104. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  4105. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  4106. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  4107. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  4108. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  4109. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  4110. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  4111. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  4112. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  4113. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  4114. ];
  4115. var CFFParser = (function CFFParserClosure() {
  4116. var CharstringValidationData = [
  4117. null,
  4118. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  4119. null,
  4120. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  4121. { id: 'vmoveto', min: 1, stackClearing: true },
  4122. { id: 'rlineto', min: 2, resetStack: true },
  4123. { id: 'hlineto', min: 1, resetStack: true },
  4124. { id: 'vlineto', min: 1, resetStack: true },
  4125. { id: 'rrcurveto', min: 6, resetStack: true },
  4126. null,
  4127. { id: 'callsubr', min: 1, undefStack: true },
  4128. { id: 'return', min: 0, undefStack: true },
  4129. null, // 12
  4130. null,
  4131. { id: 'endchar', min: 0, stackClearing: true },
  4132. null,
  4133. null,
  4134. null,
  4135. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  4136. { id: 'hintmask', min: 0, stackClearing: true },
  4137. { id: 'cntrmask', min: 0, stackClearing: true },
  4138. { id: 'rmoveto', min: 2, stackClearing: true },
  4139. { id: 'hmoveto', min: 1, stackClearing: true },
  4140. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  4141. { id: 'rcurveline', min: 8, resetStack: true },
  4142. { id: 'rlinecurve', min: 8, resetStack: true },
  4143. { id: 'vvcurveto', min: 4, resetStack: true },
  4144. { id: 'hhcurveto', min: 4, resetStack: true },
  4145. null, // shortint
  4146. { id: 'callgsubr', min: 1, undefStack: true },
  4147. { id: 'vhcurveto', min: 4, resetStack: true },
  4148. { id: 'hvcurveto', min: 4, resetStack: true }
  4149. ];
  4150. var CharstringValidationData12 = [
  4151. null,
  4152. null,
  4153. null,
  4154. { id: 'and', min: 2, stackDelta: -1 },
  4155. { id: 'or', min: 2, stackDelta: -1 },
  4156. { id: 'not', min: 1, stackDelta: 0 },
  4157. null,
  4158. null,
  4159. null,
  4160. { id: 'abs', min: 1, stackDelta: 0 },
  4161. { id: 'add', min: 2, stackDelta: -1,
  4162. stackFn: function stack_div(stack, index) {
  4163. stack[index - 2] = stack[index - 2] + stack[index - 1];
  4164. }
  4165. },
  4166. { id: 'sub', min: 2, stackDelta: -1,
  4167. stackFn: function stack_div(stack, index) {
  4168. stack[index - 2] = stack[index - 2] - stack[index - 1];
  4169. }
  4170. },
  4171. { id: 'div', min: 2, stackDelta: -1,
  4172. stackFn: function stack_div(stack, index) {
  4173. stack[index - 2] = stack[index - 2] / stack[index - 1];
  4174. }
  4175. },
  4176. null,
  4177. { id: 'neg', min: 1, stackDelta: 0,
  4178. stackFn: function stack_div(stack, index) {
  4179. stack[index - 1] = -stack[index - 1];
  4180. }
  4181. },
  4182. { id: 'eq', min: 2, stackDelta: -1 },
  4183. null,
  4184. null,
  4185. { id: 'drop', min: 1, stackDelta: -1 },
  4186. null,
  4187. { id: 'put', min: 2, stackDelta: -2 },
  4188. { id: 'get', min: 1, stackDelta: 0 },
  4189. { id: 'ifelse', min: 4, stackDelta: -3 },
  4190. { id: 'random', min: 0, stackDelta: 1 },
  4191. { id: 'mul', min: 2, stackDelta: -1,
  4192. stackFn: function stack_div(stack, index) {
  4193. stack[index - 2] = stack[index - 2] * stack[index - 1];
  4194. }
  4195. },
  4196. null,
  4197. { id: 'sqrt', min: 1, stackDelta: 0 },
  4198. { id: 'dup', min: 1, stackDelta: 1 },
  4199. { id: 'exch', min: 2, stackDelta: 0 },
  4200. { id: 'index', min: 2, stackDelta: 0 },
  4201. { id: 'roll', min: 3, stackDelta: -2 },
  4202. null,
  4203. null,
  4204. null,
  4205. { id: 'hflex', min: 7, resetStack: true },
  4206. { id: 'flex', min: 13, resetStack: true },
  4207. { id: 'hflex1', min: 9, resetStack: true },
  4208. { id: 'flex1', min: 11, resetStack: true }
  4209. ];
  4210. function CFFParser(file, properties, seacAnalysisEnabled) {
  4211. this.bytes = file.getBytes();
  4212. this.properties = properties;
  4213. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  4214. }
  4215. CFFParser.prototype = {
  4216. parse: function CFFParser_parse() {
  4217. var properties = this.properties;
  4218. var cff = new CFF();
  4219. this.cff = cff;
  4220. // The first five sections must be in order, all the others are reached
  4221. // via offsets contained in one of the below.
  4222. var header = this.parseHeader();
  4223. var nameIndex = this.parseIndex(header.endPos);
  4224. var topDictIndex = this.parseIndex(nameIndex.endPos);
  4225. var stringIndex = this.parseIndex(topDictIndex.endPos);
  4226. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  4227. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  4228. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  4229. cff.header = header.obj;
  4230. cff.names = this.parseNameIndex(nameIndex.obj);
  4231. cff.strings = this.parseStringIndex(stringIndex.obj);
  4232. cff.topDict = topDict;
  4233. cff.globalSubrIndex = globalSubrIndex.obj;
  4234. this.parsePrivateDict(cff.topDict);
  4235. cff.isCIDFont = topDict.hasName('ROS');
  4236. var charStringOffset = topDict.getByName('CharStrings');
  4237. var charStringIndex = this.parseIndex(charStringOffset).obj;
  4238. var fontMatrix = topDict.getByName('FontMatrix');
  4239. if (fontMatrix) {
  4240. properties.fontMatrix = fontMatrix;
  4241. }
  4242. var fontBBox = topDict.getByName('FontBBox');
  4243. if (fontBBox) {
  4244. // adjusting ascent/descent
  4245. properties.ascent = fontBBox[3];
  4246. properties.descent = fontBBox[1];
  4247. properties.ascentScaled = true;
  4248. }
  4249. var charset, encoding;
  4250. if (cff.isCIDFont) {
  4251. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  4252. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  4253. var dictRaw = fdArrayIndex.get(i);
  4254. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  4255. cff.strings);
  4256. this.parsePrivateDict(fontDict);
  4257. cff.fdArray.push(fontDict);
  4258. }
  4259. // cid fonts don't have an encoding
  4260. encoding = null;
  4261. charset = this.parseCharsets(topDict.getByName('charset'),
  4262. charStringIndex.count, cff.strings, true);
  4263. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  4264. charStringIndex.count);
  4265. } else {
  4266. charset = this.parseCharsets(topDict.getByName('charset'),
  4267. charStringIndex.count, cff.strings, false);
  4268. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  4269. properties,
  4270. cff.strings, charset.charset);
  4271. }
  4272. cff.charset = charset;
  4273. cff.encoding = encoding;
  4274. var charStringsAndSeacs = this.parseCharStrings(
  4275. charStringIndex,
  4276. topDict.privateDict.subrsIndex,
  4277. globalSubrIndex.obj,
  4278. cff.fdSelect,
  4279. cff.fdArray);
  4280. cff.charStrings = charStringsAndSeacs.charStrings;
  4281. cff.seacs = charStringsAndSeacs.seacs;
  4282. cff.widths = charStringsAndSeacs.widths;
  4283. return cff;
  4284. },
  4285. parseHeader: function CFFParser_parseHeader() {
  4286. var bytes = this.bytes;
  4287. var bytesLength = bytes.length;
  4288. var offset = 0;
  4289. // Prevent an infinite loop, by checking that the offset is within the
  4290. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  4291. while (offset < bytesLength && bytes[offset] !== 1) {
  4292. ++offset;
  4293. }
  4294. if (offset >= bytesLength) {
  4295. error('Invalid CFF header');
  4296. } else if (offset !== 0) {
  4297. info('cff data is shifted');
  4298. bytes = bytes.subarray(offset);
  4299. this.bytes = bytes;
  4300. }
  4301. var major = bytes[0];
  4302. var minor = bytes[1];
  4303. var hdrSize = bytes[2];
  4304. var offSize = bytes[3];
  4305. var header = new CFFHeader(major, minor, hdrSize, offSize);
  4306. return { obj: header, endPos: hdrSize };
  4307. },
  4308. parseDict: function CFFParser_parseDict(dict) {
  4309. var pos = 0;
  4310. function parseOperand() {
  4311. var value = dict[pos++];
  4312. if (value === 30) {
  4313. return parseFloatOperand();
  4314. } else if (value === 28) {
  4315. value = dict[pos++];
  4316. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  4317. return value;
  4318. } else if (value === 29) {
  4319. value = dict[pos++];
  4320. value = (value << 8) | dict[pos++];
  4321. value = (value << 8) | dict[pos++];
  4322. value = (value << 8) | dict[pos++];
  4323. return value;
  4324. } else if (value >= 32 && value <= 246) {
  4325. return value - 139;
  4326. } else if (value >= 247 && value <= 250) {
  4327. return ((value - 247) * 256) + dict[pos++] + 108;
  4328. } else if (value >= 251 && value <= 254) {
  4329. return -((value - 251) * 256) - dict[pos++] - 108;
  4330. } else {
  4331. error('255 is not a valid DICT command');
  4332. }
  4333. return -1;
  4334. }
  4335. function parseFloatOperand() {
  4336. var str = '';
  4337. var eof = 15;
  4338. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  4339. '9', '.', 'E', 'E-', null, '-'];
  4340. var length = dict.length;
  4341. while (pos < length) {
  4342. var b = dict[pos++];
  4343. var b1 = b >> 4;
  4344. var b2 = b & 15;
  4345. if (b1 === eof) {
  4346. break;
  4347. }
  4348. str += lookup[b1];
  4349. if (b2 === eof) {
  4350. break;
  4351. }
  4352. str += lookup[b2];
  4353. }
  4354. return parseFloat(str);
  4355. }
  4356. var operands = [];
  4357. var entries = [];
  4358. pos = 0;
  4359. var end = dict.length;
  4360. while (pos < end) {
  4361. var b = dict[pos];
  4362. if (b <= 21) {
  4363. if (b === 12) {
  4364. b = (b << 8) | dict[++pos];
  4365. }
  4366. entries.push([b, operands]);
  4367. operands = [];
  4368. ++pos;
  4369. } else {
  4370. operands.push(parseOperand());
  4371. }
  4372. }
  4373. return entries;
  4374. },
  4375. parseIndex: function CFFParser_parseIndex(pos) {
  4376. var cffIndex = new CFFIndex();
  4377. var bytes = this.bytes;
  4378. var count = (bytes[pos++] << 8) | bytes[pos++];
  4379. var offsets = [];
  4380. var end = pos;
  4381. var i, ii;
  4382. if (count !== 0) {
  4383. var offsetSize = bytes[pos++];
  4384. // add 1 for offset to determine size of last object
  4385. var startPos = pos + ((count + 1) * offsetSize) - 1;
  4386. for (i = 0, ii = count + 1; i < ii; ++i) {
  4387. var offset = 0;
  4388. for (var j = 0; j < offsetSize; ++j) {
  4389. offset <<= 8;
  4390. offset += bytes[pos++];
  4391. }
  4392. offsets.push(startPos + offset);
  4393. }
  4394. end = offsets[count];
  4395. }
  4396. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  4397. var offsetStart = offsets[i];
  4398. var offsetEnd = offsets[i + 1];
  4399. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  4400. }
  4401. return {obj: cffIndex, endPos: end};
  4402. },
  4403. parseNameIndex: function CFFParser_parseNameIndex(index) {
  4404. var names = [];
  4405. for (var i = 0, ii = index.count; i < ii; ++i) {
  4406. var name = index.get(i);
  4407. // OTS doesn't allow names to be over 127 characters.
  4408. var length = Math.min(name.length, 127);
  4409. var data = [];
  4410. // OTS also only permits certain characters in the name.
  4411. for (var j = 0; j < length; ++j) {
  4412. var c = name[j];
  4413. if (j === 0 && c === 0) {
  4414. data[j] = c;
  4415. continue;
  4416. }
  4417. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  4418. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  4419. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  4420. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  4421. data[j] = 95;
  4422. continue;
  4423. }
  4424. data[j] = c;
  4425. }
  4426. names.push(bytesToString(data));
  4427. }
  4428. return names;
  4429. },
  4430. parseStringIndex: function CFFParser_parseStringIndex(index) {
  4431. var strings = new CFFStrings();
  4432. for (var i = 0, ii = index.count; i < ii; ++i) {
  4433. var data = index.get(i);
  4434. strings.add(bytesToString(data));
  4435. }
  4436. return strings;
  4437. },
  4438. createDict: function CFFParser_createDict(Type, dict, strings) {
  4439. var cffDict = new Type(strings);
  4440. for (var i = 0, ii = dict.length; i < ii; ++i) {
  4441. var pair = dict[i];
  4442. var key = pair[0];
  4443. var value = pair[1];
  4444. cffDict.setByKey(key, value);
  4445. }
  4446. return cffDict;
  4447. },
  4448. parseCharString: function CFFParser_parseCharString(state, data,
  4449. localSubrIndex,
  4450. globalSubrIndex) {
  4451. if (state.callDepth > MAX_SUBR_NESTING) {
  4452. return false;
  4453. }
  4454. var stackSize = state.stackSize;
  4455. var stack = state.stack;
  4456. var length = data.length;
  4457. for (var j = 0; j < length;) {
  4458. var value = data[j++];
  4459. var validationCommand = null;
  4460. if (value === 12) {
  4461. var q = data[j++];
  4462. if (q === 0) {
  4463. // The CFF specification state that the 'dotsection' command
  4464. // (12, 0) is deprecated and treated as a no-op, but all Type2
  4465. // charstrings processors should support them. Unfortunately
  4466. // the font sanitizer don't. As a workaround the sequence (12, 0)
  4467. // is replaced by a useless (0, hmoveto).
  4468. data[j - 2] = 139;
  4469. data[j - 1] = 22;
  4470. stackSize = 0;
  4471. } else {
  4472. validationCommand = CharstringValidationData12[q];
  4473. }
  4474. } else if (value === 28) { // number (16 bit)
  4475. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  4476. j += 2;
  4477. stackSize++;
  4478. } else if (value === 14) {
  4479. if (stackSize >= 4) {
  4480. stackSize -= 4;
  4481. if (this.seacAnalysisEnabled) {
  4482. state.seac = stack.slice(stackSize, stackSize + 4);
  4483. return false;
  4484. }
  4485. }
  4486. validationCommand = CharstringValidationData[value];
  4487. } else if (value >= 32 && value <= 246) { // number
  4488. stack[stackSize] = value - 139;
  4489. stackSize++;
  4490. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  4491. stack[stackSize] = (value < 251 ?
  4492. ((value - 247) << 8) + data[j] + 108 :
  4493. -((value - 251) << 8) - data[j] - 108);
  4494. j++;
  4495. stackSize++;
  4496. } else if (value === 255) { // number (32 bit)
  4497. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  4498. (data[j + 2] << 8) | data[j + 3]) / 65536;
  4499. j += 4;
  4500. stackSize++;
  4501. } else if (value === 19 || value === 20) {
  4502. state.hints += stackSize >> 1;
  4503. // skipping right amount of hints flag data
  4504. j += (state.hints + 7) >> 3;
  4505. stackSize %= 2;
  4506. validationCommand = CharstringValidationData[value];
  4507. } else if (value === 10 || value === 29) {
  4508. var subrsIndex;
  4509. if (value === 10) {
  4510. subrsIndex = localSubrIndex;
  4511. } else {
  4512. subrsIndex = globalSubrIndex;
  4513. }
  4514. if (!subrsIndex) {
  4515. validationCommand = CharstringValidationData[value];
  4516. warn('Missing subrsIndex for ' + validationCommand.id);
  4517. return false;
  4518. }
  4519. var bias = 32768;
  4520. if (subrsIndex.count < 1240) {
  4521. bias = 107;
  4522. } else if (subrsIndex.count < 33900) {
  4523. bias = 1131;
  4524. }
  4525. var subrNumber = stack[--stackSize] + bias;
  4526. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  4527. validationCommand = CharstringValidationData[value];
  4528. warn('Out of bounds subrIndex for ' + validationCommand.id);
  4529. return false;
  4530. }
  4531. state.stackSize = stackSize;
  4532. state.callDepth++;
  4533. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  4534. localSubrIndex, globalSubrIndex);
  4535. if (!valid) {
  4536. return false;
  4537. }
  4538. state.callDepth--;
  4539. stackSize = state.stackSize;
  4540. continue;
  4541. } else if (value === 11) {
  4542. state.stackSize = stackSize;
  4543. return true;
  4544. } else {
  4545. validationCommand = CharstringValidationData[value];
  4546. }
  4547. if (validationCommand) {
  4548. if (validationCommand.stem) {
  4549. state.hints += stackSize >> 1;
  4550. }
  4551. if ('min' in validationCommand) {
  4552. if (!state.undefStack && stackSize < validationCommand.min) {
  4553. warn('Not enough parameters for ' + validationCommand.id +
  4554. '; actual: ' + stackSize +
  4555. ', expected: ' + validationCommand.min);
  4556. return false;
  4557. }
  4558. }
  4559. if (state.firstStackClearing && validationCommand.stackClearing) {
  4560. state.firstStackClearing = false;
  4561. // the optional character width can be found before the first
  4562. // stack-clearing command arguments
  4563. stackSize -= validationCommand.min;
  4564. if (stackSize >= 2 && validationCommand.stem) {
  4565. // there are even amount of arguments for stem commands
  4566. stackSize %= 2;
  4567. } else if (stackSize > 1) {
  4568. warn('Found too many parameters for stack-clearing command');
  4569. }
  4570. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  4571. state.width = stack[stackSize - 1];
  4572. }
  4573. }
  4574. if ('stackDelta' in validationCommand) {
  4575. if ('stackFn' in validationCommand) {
  4576. validationCommand.stackFn(stack, stackSize);
  4577. }
  4578. stackSize += validationCommand.stackDelta;
  4579. } else if (validationCommand.stackClearing) {
  4580. stackSize = 0;
  4581. } else if (validationCommand.resetStack) {
  4582. stackSize = 0;
  4583. state.undefStack = false;
  4584. } else if (validationCommand.undefStack) {
  4585. stackSize = 0;
  4586. state.undefStack = true;
  4587. state.firstStackClearing = false;
  4588. }
  4589. }
  4590. }
  4591. state.stackSize = stackSize;
  4592. return true;
  4593. },
  4594. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  4595. localSubrIndex,
  4596. globalSubrIndex,
  4597. fdSelect,
  4598. fdArray) {
  4599. var seacs = [];
  4600. var widths = [];
  4601. var count = charStrings.count;
  4602. for (var i = 0; i < count; i++) {
  4603. var charstring = charStrings.get(i);
  4604. var state = {
  4605. callDepth: 0,
  4606. stackSize: 0,
  4607. stack: [],
  4608. undefStack: true,
  4609. hints: 0,
  4610. firstStackClearing: true,
  4611. seac: null,
  4612. width: null
  4613. };
  4614. var valid = true;
  4615. var localSubrToUse = null;
  4616. if (fdSelect && fdArray.length) {
  4617. var fdIndex = fdSelect.getFDIndex(i);
  4618. if (fdIndex === -1) {
  4619. warn('Glyph index is not in fd select.');
  4620. valid = false;
  4621. }
  4622. if (fdIndex >= fdArray.length) {
  4623. warn('Invalid fd index for glyph index.');
  4624. valid = false;
  4625. }
  4626. if (valid) {
  4627. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  4628. }
  4629. } else if (localSubrIndex) {
  4630. localSubrToUse = localSubrIndex;
  4631. }
  4632. if (valid) {
  4633. valid = this.parseCharString(state, charstring, localSubrToUse,
  4634. globalSubrIndex);
  4635. }
  4636. if (state.width !== null) {
  4637. widths[i] = state.width;
  4638. }
  4639. if (state.seac !== null) {
  4640. seacs[i] = state.seac;
  4641. }
  4642. if (!valid) {
  4643. // resetting invalid charstring to single 'endchar'
  4644. charStrings.set(i, new Uint8Array([14]));
  4645. }
  4646. }
  4647. return { charStrings: charStrings, seacs: seacs, widths: widths };
  4648. },
  4649. emptyPrivateDictionary:
  4650. function CFFParser_emptyPrivateDictionary(parentDict) {
  4651. var privateDict = this.createDict(CFFPrivateDict, [],
  4652. parentDict.strings);
  4653. parentDict.setByKey(18, [0, 0]);
  4654. parentDict.privateDict = privateDict;
  4655. },
  4656. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  4657. // no private dict, do nothing
  4658. if (!parentDict.hasName('Private')) {
  4659. this.emptyPrivateDictionary(parentDict);
  4660. return;
  4661. }
  4662. var privateOffset = parentDict.getByName('Private');
  4663. // make sure the params are formatted correctly
  4664. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  4665. parentDict.removeByName('Private');
  4666. return;
  4667. }
  4668. var size = privateOffset[0];
  4669. var offset = privateOffset[1];
  4670. // remove empty dicts or ones that refer to invalid location
  4671. if (size === 0 || offset >= this.bytes.length) {
  4672. this.emptyPrivateDictionary(parentDict);
  4673. return;
  4674. }
  4675. var privateDictEnd = offset + size;
  4676. var dictData = this.bytes.subarray(offset, privateDictEnd);
  4677. var dict = this.parseDict(dictData);
  4678. var privateDict = this.createDict(CFFPrivateDict, dict,
  4679. parentDict.strings);
  4680. parentDict.privateDict = privateDict;
  4681. // Parse the Subrs index also since it's relative to the private dict.
  4682. if (!privateDict.getByName('Subrs')) {
  4683. return;
  4684. }
  4685. var subrsOffset = privateDict.getByName('Subrs');
  4686. var relativeOffset = offset + subrsOffset;
  4687. // Validate the offset.
  4688. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  4689. this.emptyPrivateDictionary(parentDict);
  4690. return;
  4691. }
  4692. var subrsIndex = this.parseIndex(relativeOffset);
  4693. privateDict.subrsIndex = subrsIndex.obj;
  4694. },
  4695. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  4696. if (pos === 0) {
  4697. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  4698. ISOAdobeCharset);
  4699. } else if (pos === 1) {
  4700. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  4701. ExpertCharset);
  4702. } else if (pos === 2) {
  4703. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  4704. ExpertSubsetCharset);
  4705. }
  4706. var bytes = this.bytes;
  4707. var start = pos;
  4708. var format = bytes[pos++];
  4709. var charset = ['.notdef'];
  4710. var id, count, i;
  4711. // subtract 1 for the .notdef glyph
  4712. length -= 1;
  4713. switch (format) {
  4714. case 0:
  4715. for (i = 0; i < length; i++) {
  4716. id = (bytes[pos++] << 8) | bytes[pos++];
  4717. charset.push(cid ? id : strings.get(id));
  4718. }
  4719. break;
  4720. case 1:
  4721. while (charset.length <= length) {
  4722. id = (bytes[pos++] << 8) | bytes[pos++];
  4723. count = bytes[pos++];
  4724. for (i = 0; i <= count; i++) {
  4725. charset.push(cid ? id++ : strings.get(id++));
  4726. }
  4727. }
  4728. break;
  4729. case 2:
  4730. while (charset.length <= length) {
  4731. id = (bytes[pos++] << 8) | bytes[pos++];
  4732. count = (bytes[pos++] << 8) | bytes[pos++];
  4733. for (i = 0; i <= count; i++) {
  4734. charset.push(cid ? id++ : strings.get(id++));
  4735. }
  4736. }
  4737. break;
  4738. default:
  4739. error('Unknown charset format');
  4740. }
  4741. // Raw won't be needed if we actually compile the charset.
  4742. var end = pos;
  4743. var raw = bytes.subarray(start, end);
  4744. return new CFFCharset(false, format, charset, raw);
  4745. },
  4746. parseEncoding: function CFFParser_parseEncoding(pos,
  4747. properties,
  4748. strings,
  4749. charset) {
  4750. var encoding = Object.create(null);
  4751. var bytes = this.bytes;
  4752. var predefined = false;
  4753. var hasSupplement = false;
  4754. var format, i, ii;
  4755. var raw = null;
  4756. function readSupplement() {
  4757. var supplementsCount = bytes[pos++];
  4758. for (i = 0; i < supplementsCount; i++) {
  4759. var code = bytes[pos++];
  4760. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  4761. encoding[code] = charset.indexOf(strings.get(sid));
  4762. }
  4763. }
  4764. if (pos === 0 || pos === 1) {
  4765. predefined = true;
  4766. format = pos;
  4767. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  4768. for (i = 0, ii = charset.length; i < ii; i++) {
  4769. var index = baseEncoding.indexOf(charset[i]);
  4770. if (index !== -1) {
  4771. encoding[index] = i;
  4772. }
  4773. }
  4774. } else {
  4775. var dataStart = pos;
  4776. format = bytes[pos++];
  4777. switch (format & 0x7f) {
  4778. case 0:
  4779. var glyphsCount = bytes[pos++];
  4780. for (i = 1; i <= glyphsCount; i++) {
  4781. encoding[bytes[pos++]] = i;
  4782. }
  4783. break;
  4784. case 1:
  4785. var rangesCount = bytes[pos++];
  4786. var gid = 1;
  4787. for (i = 0; i < rangesCount; i++) {
  4788. var start = bytes[pos++];
  4789. var left = bytes[pos++];
  4790. for (var j = start; j <= start + left; j++) {
  4791. encoding[j] = gid++;
  4792. }
  4793. }
  4794. break;
  4795. default:
  4796. error('Unknown encoding format: ' + format + ' in CFF');
  4797. break;
  4798. }
  4799. var dataEnd = pos;
  4800. if (format & 0x80) {
  4801. // The font sanitizer does not support CFF encoding with a
  4802. // supplement, since the encoding is not really used to map
  4803. // between gid to glyph, let's overwrite what is declared in
  4804. // the top dictionary to let the sanitizer think the font use
  4805. // StandardEncoding, that's a lie but that's ok.
  4806. bytes[dataStart] &= 0x7f;
  4807. readSupplement();
  4808. hasSupplement = true;
  4809. }
  4810. raw = bytes.subarray(dataStart, dataEnd);
  4811. }
  4812. format = format & 0x7f;
  4813. return new CFFEncoding(predefined, format, encoding, raw);
  4814. },
  4815. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  4816. var start = pos;
  4817. var bytes = this.bytes;
  4818. var format = bytes[pos++];
  4819. var fdSelect = [], rawBytes;
  4820. var i, invalidFirstGID = false;
  4821. switch (format) {
  4822. case 0:
  4823. for (i = 0; i < length; ++i) {
  4824. var id = bytes[pos++];
  4825. fdSelect.push(id);
  4826. }
  4827. rawBytes = bytes.subarray(start, pos);
  4828. break;
  4829. case 3:
  4830. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  4831. for (i = 0; i < rangesCount; ++i) {
  4832. var first = (bytes[pos++] << 8) | bytes[pos++];
  4833. if (i === 0 && first !== 0) {
  4834. warn('parseFDSelect: The first range must have a first GID of 0' +
  4835. ' -- trying to recover.');
  4836. invalidFirstGID = true;
  4837. first = 0;
  4838. }
  4839. var fdIndex = bytes[pos++];
  4840. var next = (bytes[pos] << 8) | bytes[pos + 1];
  4841. for (var j = first; j < next; ++j) {
  4842. fdSelect.push(fdIndex);
  4843. }
  4844. }
  4845. // Advance past the sentinel(next).
  4846. pos += 2;
  4847. rawBytes = bytes.subarray(start, pos);
  4848. if (invalidFirstGID) {
  4849. rawBytes[3] = rawBytes[4] = 0; // Adjust the first range, first GID.
  4850. }
  4851. break;
  4852. default:
  4853. error('parseFDSelect: Unknown format "' + format + '".');
  4854. break;
  4855. }
  4856. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  4857. return new CFFFDSelect(fdSelect, rawBytes);
  4858. }
  4859. };
  4860. return CFFParser;
  4861. })();
  4862. // Compact Font Format
  4863. var CFF = (function CFFClosure() {
  4864. function CFF() {
  4865. this.header = null;
  4866. this.names = [];
  4867. this.topDict = null;
  4868. this.strings = new CFFStrings();
  4869. this.globalSubrIndex = null;
  4870. // The following could really be per font, but since we only have one font
  4871. // store them here.
  4872. this.encoding = null;
  4873. this.charset = null;
  4874. this.charStrings = null;
  4875. this.fdArray = [];
  4876. this.fdSelect = null;
  4877. this.isCIDFont = false;
  4878. }
  4879. return CFF;
  4880. })();
  4881. var CFFHeader = (function CFFHeaderClosure() {
  4882. function CFFHeader(major, minor, hdrSize, offSize) {
  4883. this.major = major;
  4884. this.minor = minor;
  4885. this.hdrSize = hdrSize;
  4886. this.offSize = offSize;
  4887. }
  4888. return CFFHeader;
  4889. })();
  4890. var CFFStrings = (function CFFStringsClosure() {
  4891. function CFFStrings() {
  4892. this.strings = [];
  4893. }
  4894. CFFStrings.prototype = {
  4895. get: function CFFStrings_get(index) {
  4896. if (index >= 0 && index <= 390) {
  4897. return CFFStandardStrings[index];
  4898. }
  4899. if (index - 391 <= this.strings.length) {
  4900. return this.strings[index - 391];
  4901. }
  4902. return CFFStandardStrings[0];
  4903. },
  4904. add: function CFFStrings_add(value) {
  4905. this.strings.push(value);
  4906. },
  4907. get count() {
  4908. return this.strings.length;
  4909. }
  4910. };
  4911. return CFFStrings;
  4912. })();
  4913. var CFFIndex = (function CFFIndexClosure() {
  4914. function CFFIndex() {
  4915. this.objects = [];
  4916. this.length = 0;
  4917. }
  4918. CFFIndex.prototype = {
  4919. add: function CFFIndex_add(data) {
  4920. this.length += data.length;
  4921. this.objects.push(data);
  4922. },
  4923. set: function CFFIndex_set(index, data) {
  4924. this.length += data.length - this.objects[index].length;
  4925. this.objects[index] = data;
  4926. },
  4927. get: function CFFIndex_get(index) {
  4928. return this.objects[index];
  4929. },
  4930. get count() {
  4931. return this.objects.length;
  4932. }
  4933. };
  4934. return CFFIndex;
  4935. })();
  4936. var CFFDict = (function CFFDictClosure() {
  4937. function CFFDict(tables, strings) {
  4938. this.keyToNameMap = tables.keyToNameMap;
  4939. this.nameToKeyMap = tables.nameToKeyMap;
  4940. this.defaults = tables.defaults;
  4941. this.types = tables.types;
  4942. this.opcodes = tables.opcodes;
  4943. this.order = tables.order;
  4944. this.strings = strings;
  4945. this.values = Object.create(null);
  4946. }
  4947. CFFDict.prototype = {
  4948. // value should always be an array
  4949. setByKey: function CFFDict_setByKey(key, value) {
  4950. if (!(key in this.keyToNameMap)) {
  4951. return false;
  4952. }
  4953. // ignore empty values
  4954. if (value.length === 0) {
  4955. return true;
  4956. }
  4957. var type = this.types[key];
  4958. // remove the array wrapping these types of values
  4959. if (type === 'num' || type === 'sid' || type === 'offset') {
  4960. value = value[0];
  4961. // Ignore invalid values (fixes bug 1068432).
  4962. if (isNaN(value)) {
  4963. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  4964. return true;
  4965. }
  4966. }
  4967. this.values[key] = value;
  4968. return true;
  4969. },
  4970. setByName: function CFFDict_setByName(name, value) {
  4971. if (!(name in this.nameToKeyMap)) {
  4972. error('Invalid dictionary name "' + name + '"');
  4973. }
  4974. this.values[this.nameToKeyMap[name]] = value;
  4975. },
  4976. hasName: function CFFDict_hasName(name) {
  4977. return this.nameToKeyMap[name] in this.values;
  4978. },
  4979. getByName: function CFFDict_getByName(name) {
  4980. if (!(name in this.nameToKeyMap)) {
  4981. error('Invalid dictionary name "' + name + '"');
  4982. }
  4983. var key = this.nameToKeyMap[name];
  4984. if (!(key in this.values)) {
  4985. return this.defaults[key];
  4986. }
  4987. return this.values[key];
  4988. },
  4989. removeByName: function CFFDict_removeByName(name) {
  4990. delete this.values[this.nameToKeyMap[name]];
  4991. }
  4992. };
  4993. CFFDict.createTables = function CFFDict_createTables(layout) {
  4994. var tables = {
  4995. keyToNameMap: {},
  4996. nameToKeyMap: {},
  4997. defaults: {},
  4998. types: {},
  4999. opcodes: {},
  5000. order: []
  5001. };
  5002. for (var i = 0, ii = layout.length; i < ii; ++i) {
  5003. var entry = layout[i];
  5004. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  5005. tables.keyToNameMap[key] = entry[1];
  5006. tables.nameToKeyMap[entry[1]] = key;
  5007. tables.types[key] = entry[2];
  5008. tables.defaults[key] = entry[3];
  5009. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  5010. tables.order.push(key);
  5011. }
  5012. return tables;
  5013. };
  5014. return CFFDict;
  5015. })();
  5016. var CFFTopDict = (function CFFTopDictClosure() {
  5017. var layout = [
  5018. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  5019. [[12, 20], 'SyntheticBase', 'num', null],
  5020. [0, 'version', 'sid', null],
  5021. [1, 'Notice', 'sid', null],
  5022. [[12, 0], 'Copyright', 'sid', null],
  5023. [2, 'FullName', 'sid', null],
  5024. [3, 'FamilyName', 'sid', null],
  5025. [4, 'Weight', 'sid', null],
  5026. [[12, 1], 'isFixedPitch', 'num', 0],
  5027. [[12, 2], 'ItalicAngle', 'num', 0],
  5028. [[12, 3], 'UnderlinePosition', 'num', -100],
  5029. [[12, 4], 'UnderlineThickness', 'num', 50],
  5030. [[12, 5], 'PaintType', 'num', 0],
  5031. [[12, 6], 'CharstringType', 'num', 2],
  5032. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  5033. [0.001, 0, 0, 0.001, 0, 0]],
  5034. [13, 'UniqueID', 'num', null],
  5035. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  5036. [[12, 8], 'StrokeWidth', 'num', 0],
  5037. [14, 'XUID', 'array', null],
  5038. [15, 'charset', 'offset', 0],
  5039. [16, 'Encoding', 'offset', 0],
  5040. [17, 'CharStrings', 'offset', 0],
  5041. [18, 'Private', ['offset', 'offset'], null],
  5042. [[12, 21], 'PostScript', 'sid', null],
  5043. [[12, 22], 'BaseFontName', 'sid', null],
  5044. [[12, 23], 'BaseFontBlend', 'delta', null],
  5045. [[12, 31], 'CIDFontVersion', 'num', 0],
  5046. [[12, 32], 'CIDFontRevision', 'num', 0],
  5047. [[12, 33], 'CIDFontType', 'num', 0],
  5048. [[12, 34], 'CIDCount', 'num', 8720],
  5049. [[12, 35], 'UIDBase', 'num', null],
  5050. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  5051. // before FDArray.
  5052. [[12, 37], 'FDSelect', 'offset', null],
  5053. [[12, 36], 'FDArray', 'offset', null],
  5054. [[12, 38], 'FontName', 'sid', null]
  5055. ];
  5056. var tables = null;
  5057. function CFFTopDict(strings) {
  5058. if (tables === null) {
  5059. tables = CFFDict.createTables(layout);
  5060. }
  5061. CFFDict.call(this, tables, strings);
  5062. this.privateDict = null;
  5063. }
  5064. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  5065. return CFFTopDict;
  5066. })();
  5067. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  5068. var layout = [
  5069. [6, 'BlueValues', 'delta', null],
  5070. [7, 'OtherBlues', 'delta', null],
  5071. [8, 'FamilyBlues', 'delta', null],
  5072. [9, 'FamilyOtherBlues', 'delta', null],
  5073. [[12, 9], 'BlueScale', 'num', 0.039625],
  5074. [[12, 10], 'BlueShift', 'num', 7],
  5075. [[12, 11], 'BlueFuzz', 'num', 1],
  5076. [10, 'StdHW', 'num', null],
  5077. [11, 'StdVW', 'num', null],
  5078. [[12, 12], 'StemSnapH', 'delta', null],
  5079. [[12, 13], 'StemSnapV', 'delta', null],
  5080. [[12, 14], 'ForceBold', 'num', 0],
  5081. [[12, 17], 'LanguageGroup', 'num', 0],
  5082. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  5083. [[12, 19], 'initialRandomSeed', 'num', 0],
  5084. [20, 'defaultWidthX', 'num', 0],
  5085. [21, 'nominalWidthX', 'num', 0],
  5086. [19, 'Subrs', 'offset', null]
  5087. ];
  5088. var tables = null;
  5089. function CFFPrivateDict(strings) {
  5090. if (tables === null) {
  5091. tables = CFFDict.createTables(layout);
  5092. }
  5093. CFFDict.call(this, tables, strings);
  5094. this.subrsIndex = null;
  5095. }
  5096. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  5097. return CFFPrivateDict;
  5098. })();
  5099. var CFFCharsetPredefinedTypes = {
  5100. ISO_ADOBE: 0,
  5101. EXPERT: 1,
  5102. EXPERT_SUBSET: 2
  5103. };
  5104. var CFFCharset = (function CFFCharsetClosure() {
  5105. function CFFCharset(predefined, format, charset, raw) {
  5106. this.predefined = predefined;
  5107. this.format = format;
  5108. this.charset = charset;
  5109. this.raw = raw;
  5110. }
  5111. return CFFCharset;
  5112. })();
  5113. var CFFEncoding = (function CFFEncodingClosure() {
  5114. function CFFEncoding(predefined, format, encoding, raw) {
  5115. this.predefined = predefined;
  5116. this.format = format;
  5117. this.encoding = encoding;
  5118. this.raw = raw;
  5119. }
  5120. return CFFEncoding;
  5121. })();
  5122. var CFFFDSelect = (function CFFFDSelectClosure() {
  5123. function CFFFDSelect(fdSelect, raw) {
  5124. this.fdSelect = fdSelect;
  5125. this.raw = raw;
  5126. }
  5127. CFFFDSelect.prototype = {
  5128. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  5129. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  5130. return -1;
  5131. }
  5132. return this.fdSelect[glyphIndex];
  5133. }
  5134. };
  5135. return CFFFDSelect;
  5136. })();
  5137. // Helper class to keep track of where an offset is within the data and helps
  5138. // filling in that offset once it's known.
  5139. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  5140. function CFFOffsetTracker() {
  5141. this.offsets = Object.create(null);
  5142. }
  5143. CFFOffsetTracker.prototype = {
  5144. isTracking: function CFFOffsetTracker_isTracking(key) {
  5145. return key in this.offsets;
  5146. },
  5147. track: function CFFOffsetTracker_track(key, location) {
  5148. if (key in this.offsets) {
  5149. error('Already tracking location of ' + key);
  5150. }
  5151. this.offsets[key] = location;
  5152. },
  5153. offset: function CFFOffsetTracker_offset(value) {
  5154. for (var key in this.offsets) {
  5155. this.offsets[key] += value;
  5156. }
  5157. },
  5158. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  5159. values,
  5160. output) {
  5161. if (!(key in this.offsets)) {
  5162. error('Not tracking location of ' + key);
  5163. }
  5164. var data = output.data;
  5165. var dataOffset = this.offsets[key];
  5166. var size = 5;
  5167. for (var i = 0, ii = values.length; i < ii; ++i) {
  5168. var offset0 = i * size + dataOffset;
  5169. var offset1 = offset0 + 1;
  5170. var offset2 = offset0 + 2;
  5171. var offset3 = offset0 + 3;
  5172. var offset4 = offset0 + 4;
  5173. // It's easy to screw up offsets so perform this sanity check.
  5174. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  5175. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  5176. error('writing to an offset that is not empty');
  5177. }
  5178. var value = values[i];
  5179. data[offset0] = 0x1d;
  5180. data[offset1] = (value >> 24) & 0xFF;
  5181. data[offset2] = (value >> 16) & 0xFF;
  5182. data[offset3] = (value >> 8) & 0xFF;
  5183. data[offset4] = value & 0xFF;
  5184. }
  5185. }
  5186. };
  5187. return CFFOffsetTracker;
  5188. })();
  5189. // Takes a CFF and converts it to the binary representation.
  5190. var CFFCompiler = (function CFFCompilerClosure() {
  5191. function CFFCompiler(cff) {
  5192. this.cff = cff;
  5193. }
  5194. CFFCompiler.prototype = {
  5195. compile: function CFFCompiler_compile() {
  5196. var cff = this.cff;
  5197. var output = {
  5198. data: [],
  5199. length: 0,
  5200. add: function CFFCompiler_add(data) {
  5201. this.data = this.data.concat(data);
  5202. this.length = this.data.length;
  5203. }
  5204. };
  5205. // Compile the five entries that must be in order.
  5206. var header = this.compileHeader(cff.header);
  5207. output.add(header);
  5208. var nameIndex = this.compileNameIndex(cff.names);
  5209. output.add(nameIndex);
  5210. if (cff.isCIDFont) {
  5211. // The spec is unclear on how font matrices should relate to each other
  5212. // when there is one in the main top dict and the sub top dicts.
  5213. // Windows handles this differently than linux and osx so we have to
  5214. // normalize to work on all.
  5215. // Rules based off of some mailing list discussions:
  5216. // - If main font has a matrix and subfont doesn't, use the main matrix.
  5217. // - If no main font matrix and there is a subfont matrix, use the
  5218. // subfont matrix.
  5219. // - If both have matrices, concat together.
  5220. // - If neither have matrices, use default.
  5221. // To make this work on all platforms we move the top matrix into each
  5222. // sub top dict and concat if necessary.
  5223. if (cff.topDict.hasName('FontMatrix')) {
  5224. var base = cff.topDict.getByName('FontMatrix');
  5225. cff.topDict.removeByName('FontMatrix');
  5226. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  5227. var subDict = cff.fdArray[i];
  5228. var matrix = base.slice(0);
  5229. if (subDict.hasName('FontMatrix')) {
  5230. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  5231. }
  5232. subDict.setByName('FontMatrix', matrix);
  5233. }
  5234. }
  5235. }
  5236. var compiled = this.compileTopDicts([cff.topDict],
  5237. output.length,
  5238. cff.isCIDFont);
  5239. output.add(compiled.output);
  5240. var topDictTracker = compiled.trackers[0];
  5241. var stringIndex = this.compileStringIndex(cff.strings.strings);
  5242. output.add(stringIndex);
  5243. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  5244. output.add(globalSubrIndex);
  5245. // Now start on the other entries that have no specific order.
  5246. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  5247. if (cff.encoding.predefined) {
  5248. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  5249. output);
  5250. } else {
  5251. var encoding = this.compileEncoding(cff.encoding);
  5252. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  5253. output.add(encoding);
  5254. }
  5255. }
  5256. if (cff.charset && cff.topDict.hasName('charset')) {
  5257. if (cff.charset.predefined) {
  5258. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  5259. output);
  5260. } else {
  5261. var charset = this.compileCharset(cff.charset);
  5262. topDictTracker.setEntryLocation('charset', [output.length], output);
  5263. output.add(charset);
  5264. }
  5265. }
  5266. var charStrings = this.compileCharStrings(cff.charStrings);
  5267. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  5268. output.add(charStrings);
  5269. if (cff.isCIDFont) {
  5270. // For some reason FDSelect must be in front of FDArray on windows. OSX
  5271. // and linux don't seem to care.
  5272. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  5273. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  5274. output.add(fdSelect);
  5275. // It is unclear if the sub font dictionary can have CID related
  5276. // dictionary keys, but the sanitizer doesn't like them so remove them.
  5277. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  5278. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  5279. output.add(compiled.output);
  5280. var fontDictTrackers = compiled.trackers;
  5281. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  5282. }
  5283. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  5284. // If the font data ends with INDEX whose object data is zero-length,
  5285. // the sanitizer will bail out. Add a dummy byte to avoid that.
  5286. output.add([0]);
  5287. return output.data;
  5288. },
  5289. encodeNumber: function CFFCompiler_encodeNumber(value) {
  5290. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  5291. return this.encodeInteger(value);
  5292. } else {
  5293. return this.encodeFloat(value);
  5294. }
  5295. },
  5296. encodeFloat: function CFFCompiler_encodeFloat(num) {
  5297. var value = num.toString();
  5298. // rounding inaccurate doubles
  5299. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  5300. if (m) {
  5301. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  5302. value = (Math.round(num * epsilon) / epsilon).toString();
  5303. }
  5304. var nibbles = '';
  5305. var i, ii;
  5306. for (i = 0, ii = value.length; i < ii; ++i) {
  5307. var a = value[i];
  5308. if (a === 'e') {
  5309. nibbles += value[++i] === '-' ? 'c' : 'b';
  5310. } else if (a === '.') {
  5311. nibbles += 'a';
  5312. } else if (a === '-') {
  5313. nibbles += 'e';
  5314. } else {
  5315. nibbles += a;
  5316. }
  5317. }
  5318. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  5319. var out = [30];
  5320. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  5321. out.push(parseInt(nibbles.substr(i, 2), 16));
  5322. }
  5323. return out;
  5324. },
  5325. encodeInteger: function CFFCompiler_encodeInteger(value) {
  5326. var code;
  5327. if (value >= -107 && value <= 107) {
  5328. code = [value + 139];
  5329. } else if (value >= 108 && value <= 1131) {
  5330. value = value - 108;
  5331. code = [(value >> 8) + 247, value & 0xFF];
  5332. } else if (value >= -1131 && value <= -108) {
  5333. value = -value - 108;
  5334. code = [(value >> 8) + 251, value & 0xFF];
  5335. } else if (value >= -32768 && value <= 32767) {
  5336. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  5337. } else {
  5338. code = [0x1d,
  5339. (value >> 24) & 0xFF,
  5340. (value >> 16) & 0xFF,
  5341. (value >> 8) & 0xFF,
  5342. value & 0xFF];
  5343. }
  5344. return code;
  5345. },
  5346. compileHeader: function CFFCompiler_compileHeader(header) {
  5347. return [
  5348. header.major,
  5349. header.minor,
  5350. header.hdrSize,
  5351. header.offSize
  5352. ];
  5353. },
  5354. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  5355. var nameIndex = new CFFIndex();
  5356. for (var i = 0, ii = names.length; i < ii; ++i) {
  5357. nameIndex.add(stringToBytes(names[i]));
  5358. }
  5359. return this.compileIndex(nameIndex);
  5360. },
  5361. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  5362. length,
  5363. removeCidKeys) {
  5364. var fontDictTrackers = [];
  5365. var fdArrayIndex = new CFFIndex();
  5366. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  5367. var fontDict = dicts[i];
  5368. if (removeCidKeys) {
  5369. fontDict.removeByName('CIDFontVersion');
  5370. fontDict.removeByName('CIDFontRevision');
  5371. fontDict.removeByName('CIDFontType');
  5372. fontDict.removeByName('CIDCount');
  5373. fontDict.removeByName('UIDBase');
  5374. }
  5375. var fontDictTracker = new CFFOffsetTracker();
  5376. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  5377. fontDictTrackers.push(fontDictTracker);
  5378. fdArrayIndex.add(fontDictData);
  5379. fontDictTracker.offset(length);
  5380. }
  5381. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  5382. return {
  5383. trackers: fontDictTrackers,
  5384. output: fdArrayIndex
  5385. };
  5386. },
  5387. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  5388. trackers,
  5389. output) {
  5390. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  5391. var fontDict = dicts[i];
  5392. assert(fontDict.privateDict && fontDict.hasName('Private'),
  5393. 'There must be an private dictionary.');
  5394. var privateDict = fontDict.privateDict;
  5395. var privateDictTracker = new CFFOffsetTracker();
  5396. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  5397. var outputLength = output.length;
  5398. privateDictTracker.offset(outputLength);
  5399. if (!privateDictData.length) {
  5400. // The private dictionary was empty, set the output length to zero to
  5401. // ensure the offset length isn't out of bounds in the eyes of the
  5402. // sanitizer.
  5403. outputLength = 0;
  5404. }
  5405. trackers[i].setEntryLocation('Private',
  5406. [privateDictData.length, outputLength],
  5407. output);
  5408. output.add(privateDictData);
  5409. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  5410. var subrs = this.compileIndex(privateDict.subrsIndex);
  5411. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  5412. output);
  5413. output.add(subrs);
  5414. }
  5415. }
  5416. },
  5417. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  5418. var out = [];
  5419. // The dictionary keys must be in a certain order.
  5420. var order = dict.order;
  5421. for (var i = 0; i < order.length; ++i) {
  5422. var key = order[i];
  5423. if (!(key in dict.values)) {
  5424. continue;
  5425. }
  5426. var values = dict.values[key];
  5427. var types = dict.types[key];
  5428. if (!isArray(types)) {
  5429. types = [types];
  5430. }
  5431. if (!isArray(values)) {
  5432. values = [values];
  5433. }
  5434. // Remove any empty dict values.
  5435. if (values.length === 0) {
  5436. continue;
  5437. }
  5438. for (var j = 0, jj = types.length; j < jj; ++j) {
  5439. var type = types[j];
  5440. var value = values[j];
  5441. switch (type) {
  5442. case 'num':
  5443. case 'sid':
  5444. out = out.concat(this.encodeNumber(value));
  5445. break;
  5446. case 'offset':
  5447. // For offsets we just insert a 32bit integer so we don't have to
  5448. // deal with figuring out the length of the offset when it gets
  5449. // replaced later on by the compiler.
  5450. var name = dict.keyToNameMap[key];
  5451. // Some offsets have the offset and the length, so just record the
  5452. // position of the first one.
  5453. if (!offsetTracker.isTracking(name)) {
  5454. offsetTracker.track(name, out.length);
  5455. }
  5456. out = out.concat([0x1d, 0, 0, 0, 0]);
  5457. break;
  5458. case 'array':
  5459. case 'delta':
  5460. out = out.concat(this.encodeNumber(value));
  5461. for (var k = 1, kk = values.length; k < kk; ++k) {
  5462. out = out.concat(this.encodeNumber(values[k]));
  5463. }
  5464. break;
  5465. default:
  5466. error('Unknown data type of ' + type);
  5467. break;
  5468. }
  5469. }
  5470. out = out.concat(dict.opcodes[key]);
  5471. }
  5472. return out;
  5473. },
  5474. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  5475. var stringIndex = new CFFIndex();
  5476. for (var i = 0, ii = strings.length; i < ii; ++i) {
  5477. stringIndex.add(stringToBytes(strings[i]));
  5478. }
  5479. return this.compileIndex(stringIndex);
  5480. },
  5481. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  5482. var globalSubrIndex = this.cff.globalSubrIndex;
  5483. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  5484. },
  5485. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  5486. return this.compileIndex(charStrings);
  5487. },
  5488. compileCharset: function CFFCompiler_compileCharset(charset) {
  5489. return this.compileTypedArray(charset.raw);
  5490. },
  5491. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  5492. return this.compileTypedArray(encoding.raw);
  5493. },
  5494. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  5495. return this.compileTypedArray(fdSelect);
  5496. },
  5497. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  5498. var out = [];
  5499. for (var i = 0, ii = data.length; i < ii; ++i) {
  5500. out[i] = data[i];
  5501. }
  5502. return out;
  5503. },
  5504. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  5505. trackers = trackers || [];
  5506. var objects = index.objects;
  5507. // First 2 bytes contains the number of objects contained into this index
  5508. var count = objects.length;
  5509. // If there is no object, just create an index. This technically
  5510. // should just be [0, 0] but OTS has an issue with that.
  5511. if (count === 0) {
  5512. return [0, 0, 0];
  5513. }
  5514. var data = [(count >> 8) & 0xFF, count & 0xff];
  5515. var lastOffset = 1, i;
  5516. for (i = 0; i < count; ++i) {
  5517. lastOffset += objects[i].length;
  5518. }
  5519. var offsetSize;
  5520. if (lastOffset < 0x100) {
  5521. offsetSize = 1;
  5522. } else if (lastOffset < 0x10000) {
  5523. offsetSize = 2;
  5524. } else if (lastOffset < 0x1000000) {
  5525. offsetSize = 3;
  5526. } else {
  5527. offsetSize = 4;
  5528. }
  5529. // Next byte contains the offset size use to reference object in the file
  5530. data.push(offsetSize);
  5531. // Add another offset after this one because we need a new offset
  5532. var relativeOffset = 1;
  5533. for (i = 0; i < count + 1; i++) {
  5534. if (offsetSize === 1) {
  5535. data.push(relativeOffset & 0xFF);
  5536. } else if (offsetSize === 2) {
  5537. data.push((relativeOffset >> 8) & 0xFF,
  5538. relativeOffset & 0xFF);
  5539. } else if (offsetSize === 3) {
  5540. data.push((relativeOffset >> 16) & 0xFF,
  5541. (relativeOffset >> 8) & 0xFF,
  5542. relativeOffset & 0xFF);
  5543. } else {
  5544. data.push((relativeOffset >>> 24) & 0xFF,
  5545. (relativeOffset >> 16) & 0xFF,
  5546. (relativeOffset >> 8) & 0xFF,
  5547. relativeOffset & 0xFF);
  5548. }
  5549. if (objects[i]) {
  5550. relativeOffset += objects[i].length;
  5551. }
  5552. }
  5553. for (i = 0; i < count; i++) {
  5554. // Notify the tracker where the object will be offset in the data.
  5555. if (trackers[i]) {
  5556. trackers[i].offset(data.length);
  5557. }
  5558. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  5559. data.push(objects[i][j]);
  5560. }
  5561. }
  5562. return data;
  5563. }
  5564. };
  5565. return CFFCompiler;
  5566. })();
  5567. exports.CFFStandardStrings = CFFStandardStrings;
  5568. exports.CFFParser = CFFParser;
  5569. exports.CFF = CFF;
  5570. exports.CFFHeader = CFFHeader;
  5571. exports.CFFStrings = CFFStrings;
  5572. exports.CFFIndex = CFFIndex;
  5573. exports.CFFCharset = CFFCharset;
  5574. exports.CFFTopDict = CFFTopDict;
  5575. exports.CFFPrivateDict = CFFPrivateDict;
  5576. exports.CFFCompiler = CFFCompiler;
  5577. }));
  5578. (function (root, factory) {
  5579. {
  5580. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  5581. }
  5582. }(this, function (exports, sharedUtil) {
  5583. var MissingDataException = sharedUtil.MissingDataException;
  5584. var arrayByteLength = sharedUtil.arrayByteLength;
  5585. var arraysToBytes = sharedUtil.arraysToBytes;
  5586. var assert = sharedUtil.assert;
  5587. var createPromiseCapability = sharedUtil.createPromiseCapability;
  5588. var isInt = sharedUtil.isInt;
  5589. var isEmptyObj = sharedUtil.isEmptyObj;
  5590. var ChunkedStream = (function ChunkedStreamClosure() {
  5591. function ChunkedStream(length, chunkSize, manager) {
  5592. this.bytes = new Uint8Array(length);
  5593. this.start = 0;
  5594. this.pos = 0;
  5595. this.end = length;
  5596. this.chunkSize = chunkSize;
  5597. this.loadedChunks = [];
  5598. this.numChunksLoaded = 0;
  5599. this.numChunks = Math.ceil(length / chunkSize);
  5600. this.manager = manager;
  5601. this.progressiveDataLength = 0;
  5602. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  5603. }
  5604. // required methods for a stream. if a particular stream does not
  5605. // implement these, an error should be thrown
  5606. ChunkedStream.prototype = {
  5607. getMissingChunks: function ChunkedStream_getMissingChunks() {
  5608. var chunks = [];
  5609. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  5610. if (!this.loadedChunks[chunk]) {
  5611. chunks.push(chunk);
  5612. }
  5613. }
  5614. return chunks;
  5615. },
  5616. getBaseStreams: function ChunkedStream_getBaseStreams() {
  5617. return [this];
  5618. },
  5619. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  5620. return this.numChunksLoaded === this.numChunks;
  5621. },
  5622. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  5623. var end = begin + chunk.byteLength;
  5624. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  5625. // Using this.length is inaccurate here since this.start can be moved
  5626. // See ChunkedStream.moveStart()
  5627. var length = this.bytes.length;
  5628. assert(end % this.chunkSize === 0 || end === length,
  5629. 'Bad end offset: ' + end);
  5630. this.bytes.set(new Uint8Array(chunk), begin);
  5631. var chunkSize = this.chunkSize;
  5632. var beginChunk = Math.floor(begin / chunkSize);
  5633. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5634. var curChunk;
  5635. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5636. if (!this.loadedChunks[curChunk]) {
  5637. this.loadedChunks[curChunk] = true;
  5638. ++this.numChunksLoaded;
  5639. }
  5640. }
  5641. },
  5642. onReceiveProgressiveData:
  5643. function ChunkedStream_onReceiveProgressiveData(data) {
  5644. var position = this.progressiveDataLength;
  5645. var beginChunk = Math.floor(position / this.chunkSize);
  5646. this.bytes.set(new Uint8Array(data), position);
  5647. position += data.byteLength;
  5648. this.progressiveDataLength = position;
  5649. var endChunk = position >= this.end ? this.numChunks :
  5650. Math.floor(position / this.chunkSize);
  5651. var curChunk;
  5652. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5653. if (!this.loadedChunks[curChunk]) {
  5654. this.loadedChunks[curChunk] = true;
  5655. ++this.numChunksLoaded;
  5656. }
  5657. }
  5658. },
  5659. ensureByte: function ChunkedStream_ensureByte(pos) {
  5660. var chunk = Math.floor(pos / this.chunkSize);
  5661. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  5662. return;
  5663. }
  5664. if (!this.loadedChunks[chunk]) {
  5665. throw new MissingDataException(pos, pos + 1);
  5666. }
  5667. this.lastSuccessfulEnsureByteChunk = chunk;
  5668. },
  5669. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  5670. if (begin >= end) {
  5671. return;
  5672. }
  5673. if (end <= this.progressiveDataLength) {
  5674. return;
  5675. }
  5676. var chunkSize = this.chunkSize;
  5677. var beginChunk = Math.floor(begin / chunkSize);
  5678. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5679. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5680. if (!this.loadedChunks[chunk]) {
  5681. throw new MissingDataException(begin, end);
  5682. }
  5683. }
  5684. },
  5685. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  5686. var chunk, numChunks = this.numChunks;
  5687. for (var i = 0; i < numChunks; ++i) {
  5688. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  5689. if (!this.loadedChunks[chunk]) {
  5690. return chunk;
  5691. }
  5692. }
  5693. return null;
  5694. },
  5695. hasChunk: function ChunkedStream_hasChunk(chunk) {
  5696. return !!this.loadedChunks[chunk];
  5697. },
  5698. get length() {
  5699. return this.end - this.start;
  5700. },
  5701. get isEmpty() {
  5702. return this.length === 0;
  5703. },
  5704. getByte: function ChunkedStream_getByte() {
  5705. var pos = this.pos;
  5706. if (pos >= this.end) {
  5707. return -1;
  5708. }
  5709. this.ensureByte(pos);
  5710. return this.bytes[this.pos++];
  5711. },
  5712. getUint16: function ChunkedStream_getUint16() {
  5713. var b0 = this.getByte();
  5714. var b1 = this.getByte();
  5715. if (b0 === -1 || b1 === -1) {
  5716. return -1;
  5717. }
  5718. return (b0 << 8) + b1;
  5719. },
  5720. getInt32: function ChunkedStream_getInt32() {
  5721. var b0 = this.getByte();
  5722. var b1 = this.getByte();
  5723. var b2 = this.getByte();
  5724. var b3 = this.getByte();
  5725. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  5726. },
  5727. // returns subarray of original buffer
  5728. // should only be read
  5729. getBytes: function ChunkedStream_getBytes(length) {
  5730. var bytes = this.bytes;
  5731. var pos = this.pos;
  5732. var strEnd = this.end;
  5733. if (!length) {
  5734. this.ensureRange(pos, strEnd);
  5735. return bytes.subarray(pos, strEnd);
  5736. }
  5737. var end = pos + length;
  5738. if (end > strEnd) {
  5739. end = strEnd;
  5740. }
  5741. this.ensureRange(pos, end);
  5742. this.pos = end;
  5743. return bytes.subarray(pos, end);
  5744. },
  5745. peekByte: function ChunkedStream_peekByte() {
  5746. var peekedByte = this.getByte();
  5747. this.pos--;
  5748. return peekedByte;
  5749. },
  5750. peekBytes: function ChunkedStream_peekBytes(length) {
  5751. var bytes = this.getBytes(length);
  5752. this.pos -= bytes.length;
  5753. return bytes;
  5754. },
  5755. getByteRange: function ChunkedStream_getBytes(begin, end) {
  5756. this.ensureRange(begin, end);
  5757. return this.bytes.subarray(begin, end);
  5758. },
  5759. skip: function ChunkedStream_skip(n) {
  5760. if (!n) {
  5761. n = 1;
  5762. }
  5763. this.pos += n;
  5764. },
  5765. reset: function ChunkedStream_reset() {
  5766. this.pos = this.start;
  5767. },
  5768. moveStart: function ChunkedStream_moveStart() {
  5769. this.start = this.pos;
  5770. },
  5771. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  5772. this.ensureRange(start, start + length);
  5773. function ChunkedStreamSubstream() {}
  5774. ChunkedStreamSubstream.prototype = Object.create(this);
  5775. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  5776. var chunkSize = this.chunkSize;
  5777. var beginChunk = Math.floor(this.start / chunkSize);
  5778. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  5779. var missingChunks = [];
  5780. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5781. if (!this.loadedChunks[chunk]) {
  5782. missingChunks.push(chunk);
  5783. }
  5784. }
  5785. return missingChunks;
  5786. };
  5787. var subStream = new ChunkedStreamSubstream();
  5788. subStream.pos = subStream.start = start;
  5789. subStream.end = start + length || this.end;
  5790. subStream.dict = dict;
  5791. return subStream;
  5792. },
  5793. isStream: true
  5794. };
  5795. return ChunkedStream;
  5796. })();
  5797. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  5798. function ChunkedStreamManager(pdfNetworkStream, args) {
  5799. var chunkSize = args.rangeChunkSize;
  5800. var length = args.length;
  5801. this.stream = new ChunkedStream(length, chunkSize, this);
  5802. this.length = length;
  5803. this.chunkSize = chunkSize;
  5804. this.pdfNetworkStream = pdfNetworkStream;
  5805. this.url = args.url;
  5806. this.disableAutoFetch = args.disableAutoFetch;
  5807. this.msgHandler = args.msgHandler;
  5808. this.currRequestId = 0;
  5809. this.chunksNeededByRequest = Object.create(null);
  5810. this.requestsByChunk = Object.create(null);
  5811. this.promisesByRequest = Object.create(null);
  5812. this.progressiveDataLength = 0;
  5813. this.aborted = false;
  5814. this._loadedStreamCapability = createPromiseCapability();
  5815. }
  5816. ChunkedStreamManager.prototype = {
  5817. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  5818. return this._loadedStreamCapability.promise;
  5819. },
  5820. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  5821. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  5822. if (!rangeReader.isStreamingSupported) {
  5823. rangeReader.onProgress = this.onProgress.bind(this);
  5824. }
  5825. var chunks = [], loaded = 0;
  5826. var manager = this;
  5827. var promise = new Promise(function (resolve, reject) {
  5828. var readChunk = function (chunk) {
  5829. try {
  5830. if (!chunk.done) {
  5831. var data = chunk.value;
  5832. chunks.push(data);
  5833. loaded += arrayByteLength(data);
  5834. if (rangeReader.isStreamingSupported) {
  5835. manager.onProgress({loaded: loaded});
  5836. }
  5837. rangeReader.read().then(readChunk, reject);
  5838. return;
  5839. }
  5840. var chunkData = arraysToBytes(chunks);
  5841. chunks = null;
  5842. resolve(chunkData);
  5843. } catch (e) {
  5844. reject(e);
  5845. }
  5846. };
  5847. rangeReader.read().then(readChunk, reject);
  5848. });
  5849. promise.then(function (data) {
  5850. if (this.aborted) {
  5851. return; // ignoring any data after abort
  5852. }
  5853. this.onReceiveData({chunk: data, begin: begin});
  5854. }.bind(this));
  5855. // TODO check errors
  5856. },
  5857. // Get all the chunks that are not yet loaded and groups them into
  5858. // contiguous ranges to load in as few requests as possible
  5859. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  5860. var missingChunks = this.stream.getMissingChunks();
  5861. this._requestChunks(missingChunks);
  5862. return this._loadedStreamCapability.promise;
  5863. },
  5864. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  5865. var requestId = this.currRequestId++;
  5866. var i, ii;
  5867. var chunksNeeded = Object.create(null);
  5868. this.chunksNeededByRequest[requestId] = chunksNeeded;
  5869. for (i = 0, ii = chunks.length; i < ii; i++) {
  5870. if (!this.stream.hasChunk(chunks[i])) {
  5871. chunksNeeded[chunks[i]] = true;
  5872. }
  5873. }
  5874. if (isEmptyObj(chunksNeeded)) {
  5875. return Promise.resolve();
  5876. }
  5877. var capability = createPromiseCapability();
  5878. this.promisesByRequest[requestId] = capability;
  5879. var chunksToRequest = [];
  5880. for (var chunk in chunksNeeded) {
  5881. chunk = chunk | 0;
  5882. if (!(chunk in this.requestsByChunk)) {
  5883. this.requestsByChunk[chunk] = [];
  5884. chunksToRequest.push(chunk);
  5885. }
  5886. this.requestsByChunk[chunk].push(requestId);
  5887. }
  5888. if (!chunksToRequest.length) {
  5889. return capability.promise;
  5890. }
  5891. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  5892. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  5893. var groupedChunk = groupedChunksToRequest[i];
  5894. var begin = groupedChunk.beginChunk * this.chunkSize;
  5895. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  5896. this.sendRequest(begin, end);
  5897. }
  5898. return capability.promise;
  5899. },
  5900. getStream: function ChunkedStreamManager_getStream() {
  5901. return this.stream;
  5902. },
  5903. // Loads any chunks in the requested range that are not yet loaded
  5904. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  5905. end = Math.min(end, this.length);
  5906. var beginChunk = this.getBeginChunk(begin);
  5907. var endChunk = this.getEndChunk(end);
  5908. var chunks = [];
  5909. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5910. chunks.push(chunk);
  5911. }
  5912. return this._requestChunks(chunks);
  5913. },
  5914. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  5915. ranges = ranges || [];
  5916. var chunksToRequest = [];
  5917. for (var i = 0; i < ranges.length; i++) {
  5918. var beginChunk = this.getBeginChunk(ranges[i].begin);
  5919. var endChunk = this.getEndChunk(ranges[i].end);
  5920. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5921. if (chunksToRequest.indexOf(chunk) < 0) {
  5922. chunksToRequest.push(chunk);
  5923. }
  5924. }
  5925. }
  5926. chunksToRequest.sort(function(a, b) { return a - b; });
  5927. return this._requestChunks(chunksToRequest);
  5928. },
  5929. // Groups a sorted array of chunks into as few contiguous larger
  5930. // chunks as possible
  5931. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  5932. var groupedChunks = [];
  5933. var beginChunk = -1;
  5934. var prevChunk = -1;
  5935. for (var i = 0; i < chunks.length; ++i) {
  5936. var chunk = chunks[i];
  5937. if (beginChunk < 0) {
  5938. beginChunk = chunk;
  5939. }
  5940. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  5941. groupedChunks.push({ beginChunk: beginChunk,
  5942. endChunk: prevChunk + 1 });
  5943. beginChunk = chunk;
  5944. }
  5945. if (i + 1 === chunks.length) {
  5946. groupedChunks.push({ beginChunk: beginChunk,
  5947. endChunk: chunk + 1 });
  5948. }
  5949. prevChunk = chunk;
  5950. }
  5951. return groupedChunks;
  5952. },
  5953. onProgress: function ChunkedStreamManager_onProgress(args) {
  5954. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  5955. args.loaded);
  5956. this.msgHandler.send('DocProgress', {
  5957. loaded: bytesLoaded,
  5958. total: this.length
  5959. });
  5960. },
  5961. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  5962. var chunk = args.chunk;
  5963. var isProgressive = args.begin === undefined;
  5964. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  5965. var end = begin + chunk.byteLength;
  5966. var beginChunk = Math.floor(begin / this.chunkSize);
  5967. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  5968. Math.ceil(end / this.chunkSize);
  5969. if (isProgressive) {
  5970. this.stream.onReceiveProgressiveData(chunk);
  5971. this.progressiveDataLength = end;
  5972. } else {
  5973. this.stream.onReceiveData(begin, chunk);
  5974. }
  5975. if (this.stream.allChunksLoaded()) {
  5976. this._loadedStreamCapability.resolve(this.stream);
  5977. }
  5978. var loadedRequests = [];
  5979. var i, requestId;
  5980. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  5981. // The server might return more chunks than requested
  5982. var requestIds = this.requestsByChunk[chunk] || [];
  5983. delete this.requestsByChunk[chunk];
  5984. for (i = 0; i < requestIds.length; ++i) {
  5985. requestId = requestIds[i];
  5986. var chunksNeeded = this.chunksNeededByRequest[requestId];
  5987. if (chunk in chunksNeeded) {
  5988. delete chunksNeeded[chunk];
  5989. }
  5990. if (!isEmptyObj(chunksNeeded)) {
  5991. continue;
  5992. }
  5993. loadedRequests.push(requestId);
  5994. }
  5995. }
  5996. // If there are no pending requests, automatically fetch the next
  5997. // unfetched chunk of the PDF
  5998. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  5999. var nextEmptyChunk;
  6000. if (this.stream.numChunksLoaded === 1) {
  6001. // This is a special optimization so that after fetching the first
  6002. // chunk, rather than fetching the second chunk, we fetch the last
  6003. // chunk.
  6004. var lastChunk = this.stream.numChunks - 1;
  6005. if (!this.stream.hasChunk(lastChunk)) {
  6006. nextEmptyChunk = lastChunk;
  6007. }
  6008. } else {
  6009. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  6010. }
  6011. if (isInt(nextEmptyChunk)) {
  6012. this._requestChunks([nextEmptyChunk]);
  6013. }
  6014. }
  6015. for (i = 0; i < loadedRequests.length; ++i) {
  6016. requestId = loadedRequests[i];
  6017. var capability = this.promisesByRequest[requestId];
  6018. delete this.promisesByRequest[requestId];
  6019. capability.resolve();
  6020. }
  6021. this.msgHandler.send('DocProgress', {
  6022. loaded: this.stream.numChunksLoaded * this.chunkSize,
  6023. total: this.length
  6024. });
  6025. },
  6026. onError: function ChunkedStreamManager_onError(err) {
  6027. this._loadedStreamCapability.reject(err);
  6028. },
  6029. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  6030. var chunk = Math.floor(begin / this.chunkSize);
  6031. return chunk;
  6032. },
  6033. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  6034. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  6035. return chunk;
  6036. },
  6037. abort: function ChunkedStreamManager_abort() {
  6038. this.aborted = true;
  6039. if (this.pdfNetworkStream) {
  6040. this.pdfNetworkStream.cancelAllRequests('abort');
  6041. }
  6042. for(var requestId in this.promisesByRequest) {
  6043. var capability = this.promisesByRequest[requestId];
  6044. capability.reject(new Error('Request was aborted'));
  6045. }
  6046. }
  6047. };
  6048. return ChunkedStreamManager;
  6049. })();
  6050. exports.ChunkedStream = ChunkedStream;
  6051. exports.ChunkedStreamManager = ChunkedStreamManager;
  6052. }));
  6053. (function (root, factory) {
  6054. {
  6055. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  6056. }
  6057. }(this, function (exports, sharedUtil) {
  6058. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  6059. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  6060. t['A'] = 0x0041;
  6061. t['AE'] = 0x00C6;
  6062. t['AEacute'] = 0x01FC;
  6063. t['AEmacron'] = 0x01E2;
  6064. t['AEsmall'] = 0xF7E6;
  6065. t['Aacute'] = 0x00C1;
  6066. t['Aacutesmall'] = 0xF7E1;
  6067. t['Abreve'] = 0x0102;
  6068. t['Abreveacute'] = 0x1EAE;
  6069. t['Abrevecyrillic'] = 0x04D0;
  6070. t['Abrevedotbelow'] = 0x1EB6;
  6071. t['Abrevegrave'] = 0x1EB0;
  6072. t['Abrevehookabove'] = 0x1EB2;
  6073. t['Abrevetilde'] = 0x1EB4;
  6074. t['Acaron'] = 0x01CD;
  6075. t['Acircle'] = 0x24B6;
  6076. t['Acircumflex'] = 0x00C2;
  6077. t['Acircumflexacute'] = 0x1EA4;
  6078. t['Acircumflexdotbelow'] = 0x1EAC;
  6079. t['Acircumflexgrave'] = 0x1EA6;
  6080. t['Acircumflexhookabove'] = 0x1EA8;
  6081. t['Acircumflexsmall'] = 0xF7E2;
  6082. t['Acircumflextilde'] = 0x1EAA;
  6083. t['Acute'] = 0xF6C9;
  6084. t['Acutesmall'] = 0xF7B4;
  6085. t['Acyrillic'] = 0x0410;
  6086. t['Adblgrave'] = 0x0200;
  6087. t['Adieresis'] = 0x00C4;
  6088. t['Adieresiscyrillic'] = 0x04D2;
  6089. t['Adieresismacron'] = 0x01DE;
  6090. t['Adieresissmall'] = 0xF7E4;
  6091. t['Adotbelow'] = 0x1EA0;
  6092. t['Adotmacron'] = 0x01E0;
  6093. t['Agrave'] = 0x00C0;
  6094. t['Agravesmall'] = 0xF7E0;
  6095. t['Ahookabove'] = 0x1EA2;
  6096. t['Aiecyrillic'] = 0x04D4;
  6097. t['Ainvertedbreve'] = 0x0202;
  6098. t['Alpha'] = 0x0391;
  6099. t['Alphatonos'] = 0x0386;
  6100. t['Amacron'] = 0x0100;
  6101. t['Amonospace'] = 0xFF21;
  6102. t['Aogonek'] = 0x0104;
  6103. t['Aring'] = 0x00C5;
  6104. t['Aringacute'] = 0x01FA;
  6105. t['Aringbelow'] = 0x1E00;
  6106. t['Aringsmall'] = 0xF7E5;
  6107. t['Asmall'] = 0xF761;
  6108. t['Atilde'] = 0x00C3;
  6109. t['Atildesmall'] = 0xF7E3;
  6110. t['Aybarmenian'] = 0x0531;
  6111. t['B'] = 0x0042;
  6112. t['Bcircle'] = 0x24B7;
  6113. t['Bdotaccent'] = 0x1E02;
  6114. t['Bdotbelow'] = 0x1E04;
  6115. t['Becyrillic'] = 0x0411;
  6116. t['Benarmenian'] = 0x0532;
  6117. t['Beta'] = 0x0392;
  6118. t['Bhook'] = 0x0181;
  6119. t['Blinebelow'] = 0x1E06;
  6120. t['Bmonospace'] = 0xFF22;
  6121. t['Brevesmall'] = 0xF6F4;
  6122. t['Bsmall'] = 0xF762;
  6123. t['Btopbar'] = 0x0182;
  6124. t['C'] = 0x0043;
  6125. t['Caarmenian'] = 0x053E;
  6126. t['Cacute'] = 0x0106;
  6127. t['Caron'] = 0xF6CA;
  6128. t['Caronsmall'] = 0xF6F5;
  6129. t['Ccaron'] = 0x010C;
  6130. t['Ccedilla'] = 0x00C7;
  6131. t['Ccedillaacute'] = 0x1E08;
  6132. t['Ccedillasmall'] = 0xF7E7;
  6133. t['Ccircle'] = 0x24B8;
  6134. t['Ccircumflex'] = 0x0108;
  6135. t['Cdot'] = 0x010A;
  6136. t['Cdotaccent'] = 0x010A;
  6137. t['Cedillasmall'] = 0xF7B8;
  6138. t['Chaarmenian'] = 0x0549;
  6139. t['Cheabkhasiancyrillic'] = 0x04BC;
  6140. t['Checyrillic'] = 0x0427;
  6141. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  6142. t['Chedescendercyrillic'] = 0x04B6;
  6143. t['Chedieresiscyrillic'] = 0x04F4;
  6144. t['Cheharmenian'] = 0x0543;
  6145. t['Chekhakassiancyrillic'] = 0x04CB;
  6146. t['Cheverticalstrokecyrillic'] = 0x04B8;
  6147. t['Chi'] = 0x03A7;
  6148. t['Chook'] = 0x0187;
  6149. t['Circumflexsmall'] = 0xF6F6;
  6150. t['Cmonospace'] = 0xFF23;
  6151. t['Coarmenian'] = 0x0551;
  6152. t['Csmall'] = 0xF763;
  6153. t['D'] = 0x0044;
  6154. t['DZ'] = 0x01F1;
  6155. t['DZcaron'] = 0x01C4;
  6156. t['Daarmenian'] = 0x0534;
  6157. t['Dafrican'] = 0x0189;
  6158. t['Dcaron'] = 0x010E;
  6159. t['Dcedilla'] = 0x1E10;
  6160. t['Dcircle'] = 0x24B9;
  6161. t['Dcircumflexbelow'] = 0x1E12;
  6162. t['Dcroat'] = 0x0110;
  6163. t['Ddotaccent'] = 0x1E0A;
  6164. t['Ddotbelow'] = 0x1E0C;
  6165. t['Decyrillic'] = 0x0414;
  6166. t['Deicoptic'] = 0x03EE;
  6167. t['Delta'] = 0x2206;
  6168. t['Deltagreek'] = 0x0394;
  6169. t['Dhook'] = 0x018A;
  6170. t['Dieresis'] = 0xF6CB;
  6171. t['DieresisAcute'] = 0xF6CC;
  6172. t['DieresisGrave'] = 0xF6CD;
  6173. t['Dieresissmall'] = 0xF7A8;
  6174. t['Digammagreek'] = 0x03DC;
  6175. t['Djecyrillic'] = 0x0402;
  6176. t['Dlinebelow'] = 0x1E0E;
  6177. t['Dmonospace'] = 0xFF24;
  6178. t['Dotaccentsmall'] = 0xF6F7;
  6179. t['Dslash'] = 0x0110;
  6180. t['Dsmall'] = 0xF764;
  6181. t['Dtopbar'] = 0x018B;
  6182. t['Dz'] = 0x01F2;
  6183. t['Dzcaron'] = 0x01C5;
  6184. t['Dzeabkhasiancyrillic'] = 0x04E0;
  6185. t['Dzecyrillic'] = 0x0405;
  6186. t['Dzhecyrillic'] = 0x040F;
  6187. t['E'] = 0x0045;
  6188. t['Eacute'] = 0x00C9;
  6189. t['Eacutesmall'] = 0xF7E9;
  6190. t['Ebreve'] = 0x0114;
  6191. t['Ecaron'] = 0x011A;
  6192. t['Ecedillabreve'] = 0x1E1C;
  6193. t['Echarmenian'] = 0x0535;
  6194. t['Ecircle'] = 0x24BA;
  6195. t['Ecircumflex'] = 0x00CA;
  6196. t['Ecircumflexacute'] = 0x1EBE;
  6197. t['Ecircumflexbelow'] = 0x1E18;
  6198. t['Ecircumflexdotbelow'] = 0x1EC6;
  6199. t['Ecircumflexgrave'] = 0x1EC0;
  6200. t['Ecircumflexhookabove'] = 0x1EC2;
  6201. t['Ecircumflexsmall'] = 0xF7EA;
  6202. t['Ecircumflextilde'] = 0x1EC4;
  6203. t['Ecyrillic'] = 0x0404;
  6204. t['Edblgrave'] = 0x0204;
  6205. t['Edieresis'] = 0x00CB;
  6206. t['Edieresissmall'] = 0xF7EB;
  6207. t['Edot'] = 0x0116;
  6208. t['Edotaccent'] = 0x0116;
  6209. t['Edotbelow'] = 0x1EB8;
  6210. t['Efcyrillic'] = 0x0424;
  6211. t['Egrave'] = 0x00C8;
  6212. t['Egravesmall'] = 0xF7E8;
  6213. t['Eharmenian'] = 0x0537;
  6214. t['Ehookabove'] = 0x1EBA;
  6215. t['Eightroman'] = 0x2167;
  6216. t['Einvertedbreve'] = 0x0206;
  6217. t['Eiotifiedcyrillic'] = 0x0464;
  6218. t['Elcyrillic'] = 0x041B;
  6219. t['Elevenroman'] = 0x216A;
  6220. t['Emacron'] = 0x0112;
  6221. t['Emacronacute'] = 0x1E16;
  6222. t['Emacrongrave'] = 0x1E14;
  6223. t['Emcyrillic'] = 0x041C;
  6224. t['Emonospace'] = 0xFF25;
  6225. t['Encyrillic'] = 0x041D;
  6226. t['Endescendercyrillic'] = 0x04A2;
  6227. t['Eng'] = 0x014A;
  6228. t['Enghecyrillic'] = 0x04A4;
  6229. t['Enhookcyrillic'] = 0x04C7;
  6230. t['Eogonek'] = 0x0118;
  6231. t['Eopen'] = 0x0190;
  6232. t['Epsilon'] = 0x0395;
  6233. t['Epsilontonos'] = 0x0388;
  6234. t['Ercyrillic'] = 0x0420;
  6235. t['Ereversed'] = 0x018E;
  6236. t['Ereversedcyrillic'] = 0x042D;
  6237. t['Escyrillic'] = 0x0421;
  6238. t['Esdescendercyrillic'] = 0x04AA;
  6239. t['Esh'] = 0x01A9;
  6240. t['Esmall'] = 0xF765;
  6241. t['Eta'] = 0x0397;
  6242. t['Etarmenian'] = 0x0538;
  6243. t['Etatonos'] = 0x0389;
  6244. t['Eth'] = 0x00D0;
  6245. t['Ethsmall'] = 0xF7F0;
  6246. t['Etilde'] = 0x1EBC;
  6247. t['Etildebelow'] = 0x1E1A;
  6248. t['Euro'] = 0x20AC;
  6249. t['Ezh'] = 0x01B7;
  6250. t['Ezhcaron'] = 0x01EE;
  6251. t['Ezhreversed'] = 0x01B8;
  6252. t['F'] = 0x0046;
  6253. t['Fcircle'] = 0x24BB;
  6254. t['Fdotaccent'] = 0x1E1E;
  6255. t['Feharmenian'] = 0x0556;
  6256. t['Feicoptic'] = 0x03E4;
  6257. t['Fhook'] = 0x0191;
  6258. t['Fitacyrillic'] = 0x0472;
  6259. t['Fiveroman'] = 0x2164;
  6260. t['Fmonospace'] = 0xFF26;
  6261. t['Fourroman'] = 0x2163;
  6262. t['Fsmall'] = 0xF766;
  6263. t['G'] = 0x0047;
  6264. t['GBsquare'] = 0x3387;
  6265. t['Gacute'] = 0x01F4;
  6266. t['Gamma'] = 0x0393;
  6267. t['Gammaafrican'] = 0x0194;
  6268. t['Gangiacoptic'] = 0x03EA;
  6269. t['Gbreve'] = 0x011E;
  6270. t['Gcaron'] = 0x01E6;
  6271. t['Gcedilla'] = 0x0122;
  6272. t['Gcircle'] = 0x24BC;
  6273. t['Gcircumflex'] = 0x011C;
  6274. t['Gcommaaccent'] = 0x0122;
  6275. t['Gdot'] = 0x0120;
  6276. t['Gdotaccent'] = 0x0120;
  6277. t['Gecyrillic'] = 0x0413;
  6278. t['Ghadarmenian'] = 0x0542;
  6279. t['Ghemiddlehookcyrillic'] = 0x0494;
  6280. t['Ghestrokecyrillic'] = 0x0492;
  6281. t['Gheupturncyrillic'] = 0x0490;
  6282. t['Ghook'] = 0x0193;
  6283. t['Gimarmenian'] = 0x0533;
  6284. t['Gjecyrillic'] = 0x0403;
  6285. t['Gmacron'] = 0x1E20;
  6286. t['Gmonospace'] = 0xFF27;
  6287. t['Grave'] = 0xF6CE;
  6288. t['Gravesmall'] = 0xF760;
  6289. t['Gsmall'] = 0xF767;
  6290. t['Gsmallhook'] = 0x029B;
  6291. t['Gstroke'] = 0x01E4;
  6292. t['H'] = 0x0048;
  6293. t['H18533'] = 0x25CF;
  6294. t['H18543'] = 0x25AA;
  6295. t['H18551'] = 0x25AB;
  6296. t['H22073'] = 0x25A1;
  6297. t['HPsquare'] = 0x33CB;
  6298. t['Haabkhasiancyrillic'] = 0x04A8;
  6299. t['Hadescendercyrillic'] = 0x04B2;
  6300. t['Hardsigncyrillic'] = 0x042A;
  6301. t['Hbar'] = 0x0126;
  6302. t['Hbrevebelow'] = 0x1E2A;
  6303. t['Hcedilla'] = 0x1E28;
  6304. t['Hcircle'] = 0x24BD;
  6305. t['Hcircumflex'] = 0x0124;
  6306. t['Hdieresis'] = 0x1E26;
  6307. t['Hdotaccent'] = 0x1E22;
  6308. t['Hdotbelow'] = 0x1E24;
  6309. t['Hmonospace'] = 0xFF28;
  6310. t['Hoarmenian'] = 0x0540;
  6311. t['Horicoptic'] = 0x03E8;
  6312. t['Hsmall'] = 0xF768;
  6313. t['Hungarumlaut'] = 0xF6CF;
  6314. t['Hungarumlautsmall'] = 0xF6F8;
  6315. t['Hzsquare'] = 0x3390;
  6316. t['I'] = 0x0049;
  6317. t['IAcyrillic'] = 0x042F;
  6318. t['IJ'] = 0x0132;
  6319. t['IUcyrillic'] = 0x042E;
  6320. t['Iacute'] = 0x00CD;
  6321. t['Iacutesmall'] = 0xF7ED;
  6322. t['Ibreve'] = 0x012C;
  6323. t['Icaron'] = 0x01CF;
  6324. t['Icircle'] = 0x24BE;
  6325. t['Icircumflex'] = 0x00CE;
  6326. t['Icircumflexsmall'] = 0xF7EE;
  6327. t['Icyrillic'] = 0x0406;
  6328. t['Idblgrave'] = 0x0208;
  6329. t['Idieresis'] = 0x00CF;
  6330. t['Idieresisacute'] = 0x1E2E;
  6331. t['Idieresiscyrillic'] = 0x04E4;
  6332. t['Idieresissmall'] = 0xF7EF;
  6333. t['Idot'] = 0x0130;
  6334. t['Idotaccent'] = 0x0130;
  6335. t['Idotbelow'] = 0x1ECA;
  6336. t['Iebrevecyrillic'] = 0x04D6;
  6337. t['Iecyrillic'] = 0x0415;
  6338. t['Ifraktur'] = 0x2111;
  6339. t['Igrave'] = 0x00CC;
  6340. t['Igravesmall'] = 0xF7EC;
  6341. t['Ihookabove'] = 0x1EC8;
  6342. t['Iicyrillic'] = 0x0418;
  6343. t['Iinvertedbreve'] = 0x020A;
  6344. t['Iishortcyrillic'] = 0x0419;
  6345. t['Imacron'] = 0x012A;
  6346. t['Imacroncyrillic'] = 0x04E2;
  6347. t['Imonospace'] = 0xFF29;
  6348. t['Iniarmenian'] = 0x053B;
  6349. t['Iocyrillic'] = 0x0401;
  6350. t['Iogonek'] = 0x012E;
  6351. t['Iota'] = 0x0399;
  6352. t['Iotaafrican'] = 0x0196;
  6353. t['Iotadieresis'] = 0x03AA;
  6354. t['Iotatonos'] = 0x038A;
  6355. t['Ismall'] = 0xF769;
  6356. t['Istroke'] = 0x0197;
  6357. t['Itilde'] = 0x0128;
  6358. t['Itildebelow'] = 0x1E2C;
  6359. t['Izhitsacyrillic'] = 0x0474;
  6360. t['Izhitsadblgravecyrillic'] = 0x0476;
  6361. t['J'] = 0x004A;
  6362. t['Jaarmenian'] = 0x0541;
  6363. t['Jcircle'] = 0x24BF;
  6364. t['Jcircumflex'] = 0x0134;
  6365. t['Jecyrillic'] = 0x0408;
  6366. t['Jheharmenian'] = 0x054B;
  6367. t['Jmonospace'] = 0xFF2A;
  6368. t['Jsmall'] = 0xF76A;
  6369. t['K'] = 0x004B;
  6370. t['KBsquare'] = 0x3385;
  6371. t['KKsquare'] = 0x33CD;
  6372. t['Kabashkircyrillic'] = 0x04A0;
  6373. t['Kacute'] = 0x1E30;
  6374. t['Kacyrillic'] = 0x041A;
  6375. t['Kadescendercyrillic'] = 0x049A;
  6376. t['Kahookcyrillic'] = 0x04C3;
  6377. t['Kappa'] = 0x039A;
  6378. t['Kastrokecyrillic'] = 0x049E;
  6379. t['Kaverticalstrokecyrillic'] = 0x049C;
  6380. t['Kcaron'] = 0x01E8;
  6381. t['Kcedilla'] = 0x0136;
  6382. t['Kcircle'] = 0x24C0;
  6383. t['Kcommaaccent'] = 0x0136;
  6384. t['Kdotbelow'] = 0x1E32;
  6385. t['Keharmenian'] = 0x0554;
  6386. t['Kenarmenian'] = 0x053F;
  6387. t['Khacyrillic'] = 0x0425;
  6388. t['Kheicoptic'] = 0x03E6;
  6389. t['Khook'] = 0x0198;
  6390. t['Kjecyrillic'] = 0x040C;
  6391. t['Klinebelow'] = 0x1E34;
  6392. t['Kmonospace'] = 0xFF2B;
  6393. t['Koppacyrillic'] = 0x0480;
  6394. t['Koppagreek'] = 0x03DE;
  6395. t['Ksicyrillic'] = 0x046E;
  6396. t['Ksmall'] = 0xF76B;
  6397. t['L'] = 0x004C;
  6398. t['LJ'] = 0x01C7;
  6399. t['LL'] = 0xF6BF;
  6400. t['Lacute'] = 0x0139;
  6401. t['Lambda'] = 0x039B;
  6402. t['Lcaron'] = 0x013D;
  6403. t['Lcedilla'] = 0x013B;
  6404. t['Lcircle'] = 0x24C1;
  6405. t['Lcircumflexbelow'] = 0x1E3C;
  6406. t['Lcommaaccent'] = 0x013B;
  6407. t['Ldot'] = 0x013F;
  6408. t['Ldotaccent'] = 0x013F;
  6409. t['Ldotbelow'] = 0x1E36;
  6410. t['Ldotbelowmacron'] = 0x1E38;
  6411. t['Liwnarmenian'] = 0x053C;
  6412. t['Lj'] = 0x01C8;
  6413. t['Ljecyrillic'] = 0x0409;
  6414. t['Llinebelow'] = 0x1E3A;
  6415. t['Lmonospace'] = 0xFF2C;
  6416. t['Lslash'] = 0x0141;
  6417. t['Lslashsmall'] = 0xF6F9;
  6418. t['Lsmall'] = 0xF76C;
  6419. t['M'] = 0x004D;
  6420. t['MBsquare'] = 0x3386;
  6421. t['Macron'] = 0xF6D0;
  6422. t['Macronsmall'] = 0xF7AF;
  6423. t['Macute'] = 0x1E3E;
  6424. t['Mcircle'] = 0x24C2;
  6425. t['Mdotaccent'] = 0x1E40;
  6426. t['Mdotbelow'] = 0x1E42;
  6427. t['Menarmenian'] = 0x0544;
  6428. t['Mmonospace'] = 0xFF2D;
  6429. t['Msmall'] = 0xF76D;
  6430. t['Mturned'] = 0x019C;
  6431. t['Mu'] = 0x039C;
  6432. t['N'] = 0x004E;
  6433. t['NJ'] = 0x01CA;
  6434. t['Nacute'] = 0x0143;
  6435. t['Ncaron'] = 0x0147;
  6436. t['Ncedilla'] = 0x0145;
  6437. t['Ncircle'] = 0x24C3;
  6438. t['Ncircumflexbelow'] = 0x1E4A;
  6439. t['Ncommaaccent'] = 0x0145;
  6440. t['Ndotaccent'] = 0x1E44;
  6441. t['Ndotbelow'] = 0x1E46;
  6442. t['Nhookleft'] = 0x019D;
  6443. t['Nineroman'] = 0x2168;
  6444. t['Nj'] = 0x01CB;
  6445. t['Njecyrillic'] = 0x040A;
  6446. t['Nlinebelow'] = 0x1E48;
  6447. t['Nmonospace'] = 0xFF2E;
  6448. t['Nowarmenian'] = 0x0546;
  6449. t['Nsmall'] = 0xF76E;
  6450. t['Ntilde'] = 0x00D1;
  6451. t['Ntildesmall'] = 0xF7F1;
  6452. t['Nu'] = 0x039D;
  6453. t['O'] = 0x004F;
  6454. t['OE'] = 0x0152;
  6455. t['OEsmall'] = 0xF6FA;
  6456. t['Oacute'] = 0x00D3;
  6457. t['Oacutesmall'] = 0xF7F3;
  6458. t['Obarredcyrillic'] = 0x04E8;
  6459. t['Obarreddieresiscyrillic'] = 0x04EA;
  6460. t['Obreve'] = 0x014E;
  6461. t['Ocaron'] = 0x01D1;
  6462. t['Ocenteredtilde'] = 0x019F;
  6463. t['Ocircle'] = 0x24C4;
  6464. t['Ocircumflex'] = 0x00D4;
  6465. t['Ocircumflexacute'] = 0x1ED0;
  6466. t['Ocircumflexdotbelow'] = 0x1ED8;
  6467. t['Ocircumflexgrave'] = 0x1ED2;
  6468. t['Ocircumflexhookabove'] = 0x1ED4;
  6469. t['Ocircumflexsmall'] = 0xF7F4;
  6470. t['Ocircumflextilde'] = 0x1ED6;
  6471. t['Ocyrillic'] = 0x041E;
  6472. t['Odblacute'] = 0x0150;
  6473. t['Odblgrave'] = 0x020C;
  6474. t['Odieresis'] = 0x00D6;
  6475. t['Odieresiscyrillic'] = 0x04E6;
  6476. t['Odieresissmall'] = 0xF7F6;
  6477. t['Odotbelow'] = 0x1ECC;
  6478. t['Ogoneksmall'] = 0xF6FB;
  6479. t['Ograve'] = 0x00D2;
  6480. t['Ogravesmall'] = 0xF7F2;
  6481. t['Oharmenian'] = 0x0555;
  6482. t['Ohm'] = 0x2126;
  6483. t['Ohookabove'] = 0x1ECE;
  6484. t['Ohorn'] = 0x01A0;
  6485. t['Ohornacute'] = 0x1EDA;
  6486. t['Ohorndotbelow'] = 0x1EE2;
  6487. t['Ohorngrave'] = 0x1EDC;
  6488. t['Ohornhookabove'] = 0x1EDE;
  6489. t['Ohorntilde'] = 0x1EE0;
  6490. t['Ohungarumlaut'] = 0x0150;
  6491. t['Oi'] = 0x01A2;
  6492. t['Oinvertedbreve'] = 0x020E;
  6493. t['Omacron'] = 0x014C;
  6494. t['Omacronacute'] = 0x1E52;
  6495. t['Omacrongrave'] = 0x1E50;
  6496. t['Omega'] = 0x2126;
  6497. t['Omegacyrillic'] = 0x0460;
  6498. t['Omegagreek'] = 0x03A9;
  6499. t['Omegaroundcyrillic'] = 0x047A;
  6500. t['Omegatitlocyrillic'] = 0x047C;
  6501. t['Omegatonos'] = 0x038F;
  6502. t['Omicron'] = 0x039F;
  6503. t['Omicrontonos'] = 0x038C;
  6504. t['Omonospace'] = 0xFF2F;
  6505. t['Oneroman'] = 0x2160;
  6506. t['Oogonek'] = 0x01EA;
  6507. t['Oogonekmacron'] = 0x01EC;
  6508. t['Oopen'] = 0x0186;
  6509. t['Oslash'] = 0x00D8;
  6510. t['Oslashacute'] = 0x01FE;
  6511. t['Oslashsmall'] = 0xF7F8;
  6512. t['Osmall'] = 0xF76F;
  6513. t['Ostrokeacute'] = 0x01FE;
  6514. t['Otcyrillic'] = 0x047E;
  6515. t['Otilde'] = 0x00D5;
  6516. t['Otildeacute'] = 0x1E4C;
  6517. t['Otildedieresis'] = 0x1E4E;
  6518. t['Otildesmall'] = 0xF7F5;
  6519. t['P'] = 0x0050;
  6520. t['Pacute'] = 0x1E54;
  6521. t['Pcircle'] = 0x24C5;
  6522. t['Pdotaccent'] = 0x1E56;
  6523. t['Pecyrillic'] = 0x041F;
  6524. t['Peharmenian'] = 0x054A;
  6525. t['Pemiddlehookcyrillic'] = 0x04A6;
  6526. t['Phi'] = 0x03A6;
  6527. t['Phook'] = 0x01A4;
  6528. t['Pi'] = 0x03A0;
  6529. t['Piwrarmenian'] = 0x0553;
  6530. t['Pmonospace'] = 0xFF30;
  6531. t['Psi'] = 0x03A8;
  6532. t['Psicyrillic'] = 0x0470;
  6533. t['Psmall'] = 0xF770;
  6534. t['Q'] = 0x0051;
  6535. t['Qcircle'] = 0x24C6;
  6536. t['Qmonospace'] = 0xFF31;
  6537. t['Qsmall'] = 0xF771;
  6538. t['R'] = 0x0052;
  6539. t['Raarmenian'] = 0x054C;
  6540. t['Racute'] = 0x0154;
  6541. t['Rcaron'] = 0x0158;
  6542. t['Rcedilla'] = 0x0156;
  6543. t['Rcircle'] = 0x24C7;
  6544. t['Rcommaaccent'] = 0x0156;
  6545. t['Rdblgrave'] = 0x0210;
  6546. t['Rdotaccent'] = 0x1E58;
  6547. t['Rdotbelow'] = 0x1E5A;
  6548. t['Rdotbelowmacron'] = 0x1E5C;
  6549. t['Reharmenian'] = 0x0550;
  6550. t['Rfraktur'] = 0x211C;
  6551. t['Rho'] = 0x03A1;
  6552. t['Ringsmall'] = 0xF6FC;
  6553. t['Rinvertedbreve'] = 0x0212;
  6554. t['Rlinebelow'] = 0x1E5E;
  6555. t['Rmonospace'] = 0xFF32;
  6556. t['Rsmall'] = 0xF772;
  6557. t['Rsmallinverted'] = 0x0281;
  6558. t['Rsmallinvertedsuperior'] = 0x02B6;
  6559. t['S'] = 0x0053;
  6560. t['SF010000'] = 0x250C;
  6561. t['SF020000'] = 0x2514;
  6562. t['SF030000'] = 0x2510;
  6563. t['SF040000'] = 0x2518;
  6564. t['SF050000'] = 0x253C;
  6565. t['SF060000'] = 0x252C;
  6566. t['SF070000'] = 0x2534;
  6567. t['SF080000'] = 0x251C;
  6568. t['SF090000'] = 0x2524;
  6569. t['SF100000'] = 0x2500;
  6570. t['SF110000'] = 0x2502;
  6571. t['SF190000'] = 0x2561;
  6572. t['SF200000'] = 0x2562;
  6573. t['SF210000'] = 0x2556;
  6574. t['SF220000'] = 0x2555;
  6575. t['SF230000'] = 0x2563;
  6576. t['SF240000'] = 0x2551;
  6577. t['SF250000'] = 0x2557;
  6578. t['SF260000'] = 0x255D;
  6579. t['SF270000'] = 0x255C;
  6580. t['SF280000'] = 0x255B;
  6581. t['SF360000'] = 0x255E;
  6582. t['SF370000'] = 0x255F;
  6583. t['SF380000'] = 0x255A;
  6584. t['SF390000'] = 0x2554;
  6585. t['SF400000'] = 0x2569;
  6586. t['SF410000'] = 0x2566;
  6587. t['SF420000'] = 0x2560;
  6588. t['SF430000'] = 0x2550;
  6589. t['SF440000'] = 0x256C;
  6590. t['SF450000'] = 0x2567;
  6591. t['SF460000'] = 0x2568;
  6592. t['SF470000'] = 0x2564;
  6593. t['SF480000'] = 0x2565;
  6594. t['SF490000'] = 0x2559;
  6595. t['SF500000'] = 0x2558;
  6596. t['SF510000'] = 0x2552;
  6597. t['SF520000'] = 0x2553;
  6598. t['SF530000'] = 0x256B;
  6599. t['SF540000'] = 0x256A;
  6600. t['Sacute'] = 0x015A;
  6601. t['Sacutedotaccent'] = 0x1E64;
  6602. t['Sampigreek'] = 0x03E0;
  6603. t['Scaron'] = 0x0160;
  6604. t['Scarondotaccent'] = 0x1E66;
  6605. t['Scaronsmall'] = 0xF6FD;
  6606. t['Scedilla'] = 0x015E;
  6607. t['Schwa'] = 0x018F;
  6608. t['Schwacyrillic'] = 0x04D8;
  6609. t['Schwadieresiscyrillic'] = 0x04DA;
  6610. t['Scircle'] = 0x24C8;
  6611. t['Scircumflex'] = 0x015C;
  6612. t['Scommaaccent'] = 0x0218;
  6613. t['Sdotaccent'] = 0x1E60;
  6614. t['Sdotbelow'] = 0x1E62;
  6615. t['Sdotbelowdotaccent'] = 0x1E68;
  6616. t['Seharmenian'] = 0x054D;
  6617. t['Sevenroman'] = 0x2166;
  6618. t['Shaarmenian'] = 0x0547;
  6619. t['Shacyrillic'] = 0x0428;
  6620. t['Shchacyrillic'] = 0x0429;
  6621. t['Sheicoptic'] = 0x03E2;
  6622. t['Shhacyrillic'] = 0x04BA;
  6623. t['Shimacoptic'] = 0x03EC;
  6624. t['Sigma'] = 0x03A3;
  6625. t['Sixroman'] = 0x2165;
  6626. t['Smonospace'] = 0xFF33;
  6627. t['Softsigncyrillic'] = 0x042C;
  6628. t['Ssmall'] = 0xF773;
  6629. t['Stigmagreek'] = 0x03DA;
  6630. t['T'] = 0x0054;
  6631. t['Tau'] = 0x03A4;
  6632. t['Tbar'] = 0x0166;
  6633. t['Tcaron'] = 0x0164;
  6634. t['Tcedilla'] = 0x0162;
  6635. t['Tcircle'] = 0x24C9;
  6636. t['Tcircumflexbelow'] = 0x1E70;
  6637. t['Tcommaaccent'] = 0x0162;
  6638. t['Tdotaccent'] = 0x1E6A;
  6639. t['Tdotbelow'] = 0x1E6C;
  6640. t['Tecyrillic'] = 0x0422;
  6641. t['Tedescendercyrillic'] = 0x04AC;
  6642. t['Tenroman'] = 0x2169;
  6643. t['Tetsecyrillic'] = 0x04B4;
  6644. t['Theta'] = 0x0398;
  6645. t['Thook'] = 0x01AC;
  6646. t['Thorn'] = 0x00DE;
  6647. t['Thornsmall'] = 0xF7FE;
  6648. t['Threeroman'] = 0x2162;
  6649. t['Tildesmall'] = 0xF6FE;
  6650. t['Tiwnarmenian'] = 0x054F;
  6651. t['Tlinebelow'] = 0x1E6E;
  6652. t['Tmonospace'] = 0xFF34;
  6653. t['Toarmenian'] = 0x0539;
  6654. t['Tonefive'] = 0x01BC;
  6655. t['Tonesix'] = 0x0184;
  6656. t['Tonetwo'] = 0x01A7;
  6657. t['Tretroflexhook'] = 0x01AE;
  6658. t['Tsecyrillic'] = 0x0426;
  6659. t['Tshecyrillic'] = 0x040B;
  6660. t['Tsmall'] = 0xF774;
  6661. t['Twelveroman'] = 0x216B;
  6662. t['Tworoman'] = 0x2161;
  6663. t['U'] = 0x0055;
  6664. t['Uacute'] = 0x00DA;
  6665. t['Uacutesmall'] = 0xF7FA;
  6666. t['Ubreve'] = 0x016C;
  6667. t['Ucaron'] = 0x01D3;
  6668. t['Ucircle'] = 0x24CA;
  6669. t['Ucircumflex'] = 0x00DB;
  6670. t['Ucircumflexbelow'] = 0x1E76;
  6671. t['Ucircumflexsmall'] = 0xF7FB;
  6672. t['Ucyrillic'] = 0x0423;
  6673. t['Udblacute'] = 0x0170;
  6674. t['Udblgrave'] = 0x0214;
  6675. t['Udieresis'] = 0x00DC;
  6676. t['Udieresisacute'] = 0x01D7;
  6677. t['Udieresisbelow'] = 0x1E72;
  6678. t['Udieresiscaron'] = 0x01D9;
  6679. t['Udieresiscyrillic'] = 0x04F0;
  6680. t['Udieresisgrave'] = 0x01DB;
  6681. t['Udieresismacron'] = 0x01D5;
  6682. t['Udieresissmall'] = 0xF7FC;
  6683. t['Udotbelow'] = 0x1EE4;
  6684. t['Ugrave'] = 0x00D9;
  6685. t['Ugravesmall'] = 0xF7F9;
  6686. t['Uhookabove'] = 0x1EE6;
  6687. t['Uhorn'] = 0x01AF;
  6688. t['Uhornacute'] = 0x1EE8;
  6689. t['Uhorndotbelow'] = 0x1EF0;
  6690. t['Uhorngrave'] = 0x1EEA;
  6691. t['Uhornhookabove'] = 0x1EEC;
  6692. t['Uhorntilde'] = 0x1EEE;
  6693. t['Uhungarumlaut'] = 0x0170;
  6694. t['Uhungarumlautcyrillic'] = 0x04F2;
  6695. t['Uinvertedbreve'] = 0x0216;
  6696. t['Ukcyrillic'] = 0x0478;
  6697. t['Umacron'] = 0x016A;
  6698. t['Umacroncyrillic'] = 0x04EE;
  6699. t['Umacrondieresis'] = 0x1E7A;
  6700. t['Umonospace'] = 0xFF35;
  6701. t['Uogonek'] = 0x0172;
  6702. t['Upsilon'] = 0x03A5;
  6703. t['Upsilon1'] = 0x03D2;
  6704. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  6705. t['Upsilonafrican'] = 0x01B1;
  6706. t['Upsilondieresis'] = 0x03AB;
  6707. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  6708. t['Upsilonhooksymbol'] = 0x03D2;
  6709. t['Upsilontonos'] = 0x038E;
  6710. t['Uring'] = 0x016E;
  6711. t['Ushortcyrillic'] = 0x040E;
  6712. t['Usmall'] = 0xF775;
  6713. t['Ustraightcyrillic'] = 0x04AE;
  6714. t['Ustraightstrokecyrillic'] = 0x04B0;
  6715. t['Utilde'] = 0x0168;
  6716. t['Utildeacute'] = 0x1E78;
  6717. t['Utildebelow'] = 0x1E74;
  6718. t['V'] = 0x0056;
  6719. t['Vcircle'] = 0x24CB;
  6720. t['Vdotbelow'] = 0x1E7E;
  6721. t['Vecyrillic'] = 0x0412;
  6722. t['Vewarmenian'] = 0x054E;
  6723. t['Vhook'] = 0x01B2;
  6724. t['Vmonospace'] = 0xFF36;
  6725. t['Voarmenian'] = 0x0548;
  6726. t['Vsmall'] = 0xF776;
  6727. t['Vtilde'] = 0x1E7C;
  6728. t['W'] = 0x0057;
  6729. t['Wacute'] = 0x1E82;
  6730. t['Wcircle'] = 0x24CC;
  6731. t['Wcircumflex'] = 0x0174;
  6732. t['Wdieresis'] = 0x1E84;
  6733. t['Wdotaccent'] = 0x1E86;
  6734. t['Wdotbelow'] = 0x1E88;
  6735. t['Wgrave'] = 0x1E80;
  6736. t['Wmonospace'] = 0xFF37;
  6737. t['Wsmall'] = 0xF777;
  6738. t['X'] = 0x0058;
  6739. t['Xcircle'] = 0x24CD;
  6740. t['Xdieresis'] = 0x1E8C;
  6741. t['Xdotaccent'] = 0x1E8A;
  6742. t['Xeharmenian'] = 0x053D;
  6743. t['Xi'] = 0x039E;
  6744. t['Xmonospace'] = 0xFF38;
  6745. t['Xsmall'] = 0xF778;
  6746. t['Y'] = 0x0059;
  6747. t['Yacute'] = 0x00DD;
  6748. t['Yacutesmall'] = 0xF7FD;
  6749. t['Yatcyrillic'] = 0x0462;
  6750. t['Ycircle'] = 0x24CE;
  6751. t['Ycircumflex'] = 0x0176;
  6752. t['Ydieresis'] = 0x0178;
  6753. t['Ydieresissmall'] = 0xF7FF;
  6754. t['Ydotaccent'] = 0x1E8E;
  6755. t['Ydotbelow'] = 0x1EF4;
  6756. t['Yericyrillic'] = 0x042B;
  6757. t['Yerudieresiscyrillic'] = 0x04F8;
  6758. t['Ygrave'] = 0x1EF2;
  6759. t['Yhook'] = 0x01B3;
  6760. t['Yhookabove'] = 0x1EF6;
  6761. t['Yiarmenian'] = 0x0545;
  6762. t['Yicyrillic'] = 0x0407;
  6763. t['Yiwnarmenian'] = 0x0552;
  6764. t['Ymonospace'] = 0xFF39;
  6765. t['Ysmall'] = 0xF779;
  6766. t['Ytilde'] = 0x1EF8;
  6767. t['Yusbigcyrillic'] = 0x046A;
  6768. t['Yusbigiotifiedcyrillic'] = 0x046C;
  6769. t['Yuslittlecyrillic'] = 0x0466;
  6770. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  6771. t['Z'] = 0x005A;
  6772. t['Zaarmenian'] = 0x0536;
  6773. t['Zacute'] = 0x0179;
  6774. t['Zcaron'] = 0x017D;
  6775. t['Zcaronsmall'] = 0xF6FF;
  6776. t['Zcircle'] = 0x24CF;
  6777. t['Zcircumflex'] = 0x1E90;
  6778. t['Zdot'] = 0x017B;
  6779. t['Zdotaccent'] = 0x017B;
  6780. t['Zdotbelow'] = 0x1E92;
  6781. t['Zecyrillic'] = 0x0417;
  6782. t['Zedescendercyrillic'] = 0x0498;
  6783. t['Zedieresiscyrillic'] = 0x04DE;
  6784. t['Zeta'] = 0x0396;
  6785. t['Zhearmenian'] = 0x053A;
  6786. t['Zhebrevecyrillic'] = 0x04C1;
  6787. t['Zhecyrillic'] = 0x0416;
  6788. t['Zhedescendercyrillic'] = 0x0496;
  6789. t['Zhedieresiscyrillic'] = 0x04DC;
  6790. t['Zlinebelow'] = 0x1E94;
  6791. t['Zmonospace'] = 0xFF3A;
  6792. t['Zsmall'] = 0xF77A;
  6793. t['Zstroke'] = 0x01B5;
  6794. t['a'] = 0x0061;
  6795. t['aabengali'] = 0x0986;
  6796. t['aacute'] = 0x00E1;
  6797. t['aadeva'] = 0x0906;
  6798. t['aagujarati'] = 0x0A86;
  6799. t['aagurmukhi'] = 0x0A06;
  6800. t['aamatragurmukhi'] = 0x0A3E;
  6801. t['aarusquare'] = 0x3303;
  6802. t['aavowelsignbengali'] = 0x09BE;
  6803. t['aavowelsigndeva'] = 0x093E;
  6804. t['aavowelsigngujarati'] = 0x0ABE;
  6805. t['abbreviationmarkarmenian'] = 0x055F;
  6806. t['abbreviationsigndeva'] = 0x0970;
  6807. t['abengali'] = 0x0985;
  6808. t['abopomofo'] = 0x311A;
  6809. t['abreve'] = 0x0103;
  6810. t['abreveacute'] = 0x1EAF;
  6811. t['abrevecyrillic'] = 0x04D1;
  6812. t['abrevedotbelow'] = 0x1EB7;
  6813. t['abrevegrave'] = 0x1EB1;
  6814. t['abrevehookabove'] = 0x1EB3;
  6815. t['abrevetilde'] = 0x1EB5;
  6816. t['acaron'] = 0x01CE;
  6817. t['acircle'] = 0x24D0;
  6818. t['acircumflex'] = 0x00E2;
  6819. t['acircumflexacute'] = 0x1EA5;
  6820. t['acircumflexdotbelow'] = 0x1EAD;
  6821. t['acircumflexgrave'] = 0x1EA7;
  6822. t['acircumflexhookabove'] = 0x1EA9;
  6823. t['acircumflextilde'] = 0x1EAB;
  6824. t['acute'] = 0x00B4;
  6825. t['acutebelowcmb'] = 0x0317;
  6826. t['acutecmb'] = 0x0301;
  6827. t['acutecomb'] = 0x0301;
  6828. t['acutedeva'] = 0x0954;
  6829. t['acutelowmod'] = 0x02CF;
  6830. t['acutetonecmb'] = 0x0341;
  6831. t['acyrillic'] = 0x0430;
  6832. t['adblgrave'] = 0x0201;
  6833. t['addakgurmukhi'] = 0x0A71;
  6834. t['adeva'] = 0x0905;
  6835. t['adieresis'] = 0x00E4;
  6836. t['adieresiscyrillic'] = 0x04D3;
  6837. t['adieresismacron'] = 0x01DF;
  6838. t['adotbelow'] = 0x1EA1;
  6839. t['adotmacron'] = 0x01E1;
  6840. t['ae'] = 0x00E6;
  6841. t['aeacute'] = 0x01FD;
  6842. t['aekorean'] = 0x3150;
  6843. t['aemacron'] = 0x01E3;
  6844. t['afii00208'] = 0x2015;
  6845. t['afii08941'] = 0x20A4;
  6846. t['afii10017'] = 0x0410;
  6847. t['afii10018'] = 0x0411;
  6848. t['afii10019'] = 0x0412;
  6849. t['afii10020'] = 0x0413;
  6850. t['afii10021'] = 0x0414;
  6851. t['afii10022'] = 0x0415;
  6852. t['afii10023'] = 0x0401;
  6853. t['afii10024'] = 0x0416;
  6854. t['afii10025'] = 0x0417;
  6855. t['afii10026'] = 0x0418;
  6856. t['afii10027'] = 0x0419;
  6857. t['afii10028'] = 0x041A;
  6858. t['afii10029'] = 0x041B;
  6859. t['afii10030'] = 0x041C;
  6860. t['afii10031'] = 0x041D;
  6861. t['afii10032'] = 0x041E;
  6862. t['afii10033'] = 0x041F;
  6863. t['afii10034'] = 0x0420;
  6864. t['afii10035'] = 0x0421;
  6865. t['afii10036'] = 0x0422;
  6866. t['afii10037'] = 0x0423;
  6867. t['afii10038'] = 0x0424;
  6868. t['afii10039'] = 0x0425;
  6869. t['afii10040'] = 0x0426;
  6870. t['afii10041'] = 0x0427;
  6871. t['afii10042'] = 0x0428;
  6872. t['afii10043'] = 0x0429;
  6873. t['afii10044'] = 0x042A;
  6874. t['afii10045'] = 0x042B;
  6875. t['afii10046'] = 0x042C;
  6876. t['afii10047'] = 0x042D;
  6877. t['afii10048'] = 0x042E;
  6878. t['afii10049'] = 0x042F;
  6879. t['afii10050'] = 0x0490;
  6880. t['afii10051'] = 0x0402;
  6881. t['afii10052'] = 0x0403;
  6882. t['afii10053'] = 0x0404;
  6883. t['afii10054'] = 0x0405;
  6884. t['afii10055'] = 0x0406;
  6885. t['afii10056'] = 0x0407;
  6886. t['afii10057'] = 0x0408;
  6887. t['afii10058'] = 0x0409;
  6888. t['afii10059'] = 0x040A;
  6889. t['afii10060'] = 0x040B;
  6890. t['afii10061'] = 0x040C;
  6891. t['afii10062'] = 0x040E;
  6892. t['afii10063'] = 0xF6C4;
  6893. t['afii10064'] = 0xF6C5;
  6894. t['afii10065'] = 0x0430;
  6895. t['afii10066'] = 0x0431;
  6896. t['afii10067'] = 0x0432;
  6897. t['afii10068'] = 0x0433;
  6898. t['afii10069'] = 0x0434;
  6899. t['afii10070'] = 0x0435;
  6900. t['afii10071'] = 0x0451;
  6901. t['afii10072'] = 0x0436;
  6902. t['afii10073'] = 0x0437;
  6903. t['afii10074'] = 0x0438;
  6904. t['afii10075'] = 0x0439;
  6905. t['afii10076'] = 0x043A;
  6906. t['afii10077'] = 0x043B;
  6907. t['afii10078'] = 0x043C;
  6908. t['afii10079'] = 0x043D;
  6909. t['afii10080'] = 0x043E;
  6910. t['afii10081'] = 0x043F;
  6911. t['afii10082'] = 0x0440;
  6912. t['afii10083'] = 0x0441;
  6913. t['afii10084'] = 0x0442;
  6914. t['afii10085'] = 0x0443;
  6915. t['afii10086'] = 0x0444;
  6916. t['afii10087'] = 0x0445;
  6917. t['afii10088'] = 0x0446;
  6918. t['afii10089'] = 0x0447;
  6919. t['afii10090'] = 0x0448;
  6920. t['afii10091'] = 0x0449;
  6921. t['afii10092'] = 0x044A;
  6922. t['afii10093'] = 0x044B;
  6923. t['afii10094'] = 0x044C;
  6924. t['afii10095'] = 0x044D;
  6925. t['afii10096'] = 0x044E;
  6926. t['afii10097'] = 0x044F;
  6927. t['afii10098'] = 0x0491;
  6928. t['afii10099'] = 0x0452;
  6929. t['afii10100'] = 0x0453;
  6930. t['afii10101'] = 0x0454;
  6931. t['afii10102'] = 0x0455;
  6932. t['afii10103'] = 0x0456;
  6933. t['afii10104'] = 0x0457;
  6934. t['afii10105'] = 0x0458;
  6935. t['afii10106'] = 0x0459;
  6936. t['afii10107'] = 0x045A;
  6937. t['afii10108'] = 0x045B;
  6938. t['afii10109'] = 0x045C;
  6939. t['afii10110'] = 0x045E;
  6940. t['afii10145'] = 0x040F;
  6941. t['afii10146'] = 0x0462;
  6942. t['afii10147'] = 0x0472;
  6943. t['afii10148'] = 0x0474;
  6944. t['afii10192'] = 0xF6C6;
  6945. t['afii10193'] = 0x045F;
  6946. t['afii10194'] = 0x0463;
  6947. t['afii10195'] = 0x0473;
  6948. t['afii10196'] = 0x0475;
  6949. t['afii10831'] = 0xF6C7;
  6950. t['afii10832'] = 0xF6C8;
  6951. t['afii10846'] = 0x04D9;
  6952. t['afii299'] = 0x200E;
  6953. t['afii300'] = 0x200F;
  6954. t['afii301'] = 0x200D;
  6955. t['afii57381'] = 0x066A;
  6956. t['afii57388'] = 0x060C;
  6957. t['afii57392'] = 0x0660;
  6958. t['afii57393'] = 0x0661;
  6959. t['afii57394'] = 0x0662;
  6960. t['afii57395'] = 0x0663;
  6961. t['afii57396'] = 0x0664;
  6962. t['afii57397'] = 0x0665;
  6963. t['afii57398'] = 0x0666;
  6964. t['afii57399'] = 0x0667;
  6965. t['afii57400'] = 0x0668;
  6966. t['afii57401'] = 0x0669;
  6967. t['afii57403'] = 0x061B;
  6968. t['afii57407'] = 0x061F;
  6969. t['afii57409'] = 0x0621;
  6970. t['afii57410'] = 0x0622;
  6971. t['afii57411'] = 0x0623;
  6972. t['afii57412'] = 0x0624;
  6973. t['afii57413'] = 0x0625;
  6974. t['afii57414'] = 0x0626;
  6975. t['afii57415'] = 0x0627;
  6976. t['afii57416'] = 0x0628;
  6977. t['afii57417'] = 0x0629;
  6978. t['afii57418'] = 0x062A;
  6979. t['afii57419'] = 0x062B;
  6980. t['afii57420'] = 0x062C;
  6981. t['afii57421'] = 0x062D;
  6982. t['afii57422'] = 0x062E;
  6983. t['afii57423'] = 0x062F;
  6984. t['afii57424'] = 0x0630;
  6985. t['afii57425'] = 0x0631;
  6986. t['afii57426'] = 0x0632;
  6987. t['afii57427'] = 0x0633;
  6988. t['afii57428'] = 0x0634;
  6989. t['afii57429'] = 0x0635;
  6990. t['afii57430'] = 0x0636;
  6991. t['afii57431'] = 0x0637;
  6992. t['afii57432'] = 0x0638;
  6993. t['afii57433'] = 0x0639;
  6994. t['afii57434'] = 0x063A;
  6995. t['afii57440'] = 0x0640;
  6996. t['afii57441'] = 0x0641;
  6997. t['afii57442'] = 0x0642;
  6998. t['afii57443'] = 0x0643;
  6999. t['afii57444'] = 0x0644;
  7000. t['afii57445'] = 0x0645;
  7001. t['afii57446'] = 0x0646;
  7002. t['afii57448'] = 0x0648;
  7003. t['afii57449'] = 0x0649;
  7004. t['afii57450'] = 0x064A;
  7005. t['afii57451'] = 0x064B;
  7006. t['afii57452'] = 0x064C;
  7007. t['afii57453'] = 0x064D;
  7008. t['afii57454'] = 0x064E;
  7009. t['afii57455'] = 0x064F;
  7010. t['afii57456'] = 0x0650;
  7011. t['afii57457'] = 0x0651;
  7012. t['afii57458'] = 0x0652;
  7013. t['afii57470'] = 0x0647;
  7014. t['afii57505'] = 0x06A4;
  7015. t['afii57506'] = 0x067E;
  7016. t['afii57507'] = 0x0686;
  7017. t['afii57508'] = 0x0698;
  7018. t['afii57509'] = 0x06AF;
  7019. t['afii57511'] = 0x0679;
  7020. t['afii57512'] = 0x0688;
  7021. t['afii57513'] = 0x0691;
  7022. t['afii57514'] = 0x06BA;
  7023. t['afii57519'] = 0x06D2;
  7024. t['afii57534'] = 0x06D5;
  7025. t['afii57636'] = 0x20AA;
  7026. t['afii57645'] = 0x05BE;
  7027. t['afii57658'] = 0x05C3;
  7028. t['afii57664'] = 0x05D0;
  7029. t['afii57665'] = 0x05D1;
  7030. t['afii57666'] = 0x05D2;
  7031. t['afii57667'] = 0x05D3;
  7032. t['afii57668'] = 0x05D4;
  7033. t['afii57669'] = 0x05D5;
  7034. t['afii57670'] = 0x05D6;
  7035. t['afii57671'] = 0x05D7;
  7036. t['afii57672'] = 0x05D8;
  7037. t['afii57673'] = 0x05D9;
  7038. t['afii57674'] = 0x05DA;
  7039. t['afii57675'] = 0x05DB;
  7040. t['afii57676'] = 0x05DC;
  7041. t['afii57677'] = 0x05DD;
  7042. t['afii57678'] = 0x05DE;
  7043. t['afii57679'] = 0x05DF;
  7044. t['afii57680'] = 0x05E0;
  7045. t['afii57681'] = 0x05E1;
  7046. t['afii57682'] = 0x05E2;
  7047. t['afii57683'] = 0x05E3;
  7048. t['afii57684'] = 0x05E4;
  7049. t['afii57685'] = 0x05E5;
  7050. t['afii57686'] = 0x05E6;
  7051. t['afii57687'] = 0x05E7;
  7052. t['afii57688'] = 0x05E8;
  7053. t['afii57689'] = 0x05E9;
  7054. t['afii57690'] = 0x05EA;
  7055. t['afii57694'] = 0xFB2A;
  7056. t['afii57695'] = 0xFB2B;
  7057. t['afii57700'] = 0xFB4B;
  7058. t['afii57705'] = 0xFB1F;
  7059. t['afii57716'] = 0x05F0;
  7060. t['afii57717'] = 0x05F1;
  7061. t['afii57718'] = 0x05F2;
  7062. t['afii57723'] = 0xFB35;
  7063. t['afii57793'] = 0x05B4;
  7064. t['afii57794'] = 0x05B5;
  7065. t['afii57795'] = 0x05B6;
  7066. t['afii57796'] = 0x05BB;
  7067. t['afii57797'] = 0x05B8;
  7068. t['afii57798'] = 0x05B7;
  7069. t['afii57799'] = 0x05B0;
  7070. t['afii57800'] = 0x05B2;
  7071. t['afii57801'] = 0x05B1;
  7072. t['afii57802'] = 0x05B3;
  7073. t['afii57803'] = 0x05C2;
  7074. t['afii57804'] = 0x05C1;
  7075. t['afii57806'] = 0x05B9;
  7076. t['afii57807'] = 0x05BC;
  7077. t['afii57839'] = 0x05BD;
  7078. t['afii57841'] = 0x05BF;
  7079. t['afii57842'] = 0x05C0;
  7080. t['afii57929'] = 0x02BC;
  7081. t['afii61248'] = 0x2105;
  7082. t['afii61289'] = 0x2113;
  7083. t['afii61352'] = 0x2116;
  7084. t['afii61573'] = 0x202C;
  7085. t['afii61574'] = 0x202D;
  7086. t['afii61575'] = 0x202E;
  7087. t['afii61664'] = 0x200C;
  7088. t['afii63167'] = 0x066D;
  7089. t['afii64937'] = 0x02BD;
  7090. t['agrave'] = 0x00E0;
  7091. t['agujarati'] = 0x0A85;
  7092. t['agurmukhi'] = 0x0A05;
  7093. t['ahiragana'] = 0x3042;
  7094. t['ahookabove'] = 0x1EA3;
  7095. t['aibengali'] = 0x0990;
  7096. t['aibopomofo'] = 0x311E;
  7097. t['aideva'] = 0x0910;
  7098. t['aiecyrillic'] = 0x04D5;
  7099. t['aigujarati'] = 0x0A90;
  7100. t['aigurmukhi'] = 0x0A10;
  7101. t['aimatragurmukhi'] = 0x0A48;
  7102. t['ainarabic'] = 0x0639;
  7103. t['ainfinalarabic'] = 0xFECA;
  7104. t['aininitialarabic'] = 0xFECB;
  7105. t['ainmedialarabic'] = 0xFECC;
  7106. t['ainvertedbreve'] = 0x0203;
  7107. t['aivowelsignbengali'] = 0x09C8;
  7108. t['aivowelsigndeva'] = 0x0948;
  7109. t['aivowelsigngujarati'] = 0x0AC8;
  7110. t['akatakana'] = 0x30A2;
  7111. t['akatakanahalfwidth'] = 0xFF71;
  7112. t['akorean'] = 0x314F;
  7113. t['alef'] = 0x05D0;
  7114. t['alefarabic'] = 0x0627;
  7115. t['alefdageshhebrew'] = 0xFB30;
  7116. t['aleffinalarabic'] = 0xFE8E;
  7117. t['alefhamzaabovearabic'] = 0x0623;
  7118. t['alefhamzaabovefinalarabic'] = 0xFE84;
  7119. t['alefhamzabelowarabic'] = 0x0625;
  7120. t['alefhamzabelowfinalarabic'] = 0xFE88;
  7121. t['alefhebrew'] = 0x05D0;
  7122. t['aleflamedhebrew'] = 0xFB4F;
  7123. t['alefmaddaabovearabic'] = 0x0622;
  7124. t['alefmaddaabovefinalarabic'] = 0xFE82;
  7125. t['alefmaksuraarabic'] = 0x0649;
  7126. t['alefmaksurafinalarabic'] = 0xFEF0;
  7127. t['alefmaksurainitialarabic'] = 0xFEF3;
  7128. t['alefmaksuramedialarabic'] = 0xFEF4;
  7129. t['alefpatahhebrew'] = 0xFB2E;
  7130. t['alefqamatshebrew'] = 0xFB2F;
  7131. t['aleph'] = 0x2135;
  7132. t['allequal'] = 0x224C;
  7133. t['alpha'] = 0x03B1;
  7134. t['alphatonos'] = 0x03AC;
  7135. t['amacron'] = 0x0101;
  7136. t['amonospace'] = 0xFF41;
  7137. t['ampersand'] = 0x0026;
  7138. t['ampersandmonospace'] = 0xFF06;
  7139. t['ampersandsmall'] = 0xF726;
  7140. t['amsquare'] = 0x33C2;
  7141. t['anbopomofo'] = 0x3122;
  7142. t['angbopomofo'] = 0x3124;
  7143. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  7144. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  7145. t['angkhankhuthai'] = 0x0E5A;
  7146. t['angle'] = 0x2220;
  7147. t['anglebracketleft'] = 0x3008;
  7148. t['anglebracketleftvertical'] = 0xFE3F;
  7149. t['anglebracketright'] = 0x3009;
  7150. t['anglebracketrightvertical'] = 0xFE40;
  7151. t['angleleft'] = 0x2329;
  7152. t['angleright'] = 0x232A;
  7153. t['angstrom'] = 0x212B;
  7154. t['anoteleia'] = 0x0387;
  7155. t['anudattadeva'] = 0x0952;
  7156. t['anusvarabengali'] = 0x0982;
  7157. t['anusvaradeva'] = 0x0902;
  7158. t['anusvaragujarati'] = 0x0A82;
  7159. t['aogonek'] = 0x0105;
  7160. t['apaatosquare'] = 0x3300;
  7161. t['aparen'] = 0x249C;
  7162. t['apostrophearmenian'] = 0x055A;
  7163. t['apostrophemod'] = 0x02BC;
  7164. t['apple'] = 0xF8FF;
  7165. t['approaches'] = 0x2250;
  7166. t['approxequal'] = 0x2248;
  7167. t['approxequalorimage'] = 0x2252;
  7168. t['approximatelyequal'] = 0x2245;
  7169. t['araeaekorean'] = 0x318E;
  7170. t['araeakorean'] = 0x318D;
  7171. t['arc'] = 0x2312;
  7172. t['arighthalfring'] = 0x1E9A;
  7173. t['aring'] = 0x00E5;
  7174. t['aringacute'] = 0x01FB;
  7175. t['aringbelow'] = 0x1E01;
  7176. t['arrowboth'] = 0x2194;
  7177. t['arrowdashdown'] = 0x21E3;
  7178. t['arrowdashleft'] = 0x21E0;
  7179. t['arrowdashright'] = 0x21E2;
  7180. t['arrowdashup'] = 0x21E1;
  7181. t['arrowdblboth'] = 0x21D4;
  7182. t['arrowdbldown'] = 0x21D3;
  7183. t['arrowdblleft'] = 0x21D0;
  7184. t['arrowdblright'] = 0x21D2;
  7185. t['arrowdblup'] = 0x21D1;
  7186. t['arrowdown'] = 0x2193;
  7187. t['arrowdownleft'] = 0x2199;
  7188. t['arrowdownright'] = 0x2198;
  7189. t['arrowdownwhite'] = 0x21E9;
  7190. t['arrowheaddownmod'] = 0x02C5;
  7191. t['arrowheadleftmod'] = 0x02C2;
  7192. t['arrowheadrightmod'] = 0x02C3;
  7193. t['arrowheadupmod'] = 0x02C4;
  7194. t['arrowhorizex'] = 0xF8E7;
  7195. t['arrowleft'] = 0x2190;
  7196. t['arrowleftdbl'] = 0x21D0;
  7197. t['arrowleftdblstroke'] = 0x21CD;
  7198. t['arrowleftoverright'] = 0x21C6;
  7199. t['arrowleftwhite'] = 0x21E6;
  7200. t['arrowright'] = 0x2192;
  7201. t['arrowrightdblstroke'] = 0x21CF;
  7202. t['arrowrightheavy'] = 0x279E;
  7203. t['arrowrightoverleft'] = 0x21C4;
  7204. t['arrowrightwhite'] = 0x21E8;
  7205. t['arrowtableft'] = 0x21E4;
  7206. t['arrowtabright'] = 0x21E5;
  7207. t['arrowup'] = 0x2191;
  7208. t['arrowupdn'] = 0x2195;
  7209. t['arrowupdnbse'] = 0x21A8;
  7210. t['arrowupdownbase'] = 0x21A8;
  7211. t['arrowupleft'] = 0x2196;
  7212. t['arrowupleftofdown'] = 0x21C5;
  7213. t['arrowupright'] = 0x2197;
  7214. t['arrowupwhite'] = 0x21E7;
  7215. t['arrowvertex'] = 0xF8E6;
  7216. t['asciicircum'] = 0x005E;
  7217. t['asciicircummonospace'] = 0xFF3E;
  7218. t['asciitilde'] = 0x007E;
  7219. t['asciitildemonospace'] = 0xFF5E;
  7220. t['ascript'] = 0x0251;
  7221. t['ascriptturned'] = 0x0252;
  7222. t['asmallhiragana'] = 0x3041;
  7223. t['asmallkatakana'] = 0x30A1;
  7224. t['asmallkatakanahalfwidth'] = 0xFF67;
  7225. t['asterisk'] = 0x002A;
  7226. t['asteriskaltonearabic'] = 0x066D;
  7227. t['asteriskarabic'] = 0x066D;
  7228. t['asteriskmath'] = 0x2217;
  7229. t['asteriskmonospace'] = 0xFF0A;
  7230. t['asterisksmall'] = 0xFE61;
  7231. t['asterism'] = 0x2042;
  7232. t['asuperior'] = 0xF6E9;
  7233. t['asymptoticallyequal'] = 0x2243;
  7234. t['at'] = 0x0040;
  7235. t['atilde'] = 0x00E3;
  7236. t['atmonospace'] = 0xFF20;
  7237. t['atsmall'] = 0xFE6B;
  7238. t['aturned'] = 0x0250;
  7239. t['aubengali'] = 0x0994;
  7240. t['aubopomofo'] = 0x3120;
  7241. t['audeva'] = 0x0914;
  7242. t['augujarati'] = 0x0A94;
  7243. t['augurmukhi'] = 0x0A14;
  7244. t['aulengthmarkbengali'] = 0x09D7;
  7245. t['aumatragurmukhi'] = 0x0A4C;
  7246. t['auvowelsignbengali'] = 0x09CC;
  7247. t['auvowelsigndeva'] = 0x094C;
  7248. t['auvowelsigngujarati'] = 0x0ACC;
  7249. t['avagrahadeva'] = 0x093D;
  7250. t['aybarmenian'] = 0x0561;
  7251. t['ayin'] = 0x05E2;
  7252. t['ayinaltonehebrew'] = 0xFB20;
  7253. t['ayinhebrew'] = 0x05E2;
  7254. t['b'] = 0x0062;
  7255. t['babengali'] = 0x09AC;
  7256. t['backslash'] = 0x005C;
  7257. t['backslashmonospace'] = 0xFF3C;
  7258. t['badeva'] = 0x092C;
  7259. t['bagujarati'] = 0x0AAC;
  7260. t['bagurmukhi'] = 0x0A2C;
  7261. t['bahiragana'] = 0x3070;
  7262. t['bahtthai'] = 0x0E3F;
  7263. t['bakatakana'] = 0x30D0;
  7264. t['bar'] = 0x007C;
  7265. t['barmonospace'] = 0xFF5C;
  7266. t['bbopomofo'] = 0x3105;
  7267. t['bcircle'] = 0x24D1;
  7268. t['bdotaccent'] = 0x1E03;
  7269. t['bdotbelow'] = 0x1E05;
  7270. t['beamedsixteenthnotes'] = 0x266C;
  7271. t['because'] = 0x2235;
  7272. t['becyrillic'] = 0x0431;
  7273. t['beharabic'] = 0x0628;
  7274. t['behfinalarabic'] = 0xFE90;
  7275. t['behinitialarabic'] = 0xFE91;
  7276. t['behiragana'] = 0x3079;
  7277. t['behmedialarabic'] = 0xFE92;
  7278. t['behmeeminitialarabic'] = 0xFC9F;
  7279. t['behmeemisolatedarabic'] = 0xFC08;
  7280. t['behnoonfinalarabic'] = 0xFC6D;
  7281. t['bekatakana'] = 0x30D9;
  7282. t['benarmenian'] = 0x0562;
  7283. t['bet'] = 0x05D1;
  7284. t['beta'] = 0x03B2;
  7285. t['betasymbolgreek'] = 0x03D0;
  7286. t['betdagesh'] = 0xFB31;
  7287. t['betdageshhebrew'] = 0xFB31;
  7288. t['bethebrew'] = 0x05D1;
  7289. t['betrafehebrew'] = 0xFB4C;
  7290. t['bhabengali'] = 0x09AD;
  7291. t['bhadeva'] = 0x092D;
  7292. t['bhagujarati'] = 0x0AAD;
  7293. t['bhagurmukhi'] = 0x0A2D;
  7294. t['bhook'] = 0x0253;
  7295. t['bihiragana'] = 0x3073;
  7296. t['bikatakana'] = 0x30D3;
  7297. t['bilabialclick'] = 0x0298;
  7298. t['bindigurmukhi'] = 0x0A02;
  7299. t['birusquare'] = 0x3331;
  7300. t['blackcircle'] = 0x25CF;
  7301. t['blackdiamond'] = 0x25C6;
  7302. t['blackdownpointingtriangle'] = 0x25BC;
  7303. t['blackleftpointingpointer'] = 0x25C4;
  7304. t['blackleftpointingtriangle'] = 0x25C0;
  7305. t['blacklenticularbracketleft'] = 0x3010;
  7306. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  7307. t['blacklenticularbracketright'] = 0x3011;
  7308. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  7309. t['blacklowerlefttriangle'] = 0x25E3;
  7310. t['blacklowerrighttriangle'] = 0x25E2;
  7311. t['blackrectangle'] = 0x25AC;
  7312. t['blackrightpointingpointer'] = 0x25BA;
  7313. t['blackrightpointingtriangle'] = 0x25B6;
  7314. t['blacksmallsquare'] = 0x25AA;
  7315. t['blacksmilingface'] = 0x263B;
  7316. t['blacksquare'] = 0x25A0;
  7317. t['blackstar'] = 0x2605;
  7318. t['blackupperlefttriangle'] = 0x25E4;
  7319. t['blackupperrighttriangle'] = 0x25E5;
  7320. t['blackuppointingsmalltriangle'] = 0x25B4;
  7321. t['blackuppointingtriangle'] = 0x25B2;
  7322. t['blank'] = 0x2423;
  7323. t['blinebelow'] = 0x1E07;
  7324. t['block'] = 0x2588;
  7325. t['bmonospace'] = 0xFF42;
  7326. t['bobaimaithai'] = 0x0E1A;
  7327. t['bohiragana'] = 0x307C;
  7328. t['bokatakana'] = 0x30DC;
  7329. t['bparen'] = 0x249D;
  7330. t['bqsquare'] = 0x33C3;
  7331. t['braceex'] = 0xF8F4;
  7332. t['braceleft'] = 0x007B;
  7333. t['braceleftbt'] = 0xF8F3;
  7334. t['braceleftmid'] = 0xF8F2;
  7335. t['braceleftmonospace'] = 0xFF5B;
  7336. t['braceleftsmall'] = 0xFE5B;
  7337. t['bracelefttp'] = 0xF8F1;
  7338. t['braceleftvertical'] = 0xFE37;
  7339. t['braceright'] = 0x007D;
  7340. t['bracerightbt'] = 0xF8FE;
  7341. t['bracerightmid'] = 0xF8FD;
  7342. t['bracerightmonospace'] = 0xFF5D;
  7343. t['bracerightsmall'] = 0xFE5C;
  7344. t['bracerighttp'] = 0xF8FC;
  7345. t['bracerightvertical'] = 0xFE38;
  7346. t['bracketleft'] = 0x005B;
  7347. t['bracketleftbt'] = 0xF8F0;
  7348. t['bracketleftex'] = 0xF8EF;
  7349. t['bracketleftmonospace'] = 0xFF3B;
  7350. t['bracketlefttp'] = 0xF8EE;
  7351. t['bracketright'] = 0x005D;
  7352. t['bracketrightbt'] = 0xF8FB;
  7353. t['bracketrightex'] = 0xF8FA;
  7354. t['bracketrightmonospace'] = 0xFF3D;
  7355. t['bracketrighttp'] = 0xF8F9;
  7356. t['breve'] = 0x02D8;
  7357. t['brevebelowcmb'] = 0x032E;
  7358. t['brevecmb'] = 0x0306;
  7359. t['breveinvertedbelowcmb'] = 0x032F;
  7360. t['breveinvertedcmb'] = 0x0311;
  7361. t['breveinverteddoublecmb'] = 0x0361;
  7362. t['bridgebelowcmb'] = 0x032A;
  7363. t['bridgeinvertedbelowcmb'] = 0x033A;
  7364. t['brokenbar'] = 0x00A6;
  7365. t['bstroke'] = 0x0180;
  7366. t['bsuperior'] = 0xF6EA;
  7367. t['btopbar'] = 0x0183;
  7368. t['buhiragana'] = 0x3076;
  7369. t['bukatakana'] = 0x30D6;
  7370. t['bullet'] = 0x2022;
  7371. t['bulletinverse'] = 0x25D8;
  7372. t['bulletoperator'] = 0x2219;
  7373. t['bullseye'] = 0x25CE;
  7374. t['c'] = 0x0063;
  7375. t['caarmenian'] = 0x056E;
  7376. t['cabengali'] = 0x099A;
  7377. t['cacute'] = 0x0107;
  7378. t['cadeva'] = 0x091A;
  7379. t['cagujarati'] = 0x0A9A;
  7380. t['cagurmukhi'] = 0x0A1A;
  7381. t['calsquare'] = 0x3388;
  7382. t['candrabindubengali'] = 0x0981;
  7383. t['candrabinducmb'] = 0x0310;
  7384. t['candrabindudeva'] = 0x0901;
  7385. t['candrabindugujarati'] = 0x0A81;
  7386. t['capslock'] = 0x21EA;
  7387. t['careof'] = 0x2105;
  7388. t['caron'] = 0x02C7;
  7389. t['caronbelowcmb'] = 0x032C;
  7390. t['caroncmb'] = 0x030C;
  7391. t['carriagereturn'] = 0x21B5;
  7392. t['cbopomofo'] = 0x3118;
  7393. t['ccaron'] = 0x010D;
  7394. t['ccedilla'] = 0x00E7;
  7395. t['ccedillaacute'] = 0x1E09;
  7396. t['ccircle'] = 0x24D2;
  7397. t['ccircumflex'] = 0x0109;
  7398. t['ccurl'] = 0x0255;
  7399. t['cdot'] = 0x010B;
  7400. t['cdotaccent'] = 0x010B;
  7401. t['cdsquare'] = 0x33C5;
  7402. t['cedilla'] = 0x00B8;
  7403. t['cedillacmb'] = 0x0327;
  7404. t['cent'] = 0x00A2;
  7405. t['centigrade'] = 0x2103;
  7406. t['centinferior'] = 0xF6DF;
  7407. t['centmonospace'] = 0xFFE0;
  7408. t['centoldstyle'] = 0xF7A2;
  7409. t['centsuperior'] = 0xF6E0;
  7410. t['chaarmenian'] = 0x0579;
  7411. t['chabengali'] = 0x099B;
  7412. t['chadeva'] = 0x091B;
  7413. t['chagujarati'] = 0x0A9B;
  7414. t['chagurmukhi'] = 0x0A1B;
  7415. t['chbopomofo'] = 0x3114;
  7416. t['cheabkhasiancyrillic'] = 0x04BD;
  7417. t['checkmark'] = 0x2713;
  7418. t['checyrillic'] = 0x0447;
  7419. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  7420. t['chedescendercyrillic'] = 0x04B7;
  7421. t['chedieresiscyrillic'] = 0x04F5;
  7422. t['cheharmenian'] = 0x0573;
  7423. t['chekhakassiancyrillic'] = 0x04CC;
  7424. t['cheverticalstrokecyrillic'] = 0x04B9;
  7425. t['chi'] = 0x03C7;
  7426. t['chieuchacirclekorean'] = 0x3277;
  7427. t['chieuchaparenkorean'] = 0x3217;
  7428. t['chieuchcirclekorean'] = 0x3269;
  7429. t['chieuchkorean'] = 0x314A;
  7430. t['chieuchparenkorean'] = 0x3209;
  7431. t['chochangthai'] = 0x0E0A;
  7432. t['chochanthai'] = 0x0E08;
  7433. t['chochingthai'] = 0x0E09;
  7434. t['chochoethai'] = 0x0E0C;
  7435. t['chook'] = 0x0188;
  7436. t['cieucacirclekorean'] = 0x3276;
  7437. t['cieucaparenkorean'] = 0x3216;
  7438. t['cieuccirclekorean'] = 0x3268;
  7439. t['cieuckorean'] = 0x3148;
  7440. t['cieucparenkorean'] = 0x3208;
  7441. t['cieucuparenkorean'] = 0x321C;
  7442. t['circle'] = 0x25CB;
  7443. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  7444. t['circlemultiply'] = 0x2297;
  7445. t['circleot'] = 0x2299;
  7446. t['circleplus'] = 0x2295;
  7447. t['circlepostalmark'] = 0x3036;
  7448. t['circlewithlefthalfblack'] = 0x25D0;
  7449. t['circlewithrighthalfblack'] = 0x25D1;
  7450. t['circumflex'] = 0x02C6;
  7451. t['circumflexbelowcmb'] = 0x032D;
  7452. t['circumflexcmb'] = 0x0302;
  7453. t['clear'] = 0x2327;
  7454. t['clickalveolar'] = 0x01C2;
  7455. t['clickdental'] = 0x01C0;
  7456. t['clicklateral'] = 0x01C1;
  7457. t['clickretroflex'] = 0x01C3;
  7458. t['club'] = 0x2663;
  7459. t['clubsuitblack'] = 0x2663;
  7460. t['clubsuitwhite'] = 0x2667;
  7461. t['cmcubedsquare'] = 0x33A4;
  7462. t['cmonospace'] = 0xFF43;
  7463. t['cmsquaredsquare'] = 0x33A0;
  7464. t['coarmenian'] = 0x0581;
  7465. t['colon'] = 0x003A;
  7466. t['colonmonetary'] = 0x20A1;
  7467. t['colonmonospace'] = 0xFF1A;
  7468. t['colonsign'] = 0x20A1;
  7469. t['colonsmall'] = 0xFE55;
  7470. t['colontriangularhalfmod'] = 0x02D1;
  7471. t['colontriangularmod'] = 0x02D0;
  7472. t['comma'] = 0x002C;
  7473. t['commaabovecmb'] = 0x0313;
  7474. t['commaaboverightcmb'] = 0x0315;
  7475. t['commaaccent'] = 0xF6C3;
  7476. t['commaarabic'] = 0x060C;
  7477. t['commaarmenian'] = 0x055D;
  7478. t['commainferior'] = 0xF6E1;
  7479. t['commamonospace'] = 0xFF0C;
  7480. t['commareversedabovecmb'] = 0x0314;
  7481. t['commareversedmod'] = 0x02BD;
  7482. t['commasmall'] = 0xFE50;
  7483. t['commasuperior'] = 0xF6E2;
  7484. t['commaturnedabovecmb'] = 0x0312;
  7485. t['commaturnedmod'] = 0x02BB;
  7486. t['compass'] = 0x263C;
  7487. t['congruent'] = 0x2245;
  7488. t['contourintegral'] = 0x222E;
  7489. t['control'] = 0x2303;
  7490. t['controlACK'] = 0x0006;
  7491. t['controlBEL'] = 0x0007;
  7492. t['controlBS'] = 0x0008;
  7493. t['controlCAN'] = 0x0018;
  7494. t['controlCR'] = 0x000D;
  7495. t['controlDC1'] = 0x0011;
  7496. t['controlDC2'] = 0x0012;
  7497. t['controlDC3'] = 0x0013;
  7498. t['controlDC4'] = 0x0014;
  7499. t['controlDEL'] = 0x007F;
  7500. t['controlDLE'] = 0x0010;
  7501. t['controlEM'] = 0x0019;
  7502. t['controlENQ'] = 0x0005;
  7503. t['controlEOT'] = 0x0004;
  7504. t['controlESC'] = 0x001B;
  7505. t['controlETB'] = 0x0017;
  7506. t['controlETX'] = 0x0003;
  7507. t['controlFF'] = 0x000C;
  7508. t['controlFS'] = 0x001C;
  7509. t['controlGS'] = 0x001D;
  7510. t['controlHT'] = 0x0009;
  7511. t['controlLF'] = 0x000A;
  7512. t['controlNAK'] = 0x0015;
  7513. t['controlRS'] = 0x001E;
  7514. t['controlSI'] = 0x000F;
  7515. t['controlSO'] = 0x000E;
  7516. t['controlSOT'] = 0x0002;
  7517. t['controlSTX'] = 0x0001;
  7518. t['controlSUB'] = 0x001A;
  7519. t['controlSYN'] = 0x0016;
  7520. t['controlUS'] = 0x001F;
  7521. t['controlVT'] = 0x000B;
  7522. t['copyright'] = 0x00A9;
  7523. t['copyrightsans'] = 0xF8E9;
  7524. t['copyrightserif'] = 0xF6D9;
  7525. t['cornerbracketleft'] = 0x300C;
  7526. t['cornerbracketlefthalfwidth'] = 0xFF62;
  7527. t['cornerbracketleftvertical'] = 0xFE41;
  7528. t['cornerbracketright'] = 0x300D;
  7529. t['cornerbracketrighthalfwidth'] = 0xFF63;
  7530. t['cornerbracketrightvertical'] = 0xFE42;
  7531. t['corporationsquare'] = 0x337F;
  7532. t['cosquare'] = 0x33C7;
  7533. t['coverkgsquare'] = 0x33C6;
  7534. t['cparen'] = 0x249E;
  7535. t['cruzeiro'] = 0x20A2;
  7536. t['cstretched'] = 0x0297;
  7537. t['curlyand'] = 0x22CF;
  7538. t['curlyor'] = 0x22CE;
  7539. t['currency'] = 0x00A4;
  7540. t['cyrBreve'] = 0xF6D1;
  7541. t['cyrFlex'] = 0xF6D2;
  7542. t['cyrbreve'] = 0xF6D4;
  7543. t['cyrflex'] = 0xF6D5;
  7544. t['d'] = 0x0064;
  7545. t['daarmenian'] = 0x0564;
  7546. t['dabengali'] = 0x09A6;
  7547. t['dadarabic'] = 0x0636;
  7548. t['dadeva'] = 0x0926;
  7549. t['dadfinalarabic'] = 0xFEBE;
  7550. t['dadinitialarabic'] = 0xFEBF;
  7551. t['dadmedialarabic'] = 0xFEC0;
  7552. t['dagesh'] = 0x05BC;
  7553. t['dageshhebrew'] = 0x05BC;
  7554. t['dagger'] = 0x2020;
  7555. t['daggerdbl'] = 0x2021;
  7556. t['dagujarati'] = 0x0AA6;
  7557. t['dagurmukhi'] = 0x0A26;
  7558. t['dahiragana'] = 0x3060;
  7559. t['dakatakana'] = 0x30C0;
  7560. t['dalarabic'] = 0x062F;
  7561. t['dalet'] = 0x05D3;
  7562. t['daletdagesh'] = 0xFB33;
  7563. t['daletdageshhebrew'] = 0xFB33;
  7564. t['dalethebrew'] = 0x05D3;
  7565. t['dalfinalarabic'] = 0xFEAA;
  7566. t['dammaarabic'] = 0x064F;
  7567. t['dammalowarabic'] = 0x064F;
  7568. t['dammatanaltonearabic'] = 0x064C;
  7569. t['dammatanarabic'] = 0x064C;
  7570. t['danda'] = 0x0964;
  7571. t['dargahebrew'] = 0x05A7;
  7572. t['dargalefthebrew'] = 0x05A7;
  7573. t['dasiapneumatacyrilliccmb'] = 0x0485;
  7574. t['dblGrave'] = 0xF6D3;
  7575. t['dblanglebracketleft'] = 0x300A;
  7576. t['dblanglebracketleftvertical'] = 0xFE3D;
  7577. t['dblanglebracketright'] = 0x300B;
  7578. t['dblanglebracketrightvertical'] = 0xFE3E;
  7579. t['dblarchinvertedbelowcmb'] = 0x032B;
  7580. t['dblarrowleft'] = 0x21D4;
  7581. t['dblarrowright'] = 0x21D2;
  7582. t['dbldanda'] = 0x0965;
  7583. t['dblgrave'] = 0xF6D6;
  7584. t['dblgravecmb'] = 0x030F;
  7585. t['dblintegral'] = 0x222C;
  7586. t['dbllowline'] = 0x2017;
  7587. t['dbllowlinecmb'] = 0x0333;
  7588. t['dbloverlinecmb'] = 0x033F;
  7589. t['dblprimemod'] = 0x02BA;
  7590. t['dblverticalbar'] = 0x2016;
  7591. t['dblverticallineabovecmb'] = 0x030E;
  7592. t['dbopomofo'] = 0x3109;
  7593. t['dbsquare'] = 0x33C8;
  7594. t['dcaron'] = 0x010F;
  7595. t['dcedilla'] = 0x1E11;
  7596. t['dcircle'] = 0x24D3;
  7597. t['dcircumflexbelow'] = 0x1E13;
  7598. t['dcroat'] = 0x0111;
  7599. t['ddabengali'] = 0x09A1;
  7600. t['ddadeva'] = 0x0921;
  7601. t['ddagujarati'] = 0x0AA1;
  7602. t['ddagurmukhi'] = 0x0A21;
  7603. t['ddalarabic'] = 0x0688;
  7604. t['ddalfinalarabic'] = 0xFB89;
  7605. t['dddhadeva'] = 0x095C;
  7606. t['ddhabengali'] = 0x09A2;
  7607. t['ddhadeva'] = 0x0922;
  7608. t['ddhagujarati'] = 0x0AA2;
  7609. t['ddhagurmukhi'] = 0x0A22;
  7610. t['ddotaccent'] = 0x1E0B;
  7611. t['ddotbelow'] = 0x1E0D;
  7612. t['decimalseparatorarabic'] = 0x066B;
  7613. t['decimalseparatorpersian'] = 0x066B;
  7614. t['decyrillic'] = 0x0434;
  7615. t['degree'] = 0x00B0;
  7616. t['dehihebrew'] = 0x05AD;
  7617. t['dehiragana'] = 0x3067;
  7618. t['deicoptic'] = 0x03EF;
  7619. t['dekatakana'] = 0x30C7;
  7620. t['deleteleft'] = 0x232B;
  7621. t['deleteright'] = 0x2326;
  7622. t['delta'] = 0x03B4;
  7623. t['deltaturned'] = 0x018D;
  7624. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  7625. t['dezh'] = 0x02A4;
  7626. t['dhabengali'] = 0x09A7;
  7627. t['dhadeva'] = 0x0927;
  7628. t['dhagujarati'] = 0x0AA7;
  7629. t['dhagurmukhi'] = 0x0A27;
  7630. t['dhook'] = 0x0257;
  7631. t['dialytikatonos'] = 0x0385;
  7632. t['dialytikatonoscmb'] = 0x0344;
  7633. t['diamond'] = 0x2666;
  7634. t['diamondsuitwhite'] = 0x2662;
  7635. t['dieresis'] = 0x00A8;
  7636. t['dieresisacute'] = 0xF6D7;
  7637. t['dieresisbelowcmb'] = 0x0324;
  7638. t['dieresiscmb'] = 0x0308;
  7639. t['dieresisgrave'] = 0xF6D8;
  7640. t['dieresistonos'] = 0x0385;
  7641. t['dihiragana'] = 0x3062;
  7642. t['dikatakana'] = 0x30C2;
  7643. t['dittomark'] = 0x3003;
  7644. t['divide'] = 0x00F7;
  7645. t['divides'] = 0x2223;
  7646. t['divisionslash'] = 0x2215;
  7647. t['djecyrillic'] = 0x0452;
  7648. t['dkshade'] = 0x2593;
  7649. t['dlinebelow'] = 0x1E0F;
  7650. t['dlsquare'] = 0x3397;
  7651. t['dmacron'] = 0x0111;
  7652. t['dmonospace'] = 0xFF44;
  7653. t['dnblock'] = 0x2584;
  7654. t['dochadathai'] = 0x0E0E;
  7655. t['dodekthai'] = 0x0E14;
  7656. t['dohiragana'] = 0x3069;
  7657. t['dokatakana'] = 0x30C9;
  7658. t['dollar'] = 0x0024;
  7659. t['dollarinferior'] = 0xF6E3;
  7660. t['dollarmonospace'] = 0xFF04;
  7661. t['dollaroldstyle'] = 0xF724;
  7662. t['dollarsmall'] = 0xFE69;
  7663. t['dollarsuperior'] = 0xF6E4;
  7664. t['dong'] = 0x20AB;
  7665. t['dorusquare'] = 0x3326;
  7666. t['dotaccent'] = 0x02D9;
  7667. t['dotaccentcmb'] = 0x0307;
  7668. t['dotbelowcmb'] = 0x0323;
  7669. t['dotbelowcomb'] = 0x0323;
  7670. t['dotkatakana'] = 0x30FB;
  7671. t['dotlessi'] = 0x0131;
  7672. t['dotlessj'] = 0xF6BE;
  7673. t['dotlessjstrokehook'] = 0x0284;
  7674. t['dotmath'] = 0x22C5;
  7675. t['dottedcircle'] = 0x25CC;
  7676. t['doubleyodpatah'] = 0xFB1F;
  7677. t['doubleyodpatahhebrew'] = 0xFB1F;
  7678. t['downtackbelowcmb'] = 0x031E;
  7679. t['downtackmod'] = 0x02D5;
  7680. t['dparen'] = 0x249F;
  7681. t['dsuperior'] = 0xF6EB;
  7682. t['dtail'] = 0x0256;
  7683. t['dtopbar'] = 0x018C;
  7684. t['duhiragana'] = 0x3065;
  7685. t['dukatakana'] = 0x30C5;
  7686. t['dz'] = 0x01F3;
  7687. t['dzaltone'] = 0x02A3;
  7688. t['dzcaron'] = 0x01C6;
  7689. t['dzcurl'] = 0x02A5;
  7690. t['dzeabkhasiancyrillic'] = 0x04E1;
  7691. t['dzecyrillic'] = 0x0455;
  7692. t['dzhecyrillic'] = 0x045F;
  7693. t['e'] = 0x0065;
  7694. t['eacute'] = 0x00E9;
  7695. t['earth'] = 0x2641;
  7696. t['ebengali'] = 0x098F;
  7697. t['ebopomofo'] = 0x311C;
  7698. t['ebreve'] = 0x0115;
  7699. t['ecandradeva'] = 0x090D;
  7700. t['ecandragujarati'] = 0x0A8D;
  7701. t['ecandravowelsigndeva'] = 0x0945;
  7702. t['ecandravowelsigngujarati'] = 0x0AC5;
  7703. t['ecaron'] = 0x011B;
  7704. t['ecedillabreve'] = 0x1E1D;
  7705. t['echarmenian'] = 0x0565;
  7706. t['echyiwnarmenian'] = 0x0587;
  7707. t['ecircle'] = 0x24D4;
  7708. t['ecircumflex'] = 0x00EA;
  7709. t['ecircumflexacute'] = 0x1EBF;
  7710. t['ecircumflexbelow'] = 0x1E19;
  7711. t['ecircumflexdotbelow'] = 0x1EC7;
  7712. t['ecircumflexgrave'] = 0x1EC1;
  7713. t['ecircumflexhookabove'] = 0x1EC3;
  7714. t['ecircumflextilde'] = 0x1EC5;
  7715. t['ecyrillic'] = 0x0454;
  7716. t['edblgrave'] = 0x0205;
  7717. t['edeva'] = 0x090F;
  7718. t['edieresis'] = 0x00EB;
  7719. t['edot'] = 0x0117;
  7720. t['edotaccent'] = 0x0117;
  7721. t['edotbelow'] = 0x1EB9;
  7722. t['eegurmukhi'] = 0x0A0F;
  7723. t['eematragurmukhi'] = 0x0A47;
  7724. t['efcyrillic'] = 0x0444;
  7725. t['egrave'] = 0x00E8;
  7726. t['egujarati'] = 0x0A8F;
  7727. t['eharmenian'] = 0x0567;
  7728. t['ehbopomofo'] = 0x311D;
  7729. t['ehiragana'] = 0x3048;
  7730. t['ehookabove'] = 0x1EBB;
  7731. t['eibopomofo'] = 0x311F;
  7732. t['eight'] = 0x0038;
  7733. t['eightarabic'] = 0x0668;
  7734. t['eightbengali'] = 0x09EE;
  7735. t['eightcircle'] = 0x2467;
  7736. t['eightcircleinversesansserif'] = 0x2791;
  7737. t['eightdeva'] = 0x096E;
  7738. t['eighteencircle'] = 0x2471;
  7739. t['eighteenparen'] = 0x2485;
  7740. t['eighteenperiod'] = 0x2499;
  7741. t['eightgujarati'] = 0x0AEE;
  7742. t['eightgurmukhi'] = 0x0A6E;
  7743. t['eighthackarabic'] = 0x0668;
  7744. t['eighthangzhou'] = 0x3028;
  7745. t['eighthnotebeamed'] = 0x266B;
  7746. t['eightideographicparen'] = 0x3227;
  7747. t['eightinferior'] = 0x2088;
  7748. t['eightmonospace'] = 0xFF18;
  7749. t['eightoldstyle'] = 0xF738;
  7750. t['eightparen'] = 0x247B;
  7751. t['eightperiod'] = 0x248F;
  7752. t['eightpersian'] = 0x06F8;
  7753. t['eightroman'] = 0x2177;
  7754. t['eightsuperior'] = 0x2078;
  7755. t['eightthai'] = 0x0E58;
  7756. t['einvertedbreve'] = 0x0207;
  7757. t['eiotifiedcyrillic'] = 0x0465;
  7758. t['ekatakana'] = 0x30A8;
  7759. t['ekatakanahalfwidth'] = 0xFF74;
  7760. t['ekonkargurmukhi'] = 0x0A74;
  7761. t['ekorean'] = 0x3154;
  7762. t['elcyrillic'] = 0x043B;
  7763. t['element'] = 0x2208;
  7764. t['elevencircle'] = 0x246A;
  7765. t['elevenparen'] = 0x247E;
  7766. t['elevenperiod'] = 0x2492;
  7767. t['elevenroman'] = 0x217A;
  7768. t['ellipsis'] = 0x2026;
  7769. t['ellipsisvertical'] = 0x22EE;
  7770. t['emacron'] = 0x0113;
  7771. t['emacronacute'] = 0x1E17;
  7772. t['emacrongrave'] = 0x1E15;
  7773. t['emcyrillic'] = 0x043C;
  7774. t['emdash'] = 0x2014;
  7775. t['emdashvertical'] = 0xFE31;
  7776. t['emonospace'] = 0xFF45;
  7777. t['emphasismarkarmenian'] = 0x055B;
  7778. t['emptyset'] = 0x2205;
  7779. t['enbopomofo'] = 0x3123;
  7780. t['encyrillic'] = 0x043D;
  7781. t['endash'] = 0x2013;
  7782. t['endashvertical'] = 0xFE32;
  7783. t['endescendercyrillic'] = 0x04A3;
  7784. t['eng'] = 0x014B;
  7785. t['engbopomofo'] = 0x3125;
  7786. t['enghecyrillic'] = 0x04A5;
  7787. t['enhookcyrillic'] = 0x04C8;
  7788. t['enspace'] = 0x2002;
  7789. t['eogonek'] = 0x0119;
  7790. t['eokorean'] = 0x3153;
  7791. t['eopen'] = 0x025B;
  7792. t['eopenclosed'] = 0x029A;
  7793. t['eopenreversed'] = 0x025C;
  7794. t['eopenreversedclosed'] = 0x025E;
  7795. t['eopenreversedhook'] = 0x025D;
  7796. t['eparen'] = 0x24A0;
  7797. t['epsilon'] = 0x03B5;
  7798. t['epsilontonos'] = 0x03AD;
  7799. t['equal'] = 0x003D;
  7800. t['equalmonospace'] = 0xFF1D;
  7801. t['equalsmall'] = 0xFE66;
  7802. t['equalsuperior'] = 0x207C;
  7803. t['equivalence'] = 0x2261;
  7804. t['erbopomofo'] = 0x3126;
  7805. t['ercyrillic'] = 0x0440;
  7806. t['ereversed'] = 0x0258;
  7807. t['ereversedcyrillic'] = 0x044D;
  7808. t['escyrillic'] = 0x0441;
  7809. t['esdescendercyrillic'] = 0x04AB;
  7810. t['esh'] = 0x0283;
  7811. t['eshcurl'] = 0x0286;
  7812. t['eshortdeva'] = 0x090E;
  7813. t['eshortvowelsigndeva'] = 0x0946;
  7814. t['eshreversedloop'] = 0x01AA;
  7815. t['eshsquatreversed'] = 0x0285;
  7816. t['esmallhiragana'] = 0x3047;
  7817. t['esmallkatakana'] = 0x30A7;
  7818. t['esmallkatakanahalfwidth'] = 0xFF6A;
  7819. t['estimated'] = 0x212E;
  7820. t['esuperior'] = 0xF6EC;
  7821. t['eta'] = 0x03B7;
  7822. t['etarmenian'] = 0x0568;
  7823. t['etatonos'] = 0x03AE;
  7824. t['eth'] = 0x00F0;
  7825. t['etilde'] = 0x1EBD;
  7826. t['etildebelow'] = 0x1E1B;
  7827. t['etnahtafoukhhebrew'] = 0x0591;
  7828. t['etnahtafoukhlefthebrew'] = 0x0591;
  7829. t['etnahtahebrew'] = 0x0591;
  7830. t['etnahtalefthebrew'] = 0x0591;
  7831. t['eturned'] = 0x01DD;
  7832. t['eukorean'] = 0x3161;
  7833. t['euro'] = 0x20AC;
  7834. t['evowelsignbengali'] = 0x09C7;
  7835. t['evowelsigndeva'] = 0x0947;
  7836. t['evowelsigngujarati'] = 0x0AC7;
  7837. t['exclam'] = 0x0021;
  7838. t['exclamarmenian'] = 0x055C;
  7839. t['exclamdbl'] = 0x203C;
  7840. t['exclamdown'] = 0x00A1;
  7841. t['exclamdownsmall'] = 0xF7A1;
  7842. t['exclammonospace'] = 0xFF01;
  7843. t['exclamsmall'] = 0xF721;
  7844. t['existential'] = 0x2203;
  7845. t['ezh'] = 0x0292;
  7846. t['ezhcaron'] = 0x01EF;
  7847. t['ezhcurl'] = 0x0293;
  7848. t['ezhreversed'] = 0x01B9;
  7849. t['ezhtail'] = 0x01BA;
  7850. t['f'] = 0x0066;
  7851. t['fadeva'] = 0x095E;
  7852. t['fagurmukhi'] = 0x0A5E;
  7853. t['fahrenheit'] = 0x2109;
  7854. t['fathaarabic'] = 0x064E;
  7855. t['fathalowarabic'] = 0x064E;
  7856. t['fathatanarabic'] = 0x064B;
  7857. t['fbopomofo'] = 0x3108;
  7858. t['fcircle'] = 0x24D5;
  7859. t['fdotaccent'] = 0x1E1F;
  7860. t['feharabic'] = 0x0641;
  7861. t['feharmenian'] = 0x0586;
  7862. t['fehfinalarabic'] = 0xFED2;
  7863. t['fehinitialarabic'] = 0xFED3;
  7864. t['fehmedialarabic'] = 0xFED4;
  7865. t['feicoptic'] = 0x03E5;
  7866. t['female'] = 0x2640;
  7867. t['ff'] = 0xFB00;
  7868. t['ffi'] = 0xFB03;
  7869. t['ffl'] = 0xFB04;
  7870. t['fi'] = 0xFB01;
  7871. t['fifteencircle'] = 0x246E;
  7872. t['fifteenparen'] = 0x2482;
  7873. t['fifteenperiod'] = 0x2496;
  7874. t['figuredash'] = 0x2012;
  7875. t['filledbox'] = 0x25A0;
  7876. t['filledrect'] = 0x25AC;
  7877. t['finalkaf'] = 0x05DA;
  7878. t['finalkafdagesh'] = 0xFB3A;
  7879. t['finalkafdageshhebrew'] = 0xFB3A;
  7880. t['finalkafhebrew'] = 0x05DA;
  7881. t['finalmem'] = 0x05DD;
  7882. t['finalmemhebrew'] = 0x05DD;
  7883. t['finalnun'] = 0x05DF;
  7884. t['finalnunhebrew'] = 0x05DF;
  7885. t['finalpe'] = 0x05E3;
  7886. t['finalpehebrew'] = 0x05E3;
  7887. t['finaltsadi'] = 0x05E5;
  7888. t['finaltsadihebrew'] = 0x05E5;
  7889. t['firsttonechinese'] = 0x02C9;
  7890. t['fisheye'] = 0x25C9;
  7891. t['fitacyrillic'] = 0x0473;
  7892. t['five'] = 0x0035;
  7893. t['fivearabic'] = 0x0665;
  7894. t['fivebengali'] = 0x09EB;
  7895. t['fivecircle'] = 0x2464;
  7896. t['fivecircleinversesansserif'] = 0x278E;
  7897. t['fivedeva'] = 0x096B;
  7898. t['fiveeighths'] = 0x215D;
  7899. t['fivegujarati'] = 0x0AEB;
  7900. t['fivegurmukhi'] = 0x0A6B;
  7901. t['fivehackarabic'] = 0x0665;
  7902. t['fivehangzhou'] = 0x3025;
  7903. t['fiveideographicparen'] = 0x3224;
  7904. t['fiveinferior'] = 0x2085;
  7905. t['fivemonospace'] = 0xFF15;
  7906. t['fiveoldstyle'] = 0xF735;
  7907. t['fiveparen'] = 0x2478;
  7908. t['fiveperiod'] = 0x248C;
  7909. t['fivepersian'] = 0x06F5;
  7910. t['fiveroman'] = 0x2174;
  7911. t['fivesuperior'] = 0x2075;
  7912. t['fivethai'] = 0x0E55;
  7913. t['fl'] = 0xFB02;
  7914. t['florin'] = 0x0192;
  7915. t['fmonospace'] = 0xFF46;
  7916. t['fmsquare'] = 0x3399;
  7917. t['fofanthai'] = 0x0E1F;
  7918. t['fofathai'] = 0x0E1D;
  7919. t['fongmanthai'] = 0x0E4F;
  7920. t['forall'] = 0x2200;
  7921. t['four'] = 0x0034;
  7922. t['fourarabic'] = 0x0664;
  7923. t['fourbengali'] = 0x09EA;
  7924. t['fourcircle'] = 0x2463;
  7925. t['fourcircleinversesansserif'] = 0x278D;
  7926. t['fourdeva'] = 0x096A;
  7927. t['fourgujarati'] = 0x0AEA;
  7928. t['fourgurmukhi'] = 0x0A6A;
  7929. t['fourhackarabic'] = 0x0664;
  7930. t['fourhangzhou'] = 0x3024;
  7931. t['fourideographicparen'] = 0x3223;
  7932. t['fourinferior'] = 0x2084;
  7933. t['fourmonospace'] = 0xFF14;
  7934. t['fournumeratorbengali'] = 0x09F7;
  7935. t['fouroldstyle'] = 0xF734;
  7936. t['fourparen'] = 0x2477;
  7937. t['fourperiod'] = 0x248B;
  7938. t['fourpersian'] = 0x06F4;
  7939. t['fourroman'] = 0x2173;
  7940. t['foursuperior'] = 0x2074;
  7941. t['fourteencircle'] = 0x246D;
  7942. t['fourteenparen'] = 0x2481;
  7943. t['fourteenperiod'] = 0x2495;
  7944. t['fourthai'] = 0x0E54;
  7945. t['fourthtonechinese'] = 0x02CB;
  7946. t['fparen'] = 0x24A1;
  7947. t['fraction'] = 0x2044;
  7948. t['franc'] = 0x20A3;
  7949. t['g'] = 0x0067;
  7950. t['gabengali'] = 0x0997;
  7951. t['gacute'] = 0x01F5;
  7952. t['gadeva'] = 0x0917;
  7953. t['gafarabic'] = 0x06AF;
  7954. t['gaffinalarabic'] = 0xFB93;
  7955. t['gafinitialarabic'] = 0xFB94;
  7956. t['gafmedialarabic'] = 0xFB95;
  7957. t['gagujarati'] = 0x0A97;
  7958. t['gagurmukhi'] = 0x0A17;
  7959. t['gahiragana'] = 0x304C;
  7960. t['gakatakana'] = 0x30AC;
  7961. t['gamma'] = 0x03B3;
  7962. t['gammalatinsmall'] = 0x0263;
  7963. t['gammasuperior'] = 0x02E0;
  7964. t['gangiacoptic'] = 0x03EB;
  7965. t['gbopomofo'] = 0x310D;
  7966. t['gbreve'] = 0x011F;
  7967. t['gcaron'] = 0x01E7;
  7968. t['gcedilla'] = 0x0123;
  7969. t['gcircle'] = 0x24D6;
  7970. t['gcircumflex'] = 0x011D;
  7971. t['gcommaaccent'] = 0x0123;
  7972. t['gdot'] = 0x0121;
  7973. t['gdotaccent'] = 0x0121;
  7974. t['gecyrillic'] = 0x0433;
  7975. t['gehiragana'] = 0x3052;
  7976. t['gekatakana'] = 0x30B2;
  7977. t['geometricallyequal'] = 0x2251;
  7978. t['gereshaccenthebrew'] = 0x059C;
  7979. t['gereshhebrew'] = 0x05F3;
  7980. t['gereshmuqdamhebrew'] = 0x059D;
  7981. t['germandbls'] = 0x00DF;
  7982. t['gershayimaccenthebrew'] = 0x059E;
  7983. t['gershayimhebrew'] = 0x05F4;
  7984. t['getamark'] = 0x3013;
  7985. t['ghabengali'] = 0x0998;
  7986. t['ghadarmenian'] = 0x0572;
  7987. t['ghadeva'] = 0x0918;
  7988. t['ghagujarati'] = 0x0A98;
  7989. t['ghagurmukhi'] = 0x0A18;
  7990. t['ghainarabic'] = 0x063A;
  7991. t['ghainfinalarabic'] = 0xFECE;
  7992. t['ghaininitialarabic'] = 0xFECF;
  7993. t['ghainmedialarabic'] = 0xFED0;
  7994. t['ghemiddlehookcyrillic'] = 0x0495;
  7995. t['ghestrokecyrillic'] = 0x0493;
  7996. t['gheupturncyrillic'] = 0x0491;
  7997. t['ghhadeva'] = 0x095A;
  7998. t['ghhagurmukhi'] = 0x0A5A;
  7999. t['ghook'] = 0x0260;
  8000. t['ghzsquare'] = 0x3393;
  8001. t['gihiragana'] = 0x304E;
  8002. t['gikatakana'] = 0x30AE;
  8003. t['gimarmenian'] = 0x0563;
  8004. t['gimel'] = 0x05D2;
  8005. t['gimeldagesh'] = 0xFB32;
  8006. t['gimeldageshhebrew'] = 0xFB32;
  8007. t['gimelhebrew'] = 0x05D2;
  8008. t['gjecyrillic'] = 0x0453;
  8009. t['glottalinvertedstroke'] = 0x01BE;
  8010. t['glottalstop'] = 0x0294;
  8011. t['glottalstopinverted'] = 0x0296;
  8012. t['glottalstopmod'] = 0x02C0;
  8013. t['glottalstopreversed'] = 0x0295;
  8014. t['glottalstopreversedmod'] = 0x02C1;
  8015. t['glottalstopreversedsuperior'] = 0x02E4;
  8016. t['glottalstopstroke'] = 0x02A1;
  8017. t['glottalstopstrokereversed'] = 0x02A2;
  8018. t['gmacron'] = 0x1E21;
  8019. t['gmonospace'] = 0xFF47;
  8020. t['gohiragana'] = 0x3054;
  8021. t['gokatakana'] = 0x30B4;
  8022. t['gparen'] = 0x24A2;
  8023. t['gpasquare'] = 0x33AC;
  8024. t['gradient'] = 0x2207;
  8025. t['grave'] = 0x0060;
  8026. t['gravebelowcmb'] = 0x0316;
  8027. t['gravecmb'] = 0x0300;
  8028. t['gravecomb'] = 0x0300;
  8029. t['gravedeva'] = 0x0953;
  8030. t['gravelowmod'] = 0x02CE;
  8031. t['gravemonospace'] = 0xFF40;
  8032. t['gravetonecmb'] = 0x0340;
  8033. t['greater'] = 0x003E;
  8034. t['greaterequal'] = 0x2265;
  8035. t['greaterequalorless'] = 0x22DB;
  8036. t['greatermonospace'] = 0xFF1E;
  8037. t['greaterorequivalent'] = 0x2273;
  8038. t['greaterorless'] = 0x2277;
  8039. t['greateroverequal'] = 0x2267;
  8040. t['greatersmall'] = 0xFE65;
  8041. t['gscript'] = 0x0261;
  8042. t['gstroke'] = 0x01E5;
  8043. t['guhiragana'] = 0x3050;
  8044. t['guillemotleft'] = 0x00AB;
  8045. t['guillemotright'] = 0x00BB;
  8046. t['guilsinglleft'] = 0x2039;
  8047. t['guilsinglright'] = 0x203A;
  8048. t['gukatakana'] = 0x30B0;
  8049. t['guramusquare'] = 0x3318;
  8050. t['gysquare'] = 0x33C9;
  8051. t['h'] = 0x0068;
  8052. t['haabkhasiancyrillic'] = 0x04A9;
  8053. t['haaltonearabic'] = 0x06C1;
  8054. t['habengali'] = 0x09B9;
  8055. t['hadescendercyrillic'] = 0x04B3;
  8056. t['hadeva'] = 0x0939;
  8057. t['hagujarati'] = 0x0AB9;
  8058. t['hagurmukhi'] = 0x0A39;
  8059. t['haharabic'] = 0x062D;
  8060. t['hahfinalarabic'] = 0xFEA2;
  8061. t['hahinitialarabic'] = 0xFEA3;
  8062. t['hahiragana'] = 0x306F;
  8063. t['hahmedialarabic'] = 0xFEA4;
  8064. t['haitusquare'] = 0x332A;
  8065. t['hakatakana'] = 0x30CF;
  8066. t['hakatakanahalfwidth'] = 0xFF8A;
  8067. t['halantgurmukhi'] = 0x0A4D;
  8068. t['hamzaarabic'] = 0x0621;
  8069. t['hamzalowarabic'] = 0x0621;
  8070. t['hangulfiller'] = 0x3164;
  8071. t['hardsigncyrillic'] = 0x044A;
  8072. t['harpoonleftbarbup'] = 0x21BC;
  8073. t['harpoonrightbarbup'] = 0x21C0;
  8074. t['hasquare'] = 0x33CA;
  8075. t['hatafpatah'] = 0x05B2;
  8076. t['hatafpatah16'] = 0x05B2;
  8077. t['hatafpatah23'] = 0x05B2;
  8078. t['hatafpatah2f'] = 0x05B2;
  8079. t['hatafpatahhebrew'] = 0x05B2;
  8080. t['hatafpatahnarrowhebrew'] = 0x05B2;
  8081. t['hatafpatahquarterhebrew'] = 0x05B2;
  8082. t['hatafpatahwidehebrew'] = 0x05B2;
  8083. t['hatafqamats'] = 0x05B3;
  8084. t['hatafqamats1b'] = 0x05B3;
  8085. t['hatafqamats28'] = 0x05B3;
  8086. t['hatafqamats34'] = 0x05B3;
  8087. t['hatafqamatshebrew'] = 0x05B3;
  8088. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  8089. t['hatafqamatsquarterhebrew'] = 0x05B3;
  8090. t['hatafqamatswidehebrew'] = 0x05B3;
  8091. t['hatafsegol'] = 0x05B1;
  8092. t['hatafsegol17'] = 0x05B1;
  8093. t['hatafsegol24'] = 0x05B1;
  8094. t['hatafsegol30'] = 0x05B1;
  8095. t['hatafsegolhebrew'] = 0x05B1;
  8096. t['hatafsegolnarrowhebrew'] = 0x05B1;
  8097. t['hatafsegolquarterhebrew'] = 0x05B1;
  8098. t['hatafsegolwidehebrew'] = 0x05B1;
  8099. t['hbar'] = 0x0127;
  8100. t['hbopomofo'] = 0x310F;
  8101. t['hbrevebelow'] = 0x1E2B;
  8102. t['hcedilla'] = 0x1E29;
  8103. t['hcircle'] = 0x24D7;
  8104. t['hcircumflex'] = 0x0125;
  8105. t['hdieresis'] = 0x1E27;
  8106. t['hdotaccent'] = 0x1E23;
  8107. t['hdotbelow'] = 0x1E25;
  8108. t['he'] = 0x05D4;
  8109. t['heart'] = 0x2665;
  8110. t['heartsuitblack'] = 0x2665;
  8111. t['heartsuitwhite'] = 0x2661;
  8112. t['hedagesh'] = 0xFB34;
  8113. t['hedageshhebrew'] = 0xFB34;
  8114. t['hehaltonearabic'] = 0x06C1;
  8115. t['heharabic'] = 0x0647;
  8116. t['hehebrew'] = 0x05D4;
  8117. t['hehfinalaltonearabic'] = 0xFBA7;
  8118. t['hehfinalalttwoarabic'] = 0xFEEA;
  8119. t['hehfinalarabic'] = 0xFEEA;
  8120. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  8121. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  8122. t['hehinitialaltonearabic'] = 0xFBA8;
  8123. t['hehinitialarabic'] = 0xFEEB;
  8124. t['hehiragana'] = 0x3078;
  8125. t['hehmedialaltonearabic'] = 0xFBA9;
  8126. t['hehmedialarabic'] = 0xFEEC;
  8127. t['heiseierasquare'] = 0x337B;
  8128. t['hekatakana'] = 0x30D8;
  8129. t['hekatakanahalfwidth'] = 0xFF8D;
  8130. t['hekutaarusquare'] = 0x3336;
  8131. t['henghook'] = 0x0267;
  8132. t['herutusquare'] = 0x3339;
  8133. t['het'] = 0x05D7;
  8134. t['hethebrew'] = 0x05D7;
  8135. t['hhook'] = 0x0266;
  8136. t['hhooksuperior'] = 0x02B1;
  8137. t['hieuhacirclekorean'] = 0x327B;
  8138. t['hieuhaparenkorean'] = 0x321B;
  8139. t['hieuhcirclekorean'] = 0x326D;
  8140. t['hieuhkorean'] = 0x314E;
  8141. t['hieuhparenkorean'] = 0x320D;
  8142. t['hihiragana'] = 0x3072;
  8143. t['hikatakana'] = 0x30D2;
  8144. t['hikatakanahalfwidth'] = 0xFF8B;
  8145. t['hiriq'] = 0x05B4;
  8146. t['hiriq14'] = 0x05B4;
  8147. t['hiriq21'] = 0x05B4;
  8148. t['hiriq2d'] = 0x05B4;
  8149. t['hiriqhebrew'] = 0x05B4;
  8150. t['hiriqnarrowhebrew'] = 0x05B4;
  8151. t['hiriqquarterhebrew'] = 0x05B4;
  8152. t['hiriqwidehebrew'] = 0x05B4;
  8153. t['hlinebelow'] = 0x1E96;
  8154. t['hmonospace'] = 0xFF48;
  8155. t['hoarmenian'] = 0x0570;
  8156. t['hohipthai'] = 0x0E2B;
  8157. t['hohiragana'] = 0x307B;
  8158. t['hokatakana'] = 0x30DB;
  8159. t['hokatakanahalfwidth'] = 0xFF8E;
  8160. t['holam'] = 0x05B9;
  8161. t['holam19'] = 0x05B9;
  8162. t['holam26'] = 0x05B9;
  8163. t['holam32'] = 0x05B9;
  8164. t['holamhebrew'] = 0x05B9;
  8165. t['holamnarrowhebrew'] = 0x05B9;
  8166. t['holamquarterhebrew'] = 0x05B9;
  8167. t['holamwidehebrew'] = 0x05B9;
  8168. t['honokhukthai'] = 0x0E2E;
  8169. t['hookabovecomb'] = 0x0309;
  8170. t['hookcmb'] = 0x0309;
  8171. t['hookpalatalizedbelowcmb'] = 0x0321;
  8172. t['hookretroflexbelowcmb'] = 0x0322;
  8173. t['hoonsquare'] = 0x3342;
  8174. t['horicoptic'] = 0x03E9;
  8175. t['horizontalbar'] = 0x2015;
  8176. t['horncmb'] = 0x031B;
  8177. t['hotsprings'] = 0x2668;
  8178. t['house'] = 0x2302;
  8179. t['hparen'] = 0x24A3;
  8180. t['hsuperior'] = 0x02B0;
  8181. t['hturned'] = 0x0265;
  8182. t['huhiragana'] = 0x3075;
  8183. t['huiitosquare'] = 0x3333;
  8184. t['hukatakana'] = 0x30D5;
  8185. t['hukatakanahalfwidth'] = 0xFF8C;
  8186. t['hungarumlaut'] = 0x02DD;
  8187. t['hungarumlautcmb'] = 0x030B;
  8188. t['hv'] = 0x0195;
  8189. t['hyphen'] = 0x002D;
  8190. t['hypheninferior'] = 0xF6E5;
  8191. t['hyphenmonospace'] = 0xFF0D;
  8192. t['hyphensmall'] = 0xFE63;
  8193. t['hyphensuperior'] = 0xF6E6;
  8194. t['hyphentwo'] = 0x2010;
  8195. t['i'] = 0x0069;
  8196. t['iacute'] = 0x00ED;
  8197. t['iacyrillic'] = 0x044F;
  8198. t['ibengali'] = 0x0987;
  8199. t['ibopomofo'] = 0x3127;
  8200. t['ibreve'] = 0x012D;
  8201. t['icaron'] = 0x01D0;
  8202. t['icircle'] = 0x24D8;
  8203. t['icircumflex'] = 0x00EE;
  8204. t['icyrillic'] = 0x0456;
  8205. t['idblgrave'] = 0x0209;
  8206. t['ideographearthcircle'] = 0x328F;
  8207. t['ideographfirecircle'] = 0x328B;
  8208. t['ideographicallianceparen'] = 0x323F;
  8209. t['ideographiccallparen'] = 0x323A;
  8210. t['ideographiccentrecircle'] = 0x32A5;
  8211. t['ideographicclose'] = 0x3006;
  8212. t['ideographiccomma'] = 0x3001;
  8213. t['ideographiccommaleft'] = 0xFF64;
  8214. t['ideographiccongratulationparen'] = 0x3237;
  8215. t['ideographiccorrectcircle'] = 0x32A3;
  8216. t['ideographicearthparen'] = 0x322F;
  8217. t['ideographicenterpriseparen'] = 0x323D;
  8218. t['ideographicexcellentcircle'] = 0x329D;
  8219. t['ideographicfestivalparen'] = 0x3240;
  8220. t['ideographicfinancialcircle'] = 0x3296;
  8221. t['ideographicfinancialparen'] = 0x3236;
  8222. t['ideographicfireparen'] = 0x322B;
  8223. t['ideographichaveparen'] = 0x3232;
  8224. t['ideographichighcircle'] = 0x32A4;
  8225. t['ideographiciterationmark'] = 0x3005;
  8226. t['ideographiclaborcircle'] = 0x3298;
  8227. t['ideographiclaborparen'] = 0x3238;
  8228. t['ideographicleftcircle'] = 0x32A7;
  8229. t['ideographiclowcircle'] = 0x32A6;
  8230. t['ideographicmedicinecircle'] = 0x32A9;
  8231. t['ideographicmetalparen'] = 0x322E;
  8232. t['ideographicmoonparen'] = 0x322A;
  8233. t['ideographicnameparen'] = 0x3234;
  8234. t['ideographicperiod'] = 0x3002;
  8235. t['ideographicprintcircle'] = 0x329E;
  8236. t['ideographicreachparen'] = 0x3243;
  8237. t['ideographicrepresentparen'] = 0x3239;
  8238. t['ideographicresourceparen'] = 0x323E;
  8239. t['ideographicrightcircle'] = 0x32A8;
  8240. t['ideographicsecretcircle'] = 0x3299;
  8241. t['ideographicselfparen'] = 0x3242;
  8242. t['ideographicsocietyparen'] = 0x3233;
  8243. t['ideographicspace'] = 0x3000;
  8244. t['ideographicspecialparen'] = 0x3235;
  8245. t['ideographicstockparen'] = 0x3231;
  8246. t['ideographicstudyparen'] = 0x323B;
  8247. t['ideographicsunparen'] = 0x3230;
  8248. t['ideographicsuperviseparen'] = 0x323C;
  8249. t['ideographicwaterparen'] = 0x322C;
  8250. t['ideographicwoodparen'] = 0x322D;
  8251. t['ideographiczero'] = 0x3007;
  8252. t['ideographmetalcircle'] = 0x328E;
  8253. t['ideographmooncircle'] = 0x328A;
  8254. t['ideographnamecircle'] = 0x3294;
  8255. t['ideographsuncircle'] = 0x3290;
  8256. t['ideographwatercircle'] = 0x328C;
  8257. t['ideographwoodcircle'] = 0x328D;
  8258. t['ideva'] = 0x0907;
  8259. t['idieresis'] = 0x00EF;
  8260. t['idieresisacute'] = 0x1E2F;
  8261. t['idieresiscyrillic'] = 0x04E5;
  8262. t['idotbelow'] = 0x1ECB;
  8263. t['iebrevecyrillic'] = 0x04D7;
  8264. t['iecyrillic'] = 0x0435;
  8265. t['ieungacirclekorean'] = 0x3275;
  8266. t['ieungaparenkorean'] = 0x3215;
  8267. t['ieungcirclekorean'] = 0x3267;
  8268. t['ieungkorean'] = 0x3147;
  8269. t['ieungparenkorean'] = 0x3207;
  8270. t['igrave'] = 0x00EC;
  8271. t['igujarati'] = 0x0A87;
  8272. t['igurmukhi'] = 0x0A07;
  8273. t['ihiragana'] = 0x3044;
  8274. t['ihookabove'] = 0x1EC9;
  8275. t['iibengali'] = 0x0988;
  8276. t['iicyrillic'] = 0x0438;
  8277. t['iideva'] = 0x0908;
  8278. t['iigujarati'] = 0x0A88;
  8279. t['iigurmukhi'] = 0x0A08;
  8280. t['iimatragurmukhi'] = 0x0A40;
  8281. t['iinvertedbreve'] = 0x020B;
  8282. t['iishortcyrillic'] = 0x0439;
  8283. t['iivowelsignbengali'] = 0x09C0;
  8284. t['iivowelsigndeva'] = 0x0940;
  8285. t['iivowelsigngujarati'] = 0x0AC0;
  8286. t['ij'] = 0x0133;
  8287. t['ikatakana'] = 0x30A4;
  8288. t['ikatakanahalfwidth'] = 0xFF72;
  8289. t['ikorean'] = 0x3163;
  8290. t['ilde'] = 0x02DC;
  8291. t['iluyhebrew'] = 0x05AC;
  8292. t['imacron'] = 0x012B;
  8293. t['imacroncyrillic'] = 0x04E3;
  8294. t['imageorapproximatelyequal'] = 0x2253;
  8295. t['imatragurmukhi'] = 0x0A3F;
  8296. t['imonospace'] = 0xFF49;
  8297. t['increment'] = 0x2206;
  8298. t['infinity'] = 0x221E;
  8299. t['iniarmenian'] = 0x056B;
  8300. t['integral'] = 0x222B;
  8301. t['integralbottom'] = 0x2321;
  8302. t['integralbt'] = 0x2321;
  8303. t['integralex'] = 0xF8F5;
  8304. t['integraltop'] = 0x2320;
  8305. t['integraltp'] = 0x2320;
  8306. t['intersection'] = 0x2229;
  8307. t['intisquare'] = 0x3305;
  8308. t['invbullet'] = 0x25D8;
  8309. t['invcircle'] = 0x25D9;
  8310. t['invsmileface'] = 0x263B;
  8311. t['iocyrillic'] = 0x0451;
  8312. t['iogonek'] = 0x012F;
  8313. t['iota'] = 0x03B9;
  8314. t['iotadieresis'] = 0x03CA;
  8315. t['iotadieresistonos'] = 0x0390;
  8316. t['iotalatin'] = 0x0269;
  8317. t['iotatonos'] = 0x03AF;
  8318. t['iparen'] = 0x24A4;
  8319. t['irigurmukhi'] = 0x0A72;
  8320. t['ismallhiragana'] = 0x3043;
  8321. t['ismallkatakana'] = 0x30A3;
  8322. t['ismallkatakanahalfwidth'] = 0xFF68;
  8323. t['issharbengali'] = 0x09FA;
  8324. t['istroke'] = 0x0268;
  8325. t['isuperior'] = 0xF6ED;
  8326. t['iterationhiragana'] = 0x309D;
  8327. t['iterationkatakana'] = 0x30FD;
  8328. t['itilde'] = 0x0129;
  8329. t['itildebelow'] = 0x1E2D;
  8330. t['iubopomofo'] = 0x3129;
  8331. t['iucyrillic'] = 0x044E;
  8332. t['ivowelsignbengali'] = 0x09BF;
  8333. t['ivowelsigndeva'] = 0x093F;
  8334. t['ivowelsigngujarati'] = 0x0ABF;
  8335. t['izhitsacyrillic'] = 0x0475;
  8336. t['izhitsadblgravecyrillic'] = 0x0477;
  8337. t['j'] = 0x006A;
  8338. t['jaarmenian'] = 0x0571;
  8339. t['jabengali'] = 0x099C;
  8340. t['jadeva'] = 0x091C;
  8341. t['jagujarati'] = 0x0A9C;
  8342. t['jagurmukhi'] = 0x0A1C;
  8343. t['jbopomofo'] = 0x3110;
  8344. t['jcaron'] = 0x01F0;
  8345. t['jcircle'] = 0x24D9;
  8346. t['jcircumflex'] = 0x0135;
  8347. t['jcrossedtail'] = 0x029D;
  8348. t['jdotlessstroke'] = 0x025F;
  8349. t['jecyrillic'] = 0x0458;
  8350. t['jeemarabic'] = 0x062C;
  8351. t['jeemfinalarabic'] = 0xFE9E;
  8352. t['jeeminitialarabic'] = 0xFE9F;
  8353. t['jeemmedialarabic'] = 0xFEA0;
  8354. t['jeharabic'] = 0x0698;
  8355. t['jehfinalarabic'] = 0xFB8B;
  8356. t['jhabengali'] = 0x099D;
  8357. t['jhadeva'] = 0x091D;
  8358. t['jhagujarati'] = 0x0A9D;
  8359. t['jhagurmukhi'] = 0x0A1D;
  8360. t['jheharmenian'] = 0x057B;
  8361. t['jis'] = 0x3004;
  8362. t['jmonospace'] = 0xFF4A;
  8363. t['jparen'] = 0x24A5;
  8364. t['jsuperior'] = 0x02B2;
  8365. t['k'] = 0x006B;
  8366. t['kabashkircyrillic'] = 0x04A1;
  8367. t['kabengali'] = 0x0995;
  8368. t['kacute'] = 0x1E31;
  8369. t['kacyrillic'] = 0x043A;
  8370. t['kadescendercyrillic'] = 0x049B;
  8371. t['kadeva'] = 0x0915;
  8372. t['kaf'] = 0x05DB;
  8373. t['kafarabic'] = 0x0643;
  8374. t['kafdagesh'] = 0xFB3B;
  8375. t['kafdageshhebrew'] = 0xFB3B;
  8376. t['kaffinalarabic'] = 0xFEDA;
  8377. t['kafhebrew'] = 0x05DB;
  8378. t['kafinitialarabic'] = 0xFEDB;
  8379. t['kafmedialarabic'] = 0xFEDC;
  8380. t['kafrafehebrew'] = 0xFB4D;
  8381. t['kagujarati'] = 0x0A95;
  8382. t['kagurmukhi'] = 0x0A15;
  8383. t['kahiragana'] = 0x304B;
  8384. t['kahookcyrillic'] = 0x04C4;
  8385. t['kakatakana'] = 0x30AB;
  8386. t['kakatakanahalfwidth'] = 0xFF76;
  8387. t['kappa'] = 0x03BA;
  8388. t['kappasymbolgreek'] = 0x03F0;
  8389. t['kapyeounmieumkorean'] = 0x3171;
  8390. t['kapyeounphieuphkorean'] = 0x3184;
  8391. t['kapyeounpieupkorean'] = 0x3178;
  8392. t['kapyeounssangpieupkorean'] = 0x3179;
  8393. t['karoriisquare'] = 0x330D;
  8394. t['kashidaautoarabic'] = 0x0640;
  8395. t['kashidaautonosidebearingarabic'] = 0x0640;
  8396. t['kasmallkatakana'] = 0x30F5;
  8397. t['kasquare'] = 0x3384;
  8398. t['kasraarabic'] = 0x0650;
  8399. t['kasratanarabic'] = 0x064D;
  8400. t['kastrokecyrillic'] = 0x049F;
  8401. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  8402. t['kaverticalstrokecyrillic'] = 0x049D;
  8403. t['kbopomofo'] = 0x310E;
  8404. t['kcalsquare'] = 0x3389;
  8405. t['kcaron'] = 0x01E9;
  8406. t['kcedilla'] = 0x0137;
  8407. t['kcircle'] = 0x24DA;
  8408. t['kcommaaccent'] = 0x0137;
  8409. t['kdotbelow'] = 0x1E33;
  8410. t['keharmenian'] = 0x0584;
  8411. t['kehiragana'] = 0x3051;
  8412. t['kekatakana'] = 0x30B1;
  8413. t['kekatakanahalfwidth'] = 0xFF79;
  8414. t['kenarmenian'] = 0x056F;
  8415. t['kesmallkatakana'] = 0x30F6;
  8416. t['kgreenlandic'] = 0x0138;
  8417. t['khabengali'] = 0x0996;
  8418. t['khacyrillic'] = 0x0445;
  8419. t['khadeva'] = 0x0916;
  8420. t['khagujarati'] = 0x0A96;
  8421. t['khagurmukhi'] = 0x0A16;
  8422. t['khaharabic'] = 0x062E;
  8423. t['khahfinalarabic'] = 0xFEA6;
  8424. t['khahinitialarabic'] = 0xFEA7;
  8425. t['khahmedialarabic'] = 0xFEA8;
  8426. t['kheicoptic'] = 0x03E7;
  8427. t['khhadeva'] = 0x0959;
  8428. t['khhagurmukhi'] = 0x0A59;
  8429. t['khieukhacirclekorean'] = 0x3278;
  8430. t['khieukhaparenkorean'] = 0x3218;
  8431. t['khieukhcirclekorean'] = 0x326A;
  8432. t['khieukhkorean'] = 0x314B;
  8433. t['khieukhparenkorean'] = 0x320A;
  8434. t['khokhaithai'] = 0x0E02;
  8435. t['khokhonthai'] = 0x0E05;
  8436. t['khokhuatthai'] = 0x0E03;
  8437. t['khokhwaithai'] = 0x0E04;
  8438. t['khomutthai'] = 0x0E5B;
  8439. t['khook'] = 0x0199;
  8440. t['khorakhangthai'] = 0x0E06;
  8441. t['khzsquare'] = 0x3391;
  8442. t['kihiragana'] = 0x304D;
  8443. t['kikatakana'] = 0x30AD;
  8444. t['kikatakanahalfwidth'] = 0xFF77;
  8445. t['kiroguramusquare'] = 0x3315;
  8446. t['kiromeetorusquare'] = 0x3316;
  8447. t['kirosquare'] = 0x3314;
  8448. t['kiyeokacirclekorean'] = 0x326E;
  8449. t['kiyeokaparenkorean'] = 0x320E;
  8450. t['kiyeokcirclekorean'] = 0x3260;
  8451. t['kiyeokkorean'] = 0x3131;
  8452. t['kiyeokparenkorean'] = 0x3200;
  8453. t['kiyeoksioskorean'] = 0x3133;
  8454. t['kjecyrillic'] = 0x045C;
  8455. t['klinebelow'] = 0x1E35;
  8456. t['klsquare'] = 0x3398;
  8457. t['kmcubedsquare'] = 0x33A6;
  8458. t['kmonospace'] = 0xFF4B;
  8459. t['kmsquaredsquare'] = 0x33A2;
  8460. t['kohiragana'] = 0x3053;
  8461. t['kohmsquare'] = 0x33C0;
  8462. t['kokaithai'] = 0x0E01;
  8463. t['kokatakana'] = 0x30B3;
  8464. t['kokatakanahalfwidth'] = 0xFF7A;
  8465. t['kooposquare'] = 0x331E;
  8466. t['koppacyrillic'] = 0x0481;
  8467. t['koreanstandardsymbol'] = 0x327F;
  8468. t['koroniscmb'] = 0x0343;
  8469. t['kparen'] = 0x24A6;
  8470. t['kpasquare'] = 0x33AA;
  8471. t['ksicyrillic'] = 0x046F;
  8472. t['ktsquare'] = 0x33CF;
  8473. t['kturned'] = 0x029E;
  8474. t['kuhiragana'] = 0x304F;
  8475. t['kukatakana'] = 0x30AF;
  8476. t['kukatakanahalfwidth'] = 0xFF78;
  8477. t['kvsquare'] = 0x33B8;
  8478. t['kwsquare'] = 0x33BE;
  8479. t['l'] = 0x006C;
  8480. t['labengali'] = 0x09B2;
  8481. t['lacute'] = 0x013A;
  8482. t['ladeva'] = 0x0932;
  8483. t['lagujarati'] = 0x0AB2;
  8484. t['lagurmukhi'] = 0x0A32;
  8485. t['lakkhangyaothai'] = 0x0E45;
  8486. t['lamaleffinalarabic'] = 0xFEFC;
  8487. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  8488. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  8489. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  8490. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  8491. t['lamalefisolatedarabic'] = 0xFEFB;
  8492. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  8493. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  8494. t['lamarabic'] = 0x0644;
  8495. t['lambda'] = 0x03BB;
  8496. t['lambdastroke'] = 0x019B;
  8497. t['lamed'] = 0x05DC;
  8498. t['lameddagesh'] = 0xFB3C;
  8499. t['lameddageshhebrew'] = 0xFB3C;
  8500. t['lamedhebrew'] = 0x05DC;
  8501. t['lamfinalarabic'] = 0xFEDE;
  8502. t['lamhahinitialarabic'] = 0xFCCA;
  8503. t['laminitialarabic'] = 0xFEDF;
  8504. t['lamjeeminitialarabic'] = 0xFCC9;
  8505. t['lamkhahinitialarabic'] = 0xFCCB;
  8506. t['lamlamhehisolatedarabic'] = 0xFDF2;
  8507. t['lammedialarabic'] = 0xFEE0;
  8508. t['lammeemhahinitialarabic'] = 0xFD88;
  8509. t['lammeeminitialarabic'] = 0xFCCC;
  8510. t['largecircle'] = 0x25EF;
  8511. t['lbar'] = 0x019A;
  8512. t['lbelt'] = 0x026C;
  8513. t['lbopomofo'] = 0x310C;
  8514. t['lcaron'] = 0x013E;
  8515. t['lcedilla'] = 0x013C;
  8516. t['lcircle'] = 0x24DB;
  8517. t['lcircumflexbelow'] = 0x1E3D;
  8518. t['lcommaaccent'] = 0x013C;
  8519. t['ldot'] = 0x0140;
  8520. t['ldotaccent'] = 0x0140;
  8521. t['ldotbelow'] = 0x1E37;
  8522. t['ldotbelowmacron'] = 0x1E39;
  8523. t['leftangleabovecmb'] = 0x031A;
  8524. t['lefttackbelowcmb'] = 0x0318;
  8525. t['less'] = 0x003C;
  8526. t['lessequal'] = 0x2264;
  8527. t['lessequalorgreater'] = 0x22DA;
  8528. t['lessmonospace'] = 0xFF1C;
  8529. t['lessorequivalent'] = 0x2272;
  8530. t['lessorgreater'] = 0x2276;
  8531. t['lessoverequal'] = 0x2266;
  8532. t['lesssmall'] = 0xFE64;
  8533. t['lezh'] = 0x026E;
  8534. t['lfblock'] = 0x258C;
  8535. t['lhookretroflex'] = 0x026D;
  8536. t['lira'] = 0x20A4;
  8537. t['liwnarmenian'] = 0x056C;
  8538. t['lj'] = 0x01C9;
  8539. t['ljecyrillic'] = 0x0459;
  8540. t['ll'] = 0xF6C0;
  8541. t['lladeva'] = 0x0933;
  8542. t['llagujarati'] = 0x0AB3;
  8543. t['llinebelow'] = 0x1E3B;
  8544. t['llladeva'] = 0x0934;
  8545. t['llvocalicbengali'] = 0x09E1;
  8546. t['llvocalicdeva'] = 0x0961;
  8547. t['llvocalicvowelsignbengali'] = 0x09E3;
  8548. t['llvocalicvowelsigndeva'] = 0x0963;
  8549. t['lmiddletilde'] = 0x026B;
  8550. t['lmonospace'] = 0xFF4C;
  8551. t['lmsquare'] = 0x33D0;
  8552. t['lochulathai'] = 0x0E2C;
  8553. t['logicaland'] = 0x2227;
  8554. t['logicalnot'] = 0x00AC;
  8555. t['logicalnotreversed'] = 0x2310;
  8556. t['logicalor'] = 0x2228;
  8557. t['lolingthai'] = 0x0E25;
  8558. t['longs'] = 0x017F;
  8559. t['lowlinecenterline'] = 0xFE4E;
  8560. t['lowlinecmb'] = 0x0332;
  8561. t['lowlinedashed'] = 0xFE4D;
  8562. t['lozenge'] = 0x25CA;
  8563. t['lparen'] = 0x24A7;
  8564. t['lslash'] = 0x0142;
  8565. t['lsquare'] = 0x2113;
  8566. t['lsuperior'] = 0xF6EE;
  8567. t['ltshade'] = 0x2591;
  8568. t['luthai'] = 0x0E26;
  8569. t['lvocalicbengali'] = 0x098C;
  8570. t['lvocalicdeva'] = 0x090C;
  8571. t['lvocalicvowelsignbengali'] = 0x09E2;
  8572. t['lvocalicvowelsigndeva'] = 0x0962;
  8573. t['lxsquare'] = 0x33D3;
  8574. t['m'] = 0x006D;
  8575. t['mabengali'] = 0x09AE;
  8576. t['macron'] = 0x00AF;
  8577. t['macronbelowcmb'] = 0x0331;
  8578. t['macroncmb'] = 0x0304;
  8579. t['macronlowmod'] = 0x02CD;
  8580. t['macronmonospace'] = 0xFFE3;
  8581. t['macute'] = 0x1E3F;
  8582. t['madeva'] = 0x092E;
  8583. t['magujarati'] = 0x0AAE;
  8584. t['magurmukhi'] = 0x0A2E;
  8585. t['mahapakhhebrew'] = 0x05A4;
  8586. t['mahapakhlefthebrew'] = 0x05A4;
  8587. t['mahiragana'] = 0x307E;
  8588. t['maichattawalowleftthai'] = 0xF895;
  8589. t['maichattawalowrightthai'] = 0xF894;
  8590. t['maichattawathai'] = 0x0E4B;
  8591. t['maichattawaupperleftthai'] = 0xF893;
  8592. t['maieklowleftthai'] = 0xF88C;
  8593. t['maieklowrightthai'] = 0xF88B;
  8594. t['maiekthai'] = 0x0E48;
  8595. t['maiekupperleftthai'] = 0xF88A;
  8596. t['maihanakatleftthai'] = 0xF884;
  8597. t['maihanakatthai'] = 0x0E31;
  8598. t['maitaikhuleftthai'] = 0xF889;
  8599. t['maitaikhuthai'] = 0x0E47;
  8600. t['maitholowleftthai'] = 0xF88F;
  8601. t['maitholowrightthai'] = 0xF88E;
  8602. t['maithothai'] = 0x0E49;
  8603. t['maithoupperleftthai'] = 0xF88D;
  8604. t['maitrilowleftthai'] = 0xF892;
  8605. t['maitrilowrightthai'] = 0xF891;
  8606. t['maitrithai'] = 0x0E4A;
  8607. t['maitriupperleftthai'] = 0xF890;
  8608. t['maiyamokthai'] = 0x0E46;
  8609. t['makatakana'] = 0x30DE;
  8610. t['makatakanahalfwidth'] = 0xFF8F;
  8611. t['male'] = 0x2642;
  8612. t['mansyonsquare'] = 0x3347;
  8613. t['maqafhebrew'] = 0x05BE;
  8614. t['mars'] = 0x2642;
  8615. t['masoracirclehebrew'] = 0x05AF;
  8616. t['masquare'] = 0x3383;
  8617. t['mbopomofo'] = 0x3107;
  8618. t['mbsquare'] = 0x33D4;
  8619. t['mcircle'] = 0x24DC;
  8620. t['mcubedsquare'] = 0x33A5;
  8621. t['mdotaccent'] = 0x1E41;
  8622. t['mdotbelow'] = 0x1E43;
  8623. t['meemarabic'] = 0x0645;
  8624. t['meemfinalarabic'] = 0xFEE2;
  8625. t['meeminitialarabic'] = 0xFEE3;
  8626. t['meemmedialarabic'] = 0xFEE4;
  8627. t['meemmeeminitialarabic'] = 0xFCD1;
  8628. t['meemmeemisolatedarabic'] = 0xFC48;
  8629. t['meetorusquare'] = 0x334D;
  8630. t['mehiragana'] = 0x3081;
  8631. t['meizierasquare'] = 0x337E;
  8632. t['mekatakana'] = 0x30E1;
  8633. t['mekatakanahalfwidth'] = 0xFF92;
  8634. t['mem'] = 0x05DE;
  8635. t['memdagesh'] = 0xFB3E;
  8636. t['memdageshhebrew'] = 0xFB3E;
  8637. t['memhebrew'] = 0x05DE;
  8638. t['menarmenian'] = 0x0574;
  8639. t['merkhahebrew'] = 0x05A5;
  8640. t['merkhakefulahebrew'] = 0x05A6;
  8641. t['merkhakefulalefthebrew'] = 0x05A6;
  8642. t['merkhalefthebrew'] = 0x05A5;
  8643. t['mhook'] = 0x0271;
  8644. t['mhzsquare'] = 0x3392;
  8645. t['middledotkatakanahalfwidth'] = 0xFF65;
  8646. t['middot'] = 0x00B7;
  8647. t['mieumacirclekorean'] = 0x3272;
  8648. t['mieumaparenkorean'] = 0x3212;
  8649. t['mieumcirclekorean'] = 0x3264;
  8650. t['mieumkorean'] = 0x3141;
  8651. t['mieumpansioskorean'] = 0x3170;
  8652. t['mieumparenkorean'] = 0x3204;
  8653. t['mieumpieupkorean'] = 0x316E;
  8654. t['mieumsioskorean'] = 0x316F;
  8655. t['mihiragana'] = 0x307F;
  8656. t['mikatakana'] = 0x30DF;
  8657. t['mikatakanahalfwidth'] = 0xFF90;
  8658. t['minus'] = 0x2212;
  8659. t['minusbelowcmb'] = 0x0320;
  8660. t['minuscircle'] = 0x2296;
  8661. t['minusmod'] = 0x02D7;
  8662. t['minusplus'] = 0x2213;
  8663. t['minute'] = 0x2032;
  8664. t['miribaarusquare'] = 0x334A;
  8665. t['mirisquare'] = 0x3349;
  8666. t['mlonglegturned'] = 0x0270;
  8667. t['mlsquare'] = 0x3396;
  8668. t['mmcubedsquare'] = 0x33A3;
  8669. t['mmonospace'] = 0xFF4D;
  8670. t['mmsquaredsquare'] = 0x339F;
  8671. t['mohiragana'] = 0x3082;
  8672. t['mohmsquare'] = 0x33C1;
  8673. t['mokatakana'] = 0x30E2;
  8674. t['mokatakanahalfwidth'] = 0xFF93;
  8675. t['molsquare'] = 0x33D6;
  8676. t['momathai'] = 0x0E21;
  8677. t['moverssquare'] = 0x33A7;
  8678. t['moverssquaredsquare'] = 0x33A8;
  8679. t['mparen'] = 0x24A8;
  8680. t['mpasquare'] = 0x33AB;
  8681. t['mssquare'] = 0x33B3;
  8682. t['msuperior'] = 0xF6EF;
  8683. t['mturned'] = 0x026F;
  8684. t['mu'] = 0x00B5;
  8685. t['mu1'] = 0x00B5;
  8686. t['muasquare'] = 0x3382;
  8687. t['muchgreater'] = 0x226B;
  8688. t['muchless'] = 0x226A;
  8689. t['mufsquare'] = 0x338C;
  8690. t['mugreek'] = 0x03BC;
  8691. t['mugsquare'] = 0x338D;
  8692. t['muhiragana'] = 0x3080;
  8693. t['mukatakana'] = 0x30E0;
  8694. t['mukatakanahalfwidth'] = 0xFF91;
  8695. t['mulsquare'] = 0x3395;
  8696. t['multiply'] = 0x00D7;
  8697. t['mumsquare'] = 0x339B;
  8698. t['munahhebrew'] = 0x05A3;
  8699. t['munahlefthebrew'] = 0x05A3;
  8700. t['musicalnote'] = 0x266A;
  8701. t['musicalnotedbl'] = 0x266B;
  8702. t['musicflatsign'] = 0x266D;
  8703. t['musicsharpsign'] = 0x266F;
  8704. t['mussquare'] = 0x33B2;
  8705. t['muvsquare'] = 0x33B6;
  8706. t['muwsquare'] = 0x33BC;
  8707. t['mvmegasquare'] = 0x33B9;
  8708. t['mvsquare'] = 0x33B7;
  8709. t['mwmegasquare'] = 0x33BF;
  8710. t['mwsquare'] = 0x33BD;
  8711. t['n'] = 0x006E;
  8712. t['nabengali'] = 0x09A8;
  8713. t['nabla'] = 0x2207;
  8714. t['nacute'] = 0x0144;
  8715. t['nadeva'] = 0x0928;
  8716. t['nagujarati'] = 0x0AA8;
  8717. t['nagurmukhi'] = 0x0A28;
  8718. t['nahiragana'] = 0x306A;
  8719. t['nakatakana'] = 0x30CA;
  8720. t['nakatakanahalfwidth'] = 0xFF85;
  8721. t['napostrophe'] = 0x0149;
  8722. t['nasquare'] = 0x3381;
  8723. t['nbopomofo'] = 0x310B;
  8724. t['nbspace'] = 0x00A0;
  8725. t['ncaron'] = 0x0148;
  8726. t['ncedilla'] = 0x0146;
  8727. t['ncircle'] = 0x24DD;
  8728. t['ncircumflexbelow'] = 0x1E4B;
  8729. t['ncommaaccent'] = 0x0146;
  8730. t['ndotaccent'] = 0x1E45;
  8731. t['ndotbelow'] = 0x1E47;
  8732. t['nehiragana'] = 0x306D;
  8733. t['nekatakana'] = 0x30CD;
  8734. t['nekatakanahalfwidth'] = 0xFF88;
  8735. t['newsheqelsign'] = 0x20AA;
  8736. t['nfsquare'] = 0x338B;
  8737. t['ngabengali'] = 0x0999;
  8738. t['ngadeva'] = 0x0919;
  8739. t['ngagujarati'] = 0x0A99;
  8740. t['ngagurmukhi'] = 0x0A19;
  8741. t['ngonguthai'] = 0x0E07;
  8742. t['nhiragana'] = 0x3093;
  8743. t['nhookleft'] = 0x0272;
  8744. t['nhookretroflex'] = 0x0273;
  8745. t['nieunacirclekorean'] = 0x326F;
  8746. t['nieunaparenkorean'] = 0x320F;
  8747. t['nieuncieuckorean'] = 0x3135;
  8748. t['nieuncirclekorean'] = 0x3261;
  8749. t['nieunhieuhkorean'] = 0x3136;
  8750. t['nieunkorean'] = 0x3134;
  8751. t['nieunpansioskorean'] = 0x3168;
  8752. t['nieunparenkorean'] = 0x3201;
  8753. t['nieunsioskorean'] = 0x3167;
  8754. t['nieuntikeutkorean'] = 0x3166;
  8755. t['nihiragana'] = 0x306B;
  8756. t['nikatakana'] = 0x30CB;
  8757. t['nikatakanahalfwidth'] = 0xFF86;
  8758. t['nikhahitleftthai'] = 0xF899;
  8759. t['nikhahitthai'] = 0x0E4D;
  8760. t['nine'] = 0x0039;
  8761. t['ninearabic'] = 0x0669;
  8762. t['ninebengali'] = 0x09EF;
  8763. t['ninecircle'] = 0x2468;
  8764. t['ninecircleinversesansserif'] = 0x2792;
  8765. t['ninedeva'] = 0x096F;
  8766. t['ninegujarati'] = 0x0AEF;
  8767. t['ninegurmukhi'] = 0x0A6F;
  8768. t['ninehackarabic'] = 0x0669;
  8769. t['ninehangzhou'] = 0x3029;
  8770. t['nineideographicparen'] = 0x3228;
  8771. t['nineinferior'] = 0x2089;
  8772. t['ninemonospace'] = 0xFF19;
  8773. t['nineoldstyle'] = 0xF739;
  8774. t['nineparen'] = 0x247C;
  8775. t['nineperiod'] = 0x2490;
  8776. t['ninepersian'] = 0x06F9;
  8777. t['nineroman'] = 0x2178;
  8778. t['ninesuperior'] = 0x2079;
  8779. t['nineteencircle'] = 0x2472;
  8780. t['nineteenparen'] = 0x2486;
  8781. t['nineteenperiod'] = 0x249A;
  8782. t['ninethai'] = 0x0E59;
  8783. t['nj'] = 0x01CC;
  8784. t['njecyrillic'] = 0x045A;
  8785. t['nkatakana'] = 0x30F3;
  8786. t['nkatakanahalfwidth'] = 0xFF9D;
  8787. t['nlegrightlong'] = 0x019E;
  8788. t['nlinebelow'] = 0x1E49;
  8789. t['nmonospace'] = 0xFF4E;
  8790. t['nmsquare'] = 0x339A;
  8791. t['nnabengali'] = 0x09A3;
  8792. t['nnadeva'] = 0x0923;
  8793. t['nnagujarati'] = 0x0AA3;
  8794. t['nnagurmukhi'] = 0x0A23;
  8795. t['nnnadeva'] = 0x0929;
  8796. t['nohiragana'] = 0x306E;
  8797. t['nokatakana'] = 0x30CE;
  8798. t['nokatakanahalfwidth'] = 0xFF89;
  8799. t['nonbreakingspace'] = 0x00A0;
  8800. t['nonenthai'] = 0x0E13;
  8801. t['nonuthai'] = 0x0E19;
  8802. t['noonarabic'] = 0x0646;
  8803. t['noonfinalarabic'] = 0xFEE6;
  8804. t['noonghunnaarabic'] = 0x06BA;
  8805. t['noonghunnafinalarabic'] = 0xFB9F;
  8806. t['nooninitialarabic'] = 0xFEE7;
  8807. t['noonjeeminitialarabic'] = 0xFCD2;
  8808. t['noonjeemisolatedarabic'] = 0xFC4B;
  8809. t['noonmedialarabic'] = 0xFEE8;
  8810. t['noonmeeminitialarabic'] = 0xFCD5;
  8811. t['noonmeemisolatedarabic'] = 0xFC4E;
  8812. t['noonnoonfinalarabic'] = 0xFC8D;
  8813. t['notcontains'] = 0x220C;
  8814. t['notelement'] = 0x2209;
  8815. t['notelementof'] = 0x2209;
  8816. t['notequal'] = 0x2260;
  8817. t['notgreater'] = 0x226F;
  8818. t['notgreaternorequal'] = 0x2271;
  8819. t['notgreaternorless'] = 0x2279;
  8820. t['notidentical'] = 0x2262;
  8821. t['notless'] = 0x226E;
  8822. t['notlessnorequal'] = 0x2270;
  8823. t['notparallel'] = 0x2226;
  8824. t['notprecedes'] = 0x2280;
  8825. t['notsubset'] = 0x2284;
  8826. t['notsucceeds'] = 0x2281;
  8827. t['notsuperset'] = 0x2285;
  8828. t['nowarmenian'] = 0x0576;
  8829. t['nparen'] = 0x24A9;
  8830. t['nssquare'] = 0x33B1;
  8831. t['nsuperior'] = 0x207F;
  8832. t['ntilde'] = 0x00F1;
  8833. t['nu'] = 0x03BD;
  8834. t['nuhiragana'] = 0x306C;
  8835. t['nukatakana'] = 0x30CC;
  8836. t['nukatakanahalfwidth'] = 0xFF87;
  8837. t['nuktabengali'] = 0x09BC;
  8838. t['nuktadeva'] = 0x093C;
  8839. t['nuktagujarati'] = 0x0ABC;
  8840. t['nuktagurmukhi'] = 0x0A3C;
  8841. t['numbersign'] = 0x0023;
  8842. t['numbersignmonospace'] = 0xFF03;
  8843. t['numbersignsmall'] = 0xFE5F;
  8844. t['numeralsigngreek'] = 0x0374;
  8845. t['numeralsignlowergreek'] = 0x0375;
  8846. t['numero'] = 0x2116;
  8847. t['nun'] = 0x05E0;
  8848. t['nundagesh'] = 0xFB40;
  8849. t['nundageshhebrew'] = 0xFB40;
  8850. t['nunhebrew'] = 0x05E0;
  8851. t['nvsquare'] = 0x33B5;
  8852. t['nwsquare'] = 0x33BB;
  8853. t['nyabengali'] = 0x099E;
  8854. t['nyadeva'] = 0x091E;
  8855. t['nyagujarati'] = 0x0A9E;
  8856. t['nyagurmukhi'] = 0x0A1E;
  8857. t['o'] = 0x006F;
  8858. t['oacute'] = 0x00F3;
  8859. t['oangthai'] = 0x0E2D;
  8860. t['obarred'] = 0x0275;
  8861. t['obarredcyrillic'] = 0x04E9;
  8862. t['obarreddieresiscyrillic'] = 0x04EB;
  8863. t['obengali'] = 0x0993;
  8864. t['obopomofo'] = 0x311B;
  8865. t['obreve'] = 0x014F;
  8866. t['ocandradeva'] = 0x0911;
  8867. t['ocandragujarati'] = 0x0A91;
  8868. t['ocandravowelsigndeva'] = 0x0949;
  8869. t['ocandravowelsigngujarati'] = 0x0AC9;
  8870. t['ocaron'] = 0x01D2;
  8871. t['ocircle'] = 0x24DE;
  8872. t['ocircumflex'] = 0x00F4;
  8873. t['ocircumflexacute'] = 0x1ED1;
  8874. t['ocircumflexdotbelow'] = 0x1ED9;
  8875. t['ocircumflexgrave'] = 0x1ED3;
  8876. t['ocircumflexhookabove'] = 0x1ED5;
  8877. t['ocircumflextilde'] = 0x1ED7;
  8878. t['ocyrillic'] = 0x043E;
  8879. t['odblacute'] = 0x0151;
  8880. t['odblgrave'] = 0x020D;
  8881. t['odeva'] = 0x0913;
  8882. t['odieresis'] = 0x00F6;
  8883. t['odieresiscyrillic'] = 0x04E7;
  8884. t['odotbelow'] = 0x1ECD;
  8885. t['oe'] = 0x0153;
  8886. t['oekorean'] = 0x315A;
  8887. t['ogonek'] = 0x02DB;
  8888. t['ogonekcmb'] = 0x0328;
  8889. t['ograve'] = 0x00F2;
  8890. t['ogujarati'] = 0x0A93;
  8891. t['oharmenian'] = 0x0585;
  8892. t['ohiragana'] = 0x304A;
  8893. t['ohookabove'] = 0x1ECF;
  8894. t['ohorn'] = 0x01A1;
  8895. t['ohornacute'] = 0x1EDB;
  8896. t['ohorndotbelow'] = 0x1EE3;
  8897. t['ohorngrave'] = 0x1EDD;
  8898. t['ohornhookabove'] = 0x1EDF;
  8899. t['ohorntilde'] = 0x1EE1;
  8900. t['ohungarumlaut'] = 0x0151;
  8901. t['oi'] = 0x01A3;
  8902. t['oinvertedbreve'] = 0x020F;
  8903. t['okatakana'] = 0x30AA;
  8904. t['okatakanahalfwidth'] = 0xFF75;
  8905. t['okorean'] = 0x3157;
  8906. t['olehebrew'] = 0x05AB;
  8907. t['omacron'] = 0x014D;
  8908. t['omacronacute'] = 0x1E53;
  8909. t['omacrongrave'] = 0x1E51;
  8910. t['omdeva'] = 0x0950;
  8911. t['omega'] = 0x03C9;
  8912. t['omega1'] = 0x03D6;
  8913. t['omegacyrillic'] = 0x0461;
  8914. t['omegalatinclosed'] = 0x0277;
  8915. t['omegaroundcyrillic'] = 0x047B;
  8916. t['omegatitlocyrillic'] = 0x047D;
  8917. t['omegatonos'] = 0x03CE;
  8918. t['omgujarati'] = 0x0AD0;
  8919. t['omicron'] = 0x03BF;
  8920. t['omicrontonos'] = 0x03CC;
  8921. t['omonospace'] = 0xFF4F;
  8922. t['one'] = 0x0031;
  8923. t['onearabic'] = 0x0661;
  8924. t['onebengali'] = 0x09E7;
  8925. t['onecircle'] = 0x2460;
  8926. t['onecircleinversesansserif'] = 0x278A;
  8927. t['onedeva'] = 0x0967;
  8928. t['onedotenleader'] = 0x2024;
  8929. t['oneeighth'] = 0x215B;
  8930. t['onefitted'] = 0xF6DC;
  8931. t['onegujarati'] = 0x0AE7;
  8932. t['onegurmukhi'] = 0x0A67;
  8933. t['onehackarabic'] = 0x0661;
  8934. t['onehalf'] = 0x00BD;
  8935. t['onehangzhou'] = 0x3021;
  8936. t['oneideographicparen'] = 0x3220;
  8937. t['oneinferior'] = 0x2081;
  8938. t['onemonospace'] = 0xFF11;
  8939. t['onenumeratorbengali'] = 0x09F4;
  8940. t['oneoldstyle'] = 0xF731;
  8941. t['oneparen'] = 0x2474;
  8942. t['oneperiod'] = 0x2488;
  8943. t['onepersian'] = 0x06F1;
  8944. t['onequarter'] = 0x00BC;
  8945. t['oneroman'] = 0x2170;
  8946. t['onesuperior'] = 0x00B9;
  8947. t['onethai'] = 0x0E51;
  8948. t['onethird'] = 0x2153;
  8949. t['oogonek'] = 0x01EB;
  8950. t['oogonekmacron'] = 0x01ED;
  8951. t['oogurmukhi'] = 0x0A13;
  8952. t['oomatragurmukhi'] = 0x0A4B;
  8953. t['oopen'] = 0x0254;
  8954. t['oparen'] = 0x24AA;
  8955. t['openbullet'] = 0x25E6;
  8956. t['option'] = 0x2325;
  8957. t['ordfeminine'] = 0x00AA;
  8958. t['ordmasculine'] = 0x00BA;
  8959. t['orthogonal'] = 0x221F;
  8960. t['oshortdeva'] = 0x0912;
  8961. t['oshortvowelsigndeva'] = 0x094A;
  8962. t['oslash'] = 0x00F8;
  8963. t['oslashacute'] = 0x01FF;
  8964. t['osmallhiragana'] = 0x3049;
  8965. t['osmallkatakana'] = 0x30A9;
  8966. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8967. t['ostrokeacute'] = 0x01FF;
  8968. t['osuperior'] = 0xF6F0;
  8969. t['otcyrillic'] = 0x047F;
  8970. t['otilde'] = 0x00F5;
  8971. t['otildeacute'] = 0x1E4D;
  8972. t['otildedieresis'] = 0x1E4F;
  8973. t['oubopomofo'] = 0x3121;
  8974. t['overline'] = 0x203E;
  8975. t['overlinecenterline'] = 0xFE4A;
  8976. t['overlinecmb'] = 0x0305;
  8977. t['overlinedashed'] = 0xFE49;
  8978. t['overlinedblwavy'] = 0xFE4C;
  8979. t['overlinewavy'] = 0xFE4B;
  8980. t['overscore'] = 0x00AF;
  8981. t['ovowelsignbengali'] = 0x09CB;
  8982. t['ovowelsigndeva'] = 0x094B;
  8983. t['ovowelsigngujarati'] = 0x0ACB;
  8984. t['p'] = 0x0070;
  8985. t['paampssquare'] = 0x3380;
  8986. t['paasentosquare'] = 0x332B;
  8987. t['pabengali'] = 0x09AA;
  8988. t['pacute'] = 0x1E55;
  8989. t['padeva'] = 0x092A;
  8990. t['pagedown'] = 0x21DF;
  8991. t['pageup'] = 0x21DE;
  8992. t['pagujarati'] = 0x0AAA;
  8993. t['pagurmukhi'] = 0x0A2A;
  8994. t['pahiragana'] = 0x3071;
  8995. t['paiyannoithai'] = 0x0E2F;
  8996. t['pakatakana'] = 0x30D1;
  8997. t['palatalizationcyrilliccmb'] = 0x0484;
  8998. t['palochkacyrillic'] = 0x04C0;
  8999. t['pansioskorean'] = 0x317F;
  9000. t['paragraph'] = 0x00B6;
  9001. t['parallel'] = 0x2225;
  9002. t['parenleft'] = 0x0028;
  9003. t['parenleftaltonearabic'] = 0xFD3E;
  9004. t['parenleftbt'] = 0xF8ED;
  9005. t['parenleftex'] = 0xF8EC;
  9006. t['parenleftinferior'] = 0x208D;
  9007. t['parenleftmonospace'] = 0xFF08;
  9008. t['parenleftsmall'] = 0xFE59;
  9009. t['parenleftsuperior'] = 0x207D;
  9010. t['parenlefttp'] = 0xF8EB;
  9011. t['parenleftvertical'] = 0xFE35;
  9012. t['parenright'] = 0x0029;
  9013. t['parenrightaltonearabic'] = 0xFD3F;
  9014. t['parenrightbt'] = 0xF8F8;
  9015. t['parenrightex'] = 0xF8F7;
  9016. t['parenrightinferior'] = 0x208E;
  9017. t['parenrightmonospace'] = 0xFF09;
  9018. t['parenrightsmall'] = 0xFE5A;
  9019. t['parenrightsuperior'] = 0x207E;
  9020. t['parenrighttp'] = 0xF8F6;
  9021. t['parenrightvertical'] = 0xFE36;
  9022. t['partialdiff'] = 0x2202;
  9023. t['paseqhebrew'] = 0x05C0;
  9024. t['pashtahebrew'] = 0x0599;
  9025. t['pasquare'] = 0x33A9;
  9026. t['patah'] = 0x05B7;
  9027. t['patah11'] = 0x05B7;
  9028. t['patah1d'] = 0x05B7;
  9029. t['patah2a'] = 0x05B7;
  9030. t['patahhebrew'] = 0x05B7;
  9031. t['patahnarrowhebrew'] = 0x05B7;
  9032. t['patahquarterhebrew'] = 0x05B7;
  9033. t['patahwidehebrew'] = 0x05B7;
  9034. t['pazerhebrew'] = 0x05A1;
  9035. t['pbopomofo'] = 0x3106;
  9036. t['pcircle'] = 0x24DF;
  9037. t['pdotaccent'] = 0x1E57;
  9038. t['pe'] = 0x05E4;
  9039. t['pecyrillic'] = 0x043F;
  9040. t['pedagesh'] = 0xFB44;
  9041. t['pedageshhebrew'] = 0xFB44;
  9042. t['peezisquare'] = 0x333B;
  9043. t['pefinaldageshhebrew'] = 0xFB43;
  9044. t['peharabic'] = 0x067E;
  9045. t['peharmenian'] = 0x057A;
  9046. t['pehebrew'] = 0x05E4;
  9047. t['pehfinalarabic'] = 0xFB57;
  9048. t['pehinitialarabic'] = 0xFB58;
  9049. t['pehiragana'] = 0x307A;
  9050. t['pehmedialarabic'] = 0xFB59;
  9051. t['pekatakana'] = 0x30DA;
  9052. t['pemiddlehookcyrillic'] = 0x04A7;
  9053. t['perafehebrew'] = 0xFB4E;
  9054. t['percent'] = 0x0025;
  9055. t['percentarabic'] = 0x066A;
  9056. t['percentmonospace'] = 0xFF05;
  9057. t['percentsmall'] = 0xFE6A;
  9058. t['period'] = 0x002E;
  9059. t['periodarmenian'] = 0x0589;
  9060. t['periodcentered'] = 0x00B7;
  9061. t['periodhalfwidth'] = 0xFF61;
  9062. t['periodinferior'] = 0xF6E7;
  9063. t['periodmonospace'] = 0xFF0E;
  9064. t['periodsmall'] = 0xFE52;
  9065. t['periodsuperior'] = 0xF6E8;
  9066. t['perispomenigreekcmb'] = 0x0342;
  9067. t['perpendicular'] = 0x22A5;
  9068. t['perthousand'] = 0x2030;
  9069. t['peseta'] = 0x20A7;
  9070. t['pfsquare'] = 0x338A;
  9071. t['phabengali'] = 0x09AB;
  9072. t['phadeva'] = 0x092B;
  9073. t['phagujarati'] = 0x0AAB;
  9074. t['phagurmukhi'] = 0x0A2B;
  9075. t['phi'] = 0x03C6;
  9076. t['phi1'] = 0x03D5;
  9077. t['phieuphacirclekorean'] = 0x327A;
  9078. t['phieuphaparenkorean'] = 0x321A;
  9079. t['phieuphcirclekorean'] = 0x326C;
  9080. t['phieuphkorean'] = 0x314D;
  9081. t['phieuphparenkorean'] = 0x320C;
  9082. t['philatin'] = 0x0278;
  9083. t['phinthuthai'] = 0x0E3A;
  9084. t['phisymbolgreek'] = 0x03D5;
  9085. t['phook'] = 0x01A5;
  9086. t['phophanthai'] = 0x0E1E;
  9087. t['phophungthai'] = 0x0E1C;
  9088. t['phosamphaothai'] = 0x0E20;
  9089. t['pi'] = 0x03C0;
  9090. t['pieupacirclekorean'] = 0x3273;
  9091. t['pieupaparenkorean'] = 0x3213;
  9092. t['pieupcieuckorean'] = 0x3176;
  9093. t['pieupcirclekorean'] = 0x3265;
  9094. t['pieupkiyeokkorean'] = 0x3172;
  9095. t['pieupkorean'] = 0x3142;
  9096. t['pieupparenkorean'] = 0x3205;
  9097. t['pieupsioskiyeokkorean'] = 0x3174;
  9098. t['pieupsioskorean'] = 0x3144;
  9099. t['pieupsiostikeutkorean'] = 0x3175;
  9100. t['pieupthieuthkorean'] = 0x3177;
  9101. t['pieuptikeutkorean'] = 0x3173;
  9102. t['pihiragana'] = 0x3074;
  9103. t['pikatakana'] = 0x30D4;
  9104. t['pisymbolgreek'] = 0x03D6;
  9105. t['piwrarmenian'] = 0x0583;
  9106. t['plus'] = 0x002B;
  9107. t['plusbelowcmb'] = 0x031F;
  9108. t['pluscircle'] = 0x2295;
  9109. t['plusminus'] = 0x00B1;
  9110. t['plusmod'] = 0x02D6;
  9111. t['plusmonospace'] = 0xFF0B;
  9112. t['plussmall'] = 0xFE62;
  9113. t['plussuperior'] = 0x207A;
  9114. t['pmonospace'] = 0xFF50;
  9115. t['pmsquare'] = 0x33D8;
  9116. t['pohiragana'] = 0x307D;
  9117. t['pointingindexdownwhite'] = 0x261F;
  9118. t['pointingindexleftwhite'] = 0x261C;
  9119. t['pointingindexrightwhite'] = 0x261E;
  9120. t['pointingindexupwhite'] = 0x261D;
  9121. t['pokatakana'] = 0x30DD;
  9122. t['poplathai'] = 0x0E1B;
  9123. t['postalmark'] = 0x3012;
  9124. t['postalmarkface'] = 0x3020;
  9125. t['pparen'] = 0x24AB;
  9126. t['precedes'] = 0x227A;
  9127. t['prescription'] = 0x211E;
  9128. t['primemod'] = 0x02B9;
  9129. t['primereversed'] = 0x2035;
  9130. t['product'] = 0x220F;
  9131. t['projective'] = 0x2305;
  9132. t['prolongedkana'] = 0x30FC;
  9133. t['propellor'] = 0x2318;
  9134. t['propersubset'] = 0x2282;
  9135. t['propersuperset'] = 0x2283;
  9136. t['proportion'] = 0x2237;
  9137. t['proportional'] = 0x221D;
  9138. t['psi'] = 0x03C8;
  9139. t['psicyrillic'] = 0x0471;
  9140. t['psilipneumatacyrilliccmb'] = 0x0486;
  9141. t['pssquare'] = 0x33B0;
  9142. t['puhiragana'] = 0x3077;
  9143. t['pukatakana'] = 0x30D7;
  9144. t['pvsquare'] = 0x33B4;
  9145. t['pwsquare'] = 0x33BA;
  9146. t['q'] = 0x0071;
  9147. t['qadeva'] = 0x0958;
  9148. t['qadmahebrew'] = 0x05A8;
  9149. t['qafarabic'] = 0x0642;
  9150. t['qaffinalarabic'] = 0xFED6;
  9151. t['qafinitialarabic'] = 0xFED7;
  9152. t['qafmedialarabic'] = 0xFED8;
  9153. t['qamats'] = 0x05B8;
  9154. t['qamats10'] = 0x05B8;
  9155. t['qamats1a'] = 0x05B8;
  9156. t['qamats1c'] = 0x05B8;
  9157. t['qamats27'] = 0x05B8;
  9158. t['qamats29'] = 0x05B8;
  9159. t['qamats33'] = 0x05B8;
  9160. t['qamatsde'] = 0x05B8;
  9161. t['qamatshebrew'] = 0x05B8;
  9162. t['qamatsnarrowhebrew'] = 0x05B8;
  9163. t['qamatsqatanhebrew'] = 0x05B8;
  9164. t['qamatsqatannarrowhebrew'] = 0x05B8;
  9165. t['qamatsqatanquarterhebrew'] = 0x05B8;
  9166. t['qamatsqatanwidehebrew'] = 0x05B8;
  9167. t['qamatsquarterhebrew'] = 0x05B8;
  9168. t['qamatswidehebrew'] = 0x05B8;
  9169. t['qarneyparahebrew'] = 0x059F;
  9170. t['qbopomofo'] = 0x3111;
  9171. t['qcircle'] = 0x24E0;
  9172. t['qhook'] = 0x02A0;
  9173. t['qmonospace'] = 0xFF51;
  9174. t['qof'] = 0x05E7;
  9175. t['qofdagesh'] = 0xFB47;
  9176. t['qofdageshhebrew'] = 0xFB47;
  9177. t['qofhebrew'] = 0x05E7;
  9178. t['qparen'] = 0x24AC;
  9179. t['quarternote'] = 0x2669;
  9180. t['qubuts'] = 0x05BB;
  9181. t['qubuts18'] = 0x05BB;
  9182. t['qubuts25'] = 0x05BB;
  9183. t['qubuts31'] = 0x05BB;
  9184. t['qubutshebrew'] = 0x05BB;
  9185. t['qubutsnarrowhebrew'] = 0x05BB;
  9186. t['qubutsquarterhebrew'] = 0x05BB;
  9187. t['qubutswidehebrew'] = 0x05BB;
  9188. t['question'] = 0x003F;
  9189. t['questionarabic'] = 0x061F;
  9190. t['questionarmenian'] = 0x055E;
  9191. t['questiondown'] = 0x00BF;
  9192. t['questiondownsmall'] = 0xF7BF;
  9193. t['questiongreek'] = 0x037E;
  9194. t['questionmonospace'] = 0xFF1F;
  9195. t['questionsmall'] = 0xF73F;
  9196. t['quotedbl'] = 0x0022;
  9197. t['quotedblbase'] = 0x201E;
  9198. t['quotedblleft'] = 0x201C;
  9199. t['quotedblmonospace'] = 0xFF02;
  9200. t['quotedblprime'] = 0x301E;
  9201. t['quotedblprimereversed'] = 0x301D;
  9202. t['quotedblright'] = 0x201D;
  9203. t['quoteleft'] = 0x2018;
  9204. t['quoteleftreversed'] = 0x201B;
  9205. t['quotereversed'] = 0x201B;
  9206. t['quoteright'] = 0x2019;
  9207. t['quoterightn'] = 0x0149;
  9208. t['quotesinglbase'] = 0x201A;
  9209. t['quotesingle'] = 0x0027;
  9210. t['quotesinglemonospace'] = 0xFF07;
  9211. t['r'] = 0x0072;
  9212. t['raarmenian'] = 0x057C;
  9213. t['rabengali'] = 0x09B0;
  9214. t['racute'] = 0x0155;
  9215. t['radeva'] = 0x0930;
  9216. t['radical'] = 0x221A;
  9217. t['radicalex'] = 0xF8E5;
  9218. t['radoverssquare'] = 0x33AE;
  9219. t['radoverssquaredsquare'] = 0x33AF;
  9220. t['radsquare'] = 0x33AD;
  9221. t['rafe'] = 0x05BF;
  9222. t['rafehebrew'] = 0x05BF;
  9223. t['ragujarati'] = 0x0AB0;
  9224. t['ragurmukhi'] = 0x0A30;
  9225. t['rahiragana'] = 0x3089;
  9226. t['rakatakana'] = 0x30E9;
  9227. t['rakatakanahalfwidth'] = 0xFF97;
  9228. t['ralowerdiagonalbengali'] = 0x09F1;
  9229. t['ramiddlediagonalbengali'] = 0x09F0;
  9230. t['ramshorn'] = 0x0264;
  9231. t['ratio'] = 0x2236;
  9232. t['rbopomofo'] = 0x3116;
  9233. t['rcaron'] = 0x0159;
  9234. t['rcedilla'] = 0x0157;
  9235. t['rcircle'] = 0x24E1;
  9236. t['rcommaaccent'] = 0x0157;
  9237. t['rdblgrave'] = 0x0211;
  9238. t['rdotaccent'] = 0x1E59;
  9239. t['rdotbelow'] = 0x1E5B;
  9240. t['rdotbelowmacron'] = 0x1E5D;
  9241. t['referencemark'] = 0x203B;
  9242. t['reflexsubset'] = 0x2286;
  9243. t['reflexsuperset'] = 0x2287;
  9244. t['registered'] = 0x00AE;
  9245. t['registersans'] = 0xF8E8;
  9246. t['registerserif'] = 0xF6DA;
  9247. t['reharabic'] = 0x0631;
  9248. t['reharmenian'] = 0x0580;
  9249. t['rehfinalarabic'] = 0xFEAE;
  9250. t['rehiragana'] = 0x308C;
  9251. t['rekatakana'] = 0x30EC;
  9252. t['rekatakanahalfwidth'] = 0xFF9A;
  9253. t['resh'] = 0x05E8;
  9254. t['reshdageshhebrew'] = 0xFB48;
  9255. t['reshhebrew'] = 0x05E8;
  9256. t['reversedtilde'] = 0x223D;
  9257. t['reviahebrew'] = 0x0597;
  9258. t['reviamugrashhebrew'] = 0x0597;
  9259. t['revlogicalnot'] = 0x2310;
  9260. t['rfishhook'] = 0x027E;
  9261. t['rfishhookreversed'] = 0x027F;
  9262. t['rhabengali'] = 0x09DD;
  9263. t['rhadeva'] = 0x095D;
  9264. t['rho'] = 0x03C1;
  9265. t['rhook'] = 0x027D;
  9266. t['rhookturned'] = 0x027B;
  9267. t['rhookturnedsuperior'] = 0x02B5;
  9268. t['rhosymbolgreek'] = 0x03F1;
  9269. t['rhotichookmod'] = 0x02DE;
  9270. t['rieulacirclekorean'] = 0x3271;
  9271. t['rieulaparenkorean'] = 0x3211;
  9272. t['rieulcirclekorean'] = 0x3263;
  9273. t['rieulhieuhkorean'] = 0x3140;
  9274. t['rieulkiyeokkorean'] = 0x313A;
  9275. t['rieulkiyeoksioskorean'] = 0x3169;
  9276. t['rieulkorean'] = 0x3139;
  9277. t['rieulmieumkorean'] = 0x313B;
  9278. t['rieulpansioskorean'] = 0x316C;
  9279. t['rieulparenkorean'] = 0x3203;
  9280. t['rieulphieuphkorean'] = 0x313F;
  9281. t['rieulpieupkorean'] = 0x313C;
  9282. t['rieulpieupsioskorean'] = 0x316B;
  9283. t['rieulsioskorean'] = 0x313D;
  9284. t['rieulthieuthkorean'] = 0x313E;
  9285. t['rieultikeutkorean'] = 0x316A;
  9286. t['rieulyeorinhieuhkorean'] = 0x316D;
  9287. t['rightangle'] = 0x221F;
  9288. t['righttackbelowcmb'] = 0x0319;
  9289. t['righttriangle'] = 0x22BF;
  9290. t['rihiragana'] = 0x308A;
  9291. t['rikatakana'] = 0x30EA;
  9292. t['rikatakanahalfwidth'] = 0xFF98;
  9293. t['ring'] = 0x02DA;
  9294. t['ringbelowcmb'] = 0x0325;
  9295. t['ringcmb'] = 0x030A;
  9296. t['ringhalfleft'] = 0x02BF;
  9297. t['ringhalfleftarmenian'] = 0x0559;
  9298. t['ringhalfleftbelowcmb'] = 0x031C;
  9299. t['ringhalfleftcentered'] = 0x02D3;
  9300. t['ringhalfright'] = 0x02BE;
  9301. t['ringhalfrightbelowcmb'] = 0x0339;
  9302. t['ringhalfrightcentered'] = 0x02D2;
  9303. t['rinvertedbreve'] = 0x0213;
  9304. t['rittorusquare'] = 0x3351;
  9305. t['rlinebelow'] = 0x1E5F;
  9306. t['rlongleg'] = 0x027C;
  9307. t['rlonglegturned'] = 0x027A;
  9308. t['rmonospace'] = 0xFF52;
  9309. t['rohiragana'] = 0x308D;
  9310. t['rokatakana'] = 0x30ED;
  9311. t['rokatakanahalfwidth'] = 0xFF9B;
  9312. t['roruathai'] = 0x0E23;
  9313. t['rparen'] = 0x24AD;
  9314. t['rrabengali'] = 0x09DC;
  9315. t['rradeva'] = 0x0931;
  9316. t['rragurmukhi'] = 0x0A5C;
  9317. t['rreharabic'] = 0x0691;
  9318. t['rrehfinalarabic'] = 0xFB8D;
  9319. t['rrvocalicbengali'] = 0x09E0;
  9320. t['rrvocalicdeva'] = 0x0960;
  9321. t['rrvocalicgujarati'] = 0x0AE0;
  9322. t['rrvocalicvowelsignbengali'] = 0x09C4;
  9323. t['rrvocalicvowelsigndeva'] = 0x0944;
  9324. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  9325. t['rsuperior'] = 0xF6F1;
  9326. t['rtblock'] = 0x2590;
  9327. t['rturned'] = 0x0279;
  9328. t['rturnedsuperior'] = 0x02B4;
  9329. t['ruhiragana'] = 0x308B;
  9330. t['rukatakana'] = 0x30EB;
  9331. t['rukatakanahalfwidth'] = 0xFF99;
  9332. t['rupeemarkbengali'] = 0x09F2;
  9333. t['rupeesignbengali'] = 0x09F3;
  9334. t['rupiah'] = 0xF6DD;
  9335. t['ruthai'] = 0x0E24;
  9336. t['rvocalicbengali'] = 0x098B;
  9337. t['rvocalicdeva'] = 0x090B;
  9338. t['rvocalicgujarati'] = 0x0A8B;
  9339. t['rvocalicvowelsignbengali'] = 0x09C3;
  9340. t['rvocalicvowelsigndeva'] = 0x0943;
  9341. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  9342. t['s'] = 0x0073;
  9343. t['sabengali'] = 0x09B8;
  9344. t['sacute'] = 0x015B;
  9345. t['sacutedotaccent'] = 0x1E65;
  9346. t['sadarabic'] = 0x0635;
  9347. t['sadeva'] = 0x0938;
  9348. t['sadfinalarabic'] = 0xFEBA;
  9349. t['sadinitialarabic'] = 0xFEBB;
  9350. t['sadmedialarabic'] = 0xFEBC;
  9351. t['sagujarati'] = 0x0AB8;
  9352. t['sagurmukhi'] = 0x0A38;
  9353. t['sahiragana'] = 0x3055;
  9354. t['sakatakana'] = 0x30B5;
  9355. t['sakatakanahalfwidth'] = 0xFF7B;
  9356. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  9357. t['samekh'] = 0x05E1;
  9358. t['samekhdagesh'] = 0xFB41;
  9359. t['samekhdageshhebrew'] = 0xFB41;
  9360. t['samekhhebrew'] = 0x05E1;
  9361. t['saraaathai'] = 0x0E32;
  9362. t['saraaethai'] = 0x0E41;
  9363. t['saraaimaimalaithai'] = 0x0E44;
  9364. t['saraaimaimuanthai'] = 0x0E43;
  9365. t['saraamthai'] = 0x0E33;
  9366. t['saraathai'] = 0x0E30;
  9367. t['saraethai'] = 0x0E40;
  9368. t['saraiileftthai'] = 0xF886;
  9369. t['saraiithai'] = 0x0E35;
  9370. t['saraileftthai'] = 0xF885;
  9371. t['saraithai'] = 0x0E34;
  9372. t['saraothai'] = 0x0E42;
  9373. t['saraueeleftthai'] = 0xF888;
  9374. t['saraueethai'] = 0x0E37;
  9375. t['saraueleftthai'] = 0xF887;
  9376. t['sarauethai'] = 0x0E36;
  9377. t['sarauthai'] = 0x0E38;
  9378. t['sarauuthai'] = 0x0E39;
  9379. t['sbopomofo'] = 0x3119;
  9380. t['scaron'] = 0x0161;
  9381. t['scarondotaccent'] = 0x1E67;
  9382. t['scedilla'] = 0x015F;
  9383. t['schwa'] = 0x0259;
  9384. t['schwacyrillic'] = 0x04D9;
  9385. t['schwadieresiscyrillic'] = 0x04DB;
  9386. t['schwahook'] = 0x025A;
  9387. t['scircle'] = 0x24E2;
  9388. t['scircumflex'] = 0x015D;
  9389. t['scommaaccent'] = 0x0219;
  9390. t['sdotaccent'] = 0x1E61;
  9391. t['sdotbelow'] = 0x1E63;
  9392. t['sdotbelowdotaccent'] = 0x1E69;
  9393. t['seagullbelowcmb'] = 0x033C;
  9394. t['second'] = 0x2033;
  9395. t['secondtonechinese'] = 0x02CA;
  9396. t['section'] = 0x00A7;
  9397. t['seenarabic'] = 0x0633;
  9398. t['seenfinalarabic'] = 0xFEB2;
  9399. t['seeninitialarabic'] = 0xFEB3;
  9400. t['seenmedialarabic'] = 0xFEB4;
  9401. t['segol'] = 0x05B6;
  9402. t['segol13'] = 0x05B6;
  9403. t['segol1f'] = 0x05B6;
  9404. t['segol2c'] = 0x05B6;
  9405. t['segolhebrew'] = 0x05B6;
  9406. t['segolnarrowhebrew'] = 0x05B6;
  9407. t['segolquarterhebrew'] = 0x05B6;
  9408. t['segoltahebrew'] = 0x0592;
  9409. t['segolwidehebrew'] = 0x05B6;
  9410. t['seharmenian'] = 0x057D;
  9411. t['sehiragana'] = 0x305B;
  9412. t['sekatakana'] = 0x30BB;
  9413. t['sekatakanahalfwidth'] = 0xFF7E;
  9414. t['semicolon'] = 0x003B;
  9415. t['semicolonarabic'] = 0x061B;
  9416. t['semicolonmonospace'] = 0xFF1B;
  9417. t['semicolonsmall'] = 0xFE54;
  9418. t['semivoicedmarkkana'] = 0x309C;
  9419. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  9420. t['sentisquare'] = 0x3322;
  9421. t['sentosquare'] = 0x3323;
  9422. t['seven'] = 0x0037;
  9423. t['sevenarabic'] = 0x0667;
  9424. t['sevenbengali'] = 0x09ED;
  9425. t['sevencircle'] = 0x2466;
  9426. t['sevencircleinversesansserif'] = 0x2790;
  9427. t['sevendeva'] = 0x096D;
  9428. t['seveneighths'] = 0x215E;
  9429. t['sevengujarati'] = 0x0AED;
  9430. t['sevengurmukhi'] = 0x0A6D;
  9431. t['sevenhackarabic'] = 0x0667;
  9432. t['sevenhangzhou'] = 0x3027;
  9433. t['sevenideographicparen'] = 0x3226;
  9434. t['seveninferior'] = 0x2087;
  9435. t['sevenmonospace'] = 0xFF17;
  9436. t['sevenoldstyle'] = 0xF737;
  9437. t['sevenparen'] = 0x247A;
  9438. t['sevenperiod'] = 0x248E;
  9439. t['sevenpersian'] = 0x06F7;
  9440. t['sevenroman'] = 0x2176;
  9441. t['sevensuperior'] = 0x2077;
  9442. t['seventeencircle'] = 0x2470;
  9443. t['seventeenparen'] = 0x2484;
  9444. t['seventeenperiod'] = 0x2498;
  9445. t['seventhai'] = 0x0E57;
  9446. t['sfthyphen'] = 0x00AD;
  9447. t['shaarmenian'] = 0x0577;
  9448. t['shabengali'] = 0x09B6;
  9449. t['shacyrillic'] = 0x0448;
  9450. t['shaddaarabic'] = 0x0651;
  9451. t['shaddadammaarabic'] = 0xFC61;
  9452. t['shaddadammatanarabic'] = 0xFC5E;
  9453. t['shaddafathaarabic'] = 0xFC60;
  9454. t['shaddakasraarabic'] = 0xFC62;
  9455. t['shaddakasratanarabic'] = 0xFC5F;
  9456. t['shade'] = 0x2592;
  9457. t['shadedark'] = 0x2593;
  9458. t['shadelight'] = 0x2591;
  9459. t['shademedium'] = 0x2592;
  9460. t['shadeva'] = 0x0936;
  9461. t['shagujarati'] = 0x0AB6;
  9462. t['shagurmukhi'] = 0x0A36;
  9463. t['shalshelethebrew'] = 0x0593;
  9464. t['shbopomofo'] = 0x3115;
  9465. t['shchacyrillic'] = 0x0449;
  9466. t['sheenarabic'] = 0x0634;
  9467. t['sheenfinalarabic'] = 0xFEB6;
  9468. t['sheeninitialarabic'] = 0xFEB7;
  9469. t['sheenmedialarabic'] = 0xFEB8;
  9470. t['sheicoptic'] = 0x03E3;
  9471. t['sheqel'] = 0x20AA;
  9472. t['sheqelhebrew'] = 0x20AA;
  9473. t['sheva'] = 0x05B0;
  9474. t['sheva115'] = 0x05B0;
  9475. t['sheva15'] = 0x05B0;
  9476. t['sheva22'] = 0x05B0;
  9477. t['sheva2e'] = 0x05B0;
  9478. t['shevahebrew'] = 0x05B0;
  9479. t['shevanarrowhebrew'] = 0x05B0;
  9480. t['shevaquarterhebrew'] = 0x05B0;
  9481. t['shevawidehebrew'] = 0x05B0;
  9482. t['shhacyrillic'] = 0x04BB;
  9483. t['shimacoptic'] = 0x03ED;
  9484. t['shin'] = 0x05E9;
  9485. t['shindagesh'] = 0xFB49;
  9486. t['shindageshhebrew'] = 0xFB49;
  9487. t['shindageshshindot'] = 0xFB2C;
  9488. t['shindageshshindothebrew'] = 0xFB2C;
  9489. t['shindageshsindot'] = 0xFB2D;
  9490. t['shindageshsindothebrew'] = 0xFB2D;
  9491. t['shindothebrew'] = 0x05C1;
  9492. t['shinhebrew'] = 0x05E9;
  9493. t['shinshindot'] = 0xFB2A;
  9494. t['shinshindothebrew'] = 0xFB2A;
  9495. t['shinsindot'] = 0xFB2B;
  9496. t['shinsindothebrew'] = 0xFB2B;
  9497. t['shook'] = 0x0282;
  9498. t['sigma'] = 0x03C3;
  9499. t['sigma1'] = 0x03C2;
  9500. t['sigmafinal'] = 0x03C2;
  9501. t['sigmalunatesymbolgreek'] = 0x03F2;
  9502. t['sihiragana'] = 0x3057;
  9503. t['sikatakana'] = 0x30B7;
  9504. t['sikatakanahalfwidth'] = 0xFF7C;
  9505. t['siluqhebrew'] = 0x05BD;
  9506. t['siluqlefthebrew'] = 0x05BD;
  9507. t['similar'] = 0x223C;
  9508. t['sindothebrew'] = 0x05C2;
  9509. t['siosacirclekorean'] = 0x3274;
  9510. t['siosaparenkorean'] = 0x3214;
  9511. t['sioscieuckorean'] = 0x317E;
  9512. t['sioscirclekorean'] = 0x3266;
  9513. t['sioskiyeokkorean'] = 0x317A;
  9514. t['sioskorean'] = 0x3145;
  9515. t['siosnieunkorean'] = 0x317B;
  9516. t['siosparenkorean'] = 0x3206;
  9517. t['siospieupkorean'] = 0x317D;
  9518. t['siostikeutkorean'] = 0x317C;
  9519. t['six'] = 0x0036;
  9520. t['sixarabic'] = 0x0666;
  9521. t['sixbengali'] = 0x09EC;
  9522. t['sixcircle'] = 0x2465;
  9523. t['sixcircleinversesansserif'] = 0x278F;
  9524. t['sixdeva'] = 0x096C;
  9525. t['sixgujarati'] = 0x0AEC;
  9526. t['sixgurmukhi'] = 0x0A6C;
  9527. t['sixhackarabic'] = 0x0666;
  9528. t['sixhangzhou'] = 0x3026;
  9529. t['sixideographicparen'] = 0x3225;
  9530. t['sixinferior'] = 0x2086;
  9531. t['sixmonospace'] = 0xFF16;
  9532. t['sixoldstyle'] = 0xF736;
  9533. t['sixparen'] = 0x2479;
  9534. t['sixperiod'] = 0x248D;
  9535. t['sixpersian'] = 0x06F6;
  9536. t['sixroman'] = 0x2175;
  9537. t['sixsuperior'] = 0x2076;
  9538. t['sixteencircle'] = 0x246F;
  9539. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  9540. t['sixteenparen'] = 0x2483;
  9541. t['sixteenperiod'] = 0x2497;
  9542. t['sixthai'] = 0x0E56;
  9543. t['slash'] = 0x002F;
  9544. t['slashmonospace'] = 0xFF0F;
  9545. t['slong'] = 0x017F;
  9546. t['slongdotaccent'] = 0x1E9B;
  9547. t['smileface'] = 0x263A;
  9548. t['smonospace'] = 0xFF53;
  9549. t['sofpasuqhebrew'] = 0x05C3;
  9550. t['softhyphen'] = 0x00AD;
  9551. t['softsigncyrillic'] = 0x044C;
  9552. t['sohiragana'] = 0x305D;
  9553. t['sokatakana'] = 0x30BD;
  9554. t['sokatakanahalfwidth'] = 0xFF7F;
  9555. t['soliduslongoverlaycmb'] = 0x0338;
  9556. t['solidusshortoverlaycmb'] = 0x0337;
  9557. t['sorusithai'] = 0x0E29;
  9558. t['sosalathai'] = 0x0E28;
  9559. t['sosothai'] = 0x0E0B;
  9560. t['sosuathai'] = 0x0E2A;
  9561. t['space'] = 0x0020;
  9562. t['spacehackarabic'] = 0x0020;
  9563. t['spade'] = 0x2660;
  9564. t['spadesuitblack'] = 0x2660;
  9565. t['spadesuitwhite'] = 0x2664;
  9566. t['sparen'] = 0x24AE;
  9567. t['squarebelowcmb'] = 0x033B;
  9568. t['squarecc'] = 0x33C4;
  9569. t['squarecm'] = 0x339D;
  9570. t['squarediagonalcrosshatchfill'] = 0x25A9;
  9571. t['squarehorizontalfill'] = 0x25A4;
  9572. t['squarekg'] = 0x338F;
  9573. t['squarekm'] = 0x339E;
  9574. t['squarekmcapital'] = 0x33CE;
  9575. t['squareln'] = 0x33D1;
  9576. t['squarelog'] = 0x33D2;
  9577. t['squaremg'] = 0x338E;
  9578. t['squaremil'] = 0x33D5;
  9579. t['squaremm'] = 0x339C;
  9580. t['squaremsquared'] = 0x33A1;
  9581. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  9582. t['squareupperlefttolowerrightfill'] = 0x25A7;
  9583. t['squareupperrighttolowerleftfill'] = 0x25A8;
  9584. t['squareverticalfill'] = 0x25A5;
  9585. t['squarewhitewithsmallblack'] = 0x25A3;
  9586. t['srsquare'] = 0x33DB;
  9587. t['ssabengali'] = 0x09B7;
  9588. t['ssadeva'] = 0x0937;
  9589. t['ssagujarati'] = 0x0AB7;
  9590. t['ssangcieuckorean'] = 0x3149;
  9591. t['ssanghieuhkorean'] = 0x3185;
  9592. t['ssangieungkorean'] = 0x3180;
  9593. t['ssangkiyeokkorean'] = 0x3132;
  9594. t['ssangnieunkorean'] = 0x3165;
  9595. t['ssangpieupkorean'] = 0x3143;
  9596. t['ssangsioskorean'] = 0x3146;
  9597. t['ssangtikeutkorean'] = 0x3138;
  9598. t['ssuperior'] = 0xF6F2;
  9599. t['sterling'] = 0x00A3;
  9600. t['sterlingmonospace'] = 0xFFE1;
  9601. t['strokelongoverlaycmb'] = 0x0336;
  9602. t['strokeshortoverlaycmb'] = 0x0335;
  9603. t['subset'] = 0x2282;
  9604. t['subsetnotequal'] = 0x228A;
  9605. t['subsetorequal'] = 0x2286;
  9606. t['succeeds'] = 0x227B;
  9607. t['suchthat'] = 0x220B;
  9608. t['suhiragana'] = 0x3059;
  9609. t['sukatakana'] = 0x30B9;
  9610. t['sukatakanahalfwidth'] = 0xFF7D;
  9611. t['sukunarabic'] = 0x0652;
  9612. t['summation'] = 0x2211;
  9613. t['sun'] = 0x263C;
  9614. t['superset'] = 0x2283;
  9615. t['supersetnotequal'] = 0x228B;
  9616. t['supersetorequal'] = 0x2287;
  9617. t['svsquare'] = 0x33DC;
  9618. t['syouwaerasquare'] = 0x337C;
  9619. t['t'] = 0x0074;
  9620. t['tabengali'] = 0x09A4;
  9621. t['tackdown'] = 0x22A4;
  9622. t['tackleft'] = 0x22A3;
  9623. t['tadeva'] = 0x0924;
  9624. t['tagujarati'] = 0x0AA4;
  9625. t['tagurmukhi'] = 0x0A24;
  9626. t['taharabic'] = 0x0637;
  9627. t['tahfinalarabic'] = 0xFEC2;
  9628. t['tahinitialarabic'] = 0xFEC3;
  9629. t['tahiragana'] = 0x305F;
  9630. t['tahmedialarabic'] = 0xFEC4;
  9631. t['taisyouerasquare'] = 0x337D;
  9632. t['takatakana'] = 0x30BF;
  9633. t['takatakanahalfwidth'] = 0xFF80;
  9634. t['tatweelarabic'] = 0x0640;
  9635. t['tau'] = 0x03C4;
  9636. t['tav'] = 0x05EA;
  9637. t['tavdages'] = 0xFB4A;
  9638. t['tavdagesh'] = 0xFB4A;
  9639. t['tavdageshhebrew'] = 0xFB4A;
  9640. t['tavhebrew'] = 0x05EA;
  9641. t['tbar'] = 0x0167;
  9642. t['tbopomofo'] = 0x310A;
  9643. t['tcaron'] = 0x0165;
  9644. t['tccurl'] = 0x02A8;
  9645. t['tcedilla'] = 0x0163;
  9646. t['tcheharabic'] = 0x0686;
  9647. t['tchehfinalarabic'] = 0xFB7B;
  9648. t['tchehinitialarabic'] = 0xFB7C;
  9649. t['tchehmedialarabic'] = 0xFB7D;
  9650. t['tcircle'] = 0x24E3;
  9651. t['tcircumflexbelow'] = 0x1E71;
  9652. t['tcommaaccent'] = 0x0163;
  9653. t['tdieresis'] = 0x1E97;
  9654. t['tdotaccent'] = 0x1E6B;
  9655. t['tdotbelow'] = 0x1E6D;
  9656. t['tecyrillic'] = 0x0442;
  9657. t['tedescendercyrillic'] = 0x04AD;
  9658. t['teharabic'] = 0x062A;
  9659. t['tehfinalarabic'] = 0xFE96;
  9660. t['tehhahinitialarabic'] = 0xFCA2;
  9661. t['tehhahisolatedarabic'] = 0xFC0C;
  9662. t['tehinitialarabic'] = 0xFE97;
  9663. t['tehiragana'] = 0x3066;
  9664. t['tehjeeminitialarabic'] = 0xFCA1;
  9665. t['tehjeemisolatedarabic'] = 0xFC0B;
  9666. t['tehmarbutaarabic'] = 0x0629;
  9667. t['tehmarbutafinalarabic'] = 0xFE94;
  9668. t['tehmedialarabic'] = 0xFE98;
  9669. t['tehmeeminitialarabic'] = 0xFCA4;
  9670. t['tehmeemisolatedarabic'] = 0xFC0E;
  9671. t['tehnoonfinalarabic'] = 0xFC73;
  9672. t['tekatakana'] = 0x30C6;
  9673. t['tekatakanahalfwidth'] = 0xFF83;
  9674. t['telephone'] = 0x2121;
  9675. t['telephoneblack'] = 0x260E;
  9676. t['telishagedolahebrew'] = 0x05A0;
  9677. t['telishaqetanahebrew'] = 0x05A9;
  9678. t['tencircle'] = 0x2469;
  9679. t['tenideographicparen'] = 0x3229;
  9680. t['tenparen'] = 0x247D;
  9681. t['tenperiod'] = 0x2491;
  9682. t['tenroman'] = 0x2179;
  9683. t['tesh'] = 0x02A7;
  9684. t['tet'] = 0x05D8;
  9685. t['tetdagesh'] = 0xFB38;
  9686. t['tetdageshhebrew'] = 0xFB38;
  9687. t['tethebrew'] = 0x05D8;
  9688. t['tetsecyrillic'] = 0x04B5;
  9689. t['tevirhebrew'] = 0x059B;
  9690. t['tevirlefthebrew'] = 0x059B;
  9691. t['thabengali'] = 0x09A5;
  9692. t['thadeva'] = 0x0925;
  9693. t['thagujarati'] = 0x0AA5;
  9694. t['thagurmukhi'] = 0x0A25;
  9695. t['thalarabic'] = 0x0630;
  9696. t['thalfinalarabic'] = 0xFEAC;
  9697. t['thanthakhatlowleftthai'] = 0xF898;
  9698. t['thanthakhatlowrightthai'] = 0xF897;
  9699. t['thanthakhatthai'] = 0x0E4C;
  9700. t['thanthakhatupperleftthai'] = 0xF896;
  9701. t['theharabic'] = 0x062B;
  9702. t['thehfinalarabic'] = 0xFE9A;
  9703. t['thehinitialarabic'] = 0xFE9B;
  9704. t['thehmedialarabic'] = 0xFE9C;
  9705. t['thereexists'] = 0x2203;
  9706. t['therefore'] = 0x2234;
  9707. t['theta'] = 0x03B8;
  9708. t['theta1'] = 0x03D1;
  9709. t['thetasymbolgreek'] = 0x03D1;
  9710. t['thieuthacirclekorean'] = 0x3279;
  9711. t['thieuthaparenkorean'] = 0x3219;
  9712. t['thieuthcirclekorean'] = 0x326B;
  9713. t['thieuthkorean'] = 0x314C;
  9714. t['thieuthparenkorean'] = 0x320B;
  9715. t['thirteencircle'] = 0x246C;
  9716. t['thirteenparen'] = 0x2480;
  9717. t['thirteenperiod'] = 0x2494;
  9718. t['thonangmonthothai'] = 0x0E11;
  9719. t['thook'] = 0x01AD;
  9720. t['thophuthaothai'] = 0x0E12;
  9721. t['thorn'] = 0x00FE;
  9722. t['thothahanthai'] = 0x0E17;
  9723. t['thothanthai'] = 0x0E10;
  9724. t['thothongthai'] = 0x0E18;
  9725. t['thothungthai'] = 0x0E16;
  9726. t['thousandcyrillic'] = 0x0482;
  9727. t['thousandsseparatorarabic'] = 0x066C;
  9728. t['thousandsseparatorpersian'] = 0x066C;
  9729. t['three'] = 0x0033;
  9730. t['threearabic'] = 0x0663;
  9731. t['threebengali'] = 0x09E9;
  9732. t['threecircle'] = 0x2462;
  9733. t['threecircleinversesansserif'] = 0x278C;
  9734. t['threedeva'] = 0x0969;
  9735. t['threeeighths'] = 0x215C;
  9736. t['threegujarati'] = 0x0AE9;
  9737. t['threegurmukhi'] = 0x0A69;
  9738. t['threehackarabic'] = 0x0663;
  9739. t['threehangzhou'] = 0x3023;
  9740. t['threeideographicparen'] = 0x3222;
  9741. t['threeinferior'] = 0x2083;
  9742. t['threemonospace'] = 0xFF13;
  9743. t['threenumeratorbengali'] = 0x09F6;
  9744. t['threeoldstyle'] = 0xF733;
  9745. t['threeparen'] = 0x2476;
  9746. t['threeperiod'] = 0x248A;
  9747. t['threepersian'] = 0x06F3;
  9748. t['threequarters'] = 0x00BE;
  9749. t['threequartersemdash'] = 0xF6DE;
  9750. t['threeroman'] = 0x2172;
  9751. t['threesuperior'] = 0x00B3;
  9752. t['threethai'] = 0x0E53;
  9753. t['thzsquare'] = 0x3394;
  9754. t['tihiragana'] = 0x3061;
  9755. t['tikatakana'] = 0x30C1;
  9756. t['tikatakanahalfwidth'] = 0xFF81;
  9757. t['tikeutacirclekorean'] = 0x3270;
  9758. t['tikeutaparenkorean'] = 0x3210;
  9759. t['tikeutcirclekorean'] = 0x3262;
  9760. t['tikeutkorean'] = 0x3137;
  9761. t['tikeutparenkorean'] = 0x3202;
  9762. t['tilde'] = 0x02DC;
  9763. t['tildebelowcmb'] = 0x0330;
  9764. t['tildecmb'] = 0x0303;
  9765. t['tildecomb'] = 0x0303;
  9766. t['tildedoublecmb'] = 0x0360;
  9767. t['tildeoperator'] = 0x223C;
  9768. t['tildeoverlaycmb'] = 0x0334;
  9769. t['tildeverticalcmb'] = 0x033E;
  9770. t['timescircle'] = 0x2297;
  9771. t['tipehahebrew'] = 0x0596;
  9772. t['tipehalefthebrew'] = 0x0596;
  9773. t['tippigurmukhi'] = 0x0A70;
  9774. t['titlocyrilliccmb'] = 0x0483;
  9775. t['tiwnarmenian'] = 0x057F;
  9776. t['tlinebelow'] = 0x1E6F;
  9777. t['tmonospace'] = 0xFF54;
  9778. t['toarmenian'] = 0x0569;
  9779. t['tohiragana'] = 0x3068;
  9780. t['tokatakana'] = 0x30C8;
  9781. t['tokatakanahalfwidth'] = 0xFF84;
  9782. t['tonebarextrahighmod'] = 0x02E5;
  9783. t['tonebarextralowmod'] = 0x02E9;
  9784. t['tonebarhighmod'] = 0x02E6;
  9785. t['tonebarlowmod'] = 0x02E8;
  9786. t['tonebarmidmod'] = 0x02E7;
  9787. t['tonefive'] = 0x01BD;
  9788. t['tonesix'] = 0x0185;
  9789. t['tonetwo'] = 0x01A8;
  9790. t['tonos'] = 0x0384;
  9791. t['tonsquare'] = 0x3327;
  9792. t['topatakthai'] = 0x0E0F;
  9793. t['tortoiseshellbracketleft'] = 0x3014;
  9794. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  9795. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  9796. t['tortoiseshellbracketright'] = 0x3015;
  9797. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  9798. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  9799. t['totaothai'] = 0x0E15;
  9800. t['tpalatalhook'] = 0x01AB;
  9801. t['tparen'] = 0x24AF;
  9802. t['trademark'] = 0x2122;
  9803. t['trademarksans'] = 0xF8EA;
  9804. t['trademarkserif'] = 0xF6DB;
  9805. t['tretroflexhook'] = 0x0288;
  9806. t['triagdn'] = 0x25BC;
  9807. t['triaglf'] = 0x25C4;
  9808. t['triagrt'] = 0x25BA;
  9809. t['triagup'] = 0x25B2;
  9810. t['ts'] = 0x02A6;
  9811. t['tsadi'] = 0x05E6;
  9812. t['tsadidagesh'] = 0xFB46;
  9813. t['tsadidageshhebrew'] = 0xFB46;
  9814. t['tsadihebrew'] = 0x05E6;
  9815. t['tsecyrillic'] = 0x0446;
  9816. t['tsere'] = 0x05B5;
  9817. t['tsere12'] = 0x05B5;
  9818. t['tsere1e'] = 0x05B5;
  9819. t['tsere2b'] = 0x05B5;
  9820. t['tserehebrew'] = 0x05B5;
  9821. t['tserenarrowhebrew'] = 0x05B5;
  9822. t['tserequarterhebrew'] = 0x05B5;
  9823. t['tserewidehebrew'] = 0x05B5;
  9824. t['tshecyrillic'] = 0x045B;
  9825. t['tsuperior'] = 0xF6F3;
  9826. t['ttabengali'] = 0x099F;
  9827. t['ttadeva'] = 0x091F;
  9828. t['ttagujarati'] = 0x0A9F;
  9829. t['ttagurmukhi'] = 0x0A1F;
  9830. t['tteharabic'] = 0x0679;
  9831. t['ttehfinalarabic'] = 0xFB67;
  9832. t['ttehinitialarabic'] = 0xFB68;
  9833. t['ttehmedialarabic'] = 0xFB69;
  9834. t['tthabengali'] = 0x09A0;
  9835. t['tthadeva'] = 0x0920;
  9836. t['tthagujarati'] = 0x0AA0;
  9837. t['tthagurmukhi'] = 0x0A20;
  9838. t['tturned'] = 0x0287;
  9839. t['tuhiragana'] = 0x3064;
  9840. t['tukatakana'] = 0x30C4;
  9841. t['tukatakanahalfwidth'] = 0xFF82;
  9842. t['tusmallhiragana'] = 0x3063;
  9843. t['tusmallkatakana'] = 0x30C3;
  9844. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  9845. t['twelvecircle'] = 0x246B;
  9846. t['twelveparen'] = 0x247F;
  9847. t['twelveperiod'] = 0x2493;
  9848. t['twelveroman'] = 0x217B;
  9849. t['twentycircle'] = 0x2473;
  9850. t['twentyhangzhou'] = 0x5344;
  9851. t['twentyparen'] = 0x2487;
  9852. t['twentyperiod'] = 0x249B;
  9853. t['two'] = 0x0032;
  9854. t['twoarabic'] = 0x0662;
  9855. t['twobengali'] = 0x09E8;
  9856. t['twocircle'] = 0x2461;
  9857. t['twocircleinversesansserif'] = 0x278B;
  9858. t['twodeva'] = 0x0968;
  9859. t['twodotenleader'] = 0x2025;
  9860. t['twodotleader'] = 0x2025;
  9861. t['twodotleadervertical'] = 0xFE30;
  9862. t['twogujarati'] = 0x0AE8;
  9863. t['twogurmukhi'] = 0x0A68;
  9864. t['twohackarabic'] = 0x0662;
  9865. t['twohangzhou'] = 0x3022;
  9866. t['twoideographicparen'] = 0x3221;
  9867. t['twoinferior'] = 0x2082;
  9868. t['twomonospace'] = 0xFF12;
  9869. t['twonumeratorbengali'] = 0x09F5;
  9870. t['twooldstyle'] = 0xF732;
  9871. t['twoparen'] = 0x2475;
  9872. t['twoperiod'] = 0x2489;
  9873. t['twopersian'] = 0x06F2;
  9874. t['tworoman'] = 0x2171;
  9875. t['twostroke'] = 0x01BB;
  9876. t['twosuperior'] = 0x00B2;
  9877. t['twothai'] = 0x0E52;
  9878. t['twothirds'] = 0x2154;
  9879. t['u'] = 0x0075;
  9880. t['uacute'] = 0x00FA;
  9881. t['ubar'] = 0x0289;
  9882. t['ubengali'] = 0x0989;
  9883. t['ubopomofo'] = 0x3128;
  9884. t['ubreve'] = 0x016D;
  9885. t['ucaron'] = 0x01D4;
  9886. t['ucircle'] = 0x24E4;
  9887. t['ucircumflex'] = 0x00FB;
  9888. t['ucircumflexbelow'] = 0x1E77;
  9889. t['ucyrillic'] = 0x0443;
  9890. t['udattadeva'] = 0x0951;
  9891. t['udblacute'] = 0x0171;
  9892. t['udblgrave'] = 0x0215;
  9893. t['udeva'] = 0x0909;
  9894. t['udieresis'] = 0x00FC;
  9895. t['udieresisacute'] = 0x01D8;
  9896. t['udieresisbelow'] = 0x1E73;
  9897. t['udieresiscaron'] = 0x01DA;
  9898. t['udieresiscyrillic'] = 0x04F1;
  9899. t['udieresisgrave'] = 0x01DC;
  9900. t['udieresismacron'] = 0x01D6;
  9901. t['udotbelow'] = 0x1EE5;
  9902. t['ugrave'] = 0x00F9;
  9903. t['ugujarati'] = 0x0A89;
  9904. t['ugurmukhi'] = 0x0A09;
  9905. t['uhiragana'] = 0x3046;
  9906. t['uhookabove'] = 0x1EE7;
  9907. t['uhorn'] = 0x01B0;
  9908. t['uhornacute'] = 0x1EE9;
  9909. t['uhorndotbelow'] = 0x1EF1;
  9910. t['uhorngrave'] = 0x1EEB;
  9911. t['uhornhookabove'] = 0x1EED;
  9912. t['uhorntilde'] = 0x1EEF;
  9913. t['uhungarumlaut'] = 0x0171;
  9914. t['uhungarumlautcyrillic'] = 0x04F3;
  9915. t['uinvertedbreve'] = 0x0217;
  9916. t['ukatakana'] = 0x30A6;
  9917. t['ukatakanahalfwidth'] = 0xFF73;
  9918. t['ukcyrillic'] = 0x0479;
  9919. t['ukorean'] = 0x315C;
  9920. t['umacron'] = 0x016B;
  9921. t['umacroncyrillic'] = 0x04EF;
  9922. t['umacrondieresis'] = 0x1E7B;
  9923. t['umatragurmukhi'] = 0x0A41;
  9924. t['umonospace'] = 0xFF55;
  9925. t['underscore'] = 0x005F;
  9926. t['underscoredbl'] = 0x2017;
  9927. t['underscoremonospace'] = 0xFF3F;
  9928. t['underscorevertical'] = 0xFE33;
  9929. t['underscorewavy'] = 0xFE4F;
  9930. t['union'] = 0x222A;
  9931. t['universal'] = 0x2200;
  9932. t['uogonek'] = 0x0173;
  9933. t['uparen'] = 0x24B0;
  9934. t['upblock'] = 0x2580;
  9935. t['upperdothebrew'] = 0x05C4;
  9936. t['upsilon'] = 0x03C5;
  9937. t['upsilondieresis'] = 0x03CB;
  9938. t['upsilondieresistonos'] = 0x03B0;
  9939. t['upsilonlatin'] = 0x028A;
  9940. t['upsilontonos'] = 0x03CD;
  9941. t['uptackbelowcmb'] = 0x031D;
  9942. t['uptackmod'] = 0x02D4;
  9943. t['uragurmukhi'] = 0x0A73;
  9944. t['uring'] = 0x016F;
  9945. t['ushortcyrillic'] = 0x045E;
  9946. t['usmallhiragana'] = 0x3045;
  9947. t['usmallkatakana'] = 0x30A5;
  9948. t['usmallkatakanahalfwidth'] = 0xFF69;
  9949. t['ustraightcyrillic'] = 0x04AF;
  9950. t['ustraightstrokecyrillic'] = 0x04B1;
  9951. t['utilde'] = 0x0169;
  9952. t['utildeacute'] = 0x1E79;
  9953. t['utildebelow'] = 0x1E75;
  9954. t['uubengali'] = 0x098A;
  9955. t['uudeva'] = 0x090A;
  9956. t['uugujarati'] = 0x0A8A;
  9957. t['uugurmukhi'] = 0x0A0A;
  9958. t['uumatragurmukhi'] = 0x0A42;
  9959. t['uuvowelsignbengali'] = 0x09C2;
  9960. t['uuvowelsigndeva'] = 0x0942;
  9961. t['uuvowelsigngujarati'] = 0x0AC2;
  9962. t['uvowelsignbengali'] = 0x09C1;
  9963. t['uvowelsigndeva'] = 0x0941;
  9964. t['uvowelsigngujarati'] = 0x0AC1;
  9965. t['v'] = 0x0076;
  9966. t['vadeva'] = 0x0935;
  9967. t['vagujarati'] = 0x0AB5;
  9968. t['vagurmukhi'] = 0x0A35;
  9969. t['vakatakana'] = 0x30F7;
  9970. t['vav'] = 0x05D5;
  9971. t['vavdagesh'] = 0xFB35;
  9972. t['vavdagesh65'] = 0xFB35;
  9973. t['vavdageshhebrew'] = 0xFB35;
  9974. t['vavhebrew'] = 0x05D5;
  9975. t['vavholam'] = 0xFB4B;
  9976. t['vavholamhebrew'] = 0xFB4B;
  9977. t['vavvavhebrew'] = 0x05F0;
  9978. t['vavyodhebrew'] = 0x05F1;
  9979. t['vcircle'] = 0x24E5;
  9980. t['vdotbelow'] = 0x1E7F;
  9981. t['vecyrillic'] = 0x0432;
  9982. t['veharabic'] = 0x06A4;
  9983. t['vehfinalarabic'] = 0xFB6B;
  9984. t['vehinitialarabic'] = 0xFB6C;
  9985. t['vehmedialarabic'] = 0xFB6D;
  9986. t['vekatakana'] = 0x30F9;
  9987. t['venus'] = 0x2640;
  9988. t['verticalbar'] = 0x007C;
  9989. t['verticallineabovecmb'] = 0x030D;
  9990. t['verticallinebelowcmb'] = 0x0329;
  9991. t['verticallinelowmod'] = 0x02CC;
  9992. t['verticallinemod'] = 0x02C8;
  9993. t['vewarmenian'] = 0x057E;
  9994. t['vhook'] = 0x028B;
  9995. t['vikatakana'] = 0x30F8;
  9996. t['viramabengali'] = 0x09CD;
  9997. t['viramadeva'] = 0x094D;
  9998. t['viramagujarati'] = 0x0ACD;
  9999. t['visargabengali'] = 0x0983;
  10000. t['visargadeva'] = 0x0903;
  10001. t['visargagujarati'] = 0x0A83;
  10002. t['vmonospace'] = 0xFF56;
  10003. t['voarmenian'] = 0x0578;
  10004. t['voicediterationhiragana'] = 0x309E;
  10005. t['voicediterationkatakana'] = 0x30FE;
  10006. t['voicedmarkkana'] = 0x309B;
  10007. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  10008. t['vokatakana'] = 0x30FA;
  10009. t['vparen'] = 0x24B1;
  10010. t['vtilde'] = 0x1E7D;
  10011. t['vturned'] = 0x028C;
  10012. t['vuhiragana'] = 0x3094;
  10013. t['vukatakana'] = 0x30F4;
  10014. t['w'] = 0x0077;
  10015. t['wacute'] = 0x1E83;
  10016. t['waekorean'] = 0x3159;
  10017. t['wahiragana'] = 0x308F;
  10018. t['wakatakana'] = 0x30EF;
  10019. t['wakatakanahalfwidth'] = 0xFF9C;
  10020. t['wakorean'] = 0x3158;
  10021. t['wasmallhiragana'] = 0x308E;
  10022. t['wasmallkatakana'] = 0x30EE;
  10023. t['wattosquare'] = 0x3357;
  10024. t['wavedash'] = 0x301C;
  10025. t['wavyunderscorevertical'] = 0xFE34;
  10026. t['wawarabic'] = 0x0648;
  10027. t['wawfinalarabic'] = 0xFEEE;
  10028. t['wawhamzaabovearabic'] = 0x0624;
  10029. t['wawhamzaabovefinalarabic'] = 0xFE86;
  10030. t['wbsquare'] = 0x33DD;
  10031. t['wcircle'] = 0x24E6;
  10032. t['wcircumflex'] = 0x0175;
  10033. t['wdieresis'] = 0x1E85;
  10034. t['wdotaccent'] = 0x1E87;
  10035. t['wdotbelow'] = 0x1E89;
  10036. t['wehiragana'] = 0x3091;
  10037. t['weierstrass'] = 0x2118;
  10038. t['wekatakana'] = 0x30F1;
  10039. t['wekorean'] = 0x315E;
  10040. t['weokorean'] = 0x315D;
  10041. t['wgrave'] = 0x1E81;
  10042. t['whitebullet'] = 0x25E6;
  10043. t['whitecircle'] = 0x25CB;
  10044. t['whitecircleinverse'] = 0x25D9;
  10045. t['whitecornerbracketleft'] = 0x300E;
  10046. t['whitecornerbracketleftvertical'] = 0xFE43;
  10047. t['whitecornerbracketright'] = 0x300F;
  10048. t['whitecornerbracketrightvertical'] = 0xFE44;
  10049. t['whitediamond'] = 0x25C7;
  10050. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  10051. t['whitedownpointingsmalltriangle'] = 0x25BF;
  10052. t['whitedownpointingtriangle'] = 0x25BD;
  10053. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  10054. t['whiteleftpointingtriangle'] = 0x25C1;
  10055. t['whitelenticularbracketleft'] = 0x3016;
  10056. t['whitelenticularbracketright'] = 0x3017;
  10057. t['whiterightpointingsmalltriangle'] = 0x25B9;
  10058. t['whiterightpointingtriangle'] = 0x25B7;
  10059. t['whitesmallsquare'] = 0x25AB;
  10060. t['whitesmilingface'] = 0x263A;
  10061. t['whitesquare'] = 0x25A1;
  10062. t['whitestar'] = 0x2606;
  10063. t['whitetelephone'] = 0x260F;
  10064. t['whitetortoiseshellbracketleft'] = 0x3018;
  10065. t['whitetortoiseshellbracketright'] = 0x3019;
  10066. t['whiteuppointingsmalltriangle'] = 0x25B5;
  10067. t['whiteuppointingtriangle'] = 0x25B3;
  10068. t['wihiragana'] = 0x3090;
  10069. t['wikatakana'] = 0x30F0;
  10070. t['wikorean'] = 0x315F;
  10071. t['wmonospace'] = 0xFF57;
  10072. t['wohiragana'] = 0x3092;
  10073. t['wokatakana'] = 0x30F2;
  10074. t['wokatakanahalfwidth'] = 0xFF66;
  10075. t['won'] = 0x20A9;
  10076. t['wonmonospace'] = 0xFFE6;
  10077. t['wowaenthai'] = 0x0E27;
  10078. t['wparen'] = 0x24B2;
  10079. t['wring'] = 0x1E98;
  10080. t['wsuperior'] = 0x02B7;
  10081. t['wturned'] = 0x028D;
  10082. t['wynn'] = 0x01BF;
  10083. t['x'] = 0x0078;
  10084. t['xabovecmb'] = 0x033D;
  10085. t['xbopomofo'] = 0x3112;
  10086. t['xcircle'] = 0x24E7;
  10087. t['xdieresis'] = 0x1E8D;
  10088. t['xdotaccent'] = 0x1E8B;
  10089. t['xeharmenian'] = 0x056D;
  10090. t['xi'] = 0x03BE;
  10091. t['xmonospace'] = 0xFF58;
  10092. t['xparen'] = 0x24B3;
  10093. t['xsuperior'] = 0x02E3;
  10094. t['y'] = 0x0079;
  10095. t['yaadosquare'] = 0x334E;
  10096. t['yabengali'] = 0x09AF;
  10097. t['yacute'] = 0x00FD;
  10098. t['yadeva'] = 0x092F;
  10099. t['yaekorean'] = 0x3152;
  10100. t['yagujarati'] = 0x0AAF;
  10101. t['yagurmukhi'] = 0x0A2F;
  10102. t['yahiragana'] = 0x3084;
  10103. t['yakatakana'] = 0x30E4;
  10104. t['yakatakanahalfwidth'] = 0xFF94;
  10105. t['yakorean'] = 0x3151;
  10106. t['yamakkanthai'] = 0x0E4E;
  10107. t['yasmallhiragana'] = 0x3083;
  10108. t['yasmallkatakana'] = 0x30E3;
  10109. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  10110. t['yatcyrillic'] = 0x0463;
  10111. t['ycircle'] = 0x24E8;
  10112. t['ycircumflex'] = 0x0177;
  10113. t['ydieresis'] = 0x00FF;
  10114. t['ydotaccent'] = 0x1E8F;
  10115. t['ydotbelow'] = 0x1EF5;
  10116. t['yeharabic'] = 0x064A;
  10117. t['yehbarreearabic'] = 0x06D2;
  10118. t['yehbarreefinalarabic'] = 0xFBAF;
  10119. t['yehfinalarabic'] = 0xFEF2;
  10120. t['yehhamzaabovearabic'] = 0x0626;
  10121. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  10122. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  10123. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  10124. t['yehinitialarabic'] = 0xFEF3;
  10125. t['yehmedialarabic'] = 0xFEF4;
  10126. t['yehmeeminitialarabic'] = 0xFCDD;
  10127. t['yehmeemisolatedarabic'] = 0xFC58;
  10128. t['yehnoonfinalarabic'] = 0xFC94;
  10129. t['yehthreedotsbelowarabic'] = 0x06D1;
  10130. t['yekorean'] = 0x3156;
  10131. t['yen'] = 0x00A5;
  10132. t['yenmonospace'] = 0xFFE5;
  10133. t['yeokorean'] = 0x3155;
  10134. t['yeorinhieuhkorean'] = 0x3186;
  10135. t['yerahbenyomohebrew'] = 0x05AA;
  10136. t['yerahbenyomolefthebrew'] = 0x05AA;
  10137. t['yericyrillic'] = 0x044B;
  10138. t['yerudieresiscyrillic'] = 0x04F9;
  10139. t['yesieungkorean'] = 0x3181;
  10140. t['yesieungpansioskorean'] = 0x3183;
  10141. t['yesieungsioskorean'] = 0x3182;
  10142. t['yetivhebrew'] = 0x059A;
  10143. t['ygrave'] = 0x1EF3;
  10144. t['yhook'] = 0x01B4;
  10145. t['yhookabove'] = 0x1EF7;
  10146. t['yiarmenian'] = 0x0575;
  10147. t['yicyrillic'] = 0x0457;
  10148. t['yikorean'] = 0x3162;
  10149. t['yinyang'] = 0x262F;
  10150. t['yiwnarmenian'] = 0x0582;
  10151. t['ymonospace'] = 0xFF59;
  10152. t['yod'] = 0x05D9;
  10153. t['yoddagesh'] = 0xFB39;
  10154. t['yoddageshhebrew'] = 0xFB39;
  10155. t['yodhebrew'] = 0x05D9;
  10156. t['yodyodhebrew'] = 0x05F2;
  10157. t['yodyodpatahhebrew'] = 0xFB1F;
  10158. t['yohiragana'] = 0x3088;
  10159. t['yoikorean'] = 0x3189;
  10160. t['yokatakana'] = 0x30E8;
  10161. t['yokatakanahalfwidth'] = 0xFF96;
  10162. t['yokorean'] = 0x315B;
  10163. t['yosmallhiragana'] = 0x3087;
  10164. t['yosmallkatakana'] = 0x30E7;
  10165. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  10166. t['yotgreek'] = 0x03F3;
  10167. t['yoyaekorean'] = 0x3188;
  10168. t['yoyakorean'] = 0x3187;
  10169. t['yoyakthai'] = 0x0E22;
  10170. t['yoyingthai'] = 0x0E0D;
  10171. t['yparen'] = 0x24B4;
  10172. t['ypogegrammeni'] = 0x037A;
  10173. t['ypogegrammenigreekcmb'] = 0x0345;
  10174. t['yr'] = 0x01A6;
  10175. t['yring'] = 0x1E99;
  10176. t['ysuperior'] = 0x02B8;
  10177. t['ytilde'] = 0x1EF9;
  10178. t['yturned'] = 0x028E;
  10179. t['yuhiragana'] = 0x3086;
  10180. t['yuikorean'] = 0x318C;
  10181. t['yukatakana'] = 0x30E6;
  10182. t['yukatakanahalfwidth'] = 0xFF95;
  10183. t['yukorean'] = 0x3160;
  10184. t['yusbigcyrillic'] = 0x046B;
  10185. t['yusbigiotifiedcyrillic'] = 0x046D;
  10186. t['yuslittlecyrillic'] = 0x0467;
  10187. t['yuslittleiotifiedcyrillic'] = 0x0469;
  10188. t['yusmallhiragana'] = 0x3085;
  10189. t['yusmallkatakana'] = 0x30E5;
  10190. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  10191. t['yuyekorean'] = 0x318B;
  10192. t['yuyeokorean'] = 0x318A;
  10193. t['yyabengali'] = 0x09DF;
  10194. t['yyadeva'] = 0x095F;
  10195. t['z'] = 0x007A;
  10196. t['zaarmenian'] = 0x0566;
  10197. t['zacute'] = 0x017A;
  10198. t['zadeva'] = 0x095B;
  10199. t['zagurmukhi'] = 0x0A5B;
  10200. t['zaharabic'] = 0x0638;
  10201. t['zahfinalarabic'] = 0xFEC6;
  10202. t['zahinitialarabic'] = 0xFEC7;
  10203. t['zahiragana'] = 0x3056;
  10204. t['zahmedialarabic'] = 0xFEC8;
  10205. t['zainarabic'] = 0x0632;
  10206. t['zainfinalarabic'] = 0xFEB0;
  10207. t['zakatakana'] = 0x30B6;
  10208. t['zaqefgadolhebrew'] = 0x0595;
  10209. t['zaqefqatanhebrew'] = 0x0594;
  10210. t['zarqahebrew'] = 0x0598;
  10211. t['zayin'] = 0x05D6;
  10212. t['zayindagesh'] = 0xFB36;
  10213. t['zayindageshhebrew'] = 0xFB36;
  10214. t['zayinhebrew'] = 0x05D6;
  10215. t['zbopomofo'] = 0x3117;
  10216. t['zcaron'] = 0x017E;
  10217. t['zcircle'] = 0x24E9;
  10218. t['zcircumflex'] = 0x1E91;
  10219. t['zcurl'] = 0x0291;
  10220. t['zdot'] = 0x017C;
  10221. t['zdotaccent'] = 0x017C;
  10222. t['zdotbelow'] = 0x1E93;
  10223. t['zecyrillic'] = 0x0437;
  10224. t['zedescendercyrillic'] = 0x0499;
  10225. t['zedieresiscyrillic'] = 0x04DF;
  10226. t['zehiragana'] = 0x305C;
  10227. t['zekatakana'] = 0x30BC;
  10228. t['zero'] = 0x0030;
  10229. t['zeroarabic'] = 0x0660;
  10230. t['zerobengali'] = 0x09E6;
  10231. t['zerodeva'] = 0x0966;
  10232. t['zerogujarati'] = 0x0AE6;
  10233. t['zerogurmukhi'] = 0x0A66;
  10234. t['zerohackarabic'] = 0x0660;
  10235. t['zeroinferior'] = 0x2080;
  10236. t['zeromonospace'] = 0xFF10;
  10237. t['zerooldstyle'] = 0xF730;
  10238. t['zeropersian'] = 0x06F0;
  10239. t['zerosuperior'] = 0x2070;
  10240. t['zerothai'] = 0x0E50;
  10241. t['zerowidthjoiner'] = 0xFEFF;
  10242. t['zerowidthnonjoiner'] = 0x200C;
  10243. t['zerowidthspace'] = 0x200B;
  10244. t['zeta'] = 0x03B6;
  10245. t['zhbopomofo'] = 0x3113;
  10246. t['zhearmenian'] = 0x056A;
  10247. t['zhebrevecyrillic'] = 0x04C2;
  10248. t['zhecyrillic'] = 0x0436;
  10249. t['zhedescendercyrillic'] = 0x0497;
  10250. t['zhedieresiscyrillic'] = 0x04DD;
  10251. t['zihiragana'] = 0x3058;
  10252. t['zikatakana'] = 0x30B8;
  10253. t['zinorhebrew'] = 0x05AE;
  10254. t['zlinebelow'] = 0x1E95;
  10255. t['zmonospace'] = 0xFF5A;
  10256. t['zohiragana'] = 0x305E;
  10257. t['zokatakana'] = 0x30BE;
  10258. t['zparen'] = 0x24B5;
  10259. t['zretroflexhook'] = 0x0290;
  10260. t['zstroke'] = 0x01B6;
  10261. t['zuhiragana'] = 0x305A;
  10262. t['zukatakana'] = 0x30BA;
  10263. t['.notdef'] = 0x0000;
  10264. });
  10265. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  10266. t['space'] = 0x0020;
  10267. t['a1'] = 0x2701;
  10268. t['a2'] = 0x2702;
  10269. t['a202'] = 0x2703;
  10270. t['a3'] = 0x2704;
  10271. t['a4'] = 0x260E;
  10272. t['a5'] = 0x2706;
  10273. t['a119'] = 0x2707;
  10274. t['a118'] = 0x2708;
  10275. t['a117'] = 0x2709;
  10276. t['a11'] = 0x261B;
  10277. t['a12'] = 0x261E;
  10278. t['a13'] = 0x270C;
  10279. t['a14'] = 0x270D;
  10280. t['a15'] = 0x270E;
  10281. t['a16'] = 0x270F;
  10282. t['a105'] = 0x2710;
  10283. t['a17'] = 0x2711;
  10284. t['a18'] = 0x2712;
  10285. t['a19'] = 0x2713;
  10286. t['a20'] = 0x2714;
  10287. t['a21'] = 0x2715;
  10288. t['a22'] = 0x2716;
  10289. t['a23'] = 0x2717;
  10290. t['a24'] = 0x2718;
  10291. t['a25'] = 0x2719;
  10292. t['a26'] = 0x271A;
  10293. t['a27'] = 0x271B;
  10294. t['a28'] = 0x271C;
  10295. t['a6'] = 0x271D;
  10296. t['a7'] = 0x271E;
  10297. t['a8'] = 0x271F;
  10298. t['a9'] = 0x2720;
  10299. t['a10'] = 0x2721;
  10300. t['a29'] = 0x2722;
  10301. t['a30'] = 0x2723;
  10302. t['a31'] = 0x2724;
  10303. t['a32'] = 0x2725;
  10304. t['a33'] = 0x2726;
  10305. t['a34'] = 0x2727;
  10306. t['a35'] = 0x2605;
  10307. t['a36'] = 0x2729;
  10308. t['a37'] = 0x272A;
  10309. t['a38'] = 0x272B;
  10310. t['a39'] = 0x272C;
  10311. t['a40'] = 0x272D;
  10312. t['a41'] = 0x272E;
  10313. t['a42'] = 0x272F;
  10314. t['a43'] = 0x2730;
  10315. t['a44'] = 0x2731;
  10316. t['a45'] = 0x2732;
  10317. t['a46'] = 0x2733;
  10318. t['a47'] = 0x2734;
  10319. t['a48'] = 0x2735;
  10320. t['a49'] = 0x2736;
  10321. t['a50'] = 0x2737;
  10322. t['a51'] = 0x2738;
  10323. t['a52'] = 0x2739;
  10324. t['a53'] = 0x273A;
  10325. t['a54'] = 0x273B;
  10326. t['a55'] = 0x273C;
  10327. t['a56'] = 0x273D;
  10328. t['a57'] = 0x273E;
  10329. t['a58'] = 0x273F;
  10330. t['a59'] = 0x2740;
  10331. t['a60'] = 0x2741;
  10332. t['a61'] = 0x2742;
  10333. t['a62'] = 0x2743;
  10334. t['a63'] = 0x2744;
  10335. t['a64'] = 0x2745;
  10336. t['a65'] = 0x2746;
  10337. t['a66'] = 0x2747;
  10338. t['a67'] = 0x2748;
  10339. t['a68'] = 0x2749;
  10340. t['a69'] = 0x274A;
  10341. t['a70'] = 0x274B;
  10342. t['a71'] = 0x25CF;
  10343. t['a72'] = 0x274D;
  10344. t['a73'] = 0x25A0;
  10345. t['a74'] = 0x274F;
  10346. t['a203'] = 0x2750;
  10347. t['a75'] = 0x2751;
  10348. t['a204'] = 0x2752;
  10349. t['a76'] = 0x25B2;
  10350. t['a77'] = 0x25BC;
  10351. t['a78'] = 0x25C6;
  10352. t['a79'] = 0x2756;
  10353. t['a81'] = 0x25D7;
  10354. t['a82'] = 0x2758;
  10355. t['a83'] = 0x2759;
  10356. t['a84'] = 0x275A;
  10357. t['a97'] = 0x275B;
  10358. t['a98'] = 0x275C;
  10359. t['a99'] = 0x275D;
  10360. t['a100'] = 0x275E;
  10361. t['a101'] = 0x2761;
  10362. t['a102'] = 0x2762;
  10363. t['a103'] = 0x2763;
  10364. t['a104'] = 0x2764;
  10365. t['a106'] = 0x2765;
  10366. t['a107'] = 0x2766;
  10367. t['a108'] = 0x2767;
  10368. t['a112'] = 0x2663;
  10369. t['a111'] = 0x2666;
  10370. t['a110'] = 0x2665;
  10371. t['a109'] = 0x2660;
  10372. t['a120'] = 0x2460;
  10373. t['a121'] = 0x2461;
  10374. t['a122'] = 0x2462;
  10375. t['a123'] = 0x2463;
  10376. t['a124'] = 0x2464;
  10377. t['a125'] = 0x2465;
  10378. t['a126'] = 0x2466;
  10379. t['a127'] = 0x2467;
  10380. t['a128'] = 0x2468;
  10381. t['a129'] = 0x2469;
  10382. t['a130'] = 0x2776;
  10383. t['a131'] = 0x2777;
  10384. t['a132'] = 0x2778;
  10385. t['a133'] = 0x2779;
  10386. t['a134'] = 0x277A;
  10387. t['a135'] = 0x277B;
  10388. t['a136'] = 0x277C;
  10389. t['a137'] = 0x277D;
  10390. t['a138'] = 0x277E;
  10391. t['a139'] = 0x277F;
  10392. t['a140'] = 0x2780;
  10393. t['a141'] = 0x2781;
  10394. t['a142'] = 0x2782;
  10395. t['a143'] = 0x2783;
  10396. t['a144'] = 0x2784;
  10397. t['a145'] = 0x2785;
  10398. t['a146'] = 0x2786;
  10399. t['a147'] = 0x2787;
  10400. t['a148'] = 0x2788;
  10401. t['a149'] = 0x2789;
  10402. t['a150'] = 0x278A;
  10403. t['a151'] = 0x278B;
  10404. t['a152'] = 0x278C;
  10405. t['a153'] = 0x278D;
  10406. t['a154'] = 0x278E;
  10407. t['a155'] = 0x278F;
  10408. t['a156'] = 0x2790;
  10409. t['a157'] = 0x2791;
  10410. t['a158'] = 0x2792;
  10411. t['a159'] = 0x2793;
  10412. t['a160'] = 0x2794;
  10413. t['a161'] = 0x2192;
  10414. t['a163'] = 0x2194;
  10415. t['a164'] = 0x2195;
  10416. t['a196'] = 0x2798;
  10417. t['a165'] = 0x2799;
  10418. t['a192'] = 0x279A;
  10419. t['a166'] = 0x279B;
  10420. t['a167'] = 0x279C;
  10421. t['a168'] = 0x279D;
  10422. t['a169'] = 0x279E;
  10423. t['a170'] = 0x279F;
  10424. t['a171'] = 0x27A0;
  10425. t['a172'] = 0x27A1;
  10426. t['a173'] = 0x27A2;
  10427. t['a162'] = 0x27A3;
  10428. t['a174'] = 0x27A4;
  10429. t['a175'] = 0x27A5;
  10430. t['a176'] = 0x27A6;
  10431. t['a177'] = 0x27A7;
  10432. t['a178'] = 0x27A8;
  10433. t['a179'] = 0x27A9;
  10434. t['a193'] = 0x27AA;
  10435. t['a180'] = 0x27AB;
  10436. t['a199'] = 0x27AC;
  10437. t['a181'] = 0x27AD;
  10438. t['a200'] = 0x27AE;
  10439. t['a182'] = 0x27AF;
  10440. t['a201'] = 0x27B1;
  10441. t['a183'] = 0x27B2;
  10442. t['a184'] = 0x27B3;
  10443. t['a197'] = 0x27B4;
  10444. t['a185'] = 0x27B5;
  10445. t['a194'] = 0x27B6;
  10446. t['a198'] = 0x27B7;
  10447. t['a186'] = 0x27B8;
  10448. t['a195'] = 0x27B9;
  10449. t['a187'] = 0x27BA;
  10450. t['a188'] = 0x27BB;
  10451. t['a189'] = 0x27BC;
  10452. t['a190'] = 0x27BD;
  10453. t['a191'] = 0x27BE;
  10454. t['a89'] = 0x2768; // 0xF8D7
  10455. t['a90'] = 0x2769; // 0xF8D8
  10456. t['a93'] = 0x276A; // 0xF8D9
  10457. t['a94'] = 0x276B; // 0xF8DA
  10458. t['a91'] = 0x276C; // 0xF8DB
  10459. t['a92'] = 0x276D; // 0xF8DC
  10460. t['a205'] = 0x276E; // 0xF8DD
  10461. t['a85'] = 0x276F; // 0xF8DE
  10462. t['a206'] = 0x2770; // 0xF8DF
  10463. t['a86'] = 0x2771; // 0xF8E0
  10464. t['a87'] = 0x2772; // 0xF8E1
  10465. t['a88'] = 0x2773; // 0xF8E2
  10466. t['a95'] = 0x2774; // 0xF8E3
  10467. t['a96'] = 0x2775; // 0xF8E4
  10468. t['.notdef'] = 0x0000;
  10469. });
  10470. exports.getGlyphsUnicode = getGlyphsUnicode;
  10471. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  10472. }));
  10473. (function (root, factory) {
  10474. {
  10475. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  10476. root.pdfjsCoreArithmeticDecoder);
  10477. }
  10478. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10479. var error = sharedUtil.error;
  10480. var log2 = sharedUtil.log2;
  10481. var readInt8 = sharedUtil.readInt8;
  10482. var readUint16 = sharedUtil.readUint16;
  10483. var readUint32 = sharedUtil.readUint32;
  10484. var shadow = sharedUtil.shadow;
  10485. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10486. var Jbig2Image = (function Jbig2ImageClosure() {
  10487. // Utility data structures
  10488. function ContextCache() {}
  10489. ContextCache.prototype = {
  10490. getContexts: function(id) {
  10491. if (id in this) {
  10492. return this[id];
  10493. }
  10494. return (this[id] = new Int8Array(1 << 16));
  10495. }
  10496. };
  10497. function DecodingContext(data, start, end) {
  10498. this.data = data;
  10499. this.start = start;
  10500. this.end = end;
  10501. }
  10502. DecodingContext.prototype = {
  10503. get decoder() {
  10504. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  10505. return shadow(this, 'decoder', decoder);
  10506. },
  10507. get contextCache() {
  10508. var cache = new ContextCache();
  10509. return shadow(this, 'contextCache', cache);
  10510. }
  10511. };
  10512. // Annex A. Arithmetic Integer Decoding Procedure
  10513. // A.2 Procedure for decoding values
  10514. function decodeInteger(contextCache, procedure, decoder) {
  10515. var contexts = contextCache.getContexts(procedure);
  10516. var prev = 1;
  10517. function readBits(length) {
  10518. var v = 0;
  10519. for (var i = 0; i < length; i++) {
  10520. var bit = decoder.readBit(contexts, prev);
  10521. prev = (prev < 256 ? (prev << 1) | bit :
  10522. (((prev << 1) | bit) & 511) | 256);
  10523. v = (v << 1) | bit;
  10524. }
  10525. return v >>> 0;
  10526. }
  10527. var sign = readBits(1);
  10528. var value = readBits(1) ?
  10529. (readBits(1) ?
  10530. (readBits(1) ?
  10531. (readBits(1) ?
  10532. (readBits(1) ?
  10533. (readBits(32) + 4436) :
  10534. readBits(12) + 340) :
  10535. readBits(8) + 84) :
  10536. readBits(6) + 20) :
  10537. readBits(4) + 4) :
  10538. readBits(2);
  10539. return (sign === 0 ? value : (value > 0 ? -value : null));
  10540. }
  10541. // A.3 The IAID decoding procedure
  10542. function decodeIAID(contextCache, decoder, codeLength) {
  10543. var contexts = contextCache.getContexts('IAID');
  10544. var prev = 1;
  10545. for (var i = 0; i < codeLength; i++) {
  10546. var bit = decoder.readBit(contexts, prev);
  10547. prev = (prev << 1) | bit;
  10548. }
  10549. if (codeLength < 31) {
  10550. return prev & ((1 << codeLength) - 1);
  10551. }
  10552. return prev & 0x7FFFFFFF;
  10553. }
  10554. // 7.3 Segment types
  10555. var SegmentTypes = [
  10556. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  10557. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  10558. null, null, null, null, null, 'patternDictionary', null, null, null,
  10559. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  10560. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  10561. null, null, null, null, null, 'IntermediateGenericRegion', null,
  10562. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  10563. 'IntermediateGenericRefinementRegion', null,
  10564. 'ImmediateGenericRefinementRegion',
  10565. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  10566. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  10567. 'Tables', null, null, null, null, null, null, null, null,
  10568. 'Extension'
  10569. ];
  10570. var CodingTemplates = [
  10571. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  10572. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  10573. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  10574. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  10575. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  10576. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  10577. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  10578. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  10579. {x: -1, y: 0}],
  10580. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  10581. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  10582. ];
  10583. var RefinementTemplates = [
  10584. {
  10585. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  10586. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  10587. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  10588. },
  10589. {
  10590. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  10591. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  10592. {x: 0, y: 1}, {x: 1, y: 1}]
  10593. }
  10594. ];
  10595. // See 6.2.5.7 Decoding the bitmap.
  10596. var ReusedContexts = [
  10597. 0x9B25, // 10011 0110010 0101
  10598. 0x0795, // 0011 110010 101
  10599. 0x00E5, // 001 11001 01
  10600. 0x0195 // 011001 0101
  10601. ];
  10602. var RefinementReusedContexts = [
  10603. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  10604. 0x0008 // '0000' + '001000'
  10605. ];
  10606. function decodeBitmapTemplate0(width, height, decodingContext) {
  10607. var decoder = decodingContext.decoder;
  10608. var contexts = decodingContext.contextCache.getContexts('GB');
  10609. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  10610. // ...ooooo....
  10611. // ..ooooooo... Context template for current pixel (X)
  10612. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  10613. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  10614. for (i = 0; i < height; i++) {
  10615. row = bitmap[i] = new Uint8Array(width);
  10616. row1 = (i < 1) ? row : bitmap[i - 1];
  10617. row2 = (i < 2) ? row : bitmap[i - 2];
  10618. // At the beginning of each row:
  10619. // Fill contextLabel with pixels that are above/right of (X)
  10620. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  10621. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  10622. (row1[3] << 4);
  10623. for (j = 0; j < width; j++) {
  10624. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  10625. // At each pixel: Clear contextLabel pixels that are shifted
  10626. // out of the context, then add new ones.
  10627. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  10628. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  10629. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  10630. }
  10631. }
  10632. return bitmap;
  10633. }
  10634. // 6.2 Generic Region Decoding Procedure
  10635. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  10636. decodingContext) {
  10637. if (mmr) {
  10638. error('JBIG2 error: MMR encoding is not supported');
  10639. }
  10640. // Use optimized version for the most common case
  10641. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  10642. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  10643. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  10644. return decodeBitmapTemplate0(width, height, decodingContext);
  10645. }
  10646. var useskip = !!skip;
  10647. var template = CodingTemplates[templateIndex].concat(at);
  10648. // Sorting is non-standard, and it is not required. But sorting increases
  10649. // the number of template bits that can be reused from the previous
  10650. // contextLabel in the main loop.
  10651. template.sort(function (a, b) {
  10652. return (a.y - b.y) || (a.x - b.x);
  10653. });
  10654. var templateLength = template.length;
  10655. var templateX = new Int8Array(templateLength);
  10656. var templateY = new Int8Array(templateLength);
  10657. var changingTemplateEntries = [];
  10658. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  10659. var c, k;
  10660. for (k = 0; k < templateLength; k++) {
  10661. templateX[k] = template[k].x;
  10662. templateY[k] = template[k].y;
  10663. minX = Math.min(minX, template[k].x);
  10664. maxX = Math.max(maxX, template[k].x);
  10665. minY = Math.min(minY, template[k].y);
  10666. // Check if the template pixel appears in two consecutive context labels,
  10667. // so it can be reused. Otherwise, we add it to the list of changing
  10668. // template entries.
  10669. if (k < templateLength - 1 &&
  10670. template[k].y === template[k + 1].y &&
  10671. template[k].x === template[k + 1].x - 1) {
  10672. reuseMask |= 1 << (templateLength - 1 - k);
  10673. } else {
  10674. changingTemplateEntries.push(k);
  10675. }
  10676. }
  10677. var changingEntriesLength = changingTemplateEntries.length;
  10678. var changingTemplateX = new Int8Array(changingEntriesLength);
  10679. var changingTemplateY = new Int8Array(changingEntriesLength);
  10680. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  10681. for (c = 0; c < changingEntriesLength; c++) {
  10682. k = changingTemplateEntries[c];
  10683. changingTemplateX[c] = template[k].x;
  10684. changingTemplateY[c] = template[k].y;
  10685. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  10686. }
  10687. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  10688. var sbb_left = -minX;
  10689. var sbb_top = -minY;
  10690. var sbb_right = width - maxX;
  10691. var pseudoPixelContext = ReusedContexts[templateIndex];
  10692. var row = new Uint8Array(width);
  10693. var bitmap = [];
  10694. var decoder = decodingContext.decoder;
  10695. var contexts = decodingContext.contextCache.getContexts('GB');
  10696. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  10697. for (var i = 0; i < height; i++) {
  10698. if (prediction) {
  10699. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  10700. ltp ^= sltp;
  10701. if (ltp) {
  10702. bitmap.push(row); // duplicate previous row
  10703. continue;
  10704. }
  10705. }
  10706. row = new Uint8Array(row);
  10707. bitmap.push(row);
  10708. for (j = 0; j < width; j++) {
  10709. if (useskip && skip[i][j]) {
  10710. row[j] = 0;
  10711. continue;
  10712. }
  10713. // Are we in the middle of a scanline, so we can reuse contextLabel
  10714. // bits?
  10715. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  10716. // If yes, we can just shift the bits that are reusable and only
  10717. // fetch the remaining ones.
  10718. contextLabel = (contextLabel << 1) & reuseMask;
  10719. for (k = 0; k < changingEntriesLength; k++) {
  10720. i0 = i + changingTemplateY[k];
  10721. j0 = j + changingTemplateX[k];
  10722. bit = bitmap[i0][j0];
  10723. if (bit) {
  10724. bit = changingTemplateBit[k];
  10725. contextLabel |= bit;
  10726. }
  10727. }
  10728. } else {
  10729. // compute the contextLabel from scratch
  10730. contextLabel = 0;
  10731. shift = templateLength - 1;
  10732. for (k = 0; k < templateLength; k++, shift--) {
  10733. j0 = j + templateX[k];
  10734. if (j0 >= 0 && j0 < width) {
  10735. i0 = i + templateY[k];
  10736. if (i0 >= 0) {
  10737. bit = bitmap[i0][j0];
  10738. if (bit) {
  10739. contextLabel |= bit << shift;
  10740. }
  10741. }
  10742. }
  10743. }
  10744. }
  10745. var pixel = decoder.readBit(contexts, contextLabel);
  10746. row[j] = pixel;
  10747. }
  10748. }
  10749. return bitmap;
  10750. }
  10751. // 6.3.2 Generic Refinement Region Decoding Procedure
  10752. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  10753. offsetX, offsetY, prediction, at,
  10754. decodingContext) {
  10755. var codingTemplate = RefinementTemplates[templateIndex].coding;
  10756. if (templateIndex === 0) {
  10757. codingTemplate = codingTemplate.concat([at[0]]);
  10758. }
  10759. var codingTemplateLength = codingTemplate.length;
  10760. var codingTemplateX = new Int32Array(codingTemplateLength);
  10761. var codingTemplateY = new Int32Array(codingTemplateLength);
  10762. var k;
  10763. for (k = 0; k < codingTemplateLength; k++) {
  10764. codingTemplateX[k] = codingTemplate[k].x;
  10765. codingTemplateY[k] = codingTemplate[k].y;
  10766. }
  10767. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  10768. if (templateIndex === 0) {
  10769. referenceTemplate = referenceTemplate.concat([at[1]]);
  10770. }
  10771. var referenceTemplateLength = referenceTemplate.length;
  10772. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  10773. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  10774. for (k = 0; k < referenceTemplateLength; k++) {
  10775. referenceTemplateX[k] = referenceTemplate[k].x;
  10776. referenceTemplateY[k] = referenceTemplate[k].y;
  10777. }
  10778. var referenceWidth = referenceBitmap[0].length;
  10779. var referenceHeight = referenceBitmap.length;
  10780. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  10781. var bitmap = [];
  10782. var decoder = decodingContext.decoder;
  10783. var contexts = decodingContext.contextCache.getContexts('GR');
  10784. var ltp = 0;
  10785. for (var i = 0; i < height; i++) {
  10786. if (prediction) {
  10787. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  10788. ltp ^= sltp;
  10789. if (ltp) {
  10790. error('JBIG2 error: prediction is not supported');
  10791. }
  10792. }
  10793. var row = new Uint8Array(width);
  10794. bitmap.push(row);
  10795. for (var j = 0; j < width; j++) {
  10796. var i0, j0;
  10797. var contextLabel = 0;
  10798. for (k = 0; k < codingTemplateLength; k++) {
  10799. i0 = i + codingTemplateY[k];
  10800. j0 = j + codingTemplateX[k];
  10801. if (i0 < 0 || j0 < 0 || j0 >= width) {
  10802. contextLabel <<= 1; // out of bound pixel
  10803. } else {
  10804. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  10805. }
  10806. }
  10807. for (k = 0; k < referenceTemplateLength; k++) {
  10808. i0 = i + referenceTemplateY[k] + offsetY;
  10809. j0 = j + referenceTemplateX[k] + offsetX;
  10810. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  10811. j0 >= referenceWidth) {
  10812. contextLabel <<= 1; // out of bound pixel
  10813. } else {
  10814. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  10815. }
  10816. }
  10817. var pixel = decoder.readBit(contexts, contextLabel);
  10818. row[j] = pixel;
  10819. }
  10820. }
  10821. return bitmap;
  10822. }
  10823. // 6.5.5 Decoding the symbol dictionary
  10824. function decodeSymbolDictionary(huffman, refinement, symbols,
  10825. numberOfNewSymbols, numberOfExportedSymbols,
  10826. huffmanTables, templateIndex, at,
  10827. refinementTemplateIndex, refinementAt,
  10828. decodingContext) {
  10829. if (huffman) {
  10830. error('JBIG2 error: huffman is not supported');
  10831. }
  10832. var newSymbols = [];
  10833. var currentHeight = 0;
  10834. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  10835. var decoder = decodingContext.decoder;
  10836. var contextCache = decodingContext.contextCache;
  10837. while (newSymbols.length < numberOfNewSymbols) {
  10838. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  10839. currentHeight += deltaHeight;
  10840. var currentWidth = 0;
  10841. var totalWidth = 0;
  10842. while (true) {
  10843. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  10844. if (deltaWidth === null) {
  10845. break; // OOB
  10846. }
  10847. currentWidth += deltaWidth;
  10848. totalWidth += currentWidth;
  10849. var bitmap;
  10850. if (refinement) {
  10851. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  10852. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  10853. if (numberOfInstances > 1) {
  10854. bitmap = decodeTextRegion(huffman, refinement,
  10855. currentWidth, currentHeight, 0,
  10856. numberOfInstances, 1, //strip size
  10857. symbols.concat(newSymbols),
  10858. symbolCodeLength,
  10859. 0, //transposed
  10860. 0, //ds offset
  10861. 1, //top left 7.4.3.1.1
  10862. 0, //OR operator
  10863. huffmanTables,
  10864. refinementTemplateIndex, refinementAt,
  10865. decodingContext);
  10866. } else {
  10867. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10868. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10869. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10870. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  10871. newSymbols[symbolId - symbols.length]);
  10872. bitmap = decodeRefinement(currentWidth, currentHeight,
  10873. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  10874. decodingContext);
  10875. }
  10876. } else {
  10877. // 6.5.8.1 Direct-coded symbol bitmap
  10878. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  10879. templateIndex, false, null, at, decodingContext);
  10880. }
  10881. newSymbols.push(bitmap);
  10882. }
  10883. }
  10884. // 6.5.10 Exported symbols
  10885. var exportedSymbols = [];
  10886. var flags = [], currentFlag = false;
  10887. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  10888. while (flags.length < totalSymbolsLength) {
  10889. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  10890. while (runLength--) {
  10891. flags.push(currentFlag);
  10892. }
  10893. currentFlag = !currentFlag;
  10894. }
  10895. for (var i = 0, ii = symbols.length; i < ii; i++) {
  10896. if (flags[i]) {
  10897. exportedSymbols.push(symbols[i]);
  10898. }
  10899. }
  10900. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10901. if (flags[i]) {
  10902. exportedSymbols.push(newSymbols[j]);
  10903. }
  10904. }
  10905. return exportedSymbols;
  10906. }
  10907. function decodeTextRegion(huffman, refinement, width, height,
  10908. defaultPixelValue, numberOfSymbolInstances,
  10909. stripSize, inputSymbols, symbolCodeLength,
  10910. transposed, dsOffset, referenceCorner,
  10911. combinationOperator, huffmanTables,
  10912. refinementTemplateIndex, refinementAt,
  10913. decodingContext) {
  10914. if (huffman) {
  10915. error('JBIG2 error: huffman is not supported');
  10916. }
  10917. // Prepare bitmap
  10918. var bitmap = [];
  10919. var i, row;
  10920. for (i = 0; i < height; i++) {
  10921. row = new Uint8Array(width);
  10922. if (defaultPixelValue) {
  10923. for (var j = 0; j < width; j++) {
  10924. row[j] = defaultPixelValue;
  10925. }
  10926. }
  10927. bitmap.push(row);
  10928. }
  10929. var decoder = decodingContext.decoder;
  10930. var contextCache = decodingContext.contextCache;
  10931. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10932. var firstS = 0;
  10933. i = 0;
  10934. while (i < numberOfSymbolInstances) {
  10935. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10936. stripT += deltaT;
  10937. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10938. firstS += deltaFirstS;
  10939. var currentS = firstS;
  10940. do {
  10941. var currentT = (stripSize === 1 ? 0 :
  10942. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10943. var t = stripSize * stripT + currentT;
  10944. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10945. var applyRefinement = (refinement &&
  10946. decodeInteger(contextCache, 'IARI', decoder));
  10947. var symbolBitmap = inputSymbols[symbolId];
  10948. var symbolWidth = symbolBitmap[0].length;
  10949. var symbolHeight = symbolBitmap.length;
  10950. if (applyRefinement) {
  10951. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10952. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10953. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10954. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10955. symbolWidth += rdw;
  10956. symbolHeight += rdh;
  10957. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10958. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10959. (rdh >> 1) + rdy, false, refinementAt,
  10960. decodingContext);
  10961. }
  10962. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10963. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10964. var s2, t2, symbolRow;
  10965. if (transposed) {
  10966. // Place Symbol Bitmap from T1,S1
  10967. for (s2 = 0; s2 < symbolHeight; s2++) {
  10968. row = bitmap[offsetS + s2];
  10969. if (!row) {
  10970. continue;
  10971. }
  10972. symbolRow = symbolBitmap[s2];
  10973. // To ignore Parts of Symbol bitmap which goes
  10974. // outside bitmap region
  10975. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10976. switch (combinationOperator) {
  10977. case 0: // OR
  10978. for (t2 = 0; t2 < maxWidth; t2++) {
  10979. row[offsetT + t2] |= symbolRow[t2];
  10980. }
  10981. break;
  10982. case 2: // XOR
  10983. for (t2 = 0; t2 < maxWidth; t2++) {
  10984. row[offsetT + t2] ^= symbolRow[t2];
  10985. }
  10986. break;
  10987. default:
  10988. error('JBIG2 error: operator ' + combinationOperator +
  10989. ' is not supported');
  10990. }
  10991. }
  10992. currentS += symbolHeight - 1;
  10993. } else {
  10994. for (t2 = 0; t2 < symbolHeight; t2++) {
  10995. row = bitmap[offsetT + t2];
  10996. if (!row) {
  10997. continue;
  10998. }
  10999. symbolRow = symbolBitmap[t2];
  11000. switch (combinationOperator) {
  11001. case 0: // OR
  11002. for (s2 = 0; s2 < symbolWidth; s2++) {
  11003. row[offsetS + s2] |= symbolRow[s2];
  11004. }
  11005. break;
  11006. case 2: // XOR
  11007. for (s2 = 0; s2 < symbolWidth; s2++) {
  11008. row[offsetS + s2] ^= symbolRow[s2];
  11009. }
  11010. break;
  11011. default:
  11012. error('JBIG2 error: operator ' + combinationOperator +
  11013. ' is not supported');
  11014. }
  11015. }
  11016. currentS += symbolWidth - 1;
  11017. }
  11018. i++;
  11019. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11020. if (deltaS === null) {
  11021. break; // OOB
  11022. }
  11023. currentS += deltaS + dsOffset;
  11024. } while (true);
  11025. }
  11026. return bitmap;
  11027. }
  11028. function readSegmentHeader(data, start) {
  11029. var segmentHeader = {};
  11030. segmentHeader.number = readUint32(data, start);
  11031. var flags = data[start + 4];
  11032. var segmentType = flags & 0x3F;
  11033. if (!SegmentTypes[segmentType]) {
  11034. error('JBIG2 error: invalid segment type: ' + segmentType);
  11035. }
  11036. segmentHeader.type = segmentType;
  11037. segmentHeader.typeName = SegmentTypes[segmentType];
  11038. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11039. var pageAssociationFieldSize = !!(flags & 0x40);
  11040. var referredFlags = data[start + 5];
  11041. var referredToCount = (referredFlags >> 5) & 7;
  11042. var retainBits = [referredFlags & 31];
  11043. var position = start + 6;
  11044. if (referredFlags === 7) {
  11045. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11046. position += 3;
  11047. var bytes = (referredToCount + 7) >> 3;
  11048. retainBits[0] = data[position++];
  11049. while (--bytes > 0) {
  11050. retainBits.push(data[position++]);
  11051. }
  11052. } else if (referredFlags === 5 || referredFlags === 6) {
  11053. error('JBIG2 error: invalid referred-to flags');
  11054. }
  11055. segmentHeader.retainBits = retainBits;
  11056. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11057. (segmentHeader.number <= 65536 ? 2 : 4));
  11058. var referredTo = [];
  11059. var i, ii;
  11060. for (i = 0; i < referredToCount; i++) {
  11061. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11062. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11063. readUint32(data, position)));
  11064. referredTo.push(number);
  11065. position += referredToSegmentNumberSize;
  11066. }
  11067. segmentHeader.referredTo = referredTo;
  11068. if (!pageAssociationFieldSize) {
  11069. segmentHeader.pageAssociation = data[position++];
  11070. } else {
  11071. segmentHeader.pageAssociation = readUint32(data, position);
  11072. position += 4;
  11073. }
  11074. segmentHeader.length = readUint32(data, position);
  11075. position += 4;
  11076. if (segmentHeader.length === 0xFFFFFFFF) {
  11077. // 7.2.7 Segment data length, unknown segment length
  11078. if (segmentType === 38) { // ImmediateGenericRegion
  11079. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11080. var genericRegionSegmentFlags = data[position +
  11081. RegionSegmentInformationFieldLength];
  11082. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11083. // searching for the segment end
  11084. var searchPatternLength = 6;
  11085. var searchPattern = new Uint8Array(searchPatternLength);
  11086. if (!genericRegionMmr) {
  11087. searchPattern[0] = 0xFF;
  11088. searchPattern[1] = 0xAC;
  11089. }
  11090. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11091. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11092. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11093. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11094. for (i = position, ii = data.length; i < ii; i++) {
  11095. var j = 0;
  11096. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11097. j++;
  11098. }
  11099. if (j === searchPatternLength) {
  11100. segmentHeader.length = i + searchPatternLength;
  11101. break;
  11102. }
  11103. }
  11104. if (segmentHeader.length === 0xFFFFFFFF) {
  11105. error('JBIG2 error: segment end was not found');
  11106. }
  11107. } else {
  11108. error('JBIG2 error: invalid unknown segment length');
  11109. }
  11110. }
  11111. segmentHeader.headerEnd = position;
  11112. return segmentHeader;
  11113. }
  11114. function readSegments(header, data, start, end) {
  11115. var segments = [];
  11116. var position = start;
  11117. while (position < end) {
  11118. var segmentHeader = readSegmentHeader(data, position);
  11119. position = segmentHeader.headerEnd;
  11120. var segment = {
  11121. header: segmentHeader,
  11122. data: data
  11123. };
  11124. if (!header.randomAccess) {
  11125. segment.start = position;
  11126. position += segmentHeader.length;
  11127. segment.end = position;
  11128. }
  11129. segments.push(segment);
  11130. if (segmentHeader.type === 51) {
  11131. break; // end of file is found
  11132. }
  11133. }
  11134. if (header.randomAccess) {
  11135. for (var i = 0, ii = segments.length; i < ii; i++) {
  11136. segments[i].start = position;
  11137. position += segments[i].header.length;
  11138. segments[i].end = position;
  11139. }
  11140. }
  11141. return segments;
  11142. }
  11143. // 7.4.1 Region segment information field
  11144. function readRegionSegmentInformation(data, start) {
  11145. return {
  11146. width: readUint32(data, start),
  11147. height: readUint32(data, start + 4),
  11148. x: readUint32(data, start + 8),
  11149. y: readUint32(data, start + 12),
  11150. combinationOperator: data[start + 16] & 7
  11151. };
  11152. }
  11153. var RegionSegmentInformationFieldLength = 17;
  11154. function processSegment(segment, visitor) {
  11155. var header = segment.header;
  11156. var data = segment.data, position = segment.start, end = segment.end;
  11157. var args, at, i, atLength;
  11158. switch (header.type) {
  11159. case 0: // SymbolDictionary
  11160. // 7.4.2 Symbol dictionary segment syntax
  11161. var dictionary = {};
  11162. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11163. dictionary.huffman = !!(dictionaryFlags & 1);
  11164. dictionary.refinement = !!(dictionaryFlags & 2);
  11165. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11166. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11167. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11168. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11169. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11170. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11171. dictionary.template = (dictionaryFlags >> 10) & 3;
  11172. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11173. position += 2;
  11174. if (!dictionary.huffman) {
  11175. atLength = dictionary.template === 0 ? 4 : 1;
  11176. at = [];
  11177. for (i = 0; i < atLength; i++) {
  11178. at.push({
  11179. x: readInt8(data, position),
  11180. y: readInt8(data, position + 1)
  11181. });
  11182. position += 2;
  11183. }
  11184. dictionary.at = at;
  11185. }
  11186. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11187. at = [];
  11188. for (i = 0; i < 2; i++) {
  11189. at.push({
  11190. x: readInt8(data, position),
  11191. y: readInt8(data, position + 1)
  11192. });
  11193. position += 2;
  11194. }
  11195. dictionary.refinementAt = at;
  11196. }
  11197. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11198. position += 4;
  11199. dictionary.numberOfNewSymbols = readUint32(data, position);
  11200. position += 4;
  11201. args = [dictionary, header.number, header.referredTo,
  11202. data, position, end];
  11203. break;
  11204. case 6: // ImmediateTextRegion
  11205. case 7: // ImmediateLosslessTextRegion
  11206. var textRegion = {};
  11207. textRegion.info = readRegionSegmentInformation(data, position);
  11208. position += RegionSegmentInformationFieldLength;
  11209. var textRegionSegmentFlags = readUint16(data, position);
  11210. position += 2;
  11211. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11212. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11213. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11214. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11215. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11216. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11217. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11218. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11219. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11220. if (textRegion.huffman) {
  11221. var textRegionHuffmanFlags = readUint16(data, position);
  11222. position += 2;
  11223. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11224. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11225. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11226. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11227. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11228. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11229. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11230. textRegion.huffmanRefinementSizeSelector =
  11231. !!(textRegionHuffmanFlags & 14);
  11232. }
  11233. if (textRegion.refinement && !textRegion.refinementTemplate) {
  11234. at = [];
  11235. for (i = 0; i < 2; i++) {
  11236. at.push({
  11237. x: readInt8(data, position),
  11238. y: readInt8(data, position + 1)
  11239. });
  11240. position += 2;
  11241. }
  11242. textRegion.refinementAt = at;
  11243. }
  11244. textRegion.numberOfSymbolInstances = readUint32(data, position);
  11245. position += 4;
  11246. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  11247. if (textRegion.huffman) {
  11248. error('JBIG2 error: huffman is not supported');
  11249. }
  11250. args = [textRegion, header.referredTo, data, position, end];
  11251. break;
  11252. case 38: // ImmediateGenericRegion
  11253. case 39: // ImmediateLosslessGenericRegion
  11254. var genericRegion = {};
  11255. genericRegion.info = readRegionSegmentInformation(data, position);
  11256. position += RegionSegmentInformationFieldLength;
  11257. var genericRegionSegmentFlags = data[position++];
  11258. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  11259. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  11260. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  11261. if (!genericRegion.mmr) {
  11262. atLength = genericRegion.template === 0 ? 4 : 1;
  11263. at = [];
  11264. for (i = 0; i < atLength; i++) {
  11265. at.push({
  11266. x: readInt8(data, position),
  11267. y: readInt8(data, position + 1)
  11268. });
  11269. position += 2;
  11270. }
  11271. genericRegion.at = at;
  11272. }
  11273. args = [genericRegion, data, position, end];
  11274. break;
  11275. case 48: // PageInformation
  11276. var pageInfo = {
  11277. width: readUint32(data, position),
  11278. height: readUint32(data, position + 4),
  11279. resolutionX: readUint32(data, position + 8),
  11280. resolutionY: readUint32(data, position + 12)
  11281. };
  11282. if (pageInfo.height === 0xFFFFFFFF) {
  11283. delete pageInfo.height;
  11284. }
  11285. var pageSegmentFlags = data[position + 16];
  11286. var pageStripingInformation = readUint16(data, position + 17);
  11287. pageInfo.lossless = !!(pageSegmentFlags & 1);
  11288. pageInfo.refinement = !!(pageSegmentFlags & 2);
  11289. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  11290. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  11291. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  11292. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  11293. args = [pageInfo];
  11294. break;
  11295. case 49: // EndOfPage
  11296. break;
  11297. case 50: // EndOfStripe
  11298. break;
  11299. case 51: // EndOfFile
  11300. break;
  11301. case 62: // 7.4.15 defines 2 extension types which
  11302. // are comments and can be ignored.
  11303. break;
  11304. default:
  11305. error('JBIG2 error: segment type ' + header.typeName + '(' +
  11306. header.type + ') is not implemented');
  11307. }
  11308. var callbackName = 'on' + header.typeName;
  11309. if (callbackName in visitor) {
  11310. visitor[callbackName].apply(visitor, args);
  11311. }
  11312. }
  11313. function processSegments(segments, visitor) {
  11314. for (var i = 0, ii = segments.length; i < ii; i++) {
  11315. processSegment(segments[i], visitor);
  11316. }
  11317. }
  11318. function parseJbig2(data, start, end) {
  11319. var position = start;
  11320. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  11321. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  11322. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  11323. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  11324. error('JBIG2 error: invalid header');
  11325. }
  11326. var header = {};
  11327. position += 8;
  11328. var flags = data[position++];
  11329. header.randomAccess = !(flags & 1);
  11330. if (!(flags & 2)) {
  11331. header.numberOfPages = readUint32(data, position);
  11332. position += 4;
  11333. }
  11334. var segments = readSegments(header, data, position, end);
  11335. error('Not implemented');
  11336. // processSegments(segments, new SimpleSegmentVisitor());
  11337. }
  11338. function parseJbig2Chunks(chunks) {
  11339. var visitor = new SimpleSegmentVisitor();
  11340. for (var i = 0, ii = chunks.length; i < ii; i++) {
  11341. var chunk = chunks[i];
  11342. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  11343. processSegments(segments, visitor);
  11344. }
  11345. return visitor.buffer;
  11346. }
  11347. function SimpleSegmentVisitor() {}
  11348. SimpleSegmentVisitor.prototype = {
  11349. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  11350. this.currentPageInfo = info;
  11351. var rowSize = (info.width + 7) >> 3;
  11352. var buffer = new Uint8Array(rowSize * info.height);
  11353. // The contents of ArrayBuffers are initialized to 0.
  11354. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  11355. if (info.defaultPixelValue) {
  11356. for (var i = 0, ii = buffer.length; i < ii; i++) {
  11357. buffer[i] = 0xFF;
  11358. }
  11359. }
  11360. this.buffer = buffer;
  11361. },
  11362. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  11363. var pageInfo = this.currentPageInfo;
  11364. var width = regionInfo.width, height = regionInfo.height;
  11365. var rowSize = (pageInfo.width + 7) >> 3;
  11366. var combinationOperator = pageInfo.combinationOperatorOverride ?
  11367. regionInfo.combinationOperator : pageInfo.combinationOperator;
  11368. var buffer = this.buffer;
  11369. var mask0 = 128 >> (regionInfo.x & 7);
  11370. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  11371. var i, j, mask, offset;
  11372. switch (combinationOperator) {
  11373. case 0: // OR
  11374. for (i = 0; i < height; i++) {
  11375. mask = mask0;
  11376. offset = offset0;
  11377. for (j = 0; j < width; j++) {
  11378. if (bitmap[i][j]) {
  11379. buffer[offset] |= mask;
  11380. }
  11381. mask >>= 1;
  11382. if (!mask) {
  11383. mask = 128;
  11384. offset++;
  11385. }
  11386. }
  11387. offset0 += rowSize;
  11388. }
  11389. break;
  11390. case 2: // XOR
  11391. for (i = 0; i < height; i++) {
  11392. mask = mask0;
  11393. offset = offset0;
  11394. for (j = 0; j < width; j++) {
  11395. if (bitmap[i][j]) {
  11396. buffer[offset] ^= mask;
  11397. }
  11398. mask >>= 1;
  11399. if (!mask) {
  11400. mask = 128;
  11401. offset++;
  11402. }
  11403. }
  11404. offset0 += rowSize;
  11405. }
  11406. break;
  11407. default:
  11408. error('JBIG2 error: operator ' + combinationOperator +
  11409. ' is not supported');
  11410. }
  11411. },
  11412. onImmediateGenericRegion:
  11413. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  11414. start, end) {
  11415. var regionInfo = region.info;
  11416. var decodingContext = new DecodingContext(data, start, end);
  11417. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  11418. region.template, region.prediction, null,
  11419. region.at, decodingContext);
  11420. this.drawBitmap(regionInfo, bitmap);
  11421. },
  11422. onImmediateLosslessGenericRegion:
  11423. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  11424. this.onImmediateGenericRegion.apply(this, arguments);
  11425. },
  11426. onSymbolDictionary:
  11427. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  11428. currentSegment,
  11429. referredSegments,
  11430. data, start, end) {
  11431. var huffmanTables;
  11432. if (dictionary.huffman) {
  11433. error('JBIG2 error: huffman is not supported');
  11434. }
  11435. // Combines exported symbols from all referred segments
  11436. var symbols = this.symbols;
  11437. if (!symbols) {
  11438. this.symbols = symbols = {};
  11439. }
  11440. var inputSymbols = [];
  11441. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  11442. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  11443. }
  11444. var decodingContext = new DecodingContext(data, start, end);
  11445. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  11446. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  11447. dictionary.numberOfExportedSymbols, huffmanTables,
  11448. dictionary.template, dictionary.at,
  11449. dictionary.refinementTemplate, dictionary.refinementAt,
  11450. decodingContext);
  11451. },
  11452. onImmediateTextRegion:
  11453. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  11454. referredSegments,
  11455. data, start, end) {
  11456. var regionInfo = region.info;
  11457. var huffmanTables;
  11458. // Combines exported symbols from all referred segments
  11459. var symbols = this.symbols;
  11460. var inputSymbols = [];
  11461. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  11462. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  11463. }
  11464. var symbolCodeLength = log2(inputSymbols.length);
  11465. var decodingContext = new DecodingContext(data, start, end);
  11466. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  11467. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  11468. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  11469. symbolCodeLength, region.transposed, region.dsOffset,
  11470. region.referenceCorner, region.combinationOperator, huffmanTables,
  11471. region.refinementTemplate, region.refinementAt, decodingContext);
  11472. this.drawBitmap(regionInfo, bitmap);
  11473. },
  11474. onImmediateLosslessTextRegion:
  11475. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  11476. this.onImmediateTextRegion.apply(this, arguments);
  11477. }
  11478. };
  11479. function Jbig2Image() {}
  11480. Jbig2Image.prototype = {
  11481. parseChunks: function Jbig2Image_parseChunks(chunks) {
  11482. return parseJbig2Chunks(chunks);
  11483. }
  11484. };
  11485. return Jbig2Image;
  11486. })();
  11487. exports.Jbig2Image = Jbig2Image;
  11488. }));
  11489. (function (root, factory) {
  11490. {
  11491. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11492. root.pdfjsCoreArithmeticDecoder);
  11493. }
  11494. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11495. var info = sharedUtil.info;
  11496. var log2 = sharedUtil.log2;
  11497. var readUint16 = sharedUtil.readUint16;
  11498. var readUint32 = sharedUtil.readUint32;
  11499. var warn = sharedUtil.warn;
  11500. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11501. var JpxImage = (function JpxImageClosure() {
  11502. // Table E.1
  11503. var SubbandsGainLog2 = {
  11504. 'LL': 0,
  11505. 'LH': 1,
  11506. 'HL': 1,
  11507. 'HH': 2
  11508. };
  11509. function JpxImage() {
  11510. this.failOnCorruptedImage = false;
  11511. }
  11512. JpxImage.prototype = {
  11513. parse: function JpxImage_parse(data) {
  11514. var head = readUint16(data, 0);
  11515. // No box header, immediate start of codestream (SOC)
  11516. if (head === 0xFF4F) {
  11517. this.parseCodestream(data, 0, data.length);
  11518. return;
  11519. }
  11520. var position = 0, length = data.length;
  11521. while (position < length) {
  11522. var headerSize = 8;
  11523. var lbox = readUint32(data, position);
  11524. var tbox = readUint32(data, position + 4);
  11525. position += headerSize;
  11526. if (lbox === 1) {
  11527. // XLBox: read UInt64 according to spec.
  11528. // JavaScript's int precision of 53 bit should be sufficient here.
  11529. lbox = readUint32(data, position) * 4294967296 +
  11530. readUint32(data, position + 4);
  11531. position += 8;
  11532. headerSize += 8;
  11533. }
  11534. if (lbox === 0) {
  11535. lbox = length - position + headerSize;
  11536. }
  11537. if (lbox < headerSize) {
  11538. throw new Error('JPX Error: Invalid box field size');
  11539. }
  11540. var dataLength = lbox - headerSize;
  11541. var jumpDataLength = true;
  11542. switch (tbox) {
  11543. case 0x6A703268: // 'jp2h'
  11544. jumpDataLength = false; // parsing child boxes
  11545. break;
  11546. case 0x636F6C72: // 'colr'
  11547. // Colorspaces are not used, the CS from the PDF is used.
  11548. var method = data[position];
  11549. if (method === 1) {
  11550. // enumerated colorspace
  11551. var colorspace = readUint32(data, position + 3);
  11552. switch (colorspace) {
  11553. case 16: // this indicates a sRGB colorspace
  11554. case 17: // this indicates a grayscale colorspace
  11555. case 18: // this indicates a YUV colorspace
  11556. break;
  11557. default:
  11558. warn('Unknown colorspace ' + colorspace);
  11559. break;
  11560. }
  11561. } else if (method === 2) {
  11562. info('ICC profile not supported');
  11563. }
  11564. break;
  11565. case 0x6A703263: // 'jp2c'
  11566. this.parseCodestream(data, position, position + dataLength);
  11567. break;
  11568. case 0x6A502020: // 'jP\024\024'
  11569. if (0x0d0a870a !== readUint32(data, position)) {
  11570. warn('Invalid JP2 signature');
  11571. }
  11572. break;
  11573. // The following header types are valid but currently not used:
  11574. case 0x6A501A1A: // 'jP\032\032'
  11575. case 0x66747970: // 'ftyp'
  11576. case 0x72726571: // 'rreq'
  11577. case 0x72657320: // 'res '
  11578. case 0x69686472: // 'ihdr'
  11579. break;
  11580. default:
  11581. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11582. (tbox >> 16) & 0xFF,
  11583. (tbox >> 8) & 0xFF,
  11584. tbox & 0xFF);
  11585. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11586. break;
  11587. }
  11588. if (jumpDataLength) {
  11589. position += dataLength;
  11590. }
  11591. }
  11592. },
  11593. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11594. var newByte = stream.getByte();
  11595. while (newByte >= 0) {
  11596. var oldByte = newByte;
  11597. newByte = stream.getByte();
  11598. var code = (oldByte << 8) | newByte;
  11599. // Image and tile size (SIZ)
  11600. if (code === 0xFF51) {
  11601. stream.skip(4);
  11602. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11603. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11604. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11605. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11606. stream.skip(16);
  11607. var Csiz = stream.getUint16(); // Byte 36
  11608. this.width = Xsiz - XOsiz;
  11609. this.height = Ysiz - YOsiz;
  11610. this.componentsCount = Csiz;
  11611. // Results are always returned as Uint8Arrays
  11612. this.bitsPerComponent = 8;
  11613. return;
  11614. }
  11615. }
  11616. throw new Error('JPX Error: No size marker found in JPX stream');
  11617. },
  11618. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11619. var context = {};
  11620. try {
  11621. var doNotRecover = false;
  11622. var position = start;
  11623. while (position + 1 < end) {
  11624. var code = readUint16(data, position);
  11625. position += 2;
  11626. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11627. switch (code) {
  11628. case 0xFF4F: // Start of codestream (SOC)
  11629. context.mainHeader = true;
  11630. break;
  11631. case 0xFFD9: // End of codestream (EOC)
  11632. break;
  11633. case 0xFF51: // Image and tile size (SIZ)
  11634. length = readUint16(data, position);
  11635. var siz = {};
  11636. siz.Xsiz = readUint32(data, position + 4);
  11637. siz.Ysiz = readUint32(data, position + 8);
  11638. siz.XOsiz = readUint32(data, position + 12);
  11639. siz.YOsiz = readUint32(data, position + 16);
  11640. siz.XTsiz = readUint32(data, position + 20);
  11641. siz.YTsiz = readUint32(data, position + 24);
  11642. siz.XTOsiz = readUint32(data, position + 28);
  11643. siz.YTOsiz = readUint32(data, position + 32);
  11644. var componentsCount = readUint16(data, position + 36);
  11645. siz.Csiz = componentsCount;
  11646. var components = [];
  11647. j = position + 38;
  11648. for (var i = 0; i < componentsCount; i++) {
  11649. var component = {
  11650. precision: (data[j] & 0x7F) + 1,
  11651. isSigned: !!(data[j] & 0x80),
  11652. XRsiz: data[j + 1],
  11653. YRsiz: data[j + 1]
  11654. };
  11655. calculateComponentDimensions(component, siz);
  11656. components.push(component);
  11657. }
  11658. context.SIZ = siz;
  11659. context.components = components;
  11660. calculateTileGrids(context, components);
  11661. context.QCC = [];
  11662. context.COC = [];
  11663. break;
  11664. case 0xFF5C: // Quantization default (QCD)
  11665. length = readUint16(data, position);
  11666. var qcd = {};
  11667. j = position + 2;
  11668. sqcd = data[j++];
  11669. switch (sqcd & 0x1F) {
  11670. case 0:
  11671. spqcdSize = 8;
  11672. scalarExpounded = true;
  11673. break;
  11674. case 1:
  11675. spqcdSize = 16;
  11676. scalarExpounded = false;
  11677. break;
  11678. case 2:
  11679. spqcdSize = 16;
  11680. scalarExpounded = true;
  11681. break;
  11682. default:
  11683. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  11684. }
  11685. qcd.noQuantization = (spqcdSize === 8);
  11686. qcd.scalarExpounded = scalarExpounded;
  11687. qcd.guardBits = sqcd >> 5;
  11688. spqcds = [];
  11689. while (j < length + position) {
  11690. var spqcd = {};
  11691. if (spqcdSize === 8) {
  11692. spqcd.epsilon = data[j++] >> 3;
  11693. spqcd.mu = 0;
  11694. } else {
  11695. spqcd.epsilon = data[j] >> 3;
  11696. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11697. j += 2;
  11698. }
  11699. spqcds.push(spqcd);
  11700. }
  11701. qcd.SPqcds = spqcds;
  11702. if (context.mainHeader) {
  11703. context.QCD = qcd;
  11704. } else {
  11705. context.currentTile.QCD = qcd;
  11706. context.currentTile.QCC = [];
  11707. }
  11708. break;
  11709. case 0xFF5D: // Quantization component (QCC)
  11710. length = readUint16(data, position);
  11711. var qcc = {};
  11712. j = position + 2;
  11713. var cqcc;
  11714. if (context.SIZ.Csiz < 257) {
  11715. cqcc = data[j++];
  11716. } else {
  11717. cqcc = readUint16(data, j);
  11718. j += 2;
  11719. }
  11720. sqcd = data[j++];
  11721. switch (sqcd & 0x1F) {
  11722. case 0:
  11723. spqcdSize = 8;
  11724. scalarExpounded = true;
  11725. break;
  11726. case 1:
  11727. spqcdSize = 16;
  11728. scalarExpounded = false;
  11729. break;
  11730. case 2:
  11731. spqcdSize = 16;
  11732. scalarExpounded = true;
  11733. break;
  11734. default:
  11735. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  11736. }
  11737. qcc.noQuantization = (spqcdSize === 8);
  11738. qcc.scalarExpounded = scalarExpounded;
  11739. qcc.guardBits = sqcd >> 5;
  11740. spqcds = [];
  11741. while (j < (length + position)) {
  11742. spqcd = {};
  11743. if (spqcdSize === 8) {
  11744. spqcd.epsilon = data[j++] >> 3;
  11745. spqcd.mu = 0;
  11746. } else {
  11747. spqcd.epsilon = data[j] >> 3;
  11748. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11749. j += 2;
  11750. }
  11751. spqcds.push(spqcd);
  11752. }
  11753. qcc.SPqcds = spqcds;
  11754. if (context.mainHeader) {
  11755. context.QCC[cqcc] = qcc;
  11756. } else {
  11757. context.currentTile.QCC[cqcc] = qcc;
  11758. }
  11759. break;
  11760. case 0xFF52: // Coding style default (COD)
  11761. length = readUint16(data, position);
  11762. var cod = {};
  11763. j = position + 2;
  11764. var scod = data[j++];
  11765. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11766. cod.sopMarkerUsed = !!(scod & 2);
  11767. cod.ephMarkerUsed = !!(scod & 4);
  11768. cod.progressionOrder = data[j++];
  11769. cod.layersCount = readUint16(data, j);
  11770. j += 2;
  11771. cod.multipleComponentTransform = data[j++];
  11772. cod.decompositionLevelsCount = data[j++];
  11773. cod.xcb = (data[j++] & 0xF) + 2;
  11774. cod.ycb = (data[j++] & 0xF) + 2;
  11775. var blockStyle = data[j++];
  11776. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11777. cod.resetContextProbabilities = !!(blockStyle & 2);
  11778. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11779. cod.verticalyStripe = !!(blockStyle & 8);
  11780. cod.predictableTermination = !!(blockStyle & 16);
  11781. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11782. cod.reversibleTransformation = data[j++];
  11783. if (cod.entropyCoderWithCustomPrecincts) {
  11784. var precinctsSizes = [];
  11785. while (j < length + position) {
  11786. var precinctsSize = data[j++];
  11787. precinctsSizes.push({
  11788. PPx: precinctsSize & 0xF,
  11789. PPy: precinctsSize >> 4
  11790. });
  11791. }
  11792. cod.precinctsSizes = precinctsSizes;
  11793. }
  11794. var unsupported = [];
  11795. if (cod.selectiveArithmeticCodingBypass) {
  11796. unsupported.push('selectiveArithmeticCodingBypass');
  11797. }
  11798. if (cod.resetContextProbabilities) {
  11799. unsupported.push('resetContextProbabilities');
  11800. }
  11801. if (cod.terminationOnEachCodingPass) {
  11802. unsupported.push('terminationOnEachCodingPass');
  11803. }
  11804. if (cod.verticalyStripe) {
  11805. unsupported.push('verticalyStripe');
  11806. }
  11807. if (cod.predictableTermination) {
  11808. unsupported.push('predictableTermination');
  11809. }
  11810. if (unsupported.length > 0) {
  11811. doNotRecover = true;
  11812. throw new Error('JPX Error: Unsupported COD options (' +
  11813. unsupported.join(', ') + ')');
  11814. }
  11815. if (context.mainHeader) {
  11816. context.COD = cod;
  11817. } else {
  11818. context.currentTile.COD = cod;
  11819. context.currentTile.COC = [];
  11820. }
  11821. break;
  11822. case 0xFF90: // Start of tile-part (SOT)
  11823. length = readUint16(data, position);
  11824. tile = {};
  11825. tile.index = readUint16(data, position + 2);
  11826. tile.length = readUint32(data, position + 4);
  11827. tile.dataEnd = tile.length + position - 2;
  11828. tile.partIndex = data[position + 8];
  11829. tile.partsCount = data[position + 9];
  11830. context.mainHeader = false;
  11831. if (tile.partIndex === 0) {
  11832. // reset component specific settings
  11833. tile.COD = context.COD;
  11834. tile.COC = context.COC.slice(0); // clone of the global COC
  11835. tile.QCD = context.QCD;
  11836. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11837. }
  11838. context.currentTile = tile;
  11839. break;
  11840. case 0xFF93: // Start of data (SOD)
  11841. tile = context.currentTile;
  11842. if (tile.partIndex === 0) {
  11843. initializeTile(context, tile.index);
  11844. buildPackets(context);
  11845. }
  11846. // moving to the end of the data
  11847. length = tile.dataEnd - position;
  11848. parseTilePackets(context, data, position, length);
  11849. break;
  11850. case 0xFF55: // Tile-part lengths, main header (TLM)
  11851. case 0xFF57: // Packet length, main header (PLM)
  11852. case 0xFF58: // Packet length, tile-part header (PLT)
  11853. case 0xFF64: // Comment (COM)
  11854. length = readUint16(data, position);
  11855. // skipping content
  11856. break;
  11857. case 0xFF53: // Coding style component (COC)
  11858. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  11859. 'not implemented');
  11860. default:
  11861. throw new Error('JPX Error: Unknown codestream code: ' +
  11862. code.toString(16));
  11863. }
  11864. position += length;
  11865. }
  11866. } catch (e) {
  11867. if (doNotRecover || this.failOnCorruptedImage) {
  11868. throw e;
  11869. } else {
  11870. warn('Trying to recover from ' + e.message);
  11871. }
  11872. }
  11873. this.tiles = transformComponents(context);
  11874. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11875. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11876. this.componentsCount = context.SIZ.Csiz;
  11877. }
  11878. };
  11879. function calculateComponentDimensions(component, siz) {
  11880. // Section B.2 Component mapping
  11881. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11882. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11883. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11884. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11885. component.width = component.x1 - component.x0;
  11886. component.height = component.y1 - component.y0;
  11887. }
  11888. function calculateTileGrids(context, components) {
  11889. var siz = context.SIZ;
  11890. // Section B.3 Division into tile and tile-components
  11891. var tile, tiles = [];
  11892. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  11893. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  11894. for (var q = 0; q < numYtiles; q++) {
  11895. for (var p = 0; p < numXtiles; p++) {
  11896. tile = {};
  11897. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  11898. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  11899. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  11900. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  11901. tile.width = tile.tx1 - tile.tx0;
  11902. tile.height = tile.ty1 - tile.ty0;
  11903. tile.components = [];
  11904. tiles.push(tile);
  11905. }
  11906. }
  11907. context.tiles = tiles;
  11908. var componentsCount = siz.Csiz;
  11909. for (var i = 0, ii = componentsCount; i < ii; i++) {
  11910. var component = components[i];
  11911. for (var j = 0, jj = tiles.length; j < jj; j++) {
  11912. var tileComponent = {};
  11913. tile = tiles[j];
  11914. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  11915. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  11916. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  11917. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  11918. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  11919. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  11920. tile.components[i] = tileComponent;
  11921. }
  11922. }
  11923. }
  11924. function getBlocksDimensions(context, component, r) {
  11925. var codOrCoc = component.codingStyleParameters;
  11926. var result = {};
  11927. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  11928. result.PPx = 15;
  11929. result.PPy = 15;
  11930. } else {
  11931. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  11932. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  11933. }
  11934. // calculate codeblock size as described in section B.7
  11935. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  11936. Math.min(codOrCoc.xcb, result.PPx));
  11937. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  11938. Math.min(codOrCoc.ycb, result.PPy));
  11939. return result;
  11940. }
  11941. function buildPrecincts(context, resolution, dimensions) {
  11942. // Section B.6 Division resolution to precincts
  11943. var precinctWidth = 1 << dimensions.PPx;
  11944. var precinctHeight = 1 << dimensions.PPy;
  11945. // Jasper introduces codeblock groups for mapping each subband codeblocks
  11946. // to precincts. Precinct partition divides a resolution according to width
  11947. // and height parameters. The subband that belongs to the resolution level
  11948. // has a different size than the level, unless it is the zero resolution.
  11949. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  11950. // The precinct partitioning for a particular subband is derived from a
  11951. // partitioning of its parent LL band (i.e., the LL band at the next higher
  11952. // resolution level)... The LL band associated with each resolution level is
  11953. // divided into precincts... Each of the resulting precinct regions is then
  11954. // mapped into its child subbands (if any) at the next lower resolution
  11955. // level. This is accomplished by using the coordinate transformation
  11956. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  11957. // coordinates of a point in the LL band and child subband, respectively.
  11958. var isZeroRes = resolution.resLevel === 0;
  11959. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  11960. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  11961. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  11962. Math.ceil(resolution.trx1 / precinctWidth) -
  11963. Math.floor(resolution.trx0 / precinctWidth) : 0);
  11964. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  11965. Math.ceil(resolution.try1 / precinctHeight) -
  11966. Math.floor(resolution.try0 / precinctHeight) : 0);
  11967. var numprecincts = numprecinctswide * numprecinctshigh;
  11968. resolution.precinctParameters = {
  11969. precinctWidth: precinctWidth,
  11970. precinctHeight: precinctHeight,
  11971. numprecinctswide: numprecinctswide,
  11972. numprecinctshigh: numprecinctshigh,
  11973. numprecincts: numprecincts,
  11974. precinctWidthInSubband: precinctWidthInSubband,
  11975. precinctHeightInSubband: precinctHeightInSubband
  11976. };
  11977. }
  11978. function buildCodeblocks(context, subband, dimensions) {
  11979. // Section B.7 Division sub-band into code-blocks
  11980. var xcb_ = dimensions.xcb_;
  11981. var ycb_ = dimensions.ycb_;
  11982. var codeblockWidth = 1 << xcb_;
  11983. var codeblockHeight = 1 << ycb_;
  11984. var cbx0 = subband.tbx0 >> xcb_;
  11985. var cby0 = subband.tby0 >> ycb_;
  11986. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  11987. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  11988. var precinctParameters = subband.resolution.precinctParameters;
  11989. var codeblocks = [];
  11990. var precincts = [];
  11991. var i, j, codeblock, precinctNumber;
  11992. for (j = cby0; j < cby1; j++) {
  11993. for (i = cbx0; i < cbx1; i++) {
  11994. codeblock = {
  11995. cbx: i,
  11996. cby: j,
  11997. tbx0: codeblockWidth * i,
  11998. tby0: codeblockHeight * j,
  11999. tbx1: codeblockWidth * (i + 1),
  12000. tby1: codeblockHeight * (j + 1)
  12001. };
  12002. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12003. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12004. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12005. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12006. // Calculate precinct number for this codeblock, codeblock position
  12007. // should be relative to its subband, use actual dimension and position
  12008. // See comment about codeblock group width and height
  12009. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12010. precinctParameters.precinctWidthInSubband);
  12011. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12012. precinctParameters.precinctHeightInSubband);
  12013. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12014. codeblock.precinctNumber = precinctNumber;
  12015. codeblock.subbandType = subband.type;
  12016. codeblock.Lblock = 3;
  12017. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12018. codeblock.tby1_ <= codeblock.tby0_) {
  12019. continue;
  12020. }
  12021. codeblocks.push(codeblock);
  12022. // building precinct for the sub-band
  12023. var precinct = precincts[precinctNumber];
  12024. if (precinct !== undefined) {
  12025. if (i < precinct.cbxMin) {
  12026. precinct.cbxMin = i;
  12027. } else if (i > precinct.cbxMax) {
  12028. precinct.cbxMax = i;
  12029. }
  12030. if (j < precinct.cbyMin) {
  12031. precinct.cbxMin = j;
  12032. } else if (j > precinct.cbyMax) {
  12033. precinct.cbyMax = j;
  12034. }
  12035. } else {
  12036. precincts[precinctNumber] = precinct = {
  12037. cbxMin: i,
  12038. cbyMin: j,
  12039. cbxMax: i,
  12040. cbyMax: j
  12041. };
  12042. }
  12043. codeblock.precinct = precinct;
  12044. }
  12045. }
  12046. subband.codeblockParameters = {
  12047. codeblockWidth: xcb_,
  12048. codeblockHeight: ycb_,
  12049. numcodeblockwide: cbx1 - cbx0 + 1,
  12050. numcodeblockhigh: cby1 - cby0 + 1
  12051. };
  12052. subband.codeblocks = codeblocks;
  12053. subband.precincts = precincts;
  12054. }
  12055. function createPacket(resolution, precinctNumber, layerNumber) {
  12056. var precinctCodeblocks = [];
  12057. // Section B.10.8 Order of info in packet
  12058. var subbands = resolution.subbands;
  12059. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12060. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12061. var subband = subbands[i];
  12062. var codeblocks = subband.codeblocks;
  12063. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12064. var codeblock = codeblocks[j];
  12065. if (codeblock.precinctNumber !== precinctNumber) {
  12066. continue;
  12067. }
  12068. precinctCodeblocks.push(codeblock);
  12069. }
  12070. }
  12071. return {
  12072. layerNumber: layerNumber,
  12073. codeblocks: precinctCodeblocks
  12074. };
  12075. }
  12076. function LayerResolutionComponentPositionIterator(context) {
  12077. var siz = context.SIZ;
  12078. var tileIndex = context.currentTile.index;
  12079. var tile = context.tiles[tileIndex];
  12080. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12081. var componentsCount = siz.Csiz;
  12082. var maxDecompositionLevelsCount = 0;
  12083. for (var q = 0; q < componentsCount; q++) {
  12084. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12085. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12086. }
  12087. var l = 0, r = 0, i = 0, k = 0;
  12088. this.nextPacket = function JpxImage_nextPacket() {
  12089. // Section B.12.1.1 Layer-resolution-component-position
  12090. for (; l < layersCount; l++) {
  12091. for (; r <= maxDecompositionLevelsCount; r++) {
  12092. for (; i < componentsCount; i++) {
  12093. var component = tile.components[i];
  12094. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12095. continue;
  12096. }
  12097. var resolution = component.resolutions[r];
  12098. var numprecincts = resolution.precinctParameters.numprecincts;
  12099. for (; k < numprecincts;) {
  12100. var packet = createPacket(resolution, k, l);
  12101. k++;
  12102. return packet;
  12103. }
  12104. k = 0;
  12105. }
  12106. i = 0;
  12107. }
  12108. r = 0;
  12109. }
  12110. throw new Error('JPX Error: Out of packets');
  12111. };
  12112. }
  12113. function ResolutionLayerComponentPositionIterator(context) {
  12114. var siz = context.SIZ;
  12115. var tileIndex = context.currentTile.index;
  12116. var tile = context.tiles[tileIndex];
  12117. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12118. var componentsCount = siz.Csiz;
  12119. var maxDecompositionLevelsCount = 0;
  12120. for (var q = 0; q < componentsCount; q++) {
  12121. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12122. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12123. }
  12124. var r = 0, l = 0, i = 0, k = 0;
  12125. this.nextPacket = function JpxImage_nextPacket() {
  12126. // Section B.12.1.2 Resolution-layer-component-position
  12127. for (; r <= maxDecompositionLevelsCount; r++) {
  12128. for (; l < layersCount; l++) {
  12129. for (; i < componentsCount; i++) {
  12130. var component = tile.components[i];
  12131. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12132. continue;
  12133. }
  12134. var resolution = component.resolutions[r];
  12135. var numprecincts = resolution.precinctParameters.numprecincts;
  12136. for (; k < numprecincts;) {
  12137. var packet = createPacket(resolution, k, l);
  12138. k++;
  12139. return packet;
  12140. }
  12141. k = 0;
  12142. }
  12143. i = 0;
  12144. }
  12145. l = 0;
  12146. }
  12147. throw new Error('JPX Error: Out of packets');
  12148. };
  12149. }
  12150. function ResolutionPositionComponentLayerIterator(context) {
  12151. var siz = context.SIZ;
  12152. var tileIndex = context.currentTile.index;
  12153. var tile = context.tiles[tileIndex];
  12154. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12155. var componentsCount = siz.Csiz;
  12156. var l, r, c, p;
  12157. var maxDecompositionLevelsCount = 0;
  12158. for (c = 0; c < componentsCount; c++) {
  12159. var component = tile.components[c];
  12160. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12161. component.codingStyleParameters.decompositionLevelsCount);
  12162. }
  12163. var maxNumPrecinctsInLevel = new Int32Array(
  12164. maxDecompositionLevelsCount + 1);
  12165. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12166. var maxNumPrecincts = 0;
  12167. for (c = 0; c < componentsCount; ++c) {
  12168. var resolutions = tile.components[c].resolutions;
  12169. if (r < resolutions.length) {
  12170. maxNumPrecincts = Math.max(maxNumPrecincts,
  12171. resolutions[r].precinctParameters.numprecincts);
  12172. }
  12173. }
  12174. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12175. }
  12176. l = 0;
  12177. r = 0;
  12178. c = 0;
  12179. p = 0;
  12180. this.nextPacket = function JpxImage_nextPacket() {
  12181. // Section B.12.1.3 Resolution-position-component-layer
  12182. for (; r <= maxDecompositionLevelsCount; r++) {
  12183. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12184. for (; c < componentsCount; c++) {
  12185. var component = tile.components[c];
  12186. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12187. continue;
  12188. }
  12189. var resolution = component.resolutions[r];
  12190. var numprecincts = resolution.precinctParameters.numprecincts;
  12191. if (p >= numprecincts) {
  12192. continue;
  12193. }
  12194. for (; l < layersCount;) {
  12195. var packet = createPacket(resolution, p, l);
  12196. l++;
  12197. return packet;
  12198. }
  12199. l = 0;
  12200. }
  12201. c = 0;
  12202. }
  12203. p = 0;
  12204. }
  12205. throw new Error('JPX Error: Out of packets');
  12206. };
  12207. }
  12208. function PositionComponentResolutionLayerIterator(context) {
  12209. var siz = context.SIZ;
  12210. var tileIndex = context.currentTile.index;
  12211. var tile = context.tiles[tileIndex];
  12212. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12213. var componentsCount = siz.Csiz;
  12214. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12215. var precinctsIterationSizes = precinctsSizes;
  12216. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12217. this.nextPacket = function JpxImage_nextPacket() {
  12218. // Section B.12.1.4 Position-component-resolution-layer
  12219. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12220. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12221. for (; c < componentsCount; c++) {
  12222. var component = tile.components[c];
  12223. var decompositionLevelsCount =
  12224. component.codingStyleParameters.decompositionLevelsCount;
  12225. for (; r <= decompositionLevelsCount; r++) {
  12226. var resolution = component.resolutions[r];
  12227. var sizeInImageScale =
  12228. precinctsSizes.components[c].resolutions[r];
  12229. var k = getPrecinctIndexIfExist(
  12230. px,
  12231. py,
  12232. sizeInImageScale,
  12233. precinctsIterationSizes,
  12234. resolution);
  12235. if (k === null) {
  12236. continue;
  12237. }
  12238. for (; l < layersCount;) {
  12239. var packet = createPacket(resolution, k, l);
  12240. l++;
  12241. return packet;
  12242. }
  12243. l = 0;
  12244. }
  12245. r = 0;
  12246. }
  12247. c = 0;
  12248. }
  12249. px = 0;
  12250. }
  12251. throw new Error('JPX Error: Out of packets');
  12252. };
  12253. }
  12254. function ComponentPositionResolutionLayerIterator(context) {
  12255. var siz = context.SIZ;
  12256. var tileIndex = context.currentTile.index;
  12257. var tile = context.tiles[tileIndex];
  12258. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12259. var componentsCount = siz.Csiz;
  12260. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12261. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12262. this.nextPacket = function JpxImage_nextPacket() {
  12263. // Section B.12.1.5 Component-position-resolution-layer
  12264. for (; c < componentsCount; ++c) {
  12265. var component = tile.components[c];
  12266. var precinctsIterationSizes = precinctsSizes.components[c];
  12267. var decompositionLevelsCount =
  12268. component.codingStyleParameters.decompositionLevelsCount;
  12269. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12270. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12271. for (; r <= decompositionLevelsCount; r++) {
  12272. var resolution = component.resolutions[r];
  12273. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12274. var k = getPrecinctIndexIfExist(
  12275. px,
  12276. py,
  12277. sizeInImageScale,
  12278. precinctsIterationSizes,
  12279. resolution);
  12280. if (k === null) {
  12281. continue;
  12282. }
  12283. for (; l < layersCount;) {
  12284. var packet = createPacket(resolution, k, l);
  12285. l++;
  12286. return packet;
  12287. }
  12288. l = 0;
  12289. }
  12290. r = 0;
  12291. }
  12292. px = 0;
  12293. }
  12294. py = 0;
  12295. }
  12296. throw new Error('JPX Error: Out of packets');
  12297. };
  12298. }
  12299. function getPrecinctIndexIfExist(
  12300. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12301. var posX = pxIndex * precinctIterationSizes.minWidth;
  12302. var posY = pyIndex * precinctIterationSizes.minHeight;
  12303. if (posX % sizeInImageScale.width !== 0 ||
  12304. posY % sizeInImageScale.height !== 0) {
  12305. return null;
  12306. }
  12307. var startPrecinctRowIndex =
  12308. (posY / sizeInImageScale.width) *
  12309. resolution.precinctParameters.numprecinctswide;
  12310. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12311. }
  12312. function getPrecinctSizesInImageScale(tile) {
  12313. var componentsCount = tile.components.length;
  12314. var minWidth = Number.MAX_VALUE;
  12315. var minHeight = Number.MAX_VALUE;
  12316. var maxNumWide = 0;
  12317. var maxNumHigh = 0;
  12318. var sizePerComponent = new Array(componentsCount);
  12319. for (var c = 0; c < componentsCount; c++) {
  12320. var component = tile.components[c];
  12321. var decompositionLevelsCount =
  12322. component.codingStyleParameters.decompositionLevelsCount;
  12323. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12324. var minWidthCurrentComponent = Number.MAX_VALUE;
  12325. var minHeightCurrentComponent = Number.MAX_VALUE;
  12326. var maxNumWideCurrentComponent = 0;
  12327. var maxNumHighCurrentComponent = 0;
  12328. var scale = 1;
  12329. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12330. var resolution = component.resolutions[r];
  12331. var widthCurrentResolution =
  12332. scale * resolution.precinctParameters.precinctWidth;
  12333. var heightCurrentResolution =
  12334. scale * resolution.precinctParameters.precinctHeight;
  12335. minWidthCurrentComponent = Math.min(
  12336. minWidthCurrentComponent,
  12337. widthCurrentResolution);
  12338. minHeightCurrentComponent = Math.min(
  12339. minHeightCurrentComponent,
  12340. heightCurrentResolution);
  12341. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12342. resolution.precinctParameters.numprecinctswide);
  12343. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12344. resolution.precinctParameters.numprecinctshigh);
  12345. sizePerResolution[r] = {
  12346. width: widthCurrentResolution,
  12347. height: heightCurrentResolution
  12348. };
  12349. scale <<= 1;
  12350. }
  12351. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12352. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12353. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12354. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12355. sizePerComponent[c] = {
  12356. resolutions: sizePerResolution,
  12357. minWidth: minWidthCurrentComponent,
  12358. minHeight: minHeightCurrentComponent,
  12359. maxNumWide: maxNumWideCurrentComponent,
  12360. maxNumHigh: maxNumHighCurrentComponent
  12361. };
  12362. }
  12363. return {
  12364. components: sizePerComponent,
  12365. minWidth: minWidth,
  12366. minHeight: minHeight,
  12367. maxNumWide: maxNumWide,
  12368. maxNumHigh: maxNumHigh
  12369. };
  12370. }
  12371. function buildPackets(context) {
  12372. var siz = context.SIZ;
  12373. var tileIndex = context.currentTile.index;
  12374. var tile = context.tiles[tileIndex];
  12375. var componentsCount = siz.Csiz;
  12376. // Creating resolutions and sub-bands for each component
  12377. for (var c = 0; c < componentsCount; c++) {
  12378. var component = tile.components[c];
  12379. var decompositionLevelsCount =
  12380. component.codingStyleParameters.decompositionLevelsCount;
  12381. // Section B.5 Resolution levels and sub-bands
  12382. var resolutions = [];
  12383. var subbands = [];
  12384. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12385. var blocksDimensions = getBlocksDimensions(context, component, r);
  12386. var resolution = {};
  12387. var scale = 1 << (decompositionLevelsCount - r);
  12388. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12389. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12390. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12391. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12392. resolution.resLevel = r;
  12393. buildPrecincts(context, resolution, blocksDimensions);
  12394. resolutions.push(resolution);
  12395. var subband;
  12396. if (r === 0) {
  12397. // one sub-band (LL) with last decomposition
  12398. subband = {};
  12399. subband.type = 'LL';
  12400. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12401. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12402. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12403. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12404. subband.resolution = resolution;
  12405. buildCodeblocks(context, subband, blocksDimensions);
  12406. subbands.push(subband);
  12407. resolution.subbands = [subband];
  12408. } else {
  12409. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12410. var resolutionSubbands = [];
  12411. // three sub-bands (HL, LH and HH) with rest of decompositions
  12412. subband = {};
  12413. subband.type = 'HL';
  12414. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12415. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12416. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12417. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12418. subband.resolution = resolution;
  12419. buildCodeblocks(context, subband, blocksDimensions);
  12420. subbands.push(subband);
  12421. resolutionSubbands.push(subband);
  12422. subband = {};
  12423. subband.type = 'LH';
  12424. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12425. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12426. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12427. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12428. subband.resolution = resolution;
  12429. buildCodeblocks(context, subband, blocksDimensions);
  12430. subbands.push(subband);
  12431. resolutionSubbands.push(subband);
  12432. subband = {};
  12433. subband.type = 'HH';
  12434. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12435. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12436. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12437. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12438. subband.resolution = resolution;
  12439. buildCodeblocks(context, subband, blocksDimensions);
  12440. subbands.push(subband);
  12441. resolutionSubbands.push(subband);
  12442. resolution.subbands = resolutionSubbands;
  12443. }
  12444. }
  12445. component.resolutions = resolutions;
  12446. component.subbands = subbands;
  12447. }
  12448. // Generate the packets sequence
  12449. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12450. switch (progressionOrder) {
  12451. case 0:
  12452. tile.packetsIterator =
  12453. new LayerResolutionComponentPositionIterator(context);
  12454. break;
  12455. case 1:
  12456. tile.packetsIterator =
  12457. new ResolutionLayerComponentPositionIterator(context);
  12458. break;
  12459. case 2:
  12460. tile.packetsIterator =
  12461. new ResolutionPositionComponentLayerIterator(context);
  12462. break;
  12463. case 3:
  12464. tile.packetsIterator =
  12465. new PositionComponentResolutionLayerIterator(context);
  12466. break;
  12467. case 4:
  12468. tile.packetsIterator =
  12469. new ComponentPositionResolutionLayerIterator(context);
  12470. break;
  12471. default:
  12472. throw new Error('JPX Error: Unsupported progression order ' +
  12473. progressionOrder);
  12474. }
  12475. }
  12476. function parseTilePackets(context, data, offset, dataLength) {
  12477. var position = 0;
  12478. var buffer, bufferSize = 0, skipNextBit = false;
  12479. function readBits(count) {
  12480. while (bufferSize < count) {
  12481. var b = data[offset + position];
  12482. position++;
  12483. if (skipNextBit) {
  12484. buffer = (buffer << 7) | b;
  12485. bufferSize += 7;
  12486. skipNextBit = false;
  12487. } else {
  12488. buffer = (buffer << 8) | b;
  12489. bufferSize += 8;
  12490. }
  12491. if (b === 0xFF) {
  12492. skipNextBit = true;
  12493. }
  12494. }
  12495. bufferSize -= count;
  12496. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12497. }
  12498. function skipMarkerIfEqual(value) {
  12499. if (data[offset + position - 1] === 0xFF &&
  12500. data[offset + position] === value) {
  12501. skipBytes(1);
  12502. return true;
  12503. } else if (data[offset + position] === 0xFF &&
  12504. data[offset + position + 1] === value) {
  12505. skipBytes(2);
  12506. return true;
  12507. }
  12508. return false;
  12509. }
  12510. function skipBytes(count) {
  12511. position += count;
  12512. }
  12513. function alignToByte() {
  12514. bufferSize = 0;
  12515. if (skipNextBit) {
  12516. position++;
  12517. skipNextBit = false;
  12518. }
  12519. }
  12520. function readCodingpasses() {
  12521. if (readBits(1) === 0) {
  12522. return 1;
  12523. }
  12524. if (readBits(1) === 0) {
  12525. return 2;
  12526. }
  12527. var value = readBits(2);
  12528. if (value < 3) {
  12529. return value + 3;
  12530. }
  12531. value = readBits(5);
  12532. if (value < 31) {
  12533. return value + 6;
  12534. }
  12535. value = readBits(7);
  12536. return value + 37;
  12537. }
  12538. var tileIndex = context.currentTile.index;
  12539. var tile = context.tiles[tileIndex];
  12540. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12541. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12542. var packetsIterator = tile.packetsIterator;
  12543. while (position < dataLength) {
  12544. alignToByte();
  12545. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12546. // Skip also marker segment length and packet sequence ID
  12547. skipBytes(4);
  12548. }
  12549. var packet = packetsIterator.nextPacket();
  12550. if (!readBits(1)) {
  12551. continue;
  12552. }
  12553. var layerNumber = packet.layerNumber;
  12554. var queue = [], codeblock;
  12555. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12556. codeblock = packet.codeblocks[i];
  12557. var precinct = codeblock.precinct;
  12558. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12559. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12560. var codeblockIncluded = false;
  12561. var firstTimeInclusion = false;
  12562. var valueReady;
  12563. if (codeblock['included'] !== undefined) {
  12564. codeblockIncluded = !!readBits(1);
  12565. } else {
  12566. // reading inclusion tree
  12567. precinct = codeblock.precinct;
  12568. var inclusionTree, zeroBitPlanesTree;
  12569. if (precinct['inclusionTree'] !== undefined) {
  12570. inclusionTree = precinct.inclusionTree;
  12571. } else {
  12572. // building inclusion and zero bit-planes trees
  12573. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12574. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12575. inclusionTree = new InclusionTree(width, height, layerNumber);
  12576. zeroBitPlanesTree = new TagTree(width, height);
  12577. precinct.inclusionTree = inclusionTree;
  12578. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12579. }
  12580. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12581. while (true) {
  12582. if (readBits(1)) {
  12583. valueReady = !inclusionTree.nextLevel();
  12584. if (valueReady) {
  12585. codeblock.included = true;
  12586. codeblockIncluded = firstTimeInclusion = true;
  12587. break;
  12588. }
  12589. } else {
  12590. inclusionTree.incrementValue(layerNumber);
  12591. break;
  12592. }
  12593. }
  12594. }
  12595. }
  12596. if (!codeblockIncluded) {
  12597. continue;
  12598. }
  12599. if (firstTimeInclusion) {
  12600. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12601. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12602. while (true) {
  12603. if (readBits(1)) {
  12604. valueReady = !zeroBitPlanesTree.nextLevel();
  12605. if (valueReady) {
  12606. break;
  12607. }
  12608. } else {
  12609. zeroBitPlanesTree.incrementValue();
  12610. }
  12611. }
  12612. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12613. }
  12614. var codingpasses = readCodingpasses();
  12615. while (readBits(1)) {
  12616. codeblock.Lblock++;
  12617. }
  12618. var codingpassesLog2 = log2(codingpasses);
  12619. // rounding down log2
  12620. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12621. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12622. var codedDataLength = readBits(bits);
  12623. queue.push({
  12624. codeblock: codeblock,
  12625. codingpasses: codingpasses,
  12626. dataLength: codedDataLength
  12627. });
  12628. }
  12629. alignToByte();
  12630. if (ephMarkerUsed) {
  12631. skipMarkerIfEqual(0x92);
  12632. }
  12633. while (queue.length > 0) {
  12634. var packetItem = queue.shift();
  12635. codeblock = packetItem.codeblock;
  12636. if (codeblock['data'] === undefined) {
  12637. codeblock.data = [];
  12638. }
  12639. codeblock.data.push({
  12640. data: data,
  12641. start: offset + position,
  12642. end: offset + position + packetItem.dataLength,
  12643. codingpasses: packetItem.codingpasses
  12644. });
  12645. position += packetItem.dataLength;
  12646. }
  12647. }
  12648. return position;
  12649. }
  12650. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12651. delta, mb, reversible, segmentationSymbolUsed) {
  12652. var x0 = subband.tbx0;
  12653. var y0 = subband.tby0;
  12654. var width = subband.tbx1 - subband.tbx0;
  12655. var codeblocks = subband.codeblocks;
  12656. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12657. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12658. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12659. var codeblock = codeblocks[i];
  12660. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12661. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12662. if (blockWidth === 0 || blockHeight === 0) {
  12663. continue;
  12664. }
  12665. if (codeblock['data'] === undefined) {
  12666. continue;
  12667. }
  12668. var bitModel, currentCodingpassType;
  12669. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12670. codeblock.zeroBitPlanes, mb);
  12671. currentCodingpassType = 2; // first bit plane starts from cleanup
  12672. // collect data
  12673. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12674. var j, jj, dataItem;
  12675. for (j = 0, jj = data.length; j < jj; j++) {
  12676. dataItem = data[j];
  12677. totalLength += dataItem.end - dataItem.start;
  12678. codingpasses += dataItem.codingpasses;
  12679. }
  12680. var encodedData = new Uint8Array(totalLength);
  12681. var position = 0;
  12682. for (j = 0, jj = data.length; j < jj; j++) {
  12683. dataItem = data[j];
  12684. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12685. encodedData.set(chunk, position);
  12686. position += chunk.length;
  12687. }
  12688. // decoding the item
  12689. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12690. bitModel.setDecoder(decoder);
  12691. for (j = 0; j < codingpasses; j++) {
  12692. switch (currentCodingpassType) {
  12693. case 0:
  12694. bitModel.runSignificancePropagationPass();
  12695. break;
  12696. case 1:
  12697. bitModel.runMagnitudeRefinementPass();
  12698. break;
  12699. case 2:
  12700. bitModel.runCleanupPass();
  12701. if (segmentationSymbolUsed) {
  12702. bitModel.checkSegmentationSymbol();
  12703. }
  12704. break;
  12705. }
  12706. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12707. }
  12708. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12709. var sign = bitModel.coefficentsSign;
  12710. var magnitude = bitModel.coefficentsMagnitude;
  12711. var bitsDecoded = bitModel.bitsDecoded;
  12712. var magnitudeCorrection = reversible ? 0 : 0.5;
  12713. var k, n, nb;
  12714. position = 0;
  12715. // Do the interleaving of Section F.3.3 here, so we do not need
  12716. // to copy later. LL level is not interleaved, just copied.
  12717. var interleave = (subband.type !== 'LL');
  12718. for (j = 0; j < blockHeight; j++) {
  12719. var row = (offset / width) | 0; // row in the non-interleaved subband
  12720. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12721. for (k = 0; k < blockWidth; k++) {
  12722. n = magnitude[position];
  12723. if (n !== 0) {
  12724. n = (n + magnitudeCorrection) * delta;
  12725. if (sign[position] !== 0) {
  12726. n = -n;
  12727. }
  12728. nb = bitsDecoded[position];
  12729. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12730. if (reversible && (nb >= mb)) {
  12731. coefficients[pos] = n;
  12732. } else {
  12733. coefficients[pos] = n * (1 << (mb - nb));
  12734. }
  12735. }
  12736. offset++;
  12737. position++;
  12738. }
  12739. offset += width - blockWidth;
  12740. }
  12741. }
  12742. }
  12743. function transformTile(context, tile, c) {
  12744. var component = tile.components[c];
  12745. var codingStyleParameters = component.codingStyleParameters;
  12746. var quantizationParameters = component.quantizationParameters;
  12747. var decompositionLevelsCount =
  12748. codingStyleParameters.decompositionLevelsCount;
  12749. var spqcds = quantizationParameters.SPqcds;
  12750. var scalarExpounded = quantizationParameters.scalarExpounded;
  12751. var guardBits = quantizationParameters.guardBits;
  12752. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12753. var precision = context.components[c].precision;
  12754. var reversible = codingStyleParameters.reversibleTransformation;
  12755. var transform = (reversible ? new ReversibleTransform() :
  12756. new IrreversibleTransform());
  12757. var subbandCoefficients = [];
  12758. var b = 0;
  12759. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12760. var resolution = component.resolutions[i];
  12761. var width = resolution.trx1 - resolution.trx0;
  12762. var height = resolution.try1 - resolution.try0;
  12763. // Allocate space for the whole sublevel.
  12764. var coefficients = new Float32Array(width * height);
  12765. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12766. var mu, epsilon;
  12767. if (!scalarExpounded) {
  12768. // formula E-5
  12769. mu = spqcds[0].mu;
  12770. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12771. } else {
  12772. mu = spqcds[b].mu;
  12773. epsilon = spqcds[b].epsilon;
  12774. b++;
  12775. }
  12776. var subband = resolution.subbands[j];
  12777. var gainLog2 = SubbandsGainLog2[subband.type];
  12778. // calculate quantization coefficient (Section E.1.1.1)
  12779. var delta = (reversible ? 1 :
  12780. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12781. var mb = (guardBits + epsilon - 1);
  12782. // In the first resolution level, copyCoefficients will fill the
  12783. // whole array with coefficients. In the succeeding passes,
  12784. // copyCoefficients will consecutively fill in the values that belong
  12785. // to the interleaved positions of the HL, LH, and HH coefficients.
  12786. // The LL coefficients will then be interleaved in Transform.iterate().
  12787. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12788. reversible, segmentationSymbolUsed);
  12789. }
  12790. subbandCoefficients.push({
  12791. width: width,
  12792. height: height,
  12793. items: coefficients
  12794. });
  12795. }
  12796. var result = transform.calculate(subbandCoefficients,
  12797. component.tcx0, component.tcy0);
  12798. return {
  12799. left: component.tcx0,
  12800. top: component.tcy0,
  12801. width: result.width,
  12802. height: result.height,
  12803. items: result.items
  12804. };
  12805. }
  12806. function transformComponents(context) {
  12807. var siz = context.SIZ;
  12808. var components = context.components;
  12809. var componentsCount = siz.Csiz;
  12810. var resultImages = [];
  12811. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12812. var tile = context.tiles[i];
  12813. var transformedTiles = [];
  12814. var c;
  12815. for (c = 0; c < componentsCount; c++) {
  12816. transformedTiles[c] = transformTile(context, tile, c);
  12817. }
  12818. var tile0 = transformedTiles[0];
  12819. var out = new Uint8Array(tile0.items.length * componentsCount);
  12820. var result = {
  12821. left: tile0.left,
  12822. top: tile0.top,
  12823. width: tile0.width,
  12824. height: tile0.height,
  12825. items: out
  12826. };
  12827. // Section G.2.2 Inverse multi component transform
  12828. var shift, offset, max, min, maxK;
  12829. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12830. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12831. var fourComponents = componentsCount === 4;
  12832. var y0items = transformedTiles[0].items;
  12833. var y1items = transformedTiles[1].items;
  12834. var y2items = transformedTiles[2].items;
  12835. var y3items = fourComponents ? transformedTiles[3].items : null;
  12836. // HACK: The multiple component transform formulas below assume that
  12837. // all components have the same precision. With this in mind, we
  12838. // compute shift and offset only once.
  12839. shift = components[0].precision - 8;
  12840. offset = (128 << shift) + 0.5;
  12841. max = 255 * (1 << shift);
  12842. maxK = max * 0.5;
  12843. min = -maxK;
  12844. var component0 = tile.components[0];
  12845. var alpha01 = componentsCount - 3;
  12846. jj = y0items.length;
  12847. if (!component0.codingStyleParameters.reversibleTransformation) {
  12848. // inverse irreversible multiple component transform
  12849. for (j = 0; j < jj; j++, pos += alpha01) {
  12850. y0 = y0items[j] + offset;
  12851. y1 = y1items[j];
  12852. y2 = y2items[j];
  12853. r = y0 + 1.402 * y2;
  12854. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12855. b = y0 + 1.772 * y1;
  12856. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12857. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12858. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12859. }
  12860. } else {
  12861. // inverse reversible multiple component transform
  12862. for (j = 0; j < jj; j++, pos += alpha01) {
  12863. y0 = y0items[j] + offset;
  12864. y1 = y1items[j];
  12865. y2 = y2items[j];
  12866. g = y0 - ((y2 + y1) >> 2);
  12867. r = g + y2;
  12868. b = g + y1;
  12869. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12870. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12871. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12872. }
  12873. }
  12874. if (fourComponents) {
  12875. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12876. k = y3items[j];
  12877. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12878. }
  12879. }
  12880. } else { // no multi-component transform
  12881. for (c = 0; c < componentsCount; c++) {
  12882. var items = transformedTiles[c].items;
  12883. shift = components[c].precision - 8;
  12884. offset = (128 << shift) + 0.5;
  12885. max = (127.5 * (1 << shift));
  12886. min = -max;
  12887. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12888. val = items[j];
  12889. out[pos] = val <= min ? 0 :
  12890. val >= max ? 255 : (val + offset) >> shift;
  12891. pos += componentsCount;
  12892. }
  12893. }
  12894. }
  12895. resultImages.push(result);
  12896. }
  12897. return resultImages;
  12898. }
  12899. function initializeTile(context, tileIndex) {
  12900. var siz = context.SIZ;
  12901. var componentsCount = siz.Csiz;
  12902. var tile = context.tiles[tileIndex];
  12903. for (var c = 0; c < componentsCount; c++) {
  12904. var component = tile.components[c];
  12905. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  12906. context.currentTile.QCC[c] : context.currentTile.QCD);
  12907. component.quantizationParameters = qcdOrQcc;
  12908. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  12909. context.currentTile.COC[c] : context.currentTile.COD);
  12910. component.codingStyleParameters = codOrCoc;
  12911. }
  12912. tile.codingStyleDefaultParameters = context.currentTile.COD;
  12913. }
  12914. // Section B.10.2 Tag trees
  12915. var TagTree = (function TagTreeClosure() {
  12916. function TagTree(width, height) {
  12917. var levelsLength = log2(Math.max(width, height)) + 1;
  12918. this.levels = [];
  12919. for (var i = 0; i < levelsLength; i++) {
  12920. var level = {
  12921. width: width,
  12922. height: height,
  12923. items: []
  12924. };
  12925. this.levels.push(level);
  12926. width = Math.ceil(width / 2);
  12927. height = Math.ceil(height / 2);
  12928. }
  12929. }
  12930. TagTree.prototype = {
  12931. reset: function TagTree_reset(i, j) {
  12932. var currentLevel = 0, value = 0, level;
  12933. while (currentLevel < this.levels.length) {
  12934. level = this.levels[currentLevel];
  12935. var index = i + j * level.width;
  12936. if (level.items[index] !== undefined) {
  12937. value = level.items[index];
  12938. break;
  12939. }
  12940. level.index = index;
  12941. i >>= 1;
  12942. j >>= 1;
  12943. currentLevel++;
  12944. }
  12945. currentLevel--;
  12946. level = this.levels[currentLevel];
  12947. level.items[level.index] = value;
  12948. this.currentLevel = currentLevel;
  12949. delete this.value;
  12950. },
  12951. incrementValue: function TagTree_incrementValue() {
  12952. var level = this.levels[this.currentLevel];
  12953. level.items[level.index]++;
  12954. },
  12955. nextLevel: function TagTree_nextLevel() {
  12956. var currentLevel = this.currentLevel;
  12957. var level = this.levels[currentLevel];
  12958. var value = level.items[level.index];
  12959. currentLevel--;
  12960. if (currentLevel < 0) {
  12961. this.value = value;
  12962. return false;
  12963. }
  12964. this.currentLevel = currentLevel;
  12965. level = this.levels[currentLevel];
  12966. level.items[level.index] = value;
  12967. return true;
  12968. }
  12969. };
  12970. return TagTree;
  12971. })();
  12972. var InclusionTree = (function InclusionTreeClosure() {
  12973. function InclusionTree(width, height, defaultValue) {
  12974. var levelsLength = log2(Math.max(width, height)) + 1;
  12975. this.levels = [];
  12976. for (var i = 0; i < levelsLength; i++) {
  12977. var items = new Uint8Array(width * height);
  12978. for (var j = 0, jj = items.length; j < jj; j++) {
  12979. items[j] = defaultValue;
  12980. }
  12981. var level = {
  12982. width: width,
  12983. height: height,
  12984. items: items
  12985. };
  12986. this.levels.push(level);
  12987. width = Math.ceil(width / 2);
  12988. height = Math.ceil(height / 2);
  12989. }
  12990. }
  12991. InclusionTree.prototype = {
  12992. reset: function InclusionTree_reset(i, j, stopValue) {
  12993. var currentLevel = 0;
  12994. while (currentLevel < this.levels.length) {
  12995. var level = this.levels[currentLevel];
  12996. var index = i + j * level.width;
  12997. level.index = index;
  12998. var value = level.items[index];
  12999. if (value === 0xFF) {
  13000. break;
  13001. }
  13002. if (value > stopValue) {
  13003. this.currentLevel = currentLevel;
  13004. // already know about this one, propagating the value to top levels
  13005. this.propagateValues();
  13006. return false;
  13007. }
  13008. i >>= 1;
  13009. j >>= 1;
  13010. currentLevel++;
  13011. }
  13012. this.currentLevel = currentLevel - 1;
  13013. return true;
  13014. },
  13015. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13016. var level = this.levels[this.currentLevel];
  13017. level.items[level.index] = stopValue + 1;
  13018. this.propagateValues();
  13019. },
  13020. propagateValues: function InclusionTree_propagateValues() {
  13021. var levelIndex = this.currentLevel;
  13022. var level = this.levels[levelIndex];
  13023. var currentValue = level.items[level.index];
  13024. while (--levelIndex >= 0) {
  13025. level = this.levels[levelIndex];
  13026. level.items[level.index] = currentValue;
  13027. }
  13028. },
  13029. nextLevel: function InclusionTree_nextLevel() {
  13030. var currentLevel = this.currentLevel;
  13031. var level = this.levels[currentLevel];
  13032. var value = level.items[level.index];
  13033. level.items[level.index] = 0xFF;
  13034. currentLevel--;
  13035. if (currentLevel < 0) {
  13036. return false;
  13037. }
  13038. this.currentLevel = currentLevel;
  13039. level = this.levels[currentLevel];
  13040. level.items[level.index] = value;
  13041. return true;
  13042. }
  13043. };
  13044. return InclusionTree;
  13045. })();
  13046. // Section D. Coefficient bit modeling
  13047. var BitModel = (function BitModelClosure() {
  13048. var UNIFORM_CONTEXT = 17;
  13049. var RUNLENGTH_CONTEXT = 18;
  13050. // Table D-1
  13051. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13052. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13053. var LLAndLHContextsLabel = new Uint8Array([
  13054. 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,
  13055. 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,
  13056. 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
  13057. ]);
  13058. var HLContextLabel = new Uint8Array([
  13059. 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,
  13060. 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,
  13061. 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
  13062. ]);
  13063. var HHContextLabel = new Uint8Array([
  13064. 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,
  13065. 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,
  13066. 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
  13067. ]);
  13068. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13069. this.width = width;
  13070. this.height = height;
  13071. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13072. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13073. var coefficientCount = width * height;
  13074. // coefficients outside the encoding region treated as insignificant
  13075. // add border state cells for significanceState
  13076. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13077. this.coefficentsSign = new Uint8Array(coefficientCount);
  13078. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13079. mb > 6 ? new Uint16Array(coefficientCount) :
  13080. new Uint8Array(coefficientCount);
  13081. this.processingFlags = new Uint8Array(coefficientCount);
  13082. var bitsDecoded = new Uint8Array(coefficientCount);
  13083. if (zeroBitPlanes !== 0) {
  13084. for (var i = 0; i < coefficientCount; i++) {
  13085. bitsDecoded[i] = zeroBitPlanes;
  13086. }
  13087. }
  13088. this.bitsDecoded = bitsDecoded;
  13089. this.reset();
  13090. }
  13091. BitModel.prototype = {
  13092. setDecoder: function BitModel_setDecoder(decoder) {
  13093. this.decoder = decoder;
  13094. },
  13095. reset: function BitModel_reset() {
  13096. // We have 17 contexts that are accessed via context labels,
  13097. // plus the uniform and runlength context.
  13098. this.contexts = new Int8Array(19);
  13099. // Contexts are packed into 1 byte:
  13100. // highest 7 bits carry the index, lowest bit carries mps
  13101. this.contexts[0] = (4 << 1) | 0;
  13102. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13103. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13104. },
  13105. setNeighborsSignificance:
  13106. function BitModel_setNeighborsSignificance(row, column, index) {
  13107. var neighborsSignificance = this.neighborsSignificance;
  13108. var width = this.width, height = this.height;
  13109. var left = (column > 0);
  13110. var right = (column + 1 < width);
  13111. var i;
  13112. if (row > 0) {
  13113. i = index - width;
  13114. if (left) {
  13115. neighborsSignificance[i - 1] += 0x10;
  13116. }
  13117. if (right) {
  13118. neighborsSignificance[i + 1] += 0x10;
  13119. }
  13120. neighborsSignificance[i] += 0x04;
  13121. }
  13122. if (row + 1 < height) {
  13123. i = index + width;
  13124. if (left) {
  13125. neighborsSignificance[i - 1] += 0x10;
  13126. }
  13127. if (right) {
  13128. neighborsSignificance[i + 1] += 0x10;
  13129. }
  13130. neighborsSignificance[i] += 0x04;
  13131. }
  13132. if (left) {
  13133. neighborsSignificance[index - 1] += 0x01;
  13134. }
  13135. if (right) {
  13136. neighborsSignificance[index + 1] += 0x01;
  13137. }
  13138. neighborsSignificance[index] |= 0x80;
  13139. },
  13140. runSignificancePropagationPass:
  13141. function BitModel_runSignificancePropagationPass() {
  13142. var decoder = this.decoder;
  13143. var width = this.width, height = this.height;
  13144. var coefficentsMagnitude = this.coefficentsMagnitude;
  13145. var coefficentsSign = this.coefficentsSign;
  13146. var neighborsSignificance = this.neighborsSignificance;
  13147. var processingFlags = this.processingFlags;
  13148. var contexts = this.contexts;
  13149. var labels = this.contextLabelTable;
  13150. var bitsDecoded = this.bitsDecoded;
  13151. var processedInverseMask = ~1;
  13152. var processedMask = 1;
  13153. var firstMagnitudeBitMask = 2;
  13154. for (var i0 = 0; i0 < height; i0 += 4) {
  13155. for (var j = 0; j < width; j++) {
  13156. var index = i0 * width + j;
  13157. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13158. var i = i0 + i1;
  13159. if (i >= height) {
  13160. break;
  13161. }
  13162. // clear processed flag first
  13163. processingFlags[index] &= processedInverseMask;
  13164. if (coefficentsMagnitude[index] ||
  13165. !neighborsSignificance[index]) {
  13166. continue;
  13167. }
  13168. var contextLabel = labels[neighborsSignificance[index]];
  13169. var decision = decoder.readBit(contexts, contextLabel);
  13170. if (decision) {
  13171. var sign = this.decodeSignBit(i, j, index);
  13172. coefficentsSign[index] = sign;
  13173. coefficentsMagnitude[index] = 1;
  13174. this.setNeighborsSignificance(i, j, index);
  13175. processingFlags[index] |= firstMagnitudeBitMask;
  13176. }
  13177. bitsDecoded[index]++;
  13178. processingFlags[index] |= processedMask;
  13179. }
  13180. }
  13181. }
  13182. },
  13183. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13184. var width = this.width, height = this.height;
  13185. var coefficentsMagnitude = this.coefficentsMagnitude;
  13186. var coefficentsSign = this.coefficentsSign;
  13187. var contribution, sign0, sign1, significance1;
  13188. var contextLabel, decoded;
  13189. // calculate horizontal contribution
  13190. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13191. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13192. sign1 = coefficentsSign[index + 1];
  13193. if (significance1) {
  13194. sign0 = coefficentsSign[index - 1];
  13195. contribution = 1 - sign1 - sign0;
  13196. } else {
  13197. contribution = 1 - sign1 - sign1;
  13198. }
  13199. } else if (significance1) {
  13200. sign0 = coefficentsSign[index - 1];
  13201. contribution = 1 - sign0 - sign0;
  13202. } else {
  13203. contribution = 0;
  13204. }
  13205. var horizontalContribution = 3 * contribution;
  13206. // calculate vertical contribution and combine with the horizontal
  13207. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13208. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13209. sign1 = coefficentsSign[index + width];
  13210. if (significance1) {
  13211. sign0 = coefficentsSign[index - width];
  13212. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13213. } else {
  13214. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13215. }
  13216. } else if (significance1) {
  13217. sign0 = coefficentsSign[index - width];
  13218. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13219. } else {
  13220. contribution = horizontalContribution;
  13221. }
  13222. if (contribution >= 0) {
  13223. contextLabel = 9 + contribution;
  13224. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13225. } else {
  13226. contextLabel = 9 - contribution;
  13227. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13228. }
  13229. return decoded;
  13230. },
  13231. runMagnitudeRefinementPass:
  13232. function BitModel_runMagnitudeRefinementPass() {
  13233. var decoder = this.decoder;
  13234. var width = this.width, height = this.height;
  13235. var coefficentsMagnitude = this.coefficentsMagnitude;
  13236. var neighborsSignificance = this.neighborsSignificance;
  13237. var contexts = this.contexts;
  13238. var bitsDecoded = this.bitsDecoded;
  13239. var processingFlags = this.processingFlags;
  13240. var processedMask = 1;
  13241. var firstMagnitudeBitMask = 2;
  13242. var length = width * height;
  13243. var width4 = width * 4;
  13244. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13245. indexNext = Math.min(length, index0 + width4);
  13246. for (var j = 0; j < width; j++) {
  13247. for (var index = index0 + j; index < indexNext; index += width) {
  13248. // significant but not those that have just become
  13249. if (!coefficentsMagnitude[index] ||
  13250. (processingFlags[index] & processedMask) !== 0) {
  13251. continue;
  13252. }
  13253. var contextLabel = 16;
  13254. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13255. processingFlags[index] ^= firstMagnitudeBitMask;
  13256. // first refinement
  13257. var significance = neighborsSignificance[index] & 127;
  13258. contextLabel = significance === 0 ? 15 : 14;
  13259. }
  13260. var bit = decoder.readBit(contexts, contextLabel);
  13261. coefficentsMagnitude[index] =
  13262. (coefficentsMagnitude[index] << 1) | bit;
  13263. bitsDecoded[index]++;
  13264. processingFlags[index] |= processedMask;
  13265. }
  13266. }
  13267. }
  13268. },
  13269. runCleanupPass: function BitModel_runCleanupPass() {
  13270. var decoder = this.decoder;
  13271. var width = this.width, height = this.height;
  13272. var neighborsSignificance = this.neighborsSignificance;
  13273. var coefficentsMagnitude = this.coefficentsMagnitude;
  13274. var coefficentsSign = this.coefficentsSign;
  13275. var contexts = this.contexts;
  13276. var labels = this.contextLabelTable;
  13277. var bitsDecoded = this.bitsDecoded;
  13278. var processingFlags = this.processingFlags;
  13279. var processedMask = 1;
  13280. var firstMagnitudeBitMask = 2;
  13281. var oneRowDown = width;
  13282. var twoRowsDown = width * 2;
  13283. var threeRowsDown = width * 3;
  13284. var iNext;
  13285. for (var i0 = 0; i0 < height; i0 = iNext) {
  13286. iNext = Math.min(i0 + 4, height);
  13287. var indexBase = i0 * width;
  13288. var checkAllEmpty = i0 + 3 < height;
  13289. for (var j = 0; j < width; j++) {
  13290. var index0 = indexBase + j;
  13291. // using the property: labels[neighborsSignificance[index]] === 0
  13292. // when neighborsSignificance[index] === 0
  13293. var allEmpty = (checkAllEmpty &&
  13294. processingFlags[index0] === 0 &&
  13295. processingFlags[index0 + oneRowDown] === 0 &&
  13296. processingFlags[index0 + twoRowsDown] === 0 &&
  13297. processingFlags[index0 + threeRowsDown] === 0 &&
  13298. neighborsSignificance[index0] === 0 &&
  13299. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13300. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13301. neighborsSignificance[index0 + threeRowsDown] === 0);
  13302. var i1 = 0, index = index0;
  13303. var i = i0, sign;
  13304. if (allEmpty) {
  13305. var hasSignificantCoefficent =
  13306. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13307. if (!hasSignificantCoefficent) {
  13308. bitsDecoded[index0]++;
  13309. bitsDecoded[index0 + oneRowDown]++;
  13310. bitsDecoded[index0 + twoRowsDown]++;
  13311. bitsDecoded[index0 + threeRowsDown]++;
  13312. continue; // next column
  13313. }
  13314. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13315. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13316. if (i1 !== 0) {
  13317. i = i0 + i1;
  13318. index += i1 * width;
  13319. }
  13320. sign = this.decodeSignBit(i, j, index);
  13321. coefficentsSign[index] = sign;
  13322. coefficentsMagnitude[index] = 1;
  13323. this.setNeighborsSignificance(i, j, index);
  13324. processingFlags[index] |= firstMagnitudeBitMask;
  13325. index = index0;
  13326. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13327. bitsDecoded[index]++;
  13328. }
  13329. i1++;
  13330. }
  13331. for (i = i0 + i1; i < iNext; i++, index += width) {
  13332. if (coefficentsMagnitude[index] ||
  13333. (processingFlags[index] & processedMask) !== 0) {
  13334. continue;
  13335. }
  13336. var contextLabel = labels[neighborsSignificance[index]];
  13337. var decision = decoder.readBit(contexts, contextLabel);
  13338. if (decision === 1) {
  13339. sign = this.decodeSignBit(i, j, index);
  13340. coefficentsSign[index] = sign;
  13341. coefficentsMagnitude[index] = 1;
  13342. this.setNeighborsSignificance(i, j, index);
  13343. processingFlags[index] |= firstMagnitudeBitMask;
  13344. }
  13345. bitsDecoded[index]++;
  13346. }
  13347. }
  13348. }
  13349. },
  13350. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13351. var decoder = this.decoder;
  13352. var contexts = this.contexts;
  13353. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13354. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13355. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13356. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13357. if (symbol !== 0xA) {
  13358. throw new Error('JPX Error: Invalid segmentation symbol');
  13359. }
  13360. }
  13361. };
  13362. return BitModel;
  13363. })();
  13364. // Section F, Discrete wavelet transformation
  13365. var Transform = (function TransformClosure() {
  13366. function Transform() {}
  13367. Transform.prototype.calculate =
  13368. function transformCalculate(subbands, u0, v0) {
  13369. var ll = subbands[0];
  13370. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13371. ll = this.iterate(ll, subbands[i], u0, v0);
  13372. }
  13373. return ll;
  13374. };
  13375. Transform.prototype.extend = function extend(buffer, offset, size) {
  13376. // Section F.3.7 extending... using max extension of 4
  13377. var i1 = offset - 1, j1 = offset + 1;
  13378. var i2 = offset + size - 2, j2 = offset + size;
  13379. buffer[i1--] = buffer[j1++];
  13380. buffer[j2++] = buffer[i2--];
  13381. buffer[i1--] = buffer[j1++];
  13382. buffer[j2++] = buffer[i2--];
  13383. buffer[i1--] = buffer[j1++];
  13384. buffer[j2++] = buffer[i2--];
  13385. buffer[i1] = buffer[j1];
  13386. buffer[j2] = buffer[i2];
  13387. };
  13388. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13389. u0, v0) {
  13390. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13391. var width = hl_lh_hh.width;
  13392. var height = hl_lh_hh.height;
  13393. var items = hl_lh_hh.items;
  13394. var i, j, k, l, u, v;
  13395. // Interleave LL according to Section F.3.3
  13396. for (k = 0, i = 0; i < llHeight; i++) {
  13397. l = i * 2 * width;
  13398. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13399. items[l] = llItems[k];
  13400. }
  13401. }
  13402. // The LL band is not needed anymore.
  13403. llItems = ll.items = null;
  13404. var bufferPadding = 4;
  13405. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13406. // Section F.3.4 HOR_SR
  13407. if (width === 1) {
  13408. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13409. if ((u0 & 1) !== 0) {
  13410. for (v = 0, k = 0; v < height; v++, k += width) {
  13411. items[k] *= 0.5;
  13412. }
  13413. }
  13414. } else {
  13415. for (v = 0, k = 0; v < height; v++, k += width) {
  13416. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13417. this.extend(rowBuffer, bufferPadding, width);
  13418. this.filter(rowBuffer, bufferPadding, width);
  13419. items.set(
  13420. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13421. k);
  13422. }
  13423. }
  13424. // Accesses to the items array can take long, because it may not fit into
  13425. // CPU cache and has to be fetched from main memory. Since subsequent
  13426. // accesses to the items array are not local when reading columns, we
  13427. // have a cache miss every time. To reduce cache misses, get up to
  13428. // 'numBuffers' items at a time and store them into the individual
  13429. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13430. var numBuffers = 16;
  13431. var colBuffers = [];
  13432. for (i = 0; i < numBuffers; i++) {
  13433. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13434. }
  13435. var b, currentBuffer = 0;
  13436. ll = bufferPadding + height;
  13437. // Section F.3.5 VER_SR
  13438. if (height === 1) {
  13439. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13440. if ((v0 & 1) !== 0) {
  13441. for (u = 0; u < width; u++) {
  13442. items[u] *= 0.5;
  13443. }
  13444. }
  13445. } else {
  13446. for (u = 0; u < width; u++) {
  13447. // if we ran out of buffers, copy several image columns at once
  13448. if (currentBuffer === 0) {
  13449. numBuffers = Math.min(width - u, numBuffers);
  13450. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13451. for (b = 0; b < numBuffers; b++) {
  13452. colBuffers[b][l] = items[k + b];
  13453. }
  13454. }
  13455. currentBuffer = numBuffers;
  13456. }
  13457. currentBuffer--;
  13458. var buffer = colBuffers[currentBuffer];
  13459. this.extend(buffer, bufferPadding, height);
  13460. this.filter(buffer, bufferPadding, height);
  13461. // If this is last buffer in this group of buffers, flush all buffers.
  13462. if (currentBuffer === 0) {
  13463. k = u - numBuffers + 1;
  13464. for (l = bufferPadding; l < ll; k += width, l++) {
  13465. for (b = 0; b < numBuffers; b++) {
  13466. items[k + b] = colBuffers[b][l];
  13467. }
  13468. }
  13469. }
  13470. }
  13471. }
  13472. return {
  13473. width: width,
  13474. height: height,
  13475. items: items
  13476. };
  13477. };
  13478. return Transform;
  13479. })();
  13480. // Section 3.8.2 Irreversible 9-7 filter
  13481. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13482. function IrreversibleTransform() {
  13483. Transform.call(this);
  13484. }
  13485. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13486. IrreversibleTransform.prototype.filter =
  13487. function irreversibleTransformFilter(x, offset, length) {
  13488. var len = length >> 1;
  13489. offset = offset | 0;
  13490. var j, n, current, next;
  13491. var alpha = -1.586134342059924;
  13492. var beta = -0.052980118572961;
  13493. var gamma = 0.882911075530934;
  13494. var delta = 0.443506852043971;
  13495. var K = 1.230174104914001;
  13496. var K_ = 1 / K;
  13497. // step 1 is combined with step 3
  13498. // step 2
  13499. j = offset - 3;
  13500. for (n = len + 4; n--; j += 2) {
  13501. x[j] *= K_;
  13502. }
  13503. // step 1 & 3
  13504. j = offset - 2;
  13505. current = delta * x[j -1];
  13506. for (n = len + 3; n--; j += 2) {
  13507. next = delta * x[j + 1];
  13508. x[j] = K * x[j] - current - next;
  13509. if (n--) {
  13510. j += 2;
  13511. current = delta * x[j + 1];
  13512. x[j] = K * x[j] - current - next;
  13513. } else {
  13514. break;
  13515. }
  13516. }
  13517. // step 4
  13518. j = offset - 1;
  13519. current = gamma * x[j - 1];
  13520. for (n = len + 2; n--; j += 2) {
  13521. next = gamma * x[j + 1];
  13522. x[j] -= current + next;
  13523. if (n--) {
  13524. j += 2;
  13525. current = gamma * x[j + 1];
  13526. x[j] -= current + next;
  13527. } else {
  13528. break;
  13529. }
  13530. }
  13531. // step 5
  13532. j = offset;
  13533. current = beta * x[j - 1];
  13534. for (n = len + 1; n--; j += 2) {
  13535. next = beta * x[j + 1];
  13536. x[j] -= current + next;
  13537. if (n--) {
  13538. j += 2;
  13539. current = beta * x[j + 1];
  13540. x[j] -= current + next;
  13541. } else {
  13542. break;
  13543. }
  13544. }
  13545. // step 6
  13546. if (len !== 0) {
  13547. j = offset + 1;
  13548. current = alpha * x[j - 1];
  13549. for (n = len; n--; j += 2) {
  13550. next = alpha * x[j + 1];
  13551. x[j] -= current + next;
  13552. if (n--) {
  13553. j += 2;
  13554. current = alpha * x[j + 1];
  13555. x[j] -= current + next;
  13556. } else {
  13557. break;
  13558. }
  13559. }
  13560. }
  13561. };
  13562. return IrreversibleTransform;
  13563. })();
  13564. // Section 3.8.1 Reversible 5-3 filter
  13565. var ReversibleTransform = (function ReversibleTransformClosure() {
  13566. function ReversibleTransform() {
  13567. Transform.call(this);
  13568. }
  13569. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13570. ReversibleTransform.prototype.filter =
  13571. function reversibleTransformFilter(x, offset, length) {
  13572. var len = length >> 1;
  13573. offset = offset | 0;
  13574. var j, n;
  13575. for (j = offset, n = len + 1; n--; j += 2) {
  13576. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13577. }
  13578. for (j = offset + 1, n = len; n--; j += 2) {
  13579. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13580. }
  13581. };
  13582. return ReversibleTransform;
  13583. })();
  13584. return JpxImage;
  13585. })();
  13586. exports.JpxImage = JpxImage;
  13587. }));
  13588. (function (root, factory) {
  13589. {
  13590. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13591. }
  13592. }(this, function (exports, sharedUtil) {
  13593. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13594. // The Metrics object contains glyph widths (in glyph space units).
  13595. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13596. // space unit corresponds to 1/1000th of text space unit.
  13597. var getMetrics = getLookupTableFactory(function (t) {
  13598. t['Courier'] = 600;
  13599. t['Courier-Bold'] = 600;
  13600. t['Courier-BoldOblique'] = 600;
  13601. t['Courier-Oblique'] = 600;
  13602. t['Helvetica'] = getLookupTableFactory(function (t) {
  13603. t['space'] = 278;
  13604. t['exclam'] = 278;
  13605. t['quotedbl'] = 355;
  13606. t['numbersign'] = 556;
  13607. t['dollar'] = 556;
  13608. t['percent'] = 889;
  13609. t['ampersand'] = 667;
  13610. t['quoteright'] = 222;
  13611. t['parenleft'] = 333;
  13612. t['parenright'] = 333;
  13613. t['asterisk'] = 389;
  13614. t['plus'] = 584;
  13615. t['comma'] = 278;
  13616. t['hyphen'] = 333;
  13617. t['period'] = 278;
  13618. t['slash'] = 278;
  13619. t['zero'] = 556;
  13620. t['one'] = 556;
  13621. t['two'] = 556;
  13622. t['three'] = 556;
  13623. t['four'] = 556;
  13624. t['five'] = 556;
  13625. t['six'] = 556;
  13626. t['seven'] = 556;
  13627. t['eight'] = 556;
  13628. t['nine'] = 556;
  13629. t['colon'] = 278;
  13630. t['semicolon'] = 278;
  13631. t['less'] = 584;
  13632. t['equal'] = 584;
  13633. t['greater'] = 584;
  13634. t['question'] = 556;
  13635. t['at'] = 1015;
  13636. t['A'] = 667;
  13637. t['B'] = 667;
  13638. t['C'] = 722;
  13639. t['D'] = 722;
  13640. t['E'] = 667;
  13641. t['F'] = 611;
  13642. t['G'] = 778;
  13643. t['H'] = 722;
  13644. t['I'] = 278;
  13645. t['J'] = 500;
  13646. t['K'] = 667;
  13647. t['L'] = 556;
  13648. t['M'] = 833;
  13649. t['N'] = 722;
  13650. t['O'] = 778;
  13651. t['P'] = 667;
  13652. t['Q'] = 778;
  13653. t['R'] = 722;
  13654. t['S'] = 667;
  13655. t['T'] = 611;
  13656. t['U'] = 722;
  13657. t['V'] = 667;
  13658. t['W'] = 944;
  13659. t['X'] = 667;
  13660. t['Y'] = 667;
  13661. t['Z'] = 611;
  13662. t['bracketleft'] = 278;
  13663. t['backslash'] = 278;
  13664. t['bracketright'] = 278;
  13665. t['asciicircum'] = 469;
  13666. t['underscore'] = 556;
  13667. t['quoteleft'] = 222;
  13668. t['a'] = 556;
  13669. t['b'] = 556;
  13670. t['c'] = 500;
  13671. t['d'] = 556;
  13672. t['e'] = 556;
  13673. t['f'] = 278;
  13674. t['g'] = 556;
  13675. t['h'] = 556;
  13676. t['i'] = 222;
  13677. t['j'] = 222;
  13678. t['k'] = 500;
  13679. t['l'] = 222;
  13680. t['m'] = 833;
  13681. t['n'] = 556;
  13682. t['o'] = 556;
  13683. t['p'] = 556;
  13684. t['q'] = 556;
  13685. t['r'] = 333;
  13686. t['s'] = 500;
  13687. t['t'] = 278;
  13688. t['u'] = 556;
  13689. t['v'] = 500;
  13690. t['w'] = 722;
  13691. t['x'] = 500;
  13692. t['y'] = 500;
  13693. t['z'] = 500;
  13694. t['braceleft'] = 334;
  13695. t['bar'] = 260;
  13696. t['braceright'] = 334;
  13697. t['asciitilde'] = 584;
  13698. t['exclamdown'] = 333;
  13699. t['cent'] = 556;
  13700. t['sterling'] = 556;
  13701. t['fraction'] = 167;
  13702. t['yen'] = 556;
  13703. t['florin'] = 556;
  13704. t['section'] = 556;
  13705. t['currency'] = 556;
  13706. t['quotesingle'] = 191;
  13707. t['quotedblleft'] = 333;
  13708. t['guillemotleft'] = 556;
  13709. t['guilsinglleft'] = 333;
  13710. t['guilsinglright'] = 333;
  13711. t['fi'] = 500;
  13712. t['fl'] = 500;
  13713. t['endash'] = 556;
  13714. t['dagger'] = 556;
  13715. t['daggerdbl'] = 556;
  13716. t['periodcentered'] = 278;
  13717. t['paragraph'] = 537;
  13718. t['bullet'] = 350;
  13719. t['quotesinglbase'] = 222;
  13720. t['quotedblbase'] = 333;
  13721. t['quotedblright'] = 333;
  13722. t['guillemotright'] = 556;
  13723. t['ellipsis'] = 1000;
  13724. t['perthousand'] = 1000;
  13725. t['questiondown'] = 611;
  13726. t['grave'] = 333;
  13727. t['acute'] = 333;
  13728. t['circumflex'] = 333;
  13729. t['tilde'] = 333;
  13730. t['macron'] = 333;
  13731. t['breve'] = 333;
  13732. t['dotaccent'] = 333;
  13733. t['dieresis'] = 333;
  13734. t['ring'] = 333;
  13735. t['cedilla'] = 333;
  13736. t['hungarumlaut'] = 333;
  13737. t['ogonek'] = 333;
  13738. t['caron'] = 333;
  13739. t['emdash'] = 1000;
  13740. t['AE'] = 1000;
  13741. t['ordfeminine'] = 370;
  13742. t['Lslash'] = 556;
  13743. t['Oslash'] = 778;
  13744. t['OE'] = 1000;
  13745. t['ordmasculine'] = 365;
  13746. t['ae'] = 889;
  13747. t['dotlessi'] = 278;
  13748. t['lslash'] = 222;
  13749. t['oslash'] = 611;
  13750. t['oe'] = 944;
  13751. t['germandbls'] = 611;
  13752. t['Idieresis'] = 278;
  13753. t['eacute'] = 556;
  13754. t['abreve'] = 556;
  13755. t['uhungarumlaut'] = 556;
  13756. t['ecaron'] = 556;
  13757. t['Ydieresis'] = 667;
  13758. t['divide'] = 584;
  13759. t['Yacute'] = 667;
  13760. t['Acircumflex'] = 667;
  13761. t['aacute'] = 556;
  13762. t['Ucircumflex'] = 722;
  13763. t['yacute'] = 500;
  13764. t['scommaaccent'] = 500;
  13765. t['ecircumflex'] = 556;
  13766. t['Uring'] = 722;
  13767. t['Udieresis'] = 722;
  13768. t['aogonek'] = 556;
  13769. t['Uacute'] = 722;
  13770. t['uogonek'] = 556;
  13771. t['Edieresis'] = 667;
  13772. t['Dcroat'] = 722;
  13773. t['commaaccent'] = 250;
  13774. t['copyright'] = 737;
  13775. t['Emacron'] = 667;
  13776. t['ccaron'] = 500;
  13777. t['aring'] = 556;
  13778. t['Ncommaaccent'] = 722;
  13779. t['lacute'] = 222;
  13780. t['agrave'] = 556;
  13781. t['Tcommaaccent'] = 611;
  13782. t['Cacute'] = 722;
  13783. t['atilde'] = 556;
  13784. t['Edotaccent'] = 667;
  13785. t['scaron'] = 500;
  13786. t['scedilla'] = 500;
  13787. t['iacute'] = 278;
  13788. t['lozenge'] = 471;
  13789. t['Rcaron'] = 722;
  13790. t['Gcommaaccent'] = 778;
  13791. t['ucircumflex'] = 556;
  13792. t['acircumflex'] = 556;
  13793. t['Amacron'] = 667;
  13794. t['rcaron'] = 333;
  13795. t['ccedilla'] = 500;
  13796. t['Zdotaccent'] = 611;
  13797. t['Thorn'] = 667;
  13798. t['Omacron'] = 778;
  13799. t['Racute'] = 722;
  13800. t['Sacute'] = 667;
  13801. t['dcaron'] = 643;
  13802. t['Umacron'] = 722;
  13803. t['uring'] = 556;
  13804. t['threesuperior'] = 333;
  13805. t['Ograve'] = 778;
  13806. t['Agrave'] = 667;
  13807. t['Abreve'] = 667;
  13808. t['multiply'] = 584;
  13809. t['uacute'] = 556;
  13810. t['Tcaron'] = 611;
  13811. t['partialdiff'] = 476;
  13812. t['ydieresis'] = 500;
  13813. t['Nacute'] = 722;
  13814. t['icircumflex'] = 278;
  13815. t['Ecircumflex'] = 667;
  13816. t['adieresis'] = 556;
  13817. t['edieresis'] = 556;
  13818. t['cacute'] = 500;
  13819. t['nacute'] = 556;
  13820. t['umacron'] = 556;
  13821. t['Ncaron'] = 722;
  13822. t['Iacute'] = 278;
  13823. t['plusminus'] = 584;
  13824. t['brokenbar'] = 260;
  13825. t['registered'] = 737;
  13826. t['Gbreve'] = 778;
  13827. t['Idotaccent'] = 278;
  13828. t['summation'] = 600;
  13829. t['Egrave'] = 667;
  13830. t['racute'] = 333;
  13831. t['omacron'] = 556;
  13832. t['Zacute'] = 611;
  13833. t['Zcaron'] = 611;
  13834. t['greaterequal'] = 549;
  13835. t['Eth'] = 722;
  13836. t['Ccedilla'] = 722;
  13837. t['lcommaaccent'] = 222;
  13838. t['tcaron'] = 317;
  13839. t['eogonek'] = 556;
  13840. t['Uogonek'] = 722;
  13841. t['Aacute'] = 667;
  13842. t['Adieresis'] = 667;
  13843. t['egrave'] = 556;
  13844. t['zacute'] = 500;
  13845. t['iogonek'] = 222;
  13846. t['Oacute'] = 778;
  13847. t['oacute'] = 556;
  13848. t['amacron'] = 556;
  13849. t['sacute'] = 500;
  13850. t['idieresis'] = 278;
  13851. t['Ocircumflex'] = 778;
  13852. t['Ugrave'] = 722;
  13853. t['Delta'] = 612;
  13854. t['thorn'] = 556;
  13855. t['twosuperior'] = 333;
  13856. t['Odieresis'] = 778;
  13857. t['mu'] = 556;
  13858. t['igrave'] = 278;
  13859. t['ohungarumlaut'] = 556;
  13860. t['Eogonek'] = 667;
  13861. t['dcroat'] = 556;
  13862. t['threequarters'] = 834;
  13863. t['Scedilla'] = 667;
  13864. t['lcaron'] = 299;
  13865. t['Kcommaaccent'] = 667;
  13866. t['Lacute'] = 556;
  13867. t['trademark'] = 1000;
  13868. t['edotaccent'] = 556;
  13869. t['Igrave'] = 278;
  13870. t['Imacron'] = 278;
  13871. t['Lcaron'] = 556;
  13872. t['onehalf'] = 834;
  13873. t['lessequal'] = 549;
  13874. t['ocircumflex'] = 556;
  13875. t['ntilde'] = 556;
  13876. t['Uhungarumlaut'] = 722;
  13877. t['Eacute'] = 667;
  13878. t['emacron'] = 556;
  13879. t['gbreve'] = 556;
  13880. t['onequarter'] = 834;
  13881. t['Scaron'] = 667;
  13882. t['Scommaaccent'] = 667;
  13883. t['Ohungarumlaut'] = 778;
  13884. t['degree'] = 400;
  13885. t['ograve'] = 556;
  13886. t['Ccaron'] = 722;
  13887. t['ugrave'] = 556;
  13888. t['radical'] = 453;
  13889. t['Dcaron'] = 722;
  13890. t['rcommaaccent'] = 333;
  13891. t['Ntilde'] = 722;
  13892. t['otilde'] = 556;
  13893. t['Rcommaaccent'] = 722;
  13894. t['Lcommaaccent'] = 556;
  13895. t['Atilde'] = 667;
  13896. t['Aogonek'] = 667;
  13897. t['Aring'] = 667;
  13898. t['Otilde'] = 778;
  13899. t['zdotaccent'] = 500;
  13900. t['Ecaron'] = 667;
  13901. t['Iogonek'] = 278;
  13902. t['kcommaaccent'] = 500;
  13903. t['minus'] = 584;
  13904. t['Icircumflex'] = 278;
  13905. t['ncaron'] = 556;
  13906. t['tcommaaccent'] = 278;
  13907. t['logicalnot'] = 584;
  13908. t['odieresis'] = 556;
  13909. t['udieresis'] = 556;
  13910. t['notequal'] = 549;
  13911. t['gcommaaccent'] = 556;
  13912. t['eth'] = 556;
  13913. t['zcaron'] = 500;
  13914. t['ncommaaccent'] = 556;
  13915. t['onesuperior'] = 333;
  13916. t['imacron'] = 278;
  13917. t['Euro'] = 556;
  13918. });
  13919. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  13920. t['space'] = 278;
  13921. t['exclam'] = 333;
  13922. t['quotedbl'] = 474;
  13923. t['numbersign'] = 556;
  13924. t['dollar'] = 556;
  13925. t['percent'] = 889;
  13926. t['ampersand'] = 722;
  13927. t['quoteright'] = 278;
  13928. t['parenleft'] = 333;
  13929. t['parenright'] = 333;
  13930. t['asterisk'] = 389;
  13931. t['plus'] = 584;
  13932. t['comma'] = 278;
  13933. t['hyphen'] = 333;
  13934. t['period'] = 278;
  13935. t['slash'] = 278;
  13936. t['zero'] = 556;
  13937. t['one'] = 556;
  13938. t['two'] = 556;
  13939. t['three'] = 556;
  13940. t['four'] = 556;
  13941. t['five'] = 556;
  13942. t['six'] = 556;
  13943. t['seven'] = 556;
  13944. t['eight'] = 556;
  13945. t['nine'] = 556;
  13946. t['colon'] = 333;
  13947. t['semicolon'] = 333;
  13948. t['less'] = 584;
  13949. t['equal'] = 584;
  13950. t['greater'] = 584;
  13951. t['question'] = 611;
  13952. t['at'] = 975;
  13953. t['A'] = 722;
  13954. t['B'] = 722;
  13955. t['C'] = 722;
  13956. t['D'] = 722;
  13957. t['E'] = 667;
  13958. t['F'] = 611;
  13959. t['G'] = 778;
  13960. t['H'] = 722;
  13961. t['I'] = 278;
  13962. t['J'] = 556;
  13963. t['K'] = 722;
  13964. t['L'] = 611;
  13965. t['M'] = 833;
  13966. t['N'] = 722;
  13967. t['O'] = 778;
  13968. t['P'] = 667;
  13969. t['Q'] = 778;
  13970. t['R'] = 722;
  13971. t['S'] = 667;
  13972. t['T'] = 611;
  13973. t['U'] = 722;
  13974. t['V'] = 667;
  13975. t['W'] = 944;
  13976. t['X'] = 667;
  13977. t['Y'] = 667;
  13978. t['Z'] = 611;
  13979. t['bracketleft'] = 333;
  13980. t['backslash'] = 278;
  13981. t['bracketright'] = 333;
  13982. t['asciicircum'] = 584;
  13983. t['underscore'] = 556;
  13984. t['quoteleft'] = 278;
  13985. t['a'] = 556;
  13986. t['b'] = 611;
  13987. t['c'] = 556;
  13988. t['d'] = 611;
  13989. t['e'] = 556;
  13990. t['f'] = 333;
  13991. t['g'] = 611;
  13992. t['h'] = 611;
  13993. t['i'] = 278;
  13994. t['j'] = 278;
  13995. t['k'] = 556;
  13996. t['l'] = 278;
  13997. t['m'] = 889;
  13998. t['n'] = 611;
  13999. t['o'] = 611;
  14000. t['p'] = 611;
  14001. t['q'] = 611;
  14002. t['r'] = 389;
  14003. t['s'] = 556;
  14004. t['t'] = 333;
  14005. t['u'] = 611;
  14006. t['v'] = 556;
  14007. t['w'] = 778;
  14008. t['x'] = 556;
  14009. t['y'] = 556;
  14010. t['z'] = 500;
  14011. t['braceleft'] = 389;
  14012. t['bar'] = 280;
  14013. t['braceright'] = 389;
  14014. t['asciitilde'] = 584;
  14015. t['exclamdown'] = 333;
  14016. t['cent'] = 556;
  14017. t['sterling'] = 556;
  14018. t['fraction'] = 167;
  14019. t['yen'] = 556;
  14020. t['florin'] = 556;
  14021. t['section'] = 556;
  14022. t['currency'] = 556;
  14023. t['quotesingle'] = 238;
  14024. t['quotedblleft'] = 500;
  14025. t['guillemotleft'] = 556;
  14026. t['guilsinglleft'] = 333;
  14027. t['guilsinglright'] = 333;
  14028. t['fi'] = 611;
  14029. t['fl'] = 611;
  14030. t['endash'] = 556;
  14031. t['dagger'] = 556;
  14032. t['daggerdbl'] = 556;
  14033. t['periodcentered'] = 278;
  14034. t['paragraph'] = 556;
  14035. t['bullet'] = 350;
  14036. t['quotesinglbase'] = 278;
  14037. t['quotedblbase'] = 500;
  14038. t['quotedblright'] = 500;
  14039. t['guillemotright'] = 556;
  14040. t['ellipsis'] = 1000;
  14041. t['perthousand'] = 1000;
  14042. t['questiondown'] = 611;
  14043. t['grave'] = 333;
  14044. t['acute'] = 333;
  14045. t['circumflex'] = 333;
  14046. t['tilde'] = 333;
  14047. t['macron'] = 333;
  14048. t['breve'] = 333;
  14049. t['dotaccent'] = 333;
  14050. t['dieresis'] = 333;
  14051. t['ring'] = 333;
  14052. t['cedilla'] = 333;
  14053. t['hungarumlaut'] = 333;
  14054. t['ogonek'] = 333;
  14055. t['caron'] = 333;
  14056. t['emdash'] = 1000;
  14057. t['AE'] = 1000;
  14058. t['ordfeminine'] = 370;
  14059. t['Lslash'] = 611;
  14060. t['Oslash'] = 778;
  14061. t['OE'] = 1000;
  14062. t['ordmasculine'] = 365;
  14063. t['ae'] = 889;
  14064. t['dotlessi'] = 278;
  14065. t['lslash'] = 278;
  14066. t['oslash'] = 611;
  14067. t['oe'] = 944;
  14068. t['germandbls'] = 611;
  14069. t['Idieresis'] = 278;
  14070. t['eacute'] = 556;
  14071. t['abreve'] = 556;
  14072. t['uhungarumlaut'] = 611;
  14073. t['ecaron'] = 556;
  14074. t['Ydieresis'] = 667;
  14075. t['divide'] = 584;
  14076. t['Yacute'] = 667;
  14077. t['Acircumflex'] = 722;
  14078. t['aacute'] = 556;
  14079. t['Ucircumflex'] = 722;
  14080. t['yacute'] = 556;
  14081. t['scommaaccent'] = 556;
  14082. t['ecircumflex'] = 556;
  14083. t['Uring'] = 722;
  14084. t['Udieresis'] = 722;
  14085. t['aogonek'] = 556;
  14086. t['Uacute'] = 722;
  14087. t['uogonek'] = 611;
  14088. t['Edieresis'] = 667;
  14089. t['Dcroat'] = 722;
  14090. t['commaaccent'] = 250;
  14091. t['copyright'] = 737;
  14092. t['Emacron'] = 667;
  14093. t['ccaron'] = 556;
  14094. t['aring'] = 556;
  14095. t['Ncommaaccent'] = 722;
  14096. t['lacute'] = 278;
  14097. t['agrave'] = 556;
  14098. t['Tcommaaccent'] = 611;
  14099. t['Cacute'] = 722;
  14100. t['atilde'] = 556;
  14101. t['Edotaccent'] = 667;
  14102. t['scaron'] = 556;
  14103. t['scedilla'] = 556;
  14104. t['iacute'] = 278;
  14105. t['lozenge'] = 494;
  14106. t['Rcaron'] = 722;
  14107. t['Gcommaaccent'] = 778;
  14108. t['ucircumflex'] = 611;
  14109. t['acircumflex'] = 556;
  14110. t['Amacron'] = 722;
  14111. t['rcaron'] = 389;
  14112. t['ccedilla'] = 556;
  14113. t['Zdotaccent'] = 611;
  14114. t['Thorn'] = 667;
  14115. t['Omacron'] = 778;
  14116. t['Racute'] = 722;
  14117. t['Sacute'] = 667;
  14118. t['dcaron'] = 743;
  14119. t['Umacron'] = 722;
  14120. t['uring'] = 611;
  14121. t['threesuperior'] = 333;
  14122. t['Ograve'] = 778;
  14123. t['Agrave'] = 722;
  14124. t['Abreve'] = 722;
  14125. t['multiply'] = 584;
  14126. t['uacute'] = 611;
  14127. t['Tcaron'] = 611;
  14128. t['partialdiff'] = 494;
  14129. t['ydieresis'] = 556;
  14130. t['Nacute'] = 722;
  14131. t['icircumflex'] = 278;
  14132. t['Ecircumflex'] = 667;
  14133. t['adieresis'] = 556;
  14134. t['edieresis'] = 556;
  14135. t['cacute'] = 556;
  14136. t['nacute'] = 611;
  14137. t['umacron'] = 611;
  14138. t['Ncaron'] = 722;
  14139. t['Iacute'] = 278;
  14140. t['plusminus'] = 584;
  14141. t['brokenbar'] = 280;
  14142. t['registered'] = 737;
  14143. t['Gbreve'] = 778;
  14144. t['Idotaccent'] = 278;
  14145. t['summation'] = 600;
  14146. t['Egrave'] = 667;
  14147. t['racute'] = 389;
  14148. t['omacron'] = 611;
  14149. t['Zacute'] = 611;
  14150. t['Zcaron'] = 611;
  14151. t['greaterequal'] = 549;
  14152. t['Eth'] = 722;
  14153. t['Ccedilla'] = 722;
  14154. t['lcommaaccent'] = 278;
  14155. t['tcaron'] = 389;
  14156. t['eogonek'] = 556;
  14157. t['Uogonek'] = 722;
  14158. t['Aacute'] = 722;
  14159. t['Adieresis'] = 722;
  14160. t['egrave'] = 556;
  14161. t['zacute'] = 500;
  14162. t['iogonek'] = 278;
  14163. t['Oacute'] = 778;
  14164. t['oacute'] = 611;
  14165. t['amacron'] = 556;
  14166. t['sacute'] = 556;
  14167. t['idieresis'] = 278;
  14168. t['Ocircumflex'] = 778;
  14169. t['Ugrave'] = 722;
  14170. t['Delta'] = 612;
  14171. t['thorn'] = 611;
  14172. t['twosuperior'] = 333;
  14173. t['Odieresis'] = 778;
  14174. t['mu'] = 611;
  14175. t['igrave'] = 278;
  14176. t['ohungarumlaut'] = 611;
  14177. t['Eogonek'] = 667;
  14178. t['dcroat'] = 611;
  14179. t['threequarters'] = 834;
  14180. t['Scedilla'] = 667;
  14181. t['lcaron'] = 400;
  14182. t['Kcommaaccent'] = 722;
  14183. t['Lacute'] = 611;
  14184. t['trademark'] = 1000;
  14185. t['edotaccent'] = 556;
  14186. t['Igrave'] = 278;
  14187. t['Imacron'] = 278;
  14188. t['Lcaron'] = 611;
  14189. t['onehalf'] = 834;
  14190. t['lessequal'] = 549;
  14191. t['ocircumflex'] = 611;
  14192. t['ntilde'] = 611;
  14193. t['Uhungarumlaut'] = 722;
  14194. t['Eacute'] = 667;
  14195. t['emacron'] = 556;
  14196. t['gbreve'] = 611;
  14197. t['onequarter'] = 834;
  14198. t['Scaron'] = 667;
  14199. t['Scommaaccent'] = 667;
  14200. t['Ohungarumlaut'] = 778;
  14201. t['degree'] = 400;
  14202. t['ograve'] = 611;
  14203. t['Ccaron'] = 722;
  14204. t['ugrave'] = 611;
  14205. t['radical'] = 549;
  14206. t['Dcaron'] = 722;
  14207. t['rcommaaccent'] = 389;
  14208. t['Ntilde'] = 722;
  14209. t['otilde'] = 611;
  14210. t['Rcommaaccent'] = 722;
  14211. t['Lcommaaccent'] = 611;
  14212. t['Atilde'] = 722;
  14213. t['Aogonek'] = 722;
  14214. t['Aring'] = 722;
  14215. t['Otilde'] = 778;
  14216. t['zdotaccent'] = 500;
  14217. t['Ecaron'] = 667;
  14218. t['Iogonek'] = 278;
  14219. t['kcommaaccent'] = 556;
  14220. t['minus'] = 584;
  14221. t['Icircumflex'] = 278;
  14222. t['ncaron'] = 611;
  14223. t['tcommaaccent'] = 333;
  14224. t['logicalnot'] = 584;
  14225. t['odieresis'] = 611;
  14226. t['udieresis'] = 611;
  14227. t['notequal'] = 549;
  14228. t['gcommaaccent'] = 611;
  14229. t['eth'] = 611;
  14230. t['zcaron'] = 500;
  14231. t['ncommaaccent'] = 611;
  14232. t['onesuperior'] = 333;
  14233. t['imacron'] = 278;
  14234. t['Euro'] = 556;
  14235. });
  14236. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14237. t['space'] = 278;
  14238. t['exclam'] = 333;
  14239. t['quotedbl'] = 474;
  14240. t['numbersign'] = 556;
  14241. t['dollar'] = 556;
  14242. t['percent'] = 889;
  14243. t['ampersand'] = 722;
  14244. t['quoteright'] = 278;
  14245. t['parenleft'] = 333;
  14246. t['parenright'] = 333;
  14247. t['asterisk'] = 389;
  14248. t['plus'] = 584;
  14249. t['comma'] = 278;
  14250. t['hyphen'] = 333;
  14251. t['period'] = 278;
  14252. t['slash'] = 278;
  14253. t['zero'] = 556;
  14254. t['one'] = 556;
  14255. t['two'] = 556;
  14256. t['three'] = 556;
  14257. t['four'] = 556;
  14258. t['five'] = 556;
  14259. t['six'] = 556;
  14260. t['seven'] = 556;
  14261. t['eight'] = 556;
  14262. t['nine'] = 556;
  14263. t['colon'] = 333;
  14264. t['semicolon'] = 333;
  14265. t['less'] = 584;
  14266. t['equal'] = 584;
  14267. t['greater'] = 584;
  14268. t['question'] = 611;
  14269. t['at'] = 975;
  14270. t['A'] = 722;
  14271. t['B'] = 722;
  14272. t['C'] = 722;
  14273. t['D'] = 722;
  14274. t['E'] = 667;
  14275. t['F'] = 611;
  14276. t['G'] = 778;
  14277. t['H'] = 722;
  14278. t['I'] = 278;
  14279. t['J'] = 556;
  14280. t['K'] = 722;
  14281. t['L'] = 611;
  14282. t['M'] = 833;
  14283. t['N'] = 722;
  14284. t['O'] = 778;
  14285. t['P'] = 667;
  14286. t['Q'] = 778;
  14287. t['R'] = 722;
  14288. t['S'] = 667;
  14289. t['T'] = 611;
  14290. t['U'] = 722;
  14291. t['V'] = 667;
  14292. t['W'] = 944;
  14293. t['X'] = 667;
  14294. t['Y'] = 667;
  14295. t['Z'] = 611;
  14296. t['bracketleft'] = 333;
  14297. t['backslash'] = 278;
  14298. t['bracketright'] = 333;
  14299. t['asciicircum'] = 584;
  14300. t['underscore'] = 556;
  14301. t['quoteleft'] = 278;
  14302. t['a'] = 556;
  14303. t['b'] = 611;
  14304. t['c'] = 556;
  14305. t['d'] = 611;
  14306. t['e'] = 556;
  14307. t['f'] = 333;
  14308. t['g'] = 611;
  14309. t['h'] = 611;
  14310. t['i'] = 278;
  14311. t['j'] = 278;
  14312. t['k'] = 556;
  14313. t['l'] = 278;
  14314. t['m'] = 889;
  14315. t['n'] = 611;
  14316. t['o'] = 611;
  14317. t['p'] = 611;
  14318. t['q'] = 611;
  14319. t['r'] = 389;
  14320. t['s'] = 556;
  14321. t['t'] = 333;
  14322. t['u'] = 611;
  14323. t['v'] = 556;
  14324. t['w'] = 778;
  14325. t['x'] = 556;
  14326. t['y'] = 556;
  14327. t['z'] = 500;
  14328. t['braceleft'] = 389;
  14329. t['bar'] = 280;
  14330. t['braceright'] = 389;
  14331. t['asciitilde'] = 584;
  14332. t['exclamdown'] = 333;
  14333. t['cent'] = 556;
  14334. t['sterling'] = 556;
  14335. t['fraction'] = 167;
  14336. t['yen'] = 556;
  14337. t['florin'] = 556;
  14338. t['section'] = 556;
  14339. t['currency'] = 556;
  14340. t['quotesingle'] = 238;
  14341. t['quotedblleft'] = 500;
  14342. t['guillemotleft'] = 556;
  14343. t['guilsinglleft'] = 333;
  14344. t['guilsinglright'] = 333;
  14345. t['fi'] = 611;
  14346. t['fl'] = 611;
  14347. t['endash'] = 556;
  14348. t['dagger'] = 556;
  14349. t['daggerdbl'] = 556;
  14350. t['periodcentered'] = 278;
  14351. t['paragraph'] = 556;
  14352. t['bullet'] = 350;
  14353. t['quotesinglbase'] = 278;
  14354. t['quotedblbase'] = 500;
  14355. t['quotedblright'] = 500;
  14356. t['guillemotright'] = 556;
  14357. t['ellipsis'] = 1000;
  14358. t['perthousand'] = 1000;
  14359. t['questiondown'] = 611;
  14360. t['grave'] = 333;
  14361. t['acute'] = 333;
  14362. t['circumflex'] = 333;
  14363. t['tilde'] = 333;
  14364. t['macron'] = 333;
  14365. t['breve'] = 333;
  14366. t['dotaccent'] = 333;
  14367. t['dieresis'] = 333;
  14368. t['ring'] = 333;
  14369. t['cedilla'] = 333;
  14370. t['hungarumlaut'] = 333;
  14371. t['ogonek'] = 333;
  14372. t['caron'] = 333;
  14373. t['emdash'] = 1000;
  14374. t['AE'] = 1000;
  14375. t['ordfeminine'] = 370;
  14376. t['Lslash'] = 611;
  14377. t['Oslash'] = 778;
  14378. t['OE'] = 1000;
  14379. t['ordmasculine'] = 365;
  14380. t['ae'] = 889;
  14381. t['dotlessi'] = 278;
  14382. t['lslash'] = 278;
  14383. t['oslash'] = 611;
  14384. t['oe'] = 944;
  14385. t['germandbls'] = 611;
  14386. t['Idieresis'] = 278;
  14387. t['eacute'] = 556;
  14388. t['abreve'] = 556;
  14389. t['uhungarumlaut'] = 611;
  14390. t['ecaron'] = 556;
  14391. t['Ydieresis'] = 667;
  14392. t['divide'] = 584;
  14393. t['Yacute'] = 667;
  14394. t['Acircumflex'] = 722;
  14395. t['aacute'] = 556;
  14396. t['Ucircumflex'] = 722;
  14397. t['yacute'] = 556;
  14398. t['scommaaccent'] = 556;
  14399. t['ecircumflex'] = 556;
  14400. t['Uring'] = 722;
  14401. t['Udieresis'] = 722;
  14402. t['aogonek'] = 556;
  14403. t['Uacute'] = 722;
  14404. t['uogonek'] = 611;
  14405. t['Edieresis'] = 667;
  14406. t['Dcroat'] = 722;
  14407. t['commaaccent'] = 250;
  14408. t['copyright'] = 737;
  14409. t['Emacron'] = 667;
  14410. t['ccaron'] = 556;
  14411. t['aring'] = 556;
  14412. t['Ncommaaccent'] = 722;
  14413. t['lacute'] = 278;
  14414. t['agrave'] = 556;
  14415. t['Tcommaaccent'] = 611;
  14416. t['Cacute'] = 722;
  14417. t['atilde'] = 556;
  14418. t['Edotaccent'] = 667;
  14419. t['scaron'] = 556;
  14420. t['scedilla'] = 556;
  14421. t['iacute'] = 278;
  14422. t['lozenge'] = 494;
  14423. t['Rcaron'] = 722;
  14424. t['Gcommaaccent'] = 778;
  14425. t['ucircumflex'] = 611;
  14426. t['acircumflex'] = 556;
  14427. t['Amacron'] = 722;
  14428. t['rcaron'] = 389;
  14429. t['ccedilla'] = 556;
  14430. t['Zdotaccent'] = 611;
  14431. t['Thorn'] = 667;
  14432. t['Omacron'] = 778;
  14433. t['Racute'] = 722;
  14434. t['Sacute'] = 667;
  14435. t['dcaron'] = 743;
  14436. t['Umacron'] = 722;
  14437. t['uring'] = 611;
  14438. t['threesuperior'] = 333;
  14439. t['Ograve'] = 778;
  14440. t['Agrave'] = 722;
  14441. t['Abreve'] = 722;
  14442. t['multiply'] = 584;
  14443. t['uacute'] = 611;
  14444. t['Tcaron'] = 611;
  14445. t['partialdiff'] = 494;
  14446. t['ydieresis'] = 556;
  14447. t['Nacute'] = 722;
  14448. t['icircumflex'] = 278;
  14449. t['Ecircumflex'] = 667;
  14450. t['adieresis'] = 556;
  14451. t['edieresis'] = 556;
  14452. t['cacute'] = 556;
  14453. t['nacute'] = 611;
  14454. t['umacron'] = 611;
  14455. t['Ncaron'] = 722;
  14456. t['Iacute'] = 278;
  14457. t['plusminus'] = 584;
  14458. t['brokenbar'] = 280;
  14459. t['registered'] = 737;
  14460. t['Gbreve'] = 778;
  14461. t['Idotaccent'] = 278;
  14462. t['summation'] = 600;
  14463. t['Egrave'] = 667;
  14464. t['racute'] = 389;
  14465. t['omacron'] = 611;
  14466. t['Zacute'] = 611;
  14467. t['Zcaron'] = 611;
  14468. t['greaterequal'] = 549;
  14469. t['Eth'] = 722;
  14470. t['Ccedilla'] = 722;
  14471. t['lcommaaccent'] = 278;
  14472. t['tcaron'] = 389;
  14473. t['eogonek'] = 556;
  14474. t['Uogonek'] = 722;
  14475. t['Aacute'] = 722;
  14476. t['Adieresis'] = 722;
  14477. t['egrave'] = 556;
  14478. t['zacute'] = 500;
  14479. t['iogonek'] = 278;
  14480. t['Oacute'] = 778;
  14481. t['oacute'] = 611;
  14482. t['amacron'] = 556;
  14483. t['sacute'] = 556;
  14484. t['idieresis'] = 278;
  14485. t['Ocircumflex'] = 778;
  14486. t['Ugrave'] = 722;
  14487. t['Delta'] = 612;
  14488. t['thorn'] = 611;
  14489. t['twosuperior'] = 333;
  14490. t['Odieresis'] = 778;
  14491. t['mu'] = 611;
  14492. t['igrave'] = 278;
  14493. t['ohungarumlaut'] = 611;
  14494. t['Eogonek'] = 667;
  14495. t['dcroat'] = 611;
  14496. t['threequarters'] = 834;
  14497. t['Scedilla'] = 667;
  14498. t['lcaron'] = 400;
  14499. t['Kcommaaccent'] = 722;
  14500. t['Lacute'] = 611;
  14501. t['trademark'] = 1000;
  14502. t['edotaccent'] = 556;
  14503. t['Igrave'] = 278;
  14504. t['Imacron'] = 278;
  14505. t['Lcaron'] = 611;
  14506. t['onehalf'] = 834;
  14507. t['lessequal'] = 549;
  14508. t['ocircumflex'] = 611;
  14509. t['ntilde'] = 611;
  14510. t['Uhungarumlaut'] = 722;
  14511. t['Eacute'] = 667;
  14512. t['emacron'] = 556;
  14513. t['gbreve'] = 611;
  14514. t['onequarter'] = 834;
  14515. t['Scaron'] = 667;
  14516. t['Scommaaccent'] = 667;
  14517. t['Ohungarumlaut'] = 778;
  14518. t['degree'] = 400;
  14519. t['ograve'] = 611;
  14520. t['Ccaron'] = 722;
  14521. t['ugrave'] = 611;
  14522. t['radical'] = 549;
  14523. t['Dcaron'] = 722;
  14524. t['rcommaaccent'] = 389;
  14525. t['Ntilde'] = 722;
  14526. t['otilde'] = 611;
  14527. t['Rcommaaccent'] = 722;
  14528. t['Lcommaaccent'] = 611;
  14529. t['Atilde'] = 722;
  14530. t['Aogonek'] = 722;
  14531. t['Aring'] = 722;
  14532. t['Otilde'] = 778;
  14533. t['zdotaccent'] = 500;
  14534. t['Ecaron'] = 667;
  14535. t['Iogonek'] = 278;
  14536. t['kcommaaccent'] = 556;
  14537. t['minus'] = 584;
  14538. t['Icircumflex'] = 278;
  14539. t['ncaron'] = 611;
  14540. t['tcommaaccent'] = 333;
  14541. t['logicalnot'] = 584;
  14542. t['odieresis'] = 611;
  14543. t['udieresis'] = 611;
  14544. t['notequal'] = 549;
  14545. t['gcommaaccent'] = 611;
  14546. t['eth'] = 611;
  14547. t['zcaron'] = 500;
  14548. t['ncommaaccent'] = 611;
  14549. t['onesuperior'] = 333;
  14550. t['imacron'] = 278;
  14551. t['Euro'] = 556;
  14552. });
  14553. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14554. t['space'] = 278;
  14555. t['exclam'] = 278;
  14556. t['quotedbl'] = 355;
  14557. t['numbersign'] = 556;
  14558. t['dollar'] = 556;
  14559. t['percent'] = 889;
  14560. t['ampersand'] = 667;
  14561. t['quoteright'] = 222;
  14562. t['parenleft'] = 333;
  14563. t['parenright'] = 333;
  14564. t['asterisk'] = 389;
  14565. t['plus'] = 584;
  14566. t['comma'] = 278;
  14567. t['hyphen'] = 333;
  14568. t['period'] = 278;
  14569. t['slash'] = 278;
  14570. t['zero'] = 556;
  14571. t['one'] = 556;
  14572. t['two'] = 556;
  14573. t['three'] = 556;
  14574. t['four'] = 556;
  14575. t['five'] = 556;
  14576. t['six'] = 556;
  14577. t['seven'] = 556;
  14578. t['eight'] = 556;
  14579. t['nine'] = 556;
  14580. t['colon'] = 278;
  14581. t['semicolon'] = 278;
  14582. t['less'] = 584;
  14583. t['equal'] = 584;
  14584. t['greater'] = 584;
  14585. t['question'] = 556;
  14586. t['at'] = 1015;
  14587. t['A'] = 667;
  14588. t['B'] = 667;
  14589. t['C'] = 722;
  14590. t['D'] = 722;
  14591. t['E'] = 667;
  14592. t['F'] = 611;
  14593. t['G'] = 778;
  14594. t['H'] = 722;
  14595. t['I'] = 278;
  14596. t['J'] = 500;
  14597. t['K'] = 667;
  14598. t['L'] = 556;
  14599. t['M'] = 833;
  14600. t['N'] = 722;
  14601. t['O'] = 778;
  14602. t['P'] = 667;
  14603. t['Q'] = 778;
  14604. t['R'] = 722;
  14605. t['S'] = 667;
  14606. t['T'] = 611;
  14607. t['U'] = 722;
  14608. t['V'] = 667;
  14609. t['W'] = 944;
  14610. t['X'] = 667;
  14611. t['Y'] = 667;
  14612. t['Z'] = 611;
  14613. t['bracketleft'] = 278;
  14614. t['backslash'] = 278;
  14615. t['bracketright'] = 278;
  14616. t['asciicircum'] = 469;
  14617. t['underscore'] = 556;
  14618. t['quoteleft'] = 222;
  14619. t['a'] = 556;
  14620. t['b'] = 556;
  14621. t['c'] = 500;
  14622. t['d'] = 556;
  14623. t['e'] = 556;
  14624. t['f'] = 278;
  14625. t['g'] = 556;
  14626. t['h'] = 556;
  14627. t['i'] = 222;
  14628. t['j'] = 222;
  14629. t['k'] = 500;
  14630. t['l'] = 222;
  14631. t['m'] = 833;
  14632. t['n'] = 556;
  14633. t['o'] = 556;
  14634. t['p'] = 556;
  14635. t['q'] = 556;
  14636. t['r'] = 333;
  14637. t['s'] = 500;
  14638. t['t'] = 278;
  14639. t['u'] = 556;
  14640. t['v'] = 500;
  14641. t['w'] = 722;
  14642. t['x'] = 500;
  14643. t['y'] = 500;
  14644. t['z'] = 500;
  14645. t['braceleft'] = 334;
  14646. t['bar'] = 260;
  14647. t['braceright'] = 334;
  14648. t['asciitilde'] = 584;
  14649. t['exclamdown'] = 333;
  14650. t['cent'] = 556;
  14651. t['sterling'] = 556;
  14652. t['fraction'] = 167;
  14653. t['yen'] = 556;
  14654. t['florin'] = 556;
  14655. t['section'] = 556;
  14656. t['currency'] = 556;
  14657. t['quotesingle'] = 191;
  14658. t['quotedblleft'] = 333;
  14659. t['guillemotleft'] = 556;
  14660. t['guilsinglleft'] = 333;
  14661. t['guilsinglright'] = 333;
  14662. t['fi'] = 500;
  14663. t['fl'] = 500;
  14664. t['endash'] = 556;
  14665. t['dagger'] = 556;
  14666. t['daggerdbl'] = 556;
  14667. t['periodcentered'] = 278;
  14668. t['paragraph'] = 537;
  14669. t['bullet'] = 350;
  14670. t['quotesinglbase'] = 222;
  14671. t['quotedblbase'] = 333;
  14672. t['quotedblright'] = 333;
  14673. t['guillemotright'] = 556;
  14674. t['ellipsis'] = 1000;
  14675. t['perthousand'] = 1000;
  14676. t['questiondown'] = 611;
  14677. t['grave'] = 333;
  14678. t['acute'] = 333;
  14679. t['circumflex'] = 333;
  14680. t['tilde'] = 333;
  14681. t['macron'] = 333;
  14682. t['breve'] = 333;
  14683. t['dotaccent'] = 333;
  14684. t['dieresis'] = 333;
  14685. t['ring'] = 333;
  14686. t['cedilla'] = 333;
  14687. t['hungarumlaut'] = 333;
  14688. t['ogonek'] = 333;
  14689. t['caron'] = 333;
  14690. t['emdash'] = 1000;
  14691. t['AE'] = 1000;
  14692. t['ordfeminine'] = 370;
  14693. t['Lslash'] = 556;
  14694. t['Oslash'] = 778;
  14695. t['OE'] = 1000;
  14696. t['ordmasculine'] = 365;
  14697. t['ae'] = 889;
  14698. t['dotlessi'] = 278;
  14699. t['lslash'] = 222;
  14700. t['oslash'] = 611;
  14701. t['oe'] = 944;
  14702. t['germandbls'] = 611;
  14703. t['Idieresis'] = 278;
  14704. t['eacute'] = 556;
  14705. t['abreve'] = 556;
  14706. t['uhungarumlaut'] = 556;
  14707. t['ecaron'] = 556;
  14708. t['Ydieresis'] = 667;
  14709. t['divide'] = 584;
  14710. t['Yacute'] = 667;
  14711. t['Acircumflex'] = 667;
  14712. t['aacute'] = 556;
  14713. t['Ucircumflex'] = 722;
  14714. t['yacute'] = 500;
  14715. t['scommaaccent'] = 500;
  14716. t['ecircumflex'] = 556;
  14717. t['Uring'] = 722;
  14718. t['Udieresis'] = 722;
  14719. t['aogonek'] = 556;
  14720. t['Uacute'] = 722;
  14721. t['uogonek'] = 556;
  14722. t['Edieresis'] = 667;
  14723. t['Dcroat'] = 722;
  14724. t['commaaccent'] = 250;
  14725. t['copyright'] = 737;
  14726. t['Emacron'] = 667;
  14727. t['ccaron'] = 500;
  14728. t['aring'] = 556;
  14729. t['Ncommaaccent'] = 722;
  14730. t['lacute'] = 222;
  14731. t['agrave'] = 556;
  14732. t['Tcommaaccent'] = 611;
  14733. t['Cacute'] = 722;
  14734. t['atilde'] = 556;
  14735. t['Edotaccent'] = 667;
  14736. t['scaron'] = 500;
  14737. t['scedilla'] = 500;
  14738. t['iacute'] = 278;
  14739. t['lozenge'] = 471;
  14740. t['Rcaron'] = 722;
  14741. t['Gcommaaccent'] = 778;
  14742. t['ucircumflex'] = 556;
  14743. t['acircumflex'] = 556;
  14744. t['Amacron'] = 667;
  14745. t['rcaron'] = 333;
  14746. t['ccedilla'] = 500;
  14747. t['Zdotaccent'] = 611;
  14748. t['Thorn'] = 667;
  14749. t['Omacron'] = 778;
  14750. t['Racute'] = 722;
  14751. t['Sacute'] = 667;
  14752. t['dcaron'] = 643;
  14753. t['Umacron'] = 722;
  14754. t['uring'] = 556;
  14755. t['threesuperior'] = 333;
  14756. t['Ograve'] = 778;
  14757. t['Agrave'] = 667;
  14758. t['Abreve'] = 667;
  14759. t['multiply'] = 584;
  14760. t['uacute'] = 556;
  14761. t['Tcaron'] = 611;
  14762. t['partialdiff'] = 476;
  14763. t['ydieresis'] = 500;
  14764. t['Nacute'] = 722;
  14765. t['icircumflex'] = 278;
  14766. t['Ecircumflex'] = 667;
  14767. t['adieresis'] = 556;
  14768. t['edieresis'] = 556;
  14769. t['cacute'] = 500;
  14770. t['nacute'] = 556;
  14771. t['umacron'] = 556;
  14772. t['Ncaron'] = 722;
  14773. t['Iacute'] = 278;
  14774. t['plusminus'] = 584;
  14775. t['brokenbar'] = 260;
  14776. t['registered'] = 737;
  14777. t['Gbreve'] = 778;
  14778. t['Idotaccent'] = 278;
  14779. t['summation'] = 600;
  14780. t['Egrave'] = 667;
  14781. t['racute'] = 333;
  14782. t['omacron'] = 556;
  14783. t['Zacute'] = 611;
  14784. t['Zcaron'] = 611;
  14785. t['greaterequal'] = 549;
  14786. t['Eth'] = 722;
  14787. t['Ccedilla'] = 722;
  14788. t['lcommaaccent'] = 222;
  14789. t['tcaron'] = 317;
  14790. t['eogonek'] = 556;
  14791. t['Uogonek'] = 722;
  14792. t['Aacute'] = 667;
  14793. t['Adieresis'] = 667;
  14794. t['egrave'] = 556;
  14795. t['zacute'] = 500;
  14796. t['iogonek'] = 222;
  14797. t['Oacute'] = 778;
  14798. t['oacute'] = 556;
  14799. t['amacron'] = 556;
  14800. t['sacute'] = 500;
  14801. t['idieresis'] = 278;
  14802. t['Ocircumflex'] = 778;
  14803. t['Ugrave'] = 722;
  14804. t['Delta'] = 612;
  14805. t['thorn'] = 556;
  14806. t['twosuperior'] = 333;
  14807. t['Odieresis'] = 778;
  14808. t['mu'] = 556;
  14809. t['igrave'] = 278;
  14810. t['ohungarumlaut'] = 556;
  14811. t['Eogonek'] = 667;
  14812. t['dcroat'] = 556;
  14813. t['threequarters'] = 834;
  14814. t['Scedilla'] = 667;
  14815. t['lcaron'] = 299;
  14816. t['Kcommaaccent'] = 667;
  14817. t['Lacute'] = 556;
  14818. t['trademark'] = 1000;
  14819. t['edotaccent'] = 556;
  14820. t['Igrave'] = 278;
  14821. t['Imacron'] = 278;
  14822. t['Lcaron'] = 556;
  14823. t['onehalf'] = 834;
  14824. t['lessequal'] = 549;
  14825. t['ocircumflex'] = 556;
  14826. t['ntilde'] = 556;
  14827. t['Uhungarumlaut'] = 722;
  14828. t['Eacute'] = 667;
  14829. t['emacron'] = 556;
  14830. t['gbreve'] = 556;
  14831. t['onequarter'] = 834;
  14832. t['Scaron'] = 667;
  14833. t['Scommaaccent'] = 667;
  14834. t['Ohungarumlaut'] = 778;
  14835. t['degree'] = 400;
  14836. t['ograve'] = 556;
  14837. t['Ccaron'] = 722;
  14838. t['ugrave'] = 556;
  14839. t['radical'] = 453;
  14840. t['Dcaron'] = 722;
  14841. t['rcommaaccent'] = 333;
  14842. t['Ntilde'] = 722;
  14843. t['otilde'] = 556;
  14844. t['Rcommaaccent'] = 722;
  14845. t['Lcommaaccent'] = 556;
  14846. t['Atilde'] = 667;
  14847. t['Aogonek'] = 667;
  14848. t['Aring'] = 667;
  14849. t['Otilde'] = 778;
  14850. t['zdotaccent'] = 500;
  14851. t['Ecaron'] = 667;
  14852. t['Iogonek'] = 278;
  14853. t['kcommaaccent'] = 500;
  14854. t['minus'] = 584;
  14855. t['Icircumflex'] = 278;
  14856. t['ncaron'] = 556;
  14857. t['tcommaaccent'] = 278;
  14858. t['logicalnot'] = 584;
  14859. t['odieresis'] = 556;
  14860. t['udieresis'] = 556;
  14861. t['notequal'] = 549;
  14862. t['gcommaaccent'] = 556;
  14863. t['eth'] = 556;
  14864. t['zcaron'] = 500;
  14865. t['ncommaaccent'] = 556;
  14866. t['onesuperior'] = 333;
  14867. t['imacron'] = 278;
  14868. t['Euro'] = 556;
  14869. });
  14870. t['Symbol'] = getLookupTableFactory(function (t) {
  14871. t['space'] = 250;
  14872. t['exclam'] = 333;
  14873. t['universal'] = 713;
  14874. t['numbersign'] = 500;
  14875. t['existential'] = 549;
  14876. t['percent'] = 833;
  14877. t['ampersand'] = 778;
  14878. t['suchthat'] = 439;
  14879. t['parenleft'] = 333;
  14880. t['parenright'] = 333;
  14881. t['asteriskmath'] = 500;
  14882. t['plus'] = 549;
  14883. t['comma'] = 250;
  14884. t['minus'] = 549;
  14885. t['period'] = 250;
  14886. t['slash'] = 278;
  14887. t['zero'] = 500;
  14888. t['one'] = 500;
  14889. t['two'] = 500;
  14890. t['three'] = 500;
  14891. t['four'] = 500;
  14892. t['five'] = 500;
  14893. t['six'] = 500;
  14894. t['seven'] = 500;
  14895. t['eight'] = 500;
  14896. t['nine'] = 500;
  14897. t['colon'] = 278;
  14898. t['semicolon'] = 278;
  14899. t['less'] = 549;
  14900. t['equal'] = 549;
  14901. t['greater'] = 549;
  14902. t['question'] = 444;
  14903. t['congruent'] = 549;
  14904. t['Alpha'] = 722;
  14905. t['Beta'] = 667;
  14906. t['Chi'] = 722;
  14907. t['Delta'] = 612;
  14908. t['Epsilon'] = 611;
  14909. t['Phi'] = 763;
  14910. t['Gamma'] = 603;
  14911. t['Eta'] = 722;
  14912. t['Iota'] = 333;
  14913. t['theta1'] = 631;
  14914. t['Kappa'] = 722;
  14915. t['Lambda'] = 686;
  14916. t['Mu'] = 889;
  14917. t['Nu'] = 722;
  14918. t['Omicron'] = 722;
  14919. t['Pi'] = 768;
  14920. t['Theta'] = 741;
  14921. t['Rho'] = 556;
  14922. t['Sigma'] = 592;
  14923. t['Tau'] = 611;
  14924. t['Upsilon'] = 690;
  14925. t['sigma1'] = 439;
  14926. t['Omega'] = 768;
  14927. t['Xi'] = 645;
  14928. t['Psi'] = 795;
  14929. t['Zeta'] = 611;
  14930. t['bracketleft'] = 333;
  14931. t['therefore'] = 863;
  14932. t['bracketright'] = 333;
  14933. t['perpendicular'] = 658;
  14934. t['underscore'] = 500;
  14935. t['radicalex'] = 500;
  14936. t['alpha'] = 631;
  14937. t['beta'] = 549;
  14938. t['chi'] = 549;
  14939. t['delta'] = 494;
  14940. t['epsilon'] = 439;
  14941. t['phi'] = 521;
  14942. t['gamma'] = 411;
  14943. t['eta'] = 603;
  14944. t['iota'] = 329;
  14945. t['phi1'] = 603;
  14946. t['kappa'] = 549;
  14947. t['lambda'] = 549;
  14948. t['mu'] = 576;
  14949. t['nu'] = 521;
  14950. t['omicron'] = 549;
  14951. t['pi'] = 549;
  14952. t['theta'] = 521;
  14953. t['rho'] = 549;
  14954. t['sigma'] = 603;
  14955. t['tau'] = 439;
  14956. t['upsilon'] = 576;
  14957. t['omega1'] = 713;
  14958. t['omega'] = 686;
  14959. t['xi'] = 493;
  14960. t['psi'] = 686;
  14961. t['zeta'] = 494;
  14962. t['braceleft'] = 480;
  14963. t['bar'] = 200;
  14964. t['braceright'] = 480;
  14965. t['similar'] = 549;
  14966. t['Euro'] = 750;
  14967. t['Upsilon1'] = 620;
  14968. t['minute'] = 247;
  14969. t['lessequal'] = 549;
  14970. t['fraction'] = 167;
  14971. t['infinity'] = 713;
  14972. t['florin'] = 500;
  14973. t['club'] = 753;
  14974. t['diamond'] = 753;
  14975. t['heart'] = 753;
  14976. t['spade'] = 753;
  14977. t['arrowboth'] = 1042;
  14978. t['arrowleft'] = 987;
  14979. t['arrowup'] = 603;
  14980. t['arrowright'] = 987;
  14981. t['arrowdown'] = 603;
  14982. t['degree'] = 400;
  14983. t['plusminus'] = 549;
  14984. t['second'] = 411;
  14985. t['greaterequal'] = 549;
  14986. t['multiply'] = 549;
  14987. t['proportional'] = 713;
  14988. t['partialdiff'] = 494;
  14989. t['bullet'] = 460;
  14990. t['divide'] = 549;
  14991. t['notequal'] = 549;
  14992. t['equivalence'] = 549;
  14993. t['approxequal'] = 549;
  14994. t['ellipsis'] = 1000;
  14995. t['arrowvertex'] = 603;
  14996. t['arrowhorizex'] = 1000;
  14997. t['carriagereturn'] = 658;
  14998. t['aleph'] = 823;
  14999. t['Ifraktur'] = 686;
  15000. t['Rfraktur'] = 795;
  15001. t['weierstrass'] = 987;
  15002. t['circlemultiply'] = 768;
  15003. t['circleplus'] = 768;
  15004. t['emptyset'] = 823;
  15005. t['intersection'] = 768;
  15006. t['union'] = 768;
  15007. t['propersuperset'] = 713;
  15008. t['reflexsuperset'] = 713;
  15009. t['notsubset'] = 713;
  15010. t['propersubset'] = 713;
  15011. t['reflexsubset'] = 713;
  15012. t['element'] = 713;
  15013. t['notelement'] = 713;
  15014. t['angle'] = 768;
  15015. t['gradient'] = 713;
  15016. t['registerserif'] = 790;
  15017. t['copyrightserif'] = 790;
  15018. t['trademarkserif'] = 890;
  15019. t['product'] = 823;
  15020. t['radical'] = 549;
  15021. t['dotmath'] = 250;
  15022. t['logicalnot'] = 713;
  15023. t['logicaland'] = 603;
  15024. t['logicalor'] = 603;
  15025. t['arrowdblboth'] = 1042;
  15026. t['arrowdblleft'] = 987;
  15027. t['arrowdblup'] = 603;
  15028. t['arrowdblright'] = 987;
  15029. t['arrowdbldown'] = 603;
  15030. t['lozenge'] = 494;
  15031. t['angleleft'] = 329;
  15032. t['registersans'] = 790;
  15033. t['copyrightsans'] = 790;
  15034. t['trademarksans'] = 786;
  15035. t['summation'] = 713;
  15036. t['parenlefttp'] = 384;
  15037. t['parenleftex'] = 384;
  15038. t['parenleftbt'] = 384;
  15039. t['bracketlefttp'] = 384;
  15040. t['bracketleftex'] = 384;
  15041. t['bracketleftbt'] = 384;
  15042. t['bracelefttp'] = 494;
  15043. t['braceleftmid'] = 494;
  15044. t['braceleftbt'] = 494;
  15045. t['braceex'] = 494;
  15046. t['angleright'] = 329;
  15047. t['integral'] = 274;
  15048. t['integraltp'] = 686;
  15049. t['integralex'] = 686;
  15050. t['integralbt'] = 686;
  15051. t['parenrighttp'] = 384;
  15052. t['parenrightex'] = 384;
  15053. t['parenrightbt'] = 384;
  15054. t['bracketrighttp'] = 384;
  15055. t['bracketrightex'] = 384;
  15056. t['bracketrightbt'] = 384;
  15057. t['bracerighttp'] = 494;
  15058. t['bracerightmid'] = 494;
  15059. t['bracerightbt'] = 494;
  15060. t['apple'] = 790;
  15061. });
  15062. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15063. t['space'] = 250;
  15064. t['exclam'] = 333;
  15065. t['quotedbl'] = 408;
  15066. t['numbersign'] = 500;
  15067. t['dollar'] = 500;
  15068. t['percent'] = 833;
  15069. t['ampersand'] = 778;
  15070. t['quoteright'] = 333;
  15071. t['parenleft'] = 333;
  15072. t['parenright'] = 333;
  15073. t['asterisk'] = 500;
  15074. t['plus'] = 564;
  15075. t['comma'] = 250;
  15076. t['hyphen'] = 333;
  15077. t['period'] = 250;
  15078. t['slash'] = 278;
  15079. t['zero'] = 500;
  15080. t['one'] = 500;
  15081. t['two'] = 500;
  15082. t['three'] = 500;
  15083. t['four'] = 500;
  15084. t['five'] = 500;
  15085. t['six'] = 500;
  15086. t['seven'] = 500;
  15087. t['eight'] = 500;
  15088. t['nine'] = 500;
  15089. t['colon'] = 278;
  15090. t['semicolon'] = 278;
  15091. t['less'] = 564;
  15092. t['equal'] = 564;
  15093. t['greater'] = 564;
  15094. t['question'] = 444;
  15095. t['at'] = 921;
  15096. t['A'] = 722;
  15097. t['B'] = 667;
  15098. t['C'] = 667;
  15099. t['D'] = 722;
  15100. t['E'] = 611;
  15101. t['F'] = 556;
  15102. t['G'] = 722;
  15103. t['H'] = 722;
  15104. t['I'] = 333;
  15105. t['J'] = 389;
  15106. t['K'] = 722;
  15107. t['L'] = 611;
  15108. t['M'] = 889;
  15109. t['N'] = 722;
  15110. t['O'] = 722;
  15111. t['P'] = 556;
  15112. t['Q'] = 722;
  15113. t['R'] = 667;
  15114. t['S'] = 556;
  15115. t['T'] = 611;
  15116. t['U'] = 722;
  15117. t['V'] = 722;
  15118. t['W'] = 944;
  15119. t['X'] = 722;
  15120. t['Y'] = 722;
  15121. t['Z'] = 611;
  15122. t['bracketleft'] = 333;
  15123. t['backslash'] = 278;
  15124. t['bracketright'] = 333;
  15125. t['asciicircum'] = 469;
  15126. t['underscore'] = 500;
  15127. t['quoteleft'] = 333;
  15128. t['a'] = 444;
  15129. t['b'] = 500;
  15130. t['c'] = 444;
  15131. t['d'] = 500;
  15132. t['e'] = 444;
  15133. t['f'] = 333;
  15134. t['g'] = 500;
  15135. t['h'] = 500;
  15136. t['i'] = 278;
  15137. t['j'] = 278;
  15138. t['k'] = 500;
  15139. t['l'] = 278;
  15140. t['m'] = 778;
  15141. t['n'] = 500;
  15142. t['o'] = 500;
  15143. t['p'] = 500;
  15144. t['q'] = 500;
  15145. t['r'] = 333;
  15146. t['s'] = 389;
  15147. t['t'] = 278;
  15148. t['u'] = 500;
  15149. t['v'] = 500;
  15150. t['w'] = 722;
  15151. t['x'] = 500;
  15152. t['y'] = 500;
  15153. t['z'] = 444;
  15154. t['braceleft'] = 480;
  15155. t['bar'] = 200;
  15156. t['braceright'] = 480;
  15157. t['asciitilde'] = 541;
  15158. t['exclamdown'] = 333;
  15159. t['cent'] = 500;
  15160. t['sterling'] = 500;
  15161. t['fraction'] = 167;
  15162. t['yen'] = 500;
  15163. t['florin'] = 500;
  15164. t['section'] = 500;
  15165. t['currency'] = 500;
  15166. t['quotesingle'] = 180;
  15167. t['quotedblleft'] = 444;
  15168. t['guillemotleft'] = 500;
  15169. t['guilsinglleft'] = 333;
  15170. t['guilsinglright'] = 333;
  15171. t['fi'] = 556;
  15172. t['fl'] = 556;
  15173. t['endash'] = 500;
  15174. t['dagger'] = 500;
  15175. t['daggerdbl'] = 500;
  15176. t['periodcentered'] = 250;
  15177. t['paragraph'] = 453;
  15178. t['bullet'] = 350;
  15179. t['quotesinglbase'] = 333;
  15180. t['quotedblbase'] = 444;
  15181. t['quotedblright'] = 444;
  15182. t['guillemotright'] = 500;
  15183. t['ellipsis'] = 1000;
  15184. t['perthousand'] = 1000;
  15185. t['questiondown'] = 444;
  15186. t['grave'] = 333;
  15187. t['acute'] = 333;
  15188. t['circumflex'] = 333;
  15189. t['tilde'] = 333;
  15190. t['macron'] = 333;
  15191. t['breve'] = 333;
  15192. t['dotaccent'] = 333;
  15193. t['dieresis'] = 333;
  15194. t['ring'] = 333;
  15195. t['cedilla'] = 333;
  15196. t['hungarumlaut'] = 333;
  15197. t['ogonek'] = 333;
  15198. t['caron'] = 333;
  15199. t['emdash'] = 1000;
  15200. t['AE'] = 889;
  15201. t['ordfeminine'] = 276;
  15202. t['Lslash'] = 611;
  15203. t['Oslash'] = 722;
  15204. t['OE'] = 889;
  15205. t['ordmasculine'] = 310;
  15206. t['ae'] = 667;
  15207. t['dotlessi'] = 278;
  15208. t['lslash'] = 278;
  15209. t['oslash'] = 500;
  15210. t['oe'] = 722;
  15211. t['germandbls'] = 500;
  15212. t['Idieresis'] = 333;
  15213. t['eacute'] = 444;
  15214. t['abreve'] = 444;
  15215. t['uhungarumlaut'] = 500;
  15216. t['ecaron'] = 444;
  15217. t['Ydieresis'] = 722;
  15218. t['divide'] = 564;
  15219. t['Yacute'] = 722;
  15220. t['Acircumflex'] = 722;
  15221. t['aacute'] = 444;
  15222. t['Ucircumflex'] = 722;
  15223. t['yacute'] = 500;
  15224. t['scommaaccent'] = 389;
  15225. t['ecircumflex'] = 444;
  15226. t['Uring'] = 722;
  15227. t['Udieresis'] = 722;
  15228. t['aogonek'] = 444;
  15229. t['Uacute'] = 722;
  15230. t['uogonek'] = 500;
  15231. t['Edieresis'] = 611;
  15232. t['Dcroat'] = 722;
  15233. t['commaaccent'] = 250;
  15234. t['copyright'] = 760;
  15235. t['Emacron'] = 611;
  15236. t['ccaron'] = 444;
  15237. t['aring'] = 444;
  15238. t['Ncommaaccent'] = 722;
  15239. t['lacute'] = 278;
  15240. t['agrave'] = 444;
  15241. t['Tcommaaccent'] = 611;
  15242. t['Cacute'] = 667;
  15243. t['atilde'] = 444;
  15244. t['Edotaccent'] = 611;
  15245. t['scaron'] = 389;
  15246. t['scedilla'] = 389;
  15247. t['iacute'] = 278;
  15248. t['lozenge'] = 471;
  15249. t['Rcaron'] = 667;
  15250. t['Gcommaaccent'] = 722;
  15251. t['ucircumflex'] = 500;
  15252. t['acircumflex'] = 444;
  15253. t['Amacron'] = 722;
  15254. t['rcaron'] = 333;
  15255. t['ccedilla'] = 444;
  15256. t['Zdotaccent'] = 611;
  15257. t['Thorn'] = 556;
  15258. t['Omacron'] = 722;
  15259. t['Racute'] = 667;
  15260. t['Sacute'] = 556;
  15261. t['dcaron'] = 588;
  15262. t['Umacron'] = 722;
  15263. t['uring'] = 500;
  15264. t['threesuperior'] = 300;
  15265. t['Ograve'] = 722;
  15266. t['Agrave'] = 722;
  15267. t['Abreve'] = 722;
  15268. t['multiply'] = 564;
  15269. t['uacute'] = 500;
  15270. t['Tcaron'] = 611;
  15271. t['partialdiff'] = 476;
  15272. t['ydieresis'] = 500;
  15273. t['Nacute'] = 722;
  15274. t['icircumflex'] = 278;
  15275. t['Ecircumflex'] = 611;
  15276. t['adieresis'] = 444;
  15277. t['edieresis'] = 444;
  15278. t['cacute'] = 444;
  15279. t['nacute'] = 500;
  15280. t['umacron'] = 500;
  15281. t['Ncaron'] = 722;
  15282. t['Iacute'] = 333;
  15283. t['plusminus'] = 564;
  15284. t['brokenbar'] = 200;
  15285. t['registered'] = 760;
  15286. t['Gbreve'] = 722;
  15287. t['Idotaccent'] = 333;
  15288. t['summation'] = 600;
  15289. t['Egrave'] = 611;
  15290. t['racute'] = 333;
  15291. t['omacron'] = 500;
  15292. t['Zacute'] = 611;
  15293. t['Zcaron'] = 611;
  15294. t['greaterequal'] = 549;
  15295. t['Eth'] = 722;
  15296. t['Ccedilla'] = 667;
  15297. t['lcommaaccent'] = 278;
  15298. t['tcaron'] = 326;
  15299. t['eogonek'] = 444;
  15300. t['Uogonek'] = 722;
  15301. t['Aacute'] = 722;
  15302. t['Adieresis'] = 722;
  15303. t['egrave'] = 444;
  15304. t['zacute'] = 444;
  15305. t['iogonek'] = 278;
  15306. t['Oacute'] = 722;
  15307. t['oacute'] = 500;
  15308. t['amacron'] = 444;
  15309. t['sacute'] = 389;
  15310. t['idieresis'] = 278;
  15311. t['Ocircumflex'] = 722;
  15312. t['Ugrave'] = 722;
  15313. t['Delta'] = 612;
  15314. t['thorn'] = 500;
  15315. t['twosuperior'] = 300;
  15316. t['Odieresis'] = 722;
  15317. t['mu'] = 500;
  15318. t['igrave'] = 278;
  15319. t['ohungarumlaut'] = 500;
  15320. t['Eogonek'] = 611;
  15321. t['dcroat'] = 500;
  15322. t['threequarters'] = 750;
  15323. t['Scedilla'] = 556;
  15324. t['lcaron'] = 344;
  15325. t['Kcommaaccent'] = 722;
  15326. t['Lacute'] = 611;
  15327. t['trademark'] = 980;
  15328. t['edotaccent'] = 444;
  15329. t['Igrave'] = 333;
  15330. t['Imacron'] = 333;
  15331. t['Lcaron'] = 611;
  15332. t['onehalf'] = 750;
  15333. t['lessequal'] = 549;
  15334. t['ocircumflex'] = 500;
  15335. t['ntilde'] = 500;
  15336. t['Uhungarumlaut'] = 722;
  15337. t['Eacute'] = 611;
  15338. t['emacron'] = 444;
  15339. t['gbreve'] = 500;
  15340. t['onequarter'] = 750;
  15341. t['Scaron'] = 556;
  15342. t['Scommaaccent'] = 556;
  15343. t['Ohungarumlaut'] = 722;
  15344. t['degree'] = 400;
  15345. t['ograve'] = 500;
  15346. t['Ccaron'] = 667;
  15347. t['ugrave'] = 500;
  15348. t['radical'] = 453;
  15349. t['Dcaron'] = 722;
  15350. t['rcommaaccent'] = 333;
  15351. t['Ntilde'] = 722;
  15352. t['otilde'] = 500;
  15353. t['Rcommaaccent'] = 667;
  15354. t['Lcommaaccent'] = 611;
  15355. t['Atilde'] = 722;
  15356. t['Aogonek'] = 722;
  15357. t['Aring'] = 722;
  15358. t['Otilde'] = 722;
  15359. t['zdotaccent'] = 444;
  15360. t['Ecaron'] = 611;
  15361. t['Iogonek'] = 333;
  15362. t['kcommaaccent'] = 500;
  15363. t['minus'] = 564;
  15364. t['Icircumflex'] = 333;
  15365. t['ncaron'] = 500;
  15366. t['tcommaaccent'] = 278;
  15367. t['logicalnot'] = 564;
  15368. t['odieresis'] = 500;
  15369. t['udieresis'] = 500;
  15370. t['notequal'] = 549;
  15371. t['gcommaaccent'] = 500;
  15372. t['eth'] = 500;
  15373. t['zcaron'] = 444;
  15374. t['ncommaaccent'] = 500;
  15375. t['onesuperior'] = 300;
  15376. t['imacron'] = 278;
  15377. t['Euro'] = 500;
  15378. });
  15379. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15380. t['space'] = 250;
  15381. t['exclam'] = 333;
  15382. t['quotedbl'] = 555;
  15383. t['numbersign'] = 500;
  15384. t['dollar'] = 500;
  15385. t['percent'] = 1000;
  15386. t['ampersand'] = 833;
  15387. t['quoteright'] = 333;
  15388. t['parenleft'] = 333;
  15389. t['parenright'] = 333;
  15390. t['asterisk'] = 500;
  15391. t['plus'] = 570;
  15392. t['comma'] = 250;
  15393. t['hyphen'] = 333;
  15394. t['period'] = 250;
  15395. t['slash'] = 278;
  15396. t['zero'] = 500;
  15397. t['one'] = 500;
  15398. t['two'] = 500;
  15399. t['three'] = 500;
  15400. t['four'] = 500;
  15401. t['five'] = 500;
  15402. t['six'] = 500;
  15403. t['seven'] = 500;
  15404. t['eight'] = 500;
  15405. t['nine'] = 500;
  15406. t['colon'] = 333;
  15407. t['semicolon'] = 333;
  15408. t['less'] = 570;
  15409. t['equal'] = 570;
  15410. t['greater'] = 570;
  15411. t['question'] = 500;
  15412. t['at'] = 930;
  15413. t['A'] = 722;
  15414. t['B'] = 667;
  15415. t['C'] = 722;
  15416. t['D'] = 722;
  15417. t['E'] = 667;
  15418. t['F'] = 611;
  15419. t['G'] = 778;
  15420. t['H'] = 778;
  15421. t['I'] = 389;
  15422. t['J'] = 500;
  15423. t['K'] = 778;
  15424. t['L'] = 667;
  15425. t['M'] = 944;
  15426. t['N'] = 722;
  15427. t['O'] = 778;
  15428. t['P'] = 611;
  15429. t['Q'] = 778;
  15430. t['R'] = 722;
  15431. t['S'] = 556;
  15432. t['T'] = 667;
  15433. t['U'] = 722;
  15434. t['V'] = 722;
  15435. t['W'] = 1000;
  15436. t['X'] = 722;
  15437. t['Y'] = 722;
  15438. t['Z'] = 667;
  15439. t['bracketleft'] = 333;
  15440. t['backslash'] = 278;
  15441. t['bracketright'] = 333;
  15442. t['asciicircum'] = 581;
  15443. t['underscore'] = 500;
  15444. t['quoteleft'] = 333;
  15445. t['a'] = 500;
  15446. t['b'] = 556;
  15447. t['c'] = 444;
  15448. t['d'] = 556;
  15449. t['e'] = 444;
  15450. t['f'] = 333;
  15451. t['g'] = 500;
  15452. t['h'] = 556;
  15453. t['i'] = 278;
  15454. t['j'] = 333;
  15455. t['k'] = 556;
  15456. t['l'] = 278;
  15457. t['m'] = 833;
  15458. t['n'] = 556;
  15459. t['o'] = 500;
  15460. t['p'] = 556;
  15461. t['q'] = 556;
  15462. t['r'] = 444;
  15463. t['s'] = 389;
  15464. t['t'] = 333;
  15465. t['u'] = 556;
  15466. t['v'] = 500;
  15467. t['w'] = 722;
  15468. t['x'] = 500;
  15469. t['y'] = 500;
  15470. t['z'] = 444;
  15471. t['braceleft'] = 394;
  15472. t['bar'] = 220;
  15473. t['braceright'] = 394;
  15474. t['asciitilde'] = 520;
  15475. t['exclamdown'] = 333;
  15476. t['cent'] = 500;
  15477. t['sterling'] = 500;
  15478. t['fraction'] = 167;
  15479. t['yen'] = 500;
  15480. t['florin'] = 500;
  15481. t['section'] = 500;
  15482. t['currency'] = 500;
  15483. t['quotesingle'] = 278;
  15484. t['quotedblleft'] = 500;
  15485. t['guillemotleft'] = 500;
  15486. t['guilsinglleft'] = 333;
  15487. t['guilsinglright'] = 333;
  15488. t['fi'] = 556;
  15489. t['fl'] = 556;
  15490. t['endash'] = 500;
  15491. t['dagger'] = 500;
  15492. t['daggerdbl'] = 500;
  15493. t['periodcentered'] = 250;
  15494. t['paragraph'] = 540;
  15495. t['bullet'] = 350;
  15496. t['quotesinglbase'] = 333;
  15497. t['quotedblbase'] = 500;
  15498. t['quotedblright'] = 500;
  15499. t['guillemotright'] = 500;
  15500. t['ellipsis'] = 1000;
  15501. t['perthousand'] = 1000;
  15502. t['questiondown'] = 500;
  15503. t['grave'] = 333;
  15504. t['acute'] = 333;
  15505. t['circumflex'] = 333;
  15506. t['tilde'] = 333;
  15507. t['macron'] = 333;
  15508. t['breve'] = 333;
  15509. t['dotaccent'] = 333;
  15510. t['dieresis'] = 333;
  15511. t['ring'] = 333;
  15512. t['cedilla'] = 333;
  15513. t['hungarumlaut'] = 333;
  15514. t['ogonek'] = 333;
  15515. t['caron'] = 333;
  15516. t['emdash'] = 1000;
  15517. t['AE'] = 1000;
  15518. t['ordfeminine'] = 300;
  15519. t['Lslash'] = 667;
  15520. t['Oslash'] = 778;
  15521. t['OE'] = 1000;
  15522. t['ordmasculine'] = 330;
  15523. t['ae'] = 722;
  15524. t['dotlessi'] = 278;
  15525. t['lslash'] = 278;
  15526. t['oslash'] = 500;
  15527. t['oe'] = 722;
  15528. t['germandbls'] = 556;
  15529. t['Idieresis'] = 389;
  15530. t['eacute'] = 444;
  15531. t['abreve'] = 500;
  15532. t['uhungarumlaut'] = 556;
  15533. t['ecaron'] = 444;
  15534. t['Ydieresis'] = 722;
  15535. t['divide'] = 570;
  15536. t['Yacute'] = 722;
  15537. t['Acircumflex'] = 722;
  15538. t['aacute'] = 500;
  15539. t['Ucircumflex'] = 722;
  15540. t['yacute'] = 500;
  15541. t['scommaaccent'] = 389;
  15542. t['ecircumflex'] = 444;
  15543. t['Uring'] = 722;
  15544. t['Udieresis'] = 722;
  15545. t['aogonek'] = 500;
  15546. t['Uacute'] = 722;
  15547. t['uogonek'] = 556;
  15548. t['Edieresis'] = 667;
  15549. t['Dcroat'] = 722;
  15550. t['commaaccent'] = 250;
  15551. t['copyright'] = 747;
  15552. t['Emacron'] = 667;
  15553. t['ccaron'] = 444;
  15554. t['aring'] = 500;
  15555. t['Ncommaaccent'] = 722;
  15556. t['lacute'] = 278;
  15557. t['agrave'] = 500;
  15558. t['Tcommaaccent'] = 667;
  15559. t['Cacute'] = 722;
  15560. t['atilde'] = 500;
  15561. t['Edotaccent'] = 667;
  15562. t['scaron'] = 389;
  15563. t['scedilla'] = 389;
  15564. t['iacute'] = 278;
  15565. t['lozenge'] = 494;
  15566. t['Rcaron'] = 722;
  15567. t['Gcommaaccent'] = 778;
  15568. t['ucircumflex'] = 556;
  15569. t['acircumflex'] = 500;
  15570. t['Amacron'] = 722;
  15571. t['rcaron'] = 444;
  15572. t['ccedilla'] = 444;
  15573. t['Zdotaccent'] = 667;
  15574. t['Thorn'] = 611;
  15575. t['Omacron'] = 778;
  15576. t['Racute'] = 722;
  15577. t['Sacute'] = 556;
  15578. t['dcaron'] = 672;
  15579. t['Umacron'] = 722;
  15580. t['uring'] = 556;
  15581. t['threesuperior'] = 300;
  15582. t['Ograve'] = 778;
  15583. t['Agrave'] = 722;
  15584. t['Abreve'] = 722;
  15585. t['multiply'] = 570;
  15586. t['uacute'] = 556;
  15587. t['Tcaron'] = 667;
  15588. t['partialdiff'] = 494;
  15589. t['ydieresis'] = 500;
  15590. t['Nacute'] = 722;
  15591. t['icircumflex'] = 278;
  15592. t['Ecircumflex'] = 667;
  15593. t['adieresis'] = 500;
  15594. t['edieresis'] = 444;
  15595. t['cacute'] = 444;
  15596. t['nacute'] = 556;
  15597. t['umacron'] = 556;
  15598. t['Ncaron'] = 722;
  15599. t['Iacute'] = 389;
  15600. t['plusminus'] = 570;
  15601. t['brokenbar'] = 220;
  15602. t['registered'] = 747;
  15603. t['Gbreve'] = 778;
  15604. t['Idotaccent'] = 389;
  15605. t['summation'] = 600;
  15606. t['Egrave'] = 667;
  15607. t['racute'] = 444;
  15608. t['omacron'] = 500;
  15609. t['Zacute'] = 667;
  15610. t['Zcaron'] = 667;
  15611. t['greaterequal'] = 549;
  15612. t['Eth'] = 722;
  15613. t['Ccedilla'] = 722;
  15614. t['lcommaaccent'] = 278;
  15615. t['tcaron'] = 416;
  15616. t['eogonek'] = 444;
  15617. t['Uogonek'] = 722;
  15618. t['Aacute'] = 722;
  15619. t['Adieresis'] = 722;
  15620. t['egrave'] = 444;
  15621. t['zacute'] = 444;
  15622. t['iogonek'] = 278;
  15623. t['Oacute'] = 778;
  15624. t['oacute'] = 500;
  15625. t['amacron'] = 500;
  15626. t['sacute'] = 389;
  15627. t['idieresis'] = 278;
  15628. t['Ocircumflex'] = 778;
  15629. t['Ugrave'] = 722;
  15630. t['Delta'] = 612;
  15631. t['thorn'] = 556;
  15632. t['twosuperior'] = 300;
  15633. t['Odieresis'] = 778;
  15634. t['mu'] = 556;
  15635. t['igrave'] = 278;
  15636. t['ohungarumlaut'] = 500;
  15637. t['Eogonek'] = 667;
  15638. t['dcroat'] = 556;
  15639. t['threequarters'] = 750;
  15640. t['Scedilla'] = 556;
  15641. t['lcaron'] = 394;
  15642. t['Kcommaaccent'] = 778;
  15643. t['Lacute'] = 667;
  15644. t['trademark'] = 1000;
  15645. t['edotaccent'] = 444;
  15646. t['Igrave'] = 389;
  15647. t['Imacron'] = 389;
  15648. t['Lcaron'] = 667;
  15649. t['onehalf'] = 750;
  15650. t['lessequal'] = 549;
  15651. t['ocircumflex'] = 500;
  15652. t['ntilde'] = 556;
  15653. t['Uhungarumlaut'] = 722;
  15654. t['Eacute'] = 667;
  15655. t['emacron'] = 444;
  15656. t['gbreve'] = 500;
  15657. t['onequarter'] = 750;
  15658. t['Scaron'] = 556;
  15659. t['Scommaaccent'] = 556;
  15660. t['Ohungarumlaut'] = 778;
  15661. t['degree'] = 400;
  15662. t['ograve'] = 500;
  15663. t['Ccaron'] = 722;
  15664. t['ugrave'] = 556;
  15665. t['radical'] = 549;
  15666. t['Dcaron'] = 722;
  15667. t['rcommaaccent'] = 444;
  15668. t['Ntilde'] = 722;
  15669. t['otilde'] = 500;
  15670. t['Rcommaaccent'] = 722;
  15671. t['Lcommaaccent'] = 667;
  15672. t['Atilde'] = 722;
  15673. t['Aogonek'] = 722;
  15674. t['Aring'] = 722;
  15675. t['Otilde'] = 778;
  15676. t['zdotaccent'] = 444;
  15677. t['Ecaron'] = 667;
  15678. t['Iogonek'] = 389;
  15679. t['kcommaaccent'] = 556;
  15680. t['minus'] = 570;
  15681. t['Icircumflex'] = 389;
  15682. t['ncaron'] = 556;
  15683. t['tcommaaccent'] = 333;
  15684. t['logicalnot'] = 570;
  15685. t['odieresis'] = 500;
  15686. t['udieresis'] = 556;
  15687. t['notequal'] = 549;
  15688. t['gcommaaccent'] = 500;
  15689. t['eth'] = 500;
  15690. t['zcaron'] = 444;
  15691. t['ncommaaccent'] = 556;
  15692. t['onesuperior'] = 300;
  15693. t['imacron'] = 278;
  15694. t['Euro'] = 500;
  15695. });
  15696. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15697. t['space'] = 250;
  15698. t['exclam'] = 389;
  15699. t['quotedbl'] = 555;
  15700. t['numbersign'] = 500;
  15701. t['dollar'] = 500;
  15702. t['percent'] = 833;
  15703. t['ampersand'] = 778;
  15704. t['quoteright'] = 333;
  15705. t['parenleft'] = 333;
  15706. t['parenright'] = 333;
  15707. t['asterisk'] = 500;
  15708. t['plus'] = 570;
  15709. t['comma'] = 250;
  15710. t['hyphen'] = 333;
  15711. t['period'] = 250;
  15712. t['slash'] = 278;
  15713. t['zero'] = 500;
  15714. t['one'] = 500;
  15715. t['two'] = 500;
  15716. t['three'] = 500;
  15717. t['four'] = 500;
  15718. t['five'] = 500;
  15719. t['six'] = 500;
  15720. t['seven'] = 500;
  15721. t['eight'] = 500;
  15722. t['nine'] = 500;
  15723. t['colon'] = 333;
  15724. t['semicolon'] = 333;
  15725. t['less'] = 570;
  15726. t['equal'] = 570;
  15727. t['greater'] = 570;
  15728. t['question'] = 500;
  15729. t['at'] = 832;
  15730. t['A'] = 667;
  15731. t['B'] = 667;
  15732. t['C'] = 667;
  15733. t['D'] = 722;
  15734. t['E'] = 667;
  15735. t['F'] = 667;
  15736. t['G'] = 722;
  15737. t['H'] = 778;
  15738. t['I'] = 389;
  15739. t['J'] = 500;
  15740. t['K'] = 667;
  15741. t['L'] = 611;
  15742. t['M'] = 889;
  15743. t['N'] = 722;
  15744. t['O'] = 722;
  15745. t['P'] = 611;
  15746. t['Q'] = 722;
  15747. t['R'] = 667;
  15748. t['S'] = 556;
  15749. t['T'] = 611;
  15750. t['U'] = 722;
  15751. t['V'] = 667;
  15752. t['W'] = 889;
  15753. t['X'] = 667;
  15754. t['Y'] = 611;
  15755. t['Z'] = 611;
  15756. t['bracketleft'] = 333;
  15757. t['backslash'] = 278;
  15758. t['bracketright'] = 333;
  15759. t['asciicircum'] = 570;
  15760. t['underscore'] = 500;
  15761. t['quoteleft'] = 333;
  15762. t['a'] = 500;
  15763. t['b'] = 500;
  15764. t['c'] = 444;
  15765. t['d'] = 500;
  15766. t['e'] = 444;
  15767. t['f'] = 333;
  15768. t['g'] = 500;
  15769. t['h'] = 556;
  15770. t['i'] = 278;
  15771. t['j'] = 278;
  15772. t['k'] = 500;
  15773. t['l'] = 278;
  15774. t['m'] = 778;
  15775. t['n'] = 556;
  15776. t['o'] = 500;
  15777. t['p'] = 500;
  15778. t['q'] = 500;
  15779. t['r'] = 389;
  15780. t['s'] = 389;
  15781. t['t'] = 278;
  15782. t['u'] = 556;
  15783. t['v'] = 444;
  15784. t['w'] = 667;
  15785. t['x'] = 500;
  15786. t['y'] = 444;
  15787. t['z'] = 389;
  15788. t['braceleft'] = 348;
  15789. t['bar'] = 220;
  15790. t['braceright'] = 348;
  15791. t['asciitilde'] = 570;
  15792. t['exclamdown'] = 389;
  15793. t['cent'] = 500;
  15794. t['sterling'] = 500;
  15795. t['fraction'] = 167;
  15796. t['yen'] = 500;
  15797. t['florin'] = 500;
  15798. t['section'] = 500;
  15799. t['currency'] = 500;
  15800. t['quotesingle'] = 278;
  15801. t['quotedblleft'] = 500;
  15802. t['guillemotleft'] = 500;
  15803. t['guilsinglleft'] = 333;
  15804. t['guilsinglright'] = 333;
  15805. t['fi'] = 556;
  15806. t['fl'] = 556;
  15807. t['endash'] = 500;
  15808. t['dagger'] = 500;
  15809. t['daggerdbl'] = 500;
  15810. t['periodcentered'] = 250;
  15811. t['paragraph'] = 500;
  15812. t['bullet'] = 350;
  15813. t['quotesinglbase'] = 333;
  15814. t['quotedblbase'] = 500;
  15815. t['quotedblright'] = 500;
  15816. t['guillemotright'] = 500;
  15817. t['ellipsis'] = 1000;
  15818. t['perthousand'] = 1000;
  15819. t['questiondown'] = 500;
  15820. t['grave'] = 333;
  15821. t['acute'] = 333;
  15822. t['circumflex'] = 333;
  15823. t['tilde'] = 333;
  15824. t['macron'] = 333;
  15825. t['breve'] = 333;
  15826. t['dotaccent'] = 333;
  15827. t['dieresis'] = 333;
  15828. t['ring'] = 333;
  15829. t['cedilla'] = 333;
  15830. t['hungarumlaut'] = 333;
  15831. t['ogonek'] = 333;
  15832. t['caron'] = 333;
  15833. t['emdash'] = 1000;
  15834. t['AE'] = 944;
  15835. t['ordfeminine'] = 266;
  15836. t['Lslash'] = 611;
  15837. t['Oslash'] = 722;
  15838. t['OE'] = 944;
  15839. t['ordmasculine'] = 300;
  15840. t['ae'] = 722;
  15841. t['dotlessi'] = 278;
  15842. t['lslash'] = 278;
  15843. t['oslash'] = 500;
  15844. t['oe'] = 722;
  15845. t['germandbls'] = 500;
  15846. t['Idieresis'] = 389;
  15847. t['eacute'] = 444;
  15848. t['abreve'] = 500;
  15849. t['uhungarumlaut'] = 556;
  15850. t['ecaron'] = 444;
  15851. t['Ydieresis'] = 611;
  15852. t['divide'] = 570;
  15853. t['Yacute'] = 611;
  15854. t['Acircumflex'] = 667;
  15855. t['aacute'] = 500;
  15856. t['Ucircumflex'] = 722;
  15857. t['yacute'] = 444;
  15858. t['scommaaccent'] = 389;
  15859. t['ecircumflex'] = 444;
  15860. t['Uring'] = 722;
  15861. t['Udieresis'] = 722;
  15862. t['aogonek'] = 500;
  15863. t['Uacute'] = 722;
  15864. t['uogonek'] = 556;
  15865. t['Edieresis'] = 667;
  15866. t['Dcroat'] = 722;
  15867. t['commaaccent'] = 250;
  15868. t['copyright'] = 747;
  15869. t['Emacron'] = 667;
  15870. t['ccaron'] = 444;
  15871. t['aring'] = 500;
  15872. t['Ncommaaccent'] = 722;
  15873. t['lacute'] = 278;
  15874. t['agrave'] = 500;
  15875. t['Tcommaaccent'] = 611;
  15876. t['Cacute'] = 667;
  15877. t['atilde'] = 500;
  15878. t['Edotaccent'] = 667;
  15879. t['scaron'] = 389;
  15880. t['scedilla'] = 389;
  15881. t['iacute'] = 278;
  15882. t['lozenge'] = 494;
  15883. t['Rcaron'] = 667;
  15884. t['Gcommaaccent'] = 722;
  15885. t['ucircumflex'] = 556;
  15886. t['acircumflex'] = 500;
  15887. t['Amacron'] = 667;
  15888. t['rcaron'] = 389;
  15889. t['ccedilla'] = 444;
  15890. t['Zdotaccent'] = 611;
  15891. t['Thorn'] = 611;
  15892. t['Omacron'] = 722;
  15893. t['Racute'] = 667;
  15894. t['Sacute'] = 556;
  15895. t['dcaron'] = 608;
  15896. t['Umacron'] = 722;
  15897. t['uring'] = 556;
  15898. t['threesuperior'] = 300;
  15899. t['Ograve'] = 722;
  15900. t['Agrave'] = 667;
  15901. t['Abreve'] = 667;
  15902. t['multiply'] = 570;
  15903. t['uacute'] = 556;
  15904. t['Tcaron'] = 611;
  15905. t['partialdiff'] = 494;
  15906. t['ydieresis'] = 444;
  15907. t['Nacute'] = 722;
  15908. t['icircumflex'] = 278;
  15909. t['Ecircumflex'] = 667;
  15910. t['adieresis'] = 500;
  15911. t['edieresis'] = 444;
  15912. t['cacute'] = 444;
  15913. t['nacute'] = 556;
  15914. t['umacron'] = 556;
  15915. t['Ncaron'] = 722;
  15916. t['Iacute'] = 389;
  15917. t['plusminus'] = 570;
  15918. t['brokenbar'] = 220;
  15919. t['registered'] = 747;
  15920. t['Gbreve'] = 722;
  15921. t['Idotaccent'] = 389;
  15922. t['summation'] = 600;
  15923. t['Egrave'] = 667;
  15924. t['racute'] = 389;
  15925. t['omacron'] = 500;
  15926. t['Zacute'] = 611;
  15927. t['Zcaron'] = 611;
  15928. t['greaterequal'] = 549;
  15929. t['Eth'] = 722;
  15930. t['Ccedilla'] = 667;
  15931. t['lcommaaccent'] = 278;
  15932. t['tcaron'] = 366;
  15933. t['eogonek'] = 444;
  15934. t['Uogonek'] = 722;
  15935. t['Aacute'] = 667;
  15936. t['Adieresis'] = 667;
  15937. t['egrave'] = 444;
  15938. t['zacute'] = 389;
  15939. t['iogonek'] = 278;
  15940. t['Oacute'] = 722;
  15941. t['oacute'] = 500;
  15942. t['amacron'] = 500;
  15943. t['sacute'] = 389;
  15944. t['idieresis'] = 278;
  15945. t['Ocircumflex'] = 722;
  15946. t['Ugrave'] = 722;
  15947. t['Delta'] = 612;
  15948. t['thorn'] = 500;
  15949. t['twosuperior'] = 300;
  15950. t['Odieresis'] = 722;
  15951. t['mu'] = 576;
  15952. t['igrave'] = 278;
  15953. t['ohungarumlaut'] = 500;
  15954. t['Eogonek'] = 667;
  15955. t['dcroat'] = 500;
  15956. t['threequarters'] = 750;
  15957. t['Scedilla'] = 556;
  15958. t['lcaron'] = 382;
  15959. t['Kcommaaccent'] = 667;
  15960. t['Lacute'] = 611;
  15961. t['trademark'] = 1000;
  15962. t['edotaccent'] = 444;
  15963. t['Igrave'] = 389;
  15964. t['Imacron'] = 389;
  15965. t['Lcaron'] = 611;
  15966. t['onehalf'] = 750;
  15967. t['lessequal'] = 549;
  15968. t['ocircumflex'] = 500;
  15969. t['ntilde'] = 556;
  15970. t['Uhungarumlaut'] = 722;
  15971. t['Eacute'] = 667;
  15972. t['emacron'] = 444;
  15973. t['gbreve'] = 500;
  15974. t['onequarter'] = 750;
  15975. t['Scaron'] = 556;
  15976. t['Scommaaccent'] = 556;
  15977. t['Ohungarumlaut'] = 722;
  15978. t['degree'] = 400;
  15979. t['ograve'] = 500;
  15980. t['Ccaron'] = 667;
  15981. t['ugrave'] = 556;
  15982. t['radical'] = 549;
  15983. t['Dcaron'] = 722;
  15984. t['rcommaaccent'] = 389;
  15985. t['Ntilde'] = 722;
  15986. t['otilde'] = 500;
  15987. t['Rcommaaccent'] = 667;
  15988. t['Lcommaaccent'] = 611;
  15989. t['Atilde'] = 667;
  15990. t['Aogonek'] = 667;
  15991. t['Aring'] = 667;
  15992. t['Otilde'] = 722;
  15993. t['zdotaccent'] = 389;
  15994. t['Ecaron'] = 667;
  15995. t['Iogonek'] = 389;
  15996. t['kcommaaccent'] = 500;
  15997. t['minus'] = 606;
  15998. t['Icircumflex'] = 389;
  15999. t['ncaron'] = 556;
  16000. t['tcommaaccent'] = 278;
  16001. t['logicalnot'] = 606;
  16002. t['odieresis'] = 500;
  16003. t['udieresis'] = 556;
  16004. t['notequal'] = 549;
  16005. t['gcommaaccent'] = 500;
  16006. t['eth'] = 500;
  16007. t['zcaron'] = 389;
  16008. t['ncommaaccent'] = 556;
  16009. t['onesuperior'] = 300;
  16010. t['imacron'] = 278;
  16011. t['Euro'] = 500;
  16012. });
  16013. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16014. t['space'] = 250;
  16015. t['exclam'] = 333;
  16016. t['quotedbl'] = 420;
  16017. t['numbersign'] = 500;
  16018. t['dollar'] = 500;
  16019. t['percent'] = 833;
  16020. t['ampersand'] = 778;
  16021. t['quoteright'] = 333;
  16022. t['parenleft'] = 333;
  16023. t['parenright'] = 333;
  16024. t['asterisk'] = 500;
  16025. t['plus'] = 675;
  16026. t['comma'] = 250;
  16027. t['hyphen'] = 333;
  16028. t['period'] = 250;
  16029. t['slash'] = 278;
  16030. t['zero'] = 500;
  16031. t['one'] = 500;
  16032. t['two'] = 500;
  16033. t['three'] = 500;
  16034. t['four'] = 500;
  16035. t['five'] = 500;
  16036. t['six'] = 500;
  16037. t['seven'] = 500;
  16038. t['eight'] = 500;
  16039. t['nine'] = 500;
  16040. t['colon'] = 333;
  16041. t['semicolon'] = 333;
  16042. t['less'] = 675;
  16043. t['equal'] = 675;
  16044. t['greater'] = 675;
  16045. t['question'] = 500;
  16046. t['at'] = 920;
  16047. t['A'] = 611;
  16048. t['B'] = 611;
  16049. t['C'] = 667;
  16050. t['D'] = 722;
  16051. t['E'] = 611;
  16052. t['F'] = 611;
  16053. t['G'] = 722;
  16054. t['H'] = 722;
  16055. t['I'] = 333;
  16056. t['J'] = 444;
  16057. t['K'] = 667;
  16058. t['L'] = 556;
  16059. t['M'] = 833;
  16060. t['N'] = 667;
  16061. t['O'] = 722;
  16062. t['P'] = 611;
  16063. t['Q'] = 722;
  16064. t['R'] = 611;
  16065. t['S'] = 500;
  16066. t['T'] = 556;
  16067. t['U'] = 722;
  16068. t['V'] = 611;
  16069. t['W'] = 833;
  16070. t['X'] = 611;
  16071. t['Y'] = 556;
  16072. t['Z'] = 556;
  16073. t['bracketleft'] = 389;
  16074. t['backslash'] = 278;
  16075. t['bracketright'] = 389;
  16076. t['asciicircum'] = 422;
  16077. t['underscore'] = 500;
  16078. t['quoteleft'] = 333;
  16079. t['a'] = 500;
  16080. t['b'] = 500;
  16081. t['c'] = 444;
  16082. t['d'] = 500;
  16083. t['e'] = 444;
  16084. t['f'] = 278;
  16085. t['g'] = 500;
  16086. t['h'] = 500;
  16087. t['i'] = 278;
  16088. t['j'] = 278;
  16089. t['k'] = 444;
  16090. t['l'] = 278;
  16091. t['m'] = 722;
  16092. t['n'] = 500;
  16093. t['o'] = 500;
  16094. t['p'] = 500;
  16095. t['q'] = 500;
  16096. t['r'] = 389;
  16097. t['s'] = 389;
  16098. t['t'] = 278;
  16099. t['u'] = 500;
  16100. t['v'] = 444;
  16101. t['w'] = 667;
  16102. t['x'] = 444;
  16103. t['y'] = 444;
  16104. t['z'] = 389;
  16105. t['braceleft'] = 400;
  16106. t['bar'] = 275;
  16107. t['braceright'] = 400;
  16108. t['asciitilde'] = 541;
  16109. t['exclamdown'] = 389;
  16110. t['cent'] = 500;
  16111. t['sterling'] = 500;
  16112. t['fraction'] = 167;
  16113. t['yen'] = 500;
  16114. t['florin'] = 500;
  16115. t['section'] = 500;
  16116. t['currency'] = 500;
  16117. t['quotesingle'] = 214;
  16118. t['quotedblleft'] = 556;
  16119. t['guillemotleft'] = 500;
  16120. t['guilsinglleft'] = 333;
  16121. t['guilsinglright'] = 333;
  16122. t['fi'] = 500;
  16123. t['fl'] = 500;
  16124. t['endash'] = 500;
  16125. t['dagger'] = 500;
  16126. t['daggerdbl'] = 500;
  16127. t['periodcentered'] = 250;
  16128. t['paragraph'] = 523;
  16129. t['bullet'] = 350;
  16130. t['quotesinglbase'] = 333;
  16131. t['quotedblbase'] = 556;
  16132. t['quotedblright'] = 556;
  16133. t['guillemotright'] = 500;
  16134. t['ellipsis'] = 889;
  16135. t['perthousand'] = 1000;
  16136. t['questiondown'] = 500;
  16137. t['grave'] = 333;
  16138. t['acute'] = 333;
  16139. t['circumflex'] = 333;
  16140. t['tilde'] = 333;
  16141. t['macron'] = 333;
  16142. t['breve'] = 333;
  16143. t['dotaccent'] = 333;
  16144. t['dieresis'] = 333;
  16145. t['ring'] = 333;
  16146. t['cedilla'] = 333;
  16147. t['hungarumlaut'] = 333;
  16148. t['ogonek'] = 333;
  16149. t['caron'] = 333;
  16150. t['emdash'] = 889;
  16151. t['AE'] = 889;
  16152. t['ordfeminine'] = 276;
  16153. t['Lslash'] = 556;
  16154. t['Oslash'] = 722;
  16155. t['OE'] = 944;
  16156. t['ordmasculine'] = 310;
  16157. t['ae'] = 667;
  16158. t['dotlessi'] = 278;
  16159. t['lslash'] = 278;
  16160. t['oslash'] = 500;
  16161. t['oe'] = 667;
  16162. t['germandbls'] = 500;
  16163. t['Idieresis'] = 333;
  16164. t['eacute'] = 444;
  16165. t['abreve'] = 500;
  16166. t['uhungarumlaut'] = 500;
  16167. t['ecaron'] = 444;
  16168. t['Ydieresis'] = 556;
  16169. t['divide'] = 675;
  16170. t['Yacute'] = 556;
  16171. t['Acircumflex'] = 611;
  16172. t['aacute'] = 500;
  16173. t['Ucircumflex'] = 722;
  16174. t['yacute'] = 444;
  16175. t['scommaaccent'] = 389;
  16176. t['ecircumflex'] = 444;
  16177. t['Uring'] = 722;
  16178. t['Udieresis'] = 722;
  16179. t['aogonek'] = 500;
  16180. t['Uacute'] = 722;
  16181. t['uogonek'] = 500;
  16182. t['Edieresis'] = 611;
  16183. t['Dcroat'] = 722;
  16184. t['commaaccent'] = 250;
  16185. t['copyright'] = 760;
  16186. t['Emacron'] = 611;
  16187. t['ccaron'] = 444;
  16188. t['aring'] = 500;
  16189. t['Ncommaaccent'] = 667;
  16190. t['lacute'] = 278;
  16191. t['agrave'] = 500;
  16192. t['Tcommaaccent'] = 556;
  16193. t['Cacute'] = 667;
  16194. t['atilde'] = 500;
  16195. t['Edotaccent'] = 611;
  16196. t['scaron'] = 389;
  16197. t['scedilla'] = 389;
  16198. t['iacute'] = 278;
  16199. t['lozenge'] = 471;
  16200. t['Rcaron'] = 611;
  16201. t['Gcommaaccent'] = 722;
  16202. t['ucircumflex'] = 500;
  16203. t['acircumflex'] = 500;
  16204. t['Amacron'] = 611;
  16205. t['rcaron'] = 389;
  16206. t['ccedilla'] = 444;
  16207. t['Zdotaccent'] = 556;
  16208. t['Thorn'] = 611;
  16209. t['Omacron'] = 722;
  16210. t['Racute'] = 611;
  16211. t['Sacute'] = 500;
  16212. t['dcaron'] = 544;
  16213. t['Umacron'] = 722;
  16214. t['uring'] = 500;
  16215. t['threesuperior'] = 300;
  16216. t['Ograve'] = 722;
  16217. t['Agrave'] = 611;
  16218. t['Abreve'] = 611;
  16219. t['multiply'] = 675;
  16220. t['uacute'] = 500;
  16221. t['Tcaron'] = 556;
  16222. t['partialdiff'] = 476;
  16223. t['ydieresis'] = 444;
  16224. t['Nacute'] = 667;
  16225. t['icircumflex'] = 278;
  16226. t['Ecircumflex'] = 611;
  16227. t['adieresis'] = 500;
  16228. t['edieresis'] = 444;
  16229. t['cacute'] = 444;
  16230. t['nacute'] = 500;
  16231. t['umacron'] = 500;
  16232. t['Ncaron'] = 667;
  16233. t['Iacute'] = 333;
  16234. t['plusminus'] = 675;
  16235. t['brokenbar'] = 275;
  16236. t['registered'] = 760;
  16237. t['Gbreve'] = 722;
  16238. t['Idotaccent'] = 333;
  16239. t['summation'] = 600;
  16240. t['Egrave'] = 611;
  16241. t['racute'] = 389;
  16242. t['omacron'] = 500;
  16243. t['Zacute'] = 556;
  16244. t['Zcaron'] = 556;
  16245. t['greaterequal'] = 549;
  16246. t['Eth'] = 722;
  16247. t['Ccedilla'] = 667;
  16248. t['lcommaaccent'] = 278;
  16249. t['tcaron'] = 300;
  16250. t['eogonek'] = 444;
  16251. t['Uogonek'] = 722;
  16252. t['Aacute'] = 611;
  16253. t['Adieresis'] = 611;
  16254. t['egrave'] = 444;
  16255. t['zacute'] = 389;
  16256. t['iogonek'] = 278;
  16257. t['Oacute'] = 722;
  16258. t['oacute'] = 500;
  16259. t['amacron'] = 500;
  16260. t['sacute'] = 389;
  16261. t['idieresis'] = 278;
  16262. t['Ocircumflex'] = 722;
  16263. t['Ugrave'] = 722;
  16264. t['Delta'] = 612;
  16265. t['thorn'] = 500;
  16266. t['twosuperior'] = 300;
  16267. t['Odieresis'] = 722;
  16268. t['mu'] = 500;
  16269. t['igrave'] = 278;
  16270. t['ohungarumlaut'] = 500;
  16271. t['Eogonek'] = 611;
  16272. t['dcroat'] = 500;
  16273. t['threequarters'] = 750;
  16274. t['Scedilla'] = 500;
  16275. t['lcaron'] = 300;
  16276. t['Kcommaaccent'] = 667;
  16277. t['Lacute'] = 556;
  16278. t['trademark'] = 980;
  16279. t['edotaccent'] = 444;
  16280. t['Igrave'] = 333;
  16281. t['Imacron'] = 333;
  16282. t['Lcaron'] = 611;
  16283. t['onehalf'] = 750;
  16284. t['lessequal'] = 549;
  16285. t['ocircumflex'] = 500;
  16286. t['ntilde'] = 500;
  16287. t['Uhungarumlaut'] = 722;
  16288. t['Eacute'] = 611;
  16289. t['emacron'] = 444;
  16290. t['gbreve'] = 500;
  16291. t['onequarter'] = 750;
  16292. t['Scaron'] = 500;
  16293. t['Scommaaccent'] = 500;
  16294. t['Ohungarumlaut'] = 722;
  16295. t['degree'] = 400;
  16296. t['ograve'] = 500;
  16297. t['Ccaron'] = 667;
  16298. t['ugrave'] = 500;
  16299. t['radical'] = 453;
  16300. t['Dcaron'] = 722;
  16301. t['rcommaaccent'] = 389;
  16302. t['Ntilde'] = 667;
  16303. t['otilde'] = 500;
  16304. t['Rcommaaccent'] = 611;
  16305. t['Lcommaaccent'] = 556;
  16306. t['Atilde'] = 611;
  16307. t['Aogonek'] = 611;
  16308. t['Aring'] = 611;
  16309. t['Otilde'] = 722;
  16310. t['zdotaccent'] = 389;
  16311. t['Ecaron'] = 611;
  16312. t['Iogonek'] = 333;
  16313. t['kcommaaccent'] = 444;
  16314. t['minus'] = 675;
  16315. t['Icircumflex'] = 333;
  16316. t['ncaron'] = 500;
  16317. t['tcommaaccent'] = 278;
  16318. t['logicalnot'] = 675;
  16319. t['odieresis'] = 500;
  16320. t['udieresis'] = 500;
  16321. t['notequal'] = 549;
  16322. t['gcommaaccent'] = 500;
  16323. t['eth'] = 500;
  16324. t['zcaron'] = 389;
  16325. t['ncommaaccent'] = 500;
  16326. t['onesuperior'] = 300;
  16327. t['imacron'] = 278;
  16328. t['Euro'] = 500;
  16329. });
  16330. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16331. t['space'] = 278;
  16332. t['a1'] = 974;
  16333. t['a2'] = 961;
  16334. t['a202'] = 974;
  16335. t['a3'] = 980;
  16336. t['a4'] = 719;
  16337. t['a5'] = 789;
  16338. t['a119'] = 790;
  16339. t['a118'] = 791;
  16340. t['a117'] = 690;
  16341. t['a11'] = 960;
  16342. t['a12'] = 939;
  16343. t['a13'] = 549;
  16344. t['a14'] = 855;
  16345. t['a15'] = 911;
  16346. t['a16'] = 933;
  16347. t['a105'] = 911;
  16348. t['a17'] = 945;
  16349. t['a18'] = 974;
  16350. t['a19'] = 755;
  16351. t['a20'] = 846;
  16352. t['a21'] = 762;
  16353. t['a22'] = 761;
  16354. t['a23'] = 571;
  16355. t['a24'] = 677;
  16356. t['a25'] = 763;
  16357. t['a26'] = 760;
  16358. t['a27'] = 759;
  16359. t['a28'] = 754;
  16360. t['a6'] = 494;
  16361. t['a7'] = 552;
  16362. t['a8'] = 537;
  16363. t['a9'] = 577;
  16364. t['a10'] = 692;
  16365. t['a29'] = 786;
  16366. t['a30'] = 788;
  16367. t['a31'] = 788;
  16368. t['a32'] = 790;
  16369. t['a33'] = 793;
  16370. t['a34'] = 794;
  16371. t['a35'] = 816;
  16372. t['a36'] = 823;
  16373. t['a37'] = 789;
  16374. t['a38'] = 841;
  16375. t['a39'] = 823;
  16376. t['a40'] = 833;
  16377. t['a41'] = 816;
  16378. t['a42'] = 831;
  16379. t['a43'] = 923;
  16380. t['a44'] = 744;
  16381. t['a45'] = 723;
  16382. t['a46'] = 749;
  16383. t['a47'] = 790;
  16384. t['a48'] = 792;
  16385. t['a49'] = 695;
  16386. t['a50'] = 776;
  16387. t['a51'] = 768;
  16388. t['a52'] = 792;
  16389. t['a53'] = 759;
  16390. t['a54'] = 707;
  16391. t['a55'] = 708;
  16392. t['a56'] = 682;
  16393. t['a57'] = 701;
  16394. t['a58'] = 826;
  16395. t['a59'] = 815;
  16396. t['a60'] = 789;
  16397. t['a61'] = 789;
  16398. t['a62'] = 707;
  16399. t['a63'] = 687;
  16400. t['a64'] = 696;
  16401. t['a65'] = 689;
  16402. t['a66'] = 786;
  16403. t['a67'] = 787;
  16404. t['a68'] = 713;
  16405. t['a69'] = 791;
  16406. t['a70'] = 785;
  16407. t['a71'] = 791;
  16408. t['a72'] = 873;
  16409. t['a73'] = 761;
  16410. t['a74'] = 762;
  16411. t['a203'] = 762;
  16412. t['a75'] = 759;
  16413. t['a204'] = 759;
  16414. t['a76'] = 892;
  16415. t['a77'] = 892;
  16416. t['a78'] = 788;
  16417. t['a79'] = 784;
  16418. t['a81'] = 438;
  16419. t['a82'] = 138;
  16420. t['a83'] = 277;
  16421. t['a84'] = 415;
  16422. t['a97'] = 392;
  16423. t['a98'] = 392;
  16424. t['a99'] = 668;
  16425. t['a100'] = 668;
  16426. t['a89'] = 390;
  16427. t['a90'] = 390;
  16428. t['a93'] = 317;
  16429. t['a94'] = 317;
  16430. t['a91'] = 276;
  16431. t['a92'] = 276;
  16432. t['a205'] = 509;
  16433. t['a85'] = 509;
  16434. t['a206'] = 410;
  16435. t['a86'] = 410;
  16436. t['a87'] = 234;
  16437. t['a88'] = 234;
  16438. t['a95'] = 334;
  16439. t['a96'] = 334;
  16440. t['a101'] = 732;
  16441. t['a102'] = 544;
  16442. t['a103'] = 544;
  16443. t['a104'] = 910;
  16444. t['a106'] = 667;
  16445. t['a107'] = 760;
  16446. t['a108'] = 760;
  16447. t['a112'] = 776;
  16448. t['a111'] = 595;
  16449. t['a110'] = 694;
  16450. t['a109'] = 626;
  16451. t['a120'] = 788;
  16452. t['a121'] = 788;
  16453. t['a122'] = 788;
  16454. t['a123'] = 788;
  16455. t['a124'] = 788;
  16456. t['a125'] = 788;
  16457. t['a126'] = 788;
  16458. t['a127'] = 788;
  16459. t['a128'] = 788;
  16460. t['a129'] = 788;
  16461. t['a130'] = 788;
  16462. t['a131'] = 788;
  16463. t['a132'] = 788;
  16464. t['a133'] = 788;
  16465. t['a134'] = 788;
  16466. t['a135'] = 788;
  16467. t['a136'] = 788;
  16468. t['a137'] = 788;
  16469. t['a138'] = 788;
  16470. t['a139'] = 788;
  16471. t['a140'] = 788;
  16472. t['a141'] = 788;
  16473. t['a142'] = 788;
  16474. t['a143'] = 788;
  16475. t['a144'] = 788;
  16476. t['a145'] = 788;
  16477. t['a146'] = 788;
  16478. t['a147'] = 788;
  16479. t['a148'] = 788;
  16480. t['a149'] = 788;
  16481. t['a150'] = 788;
  16482. t['a151'] = 788;
  16483. t['a152'] = 788;
  16484. t['a153'] = 788;
  16485. t['a154'] = 788;
  16486. t['a155'] = 788;
  16487. t['a156'] = 788;
  16488. t['a157'] = 788;
  16489. t['a158'] = 788;
  16490. t['a159'] = 788;
  16491. t['a160'] = 894;
  16492. t['a161'] = 838;
  16493. t['a163'] = 1016;
  16494. t['a164'] = 458;
  16495. t['a196'] = 748;
  16496. t['a165'] = 924;
  16497. t['a192'] = 748;
  16498. t['a166'] = 918;
  16499. t['a167'] = 927;
  16500. t['a168'] = 928;
  16501. t['a169'] = 928;
  16502. t['a170'] = 834;
  16503. t['a171'] = 873;
  16504. t['a172'] = 828;
  16505. t['a173'] = 924;
  16506. t['a162'] = 924;
  16507. t['a174'] = 917;
  16508. t['a175'] = 930;
  16509. t['a176'] = 931;
  16510. t['a177'] = 463;
  16511. t['a178'] = 883;
  16512. t['a179'] = 836;
  16513. t['a193'] = 836;
  16514. t['a180'] = 867;
  16515. t['a199'] = 867;
  16516. t['a181'] = 696;
  16517. t['a200'] = 696;
  16518. t['a182'] = 874;
  16519. t['a201'] = 874;
  16520. t['a183'] = 760;
  16521. t['a184'] = 946;
  16522. t['a197'] = 771;
  16523. t['a185'] = 865;
  16524. t['a194'] = 771;
  16525. t['a198'] = 888;
  16526. t['a186'] = 967;
  16527. t['a195'] = 888;
  16528. t['a187'] = 831;
  16529. t['a188'] = 873;
  16530. t['a189'] = 927;
  16531. t['a190'] = 970;
  16532. t['a191'] = 918;
  16533. });
  16534. });
  16535. exports.getMetrics = getMetrics;
  16536. }));
  16537. (function (root, factory) {
  16538. {
  16539. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16540. }
  16541. }(this, function (exports, sharedUtil) {
  16542. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16543. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16544. // Workaround for missing math precision in JS.
  16545. var MASK_HIGH = 0xffff0000;
  16546. var MASK_LOW = 0xffff;
  16547. function MurmurHash3_64 (seed) {
  16548. var SEED = 0xc3d2e1f0;
  16549. this.h1 = seed ? seed & 0xffffffff : SEED;
  16550. this.h2 = seed ? seed & 0xffffffff : SEED;
  16551. }
  16552. var alwaysUseUint32ArrayView = false;
  16553. // old webkits have issues with non-aligned arrays
  16554. try {
  16555. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16556. } catch (e) {
  16557. alwaysUseUint32ArrayView = true;
  16558. }
  16559. MurmurHash3_64.prototype = {
  16560. update: function MurmurHash3_64_update(input) {
  16561. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16562. var i;
  16563. if (typeof input === 'string') {
  16564. var data = new Uint8Array(input.length * 2);
  16565. var length = 0;
  16566. for (i = 0; i < input.length; i++) {
  16567. var code = input.charCodeAt(i);
  16568. if (code <= 0xff) {
  16569. data[length++] = code;
  16570. }
  16571. else {
  16572. data[length++] = code >>> 8;
  16573. data[length++] = code & 0xff;
  16574. }
  16575. }
  16576. } else if (input instanceof Uint8Array) {
  16577. data = input;
  16578. length = data.length;
  16579. } else if (typeof input === 'object' && ('length' in input)) {
  16580. // processing regular arrays as well, e.g. for IE9
  16581. data = input;
  16582. length = data.length;
  16583. useUint32ArrayView = true;
  16584. } else {
  16585. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16586. 'Input must be a string or array.');
  16587. }
  16588. var blockCounts = length >> 2;
  16589. var tailLength = length - blockCounts * 4;
  16590. // we don't care about endianness here
  16591. var dataUint32 = useUint32ArrayView ?
  16592. new Uint32ArrayView(data, blockCounts) :
  16593. new Uint32Array(data.buffer, 0, blockCounts);
  16594. var k1 = 0;
  16595. var k2 = 0;
  16596. var h1 = this.h1;
  16597. var h2 = this.h2;
  16598. var C1 = 0xcc9e2d51;
  16599. var C2 = 0x1b873593;
  16600. var C1_LOW = C1 & MASK_LOW;
  16601. var C2_LOW = C2 & MASK_LOW;
  16602. for (i = 0; i < blockCounts; i++) {
  16603. if (i & 1) {
  16604. k1 = dataUint32[i];
  16605. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16606. k1 = k1 << 15 | k1 >>> 17;
  16607. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16608. h1 ^= k1;
  16609. h1 = h1 << 13 | h1 >>> 19;
  16610. h1 = h1 * 5 + 0xe6546b64;
  16611. } else {
  16612. k2 = dataUint32[i];
  16613. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16614. k2 = k2 << 15 | k2 >>> 17;
  16615. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16616. h2 ^= k2;
  16617. h2 = h2 << 13 | h2 >>> 19;
  16618. h2 = h2 * 5 + 0xe6546b64;
  16619. }
  16620. }
  16621. k1 = 0;
  16622. switch (tailLength) {
  16623. case 3:
  16624. k1 ^= data[blockCounts * 4 + 2] << 16;
  16625. /* falls through */
  16626. case 2:
  16627. k1 ^= data[blockCounts * 4 + 1] << 8;
  16628. /* falls through */
  16629. case 1:
  16630. k1 ^= data[blockCounts * 4];
  16631. /* falls through */
  16632. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16633. k1 = k1 << 15 | k1 >>> 17;
  16634. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16635. if (blockCounts & 1) {
  16636. h1 ^= k1;
  16637. } else {
  16638. h2 ^= k1;
  16639. }
  16640. }
  16641. this.h1 = h1;
  16642. this.h2 = h2;
  16643. return this;
  16644. },
  16645. hexdigest: function MurmurHash3_64_hexdigest () {
  16646. var h1 = this.h1;
  16647. var h2 = this.h2;
  16648. h1 ^= h2 >>> 1;
  16649. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16650. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16651. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16652. h1 ^= h2 >>> 1;
  16653. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16654. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16655. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16656. h1 ^= h2 >>> 1;
  16657. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16658. var hex = (arr[i] >>> 0).toString(16);
  16659. while (hex.length < 8) {
  16660. hex = '0' + hex;
  16661. }
  16662. str += hex;
  16663. }
  16664. return str;
  16665. }
  16666. };
  16667. return MurmurHash3_64;
  16668. })();
  16669. exports.MurmurHash3_64 = MurmurHash3_64;
  16670. }));
  16671. (function (root, factory) {
  16672. {
  16673. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16674. }
  16675. }(this, function (exports, sharedUtil) {
  16676. var isArray = sharedUtil.isArray;
  16677. var Name = (function NameClosure() {
  16678. function Name(name) {
  16679. this.name = name;
  16680. }
  16681. Name.prototype = {};
  16682. var nameCache = Object.create(null);
  16683. Name.get = function Name_get(name) {
  16684. var nameValue = nameCache[name];
  16685. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16686. };
  16687. return Name;
  16688. })();
  16689. var Cmd = (function CmdClosure() {
  16690. function Cmd(cmd) {
  16691. this.cmd = cmd;
  16692. }
  16693. Cmd.prototype = {};
  16694. var cmdCache = Object.create(null);
  16695. Cmd.get = function Cmd_get(cmd) {
  16696. var cmdValue = cmdCache[cmd];
  16697. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16698. };
  16699. return Cmd;
  16700. })();
  16701. var Dict = (function DictClosure() {
  16702. var nonSerializable = function nonSerializableClosure() {
  16703. return nonSerializable; // creating closure on some variable
  16704. };
  16705. // xref is optional
  16706. function Dict(xref) {
  16707. // Map should only be used internally, use functions below to access.
  16708. this.map = Object.create(null);
  16709. this.xref = xref;
  16710. this.objId = null;
  16711. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16712. }
  16713. Dict.prototype = {
  16714. assignXref: function Dict_assignXref(newXref) {
  16715. this.xref = newXref;
  16716. },
  16717. // automatically dereferences Ref objects
  16718. get: function Dict_get(key1, key2, key3) {
  16719. var value;
  16720. var xref = this.xref;
  16721. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16722. typeof key2 === 'undefined') {
  16723. return xref ? xref.fetchIfRef(value) : value;
  16724. }
  16725. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16726. typeof key3 === 'undefined') {
  16727. return xref ? xref.fetchIfRef(value) : value;
  16728. }
  16729. value = this.map[key3] || null;
  16730. return xref ? xref.fetchIfRef(value) : value;
  16731. },
  16732. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16733. getAsync: function Dict_getAsync(key1, key2, key3) {
  16734. var value;
  16735. var xref = this.xref;
  16736. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16737. typeof key2 === 'undefined') {
  16738. if (xref) {
  16739. return xref.fetchIfRefAsync(value);
  16740. }
  16741. return Promise.resolve(value);
  16742. }
  16743. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16744. typeof key3 === 'undefined') {
  16745. if (xref) {
  16746. return xref.fetchIfRefAsync(value);
  16747. }
  16748. return Promise.resolve(value);
  16749. }
  16750. value = this.map[key3] || null;
  16751. if (xref) {
  16752. return xref.fetchIfRefAsync(value);
  16753. }
  16754. return Promise.resolve(value);
  16755. },
  16756. // Same as get(), but dereferences all elements if the result is an Array.
  16757. getArray: function Dict_getArray(key1, key2, key3) {
  16758. var value = this.get(key1, key2, key3);
  16759. var xref = this.xref;
  16760. if (!isArray(value) || !xref) {
  16761. return value;
  16762. }
  16763. value = value.slice(); // Ensure that we don't modify the Dict data.
  16764. for (var i = 0, ii = value.length; i < ii; i++) {
  16765. if (!isRef(value[i])) {
  16766. continue;
  16767. }
  16768. value[i] = xref.fetch(value[i]);
  16769. }
  16770. return value;
  16771. },
  16772. // no dereferencing
  16773. getRaw: function Dict_getRaw(key) {
  16774. return this.map[key];
  16775. },
  16776. getKeys: function Dict_getKeys() {
  16777. return Object.keys(this.map);
  16778. },
  16779. set: function Dict_set(key, value) {
  16780. this.map[key] = value;
  16781. },
  16782. has: function Dict_has(key) {
  16783. return key in this.map;
  16784. },
  16785. forEach: function Dict_forEach(callback) {
  16786. for (var key in this.map) {
  16787. callback(key, this.get(key));
  16788. }
  16789. }
  16790. };
  16791. Dict.empty = new Dict(null);
  16792. Dict.merge = function Dict_merge(xref, dictArray) {
  16793. var mergedDict = new Dict(xref);
  16794. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16795. var dict = dictArray[i];
  16796. if (!isDict(dict)) {
  16797. continue;
  16798. }
  16799. for (var keyName in dict.map) {
  16800. if (mergedDict.map[keyName]) {
  16801. continue;
  16802. }
  16803. mergedDict.map[keyName] = dict.map[keyName];
  16804. }
  16805. }
  16806. return mergedDict;
  16807. };
  16808. return Dict;
  16809. })();
  16810. var Ref = (function RefClosure() {
  16811. function Ref(num, gen) {
  16812. this.num = num;
  16813. this.gen = gen;
  16814. }
  16815. Ref.prototype = {
  16816. toString: function Ref_toString() {
  16817. // This function is hot, so we make the string as compact as possible.
  16818. // |this.gen| is almost always zero, so we treat that case specially.
  16819. var str = this.num + 'R';
  16820. if (this.gen !== 0) {
  16821. str += this.gen;
  16822. }
  16823. return str;
  16824. }
  16825. };
  16826. return Ref;
  16827. })();
  16828. // The reference is identified by number and generation.
  16829. // This structure stores only one instance of the reference.
  16830. var RefSet = (function RefSetClosure() {
  16831. function RefSet() {
  16832. this.dict = Object.create(null);
  16833. }
  16834. RefSet.prototype = {
  16835. has: function RefSet_has(ref) {
  16836. return ref.toString() in this.dict;
  16837. },
  16838. put: function RefSet_put(ref) {
  16839. this.dict[ref.toString()] = true;
  16840. },
  16841. remove: function RefSet_remove(ref) {
  16842. delete this.dict[ref.toString()];
  16843. }
  16844. };
  16845. return RefSet;
  16846. })();
  16847. var RefSetCache = (function RefSetCacheClosure() {
  16848. function RefSetCache() {
  16849. this.dict = Object.create(null);
  16850. }
  16851. RefSetCache.prototype = {
  16852. get: function RefSetCache_get(ref) {
  16853. return this.dict[ref.toString()];
  16854. },
  16855. has: function RefSetCache_has(ref) {
  16856. return ref.toString() in this.dict;
  16857. },
  16858. put: function RefSetCache_put(ref, obj) {
  16859. this.dict[ref.toString()] = obj;
  16860. },
  16861. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16862. this.dict[ref.toString()] = this.get(aliasRef);
  16863. },
  16864. forEach: function RefSetCache_forEach(fn, thisArg) {
  16865. for (var i in this.dict) {
  16866. fn.call(thisArg, this.dict[i]);
  16867. }
  16868. },
  16869. clear: function RefSetCache_clear() {
  16870. this.dict = Object.create(null);
  16871. }
  16872. };
  16873. return RefSetCache;
  16874. })();
  16875. function isName(v, name) {
  16876. return v instanceof Name && (name === undefined || v.name === name);
  16877. }
  16878. function isCmd(v, cmd) {
  16879. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16880. }
  16881. function isDict(v, type) {
  16882. return v instanceof Dict &&
  16883. (type === undefined || isName(v.get('Type'), type));
  16884. }
  16885. function isRef(v) {
  16886. return v instanceof Ref;
  16887. }
  16888. function isRefsEqual(v1, v2) {
  16889. return v1.num === v2.num && v1.gen === v2.gen;
  16890. }
  16891. function isStream(v) {
  16892. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  16893. }
  16894. exports.Cmd = Cmd;
  16895. exports.Dict = Dict;
  16896. exports.Name = Name;
  16897. exports.Ref = Ref;
  16898. exports.RefSet = RefSet;
  16899. exports.RefSetCache = RefSetCache;
  16900. exports.isCmd = isCmd;
  16901. exports.isDict = isDict;
  16902. exports.isName = isName;
  16903. exports.isRef = isRef;
  16904. exports.isRefsEqual = isRefsEqual;
  16905. exports.isStream = isStream;
  16906. }));
  16907. (function (root, factory) {
  16908. {
  16909. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  16910. }
  16911. }(this, function (exports, sharedUtil) {
  16912. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  16913. /**
  16914. * Hold a map of decoded fonts and of the standard fourteen Type1
  16915. * fonts and their acronyms.
  16916. */
  16917. var getStdFontMap = getLookupTableFactory(function (t) {
  16918. t['ArialNarrow'] = 'Helvetica';
  16919. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  16920. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  16921. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  16922. t['ArialBlack'] = 'Helvetica';
  16923. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  16924. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  16925. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  16926. t['Arial'] = 'Helvetica';
  16927. t['Arial-Bold'] = 'Helvetica-Bold';
  16928. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  16929. t['Arial-Italic'] = 'Helvetica-Oblique';
  16930. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  16931. t['Arial-BoldMT'] = 'Helvetica-Bold';
  16932. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  16933. t['ArialMT'] = 'Helvetica';
  16934. t['Courier-Bold'] = 'Courier-Bold';
  16935. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  16936. t['Courier-Italic'] = 'Courier-Oblique';
  16937. t['CourierNew'] = 'Courier';
  16938. t['CourierNew-Bold'] = 'Courier-Bold';
  16939. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  16940. t['CourierNew-Italic'] = 'Courier-Oblique';
  16941. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  16942. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  16943. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  16944. t['CourierNewPSMT'] = 'Courier';
  16945. t['Helvetica'] = 'Helvetica';
  16946. t['Helvetica-Bold'] = 'Helvetica-Bold';
  16947. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  16948. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  16949. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  16950. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  16951. t['Symbol-Bold'] = 'Symbol';
  16952. t['Symbol-BoldItalic'] = 'Symbol';
  16953. t['Symbol-Italic'] = 'Symbol';
  16954. t['TimesNewRoman'] = 'Times-Roman';
  16955. t['TimesNewRoman-Bold'] = 'Times-Bold';
  16956. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  16957. t['TimesNewRoman-Italic'] = 'Times-Italic';
  16958. t['TimesNewRomanPS'] = 'Times-Roman';
  16959. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  16960. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  16961. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  16962. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  16963. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  16964. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  16965. t['TimesNewRomanPSMT'] = 'Times-Roman';
  16966. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  16967. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  16968. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  16969. });
  16970. /**
  16971. * Holds the map of the non-standard fonts that might be included as
  16972. * a standard fonts without glyph data.
  16973. */
  16974. var getNonStdFontMap = getLookupTableFactory(function (t) {
  16975. t['CenturyGothic'] = 'Helvetica';
  16976. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  16977. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  16978. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  16979. t['ComicSansMS'] = 'Comic Sans MS';
  16980. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  16981. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  16982. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  16983. t['LucidaConsole'] = 'Courier';
  16984. t['LucidaConsole-Bold'] = 'Courier-Bold';
  16985. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  16986. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  16987. t['MS-Gothic'] = 'MS Gothic';
  16988. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  16989. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  16990. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  16991. t['MS-Mincho'] = 'MS Mincho';
  16992. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  16993. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  16994. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  16995. t['MS-PGothic'] = 'MS PGothic';
  16996. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  16997. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  16998. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  16999. t['MS-PMincho'] = 'MS PMincho';
  17000. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17001. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17002. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17003. t['Wingdings'] = 'ZapfDingbats';
  17004. });
  17005. var getSerifFonts = getLookupTableFactory(function (t) {
  17006. t['Adobe Jenson'] = true;
  17007. t['Adobe Text'] = true;
  17008. t['Albertus'] = true;
  17009. t['Aldus'] = true;
  17010. t['Alexandria'] = true;
  17011. t['Algerian'] = true;
  17012. t['American Typewriter'] = true;
  17013. t['Antiqua'] = true;
  17014. t['Apex'] = true;
  17015. t['Arno'] = true;
  17016. t['Aster'] = true;
  17017. t['Aurora'] = true;
  17018. t['Baskerville'] = true;
  17019. t['Bell'] = true;
  17020. t['Bembo'] = true;
  17021. t['Bembo Schoolbook'] = true;
  17022. t['Benguiat'] = true;
  17023. t['Berkeley Old Style'] = true;
  17024. t['Bernhard Modern'] = true;
  17025. t['Berthold City'] = true;
  17026. t['Bodoni'] = true;
  17027. t['Bauer Bodoni'] = true;
  17028. t['Book Antiqua'] = true;
  17029. t['Bookman'] = true;
  17030. t['Bordeaux Roman'] = true;
  17031. t['Californian FB'] = true;
  17032. t['Calisto'] = true;
  17033. t['Calvert'] = true;
  17034. t['Capitals'] = true;
  17035. t['Cambria'] = true;
  17036. t['Cartier'] = true;
  17037. t['Caslon'] = true;
  17038. t['Catull'] = true;
  17039. t['Centaur'] = true;
  17040. t['Century Old Style'] = true;
  17041. t['Century Schoolbook'] = true;
  17042. t['Chaparral'] = true;
  17043. t['Charis SIL'] = true;
  17044. t['Cheltenham'] = true;
  17045. t['Cholla Slab'] = true;
  17046. t['Clarendon'] = true;
  17047. t['Clearface'] = true;
  17048. t['Cochin'] = true;
  17049. t['Colonna'] = true;
  17050. t['Computer Modern'] = true;
  17051. t['Concrete Roman'] = true;
  17052. t['Constantia'] = true;
  17053. t['Cooper Black'] = true;
  17054. t['Corona'] = true;
  17055. t['Ecotype'] = true;
  17056. t['Egyptienne'] = true;
  17057. t['Elephant'] = true;
  17058. t['Excelsior'] = true;
  17059. t['Fairfield'] = true;
  17060. t['FF Scala'] = true;
  17061. t['Folkard'] = true;
  17062. t['Footlight'] = true;
  17063. t['FreeSerif'] = true;
  17064. t['Friz Quadrata'] = true;
  17065. t['Garamond'] = true;
  17066. t['Gentium'] = true;
  17067. t['Georgia'] = true;
  17068. t['Gloucester'] = true;
  17069. t['Goudy Old Style'] = true;
  17070. t['Goudy Schoolbook'] = true;
  17071. t['Goudy Pro Font'] = true;
  17072. t['Granjon'] = true;
  17073. t['Guardian Egyptian'] = true;
  17074. t['Heather'] = true;
  17075. t['Hercules'] = true;
  17076. t['High Tower Text'] = true;
  17077. t['Hiroshige'] = true;
  17078. t['Hoefler Text'] = true;
  17079. t['Humana Serif'] = true;
  17080. t['Imprint'] = true;
  17081. t['Ionic No. 5'] = true;
  17082. t['Janson'] = true;
  17083. t['Joanna'] = true;
  17084. t['Korinna'] = true;
  17085. t['Lexicon'] = true;
  17086. t['Liberation Serif'] = true;
  17087. t['Linux Libertine'] = true;
  17088. t['Literaturnaya'] = true;
  17089. t['Lucida'] = true;
  17090. t['Lucida Bright'] = true;
  17091. t['Melior'] = true;
  17092. t['Memphis'] = true;
  17093. t['Miller'] = true;
  17094. t['Minion'] = true;
  17095. t['Modern'] = true;
  17096. t['Mona Lisa'] = true;
  17097. t['Mrs Eaves'] = true;
  17098. t['MS Serif'] = true;
  17099. t['Museo Slab'] = true;
  17100. t['New York'] = true;
  17101. t['Nimbus Roman'] = true;
  17102. t['NPS Rawlinson Roadway'] = true;
  17103. t['Palatino'] = true;
  17104. t['Perpetua'] = true;
  17105. t['Plantin'] = true;
  17106. t['Plantin Schoolbook'] = true;
  17107. t['Playbill'] = true;
  17108. t['Poor Richard'] = true;
  17109. t['Rawlinson Roadway'] = true;
  17110. t['Renault'] = true;
  17111. t['Requiem'] = true;
  17112. t['Rockwell'] = true;
  17113. t['Roman'] = true;
  17114. t['Rotis Serif'] = true;
  17115. t['Sabon'] = true;
  17116. t['Scala'] = true;
  17117. t['Seagull'] = true;
  17118. t['Sistina'] = true;
  17119. t['Souvenir'] = true;
  17120. t['STIX'] = true;
  17121. t['Stone Informal'] = true;
  17122. t['Stone Serif'] = true;
  17123. t['Sylfaen'] = true;
  17124. t['Times'] = true;
  17125. t['Trajan'] = true;
  17126. t['Trinité'] = true;
  17127. t['Trump Mediaeval'] = true;
  17128. t['Utopia'] = true;
  17129. t['Vale Type'] = true;
  17130. t['Bitstream Vera'] = true;
  17131. t['Vera Serif'] = true;
  17132. t['Versailles'] = true;
  17133. t['Wanted'] = true;
  17134. t['Weiss'] = true;
  17135. t['Wide Latin'] = true;
  17136. t['Windsor'] = true;
  17137. t['XITS'] = true;
  17138. });
  17139. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17140. t['Dingbats'] = true;
  17141. t['Symbol'] = true;
  17142. t['ZapfDingbats'] = true;
  17143. });
  17144. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17145. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17146. // for all glyphs, but common for some set of the standard fonts.
  17147. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17148. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17149. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17150. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17151. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17152. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17153. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17154. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17155. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17156. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17157. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17158. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17159. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17160. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17161. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17162. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17163. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17164. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17165. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17166. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17167. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17168. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17169. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17170. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17171. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17172. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17173. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17174. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17175. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17176. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17177. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17178. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17179. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17180. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17181. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17182. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17183. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17184. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17185. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17186. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17187. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17188. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17189. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17190. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17191. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17192. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17193. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17194. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17195. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17196. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17197. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17198. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17199. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17200. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17201. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17202. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17203. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17204. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17205. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17206. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17207. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17208. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17209. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17210. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17211. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17212. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17213. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17214. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17215. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17216. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17217. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17218. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17219. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17220. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17221. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17222. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17223. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17224. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17225. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17226. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17227. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17228. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17229. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17230. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17231. t[3416] = 8377;
  17232. });
  17233. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17234. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17235. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17236. var getSupplementalGlyphMapForArialBlack =
  17237. getLookupTableFactory(function (t) {
  17238. t[227] = 322; t[264] = 261; t[291] = 346;
  17239. });
  17240. exports.getStdFontMap = getStdFontMap;
  17241. exports.getNonStdFontMap = getNonStdFontMap;
  17242. exports.getSerifFonts = getSerifFonts;
  17243. exports.getSymbolsFonts = getSymbolsFonts;
  17244. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17245. exports.getSupplementalGlyphMapForArialBlack =
  17246. getSupplementalGlyphMapForArialBlack;
  17247. }));
  17248. (function (root, factory) {
  17249. {
  17250. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17251. }
  17252. }(this, function (exports, sharedUtil) {
  17253. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17254. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17255. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17256. // chars to the similar equivalents in the normal characters range.
  17257. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17258. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17259. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17260. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17261. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17262. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17263. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17264. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17265. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17266. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17267. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17268. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17269. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17270. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17271. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17272. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17273. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17274. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17275. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17276. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17277. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17278. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17279. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17280. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17281. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17282. });
  17283. function mapSpecialUnicodeValues(code) {
  17284. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17285. return 0;
  17286. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17287. return (getSpecialPUASymbols()[code] || code);
  17288. }
  17289. return code;
  17290. }
  17291. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17292. var unicode = glyphsUnicodeMap[name];
  17293. if (unicode !== undefined) {
  17294. return unicode;
  17295. }
  17296. if (!name) {
  17297. return -1;
  17298. }
  17299. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17300. if (name[0] === 'u') {
  17301. var nameLen = name.length, hexStr;
  17302. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17303. hexStr = name.substr(3);
  17304. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17305. hexStr = name.substr(1);
  17306. } else {
  17307. return -1;
  17308. }
  17309. // Check for upper-case hexadecimal characters, to avoid false positives.
  17310. if (hexStr === hexStr.toUpperCase()) {
  17311. unicode = parseInt(hexStr, 16);
  17312. if (unicode >= 0) {
  17313. return unicode;
  17314. }
  17315. }
  17316. }
  17317. return -1;
  17318. }
  17319. var UnicodeRanges = [
  17320. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17321. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17322. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17323. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17324. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17325. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17326. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17327. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17328. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17329. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17330. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17331. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17332. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17333. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17334. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17335. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17336. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17337. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17338. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17339. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17340. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17341. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17342. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17343. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17344. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17345. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17346. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17347. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17348. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17349. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17350. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17351. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17352. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17353. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17354. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17355. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17356. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17357. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17358. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17359. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17360. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17361. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17362. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17363. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17364. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17365. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17366. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17367. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17368. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17369. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17370. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17371. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17372. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17373. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17374. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17375. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17376. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17377. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17378. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17379. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17380. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17381. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17382. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17383. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17384. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17385. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17386. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17387. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17388. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17389. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17390. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17391. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17392. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17393. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17394. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17395. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17396. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17397. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17398. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17399. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17400. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17401. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17402. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17403. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17404. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17405. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17406. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17407. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17408. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17409. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17410. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17411. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17412. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17413. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17414. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17415. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17416. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17417. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17418. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17419. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17420. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17421. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17422. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17423. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17424. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17425. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17426. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17427. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17428. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17429. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17430. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17431. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17432. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17433. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17434. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17435. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17436. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17437. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17438. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17439. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17440. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17441. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17442. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17443. ];
  17444. function getUnicodeRangeFor(value) {
  17445. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17446. var range = UnicodeRanges[i];
  17447. if (value >= range.begin && value < range.end) {
  17448. return i;
  17449. }
  17450. }
  17451. return -1;
  17452. }
  17453. function isRTLRangeFor(value) {
  17454. var range = UnicodeRanges[13];
  17455. if (value >= range.begin && value < range.end) {
  17456. return true;
  17457. }
  17458. range = UnicodeRanges[11];
  17459. if (value >= range.begin && value < range.end) {
  17460. return true;
  17461. }
  17462. return false;
  17463. }
  17464. // The normalization table is obtained by filtering the Unicode characters
  17465. // database with <compat> entries.
  17466. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17467. t['\u00A8'] = '\u0020\u0308';
  17468. t['\u00AF'] = '\u0020\u0304';
  17469. t['\u00B4'] = '\u0020\u0301';
  17470. t['\u00B5'] = '\u03BC';
  17471. t['\u00B8'] = '\u0020\u0327';
  17472. t['\u0132'] = '\u0049\u004A';
  17473. t['\u0133'] = '\u0069\u006A';
  17474. t['\u013F'] = '\u004C\u00B7';
  17475. t['\u0140'] = '\u006C\u00B7';
  17476. t['\u0149'] = '\u02BC\u006E';
  17477. t['\u017F'] = '\u0073';
  17478. t['\u01C4'] = '\u0044\u017D';
  17479. t['\u01C5'] = '\u0044\u017E';
  17480. t['\u01C6'] = '\u0064\u017E';
  17481. t['\u01C7'] = '\u004C\u004A';
  17482. t['\u01C8'] = '\u004C\u006A';
  17483. t['\u01C9'] = '\u006C\u006A';
  17484. t['\u01CA'] = '\u004E\u004A';
  17485. t['\u01CB'] = '\u004E\u006A';
  17486. t['\u01CC'] = '\u006E\u006A';
  17487. t['\u01F1'] = '\u0044\u005A';
  17488. t['\u01F2'] = '\u0044\u007A';
  17489. t['\u01F3'] = '\u0064\u007A';
  17490. t['\u02D8'] = '\u0020\u0306';
  17491. t['\u02D9'] = '\u0020\u0307';
  17492. t['\u02DA'] = '\u0020\u030A';
  17493. t['\u02DB'] = '\u0020\u0328';
  17494. t['\u02DC'] = '\u0020\u0303';
  17495. t['\u02DD'] = '\u0020\u030B';
  17496. t['\u037A'] = '\u0020\u0345';
  17497. t['\u0384'] = '\u0020\u0301';
  17498. t['\u03D0'] = '\u03B2';
  17499. t['\u03D1'] = '\u03B8';
  17500. t['\u03D2'] = '\u03A5';
  17501. t['\u03D5'] = '\u03C6';
  17502. t['\u03D6'] = '\u03C0';
  17503. t['\u03F0'] = '\u03BA';
  17504. t['\u03F1'] = '\u03C1';
  17505. t['\u03F2'] = '\u03C2';
  17506. t['\u03F4'] = '\u0398';
  17507. t['\u03F5'] = '\u03B5';
  17508. t['\u03F9'] = '\u03A3';
  17509. t['\u0587'] = '\u0565\u0582';
  17510. t['\u0675'] = '\u0627\u0674';
  17511. t['\u0676'] = '\u0648\u0674';
  17512. t['\u0677'] = '\u06C7\u0674';
  17513. t['\u0678'] = '\u064A\u0674';
  17514. t['\u0E33'] = '\u0E4D\u0E32';
  17515. t['\u0EB3'] = '\u0ECD\u0EB2';
  17516. t['\u0EDC'] = '\u0EAB\u0E99';
  17517. t['\u0EDD'] = '\u0EAB\u0EA1';
  17518. t['\u0F77'] = '\u0FB2\u0F81';
  17519. t['\u0F79'] = '\u0FB3\u0F81';
  17520. t['\u1E9A'] = '\u0061\u02BE';
  17521. t['\u1FBD'] = '\u0020\u0313';
  17522. t['\u1FBF'] = '\u0020\u0313';
  17523. t['\u1FC0'] = '\u0020\u0342';
  17524. t['\u1FFE'] = '\u0020\u0314';
  17525. t['\u2002'] = '\u0020';
  17526. t['\u2003'] = '\u0020';
  17527. t['\u2004'] = '\u0020';
  17528. t['\u2005'] = '\u0020';
  17529. t['\u2006'] = '\u0020';
  17530. t['\u2008'] = '\u0020';
  17531. t['\u2009'] = '\u0020';
  17532. t['\u200A'] = '\u0020';
  17533. t['\u2017'] = '\u0020\u0333';
  17534. t['\u2024'] = '\u002E';
  17535. t['\u2025'] = '\u002E\u002E';
  17536. t['\u2026'] = '\u002E\u002E\u002E';
  17537. t['\u2033'] = '\u2032\u2032';
  17538. t['\u2034'] = '\u2032\u2032\u2032';
  17539. t['\u2036'] = '\u2035\u2035';
  17540. t['\u2037'] = '\u2035\u2035\u2035';
  17541. t['\u203C'] = '\u0021\u0021';
  17542. t['\u203E'] = '\u0020\u0305';
  17543. t['\u2047'] = '\u003F\u003F';
  17544. t['\u2048'] = '\u003F\u0021';
  17545. t['\u2049'] = '\u0021\u003F';
  17546. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17547. t['\u205F'] = '\u0020';
  17548. t['\u20A8'] = '\u0052\u0073';
  17549. t['\u2100'] = '\u0061\u002F\u0063';
  17550. t['\u2101'] = '\u0061\u002F\u0073';
  17551. t['\u2103'] = '\u00B0\u0043';
  17552. t['\u2105'] = '\u0063\u002F\u006F';
  17553. t['\u2106'] = '\u0063\u002F\u0075';
  17554. t['\u2107'] = '\u0190';
  17555. t['\u2109'] = '\u00B0\u0046';
  17556. t['\u2116'] = '\u004E\u006F';
  17557. t['\u2121'] = '\u0054\u0045\u004C';
  17558. t['\u2135'] = '\u05D0';
  17559. t['\u2136'] = '\u05D1';
  17560. t['\u2137'] = '\u05D2';
  17561. t['\u2138'] = '\u05D3';
  17562. t['\u213B'] = '\u0046\u0041\u0058';
  17563. t['\u2160'] = '\u0049';
  17564. t['\u2161'] = '\u0049\u0049';
  17565. t['\u2162'] = '\u0049\u0049\u0049';
  17566. t['\u2163'] = '\u0049\u0056';
  17567. t['\u2164'] = '\u0056';
  17568. t['\u2165'] = '\u0056\u0049';
  17569. t['\u2166'] = '\u0056\u0049\u0049';
  17570. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17571. t['\u2168'] = '\u0049\u0058';
  17572. t['\u2169'] = '\u0058';
  17573. t['\u216A'] = '\u0058\u0049';
  17574. t['\u216B'] = '\u0058\u0049\u0049';
  17575. t['\u216C'] = '\u004C';
  17576. t['\u216D'] = '\u0043';
  17577. t['\u216E'] = '\u0044';
  17578. t['\u216F'] = '\u004D';
  17579. t['\u2170'] = '\u0069';
  17580. t['\u2171'] = '\u0069\u0069';
  17581. t['\u2172'] = '\u0069\u0069\u0069';
  17582. t['\u2173'] = '\u0069\u0076';
  17583. t['\u2174'] = '\u0076';
  17584. t['\u2175'] = '\u0076\u0069';
  17585. t['\u2176'] = '\u0076\u0069\u0069';
  17586. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17587. t['\u2178'] = '\u0069\u0078';
  17588. t['\u2179'] = '\u0078';
  17589. t['\u217A'] = '\u0078\u0069';
  17590. t['\u217B'] = '\u0078\u0069\u0069';
  17591. t['\u217C'] = '\u006C';
  17592. t['\u217D'] = '\u0063';
  17593. t['\u217E'] = '\u0064';
  17594. t['\u217F'] = '\u006D';
  17595. t['\u222C'] = '\u222B\u222B';
  17596. t['\u222D'] = '\u222B\u222B\u222B';
  17597. t['\u222F'] = '\u222E\u222E';
  17598. t['\u2230'] = '\u222E\u222E\u222E';
  17599. t['\u2474'] = '\u0028\u0031\u0029';
  17600. t['\u2475'] = '\u0028\u0032\u0029';
  17601. t['\u2476'] = '\u0028\u0033\u0029';
  17602. t['\u2477'] = '\u0028\u0034\u0029';
  17603. t['\u2478'] = '\u0028\u0035\u0029';
  17604. t['\u2479'] = '\u0028\u0036\u0029';
  17605. t['\u247A'] = '\u0028\u0037\u0029';
  17606. t['\u247B'] = '\u0028\u0038\u0029';
  17607. t['\u247C'] = '\u0028\u0039\u0029';
  17608. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17609. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17610. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17611. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17612. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17613. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17614. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17615. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17616. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17617. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17618. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17619. t['\u2488'] = '\u0031\u002E';
  17620. t['\u2489'] = '\u0032\u002E';
  17621. t['\u248A'] = '\u0033\u002E';
  17622. t['\u248B'] = '\u0034\u002E';
  17623. t['\u248C'] = '\u0035\u002E';
  17624. t['\u248D'] = '\u0036\u002E';
  17625. t['\u248E'] = '\u0037\u002E';
  17626. t['\u248F'] = '\u0038\u002E';
  17627. t['\u2490'] = '\u0039\u002E';
  17628. t['\u2491'] = '\u0031\u0030\u002E';
  17629. t['\u2492'] = '\u0031\u0031\u002E';
  17630. t['\u2493'] = '\u0031\u0032\u002E';
  17631. t['\u2494'] = '\u0031\u0033\u002E';
  17632. t['\u2495'] = '\u0031\u0034\u002E';
  17633. t['\u2496'] = '\u0031\u0035\u002E';
  17634. t['\u2497'] = '\u0031\u0036\u002E';
  17635. t['\u2498'] = '\u0031\u0037\u002E';
  17636. t['\u2499'] = '\u0031\u0038\u002E';
  17637. t['\u249A'] = '\u0031\u0039\u002E';
  17638. t['\u249B'] = '\u0032\u0030\u002E';
  17639. t['\u249C'] = '\u0028\u0061\u0029';
  17640. t['\u249D'] = '\u0028\u0062\u0029';
  17641. t['\u249E'] = '\u0028\u0063\u0029';
  17642. t['\u249F'] = '\u0028\u0064\u0029';
  17643. t['\u24A0'] = '\u0028\u0065\u0029';
  17644. t['\u24A1'] = '\u0028\u0066\u0029';
  17645. t['\u24A2'] = '\u0028\u0067\u0029';
  17646. t['\u24A3'] = '\u0028\u0068\u0029';
  17647. t['\u24A4'] = '\u0028\u0069\u0029';
  17648. t['\u24A5'] = '\u0028\u006A\u0029';
  17649. t['\u24A6'] = '\u0028\u006B\u0029';
  17650. t['\u24A7'] = '\u0028\u006C\u0029';
  17651. t['\u24A8'] = '\u0028\u006D\u0029';
  17652. t['\u24A9'] = '\u0028\u006E\u0029';
  17653. t['\u24AA'] = '\u0028\u006F\u0029';
  17654. t['\u24AB'] = '\u0028\u0070\u0029';
  17655. t['\u24AC'] = '\u0028\u0071\u0029';
  17656. t['\u24AD'] = '\u0028\u0072\u0029';
  17657. t['\u24AE'] = '\u0028\u0073\u0029';
  17658. t['\u24AF'] = '\u0028\u0074\u0029';
  17659. t['\u24B0'] = '\u0028\u0075\u0029';
  17660. t['\u24B1'] = '\u0028\u0076\u0029';
  17661. t['\u24B2'] = '\u0028\u0077\u0029';
  17662. t['\u24B3'] = '\u0028\u0078\u0029';
  17663. t['\u24B4'] = '\u0028\u0079\u0029';
  17664. t['\u24B5'] = '\u0028\u007A\u0029';
  17665. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17666. t['\u2A74'] = '\u003A\u003A\u003D';
  17667. t['\u2A75'] = '\u003D\u003D';
  17668. t['\u2A76'] = '\u003D\u003D\u003D';
  17669. t['\u2E9F'] = '\u6BCD';
  17670. t['\u2EF3'] = '\u9F9F';
  17671. t['\u2F00'] = '\u4E00';
  17672. t['\u2F01'] = '\u4E28';
  17673. t['\u2F02'] = '\u4E36';
  17674. t['\u2F03'] = '\u4E3F';
  17675. t['\u2F04'] = '\u4E59';
  17676. t['\u2F05'] = '\u4E85';
  17677. t['\u2F06'] = '\u4E8C';
  17678. t['\u2F07'] = '\u4EA0';
  17679. t['\u2F08'] = '\u4EBA';
  17680. t['\u2F09'] = '\u513F';
  17681. t['\u2F0A'] = '\u5165';
  17682. t['\u2F0B'] = '\u516B';
  17683. t['\u2F0C'] = '\u5182';
  17684. t['\u2F0D'] = '\u5196';
  17685. t['\u2F0E'] = '\u51AB';
  17686. t['\u2F0F'] = '\u51E0';
  17687. t['\u2F10'] = '\u51F5';
  17688. t['\u2F11'] = '\u5200';
  17689. t['\u2F12'] = '\u529B';
  17690. t['\u2F13'] = '\u52F9';
  17691. t['\u2F14'] = '\u5315';
  17692. t['\u2F15'] = '\u531A';
  17693. t['\u2F16'] = '\u5338';
  17694. t['\u2F17'] = '\u5341';
  17695. t['\u2F18'] = '\u535C';
  17696. t['\u2F19'] = '\u5369';
  17697. t['\u2F1A'] = '\u5382';
  17698. t['\u2F1B'] = '\u53B6';
  17699. t['\u2F1C'] = '\u53C8';
  17700. t['\u2F1D'] = '\u53E3';
  17701. t['\u2F1E'] = '\u56D7';
  17702. t['\u2F1F'] = '\u571F';
  17703. t['\u2F20'] = '\u58EB';
  17704. t['\u2F21'] = '\u5902';
  17705. t['\u2F22'] = '\u590A';
  17706. t['\u2F23'] = '\u5915';
  17707. t['\u2F24'] = '\u5927';
  17708. t['\u2F25'] = '\u5973';
  17709. t['\u2F26'] = '\u5B50';
  17710. t['\u2F27'] = '\u5B80';
  17711. t['\u2F28'] = '\u5BF8';
  17712. t['\u2F29'] = '\u5C0F';
  17713. t['\u2F2A'] = '\u5C22';
  17714. t['\u2F2B'] = '\u5C38';
  17715. t['\u2F2C'] = '\u5C6E';
  17716. t['\u2F2D'] = '\u5C71';
  17717. t['\u2F2E'] = '\u5DDB';
  17718. t['\u2F2F'] = '\u5DE5';
  17719. t['\u2F30'] = '\u5DF1';
  17720. t['\u2F31'] = '\u5DFE';
  17721. t['\u2F32'] = '\u5E72';
  17722. t['\u2F33'] = '\u5E7A';
  17723. t['\u2F34'] = '\u5E7F';
  17724. t['\u2F35'] = '\u5EF4';
  17725. t['\u2F36'] = '\u5EFE';
  17726. t['\u2F37'] = '\u5F0B';
  17727. t['\u2F38'] = '\u5F13';
  17728. t['\u2F39'] = '\u5F50';
  17729. t['\u2F3A'] = '\u5F61';
  17730. t['\u2F3B'] = '\u5F73';
  17731. t['\u2F3C'] = '\u5FC3';
  17732. t['\u2F3D'] = '\u6208';
  17733. t['\u2F3E'] = '\u6236';
  17734. t['\u2F3F'] = '\u624B';
  17735. t['\u2F40'] = '\u652F';
  17736. t['\u2F41'] = '\u6534';
  17737. t['\u2F42'] = '\u6587';
  17738. t['\u2F43'] = '\u6597';
  17739. t['\u2F44'] = '\u65A4';
  17740. t['\u2F45'] = '\u65B9';
  17741. t['\u2F46'] = '\u65E0';
  17742. t['\u2F47'] = '\u65E5';
  17743. t['\u2F48'] = '\u66F0';
  17744. t['\u2F49'] = '\u6708';
  17745. t['\u2F4A'] = '\u6728';
  17746. t['\u2F4B'] = '\u6B20';
  17747. t['\u2F4C'] = '\u6B62';
  17748. t['\u2F4D'] = '\u6B79';
  17749. t['\u2F4E'] = '\u6BB3';
  17750. t['\u2F4F'] = '\u6BCB';
  17751. t['\u2F50'] = '\u6BD4';
  17752. t['\u2F51'] = '\u6BDB';
  17753. t['\u2F52'] = '\u6C0F';
  17754. t['\u2F53'] = '\u6C14';
  17755. t['\u2F54'] = '\u6C34';
  17756. t['\u2F55'] = '\u706B';
  17757. t['\u2F56'] = '\u722A';
  17758. t['\u2F57'] = '\u7236';
  17759. t['\u2F58'] = '\u723B';
  17760. t['\u2F59'] = '\u723F';
  17761. t['\u2F5A'] = '\u7247';
  17762. t['\u2F5B'] = '\u7259';
  17763. t['\u2F5C'] = '\u725B';
  17764. t['\u2F5D'] = '\u72AC';
  17765. t['\u2F5E'] = '\u7384';
  17766. t['\u2F5F'] = '\u7389';
  17767. t['\u2F60'] = '\u74DC';
  17768. t['\u2F61'] = '\u74E6';
  17769. t['\u2F62'] = '\u7518';
  17770. t['\u2F63'] = '\u751F';
  17771. t['\u2F64'] = '\u7528';
  17772. t['\u2F65'] = '\u7530';
  17773. t['\u2F66'] = '\u758B';
  17774. t['\u2F67'] = '\u7592';
  17775. t['\u2F68'] = '\u7676';
  17776. t['\u2F69'] = '\u767D';
  17777. t['\u2F6A'] = '\u76AE';
  17778. t['\u2F6B'] = '\u76BF';
  17779. t['\u2F6C'] = '\u76EE';
  17780. t['\u2F6D'] = '\u77DB';
  17781. t['\u2F6E'] = '\u77E2';
  17782. t['\u2F6F'] = '\u77F3';
  17783. t['\u2F70'] = '\u793A';
  17784. t['\u2F71'] = '\u79B8';
  17785. t['\u2F72'] = '\u79BE';
  17786. t['\u2F73'] = '\u7A74';
  17787. t['\u2F74'] = '\u7ACB';
  17788. t['\u2F75'] = '\u7AF9';
  17789. t['\u2F76'] = '\u7C73';
  17790. t['\u2F77'] = '\u7CF8';
  17791. t['\u2F78'] = '\u7F36';
  17792. t['\u2F79'] = '\u7F51';
  17793. t['\u2F7A'] = '\u7F8A';
  17794. t['\u2F7B'] = '\u7FBD';
  17795. t['\u2F7C'] = '\u8001';
  17796. t['\u2F7D'] = '\u800C';
  17797. t['\u2F7E'] = '\u8012';
  17798. t['\u2F7F'] = '\u8033';
  17799. t['\u2F80'] = '\u807F';
  17800. t['\u2F81'] = '\u8089';
  17801. t['\u2F82'] = '\u81E3';
  17802. t['\u2F83'] = '\u81EA';
  17803. t['\u2F84'] = '\u81F3';
  17804. t['\u2F85'] = '\u81FC';
  17805. t['\u2F86'] = '\u820C';
  17806. t['\u2F87'] = '\u821B';
  17807. t['\u2F88'] = '\u821F';
  17808. t['\u2F89'] = '\u826E';
  17809. t['\u2F8A'] = '\u8272';
  17810. t['\u2F8B'] = '\u8278';
  17811. t['\u2F8C'] = '\u864D';
  17812. t['\u2F8D'] = '\u866B';
  17813. t['\u2F8E'] = '\u8840';
  17814. t['\u2F8F'] = '\u884C';
  17815. t['\u2F90'] = '\u8863';
  17816. t['\u2F91'] = '\u897E';
  17817. t['\u2F92'] = '\u898B';
  17818. t['\u2F93'] = '\u89D2';
  17819. t['\u2F94'] = '\u8A00';
  17820. t['\u2F95'] = '\u8C37';
  17821. t['\u2F96'] = '\u8C46';
  17822. t['\u2F97'] = '\u8C55';
  17823. t['\u2F98'] = '\u8C78';
  17824. t['\u2F99'] = '\u8C9D';
  17825. t['\u2F9A'] = '\u8D64';
  17826. t['\u2F9B'] = '\u8D70';
  17827. t['\u2F9C'] = '\u8DB3';
  17828. t['\u2F9D'] = '\u8EAB';
  17829. t['\u2F9E'] = '\u8ECA';
  17830. t['\u2F9F'] = '\u8F9B';
  17831. t['\u2FA0'] = '\u8FB0';
  17832. t['\u2FA1'] = '\u8FB5';
  17833. t['\u2FA2'] = '\u9091';
  17834. t['\u2FA3'] = '\u9149';
  17835. t['\u2FA4'] = '\u91C6';
  17836. t['\u2FA5'] = '\u91CC';
  17837. t['\u2FA6'] = '\u91D1';
  17838. t['\u2FA7'] = '\u9577';
  17839. t['\u2FA8'] = '\u9580';
  17840. t['\u2FA9'] = '\u961C';
  17841. t['\u2FAA'] = '\u96B6';
  17842. t['\u2FAB'] = '\u96B9';
  17843. t['\u2FAC'] = '\u96E8';
  17844. t['\u2FAD'] = '\u9751';
  17845. t['\u2FAE'] = '\u975E';
  17846. t['\u2FAF'] = '\u9762';
  17847. t['\u2FB0'] = '\u9769';
  17848. t['\u2FB1'] = '\u97CB';
  17849. t['\u2FB2'] = '\u97ED';
  17850. t['\u2FB3'] = '\u97F3';
  17851. t['\u2FB4'] = '\u9801';
  17852. t['\u2FB5'] = '\u98A8';
  17853. t['\u2FB6'] = '\u98DB';
  17854. t['\u2FB7'] = '\u98DF';
  17855. t['\u2FB8'] = '\u9996';
  17856. t['\u2FB9'] = '\u9999';
  17857. t['\u2FBA'] = '\u99AC';
  17858. t['\u2FBB'] = '\u9AA8';
  17859. t['\u2FBC'] = '\u9AD8';
  17860. t['\u2FBD'] = '\u9ADF';
  17861. t['\u2FBE'] = '\u9B25';
  17862. t['\u2FBF'] = '\u9B2F';
  17863. t['\u2FC0'] = '\u9B32';
  17864. t['\u2FC1'] = '\u9B3C';
  17865. t['\u2FC2'] = '\u9B5A';
  17866. t['\u2FC3'] = '\u9CE5';
  17867. t['\u2FC4'] = '\u9E75';
  17868. t['\u2FC5'] = '\u9E7F';
  17869. t['\u2FC6'] = '\u9EA5';
  17870. t['\u2FC7'] = '\u9EBB';
  17871. t['\u2FC8'] = '\u9EC3';
  17872. t['\u2FC9'] = '\u9ECD';
  17873. t['\u2FCA'] = '\u9ED1';
  17874. t['\u2FCB'] = '\u9EF9';
  17875. t['\u2FCC'] = '\u9EFD';
  17876. t['\u2FCD'] = '\u9F0E';
  17877. t['\u2FCE'] = '\u9F13';
  17878. t['\u2FCF'] = '\u9F20';
  17879. t['\u2FD0'] = '\u9F3B';
  17880. t['\u2FD1'] = '\u9F4A';
  17881. t['\u2FD2'] = '\u9F52';
  17882. t['\u2FD3'] = '\u9F8D';
  17883. t['\u2FD4'] = '\u9F9C';
  17884. t['\u2FD5'] = '\u9FA0';
  17885. t['\u3036'] = '\u3012';
  17886. t['\u3038'] = '\u5341';
  17887. t['\u3039'] = '\u5344';
  17888. t['\u303A'] = '\u5345';
  17889. t['\u309B'] = '\u0020\u3099';
  17890. t['\u309C'] = '\u0020\u309A';
  17891. t['\u3131'] = '\u1100';
  17892. t['\u3132'] = '\u1101';
  17893. t['\u3133'] = '\u11AA';
  17894. t['\u3134'] = '\u1102';
  17895. t['\u3135'] = '\u11AC';
  17896. t['\u3136'] = '\u11AD';
  17897. t['\u3137'] = '\u1103';
  17898. t['\u3138'] = '\u1104';
  17899. t['\u3139'] = '\u1105';
  17900. t['\u313A'] = '\u11B0';
  17901. t['\u313B'] = '\u11B1';
  17902. t['\u313C'] = '\u11B2';
  17903. t['\u313D'] = '\u11B3';
  17904. t['\u313E'] = '\u11B4';
  17905. t['\u313F'] = '\u11B5';
  17906. t['\u3140'] = '\u111A';
  17907. t['\u3141'] = '\u1106';
  17908. t['\u3142'] = '\u1107';
  17909. t['\u3143'] = '\u1108';
  17910. t['\u3144'] = '\u1121';
  17911. t['\u3145'] = '\u1109';
  17912. t['\u3146'] = '\u110A';
  17913. t['\u3147'] = '\u110B';
  17914. t['\u3148'] = '\u110C';
  17915. t['\u3149'] = '\u110D';
  17916. t['\u314A'] = '\u110E';
  17917. t['\u314B'] = '\u110F';
  17918. t['\u314C'] = '\u1110';
  17919. t['\u314D'] = '\u1111';
  17920. t['\u314E'] = '\u1112';
  17921. t['\u314F'] = '\u1161';
  17922. t['\u3150'] = '\u1162';
  17923. t['\u3151'] = '\u1163';
  17924. t['\u3152'] = '\u1164';
  17925. t['\u3153'] = '\u1165';
  17926. t['\u3154'] = '\u1166';
  17927. t['\u3155'] = '\u1167';
  17928. t['\u3156'] = '\u1168';
  17929. t['\u3157'] = '\u1169';
  17930. t['\u3158'] = '\u116A';
  17931. t['\u3159'] = '\u116B';
  17932. t['\u315A'] = '\u116C';
  17933. t['\u315B'] = '\u116D';
  17934. t['\u315C'] = '\u116E';
  17935. t['\u315D'] = '\u116F';
  17936. t['\u315E'] = '\u1170';
  17937. t['\u315F'] = '\u1171';
  17938. t['\u3160'] = '\u1172';
  17939. t['\u3161'] = '\u1173';
  17940. t['\u3162'] = '\u1174';
  17941. t['\u3163'] = '\u1175';
  17942. t['\u3164'] = '\u1160';
  17943. t['\u3165'] = '\u1114';
  17944. t['\u3166'] = '\u1115';
  17945. t['\u3167'] = '\u11C7';
  17946. t['\u3168'] = '\u11C8';
  17947. t['\u3169'] = '\u11CC';
  17948. t['\u316A'] = '\u11CE';
  17949. t['\u316B'] = '\u11D3';
  17950. t['\u316C'] = '\u11D7';
  17951. t['\u316D'] = '\u11D9';
  17952. t['\u316E'] = '\u111C';
  17953. t['\u316F'] = '\u11DD';
  17954. t['\u3170'] = '\u11DF';
  17955. t['\u3171'] = '\u111D';
  17956. t['\u3172'] = '\u111E';
  17957. t['\u3173'] = '\u1120';
  17958. t['\u3174'] = '\u1122';
  17959. t['\u3175'] = '\u1123';
  17960. t['\u3176'] = '\u1127';
  17961. t['\u3177'] = '\u1129';
  17962. t['\u3178'] = '\u112B';
  17963. t['\u3179'] = '\u112C';
  17964. t['\u317A'] = '\u112D';
  17965. t['\u317B'] = '\u112E';
  17966. t['\u317C'] = '\u112F';
  17967. t['\u317D'] = '\u1132';
  17968. t['\u317E'] = '\u1136';
  17969. t['\u317F'] = '\u1140';
  17970. t['\u3180'] = '\u1147';
  17971. t['\u3181'] = '\u114C';
  17972. t['\u3182'] = '\u11F1';
  17973. t['\u3183'] = '\u11F2';
  17974. t['\u3184'] = '\u1157';
  17975. t['\u3185'] = '\u1158';
  17976. t['\u3186'] = '\u1159';
  17977. t['\u3187'] = '\u1184';
  17978. t['\u3188'] = '\u1185';
  17979. t['\u3189'] = '\u1188';
  17980. t['\u318A'] = '\u1191';
  17981. t['\u318B'] = '\u1192';
  17982. t['\u318C'] = '\u1194';
  17983. t['\u318D'] = '\u119E';
  17984. t['\u318E'] = '\u11A1';
  17985. t['\u3200'] = '\u0028\u1100\u0029';
  17986. t['\u3201'] = '\u0028\u1102\u0029';
  17987. t['\u3202'] = '\u0028\u1103\u0029';
  17988. t['\u3203'] = '\u0028\u1105\u0029';
  17989. t['\u3204'] = '\u0028\u1106\u0029';
  17990. t['\u3205'] = '\u0028\u1107\u0029';
  17991. t['\u3206'] = '\u0028\u1109\u0029';
  17992. t['\u3207'] = '\u0028\u110B\u0029';
  17993. t['\u3208'] = '\u0028\u110C\u0029';
  17994. t['\u3209'] = '\u0028\u110E\u0029';
  17995. t['\u320A'] = '\u0028\u110F\u0029';
  17996. t['\u320B'] = '\u0028\u1110\u0029';
  17997. t['\u320C'] = '\u0028\u1111\u0029';
  17998. t['\u320D'] = '\u0028\u1112\u0029';
  17999. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18000. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18001. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18002. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18003. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18004. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18005. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18006. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18007. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18008. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18009. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18010. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18011. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18012. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18013. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18014. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18015. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18016. t['\u3220'] = '\u0028\u4E00\u0029';
  18017. t['\u3221'] = '\u0028\u4E8C\u0029';
  18018. t['\u3222'] = '\u0028\u4E09\u0029';
  18019. t['\u3223'] = '\u0028\u56DB\u0029';
  18020. t['\u3224'] = '\u0028\u4E94\u0029';
  18021. t['\u3225'] = '\u0028\u516D\u0029';
  18022. t['\u3226'] = '\u0028\u4E03\u0029';
  18023. t['\u3227'] = '\u0028\u516B\u0029';
  18024. t['\u3228'] = '\u0028\u4E5D\u0029';
  18025. t['\u3229'] = '\u0028\u5341\u0029';
  18026. t['\u322A'] = '\u0028\u6708\u0029';
  18027. t['\u322B'] = '\u0028\u706B\u0029';
  18028. t['\u322C'] = '\u0028\u6C34\u0029';
  18029. t['\u322D'] = '\u0028\u6728\u0029';
  18030. t['\u322E'] = '\u0028\u91D1\u0029';
  18031. t['\u322F'] = '\u0028\u571F\u0029';
  18032. t['\u3230'] = '\u0028\u65E5\u0029';
  18033. t['\u3231'] = '\u0028\u682A\u0029';
  18034. t['\u3232'] = '\u0028\u6709\u0029';
  18035. t['\u3233'] = '\u0028\u793E\u0029';
  18036. t['\u3234'] = '\u0028\u540D\u0029';
  18037. t['\u3235'] = '\u0028\u7279\u0029';
  18038. t['\u3236'] = '\u0028\u8CA1\u0029';
  18039. t['\u3237'] = '\u0028\u795D\u0029';
  18040. t['\u3238'] = '\u0028\u52B4\u0029';
  18041. t['\u3239'] = '\u0028\u4EE3\u0029';
  18042. t['\u323A'] = '\u0028\u547C\u0029';
  18043. t['\u323B'] = '\u0028\u5B66\u0029';
  18044. t['\u323C'] = '\u0028\u76E3\u0029';
  18045. t['\u323D'] = '\u0028\u4F01\u0029';
  18046. t['\u323E'] = '\u0028\u8CC7\u0029';
  18047. t['\u323F'] = '\u0028\u5354\u0029';
  18048. t['\u3240'] = '\u0028\u796D\u0029';
  18049. t['\u3241'] = '\u0028\u4F11\u0029';
  18050. t['\u3242'] = '\u0028\u81EA\u0029';
  18051. t['\u3243'] = '\u0028\u81F3\u0029';
  18052. t['\u32C0'] = '\u0031\u6708';
  18053. t['\u32C1'] = '\u0032\u6708';
  18054. t['\u32C2'] = '\u0033\u6708';
  18055. t['\u32C3'] = '\u0034\u6708';
  18056. t['\u32C4'] = '\u0035\u6708';
  18057. t['\u32C5'] = '\u0036\u6708';
  18058. t['\u32C6'] = '\u0037\u6708';
  18059. t['\u32C7'] = '\u0038\u6708';
  18060. t['\u32C8'] = '\u0039\u6708';
  18061. t['\u32C9'] = '\u0031\u0030\u6708';
  18062. t['\u32CA'] = '\u0031\u0031\u6708';
  18063. t['\u32CB'] = '\u0031\u0032\u6708';
  18064. t['\u3358'] = '\u0030\u70B9';
  18065. t['\u3359'] = '\u0031\u70B9';
  18066. t['\u335A'] = '\u0032\u70B9';
  18067. t['\u335B'] = '\u0033\u70B9';
  18068. t['\u335C'] = '\u0034\u70B9';
  18069. t['\u335D'] = '\u0035\u70B9';
  18070. t['\u335E'] = '\u0036\u70B9';
  18071. t['\u335F'] = '\u0037\u70B9';
  18072. t['\u3360'] = '\u0038\u70B9';
  18073. t['\u3361'] = '\u0039\u70B9';
  18074. t['\u3362'] = '\u0031\u0030\u70B9';
  18075. t['\u3363'] = '\u0031\u0031\u70B9';
  18076. t['\u3364'] = '\u0031\u0032\u70B9';
  18077. t['\u3365'] = '\u0031\u0033\u70B9';
  18078. t['\u3366'] = '\u0031\u0034\u70B9';
  18079. t['\u3367'] = '\u0031\u0035\u70B9';
  18080. t['\u3368'] = '\u0031\u0036\u70B9';
  18081. t['\u3369'] = '\u0031\u0037\u70B9';
  18082. t['\u336A'] = '\u0031\u0038\u70B9';
  18083. t['\u336B'] = '\u0031\u0039\u70B9';
  18084. t['\u336C'] = '\u0032\u0030\u70B9';
  18085. t['\u336D'] = '\u0032\u0031\u70B9';
  18086. t['\u336E'] = '\u0032\u0032\u70B9';
  18087. t['\u336F'] = '\u0032\u0033\u70B9';
  18088. t['\u3370'] = '\u0032\u0034\u70B9';
  18089. t['\u33E0'] = '\u0031\u65E5';
  18090. t['\u33E1'] = '\u0032\u65E5';
  18091. t['\u33E2'] = '\u0033\u65E5';
  18092. t['\u33E3'] = '\u0034\u65E5';
  18093. t['\u33E4'] = '\u0035\u65E5';
  18094. t['\u33E5'] = '\u0036\u65E5';
  18095. t['\u33E6'] = '\u0037\u65E5';
  18096. t['\u33E7'] = '\u0038\u65E5';
  18097. t['\u33E8'] = '\u0039\u65E5';
  18098. t['\u33E9'] = '\u0031\u0030\u65E5';
  18099. t['\u33EA'] = '\u0031\u0031\u65E5';
  18100. t['\u33EB'] = '\u0031\u0032\u65E5';
  18101. t['\u33EC'] = '\u0031\u0033\u65E5';
  18102. t['\u33ED'] = '\u0031\u0034\u65E5';
  18103. t['\u33EE'] = '\u0031\u0035\u65E5';
  18104. t['\u33EF'] = '\u0031\u0036\u65E5';
  18105. t['\u33F0'] = '\u0031\u0037\u65E5';
  18106. t['\u33F1'] = '\u0031\u0038\u65E5';
  18107. t['\u33F2'] = '\u0031\u0039\u65E5';
  18108. t['\u33F3'] = '\u0032\u0030\u65E5';
  18109. t['\u33F4'] = '\u0032\u0031\u65E5';
  18110. t['\u33F5'] = '\u0032\u0032\u65E5';
  18111. t['\u33F6'] = '\u0032\u0033\u65E5';
  18112. t['\u33F7'] = '\u0032\u0034\u65E5';
  18113. t['\u33F8'] = '\u0032\u0035\u65E5';
  18114. t['\u33F9'] = '\u0032\u0036\u65E5';
  18115. t['\u33FA'] = '\u0032\u0037\u65E5';
  18116. t['\u33FB'] = '\u0032\u0038\u65E5';
  18117. t['\u33FC'] = '\u0032\u0039\u65E5';
  18118. t['\u33FD'] = '\u0033\u0030\u65E5';
  18119. t['\u33FE'] = '\u0033\u0031\u65E5';
  18120. t['\uFB00'] = '\u0066\u0066';
  18121. t['\uFB01'] = '\u0066\u0069';
  18122. t['\uFB02'] = '\u0066\u006C';
  18123. t['\uFB03'] = '\u0066\u0066\u0069';
  18124. t['\uFB04'] = '\u0066\u0066\u006C';
  18125. t['\uFB05'] = '\u017F\u0074';
  18126. t['\uFB06'] = '\u0073\u0074';
  18127. t['\uFB13'] = '\u0574\u0576';
  18128. t['\uFB14'] = '\u0574\u0565';
  18129. t['\uFB15'] = '\u0574\u056B';
  18130. t['\uFB16'] = '\u057E\u0576';
  18131. t['\uFB17'] = '\u0574\u056D';
  18132. t['\uFB4F'] = '\u05D0\u05DC';
  18133. t['\uFB50'] = '\u0671';
  18134. t['\uFB51'] = '\u0671';
  18135. t['\uFB52'] = '\u067B';
  18136. t['\uFB53'] = '\u067B';
  18137. t['\uFB54'] = '\u067B';
  18138. t['\uFB55'] = '\u067B';
  18139. t['\uFB56'] = '\u067E';
  18140. t['\uFB57'] = '\u067E';
  18141. t['\uFB58'] = '\u067E';
  18142. t['\uFB59'] = '\u067E';
  18143. t['\uFB5A'] = '\u0680';
  18144. t['\uFB5B'] = '\u0680';
  18145. t['\uFB5C'] = '\u0680';
  18146. t['\uFB5D'] = '\u0680';
  18147. t['\uFB5E'] = '\u067A';
  18148. t['\uFB5F'] = '\u067A';
  18149. t['\uFB60'] = '\u067A';
  18150. t['\uFB61'] = '\u067A';
  18151. t['\uFB62'] = '\u067F';
  18152. t['\uFB63'] = '\u067F';
  18153. t['\uFB64'] = '\u067F';
  18154. t['\uFB65'] = '\u067F';
  18155. t['\uFB66'] = '\u0679';
  18156. t['\uFB67'] = '\u0679';
  18157. t['\uFB68'] = '\u0679';
  18158. t['\uFB69'] = '\u0679';
  18159. t['\uFB6A'] = '\u06A4';
  18160. t['\uFB6B'] = '\u06A4';
  18161. t['\uFB6C'] = '\u06A4';
  18162. t['\uFB6D'] = '\u06A4';
  18163. t['\uFB6E'] = '\u06A6';
  18164. t['\uFB6F'] = '\u06A6';
  18165. t['\uFB70'] = '\u06A6';
  18166. t['\uFB71'] = '\u06A6';
  18167. t['\uFB72'] = '\u0684';
  18168. t['\uFB73'] = '\u0684';
  18169. t['\uFB74'] = '\u0684';
  18170. t['\uFB75'] = '\u0684';
  18171. t['\uFB76'] = '\u0683';
  18172. t['\uFB77'] = '\u0683';
  18173. t['\uFB78'] = '\u0683';
  18174. t['\uFB79'] = '\u0683';
  18175. t['\uFB7A'] = '\u0686';
  18176. t['\uFB7B'] = '\u0686';
  18177. t['\uFB7C'] = '\u0686';
  18178. t['\uFB7D'] = '\u0686';
  18179. t['\uFB7E'] = '\u0687';
  18180. t['\uFB7F'] = '\u0687';
  18181. t['\uFB80'] = '\u0687';
  18182. t['\uFB81'] = '\u0687';
  18183. t['\uFB82'] = '\u068D';
  18184. t['\uFB83'] = '\u068D';
  18185. t['\uFB84'] = '\u068C';
  18186. t['\uFB85'] = '\u068C';
  18187. t['\uFB86'] = '\u068E';
  18188. t['\uFB87'] = '\u068E';
  18189. t['\uFB88'] = '\u0688';
  18190. t['\uFB89'] = '\u0688';
  18191. t['\uFB8A'] = '\u0698';
  18192. t['\uFB8B'] = '\u0698';
  18193. t['\uFB8C'] = '\u0691';
  18194. t['\uFB8D'] = '\u0691';
  18195. t['\uFB8E'] = '\u06A9';
  18196. t['\uFB8F'] = '\u06A9';
  18197. t['\uFB90'] = '\u06A9';
  18198. t['\uFB91'] = '\u06A9';
  18199. t['\uFB92'] = '\u06AF';
  18200. t['\uFB93'] = '\u06AF';
  18201. t['\uFB94'] = '\u06AF';
  18202. t['\uFB95'] = '\u06AF';
  18203. t['\uFB96'] = '\u06B3';
  18204. t['\uFB97'] = '\u06B3';
  18205. t['\uFB98'] = '\u06B3';
  18206. t['\uFB99'] = '\u06B3';
  18207. t['\uFB9A'] = '\u06B1';
  18208. t['\uFB9B'] = '\u06B1';
  18209. t['\uFB9C'] = '\u06B1';
  18210. t['\uFB9D'] = '\u06B1';
  18211. t['\uFB9E'] = '\u06BA';
  18212. t['\uFB9F'] = '\u06BA';
  18213. t['\uFBA0'] = '\u06BB';
  18214. t['\uFBA1'] = '\u06BB';
  18215. t['\uFBA2'] = '\u06BB';
  18216. t['\uFBA3'] = '\u06BB';
  18217. t['\uFBA4'] = '\u06C0';
  18218. t['\uFBA5'] = '\u06C0';
  18219. t['\uFBA6'] = '\u06C1';
  18220. t['\uFBA7'] = '\u06C1';
  18221. t['\uFBA8'] = '\u06C1';
  18222. t['\uFBA9'] = '\u06C1';
  18223. t['\uFBAA'] = '\u06BE';
  18224. t['\uFBAB'] = '\u06BE';
  18225. t['\uFBAC'] = '\u06BE';
  18226. t['\uFBAD'] = '\u06BE';
  18227. t['\uFBAE'] = '\u06D2';
  18228. t['\uFBAF'] = '\u06D2';
  18229. t['\uFBB0'] = '\u06D3';
  18230. t['\uFBB1'] = '\u06D3';
  18231. t['\uFBD3'] = '\u06AD';
  18232. t['\uFBD4'] = '\u06AD';
  18233. t['\uFBD5'] = '\u06AD';
  18234. t['\uFBD6'] = '\u06AD';
  18235. t['\uFBD7'] = '\u06C7';
  18236. t['\uFBD8'] = '\u06C7';
  18237. t['\uFBD9'] = '\u06C6';
  18238. t['\uFBDA'] = '\u06C6';
  18239. t['\uFBDB'] = '\u06C8';
  18240. t['\uFBDC'] = '\u06C8';
  18241. t['\uFBDD'] = '\u0677';
  18242. t['\uFBDE'] = '\u06CB';
  18243. t['\uFBDF'] = '\u06CB';
  18244. t['\uFBE0'] = '\u06C5';
  18245. t['\uFBE1'] = '\u06C5';
  18246. t['\uFBE2'] = '\u06C9';
  18247. t['\uFBE3'] = '\u06C9';
  18248. t['\uFBE4'] = '\u06D0';
  18249. t['\uFBE5'] = '\u06D0';
  18250. t['\uFBE6'] = '\u06D0';
  18251. t['\uFBE7'] = '\u06D0';
  18252. t['\uFBE8'] = '\u0649';
  18253. t['\uFBE9'] = '\u0649';
  18254. t['\uFBEA'] = '\u0626\u0627';
  18255. t['\uFBEB'] = '\u0626\u0627';
  18256. t['\uFBEC'] = '\u0626\u06D5';
  18257. t['\uFBED'] = '\u0626\u06D5';
  18258. t['\uFBEE'] = '\u0626\u0648';
  18259. t['\uFBEF'] = '\u0626\u0648';
  18260. t['\uFBF0'] = '\u0626\u06C7';
  18261. t['\uFBF1'] = '\u0626\u06C7';
  18262. t['\uFBF2'] = '\u0626\u06C6';
  18263. t['\uFBF3'] = '\u0626\u06C6';
  18264. t['\uFBF4'] = '\u0626\u06C8';
  18265. t['\uFBF5'] = '\u0626\u06C8';
  18266. t['\uFBF6'] = '\u0626\u06D0';
  18267. t['\uFBF7'] = '\u0626\u06D0';
  18268. t['\uFBF8'] = '\u0626\u06D0';
  18269. t['\uFBF9'] = '\u0626\u0649';
  18270. t['\uFBFA'] = '\u0626\u0649';
  18271. t['\uFBFB'] = '\u0626\u0649';
  18272. t['\uFBFC'] = '\u06CC';
  18273. t['\uFBFD'] = '\u06CC';
  18274. t['\uFBFE'] = '\u06CC';
  18275. t['\uFBFF'] = '\u06CC';
  18276. t['\uFC00'] = '\u0626\u062C';
  18277. t['\uFC01'] = '\u0626\u062D';
  18278. t['\uFC02'] = '\u0626\u0645';
  18279. t['\uFC03'] = '\u0626\u0649';
  18280. t['\uFC04'] = '\u0626\u064A';
  18281. t['\uFC05'] = '\u0628\u062C';
  18282. t['\uFC06'] = '\u0628\u062D';
  18283. t['\uFC07'] = '\u0628\u062E';
  18284. t['\uFC08'] = '\u0628\u0645';
  18285. t['\uFC09'] = '\u0628\u0649';
  18286. t['\uFC0A'] = '\u0628\u064A';
  18287. t['\uFC0B'] = '\u062A\u062C';
  18288. t['\uFC0C'] = '\u062A\u062D';
  18289. t['\uFC0D'] = '\u062A\u062E';
  18290. t['\uFC0E'] = '\u062A\u0645';
  18291. t['\uFC0F'] = '\u062A\u0649';
  18292. t['\uFC10'] = '\u062A\u064A';
  18293. t['\uFC11'] = '\u062B\u062C';
  18294. t['\uFC12'] = '\u062B\u0645';
  18295. t['\uFC13'] = '\u062B\u0649';
  18296. t['\uFC14'] = '\u062B\u064A';
  18297. t['\uFC15'] = '\u062C\u062D';
  18298. t['\uFC16'] = '\u062C\u0645';
  18299. t['\uFC17'] = '\u062D\u062C';
  18300. t['\uFC18'] = '\u062D\u0645';
  18301. t['\uFC19'] = '\u062E\u062C';
  18302. t['\uFC1A'] = '\u062E\u062D';
  18303. t['\uFC1B'] = '\u062E\u0645';
  18304. t['\uFC1C'] = '\u0633\u062C';
  18305. t['\uFC1D'] = '\u0633\u062D';
  18306. t['\uFC1E'] = '\u0633\u062E';
  18307. t['\uFC1F'] = '\u0633\u0645';
  18308. t['\uFC20'] = '\u0635\u062D';
  18309. t['\uFC21'] = '\u0635\u0645';
  18310. t['\uFC22'] = '\u0636\u062C';
  18311. t['\uFC23'] = '\u0636\u062D';
  18312. t['\uFC24'] = '\u0636\u062E';
  18313. t['\uFC25'] = '\u0636\u0645';
  18314. t['\uFC26'] = '\u0637\u062D';
  18315. t['\uFC27'] = '\u0637\u0645';
  18316. t['\uFC28'] = '\u0638\u0645';
  18317. t['\uFC29'] = '\u0639\u062C';
  18318. t['\uFC2A'] = '\u0639\u0645';
  18319. t['\uFC2B'] = '\u063A\u062C';
  18320. t['\uFC2C'] = '\u063A\u0645';
  18321. t['\uFC2D'] = '\u0641\u062C';
  18322. t['\uFC2E'] = '\u0641\u062D';
  18323. t['\uFC2F'] = '\u0641\u062E';
  18324. t['\uFC30'] = '\u0641\u0645';
  18325. t['\uFC31'] = '\u0641\u0649';
  18326. t['\uFC32'] = '\u0641\u064A';
  18327. t['\uFC33'] = '\u0642\u062D';
  18328. t['\uFC34'] = '\u0642\u0645';
  18329. t['\uFC35'] = '\u0642\u0649';
  18330. t['\uFC36'] = '\u0642\u064A';
  18331. t['\uFC37'] = '\u0643\u0627';
  18332. t['\uFC38'] = '\u0643\u062C';
  18333. t['\uFC39'] = '\u0643\u062D';
  18334. t['\uFC3A'] = '\u0643\u062E';
  18335. t['\uFC3B'] = '\u0643\u0644';
  18336. t['\uFC3C'] = '\u0643\u0645';
  18337. t['\uFC3D'] = '\u0643\u0649';
  18338. t['\uFC3E'] = '\u0643\u064A';
  18339. t['\uFC3F'] = '\u0644\u062C';
  18340. t['\uFC40'] = '\u0644\u062D';
  18341. t['\uFC41'] = '\u0644\u062E';
  18342. t['\uFC42'] = '\u0644\u0645';
  18343. t['\uFC43'] = '\u0644\u0649';
  18344. t['\uFC44'] = '\u0644\u064A';
  18345. t['\uFC45'] = '\u0645\u062C';
  18346. t['\uFC46'] = '\u0645\u062D';
  18347. t['\uFC47'] = '\u0645\u062E';
  18348. t['\uFC48'] = '\u0645\u0645';
  18349. t['\uFC49'] = '\u0645\u0649';
  18350. t['\uFC4A'] = '\u0645\u064A';
  18351. t['\uFC4B'] = '\u0646\u062C';
  18352. t['\uFC4C'] = '\u0646\u062D';
  18353. t['\uFC4D'] = '\u0646\u062E';
  18354. t['\uFC4E'] = '\u0646\u0645';
  18355. t['\uFC4F'] = '\u0646\u0649';
  18356. t['\uFC50'] = '\u0646\u064A';
  18357. t['\uFC51'] = '\u0647\u062C';
  18358. t['\uFC52'] = '\u0647\u0645';
  18359. t['\uFC53'] = '\u0647\u0649';
  18360. t['\uFC54'] = '\u0647\u064A';
  18361. t['\uFC55'] = '\u064A\u062C';
  18362. t['\uFC56'] = '\u064A\u062D';
  18363. t['\uFC57'] = '\u064A\u062E';
  18364. t['\uFC58'] = '\u064A\u0645';
  18365. t['\uFC59'] = '\u064A\u0649';
  18366. t['\uFC5A'] = '\u064A\u064A';
  18367. t['\uFC5B'] = '\u0630\u0670';
  18368. t['\uFC5C'] = '\u0631\u0670';
  18369. t['\uFC5D'] = '\u0649\u0670';
  18370. t['\uFC5E'] = '\u0020\u064C\u0651';
  18371. t['\uFC5F'] = '\u0020\u064D\u0651';
  18372. t['\uFC60'] = '\u0020\u064E\u0651';
  18373. t['\uFC61'] = '\u0020\u064F\u0651';
  18374. t['\uFC62'] = '\u0020\u0650\u0651';
  18375. t['\uFC63'] = '\u0020\u0651\u0670';
  18376. t['\uFC64'] = '\u0626\u0631';
  18377. t['\uFC65'] = '\u0626\u0632';
  18378. t['\uFC66'] = '\u0626\u0645';
  18379. t['\uFC67'] = '\u0626\u0646';
  18380. t['\uFC68'] = '\u0626\u0649';
  18381. t['\uFC69'] = '\u0626\u064A';
  18382. t['\uFC6A'] = '\u0628\u0631';
  18383. t['\uFC6B'] = '\u0628\u0632';
  18384. t['\uFC6C'] = '\u0628\u0645';
  18385. t['\uFC6D'] = '\u0628\u0646';
  18386. t['\uFC6E'] = '\u0628\u0649';
  18387. t['\uFC6F'] = '\u0628\u064A';
  18388. t['\uFC70'] = '\u062A\u0631';
  18389. t['\uFC71'] = '\u062A\u0632';
  18390. t['\uFC72'] = '\u062A\u0645';
  18391. t['\uFC73'] = '\u062A\u0646';
  18392. t['\uFC74'] = '\u062A\u0649';
  18393. t['\uFC75'] = '\u062A\u064A';
  18394. t['\uFC76'] = '\u062B\u0631';
  18395. t['\uFC77'] = '\u062B\u0632';
  18396. t['\uFC78'] = '\u062B\u0645';
  18397. t['\uFC79'] = '\u062B\u0646';
  18398. t['\uFC7A'] = '\u062B\u0649';
  18399. t['\uFC7B'] = '\u062B\u064A';
  18400. t['\uFC7C'] = '\u0641\u0649';
  18401. t['\uFC7D'] = '\u0641\u064A';
  18402. t['\uFC7E'] = '\u0642\u0649';
  18403. t['\uFC7F'] = '\u0642\u064A';
  18404. t['\uFC80'] = '\u0643\u0627';
  18405. t['\uFC81'] = '\u0643\u0644';
  18406. t['\uFC82'] = '\u0643\u0645';
  18407. t['\uFC83'] = '\u0643\u0649';
  18408. t['\uFC84'] = '\u0643\u064A';
  18409. t['\uFC85'] = '\u0644\u0645';
  18410. t['\uFC86'] = '\u0644\u0649';
  18411. t['\uFC87'] = '\u0644\u064A';
  18412. t['\uFC88'] = '\u0645\u0627';
  18413. t['\uFC89'] = '\u0645\u0645';
  18414. t['\uFC8A'] = '\u0646\u0631';
  18415. t['\uFC8B'] = '\u0646\u0632';
  18416. t['\uFC8C'] = '\u0646\u0645';
  18417. t['\uFC8D'] = '\u0646\u0646';
  18418. t['\uFC8E'] = '\u0646\u0649';
  18419. t['\uFC8F'] = '\u0646\u064A';
  18420. t['\uFC90'] = '\u0649\u0670';
  18421. t['\uFC91'] = '\u064A\u0631';
  18422. t['\uFC92'] = '\u064A\u0632';
  18423. t['\uFC93'] = '\u064A\u0645';
  18424. t['\uFC94'] = '\u064A\u0646';
  18425. t['\uFC95'] = '\u064A\u0649';
  18426. t['\uFC96'] = '\u064A\u064A';
  18427. t['\uFC97'] = '\u0626\u062C';
  18428. t['\uFC98'] = '\u0626\u062D';
  18429. t['\uFC99'] = '\u0626\u062E';
  18430. t['\uFC9A'] = '\u0626\u0645';
  18431. t['\uFC9B'] = '\u0626\u0647';
  18432. t['\uFC9C'] = '\u0628\u062C';
  18433. t['\uFC9D'] = '\u0628\u062D';
  18434. t['\uFC9E'] = '\u0628\u062E';
  18435. t['\uFC9F'] = '\u0628\u0645';
  18436. t['\uFCA0'] = '\u0628\u0647';
  18437. t['\uFCA1'] = '\u062A\u062C';
  18438. t['\uFCA2'] = '\u062A\u062D';
  18439. t['\uFCA3'] = '\u062A\u062E';
  18440. t['\uFCA4'] = '\u062A\u0645';
  18441. t['\uFCA5'] = '\u062A\u0647';
  18442. t['\uFCA6'] = '\u062B\u0645';
  18443. t['\uFCA7'] = '\u062C\u062D';
  18444. t['\uFCA8'] = '\u062C\u0645';
  18445. t['\uFCA9'] = '\u062D\u062C';
  18446. t['\uFCAA'] = '\u062D\u0645';
  18447. t['\uFCAB'] = '\u062E\u062C';
  18448. t['\uFCAC'] = '\u062E\u0645';
  18449. t['\uFCAD'] = '\u0633\u062C';
  18450. t['\uFCAE'] = '\u0633\u062D';
  18451. t['\uFCAF'] = '\u0633\u062E';
  18452. t['\uFCB0'] = '\u0633\u0645';
  18453. t['\uFCB1'] = '\u0635\u062D';
  18454. t['\uFCB2'] = '\u0635\u062E';
  18455. t['\uFCB3'] = '\u0635\u0645';
  18456. t['\uFCB4'] = '\u0636\u062C';
  18457. t['\uFCB5'] = '\u0636\u062D';
  18458. t['\uFCB6'] = '\u0636\u062E';
  18459. t['\uFCB7'] = '\u0636\u0645';
  18460. t['\uFCB8'] = '\u0637\u062D';
  18461. t['\uFCB9'] = '\u0638\u0645';
  18462. t['\uFCBA'] = '\u0639\u062C';
  18463. t['\uFCBB'] = '\u0639\u0645';
  18464. t['\uFCBC'] = '\u063A\u062C';
  18465. t['\uFCBD'] = '\u063A\u0645';
  18466. t['\uFCBE'] = '\u0641\u062C';
  18467. t['\uFCBF'] = '\u0641\u062D';
  18468. t['\uFCC0'] = '\u0641\u062E';
  18469. t['\uFCC1'] = '\u0641\u0645';
  18470. t['\uFCC2'] = '\u0642\u062D';
  18471. t['\uFCC3'] = '\u0642\u0645';
  18472. t['\uFCC4'] = '\u0643\u062C';
  18473. t['\uFCC5'] = '\u0643\u062D';
  18474. t['\uFCC6'] = '\u0643\u062E';
  18475. t['\uFCC7'] = '\u0643\u0644';
  18476. t['\uFCC8'] = '\u0643\u0645';
  18477. t['\uFCC9'] = '\u0644\u062C';
  18478. t['\uFCCA'] = '\u0644\u062D';
  18479. t['\uFCCB'] = '\u0644\u062E';
  18480. t['\uFCCC'] = '\u0644\u0645';
  18481. t['\uFCCD'] = '\u0644\u0647';
  18482. t['\uFCCE'] = '\u0645\u062C';
  18483. t['\uFCCF'] = '\u0645\u062D';
  18484. t['\uFCD0'] = '\u0645\u062E';
  18485. t['\uFCD1'] = '\u0645\u0645';
  18486. t['\uFCD2'] = '\u0646\u062C';
  18487. t['\uFCD3'] = '\u0646\u062D';
  18488. t['\uFCD4'] = '\u0646\u062E';
  18489. t['\uFCD5'] = '\u0646\u0645';
  18490. t['\uFCD6'] = '\u0646\u0647';
  18491. t['\uFCD7'] = '\u0647\u062C';
  18492. t['\uFCD8'] = '\u0647\u0645';
  18493. t['\uFCD9'] = '\u0647\u0670';
  18494. t['\uFCDA'] = '\u064A\u062C';
  18495. t['\uFCDB'] = '\u064A\u062D';
  18496. t['\uFCDC'] = '\u064A\u062E';
  18497. t['\uFCDD'] = '\u064A\u0645';
  18498. t['\uFCDE'] = '\u064A\u0647';
  18499. t['\uFCDF'] = '\u0626\u0645';
  18500. t['\uFCE0'] = '\u0626\u0647';
  18501. t['\uFCE1'] = '\u0628\u0645';
  18502. t['\uFCE2'] = '\u0628\u0647';
  18503. t['\uFCE3'] = '\u062A\u0645';
  18504. t['\uFCE4'] = '\u062A\u0647';
  18505. t['\uFCE5'] = '\u062B\u0645';
  18506. t['\uFCE6'] = '\u062B\u0647';
  18507. t['\uFCE7'] = '\u0633\u0645';
  18508. t['\uFCE8'] = '\u0633\u0647';
  18509. t['\uFCE9'] = '\u0634\u0645';
  18510. t['\uFCEA'] = '\u0634\u0647';
  18511. t['\uFCEB'] = '\u0643\u0644';
  18512. t['\uFCEC'] = '\u0643\u0645';
  18513. t['\uFCED'] = '\u0644\u0645';
  18514. t['\uFCEE'] = '\u0646\u0645';
  18515. t['\uFCEF'] = '\u0646\u0647';
  18516. t['\uFCF0'] = '\u064A\u0645';
  18517. t['\uFCF1'] = '\u064A\u0647';
  18518. t['\uFCF2'] = '\u0640\u064E\u0651';
  18519. t['\uFCF3'] = '\u0640\u064F\u0651';
  18520. t['\uFCF4'] = '\u0640\u0650\u0651';
  18521. t['\uFCF5'] = '\u0637\u0649';
  18522. t['\uFCF6'] = '\u0637\u064A';
  18523. t['\uFCF7'] = '\u0639\u0649';
  18524. t['\uFCF8'] = '\u0639\u064A';
  18525. t['\uFCF9'] = '\u063A\u0649';
  18526. t['\uFCFA'] = '\u063A\u064A';
  18527. t['\uFCFB'] = '\u0633\u0649';
  18528. t['\uFCFC'] = '\u0633\u064A';
  18529. t['\uFCFD'] = '\u0634\u0649';
  18530. t['\uFCFE'] = '\u0634\u064A';
  18531. t['\uFCFF'] = '\u062D\u0649';
  18532. t['\uFD00'] = '\u062D\u064A';
  18533. t['\uFD01'] = '\u062C\u0649';
  18534. t['\uFD02'] = '\u062C\u064A';
  18535. t['\uFD03'] = '\u062E\u0649';
  18536. t['\uFD04'] = '\u062E\u064A';
  18537. t['\uFD05'] = '\u0635\u0649';
  18538. t['\uFD06'] = '\u0635\u064A';
  18539. t['\uFD07'] = '\u0636\u0649';
  18540. t['\uFD08'] = '\u0636\u064A';
  18541. t['\uFD09'] = '\u0634\u062C';
  18542. t['\uFD0A'] = '\u0634\u062D';
  18543. t['\uFD0B'] = '\u0634\u062E';
  18544. t['\uFD0C'] = '\u0634\u0645';
  18545. t['\uFD0D'] = '\u0634\u0631';
  18546. t['\uFD0E'] = '\u0633\u0631';
  18547. t['\uFD0F'] = '\u0635\u0631';
  18548. t['\uFD10'] = '\u0636\u0631';
  18549. t['\uFD11'] = '\u0637\u0649';
  18550. t['\uFD12'] = '\u0637\u064A';
  18551. t['\uFD13'] = '\u0639\u0649';
  18552. t['\uFD14'] = '\u0639\u064A';
  18553. t['\uFD15'] = '\u063A\u0649';
  18554. t['\uFD16'] = '\u063A\u064A';
  18555. t['\uFD17'] = '\u0633\u0649';
  18556. t['\uFD18'] = '\u0633\u064A';
  18557. t['\uFD19'] = '\u0634\u0649';
  18558. t['\uFD1A'] = '\u0634\u064A';
  18559. t['\uFD1B'] = '\u062D\u0649';
  18560. t['\uFD1C'] = '\u062D\u064A';
  18561. t['\uFD1D'] = '\u062C\u0649';
  18562. t['\uFD1E'] = '\u062C\u064A';
  18563. t['\uFD1F'] = '\u062E\u0649';
  18564. t['\uFD20'] = '\u062E\u064A';
  18565. t['\uFD21'] = '\u0635\u0649';
  18566. t['\uFD22'] = '\u0635\u064A';
  18567. t['\uFD23'] = '\u0636\u0649';
  18568. t['\uFD24'] = '\u0636\u064A';
  18569. t['\uFD25'] = '\u0634\u062C';
  18570. t['\uFD26'] = '\u0634\u062D';
  18571. t['\uFD27'] = '\u0634\u062E';
  18572. t['\uFD28'] = '\u0634\u0645';
  18573. t['\uFD29'] = '\u0634\u0631';
  18574. t['\uFD2A'] = '\u0633\u0631';
  18575. t['\uFD2B'] = '\u0635\u0631';
  18576. t['\uFD2C'] = '\u0636\u0631';
  18577. t['\uFD2D'] = '\u0634\u062C';
  18578. t['\uFD2E'] = '\u0634\u062D';
  18579. t['\uFD2F'] = '\u0634\u062E';
  18580. t['\uFD30'] = '\u0634\u0645';
  18581. t['\uFD31'] = '\u0633\u0647';
  18582. t['\uFD32'] = '\u0634\u0647';
  18583. t['\uFD33'] = '\u0637\u0645';
  18584. t['\uFD34'] = '\u0633\u062C';
  18585. t['\uFD35'] = '\u0633\u062D';
  18586. t['\uFD36'] = '\u0633\u062E';
  18587. t['\uFD37'] = '\u0634\u062C';
  18588. t['\uFD38'] = '\u0634\u062D';
  18589. t['\uFD39'] = '\u0634\u062E';
  18590. t['\uFD3A'] = '\u0637\u0645';
  18591. t['\uFD3B'] = '\u0638\u0645';
  18592. t['\uFD3C'] = '\u0627\u064B';
  18593. t['\uFD3D'] = '\u0627\u064B';
  18594. t['\uFD50'] = '\u062A\u062C\u0645';
  18595. t['\uFD51'] = '\u062A\u062D\u062C';
  18596. t['\uFD52'] = '\u062A\u062D\u062C';
  18597. t['\uFD53'] = '\u062A\u062D\u0645';
  18598. t['\uFD54'] = '\u062A\u062E\u0645';
  18599. t['\uFD55'] = '\u062A\u0645\u062C';
  18600. t['\uFD56'] = '\u062A\u0645\u062D';
  18601. t['\uFD57'] = '\u062A\u0645\u062E';
  18602. t['\uFD58'] = '\u062C\u0645\u062D';
  18603. t['\uFD59'] = '\u062C\u0645\u062D';
  18604. t['\uFD5A'] = '\u062D\u0645\u064A';
  18605. t['\uFD5B'] = '\u062D\u0645\u0649';
  18606. t['\uFD5C'] = '\u0633\u062D\u062C';
  18607. t['\uFD5D'] = '\u0633\u062C\u062D';
  18608. t['\uFD5E'] = '\u0633\u062C\u0649';
  18609. t['\uFD5F'] = '\u0633\u0645\u062D';
  18610. t['\uFD60'] = '\u0633\u0645\u062D';
  18611. t['\uFD61'] = '\u0633\u0645\u062C';
  18612. t['\uFD62'] = '\u0633\u0645\u0645';
  18613. t['\uFD63'] = '\u0633\u0645\u0645';
  18614. t['\uFD64'] = '\u0635\u062D\u062D';
  18615. t['\uFD65'] = '\u0635\u062D\u062D';
  18616. t['\uFD66'] = '\u0635\u0645\u0645';
  18617. t['\uFD67'] = '\u0634\u062D\u0645';
  18618. t['\uFD68'] = '\u0634\u062D\u0645';
  18619. t['\uFD69'] = '\u0634\u062C\u064A';
  18620. t['\uFD6A'] = '\u0634\u0645\u062E';
  18621. t['\uFD6B'] = '\u0634\u0645\u062E';
  18622. t['\uFD6C'] = '\u0634\u0645\u0645';
  18623. t['\uFD6D'] = '\u0634\u0645\u0645';
  18624. t['\uFD6E'] = '\u0636\u062D\u0649';
  18625. t['\uFD6F'] = '\u0636\u062E\u0645';
  18626. t['\uFD70'] = '\u0636\u062E\u0645';
  18627. t['\uFD71'] = '\u0637\u0645\u062D';
  18628. t['\uFD72'] = '\u0637\u0645\u062D';
  18629. t['\uFD73'] = '\u0637\u0645\u0645';
  18630. t['\uFD74'] = '\u0637\u0645\u064A';
  18631. t['\uFD75'] = '\u0639\u062C\u0645';
  18632. t['\uFD76'] = '\u0639\u0645\u0645';
  18633. t['\uFD77'] = '\u0639\u0645\u0645';
  18634. t['\uFD78'] = '\u0639\u0645\u0649';
  18635. t['\uFD79'] = '\u063A\u0645\u0645';
  18636. t['\uFD7A'] = '\u063A\u0645\u064A';
  18637. t['\uFD7B'] = '\u063A\u0645\u0649';
  18638. t['\uFD7C'] = '\u0641\u062E\u0645';
  18639. t['\uFD7D'] = '\u0641\u062E\u0645';
  18640. t['\uFD7E'] = '\u0642\u0645\u062D';
  18641. t['\uFD7F'] = '\u0642\u0645\u0645';
  18642. t['\uFD80'] = '\u0644\u062D\u0645';
  18643. t['\uFD81'] = '\u0644\u062D\u064A';
  18644. t['\uFD82'] = '\u0644\u062D\u0649';
  18645. t['\uFD83'] = '\u0644\u062C\u062C';
  18646. t['\uFD84'] = '\u0644\u062C\u062C';
  18647. t['\uFD85'] = '\u0644\u062E\u0645';
  18648. t['\uFD86'] = '\u0644\u062E\u0645';
  18649. t['\uFD87'] = '\u0644\u0645\u062D';
  18650. t['\uFD88'] = '\u0644\u0645\u062D';
  18651. t['\uFD89'] = '\u0645\u062D\u062C';
  18652. t['\uFD8A'] = '\u0645\u062D\u0645';
  18653. t['\uFD8B'] = '\u0645\u062D\u064A';
  18654. t['\uFD8C'] = '\u0645\u062C\u062D';
  18655. t['\uFD8D'] = '\u0645\u062C\u0645';
  18656. t['\uFD8E'] = '\u0645\u062E\u062C';
  18657. t['\uFD8F'] = '\u0645\u062E\u0645';
  18658. t['\uFD92'] = '\u0645\u062C\u062E';
  18659. t['\uFD93'] = '\u0647\u0645\u062C';
  18660. t['\uFD94'] = '\u0647\u0645\u0645';
  18661. t['\uFD95'] = '\u0646\u062D\u0645';
  18662. t['\uFD96'] = '\u0646\u062D\u0649';
  18663. t['\uFD97'] = '\u0646\u062C\u0645';
  18664. t['\uFD98'] = '\u0646\u062C\u0645';
  18665. t['\uFD99'] = '\u0646\u062C\u0649';
  18666. t['\uFD9A'] = '\u0646\u0645\u064A';
  18667. t['\uFD9B'] = '\u0646\u0645\u0649';
  18668. t['\uFD9C'] = '\u064A\u0645\u0645';
  18669. t['\uFD9D'] = '\u064A\u0645\u0645';
  18670. t['\uFD9E'] = '\u0628\u062E\u064A';
  18671. t['\uFD9F'] = '\u062A\u062C\u064A';
  18672. t['\uFDA0'] = '\u062A\u062C\u0649';
  18673. t['\uFDA1'] = '\u062A\u062E\u064A';
  18674. t['\uFDA2'] = '\u062A\u062E\u0649';
  18675. t['\uFDA3'] = '\u062A\u0645\u064A';
  18676. t['\uFDA4'] = '\u062A\u0645\u0649';
  18677. t['\uFDA5'] = '\u062C\u0645\u064A';
  18678. t['\uFDA6'] = '\u062C\u062D\u0649';
  18679. t['\uFDA7'] = '\u062C\u0645\u0649';
  18680. t['\uFDA8'] = '\u0633\u062E\u0649';
  18681. t['\uFDA9'] = '\u0635\u062D\u064A';
  18682. t['\uFDAA'] = '\u0634\u062D\u064A';
  18683. t['\uFDAB'] = '\u0636\u062D\u064A';
  18684. t['\uFDAC'] = '\u0644\u062C\u064A';
  18685. t['\uFDAD'] = '\u0644\u0645\u064A';
  18686. t['\uFDAE'] = '\u064A\u062D\u064A';
  18687. t['\uFDAF'] = '\u064A\u062C\u064A';
  18688. t['\uFDB0'] = '\u064A\u0645\u064A';
  18689. t['\uFDB1'] = '\u0645\u0645\u064A';
  18690. t['\uFDB2'] = '\u0642\u0645\u064A';
  18691. t['\uFDB3'] = '\u0646\u062D\u064A';
  18692. t['\uFDB4'] = '\u0642\u0645\u062D';
  18693. t['\uFDB5'] = '\u0644\u062D\u0645';
  18694. t['\uFDB6'] = '\u0639\u0645\u064A';
  18695. t['\uFDB7'] = '\u0643\u0645\u064A';
  18696. t['\uFDB8'] = '\u0646\u062C\u062D';
  18697. t['\uFDB9'] = '\u0645\u062E\u064A';
  18698. t['\uFDBA'] = '\u0644\u062C\u0645';
  18699. t['\uFDBB'] = '\u0643\u0645\u0645';
  18700. t['\uFDBC'] = '\u0644\u062C\u0645';
  18701. t['\uFDBD'] = '\u0646\u062C\u062D';
  18702. t['\uFDBE'] = '\u062C\u062D\u064A';
  18703. t['\uFDBF'] = '\u062D\u062C\u064A';
  18704. t['\uFDC0'] = '\u0645\u062C\u064A';
  18705. t['\uFDC1'] = '\u0641\u0645\u064A';
  18706. t['\uFDC2'] = '\u0628\u062D\u064A';
  18707. t['\uFDC3'] = '\u0643\u0645\u0645';
  18708. t['\uFDC4'] = '\u0639\u062C\u0645';
  18709. t['\uFDC5'] = '\u0635\u0645\u0645';
  18710. t['\uFDC6'] = '\u0633\u062E\u064A';
  18711. t['\uFDC7'] = '\u0646\u062C\u064A';
  18712. t['\uFE49'] = '\u203E';
  18713. t['\uFE4A'] = '\u203E';
  18714. t['\uFE4B'] = '\u203E';
  18715. t['\uFE4C'] = '\u203E';
  18716. t['\uFE4D'] = '\u005F';
  18717. t['\uFE4E'] = '\u005F';
  18718. t['\uFE4F'] = '\u005F';
  18719. t['\uFE80'] = '\u0621';
  18720. t['\uFE81'] = '\u0622';
  18721. t['\uFE82'] = '\u0622';
  18722. t['\uFE83'] = '\u0623';
  18723. t['\uFE84'] = '\u0623';
  18724. t['\uFE85'] = '\u0624';
  18725. t['\uFE86'] = '\u0624';
  18726. t['\uFE87'] = '\u0625';
  18727. t['\uFE88'] = '\u0625';
  18728. t['\uFE89'] = '\u0626';
  18729. t['\uFE8A'] = '\u0626';
  18730. t['\uFE8B'] = '\u0626';
  18731. t['\uFE8C'] = '\u0626';
  18732. t['\uFE8D'] = '\u0627';
  18733. t['\uFE8E'] = '\u0627';
  18734. t['\uFE8F'] = '\u0628';
  18735. t['\uFE90'] = '\u0628';
  18736. t['\uFE91'] = '\u0628';
  18737. t['\uFE92'] = '\u0628';
  18738. t['\uFE93'] = '\u0629';
  18739. t['\uFE94'] = '\u0629';
  18740. t['\uFE95'] = '\u062A';
  18741. t['\uFE96'] = '\u062A';
  18742. t['\uFE97'] = '\u062A';
  18743. t['\uFE98'] = '\u062A';
  18744. t['\uFE99'] = '\u062B';
  18745. t['\uFE9A'] = '\u062B';
  18746. t['\uFE9B'] = '\u062B';
  18747. t['\uFE9C'] = '\u062B';
  18748. t['\uFE9D'] = '\u062C';
  18749. t['\uFE9E'] = '\u062C';
  18750. t['\uFE9F'] = '\u062C';
  18751. t['\uFEA0'] = '\u062C';
  18752. t['\uFEA1'] = '\u062D';
  18753. t['\uFEA2'] = '\u062D';
  18754. t['\uFEA3'] = '\u062D';
  18755. t['\uFEA4'] = '\u062D';
  18756. t['\uFEA5'] = '\u062E';
  18757. t['\uFEA6'] = '\u062E';
  18758. t['\uFEA7'] = '\u062E';
  18759. t['\uFEA8'] = '\u062E';
  18760. t['\uFEA9'] = '\u062F';
  18761. t['\uFEAA'] = '\u062F';
  18762. t['\uFEAB'] = '\u0630';
  18763. t['\uFEAC'] = '\u0630';
  18764. t['\uFEAD'] = '\u0631';
  18765. t['\uFEAE'] = '\u0631';
  18766. t['\uFEAF'] = '\u0632';
  18767. t['\uFEB0'] = '\u0632';
  18768. t['\uFEB1'] = '\u0633';
  18769. t['\uFEB2'] = '\u0633';
  18770. t['\uFEB3'] = '\u0633';
  18771. t['\uFEB4'] = '\u0633';
  18772. t['\uFEB5'] = '\u0634';
  18773. t['\uFEB6'] = '\u0634';
  18774. t['\uFEB7'] = '\u0634';
  18775. t['\uFEB8'] = '\u0634';
  18776. t['\uFEB9'] = '\u0635';
  18777. t['\uFEBA'] = '\u0635';
  18778. t['\uFEBB'] = '\u0635';
  18779. t['\uFEBC'] = '\u0635';
  18780. t['\uFEBD'] = '\u0636';
  18781. t['\uFEBE'] = '\u0636';
  18782. t['\uFEBF'] = '\u0636';
  18783. t['\uFEC0'] = '\u0636';
  18784. t['\uFEC1'] = '\u0637';
  18785. t['\uFEC2'] = '\u0637';
  18786. t['\uFEC3'] = '\u0637';
  18787. t['\uFEC4'] = '\u0637';
  18788. t['\uFEC5'] = '\u0638';
  18789. t['\uFEC6'] = '\u0638';
  18790. t['\uFEC7'] = '\u0638';
  18791. t['\uFEC8'] = '\u0638';
  18792. t['\uFEC9'] = '\u0639';
  18793. t['\uFECA'] = '\u0639';
  18794. t['\uFECB'] = '\u0639';
  18795. t['\uFECC'] = '\u0639';
  18796. t['\uFECD'] = '\u063A';
  18797. t['\uFECE'] = '\u063A';
  18798. t['\uFECF'] = '\u063A';
  18799. t['\uFED0'] = '\u063A';
  18800. t['\uFED1'] = '\u0641';
  18801. t['\uFED2'] = '\u0641';
  18802. t['\uFED3'] = '\u0641';
  18803. t['\uFED4'] = '\u0641';
  18804. t['\uFED5'] = '\u0642';
  18805. t['\uFED6'] = '\u0642';
  18806. t['\uFED7'] = '\u0642';
  18807. t['\uFED8'] = '\u0642';
  18808. t['\uFED9'] = '\u0643';
  18809. t['\uFEDA'] = '\u0643';
  18810. t['\uFEDB'] = '\u0643';
  18811. t['\uFEDC'] = '\u0643';
  18812. t['\uFEDD'] = '\u0644';
  18813. t['\uFEDE'] = '\u0644';
  18814. t['\uFEDF'] = '\u0644';
  18815. t['\uFEE0'] = '\u0644';
  18816. t['\uFEE1'] = '\u0645';
  18817. t['\uFEE2'] = '\u0645';
  18818. t['\uFEE3'] = '\u0645';
  18819. t['\uFEE4'] = '\u0645';
  18820. t['\uFEE5'] = '\u0646';
  18821. t['\uFEE6'] = '\u0646';
  18822. t['\uFEE7'] = '\u0646';
  18823. t['\uFEE8'] = '\u0646';
  18824. t['\uFEE9'] = '\u0647';
  18825. t['\uFEEA'] = '\u0647';
  18826. t['\uFEEB'] = '\u0647';
  18827. t['\uFEEC'] = '\u0647';
  18828. t['\uFEED'] = '\u0648';
  18829. t['\uFEEE'] = '\u0648';
  18830. t['\uFEEF'] = '\u0649';
  18831. t['\uFEF0'] = '\u0649';
  18832. t['\uFEF1'] = '\u064A';
  18833. t['\uFEF2'] = '\u064A';
  18834. t['\uFEF3'] = '\u064A';
  18835. t['\uFEF4'] = '\u064A';
  18836. t['\uFEF5'] = '\u0644\u0622';
  18837. t['\uFEF6'] = '\u0644\u0622';
  18838. t['\uFEF7'] = '\u0644\u0623';
  18839. t['\uFEF8'] = '\u0644\u0623';
  18840. t['\uFEF9'] = '\u0644\u0625';
  18841. t['\uFEFA'] = '\u0644\u0625';
  18842. t['\uFEFB'] = '\u0644\u0627';
  18843. t['\uFEFC'] = '\u0644\u0627';
  18844. });
  18845. function reverseIfRtl(chars) {
  18846. var charsLength = chars.length;
  18847. //reverse an arabic ligature
  18848. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18849. return chars;
  18850. }
  18851. var s = '';
  18852. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18853. s += chars[ii];
  18854. }
  18855. return s;
  18856. }
  18857. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18858. exports.reverseIfRtl = reverseIfRtl;
  18859. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18860. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18861. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18862. }));
  18863. (function (root, factory) {
  18864. {
  18865. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedUtil);
  18866. }
  18867. }(this, function (exports, sharedUtil) {
  18868. var removeNullCharacters = sharedUtil.removeNullCharacters;
  18869. var warn = sharedUtil.warn;
  18870. /**
  18871. * Optimised CSS custom property getter/setter.
  18872. * @class
  18873. */
  18874. var CustomStyle = (function CustomStyleClosure() {
  18875. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  18876. // animate-css-transforms-firefox-webkit.html
  18877. // in some versions of IE9 it is critical that ms appear in this list
  18878. // before Moz
  18879. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  18880. var _cache = Object.create(null);
  18881. function CustomStyle() {}
  18882. CustomStyle.getProp = function get(propName, element) {
  18883. // check cache only when no element is given
  18884. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  18885. return _cache[propName];
  18886. }
  18887. element = element || document.documentElement;
  18888. var style = element.style, prefixed, uPropName;
  18889. // test standard property first
  18890. if (typeof style[propName] === 'string') {
  18891. return (_cache[propName] = propName);
  18892. }
  18893. // capitalize
  18894. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  18895. // test vendor specific properties
  18896. for (var i = 0, l = prefixes.length; i < l; i++) {
  18897. prefixed = prefixes[i] + uPropName;
  18898. if (typeof style[prefixed] === 'string') {
  18899. return (_cache[propName] = prefixed);
  18900. }
  18901. }
  18902. //if all fails then set to undefined
  18903. return (_cache[propName] = 'undefined');
  18904. };
  18905. CustomStyle.setProp = function set(propName, element, str) {
  18906. var prop = this.getProp(propName);
  18907. if (prop !== 'undefined') {
  18908. element.style[prop] = str;
  18909. }
  18910. };
  18911. return CustomStyle;
  18912. })();
  18913. function hasCanvasTypedArrays() {
  18914. var canvas = document.createElement('canvas');
  18915. canvas.width = canvas.height = 1;
  18916. var ctx = canvas.getContext('2d');
  18917. var imageData = ctx.createImageData(1, 1);
  18918. return (typeof imageData.data.buffer !== 'undefined');
  18919. }
  18920. var LinkTarget = {
  18921. NONE: 0, // Default value.
  18922. SELF: 1,
  18923. BLANK: 2,
  18924. PARENT: 3,
  18925. TOP: 4,
  18926. };
  18927. var LinkTargetStringMap = [
  18928. '',
  18929. '_self',
  18930. '_blank',
  18931. '_parent',
  18932. '_top'
  18933. ];
  18934. /**
  18935. * @typedef ExternalLinkParameters
  18936. * @typedef {Object} ExternalLinkParameters
  18937. * @property {string} url - An absolute URL.
  18938. * @property {LinkTarget} target - The link target.
  18939. * @property {string} rel - The link relationship.
  18940. */
  18941. /**
  18942. * Adds various attributes (href, title, target, rel) to hyperlinks.
  18943. * @param {HTMLLinkElement} link - The link element.
  18944. * @param {ExternalLinkParameters} params
  18945. */
  18946. function addLinkAttributes(link, params) {
  18947. var url = params && params.url;
  18948. link.href = link.title = (url ? removeNullCharacters(url) : '');
  18949. if (url) {
  18950. var target = params.target;
  18951. if (typeof target === 'undefined') {
  18952. target = getDefaultSetting('externalLinkTarget');
  18953. }
  18954. link.target = LinkTargetStringMap[target];
  18955. var rel = params.rel;
  18956. if (typeof rel === 'undefined') {
  18957. rel = getDefaultSetting('externalLinkRel');
  18958. }
  18959. link.rel = rel;
  18960. }
  18961. }
  18962. // Gets the file name from a given URL.
  18963. function getFilenameFromUrl(url) {
  18964. var anchor = url.indexOf('#');
  18965. var query = url.indexOf('?');
  18966. var end = Math.min(
  18967. anchor > 0 ? anchor : url.length,
  18968. query > 0 ? query : url.length);
  18969. return url.substring(url.lastIndexOf('/', end) + 1, end);
  18970. }
  18971. function getDefaultSetting(id) {
  18972. // The list of the settings and their default is maintained for backward
  18973. // compatibility and shall not be extended or modified. See also global.js.
  18974. var globalSettings = sharedUtil.globalScope.PDFJS;
  18975. switch (id) {
  18976. case 'pdfBug':
  18977. return globalSettings ? globalSettings.pdfBug : false;
  18978. case 'disableAutoFetch':
  18979. return globalSettings ? globalSettings.disableAutoFetch : false;
  18980. case 'disableStream':
  18981. return globalSettings ? globalSettings.disableStream : false;
  18982. case 'disableRange':
  18983. return globalSettings ? globalSettings.disableRange : false;
  18984. case 'disableFontFace':
  18985. return globalSettings ? globalSettings.disableFontFace : false;
  18986. case 'disableCreateObjectURL':
  18987. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  18988. case 'disableWebGL':
  18989. return globalSettings ? globalSettings.disableWebGL : true;
  18990. case 'cMapUrl':
  18991. return globalSettings ? globalSettings.cMapUrl : null;
  18992. case 'cMapPacked':
  18993. return globalSettings ? globalSettings.cMapPacked : false;
  18994. case 'postMessageTransfers':
  18995. return globalSettings ? globalSettings.postMessageTransfers : true;
  18996. case 'workerSrc':
  18997. return globalSettings ? globalSettings.workerSrc : null;
  18998. case 'disableWorker':
  18999. return globalSettings ? globalSettings.disableWorker : false;
  19000. case 'maxImageSize':
  19001. return globalSettings ? globalSettings.maxImageSize : -1;
  19002. case 'imageResourcesPath':
  19003. return globalSettings ? globalSettings.imageResourcesPath : '';
  19004. case 'isEvalSupported':
  19005. return globalSettings ? globalSettings.isEvalSupported : true;
  19006. case 'externalLinkTarget':
  19007. if (!globalSettings) {
  19008. return LinkTarget.NONE;
  19009. }
  19010. switch (globalSettings.externalLinkTarget) {
  19011. case LinkTarget.NONE:
  19012. case LinkTarget.SELF:
  19013. case LinkTarget.BLANK:
  19014. case LinkTarget.PARENT:
  19015. case LinkTarget.TOP:
  19016. return globalSettings.externalLinkTarget;
  19017. }
  19018. warn('PDFJS.externalLinkTarget is invalid: ' +
  19019. globalSettings.externalLinkTarget);
  19020. // Reset the external link target, to suppress further warnings.
  19021. globalSettings.externalLinkTarget = LinkTarget.NONE;
  19022. return LinkTarget.NONE;
  19023. case 'externalLinkRel':
  19024. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  19025. case 'enableStats':
  19026. return !!(globalSettings && globalSettings.enableStats);
  19027. default:
  19028. throw new Error('Unknown default setting: ' + id);
  19029. }
  19030. }
  19031. function isExternalLinkTargetSet() {
  19032. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  19033. switch (externalLinkTarget) {
  19034. case LinkTarget.NONE:
  19035. return false;
  19036. case LinkTarget.SELF:
  19037. case LinkTarget.BLANK:
  19038. case LinkTarget.PARENT:
  19039. case LinkTarget.TOP:
  19040. return true;
  19041. }
  19042. }
  19043. exports.CustomStyle = CustomStyle;
  19044. exports.addLinkAttributes = addLinkAttributes;
  19045. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  19046. exports.getFilenameFromUrl = getFilenameFromUrl;
  19047. exports.LinkTarget = LinkTarget;
  19048. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  19049. exports.getDefaultSetting = getDefaultSetting;
  19050. }));
  19051. (function (root, factory) {
  19052. {
  19053. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil);
  19054. }
  19055. }(this, function (exports, sharedUtil) {
  19056. var assert = sharedUtil.assert;
  19057. var bytesToString = sharedUtil.bytesToString;
  19058. var string32 = sharedUtil.string32;
  19059. var shadow = sharedUtil.shadow;
  19060. var warn = sharedUtil.warn;
  19061. function FontLoader(docId) {
  19062. this.docId = docId;
  19063. this.styleElement = null;
  19064. this.nativeFontFaces = [];
  19065. this.loadTestFontId = 0;
  19066. this.loadingContext = {
  19067. requests: [],
  19068. nextRequestId: 0
  19069. };
  19070. }
  19071. FontLoader.prototype = {
  19072. insertRule: function fontLoaderInsertRule(rule) {
  19073. var styleElement = this.styleElement;
  19074. if (!styleElement) {
  19075. styleElement = this.styleElement = document.createElement('style');
  19076. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  19077. document.documentElement.getElementsByTagName('head')[0].appendChild(
  19078. styleElement);
  19079. }
  19080. var styleSheet = styleElement.sheet;
  19081. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  19082. },
  19083. clear: function fontLoaderClear() {
  19084. var styleElement = this.styleElement;
  19085. if (styleElement) {
  19086. styleElement.parentNode.removeChild(styleElement);
  19087. styleElement = this.styleElement = null;
  19088. }
  19089. this.nativeFontFaces.forEach(function(nativeFontFace) {
  19090. document.fonts.delete(nativeFontFace);
  19091. });
  19092. this.nativeFontFaces.length = 0;
  19093. },
  19094. get loadTestFont() {
  19095. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  19096. // height.
  19097. return shadow(this, 'loadTestFont', atob(
  19098. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  19099. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  19100. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  19101. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  19102. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  19103. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  19104. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  19105. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  19106. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  19107. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  19108. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  19109. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  19110. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  19111. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19112. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19113. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19114. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  19115. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  19116. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  19117. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  19118. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  19119. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  19120. ));
  19121. },
  19122. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  19123. this.nativeFontFaces.push(nativeFontFace);
  19124. document.fonts.add(nativeFontFace);
  19125. },
  19126. bind: function fontLoaderBind(fonts, callback) {
  19127. var rules = [];
  19128. var fontsToLoad = [];
  19129. var fontLoadPromises = [];
  19130. var getNativeFontPromise = function(nativeFontFace) {
  19131. // Return a promise that is always fulfilled, even when the font fails to
  19132. // load.
  19133. return nativeFontFace.loaded.catch(function(e) {
  19134. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  19135. });
  19136. };
  19137. for (var i = 0, ii = fonts.length; i < ii; i++) {
  19138. var font = fonts[i];
  19139. // Add the font to the DOM only once or skip if the font
  19140. // is already loaded.
  19141. if (font.attached || font.loading === false) {
  19142. continue;
  19143. }
  19144. font.attached = true;
  19145. if (FontLoader.isFontLoadingAPISupported) {
  19146. var nativeFontFace = font.createNativeFontFace();
  19147. if (nativeFontFace) {
  19148. this.addNativeFontFace(nativeFontFace);
  19149. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  19150. }
  19151. } else {
  19152. var rule = font.createFontFaceRule();
  19153. if (rule) {
  19154. this.insertRule(rule);
  19155. rules.push(rule);
  19156. fontsToLoad.push(font);
  19157. }
  19158. }
  19159. }
  19160. var request = this.queueLoadingCallback(callback);
  19161. if (FontLoader.isFontLoadingAPISupported) {
  19162. Promise.all(fontLoadPromises).then(function() {
  19163. request.complete();
  19164. });
  19165. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  19166. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  19167. } else {
  19168. request.complete();
  19169. }
  19170. },
  19171. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  19172. function LoadLoader_completeRequest() {
  19173. assert(!request.end, 'completeRequest() cannot be called twice');
  19174. request.end = Date.now();
  19175. // sending all completed requests in order how they were queued
  19176. while (context.requests.length > 0 && context.requests[0].end) {
  19177. var otherRequest = context.requests.shift();
  19178. setTimeout(otherRequest.callback, 0);
  19179. }
  19180. }
  19181. var context = this.loadingContext;
  19182. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  19183. var request = {
  19184. id: requestId,
  19185. complete: LoadLoader_completeRequest,
  19186. callback: callback,
  19187. started: Date.now()
  19188. };
  19189. context.requests.push(request);
  19190. return request;
  19191. },
  19192. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  19193. fonts,
  19194. request) {
  19195. /** Hack begin */
  19196. // There's currently no event when a font has finished downloading so the
  19197. // following code is a dirty hack to 'guess' when a font is
  19198. // ready. It's assumed fonts are loaded in order, so add a known test
  19199. // font after the desired fonts and then test for the loading of that
  19200. // test font.
  19201. function int32(data, offset) {
  19202. return (data.charCodeAt(offset) << 24) |
  19203. (data.charCodeAt(offset + 1) << 16) |
  19204. (data.charCodeAt(offset + 2) << 8) |
  19205. (data.charCodeAt(offset + 3) & 0xff);
  19206. }
  19207. function spliceString(s, offset, remove, insert) {
  19208. var chunk1 = s.substr(0, offset);
  19209. var chunk2 = s.substr(offset + remove);
  19210. return chunk1 + insert + chunk2;
  19211. }
  19212. var i, ii;
  19213. var canvas = document.createElement('canvas');
  19214. canvas.width = 1;
  19215. canvas.height = 1;
  19216. var ctx = canvas.getContext('2d');
  19217. var called = 0;
  19218. function isFontReady(name, callback) {
  19219. called++;
  19220. // With setTimeout clamping this gives the font ~100ms to load.
  19221. if(called > 30) {
  19222. warn('Load test font never loaded.');
  19223. callback();
  19224. return;
  19225. }
  19226. ctx.font = '30px ' + name;
  19227. ctx.fillText('.', 0, 20);
  19228. var imageData = ctx.getImageData(0, 0, 1, 1);
  19229. if (imageData.data[3] > 0) {
  19230. callback();
  19231. return;
  19232. }
  19233. setTimeout(isFontReady.bind(null, name, callback));
  19234. }
  19235. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  19236. // Chromium seems to cache fonts based on a hash of the actual font data,
  19237. // so the font must be modified for each load test else it will appear to
  19238. // be loaded already.
  19239. // TODO: This could maybe be made faster by avoiding the btoa of the full
  19240. // font by splitting it in chunks before hand and padding the font id.
  19241. var data = this.loadTestFont;
  19242. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  19243. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  19244. loadTestFontId);
  19245. // CFF checksum is important for IE, adjusting it
  19246. var CFF_CHECKSUM_OFFSET = 16;
  19247. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  19248. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  19249. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  19250. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  19251. }
  19252. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  19253. checksum = (checksum - XXXX_VALUE +
  19254. int32(loadTestFontId + 'XXX', i)) | 0;
  19255. }
  19256. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  19257. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  19258. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  19259. url + '}';
  19260. this.insertRule(rule);
  19261. var names = [];
  19262. for (i = 0, ii = fonts.length; i < ii; i++) {
  19263. names.push(fonts[i].loadedName);
  19264. }
  19265. names.push(loadTestFontId);
  19266. var div = document.createElement('div');
  19267. div.setAttribute('style',
  19268. 'visibility: hidden;' +
  19269. 'width: 10px; height: 10px;' +
  19270. 'position: absolute; top: 0px; left: 0px;');
  19271. for (i = 0, ii = names.length; i < ii; ++i) {
  19272. var span = document.createElement('span');
  19273. span.textContent = 'Hi';
  19274. span.style.fontFamily = names[i];
  19275. div.appendChild(span);
  19276. }
  19277. document.body.appendChild(div);
  19278. isFontReady(loadTestFontId, function() {
  19279. document.body.removeChild(div);
  19280. request.complete();
  19281. });
  19282. /** Hack end */
  19283. }
  19284. };
  19285. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
  19286. !!document.fonts;
  19287. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  19288. get: function () {
  19289. if (typeof navigator === 'undefined') {
  19290. // node.js - we can pretend sync font loading is supported.
  19291. return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
  19292. }
  19293. var supported = false;
  19294. // User agent string sniffing is bad, but there is no reliable way to tell
  19295. // if font is fully loaded and ready to be used with canvas.
  19296. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  19297. if (m && m[1] >= 14) {
  19298. supported = true;
  19299. }
  19300. // TODO other browsers
  19301. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  19302. },
  19303. enumerable: true,
  19304. configurable: true
  19305. });
  19306. var IsEvalSupportedCached = {
  19307. get value() {
  19308. return shadow(this, 'value', sharedUtil.isEvalSupported());
  19309. }
  19310. };
  19311. var FontFaceObject = (function FontFaceObjectClosure() {
  19312. function FontFaceObject(translatedData, options) {
  19313. this.compiledGlyphs = Object.create(null);
  19314. // importing translated data
  19315. for (var i in translatedData) {
  19316. this[i] = translatedData[i];
  19317. }
  19318. this.options = options;
  19319. }
  19320. FontFaceObject.prototype = {
  19321. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  19322. if (!this.data) {
  19323. return null;
  19324. }
  19325. if (this.options.disableFontFace) {
  19326. this.disableFontFace = true;
  19327. return null;
  19328. }
  19329. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  19330. if (this.options.fontRegistry) {
  19331. this.options.fontRegistry.registerFont(this);
  19332. }
  19333. return nativeFontFace;
  19334. },
  19335. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  19336. if (!this.data) {
  19337. return null;
  19338. }
  19339. if (this.options.disableFontFace) {
  19340. this.disableFontFace = true;
  19341. return null;
  19342. }
  19343. var data = bytesToString(new Uint8Array(this.data));
  19344. var fontName = this.loadedName;
  19345. // Add the font-face rule to the document
  19346. var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
  19347. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  19348. if (this.options.fontRegistry) {
  19349. this.options.fontRegistry.registerFont(this, url);
  19350. }
  19351. return rule;
  19352. },
  19353. getPathGenerator:
  19354. function FontFaceObject_getPathGenerator(objs, character) {
  19355. if (!(character in this.compiledGlyphs)) {
  19356. var cmds = objs.get(this.loadedName + '_path_' + character);
  19357. var current, i, len;
  19358. // If we can, compile cmds into JS for MAXIMUM SPEED
  19359. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  19360. var args, js = '';
  19361. for (i = 0, len = cmds.length; i < len; i++) {
  19362. current = cmds[i];
  19363. if (current.args !== undefined) {
  19364. args = current.args.join(',');
  19365. } else {
  19366. args = '';
  19367. }
  19368. js += 'c.' + current.cmd + '(' + args + ');\n';
  19369. }
  19370. /* jshint -W054 */
  19371. this.compiledGlyphs[character] = new Function('c', 'size', js);
  19372. } else {
  19373. // But fall back on using Function.prototype.apply() if we're
  19374. // blocked from using eval() for whatever reason (like CSP policies)
  19375. this.compiledGlyphs[character] = function(c, size) {
  19376. for (i = 0, len = cmds.length; i < len; i++) {
  19377. current = cmds[i];
  19378. if (current.cmd === 'scale') {
  19379. current.args = [size, -size];
  19380. }
  19381. c[current.cmd].apply(c, current.args);
  19382. }
  19383. };
  19384. }
  19385. }
  19386. return this.compiledGlyphs[character];
  19387. }
  19388. };
  19389. return FontFaceObject;
  19390. })();
  19391. exports.FontFaceObject = FontFaceObject;
  19392. exports.FontLoader = FontLoader;
  19393. }));
  19394. (function (root, factory) {
  19395. {
  19396. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  19397. }
  19398. }(this, function (exports, sharedUtil) {
  19399. var error = sharedUtil.error;
  19400. function fixMetadata(meta) {
  19401. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  19402. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  19403. function(code, d1, d2, d3) {
  19404. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  19405. });
  19406. var chars = '';
  19407. for (var i = 0; i < bytes.length; i += 2) {
  19408. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  19409. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  19410. code !== 38 && false ? String.fromCharCode(code) :
  19411. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  19412. }
  19413. return '>' + chars;
  19414. });
  19415. }
  19416. function Metadata(meta) {
  19417. if (typeof meta === 'string') {
  19418. // Ghostscript produces invalid metadata
  19419. meta = fixMetadata(meta);
  19420. var parser = new DOMParser();
  19421. meta = parser.parseFromString(meta, 'application/xml');
  19422. } else if (!(meta instanceof Document)) {
  19423. error('Metadata: Invalid metadata object');
  19424. }
  19425. this.metaDocument = meta;
  19426. this.metadata = Object.create(null);
  19427. this.parse();
  19428. }
  19429. Metadata.prototype = {
  19430. parse: function Metadata_parse() {
  19431. var doc = this.metaDocument;
  19432. var rdf = doc.documentElement;
  19433. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  19434. rdf = rdf.firstChild;
  19435. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  19436. rdf = rdf.nextSibling;
  19437. }
  19438. }
  19439. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  19440. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  19441. return;
  19442. }
  19443. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  19444. for (i = 0, length = children.length; i < length; i++) {
  19445. desc = children[i];
  19446. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  19447. continue;
  19448. }
  19449. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  19450. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  19451. entry = desc.childNodes[ii];
  19452. name = entry.nodeName.toLowerCase();
  19453. this.metadata[name] = entry.textContent.trim();
  19454. }
  19455. }
  19456. }
  19457. },
  19458. get: function Metadata_get(name) {
  19459. return this.metadata[name] || null;
  19460. },
  19461. has: function Metadata_has(name) {
  19462. return typeof this.metadata[name] !== 'undefined';
  19463. }
  19464. };
  19465. exports.Metadata = Metadata;
  19466. }));
  19467. (function (root, factory) {
  19468. {
  19469. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  19470. }
  19471. }(this, function (exports, sharedUtil) {
  19472. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  19473. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  19474. var ImageKind = sharedUtil.ImageKind;
  19475. var OPS = sharedUtil.OPS;
  19476. var Util = sharedUtil.Util;
  19477. var isNum = sharedUtil.isNum;
  19478. var isArray = sharedUtil.isArray;
  19479. var warn = sharedUtil.warn;
  19480. var createObjectURL = sharedUtil.createObjectURL;
  19481. var SVG_DEFAULTS = {
  19482. fontStyle: 'normal',
  19483. fontWeight: 'normal',
  19484. fillColor: '#000000'
  19485. };
  19486. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  19487. var PNG_HEADER =
  19488. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  19489. var CHUNK_WRAPPER_SIZE = 12;
  19490. var crcTable = new Int32Array(256);
  19491. for (var i = 0; i < 256; i++) {
  19492. var c = i;
  19493. for (var h = 0; h < 8; h++) {
  19494. if (c & 1) {
  19495. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  19496. } else {
  19497. c = (c >> 1) & 0x7fffffff;
  19498. }
  19499. }
  19500. crcTable[i] = c;
  19501. }
  19502. function crc32(data, start, end) {
  19503. var crc = -1;
  19504. for (var i = start; i < end; i++) {
  19505. var a = (crc ^ data[i]) & 0xff;
  19506. var b = crcTable[a];
  19507. crc = (crc >>> 8) ^ b;
  19508. }
  19509. return crc ^ -1;
  19510. }
  19511. function writePngChunk(type, body, data, offset) {
  19512. var p = offset;
  19513. var len = body.length;
  19514. data[p] = len >> 24 & 0xff;
  19515. data[p + 1] = len >> 16 & 0xff;
  19516. data[p + 2] = len >> 8 & 0xff;
  19517. data[p + 3] = len & 0xff;
  19518. p += 4;
  19519. data[p] = type.charCodeAt(0) & 0xff;
  19520. data[p + 1] = type.charCodeAt(1) & 0xff;
  19521. data[p + 2] = type.charCodeAt(2) & 0xff;
  19522. data[p + 3] = type.charCodeAt(3) & 0xff;
  19523. p += 4;
  19524. data.set(body, p);
  19525. p += body.length;
  19526. var crc = crc32(data, offset + 4, p);
  19527. data[p] = crc >> 24 & 0xff;
  19528. data[p + 1] = crc >> 16 & 0xff;
  19529. data[p + 2] = crc >> 8 & 0xff;
  19530. data[p + 3] = crc & 0xff;
  19531. }
  19532. function adler32(data, start, end) {
  19533. var a = 1;
  19534. var b = 0;
  19535. for (var i = start; i < end; ++i) {
  19536. a = (a + (data[i] & 0xff)) % 65521;
  19537. b = (b + a) % 65521;
  19538. }
  19539. return (b << 16) | a;
  19540. }
  19541. function encode(imgData, kind, forceDataSchema) {
  19542. var width = imgData.width;
  19543. var height = imgData.height;
  19544. var bitDepth, colorType, lineSize;
  19545. var bytes = imgData.data;
  19546. switch (kind) {
  19547. case ImageKind.GRAYSCALE_1BPP:
  19548. colorType = 0;
  19549. bitDepth = 1;
  19550. lineSize = (width + 7) >> 3;
  19551. break;
  19552. case ImageKind.RGB_24BPP:
  19553. colorType = 2;
  19554. bitDepth = 8;
  19555. lineSize = width * 3;
  19556. break;
  19557. case ImageKind.RGBA_32BPP:
  19558. colorType = 6;
  19559. bitDepth = 8;
  19560. lineSize = width * 4;
  19561. break;
  19562. default:
  19563. throw new Error('invalid format');
  19564. }
  19565. // prefix every row with predictor 0
  19566. var literals = new Uint8Array((1 + lineSize) * height);
  19567. var offsetLiterals = 0, offsetBytes = 0;
  19568. var y, i;
  19569. for (y = 0; y < height; ++y) {
  19570. literals[offsetLiterals++] = 0; // no prediction
  19571. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  19572. offsetLiterals);
  19573. offsetBytes += lineSize;
  19574. offsetLiterals += lineSize;
  19575. }
  19576. if (kind === ImageKind.GRAYSCALE_1BPP) {
  19577. // inverting for B/W
  19578. offsetLiterals = 0;
  19579. for (y = 0; y < height; y++) {
  19580. offsetLiterals++; // skipping predictor
  19581. for (i = 0; i < lineSize; i++) {
  19582. literals[offsetLiterals++] ^= 0xFF;
  19583. }
  19584. }
  19585. }
  19586. var ihdr = new Uint8Array([
  19587. width >> 24 & 0xff,
  19588. width >> 16 & 0xff,
  19589. width >> 8 & 0xff,
  19590. width & 0xff,
  19591. height >> 24 & 0xff,
  19592. height >> 16 & 0xff,
  19593. height >> 8 & 0xff,
  19594. height & 0xff,
  19595. bitDepth, // bit depth
  19596. colorType, // color type
  19597. 0x00, // compression method
  19598. 0x00, // filter method
  19599. 0x00 // interlace method
  19600. ]);
  19601. var len = literals.length;
  19602. var maxBlockLength = 0xFFFF;
  19603. var deflateBlocks = Math.ceil(len / maxBlockLength);
  19604. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  19605. var pi = 0;
  19606. idat[pi++] = 0x78; // compression method and flags
  19607. idat[pi++] = 0x9c; // flags
  19608. var pos = 0;
  19609. while (len > maxBlockLength) {
  19610. // writing non-final DEFLATE blocks type 0 and length of 65535
  19611. idat[pi++] = 0x00;
  19612. idat[pi++] = 0xff;
  19613. idat[pi++] = 0xff;
  19614. idat[pi++] = 0x00;
  19615. idat[pi++] = 0x00;
  19616. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  19617. pi += maxBlockLength;
  19618. pos += maxBlockLength;
  19619. len -= maxBlockLength;
  19620. }
  19621. // writing non-final DEFLATE blocks type 0
  19622. idat[pi++] = 0x01;
  19623. idat[pi++] = len & 0xff;
  19624. idat[pi++] = len >> 8 & 0xff;
  19625. idat[pi++] = (~len & 0xffff) & 0xff;
  19626. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  19627. idat.set(literals.subarray(pos), pi);
  19628. pi += literals.length - pos;
  19629. var adler = adler32(literals, 0, literals.length); // checksum
  19630. idat[pi++] = adler >> 24 & 0xff;
  19631. idat[pi++] = adler >> 16 & 0xff;
  19632. idat[pi++] = adler >> 8 & 0xff;
  19633. idat[pi++] = adler & 0xff;
  19634. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  19635. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  19636. ihdr.length + idat.length;
  19637. var data = new Uint8Array(pngLength);
  19638. var offset = 0;
  19639. data.set(PNG_HEADER, offset);
  19640. offset += PNG_HEADER.length;
  19641. writePngChunk('IHDR', ihdr, data, offset);
  19642. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  19643. writePngChunk('IDATA', idat, data, offset);
  19644. offset += CHUNK_WRAPPER_SIZE + idat.length;
  19645. writePngChunk('IEND', new Uint8Array(0), data, offset);
  19646. return createObjectURL(data, 'image/png', forceDataSchema);
  19647. }
  19648. return function convertImgDataToPng(imgData, forceDataSchema) {
  19649. var kind = (imgData.kind === undefined ?
  19650. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  19651. return encode(imgData, kind, forceDataSchema);
  19652. };
  19653. })();
  19654. var SVGExtraState = (function SVGExtraStateClosure() {
  19655. function SVGExtraState() {
  19656. this.fontSizeScale = 1;
  19657. this.fontWeight = SVG_DEFAULTS.fontWeight;
  19658. this.fontSize = 0;
  19659. this.textMatrix = IDENTITY_MATRIX;
  19660. this.fontMatrix = FONT_IDENTITY_MATRIX;
  19661. this.leading = 0;
  19662. // Current point (in user coordinates)
  19663. this.x = 0;
  19664. this.y = 0;
  19665. // Start of text line (in text coordinates)
  19666. this.lineX = 0;
  19667. this.lineY = 0;
  19668. // Character and word spacing
  19669. this.charSpacing = 0;
  19670. this.wordSpacing = 0;
  19671. this.textHScale = 1;
  19672. this.textRise = 0;
  19673. // Default foreground and background colors
  19674. this.fillColor = SVG_DEFAULTS.fillColor;
  19675. this.strokeColor = '#000000';
  19676. this.fillAlpha = 1;
  19677. this.strokeAlpha = 1;
  19678. this.lineWidth = 1;
  19679. this.lineJoin = '';
  19680. this.lineCap = '';
  19681. this.miterLimit = 0;
  19682. this.dashArray = [];
  19683. this.dashPhase = 0;
  19684. this.dependencies = [];
  19685. // Clipping
  19686. this.clipId = '';
  19687. this.pendingClip = false;
  19688. this.maskId = '';
  19689. }
  19690. SVGExtraState.prototype = {
  19691. clone: function SVGExtraState_clone() {
  19692. return Object.create(this);
  19693. },
  19694. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  19695. this.x = x;
  19696. this.y = y;
  19697. }
  19698. };
  19699. return SVGExtraState;
  19700. })();
  19701. var SVGGraphics = (function SVGGraphicsClosure() {
  19702. function createScratchSVG(width, height) {
  19703. var NS = 'http://www.w3.org/2000/svg';
  19704. var svg = document.createElementNS(NS, 'svg:svg');
  19705. svg.setAttributeNS(null, 'version', '1.1');
  19706. svg.setAttributeNS(null, 'width', width + 'px');
  19707. svg.setAttributeNS(null, 'height', height + 'px');
  19708. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  19709. return svg;
  19710. }
  19711. function opListToTree(opList) {
  19712. var opTree = [];
  19713. var tmp = [];
  19714. var opListLen = opList.length;
  19715. for (var x = 0; x < opListLen; x++) {
  19716. if (opList[x].fn === 'save') {
  19717. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  19718. tmp.push(opTree);
  19719. opTree = opTree[opTree.length - 1].items;
  19720. continue;
  19721. }
  19722. if(opList[x].fn === 'restore') {
  19723. opTree = tmp.pop();
  19724. } else {
  19725. opTree.push(opList[x]);
  19726. }
  19727. }
  19728. return opTree;
  19729. }
  19730. /**
  19731. * Formats float number.
  19732. * @param value {number} number to format.
  19733. * @returns {string}
  19734. */
  19735. function pf(value) {
  19736. if (value === (value | 0)) { // integer number
  19737. return value.toString();
  19738. }
  19739. var s = value.toFixed(10);
  19740. var i = s.length - 1;
  19741. if (s[i] !== '0') {
  19742. return s;
  19743. }
  19744. // removing trailing zeros
  19745. do {
  19746. i--;
  19747. } while (s[i] === '0');
  19748. return s.substr(0, s[i] === '.' ? i : i + 1);
  19749. }
  19750. /**
  19751. * Formats transform matrix. The standard rotation, scale and translate
  19752. * matrices are replaced by their shorter forms, and for identity matrix
  19753. * returns empty string to save the memory.
  19754. * @param m {Array} matrix to format.
  19755. * @returns {string}
  19756. */
  19757. function pm(m) {
  19758. if (m[4] === 0 && m[5] === 0) {
  19759. if (m[1] === 0 && m[2] === 0) {
  19760. if (m[0] === 1 && m[3] === 1) {
  19761. return '';
  19762. }
  19763. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  19764. }
  19765. if (m[0] === m[3] && m[1] === -m[2]) {
  19766. var a = Math.acos(m[0]) * 180 / Math.PI;
  19767. return 'rotate(' + pf(a) + ')';
  19768. }
  19769. } else {
  19770. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  19771. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19772. }
  19773. }
  19774. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  19775. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19776. }
  19777. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  19778. this.current = new SVGExtraState();
  19779. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  19780. this.transformStack = [];
  19781. this.extraStack = [];
  19782. this.commonObjs = commonObjs;
  19783. this.objs = objs;
  19784. this.pendingEOFill = false;
  19785. this.embedFonts = false;
  19786. this.embeddedFonts = Object.create(null);
  19787. this.cssStyle = null;
  19788. this.forceDataSchema = !!forceDataSchema;
  19789. }
  19790. var NS = 'http://www.w3.org/2000/svg';
  19791. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  19792. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  19793. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  19794. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  19795. var clipCount = 0;
  19796. var maskCount = 0;
  19797. SVGGraphics.prototype = {
  19798. save: function SVGGraphics_save() {
  19799. this.transformStack.push(this.transformMatrix);
  19800. var old = this.current;
  19801. this.extraStack.push(old);
  19802. this.current = old.clone();
  19803. },
  19804. restore: function SVGGraphics_restore() {
  19805. this.transformMatrix = this.transformStack.pop();
  19806. this.current = this.extraStack.pop();
  19807. this.tgrp = document.createElementNS(NS, 'svg:g');
  19808. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19809. this.pgrp.appendChild(this.tgrp);
  19810. },
  19811. group: function SVGGraphics_group(items) {
  19812. this.save();
  19813. this.executeOpTree(items);
  19814. this.restore();
  19815. },
  19816. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  19817. var fnArray = operatorList.fnArray;
  19818. var fnArrayLen = fnArray.length;
  19819. var argsArray = operatorList.argsArray;
  19820. var self = this;
  19821. for (var i = 0; i < fnArrayLen; i++) {
  19822. if (OPS.dependency === fnArray[i]) {
  19823. var deps = argsArray[i];
  19824. for (var n = 0, nn = deps.length; n < nn; n++) {
  19825. var obj = deps[n];
  19826. var common = obj.substring(0, 2) === 'g_';
  19827. var promise;
  19828. if (common) {
  19829. promise = new Promise(function(resolve) {
  19830. self.commonObjs.get(obj, resolve);
  19831. });
  19832. } else {
  19833. promise = new Promise(function(resolve) {
  19834. self.objs.get(obj, resolve);
  19835. });
  19836. }
  19837. this.current.dependencies.push(promise);
  19838. }
  19839. }
  19840. }
  19841. return Promise.all(this.current.dependencies);
  19842. },
  19843. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19844. var transformMatrix = [a, b, c, d, e, f];
  19845. this.transformMatrix = Util.transform(this.transformMatrix,
  19846. transformMatrix);
  19847. this.tgrp = document.createElementNS(NS, 'svg:g');
  19848. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19849. },
  19850. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19851. this.svg = createScratchSVG(viewport.width, viewport.height);
  19852. this.viewport = viewport;
  19853. return this.loadDependencies(operatorList).then(function () {
  19854. this.transformMatrix = IDENTITY_MATRIX;
  19855. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19856. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19857. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19858. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19859. this.defs = document.createElementNS(NS, 'svg:defs');
  19860. this.pgrp.appendChild(this.defs);
  19861. this.pgrp.appendChild(this.tgrp);
  19862. this.svg.appendChild(this.pgrp);
  19863. var opTree = this.convertOpList(operatorList);
  19864. this.executeOpTree(opTree);
  19865. return this.svg;
  19866. }.bind(this));
  19867. },
  19868. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19869. var argsArray = operatorList.argsArray;
  19870. var fnArray = operatorList.fnArray;
  19871. var fnArrayLen = fnArray.length;
  19872. var REVOPS = [];
  19873. var opList = [];
  19874. for (var op in OPS) {
  19875. REVOPS[OPS[op]] = op;
  19876. }
  19877. for (var x = 0; x < fnArrayLen; x++) {
  19878. var fnId = fnArray[x];
  19879. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19880. }
  19881. return opListToTree(opList);
  19882. },
  19883. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19884. var opTreeLen = opTree.length;
  19885. for(var x = 0; x < opTreeLen; x++) {
  19886. var fn = opTree[x].fn;
  19887. var fnId = opTree[x].fnId;
  19888. var args = opTree[x].args;
  19889. switch (fnId | 0) {
  19890. case OPS.beginText:
  19891. this.beginText();
  19892. break;
  19893. case OPS.setLeading:
  19894. this.setLeading(args);
  19895. break;
  19896. case OPS.setLeadingMoveText:
  19897. this.setLeadingMoveText(args[0], args[1]);
  19898. break;
  19899. case OPS.setFont:
  19900. this.setFont(args);
  19901. break;
  19902. case OPS.showText:
  19903. this.showText(args[0]);
  19904. break;
  19905. case OPS.showSpacedText:
  19906. this.showText(args[0]);
  19907. break;
  19908. case OPS.endText:
  19909. this.endText();
  19910. break;
  19911. case OPS.moveText:
  19912. this.moveText(args[0], args[1]);
  19913. break;
  19914. case OPS.setCharSpacing:
  19915. this.setCharSpacing(args[0]);
  19916. break;
  19917. case OPS.setWordSpacing:
  19918. this.setWordSpacing(args[0]);
  19919. break;
  19920. case OPS.setHScale:
  19921. this.setHScale(args[0]);
  19922. break;
  19923. case OPS.setTextMatrix:
  19924. this.setTextMatrix(args[0], args[1], args[2],
  19925. args[3], args[4], args[5]);
  19926. break;
  19927. case OPS.setLineWidth:
  19928. this.setLineWidth(args[0]);
  19929. break;
  19930. case OPS.setLineJoin:
  19931. this.setLineJoin(args[0]);
  19932. break;
  19933. case OPS.setLineCap:
  19934. this.setLineCap(args[0]);
  19935. break;
  19936. case OPS.setMiterLimit:
  19937. this.setMiterLimit(args[0]);
  19938. break;
  19939. case OPS.setFillRGBColor:
  19940. this.setFillRGBColor(args[0], args[1], args[2]);
  19941. break;
  19942. case OPS.setStrokeRGBColor:
  19943. this.setStrokeRGBColor(args[0], args[1], args[2]);
  19944. break;
  19945. case OPS.setDash:
  19946. this.setDash(args[0], args[1]);
  19947. break;
  19948. case OPS.setGState:
  19949. this.setGState(args[0]);
  19950. break;
  19951. case OPS.fill:
  19952. this.fill();
  19953. break;
  19954. case OPS.eoFill:
  19955. this.eoFill();
  19956. break;
  19957. case OPS.stroke:
  19958. this.stroke();
  19959. break;
  19960. case OPS.fillStroke:
  19961. this.fillStroke();
  19962. break;
  19963. case OPS.eoFillStroke:
  19964. this.eoFillStroke();
  19965. break;
  19966. case OPS.clip:
  19967. this.clip('nonzero');
  19968. break;
  19969. case OPS.eoClip:
  19970. this.clip('evenodd');
  19971. break;
  19972. case OPS.paintSolidColorImageMask:
  19973. this.paintSolidColorImageMask();
  19974. break;
  19975. case OPS.paintJpegXObject:
  19976. this.paintJpegXObject(args[0], args[1], args[2]);
  19977. break;
  19978. case OPS.paintImageXObject:
  19979. this.paintImageXObject(args[0]);
  19980. break;
  19981. case OPS.paintInlineImageXObject:
  19982. this.paintInlineImageXObject(args[0]);
  19983. break;
  19984. case OPS.paintImageMaskXObject:
  19985. this.paintImageMaskXObject(args[0]);
  19986. break;
  19987. case OPS.paintFormXObjectBegin:
  19988. this.paintFormXObjectBegin(args[0], args[1]);
  19989. break;
  19990. case OPS.paintFormXObjectEnd:
  19991. this.paintFormXObjectEnd();
  19992. break;
  19993. case OPS.closePath:
  19994. this.closePath();
  19995. break;
  19996. case OPS.closeStroke:
  19997. this.closeStroke();
  19998. break;
  19999. case OPS.closeFillStroke:
  20000. this.closeFillStroke();
  20001. break;
  20002. case OPS.nextLine:
  20003. this.nextLine();
  20004. break;
  20005. case OPS.transform:
  20006. this.transform(args[0], args[1], args[2], args[3],
  20007. args[4], args[5]);
  20008. break;
  20009. case OPS.constructPath:
  20010. this.constructPath(args[0], args[1]);
  20011. break;
  20012. case OPS.endPath:
  20013. this.endPath();
  20014. break;
  20015. case 92:
  20016. this.group(opTree[x].items);
  20017. break;
  20018. default:
  20019. warn('Unimplemented method '+ fn);
  20020. break;
  20021. }
  20022. }
  20023. },
  20024. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  20025. this.current.wordSpacing = wordSpacing;
  20026. },
  20027. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  20028. this.current.charSpacing = charSpacing;
  20029. },
  20030. nextLine: function SVGGraphics_nextLine() {
  20031. this.moveText(0, this.current.leading);
  20032. },
  20033. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  20034. var current = this.current;
  20035. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  20036. this.current.x = this.current.lineX = 0;
  20037. this.current.y = this.current.lineY = 0;
  20038. current.xcoords = [];
  20039. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20040. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20041. current.tspan.setAttributeNS(null, 'font-size',
  20042. pf(current.fontSize) + 'px');
  20043. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20044. current.txtElement = document.createElementNS(NS, 'svg:text');
  20045. current.txtElement.appendChild(current.tspan);
  20046. },
  20047. beginText: function SVGGraphics_beginText() {
  20048. this.current.x = this.current.lineX = 0;
  20049. this.current.y = this.current.lineY = 0;
  20050. this.current.textMatrix = IDENTITY_MATRIX;
  20051. this.current.lineMatrix = IDENTITY_MATRIX;
  20052. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20053. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  20054. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  20055. this.current.xcoords = [];
  20056. },
  20057. moveText: function SVGGraphics_moveText(x, y) {
  20058. var current = this.current;
  20059. this.current.x = this.current.lineX += x;
  20060. this.current.y = this.current.lineY += y;
  20061. current.xcoords = [];
  20062. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20063. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20064. current.tspan.setAttributeNS(null, 'font-size',
  20065. pf(current.fontSize) + 'px');
  20066. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20067. },
  20068. showText: function SVGGraphics_showText(glyphs) {
  20069. var current = this.current;
  20070. var font = current.font;
  20071. var fontSize = current.fontSize;
  20072. if (fontSize === 0) {
  20073. return;
  20074. }
  20075. var charSpacing = current.charSpacing;
  20076. var wordSpacing = current.wordSpacing;
  20077. var fontDirection = current.fontDirection;
  20078. var textHScale = current.textHScale * fontDirection;
  20079. var glyphsLength = glyphs.length;
  20080. var vertical = font.vertical;
  20081. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  20082. var x = 0, i;
  20083. for (i = 0; i < glyphsLength; ++i) {
  20084. var glyph = glyphs[i];
  20085. if (glyph === null) {
  20086. // word break
  20087. x += fontDirection * wordSpacing;
  20088. continue;
  20089. } else if (isNum(glyph)) {
  20090. x += -glyph * fontSize * 0.001;
  20091. continue;
  20092. }
  20093. current.xcoords.push(current.x + x * textHScale);
  20094. var width = glyph.width;
  20095. var character = glyph.fontChar;
  20096. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  20097. x += charWidth;
  20098. current.tspan.textContent += character;
  20099. }
  20100. if (vertical) {
  20101. current.y -= x * textHScale;
  20102. } else {
  20103. current.x += x * textHScale;
  20104. }
  20105. current.tspan.setAttributeNS(null, 'x',
  20106. current.xcoords.map(pf).join(' '));
  20107. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20108. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20109. current.tspan.setAttributeNS(null, 'font-size',
  20110. pf(current.fontSize) + 'px');
  20111. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  20112. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  20113. }
  20114. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  20115. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  20116. }
  20117. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  20118. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  20119. }
  20120. current.txtElement.setAttributeNS(null, 'transform',
  20121. pm(current.textMatrix) +
  20122. ' scale(1, -1)' );
  20123. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  20124. current.txtElement.appendChild(current.tspan);
  20125. current.txtgrp.appendChild(current.txtElement);
  20126. this.tgrp.appendChild(current.txtElement);
  20127. },
  20128. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  20129. this.setLeading(-y);
  20130. this.moveText(x, y);
  20131. },
  20132. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  20133. if (!this.cssStyle) {
  20134. this.cssStyle = document.createElementNS(NS, 'svg:style');
  20135. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  20136. this.defs.appendChild(this.cssStyle);
  20137. }
  20138. var url = createObjectURL(fontObj.data, fontObj.mimetype,
  20139. this.forceDataSchema);
  20140. this.cssStyle.textContent +=
  20141. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  20142. ' src: url(' + url + '); }\n';
  20143. },
  20144. setFont: function SVGGraphics_setFont(details) {
  20145. var current = this.current;
  20146. var fontObj = this.commonObjs.get(details[0]);
  20147. var size = details[1];
  20148. this.current.font = fontObj;
  20149. if (this.embedFonts && fontObj.data &&
  20150. !this.embeddedFonts[fontObj.loadedName]) {
  20151. this.addFontStyle(fontObj);
  20152. this.embeddedFonts[fontObj.loadedName] = fontObj;
  20153. }
  20154. current.fontMatrix = (fontObj.fontMatrix ?
  20155. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  20156. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  20157. (fontObj.bold ? 'bold' : 'normal');
  20158. var italic = fontObj.italic ? 'italic' : 'normal';
  20159. if (size < 0) {
  20160. size = -size;
  20161. current.fontDirection = -1;
  20162. } else {
  20163. current.fontDirection = 1;
  20164. }
  20165. current.fontSize = size;
  20166. current.fontFamily = fontObj.loadedName;
  20167. current.fontWeight = bold;
  20168. current.fontStyle = italic;
  20169. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20170. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20171. current.xcoords = [];
  20172. },
  20173. endText: function SVGGraphics_endText() {
  20174. if (this.current.pendingClip) {
  20175. this.cgrp.appendChild(this.tgrp);
  20176. this.pgrp.appendChild(this.cgrp);
  20177. } else {
  20178. this.pgrp.appendChild(this.tgrp);
  20179. }
  20180. this.tgrp = document.createElementNS(NS, 'svg:g');
  20181. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20182. },
  20183. // Path properties
  20184. setLineWidth: function SVGGraphics_setLineWidth(width) {
  20185. this.current.lineWidth = width;
  20186. },
  20187. setLineCap: function SVGGraphics_setLineCap(style) {
  20188. this.current.lineCap = LINE_CAP_STYLES[style];
  20189. },
  20190. setLineJoin: function SVGGraphics_setLineJoin(style) {
  20191. this.current.lineJoin = LINE_JOIN_STYLES[style];
  20192. },
  20193. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  20194. this.current.miterLimit = limit;
  20195. },
  20196. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  20197. var color = Util.makeCssRgb(r, g, b);
  20198. this.current.strokeColor = color;
  20199. },
  20200. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  20201. var color = Util.makeCssRgb(r, g, b);
  20202. this.current.fillColor = color;
  20203. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20204. this.current.xcoords = [];
  20205. },
  20206. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  20207. this.current.dashArray = dashArray;
  20208. this.current.dashPhase = dashPhase;
  20209. },
  20210. constructPath: function SVGGraphics_constructPath(ops, args) {
  20211. var current = this.current;
  20212. var x = current.x, y = current.y;
  20213. current.path = document.createElementNS(NS, 'svg:path');
  20214. var d = [];
  20215. var opLength = ops.length;
  20216. for (var i = 0, j = 0; i < opLength; i++) {
  20217. switch (ops[i] | 0) {
  20218. case OPS.rectangle:
  20219. x = args[j++];
  20220. y = args[j++];
  20221. var width = args[j++];
  20222. var height = args[j++];
  20223. var xw = x + width;
  20224. var yh = y + height;
  20225. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  20226. 'L', pf(x), pf(yh), 'Z');
  20227. break;
  20228. case OPS.moveTo:
  20229. x = args[j++];
  20230. y = args[j++];
  20231. d.push('M', pf(x), pf(y));
  20232. break;
  20233. case OPS.lineTo:
  20234. x = args[j++];
  20235. y = args[j++];
  20236. d.push('L', pf(x) , pf(y));
  20237. break;
  20238. case OPS.curveTo:
  20239. x = args[j + 4];
  20240. y = args[j + 5];
  20241. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  20242. pf(args[j + 3]), pf(x), pf(y));
  20243. j += 6;
  20244. break;
  20245. case OPS.curveTo2:
  20246. x = args[j + 2];
  20247. y = args[j + 3];
  20248. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  20249. pf(args[j + 2]), pf(args[j + 3]));
  20250. j += 4;
  20251. break;
  20252. case OPS.curveTo3:
  20253. x = args[j + 2];
  20254. y = args[j + 3];
  20255. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  20256. pf(x), pf(y));
  20257. j += 4;
  20258. break;
  20259. case OPS.closePath:
  20260. d.push('Z');
  20261. break;
  20262. }
  20263. }
  20264. current.path.setAttributeNS(null, 'd', d.join(' '));
  20265. current.path.setAttributeNS(null, 'stroke-miterlimit',
  20266. pf(current.miterLimit));
  20267. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  20268. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  20269. current.path.setAttributeNS(null, 'stroke-width',
  20270. pf(current.lineWidth) + 'px');
  20271. current.path.setAttributeNS(null, 'stroke-dasharray',
  20272. current.dashArray.map(pf).join(' '));
  20273. current.path.setAttributeNS(null, 'stroke-dashoffset',
  20274. pf(current.dashPhase) + 'px');
  20275. current.path.setAttributeNS(null, 'fill', 'none');
  20276. this.tgrp.appendChild(current.path);
  20277. if (current.pendingClip) {
  20278. this.cgrp.appendChild(this.tgrp);
  20279. this.pgrp.appendChild(this.cgrp);
  20280. } else {
  20281. this.pgrp.appendChild(this.tgrp);
  20282. }
  20283. // Saving a reference in current.element so that it can be addressed
  20284. // in 'fill' and 'stroke'
  20285. current.element = current.path;
  20286. current.setCurrentPoint(x, y);
  20287. },
  20288. endPath: function SVGGraphics_endPath() {
  20289. var current = this.current;
  20290. if (current.pendingClip) {
  20291. this.cgrp.appendChild(this.tgrp);
  20292. this.pgrp.appendChild(this.cgrp);
  20293. } else {
  20294. this.pgrp.appendChild(this.tgrp);
  20295. }
  20296. this.tgrp = document.createElementNS(NS, 'svg:g');
  20297. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20298. },
  20299. clip: function SVGGraphics_clip(type) {
  20300. var current = this.current;
  20301. // Add current path to clipping path
  20302. current.clipId = 'clippath' + clipCount;
  20303. clipCount++;
  20304. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  20305. this.clippath.setAttributeNS(null, 'id', current.clipId);
  20306. var clipElement = current.element.cloneNode();
  20307. if (type === 'evenodd') {
  20308. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  20309. } else {
  20310. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  20311. }
  20312. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20313. this.clippath.appendChild(clipElement);
  20314. this.defs.appendChild(this.clippath);
  20315. // Create a new group with that attribute
  20316. current.pendingClip = true;
  20317. this.cgrp = document.createElementNS(NS, 'svg:g');
  20318. this.cgrp.setAttributeNS(null, 'clip-path',
  20319. 'url(#' + current.clipId + ')');
  20320. this.pgrp.appendChild(this.cgrp);
  20321. },
  20322. closePath: function SVGGraphics_closePath() {
  20323. var current = this.current;
  20324. var d = current.path.getAttributeNS(null, 'd');
  20325. d += 'Z';
  20326. current.path.setAttributeNS(null, 'd', d);
  20327. },
  20328. setLeading: function SVGGraphics_setLeading(leading) {
  20329. this.current.leading = -leading;
  20330. },
  20331. setTextRise: function SVGGraphics_setTextRise(textRise) {
  20332. this.current.textRise = textRise;
  20333. },
  20334. setHScale: function SVGGraphics_setHScale(scale) {
  20335. this.current.textHScale = scale / 100;
  20336. },
  20337. setGState: function SVGGraphics_setGState(states) {
  20338. for (var i = 0, ii = states.length; i < ii; i++) {
  20339. var state = states[i];
  20340. var key = state[0];
  20341. var value = state[1];
  20342. switch (key) {
  20343. case 'LW':
  20344. this.setLineWidth(value);
  20345. break;
  20346. case 'LC':
  20347. this.setLineCap(value);
  20348. break;
  20349. case 'LJ':
  20350. this.setLineJoin(value);
  20351. break;
  20352. case 'ML':
  20353. this.setMiterLimit(value);
  20354. break;
  20355. case 'D':
  20356. this.setDash(value[0], value[1]);
  20357. break;
  20358. case 'RI':
  20359. break;
  20360. case 'FL':
  20361. break;
  20362. case 'Font':
  20363. this.setFont(value);
  20364. break;
  20365. case 'CA':
  20366. break;
  20367. case 'ca':
  20368. break;
  20369. case 'BM':
  20370. break;
  20371. case 'SMask':
  20372. break;
  20373. }
  20374. }
  20375. },
  20376. fill: function SVGGraphics_fill() {
  20377. var current = this.current;
  20378. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20379. },
  20380. stroke: function SVGGraphics_stroke() {
  20381. var current = this.current;
  20382. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  20383. current.element.setAttributeNS(null, 'fill', 'none');
  20384. },
  20385. eoFill: function SVGGraphics_eoFill() {
  20386. var current = this.current;
  20387. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20388. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20389. },
  20390. fillStroke: function SVGGraphics_fillStroke() {
  20391. // Order is important since stroke wants fill to be none.
  20392. // First stroke, then if fill needed, it will be overwritten.
  20393. this.stroke();
  20394. this.fill();
  20395. },
  20396. eoFillStroke: function SVGGraphics_eoFillStroke() {
  20397. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20398. this.fillStroke();
  20399. },
  20400. closeStroke: function SVGGraphics_closeStroke() {
  20401. this.closePath();
  20402. this.stroke();
  20403. },
  20404. closeFillStroke: function SVGGraphics_closeFillStroke() {
  20405. this.closePath();
  20406. this.fillStroke();
  20407. },
  20408. paintSolidColorImageMask:
  20409. function SVGGraphics_paintSolidColorImageMask() {
  20410. var current = this.current;
  20411. var rect = document.createElementNS(NS, 'svg:rect');
  20412. rect.setAttributeNS(null, 'x', '0');
  20413. rect.setAttributeNS(null, 'y', '0');
  20414. rect.setAttributeNS(null, 'width', '1px');
  20415. rect.setAttributeNS(null, 'height', '1px');
  20416. rect.setAttributeNS(null, 'fill', current.fillColor);
  20417. this.tgrp.appendChild(rect);
  20418. },
  20419. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  20420. var current = this.current;
  20421. var imgObj = this.objs.get(objId);
  20422. var imgEl = document.createElementNS(NS, 'svg:image');
  20423. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  20424. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  20425. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  20426. imgEl.setAttributeNS(null, 'x', '0');
  20427. imgEl.setAttributeNS(null, 'y', pf(-h));
  20428. imgEl.setAttributeNS(null, 'transform',
  20429. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  20430. this.tgrp.appendChild(imgEl);
  20431. if (current.pendingClip) {
  20432. this.cgrp.appendChild(this.tgrp);
  20433. this.pgrp.appendChild(this.cgrp);
  20434. } else {
  20435. this.pgrp.appendChild(this.tgrp);
  20436. }
  20437. },
  20438. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  20439. var imgData = this.objs.get(objId);
  20440. if (!imgData) {
  20441. warn('Dependent image isn\'t ready yet');
  20442. return;
  20443. }
  20444. this.paintInlineImageXObject(imgData);
  20445. },
  20446. paintInlineImageXObject:
  20447. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  20448. var current = this.current;
  20449. var width = imgData.width;
  20450. var height = imgData.height;
  20451. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  20452. var cliprect = document.createElementNS(NS, 'svg:rect');
  20453. cliprect.setAttributeNS(null, 'x', '0');
  20454. cliprect.setAttributeNS(null, 'y', '0');
  20455. cliprect.setAttributeNS(null, 'width', pf(width));
  20456. cliprect.setAttributeNS(null, 'height', pf(height));
  20457. current.element = cliprect;
  20458. this.clip('nonzero');
  20459. var imgEl = document.createElementNS(NS, 'svg:image');
  20460. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  20461. imgEl.setAttributeNS(null, 'x', '0');
  20462. imgEl.setAttributeNS(null, 'y', pf(-height));
  20463. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  20464. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  20465. imgEl.setAttributeNS(null, 'transform',
  20466. 'scale(' + pf(1 / width) + ' ' +
  20467. pf(-1 / height) + ')');
  20468. if (mask) {
  20469. mask.appendChild(imgEl);
  20470. } else {
  20471. this.tgrp.appendChild(imgEl);
  20472. }
  20473. if (current.pendingClip) {
  20474. this.cgrp.appendChild(this.tgrp);
  20475. this.pgrp.appendChild(this.cgrp);
  20476. } else {
  20477. this.pgrp.appendChild(this.tgrp);
  20478. }
  20479. },
  20480. paintImageMaskXObject:
  20481. function SVGGraphics_paintImageMaskXObject(imgData) {
  20482. var current = this.current;
  20483. var width = imgData.width;
  20484. var height = imgData.height;
  20485. var fillColor = current.fillColor;
  20486. current.maskId = 'mask' + maskCount++;
  20487. var mask = document.createElementNS(NS, 'svg:mask');
  20488. mask.setAttributeNS(null, 'id', current.maskId);
  20489. var rect = document.createElementNS(NS, 'svg:rect');
  20490. rect.setAttributeNS(null, 'x', '0');
  20491. rect.setAttributeNS(null, 'y', '0');
  20492. rect.setAttributeNS(null, 'width', pf(width));
  20493. rect.setAttributeNS(null, 'height', pf(height));
  20494. rect.setAttributeNS(null, 'fill', fillColor);
  20495. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  20496. this.defs.appendChild(mask);
  20497. this.tgrp.appendChild(rect);
  20498. this.paintInlineImageXObject(imgData, mask);
  20499. },
  20500. paintFormXObjectBegin:
  20501. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  20502. this.save();
  20503. if (isArray(matrix) && matrix.length === 6) {
  20504. this.transform(matrix[0], matrix[1], matrix[2],
  20505. matrix[3], matrix[4], matrix[5]);
  20506. }
  20507. if (isArray(bbox) && bbox.length === 4) {
  20508. var width = bbox[2] - bbox[0];
  20509. var height = bbox[3] - bbox[1];
  20510. var cliprect = document.createElementNS(NS, 'svg:rect');
  20511. cliprect.setAttributeNS(null, 'x', bbox[0]);
  20512. cliprect.setAttributeNS(null, 'y', bbox[1]);
  20513. cliprect.setAttributeNS(null, 'width', pf(width));
  20514. cliprect.setAttributeNS(null, 'height', pf(height));
  20515. this.current.element = cliprect;
  20516. this.clip('nonzero');
  20517. this.endPath();
  20518. }
  20519. },
  20520. paintFormXObjectEnd:
  20521. function SVGGraphics_paintFormXObjectEnd() {
  20522. this.restore();
  20523. }
  20524. };
  20525. return SVGGraphics;
  20526. })();
  20527. exports.SVGGraphics = SVGGraphics;
  20528. }));
  20529. (function (root, factory) {
  20530. {
  20531. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20532. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20533. root.pdfjsCoreJpx);
  20534. }
  20535. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20536. coreJpx) {
  20537. var Util = sharedUtil.Util;
  20538. var error = sharedUtil.error;
  20539. var info = sharedUtil.info;
  20540. var isArray = sharedUtil.isArray;
  20541. var createObjectURL = sharedUtil.createObjectURL;
  20542. var shadow = sharedUtil.shadow;
  20543. var warn = sharedUtil.warn;
  20544. var isSpace = sharedUtil.isSpace;
  20545. var Dict = corePrimitives.Dict;
  20546. var isDict = corePrimitives.isDict;
  20547. var Jbig2Image = coreJbig2.Jbig2Image;
  20548. var JpegImage = coreJpg.JpegImage;
  20549. var JpxImage = coreJpx.JpxImage;
  20550. var Stream = (function StreamClosure() {
  20551. function Stream(arrayBuffer, start, length, dict) {
  20552. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20553. arrayBuffer : new Uint8Array(arrayBuffer));
  20554. this.start = start || 0;
  20555. this.pos = this.start;
  20556. this.end = (start + length) || this.bytes.length;
  20557. this.dict = dict;
  20558. }
  20559. // required methods for a stream. if a particular stream does not
  20560. // implement these, an error should be thrown
  20561. Stream.prototype = {
  20562. get length() {
  20563. return this.end - this.start;
  20564. },
  20565. get isEmpty() {
  20566. return this.length === 0;
  20567. },
  20568. getByte: function Stream_getByte() {
  20569. if (this.pos >= this.end) {
  20570. return -1;
  20571. }
  20572. return this.bytes[this.pos++];
  20573. },
  20574. getUint16: function Stream_getUint16() {
  20575. var b0 = this.getByte();
  20576. var b1 = this.getByte();
  20577. if (b0 === -1 || b1 === -1) {
  20578. return -1;
  20579. }
  20580. return (b0 << 8) + b1;
  20581. },
  20582. getInt32: function Stream_getInt32() {
  20583. var b0 = this.getByte();
  20584. var b1 = this.getByte();
  20585. var b2 = this.getByte();
  20586. var b3 = this.getByte();
  20587. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20588. },
  20589. // returns subarray of original buffer
  20590. // should only be read
  20591. getBytes: function Stream_getBytes(length) {
  20592. var bytes = this.bytes;
  20593. var pos = this.pos;
  20594. var strEnd = this.end;
  20595. if (!length) {
  20596. return bytes.subarray(pos, strEnd);
  20597. }
  20598. var end = pos + length;
  20599. if (end > strEnd) {
  20600. end = strEnd;
  20601. }
  20602. this.pos = end;
  20603. return bytes.subarray(pos, end);
  20604. },
  20605. peekByte: function Stream_peekByte() {
  20606. var peekedByte = this.getByte();
  20607. this.pos--;
  20608. return peekedByte;
  20609. },
  20610. peekBytes: function Stream_peekBytes(length) {
  20611. var bytes = this.getBytes(length);
  20612. this.pos -= bytes.length;
  20613. return bytes;
  20614. },
  20615. skip: function Stream_skip(n) {
  20616. if (!n) {
  20617. n = 1;
  20618. }
  20619. this.pos += n;
  20620. },
  20621. reset: function Stream_reset() {
  20622. this.pos = this.start;
  20623. },
  20624. moveStart: function Stream_moveStart() {
  20625. this.start = this.pos;
  20626. },
  20627. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20628. return new Stream(this.bytes.buffer, start, length, dict);
  20629. },
  20630. isStream: true
  20631. };
  20632. return Stream;
  20633. })();
  20634. var StringStream = (function StringStreamClosure() {
  20635. function StringStream(str) {
  20636. var length = str.length;
  20637. var bytes = new Uint8Array(length);
  20638. for (var n = 0; n < length; ++n) {
  20639. bytes[n] = str.charCodeAt(n);
  20640. }
  20641. Stream.call(this, bytes);
  20642. }
  20643. StringStream.prototype = Stream.prototype;
  20644. return StringStream;
  20645. })();
  20646. // super class for the decoding streams
  20647. var DecodeStream = (function DecodeStreamClosure() {
  20648. // Lots of DecodeStreams are created whose buffers are never used. For these
  20649. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20650. // having special cases that would be required if we used |null| for an empty
  20651. // buffer.
  20652. var emptyBuffer = new Uint8Array(0);
  20653. function DecodeStream(maybeMinBufferLength) {
  20654. this.pos = 0;
  20655. this.bufferLength = 0;
  20656. this.eof = false;
  20657. this.buffer = emptyBuffer;
  20658. this.minBufferLength = 512;
  20659. if (maybeMinBufferLength) {
  20660. // Compute the first power of two that is as big as maybeMinBufferLength.
  20661. while (this.minBufferLength < maybeMinBufferLength) {
  20662. this.minBufferLength *= 2;
  20663. }
  20664. }
  20665. }
  20666. DecodeStream.prototype = {
  20667. get isEmpty() {
  20668. while (!this.eof && this.bufferLength === 0) {
  20669. this.readBlock();
  20670. }
  20671. return this.bufferLength === 0;
  20672. },
  20673. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20674. var buffer = this.buffer;
  20675. if (requested <= buffer.byteLength) {
  20676. return buffer;
  20677. }
  20678. var size = this.minBufferLength;
  20679. while (size < requested) {
  20680. size *= 2;
  20681. }
  20682. var buffer2 = new Uint8Array(size);
  20683. buffer2.set(buffer);
  20684. return (this.buffer = buffer2);
  20685. },
  20686. getByte: function DecodeStream_getByte() {
  20687. var pos = this.pos;
  20688. while (this.bufferLength <= pos) {
  20689. if (this.eof) {
  20690. return -1;
  20691. }
  20692. this.readBlock();
  20693. }
  20694. return this.buffer[this.pos++];
  20695. },
  20696. getUint16: function DecodeStream_getUint16() {
  20697. var b0 = this.getByte();
  20698. var b1 = this.getByte();
  20699. if (b0 === -1 || b1 === -1) {
  20700. return -1;
  20701. }
  20702. return (b0 << 8) + b1;
  20703. },
  20704. getInt32: function DecodeStream_getInt32() {
  20705. var b0 = this.getByte();
  20706. var b1 = this.getByte();
  20707. var b2 = this.getByte();
  20708. var b3 = this.getByte();
  20709. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20710. },
  20711. getBytes: function DecodeStream_getBytes(length) {
  20712. var end, pos = this.pos;
  20713. if (length) {
  20714. this.ensureBuffer(pos + length);
  20715. end = pos + length;
  20716. while (!this.eof && this.bufferLength < end) {
  20717. this.readBlock();
  20718. }
  20719. var bufEnd = this.bufferLength;
  20720. if (end > bufEnd) {
  20721. end = bufEnd;
  20722. }
  20723. } else {
  20724. while (!this.eof) {
  20725. this.readBlock();
  20726. }
  20727. end = this.bufferLength;
  20728. }
  20729. this.pos = end;
  20730. return this.buffer.subarray(pos, end);
  20731. },
  20732. peekByte: function DecodeStream_peekByte() {
  20733. var peekedByte = this.getByte();
  20734. this.pos--;
  20735. return peekedByte;
  20736. },
  20737. peekBytes: function DecodeStream_peekBytes(length) {
  20738. var bytes = this.getBytes(length);
  20739. this.pos -= bytes.length;
  20740. return bytes;
  20741. },
  20742. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20743. var end = start + length;
  20744. while (this.bufferLength <= end && !this.eof) {
  20745. this.readBlock();
  20746. }
  20747. return new Stream(this.buffer, start, length, dict);
  20748. },
  20749. skip: function DecodeStream_skip(n) {
  20750. if (!n) {
  20751. n = 1;
  20752. }
  20753. this.pos += n;
  20754. },
  20755. reset: function DecodeStream_reset() {
  20756. this.pos = 0;
  20757. },
  20758. getBaseStreams: function DecodeStream_getBaseStreams() {
  20759. if (this.str && this.str.getBaseStreams) {
  20760. return this.str.getBaseStreams();
  20761. }
  20762. return [];
  20763. }
  20764. };
  20765. return DecodeStream;
  20766. })();
  20767. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20768. function StreamsSequenceStream(streams) {
  20769. this.streams = streams;
  20770. DecodeStream.call(this, /* maybeLength = */ null);
  20771. }
  20772. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20773. StreamsSequenceStream.prototype.readBlock =
  20774. function streamSequenceStreamReadBlock() {
  20775. var streams = this.streams;
  20776. if (streams.length === 0) {
  20777. this.eof = true;
  20778. return;
  20779. }
  20780. var stream = streams.shift();
  20781. var chunk = stream.getBytes();
  20782. var bufferLength = this.bufferLength;
  20783. var newLength = bufferLength + chunk.length;
  20784. var buffer = this.ensureBuffer(newLength);
  20785. buffer.set(chunk, bufferLength);
  20786. this.bufferLength = newLength;
  20787. };
  20788. StreamsSequenceStream.prototype.getBaseStreams =
  20789. function StreamsSequenceStream_getBaseStreams() {
  20790. var baseStreams = [];
  20791. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20792. var stream = this.streams[i];
  20793. if (stream.getBaseStreams) {
  20794. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20795. }
  20796. }
  20797. return baseStreams;
  20798. };
  20799. return StreamsSequenceStream;
  20800. })();
  20801. var FlateStream = (function FlateStreamClosure() {
  20802. var codeLenCodeMap = new Int32Array([
  20803. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20804. ]);
  20805. var lengthDecode = new Int32Array([
  20806. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20807. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20808. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20809. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20810. ]);
  20811. var distDecode = new Int32Array([
  20812. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20813. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20814. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20815. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20816. ]);
  20817. var fixedLitCodeTab = [new Int32Array([
  20818. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20819. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20820. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20821. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20822. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20823. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20824. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20825. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20826. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20827. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20828. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20829. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20830. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20831. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20832. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20833. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20834. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20835. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20836. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20837. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20838. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20839. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20840. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20841. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20842. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20843. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20844. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20845. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20846. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20847. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20848. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20849. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20850. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20851. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20852. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20853. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20854. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20855. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20856. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20857. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20858. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20859. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20860. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20861. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20862. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20863. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20864. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20865. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20866. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20867. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20868. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20869. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20870. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20871. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20872. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20873. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20874. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20875. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20876. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20877. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20878. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20879. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20880. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20881. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20882. ]), 9];
  20883. var fixedDistCodeTab = [new Int32Array([
  20884. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20885. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20886. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20887. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  20888. ]), 5];
  20889. function FlateStream(str, maybeLength) {
  20890. this.str = str;
  20891. this.dict = str.dict;
  20892. var cmf = str.getByte();
  20893. var flg = str.getByte();
  20894. if (cmf === -1 || flg === -1) {
  20895. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  20896. }
  20897. if ((cmf & 0x0f) !== 0x08) {
  20898. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  20899. }
  20900. if ((((cmf << 8) + flg) % 31) !== 0) {
  20901. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  20902. }
  20903. if (flg & 0x20) {
  20904. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  20905. }
  20906. this.codeSize = 0;
  20907. this.codeBuf = 0;
  20908. DecodeStream.call(this, maybeLength);
  20909. }
  20910. FlateStream.prototype = Object.create(DecodeStream.prototype);
  20911. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  20912. var str = this.str;
  20913. var codeSize = this.codeSize;
  20914. var codeBuf = this.codeBuf;
  20915. var b;
  20916. while (codeSize < bits) {
  20917. if ((b = str.getByte()) === -1) {
  20918. error('Bad encoding in flate stream');
  20919. }
  20920. codeBuf |= b << codeSize;
  20921. codeSize += 8;
  20922. }
  20923. b = codeBuf & ((1 << bits) - 1);
  20924. this.codeBuf = codeBuf >> bits;
  20925. this.codeSize = codeSize -= bits;
  20926. return b;
  20927. };
  20928. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  20929. var str = this.str;
  20930. var codes = table[0];
  20931. var maxLen = table[1];
  20932. var codeSize = this.codeSize;
  20933. var codeBuf = this.codeBuf;
  20934. var b;
  20935. while (codeSize < maxLen) {
  20936. if ((b = str.getByte()) === -1) {
  20937. // premature end of stream. code might however still be valid.
  20938. // codeSize < codeLen check below guards against incomplete codeVal.
  20939. break;
  20940. }
  20941. codeBuf |= (b << codeSize);
  20942. codeSize += 8;
  20943. }
  20944. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  20945. var codeLen = code >> 16;
  20946. var codeVal = code & 0xffff;
  20947. if (codeLen < 1 || codeSize < codeLen) {
  20948. error('Bad encoding in flate stream');
  20949. }
  20950. this.codeBuf = (codeBuf >> codeLen);
  20951. this.codeSize = (codeSize - codeLen);
  20952. return codeVal;
  20953. };
  20954. FlateStream.prototype.generateHuffmanTable =
  20955. function flateStreamGenerateHuffmanTable(lengths) {
  20956. var n = lengths.length;
  20957. // find max code length
  20958. var maxLen = 0;
  20959. var i;
  20960. for (i = 0; i < n; ++i) {
  20961. if (lengths[i] > maxLen) {
  20962. maxLen = lengths[i];
  20963. }
  20964. }
  20965. // build the table
  20966. var size = 1 << maxLen;
  20967. var codes = new Int32Array(size);
  20968. for (var len = 1, code = 0, skip = 2;
  20969. len <= maxLen;
  20970. ++len, code <<= 1, skip <<= 1) {
  20971. for (var val = 0; val < n; ++val) {
  20972. if (lengths[val] === len) {
  20973. // bit-reverse the code
  20974. var code2 = 0;
  20975. var t = code;
  20976. for (i = 0; i < len; ++i) {
  20977. code2 = (code2 << 1) | (t & 1);
  20978. t >>= 1;
  20979. }
  20980. // fill the table entries
  20981. for (i = code2; i < size; i += skip) {
  20982. codes[i] = (len << 16) | val;
  20983. }
  20984. ++code;
  20985. }
  20986. }
  20987. }
  20988. return [codes, maxLen];
  20989. };
  20990. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  20991. var buffer, len;
  20992. var str = this.str;
  20993. // read block header
  20994. var hdr = this.getBits(3);
  20995. if (hdr & 1) {
  20996. this.eof = true;
  20997. }
  20998. hdr >>= 1;
  20999. if (hdr === 0) { // uncompressed block
  21000. var b;
  21001. if ((b = str.getByte()) === -1) {
  21002. error('Bad block header in flate stream');
  21003. }
  21004. var blockLen = b;
  21005. if ((b = str.getByte()) === -1) {
  21006. error('Bad block header in flate stream');
  21007. }
  21008. blockLen |= (b << 8);
  21009. if ((b = str.getByte()) === -1) {
  21010. error('Bad block header in flate stream');
  21011. }
  21012. var check = b;
  21013. if ((b = str.getByte()) === -1) {
  21014. error('Bad block header in flate stream');
  21015. }
  21016. check |= (b << 8);
  21017. if (check !== (~blockLen & 0xffff) &&
  21018. (blockLen !== 0 || check !== 0)) {
  21019. // Ignoring error for bad "empty" block (see issue 1277)
  21020. error('Bad uncompressed block length in flate stream');
  21021. }
  21022. this.codeBuf = 0;
  21023. this.codeSize = 0;
  21024. var bufferLength = this.bufferLength;
  21025. buffer = this.ensureBuffer(bufferLength + blockLen);
  21026. var end = bufferLength + blockLen;
  21027. this.bufferLength = end;
  21028. if (blockLen === 0) {
  21029. if (str.peekByte() === -1) {
  21030. this.eof = true;
  21031. }
  21032. } else {
  21033. for (var n = bufferLength; n < end; ++n) {
  21034. if ((b = str.getByte()) === -1) {
  21035. this.eof = true;
  21036. break;
  21037. }
  21038. buffer[n] = b;
  21039. }
  21040. }
  21041. return;
  21042. }
  21043. var litCodeTable;
  21044. var distCodeTable;
  21045. if (hdr === 1) { // compressed block, fixed codes
  21046. litCodeTable = fixedLitCodeTab;
  21047. distCodeTable = fixedDistCodeTab;
  21048. } else if (hdr === 2) { // compressed block, dynamic codes
  21049. var numLitCodes = this.getBits(5) + 257;
  21050. var numDistCodes = this.getBits(5) + 1;
  21051. var numCodeLenCodes = this.getBits(4) + 4;
  21052. // build the code lengths code table
  21053. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  21054. var i;
  21055. for (i = 0; i < numCodeLenCodes; ++i) {
  21056. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  21057. }
  21058. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  21059. // build the literal and distance code tables
  21060. len = 0;
  21061. i = 0;
  21062. var codes = numLitCodes + numDistCodes;
  21063. var codeLengths = new Uint8Array(codes);
  21064. var bitsLength, bitsOffset, what;
  21065. while (i < codes) {
  21066. var code = this.getCode(codeLenCodeTab);
  21067. if (code === 16) {
  21068. bitsLength = 2; bitsOffset = 3; what = len;
  21069. } else if (code === 17) {
  21070. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  21071. } else if (code === 18) {
  21072. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  21073. } else {
  21074. codeLengths[i++] = len = code;
  21075. continue;
  21076. }
  21077. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  21078. while (repeatLength-- > 0) {
  21079. codeLengths[i++] = what;
  21080. }
  21081. }
  21082. litCodeTable =
  21083. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  21084. distCodeTable =
  21085. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  21086. } else {
  21087. error('Unknown block type in flate stream');
  21088. }
  21089. buffer = this.buffer;
  21090. var limit = buffer ? buffer.length : 0;
  21091. var pos = this.bufferLength;
  21092. while (true) {
  21093. var code1 = this.getCode(litCodeTable);
  21094. if (code1 < 256) {
  21095. if (pos + 1 >= limit) {
  21096. buffer = this.ensureBuffer(pos + 1);
  21097. limit = buffer.length;
  21098. }
  21099. buffer[pos++] = code1;
  21100. continue;
  21101. }
  21102. if (code1 === 256) {
  21103. this.bufferLength = pos;
  21104. return;
  21105. }
  21106. code1 -= 257;
  21107. code1 = lengthDecode[code1];
  21108. var code2 = code1 >> 16;
  21109. if (code2 > 0) {
  21110. code2 = this.getBits(code2);
  21111. }
  21112. len = (code1 & 0xffff) + code2;
  21113. code1 = this.getCode(distCodeTable);
  21114. code1 = distDecode[code1];
  21115. code2 = code1 >> 16;
  21116. if (code2 > 0) {
  21117. code2 = this.getBits(code2);
  21118. }
  21119. var dist = (code1 & 0xffff) + code2;
  21120. if (pos + len >= limit) {
  21121. buffer = this.ensureBuffer(pos + len);
  21122. limit = buffer.length;
  21123. }
  21124. for (var k = 0; k < len; ++k, ++pos) {
  21125. buffer[pos] = buffer[pos - dist];
  21126. }
  21127. }
  21128. };
  21129. return FlateStream;
  21130. })();
  21131. var PredictorStream = (function PredictorStreamClosure() {
  21132. function PredictorStream(str, maybeLength, params) {
  21133. if (!isDict(params)) {
  21134. return str; // no prediction
  21135. }
  21136. var predictor = this.predictor = params.get('Predictor') || 1;
  21137. if (predictor <= 1) {
  21138. return str; // no prediction
  21139. }
  21140. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  21141. error('Unsupported predictor: ' + predictor);
  21142. }
  21143. if (predictor === 2) {
  21144. this.readBlock = this.readBlockTiff;
  21145. } else {
  21146. this.readBlock = this.readBlockPng;
  21147. }
  21148. this.str = str;
  21149. this.dict = str.dict;
  21150. var colors = this.colors = params.get('Colors') || 1;
  21151. var bits = this.bits = params.get('BitsPerComponent') || 8;
  21152. var columns = this.columns = params.get('Columns') || 1;
  21153. this.pixBytes = (colors * bits + 7) >> 3;
  21154. this.rowBytes = (columns * colors * bits + 7) >> 3;
  21155. DecodeStream.call(this, maybeLength);
  21156. return this;
  21157. }
  21158. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  21159. PredictorStream.prototype.readBlockTiff =
  21160. function predictorStreamReadBlockTiff() {
  21161. var rowBytes = this.rowBytes;
  21162. var bufferLength = this.bufferLength;
  21163. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21164. var bits = this.bits;
  21165. var colors = this.colors;
  21166. var rawBytes = this.str.getBytes(rowBytes);
  21167. this.eof = !rawBytes.length;
  21168. if (this.eof) {
  21169. return;
  21170. }
  21171. var inbuf = 0, outbuf = 0;
  21172. var inbits = 0, outbits = 0;
  21173. var pos = bufferLength;
  21174. var i;
  21175. if (bits === 1) {
  21176. for (i = 0; i < rowBytes; ++i) {
  21177. var c = rawBytes[i];
  21178. inbuf = (inbuf << 8) | c;
  21179. // bitwise addition is exclusive or
  21180. // first shift inbuf and then add
  21181. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  21182. // truncate inbuf (assumes colors < 16)
  21183. inbuf &= 0xFFFF;
  21184. }
  21185. } else if (bits === 8) {
  21186. for (i = 0; i < colors; ++i) {
  21187. buffer[pos++] = rawBytes[i];
  21188. }
  21189. for (; i < rowBytes; ++i) {
  21190. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  21191. pos++;
  21192. }
  21193. } else {
  21194. var compArray = new Uint8Array(colors + 1);
  21195. var bitMask = (1 << bits) - 1;
  21196. var j = 0, k = bufferLength;
  21197. var columns = this.columns;
  21198. for (i = 0; i < columns; ++i) {
  21199. for (var kk = 0; kk < colors; ++kk) {
  21200. if (inbits < bits) {
  21201. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21202. inbits += 8;
  21203. }
  21204. compArray[kk] = (compArray[kk] +
  21205. (inbuf >> (inbits - bits))) & bitMask;
  21206. inbits -= bits;
  21207. outbuf = (outbuf << bits) | compArray[kk];
  21208. outbits += bits;
  21209. if (outbits >= 8) {
  21210. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21211. outbits -= 8;
  21212. }
  21213. }
  21214. }
  21215. if (outbits > 0) {
  21216. buffer[k++] = (outbuf << (8 - outbits)) +
  21217. (inbuf & ((1 << (8 - outbits)) - 1));
  21218. }
  21219. }
  21220. this.bufferLength += rowBytes;
  21221. };
  21222. PredictorStream.prototype.readBlockPng =
  21223. function predictorStreamReadBlockPng() {
  21224. var rowBytes = this.rowBytes;
  21225. var pixBytes = this.pixBytes;
  21226. var predictor = this.str.getByte();
  21227. var rawBytes = this.str.getBytes(rowBytes);
  21228. this.eof = !rawBytes.length;
  21229. if (this.eof) {
  21230. return;
  21231. }
  21232. var bufferLength = this.bufferLength;
  21233. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21234. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21235. if (prevRow.length === 0) {
  21236. prevRow = new Uint8Array(rowBytes);
  21237. }
  21238. var i, j = bufferLength, up, c;
  21239. switch (predictor) {
  21240. case 0:
  21241. for (i = 0; i < rowBytes; ++i) {
  21242. buffer[j++] = rawBytes[i];
  21243. }
  21244. break;
  21245. case 1:
  21246. for (i = 0; i < pixBytes; ++i) {
  21247. buffer[j++] = rawBytes[i];
  21248. }
  21249. for (; i < rowBytes; ++i) {
  21250. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21251. j++;
  21252. }
  21253. break;
  21254. case 2:
  21255. for (i = 0; i < rowBytes; ++i) {
  21256. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21257. }
  21258. break;
  21259. case 3:
  21260. for (i = 0; i < pixBytes; ++i) {
  21261. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21262. }
  21263. for (; i < rowBytes; ++i) {
  21264. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21265. rawBytes[i]) & 0xFF;
  21266. j++;
  21267. }
  21268. break;
  21269. case 4:
  21270. // we need to save the up left pixels values. the simplest way
  21271. // is to create a new buffer
  21272. for (i = 0; i < pixBytes; ++i) {
  21273. up = prevRow[i];
  21274. c = rawBytes[i];
  21275. buffer[j++] = up + c;
  21276. }
  21277. for (; i < rowBytes; ++i) {
  21278. up = prevRow[i];
  21279. var upLeft = prevRow[i - pixBytes];
  21280. var left = buffer[j - pixBytes];
  21281. var p = left + up - upLeft;
  21282. var pa = p - left;
  21283. if (pa < 0) {
  21284. pa = -pa;
  21285. }
  21286. var pb = p - up;
  21287. if (pb < 0) {
  21288. pb = -pb;
  21289. }
  21290. var pc = p - upLeft;
  21291. if (pc < 0) {
  21292. pc = -pc;
  21293. }
  21294. c = rawBytes[i];
  21295. if (pa <= pb && pa <= pc) {
  21296. buffer[j++] = left + c;
  21297. } else if (pb <= pc) {
  21298. buffer[j++] = up + c;
  21299. } else {
  21300. buffer[j++] = upLeft + c;
  21301. }
  21302. }
  21303. break;
  21304. default:
  21305. error('Unsupported predictor: ' + predictor);
  21306. }
  21307. this.bufferLength += rowBytes;
  21308. };
  21309. return PredictorStream;
  21310. })();
  21311. /**
  21312. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21313. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21314. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21315. * a library to decode these images and the stream behaves like all the other
  21316. * DecodeStreams.
  21317. */
  21318. var JpegStream = (function JpegStreamClosure() {
  21319. function JpegStream(stream, maybeLength, dict, xref) {
  21320. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21321. // Note: this seems to mainly affect inline images.
  21322. var ch;
  21323. while ((ch = stream.getByte()) !== -1) {
  21324. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21325. stream.skip(-1); // Reset the stream position to the SOI.
  21326. break;
  21327. }
  21328. }
  21329. this.stream = stream;
  21330. this.maybeLength = maybeLength;
  21331. this.dict = dict;
  21332. DecodeStream.call(this, maybeLength);
  21333. }
  21334. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21335. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21336. get: function JpegStream_bytes() {
  21337. // If this.maybeLength is null, we'll get the entire stream.
  21338. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21339. },
  21340. configurable: true
  21341. });
  21342. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21343. if (this.bufferLength) {
  21344. return;
  21345. }
  21346. try {
  21347. var jpegImage = new JpegImage();
  21348. // checking if values needs to be transformed before conversion
  21349. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  21350. var decodeArr = this.dict.getArray('Decode');
  21351. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21352. var decodeArrLength = decodeArr.length;
  21353. var transform = new Int32Array(decodeArrLength);
  21354. var transformNeeded = false;
  21355. var maxValue = (1 << bitsPerComponent) - 1;
  21356. for (var i = 0; i < decodeArrLength; i += 2) {
  21357. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21358. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21359. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21360. transformNeeded = true;
  21361. }
  21362. }
  21363. if (transformNeeded) {
  21364. jpegImage.decodeTransform = transform;
  21365. }
  21366. }
  21367. jpegImage.parse(this.bytes);
  21368. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21369. this.forceRGB);
  21370. this.buffer = data;
  21371. this.bufferLength = data.length;
  21372. this.eof = true;
  21373. } catch (e) {
  21374. error('JPEG error: ' + e);
  21375. }
  21376. };
  21377. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21378. this.ensureBuffer();
  21379. return this.buffer;
  21380. };
  21381. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  21382. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  21383. };
  21384. return JpegStream;
  21385. })();
  21386. /**
  21387. * For JPEG 2000's we use a library to decode these images and
  21388. * the stream behaves like all the other DecodeStreams.
  21389. */
  21390. var JpxStream = (function JpxStreamClosure() {
  21391. function JpxStream(stream, maybeLength, dict) {
  21392. this.stream = stream;
  21393. this.maybeLength = maybeLength;
  21394. this.dict = dict;
  21395. DecodeStream.call(this, maybeLength);
  21396. }
  21397. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21398. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21399. get: function JpxStream_bytes() {
  21400. // If this.maybeLength is null, we'll get the entire stream.
  21401. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21402. },
  21403. configurable: true
  21404. });
  21405. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21406. if (this.bufferLength) {
  21407. return;
  21408. }
  21409. var jpxImage = new JpxImage();
  21410. jpxImage.parse(this.bytes);
  21411. var width = jpxImage.width;
  21412. var height = jpxImage.height;
  21413. var componentsCount = jpxImage.componentsCount;
  21414. var tileCount = jpxImage.tiles.length;
  21415. if (tileCount === 1) {
  21416. this.buffer = jpxImage.tiles[0].items;
  21417. } else {
  21418. var data = new Uint8Array(width * height * componentsCount);
  21419. for (var k = 0; k < tileCount; k++) {
  21420. var tileComponents = jpxImage.tiles[k];
  21421. var tileWidth = tileComponents.width;
  21422. var tileHeight = tileComponents.height;
  21423. var tileLeft = tileComponents.left;
  21424. var tileTop = tileComponents.top;
  21425. var src = tileComponents.items;
  21426. var srcPosition = 0;
  21427. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21428. var imgRowSize = width * componentsCount;
  21429. var tileRowSize = tileWidth * componentsCount;
  21430. for (var j = 0; j < tileHeight; j++) {
  21431. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21432. data.set(rowBytes, dataPosition);
  21433. srcPosition += tileRowSize;
  21434. dataPosition += imgRowSize;
  21435. }
  21436. }
  21437. this.buffer = data;
  21438. }
  21439. this.bufferLength = this.buffer.length;
  21440. this.eof = true;
  21441. };
  21442. return JpxStream;
  21443. })();
  21444. /**
  21445. * For JBIG2's we use a library to decode these images and
  21446. * the stream behaves like all the other DecodeStreams.
  21447. */
  21448. var Jbig2Stream = (function Jbig2StreamClosure() {
  21449. function Jbig2Stream(stream, maybeLength, dict) {
  21450. this.stream = stream;
  21451. this.maybeLength = maybeLength;
  21452. this.dict = dict;
  21453. DecodeStream.call(this, maybeLength);
  21454. }
  21455. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21456. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21457. get: function Jbig2Stream_bytes() {
  21458. // If this.maybeLength is null, we'll get the entire stream.
  21459. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21460. },
  21461. configurable: true
  21462. });
  21463. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21464. if (this.bufferLength) {
  21465. return;
  21466. }
  21467. var jbig2Image = new Jbig2Image();
  21468. var chunks = [];
  21469. var decodeParams = this.dict.getArray('DecodeParms');
  21470. // According to the PDF specification, DecodeParms can be either
  21471. // a dictionary, or an array whose elements are dictionaries.
  21472. if (isArray(decodeParams)) {
  21473. if (decodeParams.length > 1) {
  21474. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21475. 'not supported.');
  21476. }
  21477. decodeParams = decodeParams[0];
  21478. }
  21479. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21480. var globalsStream = decodeParams.get('JBIG2Globals');
  21481. var globals = globalsStream.getBytes();
  21482. chunks.push({data: globals, start: 0, end: globals.length});
  21483. }
  21484. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21485. var data = jbig2Image.parseChunks(chunks);
  21486. var dataLength = data.length;
  21487. // JBIG2 had black as 1 and white as 0, inverting the colors
  21488. for (var i = 0; i < dataLength; i++) {
  21489. data[i] ^= 0xFF;
  21490. }
  21491. this.buffer = data;
  21492. this.bufferLength = dataLength;
  21493. this.eof = true;
  21494. };
  21495. return Jbig2Stream;
  21496. })();
  21497. var DecryptStream = (function DecryptStreamClosure() {
  21498. function DecryptStream(str, maybeLength, decrypt) {
  21499. this.str = str;
  21500. this.dict = str.dict;
  21501. this.decrypt = decrypt;
  21502. this.nextChunk = null;
  21503. this.initialized = false;
  21504. DecodeStream.call(this, maybeLength);
  21505. }
  21506. var chunkSize = 512;
  21507. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21508. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21509. var chunk;
  21510. if (this.initialized) {
  21511. chunk = this.nextChunk;
  21512. } else {
  21513. chunk = this.str.getBytes(chunkSize);
  21514. this.initialized = true;
  21515. }
  21516. if (!chunk || chunk.length === 0) {
  21517. this.eof = true;
  21518. return;
  21519. }
  21520. this.nextChunk = this.str.getBytes(chunkSize);
  21521. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21522. var decrypt = this.decrypt;
  21523. chunk = decrypt(chunk, !hasMoreData);
  21524. var bufferLength = this.bufferLength;
  21525. var i, n = chunk.length;
  21526. var buffer = this.ensureBuffer(bufferLength + n);
  21527. for (i = 0; i < n; i++) {
  21528. buffer[bufferLength++] = chunk[i];
  21529. }
  21530. this.bufferLength = bufferLength;
  21531. };
  21532. return DecryptStream;
  21533. })();
  21534. var Ascii85Stream = (function Ascii85StreamClosure() {
  21535. function Ascii85Stream(str, maybeLength) {
  21536. this.str = str;
  21537. this.dict = str.dict;
  21538. this.input = new Uint8Array(5);
  21539. // Most streams increase in size when decoded, but Ascii85 streams
  21540. // typically shrink by ~20%.
  21541. if (maybeLength) {
  21542. maybeLength = 0.8 * maybeLength;
  21543. }
  21544. DecodeStream.call(this, maybeLength);
  21545. }
  21546. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21547. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21548. var TILDA_CHAR = 0x7E; // '~'
  21549. var Z_LOWER_CHAR = 0x7A; // 'z'
  21550. var EOF = -1;
  21551. var str = this.str;
  21552. var c = str.getByte();
  21553. while (isSpace(c)) {
  21554. c = str.getByte();
  21555. }
  21556. if (c === EOF || c === TILDA_CHAR) {
  21557. this.eof = true;
  21558. return;
  21559. }
  21560. var bufferLength = this.bufferLength, buffer;
  21561. var i;
  21562. // special code for z
  21563. if (c === Z_LOWER_CHAR) {
  21564. buffer = this.ensureBuffer(bufferLength + 4);
  21565. for (i = 0; i < 4; ++i) {
  21566. buffer[bufferLength + i] = 0;
  21567. }
  21568. this.bufferLength += 4;
  21569. } else {
  21570. var input = this.input;
  21571. input[0] = c;
  21572. for (i = 1; i < 5; ++i) {
  21573. c = str.getByte();
  21574. while (isSpace(c)) {
  21575. c = str.getByte();
  21576. }
  21577. input[i] = c;
  21578. if (c === EOF || c === TILDA_CHAR) {
  21579. break;
  21580. }
  21581. }
  21582. buffer = this.ensureBuffer(bufferLength + i - 1);
  21583. this.bufferLength += i - 1;
  21584. // partial ending;
  21585. if (i < 5) {
  21586. for (; i < 5; ++i) {
  21587. input[i] = 0x21 + 84;
  21588. }
  21589. this.eof = true;
  21590. }
  21591. var t = 0;
  21592. for (i = 0; i < 5; ++i) {
  21593. t = t * 85 + (input[i] - 0x21);
  21594. }
  21595. for (i = 3; i >= 0; --i) {
  21596. buffer[bufferLength + i] = t & 0xFF;
  21597. t >>= 8;
  21598. }
  21599. }
  21600. };
  21601. return Ascii85Stream;
  21602. })();
  21603. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21604. function AsciiHexStream(str, maybeLength) {
  21605. this.str = str;
  21606. this.dict = str.dict;
  21607. this.firstDigit = -1;
  21608. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21609. // by 50%.
  21610. if (maybeLength) {
  21611. maybeLength = 0.5 * maybeLength;
  21612. }
  21613. DecodeStream.call(this, maybeLength);
  21614. }
  21615. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21616. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21617. var UPSTREAM_BLOCK_SIZE = 8000;
  21618. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21619. if (!bytes.length) {
  21620. this.eof = true;
  21621. return;
  21622. }
  21623. var maxDecodeLength = (bytes.length + 1) >> 1;
  21624. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21625. var bufferLength = this.bufferLength;
  21626. var firstDigit = this.firstDigit;
  21627. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21628. var ch = bytes[i], digit;
  21629. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21630. digit = ch & 0x0F;
  21631. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21632. // 'A'-'Z', 'a'-'z'
  21633. digit = (ch & 0x0F) + 9;
  21634. } else if (ch === 0x3E) { // '>'
  21635. this.eof = true;
  21636. break;
  21637. } else { // probably whitespace
  21638. continue; // ignoring
  21639. }
  21640. if (firstDigit < 0) {
  21641. firstDigit = digit;
  21642. } else {
  21643. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21644. firstDigit = -1;
  21645. }
  21646. }
  21647. if (firstDigit >= 0 && this.eof) {
  21648. // incomplete byte
  21649. buffer[bufferLength++] = (firstDigit << 4);
  21650. firstDigit = -1;
  21651. }
  21652. this.firstDigit = firstDigit;
  21653. this.bufferLength = bufferLength;
  21654. };
  21655. return AsciiHexStream;
  21656. })();
  21657. var RunLengthStream = (function RunLengthStreamClosure() {
  21658. function RunLengthStream(str, maybeLength) {
  21659. this.str = str;
  21660. this.dict = str.dict;
  21661. DecodeStream.call(this, maybeLength);
  21662. }
  21663. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21664. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21665. // The repeatHeader has following format. The first byte defines type of run
  21666. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21667. // (in addition to the second byte from the header), n = 129 through 255 -
  21668. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21669. var repeatHeader = this.str.getBytes(2);
  21670. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21671. this.eof = true;
  21672. return;
  21673. }
  21674. var buffer;
  21675. var bufferLength = this.bufferLength;
  21676. var n = repeatHeader[0];
  21677. if (n < 128) {
  21678. // copy n bytes
  21679. buffer = this.ensureBuffer(bufferLength + n + 1);
  21680. buffer[bufferLength++] = repeatHeader[1];
  21681. if (n > 0) {
  21682. var source = this.str.getBytes(n);
  21683. buffer.set(source, bufferLength);
  21684. bufferLength += n;
  21685. }
  21686. } else {
  21687. n = 257 - n;
  21688. var b = repeatHeader[1];
  21689. buffer = this.ensureBuffer(bufferLength + n + 1);
  21690. for (var i = 0; i < n; i++) {
  21691. buffer[bufferLength++] = b;
  21692. }
  21693. }
  21694. this.bufferLength = bufferLength;
  21695. };
  21696. return RunLengthStream;
  21697. })();
  21698. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21699. var ccittEOL = -2;
  21700. var ccittEOF = -1;
  21701. var twoDimPass = 0;
  21702. var twoDimHoriz = 1;
  21703. var twoDimVert0 = 2;
  21704. var twoDimVertR1 = 3;
  21705. var twoDimVertL1 = 4;
  21706. var twoDimVertR2 = 5;
  21707. var twoDimVertL2 = 6;
  21708. var twoDimVertR3 = 7;
  21709. var twoDimVertL3 = 8;
  21710. var twoDimTable = [
  21711. [-1, -1], [-1, -1], // 000000x
  21712. [7, twoDimVertL3], // 0000010
  21713. [7, twoDimVertR3], // 0000011
  21714. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21715. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21716. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21717. [4, twoDimPass], [4, twoDimPass],
  21718. [4, twoDimPass], [4, twoDimPass],
  21719. [4, twoDimPass], [4, twoDimPass],
  21720. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21721. [3, twoDimHoriz], [3, twoDimHoriz],
  21722. [3, twoDimHoriz], [3, twoDimHoriz],
  21723. [3, twoDimHoriz], [3, twoDimHoriz],
  21724. [3, twoDimHoriz], [3, twoDimHoriz],
  21725. [3, twoDimHoriz], [3, twoDimHoriz],
  21726. [3, twoDimHoriz], [3, twoDimHoriz],
  21727. [3, twoDimHoriz], [3, twoDimHoriz],
  21728. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21729. [3, twoDimVertL1], [3, twoDimVertL1],
  21730. [3, twoDimVertL1], [3, twoDimVertL1],
  21731. [3, twoDimVertL1], [3, twoDimVertL1],
  21732. [3, twoDimVertL1], [3, twoDimVertL1],
  21733. [3, twoDimVertL1], [3, twoDimVertL1],
  21734. [3, twoDimVertL1], [3, twoDimVertL1],
  21735. [3, twoDimVertL1], [3, twoDimVertL1],
  21736. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21737. [3, twoDimVertR1], [3, twoDimVertR1],
  21738. [3, twoDimVertR1], [3, twoDimVertR1],
  21739. [3, twoDimVertR1], [3, twoDimVertR1],
  21740. [3, twoDimVertR1], [3, twoDimVertR1],
  21741. [3, twoDimVertR1], [3, twoDimVertR1],
  21742. [3, twoDimVertR1], [3, twoDimVertR1],
  21743. [3, twoDimVertR1], [3, twoDimVertR1],
  21744. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21745. [1, twoDimVert0], [1, twoDimVert0],
  21746. [1, twoDimVert0], [1, twoDimVert0],
  21747. [1, twoDimVert0], [1, twoDimVert0],
  21748. [1, twoDimVert0], [1, twoDimVert0],
  21749. [1, twoDimVert0], [1, twoDimVert0],
  21750. [1, twoDimVert0], [1, twoDimVert0],
  21751. [1, twoDimVert0], [1, twoDimVert0],
  21752. [1, twoDimVert0], [1, twoDimVert0],
  21753. [1, twoDimVert0], [1, twoDimVert0],
  21754. [1, twoDimVert0], [1, twoDimVert0],
  21755. [1, twoDimVert0], [1, twoDimVert0],
  21756. [1, twoDimVert0], [1, twoDimVert0],
  21757. [1, twoDimVert0], [1, twoDimVert0],
  21758. [1, twoDimVert0], [1, twoDimVert0],
  21759. [1, twoDimVert0], [1, twoDimVert0],
  21760. [1, twoDimVert0], [1, twoDimVert0],
  21761. [1, twoDimVert0], [1, twoDimVert0],
  21762. [1, twoDimVert0], [1, twoDimVert0],
  21763. [1, twoDimVert0], [1, twoDimVert0],
  21764. [1, twoDimVert0], [1, twoDimVert0],
  21765. [1, twoDimVert0], [1, twoDimVert0],
  21766. [1, twoDimVert0], [1, twoDimVert0],
  21767. [1, twoDimVert0], [1, twoDimVert0],
  21768. [1, twoDimVert0], [1, twoDimVert0],
  21769. [1, twoDimVert0], [1, twoDimVert0],
  21770. [1, twoDimVert0], [1, twoDimVert0],
  21771. [1, twoDimVert0], [1, twoDimVert0],
  21772. [1, twoDimVert0], [1, twoDimVert0],
  21773. [1, twoDimVert0], [1, twoDimVert0],
  21774. [1, twoDimVert0], [1, twoDimVert0],
  21775. [1, twoDimVert0], [1, twoDimVert0]
  21776. ];
  21777. var whiteTable1 = [
  21778. [-1, -1], // 00000
  21779. [12, ccittEOL], // 00001
  21780. [-1, -1], [-1, -1], // 0001x
  21781. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21782. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21783. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21784. [11, 1792], [11, 1792], // 1000x
  21785. [12, 1984], // 10010
  21786. [12, 2048], // 10011
  21787. [12, 2112], // 10100
  21788. [12, 2176], // 10101
  21789. [12, 2240], // 10110
  21790. [12, 2304], // 10111
  21791. [11, 1856], [11, 1856], // 1100x
  21792. [11, 1920], [11, 1920], // 1101x
  21793. [12, 2368], // 11100
  21794. [12, 2432], // 11101
  21795. [12, 2496], // 11110
  21796. [12, 2560] // 11111
  21797. ];
  21798. var whiteTable2 = [
  21799. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21800. [8, 29], [8, 29], // 00000010x
  21801. [8, 30], [8, 30], // 00000011x
  21802. [8, 45], [8, 45], // 00000100x
  21803. [8, 46], [8, 46], // 00000101x
  21804. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21805. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21806. [8, 47], [8, 47], // 00001010x
  21807. [8, 48], [8, 48], // 00001011x
  21808. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21809. [6, 13], [6, 13], [6, 13], [6, 13],
  21810. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21811. [8, 33], [8, 33], // 00010010x
  21812. [8, 34], [8, 34], // 00010011x
  21813. [8, 35], [8, 35], // 00010100x
  21814. [8, 36], [8, 36], // 00010101x
  21815. [8, 37], [8, 37], // 00010110x
  21816. [8, 38], [8, 38], // 00010111x
  21817. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21818. [8, 31], [8, 31], // 00011010x
  21819. [8, 32], [8, 32], // 00011011x
  21820. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21821. [6, 1], [6, 1], [6, 1], [6, 1],
  21822. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21823. [6, 12], [6, 12], [6, 12], [6, 12],
  21824. [8, 53], [8, 53], // 00100100x
  21825. [8, 54], [8, 54], // 00100101x
  21826. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21827. [8, 39], [8, 39], // 00101000x
  21828. [8, 40], [8, 40], // 00101001x
  21829. [8, 41], [8, 41], // 00101010x
  21830. [8, 42], [8, 42], // 00101011x
  21831. [8, 43], [8, 43], // 00101100x
  21832. [8, 44], [8, 44], // 00101101x
  21833. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21834. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21835. [8, 61], [8, 61], // 00110010x
  21836. [8, 62], [8, 62], // 00110011x
  21837. [8, 63], [8, 63], // 00110100x
  21838. [8, 0], [8, 0], // 00110101x
  21839. [8, 320], [8, 320], // 00110110x
  21840. [8, 384], [8, 384], // 00110111x
  21841. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21842. [5, 10], [5, 10], [5, 10], [5, 10],
  21843. [5, 10], [5, 10], [5, 10], [5, 10],
  21844. [5, 10], [5, 10], [5, 10], [5, 10],
  21845. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21846. [5, 11], [5, 11], [5, 11], [5, 11],
  21847. [5, 11], [5, 11], [5, 11], [5, 11],
  21848. [5, 11], [5, 11], [5, 11], [5, 11],
  21849. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21850. [8, 59], [8, 59], // 01001010x
  21851. [8, 60], [8, 60], // 01001011x
  21852. [9, 1472], // 010011000
  21853. [9, 1536], // 010011001
  21854. [9, 1600], // 010011010
  21855. [9, 1728], // 010011011
  21856. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21857. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21858. [8, 49], [8, 49], // 01010010x
  21859. [8, 50], [8, 50], // 01010011x
  21860. [8, 51], [8, 51], // 01010100x
  21861. [8, 52], [8, 52], // 01010101x
  21862. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21863. [8, 55], [8, 55], // 01011000x
  21864. [8, 56], [8, 56], // 01011001x
  21865. [8, 57], [8, 57], // 01011010x
  21866. [8, 58], [8, 58], // 01011011x
  21867. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21868. [6, 192], [6, 192], [6, 192], [6, 192],
  21869. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21870. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21871. [8, 448], [8, 448], // 01100100x
  21872. [8, 512], [8, 512], // 01100101x
  21873. [9, 704], // 011001100
  21874. [9, 768], // 011001101
  21875. [8, 640], [8, 640], // 01100111x
  21876. [8, 576], [8, 576], // 01101000x
  21877. [9, 832], // 011010010
  21878. [9, 896], // 011010011
  21879. [9, 960], // 011010100
  21880. [9, 1024], // 011010101
  21881. [9, 1088], // 011010110
  21882. [9, 1152], // 011010111
  21883. [9, 1216], // 011011000
  21884. [9, 1280], // 011011001
  21885. [9, 1344], // 011011010
  21886. [9, 1408], // 011011011
  21887. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  21888. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  21889. [4, 2], [4, 2], [4, 2], [4, 2],
  21890. [4, 2], [4, 2], [4, 2], [4, 2],
  21891. [4, 2], [4, 2], [4, 2], [4, 2],
  21892. [4, 2], [4, 2], [4, 2], [4, 2],
  21893. [4, 2], [4, 2], [4, 2], [4, 2],
  21894. [4, 2], [4, 2], [4, 2], [4, 2],
  21895. [4, 2], [4, 2], [4, 2], [4, 2],
  21896. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  21897. [4, 3], [4, 3], [4, 3], [4, 3],
  21898. [4, 3], [4, 3], [4, 3], [4, 3],
  21899. [4, 3], [4, 3], [4, 3], [4, 3],
  21900. [4, 3], [4, 3], [4, 3], [4, 3],
  21901. [4, 3], [4, 3], [4, 3], [4, 3],
  21902. [4, 3], [4, 3], [4, 3], [4, 3],
  21903. [4, 3], [4, 3], [4, 3], [4, 3],
  21904. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  21905. [5, 128], [5, 128], [5, 128], [5, 128],
  21906. [5, 128], [5, 128], [5, 128], [5, 128],
  21907. [5, 128], [5, 128], [5, 128], [5, 128],
  21908. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  21909. [5, 8], [5, 8], [5, 8], [5, 8],
  21910. [5, 8], [5, 8], [5, 8], [5, 8],
  21911. [5, 8], [5, 8], [5, 8], [5, 8],
  21912. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  21913. [5, 9], [5, 9], [5, 9], [5, 9],
  21914. [5, 9], [5, 9], [5, 9], [5, 9],
  21915. [5, 9], [5, 9], [5, 9], [5, 9],
  21916. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  21917. [6, 16], [6, 16], [6, 16], [6, 16],
  21918. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  21919. [6, 17], [6, 17], [6, 17], [6, 17],
  21920. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  21921. [4, 4], [4, 4], [4, 4], [4, 4],
  21922. [4, 4], [4, 4], [4, 4], [4, 4],
  21923. [4, 4], [4, 4], [4, 4], [4, 4],
  21924. [4, 4], [4, 4], [4, 4], [4, 4],
  21925. [4, 4], [4, 4], [4, 4], [4, 4],
  21926. [4, 4], [4, 4], [4, 4], [4, 4],
  21927. [4, 4], [4, 4], [4, 4], [4, 4],
  21928. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  21929. [4, 5], [4, 5], [4, 5], [4, 5],
  21930. [4, 5], [4, 5], [4, 5], [4, 5],
  21931. [4, 5], [4, 5], [4, 5], [4, 5],
  21932. [4, 5], [4, 5], [4, 5], [4, 5],
  21933. [4, 5], [4, 5], [4, 5], [4, 5],
  21934. [4, 5], [4, 5], [4, 5], [4, 5],
  21935. [4, 5], [4, 5], [4, 5], [4, 5],
  21936. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  21937. [6, 14], [6, 14], [6, 14], [6, 14],
  21938. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  21939. [6, 15], [6, 15], [6, 15], [6, 15],
  21940. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  21941. [5, 64], [5, 64], [5, 64], [5, 64],
  21942. [5, 64], [5, 64], [5, 64], [5, 64],
  21943. [5, 64], [5, 64], [5, 64], [5, 64],
  21944. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  21945. [4, 6], [4, 6], [4, 6], [4, 6],
  21946. [4, 6], [4, 6], [4, 6], [4, 6],
  21947. [4, 6], [4, 6], [4, 6], [4, 6],
  21948. [4, 6], [4, 6], [4, 6], [4, 6],
  21949. [4, 6], [4, 6], [4, 6], [4, 6],
  21950. [4, 6], [4, 6], [4, 6], [4, 6],
  21951. [4, 6], [4, 6], [4, 6], [4, 6],
  21952. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  21953. [4, 7], [4, 7], [4, 7], [4, 7],
  21954. [4, 7], [4, 7], [4, 7], [4, 7],
  21955. [4, 7], [4, 7], [4, 7], [4, 7],
  21956. [4, 7], [4, 7], [4, 7], [4, 7],
  21957. [4, 7], [4, 7], [4, 7], [4, 7],
  21958. [4, 7], [4, 7], [4, 7], [4, 7],
  21959. [4, 7], [4, 7], [4, 7], [4, 7]
  21960. ];
  21961. var blackTable1 = [
  21962. [-1, -1], [-1, -1], // 000000000000x
  21963. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  21964. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  21965. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  21966. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  21967. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  21968. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  21969. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  21970. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  21971. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  21972. [12, 1984], [12, 1984], // 000000010010x
  21973. [12, 2048], [12, 2048], // 000000010011x
  21974. [12, 2112], [12, 2112], // 000000010100x
  21975. [12, 2176], [12, 2176], // 000000010101x
  21976. [12, 2240], [12, 2240], // 000000010110x
  21977. [12, 2304], [12, 2304], // 000000010111x
  21978. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  21979. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  21980. [12, 2368], [12, 2368], // 000000011100x
  21981. [12, 2432], [12, 2432], // 000000011101x
  21982. [12, 2496], [12, 2496], // 000000011110x
  21983. [12, 2560], [12, 2560], // 000000011111x
  21984. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  21985. [10, 18], [10, 18], [10, 18], [10, 18],
  21986. [12, 52], [12, 52], // 000000100100x
  21987. [13, 640], // 0000001001010
  21988. [13, 704], // 0000001001011
  21989. [13, 768], // 0000001001100
  21990. [13, 832], // 0000001001101
  21991. [12, 55], [12, 55], // 000000100111x
  21992. [12, 56], [12, 56], // 000000101000x
  21993. [13, 1280], // 0000001010010
  21994. [13, 1344], // 0000001010011
  21995. [13, 1408], // 0000001010100
  21996. [13, 1472], // 0000001010101
  21997. [12, 59], [12, 59], // 000000101011x
  21998. [12, 60], [12, 60], // 000000101100x
  21999. [13, 1536], // 0000001011010
  22000. [13, 1600], // 0000001011011
  22001. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  22002. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  22003. [13, 1664], // 0000001100100
  22004. [13, 1728], // 0000001100101
  22005. [12, 320], [12, 320], // 000000110011x
  22006. [12, 384], [12, 384], // 000000110100x
  22007. [12, 448], [12, 448], // 000000110101x
  22008. [13, 512], // 0000001101100
  22009. [13, 576], // 0000001101101
  22010. [12, 53], [12, 53], // 000000110111x
  22011. [12, 54], [12, 54], // 000000111000x
  22012. [13, 896], // 0000001110010
  22013. [13, 960], // 0000001110011
  22014. [13, 1024], // 0000001110100
  22015. [13, 1088], // 0000001110101
  22016. [13, 1152], // 0000001110110
  22017. [13, 1216], // 0000001110111
  22018. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  22019. [10, 64], [10, 64], [10, 64], [10, 64]
  22020. ];
  22021. var blackTable2 = [
  22022. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  22023. [8, 13], [8, 13], [8, 13], [8, 13],
  22024. [8, 13], [8, 13], [8, 13], [8, 13],
  22025. [8, 13], [8, 13], [8, 13], [8, 13],
  22026. [11, 23], [11, 23], // 00000101000x
  22027. [12, 50], // 000001010010
  22028. [12, 51], // 000001010011
  22029. [12, 44], // 000001010100
  22030. [12, 45], // 000001010101
  22031. [12, 46], // 000001010110
  22032. [12, 47], // 000001010111
  22033. [12, 57], // 000001011000
  22034. [12, 58], // 000001011001
  22035. [12, 61], // 000001011010
  22036. [12, 256], // 000001011011
  22037. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  22038. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  22039. [12, 48], // 000001100100
  22040. [12, 49], // 000001100101
  22041. [12, 62], // 000001100110
  22042. [12, 63], // 000001100111
  22043. [12, 30], // 000001101000
  22044. [12, 31], // 000001101001
  22045. [12, 32], // 000001101010
  22046. [12, 33], // 000001101011
  22047. [12, 40], // 000001101100
  22048. [12, 41], // 000001101101
  22049. [11, 22], [11, 22], // 00000110111x
  22050. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  22051. [8, 14], [8, 14], [8, 14], [8, 14],
  22052. [8, 14], [8, 14], [8, 14], [8, 14],
  22053. [8, 14], [8, 14], [8, 14], [8, 14],
  22054. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  22055. [7, 10], [7, 10], [7, 10], [7, 10],
  22056. [7, 10], [7, 10], [7, 10], [7, 10],
  22057. [7, 10], [7, 10], [7, 10], [7, 10],
  22058. [7, 10], [7, 10], [7, 10], [7, 10],
  22059. [7, 10], [7, 10], [7, 10], [7, 10],
  22060. [7, 10], [7, 10], [7, 10], [7, 10],
  22061. [7, 10], [7, 10], [7, 10], [7, 10],
  22062. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  22063. [7, 11], [7, 11], [7, 11], [7, 11],
  22064. [7, 11], [7, 11], [7, 11], [7, 11],
  22065. [7, 11], [7, 11], [7, 11], [7, 11],
  22066. [7, 11], [7, 11], [7, 11], [7, 11],
  22067. [7, 11], [7, 11], [7, 11], [7, 11],
  22068. [7, 11], [7, 11], [7, 11], [7, 11],
  22069. [7, 11], [7, 11], [7, 11], [7, 11],
  22070. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  22071. [9, 15], [9, 15], [9, 15], [9, 15],
  22072. [12, 128], // 000011001000
  22073. [12, 192], // 000011001001
  22074. [12, 26], // 000011001010
  22075. [12, 27], // 000011001011
  22076. [12, 28], // 000011001100
  22077. [12, 29], // 000011001101
  22078. [11, 19], [11, 19], // 00001100111x
  22079. [11, 20], [11, 20], // 00001101000x
  22080. [12, 34], // 000011010010
  22081. [12, 35], // 000011010011
  22082. [12, 36], // 000011010100
  22083. [12, 37], // 000011010101
  22084. [12, 38], // 000011010110
  22085. [12, 39], // 000011010111
  22086. [11, 21], [11, 21], // 00001101100x
  22087. [12, 42], // 000011011010
  22088. [12, 43], // 000011011011
  22089. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  22090. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  22091. [7, 12], [7, 12], [7, 12], [7, 12],
  22092. [7, 12], [7, 12], [7, 12], [7, 12],
  22093. [7, 12], [7, 12], [7, 12], [7, 12],
  22094. [7, 12], [7, 12], [7, 12], [7, 12],
  22095. [7, 12], [7, 12], [7, 12], [7, 12],
  22096. [7, 12], [7, 12], [7, 12], [7, 12],
  22097. [7, 12], [7, 12], [7, 12], [7, 12]
  22098. ];
  22099. var blackTable3 = [
  22100. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  22101. [6, 9], // 000100
  22102. [6, 8], // 000101
  22103. [5, 7], [5, 7], // 00011x
  22104. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  22105. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  22106. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  22107. [3, 1], [3, 1], [3, 1], [3, 1],
  22108. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  22109. [3, 4], [3, 4], [3, 4], [3, 4],
  22110. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  22111. [2, 3], [2, 3], [2, 3], [2, 3],
  22112. [2, 3], [2, 3], [2, 3], [2, 3],
  22113. [2, 3], [2, 3], [2, 3], [2, 3],
  22114. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  22115. [2, 2], [2, 2], [2, 2], [2, 2],
  22116. [2, 2], [2, 2], [2, 2], [2, 2],
  22117. [2, 2], [2, 2], [2, 2], [2, 2]
  22118. ];
  22119. function CCITTFaxStream(str, maybeLength, params) {
  22120. this.str = str;
  22121. this.dict = str.dict;
  22122. params = params || Dict.empty;
  22123. this.encoding = params.get('K') || 0;
  22124. this.eoline = params.get('EndOfLine') || false;
  22125. this.byteAlign = params.get('EncodedByteAlign') || false;
  22126. this.columns = params.get('Columns') || 1728;
  22127. this.rows = params.get('Rows') || 0;
  22128. var eoblock = params.get('EndOfBlock');
  22129. if (eoblock === null || eoblock === undefined) {
  22130. eoblock = true;
  22131. }
  22132. this.eoblock = eoblock;
  22133. this.black = params.get('BlackIs1') || false;
  22134. this.codingLine = new Uint32Array(this.columns + 1);
  22135. this.refLine = new Uint32Array(this.columns + 2);
  22136. this.codingLine[0] = this.columns;
  22137. this.codingPos = 0;
  22138. this.row = 0;
  22139. this.nextLine2D = this.encoding < 0;
  22140. this.inputBits = 0;
  22141. this.inputBuf = 0;
  22142. this.outputBits = 0;
  22143. var code1;
  22144. while ((code1 = this.lookBits(12)) === 0) {
  22145. this.eatBits(1);
  22146. }
  22147. if (code1 === 1) {
  22148. this.eatBits(12);
  22149. }
  22150. if (this.encoding > 0) {
  22151. this.nextLine2D = !this.lookBits(1);
  22152. this.eatBits(1);
  22153. }
  22154. DecodeStream.call(this, maybeLength);
  22155. }
  22156. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  22157. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  22158. while (!this.eof) {
  22159. var c = this.lookChar();
  22160. this.ensureBuffer(this.bufferLength + 1);
  22161. this.buffer[this.bufferLength++] = c;
  22162. }
  22163. };
  22164. CCITTFaxStream.prototype.addPixels =
  22165. function ccittFaxStreamAddPixels(a1, blackPixels) {
  22166. var codingLine = this.codingLine;
  22167. var codingPos = this.codingPos;
  22168. if (a1 > codingLine[codingPos]) {
  22169. if (a1 > this.columns) {
  22170. info('row is wrong length');
  22171. this.err = true;
  22172. a1 = this.columns;
  22173. }
  22174. if ((codingPos & 1) ^ blackPixels) {
  22175. ++codingPos;
  22176. }
  22177. codingLine[codingPos] = a1;
  22178. }
  22179. this.codingPos = codingPos;
  22180. };
  22181. CCITTFaxStream.prototype.addPixelsNeg =
  22182. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22183. var codingLine = this.codingLine;
  22184. var codingPos = this.codingPos;
  22185. if (a1 > codingLine[codingPos]) {
  22186. if (a1 > this.columns) {
  22187. info('row is wrong length');
  22188. this.err = true;
  22189. a1 = this.columns;
  22190. }
  22191. if ((codingPos & 1) ^ blackPixels) {
  22192. ++codingPos;
  22193. }
  22194. codingLine[codingPos] = a1;
  22195. } else if (a1 < codingLine[codingPos]) {
  22196. if (a1 < 0) {
  22197. info('invalid code');
  22198. this.err = true;
  22199. a1 = 0;
  22200. }
  22201. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22202. --codingPos;
  22203. }
  22204. codingLine[codingPos] = a1;
  22205. }
  22206. this.codingPos = codingPos;
  22207. };
  22208. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22209. var refLine = this.refLine;
  22210. var codingLine = this.codingLine;
  22211. var columns = this.columns;
  22212. var refPos, blackPixels, bits, i;
  22213. if (this.outputBits === 0) {
  22214. if (this.eof) {
  22215. return null;
  22216. }
  22217. this.err = false;
  22218. var code1, code2, code3;
  22219. if (this.nextLine2D) {
  22220. for (i = 0; codingLine[i] < columns; ++i) {
  22221. refLine[i] = codingLine[i];
  22222. }
  22223. refLine[i++] = columns;
  22224. refLine[i] = columns;
  22225. codingLine[0] = 0;
  22226. this.codingPos = 0;
  22227. refPos = 0;
  22228. blackPixels = 0;
  22229. while (codingLine[this.codingPos] < columns) {
  22230. code1 = this.getTwoDimCode();
  22231. switch (code1) {
  22232. case twoDimPass:
  22233. this.addPixels(refLine[refPos + 1], blackPixels);
  22234. if (refLine[refPos + 1] < columns) {
  22235. refPos += 2;
  22236. }
  22237. break;
  22238. case twoDimHoriz:
  22239. code1 = code2 = 0;
  22240. if (blackPixels) {
  22241. do {
  22242. code1 += (code3 = this.getBlackCode());
  22243. } while (code3 >= 64);
  22244. do {
  22245. code2 += (code3 = this.getWhiteCode());
  22246. } while (code3 >= 64);
  22247. } else {
  22248. do {
  22249. code1 += (code3 = this.getWhiteCode());
  22250. } while (code3 >= 64);
  22251. do {
  22252. code2 += (code3 = this.getBlackCode());
  22253. } while (code3 >= 64);
  22254. }
  22255. this.addPixels(codingLine[this.codingPos] +
  22256. code1, blackPixels);
  22257. if (codingLine[this.codingPos] < columns) {
  22258. this.addPixels(codingLine[this.codingPos] + code2,
  22259. blackPixels ^ 1);
  22260. }
  22261. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22262. refLine[refPos] < columns) {
  22263. refPos += 2;
  22264. }
  22265. break;
  22266. case twoDimVertR3:
  22267. this.addPixels(refLine[refPos] + 3, blackPixels);
  22268. blackPixels ^= 1;
  22269. if (codingLine[this.codingPos] < columns) {
  22270. ++refPos;
  22271. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22272. refLine[refPos] < columns) {
  22273. refPos += 2;
  22274. }
  22275. }
  22276. break;
  22277. case twoDimVertR2:
  22278. this.addPixels(refLine[refPos] + 2, blackPixels);
  22279. blackPixels ^= 1;
  22280. if (codingLine[this.codingPos] < columns) {
  22281. ++refPos;
  22282. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22283. refLine[refPos] < columns) {
  22284. refPos += 2;
  22285. }
  22286. }
  22287. break;
  22288. case twoDimVertR1:
  22289. this.addPixels(refLine[refPos] + 1, blackPixels);
  22290. blackPixels ^= 1;
  22291. if (codingLine[this.codingPos] < columns) {
  22292. ++refPos;
  22293. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22294. refLine[refPos] < columns) {
  22295. refPos += 2;
  22296. }
  22297. }
  22298. break;
  22299. case twoDimVert0:
  22300. this.addPixels(refLine[refPos], blackPixels);
  22301. blackPixels ^= 1;
  22302. if (codingLine[this.codingPos] < columns) {
  22303. ++refPos;
  22304. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22305. refLine[refPos] < columns) {
  22306. refPos += 2;
  22307. }
  22308. }
  22309. break;
  22310. case twoDimVertL3:
  22311. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22312. blackPixels ^= 1;
  22313. if (codingLine[this.codingPos] < columns) {
  22314. if (refPos > 0) {
  22315. --refPos;
  22316. } else {
  22317. ++refPos;
  22318. }
  22319. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22320. refLine[refPos] < columns) {
  22321. refPos += 2;
  22322. }
  22323. }
  22324. break;
  22325. case twoDimVertL2:
  22326. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22327. blackPixels ^= 1;
  22328. if (codingLine[this.codingPos] < columns) {
  22329. if (refPos > 0) {
  22330. --refPos;
  22331. } else {
  22332. ++refPos;
  22333. }
  22334. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22335. refLine[refPos] < columns) {
  22336. refPos += 2;
  22337. }
  22338. }
  22339. break;
  22340. case twoDimVertL1:
  22341. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22342. blackPixels ^= 1;
  22343. if (codingLine[this.codingPos] < columns) {
  22344. if (refPos > 0) {
  22345. --refPos;
  22346. } else {
  22347. ++refPos;
  22348. }
  22349. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22350. refLine[refPos] < columns) {
  22351. refPos += 2;
  22352. }
  22353. }
  22354. break;
  22355. case ccittEOF:
  22356. this.addPixels(columns, 0);
  22357. this.eof = true;
  22358. break;
  22359. default:
  22360. info('bad 2d code');
  22361. this.addPixels(columns, 0);
  22362. this.err = true;
  22363. }
  22364. }
  22365. } else {
  22366. codingLine[0] = 0;
  22367. this.codingPos = 0;
  22368. blackPixels = 0;
  22369. while (codingLine[this.codingPos] < columns) {
  22370. code1 = 0;
  22371. if (blackPixels) {
  22372. do {
  22373. code1 += (code3 = this.getBlackCode());
  22374. } while (code3 >= 64);
  22375. } else {
  22376. do {
  22377. code1 += (code3 = this.getWhiteCode());
  22378. } while (code3 >= 64);
  22379. }
  22380. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22381. blackPixels ^= 1;
  22382. }
  22383. }
  22384. var gotEOL = false;
  22385. if (this.byteAlign) {
  22386. this.inputBits &= ~7;
  22387. }
  22388. if (!this.eoblock && this.row === this.rows - 1) {
  22389. this.eof = true;
  22390. } else {
  22391. code1 = this.lookBits(12);
  22392. if (this.eoline) {
  22393. while (code1 !== ccittEOF && code1 !== 1) {
  22394. this.eatBits(1);
  22395. code1 = this.lookBits(12);
  22396. }
  22397. } else {
  22398. while (code1 === 0) {
  22399. this.eatBits(1);
  22400. code1 = this.lookBits(12);
  22401. }
  22402. }
  22403. if (code1 === 1) {
  22404. this.eatBits(12);
  22405. gotEOL = true;
  22406. } else if (code1 === ccittEOF) {
  22407. this.eof = true;
  22408. }
  22409. }
  22410. if (!this.eof && this.encoding > 0) {
  22411. this.nextLine2D = !this.lookBits(1);
  22412. this.eatBits(1);
  22413. }
  22414. if (this.eoblock && gotEOL && this.byteAlign) {
  22415. code1 = this.lookBits(12);
  22416. if (code1 === 1) {
  22417. this.eatBits(12);
  22418. if (this.encoding > 0) {
  22419. this.lookBits(1);
  22420. this.eatBits(1);
  22421. }
  22422. if (this.encoding >= 0) {
  22423. for (i = 0; i < 4; ++i) {
  22424. code1 = this.lookBits(12);
  22425. if (code1 !== 1) {
  22426. info('bad rtc code: ' + code1);
  22427. }
  22428. this.eatBits(12);
  22429. if (this.encoding > 0) {
  22430. this.lookBits(1);
  22431. this.eatBits(1);
  22432. }
  22433. }
  22434. }
  22435. this.eof = true;
  22436. }
  22437. } else if (this.err && this.eoline) {
  22438. while (true) {
  22439. code1 = this.lookBits(13);
  22440. if (code1 === ccittEOF) {
  22441. this.eof = true;
  22442. return null;
  22443. }
  22444. if ((code1 >> 1) === 1) {
  22445. break;
  22446. }
  22447. this.eatBits(1);
  22448. }
  22449. this.eatBits(12);
  22450. if (this.encoding > 0) {
  22451. this.eatBits(1);
  22452. this.nextLine2D = !(code1 & 1);
  22453. }
  22454. }
  22455. if (codingLine[0] > 0) {
  22456. this.outputBits = codingLine[this.codingPos = 0];
  22457. } else {
  22458. this.outputBits = codingLine[this.codingPos = 1];
  22459. }
  22460. this.row++;
  22461. }
  22462. var c;
  22463. if (this.outputBits >= 8) {
  22464. c = (this.codingPos & 1) ? 0 : 0xFF;
  22465. this.outputBits -= 8;
  22466. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22467. this.codingPos++;
  22468. this.outputBits = (codingLine[this.codingPos] -
  22469. codingLine[this.codingPos - 1]);
  22470. }
  22471. } else {
  22472. bits = 8;
  22473. c = 0;
  22474. do {
  22475. if (this.outputBits > bits) {
  22476. c <<= bits;
  22477. if (!(this.codingPos & 1)) {
  22478. c |= 0xFF >> (8 - bits);
  22479. }
  22480. this.outputBits -= bits;
  22481. bits = 0;
  22482. } else {
  22483. c <<= this.outputBits;
  22484. if (!(this.codingPos & 1)) {
  22485. c |= 0xFF >> (8 - this.outputBits);
  22486. }
  22487. bits -= this.outputBits;
  22488. this.outputBits = 0;
  22489. if (codingLine[this.codingPos] < columns) {
  22490. this.codingPos++;
  22491. this.outputBits = (codingLine[this.codingPos] -
  22492. codingLine[this.codingPos - 1]);
  22493. } else if (bits > 0) {
  22494. c <<= bits;
  22495. bits = 0;
  22496. }
  22497. }
  22498. } while (bits);
  22499. }
  22500. if (this.black) {
  22501. c ^= 0xFF;
  22502. }
  22503. return c;
  22504. };
  22505. // This functions returns the code found from the table.
  22506. // The start and end parameters set the boundaries for searching the table.
  22507. // The limit parameter is optional. Function returns an array with three
  22508. // values. The first array element indicates whether a valid code is being
  22509. // returned. The second array element is the actual code. The third array
  22510. // element indicates whether EOF was reached.
  22511. CCITTFaxStream.prototype.findTableCode =
  22512. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22513. var limitValue = limit || 0;
  22514. for (var i = start; i <= end; ++i) {
  22515. var code = this.lookBits(i);
  22516. if (code === ccittEOF) {
  22517. return [true, 1, false];
  22518. }
  22519. if (i < end) {
  22520. code <<= end - i;
  22521. }
  22522. if (!limitValue || code >= limitValue) {
  22523. var p = table[code - limitValue];
  22524. if (p[0] === i) {
  22525. this.eatBits(i);
  22526. return [true, p[1], true];
  22527. }
  22528. }
  22529. }
  22530. return [false, 0, false];
  22531. };
  22532. CCITTFaxStream.prototype.getTwoDimCode =
  22533. function ccittFaxStreamGetTwoDimCode() {
  22534. var code = 0;
  22535. var p;
  22536. if (this.eoblock) {
  22537. code = this.lookBits(7);
  22538. p = twoDimTable[code];
  22539. if (p && p[0] > 0) {
  22540. this.eatBits(p[0]);
  22541. return p[1];
  22542. }
  22543. } else {
  22544. var result = this.findTableCode(1, 7, twoDimTable);
  22545. if (result[0] && result[2]) {
  22546. return result[1];
  22547. }
  22548. }
  22549. info('Bad two dim code');
  22550. return ccittEOF;
  22551. };
  22552. CCITTFaxStream.prototype.getWhiteCode =
  22553. function ccittFaxStreamGetWhiteCode() {
  22554. var code = 0;
  22555. var p;
  22556. if (this.eoblock) {
  22557. code = this.lookBits(12);
  22558. if (code === ccittEOF) {
  22559. return 1;
  22560. }
  22561. if ((code >> 5) === 0) {
  22562. p = whiteTable1[code];
  22563. } else {
  22564. p = whiteTable2[code >> 3];
  22565. }
  22566. if (p[0] > 0) {
  22567. this.eatBits(p[0]);
  22568. return p[1];
  22569. }
  22570. } else {
  22571. var result = this.findTableCode(1, 9, whiteTable2);
  22572. if (result[0]) {
  22573. return result[1];
  22574. }
  22575. result = this.findTableCode(11, 12, whiteTable1);
  22576. if (result[0]) {
  22577. return result[1];
  22578. }
  22579. }
  22580. info('bad white code');
  22581. this.eatBits(1);
  22582. return 1;
  22583. };
  22584. CCITTFaxStream.prototype.getBlackCode =
  22585. function ccittFaxStreamGetBlackCode() {
  22586. var code, p;
  22587. if (this.eoblock) {
  22588. code = this.lookBits(13);
  22589. if (code === ccittEOF) {
  22590. return 1;
  22591. }
  22592. if ((code >> 7) === 0) {
  22593. p = blackTable1[code];
  22594. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22595. p = blackTable2[(code >> 1) - 64];
  22596. } else {
  22597. p = blackTable3[code >> 7];
  22598. }
  22599. if (p[0] > 0) {
  22600. this.eatBits(p[0]);
  22601. return p[1];
  22602. }
  22603. } else {
  22604. var result = this.findTableCode(2, 6, blackTable3);
  22605. if (result[0]) {
  22606. return result[1];
  22607. }
  22608. result = this.findTableCode(7, 12, blackTable2, 64);
  22609. if (result[0]) {
  22610. return result[1];
  22611. }
  22612. result = this.findTableCode(10, 13, blackTable1);
  22613. if (result[0]) {
  22614. return result[1];
  22615. }
  22616. }
  22617. info('bad black code');
  22618. this.eatBits(1);
  22619. return 1;
  22620. };
  22621. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22622. var c;
  22623. while (this.inputBits < n) {
  22624. if ((c = this.str.getByte()) === -1) {
  22625. if (this.inputBits === 0) {
  22626. return ccittEOF;
  22627. }
  22628. return ((this.inputBuf << (n - this.inputBits)) &
  22629. (0xFFFF >> (16 - n)));
  22630. }
  22631. this.inputBuf = (this.inputBuf << 8) | c;
  22632. this.inputBits += 8;
  22633. }
  22634. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22635. };
  22636. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22637. if ((this.inputBits -= n) < 0) {
  22638. this.inputBits = 0;
  22639. }
  22640. };
  22641. return CCITTFaxStream;
  22642. })();
  22643. var LZWStream = (function LZWStreamClosure() {
  22644. function LZWStream(str, maybeLength, earlyChange) {
  22645. this.str = str;
  22646. this.dict = str.dict;
  22647. this.cachedData = 0;
  22648. this.bitsCached = 0;
  22649. var maxLzwDictionarySize = 4096;
  22650. var lzwState = {
  22651. earlyChange: earlyChange,
  22652. codeLength: 9,
  22653. nextCode: 258,
  22654. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22655. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22656. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22657. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22658. currentSequenceLength: 0
  22659. };
  22660. for (var i = 0; i < 256; ++i) {
  22661. lzwState.dictionaryValues[i] = i;
  22662. lzwState.dictionaryLengths[i] = 1;
  22663. }
  22664. this.lzwState = lzwState;
  22665. DecodeStream.call(this, maybeLength);
  22666. }
  22667. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22668. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22669. var bitsCached = this.bitsCached;
  22670. var cachedData = this.cachedData;
  22671. while (bitsCached < n) {
  22672. var c = this.str.getByte();
  22673. if (c === -1) {
  22674. this.eof = true;
  22675. return null;
  22676. }
  22677. cachedData = (cachedData << 8) | c;
  22678. bitsCached += 8;
  22679. }
  22680. this.bitsCached = (bitsCached -= n);
  22681. this.cachedData = cachedData;
  22682. this.lastCode = null;
  22683. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22684. };
  22685. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22686. var blockSize = 512;
  22687. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22688. var i, j, q;
  22689. var lzwState = this.lzwState;
  22690. if (!lzwState) {
  22691. return; // eof was found
  22692. }
  22693. var earlyChange = lzwState.earlyChange;
  22694. var nextCode = lzwState.nextCode;
  22695. var dictionaryValues = lzwState.dictionaryValues;
  22696. var dictionaryLengths = lzwState.dictionaryLengths;
  22697. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22698. var codeLength = lzwState.codeLength;
  22699. var prevCode = lzwState.prevCode;
  22700. var currentSequence = lzwState.currentSequence;
  22701. var currentSequenceLength = lzwState.currentSequenceLength;
  22702. var decodedLength = 0;
  22703. var currentBufferLength = this.bufferLength;
  22704. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22705. for (i = 0; i < blockSize; i++) {
  22706. var code = this.readBits(codeLength);
  22707. var hasPrev = currentSequenceLength > 0;
  22708. if (code < 256) {
  22709. currentSequence[0] = code;
  22710. currentSequenceLength = 1;
  22711. } else if (code >= 258) {
  22712. if (code < nextCode) {
  22713. currentSequenceLength = dictionaryLengths[code];
  22714. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22715. currentSequence[j] = dictionaryValues[q];
  22716. q = dictionaryPrevCodes[q];
  22717. }
  22718. } else {
  22719. currentSequence[currentSequenceLength++] = currentSequence[0];
  22720. }
  22721. } else if (code === 256) {
  22722. codeLength = 9;
  22723. nextCode = 258;
  22724. currentSequenceLength = 0;
  22725. continue;
  22726. } else {
  22727. this.eof = true;
  22728. delete this.lzwState;
  22729. break;
  22730. }
  22731. if (hasPrev) {
  22732. dictionaryPrevCodes[nextCode] = prevCode;
  22733. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22734. dictionaryValues[nextCode] = currentSequence[0];
  22735. nextCode++;
  22736. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22737. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22738. 0.6931471805599453 + 1, 12) | 0;
  22739. }
  22740. prevCode = code;
  22741. decodedLength += currentSequenceLength;
  22742. if (estimatedDecodedSize < decodedLength) {
  22743. do {
  22744. estimatedDecodedSize += decodedSizeDelta;
  22745. } while (estimatedDecodedSize < decodedLength);
  22746. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22747. }
  22748. for (j = 0; j < currentSequenceLength; j++) {
  22749. buffer[currentBufferLength++] = currentSequence[j];
  22750. }
  22751. }
  22752. lzwState.nextCode = nextCode;
  22753. lzwState.codeLength = codeLength;
  22754. lzwState.prevCode = prevCode;
  22755. lzwState.currentSequenceLength = currentSequenceLength;
  22756. this.bufferLength = currentBufferLength;
  22757. };
  22758. return LZWStream;
  22759. })();
  22760. var NullStream = (function NullStreamClosure() {
  22761. function NullStream() {
  22762. Stream.call(this, new Uint8Array(0));
  22763. }
  22764. NullStream.prototype = Stream.prototype;
  22765. return NullStream;
  22766. })();
  22767. exports.Ascii85Stream = Ascii85Stream;
  22768. exports.AsciiHexStream = AsciiHexStream;
  22769. exports.CCITTFaxStream = CCITTFaxStream;
  22770. exports.DecryptStream = DecryptStream;
  22771. exports.DecodeStream = DecodeStream;
  22772. exports.FlateStream = FlateStream;
  22773. exports.Jbig2Stream = Jbig2Stream;
  22774. exports.JpegStream = JpegStream;
  22775. exports.JpxStream = JpxStream;
  22776. exports.NullStream = NullStream;
  22777. exports.PredictorStream = PredictorStream;
  22778. exports.RunLengthStream = RunLengthStream;
  22779. exports.Stream = Stream;
  22780. exports.StreamsSequenceStream = StreamsSequenceStream;
  22781. exports.StringStream = StringStream;
  22782. exports.LZWStream = LZWStream;
  22783. }));
  22784. (function (root, factory) {
  22785. {
  22786. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  22787. root.pdfjsDisplayDOMUtils);
  22788. }
  22789. }(this, function (exports, sharedUtil, displayDOMUtils) {
  22790. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  22791. var AnnotationType = sharedUtil.AnnotationType;
  22792. var Util = sharedUtil.Util;
  22793. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  22794. var LinkTarget = displayDOMUtils.LinkTarget;
  22795. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  22796. var warn = sharedUtil.warn;
  22797. var CustomStyle = displayDOMUtils.CustomStyle;
  22798. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  22799. /**
  22800. * @typedef {Object} AnnotationElementParameters
  22801. * @property {Object} data
  22802. * @property {HTMLDivElement} layer
  22803. * @property {PDFPage} page
  22804. * @property {PageViewport} viewport
  22805. * @property {IPDFLinkService} linkService
  22806. * @property {DownloadManager} downloadManager
  22807. */
  22808. /**
  22809. * @class
  22810. * @alias AnnotationElementFactory
  22811. */
  22812. function AnnotationElementFactory() {}
  22813. AnnotationElementFactory.prototype =
  22814. /** @lends AnnotationElementFactory.prototype */ {
  22815. /**
  22816. * @param {AnnotationElementParameters} parameters
  22817. * @returns {AnnotationElement}
  22818. */
  22819. create: function AnnotationElementFactory_create(parameters) {
  22820. var subtype = parameters.data.annotationType;
  22821. switch (subtype) {
  22822. case AnnotationType.LINK:
  22823. return new LinkAnnotationElement(parameters);
  22824. case AnnotationType.TEXT:
  22825. return new TextAnnotationElement(parameters);
  22826. case AnnotationType.WIDGET:
  22827. return new WidgetAnnotationElement(parameters);
  22828. case AnnotationType.POPUP:
  22829. return new PopupAnnotationElement(parameters);
  22830. case AnnotationType.HIGHLIGHT:
  22831. return new HighlightAnnotationElement(parameters);
  22832. case AnnotationType.UNDERLINE:
  22833. return new UnderlineAnnotationElement(parameters);
  22834. case AnnotationType.SQUIGGLY:
  22835. return new SquigglyAnnotationElement(parameters);
  22836. case AnnotationType.STRIKEOUT:
  22837. return new StrikeOutAnnotationElement(parameters);
  22838. case AnnotationType.FILEATTACHMENT:
  22839. return new FileAttachmentAnnotationElement(parameters);
  22840. default:
  22841. return new AnnotationElement(parameters);
  22842. }
  22843. }
  22844. };
  22845. /**
  22846. * @class
  22847. * @alias AnnotationElement
  22848. */
  22849. var AnnotationElement = (function AnnotationElementClosure() {
  22850. function AnnotationElement(parameters, isRenderable) {
  22851. this.isRenderable = isRenderable || false;
  22852. this.data = parameters.data;
  22853. this.layer = parameters.layer;
  22854. this.page = parameters.page;
  22855. this.viewport = parameters.viewport;
  22856. this.linkService = parameters.linkService;
  22857. this.downloadManager = parameters.downloadManager;
  22858. this.imageResourcesPath = parameters.imageResourcesPath;
  22859. if (isRenderable) {
  22860. this.container = this._createContainer();
  22861. }
  22862. }
  22863. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  22864. /**
  22865. * Create an empty container for the annotation's HTML element.
  22866. *
  22867. * @private
  22868. * @memberof AnnotationElement
  22869. * @returns {HTMLSectionElement}
  22870. */
  22871. _createContainer: function AnnotationElement_createContainer() {
  22872. var data = this.data, page = this.page, viewport = this.viewport;
  22873. var container = document.createElement('section');
  22874. var width = data.rect[2] - data.rect[0];
  22875. var height = data.rect[3] - data.rect[1];
  22876. container.setAttribute('data-annotation-id', data.id);
  22877. // Do *not* modify `data.rect`, since that will corrupt the annotation
  22878. // position on subsequent calls to `_createContainer` (see issue 6804).
  22879. var rect = Util.normalizeRect([
  22880. data.rect[0],
  22881. page.view[3] - data.rect[1] + page.view[1],
  22882. data.rect[2],
  22883. page.view[3] - data.rect[3] + page.view[1]
  22884. ]);
  22885. CustomStyle.setProp('transform', container,
  22886. 'matrix(' + viewport.transform.join(',') + ')');
  22887. CustomStyle.setProp('transformOrigin', container,
  22888. -rect[0] + 'px ' + -rect[1] + 'px');
  22889. if (data.borderStyle.width > 0) {
  22890. container.style.borderWidth = data.borderStyle.width + 'px';
  22891. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  22892. // Underline styles only have a bottom border, so we do not need
  22893. // to adjust for all borders. This yields a similar result as
  22894. // Adobe Acrobat/Reader.
  22895. width = width - 2 * data.borderStyle.width;
  22896. height = height - 2 * data.borderStyle.width;
  22897. }
  22898. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  22899. var verticalRadius = data.borderStyle.verticalCornerRadius;
  22900. if (horizontalRadius > 0 || verticalRadius > 0) {
  22901. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  22902. CustomStyle.setProp('borderRadius', container, radius);
  22903. }
  22904. switch (data.borderStyle.style) {
  22905. case AnnotationBorderStyleType.SOLID:
  22906. container.style.borderStyle = 'solid';
  22907. break;
  22908. case AnnotationBorderStyleType.DASHED:
  22909. container.style.borderStyle = 'dashed';
  22910. break;
  22911. case AnnotationBorderStyleType.BEVELED:
  22912. warn('Unimplemented border style: beveled');
  22913. break;
  22914. case AnnotationBorderStyleType.INSET:
  22915. warn('Unimplemented border style: inset');
  22916. break;
  22917. case AnnotationBorderStyleType.UNDERLINE:
  22918. container.style.borderBottomStyle = 'solid';
  22919. break;
  22920. default:
  22921. break;
  22922. }
  22923. if (data.color) {
  22924. container.style.borderColor =
  22925. Util.makeCssRgb(data.color[0] | 0,
  22926. data.color[1] | 0,
  22927. data.color[2] | 0);
  22928. } else {
  22929. // Transparent (invisible) border, so do not draw it at all.
  22930. container.style.borderWidth = 0;
  22931. }
  22932. }
  22933. container.style.left = rect[0] + 'px';
  22934. container.style.top = rect[1] + 'px';
  22935. container.style.width = width + 'px';
  22936. container.style.height = height + 'px';
  22937. return container;
  22938. },
  22939. /**
  22940. * Create a popup for the annotation's HTML element. This is used for
  22941. * annotations that do not have a Popup entry in the dictionary, but
  22942. * are of a type that works with popups (such as Highlight annotations).
  22943. *
  22944. * @private
  22945. * @param {HTMLSectionElement} container
  22946. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  22947. * @param {Object} data
  22948. * @memberof AnnotationElement
  22949. */
  22950. _createPopup:
  22951. function AnnotationElement_createPopup(container, trigger, data) {
  22952. // If no trigger element is specified, create it.
  22953. if (!trigger) {
  22954. trigger = document.createElement('div');
  22955. trigger.style.height = container.style.height;
  22956. trigger.style.width = container.style.width;
  22957. container.appendChild(trigger);
  22958. }
  22959. var popupElement = new PopupElement({
  22960. container: container,
  22961. trigger: trigger,
  22962. color: data.color,
  22963. title: data.title,
  22964. contents: data.contents,
  22965. hideWrapper: true
  22966. });
  22967. var popup = popupElement.render();
  22968. // Position the popup next to the annotation's container.
  22969. popup.style.left = container.style.width;
  22970. container.appendChild(popup);
  22971. },
  22972. /**
  22973. * Render the annotation's HTML element in the empty container.
  22974. *
  22975. * @public
  22976. * @memberof AnnotationElement
  22977. */
  22978. render: function AnnotationElement_render() {
  22979. throw new Error('Abstract method AnnotationElement.render called');
  22980. }
  22981. };
  22982. return AnnotationElement;
  22983. })();
  22984. /**
  22985. * @class
  22986. * @alias LinkAnnotationElement
  22987. */
  22988. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  22989. function LinkAnnotationElement(parameters) {
  22990. AnnotationElement.call(this, parameters, true);
  22991. }
  22992. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  22993. /**
  22994. * Render the link annotation's HTML element in the empty container.
  22995. *
  22996. * @public
  22997. * @memberof LinkAnnotationElement
  22998. * @returns {HTMLSectionElement}
  22999. */
  23000. render: function LinkAnnotationElement_render() {
  23001. this.container.className = 'linkAnnotation';
  23002. var link = document.createElement('a');
  23003. addLinkAttributes(link, {
  23004. url: this.data.url,
  23005. target: (this.data.newWindow ? LinkTarget.BLANK : undefined),
  23006. });
  23007. if (!this.data.url) {
  23008. if (this.data.action) {
  23009. this._bindNamedAction(link, this.data.action);
  23010. } else {
  23011. this._bindLink(link, (this.data.dest || null));
  23012. }
  23013. }
  23014. this.container.appendChild(link);
  23015. return this.container;
  23016. },
  23017. /**
  23018. * Bind internal links to the link element.
  23019. *
  23020. * @private
  23021. * @param {Object} link
  23022. * @param {Object} destination
  23023. * @memberof LinkAnnotationElement
  23024. */
  23025. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  23026. var self = this;
  23027. link.href = this.linkService.getDestinationHash(destination);
  23028. link.onclick = function() {
  23029. if (destination) {
  23030. self.linkService.navigateTo(destination);
  23031. }
  23032. return false;
  23033. };
  23034. if (destination) {
  23035. link.className = 'internalLink';
  23036. }
  23037. },
  23038. /**
  23039. * Bind named actions to the link element.
  23040. *
  23041. * @private
  23042. * @param {Object} link
  23043. * @param {Object} action
  23044. * @memberof LinkAnnotationElement
  23045. */
  23046. _bindNamedAction:
  23047. function LinkAnnotationElement_bindNamedAction(link, action) {
  23048. var self = this;
  23049. link.href = this.linkService.getAnchorUrl('');
  23050. link.onclick = function() {
  23051. self.linkService.executeNamedAction(action);
  23052. return false;
  23053. };
  23054. link.className = 'internalLink';
  23055. }
  23056. });
  23057. return LinkAnnotationElement;
  23058. })();
  23059. /**
  23060. * @class
  23061. * @alias TextAnnotationElement
  23062. */
  23063. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  23064. function TextAnnotationElement(parameters) {
  23065. var isRenderable = !!(parameters.data.hasPopup ||
  23066. parameters.data.title || parameters.data.contents);
  23067. AnnotationElement.call(this, parameters, isRenderable);
  23068. }
  23069. Util.inherit(TextAnnotationElement, AnnotationElement, {
  23070. /**
  23071. * Render the text annotation's HTML element in the empty container.
  23072. *
  23073. * @public
  23074. * @memberof TextAnnotationElement
  23075. * @returns {HTMLSectionElement}
  23076. */
  23077. render: function TextAnnotationElement_render() {
  23078. this.container.className = 'textAnnotation';
  23079. var image = document.createElement('img');
  23080. image.style.height = this.container.style.height;
  23081. image.style.width = this.container.style.width;
  23082. image.src = this.imageResourcesPath + 'annotation-' +
  23083. this.data.name.toLowerCase() + '.svg';
  23084. image.alt = '[{{type}} Annotation]';
  23085. image.dataset.l10nId = 'text_annotation_type';
  23086. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  23087. if (!this.data.hasPopup) {
  23088. this._createPopup(this.container, image, this.data);
  23089. }
  23090. this.container.appendChild(image);
  23091. return this.container;
  23092. }
  23093. });
  23094. return TextAnnotationElement;
  23095. })();
  23096. /**
  23097. * @class
  23098. * @alias WidgetAnnotationElement
  23099. */
  23100. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  23101. function WidgetAnnotationElement(parameters) {
  23102. var isRenderable = !parameters.data.hasAppearance &&
  23103. !!parameters.data.fieldValue;
  23104. AnnotationElement.call(this, parameters, isRenderable);
  23105. }
  23106. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  23107. /**
  23108. * Render the widget annotation's HTML element in the empty container.
  23109. *
  23110. * @public
  23111. * @memberof WidgetAnnotationElement
  23112. * @returns {HTMLSectionElement}
  23113. */
  23114. render: function WidgetAnnotationElement_render() {
  23115. var content = document.createElement('div');
  23116. content.textContent = this.data.fieldValue;
  23117. var textAlignment = this.data.textAlignment;
  23118. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  23119. content.style.verticalAlign = 'middle';
  23120. content.style.display = 'table-cell';
  23121. var font = (this.data.fontRefName ?
  23122. this.page.commonObjs.getData(this.data.fontRefName) : null);
  23123. this._setTextStyle(content, font);
  23124. this.container.appendChild(content);
  23125. return this.container;
  23126. },
  23127. /**
  23128. * Apply text styles to the text in the element.
  23129. *
  23130. * @private
  23131. * @param {HTMLDivElement} element
  23132. * @param {Object} font
  23133. * @memberof WidgetAnnotationElement
  23134. */
  23135. _setTextStyle:
  23136. function WidgetAnnotationElement_setTextStyle(element, font) {
  23137. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  23138. var style = element.style;
  23139. style.fontSize = this.data.fontSize + 'px';
  23140. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  23141. if (!font) {
  23142. return;
  23143. }
  23144. style.fontWeight = (font.black ?
  23145. (font.bold ? '900' : 'bold') :
  23146. (font.bold ? 'bold' : 'normal'));
  23147. style.fontStyle = (font.italic ? 'italic' : 'normal');
  23148. // Use a reasonable default font if the font doesn't specify a fallback.
  23149. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  23150. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  23151. style.fontFamily = fontFamily + fallbackName;
  23152. }
  23153. });
  23154. return WidgetAnnotationElement;
  23155. })();
  23156. /**
  23157. * @class
  23158. * @alias PopupAnnotationElement
  23159. */
  23160. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  23161. function PopupAnnotationElement(parameters) {
  23162. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  23163. AnnotationElement.call(this, parameters, isRenderable);
  23164. }
  23165. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  23166. /**
  23167. * Render the popup annotation's HTML element in the empty container.
  23168. *
  23169. * @public
  23170. * @memberof PopupAnnotationElement
  23171. * @returns {HTMLSectionElement}
  23172. */
  23173. render: function PopupAnnotationElement_render() {
  23174. this.container.className = 'popupAnnotation';
  23175. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  23176. var parentElement = this.layer.querySelector(selector);
  23177. if (!parentElement) {
  23178. return this.container;
  23179. }
  23180. var popup = new PopupElement({
  23181. container: this.container,
  23182. trigger: parentElement,
  23183. color: this.data.color,
  23184. title: this.data.title,
  23185. contents: this.data.contents
  23186. });
  23187. // Position the popup next to the parent annotation's container.
  23188. // PDF viewers ignore a popup annotation's rectangle.
  23189. var parentLeft = parseFloat(parentElement.style.left);
  23190. var parentWidth = parseFloat(parentElement.style.width);
  23191. CustomStyle.setProp('transformOrigin', this.container,
  23192. -(parentLeft + parentWidth) + 'px -' +
  23193. parentElement.style.top);
  23194. this.container.style.left = (parentLeft + parentWidth) + 'px';
  23195. this.container.appendChild(popup.render());
  23196. return this.container;
  23197. }
  23198. });
  23199. return PopupAnnotationElement;
  23200. })();
  23201. /**
  23202. * @class
  23203. * @alias PopupElement
  23204. */
  23205. var PopupElement = (function PopupElementClosure() {
  23206. var BACKGROUND_ENLIGHT = 0.7;
  23207. function PopupElement(parameters) {
  23208. this.container = parameters.container;
  23209. this.trigger = parameters.trigger;
  23210. this.color = parameters.color;
  23211. this.title = parameters.title;
  23212. this.contents = parameters.contents;
  23213. this.hideWrapper = parameters.hideWrapper || false;
  23214. this.pinned = false;
  23215. }
  23216. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  23217. /**
  23218. * Render the popup's HTML element.
  23219. *
  23220. * @public
  23221. * @memberof PopupElement
  23222. * @returns {HTMLSectionElement}
  23223. */
  23224. render: function PopupElement_render() {
  23225. var wrapper = document.createElement('div');
  23226. wrapper.className = 'popupWrapper';
  23227. // For Popup annotations we hide the entire section because it contains
  23228. // only the popup. However, for Text annotations without a separate Popup
  23229. // annotation, we cannot hide the entire container as the image would
  23230. // disappear too. In that special case, hiding the wrapper suffices.
  23231. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  23232. this.hideElement.setAttribute('hidden', true);
  23233. var popup = document.createElement('div');
  23234. popup.className = 'popup';
  23235. var color = this.color;
  23236. if (color) {
  23237. // Enlighten the color.
  23238. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  23239. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  23240. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  23241. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  23242. }
  23243. var contents = this._formatContents(this.contents);
  23244. var title = document.createElement('h1');
  23245. title.textContent = this.title;
  23246. // Attach the event listeners to the trigger element.
  23247. this.trigger.addEventListener('click', this._toggle.bind(this));
  23248. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  23249. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  23250. popup.addEventListener('click', this._hide.bind(this, true));
  23251. popup.appendChild(title);
  23252. popup.appendChild(contents);
  23253. wrapper.appendChild(popup);
  23254. return wrapper;
  23255. },
  23256. /**
  23257. * Format the contents of the popup by adding newlines where necessary.
  23258. *
  23259. * @private
  23260. * @param {string} contents
  23261. * @memberof PopupElement
  23262. * @returns {HTMLParagraphElement}
  23263. */
  23264. _formatContents: function PopupElement_formatContents(contents) {
  23265. var p = document.createElement('p');
  23266. var lines = contents.split(/(?:\r\n?|\n)/);
  23267. for (var i = 0, ii = lines.length; i < ii; ++i) {
  23268. var line = lines[i];
  23269. p.appendChild(document.createTextNode(line));
  23270. if (i < (ii - 1)) {
  23271. p.appendChild(document.createElement('br'));
  23272. }
  23273. }
  23274. return p;
  23275. },
  23276. /**
  23277. * Toggle the visibility of the popup.
  23278. *
  23279. * @private
  23280. * @memberof PopupElement
  23281. */
  23282. _toggle: function PopupElement_toggle() {
  23283. if (this.pinned) {
  23284. this._hide(true);
  23285. } else {
  23286. this._show(true);
  23287. }
  23288. },
  23289. /**
  23290. * Show the popup.
  23291. *
  23292. * @private
  23293. * @param {boolean} pin
  23294. * @memberof PopupElement
  23295. */
  23296. _show: function PopupElement_show(pin) {
  23297. if (pin) {
  23298. this.pinned = true;
  23299. }
  23300. if (this.hideElement.hasAttribute('hidden')) {
  23301. this.hideElement.removeAttribute('hidden');
  23302. this.container.style.zIndex += 1;
  23303. }
  23304. },
  23305. /**
  23306. * Hide the popup.
  23307. *
  23308. * @private
  23309. * @param {boolean} unpin
  23310. * @memberof PopupElement
  23311. */
  23312. _hide: function PopupElement_hide(unpin) {
  23313. if (unpin) {
  23314. this.pinned = false;
  23315. }
  23316. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  23317. this.hideElement.setAttribute('hidden', true);
  23318. this.container.style.zIndex -= 1;
  23319. }
  23320. }
  23321. };
  23322. return PopupElement;
  23323. })();
  23324. /**
  23325. * @class
  23326. * @alias HighlightAnnotationElement
  23327. */
  23328. var HighlightAnnotationElement = (
  23329. function HighlightAnnotationElementClosure() {
  23330. function HighlightAnnotationElement(parameters) {
  23331. var isRenderable = !!(parameters.data.hasPopup ||
  23332. parameters.data.title || parameters.data.contents);
  23333. AnnotationElement.call(this, parameters, isRenderable);
  23334. }
  23335. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  23336. /**
  23337. * Render the highlight annotation's HTML element in the empty container.
  23338. *
  23339. * @public
  23340. * @memberof HighlightAnnotationElement
  23341. * @returns {HTMLSectionElement}
  23342. */
  23343. render: function HighlightAnnotationElement_render() {
  23344. this.container.className = 'highlightAnnotation';
  23345. if (!this.data.hasPopup) {
  23346. this._createPopup(this.container, null, this.data);
  23347. }
  23348. return this.container;
  23349. }
  23350. });
  23351. return HighlightAnnotationElement;
  23352. })();
  23353. /**
  23354. * @class
  23355. * @alias UnderlineAnnotationElement
  23356. */
  23357. var UnderlineAnnotationElement = (
  23358. function UnderlineAnnotationElementClosure() {
  23359. function UnderlineAnnotationElement(parameters) {
  23360. var isRenderable = !!(parameters.data.hasPopup ||
  23361. parameters.data.title || parameters.data.contents);
  23362. AnnotationElement.call(this, parameters, isRenderable);
  23363. }
  23364. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  23365. /**
  23366. * Render the underline annotation's HTML element in the empty container.
  23367. *
  23368. * @public
  23369. * @memberof UnderlineAnnotationElement
  23370. * @returns {HTMLSectionElement}
  23371. */
  23372. render: function UnderlineAnnotationElement_render() {
  23373. this.container.className = 'underlineAnnotation';
  23374. if (!this.data.hasPopup) {
  23375. this._createPopup(this.container, null, this.data);
  23376. }
  23377. return this.container;
  23378. }
  23379. });
  23380. return UnderlineAnnotationElement;
  23381. })();
  23382. /**
  23383. * @class
  23384. * @alias SquigglyAnnotationElement
  23385. */
  23386. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  23387. function SquigglyAnnotationElement(parameters) {
  23388. var isRenderable = !!(parameters.data.hasPopup ||
  23389. parameters.data.title || parameters.data.contents);
  23390. AnnotationElement.call(this, parameters, isRenderable);
  23391. }
  23392. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  23393. /**
  23394. * Render the squiggly annotation's HTML element in the empty container.
  23395. *
  23396. * @public
  23397. * @memberof SquigglyAnnotationElement
  23398. * @returns {HTMLSectionElement}
  23399. */
  23400. render: function SquigglyAnnotationElement_render() {
  23401. this.container.className = 'squigglyAnnotation';
  23402. if (!this.data.hasPopup) {
  23403. this._createPopup(this.container, null, this.data);
  23404. }
  23405. return this.container;
  23406. }
  23407. });
  23408. return SquigglyAnnotationElement;
  23409. })();
  23410. /**
  23411. * @class
  23412. * @alias StrikeOutAnnotationElement
  23413. */
  23414. var StrikeOutAnnotationElement = (
  23415. function StrikeOutAnnotationElementClosure() {
  23416. function StrikeOutAnnotationElement(parameters) {
  23417. var isRenderable = !!(parameters.data.hasPopup ||
  23418. parameters.data.title || parameters.data.contents);
  23419. AnnotationElement.call(this, parameters, isRenderable);
  23420. }
  23421. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  23422. /**
  23423. * Render the strikeout annotation's HTML element in the empty container.
  23424. *
  23425. * @public
  23426. * @memberof StrikeOutAnnotationElement
  23427. * @returns {HTMLSectionElement}
  23428. */
  23429. render: function StrikeOutAnnotationElement_render() {
  23430. this.container.className = 'strikeoutAnnotation';
  23431. if (!this.data.hasPopup) {
  23432. this._createPopup(this.container, null, this.data);
  23433. }
  23434. return this.container;
  23435. }
  23436. });
  23437. return StrikeOutAnnotationElement;
  23438. })();
  23439. /**
  23440. * @class
  23441. * @alias FileAttachmentAnnotationElement
  23442. */
  23443. var FileAttachmentAnnotationElement = (
  23444. function FileAttachmentAnnotationElementClosure() {
  23445. function FileAttachmentAnnotationElement(parameters) {
  23446. AnnotationElement.call(this, parameters, true);
  23447. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  23448. this.content = parameters.data.file.content;
  23449. }
  23450. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  23451. /**
  23452. * Render the file attachment annotation's HTML element in the empty
  23453. * container.
  23454. *
  23455. * @public
  23456. * @memberof FileAttachmentAnnotationElement
  23457. * @returns {HTMLSectionElement}
  23458. */
  23459. render: function FileAttachmentAnnotationElement_render() {
  23460. this.container.className = 'fileAttachmentAnnotation';
  23461. var trigger = document.createElement('div');
  23462. trigger.style.height = this.container.style.height;
  23463. trigger.style.width = this.container.style.width;
  23464. trigger.addEventListener('dblclick', this._download.bind(this));
  23465. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  23466. this._createPopup(this.container, trigger, this.data);
  23467. }
  23468. this.container.appendChild(trigger);
  23469. return this.container;
  23470. },
  23471. /**
  23472. * Download the file attachment associated with this annotation.
  23473. *
  23474. * @private
  23475. * @memberof FileAttachmentAnnotationElement
  23476. */
  23477. _download: function FileAttachmentAnnotationElement_download() {
  23478. if (!this.downloadManager) {
  23479. warn('Download cannot be started due to unavailable download manager');
  23480. return;
  23481. }
  23482. this.downloadManager.downloadData(this.content, this.filename, '');
  23483. }
  23484. });
  23485. return FileAttachmentAnnotationElement;
  23486. })();
  23487. /**
  23488. * @typedef {Object} AnnotationLayerParameters
  23489. * @property {PageViewport} viewport
  23490. * @property {HTMLDivElement} div
  23491. * @property {Array} annotations
  23492. * @property {PDFPage} page
  23493. * @property {IPDFLinkService} linkService
  23494. * @property {string} imageResourcesPath
  23495. */
  23496. /**
  23497. * @class
  23498. * @alias AnnotationLayer
  23499. */
  23500. var AnnotationLayer = (function AnnotationLayerClosure() {
  23501. return {
  23502. /**
  23503. * Render a new annotation layer with all annotation elements.
  23504. *
  23505. * @public
  23506. * @param {AnnotationLayerParameters} parameters
  23507. * @memberof AnnotationLayer
  23508. */
  23509. render: function AnnotationLayer_render(parameters) {
  23510. var annotationElementFactory = new AnnotationElementFactory();
  23511. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23512. var data = parameters.annotations[i];
  23513. if (!data) {
  23514. continue;
  23515. }
  23516. var properties = {
  23517. data: data,
  23518. layer: parameters.div,
  23519. page: parameters.page,
  23520. viewport: parameters.viewport,
  23521. linkService: parameters.linkService,
  23522. downloadManager: parameters.downloadManager,
  23523. imageResourcesPath: parameters.imageResourcesPath ||
  23524. getDefaultSetting('imageResourcesPath')
  23525. };
  23526. var element = annotationElementFactory.create(properties);
  23527. if (element.isRenderable) {
  23528. parameters.div.appendChild(element.render());
  23529. }
  23530. }
  23531. },
  23532. /**
  23533. * Update the annotation elements on existing annotation layer.
  23534. *
  23535. * @public
  23536. * @param {AnnotationLayerParameters} parameters
  23537. * @memberof AnnotationLayer
  23538. */
  23539. update: function AnnotationLayer_update(parameters) {
  23540. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23541. var data = parameters.annotations[i];
  23542. var element = parameters.div.querySelector(
  23543. '[data-annotation-id="' + data.id + '"]');
  23544. if (element) {
  23545. CustomStyle.setProp('transform', element,
  23546. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  23547. }
  23548. }
  23549. parameters.div.removeAttribute('hidden');
  23550. }
  23551. };
  23552. })();
  23553. exports.AnnotationLayer = AnnotationLayer;
  23554. }));
  23555. (function (root, factory) {
  23556. {
  23557. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  23558. root.pdfjsDisplayDOMUtils);
  23559. }
  23560. }(this, function (exports, sharedUtil, displayDOMUtils) {
  23561. var Util = sharedUtil.Util;
  23562. var createPromiseCapability = sharedUtil.createPromiseCapability;
  23563. var CustomStyle = displayDOMUtils.CustomStyle;
  23564. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  23565. /**
  23566. * Text layer render parameters.
  23567. *
  23568. * @typedef {Object} TextLayerRenderParameters
  23569. * @property {TextContent} textContent - Text content to render (the object is
  23570. * returned by the page's getTextContent() method).
  23571. * @property {HTMLElement} container - HTML element that will contain text runs.
  23572. * @property {PageViewport} viewport - The target viewport to properly
  23573. * layout the text runs.
  23574. * @property {Array} textDivs - (optional) HTML elements that are correspond
  23575. * the text items of the textContent input. This is output and shall be
  23576. * initially be set to empty array.
  23577. * @property {number} timeout - (optional) Delay in milliseconds before
  23578. * rendering of the text runs occurs.
  23579. */
  23580. var renderTextLayer = (function renderTextLayerClosure() {
  23581. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  23582. var NonWhitespaceRegexp = /\S/;
  23583. function isAllWhitespace(str) {
  23584. return !NonWhitespaceRegexp.test(str);
  23585. }
  23586. function appendText(textDivs, viewport, geom, styles, bounds,
  23587. enhanceTextSelection) {
  23588. var style = styles[geom.fontName];
  23589. var textDiv = document.createElement('div');
  23590. textDivs.push(textDiv);
  23591. if (isAllWhitespace(geom.str)) {
  23592. textDiv.dataset.isWhitespace = true;
  23593. return;
  23594. }
  23595. var tx = Util.transform(viewport.transform, geom.transform);
  23596. var angle = Math.atan2(tx[1], tx[0]);
  23597. if (style.vertical) {
  23598. angle += Math.PI / 2;
  23599. }
  23600. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  23601. var fontAscent = fontHeight;
  23602. if (style.ascent) {
  23603. fontAscent = style.ascent * fontAscent;
  23604. } else if (style.descent) {
  23605. fontAscent = (1 + style.descent) * fontAscent;
  23606. }
  23607. var left;
  23608. var top;
  23609. if (angle === 0) {
  23610. left = tx[4];
  23611. top = tx[5] - fontAscent;
  23612. } else {
  23613. left = tx[4] + (fontAscent * Math.sin(angle));
  23614. top = tx[5] - (fontAscent * Math.cos(angle));
  23615. }
  23616. textDiv.style.left = left + 'px';
  23617. textDiv.style.top = top + 'px';
  23618. textDiv.style.fontSize = fontHeight + 'px';
  23619. textDiv.style.fontFamily = style.fontFamily;
  23620. textDiv.textContent = geom.str;
  23621. // |fontName| is only used by the Font Inspector. This test will succeed
  23622. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  23623. // not worth the effort to do a more accurate test.
  23624. if (getDefaultSetting('pdfBug')) {
  23625. textDiv.dataset.fontName = geom.fontName;
  23626. }
  23627. // Storing into dataset will convert number into string.
  23628. if (angle !== 0) {
  23629. textDiv.dataset.angle = angle * (180 / Math.PI);
  23630. }
  23631. // We don't bother scaling single-char text divs, because it has very
  23632. // little effect on text highlighting. This makes scrolling on docs with
  23633. // lots of such divs a lot faster.
  23634. if (geom.str.length > 1) {
  23635. if (style.vertical) {
  23636. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  23637. } else {
  23638. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  23639. }
  23640. }
  23641. if (enhanceTextSelection) {
  23642. var angleCos = 1, angleSin = 0;
  23643. if (angle !== 0) {
  23644. angleCos = Math.cos(angle);
  23645. angleSin = Math.sin(angle);
  23646. }
  23647. var divWidth = (style.vertical ? geom.height : geom.width) *
  23648. viewport.scale;
  23649. var divHeight = fontHeight;
  23650. var m, b;
  23651. if (angle !== 0) {
  23652. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  23653. b = Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  23654. } else {
  23655. b = [left, top, left + divWidth, top + divHeight];
  23656. }
  23657. bounds.push({
  23658. left: b[0],
  23659. top: b[1],
  23660. right: b[2],
  23661. bottom: b[3],
  23662. div: textDiv,
  23663. size: [divWidth, divHeight],
  23664. m: m
  23665. });
  23666. }
  23667. }
  23668. function render(task) {
  23669. if (task._canceled) {
  23670. return;
  23671. }
  23672. var textLayerFrag = task._container;
  23673. var textDivs = task._textDivs;
  23674. var capability = task._capability;
  23675. var textDivsLength = textDivs.length;
  23676. // No point in rendering many divs as it would make the browser
  23677. // unusable even after the divs are rendered.
  23678. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  23679. task._renderingDone = true;
  23680. capability.resolve();
  23681. return;
  23682. }
  23683. var canvas = document.createElement('canvas');
  23684. var ctx = canvas.getContext('2d', {alpha: false});
  23685. var lastFontSize;
  23686. var lastFontFamily;
  23687. for (var i = 0; i < textDivsLength; i++) {
  23688. var textDiv = textDivs[i];
  23689. if (textDiv.dataset.isWhitespace !== undefined) {
  23690. continue;
  23691. }
  23692. var fontSize = textDiv.style.fontSize;
  23693. var fontFamily = textDiv.style.fontFamily;
  23694. // Only build font string and set to context if different from last.
  23695. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  23696. ctx.font = fontSize + ' ' + fontFamily;
  23697. lastFontSize = fontSize;
  23698. lastFontFamily = fontFamily;
  23699. }
  23700. var width = ctx.measureText(textDiv.textContent).width;
  23701. textDiv.dataset.originalWidth = width;
  23702. textLayerFrag.appendChild(textDiv);
  23703. var transform;
  23704. if (textDiv.dataset.canvasWidth !== undefined && width > 0) {
  23705. // Dataset values are of type string.
  23706. var textScale = textDiv.dataset.canvasWidth / width;
  23707. transform = 'scaleX(' + textScale + ')';
  23708. } else {
  23709. transform = '';
  23710. }
  23711. var rotation = textDiv.dataset.angle;
  23712. if (rotation) {
  23713. transform = 'rotate(' + rotation + 'deg) ' + transform;
  23714. }
  23715. if (transform) {
  23716. textDiv.dataset.originalTransform = transform;
  23717. CustomStyle.setProp('transform' , textDiv, transform);
  23718. }
  23719. }
  23720. task._renderingDone = true;
  23721. capability.resolve();
  23722. }
  23723. function expand(bounds, viewport) {
  23724. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  23725. for (var i = 0; i < expanded.length; i++) {
  23726. var div = bounds[i].div;
  23727. if (!div.dataset.angle) {
  23728. div.dataset.paddingLeft = bounds[i].left - expanded[i].left;
  23729. div.dataset.paddingTop = bounds[i].top - expanded[i].top;
  23730. div.dataset.paddingRight = expanded[i].right - bounds[i].right;
  23731. div.dataset.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  23732. continue;
  23733. }
  23734. // Box is rotated -- trying to find padding so rotated div will not
  23735. // exceed its expanded bounds.
  23736. var e = expanded[i], b = bounds[i];
  23737. var m = b.m, c = m[0], s = m[1];
  23738. // Finding intersections with expanded box.
  23739. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  23740. var ts = new Float64Array(64);
  23741. points.forEach(function (p, i) {
  23742. var t = Util.applyTransform(p, m);
  23743. ts[i + 0] = c && (e.left - t[0]) / c;
  23744. ts[i + 4] = s && (e.top - t[1]) / s;
  23745. ts[i + 8] = c && (e.right - t[0]) / c;
  23746. ts[i + 12] = s && (e.bottom - t[1]) / s;
  23747. ts[i + 16] = s && (e.left - t[0]) / -s;
  23748. ts[i + 20] = c && (e.top - t[1]) / c;
  23749. ts[i + 24] = s && (e.right - t[0]) / -s;
  23750. ts[i + 28] = c && (e.bottom - t[1]) / c;
  23751. ts[i + 32] = c && (e.left - t[0]) / -c;
  23752. ts[i + 36] = s && (e.top - t[1]) / -s;
  23753. ts[i + 40] = c && (e.right - t[0]) / -c;
  23754. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  23755. ts[i + 48] = s && (e.left - t[0]) / s;
  23756. ts[i + 52] = c && (e.top - t[1]) / -c;
  23757. ts[i + 56] = s && (e.right - t[0]) / s;
  23758. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  23759. });
  23760. var findPositiveMin = function (ts, offset, count) {
  23761. var result = 0;
  23762. for (var i = 0; i < count; i++) {
  23763. var t = ts[offset++];
  23764. if (t > 0) {
  23765. result = result ? Math.min(t, result) : t;
  23766. }
  23767. }
  23768. return result;
  23769. };
  23770. // Not based on math, but to simplify calculations, using cos and sin
  23771. // absolute values to not exceed the box (it can but insignificantly).
  23772. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  23773. div.dataset.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  23774. div.dataset.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  23775. div.dataset.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  23776. div.dataset.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  23777. }
  23778. }
  23779. function expandBounds(width, height, boxes) {
  23780. var bounds = boxes.map(function (box, i) {
  23781. return {
  23782. x1: box.left,
  23783. y1: box.top,
  23784. x2: box.right,
  23785. y2: box.bottom,
  23786. index: i,
  23787. x1New: undefined,
  23788. x2New: undefined
  23789. };
  23790. });
  23791. expandBoundsLTR(width, bounds);
  23792. var expanded = new Array(boxes.length);
  23793. bounds.forEach(function (b) {
  23794. var i = b.index;
  23795. expanded[i] = {
  23796. left: b.x1New,
  23797. top: 0,
  23798. right: b.x2New,
  23799. bottom: 0
  23800. };
  23801. });
  23802. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  23803. // array and objects.
  23804. boxes.map(function (box, i) {
  23805. var e = expanded[i], b = bounds[i];
  23806. b.x1 = box.top;
  23807. b.y1 = width - e.right;
  23808. b.x2 = box.bottom;
  23809. b.y2 = width - e.left;
  23810. b.index = i;
  23811. b.x1New = undefined;
  23812. b.x2New = undefined;
  23813. });
  23814. expandBoundsLTR(height, bounds);
  23815. bounds.forEach(function (b) {
  23816. var i = b.index;
  23817. expanded[i].top = b.x1New;
  23818. expanded[i].bottom = b.x2New;
  23819. });
  23820. return expanded;
  23821. }
  23822. function expandBoundsLTR(width, bounds) {
  23823. // Sorting by x1 coordinate and walk by the bounds in the same order.
  23824. bounds.sort(function (a, b) { return a.x1 - b.x1 || a.index - b.index; });
  23825. // First we see on the horizon is a fake boundary.
  23826. var fakeBoundary = {
  23827. x1: -Infinity,
  23828. y1: -Infinity,
  23829. x2: 0,
  23830. y2: Infinity,
  23831. index: -1,
  23832. x1New: 0,
  23833. x2New: 0
  23834. };
  23835. var horizon = [{
  23836. start: -Infinity,
  23837. end: Infinity,
  23838. boundary: fakeBoundary
  23839. }];
  23840. bounds.forEach(function (boundary) {
  23841. // Searching for the affected part of horizon.
  23842. // TODO red-black tree or simple binary search
  23843. var i = 0;
  23844. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  23845. i++;
  23846. }
  23847. var j = horizon.length - 1;
  23848. while(j >= 0 && horizon[j].start >= boundary.y2) {
  23849. j--;
  23850. }
  23851. var horizonPart, affectedBoundary;
  23852. var q, k, maxXNew = -Infinity;
  23853. for (q = i; q <= j; q++) {
  23854. horizonPart = horizon[q];
  23855. affectedBoundary = horizonPart.boundary;
  23856. var xNew;
  23857. if (affectedBoundary.x2 > boundary.x1) {
  23858. // In the middle of the previous element, new x shall be at the
  23859. // boundary start. Extending if further if the affected bondary
  23860. // placed on top of the current one.
  23861. xNew = affectedBoundary.index > boundary.index ?
  23862. affectedBoundary.x1New : boundary.x1;
  23863. } else if (affectedBoundary.x2New === undefined) {
  23864. // We have some space in between, new x in middle will be a fair
  23865. // choice.
  23866. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  23867. } else {
  23868. // Affected boundary has x2new set, using it as new x.
  23869. xNew = affectedBoundary.x2New;
  23870. }
  23871. if (xNew > maxXNew) {
  23872. maxXNew = xNew;
  23873. }
  23874. }
  23875. // Set new x1 for current boundary.
  23876. boundary.x1New = maxXNew;
  23877. // Adjusts new x2 for the affected boundaries.
  23878. for (q = i; q <= j; q++) {
  23879. horizonPart = horizon[q];
  23880. affectedBoundary = horizonPart.boundary;
  23881. if (affectedBoundary.x2New === undefined) {
  23882. // Was not set yet, choosing new x if possible.
  23883. if (affectedBoundary.x2 > boundary.x1) {
  23884. // Current and affected boundaries intersect. If affected boundary
  23885. // is placed on top of the current, shrinking the affected.
  23886. if (affectedBoundary.index > boundary.index) {
  23887. affectedBoundary.x2New = affectedBoundary.x2;
  23888. }
  23889. } else {
  23890. affectedBoundary.x2New = maxXNew;
  23891. }
  23892. } else if (affectedBoundary.x2New > maxXNew) {
  23893. // Affected boundary is touching new x, pushing it back.
  23894. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  23895. }
  23896. }
  23897. // Fixing the horizon.
  23898. var changedHorizon = [], lastBoundary = null;
  23899. for (q = i; q <= j; q++) {
  23900. horizonPart = horizon[q];
  23901. affectedBoundary = horizonPart.boundary;
  23902. // Checking which boundary will be visible.
  23903. var useBoundary = affectedBoundary.x2 > boundary.x2 ?
  23904. affectedBoundary : boundary;
  23905. if (lastBoundary === useBoundary) {
  23906. // Merging with previous.
  23907. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  23908. } else {
  23909. changedHorizon.push({
  23910. start: horizonPart.start,
  23911. end: horizonPart.end,
  23912. boundary: useBoundary
  23913. });
  23914. lastBoundary = useBoundary;
  23915. }
  23916. }
  23917. if (horizon[i].start < boundary.y1) {
  23918. changedHorizon[0].start = boundary.y1;
  23919. changedHorizon.unshift({
  23920. start: horizon[i].start,
  23921. end: boundary.y1,
  23922. boundary: horizon[i].boundary
  23923. });
  23924. }
  23925. if (boundary.y2 < horizon[j].end) {
  23926. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  23927. changedHorizon.push({
  23928. start: boundary.y2,
  23929. end: horizon[j].end,
  23930. boundary: horizon[j].boundary
  23931. });
  23932. }
  23933. // Set x2 new of boundary that is no longer visible (see overlapping case
  23934. // above).
  23935. // TODO more efficient, e.g. via reference counting.
  23936. for (q = i; q <= j; q++) {
  23937. horizonPart = horizon[q];
  23938. affectedBoundary = horizonPart.boundary;
  23939. if (affectedBoundary.x2New !== undefined) {
  23940. continue;
  23941. }
  23942. var used = false;
  23943. for (k = i - 1; !used && k >= 0 &&
  23944. horizon[k].start >= affectedBoundary.y1; k--) {
  23945. used = horizon[k].boundary === affectedBoundary;
  23946. }
  23947. for (k = j + 1; !used && k < horizon.length &&
  23948. horizon[k].end <= affectedBoundary.y2; k++) {
  23949. used = horizon[k].boundary === affectedBoundary;
  23950. }
  23951. for (k = 0; !used && k < changedHorizon.length; k++) {
  23952. used = changedHorizon[k].boundary === affectedBoundary;
  23953. }
  23954. if (!used) {
  23955. affectedBoundary.x2New = maxXNew;
  23956. }
  23957. }
  23958. Array.prototype.splice.apply(horizon,
  23959. [i, j - i + 1].concat(changedHorizon));
  23960. });
  23961. // Set new x2 for all unset boundaries.
  23962. horizon.forEach(function (horizonPart) {
  23963. var affectedBoundary = horizonPart.boundary;
  23964. if (affectedBoundary.x2New === undefined) {
  23965. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  23966. }
  23967. });
  23968. }
  23969. /**
  23970. * Text layer rendering task.
  23971. *
  23972. * @param {TextContent} textContent
  23973. * @param {HTMLElement} container
  23974. * @param {PageViewport} viewport
  23975. * @param {Array} textDivs
  23976. * @param {boolean} enhanceTextSelection
  23977. * @private
  23978. */
  23979. function TextLayerRenderTask(textContent, container, viewport, textDivs,
  23980. enhanceTextSelection) {
  23981. this._textContent = textContent;
  23982. this._container = container;
  23983. this._viewport = viewport;
  23984. textDivs = textDivs || [];
  23985. this._textDivs = textDivs;
  23986. this._renderingDone = false;
  23987. this._canceled = false;
  23988. this._capability = createPromiseCapability();
  23989. this._renderTimer = null;
  23990. this._bounds = [];
  23991. this._enhanceTextSelection = !!enhanceTextSelection;
  23992. this._expanded = false;
  23993. }
  23994. TextLayerRenderTask.prototype = {
  23995. get promise() {
  23996. return this._capability.promise;
  23997. },
  23998. cancel: function TextLayer_cancel() {
  23999. this._canceled = true;
  24000. if (this._renderTimer !== null) {
  24001. clearTimeout(this._renderTimer);
  24002. this._renderTimer = null;
  24003. }
  24004. this._capability.reject('canceled');
  24005. },
  24006. _render: function TextLayer_render(timeout) {
  24007. var textItems = this._textContent.items;
  24008. var styles = this._textContent.styles;
  24009. var textDivs = this._textDivs;
  24010. var viewport = this._viewport;
  24011. var bounds = this._bounds;
  24012. var enhanceTextSelection = this._enhanceTextSelection;
  24013. for (var i = 0, len = textItems.length; i < len; i++) {
  24014. appendText(textDivs, viewport, textItems[i], styles, bounds,
  24015. enhanceTextSelection);
  24016. }
  24017. if (!timeout) { // Render right away
  24018. render(this);
  24019. } else { // Schedule
  24020. var self = this;
  24021. this._renderTimer = setTimeout(function() {
  24022. render(self);
  24023. self._renderTimer = null;
  24024. }, timeout);
  24025. }
  24026. },
  24027. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  24028. if (!this._enhanceTextSelection || !this._renderingDone) {
  24029. return;
  24030. }
  24031. if (!this._expanded) {
  24032. expand(this._bounds, this._viewport);
  24033. this._expanded = true;
  24034. this._bounds.length = 0;
  24035. }
  24036. if (expandDivs) {
  24037. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  24038. var div = this._textDivs[i];
  24039. var transform;
  24040. var width = div.dataset.originalWidth;
  24041. if (div.dataset.canvasWidth !== undefined && width > 0) {
  24042. // Dataset values are of type string.
  24043. var textScale = div.dataset.canvasWidth / width;
  24044. transform = 'scaleX(' + textScale + ')';
  24045. } else {
  24046. transform = '';
  24047. }
  24048. var rotation = div.dataset.angle;
  24049. if (rotation) {
  24050. transform = 'rotate(' + rotation + 'deg) ' + transform;
  24051. }
  24052. if (div.dataset.paddingLeft) {
  24053. div.style.paddingLeft =
  24054. (div.dataset.paddingLeft / textScale) + 'px';
  24055. transform += ' translateX(' +
  24056. (-div.dataset.paddingLeft / textScale) + 'px)';
  24057. }
  24058. if (div.dataset.paddingTop) {
  24059. div.style.paddingTop = div.dataset.paddingTop + 'px';
  24060. transform += ' translateY(' + (-div.dataset.paddingTop) + 'px)';
  24061. }
  24062. if (div.dataset.paddingRight) {
  24063. div.style.paddingRight =
  24064. div.dataset.paddingRight / textScale + 'px';
  24065. }
  24066. if (div.dataset.paddingBottom) {
  24067. div.style.paddingBottom = div.dataset.paddingBottom + 'px';
  24068. }
  24069. if (transform) {
  24070. CustomStyle.setProp('transform' , div, transform);
  24071. }
  24072. }
  24073. } else {
  24074. for (i = 0, ii = this._textDivs.length; i < ii; i++) {
  24075. div = this._textDivs[i];
  24076. div.style.padding = 0;
  24077. transform = div.dataset.originalTransform || '';
  24078. CustomStyle.setProp('transform', div, transform);
  24079. }
  24080. }
  24081. },
  24082. };
  24083. /**
  24084. * Starts rendering of the text layer.
  24085. *
  24086. * @param {TextLayerRenderParameters} renderParameters
  24087. * @returns {TextLayerRenderTask}
  24088. */
  24089. function renderTextLayer(renderParameters) {
  24090. var task = new TextLayerRenderTask(renderParameters.textContent,
  24091. renderParameters.container,
  24092. renderParameters.viewport,
  24093. renderParameters.textDivs,
  24094. renderParameters.enhanceTextSelection);
  24095. task._render(renderParameters.timeout);
  24096. return task;
  24097. }
  24098. return renderTextLayer;
  24099. })();
  24100. exports.renderTextLayer = renderTextLayer;
  24101. }));
  24102. (function (root, factory) {
  24103. {
  24104. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil,
  24105. root.pdfjsDisplayDOMUtils);
  24106. }
  24107. }(this, function (exports, sharedUtil, displayDOMUtils) {
  24108. var shadow = sharedUtil.shadow;
  24109. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  24110. var WebGLUtils = (function WebGLUtilsClosure() {
  24111. function loadShader(gl, code, shaderType) {
  24112. var shader = gl.createShader(shaderType);
  24113. gl.shaderSource(shader, code);
  24114. gl.compileShader(shader);
  24115. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  24116. if (!compiled) {
  24117. var errorMsg = gl.getShaderInfoLog(shader);
  24118. throw new Error('Error during shader compilation: ' + errorMsg);
  24119. }
  24120. return shader;
  24121. }
  24122. function createVertexShader(gl, code) {
  24123. return loadShader(gl, code, gl.VERTEX_SHADER);
  24124. }
  24125. function createFragmentShader(gl, code) {
  24126. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  24127. }
  24128. function createProgram(gl, shaders) {
  24129. var program = gl.createProgram();
  24130. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  24131. gl.attachShader(program, shaders[i]);
  24132. }
  24133. gl.linkProgram(program);
  24134. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  24135. if (!linked) {
  24136. var errorMsg = gl.getProgramInfoLog(program);
  24137. throw new Error('Error during program linking: ' + errorMsg);
  24138. }
  24139. return program;
  24140. }
  24141. function createTexture(gl, image, textureId) {
  24142. gl.activeTexture(textureId);
  24143. var texture = gl.createTexture();
  24144. gl.bindTexture(gl.TEXTURE_2D, texture);
  24145. // Set the parameters so we can render any size image.
  24146. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  24147. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  24148. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  24149. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  24150. // Upload the image into the texture.
  24151. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  24152. return texture;
  24153. }
  24154. var currentGL, currentCanvas;
  24155. function generateGL() {
  24156. if (currentGL) {
  24157. return;
  24158. }
  24159. currentCanvas = document.createElement('canvas');
  24160. currentGL = currentCanvas.getContext('webgl',
  24161. { premultipliedalpha: false });
  24162. }
  24163. var smaskVertexShaderCode = '\
  24164. attribute vec2 a_position; \
  24165. attribute vec2 a_texCoord; \
  24166. \
  24167. uniform vec2 u_resolution; \
  24168. \
  24169. varying vec2 v_texCoord; \
  24170. \
  24171. void main() { \
  24172. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  24173. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24174. \
  24175. v_texCoord = a_texCoord; \
  24176. } ';
  24177. var smaskFragmentShaderCode = '\
  24178. precision mediump float; \
  24179. \
  24180. uniform vec4 u_backdrop; \
  24181. uniform int u_subtype; \
  24182. uniform sampler2D u_image; \
  24183. uniform sampler2D u_mask; \
  24184. \
  24185. varying vec2 v_texCoord; \
  24186. \
  24187. void main() { \
  24188. vec4 imageColor = texture2D(u_image, v_texCoord); \
  24189. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  24190. if (u_backdrop.a > 0.0) { \
  24191. maskColor.rgb = maskColor.rgb * maskColor.a + \
  24192. u_backdrop.rgb * (1.0 - maskColor.a); \
  24193. } \
  24194. float lum; \
  24195. if (u_subtype == 0) { \
  24196. lum = maskColor.a; \
  24197. } else { \
  24198. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  24199. maskColor.b * 0.11; \
  24200. } \
  24201. imageColor.a *= lum; \
  24202. imageColor.rgb *= imageColor.a; \
  24203. gl_FragColor = imageColor; \
  24204. } ';
  24205. var smaskCache = null;
  24206. function initSmaskGL() {
  24207. var canvas, gl;
  24208. generateGL();
  24209. canvas = currentCanvas;
  24210. currentCanvas = null;
  24211. gl = currentGL;
  24212. currentGL = null;
  24213. // setup a GLSL program
  24214. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  24215. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  24216. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24217. gl.useProgram(program);
  24218. var cache = {};
  24219. cache.gl = gl;
  24220. cache.canvas = canvas;
  24221. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24222. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24223. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  24224. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  24225. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  24226. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  24227. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  24228. // provide texture coordinates for the rectangle.
  24229. var texCoordBuffer = gl.createBuffer();
  24230. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  24231. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24232. 0.0, 0.0,
  24233. 1.0, 0.0,
  24234. 0.0, 1.0,
  24235. 0.0, 1.0,
  24236. 1.0, 0.0,
  24237. 1.0, 1.0]), gl.STATIC_DRAW);
  24238. gl.enableVertexAttribArray(texCoordLocation);
  24239. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  24240. gl.uniform1i(texLayerLocation, 0);
  24241. gl.uniform1i(texMaskLocation, 1);
  24242. smaskCache = cache;
  24243. }
  24244. function composeSMask(layer, mask, properties) {
  24245. var width = layer.width, height = layer.height;
  24246. if (!smaskCache) {
  24247. initSmaskGL();
  24248. }
  24249. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  24250. canvas.width = width;
  24251. canvas.height = height;
  24252. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24253. gl.uniform2f(cache.resolutionLocation, width, height);
  24254. if (properties.backdrop) {
  24255. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  24256. properties.backdrop[1], properties.backdrop[2], 1);
  24257. } else {
  24258. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  24259. }
  24260. gl.uniform1i(cache.subtypeLocation,
  24261. properties.subtype === 'Luminosity' ? 1 : 0);
  24262. // Create a textures
  24263. var texture = createTexture(gl, layer, gl.TEXTURE0);
  24264. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  24265. // Create a buffer and put a single clipspace rectangle in
  24266. // it (2 triangles)
  24267. var buffer = gl.createBuffer();
  24268. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  24269. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24270. 0, 0,
  24271. width, 0,
  24272. 0, height,
  24273. 0, height,
  24274. width, 0,
  24275. width, height]), gl.STATIC_DRAW);
  24276. gl.enableVertexAttribArray(cache.positionLocation);
  24277. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24278. // draw
  24279. gl.clearColor(0, 0, 0, 0);
  24280. gl.enable(gl.BLEND);
  24281. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  24282. gl.clear(gl.COLOR_BUFFER_BIT);
  24283. gl.drawArrays(gl.TRIANGLES, 0, 6);
  24284. gl.flush();
  24285. gl.deleteTexture(texture);
  24286. gl.deleteTexture(maskTexture);
  24287. gl.deleteBuffer(buffer);
  24288. return canvas;
  24289. }
  24290. var figuresVertexShaderCode = '\
  24291. attribute vec2 a_position; \
  24292. attribute vec3 a_color; \
  24293. \
  24294. uniform vec2 u_resolution; \
  24295. uniform vec2 u_scale; \
  24296. uniform vec2 u_offset; \
  24297. \
  24298. varying vec4 v_color; \
  24299. \
  24300. void main() { \
  24301. vec2 position = (a_position + u_offset) * u_scale; \
  24302. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  24303. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24304. \
  24305. v_color = vec4(a_color / 255.0, 1.0); \
  24306. } ';
  24307. var figuresFragmentShaderCode = '\
  24308. precision mediump float; \
  24309. \
  24310. varying vec4 v_color; \
  24311. \
  24312. void main() { \
  24313. gl_FragColor = v_color; \
  24314. } ';
  24315. var figuresCache = null;
  24316. function initFiguresGL() {
  24317. var canvas, gl;
  24318. generateGL();
  24319. canvas = currentCanvas;
  24320. currentCanvas = null;
  24321. gl = currentGL;
  24322. currentGL = null;
  24323. // setup a GLSL program
  24324. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  24325. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  24326. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24327. gl.useProgram(program);
  24328. var cache = {};
  24329. cache.gl = gl;
  24330. cache.canvas = canvas;
  24331. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24332. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  24333. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  24334. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24335. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  24336. figuresCache = cache;
  24337. }
  24338. function drawFigures(width, height, backgroundColor, figures, context) {
  24339. if (!figuresCache) {
  24340. initFiguresGL();
  24341. }
  24342. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  24343. canvas.width = width;
  24344. canvas.height = height;
  24345. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24346. gl.uniform2f(cache.resolutionLocation, width, height);
  24347. // count triangle points
  24348. var count = 0;
  24349. var i, ii, rows;
  24350. for (i = 0, ii = figures.length; i < ii; i++) {
  24351. switch (figures[i].type) {
  24352. case 'lattice':
  24353. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  24354. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  24355. break;
  24356. case 'triangles':
  24357. count += figures[i].coords.length;
  24358. break;
  24359. }
  24360. }
  24361. // transfer data
  24362. var coords = new Float32Array(count * 2);
  24363. var colors = new Uint8Array(count * 3);
  24364. var coordsMap = context.coords, colorsMap = context.colors;
  24365. var pIndex = 0, cIndex = 0;
  24366. for (i = 0, ii = figures.length; i < ii; i++) {
  24367. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  24368. switch (figure.type) {
  24369. case 'lattice':
  24370. var cols = figure.verticesPerRow;
  24371. rows = (ps.length / cols) | 0;
  24372. for (var row = 1; row < rows; row++) {
  24373. var offset = row * cols + 1;
  24374. for (var col = 1; col < cols; col++, offset++) {
  24375. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  24376. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  24377. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  24378. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  24379. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  24380. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  24381. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  24382. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  24383. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  24384. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  24385. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  24386. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  24387. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  24388. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  24389. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  24390. coords[pIndex + 6] = coords[pIndex + 2];
  24391. coords[pIndex + 7] = coords[pIndex + 3];
  24392. coords[pIndex + 8] = coords[pIndex + 4];
  24393. coords[pIndex + 9] = coords[pIndex + 5];
  24394. coords[pIndex + 10] = coordsMap[ps[offset]];
  24395. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  24396. colors[cIndex + 9] = colors[cIndex + 3];
  24397. colors[cIndex + 10] = colors[cIndex + 4];
  24398. colors[cIndex + 11] = colors[cIndex + 5];
  24399. colors[cIndex + 12] = colors[cIndex + 6];
  24400. colors[cIndex + 13] = colors[cIndex + 7];
  24401. colors[cIndex + 14] = colors[cIndex + 8];
  24402. colors[cIndex + 15] = colorsMap[cs[offset]];
  24403. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  24404. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  24405. pIndex += 12;
  24406. cIndex += 18;
  24407. }
  24408. }
  24409. break;
  24410. case 'triangles':
  24411. for (var j = 0, jj = ps.length; j < jj; j++) {
  24412. coords[pIndex] = coordsMap[ps[j]];
  24413. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  24414. colors[cIndex] = colorsMap[cs[j]];
  24415. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  24416. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  24417. pIndex += 2;
  24418. cIndex += 3;
  24419. }
  24420. break;
  24421. }
  24422. }
  24423. // draw
  24424. if (backgroundColor) {
  24425. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  24426. backgroundColor[2] / 255, 1.0);
  24427. } else {
  24428. gl.clearColor(0, 0, 0, 0);
  24429. }
  24430. gl.clear(gl.COLOR_BUFFER_BIT);
  24431. var coordsBuffer = gl.createBuffer();
  24432. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  24433. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  24434. gl.enableVertexAttribArray(cache.positionLocation);
  24435. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24436. var colorsBuffer = gl.createBuffer();
  24437. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  24438. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  24439. gl.enableVertexAttribArray(cache.colorLocation);
  24440. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  24441. 0, 0);
  24442. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  24443. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  24444. gl.drawArrays(gl.TRIANGLES, 0, count);
  24445. gl.flush();
  24446. gl.deleteBuffer(coordsBuffer);
  24447. gl.deleteBuffer(colorsBuffer);
  24448. return canvas;
  24449. }
  24450. function cleanup() {
  24451. if (smaskCache && smaskCache.canvas) {
  24452. smaskCache.canvas.width = 0;
  24453. smaskCache.canvas.height = 0;
  24454. }
  24455. if (figuresCache && figuresCache.canvas) {
  24456. figuresCache.canvas.width = 0;
  24457. figuresCache.canvas.height = 0;
  24458. }
  24459. smaskCache = null;
  24460. figuresCache = null;
  24461. }
  24462. return {
  24463. get isEnabled() {
  24464. if (getDefaultSetting('disableWebGL')) {
  24465. return false;
  24466. }
  24467. var enabled = false;
  24468. try {
  24469. generateGL();
  24470. enabled = !!currentGL;
  24471. } catch (e) { }
  24472. return shadow(this, 'isEnabled', enabled);
  24473. },
  24474. composeSMask: composeSMask,
  24475. drawFigures: drawFigures,
  24476. clear: cleanup
  24477. };
  24478. })();
  24479. exports.WebGLUtils = WebGLUtils;
  24480. }));
  24481. (function (root, factory) {
  24482. {
  24483. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  24484. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  24485. }
  24486. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  24487. var PasswordException = sharedUtil.PasswordException;
  24488. var PasswordResponses = sharedUtil.PasswordResponses;
  24489. var bytesToString = sharedUtil.bytesToString;
  24490. var error = sharedUtil.error;
  24491. var isInt = sharedUtil.isInt;
  24492. var stringToBytes = sharedUtil.stringToBytes;
  24493. var utf8StringToString = sharedUtil.utf8StringToString;
  24494. var warn = sharedUtil.warn;
  24495. var Name = corePrimitives.Name;
  24496. var isName = corePrimitives.isName;
  24497. var isDict = corePrimitives.isDict;
  24498. var DecryptStream = coreStream.DecryptStream;
  24499. var ARCFourCipher = (function ARCFourCipherClosure() {
  24500. function ARCFourCipher(key) {
  24501. this.a = 0;
  24502. this.b = 0;
  24503. var s = new Uint8Array(256);
  24504. var i, j = 0, tmp, keyLength = key.length;
  24505. for (i = 0; i < 256; ++i) {
  24506. s[i] = i;
  24507. }
  24508. for (i = 0; i < 256; ++i) {
  24509. tmp = s[i];
  24510. j = (j + tmp + key[i % keyLength]) & 0xFF;
  24511. s[i] = s[j];
  24512. s[j] = tmp;
  24513. }
  24514. this.s = s;
  24515. }
  24516. ARCFourCipher.prototype = {
  24517. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  24518. var i, n = data.length, tmp, tmp2;
  24519. var a = this.a, b = this.b, s = this.s;
  24520. var output = new Uint8Array(n);
  24521. for (i = 0; i < n; ++i) {
  24522. a = (a + 1) & 0xFF;
  24523. tmp = s[a];
  24524. b = (b + tmp) & 0xFF;
  24525. tmp2 = s[b];
  24526. s[a] = tmp2;
  24527. s[b] = tmp;
  24528. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  24529. }
  24530. this.a = a;
  24531. this.b = b;
  24532. return output;
  24533. }
  24534. };
  24535. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  24536. return ARCFourCipher;
  24537. })();
  24538. var calculateMD5 = (function calculateMD5Closure() {
  24539. var r = new Uint8Array([
  24540. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  24541. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  24542. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  24543. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  24544. var k = new Int32Array([
  24545. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  24546. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  24547. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  24548. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  24549. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  24550. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  24551. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  24552. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  24553. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  24554. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  24555. -145523070, -1120210379, 718787259, -343485551]);
  24556. function hash(data, offset, length) {
  24557. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  24558. // pre-processing
  24559. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  24560. var padded = new Uint8Array(paddedLength);
  24561. var i, j, n;
  24562. for (i = 0; i < length; ++i) {
  24563. padded[i] = data[offset++];
  24564. }
  24565. padded[i++] = 0x80;
  24566. n = paddedLength - 8;
  24567. while (i < n) {
  24568. padded[i++] = 0;
  24569. }
  24570. padded[i++] = (length << 3) & 0xFF;
  24571. padded[i++] = (length >> 5) & 0xFF;
  24572. padded[i++] = (length >> 13) & 0xFF;
  24573. padded[i++] = (length >> 21) & 0xFF;
  24574. padded[i++] = (length >>> 29) & 0xFF;
  24575. padded[i++] = 0;
  24576. padded[i++] = 0;
  24577. padded[i++] = 0;
  24578. var w = new Int32Array(16);
  24579. for (i = 0; i < paddedLength;) {
  24580. for (j = 0; j < 16; ++j, i += 4) {
  24581. w[j] = (padded[i] | (padded[i + 1] << 8) |
  24582. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  24583. }
  24584. var a = h0, b = h1, c = h2, d = h3, f, g;
  24585. for (j = 0; j < 64; ++j) {
  24586. if (j < 16) {
  24587. f = (b & c) | ((~b) & d);
  24588. g = j;
  24589. } else if (j < 32) {
  24590. f = (d & b) | ((~d) & c);
  24591. g = (5 * j + 1) & 15;
  24592. } else if (j < 48) {
  24593. f = b ^ c ^ d;
  24594. g = (3 * j + 5) & 15;
  24595. } else {
  24596. f = c ^ (b | (~d));
  24597. g = (7 * j) & 15;
  24598. }
  24599. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  24600. d = c;
  24601. c = b;
  24602. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  24603. a = tmp;
  24604. }
  24605. h0 = (h0 + a) | 0;
  24606. h1 = (h1 + b) | 0;
  24607. h2 = (h2 + c) | 0;
  24608. h3 = (h3 + d) | 0;
  24609. }
  24610. return new Uint8Array([
  24611. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  24612. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  24613. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  24614. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  24615. ]);
  24616. }
  24617. return hash;
  24618. })();
  24619. var Word64 = (function Word64Closure() {
  24620. function Word64(highInteger, lowInteger) {
  24621. this.high = highInteger | 0;
  24622. this.low = lowInteger | 0;
  24623. }
  24624. Word64.prototype = {
  24625. and: function Word64_and(word) {
  24626. this.high &= word.high;
  24627. this.low &= word.low;
  24628. },
  24629. xor: function Word64_xor(word) {
  24630. this.high ^= word.high;
  24631. this.low ^= word.low;
  24632. },
  24633. or: function Word64_or(word) {
  24634. this.high |= word.high;
  24635. this.low |= word.low;
  24636. },
  24637. shiftRight: function Word64_shiftRight(places) {
  24638. if (places >= 32) {
  24639. this.low = (this.high >>> (places - 32)) | 0;
  24640. this.high = 0;
  24641. } else {
  24642. this.low = (this.low >>> places) | (this.high << (32 - places));
  24643. this.high = (this.high >>> places) | 0;
  24644. }
  24645. },
  24646. shiftLeft: function Word64_shiftLeft(places) {
  24647. if (places >= 32) {
  24648. this.high = this.low << (places - 32);
  24649. this.low = 0;
  24650. } else {
  24651. this.high = (this.high << places) | (this.low >>> (32 - places));
  24652. this.low = this.low << places;
  24653. }
  24654. },
  24655. rotateRight: function Word64_rotateRight(places) {
  24656. var low, high;
  24657. if (places & 32) {
  24658. high = this.low;
  24659. low = this.high;
  24660. } else {
  24661. low = this.low;
  24662. high = this.high;
  24663. }
  24664. places &= 31;
  24665. this.low = (low >>> places) | (high << (32 - places));
  24666. this.high = (high >>> places) | (low << (32 - places));
  24667. },
  24668. not: function Word64_not() {
  24669. this.high = ~this.high;
  24670. this.low = ~this.low;
  24671. },
  24672. add: function Word64_add(word) {
  24673. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  24674. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  24675. if (lowAdd > 0xFFFFFFFF) {
  24676. highAdd += 1;
  24677. }
  24678. this.low = lowAdd | 0;
  24679. this.high = highAdd | 0;
  24680. },
  24681. copyTo: function Word64_copyTo(bytes, offset) {
  24682. bytes[offset] = (this.high >>> 24) & 0xFF;
  24683. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  24684. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  24685. bytes[offset + 3] = this.high & 0xFF;
  24686. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  24687. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  24688. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  24689. bytes[offset + 7] = this.low & 0xFF;
  24690. },
  24691. assign: function Word64_assign(word) {
  24692. this.high = word.high;
  24693. this.low = word.low;
  24694. }
  24695. };
  24696. return Word64;
  24697. })();
  24698. var calculateSHA256 = (function calculateSHA256Closure() {
  24699. function rotr(x, n) {
  24700. return (x >>> n) | (x << 32 - n);
  24701. }
  24702. function ch(x, y, z) {
  24703. return (x & y) ^ (~x & z);
  24704. }
  24705. function maj(x, y, z) {
  24706. return (x & y) ^ (x & z) ^ (y & z);
  24707. }
  24708. function sigma(x) {
  24709. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  24710. }
  24711. function sigmaPrime(x) {
  24712. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  24713. }
  24714. function littleSigma(x) {
  24715. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  24716. }
  24717. function littleSigmaPrime(x) {
  24718. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  24719. }
  24720. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  24721. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  24722. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  24723. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  24724. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  24725. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  24726. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  24727. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  24728. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  24729. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  24730. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  24731. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  24732. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  24733. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24734. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  24735. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  24736. function hash(data, offset, length) {
  24737. // initial hash values
  24738. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  24739. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  24740. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  24741. // pre-processing
  24742. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  24743. var padded = new Uint8Array(paddedLength);
  24744. var i, j, n;
  24745. for (i = 0; i < length; ++i) {
  24746. padded[i] = data[offset++];
  24747. }
  24748. padded[i++] = 0x80;
  24749. n = paddedLength - 8;
  24750. while (i < n) {
  24751. padded[i++] = 0;
  24752. }
  24753. padded[i++] = 0;
  24754. padded[i++] = 0;
  24755. padded[i++] = 0;
  24756. padded[i++] = (length >>> 29) & 0xFF;
  24757. padded[i++] = (length >> 21) & 0xFF;
  24758. padded[i++] = (length >> 13) & 0xFF;
  24759. padded[i++] = (length >> 5) & 0xFF;
  24760. padded[i++] = (length << 3) & 0xFF;
  24761. var w = new Uint32Array(64);
  24762. // for each 512 bit block
  24763. for (i = 0; i < paddedLength;) {
  24764. for (j = 0; j < 16; ++j) {
  24765. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  24766. (padded[i + 2] << 8) | (padded[i + 3]));
  24767. i += 4;
  24768. }
  24769. for (j = 16; j < 64; ++j) {
  24770. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  24771. littleSigma(w[j - 15]) + w[j - 16] | 0;
  24772. }
  24773. var a = h0, b = h1, c = h2, d = h3, e = h4,
  24774. f = h5, g = h6, h = h7, t1, t2;
  24775. for (j = 0; j < 64; ++j) {
  24776. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  24777. t2 = sigma(a) + maj(a, b, c);
  24778. h = g;
  24779. g = f;
  24780. f = e;
  24781. e = (d + t1) | 0;
  24782. d = c;
  24783. c = b;
  24784. b = a;
  24785. a = (t1 + t2) | 0;
  24786. }
  24787. h0 = (h0 + a) | 0;
  24788. h1 = (h1 + b) | 0;
  24789. h2 = (h2 + c) | 0;
  24790. h3 = (h3 + d) | 0;
  24791. h4 = (h4 + e) | 0;
  24792. h5 = (h5 + f) | 0;
  24793. h6 = (h6 + g) | 0;
  24794. h7 = (h7 + h) | 0;
  24795. }
  24796. return new Uint8Array([
  24797. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  24798. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  24799. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  24800. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  24801. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  24802. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  24803. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  24804. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  24805. ]);
  24806. }
  24807. return hash;
  24808. })();
  24809. var calculateSHA512 = (function calculateSHA512Closure() {
  24810. function ch(result, x, y, z, tmp) {
  24811. result.assign(x);
  24812. result.and(y);
  24813. tmp.assign(x);
  24814. tmp.not();
  24815. tmp.and(z);
  24816. result.xor(tmp);
  24817. }
  24818. function maj(result, x, y, z, tmp) {
  24819. result.assign(x);
  24820. result.and(y);
  24821. tmp.assign(x);
  24822. tmp.and(z);
  24823. result.xor(tmp);
  24824. tmp.assign(y);
  24825. tmp.and(z);
  24826. result.xor(tmp);
  24827. }
  24828. function sigma(result, x, tmp) {
  24829. result.assign(x);
  24830. result.rotateRight(28);
  24831. tmp.assign(x);
  24832. tmp.rotateRight(34);
  24833. result.xor(tmp);
  24834. tmp.assign(x);
  24835. tmp.rotateRight(39);
  24836. result.xor(tmp);
  24837. }
  24838. function sigmaPrime(result, x, tmp) {
  24839. result.assign(x);
  24840. result.rotateRight(14);
  24841. tmp.assign(x);
  24842. tmp.rotateRight(18);
  24843. result.xor(tmp);
  24844. tmp.assign(x);
  24845. tmp.rotateRight(41);
  24846. result.xor(tmp);
  24847. }
  24848. function littleSigma(result, x, tmp) {
  24849. result.assign(x);
  24850. result.rotateRight(1);
  24851. tmp.assign(x);
  24852. tmp.rotateRight(8);
  24853. result.xor(tmp);
  24854. tmp.assign(x);
  24855. tmp.shiftRight(7);
  24856. result.xor(tmp);
  24857. }
  24858. function littleSigmaPrime(result, x, tmp) {
  24859. result.assign(x);
  24860. result.rotateRight(19);
  24861. tmp.assign(x);
  24862. tmp.rotateRight(61);
  24863. result.xor(tmp);
  24864. tmp.assign(x);
  24865. tmp.shiftRight(6);
  24866. result.xor(tmp);
  24867. }
  24868. var k = [
  24869. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  24870. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  24871. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  24872. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  24873. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  24874. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  24875. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  24876. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  24877. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  24878. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  24879. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  24880. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  24881. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  24882. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  24883. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  24884. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  24885. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  24886. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  24887. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  24888. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  24889. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  24890. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  24891. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  24892. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  24893. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  24894. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  24895. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  24896. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  24897. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  24898. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  24899. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  24900. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  24901. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  24902. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  24903. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  24904. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  24905. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  24906. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  24907. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  24908. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  24909. function hash(data, offset, length, mode384) {
  24910. mode384 = !!mode384;
  24911. // initial hash values
  24912. var h0, h1, h2, h3, h4, h5, h6, h7;
  24913. if (!mode384) {
  24914. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  24915. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  24916. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  24917. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  24918. h4 = new Word64(0x510e527f, 0xade682d1);
  24919. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  24920. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  24921. h7 = new Word64(0x5be0cd19, 0x137e2179);
  24922. }
  24923. else {
  24924. // SHA384 is exactly the same
  24925. // except with different starting values and a trimmed result
  24926. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  24927. h1 = new Word64(0x629a292a, 0x367cd507);
  24928. h2 = new Word64(0x9159015a, 0x3070dd17);
  24929. h3 = new Word64(0x152fecd8, 0xf70e5939);
  24930. h4 = new Word64(0x67332667, 0xffc00b31);
  24931. h5 = new Word64(0x8eb44a87, 0x68581511);
  24932. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  24933. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  24934. }
  24935. // pre-processing
  24936. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  24937. var padded = new Uint8Array(paddedLength);
  24938. var i, j, n;
  24939. for (i = 0; i < length; ++i) {
  24940. padded[i] = data[offset++];
  24941. }
  24942. padded[i++] = 0x80;
  24943. n = paddedLength - 16;
  24944. while (i < n) {
  24945. padded[i++] = 0;
  24946. }
  24947. padded[i++] = 0;
  24948. padded[i++] = 0;
  24949. padded[i++] = 0;
  24950. padded[i++] = 0;
  24951. padded[i++] = 0;
  24952. padded[i++] = 0;
  24953. padded[i++] = 0;
  24954. padded[i++] = 0;
  24955. padded[i++] = 0;
  24956. padded[i++] = 0;
  24957. padded[i++] = 0;
  24958. padded[i++] = (length >>> 29) & 0xFF;
  24959. padded[i++] = (length >> 21) & 0xFF;
  24960. padded[i++] = (length >> 13) & 0xFF;
  24961. padded[i++] = (length >> 5) & 0xFF;
  24962. padded[i++] = (length << 3) & 0xFF;
  24963. var w = new Array(80);
  24964. for (i = 0; i < 80; i++) {
  24965. w[i] = new Word64(0, 0);
  24966. }
  24967. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  24968. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  24969. var g = new Word64(0, 0), h = new Word64(0, 0);
  24970. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  24971. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  24972. // for each 1024 bit block
  24973. for (i = 0; i < paddedLength;) {
  24974. for (j = 0; j < 16; ++j) {
  24975. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  24976. (padded[i + 2] << 8) | (padded[i + 3]);
  24977. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  24978. (padded[i + 6]) << 8 | (padded[i + 7]);
  24979. i += 8;
  24980. }
  24981. for (j = 16; j < 80; ++j) {
  24982. tmp3 = w[j];
  24983. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  24984. tmp3.add(w[j - 7]);
  24985. littleSigma(tmp1, w[j - 15], tmp2);
  24986. tmp3.add(tmp1);
  24987. tmp3.add(w[j - 16]);
  24988. }
  24989. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  24990. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  24991. for (j = 0; j < 80; ++j) {
  24992. t1.assign(h);
  24993. sigmaPrime(tmp1, e, tmp2);
  24994. t1.add(tmp1);
  24995. ch(tmp1, e, f, g, tmp2);
  24996. t1.add(tmp1);
  24997. t1.add(k[j]);
  24998. t1.add(w[j]);
  24999. sigma(t2, a, tmp2);
  25000. maj(tmp1, a, b, c, tmp2);
  25001. t2.add(tmp1);
  25002. tmp3 = h;
  25003. h = g;
  25004. g = f;
  25005. f = e;
  25006. d.add(t1);
  25007. e = d;
  25008. d = c;
  25009. c = b;
  25010. b = a;
  25011. tmp3.assign(t1);
  25012. tmp3.add(t2);
  25013. a = tmp3;
  25014. }
  25015. h0.add(a);
  25016. h1.add(b);
  25017. h2.add(c);
  25018. h3.add(d);
  25019. h4.add(e);
  25020. h5.add(f);
  25021. h6.add(g);
  25022. h7.add(h);
  25023. }
  25024. var result;
  25025. if (!mode384) {
  25026. result = new Uint8Array(64);
  25027. h0.copyTo(result,0);
  25028. h1.copyTo(result,8);
  25029. h2.copyTo(result,16);
  25030. h3.copyTo(result,24);
  25031. h4.copyTo(result,32);
  25032. h5.copyTo(result,40);
  25033. h6.copyTo(result,48);
  25034. h7.copyTo(result,56);
  25035. }
  25036. else {
  25037. result = new Uint8Array(48);
  25038. h0.copyTo(result,0);
  25039. h1.copyTo(result,8);
  25040. h2.copyTo(result,16);
  25041. h3.copyTo(result,24);
  25042. h4.copyTo(result,32);
  25043. h5.copyTo(result,40);
  25044. }
  25045. return result;
  25046. }
  25047. return hash;
  25048. })();
  25049. var calculateSHA384 = (function calculateSHA384Closure() {
  25050. function hash(data, offset, length) {
  25051. return calculateSHA512(data, offset, length, true);
  25052. }
  25053. return hash;
  25054. })();
  25055. var NullCipher = (function NullCipherClosure() {
  25056. function NullCipher() {
  25057. }
  25058. NullCipher.prototype = {
  25059. decryptBlock: function NullCipher_decryptBlock(data) {
  25060. return data;
  25061. }
  25062. };
  25063. return NullCipher;
  25064. })();
  25065. var AES128Cipher = (function AES128CipherClosure() {
  25066. var rcon = new Uint8Array([
  25067. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25068. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25069. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25070. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25071. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25072. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25073. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25074. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25075. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25076. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25077. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25078. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25079. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25080. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25081. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25082. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25083. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25084. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25085. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25086. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25087. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25088. 0x74, 0xe8, 0xcb, 0x8d]);
  25089. var s = new Uint8Array([
  25090. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25091. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25092. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25093. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25094. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25095. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25096. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25097. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25098. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25099. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25100. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25101. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25102. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25103. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25104. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25105. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25106. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25107. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25108. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25109. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25110. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25111. 0xb0, 0x54, 0xbb, 0x16]);
  25112. var inv_s = new Uint8Array([
  25113. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25114. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25115. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25116. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25117. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25118. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25119. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25120. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25121. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25122. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25123. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25124. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25125. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25126. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25127. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25128. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25129. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25130. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25131. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25132. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25133. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25134. 0x55, 0x21, 0x0c, 0x7d]);
  25135. var mixCol = new Uint8Array(256);
  25136. for (var i = 0; i < 256; i++) {
  25137. if (i < 128) {
  25138. mixCol[i] = i << 1;
  25139. } else {
  25140. mixCol[i] = (i << 1) ^ 0x1b;
  25141. }
  25142. }
  25143. var mix = new Uint32Array([
  25144. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25145. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25146. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25147. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25148. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25149. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25150. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25151. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25152. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25153. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25154. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25155. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25156. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25157. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25158. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25159. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25160. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25161. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25162. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25163. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25164. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25165. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25166. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25167. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25168. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25169. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25170. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25171. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25172. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25173. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25174. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25175. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25176. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25177. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25178. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25179. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25180. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25181. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25182. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25183. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25184. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25185. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25186. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25187. function expandKey128(cipherKey) {
  25188. var b = 176, result = new Uint8Array(b);
  25189. result.set(cipherKey);
  25190. for (var j = 16, i = 1; j < b; ++i) {
  25191. // RotWord
  25192. var t1 = result[j - 3], t2 = result[j - 2],
  25193. t3 = result[j - 1], t4 = result[j - 4];
  25194. // SubWord
  25195. t1 = s[t1];
  25196. t2 = s[t2];
  25197. t3 = s[t3];
  25198. t4 = s[t4];
  25199. // Rcon
  25200. t1 = t1 ^ rcon[i];
  25201. for (var n = 0; n < 4; ++n) {
  25202. result[j] = (t1 ^= result[j - 16]);
  25203. j++;
  25204. result[j] = (t2 ^= result[j - 16]);
  25205. j++;
  25206. result[j] = (t3 ^= result[j - 16]);
  25207. j++;
  25208. result[j] = (t4 ^= result[j - 16]);
  25209. j++;
  25210. }
  25211. }
  25212. return result;
  25213. }
  25214. function decrypt128(input, key) {
  25215. var state = new Uint8Array(16);
  25216. state.set(input);
  25217. var i, j, k;
  25218. var t, u, v;
  25219. // AddRoundKey
  25220. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25221. state[j] ^= key[k];
  25222. }
  25223. for (i = 9; i >= 1; --i) {
  25224. // InvShiftRows
  25225. t = state[13];
  25226. state[13] = state[9];
  25227. state[9] = state[5];
  25228. state[5] = state[1];
  25229. state[1] = t;
  25230. t = state[14];
  25231. u = state[10];
  25232. state[14] = state[6];
  25233. state[10] = state[2];
  25234. state[6] = t;
  25235. state[2] = u;
  25236. t = state[15];
  25237. u = state[11];
  25238. v = state[7];
  25239. state[15] = state[3];
  25240. state[11] = t;
  25241. state[7] = u;
  25242. state[3] = v;
  25243. // InvSubBytes
  25244. for (j = 0; j < 16; ++j) {
  25245. state[j] = inv_s[state[j]];
  25246. }
  25247. // AddRoundKey
  25248. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25249. state[j] ^= key[k];
  25250. }
  25251. // InvMixColumns
  25252. for (j = 0; j < 16; j += 4) {
  25253. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25254. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25255. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25256. (s3 >>> 24) ^ (s3 << 8));
  25257. state[j] = (t >>> 24) & 0xFF;
  25258. state[j + 1] = (t >> 16) & 0xFF;
  25259. state[j + 2] = (t >> 8) & 0xFF;
  25260. state[j + 3] = t & 0xFF;
  25261. }
  25262. }
  25263. // InvShiftRows
  25264. t = state[13];
  25265. state[13] = state[9];
  25266. state[9] = state[5];
  25267. state[5] = state[1];
  25268. state[1] = t;
  25269. t = state[14];
  25270. u = state[10];
  25271. state[14] = state[6];
  25272. state[10] = state[2];
  25273. state[6] = t;
  25274. state[2] = u;
  25275. t = state[15];
  25276. u = state[11];
  25277. v = state[7];
  25278. state[15] = state[3];
  25279. state[11] = t;
  25280. state[7] = u;
  25281. state[3] = v;
  25282. for (j = 0; j < 16; ++j) {
  25283. // InvSubBytes
  25284. state[j] = inv_s[state[j]];
  25285. // AddRoundKey
  25286. state[j] ^= key[j];
  25287. }
  25288. return state;
  25289. }
  25290. function encrypt128(input, key) {
  25291. var t, u, v, k;
  25292. var state = new Uint8Array(16);
  25293. state.set(input);
  25294. for (j = 0; j < 16; ++j) {
  25295. // AddRoundKey
  25296. state[j] ^= key[j];
  25297. }
  25298. for (i = 1; i < 10; i++) {
  25299. //SubBytes
  25300. for (j = 0; j < 16; ++j) {
  25301. state[j] = s[state[j]];
  25302. }
  25303. //ShiftRows
  25304. v = state[1];
  25305. state[1] = state[5];
  25306. state[5] = state[9];
  25307. state[9] = state[13];
  25308. state[13] = v;
  25309. v = state[2];
  25310. u = state[6];
  25311. state[2] = state[10];
  25312. state[6] = state[14];
  25313. state[10] = v;
  25314. state[14] = u;
  25315. v = state[3];
  25316. u = state[7];
  25317. t = state[11];
  25318. state[3] = state[15];
  25319. state[7] = v;
  25320. state[11] = u;
  25321. state[15] = t;
  25322. //MixColumns
  25323. for (var j = 0; j < 16; j += 4) {
  25324. var s0 = state[j + 0], s1 = state[j + 1];
  25325. var s2 = state[j + 2], s3 = state[j + 3];
  25326. t = s0 ^ s1 ^ s2 ^ s3;
  25327. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25328. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25329. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25330. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25331. }
  25332. //AddRoundKey
  25333. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25334. state[j] ^= key[k];
  25335. }
  25336. }
  25337. //SubBytes
  25338. for (j = 0; j < 16; ++j) {
  25339. state[j] = s[state[j]];
  25340. }
  25341. //ShiftRows
  25342. v = state[1];
  25343. state[1] = state[5];
  25344. state[5] = state[9];
  25345. state[9] = state[13];
  25346. state[13] = v;
  25347. v = state[2];
  25348. u = state[6];
  25349. state[2] = state[10];
  25350. state[6] = state[14];
  25351. state[10] = v;
  25352. state[14] = u;
  25353. v = state[3];
  25354. u = state[7];
  25355. t = state[11];
  25356. state[3] = state[15];
  25357. state[7] = v;
  25358. state[11] = u;
  25359. state[15] = t;
  25360. //AddRoundKey
  25361. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25362. state[j] ^= key[k];
  25363. }
  25364. return state;
  25365. }
  25366. function AES128Cipher(key) {
  25367. this.key = expandKey128(key);
  25368. this.buffer = new Uint8Array(16);
  25369. this.bufferPosition = 0;
  25370. }
  25371. function decryptBlock2(data, finalize) {
  25372. var i, j, ii, sourceLength = data.length,
  25373. buffer = this.buffer, bufferLength = this.bufferPosition,
  25374. result = [], iv = this.iv;
  25375. for (i = 0; i < sourceLength; ++i) {
  25376. buffer[bufferLength] = data[i];
  25377. ++bufferLength;
  25378. if (bufferLength < 16) {
  25379. continue;
  25380. }
  25381. // buffer is full, decrypting
  25382. var plain = decrypt128(buffer, this.key);
  25383. // xor-ing the IV vector to get plain text
  25384. for (j = 0; j < 16; ++j) {
  25385. plain[j] ^= iv[j];
  25386. }
  25387. iv = buffer;
  25388. result.push(plain);
  25389. buffer = new Uint8Array(16);
  25390. bufferLength = 0;
  25391. }
  25392. // saving incomplete buffer
  25393. this.buffer = buffer;
  25394. this.bufferLength = bufferLength;
  25395. this.iv = iv;
  25396. if (result.length === 0) {
  25397. return new Uint8Array([]);
  25398. }
  25399. // combining plain text blocks into one
  25400. var outputLength = 16 * result.length;
  25401. if (finalize) {
  25402. // undo a padding that is described in RFC 2898
  25403. var lastBlock = result[result.length - 1];
  25404. var psLen = lastBlock[15];
  25405. if (psLen <= 16) {
  25406. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25407. if (lastBlock[i] !== psLen) {
  25408. // Invalid padding, assume that the block has no padding.
  25409. psLen = 0;
  25410. break;
  25411. }
  25412. }
  25413. outputLength -= psLen;
  25414. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25415. }
  25416. }
  25417. var output = new Uint8Array(outputLength);
  25418. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25419. output.set(result[i], j);
  25420. }
  25421. return output;
  25422. }
  25423. AES128Cipher.prototype = {
  25424. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  25425. var i, sourceLength = data.length;
  25426. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25427. // waiting for IV values -- they are at the start of the stream
  25428. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  25429. buffer[bufferLength] = data[i];
  25430. }
  25431. if (bufferLength < 16) {
  25432. // need more data
  25433. this.bufferLength = bufferLength;
  25434. return new Uint8Array([]);
  25435. }
  25436. this.iv = buffer;
  25437. this.buffer = new Uint8Array(16);
  25438. this.bufferLength = 0;
  25439. // starting decryption
  25440. this.decryptBlock = decryptBlock2;
  25441. return this.decryptBlock(data.subarray(16), finalize);
  25442. },
  25443. encrypt: function AES128Cipher_encrypt(data, iv) {
  25444. var i, j, ii, sourceLength = data.length,
  25445. buffer = this.buffer, bufferLength = this.bufferPosition,
  25446. result = [];
  25447. if (!iv) {
  25448. iv = new Uint8Array(16);
  25449. }
  25450. for (i = 0; i < sourceLength; ++i) {
  25451. buffer[bufferLength] = data[i];
  25452. ++bufferLength;
  25453. if (bufferLength < 16) {
  25454. continue;
  25455. }
  25456. for (j = 0; j < 16; ++j) {
  25457. buffer[j] ^= iv[j];
  25458. }
  25459. // buffer is full, encrypting
  25460. var cipher = encrypt128(buffer, this.key);
  25461. iv = cipher;
  25462. result.push(cipher);
  25463. buffer = new Uint8Array(16);
  25464. bufferLength = 0;
  25465. }
  25466. // saving incomplete buffer
  25467. this.buffer = buffer;
  25468. this.bufferLength = bufferLength;
  25469. this.iv = iv;
  25470. if (result.length === 0) {
  25471. return new Uint8Array([]);
  25472. }
  25473. // combining plain text blocks into one
  25474. var outputLength = 16 * result.length;
  25475. var output = new Uint8Array(outputLength);
  25476. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25477. output.set(result[i], j);
  25478. }
  25479. return output;
  25480. }
  25481. };
  25482. return AES128Cipher;
  25483. })();
  25484. var AES256Cipher = (function AES256CipherClosure() {
  25485. var rcon = new Uint8Array([
  25486. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25487. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25488. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25489. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25490. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25491. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25492. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25493. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25494. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25495. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25496. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25497. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25498. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25499. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25500. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25501. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25502. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25503. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25504. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25505. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25506. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25507. 0x74, 0xe8, 0xcb, 0x8d]);
  25508. var s = new Uint8Array([
  25509. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25510. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25511. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25512. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25513. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25514. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25515. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25516. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25517. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25518. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25519. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25520. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25521. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25522. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25523. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25524. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25525. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25526. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25527. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25528. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25529. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25530. 0xb0, 0x54, 0xbb, 0x16]);
  25531. var inv_s = new Uint8Array([
  25532. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25533. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25534. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25535. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25536. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25537. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25538. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25539. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25540. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25541. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25542. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25543. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25544. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25545. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25546. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25547. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25548. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25549. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25550. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25551. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25552. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25553. 0x55, 0x21, 0x0c, 0x7d]);
  25554. var mixCol = new Uint8Array(256);
  25555. for (var i = 0; i < 256; i++) {
  25556. if (i < 128) {
  25557. mixCol[i] = i << 1;
  25558. } else {
  25559. mixCol[i] = (i << 1) ^ 0x1b;
  25560. }
  25561. }
  25562. var mix = new Uint32Array([
  25563. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25564. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25565. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25566. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25567. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25568. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25569. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25570. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25571. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25572. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25573. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25574. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25575. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25576. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25577. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25578. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25579. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25580. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25581. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25582. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25583. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25584. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25585. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25586. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25587. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25588. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25589. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25590. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25591. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25592. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25593. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25594. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25595. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25596. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25597. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25598. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25599. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25600. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25601. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25602. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25603. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25604. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25605. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25606. function expandKey256(cipherKey) {
  25607. var b = 240, result = new Uint8Array(b);
  25608. var r = 1;
  25609. result.set(cipherKey);
  25610. for (var j = 32, i = 1; j < b; ++i) {
  25611. if (j % 32 === 16) {
  25612. t1 = s[t1];
  25613. t2 = s[t2];
  25614. t3 = s[t3];
  25615. t4 = s[t4];
  25616. } else if (j % 32 === 0) {
  25617. // RotWord
  25618. var t1 = result[j - 3], t2 = result[j - 2],
  25619. t3 = result[j - 1], t4 = result[j - 4];
  25620. // SubWord
  25621. t1 = s[t1];
  25622. t2 = s[t2];
  25623. t3 = s[t3];
  25624. t4 = s[t4];
  25625. // Rcon
  25626. t1 = t1 ^ r;
  25627. if ((r <<= 1) >= 256) {
  25628. r = (r ^ 0x1b) & 0xFF;
  25629. }
  25630. }
  25631. for (var n = 0; n < 4; ++n) {
  25632. result[j] = (t1 ^= result[j - 32]);
  25633. j++;
  25634. result[j] = (t2 ^= result[j - 32]);
  25635. j++;
  25636. result[j] = (t3 ^= result[j - 32]);
  25637. j++;
  25638. result[j] = (t4 ^= result[j - 32]);
  25639. j++;
  25640. }
  25641. }
  25642. return result;
  25643. }
  25644. function decrypt256(input, key) {
  25645. var state = new Uint8Array(16);
  25646. state.set(input);
  25647. var i, j, k;
  25648. var t, u, v;
  25649. // AddRoundKey
  25650. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25651. state[j] ^= key[k];
  25652. }
  25653. for (i = 13; i >= 1; --i) {
  25654. // InvShiftRows
  25655. t = state[13];
  25656. state[13] = state[9];
  25657. state[9] = state[5];
  25658. state[5] = state[1];
  25659. state[1] = t;
  25660. t = state[14];
  25661. u = state[10];
  25662. state[14] = state[6];
  25663. state[10] = state[2];
  25664. state[6] = t;
  25665. state[2] = u;
  25666. t = state[15];
  25667. u = state[11];
  25668. v = state[7];
  25669. state[15] = state[3];
  25670. state[11] = t;
  25671. state[7] = u;
  25672. state[3] = v;
  25673. // InvSubBytes
  25674. for (j = 0; j < 16; ++j) {
  25675. state[j] = inv_s[state[j]];
  25676. }
  25677. // AddRoundKey
  25678. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25679. state[j] ^= key[k];
  25680. }
  25681. // InvMixColumns
  25682. for (j = 0; j < 16; j += 4) {
  25683. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25684. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25685. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25686. (s3 >>> 24) ^ (s3 << 8));
  25687. state[j] = (t >>> 24) & 0xFF;
  25688. state[j + 1] = (t >> 16) & 0xFF;
  25689. state[j + 2] = (t >> 8) & 0xFF;
  25690. state[j + 3] = t & 0xFF;
  25691. }
  25692. }
  25693. // InvShiftRows
  25694. t = state[13];
  25695. state[13] = state[9];
  25696. state[9] = state[5];
  25697. state[5] = state[1];
  25698. state[1] = t;
  25699. t = state[14];
  25700. u = state[10];
  25701. state[14] = state[6];
  25702. state[10] = state[2];
  25703. state[6] = t;
  25704. state[2] = u;
  25705. t = state[15];
  25706. u = state[11];
  25707. v = state[7];
  25708. state[15] = state[3];
  25709. state[11] = t;
  25710. state[7] = u;
  25711. state[3] = v;
  25712. for (j = 0; j < 16; ++j) {
  25713. // InvSubBytes
  25714. state[j] = inv_s[state[j]];
  25715. // AddRoundKey
  25716. state[j] ^= key[j];
  25717. }
  25718. return state;
  25719. }
  25720. function encrypt256(input, key) {
  25721. var t, u, v, k;
  25722. var state = new Uint8Array(16);
  25723. state.set(input);
  25724. for (j = 0; j < 16; ++j) {
  25725. // AddRoundKey
  25726. state[j] ^= key[j];
  25727. }
  25728. for (i = 1; i < 14; i++) {
  25729. //SubBytes
  25730. for (j = 0; j < 16; ++j) {
  25731. state[j] = s[state[j]];
  25732. }
  25733. //ShiftRows
  25734. v = state[1];
  25735. state[1] = state[5];
  25736. state[5] = state[9];
  25737. state[9] = state[13];
  25738. state[13] = v;
  25739. v = state[2];
  25740. u = state[6];
  25741. state[2] = state[10];
  25742. state[6] = state[14];
  25743. state[10] = v;
  25744. state[14] = u;
  25745. v = state[3];
  25746. u = state[7];
  25747. t = state[11];
  25748. state[3] = state[15];
  25749. state[7] = v;
  25750. state[11] = u;
  25751. state[15] = t;
  25752. //MixColumns
  25753. for (var j = 0; j < 16; j += 4) {
  25754. var s0 = state[j + 0], s1 = state[j + 1];
  25755. var s2 = state[j + 2], s3 = state[j + 3];
  25756. t = s0 ^ s1 ^ s2 ^ s3;
  25757. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25758. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25759. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25760. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25761. }
  25762. //AddRoundKey
  25763. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25764. state[j] ^= key[k];
  25765. }
  25766. }
  25767. //SubBytes
  25768. for (j = 0; j < 16; ++j) {
  25769. state[j] = s[state[j]];
  25770. }
  25771. //ShiftRows
  25772. v = state[1];
  25773. state[1] = state[5];
  25774. state[5] = state[9];
  25775. state[9] = state[13];
  25776. state[13] = v;
  25777. v = state[2];
  25778. u = state[6];
  25779. state[2] = state[10];
  25780. state[6] = state[14];
  25781. state[10] = v;
  25782. state[14] = u;
  25783. v = state[3];
  25784. u = state[7];
  25785. t = state[11];
  25786. state[3] = state[15];
  25787. state[7] = v;
  25788. state[11] = u;
  25789. state[15] = t;
  25790. //AddRoundKey
  25791. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25792. state[j] ^= key[k];
  25793. }
  25794. return state;
  25795. }
  25796. function AES256Cipher(key) {
  25797. this.key = expandKey256(key);
  25798. this.buffer = new Uint8Array(16);
  25799. this.bufferPosition = 0;
  25800. }
  25801. function decryptBlock2(data, finalize) {
  25802. var i, j, ii, sourceLength = data.length,
  25803. buffer = this.buffer, bufferLength = this.bufferPosition,
  25804. result = [], iv = this.iv;
  25805. for (i = 0; i < sourceLength; ++i) {
  25806. buffer[bufferLength] = data[i];
  25807. ++bufferLength;
  25808. if (bufferLength < 16) {
  25809. continue;
  25810. }
  25811. // buffer is full, decrypting
  25812. var plain = decrypt256(buffer, this.key);
  25813. // xor-ing the IV vector to get plain text
  25814. for (j = 0; j < 16; ++j) {
  25815. plain[j] ^= iv[j];
  25816. }
  25817. iv = buffer;
  25818. result.push(plain);
  25819. buffer = new Uint8Array(16);
  25820. bufferLength = 0;
  25821. }
  25822. // saving incomplete buffer
  25823. this.buffer = buffer;
  25824. this.bufferLength = bufferLength;
  25825. this.iv = iv;
  25826. if (result.length === 0) {
  25827. return new Uint8Array([]);
  25828. }
  25829. // combining plain text blocks into one
  25830. var outputLength = 16 * result.length;
  25831. if (finalize) {
  25832. // undo a padding that is described in RFC 2898
  25833. var lastBlock = result[result.length - 1];
  25834. var psLen = lastBlock[15];
  25835. if (psLen <= 16) {
  25836. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25837. if (lastBlock[i] !== psLen) {
  25838. // Invalid padding, assume that the block has no padding.
  25839. psLen = 0;
  25840. break;
  25841. }
  25842. }
  25843. outputLength -= psLen;
  25844. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25845. }
  25846. }
  25847. var output = new Uint8Array(outputLength);
  25848. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25849. output.set(result[i], j);
  25850. }
  25851. return output;
  25852. }
  25853. AES256Cipher.prototype = {
  25854. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  25855. var i, sourceLength = data.length;
  25856. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25857. // if not supplied an IV wait for IV values
  25858. // they are at the start of the stream
  25859. if (iv) {
  25860. this.iv = iv;
  25861. } else {
  25862. for (i = 0; bufferLength < 16 &&
  25863. i < sourceLength; ++i, ++bufferLength) {
  25864. buffer[bufferLength] = data[i];
  25865. }
  25866. if (bufferLength < 16) {
  25867. //need more data
  25868. this.bufferLength = bufferLength;
  25869. return new Uint8Array([]);
  25870. }
  25871. this.iv = buffer;
  25872. data = data.subarray(16);
  25873. }
  25874. this.buffer = new Uint8Array(16);
  25875. this.bufferLength = 0;
  25876. // starting decryption
  25877. this.decryptBlock = decryptBlock2;
  25878. return this.decryptBlock(data, finalize);
  25879. },
  25880. encrypt: function AES256Cipher_encrypt(data, iv) {
  25881. var i, j, ii, sourceLength = data.length,
  25882. buffer = this.buffer, bufferLength = this.bufferPosition,
  25883. result = [];
  25884. if (!iv) {
  25885. iv = new Uint8Array(16);
  25886. }
  25887. for (i = 0; i < sourceLength; ++i) {
  25888. buffer[bufferLength] = data[i];
  25889. ++bufferLength;
  25890. if (bufferLength < 16) {
  25891. continue;
  25892. }
  25893. for (j = 0; j < 16; ++j) {
  25894. buffer[j] ^= iv[j];
  25895. }
  25896. // buffer is full, encrypting
  25897. var cipher = encrypt256(buffer, this.key);
  25898. this.iv = cipher;
  25899. result.push(cipher);
  25900. buffer = new Uint8Array(16);
  25901. bufferLength = 0;
  25902. }
  25903. // saving incomplete buffer
  25904. this.buffer = buffer;
  25905. this.bufferLength = bufferLength;
  25906. this.iv = iv;
  25907. if (result.length === 0) {
  25908. return new Uint8Array([]);
  25909. }
  25910. // combining plain text blocks into one
  25911. var outputLength = 16 * result.length;
  25912. var output = new Uint8Array(outputLength);
  25913. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25914. output.set(result[i], j);
  25915. }
  25916. return output;
  25917. }
  25918. };
  25919. return AES256Cipher;
  25920. })();
  25921. var PDF17 = (function PDF17Closure() {
  25922. function compareByteArrays(array1, array2) {
  25923. if (array1.length !== array2.length) {
  25924. return false;
  25925. }
  25926. for (var i = 0; i < array1.length; i++) {
  25927. if (array1[i] !== array2[i]) {
  25928. return false;
  25929. }
  25930. }
  25931. return true;
  25932. }
  25933. function PDF17() {
  25934. }
  25935. PDF17.prototype = {
  25936. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  25937. ownerValidationSalt,
  25938. userBytes,
  25939. ownerPassword) {
  25940. var hashData = new Uint8Array(password.length + 56);
  25941. hashData.set(password, 0);
  25942. hashData.set(ownerValidationSalt, password.length);
  25943. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25944. var result = calculateSHA256(hashData, 0, hashData.length);
  25945. return compareByteArrays(result, ownerPassword);
  25946. },
  25947. checkUserPassword: function PDF17_checkUserPassword(password,
  25948. userValidationSalt,
  25949. userPassword) {
  25950. var hashData = new Uint8Array(password.length + 8);
  25951. hashData.set(password, 0);
  25952. hashData.set(userValidationSalt, password.length);
  25953. var result = calculateSHA256(hashData, 0, hashData.length);
  25954. return compareByteArrays(result, userPassword);
  25955. },
  25956. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  25957. ownerEncryption) {
  25958. var hashData = new Uint8Array(password.length + 56);
  25959. hashData.set(password, 0);
  25960. hashData.set(ownerKeySalt, password.length);
  25961. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25962. var key = calculateSHA256(hashData, 0, hashData.length);
  25963. var cipher = new AES256Cipher(key);
  25964. return cipher.decryptBlock(ownerEncryption,
  25965. false,
  25966. new Uint8Array(16));
  25967. },
  25968. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  25969. userEncryption) {
  25970. var hashData = new Uint8Array(password.length + 8);
  25971. hashData.set(password, 0);
  25972. hashData.set(userKeySalt, password.length);
  25973. //key is the decryption key for the UE string
  25974. var key = calculateSHA256(hashData, 0, hashData.length);
  25975. var cipher = new AES256Cipher(key);
  25976. return cipher.decryptBlock(userEncryption,
  25977. false,
  25978. new Uint8Array(16));
  25979. }
  25980. };
  25981. return PDF17;
  25982. })();
  25983. var PDF20 = (function PDF20Closure() {
  25984. function concatArrays(array1, array2) {
  25985. var t = new Uint8Array(array1.length + array2.length);
  25986. t.set(array1, 0);
  25987. t.set(array2, array1.length);
  25988. return t;
  25989. }
  25990. function calculatePDF20Hash(password, input, userBytes) {
  25991. //This refers to Algorithm 2.B as defined in ISO 32000-2
  25992. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  25993. var e = [0];
  25994. var i = 0;
  25995. while (i < 64 || e[e.length - 1] > i - 32) {
  25996. var arrayLength = password.length + k.length + userBytes.length;
  25997. var k1 = new Uint8Array(arrayLength * 64);
  25998. var array = concatArrays(password, k);
  25999. array = concatArrays(array, userBytes);
  26000. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  26001. k1.set(array, pos);
  26002. }
  26003. //AES128 CBC NO PADDING with
  26004. //first 16 bytes of k as the key and the second 16 as the iv.
  26005. var cipher = new AES128Cipher(k.subarray(0, 16));
  26006. e = cipher.encrypt(k1, k.subarray(16, 32));
  26007. //Now we have to take the first 16 bytes of an unsigned
  26008. //big endian integer... and compute the remainder
  26009. //modulo 3.... That is a fairly large number and
  26010. //JavaScript isn't going to handle that well...
  26011. //So we're using a trick that allows us to perform
  26012. //modulo math byte by byte
  26013. var remainder = 0;
  26014. for (var z = 0; z < 16; z++) {
  26015. remainder *= (256 % 3);
  26016. remainder %= 3;
  26017. remainder += ((e[z] >>> 0) % 3);
  26018. remainder %= 3;
  26019. }
  26020. if (remainder === 0) {
  26021. k = calculateSHA256(e, 0, e.length);
  26022. }
  26023. else if (remainder === 1) {
  26024. k = calculateSHA384(e, 0, e.length);
  26025. }
  26026. else if (remainder === 2) {
  26027. k = calculateSHA512(e, 0, e.length);
  26028. }
  26029. i++;
  26030. }
  26031. return k.subarray(0, 32);
  26032. }
  26033. function PDF20() {
  26034. }
  26035. function compareByteArrays(array1, array2) {
  26036. if (array1.length !== array2.length) {
  26037. return false;
  26038. }
  26039. for (var i = 0; i < array1.length; i++) {
  26040. if (array1[i] !== array2[i]) {
  26041. return false;
  26042. }
  26043. }
  26044. return true;
  26045. }
  26046. PDF20.prototype = {
  26047. hash: function PDF20_hash(password, concatBytes, userBytes) {
  26048. return calculatePDF20Hash(password, concatBytes, userBytes);
  26049. },
  26050. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  26051. ownerValidationSalt,
  26052. userBytes,
  26053. ownerPassword) {
  26054. var hashData = new Uint8Array(password.length + 56);
  26055. hashData.set(password, 0);
  26056. hashData.set(ownerValidationSalt, password.length);
  26057. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26058. var result = calculatePDF20Hash(password, hashData, userBytes);
  26059. return compareByteArrays(result, ownerPassword);
  26060. },
  26061. checkUserPassword: function PDF20_checkUserPassword(password,
  26062. userValidationSalt,
  26063. userPassword) {
  26064. var hashData = new Uint8Array(password.length + 8);
  26065. hashData.set(password, 0);
  26066. hashData.set(userValidationSalt, password.length);
  26067. var result = calculatePDF20Hash(password, hashData, []);
  26068. return compareByteArrays(result, userPassword);
  26069. },
  26070. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  26071. ownerEncryption) {
  26072. var hashData = new Uint8Array(password.length + 56);
  26073. hashData.set(password, 0);
  26074. hashData.set(ownerKeySalt, password.length);
  26075. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26076. var key = calculatePDF20Hash(password, hashData, userBytes);
  26077. var cipher = new AES256Cipher(key);
  26078. return cipher.decryptBlock(ownerEncryption,
  26079. false,
  26080. new Uint8Array(16));
  26081. },
  26082. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  26083. userEncryption) {
  26084. var hashData = new Uint8Array(password.length + 8);
  26085. hashData.set(password, 0);
  26086. hashData.set(userKeySalt, password.length);
  26087. //key is the decryption key for the UE string
  26088. var key = calculatePDF20Hash(password, hashData, []);
  26089. var cipher = new AES256Cipher(key);
  26090. return cipher.decryptBlock(userEncryption,
  26091. false,
  26092. new Uint8Array(16));
  26093. }
  26094. };
  26095. return PDF20;
  26096. })();
  26097. var CipherTransform = (function CipherTransformClosure() {
  26098. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  26099. this.stringCipherConstructor = stringCipherConstructor;
  26100. this.streamCipherConstructor = streamCipherConstructor;
  26101. }
  26102. CipherTransform.prototype = {
  26103. createStream: function CipherTransform_createStream(stream, length) {
  26104. var cipher = new this.streamCipherConstructor();
  26105. return new DecryptStream(stream, length,
  26106. function cipherTransformDecryptStream(data, finalize) {
  26107. return cipher.decryptBlock(data, finalize);
  26108. }
  26109. );
  26110. },
  26111. decryptString: function CipherTransform_decryptString(s) {
  26112. var cipher = new this.stringCipherConstructor();
  26113. var data = stringToBytes(s);
  26114. data = cipher.decryptBlock(data, true);
  26115. return bytesToString(data);
  26116. }
  26117. };
  26118. return CipherTransform;
  26119. })();
  26120. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  26121. var defaultPasswordBytes = new Uint8Array([
  26122. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  26123. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  26124. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  26125. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  26126. function createEncryptionKey20(revision, password, ownerPassword,
  26127. ownerValidationSalt, ownerKeySalt, uBytes,
  26128. userPassword, userValidationSalt, userKeySalt,
  26129. ownerEncryption, userEncryption, perms) {
  26130. if (password) {
  26131. var passwordLength = Math.min(127, password.length);
  26132. password = password.subarray(0, passwordLength);
  26133. } else {
  26134. password = [];
  26135. }
  26136. var pdfAlgorithm;
  26137. if (revision === 6) {
  26138. pdfAlgorithm = new PDF20();
  26139. } else {
  26140. pdfAlgorithm = new PDF17();
  26141. }
  26142. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  26143. userPassword)) {
  26144. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  26145. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  26146. ownerValidationSalt,
  26147. uBytes,
  26148. ownerPassword)) {
  26149. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  26150. ownerEncryption);
  26151. }
  26152. return null;
  26153. }
  26154. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  26155. flags, revision, keyLength, encryptMetadata) {
  26156. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  26157. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  26158. if (password) {
  26159. n = Math.min(32, password.length);
  26160. for (; i < n; ++i) {
  26161. hashData[i] = password[i];
  26162. }
  26163. }
  26164. j = 0;
  26165. while (i < 32) {
  26166. hashData[i++] = defaultPasswordBytes[j++];
  26167. }
  26168. // as now the padded password in the hashData[0..i]
  26169. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  26170. hashData[i++] = ownerPassword[j];
  26171. }
  26172. hashData[i++] = flags & 0xFF;
  26173. hashData[i++] = (flags >> 8) & 0xFF;
  26174. hashData[i++] = (flags >> 16) & 0xFF;
  26175. hashData[i++] = (flags >>> 24) & 0xFF;
  26176. for (j = 0, n = fileId.length; j < n; ++j) {
  26177. hashData[i++] = fileId[j];
  26178. }
  26179. if (revision >= 4 && !encryptMetadata) {
  26180. hashData[i++] = 0xFF;
  26181. hashData[i++] = 0xFF;
  26182. hashData[i++] = 0xFF;
  26183. hashData[i++] = 0xFF;
  26184. }
  26185. var hash = calculateMD5(hashData, 0, i);
  26186. var keyLengthInBytes = keyLength >> 3;
  26187. if (revision >= 3) {
  26188. for (j = 0; j < 50; ++j) {
  26189. hash = calculateMD5(hash, 0, keyLengthInBytes);
  26190. }
  26191. }
  26192. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  26193. var cipher, checkData;
  26194. if (revision >= 3) {
  26195. for (i = 0; i < 32; ++i) {
  26196. hashData[i] = defaultPasswordBytes[i];
  26197. }
  26198. for (j = 0, n = fileId.length; j < n; ++j) {
  26199. hashData[i++] = fileId[j];
  26200. }
  26201. cipher = new ARCFourCipher(encryptionKey);
  26202. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  26203. n = encryptionKey.length;
  26204. var derivedKey = new Uint8Array(n), k;
  26205. for (j = 1; j <= 19; ++j) {
  26206. for (k = 0; k < n; ++k) {
  26207. derivedKey[k] = encryptionKey[k] ^ j;
  26208. }
  26209. cipher = new ARCFourCipher(derivedKey);
  26210. checkData = cipher.encryptBlock(checkData);
  26211. }
  26212. for (j = 0, n = checkData.length; j < n; ++j) {
  26213. if (userPassword[j] !== checkData[j]) {
  26214. return null;
  26215. }
  26216. }
  26217. } else {
  26218. cipher = new ARCFourCipher(encryptionKey);
  26219. checkData = cipher.encryptBlock(defaultPasswordBytes);
  26220. for (j = 0, n = checkData.length; j < n; ++j) {
  26221. if (userPassword[j] !== checkData[j]) {
  26222. return null;
  26223. }
  26224. }
  26225. }
  26226. return encryptionKey;
  26227. }
  26228. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  26229. var hashData = new Uint8Array(32), i = 0, j, n;
  26230. n = Math.min(32, password.length);
  26231. for (; i < n; ++i) {
  26232. hashData[i] = password[i];
  26233. }
  26234. j = 0;
  26235. while (i < 32) {
  26236. hashData[i++] = defaultPasswordBytes[j++];
  26237. }
  26238. var hash = calculateMD5(hashData, 0, i);
  26239. var keyLengthInBytes = keyLength >> 3;
  26240. if (revision >= 3) {
  26241. for (j = 0; j < 50; ++j) {
  26242. hash = calculateMD5(hash, 0, hash.length);
  26243. }
  26244. }
  26245. var cipher, userPassword;
  26246. if (revision >= 3) {
  26247. userPassword = ownerPassword;
  26248. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  26249. for (j = 19; j >= 0; j--) {
  26250. for (k = 0; k < keyLengthInBytes; ++k) {
  26251. derivedKey[k] = hash[k] ^ j;
  26252. }
  26253. cipher = new ARCFourCipher(derivedKey);
  26254. userPassword = cipher.encryptBlock(userPassword);
  26255. }
  26256. } else {
  26257. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  26258. userPassword = cipher.encryptBlock(ownerPassword);
  26259. }
  26260. return userPassword;
  26261. }
  26262. var identityName = Name.get('Identity');
  26263. function CipherTransformFactory(dict, fileId, password) {
  26264. var filter = dict.get('Filter');
  26265. if (!isName(filter, 'Standard')) {
  26266. error('unknown encryption method');
  26267. }
  26268. this.dict = dict;
  26269. var algorithm = dict.get('V');
  26270. if (!isInt(algorithm) ||
  26271. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  26272. algorithm !== 5)) {
  26273. error('unsupported encryption algorithm');
  26274. }
  26275. this.algorithm = algorithm;
  26276. var keyLength = dict.get('Length');
  26277. if (!keyLength) {
  26278. // Spec asks to rely on encryption dictionary's Length entry, however
  26279. // some PDFs don't have it. Trying to recover.
  26280. if (algorithm <= 3) {
  26281. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  26282. keyLength = 40;
  26283. } else {
  26284. // Trying to find default handler -- it usually has Length.
  26285. var cfDict = dict.get('CF');
  26286. var streamCryptoName = dict.get('StmF');
  26287. if (isDict(cfDict) && isName(streamCryptoName)) {
  26288. var handlerDict = cfDict.get(streamCryptoName.name);
  26289. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  26290. if (keyLength < 40) {
  26291. // Sometimes it's incorrect value of bits, generators specify bytes.
  26292. keyLength <<= 3;
  26293. }
  26294. }
  26295. }
  26296. }
  26297. if (!isInt(keyLength) ||
  26298. keyLength < 40 || (keyLength % 8) !== 0) {
  26299. error('invalid key length');
  26300. }
  26301. // prepare keys
  26302. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  26303. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  26304. var flags = dict.get('P');
  26305. var revision = dict.get('R');
  26306. // meaningful when V is 4 or 5
  26307. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  26308. dict.get('EncryptMetadata') !== false);
  26309. this.encryptMetadata = encryptMetadata;
  26310. var fileIdBytes = stringToBytes(fileId);
  26311. var passwordBytes;
  26312. if (password) {
  26313. if (revision === 6) {
  26314. try {
  26315. password = utf8StringToString(password);
  26316. } catch (ex) {
  26317. warn('CipherTransformFactory: ' +
  26318. 'Unable to convert UTF8 encoded password.');
  26319. }
  26320. }
  26321. passwordBytes = stringToBytes(password);
  26322. }
  26323. var encryptionKey;
  26324. if (algorithm !== 5) {
  26325. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  26326. ownerPassword, userPassword, flags,
  26327. revision, keyLength, encryptMetadata);
  26328. }
  26329. else {
  26330. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  26331. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  26332. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  26333. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  26334. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  26335. var ownerEncryption = stringToBytes(dict.get('OE'));
  26336. var userEncryption = stringToBytes(dict.get('UE'));
  26337. var perms = stringToBytes(dict.get('Perms'));
  26338. encryptionKey =
  26339. createEncryptionKey20(revision, passwordBytes,
  26340. ownerPassword, ownerValidationSalt,
  26341. ownerKeySalt, uBytes,
  26342. userPassword, userValidationSalt,
  26343. userKeySalt, ownerEncryption,
  26344. userEncryption, perms);
  26345. }
  26346. if (!encryptionKey && !password) {
  26347. throw new PasswordException('No password given',
  26348. PasswordResponses.NEED_PASSWORD);
  26349. } else if (!encryptionKey && password) {
  26350. // Attempting use the password as an owner password
  26351. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  26352. revision, keyLength);
  26353. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  26354. ownerPassword, userPassword, flags,
  26355. revision, keyLength, encryptMetadata);
  26356. }
  26357. if (!encryptionKey) {
  26358. throw new PasswordException('Incorrect Password',
  26359. PasswordResponses.INCORRECT_PASSWORD);
  26360. }
  26361. this.encryptionKey = encryptionKey;
  26362. if (algorithm >= 4) {
  26363. this.cf = dict.get('CF');
  26364. this.stmf = dict.get('StmF') || identityName;
  26365. this.strf = dict.get('StrF') || identityName;
  26366. this.eff = dict.get('EFF') || this.stmf;
  26367. }
  26368. }
  26369. function buildObjectKey(num, gen, encryptionKey, isAes) {
  26370. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  26371. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  26372. key[i] = encryptionKey[i];
  26373. }
  26374. key[i++] = num & 0xFF;
  26375. key[i++] = (num >> 8) & 0xFF;
  26376. key[i++] = (num >> 16) & 0xFF;
  26377. key[i++] = gen & 0xFF;
  26378. key[i++] = (gen >> 8) & 0xFF;
  26379. if (isAes) {
  26380. key[i++] = 0x73;
  26381. key[i++] = 0x41;
  26382. key[i++] = 0x6C;
  26383. key[i++] = 0x54;
  26384. }
  26385. var hash = calculateMD5(key, 0, i);
  26386. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  26387. }
  26388. function buildCipherConstructor(cf, name, num, gen, key) {
  26389. var cryptFilter = cf.get(name.name);
  26390. var cfm;
  26391. if (cryptFilter !== null && cryptFilter !== undefined) {
  26392. cfm = cryptFilter.get('CFM');
  26393. }
  26394. if (!cfm || cfm.name === 'None') {
  26395. return function cipherTransformFactoryBuildCipherConstructorNone() {
  26396. return new NullCipher();
  26397. };
  26398. }
  26399. if ('V2' === cfm.name) {
  26400. return function cipherTransformFactoryBuildCipherConstructorV2() {
  26401. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  26402. };
  26403. }
  26404. if ('AESV2' === cfm.name) {
  26405. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  26406. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  26407. };
  26408. }
  26409. if ('AESV3' === cfm.name) {
  26410. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  26411. return new AES256Cipher(key);
  26412. };
  26413. }
  26414. error('Unknown crypto method');
  26415. }
  26416. CipherTransformFactory.prototype = {
  26417. createCipherTransform:
  26418. function CipherTransformFactory_createCipherTransform(num, gen) {
  26419. if (this.algorithm === 4 || this.algorithm === 5) {
  26420. return new CipherTransform(
  26421. buildCipherConstructor(this.cf, this.stmf,
  26422. num, gen, this.encryptionKey),
  26423. buildCipherConstructor(this.cf, this.strf,
  26424. num, gen, this.encryptionKey));
  26425. }
  26426. // algorithms 1 and 2
  26427. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  26428. var cipherConstructor = function buildCipherCipherConstructor() {
  26429. return new ARCFourCipher(key);
  26430. };
  26431. return new CipherTransform(cipherConstructor, cipherConstructor);
  26432. }
  26433. };
  26434. return CipherTransformFactory;
  26435. })();
  26436. exports.AES128Cipher = AES128Cipher;
  26437. exports.AES256Cipher = AES256Cipher;
  26438. exports.ARCFourCipher = ARCFourCipher;
  26439. exports.CipherTransformFactory = CipherTransformFactory;
  26440. exports.PDF17 = PDF17;
  26441. exports.PDF20 = PDF20;
  26442. exports.calculateMD5 = calculateMD5;
  26443. exports.calculateSHA256 = calculateSHA256;
  26444. exports.calculateSHA384 = calculateSHA384;
  26445. exports.calculateSHA512 = calculateSHA512;
  26446. }));
  26447. (function (root, factory) {
  26448. {
  26449. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  26450. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  26451. root.pdfjsCoreCFFParser);
  26452. }
  26453. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  26454. coreEncodings, coreCFFParser) {
  26455. var Util = sharedUtil.Util;
  26456. var bytesToString = sharedUtil.bytesToString;
  26457. var error = sharedUtil.error;
  26458. var Stream = coreStream.Stream;
  26459. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26460. var StandardEncoding = coreEncodings.StandardEncoding;
  26461. var CFFParser = coreCFFParser.CFFParser;
  26462. var FontRendererFactory = (function FontRendererFactoryClosure() {
  26463. function getLong(data, offset) {
  26464. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26465. (data[offset + 2] << 8) | data[offset + 3];
  26466. }
  26467. function getUshort(data, offset) {
  26468. return (data[offset] << 8) | data[offset + 1];
  26469. }
  26470. function parseCmap(data, start, end) {
  26471. var offset = (getUshort(data, start + 2) === 1 ?
  26472. getLong(data, start + 8) : getLong(data, start + 16));
  26473. var format = getUshort(data, start + offset);
  26474. var length, ranges, p, i;
  26475. if (format === 4) {
  26476. length = getUshort(data, start + offset + 2);
  26477. var segCount = getUshort(data, start + offset + 6) >> 1;
  26478. p = start + offset + 14;
  26479. ranges = [];
  26480. for (i = 0; i < segCount; i++, p += 2) {
  26481. ranges[i] = {end: getUshort(data, p)};
  26482. }
  26483. p += 2;
  26484. for (i = 0; i < segCount; i++, p += 2) {
  26485. ranges[i].start = getUshort(data, p);
  26486. }
  26487. for (i = 0; i < segCount; i++, p += 2) {
  26488. ranges[i].idDelta = getUshort(data, p);
  26489. }
  26490. for (i = 0; i < segCount; i++, p += 2) {
  26491. var idOffset = getUshort(data, p);
  26492. if (idOffset === 0) {
  26493. continue;
  26494. }
  26495. ranges[i].ids = [];
  26496. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  26497. ranges[i].ids[j] = getUshort(data, p + idOffset);
  26498. idOffset += 2;
  26499. }
  26500. }
  26501. return ranges;
  26502. } else if (format === 12) {
  26503. length = getLong(data, start + offset + 4);
  26504. var groups = getLong(data, start + offset + 12);
  26505. p = start + offset + 16;
  26506. ranges = [];
  26507. for (i = 0; i < groups; i++) {
  26508. ranges.push({
  26509. start: getLong(data, p),
  26510. end: getLong(data, p + 4),
  26511. idDelta: getLong(data, p + 8) - getLong(data, p)
  26512. });
  26513. p += 12;
  26514. }
  26515. return ranges;
  26516. }
  26517. error('not supported cmap: ' + format);
  26518. }
  26519. function parseCff(data, start, end, seacAnalysisEnabled) {
  26520. var properties = {};
  26521. var parser = new CFFParser(new Stream(data, start, end - start),
  26522. properties, seacAnalysisEnabled);
  26523. var cff = parser.parse();
  26524. return {
  26525. glyphs: cff.charStrings.objects,
  26526. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  26527. cff.topDict.privateDict.subrsIndex.objects),
  26528. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  26529. };
  26530. }
  26531. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  26532. var itemSize, itemDecode;
  26533. if (isGlyphLocationsLong) {
  26534. itemSize = 4;
  26535. itemDecode = function fontItemDecodeLong(data, offset) {
  26536. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26537. (data[offset + 2] << 8) | data[offset + 3];
  26538. };
  26539. } else {
  26540. itemSize = 2;
  26541. itemDecode = function fontItemDecode(data, offset) {
  26542. return (data[offset] << 9) | (data[offset + 1] << 1);
  26543. };
  26544. }
  26545. var glyphs = [];
  26546. var startOffset = itemDecode(loca, 0);
  26547. for (var j = itemSize; j < loca.length; j += itemSize) {
  26548. var endOffset = itemDecode(loca, j);
  26549. glyphs.push(glyf.subarray(startOffset, endOffset));
  26550. startOffset = endOffset;
  26551. }
  26552. return glyphs;
  26553. }
  26554. function lookupCmap(ranges, unicode) {
  26555. var code = unicode.charCodeAt(0), gid = 0;
  26556. var l = 0, r = ranges.length - 1;
  26557. while (l < r) {
  26558. var c = (l + r + 1) >> 1;
  26559. if (code < ranges[c].start) {
  26560. r = c - 1;
  26561. } else {
  26562. l = c;
  26563. }
  26564. }
  26565. if (ranges[l].start <= code && code <= ranges[l].end) {
  26566. gid = (ranges[l].idDelta + (ranges[l].ids ?
  26567. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  26568. }
  26569. return {
  26570. charCode: code,
  26571. glyphId: gid,
  26572. };
  26573. }
  26574. function compileGlyf(code, cmds, font) {
  26575. function moveTo(x, y) {
  26576. cmds.push({cmd: 'moveTo', args: [x, y]});
  26577. }
  26578. function lineTo(x, y) {
  26579. cmds.push({cmd: 'lineTo', args: [x, y]});
  26580. }
  26581. function quadraticCurveTo(xa, ya, x, y) {
  26582. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  26583. }
  26584. var i = 0;
  26585. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26586. var flags;
  26587. var x = 0, y = 0;
  26588. i += 10;
  26589. if (numberOfContours < 0) {
  26590. // composite glyph
  26591. do {
  26592. flags = (code[i] << 8) | code[i + 1];
  26593. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  26594. i += 4;
  26595. var arg1, arg2;
  26596. if ((flags & 0x01)) {
  26597. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26598. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  26599. i += 4;
  26600. } else {
  26601. arg1 = code[i++]; arg2 = code[i++];
  26602. }
  26603. if ((flags & 0x02)) {
  26604. x = arg1;
  26605. y = arg2;
  26606. } else {
  26607. x = 0; y = 0; // TODO "they are points" ?
  26608. }
  26609. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  26610. if ((flags & 0x08)) {
  26611. scaleX =
  26612. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26613. i += 2;
  26614. } else if ((flags & 0x40)) {
  26615. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26616. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26617. i += 4;
  26618. } else if ((flags & 0x80)) {
  26619. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26620. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26621. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  26622. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  26623. i += 8;
  26624. }
  26625. var subglyph = font.glyphs[glyphIndex];
  26626. if (subglyph) {
  26627. cmds.push({cmd: 'save'});
  26628. cmds.push({cmd: 'transform',
  26629. args: [scaleX, scale01, scale10, scaleY, x, y]});
  26630. compileGlyf(subglyph, cmds, font);
  26631. cmds.push({cmd: 'restore'});
  26632. }
  26633. } while ((flags & 0x20));
  26634. } else {
  26635. // simple glyph
  26636. var endPtsOfContours = [];
  26637. var j, jj;
  26638. for (j = 0; j < numberOfContours; j++) {
  26639. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  26640. i += 2;
  26641. }
  26642. var instructionLength = (code[i] << 8) | code[i + 1];
  26643. i += 2 + instructionLength; // skipping the instructions
  26644. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  26645. var points = [];
  26646. while (points.length < numberOfPoints) {
  26647. flags = code[i++];
  26648. var repeat = 1;
  26649. if ((flags & 0x08)) {
  26650. repeat += code[i++];
  26651. }
  26652. while (repeat-- > 0) {
  26653. points.push({flags: flags});
  26654. }
  26655. }
  26656. for (j = 0; j < numberOfPoints; j++) {
  26657. switch (points[j].flags & 0x12) {
  26658. case 0x00:
  26659. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26660. i += 2;
  26661. break;
  26662. case 0x02:
  26663. x -= code[i++];
  26664. break;
  26665. case 0x12:
  26666. x += code[i++];
  26667. break;
  26668. }
  26669. points[j].x = x;
  26670. }
  26671. for (j = 0; j < numberOfPoints; j++) {
  26672. switch (points[j].flags & 0x24) {
  26673. case 0x00:
  26674. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26675. i += 2;
  26676. break;
  26677. case 0x04:
  26678. y -= code[i++];
  26679. break;
  26680. case 0x24:
  26681. y += code[i++];
  26682. break;
  26683. }
  26684. points[j].y = y;
  26685. }
  26686. var startPoint = 0;
  26687. for (i = 0; i < numberOfContours; i++) {
  26688. var endPoint = endPtsOfContours[i];
  26689. // contours might have implicit points, which is located in the middle
  26690. // between two neighboring off-curve points
  26691. var contour = points.slice(startPoint, endPoint + 1);
  26692. if ((contour[0].flags & 1)) {
  26693. contour.push(contour[0]); // using start point at the contour end
  26694. } else if ((contour[contour.length - 1].flags & 1)) {
  26695. // first is off-curve point, trying to use one from the end
  26696. contour.unshift(contour[contour.length - 1]);
  26697. } else {
  26698. // start and end are off-curve points, creating implicit one
  26699. var p = {
  26700. flags: 1,
  26701. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26702. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26703. };
  26704. contour.unshift(p);
  26705. contour.push(p);
  26706. }
  26707. moveTo(contour[0].x, contour[0].y);
  26708. for (j = 1, jj = contour.length; j < jj; j++) {
  26709. if ((contour[j].flags & 1)) {
  26710. lineTo(contour[j].x, contour[j].y);
  26711. } else if ((contour[j + 1].flags & 1)){
  26712. quadraticCurveTo(contour[j].x, contour[j].y,
  26713. contour[j + 1].x, contour[j + 1].y);
  26714. j++;
  26715. } else {
  26716. quadraticCurveTo(contour[j].x, contour[j].y,
  26717. (contour[j].x + contour[j + 1].x) / 2,
  26718. (contour[j].y + contour[j + 1].y) / 2);
  26719. }
  26720. }
  26721. startPoint = endPoint + 1;
  26722. }
  26723. }
  26724. }
  26725. function compileCharString(code, cmds, font) {
  26726. var stack = [];
  26727. var x = 0, y = 0;
  26728. var stems = 0;
  26729. function moveTo(x, y) {
  26730. cmds.push({cmd: 'moveTo', args: [x, y]});
  26731. }
  26732. function lineTo(x, y) {
  26733. cmds.push({cmd: 'lineTo', args: [x, y]});
  26734. }
  26735. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26736. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26737. }
  26738. function parse(code) {
  26739. var i = 0;
  26740. while (i < code.length) {
  26741. var stackClean = false;
  26742. var v = code[i++];
  26743. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26744. switch (v) {
  26745. case 1: // hstem
  26746. stems += stack.length >> 1;
  26747. stackClean = true;
  26748. break;
  26749. case 3: // vstem
  26750. stems += stack.length >> 1;
  26751. stackClean = true;
  26752. break;
  26753. case 4: // vmoveto
  26754. y += stack.pop();
  26755. moveTo(x, y);
  26756. stackClean = true;
  26757. break;
  26758. case 5: // rlineto
  26759. while (stack.length > 0) {
  26760. x += stack.shift();
  26761. y += stack.shift();
  26762. lineTo(x, y);
  26763. }
  26764. break;
  26765. case 6: // hlineto
  26766. while (stack.length > 0) {
  26767. x += stack.shift();
  26768. lineTo(x, y);
  26769. if (stack.length === 0) {
  26770. break;
  26771. }
  26772. y += stack.shift();
  26773. lineTo(x, y);
  26774. }
  26775. break;
  26776. case 7: // vlineto
  26777. while (stack.length > 0) {
  26778. y += stack.shift();
  26779. lineTo(x, y);
  26780. if (stack.length === 0) {
  26781. break;
  26782. }
  26783. x += stack.shift();
  26784. lineTo(x, y);
  26785. }
  26786. break;
  26787. case 8: // rrcurveto
  26788. while (stack.length > 0) {
  26789. xa = x + stack.shift(); ya = y + stack.shift();
  26790. xb = xa + stack.shift(); yb = ya + stack.shift();
  26791. x = xb + stack.shift(); y = yb + stack.shift();
  26792. bezierCurveTo(xa, ya, xb, yb, x, y);
  26793. }
  26794. break;
  26795. case 10: // callsubr
  26796. n = stack.pop() + font.subrsBias;
  26797. subrCode = font.subrs[n];
  26798. if (subrCode) {
  26799. parse(subrCode);
  26800. }
  26801. break;
  26802. case 11: // return
  26803. return;
  26804. case 12:
  26805. v = code[i++];
  26806. switch (v) {
  26807. case 34: // flex
  26808. xa = x + stack.shift();
  26809. xb = xa + stack.shift(); y1 = y + stack.shift();
  26810. x = xb + stack.shift();
  26811. bezierCurveTo(xa, y, xb, y1, x, y1);
  26812. xa = x + stack.shift();
  26813. xb = xa + stack.shift();
  26814. x = xb + stack.shift();
  26815. bezierCurveTo(xa, y1, xb, y, x, y);
  26816. break;
  26817. case 35: // flex
  26818. xa = x + stack.shift(); ya = y + stack.shift();
  26819. xb = xa + stack.shift(); yb = ya + stack.shift();
  26820. x = xb + stack.shift(); y = yb + stack.shift();
  26821. bezierCurveTo(xa, ya, xb, yb, x, y);
  26822. xa = x + stack.shift(); ya = y + stack.shift();
  26823. xb = xa + stack.shift(); yb = ya + stack.shift();
  26824. x = xb + stack.shift(); y = yb + stack.shift();
  26825. bezierCurveTo(xa, ya, xb, yb, x, y);
  26826. stack.pop(); // fd
  26827. break;
  26828. case 36: // hflex1
  26829. xa = x + stack.shift(); y1 = y + stack.shift();
  26830. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26831. x = xb + stack.shift();
  26832. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26833. xa = x + stack.shift();
  26834. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26835. x = xb + stack.shift();
  26836. bezierCurveTo(xa, y2, xb, y3, x, y);
  26837. break;
  26838. case 37: // flex1
  26839. var x0 = x, y0 = y;
  26840. xa = x + stack.shift(); ya = y + stack.shift();
  26841. xb = xa + stack.shift(); yb = ya + stack.shift();
  26842. x = xb + stack.shift(); y = yb + stack.shift();
  26843. bezierCurveTo(xa, ya, xb, yb, x, y);
  26844. xa = x + stack.shift(); ya = y + stack.shift();
  26845. xb = xa + stack.shift(); yb = ya + stack.shift();
  26846. x = xb; y = yb;
  26847. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  26848. x += stack.shift();
  26849. } else {
  26850. y += stack.shift();
  26851. }
  26852. bezierCurveTo(xa, ya, xb, yb, x, y);
  26853. break;
  26854. default:
  26855. error('unknown operator: 12 ' + v);
  26856. }
  26857. break;
  26858. case 14: // endchar
  26859. if (stack.length >= 4) {
  26860. var achar = stack.pop();
  26861. var bchar = stack.pop();
  26862. y = stack.pop();
  26863. x = stack.pop();
  26864. cmds.push({cmd: 'save'});
  26865. cmds.push({cmd: 'translate', args: [x, y]});
  26866. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  26867. font.glyphNameMap[StandardEncoding[achar]]));
  26868. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  26869. cmds.push({cmd: 'restore'});
  26870. cmap = lookupCmap(font.cmap, String.fromCharCode(
  26871. font.glyphNameMap[StandardEncoding[bchar]]));
  26872. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  26873. }
  26874. return;
  26875. case 18: // hstemhm
  26876. stems += stack.length >> 1;
  26877. stackClean = true;
  26878. break;
  26879. case 19: // hintmask
  26880. stems += stack.length >> 1;
  26881. i += (stems + 7) >> 3;
  26882. stackClean = true;
  26883. break;
  26884. case 20: // cntrmask
  26885. stems += stack.length >> 1;
  26886. i += (stems + 7) >> 3;
  26887. stackClean = true;
  26888. break;
  26889. case 21: // rmoveto
  26890. y += stack.pop();
  26891. x += stack.pop();
  26892. moveTo(x, y);
  26893. stackClean = true;
  26894. break;
  26895. case 22: // hmoveto
  26896. x += stack.pop();
  26897. moveTo(x, y);
  26898. stackClean = true;
  26899. break;
  26900. case 23: // vstemhm
  26901. stems += stack.length >> 1;
  26902. stackClean = true;
  26903. break;
  26904. case 24: // rcurveline
  26905. while (stack.length > 2) {
  26906. xa = x + stack.shift(); ya = y + stack.shift();
  26907. xb = xa + stack.shift(); yb = ya + stack.shift();
  26908. x = xb + stack.shift(); y = yb + stack.shift();
  26909. bezierCurveTo(xa, ya, xb, yb, x, y);
  26910. }
  26911. x += stack.shift();
  26912. y += stack.shift();
  26913. lineTo(x, y);
  26914. break;
  26915. case 25: // rlinecurve
  26916. while (stack.length > 6) {
  26917. x += stack.shift();
  26918. y += stack.shift();
  26919. lineTo(x, y);
  26920. }
  26921. xa = x + stack.shift(); ya = y + stack.shift();
  26922. xb = xa + stack.shift(); yb = ya + stack.shift();
  26923. x = xb + stack.shift(); y = yb + stack.shift();
  26924. bezierCurveTo(xa, ya, xb, yb, x, y);
  26925. break;
  26926. case 26: // vvcurveto
  26927. if (stack.length % 2) {
  26928. x += stack.shift();
  26929. }
  26930. while (stack.length > 0) {
  26931. xa = x; ya = y + stack.shift();
  26932. xb = xa + stack.shift(); yb = ya + stack.shift();
  26933. x = xb; y = yb + stack.shift();
  26934. bezierCurveTo(xa, ya, xb, yb, x, y);
  26935. }
  26936. break;
  26937. case 27: // hhcurveto
  26938. if (stack.length % 2) {
  26939. y += stack.shift();
  26940. }
  26941. while (stack.length > 0) {
  26942. xa = x + stack.shift(); ya = y;
  26943. xb = xa + stack.shift(); yb = ya + stack.shift();
  26944. x = xb + stack.shift(); y = yb;
  26945. bezierCurveTo(xa, ya, xb, yb, x, y);
  26946. }
  26947. break;
  26948. case 28:
  26949. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  26950. i += 2;
  26951. break;
  26952. case 29: // callgsubr
  26953. n = stack.pop() + font.gsubrsBias;
  26954. subrCode = font.gsubrs[n];
  26955. if (subrCode) {
  26956. parse(subrCode);
  26957. }
  26958. break;
  26959. case 30: // vhcurveto
  26960. while (stack.length > 0) {
  26961. xa = x; ya = y + stack.shift();
  26962. xb = xa + stack.shift(); yb = ya + stack.shift();
  26963. x = xb + stack.shift();
  26964. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26965. bezierCurveTo(xa, ya, xb, yb, x, y);
  26966. if (stack.length === 0) {
  26967. break;
  26968. }
  26969. xa = x + stack.shift(); ya = y;
  26970. xb = xa + stack.shift(); yb = ya + stack.shift();
  26971. y = yb + stack.shift();
  26972. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26973. bezierCurveTo(xa, ya, xb, yb, x, y);
  26974. }
  26975. break;
  26976. case 31: // hvcurveto
  26977. while (stack.length > 0) {
  26978. xa = x + stack.shift(); ya = y;
  26979. xb = xa + stack.shift(); yb = ya + stack.shift();
  26980. y = yb + stack.shift();
  26981. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26982. bezierCurveTo(xa, ya, xb, yb, x, y);
  26983. if (stack.length === 0) {
  26984. break;
  26985. }
  26986. xa = x; ya = y + stack.shift();
  26987. xb = xa + stack.shift(); yb = ya + stack.shift();
  26988. x = xb + stack.shift();
  26989. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26990. bezierCurveTo(xa, ya, xb, yb, x, y);
  26991. }
  26992. break;
  26993. default:
  26994. if (v < 32) {
  26995. error('unknown operator: ' + v);
  26996. }
  26997. if (v < 247) {
  26998. stack.push(v - 139);
  26999. } else if (v < 251) {
  27000. stack.push((v - 247) * 256 + code[i++] + 108);
  27001. } else if (v < 255) {
  27002. stack.push(-(v - 251) * 256 - code[i++] - 108);
  27003. } else {
  27004. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  27005. (code[i + 2] << 8) | code[i + 3]) / 65536);
  27006. i += 4;
  27007. }
  27008. break;
  27009. }
  27010. if (stackClean) {
  27011. stack.length = 0;
  27012. }
  27013. }
  27014. }
  27015. parse(code);
  27016. }
  27017. var noop = '';
  27018. function CompiledFont(fontMatrix) {
  27019. this.compiledGlyphs = Object.create(null);
  27020. this.compiledCharCodeToGlyphId = Object.create(null);
  27021. this.fontMatrix = fontMatrix;
  27022. }
  27023. CompiledFont.prototype = {
  27024. getPathJs: function (unicode) {
  27025. var cmap = lookupCmap(this.cmap, unicode);
  27026. var fn = this.compiledGlyphs[cmap.glyphId];
  27027. if (!fn) {
  27028. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  27029. this.compiledGlyphs[cmap.glyphId] = fn;
  27030. }
  27031. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  27032. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  27033. }
  27034. return fn;
  27035. },
  27036. compileGlyph: function (code) {
  27037. if (!code || code.length === 0 || code[0] === 14) {
  27038. return noop;
  27039. }
  27040. var cmds = [];
  27041. cmds.push({cmd: 'save'});
  27042. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  27043. cmds.push({cmd: 'scale', args: ['size', '-size']});
  27044. this.compileGlyphImpl(code, cmds);
  27045. cmds.push({cmd: 'restore'});
  27046. return cmds;
  27047. },
  27048. compileGlyphImpl: function () {
  27049. error('Children classes should implement this.');
  27050. },
  27051. hasBuiltPath: function (unicode) {
  27052. var cmap = lookupCmap(this.cmap, unicode);
  27053. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  27054. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  27055. }
  27056. };
  27057. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  27058. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  27059. CompiledFont.call(this, fontMatrix);
  27060. this.glyphs = glyphs;
  27061. this.cmap = cmap;
  27062. }
  27063. Util.inherit(TrueTypeCompiled, CompiledFont, {
  27064. compileGlyphImpl: function (code, cmds) {
  27065. compileGlyf(code, cmds, this);
  27066. }
  27067. });
  27068. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  27069. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  27070. CompiledFont.call(this, fontMatrix);
  27071. this.glyphs = cffInfo.glyphs;
  27072. this.gsubrs = cffInfo.gsubrs || [];
  27073. this.subrs = cffInfo.subrs || [];
  27074. this.cmap = cmap;
  27075. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  27076. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  27077. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  27078. this.subrsBias = (this.subrs.length < 1240 ?
  27079. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  27080. }
  27081. Util.inherit(Type2Compiled, CompiledFont, {
  27082. compileGlyphImpl: function (code, cmds) {
  27083. compileCharString(code, cmds, this);
  27084. }
  27085. });
  27086. return {
  27087. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  27088. var data = new Uint8Array(font.data);
  27089. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  27090. var numTables = getUshort(data, 4);
  27091. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  27092. var tag = bytesToString(data.subarray(p, p + 4));
  27093. var offset = getLong(data, p + 8);
  27094. var length = getLong(data, p + 12);
  27095. switch (tag) {
  27096. case 'cmap':
  27097. cmap = parseCmap(data, offset, offset + length);
  27098. break;
  27099. case 'glyf':
  27100. glyf = data.subarray(offset, offset + length);
  27101. break;
  27102. case 'loca':
  27103. loca = data.subarray(offset, offset + length);
  27104. break;
  27105. case 'head':
  27106. unitsPerEm = getUshort(data, offset + 18);
  27107. indexToLocFormat = getUshort(data, offset + 50);
  27108. break;
  27109. case 'CFF ':
  27110. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  27111. break;
  27112. }
  27113. }
  27114. if (glyf) {
  27115. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  27116. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  27117. return new TrueTypeCompiled(
  27118. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  27119. } else {
  27120. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  27121. }
  27122. }
  27123. };
  27124. })();
  27125. exports.FontRendererFactory = FontRendererFactory;
  27126. }));
  27127. (function (root, factory) {
  27128. {
  27129. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  27130. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  27131. }
  27132. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  27133. var MissingDataException = sharedUtil.MissingDataException;
  27134. var StreamType = sharedUtil.StreamType;
  27135. var assert = sharedUtil.assert;
  27136. var error = sharedUtil.error;
  27137. var info = sharedUtil.info;
  27138. var isArray = sharedUtil.isArray;
  27139. var isInt = sharedUtil.isInt;
  27140. var isNum = sharedUtil.isNum;
  27141. var isString = sharedUtil.isString;
  27142. var warn = sharedUtil.warn;
  27143. var Cmd = corePrimitives.Cmd;
  27144. var Dict = corePrimitives.Dict;
  27145. var Name = corePrimitives.Name;
  27146. var Ref = corePrimitives.Ref;
  27147. var isCmd = corePrimitives.isCmd;
  27148. var isDict = corePrimitives.isDict;
  27149. var isName = corePrimitives.isName;
  27150. var Ascii85Stream = coreStream.Ascii85Stream;
  27151. var AsciiHexStream = coreStream.AsciiHexStream;
  27152. var CCITTFaxStream = coreStream.CCITTFaxStream;
  27153. var FlateStream = coreStream.FlateStream;
  27154. var Jbig2Stream = coreStream.Jbig2Stream;
  27155. var JpegStream = coreStream.JpegStream;
  27156. var JpxStream = coreStream.JpxStream;
  27157. var LZWStream = coreStream.LZWStream;
  27158. var NullStream = coreStream.NullStream;
  27159. var PredictorStream = coreStream.PredictorStream;
  27160. var RunLengthStream = coreStream.RunLengthStream;
  27161. var EOF = {};
  27162. function isEOF(v) {
  27163. return (v === EOF);
  27164. }
  27165. var MAX_LENGTH_TO_CACHE = 1000;
  27166. var Parser = (function ParserClosure() {
  27167. function Parser(lexer, allowStreams, xref, recoveryMode) {
  27168. this.lexer = lexer;
  27169. this.allowStreams = allowStreams;
  27170. this.xref = xref;
  27171. this.recoveryMode = recoveryMode || false;
  27172. this.imageCache = Object.create(null);
  27173. this.refill();
  27174. }
  27175. Parser.prototype = {
  27176. refill: function Parser_refill() {
  27177. this.buf1 = this.lexer.getObj();
  27178. this.buf2 = this.lexer.getObj();
  27179. },
  27180. shift: function Parser_shift() {
  27181. if (isCmd(this.buf2, 'ID')) {
  27182. this.buf1 = this.buf2;
  27183. this.buf2 = null;
  27184. } else {
  27185. this.buf1 = this.buf2;
  27186. this.buf2 = this.lexer.getObj();
  27187. }
  27188. },
  27189. tryShift: function Parser_tryShift() {
  27190. try {
  27191. this.shift();
  27192. return true;
  27193. } catch (e) {
  27194. if (e instanceof MissingDataException) {
  27195. throw e;
  27196. }
  27197. // Upon failure, the caller should reset this.lexer.pos to a known good
  27198. // state and call this.shift() twice to reset the buffers.
  27199. return false;
  27200. }
  27201. },
  27202. getObj: function Parser_getObj(cipherTransform) {
  27203. var buf1 = this.buf1;
  27204. this.shift();
  27205. if (buf1 instanceof Cmd) {
  27206. switch (buf1.cmd) {
  27207. case 'BI': // inline image
  27208. return this.makeInlineImage(cipherTransform);
  27209. case '[': // array
  27210. var array = [];
  27211. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  27212. array.push(this.getObj(cipherTransform));
  27213. }
  27214. if (isEOF(this.buf1)) {
  27215. if (!this.recoveryMode) {
  27216. error('End of file inside array');
  27217. }
  27218. return array;
  27219. }
  27220. this.shift();
  27221. return array;
  27222. case '<<': // dictionary or stream
  27223. var dict = new Dict(this.xref);
  27224. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  27225. if (!isName(this.buf1)) {
  27226. info('Malformed dictionary: key must be a name object');
  27227. this.shift();
  27228. continue;
  27229. }
  27230. var key = this.buf1.name;
  27231. this.shift();
  27232. if (isEOF(this.buf1)) {
  27233. break;
  27234. }
  27235. dict.set(key, this.getObj(cipherTransform));
  27236. }
  27237. if (isEOF(this.buf1)) {
  27238. if (!this.recoveryMode) {
  27239. error('End of file inside dictionary');
  27240. }
  27241. return dict;
  27242. }
  27243. // Stream objects are not allowed inside content streams or
  27244. // object streams.
  27245. if (isCmd(this.buf2, 'stream')) {
  27246. return (this.allowStreams ?
  27247. this.makeStream(dict, cipherTransform) : dict);
  27248. }
  27249. this.shift();
  27250. return dict;
  27251. default: // simple object
  27252. return buf1;
  27253. }
  27254. }
  27255. if (isInt(buf1)) { // indirect reference or integer
  27256. var num = buf1;
  27257. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  27258. var ref = new Ref(num, this.buf1);
  27259. this.shift();
  27260. this.shift();
  27261. return ref;
  27262. }
  27263. return num;
  27264. }
  27265. if (isString(buf1)) { // string
  27266. var str = buf1;
  27267. if (cipherTransform) {
  27268. str = cipherTransform.decryptString(str);
  27269. }
  27270. return str;
  27271. }
  27272. // simple object
  27273. return buf1;
  27274. },
  27275. /**
  27276. * Find the end of the stream by searching for the /EI\s/.
  27277. * @returns {number} The inline stream length.
  27278. */
  27279. findDefaultInlineStreamEnd:
  27280. function Parser_findDefaultInlineStreamEnd(stream) {
  27281. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  27282. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  27283. while ((ch = stream.getByte()) !== -1) {
  27284. if (state === 0) {
  27285. state = (ch === E) ? 1 : 0;
  27286. } else if (state === 1) {
  27287. state = (ch === I) ? 2 : 0;
  27288. } else {
  27289. assert(state === 2);
  27290. if (ch === SPACE || ch === LF || ch === CR) {
  27291. // Let's check the next five bytes are ASCII... just be sure.
  27292. n = 5;
  27293. followingBytes = stream.peekBytes(n);
  27294. for (i = 0; i < n; i++) {
  27295. ch = followingBytes[i];
  27296. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  27297. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  27298. // it's binary stuff. Resetting the state.
  27299. state = 0;
  27300. break;
  27301. }
  27302. }
  27303. if (state === 2) {
  27304. break; // Finished!
  27305. }
  27306. } else {
  27307. state = 0;
  27308. }
  27309. }
  27310. }
  27311. return ((stream.pos - 4) - startPos);
  27312. },
  27313. /**
  27314. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  27315. * @returns {number} The inline stream length.
  27316. */
  27317. findDCTDecodeInlineStreamEnd:
  27318. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  27319. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  27320. while ((b = stream.getByte()) !== -1) {
  27321. if (b !== 0xFF) { // Not a valid marker.
  27322. continue;
  27323. }
  27324. switch (stream.getByte()) {
  27325. case 0x00: // Byte stuffing.
  27326. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  27327. break;
  27328. case 0xFF: // Fill byte.
  27329. // Avoid skipping a valid marker, resetting the stream position.
  27330. stream.skip(-1);
  27331. break;
  27332. case 0xD9: // EOI
  27333. foundEOI = true;
  27334. break;
  27335. case 0xC0: // SOF0
  27336. case 0xC1: // SOF1
  27337. case 0xC2: // SOF2
  27338. case 0xC3: // SOF3
  27339. case 0xC5: // SOF5
  27340. case 0xC6: // SOF6
  27341. case 0xC7: // SOF7
  27342. case 0xC9: // SOF9
  27343. case 0xCA: // SOF10
  27344. case 0xCB: // SOF11
  27345. case 0xCD: // SOF13
  27346. case 0xCE: // SOF14
  27347. case 0xCF: // SOF15
  27348. case 0xC4: // DHT
  27349. case 0xCC: // DAC
  27350. case 0xDA: // SOS
  27351. case 0xDB: // DQT
  27352. case 0xDC: // DNL
  27353. case 0xDD: // DRI
  27354. case 0xDE: // DHP
  27355. case 0xDF: // EXP
  27356. case 0xE0: // APP0
  27357. case 0xE1: // APP1
  27358. case 0xE2: // APP2
  27359. case 0xE3: // APP3
  27360. case 0xE4: // APP4
  27361. case 0xE5: // APP5
  27362. case 0xE6: // APP6
  27363. case 0xE7: // APP7
  27364. case 0xE8: // APP8
  27365. case 0xE9: // APP9
  27366. case 0xEA: // APP10
  27367. case 0xEB: // APP11
  27368. case 0xEC: // APP12
  27369. case 0xED: // APP13
  27370. case 0xEE: // APP14
  27371. case 0xEF: // APP15
  27372. case 0xFE: // COM
  27373. // The marker should be followed by the length of the segment.
  27374. markerLength = stream.getUint16();
  27375. if (markerLength > 2) {
  27376. // |markerLength| contains the byte length of the marker segment,
  27377. // including its own length (2 bytes) and excluding the marker.
  27378. stream.skip(markerLength - 2); // Jump to the next marker.
  27379. } else {
  27380. // The marker length is invalid, resetting the stream position.
  27381. stream.skip(-2);
  27382. }
  27383. break;
  27384. }
  27385. if (foundEOI) {
  27386. break;
  27387. }
  27388. }
  27389. length = stream.pos - startPos;
  27390. if (b === -1) {
  27391. warn('Inline DCTDecode image stream: ' +
  27392. 'EOI marker not found, searching for /EI/ instead.');
  27393. stream.skip(-length); // Reset the stream position.
  27394. return this.findDefaultInlineStreamEnd(stream);
  27395. }
  27396. this.inlineStreamSkipEI(stream);
  27397. return length;
  27398. },
  27399. /**
  27400. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  27401. * @returns {number} The inline stream length.
  27402. */
  27403. findASCII85DecodeInlineStreamEnd:
  27404. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  27405. var TILDE = 0x7E, GT = 0x3E;
  27406. var startPos = stream.pos, ch, length;
  27407. while ((ch = stream.getByte()) !== -1) {
  27408. if (ch === TILDE && stream.peekByte() === GT) {
  27409. stream.skip();
  27410. break;
  27411. }
  27412. }
  27413. length = stream.pos - startPos;
  27414. if (ch === -1) {
  27415. warn('Inline ASCII85Decode image stream: ' +
  27416. 'EOD marker not found, searching for /EI/ instead.');
  27417. stream.skip(-length); // Reset the stream position.
  27418. return this.findDefaultInlineStreamEnd(stream);
  27419. }
  27420. this.inlineStreamSkipEI(stream);
  27421. return length;
  27422. },
  27423. /**
  27424. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  27425. * @returns {number} The inline stream length.
  27426. */
  27427. findASCIIHexDecodeInlineStreamEnd:
  27428. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  27429. var GT = 0x3E;
  27430. var startPos = stream.pos, ch, length;
  27431. while ((ch = stream.getByte()) !== -1) {
  27432. if (ch === GT) {
  27433. break;
  27434. }
  27435. }
  27436. length = stream.pos - startPos;
  27437. if (ch === -1) {
  27438. warn('Inline ASCIIHexDecode image stream: ' +
  27439. 'EOD marker not found, searching for /EI/ instead.');
  27440. stream.skip(-length); // Reset the stream position.
  27441. return this.findDefaultInlineStreamEnd(stream);
  27442. }
  27443. this.inlineStreamSkipEI(stream);
  27444. return length;
  27445. },
  27446. /**
  27447. * Skip over the /EI/ for streams where we search for an EOD marker.
  27448. */
  27449. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  27450. var E = 0x45, I = 0x49;
  27451. var state = 0, ch;
  27452. while ((ch = stream.getByte()) !== -1) {
  27453. if (state === 0) {
  27454. state = (ch === E) ? 1 : 0;
  27455. } else if (state === 1) {
  27456. state = (ch === I) ? 2 : 0;
  27457. } else if (state === 2) {
  27458. break;
  27459. }
  27460. }
  27461. },
  27462. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27463. var lexer = this.lexer;
  27464. var stream = lexer.stream;
  27465. // Parse dictionary.
  27466. var dict = new Dict(this.xref);
  27467. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27468. if (!isName(this.buf1)) {
  27469. error('Dictionary key must be a name object');
  27470. }
  27471. var key = this.buf1.name;
  27472. this.shift();
  27473. if (isEOF(this.buf1)) {
  27474. break;
  27475. }
  27476. dict.set(key, this.getObj(cipherTransform));
  27477. }
  27478. // Extract the name of the first (i.e. the current) image filter.
  27479. var filter = dict.get('Filter', 'F'), filterName;
  27480. if (isName(filter)) {
  27481. filterName = filter.name;
  27482. } else if (isArray(filter) && isName(filter[0])) {
  27483. filterName = filter[0].name;
  27484. }
  27485. // Parse image stream.
  27486. var startPos = stream.pos, length, i, ii;
  27487. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  27488. length = this.findDCTDecodeInlineStreamEnd(stream);
  27489. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  27490. length = this.findASCII85DecodeInlineStreamEnd(stream);
  27491. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  27492. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  27493. } else {
  27494. length = this.findDefaultInlineStreamEnd(stream);
  27495. }
  27496. var imageStream = stream.makeSubStream(startPos, length, dict);
  27497. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  27498. // adler32 checksum.
  27499. var adler32;
  27500. if (length < MAX_LENGTH_TO_CACHE) {
  27501. var imageBytes = imageStream.getBytes();
  27502. imageStream.reset();
  27503. var a = 1;
  27504. var b = 0;
  27505. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27506. // No modulo required in the loop if imageBytes.length < 5552.
  27507. a += imageBytes[i] & 0xff;
  27508. b += a;
  27509. }
  27510. adler32 = ((b % 65521) << 16) | (a % 65521);
  27511. if (this.imageCache.adler32 === adler32) {
  27512. this.buf2 = Cmd.get('EI');
  27513. this.shift();
  27514. this.imageCache[adler32].reset();
  27515. return this.imageCache[adler32];
  27516. }
  27517. }
  27518. if (cipherTransform) {
  27519. imageStream = cipherTransform.createStream(imageStream, length);
  27520. }
  27521. imageStream = this.filter(imageStream, dict, length);
  27522. imageStream.dict = dict;
  27523. if (adler32 !== undefined) {
  27524. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27525. this.imageCache[adler32] = imageStream;
  27526. }
  27527. this.buf2 = Cmd.get('EI');
  27528. this.shift();
  27529. return imageStream;
  27530. },
  27531. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27532. var lexer = this.lexer;
  27533. var stream = lexer.stream;
  27534. // get stream start position
  27535. lexer.skipToNextLine();
  27536. var pos = stream.pos - 1;
  27537. // get length
  27538. var length = dict.get('Length');
  27539. if (!isInt(length)) {
  27540. info('Bad ' + length + ' attribute in stream');
  27541. length = 0;
  27542. }
  27543. // skip over the stream data
  27544. stream.pos = pos + length;
  27545. lexer.nextChar();
  27546. // Shift '>>' and check whether the new object marks the end of the stream
  27547. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  27548. this.shift(); // 'stream'
  27549. } else {
  27550. // bad stream length, scanning for endstream
  27551. stream.pos = pos;
  27552. var SCAN_BLOCK_SIZE = 2048;
  27553. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27554. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27555. 0x61, 0x6D];
  27556. var skipped = 0, found = false, i, j;
  27557. while (stream.pos < stream.end) {
  27558. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27559. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27560. if (scanLength <= 0) {
  27561. break;
  27562. }
  27563. found = false;
  27564. i = 0;
  27565. while (i < scanLength) {
  27566. j = 0;
  27567. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  27568. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  27569. j++;
  27570. }
  27571. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27572. found = true;
  27573. break;
  27574. }
  27575. i++;
  27576. }
  27577. if (found) {
  27578. skipped += i;
  27579. stream.pos += i;
  27580. break;
  27581. }
  27582. skipped += scanLength;
  27583. stream.pos += scanLength;
  27584. }
  27585. if (!found) {
  27586. error('Missing endstream');
  27587. }
  27588. length = skipped;
  27589. lexer.nextChar();
  27590. this.shift();
  27591. this.shift();
  27592. }
  27593. this.shift(); // 'endstream'
  27594. stream = stream.makeSubStream(pos, length, dict);
  27595. if (cipherTransform) {
  27596. stream = cipherTransform.createStream(stream, length);
  27597. }
  27598. stream = this.filter(stream, dict, length);
  27599. stream.dict = dict;
  27600. return stream;
  27601. },
  27602. filter: function Parser_filter(stream, dict, length) {
  27603. var filter = dict.get('Filter', 'F');
  27604. var params = dict.get('DecodeParms', 'DP');
  27605. if (isName(filter)) {
  27606. return this.makeFilter(stream, filter.name, length, params);
  27607. }
  27608. var maybeLength = length;
  27609. if (isArray(filter)) {
  27610. var filterArray = filter;
  27611. var paramsArray = params;
  27612. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  27613. filter = filterArray[i];
  27614. if (!isName(filter)) {
  27615. error('Bad filter name: ' + filter);
  27616. }
  27617. params = null;
  27618. if (isArray(paramsArray) && (i in paramsArray)) {
  27619. params = paramsArray[i];
  27620. }
  27621. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  27622. // after the first stream the length variable is invalid
  27623. maybeLength = null;
  27624. }
  27625. }
  27626. return stream;
  27627. },
  27628. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  27629. if (stream.dict.get('Length') === 0 && !maybeLength) {
  27630. warn('Empty "' + name + '" stream.');
  27631. return new NullStream(stream);
  27632. }
  27633. try {
  27634. if (params && this.xref) {
  27635. params = this.xref.fetchIfRef(params);
  27636. }
  27637. var xrefStreamStats = this.xref.stats.streamTypes;
  27638. if (name === 'FlateDecode' || name === 'Fl') {
  27639. xrefStreamStats[StreamType.FLATE] = true;
  27640. if (params) {
  27641. return new PredictorStream(new FlateStream(stream, maybeLength),
  27642. maybeLength, params);
  27643. }
  27644. return new FlateStream(stream, maybeLength);
  27645. }
  27646. if (name === 'LZWDecode' || name === 'LZW') {
  27647. xrefStreamStats[StreamType.LZW] = true;
  27648. var earlyChange = 1;
  27649. if (params) {
  27650. if (params.has('EarlyChange')) {
  27651. earlyChange = params.get('EarlyChange');
  27652. }
  27653. return new PredictorStream(
  27654. new LZWStream(stream, maybeLength, earlyChange),
  27655. maybeLength, params);
  27656. }
  27657. return new LZWStream(stream, maybeLength, earlyChange);
  27658. }
  27659. if (name === 'DCTDecode' || name === 'DCT') {
  27660. xrefStreamStats[StreamType.DCT] = true;
  27661. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  27662. }
  27663. if (name === 'JPXDecode' || name === 'JPX') {
  27664. xrefStreamStats[StreamType.JPX] = true;
  27665. return new JpxStream(stream, maybeLength, stream.dict);
  27666. }
  27667. if (name === 'ASCII85Decode' || name === 'A85') {
  27668. xrefStreamStats[StreamType.A85] = true;
  27669. return new Ascii85Stream(stream, maybeLength);
  27670. }
  27671. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  27672. xrefStreamStats[StreamType.AHX] = true;
  27673. return new AsciiHexStream(stream, maybeLength);
  27674. }
  27675. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  27676. xrefStreamStats[StreamType.CCF] = true;
  27677. return new CCITTFaxStream(stream, maybeLength, params);
  27678. }
  27679. if (name === 'RunLengthDecode' || name === 'RL') {
  27680. xrefStreamStats[StreamType.RL] = true;
  27681. return new RunLengthStream(stream, maybeLength);
  27682. }
  27683. if (name === 'JBIG2Decode') {
  27684. xrefStreamStats[StreamType.JBIG] = true;
  27685. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27686. }
  27687. warn('filter "' + name + '" not supported yet');
  27688. return stream;
  27689. } catch (ex) {
  27690. if (ex instanceof MissingDataException) {
  27691. throw ex;
  27692. }
  27693. warn('Invalid stream: \"' + ex + '\"');
  27694. return new NullStream(stream);
  27695. }
  27696. }
  27697. };
  27698. return Parser;
  27699. })();
  27700. var Lexer = (function LexerClosure() {
  27701. function Lexer(stream, knownCommands) {
  27702. this.stream = stream;
  27703. this.nextChar();
  27704. // While lexing, we build up many strings one char at a time. Using += for
  27705. // this can result in lots of garbage strings. It's better to build an
  27706. // array of single-char strings and then join() them together at the end.
  27707. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27708. // purpose uses less memory than using a new array for each string.
  27709. this.strBuf = [];
  27710. // The PDFs might have "glued" commands with other commands, operands or
  27711. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27712. // commands and their prefixes. The prefixes are built the following way:
  27713. // if there a command that is a prefix of the other valid command or
  27714. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27715. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27716. // other commands or literals as a prefix. The knowCommands is optional.
  27717. this.knownCommands = knownCommands;
  27718. }
  27719. // A '1' in this array means the character is white space. A '1' or
  27720. // '2' means the character ends a name or command.
  27721. var specialChars = [
  27722. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27724. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27738. ];
  27739. function toHexDigit(ch) {
  27740. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27741. return ch & 0x0F;
  27742. }
  27743. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27744. // 'A'-'F', 'a'-'f'
  27745. return (ch & 0x0F) + 9;
  27746. }
  27747. return -1;
  27748. }
  27749. Lexer.prototype = {
  27750. nextChar: function Lexer_nextChar() {
  27751. return (this.currentChar = this.stream.getByte());
  27752. },
  27753. peekChar: function Lexer_peekChar() {
  27754. return this.stream.peekByte();
  27755. },
  27756. getNumber: function Lexer_getNumber() {
  27757. var ch = this.currentChar;
  27758. var eNotation = false;
  27759. var divideBy = 0; // different from 0 if it's a floating point value
  27760. var sign = 1;
  27761. if (ch === 0x2D) { // '-'
  27762. sign = -1;
  27763. ch = this.nextChar();
  27764. if (ch === 0x2D) { // '-'
  27765. // Ignore double negative (this is consistent with Adobe Reader).
  27766. ch = this.nextChar();
  27767. }
  27768. } else if (ch === 0x2B) { // '+'
  27769. ch = this.nextChar();
  27770. }
  27771. if (ch === 0x2E) { // '.'
  27772. divideBy = 10;
  27773. ch = this.nextChar();
  27774. }
  27775. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27776. error('Invalid number: ' + String.fromCharCode(ch));
  27777. return 0;
  27778. }
  27779. var baseValue = ch - 0x30; // '0'
  27780. var powerValue = 0;
  27781. var powerValueSign = 1;
  27782. while ((ch = this.nextChar()) >= 0) {
  27783. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27784. var currentDigit = ch - 0x30; // '0'
  27785. if (eNotation) { // We are after an 'e' or 'E'
  27786. powerValue = powerValue * 10 + currentDigit;
  27787. } else {
  27788. if (divideBy !== 0) { // We are after a point
  27789. divideBy *= 10;
  27790. }
  27791. baseValue = baseValue * 10 + currentDigit;
  27792. }
  27793. } else if (ch === 0x2E) { // '.'
  27794. if (divideBy === 0) {
  27795. divideBy = 1;
  27796. } else {
  27797. // A number can have only one '.'
  27798. break;
  27799. }
  27800. } else if (ch === 0x2D) { // '-'
  27801. // ignore minus signs in the middle of numbers to match
  27802. // Adobe's behavior
  27803. warn('Badly formatted number');
  27804. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27805. // 'E' can be either a scientific notation or the beginning of a new
  27806. // operator
  27807. ch = this.peekChar();
  27808. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27809. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27810. this.nextChar(); // Consume the sign character
  27811. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27812. // The 'E' must be the beginning of a new operator
  27813. break;
  27814. }
  27815. eNotation = true;
  27816. } else {
  27817. // the last character doesn't belong to us
  27818. break;
  27819. }
  27820. }
  27821. if (divideBy !== 0) {
  27822. baseValue /= divideBy;
  27823. }
  27824. if (eNotation) {
  27825. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27826. }
  27827. return sign * baseValue;
  27828. },
  27829. getString: function Lexer_getString() {
  27830. var numParen = 1;
  27831. var done = false;
  27832. var strBuf = this.strBuf;
  27833. strBuf.length = 0;
  27834. var ch = this.nextChar();
  27835. while (true) {
  27836. var charBuffered = false;
  27837. switch (ch | 0) {
  27838. case -1:
  27839. warn('Unterminated string');
  27840. done = true;
  27841. break;
  27842. case 0x28: // '('
  27843. ++numParen;
  27844. strBuf.push('(');
  27845. break;
  27846. case 0x29: // ')'
  27847. if (--numParen === 0) {
  27848. this.nextChar(); // consume strings ')'
  27849. done = true;
  27850. } else {
  27851. strBuf.push(')');
  27852. }
  27853. break;
  27854. case 0x5C: // '\\'
  27855. ch = this.nextChar();
  27856. switch (ch) {
  27857. case -1:
  27858. warn('Unterminated string');
  27859. done = true;
  27860. break;
  27861. case 0x6E: // 'n'
  27862. strBuf.push('\n');
  27863. break;
  27864. case 0x72: // 'r'
  27865. strBuf.push('\r');
  27866. break;
  27867. case 0x74: // 't'
  27868. strBuf.push('\t');
  27869. break;
  27870. case 0x62: // 'b'
  27871. strBuf.push('\b');
  27872. break;
  27873. case 0x66: // 'f'
  27874. strBuf.push('\f');
  27875. break;
  27876. case 0x5C: // '\'
  27877. case 0x28: // '('
  27878. case 0x29: // ')'
  27879. strBuf.push(String.fromCharCode(ch));
  27880. break;
  27881. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  27882. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  27883. var x = ch & 0x0F;
  27884. ch = this.nextChar();
  27885. charBuffered = true;
  27886. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27887. x = (x << 3) + (ch & 0x0F);
  27888. ch = this.nextChar();
  27889. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27890. charBuffered = false;
  27891. x = (x << 3) + (ch & 0x0F);
  27892. }
  27893. }
  27894. strBuf.push(String.fromCharCode(x));
  27895. break;
  27896. case 0x0D: // CR
  27897. if (this.peekChar() === 0x0A) { // LF
  27898. this.nextChar();
  27899. }
  27900. break;
  27901. case 0x0A: // LF
  27902. break;
  27903. default:
  27904. strBuf.push(String.fromCharCode(ch));
  27905. break;
  27906. }
  27907. break;
  27908. default:
  27909. strBuf.push(String.fromCharCode(ch));
  27910. break;
  27911. }
  27912. if (done) {
  27913. break;
  27914. }
  27915. if (!charBuffered) {
  27916. ch = this.nextChar();
  27917. }
  27918. }
  27919. return strBuf.join('');
  27920. },
  27921. getName: function Lexer_getName() {
  27922. var ch, previousCh;
  27923. var strBuf = this.strBuf;
  27924. strBuf.length = 0;
  27925. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27926. if (ch === 0x23) { // '#'
  27927. ch = this.nextChar();
  27928. if (specialChars[ch]) {
  27929. warn('Lexer_getName: ' +
  27930. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  27931. strBuf.push('#');
  27932. break;
  27933. }
  27934. var x = toHexDigit(ch);
  27935. if (x !== -1) {
  27936. previousCh = ch;
  27937. ch = this.nextChar();
  27938. var x2 = toHexDigit(ch);
  27939. if (x2 === -1) {
  27940. warn('Lexer_getName: Illegal digit (' +
  27941. String.fromCharCode(ch) +') in hexadecimal number.');
  27942. strBuf.push('#', String.fromCharCode(previousCh));
  27943. if (specialChars[ch]) {
  27944. break;
  27945. }
  27946. strBuf.push(String.fromCharCode(ch));
  27947. continue;
  27948. }
  27949. strBuf.push(String.fromCharCode((x << 4) | x2));
  27950. } else {
  27951. strBuf.push('#', String.fromCharCode(ch));
  27952. }
  27953. } else {
  27954. strBuf.push(String.fromCharCode(ch));
  27955. }
  27956. }
  27957. if (strBuf.length > 127) {
  27958. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  27959. }
  27960. return Name.get(strBuf.join(''));
  27961. },
  27962. getHexString: function Lexer_getHexString() {
  27963. var strBuf = this.strBuf;
  27964. strBuf.length = 0;
  27965. var ch = this.currentChar;
  27966. var isFirstHex = true;
  27967. var firstDigit;
  27968. var secondDigit;
  27969. while (true) {
  27970. if (ch < 0) {
  27971. warn('Unterminated hex string');
  27972. break;
  27973. } else if (ch === 0x3E) { // '>'
  27974. this.nextChar();
  27975. break;
  27976. } else if (specialChars[ch] === 1) {
  27977. ch = this.nextChar();
  27978. continue;
  27979. } else {
  27980. if (isFirstHex) {
  27981. firstDigit = toHexDigit(ch);
  27982. if (firstDigit === -1) {
  27983. warn('Ignoring invalid character "' + ch + '" in hex string');
  27984. ch = this.nextChar();
  27985. continue;
  27986. }
  27987. } else {
  27988. secondDigit = toHexDigit(ch);
  27989. if (secondDigit === -1) {
  27990. warn('Ignoring invalid character "' + ch + '" in hex string');
  27991. ch = this.nextChar();
  27992. continue;
  27993. }
  27994. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  27995. }
  27996. isFirstHex = !isFirstHex;
  27997. ch = this.nextChar();
  27998. }
  27999. }
  28000. return strBuf.join('');
  28001. },
  28002. getObj: function Lexer_getObj() {
  28003. // skip whitespace and comments
  28004. var comment = false;
  28005. var ch = this.currentChar;
  28006. while (true) {
  28007. if (ch < 0) {
  28008. return EOF;
  28009. }
  28010. if (comment) {
  28011. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28012. comment = false;
  28013. }
  28014. } else if (ch === 0x25) { // '%'
  28015. comment = true;
  28016. } else if (specialChars[ch] !== 1) {
  28017. break;
  28018. }
  28019. ch = this.nextChar();
  28020. }
  28021. // start reading token
  28022. switch (ch | 0) {
  28023. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28024. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28025. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28026. return this.getNumber();
  28027. case 0x28: // '('
  28028. return this.getString();
  28029. case 0x2F: // '/'
  28030. return this.getName();
  28031. // array punctuation
  28032. case 0x5B: // '['
  28033. this.nextChar();
  28034. return Cmd.get('[');
  28035. case 0x5D: // ']'
  28036. this.nextChar();
  28037. return Cmd.get(']');
  28038. // hex string or dict punctuation
  28039. case 0x3C: // '<'
  28040. ch = this.nextChar();
  28041. if (ch === 0x3C) {
  28042. // dict punctuation
  28043. this.nextChar();
  28044. return Cmd.get('<<');
  28045. }
  28046. return this.getHexString();
  28047. // dict punctuation
  28048. case 0x3E: // '>'
  28049. ch = this.nextChar();
  28050. if (ch === 0x3E) {
  28051. this.nextChar();
  28052. return Cmd.get('>>');
  28053. }
  28054. return Cmd.get('>');
  28055. case 0x7B: // '{'
  28056. this.nextChar();
  28057. return Cmd.get('{');
  28058. case 0x7D: // '}'
  28059. this.nextChar();
  28060. return Cmd.get('}');
  28061. case 0x29: // ')'
  28062. error('Illegal character: ' + ch);
  28063. break;
  28064. }
  28065. // command
  28066. var str = String.fromCharCode(ch);
  28067. var knownCommands = this.knownCommands;
  28068. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28069. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28070. // stop if known command is found and next character does not make
  28071. // the str a command
  28072. var possibleCommand = str + String.fromCharCode(ch);
  28073. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28074. break;
  28075. }
  28076. if (str.length === 128) {
  28077. error('Command token too long: ' + str.length);
  28078. }
  28079. str = possibleCommand;
  28080. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28081. }
  28082. if (str === 'true') {
  28083. return true;
  28084. }
  28085. if (str === 'false') {
  28086. return false;
  28087. }
  28088. if (str === 'null') {
  28089. return null;
  28090. }
  28091. return Cmd.get(str);
  28092. },
  28093. skipToNextLine: function Lexer_skipToNextLine() {
  28094. var ch = this.currentChar;
  28095. while (ch >= 0) {
  28096. if (ch === 0x0D) { // CR
  28097. ch = this.nextChar();
  28098. if (ch === 0x0A) { // LF
  28099. this.nextChar();
  28100. }
  28101. break;
  28102. } else if (ch === 0x0A) { // LF
  28103. this.nextChar();
  28104. break;
  28105. }
  28106. ch = this.nextChar();
  28107. }
  28108. }
  28109. };
  28110. return Lexer;
  28111. })();
  28112. var Linearization = {
  28113. create: function LinearizationCreate(stream) {
  28114. function getInt(name, allowZeroValue) {
  28115. var obj = linDict.get(name);
  28116. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28117. return obj;
  28118. }
  28119. throw new Error('The "' + name + '" parameter in the linearization ' +
  28120. 'dictionary is invalid.');
  28121. }
  28122. function getHints() {
  28123. var hints = linDict.get('H'), hintsLength, item;
  28124. if (isArray(hints) &&
  28125. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28126. for (var index = 0; index < hintsLength; index++) {
  28127. if (!(isInt(item = hints[index]) && item > 0)) {
  28128. throw new Error('Hint (' + index +
  28129. ') in the linearization dictionary is invalid.');
  28130. }
  28131. }
  28132. return hints;
  28133. }
  28134. throw new Error('Hint array in the linearization dictionary is invalid.');
  28135. }
  28136. var parser = new Parser(new Lexer(stream), false, null);
  28137. var obj1 = parser.getObj();
  28138. var obj2 = parser.getObj();
  28139. var obj3 = parser.getObj();
  28140. var linDict = parser.getObj();
  28141. var obj, length;
  28142. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28143. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28144. return null; // No valid linearization dictionary found.
  28145. } else if ((length = getInt('L')) !== stream.length) {
  28146. throw new Error('The "L" parameter in the linearization dictionary ' +
  28147. 'does not equal the stream length.');
  28148. }
  28149. return {
  28150. length: length,
  28151. hints: getHints(),
  28152. objectNumberFirst: getInt('O'),
  28153. endFirst: getInt('E'),
  28154. numPages: getInt('N'),
  28155. mainXRefEntriesOffset: getInt('T'),
  28156. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28157. };
  28158. }
  28159. };
  28160. exports.EOF = EOF;
  28161. exports.Lexer = Lexer;
  28162. exports.Linearization = Linearization;
  28163. exports.Parser = Parser;
  28164. exports.isEOF = isEOF;
  28165. }));
  28166. (function (root, factory) {
  28167. {
  28168. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  28169. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  28170. }
  28171. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  28172. var warn = sharedUtil.warn;
  28173. var isSpace = sharedUtil.isSpace;
  28174. var Stream = coreStream.Stream;
  28175. var getEncoding = coreEncodings.getEncoding;
  28176. // Hinting is currently disabled due to unknown problems on windows
  28177. // in tracemonkey and various other pdfs with type1 fonts.
  28178. var HINTING_ENABLED = false;
  28179. /*
  28180. * CharStrings are encoded following the the CharString Encoding sequence
  28181. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  28182. * The value in a byte indicates a command, a number, or subsequent bytes
  28183. * that are to be interpreted in a special way.
  28184. *
  28185. * CharString Number Encoding:
  28186. * A CharString byte containing the values from 32 through 255 inclusive
  28187. * indicate an integer. These values are decoded in four ranges.
  28188. *
  28189. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  28190. * indicate the integer v - 139. Thus, the integer values from -107 through
  28191. * 107 inclusive may be encoded in single byte.
  28192. *
  28193. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  28194. * indicates an integer involving the next byte, w, according to the formula:
  28195. * [(v - 247) x 256] + w + 108
  28196. *
  28197. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  28198. * indicates an integer involving the next byte, w, according to the formula:
  28199. * -[(v - 251) * 256] - w - 108
  28200. *
  28201. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  28202. * are a two complement signed integer. The first of these bytes contains the
  28203. * highest order bits, the second byte contains the next higher order bits
  28204. * and the fourth byte contain the lowest order bits.
  28205. *
  28206. *
  28207. * CharString Command Encoding:
  28208. * CharStrings commands are encoded in 1 or 2 bytes.
  28209. *
  28210. * Single byte commands are encoded in 1 byte that contains a value between
  28211. * 0 and 31 inclusive.
  28212. * If a command byte contains the value 12, then the value in the next byte
  28213. * indicates a command. This "escape" mechanism allows many extra commands
  28214. * to be encoded and this encoding technique helps to minimize the length of
  28215. * the charStrings.
  28216. */
  28217. var Type1CharString = (function Type1CharStringClosure() {
  28218. var COMMAND_MAP = {
  28219. 'hstem': [1],
  28220. 'vstem': [3],
  28221. 'vmoveto': [4],
  28222. 'rlineto': [5],
  28223. 'hlineto': [6],
  28224. 'vlineto': [7],
  28225. 'rrcurveto': [8],
  28226. 'callsubr': [10],
  28227. 'flex': [12, 35],
  28228. 'drop' : [12, 18],
  28229. 'endchar': [14],
  28230. 'rmoveto': [21],
  28231. 'hmoveto': [22],
  28232. 'vhcurveto': [30],
  28233. 'hvcurveto': [31]
  28234. };
  28235. function Type1CharString() {
  28236. this.width = 0;
  28237. this.lsb = 0;
  28238. this.flexing = false;
  28239. this.output = [];
  28240. this.stack = [];
  28241. }
  28242. Type1CharString.prototype = {
  28243. convert: function Type1CharString_convert(encoded, subrs,
  28244. seacAnalysisEnabled) {
  28245. var count = encoded.length;
  28246. var error = false;
  28247. var wx, sbx, subrNumber;
  28248. for (var i = 0; i < count; i++) {
  28249. var value = encoded[i];
  28250. if (value < 32) {
  28251. if (value === 12) {
  28252. value = (value << 8) + encoded[++i];
  28253. }
  28254. switch (value) {
  28255. case 1: // hstem
  28256. if (!HINTING_ENABLED) {
  28257. this.stack = [];
  28258. break;
  28259. }
  28260. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28261. break;
  28262. case 3: // vstem
  28263. if (!HINTING_ENABLED) {
  28264. this.stack = [];
  28265. break;
  28266. }
  28267. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28268. break;
  28269. case 4: // vmoveto
  28270. if (this.flexing) {
  28271. if (this.stack.length < 1) {
  28272. error = true;
  28273. break;
  28274. }
  28275. // Add the dx for flex and but also swap the values so they are
  28276. // the right order.
  28277. var dy = this.stack.pop();
  28278. this.stack.push(0, dy);
  28279. break;
  28280. }
  28281. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  28282. break;
  28283. case 5: // rlineto
  28284. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  28285. break;
  28286. case 6: // hlineto
  28287. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  28288. break;
  28289. case 7: // vlineto
  28290. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  28291. break;
  28292. case 8: // rrcurveto
  28293. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  28294. break;
  28295. case 9: // closepath
  28296. // closepath is a Type1 command that does not take argument and is
  28297. // useless in Type2 and it can simply be ignored.
  28298. this.stack = [];
  28299. break;
  28300. case 10: // callsubr
  28301. if (this.stack.length < 1) {
  28302. error = true;
  28303. break;
  28304. }
  28305. subrNumber = this.stack.pop();
  28306. error = this.convert(subrs[subrNumber], subrs,
  28307. seacAnalysisEnabled);
  28308. break;
  28309. case 11: // return
  28310. return error;
  28311. case 13: // hsbw
  28312. if (this.stack.length < 2) {
  28313. error = true;
  28314. break;
  28315. }
  28316. // To convert to type2 we have to move the width value to the
  28317. // first part of the charstring and then use hmoveto with lsb.
  28318. wx = this.stack.pop();
  28319. sbx = this.stack.pop();
  28320. this.lsb = sbx;
  28321. this.width = wx;
  28322. this.stack.push(wx, sbx);
  28323. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28324. break;
  28325. case 14: // endchar
  28326. this.output.push(COMMAND_MAP.endchar[0]);
  28327. break;
  28328. case 21: // rmoveto
  28329. if (this.flexing) {
  28330. break;
  28331. }
  28332. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28333. break;
  28334. case 22: // hmoveto
  28335. if (this.flexing) {
  28336. // Add the dy for flex.
  28337. this.stack.push(0);
  28338. break;
  28339. }
  28340. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28341. break;
  28342. case 30: // vhcurveto
  28343. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28344. break;
  28345. case 31: // hvcurveto
  28346. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28347. break;
  28348. case (12 << 8) + 0: // dotsection
  28349. // dotsection is a Type1 command to specify some hinting feature
  28350. // for dots that do not take a parameter and it can safely be
  28351. // ignored for Type2.
  28352. this.stack = [];
  28353. break;
  28354. case (12 << 8) + 1: // vstem3
  28355. if (!HINTING_ENABLED) {
  28356. this.stack = [];
  28357. break;
  28358. }
  28359. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28360. // multiple parameters, so instead of returning [vh]stem3 take a
  28361. // shortcut and return [vhstem] instead.
  28362. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28363. break;
  28364. case (12 << 8) + 2: // hstem3
  28365. if (!HINTING_ENABLED) {
  28366. this.stack = [];
  28367. break;
  28368. }
  28369. // See vstem3.
  28370. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28371. break;
  28372. case (12 << 8) + 6: // seac
  28373. // seac is like type 2's special endchar but it doesn't use the
  28374. // first argument asb, so remove it.
  28375. if (seacAnalysisEnabled) {
  28376. this.seac = this.stack.splice(-4, 4);
  28377. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28378. } else {
  28379. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28380. }
  28381. break;
  28382. case (12 << 8) + 7: // sbw
  28383. if (this.stack.length < 4) {
  28384. error = true;
  28385. break;
  28386. }
  28387. // To convert to type2 we have to move the width value to the
  28388. // first part of the charstring and then use rmoveto with
  28389. // (dx, dy). The height argument will not be used for vmtx and
  28390. // vhea tables reconstruction -- ignoring it.
  28391. var wy = this.stack.pop();
  28392. wx = this.stack.pop();
  28393. var sby = this.stack.pop();
  28394. sbx = this.stack.pop();
  28395. this.lsb = sbx;
  28396. this.width = wx;
  28397. this.stack.push(wx, sbx, sby);
  28398. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28399. break;
  28400. case (12 << 8) + 12: // div
  28401. if (this.stack.length < 2) {
  28402. error = true;
  28403. break;
  28404. }
  28405. var num2 = this.stack.pop();
  28406. var num1 = this.stack.pop();
  28407. this.stack.push(num1 / num2);
  28408. break;
  28409. case (12 << 8) + 16: // callothersubr
  28410. if (this.stack.length < 2) {
  28411. error = true;
  28412. break;
  28413. }
  28414. subrNumber = this.stack.pop();
  28415. var numArgs = this.stack.pop();
  28416. if (subrNumber === 0 && numArgs === 3) {
  28417. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28418. this.stack.push(
  28419. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28420. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28421. flexArgs[4], // bcp2x
  28422. flexArgs[5], // bcp2y
  28423. flexArgs[6], // p2x
  28424. flexArgs[7], // p2y
  28425. flexArgs[8], // bcp3x
  28426. flexArgs[9], // bcp3y
  28427. flexArgs[10], // bcp4x
  28428. flexArgs[11], // bcp4y
  28429. flexArgs[12], // p3x
  28430. flexArgs[13], // p3y
  28431. flexArgs[14] // flexDepth
  28432. // 15 = finalx unused by flex
  28433. // 16 = finaly unused by flex
  28434. );
  28435. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28436. this.flexing = false;
  28437. this.stack.push(flexArgs[15], flexArgs[16]);
  28438. } else if (subrNumber === 1 && numArgs === 0) {
  28439. this.flexing = true;
  28440. }
  28441. break;
  28442. case (12 << 8) + 17: // pop
  28443. // Ignore this since it is only used with othersubr.
  28444. break;
  28445. case (12 << 8) + 33: // setcurrentpoint
  28446. // Ignore for now.
  28447. this.stack = [];
  28448. break;
  28449. default:
  28450. warn('Unknown type 1 charstring command of "' + value + '"');
  28451. break;
  28452. }
  28453. if (error) {
  28454. break;
  28455. }
  28456. continue;
  28457. } else if (value <= 246) {
  28458. value = value - 139;
  28459. } else if (value <= 250) {
  28460. value = ((value - 247) * 256) + encoded[++i] + 108;
  28461. } else if (value <= 254) {
  28462. value = -((value - 251) * 256) - encoded[++i] - 108;
  28463. } else {
  28464. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28465. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28466. }
  28467. this.stack.push(value);
  28468. }
  28469. return error;
  28470. },
  28471. executeCommand: function(howManyArgs, command, keepStack) {
  28472. var stackLength = this.stack.length;
  28473. if (howManyArgs > stackLength) {
  28474. return true;
  28475. }
  28476. var start = stackLength - howManyArgs;
  28477. for (var i = start; i < stackLength; i++) {
  28478. var value = this.stack[i];
  28479. if (value === (value | 0)) { // int
  28480. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28481. } else { // fixed point
  28482. value = (65536 * value) | 0;
  28483. this.output.push(255,
  28484. (value >> 24) & 0xFF,
  28485. (value >> 16) & 0xFF,
  28486. (value >> 8) & 0xFF,
  28487. value & 0xFF);
  28488. }
  28489. }
  28490. this.output.push.apply(this.output, command);
  28491. if (keepStack) {
  28492. this.stack.splice(start, howManyArgs);
  28493. } else {
  28494. this.stack.length = 0;
  28495. }
  28496. return false;
  28497. }
  28498. };
  28499. return Type1CharString;
  28500. })();
  28501. /*
  28502. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28503. * program. Some of its logic depends on the Type2 charstrings
  28504. * structure.
  28505. * Note: this doesn't really parse the font since that would require evaluation
  28506. * of PostScript, but it is possible in most cases to extract what we need
  28507. * without a full parse.
  28508. */
  28509. var Type1Parser = (function Type1ParserClosure() {
  28510. /*
  28511. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28512. * of Plaintext Bytes. The function took a key as a parameter which can be
  28513. * for decrypting the eexec block of for decoding charStrings.
  28514. */
  28515. var EEXEC_ENCRYPT_KEY = 55665;
  28516. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28517. function isHexDigit(code) {
  28518. return code >= 48 && code <= 57 || // '0'-'9'
  28519. code >= 65 && code <= 70 || // 'A'-'F'
  28520. code >= 97 && code <= 102; // 'a'-'f'
  28521. }
  28522. function decrypt(data, key, discardNumber) {
  28523. if (discardNumber >= data.length) {
  28524. return new Uint8Array(0);
  28525. }
  28526. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  28527. for (i = 0; i < discardNumber; i++) {
  28528. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  28529. }
  28530. var count = data.length - discardNumber;
  28531. var decrypted = new Uint8Array(count);
  28532. for (i = discardNumber, j = 0; j < count; i++, j++) {
  28533. var value = data[i];
  28534. decrypted[j] = value ^ (r >> 8);
  28535. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28536. }
  28537. return decrypted;
  28538. }
  28539. function decryptAscii(data, key, discardNumber) {
  28540. var r = key | 0, c1 = 52845, c2 = 22719;
  28541. var count = data.length, maybeLength = count >>> 1;
  28542. var decrypted = new Uint8Array(maybeLength);
  28543. var i, j;
  28544. for (i = 0, j = 0; i < count; i++) {
  28545. var digit1 = data[i];
  28546. if (!isHexDigit(digit1)) {
  28547. continue;
  28548. }
  28549. i++;
  28550. var digit2;
  28551. while (i < count && !isHexDigit(digit2 = data[i])) {
  28552. i++;
  28553. }
  28554. if (i < count) {
  28555. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28556. decrypted[j++] = value ^ (r >> 8);
  28557. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28558. }
  28559. }
  28560. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28561. }
  28562. function isSpecial(c) {
  28563. return c === 0x2F || // '/'
  28564. c === 0x5B || c === 0x5D || // '[', ']'
  28565. c === 0x7B || c === 0x7D || // '{', '}'
  28566. c === 0x28 || c === 0x29; // '(', ')'
  28567. }
  28568. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  28569. if (encrypted) {
  28570. var data = stream.getBytes();
  28571. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28572. isHexDigit(data[2]) && isHexDigit(data[3]));
  28573. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28574. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28575. }
  28576. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  28577. this.stream = stream;
  28578. this.nextChar();
  28579. }
  28580. Type1Parser.prototype = {
  28581. readNumberArray: function Type1Parser_readNumberArray() {
  28582. this.getToken(); // read '[' or '{' (arrays can start with either)
  28583. var array = [];
  28584. while (true) {
  28585. var token = this.getToken();
  28586. if (token === null || token === ']' || token === '}') {
  28587. break;
  28588. }
  28589. array.push(parseFloat(token || 0));
  28590. }
  28591. return array;
  28592. },
  28593. readNumber: function Type1Parser_readNumber() {
  28594. var token = this.getToken();
  28595. return parseFloat(token || 0);
  28596. },
  28597. readInt: function Type1Parser_readInt() {
  28598. // Use '| 0' to prevent setting a double into length such as the double
  28599. // does not flow into the loop variable.
  28600. var token = this.getToken();
  28601. return parseInt(token || 0, 10) | 0;
  28602. },
  28603. readBoolean: function Type1Parser_readBoolean() {
  28604. var token = this.getToken();
  28605. // Use 1 and 0 since that's what type2 charstrings use.
  28606. return token === 'true' ? 1 : 0;
  28607. },
  28608. nextChar : function Type1_nextChar() {
  28609. return (this.currentChar = this.stream.getByte());
  28610. },
  28611. getToken: function Type1Parser_getToken() {
  28612. // Eat whitespace and comments.
  28613. var comment = false;
  28614. var ch = this.currentChar;
  28615. while (true) {
  28616. if (ch === -1) {
  28617. return null;
  28618. }
  28619. if (comment) {
  28620. if (ch === 0x0A || ch === 0x0D) {
  28621. comment = false;
  28622. }
  28623. } else if (ch === 0x25) { // '%'
  28624. comment = true;
  28625. } else if (!isSpace(ch)) {
  28626. break;
  28627. }
  28628. ch = this.nextChar();
  28629. }
  28630. if (isSpecial(ch)) {
  28631. this.nextChar();
  28632. return String.fromCharCode(ch);
  28633. }
  28634. var token = '';
  28635. do {
  28636. token += String.fromCharCode(ch);
  28637. ch = this.nextChar();
  28638. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  28639. return token;
  28640. },
  28641. /*
  28642. * Returns an object containing a Subrs array and a CharStrings
  28643. * array extracted from and eexec encrypted block of data
  28644. */
  28645. extractFontProgram: function Type1Parser_extractFontProgram() {
  28646. var stream = this.stream;
  28647. var subrs = [], charstrings = [];
  28648. var privateData = Object.create(null);
  28649. privateData['lenIV'] = 4;
  28650. var program = {
  28651. subrs: [],
  28652. charstrings: [],
  28653. properties: {
  28654. 'privateData': privateData
  28655. }
  28656. };
  28657. var token, length, data, lenIV, encoded;
  28658. while ((token = this.getToken()) !== null) {
  28659. if (token !== '/') {
  28660. continue;
  28661. }
  28662. token = this.getToken();
  28663. switch (token) {
  28664. case 'CharStrings':
  28665. // The number immediately following CharStrings must be greater or
  28666. // equal to the number of CharStrings.
  28667. this.getToken();
  28668. this.getToken(); // read in 'dict'
  28669. this.getToken(); // read in 'dup'
  28670. this.getToken(); // read in 'begin'
  28671. while(true) {
  28672. token = this.getToken();
  28673. if (token === null || token === 'end') {
  28674. break;
  28675. }
  28676. if (token !== '/') {
  28677. continue;
  28678. }
  28679. var glyph = this.getToken();
  28680. length = this.readInt();
  28681. this.getToken(); // read in 'RD' or '-|'
  28682. data = stream.makeSubStream(stream.pos, length);
  28683. lenIV = program.properties.privateData['lenIV'];
  28684. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28685. // Skip past the required space and binary data.
  28686. stream.skip(length);
  28687. this.nextChar();
  28688. token = this.getToken(); // read in 'ND' or '|-'
  28689. if (token === 'noaccess') {
  28690. this.getToken(); // read in 'def'
  28691. }
  28692. charstrings.push({
  28693. glyph: glyph,
  28694. encoded: encoded
  28695. });
  28696. }
  28697. break;
  28698. case 'Subrs':
  28699. var num = this.readInt();
  28700. this.getToken(); // read in 'array'
  28701. while ((token = this.getToken()) === 'dup') {
  28702. var index = this.readInt();
  28703. length = this.readInt();
  28704. this.getToken(); // read in 'RD' or '-|'
  28705. data = stream.makeSubStream(stream.pos, length);
  28706. lenIV = program.properties.privateData['lenIV'];
  28707. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28708. // Skip past the required space and binary data.
  28709. stream.skip(length);
  28710. this.nextChar();
  28711. token = this.getToken(); // read in 'NP' or '|'
  28712. if (token === 'noaccess') {
  28713. this.getToken(); // read in 'put'
  28714. }
  28715. subrs[index] = encoded;
  28716. }
  28717. break;
  28718. case 'BlueValues':
  28719. case 'OtherBlues':
  28720. case 'FamilyBlues':
  28721. case 'FamilyOtherBlues':
  28722. var blueArray = this.readNumberArray();
  28723. // *Blue* values may contain invalid data: disables reading of
  28724. // those values when hinting is disabled.
  28725. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28726. HINTING_ENABLED) {
  28727. program.properties.privateData[token] = blueArray;
  28728. }
  28729. break;
  28730. case 'StemSnapH':
  28731. case 'StemSnapV':
  28732. program.properties.privateData[token] = this.readNumberArray();
  28733. break;
  28734. case 'StdHW':
  28735. case 'StdVW':
  28736. program.properties.privateData[token] =
  28737. this.readNumberArray()[0];
  28738. break;
  28739. case 'BlueShift':
  28740. case 'lenIV':
  28741. case 'BlueFuzz':
  28742. case 'BlueScale':
  28743. case 'LanguageGroup':
  28744. case 'ExpansionFactor':
  28745. program.properties.privateData[token] = this.readNumber();
  28746. break;
  28747. case 'ForceBold':
  28748. program.properties.privateData[token] = this.readBoolean();
  28749. break;
  28750. }
  28751. }
  28752. for (var i = 0; i < charstrings.length; i++) {
  28753. glyph = charstrings[i].glyph;
  28754. encoded = charstrings[i].encoded;
  28755. var charString = new Type1CharString();
  28756. var error = charString.convert(encoded, subrs,
  28757. this.seacAnalysisEnabled);
  28758. var output = charString.output;
  28759. if (error) {
  28760. // It seems when FreeType encounters an error while evaluating a glyph
  28761. // that it completely ignores the glyph so we'll mimic that behaviour
  28762. // here and put an endchar to make the validator happy.
  28763. output = [14];
  28764. }
  28765. program.charstrings.push({
  28766. glyphName: glyph,
  28767. charstring: output,
  28768. width: charString.width,
  28769. lsb: charString.lsb,
  28770. seac: charString.seac
  28771. });
  28772. }
  28773. return program;
  28774. },
  28775. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28776. var token;
  28777. while ((token = this.getToken()) !== null) {
  28778. if (token !== '/') {
  28779. continue;
  28780. }
  28781. token = this.getToken();
  28782. switch (token) {
  28783. case 'FontMatrix':
  28784. var matrix = this.readNumberArray();
  28785. properties.fontMatrix = matrix;
  28786. break;
  28787. case 'Encoding':
  28788. var encodingArg = this.getToken();
  28789. var encoding;
  28790. if (!/^\d+$/.test(encodingArg)) {
  28791. // encoding name is specified
  28792. encoding = getEncoding(encodingArg);
  28793. } else {
  28794. encoding = [];
  28795. var size = parseInt(encodingArg, 10) | 0;
  28796. this.getToken(); // read in 'array'
  28797. for (var j = 0; j < size; j++) {
  28798. token = this.getToken();
  28799. // skipping till first dup or def (e.g. ignoring for statement)
  28800. while (token !== 'dup' && token !== 'def') {
  28801. token = this.getToken();
  28802. if (token === null) {
  28803. return; // invalid header
  28804. }
  28805. }
  28806. if (token === 'def') {
  28807. break; // read all array data
  28808. }
  28809. var index = this.readInt();
  28810. this.getToken(); // read in '/'
  28811. var glyph = this.getToken();
  28812. encoding[index] = glyph;
  28813. this.getToken(); // read the in 'put'
  28814. }
  28815. }
  28816. properties.builtInEncoding = encoding;
  28817. break;
  28818. case 'FontBBox':
  28819. var fontBBox = this.readNumberArray();
  28820. // adjusting ascent/descent
  28821. properties.ascent = fontBBox[3];
  28822. properties.descent = fontBBox[1];
  28823. properties.ascentScaled = true;
  28824. break;
  28825. }
  28826. }
  28827. }
  28828. };
  28829. return Type1Parser;
  28830. })();
  28831. exports.Type1Parser = Type1Parser;
  28832. }));
  28833. (function (root, factory) {
  28834. {
  28835. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  28836. root.pdfjsDisplayWebGL);
  28837. }
  28838. }(this, function (exports, sharedUtil, displayWebGL) {
  28839. var Util = sharedUtil.Util;
  28840. var info = sharedUtil.info;
  28841. var isArray = sharedUtil.isArray;
  28842. var error = sharedUtil.error;
  28843. var WebGLUtils = displayWebGL.WebGLUtils;
  28844. var ShadingIRs = {};
  28845. ShadingIRs.RadialAxial = {
  28846. fromIR: function RadialAxial_fromIR(raw) {
  28847. var type = raw[1];
  28848. var colorStops = raw[2];
  28849. var p0 = raw[3];
  28850. var p1 = raw[4];
  28851. var r0 = raw[5];
  28852. var r1 = raw[6];
  28853. return {
  28854. type: 'Pattern',
  28855. getPattern: function RadialAxial_getPattern(ctx) {
  28856. var grad;
  28857. if (type === 'axial') {
  28858. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  28859. } else if (type === 'radial') {
  28860. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  28861. }
  28862. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  28863. var c = colorStops[i];
  28864. grad.addColorStop(c[0], c[1]);
  28865. }
  28866. return grad;
  28867. }
  28868. };
  28869. }
  28870. };
  28871. var createMeshCanvas = (function createMeshCanvasClosure() {
  28872. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  28873. // Very basic Gouraud-shaded triangle rasterization algorithm.
  28874. var coords = context.coords, colors = context.colors;
  28875. var bytes = data.data, rowSize = data.width * 4;
  28876. var tmp;
  28877. if (coords[p1 + 1] > coords[p2 + 1]) {
  28878. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  28879. }
  28880. if (coords[p2 + 1] > coords[p3 + 1]) {
  28881. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  28882. }
  28883. if (coords[p1 + 1] > coords[p2 + 1]) {
  28884. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  28885. }
  28886. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  28887. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  28888. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  28889. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  28890. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  28891. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  28892. if (y1 >= y3) {
  28893. return;
  28894. }
  28895. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  28896. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  28897. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  28898. var minY = Math.round(y1), maxY = Math.round(y3);
  28899. var xa, car, cag, cab;
  28900. var xb, cbr, cbg, cbb;
  28901. var k;
  28902. for (var y = minY; y <= maxY; y++) {
  28903. if (y < y2) {
  28904. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  28905. xa = x1 - (x1 - x2) * k;
  28906. car = c1r - (c1r - c2r) * k;
  28907. cag = c1g - (c1g - c2g) * k;
  28908. cab = c1b - (c1b - c2b) * k;
  28909. } else {
  28910. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  28911. xa = x2 - (x2 - x3) * k;
  28912. car = c2r - (c2r - c3r) * k;
  28913. cag = c2g - (c2g - c3g) * k;
  28914. cab = c2b - (c2b - c3b) * k;
  28915. }
  28916. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  28917. xb = x1 - (x1 - x3) * k;
  28918. cbr = c1r - (c1r - c3r) * k;
  28919. cbg = c1g - (c1g - c3g) * k;
  28920. cbb = c1b - (c1b - c3b) * k;
  28921. var x1_ = Math.round(Math.min(xa, xb));
  28922. var x2_ = Math.round(Math.max(xa, xb));
  28923. var j = rowSize * y + x1_ * 4;
  28924. for (var x = x1_; x <= x2_; x++) {
  28925. k = (xa - x) / (xa - xb);
  28926. k = k < 0 ? 0 : k > 1 ? 1 : k;
  28927. bytes[j++] = (car - (car - cbr) * k) | 0;
  28928. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  28929. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  28930. bytes[j++] = 255;
  28931. }
  28932. }
  28933. }
  28934. function drawFigure(data, figure, context) {
  28935. var ps = figure.coords;
  28936. var cs = figure.colors;
  28937. var i, ii;
  28938. switch (figure.type) {
  28939. case 'lattice':
  28940. var verticesPerRow = figure.verticesPerRow;
  28941. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  28942. var cols = verticesPerRow - 1;
  28943. for (i = 0; i < rows; i++) {
  28944. var q = i * verticesPerRow;
  28945. for (var j = 0; j < cols; j++, q++) {
  28946. drawTriangle(data, context,
  28947. ps[q], ps[q + 1], ps[q + verticesPerRow],
  28948. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  28949. drawTriangle(data, context,
  28950. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  28951. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  28952. }
  28953. }
  28954. break;
  28955. case 'triangles':
  28956. for (i = 0, ii = ps.length; i < ii; i += 3) {
  28957. drawTriangle(data, context,
  28958. ps[i], ps[i + 1], ps[i + 2],
  28959. cs[i], cs[i + 1], cs[i + 2]);
  28960. }
  28961. break;
  28962. default:
  28963. error('illigal figure');
  28964. break;
  28965. }
  28966. }
  28967. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  28968. backgroundColor, cachedCanvases) {
  28969. // we will increase scale on some weird factor to let antialiasing take
  28970. // care of "rough" edges
  28971. var EXPECTED_SCALE = 1.1;
  28972. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  28973. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  28974. // We need to keep transparent border around our pattern for fill():
  28975. // createPattern with 'no-repeat' will bleed edges across entire area.
  28976. var BORDER_SIZE = 2;
  28977. var offsetX = Math.floor(bounds[0]);
  28978. var offsetY = Math.floor(bounds[1]);
  28979. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  28980. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  28981. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  28982. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  28983. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  28984. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  28985. var scaleX = boundsWidth / width;
  28986. var scaleY = boundsHeight / height;
  28987. var context = {
  28988. coords: coords,
  28989. colors: colors,
  28990. offsetX: -offsetX,
  28991. offsetY: -offsetY,
  28992. scaleX: 1 / scaleX,
  28993. scaleY: 1 / scaleY
  28994. };
  28995. var paddedWidth = width + BORDER_SIZE * 2;
  28996. var paddedHeight = height + BORDER_SIZE * 2;
  28997. var canvas, tmpCanvas, i, ii;
  28998. if (WebGLUtils.isEnabled) {
  28999. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  29000. figures, context);
  29001. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  29002. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29003. false);
  29004. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  29005. canvas = tmpCanvas.canvas;
  29006. } else {
  29007. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29008. false);
  29009. var tmpCtx = tmpCanvas.context;
  29010. var data = tmpCtx.createImageData(width, height);
  29011. if (backgroundColor) {
  29012. var bytes = data.data;
  29013. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  29014. bytes[i] = backgroundColor[0];
  29015. bytes[i + 1] = backgroundColor[1];
  29016. bytes[i + 2] = backgroundColor[2];
  29017. bytes[i + 3] = 255;
  29018. }
  29019. }
  29020. for (i = 0; i < figures.length; i++) {
  29021. drawFigure(data, figures[i], context);
  29022. }
  29023. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  29024. canvas = tmpCanvas.canvas;
  29025. }
  29026. return {canvas: canvas,
  29027. offsetX: offsetX - BORDER_SIZE * scaleX,
  29028. offsetY: offsetY - BORDER_SIZE * scaleY,
  29029. scaleX: scaleX, scaleY: scaleY};
  29030. }
  29031. return createMeshCanvas;
  29032. })();
  29033. ShadingIRs.Mesh = {
  29034. fromIR: function Mesh_fromIR(raw) {
  29035. //var type = raw[1];
  29036. var coords = raw[2];
  29037. var colors = raw[3];
  29038. var figures = raw[4];
  29039. var bounds = raw[5];
  29040. var matrix = raw[6];
  29041. //var bbox = raw[7];
  29042. var background = raw[8];
  29043. return {
  29044. type: 'Pattern',
  29045. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  29046. var scale;
  29047. if (shadingFill) {
  29048. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  29049. } else {
  29050. // Obtain scale from matrix and current transformation matrix.
  29051. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  29052. if (matrix) {
  29053. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  29054. scale = [scale[0] * matrixScale[0],
  29055. scale[1] * matrixScale[1]];
  29056. }
  29057. }
  29058. // Rasterizing on the main thread since sending/queue large canvases
  29059. // might cause OOM.
  29060. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  29061. colors, figures, shadingFill ? null : background,
  29062. owner.cachedCanvases);
  29063. if (!shadingFill) {
  29064. ctx.setTransform.apply(ctx, owner.baseTransform);
  29065. if (matrix) {
  29066. ctx.transform.apply(ctx, matrix);
  29067. }
  29068. }
  29069. ctx.translate(temporaryPatternCanvas.offsetX,
  29070. temporaryPatternCanvas.offsetY);
  29071. ctx.scale(temporaryPatternCanvas.scaleX,
  29072. temporaryPatternCanvas.scaleY);
  29073. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  29074. }
  29075. };
  29076. }
  29077. };
  29078. ShadingIRs.Dummy = {
  29079. fromIR: function Dummy_fromIR() {
  29080. return {
  29081. type: 'Pattern',
  29082. getPattern: function Dummy_fromIR_getPattern() {
  29083. return 'hotpink';
  29084. }
  29085. };
  29086. }
  29087. };
  29088. function getShadingPatternFromIR(raw) {
  29089. var shadingIR = ShadingIRs[raw[0]];
  29090. if (!shadingIR) {
  29091. error('Unknown IR type: ' + raw[0]);
  29092. }
  29093. return shadingIR.fromIR(raw);
  29094. }
  29095. var TilingPattern = (function TilingPatternClosure() {
  29096. var PaintType = {
  29097. COLORED: 1,
  29098. UNCOLORED: 2
  29099. };
  29100. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29101. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  29102. this.operatorList = IR[2];
  29103. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  29104. this.bbox = IR[4];
  29105. this.xstep = IR[5];
  29106. this.ystep = IR[6];
  29107. this.paintType = IR[7];
  29108. this.tilingType = IR[8];
  29109. this.color = color;
  29110. this.canvasGraphicsFactory = canvasGraphicsFactory;
  29111. this.baseTransform = baseTransform;
  29112. this.type = 'Pattern';
  29113. this.ctx = ctx;
  29114. }
  29115. TilingPattern.prototype = {
  29116. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  29117. var operatorList = this.operatorList;
  29118. var bbox = this.bbox;
  29119. var xstep = this.xstep;
  29120. var ystep = this.ystep;
  29121. var paintType = this.paintType;
  29122. var tilingType = this.tilingType;
  29123. var color = this.color;
  29124. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  29125. info('TilingType: ' + tilingType);
  29126. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  29127. var topLeft = [x0, y0];
  29128. // we want the canvas to be as large as the step size
  29129. var botRight = [x0 + xstep, y0 + ystep];
  29130. var width = botRight[0] - topLeft[0];
  29131. var height = botRight[1] - topLeft[1];
  29132. // Obtain scale from matrix and current transformation matrix.
  29133. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  29134. var curMatrixScale = Util.singularValueDecompose2dScale(
  29135. this.baseTransform);
  29136. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  29137. matrixScale[1] * curMatrixScale[1]];
  29138. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29139. // Use width and height values that are as close as possible to the end
  29140. // result when the pattern is used. Too low value makes the pattern look
  29141. // blurry. Too large value makes it look too crispy.
  29142. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  29143. MAX_PATTERN_SIZE);
  29144. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  29145. MAX_PATTERN_SIZE);
  29146. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  29147. width, height, true);
  29148. var tmpCtx = tmpCanvas.context;
  29149. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  29150. graphics.groupLevel = owner.groupLevel;
  29151. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  29152. this.setScale(width, height, xstep, ystep);
  29153. this.transformToScale(graphics);
  29154. // transform coordinates to pattern space
  29155. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  29156. graphics.transform.apply(graphics, tmpTranslate);
  29157. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  29158. graphics.executeOperatorList(operatorList);
  29159. return tmpCanvas.canvas;
  29160. },
  29161. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  29162. this.scale = [width / xstep, height / ystep];
  29163. },
  29164. transformToScale: function TilingPattern_transformToScale(graphics) {
  29165. var scale = this.scale;
  29166. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  29167. graphics.transform.apply(graphics, tmpScale);
  29168. },
  29169. scaleToContext: function TilingPattern_scaleToContext() {
  29170. var scale = this.scale;
  29171. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  29172. },
  29173. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  29174. if (bbox && isArray(bbox) && bbox.length === 4) {
  29175. var bboxWidth = x1 - x0;
  29176. var bboxHeight = y1 - y0;
  29177. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  29178. graphics.clip();
  29179. graphics.endPath();
  29180. }
  29181. },
  29182. setFillAndStrokeStyleToContext:
  29183. function setFillAndStrokeStyleToContext(context, paintType, color) {
  29184. switch (paintType) {
  29185. case PaintType.COLORED:
  29186. var ctx = this.ctx;
  29187. context.fillStyle = ctx.fillStyle;
  29188. context.strokeStyle = ctx.strokeStyle;
  29189. break;
  29190. case PaintType.UNCOLORED:
  29191. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  29192. context.fillStyle = cssColor;
  29193. context.strokeStyle = cssColor;
  29194. break;
  29195. default:
  29196. error('Unsupported paint type: ' + paintType);
  29197. }
  29198. },
  29199. getPattern: function TilingPattern_getPattern(ctx, owner) {
  29200. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  29201. ctx = this.ctx;
  29202. ctx.setTransform.apply(ctx, this.baseTransform);
  29203. ctx.transform.apply(ctx, this.matrix);
  29204. this.scaleToContext();
  29205. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  29206. }
  29207. };
  29208. return TilingPattern;
  29209. })();
  29210. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  29211. exports.TilingPattern = TilingPattern;
  29212. }));
  29213. (function (root, factory) {
  29214. {
  29215. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  29216. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  29217. }
  29218. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  29219. var Util = sharedUtil.Util;
  29220. var assert = sharedUtil.assert;
  29221. var warn = sharedUtil.warn;
  29222. var error = sharedUtil.error;
  29223. var isInt = sharedUtil.isInt;
  29224. var isString = sharedUtil.isString;
  29225. var MissingDataException = sharedUtil.MissingDataException;
  29226. var isName = corePrimitives.isName;
  29227. var isCmd = corePrimitives.isCmd;
  29228. var isStream = corePrimitives.isStream;
  29229. var StringStream = coreStream.StringStream;
  29230. var Lexer = coreParser.Lexer;
  29231. var isEOF = coreParser.isEOF;
  29232. var BUILT_IN_CMAPS = [
  29233. // << Start unicode maps.
  29234. 'Adobe-GB1-UCS2',
  29235. 'Adobe-CNS1-UCS2',
  29236. 'Adobe-Japan1-UCS2',
  29237. 'Adobe-Korea1-UCS2',
  29238. // >> End unicode maps.
  29239. '78-EUC-H',
  29240. '78-EUC-V',
  29241. '78-H',
  29242. '78-RKSJ-H',
  29243. '78-RKSJ-V',
  29244. '78-V',
  29245. '78ms-RKSJ-H',
  29246. '78ms-RKSJ-V',
  29247. '83pv-RKSJ-H',
  29248. '90ms-RKSJ-H',
  29249. '90ms-RKSJ-V',
  29250. '90msp-RKSJ-H',
  29251. '90msp-RKSJ-V',
  29252. '90pv-RKSJ-H',
  29253. '90pv-RKSJ-V',
  29254. 'Add-H',
  29255. 'Add-RKSJ-H',
  29256. 'Add-RKSJ-V',
  29257. 'Add-V',
  29258. 'Adobe-CNS1-0',
  29259. 'Adobe-CNS1-1',
  29260. 'Adobe-CNS1-2',
  29261. 'Adobe-CNS1-3',
  29262. 'Adobe-CNS1-4',
  29263. 'Adobe-CNS1-5',
  29264. 'Adobe-CNS1-6',
  29265. 'Adobe-GB1-0',
  29266. 'Adobe-GB1-1',
  29267. 'Adobe-GB1-2',
  29268. 'Adobe-GB1-3',
  29269. 'Adobe-GB1-4',
  29270. 'Adobe-GB1-5',
  29271. 'Adobe-Japan1-0',
  29272. 'Adobe-Japan1-1',
  29273. 'Adobe-Japan1-2',
  29274. 'Adobe-Japan1-3',
  29275. 'Adobe-Japan1-4',
  29276. 'Adobe-Japan1-5',
  29277. 'Adobe-Japan1-6',
  29278. 'Adobe-Korea1-0',
  29279. 'Adobe-Korea1-1',
  29280. 'Adobe-Korea1-2',
  29281. 'B5-H',
  29282. 'B5-V',
  29283. 'B5pc-H',
  29284. 'B5pc-V',
  29285. 'CNS-EUC-H',
  29286. 'CNS-EUC-V',
  29287. 'CNS1-H',
  29288. 'CNS1-V',
  29289. 'CNS2-H',
  29290. 'CNS2-V',
  29291. 'ETHK-B5-H',
  29292. 'ETHK-B5-V',
  29293. 'ETen-B5-H',
  29294. 'ETen-B5-V',
  29295. 'ETenms-B5-H',
  29296. 'ETenms-B5-V',
  29297. 'EUC-H',
  29298. 'EUC-V',
  29299. 'Ext-H',
  29300. 'Ext-RKSJ-H',
  29301. 'Ext-RKSJ-V',
  29302. 'Ext-V',
  29303. 'GB-EUC-H',
  29304. 'GB-EUC-V',
  29305. 'GB-H',
  29306. 'GB-V',
  29307. 'GBK-EUC-H',
  29308. 'GBK-EUC-V',
  29309. 'GBK2K-H',
  29310. 'GBK2K-V',
  29311. 'GBKp-EUC-H',
  29312. 'GBKp-EUC-V',
  29313. 'GBT-EUC-H',
  29314. 'GBT-EUC-V',
  29315. 'GBT-H',
  29316. 'GBT-V',
  29317. 'GBTpc-EUC-H',
  29318. 'GBTpc-EUC-V',
  29319. 'GBpc-EUC-H',
  29320. 'GBpc-EUC-V',
  29321. 'H',
  29322. 'HKdla-B5-H',
  29323. 'HKdla-B5-V',
  29324. 'HKdlb-B5-H',
  29325. 'HKdlb-B5-V',
  29326. 'HKgccs-B5-H',
  29327. 'HKgccs-B5-V',
  29328. 'HKm314-B5-H',
  29329. 'HKm314-B5-V',
  29330. 'HKm471-B5-H',
  29331. 'HKm471-B5-V',
  29332. 'HKscs-B5-H',
  29333. 'HKscs-B5-V',
  29334. 'Hankaku',
  29335. 'Hiragana',
  29336. 'KSC-EUC-H',
  29337. 'KSC-EUC-V',
  29338. 'KSC-H',
  29339. 'KSC-Johab-H',
  29340. 'KSC-Johab-V',
  29341. 'KSC-V',
  29342. 'KSCms-UHC-H',
  29343. 'KSCms-UHC-HW-H',
  29344. 'KSCms-UHC-HW-V',
  29345. 'KSCms-UHC-V',
  29346. 'KSCpc-EUC-H',
  29347. 'KSCpc-EUC-V',
  29348. 'Katakana',
  29349. 'NWP-H',
  29350. 'NWP-V',
  29351. 'RKSJ-H',
  29352. 'RKSJ-V',
  29353. 'Roman',
  29354. 'UniCNS-UCS2-H',
  29355. 'UniCNS-UCS2-V',
  29356. 'UniCNS-UTF16-H',
  29357. 'UniCNS-UTF16-V',
  29358. 'UniCNS-UTF32-H',
  29359. 'UniCNS-UTF32-V',
  29360. 'UniCNS-UTF8-H',
  29361. 'UniCNS-UTF8-V',
  29362. 'UniGB-UCS2-H',
  29363. 'UniGB-UCS2-V',
  29364. 'UniGB-UTF16-H',
  29365. 'UniGB-UTF16-V',
  29366. 'UniGB-UTF32-H',
  29367. 'UniGB-UTF32-V',
  29368. 'UniGB-UTF8-H',
  29369. 'UniGB-UTF8-V',
  29370. 'UniJIS-UCS2-H',
  29371. 'UniJIS-UCS2-HW-H',
  29372. 'UniJIS-UCS2-HW-V',
  29373. 'UniJIS-UCS2-V',
  29374. 'UniJIS-UTF16-H',
  29375. 'UniJIS-UTF16-V',
  29376. 'UniJIS-UTF32-H',
  29377. 'UniJIS-UTF32-V',
  29378. 'UniJIS-UTF8-H',
  29379. 'UniJIS-UTF8-V',
  29380. 'UniJIS2004-UTF16-H',
  29381. 'UniJIS2004-UTF16-V',
  29382. 'UniJIS2004-UTF32-H',
  29383. 'UniJIS2004-UTF32-V',
  29384. 'UniJIS2004-UTF8-H',
  29385. 'UniJIS2004-UTF8-V',
  29386. 'UniJISPro-UCS2-HW-V',
  29387. 'UniJISPro-UCS2-V',
  29388. 'UniJISPro-UTF8-V',
  29389. 'UniJISX0213-UTF32-H',
  29390. 'UniJISX0213-UTF32-V',
  29391. 'UniJISX02132004-UTF32-H',
  29392. 'UniJISX02132004-UTF32-V',
  29393. 'UniKS-UCS2-H',
  29394. 'UniKS-UCS2-V',
  29395. 'UniKS-UTF16-H',
  29396. 'UniKS-UTF16-V',
  29397. 'UniKS-UTF32-H',
  29398. 'UniKS-UTF32-V',
  29399. 'UniKS-UTF8-H',
  29400. 'UniKS-UTF8-V',
  29401. 'V',
  29402. 'WP-Symbol'];
  29403. // CMap, not to be confused with TrueType's cmap.
  29404. var CMap = (function CMapClosure() {
  29405. function CMap(builtInCMap) {
  29406. // Codespace ranges are stored as follows:
  29407. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  29408. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  29409. this.codespaceRanges = [[], [], [], []];
  29410. this.numCodespaceRanges = 0;
  29411. // Map entries have one of two forms.
  29412. // - cid chars are 16-bit unsigned integers, stored as integers.
  29413. // - bf chars are variable-length byte sequences, stored as strings, with
  29414. // one byte per character.
  29415. this._map = [];
  29416. this.name = '';
  29417. this.vertical = false;
  29418. this.useCMap = null;
  29419. this.builtInCMap = builtInCMap;
  29420. }
  29421. CMap.prototype = {
  29422. addCodespaceRange: function(n, low, high) {
  29423. this.codespaceRanges[n - 1].push(low, high);
  29424. this.numCodespaceRanges++;
  29425. },
  29426. mapCidRange: function(low, high, dstLow) {
  29427. while (low <= high) {
  29428. this._map[low++] = dstLow++;
  29429. }
  29430. },
  29431. mapBfRange: function(low, high, dstLow) {
  29432. var lastByte = dstLow.length - 1;
  29433. while (low <= high) {
  29434. this._map[low++] = dstLow;
  29435. // Only the last byte has to be incremented.
  29436. dstLow = dstLow.substr(0, lastByte) +
  29437. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  29438. }
  29439. },
  29440. mapBfRangeToArray: function(low, high, array) {
  29441. var i = 0, ii = array.length;
  29442. while (low <= high && i < ii) {
  29443. this._map[low] = array[i++];
  29444. ++low;
  29445. }
  29446. },
  29447. // This is used for both bf and cid chars.
  29448. mapOne: function(src, dst) {
  29449. this._map[src] = dst;
  29450. },
  29451. lookup: function(code) {
  29452. return this._map[code];
  29453. },
  29454. contains: function(code) {
  29455. return this._map[code] !== undefined;
  29456. },
  29457. forEach: function(callback) {
  29458. // Most maps have fewer than 65536 entries, and for those we use normal
  29459. // array iteration. But really sparse tables are possible -- e.g. with
  29460. // indices in the *billions*. For such tables we use for..in, which isn't
  29461. // ideal because it stringifies the indices for all present elements, but
  29462. // it does avoid iterating over every undefined entry.
  29463. var map = this._map;
  29464. var length = map.length;
  29465. var i;
  29466. if (length <= 0x10000) {
  29467. for (i = 0; i < length; i++) {
  29468. if (map[i] !== undefined) {
  29469. callback(i, map[i]);
  29470. }
  29471. }
  29472. } else {
  29473. for (i in this._map) {
  29474. callback(i, map[i]);
  29475. }
  29476. }
  29477. },
  29478. charCodeOf: function(value) {
  29479. return this._map.indexOf(value);
  29480. },
  29481. getMap: function() {
  29482. return this._map;
  29483. },
  29484. readCharCode: function(str, offset, out) {
  29485. var c = 0;
  29486. var codespaceRanges = this.codespaceRanges;
  29487. var codespaceRangesLen = this.codespaceRanges.length;
  29488. // 9.7.6.2 CMap Mapping
  29489. // The code length is at most 4.
  29490. for (var n = 0; n < codespaceRangesLen; n++) {
  29491. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  29492. // Check each codespace range to see if it falls within.
  29493. var codespaceRange = codespaceRanges[n];
  29494. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  29495. var low = codespaceRange[k++];
  29496. var high = codespaceRange[k++];
  29497. if (c >= low && c <= high) {
  29498. out.charcode = c;
  29499. out.length = n + 1;
  29500. return;
  29501. }
  29502. }
  29503. }
  29504. out.charcode = 0;
  29505. out.length = 1;
  29506. },
  29507. get length() {
  29508. return this._map.length;
  29509. },
  29510. get isIdentityCMap() {
  29511. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  29512. return false;
  29513. }
  29514. if (this._map.length !== 0x10000) {
  29515. return false;
  29516. }
  29517. for (var i = 0; i < 0x10000; i++) {
  29518. if (this._map[i] !== i) {
  29519. return false;
  29520. }
  29521. }
  29522. return true;
  29523. }
  29524. };
  29525. return CMap;
  29526. })();
  29527. // A special case of CMap, where the _map array implicitly has a length of
  29528. // 65536 and each element is equal to its index.
  29529. var IdentityCMap = (function IdentityCMapClosure() {
  29530. function IdentityCMap(vertical, n) {
  29531. CMap.call(this);
  29532. this.vertical = vertical;
  29533. this.addCodespaceRange(n, 0, 0xffff);
  29534. }
  29535. Util.inherit(IdentityCMap, CMap, {});
  29536. IdentityCMap.prototype = {
  29537. addCodespaceRange: CMap.prototype.addCodespaceRange,
  29538. mapCidRange: function(low, high, dstLow) {
  29539. error('should not call mapCidRange');
  29540. },
  29541. mapBfRange: function(low, high, dstLow) {
  29542. error('should not call mapBfRange');
  29543. },
  29544. mapBfRangeToArray: function(low, high, array) {
  29545. error('should not call mapBfRangeToArray');
  29546. },
  29547. mapOne: function(src, dst) {
  29548. error('should not call mapCidOne');
  29549. },
  29550. lookup: function(code) {
  29551. return (isInt(code) && code <= 0xffff) ? code : undefined;
  29552. },
  29553. contains: function(code) {
  29554. return isInt(code) && code <= 0xffff;
  29555. },
  29556. forEach: function(callback) {
  29557. for (var i = 0; i <= 0xffff; i++) {
  29558. callback(i, i);
  29559. }
  29560. },
  29561. charCodeOf: function(value) {
  29562. return (isInt(value) && value <= 0xffff) ? value : -1;
  29563. },
  29564. getMap: function() {
  29565. // Sometimes identity maps must be instantiated, but it's rare.
  29566. var map = new Array(0x10000);
  29567. for (var i = 0; i <= 0xffff; i++) {
  29568. map[i] = i;
  29569. }
  29570. return map;
  29571. },
  29572. readCharCode: CMap.prototype.readCharCode,
  29573. get length() {
  29574. return 0x10000;
  29575. },
  29576. get isIdentityCMap() {
  29577. error('should not access .isIdentityCMap');
  29578. }
  29579. };
  29580. return IdentityCMap;
  29581. })();
  29582. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  29583. function fetchBinaryData(url) {
  29584. return new Promise(function (resolve, reject) {
  29585. var request = new XMLHttpRequest();
  29586. request.open('GET', url, true);
  29587. request.responseType = 'arraybuffer';
  29588. request.onreadystatechange = function () {
  29589. if (request.readyState === XMLHttpRequest.DONE) {
  29590. if (!request.response || request.status !== 200 &&
  29591. request.status !== 0) {
  29592. reject(new Error('Unable to get binary cMap at: ' + url));
  29593. } else {
  29594. resolve(new Uint8Array(request.response));
  29595. }
  29596. }
  29597. };
  29598. request.send(null);
  29599. });
  29600. }
  29601. function hexToInt(a, size) {
  29602. var n = 0;
  29603. for (var i = 0; i <= size; i++) {
  29604. n = (n << 8) | a[i];
  29605. }
  29606. return n >>> 0;
  29607. }
  29608. function hexToStr(a, size) {
  29609. // This code is hot. Special-case some common values to avoid creating an
  29610. // object with subarray().
  29611. if (size === 1) {
  29612. return String.fromCharCode(a[0], a[1]);
  29613. }
  29614. if (size === 3) {
  29615. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29616. }
  29617. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29618. }
  29619. function addHex(a, b, size) {
  29620. var c = 0;
  29621. for (var i = size; i >= 0; i--) {
  29622. c += a[i] + b[i];
  29623. a[i] = c & 255;
  29624. c >>= 8;
  29625. }
  29626. }
  29627. function incHex(a, size) {
  29628. var c = 1;
  29629. for (var i = size; i >= 0 && c > 0; i--) {
  29630. c += a[i];
  29631. a[i] = c & 255;
  29632. c >>= 8;
  29633. }
  29634. }
  29635. var MAX_NUM_SIZE = 16;
  29636. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29637. function BinaryCMapStream(data) {
  29638. this.buffer = data;
  29639. this.pos = 0;
  29640. this.end = data.length;
  29641. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29642. }
  29643. BinaryCMapStream.prototype = {
  29644. readByte: function () {
  29645. if (this.pos >= this.end) {
  29646. return -1;
  29647. }
  29648. return this.buffer[this.pos++];
  29649. },
  29650. readNumber: function () {
  29651. var n = 0;
  29652. var last;
  29653. do {
  29654. var b = this.readByte();
  29655. if (b < 0) {
  29656. error('unexpected EOF in bcmap');
  29657. }
  29658. last = !(b & 0x80);
  29659. n = (n << 7) | (b & 0x7F);
  29660. } while (!last);
  29661. return n;
  29662. },
  29663. readSigned: function () {
  29664. var n = this.readNumber();
  29665. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29666. },
  29667. readHex: function (num, size) {
  29668. num.set(this.buffer.subarray(this.pos,
  29669. this.pos + size + 1));
  29670. this.pos += size + 1;
  29671. },
  29672. readHexNumber: function (num, size) {
  29673. var last;
  29674. var stack = this.tmpBuf, sp = 0;
  29675. do {
  29676. var b = this.readByte();
  29677. if (b < 0) {
  29678. error('unexpected EOF in bcmap');
  29679. }
  29680. last = !(b & 0x80);
  29681. stack[sp++] = b & 0x7F;
  29682. } while (!last);
  29683. var i = size, buffer = 0, bufferSize = 0;
  29684. while (i >= 0) {
  29685. while (bufferSize < 8 && stack.length > 0) {
  29686. buffer = (stack[--sp] << bufferSize) | buffer;
  29687. bufferSize += 7;
  29688. }
  29689. num[i] = buffer & 255;
  29690. i--;
  29691. buffer >>= 8;
  29692. bufferSize -= 8;
  29693. }
  29694. },
  29695. readHexSigned: function (num, size) {
  29696. this.readHexNumber(num, size);
  29697. var sign = num[size] & 1 ? 255 : 0;
  29698. var c = 0;
  29699. for (var i = 0; i <= size; i++) {
  29700. c = ((c & 1) << 8) | num[i];
  29701. num[i] = (c >> 1) ^ sign;
  29702. }
  29703. },
  29704. readString: function () {
  29705. var len = this.readNumber();
  29706. var s = '';
  29707. for (var i = 0; i < len; i++) {
  29708. s += String.fromCharCode(this.readNumber());
  29709. }
  29710. return s;
  29711. }
  29712. };
  29713. function processBinaryCMap(url, cMap, extend) {
  29714. return fetchBinaryData(url).then(function (data) {
  29715. var stream = new BinaryCMapStream(data);
  29716. var header = stream.readByte();
  29717. cMap.vertical = !!(header & 1);
  29718. var useCMap = null;
  29719. var start = new Uint8Array(MAX_NUM_SIZE);
  29720. var end = new Uint8Array(MAX_NUM_SIZE);
  29721. var char = new Uint8Array(MAX_NUM_SIZE);
  29722. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29723. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29724. var code;
  29725. var b;
  29726. while ((b = stream.readByte()) >= 0) {
  29727. var type = b >> 5;
  29728. if (type === 7) { // metadata, e.g. comment or usecmap
  29729. switch (b & 0x1F) {
  29730. case 0:
  29731. stream.readString(); // skipping comment
  29732. break;
  29733. case 1:
  29734. useCMap = stream.readString();
  29735. break;
  29736. }
  29737. continue;
  29738. }
  29739. var sequence = !!(b & 0x10);
  29740. var dataSize = b & 15;
  29741. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29742. var ucs2DataSize = 1;
  29743. var subitemsCount = stream.readNumber();
  29744. var i;
  29745. switch (type) {
  29746. case 0: // codespacerange
  29747. stream.readHex(start, dataSize);
  29748. stream.readHexNumber(end, dataSize);
  29749. addHex(end, start, dataSize);
  29750. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29751. hexToInt(end, dataSize));
  29752. for (i = 1; i < subitemsCount; i++) {
  29753. incHex(end, dataSize);
  29754. stream.readHexNumber(start, dataSize);
  29755. addHex(start, end, dataSize);
  29756. stream.readHexNumber(end, dataSize);
  29757. addHex(end, start, dataSize);
  29758. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29759. hexToInt(end, dataSize));
  29760. }
  29761. break;
  29762. case 1: // notdefrange
  29763. stream.readHex(start, dataSize);
  29764. stream.readHexNumber(end, dataSize);
  29765. addHex(end, start, dataSize);
  29766. code = stream.readNumber();
  29767. // undefined range, skipping
  29768. for (i = 1; i < subitemsCount; i++) {
  29769. incHex(end, dataSize);
  29770. stream.readHexNumber(start, dataSize);
  29771. addHex(start, end, dataSize);
  29772. stream.readHexNumber(end, dataSize);
  29773. addHex(end, start, dataSize);
  29774. code = stream.readNumber();
  29775. // nop
  29776. }
  29777. break;
  29778. case 2: // cidchar
  29779. stream.readHex(char, dataSize);
  29780. code = stream.readNumber();
  29781. cMap.mapOne(hexToInt(char, dataSize), code);
  29782. for (i = 1; i < subitemsCount; i++) {
  29783. incHex(char, dataSize);
  29784. if (!sequence) {
  29785. stream.readHexNumber(tmp, dataSize);
  29786. addHex(char, tmp, dataSize);
  29787. }
  29788. code = stream.readSigned() + (code + 1);
  29789. cMap.mapOne(hexToInt(char, dataSize), code);
  29790. }
  29791. break;
  29792. case 3: // cidrange
  29793. stream.readHex(start, dataSize);
  29794. stream.readHexNumber(end, dataSize);
  29795. addHex(end, start, dataSize);
  29796. code = stream.readNumber();
  29797. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29798. code);
  29799. for (i = 1; i < subitemsCount; i++) {
  29800. incHex(end, dataSize);
  29801. if (!sequence) {
  29802. stream.readHexNumber(start, dataSize);
  29803. addHex(start, end, dataSize);
  29804. } else {
  29805. start.set(end);
  29806. }
  29807. stream.readHexNumber(end, dataSize);
  29808. addHex(end, start, dataSize);
  29809. code = stream.readNumber();
  29810. cMap.mapCidRange(hexToInt(start, dataSize),
  29811. hexToInt(end, dataSize), code);
  29812. }
  29813. break;
  29814. case 4: // bfchar
  29815. stream.readHex(char, ucs2DataSize);
  29816. stream.readHex(charCode, dataSize);
  29817. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29818. hexToStr(charCode, dataSize));
  29819. for (i = 1; i < subitemsCount; i++) {
  29820. incHex(char, ucs2DataSize);
  29821. if (!sequence) {
  29822. stream.readHexNumber(tmp, ucs2DataSize);
  29823. addHex(char, tmp, ucs2DataSize);
  29824. }
  29825. incHex(charCode, dataSize);
  29826. stream.readHexSigned(tmp, dataSize);
  29827. addHex(charCode, tmp, dataSize);
  29828. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29829. hexToStr(charCode, dataSize));
  29830. }
  29831. break;
  29832. case 5: // bfrange
  29833. stream.readHex(start, ucs2DataSize);
  29834. stream.readHexNumber(end, ucs2DataSize);
  29835. addHex(end, start, ucs2DataSize);
  29836. stream.readHex(charCode, dataSize);
  29837. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29838. hexToInt(end, ucs2DataSize),
  29839. hexToStr(charCode, dataSize));
  29840. for (i = 1; i < subitemsCount; i++) {
  29841. incHex(end, ucs2DataSize);
  29842. if (!sequence) {
  29843. stream.readHexNumber(start, ucs2DataSize);
  29844. addHex(start, end, ucs2DataSize);
  29845. } else {
  29846. start.set(end);
  29847. }
  29848. stream.readHexNumber(end, ucs2DataSize);
  29849. addHex(end, start, ucs2DataSize);
  29850. stream.readHex(charCode, dataSize);
  29851. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29852. hexToInt(end, ucs2DataSize),
  29853. hexToStr(charCode, dataSize));
  29854. }
  29855. break;
  29856. default:
  29857. error('Unknown type: ' + type);
  29858. break;
  29859. }
  29860. }
  29861. if (useCMap) {
  29862. return extend(useCMap);
  29863. }
  29864. return cMap;
  29865. });
  29866. }
  29867. function BinaryCMapReader() {}
  29868. BinaryCMapReader.prototype = {
  29869. read: processBinaryCMap
  29870. };
  29871. return BinaryCMapReader;
  29872. })();
  29873. var CMapFactory = (function CMapFactoryClosure() {
  29874. function strToInt(str) {
  29875. var a = 0;
  29876. for (var i = 0; i < str.length; i++) {
  29877. a = (a << 8) | str.charCodeAt(i);
  29878. }
  29879. return a >>> 0;
  29880. }
  29881. function expectString(obj) {
  29882. if (!isString(obj)) {
  29883. error('Malformed CMap: expected string.');
  29884. }
  29885. }
  29886. function expectInt(obj) {
  29887. if (!isInt(obj)) {
  29888. error('Malformed CMap: expected int.');
  29889. }
  29890. }
  29891. function parseBfChar(cMap, lexer) {
  29892. while (true) {
  29893. var obj = lexer.getObj();
  29894. if (isEOF(obj)) {
  29895. break;
  29896. }
  29897. if (isCmd(obj, 'endbfchar')) {
  29898. return;
  29899. }
  29900. expectString(obj);
  29901. var src = strToInt(obj);
  29902. obj = lexer.getObj();
  29903. // TODO are /dstName used?
  29904. expectString(obj);
  29905. var dst = obj;
  29906. cMap.mapOne(src, dst);
  29907. }
  29908. }
  29909. function parseBfRange(cMap, lexer) {
  29910. while (true) {
  29911. var obj = lexer.getObj();
  29912. if (isEOF(obj)) {
  29913. break;
  29914. }
  29915. if (isCmd(obj, 'endbfrange')) {
  29916. return;
  29917. }
  29918. expectString(obj);
  29919. var low = strToInt(obj);
  29920. obj = lexer.getObj();
  29921. expectString(obj);
  29922. var high = strToInt(obj);
  29923. obj = lexer.getObj();
  29924. if (isInt(obj) || isString(obj)) {
  29925. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  29926. cMap.mapBfRange(low, high, dstLow);
  29927. } else if (isCmd(obj, '[')) {
  29928. obj = lexer.getObj();
  29929. var array = [];
  29930. while (!isCmd(obj, ']') && !isEOF(obj)) {
  29931. array.push(obj);
  29932. obj = lexer.getObj();
  29933. }
  29934. cMap.mapBfRangeToArray(low, high, array);
  29935. } else {
  29936. break;
  29937. }
  29938. }
  29939. error('Invalid bf range.');
  29940. }
  29941. function parseCidChar(cMap, lexer) {
  29942. while (true) {
  29943. var obj = lexer.getObj();
  29944. if (isEOF(obj)) {
  29945. break;
  29946. }
  29947. if (isCmd(obj, 'endcidchar')) {
  29948. return;
  29949. }
  29950. expectString(obj);
  29951. var src = strToInt(obj);
  29952. obj = lexer.getObj();
  29953. expectInt(obj);
  29954. var dst = obj;
  29955. cMap.mapOne(src, dst);
  29956. }
  29957. }
  29958. function parseCidRange(cMap, lexer) {
  29959. while (true) {
  29960. var obj = lexer.getObj();
  29961. if (isEOF(obj)) {
  29962. break;
  29963. }
  29964. if (isCmd(obj, 'endcidrange')) {
  29965. return;
  29966. }
  29967. expectString(obj);
  29968. var low = strToInt(obj);
  29969. obj = lexer.getObj();
  29970. expectString(obj);
  29971. var high = strToInt(obj);
  29972. obj = lexer.getObj();
  29973. expectInt(obj);
  29974. var dstLow = obj;
  29975. cMap.mapCidRange(low, high, dstLow);
  29976. }
  29977. }
  29978. function parseCodespaceRange(cMap, lexer) {
  29979. while (true) {
  29980. var obj = lexer.getObj();
  29981. if (isEOF(obj)) {
  29982. break;
  29983. }
  29984. if (isCmd(obj, 'endcodespacerange')) {
  29985. return;
  29986. }
  29987. if (!isString(obj)) {
  29988. break;
  29989. }
  29990. var low = strToInt(obj);
  29991. obj = lexer.getObj();
  29992. if (!isString(obj)) {
  29993. break;
  29994. }
  29995. var high = strToInt(obj);
  29996. cMap.addCodespaceRange(obj.length, low, high);
  29997. }
  29998. error('Invalid codespace range.');
  29999. }
  30000. function parseWMode(cMap, lexer) {
  30001. var obj = lexer.getObj();
  30002. if (isInt(obj)) {
  30003. cMap.vertical = !!obj;
  30004. }
  30005. }
  30006. function parseCMapName(cMap, lexer) {
  30007. var obj = lexer.getObj();
  30008. if (isName(obj) && isString(obj.name)) {
  30009. cMap.name = obj.name;
  30010. }
  30011. }
  30012. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  30013. var previous;
  30014. var embededUseCMap;
  30015. objLoop: while (true) {
  30016. try {
  30017. var obj = lexer.getObj();
  30018. if (isEOF(obj)) {
  30019. break;
  30020. } else if (isName(obj)) {
  30021. if (obj.name === 'WMode') {
  30022. parseWMode(cMap, lexer);
  30023. } else if (obj.name === 'CMapName') {
  30024. parseCMapName(cMap, lexer);
  30025. }
  30026. previous = obj;
  30027. } else if (isCmd(obj)) {
  30028. switch (obj.cmd) {
  30029. case 'endcmap':
  30030. break objLoop;
  30031. case 'usecmap':
  30032. if (isName(previous)) {
  30033. embededUseCMap = previous.name;
  30034. }
  30035. break;
  30036. case 'begincodespacerange':
  30037. parseCodespaceRange(cMap, lexer);
  30038. break;
  30039. case 'beginbfchar':
  30040. parseBfChar(cMap, lexer);
  30041. break;
  30042. case 'begincidchar':
  30043. parseCidChar(cMap, lexer);
  30044. break;
  30045. case 'beginbfrange':
  30046. parseBfRange(cMap, lexer);
  30047. break;
  30048. case 'begincidrange':
  30049. parseCidRange(cMap, lexer);
  30050. break;
  30051. }
  30052. }
  30053. } catch (ex) {
  30054. if (ex instanceof MissingDataException) {
  30055. throw ex;
  30056. }
  30057. warn('Invalid cMap data: ' + ex);
  30058. continue;
  30059. }
  30060. }
  30061. if (!useCMap && embededUseCMap) {
  30062. // Load the usecmap definition from the file only if there wasn't one
  30063. // specified.
  30064. useCMap = embededUseCMap;
  30065. }
  30066. if (useCMap) {
  30067. return extendCMap(cMap, builtInCMapParams, useCMap);
  30068. }
  30069. return Promise.resolve(cMap);
  30070. }
  30071. function extendCMap(cMap, builtInCMapParams, useCMap) {
  30072. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  30073. function(newCMap) {
  30074. cMap.useCMap = newCMap;
  30075. // If there aren't any code space ranges defined clone all the parent ones
  30076. // into this cMap.
  30077. if (cMap.numCodespaceRanges === 0) {
  30078. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  30079. for (var i = 0; i < useCodespaceRanges.length; i++) {
  30080. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  30081. }
  30082. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  30083. }
  30084. // Merge the map into the current one, making sure not to override
  30085. // any previously defined entries.
  30086. cMap.useCMap.forEach(function(key, value) {
  30087. if (!cMap.contains(key)) {
  30088. cMap.mapOne(key, cMap.useCMap.lookup(key));
  30089. }
  30090. });
  30091. return cMap;
  30092. });
  30093. }
  30094. function parseBinaryCMap(name, builtInCMapParams) {
  30095. var url = builtInCMapParams.url + name + '.bcmap';
  30096. var cMap = new CMap(true);
  30097. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  30098. return extendCMap(cMap, builtInCMapParams, useCMap);
  30099. });
  30100. }
  30101. function createBuiltInCMap(name, builtInCMapParams) {
  30102. if (name === 'Identity-H') {
  30103. return Promise.resolve(new IdentityCMap(false, 2));
  30104. } else if (name === 'Identity-V') {
  30105. return Promise.resolve(new IdentityCMap(true, 2));
  30106. }
  30107. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  30108. return Promise.reject(new Error('Unknown cMap name: ' + name));
  30109. }
  30110. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  30111. if (builtInCMapParams.packed) {
  30112. return parseBinaryCMap(name, builtInCMapParams);
  30113. }
  30114. return new Promise(function (resolve, reject) {
  30115. var url = builtInCMapParams.url + name;
  30116. var request = new XMLHttpRequest();
  30117. request.onreadystatechange = function () {
  30118. if (request.readyState === XMLHttpRequest.DONE) {
  30119. if (request.status === 200 || request.status === 0) {
  30120. var cMap = new CMap(true);
  30121. var lexer = new Lexer(new StringStream(request.responseText));
  30122. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  30123. function (parsedCMap) {
  30124. resolve(parsedCMap);
  30125. });
  30126. } else {
  30127. reject(new Error('Unable to get cMap at: ' + url));
  30128. }
  30129. }
  30130. };
  30131. request.open('GET', url, true);
  30132. request.send(null);
  30133. });
  30134. }
  30135. return {
  30136. create: function (encoding, builtInCMapParams, useCMap) {
  30137. if (isName(encoding)) {
  30138. return createBuiltInCMap(encoding.name, builtInCMapParams);
  30139. } else if (isStream(encoding)) {
  30140. var cMap = new CMap();
  30141. var lexer = new Lexer(encoding);
  30142. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  30143. function (parsedCMap) {
  30144. if (parsedCMap.isIdentityCMap) {
  30145. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  30146. }
  30147. return parsedCMap;
  30148. });
  30149. }
  30150. return Promise.reject(new Error('Encoding required.'));
  30151. }
  30152. };
  30153. })();
  30154. exports.CMap = CMap;
  30155. exports.CMapFactory = CMapFactory;
  30156. exports.IdentityCMap = IdentityCMap;
  30157. }));
  30158. (function (root, factory) {
  30159. {
  30160. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  30161. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  30162. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  30163. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  30164. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  30165. }
  30166. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  30167. coreGlyphList, coreFontRenderer, coreEncodings,
  30168. coreStandardFonts, coreUnicode, coreType1Parser,
  30169. coreCFFParser) {
  30170. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30171. var FontType = sharedUtil.FontType;
  30172. var assert = sharedUtil.assert;
  30173. var bytesToString = sharedUtil.bytesToString;
  30174. var error = sharedUtil.error;
  30175. var info = sharedUtil.info;
  30176. var isArray = sharedUtil.isArray;
  30177. var isInt = sharedUtil.isInt;
  30178. var isNum = sharedUtil.isNum;
  30179. var readUint32 = sharedUtil.readUint32;
  30180. var shadow = sharedUtil.shadow;
  30181. var string32 = sharedUtil.string32;
  30182. var warn = sharedUtil.warn;
  30183. var MissingDataException = sharedUtil.MissingDataException;
  30184. var isSpace = sharedUtil.isSpace;
  30185. var Stream = coreStream.Stream;
  30186. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  30187. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  30188. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30189. var StandardEncoding = coreEncodings.StandardEncoding;
  30190. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  30191. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  30192. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  30193. var getEncoding = coreEncodings.getEncoding;
  30194. var getStdFontMap = coreStandardFonts.getStdFontMap;
  30195. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  30196. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  30197. var getSupplementalGlyphMapForArialBlack =
  30198. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  30199. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  30200. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  30201. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  30202. var Type1Parser = coreType1Parser.Type1Parser;
  30203. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  30204. var CFFParser = coreCFFParser.CFFParser;
  30205. var CFFCompiler = coreCFFParser.CFFCompiler;
  30206. var CFF = coreCFFParser.CFF;
  30207. var CFFHeader = coreCFFParser.CFFHeader;
  30208. var CFFTopDict = coreCFFParser.CFFTopDict;
  30209. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  30210. var CFFStrings = coreCFFParser.CFFStrings;
  30211. var CFFIndex = coreCFFParser.CFFIndex;
  30212. var CFFCharset = coreCFFParser.CFFCharset;
  30213. // Unicode Private Use Area
  30214. var PRIVATE_USE_OFFSET_START = 0xE000;
  30215. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30216. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30217. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30218. // except for Type 3 fonts
  30219. var PDF_GLYPH_SPACE_UNITS = 1000;
  30220. // Accented charactars are not displayed properly on Windows, using this flag
  30221. // to control analysis of seac charstrings.
  30222. var SEAC_ANALYSIS_ENABLED = false;
  30223. var FontFlags = {
  30224. FixedPitch: 1,
  30225. Serif: 2,
  30226. Symbolic: 4,
  30227. Script: 8,
  30228. Nonsymbolic: 32,
  30229. Italic: 64,
  30230. AllCap: 65536,
  30231. SmallCap: 131072,
  30232. ForceBold: 262144
  30233. };
  30234. var MacStandardGlyphOrdering = [
  30235. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30236. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30237. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30238. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30239. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30240. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30241. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30242. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30243. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30244. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30245. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30246. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30247. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30248. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30249. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30250. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30251. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30252. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30253. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30254. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30255. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30256. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30257. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30258. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30259. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30260. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30261. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30262. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30263. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30264. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30265. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30266. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30267. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30268. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30269. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30270. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30271. function adjustWidths(properties) {
  30272. if (!properties.fontMatrix) {
  30273. return;
  30274. }
  30275. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  30276. return;
  30277. }
  30278. // adjusting width to fontMatrix scale
  30279. var scale = 0.001 / properties.fontMatrix[0];
  30280. var glyphsWidths = properties.widths;
  30281. for (var glyph in glyphsWidths) {
  30282. glyphsWidths[glyph] *= scale;
  30283. }
  30284. properties.defaultWidth *= scale;
  30285. }
  30286. function getFontType(type, subtype) {
  30287. switch (type) {
  30288. case 'Type1':
  30289. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  30290. case 'CIDFontType0':
  30291. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  30292. FontType.CIDFONTTYPE0;
  30293. case 'OpenType':
  30294. return FontType.OPENTYPE;
  30295. case 'TrueType':
  30296. return FontType.TRUETYPE;
  30297. case 'CIDFontType2':
  30298. return FontType.CIDFONTTYPE2;
  30299. case 'MMType1':
  30300. return FontType.MMTYPE1;
  30301. case 'Type0':
  30302. return FontType.TYPE0;
  30303. default:
  30304. return FontType.UNKNOWN;
  30305. }
  30306. }
  30307. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  30308. // in a 'uniXXXX' format -- attempting to recover proper ones.
  30309. function recoverGlyphName(name, glyphsUnicodeMap) {
  30310. if (glyphsUnicodeMap[name] !== undefined) {
  30311. return name;
  30312. }
  30313. // The glyph name is non-standard, trying to recover.
  30314. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  30315. if (unicode !== -1) {
  30316. for (var key in glyphsUnicodeMap) {
  30317. if (glyphsUnicodeMap[key] === unicode) {
  30318. return key;
  30319. }
  30320. }
  30321. }
  30322. info('Unable to recover a standard glyph name for: ' + name);
  30323. return name;
  30324. }
  30325. var Glyph = (function GlyphClosure() {
  30326. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  30327. isSpace, isInFont) {
  30328. this.fontChar = fontChar;
  30329. this.unicode = unicode;
  30330. this.accent = accent;
  30331. this.width = width;
  30332. this.vmetric = vmetric;
  30333. this.operatorListId = operatorListId;
  30334. this.isSpace = isSpace;
  30335. this.isInFont = isInFont;
  30336. }
  30337. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  30338. vmetric, operatorListId, isSpace,
  30339. isInFont) {
  30340. return this.fontChar === fontChar &&
  30341. this.unicode === unicode &&
  30342. this.accent === accent &&
  30343. this.width === width &&
  30344. this.vmetric === vmetric &&
  30345. this.operatorListId === operatorListId &&
  30346. this.isSpace === isSpace &&
  30347. this.isInFont === isInFont;
  30348. };
  30349. return Glyph;
  30350. })();
  30351. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  30352. function ToUnicodeMap(cmap) {
  30353. // The elements of this._map can be integers or strings, depending on how
  30354. // |cmap| was created.
  30355. this._map = cmap;
  30356. }
  30357. ToUnicodeMap.prototype = {
  30358. get length() {
  30359. return this._map.length;
  30360. },
  30361. forEach: function(callback) {
  30362. for (var charCode in this._map) {
  30363. callback(charCode, this._map[charCode].charCodeAt(0));
  30364. }
  30365. },
  30366. has: function(i) {
  30367. return this._map[i] !== undefined;
  30368. },
  30369. get: function(i) {
  30370. return this._map[i];
  30371. },
  30372. charCodeOf: function(v) {
  30373. return this._map.indexOf(v);
  30374. }
  30375. };
  30376. return ToUnicodeMap;
  30377. })();
  30378. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  30379. function IdentityToUnicodeMap(firstChar, lastChar) {
  30380. this.firstChar = firstChar;
  30381. this.lastChar = lastChar;
  30382. }
  30383. IdentityToUnicodeMap.prototype = {
  30384. get length() {
  30385. return (this.lastChar + 1) - this.firstChar;
  30386. },
  30387. forEach: function (callback) {
  30388. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  30389. callback(i, i);
  30390. }
  30391. },
  30392. has: function (i) {
  30393. return this.firstChar <= i && i <= this.lastChar;
  30394. },
  30395. get: function (i) {
  30396. if (this.firstChar <= i && i <= this.lastChar) {
  30397. return String.fromCharCode(i);
  30398. }
  30399. return undefined;
  30400. },
  30401. charCodeOf: function (v) {
  30402. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  30403. }
  30404. };
  30405. return IdentityToUnicodeMap;
  30406. })();
  30407. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  30408. function writeInt16(dest, offset, num) {
  30409. dest[offset] = (num >> 8) & 0xFF;
  30410. dest[offset + 1] = num & 0xFF;
  30411. }
  30412. function writeInt32(dest, offset, num) {
  30413. dest[offset] = (num >> 24) & 0xFF;
  30414. dest[offset + 1] = (num >> 16) & 0xFF;
  30415. dest[offset + 2] = (num >> 8) & 0xFF;
  30416. dest[offset + 3] = num & 0xFF;
  30417. }
  30418. function writeData(dest, offset, data) {
  30419. var i, ii;
  30420. if (data instanceof Uint8Array) {
  30421. dest.set(data, offset);
  30422. } else if (typeof data === 'string') {
  30423. for (i = 0, ii = data.length; i < ii; i++) {
  30424. dest[offset++] = data.charCodeAt(i) & 0xFF;
  30425. }
  30426. } else {
  30427. // treating everything else as array
  30428. for (i = 0, ii = data.length; i < ii; i++) {
  30429. dest[offset++] = data[i] & 0xFF;
  30430. }
  30431. }
  30432. }
  30433. function OpenTypeFileBuilder(sfnt) {
  30434. this.sfnt = sfnt;
  30435. this.tables = Object.create(null);
  30436. }
  30437. OpenTypeFileBuilder.getSearchParams =
  30438. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  30439. var maxPower2 = 1, log2 = 0;
  30440. while ((maxPower2 ^ entriesCount) > maxPower2) {
  30441. maxPower2 <<= 1;
  30442. log2++;
  30443. }
  30444. var searchRange = maxPower2 * entrySize;
  30445. return {
  30446. range: searchRange,
  30447. entry: log2,
  30448. rangeShift: entrySize * entriesCount - searchRange
  30449. };
  30450. };
  30451. var OTF_HEADER_SIZE = 12;
  30452. var OTF_TABLE_ENTRY_SIZE = 16;
  30453. OpenTypeFileBuilder.prototype = {
  30454. toArray: function OpenTypeFileBuilder_toArray() {
  30455. var sfnt = this.sfnt;
  30456. // Tables needs to be written by ascendant alphabetic order
  30457. var tables = this.tables;
  30458. var tablesNames = Object.keys(tables);
  30459. tablesNames.sort();
  30460. var numTables = tablesNames.length;
  30461. var i, j, jj, table, tableName;
  30462. // layout the tables data
  30463. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  30464. var tableOffsets = [offset];
  30465. for (i = 0; i < numTables; i++) {
  30466. table = tables[tablesNames[i]];
  30467. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  30468. offset += paddedLength;
  30469. tableOffsets.push(offset);
  30470. }
  30471. var file = new Uint8Array(offset);
  30472. // write the table data first (mostly for checksum)
  30473. for (i = 0; i < numTables; i++) {
  30474. table = tables[tablesNames[i]];
  30475. writeData(file, tableOffsets[i], table);
  30476. }
  30477. // sfnt version (4 bytes)
  30478. if (sfnt === 'true') {
  30479. // Windows hates the Mac TrueType sfnt version number
  30480. sfnt = string32(0x00010000);
  30481. }
  30482. file[0] = sfnt.charCodeAt(0) & 0xFF;
  30483. file[1] = sfnt.charCodeAt(1) & 0xFF;
  30484. file[2] = sfnt.charCodeAt(2) & 0xFF;
  30485. file[3] = sfnt.charCodeAt(3) & 0xFF;
  30486. // numTables (2 bytes)
  30487. writeInt16(file, 4, numTables);
  30488. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  30489. // searchRange (2 bytes)
  30490. writeInt16(file, 6, searchParams.range);
  30491. // entrySelector (2 bytes)
  30492. writeInt16(file, 8, searchParams.entry);
  30493. // rangeShift (2 bytes)
  30494. writeInt16(file, 10, searchParams.rangeShift);
  30495. offset = OTF_HEADER_SIZE;
  30496. // writing table entries
  30497. for (i = 0; i < numTables; i++) {
  30498. tableName = tablesNames[i];
  30499. file[offset] = tableName.charCodeAt(0) & 0xFF;
  30500. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  30501. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  30502. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  30503. // checksum
  30504. var checksum = 0;
  30505. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  30506. var quad = readUint32(file, j);
  30507. checksum = (checksum + quad) >>> 0;
  30508. }
  30509. writeInt32(file, offset + 4, checksum);
  30510. // offset
  30511. writeInt32(file, offset + 8, tableOffsets[i]);
  30512. // length
  30513. writeInt32(file, offset + 12, tables[tableName].length);
  30514. offset += OTF_TABLE_ENTRY_SIZE;
  30515. }
  30516. return file;
  30517. },
  30518. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  30519. if (tag in this.tables) {
  30520. throw new Error('Table ' + tag + ' already exists');
  30521. }
  30522. this.tables[tag] = data;
  30523. }
  30524. };
  30525. return OpenTypeFileBuilder;
  30526. })();
  30527. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  30528. // issues when they are painted on the canvas, e.g. complex-script shaping or
  30529. // control/whitespace characters. The ranges are listed in pairs: the first item
  30530. // is a code of the first problematic code, the second one is the next
  30531. // non-problematic code. The ranges must be in sorted order.
  30532. var ProblematicCharRanges = new Int32Array([
  30533. // Control characters.
  30534. 0x0000, 0x0020,
  30535. 0x007F, 0x00A1,
  30536. 0x00AD, 0x00AE,
  30537. // Chars that is used in complex-script shaping.
  30538. 0x0600, 0x0780,
  30539. 0x08A0, 0x10A0,
  30540. 0x1780, 0x1800,
  30541. 0x1C00, 0x1C50,
  30542. // General punctuation chars.
  30543. 0x2000, 0x2010,
  30544. 0x2011, 0x2012,
  30545. 0x2028, 0x2030,
  30546. 0x205F, 0x2070,
  30547. 0x25CC, 0x25CD,
  30548. 0x3000, 0x3001,
  30549. // Chars that is used in complex-script shaping.
  30550. 0xAA60, 0xAA80,
  30551. // Specials Unicode block.
  30552. 0xFFF0, 0x10000
  30553. ]);
  30554. /**
  30555. * 'Font' is the class the outside world should use, it encapsulate all the font
  30556. * decoding logics whatever type it is (assuming the font type is supported).
  30557. *
  30558. * For example to read a Type1 font and to attach it to the document:
  30559. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  30560. * type1Font.bind();
  30561. */
  30562. var Font = (function FontClosure() {
  30563. function Font(name, file, properties) {
  30564. var charCode, glyphName, unicode;
  30565. this.name = name;
  30566. this.loadedName = properties.loadedName;
  30567. this.isType3Font = properties.isType3Font;
  30568. this.sizes = [];
  30569. this.missingFile = false;
  30570. this.glyphCache = Object.create(null);
  30571. var names = name.split('+');
  30572. names = names.length > 1 ? names[1] : names[0];
  30573. names = names.split(/[-,_]/g)[0];
  30574. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  30575. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  30576. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  30577. var type = properties.type;
  30578. var subtype = properties.subtype;
  30579. this.type = type;
  30580. this.fallbackName = (this.isMonospace ? 'monospace' :
  30581. (this.isSerifFont ? 'serif' : 'sans-serif'));
  30582. this.differences = properties.differences;
  30583. this.widths = properties.widths;
  30584. this.defaultWidth = properties.defaultWidth;
  30585. this.composite = properties.composite;
  30586. this.wideChars = properties.wideChars;
  30587. this.cMap = properties.cMap;
  30588. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  30589. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  30590. this.fontMatrix = properties.fontMatrix;
  30591. this.bbox = properties.bbox;
  30592. this.toUnicode = properties.toUnicode;
  30593. this.toFontChar = [];
  30594. if (properties.type === 'Type3') {
  30595. for (charCode = 0; charCode < 256; charCode++) {
  30596. this.toFontChar[charCode] = (this.differences[charCode] ||
  30597. properties.defaultEncoding[charCode]);
  30598. }
  30599. this.fontType = FontType.TYPE3;
  30600. return;
  30601. }
  30602. this.cidEncoding = properties.cidEncoding;
  30603. this.vertical = properties.vertical;
  30604. if (this.vertical) {
  30605. this.vmetrics = properties.vmetrics;
  30606. this.defaultVMetrics = properties.defaultVMetrics;
  30607. }
  30608. var glyphsUnicodeMap;
  30609. if (!file || file.isEmpty) {
  30610. if (file) {
  30611. // Some bad PDF generators will include empty font files,
  30612. // attempting to recover by assuming that no file exists.
  30613. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  30614. }
  30615. this.missingFile = true;
  30616. // The file data is not specified. Trying to fix the font name
  30617. // to be used with the canvas.font.
  30618. var fontName = name.replace(/[,_]/g, '-');
  30619. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  30620. var isStandardFont = !!stdFontMap[fontName] ||
  30621. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  30622. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  30623. this.bold = (fontName.search(/bold/gi) !== -1);
  30624. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  30625. (fontName.search(/italic/gi) !== -1));
  30626. // Use 'name' instead of 'fontName' here because the original
  30627. // name ArialBlack for example will be replaced by Helvetica.
  30628. this.black = (name.search(/Black/g) !== -1);
  30629. // if at least one width is present, remeasure all chars when exists
  30630. this.remeasure = Object.keys(this.widths).length > 0;
  30631. if (isStandardFont && type === 'CIDFontType2' &&
  30632. properties.cidEncoding.indexOf('Identity-') === 0) {
  30633. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  30634. // Standard fonts might be embedded as CID font without glyph mapping.
  30635. // Building one based on GlyphMapForStandardFonts.
  30636. var map = [];
  30637. for (charCode in GlyphMapForStandardFonts) {
  30638. map[+charCode] = GlyphMapForStandardFonts[charCode];
  30639. }
  30640. if (/ArialBlack/i.test(name)) {
  30641. var SupplementalGlyphMapForArialBlack =
  30642. getSupplementalGlyphMapForArialBlack();
  30643. for (charCode in SupplementalGlyphMapForArialBlack) {
  30644. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  30645. }
  30646. }
  30647. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  30648. if (!isIdentityUnicode) {
  30649. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30650. map[+charCode] = unicodeCharCode;
  30651. });
  30652. }
  30653. this.toFontChar = map;
  30654. this.toUnicode = new ToUnicodeMap(map);
  30655. } else if (/Symbol/i.test(fontName)) {
  30656. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  30657. properties.differences);
  30658. } else if (/Dingbats/i.test(fontName)) {
  30659. if (/Wingdings/i.test(name)) {
  30660. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  30661. }
  30662. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  30663. getDingbatsGlyphsUnicode(),
  30664. properties.differences);
  30665. } else if (isStandardFont) {
  30666. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  30667. getGlyphsUnicode(),
  30668. properties.differences);
  30669. } else {
  30670. glyphsUnicodeMap = getGlyphsUnicode();
  30671. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30672. if (!this.composite) {
  30673. glyphName = (properties.differences[charCode] ||
  30674. properties.defaultEncoding[charCode]);
  30675. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  30676. if (unicode !== -1) {
  30677. unicodeCharCode = unicode;
  30678. }
  30679. }
  30680. this.toFontChar[charCode] = unicodeCharCode;
  30681. }.bind(this));
  30682. }
  30683. this.loadedName = fontName.split('-')[0];
  30684. this.loading = false;
  30685. this.fontType = getFontType(type, subtype);
  30686. return;
  30687. }
  30688. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  30689. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  30690. // Some TrueType fonts by mistake claim Type1C
  30691. if (isTrueTypeFile(file)) {
  30692. subtype = 'TrueType';
  30693. } else {
  30694. type = 'Type1';
  30695. }
  30696. }
  30697. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  30698. type = 'CIDFontType0';
  30699. }
  30700. if (subtype === 'OpenType') {
  30701. type = 'OpenType';
  30702. }
  30703. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  30704. if (type === 'CIDFontType0') {
  30705. if (isType1File(file)) {
  30706. subtype = 'CIDFontType0';
  30707. } else if (isOpenTypeFile(file)) {
  30708. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  30709. type = subtype = 'OpenType';
  30710. } else {
  30711. subtype = 'CIDFontType0C';
  30712. }
  30713. }
  30714. var data;
  30715. switch (type) {
  30716. case 'MMType1':
  30717. info('MMType1 font (' + name + '), falling back to Type1.');
  30718. /* falls through */
  30719. case 'Type1':
  30720. case 'CIDFontType0':
  30721. this.mimetype = 'font/opentype';
  30722. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  30723. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  30724. adjustWidths(properties);
  30725. // Wrap the CFF data inside an OTF font file
  30726. data = this.convert(name, cff, properties);
  30727. break;
  30728. case 'OpenType':
  30729. case 'TrueType':
  30730. case 'CIDFontType2':
  30731. this.mimetype = 'font/opentype';
  30732. // Repair the TrueType file. It is can be damaged in the point of
  30733. // view of the sanitizer
  30734. data = this.checkAndRepair(name, file, properties);
  30735. if (this.isOpenType) {
  30736. adjustWidths(properties);
  30737. type = 'OpenType';
  30738. }
  30739. break;
  30740. default:
  30741. error('Font ' + type + ' is not supported');
  30742. break;
  30743. }
  30744. this.data = data;
  30745. this.fontType = getFontType(type, subtype);
  30746. // Transfer some properties again that could change during font conversion
  30747. this.fontMatrix = properties.fontMatrix;
  30748. this.widths = properties.widths;
  30749. this.defaultWidth = properties.defaultWidth;
  30750. this.encoding = properties.baseEncoding;
  30751. this.seacMap = properties.seacMap;
  30752. this.loading = true;
  30753. }
  30754. Font.getFontID = (function () {
  30755. var ID = 1;
  30756. return function Font_getFontID() {
  30757. return String(ID++);
  30758. };
  30759. })();
  30760. function int16(b0, b1) {
  30761. return (b0 << 8) + b1;
  30762. }
  30763. function signedInt16(b0, b1) {
  30764. var value = (b0 << 8) + b1;
  30765. return value & (1 << 15) ? value - 0x10000 : value;
  30766. }
  30767. function int32(b0, b1, b2, b3) {
  30768. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30769. }
  30770. function string16(value) {
  30771. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  30772. }
  30773. function safeString16(value) {
  30774. // clamp value to the 16-bit int range
  30775. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  30776. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  30777. }
  30778. function isTrueTypeFile(file) {
  30779. var header = file.peekBytes(4);
  30780. return readUint32(header, 0) === 0x00010000;
  30781. }
  30782. function isOpenTypeFile(file) {
  30783. var header = file.peekBytes(4);
  30784. return bytesToString(header) === 'OTTO';
  30785. }
  30786. function isType1File(file) {
  30787. var header = file.peekBytes(2);
  30788. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  30789. if (header[0] === 0x25 && header[1] === 0x21) {
  30790. return true;
  30791. }
  30792. // ... obviously some fonts violate that part of the specification,
  30793. // please refer to the comment in |Type1Font| below.
  30794. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  30795. return true;
  30796. }
  30797. return false;
  30798. }
  30799. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  30800. var toFontChar = [], unicode;
  30801. for (var i = 0, ii = encoding.length; i < ii; i++) {
  30802. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  30803. if (unicode !== -1) {
  30804. toFontChar[i] = unicode;
  30805. }
  30806. }
  30807. for (var charCode in differences) {
  30808. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  30809. if (unicode !== -1) {
  30810. toFontChar[+charCode] = unicode;
  30811. }
  30812. }
  30813. return toFontChar;
  30814. }
  30815. /**
  30816. * Helper function for |adjustMapping|.
  30817. * @return {boolean}
  30818. */
  30819. function isProblematicUnicodeLocation(code) {
  30820. // Using binary search to find a range start.
  30821. var i = 0, j = ProblematicCharRanges.length - 1;
  30822. while (i < j) {
  30823. var c = (i + j + 1) >> 1;
  30824. if (code < ProblematicCharRanges[c]) {
  30825. j = c - 1;
  30826. } else {
  30827. i = c;
  30828. }
  30829. }
  30830. // Even index means code in problematic range.
  30831. return !(i & 1);
  30832. }
  30833. /**
  30834. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  30835. * with their unicode value. It also moves char codes that are in known
  30836. * problematic locations.
  30837. * @return {Object} Two properties:
  30838. * 'toFontChar' - maps original char codes(the value that will be read
  30839. * from commands such as show text) to the char codes that will be used in the
  30840. * font that we build
  30841. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  30842. */
  30843. function adjustMapping(charCodeToGlyphId, properties) {
  30844. var toUnicode = properties.toUnicode;
  30845. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  30846. var isIdentityUnicode =
  30847. properties.toUnicode instanceof IdentityToUnicodeMap;
  30848. var newMap = Object.create(null);
  30849. var toFontChar = [];
  30850. var usedFontCharCodes = [];
  30851. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  30852. for (var originalCharCode in charCodeToGlyphId) {
  30853. originalCharCode |= 0;
  30854. var glyphId = charCodeToGlyphId[originalCharCode];
  30855. var fontCharCode = originalCharCode;
  30856. // First try to map the value to a unicode position if a non identity map
  30857. // was created.
  30858. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  30859. var unicode = toUnicode.get(fontCharCode);
  30860. // TODO: Try to map ligatures to the correct spot.
  30861. if (unicode.length === 1) {
  30862. fontCharCode = unicode.charCodeAt(0);
  30863. }
  30864. }
  30865. // Try to move control characters, special characters and already mapped
  30866. // characters to the private use area since they will not be drawn by
  30867. // canvas if left in their current position. Also, move characters if the
  30868. // font was symbolic and there is only an identity unicode map since the
  30869. // characters probably aren't in the correct position (fixes an issue
  30870. // with firefox and thuluthfont).
  30871. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  30872. isProblematicUnicodeLocation(fontCharCode) ||
  30873. (isSymbolic && isIdentityUnicode)) &&
  30874. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  30875. // Loop to try and find a free spot in the private use area.
  30876. do {
  30877. fontCharCode = nextAvailableFontCharCode++;
  30878. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  30879. fontCharCode = 0xF020;
  30880. nextAvailableFontCharCode = fontCharCode + 1;
  30881. }
  30882. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  30883. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  30884. }
  30885. newMap[fontCharCode] = glyphId;
  30886. toFontChar[originalCharCode] = fontCharCode;
  30887. usedFontCharCodes[fontCharCode] = true;
  30888. }
  30889. return {
  30890. toFontChar: toFontChar,
  30891. charCodeToGlyphId: newMap,
  30892. nextAvailableFontCharCode: nextAvailableFontCharCode
  30893. };
  30894. }
  30895. function getRanges(glyphs, numGlyphs) {
  30896. // Array.sort() sorts by characters, not numerically, so convert to an
  30897. // array of characters.
  30898. var codes = [];
  30899. for (var charCode in glyphs) {
  30900. // Remove an invalid glyph ID mappings to make OTS happy.
  30901. if (glyphs[charCode] >= numGlyphs) {
  30902. continue;
  30903. }
  30904. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  30905. }
  30906. codes.sort(function fontGetRangesSort(a, b) {
  30907. return a.fontCharCode - b.fontCharCode;
  30908. });
  30909. // Split the sorted codes into ranges.
  30910. var ranges = [];
  30911. var length = codes.length;
  30912. for (var n = 0; n < length; ) {
  30913. var start = codes[n].fontCharCode;
  30914. var codeIndices = [codes[n].glyphId];
  30915. ++n;
  30916. var end = start;
  30917. while (n < length && end + 1 === codes[n].fontCharCode) {
  30918. codeIndices.push(codes[n].glyphId);
  30919. ++end;
  30920. ++n;
  30921. if (end === 0xFFFF) {
  30922. break;
  30923. }
  30924. }
  30925. ranges.push([start, end, codeIndices]);
  30926. }
  30927. return ranges;
  30928. }
  30929. function createCmapTable(glyphs, numGlyphs) {
  30930. var ranges = getRanges(glyphs, numGlyphs);
  30931. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  30932. var cmap = '\x00\x00' + // version
  30933. string16(numTables) + // numTables
  30934. '\x00\x03' + // platformID
  30935. '\x00\x01' + // encodingID
  30936. string32(4 + numTables * 8); // start of the table record
  30937. var i, ii, j, jj;
  30938. for (i = ranges.length - 1; i >= 0; --i) {
  30939. if (ranges[i][0] <= 0xFFFF) { break; }
  30940. }
  30941. var bmpLength = i + 1;
  30942. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  30943. ranges[i][1] = 0xFFFE;
  30944. }
  30945. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  30946. var segCount = bmpLength + trailingRangesCount;
  30947. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  30948. // Fill up the 4 parallel arrays describing the segments.
  30949. var startCount = '';
  30950. var endCount = '';
  30951. var idDeltas = '';
  30952. var idRangeOffsets = '';
  30953. var glyphsIds = '';
  30954. var bias = 0;
  30955. var range, start, end, codes;
  30956. for (i = 0, ii = bmpLength; i < ii; i++) {
  30957. range = ranges[i];
  30958. start = range[0];
  30959. end = range[1];
  30960. startCount += string16(start);
  30961. endCount += string16(end);
  30962. codes = range[2];
  30963. var contiguous = true;
  30964. for (j = 1, jj = codes.length; j < jj; ++j) {
  30965. if (codes[j] !== codes[j - 1] + 1) {
  30966. contiguous = false;
  30967. break;
  30968. }
  30969. }
  30970. if (!contiguous) {
  30971. var offset = (segCount - i) * 2 + bias * 2;
  30972. bias += (end - start + 1);
  30973. idDeltas += string16(0);
  30974. idRangeOffsets += string16(offset);
  30975. for (j = 0, jj = codes.length; j < jj; ++j) {
  30976. glyphsIds += string16(codes[j]);
  30977. }
  30978. } else {
  30979. var startCode = codes[0];
  30980. idDeltas += string16((startCode - start) & 0xFFFF);
  30981. idRangeOffsets += string16(0);
  30982. }
  30983. }
  30984. if (trailingRangesCount > 0) {
  30985. endCount += '\xFF\xFF';
  30986. startCount += '\xFF\xFF';
  30987. idDeltas += '\x00\x01';
  30988. idRangeOffsets += '\x00\x00';
  30989. }
  30990. var format314 = '\x00\x00' + // language
  30991. string16(2 * segCount) +
  30992. string16(searchParams.range) +
  30993. string16(searchParams.entry) +
  30994. string16(searchParams.rangeShift) +
  30995. endCount + '\x00\x00' + startCount +
  30996. idDeltas + idRangeOffsets + glyphsIds;
  30997. var format31012 = '';
  30998. var header31012 = '';
  30999. if (numTables > 1) {
  31000. cmap += '\x00\x03' + // platformID
  31001. '\x00\x0A' + // encodingID
  31002. string32(4 + numTables * 8 +
  31003. 4 + format314.length); // start of the table record
  31004. format31012 = '';
  31005. for (i = 0, ii = ranges.length; i < ii; i++) {
  31006. range = ranges[i];
  31007. start = range[0];
  31008. codes = range[2];
  31009. var code = codes[0];
  31010. for (j = 1, jj = codes.length; j < jj; ++j) {
  31011. if (codes[j] !== codes[j - 1] + 1) {
  31012. end = range[0] + j - 1;
  31013. format31012 += string32(start) + // startCharCode
  31014. string32(end) + // endCharCode
  31015. string32(code); // startGlyphID
  31016. start = end + 1;
  31017. code = codes[j];
  31018. }
  31019. }
  31020. format31012 += string32(start) + // startCharCode
  31021. string32(range[1]) + // endCharCode
  31022. string32(code); // startGlyphID
  31023. }
  31024. header31012 = '\x00\x0C' + // format
  31025. '\x00\x00' + // reserved
  31026. string32(format31012.length + 16) + // length
  31027. '\x00\x00\x00\x00' + // language
  31028. string32(format31012.length / 12); // nGroups
  31029. }
  31030. return cmap + '\x00\x04' + // format
  31031. string16(format314.length + 4) + // length
  31032. format314 + header31012 + format31012;
  31033. }
  31034. function validateOS2Table(os2) {
  31035. var stream = new Stream(os2.data);
  31036. var version = stream.getUint16();
  31037. // TODO verify all OS/2 tables fields, but currently we validate only those
  31038. // that give us issues
  31039. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  31040. var selection = stream.getUint16();
  31041. if (version < 4 && (selection & 0x0300)) {
  31042. return false;
  31043. }
  31044. var firstChar = stream.getUint16();
  31045. var lastChar = stream.getUint16();
  31046. if (firstChar > lastChar) {
  31047. return false;
  31048. }
  31049. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  31050. var usWinAscent = stream.getUint16();
  31051. if (usWinAscent === 0) { // makes font unreadable by windows
  31052. return false;
  31053. }
  31054. // OS/2 appears to be valid, resetting some fields
  31055. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  31056. return true;
  31057. }
  31058. function createOS2Table(properties, charstrings, override) {
  31059. override = override || {
  31060. unitsPerEm: 0,
  31061. yMax: 0,
  31062. yMin: 0,
  31063. ascent: 0,
  31064. descent: 0
  31065. };
  31066. var ulUnicodeRange1 = 0;
  31067. var ulUnicodeRange2 = 0;
  31068. var ulUnicodeRange3 = 0;
  31069. var ulUnicodeRange4 = 0;
  31070. var firstCharIndex = null;
  31071. var lastCharIndex = 0;
  31072. if (charstrings) {
  31073. for (var code in charstrings) {
  31074. code |= 0;
  31075. if (firstCharIndex > code || !firstCharIndex) {
  31076. firstCharIndex = code;
  31077. }
  31078. if (lastCharIndex < code) {
  31079. lastCharIndex = code;
  31080. }
  31081. var position = getUnicodeRangeFor(code);
  31082. if (position < 32) {
  31083. ulUnicodeRange1 |= 1 << position;
  31084. } else if (position < 64) {
  31085. ulUnicodeRange2 |= 1 << position - 32;
  31086. } else if (position < 96) {
  31087. ulUnicodeRange3 |= 1 << position - 64;
  31088. } else if (position < 123) {
  31089. ulUnicodeRange4 |= 1 << position - 96;
  31090. } else {
  31091. error('Unicode ranges Bits > 123 are reserved for internal usage');
  31092. }
  31093. }
  31094. } else {
  31095. // TODO
  31096. firstCharIndex = 0;
  31097. lastCharIndex = 255;
  31098. }
  31099. var bbox = properties.bbox || [0, 0, 0, 0];
  31100. var unitsPerEm = (override.unitsPerEm ||
  31101. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  31102. // if the font units differ to the PDF glyph space units
  31103. // then scale up the values
  31104. var scale = (properties.ascentScaled ? 1.0 :
  31105. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  31106. var typoAscent = (override.ascent ||
  31107. Math.round(scale * (properties.ascent || bbox[3])));
  31108. var typoDescent = (override.descent ||
  31109. Math.round(scale * (properties.descent || bbox[1])));
  31110. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  31111. typoDescent = -typoDescent; // fixing incorrect descent
  31112. }
  31113. var winAscent = override.yMax || typoAscent;
  31114. var winDescent = -override.yMin || -typoDescent;
  31115. return '\x00\x03' + // version
  31116. '\x02\x24' + // xAvgCharWidth
  31117. '\x01\xF4' + // usWeightClass
  31118. '\x00\x05' + // usWidthClass
  31119. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  31120. '\x02\x8A' + // ySubscriptXSize
  31121. '\x02\xBB' + // ySubscriptYSize
  31122. '\x00\x00' + // ySubscriptXOffset
  31123. '\x00\x8C' + // ySubscriptYOffset
  31124. '\x02\x8A' + // ySuperScriptXSize
  31125. '\x02\xBB' + // ySuperScriptYSize
  31126. '\x00\x00' + // ySuperScriptXOffset
  31127. '\x01\xDF' + // ySuperScriptYOffset
  31128. '\x00\x31' + // yStrikeOutSize
  31129. '\x01\x02' + // yStrikeOutPosition
  31130. '\x00\x00' + // sFamilyClass
  31131. '\x00\x00\x06' +
  31132. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  31133. '\x00\x00\x00\x00\x00\x00' + // Panose
  31134. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  31135. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  31136. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  31137. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  31138. '\x2A\x32\x31\x2A' + // achVendID
  31139. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  31140. string16(firstCharIndex ||
  31141. properties.firstChar) + // usFirstCharIndex
  31142. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  31143. string16(typoAscent) + // sTypoAscender
  31144. string16(typoDescent) + // sTypoDescender
  31145. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  31146. string16(winAscent) + // usWinAscent
  31147. string16(winDescent) + // usWinDescent
  31148. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  31149. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  31150. string16(properties.xHeight) + // sxHeight
  31151. string16(properties.capHeight) + // sCapHeight
  31152. string16(0) + // usDefaultChar
  31153. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  31154. '\x00\x03'; // usMaxContext
  31155. }
  31156. function createPostTable(properties) {
  31157. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  31158. return ('\x00\x03\x00\x00' + // Version number
  31159. string32(angle) + // italicAngle
  31160. '\x00\x00' + // underlinePosition
  31161. '\x00\x00' + // underlineThickness
  31162. string32(properties.fixedPitch) + // isFixedPitch
  31163. '\x00\x00\x00\x00' + // minMemType42
  31164. '\x00\x00\x00\x00' + // maxMemType42
  31165. '\x00\x00\x00\x00' + // minMemType1
  31166. '\x00\x00\x00\x00'); // maxMemType1
  31167. }
  31168. function createNameTable(name, proto) {
  31169. if (!proto) {
  31170. proto = [[], []]; // no strings and unicode strings
  31171. }
  31172. var strings = [
  31173. proto[0][0] || 'Original licence', // 0.Copyright
  31174. proto[0][1] || name, // 1.Font family
  31175. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  31176. proto[0][3] || 'uniqueID', // 3.Unique ID
  31177. proto[0][4] || name, // 4.Full font name
  31178. proto[0][5] || 'Version 0.11', // 5.Version
  31179. proto[0][6] || '', // 6.Postscript name
  31180. proto[0][7] || 'Unknown', // 7.Trademark
  31181. proto[0][8] || 'Unknown', // 8.Manufacturer
  31182. proto[0][9] || 'Unknown' // 9.Designer
  31183. ];
  31184. // Mac want 1-byte per character strings while Windows want
  31185. // 2-bytes per character, so duplicate the names table
  31186. var stringsUnicode = [];
  31187. var i, ii, j, jj, str;
  31188. for (i = 0, ii = strings.length; i < ii; i++) {
  31189. str = proto[1][i] || strings[i];
  31190. var strBufUnicode = [];
  31191. for (j = 0, jj = str.length; j < jj; j++) {
  31192. strBufUnicode.push(string16(str.charCodeAt(j)));
  31193. }
  31194. stringsUnicode.push(strBufUnicode.join(''));
  31195. }
  31196. var names = [strings, stringsUnicode];
  31197. var platforms = ['\x00\x01', '\x00\x03'];
  31198. var encodings = ['\x00\x00', '\x00\x01'];
  31199. var languages = ['\x00\x00', '\x04\x09'];
  31200. var namesRecordCount = strings.length * platforms.length;
  31201. var nameTable =
  31202. '\x00\x00' + // format
  31203. string16(namesRecordCount) + // Number of names Record
  31204. string16(namesRecordCount * 12 + 6); // Storage
  31205. // Build the name records field
  31206. var strOffset = 0;
  31207. for (i = 0, ii = platforms.length; i < ii; i++) {
  31208. var strs = names[i];
  31209. for (j = 0, jj = strs.length; j < jj; j++) {
  31210. str = strs[j];
  31211. var nameRecord =
  31212. platforms[i] + // platform ID
  31213. encodings[i] + // encoding ID
  31214. languages[i] + // language ID
  31215. string16(j) + // name ID
  31216. string16(str.length) +
  31217. string16(strOffset);
  31218. nameTable += nameRecord;
  31219. strOffset += str.length;
  31220. }
  31221. }
  31222. nameTable += strings.join('') + stringsUnicode.join('');
  31223. return nameTable;
  31224. }
  31225. Font.prototype = {
  31226. name: null,
  31227. font: null,
  31228. mimetype: null,
  31229. encoding: null,
  31230. get renderer() {
  31231. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  31232. return shadow(this, 'renderer', renderer);
  31233. },
  31234. exportData: function Font_exportData() {
  31235. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  31236. var data = {};
  31237. for (var i in this) {
  31238. if (this.hasOwnProperty(i)) {
  31239. data[i] = this[i];
  31240. }
  31241. }
  31242. return data;
  31243. },
  31244. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  31245. function readTableEntry(file) {
  31246. var tag = bytesToString(file.getBytes(4));
  31247. var checksum = file.getInt32() >>> 0;
  31248. var offset = file.getInt32() >>> 0;
  31249. var length = file.getInt32() >>> 0;
  31250. // Read the table associated data
  31251. var previousPosition = file.pos;
  31252. file.pos = file.start ? file.start : 0;
  31253. file.skip(offset);
  31254. var data = file.getBytes(length);
  31255. file.pos = previousPosition;
  31256. if (tag === 'head') {
  31257. // clearing checksum adjustment
  31258. data[8] = data[9] = data[10] = data[11] = 0;
  31259. data[17] |= 0x20; //Set font optimized for cleartype flag
  31260. }
  31261. return {
  31262. tag: tag,
  31263. checksum: checksum,
  31264. length: length,
  31265. offset: offset,
  31266. data: data
  31267. };
  31268. }
  31269. function readOpenTypeHeader(ttf) {
  31270. return {
  31271. version: bytesToString(ttf.getBytes(4)),
  31272. numTables: ttf.getUint16(),
  31273. searchRange: ttf.getUint16(),
  31274. entrySelector: ttf.getUint16(),
  31275. rangeShift: ttf.getUint16()
  31276. };
  31277. }
  31278. /**
  31279. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  31280. * PDF spec
  31281. */
  31282. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  31283. if (!cmap) {
  31284. warn('No cmap table available.');
  31285. return {
  31286. platformId: -1,
  31287. encodingId: -1,
  31288. mappings: [],
  31289. hasShortCmap: false
  31290. };
  31291. }
  31292. var segment;
  31293. var start = (font.start ? font.start : 0) + cmap.offset;
  31294. font.pos = start;
  31295. var version = font.getUint16();
  31296. var numTables = font.getUint16();
  31297. var potentialTable;
  31298. var canBreak = false;
  31299. // There's an order of preference in terms of which cmap subtable to
  31300. // use:
  31301. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  31302. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  31303. // The following takes advantage of the fact that the tables are sorted
  31304. // to work.
  31305. for (var i = 0; i < numTables; i++) {
  31306. var platformId = font.getUint16();
  31307. var encodingId = font.getUint16();
  31308. var offset = font.getInt32() >>> 0;
  31309. var useTable = false;
  31310. if (platformId === 0 && encodingId === 0) {
  31311. useTable = true;
  31312. // Continue the loop since there still may be a higher priority
  31313. // table.
  31314. } else if (platformId === 1 && encodingId === 0) {
  31315. useTable = true;
  31316. // Continue the loop since there still may be a higher priority
  31317. // table.
  31318. } else if (platformId === 3 && encodingId === 1 &&
  31319. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  31320. useTable = true;
  31321. if (!isSymbolicFont) {
  31322. canBreak = true;
  31323. }
  31324. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  31325. useTable = true;
  31326. canBreak = true;
  31327. }
  31328. if (useTable) {
  31329. potentialTable = {
  31330. platformId: platformId,
  31331. encodingId: encodingId,
  31332. offset: offset
  31333. };
  31334. }
  31335. if (canBreak) {
  31336. break;
  31337. }
  31338. }
  31339. if (potentialTable) {
  31340. font.pos = start + potentialTable.offset;
  31341. }
  31342. if (!potentialTable || font.peekByte() === -1) {
  31343. warn('Could not find a preferred cmap table.');
  31344. return {
  31345. platformId: -1,
  31346. encodingId: -1,
  31347. mappings: [],
  31348. hasShortCmap: false
  31349. };
  31350. }
  31351. var format = font.getUint16();
  31352. var length = font.getUint16();
  31353. var language = font.getUint16();
  31354. var hasShortCmap = false;
  31355. var mappings = [];
  31356. var j, glyphId;
  31357. // TODO(mack): refactor this cmap subtable reading logic out
  31358. if (format === 0) {
  31359. for (j = 0; j < 256; j++) {
  31360. var index = font.getByte();
  31361. if (!index) {
  31362. continue;
  31363. }
  31364. mappings.push({
  31365. charCode: j,
  31366. glyphId: index
  31367. });
  31368. }
  31369. hasShortCmap = true;
  31370. } else if (format === 4) {
  31371. // re-creating the table in format 4 since the encoding
  31372. // might be changed
  31373. var segCount = (font.getUint16() >> 1);
  31374. font.getBytes(6); // skipping range fields
  31375. var segIndex, segments = [];
  31376. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31377. segments.push({ end: font.getUint16() });
  31378. }
  31379. font.getUint16();
  31380. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31381. segments[segIndex].start = font.getUint16();
  31382. }
  31383. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31384. segments[segIndex].delta = font.getUint16();
  31385. }
  31386. var offsetsCount = 0;
  31387. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31388. segment = segments[segIndex];
  31389. var rangeOffset = font.getUint16();
  31390. if (!rangeOffset) {
  31391. segment.offsetIndex = -1;
  31392. continue;
  31393. }
  31394. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  31395. segment.offsetIndex = offsetIndex;
  31396. offsetsCount = Math.max(offsetsCount, offsetIndex +
  31397. segment.end - segment.start + 1);
  31398. }
  31399. var offsets = [];
  31400. for (j = 0; j < offsetsCount; j++) {
  31401. offsets.push(font.getUint16());
  31402. }
  31403. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31404. segment = segments[segIndex];
  31405. start = segment.start;
  31406. var end = segment.end;
  31407. var delta = segment.delta;
  31408. offsetIndex = segment.offsetIndex;
  31409. for (j = start; j <= end; j++) {
  31410. if (j === 0xFFFF) {
  31411. continue;
  31412. }
  31413. glyphId = (offsetIndex < 0 ?
  31414. j : offsets[offsetIndex + j - start]);
  31415. glyphId = (glyphId + delta) & 0xFFFF;
  31416. if (glyphId === 0) {
  31417. continue;
  31418. }
  31419. mappings.push({
  31420. charCode: j,
  31421. glyphId: glyphId
  31422. });
  31423. }
  31424. }
  31425. } else if (format === 6) {
  31426. // Format 6 is a 2-bytes dense mapping, which means the font data
  31427. // lives glue together even if they are pretty far in the unicode
  31428. // table. (This looks weird, so I can have missed something), this
  31429. // works on Linux but seems to fails on Mac so let's rewrite the
  31430. // cmap table to a 3-1-4 style
  31431. var firstCode = font.getUint16();
  31432. var entryCount = font.getUint16();
  31433. for (j = 0; j < entryCount; j++) {
  31434. glyphId = font.getUint16();
  31435. var charCode = firstCode + j;
  31436. mappings.push({
  31437. charCode: charCode,
  31438. glyphId: glyphId
  31439. });
  31440. }
  31441. } else {
  31442. warn('cmap table has unsupported format: ' + format);
  31443. return {
  31444. platformId: -1,
  31445. encodingId: -1,
  31446. mappings: [],
  31447. hasShortCmap: false
  31448. };
  31449. }
  31450. // removing duplicate entries
  31451. mappings.sort(function (a, b) {
  31452. return a.charCode - b.charCode;
  31453. });
  31454. for (i = 1; i < mappings.length; i++) {
  31455. if (mappings[i - 1].charCode === mappings[i].charCode) {
  31456. mappings.splice(i, 1);
  31457. i--;
  31458. }
  31459. }
  31460. return {
  31461. platformId: potentialTable.platformId,
  31462. encodingId: potentialTable.encodingId,
  31463. mappings: mappings,
  31464. hasShortCmap: hasShortCmap
  31465. };
  31466. }
  31467. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  31468. if (!header) {
  31469. if (metrics) {
  31470. metrics.data = null;
  31471. }
  31472. return;
  31473. }
  31474. font.pos = (font.start ? font.start : 0) + header.offset;
  31475. font.pos += header.length - 2;
  31476. var numOfMetrics = font.getUint16();
  31477. if (numOfMetrics > numGlyphs) {
  31478. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  31479. 'greater than the numGlyphs (' + numGlyphs + ')');
  31480. // Reduce numOfMetrics if it is greater than numGlyphs
  31481. numOfMetrics = numGlyphs;
  31482. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  31483. header.data[35] = numOfMetrics & 0x00ff;
  31484. }
  31485. var numOfSidebearings = numGlyphs - numOfMetrics;
  31486. var numMissing = numOfSidebearings -
  31487. ((metrics.length - numOfMetrics * 4) >> 1);
  31488. if (numMissing > 0) {
  31489. // For each missing glyph, we set both the width and lsb to 0 (zero).
  31490. // Since we need to add two properties for each glyph, this explains
  31491. // the use of |numMissing * 2| when initializing the typed array.
  31492. var entries = new Uint8Array(metrics.length + numMissing * 2);
  31493. entries.set(metrics.data);
  31494. metrics.data = entries;
  31495. }
  31496. }
  31497. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  31498. hintsValid) {
  31499. if (sourceEnd - sourceStart <= 12) {
  31500. // glyph with data less than 12 is invalid one
  31501. return 0;
  31502. }
  31503. var glyf = source.subarray(sourceStart, sourceEnd);
  31504. var contoursCount = (glyf[0] << 8) | glyf[1];
  31505. if (contoursCount & 0x8000) {
  31506. // complex glyph, writing as is
  31507. dest.set(glyf, destStart);
  31508. return glyf.length;
  31509. }
  31510. var i, j = 10, flagsCount = 0;
  31511. for (i = 0; i < contoursCount; i++) {
  31512. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  31513. flagsCount = endPoint + 1;
  31514. j += 2;
  31515. }
  31516. // skipping instructions
  31517. var instructionsStart = j;
  31518. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  31519. j += 2 + instructionsLength;
  31520. var instructionsEnd = j;
  31521. // validating flags
  31522. var coordinatesLength = 0;
  31523. for (i = 0; i < flagsCount; i++) {
  31524. var flag = glyf[j++];
  31525. if (flag & 0xC0) {
  31526. // reserved flags must be zero, cleaning up
  31527. glyf[j - 1] = flag & 0x3F;
  31528. }
  31529. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  31530. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  31531. coordinatesLength += xyLength;
  31532. if (flag & 8) {
  31533. var repeat = glyf[j++];
  31534. i += repeat;
  31535. coordinatesLength += repeat * xyLength;
  31536. }
  31537. }
  31538. // glyph without coordinates will be rejected
  31539. if (coordinatesLength === 0) {
  31540. return 0;
  31541. }
  31542. var glyphDataLength = j + coordinatesLength;
  31543. if (glyphDataLength > glyf.length) {
  31544. // not enough data for coordinates
  31545. return 0;
  31546. }
  31547. if (!hintsValid && instructionsLength > 0) {
  31548. dest.set(glyf.subarray(0, instructionsStart), destStart);
  31549. dest.set([0, 0], destStart + instructionsStart);
  31550. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  31551. destStart + instructionsStart + 2);
  31552. glyphDataLength -= instructionsLength;
  31553. if (glyf.length - glyphDataLength > 3) {
  31554. glyphDataLength = (glyphDataLength + 3) & ~3;
  31555. }
  31556. return glyphDataLength;
  31557. }
  31558. if (glyf.length - glyphDataLength > 3) {
  31559. // truncating and aligning to 4 bytes the long glyph data
  31560. glyphDataLength = (glyphDataLength + 3) & ~3;
  31561. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  31562. return glyphDataLength;
  31563. }
  31564. // glyph data is fine
  31565. dest.set(glyf, destStart);
  31566. return glyf.length;
  31567. }
  31568. function sanitizeHead(head, numGlyphs, locaLength) {
  31569. var data = head.data;
  31570. // Validate version:
  31571. // Should always be 0x00010000
  31572. var version = int32(data[0], data[1], data[2], data[3]);
  31573. if (version >> 16 !== 1) {
  31574. info('Attempting to fix invalid version in head table: ' + version);
  31575. data[0] = 0;
  31576. data[1] = 1;
  31577. data[2] = 0;
  31578. data[3] = 0;
  31579. }
  31580. var indexToLocFormat = int16(data[50], data[51]);
  31581. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  31582. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  31583. indexToLocFormat);
  31584. // The value of indexToLocFormat should be 0 if the loca table
  31585. // consists of short offsets, and should be 1 if the loca table
  31586. // consists of long offsets.
  31587. //
  31588. // The number of entries in the loca table should be numGlyphs + 1.
  31589. //
  31590. // Using this information, we can work backwards to deduce if the
  31591. // size of each offset in the loca table, and thus figure out the
  31592. // appropriate value for indexToLocFormat.
  31593. var numGlyphsPlusOne = numGlyphs + 1;
  31594. if (locaLength === numGlyphsPlusOne << 1) {
  31595. // 0x0000 indicates the loca table consists of short offsets
  31596. data[50] = 0;
  31597. data[51] = 0;
  31598. } else if (locaLength === numGlyphsPlusOne << 2) {
  31599. // 0x0001 indicates the loca table consists of long offsets
  31600. data[50] = 0;
  31601. data[51] = 1;
  31602. } else {
  31603. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  31604. }
  31605. }
  31606. }
  31607. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  31608. isGlyphLocationsLong, hintsValid,
  31609. dupFirstEntry) {
  31610. var itemSize, itemDecode, itemEncode;
  31611. if (isGlyphLocationsLong) {
  31612. itemSize = 4;
  31613. itemDecode = function fontItemDecodeLong(data, offset) {
  31614. return (data[offset] << 24) | (data[offset + 1] << 16) |
  31615. (data[offset + 2] << 8) | data[offset + 3];
  31616. };
  31617. itemEncode = function fontItemEncodeLong(data, offset, value) {
  31618. data[offset] = (value >>> 24) & 0xFF;
  31619. data[offset + 1] = (value >> 16) & 0xFF;
  31620. data[offset + 2] = (value >> 8) & 0xFF;
  31621. data[offset + 3] = value & 0xFF;
  31622. };
  31623. } else {
  31624. itemSize = 2;
  31625. itemDecode = function fontItemDecode(data, offset) {
  31626. return (data[offset] << 9) | (data[offset + 1] << 1);
  31627. };
  31628. itemEncode = function fontItemEncode(data, offset, value) {
  31629. data[offset] = (value >> 9) & 0xFF;
  31630. data[offset + 1] = (value >> 1) & 0xFF;
  31631. };
  31632. }
  31633. var locaData = loca.data;
  31634. var locaDataSize = itemSize * (1 + numGlyphs);
  31635. // is loca.data too short or long?
  31636. if (locaData.length !== locaDataSize) {
  31637. locaData = new Uint8Array(locaDataSize);
  31638. locaData.set(loca.data.subarray(0, locaDataSize));
  31639. loca.data = locaData;
  31640. }
  31641. // removing the invalid glyphs
  31642. var oldGlyfData = glyf.data;
  31643. var oldGlyfDataLength = oldGlyfData.length;
  31644. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  31645. var startOffset = itemDecode(locaData, 0);
  31646. var writeOffset = 0;
  31647. var missingGlyphData = Object.create(null);
  31648. itemEncode(locaData, 0, writeOffset);
  31649. var i, j;
  31650. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31651. var endOffset = itemDecode(locaData, j);
  31652. if (endOffset > oldGlyfDataLength &&
  31653. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  31654. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  31655. // the glyf table size, which makes last glyph out of range.
  31656. endOffset = oldGlyfDataLength;
  31657. }
  31658. if (endOffset > oldGlyfDataLength) {
  31659. // glyph end offset points outside glyf data, rejecting the glyph
  31660. itemEncode(locaData, j, writeOffset);
  31661. startOffset = endOffset;
  31662. continue;
  31663. }
  31664. if (startOffset === endOffset) {
  31665. missingGlyphData[i] = true;
  31666. }
  31667. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  31668. newGlyfData, writeOffset, hintsValid);
  31669. writeOffset += newLength;
  31670. itemEncode(locaData, j, writeOffset);
  31671. startOffset = endOffset;
  31672. }
  31673. if (writeOffset === 0) {
  31674. // glyf table cannot be empty -- redoing the glyf and loca tables
  31675. // to have single glyph with one point
  31676. var simpleGlyph = new Uint8Array(
  31677. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  31678. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31679. itemEncode(locaData, j, simpleGlyph.length);
  31680. }
  31681. glyf.data = simpleGlyph;
  31682. return missingGlyphData;
  31683. }
  31684. if (dupFirstEntry) {
  31685. var firstEntryLength = itemDecode(locaData, itemSize);
  31686. if (newGlyfData.length > firstEntryLength + writeOffset) {
  31687. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  31688. } else {
  31689. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  31690. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  31691. }
  31692. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  31693. itemEncode(loca.data, locaData.length - itemSize,
  31694. writeOffset + firstEntryLength);
  31695. } else {
  31696. glyf.data = newGlyfData.subarray(0, writeOffset);
  31697. }
  31698. return missingGlyphData;
  31699. }
  31700. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  31701. var start = (font.start ? font.start : 0) + post.offset;
  31702. font.pos = start;
  31703. var length = post.length, end = start + length;
  31704. var version = font.getInt32();
  31705. // skip rest to the tables
  31706. font.getBytes(28);
  31707. var glyphNames;
  31708. var valid = true;
  31709. var i;
  31710. switch (version) {
  31711. case 0x00010000:
  31712. glyphNames = MacStandardGlyphOrdering;
  31713. break;
  31714. case 0x00020000:
  31715. var numGlyphs = font.getUint16();
  31716. if (numGlyphs !== maxpNumGlyphs) {
  31717. valid = false;
  31718. break;
  31719. }
  31720. var glyphNameIndexes = [];
  31721. for (i = 0; i < numGlyphs; ++i) {
  31722. var index = font.getUint16();
  31723. if (index >= 32768) {
  31724. valid = false;
  31725. break;
  31726. }
  31727. glyphNameIndexes.push(index);
  31728. }
  31729. if (!valid) {
  31730. break;
  31731. }
  31732. var customNames = [];
  31733. var strBuf = [];
  31734. while (font.pos < end) {
  31735. var stringLength = font.getByte();
  31736. strBuf.length = stringLength;
  31737. for (i = 0; i < stringLength; ++i) {
  31738. strBuf[i] = String.fromCharCode(font.getByte());
  31739. }
  31740. customNames.push(strBuf.join(''));
  31741. }
  31742. glyphNames = [];
  31743. for (i = 0; i < numGlyphs; ++i) {
  31744. var j = glyphNameIndexes[i];
  31745. if (j < 258) {
  31746. glyphNames.push(MacStandardGlyphOrdering[j]);
  31747. continue;
  31748. }
  31749. glyphNames.push(customNames[j - 258]);
  31750. }
  31751. break;
  31752. case 0x00030000:
  31753. break;
  31754. default:
  31755. warn('Unknown/unsupported post table version ' + version);
  31756. valid = false;
  31757. if (properties.defaultEncoding) {
  31758. glyphNames = properties.defaultEncoding;
  31759. }
  31760. break;
  31761. }
  31762. properties.glyphNames = glyphNames;
  31763. return valid;
  31764. }
  31765. function readNameTable(nameTable) {
  31766. var start = (font.start ? font.start : 0) + nameTable.offset;
  31767. font.pos = start;
  31768. var names = [[], []];
  31769. var length = nameTable.length, end = start + length;
  31770. var format = font.getUint16();
  31771. var FORMAT_0_HEADER_LENGTH = 6;
  31772. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  31773. // unsupported name table format or table "too" small
  31774. return names;
  31775. }
  31776. var numRecords = font.getUint16();
  31777. var stringsStart = font.getUint16();
  31778. var records = [];
  31779. var NAME_RECORD_LENGTH = 12;
  31780. var i, ii;
  31781. for (i = 0; i < numRecords &&
  31782. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  31783. var r = {
  31784. platform: font.getUint16(),
  31785. encoding: font.getUint16(),
  31786. language: font.getUint16(),
  31787. name: font.getUint16(),
  31788. length: font.getUint16(),
  31789. offset: font.getUint16()
  31790. };
  31791. // using only Macintosh and Windows platform/encoding names
  31792. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  31793. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  31794. records.push(r);
  31795. }
  31796. }
  31797. for (i = 0, ii = records.length; i < ii; i++) {
  31798. var record = records[i];
  31799. if (record.length <= 0) {
  31800. continue; // Nothing to process, ignoring.
  31801. }
  31802. var pos = start + stringsStart + record.offset;
  31803. if (pos + record.length > end) {
  31804. continue; // outside of name table, ignoring
  31805. }
  31806. font.pos = pos;
  31807. var nameIndex = record.name;
  31808. if (record.encoding) {
  31809. // unicode
  31810. var str = '';
  31811. for (var j = 0, jj = record.length; j < jj; j += 2) {
  31812. str += String.fromCharCode(font.getUint16());
  31813. }
  31814. names[1][nameIndex] = str;
  31815. } else {
  31816. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  31817. }
  31818. }
  31819. return names;
  31820. }
  31821. var TTOpsStackDeltas = [
  31822. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  31823. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  31824. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  31825. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  31826. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  31827. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  31828. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  31829. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  31830. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  31831. // 0xC0-DF == -1 and 0xE0-FF == -2
  31832. function sanitizeTTProgram(table, ttContext) {
  31833. var data = table.data;
  31834. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  31835. var stack = [];
  31836. var callstack = [];
  31837. var functionsCalled = [];
  31838. var tooComplexToFollowFunctions =
  31839. ttContext.tooComplexToFollowFunctions;
  31840. var inFDEF = false, ifLevel = 0, inELSE = 0;
  31841. for (var ii = data.length; i < ii;) {
  31842. var op = data[i++];
  31843. // The TrueType instruction set docs can be found at
  31844. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  31845. if (op === 0x40) { // NPUSHB - pushes n bytes
  31846. n = data[i++];
  31847. if (inFDEF || inELSE) {
  31848. i += n;
  31849. } else {
  31850. for (j = 0; j < n; j++) {
  31851. stack.push(data[i++]);
  31852. }
  31853. }
  31854. } else if (op === 0x41) { // NPUSHW - pushes n words
  31855. n = data[i++];
  31856. if (inFDEF || inELSE) {
  31857. i += n * 2;
  31858. } else {
  31859. for (j = 0; j < n; j++) {
  31860. b = data[i++];
  31861. stack.push((b << 8) | data[i++]);
  31862. }
  31863. }
  31864. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  31865. n = op - 0xB0 + 1;
  31866. if (inFDEF || inELSE) {
  31867. i += n;
  31868. } else {
  31869. for (j = 0; j < n; j++) {
  31870. stack.push(data[i++]);
  31871. }
  31872. }
  31873. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  31874. n = op - 0xB8 + 1;
  31875. if (inFDEF || inELSE) {
  31876. i += n * 2;
  31877. } else {
  31878. for (j = 0; j < n; j++) {
  31879. b = data[i++];
  31880. stack.push((b << 8) | data[i++]);
  31881. }
  31882. }
  31883. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  31884. if (!inFDEF && !inELSE) {
  31885. // collecting inforamtion about which functions are used
  31886. funcId = stack[stack.length - 1];
  31887. ttContext.functionsUsed[funcId] = true;
  31888. if (funcId in ttContext.functionsStackDeltas) {
  31889. stack.length += ttContext.functionsStackDeltas[funcId];
  31890. } else if (funcId in ttContext.functionsDefined &&
  31891. functionsCalled.indexOf(funcId) < 0) {
  31892. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  31893. functionsCalled.push(funcId);
  31894. pc = ttContext.functionsDefined[funcId];
  31895. if (!pc) {
  31896. warn('TT: CALL non-existent function');
  31897. ttContext.hintsValid = false;
  31898. return;
  31899. }
  31900. data = pc.data;
  31901. i = pc.i;
  31902. }
  31903. }
  31904. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  31905. if (inFDEF || inELSE) {
  31906. warn('TT: nested FDEFs not allowed');
  31907. tooComplexToFollowFunctions = true;
  31908. }
  31909. inFDEF = true;
  31910. // collecting inforamtion about which functions are defined
  31911. lastDeff = i;
  31912. funcId = stack.pop();
  31913. ttContext.functionsDefined[funcId] = {data: data, i: i};
  31914. } else if (op === 0x2D) { // ENDF - end of function
  31915. if (inFDEF) {
  31916. inFDEF = false;
  31917. lastEndf = i;
  31918. } else {
  31919. pc = callstack.pop();
  31920. if (!pc) {
  31921. warn('TT: ENDF bad stack');
  31922. ttContext.hintsValid = false;
  31923. return;
  31924. }
  31925. funcId = functionsCalled.pop();
  31926. data = pc.data;
  31927. i = pc.i;
  31928. ttContext.functionsStackDeltas[funcId] =
  31929. stack.length - pc.stackTop;
  31930. }
  31931. } else if (op === 0x89) { // IDEF - instruction definition
  31932. if (inFDEF || inELSE) {
  31933. warn('TT: nested IDEFs not allowed');
  31934. tooComplexToFollowFunctions = true;
  31935. }
  31936. inFDEF = true;
  31937. // recording it as a function to track ENDF
  31938. lastDeff = i;
  31939. } else if (op === 0x58) { // IF
  31940. ++ifLevel;
  31941. } else if (op === 0x1B) { // ELSE
  31942. inELSE = ifLevel;
  31943. } else if (op === 0x59) { // EIF
  31944. if (inELSE === ifLevel) {
  31945. inELSE = 0;
  31946. }
  31947. --ifLevel;
  31948. } else if (op === 0x1C) { // JMPR
  31949. if (!inFDEF && !inELSE) {
  31950. var offset = stack[stack.length - 1];
  31951. // only jumping forward to prevent infinite loop
  31952. if (offset > 0) {
  31953. i += offset - 1;
  31954. }
  31955. }
  31956. }
  31957. // Adjusting stack not extactly, but just enough to get function id
  31958. if (!inFDEF && !inELSE) {
  31959. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  31960. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  31961. if (op >= 0x71 && op <= 0x75) {
  31962. n = stack.pop();
  31963. if (n === n) {
  31964. stackDelta = -n * 2;
  31965. }
  31966. }
  31967. while (stackDelta < 0 && stack.length > 0) {
  31968. stack.pop();
  31969. stackDelta++;
  31970. }
  31971. while (stackDelta > 0) {
  31972. stack.push(NaN); // pushing any number into stack
  31973. stackDelta--;
  31974. }
  31975. }
  31976. }
  31977. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  31978. var content = [data];
  31979. if (i > data.length) {
  31980. content.push(new Uint8Array(i - data.length));
  31981. }
  31982. if (lastDeff > lastEndf) {
  31983. warn('TT: complementing a missing function tail');
  31984. // new function definition started, but not finished
  31985. // complete function by [CLEAR, ENDF]
  31986. content.push(new Uint8Array([0x22, 0x2D]));
  31987. }
  31988. foldTTTable(table, content);
  31989. }
  31990. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  31991. if (ttContext.tooComplexToFollowFunctions) {
  31992. return;
  31993. }
  31994. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  31995. warn('TT: more functions defined than expected');
  31996. ttContext.hintsValid = false;
  31997. return;
  31998. }
  31999. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  32000. if (j > maxFunctionDefs) {
  32001. warn('TT: invalid function id: ' + j);
  32002. ttContext.hintsValid = false;
  32003. return;
  32004. }
  32005. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  32006. warn('TT: undefined function: ' + j);
  32007. ttContext.hintsValid = false;
  32008. return;
  32009. }
  32010. }
  32011. }
  32012. function foldTTTable(table, content) {
  32013. if (content.length > 1) {
  32014. // concatenating the content items
  32015. var newLength = 0;
  32016. var j, jj;
  32017. for (j = 0, jj = content.length; j < jj; j++) {
  32018. newLength += content[j].length;
  32019. }
  32020. newLength = (newLength + 3) & ~3;
  32021. var result = new Uint8Array(newLength);
  32022. var pos = 0;
  32023. for (j = 0, jj = content.length; j < jj; j++) {
  32024. result.set(content[j], pos);
  32025. pos += content[j].length;
  32026. }
  32027. table.data = result;
  32028. table.length = newLength;
  32029. }
  32030. }
  32031. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  32032. var ttContext = {
  32033. functionsDefined: [],
  32034. functionsUsed: [],
  32035. functionsStackDeltas: [],
  32036. tooComplexToFollowFunctions: false,
  32037. hintsValid: true
  32038. };
  32039. if (fpgm) {
  32040. sanitizeTTProgram(fpgm, ttContext);
  32041. }
  32042. if (prep) {
  32043. sanitizeTTProgram(prep, ttContext);
  32044. }
  32045. if (fpgm) {
  32046. checkInvalidFunctions(ttContext, maxFunctionDefs);
  32047. }
  32048. if (cvt && (cvt.length & 1)) {
  32049. var cvtData = new Uint8Array(cvt.length + 1);
  32050. cvtData.set(cvt.data);
  32051. cvt.data = cvtData;
  32052. }
  32053. return ttContext.hintsValid;
  32054. }
  32055. // The following steps modify the original font data, making copy
  32056. font = new Stream(new Uint8Array(font.getBytes()));
  32057. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  32058. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  32059. var header = readOpenTypeHeader(font);
  32060. var numTables = header.numTables;
  32061. var cff, cffFile;
  32062. var tables = Object.create(null);
  32063. tables['OS/2'] = null;
  32064. tables['cmap'] = null;
  32065. tables['head'] = null;
  32066. tables['hhea'] = null;
  32067. tables['hmtx'] = null;
  32068. tables['maxp'] = null;
  32069. tables['name'] = null;
  32070. tables['post'] = null;
  32071. var table;
  32072. for (var i = 0; i < numTables; i++) {
  32073. table = readTableEntry(font);
  32074. if (VALID_TABLES.indexOf(table.tag) < 0) {
  32075. continue; // skipping table if it's not a required or optional table
  32076. }
  32077. if (table.length === 0) {
  32078. continue; // skipping empty tables
  32079. }
  32080. tables[table.tag] = table;
  32081. }
  32082. var isTrueType = !tables['CFF '];
  32083. if (!isTrueType) {
  32084. // OpenType font
  32085. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  32086. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  32087. !tables['post']) {
  32088. // no major tables: throwing everything at CFFFont
  32089. cffFile = new Stream(tables['CFF '].data);
  32090. cff = new CFFFont(cffFile, properties);
  32091. adjustWidths(properties);
  32092. return this.convert(name, cff, properties);
  32093. }
  32094. delete tables['glyf'];
  32095. delete tables['loca'];
  32096. delete tables['fpgm'];
  32097. delete tables['prep'];
  32098. delete tables['cvt '];
  32099. this.isOpenType = true;
  32100. } else {
  32101. if (!tables['loca']) {
  32102. error('Required "loca" table is not found');
  32103. }
  32104. if (!tables['glyf']) {
  32105. warn('Required "glyf" table is not found -- trying to recover.');
  32106. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  32107. tables['glyf'] = {
  32108. tag: 'glyf',
  32109. data: new Uint8Array(0),
  32110. };
  32111. }
  32112. this.isOpenType = false;
  32113. }
  32114. if (!tables['maxp']) {
  32115. error('Required "maxp" table is not found');
  32116. }
  32117. font.pos = (font.start || 0) + tables['maxp'].offset;
  32118. var version = font.getInt32();
  32119. var numGlyphs = font.getUint16();
  32120. var maxFunctionDefs = 0;
  32121. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  32122. // maxZones can be invalid
  32123. font.pos += 8;
  32124. var maxZones = font.getUint16();
  32125. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  32126. tables['maxp'].data[14] = 0;
  32127. tables['maxp'].data[15] = 2;
  32128. }
  32129. font.pos += 4;
  32130. maxFunctionDefs = font.getUint16();
  32131. }
  32132. var dupFirstEntry = false;
  32133. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  32134. properties.toUnicode.get(0) > '\u0000') {
  32135. // oracle's defect (see 3427), duplicating first entry
  32136. dupFirstEntry = true;
  32137. numGlyphs++;
  32138. tables['maxp'].data[4] = numGlyphs >> 8;
  32139. tables['maxp'].data[5] = numGlyphs & 255;
  32140. }
  32141. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  32142. tables['cvt '], maxFunctionDefs);
  32143. if (!hintsValid) {
  32144. delete tables['fpgm'];
  32145. delete tables['prep'];
  32146. delete tables['cvt '];
  32147. }
  32148. // Ensure the hmtx table contains the advance width and
  32149. // sidebearings information for numGlyphs in the maxp table
  32150. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  32151. if (!tables['head']) {
  32152. error('Required "head" table is not found');
  32153. }
  32154. sanitizeHead(tables['head'], numGlyphs,
  32155. isTrueType ? tables['loca'].length : 0);
  32156. var missingGlyphs = Object.create(null);
  32157. if (isTrueType) {
  32158. var isGlyphLocationsLong = int16(tables['head'].data[50],
  32159. tables['head'].data[51]);
  32160. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  32161. numGlyphs, isGlyphLocationsLong,
  32162. hintsValid, dupFirstEntry);
  32163. }
  32164. if (!tables['hhea']) {
  32165. error('Required "hhea" table is not found');
  32166. }
  32167. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  32168. // Sometimes it's 0. That needs to be fixed
  32169. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  32170. tables['hhea'].data[10] = 0xFF;
  32171. tables['hhea'].data[11] = 0xFF;
  32172. }
  32173. // Extract some more font properties from the OpenType head and
  32174. // hhea tables; yMin and descent value are always negative.
  32175. var metricsOverride = {
  32176. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  32177. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  32178. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  32179. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  32180. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  32181. };
  32182. // PDF FontDescriptor metrics lie -- using data from actual font.
  32183. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  32184. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  32185. // The 'post' table has glyphs names.
  32186. if (tables['post']) {
  32187. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  32188. if (!valid) {
  32189. tables['post'] = null;
  32190. }
  32191. }
  32192. var charCodeToGlyphId = [], charCode;
  32193. var toUnicode = properties.toUnicode, widths = properties.widths;
  32194. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  32195. toUnicode.length === 0x10000);
  32196. // Helper function to try to skip mapping of empty glyphs.
  32197. // Note: In some cases, just relying on the glyph data doesn't work,
  32198. // hence we also use a few heuristics to fix various PDF files.
  32199. function hasGlyph(glyphId, charCode, widthCode) {
  32200. if (!missingGlyphs[glyphId]) {
  32201. return true;
  32202. }
  32203. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  32204. return true;
  32205. }
  32206. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  32207. return true;
  32208. }
  32209. return false;
  32210. }
  32211. if (properties.type === 'CIDFontType2') {
  32212. var cidToGidMap = properties.cidToGidMap || [];
  32213. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  32214. properties.cMap.forEach(function(charCode, cid) {
  32215. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  32216. var glyphId = -1;
  32217. if (isCidToGidMapEmpty) {
  32218. glyphId = cid;
  32219. } else if (cidToGidMap[cid] !== undefined) {
  32220. glyphId = cidToGidMap[cid];
  32221. }
  32222. if (glyphId >= 0 && glyphId < numGlyphs &&
  32223. hasGlyph(glyphId, charCode, cid)) {
  32224. charCodeToGlyphId[charCode] = glyphId;
  32225. }
  32226. });
  32227. if (dupFirstEntry) {
  32228. charCodeToGlyphId[0] = numGlyphs - 1;
  32229. }
  32230. } else {
  32231. // Most of the following logic in this code branch is based on the
  32232. // 9.6.6.4 of the PDF spec.
  32233. var hasEncoding =
  32234. properties.differences.length > 0 || !!properties.baseEncodingName;
  32235. var cmapTable =
  32236. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  32237. var cmapPlatformId = cmapTable.platformId;
  32238. var cmapEncodingId = cmapTable.encodingId;
  32239. var cmapMappings = cmapTable.mappings;
  32240. var cmapMappingsLength = cmapMappings.length;
  32241. // The spec seems to imply that if the font is symbolic the encoding
  32242. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  32243. // where the the font is symbolic and it has an encoding.
  32244. if (hasEncoding &&
  32245. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  32246. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  32247. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  32248. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  32249. // When no preferred cmap table was found and |baseEncodingName| is
  32250. // one of the predefined encodings, we seem to obtain a better
  32251. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  32252. // TODO: Note that this is a hack which should be removed as soon as
  32253. // we have proper support for more exotic cmap tables.
  32254. var baseEncoding = [];
  32255. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  32256. properties.baseEncodingName === 'WinAnsiEncoding') {
  32257. baseEncoding = getEncoding(properties.baseEncodingName);
  32258. }
  32259. var glyphsUnicodeMap = getGlyphsUnicode();
  32260. for (charCode = 0; charCode < 256; charCode++) {
  32261. var glyphName, standardGlyphName;
  32262. if (this.differences && charCode in this.differences) {
  32263. glyphName = this.differences[charCode];
  32264. } else if (charCode in baseEncoding &&
  32265. baseEncoding[charCode] !== '') {
  32266. glyphName = baseEncoding[charCode];
  32267. } else {
  32268. glyphName = StandardEncoding[charCode];
  32269. }
  32270. if (!glyphName) {
  32271. continue;
  32272. }
  32273. // Ensure that non-standard glyph names are resolved to valid ones.
  32274. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32275. var unicodeOrCharCode, isUnicode = false;
  32276. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  32277. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  32278. isUnicode = true;
  32279. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  32280. // TODO: the encoding needs to be updated with mac os table.
  32281. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  32282. }
  32283. var found = false;
  32284. for (i = 0; i < cmapMappingsLength; ++i) {
  32285. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  32286. continue;
  32287. }
  32288. var code = isUnicode ? charCode : unicodeOrCharCode;
  32289. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  32290. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32291. found = true;
  32292. break;
  32293. }
  32294. }
  32295. if (!found && properties.glyphNames) {
  32296. // Try to map using the post table.
  32297. var glyphId = properties.glyphNames.indexOf(glyphName);
  32298. // The post table ought to use the same kind of glyph names as the
  32299. // `differences` array, but check the standard ones as a fallback.
  32300. if (glyphId === -1 && standardGlyphName !== glyphName) {
  32301. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  32302. }
  32303. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  32304. charCodeToGlyphId[charCode] = glyphId;
  32305. found = true;
  32306. }
  32307. }
  32308. if (!found) {
  32309. charCodeToGlyphId[charCode] = 0; // notdef
  32310. }
  32311. }
  32312. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  32313. // Default Unicode semantics, use the charcodes as is.
  32314. for (i = 0; i < cmapMappingsLength; ++i) {
  32315. charCodeToGlyphId[cmapMappings[i].charCode] =
  32316. cmapMappings[i].glyphId;
  32317. }
  32318. } else {
  32319. // For (3, 0) cmap tables:
  32320. // The charcode key being stored in charCodeToGlyphId is the lower
  32321. // byte of the two-byte charcodes of the cmap table since according to
  32322. // the spec: 'each byte from the string shall be prepended with the
  32323. // high byte of the range [of charcodes in the cmap table], to form
  32324. // a two-byte character, which shall be used to select the
  32325. // associated glyph description from the subtable'.
  32326. //
  32327. // For (1, 0) cmap tables:
  32328. // 'single bytes from the string shall be used to look up the
  32329. // associated glyph descriptions from the subtable'. This means
  32330. // charcodes in the cmap will be single bytes, so no-op since
  32331. // glyph.charCode & 0xFF === glyph.charCode
  32332. for (i = 0; i < cmapMappingsLength; ++i) {
  32333. charCode = cmapMappings[i].charCode & 0xFF;
  32334. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32335. }
  32336. }
  32337. }
  32338. if (charCodeToGlyphId.length === 0) {
  32339. // defines at least one glyph
  32340. charCodeToGlyphId[0] = 0;
  32341. }
  32342. // Converting glyphs and ids into font's cmap table
  32343. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  32344. this.toFontChar = newMapping.toFontChar;
  32345. tables['cmap'] = {
  32346. tag: 'cmap',
  32347. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  32348. };
  32349. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  32350. tables['OS/2'] = {
  32351. tag: 'OS/2',
  32352. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  32353. metricsOverride)
  32354. };
  32355. }
  32356. // Rewrite the 'post' table if needed
  32357. if (!tables['post']) {
  32358. tables['post'] = {
  32359. tag: 'post',
  32360. data: createPostTable(properties)
  32361. };
  32362. }
  32363. if (!isTrueType) {
  32364. try {
  32365. // Trying to repair CFF file
  32366. cffFile = new Stream(tables['CFF '].data);
  32367. var parser = new CFFParser(cffFile, properties,
  32368. SEAC_ANALYSIS_ENABLED);
  32369. cff = parser.parse();
  32370. var compiler = new CFFCompiler(cff);
  32371. tables['CFF '].data = compiler.compile();
  32372. } catch (e) {
  32373. warn('Failed to compile font ' + properties.loadedName);
  32374. }
  32375. }
  32376. // Re-creating 'name' table
  32377. if (!tables['name']) {
  32378. tables['name'] = {
  32379. tag: 'name',
  32380. data: createNameTable(this.name)
  32381. };
  32382. } else {
  32383. // ... using existing 'name' table as prototype
  32384. var namePrototype = readNameTable(tables['name']);
  32385. tables['name'].data = createNameTable(name, namePrototype);
  32386. }
  32387. var builder = new OpenTypeFileBuilder(header.version);
  32388. for (var tableTag in tables) {
  32389. builder.addTable(tableTag, tables[tableTag].data);
  32390. }
  32391. return builder.toArray();
  32392. },
  32393. convert: function Font_convert(fontName, font, properties) {
  32394. // TODO: Check the charstring widths to determine this.
  32395. properties.fixedPitch = false;
  32396. var mapping = font.getGlyphMapping(properties);
  32397. var newMapping = adjustMapping(mapping, properties);
  32398. this.toFontChar = newMapping.toFontChar;
  32399. var numGlyphs = font.numGlyphs;
  32400. function getCharCodes(charCodeToGlyphId, glyphId) {
  32401. var charCodes = null;
  32402. for (var charCode in charCodeToGlyphId) {
  32403. if (glyphId === charCodeToGlyphId[charCode]) {
  32404. if (!charCodes) {
  32405. charCodes = [];
  32406. }
  32407. charCodes.push(charCode | 0);
  32408. }
  32409. }
  32410. return charCodes;
  32411. }
  32412. function createCharCode(charCodeToGlyphId, glyphId) {
  32413. for (var charCode in charCodeToGlyphId) {
  32414. if (glyphId === charCodeToGlyphId[charCode]) {
  32415. return charCode | 0;
  32416. }
  32417. }
  32418. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  32419. glyphId;
  32420. return newMapping.nextAvailableFontCharCode++;
  32421. }
  32422. var seacs = font.seacs;
  32423. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  32424. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  32425. var charset = font.getCharset();
  32426. var seacMap = Object.create(null);
  32427. for (var glyphId in seacs) {
  32428. glyphId |= 0;
  32429. var seac = seacs[glyphId];
  32430. var baseGlyphName = StandardEncoding[seac[2]];
  32431. var accentGlyphName = StandardEncoding[seac[3]];
  32432. var baseGlyphId = charset.indexOf(baseGlyphName);
  32433. var accentGlyphId = charset.indexOf(accentGlyphName);
  32434. if (baseGlyphId < 0 || accentGlyphId < 0) {
  32435. continue;
  32436. }
  32437. var accentOffset = {
  32438. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  32439. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  32440. };
  32441. var charCodes = getCharCodes(mapping, glyphId);
  32442. if (!charCodes) {
  32443. // There's no point in mapping it if the char code was never mapped
  32444. // to begin with.
  32445. continue;
  32446. }
  32447. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  32448. var charCode = charCodes[i];
  32449. // Find a fontCharCode that maps to the base and accent glyphs.
  32450. // If one doesn't exists, create it.
  32451. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  32452. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  32453. baseGlyphId);
  32454. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  32455. accentGlyphId);
  32456. seacMap[charCode] = {
  32457. baseFontCharCode: baseFontCharCode,
  32458. accentFontCharCode: accentFontCharCode,
  32459. accentOffset: accentOffset
  32460. };
  32461. }
  32462. }
  32463. properties.seacMap = seacMap;
  32464. }
  32465. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  32466. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  32467. // PostScript Font Program
  32468. builder.addTable('CFF ', font.data);
  32469. // OS/2 and Windows Specific metrics
  32470. builder.addTable('OS/2', createOS2Table(properties,
  32471. newMapping.charCodeToGlyphId));
  32472. // Character to glyphs mapping
  32473. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  32474. numGlyphs));
  32475. // Font header
  32476. builder.addTable('head',
  32477. '\x00\x01\x00\x00' + // Version number
  32478. '\x00\x00\x10\x00' + // fontRevision
  32479. '\x00\x00\x00\x00' + // checksumAdjustement
  32480. '\x5F\x0F\x3C\xF5' + // magicNumber
  32481. '\x00\x00' + // Flags
  32482. safeString16(unitsPerEm) + // unitsPerEM
  32483. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  32484. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  32485. '\x00\x00' + // xMin
  32486. safeString16(properties.descent) + // yMin
  32487. '\x0F\xFF' + // xMax
  32488. safeString16(properties.ascent) + // yMax
  32489. string16(properties.italicAngle ? 2 : 0) + // macStyle
  32490. '\x00\x11' + // lowestRecPPEM
  32491. '\x00\x00' + // fontDirectionHint
  32492. '\x00\x00' + // indexToLocFormat
  32493. '\x00\x00'); // glyphDataFormat
  32494. // Horizontal header
  32495. builder.addTable('hhea',
  32496. '\x00\x01\x00\x00' + // Version number
  32497. safeString16(properties.ascent) + // Typographic Ascent
  32498. safeString16(properties.descent) + // Typographic Descent
  32499. '\x00\x00' + // Line Gap
  32500. '\xFF\xFF' + // advanceWidthMax
  32501. '\x00\x00' + // minLeftSidebearing
  32502. '\x00\x00' + // minRightSidebearing
  32503. '\x00\x00' + // xMaxExtent
  32504. safeString16(properties.capHeight) + // caretSlopeRise
  32505. safeString16(Math.tan(properties.italicAngle) *
  32506. properties.xHeight) + // caretSlopeRun
  32507. '\x00\x00' + // caretOffset
  32508. '\x00\x00' + // -reserved-
  32509. '\x00\x00' + // -reserved-
  32510. '\x00\x00' + // -reserved-
  32511. '\x00\x00' + // -reserved-
  32512. '\x00\x00' + // metricDataFormat
  32513. string16(numGlyphs)); // Number of HMetrics
  32514. // Horizontal metrics
  32515. builder.addTable('hmtx', (function fontFieldsHmtx() {
  32516. var charstrings = font.charstrings;
  32517. var cffWidths = font.cff ? font.cff.widths : null;
  32518. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  32519. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  32520. var width = 0;
  32521. if (charstrings) {
  32522. var charstring = charstrings[i - 1];
  32523. width = 'width' in charstring ? charstring.width : 0;
  32524. } else if (cffWidths) {
  32525. width = Math.ceil(cffWidths[i] || 0);
  32526. }
  32527. hmtx += string16(width) + string16(0);
  32528. }
  32529. return hmtx;
  32530. })());
  32531. // Maximum profile
  32532. builder.addTable('maxp',
  32533. '\x00\x00\x50\x00' + // Version number
  32534. string16(numGlyphs)); // Num of glyphs
  32535. // Naming tables
  32536. builder.addTable('name', createNameTable(fontName));
  32537. // PostScript information
  32538. builder.addTable('post', createPostTable(properties));
  32539. return builder.toArray();
  32540. },
  32541. get spaceWidth() {
  32542. if ('_shadowWidth' in this) {
  32543. return this._shadowWidth;
  32544. }
  32545. // trying to estimate space character width
  32546. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  32547. var width;
  32548. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  32549. var glyphName = possibleSpaceReplacements[i];
  32550. // if possible, getting width by glyph name
  32551. if (glyphName in this.widths) {
  32552. width = this.widths[glyphName];
  32553. break;
  32554. }
  32555. var glyphsUnicodeMap = getGlyphsUnicode();
  32556. var glyphUnicode = glyphsUnicodeMap[glyphName];
  32557. // finding the charcode via unicodeToCID map
  32558. var charcode = 0;
  32559. if (this.composite) {
  32560. if (this.cMap.contains(glyphUnicode)) {
  32561. charcode = this.cMap.lookup(glyphUnicode);
  32562. }
  32563. }
  32564. // ... via toUnicode map
  32565. if (!charcode && this.toUnicode) {
  32566. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  32567. }
  32568. // setting it to unicode if negative or undefined
  32569. if (charcode <= 0) {
  32570. charcode = glyphUnicode;
  32571. }
  32572. // trying to get width via charcode
  32573. width = this.widths[charcode];
  32574. if (width) {
  32575. break; // the non-zero width found
  32576. }
  32577. }
  32578. width = width || this.defaultWidth;
  32579. // Do not shadow the property here. See discussion:
  32580. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  32581. this._shadowWidth = width;
  32582. return width;
  32583. },
  32584. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  32585. var fontCharCode, width, operatorListId;
  32586. var widthCode = charcode;
  32587. if (this.cMap && this.cMap.contains(charcode)) {
  32588. widthCode = this.cMap.lookup(charcode);
  32589. }
  32590. width = this.widths[widthCode];
  32591. width = isNum(width) ? width : this.defaultWidth;
  32592. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  32593. var unicode = this.toUnicode.get(charcode) || charcode;
  32594. if (typeof unicode === 'number') {
  32595. unicode = String.fromCharCode(unicode);
  32596. }
  32597. var isInFont = charcode in this.toFontChar;
  32598. // First try the toFontChar map, if it's not there then try falling
  32599. // back to the char code.
  32600. fontCharCode = this.toFontChar[charcode] || charcode;
  32601. if (this.missingFile) {
  32602. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  32603. }
  32604. if (this.isType3Font) {
  32605. // Font char code in this case is actually a glyph name.
  32606. operatorListId = fontCharCode;
  32607. }
  32608. var accent = null;
  32609. if (this.seacMap && this.seacMap[charcode]) {
  32610. isInFont = true;
  32611. var seac = this.seacMap[charcode];
  32612. fontCharCode = seac.baseFontCharCode;
  32613. accent = {
  32614. fontChar: String.fromCharCode(seac.accentFontCharCode),
  32615. offset: seac.accentOffset
  32616. };
  32617. }
  32618. var fontChar = String.fromCharCode(fontCharCode);
  32619. var glyph = this.glyphCache[charcode];
  32620. if (!glyph ||
  32621. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  32622. operatorListId, isSpace, isInFont)) {
  32623. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  32624. operatorListId, isSpace, isInFont);
  32625. this.glyphCache[charcode] = glyph;
  32626. }
  32627. return glyph;
  32628. },
  32629. charsToGlyphs: function Font_charsToGlyphs(chars) {
  32630. var charsCache = this.charsCache;
  32631. var glyphs, glyph, charcode;
  32632. // if we translated this string before, just grab it from the cache
  32633. if (charsCache) {
  32634. glyphs = charsCache[chars];
  32635. if (glyphs) {
  32636. return glyphs;
  32637. }
  32638. }
  32639. // lazily create the translation cache
  32640. if (!charsCache) {
  32641. charsCache = this.charsCache = Object.create(null);
  32642. }
  32643. glyphs = [];
  32644. var charsCacheKey = chars;
  32645. var i = 0, ii;
  32646. if (this.cMap) {
  32647. // composite fonts have multi-byte strings convert the string from
  32648. // single-byte to multi-byte
  32649. var c = Object.create(null);
  32650. while (i < chars.length) {
  32651. this.cMap.readCharCode(chars, i, c);
  32652. charcode = c.charcode;
  32653. var length = c.length;
  32654. i += length;
  32655. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  32656. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  32657. glyph = this.charToGlyph(charcode, isSpace);
  32658. glyphs.push(glyph);
  32659. }
  32660. } else {
  32661. for (i = 0, ii = chars.length; i < ii; ++i) {
  32662. charcode = chars.charCodeAt(i);
  32663. glyph = this.charToGlyph(charcode, charcode === 0x20);
  32664. glyphs.push(glyph);
  32665. }
  32666. }
  32667. // Enter the translated string into the cache
  32668. return (charsCache[charsCacheKey] = glyphs);
  32669. }
  32670. };
  32671. return Font;
  32672. })();
  32673. var ErrorFont = (function ErrorFontClosure() {
  32674. function ErrorFont(error) {
  32675. this.error = error;
  32676. this.loadedName = 'g_font_error';
  32677. this.loading = false;
  32678. }
  32679. ErrorFont.prototype = {
  32680. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  32681. return [];
  32682. },
  32683. exportData: function ErrorFont_exportData() {
  32684. return {error: this.error};
  32685. }
  32686. };
  32687. return ErrorFont;
  32688. })();
  32689. /**
  32690. * Shared logic for building a char code to glyph id mapping for Type1 and
  32691. * simple CFF fonts. See section 9.6.6.2 of the spec.
  32692. * @param {Object} properties Font properties object.
  32693. * @param {Object} builtInEncoding The encoding contained within the actual font
  32694. * data.
  32695. * @param {Array} glyphNames Array of glyph names where the index is the
  32696. * glyph ID.
  32697. * @returns {Object} A char code to glyph ID map.
  32698. */
  32699. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  32700. var charCodeToGlyphId = Object.create(null);
  32701. var glyphId, charCode, baseEncoding;
  32702. if (properties.baseEncodingName) {
  32703. // If a valid base encoding name was used, the mapping is initialized with
  32704. // that.
  32705. baseEncoding = getEncoding(properties.baseEncodingName);
  32706. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32707. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32708. if (glyphId >= 0) {
  32709. charCodeToGlyphId[charCode] = glyphId;
  32710. } else {
  32711. charCodeToGlyphId[charCode] = 0; // notdef
  32712. }
  32713. }
  32714. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  32715. // For a symbolic font the encoding should be the fonts built-in
  32716. // encoding.
  32717. for (charCode in builtInEncoding) {
  32718. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  32719. }
  32720. } else {
  32721. // For non-symbolic fonts that don't have a base encoding the standard
  32722. // encoding should be used.
  32723. baseEncoding = StandardEncoding;
  32724. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32725. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32726. if (glyphId >= 0) {
  32727. charCodeToGlyphId[charCode] = glyphId;
  32728. } else {
  32729. charCodeToGlyphId[charCode] = 0; // notdef
  32730. }
  32731. }
  32732. }
  32733. // Lastly, merge in the differences.
  32734. var differences = properties.differences, glyphsUnicodeMap;
  32735. if (differences) {
  32736. for (charCode in differences) {
  32737. var glyphName = differences[charCode];
  32738. glyphId = glyphNames.indexOf(glyphName);
  32739. if (glyphId === -1) {
  32740. if (!glyphsUnicodeMap) {
  32741. glyphsUnicodeMap = getGlyphsUnicode();
  32742. }
  32743. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32744. if (standardGlyphName !== glyphName) {
  32745. glyphId = glyphNames.indexOf(standardGlyphName);
  32746. }
  32747. }
  32748. if (glyphId >= 0) {
  32749. charCodeToGlyphId[charCode] = glyphId;
  32750. } else {
  32751. charCodeToGlyphId[charCode] = 0; // notdef
  32752. }
  32753. }
  32754. }
  32755. return charCodeToGlyphId;
  32756. }
  32757. // Type1Font is also a CIDFontType0.
  32758. var Type1Font = (function Type1FontClosure() {
  32759. function findBlock(streamBytes, signature, startIndex) {
  32760. var streamBytesLength = streamBytes.length;
  32761. var signatureLength = signature.length;
  32762. var scanLength = streamBytesLength - signatureLength;
  32763. var i = startIndex, j, found = false;
  32764. while (i < scanLength) {
  32765. j = 0;
  32766. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  32767. j++;
  32768. }
  32769. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  32770. i += j;
  32771. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  32772. i++;
  32773. }
  32774. found = true;
  32775. break;
  32776. }
  32777. i++;
  32778. }
  32779. return {
  32780. found: found,
  32781. length: i,
  32782. };
  32783. }
  32784. function getHeaderBlock(stream, suggestedLength) {
  32785. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  32786. var streamStartPos = stream.pos; // Save the initial stream position.
  32787. var headerBytes, headerBytesLength, block;
  32788. try {
  32789. headerBytes = stream.getBytes(suggestedLength);
  32790. headerBytesLength = headerBytes.length;
  32791. } catch (ex) {
  32792. if (ex instanceof MissingDataException) {
  32793. throw ex;
  32794. }
  32795. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  32796. // cannot hold the result of `getBytes`, and fallback to simply checking
  32797. // the entire stream (fixes issue3928.pdf).
  32798. }
  32799. if (headerBytesLength === suggestedLength) {
  32800. // Most of the time `suggestedLength` is correct, so to speed things up we
  32801. // initially only check the last few bytes to see if the header was found.
  32802. // Otherwise we (potentially) check the entire stream to prevent errors in
  32803. // `Type1Parser` (fixes issue5686.pdf).
  32804. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  32805. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  32806. if (block.found && block.length === suggestedLength) {
  32807. return {
  32808. stream: new Stream(headerBytes),
  32809. length: suggestedLength,
  32810. };
  32811. }
  32812. }
  32813. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  32814. stream.pos = streamStartPos; // Reset the stream position.
  32815. var SCAN_BLOCK_LENGTH = 2048;
  32816. var actualLength;
  32817. while (true) {
  32818. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  32819. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  32820. if (block.length === 0) {
  32821. break;
  32822. }
  32823. stream.pos += block.length; // Update the stream position.
  32824. if (block.found) {
  32825. actualLength = stream.pos - streamStartPos;
  32826. break;
  32827. }
  32828. }
  32829. stream.pos = streamStartPos; // Reset the stream position.
  32830. if (actualLength) {
  32831. return {
  32832. stream: new Stream(stream.getBytes(actualLength)),
  32833. length: actualLength,
  32834. };
  32835. }
  32836. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  32837. return {
  32838. stream: new Stream(stream.getBytes(suggestedLength)),
  32839. length: suggestedLength,
  32840. };
  32841. }
  32842. function getEexecBlock(stream, suggestedLength) {
  32843. // We should ideally parse the eexec block to ensure that `suggestedLength`
  32844. // is correct, so we don't truncate the block data if it's too small.
  32845. // However, this would also require checking if the fixed-content portion
  32846. // exists (using the 'Length3' property), and ensuring that it's valid.
  32847. //
  32848. // Given that `suggestedLength` almost always is correct, all the validation
  32849. // would require a great deal of unnecessary parsing for most fonts.
  32850. // To save time, we always fetch the entire stream instead, which also avoid
  32851. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  32852. //
  32853. // NOTE: This means that the function can include the fixed-content portion
  32854. // in the returned eexec block. In practice this does *not* seem to matter,
  32855. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  32856. var eexecBytes = stream.getBytes();
  32857. return {
  32858. stream: new Stream(eexecBytes),
  32859. length: eexecBytes.length,
  32860. };
  32861. }
  32862. function Type1Font(name, file, properties) {
  32863. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  32864. // Also, length1 and length2 might be off by 6 bytes as well.
  32865. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  32866. var PFB_HEADER_SIZE = 6;
  32867. var headerBlockLength = properties.length1;
  32868. var eexecBlockLength = properties.length2;
  32869. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  32870. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  32871. if (pfbHeaderPresent) {
  32872. file.skip(PFB_HEADER_SIZE);
  32873. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  32874. (pfbHeader[3] << 8) | pfbHeader[2];
  32875. }
  32876. // Get the data block containing glyphs and subrs information
  32877. var headerBlock = getHeaderBlock(file, headerBlockLength);
  32878. headerBlockLength = headerBlock.length;
  32879. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  32880. SEAC_ANALYSIS_ENABLED);
  32881. headerBlockParser.extractFontHeader(properties);
  32882. if (pfbHeaderPresent) {
  32883. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  32884. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  32885. (pfbHeader[3] << 8) | pfbHeader[2];
  32886. }
  32887. // Decrypt the data blocks and retrieve it's content
  32888. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  32889. eexecBlockLength = eexecBlock.length;
  32890. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  32891. SEAC_ANALYSIS_ENABLED);
  32892. var data = eexecBlockParser.extractFontProgram();
  32893. for (var info in data.properties) {
  32894. properties[info] = data.properties[info];
  32895. }
  32896. var charstrings = data.charstrings;
  32897. var type2Charstrings = this.getType2Charstrings(charstrings);
  32898. var subrs = this.getType2Subrs(data.subrs);
  32899. this.charstrings = charstrings;
  32900. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  32901. subrs, properties);
  32902. this.seacs = this.getSeacs(data.charstrings);
  32903. }
  32904. Type1Font.prototype = {
  32905. get numGlyphs() {
  32906. return this.charstrings.length + 1;
  32907. },
  32908. getCharset: function Type1Font_getCharset() {
  32909. var charset = ['.notdef'];
  32910. var charstrings = this.charstrings;
  32911. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  32912. charset.push(charstrings[glyphId].glyphName);
  32913. }
  32914. return charset;
  32915. },
  32916. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  32917. var charstrings = this.charstrings;
  32918. var glyphNames = ['.notdef'], glyphId;
  32919. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  32920. glyphNames.push(charstrings[glyphId].glyphName);
  32921. }
  32922. var encoding = properties.builtInEncoding;
  32923. if (encoding) {
  32924. var builtInEncoding = Object.create(null);
  32925. for (var charCode in encoding) {
  32926. glyphId = glyphNames.indexOf(encoding[charCode]);
  32927. if (glyphId >= 0) {
  32928. builtInEncoding[charCode] = glyphId;
  32929. }
  32930. }
  32931. }
  32932. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  32933. },
  32934. getSeacs: function Type1Font_getSeacs(charstrings) {
  32935. var i, ii;
  32936. var seacMap = [];
  32937. for (i = 0, ii = charstrings.length; i < ii; i++) {
  32938. var charstring = charstrings[i];
  32939. if (charstring.seac) {
  32940. // Offset by 1 for .notdef
  32941. seacMap[i + 1] = charstring.seac;
  32942. }
  32943. }
  32944. return seacMap;
  32945. },
  32946. getType2Charstrings: function Type1Font_getType2Charstrings(
  32947. type1Charstrings) {
  32948. var type2Charstrings = [];
  32949. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  32950. type2Charstrings.push(type1Charstrings[i].charstring);
  32951. }
  32952. return type2Charstrings;
  32953. },
  32954. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  32955. var bias = 0;
  32956. var count = type1Subrs.length;
  32957. if (count < 1133) {
  32958. bias = 107;
  32959. } else if (count < 33769) {
  32960. bias = 1131;
  32961. } else {
  32962. bias = 32768;
  32963. }
  32964. // Add a bunch of empty subrs to deal with the Type2 bias
  32965. var type2Subrs = [];
  32966. var i;
  32967. for (i = 0; i < bias; i++) {
  32968. type2Subrs.push([0x0B]);
  32969. }
  32970. for (i = 0; i < count; i++) {
  32971. type2Subrs.push(type1Subrs[i]);
  32972. }
  32973. return type2Subrs;
  32974. },
  32975. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  32976. properties) {
  32977. var cff = new CFF();
  32978. cff.header = new CFFHeader(1, 0, 4, 4);
  32979. cff.names = [name];
  32980. var topDict = new CFFTopDict();
  32981. // CFF strings IDs 0...390 are predefined names, so refering
  32982. // to entries in our own String INDEX starts at SID 391.
  32983. topDict.setByName('version', 391);
  32984. topDict.setByName('Notice', 392);
  32985. topDict.setByName('FullName', 393);
  32986. topDict.setByName('FamilyName', 394);
  32987. topDict.setByName('Weight', 395);
  32988. topDict.setByName('Encoding', null); // placeholder
  32989. topDict.setByName('FontMatrix', properties.fontMatrix);
  32990. topDict.setByName('FontBBox', properties.bbox);
  32991. topDict.setByName('charset', null); // placeholder
  32992. topDict.setByName('CharStrings', null); // placeholder
  32993. topDict.setByName('Private', null); // placeholder
  32994. cff.topDict = topDict;
  32995. var strings = new CFFStrings();
  32996. strings.add('Version 0.11'); // Version
  32997. strings.add('See original notice'); // Notice
  32998. strings.add(name); // FullName
  32999. strings.add(name); // FamilyName
  33000. strings.add('Medium'); // Weight
  33001. cff.strings = strings;
  33002. cff.globalSubrIndex = new CFFIndex();
  33003. var count = glyphs.length;
  33004. var charsetArray = [0];
  33005. var i, ii;
  33006. for (i = 0; i < count; i++) {
  33007. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  33008. // TODO: Insert the string and correctly map it. Previously it was
  33009. // thought mapping names that aren't in the standard strings to .notdef
  33010. // was fine, however in issue818 when mapping them all to .notdef the
  33011. // adieresis glyph no longer worked.
  33012. if (index === -1) {
  33013. index = 0;
  33014. }
  33015. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  33016. }
  33017. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  33018. var charStringsIndex = new CFFIndex();
  33019. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  33020. for (i = 0; i < count; i++) {
  33021. charStringsIndex.add(glyphs[i]);
  33022. }
  33023. cff.charStrings = charStringsIndex;
  33024. var privateDict = new CFFPrivateDict();
  33025. privateDict.setByName('Subrs', null); // placeholder
  33026. var fields = [
  33027. 'BlueValues',
  33028. 'OtherBlues',
  33029. 'FamilyBlues',
  33030. 'FamilyOtherBlues',
  33031. 'StemSnapH',
  33032. 'StemSnapV',
  33033. 'BlueShift',
  33034. 'BlueFuzz',
  33035. 'BlueScale',
  33036. 'LanguageGroup',
  33037. 'ExpansionFactor',
  33038. 'ForceBold',
  33039. 'StdHW',
  33040. 'StdVW'
  33041. ];
  33042. for (i = 0, ii = fields.length; i < ii; i++) {
  33043. var field = fields[i];
  33044. if (!(field in properties.privateData)) {
  33045. continue;
  33046. }
  33047. var value = properties.privateData[field];
  33048. if (isArray(value)) {
  33049. // All of the private dictionary array data in CFF must be stored as
  33050. // "delta-encoded" numbers.
  33051. for (var j = value.length - 1; j > 0; j--) {
  33052. value[j] -= value[j - 1]; // ... difference from previous value
  33053. }
  33054. }
  33055. privateDict.setByName(field, value);
  33056. }
  33057. cff.topDict.privateDict = privateDict;
  33058. var subrIndex = new CFFIndex();
  33059. for (i = 0, ii = subrs.length; i < ii; i++) {
  33060. subrIndex.add(subrs[i]);
  33061. }
  33062. privateDict.subrsIndex = subrIndex;
  33063. var compiler = new CFFCompiler(cff);
  33064. return compiler.compile();
  33065. }
  33066. };
  33067. return Type1Font;
  33068. })();
  33069. var CFFFont = (function CFFFontClosure() {
  33070. function CFFFont(file, properties) {
  33071. this.properties = properties;
  33072. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  33073. this.cff = parser.parse();
  33074. var compiler = new CFFCompiler(this.cff);
  33075. this.seacs = this.cff.seacs;
  33076. try {
  33077. this.data = compiler.compile();
  33078. } catch (e) {
  33079. warn('Failed to compile font ' + properties.loadedName);
  33080. // There may have just been an issue with the compiler, set the data
  33081. // anyway and hope the font loaded.
  33082. this.data = file;
  33083. }
  33084. }
  33085. CFFFont.prototype = {
  33086. get numGlyphs() {
  33087. return this.cff.charStrings.count;
  33088. },
  33089. getCharset: function CFFFont_getCharset() {
  33090. return this.cff.charset.charset;
  33091. },
  33092. getGlyphMapping: function CFFFont_getGlyphMapping() {
  33093. var cff = this.cff;
  33094. var properties = this.properties;
  33095. var charsets = cff.charset.charset;
  33096. var charCodeToGlyphId;
  33097. var glyphId;
  33098. if (properties.composite) {
  33099. charCodeToGlyphId = Object.create(null);
  33100. if (cff.isCIDFont) {
  33101. // If the font is actually a CID font then we should use the charset
  33102. // to map CIDs to GIDs.
  33103. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  33104. var cid = charsets[glyphId];
  33105. var charCode = properties.cMap.charCodeOf(cid);
  33106. charCodeToGlyphId[charCode] = glyphId;
  33107. }
  33108. } else {
  33109. // If it is NOT actually a CID font then CIDs should be mapped
  33110. // directly to GIDs.
  33111. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  33112. charCodeToGlyphId[glyphId] = glyphId;
  33113. }
  33114. }
  33115. return charCodeToGlyphId;
  33116. }
  33117. var encoding = cff.encoding ? cff.encoding.encoding : null;
  33118. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  33119. return charCodeToGlyphId;
  33120. }
  33121. };
  33122. return CFFFont;
  33123. })();
  33124. // Workaround for seac on Windows.
  33125. (function checkSeacSupport() {
  33126. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  33127. SEAC_ANALYSIS_ENABLED = true;
  33128. }
  33129. })();
  33130. // Workaround for Private Use Area characters in Chrome on Windows
  33131. // http://code.google.com/p/chromium/issues/detail?id=122465
  33132. // https://github.com/mozilla/pdf.js/issues/1689
  33133. (function checkChromeWindows() {
  33134. if (typeof navigator !== 'undefined' &&
  33135. /Windows.*Chrome/.test(navigator.userAgent)) {
  33136. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  33137. }
  33138. })();
  33139. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  33140. exports.ErrorFont = ErrorFont;
  33141. exports.Font = Font;
  33142. exports.FontFlags = FontFlags;
  33143. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  33144. exports.ToUnicodeMap = ToUnicodeMap;
  33145. exports.getFontType = getFontType;
  33146. }));
  33147. (function (root, factory) {
  33148. {
  33149. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  33150. root.pdfjsCoreParser);
  33151. }
  33152. }(this, function (exports, sharedUtil, coreParser) {
  33153. var error = sharedUtil.error;
  33154. var isSpace = sharedUtil.isSpace;
  33155. var EOF = coreParser.EOF;
  33156. var PostScriptParser = (function PostScriptParserClosure() {
  33157. function PostScriptParser(lexer) {
  33158. this.lexer = lexer;
  33159. this.operators = [];
  33160. this.token = null;
  33161. this.prev = null;
  33162. }
  33163. PostScriptParser.prototype = {
  33164. nextToken: function PostScriptParser_nextToken() {
  33165. this.prev = this.token;
  33166. this.token = this.lexer.getToken();
  33167. },
  33168. accept: function PostScriptParser_accept(type) {
  33169. if (this.token.type === type) {
  33170. this.nextToken();
  33171. return true;
  33172. }
  33173. return false;
  33174. },
  33175. expect: function PostScriptParser_expect(type) {
  33176. if (this.accept(type)) {
  33177. return true;
  33178. }
  33179. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  33180. type + '.');
  33181. },
  33182. parse: function PostScriptParser_parse() {
  33183. this.nextToken();
  33184. this.expect(PostScriptTokenTypes.LBRACE);
  33185. this.parseBlock();
  33186. this.expect(PostScriptTokenTypes.RBRACE);
  33187. return this.operators;
  33188. },
  33189. parseBlock: function PostScriptParser_parseBlock() {
  33190. while (true) {
  33191. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  33192. this.operators.push(this.prev.value);
  33193. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  33194. this.operators.push(this.prev.value);
  33195. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33196. this.parseCondition();
  33197. } else {
  33198. return;
  33199. }
  33200. }
  33201. },
  33202. parseCondition: function PostScriptParser_parseCondition() {
  33203. // Add two place holders that will be updated later
  33204. var conditionLocation = this.operators.length;
  33205. this.operators.push(null, null);
  33206. this.parseBlock();
  33207. this.expect(PostScriptTokenTypes.RBRACE);
  33208. if (this.accept(PostScriptTokenTypes.IF)) {
  33209. // The true block is right after the 'if' so it just falls through on
  33210. // true else it jumps and skips the true block.
  33211. this.operators[conditionLocation] = this.operators.length;
  33212. this.operators[conditionLocation + 1] = 'jz';
  33213. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33214. var jumpLocation = this.operators.length;
  33215. this.operators.push(null, null);
  33216. var endOfTrue = this.operators.length;
  33217. this.parseBlock();
  33218. this.expect(PostScriptTokenTypes.RBRACE);
  33219. this.expect(PostScriptTokenTypes.IFELSE);
  33220. // The jump is added at the end of the true block to skip the false
  33221. // block.
  33222. this.operators[jumpLocation] = this.operators.length;
  33223. this.operators[jumpLocation + 1] = 'j';
  33224. this.operators[conditionLocation] = endOfTrue;
  33225. this.operators[conditionLocation + 1] = 'jz';
  33226. } else {
  33227. error('PS Function: error parsing conditional.');
  33228. }
  33229. }
  33230. };
  33231. return PostScriptParser;
  33232. })();
  33233. var PostScriptTokenTypes = {
  33234. LBRACE: 0,
  33235. RBRACE: 1,
  33236. NUMBER: 2,
  33237. OPERATOR: 3,
  33238. IF: 4,
  33239. IFELSE: 5
  33240. };
  33241. var PostScriptToken = (function PostScriptTokenClosure() {
  33242. function PostScriptToken(type, value) {
  33243. this.type = type;
  33244. this.value = value;
  33245. }
  33246. var opCache = Object.create(null);
  33247. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  33248. var opValue = opCache[op];
  33249. if (opValue) {
  33250. return opValue;
  33251. }
  33252. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  33253. };
  33254. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  33255. '{');
  33256. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  33257. '}');
  33258. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  33259. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  33260. 'IFELSE');
  33261. return PostScriptToken;
  33262. })();
  33263. var PostScriptLexer = (function PostScriptLexerClosure() {
  33264. function PostScriptLexer(stream) {
  33265. this.stream = stream;
  33266. this.nextChar();
  33267. this.strBuf = [];
  33268. }
  33269. PostScriptLexer.prototype = {
  33270. nextChar: function PostScriptLexer_nextChar() {
  33271. return (this.currentChar = this.stream.getByte());
  33272. },
  33273. getToken: function PostScriptLexer_getToken() {
  33274. var comment = false;
  33275. var ch = this.currentChar;
  33276. // skip comments
  33277. while (true) {
  33278. if (ch < 0) {
  33279. return EOF;
  33280. }
  33281. if (comment) {
  33282. if (ch === 0x0A || ch === 0x0D) {
  33283. comment = false;
  33284. }
  33285. } else if (ch === 0x25) { // '%'
  33286. comment = true;
  33287. } else if (!isSpace(ch)) {
  33288. break;
  33289. }
  33290. ch = this.nextChar();
  33291. }
  33292. switch (ch | 0) {
  33293. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  33294. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  33295. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  33296. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  33297. this.getNumber());
  33298. case 0x7B: // '{'
  33299. this.nextChar();
  33300. return PostScriptToken.LBRACE;
  33301. case 0x7D: // '}'
  33302. this.nextChar();
  33303. return PostScriptToken.RBRACE;
  33304. }
  33305. // operator
  33306. var strBuf = this.strBuf;
  33307. strBuf.length = 0;
  33308. strBuf[0] = String.fromCharCode(ch);
  33309. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  33310. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  33311. strBuf.push(String.fromCharCode(ch));
  33312. }
  33313. var str = strBuf.join('');
  33314. switch (str.toLowerCase()) {
  33315. case 'if':
  33316. return PostScriptToken.IF;
  33317. case 'ifelse':
  33318. return PostScriptToken.IFELSE;
  33319. default:
  33320. return PostScriptToken.getOperator(str);
  33321. }
  33322. },
  33323. getNumber: function PostScriptLexer_getNumber() {
  33324. var ch = this.currentChar;
  33325. var strBuf = this.strBuf;
  33326. strBuf.length = 0;
  33327. strBuf[0] = String.fromCharCode(ch);
  33328. while ((ch = this.nextChar()) >= 0) {
  33329. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  33330. ch === 0x2D || ch === 0x2E) { // '-', '.'
  33331. strBuf.push(String.fromCharCode(ch));
  33332. } else {
  33333. break;
  33334. }
  33335. }
  33336. var value = parseFloat(strBuf.join(''));
  33337. if (isNaN(value)) {
  33338. error('Invalid floating point number: ' + value);
  33339. }
  33340. return value;
  33341. }
  33342. };
  33343. return PostScriptLexer;
  33344. })();
  33345. exports.PostScriptLexer = PostScriptLexer;
  33346. exports.PostScriptParser = PostScriptParser;
  33347. }));
  33348. (function (root, factory) {
  33349. {
  33350. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  33351. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper,
  33352. root.pdfjsDisplayWebGL);
  33353. }
  33354. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper,
  33355. displayWebGL) {
  33356. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33357. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33358. var ImageKind = sharedUtil.ImageKind;
  33359. var OPS = sharedUtil.OPS;
  33360. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33361. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  33362. var Util = sharedUtil.Util;
  33363. var assert = sharedUtil.assert;
  33364. var info = sharedUtil.info;
  33365. var isNum = sharedUtil.isNum;
  33366. var isArray = sharedUtil.isArray;
  33367. var isLittleEndian = sharedUtil.isLittleEndian;
  33368. var error = sharedUtil.error;
  33369. var shadow = sharedUtil.shadow;
  33370. var warn = sharedUtil.warn;
  33371. var TilingPattern = displayPatternHelper.TilingPattern;
  33372. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  33373. var WebGLUtils = displayWebGL.WebGLUtils;
  33374. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  33375. // <canvas> contexts store most of the state we need natively.
  33376. // However, PDF needs a bit more state, which we store here.
  33377. // Minimal font size that would be used during canvas fillText operations.
  33378. var MIN_FONT_SIZE = 16;
  33379. // Maximum font size that would be used during canvas fillText operations.
  33380. var MAX_FONT_SIZE = 100;
  33381. var MAX_GROUP_SIZE = 4096;
  33382. // Heuristic value used when enforcing minimum line widths.
  33383. var MIN_WIDTH_FACTOR = 0.65;
  33384. var COMPILE_TYPE3_GLYPHS = true;
  33385. var MAX_SIZE_TO_COMPILE = 1000;
  33386. var FULL_CHUNK_HEIGHT = 16;
  33387. var HasCanvasTypedArraysCached = {
  33388. get value() {
  33389. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  33390. }
  33391. };
  33392. var IsLittleEndianCached = {
  33393. get value() {
  33394. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  33395. }
  33396. };
  33397. function createScratchCanvas(width, height) {
  33398. var canvas = document.createElement('canvas');
  33399. canvas.width = width;
  33400. canvas.height = height;
  33401. return canvas;
  33402. }
  33403. function addContextCurrentTransform(ctx) {
  33404. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  33405. if (!ctx.mozCurrentTransform) {
  33406. ctx._originalSave = ctx.save;
  33407. ctx._originalRestore = ctx.restore;
  33408. ctx._originalRotate = ctx.rotate;
  33409. ctx._originalScale = ctx.scale;
  33410. ctx._originalTranslate = ctx.translate;
  33411. ctx._originalTransform = ctx.transform;
  33412. ctx._originalSetTransform = ctx.setTransform;
  33413. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  33414. ctx._transformStack = [];
  33415. Object.defineProperty(ctx, 'mozCurrentTransform', {
  33416. get: function getCurrentTransform() {
  33417. return this._transformMatrix;
  33418. }
  33419. });
  33420. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  33421. get: function getCurrentTransformInverse() {
  33422. // Calculation done using WolframAlpha:
  33423. // http://www.wolframalpha.com/input/?
  33424. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  33425. var m = this._transformMatrix;
  33426. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  33427. var ad_bc = a * d - b * c;
  33428. var bc_ad = b * c - a * d;
  33429. return [
  33430. d / ad_bc,
  33431. b / bc_ad,
  33432. c / bc_ad,
  33433. a / ad_bc,
  33434. (d * e - c * f) / bc_ad,
  33435. (b * e - a * f) / ad_bc
  33436. ];
  33437. }
  33438. });
  33439. ctx.save = function ctxSave() {
  33440. var old = this._transformMatrix;
  33441. this._transformStack.push(old);
  33442. this._transformMatrix = old.slice(0, 6);
  33443. this._originalSave();
  33444. };
  33445. ctx.restore = function ctxRestore() {
  33446. var prev = this._transformStack.pop();
  33447. if (prev) {
  33448. this._transformMatrix = prev;
  33449. this._originalRestore();
  33450. }
  33451. };
  33452. ctx.translate = function ctxTranslate(x, y) {
  33453. var m = this._transformMatrix;
  33454. m[4] = m[0] * x + m[2] * y + m[4];
  33455. m[5] = m[1] * x + m[3] * y + m[5];
  33456. this._originalTranslate(x, y);
  33457. };
  33458. ctx.scale = function ctxScale(x, y) {
  33459. var m = this._transformMatrix;
  33460. m[0] = m[0] * x;
  33461. m[1] = m[1] * x;
  33462. m[2] = m[2] * y;
  33463. m[3] = m[3] * y;
  33464. this._originalScale(x, y);
  33465. };
  33466. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  33467. var m = this._transformMatrix;
  33468. this._transformMatrix = [
  33469. m[0] * a + m[2] * b,
  33470. m[1] * a + m[3] * b,
  33471. m[0] * c + m[2] * d,
  33472. m[1] * c + m[3] * d,
  33473. m[0] * e + m[2] * f + m[4],
  33474. m[1] * e + m[3] * f + m[5]
  33475. ];
  33476. ctx._originalTransform(a, b, c, d, e, f);
  33477. };
  33478. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  33479. this._transformMatrix = [a, b, c, d, e, f];
  33480. ctx._originalSetTransform(a, b, c, d, e, f);
  33481. };
  33482. ctx.rotate = function ctxRotate(angle) {
  33483. var cosValue = Math.cos(angle);
  33484. var sinValue = Math.sin(angle);
  33485. var m = this._transformMatrix;
  33486. this._transformMatrix = [
  33487. m[0] * cosValue + m[2] * sinValue,
  33488. m[1] * cosValue + m[3] * sinValue,
  33489. m[0] * (-sinValue) + m[2] * cosValue,
  33490. m[1] * (-sinValue) + m[3] * cosValue,
  33491. m[4],
  33492. m[5]
  33493. ];
  33494. this._originalRotate(angle);
  33495. };
  33496. }
  33497. }
  33498. var CachedCanvases = (function CachedCanvasesClosure() {
  33499. function CachedCanvases() {
  33500. this.cache = Object.create(null);
  33501. }
  33502. CachedCanvases.prototype = {
  33503. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  33504. trackTransform) {
  33505. var canvasEntry;
  33506. if (this.cache[id] !== undefined) {
  33507. canvasEntry = this.cache[id];
  33508. canvasEntry.canvas.width = width;
  33509. canvasEntry.canvas.height = height;
  33510. // reset canvas transform for emulated mozCurrentTransform, if needed
  33511. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  33512. } else {
  33513. var canvas = createScratchCanvas(width, height);
  33514. var ctx = canvas.getContext('2d');
  33515. if (trackTransform) {
  33516. addContextCurrentTransform(ctx);
  33517. }
  33518. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  33519. }
  33520. return canvasEntry;
  33521. },
  33522. clear: function () {
  33523. for (var id in this.cache) {
  33524. var canvasEntry = this.cache[id];
  33525. // Zeroing the width and height causes Firefox to release graphics
  33526. // resources immediately, which can greatly reduce memory consumption.
  33527. canvasEntry.canvas.width = 0;
  33528. canvasEntry.canvas.height = 0;
  33529. delete this.cache[id];
  33530. }
  33531. }
  33532. };
  33533. return CachedCanvases;
  33534. })();
  33535. function compileType3Glyph(imgData) {
  33536. var POINT_TO_PROCESS_LIMIT = 1000;
  33537. var width = imgData.width, height = imgData.height;
  33538. var i, j, j0, width1 = width + 1;
  33539. var points = new Uint8Array(width1 * (height + 1));
  33540. var POINT_TYPES =
  33541. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  33542. // decodes bit-packed mask data
  33543. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  33544. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  33545. for (i = 0, ii = data0.length; i < ii; i++) {
  33546. var mask = 128, elem = data0[i];
  33547. while (mask > 0) {
  33548. data[pos++] = (elem & mask) ? 0 : 255;
  33549. mask >>= 1;
  33550. }
  33551. }
  33552. // finding iteresting points: every point is located between mask pixels,
  33553. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  33554. // will have flags assigned based on neighboring mask pixels:
  33555. // 4 | 8
  33556. // --P--
  33557. // 2 | 1
  33558. // We are interested only in points with the flags:
  33559. // - outside corners: 1, 2, 4, 8;
  33560. // - inside corners: 7, 11, 13, 14;
  33561. // - and, intersections: 5, 10.
  33562. var count = 0;
  33563. pos = 0;
  33564. if (data[pos] !== 0) {
  33565. points[0] = 1;
  33566. ++count;
  33567. }
  33568. for (j = 1; j < width; j++) {
  33569. if (data[pos] !== data[pos + 1]) {
  33570. points[j] = data[pos] ? 2 : 1;
  33571. ++count;
  33572. }
  33573. pos++;
  33574. }
  33575. if (data[pos] !== 0) {
  33576. points[j] = 2;
  33577. ++count;
  33578. }
  33579. for (i = 1; i < height; i++) {
  33580. pos = i * lineSize;
  33581. j0 = i * width1;
  33582. if (data[pos - lineSize] !== data[pos]) {
  33583. points[j0] = data[pos] ? 1 : 8;
  33584. ++count;
  33585. }
  33586. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  33587. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  33588. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  33589. for (j = 1; j < width; j++) {
  33590. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  33591. (data[pos - lineSize + 1] ? 8 : 0);
  33592. if (POINT_TYPES[sum]) {
  33593. points[j0 + j] = POINT_TYPES[sum];
  33594. ++count;
  33595. }
  33596. pos++;
  33597. }
  33598. if (data[pos - lineSize] !== data[pos]) {
  33599. points[j0 + j] = data[pos] ? 2 : 4;
  33600. ++count;
  33601. }
  33602. if (count > POINT_TO_PROCESS_LIMIT) {
  33603. return null;
  33604. }
  33605. }
  33606. pos = lineSize * (height - 1);
  33607. j0 = i * width1;
  33608. if (data[pos] !== 0) {
  33609. points[j0] = 8;
  33610. ++count;
  33611. }
  33612. for (j = 1; j < width; j++) {
  33613. if (data[pos] !== data[pos + 1]) {
  33614. points[j0 + j] = data[pos] ? 4 : 8;
  33615. ++count;
  33616. }
  33617. pos++;
  33618. }
  33619. if (data[pos] !== 0) {
  33620. points[j0 + j] = 4;
  33621. ++count;
  33622. }
  33623. if (count > POINT_TO_PROCESS_LIMIT) {
  33624. return null;
  33625. }
  33626. // building outlines
  33627. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  33628. var outlines = [];
  33629. for (i = 0; count && i <= height; i++) {
  33630. var p = i * width1;
  33631. var end = p + width;
  33632. while (p < end && !points[p]) {
  33633. p++;
  33634. }
  33635. if (p === end) {
  33636. continue;
  33637. }
  33638. var coords = [p % width1, i];
  33639. var type = points[p], p0 = p, pp;
  33640. do {
  33641. var step = steps[type];
  33642. do {
  33643. p += step;
  33644. } while (!points[p]);
  33645. pp = points[p];
  33646. if (pp !== 5 && pp !== 10) {
  33647. // set new direction
  33648. type = pp;
  33649. // delete mark
  33650. points[p] = 0;
  33651. } else { // type is 5 or 10, ie, a crossing
  33652. // set new direction
  33653. type = pp & ((0x33 * type) >> 4);
  33654. // set new type for "future hit"
  33655. points[p] &= (type >> 2 | type << 2);
  33656. }
  33657. coords.push(p % width1);
  33658. coords.push((p / width1) | 0);
  33659. --count;
  33660. } while (p0 !== p);
  33661. outlines.push(coords);
  33662. --i;
  33663. }
  33664. var drawOutline = function(c) {
  33665. c.save();
  33666. // the path shall be painted in [0..1]x[0..1] space
  33667. c.scale(1 / width, -1 / height);
  33668. c.translate(0, -height);
  33669. c.beginPath();
  33670. for (var i = 0, ii = outlines.length; i < ii; i++) {
  33671. var o = outlines[i];
  33672. c.moveTo(o[0], o[1]);
  33673. for (var j = 2, jj = o.length; j < jj; j += 2) {
  33674. c.lineTo(o[j], o[j+1]);
  33675. }
  33676. }
  33677. c.fill();
  33678. c.beginPath();
  33679. c.restore();
  33680. };
  33681. return drawOutline;
  33682. }
  33683. var CanvasExtraState = (function CanvasExtraStateClosure() {
  33684. function CanvasExtraState(old) {
  33685. // Are soft masks and alpha values shapes or opacities?
  33686. this.alphaIsShape = false;
  33687. this.fontSize = 0;
  33688. this.fontSizeScale = 1;
  33689. this.textMatrix = IDENTITY_MATRIX;
  33690. this.textMatrixScale = 1;
  33691. this.fontMatrix = FONT_IDENTITY_MATRIX;
  33692. this.leading = 0;
  33693. // Current point (in user coordinates)
  33694. this.x = 0;
  33695. this.y = 0;
  33696. // Start of text line (in text coordinates)
  33697. this.lineX = 0;
  33698. this.lineY = 0;
  33699. // Character and word spacing
  33700. this.charSpacing = 0;
  33701. this.wordSpacing = 0;
  33702. this.textHScale = 1;
  33703. this.textRenderingMode = TextRenderingMode.FILL;
  33704. this.textRise = 0;
  33705. // Default fore and background colors
  33706. this.fillColor = '#000000';
  33707. this.strokeColor = '#000000';
  33708. this.patternFill = false;
  33709. // Note: fill alpha applies to all non-stroking operations
  33710. this.fillAlpha = 1;
  33711. this.strokeAlpha = 1;
  33712. this.lineWidth = 1;
  33713. this.activeSMask = null;
  33714. this.resumeSMaskCtx = null; // nonclonable field (see the save method below)
  33715. this.old = old;
  33716. }
  33717. CanvasExtraState.prototype = {
  33718. clone: function CanvasExtraState_clone() {
  33719. return Object.create(this);
  33720. },
  33721. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  33722. this.x = x;
  33723. this.y = y;
  33724. }
  33725. };
  33726. return CanvasExtraState;
  33727. })();
  33728. var CanvasGraphics = (function CanvasGraphicsClosure() {
  33729. // Defines the time the executeOperatorList is going to be executing
  33730. // before it stops and shedules a continue of execution.
  33731. var EXECUTION_TIME = 15;
  33732. // Defines the number of steps before checking the execution time
  33733. var EXECUTION_STEPS = 10;
  33734. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  33735. this.ctx = canvasCtx;
  33736. this.current = new CanvasExtraState();
  33737. this.stateStack = [];
  33738. this.pendingClip = null;
  33739. this.pendingEOFill = false;
  33740. this.res = null;
  33741. this.xobjs = null;
  33742. this.commonObjs = commonObjs;
  33743. this.objs = objs;
  33744. this.imageLayer = imageLayer;
  33745. this.groupStack = [];
  33746. this.processingType3 = null;
  33747. // Patterns are painted relative to the initial page/form transform, see pdf
  33748. // spec 8.7.2 NOTE 1.
  33749. this.baseTransform = null;
  33750. this.baseTransformStack = [];
  33751. this.groupLevel = 0;
  33752. this.smaskStack = [];
  33753. this.smaskCounter = 0;
  33754. this.tempSMask = null;
  33755. this.cachedCanvases = new CachedCanvases();
  33756. if (canvasCtx) {
  33757. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  33758. // the transformation must already be set in canvasCtx._transformMatrix.
  33759. addContextCurrentTransform(canvasCtx);
  33760. }
  33761. this.cachedGetSinglePixelWidth = null;
  33762. }
  33763. function putBinaryImageData(ctx, imgData) {
  33764. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  33765. ctx.putImageData(imgData, 0, 0);
  33766. return;
  33767. }
  33768. // Put the image data to the canvas in chunks, rather than putting the
  33769. // whole image at once. This saves JS memory, because the ImageData object
  33770. // is smaller. It also possibly saves C++ memory within the implementation
  33771. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  33772. // the data passed to putImageData()). |n| shouldn't be too small, however,
  33773. // because too many putImageData() calls will slow things down.
  33774. //
  33775. // Note: as written, if the last chunk is partial, the putImageData() call
  33776. // will (conceptually) put pixels past the bounds of the canvas. But
  33777. // that's ok; any such pixels are ignored.
  33778. var height = imgData.height, width = imgData.width;
  33779. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  33780. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  33781. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  33782. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  33783. var srcPos = 0, destPos;
  33784. var src = imgData.data;
  33785. var dest = chunkImgData.data;
  33786. var i, j, thisChunkHeight, elemsInThisChunk;
  33787. // There are multiple forms in which the pixel data can be passed, and
  33788. // imgData.kind tells us which one this is.
  33789. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  33790. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  33791. var srcLength = src.byteLength;
  33792. var dest32 = HasCanvasTypedArraysCached.value ?
  33793. new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  33794. var dest32DataLength = dest32.length;
  33795. var fullSrcDiff = (width + 7) >> 3;
  33796. var white = 0xFFFFFFFF;
  33797. var black = (IsLittleEndianCached.value ||
  33798. !HasCanvasTypedArraysCached.value) ? 0xFF000000 : 0x000000FF;
  33799. for (i = 0; i < totalChunks; i++) {
  33800. thisChunkHeight =
  33801. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  33802. destPos = 0;
  33803. for (j = 0; j < thisChunkHeight; j++) {
  33804. var srcDiff = srcLength - srcPos;
  33805. var k = 0;
  33806. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  33807. var kEndUnrolled = kEnd & ~7;
  33808. var mask = 0;
  33809. var srcByte = 0;
  33810. for (; k < kEndUnrolled; k += 8) {
  33811. srcByte = src[srcPos++];
  33812. dest32[destPos++] = (srcByte & 128) ? white : black;
  33813. dest32[destPos++] = (srcByte & 64) ? white : black;
  33814. dest32[destPos++] = (srcByte & 32) ? white : black;
  33815. dest32[destPos++] = (srcByte & 16) ? white : black;
  33816. dest32[destPos++] = (srcByte & 8) ? white : black;
  33817. dest32[destPos++] = (srcByte & 4) ? white : black;
  33818. dest32[destPos++] = (srcByte & 2) ? white : black;
  33819. dest32[destPos++] = (srcByte & 1) ? white : black;
  33820. }
  33821. for (; k < kEnd; k++) {
  33822. if (mask === 0) {
  33823. srcByte = src[srcPos++];
  33824. mask = 128;
  33825. }
  33826. dest32[destPos++] = (srcByte & mask) ? white : black;
  33827. mask >>= 1;
  33828. }
  33829. }
  33830. // We ran out of input. Make all remaining pixels transparent.
  33831. while (destPos < dest32DataLength) {
  33832. dest32[destPos++] = 0;
  33833. }
  33834. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  33835. }
  33836. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  33837. // RGBA, 32-bits per pixel.
  33838. j = 0;
  33839. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  33840. for (i = 0; i < fullChunks; i++) {
  33841. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  33842. srcPos += elemsInThisChunk;
  33843. ctx.putImageData(chunkImgData, 0, j);
  33844. j += FULL_CHUNK_HEIGHT;
  33845. }
  33846. if (i < totalChunks) {
  33847. elemsInThisChunk = width * partialChunkHeight * 4;
  33848. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  33849. ctx.putImageData(chunkImgData, 0, j);
  33850. }
  33851. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  33852. // RGB, 24-bits per pixel.
  33853. thisChunkHeight = FULL_CHUNK_HEIGHT;
  33854. elemsInThisChunk = width * thisChunkHeight;
  33855. for (i = 0; i < totalChunks; i++) {
  33856. if (i >= fullChunks) {
  33857. thisChunkHeight = partialChunkHeight;
  33858. elemsInThisChunk = width * thisChunkHeight;
  33859. }
  33860. destPos = 0;
  33861. for (j = elemsInThisChunk; j--;) {
  33862. dest[destPos++] = src[srcPos++];
  33863. dest[destPos++] = src[srcPos++];
  33864. dest[destPos++] = src[srcPos++];
  33865. dest[destPos++] = 255;
  33866. }
  33867. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  33868. }
  33869. } else {
  33870. error('bad image kind: ' + imgData.kind);
  33871. }
  33872. }
  33873. function putBinaryImageMask(ctx, imgData) {
  33874. var height = imgData.height, width = imgData.width;
  33875. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  33876. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  33877. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  33878. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  33879. var srcPos = 0;
  33880. var src = imgData.data;
  33881. var dest = chunkImgData.data;
  33882. for (var i = 0; i < totalChunks; i++) {
  33883. var thisChunkHeight =
  33884. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  33885. // Expand the mask so it can be used by the canvas. Any required
  33886. // inversion has already been handled.
  33887. var destPos = 3; // alpha component offset
  33888. for (var j = 0; j < thisChunkHeight; j++) {
  33889. var mask = 0;
  33890. for (var k = 0; k < width; k++) {
  33891. if (!mask) {
  33892. var elem = src[srcPos++];
  33893. mask = 128;
  33894. }
  33895. dest[destPos] = (elem & mask) ? 0 : 255;
  33896. destPos += 4;
  33897. mask >>= 1;
  33898. }
  33899. }
  33900. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  33901. }
  33902. }
  33903. function copyCtxState(sourceCtx, destCtx) {
  33904. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  33905. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  33906. 'globalCompositeOperation', 'font'];
  33907. for (var i = 0, ii = properties.length; i < ii; i++) {
  33908. var property = properties[i];
  33909. if (sourceCtx[property] !== undefined) {
  33910. destCtx[property] = sourceCtx[property];
  33911. }
  33912. }
  33913. if (sourceCtx.setLineDash !== undefined) {
  33914. destCtx.setLineDash(sourceCtx.getLineDash());
  33915. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  33916. } else if (sourceCtx.mozDashOffset !== undefined) {
  33917. destCtx.mozDash = sourceCtx.mozDash;
  33918. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  33919. }
  33920. }
  33921. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  33922. var length = bytes.length;
  33923. for (var i = 3; i < length; i += 4) {
  33924. var alpha = bytes[i];
  33925. if (alpha === 0) {
  33926. bytes[i - 3] = r0;
  33927. bytes[i - 2] = g0;
  33928. bytes[i - 1] = b0;
  33929. } else if (alpha < 255) {
  33930. var alpha_ = 255 - alpha;
  33931. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  33932. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  33933. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  33934. }
  33935. }
  33936. }
  33937. function composeSMaskAlpha(maskData, layerData, transferMap) {
  33938. var length = maskData.length;
  33939. var scale = 1 / 255;
  33940. for (var i = 3; i < length; i += 4) {
  33941. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  33942. layerData[i] = (layerData[i] * alpha * scale) | 0;
  33943. }
  33944. }
  33945. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  33946. var length = maskData.length;
  33947. for (var i = 3; i < length; i += 4) {
  33948. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  33949. (maskData[i - 2] * 152) + // * 0.59 ....
  33950. (maskData[i - 1] * 28); // * 0.11 ....
  33951. layerData[i] = transferMap ?
  33952. (layerData[i] * transferMap[y >> 8]) >> 8 :
  33953. (layerData[i] * y) >> 16;
  33954. }
  33955. }
  33956. function genericComposeSMask(maskCtx, layerCtx, width, height,
  33957. subtype, backdrop, transferMap) {
  33958. var hasBackdrop = !!backdrop;
  33959. var r0 = hasBackdrop ? backdrop[0] : 0;
  33960. var g0 = hasBackdrop ? backdrop[1] : 0;
  33961. var b0 = hasBackdrop ? backdrop[2] : 0;
  33962. var composeFn;
  33963. if (subtype === 'Luminosity') {
  33964. composeFn = composeSMaskLuminosity;
  33965. } else {
  33966. composeFn = composeSMaskAlpha;
  33967. }
  33968. // processing image in chunks to save memory
  33969. var PIXELS_TO_PROCESS = 1048576;
  33970. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  33971. for (var row = 0; row < height; row += chunkSize) {
  33972. var chunkHeight = Math.min(chunkSize, height - row);
  33973. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  33974. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  33975. if (hasBackdrop) {
  33976. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  33977. }
  33978. composeFn(maskData.data, layerData.data, transferMap);
  33979. maskCtx.putImageData(layerData, 0, row);
  33980. }
  33981. }
  33982. function composeSMask(ctx, smask, layerCtx) {
  33983. var mask = smask.canvas;
  33984. var maskCtx = smask.context;
  33985. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  33986. smask.offsetX, smask.offsetY);
  33987. var backdrop = smask.backdrop || null;
  33988. if (!smask.transferMap && WebGLUtils.isEnabled) {
  33989. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  33990. {subtype: smask.subtype, backdrop: backdrop});
  33991. ctx.setTransform(1, 0, 0, 1, 0, 0);
  33992. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  33993. return;
  33994. }
  33995. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  33996. smask.subtype, backdrop, smask.transferMap);
  33997. ctx.drawImage(mask, 0, 0);
  33998. }
  33999. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  34000. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  34001. var NORMAL_CLIP = {};
  34002. var EO_CLIP = {};
  34003. CanvasGraphics.prototype = {
  34004. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  34005. transparency) {
  34006. // For pdfs that use blend modes we have to clear the canvas else certain
  34007. // blend modes can look wrong since we'd be blending with a white
  34008. // backdrop. The problem with a transparent backdrop though is we then
  34009. // don't get sub pixel anti aliasing on text, creating temporary
  34010. // transparent canvas when we have blend modes.
  34011. var width = this.ctx.canvas.width;
  34012. var height = this.ctx.canvas.height;
  34013. this.ctx.save();
  34014. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  34015. this.ctx.fillRect(0, 0, width, height);
  34016. this.ctx.restore();
  34017. if (transparency) {
  34018. var transparentCanvas = this.cachedCanvases.getCanvas(
  34019. 'transparent', width, height, true);
  34020. this.compositeCtx = this.ctx;
  34021. this.transparentCanvas = transparentCanvas.canvas;
  34022. this.ctx = transparentCanvas.context;
  34023. this.ctx.save();
  34024. // The transform can be applied before rendering, transferring it to
  34025. // the new canvas.
  34026. this.ctx.transform.apply(this.ctx,
  34027. this.compositeCtx.mozCurrentTransform);
  34028. }
  34029. this.ctx.save();
  34030. if (transform) {
  34031. this.ctx.transform.apply(this.ctx, transform);
  34032. }
  34033. this.ctx.transform.apply(this.ctx, viewport.transform);
  34034. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  34035. if (this.imageLayer) {
  34036. this.imageLayer.beginLayout();
  34037. }
  34038. },
  34039. executeOperatorList: function CanvasGraphics_executeOperatorList(
  34040. operatorList,
  34041. executionStartIdx, continueCallback,
  34042. stepper) {
  34043. var argsArray = operatorList.argsArray;
  34044. var fnArray = operatorList.fnArray;
  34045. var i = executionStartIdx || 0;
  34046. var argsArrayLen = argsArray.length;
  34047. // Sometimes the OperatorList to execute is empty.
  34048. if (argsArrayLen === i) {
  34049. return i;
  34050. }
  34051. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  34052. typeof continueCallback === 'function');
  34053. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  34054. var steps = 0;
  34055. var commonObjs = this.commonObjs;
  34056. var objs = this.objs;
  34057. var fnId;
  34058. while (true) {
  34059. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  34060. stepper.breakIt(i, continueCallback);
  34061. return i;
  34062. }
  34063. fnId = fnArray[i];
  34064. if (fnId !== OPS.dependency) {
  34065. this[fnId].apply(this, argsArray[i]);
  34066. } else {
  34067. var deps = argsArray[i];
  34068. for (var n = 0, nn = deps.length; n < nn; n++) {
  34069. var depObjId = deps[n];
  34070. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  34071. var objsPool = common ? commonObjs : objs;
  34072. // If the promise isn't resolved yet, add the continueCallback
  34073. // to the promise and bail out.
  34074. if (!objsPool.isResolved(depObjId)) {
  34075. objsPool.get(depObjId, continueCallback);
  34076. return i;
  34077. }
  34078. }
  34079. }
  34080. i++;
  34081. // If the entire operatorList was executed, stop as were done.
  34082. if (i === argsArrayLen) {
  34083. return i;
  34084. }
  34085. // If the execution took longer then a certain amount of time and
  34086. // `continueCallback` is specified, interrupt the execution.
  34087. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  34088. if (Date.now() > endTime) {
  34089. continueCallback();
  34090. return i;
  34091. }
  34092. steps = 0;
  34093. }
  34094. // If the operatorList isn't executed completely yet OR the execution
  34095. // time was short enough, do another execution round.
  34096. }
  34097. },
  34098. endDrawing: function CanvasGraphics_endDrawing() {
  34099. // Finishing all opened operations such as SMask group painting.
  34100. if (this.current.activeSMask !== null) {
  34101. this.endSMaskGroup();
  34102. }
  34103. this.ctx.restore();
  34104. if (this.transparentCanvas) {
  34105. this.ctx = this.compositeCtx;
  34106. this.ctx.save();
  34107. this.ctx.setTransform(1, 0, 0, 1, 0, 0); // Avoid apply transform twice
  34108. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  34109. this.ctx.restore();
  34110. this.transparentCanvas = null;
  34111. }
  34112. this.cachedCanvases.clear();
  34113. WebGLUtils.clear();
  34114. if (this.imageLayer) {
  34115. this.imageLayer.endLayout();
  34116. }
  34117. },
  34118. // Graphics state
  34119. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  34120. this.current.lineWidth = width;
  34121. this.ctx.lineWidth = width;
  34122. },
  34123. setLineCap: function CanvasGraphics_setLineCap(style) {
  34124. this.ctx.lineCap = LINE_CAP_STYLES[style];
  34125. },
  34126. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  34127. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  34128. },
  34129. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  34130. this.ctx.miterLimit = limit;
  34131. },
  34132. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  34133. var ctx = this.ctx;
  34134. if (ctx.setLineDash !== undefined) {
  34135. ctx.setLineDash(dashArray);
  34136. ctx.lineDashOffset = dashPhase;
  34137. } else {
  34138. ctx.mozDash = dashArray;
  34139. ctx.mozDashOffset = dashPhase;
  34140. }
  34141. },
  34142. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  34143. // Maybe if we one day fully support color spaces this will be important
  34144. // for now we can ignore.
  34145. // TODO set rendering intent?
  34146. },
  34147. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  34148. // There's no way to control this with canvas, but we can safely ignore.
  34149. // TODO set flatness?
  34150. },
  34151. setGState: function CanvasGraphics_setGState(states) {
  34152. for (var i = 0, ii = states.length; i < ii; i++) {
  34153. var state = states[i];
  34154. var key = state[0];
  34155. var value = state[1];
  34156. switch (key) {
  34157. case 'LW':
  34158. this.setLineWidth(value);
  34159. break;
  34160. case 'LC':
  34161. this.setLineCap(value);
  34162. break;
  34163. case 'LJ':
  34164. this.setLineJoin(value);
  34165. break;
  34166. case 'ML':
  34167. this.setMiterLimit(value);
  34168. break;
  34169. case 'D':
  34170. this.setDash(value[0], value[1]);
  34171. break;
  34172. case 'RI':
  34173. this.setRenderingIntent(value);
  34174. break;
  34175. case 'FL':
  34176. this.setFlatness(value);
  34177. break;
  34178. case 'Font':
  34179. this.setFont(value[0], value[1]);
  34180. break;
  34181. case 'CA':
  34182. this.current.strokeAlpha = state[1];
  34183. break;
  34184. case 'ca':
  34185. this.current.fillAlpha = state[1];
  34186. this.ctx.globalAlpha = state[1];
  34187. break;
  34188. case 'BM':
  34189. if (value && value.name && (value.name !== 'Normal')) {
  34190. var mode = value.name.replace(/([A-Z])/g,
  34191. function(c) {
  34192. return '-' + c.toLowerCase();
  34193. }
  34194. ).substring(1);
  34195. this.ctx.globalCompositeOperation = mode;
  34196. if (this.ctx.globalCompositeOperation !== mode) {
  34197. warn('globalCompositeOperation "' + mode +
  34198. '" is not supported');
  34199. }
  34200. } else {
  34201. this.ctx.globalCompositeOperation = 'source-over';
  34202. }
  34203. break;
  34204. case 'SMask':
  34205. if (this.current.activeSMask) {
  34206. // If SMask is currrenly used, it needs to be suspended or
  34207. // finished. Suspend only makes sense when at least one save()
  34208. // was performed and state needs to be reverted on restore().
  34209. if (this.stateStack.length > 0 &&
  34210. (this.stateStack[this.stateStack.length - 1].activeSMask ===
  34211. this.current.activeSMask)) {
  34212. this.suspendSMaskGroup();
  34213. } else {
  34214. this.endSMaskGroup();
  34215. }
  34216. }
  34217. this.current.activeSMask = value ? this.tempSMask : null;
  34218. if (this.current.activeSMask) {
  34219. this.beginSMaskGroup();
  34220. }
  34221. this.tempSMask = null;
  34222. break;
  34223. }
  34224. }
  34225. },
  34226. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  34227. var activeSMask = this.current.activeSMask;
  34228. var drawnWidth = activeSMask.canvas.width;
  34229. var drawnHeight = activeSMask.canvas.height;
  34230. var cacheId = 'smaskGroupAt' + this.groupLevel;
  34231. var scratchCanvas = this.cachedCanvases.getCanvas(
  34232. cacheId, drawnWidth, drawnHeight, true);
  34233. var currentCtx = this.ctx;
  34234. var currentTransform = currentCtx.mozCurrentTransform;
  34235. this.ctx.save();
  34236. var groupCtx = scratchCanvas.context;
  34237. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  34238. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  34239. groupCtx.transform.apply(groupCtx, currentTransform);
  34240. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  34241. copyCtxState(currentCtx, groupCtx);
  34242. this.ctx = groupCtx;
  34243. this.setGState([
  34244. ['BM', 'Normal'],
  34245. ['ca', 1],
  34246. ['CA', 1]
  34247. ]);
  34248. this.groupStack.push(currentCtx);
  34249. this.groupLevel++;
  34250. },
  34251. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34252. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  34253. // and future ctx state restored.
  34254. var groupCtx = this.ctx;
  34255. this.groupLevel--;
  34256. this.ctx = this.groupStack.pop();
  34257. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34258. this.ctx.restore();
  34259. this.ctx.save(); // save is needed since SMask will be resumed.
  34260. copyCtxState(groupCtx, this.ctx);
  34261. // Saving state for resuming.
  34262. this.current.resumeSMaskCtx = groupCtx;
  34263. // Transform was changed in the SMask canvas, reflecting this change on
  34264. // this.ctx.
  34265. var deltaTransform = Util.transform(
  34266. this.current.activeSMask.startTransformInverse,
  34267. groupCtx.mozCurrentTransform);
  34268. this.ctx.transform.apply(this.ctx, deltaTransform);
  34269. // SMask was composed, the results at the groupCtx can be cleared.
  34270. groupCtx.save();
  34271. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  34272. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  34273. groupCtx.restore();
  34274. },
  34275. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34276. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  34277. // any groupCtx state since restore() command (the only caller) will do
  34278. // that for us. See also beginSMaskGroup.
  34279. var groupCtx = this.current.resumeSMaskCtx;
  34280. var currentCtx = this.ctx;
  34281. this.ctx = groupCtx;
  34282. this.groupStack.push(currentCtx);
  34283. this.groupLevel++;
  34284. },
  34285. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34286. var groupCtx = this.ctx;
  34287. this.groupLevel--;
  34288. this.ctx = this.groupStack.pop();
  34289. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34290. this.ctx.restore();
  34291. copyCtxState(groupCtx, this.ctx);
  34292. // Transform was changed in the SMask canvas, reflecting this change on
  34293. // this.ctx.
  34294. var deltaTransform = Util.transform(
  34295. this.current.activeSMask.startTransformInverse,
  34296. groupCtx.mozCurrentTransform);
  34297. this.ctx.transform.apply(this.ctx, deltaTransform);
  34298. },
  34299. save: function CanvasGraphics_save() {
  34300. this.ctx.save();
  34301. var old = this.current;
  34302. this.stateStack.push(old);
  34303. this.current = old.clone();
  34304. this.current.resumeSMaskCtx = null;
  34305. },
  34306. restore: function CanvasGraphics_restore() {
  34307. // SMask was suspended, we just need to resume it.
  34308. if (this.current.resumeSMaskCtx) {
  34309. this.resumeSMaskGroup();
  34310. }
  34311. // SMask has to be finished once there is no states that are using the
  34312. // same SMask.
  34313. if (this.current.activeSMask !== null && (this.stateStack.length === 0 ||
  34314. this.stateStack[this.stateStack.length - 1].activeSMask !==
  34315. this.current.activeSMask)) {
  34316. this.endSMaskGroup();
  34317. }
  34318. if (this.stateStack.length !== 0) {
  34319. this.current = this.stateStack.pop();
  34320. this.ctx.restore();
  34321. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  34322. this.pendingClip = null;
  34323. this.cachedGetSinglePixelWidth = null;
  34324. }
  34325. },
  34326. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  34327. this.ctx.transform(a, b, c, d, e, f);
  34328. this.cachedGetSinglePixelWidth = null;
  34329. },
  34330. // Path
  34331. constructPath: function CanvasGraphics_constructPath(ops, args) {
  34332. var ctx = this.ctx;
  34333. var current = this.current;
  34334. var x = current.x, y = current.y;
  34335. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  34336. switch (ops[i] | 0) {
  34337. case OPS.rectangle:
  34338. x = args[j++];
  34339. y = args[j++];
  34340. var width = args[j++];
  34341. var height = args[j++];
  34342. if (width === 0) {
  34343. width = this.getSinglePixelWidth();
  34344. }
  34345. if (height === 0) {
  34346. height = this.getSinglePixelWidth();
  34347. }
  34348. var xw = x + width;
  34349. var yh = y + height;
  34350. this.ctx.moveTo(x, y);
  34351. this.ctx.lineTo(xw, y);
  34352. this.ctx.lineTo(xw, yh);
  34353. this.ctx.lineTo(x, yh);
  34354. this.ctx.lineTo(x, y);
  34355. this.ctx.closePath();
  34356. break;
  34357. case OPS.moveTo:
  34358. x = args[j++];
  34359. y = args[j++];
  34360. ctx.moveTo(x, y);
  34361. break;
  34362. case OPS.lineTo:
  34363. x = args[j++];
  34364. y = args[j++];
  34365. ctx.lineTo(x, y);
  34366. break;
  34367. case OPS.curveTo:
  34368. x = args[j + 4];
  34369. y = args[j + 5];
  34370. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  34371. x, y);
  34372. j += 6;
  34373. break;
  34374. case OPS.curveTo2:
  34375. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  34376. args[j + 2], args[j + 3]);
  34377. x = args[j + 2];
  34378. y = args[j + 3];
  34379. j += 4;
  34380. break;
  34381. case OPS.curveTo3:
  34382. x = args[j + 2];
  34383. y = args[j + 3];
  34384. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  34385. j += 4;
  34386. break;
  34387. case OPS.closePath:
  34388. ctx.closePath();
  34389. break;
  34390. }
  34391. }
  34392. current.setCurrentPoint(x, y);
  34393. },
  34394. closePath: function CanvasGraphics_closePath() {
  34395. this.ctx.closePath();
  34396. },
  34397. stroke: function CanvasGraphics_stroke(consumePath) {
  34398. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34399. var ctx = this.ctx;
  34400. var strokeColor = this.current.strokeColor;
  34401. // Prevent drawing too thin lines by enforcing a minimum line width.
  34402. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  34403. this.current.lineWidth);
  34404. // For stroke we want to temporarily change the global alpha to the
  34405. // stroking alpha.
  34406. ctx.globalAlpha = this.current.strokeAlpha;
  34407. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  34408. strokeColor.type === 'Pattern') {
  34409. // for patterns, we transform to pattern space, calculate
  34410. // the pattern, call stroke, and restore to user space
  34411. ctx.save();
  34412. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  34413. ctx.stroke();
  34414. ctx.restore();
  34415. } else {
  34416. ctx.stroke();
  34417. }
  34418. if (consumePath) {
  34419. this.consumePath();
  34420. }
  34421. // Restore the global alpha to the fill alpha
  34422. ctx.globalAlpha = this.current.fillAlpha;
  34423. },
  34424. closeStroke: function CanvasGraphics_closeStroke() {
  34425. this.closePath();
  34426. this.stroke();
  34427. },
  34428. fill: function CanvasGraphics_fill(consumePath) {
  34429. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34430. var ctx = this.ctx;
  34431. var fillColor = this.current.fillColor;
  34432. var isPatternFill = this.current.patternFill;
  34433. var needRestore = false;
  34434. if (isPatternFill) {
  34435. ctx.save();
  34436. if (this.baseTransform) {
  34437. ctx.setTransform.apply(ctx, this.baseTransform);
  34438. }
  34439. ctx.fillStyle = fillColor.getPattern(ctx, this);
  34440. needRestore = true;
  34441. }
  34442. if (this.pendingEOFill) {
  34443. if (ctx.mozFillRule !== undefined) {
  34444. ctx.mozFillRule = 'evenodd';
  34445. ctx.fill();
  34446. ctx.mozFillRule = 'nonzero';
  34447. } else {
  34448. ctx.fill('evenodd');
  34449. }
  34450. this.pendingEOFill = false;
  34451. } else {
  34452. ctx.fill();
  34453. }
  34454. if (needRestore) {
  34455. ctx.restore();
  34456. }
  34457. if (consumePath) {
  34458. this.consumePath();
  34459. }
  34460. },
  34461. eoFill: function CanvasGraphics_eoFill() {
  34462. this.pendingEOFill = true;
  34463. this.fill();
  34464. },
  34465. fillStroke: function CanvasGraphics_fillStroke() {
  34466. this.fill(false);
  34467. this.stroke(false);
  34468. this.consumePath();
  34469. },
  34470. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  34471. this.pendingEOFill = true;
  34472. this.fillStroke();
  34473. },
  34474. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  34475. this.closePath();
  34476. this.fillStroke();
  34477. },
  34478. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  34479. this.pendingEOFill = true;
  34480. this.closePath();
  34481. this.fillStroke();
  34482. },
  34483. endPath: function CanvasGraphics_endPath() {
  34484. this.consumePath();
  34485. },
  34486. // Clipping
  34487. clip: function CanvasGraphics_clip() {
  34488. this.pendingClip = NORMAL_CLIP;
  34489. },
  34490. eoClip: function CanvasGraphics_eoClip() {
  34491. this.pendingClip = EO_CLIP;
  34492. },
  34493. // Text
  34494. beginText: function CanvasGraphics_beginText() {
  34495. this.current.textMatrix = IDENTITY_MATRIX;
  34496. this.current.textMatrixScale = 1;
  34497. this.current.x = this.current.lineX = 0;
  34498. this.current.y = this.current.lineY = 0;
  34499. },
  34500. endText: function CanvasGraphics_endText() {
  34501. var paths = this.pendingTextPaths;
  34502. var ctx = this.ctx;
  34503. if (paths === undefined) {
  34504. ctx.beginPath();
  34505. return;
  34506. }
  34507. ctx.save();
  34508. ctx.beginPath();
  34509. for (var i = 0; i < paths.length; i++) {
  34510. var path = paths[i];
  34511. ctx.setTransform.apply(ctx, path.transform);
  34512. ctx.translate(path.x, path.y);
  34513. path.addToPath(ctx, path.fontSize);
  34514. }
  34515. ctx.restore();
  34516. ctx.clip();
  34517. ctx.beginPath();
  34518. delete this.pendingTextPaths;
  34519. },
  34520. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  34521. this.current.charSpacing = spacing;
  34522. },
  34523. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  34524. this.current.wordSpacing = spacing;
  34525. },
  34526. setHScale: function CanvasGraphics_setHScale(scale) {
  34527. this.current.textHScale = scale / 100;
  34528. },
  34529. setLeading: function CanvasGraphics_setLeading(leading) {
  34530. this.current.leading = -leading;
  34531. },
  34532. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  34533. var fontObj = this.commonObjs.get(fontRefName);
  34534. var current = this.current;
  34535. if (!fontObj) {
  34536. error('Can\'t find font for ' + fontRefName);
  34537. }
  34538. current.fontMatrix = (fontObj.fontMatrix ?
  34539. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  34540. // A valid matrix needs all main diagonal elements to be non-zero
  34541. // This also ensures we bypass FF bugzilla bug #719844.
  34542. if (current.fontMatrix[0] === 0 ||
  34543. current.fontMatrix[3] === 0) {
  34544. warn('Invalid font matrix for font ' + fontRefName);
  34545. }
  34546. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  34547. // and in some docs this can be negative (inverted x-y axes).
  34548. if (size < 0) {
  34549. size = -size;
  34550. current.fontDirection = -1;
  34551. } else {
  34552. current.fontDirection = 1;
  34553. }
  34554. this.current.font = fontObj;
  34555. this.current.fontSize = size;
  34556. if (fontObj.isType3Font) {
  34557. return; // we don't need ctx.font for Type3 fonts
  34558. }
  34559. var name = fontObj.loadedName || 'sans-serif';
  34560. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  34561. (fontObj.bold ? 'bold' : 'normal');
  34562. var italic = fontObj.italic ? 'italic' : 'normal';
  34563. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  34564. // Some font backends cannot handle fonts below certain size.
  34565. // Keeping the font at minimal size and using the fontSizeScale to change
  34566. // the current transformation matrix before the fillText/strokeText.
  34567. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  34568. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  34569. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  34570. this.current.fontSizeScale = size / browserFontSize;
  34571. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  34572. this.ctx.font = rule;
  34573. },
  34574. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  34575. this.current.textRenderingMode = mode;
  34576. },
  34577. setTextRise: function CanvasGraphics_setTextRise(rise) {
  34578. this.current.textRise = rise;
  34579. },
  34580. moveText: function CanvasGraphics_moveText(x, y) {
  34581. this.current.x = this.current.lineX += x;
  34582. this.current.y = this.current.lineY += y;
  34583. },
  34584. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  34585. this.setLeading(-y);
  34586. this.moveText(x, y);
  34587. },
  34588. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  34589. this.current.textMatrix = [a, b, c, d, e, f];
  34590. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  34591. this.current.x = this.current.lineX = 0;
  34592. this.current.y = this.current.lineY = 0;
  34593. },
  34594. nextLine: function CanvasGraphics_nextLine() {
  34595. this.moveText(0, this.current.leading);
  34596. },
  34597. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  34598. var ctx = this.ctx;
  34599. var current = this.current;
  34600. var font = current.font;
  34601. var textRenderingMode = current.textRenderingMode;
  34602. var fontSize = current.fontSize / current.fontSizeScale;
  34603. var fillStrokeMode = textRenderingMode &
  34604. TextRenderingMode.FILL_STROKE_MASK;
  34605. var isAddToPathSet = !!(textRenderingMode &
  34606. TextRenderingMode.ADD_TO_PATH_FLAG);
  34607. var addToPath;
  34608. if (font.disableFontFace || isAddToPathSet) {
  34609. addToPath = font.getPathGenerator(this.commonObjs, character);
  34610. }
  34611. if (font.disableFontFace) {
  34612. ctx.save();
  34613. ctx.translate(x, y);
  34614. ctx.beginPath();
  34615. addToPath(ctx, fontSize);
  34616. if (fillStrokeMode === TextRenderingMode.FILL ||
  34617. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34618. ctx.fill();
  34619. }
  34620. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34621. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34622. ctx.stroke();
  34623. }
  34624. ctx.restore();
  34625. } else {
  34626. if (fillStrokeMode === TextRenderingMode.FILL ||
  34627. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34628. ctx.fillText(character, x, y);
  34629. }
  34630. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34631. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34632. ctx.strokeText(character, x, y);
  34633. }
  34634. }
  34635. if (isAddToPathSet) {
  34636. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  34637. paths.push({
  34638. transform: ctx.mozCurrentTransform,
  34639. x: x,
  34640. y: y,
  34641. fontSize: fontSize,
  34642. addToPath: addToPath
  34643. });
  34644. }
  34645. },
  34646. get isFontSubpixelAAEnabled() {
  34647. // Checks if anti-aliasing is enabled when scaled text is painted.
  34648. // On Windows GDI scaled fonts looks bad.
  34649. var ctx = document.createElement('canvas').getContext('2d');
  34650. ctx.scale(1.5, 1);
  34651. ctx.fillText('I', 0, 10);
  34652. var data = ctx.getImageData(0, 0, 10, 10).data;
  34653. var enabled = false;
  34654. for (var i = 3; i < data.length; i += 4) {
  34655. if (data[i] > 0 && data[i] < 255) {
  34656. enabled = true;
  34657. break;
  34658. }
  34659. }
  34660. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  34661. },
  34662. showText: function CanvasGraphics_showText(glyphs) {
  34663. var current = this.current;
  34664. var font = current.font;
  34665. if (font.isType3Font) {
  34666. return this.showType3Text(glyphs);
  34667. }
  34668. var fontSize = current.fontSize;
  34669. if (fontSize === 0) {
  34670. return;
  34671. }
  34672. var ctx = this.ctx;
  34673. var fontSizeScale = current.fontSizeScale;
  34674. var charSpacing = current.charSpacing;
  34675. var wordSpacing = current.wordSpacing;
  34676. var fontDirection = current.fontDirection;
  34677. var textHScale = current.textHScale * fontDirection;
  34678. var glyphsLength = glyphs.length;
  34679. var vertical = font.vertical;
  34680. var spacingDir = vertical ? 1 : -1;
  34681. var defaultVMetrics = font.defaultVMetrics;
  34682. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  34683. var simpleFillText =
  34684. current.textRenderingMode === TextRenderingMode.FILL &&
  34685. !font.disableFontFace;
  34686. ctx.save();
  34687. ctx.transform.apply(ctx, current.textMatrix);
  34688. ctx.translate(current.x, current.y + current.textRise);
  34689. if (current.patternFill) {
  34690. // TODO: Some shading patterns are not applied correctly to text,
  34691. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  34692. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  34693. }
  34694. if (fontDirection > 0) {
  34695. ctx.scale(textHScale, -1);
  34696. } else {
  34697. ctx.scale(textHScale, 1);
  34698. }
  34699. var lineWidth = current.lineWidth;
  34700. var scale = current.textMatrixScale;
  34701. if (scale === 0 || lineWidth === 0) {
  34702. var fillStrokeMode = current.textRenderingMode &
  34703. TextRenderingMode.FILL_STROKE_MASK;
  34704. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34705. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34706. this.cachedGetSinglePixelWidth = null;
  34707. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  34708. }
  34709. } else {
  34710. lineWidth /= scale;
  34711. }
  34712. if (fontSizeScale !== 1.0) {
  34713. ctx.scale(fontSizeScale, fontSizeScale);
  34714. lineWidth /= fontSizeScale;
  34715. }
  34716. ctx.lineWidth = lineWidth;
  34717. var x = 0, i;
  34718. for (i = 0; i < glyphsLength; ++i) {
  34719. var glyph = glyphs[i];
  34720. if (isNum(glyph)) {
  34721. x += spacingDir * glyph * fontSize / 1000;
  34722. continue;
  34723. }
  34724. var restoreNeeded = false;
  34725. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  34726. var character = glyph.fontChar;
  34727. var accent = glyph.accent;
  34728. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  34729. var width = glyph.width;
  34730. if (vertical) {
  34731. var vmetric, vx, vy;
  34732. vmetric = glyph.vmetric || defaultVMetrics;
  34733. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  34734. vx = -vx * widthAdvanceScale;
  34735. vy = vmetric[2] * widthAdvanceScale;
  34736. width = vmetric ? -vmetric[0] : width;
  34737. scaledX = vx / fontSizeScale;
  34738. scaledY = (x + vy) / fontSizeScale;
  34739. } else {
  34740. scaledX = x / fontSizeScale;
  34741. scaledY = 0;
  34742. }
  34743. if (font.remeasure && width > 0) {
  34744. // Some standard fonts may not have the exact width: rescale per
  34745. // character if measured width is greater than expected glyph width
  34746. // and subpixel-aa is enabled, otherwise just center the glyph.
  34747. var measuredWidth = ctx.measureText(character).width * 1000 /
  34748. fontSize * fontSizeScale;
  34749. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  34750. var characterScaleX = width / measuredWidth;
  34751. restoreNeeded = true;
  34752. ctx.save();
  34753. ctx.scale(characterScaleX, 1);
  34754. scaledX /= characterScaleX;
  34755. } else if (width !== measuredWidth) {
  34756. scaledX += (width - measuredWidth) / 2000 *
  34757. fontSize / fontSizeScale;
  34758. }
  34759. }
  34760. // Only attempt to draw the glyph if it is actually in the embedded font
  34761. // file or if there isn't a font file so the fallback font is shown.
  34762. if (glyph.isInFont || font.missingFile) {
  34763. if (simpleFillText && !accent) {
  34764. // common case
  34765. ctx.fillText(character, scaledX, scaledY);
  34766. } else {
  34767. this.paintChar(character, scaledX, scaledY);
  34768. if (accent) {
  34769. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  34770. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  34771. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  34772. }
  34773. }
  34774. }
  34775. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  34776. x += charWidth;
  34777. if (restoreNeeded) {
  34778. ctx.restore();
  34779. }
  34780. }
  34781. if (vertical) {
  34782. current.y -= x * textHScale;
  34783. } else {
  34784. current.x += x * textHScale;
  34785. }
  34786. ctx.restore();
  34787. },
  34788. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  34789. // Type3 fonts - each glyph is a "mini-PDF"
  34790. var ctx = this.ctx;
  34791. var current = this.current;
  34792. var font = current.font;
  34793. var fontSize = current.fontSize;
  34794. var fontDirection = current.fontDirection;
  34795. var spacingDir = font.vertical ? 1 : -1;
  34796. var charSpacing = current.charSpacing;
  34797. var wordSpacing = current.wordSpacing;
  34798. var textHScale = current.textHScale * fontDirection;
  34799. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  34800. var glyphsLength = glyphs.length;
  34801. var isTextInvisible =
  34802. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  34803. var i, glyph, width, spacingLength;
  34804. if (isTextInvisible || fontSize === 0) {
  34805. return;
  34806. }
  34807. this.cachedGetSinglePixelWidth = null;
  34808. ctx.save();
  34809. ctx.transform.apply(ctx, current.textMatrix);
  34810. ctx.translate(current.x, current.y);
  34811. ctx.scale(textHScale, fontDirection);
  34812. for (i = 0; i < glyphsLength; ++i) {
  34813. glyph = glyphs[i];
  34814. if (isNum(glyph)) {
  34815. spacingLength = spacingDir * glyph * fontSize / 1000;
  34816. this.ctx.translate(spacingLength, 0);
  34817. current.x += spacingLength * textHScale;
  34818. continue;
  34819. }
  34820. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  34821. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  34822. if (!operatorList) {
  34823. warn('Type3 character \"' + glyph.operatorListId +
  34824. '\" is not available');
  34825. continue;
  34826. }
  34827. this.processingType3 = glyph;
  34828. this.save();
  34829. ctx.scale(fontSize, fontSize);
  34830. ctx.transform.apply(ctx, fontMatrix);
  34831. this.executeOperatorList(operatorList);
  34832. this.restore();
  34833. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  34834. width = transformed[0] * fontSize + spacing;
  34835. ctx.translate(width, 0);
  34836. current.x += width * textHScale;
  34837. }
  34838. ctx.restore();
  34839. this.processingType3 = null;
  34840. },
  34841. // Type3 fonts
  34842. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  34843. // We can safely ignore this since the width should be the same
  34844. // as the width in the Widths array.
  34845. },
  34846. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  34847. yWidth,
  34848. llx,
  34849. lly,
  34850. urx,
  34851. ury) {
  34852. // TODO According to the spec we're also suppose to ignore any operators
  34853. // that set color or include images while processing this type3 font.
  34854. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  34855. this.clip();
  34856. this.endPath();
  34857. },
  34858. // Color
  34859. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  34860. var pattern;
  34861. if (IR[0] === 'TilingPattern') {
  34862. var color = IR[1];
  34863. var baseTransform = this.baseTransform ||
  34864. this.ctx.mozCurrentTransform.slice();
  34865. var self = this;
  34866. var canvasGraphicsFactory = {
  34867. createCanvasGraphics: function (ctx) {
  34868. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  34869. }
  34870. };
  34871. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  34872. baseTransform);
  34873. } else {
  34874. pattern = getShadingPatternFromIR(IR);
  34875. }
  34876. return pattern;
  34877. },
  34878. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  34879. this.current.strokeColor = this.getColorN_Pattern(arguments);
  34880. },
  34881. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  34882. this.current.fillColor = this.getColorN_Pattern(arguments);
  34883. this.current.patternFill = true;
  34884. },
  34885. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  34886. var color = Util.makeCssRgb(r, g, b);
  34887. this.ctx.strokeStyle = color;
  34888. this.current.strokeColor = color;
  34889. },
  34890. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  34891. var color = Util.makeCssRgb(r, g, b);
  34892. this.ctx.fillStyle = color;
  34893. this.current.fillColor = color;
  34894. this.current.patternFill = false;
  34895. },
  34896. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  34897. var ctx = this.ctx;
  34898. this.save();
  34899. var pattern = getShadingPatternFromIR(patternIR);
  34900. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  34901. var inv = ctx.mozCurrentTransformInverse;
  34902. if (inv) {
  34903. var canvas = ctx.canvas;
  34904. var width = canvas.width;
  34905. var height = canvas.height;
  34906. var bl = Util.applyTransform([0, 0], inv);
  34907. var br = Util.applyTransform([0, height], inv);
  34908. var ul = Util.applyTransform([width, 0], inv);
  34909. var ur = Util.applyTransform([width, height], inv);
  34910. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  34911. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  34912. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  34913. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  34914. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  34915. } else {
  34916. // HACK to draw the gradient onto an infinite rectangle.
  34917. // PDF gradients are drawn across the entire image while
  34918. // Canvas only allows gradients to be drawn in a rectangle
  34919. // The following bug should allow us to remove this.
  34920. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  34921. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  34922. }
  34923. this.restore();
  34924. },
  34925. // Images
  34926. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  34927. error('Should not call beginInlineImage');
  34928. },
  34929. beginImageData: function CanvasGraphics_beginImageData() {
  34930. error('Should not call beginImageData');
  34931. },
  34932. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  34933. bbox) {
  34934. this.save();
  34935. this.baseTransformStack.push(this.baseTransform);
  34936. if (isArray(matrix) && 6 === matrix.length) {
  34937. this.transform.apply(this, matrix);
  34938. }
  34939. this.baseTransform = this.ctx.mozCurrentTransform;
  34940. if (isArray(bbox) && 4 === bbox.length) {
  34941. var width = bbox[2] - bbox[0];
  34942. var height = bbox[3] - bbox[1];
  34943. this.ctx.rect(bbox[0], bbox[1], width, height);
  34944. this.clip();
  34945. this.endPath();
  34946. }
  34947. },
  34948. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  34949. this.restore();
  34950. this.baseTransform = this.baseTransformStack.pop();
  34951. },
  34952. beginGroup: function CanvasGraphics_beginGroup(group) {
  34953. this.save();
  34954. var currentCtx = this.ctx;
  34955. // TODO non-isolated groups - according to Rik at adobe non-isolated
  34956. // group results aren't usually that different and they even have tools
  34957. // that ignore this setting. Notes from Rik on implementing:
  34958. // - When you encounter an transparency group, create a new canvas with
  34959. // the dimensions of the bbox
  34960. // - copy the content from the previous canvas to the new canvas
  34961. // - draw as usual
  34962. // - remove the backdrop alpha:
  34963. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  34964. // value of your transparency group and 'alphaBackdrop' the alpha of the
  34965. // backdrop
  34966. // - remove background color:
  34967. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  34968. if (!group.isolated) {
  34969. info('TODO: Support non-isolated groups.');
  34970. }
  34971. // TODO knockout - supposedly possible with the clever use of compositing
  34972. // modes.
  34973. if (group.knockout) {
  34974. warn('Knockout groups not supported.');
  34975. }
  34976. var currentTransform = currentCtx.mozCurrentTransform;
  34977. if (group.matrix) {
  34978. currentCtx.transform.apply(currentCtx, group.matrix);
  34979. }
  34980. assert(group.bbox, 'Bounding box is required.');
  34981. // Based on the current transform figure out how big the bounding box
  34982. // will actually be.
  34983. var bounds = Util.getAxialAlignedBoundingBox(
  34984. group.bbox,
  34985. currentCtx.mozCurrentTransform);
  34986. // Clip the bounding box to the current canvas.
  34987. var canvasBounds = [0,
  34988. 0,
  34989. currentCtx.canvas.width,
  34990. currentCtx.canvas.height];
  34991. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  34992. // Use ceil in case we're between sizes so we don't create canvas that is
  34993. // too small and make the canvas at least 1x1 pixels.
  34994. var offsetX = Math.floor(bounds[0]);
  34995. var offsetY = Math.floor(bounds[1]);
  34996. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  34997. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  34998. var scaleX = 1, scaleY = 1;
  34999. if (drawnWidth > MAX_GROUP_SIZE) {
  35000. scaleX = drawnWidth / MAX_GROUP_SIZE;
  35001. drawnWidth = MAX_GROUP_SIZE;
  35002. }
  35003. if (drawnHeight > MAX_GROUP_SIZE) {
  35004. scaleY = drawnHeight / MAX_GROUP_SIZE;
  35005. drawnHeight = MAX_GROUP_SIZE;
  35006. }
  35007. var cacheId = 'groupAt' + this.groupLevel;
  35008. if (group.smask) {
  35009. // Using two cache entries is case if masks are used one after another.
  35010. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  35011. }
  35012. var scratchCanvas = this.cachedCanvases.getCanvas(
  35013. cacheId, drawnWidth, drawnHeight, true);
  35014. var groupCtx = scratchCanvas.context;
  35015. // Since we created a new canvas that is just the size of the bounding box
  35016. // we have to translate the group ctx.
  35017. groupCtx.scale(1 / scaleX, 1 / scaleY);
  35018. groupCtx.translate(-offsetX, -offsetY);
  35019. groupCtx.transform.apply(groupCtx, currentTransform);
  35020. if (group.smask) {
  35021. // Saving state and cached mask to be used in setGState.
  35022. this.smaskStack.push({
  35023. canvas: scratchCanvas.canvas,
  35024. context: groupCtx,
  35025. offsetX: offsetX,
  35026. offsetY: offsetY,
  35027. scaleX: scaleX,
  35028. scaleY: scaleY,
  35029. subtype: group.smask.subtype,
  35030. backdrop: group.smask.backdrop,
  35031. transferMap: group.smask.transferMap || null,
  35032. startTransformInverse: null, // used during suspend operation
  35033. });
  35034. } else {
  35035. // Setup the current ctx so when the group is popped we draw it at the
  35036. // right location.
  35037. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  35038. currentCtx.translate(offsetX, offsetY);
  35039. currentCtx.scale(scaleX, scaleY);
  35040. }
  35041. // The transparency group inherits all off the current graphics state
  35042. // except the blend mode, soft mask, and alpha constants.
  35043. copyCtxState(currentCtx, groupCtx);
  35044. this.ctx = groupCtx;
  35045. this.setGState([
  35046. ['BM', 'Normal'],
  35047. ['ca', 1],
  35048. ['CA', 1]
  35049. ]);
  35050. this.groupStack.push(currentCtx);
  35051. this.groupLevel++;
  35052. // Reseting mask state, masks will be applied on restore of the group.
  35053. this.current.activeSMask = null;
  35054. },
  35055. endGroup: function CanvasGraphics_endGroup(group) {
  35056. this.groupLevel--;
  35057. var groupCtx = this.ctx;
  35058. this.ctx = this.groupStack.pop();
  35059. // Turn off image smoothing to avoid sub pixel interpolation which can
  35060. // look kind of blurry for some pdfs.
  35061. if (this.ctx.imageSmoothingEnabled !== undefined) {
  35062. this.ctx.imageSmoothingEnabled = false;
  35063. } else {
  35064. this.ctx.mozImageSmoothingEnabled = false;
  35065. }
  35066. if (group.smask) {
  35067. this.tempSMask = this.smaskStack.pop();
  35068. } else {
  35069. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  35070. }
  35071. this.restore();
  35072. },
  35073. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  35074. this.save();
  35075. this.current = new CanvasExtraState();
  35076. if (this.baseTransform) {
  35077. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  35078. }
  35079. },
  35080. endAnnotations: function CanvasGraphics_endAnnotations() {
  35081. this.restore();
  35082. },
  35083. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  35084. matrix) {
  35085. this.save();
  35086. if (isArray(rect) && 4 === rect.length) {
  35087. var width = rect[2] - rect[0];
  35088. var height = rect[3] - rect[1];
  35089. this.ctx.rect(rect[0], rect[1], width, height);
  35090. this.clip();
  35091. this.endPath();
  35092. }
  35093. this.transform.apply(this, transform);
  35094. this.transform.apply(this, matrix);
  35095. },
  35096. endAnnotation: function CanvasGraphics_endAnnotation() {
  35097. this.restore();
  35098. },
  35099. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  35100. var domImage = this.objs.get(objId);
  35101. if (!domImage) {
  35102. warn('Dependent image isn\'t ready yet');
  35103. return;
  35104. }
  35105. this.save();
  35106. var ctx = this.ctx;
  35107. // scale the image to the unit square
  35108. ctx.scale(1 / w, -1 / h);
  35109. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  35110. 0, -h, w, h);
  35111. if (this.imageLayer) {
  35112. var currentTransform = ctx.mozCurrentTransformInverse;
  35113. var position = this.getCanvasPosition(0, 0);
  35114. this.imageLayer.appendImage({
  35115. objId: objId,
  35116. left: position[0],
  35117. top: position[1],
  35118. width: w / currentTransform[0],
  35119. height: h / currentTransform[3]
  35120. });
  35121. }
  35122. this.restore();
  35123. },
  35124. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  35125. var ctx = this.ctx;
  35126. var width = img.width, height = img.height;
  35127. var fillColor = this.current.fillColor;
  35128. var isPatternFill = this.current.patternFill;
  35129. var glyph = this.processingType3;
  35130. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  35131. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  35132. glyph.compiled =
  35133. compileType3Glyph({data: img.data, width: width, height: height});
  35134. } else {
  35135. glyph.compiled = null;
  35136. }
  35137. }
  35138. if (glyph && glyph.compiled) {
  35139. glyph.compiled(ctx);
  35140. return;
  35141. }
  35142. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35143. width, height);
  35144. var maskCtx = maskCanvas.context;
  35145. maskCtx.save();
  35146. putBinaryImageMask(maskCtx, img);
  35147. maskCtx.globalCompositeOperation = 'source-in';
  35148. maskCtx.fillStyle = isPatternFill ?
  35149. fillColor.getPattern(maskCtx, this) : fillColor;
  35150. maskCtx.fillRect(0, 0, width, height);
  35151. maskCtx.restore();
  35152. this.paintInlineImageXObject(maskCanvas.canvas);
  35153. },
  35154. paintImageMaskXObjectRepeat:
  35155. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  35156. scaleY, positions) {
  35157. var width = imgData.width;
  35158. var height = imgData.height;
  35159. var fillColor = this.current.fillColor;
  35160. var isPatternFill = this.current.patternFill;
  35161. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35162. width, height);
  35163. var maskCtx = maskCanvas.context;
  35164. maskCtx.save();
  35165. putBinaryImageMask(maskCtx, imgData);
  35166. maskCtx.globalCompositeOperation = 'source-in';
  35167. maskCtx.fillStyle = isPatternFill ?
  35168. fillColor.getPattern(maskCtx, this) : fillColor;
  35169. maskCtx.fillRect(0, 0, width, height);
  35170. maskCtx.restore();
  35171. var ctx = this.ctx;
  35172. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35173. ctx.save();
  35174. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  35175. ctx.scale(1, -1);
  35176. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35177. 0, -1, 1, 1);
  35178. ctx.restore();
  35179. }
  35180. },
  35181. paintImageMaskXObjectGroup:
  35182. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  35183. var ctx = this.ctx;
  35184. var fillColor = this.current.fillColor;
  35185. var isPatternFill = this.current.patternFill;
  35186. for (var i = 0, ii = images.length; i < ii; i++) {
  35187. var image = images[i];
  35188. var width = image.width, height = image.height;
  35189. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35190. width, height);
  35191. var maskCtx = maskCanvas.context;
  35192. maskCtx.save();
  35193. putBinaryImageMask(maskCtx, image);
  35194. maskCtx.globalCompositeOperation = 'source-in';
  35195. maskCtx.fillStyle = isPatternFill ?
  35196. fillColor.getPattern(maskCtx, this) : fillColor;
  35197. maskCtx.fillRect(0, 0, width, height);
  35198. maskCtx.restore();
  35199. ctx.save();
  35200. ctx.transform.apply(ctx, image.transform);
  35201. ctx.scale(1, -1);
  35202. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35203. 0, -1, 1, 1);
  35204. ctx.restore();
  35205. }
  35206. },
  35207. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  35208. var imgData = this.objs.get(objId);
  35209. if (!imgData) {
  35210. warn('Dependent image isn\'t ready yet');
  35211. return;
  35212. }
  35213. this.paintInlineImageXObject(imgData);
  35214. },
  35215. paintImageXObjectRepeat:
  35216. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  35217. positions) {
  35218. var imgData = this.objs.get(objId);
  35219. if (!imgData) {
  35220. warn('Dependent image isn\'t ready yet');
  35221. return;
  35222. }
  35223. var width = imgData.width;
  35224. var height = imgData.height;
  35225. var map = [];
  35226. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35227. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  35228. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  35229. }
  35230. this.paintInlineImageXObjectGroup(imgData, map);
  35231. },
  35232. paintInlineImageXObject:
  35233. function CanvasGraphics_paintInlineImageXObject(imgData) {
  35234. var width = imgData.width;
  35235. var height = imgData.height;
  35236. var ctx = this.ctx;
  35237. this.save();
  35238. // scale the image to the unit square
  35239. ctx.scale(1 / width, -1 / height);
  35240. var currentTransform = ctx.mozCurrentTransformInverse;
  35241. var a = currentTransform[0], b = currentTransform[1];
  35242. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  35243. var c = currentTransform[2], d = currentTransform[3];
  35244. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  35245. var imgToPaint, tmpCanvas;
  35246. // instanceof HTMLElement does not work in jsdom node.js module
  35247. if (imgData instanceof HTMLElement || !imgData.data) {
  35248. imgToPaint = imgData;
  35249. } else {
  35250. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  35251. width, height);
  35252. var tmpCtx = tmpCanvas.context;
  35253. putBinaryImageData(tmpCtx, imgData);
  35254. imgToPaint = tmpCanvas.canvas;
  35255. }
  35256. var paintWidth = width, paintHeight = height;
  35257. var tmpCanvasId = 'prescale1';
  35258. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  35259. // pixels during drawImage operation, painting on the temporary canvas(es)
  35260. // that are twice smaller in size
  35261. while ((widthScale > 2 && paintWidth > 1) ||
  35262. (heightScale > 2 && paintHeight > 1)) {
  35263. var newWidth = paintWidth, newHeight = paintHeight;
  35264. if (widthScale > 2 && paintWidth > 1) {
  35265. newWidth = Math.ceil(paintWidth / 2);
  35266. widthScale /= paintWidth / newWidth;
  35267. }
  35268. if (heightScale > 2 && paintHeight > 1) {
  35269. newHeight = Math.ceil(paintHeight / 2);
  35270. heightScale /= paintHeight / newHeight;
  35271. }
  35272. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  35273. newWidth, newHeight);
  35274. tmpCtx = tmpCanvas.context;
  35275. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  35276. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35277. 0, 0, newWidth, newHeight);
  35278. imgToPaint = tmpCanvas.canvas;
  35279. paintWidth = newWidth;
  35280. paintHeight = newHeight;
  35281. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  35282. }
  35283. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35284. 0, -height, width, height);
  35285. if (this.imageLayer) {
  35286. var position = this.getCanvasPosition(0, -height);
  35287. this.imageLayer.appendImage({
  35288. imgData: imgData,
  35289. left: position[0],
  35290. top: position[1],
  35291. width: width / currentTransform[0],
  35292. height: height / currentTransform[3]
  35293. });
  35294. }
  35295. this.restore();
  35296. },
  35297. paintInlineImageXObjectGroup:
  35298. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  35299. var ctx = this.ctx;
  35300. var w = imgData.width;
  35301. var h = imgData.height;
  35302. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  35303. var tmpCtx = tmpCanvas.context;
  35304. putBinaryImageData(tmpCtx, imgData);
  35305. for (var i = 0, ii = map.length; i < ii; i++) {
  35306. var entry = map[i];
  35307. ctx.save();
  35308. ctx.transform.apply(ctx, entry.transform);
  35309. ctx.scale(1, -1);
  35310. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  35311. 0, -1, 1, 1);
  35312. if (this.imageLayer) {
  35313. var position = this.getCanvasPosition(entry.x, entry.y);
  35314. this.imageLayer.appendImage({
  35315. imgData: imgData,
  35316. left: position[0],
  35317. top: position[1],
  35318. width: w,
  35319. height: h
  35320. });
  35321. }
  35322. ctx.restore();
  35323. }
  35324. },
  35325. paintSolidColorImageMask:
  35326. function CanvasGraphics_paintSolidColorImageMask() {
  35327. this.ctx.fillRect(0, 0, 1, 1);
  35328. },
  35329. paintXObject: function CanvasGraphics_paintXObject() {
  35330. warn('Unsupported \'paintXObject\' command.');
  35331. },
  35332. // Marked content
  35333. markPoint: function CanvasGraphics_markPoint(tag) {
  35334. // TODO Marked content.
  35335. },
  35336. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  35337. // TODO Marked content.
  35338. },
  35339. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  35340. // TODO Marked content.
  35341. },
  35342. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  35343. tag, properties) {
  35344. // TODO Marked content.
  35345. },
  35346. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  35347. // TODO Marked content.
  35348. },
  35349. // Compatibility
  35350. beginCompat: function CanvasGraphics_beginCompat() {
  35351. // TODO ignore undefined operators (should we do that anyway?)
  35352. },
  35353. endCompat: function CanvasGraphics_endCompat() {
  35354. // TODO stop ignoring undefined operators
  35355. },
  35356. // Helper functions
  35357. consumePath: function CanvasGraphics_consumePath() {
  35358. var ctx = this.ctx;
  35359. if (this.pendingClip) {
  35360. if (this.pendingClip === EO_CLIP) {
  35361. if (ctx.mozFillRule !== undefined) {
  35362. ctx.mozFillRule = 'evenodd';
  35363. ctx.clip();
  35364. ctx.mozFillRule = 'nonzero';
  35365. } else {
  35366. ctx.clip('evenodd');
  35367. }
  35368. } else {
  35369. ctx.clip();
  35370. }
  35371. this.pendingClip = null;
  35372. }
  35373. ctx.beginPath();
  35374. },
  35375. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  35376. if (this.cachedGetSinglePixelWidth === null) {
  35377. // NOTE: The `save` and `restore` commands used below is a workaround
  35378. // that is necessary in order to prevent `mozCurrentTransformInverse`
  35379. // from intermittently returning incorrect values in Firefox, see:
  35380. // https://github.com/mozilla/pdf.js/issues/7188.
  35381. this.ctx.save();
  35382. var inverse = this.ctx.mozCurrentTransformInverse;
  35383. this.ctx.restore();
  35384. // max of the current horizontal and vertical scale
  35385. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  35386. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  35387. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  35388. }
  35389. return this.cachedGetSinglePixelWidth;
  35390. },
  35391. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  35392. var transform = this.ctx.mozCurrentTransform;
  35393. return [
  35394. transform[0] * x + transform[2] * y + transform[4],
  35395. transform[1] * x + transform[3] * y + transform[5]
  35396. ];
  35397. }
  35398. };
  35399. for (var op in OPS) {
  35400. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  35401. }
  35402. return CanvasGraphics;
  35403. })();
  35404. exports.CanvasGraphics = CanvasGraphics;
  35405. exports.createScratchCanvas = createScratchCanvas;
  35406. }));
  35407. (function (root, factory) {
  35408. {
  35409. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  35410. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  35411. }
  35412. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  35413. var error = sharedUtil.error;
  35414. var info = sharedUtil.info;
  35415. var isArray = sharedUtil.isArray;
  35416. var isBool = sharedUtil.isBool;
  35417. var isDict = corePrimitives.isDict;
  35418. var isStream = corePrimitives.isStream;
  35419. var PostScriptLexer = corePsParser.PostScriptLexer;
  35420. var PostScriptParser = corePsParser.PostScriptParser;
  35421. var PDFFunction = (function PDFFunctionClosure() {
  35422. var CONSTRUCT_SAMPLED = 0;
  35423. var CONSTRUCT_INTERPOLATED = 2;
  35424. var CONSTRUCT_STICHED = 3;
  35425. var CONSTRUCT_POSTSCRIPT = 4;
  35426. return {
  35427. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  35428. str) {
  35429. var i, ii;
  35430. var length = 1;
  35431. for (i = 0, ii = size.length; i < ii; i++) {
  35432. length *= size[i];
  35433. }
  35434. length *= outputSize;
  35435. var array = new Array(length);
  35436. var codeSize = 0;
  35437. var codeBuf = 0;
  35438. // 32 is a valid bps so shifting won't work
  35439. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  35440. var strBytes = str.getBytes((length * bps + 7) / 8);
  35441. var strIdx = 0;
  35442. for (i = 0; i < length; i++) {
  35443. while (codeSize < bps) {
  35444. codeBuf <<= 8;
  35445. codeBuf |= strBytes[strIdx++];
  35446. codeSize += 8;
  35447. }
  35448. codeSize -= bps;
  35449. array[i] = (codeBuf >> codeSize) * sampleMul;
  35450. codeBuf &= (1 << codeSize) - 1;
  35451. }
  35452. return array;
  35453. },
  35454. getIR: function PDFFunction_getIR(xref, fn) {
  35455. var dict = fn.dict;
  35456. if (!dict) {
  35457. dict = fn;
  35458. }
  35459. var types = [this.constructSampled,
  35460. null,
  35461. this.constructInterpolated,
  35462. this.constructStiched,
  35463. this.constructPostScript];
  35464. var typeNum = dict.get('FunctionType');
  35465. var typeFn = types[typeNum];
  35466. if (!typeFn) {
  35467. error('Unknown type of function');
  35468. }
  35469. return typeFn.call(this, fn, dict, xref);
  35470. },
  35471. fromIR: function PDFFunction_fromIR(IR) {
  35472. var type = IR[0];
  35473. switch (type) {
  35474. case CONSTRUCT_SAMPLED:
  35475. return this.constructSampledFromIR(IR);
  35476. case CONSTRUCT_INTERPOLATED:
  35477. return this.constructInterpolatedFromIR(IR);
  35478. case CONSTRUCT_STICHED:
  35479. return this.constructStichedFromIR(IR);
  35480. //case CONSTRUCT_POSTSCRIPT:
  35481. default:
  35482. return this.constructPostScriptFromIR(IR);
  35483. }
  35484. },
  35485. parse: function PDFFunction_parse(xref, fn) {
  35486. var IR = this.getIR(xref, fn);
  35487. return this.fromIR(IR);
  35488. },
  35489. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  35490. if (!isArray(fnObj)) {
  35491. // not an array -- parsing as regular function
  35492. return this.parse(xref, fnObj);
  35493. }
  35494. var fnArray = [];
  35495. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  35496. var obj = xref.fetchIfRef(fnObj[j]);
  35497. fnArray.push(PDFFunction.parse(xref, obj));
  35498. }
  35499. return function (src, srcOffset, dest, destOffset) {
  35500. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  35501. fnArray[i](src, srcOffset, dest, destOffset + i);
  35502. }
  35503. };
  35504. },
  35505. constructSampled: function PDFFunction_constructSampled(str, dict) {
  35506. function toMultiArray(arr) {
  35507. var inputLength = arr.length;
  35508. var out = [];
  35509. var index = 0;
  35510. for (var i = 0; i < inputLength; i += 2) {
  35511. out[index] = [arr[i], arr[i + 1]];
  35512. ++index;
  35513. }
  35514. return out;
  35515. }
  35516. var domain = dict.getArray('Domain');
  35517. var range = dict.getArray('Range');
  35518. if (!domain || !range) {
  35519. error('No domain or range');
  35520. }
  35521. var inputSize = domain.length / 2;
  35522. var outputSize = range.length / 2;
  35523. domain = toMultiArray(domain);
  35524. range = toMultiArray(range);
  35525. var size = dict.get('Size');
  35526. var bps = dict.get('BitsPerSample');
  35527. var order = dict.get('Order') || 1;
  35528. if (order !== 1) {
  35529. // No description how cubic spline interpolation works in PDF32000:2008
  35530. // As in poppler, ignoring order, linear interpolation may work as good
  35531. info('No support for cubic spline interpolation: ' + order);
  35532. }
  35533. var encode = dict.getArray('Encode');
  35534. if (!encode) {
  35535. encode = [];
  35536. for (var i = 0; i < inputSize; ++i) {
  35537. encode.push(0);
  35538. encode.push(size[i] - 1);
  35539. }
  35540. }
  35541. encode = toMultiArray(encode);
  35542. var decode = dict.getArray('Decode');
  35543. if (!decode) {
  35544. decode = range;
  35545. } else {
  35546. decode = toMultiArray(decode);
  35547. }
  35548. var samples = this.getSampleArray(size, outputSize, bps, str);
  35549. return [
  35550. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  35551. outputSize, Math.pow(2, bps) - 1, range
  35552. ];
  35553. },
  35554. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  35555. // See chapter 3, page 109 of the PDF reference
  35556. function interpolate(x, xmin, xmax, ymin, ymax) {
  35557. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  35558. }
  35559. return function constructSampledFromIRResult(src, srcOffset,
  35560. dest, destOffset) {
  35561. // See chapter 3, page 110 of the PDF reference.
  35562. var m = IR[1];
  35563. var domain = IR[2];
  35564. var encode = IR[3];
  35565. var decode = IR[4];
  35566. var samples = IR[5];
  35567. var size = IR[6];
  35568. var n = IR[7];
  35569. //var mask = IR[8];
  35570. var range = IR[9];
  35571. // Building the cube vertices: its part and sample index
  35572. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  35573. var cubeVertices = 1 << m;
  35574. var cubeN = new Float64Array(cubeVertices);
  35575. var cubeVertex = new Uint32Array(cubeVertices);
  35576. var i, j;
  35577. for (j = 0; j < cubeVertices; j++) {
  35578. cubeN[j] = 1;
  35579. }
  35580. var k = n, pos = 1;
  35581. // Map x_i to y_j for 0 <= i < m using the sampled function.
  35582. for (i = 0; i < m; ++i) {
  35583. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  35584. var domain_2i = domain[i][0];
  35585. var domain_2i_1 = domain[i][1];
  35586. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  35587. domain_2i_1);
  35588. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  35589. // Encode_2i, Encode_2i+1)
  35590. var e = interpolate(xi, domain_2i, domain_2i_1,
  35591. encode[i][0], encode[i][1]);
  35592. // e_i' = min(max(e_i, 0), Size_i - 1)
  35593. var size_i = size[i];
  35594. e = Math.min(Math.max(e, 0), size_i - 1);
  35595. // Adjusting the cube: N and vertex sample index
  35596. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  35597. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  35598. var n1 = e - e0; // (e - e0) / (e1 - e0);
  35599. var offset0 = e0 * k;
  35600. var offset1 = offset0 + k; // e1 * k
  35601. for (j = 0; j < cubeVertices; j++) {
  35602. if (j & pos) {
  35603. cubeN[j] *= n1;
  35604. cubeVertex[j] += offset1;
  35605. } else {
  35606. cubeN[j] *= n0;
  35607. cubeVertex[j] += offset0;
  35608. }
  35609. }
  35610. k *= size_i;
  35611. pos <<= 1;
  35612. }
  35613. for (j = 0; j < n; ++j) {
  35614. // Sum all cube vertices' samples portions
  35615. var rj = 0;
  35616. for (i = 0; i < cubeVertices; i++) {
  35617. rj += samples[cubeVertex[i] + j] * cubeN[i];
  35618. }
  35619. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  35620. // Decode_2j, Decode_2j+1)
  35621. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  35622. // y_j = min(max(r_j, range_2j), range_2j+1)
  35623. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  35624. range[j][1]);
  35625. }
  35626. };
  35627. },
  35628. constructInterpolated: function PDFFunction_constructInterpolated(str,
  35629. dict) {
  35630. var c0 = dict.getArray('C0') || [0];
  35631. var c1 = dict.getArray('C1') || [1];
  35632. var n = dict.get('N');
  35633. if (!isArray(c0) || !isArray(c1)) {
  35634. error('Illegal dictionary for interpolated function');
  35635. }
  35636. var length = c0.length;
  35637. var diff = [];
  35638. for (var i = 0; i < length; ++i) {
  35639. diff.push(c1[i] - c0[i]);
  35640. }
  35641. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  35642. },
  35643. constructInterpolatedFromIR:
  35644. function PDFFunction_constructInterpolatedFromIR(IR) {
  35645. var c0 = IR[1];
  35646. var diff = IR[2];
  35647. var n = IR[3];
  35648. var length = diff.length;
  35649. return function constructInterpolatedFromIRResult(src, srcOffset,
  35650. dest, destOffset) {
  35651. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  35652. for (var j = 0; j < length; ++j) {
  35653. dest[destOffset + j] = c0[j] + (x * diff[j]);
  35654. }
  35655. };
  35656. },
  35657. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  35658. var domain = dict.getArray('Domain');
  35659. if (!domain) {
  35660. error('No domain');
  35661. }
  35662. var inputSize = domain.length / 2;
  35663. if (inputSize !== 1) {
  35664. error('Bad domain for stiched function');
  35665. }
  35666. var fnRefs = dict.get('Functions');
  35667. var fns = [];
  35668. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  35669. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  35670. }
  35671. var bounds = dict.getArray('Bounds');
  35672. var encode = dict.getArray('Encode');
  35673. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  35674. },
  35675. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  35676. var domain = IR[1];
  35677. var bounds = IR[2];
  35678. var encode = IR[3];
  35679. var fnsIR = IR[4];
  35680. var fns = [];
  35681. var tmpBuf = new Float32Array(1);
  35682. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  35683. fns.push(PDFFunction.fromIR(fnsIR[i]));
  35684. }
  35685. return function constructStichedFromIRResult(src, srcOffset,
  35686. dest, destOffset) {
  35687. var clip = function constructStichedFromIRClip(v, min, max) {
  35688. if (v > max) {
  35689. v = max;
  35690. } else if (v < min) {
  35691. v = min;
  35692. }
  35693. return v;
  35694. };
  35695. // clip to domain
  35696. var v = clip(src[srcOffset], domain[0], domain[1]);
  35697. // calculate which bound the value is in
  35698. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  35699. if (v < bounds[i]) {
  35700. break;
  35701. }
  35702. }
  35703. // encode value into domain of function
  35704. var dmin = domain[0];
  35705. if (i > 0) {
  35706. dmin = bounds[i - 1];
  35707. }
  35708. var dmax = domain[1];
  35709. if (i < bounds.length) {
  35710. dmax = bounds[i];
  35711. }
  35712. var rmin = encode[2 * i];
  35713. var rmax = encode[2 * i + 1];
  35714. // Prevent the value from becoming NaN as a result
  35715. // of division by zero (fixes issue6113.pdf).
  35716. tmpBuf[0] = dmin === dmax ? rmin :
  35717. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  35718. // call the appropriate function
  35719. fns[i](tmpBuf, 0, dest, destOffset);
  35720. };
  35721. },
  35722. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  35723. xref) {
  35724. var domain = dict.getArray('Domain');
  35725. var range = dict.getArray('Range');
  35726. if (!domain) {
  35727. error('No domain.');
  35728. }
  35729. if (!range) {
  35730. error('No range.');
  35731. }
  35732. var lexer = new PostScriptLexer(fn);
  35733. var parser = new PostScriptParser(lexer);
  35734. var code = parser.parse();
  35735. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  35736. },
  35737. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  35738. IR) {
  35739. var domain = IR[1];
  35740. var range = IR[2];
  35741. var code = IR[3];
  35742. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  35743. if (compiled) {
  35744. // Compiled function consists of simple expressions such as addition,
  35745. // subtraction, Math.max, and also contains 'var' and 'return'
  35746. // statements. See the generation in the PostScriptCompiler below.
  35747. /*jshint -W054 */
  35748. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  35749. }
  35750. info('Unable to compile PS function');
  35751. var numOutputs = range.length >> 1;
  35752. var numInputs = domain.length >> 1;
  35753. var evaluator = new PostScriptEvaluator(code);
  35754. // Cache the values for a big speed up, the cache size is limited though
  35755. // since the number of possible values can be huge from a PS function.
  35756. var cache = Object.create(null);
  35757. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  35758. // seen in our tests.
  35759. var MAX_CACHE_SIZE = 2048 * 4;
  35760. var cache_available = MAX_CACHE_SIZE;
  35761. var tmpBuf = new Float32Array(numInputs);
  35762. return function constructPostScriptFromIRResult(src, srcOffset,
  35763. dest, destOffset) {
  35764. var i, value;
  35765. var key = '';
  35766. var input = tmpBuf;
  35767. for (i = 0; i < numInputs; i++) {
  35768. value = src[srcOffset + i];
  35769. input[i] = value;
  35770. key += value + '_';
  35771. }
  35772. var cachedValue = cache[key];
  35773. if (cachedValue !== undefined) {
  35774. dest.set(cachedValue, destOffset);
  35775. return;
  35776. }
  35777. var output = new Float32Array(numOutputs);
  35778. var stack = evaluator.execute(input);
  35779. var stackIndex = stack.length - numOutputs;
  35780. for (i = 0; i < numOutputs; i++) {
  35781. value = stack[stackIndex + i];
  35782. var bound = range[i * 2];
  35783. if (value < bound) {
  35784. value = bound;
  35785. } else {
  35786. bound = range[i * 2 +1];
  35787. if (value > bound) {
  35788. value = bound;
  35789. }
  35790. }
  35791. output[i] = value;
  35792. }
  35793. if (cache_available > 0) {
  35794. cache_available--;
  35795. cache[key] = output;
  35796. }
  35797. dest.set(output, destOffset);
  35798. };
  35799. }
  35800. };
  35801. })();
  35802. function isPDFFunction(v) {
  35803. var fnDict;
  35804. if (typeof v !== 'object') {
  35805. return false;
  35806. } else if (isDict(v)) {
  35807. fnDict = v;
  35808. } else if (isStream(v)) {
  35809. fnDict = v.dict;
  35810. } else {
  35811. return false;
  35812. }
  35813. return fnDict.has('FunctionType');
  35814. }
  35815. var PostScriptStack = (function PostScriptStackClosure() {
  35816. var MAX_STACK_SIZE = 100;
  35817. function PostScriptStack(initialStack) {
  35818. this.stack = !initialStack ? [] :
  35819. Array.prototype.slice.call(initialStack, 0);
  35820. }
  35821. PostScriptStack.prototype = {
  35822. push: function PostScriptStack_push(value) {
  35823. if (this.stack.length >= MAX_STACK_SIZE) {
  35824. error('PostScript function stack overflow.');
  35825. }
  35826. this.stack.push(value);
  35827. },
  35828. pop: function PostScriptStack_pop() {
  35829. if (this.stack.length <= 0) {
  35830. error('PostScript function stack underflow.');
  35831. }
  35832. return this.stack.pop();
  35833. },
  35834. copy: function PostScriptStack_copy(n) {
  35835. if (this.stack.length + n >= MAX_STACK_SIZE) {
  35836. error('PostScript function stack overflow.');
  35837. }
  35838. var stack = this.stack;
  35839. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  35840. stack.push(stack[i]);
  35841. }
  35842. },
  35843. index: function PostScriptStack_index(n) {
  35844. this.push(this.stack[this.stack.length - n - 1]);
  35845. },
  35846. // rotate the last n stack elements p times
  35847. roll: function PostScriptStack_roll(n, p) {
  35848. var stack = this.stack;
  35849. var l = stack.length - n;
  35850. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  35851. for (i = l, j = r; i < j; i++, j--) {
  35852. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35853. }
  35854. for (i = l, j = c - 1; i < j; i++, j--) {
  35855. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35856. }
  35857. for (i = c, j = r; i < j; i++, j--) {
  35858. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35859. }
  35860. }
  35861. };
  35862. return PostScriptStack;
  35863. })();
  35864. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  35865. function PostScriptEvaluator(operators) {
  35866. this.operators = operators;
  35867. }
  35868. PostScriptEvaluator.prototype = {
  35869. execute: function PostScriptEvaluator_execute(initialStack) {
  35870. var stack = new PostScriptStack(initialStack);
  35871. var counter = 0;
  35872. var operators = this.operators;
  35873. var length = operators.length;
  35874. var operator, a, b;
  35875. while (counter < length) {
  35876. operator = operators[counter++];
  35877. if (typeof operator === 'number') {
  35878. // Operator is really an operand and should be pushed to the stack.
  35879. stack.push(operator);
  35880. continue;
  35881. }
  35882. switch (operator) {
  35883. // non standard ps operators
  35884. case 'jz': // jump if false
  35885. b = stack.pop();
  35886. a = stack.pop();
  35887. if (!a) {
  35888. counter = b;
  35889. }
  35890. break;
  35891. case 'j': // jump
  35892. a = stack.pop();
  35893. counter = a;
  35894. break;
  35895. // all ps operators in alphabetical order (excluding if/ifelse)
  35896. case 'abs':
  35897. a = stack.pop();
  35898. stack.push(Math.abs(a));
  35899. break;
  35900. case 'add':
  35901. b = stack.pop();
  35902. a = stack.pop();
  35903. stack.push(a + b);
  35904. break;
  35905. case 'and':
  35906. b = stack.pop();
  35907. a = stack.pop();
  35908. if (isBool(a) && isBool(b)) {
  35909. stack.push(a && b);
  35910. } else {
  35911. stack.push(a & b);
  35912. }
  35913. break;
  35914. case 'atan':
  35915. a = stack.pop();
  35916. stack.push(Math.atan(a));
  35917. break;
  35918. case 'bitshift':
  35919. b = stack.pop();
  35920. a = stack.pop();
  35921. if (a > 0) {
  35922. stack.push(a << b);
  35923. } else {
  35924. stack.push(a >> b);
  35925. }
  35926. break;
  35927. case 'ceiling':
  35928. a = stack.pop();
  35929. stack.push(Math.ceil(a));
  35930. break;
  35931. case 'copy':
  35932. a = stack.pop();
  35933. stack.copy(a);
  35934. break;
  35935. case 'cos':
  35936. a = stack.pop();
  35937. stack.push(Math.cos(a));
  35938. break;
  35939. case 'cvi':
  35940. a = stack.pop() | 0;
  35941. stack.push(a);
  35942. break;
  35943. case 'cvr':
  35944. // noop
  35945. break;
  35946. case 'div':
  35947. b = stack.pop();
  35948. a = stack.pop();
  35949. stack.push(a / b);
  35950. break;
  35951. case 'dup':
  35952. stack.copy(1);
  35953. break;
  35954. case 'eq':
  35955. b = stack.pop();
  35956. a = stack.pop();
  35957. stack.push(a === b);
  35958. break;
  35959. case 'exch':
  35960. stack.roll(2, 1);
  35961. break;
  35962. case 'exp':
  35963. b = stack.pop();
  35964. a = stack.pop();
  35965. stack.push(Math.pow(a, b));
  35966. break;
  35967. case 'false':
  35968. stack.push(false);
  35969. break;
  35970. case 'floor':
  35971. a = stack.pop();
  35972. stack.push(Math.floor(a));
  35973. break;
  35974. case 'ge':
  35975. b = stack.pop();
  35976. a = stack.pop();
  35977. stack.push(a >= b);
  35978. break;
  35979. case 'gt':
  35980. b = stack.pop();
  35981. a = stack.pop();
  35982. stack.push(a > b);
  35983. break;
  35984. case 'idiv':
  35985. b = stack.pop();
  35986. a = stack.pop();
  35987. stack.push((a / b) | 0);
  35988. break;
  35989. case 'index':
  35990. a = stack.pop();
  35991. stack.index(a);
  35992. break;
  35993. case 'le':
  35994. b = stack.pop();
  35995. a = stack.pop();
  35996. stack.push(a <= b);
  35997. break;
  35998. case 'ln':
  35999. a = stack.pop();
  36000. stack.push(Math.log(a));
  36001. break;
  36002. case 'log':
  36003. a = stack.pop();
  36004. stack.push(Math.log(a) / Math.LN10);
  36005. break;
  36006. case 'lt':
  36007. b = stack.pop();
  36008. a = stack.pop();
  36009. stack.push(a < b);
  36010. break;
  36011. case 'mod':
  36012. b = stack.pop();
  36013. a = stack.pop();
  36014. stack.push(a % b);
  36015. break;
  36016. case 'mul':
  36017. b = stack.pop();
  36018. a = stack.pop();
  36019. stack.push(a * b);
  36020. break;
  36021. case 'ne':
  36022. b = stack.pop();
  36023. a = stack.pop();
  36024. stack.push(a !== b);
  36025. break;
  36026. case 'neg':
  36027. a = stack.pop();
  36028. stack.push(-a);
  36029. break;
  36030. case 'not':
  36031. a = stack.pop();
  36032. if (isBool(a)) {
  36033. stack.push(!a);
  36034. } else {
  36035. stack.push(~a);
  36036. }
  36037. break;
  36038. case 'or':
  36039. b = stack.pop();
  36040. a = stack.pop();
  36041. if (isBool(a) && isBool(b)) {
  36042. stack.push(a || b);
  36043. } else {
  36044. stack.push(a | b);
  36045. }
  36046. break;
  36047. case 'pop':
  36048. stack.pop();
  36049. break;
  36050. case 'roll':
  36051. b = stack.pop();
  36052. a = stack.pop();
  36053. stack.roll(a, b);
  36054. break;
  36055. case 'round':
  36056. a = stack.pop();
  36057. stack.push(Math.round(a));
  36058. break;
  36059. case 'sin':
  36060. a = stack.pop();
  36061. stack.push(Math.sin(a));
  36062. break;
  36063. case 'sqrt':
  36064. a = stack.pop();
  36065. stack.push(Math.sqrt(a));
  36066. break;
  36067. case 'sub':
  36068. b = stack.pop();
  36069. a = stack.pop();
  36070. stack.push(a - b);
  36071. break;
  36072. case 'true':
  36073. stack.push(true);
  36074. break;
  36075. case 'truncate':
  36076. a = stack.pop();
  36077. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  36078. stack.push(a);
  36079. break;
  36080. case 'xor':
  36081. b = stack.pop();
  36082. a = stack.pop();
  36083. if (isBool(a) && isBool(b)) {
  36084. stack.push(a !== b);
  36085. } else {
  36086. stack.push(a ^ b);
  36087. }
  36088. break;
  36089. default:
  36090. error('Unknown operator ' + operator);
  36091. break;
  36092. }
  36093. }
  36094. return stack.stack;
  36095. }
  36096. };
  36097. return PostScriptEvaluator;
  36098. })();
  36099. // Most of the PDFs functions consist of simple operations such as:
  36100. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  36101. //
  36102. // We can compile most of such programs, and at the same moment, we can
  36103. // optimize some expressions using basic math properties. Keeping track of
  36104. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  36105. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  36106. function AstNode(type) {
  36107. this.type = type;
  36108. }
  36109. AstNode.prototype.visit = function (visitor) {
  36110. throw new Error('abstract method');
  36111. };
  36112. function AstArgument(index, min, max) {
  36113. AstNode.call(this, 'args');
  36114. this.index = index;
  36115. this.min = min;
  36116. this.max = max;
  36117. }
  36118. AstArgument.prototype = Object.create(AstNode.prototype);
  36119. AstArgument.prototype.visit = function (visitor) {
  36120. visitor.visitArgument(this);
  36121. };
  36122. function AstLiteral(number) {
  36123. AstNode.call(this, 'literal');
  36124. this.number = number;
  36125. this.min = number;
  36126. this.max = number;
  36127. }
  36128. AstLiteral.prototype = Object.create(AstNode.prototype);
  36129. AstLiteral.prototype.visit = function (visitor) {
  36130. visitor.visitLiteral(this);
  36131. };
  36132. function AstBinaryOperation(op, arg1, arg2, min, max) {
  36133. AstNode.call(this, 'binary');
  36134. this.op = op;
  36135. this.arg1 = arg1;
  36136. this.arg2 = arg2;
  36137. this.min = min;
  36138. this.max = max;
  36139. }
  36140. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  36141. AstBinaryOperation.prototype.visit = function (visitor) {
  36142. visitor.visitBinaryOperation(this);
  36143. };
  36144. function AstMin(arg, max) {
  36145. AstNode.call(this, 'max');
  36146. this.arg = arg;
  36147. this.min = arg.min;
  36148. this.max = max;
  36149. }
  36150. AstMin.prototype = Object.create(AstNode.prototype);
  36151. AstMin.prototype.visit = function (visitor) {
  36152. visitor.visitMin(this);
  36153. };
  36154. function AstVariable(index, min, max) {
  36155. AstNode.call(this, 'var');
  36156. this.index = index;
  36157. this.min = min;
  36158. this.max = max;
  36159. }
  36160. AstVariable.prototype = Object.create(AstNode.prototype);
  36161. AstVariable.prototype.visit = function (visitor) {
  36162. visitor.visitVariable(this);
  36163. };
  36164. function AstVariableDefinition(variable, arg) {
  36165. AstNode.call(this, 'definition');
  36166. this.variable = variable;
  36167. this.arg = arg;
  36168. }
  36169. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  36170. AstVariableDefinition.prototype.visit = function (visitor) {
  36171. visitor.visitVariableDefinition(this);
  36172. };
  36173. function ExpressionBuilderVisitor() {
  36174. this.parts = [];
  36175. }
  36176. ExpressionBuilderVisitor.prototype = {
  36177. visitArgument: function (arg) {
  36178. this.parts.push('Math.max(', arg.min, ', Math.min(',
  36179. arg.max, ', src[srcOffset + ', arg.index, ']))');
  36180. },
  36181. visitVariable: function (variable) {
  36182. this.parts.push('v', variable.index);
  36183. },
  36184. visitLiteral: function (literal) {
  36185. this.parts.push(literal.number);
  36186. },
  36187. visitBinaryOperation: function (operation) {
  36188. this.parts.push('(');
  36189. operation.arg1.visit(this);
  36190. this.parts.push(' ', operation.op, ' ');
  36191. operation.arg2.visit(this);
  36192. this.parts.push(')');
  36193. },
  36194. visitVariableDefinition: function (definition) {
  36195. this.parts.push('var ');
  36196. definition.variable.visit(this);
  36197. this.parts.push(' = ');
  36198. definition.arg.visit(this);
  36199. this.parts.push(';');
  36200. },
  36201. visitMin: function (max) {
  36202. this.parts.push('Math.min(');
  36203. max.arg.visit(this);
  36204. this.parts.push(', ', max.max, ')');
  36205. },
  36206. toString: function () {
  36207. return this.parts.join('');
  36208. }
  36209. };
  36210. function buildAddOperation(num1, num2) {
  36211. if (num2.type === 'literal' && num2.number === 0) {
  36212. // optimization: second operand is 0
  36213. return num1;
  36214. }
  36215. if (num1.type === 'literal' && num1.number === 0) {
  36216. // optimization: first operand is 0
  36217. return num2;
  36218. }
  36219. if (num2.type === 'literal' && num1.type === 'literal') {
  36220. // optimization: operands operand are literals
  36221. return new AstLiteral(num1.number + num2.number);
  36222. }
  36223. return new AstBinaryOperation('+', num1, num2,
  36224. num1.min + num2.min, num1.max + num2.max);
  36225. }
  36226. function buildMulOperation(num1, num2) {
  36227. if (num2.type === 'literal') {
  36228. // optimization: second operands is a literal...
  36229. if (num2.number === 0) {
  36230. return new AstLiteral(0); // and it's 0
  36231. } else if (num2.number === 1) {
  36232. return num1; // and it's 1
  36233. } else if (num1.type === 'literal') {
  36234. // ... and first operands is a literal too
  36235. return new AstLiteral(num1.number * num2.number);
  36236. }
  36237. }
  36238. if (num1.type === 'literal') {
  36239. // optimization: first operands is a literal...
  36240. if (num1.number === 0) {
  36241. return new AstLiteral(0); // and it's 0
  36242. } else if (num1.number === 1) {
  36243. return num2; // and it's 1
  36244. }
  36245. }
  36246. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  36247. num1.max * num2.min, num1.max * num2.max);
  36248. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  36249. num1.max * num2.min, num1.max * num2.max);
  36250. return new AstBinaryOperation('*', num1, num2, min, max);
  36251. }
  36252. function buildSubOperation(num1, num2) {
  36253. if (num2.type === 'literal') {
  36254. // optimization: second operands is a literal...
  36255. if (num2.number === 0) {
  36256. return num1; // ... and it's 0
  36257. } else if (num1.type === 'literal') {
  36258. // ... and first operands is a literal too
  36259. return new AstLiteral(num1.number - num2.number);
  36260. }
  36261. }
  36262. if (num2.type === 'binary' && num2.op === '-' &&
  36263. num1.type === 'literal' && num1.number === 1 &&
  36264. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  36265. // optimization for case: 1 - (1 - x)
  36266. return num2.arg2;
  36267. }
  36268. return new AstBinaryOperation('-', num1, num2,
  36269. num1.min - num2.max, num1.max - num2.min);
  36270. }
  36271. function buildMinOperation(num1, max) {
  36272. if (num1.min >= max) {
  36273. // optimization: num1 min value is not less than required max
  36274. return new AstLiteral(max); // just returning max
  36275. } else if (num1.max <= max) {
  36276. // optimization: num1 max value is not greater than required max
  36277. return num1; // just returning an argument
  36278. }
  36279. return new AstMin(num1, max);
  36280. }
  36281. function PostScriptCompiler() {}
  36282. PostScriptCompiler.prototype = {
  36283. compile: function PostScriptCompiler_compile(code, domain, range) {
  36284. var stack = [];
  36285. var i, ii;
  36286. var instructions = [];
  36287. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  36288. var lastRegister = 0;
  36289. var n, j;
  36290. var num1, num2, ast1, ast2, tmpVar, item;
  36291. for (i = 0; i < inputSize; i++) {
  36292. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  36293. }
  36294. for (i = 0, ii = code.length; i < ii; i++) {
  36295. item = code[i];
  36296. if (typeof item === 'number') {
  36297. stack.push(new AstLiteral(item));
  36298. continue;
  36299. }
  36300. switch (item) {
  36301. case 'add':
  36302. if (stack.length < 2) {
  36303. return null;
  36304. }
  36305. num2 = stack.pop();
  36306. num1 = stack.pop();
  36307. stack.push(buildAddOperation(num1, num2));
  36308. break;
  36309. case 'cvr':
  36310. if (stack.length < 1) {
  36311. return null;
  36312. }
  36313. break;
  36314. case 'mul':
  36315. if (stack.length < 2) {
  36316. return null;
  36317. }
  36318. num2 = stack.pop();
  36319. num1 = stack.pop();
  36320. stack.push(buildMulOperation(num1, num2));
  36321. break;
  36322. case 'sub':
  36323. if (stack.length < 2) {
  36324. return null;
  36325. }
  36326. num2 = stack.pop();
  36327. num1 = stack.pop();
  36328. stack.push(buildSubOperation(num1, num2));
  36329. break;
  36330. case 'exch':
  36331. if (stack.length < 2) {
  36332. return null;
  36333. }
  36334. ast1 = stack.pop(); ast2 = stack.pop();
  36335. stack.push(ast1, ast2);
  36336. break;
  36337. case 'pop':
  36338. if (stack.length < 1) {
  36339. return null;
  36340. }
  36341. stack.pop();
  36342. break;
  36343. case 'index':
  36344. if (stack.length < 1) {
  36345. return null;
  36346. }
  36347. num1 = stack.pop();
  36348. if (num1.type !== 'literal') {
  36349. return null;
  36350. }
  36351. n = num1.number;
  36352. if (n < 0 || (n|0) !== n || stack.length < n) {
  36353. return null;
  36354. }
  36355. ast1 = stack[stack.length - n - 1];
  36356. if (ast1.type === 'literal' || ast1.type === 'var') {
  36357. stack.push(ast1);
  36358. break;
  36359. }
  36360. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36361. stack[stack.length - n - 1] = tmpVar;
  36362. stack.push(tmpVar);
  36363. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36364. break;
  36365. case 'dup':
  36366. if (stack.length < 1) {
  36367. return null;
  36368. }
  36369. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  36370. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  36371. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  36372. // special case of the commands sequence for the min operation
  36373. num1 = stack.pop();
  36374. stack.push(buildMinOperation(num1, code[i + 1]));
  36375. i += 6;
  36376. break;
  36377. }
  36378. ast1 = stack[stack.length - 1];
  36379. if (ast1.type === 'literal' || ast1.type === 'var') {
  36380. // we don't have to save into intermediate variable a literal or
  36381. // variable.
  36382. stack.push(ast1);
  36383. break;
  36384. }
  36385. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36386. stack[stack.length - 1] = tmpVar;
  36387. stack.push(tmpVar);
  36388. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36389. break;
  36390. case 'roll':
  36391. if (stack.length < 2) {
  36392. return null;
  36393. }
  36394. num2 = stack.pop();
  36395. num1 = stack.pop();
  36396. if (num2.type !== 'literal' || num1.type !== 'literal') {
  36397. // both roll operands must be numbers
  36398. return null;
  36399. }
  36400. j = num2.number;
  36401. n = num1.number;
  36402. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  36403. // ... and integers
  36404. return null;
  36405. }
  36406. j = ((j % n) + n) % n;
  36407. if (j === 0) {
  36408. break; // just skipping -- there are nothing to rotate
  36409. }
  36410. Array.prototype.push.apply(stack,
  36411. stack.splice(stack.length - n, n - j));
  36412. break;
  36413. default:
  36414. return null; // unsupported operator
  36415. }
  36416. }
  36417. if (stack.length !== outputSize) {
  36418. return null;
  36419. }
  36420. var result = [];
  36421. instructions.forEach(function (instruction) {
  36422. var statementBuilder = new ExpressionBuilderVisitor();
  36423. instruction.visit(statementBuilder);
  36424. result.push(statementBuilder.toString());
  36425. });
  36426. stack.forEach(function (expr, i) {
  36427. var statementBuilder = new ExpressionBuilderVisitor();
  36428. expr.visit(statementBuilder);
  36429. var min = range[i * 2], max = range[i * 2 + 1];
  36430. var out = [statementBuilder.toString()];
  36431. if (min > expr.min) {
  36432. out.unshift('Math.max(', min, ', ');
  36433. out.push(')');
  36434. }
  36435. if (max < expr.max) {
  36436. out.unshift('Math.min(', max, ', ');
  36437. out.push(')');
  36438. }
  36439. out.unshift('dest[destOffset + ', i, '] = ');
  36440. out.push(';');
  36441. result.push(out.join(''));
  36442. });
  36443. return result.join('\n');
  36444. }
  36445. };
  36446. return PostScriptCompiler;
  36447. })();
  36448. exports.isPDFFunction = isPDFFunction;
  36449. exports.PDFFunction = PDFFunction;
  36450. exports.PostScriptEvaluator = PostScriptEvaluator;
  36451. exports.PostScriptCompiler = PostScriptCompiler;
  36452. }));
  36453. (function (root, factory) {
  36454. {
  36455. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  36456. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  36457. root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  36458. }
  36459. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  36460. displayMetadata, displayDOMUtils, amdRequire) {
  36461. var InvalidPDFException = sharedUtil.InvalidPDFException;
  36462. var MessageHandler = sharedUtil.MessageHandler;
  36463. var MissingPDFException = sharedUtil.MissingPDFException;
  36464. var PageViewport = sharedUtil.PageViewport;
  36465. var PasswordResponses = sharedUtil.PasswordResponses;
  36466. var PasswordException = sharedUtil.PasswordException;
  36467. var StatTimer = sharedUtil.StatTimer;
  36468. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  36469. var UnknownErrorException = sharedUtil.UnknownErrorException;
  36470. var Util = sharedUtil.Util;
  36471. var createPromiseCapability = sharedUtil.createPromiseCapability;
  36472. var error = sharedUtil.error;
  36473. var deprecated = sharedUtil.deprecated;
  36474. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  36475. var info = sharedUtil.info;
  36476. var isArrayBuffer = sharedUtil.isArrayBuffer;
  36477. var isSameOrigin = sharedUtil.isSameOrigin;
  36478. var loadJpegStream = sharedUtil.loadJpegStream;
  36479. var stringToBytes = sharedUtil.stringToBytes;
  36480. var globalScope = sharedUtil.globalScope;
  36481. var warn = sharedUtil.warn;
  36482. var FontFaceObject = displayFontLoader.FontFaceObject;
  36483. var FontLoader = displayFontLoader.FontLoader;
  36484. var CanvasGraphics = displayCanvas.CanvasGraphics;
  36485. var createScratchCanvas = displayCanvas.createScratchCanvas;
  36486. var Metadata = displayMetadata.Metadata;
  36487. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  36488. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  36489. var isWorkerDisabled = false;
  36490. var workerSrc;
  36491. var isPostMessageTransfersDisabled = false;
  36492. /**
  36493. * Document initialization / loading parameters object.
  36494. *
  36495. * @typedef {Object} DocumentInitParameters
  36496. * @property {string} url - The URL of the PDF.
  36497. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  36498. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  36499. * use atob() to convert it to a binary string first.
  36500. * @property {Object} httpHeaders - Basic authentication headers.
  36501. * @property {boolean} withCredentials - Indicates whether or not cross-site
  36502. * Access-Control requests should be made using credentials such as cookies
  36503. * or authorization headers. The default is false.
  36504. * @property {string} password - For decrypting password-protected PDFs.
  36505. * @property {TypedArray} initialData - A typed array with the first portion or
  36506. * all of the pdf data. Used by the extension since some data is already
  36507. * loaded before the switch to range requests.
  36508. * @property {number} length - The PDF file length. It's used for progress
  36509. * reports and range requests operations.
  36510. * @property {PDFDataRangeTransport} range
  36511. * @property {number} rangeChunkSize - Optional parameter to specify
  36512. * maximum number of bytes fetched per range request. The default value is
  36513. * 2^16 = 65536.
  36514. * @property {PDFWorker} worker - The worker that will be used for the loading
  36515. * and parsing of the PDF data.
  36516. */
  36517. /**
  36518. * @typedef {Object} PDFDocumentStats
  36519. * @property {Array} streamTypes - Used stream types in the document (an item
  36520. * is set to true if specific stream ID was used in the document).
  36521. * @property {Array} fontTypes - Used font type in the document (an item is set
  36522. * to true if specific font ID was used in the document).
  36523. */
  36524. /**
  36525. * This is the main entry point for loading a PDF and interacting with it.
  36526. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  36527. * is used, which means it must follow the same origin rules that any XHR does
  36528. * e.g. No cross domain requests without CORS.
  36529. *
  36530. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  36531. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  36532. * already populated with data or parameter object.
  36533. *
  36534. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  36535. * if you want to manually serve range requests for data in the PDF.
  36536. *
  36537. * @param {function} passwordCallback (deprecated) It is used to request a
  36538. * password if wrong or no password was provided. The callback receives two
  36539. * parameters: function that needs to be called with new password and reason
  36540. * (see {PasswordResponses}).
  36541. *
  36542. * @param {function} progressCallback (deprecated) It is used to be able to
  36543. * monitor the loading progress of the PDF file (necessary to implement e.g.
  36544. * a loading bar). The callback receives an {Object} with the properties:
  36545. * {number} loaded and {number} total.
  36546. *
  36547. * @return {PDFDocumentLoadingTask}
  36548. */
  36549. function getDocument(src, pdfDataRangeTransport,
  36550. passwordCallback, progressCallback) {
  36551. var task = new PDFDocumentLoadingTask();
  36552. // Support of the obsolete arguments (for compatibility with API v1.0)
  36553. if (arguments.length > 1) {
  36554. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  36555. 'passwordCallback or progressCallback argument');
  36556. }
  36557. if (pdfDataRangeTransport) {
  36558. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  36559. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  36560. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  36561. pdfDataRangeTransport.length = src.length;
  36562. pdfDataRangeTransport.initialData = src.initialData;
  36563. if (!pdfDataRangeTransport.abort) {
  36564. pdfDataRangeTransport.abort = function () {};
  36565. }
  36566. }
  36567. src = Object.create(src);
  36568. src.range = pdfDataRangeTransport;
  36569. }
  36570. task.onPassword = passwordCallback || null;
  36571. task.onProgress = progressCallback || null;
  36572. var source;
  36573. if (typeof src === 'string') {
  36574. source = { url: src };
  36575. } else if (isArrayBuffer(src)) {
  36576. source = { data: src };
  36577. } else if (src instanceof PDFDataRangeTransport) {
  36578. source = { range: src };
  36579. } else {
  36580. if (typeof src !== 'object') {
  36581. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  36582. 'string or a parameter object');
  36583. }
  36584. if (!src.url && !src.data && !src.range) {
  36585. error('Invalid parameter object: need either .data, .range or .url');
  36586. }
  36587. source = src;
  36588. }
  36589. var params = {};
  36590. var rangeTransport = null;
  36591. var worker = null;
  36592. for (var key in source) {
  36593. if (key === 'url' && typeof window !== 'undefined') {
  36594. // The full path is required in the 'url' field.
  36595. params[key] = new URL(source[key], window.location).href;
  36596. continue;
  36597. } else if (key === 'range') {
  36598. rangeTransport = source[key];
  36599. continue;
  36600. } else if (key === 'worker') {
  36601. worker = source[key];
  36602. continue;
  36603. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  36604. // Converting string or array-like data to Uint8Array.
  36605. var pdfBytes = source[key];
  36606. if (typeof pdfBytes === 'string') {
  36607. params[key] = stringToBytes(pdfBytes);
  36608. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  36609. !isNaN(pdfBytes.length)) {
  36610. params[key] = new Uint8Array(pdfBytes);
  36611. } else if (isArrayBuffer(pdfBytes)) {
  36612. params[key] = new Uint8Array(pdfBytes);
  36613. } else {
  36614. error('Invalid PDF binary data: either typed array, string or ' +
  36615. 'array-like object is expected in the data property.');
  36616. }
  36617. continue;
  36618. }
  36619. params[key] = source[key];
  36620. }
  36621. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  36622. if (!worker) {
  36623. // Worker was not provided -- creating and owning our own.
  36624. worker = new PDFWorker();
  36625. task._worker = worker;
  36626. }
  36627. var docId = task.docId;
  36628. worker.promise.then(function () {
  36629. if (task.destroyed) {
  36630. throw new Error('Loading aborted');
  36631. }
  36632. return _fetchDocument(worker, params, rangeTransport, docId).then(
  36633. function (workerId) {
  36634. if (task.destroyed) {
  36635. throw new Error('Loading aborted');
  36636. }
  36637. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  36638. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  36639. task._transport = transport;
  36640. messageHandler.send('Ready', null);
  36641. });
  36642. }).catch(task._capability.reject);
  36643. return task;
  36644. }
  36645. /**
  36646. * Starts fetching of specified PDF document/data.
  36647. * @param {PDFWorker} worker
  36648. * @param {Object} source
  36649. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  36650. * @param {string} docId Unique document id, used as MessageHandler id.
  36651. * @returns {Promise} The promise, which is resolved when worker id of
  36652. * MessageHandler is known.
  36653. * @private
  36654. */
  36655. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  36656. if (worker.destroyed) {
  36657. return Promise.reject(new Error('Worker was destroyed'));
  36658. }
  36659. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  36660. source.disableStream = getDefaultSetting('disableStream');
  36661. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  36662. if (pdfDataRangeTransport) {
  36663. source.length = pdfDataRangeTransport.length;
  36664. source.initialData = pdfDataRangeTransport.initialData;
  36665. }
  36666. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  36667. docId: docId,
  36668. source: source,
  36669. disableRange: getDefaultSetting('disableRange'),
  36670. maxImageSize: getDefaultSetting('maxImageSize'),
  36671. cMapUrl: getDefaultSetting('cMapUrl'),
  36672. cMapPacked: getDefaultSetting('cMapPacked'),
  36673. disableFontFace: getDefaultSetting('disableFontFace'),
  36674. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  36675. postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
  36676. !isPostMessageTransfersDisabled,
  36677. }).then(function (workerId) {
  36678. if (worker.destroyed) {
  36679. throw new Error('Worker was destroyed');
  36680. }
  36681. return workerId;
  36682. });
  36683. }
  36684. /**
  36685. * PDF document loading operation.
  36686. * @class
  36687. * @alias PDFDocumentLoadingTask
  36688. */
  36689. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  36690. var nextDocumentId = 0;
  36691. /** @constructs PDFDocumentLoadingTask */
  36692. function PDFDocumentLoadingTask() {
  36693. this._capability = createPromiseCapability();
  36694. this._transport = null;
  36695. this._worker = null;
  36696. /**
  36697. * Unique document loading task id -- used in MessageHandlers.
  36698. * @type {string}
  36699. */
  36700. this.docId = 'd' + (nextDocumentId++);
  36701. /**
  36702. * Shows if loading task is destroyed.
  36703. * @type {boolean}
  36704. */
  36705. this.destroyed = false;
  36706. /**
  36707. * Callback to request a password if wrong or no password was provided.
  36708. * The callback receives two parameters: function that needs to be called
  36709. * with new password and reason (see {PasswordResponses}).
  36710. */
  36711. this.onPassword = null;
  36712. /**
  36713. * Callback to be able to monitor the loading progress of the PDF file
  36714. * (necessary to implement e.g. a loading bar). The callback receives
  36715. * an {Object} with the properties: {number} loaded and {number} total.
  36716. */
  36717. this.onProgress = null;
  36718. /**
  36719. * Callback to when unsupported feature is used. The callback receives
  36720. * an {UNSUPPORTED_FEATURES} argument.
  36721. */
  36722. this.onUnsupportedFeature = null;
  36723. }
  36724. PDFDocumentLoadingTask.prototype =
  36725. /** @lends PDFDocumentLoadingTask.prototype */ {
  36726. /**
  36727. * @return {Promise}
  36728. */
  36729. get promise() {
  36730. return this._capability.promise;
  36731. },
  36732. /**
  36733. * Aborts all network requests and destroys worker.
  36734. * @return {Promise} A promise that is resolved after destruction activity
  36735. * is completed.
  36736. */
  36737. destroy: function () {
  36738. this.destroyed = true;
  36739. var transportDestroyed = !this._transport ? Promise.resolve() :
  36740. this._transport.destroy();
  36741. return transportDestroyed.then(function () {
  36742. this._transport = null;
  36743. if (this._worker) {
  36744. this._worker.destroy();
  36745. this._worker = null;
  36746. }
  36747. }.bind(this));
  36748. },
  36749. /**
  36750. * Registers callbacks to indicate the document loading completion.
  36751. *
  36752. * @param {function} onFulfilled The callback for the loading completion.
  36753. * @param {function} onRejected The callback for the loading failure.
  36754. * @return {Promise} A promise that is resolved after the onFulfilled or
  36755. * onRejected callback.
  36756. */
  36757. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  36758. return this.promise.then.apply(this.promise, arguments);
  36759. }
  36760. };
  36761. return PDFDocumentLoadingTask;
  36762. })();
  36763. /**
  36764. * Abstract class to support range requests file loading.
  36765. * @class
  36766. * @alias PDFDataRangeTransport
  36767. * @param {number} length
  36768. * @param {Uint8Array} initialData
  36769. */
  36770. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  36771. function PDFDataRangeTransport(length, initialData) {
  36772. this.length = length;
  36773. this.initialData = initialData;
  36774. this._rangeListeners = [];
  36775. this._progressListeners = [];
  36776. this._progressiveReadListeners = [];
  36777. this._readyCapability = createPromiseCapability();
  36778. }
  36779. PDFDataRangeTransport.prototype =
  36780. /** @lends PDFDataRangeTransport.prototype */ {
  36781. addRangeListener:
  36782. function PDFDataRangeTransport_addRangeListener(listener) {
  36783. this._rangeListeners.push(listener);
  36784. },
  36785. addProgressListener:
  36786. function PDFDataRangeTransport_addProgressListener(listener) {
  36787. this._progressListeners.push(listener);
  36788. },
  36789. addProgressiveReadListener:
  36790. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  36791. this._progressiveReadListeners.push(listener);
  36792. },
  36793. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  36794. var listeners = this._rangeListeners;
  36795. for (var i = 0, n = listeners.length; i < n; ++i) {
  36796. listeners[i](begin, chunk);
  36797. }
  36798. },
  36799. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  36800. this._readyCapability.promise.then(function () {
  36801. var listeners = this._progressListeners;
  36802. for (var i = 0, n = listeners.length; i < n; ++i) {
  36803. listeners[i](loaded);
  36804. }
  36805. }.bind(this));
  36806. },
  36807. onDataProgressiveRead:
  36808. function PDFDataRangeTransport_onDataProgress(chunk) {
  36809. this._readyCapability.promise.then(function () {
  36810. var listeners = this._progressiveReadListeners;
  36811. for (var i = 0, n = listeners.length; i < n; ++i) {
  36812. listeners[i](chunk);
  36813. }
  36814. }.bind(this));
  36815. },
  36816. transportReady: function PDFDataRangeTransport_transportReady() {
  36817. this._readyCapability.resolve();
  36818. },
  36819. requestDataRange:
  36820. function PDFDataRangeTransport_requestDataRange(begin, end) {
  36821. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  36822. },
  36823. abort: function PDFDataRangeTransport_abort() {
  36824. }
  36825. };
  36826. return PDFDataRangeTransport;
  36827. })();
  36828. /**
  36829. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  36830. * properties that can be read synchronously.
  36831. * @class
  36832. * @alias PDFDocumentProxy
  36833. */
  36834. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  36835. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  36836. this.pdfInfo = pdfInfo;
  36837. this.transport = transport;
  36838. this.loadingTask = loadingTask;
  36839. }
  36840. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  36841. /**
  36842. * @return {number} Total number of pages the PDF contains.
  36843. */
  36844. get numPages() {
  36845. return this.pdfInfo.numPages;
  36846. },
  36847. /**
  36848. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  36849. * unique.
  36850. */
  36851. get fingerprint() {
  36852. return this.pdfInfo.fingerprint;
  36853. },
  36854. /**
  36855. * @param {number} pageNumber The page number to get. The first page is 1.
  36856. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  36857. * object.
  36858. */
  36859. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  36860. return this.transport.getPage(pageNumber);
  36861. },
  36862. /**
  36863. * @param {{num: number, gen: number}} ref The page reference. Must have
  36864. * the 'num' and 'gen' properties.
  36865. * @return {Promise} A promise that is resolved with the page index that is
  36866. * associated with the reference.
  36867. */
  36868. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  36869. return this.transport.getPageIndex(ref);
  36870. },
  36871. /**
  36872. * @return {Promise} A promise that is resolved with a lookup table for
  36873. * mapping named destinations to reference numbers.
  36874. *
  36875. * This can be slow for large documents: use getDestination instead
  36876. */
  36877. getDestinations: function PDFDocumentProxy_getDestinations() {
  36878. return this.transport.getDestinations();
  36879. },
  36880. /**
  36881. * @param {string} id The named destination to get.
  36882. * @return {Promise} A promise that is resolved with all information
  36883. * of the given named destination.
  36884. */
  36885. getDestination: function PDFDocumentProxy_getDestination(id) {
  36886. return this.transport.getDestination(id);
  36887. },
  36888. /**
  36889. * @return {Promise} A promise that is resolved with:
  36890. * an Array containing the pageLabels that correspond to the pageIndexes,
  36891. * or `null` when no pageLabels are present in the PDF file.
  36892. */
  36893. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  36894. return this.transport.getPageLabels();
  36895. },
  36896. /**
  36897. * @return {Promise} A promise that is resolved with a lookup table for
  36898. * mapping named attachments to their content.
  36899. */
  36900. getAttachments: function PDFDocumentProxy_getAttachments() {
  36901. return this.transport.getAttachments();
  36902. },
  36903. /**
  36904. * @return {Promise} A promise that is resolved with an array of all the
  36905. * JavaScript strings in the name tree.
  36906. */
  36907. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  36908. return this.transport.getJavaScript();
  36909. },
  36910. /**
  36911. * @return {Promise} A promise that is resolved with an {Array} that is a
  36912. * tree outline (if it has one) of the PDF. The tree is in the format of:
  36913. * [
  36914. * {
  36915. * title: string,
  36916. * bold: boolean,
  36917. * italic: boolean,
  36918. * color: rgb Uint8Array,
  36919. * dest: dest obj,
  36920. * url: string,
  36921. * items: array of more items like this
  36922. * },
  36923. * ...
  36924. * ].
  36925. */
  36926. getOutline: function PDFDocumentProxy_getOutline() {
  36927. return this.transport.getOutline();
  36928. },
  36929. /**
  36930. * @return {Promise} A promise that is resolved with an {Object} that has
  36931. * info and metadata properties. Info is an {Object} filled with anything
  36932. * available in the information dictionary and similarly metadata is a
  36933. * {Metadata} object with information from the metadata section of the PDF.
  36934. */
  36935. getMetadata: function PDFDocumentProxy_getMetadata() {
  36936. return this.transport.getMetadata();
  36937. },
  36938. /**
  36939. * @return {Promise} A promise that is resolved with a TypedArray that has
  36940. * the raw data from the PDF.
  36941. */
  36942. getData: function PDFDocumentProxy_getData() {
  36943. return this.transport.getData();
  36944. },
  36945. /**
  36946. * @return {Promise} A promise that is resolved when the document's data
  36947. * is loaded. It is resolved with an {Object} that contains the length
  36948. * property that indicates size of the PDF data in bytes.
  36949. */
  36950. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  36951. return this.transport.downloadInfoCapability.promise;
  36952. },
  36953. /**
  36954. * @return {Promise} A promise this is resolved with current stats about
  36955. * document structures (see {@link PDFDocumentStats}).
  36956. */
  36957. getStats: function PDFDocumentProxy_getStats() {
  36958. return this.transport.getStats();
  36959. },
  36960. /**
  36961. * Cleans up resources allocated by the document, e.g. created @font-face.
  36962. */
  36963. cleanup: function PDFDocumentProxy_cleanup() {
  36964. this.transport.startCleanup();
  36965. },
  36966. /**
  36967. * Destroys current document instance and terminates worker.
  36968. */
  36969. destroy: function PDFDocumentProxy_destroy() {
  36970. return this.loadingTask.destroy();
  36971. }
  36972. };
  36973. return PDFDocumentProxy;
  36974. })();
  36975. /**
  36976. * Page getTextContent parameters.
  36977. *
  36978. * @typedef {Object} getTextContentParameters
  36979. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  36980. * whitespace with standard spaces (0x20). The default value is `false`.
  36981. * @param {boolean} disableCombineTextItems - do not attempt to combine
  36982. * same line {@link TextItem}'s. The default value is `false`.
  36983. */
  36984. /**
  36985. * Page text content.
  36986. *
  36987. * @typedef {Object} TextContent
  36988. * @property {array} items - array of {@link TextItem}
  36989. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  36990. * name.
  36991. */
  36992. /**
  36993. * Page text content part.
  36994. *
  36995. * @typedef {Object} TextItem
  36996. * @property {string} str - text content.
  36997. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  36998. * @property {array} transform - transformation matrix.
  36999. * @property {number} width - width in device space.
  37000. * @property {number} height - height in device space.
  37001. * @property {string} fontName - font name used by pdf.js for converted font.
  37002. */
  37003. /**
  37004. * Text style.
  37005. *
  37006. * @typedef {Object} TextStyle
  37007. * @property {number} ascent - font ascent.
  37008. * @property {number} descent - font descent.
  37009. * @property {boolean} vertical - text is in vertical mode.
  37010. * @property {string} fontFamily - possible font family
  37011. */
  37012. /**
  37013. * Page annotation parameters.
  37014. *
  37015. * @typedef {Object} GetAnnotationsParameters
  37016. * @param {string} intent - Determines the annotations that will be fetched,
  37017. * can be either 'display' (viewable annotations) or 'print'
  37018. * (printable annotations).
  37019. * If the parameter is omitted, all annotations are fetched.
  37020. */
  37021. /**
  37022. * Page render parameters.
  37023. *
  37024. * @typedef {Object} RenderParameters
  37025. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  37026. * @property {PageViewport} viewport - Rendering viewport obtained by
  37027. * calling of PDFPage.getViewport method.
  37028. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  37029. * (default value is 'display').
  37030. * @property {Array} transform - (optional) Additional transform, applied
  37031. * just before viewport transform.
  37032. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  37033. * endLayout and appendImage functions.
  37034. * @property {function} continueCallback - (deprecated) A function that will be
  37035. * called each time the rendering is paused. To continue
  37036. * rendering call the function that is the first argument
  37037. * to the callback.
  37038. */
  37039. /**
  37040. * PDF page operator list.
  37041. *
  37042. * @typedef {Object} PDFOperatorList
  37043. * @property {Array} fnArray - Array containing the operator functions.
  37044. * @property {Array} argsArray - Array containing the arguments of the
  37045. * functions.
  37046. */
  37047. /**
  37048. * Proxy to a PDFPage in the worker thread.
  37049. * @class
  37050. * @alias PDFPageProxy
  37051. */
  37052. var PDFPageProxy = (function PDFPageProxyClosure() {
  37053. function PDFPageProxy(pageIndex, pageInfo, transport) {
  37054. this.pageIndex = pageIndex;
  37055. this.pageInfo = pageInfo;
  37056. this.transport = transport;
  37057. this.stats = new StatTimer();
  37058. this.stats.enabled = getDefaultSetting('enableStats');
  37059. this.commonObjs = transport.commonObjs;
  37060. this.objs = new PDFObjects();
  37061. this.cleanupAfterRender = false;
  37062. this.pendingCleanup = false;
  37063. this.intentStates = Object.create(null);
  37064. this.destroyed = false;
  37065. }
  37066. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  37067. /**
  37068. * @return {number} Page number of the page. First page is 1.
  37069. */
  37070. get pageNumber() {
  37071. return this.pageIndex + 1;
  37072. },
  37073. /**
  37074. * @return {number} The number of degrees the page is rotated clockwise.
  37075. */
  37076. get rotate() {
  37077. return this.pageInfo.rotate;
  37078. },
  37079. /**
  37080. * @return {Object} The reference that points to this page. It has 'num' and
  37081. * 'gen' properties.
  37082. */
  37083. get ref() {
  37084. return this.pageInfo.ref;
  37085. },
  37086. /**
  37087. * @return {Array} An array of the visible portion of the PDF page in the
  37088. * user space units - [x1, y1, x2, y2].
  37089. */
  37090. get view() {
  37091. return this.pageInfo.view;
  37092. },
  37093. /**
  37094. * @param {number} scale The desired scale of the viewport.
  37095. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  37096. * defaults to the page rotation.
  37097. * @return {PageViewport} Contains 'width' and 'height' properties
  37098. * along with transforms required for rendering.
  37099. */
  37100. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  37101. if (arguments.length < 2) {
  37102. rotate = this.rotate;
  37103. }
  37104. return new PageViewport(this.view, scale, rotate, 0, 0);
  37105. },
  37106. /**
  37107. * @param {GetAnnotationsParameters} params - Annotation parameters.
  37108. * @return {Promise} A promise that is resolved with an {Array} of the
  37109. * annotation objects.
  37110. */
  37111. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  37112. var intent = (params && params.intent) || null;
  37113. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  37114. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  37115. intent);
  37116. this.annotationsIntent = intent;
  37117. }
  37118. return this.annotationsPromise;
  37119. },
  37120. /**
  37121. * Begins the process of rendering a page to the desired context.
  37122. * @param {RenderParameters} params Page render parameters.
  37123. * @return {RenderTask} An object that contains the promise, which
  37124. * is resolved when the page finishes rendering.
  37125. */
  37126. render: function PDFPageProxy_render(params) {
  37127. var stats = this.stats;
  37128. stats.time('Overall');
  37129. // If there was a pending destroy cancel it so no cleanup happens during
  37130. // this call to render.
  37131. this.pendingCleanup = false;
  37132. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  37133. if (!this.intentStates[renderingIntent]) {
  37134. this.intentStates[renderingIntent] = Object.create(null);
  37135. }
  37136. var intentState = this.intentStates[renderingIntent];
  37137. // If there's no displayReadyCapability yet, then the operatorList
  37138. // was never requested before. Make the request and create the promise.
  37139. if (!intentState.displayReadyCapability) {
  37140. intentState.receivingOperatorList = true;
  37141. intentState.displayReadyCapability = createPromiseCapability();
  37142. intentState.operatorList = {
  37143. fnArray: [],
  37144. argsArray: [],
  37145. lastChunk: false
  37146. };
  37147. this.stats.time('Page Request');
  37148. this.transport.messageHandler.send('RenderPageRequest', {
  37149. pageIndex: this.pageNumber - 1,
  37150. intent: renderingIntent
  37151. });
  37152. }
  37153. var internalRenderTask = new InternalRenderTask(complete, params,
  37154. this.objs,
  37155. this.commonObjs,
  37156. intentState.operatorList,
  37157. this.pageNumber);
  37158. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  37159. if (!intentState.renderTasks) {
  37160. intentState.renderTasks = [];
  37161. }
  37162. intentState.renderTasks.push(internalRenderTask);
  37163. var renderTask = internalRenderTask.task;
  37164. // Obsolete parameter support
  37165. if (params.continueCallback) {
  37166. deprecated('render is used with continueCallback parameter');
  37167. renderTask.onContinue = params.continueCallback;
  37168. }
  37169. var self = this;
  37170. intentState.displayReadyCapability.promise.then(
  37171. function pageDisplayReadyPromise(transparency) {
  37172. if (self.pendingCleanup) {
  37173. complete();
  37174. return;
  37175. }
  37176. stats.time('Rendering');
  37177. internalRenderTask.initializeGraphics(transparency);
  37178. internalRenderTask.operatorListChanged();
  37179. },
  37180. function pageDisplayReadPromiseError(reason) {
  37181. complete(reason);
  37182. }
  37183. );
  37184. function complete(error) {
  37185. var i = intentState.renderTasks.indexOf(internalRenderTask);
  37186. if (i >= 0) {
  37187. intentState.renderTasks.splice(i, 1);
  37188. }
  37189. if (self.cleanupAfterRender) {
  37190. self.pendingCleanup = true;
  37191. }
  37192. self._tryCleanup();
  37193. if (error) {
  37194. internalRenderTask.capability.reject(error);
  37195. } else {
  37196. internalRenderTask.capability.resolve();
  37197. }
  37198. stats.timeEnd('Rendering');
  37199. stats.timeEnd('Overall');
  37200. }
  37201. return renderTask;
  37202. },
  37203. /**
  37204. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  37205. * object that represents page's operator list.
  37206. */
  37207. getOperatorList: function PDFPageProxy_getOperatorList() {
  37208. function operatorListChanged() {
  37209. if (intentState.operatorList.lastChunk) {
  37210. intentState.opListReadCapability.resolve(intentState.operatorList);
  37211. var i = intentState.renderTasks.indexOf(opListTask);
  37212. if (i >= 0) {
  37213. intentState.renderTasks.splice(i, 1);
  37214. }
  37215. }
  37216. }
  37217. var renderingIntent = 'oplist';
  37218. if (!this.intentStates[renderingIntent]) {
  37219. this.intentStates[renderingIntent] = Object.create(null);
  37220. }
  37221. var intentState = this.intentStates[renderingIntent];
  37222. var opListTask;
  37223. if (!intentState.opListReadCapability) {
  37224. opListTask = {};
  37225. opListTask.operatorListChanged = operatorListChanged;
  37226. intentState.receivingOperatorList = true;
  37227. intentState.opListReadCapability = createPromiseCapability();
  37228. intentState.renderTasks = [];
  37229. intentState.renderTasks.push(opListTask);
  37230. intentState.operatorList = {
  37231. fnArray: [],
  37232. argsArray: [],
  37233. lastChunk: false
  37234. };
  37235. this.transport.messageHandler.send('RenderPageRequest', {
  37236. pageIndex: this.pageIndex,
  37237. intent: renderingIntent
  37238. });
  37239. }
  37240. return intentState.opListReadCapability.promise;
  37241. },
  37242. /**
  37243. * @param {getTextContentParameters} params - getTextContent parameters.
  37244. * @return {Promise} That is resolved a {@link TextContent}
  37245. * object that represent the page text content.
  37246. */
  37247. getTextContent: function PDFPageProxy_getTextContent(params) {
  37248. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  37249. pageIndex: this.pageNumber - 1,
  37250. normalizeWhitespace: (params && params.normalizeWhitespace === true ?
  37251. true : /* Default */ false),
  37252. combineTextItems: (params && params.disableCombineTextItems === true ?
  37253. false : /* Default */ true),
  37254. });
  37255. },
  37256. /**
  37257. * Destroys page object.
  37258. */
  37259. _destroy: function PDFPageProxy_destroy() {
  37260. this.destroyed = true;
  37261. this.transport.pageCache[this.pageIndex] = null;
  37262. var waitOn = [];
  37263. Object.keys(this.intentStates).forEach(function(intent) {
  37264. if (intent === 'oplist') {
  37265. // Avoid errors below, since the renderTasks are just stubs.
  37266. return;
  37267. }
  37268. var intentState = this.intentStates[intent];
  37269. intentState.renderTasks.forEach(function(renderTask) {
  37270. var renderCompleted = renderTask.capability.promise.
  37271. catch(function () {}); // ignoring failures
  37272. waitOn.push(renderCompleted);
  37273. renderTask.cancel();
  37274. });
  37275. }, this);
  37276. this.objs.clear();
  37277. this.annotationsPromise = null;
  37278. this.pendingCleanup = false;
  37279. return Promise.all(waitOn);
  37280. },
  37281. /**
  37282. * Cleans up resources allocated by the page. (deprecated)
  37283. */
  37284. destroy: function() {
  37285. deprecated('page destroy method, use cleanup() instead');
  37286. this.cleanup();
  37287. },
  37288. /**
  37289. * Cleans up resources allocated by the page.
  37290. */
  37291. cleanup: function PDFPageProxy_cleanup() {
  37292. this.pendingCleanup = true;
  37293. this._tryCleanup();
  37294. },
  37295. /**
  37296. * For internal use only. Attempts to clean up if rendering is in a state
  37297. * where that's possible.
  37298. * @ignore
  37299. */
  37300. _tryCleanup: function PDFPageProxy_tryCleanup() {
  37301. if (!this.pendingCleanup ||
  37302. Object.keys(this.intentStates).some(function(intent) {
  37303. var intentState = this.intentStates[intent];
  37304. return (intentState.renderTasks.length !== 0 ||
  37305. intentState.receivingOperatorList);
  37306. }, this)) {
  37307. return;
  37308. }
  37309. Object.keys(this.intentStates).forEach(function(intent) {
  37310. delete this.intentStates[intent];
  37311. }, this);
  37312. this.objs.clear();
  37313. this.annotationsPromise = null;
  37314. this.pendingCleanup = false;
  37315. },
  37316. /**
  37317. * For internal use only.
  37318. * @ignore
  37319. */
  37320. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  37321. intent) {
  37322. var intentState = this.intentStates[intent];
  37323. // TODO Refactor RenderPageRequest to separate rendering
  37324. // and operator list logic
  37325. if (intentState.displayReadyCapability) {
  37326. intentState.displayReadyCapability.resolve(transparency);
  37327. }
  37328. },
  37329. /**
  37330. * For internal use only.
  37331. * @ignore
  37332. */
  37333. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  37334. intent) {
  37335. var intentState = this.intentStates[intent];
  37336. var i, ii;
  37337. // Add the new chunk to the current operator list.
  37338. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  37339. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  37340. intentState.operatorList.argsArray.push(
  37341. operatorListChunk.argsArray[i]);
  37342. }
  37343. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  37344. // Notify all the rendering tasks there are more operators to be consumed.
  37345. for (i = 0; i < intentState.renderTasks.length; i++) {
  37346. intentState.renderTasks[i].operatorListChanged();
  37347. }
  37348. if (operatorListChunk.lastChunk) {
  37349. intentState.receivingOperatorList = false;
  37350. this._tryCleanup();
  37351. }
  37352. }
  37353. };
  37354. return PDFPageProxy;
  37355. })();
  37356. /**
  37357. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  37358. * WorkerTransport for them. If creation of a web worker is not possible,
  37359. * a "fake" worker will be used instead.
  37360. * @class
  37361. */
  37362. var PDFWorker = (function PDFWorkerClosure() {
  37363. var nextFakeWorkerId = 0;
  37364. function getWorkerSrc() {
  37365. if (typeof workerSrc !== 'undefined') {
  37366. return workerSrc;
  37367. }
  37368. if (getDefaultSetting('workerSrc')) {
  37369. return getDefaultSetting('workerSrc');
  37370. }
  37371. if (pdfjsFilePath) {
  37372. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  37373. }
  37374. error('No PDFJS.workerSrc specified');
  37375. }
  37376. var fakeWorkerFilesLoadedCapability;
  37377. // Loads worker code into main thread.
  37378. function setupFakeWorkerGlobal() {
  37379. var WorkerMessageHandler;
  37380. if (!fakeWorkerFilesLoadedCapability) {
  37381. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  37382. // In the developer build load worker_loader which in turn loads all the
  37383. // other files and resolves the promise. In production only the
  37384. // pdf.worker.js file is needed.
  37385. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  37386. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  37387. }
  37388. return fakeWorkerFilesLoadedCapability.promise;
  37389. }
  37390. function createCDNWrapper(url) {
  37391. // We will rely on blob URL's property to specify origin.
  37392. // We want this function to fail in case if createObjectURL or Blob do not
  37393. // exist or fail for some reason -- our Worker creation will fail anyway.
  37394. var wrapper = 'importScripts(\'' + url + '\');';
  37395. return URL.createObjectURL(new Blob([wrapper]));
  37396. }
  37397. function PDFWorker(name) {
  37398. this.name = name;
  37399. this.destroyed = false;
  37400. this._readyCapability = createPromiseCapability();
  37401. this._port = null;
  37402. this._webWorker = null;
  37403. this._messageHandler = null;
  37404. this._initialize();
  37405. }
  37406. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  37407. get promise() {
  37408. return this._readyCapability.promise;
  37409. },
  37410. get port() {
  37411. return this._port;
  37412. },
  37413. get messageHandler() {
  37414. return this._messageHandler;
  37415. },
  37416. _initialize: function PDFWorker_initialize() {
  37417. // If worker support isn't disabled explicit and the browser has worker
  37418. // support, create a new web worker and test if it/the browser fulfills
  37419. // all requirements to run parts of pdf.js in a web worker.
  37420. // Right now, the requirement is, that an Uint8Array is still an
  37421. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  37422. // Either workers are disabled, not supported or have thrown an exception.
  37423. // Thus, we fallback to a faked worker.
  37424. this._setupFakeWorker();
  37425. },
  37426. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  37427. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  37428. warn('Setting up fake worker.');
  37429. isWorkerDisabled = true;
  37430. }
  37431. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  37432. if (this.destroyed) {
  37433. this._readyCapability.reject(new Error('Worker was destroyed'));
  37434. return;
  37435. }
  37436. // If we don't use a worker, just post/sendMessage to the main thread.
  37437. var port = {
  37438. _listeners: [],
  37439. postMessage: function (obj) {
  37440. var e = {data: obj};
  37441. this._listeners.forEach(function (listener) {
  37442. listener.call(this, e);
  37443. }, this);
  37444. },
  37445. addEventListener: function (name, listener) {
  37446. this._listeners.push(listener);
  37447. },
  37448. removeEventListener: function (name, listener) {
  37449. var i = this._listeners.indexOf(listener);
  37450. this._listeners.splice(i, 1);
  37451. },
  37452. terminate: function () {}
  37453. };
  37454. this._port = port;
  37455. // All fake workers use the same port, making id unique.
  37456. var id = 'fake' + (nextFakeWorkerId++);
  37457. // If the main thread is our worker, setup the handling for the
  37458. // messages -- the main thread sends to it self.
  37459. var workerHandler = new MessageHandler(id + '_worker', id, port);
  37460. WorkerMessageHandler.setup(workerHandler, port);
  37461. var messageHandler = new MessageHandler(id, id + '_worker', port);
  37462. this._messageHandler = messageHandler;
  37463. this._readyCapability.resolve();
  37464. }.bind(this));
  37465. },
  37466. /**
  37467. * Destroys the worker instance.
  37468. */
  37469. destroy: function PDFWorker_destroy() {
  37470. this.destroyed = true;
  37471. if (this._webWorker) {
  37472. // We need to terminate only web worker created resource.
  37473. this._webWorker.terminate();
  37474. this._webWorker = null;
  37475. }
  37476. this._port = null;
  37477. if (this._messageHandler) {
  37478. this._messageHandler.destroy();
  37479. this._messageHandler = null;
  37480. }
  37481. }
  37482. };
  37483. return PDFWorker;
  37484. })();
  37485. /**
  37486. * For internal use only.
  37487. * @ignore
  37488. */
  37489. var WorkerTransport = (function WorkerTransportClosure() {
  37490. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  37491. this.messageHandler = messageHandler;
  37492. this.loadingTask = loadingTask;
  37493. this.pdfDataRangeTransport = pdfDataRangeTransport;
  37494. this.commonObjs = new PDFObjects();
  37495. this.fontLoader = new FontLoader(loadingTask.docId);
  37496. this.destroyed = false;
  37497. this.destroyCapability = null;
  37498. this.pageCache = [];
  37499. this.pagePromises = [];
  37500. this.downloadInfoCapability = createPromiseCapability();
  37501. this.setupMessageHandler();
  37502. }
  37503. WorkerTransport.prototype = {
  37504. destroy: function WorkerTransport_destroy() {
  37505. if (this.destroyCapability) {
  37506. return this.destroyCapability.promise;
  37507. }
  37508. this.destroyed = true;
  37509. this.destroyCapability = createPromiseCapability();
  37510. var waitOn = [];
  37511. // We need to wait for all renderings to be completed, e.g.
  37512. // timeout/rAF can take a long time.
  37513. this.pageCache.forEach(function (page) {
  37514. if (page) {
  37515. waitOn.push(page._destroy());
  37516. }
  37517. });
  37518. this.pageCache = [];
  37519. this.pagePromises = [];
  37520. var self = this;
  37521. // We also need to wait for the worker to finish its long running tasks.
  37522. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  37523. waitOn.push(terminated);
  37524. Promise.all(waitOn).then(function () {
  37525. self.fontLoader.clear();
  37526. if (self.pdfDataRangeTransport) {
  37527. self.pdfDataRangeTransport.abort();
  37528. self.pdfDataRangeTransport = null;
  37529. }
  37530. if (self.messageHandler) {
  37531. self.messageHandler.destroy();
  37532. self.messageHandler = null;
  37533. }
  37534. self.destroyCapability.resolve();
  37535. }, this.destroyCapability.reject);
  37536. return this.destroyCapability.promise;
  37537. },
  37538. setupMessageHandler:
  37539. function WorkerTransport_setupMessageHandler() {
  37540. var messageHandler = this.messageHandler;
  37541. function updatePassword(password) {
  37542. messageHandler.send('UpdatePassword', password);
  37543. }
  37544. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  37545. if (pdfDataRangeTransport) {
  37546. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  37547. messageHandler.send('OnDataRange', {
  37548. begin: begin,
  37549. chunk: chunk
  37550. });
  37551. });
  37552. pdfDataRangeTransport.addProgressListener(function(loaded) {
  37553. messageHandler.send('OnDataProgress', {
  37554. loaded: loaded
  37555. });
  37556. });
  37557. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  37558. messageHandler.send('OnDataRange', {
  37559. chunk: chunk
  37560. });
  37561. });
  37562. messageHandler.on('RequestDataRange',
  37563. function transportDataRange(data) {
  37564. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  37565. }, this);
  37566. }
  37567. messageHandler.on('GetDoc', function transportDoc(data) {
  37568. var pdfInfo = data.pdfInfo;
  37569. this.numPages = data.pdfInfo.numPages;
  37570. var loadingTask = this.loadingTask;
  37571. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  37572. this.pdfDocument = pdfDocument;
  37573. loadingTask._capability.resolve(pdfDocument);
  37574. }, this);
  37575. messageHandler.on('NeedPassword',
  37576. function transportNeedPassword(exception) {
  37577. var loadingTask = this.loadingTask;
  37578. if (loadingTask.onPassword) {
  37579. return loadingTask.onPassword(updatePassword,
  37580. PasswordResponses.NEED_PASSWORD);
  37581. }
  37582. loadingTask._capability.reject(
  37583. new PasswordException(exception.message, exception.code));
  37584. }, this);
  37585. messageHandler.on('IncorrectPassword',
  37586. function transportIncorrectPassword(exception) {
  37587. var loadingTask = this.loadingTask;
  37588. if (loadingTask.onPassword) {
  37589. return loadingTask.onPassword(updatePassword,
  37590. PasswordResponses.INCORRECT_PASSWORD);
  37591. }
  37592. loadingTask._capability.reject(
  37593. new PasswordException(exception.message, exception.code));
  37594. }, this);
  37595. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  37596. this.loadingTask._capability.reject(
  37597. new InvalidPDFException(exception.message));
  37598. }, this);
  37599. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  37600. this.loadingTask._capability.reject(
  37601. new MissingPDFException(exception.message));
  37602. }, this);
  37603. messageHandler.on('UnexpectedResponse',
  37604. function transportUnexpectedResponse(exception) {
  37605. this.loadingTask._capability.reject(
  37606. new UnexpectedResponseException(exception.message, exception.status));
  37607. }, this);
  37608. messageHandler.on('UnknownError',
  37609. function transportUnknownError(exception) {
  37610. this.loadingTask._capability.reject(
  37611. new UnknownErrorException(exception.message, exception.details));
  37612. }, this);
  37613. messageHandler.on('DataLoaded', function transportPage(data) {
  37614. this.downloadInfoCapability.resolve(data);
  37615. }, this);
  37616. messageHandler.on('PDFManagerReady', function transportPage(data) {
  37617. if (this.pdfDataRangeTransport) {
  37618. this.pdfDataRangeTransport.transportReady();
  37619. }
  37620. }, this);
  37621. messageHandler.on('StartRenderPage', function transportRender(data) {
  37622. if (this.destroyed) {
  37623. return; // Ignore any pending requests if the worker was terminated.
  37624. }
  37625. var page = this.pageCache[data.pageIndex];
  37626. page.stats.timeEnd('Page Request');
  37627. page._startRenderPage(data.transparency, data.intent);
  37628. }, this);
  37629. messageHandler.on('RenderPageChunk', function transportRender(data) {
  37630. if (this.destroyed) {
  37631. return; // Ignore any pending requests if the worker was terminated.
  37632. }
  37633. var page = this.pageCache[data.pageIndex];
  37634. page._renderPageChunk(data.operatorList, data.intent);
  37635. }, this);
  37636. messageHandler.on('commonobj', function transportObj(data) {
  37637. if (this.destroyed) {
  37638. return; // Ignore any pending requests if the worker was terminated.
  37639. }
  37640. var id = data[0];
  37641. var type = data[1];
  37642. if (this.commonObjs.hasData(id)) {
  37643. return;
  37644. }
  37645. switch (type) {
  37646. case 'Font':
  37647. var exportedData = data[2];
  37648. if ('error' in exportedData) {
  37649. var exportedError = exportedData.error;
  37650. warn('Error during font loading: ' + exportedError);
  37651. this.commonObjs.resolve(id, exportedError);
  37652. break;
  37653. }
  37654. var fontRegistry = null;
  37655. if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
  37656. globalScope['FontInspector'].enabled) {
  37657. fontRegistry = {
  37658. registerFont: function (font, url) {
  37659. globalScope['FontInspector'].fontAdded(font, url);
  37660. }
  37661. };
  37662. }
  37663. var font = new FontFaceObject(exportedData, {
  37664. isEvalSuported: getDefaultSetting('isEvalSupported'),
  37665. disableFontFace: getDefaultSetting('disableFontFace'),
  37666. fontRegistry: fontRegistry
  37667. });
  37668. this.fontLoader.bind(
  37669. [font],
  37670. function fontReady(fontObjs) {
  37671. this.commonObjs.resolve(id, font);
  37672. }.bind(this)
  37673. );
  37674. break;
  37675. case 'FontPath':
  37676. this.commonObjs.resolve(id, data[2]);
  37677. break;
  37678. default:
  37679. error('Got unknown common object type ' + type);
  37680. }
  37681. }, this);
  37682. messageHandler.on('obj', function transportObj(data) {
  37683. if (this.destroyed) {
  37684. return; // Ignore any pending requests if the worker was terminated.
  37685. }
  37686. var id = data[0];
  37687. var pageIndex = data[1];
  37688. var type = data[2];
  37689. var pageProxy = this.pageCache[pageIndex];
  37690. var imageData;
  37691. if (pageProxy.objs.hasData(id)) {
  37692. return;
  37693. }
  37694. switch (type) {
  37695. case 'JpegStream':
  37696. imageData = data[3];
  37697. loadJpegStream(id, imageData, pageProxy.objs);
  37698. break;
  37699. case 'Image':
  37700. imageData = data[3];
  37701. pageProxy.objs.resolve(id, imageData);
  37702. // heuristics that will allow not to store large data
  37703. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  37704. if (imageData && 'data' in imageData &&
  37705. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  37706. pageProxy.cleanupAfterRender = true;
  37707. }
  37708. break;
  37709. default:
  37710. error('Got unknown object type ' + type);
  37711. }
  37712. }, this);
  37713. messageHandler.on('DocProgress', function transportDocProgress(data) {
  37714. if (this.destroyed) {
  37715. return; // Ignore any pending requests if the worker was terminated.
  37716. }
  37717. var loadingTask = this.loadingTask;
  37718. if (loadingTask.onProgress) {
  37719. loadingTask.onProgress({
  37720. loaded: data.loaded,
  37721. total: data.total
  37722. });
  37723. }
  37724. }, this);
  37725. messageHandler.on('PageError', function transportError(data) {
  37726. if (this.destroyed) {
  37727. return; // Ignore any pending requests if the worker was terminated.
  37728. }
  37729. var page = this.pageCache[data.pageNum - 1];
  37730. var intentState = page.intentStates[data.intent];
  37731. if (intentState.displayReadyCapability) {
  37732. intentState.displayReadyCapability.reject(data.error);
  37733. } else {
  37734. error(data.error);
  37735. }
  37736. if (intentState.operatorList) {
  37737. // Mark operator list as complete.
  37738. intentState.operatorList.lastChunk = true;
  37739. for (var i = 0; i < intentState.renderTasks.length; i++) {
  37740. intentState.renderTasks[i].operatorListChanged();
  37741. }
  37742. }
  37743. }, this);
  37744. messageHandler.on('UnsupportedFeature',
  37745. function transportUnsupportedFeature(data) {
  37746. if (this.destroyed) {
  37747. return; // Ignore any pending requests if the worker was terminated.
  37748. }
  37749. var featureId = data.featureId;
  37750. var loadingTask = this.loadingTask;
  37751. if (loadingTask.onUnsupportedFeature) {
  37752. loadingTask.onUnsupportedFeature(featureId);
  37753. }
  37754. _UnsupportedManager.notify(featureId);
  37755. }, this);
  37756. messageHandler.on('JpegDecode', function(data) {
  37757. if (this.destroyed) {
  37758. return Promise.reject('Worker was terminated');
  37759. }
  37760. var imageUrl = data[0];
  37761. var components = data[1];
  37762. if (components !== 3 && components !== 1) {
  37763. return Promise.reject(
  37764. new Error('Only 3 components or 1 component can be returned'));
  37765. }
  37766. return new Promise(function (resolve, reject) {
  37767. var img = new Image();
  37768. img.onload = function () {
  37769. var width = img.width;
  37770. var height = img.height;
  37771. var size = width * height;
  37772. var rgbaLength = size * 4;
  37773. var buf = new Uint8Array(size * components);
  37774. var tmpCanvas = createScratchCanvas(width, height);
  37775. var tmpCtx = tmpCanvas.getContext('2d');
  37776. tmpCtx.drawImage(img, 0, 0);
  37777. var data = tmpCtx.getImageData(0, 0, width, height).data;
  37778. var i, j;
  37779. if (components === 3) {
  37780. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  37781. buf[j] = data[i];
  37782. buf[j + 1] = data[i + 1];
  37783. buf[j + 2] = data[i + 2];
  37784. }
  37785. } else if (components === 1) {
  37786. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  37787. buf[j] = data[i];
  37788. }
  37789. }
  37790. resolve({ data: buf, width: width, height: height});
  37791. };
  37792. img.onerror = function () {
  37793. reject(new Error('JpegDecode failed to load image'));
  37794. };
  37795. img.src = imageUrl;
  37796. });
  37797. }, this);
  37798. },
  37799. getData: function WorkerTransport_getData() {
  37800. return this.messageHandler.sendWithPromise('GetData', null);
  37801. },
  37802. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  37803. if (pageNumber <= 0 || pageNumber > this.numPages ||
  37804. (pageNumber|0) !== pageNumber) {
  37805. return Promise.reject(new Error('Invalid page request'));
  37806. }
  37807. var pageIndex = pageNumber - 1;
  37808. if (pageIndex in this.pagePromises) {
  37809. return this.pagePromises[pageIndex];
  37810. }
  37811. var promise = this.messageHandler.sendWithPromise('GetPage', {
  37812. pageIndex: pageIndex
  37813. }).then(function (pageInfo) {
  37814. if (this.destroyed) {
  37815. throw new Error('Transport destroyed');
  37816. }
  37817. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  37818. this.pageCache[pageIndex] = page;
  37819. return page;
  37820. }.bind(this));
  37821. this.pagePromises[pageIndex] = promise;
  37822. return promise;
  37823. },
  37824. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  37825. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).
  37826. then(function (pageIndex) {
  37827. return pageIndex;
  37828. }, function (reason) {
  37829. return Promise.reject(new Error(reason));
  37830. });
  37831. },
  37832. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  37833. return this.messageHandler.sendWithPromise('GetAnnotations', {
  37834. pageIndex: pageIndex,
  37835. intent: intent,
  37836. });
  37837. },
  37838. getDestinations: function WorkerTransport_getDestinations() {
  37839. return this.messageHandler.sendWithPromise('GetDestinations', null);
  37840. },
  37841. getDestination: function WorkerTransport_getDestination(id) {
  37842. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  37843. },
  37844. getPageLabels: function WorkerTransport_getPageLabels() {
  37845. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  37846. },
  37847. getAttachments: function WorkerTransport_getAttachments() {
  37848. return this.messageHandler.sendWithPromise('GetAttachments', null);
  37849. },
  37850. getJavaScript: function WorkerTransport_getJavaScript() {
  37851. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  37852. },
  37853. getOutline: function WorkerTransport_getOutline() {
  37854. return this.messageHandler.sendWithPromise('GetOutline', null);
  37855. },
  37856. getMetadata: function WorkerTransport_getMetadata() {
  37857. return this.messageHandler.sendWithPromise('GetMetadata', null).
  37858. then(function transportMetadata(results) {
  37859. return {
  37860. info: results[0],
  37861. metadata: (results[1] ? new Metadata(results[1]) : null)
  37862. };
  37863. });
  37864. },
  37865. getStats: function WorkerTransport_getStats() {
  37866. return this.messageHandler.sendWithPromise('GetStats', null);
  37867. },
  37868. startCleanup: function WorkerTransport_startCleanup() {
  37869. this.messageHandler.sendWithPromise('Cleanup', null).
  37870. then(function endCleanup() {
  37871. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  37872. var page = this.pageCache[i];
  37873. if (page) {
  37874. page.cleanup();
  37875. }
  37876. }
  37877. this.commonObjs.clear();
  37878. this.fontLoader.clear();
  37879. }.bind(this));
  37880. }
  37881. };
  37882. return WorkerTransport;
  37883. })();
  37884. /**
  37885. * A PDF document and page is built of many objects. E.g. there are objects
  37886. * for fonts, images, rendering code and such. These objects might get processed
  37887. * inside of a worker. The `PDFObjects` implements some basic functions to
  37888. * manage these objects.
  37889. * @ignore
  37890. */
  37891. var PDFObjects = (function PDFObjectsClosure() {
  37892. function PDFObjects() {
  37893. this.objs = Object.create(null);
  37894. }
  37895. PDFObjects.prototype = {
  37896. /**
  37897. * Internal function.
  37898. * Ensures there is an object defined for `objId`.
  37899. */
  37900. ensureObj: function PDFObjects_ensureObj(objId) {
  37901. if (this.objs[objId]) {
  37902. return this.objs[objId];
  37903. }
  37904. var obj = {
  37905. capability: createPromiseCapability(),
  37906. data: null,
  37907. resolved: false
  37908. };
  37909. this.objs[objId] = obj;
  37910. return obj;
  37911. },
  37912. /**
  37913. * If called *without* callback, this returns the data of `objId` but the
  37914. * object needs to be resolved. If it isn't, this function throws.
  37915. *
  37916. * If called *with* a callback, the callback is called with the data of the
  37917. * object once the object is resolved. That means, if you call this
  37918. * function and the object is already resolved, the callback gets called
  37919. * right away.
  37920. */
  37921. get: function PDFObjects_get(objId, callback) {
  37922. // If there is a callback, then the get can be async and the object is
  37923. // not required to be resolved right now
  37924. if (callback) {
  37925. this.ensureObj(objId).capability.promise.then(callback);
  37926. return null;
  37927. }
  37928. // If there isn't a callback, the user expects to get the resolved data
  37929. // directly.
  37930. var obj = this.objs[objId];
  37931. // If there isn't an object yet or the object isn't resolved, then the
  37932. // data isn't ready yet!
  37933. if (!obj || !obj.resolved) {
  37934. error('Requesting object that isn\'t resolved yet ' + objId);
  37935. }
  37936. return obj.data;
  37937. },
  37938. /**
  37939. * Resolves the object `objId` with optional `data`.
  37940. */
  37941. resolve: function PDFObjects_resolve(objId, data) {
  37942. var obj = this.ensureObj(objId);
  37943. obj.resolved = true;
  37944. obj.data = data;
  37945. obj.capability.resolve(data);
  37946. },
  37947. isResolved: function PDFObjects_isResolved(objId) {
  37948. var objs = this.objs;
  37949. if (!objs[objId]) {
  37950. return false;
  37951. } else {
  37952. return objs[objId].resolved;
  37953. }
  37954. },
  37955. hasData: function PDFObjects_hasData(objId) {
  37956. return this.isResolved(objId);
  37957. },
  37958. /**
  37959. * Returns the data of `objId` if object exists, null otherwise.
  37960. */
  37961. getData: function PDFObjects_getData(objId) {
  37962. var objs = this.objs;
  37963. if (!objs[objId] || !objs[objId].resolved) {
  37964. return null;
  37965. } else {
  37966. return objs[objId].data;
  37967. }
  37968. },
  37969. clear: function PDFObjects_clear() {
  37970. this.objs = Object.create(null);
  37971. }
  37972. };
  37973. return PDFObjects;
  37974. })();
  37975. /**
  37976. * Allows controlling of the rendering tasks.
  37977. * @class
  37978. * @alias RenderTask
  37979. */
  37980. var RenderTask = (function RenderTaskClosure() {
  37981. function RenderTask(internalRenderTask) {
  37982. this._internalRenderTask = internalRenderTask;
  37983. /**
  37984. * Callback for incremental rendering -- a function that will be called
  37985. * each time the rendering is paused. To continue rendering call the
  37986. * function that is the first argument to the callback.
  37987. * @type {function}
  37988. */
  37989. this.onContinue = null;
  37990. }
  37991. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  37992. /**
  37993. * Promise for rendering task completion.
  37994. * @return {Promise}
  37995. */
  37996. get promise() {
  37997. return this._internalRenderTask.capability.promise;
  37998. },
  37999. /**
  38000. * Cancels the rendering task. If the task is currently rendering it will
  38001. * not be cancelled until graphics pauses with a timeout. The promise that
  38002. * this object extends will resolved when cancelled.
  38003. */
  38004. cancel: function RenderTask_cancel() {
  38005. this._internalRenderTask.cancel();
  38006. },
  38007. /**
  38008. * Registers callbacks to indicate the rendering task completion.
  38009. *
  38010. * @param {function} onFulfilled The callback for the rendering completion.
  38011. * @param {function} onRejected The callback for the rendering failure.
  38012. * @return {Promise} A promise that is resolved after the onFulfilled or
  38013. * onRejected callback.
  38014. */
  38015. then: function RenderTask_then(onFulfilled, onRejected) {
  38016. return this.promise.then.apply(this.promise, arguments);
  38017. }
  38018. };
  38019. return RenderTask;
  38020. })();
  38021. /**
  38022. * For internal use only.
  38023. * @ignore
  38024. */
  38025. var InternalRenderTask = (function InternalRenderTaskClosure() {
  38026. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  38027. pageNumber) {
  38028. this.callback = callback;
  38029. this.params = params;
  38030. this.objs = objs;
  38031. this.commonObjs = commonObjs;
  38032. this.operatorListIdx = null;
  38033. this.operatorList = operatorList;
  38034. this.pageNumber = pageNumber;
  38035. this.running = false;
  38036. this.graphicsReadyCallback = null;
  38037. this.graphicsReady = false;
  38038. this.useRequestAnimationFrame = false;
  38039. this.cancelled = false;
  38040. this.capability = createPromiseCapability();
  38041. this.task = new RenderTask(this);
  38042. // caching this-bound methods
  38043. this._continueBound = this._continue.bind(this);
  38044. this._scheduleNextBound = this._scheduleNext.bind(this);
  38045. this._nextBound = this._next.bind(this);
  38046. }
  38047. InternalRenderTask.prototype = {
  38048. initializeGraphics:
  38049. function InternalRenderTask_initializeGraphics(transparency) {
  38050. if (this.cancelled) {
  38051. return;
  38052. }
  38053. if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
  38054. globalScope.StepperManager.enabled) {
  38055. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  38056. this.stepper.init(this.operatorList);
  38057. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  38058. }
  38059. var params = this.params;
  38060. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  38061. this.objs, params.imageLayer);
  38062. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  38063. this.operatorListIdx = 0;
  38064. this.graphicsReady = true;
  38065. if (this.graphicsReadyCallback) {
  38066. this.graphicsReadyCallback();
  38067. }
  38068. },
  38069. cancel: function InternalRenderTask_cancel() {
  38070. this.running = false;
  38071. this.cancelled = true;
  38072. this.callback('cancelled');
  38073. },
  38074. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  38075. if (!this.graphicsReady) {
  38076. if (!this.graphicsReadyCallback) {
  38077. this.graphicsReadyCallback = this._continueBound;
  38078. }
  38079. return;
  38080. }
  38081. if (this.stepper) {
  38082. this.stepper.updateOperatorList(this.operatorList);
  38083. }
  38084. if (this.running) {
  38085. return;
  38086. }
  38087. this._continue();
  38088. },
  38089. _continue: function InternalRenderTask__continue() {
  38090. this.running = true;
  38091. if (this.cancelled) {
  38092. return;
  38093. }
  38094. if (this.task.onContinue) {
  38095. this.task.onContinue.call(this.task, this._scheduleNextBound);
  38096. } else {
  38097. this._scheduleNext();
  38098. }
  38099. },
  38100. _scheduleNext: function InternalRenderTask__scheduleNext() {
  38101. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  38102. window.requestAnimationFrame(this._nextBound);
  38103. } else {
  38104. Promise.resolve(undefined).then(this._nextBound);
  38105. }
  38106. },
  38107. _next: function InternalRenderTask__next() {
  38108. if (this.cancelled) {
  38109. return;
  38110. }
  38111. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  38112. this.operatorListIdx,
  38113. this._continueBound,
  38114. this.stepper);
  38115. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  38116. this.running = false;
  38117. if (this.operatorList.lastChunk) {
  38118. this.gfx.endDrawing();
  38119. this.callback();
  38120. }
  38121. }
  38122. }
  38123. };
  38124. return InternalRenderTask;
  38125. })();
  38126. /**
  38127. * (Deprecated) Global observer of unsupported feature usages. Use
  38128. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  38129. */
  38130. var _UnsupportedManager = (function UnsupportedManagerClosure() {
  38131. var listeners = [];
  38132. return {
  38133. listen: function (cb) {
  38134. deprecated('Global UnsupportedManager.listen is used: ' +
  38135. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  38136. listeners.push(cb);
  38137. },
  38138. notify: function (featureId) {
  38139. for (var i = 0, ii = listeners.length; i < ii; i++) {
  38140. listeners[i](featureId);
  38141. }
  38142. }
  38143. };
  38144. })();
  38145. if (typeof pdfjsVersion !== 'undefined') {
  38146. exports.version = pdfjsVersion;
  38147. }
  38148. if (typeof pdfjsBuild !== 'undefined') {
  38149. exports.build = pdfjsBuild;
  38150. }
  38151. exports.getDocument = getDocument;
  38152. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  38153. exports.PDFWorker = PDFWorker;
  38154. exports.PDFDocumentProxy = PDFDocumentProxy;
  38155. exports.PDFPageProxy = PDFPageProxy;
  38156. exports._UnsupportedManager = _UnsupportedManager;
  38157. }));
  38158. (function (root, factory) {
  38159. {
  38160. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38161. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  38162. }
  38163. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  38164. var error = sharedUtil.error;
  38165. var info = sharedUtil.info;
  38166. var isArray = sharedUtil.isArray;
  38167. var isString = sharedUtil.isString;
  38168. var shadow = sharedUtil.shadow;
  38169. var warn = sharedUtil.warn;
  38170. var isDict = corePrimitives.isDict;
  38171. var isName = corePrimitives.isName;
  38172. var isStream = corePrimitives.isStream;
  38173. var PDFFunction = coreFunction.PDFFunction;
  38174. var ColorSpace = (function ColorSpaceClosure() {
  38175. /**
  38176. * Resizes an RGB image with 3 components.
  38177. * @param {TypedArray} src - The source buffer.
  38178. * @param {Number} bpc - Number of bits per component.
  38179. * @param {Number} w1 - Original width.
  38180. * @param {Number} h1 - Original height.
  38181. * @param {Number} w2 - New width.
  38182. * @param {Number} h2 - New height.
  38183. * @param {Number} alpha01 - Size reserved for the alpha channel.
  38184. * @param {TypedArray} dest - The destination buffer.
  38185. */
  38186. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  38187. var COMPONENTS = 3;
  38188. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  38189. var xRatio = w1 / w2;
  38190. var yRatio = h1 / h2;
  38191. var i, j, py, newIndex = 0, oldIndex;
  38192. var xScaled = new Uint16Array(w2);
  38193. var w1Scanline = w1 * COMPONENTS;
  38194. for (i = 0; i < w2; i++) {
  38195. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  38196. }
  38197. for (i = 0; i < h2; i++) {
  38198. py = Math.floor(i * yRatio) * w1Scanline;
  38199. for (j = 0; j < w2; j++) {
  38200. oldIndex = py + xScaled[j];
  38201. dest[newIndex++] = src[oldIndex++];
  38202. dest[newIndex++] = src[oldIndex++];
  38203. dest[newIndex++] = src[oldIndex++];
  38204. newIndex += alpha01;
  38205. }
  38206. }
  38207. }
  38208. // Constructor should define this.numComps, this.defaultColor, this.name
  38209. function ColorSpace() {
  38210. error('should not call ColorSpace constructor');
  38211. }
  38212. ColorSpace.prototype = {
  38213. /**
  38214. * Converts the color value to the RGB color. The color components are
  38215. * located in the src array starting from the srcOffset. Returns the array
  38216. * of the rgb components, each value ranging from [0,255].
  38217. */
  38218. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38219. var rgb = new Uint8Array(3);
  38220. this.getRgbItem(src, srcOffset, rgb, 0);
  38221. return rgb;
  38222. },
  38223. /**
  38224. * Converts the color value to the RGB color, similar to the getRgb method.
  38225. * The result placed into the dest array starting from the destOffset.
  38226. */
  38227. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38228. dest, destOffset) {
  38229. error('Should not call ColorSpace.getRgbItem');
  38230. },
  38231. /**
  38232. * Converts the specified number of the color values to the RGB colors.
  38233. * The colors are located in the src array starting from the srcOffset.
  38234. * The result is placed into the dest array starting from the destOffset.
  38235. * The src array items shall be in [0,2^bits) range, the dest array items
  38236. * will be in [0,255] range. alpha01 indicates how many alpha components
  38237. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38238. * array).
  38239. */
  38240. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38241. dest, destOffset, bits,
  38242. alpha01) {
  38243. error('Should not call ColorSpace.getRgbBuffer');
  38244. },
  38245. /**
  38246. * Determines the number of bytes required to store the result of the
  38247. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38248. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38249. */
  38250. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38251. alpha01) {
  38252. error('Should not call ColorSpace.getOutputLength');
  38253. },
  38254. /**
  38255. * Returns true if source data will be equal the result/output data.
  38256. */
  38257. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38258. return false;
  38259. },
  38260. /**
  38261. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38262. * how many alpha components there are in the dest array; it will be either
  38263. * 0 (RGB array) or 1 (RGBA array).
  38264. */
  38265. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38266. originalHeight, width, height,
  38267. actualHeight, bpc, comps, alpha01) {
  38268. var count = originalWidth * originalHeight;
  38269. var rgbBuf = null;
  38270. var numComponentColors = 1 << bpc;
  38271. var needsResizing = originalHeight !== height || originalWidth !== width;
  38272. var i, ii;
  38273. if (this.isPassthrough(bpc)) {
  38274. rgbBuf = comps;
  38275. } else if (this.numComps === 1 && count > numComponentColors &&
  38276. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38277. // Optimization: create a color map when there is just one component and
  38278. // we are converting more colors than the size of the color map. We
  38279. // don't build the map if the colorspace is gray or rgb since those
  38280. // methods are faster than building a map. This mainly offers big speed
  38281. // ups for indexed and alternate colorspaces.
  38282. //
  38283. // TODO it may be worth while to cache the color map. While running
  38284. // testing I never hit a cache so I will leave that out for now (perhaps
  38285. // we are reparsing colorspaces too much?).
  38286. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38287. new Uint16Array(numComponentColors);
  38288. var key;
  38289. for (i = 0; i < numComponentColors; i++) {
  38290. allColors[i] = i;
  38291. }
  38292. var colorMap = new Uint8Array(numComponentColors * 3);
  38293. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38294. /* alpha01 = */ 0);
  38295. var destPos, rgbPos;
  38296. if (!needsResizing) {
  38297. // Fill in the RGB values directly into |dest|.
  38298. destPos = 0;
  38299. for (i = 0; i < count; ++i) {
  38300. key = comps[i] * 3;
  38301. dest[destPos++] = colorMap[key];
  38302. dest[destPos++] = colorMap[key + 1];
  38303. dest[destPos++] = colorMap[key + 2];
  38304. destPos += alpha01;
  38305. }
  38306. } else {
  38307. rgbBuf = new Uint8Array(count * 3);
  38308. rgbPos = 0;
  38309. for (i = 0; i < count; ++i) {
  38310. key = comps[i] * 3;
  38311. rgbBuf[rgbPos++] = colorMap[key];
  38312. rgbBuf[rgbPos++] = colorMap[key + 1];
  38313. rgbBuf[rgbPos++] = colorMap[key + 2];
  38314. }
  38315. }
  38316. } else {
  38317. if (!needsResizing) {
  38318. // Fill in the RGB values directly into |dest|.
  38319. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38320. alpha01);
  38321. } else {
  38322. rgbBuf = new Uint8Array(count * 3);
  38323. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38324. /* alpha01 = */ 0);
  38325. }
  38326. }
  38327. if (rgbBuf) {
  38328. if (needsResizing) {
  38329. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  38330. width, height, alpha01, dest);
  38331. } else {
  38332. rgbPos = 0;
  38333. destPos = 0;
  38334. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38335. dest[destPos++] = rgbBuf[rgbPos++];
  38336. dest[destPos++] = rgbBuf[rgbPos++];
  38337. dest[destPos++] = rgbBuf[rgbPos++];
  38338. destPos += alpha01;
  38339. }
  38340. }
  38341. }
  38342. },
  38343. /**
  38344. * True if the colorspace has components in the default range of [0, 1].
  38345. * This should be true for all colorspaces except for lab color spaces
  38346. * which are [0,100], [-128, 127], [-128, 127].
  38347. */
  38348. usesZeroToOneRange: true
  38349. };
  38350. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38351. var IR = ColorSpace.parseToIR(cs, xref, res);
  38352. if (IR instanceof AlternateCS) {
  38353. return IR;
  38354. }
  38355. return ColorSpace.fromIR(IR);
  38356. };
  38357. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38358. var name = isArray(IR) ? IR[0] : IR;
  38359. var whitePoint, blackPoint, gamma;
  38360. switch (name) {
  38361. case 'DeviceGrayCS':
  38362. return this.singletons.gray;
  38363. case 'DeviceRgbCS':
  38364. return this.singletons.rgb;
  38365. case 'DeviceCmykCS':
  38366. return this.singletons.cmyk;
  38367. case 'CalGrayCS':
  38368. whitePoint = IR[1];
  38369. blackPoint = IR[2];
  38370. gamma = IR[3];
  38371. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38372. case 'CalRGBCS':
  38373. whitePoint = IR[1];
  38374. blackPoint = IR[2];
  38375. gamma = IR[3];
  38376. var matrix = IR[4];
  38377. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38378. case 'PatternCS':
  38379. var basePatternCS = IR[1];
  38380. if (basePatternCS) {
  38381. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38382. }
  38383. return new PatternCS(basePatternCS);
  38384. case 'IndexedCS':
  38385. var baseIndexedCS = IR[1];
  38386. var hiVal = IR[2];
  38387. var lookup = IR[3];
  38388. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38389. case 'AlternateCS':
  38390. var numComps = IR[1];
  38391. var alt = IR[2];
  38392. var tintFnIR = IR[3];
  38393. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38394. PDFFunction.fromIR(tintFnIR));
  38395. case 'LabCS':
  38396. whitePoint = IR[1];
  38397. blackPoint = IR[2];
  38398. var range = IR[3];
  38399. return new LabCS(whitePoint, blackPoint, range);
  38400. default:
  38401. error('Unknown name ' + name);
  38402. }
  38403. return null;
  38404. };
  38405. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38406. if (isName(cs)) {
  38407. var colorSpaces = res.get('ColorSpace');
  38408. if (isDict(colorSpaces)) {
  38409. var refcs = colorSpaces.get(cs.name);
  38410. if (refcs) {
  38411. cs = refcs;
  38412. }
  38413. }
  38414. }
  38415. cs = xref.fetchIfRef(cs);
  38416. var mode;
  38417. if (isName(cs)) {
  38418. mode = cs.name;
  38419. this.mode = mode;
  38420. switch (mode) {
  38421. case 'DeviceGray':
  38422. case 'G':
  38423. return 'DeviceGrayCS';
  38424. case 'DeviceRGB':
  38425. case 'RGB':
  38426. return 'DeviceRgbCS';
  38427. case 'DeviceCMYK':
  38428. case 'CMYK':
  38429. return 'DeviceCmykCS';
  38430. case 'Pattern':
  38431. return ['PatternCS', null];
  38432. default:
  38433. error('unrecognized colorspace ' + mode);
  38434. }
  38435. } else if (isArray(cs)) {
  38436. mode = xref.fetchIfRef(cs[0]).name;
  38437. this.mode = mode;
  38438. var numComps, params, alt, whitePoint, blackPoint, gamma;
  38439. switch (mode) {
  38440. case 'DeviceGray':
  38441. case 'G':
  38442. return 'DeviceGrayCS';
  38443. case 'DeviceRGB':
  38444. case 'RGB':
  38445. return 'DeviceRgbCS';
  38446. case 'DeviceCMYK':
  38447. case 'CMYK':
  38448. return 'DeviceCmykCS';
  38449. case 'CalGray':
  38450. params = xref.fetchIfRef(cs[1]);
  38451. whitePoint = params.getArray('WhitePoint');
  38452. blackPoint = params.getArray('BlackPoint');
  38453. gamma = params.get('Gamma');
  38454. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38455. case 'CalRGB':
  38456. params = xref.fetchIfRef(cs[1]);
  38457. whitePoint = params.getArray('WhitePoint');
  38458. blackPoint = params.getArray('BlackPoint');
  38459. gamma = params.getArray('Gamma');
  38460. var matrix = params.getArray('Matrix');
  38461. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38462. case 'ICCBased':
  38463. var stream = xref.fetchIfRef(cs[1]);
  38464. var dict = stream.dict;
  38465. numComps = dict.get('N');
  38466. alt = dict.get('Alternate');
  38467. if (alt) {
  38468. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38469. // Parse the /Alternate CS to ensure that the number of components
  38470. // are correct, and also (indirectly) that it is not a PatternCS.
  38471. var altCS = ColorSpace.fromIR(altIR);
  38472. if (altCS.numComps === numComps) {
  38473. return altIR;
  38474. }
  38475. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38476. }
  38477. if (numComps === 1) {
  38478. return 'DeviceGrayCS';
  38479. } else if (numComps === 3) {
  38480. return 'DeviceRgbCS';
  38481. } else if (numComps === 4) {
  38482. return 'DeviceCmykCS';
  38483. }
  38484. break;
  38485. case 'Pattern':
  38486. var basePatternCS = cs[1] || null;
  38487. if (basePatternCS) {
  38488. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38489. }
  38490. return ['PatternCS', basePatternCS];
  38491. case 'Indexed':
  38492. case 'I':
  38493. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38494. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38495. var lookup = xref.fetchIfRef(cs[3]);
  38496. if (isStream(lookup)) {
  38497. lookup = lookup.getBytes();
  38498. }
  38499. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38500. case 'Separation':
  38501. case 'DeviceN':
  38502. var name = xref.fetchIfRef(cs[1]);
  38503. numComps = 1;
  38504. if (isName(name)) {
  38505. numComps = 1;
  38506. } else if (isArray(name)) {
  38507. numComps = name.length;
  38508. }
  38509. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38510. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38511. return ['AlternateCS', numComps, alt, tintFnIR];
  38512. case 'Lab':
  38513. params = xref.fetchIfRef(cs[1]);
  38514. whitePoint = params.getArray('WhitePoint');
  38515. blackPoint = params.getArray('BlackPoint');
  38516. var range = params.getArray('Range');
  38517. return ['LabCS', whitePoint, blackPoint, range];
  38518. default:
  38519. error('unimplemented color space object "' + mode + '"');
  38520. }
  38521. } else {
  38522. error('unrecognized color space object: "' + cs + '"');
  38523. }
  38524. return null;
  38525. };
  38526. /**
  38527. * Checks if a decode map matches the default decode map for a color space.
  38528. * This handles the general decode maps where there are two values per
  38529. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38530. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38531. * slightly different.
  38532. * @param {Array} decode Decode map (usually from an image).
  38533. * @param {Number} n Number of components the color space has.
  38534. */
  38535. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38536. if (!isArray(decode)) {
  38537. return true;
  38538. }
  38539. if (n * 2 !== decode.length) {
  38540. warn('The decode map is not the correct length');
  38541. return true;
  38542. }
  38543. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38544. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38545. return false;
  38546. }
  38547. }
  38548. return true;
  38549. };
  38550. ColorSpace.singletons = {
  38551. get gray() {
  38552. return shadow(this, 'gray', new DeviceGrayCS());
  38553. },
  38554. get rgb() {
  38555. return shadow(this, 'rgb', new DeviceRgbCS());
  38556. },
  38557. get cmyk() {
  38558. return shadow(this, 'cmyk', new DeviceCmykCS());
  38559. }
  38560. };
  38561. return ColorSpace;
  38562. })();
  38563. /**
  38564. * Alternate color space handles both Separation and DeviceN color spaces. A
  38565. * Separation color space is actually just a DeviceN with one color component.
  38566. * Both color spaces use a tinting function to convert colors to a base color
  38567. * space.
  38568. */
  38569. var AlternateCS = (function AlternateCSClosure() {
  38570. function AlternateCS(numComps, base, tintFn) {
  38571. this.name = 'Alternate';
  38572. this.numComps = numComps;
  38573. this.defaultColor = new Float32Array(numComps);
  38574. for (var i = 0; i < numComps; ++i) {
  38575. this.defaultColor[i] = 1;
  38576. }
  38577. this.base = base;
  38578. this.tintFn = tintFn;
  38579. this.tmpBuf = new Float32Array(base.numComps);
  38580. }
  38581. AlternateCS.prototype = {
  38582. getRgb: ColorSpace.prototype.getRgb,
  38583. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38584. dest, destOffset) {
  38585. var tmpBuf = this.tmpBuf;
  38586. this.tintFn(src, srcOffset, tmpBuf, 0);
  38587. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38588. },
  38589. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38590. dest, destOffset, bits,
  38591. alpha01) {
  38592. var tintFn = this.tintFn;
  38593. var base = this.base;
  38594. var scale = 1 / ((1 << bits) - 1);
  38595. var baseNumComps = base.numComps;
  38596. var usesZeroToOneRange = base.usesZeroToOneRange;
  38597. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38598. alpha01 === 0;
  38599. var pos = isPassthrough ? destOffset : 0;
  38600. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38601. var numComps = this.numComps;
  38602. var scaled = new Float32Array(numComps);
  38603. var tinted = new Float32Array(baseNumComps);
  38604. var i, j;
  38605. if (usesZeroToOneRange) {
  38606. for (i = 0; i < count; i++) {
  38607. for (j = 0; j < numComps; j++) {
  38608. scaled[j] = src[srcOffset++] * scale;
  38609. }
  38610. tintFn(scaled, 0, tinted, 0);
  38611. for (j = 0; j < baseNumComps; j++) {
  38612. baseBuf[pos++] = tinted[j] * 255;
  38613. }
  38614. }
  38615. } else {
  38616. for (i = 0; i < count; i++) {
  38617. for (j = 0; j < numComps; j++) {
  38618. scaled[j] = src[srcOffset++] * scale;
  38619. }
  38620. tintFn(scaled, 0, tinted, 0);
  38621. base.getRgbItem(tinted, 0, baseBuf, pos);
  38622. pos += baseNumComps;
  38623. }
  38624. }
  38625. if (!isPassthrough) {
  38626. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38627. }
  38628. },
  38629. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38630. alpha01) {
  38631. return this.base.getOutputLength(inputLength *
  38632. this.base.numComps / this.numComps,
  38633. alpha01);
  38634. },
  38635. isPassthrough: ColorSpace.prototype.isPassthrough,
  38636. fillRgb: ColorSpace.prototype.fillRgb,
  38637. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38638. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38639. },
  38640. usesZeroToOneRange: true
  38641. };
  38642. return AlternateCS;
  38643. })();
  38644. var PatternCS = (function PatternCSClosure() {
  38645. function PatternCS(baseCS) {
  38646. this.name = 'Pattern';
  38647. this.base = baseCS;
  38648. }
  38649. PatternCS.prototype = {};
  38650. return PatternCS;
  38651. })();
  38652. var IndexedCS = (function IndexedCSClosure() {
  38653. function IndexedCS(base, highVal, lookup) {
  38654. this.name = 'Indexed';
  38655. this.numComps = 1;
  38656. this.defaultColor = new Uint8Array([0]);
  38657. this.base = base;
  38658. this.highVal = highVal;
  38659. var baseNumComps = base.numComps;
  38660. var length = baseNumComps * highVal;
  38661. var lookupArray;
  38662. if (isStream(lookup)) {
  38663. lookupArray = new Uint8Array(length);
  38664. var bytes = lookup.getBytes(length);
  38665. lookupArray.set(bytes);
  38666. } else if (isString(lookup)) {
  38667. lookupArray = new Uint8Array(length);
  38668. for (var i = 0; i < length; ++i) {
  38669. lookupArray[i] = lookup.charCodeAt(i);
  38670. }
  38671. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38672. lookupArray = lookup;
  38673. } else {
  38674. error('Unrecognized lookup table: ' + lookup);
  38675. }
  38676. this.lookup = lookupArray;
  38677. }
  38678. IndexedCS.prototype = {
  38679. getRgb: ColorSpace.prototype.getRgb,
  38680. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38681. dest, destOffset) {
  38682. var numComps = this.base.numComps;
  38683. var start = src[srcOffset] * numComps;
  38684. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38685. },
  38686. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38687. dest, destOffset, bits,
  38688. alpha01) {
  38689. var base = this.base;
  38690. var numComps = base.numComps;
  38691. var outputDelta = base.getOutputLength(numComps, alpha01);
  38692. var lookup = this.lookup;
  38693. for (var i = 0; i < count; ++i) {
  38694. var lookupPos = src[srcOffset++] * numComps;
  38695. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38696. destOffset += outputDelta;
  38697. }
  38698. },
  38699. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38700. return this.base.getOutputLength(inputLength * this.base.numComps,
  38701. alpha01);
  38702. },
  38703. isPassthrough: ColorSpace.prototype.isPassthrough,
  38704. fillRgb: ColorSpace.prototype.fillRgb,
  38705. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38706. // indexed color maps shouldn't be changed
  38707. return true;
  38708. },
  38709. usesZeroToOneRange: true
  38710. };
  38711. return IndexedCS;
  38712. })();
  38713. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38714. function DeviceGrayCS() {
  38715. this.name = 'DeviceGray';
  38716. this.numComps = 1;
  38717. this.defaultColor = new Float32Array([0]);
  38718. }
  38719. DeviceGrayCS.prototype = {
  38720. getRgb: ColorSpace.prototype.getRgb,
  38721. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38722. dest, destOffset) {
  38723. var c = (src[srcOffset] * 255) | 0;
  38724. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38725. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38726. },
  38727. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38728. dest, destOffset, bits,
  38729. alpha01) {
  38730. var scale = 255 / ((1 << bits) - 1);
  38731. var j = srcOffset, q = destOffset;
  38732. for (var i = 0; i < count; ++i) {
  38733. var c = (scale * src[j++]) | 0;
  38734. dest[q++] = c;
  38735. dest[q++] = c;
  38736. dest[q++] = c;
  38737. q += alpha01;
  38738. }
  38739. },
  38740. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38741. alpha01) {
  38742. return inputLength * (3 + alpha01);
  38743. },
  38744. isPassthrough: ColorSpace.prototype.isPassthrough,
  38745. fillRgb: ColorSpace.prototype.fillRgb,
  38746. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38747. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38748. },
  38749. usesZeroToOneRange: true
  38750. };
  38751. return DeviceGrayCS;
  38752. })();
  38753. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38754. function DeviceRgbCS() {
  38755. this.name = 'DeviceRGB';
  38756. this.numComps = 3;
  38757. this.defaultColor = new Float32Array([0, 0, 0]);
  38758. }
  38759. DeviceRgbCS.prototype = {
  38760. getRgb: ColorSpace.prototype.getRgb,
  38761. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38762. dest, destOffset) {
  38763. var r = (src[srcOffset] * 255) | 0;
  38764. var g = (src[srcOffset + 1] * 255) | 0;
  38765. var b = (src[srcOffset + 2] * 255) | 0;
  38766. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38767. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38768. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38769. },
  38770. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38771. dest, destOffset, bits,
  38772. alpha01) {
  38773. if (bits === 8 && alpha01 === 0) {
  38774. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38775. return;
  38776. }
  38777. var scale = 255 / ((1 << bits) - 1);
  38778. var j = srcOffset, q = destOffset;
  38779. for (var i = 0; i < count; ++i) {
  38780. dest[q++] = (scale * src[j++]) | 0;
  38781. dest[q++] = (scale * src[j++]) | 0;
  38782. dest[q++] = (scale * src[j++]) | 0;
  38783. q += alpha01;
  38784. }
  38785. },
  38786. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38787. alpha01) {
  38788. return (inputLength * (3 + alpha01) / 3) | 0;
  38789. },
  38790. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38791. return bits === 8;
  38792. },
  38793. fillRgb: ColorSpace.prototype.fillRgb,
  38794. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38795. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38796. },
  38797. usesZeroToOneRange: true
  38798. };
  38799. return DeviceRgbCS;
  38800. })();
  38801. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38802. // The coefficients below was found using numerical analysis: the method of
  38803. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38804. // where color_value is the tabular value from the table of sampled RGB colors
  38805. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38806. // CMYK color conversion using the estimation below:
  38807. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38808. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38809. var c = src[srcOffset + 0] * srcScale;
  38810. var m = src[srcOffset + 1] * srcScale;
  38811. var y = src[srcOffset + 2] * srcScale;
  38812. var k = src[srcOffset + 3] * srcScale;
  38813. var r =
  38814. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38815. 18.82290502165302 * y + 212.25662451639585 * k +
  38816. -285.2331026137004) +
  38817. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38818. -17.873870861415444 * k - 5.497006427196366) +
  38819. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38820. 17.5119270841813) +
  38821. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38822. var g =
  38823. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38824. 6.871425592049007 * y + 31.159100130055922 * k +
  38825. -79.2970844816548) +
  38826. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38827. 131.35250912493976 * k - 190.9453302588951) +
  38828. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38829. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38830. var b =
  38831. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38832. 30.89978309703729 * y - 0.23883238689178934 * k +
  38833. -14.183576799673286) +
  38834. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38835. 50.606957656360734 * k - 112.23884253719248) +
  38836. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38837. -193.58209356861505) +
  38838. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38839. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38840. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38841. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38842. }
  38843. function DeviceCmykCS() {
  38844. this.name = 'DeviceCMYK';
  38845. this.numComps = 4;
  38846. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38847. }
  38848. DeviceCmykCS.prototype = {
  38849. getRgb: ColorSpace.prototype.getRgb,
  38850. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38851. dest, destOffset) {
  38852. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38853. },
  38854. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38855. dest, destOffset, bits,
  38856. alpha01) {
  38857. var scale = 1 / ((1 << bits) - 1);
  38858. for (var i = 0; i < count; i++) {
  38859. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38860. srcOffset += 4;
  38861. destOffset += 3 + alpha01;
  38862. }
  38863. },
  38864. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38865. alpha01) {
  38866. return (inputLength / 4 * (3 + alpha01)) | 0;
  38867. },
  38868. isPassthrough: ColorSpace.prototype.isPassthrough,
  38869. fillRgb: ColorSpace.prototype.fillRgb,
  38870. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38871. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38872. },
  38873. usesZeroToOneRange: true
  38874. };
  38875. return DeviceCmykCS;
  38876. })();
  38877. //
  38878. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38879. //
  38880. var CalGrayCS = (function CalGrayCSClosure() {
  38881. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38882. this.name = 'CalGray';
  38883. this.numComps = 1;
  38884. this.defaultColor = new Float32Array([0]);
  38885. if (!whitePoint) {
  38886. error('WhitePoint missing - required for color space CalGray');
  38887. }
  38888. blackPoint = blackPoint || [0, 0, 0];
  38889. gamma = gamma || 1;
  38890. // Translate arguments to spec variables.
  38891. this.XW = whitePoint[0];
  38892. this.YW = whitePoint[1];
  38893. this.ZW = whitePoint[2];
  38894. this.XB = blackPoint[0];
  38895. this.YB = blackPoint[1];
  38896. this.ZB = blackPoint[2];
  38897. this.G = gamma;
  38898. // Validate variables as per spec.
  38899. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38900. error('Invalid WhitePoint components for ' + this.name +
  38901. ', no fallback available');
  38902. }
  38903. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38904. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38905. this.XB = this.YB = this.ZB = 0;
  38906. }
  38907. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38908. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38909. ', ZB: ' + this.ZB + ', only default values are supported.');
  38910. }
  38911. if (this.G < 1) {
  38912. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38913. ', falling back to default');
  38914. this.G = 1;
  38915. }
  38916. }
  38917. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38918. // A represents a gray component of a calibrated gray space.
  38919. // A <---> AG in the spec
  38920. var A = src[srcOffset] * scale;
  38921. var AG = Math.pow(A, cs.G);
  38922. // Computes L as per spec. ( = cs.YW * AG )
  38923. // Except if other than default BlackPoint values are used.
  38924. var L = cs.YW * AG;
  38925. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38926. // Convert values to rgb range [0, 255].
  38927. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38928. dest[destOffset] = val;
  38929. dest[destOffset + 1] = val;
  38930. dest[destOffset + 2] = val;
  38931. }
  38932. CalGrayCS.prototype = {
  38933. getRgb: ColorSpace.prototype.getRgb,
  38934. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38935. dest, destOffset) {
  38936. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38937. },
  38938. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38939. dest, destOffset, bits,
  38940. alpha01) {
  38941. var scale = 1 / ((1 << bits) - 1);
  38942. for (var i = 0; i < count; ++i) {
  38943. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38944. srcOffset += 1;
  38945. destOffset += 3 + alpha01;
  38946. }
  38947. },
  38948. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38949. return inputLength * (3 + alpha01);
  38950. },
  38951. isPassthrough: ColorSpace.prototype.isPassthrough,
  38952. fillRgb: ColorSpace.prototype.fillRgb,
  38953. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38954. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38955. },
  38956. usesZeroToOneRange: true
  38957. };
  38958. return CalGrayCS;
  38959. })();
  38960. //
  38961. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38962. //
  38963. var CalRGBCS = (function CalRGBCSClosure() {
  38964. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38965. // matrices.
  38966. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38967. 0.8951, 0.2664, -0.1614,
  38968. -0.7502, 1.7135, 0.0367,
  38969. 0.0389, -0.0685, 1.0296]);
  38970. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38971. 0.9869929, -0.1470543, 0.1599627,
  38972. 0.4323053, 0.5183603, 0.0492912,
  38973. -0.0085287, 0.0400428, 0.9684867]);
  38974. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38975. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38976. 3.2404542, -1.5371385, -0.4985314,
  38977. -0.9692660, 1.8760108, 0.0415560,
  38978. 0.0556434, -0.2040259, 1.0572252]);
  38979. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38980. var tempNormalizeMatrix = new Float32Array(3);
  38981. var tempConvertMatrix1 = new Float32Array(3);
  38982. var tempConvertMatrix2 = new Float32Array(3);
  38983. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38984. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38985. this.name = 'CalRGB';
  38986. this.numComps = 3;
  38987. this.defaultColor = new Float32Array(3);
  38988. if (!whitePoint) {
  38989. error('WhitePoint missing - required for color space CalRGB');
  38990. }
  38991. blackPoint = blackPoint || new Float32Array(3);
  38992. gamma = gamma || new Float32Array([1, 1, 1]);
  38993. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38994. // Translate arguments to spec variables.
  38995. var XW = whitePoint[0];
  38996. var YW = whitePoint[1];
  38997. var ZW = whitePoint[2];
  38998. this.whitePoint = whitePoint;
  38999. var XB = blackPoint[0];
  39000. var YB = blackPoint[1];
  39001. var ZB = blackPoint[2];
  39002. this.blackPoint = blackPoint;
  39003. this.GR = gamma[0];
  39004. this.GG = gamma[1];
  39005. this.GB = gamma[2];
  39006. this.MXA = matrix[0];
  39007. this.MYA = matrix[1];
  39008. this.MZA = matrix[2];
  39009. this.MXB = matrix[3];
  39010. this.MYB = matrix[4];
  39011. this.MZB = matrix[5];
  39012. this.MXC = matrix[6];
  39013. this.MYC = matrix[7];
  39014. this.MZC = matrix[8];
  39015. // Validate variables as per spec.
  39016. if (XW < 0 || ZW < 0 || YW !== 1) {
  39017. error('Invalid WhitePoint components for ' + this.name +
  39018. ', no fallback available');
  39019. }
  39020. if (XB < 0 || YB < 0 || ZB < 0) {
  39021. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  39022. ', ' + ZB + '], falling back to default');
  39023. this.blackPoint = new Float32Array(3);
  39024. }
  39025. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  39026. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  39027. '] for ' + this.name + ', falling back to default');
  39028. this.GR = this.GG = this.GB = 1;
  39029. }
  39030. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  39031. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  39032. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  39033. info('Invalid Matrix for ' + this.name + ' [' +
  39034. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  39035. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  39036. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  39037. '], falling back to default');
  39038. this.MXA = this.MYB = this.MZC = 1;
  39039. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  39040. }
  39041. }
  39042. function matrixProduct(a, b, result) {
  39043. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  39044. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  39045. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  39046. }
  39047. function convertToFlat(sourceWhitePoint, LMS, result) {
  39048. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  39049. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  39050. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  39051. }
  39052. function convertToD65(sourceWhitePoint, LMS, result) {
  39053. var D65X = 0.95047;
  39054. var D65Y = 1;
  39055. var D65Z = 1.08883;
  39056. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  39057. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  39058. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  39059. }
  39060. function sRGBTransferFunction(color) {
  39061. // See http://en.wikipedia.org/wiki/SRGB.
  39062. if (color <= 0.0031308){
  39063. return adjustToRange(0, 1, 12.92 * color);
  39064. }
  39065. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  39066. }
  39067. function adjustToRange(min, max, value) {
  39068. return Math.max(min, Math.min(max, value));
  39069. }
  39070. function decodeL(L) {
  39071. if (L < 0) {
  39072. return -decodeL(-L);
  39073. }
  39074. if (L > 8.0) {
  39075. return Math.pow(((L + 16) / 116), 3);
  39076. }
  39077. return L * DECODE_L_CONSTANT;
  39078. }
  39079. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  39080. // In case the blackPoint is already the default blackPoint then there is
  39081. // no need to do compensation.
  39082. if (sourceBlackPoint[0] === 0 &&
  39083. sourceBlackPoint[1] === 0 &&
  39084. sourceBlackPoint[2] === 0) {
  39085. result[0] = XYZ_Flat[0];
  39086. result[1] = XYZ_Flat[1];
  39087. result[2] = XYZ_Flat[2];
  39088. return;
  39089. }
  39090. // For the blackPoint calculation details, please see
  39091. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39092. // AdobeBPC.pdf.
  39093. // The destination blackPoint is the default blackPoint [0, 0, 0].
  39094. var zeroDecodeL = decodeL(0);
  39095. var X_DST = zeroDecodeL;
  39096. var X_SRC = decodeL(sourceBlackPoint[0]);
  39097. var Y_DST = zeroDecodeL;
  39098. var Y_SRC = decodeL(sourceBlackPoint[1]);
  39099. var Z_DST = zeroDecodeL;
  39100. var Z_SRC = decodeL(sourceBlackPoint[2]);
  39101. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  39102. var X_Offset = 1 - X_Scale;
  39103. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  39104. var Y_Offset = 1 - Y_Scale;
  39105. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  39106. var Z_Offset = 1 - Z_Scale;
  39107. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  39108. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  39109. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  39110. }
  39111. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  39112. // In case the whitePoint is already flat then there is no need to do
  39113. // normalization.
  39114. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  39115. result[0] = XYZ_In[0];
  39116. result[1] = XYZ_In[1];
  39117. result[2] = XYZ_In[2];
  39118. return;
  39119. }
  39120. var LMS = result;
  39121. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39122. var LMS_Flat = tempNormalizeMatrix;
  39123. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  39124. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  39125. }
  39126. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  39127. var LMS = result;
  39128. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39129. var LMS_D65 = tempNormalizeMatrix;
  39130. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  39131. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  39132. }
  39133. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39134. // A, B and C represent a red, green and blue components of a calibrated
  39135. // rgb space.
  39136. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  39137. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  39138. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  39139. // A <---> AGR in the spec
  39140. // B <---> BGG in the spec
  39141. // C <---> CGB in the spec
  39142. var AGR = Math.pow(A, cs.GR);
  39143. var BGG = Math.pow(B, cs.GG);
  39144. var CGB = Math.pow(C, cs.GB);
  39145. // Computes intermediate variables L, M, N as per spec.
  39146. // To decode X, Y, Z values map L, M, N directly to them.
  39147. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  39148. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  39149. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  39150. // The following calculations are based on this document:
  39151. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39152. // AdobeBPC.pdf.
  39153. var XYZ = tempConvertMatrix1;
  39154. XYZ[0] = X;
  39155. XYZ[1] = Y;
  39156. XYZ[2] = Z;
  39157. var XYZ_Flat = tempConvertMatrix2;
  39158. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  39159. var XYZ_Black = tempConvertMatrix1;
  39160. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  39161. var XYZ_D65 = tempConvertMatrix2;
  39162. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  39163. var SRGB = tempConvertMatrix1;
  39164. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  39165. var sR = sRGBTransferFunction(SRGB[0]);
  39166. var sG = sRGBTransferFunction(SRGB[1]);
  39167. var sB = sRGBTransferFunction(SRGB[2]);
  39168. // Convert the values to rgb range [0, 255].
  39169. dest[destOffset] = Math.round(sR * 255);
  39170. dest[destOffset + 1] = Math.round(sG * 255);
  39171. dest[destOffset + 2] = Math.round(sB * 255);
  39172. }
  39173. CalRGBCS.prototype = {
  39174. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39175. var rgb = new Uint8Array(3);
  39176. this.getRgbItem(src, srcOffset, rgb, 0);
  39177. return rgb;
  39178. },
  39179. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39180. dest, destOffset) {
  39181. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39182. },
  39183. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39184. dest, destOffset, bits,
  39185. alpha01) {
  39186. var scale = 1 / ((1 << bits) - 1);
  39187. for (var i = 0; i < count; ++i) {
  39188. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39189. srcOffset += 3;
  39190. destOffset += 3 + alpha01;
  39191. }
  39192. },
  39193. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39194. return (inputLength * (3 + alpha01) / 3) | 0;
  39195. },
  39196. isPassthrough: ColorSpace.prototype.isPassthrough,
  39197. fillRgb: ColorSpace.prototype.fillRgb,
  39198. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39199. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39200. },
  39201. usesZeroToOneRange: true
  39202. };
  39203. return CalRGBCS;
  39204. })();
  39205. //
  39206. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39207. //
  39208. var LabCS = (function LabCSClosure() {
  39209. function LabCS(whitePoint, blackPoint, range) {
  39210. this.name = 'Lab';
  39211. this.numComps = 3;
  39212. this.defaultColor = new Float32Array([0, 0, 0]);
  39213. if (!whitePoint) {
  39214. error('WhitePoint missing - required for color space Lab');
  39215. }
  39216. blackPoint = blackPoint || [0, 0, 0];
  39217. range = range || [-100, 100, -100, 100];
  39218. // Translate args to spec variables
  39219. this.XW = whitePoint[0];
  39220. this.YW = whitePoint[1];
  39221. this.ZW = whitePoint[2];
  39222. this.amin = range[0];
  39223. this.amax = range[1];
  39224. this.bmin = range[2];
  39225. this.bmax = range[3];
  39226. // These are here just for completeness - the spec doesn't offer any
  39227. // formulas that use BlackPoint in Lab
  39228. this.XB = blackPoint[0];
  39229. this.YB = blackPoint[1];
  39230. this.ZB = blackPoint[2];
  39231. // Validate vars as per spec
  39232. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39233. error('Invalid WhitePoint components, no fallback available');
  39234. }
  39235. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39236. info('Invalid BlackPoint, falling back to default');
  39237. this.XB = this.YB = this.ZB = 0;
  39238. }
  39239. if (this.amin > this.amax || this.bmin > this.bmax) {
  39240. info('Invalid Range, falling back to defaults');
  39241. this.amin = -100;
  39242. this.amax = 100;
  39243. this.bmin = -100;
  39244. this.bmax = 100;
  39245. }
  39246. }
  39247. // Function g(x) from spec
  39248. function fn_g(x) {
  39249. if (x >= 6 / 29) {
  39250. return x * x * x;
  39251. } else {
  39252. return (108 / 841) * (x - 4 / 29);
  39253. }
  39254. }
  39255. function decode(value, high1, low2, high2) {
  39256. return low2 + (value) * (high2 - low2) / (high1);
  39257. }
  39258. // If decoding is needed maxVal should be 2^bits per component - 1.
  39259. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39260. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39261. // not the usual [0, 1]. If a command like setFillColor is used the src
  39262. // values will already be within the correct range. However, if we are
  39263. // converting an image we have to map the values to the correct range given
  39264. // above.
  39265. // Ls,as,bs <---> L*,a*,b* in the spec
  39266. var Ls = src[srcOffset];
  39267. var as = src[srcOffset + 1];
  39268. var bs = src[srcOffset + 2];
  39269. if (maxVal !== false) {
  39270. Ls = decode(Ls, maxVal, 0, 100);
  39271. as = decode(as, maxVal, cs.amin, cs.amax);
  39272. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39273. }
  39274. // Adjust limits of 'as' and 'bs'
  39275. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39276. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39277. // Computes intermediate variables X,Y,Z as per spec
  39278. var M = (Ls + 16) / 116;
  39279. var L = M + (as / 500);
  39280. var N = M - (bs / 200);
  39281. var X = cs.XW * fn_g(L);
  39282. var Y = cs.YW * fn_g(M);
  39283. var Z = cs.ZW * fn_g(N);
  39284. var r, g, b;
  39285. // Using different conversions for D50 and D65 white points,
  39286. // per http://www.color.org/srgb.pdf
  39287. if (cs.ZW < 1) {
  39288. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39289. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39290. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39291. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39292. } else {
  39293. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39294. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39295. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39296. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39297. }
  39298. // clamp color values to [0,1] range then convert to [0,255] range.
  39299. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39300. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39301. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39302. }
  39303. LabCS.prototype = {
  39304. getRgb: ColorSpace.prototype.getRgb,
  39305. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39306. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39307. },
  39308. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39309. dest, destOffset, bits,
  39310. alpha01) {
  39311. var maxVal = (1 << bits) - 1;
  39312. for (var i = 0; i < count; i++) {
  39313. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39314. srcOffset += 3;
  39315. destOffset += 3 + alpha01;
  39316. }
  39317. },
  39318. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39319. return (inputLength * (3 + alpha01) / 3) | 0;
  39320. },
  39321. isPassthrough: ColorSpace.prototype.isPassthrough,
  39322. fillRgb: ColorSpace.prototype.fillRgb,
  39323. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39324. // XXX: Decoding is handled with the lab conversion because of the strange
  39325. // ranges that are used.
  39326. return true;
  39327. },
  39328. usesZeroToOneRange: false
  39329. };
  39330. return LabCS;
  39331. })();
  39332. exports.ColorSpace = ColorSpace;
  39333. }));
  39334. (function (root, factory) {
  39335. {
  39336. factory((root.pdfjsDisplayGlobal = {}), root.pdfjsSharedUtil,
  39337. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI,
  39338. root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer,
  39339. root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  39340. }
  39341. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI,
  39342. displayAnnotationLayer, displayTextLayer, displayMetadata,
  39343. displaySVG) {
  39344. var globalScope = sharedUtil.globalScope;
  39345. var deprecated = sharedUtil.deprecated;
  39346. var warn = sharedUtil.warn;
  39347. var LinkTarget = displayDOMUtils.LinkTarget;
  39348. var isWorker = (typeof window === 'undefined');
  39349. // The global PDFJS object is now deprecated and will not be supported in
  39350. // the future. The members below are maintained for backward compatibility
  39351. // and shall not be extended or modified. If the global.js is included as
  39352. // a module, we will create a global PDFJS object instance or use existing.
  39353. if (!globalScope.PDFJS) {
  39354. globalScope.PDFJS = {};
  39355. }
  39356. var PDFJS = globalScope.PDFJS;
  39357. if (typeof pdfjsVersion !== 'undefined') {
  39358. PDFJS.version = pdfjsVersion;
  39359. }
  39360. if (typeof pdfjsBuild !== 'undefined') {
  39361. PDFJS.build = pdfjsBuild;
  39362. }
  39363. PDFJS.pdfBug = false;
  39364. if (PDFJS.verbosity !== undefined) {
  39365. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  39366. }
  39367. delete PDFJS.verbosity;
  39368. Object.defineProperty(PDFJS, 'verbosity', {
  39369. get: function () { return sharedUtil.getVerbosityLevel(); },
  39370. set: function (level) { sharedUtil.setVerbosityLevel(level); },
  39371. enumerable: true,
  39372. configurable: true
  39373. });
  39374. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  39375. PDFJS.OPS = sharedUtil.OPS;
  39376. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39377. PDFJS.isValidUrl = sharedUtil.isValidUrl;
  39378. PDFJS.shadow = sharedUtil.shadow;
  39379. PDFJS.createBlob = sharedUtil.createBlob;
  39380. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  39381. return sharedUtil.createObjectURL(data, contentType,
  39382. PDFJS.disableCreateObjectURL);
  39383. };
  39384. Object.defineProperty(PDFJS, 'isLittleEndian', {
  39385. configurable: true,
  39386. get: function PDFJS_isLittleEndian() {
  39387. var value = sharedUtil.isLittleEndian();
  39388. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  39389. }
  39390. });
  39391. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  39392. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  39393. PDFJS.PasswordException = sharedUtil.PasswordException;
  39394. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  39395. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  39396. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  39397. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39398. PDFJS.Util = sharedUtil.Util;
  39399. PDFJS.PageViewport = sharedUtil.PageViewport;
  39400. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  39401. /**
  39402. * The maximum allowed image size in total pixels e.g. width * height. Images
  39403. * above this value will not be drawn. Use -1 for no limit.
  39404. * @var {number}
  39405. */
  39406. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  39407. -1 : PDFJS.maxImageSize);
  39408. /**
  39409. * The url of where the predefined Adobe CMaps are located. Include trailing
  39410. * slash.
  39411. * @var {string}
  39412. */
  39413. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  39414. /**
  39415. * Specifies if CMaps are binary packed.
  39416. * @var {boolean}
  39417. */
  39418. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  39419. /**
  39420. * By default fonts are converted to OpenType fonts and loaded via font face
  39421. * rules. If disabled, the font will be rendered using a built in font
  39422. * renderer that constructs the glyphs with primitive path commands.
  39423. * @var {boolean}
  39424. */
  39425. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  39426. false : PDFJS.disableFontFace);
  39427. /**
  39428. * Path for image resources, mainly for annotation icons. Include trailing
  39429. * slash.
  39430. * @var {string}
  39431. */
  39432. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  39433. '' : PDFJS.imageResourcesPath);
  39434. /**
  39435. * Disable the web worker and run all code on the main thread. This will
  39436. * happen automatically if the browser doesn't support workers or sending
  39437. * typed arrays to workers.
  39438. * @var {boolean}
  39439. */
  39440. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  39441. false : PDFJS.disableWorker);
  39442. /**
  39443. * Path and filename of the worker file. Required when the worker is enabled
  39444. * in development mode. If unspecified in the production build, the worker
  39445. * will be loaded based on the location of the pdf.js file. It is recommended
  39446. * that the workerSrc is set in a custom application to prevent issues caused
  39447. * by third-party frameworks and libraries.
  39448. * @var {string}
  39449. */
  39450. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  39451. /**
  39452. * Disable range request loading of PDF files. When enabled and if the server
  39453. * supports partial content requests then the PDF will be fetched in chunks.
  39454. * Enabled (false) by default.
  39455. * @var {boolean}
  39456. */
  39457. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  39458. false : PDFJS.disableRange);
  39459. /**
  39460. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  39461. * in chunks. This default behavior can be disabled.
  39462. * @var {boolean}
  39463. */
  39464. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  39465. false : PDFJS.disableStream);
  39466. /**
  39467. * Disable pre-fetching of PDF file data. When range requests are enabled
  39468. * PDF.js will automatically keep fetching more data even if it isn't needed
  39469. * to display the current page. This default behavior can be disabled.
  39470. *
  39471. * NOTE: It is also necessary to disable streaming, see above,
  39472. * in order for disabling of pre-fetching to work correctly.
  39473. * @var {boolean}
  39474. */
  39475. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  39476. false : PDFJS.disableAutoFetch);
  39477. /**
  39478. * Enables special hooks for debugging PDF.js.
  39479. * @var {boolean}
  39480. */
  39481. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  39482. /**
  39483. * Enables transfer usage in postMessage for ArrayBuffers.
  39484. * @var {boolean}
  39485. */
  39486. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  39487. true : PDFJS.postMessageTransfers);
  39488. /**
  39489. * Disables URL.createObjectURL usage.
  39490. * @var {boolean}
  39491. */
  39492. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  39493. false : PDFJS.disableCreateObjectURL);
  39494. /**
  39495. * Disables WebGL usage.
  39496. * @var {boolean}
  39497. */
  39498. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  39499. true : PDFJS.disableWebGL);
  39500. /**
  39501. * Specifies the |target| attribute for external links.
  39502. * The constants from PDFJS.LinkTarget should be used:
  39503. * - NONE [default]
  39504. * - SELF
  39505. * - BLANK
  39506. * - PARENT
  39507. * - TOP
  39508. * @var {number}
  39509. */
  39510. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  39511. LinkTarget.NONE : PDFJS.externalLinkTarget);
  39512. /**
  39513. * Specifies the |rel| attribute for external links. Defaults to stripping
  39514. * the referrer.
  39515. * @var {string}
  39516. */
  39517. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  39518. 'noreferrer' : PDFJS.externalLinkRel);
  39519. /**
  39520. * Determines if we can eval strings as JS. Primarily used to improve
  39521. * performance for font rendering.
  39522. * @var {boolean}
  39523. */
  39524. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  39525. true : PDFJS.isEvalSupported);
  39526. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  39527. delete PDFJS.openExternalLinksInNewWindow;
  39528. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  39529. get: function () {
  39530. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  39531. },
  39532. set: function (value) {
  39533. if (value) {
  39534. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  39535. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  39536. }
  39537. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  39538. warn('PDFJS.externalLinkTarget is already initialized');
  39539. return;
  39540. }
  39541. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  39542. },
  39543. enumerable: true,
  39544. configurable: true
  39545. });
  39546. if (savedOpenExternalLinksInNewWindow) {
  39547. /**
  39548. * (Deprecated) Opens external links in a new window if enabled.
  39549. * The default behavior opens external links in the PDF.js window.
  39550. *
  39551. * NOTE: This property has been deprecated, please use
  39552. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  39553. * @var {boolean}
  39554. */
  39555. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  39556. }
  39557. PDFJS.getDocument = displayAPI.getDocument;
  39558. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  39559. PDFJS.PDFWorker = displayAPI.PDFWorker;
  39560. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  39561. configurable: true,
  39562. get: function PDFJS_hasCanvasTypedArrays() {
  39563. var value = displayDOMUtils.hasCanvasTypedArrays();
  39564. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  39565. }
  39566. });
  39567. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  39568. PDFJS.LinkTarget = LinkTarget;
  39569. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  39570. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  39571. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  39572. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  39573. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  39574. PDFJS.Metadata = displayMetadata.Metadata;
  39575. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  39576. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  39577. exports.globalScope = globalScope;
  39578. exports.isWorker = isWorker;
  39579. exports.PDFJS = globalScope.PDFJS;
  39580. }));
  39581. (function (root, factory) {
  39582. {
  39583. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39584. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39585. root.pdfjsCoreJpx);
  39586. }
  39587. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39588. coreStream, coreJpx) {
  39589. var ImageKind = sharedUtil.ImageKind;
  39590. var assert = sharedUtil.assert;
  39591. var error = sharedUtil.error;
  39592. var info = sharedUtil.info;
  39593. var isArray = sharedUtil.isArray;
  39594. var warn = sharedUtil.warn;
  39595. var Name = corePrimitives.Name;
  39596. var isStream = corePrimitives.isStream;
  39597. var ColorSpace = coreColorSpace.ColorSpace;
  39598. var DecodeStream = coreStream.DecodeStream;
  39599. var JpegStream = coreStream.JpegStream;
  39600. var JpxImage = coreJpx.JpxImage;
  39601. var PDFImage = (function PDFImageClosure() {
  39602. /**
  39603. * Decodes the image using native decoder if possible. Resolves the promise
  39604. * when the image data is ready.
  39605. */
  39606. function handleImageData(image, nativeDecoder) {
  39607. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  39608. return nativeDecoder.decode(image);
  39609. } else {
  39610. return Promise.resolve(image);
  39611. }
  39612. }
  39613. /**
  39614. * Decode and clamp a value. The formula is different from the spec because we
  39615. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39616. */
  39617. function decodeAndClamp(value, addend, coefficient, max) {
  39618. value = addend + value * coefficient;
  39619. // Clamp the value to the range
  39620. return (value < 0 ? 0 : (value > max ? max : value));
  39621. }
  39622. /**
  39623. * Resizes an image mask with 1 component.
  39624. * @param {TypedArray} src - The source buffer.
  39625. * @param {Number} bpc - Number of bits per component.
  39626. * @param {Number} w1 - Original width.
  39627. * @param {Number} h1 - Original height.
  39628. * @param {Number} w2 - New width.
  39629. * @param {Number} h2 - New height.
  39630. * @returns {TypedArray} The resized image mask buffer.
  39631. */
  39632. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  39633. var length = w2 * h2;
  39634. var dest = (bpc <= 8 ? new Uint8Array(length) :
  39635. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39636. var xRatio = w1 / w2;
  39637. var yRatio = h1 / h2;
  39638. var i, j, py, newIndex = 0, oldIndex;
  39639. var xScaled = new Uint16Array(w2);
  39640. var w1Scanline = w1;
  39641. for (i = 0; i < w2; i++) {
  39642. xScaled[i] = Math.floor(i * xRatio);
  39643. }
  39644. for (i = 0; i < h2; i++) {
  39645. py = Math.floor(i * yRatio) * w1Scanline;
  39646. for (j = 0; j < w2; j++) {
  39647. oldIndex = py + xScaled[j];
  39648. dest[newIndex++] = src[oldIndex];
  39649. }
  39650. }
  39651. return dest;
  39652. }
  39653. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39654. this.image = image;
  39655. var dict = image.dict;
  39656. if (dict.has('Filter')) {
  39657. var filter = dict.get('Filter').name;
  39658. if (filter === 'JPXDecode') {
  39659. var jpxImage = new JpxImage();
  39660. jpxImage.parseImageProperties(image.stream);
  39661. image.stream.reset();
  39662. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39663. image.numComps = jpxImage.componentsCount;
  39664. } else if (filter === 'JBIG2Decode') {
  39665. image.bitsPerComponent = 1;
  39666. image.numComps = 1;
  39667. }
  39668. }
  39669. // TODO cache rendered images?
  39670. this.width = dict.get('Width', 'W');
  39671. this.height = dict.get('Height', 'H');
  39672. if (this.width < 1 || this.height < 1) {
  39673. error('Invalid image width: ' + this.width + ' or height: ' +
  39674. this.height);
  39675. }
  39676. this.interpolate = dict.get('Interpolate', 'I') || false;
  39677. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39678. this.matte = dict.get('Matte') || false;
  39679. var bitsPerComponent = image.bitsPerComponent;
  39680. if (!bitsPerComponent) {
  39681. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39682. if (!bitsPerComponent) {
  39683. if (this.imageMask) {
  39684. bitsPerComponent = 1;
  39685. } else {
  39686. error('Bits per component missing in image: ' + this.imageMask);
  39687. }
  39688. }
  39689. }
  39690. this.bpc = bitsPerComponent;
  39691. if (!this.imageMask) {
  39692. var colorSpace = dict.get('ColorSpace', 'CS');
  39693. if (!colorSpace) {
  39694. info('JPX images (which do not require color spaces)');
  39695. switch (image.numComps) {
  39696. case 1:
  39697. colorSpace = Name.get('DeviceGray');
  39698. break;
  39699. case 3:
  39700. colorSpace = Name.get('DeviceRGB');
  39701. break;
  39702. case 4:
  39703. colorSpace = Name.get('DeviceCMYK');
  39704. break;
  39705. default:
  39706. error('JPX images with ' + this.numComps +
  39707. ' color components not supported.');
  39708. }
  39709. }
  39710. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39711. this.numComps = this.colorSpace.numComps;
  39712. }
  39713. this.decode = dict.getArray('Decode', 'D');
  39714. this.needsDecode = false;
  39715. if (this.decode &&
  39716. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39717. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39718. this.needsDecode = true;
  39719. // Do some preprocessing to avoid more math.
  39720. var max = (1 << bitsPerComponent) - 1;
  39721. this.decodeCoefficients = [];
  39722. this.decodeAddends = [];
  39723. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39724. var dmin = this.decode[i];
  39725. var dmax = this.decode[i + 1];
  39726. this.decodeCoefficients[j] = dmax - dmin;
  39727. this.decodeAddends[j] = max * dmin;
  39728. }
  39729. }
  39730. if (smask) {
  39731. this.smask = new PDFImage(xref, res, smask, false);
  39732. } else if (mask) {
  39733. if (isStream(mask)) {
  39734. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39735. if (!imageMask) {
  39736. warn('Ignoring /Mask in image without /ImageMask.');
  39737. } else {
  39738. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39739. }
  39740. } else {
  39741. // Color key mask (just an array).
  39742. this.mask = mask;
  39743. }
  39744. }
  39745. }
  39746. /**
  39747. * Handles processing of image data and returns the Promise that is resolved
  39748. * with a PDFImage when the image is ready to be used.
  39749. */
  39750. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39751. res, image, inline,
  39752. nativeDecoder) {
  39753. var imagePromise = handleImageData(image, nativeDecoder);
  39754. var smaskPromise;
  39755. var maskPromise;
  39756. var smask = image.dict.get('SMask');
  39757. var mask = image.dict.get('Mask');
  39758. if (smask) {
  39759. smaskPromise = handleImageData(smask, nativeDecoder);
  39760. maskPromise = Promise.resolve(null);
  39761. } else {
  39762. smaskPromise = Promise.resolve(null);
  39763. if (mask) {
  39764. if (isStream(mask)) {
  39765. maskPromise = handleImageData(mask, nativeDecoder);
  39766. } else if (isArray(mask)) {
  39767. maskPromise = Promise.resolve(mask);
  39768. } else {
  39769. warn('Unsupported mask format.');
  39770. maskPromise = Promise.resolve(null);
  39771. }
  39772. } else {
  39773. maskPromise = Promise.resolve(null);
  39774. }
  39775. }
  39776. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39777. function(results) {
  39778. var imageData = results[0];
  39779. var smaskData = results[1];
  39780. var maskData = results[2];
  39781. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39782. });
  39783. };
  39784. PDFImage.createMask =
  39785. function PDFImage_createMask(imgArray, width, height,
  39786. imageIsFromDecodeStream, inverseDecode) {
  39787. // |imgArray| might not contain full data for every pixel of the mask, so
  39788. // we need to distinguish between |computedLength| and |actualLength|.
  39789. // In particular, if inverseDecode is true, then the array we return must
  39790. // have a length of |computedLength|.
  39791. var computedLength = ((width + 7) >> 3) * height;
  39792. var actualLength = imgArray.byteLength;
  39793. var haveFullData = computedLength === actualLength;
  39794. var data, i;
  39795. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39796. // imgArray came from a DecodeStream and its data is in an appropriate
  39797. // form, so we can just transfer it.
  39798. data = imgArray;
  39799. } else if (!inverseDecode) {
  39800. data = new Uint8Array(actualLength);
  39801. data.set(imgArray);
  39802. } else {
  39803. data = new Uint8Array(computedLength);
  39804. data.set(imgArray);
  39805. for (i = actualLength; i < computedLength; i++) {
  39806. data[i] = 0xff;
  39807. }
  39808. }
  39809. // If necessary, invert the original mask data (but not any extra we might
  39810. // have added above). It's safe to modify the array -- whether it's the
  39811. // original or a copy, we're about to transfer it anyway, so nothing else
  39812. // in this thread can be relying on its contents.
  39813. if (inverseDecode) {
  39814. for (i = 0; i < actualLength; i++) {
  39815. data[i] = ~data[i];
  39816. }
  39817. }
  39818. return {data: data, width: width, height: height};
  39819. };
  39820. PDFImage.prototype = {
  39821. get drawWidth() {
  39822. return Math.max(this.width,
  39823. this.smask && this.smask.width || 0,
  39824. this.mask && this.mask.width || 0);
  39825. },
  39826. get drawHeight() {
  39827. return Math.max(this.height,
  39828. this.smask && this.smask.height || 0,
  39829. this.mask && this.mask.height || 0);
  39830. },
  39831. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39832. var bpc = this.bpc;
  39833. var numComps = this.numComps;
  39834. var decodeAddends = this.decodeAddends;
  39835. var decodeCoefficients = this.decodeCoefficients;
  39836. var max = (1 << bpc) - 1;
  39837. var i, ii;
  39838. if (bpc === 1) {
  39839. // If the buffer needed decode that means it just needs to be inverted.
  39840. for (i = 0, ii = buffer.length; i < ii; i++) {
  39841. buffer[i] = +!(buffer[i]);
  39842. }
  39843. return;
  39844. }
  39845. var index = 0;
  39846. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39847. for (var j = 0; j < numComps; j++) {
  39848. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39849. decodeCoefficients[j], max);
  39850. index++;
  39851. }
  39852. }
  39853. },
  39854. getComponents: function PDFImage_getComponents(buffer) {
  39855. var bpc = this.bpc;
  39856. // This image doesn't require any extra work.
  39857. if (bpc === 8) {
  39858. return buffer;
  39859. }
  39860. var width = this.width;
  39861. var height = this.height;
  39862. var numComps = this.numComps;
  39863. var length = width * height * numComps;
  39864. var bufferPos = 0;
  39865. var output = (bpc <= 8 ? new Uint8Array(length) :
  39866. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39867. var rowComps = width * numComps;
  39868. var max = (1 << bpc) - 1;
  39869. var i = 0, ii, buf;
  39870. if (bpc === 1) {
  39871. // Optimization for reading 1 bpc images.
  39872. var mask, loop1End, loop2End;
  39873. for (var j = 0; j < height; j++) {
  39874. loop1End = i + (rowComps & ~7);
  39875. loop2End = i + rowComps;
  39876. // unroll loop for all full bytes
  39877. while (i < loop1End) {
  39878. buf = buffer[bufferPos++];
  39879. output[i] = (buf >> 7) & 1;
  39880. output[i + 1] = (buf >> 6) & 1;
  39881. output[i + 2] = (buf >> 5) & 1;
  39882. output[i + 3] = (buf >> 4) & 1;
  39883. output[i + 4] = (buf >> 3) & 1;
  39884. output[i + 5] = (buf >> 2) & 1;
  39885. output[i + 6] = (buf >> 1) & 1;
  39886. output[i + 7] = buf & 1;
  39887. i += 8;
  39888. }
  39889. // handle remaining bits
  39890. if (i < loop2End) {
  39891. buf = buffer[bufferPos++];
  39892. mask = 128;
  39893. while (i < loop2End) {
  39894. output[i++] = +!!(buf & mask);
  39895. mask >>= 1;
  39896. }
  39897. }
  39898. }
  39899. } else {
  39900. // The general case that handles all other bpc values.
  39901. var bits = 0;
  39902. buf = 0;
  39903. for (i = 0, ii = length; i < ii; ++i) {
  39904. if (i % rowComps === 0) {
  39905. buf = 0;
  39906. bits = 0;
  39907. }
  39908. while (bits < bpc) {
  39909. buf = (buf << 8) | buffer[bufferPos++];
  39910. bits += 8;
  39911. }
  39912. var remainingBits = bits - bpc;
  39913. var value = buf >> remainingBits;
  39914. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39915. buf = buf & ((1 << remainingBits) - 1);
  39916. bits = remainingBits;
  39917. }
  39918. }
  39919. return output;
  39920. },
  39921. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39922. actualHeight, image) {
  39923. var smask = this.smask;
  39924. var mask = this.mask;
  39925. var alphaBuf, sw, sh, i, ii, j;
  39926. if (smask) {
  39927. sw = smask.width;
  39928. sh = smask.height;
  39929. alphaBuf = new Uint8Array(sw * sh);
  39930. smask.fillGrayBuffer(alphaBuf);
  39931. if (sw !== width || sh !== height) {
  39932. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  39933. width, height);
  39934. }
  39935. } else if (mask) {
  39936. if (mask instanceof PDFImage) {
  39937. sw = mask.width;
  39938. sh = mask.height;
  39939. alphaBuf = new Uint8Array(sw * sh);
  39940. mask.numComps = 1;
  39941. mask.fillGrayBuffer(alphaBuf);
  39942. // Need to invert values in rgbaBuf
  39943. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39944. alphaBuf[i] = 255 - alphaBuf[i];
  39945. }
  39946. if (sw !== width || sh !== height) {
  39947. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  39948. width, height);
  39949. }
  39950. } else if (isArray(mask)) {
  39951. // Color key mask: if any of the components are outside the range
  39952. // then they should be painted.
  39953. alphaBuf = new Uint8Array(width * height);
  39954. var numComps = this.numComps;
  39955. for (i = 0, ii = width * height; i < ii; ++i) {
  39956. var opacity = 0;
  39957. var imageOffset = i * numComps;
  39958. for (j = 0; j < numComps; ++j) {
  39959. var color = image[imageOffset + j];
  39960. var maskOffset = j * 2;
  39961. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39962. opacity = 255;
  39963. break;
  39964. }
  39965. }
  39966. alphaBuf[i] = opacity;
  39967. }
  39968. } else {
  39969. error('Unknown mask format.');
  39970. }
  39971. }
  39972. if (alphaBuf) {
  39973. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39974. rgbaBuf[j] = alphaBuf[i];
  39975. }
  39976. } else {
  39977. // No mask.
  39978. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39979. rgbaBuf[j] = 255;
  39980. }
  39981. }
  39982. },
  39983. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39984. var matte = this.smask && this.smask.matte;
  39985. if (!matte) {
  39986. return;
  39987. }
  39988. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39989. var matteR = matteRgb[0];
  39990. var matteG = matteRgb[1];
  39991. var matteB = matteRgb[2];
  39992. var length = width * height * 4;
  39993. var r, g, b;
  39994. for (var i = 0; i < length; i += 4) {
  39995. var alpha = buffer[i + 3];
  39996. if (alpha === 0) {
  39997. // according formula we have to get Infinity in all components
  39998. // making it white (typical paper color) should be okay
  39999. buffer[i] = 255;
  40000. buffer[i + 1] = 255;
  40001. buffer[i + 2] = 255;
  40002. continue;
  40003. }
  40004. var k = 255 / alpha;
  40005. r = (buffer[i] - matteR) * k + matteR;
  40006. g = (buffer[i + 1] - matteG) * k + matteG;
  40007. b = (buffer[i + 2] - matteB) * k + matteB;
  40008. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  40009. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  40010. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  40011. }
  40012. },
  40013. createImageData: function PDFImage_createImageData(forceRGBA) {
  40014. var drawWidth = this.drawWidth;
  40015. var drawHeight = this.drawHeight;
  40016. var imgData = { // other fields are filled in below
  40017. width: drawWidth,
  40018. height: drawHeight
  40019. };
  40020. var numComps = this.numComps;
  40021. var originalWidth = this.width;
  40022. var originalHeight = this.height;
  40023. var bpc = this.bpc;
  40024. // Rows start at byte boundary.
  40025. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  40026. var imgArray;
  40027. if (!forceRGBA) {
  40028. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  40029. // without any complications, we pass a same-sized copy to the main
  40030. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  40031. // of memory for many scanned documents. It's also much faster.
  40032. //
  40033. // Similarly, if it is a 24-bit-per pixel RGB image without any
  40034. // complications, we avoid expanding by 1.333x to RGBA form.
  40035. var kind;
  40036. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  40037. kind = ImageKind.GRAYSCALE_1BPP;
  40038. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  40039. !this.needsDecode) {
  40040. kind = ImageKind.RGB_24BPP;
  40041. }
  40042. if (kind && !this.smask && !this.mask &&
  40043. drawWidth === originalWidth && drawHeight === originalHeight) {
  40044. imgData.kind = kind;
  40045. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40046. // If imgArray came from a DecodeStream, we're safe to transfer it
  40047. // (and thus detach its underlying buffer) because it will constitute
  40048. // the entire DecodeStream's data. But if it came from a Stream, we
  40049. // need to copy it because it'll only be a portion of the Stream's
  40050. // data, and the rest will be read later on.
  40051. if (this.image instanceof DecodeStream) {
  40052. imgData.data = imgArray;
  40053. } else {
  40054. var newArray = new Uint8Array(imgArray.length);
  40055. newArray.set(imgArray);
  40056. imgData.data = newArray;
  40057. }
  40058. if (this.needsDecode) {
  40059. // Invert the buffer (which must be grayscale if we reached here).
  40060. assert(kind === ImageKind.GRAYSCALE_1BPP);
  40061. var buffer = imgData.data;
  40062. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40063. buffer[i] ^= 0xff;
  40064. }
  40065. }
  40066. return imgData;
  40067. }
  40068. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  40069. (this.colorSpace.name === 'DeviceGray' ||
  40070. this.colorSpace.name === 'DeviceRGB' ||
  40071. this.colorSpace.name === 'DeviceCMYK')) {
  40072. imgData.kind = ImageKind.RGB_24BPP;
  40073. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  40074. drawWidth, drawHeight, true);
  40075. return imgData;
  40076. }
  40077. }
  40078. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40079. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  40080. var actualHeight = 0 | (imgArray.length / rowBytes *
  40081. drawHeight / originalHeight);
  40082. var comps = this.getComponents(imgArray);
  40083. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  40084. // more compact RGB_24BPP form if allowable.
  40085. var alpha01, maybeUndoPreblend;
  40086. if (!forceRGBA && !this.smask && !this.mask) {
  40087. imgData.kind = ImageKind.RGB_24BPP;
  40088. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  40089. alpha01 = 0;
  40090. maybeUndoPreblend = false;
  40091. } else {
  40092. imgData.kind = ImageKind.RGBA_32BPP;
  40093. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  40094. alpha01 = 1;
  40095. maybeUndoPreblend = true;
  40096. // Color key masking (opacity) must be performed before decoding.
  40097. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  40098. comps);
  40099. }
  40100. if (this.needsDecode) {
  40101. this.decodeBuffer(comps);
  40102. }
  40103. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  40104. drawWidth, drawHeight, actualHeight, bpc, comps,
  40105. alpha01);
  40106. if (maybeUndoPreblend) {
  40107. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  40108. }
  40109. return imgData;
  40110. },
  40111. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  40112. var numComps = this.numComps;
  40113. if (numComps !== 1) {
  40114. error('Reading gray scale from a color image: ' + numComps);
  40115. }
  40116. var width = this.width;
  40117. var height = this.height;
  40118. var bpc = this.bpc;
  40119. // rows start at byte boundary
  40120. var rowBytes = (width * numComps * bpc + 7) >> 3;
  40121. var imgArray = this.getImageBytes(height * rowBytes);
  40122. var comps = this.getComponents(imgArray);
  40123. var i, length;
  40124. if (bpc === 1) {
  40125. // inline decoding (= inversion) for 1 bpc images
  40126. length = width * height;
  40127. if (this.needsDecode) {
  40128. // invert and scale to {0, 255}
  40129. for (i = 0; i < length; ++i) {
  40130. buffer[i] = (comps[i] - 1) & 255;
  40131. }
  40132. } else {
  40133. // scale to {0, 255}
  40134. for (i = 0; i < length; ++i) {
  40135. buffer[i] = (-comps[i]) & 255;
  40136. }
  40137. }
  40138. return;
  40139. }
  40140. if (this.needsDecode) {
  40141. this.decodeBuffer(comps);
  40142. }
  40143. length = width * height;
  40144. // we aren't using a colorspace so we need to scale the value
  40145. var scale = 255 / ((1 << bpc) - 1);
  40146. for (i = 0; i < length; ++i) {
  40147. buffer[i] = (scale * comps[i]) | 0;
  40148. }
  40149. },
  40150. getImageBytes: function PDFImage_getImageBytes(length,
  40151. drawWidth, drawHeight,
  40152. forceRGB) {
  40153. this.image.reset();
  40154. this.image.drawWidth = drawWidth || this.width;
  40155. this.image.drawHeight = drawHeight || this.height;
  40156. this.image.forceRGB = !!forceRGB;
  40157. return this.image.getBytes(length);
  40158. }
  40159. };
  40160. return PDFImage;
  40161. })();
  40162. exports.PDFImage = PDFImage;
  40163. }));
  40164. (function (root, factory) {
  40165. {
  40166. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  40167. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  40168. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  40169. }
  40170. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  40171. coreChunkedStream, coreColorSpace) {
  40172. var InvalidPDFException = sharedUtil.InvalidPDFException;
  40173. var MissingDataException = sharedUtil.MissingDataException;
  40174. var XRefParseException = sharedUtil.XRefParseException;
  40175. var assert = sharedUtil.assert;
  40176. var bytesToString = sharedUtil.bytesToString;
  40177. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40178. var error = sharedUtil.error;
  40179. var info = sharedUtil.info;
  40180. var isArray = sharedUtil.isArray;
  40181. var isInt = sharedUtil.isInt;
  40182. var isString = sharedUtil.isString;
  40183. var shadow = sharedUtil.shadow;
  40184. var stringToPDFString = sharedUtil.stringToPDFString;
  40185. var stringToUTF8String = sharedUtil.stringToUTF8String;
  40186. var warn = sharedUtil.warn;
  40187. var isValidUrl = sharedUtil.isValidUrl;
  40188. var Util = sharedUtil.Util;
  40189. var Ref = corePrimitives.Ref;
  40190. var RefSet = corePrimitives.RefSet;
  40191. var RefSetCache = corePrimitives.RefSetCache;
  40192. var isName = corePrimitives.isName;
  40193. var isCmd = corePrimitives.isCmd;
  40194. var isDict = corePrimitives.isDict;
  40195. var isRef = corePrimitives.isRef;
  40196. var isRefsEqual = corePrimitives.isRefsEqual;
  40197. var isStream = corePrimitives.isStream;
  40198. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  40199. var Lexer = coreParser.Lexer;
  40200. var Parser = coreParser.Parser;
  40201. var ChunkedStream = coreChunkedStream.ChunkedStream;
  40202. var ColorSpace = coreColorSpace.ColorSpace;
  40203. var Catalog = (function CatalogClosure() {
  40204. function Catalog(pdfManager, xref, pageFactory) {
  40205. this.pdfManager = pdfManager;
  40206. this.xref = xref;
  40207. this.catDict = xref.getCatalogObj();
  40208. this.fontCache = new RefSetCache();
  40209. assert(isDict(this.catDict),
  40210. 'catalog object is not a dictionary');
  40211. // TODO refactor to move getPage() to the PDFDocument.
  40212. this.pageFactory = pageFactory;
  40213. this.pagePromises = [];
  40214. }
  40215. Catalog.prototype = {
  40216. get metadata() {
  40217. var streamRef = this.catDict.getRaw('Metadata');
  40218. if (!isRef(streamRef)) {
  40219. return shadow(this, 'metadata', null);
  40220. }
  40221. var encryptMetadata = (!this.xref.encrypt ? false :
  40222. this.xref.encrypt.encryptMetadata);
  40223. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  40224. var metadata;
  40225. if (stream && isDict(stream.dict)) {
  40226. var type = stream.dict.get('Type');
  40227. var subtype = stream.dict.get('Subtype');
  40228. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  40229. // XXX: This should examine the charset the XML document defines,
  40230. // however since there are currently no real means to decode
  40231. // arbitrary charsets, let's just hope that the author of the PDF
  40232. // was reasonable enough to stick with the XML default charset,
  40233. // which is UTF-8.
  40234. try {
  40235. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  40236. } catch (e) {
  40237. info('Skipping invalid metadata.');
  40238. }
  40239. }
  40240. }
  40241. return shadow(this, 'metadata', metadata);
  40242. },
  40243. get toplevelPagesDict() {
  40244. var pagesObj = this.catDict.get('Pages');
  40245. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  40246. // shadow the prototype getter
  40247. return shadow(this, 'toplevelPagesDict', pagesObj);
  40248. },
  40249. get documentOutline() {
  40250. var obj = null;
  40251. try {
  40252. obj = this.readDocumentOutline();
  40253. } catch (ex) {
  40254. if (ex instanceof MissingDataException) {
  40255. throw ex;
  40256. }
  40257. warn('Unable to read document outline');
  40258. }
  40259. return shadow(this, 'documentOutline', obj);
  40260. },
  40261. readDocumentOutline: function Catalog_readDocumentOutline() {
  40262. var obj = this.catDict.get('Outlines');
  40263. if (!isDict(obj)) {
  40264. return null;
  40265. }
  40266. obj = obj.getRaw('First');
  40267. if (!isRef(obj)) {
  40268. return null;
  40269. }
  40270. var root = { items: [] };
  40271. var queue = [{obj: obj, parent: root}];
  40272. // To avoid recursion, keep track of the already processed items.
  40273. var processed = new RefSet();
  40274. processed.put(obj);
  40275. var xref = this.xref, blackColor = new Uint8Array(3);
  40276. while (queue.length > 0) {
  40277. var i = queue.shift();
  40278. var outlineDict = xref.fetchIfRef(i.obj);
  40279. if (outlineDict === null) {
  40280. continue;
  40281. }
  40282. assert(outlineDict.has('Title'), 'Invalid outline item');
  40283. var actionDict = outlineDict.get('A'), dest = null, url = null;
  40284. if (actionDict) {
  40285. var destEntry = actionDict.get('D');
  40286. if (destEntry) {
  40287. dest = destEntry;
  40288. } else {
  40289. var uriEntry = actionDict.get('URI');
  40290. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  40291. url = uriEntry;
  40292. }
  40293. }
  40294. } else if (outlineDict.has('Dest')) {
  40295. dest = outlineDict.getRaw('Dest');
  40296. if (isName(dest)) {
  40297. dest = dest.name;
  40298. }
  40299. }
  40300. var title = outlineDict.get('Title');
  40301. var flags = outlineDict.get('F') || 0;
  40302. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  40303. // We only need to parse the color when it's valid, and non-default.
  40304. if (isArray(color) && color.length === 3 &&
  40305. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  40306. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  40307. }
  40308. var outlineItem = {
  40309. dest: dest,
  40310. url: url,
  40311. title: stringToPDFString(title),
  40312. color: rgbColor,
  40313. count: outlineDict.get('Count'),
  40314. bold: !!(flags & 2),
  40315. italic: !!(flags & 1),
  40316. items: []
  40317. };
  40318. i.parent.items.push(outlineItem);
  40319. obj = outlineDict.getRaw('First');
  40320. if (isRef(obj) && !processed.has(obj)) {
  40321. queue.push({obj: obj, parent: outlineItem});
  40322. processed.put(obj);
  40323. }
  40324. obj = outlineDict.getRaw('Next');
  40325. if (isRef(obj) && !processed.has(obj)) {
  40326. queue.push({obj: obj, parent: i.parent});
  40327. processed.put(obj);
  40328. }
  40329. }
  40330. return (root.items.length > 0 ? root.items : null);
  40331. },
  40332. get numPages() {
  40333. var obj = this.toplevelPagesDict.get('Count');
  40334. assert(
  40335. isInt(obj),
  40336. 'page count in top level pages object is not an integer'
  40337. );
  40338. // shadow the prototype getter
  40339. return shadow(this, 'num', obj);
  40340. },
  40341. get destinations() {
  40342. function fetchDestination(dest) {
  40343. return isDict(dest) ? dest.get('D') : dest;
  40344. }
  40345. var xref = this.xref;
  40346. var dests = {}, nameTreeRef, nameDictionaryRef;
  40347. var obj = this.catDict.get('Names');
  40348. if (obj && obj.has('Dests')) {
  40349. nameTreeRef = obj.getRaw('Dests');
  40350. } else if (this.catDict.has('Dests')) {
  40351. nameDictionaryRef = this.catDict.get('Dests');
  40352. }
  40353. if (nameDictionaryRef) {
  40354. // reading simple destination dictionary
  40355. obj = nameDictionaryRef;
  40356. obj.forEach(function catalogForEach(key, value) {
  40357. if (!value) {
  40358. return;
  40359. }
  40360. dests[key] = fetchDestination(value);
  40361. });
  40362. }
  40363. if (nameTreeRef) {
  40364. var nameTree = new NameTree(nameTreeRef, xref);
  40365. var names = nameTree.getAll();
  40366. for (var name in names) {
  40367. dests[name] = fetchDestination(names[name]);
  40368. }
  40369. }
  40370. return shadow(this, 'destinations', dests);
  40371. },
  40372. getDestination: function Catalog_getDestination(destinationId) {
  40373. function fetchDestination(dest) {
  40374. return isDict(dest) ? dest.get('D') : dest;
  40375. }
  40376. var xref = this.xref;
  40377. var dest = null, nameTreeRef, nameDictionaryRef;
  40378. var obj = this.catDict.get('Names');
  40379. if (obj && obj.has('Dests')) {
  40380. nameTreeRef = obj.getRaw('Dests');
  40381. } else if (this.catDict.has('Dests')) {
  40382. nameDictionaryRef = this.catDict.get('Dests');
  40383. }
  40384. if (nameDictionaryRef) { // Simple destination dictionary.
  40385. var value = nameDictionaryRef.get(destinationId);
  40386. if (value) {
  40387. dest = fetchDestination(value);
  40388. }
  40389. }
  40390. if (nameTreeRef) {
  40391. var nameTree = new NameTree(nameTreeRef, xref);
  40392. dest = fetchDestination(nameTree.get(destinationId));
  40393. }
  40394. return dest;
  40395. },
  40396. get pageLabels() {
  40397. var obj = null;
  40398. try {
  40399. obj = this.readPageLabels();
  40400. } catch (ex) {
  40401. if (ex instanceof MissingDataException) {
  40402. throw ex;
  40403. }
  40404. warn('Unable to read page labels.');
  40405. }
  40406. return shadow(this, 'pageLabels', obj);
  40407. },
  40408. readPageLabels: function Catalog_readPageLabels() {
  40409. var obj = this.catDict.getRaw('PageLabels');
  40410. if (!obj) {
  40411. return null;
  40412. }
  40413. var pageLabels = new Array(this.numPages);
  40414. var style = null;
  40415. var prefix = '';
  40416. var start = 1;
  40417. var numberTree = new NumberTree(obj, this.xref);
  40418. var nums = numberTree.getAll();
  40419. var currentLabel = '', currentIndex = 1;
  40420. for (var i = 0, ii = this.numPages; i < ii; i++) {
  40421. if (i in nums) {
  40422. var labelDict = nums[i];
  40423. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  40424. var type = labelDict.get('Type');
  40425. assert(!type || isName(type, 'PageLabel'),
  40426. 'Invalid type in PageLabel dictionary.');
  40427. var s = labelDict.get('S');
  40428. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  40429. style = (s ? s.name : null);
  40430. prefix = labelDict.get('P') || '';
  40431. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  40432. start = labelDict.get('St') || 1;
  40433. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  40434. currentIndex = start;
  40435. }
  40436. switch (style) {
  40437. case 'D':
  40438. currentLabel = currentIndex;
  40439. break;
  40440. case 'R':
  40441. case 'r':
  40442. currentLabel = Util.toRoman(currentIndex, style === 'r');
  40443. break;
  40444. case 'A':
  40445. case 'a':
  40446. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  40447. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  40448. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  40449. var letterIndex = currentIndex - 1;
  40450. var character = String.fromCharCode(baseCharCode +
  40451. (letterIndex % LIMIT));
  40452. var charBuf = [];
  40453. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  40454. charBuf.push(character);
  40455. }
  40456. currentLabel = charBuf.join('');
  40457. break;
  40458. default:
  40459. assert(!style,
  40460. 'Invalid style "' + style + '" in PageLabel dictionary.');
  40461. }
  40462. pageLabels[i] = prefix + currentLabel;
  40463. currentLabel = '';
  40464. currentIndex++;
  40465. }
  40466. return pageLabels;
  40467. },
  40468. get attachments() {
  40469. var xref = this.xref;
  40470. var attachments = null, nameTreeRef;
  40471. var obj = this.catDict.get('Names');
  40472. if (obj) {
  40473. nameTreeRef = obj.getRaw('EmbeddedFiles');
  40474. }
  40475. if (nameTreeRef) {
  40476. var nameTree = new NameTree(nameTreeRef, xref);
  40477. var names = nameTree.getAll();
  40478. for (var name in names) {
  40479. var fs = new FileSpec(names[name], xref);
  40480. if (!attachments) {
  40481. attachments = Object.create(null);
  40482. }
  40483. attachments[stringToPDFString(name)] = fs.serializable;
  40484. }
  40485. }
  40486. return shadow(this, 'attachments', attachments);
  40487. },
  40488. get javaScript() {
  40489. var xref = this.xref;
  40490. var obj = this.catDict.get('Names');
  40491. var javaScript = [];
  40492. function appendIfJavaScriptDict(jsDict) {
  40493. var type = jsDict.get('S');
  40494. if (!isName(type, 'JavaScript')) {
  40495. return;
  40496. }
  40497. var js = jsDict.get('JS');
  40498. if (isStream(js)) {
  40499. js = bytesToString(js.getBytes());
  40500. } else if (!isString(js)) {
  40501. return;
  40502. }
  40503. javaScript.push(stringToPDFString(js));
  40504. }
  40505. if (obj && obj.has('JavaScript')) {
  40506. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  40507. var names = nameTree.getAll();
  40508. for (var name in names) {
  40509. // We don't really use the JavaScript right now. This code is
  40510. // defensive so we don't cause errors on document load.
  40511. var jsDict = names[name];
  40512. if (isDict(jsDict)) {
  40513. appendIfJavaScriptDict(jsDict);
  40514. }
  40515. }
  40516. }
  40517. // Append OpenAction actions to javaScript array
  40518. var openactionDict = this.catDict.get('OpenAction');
  40519. if (isDict(openactionDict, 'Action')) {
  40520. var actionType = openactionDict.get('S');
  40521. if (isName(actionType, 'Named')) {
  40522. // The named Print action is not a part of the PDF 1.7 specification,
  40523. // but is supported by many PDF readers/writers (including Adobe's).
  40524. var action = openactionDict.get('N');
  40525. if (isName(action, 'Print')) {
  40526. javaScript.push('print({});');
  40527. }
  40528. } else {
  40529. appendIfJavaScriptDict(openactionDict);
  40530. }
  40531. }
  40532. return shadow(this, 'javaScript', javaScript);
  40533. },
  40534. cleanup: function Catalog_cleanup() {
  40535. var promises = [];
  40536. this.fontCache.forEach(function (promise) {
  40537. promises.push(promise);
  40538. });
  40539. return Promise.all(promises).then(function (translatedFonts) {
  40540. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  40541. var font = translatedFonts[i].dict;
  40542. delete font.translated;
  40543. }
  40544. this.fontCache.clear();
  40545. }.bind(this));
  40546. },
  40547. getPage: function Catalog_getPage(pageIndex) {
  40548. if (!(pageIndex in this.pagePromises)) {
  40549. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  40550. function (a) {
  40551. var dict = a[0];
  40552. var ref = a[1];
  40553. return this.pageFactory.createPage(pageIndex, dict, ref,
  40554. this.fontCache);
  40555. }.bind(this)
  40556. );
  40557. }
  40558. return this.pagePromises[pageIndex];
  40559. },
  40560. getPageDict: function Catalog_getPageDict(pageIndex) {
  40561. var capability = createPromiseCapability();
  40562. var nodesToVisit = [this.catDict.getRaw('Pages')];
  40563. var currentPageIndex = 0;
  40564. var xref = this.xref;
  40565. var checkAllKids = false;
  40566. function next() {
  40567. while (nodesToVisit.length) {
  40568. var currentNode = nodesToVisit.pop();
  40569. if (isRef(currentNode)) {
  40570. xref.fetchAsync(currentNode).then(function (obj) {
  40571. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  40572. if (pageIndex === currentPageIndex) {
  40573. capability.resolve([obj, currentNode]);
  40574. } else {
  40575. currentPageIndex++;
  40576. next();
  40577. }
  40578. return;
  40579. }
  40580. nodesToVisit.push(obj);
  40581. next();
  40582. }, capability.reject);
  40583. return;
  40584. }
  40585. // Must be a child page dictionary.
  40586. assert(
  40587. isDict(currentNode),
  40588. 'page dictionary kid reference points to wrong type of object'
  40589. );
  40590. var count = currentNode.get('Count');
  40591. // If the current node doesn't have any children, avoid getting stuck
  40592. // in an empty node further down in the tree (see issue5644.pdf).
  40593. if (count === 0) {
  40594. checkAllKids = true;
  40595. }
  40596. // Skip nodes where the page can't be.
  40597. if (currentPageIndex + count <= pageIndex) {
  40598. currentPageIndex += count;
  40599. continue;
  40600. }
  40601. var kids = currentNode.get('Kids');
  40602. assert(isArray(kids), 'page dictionary kids object is not an array');
  40603. if (!checkAllKids && count === kids.length) {
  40604. // Nodes that don't have the page have been skipped and this is the
  40605. // bottom of the tree which means the page requested must be a
  40606. // descendant of this pages node. Ideally we would just resolve the
  40607. // promise with the page ref here, but there is the case where more
  40608. // pages nodes could link to single a page (see issue 3666 pdf). To
  40609. // handle this push it back on the queue so if it is a pages node it
  40610. // will be descended into.
  40611. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  40612. currentPageIndex = pageIndex;
  40613. continue;
  40614. } else {
  40615. for (var last = kids.length - 1; last >= 0; last--) {
  40616. nodesToVisit.push(kids[last]);
  40617. }
  40618. }
  40619. }
  40620. capability.reject('Page index ' + pageIndex + ' not found.');
  40621. }
  40622. next();
  40623. return capability.promise;
  40624. },
  40625. getPageIndex: function Catalog_getPageIndex(pageRef) {
  40626. // The page tree nodes have the count of all the leaves below them. To get
  40627. // how many pages are before we just have to walk up the tree and keep
  40628. // adding the count of siblings to the left of the node.
  40629. var xref = this.xref;
  40630. function pagesBeforeRef(kidRef) {
  40631. var total = 0;
  40632. var parentRef;
  40633. return xref.fetchAsync(kidRef).then(function (node) {
  40634. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  40635. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  40636. throw new Error('The reference does not point to a /Page Dict.');
  40637. }
  40638. if (!node) {
  40639. return null;
  40640. }
  40641. assert(isDict(node), 'node must be a Dict.');
  40642. parentRef = node.getRaw('Parent');
  40643. return node.getAsync('Parent');
  40644. }).then(function (parent) {
  40645. if (!parent) {
  40646. return null;
  40647. }
  40648. assert(isDict(parent), 'parent must be a Dict.');
  40649. return parent.getAsync('Kids');
  40650. }).then(function (kids) {
  40651. if (!kids) {
  40652. return null;
  40653. }
  40654. var kidPromises = [];
  40655. var found = false;
  40656. for (var i = 0; i < kids.length; i++) {
  40657. var kid = kids[i];
  40658. assert(isRef(kid), 'kid must be a Ref.');
  40659. if (kid.num === kidRef.num) {
  40660. found = true;
  40661. break;
  40662. }
  40663. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  40664. if (kid.has('Count')) {
  40665. var count = kid.get('Count');
  40666. total += count;
  40667. } else { // page leaf node
  40668. total++;
  40669. }
  40670. }));
  40671. }
  40672. if (!found) {
  40673. error('kid ref not found in parents kids');
  40674. }
  40675. return Promise.all(kidPromises).then(function () {
  40676. return [total, parentRef];
  40677. });
  40678. });
  40679. }
  40680. var total = 0;
  40681. function next(ref) {
  40682. return pagesBeforeRef(ref).then(function (args) {
  40683. if (!args) {
  40684. return total;
  40685. }
  40686. var count = args[0];
  40687. var parentRef = args[1];
  40688. total += count;
  40689. return next(parentRef);
  40690. });
  40691. }
  40692. return next(pageRef);
  40693. }
  40694. };
  40695. return Catalog;
  40696. })();
  40697. var XRef = (function XRefClosure() {
  40698. function XRef(stream, password) {
  40699. this.stream = stream;
  40700. this.entries = [];
  40701. this.xrefstms = Object.create(null);
  40702. // prepare the XRef cache
  40703. this.cache = [];
  40704. this.password = password;
  40705. this.stats = {
  40706. streamTypes: [],
  40707. fontTypes: []
  40708. };
  40709. }
  40710. XRef.prototype = {
  40711. setStartXRef: function XRef_setStartXRef(startXRef) {
  40712. // Store the starting positions of xref tables as we process them
  40713. // so we can recover from missing data errors
  40714. this.startXRefQueue = [startXRef];
  40715. },
  40716. parse: function XRef_parse(recoveryMode) {
  40717. var trailerDict;
  40718. if (!recoveryMode) {
  40719. trailerDict = this.readXRef();
  40720. } else {
  40721. warn('Indexing all PDF objects');
  40722. trailerDict = this.indexObjects();
  40723. }
  40724. trailerDict.assignXref(this);
  40725. this.trailer = trailerDict;
  40726. var encrypt = trailerDict.get('Encrypt');
  40727. if (encrypt) {
  40728. var ids = trailerDict.get('ID');
  40729. var fileId = (ids && ids.length) ? ids[0] : '';
  40730. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  40731. this.password);
  40732. }
  40733. // get the root dictionary (catalog) object
  40734. if (!(this.root = trailerDict.get('Root'))) {
  40735. error('Invalid root reference');
  40736. }
  40737. },
  40738. processXRefTable: function XRef_processXRefTable(parser) {
  40739. if (!('tableState' in this)) {
  40740. // Stores state of the table as we process it so we can resume
  40741. // from middle of table in case of missing data error
  40742. this.tableState = {
  40743. entryNum: 0,
  40744. streamPos: parser.lexer.stream.pos,
  40745. parserBuf1: parser.buf1,
  40746. parserBuf2: parser.buf2
  40747. };
  40748. }
  40749. var obj = this.readXRefTable(parser);
  40750. // Sanity check
  40751. if (!isCmd(obj, 'trailer')) {
  40752. error('Invalid XRef table: could not find trailer dictionary');
  40753. }
  40754. // Read trailer dictionary, e.g.
  40755. // trailer
  40756. // << /Size 22
  40757. // /Root 20R
  40758. // /Info 10R
  40759. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  40760. // >>
  40761. // The parser goes through the entire stream << ... >> and provides
  40762. // a getter interface for the key-value table
  40763. var dict = parser.getObj();
  40764. // The pdflib PDF generator can generate a nested trailer dictionary
  40765. if (!isDict(dict) && dict.dict) {
  40766. dict = dict.dict;
  40767. }
  40768. if (!isDict(dict)) {
  40769. error('Invalid XRef table: could not parse trailer dictionary');
  40770. }
  40771. delete this.tableState;
  40772. return dict;
  40773. },
  40774. readXRefTable: function XRef_readXRefTable(parser) {
  40775. // Example of cross-reference table:
  40776. // xref
  40777. // 0 1 <-- subsection header (first obj #, obj count)
  40778. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  40779. // 23 2 <-- subsection header ... and so on ...
  40780. // 0000025518 00002 n
  40781. // 0000025635 00000 n
  40782. // trailer
  40783. // ...
  40784. var stream = parser.lexer.stream;
  40785. var tableState = this.tableState;
  40786. stream.pos = tableState.streamPos;
  40787. parser.buf1 = tableState.parserBuf1;
  40788. parser.buf2 = tableState.parserBuf2;
  40789. // Outer loop is over subsection headers
  40790. var obj;
  40791. while (true) {
  40792. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  40793. if (isCmd(obj = parser.getObj(), 'trailer')) {
  40794. break;
  40795. }
  40796. tableState.firstEntryNum = obj;
  40797. tableState.entryCount = parser.getObj();
  40798. }
  40799. var first = tableState.firstEntryNum;
  40800. var count = tableState.entryCount;
  40801. if (!isInt(first) || !isInt(count)) {
  40802. error('Invalid XRef table: wrong types in subsection header');
  40803. }
  40804. // Inner loop is over objects themselves
  40805. for (var i = tableState.entryNum; i < count; i++) {
  40806. tableState.streamPos = stream.pos;
  40807. tableState.entryNum = i;
  40808. tableState.parserBuf1 = parser.buf1;
  40809. tableState.parserBuf2 = parser.buf2;
  40810. var entry = {};
  40811. entry.offset = parser.getObj();
  40812. entry.gen = parser.getObj();
  40813. var type = parser.getObj();
  40814. if (isCmd(type, 'f')) {
  40815. entry.free = true;
  40816. } else if (isCmd(type, 'n')) {
  40817. entry.uncompressed = true;
  40818. }
  40819. // Validate entry obj
  40820. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  40821. !(entry.free || entry.uncompressed)) {
  40822. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  40823. }
  40824. // The first xref table entry, i.e. obj 0, should be free. Attempting
  40825. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  40826. if (i === 0 && entry.free && first === 1) {
  40827. first = 0;
  40828. }
  40829. if (!this.entries[i + first]) {
  40830. this.entries[i + first] = entry;
  40831. }
  40832. }
  40833. tableState.entryNum = 0;
  40834. tableState.streamPos = stream.pos;
  40835. tableState.parserBuf1 = parser.buf1;
  40836. tableState.parserBuf2 = parser.buf2;
  40837. delete tableState.firstEntryNum;
  40838. delete tableState.entryCount;
  40839. }
  40840. // Sanity check: as per spec, first object must be free
  40841. if (this.entries[0] && !this.entries[0].free) {
  40842. error('Invalid XRef table: unexpected first object');
  40843. }
  40844. return obj;
  40845. },
  40846. processXRefStream: function XRef_processXRefStream(stream) {
  40847. if (!('streamState' in this)) {
  40848. // Stores state of the stream as we process it so we can resume
  40849. // from middle of stream in case of missing data error
  40850. var streamParameters = stream.dict;
  40851. var byteWidths = streamParameters.get('W');
  40852. var range = streamParameters.get('Index');
  40853. if (!range) {
  40854. range = [0, streamParameters.get('Size')];
  40855. }
  40856. this.streamState = {
  40857. entryRanges: range,
  40858. byteWidths: byteWidths,
  40859. entryNum: 0,
  40860. streamPos: stream.pos
  40861. };
  40862. }
  40863. this.readXRefStream(stream);
  40864. delete this.streamState;
  40865. return stream.dict;
  40866. },
  40867. readXRefStream: function XRef_readXRefStream(stream) {
  40868. var i, j;
  40869. var streamState = this.streamState;
  40870. stream.pos = streamState.streamPos;
  40871. var byteWidths = streamState.byteWidths;
  40872. var typeFieldWidth = byteWidths[0];
  40873. var offsetFieldWidth = byteWidths[1];
  40874. var generationFieldWidth = byteWidths[2];
  40875. var entryRanges = streamState.entryRanges;
  40876. while (entryRanges.length > 0) {
  40877. var first = entryRanges[0];
  40878. var n = entryRanges[1];
  40879. if (!isInt(first) || !isInt(n)) {
  40880. error('Invalid XRef range fields: ' + first + ', ' + n);
  40881. }
  40882. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  40883. !isInt(generationFieldWidth)) {
  40884. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  40885. }
  40886. for (i = streamState.entryNum; i < n; ++i) {
  40887. streamState.entryNum = i;
  40888. streamState.streamPos = stream.pos;
  40889. var type = 0, offset = 0, generation = 0;
  40890. for (j = 0; j < typeFieldWidth; ++j) {
  40891. type = (type << 8) | stream.getByte();
  40892. }
  40893. // if type field is absent, its default value is 1
  40894. if (typeFieldWidth === 0) {
  40895. type = 1;
  40896. }
  40897. for (j = 0; j < offsetFieldWidth; ++j) {
  40898. offset = (offset << 8) | stream.getByte();
  40899. }
  40900. for (j = 0; j < generationFieldWidth; ++j) {
  40901. generation = (generation << 8) | stream.getByte();
  40902. }
  40903. var entry = {};
  40904. entry.offset = offset;
  40905. entry.gen = generation;
  40906. switch (type) {
  40907. case 0:
  40908. entry.free = true;
  40909. break;
  40910. case 1:
  40911. entry.uncompressed = true;
  40912. break;
  40913. case 2:
  40914. break;
  40915. default:
  40916. error('Invalid XRef entry type: ' + type);
  40917. }
  40918. if (!this.entries[first + i]) {
  40919. this.entries[first + i] = entry;
  40920. }
  40921. }
  40922. streamState.entryNum = 0;
  40923. streamState.streamPos = stream.pos;
  40924. entryRanges.splice(0, 2);
  40925. }
  40926. },
  40927. indexObjects: function XRef_indexObjects() {
  40928. // Simple scan through the PDF content to find objects,
  40929. // trailers and XRef streams.
  40930. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  40931. var PERCENT = 0x25, LT = 0x3C;
  40932. function readToken(data, offset) {
  40933. var token = '', ch = data[offset];
  40934. while (ch !== LF && ch !== CR && ch !== LT) {
  40935. if (++offset >= data.length) {
  40936. break;
  40937. }
  40938. token += String.fromCharCode(ch);
  40939. ch = data[offset];
  40940. }
  40941. return token;
  40942. }
  40943. function skipUntil(data, offset, what) {
  40944. var length = what.length, dataLength = data.length;
  40945. var skipped = 0;
  40946. // finding byte sequence
  40947. while (offset < dataLength) {
  40948. var i = 0;
  40949. while (i < length && data[offset + i] === what[i]) {
  40950. ++i;
  40951. }
  40952. if (i >= length) {
  40953. break; // sequence found
  40954. }
  40955. offset++;
  40956. skipped++;
  40957. }
  40958. return skipped;
  40959. }
  40960. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  40961. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  40962. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  40963. 101, 102]);
  40964. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  40965. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  40966. // Clear out any existing entries, since they may be bogus.
  40967. this.entries.length = 0;
  40968. var stream = this.stream;
  40969. stream.pos = 0;
  40970. var buffer = stream.getBytes();
  40971. var position = stream.start, length = buffer.length;
  40972. var trailers = [], xrefStms = [];
  40973. while (position < length) {
  40974. var ch = buffer[position];
  40975. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  40976. ++position;
  40977. continue;
  40978. }
  40979. if (ch === PERCENT) { // %-comment
  40980. do {
  40981. ++position;
  40982. if (position >= length) {
  40983. break;
  40984. }
  40985. ch = buffer[position];
  40986. } while (ch !== LF && ch !== CR);
  40987. continue;
  40988. }
  40989. var token = readToken(buffer, position);
  40990. var m;
  40991. if (token.indexOf('xref') === 0 &&
  40992. (token.length === 4 || /\s/.test(token[4]))) {
  40993. position += skipUntil(buffer, position, trailerBytes);
  40994. trailers.push(position);
  40995. position += skipUntil(buffer, position, startxrefBytes);
  40996. } else if ((m = objRegExp.exec(token))) {
  40997. if (typeof this.entries[m[1]] === 'undefined') {
  40998. this.entries[m[1]] = {
  40999. offset: position - stream.start,
  41000. gen: m[2] | 0,
  41001. uncompressed: true
  41002. };
  41003. }
  41004. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  41005. var content = buffer.subarray(position, position + contentLength);
  41006. // checking XRef stream suspect
  41007. // (it shall have '/XRef' and next char is not a letter)
  41008. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  41009. if (xrefTagOffset < contentLength &&
  41010. content[xrefTagOffset + 5] < 64) {
  41011. xrefStms.push(position - stream.start);
  41012. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  41013. }
  41014. position += contentLength;
  41015. } else if (token.indexOf('trailer') === 0 &&
  41016. (token.length === 7 || /\s/.test(token[7]))) {
  41017. trailers.push(position);
  41018. position += skipUntil(buffer, position, startxrefBytes);
  41019. } else {
  41020. position += token.length + 1;
  41021. }
  41022. }
  41023. // reading XRef streams
  41024. var i, ii;
  41025. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  41026. this.startXRefQueue.push(xrefStms[i]);
  41027. this.readXRef(/* recoveryMode */ true);
  41028. }
  41029. // finding main trailer
  41030. var dict;
  41031. for (i = 0, ii = trailers.length; i < ii; ++i) {
  41032. stream.pos = trailers[i];
  41033. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  41034. /* xref = */ this, /* recoveryMode = */ true);
  41035. var obj = parser.getObj();
  41036. if (!isCmd(obj, 'trailer')) {
  41037. continue;
  41038. }
  41039. // read the trailer dictionary
  41040. dict = parser.getObj();
  41041. if (!isDict(dict)) {
  41042. continue;
  41043. }
  41044. // taking the first one with 'ID'
  41045. if (dict.has('ID')) {
  41046. return dict;
  41047. }
  41048. }
  41049. // no tailer with 'ID', taking last one (if exists)
  41050. if (dict) {
  41051. return dict;
  41052. }
  41053. // nothing helps
  41054. // calling error() would reject worker with an UnknownErrorException.
  41055. throw new InvalidPDFException('Invalid PDF structure');
  41056. },
  41057. readXRef: function XRef_readXRef(recoveryMode) {
  41058. var stream = this.stream;
  41059. try {
  41060. while (this.startXRefQueue.length) {
  41061. var startXRef = this.startXRefQueue[0];
  41062. stream.pos = startXRef + stream.start;
  41063. var parser = new Parser(new Lexer(stream), true, this);
  41064. var obj = parser.getObj();
  41065. var dict;
  41066. // Get dictionary
  41067. if (isCmd(obj, 'xref')) {
  41068. // Parse end-of-file XRef
  41069. dict = this.processXRefTable(parser);
  41070. if (!this.topDict) {
  41071. this.topDict = dict;
  41072. }
  41073. // Recursively get other XRefs 'XRefStm', if any
  41074. obj = dict.get('XRefStm');
  41075. if (isInt(obj)) {
  41076. var pos = obj;
  41077. // ignore previously loaded xref streams
  41078. // (possible infinite recursion)
  41079. if (!(pos in this.xrefstms)) {
  41080. this.xrefstms[pos] = 1;
  41081. this.startXRefQueue.push(pos);
  41082. }
  41083. }
  41084. } else if (isInt(obj)) {
  41085. // Parse in-stream XRef
  41086. if (!isInt(parser.getObj()) ||
  41087. !isCmd(parser.getObj(), 'obj') ||
  41088. !isStream(obj = parser.getObj())) {
  41089. error('Invalid XRef stream');
  41090. }
  41091. dict = this.processXRefStream(obj);
  41092. if (!this.topDict) {
  41093. this.topDict = dict;
  41094. }
  41095. if (!dict) {
  41096. error('Failed to read XRef stream');
  41097. }
  41098. } else {
  41099. error('Invalid XRef stream header');
  41100. }
  41101. // Recursively get previous dictionary, if any
  41102. obj = dict.get('Prev');
  41103. if (isInt(obj)) {
  41104. this.startXRefQueue.push(obj);
  41105. } else if (isRef(obj)) {
  41106. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  41107. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  41108. this.startXRefQueue.push(obj.num);
  41109. }
  41110. this.startXRefQueue.shift();
  41111. }
  41112. return this.topDict;
  41113. } catch (e) {
  41114. if (e instanceof MissingDataException) {
  41115. throw e;
  41116. }
  41117. info('(while reading XRef): ' + e);
  41118. }
  41119. if (recoveryMode) {
  41120. return;
  41121. }
  41122. throw new XRefParseException();
  41123. },
  41124. getEntry: function XRef_getEntry(i) {
  41125. var xrefEntry = this.entries[i];
  41126. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  41127. return xrefEntry;
  41128. }
  41129. return null;
  41130. },
  41131. fetchIfRef: function XRef_fetchIfRef(obj) {
  41132. if (!isRef(obj)) {
  41133. return obj;
  41134. }
  41135. return this.fetch(obj);
  41136. },
  41137. fetch: function XRef_fetch(ref, suppressEncryption) {
  41138. assert(isRef(ref), 'ref object is not a reference');
  41139. var num = ref.num;
  41140. if (num in this.cache) {
  41141. var cacheEntry = this.cache[num];
  41142. return cacheEntry;
  41143. }
  41144. var xrefEntry = this.getEntry(num);
  41145. // the referenced entry can be free
  41146. if (xrefEntry === null) {
  41147. return (this.cache[num] = null);
  41148. }
  41149. if (xrefEntry.uncompressed) {
  41150. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  41151. } else {
  41152. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  41153. }
  41154. if (isDict(xrefEntry)){
  41155. xrefEntry.objId = ref.toString();
  41156. } else if (isStream(xrefEntry)) {
  41157. xrefEntry.dict.objId = ref.toString();
  41158. }
  41159. return xrefEntry;
  41160. },
  41161. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  41162. suppressEncryption) {
  41163. var gen = ref.gen;
  41164. var num = ref.num;
  41165. if (xrefEntry.gen !== gen) {
  41166. error('inconsistent generation in XRef');
  41167. }
  41168. var stream = this.stream.makeSubStream(xrefEntry.offset +
  41169. this.stream.start);
  41170. var parser = new Parser(new Lexer(stream), true, this);
  41171. var obj1 = parser.getObj();
  41172. var obj2 = parser.getObj();
  41173. var obj3 = parser.getObj();
  41174. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  41175. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  41176. !isCmd(obj3)) {
  41177. error('bad XRef entry');
  41178. }
  41179. if (!isCmd(obj3, 'obj')) {
  41180. // some bad PDFs use "obj1234" and really mean 1234
  41181. if (obj3.cmd.indexOf('obj') === 0) {
  41182. num = parseInt(obj3.cmd.substring(3), 10);
  41183. if (!isNaN(num)) {
  41184. return num;
  41185. }
  41186. }
  41187. error('bad XRef entry');
  41188. }
  41189. if (this.encrypt && !suppressEncryption) {
  41190. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  41191. } else {
  41192. xrefEntry = parser.getObj();
  41193. }
  41194. if (!isStream(xrefEntry)) {
  41195. this.cache[num] = xrefEntry;
  41196. }
  41197. return xrefEntry;
  41198. },
  41199. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  41200. suppressEncryption) {
  41201. var tableOffset = xrefEntry.offset;
  41202. var stream = this.fetch(new Ref(tableOffset, 0));
  41203. if (!isStream(stream)) {
  41204. error('bad ObjStm stream');
  41205. }
  41206. var first = stream.dict.get('First');
  41207. var n = stream.dict.get('N');
  41208. if (!isInt(first) || !isInt(n)) {
  41209. error('invalid first and n parameters for ObjStm stream');
  41210. }
  41211. var parser = new Parser(new Lexer(stream), false, this);
  41212. parser.allowStreams = true;
  41213. var i, entries = [], num, nums = [];
  41214. // read the object numbers to populate cache
  41215. for (i = 0; i < n; ++i) {
  41216. num = parser.getObj();
  41217. if (!isInt(num)) {
  41218. error('invalid object number in the ObjStm stream: ' + num);
  41219. }
  41220. nums.push(num);
  41221. var offset = parser.getObj();
  41222. if (!isInt(offset)) {
  41223. error('invalid object offset in the ObjStm stream: ' + offset);
  41224. }
  41225. }
  41226. // read stream objects for cache
  41227. for (i = 0; i < n; ++i) {
  41228. entries.push(parser.getObj());
  41229. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  41230. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  41231. if (isCmd(parser.buf1, 'endobj')) {
  41232. parser.shift();
  41233. }
  41234. num = nums[i];
  41235. var entry = this.entries[num];
  41236. if (entry && entry.offset === tableOffset && entry.gen === i) {
  41237. this.cache[num] = entries[i];
  41238. }
  41239. }
  41240. xrefEntry = entries[xrefEntry.gen];
  41241. if (xrefEntry === undefined) {
  41242. error('bad XRef entry for compressed object');
  41243. }
  41244. return xrefEntry;
  41245. },
  41246. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  41247. if (!isRef(obj)) {
  41248. return Promise.resolve(obj);
  41249. }
  41250. return this.fetchAsync(obj);
  41251. },
  41252. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  41253. var streamManager = this.stream.manager;
  41254. var xref = this;
  41255. return new Promise(function tryFetch(resolve, reject) {
  41256. try {
  41257. resolve(xref.fetch(ref, suppressEncryption));
  41258. } catch (e) {
  41259. if (e instanceof MissingDataException) {
  41260. streamManager.requestRange(e.begin, e.end).then(function () {
  41261. tryFetch(resolve, reject);
  41262. }, reject);
  41263. return;
  41264. }
  41265. reject(e);
  41266. }
  41267. });
  41268. },
  41269. getCatalogObj: function XRef_getCatalogObj() {
  41270. return this.root;
  41271. }
  41272. };
  41273. return XRef;
  41274. })();
  41275. /**
  41276. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  41277. * see the specification (7.9.6 and 7.9.7) for additional details.
  41278. * TODO: implement all the Dict functions and make this more efficient.
  41279. */
  41280. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  41281. function NameOrNumberTree(root, xref) {
  41282. throw new Error('Cannot initialize NameOrNumberTree.');
  41283. }
  41284. NameOrNumberTree.prototype = {
  41285. getAll: function NameOrNumberTree_getAll() {
  41286. var dict = Object.create(null);
  41287. if (!this.root) {
  41288. return dict;
  41289. }
  41290. var xref = this.xref;
  41291. // Reading Name/Number tree.
  41292. var processed = new RefSet();
  41293. processed.put(this.root);
  41294. var queue = [this.root];
  41295. while (queue.length > 0) {
  41296. var i, n;
  41297. var obj = xref.fetchIfRef(queue.shift());
  41298. if (!isDict(obj)) {
  41299. continue;
  41300. }
  41301. if (obj.has('Kids')) {
  41302. var kids = obj.get('Kids');
  41303. for (i = 0, n = kids.length; i < n; i++) {
  41304. var kid = kids[i];
  41305. assert(!processed.has(kid),
  41306. 'Duplicate entry in "' + this._type + '" tree.');
  41307. queue.push(kid);
  41308. processed.put(kid);
  41309. }
  41310. continue;
  41311. }
  41312. var entries = obj.get(this._type);
  41313. if (isArray(entries)) {
  41314. for (i = 0, n = entries.length; i < n; i += 2) {
  41315. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  41316. }
  41317. }
  41318. }
  41319. return dict;
  41320. },
  41321. get: function NameOrNumberTree_get(key) {
  41322. if (!this.root) {
  41323. return null;
  41324. }
  41325. var xref = this.xref;
  41326. var kidsOrEntries = xref.fetchIfRef(this.root);
  41327. var loopCount = 0;
  41328. var MAX_LEVELS = 10;
  41329. var l, r, m;
  41330. // Perform a binary search to quickly find the entry that
  41331. // contains the key we are looking for.
  41332. while (kidsOrEntries.has('Kids')) {
  41333. if (++loopCount > MAX_LEVELS) {
  41334. warn('Search depth limit reached for "' + this._type + '" tree.');
  41335. return null;
  41336. }
  41337. var kids = kidsOrEntries.get('Kids');
  41338. if (!isArray(kids)) {
  41339. return null;
  41340. }
  41341. l = 0;
  41342. r = kids.length - 1;
  41343. while (l <= r) {
  41344. m = (l + r) >> 1;
  41345. var kid = xref.fetchIfRef(kids[m]);
  41346. var limits = kid.get('Limits');
  41347. if (key < xref.fetchIfRef(limits[0])) {
  41348. r = m - 1;
  41349. } else if (key > xref.fetchIfRef(limits[1])) {
  41350. l = m + 1;
  41351. } else {
  41352. kidsOrEntries = xref.fetchIfRef(kids[m]);
  41353. break;
  41354. }
  41355. }
  41356. if (l > r) {
  41357. return null;
  41358. }
  41359. }
  41360. // If we get here, then we have found the right entry. Now go through the
  41361. // entries in the dictionary until we find the key we're looking for.
  41362. var entries = kidsOrEntries.get(this._type);
  41363. if (isArray(entries)) {
  41364. // Perform a binary search to reduce the lookup time.
  41365. l = 0;
  41366. r = entries.length - 2;
  41367. while (l <= r) {
  41368. // Check only even indices (0, 2, 4, ...) because the
  41369. // odd indices contain the actual data.
  41370. m = (l + r) & ~1;
  41371. var currentKey = xref.fetchIfRef(entries[m]);
  41372. if (key < currentKey) {
  41373. r = m - 2;
  41374. } else if (key > currentKey) {
  41375. l = m + 2;
  41376. } else {
  41377. return xref.fetchIfRef(entries[m + 1]);
  41378. }
  41379. }
  41380. }
  41381. return null;
  41382. }
  41383. };
  41384. return NameOrNumberTree;
  41385. })();
  41386. var NameTree = (function NameTreeClosure() {
  41387. function NameTree(root, xref) {
  41388. this.root = root;
  41389. this.xref = xref;
  41390. this._type = 'Names';
  41391. }
  41392. Util.inherit(NameTree, NameOrNumberTree, {});
  41393. return NameTree;
  41394. })();
  41395. var NumberTree = (function NumberTreeClosure() {
  41396. function NumberTree(root, xref) {
  41397. this.root = root;
  41398. this.xref = xref;
  41399. this._type = 'Nums';
  41400. }
  41401. Util.inherit(NumberTree, NameOrNumberTree, {});
  41402. return NumberTree;
  41403. })();
  41404. /**
  41405. * "A PDF file can refer to the contents of another file by using a File
  41406. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  41407. * NOTE: Only embedded files are supported (as part of the attachments support)
  41408. * TODO: support the 'URL' file system (with caching if !/V), portable
  41409. * collections attributes and related files (/RF)
  41410. */
  41411. var FileSpec = (function FileSpecClosure() {
  41412. function FileSpec(root, xref) {
  41413. if (!root || !isDict(root)) {
  41414. return;
  41415. }
  41416. this.xref = xref;
  41417. this.root = root;
  41418. if (root.has('FS')) {
  41419. this.fs = root.get('FS');
  41420. }
  41421. this.description = root.has('Desc') ?
  41422. stringToPDFString(root.get('Desc')) :
  41423. '';
  41424. if (root.has('RF')) {
  41425. warn('Related file specifications are not supported');
  41426. }
  41427. this.contentAvailable = true;
  41428. if (!root.has('EF')) {
  41429. this.contentAvailable = false;
  41430. warn('Non-embedded file specifications are not supported');
  41431. }
  41432. }
  41433. function pickPlatformItem(dict) {
  41434. // Look for the filename in this order:
  41435. // UF, F, Unix, Mac, DOS
  41436. if (dict.has('UF')) {
  41437. return dict.get('UF');
  41438. } else if (dict.has('F')) {
  41439. return dict.get('F');
  41440. } else if (dict.has('Unix')) {
  41441. return dict.get('Unix');
  41442. } else if (dict.has('Mac')) {
  41443. return dict.get('Mac');
  41444. } else if (dict.has('DOS')) {
  41445. return dict.get('DOS');
  41446. } else {
  41447. return null;
  41448. }
  41449. }
  41450. FileSpec.prototype = {
  41451. get filename() {
  41452. if (!this._filename && this.root) {
  41453. var filename = pickPlatformItem(this.root) || 'unnamed';
  41454. this._filename = stringToPDFString(filename).
  41455. replace(/\\\\/g, '\\').
  41456. replace(/\\\//g, '/').
  41457. replace(/\\/g, '/');
  41458. }
  41459. return this._filename;
  41460. },
  41461. get content() {
  41462. if (!this.contentAvailable) {
  41463. return null;
  41464. }
  41465. if (!this.contentRef && this.root) {
  41466. this.contentRef = pickPlatformItem(this.root.get('EF'));
  41467. }
  41468. var content = null;
  41469. if (this.contentRef) {
  41470. var xref = this.xref;
  41471. var fileObj = xref.fetchIfRef(this.contentRef);
  41472. if (fileObj && isStream(fileObj)) {
  41473. content = fileObj.getBytes();
  41474. } else {
  41475. warn('Embedded file specification points to non-existing/invalid ' +
  41476. 'content');
  41477. }
  41478. } else {
  41479. warn('Embedded file specification does not have a content');
  41480. }
  41481. return content;
  41482. },
  41483. get serializable() {
  41484. return {
  41485. filename: this.filename,
  41486. content: this.content
  41487. };
  41488. }
  41489. };
  41490. return FileSpec;
  41491. })();
  41492. /**
  41493. * A helper for loading missing data in object graphs. It traverses the graph
  41494. * depth first and queues up any objects that have missing data. Once it has
  41495. * has traversed as many objects that are available it attempts to bundle the
  41496. * missing data requests and then resume from the nodes that weren't ready.
  41497. *
  41498. * NOTE: It provides protection from circular references by keeping track of
  41499. * of loaded references. However, you must be careful not to load any graphs
  41500. * that have references to the catalog or other pages since that will cause the
  41501. * entire PDF document object graph to be traversed.
  41502. */
  41503. var ObjectLoader = (function() {
  41504. function mayHaveChildren(value) {
  41505. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  41506. }
  41507. function addChildren(node, nodesToVisit) {
  41508. var value;
  41509. if (isDict(node) || isStream(node)) {
  41510. var map;
  41511. if (isDict(node)) {
  41512. map = node.map;
  41513. } else {
  41514. map = node.dict.map;
  41515. }
  41516. for (var key in map) {
  41517. value = map[key];
  41518. if (mayHaveChildren(value)) {
  41519. nodesToVisit.push(value);
  41520. }
  41521. }
  41522. } else if (isArray(node)) {
  41523. for (var i = 0, ii = node.length; i < ii; i++) {
  41524. value = node[i];
  41525. if (mayHaveChildren(value)) {
  41526. nodesToVisit.push(value);
  41527. }
  41528. }
  41529. }
  41530. }
  41531. function ObjectLoader(obj, keys, xref) {
  41532. this.obj = obj;
  41533. this.keys = keys;
  41534. this.xref = xref;
  41535. this.refSet = null;
  41536. this.capability = null;
  41537. }
  41538. ObjectLoader.prototype = {
  41539. load: function ObjectLoader_load() {
  41540. var keys = this.keys;
  41541. this.capability = createPromiseCapability();
  41542. // Don't walk the graph if all the data is already loaded.
  41543. if (!(this.xref.stream instanceof ChunkedStream) ||
  41544. this.xref.stream.getMissingChunks().length === 0) {
  41545. this.capability.resolve();
  41546. return this.capability.promise;
  41547. }
  41548. this.refSet = new RefSet();
  41549. // Setup the initial nodes to visit.
  41550. var nodesToVisit = [];
  41551. for (var i = 0; i < keys.length; i++) {
  41552. nodesToVisit.push(this.obj[keys[i]]);
  41553. }
  41554. this._walk(nodesToVisit);
  41555. return this.capability.promise;
  41556. },
  41557. _walk: function ObjectLoader_walk(nodesToVisit) {
  41558. var nodesToRevisit = [];
  41559. var pendingRequests = [];
  41560. // DFS walk of the object graph.
  41561. while (nodesToVisit.length) {
  41562. var currentNode = nodesToVisit.pop();
  41563. // Only references or chunked streams can cause missing data exceptions.
  41564. if (isRef(currentNode)) {
  41565. // Skip nodes that have already been visited.
  41566. if (this.refSet.has(currentNode)) {
  41567. continue;
  41568. }
  41569. try {
  41570. var ref = currentNode;
  41571. this.refSet.put(ref);
  41572. currentNode = this.xref.fetch(currentNode);
  41573. } catch (e) {
  41574. if (!(e instanceof MissingDataException)) {
  41575. throw e;
  41576. }
  41577. nodesToRevisit.push(currentNode);
  41578. pendingRequests.push({ begin: e.begin, end: e.end });
  41579. }
  41580. }
  41581. if (currentNode && currentNode.getBaseStreams) {
  41582. var baseStreams = currentNode.getBaseStreams();
  41583. var foundMissingData = false;
  41584. for (var i = 0; i < baseStreams.length; i++) {
  41585. var stream = baseStreams[i];
  41586. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  41587. foundMissingData = true;
  41588. pendingRequests.push({
  41589. begin: stream.start,
  41590. end: stream.end
  41591. });
  41592. }
  41593. }
  41594. if (foundMissingData) {
  41595. nodesToRevisit.push(currentNode);
  41596. }
  41597. }
  41598. addChildren(currentNode, nodesToVisit);
  41599. }
  41600. if (pendingRequests.length) {
  41601. this.xref.stream.manager.requestRanges(pendingRequests).then(
  41602. function pendingRequestCallback() {
  41603. nodesToVisit = nodesToRevisit;
  41604. for (var i = 0; i < nodesToRevisit.length; i++) {
  41605. var node = nodesToRevisit[i];
  41606. // Remove any reference nodes from the currrent refset so they
  41607. // aren't skipped when we revist them.
  41608. if (isRef(node)) {
  41609. this.refSet.remove(node);
  41610. }
  41611. }
  41612. this._walk(nodesToVisit);
  41613. }.bind(this), this.capability.reject);
  41614. return;
  41615. }
  41616. // Everything is loaded.
  41617. this.refSet = null;
  41618. this.capability.resolve();
  41619. }
  41620. };
  41621. return ObjectLoader;
  41622. })();
  41623. exports.Catalog = Catalog;
  41624. exports.ObjectLoader = ObjectLoader;
  41625. exports.XRef = XRef;
  41626. exports.FileSpec = FileSpec;
  41627. }));
  41628. (function (root, factory) {
  41629. {
  41630. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41631. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41632. root.pdfjsCoreColorSpace);
  41633. }
  41634. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41635. coreColorSpace) {
  41636. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41637. var MissingDataException = sharedUtil.MissingDataException;
  41638. var Util = sharedUtil.Util;
  41639. var assert = sharedUtil.assert;
  41640. var error = sharedUtil.error;
  41641. var info = sharedUtil.info;
  41642. var warn = sharedUtil.warn;
  41643. var isStream = corePrimitives.isStream;
  41644. var PDFFunction = coreFunction.PDFFunction;
  41645. var ColorSpace = coreColorSpace.ColorSpace;
  41646. var ShadingType = {
  41647. FUNCTION_BASED: 1,
  41648. AXIAL: 2,
  41649. RADIAL: 3,
  41650. FREE_FORM_MESH: 4,
  41651. LATTICE_FORM_MESH: 5,
  41652. COONS_PATCH_MESH: 6,
  41653. TENSOR_PATCH_MESH: 7
  41654. };
  41655. var Pattern = (function PatternClosure() {
  41656. // Constructor should define this.getPattern
  41657. function Pattern() {
  41658. error('should not call Pattern constructor');
  41659. }
  41660. Pattern.prototype = {
  41661. // Input: current Canvas context
  41662. // Output: the appropriate fillStyle or strokeStyle
  41663. getPattern: function Pattern_getPattern(ctx) {
  41664. error('Should not call Pattern.getStyle: ' + ctx);
  41665. }
  41666. };
  41667. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41668. res, handler) {
  41669. var dict = isStream(shading) ? shading.dict : shading;
  41670. var type = dict.get('ShadingType');
  41671. try {
  41672. switch (type) {
  41673. case ShadingType.AXIAL:
  41674. case ShadingType.RADIAL:
  41675. // Both radial and axial shadings are handled by RadialAxial shading.
  41676. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41677. case ShadingType.FREE_FORM_MESH:
  41678. case ShadingType.LATTICE_FORM_MESH:
  41679. case ShadingType.COONS_PATCH_MESH:
  41680. case ShadingType.TENSOR_PATCH_MESH:
  41681. return new Shadings.Mesh(shading, matrix, xref, res);
  41682. default:
  41683. throw new Error('Unsupported ShadingType: ' + type);
  41684. }
  41685. } catch (ex) {
  41686. if (ex instanceof MissingDataException) {
  41687. throw ex;
  41688. }
  41689. handler.send('UnsupportedFeature',
  41690. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41691. warn(ex);
  41692. return new Shadings.Dummy();
  41693. }
  41694. };
  41695. return Pattern;
  41696. })();
  41697. var Shadings = {};
  41698. // A small number to offset the first/last color stops so we can insert ones to
  41699. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41700. Shadings.SMALL_NUMBER = 1e-6;
  41701. // Radial and axial shading have very similar implementations
  41702. // If needed, the implementations can be broken into two classes
  41703. Shadings.RadialAxial = (function RadialAxialClosure() {
  41704. function RadialAxial(dict, matrix, xref, res) {
  41705. this.matrix = matrix;
  41706. this.coordsArr = dict.getArray('Coords');
  41707. this.shadingType = dict.get('ShadingType');
  41708. this.type = 'Pattern';
  41709. var cs = dict.get('ColorSpace', 'CS');
  41710. cs = ColorSpace.parse(cs, xref, res);
  41711. this.cs = cs;
  41712. var t0 = 0.0, t1 = 1.0;
  41713. if (dict.has('Domain')) {
  41714. var domainArr = dict.getArray('Domain');
  41715. t0 = domainArr[0];
  41716. t1 = domainArr[1];
  41717. }
  41718. var extendStart = false, extendEnd = false;
  41719. if (dict.has('Extend')) {
  41720. var extendArr = dict.getArray('Extend');
  41721. extendStart = extendArr[0];
  41722. extendEnd = extendArr[1];
  41723. }
  41724. if (this.shadingType === ShadingType.RADIAL &&
  41725. (!extendStart || !extendEnd)) {
  41726. // Radial gradient only currently works if either circle is fully within
  41727. // the other circle.
  41728. var x1 = this.coordsArr[0];
  41729. var y1 = this.coordsArr[1];
  41730. var r1 = this.coordsArr[2];
  41731. var x2 = this.coordsArr[3];
  41732. var y2 = this.coordsArr[4];
  41733. var r2 = this.coordsArr[5];
  41734. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  41735. if (r1 <= r2 + distance &&
  41736. r2 <= r1 + distance) {
  41737. warn('Unsupported radial gradient.');
  41738. }
  41739. }
  41740. this.extendStart = extendStart;
  41741. this.extendEnd = extendEnd;
  41742. var fnObj = dict.get('Function');
  41743. var fn = PDFFunction.parseArray(xref, fnObj);
  41744. // 10 samples seems good enough for now, but probably won't work
  41745. // if there are sharp color changes. Ideally, we would implement
  41746. // the spec faithfully and add lossless optimizations.
  41747. var diff = t1 - t0;
  41748. var step = diff / 10;
  41749. var colorStops = this.colorStops = [];
  41750. // Protect against bad domains so we don't end up in an infinte loop below.
  41751. if (t0 >= t1 || step <= 0) {
  41752. // Acrobat doesn't seem to handle these cases so we'll ignore for
  41753. // now.
  41754. info('Bad shading domain.');
  41755. return;
  41756. }
  41757. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  41758. var rgbColor;
  41759. for (var i = t0; i <= t1; i += step) {
  41760. ratio[0] = i;
  41761. fn(ratio, 0, color, 0);
  41762. rgbColor = cs.getRgb(color, 0);
  41763. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41764. colorStops.push([(i - t0) / diff, cssColor]);
  41765. }
  41766. var background = 'transparent';
  41767. if (dict.has('Background')) {
  41768. rgbColor = cs.getRgb(dict.get('Background'), 0);
  41769. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41770. }
  41771. if (!extendStart) {
  41772. // Insert a color stop at the front and offset the first real color stop
  41773. // so it doesn't conflict with the one we insert.
  41774. colorStops.unshift([0, background]);
  41775. colorStops[1][0] += Shadings.SMALL_NUMBER;
  41776. }
  41777. if (!extendEnd) {
  41778. // Same idea as above in extendStart but for the end.
  41779. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  41780. colorStops.push([1, background]);
  41781. }
  41782. this.colorStops = colorStops;
  41783. }
  41784. RadialAxial.prototype = {
  41785. getIR: function RadialAxial_getIR() {
  41786. var coordsArr = this.coordsArr;
  41787. var shadingType = this.shadingType;
  41788. var type, p0, p1, r0, r1;
  41789. if (shadingType === ShadingType.AXIAL) {
  41790. p0 = [coordsArr[0], coordsArr[1]];
  41791. p1 = [coordsArr[2], coordsArr[3]];
  41792. r0 = null;
  41793. r1 = null;
  41794. type = 'axial';
  41795. } else if (shadingType === ShadingType.RADIAL) {
  41796. p0 = [coordsArr[0], coordsArr[1]];
  41797. p1 = [coordsArr[3], coordsArr[4]];
  41798. r0 = coordsArr[2];
  41799. r1 = coordsArr[5];
  41800. type = 'radial';
  41801. } else {
  41802. error('getPattern type unknown: ' + shadingType);
  41803. }
  41804. var matrix = this.matrix;
  41805. if (matrix) {
  41806. p0 = Util.applyTransform(p0, matrix);
  41807. p1 = Util.applyTransform(p1, matrix);
  41808. if (shadingType === ShadingType.RADIAL) {
  41809. var scale = Util.singularValueDecompose2dScale(matrix);
  41810. r0 *= scale[0];
  41811. r1 *= scale[1];
  41812. }
  41813. }
  41814. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  41815. }
  41816. };
  41817. return RadialAxial;
  41818. })();
  41819. // All mesh shading. For now, they will be presented as set of the triangles
  41820. // to be drawn on the canvas and rgb color for each vertex.
  41821. Shadings.Mesh = (function MeshClosure() {
  41822. function MeshStreamReader(stream, context) {
  41823. this.stream = stream;
  41824. this.context = context;
  41825. this.buffer = 0;
  41826. this.bufferLength = 0;
  41827. var numComps = context.numComps;
  41828. this.tmpCompsBuf = new Float32Array(numComps);
  41829. var csNumComps = context.colorSpace.numComps;
  41830. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  41831. this.tmpCompsBuf;
  41832. }
  41833. MeshStreamReader.prototype = {
  41834. get hasData() {
  41835. if (this.stream.end) {
  41836. return this.stream.pos < this.stream.end;
  41837. }
  41838. if (this.bufferLength > 0) {
  41839. return true;
  41840. }
  41841. var nextByte = this.stream.getByte();
  41842. if (nextByte < 0) {
  41843. return false;
  41844. }
  41845. this.buffer = nextByte;
  41846. this.bufferLength = 8;
  41847. return true;
  41848. },
  41849. readBits: function MeshStreamReader_readBits(n) {
  41850. var buffer = this.buffer;
  41851. var bufferLength = this.bufferLength;
  41852. if (n === 32) {
  41853. if (bufferLength === 0) {
  41854. return ((this.stream.getByte() << 24) |
  41855. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  41856. this.stream.getByte()) >>> 0;
  41857. }
  41858. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  41859. (this.stream.getByte() << 8) | this.stream.getByte();
  41860. var nextByte = this.stream.getByte();
  41861. this.buffer = nextByte & ((1 << bufferLength) - 1);
  41862. return ((buffer << (8 - bufferLength)) |
  41863. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  41864. }
  41865. if (n === 8 && bufferLength === 0) {
  41866. return this.stream.getByte();
  41867. }
  41868. while (bufferLength < n) {
  41869. buffer = (buffer << 8) | this.stream.getByte();
  41870. bufferLength += 8;
  41871. }
  41872. bufferLength -= n;
  41873. this.bufferLength = bufferLength;
  41874. this.buffer = buffer & ((1 << bufferLength) - 1);
  41875. return buffer >> bufferLength;
  41876. },
  41877. align: function MeshStreamReader_align() {
  41878. this.buffer = 0;
  41879. this.bufferLength = 0;
  41880. },
  41881. readFlag: function MeshStreamReader_readFlag() {
  41882. return this.readBits(this.context.bitsPerFlag);
  41883. },
  41884. readCoordinate: function MeshStreamReader_readCoordinate() {
  41885. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  41886. var xi = this.readBits(bitsPerCoordinate);
  41887. var yi = this.readBits(bitsPerCoordinate);
  41888. var decode = this.context.decode;
  41889. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  41890. 2.3283064365386963e-10; // 2 ^ -32
  41891. return [
  41892. xi * scale * (decode[1] - decode[0]) + decode[0],
  41893. yi * scale * (decode[3] - decode[2]) + decode[2]
  41894. ];
  41895. },
  41896. readComponents: function MeshStreamReader_readComponents() {
  41897. var numComps = this.context.numComps;
  41898. var bitsPerComponent = this.context.bitsPerComponent;
  41899. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  41900. 2.3283064365386963e-10; // 2 ^ -32
  41901. var decode = this.context.decode;
  41902. var components = this.tmpCompsBuf;
  41903. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  41904. var ci = this.readBits(bitsPerComponent);
  41905. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  41906. }
  41907. var color = this.tmpCsCompsBuf;
  41908. if (this.context.colorFn) {
  41909. this.context.colorFn(components, 0, color, 0);
  41910. }
  41911. return this.context.colorSpace.getRgb(color, 0);
  41912. }
  41913. };
  41914. function decodeType4Shading(mesh, reader) {
  41915. var coords = mesh.coords;
  41916. var colors = mesh.colors;
  41917. var operators = [];
  41918. var ps = []; // not maintaining cs since that will match ps
  41919. var verticesLeft = 0; // assuming we have all data to start a new triangle
  41920. while (reader.hasData) {
  41921. var f = reader.readFlag();
  41922. var coord = reader.readCoordinate();
  41923. var color = reader.readComponents();
  41924. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  41925. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  41926. switch (f) {
  41927. case 0:
  41928. verticesLeft = 3;
  41929. break;
  41930. case 1:
  41931. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  41932. verticesLeft = 1;
  41933. break;
  41934. case 2:
  41935. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  41936. verticesLeft = 1;
  41937. break;
  41938. }
  41939. operators.push(f);
  41940. }
  41941. ps.push(coords.length);
  41942. coords.push(coord);
  41943. colors.push(color);
  41944. verticesLeft--;
  41945. reader.align();
  41946. }
  41947. mesh.figures.push({
  41948. type: 'triangles',
  41949. coords: new Int32Array(ps),
  41950. colors: new Int32Array(ps),
  41951. });
  41952. }
  41953. function decodeType5Shading(mesh, reader, verticesPerRow) {
  41954. var coords = mesh.coords;
  41955. var colors = mesh.colors;
  41956. var ps = []; // not maintaining cs since that will match ps
  41957. while (reader.hasData) {
  41958. var coord = reader.readCoordinate();
  41959. var color = reader.readComponents();
  41960. ps.push(coords.length);
  41961. coords.push(coord);
  41962. colors.push(color);
  41963. }
  41964. mesh.figures.push({
  41965. type: 'lattice',
  41966. coords: new Int32Array(ps),
  41967. colors: new Int32Array(ps),
  41968. verticesPerRow: verticesPerRow
  41969. });
  41970. }
  41971. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  41972. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  41973. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  41974. var getB = (function getBClosure() {
  41975. function buildB(count) {
  41976. var lut = [];
  41977. for (var i = 0; i <= count; i++) {
  41978. var t = i / count, t_ = 1 - t;
  41979. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  41980. 3 * t * t * t_, t * t * t]));
  41981. }
  41982. return lut;
  41983. }
  41984. var cache = [];
  41985. return function getB(count) {
  41986. if (!cache[count]) {
  41987. cache[count] = buildB(count);
  41988. }
  41989. return cache[count];
  41990. };
  41991. })();
  41992. function buildFigureFromPatch(mesh, index) {
  41993. var figure = mesh.figures[index];
  41994. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  41995. var coords = mesh.coords, colors = mesh.colors;
  41996. var pi = figure.coords;
  41997. var ci = figure.colors;
  41998. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  41999. coords[pi[12]][0], coords[pi[15]][0]);
  42000. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  42001. coords[pi[12]][1], coords[pi[15]][1]);
  42002. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  42003. coords[pi[12]][0], coords[pi[15]][0]);
  42004. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  42005. coords[pi[12]][1], coords[pi[15]][1]);
  42006. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  42007. (mesh.bounds[2] - mesh.bounds[0]));
  42008. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42009. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  42010. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  42011. (mesh.bounds[3] - mesh.bounds[1]));
  42012. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42013. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  42014. var verticesPerRow = splitXBy + 1;
  42015. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  42016. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  42017. var k = 0;
  42018. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  42019. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  42020. c2 = colors[ci[2]], c3 = colors[ci[3]];
  42021. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  42022. for (var row = 0; row <= splitYBy; row++) {
  42023. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  42024. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  42025. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  42026. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  42027. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  42028. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  42029. for (var col = 0; col <= splitXBy; col++, k++) {
  42030. if ((row === 0 || row === splitYBy) &&
  42031. (col === 0 || col === splitXBy)) {
  42032. continue;
  42033. }
  42034. var x = 0, y = 0;
  42035. var q = 0;
  42036. for (var i = 0; i <= 3; i++) {
  42037. for (var j = 0; j <= 3; j++, q++) {
  42038. var m = bRow[row][i] * bCol[col][j];
  42039. x += coords[pi[q]][0] * m;
  42040. y += coords[pi[q]][1] * m;
  42041. }
  42042. }
  42043. figureCoords[k] = coords.length;
  42044. coords.push([x, y]);
  42045. figureColors[k] = colors.length;
  42046. var newColor = new Uint8Array(3);
  42047. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  42048. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  42049. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  42050. colors.push(newColor);
  42051. }
  42052. }
  42053. figureCoords[0] = pi[0];
  42054. figureColors[0] = ci[0];
  42055. figureCoords[splitXBy] = pi[3];
  42056. figureColors[splitXBy] = ci[1];
  42057. figureCoords[verticesPerRow * splitYBy] = pi[12];
  42058. figureColors[verticesPerRow * splitYBy] = ci[2];
  42059. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  42060. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  42061. mesh.figures[index] = {
  42062. type: 'lattice',
  42063. coords: figureCoords,
  42064. colors: figureColors,
  42065. verticesPerRow: verticesPerRow
  42066. };
  42067. }
  42068. function decodeType6Shading(mesh, reader) {
  42069. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  42070. var coords = mesh.coords;
  42071. var colors = mesh.colors;
  42072. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42073. var cs = new Int32Array(4); // c00, c30, c03, c33
  42074. while (reader.hasData) {
  42075. var f = reader.readFlag();
  42076. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  42077. var i, ii;
  42078. var pi = coords.length;
  42079. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  42080. coords.push(reader.readCoordinate());
  42081. }
  42082. var ci = colors.length;
  42083. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42084. colors.push(reader.readComponents());
  42085. }
  42086. var tmp1, tmp2, tmp3, tmp4;
  42087. switch (f) {
  42088. case 0:
  42089. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42090. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  42091. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  42092. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42093. cs[2] = ci + 1; cs[3] = ci + 2;
  42094. cs[0] = ci; cs[1] = ci + 3;
  42095. break;
  42096. case 1:
  42097. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42098. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42099. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42100. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42101. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42102. tmp1 = cs[2]; tmp2 = cs[3];
  42103. cs[2] = tmp2; cs[3] = ci;
  42104. cs[0] = tmp1; cs[1] = ci + 1;
  42105. break;
  42106. case 2:
  42107. tmp1 = ps[15];
  42108. tmp2 = ps[11];
  42109. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42110. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42111. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42112. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42113. tmp1 = cs[3];
  42114. cs[2] = cs[1]; cs[3] = ci;
  42115. cs[0] = tmp1; cs[1] = ci + 1;
  42116. break;
  42117. case 3:
  42118. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42119. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42120. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  42121. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42122. cs[2] = cs[0]; cs[3] = ci;
  42123. cs[0] = cs[1]; cs[1] = ci + 1;
  42124. break;
  42125. }
  42126. // set p11, p12, p21, p22
  42127. ps[5] = coords.length;
  42128. coords.push([
  42129. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  42130. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  42131. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42132. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  42133. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  42134. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  42135. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42136. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  42137. ]);
  42138. ps[6] = coords.length;
  42139. coords.push([
  42140. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  42141. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  42142. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42143. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  42144. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  42145. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  42146. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42147. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  42148. ]);
  42149. ps[9] = coords.length;
  42150. coords.push([
  42151. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  42152. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  42153. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42154. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  42155. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  42156. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  42157. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42158. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  42159. ]);
  42160. ps[10] = coords.length;
  42161. coords.push([
  42162. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  42163. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  42164. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42165. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  42166. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  42167. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  42168. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42169. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  42170. ]);
  42171. mesh.figures.push({
  42172. type: 'patch',
  42173. coords: new Int32Array(ps), // making copies of ps and cs
  42174. colors: new Int32Array(cs)
  42175. });
  42176. }
  42177. }
  42178. function decodeType7Shading(mesh, reader) {
  42179. var coords = mesh.coords;
  42180. var colors = mesh.colors;
  42181. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42182. var cs = new Int32Array(4); // c00, c30, c03, c33
  42183. while (reader.hasData) {
  42184. var f = reader.readFlag();
  42185. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  42186. var i, ii;
  42187. var pi = coords.length;
  42188. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  42189. coords.push(reader.readCoordinate());
  42190. }
  42191. var ci = colors.length;
  42192. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42193. colors.push(reader.readComponents());
  42194. }
  42195. var tmp1, tmp2, tmp3, tmp4;
  42196. switch (f) {
  42197. case 0:
  42198. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42199. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  42200. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  42201. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42202. cs[2] = ci + 1; cs[3] = ci + 2;
  42203. cs[0] = ci; cs[1] = ci + 3;
  42204. break;
  42205. case 1:
  42206. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42207. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42208. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42209. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42210. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42211. tmp1 = cs[2]; tmp2 = cs[3];
  42212. cs[2] = tmp2; cs[3] = ci;
  42213. cs[0] = tmp1; cs[1] = ci + 1;
  42214. break;
  42215. case 2:
  42216. tmp1 = ps[15];
  42217. tmp2 = ps[11];
  42218. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42219. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42220. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42221. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42222. tmp1 = cs[3];
  42223. cs[2] = cs[1]; cs[3] = ci;
  42224. cs[0] = tmp1; cs[1] = ci + 1;
  42225. break;
  42226. case 3:
  42227. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42228. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42229. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42230. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42231. cs[2] = cs[0]; cs[3] = ci;
  42232. cs[0] = cs[1]; cs[1] = ci + 1;
  42233. break;
  42234. }
  42235. mesh.figures.push({
  42236. type: 'patch',
  42237. coords: new Int32Array(ps), // making copies of ps and cs
  42238. colors: new Int32Array(cs)
  42239. });
  42240. }
  42241. }
  42242. function updateBounds(mesh) {
  42243. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  42244. maxX = minX, maxY = minY;
  42245. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  42246. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  42247. minX = minX > x ? x : minX;
  42248. minY = minY > y ? y : minY;
  42249. maxX = maxX < x ? x : maxX;
  42250. maxY = maxY < y ? y : maxY;
  42251. }
  42252. mesh.bounds = [minX, minY, maxX, maxY];
  42253. }
  42254. function packData(mesh) {
  42255. var i, ii, j, jj;
  42256. var coords = mesh.coords;
  42257. var coordsPacked = new Float32Array(coords.length * 2);
  42258. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  42259. var xy = coords[i];
  42260. coordsPacked[j++] = xy[0];
  42261. coordsPacked[j++] = xy[1];
  42262. }
  42263. mesh.coords = coordsPacked;
  42264. var colors = mesh.colors;
  42265. var colorsPacked = new Uint8Array(colors.length * 3);
  42266. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  42267. var c = colors[i];
  42268. colorsPacked[j++] = c[0];
  42269. colorsPacked[j++] = c[1];
  42270. colorsPacked[j++] = c[2];
  42271. }
  42272. mesh.colors = colorsPacked;
  42273. var figures = mesh.figures;
  42274. for (i = 0, ii = figures.length; i < ii; i++) {
  42275. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  42276. for (j = 0, jj = ps.length; j < jj; j++) {
  42277. ps[j] *= 2;
  42278. cs[j] *= 3;
  42279. }
  42280. }
  42281. }
  42282. function Mesh(stream, matrix, xref, res) {
  42283. assert(isStream(stream), 'Mesh data is not a stream');
  42284. var dict = stream.dict;
  42285. this.matrix = matrix;
  42286. this.shadingType = dict.get('ShadingType');
  42287. this.type = 'Pattern';
  42288. this.bbox = dict.getArray('BBox');
  42289. var cs = dict.get('ColorSpace', 'CS');
  42290. cs = ColorSpace.parse(cs, xref, res);
  42291. this.cs = cs;
  42292. this.background = dict.has('Background') ?
  42293. cs.getRgb(dict.get('Background'), 0) : null;
  42294. var fnObj = dict.get('Function');
  42295. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  42296. this.coords = [];
  42297. this.colors = [];
  42298. this.figures = [];
  42299. var decodeContext = {
  42300. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  42301. bitsPerComponent: dict.get('BitsPerComponent'),
  42302. bitsPerFlag: dict.get('BitsPerFlag'),
  42303. decode: dict.getArray('Decode'),
  42304. colorFn: fn,
  42305. colorSpace: cs,
  42306. numComps: fn ? 1 : cs.numComps
  42307. };
  42308. var reader = new MeshStreamReader(stream, decodeContext);
  42309. var patchMesh = false;
  42310. switch (this.shadingType) {
  42311. case ShadingType.FREE_FORM_MESH:
  42312. decodeType4Shading(this, reader);
  42313. break;
  42314. case ShadingType.LATTICE_FORM_MESH:
  42315. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  42316. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  42317. decodeType5Shading(this, reader, verticesPerRow);
  42318. break;
  42319. case ShadingType.COONS_PATCH_MESH:
  42320. decodeType6Shading(this, reader);
  42321. patchMesh = true;
  42322. break;
  42323. case ShadingType.TENSOR_PATCH_MESH:
  42324. decodeType7Shading(this, reader);
  42325. patchMesh = true;
  42326. break;
  42327. default:
  42328. error('Unsupported mesh type.');
  42329. break;
  42330. }
  42331. if (patchMesh) {
  42332. // dirty bounds calculation for determining, how dense shall be triangles
  42333. updateBounds(this);
  42334. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  42335. buildFigureFromPatch(this, i);
  42336. }
  42337. }
  42338. // calculate bounds
  42339. updateBounds(this);
  42340. packData(this);
  42341. }
  42342. Mesh.prototype = {
  42343. getIR: function Mesh_getIR() {
  42344. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  42345. this.bounds, this.matrix, this.bbox, this.background];
  42346. }
  42347. };
  42348. return Mesh;
  42349. })();
  42350. Shadings.Dummy = (function DummyClosure() {
  42351. function Dummy() {
  42352. this.type = 'Pattern';
  42353. }
  42354. Dummy.prototype = {
  42355. getIR: function Dummy_getIR() {
  42356. return ['Dummy'];
  42357. }
  42358. };
  42359. return Dummy;
  42360. })();
  42361. function getTilingPatternIR(operatorList, dict, args) {
  42362. var matrix = dict.getArray('Matrix');
  42363. var bbox = dict.getArray('BBox');
  42364. var xstep = dict.get('XStep');
  42365. var ystep = dict.get('YStep');
  42366. var paintType = dict.get('PaintType');
  42367. var tilingType = dict.get('TilingType');
  42368. return [
  42369. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  42370. paintType, tilingType
  42371. ];
  42372. }
  42373. exports.Pattern = Pattern;
  42374. exports.getTilingPatternIR = getTilingPatternIR;
  42375. }));
  42376. (function (root, factory) {
  42377. {
  42378. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  42379. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  42380. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  42381. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  42382. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  42383. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  42384. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  42385. }
  42386. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  42387. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  42388. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  42389. coreEncodings, coreStandardFonts, coreUnicode,
  42390. coreGlyphList) {
  42391. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42392. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  42393. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  42394. var ImageKind = sharedUtil.ImageKind;
  42395. var OPS = sharedUtil.OPS;
  42396. var TextRenderingMode = sharedUtil.TextRenderingMode;
  42397. var Util = sharedUtil.Util;
  42398. var assert = sharedUtil.assert;
  42399. var createPromiseCapability = sharedUtil.createPromiseCapability;
  42400. var error = sharedUtil.error;
  42401. var info = sharedUtil.info;
  42402. var isArray = sharedUtil.isArray;
  42403. var isNum = sharedUtil.isNum;
  42404. var isString = sharedUtil.isString;
  42405. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  42406. var warn = sharedUtil.warn;
  42407. var Dict = corePrimitives.Dict;
  42408. var Name = corePrimitives.Name;
  42409. var isCmd = corePrimitives.isCmd;
  42410. var isDict = corePrimitives.isDict;
  42411. var isName = corePrimitives.isName;
  42412. var isRef = corePrimitives.isRef;
  42413. var isStream = corePrimitives.isStream;
  42414. var DecodeStream = coreStream.DecodeStream;
  42415. var JpegStream = coreStream.JpegStream;
  42416. var Stream = coreStream.Stream;
  42417. var Lexer = coreParser.Lexer;
  42418. var Parser = coreParser.Parser;
  42419. var isEOF = coreParser.isEOF;
  42420. var PDFImage = coreImage.PDFImage;
  42421. var ColorSpace = coreColorSpace.ColorSpace;
  42422. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  42423. var ErrorFont = coreFonts.ErrorFont;
  42424. var FontFlags = coreFonts.FontFlags;
  42425. var Font = coreFonts.Font;
  42426. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  42427. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  42428. var getFontType = coreFonts.getFontType;
  42429. var isPDFFunction = coreFunction.isPDFFunction;
  42430. var PDFFunction = coreFunction.PDFFunction;
  42431. var Pattern = corePattern.Pattern;
  42432. var getTilingPatternIR = corePattern.getTilingPatternIR;
  42433. var CMapFactory = coreCMap.CMapFactory;
  42434. var IdentityCMap = coreCMap.IdentityCMap;
  42435. var getMetrics = coreMetrics.getMetrics;
  42436. var bidi = coreBidi.bidi;
  42437. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  42438. var StandardEncoding = coreEncodings.StandardEncoding;
  42439. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42440. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42441. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42442. var getEncoding = coreEncodings.getEncoding;
  42443. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42444. var getSerifFonts = coreStandardFonts.getSerifFonts;
  42445. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  42446. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  42447. var reverseIfRtl = coreUnicode.reverseIfRtl;
  42448. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42449. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42450. var PartialEvaluator = (function PartialEvaluatorClosure() {
  42451. var DefaultPartialEvaluatorOptions = {
  42452. forceDataSchema: false,
  42453. maxImageSize: -1,
  42454. disableFontFace: false,
  42455. cMapOptions: { url: null, packed: false }
  42456. };
  42457. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  42458. this.xref = xref;
  42459. this.resources = resources;
  42460. this.handler = handler;
  42461. this.forceDataSchema = forceDataSchema;
  42462. }
  42463. NativeImageDecoder.prototype = {
  42464. canDecode: function (image) {
  42465. return image instanceof JpegStream &&
  42466. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  42467. },
  42468. decode: function (image) {
  42469. // For natively supported JPEGs send them to the main thread for decoding.
  42470. var dict = image.dict;
  42471. var colorSpace = dict.get('ColorSpace', 'CS');
  42472. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  42473. var numComps = colorSpace.numComps;
  42474. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  42475. [image.getIR(this.forceDataSchema), numComps]);
  42476. return decodePromise.then(function (message) {
  42477. var data = message.data;
  42478. return new Stream(data, 0, data.length, image.dict);
  42479. });
  42480. }
  42481. };
  42482. /**
  42483. * Checks if the image can be decoded and displayed by the browser without any
  42484. * further processing such as color space conversions.
  42485. */
  42486. NativeImageDecoder.isSupported =
  42487. function NativeImageDecoder_isSupported(image, xref, res) {
  42488. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  42489. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  42490. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  42491. };
  42492. /**
  42493. * Checks if the image can be decoded by the browser.
  42494. */
  42495. NativeImageDecoder.isDecodable =
  42496. function NativeImageDecoder_isDecodable(image, xref, res) {
  42497. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  42498. return (cs.numComps === 1 || cs.numComps === 3) &&
  42499. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  42500. };
  42501. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  42502. uniquePrefix, idCounters, fontCache, options) {
  42503. this.pdfManager = pdfManager;
  42504. this.xref = xref;
  42505. this.handler = handler;
  42506. this.pageIndex = pageIndex;
  42507. this.uniquePrefix = uniquePrefix;
  42508. this.idCounters = idCounters;
  42509. this.fontCache = fontCache;
  42510. this.options = options || DefaultPartialEvaluatorOptions;
  42511. }
  42512. // Trying to minimize Date.now() usage and check every 100 time
  42513. var TIME_SLOT_DURATION_MS = 20;
  42514. var CHECK_TIME_EVERY = 100;
  42515. function TimeSlotManager() {
  42516. this.reset();
  42517. }
  42518. TimeSlotManager.prototype = {
  42519. check: function TimeSlotManager_check() {
  42520. if (++this.checked < CHECK_TIME_EVERY) {
  42521. return false;
  42522. }
  42523. this.checked = 0;
  42524. return this.endTime <= Date.now();
  42525. },
  42526. reset: function TimeSlotManager_reset() {
  42527. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  42528. this.checked = 0;
  42529. }
  42530. };
  42531. var deferred = Promise.resolve();
  42532. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  42533. PartialEvaluator.prototype = {
  42534. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  42535. if (!isDict(resources)) {
  42536. return false;
  42537. }
  42538. var processed = Object.create(null);
  42539. if (resources.objId) {
  42540. processed[resources.objId] = true;
  42541. }
  42542. var nodes = [resources], xref = this.xref;
  42543. while (nodes.length) {
  42544. var key, i, ii;
  42545. var node = nodes.shift();
  42546. // First check the current resources for blend modes.
  42547. var graphicStates = node.get('ExtGState');
  42548. if (isDict(graphicStates)) {
  42549. var graphicStatesKeys = graphicStates.getKeys();
  42550. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  42551. key = graphicStatesKeys[i];
  42552. var graphicState = graphicStates.get(key);
  42553. var bm = graphicState.get('BM');
  42554. if (isName(bm) && bm.name !== 'Normal') {
  42555. return true;
  42556. }
  42557. }
  42558. }
  42559. // Descend into the XObjects to look for more resources and blend modes.
  42560. var xObjects = node.get('XObject');
  42561. if (!isDict(xObjects)) {
  42562. continue;
  42563. }
  42564. var xObjectsKeys = xObjects.getKeys();
  42565. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  42566. key = xObjectsKeys[i];
  42567. var xObject = xObjects.getRaw(key);
  42568. if (isRef(xObject)) {
  42569. if (processed[xObject.toString()]) {
  42570. // The XObject has already been processed, and by avoiding a
  42571. // redundant `xref.fetch` we can *significantly* reduce the load
  42572. // time for badly generated PDF files (fixes issue6961.pdf).
  42573. continue;
  42574. }
  42575. xObject = xref.fetch(xObject);
  42576. }
  42577. if (!isStream(xObject)) {
  42578. continue;
  42579. }
  42580. if (xObject.dict.objId) {
  42581. if (processed[xObject.dict.objId]) {
  42582. // stream has objId and is processed already
  42583. continue;
  42584. }
  42585. processed[xObject.dict.objId] = true;
  42586. }
  42587. var xResources = xObject.dict.get('Resources');
  42588. // Checking objId to detect an infinite loop.
  42589. if (isDict(xResources) &&
  42590. (!xResources.objId || !processed[xResources.objId])) {
  42591. nodes.push(xResources);
  42592. if (xResources.objId) {
  42593. processed[xResources.objId] = true;
  42594. }
  42595. }
  42596. }
  42597. }
  42598. return false;
  42599. },
  42600. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  42601. xobj, smask,
  42602. operatorList,
  42603. task,
  42604. initialState) {
  42605. var matrix = xobj.dict.getArray('Matrix');
  42606. var bbox = xobj.dict.getArray('BBox');
  42607. var group = xobj.dict.get('Group');
  42608. if (group) {
  42609. var groupOptions = {
  42610. matrix: matrix,
  42611. bbox: bbox,
  42612. smask: smask,
  42613. isolated: false,
  42614. knockout: false
  42615. };
  42616. var groupSubtype = group.get('S');
  42617. var colorSpace;
  42618. if (isName(groupSubtype, 'Transparency')) {
  42619. groupOptions.isolated = (group.get('I') || false);
  42620. groupOptions.knockout = (group.get('K') || false);
  42621. colorSpace = (group.has('CS') ?
  42622. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  42623. }
  42624. if (smask && smask.backdrop) {
  42625. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  42626. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  42627. }
  42628. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  42629. }
  42630. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  42631. return this.getOperatorList(xobj, task,
  42632. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  42633. then(function () {
  42634. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  42635. if (group) {
  42636. operatorList.addOp(OPS.endGroup, [groupOptions]);
  42637. }
  42638. });
  42639. },
  42640. buildPaintImageXObject:
  42641. function PartialEvaluator_buildPaintImageXObject(resources, image,
  42642. inline, operatorList,
  42643. cacheKey, imageCache) {
  42644. var self = this;
  42645. var dict = image.dict;
  42646. var w = dict.get('Width', 'W');
  42647. var h = dict.get('Height', 'H');
  42648. if (!(w && isNum(w)) || !(h && isNum(h))) {
  42649. warn('Image dimensions are missing, or not numbers.');
  42650. return;
  42651. }
  42652. var maxImageSize = this.options.maxImageSize;
  42653. if (maxImageSize !== -1 && w * h > maxImageSize) {
  42654. warn('Image exceeded maximum allowed size and was removed.');
  42655. return;
  42656. }
  42657. var imageMask = (dict.get('ImageMask', 'IM') || false);
  42658. var imgData, args;
  42659. if (imageMask) {
  42660. // This depends on a tmpCanvas being filled with the
  42661. // current fillStyle, such that processing the pixel
  42662. // data can't be done here. Instead of creating a
  42663. // complete PDFImage, only read the information needed
  42664. // for later.
  42665. var width = dict.get('Width', 'W');
  42666. var height = dict.get('Height', 'H');
  42667. var bitStrideLength = (width + 7) >> 3;
  42668. var imgArray = image.getBytes(bitStrideLength * height);
  42669. var decode = dict.getArray('Decode', 'D');
  42670. var inverseDecode = (!!decode && decode[0] > 0);
  42671. imgData = PDFImage.createMask(imgArray, width, height,
  42672. image instanceof DecodeStream,
  42673. inverseDecode);
  42674. imgData.cached = true;
  42675. args = [imgData];
  42676. operatorList.addOp(OPS.paintImageMaskXObject, args);
  42677. if (cacheKey) {
  42678. imageCache[cacheKey] = {
  42679. fn: OPS.paintImageMaskXObject,
  42680. args: args
  42681. };
  42682. }
  42683. return;
  42684. }
  42685. var softMask = (dict.get('SMask', 'SM') || false);
  42686. var mask = (dict.get('Mask') || false);
  42687. var SMALL_IMAGE_DIMENSIONS = 200;
  42688. // Inlining small images into the queue as RGB data
  42689. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  42690. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  42691. var imageObj = new PDFImage(this.xref, resources, image,
  42692. inline, null, null);
  42693. // We force the use of RGBA_32BPP images here, because we can't handle
  42694. // any other kind.
  42695. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  42696. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  42697. return;
  42698. }
  42699. // If there is no imageMask, create the PDFImage and a lot
  42700. // of image processing can be done here.
  42701. var uniquePrefix = (this.uniquePrefix || '');
  42702. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  42703. operatorList.addDependency(objId);
  42704. args = [objId, w, h];
  42705. if (!softMask && !mask && image instanceof JpegStream &&
  42706. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  42707. // These JPEGs don't need any more processing so we can just send it.
  42708. operatorList.addOp(OPS.paintJpegXObject, args);
  42709. this.handler.send('obj',
  42710. [objId, this.pageIndex, 'JpegStream',
  42711. image.getIR(this.options.forceDataSchema)]);
  42712. return;
  42713. }
  42714. // Creates native image decoder only if a JPEG image or mask is present.
  42715. var nativeImageDecoder = null;
  42716. if (image instanceof JpegStream || mask instanceof JpegStream ||
  42717. softMask instanceof JpegStream) {
  42718. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  42719. self.handler, self.options.forceDataSchema);
  42720. }
  42721. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  42722. nativeImageDecoder).
  42723. then(function(imageObj) {
  42724. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  42725. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  42726. [imgData.data.buffer]);
  42727. }).then(undefined, function (reason) {
  42728. warn('Unable to decode image: ' + reason);
  42729. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  42730. });
  42731. operatorList.addOp(OPS.paintImageXObject, args);
  42732. if (cacheKey) {
  42733. imageCache[cacheKey] = {
  42734. fn: OPS.paintImageXObject,
  42735. args: args
  42736. };
  42737. }
  42738. },
  42739. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  42740. operatorList, task,
  42741. stateManager) {
  42742. var smaskContent = smask.get('G');
  42743. var smaskOptions = {
  42744. subtype: smask.get('S').name,
  42745. backdrop: smask.get('BC')
  42746. };
  42747. // The SMask might have a alpha/luminosity value transfer function --
  42748. // we will build a map of integer values in range 0..255 to be fast.
  42749. var transferObj = smask.get('TR');
  42750. if (isPDFFunction(transferObj)) {
  42751. var transferFn = PDFFunction.parse(this.xref, transferObj);
  42752. var transferMap = new Uint8Array(256);
  42753. var tmp = new Float32Array(1);
  42754. for (var i = 0; i < 256; i++) {
  42755. tmp[0] = i / 255;
  42756. transferFn(tmp, 0, tmp, 0);
  42757. transferMap[i] = (tmp[0] * 255) | 0;
  42758. }
  42759. smaskOptions.transferMap = transferMap;
  42760. }
  42761. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  42762. operatorList, task, stateManager.state.clone());
  42763. },
  42764. handleTilingType:
  42765. function PartialEvaluator_handleTilingType(fn, args, resources,
  42766. pattern, patternDict,
  42767. operatorList, task) {
  42768. // Create an IR of the pattern code.
  42769. var tilingOpList = new OperatorList();
  42770. // Merge the available resources, to prevent issues when the patternDict
  42771. // is missing some /Resources entries (fixes issue6541.pdf).
  42772. var resourcesArray = [patternDict.get('Resources'), resources];
  42773. var patternResources = Dict.merge(this.xref, resourcesArray);
  42774. return this.getOperatorList(pattern, task, patternResources,
  42775. tilingOpList).then(function () {
  42776. // Add the dependencies to the parent operator list so they are
  42777. // resolved before sub operator list is executed synchronously.
  42778. operatorList.addDependencies(tilingOpList.dependencies);
  42779. operatorList.addOp(fn, getTilingPatternIR({
  42780. fnArray: tilingOpList.fnArray,
  42781. argsArray: tilingOpList.argsArray
  42782. }, patternDict, args));
  42783. });
  42784. },
  42785. handleSetFont:
  42786. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  42787. operatorList, task, state) {
  42788. // TODO(mack): Not needed?
  42789. var fontName;
  42790. if (fontArgs) {
  42791. fontArgs = fontArgs.slice();
  42792. fontName = fontArgs[0].name;
  42793. }
  42794. var self = this;
  42795. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  42796. function (translated) {
  42797. if (!translated.font.isType3Font) {
  42798. return translated;
  42799. }
  42800. return translated.loadType3Data(self, resources, operatorList, task).
  42801. then(function () {
  42802. return translated;
  42803. }, function (reason) {
  42804. // Error in the font data -- sending unsupported feature notification.
  42805. self.handler.send('UnsupportedFeature',
  42806. {featureId: UNSUPPORTED_FEATURES.font});
  42807. return new TranslatedFont('g_font_error',
  42808. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  42809. });
  42810. }).then(function (translated) {
  42811. state.font = translated.font;
  42812. translated.send(self.handler);
  42813. return translated.loadedName;
  42814. });
  42815. },
  42816. handleText: function PartialEvaluator_handleText(chars, state) {
  42817. var font = state.font;
  42818. var glyphs = font.charsToGlyphs(chars);
  42819. var isAddToPathSet = !!(state.textRenderingMode &
  42820. TextRenderingMode.ADD_TO_PATH_FLAG);
  42821. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  42822. var buildPath = function (fontChar) {
  42823. if (!font.renderer.hasBuiltPath(fontChar)) {
  42824. var path = font.renderer.getPathJs(fontChar);
  42825. this.handler.send('commonobj', [
  42826. font.loadedName + '_path_' + fontChar,
  42827. 'FontPath',
  42828. path
  42829. ]);
  42830. }
  42831. }.bind(this);
  42832. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  42833. var glyph = glyphs[i];
  42834. buildPath(glyph.fontChar);
  42835. // If the glyph has an accent we need to build a path for its
  42836. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  42837. var accent = glyph.accent;
  42838. if (accent && accent.fontChar) {
  42839. buildPath(accent.fontChar);
  42840. }
  42841. }
  42842. }
  42843. return glyphs;
  42844. },
  42845. setGState: function PartialEvaluator_setGState(resources, gState,
  42846. operatorList, task,
  42847. xref, stateManager) {
  42848. // This array holds the converted/processed state data.
  42849. var gStateObj = [];
  42850. var gStateKeys = gState.getKeys();
  42851. var self = this;
  42852. var promise = Promise.resolve();
  42853. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  42854. var key = gStateKeys[i];
  42855. var value = gState.get(key);
  42856. switch (key) {
  42857. case 'Type':
  42858. break;
  42859. case 'LW':
  42860. case 'LC':
  42861. case 'LJ':
  42862. case 'ML':
  42863. case 'D':
  42864. case 'RI':
  42865. case 'FL':
  42866. case 'CA':
  42867. case 'ca':
  42868. gStateObj.push([key, value]);
  42869. break;
  42870. case 'Font':
  42871. promise = promise.then(function () {
  42872. return self.handleSetFont(resources, null, value[0], operatorList,
  42873. task, stateManager.state).
  42874. then(function (loadedName) {
  42875. operatorList.addDependency(loadedName);
  42876. gStateObj.push([key, [loadedName, value[1]]]);
  42877. });
  42878. });
  42879. break;
  42880. case 'BM':
  42881. gStateObj.push([key, value]);
  42882. break;
  42883. case 'SMask':
  42884. if (isName(value, 'None')) {
  42885. gStateObj.push([key, false]);
  42886. break;
  42887. }
  42888. if (isDict(value)) {
  42889. promise = promise.then(function (dict) {
  42890. return self.handleSMask(dict, resources, operatorList,
  42891. task, stateManager);
  42892. }.bind(this, value));
  42893. gStateObj.push([key, true]);
  42894. } else {
  42895. warn('Unsupported SMask type');
  42896. }
  42897. break;
  42898. // Only generate info log messages for the following since
  42899. // they are unlikely to have a big impact on the rendering.
  42900. case 'OP':
  42901. case 'op':
  42902. case 'OPM':
  42903. case 'BG':
  42904. case 'BG2':
  42905. case 'UCR':
  42906. case 'UCR2':
  42907. case 'TR':
  42908. case 'TR2':
  42909. case 'HT':
  42910. case 'SM':
  42911. case 'SA':
  42912. case 'AIS':
  42913. case 'TK':
  42914. // TODO implement these operators.
  42915. info('graphic state operator ' + key);
  42916. break;
  42917. default:
  42918. info('Unknown graphic state operator ' + key);
  42919. break;
  42920. }
  42921. }
  42922. return promise.then(function () {
  42923. if (gStateObj.length > 0) {
  42924. operatorList.addOp(OPS.setGState, [gStateObj]);
  42925. }
  42926. });
  42927. },
  42928. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  42929. resources) {
  42930. function errorFont() {
  42931. return Promise.resolve(new TranslatedFont('g_font_error',
  42932. new ErrorFont('Font ' + fontName + ' is not available'), font));
  42933. }
  42934. var fontRef;
  42935. if (font) { // Loading by ref.
  42936. assert(isRef(font));
  42937. fontRef = font;
  42938. } else { // Loading by name.
  42939. var fontRes = resources.get('Font');
  42940. if (fontRes) {
  42941. fontRef = fontRes.getRaw(fontName);
  42942. } else {
  42943. warn('fontRes not available');
  42944. return errorFont();
  42945. }
  42946. }
  42947. if (!fontRef) {
  42948. warn('fontRef not available');
  42949. return errorFont();
  42950. }
  42951. if (this.fontCache.has(fontRef)) {
  42952. return this.fontCache.get(fontRef);
  42953. }
  42954. font = xref.fetchIfRef(fontRef);
  42955. if (!isDict(font)) {
  42956. return errorFont();
  42957. }
  42958. // We are holding `font.translated` references just for `fontRef`s that
  42959. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  42960. if (font.translated) {
  42961. return font.translated;
  42962. }
  42963. var fontCapability = createPromiseCapability();
  42964. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  42965. var descriptor = preEvaluatedFont.descriptor;
  42966. var fontRefIsRef = isRef(fontRef), fontID;
  42967. if (fontRefIsRef) {
  42968. fontID = fontRef.toString();
  42969. }
  42970. if (isDict(descriptor)) {
  42971. if (!descriptor.fontAliases) {
  42972. descriptor.fontAliases = Object.create(null);
  42973. }
  42974. var fontAliases = descriptor.fontAliases;
  42975. var hash = preEvaluatedFont.hash;
  42976. if (fontAliases[hash]) {
  42977. var aliasFontRef = fontAliases[hash].aliasRef;
  42978. if (fontRefIsRef && aliasFontRef &&
  42979. this.fontCache.has(aliasFontRef)) {
  42980. this.fontCache.putAlias(fontRef, aliasFontRef);
  42981. return this.fontCache.get(fontRef);
  42982. }
  42983. } else {
  42984. fontAliases[hash] = {
  42985. fontID: Font.getFontID()
  42986. };
  42987. }
  42988. if (fontRefIsRef) {
  42989. fontAliases[hash].aliasRef = fontRef;
  42990. }
  42991. fontID = fontAliases[hash].fontID;
  42992. }
  42993. // Workaround for bad PDF generators that reference fonts incorrectly,
  42994. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  42995. // In this case we should not put the font into `this.fontCache` (which is
  42996. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  42997. //
  42998. // However, if we don't cache the font it's not possible to remove it
  42999. // when `cleanup` is triggered from the API, which causes issues on
  43000. // subsequent rendering operations (see issue7403.pdf).
  43001. // A simple workaround would be to just not hold `font.translated`
  43002. // references in this case, but this would force us to unnecessarily load
  43003. // the same fonts over and over.
  43004. //
  43005. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  43006. // key in `this.fontCache`, to allow the font to be cached.
  43007. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  43008. // keys. Also, since `fontRef` is used when getting cached fonts,
  43009. // we'll not accidentally match fonts cached with the `fontID`.
  43010. if (fontRefIsRef) {
  43011. this.fontCache.put(fontRef, fontCapability.promise);
  43012. } else {
  43013. if (!fontID) {
  43014. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  43015. }
  43016. this.fontCache.put('id_' + fontID, fontCapability.promise);
  43017. }
  43018. assert(fontID, 'The "fontID" must be defined.');
  43019. // Keep track of each font we translated so the caller can
  43020. // load them asynchronously before calling display on a page.
  43021. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  43022. font.translated = fontCapability.promise;
  43023. // TODO move promises into translate font
  43024. var translatedPromise;
  43025. try {
  43026. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  43027. } catch (e) {
  43028. translatedPromise = Promise.reject(e);
  43029. }
  43030. var self = this;
  43031. translatedPromise.then(function (translatedFont) {
  43032. if (translatedFont.fontType !== undefined) {
  43033. var xrefFontStats = xref.stats.fontTypes;
  43034. xrefFontStats[translatedFont.fontType] = true;
  43035. }
  43036. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43037. translatedFont, font));
  43038. }, function (reason) {
  43039. // TODO fontCapability.reject?
  43040. // Error in the font data -- sending unsupported feature notification.
  43041. self.handler.send('UnsupportedFeature',
  43042. {featureId: UNSUPPORTED_FEATURES.font});
  43043. try {
  43044. // error, but it's still nice to have font type reported
  43045. var descriptor = preEvaluatedFont.descriptor;
  43046. var fontFile3 = descriptor && descriptor.get('FontFile3');
  43047. var subtype = fontFile3 && fontFile3.get('Subtype');
  43048. var fontType = getFontType(preEvaluatedFont.type,
  43049. subtype && subtype.name);
  43050. var xrefFontStats = xref.stats.fontTypes;
  43051. xrefFontStats[fontType] = true;
  43052. } catch (ex) { }
  43053. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43054. new ErrorFont(reason instanceof Error ? reason.message : reason),
  43055. font));
  43056. });
  43057. return fontCapability.promise;
  43058. },
  43059. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  43060. var lastIndex = operatorList.length - 1;
  43061. if (!args) {
  43062. args = [];
  43063. }
  43064. if (lastIndex < 0 ||
  43065. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  43066. operatorList.addOp(OPS.constructPath, [[fn], args]);
  43067. } else {
  43068. var opArgs = operatorList.argsArray[lastIndex];
  43069. opArgs[0].push(fn);
  43070. Array.prototype.push.apply(opArgs[1], args);
  43071. }
  43072. },
  43073. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  43074. cs, patterns, resources, task, xref) {
  43075. // compile tiling patterns
  43076. var patternName = args[args.length - 1];
  43077. // SCN/scn applies patterns along with normal colors
  43078. var pattern;
  43079. if (isName(patternName) &&
  43080. (pattern = patterns.get(patternName.name))) {
  43081. var dict = (isStream(pattern) ? pattern.dict : pattern);
  43082. var typeNum = dict.get('PatternType');
  43083. if (typeNum === TILING_PATTERN) {
  43084. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  43085. return this.handleTilingType(fn, color, resources, pattern,
  43086. dict, operatorList, task);
  43087. } else if (typeNum === SHADING_PATTERN) {
  43088. var shading = dict.get('Shading');
  43089. var matrix = dict.getArray('Matrix');
  43090. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  43091. this.handler);
  43092. operatorList.addOp(fn, pattern.getIR());
  43093. return Promise.resolve();
  43094. } else {
  43095. return Promise.reject('Unknown PatternType: ' + typeNum);
  43096. }
  43097. }
  43098. // TODO shall we fail here?
  43099. operatorList.addOp(fn, args);
  43100. return Promise.resolve();
  43101. },
  43102. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  43103. task,
  43104. resources,
  43105. operatorList,
  43106. initialState) {
  43107. var self = this;
  43108. var xref = this.xref;
  43109. var imageCache = Object.create(null);
  43110. assert(operatorList);
  43111. resources = (resources || Dict.empty);
  43112. var xobjs = (resources.get('XObject') || Dict.empty);
  43113. var patterns = (resources.get('Pattern') || Dict.empty);
  43114. var stateManager = new StateManager(initialState || new EvalState());
  43115. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43116. var timeSlotManager = new TimeSlotManager();
  43117. return new Promise(function promiseBody(resolve, reject) {
  43118. var next = function (promise) {
  43119. promise.then(function () {
  43120. try {
  43121. promiseBody(resolve, reject);
  43122. } catch (ex) {
  43123. reject(ex);
  43124. }
  43125. }, reject);
  43126. };
  43127. task.ensureNotTerminated();
  43128. timeSlotManager.reset();
  43129. var stop, operation = {}, i, ii, cs;
  43130. while (!(stop = timeSlotManager.check())) {
  43131. // The arguments parsed by read() are used beyond this loop, so we
  43132. // cannot reuse the same array on each iteration. Therefore we pass
  43133. // in |null| as the initial value (see the comment on
  43134. // EvaluatorPreprocessor_read() for why).
  43135. operation.args = null;
  43136. if (!(preprocessor.read(operation))) {
  43137. break;
  43138. }
  43139. var args = operation.args;
  43140. var fn = operation.fn;
  43141. switch (fn | 0) {
  43142. case OPS.paintXObject:
  43143. if (args[0].code) {
  43144. break;
  43145. }
  43146. // eagerly compile XForm objects
  43147. var name = args[0].name;
  43148. if (!name) {
  43149. warn('XObject must be referred to by name.');
  43150. continue;
  43151. }
  43152. if (imageCache[name] !== undefined) {
  43153. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  43154. args = null;
  43155. continue;
  43156. }
  43157. var xobj = xobjs.get(name);
  43158. if (xobj) {
  43159. assert(isStream(xobj), 'XObject should be a stream');
  43160. var type = xobj.dict.get('Subtype');
  43161. assert(isName(type), 'XObject should have a Name subtype');
  43162. if (type.name === 'Form') {
  43163. stateManager.save();
  43164. next(self.buildFormXObject(resources, xobj, null,
  43165. operatorList, task,
  43166. stateManager.state.clone()).
  43167. then(function () {
  43168. stateManager.restore();
  43169. }));
  43170. return;
  43171. } else if (type.name === 'Image') {
  43172. self.buildPaintImageXObject(resources, xobj, false,
  43173. operatorList, name, imageCache);
  43174. args = null;
  43175. continue;
  43176. } else if (type.name === 'PS') {
  43177. // PostScript XObjects are unused when viewing documents.
  43178. // See section 4.7.1 of Adobe's PDF reference.
  43179. info('Ignored XObject subtype PS');
  43180. continue;
  43181. } else {
  43182. error('Unhandled XObject subtype ' + type.name);
  43183. }
  43184. }
  43185. break;
  43186. case OPS.setFont:
  43187. var fontSize = args[1];
  43188. // eagerly collect all fonts
  43189. next(self.handleSetFont(resources, args, null, operatorList,
  43190. task, stateManager.state).
  43191. then(function (loadedName) {
  43192. operatorList.addDependency(loadedName);
  43193. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  43194. }));
  43195. return;
  43196. case OPS.endInlineImage:
  43197. var cacheKey = args[0].cacheKey;
  43198. if (cacheKey) {
  43199. var cacheEntry = imageCache[cacheKey];
  43200. if (cacheEntry !== undefined) {
  43201. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  43202. args = null;
  43203. continue;
  43204. }
  43205. }
  43206. self.buildPaintImageXObject(resources, args[0], true,
  43207. operatorList, cacheKey, imageCache);
  43208. args = null;
  43209. continue;
  43210. case OPS.showText:
  43211. args[0] = self.handleText(args[0], stateManager.state);
  43212. break;
  43213. case OPS.showSpacedText:
  43214. var arr = args[0];
  43215. var combinedGlyphs = [];
  43216. var arrLength = arr.length;
  43217. var state = stateManager.state;
  43218. for (i = 0; i < arrLength; ++i) {
  43219. var arrItem = arr[i];
  43220. if (isString(arrItem)) {
  43221. Array.prototype.push.apply(combinedGlyphs,
  43222. self.handleText(arrItem, state));
  43223. } else if (isNum(arrItem)) {
  43224. combinedGlyphs.push(arrItem);
  43225. }
  43226. }
  43227. args[0] = combinedGlyphs;
  43228. fn = OPS.showText;
  43229. break;
  43230. case OPS.nextLineShowText:
  43231. operatorList.addOp(OPS.nextLine);
  43232. args[0] = self.handleText(args[0], stateManager.state);
  43233. fn = OPS.showText;
  43234. break;
  43235. case OPS.nextLineSetSpacingShowText:
  43236. operatorList.addOp(OPS.nextLine);
  43237. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  43238. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  43239. args[0] = self.handleText(args[0], stateManager.state);
  43240. fn = OPS.showText;
  43241. break;
  43242. case OPS.setTextRenderingMode:
  43243. stateManager.state.textRenderingMode = args[0];
  43244. break;
  43245. case OPS.setFillColorSpace:
  43246. stateManager.state.fillColorSpace =
  43247. ColorSpace.parse(args[0], xref, resources);
  43248. continue;
  43249. case OPS.setStrokeColorSpace:
  43250. stateManager.state.strokeColorSpace =
  43251. ColorSpace.parse(args[0], xref, resources);
  43252. continue;
  43253. case OPS.setFillColor:
  43254. cs = stateManager.state.fillColorSpace;
  43255. args = cs.getRgb(args, 0);
  43256. fn = OPS.setFillRGBColor;
  43257. break;
  43258. case OPS.setStrokeColor:
  43259. cs = stateManager.state.strokeColorSpace;
  43260. args = cs.getRgb(args, 0);
  43261. fn = OPS.setStrokeRGBColor;
  43262. break;
  43263. case OPS.setFillGray:
  43264. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  43265. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43266. fn = OPS.setFillRGBColor;
  43267. break;
  43268. case OPS.setStrokeGray:
  43269. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  43270. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43271. fn = OPS.setStrokeRGBColor;
  43272. break;
  43273. case OPS.setFillCMYKColor:
  43274. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  43275. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43276. fn = OPS.setFillRGBColor;
  43277. break;
  43278. case OPS.setStrokeCMYKColor:
  43279. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  43280. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43281. fn = OPS.setStrokeRGBColor;
  43282. break;
  43283. case OPS.setFillRGBColor:
  43284. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  43285. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43286. break;
  43287. case OPS.setStrokeRGBColor:
  43288. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  43289. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43290. break;
  43291. case OPS.setFillColorN:
  43292. cs = stateManager.state.fillColorSpace;
  43293. if (cs.name === 'Pattern') {
  43294. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  43295. cs, patterns, resources, task, xref));
  43296. return;
  43297. }
  43298. args = cs.getRgb(args, 0);
  43299. fn = OPS.setFillRGBColor;
  43300. break;
  43301. case OPS.setStrokeColorN:
  43302. cs = stateManager.state.strokeColorSpace;
  43303. if (cs.name === 'Pattern') {
  43304. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  43305. cs, patterns, resources, task, xref));
  43306. return;
  43307. }
  43308. args = cs.getRgb(args, 0);
  43309. fn = OPS.setStrokeRGBColor;
  43310. break;
  43311. case OPS.shadingFill:
  43312. var shadingRes = resources.get('Shading');
  43313. if (!shadingRes) {
  43314. error('No shading resource found');
  43315. }
  43316. var shading = shadingRes.get(args[0].name);
  43317. if (!shading) {
  43318. error('No shading object found');
  43319. }
  43320. var shadingFill = Pattern.parseShading(shading, null, xref,
  43321. resources, self.handler);
  43322. var patternIR = shadingFill.getIR();
  43323. args = [patternIR];
  43324. fn = OPS.shadingFill;
  43325. break;
  43326. case OPS.setGState:
  43327. var dictName = args[0];
  43328. var extGState = resources.get('ExtGState');
  43329. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43330. break;
  43331. }
  43332. var gState = extGState.get(dictName.name);
  43333. next(self.setGState(resources, gState, operatorList, task, xref,
  43334. stateManager));
  43335. return;
  43336. case OPS.moveTo:
  43337. case OPS.lineTo:
  43338. case OPS.curveTo:
  43339. case OPS.curveTo2:
  43340. case OPS.curveTo3:
  43341. case OPS.closePath:
  43342. self.buildPath(operatorList, fn, args);
  43343. continue;
  43344. case OPS.rectangle:
  43345. self.buildPath(operatorList, fn, args);
  43346. continue;
  43347. case OPS.markPoint:
  43348. case OPS.markPointProps:
  43349. case OPS.beginMarkedContent:
  43350. case OPS.beginMarkedContentProps:
  43351. case OPS.endMarkedContent:
  43352. case OPS.beginCompat:
  43353. case OPS.endCompat:
  43354. // Ignore operators where the corresponding handlers are known to
  43355. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  43356. // serialization errors and is also a bit more efficient.
  43357. // We could also try to serialize all objects in a general way,
  43358. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  43359. // but doing so is meaningless without knowing the semantics.
  43360. continue;
  43361. default:
  43362. // Note: Ignore the operator if it has `Dict` arguments, since
  43363. // those are non-serializable, otherwise postMessage will throw
  43364. // "An object could not be cloned.".
  43365. if (args !== null) {
  43366. for (i = 0, ii = args.length; i < ii; i++) {
  43367. if (args[i] instanceof Dict) {
  43368. break;
  43369. }
  43370. }
  43371. if (i < ii) {
  43372. warn('getOperatorList - ignoring operator: ' + fn);
  43373. continue;
  43374. }
  43375. }
  43376. }
  43377. operatorList.addOp(fn, args);
  43378. }
  43379. if (stop) {
  43380. next(deferred);
  43381. return;
  43382. }
  43383. // Some PDFs don't close all restores inside object/form.
  43384. // Closing those for them.
  43385. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  43386. operatorList.addOp(OPS.restore, []);
  43387. }
  43388. resolve();
  43389. });
  43390. },
  43391. getTextContent:
  43392. function PartialEvaluator_getTextContent(stream, task, resources,
  43393. stateManager,
  43394. normalizeWhitespace,
  43395. combineTextItems) {
  43396. stateManager = (stateManager || new StateManager(new TextState()));
  43397. var WhitespaceRegexp = /\s/g;
  43398. var textContent = {
  43399. items: [],
  43400. styles: Object.create(null)
  43401. };
  43402. var textContentItem = {
  43403. initialized: false,
  43404. str: [],
  43405. width: 0,
  43406. height: 0,
  43407. vertical: false,
  43408. lastAdvanceWidth: 0,
  43409. lastAdvanceHeight: 0,
  43410. textAdvanceScale: 0,
  43411. spaceWidth: 0,
  43412. fakeSpaceMin: Infinity,
  43413. fakeMultiSpaceMin: Infinity,
  43414. fakeMultiSpaceMax: -0,
  43415. textRunBreakAllowed: false,
  43416. transform: null,
  43417. fontName: null
  43418. };
  43419. var SPACE_FACTOR = 0.3;
  43420. var MULTI_SPACE_FACTOR = 1.5;
  43421. var MULTI_SPACE_FACTOR_MAX = 4;
  43422. var self = this;
  43423. var xref = this.xref;
  43424. resources = (xref.fetchIfRef(resources) || Dict.empty);
  43425. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  43426. var xobjs = null;
  43427. var xobjsCache = Object.create(null);
  43428. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43429. var textState;
  43430. function ensureTextContentItem() {
  43431. if (textContentItem.initialized) {
  43432. return textContentItem;
  43433. }
  43434. var font = textState.font;
  43435. if (!(font.loadedName in textContent.styles)) {
  43436. textContent.styles[font.loadedName] = {
  43437. fontFamily: font.fallbackName,
  43438. ascent: font.ascent,
  43439. descent: font.descent,
  43440. vertical: font.vertical
  43441. };
  43442. }
  43443. textContentItem.fontName = font.loadedName;
  43444. // 9.4.4 Text Space Details
  43445. var tsm = [textState.fontSize * textState.textHScale, 0,
  43446. 0, textState.fontSize,
  43447. 0, textState.textRise];
  43448. if (font.isType3Font &&
  43449. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  43450. textState.fontSize === 1) {
  43451. var glyphHeight = font.bbox[3] - font.bbox[1];
  43452. if (glyphHeight > 0) {
  43453. glyphHeight = glyphHeight * textState.fontMatrix[3];
  43454. tsm[3] *= glyphHeight;
  43455. }
  43456. }
  43457. var trm = Util.transform(textState.ctm,
  43458. Util.transform(textState.textMatrix, tsm));
  43459. textContentItem.transform = trm;
  43460. if (!font.vertical) {
  43461. textContentItem.width = 0;
  43462. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  43463. textContentItem.vertical = false;
  43464. } else {
  43465. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  43466. textContentItem.height = 0;
  43467. textContentItem.vertical = true;
  43468. }
  43469. var a = textState.textLineMatrix[0];
  43470. var b = textState.textLineMatrix[1];
  43471. var scaleLineX = Math.sqrt(a * a + b * b);
  43472. a = textState.ctm[0];
  43473. b = textState.ctm[1];
  43474. var scaleCtmX = Math.sqrt(a * a + b * b);
  43475. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  43476. textContentItem.lastAdvanceWidth = 0;
  43477. textContentItem.lastAdvanceHeight = 0;
  43478. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  43479. if (spaceWidth) {
  43480. textContentItem.spaceWidth = spaceWidth;
  43481. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  43482. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  43483. textContentItem.fakeMultiSpaceMax =
  43484. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  43485. // It's okay for monospace fonts to fake as much space as needed.
  43486. textContentItem.textRunBreakAllowed = !font.isMonospace;
  43487. } else {
  43488. textContentItem.spaceWidth = 0;
  43489. textContentItem.fakeSpaceMin = Infinity;
  43490. textContentItem.fakeMultiSpaceMin = Infinity;
  43491. textContentItem.fakeMultiSpaceMax = 0;
  43492. textContentItem.textRunBreakAllowed = false;
  43493. }
  43494. textContentItem.initialized = true;
  43495. return textContentItem;
  43496. }
  43497. function replaceWhitespace(str) {
  43498. // Replaces all whitespaces with standard spaces (0x20), to avoid
  43499. // alignment issues between the textLayer and the canvas if the text
  43500. // contains e.g. tabs (fixes issue6612.pdf).
  43501. var i = 0, ii = str.length, code;
  43502. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  43503. i++;
  43504. }
  43505. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  43506. }
  43507. function runBidiTransform(textChunk) {
  43508. var str = textChunk.str.join('');
  43509. var bidiResult = bidi(str, -1, textChunk.vertical);
  43510. return {
  43511. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  43512. bidiResult.str),
  43513. dir: bidiResult.dir,
  43514. width: textChunk.width,
  43515. height: textChunk.height,
  43516. transform: textChunk.transform,
  43517. fontName: textChunk.fontName
  43518. };
  43519. }
  43520. function handleSetFont(fontName, fontRef) {
  43521. return self.loadFont(fontName, fontRef, xref, resources).
  43522. then(function (translated) {
  43523. textState.font = translated.font;
  43524. textState.fontMatrix = translated.font.fontMatrix ||
  43525. FONT_IDENTITY_MATRIX;
  43526. });
  43527. }
  43528. function buildTextContentItem(chars) {
  43529. var font = textState.font;
  43530. var textChunk = ensureTextContentItem();
  43531. var width = 0;
  43532. var height = 0;
  43533. var glyphs = font.charsToGlyphs(chars);
  43534. var defaultVMetrics = font.defaultVMetrics;
  43535. for (var i = 0; i < glyphs.length; i++) {
  43536. var glyph = glyphs[i];
  43537. var vMetricX = null;
  43538. var vMetricY = null;
  43539. var glyphWidth = null;
  43540. if (font.vertical) {
  43541. if (glyph.vmetric) {
  43542. glyphWidth = glyph.vmetric[0];
  43543. vMetricX = glyph.vmetric[1];
  43544. vMetricY = glyph.vmetric[2];
  43545. } else {
  43546. glyphWidth = glyph.width;
  43547. vMetricX = glyph.width * 0.5;
  43548. vMetricY = defaultVMetrics[2];
  43549. }
  43550. } else {
  43551. glyphWidth = glyph.width;
  43552. }
  43553. var glyphUnicode = glyph.unicode;
  43554. var NormalizedUnicodes = getNormalizedUnicodes();
  43555. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  43556. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  43557. }
  43558. glyphUnicode = reverseIfRtl(glyphUnicode);
  43559. // The following will calculate the x and y of the individual glyphs.
  43560. // if (font.vertical) {
  43561. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  43562. // textState.fontMatrix[0];
  43563. // tsm[5] -= vMetricY * textState.fontSize *
  43564. // textState.fontMatrix[0];
  43565. // }
  43566. // var trm = Util.transform(textState.textMatrix, tsm);
  43567. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  43568. // var x = pt[0];
  43569. // var y = pt[1];
  43570. var charSpacing = textState.charSpacing;
  43571. if (glyph.isSpace) {
  43572. var wordSpacing = textState.wordSpacing;
  43573. charSpacing += wordSpacing;
  43574. if (wordSpacing > 0) {
  43575. addFakeSpaces(wordSpacing, textChunk.str);
  43576. }
  43577. }
  43578. var tx = 0;
  43579. var ty = 0;
  43580. if (!font.vertical) {
  43581. var w0 = glyphWidth * textState.fontMatrix[0];
  43582. tx = (w0 * textState.fontSize + charSpacing) *
  43583. textState.textHScale;
  43584. width += tx;
  43585. } else {
  43586. var w1 = glyphWidth * textState.fontMatrix[0];
  43587. ty = w1 * textState.fontSize + charSpacing;
  43588. height += ty;
  43589. }
  43590. textState.translateTextMatrix(tx, ty);
  43591. textChunk.str.push(glyphUnicode);
  43592. }
  43593. if (!font.vertical) {
  43594. textChunk.lastAdvanceWidth = width;
  43595. textChunk.width += width * textChunk.textAdvanceScale;
  43596. } else {
  43597. textChunk.lastAdvanceHeight = height;
  43598. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  43599. }
  43600. return textChunk;
  43601. }
  43602. function addFakeSpaces(width, strBuf) {
  43603. if (width < textContentItem.fakeSpaceMin) {
  43604. return;
  43605. }
  43606. if (width < textContentItem.fakeMultiSpaceMin) {
  43607. strBuf.push(' ');
  43608. return;
  43609. }
  43610. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  43611. while (fakeSpaces-- > 0) {
  43612. strBuf.push(' ');
  43613. }
  43614. }
  43615. function flushTextContentItem() {
  43616. if (!textContentItem.initialized) {
  43617. return;
  43618. }
  43619. textContent.items.push(runBidiTransform(textContentItem));
  43620. textContentItem.initialized = false;
  43621. textContentItem.str.length = 0;
  43622. }
  43623. var timeSlotManager = new TimeSlotManager();
  43624. return new Promise(function promiseBody(resolve, reject) {
  43625. var next = function (promise) {
  43626. promise.then(function () {
  43627. try {
  43628. promiseBody(resolve, reject);
  43629. } catch (ex) {
  43630. reject(ex);
  43631. }
  43632. }, reject);
  43633. };
  43634. task.ensureNotTerminated();
  43635. timeSlotManager.reset();
  43636. var stop, operation = {}, args = [];
  43637. while (!(stop = timeSlotManager.check())) {
  43638. // The arguments parsed by read() are not used beyond this loop, so
  43639. // we can reuse the same array on every iteration, thus avoiding
  43640. // unnecessary allocations.
  43641. args.length = 0;
  43642. operation.args = args;
  43643. if (!(preprocessor.read(operation))) {
  43644. break;
  43645. }
  43646. textState = stateManager.state;
  43647. var fn = operation.fn;
  43648. args = operation.args;
  43649. var advance, diff;
  43650. switch (fn | 0) {
  43651. case OPS.setFont:
  43652. // Optimization to ignore multiple identical Tf commands.
  43653. var fontNameArg = args[0].name, fontSizeArg = args[1];
  43654. if (textState.font && fontNameArg === textState.fontName &&
  43655. fontSizeArg === textState.fontSize) {
  43656. break;
  43657. }
  43658. flushTextContentItem();
  43659. textState.fontName = fontNameArg;
  43660. textState.fontSize = fontSizeArg;
  43661. next(handleSetFont(fontNameArg, null));
  43662. return;
  43663. case OPS.setTextRise:
  43664. flushTextContentItem();
  43665. textState.textRise = args[0];
  43666. break;
  43667. case OPS.setHScale:
  43668. flushTextContentItem();
  43669. textState.textHScale = args[0] / 100;
  43670. break;
  43671. case OPS.setLeading:
  43672. flushTextContentItem();
  43673. textState.leading = args[0];
  43674. break;
  43675. case OPS.moveText:
  43676. // Optimization to treat same line movement as advance
  43677. var isSameTextLine = !textState.font ? false :
  43678. ((textState.font.vertical ? args[0] : args[1]) === 0);
  43679. advance = args[0] - args[1];
  43680. if (combineTextItems &&
  43681. isSameTextLine && textContentItem.initialized &&
  43682. advance > 0 &&
  43683. advance <= textContentItem.fakeMultiSpaceMax) {
  43684. textState.translateTextLineMatrix(args[0], args[1]);
  43685. textContentItem.width +=
  43686. (args[0] - textContentItem.lastAdvanceWidth);
  43687. textContentItem.height +=
  43688. (args[1] - textContentItem.lastAdvanceHeight);
  43689. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  43690. (args[1] - textContentItem.lastAdvanceHeight);
  43691. addFakeSpaces(diff, textContentItem.str);
  43692. break;
  43693. }
  43694. flushTextContentItem();
  43695. textState.translateTextLineMatrix(args[0], args[1]);
  43696. textState.textMatrix = textState.textLineMatrix.slice();
  43697. break;
  43698. case OPS.setLeadingMoveText:
  43699. flushTextContentItem();
  43700. textState.leading = -args[1];
  43701. textState.translateTextLineMatrix(args[0], args[1]);
  43702. textState.textMatrix = textState.textLineMatrix.slice();
  43703. break;
  43704. case OPS.nextLine:
  43705. flushTextContentItem();
  43706. textState.carriageReturn();
  43707. break;
  43708. case OPS.setTextMatrix:
  43709. // Optimization to treat same line movement as advance.
  43710. advance = textState.calcTextLineMatrixAdvance(
  43711. args[0], args[1], args[2], args[3], args[4], args[5]);
  43712. if (combineTextItems &&
  43713. advance !== null && textContentItem.initialized &&
  43714. advance.value > 0 &&
  43715. advance.value <= textContentItem.fakeMultiSpaceMax) {
  43716. textState.translateTextLineMatrix(advance.width,
  43717. advance.height);
  43718. textContentItem.width +=
  43719. (advance.width - textContentItem.lastAdvanceWidth);
  43720. textContentItem.height +=
  43721. (advance.height - textContentItem.lastAdvanceHeight);
  43722. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  43723. (advance.height - textContentItem.lastAdvanceHeight);
  43724. addFakeSpaces(diff, textContentItem.str);
  43725. break;
  43726. }
  43727. flushTextContentItem();
  43728. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  43729. args[4], args[5]);
  43730. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  43731. args[4], args[5]);
  43732. break;
  43733. case OPS.setCharSpacing:
  43734. textState.charSpacing = args[0];
  43735. break;
  43736. case OPS.setWordSpacing:
  43737. textState.wordSpacing = args[0];
  43738. break;
  43739. case OPS.beginText:
  43740. flushTextContentItem();
  43741. textState.textMatrix = IDENTITY_MATRIX.slice();
  43742. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  43743. break;
  43744. case OPS.showSpacedText:
  43745. var items = args[0];
  43746. var offset;
  43747. for (var j = 0, jj = items.length; j < jj; j++) {
  43748. if (typeof items[j] === 'string') {
  43749. buildTextContentItem(items[j]);
  43750. } else {
  43751. ensureTextContentItem();
  43752. // PDF Specification 5.3.2 states:
  43753. // The number is expressed in thousandths of a unit of text
  43754. // space.
  43755. // This amount is subtracted from the current horizontal or
  43756. // vertical coordinate, depending on the writing mode.
  43757. // In the default coordinate system, a positive adjustment
  43758. // has the effect of moving the next glyph painted either to
  43759. // the left or down by the given amount.
  43760. advance = items[j] * textState.fontSize / 1000;
  43761. var breakTextRun = false;
  43762. if (textState.font.vertical) {
  43763. offset = advance *
  43764. (textState.textHScale * textState.textMatrix[2] +
  43765. textState.textMatrix[3]);
  43766. textState.translateTextMatrix(0, advance);
  43767. breakTextRun = textContentItem.textRunBreakAllowed &&
  43768. advance > textContentItem.fakeMultiSpaceMax;
  43769. if (!breakTextRun) {
  43770. // Value needs to be added to height to paint down.
  43771. textContentItem.height += offset;
  43772. }
  43773. } else {
  43774. advance = -advance;
  43775. offset = advance * (
  43776. textState.textHScale * textState.textMatrix[0] +
  43777. textState.textMatrix[1]);
  43778. textState.translateTextMatrix(advance, 0);
  43779. breakTextRun = textContentItem.textRunBreakAllowed &&
  43780. advance > textContentItem.fakeMultiSpaceMax;
  43781. if (!breakTextRun) {
  43782. // Value needs to be subtracted from width to paint left.
  43783. textContentItem.width += offset;
  43784. }
  43785. }
  43786. if (breakTextRun) {
  43787. flushTextContentItem();
  43788. } else if (advance > 0) {
  43789. addFakeSpaces(advance, textContentItem.str);
  43790. }
  43791. }
  43792. }
  43793. break;
  43794. case OPS.showText:
  43795. buildTextContentItem(args[0]);
  43796. break;
  43797. case OPS.nextLineShowText:
  43798. flushTextContentItem();
  43799. textState.carriageReturn();
  43800. buildTextContentItem(args[0]);
  43801. break;
  43802. case OPS.nextLineSetSpacingShowText:
  43803. flushTextContentItem();
  43804. textState.wordSpacing = args[0];
  43805. textState.charSpacing = args[1];
  43806. textState.carriageReturn();
  43807. buildTextContentItem(args[2]);
  43808. break;
  43809. case OPS.paintXObject:
  43810. flushTextContentItem();
  43811. if (args[0].code) {
  43812. break;
  43813. }
  43814. if (!xobjs) {
  43815. xobjs = (resources.get('XObject') || Dict.empty);
  43816. }
  43817. var name = args[0].name;
  43818. if (xobjsCache.key === name) {
  43819. if (xobjsCache.texts) {
  43820. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  43821. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  43822. }
  43823. break;
  43824. }
  43825. var xobj = xobjs.get(name);
  43826. if (!xobj) {
  43827. break;
  43828. }
  43829. assert(isStream(xobj), 'XObject should be a stream');
  43830. var type = xobj.dict.get('Subtype');
  43831. assert(isName(type), 'XObject should have a Name subtype');
  43832. if ('Form' !== type.name) {
  43833. xobjsCache.key = name;
  43834. xobjsCache.texts = null;
  43835. break;
  43836. }
  43837. stateManager.save();
  43838. var matrix = xobj.dict.getArray('Matrix');
  43839. if (isArray(matrix) && matrix.length === 6) {
  43840. stateManager.transform(matrix);
  43841. }
  43842. next(self.getTextContent(xobj, task,
  43843. xobj.dict.get('Resources') || resources, stateManager,
  43844. normalizeWhitespace, combineTextItems).then(
  43845. function (formTextContent) {
  43846. Util.appendToArray(textContent.items, formTextContent.items);
  43847. Util.extendObj(textContent.styles, formTextContent.styles);
  43848. stateManager.restore();
  43849. xobjsCache.key = name;
  43850. xobjsCache.texts = formTextContent;
  43851. }));
  43852. return;
  43853. case OPS.setGState:
  43854. flushTextContentItem();
  43855. var dictName = args[0];
  43856. var extGState = resources.get('ExtGState');
  43857. if (!isDict(extGState) || !isName(dictName)) {
  43858. break;
  43859. }
  43860. var gState = extGState.get(dictName.name);
  43861. if (!isDict(gState)) {
  43862. break;
  43863. }
  43864. var gStateFont = gState.get('Font');
  43865. if (gStateFont) {
  43866. textState.fontName = null;
  43867. textState.fontSize = gStateFont[1];
  43868. next(handleSetFont(null, gStateFont[0]));
  43869. return;
  43870. }
  43871. break;
  43872. } // switch
  43873. } // while
  43874. if (stop) {
  43875. next(deferred);
  43876. return;
  43877. }
  43878. flushTextContentItem();
  43879. resolve(textContent);
  43880. });
  43881. },
  43882. extractDataStructures:
  43883. function PartialEvaluator_extractDataStructures(dict, baseDict,
  43884. xref, properties) {
  43885. // 9.10.2
  43886. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  43887. var toUnicodePromise = toUnicode ?
  43888. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  43889. if (properties.composite) {
  43890. // CIDSystemInfo helps to match CID to glyphs
  43891. var cidSystemInfo = dict.get('CIDSystemInfo');
  43892. if (isDict(cidSystemInfo)) {
  43893. properties.cidSystemInfo = {
  43894. registry: cidSystemInfo.get('Registry'),
  43895. ordering: cidSystemInfo.get('Ordering'),
  43896. supplement: cidSystemInfo.get('Supplement')
  43897. };
  43898. }
  43899. var cidToGidMap = dict.get('CIDToGIDMap');
  43900. if (isStream(cidToGidMap)) {
  43901. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  43902. }
  43903. }
  43904. // Based on 9.6.6 of the spec the encoding can come from multiple places
  43905. // and depends on the font type. The base encoding and differences are
  43906. // read here, but the encoding that is actually used is chosen during
  43907. // glyph mapping in the font.
  43908. // TODO: Loading the built in encoding in the font would allow the
  43909. // differences to be merged in here not require us to hold on to it.
  43910. var differences = [];
  43911. var baseEncodingName = null;
  43912. var encoding;
  43913. if (dict.has('Encoding')) {
  43914. encoding = dict.get('Encoding');
  43915. if (isDict(encoding)) {
  43916. baseEncodingName = encoding.get('BaseEncoding');
  43917. baseEncodingName = (isName(baseEncodingName) ?
  43918. baseEncodingName.name : null);
  43919. // Load the differences between the base and original
  43920. if (encoding.has('Differences')) {
  43921. var diffEncoding = encoding.get('Differences');
  43922. var index = 0;
  43923. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  43924. var data = xref.fetchIfRef(diffEncoding[j]);
  43925. if (isNum(data)) {
  43926. index = data;
  43927. } else if (isName(data)) {
  43928. differences[index++] = data.name;
  43929. } else {
  43930. error('Invalid entry in \'Differences\' array: ' + data);
  43931. }
  43932. }
  43933. }
  43934. } else if (isName(encoding)) {
  43935. baseEncodingName = encoding.name;
  43936. } else {
  43937. error('Encoding is not a Name nor a Dict');
  43938. }
  43939. // According to table 114 if the encoding is a named encoding it must be
  43940. // one of these predefined encodings.
  43941. if ((baseEncodingName !== 'MacRomanEncoding' &&
  43942. baseEncodingName !== 'MacExpertEncoding' &&
  43943. baseEncodingName !== 'WinAnsiEncoding')) {
  43944. baseEncodingName = null;
  43945. }
  43946. }
  43947. if (baseEncodingName) {
  43948. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  43949. } else {
  43950. encoding = (properties.type === 'TrueType' ?
  43951. WinAnsiEncoding : StandardEncoding);
  43952. // The Symbolic attribute can be misused for regular fonts
  43953. // Heuristic: we have to check if the font is a standard one also
  43954. if (!!(properties.flags & FontFlags.Symbolic)) {
  43955. encoding = MacRomanEncoding;
  43956. if (!properties.file) {
  43957. if (/Symbol/i.test(properties.name)) {
  43958. encoding = SymbolSetEncoding;
  43959. } else if (/Dingbats/i.test(properties.name)) {
  43960. encoding = ZapfDingbatsEncoding;
  43961. }
  43962. }
  43963. }
  43964. properties.defaultEncoding = encoding;
  43965. }
  43966. properties.differences = differences;
  43967. properties.baseEncodingName = baseEncodingName;
  43968. properties.dict = dict;
  43969. return toUnicodePromise.then(function(toUnicode) {
  43970. properties.toUnicode = toUnicode;
  43971. return this.buildToUnicode(properties);
  43972. }.bind(this)).then(function (toUnicode) {
  43973. properties.toUnicode = toUnicode;
  43974. return properties;
  43975. });
  43976. },
  43977. /**
  43978. * Builds a char code to unicode map based on section 9.10 of the spec.
  43979. * @param {Object} properties Font properties object.
  43980. * @return {Promise} A Promise that is resolved with a
  43981. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  43982. */
  43983. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  43984. // Section 9.10.2 Mapping Character Codes to Unicode Values
  43985. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  43986. return Promise.resolve(properties.toUnicode);
  43987. }
  43988. // According to the spec if the font is a simple font we should only map
  43989. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  43990. // the differences array only contains adobe standard or symbol set names,
  43991. // in pratice it seems better to always try to create a toUnicode
  43992. // map based of the default encoding.
  43993. var toUnicode, charcode, glyphName;
  43994. if (!properties.composite /* is simple font */) {
  43995. toUnicode = [];
  43996. var encoding = properties.defaultEncoding.slice();
  43997. var baseEncodingName = properties.baseEncodingName;
  43998. // Merge in the differences array.
  43999. var differences = properties.differences;
  44000. for (charcode in differences) {
  44001. glyphName = differences[charcode];
  44002. if (glyphName === '.notdef') {
  44003. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  44004. // where there should be spaces (fixes issue5256.pdf).
  44005. continue;
  44006. }
  44007. encoding[charcode] = glyphName;
  44008. }
  44009. var glyphsUnicodeMap = getGlyphsUnicode();
  44010. for (charcode in encoding) {
  44011. // a) Map the character code to a character name.
  44012. glyphName = encoding[charcode];
  44013. // b) Look up the character name in the Adobe Glyph List (see the
  44014. // Bibliography) to obtain the corresponding Unicode value.
  44015. if (glyphName === '') {
  44016. continue;
  44017. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  44018. // (undocumented) c) Few heuristics to recognize unknown glyphs
  44019. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  44020. var code = 0;
  44021. switch (glyphName[0]) {
  44022. case 'G': // Gxx glyph
  44023. if (glyphName.length === 3) {
  44024. code = parseInt(glyphName.substr(1), 16);
  44025. }
  44026. break;
  44027. case 'g': // g00xx glyph
  44028. if (glyphName.length === 5) {
  44029. code = parseInt(glyphName.substr(1), 16);
  44030. }
  44031. break;
  44032. case 'C': // Cddd glyph
  44033. case 'c': // cddd glyph
  44034. if (glyphName.length >= 3) {
  44035. code = +glyphName.substr(1);
  44036. }
  44037. break;
  44038. default:
  44039. // 'uniXXXX'/'uXXXX{XX}' glyphs
  44040. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  44041. if (unicode !== -1) {
  44042. code = unicode;
  44043. }
  44044. }
  44045. if (code) {
  44046. // If |baseEncodingName| is one the predefined encodings,
  44047. // and |code| equals |charcode|, using the glyph defined in the
  44048. // baseEncoding seems to yield a better |toUnicode| mapping
  44049. // (fixes issue 5070).
  44050. if (baseEncodingName && code === +charcode) {
  44051. var baseEncoding = getEncoding(baseEncodingName);
  44052. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  44053. toUnicode[charcode] =
  44054. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44055. continue;
  44056. }
  44057. }
  44058. toUnicode[charcode] = String.fromCharCode(code);
  44059. }
  44060. continue;
  44061. }
  44062. toUnicode[charcode] =
  44063. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44064. }
  44065. return Promise.resolve(new ToUnicodeMap(toUnicode));
  44066. }
  44067. // If the font is a composite font that uses one of the predefined CMaps
  44068. // listed in Table 118 (except Identity–H and Identity–V) or whose
  44069. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  44070. // Adobe-Korea1 character collection:
  44071. if (properties.composite && (
  44072. (properties.cMap.builtInCMap &&
  44073. !(properties.cMap instanceof IdentityCMap)) ||
  44074. (properties.cidSystemInfo.registry === 'Adobe' &&
  44075. (properties.cidSystemInfo.ordering === 'GB1' ||
  44076. properties.cidSystemInfo.ordering === 'CNS1' ||
  44077. properties.cidSystemInfo.ordering === 'Japan1' ||
  44078. properties.cidSystemInfo.ordering === 'Korea1')))) {
  44079. // Then:
  44080. // a) Map the character code to a character identifier (CID) according
  44081. // to the font’s CMap.
  44082. // b) Obtain the registry and ordering of the character collection used
  44083. // by the font’s CMap (for example, Adobe and Japan1) from its
  44084. // CIDSystemInfo dictionary.
  44085. var registry = properties.cidSystemInfo.registry;
  44086. var ordering = properties.cidSystemInfo.ordering;
  44087. // c) Construct a second CMap name by concatenating the registry and
  44088. // ordering obtained in step (b) in the format registry–ordering–UCS2
  44089. // (for example, Adobe–Japan1–UCS2).
  44090. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  44091. // d) Obtain the CMap with the name constructed in step (c) (available
  44092. // from the ASN Web site; see the Bibliography).
  44093. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  44094. null).then(
  44095. function (ucs2CMap) {
  44096. var cMap = properties.cMap;
  44097. toUnicode = [];
  44098. cMap.forEach(function(charcode, cid) {
  44099. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  44100. // e) Map the CID obtained in step (a) according to the CMap
  44101. // obtained in step (d), producing a Unicode value.
  44102. var ucs2 = ucs2CMap.lookup(cid);
  44103. if (ucs2) {
  44104. toUnicode[charcode] =
  44105. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  44106. ucs2.charCodeAt(1));
  44107. }
  44108. });
  44109. return new ToUnicodeMap(toUnicode);
  44110. });
  44111. }
  44112. // The viewer's choice, just use an identity map.
  44113. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  44114. properties.lastChar));
  44115. },
  44116. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  44117. var cmapObj = toUnicode;
  44118. if (isName(cmapObj)) {
  44119. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44120. function (cmap) {
  44121. if (cmap instanceof IdentityCMap) {
  44122. return new IdentityToUnicodeMap(0, 0xFFFF);
  44123. }
  44124. return new ToUnicodeMap(cmap.getMap());
  44125. });
  44126. } else if (isStream(cmapObj)) {
  44127. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44128. function (cmap) {
  44129. if (cmap instanceof IdentityCMap) {
  44130. return new IdentityToUnicodeMap(0, 0xFFFF);
  44131. }
  44132. var map = new Array(cmap.length);
  44133. // Convert UTF-16BE
  44134. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  44135. // to iterate over all keys.
  44136. cmap.forEach(function(charCode, token) {
  44137. var str = [];
  44138. for (var k = 0; k < token.length; k += 2) {
  44139. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44140. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  44141. str.push(w1);
  44142. continue;
  44143. }
  44144. k += 2;
  44145. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44146. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  44147. }
  44148. map[charCode] = String.fromCharCode.apply(String, str);
  44149. });
  44150. return new ToUnicodeMap(map);
  44151. });
  44152. }
  44153. return Promise.resolve(null);
  44154. },
  44155. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  44156. // Extract the encoding from the CIDToGIDMap
  44157. var glyphsData = cidToGidStream.getBytes();
  44158. // Set encoding 0 to later verify the font has an encoding
  44159. var result = [];
  44160. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  44161. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  44162. if (glyphID === 0) {
  44163. continue;
  44164. }
  44165. var code = j >> 1;
  44166. result[code] = glyphID;
  44167. }
  44168. return result;
  44169. },
  44170. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  44171. descriptor,
  44172. properties) {
  44173. var glyphsWidths = [];
  44174. var defaultWidth = 0;
  44175. var glyphsVMetrics = [];
  44176. var defaultVMetrics;
  44177. var i, ii, j, jj, start, code, widths;
  44178. if (properties.composite) {
  44179. defaultWidth = dict.get('DW') || 1000;
  44180. widths = dict.get('W');
  44181. if (widths) {
  44182. for (i = 0, ii = widths.length; i < ii; i++) {
  44183. start = widths[i++];
  44184. code = xref.fetchIfRef(widths[i]);
  44185. if (isArray(code)) {
  44186. for (j = 0, jj = code.length; j < jj; j++) {
  44187. glyphsWidths[start++] = code[j];
  44188. }
  44189. } else {
  44190. var width = widths[++i];
  44191. for (j = start; j <= code; j++) {
  44192. glyphsWidths[j] = width;
  44193. }
  44194. }
  44195. }
  44196. }
  44197. if (properties.vertical) {
  44198. var vmetrics = (dict.get('DW2') || [880, -1000]);
  44199. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  44200. vmetrics = dict.get('W2');
  44201. if (vmetrics) {
  44202. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  44203. start = vmetrics[i++];
  44204. code = xref.fetchIfRef(vmetrics[i]);
  44205. if (isArray(code)) {
  44206. for (j = 0, jj = code.length; j < jj; j++) {
  44207. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  44208. }
  44209. } else {
  44210. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  44211. for (j = start; j <= code; j++) {
  44212. glyphsVMetrics[j] = vmetric;
  44213. }
  44214. }
  44215. }
  44216. }
  44217. }
  44218. } else {
  44219. var firstChar = properties.firstChar;
  44220. widths = dict.get('Widths');
  44221. if (widths) {
  44222. j = firstChar;
  44223. for (i = 0, ii = widths.length; i < ii; i++) {
  44224. glyphsWidths[j++] = widths[i];
  44225. }
  44226. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  44227. } else {
  44228. // Trying get the BaseFont metrics (see comment above).
  44229. var baseFontName = dict.get('BaseFont');
  44230. if (isName(baseFontName)) {
  44231. var metrics = this.getBaseFontMetrics(baseFontName.name);
  44232. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  44233. properties);
  44234. defaultWidth = metrics.defaultWidth;
  44235. }
  44236. }
  44237. }
  44238. // Heuristic: detection of monospace font by checking all non-zero widths
  44239. var isMonospace = true;
  44240. var firstWidth = defaultWidth;
  44241. for (var glyph in glyphsWidths) {
  44242. var glyphWidth = glyphsWidths[glyph];
  44243. if (!glyphWidth) {
  44244. continue;
  44245. }
  44246. if (!firstWidth) {
  44247. firstWidth = glyphWidth;
  44248. continue;
  44249. }
  44250. if (firstWidth !== glyphWidth) {
  44251. isMonospace = false;
  44252. break;
  44253. }
  44254. }
  44255. if (isMonospace) {
  44256. properties.flags |= FontFlags.FixedPitch;
  44257. }
  44258. properties.defaultWidth = defaultWidth;
  44259. properties.widths = glyphsWidths;
  44260. properties.defaultVMetrics = defaultVMetrics;
  44261. properties.vmetrics = glyphsVMetrics;
  44262. },
  44263. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  44264. // Simulating descriptor flags attribute
  44265. var fontNameWoStyle = baseFontName.split('-')[0];
  44266. return (fontNameWoStyle in getSerifFonts()) ||
  44267. (fontNameWoStyle.search(/serif/gi) !== -1);
  44268. },
  44269. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  44270. var defaultWidth = 0;
  44271. var widths = [];
  44272. var monospace = false;
  44273. var stdFontMap = getStdFontMap();
  44274. var lookupName = (stdFontMap[name] || name);
  44275. var Metrics = getMetrics();
  44276. if (!(lookupName in Metrics)) {
  44277. // Use default fonts for looking up font metrics if the passed
  44278. // font is not a base font
  44279. if (this.isSerifFont(name)) {
  44280. lookupName = 'Times-Roman';
  44281. } else {
  44282. lookupName = 'Helvetica';
  44283. }
  44284. }
  44285. var glyphWidths = Metrics[lookupName];
  44286. if (isNum(glyphWidths)) {
  44287. defaultWidth = glyphWidths;
  44288. monospace = true;
  44289. } else {
  44290. widths = glyphWidths(); // expand lazy widths array
  44291. }
  44292. return {
  44293. defaultWidth: defaultWidth,
  44294. monospace: monospace,
  44295. widths: widths
  44296. };
  44297. },
  44298. buildCharCodeToWidth:
  44299. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  44300. properties) {
  44301. var widths = Object.create(null);
  44302. var differences = properties.differences;
  44303. var encoding = properties.defaultEncoding;
  44304. for (var charCode = 0; charCode < 256; charCode++) {
  44305. if (charCode in differences &&
  44306. widthsByGlyphName[differences[charCode]]) {
  44307. widths[charCode] = widthsByGlyphName[differences[charCode]];
  44308. continue;
  44309. }
  44310. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  44311. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  44312. continue;
  44313. }
  44314. }
  44315. return widths;
  44316. },
  44317. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  44318. var baseDict = dict;
  44319. var type = dict.get('Subtype');
  44320. assert(isName(type), 'invalid font Subtype');
  44321. var composite = false;
  44322. var uint8array;
  44323. if (type.name === 'Type0') {
  44324. // If font is a composite
  44325. // - get the descendant font
  44326. // - set the type according to the descendant font
  44327. // - get the FontDescriptor from the descendant font
  44328. var df = dict.get('DescendantFonts');
  44329. if (!df) {
  44330. error('Descendant fonts are not specified');
  44331. }
  44332. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  44333. type = dict.get('Subtype');
  44334. assert(isName(type), 'invalid font Subtype');
  44335. composite = true;
  44336. }
  44337. var descriptor = dict.get('FontDescriptor');
  44338. if (descriptor) {
  44339. var hash = new MurmurHash3_64();
  44340. var encoding = baseDict.getRaw('Encoding');
  44341. if (isName(encoding)) {
  44342. hash.update(encoding.name);
  44343. } else if (isRef(encoding)) {
  44344. hash.update(encoding.toString());
  44345. } else if (isDict(encoding)) {
  44346. var keys = encoding.getKeys();
  44347. for (var i = 0, ii = keys.length; i < ii; i++) {
  44348. var entry = encoding.getRaw(keys[i]);
  44349. if (isName(entry)) {
  44350. hash.update(entry.name);
  44351. } else if (isRef(entry)) {
  44352. hash.update(entry.toString());
  44353. } else if (isArray(entry)) { // 'Differences' entry.
  44354. // Ideally we should check the contents of the array, but to avoid
  44355. // parsing it here and then again in |extractDataStructures|,
  44356. // we only use the array length for now (fixes bug1157493.pdf).
  44357. hash.update(entry.length.toString());
  44358. }
  44359. }
  44360. }
  44361. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  44362. if (isStream(toUnicode)) {
  44363. var stream = toUnicode.str || toUnicode;
  44364. uint8array = stream.buffer ?
  44365. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  44366. new Uint8Array(stream.bytes.buffer,
  44367. stream.start, stream.end - stream.start);
  44368. hash.update(uint8array);
  44369. } else if (isName(toUnicode)) {
  44370. hash.update(toUnicode.name);
  44371. }
  44372. var widths = dict.get('Widths') || baseDict.get('Widths');
  44373. if (widths) {
  44374. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  44375. hash.update(uint8array);
  44376. }
  44377. }
  44378. return {
  44379. descriptor: descriptor,
  44380. dict: dict,
  44381. baseDict: baseDict,
  44382. composite: composite,
  44383. type: type.name,
  44384. hash: hash ? hash.hexdigest() : ''
  44385. };
  44386. },
  44387. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  44388. xref) {
  44389. var baseDict = preEvaluatedFont.baseDict;
  44390. var dict = preEvaluatedFont.dict;
  44391. var composite = preEvaluatedFont.composite;
  44392. var descriptor = preEvaluatedFont.descriptor;
  44393. var type = preEvaluatedFont.type;
  44394. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  44395. var cMapOptions = this.options.cMapOptions;
  44396. var properties;
  44397. if (!descriptor) {
  44398. if (type === 'Type3') {
  44399. // FontDescriptor is only required for Type3 fonts when the document
  44400. // is a tagged pdf. Create a barbebones one to get by.
  44401. descriptor = new Dict(null);
  44402. descriptor.set('FontName', Name.get(type));
  44403. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  44404. } else {
  44405. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  44406. // FontDescriptor was not required.
  44407. // This case is here for compatibility.
  44408. var baseFontName = dict.get('BaseFont');
  44409. if (!isName(baseFontName)) {
  44410. error('Base font is not specified');
  44411. }
  44412. // Using base font name as a font name.
  44413. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  44414. var metrics = this.getBaseFontMetrics(baseFontName);
  44415. // Simulating descriptor flags attribute
  44416. var fontNameWoStyle = baseFontName.split('-')[0];
  44417. var flags =
  44418. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  44419. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  44420. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  44421. FontFlags.Nonsymbolic);
  44422. properties = {
  44423. type: type,
  44424. name: baseFontName,
  44425. widths: metrics.widths,
  44426. defaultWidth: metrics.defaultWidth,
  44427. flags: flags,
  44428. firstChar: 0,
  44429. lastChar: maxCharIndex
  44430. };
  44431. return this.extractDataStructures(dict, dict, xref, properties).then(
  44432. function (properties) {
  44433. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  44434. properties);
  44435. return new Font(baseFontName, null, properties);
  44436. }.bind(this));
  44437. }
  44438. }
  44439. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  44440. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  44441. // to ignore this rule when a variant of a standard font is used.
  44442. // TODO Fill the width array depending on which of the base font this is
  44443. // a variant.
  44444. var firstChar = (dict.get('FirstChar') || 0);
  44445. var lastChar = (dict.get('LastChar') || maxCharIndex);
  44446. var fontName = descriptor.get('FontName');
  44447. var baseFont = dict.get('BaseFont');
  44448. // Some bad PDFs have a string as the font name.
  44449. if (isString(fontName)) {
  44450. fontName = Name.get(fontName);
  44451. }
  44452. if (isString(baseFont)) {
  44453. baseFont = Name.get(baseFont);
  44454. }
  44455. if (type !== 'Type3') {
  44456. var fontNameStr = fontName && fontName.name;
  44457. var baseFontStr = baseFont && baseFont.name;
  44458. if (fontNameStr !== baseFontStr) {
  44459. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  44460. '" but should be the same as the Font\'s BaseFont "' +
  44461. baseFontStr + '"');
  44462. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  44463. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  44464. if (fontNameStr && baseFontStr &&
  44465. baseFontStr.indexOf(fontNameStr) === 0) {
  44466. fontName = baseFont;
  44467. }
  44468. }
  44469. }
  44470. fontName = (fontName || baseFont);
  44471. assert(isName(fontName), 'invalid font name');
  44472. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  44473. if (fontFile) {
  44474. if (fontFile.dict) {
  44475. var subtype = fontFile.dict.get('Subtype');
  44476. if (subtype) {
  44477. subtype = subtype.name;
  44478. }
  44479. var length1 = fontFile.dict.get('Length1');
  44480. var length2 = fontFile.dict.get('Length2');
  44481. var length3 = fontFile.dict.get('Length3');
  44482. }
  44483. }
  44484. properties = {
  44485. type: type,
  44486. name: fontName.name,
  44487. subtype: subtype,
  44488. file: fontFile,
  44489. length1: length1,
  44490. length2: length2,
  44491. length3: length3,
  44492. loadedName: baseDict.loadedName,
  44493. composite: composite,
  44494. wideChars: composite,
  44495. fixedPitch: false,
  44496. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  44497. firstChar: firstChar || 0,
  44498. lastChar: (lastChar || maxCharIndex),
  44499. bbox: descriptor.getArray('FontBBox'),
  44500. ascent: descriptor.get('Ascent'),
  44501. descent: descriptor.get('Descent'),
  44502. xHeight: descriptor.get('XHeight'),
  44503. capHeight: descriptor.get('CapHeight'),
  44504. flags: descriptor.get('Flags'),
  44505. italicAngle: descriptor.get('ItalicAngle'),
  44506. coded: false
  44507. };
  44508. var cMapPromise;
  44509. if (composite) {
  44510. var cidEncoding = baseDict.get('Encoding');
  44511. if (isName(cidEncoding)) {
  44512. properties.cidEncoding = cidEncoding.name;
  44513. }
  44514. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  44515. function (cMap) {
  44516. properties.cMap = cMap;
  44517. properties.vertical = properties.cMap.vertical;
  44518. });
  44519. } else {
  44520. cMapPromise = Promise.resolve(undefined);
  44521. }
  44522. return cMapPromise.then(function () {
  44523. return this.extractDataStructures(dict, baseDict, xref, properties);
  44524. }.bind(this)).then(function (properties) {
  44525. this.extractWidths(dict, xref, descriptor, properties);
  44526. if (type === 'Type3') {
  44527. properties.isType3Font = true;
  44528. }
  44529. return new Font(fontName.name, fontFile, properties);
  44530. }.bind(this));
  44531. }
  44532. };
  44533. return PartialEvaluator;
  44534. })();
  44535. var TranslatedFont = (function TranslatedFontClosure() {
  44536. function TranslatedFont(loadedName, font, dict) {
  44537. this.loadedName = loadedName;
  44538. this.font = font;
  44539. this.dict = dict;
  44540. this.type3Loaded = null;
  44541. this.sent = false;
  44542. }
  44543. TranslatedFont.prototype = {
  44544. send: function (handler) {
  44545. if (this.sent) {
  44546. return;
  44547. }
  44548. var fontData = this.font.exportData();
  44549. handler.send('commonobj', [
  44550. this.loadedName,
  44551. 'Font',
  44552. fontData
  44553. ]);
  44554. this.sent = true;
  44555. },
  44556. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  44557. assert(this.font.isType3Font);
  44558. if (this.type3Loaded) {
  44559. return this.type3Loaded;
  44560. }
  44561. var translatedFont = this.font;
  44562. var loadCharProcsPromise = Promise.resolve();
  44563. var charProcs = this.dict.get('CharProcs');
  44564. var fontResources = this.dict.get('Resources') || resources;
  44565. var charProcKeys = charProcs.getKeys();
  44566. var charProcOperatorList = Object.create(null);
  44567. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  44568. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  44569. var glyphStream = charProcs.get(key);
  44570. var operatorList = new OperatorList();
  44571. return evaluator.getOperatorList(glyphStream, task, fontResources,
  44572. operatorList).then(function () {
  44573. charProcOperatorList[key] = operatorList.getIR();
  44574. // Add the dependencies to the parent operator list so they are
  44575. // resolved before sub operator list is executed synchronously.
  44576. parentOperatorList.addDependencies(operatorList.dependencies);
  44577. }, function (reason) {
  44578. warn('Type3 font resource \"' + key + '\" is not available');
  44579. var operatorList = new OperatorList();
  44580. charProcOperatorList[key] = operatorList.getIR();
  44581. });
  44582. }.bind(this, charProcKeys[i]));
  44583. }
  44584. this.type3Loaded = loadCharProcsPromise.then(function () {
  44585. translatedFont.charProcOperatorList = charProcOperatorList;
  44586. });
  44587. return this.type3Loaded;
  44588. }
  44589. };
  44590. return TranslatedFont;
  44591. })();
  44592. var OperatorList = (function OperatorListClosure() {
  44593. var CHUNK_SIZE = 1000;
  44594. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  44595. function getTransfers(queue) {
  44596. var transfers = [];
  44597. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44598. for (var i = 0, ii = queue.length; i < ii; i++) {
  44599. switch (fnArray[i]) {
  44600. case OPS.paintInlineImageXObject:
  44601. case OPS.paintInlineImageXObjectGroup:
  44602. case OPS.paintImageMaskXObject:
  44603. var arg = argsArray[i][0]; // first param in imgData
  44604. if (!arg.cached) {
  44605. transfers.push(arg.data.buffer);
  44606. }
  44607. break;
  44608. }
  44609. }
  44610. return transfers;
  44611. }
  44612. function OperatorList(intent, messageHandler, pageIndex) {
  44613. this.messageHandler = messageHandler;
  44614. this.fnArray = [];
  44615. this.argsArray = [];
  44616. this.dependencies = Object.create(null);
  44617. this._totalLength = 0;
  44618. this.pageIndex = pageIndex;
  44619. this.intent = intent;
  44620. }
  44621. OperatorList.prototype = {
  44622. get length() {
  44623. return this.argsArray.length;
  44624. },
  44625. /**
  44626. * @returns {number} The total length of the entire operator list,
  44627. * since `this.length === 0` after flushing.
  44628. */
  44629. get totalLength() {
  44630. return (this._totalLength + this.length);
  44631. },
  44632. addOp: function(fn, args) {
  44633. this.fnArray.push(fn);
  44634. this.argsArray.push(args);
  44635. if (this.messageHandler) {
  44636. if (this.fnArray.length >= CHUNK_SIZE) {
  44637. this.flush();
  44638. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  44639. (fn === OPS.restore || fn === OPS.endText)) {
  44640. // heuristic to flush on boundary of restore or endText
  44641. this.flush();
  44642. }
  44643. }
  44644. },
  44645. addDependency: function(dependency) {
  44646. if (dependency in this.dependencies) {
  44647. return;
  44648. }
  44649. this.dependencies[dependency] = true;
  44650. this.addOp(OPS.dependency, [dependency]);
  44651. },
  44652. addDependencies: function(dependencies) {
  44653. for (var key in dependencies) {
  44654. this.addDependency(key);
  44655. }
  44656. },
  44657. addOpList: function(opList) {
  44658. Util.extendObj(this.dependencies, opList.dependencies);
  44659. for (var i = 0, ii = opList.length; i < ii; i++) {
  44660. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  44661. }
  44662. },
  44663. getIR: function() {
  44664. return {
  44665. fnArray: this.fnArray,
  44666. argsArray: this.argsArray,
  44667. length: this.length
  44668. };
  44669. },
  44670. flush: function(lastChunk) {
  44671. if (this.intent !== 'oplist') {
  44672. new QueueOptimizer().optimize(this);
  44673. }
  44674. var transfers = getTransfers(this);
  44675. var length = this.length;
  44676. this._totalLength += length;
  44677. this.messageHandler.send('RenderPageChunk', {
  44678. operatorList: {
  44679. fnArray: this.fnArray,
  44680. argsArray: this.argsArray,
  44681. lastChunk: lastChunk,
  44682. length: length
  44683. },
  44684. pageIndex: this.pageIndex,
  44685. intent: this.intent
  44686. }, transfers);
  44687. this.dependencies = Object.create(null);
  44688. this.fnArray.length = 0;
  44689. this.argsArray.length = 0;
  44690. }
  44691. };
  44692. return OperatorList;
  44693. })();
  44694. var StateManager = (function StateManagerClosure() {
  44695. function StateManager(initialState) {
  44696. this.state = initialState;
  44697. this.stateStack = [];
  44698. }
  44699. StateManager.prototype = {
  44700. save: function () {
  44701. var old = this.state;
  44702. this.stateStack.push(this.state);
  44703. this.state = old.clone();
  44704. },
  44705. restore: function () {
  44706. var prev = this.stateStack.pop();
  44707. if (prev) {
  44708. this.state = prev;
  44709. }
  44710. },
  44711. transform: function (args) {
  44712. this.state.ctm = Util.transform(this.state.ctm, args);
  44713. }
  44714. };
  44715. return StateManager;
  44716. })();
  44717. var TextState = (function TextStateClosure() {
  44718. function TextState() {
  44719. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44720. this.fontName = null;
  44721. this.fontSize = 0;
  44722. this.font = null;
  44723. this.fontMatrix = FONT_IDENTITY_MATRIX;
  44724. this.textMatrix = IDENTITY_MATRIX.slice();
  44725. this.textLineMatrix = IDENTITY_MATRIX.slice();
  44726. this.charSpacing = 0;
  44727. this.wordSpacing = 0;
  44728. this.leading = 0;
  44729. this.textHScale = 1;
  44730. this.textRise = 0;
  44731. }
  44732. TextState.prototype = {
  44733. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  44734. var m = this.textMatrix;
  44735. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  44736. },
  44737. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  44738. var m = this.textLineMatrix;
  44739. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  44740. },
  44741. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  44742. var m = this.textMatrix;
  44743. m[4] = m[0] * x + m[2] * y + m[4];
  44744. m[5] = m[1] * x + m[3] * y + m[5];
  44745. },
  44746. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  44747. var m = this.textLineMatrix;
  44748. m[4] = m[0] * x + m[2] * y + m[4];
  44749. m[5] = m[1] * x + m[3] * y + m[5];
  44750. },
  44751. calcTextLineMatrixAdvance:
  44752. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  44753. var font = this.font;
  44754. if (!font) {
  44755. return null;
  44756. }
  44757. var m = this.textLineMatrix;
  44758. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  44759. return null;
  44760. }
  44761. var txDiff = e - m[4], tyDiff = f - m[5];
  44762. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  44763. return null;
  44764. }
  44765. var tx, ty, denominator = a * d - b * c;
  44766. if (font.vertical) {
  44767. tx = -tyDiff * c / denominator;
  44768. ty = tyDiff * a / denominator;
  44769. } else {
  44770. tx = txDiff * d / denominator;
  44771. ty = -txDiff * b / denominator;
  44772. }
  44773. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  44774. },
  44775. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  44776. // 9.4.4 Text Space Details
  44777. var tsm = [this.fontSize * this.textHScale, 0,
  44778. 0, this.fontSize,
  44779. 0, this.textRise];
  44780. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  44781. },
  44782. carriageReturn: function TextState_carriageReturn() {
  44783. this.translateTextLineMatrix(0, -this.leading);
  44784. this.textMatrix = this.textLineMatrix.slice();
  44785. },
  44786. clone: function TextState_clone() {
  44787. var clone = Object.create(this);
  44788. clone.textMatrix = this.textMatrix.slice();
  44789. clone.textLineMatrix = this.textLineMatrix.slice();
  44790. clone.fontMatrix = this.fontMatrix.slice();
  44791. return clone;
  44792. }
  44793. };
  44794. return TextState;
  44795. })();
  44796. var EvalState = (function EvalStateClosure() {
  44797. function EvalState() {
  44798. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44799. this.font = null;
  44800. this.textRenderingMode = TextRenderingMode.FILL;
  44801. this.fillColorSpace = ColorSpace.singletons.gray;
  44802. this.strokeColorSpace = ColorSpace.singletons.gray;
  44803. }
  44804. EvalState.prototype = {
  44805. clone: function CanvasExtraState_clone() {
  44806. return Object.create(this);
  44807. },
  44808. };
  44809. return EvalState;
  44810. })();
  44811. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  44812. // Specifies properties for each command
  44813. //
  44814. // If variableArgs === true: [0, `numArgs`] expected
  44815. // If variableArgs === false: exactly `numArgs` expected
  44816. var getOPMap = getLookupTableFactory(function (t) {
  44817. // Graphic state
  44818. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  44819. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  44820. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  44821. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  44822. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  44823. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  44824. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  44825. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  44826. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  44827. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  44828. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  44829. // Path
  44830. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  44831. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  44832. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  44833. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  44834. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  44835. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  44836. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  44837. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  44838. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  44839. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  44840. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  44841. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  44842. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  44843. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  44844. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  44845. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  44846. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  44847. // Clipping
  44848. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  44849. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  44850. // Text
  44851. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  44852. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  44853. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  44854. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  44855. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  44856. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  44857. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  44858. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  44859. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  44860. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  44861. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  44862. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  44863. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  44864. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  44865. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  44866. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  44867. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  44868. variableArgs: false };
  44869. // Type3 fonts
  44870. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  44871. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  44872. variableArgs: false };
  44873. // Color
  44874. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  44875. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  44876. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  44877. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  44878. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  44879. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  44880. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  44881. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  44882. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  44883. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  44884. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  44885. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  44886. // Shading
  44887. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  44888. // Images
  44889. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  44890. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  44891. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  44892. // XObjects
  44893. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  44894. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  44895. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  44896. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  44897. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  44898. variableArgs: false };
  44899. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  44900. // Compatibility
  44901. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  44902. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  44903. // (reserved partial commands for the lexer)
  44904. t['BM'] = null;
  44905. t['BD'] = null;
  44906. t['true'] = null;
  44907. t['fa'] = null;
  44908. t['fal'] = null;
  44909. t['fals'] = null;
  44910. t['false'] = null;
  44911. t['nu'] = null;
  44912. t['nul'] = null;
  44913. t['null'] = null;
  44914. });
  44915. function EvaluatorPreprocessor(stream, xref, stateManager) {
  44916. this.opMap = getOPMap();
  44917. // TODO(mduan): pass array of knownCommands rather than this.opMap
  44918. // dictionary
  44919. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  44920. this.stateManager = stateManager;
  44921. this.nonProcessedArgs = [];
  44922. }
  44923. EvaluatorPreprocessor.prototype = {
  44924. get savedStatesDepth() {
  44925. return this.stateManager.stateStack.length;
  44926. },
  44927. // |operation| is an object with two fields:
  44928. //
  44929. // - |fn| is an out param.
  44930. //
  44931. // - |args| is an inout param. On entry, it should have one of two values.
  44932. //
  44933. // - An empty array. This indicates that the caller is providing the
  44934. // array in which the args will be stored in. The caller should use
  44935. // this value if it can reuse a single array for each call to read().
  44936. //
  44937. // - |null|. This indicates that the caller needs this function to create
  44938. // the array in which any args are stored in. If there are zero args,
  44939. // this function will leave |operation.args| as |null| (thus avoiding
  44940. // allocations that would occur if we used an empty array to represent
  44941. // zero arguments). Otherwise, it will replace |null| with a new array
  44942. // containing the arguments. The caller should use this value if it
  44943. // cannot reuse an array for each call to read().
  44944. //
  44945. // These two modes are present because this function is very hot and so
  44946. // avoiding allocations where possible is worthwhile.
  44947. //
  44948. read: function EvaluatorPreprocessor_read(operation) {
  44949. var args = operation.args;
  44950. while (true) {
  44951. var obj = this.parser.getObj();
  44952. if (isCmd(obj)) {
  44953. var cmd = obj.cmd;
  44954. // Check that the command is valid
  44955. var opSpec = this.opMap[cmd];
  44956. if (!opSpec) {
  44957. warn('Unknown command "' + cmd + '"');
  44958. continue;
  44959. }
  44960. var fn = opSpec.id;
  44961. var numArgs = opSpec.numArgs;
  44962. var argsLength = args !== null ? args.length : 0;
  44963. if (!opSpec.variableArgs) {
  44964. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  44965. if (argsLength !== numArgs) {
  44966. var nonProcessedArgs = this.nonProcessedArgs;
  44967. while (argsLength > numArgs) {
  44968. nonProcessedArgs.push(args.shift());
  44969. argsLength--;
  44970. }
  44971. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  44972. if (!args) {
  44973. args = [];
  44974. }
  44975. args.unshift(nonProcessedArgs.pop());
  44976. argsLength++;
  44977. }
  44978. }
  44979. if (argsLength < numArgs) {
  44980. // If we receive too few args, it's not possible to possible
  44981. // to execute the command, so skip the command
  44982. info('Command ' + fn + ': because expected ' +
  44983. numArgs + ' args, but received ' + argsLength +
  44984. ' args; skipping');
  44985. args = null;
  44986. continue;
  44987. }
  44988. } else if (argsLength > numArgs) {
  44989. info('Command ' + fn + ': expected [0,' + numArgs +
  44990. '] args, but received ' + argsLength + ' args');
  44991. }
  44992. // TODO figure out how to type-check vararg functions
  44993. this.preprocessCommand(fn, args);
  44994. operation.fn = fn;
  44995. operation.args = args;
  44996. return true;
  44997. } else {
  44998. if (isEOF(obj)) {
  44999. return false; // no more commands
  45000. }
  45001. // argument
  45002. if (obj !== null) {
  45003. if (!args) {
  45004. args = [];
  45005. }
  45006. args.push(obj);
  45007. assert(args.length <= 33, 'Too many arguments');
  45008. }
  45009. }
  45010. }
  45011. },
  45012. preprocessCommand:
  45013. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  45014. switch (fn | 0) {
  45015. case OPS.save:
  45016. this.stateManager.save();
  45017. break;
  45018. case OPS.restore:
  45019. this.stateManager.restore();
  45020. break;
  45021. case OPS.transform:
  45022. this.stateManager.transform(args);
  45023. break;
  45024. }
  45025. }
  45026. };
  45027. return EvaluatorPreprocessor;
  45028. })();
  45029. var QueueOptimizer = (function QueueOptimizerClosure() {
  45030. function addState(parentState, pattern, fn) {
  45031. var state = parentState;
  45032. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  45033. var item = pattern[i];
  45034. state = (state[item] || (state[item] = []));
  45035. }
  45036. state[pattern[pattern.length - 1]] = fn;
  45037. }
  45038. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45039. argsArray) {
  45040. // Handles special case of mainly LaTeX documents which use image masks to
  45041. // draw lines with the current fill style.
  45042. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  45043. // have been found at iFirstSave.
  45044. var iFirstPIMXO = iFirstSave + 2;
  45045. for (var i = 0; i < count; i++) {
  45046. var arg = argsArray[iFirstPIMXO + 4 * i];
  45047. var imageMask = arg.length === 1 && arg[0];
  45048. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  45049. (!imageMask.data.length ||
  45050. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  45051. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  45052. continue;
  45053. }
  45054. break;
  45055. }
  45056. return count - i;
  45057. }
  45058. var InitialState = [];
  45059. // This replaces (save, transform, paintInlineImageXObject, restore)+
  45060. // sequences with one |paintInlineImageXObjectGroup| operation.
  45061. addState(InitialState,
  45062. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  45063. function foundInlineImageGroup(context) {
  45064. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  45065. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  45066. var MAX_WIDTH = 1000;
  45067. var IMAGE_PADDING = 1;
  45068. var fnArray = context.fnArray, argsArray = context.argsArray;
  45069. var curr = context.iCurr;
  45070. var iFirstSave = curr - 3;
  45071. var iFirstTransform = curr - 2;
  45072. var iFirstPIIXO = curr - 1;
  45073. // Look for the quartets.
  45074. var i = iFirstSave + 4;
  45075. var ii = fnArray.length;
  45076. while (i + 3 < ii) {
  45077. if (fnArray[i] !== OPS.save ||
  45078. fnArray[i + 1] !== OPS.transform ||
  45079. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  45080. fnArray[i + 3] !== OPS.restore) {
  45081. break; // ops don't match
  45082. }
  45083. i += 4;
  45084. }
  45085. // At this point, i is the index of the first op past the last valid
  45086. // quartet.
  45087. var count = Math.min((i - iFirstSave) / 4,
  45088. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  45089. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  45090. return i;
  45091. }
  45092. // assuming that heights of those image is too small (~1 pixel)
  45093. // packing as much as possible by lines
  45094. var maxX = 0;
  45095. var map = [], maxLineHeight = 0;
  45096. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  45097. var q;
  45098. for (q = 0; q < count; q++) {
  45099. var transform = argsArray[iFirstTransform + (q << 2)];
  45100. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  45101. if (currentX + img.width > MAX_WIDTH) {
  45102. // starting new line
  45103. maxX = Math.max(maxX, currentX);
  45104. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  45105. currentX = 0;
  45106. maxLineHeight = 0;
  45107. }
  45108. map.push({
  45109. transform: transform,
  45110. x: currentX, y: currentY,
  45111. w: img.width, h: img.height
  45112. });
  45113. currentX += img.width + 2 * IMAGE_PADDING;
  45114. maxLineHeight = Math.max(maxLineHeight, img.height);
  45115. }
  45116. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  45117. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  45118. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  45119. var imgRowSize = imgWidth << 2;
  45120. for (q = 0; q < count; q++) {
  45121. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  45122. // Copy image by lines and extends pixels into padding.
  45123. var rowSize = map[q].w << 2;
  45124. var dataOffset = 0;
  45125. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  45126. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  45127. for (var k = 0, kk = map[q].h; k < kk; k++) {
  45128. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  45129. dataOffset += rowSize;
  45130. offset += imgRowSize;
  45131. }
  45132. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  45133. while (offset >= 0) {
  45134. data[offset - 4] = data[offset];
  45135. data[offset - 3] = data[offset + 1];
  45136. data[offset - 2] = data[offset + 2];
  45137. data[offset - 1] = data[offset + 3];
  45138. data[offset + rowSize] = data[offset + rowSize - 4];
  45139. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  45140. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  45141. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  45142. offset -= imgRowSize;
  45143. }
  45144. }
  45145. // Replace queue items.
  45146. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  45147. argsArray.splice(iFirstSave, count * 4,
  45148. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  45149. data: imgData }, map]);
  45150. return iFirstSave + 1;
  45151. });
  45152. // This replaces (save, transform, paintImageMaskXObject, restore)+
  45153. // sequences with one |paintImageMaskXObjectGroup| or one
  45154. // |paintImageMaskXObjectRepeat| operation.
  45155. addState(InitialState,
  45156. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  45157. function foundImageMaskGroup(context) {
  45158. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  45159. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  45160. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  45161. var fnArray = context.fnArray, argsArray = context.argsArray;
  45162. var curr = context.iCurr;
  45163. var iFirstSave = curr - 3;
  45164. var iFirstTransform = curr - 2;
  45165. var iFirstPIMXO = curr - 1;
  45166. // Look for the quartets.
  45167. var i = iFirstSave + 4;
  45168. var ii = fnArray.length;
  45169. while (i + 3 < ii) {
  45170. if (fnArray[i] !== OPS.save ||
  45171. fnArray[i + 1] !== OPS.transform ||
  45172. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  45173. fnArray[i + 3] !== OPS.restore) {
  45174. break; // ops don't match
  45175. }
  45176. i += 4;
  45177. }
  45178. // At this point, i is the index of the first op past the last valid
  45179. // quartet.
  45180. var count = (i - iFirstSave) / 4;
  45181. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45182. argsArray);
  45183. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  45184. return i;
  45185. }
  45186. var q;
  45187. var isSameImage = false;
  45188. var iTransform, transformArgs;
  45189. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  45190. if (argsArray[iFirstTransform][1] === 0 &&
  45191. argsArray[iFirstTransform][2] === 0) {
  45192. isSameImage = true;
  45193. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45194. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45195. iTransform = iFirstTransform + 4;
  45196. var iPIMXO = iFirstPIMXO + 4;
  45197. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  45198. transformArgs = argsArray[iTransform];
  45199. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  45200. transformArgs[0] !== firstTransformArg0 ||
  45201. transformArgs[1] !== 0 ||
  45202. transformArgs[2] !== 0 ||
  45203. transformArgs[3] !== firstTransformArg3) {
  45204. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  45205. isSameImage = false;
  45206. } else {
  45207. count = q;
  45208. }
  45209. break; // different image or transform
  45210. }
  45211. }
  45212. }
  45213. if (isSameImage) {
  45214. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  45215. var positions = new Float32Array(count * 2);
  45216. iTransform = iFirstTransform;
  45217. for (q = 0; q < count; q++, iTransform += 4) {
  45218. transformArgs = argsArray[iTransform];
  45219. positions[(q << 1)] = transformArgs[4];
  45220. positions[(q << 1) + 1] = transformArgs[5];
  45221. }
  45222. // Replace queue items.
  45223. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  45224. argsArray.splice(iFirstSave, count * 4,
  45225. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  45226. } else {
  45227. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  45228. var images = [];
  45229. for (q = 0; q < count; q++) {
  45230. transformArgs = argsArray[iFirstTransform + (q << 2)];
  45231. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  45232. images.push({ data: maskParams.data, width: maskParams.width,
  45233. height: maskParams.height,
  45234. transform: transformArgs });
  45235. }
  45236. // Replace queue items.
  45237. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  45238. argsArray.splice(iFirstSave, count * 4, [images]);
  45239. }
  45240. return iFirstSave + 1;
  45241. });
  45242. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  45243. // with one paintImageXObjectRepeat operation, if the |transform| and
  45244. // |paintImageXObjectRepeat| ops are appropriate.
  45245. addState(InitialState,
  45246. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  45247. function (context) {
  45248. var MIN_IMAGES_IN_BLOCK = 3;
  45249. var MAX_IMAGES_IN_BLOCK = 1000;
  45250. var fnArray = context.fnArray, argsArray = context.argsArray;
  45251. var curr = context.iCurr;
  45252. var iFirstSave = curr - 3;
  45253. var iFirstTransform = curr - 2;
  45254. var iFirstPIXO = curr - 1;
  45255. var iFirstRestore = curr;
  45256. if (argsArray[iFirstTransform][1] !== 0 ||
  45257. argsArray[iFirstTransform][2] !== 0) {
  45258. return iFirstRestore + 1; // transform has the wrong form
  45259. }
  45260. // Look for the quartets.
  45261. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  45262. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45263. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45264. var i = iFirstSave + 4;
  45265. var ii = fnArray.length;
  45266. while (i + 3 < ii) {
  45267. if (fnArray[i] !== OPS.save ||
  45268. fnArray[i + 1] !== OPS.transform ||
  45269. fnArray[i + 2] !== OPS.paintImageXObject ||
  45270. fnArray[i + 3] !== OPS.restore) {
  45271. break; // ops don't match
  45272. }
  45273. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  45274. argsArray[i + 1][1] !== 0 ||
  45275. argsArray[i + 1][2] !== 0 ||
  45276. argsArray[i + 1][3] !== firstTransformArg3) {
  45277. break; // transforms don't match
  45278. }
  45279. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  45280. break; // images don't match
  45281. }
  45282. i += 4;
  45283. }
  45284. // At this point, i is the index of the first op past the last valid
  45285. // quartet.
  45286. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  45287. if (count < MIN_IMAGES_IN_BLOCK) {
  45288. return i;
  45289. }
  45290. // Extract the (x,y) positions from all of the matching transforms.
  45291. var positions = new Float32Array(count * 2);
  45292. var iTransform = iFirstTransform;
  45293. for (var q = 0; q < count; q++, iTransform += 4) {
  45294. var transformArgs = argsArray[iTransform];
  45295. positions[(q << 1)] = transformArgs[4];
  45296. positions[(q << 1) + 1] = transformArgs[5];
  45297. }
  45298. // Replace queue items.
  45299. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  45300. positions];
  45301. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  45302. argsArray.splice(iFirstSave, count * 4, args);
  45303. return iFirstSave + 1;
  45304. });
  45305. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  45306. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  45307. // sequences, if the font for each one is the same.
  45308. addState(InitialState,
  45309. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  45310. function (context) {
  45311. var MIN_CHARS_IN_BLOCK = 3;
  45312. var MAX_CHARS_IN_BLOCK = 1000;
  45313. var fnArray = context.fnArray, argsArray = context.argsArray;
  45314. var curr = context.iCurr;
  45315. var iFirstBeginText = curr - 4;
  45316. var iFirstSetFont = curr - 3;
  45317. var iFirstSetTextMatrix = curr - 2;
  45318. var iFirstShowText = curr - 1;
  45319. var iFirstEndText = curr;
  45320. // Look for the quintets.
  45321. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  45322. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  45323. var i = iFirstBeginText + 5;
  45324. var ii = fnArray.length;
  45325. while (i + 4 < ii) {
  45326. if (fnArray[i] !== OPS.beginText ||
  45327. fnArray[i + 1] !== OPS.setFont ||
  45328. fnArray[i + 2] !== OPS.setTextMatrix ||
  45329. fnArray[i + 3] !== OPS.showText ||
  45330. fnArray[i + 4] !== OPS.endText) {
  45331. break; // ops don't match
  45332. }
  45333. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  45334. argsArray[i + 1][1] !== firstSetFontArg1) {
  45335. break; // fonts don't match
  45336. }
  45337. i += 5;
  45338. }
  45339. // At this point, i is the index of the first op past the last valid
  45340. // quintet.
  45341. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  45342. if (count < MIN_CHARS_IN_BLOCK) {
  45343. return i;
  45344. }
  45345. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  45346. // showText, endText), include that as well. (E.g. <something> might be
  45347. // |dependency|.)
  45348. var iFirst = iFirstBeginText;
  45349. if (iFirstBeginText >= 4 &&
  45350. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  45351. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  45352. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  45353. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  45354. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  45355. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  45356. count++;
  45357. iFirst -= 5;
  45358. }
  45359. // Remove (endText, beginText, setFont) trios.
  45360. var iEndText = iFirst + 4;
  45361. for (var q = 1; q < count; q++) {
  45362. fnArray.splice(iEndText, 3);
  45363. argsArray.splice(iEndText, 3);
  45364. iEndText += 2;
  45365. }
  45366. return iEndText + 1;
  45367. });
  45368. function QueueOptimizer() {}
  45369. QueueOptimizer.prototype = {
  45370. optimize: function QueueOptimizer_optimize(queue) {
  45371. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  45372. var context = {
  45373. iCurr: 0,
  45374. fnArray: fnArray,
  45375. argsArray: argsArray
  45376. };
  45377. var state;
  45378. var i = 0, ii = fnArray.length;
  45379. while (i < ii) {
  45380. state = (state || InitialState)[fnArray[i]];
  45381. if (typeof state === 'function') { // we found some handler
  45382. context.iCurr = i;
  45383. // state() returns the index of the first non-matching op (if we
  45384. // didn't match) or the first op past the modified ops (if we did
  45385. // match and replace).
  45386. i = state(context);
  45387. state = undefined; // reset the state machine
  45388. ii = context.fnArray.length;
  45389. } else {
  45390. i++;
  45391. }
  45392. }
  45393. }
  45394. };
  45395. return QueueOptimizer;
  45396. })();
  45397. exports.OperatorList = OperatorList;
  45398. exports.PartialEvaluator = PartialEvaluator;
  45399. }));
  45400. (function (root, factory) {
  45401. {
  45402. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  45403. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  45404. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  45405. }
  45406. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  45407. coreColorSpace, coreObj, coreEvaluator) {
  45408. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  45409. var AnnotationFlag = sharedUtil.AnnotationFlag;
  45410. var AnnotationType = sharedUtil.AnnotationType;
  45411. var OPS = sharedUtil.OPS;
  45412. var Util = sharedUtil.Util;
  45413. var isBool = sharedUtil.isBool;
  45414. var isString = sharedUtil.isString;
  45415. var isArray = sharedUtil.isArray;
  45416. var isInt = sharedUtil.isInt;
  45417. var isValidUrl = sharedUtil.isValidUrl;
  45418. var stringToBytes = sharedUtil.stringToBytes;
  45419. var stringToPDFString = sharedUtil.stringToPDFString;
  45420. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45421. var warn = sharedUtil.warn;
  45422. var Dict = corePrimitives.Dict;
  45423. var isDict = corePrimitives.isDict;
  45424. var isName = corePrimitives.isName;
  45425. var isRef = corePrimitives.isRef;
  45426. var Stream = coreStream.Stream;
  45427. var ColorSpace = coreColorSpace.ColorSpace;
  45428. var ObjectLoader = coreObj.ObjectLoader;
  45429. var FileSpec = coreObj.FileSpec;
  45430. var OperatorList = coreEvaluator.OperatorList;
  45431. /**
  45432. * @class
  45433. * @alias AnnotationFactory
  45434. */
  45435. function AnnotationFactory() {}
  45436. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  45437. /**
  45438. * @param {XRef} xref
  45439. * @param {Object} ref
  45440. * @returns {Annotation}
  45441. */
  45442. create: function AnnotationFactory_create(xref, ref,
  45443. uniquePrefix, idCounters) {
  45444. var dict = xref.fetchIfRef(ref);
  45445. if (!isDict(dict)) {
  45446. return;
  45447. }
  45448. var id = isRef(ref) ? ref.toString() :
  45449. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  45450. // Determine the annotation's subtype.
  45451. var subtype = dict.get('Subtype');
  45452. subtype = isName(subtype) ? subtype.name : null;
  45453. // Return the right annotation object based on the subtype and field type.
  45454. var parameters = {
  45455. xref: xref,
  45456. dict: dict,
  45457. ref: isRef(ref) ? ref : null,
  45458. subtype: subtype,
  45459. id: id,
  45460. };
  45461. switch (subtype) {
  45462. case 'Link':
  45463. return new LinkAnnotation(parameters);
  45464. case 'Text':
  45465. return new TextAnnotation(parameters);
  45466. case 'Widget':
  45467. var fieldType = Util.getInheritableProperty(dict, 'FT');
  45468. if (isName(fieldType, 'Tx')) {
  45469. return new TextWidgetAnnotation(parameters);
  45470. }
  45471. return new WidgetAnnotation(parameters);
  45472. case 'Popup':
  45473. return new PopupAnnotation(parameters);
  45474. case 'Highlight':
  45475. return new HighlightAnnotation(parameters);
  45476. case 'Underline':
  45477. return new UnderlineAnnotation(parameters);
  45478. case 'Squiggly':
  45479. return new SquigglyAnnotation(parameters);
  45480. case 'StrikeOut':
  45481. return new StrikeOutAnnotation(parameters);
  45482. case 'FileAttachment':
  45483. return new FileAttachmentAnnotation(parameters);
  45484. default:
  45485. if (!subtype) {
  45486. warn('Annotation is missing the required /Subtype.');
  45487. } else {
  45488. warn('Unimplemented annotation type "' + subtype + '", ' +
  45489. 'falling back to base annotation.');
  45490. }
  45491. return new Annotation(parameters);
  45492. }
  45493. }
  45494. };
  45495. var Annotation = (function AnnotationClosure() {
  45496. // 12.5.5: Algorithm: Appearance streams
  45497. function getTransformMatrix(rect, bbox, matrix) {
  45498. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  45499. var minX = bounds[0];
  45500. var minY = bounds[1];
  45501. var maxX = bounds[2];
  45502. var maxY = bounds[3];
  45503. if (minX === maxX || minY === maxY) {
  45504. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  45505. // just apply the transform for rect
  45506. return [1, 0, 0, 1, rect[0], rect[1]];
  45507. }
  45508. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  45509. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  45510. return [
  45511. xRatio,
  45512. 0,
  45513. 0,
  45514. yRatio,
  45515. rect[0] - minX * xRatio,
  45516. rect[1] - minY * yRatio
  45517. ];
  45518. }
  45519. function getDefaultAppearance(dict) {
  45520. var appearanceState = dict.get('AP');
  45521. if (!isDict(appearanceState)) {
  45522. return;
  45523. }
  45524. var appearance;
  45525. var appearances = appearanceState.get('N');
  45526. if (isDict(appearances)) {
  45527. var as = dict.get('AS');
  45528. if (as && appearances.has(as.name)) {
  45529. appearance = appearances.get(as.name);
  45530. }
  45531. } else {
  45532. appearance = appearances;
  45533. }
  45534. return appearance;
  45535. }
  45536. function Annotation(params) {
  45537. var dict = params.dict;
  45538. this.setFlags(dict.get('F'));
  45539. this.setRectangle(dict.getArray('Rect'));
  45540. this.setColor(dict.getArray('C'));
  45541. this.setBorderStyle(dict);
  45542. this.appearance = getDefaultAppearance(dict);
  45543. // Expose public properties using a data object.
  45544. this.data = {};
  45545. this.data.id = params.id;
  45546. this.data.subtype = params.subtype;
  45547. this.data.annotationFlags = this.flags;
  45548. this.data.rect = this.rectangle;
  45549. this.data.color = this.color;
  45550. this.data.borderStyle = this.borderStyle;
  45551. this.data.hasAppearance = !!this.appearance;
  45552. }
  45553. Annotation.prototype = {
  45554. /**
  45555. * @private
  45556. */
  45557. _hasFlag: function Annotation_hasFlag(flags, flag) {
  45558. return !!(flags & flag);
  45559. },
  45560. /**
  45561. * @private
  45562. */
  45563. _isViewable: function Annotation_isViewable(flags) {
  45564. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45565. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  45566. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  45567. },
  45568. /**
  45569. * @private
  45570. */
  45571. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  45572. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  45573. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45574. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  45575. },
  45576. /**
  45577. * @return {boolean}
  45578. */
  45579. get viewable() {
  45580. if (this.flags === 0) {
  45581. return true;
  45582. }
  45583. return this._isViewable(this.flags);
  45584. },
  45585. /**
  45586. * @return {boolean}
  45587. */
  45588. get printable() {
  45589. if (this.flags === 0) {
  45590. return false;
  45591. }
  45592. return this._isPrintable(this.flags);
  45593. },
  45594. /**
  45595. * Set the flags.
  45596. *
  45597. * @public
  45598. * @memberof Annotation
  45599. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  45600. * characteristics
  45601. * @see {@link shared/util.js}
  45602. */
  45603. setFlags: function Annotation_setFlags(flags) {
  45604. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  45605. },
  45606. /**
  45607. * Check if a provided flag is set.
  45608. *
  45609. * @public
  45610. * @memberof Annotation
  45611. * @param {number} flag - Hexadecimal representation for an annotation
  45612. * characteristic
  45613. * @return {boolean}
  45614. * @see {@link shared/util.js}
  45615. */
  45616. hasFlag: function Annotation_hasFlag(flag) {
  45617. return this._hasFlag(this.flags, flag);
  45618. },
  45619. /**
  45620. * Set the rectangle.
  45621. *
  45622. * @public
  45623. * @memberof Annotation
  45624. * @param {Array} rectangle - The rectangle array with exactly four entries
  45625. */
  45626. setRectangle: function Annotation_setRectangle(rectangle) {
  45627. if (isArray(rectangle) && rectangle.length === 4) {
  45628. this.rectangle = Util.normalizeRect(rectangle);
  45629. } else {
  45630. this.rectangle = [0, 0, 0, 0];
  45631. }
  45632. },
  45633. /**
  45634. * Set the color and take care of color space conversion.
  45635. *
  45636. * @public
  45637. * @memberof Annotation
  45638. * @param {Array} color - The color array containing either 0
  45639. * (transparent), 1 (grayscale), 3 (RGB) or
  45640. * 4 (CMYK) elements
  45641. */
  45642. setColor: function Annotation_setColor(color) {
  45643. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  45644. if (!isArray(color)) {
  45645. this.color = rgbColor;
  45646. return;
  45647. }
  45648. switch (color.length) {
  45649. case 0: // Transparent, which we indicate with a null value
  45650. this.color = null;
  45651. break;
  45652. case 1: // Convert grayscale to RGB
  45653. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  45654. this.color = rgbColor;
  45655. break;
  45656. case 3: // Convert RGB percentages to RGB
  45657. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  45658. this.color = rgbColor;
  45659. break;
  45660. case 4: // Convert CMYK to RGB
  45661. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  45662. this.color = rgbColor;
  45663. break;
  45664. default:
  45665. this.color = rgbColor;
  45666. break;
  45667. }
  45668. },
  45669. /**
  45670. * Set the border style (as AnnotationBorderStyle object).
  45671. *
  45672. * @public
  45673. * @memberof Annotation
  45674. * @param {Dict} borderStyle - The border style dictionary
  45675. */
  45676. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  45677. this.borderStyle = new AnnotationBorderStyle();
  45678. if (!isDict(borderStyle)) {
  45679. return;
  45680. }
  45681. if (borderStyle.has('BS')) {
  45682. var dict = borderStyle.get('BS');
  45683. var dictType = dict.get('Type');
  45684. if (!dictType || isName(dictType, 'Border')) {
  45685. this.borderStyle.setWidth(dict.get('W'));
  45686. this.borderStyle.setStyle(dict.get('S'));
  45687. this.borderStyle.setDashArray(dict.getArray('D'));
  45688. }
  45689. } else if (borderStyle.has('Border')) {
  45690. var array = borderStyle.getArray('Border');
  45691. if (isArray(array) && array.length >= 3) {
  45692. this.borderStyle.setHorizontalCornerRadius(array[0]);
  45693. this.borderStyle.setVerticalCornerRadius(array[1]);
  45694. this.borderStyle.setWidth(array[2]);
  45695. if (array.length === 4) { // Dash array available
  45696. this.borderStyle.setDashArray(array[3]);
  45697. }
  45698. }
  45699. } else {
  45700. // There are no border entries in the dictionary. According to the
  45701. // specification, we should draw a solid border of width 1 in that
  45702. // case, but Adobe Reader did not implement that part of the
  45703. // specification and instead draws no border at all, so we do the same.
  45704. // See also https://github.com/mozilla/pdf.js/issues/6179.
  45705. this.borderStyle.setWidth(0);
  45706. }
  45707. },
  45708. /**
  45709. * Prepare the annotation for working with a popup in the display layer.
  45710. *
  45711. * @private
  45712. * @memberof Annotation
  45713. * @param {Dict} dict - The annotation's data dictionary
  45714. */
  45715. _preparePopup: function Annotation_preparePopup(dict) {
  45716. if (!dict.has('C')) {
  45717. // Fall back to the default background color.
  45718. this.data.color = null;
  45719. }
  45720. this.data.hasPopup = dict.has('Popup');
  45721. this.data.title = stringToPDFString(dict.get('T') || '');
  45722. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  45723. },
  45724. loadResources: function Annotation_loadResources(keys) {
  45725. return new Promise(function (resolve, reject) {
  45726. this.appearance.dict.getAsync('Resources').then(function (resources) {
  45727. if (!resources) {
  45728. resolve();
  45729. return;
  45730. }
  45731. var objectLoader = new ObjectLoader(resources.map,
  45732. keys,
  45733. resources.xref);
  45734. objectLoader.load().then(function() {
  45735. resolve(resources);
  45736. }, reject);
  45737. }, reject);
  45738. }.bind(this));
  45739. },
  45740. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  45741. if (!this.appearance) {
  45742. return Promise.resolve(new OperatorList());
  45743. }
  45744. var data = this.data;
  45745. var appearanceDict = this.appearance.dict;
  45746. var resourcesPromise = this.loadResources([
  45747. 'ExtGState',
  45748. 'ColorSpace',
  45749. 'Pattern',
  45750. 'Shading',
  45751. 'XObject',
  45752. 'Font'
  45753. // ProcSet
  45754. // Properties
  45755. ]);
  45756. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  45757. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  45758. var transform = getTransformMatrix(data.rect, bbox, matrix);
  45759. var self = this;
  45760. return resourcesPromise.then(function(resources) {
  45761. var opList = new OperatorList();
  45762. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  45763. return evaluator.getOperatorList(self.appearance, task,
  45764. resources, opList).
  45765. then(function () {
  45766. opList.addOp(OPS.endAnnotation, []);
  45767. self.appearance.reset();
  45768. return opList;
  45769. });
  45770. });
  45771. }
  45772. };
  45773. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  45774. annotations, opList, partialEvaluator, task, intent) {
  45775. var annotationPromises = [];
  45776. for (var i = 0, n = annotations.length; i < n; ++i) {
  45777. if ((intent === 'display' && annotations[i].viewable) ||
  45778. (intent === 'print' && annotations[i].printable)) {
  45779. annotationPromises.push(
  45780. annotations[i].getOperatorList(partialEvaluator, task));
  45781. }
  45782. }
  45783. return Promise.all(annotationPromises).then(function(operatorLists) {
  45784. opList.addOp(OPS.beginAnnotations, []);
  45785. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  45786. opList.addOpList(operatorLists[i]);
  45787. }
  45788. opList.addOp(OPS.endAnnotations, []);
  45789. });
  45790. };
  45791. return Annotation;
  45792. })();
  45793. /**
  45794. * Contains all data regarding an annotation's border style.
  45795. *
  45796. * @class
  45797. */
  45798. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  45799. /**
  45800. * @constructor
  45801. * @private
  45802. */
  45803. function AnnotationBorderStyle() {
  45804. this.width = 1;
  45805. this.style = AnnotationBorderStyleType.SOLID;
  45806. this.dashArray = [3];
  45807. this.horizontalCornerRadius = 0;
  45808. this.verticalCornerRadius = 0;
  45809. }
  45810. AnnotationBorderStyle.prototype = {
  45811. /**
  45812. * Set the width.
  45813. *
  45814. * @public
  45815. * @memberof AnnotationBorderStyle
  45816. * @param {integer} width - The width
  45817. */
  45818. setWidth: function AnnotationBorderStyle_setWidth(width) {
  45819. if (width === (width | 0)) {
  45820. this.width = width;
  45821. }
  45822. },
  45823. /**
  45824. * Set the style.
  45825. *
  45826. * @public
  45827. * @memberof AnnotationBorderStyle
  45828. * @param {Object} style - The style object
  45829. * @see {@link shared/util.js}
  45830. */
  45831. setStyle: function AnnotationBorderStyle_setStyle(style) {
  45832. if (!style) {
  45833. return;
  45834. }
  45835. switch (style.name) {
  45836. case 'S':
  45837. this.style = AnnotationBorderStyleType.SOLID;
  45838. break;
  45839. case 'D':
  45840. this.style = AnnotationBorderStyleType.DASHED;
  45841. break;
  45842. case 'B':
  45843. this.style = AnnotationBorderStyleType.BEVELED;
  45844. break;
  45845. case 'I':
  45846. this.style = AnnotationBorderStyleType.INSET;
  45847. break;
  45848. case 'U':
  45849. this.style = AnnotationBorderStyleType.UNDERLINE;
  45850. break;
  45851. default:
  45852. break;
  45853. }
  45854. },
  45855. /**
  45856. * Set the dash array.
  45857. *
  45858. * @public
  45859. * @memberof AnnotationBorderStyle
  45860. * @param {Array} dashArray - The dash array with at least one element
  45861. */
  45862. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  45863. // We validate the dash array, but we do not use it because CSS does not
  45864. // allow us to change spacing of dashes. For more information, visit
  45865. // http://www.w3.org/TR/css3-background/#the-border-style.
  45866. if (isArray(dashArray) && dashArray.length > 0) {
  45867. // According to the PDF specification: the elements in a dashArray
  45868. // shall be numbers that are nonnegative and not all equal to zero.
  45869. var isValid = true;
  45870. var allZeros = true;
  45871. for (var i = 0, len = dashArray.length; i < len; i++) {
  45872. var element = dashArray[i];
  45873. var validNumber = (+element >= 0);
  45874. if (!validNumber) {
  45875. isValid = false;
  45876. break;
  45877. } else if (element > 0) {
  45878. allZeros = false;
  45879. }
  45880. }
  45881. if (isValid && !allZeros) {
  45882. this.dashArray = dashArray;
  45883. } else {
  45884. this.width = 0; // Adobe behavior when the array is invalid.
  45885. }
  45886. } else if (dashArray) {
  45887. this.width = 0; // Adobe behavior when the array is invalid.
  45888. }
  45889. },
  45890. /**
  45891. * Set the horizontal corner radius (from a Border dictionary).
  45892. *
  45893. * @public
  45894. * @memberof AnnotationBorderStyle
  45895. * @param {integer} radius - The horizontal corner radius
  45896. */
  45897. setHorizontalCornerRadius:
  45898. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  45899. if (radius === (radius | 0)) {
  45900. this.horizontalCornerRadius = radius;
  45901. }
  45902. },
  45903. /**
  45904. * Set the vertical corner radius (from a Border dictionary).
  45905. *
  45906. * @public
  45907. * @memberof AnnotationBorderStyle
  45908. * @param {integer} radius - The vertical corner radius
  45909. */
  45910. setVerticalCornerRadius:
  45911. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  45912. if (radius === (radius | 0)) {
  45913. this.verticalCornerRadius = radius;
  45914. }
  45915. }
  45916. };
  45917. return AnnotationBorderStyle;
  45918. })();
  45919. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  45920. function WidgetAnnotation(params) {
  45921. Annotation.call(this, params);
  45922. var dict = params.dict;
  45923. var data = this.data;
  45924. data.annotationType = AnnotationType.WIDGET;
  45925. data.fieldValue = stringToPDFString(
  45926. Util.getInheritableProperty(dict, 'V') || '');
  45927. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  45928. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  45929. var fieldType = Util.getInheritableProperty(dict, 'FT');
  45930. data.fieldType = isName(fieldType) ? fieldType.name : '';
  45931. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  45932. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  45933. // Hide unsupported Widget signatures.
  45934. if (data.fieldType === 'Sig') {
  45935. warn('unimplemented annotation type: Widget signature');
  45936. this.setFlags(AnnotationFlag.HIDDEN);
  45937. }
  45938. // Building the full field name by collecting the field and
  45939. // its ancestors 'T' data and joining them using '.'.
  45940. var fieldName = [];
  45941. var namedItem = dict;
  45942. var ref = params.ref;
  45943. while (namedItem) {
  45944. var parent = namedItem.get('Parent');
  45945. var parentRef = namedItem.getRaw('Parent');
  45946. var name = namedItem.get('T');
  45947. if (name) {
  45948. fieldName.unshift(stringToPDFString(name));
  45949. } else if (parent && ref) {
  45950. // The field name is absent, that means more than one field
  45951. // with the same name may exist. Replacing the empty name
  45952. // with the '`' plus index in the parent's 'Kids' array.
  45953. // This is not in the PDF spec but necessary to id the
  45954. // the input controls.
  45955. var kids = parent.get('Kids');
  45956. var j, jj;
  45957. for (j = 0, jj = kids.length; j < jj; j++) {
  45958. var kidRef = kids[j];
  45959. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  45960. break;
  45961. }
  45962. }
  45963. fieldName.unshift('`' + j);
  45964. }
  45965. namedItem = parent;
  45966. ref = parentRef;
  45967. }
  45968. data.fullName = fieldName.join('.');
  45969. }
  45970. Util.inherit(WidgetAnnotation, Annotation, {});
  45971. return WidgetAnnotation;
  45972. })();
  45973. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  45974. function TextWidgetAnnotation(params) {
  45975. WidgetAnnotation.call(this, params);
  45976. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  45977. this.data.maxLen = Util.getInheritableProperty(params.dict, 'MaxLen');
  45978. }
  45979. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  45980. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  45981. task) {
  45982. if (this.appearance) {
  45983. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  45984. }
  45985. var opList = new OperatorList();
  45986. var data = this.data;
  45987. // Even if there is an appearance stream, ignore it. This is the
  45988. // behaviour used by Adobe Reader.
  45989. if (!data.defaultAppearance) {
  45990. return Promise.resolve(opList);
  45991. }
  45992. var stream = new Stream(stringToBytes(data.defaultAppearance));
  45993. return evaluator.getOperatorList(stream, task,
  45994. this.fieldResources, opList).
  45995. then(function () {
  45996. return opList;
  45997. });
  45998. }
  45999. });
  46000. return TextWidgetAnnotation;
  46001. })();
  46002. var TextAnnotation = (function TextAnnotationClosure() {
  46003. var DEFAULT_ICON_SIZE = 22; // px
  46004. function TextAnnotation(parameters) {
  46005. Annotation.call(this, parameters);
  46006. this.data.annotationType = AnnotationType.TEXT;
  46007. if (this.data.hasAppearance) {
  46008. this.data.name = 'NoIcon';
  46009. } else {
  46010. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  46011. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  46012. this.data.name = parameters.dict.has('Name') ?
  46013. parameters.dict.get('Name').name : 'Note';
  46014. }
  46015. this._preparePopup(parameters.dict);
  46016. }
  46017. Util.inherit(TextAnnotation, Annotation, {});
  46018. return TextAnnotation;
  46019. })();
  46020. var LinkAnnotation = (function LinkAnnotationClosure() {
  46021. function LinkAnnotation(params) {
  46022. Annotation.call(this, params);
  46023. var dict = params.dict;
  46024. var data = this.data;
  46025. data.annotationType = AnnotationType.LINK;
  46026. var action = dict.get('A'), url, dest;
  46027. if (action && isDict(action)) {
  46028. var linkType = action.get('S').name;
  46029. switch (linkType) {
  46030. case 'URI':
  46031. url = action.get('URI');
  46032. if (isName(url)) {
  46033. // Some bad PDFs do not put parentheses around relative URLs.
  46034. url = '/' + url.name;
  46035. } else if (url) {
  46036. url = addDefaultProtocolToUrl(url);
  46037. }
  46038. // TODO: pdf spec mentions urls can be relative to a Base
  46039. // entry in the dictionary.
  46040. break;
  46041. case 'GoTo':
  46042. dest = action.get('D');
  46043. break;
  46044. case 'GoToR':
  46045. var urlDict = action.get('F');
  46046. if (isDict(urlDict)) {
  46047. // We assume that we found a FileSpec dictionary
  46048. // and fetch the URL without checking any further.
  46049. url = urlDict.get('F') || null;
  46050. } else if (isString(urlDict)) {
  46051. url = urlDict;
  46052. }
  46053. // NOTE: the destination is relative to the *remote* document.
  46054. var remoteDest = action.get('D');
  46055. if (remoteDest) {
  46056. if (isName(remoteDest)) {
  46057. remoteDest = remoteDest.name;
  46058. }
  46059. if (isString(url)) {
  46060. var baseUrl = url.split('#')[0];
  46061. if (isString(remoteDest)) {
  46062. // In practice, a named destination may contain only a number.
  46063. // If that happens, use the '#nameddest=' form to avoid the link
  46064. // redirecting to a page, instead of the correct destination.
  46065. url = baseUrl + '#' +
  46066. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  46067. } else if (isArray(remoteDest)) {
  46068. url = baseUrl + '#' + JSON.stringify(remoteDest);
  46069. }
  46070. }
  46071. }
  46072. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  46073. var newWindow = action.get('NewWindow');
  46074. if (isBool(newWindow)) {
  46075. data.newWindow = newWindow;
  46076. }
  46077. break;
  46078. case 'Named':
  46079. data.action = action.get('N').name;
  46080. break;
  46081. default:
  46082. warn('unrecognized link type: ' + linkType);
  46083. }
  46084. } else if (dict.has('Dest')) { // Simple destination link.
  46085. dest = dict.get('Dest');
  46086. }
  46087. if (url) {
  46088. if (isValidUrl(url, /* allowRelative = */ false)) {
  46089. data.url = tryConvertUrlEncoding(url);
  46090. }
  46091. }
  46092. if (dest) {
  46093. data.dest = isName(dest) ? dest.name : dest;
  46094. }
  46095. }
  46096. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  46097. function addDefaultProtocolToUrl(url) {
  46098. if (isString(url) && url.indexOf('www.') === 0) {
  46099. return ('http://' + url);
  46100. }
  46101. return url;
  46102. }
  46103. function tryConvertUrlEncoding(url) {
  46104. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  46105. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  46106. try {
  46107. return stringToUTF8String(url);
  46108. } catch (e) {
  46109. return url;
  46110. }
  46111. }
  46112. Util.inherit(LinkAnnotation, Annotation, {});
  46113. return LinkAnnotation;
  46114. })();
  46115. var PopupAnnotation = (function PopupAnnotationClosure() {
  46116. function PopupAnnotation(parameters) {
  46117. Annotation.call(this, parameters);
  46118. this.data.annotationType = AnnotationType.POPUP;
  46119. var dict = parameters.dict;
  46120. var parentItem = dict.get('Parent');
  46121. if (!parentItem) {
  46122. warn('Popup annotation has a missing or invalid parent annotation.');
  46123. return;
  46124. }
  46125. this.data.parentId = dict.getRaw('Parent').toString();
  46126. this.data.title = stringToPDFString(parentItem.get('T') || '');
  46127. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  46128. if (!parentItem.has('C')) {
  46129. // Fall back to the default background color.
  46130. this.data.color = null;
  46131. } else {
  46132. this.setColor(parentItem.getArray('C'));
  46133. this.data.color = this.color;
  46134. }
  46135. // If the Popup annotation is not viewable, but the parent annotation is,
  46136. // that is most likely a bug. Fallback to inherit the flags from the parent
  46137. // annotation (this is consistent with the behaviour in Adobe Reader).
  46138. if (!this.viewable) {
  46139. var parentFlags = parentItem.get('F');
  46140. if (this._isViewable(parentFlags)) {
  46141. this.setFlags(parentFlags);
  46142. }
  46143. }
  46144. }
  46145. Util.inherit(PopupAnnotation, Annotation, {});
  46146. return PopupAnnotation;
  46147. })();
  46148. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  46149. function HighlightAnnotation(parameters) {
  46150. Annotation.call(this, parameters);
  46151. this.data.annotationType = AnnotationType.HIGHLIGHT;
  46152. this._preparePopup(parameters.dict);
  46153. // PDF viewers completely ignore any border styles.
  46154. this.data.borderStyle.setWidth(0);
  46155. }
  46156. Util.inherit(HighlightAnnotation, Annotation, {});
  46157. return HighlightAnnotation;
  46158. })();
  46159. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  46160. function UnderlineAnnotation(parameters) {
  46161. Annotation.call(this, parameters);
  46162. this.data.annotationType = AnnotationType.UNDERLINE;
  46163. this._preparePopup(parameters.dict);
  46164. // PDF viewers completely ignore any border styles.
  46165. this.data.borderStyle.setWidth(0);
  46166. }
  46167. Util.inherit(UnderlineAnnotation, Annotation, {});
  46168. return UnderlineAnnotation;
  46169. })();
  46170. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  46171. function SquigglyAnnotation(parameters) {
  46172. Annotation.call(this, parameters);
  46173. this.data.annotationType = AnnotationType.SQUIGGLY;
  46174. this._preparePopup(parameters.dict);
  46175. // PDF viewers completely ignore any border styles.
  46176. this.data.borderStyle.setWidth(0);
  46177. }
  46178. Util.inherit(SquigglyAnnotation, Annotation, {});
  46179. return SquigglyAnnotation;
  46180. })();
  46181. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  46182. function StrikeOutAnnotation(parameters) {
  46183. Annotation.call(this, parameters);
  46184. this.data.annotationType = AnnotationType.STRIKEOUT;
  46185. this._preparePopup(parameters.dict);
  46186. // PDF viewers completely ignore any border styles.
  46187. this.data.borderStyle.setWidth(0);
  46188. }
  46189. Util.inherit(StrikeOutAnnotation, Annotation, {});
  46190. return StrikeOutAnnotation;
  46191. })();
  46192. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  46193. function FileAttachmentAnnotation(parameters) {
  46194. Annotation.call(this, parameters);
  46195. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  46196. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  46197. this.data.file = file.serializable;
  46198. this._preparePopup(parameters.dict);
  46199. }
  46200. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  46201. return FileAttachmentAnnotation;
  46202. })();
  46203. exports.Annotation = Annotation;
  46204. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  46205. exports.AnnotationFactory = AnnotationFactory;
  46206. }));
  46207. (function (root, factory) {
  46208. {
  46209. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  46210. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  46211. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  46212. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  46213. }
  46214. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  46215. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  46216. var MissingDataException = sharedUtil.MissingDataException;
  46217. var Util = sharedUtil.Util;
  46218. var assert = sharedUtil.assert;
  46219. var error = sharedUtil.error;
  46220. var info = sharedUtil.info;
  46221. var isArray = sharedUtil.isArray;
  46222. var isArrayBuffer = sharedUtil.isArrayBuffer;
  46223. var isString = sharedUtil.isString;
  46224. var shadow = sharedUtil.shadow;
  46225. var stringToBytes = sharedUtil.stringToBytes;
  46226. var stringToPDFString = sharedUtil.stringToPDFString;
  46227. var warn = sharedUtil.warn;
  46228. var isSpace = sharedUtil.isSpace;
  46229. var Dict = corePrimitives.Dict;
  46230. var isDict = corePrimitives.isDict;
  46231. var isName = corePrimitives.isName;
  46232. var isStream = corePrimitives.isStream;
  46233. var NullStream = coreStream.NullStream;
  46234. var Stream = coreStream.Stream;
  46235. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  46236. var Catalog = coreObj.Catalog;
  46237. var ObjectLoader = coreObj.ObjectLoader;
  46238. var XRef = coreObj.XRef;
  46239. var Linearization = coreParser.Linearization;
  46240. var calculateMD5 = coreCrypto.calculateMD5;
  46241. var OperatorList = coreEvaluator.OperatorList;
  46242. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  46243. var Annotation = coreAnnotation.Annotation;
  46244. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  46245. var Page = (function PageClosure() {
  46246. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  46247. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  46248. this.pdfManager = pdfManager;
  46249. this.pageIndex = pageIndex;
  46250. this.pageDict = pageDict;
  46251. this.xref = xref;
  46252. this.ref = ref;
  46253. this.fontCache = fontCache;
  46254. this.uniquePrefix = 'p' + this.pageIndex + '_';
  46255. this.idCounters = {
  46256. obj: 0
  46257. };
  46258. this.evaluatorOptions = pdfManager.evaluatorOptions;
  46259. this.resourcesPromise = null;
  46260. }
  46261. Page.prototype = {
  46262. getPageProp: function Page_getPageProp(key) {
  46263. return this.pageDict.get(key);
  46264. },
  46265. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  46266. var dict = this.pageDict, valueArray = null, loopCount = 0;
  46267. var MAX_LOOP_COUNT = 100;
  46268. // Always walk up the entire parent chain, to be able to find
  46269. // e.g. \Resources placed on multiple levels of the tree.
  46270. while (dict) {
  46271. var value = dict.get(key);
  46272. if (value) {
  46273. if (!valueArray) {
  46274. valueArray = [];
  46275. }
  46276. valueArray.push(value);
  46277. }
  46278. if (++loopCount > MAX_LOOP_COUNT) {
  46279. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  46280. break;
  46281. }
  46282. dict = dict.get('Parent');
  46283. }
  46284. if (!valueArray) {
  46285. return Dict.empty;
  46286. }
  46287. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  46288. loopCount > MAX_LOOP_COUNT) {
  46289. return valueArray[0];
  46290. }
  46291. return Dict.merge(this.xref, valueArray);
  46292. },
  46293. get content() {
  46294. return this.getPageProp('Contents');
  46295. },
  46296. get resources() {
  46297. // For robustness: The spec states that a \Resources entry has to be
  46298. // present, but can be empty. Some document omit it still, in this case
  46299. // we return an empty dictionary.
  46300. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  46301. },
  46302. get mediaBox() {
  46303. var obj = this.getInheritedPageProp('MediaBox');
  46304. // Reset invalid media box to letter size.
  46305. if (!isArray(obj) || obj.length !== 4) {
  46306. obj = LETTER_SIZE_MEDIABOX;
  46307. }
  46308. return shadow(this, 'mediaBox', obj);
  46309. },
  46310. get view() {
  46311. var mediaBox = this.mediaBox;
  46312. var cropBox = this.getInheritedPageProp('CropBox');
  46313. if (!isArray(cropBox) || cropBox.length !== 4) {
  46314. return shadow(this, 'view', mediaBox);
  46315. }
  46316. // From the spec, 6th ed., p.963:
  46317. // "The crop, bleed, trim, and art boxes should not ordinarily
  46318. // extend beyond the boundaries of the media box. If they do, they are
  46319. // effectively reduced to their intersection with the media box."
  46320. cropBox = Util.intersect(cropBox, mediaBox);
  46321. if (!cropBox) {
  46322. return shadow(this, 'view', mediaBox);
  46323. }
  46324. return shadow(this, 'view', cropBox);
  46325. },
  46326. get rotate() {
  46327. var rotate = this.getInheritedPageProp('Rotate') || 0;
  46328. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  46329. if (rotate % 90 !== 0) {
  46330. rotate = 0;
  46331. } else if (rotate >= 360) {
  46332. rotate = rotate % 360;
  46333. } else if (rotate < 0) {
  46334. // The spec doesn't cover negatives, assume its counterclockwise
  46335. // rotation. The following is the other implementation of modulo.
  46336. rotate = ((rotate % 360) + 360) % 360;
  46337. }
  46338. return shadow(this, 'rotate', rotate);
  46339. },
  46340. getContentStream: function Page_getContentStream() {
  46341. var content = this.content;
  46342. var stream;
  46343. if (isArray(content)) {
  46344. // fetching items
  46345. var xref = this.xref;
  46346. var i, n = content.length;
  46347. var streams = [];
  46348. for (i = 0; i < n; ++i) {
  46349. streams.push(xref.fetchIfRef(content[i]));
  46350. }
  46351. stream = new StreamsSequenceStream(streams);
  46352. } else if (isStream(content)) {
  46353. stream = content;
  46354. } else {
  46355. // replacing non-existent page content with empty one
  46356. stream = new NullStream();
  46357. }
  46358. return stream;
  46359. },
  46360. loadResources: function Page_loadResources(keys) {
  46361. if (!this.resourcesPromise) {
  46362. // TODO: add async getInheritedPageProp and remove this.
  46363. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  46364. }
  46365. return this.resourcesPromise.then(function resourceSuccess() {
  46366. var objectLoader = new ObjectLoader(this.resources.map,
  46367. keys,
  46368. this.xref);
  46369. return objectLoader.load();
  46370. }.bind(this));
  46371. },
  46372. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  46373. var self = this;
  46374. var pdfManager = this.pdfManager;
  46375. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46376. []);
  46377. var resourcesPromise = this.loadResources([
  46378. 'ExtGState',
  46379. 'ColorSpace',
  46380. 'Pattern',
  46381. 'Shading',
  46382. 'XObject',
  46383. 'Font'
  46384. // ProcSet
  46385. // Properties
  46386. ]);
  46387. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  46388. handler, this.pageIndex,
  46389. this.uniquePrefix,
  46390. this.idCounters,
  46391. this.fontCache,
  46392. this.evaluatorOptions);
  46393. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  46394. var pageListPromise = dataPromises.then(function(data) {
  46395. var contentStream = data[0];
  46396. var opList = new OperatorList(intent, handler, self.pageIndex);
  46397. handler.send('StartRenderPage', {
  46398. transparency: partialEvaluator.hasBlendModes(self.resources),
  46399. pageIndex: self.pageIndex,
  46400. intent: intent
  46401. });
  46402. return partialEvaluator.getOperatorList(contentStream, task,
  46403. self.resources, opList).then(function () {
  46404. return opList;
  46405. });
  46406. });
  46407. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  46408. return Promise.all([pageListPromise, annotationsPromise]).then(
  46409. function(datas) {
  46410. var pageOpList = datas[0];
  46411. var annotations = datas[1];
  46412. if (annotations.length === 0) {
  46413. pageOpList.flush(true);
  46414. return pageOpList;
  46415. }
  46416. var annotationsReadyPromise = Annotation.appendToOperatorList(
  46417. annotations, pageOpList, partialEvaluator, task, intent);
  46418. return annotationsReadyPromise.then(function () {
  46419. pageOpList.flush(true);
  46420. return pageOpList;
  46421. });
  46422. });
  46423. },
  46424. extractTextContent: function Page_extractTextContent(task,
  46425. normalizeWhitespace,
  46426. combineTextItems) {
  46427. var handler = {
  46428. on: function nullHandlerOn() {},
  46429. send: function nullHandlerSend() {}
  46430. };
  46431. var self = this;
  46432. var pdfManager = this.pdfManager;
  46433. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46434. []);
  46435. var resourcesPromise = this.loadResources([
  46436. 'ExtGState',
  46437. 'XObject',
  46438. 'Font'
  46439. ]);
  46440. var dataPromises = Promise.all([contentStreamPromise,
  46441. resourcesPromise]);
  46442. return dataPromises.then(function(data) {
  46443. var contentStream = data[0];
  46444. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  46445. handler, self.pageIndex,
  46446. self.uniquePrefix,
  46447. self.idCounters,
  46448. self.fontCache,
  46449. self.evaluatorOptions);
  46450. return partialEvaluator.getTextContent(contentStream,
  46451. task,
  46452. self.resources,
  46453. /* stateManager = */ null,
  46454. normalizeWhitespace,
  46455. combineTextItems);
  46456. });
  46457. },
  46458. getAnnotationsData: function Page_getAnnotationsData(intent) {
  46459. var annotations = this.annotations;
  46460. var annotationsData = [];
  46461. for (var i = 0, n = annotations.length; i < n; ++i) {
  46462. if (intent) {
  46463. if (!(intent === 'display' && annotations[i].viewable) &&
  46464. !(intent === 'print' && annotations[i].printable)) {
  46465. continue;
  46466. }
  46467. }
  46468. annotationsData.push(annotations[i].data);
  46469. }
  46470. return annotationsData;
  46471. },
  46472. get annotations() {
  46473. var annotations = [];
  46474. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  46475. var annotationFactory = new AnnotationFactory();
  46476. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  46477. var annotationRef = annotationRefs[i];
  46478. var annotation = annotationFactory.create(this.xref, annotationRef,
  46479. this.uniquePrefix,
  46480. this.idCounters);
  46481. if (annotation) {
  46482. annotations.push(annotation);
  46483. }
  46484. }
  46485. return shadow(this, 'annotations', annotations);
  46486. }
  46487. };
  46488. return Page;
  46489. })();
  46490. /**
  46491. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  46492. * `PDFDoc`, this one doesn't have any job management code.
  46493. * Right now there exists one PDFDocument on the main thread + one object
  46494. * for each worker. If there is no worker support enabled, there are two
  46495. * `PDFDocument` objects on the main thread created.
  46496. */
  46497. var PDFDocument = (function PDFDocumentClosure() {
  46498. var FINGERPRINT_FIRST_BYTES = 1024;
  46499. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  46500. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  46501. function PDFDocument(pdfManager, arg, password) {
  46502. if (isStream(arg)) {
  46503. init.call(this, pdfManager, arg, password);
  46504. } else if (isArrayBuffer(arg)) {
  46505. init.call(this, pdfManager, new Stream(arg), password);
  46506. } else {
  46507. error('PDFDocument: Unknown argument type');
  46508. }
  46509. }
  46510. function init(pdfManager, stream, password) {
  46511. assert(stream.length > 0, 'stream must have data');
  46512. this.pdfManager = pdfManager;
  46513. this.stream = stream;
  46514. var xref = new XRef(this.stream, password, pdfManager);
  46515. this.xref = xref;
  46516. }
  46517. function find(stream, needle, limit, backwards) {
  46518. var pos = stream.pos;
  46519. var end = stream.end;
  46520. var strBuf = [];
  46521. if (pos + limit > end) {
  46522. limit = end - pos;
  46523. }
  46524. for (var n = 0; n < limit; ++n) {
  46525. strBuf.push(String.fromCharCode(stream.getByte()));
  46526. }
  46527. var str = strBuf.join('');
  46528. stream.pos = pos;
  46529. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  46530. if (index === -1) {
  46531. return false; /* not found */
  46532. }
  46533. stream.pos += index;
  46534. return true; /* found */
  46535. }
  46536. var DocumentInfoValidators = {
  46537. get entries() {
  46538. // Lazily build this since all the validation functions below are not
  46539. // defined until after this file loads.
  46540. return shadow(this, 'entries', {
  46541. Title: isString,
  46542. Author: isString,
  46543. Subject: isString,
  46544. Keywords: isString,
  46545. Creator: isString,
  46546. Producer: isString,
  46547. CreationDate: isString,
  46548. ModDate: isString,
  46549. Trapped: isName
  46550. });
  46551. }
  46552. };
  46553. PDFDocument.prototype = {
  46554. parse: function PDFDocument_parse(recoveryMode) {
  46555. this.setup(recoveryMode);
  46556. var version = this.catalog.catDict.get('Version');
  46557. if (isName(version)) {
  46558. this.pdfFormatVersion = version.name;
  46559. }
  46560. try {
  46561. // checking if AcroForm is present
  46562. this.acroForm = this.catalog.catDict.get('AcroForm');
  46563. if (this.acroForm) {
  46564. this.xfa = this.acroForm.get('XFA');
  46565. var fields = this.acroForm.get('Fields');
  46566. if ((!fields || !isArray(fields) || fields.length === 0) &&
  46567. !this.xfa) {
  46568. // no fields and no XFA -- not a form (?)
  46569. this.acroForm = null;
  46570. }
  46571. }
  46572. } catch (ex) {
  46573. info('Something wrong with AcroForm entry');
  46574. this.acroForm = null;
  46575. }
  46576. },
  46577. get linearization() {
  46578. var linearization = null;
  46579. if (this.stream.length) {
  46580. try {
  46581. linearization = Linearization.create(this.stream);
  46582. } catch (err) {
  46583. if (err instanceof MissingDataException) {
  46584. throw err;
  46585. }
  46586. info(err);
  46587. }
  46588. }
  46589. // shadow the prototype getter with a data property
  46590. return shadow(this, 'linearization', linearization);
  46591. },
  46592. get startXRef() {
  46593. var stream = this.stream;
  46594. var startXRef = 0;
  46595. var linearization = this.linearization;
  46596. if (linearization) {
  46597. // Find end of first obj.
  46598. stream.reset();
  46599. if (find(stream, 'endobj', 1024)) {
  46600. startXRef = stream.pos + 6;
  46601. }
  46602. } else {
  46603. // Find startxref by jumping backward from the end of the file.
  46604. var step = 1024;
  46605. var found = false, pos = stream.end;
  46606. while (!found && pos > 0) {
  46607. pos -= step - 'startxref'.length;
  46608. if (pos < 0) {
  46609. pos = 0;
  46610. }
  46611. stream.pos = pos;
  46612. found = find(stream, 'startxref', step, true);
  46613. }
  46614. if (found) {
  46615. stream.skip(9);
  46616. var ch;
  46617. do {
  46618. ch = stream.getByte();
  46619. } while (isSpace(ch));
  46620. var str = '';
  46621. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  46622. str += String.fromCharCode(ch);
  46623. ch = stream.getByte();
  46624. }
  46625. startXRef = parseInt(str, 10);
  46626. if (isNaN(startXRef)) {
  46627. startXRef = 0;
  46628. }
  46629. }
  46630. }
  46631. // shadow the prototype getter with a data property
  46632. return shadow(this, 'startXRef', startXRef);
  46633. },
  46634. get mainXRefEntriesOffset() {
  46635. var mainXRefEntriesOffset = 0;
  46636. var linearization = this.linearization;
  46637. if (linearization) {
  46638. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  46639. }
  46640. // shadow the prototype getter with a data property
  46641. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  46642. },
  46643. // Find the header, remove leading garbage and setup the stream
  46644. // starting from the header.
  46645. checkHeader: function PDFDocument_checkHeader() {
  46646. var stream = this.stream;
  46647. stream.reset();
  46648. if (find(stream, '%PDF-', 1024)) {
  46649. // Found the header, trim off any garbage before it.
  46650. stream.moveStart();
  46651. // Reading file format version
  46652. var MAX_VERSION_LENGTH = 12;
  46653. var version = '', ch;
  46654. while ((ch = stream.getByte()) > 0x20) { // SPACE
  46655. if (version.length >= MAX_VERSION_LENGTH) {
  46656. break;
  46657. }
  46658. version += String.fromCharCode(ch);
  46659. }
  46660. if (!this.pdfFormatVersion) {
  46661. // removing "%PDF-"-prefix
  46662. this.pdfFormatVersion = version.substring(5);
  46663. }
  46664. return;
  46665. }
  46666. // May not be a PDF file, continue anyway.
  46667. },
  46668. parseStartXRef: function PDFDocument_parseStartXRef() {
  46669. var startXRef = this.startXRef;
  46670. this.xref.setStartXRef(startXRef);
  46671. },
  46672. setup: function PDFDocument_setup(recoveryMode) {
  46673. this.xref.parse(recoveryMode);
  46674. var self = this;
  46675. var pageFactory = {
  46676. createPage: function (pageIndex, dict, ref, fontCache) {
  46677. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  46678. fontCache);
  46679. }
  46680. };
  46681. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  46682. },
  46683. get numPages() {
  46684. var linearization = this.linearization;
  46685. var num = linearization ? linearization.numPages : this.catalog.numPages;
  46686. // shadow the prototype getter
  46687. return shadow(this, 'numPages', num);
  46688. },
  46689. get documentInfo() {
  46690. var docInfo = {
  46691. PDFFormatVersion: this.pdfFormatVersion,
  46692. IsAcroFormPresent: !!this.acroForm,
  46693. IsXFAPresent: !!this.xfa
  46694. };
  46695. var infoDict;
  46696. try {
  46697. infoDict = this.xref.trailer.get('Info');
  46698. } catch (err) {
  46699. info('The document information dictionary is invalid.');
  46700. }
  46701. if (infoDict) {
  46702. var validEntries = DocumentInfoValidators.entries;
  46703. // Only fill the document info with valid entries from the spec.
  46704. for (var key in validEntries) {
  46705. if (infoDict.has(key)) {
  46706. var value = infoDict.get(key);
  46707. // Make sure the value conforms to the spec.
  46708. if (validEntries[key](value)) {
  46709. docInfo[key] = (typeof value !== 'string' ?
  46710. value : stringToPDFString(value));
  46711. } else {
  46712. info('Bad value in document info for "' + key + '"');
  46713. }
  46714. }
  46715. }
  46716. }
  46717. return shadow(this, 'documentInfo', docInfo);
  46718. },
  46719. get fingerprint() {
  46720. var xref = this.xref, hash, fileID = '';
  46721. var idArray = xref.trailer.get('ID');
  46722. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  46723. idArray[0] !== EMPTY_FINGERPRINT) {
  46724. hash = stringToBytes(idArray[0]);
  46725. } else {
  46726. if (this.stream.ensureRange) {
  46727. this.stream.ensureRange(0,
  46728. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  46729. }
  46730. hash = calculateMD5(this.stream.bytes.subarray(0,
  46731. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  46732. }
  46733. for (var i = 0, n = hash.length; i < n; i++) {
  46734. var hex = hash[i].toString(16);
  46735. fileID += hex.length === 1 ? '0' + hex : hex;
  46736. }
  46737. return shadow(this, 'fingerprint', fileID);
  46738. },
  46739. getPage: function PDFDocument_getPage(pageIndex) {
  46740. return this.catalog.getPage(pageIndex);
  46741. },
  46742. cleanup: function PDFDocument_cleanup() {
  46743. return this.catalog.cleanup();
  46744. }
  46745. };
  46746. return PDFDocument;
  46747. })();
  46748. exports.Page = Page;
  46749. exports.PDFDocument = PDFDocument;
  46750. }));
  46751. (function (root, factory) {
  46752. {
  46753. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  46754. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  46755. root.pdfjsCoreDocument);
  46756. }
  46757. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  46758. coreDocument) {
  46759. var NotImplementedException = sharedUtil.NotImplementedException;
  46760. var MissingDataException = sharedUtil.MissingDataException;
  46761. var createPromiseCapability = sharedUtil.createPromiseCapability;
  46762. var Util = sharedUtil.Util;
  46763. var Stream = coreStream.Stream;
  46764. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  46765. var PDFDocument = coreDocument.PDFDocument;
  46766. var BasePdfManager = (function BasePdfManagerClosure() {
  46767. function BasePdfManager() {
  46768. throw new Error('Cannot initialize BaseManagerManager');
  46769. }
  46770. BasePdfManager.prototype = {
  46771. get docId() {
  46772. return this._docId;
  46773. },
  46774. onLoadedStream: function BasePdfManager_onLoadedStream() {
  46775. throw new NotImplementedException();
  46776. },
  46777. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  46778. return this.ensure(this.pdfDocument, prop, args);
  46779. },
  46780. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  46781. return this.ensure(this.pdfDocument.xref, prop, args);
  46782. },
  46783. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  46784. return this.ensure(this.pdfDocument.catalog, prop, args);
  46785. },
  46786. getPage: function BasePdfManager_getPage(pageIndex) {
  46787. return this.pdfDocument.getPage(pageIndex);
  46788. },
  46789. cleanup: function BasePdfManager_cleanup() {
  46790. return this.pdfDocument.cleanup();
  46791. },
  46792. ensure: function BasePdfManager_ensure(obj, prop, args) {
  46793. return new NotImplementedException();
  46794. },
  46795. requestRange: function BasePdfManager_requestRange(begin, end) {
  46796. return new NotImplementedException();
  46797. },
  46798. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  46799. return new NotImplementedException();
  46800. },
  46801. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  46802. return new NotImplementedException();
  46803. },
  46804. updatePassword: function BasePdfManager_updatePassword(password) {
  46805. this.pdfDocument.xref.password = this.password = password;
  46806. if (this._passwordChangedCapability) {
  46807. this._passwordChangedCapability.resolve();
  46808. }
  46809. },
  46810. passwordChanged: function BasePdfManager_passwordChanged() {
  46811. this._passwordChangedCapability = createPromiseCapability();
  46812. return this._passwordChangedCapability.promise;
  46813. },
  46814. terminate: function BasePdfManager_terminate() {
  46815. return new NotImplementedException();
  46816. }
  46817. };
  46818. return BasePdfManager;
  46819. })();
  46820. var LocalPdfManager = (function LocalPdfManagerClosure() {
  46821. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  46822. this._docId = docId;
  46823. this.evaluatorOptions = evaluatorOptions;
  46824. var stream = new Stream(data);
  46825. this.pdfDocument = new PDFDocument(this, stream, password);
  46826. this._loadedStreamCapability = createPromiseCapability();
  46827. this._loadedStreamCapability.resolve(stream);
  46828. }
  46829. Util.inherit(LocalPdfManager, BasePdfManager, {
  46830. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  46831. return new Promise(function (resolve, reject) {
  46832. try {
  46833. var value = obj[prop];
  46834. var result;
  46835. if (typeof value === 'function') {
  46836. result = value.apply(obj, args);
  46837. } else {
  46838. result = value;
  46839. }
  46840. resolve(result);
  46841. } catch (e) {
  46842. reject(e);
  46843. }
  46844. });
  46845. },
  46846. requestRange: function LocalPdfManager_requestRange(begin, end) {
  46847. return Promise.resolve();
  46848. },
  46849. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  46850. return;
  46851. },
  46852. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  46853. return this._loadedStreamCapability.promise;
  46854. },
  46855. terminate: function LocalPdfManager_terminate() {
  46856. return;
  46857. }
  46858. });
  46859. return LocalPdfManager;
  46860. })();
  46861. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  46862. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  46863. this._docId = docId;
  46864. this.msgHandler = args.msgHandler;
  46865. this.evaluatorOptions = evaluatorOptions;
  46866. var params = {
  46867. msgHandler: args.msgHandler,
  46868. url: args.url,
  46869. length: args.length,
  46870. disableAutoFetch: args.disableAutoFetch,
  46871. rangeChunkSize: args.rangeChunkSize
  46872. };
  46873. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  46874. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  46875. args.password);
  46876. }
  46877. Util.inherit(NetworkPdfManager, BasePdfManager, {
  46878. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  46879. var pdfManager = this;
  46880. return new Promise(function (resolve, reject) {
  46881. function ensureHelper() {
  46882. try {
  46883. var result;
  46884. var value = obj[prop];
  46885. if (typeof value === 'function') {
  46886. result = value.apply(obj, args);
  46887. } else {
  46888. result = value;
  46889. }
  46890. resolve(result);
  46891. } catch(e) {
  46892. if (!(e instanceof MissingDataException)) {
  46893. reject(e);
  46894. return;
  46895. }
  46896. pdfManager.streamManager.requestRange(e.begin, e.end).
  46897. then(ensureHelper, reject);
  46898. }
  46899. }
  46900. ensureHelper();
  46901. });
  46902. },
  46903. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  46904. return this.streamManager.requestRange(begin, end);
  46905. },
  46906. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  46907. this.streamManager.requestAllChunks();
  46908. },
  46909. sendProgressiveData:
  46910. function NetworkPdfManager_sendProgressiveData(chunk) {
  46911. this.streamManager.onReceiveData({ chunk: chunk });
  46912. },
  46913. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  46914. return this.streamManager.onLoadedStream();
  46915. },
  46916. terminate: function NetworkPdfManager_terminate() {
  46917. this.streamManager.abort();
  46918. }
  46919. });
  46920. return NetworkPdfManager;
  46921. })();
  46922. exports.LocalPdfManager = LocalPdfManager;
  46923. exports.NetworkPdfManager = NetworkPdfManager;
  46924. }));
  46925. (function (root, factory) {
  46926. {
  46927. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  46928. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  46929. }
  46930. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  46931. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  46932. var InvalidPDFException = sharedUtil.InvalidPDFException;
  46933. var MessageHandler = sharedUtil.MessageHandler;
  46934. var MissingPDFException = sharedUtil.MissingPDFException;
  46935. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  46936. var PasswordException = sharedUtil.PasswordException;
  46937. var PasswordResponses = sharedUtil.PasswordResponses;
  46938. var UnknownErrorException = sharedUtil.UnknownErrorException;
  46939. var XRefParseException = sharedUtil.XRefParseException;
  46940. var arrayByteLength = sharedUtil.arrayByteLength;
  46941. var arraysToBytes = sharedUtil.arraysToBytes;
  46942. var assert = sharedUtil.assert;
  46943. var createPromiseCapability = sharedUtil.createPromiseCapability;
  46944. var error = sharedUtil.error;
  46945. var info = sharedUtil.info;
  46946. var warn = sharedUtil.warn;
  46947. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  46948. var Ref = corePrimitives.Ref;
  46949. var LocalPdfManager = corePdfManager.LocalPdfManager;
  46950. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  46951. var globalScope = sharedUtil.globalScope;
  46952. var WorkerTask = (function WorkerTaskClosure() {
  46953. function WorkerTask(name) {
  46954. this.name = name;
  46955. this.terminated = false;
  46956. this._capability = createPromiseCapability();
  46957. }
  46958. WorkerTask.prototype = {
  46959. get finished() {
  46960. return this._capability.promise;
  46961. },
  46962. finish: function () {
  46963. this._capability.resolve();
  46964. },
  46965. terminate: function () {
  46966. this.terminated = true;
  46967. },
  46968. ensureNotTerminated: function () {
  46969. if (this.terminated) {
  46970. throw new Error('Worker task was terminated');
  46971. }
  46972. }
  46973. };
  46974. return WorkerTask;
  46975. })();
  46976. /** @implements {IPDFStream} */
  46977. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  46978. function PDFWorkerStream(params, msgHandler) {
  46979. this._queuedChunks = [];
  46980. var initialData = params.initialData;
  46981. if (initialData && initialData.length > 0) {
  46982. this._queuedChunks.push(initialData);
  46983. }
  46984. this._msgHandler = msgHandler;
  46985. this._isRangeSupported = !(params.disableRange);
  46986. this._isStreamingSupported = !(params.disableStream);
  46987. this._contentLength = params.length;
  46988. this._fullRequestReader = null;
  46989. this._rangeReaders = [];
  46990. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  46991. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  46992. }
  46993. PDFWorkerStream.prototype = {
  46994. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  46995. if (args.begin === undefined) {
  46996. if (this._fullRequestReader) {
  46997. this._fullRequestReader._enqueue(args.chunk);
  46998. } else {
  46999. this._queuedChunks.push(args.chunk);
  47000. }
  47001. } else {
  47002. var found = this._rangeReaders.some(function (rangeReader) {
  47003. if (rangeReader._begin !== args.begin) {
  47004. return false;
  47005. }
  47006. rangeReader._enqueue(args.chunk);
  47007. return true;
  47008. });
  47009. assert(found);
  47010. }
  47011. },
  47012. _onProgress: function PDFWorkerStream_onProgress(evt) {
  47013. if (this._rangeReaders.length > 0) {
  47014. // Reporting to first range reader.
  47015. var firstReader = this._rangeReaders[0];
  47016. if (firstReader.onProgress) {
  47017. firstReader.onProgress({loaded: evt.loaded});
  47018. }
  47019. }
  47020. },
  47021. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  47022. var i = this._rangeReaders.indexOf(reader);
  47023. if (i >= 0) {
  47024. this._rangeReaders.splice(i, 1);
  47025. }
  47026. },
  47027. getFullReader: function PDFWorkerStream_getFullReader() {
  47028. assert(!this._fullRequestReader);
  47029. var queuedChunks = this._queuedChunks;
  47030. this._queuedChunks = null;
  47031. return new PDFWorkerStreamReader(this, queuedChunks);
  47032. },
  47033. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  47034. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  47035. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  47036. this._rangeReaders.push(reader);
  47037. return reader;
  47038. },
  47039. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  47040. if (this._fullRequestReader) {
  47041. this._fullRequestReader.cancel(reason);
  47042. }
  47043. var readers = this._rangeReaders.slice(0);
  47044. readers.forEach(function (rangeReader) {
  47045. rangeReader.cancel(reason);
  47046. });
  47047. }
  47048. };
  47049. /** @implements {IPDFStreamReader} */
  47050. function PDFWorkerStreamReader(stream, queuedChunks) {
  47051. this._stream = stream;
  47052. this._done = false;
  47053. this._queuedChunks = queuedChunks || [];
  47054. this._requests = [];
  47055. this._headersReady = Promise.resolve();
  47056. stream._fullRequestReader = this;
  47057. this.onProgress = null; // not used
  47058. }
  47059. PDFWorkerStreamReader.prototype = {
  47060. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  47061. if (this._done) {
  47062. return; // ignore new data
  47063. }
  47064. if (this._requests.length > 0) {
  47065. var requestCapability = this._requests.shift();
  47066. requestCapability.resolve({value: chunk, done: false});
  47067. return;
  47068. }
  47069. this._queuedChunks.push(chunk);
  47070. },
  47071. get headersReady() {
  47072. return this._headersReady;
  47073. },
  47074. get isRangeSupported() {
  47075. return this._stream._isRangeSupported;
  47076. },
  47077. get isStreamingSupported() {
  47078. return this._stream._isStreamingSupported;
  47079. },
  47080. get contentLength() {
  47081. return this._stream._contentLength;
  47082. },
  47083. read: function PDFWorkerStreamReader_read() {
  47084. if (this._queuedChunks.length > 0) {
  47085. var chunk = this._queuedChunks.shift();
  47086. return Promise.resolve({value: chunk, done: false});
  47087. }
  47088. if (this._done) {
  47089. return Promise.resolve({value: undefined, done: true});
  47090. }
  47091. var requestCapability = createPromiseCapability();
  47092. this._requests.push(requestCapability);
  47093. return requestCapability.promise;
  47094. },
  47095. cancel: function PDFWorkerStreamReader_cancel(reason) {
  47096. this._done = true;
  47097. this._requests.forEach(function (requestCapability) {
  47098. requestCapability.resolve({value: undefined, done: true});
  47099. });
  47100. this._requests = [];
  47101. }
  47102. };
  47103. /** @implements {IPDFStreamRangeReader} */
  47104. function PDFWorkerStreamRangeReader(stream, begin, end) {
  47105. this._stream = stream;
  47106. this._begin = begin;
  47107. this._end = end;
  47108. this._queuedChunk = null;
  47109. this._requests = [];
  47110. this._done = false;
  47111. this.onProgress = null;
  47112. }
  47113. PDFWorkerStreamRangeReader.prototype = {
  47114. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  47115. if (this._done) {
  47116. return; // ignore new data
  47117. }
  47118. if (this._requests.length === 0) {
  47119. this._queuedChunk = chunk;
  47120. } else {
  47121. var requestsCapability = this._requests.shift();
  47122. requestsCapability.resolve({value: chunk, done: false});
  47123. this._requests.forEach(function (requestCapability) {
  47124. requestCapability.resolve({value: undefined, done: true});
  47125. });
  47126. this._requests = [];
  47127. }
  47128. this._done = true;
  47129. this._stream._removeRangeReader(this);
  47130. },
  47131. get isStreamingSupported() {
  47132. return false;
  47133. },
  47134. read: function PDFWorkerStreamRangeReader_read() {
  47135. if (this._queuedChunk) {
  47136. return Promise.resolve({value: this._queuedChunk, done: false});
  47137. }
  47138. if (this._done) {
  47139. return Promise.resolve({value: undefined, done: true});
  47140. }
  47141. var requestCapability = createPromiseCapability();
  47142. this._requests.push(requestCapability);
  47143. return requestCapability.promise;
  47144. },
  47145. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  47146. this._done = true;
  47147. this._requests.forEach(function (requestCapability) {
  47148. requestCapability.resolve({value: undefined, done: true});
  47149. });
  47150. this._requests = [];
  47151. this._stream._removeRangeReader(this);
  47152. }
  47153. };
  47154. return PDFWorkerStream;
  47155. })();
  47156. /** @type IPDFStream */
  47157. var PDFNetworkStream;
  47158. /**
  47159. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  47160. * @param {IPDFStream} cls - the PDF data transport.
  47161. */
  47162. function setPDFNetworkStreamClass(cls) {
  47163. PDFNetworkStream = cls;
  47164. }
  47165. var WorkerMessageHandler = {
  47166. setup: function wphSetup(handler, port) {
  47167. var testMessageProcessed = false;
  47168. handler.on('test', function wphSetupTest(data) {
  47169. if (testMessageProcessed) {
  47170. return; // we already processed 'test' message once
  47171. }
  47172. testMessageProcessed = true;
  47173. // check if Uint8Array can be sent to worker
  47174. if (!(data instanceof Uint8Array)) {
  47175. handler.send('test', 'main', false);
  47176. return;
  47177. }
  47178. // making sure postMessage transfers are working
  47179. var supportTransfers = data[0] === 255;
  47180. handler.postMessageTransfers = supportTransfers;
  47181. // check if the response property is supported by xhr
  47182. var xhr = new XMLHttpRequest();
  47183. var responseExists = 'response' in xhr;
  47184. // check if the property is actually implemented
  47185. try {
  47186. var dummy = xhr.responseType;
  47187. } catch (e) {
  47188. responseExists = false;
  47189. }
  47190. if (!responseExists) {
  47191. handler.send('test', false);
  47192. return;
  47193. }
  47194. handler.send('test', {
  47195. supportTypedArray: true,
  47196. supportTransfers: supportTransfers
  47197. });
  47198. });
  47199. handler.on('configure', function wphConfigure(data) {
  47200. setVerbosityLevel(data.verbosity);
  47201. });
  47202. handler.on('GetDocRequest', function wphSetupDoc(data) {
  47203. return WorkerMessageHandler.createDocumentHandler(data, port);
  47204. });
  47205. },
  47206. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  47207. // This context is actually holds references on pdfManager and handler,
  47208. // until the latter is destroyed.
  47209. var pdfManager;
  47210. var terminated = false;
  47211. var cancelXHRs = null;
  47212. var WorkerTasks = [];
  47213. var docId = docParams.docId;
  47214. var workerHandlerName = docParams.docId + '_worker';
  47215. var handler = new MessageHandler(workerHandlerName, docId, port);
  47216. // Ensure that postMessage transfers are correctly enabled/disabled,
  47217. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  47218. handler.postMessageTransfers = docParams.postMessageTransfers;
  47219. function ensureNotTerminated() {
  47220. if (terminated) {
  47221. throw new Error('Worker was terminated');
  47222. }
  47223. }
  47224. function startWorkerTask(task) {
  47225. WorkerTasks.push(task);
  47226. }
  47227. function finishWorkerTask(task) {
  47228. task.finish();
  47229. var i = WorkerTasks.indexOf(task);
  47230. WorkerTasks.splice(i, 1);
  47231. }
  47232. function loadDocument(recoveryMode) {
  47233. var loadDocumentCapability = createPromiseCapability();
  47234. var parseSuccess = function parseSuccess() {
  47235. var numPagesPromise = pdfManager.ensureDoc('numPages');
  47236. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  47237. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  47238. Promise.all([numPagesPromise, fingerprintPromise,
  47239. encryptedPromise]).then(function onDocReady(results) {
  47240. var doc = {
  47241. numPages: results[0],
  47242. fingerprint: results[1],
  47243. encrypted: !!results[2],
  47244. };
  47245. loadDocumentCapability.resolve(doc);
  47246. },
  47247. parseFailure);
  47248. };
  47249. var parseFailure = function parseFailure(e) {
  47250. loadDocumentCapability.reject(e);
  47251. };
  47252. pdfManager.ensureDoc('checkHeader', []).then(function() {
  47253. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  47254. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  47255. parseSuccess, parseFailure);
  47256. }, parseFailure);
  47257. }, parseFailure);
  47258. return loadDocumentCapability.promise;
  47259. }
  47260. function getPdfManager(data, evaluatorOptions) {
  47261. var pdfManagerCapability = createPromiseCapability();
  47262. var pdfManager;
  47263. var source = data.source;
  47264. if (source.data) {
  47265. try {
  47266. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  47267. evaluatorOptions);
  47268. pdfManagerCapability.resolve(pdfManager);
  47269. } catch (ex) {
  47270. pdfManagerCapability.reject(ex);
  47271. }
  47272. return pdfManagerCapability.promise;
  47273. }
  47274. var pdfStream;
  47275. try {
  47276. if (source.chunkedViewerLoading) {
  47277. pdfStream = new PDFWorkerStream(source, handler);
  47278. } else {
  47279. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  47280. pdfStream = new PDFNetworkStream(data);
  47281. }
  47282. } catch (ex) {
  47283. pdfManagerCapability.reject(ex);
  47284. return pdfManagerCapability.promise;
  47285. }
  47286. var fullRequest = pdfStream.getFullReader();
  47287. fullRequest.headersReady.then(function () {
  47288. if (!fullRequest.isStreamingSupported ||
  47289. !fullRequest.isRangeSupported) {
  47290. // If stream or range are disabled, it's our only way to report
  47291. // loading progress.
  47292. fullRequest.onProgress = function (evt) {
  47293. handler.send('DocProgress', {
  47294. loaded: evt.loaded,
  47295. total: evt.total
  47296. });
  47297. };
  47298. }
  47299. if (!fullRequest.isRangeSupported) {
  47300. return;
  47301. }
  47302. // We don't need auto-fetch when streaming is enabled.
  47303. var disableAutoFetch = source.disableAutoFetch ||
  47304. fullRequest.isStreamingSupported;
  47305. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  47306. msgHandler: handler,
  47307. url: source.url,
  47308. password: source.password,
  47309. length: fullRequest.contentLength,
  47310. disableAutoFetch: disableAutoFetch,
  47311. rangeChunkSize: source.rangeChunkSize
  47312. }, evaluatorOptions);
  47313. pdfManagerCapability.resolve(pdfManager);
  47314. cancelXHRs = null;
  47315. }).catch(function (reason) {
  47316. pdfManagerCapability.reject(reason);
  47317. cancelXHRs = null;
  47318. });
  47319. var cachedChunks = [], loaded = 0;
  47320. var flushChunks = function () {
  47321. var pdfFile = arraysToBytes(cachedChunks);
  47322. if (source.length && pdfFile.length !== source.length) {
  47323. warn('reported HTTP length is different from actual');
  47324. }
  47325. // the data is array, instantiating directly from it
  47326. try {
  47327. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  47328. evaluatorOptions);
  47329. pdfManagerCapability.resolve(pdfManager);
  47330. } catch (ex) {
  47331. pdfManagerCapability.reject(ex);
  47332. }
  47333. cachedChunks = [];
  47334. };
  47335. var readPromise = new Promise(function (resolve, reject) {
  47336. var readChunk = function (chunk) {
  47337. try {
  47338. ensureNotTerminated();
  47339. if (chunk.done) {
  47340. if (!pdfManager) {
  47341. flushChunks();
  47342. }
  47343. cancelXHRs = null;
  47344. return;
  47345. }
  47346. var data = chunk.value;
  47347. loaded += arrayByteLength(data);
  47348. if (!fullRequest.isStreamingSupported) {
  47349. handler.send('DocProgress', {
  47350. loaded: loaded,
  47351. total: Math.max(loaded, fullRequest.contentLength || 0)
  47352. });
  47353. }
  47354. if (pdfManager) {
  47355. pdfManager.sendProgressiveData(data);
  47356. } else {
  47357. cachedChunks.push(data);
  47358. }
  47359. fullRequest.read().then(readChunk, reject);
  47360. } catch (e) {
  47361. reject(e);
  47362. }
  47363. };
  47364. fullRequest.read().then(readChunk, reject);
  47365. });
  47366. readPromise.catch(function (e) {
  47367. pdfManagerCapability.reject(e);
  47368. cancelXHRs = null;
  47369. });
  47370. cancelXHRs = function () {
  47371. pdfStream.cancelAllRequests('abort');
  47372. };
  47373. return pdfManagerCapability.promise;
  47374. }
  47375. var setupDoc = function(data) {
  47376. var onSuccess = function(doc) {
  47377. ensureNotTerminated();
  47378. handler.send('GetDoc', { pdfInfo: doc });
  47379. };
  47380. var onFailure = function(e) {
  47381. if (e instanceof PasswordException) {
  47382. if (e.code === PasswordResponses.NEED_PASSWORD) {
  47383. handler.send('NeedPassword', e);
  47384. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  47385. handler.send('IncorrectPassword', e);
  47386. }
  47387. } else if (e instanceof InvalidPDFException) {
  47388. handler.send('InvalidPDF', e);
  47389. } else if (e instanceof MissingPDFException) {
  47390. handler.send('MissingPDF', e);
  47391. } else if (e instanceof UnexpectedResponseException) {
  47392. handler.send('UnexpectedResponse', e);
  47393. } else {
  47394. handler.send('UnknownError',
  47395. new UnknownErrorException(e.message, e.toString()));
  47396. }
  47397. };
  47398. ensureNotTerminated();
  47399. var cMapOptions = {
  47400. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  47401. packed: data.cMapPacked === true
  47402. };
  47403. var evaluatorOptions = {
  47404. forceDataSchema: data.disableCreateObjectURL,
  47405. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  47406. disableFontFace: data.disableFontFace,
  47407. cMapOptions: cMapOptions
  47408. };
  47409. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  47410. if (terminated) {
  47411. // We were in a process of setting up the manager, but it got
  47412. // terminated in the middle.
  47413. newPdfManager.terminate();
  47414. throw new Error('Worker was terminated');
  47415. }
  47416. pdfManager = newPdfManager;
  47417. handler.send('PDFManagerReady', null);
  47418. pdfManager.onLoadedStream().then(function(stream) {
  47419. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  47420. });
  47421. }).then(function pdfManagerReady() {
  47422. ensureNotTerminated();
  47423. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  47424. ensureNotTerminated();
  47425. // Try again with recoveryMode == true
  47426. if (!(ex instanceof XRefParseException)) {
  47427. if (ex instanceof PasswordException) {
  47428. // after password exception prepare to receive a new password
  47429. // to repeat loading
  47430. pdfManager.passwordChanged().then(pdfManagerReady);
  47431. }
  47432. onFailure(ex);
  47433. return;
  47434. }
  47435. pdfManager.requestLoadedStream();
  47436. pdfManager.onLoadedStream().then(function() {
  47437. ensureNotTerminated();
  47438. loadDocument(true).then(onSuccess, onFailure);
  47439. });
  47440. }, onFailure);
  47441. }, onFailure);
  47442. };
  47443. handler.on('GetPage', function wphSetupGetPage(data) {
  47444. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47445. var rotatePromise = pdfManager.ensure(page, 'rotate');
  47446. var refPromise = pdfManager.ensure(page, 'ref');
  47447. var viewPromise = pdfManager.ensure(page, 'view');
  47448. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  47449. function(results) {
  47450. return {
  47451. rotate: results[0],
  47452. ref: results[1],
  47453. view: results[2]
  47454. };
  47455. });
  47456. });
  47457. });
  47458. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  47459. var ref = new Ref(data.ref.num, data.ref.gen);
  47460. var catalog = pdfManager.pdfDocument.catalog;
  47461. return catalog.getPageIndex(ref);
  47462. });
  47463. handler.on('GetDestinations',
  47464. function wphSetupGetDestinations(data) {
  47465. return pdfManager.ensureCatalog('destinations');
  47466. }
  47467. );
  47468. handler.on('GetDestination',
  47469. function wphSetupGetDestination(data) {
  47470. return pdfManager.ensureCatalog('getDestination', [data.id]);
  47471. }
  47472. );
  47473. handler.on('GetPageLabels',
  47474. function wphSetupGetPageLabels(data) {
  47475. return pdfManager.ensureCatalog('pageLabels');
  47476. }
  47477. );
  47478. handler.on('GetAttachments',
  47479. function wphSetupGetAttachments(data) {
  47480. return pdfManager.ensureCatalog('attachments');
  47481. }
  47482. );
  47483. handler.on('GetJavaScript',
  47484. function wphSetupGetJavaScript(data) {
  47485. return pdfManager.ensureCatalog('javaScript');
  47486. }
  47487. );
  47488. handler.on('GetOutline',
  47489. function wphSetupGetOutline(data) {
  47490. return pdfManager.ensureCatalog('documentOutline');
  47491. }
  47492. );
  47493. handler.on('GetMetadata',
  47494. function wphSetupGetMetadata(data) {
  47495. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  47496. pdfManager.ensureCatalog('metadata')]);
  47497. }
  47498. );
  47499. handler.on('GetData', function wphSetupGetData(data) {
  47500. pdfManager.requestLoadedStream();
  47501. return pdfManager.onLoadedStream().then(function(stream) {
  47502. return stream.bytes;
  47503. });
  47504. });
  47505. handler.on('GetStats',
  47506. function wphSetupGetStats(data) {
  47507. return pdfManager.pdfDocument.xref.stats;
  47508. }
  47509. );
  47510. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  47511. pdfManager.updatePassword(data);
  47512. });
  47513. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  47514. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47515. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  47516. });
  47517. });
  47518. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  47519. var pageIndex = data.pageIndex;
  47520. pdfManager.getPage(pageIndex).then(function(page) {
  47521. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  47522. startWorkerTask(task);
  47523. var pageNum = pageIndex + 1;
  47524. var start = Date.now();
  47525. // Pre compile the pdf page and fetch the fonts/images.
  47526. page.getOperatorList(handler, task, data.intent).then(
  47527. function(operatorList) {
  47528. finishWorkerTask(task);
  47529. info('page=' + pageNum + ' - getOperatorList: time=' +
  47530. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  47531. }, function(e) {
  47532. finishWorkerTask(task);
  47533. if (task.terminated) {
  47534. return; // ignoring errors from the terminated thread
  47535. }
  47536. // For compatibility with older behavior, generating unknown
  47537. // unsupported feature notification on errors.
  47538. handler.send('UnsupportedFeature',
  47539. {featureId: UNSUPPORTED_FEATURES.unknown});
  47540. var minimumStackMessage =
  47541. 'worker.js: while trying to getPage() and getOperatorList()';
  47542. var wrappedException;
  47543. // Turn the error into an obj that can be serialized
  47544. if (typeof e === 'string') {
  47545. wrappedException = {
  47546. message: e,
  47547. stack: minimumStackMessage
  47548. };
  47549. } else if (typeof e === 'object') {
  47550. wrappedException = {
  47551. message: e.message || e.toString(),
  47552. stack: e.stack || minimumStackMessage
  47553. };
  47554. } else {
  47555. wrappedException = {
  47556. message: 'Unknown exception type: ' + (typeof e),
  47557. stack: minimumStackMessage
  47558. };
  47559. }
  47560. handler.send('PageError', {
  47561. pageNum: pageNum,
  47562. error: wrappedException,
  47563. intent: data.intent
  47564. });
  47565. });
  47566. });
  47567. }, this);
  47568. handler.on('GetTextContent', function wphExtractText(data) {
  47569. var pageIndex = data.pageIndex;
  47570. var normalizeWhitespace = data.normalizeWhitespace;
  47571. var combineTextItems = data.combineTextItems;
  47572. return pdfManager.getPage(pageIndex).then(function(page) {
  47573. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  47574. startWorkerTask(task);
  47575. var pageNum = pageIndex + 1;
  47576. var start = Date.now();
  47577. return page.extractTextContent(task, normalizeWhitespace,
  47578. combineTextItems).then(
  47579. function(textContent) {
  47580. finishWorkerTask(task);
  47581. info('text indexing: page=' + pageNum + ' - time=' +
  47582. (Date.now() - start) + 'ms');
  47583. return textContent;
  47584. }, function (reason) {
  47585. finishWorkerTask(task);
  47586. if (task.terminated) {
  47587. return; // ignoring errors from the terminated thread
  47588. }
  47589. throw reason;
  47590. });
  47591. });
  47592. });
  47593. handler.on('Cleanup', function wphCleanup(data) {
  47594. return pdfManager.cleanup();
  47595. });
  47596. handler.on('Terminate', function wphTerminate(data) {
  47597. terminated = true;
  47598. if (pdfManager) {
  47599. pdfManager.terminate();
  47600. pdfManager = null;
  47601. }
  47602. if (cancelXHRs) {
  47603. cancelXHRs();
  47604. }
  47605. var waitOn = [];
  47606. WorkerTasks.forEach(function (task) {
  47607. waitOn.push(task.finished);
  47608. task.terminate();
  47609. });
  47610. return Promise.all(waitOn).then(function () {
  47611. // Notice that even if we destroying handler, resolved response promise
  47612. // must be sent back.
  47613. handler.destroy();
  47614. handler = null;
  47615. });
  47616. });
  47617. handler.on('Ready', function wphReady(data) {
  47618. setupDoc(docParams);
  47619. docParams = null; // we don't need docParams anymore -- saving memory.
  47620. });
  47621. return workerHandlerName;
  47622. }
  47623. };
  47624. function initializeWorker() {
  47625. if (!('console' in globalScope)) {
  47626. var consoleTimer = {};
  47627. var workerConsole = {
  47628. log: function log() {
  47629. var args = Array.prototype.slice.call(arguments);
  47630. globalScope.postMessage({
  47631. targetName: 'main',
  47632. action: 'console_log',
  47633. data: args
  47634. });
  47635. },
  47636. error: function error() {
  47637. var args = Array.prototype.slice.call(arguments);
  47638. globalScope.postMessage({
  47639. targetName: 'main',
  47640. action: 'console_error',
  47641. data: args
  47642. });
  47643. throw 'pdf.js execution error';
  47644. },
  47645. time: function time(name) {
  47646. consoleTimer[name] = Date.now();
  47647. },
  47648. timeEnd: function timeEnd(name) {
  47649. var time = consoleTimer[name];
  47650. if (!time) {
  47651. error('Unknown timer name ' + name);
  47652. }
  47653. this.log('Timer:', name, Date.now() - time);
  47654. }
  47655. };
  47656. globalScope.console = workerConsole;
  47657. }
  47658. var handler = new MessageHandler('worker', 'main', self);
  47659. WorkerMessageHandler.setup(handler, self);
  47660. handler.send('ready', null);
  47661. }
  47662. // Worker thread (and not node.js)?
  47663. if (typeof window === 'undefined' &&
  47664. !(typeof module !== 'undefined' && module.require)) {
  47665. initializeWorker();
  47666. }
  47667. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  47668. exports.WorkerTask = WorkerTask;
  47669. exports.WorkerMessageHandler = WorkerMessageHandler;
  47670. }));
  47671. var NetworkManager = (function NetworkManagerClosure() {
  47672. var OK_RESPONSE = 200;
  47673. var PARTIAL_CONTENT_RESPONSE = 206;
  47674. function NetworkManager(url, args) {
  47675. this.url = url;
  47676. args = args || {};
  47677. this.isHttp = /^https?:/i.test(url);
  47678. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  47679. this.withCredentials = args.withCredentials || false;
  47680. this.getXhr = args.getXhr ||
  47681. function NetworkManager_getXhr() {
  47682. return new XMLHttpRequest();
  47683. };
  47684. this.currXhrId = 0;
  47685. this.pendingRequests = Object.create(null);
  47686. this.loadedRequests = Object.create(null);
  47687. }
  47688. function getArrayBuffer(xhr) {
  47689. var data = xhr.response;
  47690. if (typeof data !== 'string') {
  47691. return data;
  47692. }
  47693. var length = data.length;
  47694. var array = new Uint8Array(length);
  47695. for (var i = 0; i < length; i++) {
  47696. array[i] = data.charCodeAt(i) & 0xFF;
  47697. }
  47698. return array.buffer;
  47699. }
  47700. var supportsMozChunked = (function supportsMozChunkedClosure() {
  47701. try {
  47702. var x = new XMLHttpRequest();
  47703. // Firefox 37- required .open() to be called before setting responseType.
  47704. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  47705. // Even though the URL is not visited, .open() could fail if the URL is
  47706. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  47707. // When this error occurs, this feature detection method will mistakenly
  47708. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  47709. x.open('GET', 'https://example.com');
  47710. x.responseType = 'moz-chunked-arraybuffer';
  47711. return x.responseType === 'moz-chunked-arraybuffer';
  47712. } catch (e) {
  47713. return false;
  47714. }
  47715. })();
  47716. NetworkManager.prototype = {
  47717. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  47718. var args = {
  47719. begin: begin,
  47720. end: end
  47721. };
  47722. for (var prop in listeners) {
  47723. args[prop] = listeners[prop];
  47724. }
  47725. return this.request(args);
  47726. },
  47727. requestFull: function NetworkManager_requestFull(listeners) {
  47728. return this.request(listeners);
  47729. },
  47730. request: function NetworkManager_request(args) {
  47731. var xhr = this.getXhr();
  47732. var xhrId = this.currXhrId++;
  47733. var pendingRequest = this.pendingRequests[xhrId] = {
  47734. xhr: xhr
  47735. };
  47736. xhr.open('GET', this.url);
  47737. xhr.withCredentials = this.withCredentials;
  47738. for (var property in this.httpHeaders) {
  47739. var value = this.httpHeaders[property];
  47740. if (typeof value === 'undefined') {
  47741. continue;
  47742. }
  47743. xhr.setRequestHeader(property, value);
  47744. }
  47745. if (this.isHttp && 'begin' in args && 'end' in args) {
  47746. var rangeStr = args.begin + '-' + (args.end - 1);
  47747. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  47748. pendingRequest.expectedStatus = 206;
  47749. } else {
  47750. pendingRequest.expectedStatus = 200;
  47751. }
  47752. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  47753. if (useMozChunkedLoading) {
  47754. xhr.responseType = 'moz-chunked-arraybuffer';
  47755. pendingRequest.onProgressiveData = args.onProgressiveData;
  47756. pendingRequest.mozChunked = true;
  47757. } else {
  47758. xhr.responseType = 'arraybuffer';
  47759. }
  47760. if (args.onError) {
  47761. xhr.onerror = function(evt) {
  47762. args.onError(xhr.status);
  47763. };
  47764. }
  47765. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  47766. xhr.onprogress = this.onProgress.bind(this, xhrId);
  47767. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  47768. pendingRequest.onDone = args.onDone;
  47769. pendingRequest.onError = args.onError;
  47770. pendingRequest.onProgress = args.onProgress;
  47771. xhr.send(null);
  47772. return xhrId;
  47773. },
  47774. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  47775. var pendingRequest = this.pendingRequests[xhrId];
  47776. if (!pendingRequest) {
  47777. // Maybe abortRequest was called...
  47778. return;
  47779. }
  47780. if (pendingRequest.mozChunked) {
  47781. var chunk = getArrayBuffer(pendingRequest.xhr);
  47782. pendingRequest.onProgressiveData(chunk);
  47783. }
  47784. var onProgress = pendingRequest.onProgress;
  47785. if (onProgress) {
  47786. onProgress(evt);
  47787. }
  47788. },
  47789. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  47790. var pendingRequest = this.pendingRequests[xhrId];
  47791. if (!pendingRequest) {
  47792. // Maybe abortRequest was called...
  47793. return;
  47794. }
  47795. var xhr = pendingRequest.xhr;
  47796. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  47797. pendingRequest.onHeadersReceived();
  47798. delete pendingRequest.onHeadersReceived;
  47799. }
  47800. if (xhr.readyState !== 4) {
  47801. return;
  47802. }
  47803. if (!(xhrId in this.pendingRequests)) {
  47804. // The XHR request might have been aborted in onHeadersReceived()
  47805. // callback, in which case we should abort request
  47806. return;
  47807. }
  47808. delete this.pendingRequests[xhrId];
  47809. // success status == 0 can be on ftp, file and other protocols
  47810. if (xhr.status === 0 && this.isHttp) {
  47811. if (pendingRequest.onError) {
  47812. pendingRequest.onError(xhr.status);
  47813. }
  47814. return;
  47815. }
  47816. var xhrStatus = xhr.status || OK_RESPONSE;
  47817. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  47818. // "A server MAY ignore the Range header". This means it's possible to
  47819. // get a 200 rather than a 206 response from a range request.
  47820. var ok_response_on_range_request =
  47821. xhrStatus === OK_RESPONSE &&
  47822. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  47823. if (!ok_response_on_range_request &&
  47824. xhrStatus !== pendingRequest.expectedStatus) {
  47825. if (pendingRequest.onError) {
  47826. pendingRequest.onError(xhr.status);
  47827. }
  47828. return;
  47829. }
  47830. this.loadedRequests[xhrId] = true;
  47831. var chunk = getArrayBuffer(xhr);
  47832. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  47833. var rangeHeader = xhr.getResponseHeader('Content-Range');
  47834. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  47835. var begin = parseInt(matches[1], 10);
  47836. pendingRequest.onDone({
  47837. begin: begin,
  47838. chunk: chunk
  47839. });
  47840. } else if (pendingRequest.onProgressiveData) {
  47841. pendingRequest.onDone(null);
  47842. } else if (chunk) {
  47843. pendingRequest.onDone({
  47844. begin: 0,
  47845. chunk: chunk
  47846. });
  47847. } else if (pendingRequest.onError) {
  47848. pendingRequest.onError(xhr.status);
  47849. }
  47850. },
  47851. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  47852. for (var xhrId in this.pendingRequests) {
  47853. return true;
  47854. }
  47855. return false;
  47856. },
  47857. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  47858. return this.pendingRequests[xhrId].xhr;
  47859. },
  47860. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  47861. return !!(this.pendingRequests[xhrId].onProgressiveData);
  47862. },
  47863. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  47864. return xhrId in this.pendingRequests;
  47865. },
  47866. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  47867. return xhrId in this.loadedRequests;
  47868. },
  47869. abortAllRequests: function NetworkManager_abortAllRequests() {
  47870. for (var xhrId in this.pendingRequests) {
  47871. this.abortRequest(xhrId | 0);
  47872. }
  47873. },
  47874. abortRequest: function NetworkManager_abortRequest(xhrId) {
  47875. var xhr = this.pendingRequests[xhrId].xhr;
  47876. delete this.pendingRequests[xhrId];
  47877. xhr.abort();
  47878. }
  47879. };
  47880. return NetworkManager;
  47881. })();
  47882. (function (root, factory) {
  47883. {
  47884. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  47885. root.pdfjsCoreWorker);
  47886. }
  47887. }(this, function (exports, sharedUtil, coreWorker) {
  47888. var assert = sharedUtil.assert;
  47889. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47890. var isInt = sharedUtil.isInt;
  47891. var MissingPDFException = sharedUtil.MissingPDFException;
  47892. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  47893. /** @implements {IPDFStream} */
  47894. function PDFNetworkStream(options) {
  47895. this._options = options;
  47896. var source = options.source;
  47897. this._manager = new NetworkManager(source.url, {
  47898. httpHeaders: source.httpHeaders,
  47899. withCredentials: source.withCredentials
  47900. });
  47901. this._rangeChunkSize = source.rangeChunkSize;
  47902. this._fullRequestReader = null;
  47903. this._rangeRequestReaders = [];
  47904. }
  47905. PDFNetworkStream.prototype = {
  47906. _onRangeRequestReaderClosed:
  47907. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  47908. var i = this._rangeRequestReaders.indexOf(reader);
  47909. if (i >= 0) {
  47910. this._rangeRequestReaders.splice(i, 1);
  47911. }
  47912. },
  47913. getFullReader: function PDFNetworkStream_getFullReader() {
  47914. assert(!this._fullRequestReader);
  47915. this._fullRequestReader =
  47916. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  47917. return this._fullRequestReader;
  47918. },
  47919. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  47920. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  47921. begin, end);
  47922. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  47923. this._rangeRequestReaders.push(reader);
  47924. return reader;
  47925. },
  47926. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  47927. if (this._fullRequestReader) {
  47928. this._fullRequestReader.cancel(reason);
  47929. }
  47930. var readers = this._rangeRequestReaders.slice(0);
  47931. readers.forEach(function (reader) {
  47932. reader.cancel(reason);
  47933. });
  47934. }
  47935. };
  47936. /** @implements {IPDFStreamReader} */
  47937. function PDFNetworkStreamFullRequestReader(manager, options) {
  47938. this._manager = manager;
  47939. var source = options.source;
  47940. var args = {
  47941. onHeadersReceived: this._onHeadersReceived.bind(this),
  47942. onProgressiveData: source.disableStream ? null :
  47943. this._onProgressiveData.bind(this),
  47944. onDone: this._onDone.bind(this),
  47945. onError: this._onError.bind(this),
  47946. onProgress: this._onProgress.bind(this)
  47947. };
  47948. this._url = source.url;
  47949. this._fullRequestId = manager.requestFull(args);
  47950. this._headersReceivedCapability = createPromiseCapability();
  47951. this._disableRange = options.disableRange || false;
  47952. this._contentLength = source.length; // optional
  47953. this._rangeChunkSize = source.rangeChunkSize;
  47954. if (!this._rangeChunkSize && !this._disableRange) {
  47955. this._disableRange = true;
  47956. }
  47957. this._isStreamingSupported = false;
  47958. this._isRangeSupported = false;
  47959. this._cachedChunks = [];
  47960. this._requests = [];
  47961. this._done = false;
  47962. this._storedError = undefined;
  47963. this.onProgress = null;
  47964. }
  47965. PDFNetworkStreamFullRequestReader.prototype = {
  47966. _validateRangeRequestCapabilities: function
  47967. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  47968. if (this._disableRange) {
  47969. return false;
  47970. }
  47971. var networkManager = this._manager;
  47972. var fullRequestXhrId = this._fullRequestId;
  47973. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  47974. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  47975. return false;
  47976. }
  47977. var contentEncoding =
  47978. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  47979. if (contentEncoding !== 'identity') {
  47980. return false;
  47981. }
  47982. var length = fullRequestXhr.getResponseHeader('Content-Length');
  47983. length = parseInt(length, 10);
  47984. if (!isInt(length)) {
  47985. return false;
  47986. }
  47987. this._contentLength = length; // setting right content length
  47988. if (length <= 2 * this._rangeChunkSize) {
  47989. // The file size is smaller than the size of two chunks, so it does
  47990. // not make any sense to abort the request and retry with a range
  47991. // request.
  47992. return false;
  47993. }
  47994. return true;
  47995. },
  47996. _onHeadersReceived:
  47997. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  47998. if (this._validateRangeRequestCapabilities()) {
  47999. this._isRangeSupported = true;
  48000. }
  48001. var networkManager = this._manager;
  48002. var fullRequestXhrId = this._fullRequestId;
  48003. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  48004. // We can continue fetching when progressive loading is enabled,
  48005. // and we don't need the autoFetch feature.
  48006. this._isStreamingSupported = true;
  48007. } else if (this._isRangeSupported) {
  48008. // NOTE: by cancelling the full request, and then issuing range
  48009. // requests, there will be an issue for sites where you can only
  48010. // request the pdf once. However, if this is the case, then the
  48011. // server should not be returning that it can support range
  48012. // requests.
  48013. networkManager.abortRequest(fullRequestXhrId);
  48014. }
  48015. this._headersReceivedCapability.resolve();
  48016. },
  48017. _onProgressiveData:
  48018. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  48019. if (this._requests.length > 0) {
  48020. var requestCapability = this._requests.shift();
  48021. requestCapability.resolve({value: chunk, done: false});
  48022. } else {
  48023. this._cachedChunks.push(chunk);
  48024. }
  48025. },
  48026. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  48027. if (args) {
  48028. this._onProgressiveData(args.chunk);
  48029. }
  48030. this._done = true;
  48031. if (this._cachedChunks.length > 0) {
  48032. return;
  48033. }
  48034. this._requests.forEach(function (requestCapability) {
  48035. requestCapability.resolve({value: undefined, done: true});
  48036. });
  48037. this._requests = [];
  48038. },
  48039. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  48040. var url = this._url;
  48041. var exception;
  48042. if (status === 404 || status === 0 && /^file:/.test(url)) {
  48043. exception = new MissingPDFException('Missing PDF "' + url + '".');
  48044. } else {
  48045. exception = new UnexpectedResponseException(
  48046. 'Unexpected server response (' + status +
  48047. ') while retrieving PDF "' + url + '".', status);
  48048. }
  48049. this._storedError = exception;
  48050. this._headersReceivedCapability.reject(exception);
  48051. this._requests.forEach(function (requestCapability) {
  48052. requestCapability.reject(exception);
  48053. });
  48054. this._requests = [];
  48055. this._cachedChunks = [];
  48056. },
  48057. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  48058. if (this.onProgress) {
  48059. this.onProgress({
  48060. loaded: data.loaded,
  48061. total: data.lengthComputable ? data.total : this._contentLength
  48062. });
  48063. }
  48064. },
  48065. get isRangeSupported() {
  48066. return this._isRangeSupported;
  48067. },
  48068. get isStreamingSupported() {
  48069. return this._isStreamingSupported;
  48070. },
  48071. get contentLength() {
  48072. return this._contentLength;
  48073. },
  48074. get headersReady() {
  48075. return this._headersReceivedCapability.promise;
  48076. },
  48077. read: function PDFNetworkStreamFullRequestReader_read() {
  48078. if (this._storedError) {
  48079. return Promise.reject(this._storedError);
  48080. }
  48081. if (this._cachedChunks.length > 0) {
  48082. var chunk = this._cachedChunks.shift();
  48083. return Promise.resolve(chunk);
  48084. }
  48085. if (this._done) {
  48086. return Promise.resolve({value: undefined, done: true});
  48087. }
  48088. var requestCapability = createPromiseCapability();
  48089. this._requests.push(requestCapability);
  48090. return requestCapability.promise;
  48091. },
  48092. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  48093. this._done = true;
  48094. this._headersReceivedCapability.reject(reason);
  48095. this._requests.forEach(function (requestCapability) {
  48096. requestCapability.resolve({value: undefined, done: true});
  48097. });
  48098. this._requests = [];
  48099. if (this._manager.isPendingRequest(this._fullRequestId)) {
  48100. this._manager.abortRequest(this._fullRequestId);
  48101. }
  48102. this._fullRequestReader = null;
  48103. }
  48104. };
  48105. /** @implements {IPDFStreamRangeReader} */
  48106. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  48107. this._manager = manager;
  48108. var args = {
  48109. onDone: this._onDone.bind(this),
  48110. onProgress: this._onProgress.bind(this)
  48111. };
  48112. this._requestId = manager.requestRange(begin, end, args);
  48113. this._requests = [];
  48114. this._queuedChunk = null;
  48115. this._done = false;
  48116. this.onProgress = null;
  48117. this.onClosed = null;
  48118. }
  48119. PDFNetworkStreamRangeRequestReader.prototype = {
  48120. _close: function PDFNetworkStreamRangeRequestReader_close() {
  48121. if (this.onClosed) {
  48122. this.onClosed(this);
  48123. }
  48124. },
  48125. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  48126. var chunk = data.chunk;
  48127. if (this._requests.length > 0) {
  48128. var requestCapability = this._requests.shift();
  48129. requestCapability.resolve({value: chunk, done: false});
  48130. } else {
  48131. this._queuedChunk = chunk;
  48132. }
  48133. this._done = true;
  48134. this._requests.forEach(function (requestCapability) {
  48135. requestCapability.resolve({value: undefined, done: true});
  48136. });
  48137. this._requests = [];
  48138. this._close();
  48139. },
  48140. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  48141. if (!this.isStreamingSupported && this.onProgress) {
  48142. this.onProgress({
  48143. loaded: evt.loaded
  48144. });
  48145. }
  48146. },
  48147. get isStreamingSupported() {
  48148. return false; // TODO allow progressive range bytes loading
  48149. },
  48150. read: function PDFNetworkStreamRangeRequestReader_read() {
  48151. if (this._queuedChunk !== null) {
  48152. var chunk = this._queuedChunk;
  48153. this._queuedChunk = null;
  48154. return Promise.resolve({value: chunk, done: false});
  48155. }
  48156. if (this._done) {
  48157. return Promise.resolve({value: undefined, done: true});
  48158. }
  48159. var requestCapability = createPromiseCapability();
  48160. this._requests.push(requestCapability);
  48161. return requestCapability.promise;
  48162. },
  48163. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  48164. this._done = true;
  48165. this._requests.forEach(function (requestCapability) {
  48166. requestCapability.resolve({value: undefined, done: true});
  48167. });
  48168. this._requests = [];
  48169. if (this._manager.isPendingRequest(this._requestId)) {
  48170. this._manager.abortRequest(this._requestId);
  48171. }
  48172. this._close();
  48173. }
  48174. };
  48175. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  48176. exports.PDFNetworkStream = PDFNetworkStream;
  48177. exports.NetworkManager = NetworkManager;
  48178. }));
  48179. }).call(pdfjsLibs);
  48180. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  48181. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  48182. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  48183. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  48184. exports.PDFDataRangeTransport =
  48185. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  48186. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  48187. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  48188. exports.AnnotationLayer =
  48189. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  48190. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  48191. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  48192. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  48193. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  48194. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  48195. exports.UnexpectedResponseException =
  48196. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  48197. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  48198. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  48199. exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
  48200. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  48201. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  48202. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  48203. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  48204. exports.getFilenameFromUrl =
  48205. pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  48206. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  48207. }));