pdf.combined.js 1.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227
  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.456';
  30. var pdfjsBuild = '4d15928';
  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.pdfjsSharedUtil = {}));
  953. }
  954. }(this, function (exports) {
  955. var globalScope = (typeof window !== 'undefined') ? window :
  956. (typeof global !== 'undefined') ? global :
  957. (typeof self !== 'undefined') ? self : this;
  958. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  959. var TextRenderingMode = {
  960. FILL: 0,
  961. STROKE: 1,
  962. FILL_STROKE: 2,
  963. INVISIBLE: 3,
  964. FILL_ADD_TO_PATH: 4,
  965. STROKE_ADD_TO_PATH: 5,
  966. FILL_STROKE_ADD_TO_PATH: 6,
  967. ADD_TO_PATH: 7,
  968. FILL_STROKE_MASK: 3,
  969. ADD_TO_PATH_FLAG: 4
  970. };
  971. var ImageKind = {
  972. GRAYSCALE_1BPP: 1,
  973. RGB_24BPP: 2,
  974. RGBA_32BPP: 3
  975. };
  976. var AnnotationType = {
  977. TEXT: 1,
  978. LINK: 2,
  979. FREETEXT: 3,
  980. LINE: 4,
  981. SQUARE: 5,
  982. CIRCLE: 6,
  983. POLYGON: 7,
  984. POLYLINE: 8,
  985. HIGHLIGHT: 9,
  986. UNDERLINE: 10,
  987. SQUIGGLY: 11,
  988. STRIKEOUT: 12,
  989. STAMP: 13,
  990. CARET: 14,
  991. INK: 15,
  992. POPUP: 16,
  993. FILEATTACHMENT: 17,
  994. SOUND: 18,
  995. MOVIE: 19,
  996. WIDGET: 20,
  997. SCREEN: 21,
  998. PRINTERMARK: 22,
  999. TRAPNET: 23,
  1000. WATERMARK: 24,
  1001. THREED: 25,
  1002. REDACT: 26
  1003. };
  1004. var AnnotationFlag = {
  1005. INVISIBLE: 0x01,
  1006. HIDDEN: 0x02,
  1007. PRINT: 0x04,
  1008. NOZOOM: 0x08,
  1009. NOROTATE: 0x10,
  1010. NOVIEW: 0x20,
  1011. READONLY: 0x40,
  1012. LOCKED: 0x80,
  1013. TOGGLENOVIEW: 0x100,
  1014. LOCKEDCONTENTS: 0x200
  1015. };
  1016. var AnnotationBorderStyleType = {
  1017. SOLID: 1,
  1018. DASHED: 2,
  1019. BEVELED: 3,
  1020. INSET: 4,
  1021. UNDERLINE: 5
  1022. };
  1023. var StreamType = {
  1024. UNKNOWN: 0,
  1025. FLATE: 1,
  1026. LZW: 2,
  1027. DCT: 3,
  1028. JPX: 4,
  1029. JBIG: 5,
  1030. A85: 6,
  1031. AHX: 7,
  1032. CCF: 8,
  1033. RL: 9
  1034. };
  1035. var FontType = {
  1036. UNKNOWN: 0,
  1037. TYPE1: 1,
  1038. TYPE1C: 2,
  1039. CIDFONTTYPE0: 3,
  1040. CIDFONTTYPE0C: 4,
  1041. TRUETYPE: 5,
  1042. CIDFONTTYPE2: 6,
  1043. TYPE3: 7,
  1044. OPENTYPE: 8,
  1045. TYPE0: 9,
  1046. MMTYPE1: 10
  1047. };
  1048. var VERBOSITY_LEVELS = {
  1049. errors: 0,
  1050. warnings: 1,
  1051. infos: 5
  1052. };
  1053. // All the possible operations for an operator list.
  1054. var OPS = {
  1055. // Intentionally start from 1 so it is easy to spot bad operators that will be
  1056. // 0's.
  1057. dependency: 1,
  1058. setLineWidth: 2,
  1059. setLineCap: 3,
  1060. setLineJoin: 4,
  1061. setMiterLimit: 5,
  1062. setDash: 6,
  1063. setRenderingIntent: 7,
  1064. setFlatness: 8,
  1065. setGState: 9,
  1066. save: 10,
  1067. restore: 11,
  1068. transform: 12,
  1069. moveTo: 13,
  1070. lineTo: 14,
  1071. curveTo: 15,
  1072. curveTo2: 16,
  1073. curveTo3: 17,
  1074. closePath: 18,
  1075. rectangle: 19,
  1076. stroke: 20,
  1077. closeStroke: 21,
  1078. fill: 22,
  1079. eoFill: 23,
  1080. fillStroke: 24,
  1081. eoFillStroke: 25,
  1082. closeFillStroke: 26,
  1083. closeEOFillStroke: 27,
  1084. endPath: 28,
  1085. clip: 29,
  1086. eoClip: 30,
  1087. beginText: 31,
  1088. endText: 32,
  1089. setCharSpacing: 33,
  1090. setWordSpacing: 34,
  1091. setHScale: 35,
  1092. setLeading: 36,
  1093. setFont: 37,
  1094. setTextRenderingMode: 38,
  1095. setTextRise: 39,
  1096. moveText: 40,
  1097. setLeadingMoveText: 41,
  1098. setTextMatrix: 42,
  1099. nextLine: 43,
  1100. showText: 44,
  1101. showSpacedText: 45,
  1102. nextLineShowText: 46,
  1103. nextLineSetSpacingShowText: 47,
  1104. setCharWidth: 48,
  1105. setCharWidthAndBounds: 49,
  1106. setStrokeColorSpace: 50,
  1107. setFillColorSpace: 51,
  1108. setStrokeColor: 52,
  1109. setStrokeColorN: 53,
  1110. setFillColor: 54,
  1111. setFillColorN: 55,
  1112. setStrokeGray: 56,
  1113. setFillGray: 57,
  1114. setStrokeRGBColor: 58,
  1115. setFillRGBColor: 59,
  1116. setStrokeCMYKColor: 60,
  1117. setFillCMYKColor: 61,
  1118. shadingFill: 62,
  1119. beginInlineImage: 63,
  1120. beginImageData: 64,
  1121. endInlineImage: 65,
  1122. paintXObject: 66,
  1123. markPoint: 67,
  1124. markPointProps: 68,
  1125. beginMarkedContent: 69,
  1126. beginMarkedContentProps: 70,
  1127. endMarkedContent: 71,
  1128. beginCompat: 72,
  1129. endCompat: 73,
  1130. paintFormXObjectBegin: 74,
  1131. paintFormXObjectEnd: 75,
  1132. beginGroup: 76,
  1133. endGroup: 77,
  1134. beginAnnotations: 78,
  1135. endAnnotations: 79,
  1136. beginAnnotation: 80,
  1137. endAnnotation: 81,
  1138. paintJpegXObject: 82,
  1139. paintImageMaskXObject: 83,
  1140. paintImageMaskXObjectGroup: 84,
  1141. paintImageXObject: 85,
  1142. paintInlineImageXObject: 86,
  1143. paintInlineImageXObjectGroup: 87,
  1144. paintImageXObjectRepeat: 88,
  1145. paintImageMaskXObjectRepeat: 89,
  1146. paintSolidColorImageMask: 90,
  1147. constructPath: 91
  1148. };
  1149. var verbosity = VERBOSITY_LEVELS.warnings;
  1150. function setVerbosityLevel(level) {
  1151. verbosity = level;
  1152. }
  1153. function getVerbosityLevel() {
  1154. return verbosity;
  1155. }
  1156. // A notice for devs. These are good for things that are helpful to devs, such
  1157. // as warning that Workers were disabled, which is important to devs but not
  1158. // end users.
  1159. function info(msg) {
  1160. if (verbosity >= VERBOSITY_LEVELS.infos) {
  1161. console.log('Info: ' + msg);
  1162. }
  1163. }
  1164. // Non-fatal warnings.
  1165. function warn(msg) {
  1166. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  1167. console.log('Warning: ' + msg);
  1168. }
  1169. }
  1170. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  1171. function deprecated(details) {
  1172. console.log('Deprecated API usage: ' + details);
  1173. }
  1174. // Fatal errors that should trigger the fallback UI and halt execution by
  1175. // throwing an exception.
  1176. function error(msg) {
  1177. if (verbosity >= VERBOSITY_LEVELS.errors) {
  1178. console.log('Error: ' + msg);
  1179. console.log(backtrace());
  1180. }
  1181. throw new Error(msg);
  1182. }
  1183. function backtrace() {
  1184. try {
  1185. throw new Error();
  1186. } catch (e) {
  1187. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  1188. }
  1189. }
  1190. function assert(cond, msg) {
  1191. if (!cond) {
  1192. error(msg);
  1193. }
  1194. }
  1195. var UNSUPPORTED_FEATURES = {
  1196. unknown: 'unknown',
  1197. forms: 'forms',
  1198. javaScript: 'javaScript',
  1199. smask: 'smask',
  1200. shadingPattern: 'shadingPattern',
  1201. font: 'font'
  1202. };
  1203. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  1204. function isSameOrigin(baseUrl, otherUrl) {
  1205. try {
  1206. var base = new URL(baseUrl);
  1207. if (!base.origin || base.origin === 'null') {
  1208. return false; // non-HTTP url
  1209. }
  1210. } catch (e) {
  1211. return false;
  1212. }
  1213. var other = new URL(otherUrl, base);
  1214. return base.origin === other.origin;
  1215. }
  1216. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  1217. function isValidUrl(url, allowRelative) {
  1218. if (!url || typeof url !== 'string') {
  1219. return false;
  1220. }
  1221. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  1222. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  1223. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  1224. if (!protocol) {
  1225. return allowRelative;
  1226. }
  1227. protocol = protocol[0].toLowerCase();
  1228. switch (protocol) {
  1229. case 'http':
  1230. case 'https':
  1231. case 'ftp':
  1232. case 'mailto':
  1233. case 'tel':
  1234. return true;
  1235. default:
  1236. return false;
  1237. }
  1238. }
  1239. function shadow(obj, prop, value) {
  1240. Object.defineProperty(obj, prop, { value: value,
  1241. enumerable: true,
  1242. configurable: true,
  1243. writable: false });
  1244. return value;
  1245. }
  1246. function getLookupTableFactory(initializer) {
  1247. var lookup;
  1248. return function () {
  1249. if (initializer) {
  1250. lookup = Object.create(null);
  1251. initializer(lookup);
  1252. initializer = null;
  1253. }
  1254. return lookup;
  1255. };
  1256. }
  1257. var PasswordResponses = {
  1258. NEED_PASSWORD: 1,
  1259. INCORRECT_PASSWORD: 2
  1260. };
  1261. var PasswordException = (function PasswordExceptionClosure() {
  1262. function PasswordException(msg, code) {
  1263. this.name = 'PasswordException';
  1264. this.message = msg;
  1265. this.code = code;
  1266. }
  1267. PasswordException.prototype = new Error();
  1268. PasswordException.constructor = PasswordException;
  1269. return PasswordException;
  1270. })();
  1271. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  1272. function UnknownErrorException(msg, details) {
  1273. this.name = 'UnknownErrorException';
  1274. this.message = msg;
  1275. this.details = details;
  1276. }
  1277. UnknownErrorException.prototype = new Error();
  1278. UnknownErrorException.constructor = UnknownErrorException;
  1279. return UnknownErrorException;
  1280. })();
  1281. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  1282. function InvalidPDFException(msg) {
  1283. this.name = 'InvalidPDFException';
  1284. this.message = msg;
  1285. }
  1286. InvalidPDFException.prototype = new Error();
  1287. InvalidPDFException.constructor = InvalidPDFException;
  1288. return InvalidPDFException;
  1289. })();
  1290. var MissingPDFException = (function MissingPDFExceptionClosure() {
  1291. function MissingPDFException(msg) {
  1292. this.name = 'MissingPDFException';
  1293. this.message = msg;
  1294. }
  1295. MissingPDFException.prototype = new Error();
  1296. MissingPDFException.constructor = MissingPDFException;
  1297. return MissingPDFException;
  1298. })();
  1299. var UnexpectedResponseException =
  1300. (function UnexpectedResponseExceptionClosure() {
  1301. function UnexpectedResponseException(msg, status) {
  1302. this.name = 'UnexpectedResponseException';
  1303. this.message = msg;
  1304. this.status = status;
  1305. }
  1306. UnexpectedResponseException.prototype = new Error();
  1307. UnexpectedResponseException.constructor = UnexpectedResponseException;
  1308. return UnexpectedResponseException;
  1309. })();
  1310. var NotImplementedException = (function NotImplementedExceptionClosure() {
  1311. function NotImplementedException(msg) {
  1312. this.message = msg;
  1313. }
  1314. NotImplementedException.prototype = new Error();
  1315. NotImplementedException.prototype.name = 'NotImplementedException';
  1316. NotImplementedException.constructor = NotImplementedException;
  1317. return NotImplementedException;
  1318. })();
  1319. var MissingDataException = (function MissingDataExceptionClosure() {
  1320. function MissingDataException(begin, end) {
  1321. this.begin = begin;
  1322. this.end = end;
  1323. this.message = 'Missing data [' + begin + ', ' + end + ')';
  1324. }
  1325. MissingDataException.prototype = new Error();
  1326. MissingDataException.prototype.name = 'MissingDataException';
  1327. MissingDataException.constructor = MissingDataException;
  1328. return MissingDataException;
  1329. })();
  1330. var XRefParseException = (function XRefParseExceptionClosure() {
  1331. function XRefParseException(msg) {
  1332. this.message = msg;
  1333. }
  1334. XRefParseException.prototype = new Error();
  1335. XRefParseException.prototype.name = 'XRefParseException';
  1336. XRefParseException.constructor = XRefParseException;
  1337. return XRefParseException;
  1338. })();
  1339. var NullCharactersRegExp = /\x00/g;
  1340. function removeNullCharacters(str) {
  1341. if (typeof str !== 'string') {
  1342. warn('The argument for removeNullCharacters must be a string.');
  1343. return str;
  1344. }
  1345. return str.replace(NullCharactersRegExp, '');
  1346. }
  1347. function bytesToString(bytes) {
  1348. assert(bytes !== null && typeof bytes === 'object' &&
  1349. bytes.length !== undefined, 'Invalid argument for bytesToString');
  1350. var length = bytes.length;
  1351. var MAX_ARGUMENT_COUNT = 8192;
  1352. if (length < MAX_ARGUMENT_COUNT) {
  1353. return String.fromCharCode.apply(null, bytes);
  1354. }
  1355. var strBuf = [];
  1356. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  1357. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  1358. var chunk = bytes.subarray(i, chunkEnd);
  1359. strBuf.push(String.fromCharCode.apply(null, chunk));
  1360. }
  1361. return strBuf.join('');
  1362. }
  1363. function stringToBytes(str) {
  1364. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  1365. var length = str.length;
  1366. var bytes = new Uint8Array(length);
  1367. for (var i = 0; i < length; ++i) {
  1368. bytes[i] = str.charCodeAt(i) & 0xFF;
  1369. }
  1370. return bytes;
  1371. }
  1372. /**
  1373. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  1374. * @param {Array|Uint8Array|string} arr
  1375. * @returns {number}
  1376. */
  1377. function arrayByteLength(arr) {
  1378. if (arr.length !== undefined) {
  1379. return arr.length;
  1380. }
  1381. assert(arr.byteLength !== undefined);
  1382. return arr.byteLength;
  1383. }
  1384. /**
  1385. * Combines array items (arrays) into single Uint8Array object.
  1386. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  1387. * @returns {Uint8Array}
  1388. */
  1389. function arraysToBytes(arr) {
  1390. // Shortcut: if first and only item is Uint8Array, return it.
  1391. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  1392. return arr[0];
  1393. }
  1394. var resultLength = 0;
  1395. var i, ii = arr.length;
  1396. var item, itemLength ;
  1397. for (i = 0; i < ii; i++) {
  1398. item = arr[i];
  1399. itemLength = arrayByteLength(item);
  1400. resultLength += itemLength;
  1401. }
  1402. var pos = 0;
  1403. var data = new Uint8Array(resultLength);
  1404. for (i = 0; i < ii; i++) {
  1405. item = arr[i];
  1406. if (!(item instanceof Uint8Array)) {
  1407. if (typeof item === 'string') {
  1408. item = stringToBytes(item);
  1409. } else {
  1410. item = new Uint8Array(item);
  1411. }
  1412. }
  1413. itemLength = item.byteLength;
  1414. data.set(item, pos);
  1415. pos += itemLength;
  1416. }
  1417. return data;
  1418. }
  1419. function string32(value) {
  1420. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  1421. (value >> 8) & 0xff, value & 0xff);
  1422. }
  1423. function log2(x) {
  1424. var n = 1, i = 0;
  1425. while (x > n) {
  1426. n <<= 1;
  1427. i++;
  1428. }
  1429. return i;
  1430. }
  1431. function readInt8(data, start) {
  1432. return (data[start] << 24) >> 24;
  1433. }
  1434. function readUint16(data, offset) {
  1435. return (data[offset] << 8) | data[offset + 1];
  1436. }
  1437. function readUint32(data, offset) {
  1438. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  1439. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  1440. }
  1441. // Lazy test the endianness of the platform
  1442. // NOTE: This will be 'true' for simulated TypedArrays
  1443. function isLittleEndian() {
  1444. var buffer8 = new Uint8Array(2);
  1445. buffer8[0] = 1;
  1446. var buffer16 = new Uint16Array(buffer8.buffer);
  1447. return (buffer16[0] === 1);
  1448. }
  1449. // Checks if it's possible to eval JS expressions.
  1450. function isEvalSupported() {
  1451. try {
  1452. /* jshint evil: true */
  1453. new Function('');
  1454. return true;
  1455. } catch (e) {
  1456. return false;
  1457. }
  1458. }
  1459. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  1460. function Uint32ArrayView(buffer, length) {
  1461. this.buffer = buffer;
  1462. this.byteLength = buffer.length;
  1463. this.length = length === undefined ? (this.byteLength >> 2) : length;
  1464. ensureUint32ArrayViewProps(this.length);
  1465. }
  1466. Uint32ArrayView.prototype = Object.create(null);
  1467. var uint32ArrayViewSetters = 0;
  1468. function createUint32ArrayProp(index) {
  1469. return {
  1470. get: function () {
  1471. var buffer = this.buffer, offset = index << 2;
  1472. return (buffer[offset] | (buffer[offset + 1] << 8) |
  1473. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  1474. },
  1475. set: function (value) {
  1476. var buffer = this.buffer, offset = index << 2;
  1477. buffer[offset] = value & 255;
  1478. buffer[offset + 1] = (value >> 8) & 255;
  1479. buffer[offset + 2] = (value >> 16) & 255;
  1480. buffer[offset + 3] = (value >>> 24) & 255;
  1481. }
  1482. };
  1483. }
  1484. function ensureUint32ArrayViewProps(length) {
  1485. while (uint32ArrayViewSetters < length) {
  1486. Object.defineProperty(Uint32ArrayView.prototype,
  1487. uint32ArrayViewSetters,
  1488. createUint32ArrayProp(uint32ArrayViewSetters));
  1489. uint32ArrayViewSetters++;
  1490. }
  1491. }
  1492. return Uint32ArrayView;
  1493. })();
  1494. exports.Uint32ArrayView = Uint32ArrayView;
  1495. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  1496. var Util = (function UtilClosure() {
  1497. function Util() {}
  1498. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  1499. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  1500. // creating many intermediate strings.
  1501. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  1502. rgbBuf[1] = r;
  1503. rgbBuf[3] = g;
  1504. rgbBuf[5] = b;
  1505. return rgbBuf.join('');
  1506. };
  1507. // Concatenates two transformation matrices together and returns the result.
  1508. Util.transform = function Util_transform(m1, m2) {
  1509. return [
  1510. m1[0] * m2[0] + m1[2] * m2[1],
  1511. m1[1] * m2[0] + m1[3] * m2[1],
  1512. m1[0] * m2[2] + m1[2] * m2[3],
  1513. m1[1] * m2[2] + m1[3] * m2[3],
  1514. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  1515. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  1516. ];
  1517. };
  1518. // For 2d affine transforms
  1519. Util.applyTransform = function Util_applyTransform(p, m) {
  1520. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1521. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1522. return [xt, yt];
  1523. };
  1524. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  1525. var d = m[0] * m[3] - m[1] * m[2];
  1526. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1527. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1528. return [xt, yt];
  1529. };
  1530. // Applies the transform to the rectangle and finds the minimum axially
  1531. // aligned bounding box.
  1532. Util.getAxialAlignedBoundingBox =
  1533. function Util_getAxialAlignedBoundingBox(r, m) {
  1534. var p1 = Util.applyTransform(r, m);
  1535. var p2 = Util.applyTransform(r.slice(2, 4), m);
  1536. var p3 = Util.applyTransform([r[0], r[3]], m);
  1537. var p4 = Util.applyTransform([r[2], r[1]], m);
  1538. return [
  1539. Math.min(p1[0], p2[0], p3[0], p4[0]),
  1540. Math.min(p1[1], p2[1], p3[1], p4[1]),
  1541. Math.max(p1[0], p2[0], p3[0], p4[0]),
  1542. Math.max(p1[1], p2[1], p3[1], p4[1])
  1543. ];
  1544. };
  1545. Util.inverseTransform = function Util_inverseTransform(m) {
  1546. var d = m[0] * m[3] - m[1] * m[2];
  1547. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  1548. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  1549. };
  1550. // Apply a generic 3d matrix M on a 3-vector v:
  1551. // | a b c | | X |
  1552. // | d e f | x | Y |
  1553. // | g h i | | Z |
  1554. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  1555. // with v as [X,Y,Z]
  1556. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  1557. return [
  1558. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  1559. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  1560. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  1561. ];
  1562. };
  1563. // This calculation uses Singular Value Decomposition.
  1564. // The SVD can be represented with formula A = USV. We are interested in the
  1565. // matrix S here because it represents the scale values.
  1566. Util.singularValueDecompose2dScale =
  1567. function Util_singularValueDecompose2dScale(m) {
  1568. var transpose = [m[0], m[2], m[1], m[3]];
  1569. // Multiply matrix m with its transpose.
  1570. var a = m[0] * transpose[0] + m[1] * transpose[2];
  1571. var b = m[0] * transpose[1] + m[1] * transpose[3];
  1572. var c = m[2] * transpose[0] + m[3] * transpose[2];
  1573. var d = m[2] * transpose[1] + m[3] * transpose[3];
  1574. // Solve the second degree polynomial to get roots.
  1575. var first = (a + d) / 2;
  1576. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  1577. var sx = first + second || 1;
  1578. var sy = first - second || 1;
  1579. // Scale values are the square roots of the eigenvalues.
  1580. return [Math.sqrt(sx), Math.sqrt(sy)];
  1581. };
  1582. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  1583. // For coordinate systems whose origin lies in the bottom-left, this
  1584. // means normalization to (BL,TR) ordering. For systems with origin in the
  1585. // top-left, this means (TL,BR) ordering.
  1586. Util.normalizeRect = function Util_normalizeRect(rect) {
  1587. var r = rect.slice(0); // clone rect
  1588. if (rect[0] > rect[2]) {
  1589. r[0] = rect[2];
  1590. r[2] = rect[0];
  1591. }
  1592. if (rect[1] > rect[3]) {
  1593. r[1] = rect[3];
  1594. r[3] = rect[1];
  1595. }
  1596. return r;
  1597. };
  1598. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  1599. // intersection of rect1 and rect2. If no intersection, returns 'false'
  1600. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  1601. Util.intersect = function Util_intersect(rect1, rect2) {
  1602. function compare(a, b) {
  1603. return a - b;
  1604. }
  1605. // Order points along the axes
  1606. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  1607. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  1608. result = [];
  1609. rect1 = Util.normalizeRect(rect1);
  1610. rect2 = Util.normalizeRect(rect2);
  1611. // X: first and second points belong to different rectangles?
  1612. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  1613. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  1614. // Intersection must be between second and third points
  1615. result[0] = orderedX[1];
  1616. result[2] = orderedX[2];
  1617. } else {
  1618. return false;
  1619. }
  1620. // Y: first and second points belong to different rectangles?
  1621. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  1622. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  1623. // Intersection must be between second and third points
  1624. result[1] = orderedY[1];
  1625. result[3] = orderedY[2];
  1626. } else {
  1627. return false;
  1628. }
  1629. return result;
  1630. };
  1631. Util.sign = function Util_sign(num) {
  1632. return num < 0 ? -1 : 1;
  1633. };
  1634. var ROMAN_NUMBER_MAP = [
  1635. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  1636. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  1637. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  1638. ];
  1639. /**
  1640. * Converts positive integers to (upper case) Roman numerals.
  1641. * @param {integer} number - The number that should be converted.
  1642. * @param {boolean} lowerCase - Indicates if the result should be converted
  1643. * to lower case letters. The default is false.
  1644. * @return {string} The resulting Roman number.
  1645. */
  1646. Util.toRoman = function Util_toRoman(number, lowerCase) {
  1647. assert(isInt(number) && number > 0,
  1648. 'The number should be a positive integer.');
  1649. var pos, romanBuf = [];
  1650. // Thousands
  1651. while (number >= 1000) {
  1652. number -= 1000;
  1653. romanBuf.push('M');
  1654. }
  1655. // Hundreds
  1656. pos = (number / 100) | 0;
  1657. number %= 100;
  1658. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  1659. // Tens
  1660. pos = (number / 10) | 0;
  1661. number %= 10;
  1662. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  1663. // Ones
  1664. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  1665. var romanStr = romanBuf.join('');
  1666. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  1667. };
  1668. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  1669. Array.prototype.push.apply(arr1, arr2);
  1670. };
  1671. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  1672. Array.prototype.unshift.apply(arr1, arr2);
  1673. };
  1674. Util.extendObj = function extendObj(obj1, obj2) {
  1675. for (var key in obj2) {
  1676. obj1[key] = obj2[key];
  1677. }
  1678. };
  1679. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  1680. name) {
  1681. while (dict && !dict.has(name)) {
  1682. dict = dict.get('Parent');
  1683. }
  1684. if (!dict) {
  1685. return null;
  1686. }
  1687. return dict.get(name);
  1688. };
  1689. Util.inherit = function Util_inherit(sub, base, prototype) {
  1690. sub.prototype = Object.create(base.prototype);
  1691. sub.prototype.constructor = sub;
  1692. for (var prop in prototype) {
  1693. sub.prototype[prop] = prototype[prop];
  1694. }
  1695. };
  1696. Util.loadScript = function Util_loadScript(src, callback) {
  1697. var script = document.createElement('script');
  1698. var loaded = false;
  1699. script.setAttribute('src', src);
  1700. if (callback) {
  1701. script.onload = function() {
  1702. if (!loaded) {
  1703. callback();
  1704. }
  1705. loaded = true;
  1706. };
  1707. }
  1708. document.getElementsByTagName('head')[0].appendChild(script);
  1709. };
  1710. return Util;
  1711. })();
  1712. /**
  1713. * PDF page viewport created based on scale, rotation and offset.
  1714. * @class
  1715. * @alias PageViewport
  1716. */
  1717. var PageViewport = (function PageViewportClosure() {
  1718. /**
  1719. * @constructor
  1720. * @private
  1721. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  1722. * @param scale {number} scale of the viewport.
  1723. * @param rotation {number} rotations of the viewport in degrees.
  1724. * @param offsetX {number} offset X
  1725. * @param offsetY {number} offset Y
  1726. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  1727. */
  1728. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  1729. this.viewBox = viewBox;
  1730. this.scale = scale;
  1731. this.rotation = rotation;
  1732. this.offsetX = offsetX;
  1733. this.offsetY = offsetY;
  1734. // creating transform to convert pdf coordinate system to the normal
  1735. // canvas like coordinates taking in account scale and rotation
  1736. var centerX = (viewBox[2] + viewBox[0]) / 2;
  1737. var centerY = (viewBox[3] + viewBox[1]) / 2;
  1738. var rotateA, rotateB, rotateC, rotateD;
  1739. rotation = rotation % 360;
  1740. rotation = rotation < 0 ? rotation + 360 : rotation;
  1741. switch (rotation) {
  1742. case 180:
  1743. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  1744. break;
  1745. case 90:
  1746. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  1747. break;
  1748. case 270:
  1749. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  1750. break;
  1751. //case 0:
  1752. default:
  1753. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  1754. break;
  1755. }
  1756. if (dontFlip) {
  1757. rotateC = -rotateC; rotateD = -rotateD;
  1758. }
  1759. var offsetCanvasX, offsetCanvasY;
  1760. var width, height;
  1761. if (rotateA === 0) {
  1762. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  1763. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  1764. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  1765. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  1766. } else {
  1767. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  1768. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  1769. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  1770. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  1771. }
  1772. // creating transform for the following operations:
  1773. // translate(-centerX, -centerY), rotate and flip vertically,
  1774. // scale, and translate(offsetCanvasX, offsetCanvasY)
  1775. this.transform = [
  1776. rotateA * scale,
  1777. rotateB * scale,
  1778. rotateC * scale,
  1779. rotateD * scale,
  1780. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  1781. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  1782. ];
  1783. this.width = width;
  1784. this.height = height;
  1785. this.fontScale = scale;
  1786. }
  1787. PageViewport.prototype = /** @lends PageViewport.prototype */ {
  1788. /**
  1789. * Clones viewport with additional properties.
  1790. * @param args {Object} (optional) If specified, may contain the 'scale' or
  1791. * 'rotation' properties to override the corresponding properties in
  1792. * the cloned viewport.
  1793. * @returns {PageViewport} Cloned viewport.
  1794. */
  1795. clone: function PageViewPort_clone(args) {
  1796. args = args || {};
  1797. var scale = 'scale' in args ? args.scale : this.scale;
  1798. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  1799. return new PageViewport(this.viewBox.slice(), scale, rotation,
  1800. this.offsetX, this.offsetY, args.dontFlip);
  1801. },
  1802. /**
  1803. * Converts PDF point to the viewport coordinates. For examples, useful for
  1804. * converting PDF location into canvas pixel coordinates.
  1805. * @param x {number} X coordinate.
  1806. * @param y {number} Y coordinate.
  1807. * @returns {Object} Object that contains 'x' and 'y' properties of the
  1808. * point in the viewport coordinate space.
  1809. * @see {@link convertToPdfPoint}
  1810. * @see {@link convertToViewportRectangle}
  1811. */
  1812. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  1813. return Util.applyTransform([x, y], this.transform);
  1814. },
  1815. /**
  1816. * Converts PDF rectangle to the viewport coordinates.
  1817. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  1818. * @returns {Array} Contains corresponding coordinates of the rectangle
  1819. * in the viewport coordinate space.
  1820. * @see {@link convertToViewportPoint}
  1821. */
  1822. convertToViewportRectangle:
  1823. function PageViewport_convertToViewportRectangle(rect) {
  1824. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  1825. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  1826. return [tl[0], tl[1], br[0], br[1]];
  1827. },
  1828. /**
  1829. * Converts viewport coordinates to the PDF location. For examples, useful
  1830. * for converting canvas pixel location into PDF one.
  1831. * @param x {number} X coordinate.
  1832. * @param y {number} Y coordinate.
  1833. * @returns {Object} Object that contains 'x' and 'y' properties of the
  1834. * point in the PDF coordinate space.
  1835. * @see {@link convertToViewportPoint}
  1836. */
  1837. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  1838. return Util.applyInverseTransform([x, y], this.transform);
  1839. }
  1840. };
  1841. return PageViewport;
  1842. })();
  1843. var PDFStringTranslateTable = [
  1844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1845. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  1846. 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,
  1847. 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,
  1848. 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,
  1849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  1850. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  1851. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  1852. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  1853. ];
  1854. function stringToPDFString(str) {
  1855. var i, n = str.length, strBuf = [];
  1856. if (str[0] === '\xFE' && str[1] === '\xFF') {
  1857. // UTF16BE BOM
  1858. for (i = 2; i < n; i += 2) {
  1859. strBuf.push(String.fromCharCode(
  1860. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  1861. }
  1862. } else {
  1863. for (i = 0; i < n; ++i) {
  1864. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  1865. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1866. }
  1867. }
  1868. return strBuf.join('');
  1869. }
  1870. function stringToUTF8String(str) {
  1871. return decodeURIComponent(escape(str));
  1872. }
  1873. function utf8StringToString(str) {
  1874. return unescape(encodeURIComponent(str));
  1875. }
  1876. function isEmptyObj(obj) {
  1877. for (var key in obj) {
  1878. return false;
  1879. }
  1880. return true;
  1881. }
  1882. function isBool(v) {
  1883. return typeof v === 'boolean';
  1884. }
  1885. function isInt(v) {
  1886. return typeof v === 'number' && ((v | 0) === v);
  1887. }
  1888. function isNum(v) {
  1889. return typeof v === 'number';
  1890. }
  1891. function isString(v) {
  1892. return typeof v === 'string';
  1893. }
  1894. function isArray(v) {
  1895. return v instanceof Array;
  1896. }
  1897. function isArrayBuffer(v) {
  1898. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  1899. }
  1900. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  1901. function isSpace(ch) {
  1902. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  1903. }
  1904. /**
  1905. * Promise Capability object.
  1906. *
  1907. * @typedef {Object} PromiseCapability
  1908. * @property {Promise} promise - A promise object.
  1909. * @property {function} resolve - Fulfills the promise.
  1910. * @property {function} reject - Rejects the promise.
  1911. */
  1912. /**
  1913. * Creates a promise capability object.
  1914. * @alias createPromiseCapability
  1915. *
  1916. * @return {PromiseCapability} A capability object contains:
  1917. * - a Promise, resolve and reject methods.
  1918. */
  1919. function createPromiseCapability() {
  1920. var capability = {};
  1921. capability.promise = new Promise(function (resolve, reject) {
  1922. capability.resolve = resolve;
  1923. capability.reject = reject;
  1924. });
  1925. return capability;
  1926. }
  1927. /**
  1928. * Polyfill for Promises:
  1929. * The following promise implementation tries to generally implement the
  1930. * Promise/A+ spec. Some notable differences from other promise libraries are:
  1931. * - There currently isn't a separate deferred and promise object.
  1932. * - Unhandled rejections eventually show an error if they aren't handled.
  1933. *
  1934. * Based off of the work in:
  1935. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  1936. */
  1937. (function PromiseClosure() {
  1938. if (globalScope.Promise) {
  1939. // Promises existing in the DOM/Worker, checking presence of all/resolve
  1940. if (typeof globalScope.Promise.all !== 'function') {
  1941. globalScope.Promise.all = function (iterable) {
  1942. var count = 0, results = [], resolve, reject;
  1943. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1944. resolve = resolve_;
  1945. reject = reject_;
  1946. });
  1947. iterable.forEach(function (p, i) {
  1948. count++;
  1949. p.then(function (result) {
  1950. results[i] = result;
  1951. count--;
  1952. if (count === 0) {
  1953. resolve(results);
  1954. }
  1955. }, reject);
  1956. });
  1957. if (count === 0) {
  1958. resolve(results);
  1959. }
  1960. return promise;
  1961. };
  1962. }
  1963. if (typeof globalScope.Promise.resolve !== 'function') {
  1964. globalScope.Promise.resolve = function (value) {
  1965. return new globalScope.Promise(function (resolve) { resolve(value); });
  1966. };
  1967. }
  1968. if (typeof globalScope.Promise.reject !== 'function') {
  1969. globalScope.Promise.reject = function (reason) {
  1970. return new globalScope.Promise(function (resolve, reject) {
  1971. reject(reason);
  1972. });
  1973. };
  1974. }
  1975. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1976. globalScope.Promise.prototype.catch = function (onReject) {
  1977. return globalScope.Promise.prototype.then(undefined, onReject);
  1978. };
  1979. }
  1980. return;
  1981. }
  1982. var STATUS_PENDING = 0;
  1983. var STATUS_RESOLVED = 1;
  1984. var STATUS_REJECTED = 2;
  1985. // In an attempt to avoid silent exceptions, unhandled rejections are
  1986. // tracked and if they aren't handled in a certain amount of time an
  1987. // error is logged.
  1988. var REJECTION_TIMEOUT = 500;
  1989. var HandlerManager = {
  1990. handlers: [],
  1991. running: false,
  1992. unhandledRejections: [],
  1993. pendingRejectionCheck: false,
  1994. scheduleHandlers: function scheduleHandlers(promise) {
  1995. if (promise._status === STATUS_PENDING) {
  1996. return;
  1997. }
  1998. this.handlers = this.handlers.concat(promise._handlers);
  1999. promise._handlers = [];
  2000. if (this.running) {
  2001. return;
  2002. }
  2003. this.running = true;
  2004. setTimeout(this.runHandlers.bind(this), 0);
  2005. },
  2006. runHandlers: function runHandlers() {
  2007. var RUN_TIMEOUT = 1; // ms
  2008. var timeoutAt = Date.now() + RUN_TIMEOUT;
  2009. while (this.handlers.length > 0) {
  2010. var handler = this.handlers.shift();
  2011. var nextStatus = handler.thisPromise._status;
  2012. var nextValue = handler.thisPromise._value;
  2013. try {
  2014. if (nextStatus === STATUS_RESOLVED) {
  2015. if (typeof handler.onResolve === 'function') {
  2016. nextValue = handler.onResolve(nextValue);
  2017. }
  2018. } else if (typeof handler.onReject === 'function') {
  2019. nextValue = handler.onReject(nextValue);
  2020. nextStatus = STATUS_RESOLVED;
  2021. if (handler.thisPromise._unhandledRejection) {
  2022. this.removeUnhandeledRejection(handler.thisPromise);
  2023. }
  2024. }
  2025. } catch (ex) {
  2026. nextStatus = STATUS_REJECTED;
  2027. nextValue = ex;
  2028. }
  2029. handler.nextPromise._updateStatus(nextStatus, nextValue);
  2030. if (Date.now() >= timeoutAt) {
  2031. break;
  2032. }
  2033. }
  2034. if (this.handlers.length > 0) {
  2035. setTimeout(this.runHandlers.bind(this), 0);
  2036. return;
  2037. }
  2038. this.running = false;
  2039. },
  2040. addUnhandledRejection: function addUnhandledRejection(promise) {
  2041. this.unhandledRejections.push({
  2042. promise: promise,
  2043. time: Date.now()
  2044. });
  2045. this.scheduleRejectionCheck();
  2046. },
  2047. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  2048. promise._unhandledRejection = false;
  2049. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2050. if (this.unhandledRejections[i].promise === promise) {
  2051. this.unhandledRejections.splice(i);
  2052. i--;
  2053. }
  2054. }
  2055. },
  2056. scheduleRejectionCheck: function scheduleRejectionCheck() {
  2057. if (this.pendingRejectionCheck) {
  2058. return;
  2059. }
  2060. this.pendingRejectionCheck = true;
  2061. setTimeout(function rejectionCheck() {
  2062. this.pendingRejectionCheck = false;
  2063. var now = Date.now();
  2064. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2065. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  2066. var unhandled = this.unhandledRejections[i].promise._value;
  2067. var msg = 'Unhandled rejection: ' + unhandled;
  2068. if (unhandled.stack) {
  2069. msg += '\n' + unhandled.stack;
  2070. }
  2071. warn(msg);
  2072. this.unhandledRejections.splice(i);
  2073. i--;
  2074. }
  2075. }
  2076. if (this.unhandledRejections.length) {
  2077. this.scheduleRejectionCheck();
  2078. }
  2079. }.bind(this), REJECTION_TIMEOUT);
  2080. }
  2081. };
  2082. function Promise(resolver) {
  2083. this._status = STATUS_PENDING;
  2084. this._handlers = [];
  2085. try {
  2086. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  2087. } catch (e) {
  2088. this._reject(e);
  2089. }
  2090. }
  2091. /**
  2092. * Builds a promise that is resolved when all the passed in promises are
  2093. * resolved.
  2094. * @param {array} promises array of data and/or promises to wait for.
  2095. * @return {Promise} New dependent promise.
  2096. */
  2097. Promise.all = function Promise_all(promises) {
  2098. var resolveAll, rejectAll;
  2099. var deferred = new Promise(function (resolve, reject) {
  2100. resolveAll = resolve;
  2101. rejectAll = reject;
  2102. });
  2103. var unresolved = promises.length;
  2104. var results = [];
  2105. if (unresolved === 0) {
  2106. resolveAll(results);
  2107. return deferred;
  2108. }
  2109. function reject(reason) {
  2110. if (deferred._status === STATUS_REJECTED) {
  2111. return;
  2112. }
  2113. results = [];
  2114. rejectAll(reason);
  2115. }
  2116. for (var i = 0, ii = promises.length; i < ii; ++i) {
  2117. var promise = promises[i];
  2118. var resolve = (function(i) {
  2119. return function(value) {
  2120. if (deferred._status === STATUS_REJECTED) {
  2121. return;
  2122. }
  2123. results[i] = value;
  2124. unresolved--;
  2125. if (unresolved === 0) {
  2126. resolveAll(results);
  2127. }
  2128. };
  2129. })(i);
  2130. if (Promise.isPromise(promise)) {
  2131. promise.then(resolve, reject);
  2132. } else {
  2133. resolve(promise);
  2134. }
  2135. }
  2136. return deferred;
  2137. };
  2138. /**
  2139. * Checks if the value is likely a promise (has a 'then' function).
  2140. * @return {boolean} true if value is thenable
  2141. */
  2142. Promise.isPromise = function Promise_isPromise(value) {
  2143. return value && typeof value.then === 'function';
  2144. };
  2145. /**
  2146. * Creates resolved promise
  2147. * @param value resolve value
  2148. * @returns {Promise}
  2149. */
  2150. Promise.resolve = function Promise_resolve(value) {
  2151. return new Promise(function (resolve) { resolve(value); });
  2152. };
  2153. /**
  2154. * Creates rejected promise
  2155. * @param reason rejection value
  2156. * @returns {Promise}
  2157. */
  2158. Promise.reject = function Promise_reject(reason) {
  2159. return new Promise(function (resolve, reject) { reject(reason); });
  2160. };
  2161. Promise.prototype = {
  2162. _status: null,
  2163. _value: null,
  2164. _handlers: null,
  2165. _unhandledRejection: null,
  2166. _updateStatus: function Promise__updateStatus(status, value) {
  2167. if (this._status === STATUS_RESOLVED ||
  2168. this._status === STATUS_REJECTED) {
  2169. return;
  2170. }
  2171. if (status === STATUS_RESOLVED &&
  2172. Promise.isPromise(value)) {
  2173. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  2174. this._updateStatus.bind(this, STATUS_REJECTED));
  2175. return;
  2176. }
  2177. this._status = status;
  2178. this._value = value;
  2179. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  2180. this._unhandledRejection = true;
  2181. HandlerManager.addUnhandledRejection(this);
  2182. }
  2183. HandlerManager.scheduleHandlers(this);
  2184. },
  2185. _resolve: function Promise_resolve(value) {
  2186. this._updateStatus(STATUS_RESOLVED, value);
  2187. },
  2188. _reject: function Promise_reject(reason) {
  2189. this._updateStatus(STATUS_REJECTED, reason);
  2190. },
  2191. then: function Promise_then(onResolve, onReject) {
  2192. var nextPromise = new Promise(function (resolve, reject) {
  2193. this.resolve = resolve;
  2194. this.reject = reject;
  2195. });
  2196. this._handlers.push({
  2197. thisPromise: this,
  2198. onResolve: onResolve,
  2199. onReject: onReject,
  2200. nextPromise: nextPromise
  2201. });
  2202. HandlerManager.scheduleHandlers(this);
  2203. return nextPromise;
  2204. },
  2205. catch: function Promise_catch(onReject) {
  2206. return this.then(undefined, onReject);
  2207. }
  2208. };
  2209. globalScope.Promise = Promise;
  2210. })();
  2211. (function WeakMapClosure() {
  2212. if (globalScope.WeakMap) {
  2213. return;
  2214. }
  2215. var id = 0;
  2216. function WeakMap() {
  2217. this.id = '$weakmap' + (id++);
  2218. }
  2219. WeakMap.prototype = {
  2220. has: function(obj) {
  2221. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  2222. },
  2223. get: function(obj, defaultValue) {
  2224. return this.has(obj) ? obj[this.id] : defaultValue;
  2225. },
  2226. set: function(obj, value) {
  2227. Object.defineProperty(obj, this.id, {
  2228. value: value,
  2229. enumerable: false,
  2230. configurable: true
  2231. });
  2232. },
  2233. delete: function(obj) {
  2234. delete obj[this.id];
  2235. }
  2236. };
  2237. globalScope.WeakMap = WeakMap;
  2238. })();
  2239. var StatTimer = (function StatTimerClosure() {
  2240. function rpad(str, pad, length) {
  2241. while (str.length < length) {
  2242. str += pad;
  2243. }
  2244. return str;
  2245. }
  2246. function StatTimer() {
  2247. this.started = Object.create(null);
  2248. this.times = [];
  2249. this.enabled = true;
  2250. }
  2251. StatTimer.prototype = {
  2252. time: function StatTimer_time(name) {
  2253. if (!this.enabled) {
  2254. return;
  2255. }
  2256. if (name in this.started) {
  2257. warn('Timer is already running for ' + name);
  2258. }
  2259. this.started[name] = Date.now();
  2260. },
  2261. timeEnd: function StatTimer_timeEnd(name) {
  2262. if (!this.enabled) {
  2263. return;
  2264. }
  2265. if (!(name in this.started)) {
  2266. warn('Timer has not been started for ' + name);
  2267. }
  2268. this.times.push({
  2269. 'name': name,
  2270. 'start': this.started[name],
  2271. 'end': Date.now()
  2272. });
  2273. // Remove timer from started so it can be called again.
  2274. delete this.started[name];
  2275. },
  2276. toString: function StatTimer_toString() {
  2277. var i, ii;
  2278. var times = this.times;
  2279. var out = '';
  2280. // Find the longest name for padding purposes.
  2281. var longest = 0;
  2282. for (i = 0, ii = times.length; i < ii; ++i) {
  2283. var name = times[i]['name'];
  2284. if (name.length > longest) {
  2285. longest = name.length;
  2286. }
  2287. }
  2288. for (i = 0, ii = times.length; i < ii; ++i) {
  2289. var span = times[i];
  2290. var duration = span.end - span.start;
  2291. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  2292. }
  2293. return out;
  2294. }
  2295. };
  2296. return StatTimer;
  2297. })();
  2298. var createBlob = function createBlob(data, contentType) {
  2299. if (typeof Blob !== 'undefined') {
  2300. return new Blob([data], { type: contentType });
  2301. }
  2302. warn('The "Blob" constructor is not supported.');
  2303. };
  2304. var createObjectURL = (function createObjectURLClosure() {
  2305. // Blob/createObjectURL is not available, falling back to data schema.
  2306. var digits =
  2307. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  2308. return function createObjectURL(data, contentType, forceDataSchema) {
  2309. if (!forceDataSchema &&
  2310. typeof URL !== 'undefined' && URL.createObjectURL) {
  2311. var blob = createBlob(data, contentType);
  2312. return URL.createObjectURL(blob);
  2313. }
  2314. var buffer = 'data:' + contentType + ';base64,';
  2315. for (var i = 0, ii = data.length; i < ii; i += 3) {
  2316. var b1 = data[i] & 0xFF;
  2317. var b2 = data[i + 1] & 0xFF;
  2318. var b3 = data[i + 2] & 0xFF;
  2319. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  2320. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  2321. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  2322. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  2323. }
  2324. return buffer;
  2325. };
  2326. })();
  2327. function MessageHandler(sourceName, targetName, comObj) {
  2328. this.sourceName = sourceName;
  2329. this.targetName = targetName;
  2330. this.comObj = comObj;
  2331. this.callbackIndex = 1;
  2332. this.postMessageTransfers = true;
  2333. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  2334. var ah = this.actionHandler = Object.create(null);
  2335. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  2336. var data = event.data;
  2337. if (data.targetName !== this.sourceName) {
  2338. return;
  2339. }
  2340. if (data.isReply) {
  2341. var callbackId = data.callbackId;
  2342. if (data.callbackId in callbacksCapabilities) {
  2343. var callback = callbacksCapabilities[callbackId];
  2344. delete callbacksCapabilities[callbackId];
  2345. if ('error' in data) {
  2346. callback.reject(data.error);
  2347. } else {
  2348. callback.resolve(data.data);
  2349. }
  2350. } else {
  2351. error('Cannot resolve callback ' + callbackId);
  2352. }
  2353. } else if (data.action in ah) {
  2354. var action = ah[data.action];
  2355. if (data.callbackId) {
  2356. var sourceName = this.sourceName;
  2357. var targetName = data.sourceName;
  2358. Promise.resolve().then(function () {
  2359. return action[0].call(action[1], data.data);
  2360. }).then(function (result) {
  2361. comObj.postMessage({
  2362. sourceName: sourceName,
  2363. targetName: targetName,
  2364. isReply: true,
  2365. callbackId: data.callbackId,
  2366. data: result
  2367. });
  2368. }, function (reason) {
  2369. if (reason instanceof Error) {
  2370. // Serialize error to avoid "DataCloneError"
  2371. reason = reason + '';
  2372. }
  2373. comObj.postMessage({
  2374. sourceName: sourceName,
  2375. targetName: targetName,
  2376. isReply: true,
  2377. callbackId: data.callbackId,
  2378. error: reason
  2379. });
  2380. });
  2381. } else {
  2382. action[0].call(action[1], data.data);
  2383. }
  2384. } else {
  2385. error('Unknown action from worker: ' + data.action);
  2386. }
  2387. }.bind(this);
  2388. comObj.addEventListener('message', this._onComObjOnMessage);
  2389. }
  2390. MessageHandler.prototype = {
  2391. on: function messageHandlerOn(actionName, handler, scope) {
  2392. var ah = this.actionHandler;
  2393. if (ah[actionName]) {
  2394. error('There is already an actionName called "' + actionName + '"');
  2395. }
  2396. ah[actionName] = [handler, scope];
  2397. },
  2398. /**
  2399. * Sends a message to the comObj to invoke the action with the supplied data.
  2400. * @param {String} actionName Action to call.
  2401. * @param {JSON} data JSON data to send.
  2402. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  2403. */
  2404. send: function messageHandlerSend(actionName, data, transfers) {
  2405. var message = {
  2406. sourceName: this.sourceName,
  2407. targetName: this.targetName,
  2408. action: actionName,
  2409. data: data
  2410. };
  2411. this.postMessage(message, transfers);
  2412. },
  2413. /**
  2414. * Sends a message to the comObj to invoke the action with the supplied data.
  2415. * Expects that other side will callback with the response.
  2416. * @param {String} actionName Action to call.
  2417. * @param {JSON} data JSON data to send.
  2418. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  2419. * @returns {Promise} Promise to be resolved with response data.
  2420. */
  2421. sendWithPromise:
  2422. function messageHandlerSendWithPromise(actionName, data, transfers) {
  2423. var callbackId = this.callbackIndex++;
  2424. var message = {
  2425. sourceName: this.sourceName,
  2426. targetName: this.targetName,
  2427. action: actionName,
  2428. data: data,
  2429. callbackId: callbackId
  2430. };
  2431. var capability = createPromiseCapability();
  2432. this.callbacksCapabilities[callbackId] = capability;
  2433. try {
  2434. this.postMessage(message, transfers);
  2435. } catch (e) {
  2436. capability.reject(e);
  2437. }
  2438. return capability.promise;
  2439. },
  2440. /**
  2441. * Sends raw message to the comObj.
  2442. * @private
  2443. * @param message {Object} Raw message.
  2444. * @param transfers List of transfers/ArrayBuffers, or undefined.
  2445. */
  2446. postMessage: function (message, transfers) {
  2447. if (transfers && this.postMessageTransfers) {
  2448. this.comObj.postMessage(message, transfers);
  2449. } else {
  2450. this.comObj.postMessage(message);
  2451. }
  2452. },
  2453. destroy: function () {
  2454. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  2455. }
  2456. };
  2457. function loadJpegStream(id, imageUrl, objs) {
  2458. var img = new Image();
  2459. img.onload = (function loadJpegStream_onloadClosure() {
  2460. objs.resolve(id, img);
  2461. });
  2462. img.onerror = (function loadJpegStream_onerrorClosure() {
  2463. objs.resolve(id, null);
  2464. warn('Error during JPEG image loading');
  2465. });
  2466. img.src = imageUrl;
  2467. }
  2468. // Polyfill from https://github.com/Polymer/URL
  2469. /* Any copyright is dedicated to the Public Domain.
  2470. * http://creativecommons.org/publicdomain/zero/1.0/ */
  2471. (function checkURLConstructor(scope) {
  2472. // feature detect for URL constructor
  2473. var hasWorkingUrl = false;
  2474. try {
  2475. if (typeof URL === 'function' &&
  2476. typeof URL.prototype === 'object' &&
  2477. ('origin' in URL.prototype)) {
  2478. var u = new URL('b', 'http://a');
  2479. u.pathname = 'c%20d';
  2480. hasWorkingUrl = u.href === 'http://a/c%20d';
  2481. }
  2482. } catch(e) { }
  2483. if (hasWorkingUrl) {
  2484. return;
  2485. }
  2486. var relative = Object.create(null);
  2487. relative['ftp'] = 21;
  2488. relative['file'] = 0;
  2489. relative['gopher'] = 70;
  2490. relative['http'] = 80;
  2491. relative['https'] = 443;
  2492. relative['ws'] = 80;
  2493. relative['wss'] = 443;
  2494. var relativePathDotMapping = Object.create(null);
  2495. relativePathDotMapping['%2e'] = '.';
  2496. relativePathDotMapping['.%2e'] = '..';
  2497. relativePathDotMapping['%2e.'] = '..';
  2498. relativePathDotMapping['%2e%2e'] = '..';
  2499. function isRelativeScheme(scheme) {
  2500. return relative[scheme] !== undefined;
  2501. }
  2502. function invalid() {
  2503. clear.call(this);
  2504. this._isInvalid = true;
  2505. }
  2506. function IDNAToASCII(h) {
  2507. if ('' === h) {
  2508. invalid.call(this);
  2509. }
  2510. // XXX
  2511. return h.toLowerCase();
  2512. }
  2513. function percentEscape(c) {
  2514. var unicode = c.charCodeAt(0);
  2515. if (unicode > 0x20 &&
  2516. unicode < 0x7F &&
  2517. // " # < > ? `
  2518. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1
  2519. ) {
  2520. return c;
  2521. }
  2522. return encodeURIComponent(c);
  2523. }
  2524. function percentEscapeQuery(c) {
  2525. // XXX This actually needs to encode c using encoding and then
  2526. // convert the bytes one-by-one.
  2527. var unicode = c.charCodeAt(0);
  2528. if (unicode > 0x20 &&
  2529. unicode < 0x7F &&
  2530. // " # < > ` (do not escape '?')
  2531. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1
  2532. ) {
  2533. return c;
  2534. }
  2535. return encodeURIComponent(c);
  2536. }
  2537. var EOF, ALPHA = /[a-zA-Z]/,
  2538. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  2539. function parse(input, stateOverride, base) {
  2540. function err(message) {
  2541. errors.push(message);
  2542. }
  2543. var state = stateOverride || 'scheme start',
  2544. cursor = 0,
  2545. buffer = '',
  2546. seenAt = false,
  2547. seenBracket = false,
  2548. errors = [];
  2549. loop: while ((input[cursor - 1] !== EOF || cursor === 0) &&
  2550. !this._isInvalid) {
  2551. var c = input[cursor];
  2552. switch (state) {
  2553. case 'scheme start':
  2554. if (c && ALPHA.test(c)) {
  2555. buffer += c.toLowerCase(); // ASCII-safe
  2556. state = 'scheme';
  2557. } else if (!stateOverride) {
  2558. buffer = '';
  2559. state = 'no scheme';
  2560. continue;
  2561. } else {
  2562. err('Invalid scheme.');
  2563. break loop;
  2564. }
  2565. break;
  2566. case 'scheme':
  2567. if (c && ALPHANUMERIC.test(c)) {
  2568. buffer += c.toLowerCase(); // ASCII-safe
  2569. } else if (':' === c) {
  2570. this._scheme = buffer;
  2571. buffer = '';
  2572. if (stateOverride) {
  2573. break loop;
  2574. }
  2575. if (isRelativeScheme(this._scheme)) {
  2576. this._isRelative = true;
  2577. }
  2578. if ('file' === this._scheme) {
  2579. state = 'relative';
  2580. } else if (this._isRelative && base &&
  2581. base._scheme === this._scheme) {
  2582. state = 'relative or authority';
  2583. } else if (this._isRelative) {
  2584. state = 'authority first slash';
  2585. } else {
  2586. state = 'scheme data';
  2587. }
  2588. } else if (!stateOverride) {
  2589. buffer = '';
  2590. cursor = 0;
  2591. state = 'no scheme';
  2592. continue;
  2593. } else if (EOF === c) {
  2594. break loop;
  2595. } else {
  2596. err('Code point not allowed in scheme: ' + c);
  2597. break loop;
  2598. }
  2599. break;
  2600. case 'scheme data':
  2601. if ('?' === c) {
  2602. this._query = '?';
  2603. state = 'query';
  2604. } else if ('#' === c) {
  2605. this._fragment = '#';
  2606. state = 'fragment';
  2607. } else {
  2608. // XXX error handling
  2609. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2610. this._schemeData += percentEscape(c);
  2611. }
  2612. }
  2613. break;
  2614. case 'no scheme':
  2615. if (!base || !(isRelativeScheme(base._scheme))) {
  2616. err('Missing scheme.');
  2617. invalid.call(this);
  2618. } else {
  2619. state = 'relative';
  2620. continue;
  2621. }
  2622. break;
  2623. case 'relative or authority':
  2624. if ('/' === c && '/' === input[cursor+1]) {
  2625. state = 'authority ignore slashes';
  2626. } else {
  2627. err('Expected /, got: ' + c);
  2628. state = 'relative';
  2629. continue;
  2630. }
  2631. break;
  2632. case 'relative':
  2633. this._isRelative = true;
  2634. if ('file' !== this._scheme) {
  2635. this._scheme = base._scheme;
  2636. }
  2637. if (EOF === c) {
  2638. this._host = base._host;
  2639. this._port = base._port;
  2640. this._path = base._path.slice();
  2641. this._query = base._query;
  2642. this._username = base._username;
  2643. this._password = base._password;
  2644. break loop;
  2645. } else if ('/' === c || '\\' === c) {
  2646. if ('\\' === c) {
  2647. err('\\ is an invalid code point.');
  2648. }
  2649. state = 'relative slash';
  2650. } else if ('?' === c) {
  2651. this._host = base._host;
  2652. this._port = base._port;
  2653. this._path = base._path.slice();
  2654. this._query = '?';
  2655. this._username = base._username;
  2656. this._password = base._password;
  2657. state = 'query';
  2658. } else if ('#' === c) {
  2659. this._host = base._host;
  2660. this._port = base._port;
  2661. this._path = base._path.slice();
  2662. this._query = base._query;
  2663. this._fragment = '#';
  2664. this._username = base._username;
  2665. this._password = base._password;
  2666. state = 'fragment';
  2667. } else {
  2668. var nextC = input[cursor+1];
  2669. var nextNextC = input[cursor+2];
  2670. if ('file' !== this._scheme || !ALPHA.test(c) ||
  2671. (nextC !== ':' && nextC !== '|') ||
  2672. (EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC &&
  2673. '?' !== nextNextC && '#' !== nextNextC)) {
  2674. this._host = base._host;
  2675. this._port = base._port;
  2676. this._username = base._username;
  2677. this._password = base._password;
  2678. this._path = base._path.slice();
  2679. this._path.pop();
  2680. }
  2681. state = 'relative path';
  2682. continue;
  2683. }
  2684. break;
  2685. case 'relative slash':
  2686. if ('/' === c || '\\' === c) {
  2687. if ('\\' === c) {
  2688. err('\\ is an invalid code point.');
  2689. }
  2690. if ('file' === this._scheme) {
  2691. state = 'file host';
  2692. } else {
  2693. state = 'authority ignore slashes';
  2694. }
  2695. } else {
  2696. if ('file' !== this._scheme) {
  2697. this._host = base._host;
  2698. this._port = base._port;
  2699. this._username = base._username;
  2700. this._password = base._password;
  2701. }
  2702. state = 'relative path';
  2703. continue;
  2704. }
  2705. break;
  2706. case 'authority first slash':
  2707. if ('/' === c) {
  2708. state = 'authority second slash';
  2709. } else {
  2710. err('Expected \'/\', got: ' + c);
  2711. state = 'authority ignore slashes';
  2712. continue;
  2713. }
  2714. break;
  2715. case 'authority second slash':
  2716. state = 'authority ignore slashes';
  2717. if ('/' !== c) {
  2718. err('Expected \'/\', got: ' + c);
  2719. continue;
  2720. }
  2721. break;
  2722. case 'authority ignore slashes':
  2723. if ('/' !== c && '\\' !== c) {
  2724. state = 'authority';
  2725. continue;
  2726. } else {
  2727. err('Expected authority, got: ' + c);
  2728. }
  2729. break;
  2730. case 'authority':
  2731. if ('@' === c) {
  2732. if (seenAt) {
  2733. err('@ already seen.');
  2734. buffer += '%40';
  2735. }
  2736. seenAt = true;
  2737. for (var i = 0; i < buffer.length; i++) {
  2738. var cp = buffer[i];
  2739. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  2740. err('Invalid whitespace in authority.');
  2741. continue;
  2742. }
  2743. // XXX check URL code points
  2744. if (':' === cp && null === this._password) {
  2745. this._password = '';
  2746. continue;
  2747. }
  2748. var tempC = percentEscape(cp);
  2749. if (null !== this._password) {
  2750. this._password += tempC;
  2751. } else {
  2752. this._username += tempC;
  2753. }
  2754. }
  2755. buffer = '';
  2756. } else if (EOF === c || '/' === c || '\\' === c ||
  2757. '?' === c || '#' === c) {
  2758. cursor -= buffer.length;
  2759. buffer = '';
  2760. state = 'host';
  2761. continue;
  2762. } else {
  2763. buffer += c;
  2764. }
  2765. break;
  2766. case 'file host':
  2767. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  2768. if (buffer.length === 2 && ALPHA.test(buffer[0]) &&
  2769. (buffer[1] === ':' || buffer[1] === '|')) {
  2770. state = 'relative path';
  2771. } else if (buffer.length === 0) {
  2772. state = 'relative path start';
  2773. } else {
  2774. this._host = IDNAToASCII.call(this, buffer);
  2775. buffer = '';
  2776. state = 'relative path start';
  2777. }
  2778. continue;
  2779. } else if ('\t' === c || '\n' === c || '\r' === c) {
  2780. err('Invalid whitespace in file host.');
  2781. } else {
  2782. buffer += c;
  2783. }
  2784. break;
  2785. case 'host':
  2786. case 'hostname':
  2787. if (':' === c && !seenBracket) {
  2788. // XXX host parsing
  2789. this._host = IDNAToASCII.call(this, buffer);
  2790. buffer = '';
  2791. state = 'port';
  2792. if ('hostname' === stateOverride) {
  2793. break loop;
  2794. }
  2795. } else if (EOF === c || '/' === c ||
  2796. '\\' === c || '?' === c || '#' === c) {
  2797. this._host = IDNAToASCII.call(this, buffer);
  2798. buffer = '';
  2799. state = 'relative path start';
  2800. if (stateOverride) {
  2801. break loop;
  2802. }
  2803. continue;
  2804. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  2805. if ('[' === c) {
  2806. seenBracket = true;
  2807. } else if (']' === c) {
  2808. seenBracket = false;
  2809. }
  2810. buffer += c;
  2811. } else {
  2812. err('Invalid code point in host/hostname: ' + c);
  2813. }
  2814. break;
  2815. case 'port':
  2816. if (/[0-9]/.test(c)) {
  2817. buffer += c;
  2818. } else if (EOF === c || '/' === c || '\\' === c ||
  2819. '?' === c || '#' === c || stateOverride) {
  2820. if ('' !== buffer) {
  2821. var temp = parseInt(buffer, 10);
  2822. if (temp !== relative[this._scheme]) {
  2823. this._port = temp + '';
  2824. }
  2825. buffer = '';
  2826. }
  2827. if (stateOverride) {
  2828. break loop;
  2829. }
  2830. state = 'relative path start';
  2831. continue;
  2832. } else if ('\t' === c || '\n' === c || '\r' === c) {
  2833. err('Invalid code point in port: ' + c);
  2834. } else {
  2835. invalid.call(this);
  2836. }
  2837. break;
  2838. case 'relative path start':
  2839. if ('\\' === c) {
  2840. err('\'\\\' not allowed in path.');
  2841. }
  2842. state = 'relative path';
  2843. if ('/' !== c && '\\' !== c) {
  2844. continue;
  2845. }
  2846. break;
  2847. case 'relative path':
  2848. if (EOF === c || '/' === c || '\\' === c ||
  2849. (!stateOverride && ('?' === c || '#' === c))) {
  2850. if ('\\' === c) {
  2851. err('\\ not allowed in relative path.');
  2852. }
  2853. var tmp;
  2854. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  2855. buffer = tmp;
  2856. }
  2857. if ('..' === buffer) {
  2858. this._path.pop();
  2859. if ('/' !== c && '\\' !== c) {
  2860. this._path.push('');
  2861. }
  2862. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  2863. this._path.push('');
  2864. } else if ('.' !== buffer) {
  2865. if ('file' === this._scheme && this._path.length === 0 &&
  2866. buffer.length === 2 && ALPHA.test(buffer[0]) &&
  2867. buffer[1] === '|') {
  2868. buffer = buffer[0] + ':';
  2869. }
  2870. this._path.push(buffer);
  2871. }
  2872. buffer = '';
  2873. if ('?' === c) {
  2874. this._query = '?';
  2875. state = 'query';
  2876. } else if ('#' === c) {
  2877. this._fragment = '#';
  2878. state = 'fragment';
  2879. }
  2880. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  2881. buffer += percentEscape(c);
  2882. }
  2883. break;
  2884. case 'query':
  2885. if (!stateOverride && '#' === c) {
  2886. this._fragment = '#';
  2887. state = 'fragment';
  2888. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2889. this._query += percentEscapeQuery(c);
  2890. }
  2891. break;
  2892. case 'fragment':
  2893. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2894. this._fragment += c;
  2895. }
  2896. break;
  2897. }
  2898. cursor++;
  2899. }
  2900. }
  2901. function clear() {
  2902. this._scheme = '';
  2903. this._schemeData = '';
  2904. this._username = '';
  2905. this._password = null;
  2906. this._host = '';
  2907. this._port = '';
  2908. this._path = [];
  2909. this._query = '';
  2910. this._fragment = '';
  2911. this._isInvalid = false;
  2912. this._isRelative = false;
  2913. }
  2914. // Does not process domain names or IP addresses.
  2915. // Does not handle encoding for the query parameter.
  2916. function JURL(url, base /* , encoding */) {
  2917. if (base !== undefined && !(base instanceof JURL)) {
  2918. base = new JURL(String(base));
  2919. }
  2920. this._url = url;
  2921. clear.call(this);
  2922. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  2923. // encoding = encoding || 'utf-8'
  2924. parse.call(this, input, null, base);
  2925. }
  2926. JURL.prototype = {
  2927. toString: function() {
  2928. return this.href;
  2929. },
  2930. get href() {
  2931. if (this._isInvalid) {
  2932. return this._url;
  2933. }
  2934. var authority = '';
  2935. if ('' !== this._username || null !== this._password) {
  2936. authority = this._username +
  2937. (null !== this._password ? ':' + this._password : '') + '@';
  2938. }
  2939. return this.protocol +
  2940. (this._isRelative ? '//' + authority + this.host : '') +
  2941. this.pathname + this._query + this._fragment;
  2942. },
  2943. set href(href) {
  2944. clear.call(this);
  2945. parse.call(this, href);
  2946. },
  2947. get protocol() {
  2948. return this._scheme + ':';
  2949. },
  2950. set protocol(protocol) {
  2951. if (this._isInvalid) {
  2952. return;
  2953. }
  2954. parse.call(this, protocol + ':', 'scheme start');
  2955. },
  2956. get host() {
  2957. return this._isInvalid ? '' : this._port ?
  2958. this._host + ':' + this._port : this._host;
  2959. },
  2960. set host(host) {
  2961. if (this._isInvalid || !this._isRelative) {
  2962. return;
  2963. }
  2964. parse.call(this, host, 'host');
  2965. },
  2966. get hostname() {
  2967. return this._host;
  2968. },
  2969. set hostname(hostname) {
  2970. if (this._isInvalid || !this._isRelative) {
  2971. return;
  2972. }
  2973. parse.call(this, hostname, 'hostname');
  2974. },
  2975. get port() {
  2976. return this._port;
  2977. },
  2978. set port(port) {
  2979. if (this._isInvalid || !this._isRelative) {
  2980. return;
  2981. }
  2982. parse.call(this, port, 'port');
  2983. },
  2984. get pathname() {
  2985. return this._isInvalid ? '' : this._isRelative ?
  2986. '/' + this._path.join('/') : this._schemeData;
  2987. },
  2988. set pathname(pathname) {
  2989. if (this._isInvalid || !this._isRelative) {
  2990. return;
  2991. }
  2992. this._path = [];
  2993. parse.call(this, pathname, 'relative path start');
  2994. },
  2995. get search() {
  2996. return this._isInvalid || !this._query || '?' === this._query ?
  2997. '' : this._query;
  2998. },
  2999. set search(search) {
  3000. if (this._isInvalid || !this._isRelative) {
  3001. return;
  3002. }
  3003. this._query = '?';
  3004. if ('?' === search[0]) {
  3005. search = search.slice(1);
  3006. }
  3007. parse.call(this, search, 'query');
  3008. },
  3009. get hash() {
  3010. return this._isInvalid || !this._fragment || '#' === this._fragment ?
  3011. '' : this._fragment;
  3012. },
  3013. set hash(hash) {
  3014. if (this._isInvalid) {
  3015. return;
  3016. }
  3017. this._fragment = '#';
  3018. if ('#' === hash[0]) {
  3019. hash = hash.slice(1);
  3020. }
  3021. parse.call(this, hash, 'fragment');
  3022. },
  3023. get origin() {
  3024. var host;
  3025. if (this._isInvalid || !this._scheme) {
  3026. return '';
  3027. }
  3028. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  3029. // Gecko throws error for "data://"
  3030. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  3031. // Gecko returns String("") for file: mailto:
  3032. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  3033. switch (this._scheme) {
  3034. case 'data':
  3035. case 'file':
  3036. case 'javascript':
  3037. case 'mailto':
  3038. return 'null';
  3039. }
  3040. host = this.host;
  3041. if (!host) {
  3042. return '';
  3043. }
  3044. return this._scheme + '://' + host;
  3045. }
  3046. };
  3047. // Copy over the static methods
  3048. var OriginalURL = scope.URL;
  3049. if (OriginalURL) {
  3050. JURL.createObjectURL = function(blob) {
  3051. // IE extension allows a second optional options argument.
  3052. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  3053. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  3054. };
  3055. JURL.revokeObjectURL = function(url) {
  3056. OriginalURL.revokeObjectURL(url);
  3057. };
  3058. }
  3059. scope.URL = JURL;
  3060. })(globalScope);
  3061. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  3062. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  3063. exports.OPS = OPS;
  3064. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  3065. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  3066. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  3067. exports.AnnotationFlag = AnnotationFlag;
  3068. exports.AnnotationType = AnnotationType;
  3069. exports.FontType = FontType;
  3070. exports.ImageKind = ImageKind;
  3071. exports.InvalidPDFException = InvalidPDFException;
  3072. exports.MessageHandler = MessageHandler;
  3073. exports.MissingDataException = MissingDataException;
  3074. exports.MissingPDFException = MissingPDFException;
  3075. exports.NotImplementedException = NotImplementedException;
  3076. exports.PageViewport = PageViewport;
  3077. exports.PasswordException = PasswordException;
  3078. exports.PasswordResponses = PasswordResponses;
  3079. exports.StatTimer = StatTimer;
  3080. exports.StreamType = StreamType;
  3081. exports.TextRenderingMode = TextRenderingMode;
  3082. exports.UnexpectedResponseException = UnexpectedResponseException;
  3083. exports.UnknownErrorException = UnknownErrorException;
  3084. exports.Util = Util;
  3085. exports.XRefParseException = XRefParseException;
  3086. exports.arrayByteLength = arrayByteLength;
  3087. exports.arraysToBytes = arraysToBytes;
  3088. exports.assert = assert;
  3089. exports.bytesToString = bytesToString;
  3090. exports.createBlob = createBlob;
  3091. exports.createPromiseCapability = createPromiseCapability;
  3092. exports.createObjectURL = createObjectURL;
  3093. exports.deprecated = deprecated;
  3094. exports.error = error;
  3095. exports.getLookupTableFactory = getLookupTableFactory;
  3096. exports.getVerbosityLevel = getVerbosityLevel;
  3097. exports.globalScope = globalScope;
  3098. exports.info = info;
  3099. exports.isArray = isArray;
  3100. exports.isArrayBuffer = isArrayBuffer;
  3101. exports.isBool = isBool;
  3102. exports.isEmptyObj = isEmptyObj;
  3103. exports.isInt = isInt;
  3104. exports.isNum = isNum;
  3105. exports.isString = isString;
  3106. exports.isSpace = isSpace;
  3107. exports.isSameOrigin = isSameOrigin;
  3108. exports.isValidUrl = isValidUrl;
  3109. exports.isLittleEndian = isLittleEndian;
  3110. exports.isEvalSupported = isEvalSupported;
  3111. exports.loadJpegStream = loadJpegStream;
  3112. exports.log2 = log2;
  3113. exports.readInt8 = readInt8;
  3114. exports.readUint16 = readUint16;
  3115. exports.readUint32 = readUint32;
  3116. exports.removeNullCharacters = removeNullCharacters;
  3117. exports.setVerbosityLevel = setVerbosityLevel;
  3118. exports.shadow = shadow;
  3119. exports.string32 = string32;
  3120. exports.stringToBytes = stringToBytes;
  3121. exports.stringToPDFString = stringToPDFString;
  3122. exports.stringToUTF8String = stringToUTF8String;
  3123. exports.utf8StringToString = utf8StringToString;
  3124. exports.warn = warn;
  3125. }));
  3126. (function (root, factory) {
  3127. {
  3128. factory((root.pdfjsCoreCFFParser = {}), root.pdfjsSharedUtil,
  3129. root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  3130. }
  3131. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  3132. var error = sharedUtil.error;
  3133. var info = sharedUtil.info;
  3134. var bytesToString = sharedUtil.bytesToString;
  3135. var warn = sharedUtil.warn;
  3136. var isArray = sharedUtil.isArray;
  3137. var Util = sharedUtil.Util;
  3138. var stringToBytes = sharedUtil.stringToBytes;
  3139. var assert = sharedUtil.assert;
  3140. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  3141. var ExpertCharset = coreCharsets.ExpertCharset;
  3142. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  3143. var StandardEncoding = coreEncodings.StandardEncoding;
  3144. var ExpertEncoding = coreEncodings.ExpertEncoding;
  3145. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  3146. var MAX_SUBR_NESTING = 10;
  3147. /**
  3148. * The CFF class takes a Type1 file and wrap it into a
  3149. * 'Compact Font Format' which itself embed Type2 charstrings.
  3150. */
  3151. var CFFStandardStrings = [
  3152. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  3153. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  3154. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  3155. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  3156. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  3157. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  3158. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  3159. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  3160. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  3161. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  3162. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  3163. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  3164. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  3165. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  3166. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  3167. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  3168. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  3169. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  3170. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  3171. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  3172. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  3173. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  3174. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  3175. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  3176. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  3177. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  3178. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  3179. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  3180. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  3181. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  3182. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  3183. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  3184. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  3185. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  3186. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  3187. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  3188. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  3189. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  3190. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  3191. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  3192. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  3193. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  3194. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  3195. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  3196. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  3197. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  3198. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  3199. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  3200. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  3201. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  3202. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  3203. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  3204. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  3205. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  3206. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  3207. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  3208. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  3209. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  3210. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  3211. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  3212. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  3213. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  3214. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  3215. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  3216. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  3217. ];
  3218. var CFFParser = (function CFFParserClosure() {
  3219. var CharstringValidationData = [
  3220. null,
  3221. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  3222. null,
  3223. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  3224. { id: 'vmoveto', min: 1, stackClearing: true },
  3225. { id: 'rlineto', min: 2, resetStack: true },
  3226. { id: 'hlineto', min: 1, resetStack: true },
  3227. { id: 'vlineto', min: 1, resetStack: true },
  3228. { id: 'rrcurveto', min: 6, resetStack: true },
  3229. null,
  3230. { id: 'callsubr', min: 1, undefStack: true },
  3231. { id: 'return', min: 0, undefStack: true },
  3232. null, // 12
  3233. null,
  3234. { id: 'endchar', min: 0, stackClearing: true },
  3235. null,
  3236. null,
  3237. null,
  3238. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  3239. { id: 'hintmask', min: 0, stackClearing: true },
  3240. { id: 'cntrmask', min: 0, stackClearing: true },
  3241. { id: 'rmoveto', min: 2, stackClearing: true },
  3242. { id: 'hmoveto', min: 1, stackClearing: true },
  3243. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  3244. { id: 'rcurveline', min: 8, resetStack: true },
  3245. { id: 'rlinecurve', min: 8, resetStack: true },
  3246. { id: 'vvcurveto', min: 4, resetStack: true },
  3247. { id: 'hhcurveto', min: 4, resetStack: true },
  3248. null, // shortint
  3249. { id: 'callgsubr', min: 1, undefStack: true },
  3250. { id: 'vhcurveto', min: 4, resetStack: true },
  3251. { id: 'hvcurveto', min: 4, resetStack: true }
  3252. ];
  3253. var CharstringValidationData12 = [
  3254. null,
  3255. null,
  3256. null,
  3257. { id: 'and', min: 2, stackDelta: -1 },
  3258. { id: 'or', min: 2, stackDelta: -1 },
  3259. { id: 'not', min: 1, stackDelta: 0 },
  3260. null,
  3261. null,
  3262. null,
  3263. { id: 'abs', min: 1, stackDelta: 0 },
  3264. { id: 'add', min: 2, stackDelta: -1,
  3265. stackFn: function stack_div(stack, index) {
  3266. stack[index - 2] = stack[index - 2] + stack[index - 1];
  3267. }
  3268. },
  3269. { id: 'sub', min: 2, stackDelta: -1,
  3270. stackFn: function stack_div(stack, index) {
  3271. stack[index - 2] = stack[index - 2] - stack[index - 1];
  3272. }
  3273. },
  3274. { id: 'div', min: 2, stackDelta: -1,
  3275. stackFn: function stack_div(stack, index) {
  3276. stack[index - 2] = stack[index - 2] / stack[index - 1];
  3277. }
  3278. },
  3279. null,
  3280. { id: 'neg', min: 1, stackDelta: 0,
  3281. stackFn: function stack_div(stack, index) {
  3282. stack[index - 1] = -stack[index - 1];
  3283. }
  3284. },
  3285. { id: 'eq', min: 2, stackDelta: -1 },
  3286. null,
  3287. null,
  3288. { id: 'drop', min: 1, stackDelta: -1 },
  3289. null,
  3290. { id: 'put', min: 2, stackDelta: -2 },
  3291. { id: 'get', min: 1, stackDelta: 0 },
  3292. { id: 'ifelse', min: 4, stackDelta: -3 },
  3293. { id: 'random', min: 0, stackDelta: 1 },
  3294. { id: 'mul', min: 2, stackDelta: -1,
  3295. stackFn: function stack_div(stack, index) {
  3296. stack[index - 2] = stack[index - 2] * stack[index - 1];
  3297. }
  3298. },
  3299. null,
  3300. { id: 'sqrt', min: 1, stackDelta: 0 },
  3301. { id: 'dup', min: 1, stackDelta: 1 },
  3302. { id: 'exch', min: 2, stackDelta: 0 },
  3303. { id: 'index', min: 2, stackDelta: 0 },
  3304. { id: 'roll', min: 3, stackDelta: -2 },
  3305. null,
  3306. null,
  3307. null,
  3308. { id: 'hflex', min: 7, resetStack: true },
  3309. { id: 'flex', min: 13, resetStack: true },
  3310. { id: 'hflex1', min: 9, resetStack: true },
  3311. { id: 'flex1', min: 11, resetStack: true }
  3312. ];
  3313. function CFFParser(file, properties, seacAnalysisEnabled) {
  3314. this.bytes = file.getBytes();
  3315. this.properties = properties;
  3316. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  3317. }
  3318. CFFParser.prototype = {
  3319. parse: function CFFParser_parse() {
  3320. var properties = this.properties;
  3321. var cff = new CFF();
  3322. this.cff = cff;
  3323. // The first five sections must be in order, all the others are reached
  3324. // via offsets contained in one of the below.
  3325. var header = this.parseHeader();
  3326. var nameIndex = this.parseIndex(header.endPos);
  3327. var topDictIndex = this.parseIndex(nameIndex.endPos);
  3328. var stringIndex = this.parseIndex(topDictIndex.endPos);
  3329. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  3330. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  3331. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  3332. cff.header = header.obj;
  3333. cff.names = this.parseNameIndex(nameIndex.obj);
  3334. cff.strings = this.parseStringIndex(stringIndex.obj);
  3335. cff.topDict = topDict;
  3336. cff.globalSubrIndex = globalSubrIndex.obj;
  3337. this.parsePrivateDict(cff.topDict);
  3338. cff.isCIDFont = topDict.hasName('ROS');
  3339. var charStringOffset = topDict.getByName('CharStrings');
  3340. var charStringIndex = this.parseIndex(charStringOffset).obj;
  3341. var fontMatrix = topDict.getByName('FontMatrix');
  3342. if (fontMatrix) {
  3343. properties.fontMatrix = fontMatrix;
  3344. }
  3345. var fontBBox = topDict.getByName('FontBBox');
  3346. if (fontBBox) {
  3347. // adjusting ascent/descent
  3348. properties.ascent = fontBBox[3];
  3349. properties.descent = fontBBox[1];
  3350. properties.ascentScaled = true;
  3351. }
  3352. var charset, encoding;
  3353. if (cff.isCIDFont) {
  3354. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  3355. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  3356. var dictRaw = fdArrayIndex.get(i);
  3357. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  3358. cff.strings);
  3359. this.parsePrivateDict(fontDict);
  3360. cff.fdArray.push(fontDict);
  3361. }
  3362. // cid fonts don't have an encoding
  3363. encoding = null;
  3364. charset = this.parseCharsets(topDict.getByName('charset'),
  3365. charStringIndex.count, cff.strings, true);
  3366. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  3367. charStringIndex.count);
  3368. } else {
  3369. charset = this.parseCharsets(topDict.getByName('charset'),
  3370. charStringIndex.count, cff.strings, false);
  3371. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  3372. properties,
  3373. cff.strings, charset.charset);
  3374. }
  3375. cff.charset = charset;
  3376. cff.encoding = encoding;
  3377. var charStringsAndSeacs = this.parseCharStrings(
  3378. charStringIndex,
  3379. topDict.privateDict.subrsIndex,
  3380. globalSubrIndex.obj,
  3381. cff.fdSelect,
  3382. cff.fdArray);
  3383. cff.charStrings = charStringsAndSeacs.charStrings;
  3384. cff.seacs = charStringsAndSeacs.seacs;
  3385. cff.widths = charStringsAndSeacs.widths;
  3386. return cff;
  3387. },
  3388. parseHeader: function CFFParser_parseHeader() {
  3389. var bytes = this.bytes;
  3390. var bytesLength = bytes.length;
  3391. var offset = 0;
  3392. // Prevent an infinite loop, by checking that the offset is within the
  3393. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  3394. while (offset < bytesLength && bytes[offset] !== 1) {
  3395. ++offset;
  3396. }
  3397. if (offset >= bytesLength) {
  3398. error('Invalid CFF header');
  3399. } else if (offset !== 0) {
  3400. info('cff data is shifted');
  3401. bytes = bytes.subarray(offset);
  3402. this.bytes = bytes;
  3403. }
  3404. var major = bytes[0];
  3405. var minor = bytes[1];
  3406. var hdrSize = bytes[2];
  3407. var offSize = bytes[3];
  3408. var header = new CFFHeader(major, minor, hdrSize, offSize);
  3409. return { obj: header, endPos: hdrSize };
  3410. },
  3411. parseDict: function CFFParser_parseDict(dict) {
  3412. var pos = 0;
  3413. function parseOperand() {
  3414. var value = dict[pos++];
  3415. if (value === 30) {
  3416. return parseFloatOperand();
  3417. } else if (value === 28) {
  3418. value = dict[pos++];
  3419. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  3420. return value;
  3421. } else if (value === 29) {
  3422. value = dict[pos++];
  3423. value = (value << 8) | dict[pos++];
  3424. value = (value << 8) | dict[pos++];
  3425. value = (value << 8) | dict[pos++];
  3426. return value;
  3427. } else if (value >= 32 && value <= 246) {
  3428. return value - 139;
  3429. } else if (value >= 247 && value <= 250) {
  3430. return ((value - 247) * 256) + dict[pos++] + 108;
  3431. } else if (value >= 251 && value <= 254) {
  3432. return -((value - 251) * 256) - dict[pos++] - 108;
  3433. } else {
  3434. error('255 is not a valid DICT command');
  3435. }
  3436. return -1;
  3437. }
  3438. function parseFloatOperand() {
  3439. var str = '';
  3440. var eof = 15;
  3441. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  3442. '9', '.', 'E', 'E-', null, '-'];
  3443. var length = dict.length;
  3444. while (pos < length) {
  3445. var b = dict[pos++];
  3446. var b1 = b >> 4;
  3447. var b2 = b & 15;
  3448. if (b1 === eof) {
  3449. break;
  3450. }
  3451. str += lookup[b1];
  3452. if (b2 === eof) {
  3453. break;
  3454. }
  3455. str += lookup[b2];
  3456. }
  3457. return parseFloat(str);
  3458. }
  3459. var operands = [];
  3460. var entries = [];
  3461. pos = 0;
  3462. var end = dict.length;
  3463. while (pos < end) {
  3464. var b = dict[pos];
  3465. if (b <= 21) {
  3466. if (b === 12) {
  3467. b = (b << 8) | dict[++pos];
  3468. }
  3469. entries.push([b, operands]);
  3470. operands = [];
  3471. ++pos;
  3472. } else {
  3473. operands.push(parseOperand());
  3474. }
  3475. }
  3476. return entries;
  3477. },
  3478. parseIndex: function CFFParser_parseIndex(pos) {
  3479. var cffIndex = new CFFIndex();
  3480. var bytes = this.bytes;
  3481. var count = (bytes[pos++] << 8) | bytes[pos++];
  3482. var offsets = [];
  3483. var end = pos;
  3484. var i, ii;
  3485. if (count !== 0) {
  3486. var offsetSize = bytes[pos++];
  3487. // add 1 for offset to determine size of last object
  3488. var startPos = pos + ((count + 1) * offsetSize) - 1;
  3489. for (i = 0, ii = count + 1; i < ii; ++i) {
  3490. var offset = 0;
  3491. for (var j = 0; j < offsetSize; ++j) {
  3492. offset <<= 8;
  3493. offset += bytes[pos++];
  3494. }
  3495. offsets.push(startPos + offset);
  3496. }
  3497. end = offsets[count];
  3498. }
  3499. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  3500. var offsetStart = offsets[i];
  3501. var offsetEnd = offsets[i + 1];
  3502. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  3503. }
  3504. return {obj: cffIndex, endPos: end};
  3505. },
  3506. parseNameIndex: function CFFParser_parseNameIndex(index) {
  3507. var names = [];
  3508. for (var i = 0, ii = index.count; i < ii; ++i) {
  3509. var name = index.get(i);
  3510. // OTS doesn't allow names to be over 127 characters.
  3511. var length = Math.min(name.length, 127);
  3512. var data = [];
  3513. // OTS also only permits certain characters in the name.
  3514. for (var j = 0; j < length; ++j) {
  3515. var c = name[j];
  3516. if (j === 0 && c === 0) {
  3517. data[j] = c;
  3518. continue;
  3519. }
  3520. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  3521. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  3522. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  3523. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  3524. data[j] = 95;
  3525. continue;
  3526. }
  3527. data[j] = c;
  3528. }
  3529. names.push(bytesToString(data));
  3530. }
  3531. return names;
  3532. },
  3533. parseStringIndex: function CFFParser_parseStringIndex(index) {
  3534. var strings = new CFFStrings();
  3535. for (var i = 0, ii = index.count; i < ii; ++i) {
  3536. var data = index.get(i);
  3537. strings.add(bytesToString(data));
  3538. }
  3539. return strings;
  3540. },
  3541. createDict: function CFFParser_createDict(Type, dict, strings) {
  3542. var cffDict = new Type(strings);
  3543. for (var i = 0, ii = dict.length; i < ii; ++i) {
  3544. var pair = dict[i];
  3545. var key = pair[0];
  3546. var value = pair[1];
  3547. cffDict.setByKey(key, value);
  3548. }
  3549. return cffDict;
  3550. },
  3551. parseCharString: function CFFParser_parseCharString(state, data,
  3552. localSubrIndex,
  3553. globalSubrIndex) {
  3554. if (state.callDepth > MAX_SUBR_NESTING) {
  3555. return false;
  3556. }
  3557. var stackSize = state.stackSize;
  3558. var stack = state.stack;
  3559. var length = data.length;
  3560. for (var j = 0; j < length;) {
  3561. var value = data[j++];
  3562. var validationCommand = null;
  3563. if (value === 12) {
  3564. var q = data[j++];
  3565. if (q === 0) {
  3566. // The CFF specification state that the 'dotsection' command
  3567. // (12, 0) is deprecated and treated as a no-op, but all Type2
  3568. // charstrings processors should support them. Unfortunately
  3569. // the font sanitizer don't. As a workaround the sequence (12, 0)
  3570. // is replaced by a useless (0, hmoveto).
  3571. data[j - 2] = 139;
  3572. data[j - 1] = 22;
  3573. stackSize = 0;
  3574. } else {
  3575. validationCommand = CharstringValidationData12[q];
  3576. }
  3577. } else if (value === 28) { // number (16 bit)
  3578. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  3579. j += 2;
  3580. stackSize++;
  3581. } else if (value === 14) {
  3582. if (stackSize >= 4) {
  3583. stackSize -= 4;
  3584. if (this.seacAnalysisEnabled) {
  3585. state.seac = stack.slice(stackSize, stackSize + 4);
  3586. return false;
  3587. }
  3588. }
  3589. validationCommand = CharstringValidationData[value];
  3590. } else if (value >= 32 && value <= 246) { // number
  3591. stack[stackSize] = value - 139;
  3592. stackSize++;
  3593. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  3594. stack[stackSize] = (value < 251 ?
  3595. ((value - 247) << 8) + data[j] + 108 :
  3596. -((value - 251) << 8) - data[j] - 108);
  3597. j++;
  3598. stackSize++;
  3599. } else if (value === 255) { // number (32 bit)
  3600. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  3601. (data[j + 2] << 8) | data[j + 3]) / 65536;
  3602. j += 4;
  3603. stackSize++;
  3604. } else if (value === 19 || value === 20) {
  3605. state.hints += stackSize >> 1;
  3606. // skipping right amount of hints flag data
  3607. j += (state.hints + 7) >> 3;
  3608. stackSize %= 2;
  3609. validationCommand = CharstringValidationData[value];
  3610. } else if (value === 10 || value === 29) {
  3611. var subrsIndex;
  3612. if (value === 10) {
  3613. subrsIndex = localSubrIndex;
  3614. } else {
  3615. subrsIndex = globalSubrIndex;
  3616. }
  3617. if (!subrsIndex) {
  3618. validationCommand = CharstringValidationData[value];
  3619. warn('Missing subrsIndex for ' + validationCommand.id);
  3620. return false;
  3621. }
  3622. var bias = 32768;
  3623. if (subrsIndex.count < 1240) {
  3624. bias = 107;
  3625. } else if (subrsIndex.count < 33900) {
  3626. bias = 1131;
  3627. }
  3628. var subrNumber = stack[--stackSize] + bias;
  3629. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  3630. validationCommand = CharstringValidationData[value];
  3631. warn('Out of bounds subrIndex for ' + validationCommand.id);
  3632. return false;
  3633. }
  3634. state.stackSize = stackSize;
  3635. state.callDepth++;
  3636. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  3637. localSubrIndex, globalSubrIndex);
  3638. if (!valid) {
  3639. return false;
  3640. }
  3641. state.callDepth--;
  3642. stackSize = state.stackSize;
  3643. continue;
  3644. } else if (value === 11) {
  3645. state.stackSize = stackSize;
  3646. return true;
  3647. } else {
  3648. validationCommand = CharstringValidationData[value];
  3649. }
  3650. if (validationCommand) {
  3651. if (validationCommand.stem) {
  3652. state.hints += stackSize >> 1;
  3653. }
  3654. if ('min' in validationCommand) {
  3655. if (!state.undefStack && stackSize < validationCommand.min) {
  3656. warn('Not enough parameters for ' + validationCommand.id +
  3657. '; actual: ' + stackSize +
  3658. ', expected: ' + validationCommand.min);
  3659. return false;
  3660. }
  3661. }
  3662. if (state.firstStackClearing && validationCommand.stackClearing) {
  3663. state.firstStackClearing = false;
  3664. // the optional character width can be found before the first
  3665. // stack-clearing command arguments
  3666. stackSize -= validationCommand.min;
  3667. if (stackSize >= 2 && validationCommand.stem) {
  3668. // there are even amount of arguments for stem commands
  3669. stackSize %= 2;
  3670. } else if (stackSize > 1) {
  3671. warn('Found too many parameters for stack-clearing command');
  3672. }
  3673. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  3674. state.width = stack[stackSize - 1];
  3675. }
  3676. }
  3677. if ('stackDelta' in validationCommand) {
  3678. if ('stackFn' in validationCommand) {
  3679. validationCommand.stackFn(stack, stackSize);
  3680. }
  3681. stackSize += validationCommand.stackDelta;
  3682. } else if (validationCommand.stackClearing) {
  3683. stackSize = 0;
  3684. } else if (validationCommand.resetStack) {
  3685. stackSize = 0;
  3686. state.undefStack = false;
  3687. } else if (validationCommand.undefStack) {
  3688. stackSize = 0;
  3689. state.undefStack = true;
  3690. state.firstStackClearing = false;
  3691. }
  3692. }
  3693. }
  3694. state.stackSize = stackSize;
  3695. return true;
  3696. },
  3697. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  3698. localSubrIndex,
  3699. globalSubrIndex,
  3700. fdSelect,
  3701. fdArray) {
  3702. var seacs = [];
  3703. var widths = [];
  3704. var count = charStrings.count;
  3705. for (var i = 0; i < count; i++) {
  3706. var charstring = charStrings.get(i);
  3707. var state = {
  3708. callDepth: 0,
  3709. stackSize: 0,
  3710. stack: [],
  3711. undefStack: true,
  3712. hints: 0,
  3713. firstStackClearing: true,
  3714. seac: null,
  3715. width: null
  3716. };
  3717. var valid = true;
  3718. var localSubrToUse = null;
  3719. if (fdSelect && fdArray.length) {
  3720. var fdIndex = fdSelect.getFDIndex(i);
  3721. if (fdIndex === -1) {
  3722. warn('Glyph index is not in fd select.');
  3723. valid = false;
  3724. }
  3725. if (fdIndex >= fdArray.length) {
  3726. warn('Invalid fd index for glyph index.');
  3727. valid = false;
  3728. }
  3729. if (valid) {
  3730. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  3731. }
  3732. } else if (localSubrIndex) {
  3733. localSubrToUse = localSubrIndex;
  3734. }
  3735. if (valid) {
  3736. valid = this.parseCharString(state, charstring, localSubrToUse,
  3737. globalSubrIndex);
  3738. }
  3739. if (state.width !== null) {
  3740. widths[i] = state.width;
  3741. }
  3742. if (state.seac !== null) {
  3743. seacs[i] = state.seac;
  3744. }
  3745. if (!valid) {
  3746. // resetting invalid charstring to single 'endchar'
  3747. charStrings.set(i, new Uint8Array([14]));
  3748. }
  3749. }
  3750. return { charStrings: charStrings, seacs: seacs, widths: widths };
  3751. },
  3752. emptyPrivateDictionary:
  3753. function CFFParser_emptyPrivateDictionary(parentDict) {
  3754. var privateDict = this.createDict(CFFPrivateDict, [],
  3755. parentDict.strings);
  3756. parentDict.setByKey(18, [0, 0]);
  3757. parentDict.privateDict = privateDict;
  3758. },
  3759. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  3760. // no private dict, do nothing
  3761. if (!parentDict.hasName('Private')) {
  3762. this.emptyPrivateDictionary(parentDict);
  3763. return;
  3764. }
  3765. var privateOffset = parentDict.getByName('Private');
  3766. // make sure the params are formatted correctly
  3767. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  3768. parentDict.removeByName('Private');
  3769. return;
  3770. }
  3771. var size = privateOffset[0];
  3772. var offset = privateOffset[1];
  3773. // remove empty dicts or ones that refer to invalid location
  3774. if (size === 0 || offset >= this.bytes.length) {
  3775. this.emptyPrivateDictionary(parentDict);
  3776. return;
  3777. }
  3778. var privateDictEnd = offset + size;
  3779. var dictData = this.bytes.subarray(offset, privateDictEnd);
  3780. var dict = this.parseDict(dictData);
  3781. var privateDict = this.createDict(CFFPrivateDict, dict,
  3782. parentDict.strings);
  3783. parentDict.privateDict = privateDict;
  3784. // Parse the Subrs index also since it's relative to the private dict.
  3785. if (!privateDict.getByName('Subrs')) {
  3786. return;
  3787. }
  3788. var subrsOffset = privateDict.getByName('Subrs');
  3789. var relativeOffset = offset + subrsOffset;
  3790. // Validate the offset.
  3791. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  3792. this.emptyPrivateDictionary(parentDict);
  3793. return;
  3794. }
  3795. var subrsIndex = this.parseIndex(relativeOffset);
  3796. privateDict.subrsIndex = subrsIndex.obj;
  3797. },
  3798. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  3799. if (pos === 0) {
  3800. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  3801. ISOAdobeCharset);
  3802. } else if (pos === 1) {
  3803. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  3804. ExpertCharset);
  3805. } else if (pos === 2) {
  3806. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  3807. ExpertSubsetCharset);
  3808. }
  3809. var bytes = this.bytes;
  3810. var start = pos;
  3811. var format = bytes[pos++];
  3812. var charset = ['.notdef'];
  3813. var id, count, i;
  3814. // subtract 1 for the .notdef glyph
  3815. length -= 1;
  3816. switch (format) {
  3817. case 0:
  3818. for (i = 0; i < length; i++) {
  3819. id = (bytes[pos++] << 8) | bytes[pos++];
  3820. charset.push(cid ? id : strings.get(id));
  3821. }
  3822. break;
  3823. case 1:
  3824. while (charset.length <= length) {
  3825. id = (bytes[pos++] << 8) | bytes[pos++];
  3826. count = bytes[pos++];
  3827. for (i = 0; i <= count; i++) {
  3828. charset.push(cid ? id++ : strings.get(id++));
  3829. }
  3830. }
  3831. break;
  3832. case 2:
  3833. while (charset.length <= length) {
  3834. id = (bytes[pos++] << 8) | bytes[pos++];
  3835. count = (bytes[pos++] << 8) | bytes[pos++];
  3836. for (i = 0; i <= count; i++) {
  3837. charset.push(cid ? id++ : strings.get(id++));
  3838. }
  3839. }
  3840. break;
  3841. default:
  3842. error('Unknown charset format');
  3843. }
  3844. // Raw won't be needed if we actually compile the charset.
  3845. var end = pos;
  3846. var raw = bytes.subarray(start, end);
  3847. return new CFFCharset(false, format, charset, raw);
  3848. },
  3849. parseEncoding: function CFFParser_parseEncoding(pos,
  3850. properties,
  3851. strings,
  3852. charset) {
  3853. var encoding = Object.create(null);
  3854. var bytes = this.bytes;
  3855. var predefined = false;
  3856. var hasSupplement = false;
  3857. var format, i, ii;
  3858. var raw = null;
  3859. function readSupplement() {
  3860. var supplementsCount = bytes[pos++];
  3861. for (i = 0; i < supplementsCount; i++) {
  3862. var code = bytes[pos++];
  3863. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  3864. encoding[code] = charset.indexOf(strings.get(sid));
  3865. }
  3866. }
  3867. if (pos === 0 || pos === 1) {
  3868. predefined = true;
  3869. format = pos;
  3870. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  3871. for (i = 0, ii = charset.length; i < ii; i++) {
  3872. var index = baseEncoding.indexOf(charset[i]);
  3873. if (index !== -1) {
  3874. encoding[index] = i;
  3875. }
  3876. }
  3877. } else {
  3878. var dataStart = pos;
  3879. format = bytes[pos++];
  3880. switch (format & 0x7f) {
  3881. case 0:
  3882. var glyphsCount = bytes[pos++];
  3883. for (i = 1; i <= glyphsCount; i++) {
  3884. encoding[bytes[pos++]] = i;
  3885. }
  3886. break;
  3887. case 1:
  3888. var rangesCount = bytes[pos++];
  3889. var gid = 1;
  3890. for (i = 0; i < rangesCount; i++) {
  3891. var start = bytes[pos++];
  3892. var left = bytes[pos++];
  3893. for (var j = start; j <= start + left; j++) {
  3894. encoding[j] = gid++;
  3895. }
  3896. }
  3897. break;
  3898. default:
  3899. error('Unknown encoding format: ' + format + ' in CFF');
  3900. break;
  3901. }
  3902. var dataEnd = pos;
  3903. if (format & 0x80) {
  3904. // The font sanitizer does not support CFF encoding with a
  3905. // supplement, since the encoding is not really used to map
  3906. // between gid to glyph, let's overwrite what is declared in
  3907. // the top dictionary to let the sanitizer think the font use
  3908. // StandardEncoding, that's a lie but that's ok.
  3909. bytes[dataStart] &= 0x7f;
  3910. readSupplement();
  3911. hasSupplement = true;
  3912. }
  3913. raw = bytes.subarray(dataStart, dataEnd);
  3914. }
  3915. format = format & 0x7f;
  3916. return new CFFEncoding(predefined, format, encoding, raw);
  3917. },
  3918. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  3919. var start = pos;
  3920. var bytes = this.bytes;
  3921. var format = bytes[pos++];
  3922. var fdSelect = [], rawBytes;
  3923. var i, invalidFirstGID = false;
  3924. switch (format) {
  3925. case 0:
  3926. for (i = 0; i < length; ++i) {
  3927. var id = bytes[pos++];
  3928. fdSelect.push(id);
  3929. }
  3930. rawBytes = bytes.subarray(start, pos);
  3931. break;
  3932. case 3:
  3933. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  3934. for (i = 0; i < rangesCount; ++i) {
  3935. var first = (bytes[pos++] << 8) | bytes[pos++];
  3936. if (i === 0 && first !== 0) {
  3937. warn('parseFDSelect: The first range must have a first GID of 0' +
  3938. ' -- trying to recover.');
  3939. invalidFirstGID = true;
  3940. first = 0;
  3941. }
  3942. var fdIndex = bytes[pos++];
  3943. var next = (bytes[pos] << 8) | bytes[pos + 1];
  3944. for (var j = first; j < next; ++j) {
  3945. fdSelect.push(fdIndex);
  3946. }
  3947. }
  3948. // Advance past the sentinel(next).
  3949. pos += 2;
  3950. rawBytes = bytes.subarray(start, pos);
  3951. if (invalidFirstGID) {
  3952. rawBytes[3] = rawBytes[4] = 0; // Adjust the first range, first GID.
  3953. }
  3954. break;
  3955. default:
  3956. error('parseFDSelect: Unknown format "' + format + '".');
  3957. break;
  3958. }
  3959. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  3960. return new CFFFDSelect(fdSelect, rawBytes);
  3961. }
  3962. };
  3963. return CFFParser;
  3964. })();
  3965. // Compact Font Format
  3966. var CFF = (function CFFClosure() {
  3967. function CFF() {
  3968. this.header = null;
  3969. this.names = [];
  3970. this.topDict = null;
  3971. this.strings = new CFFStrings();
  3972. this.globalSubrIndex = null;
  3973. // The following could really be per font, but since we only have one font
  3974. // store them here.
  3975. this.encoding = null;
  3976. this.charset = null;
  3977. this.charStrings = null;
  3978. this.fdArray = [];
  3979. this.fdSelect = null;
  3980. this.isCIDFont = false;
  3981. }
  3982. return CFF;
  3983. })();
  3984. var CFFHeader = (function CFFHeaderClosure() {
  3985. function CFFHeader(major, minor, hdrSize, offSize) {
  3986. this.major = major;
  3987. this.minor = minor;
  3988. this.hdrSize = hdrSize;
  3989. this.offSize = offSize;
  3990. }
  3991. return CFFHeader;
  3992. })();
  3993. var CFFStrings = (function CFFStringsClosure() {
  3994. function CFFStrings() {
  3995. this.strings = [];
  3996. }
  3997. CFFStrings.prototype = {
  3998. get: function CFFStrings_get(index) {
  3999. if (index >= 0 && index <= 390) {
  4000. return CFFStandardStrings[index];
  4001. }
  4002. if (index - 391 <= this.strings.length) {
  4003. return this.strings[index - 391];
  4004. }
  4005. return CFFStandardStrings[0];
  4006. },
  4007. add: function CFFStrings_add(value) {
  4008. this.strings.push(value);
  4009. },
  4010. get count() {
  4011. return this.strings.length;
  4012. }
  4013. };
  4014. return CFFStrings;
  4015. })();
  4016. var CFFIndex = (function CFFIndexClosure() {
  4017. function CFFIndex() {
  4018. this.objects = [];
  4019. this.length = 0;
  4020. }
  4021. CFFIndex.prototype = {
  4022. add: function CFFIndex_add(data) {
  4023. this.length += data.length;
  4024. this.objects.push(data);
  4025. },
  4026. set: function CFFIndex_set(index, data) {
  4027. this.length += data.length - this.objects[index].length;
  4028. this.objects[index] = data;
  4029. },
  4030. get: function CFFIndex_get(index) {
  4031. return this.objects[index];
  4032. },
  4033. get count() {
  4034. return this.objects.length;
  4035. }
  4036. };
  4037. return CFFIndex;
  4038. })();
  4039. var CFFDict = (function CFFDictClosure() {
  4040. function CFFDict(tables, strings) {
  4041. this.keyToNameMap = tables.keyToNameMap;
  4042. this.nameToKeyMap = tables.nameToKeyMap;
  4043. this.defaults = tables.defaults;
  4044. this.types = tables.types;
  4045. this.opcodes = tables.opcodes;
  4046. this.order = tables.order;
  4047. this.strings = strings;
  4048. this.values = Object.create(null);
  4049. }
  4050. CFFDict.prototype = {
  4051. // value should always be an array
  4052. setByKey: function CFFDict_setByKey(key, value) {
  4053. if (!(key in this.keyToNameMap)) {
  4054. return false;
  4055. }
  4056. // ignore empty values
  4057. if (value.length === 0) {
  4058. return true;
  4059. }
  4060. var type = this.types[key];
  4061. // remove the array wrapping these types of values
  4062. if (type === 'num' || type === 'sid' || type === 'offset') {
  4063. value = value[0];
  4064. // Ignore invalid values (fixes bug 1068432).
  4065. if (isNaN(value)) {
  4066. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  4067. return true;
  4068. }
  4069. }
  4070. this.values[key] = value;
  4071. return true;
  4072. },
  4073. setByName: function CFFDict_setByName(name, value) {
  4074. if (!(name in this.nameToKeyMap)) {
  4075. error('Invalid dictionary name "' + name + '"');
  4076. }
  4077. this.values[this.nameToKeyMap[name]] = value;
  4078. },
  4079. hasName: function CFFDict_hasName(name) {
  4080. return this.nameToKeyMap[name] in this.values;
  4081. },
  4082. getByName: function CFFDict_getByName(name) {
  4083. if (!(name in this.nameToKeyMap)) {
  4084. error('Invalid dictionary name "' + name + '"');
  4085. }
  4086. var key = this.nameToKeyMap[name];
  4087. if (!(key in this.values)) {
  4088. return this.defaults[key];
  4089. }
  4090. return this.values[key];
  4091. },
  4092. removeByName: function CFFDict_removeByName(name) {
  4093. delete this.values[this.nameToKeyMap[name]];
  4094. }
  4095. };
  4096. CFFDict.createTables = function CFFDict_createTables(layout) {
  4097. var tables = {
  4098. keyToNameMap: {},
  4099. nameToKeyMap: {},
  4100. defaults: {},
  4101. types: {},
  4102. opcodes: {},
  4103. order: []
  4104. };
  4105. for (var i = 0, ii = layout.length; i < ii; ++i) {
  4106. var entry = layout[i];
  4107. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  4108. tables.keyToNameMap[key] = entry[1];
  4109. tables.nameToKeyMap[entry[1]] = key;
  4110. tables.types[key] = entry[2];
  4111. tables.defaults[key] = entry[3];
  4112. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  4113. tables.order.push(key);
  4114. }
  4115. return tables;
  4116. };
  4117. return CFFDict;
  4118. })();
  4119. var CFFTopDict = (function CFFTopDictClosure() {
  4120. var layout = [
  4121. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  4122. [[12, 20], 'SyntheticBase', 'num', null],
  4123. [0, 'version', 'sid', null],
  4124. [1, 'Notice', 'sid', null],
  4125. [[12, 0], 'Copyright', 'sid', null],
  4126. [2, 'FullName', 'sid', null],
  4127. [3, 'FamilyName', 'sid', null],
  4128. [4, 'Weight', 'sid', null],
  4129. [[12, 1], 'isFixedPitch', 'num', 0],
  4130. [[12, 2], 'ItalicAngle', 'num', 0],
  4131. [[12, 3], 'UnderlinePosition', 'num', -100],
  4132. [[12, 4], 'UnderlineThickness', 'num', 50],
  4133. [[12, 5], 'PaintType', 'num', 0],
  4134. [[12, 6], 'CharstringType', 'num', 2],
  4135. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  4136. [0.001, 0, 0, 0.001, 0, 0]],
  4137. [13, 'UniqueID', 'num', null],
  4138. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  4139. [[12, 8], 'StrokeWidth', 'num', 0],
  4140. [14, 'XUID', 'array', null],
  4141. [15, 'charset', 'offset', 0],
  4142. [16, 'Encoding', 'offset', 0],
  4143. [17, 'CharStrings', 'offset', 0],
  4144. [18, 'Private', ['offset', 'offset'], null],
  4145. [[12, 21], 'PostScript', 'sid', null],
  4146. [[12, 22], 'BaseFontName', 'sid', null],
  4147. [[12, 23], 'BaseFontBlend', 'delta', null],
  4148. [[12, 31], 'CIDFontVersion', 'num', 0],
  4149. [[12, 32], 'CIDFontRevision', 'num', 0],
  4150. [[12, 33], 'CIDFontType', 'num', 0],
  4151. [[12, 34], 'CIDCount', 'num', 8720],
  4152. [[12, 35], 'UIDBase', 'num', null],
  4153. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  4154. // before FDArray.
  4155. [[12, 37], 'FDSelect', 'offset', null],
  4156. [[12, 36], 'FDArray', 'offset', null],
  4157. [[12, 38], 'FontName', 'sid', null]
  4158. ];
  4159. var tables = null;
  4160. function CFFTopDict(strings) {
  4161. if (tables === null) {
  4162. tables = CFFDict.createTables(layout);
  4163. }
  4164. CFFDict.call(this, tables, strings);
  4165. this.privateDict = null;
  4166. }
  4167. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  4168. return CFFTopDict;
  4169. })();
  4170. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  4171. var layout = [
  4172. [6, 'BlueValues', 'delta', null],
  4173. [7, 'OtherBlues', 'delta', null],
  4174. [8, 'FamilyBlues', 'delta', null],
  4175. [9, 'FamilyOtherBlues', 'delta', null],
  4176. [[12, 9], 'BlueScale', 'num', 0.039625],
  4177. [[12, 10], 'BlueShift', 'num', 7],
  4178. [[12, 11], 'BlueFuzz', 'num', 1],
  4179. [10, 'StdHW', 'num', null],
  4180. [11, 'StdVW', 'num', null],
  4181. [[12, 12], 'StemSnapH', 'delta', null],
  4182. [[12, 13], 'StemSnapV', 'delta', null],
  4183. [[12, 14], 'ForceBold', 'num', 0],
  4184. [[12, 17], 'LanguageGroup', 'num', 0],
  4185. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  4186. [[12, 19], 'initialRandomSeed', 'num', 0],
  4187. [20, 'defaultWidthX', 'num', 0],
  4188. [21, 'nominalWidthX', 'num', 0],
  4189. [19, 'Subrs', 'offset', null]
  4190. ];
  4191. var tables = null;
  4192. function CFFPrivateDict(strings) {
  4193. if (tables === null) {
  4194. tables = CFFDict.createTables(layout);
  4195. }
  4196. CFFDict.call(this, tables, strings);
  4197. this.subrsIndex = null;
  4198. }
  4199. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  4200. return CFFPrivateDict;
  4201. })();
  4202. var CFFCharsetPredefinedTypes = {
  4203. ISO_ADOBE: 0,
  4204. EXPERT: 1,
  4205. EXPERT_SUBSET: 2
  4206. };
  4207. var CFFCharset = (function CFFCharsetClosure() {
  4208. function CFFCharset(predefined, format, charset, raw) {
  4209. this.predefined = predefined;
  4210. this.format = format;
  4211. this.charset = charset;
  4212. this.raw = raw;
  4213. }
  4214. return CFFCharset;
  4215. })();
  4216. var CFFEncoding = (function CFFEncodingClosure() {
  4217. function CFFEncoding(predefined, format, encoding, raw) {
  4218. this.predefined = predefined;
  4219. this.format = format;
  4220. this.encoding = encoding;
  4221. this.raw = raw;
  4222. }
  4223. return CFFEncoding;
  4224. })();
  4225. var CFFFDSelect = (function CFFFDSelectClosure() {
  4226. function CFFFDSelect(fdSelect, raw) {
  4227. this.fdSelect = fdSelect;
  4228. this.raw = raw;
  4229. }
  4230. CFFFDSelect.prototype = {
  4231. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  4232. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  4233. return -1;
  4234. }
  4235. return this.fdSelect[glyphIndex];
  4236. }
  4237. };
  4238. return CFFFDSelect;
  4239. })();
  4240. // Helper class to keep track of where an offset is within the data and helps
  4241. // filling in that offset once it's known.
  4242. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  4243. function CFFOffsetTracker() {
  4244. this.offsets = Object.create(null);
  4245. }
  4246. CFFOffsetTracker.prototype = {
  4247. isTracking: function CFFOffsetTracker_isTracking(key) {
  4248. return key in this.offsets;
  4249. },
  4250. track: function CFFOffsetTracker_track(key, location) {
  4251. if (key in this.offsets) {
  4252. error('Already tracking location of ' + key);
  4253. }
  4254. this.offsets[key] = location;
  4255. },
  4256. offset: function CFFOffsetTracker_offset(value) {
  4257. for (var key in this.offsets) {
  4258. this.offsets[key] += value;
  4259. }
  4260. },
  4261. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  4262. values,
  4263. output) {
  4264. if (!(key in this.offsets)) {
  4265. error('Not tracking location of ' + key);
  4266. }
  4267. var data = output.data;
  4268. var dataOffset = this.offsets[key];
  4269. var size = 5;
  4270. for (var i = 0, ii = values.length; i < ii; ++i) {
  4271. var offset0 = i * size + dataOffset;
  4272. var offset1 = offset0 + 1;
  4273. var offset2 = offset0 + 2;
  4274. var offset3 = offset0 + 3;
  4275. var offset4 = offset0 + 4;
  4276. // It's easy to screw up offsets so perform this sanity check.
  4277. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  4278. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  4279. error('writing to an offset that is not empty');
  4280. }
  4281. var value = values[i];
  4282. data[offset0] = 0x1d;
  4283. data[offset1] = (value >> 24) & 0xFF;
  4284. data[offset2] = (value >> 16) & 0xFF;
  4285. data[offset3] = (value >> 8) & 0xFF;
  4286. data[offset4] = value & 0xFF;
  4287. }
  4288. }
  4289. };
  4290. return CFFOffsetTracker;
  4291. })();
  4292. // Takes a CFF and converts it to the binary representation.
  4293. var CFFCompiler = (function CFFCompilerClosure() {
  4294. function CFFCompiler(cff) {
  4295. this.cff = cff;
  4296. }
  4297. CFFCompiler.prototype = {
  4298. compile: function CFFCompiler_compile() {
  4299. var cff = this.cff;
  4300. var output = {
  4301. data: [],
  4302. length: 0,
  4303. add: function CFFCompiler_add(data) {
  4304. this.data = this.data.concat(data);
  4305. this.length = this.data.length;
  4306. }
  4307. };
  4308. // Compile the five entries that must be in order.
  4309. var header = this.compileHeader(cff.header);
  4310. output.add(header);
  4311. var nameIndex = this.compileNameIndex(cff.names);
  4312. output.add(nameIndex);
  4313. if (cff.isCIDFont) {
  4314. // The spec is unclear on how font matrices should relate to each other
  4315. // when there is one in the main top dict and the sub top dicts.
  4316. // Windows handles this differently than linux and osx so we have to
  4317. // normalize to work on all.
  4318. // Rules based off of some mailing list discussions:
  4319. // - If main font has a matrix and subfont doesn't, use the main matrix.
  4320. // - If no main font matrix and there is a subfont matrix, use the
  4321. // subfont matrix.
  4322. // - If both have matrices, concat together.
  4323. // - If neither have matrices, use default.
  4324. // To make this work on all platforms we move the top matrix into each
  4325. // sub top dict and concat if necessary.
  4326. if (cff.topDict.hasName('FontMatrix')) {
  4327. var base = cff.topDict.getByName('FontMatrix');
  4328. cff.topDict.removeByName('FontMatrix');
  4329. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  4330. var subDict = cff.fdArray[i];
  4331. var matrix = base.slice(0);
  4332. if (subDict.hasName('FontMatrix')) {
  4333. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  4334. }
  4335. subDict.setByName('FontMatrix', matrix);
  4336. }
  4337. }
  4338. }
  4339. var compiled = this.compileTopDicts([cff.topDict],
  4340. output.length,
  4341. cff.isCIDFont);
  4342. output.add(compiled.output);
  4343. var topDictTracker = compiled.trackers[0];
  4344. var stringIndex = this.compileStringIndex(cff.strings.strings);
  4345. output.add(stringIndex);
  4346. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  4347. output.add(globalSubrIndex);
  4348. // Now start on the other entries that have no specific order.
  4349. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  4350. if (cff.encoding.predefined) {
  4351. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  4352. output);
  4353. } else {
  4354. var encoding = this.compileEncoding(cff.encoding);
  4355. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  4356. output.add(encoding);
  4357. }
  4358. }
  4359. if (cff.charset && cff.topDict.hasName('charset')) {
  4360. if (cff.charset.predefined) {
  4361. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  4362. output);
  4363. } else {
  4364. var charset = this.compileCharset(cff.charset);
  4365. topDictTracker.setEntryLocation('charset', [output.length], output);
  4366. output.add(charset);
  4367. }
  4368. }
  4369. var charStrings = this.compileCharStrings(cff.charStrings);
  4370. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  4371. output.add(charStrings);
  4372. if (cff.isCIDFont) {
  4373. // For some reason FDSelect must be in front of FDArray on windows. OSX
  4374. // and linux don't seem to care.
  4375. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  4376. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  4377. output.add(fdSelect);
  4378. // It is unclear if the sub font dictionary can have CID related
  4379. // dictionary keys, but the sanitizer doesn't like them so remove them.
  4380. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  4381. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  4382. output.add(compiled.output);
  4383. var fontDictTrackers = compiled.trackers;
  4384. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  4385. }
  4386. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  4387. // If the font data ends with INDEX whose object data is zero-length,
  4388. // the sanitizer will bail out. Add a dummy byte to avoid that.
  4389. output.add([0]);
  4390. return output.data;
  4391. },
  4392. encodeNumber: function CFFCompiler_encodeNumber(value) {
  4393. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  4394. return this.encodeInteger(value);
  4395. } else {
  4396. return this.encodeFloat(value);
  4397. }
  4398. },
  4399. encodeFloat: function CFFCompiler_encodeFloat(num) {
  4400. var value = num.toString();
  4401. // rounding inaccurate doubles
  4402. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  4403. if (m) {
  4404. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  4405. value = (Math.round(num * epsilon) / epsilon).toString();
  4406. }
  4407. var nibbles = '';
  4408. var i, ii;
  4409. for (i = 0, ii = value.length; i < ii; ++i) {
  4410. var a = value[i];
  4411. if (a === 'e') {
  4412. nibbles += value[++i] === '-' ? 'c' : 'b';
  4413. } else if (a === '.') {
  4414. nibbles += 'a';
  4415. } else if (a === '-') {
  4416. nibbles += 'e';
  4417. } else {
  4418. nibbles += a;
  4419. }
  4420. }
  4421. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  4422. var out = [30];
  4423. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  4424. out.push(parseInt(nibbles.substr(i, 2), 16));
  4425. }
  4426. return out;
  4427. },
  4428. encodeInteger: function CFFCompiler_encodeInteger(value) {
  4429. var code;
  4430. if (value >= -107 && value <= 107) {
  4431. code = [value + 139];
  4432. } else if (value >= 108 && value <= 1131) {
  4433. value = value - 108;
  4434. code = [(value >> 8) + 247, value & 0xFF];
  4435. } else if (value >= -1131 && value <= -108) {
  4436. value = -value - 108;
  4437. code = [(value >> 8) + 251, value & 0xFF];
  4438. } else if (value >= -32768 && value <= 32767) {
  4439. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  4440. } else {
  4441. code = [0x1d,
  4442. (value >> 24) & 0xFF,
  4443. (value >> 16) & 0xFF,
  4444. (value >> 8) & 0xFF,
  4445. value & 0xFF];
  4446. }
  4447. return code;
  4448. },
  4449. compileHeader: function CFFCompiler_compileHeader(header) {
  4450. return [
  4451. header.major,
  4452. header.minor,
  4453. header.hdrSize,
  4454. header.offSize
  4455. ];
  4456. },
  4457. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  4458. var nameIndex = new CFFIndex();
  4459. for (var i = 0, ii = names.length; i < ii; ++i) {
  4460. nameIndex.add(stringToBytes(names[i]));
  4461. }
  4462. return this.compileIndex(nameIndex);
  4463. },
  4464. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  4465. length,
  4466. removeCidKeys) {
  4467. var fontDictTrackers = [];
  4468. var fdArrayIndex = new CFFIndex();
  4469. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  4470. var fontDict = dicts[i];
  4471. if (removeCidKeys) {
  4472. fontDict.removeByName('CIDFontVersion');
  4473. fontDict.removeByName('CIDFontRevision');
  4474. fontDict.removeByName('CIDFontType');
  4475. fontDict.removeByName('CIDCount');
  4476. fontDict.removeByName('UIDBase');
  4477. }
  4478. var fontDictTracker = new CFFOffsetTracker();
  4479. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  4480. fontDictTrackers.push(fontDictTracker);
  4481. fdArrayIndex.add(fontDictData);
  4482. fontDictTracker.offset(length);
  4483. }
  4484. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  4485. return {
  4486. trackers: fontDictTrackers,
  4487. output: fdArrayIndex
  4488. };
  4489. },
  4490. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  4491. trackers,
  4492. output) {
  4493. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  4494. var fontDict = dicts[i];
  4495. assert(fontDict.privateDict && fontDict.hasName('Private'),
  4496. 'There must be an private dictionary.');
  4497. var privateDict = fontDict.privateDict;
  4498. var privateDictTracker = new CFFOffsetTracker();
  4499. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  4500. var outputLength = output.length;
  4501. privateDictTracker.offset(outputLength);
  4502. if (!privateDictData.length) {
  4503. // The private dictionary was empty, set the output length to zero to
  4504. // ensure the offset length isn't out of bounds in the eyes of the
  4505. // sanitizer.
  4506. outputLength = 0;
  4507. }
  4508. trackers[i].setEntryLocation('Private',
  4509. [privateDictData.length, outputLength],
  4510. output);
  4511. output.add(privateDictData);
  4512. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  4513. var subrs = this.compileIndex(privateDict.subrsIndex);
  4514. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  4515. output);
  4516. output.add(subrs);
  4517. }
  4518. }
  4519. },
  4520. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  4521. var out = [];
  4522. // The dictionary keys must be in a certain order.
  4523. var order = dict.order;
  4524. for (var i = 0; i < order.length; ++i) {
  4525. var key = order[i];
  4526. if (!(key in dict.values)) {
  4527. continue;
  4528. }
  4529. var values = dict.values[key];
  4530. var types = dict.types[key];
  4531. if (!isArray(types)) {
  4532. types = [types];
  4533. }
  4534. if (!isArray(values)) {
  4535. values = [values];
  4536. }
  4537. // Remove any empty dict values.
  4538. if (values.length === 0) {
  4539. continue;
  4540. }
  4541. for (var j = 0, jj = types.length; j < jj; ++j) {
  4542. var type = types[j];
  4543. var value = values[j];
  4544. switch (type) {
  4545. case 'num':
  4546. case 'sid':
  4547. out = out.concat(this.encodeNumber(value));
  4548. break;
  4549. case 'offset':
  4550. // For offsets we just insert a 32bit integer so we don't have to
  4551. // deal with figuring out the length of the offset when it gets
  4552. // replaced later on by the compiler.
  4553. var name = dict.keyToNameMap[key];
  4554. // Some offsets have the offset and the length, so just record the
  4555. // position of the first one.
  4556. if (!offsetTracker.isTracking(name)) {
  4557. offsetTracker.track(name, out.length);
  4558. }
  4559. out = out.concat([0x1d, 0, 0, 0, 0]);
  4560. break;
  4561. case 'array':
  4562. case 'delta':
  4563. out = out.concat(this.encodeNumber(value));
  4564. for (var k = 1, kk = values.length; k < kk; ++k) {
  4565. out = out.concat(this.encodeNumber(values[k]));
  4566. }
  4567. break;
  4568. default:
  4569. error('Unknown data type of ' + type);
  4570. break;
  4571. }
  4572. }
  4573. out = out.concat(dict.opcodes[key]);
  4574. }
  4575. return out;
  4576. },
  4577. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  4578. var stringIndex = new CFFIndex();
  4579. for (var i = 0, ii = strings.length; i < ii; ++i) {
  4580. stringIndex.add(stringToBytes(strings[i]));
  4581. }
  4582. return this.compileIndex(stringIndex);
  4583. },
  4584. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  4585. var globalSubrIndex = this.cff.globalSubrIndex;
  4586. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  4587. },
  4588. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  4589. return this.compileIndex(charStrings);
  4590. },
  4591. compileCharset: function CFFCompiler_compileCharset(charset) {
  4592. return this.compileTypedArray(charset.raw);
  4593. },
  4594. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  4595. return this.compileTypedArray(encoding.raw);
  4596. },
  4597. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  4598. return this.compileTypedArray(fdSelect);
  4599. },
  4600. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  4601. var out = [];
  4602. for (var i = 0, ii = data.length; i < ii; ++i) {
  4603. out[i] = data[i];
  4604. }
  4605. return out;
  4606. },
  4607. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  4608. trackers = trackers || [];
  4609. var objects = index.objects;
  4610. // First 2 bytes contains the number of objects contained into this index
  4611. var count = objects.length;
  4612. // If there is no object, just create an index. This technically
  4613. // should just be [0, 0] but OTS has an issue with that.
  4614. if (count === 0) {
  4615. return [0, 0, 0];
  4616. }
  4617. var data = [(count >> 8) & 0xFF, count & 0xff];
  4618. var lastOffset = 1, i;
  4619. for (i = 0; i < count; ++i) {
  4620. lastOffset += objects[i].length;
  4621. }
  4622. var offsetSize;
  4623. if (lastOffset < 0x100) {
  4624. offsetSize = 1;
  4625. } else if (lastOffset < 0x10000) {
  4626. offsetSize = 2;
  4627. } else if (lastOffset < 0x1000000) {
  4628. offsetSize = 3;
  4629. } else {
  4630. offsetSize = 4;
  4631. }
  4632. // Next byte contains the offset size use to reference object in the file
  4633. data.push(offsetSize);
  4634. // Add another offset after this one because we need a new offset
  4635. var relativeOffset = 1;
  4636. for (i = 0; i < count + 1; i++) {
  4637. if (offsetSize === 1) {
  4638. data.push(relativeOffset & 0xFF);
  4639. } else if (offsetSize === 2) {
  4640. data.push((relativeOffset >> 8) & 0xFF,
  4641. relativeOffset & 0xFF);
  4642. } else if (offsetSize === 3) {
  4643. data.push((relativeOffset >> 16) & 0xFF,
  4644. (relativeOffset >> 8) & 0xFF,
  4645. relativeOffset & 0xFF);
  4646. } else {
  4647. data.push((relativeOffset >>> 24) & 0xFF,
  4648. (relativeOffset >> 16) & 0xFF,
  4649. (relativeOffset >> 8) & 0xFF,
  4650. relativeOffset & 0xFF);
  4651. }
  4652. if (objects[i]) {
  4653. relativeOffset += objects[i].length;
  4654. }
  4655. }
  4656. for (i = 0; i < count; i++) {
  4657. // Notify the tracker where the object will be offset in the data.
  4658. if (trackers[i]) {
  4659. trackers[i].offset(data.length);
  4660. }
  4661. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  4662. data.push(objects[i][j]);
  4663. }
  4664. }
  4665. return data;
  4666. }
  4667. };
  4668. return CFFCompiler;
  4669. })();
  4670. exports.CFFStandardStrings = CFFStandardStrings;
  4671. exports.CFFParser = CFFParser;
  4672. exports.CFF = CFF;
  4673. exports.CFFHeader = CFFHeader;
  4674. exports.CFFStrings = CFFStrings;
  4675. exports.CFFIndex = CFFIndex;
  4676. exports.CFFCharset = CFFCharset;
  4677. exports.CFFTopDict = CFFTopDict;
  4678. exports.CFFPrivateDict = CFFPrivateDict;
  4679. exports.CFFCompiler = CFFCompiler;
  4680. }));
  4681. (function (root, factory) {
  4682. {
  4683. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4684. }
  4685. }(this, function (exports, sharedUtil) {
  4686. var MissingDataException = sharedUtil.MissingDataException;
  4687. var arrayByteLength = sharedUtil.arrayByteLength;
  4688. var arraysToBytes = sharedUtil.arraysToBytes;
  4689. var assert = sharedUtil.assert;
  4690. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4691. var isInt = sharedUtil.isInt;
  4692. var isEmptyObj = sharedUtil.isEmptyObj;
  4693. var ChunkedStream = (function ChunkedStreamClosure() {
  4694. function ChunkedStream(length, chunkSize, manager) {
  4695. this.bytes = new Uint8Array(length);
  4696. this.start = 0;
  4697. this.pos = 0;
  4698. this.end = length;
  4699. this.chunkSize = chunkSize;
  4700. this.loadedChunks = [];
  4701. this.numChunksLoaded = 0;
  4702. this.numChunks = Math.ceil(length / chunkSize);
  4703. this.manager = manager;
  4704. this.progressiveDataLength = 0;
  4705. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4706. }
  4707. // required methods for a stream. if a particular stream does not
  4708. // implement these, an error should be thrown
  4709. ChunkedStream.prototype = {
  4710. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4711. var chunks = [];
  4712. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4713. if (!this.loadedChunks[chunk]) {
  4714. chunks.push(chunk);
  4715. }
  4716. }
  4717. return chunks;
  4718. },
  4719. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4720. return [this];
  4721. },
  4722. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4723. return this.numChunksLoaded === this.numChunks;
  4724. },
  4725. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4726. var end = begin + chunk.byteLength;
  4727. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4728. // Using this.length is inaccurate here since this.start can be moved
  4729. // See ChunkedStream.moveStart()
  4730. var length = this.bytes.length;
  4731. assert(end % this.chunkSize === 0 || end === length,
  4732. 'Bad end offset: ' + end);
  4733. this.bytes.set(new Uint8Array(chunk), begin);
  4734. var chunkSize = this.chunkSize;
  4735. var beginChunk = Math.floor(begin / chunkSize);
  4736. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4737. var curChunk;
  4738. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4739. if (!this.loadedChunks[curChunk]) {
  4740. this.loadedChunks[curChunk] = true;
  4741. ++this.numChunksLoaded;
  4742. }
  4743. }
  4744. },
  4745. onReceiveProgressiveData:
  4746. function ChunkedStream_onReceiveProgressiveData(data) {
  4747. var position = this.progressiveDataLength;
  4748. var beginChunk = Math.floor(position / this.chunkSize);
  4749. this.bytes.set(new Uint8Array(data), position);
  4750. position += data.byteLength;
  4751. this.progressiveDataLength = position;
  4752. var endChunk = position >= this.end ? this.numChunks :
  4753. Math.floor(position / this.chunkSize);
  4754. var curChunk;
  4755. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4756. if (!this.loadedChunks[curChunk]) {
  4757. this.loadedChunks[curChunk] = true;
  4758. ++this.numChunksLoaded;
  4759. }
  4760. }
  4761. },
  4762. ensureByte: function ChunkedStream_ensureByte(pos) {
  4763. var chunk = Math.floor(pos / this.chunkSize);
  4764. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4765. return;
  4766. }
  4767. if (!this.loadedChunks[chunk]) {
  4768. throw new MissingDataException(pos, pos + 1);
  4769. }
  4770. this.lastSuccessfulEnsureByteChunk = chunk;
  4771. },
  4772. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4773. if (begin >= end) {
  4774. return;
  4775. }
  4776. if (end <= this.progressiveDataLength) {
  4777. return;
  4778. }
  4779. var chunkSize = this.chunkSize;
  4780. var beginChunk = Math.floor(begin / chunkSize);
  4781. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4782. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4783. if (!this.loadedChunks[chunk]) {
  4784. throw new MissingDataException(begin, end);
  4785. }
  4786. }
  4787. },
  4788. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4789. var chunk, numChunks = this.numChunks;
  4790. for (var i = 0; i < numChunks; ++i) {
  4791. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4792. if (!this.loadedChunks[chunk]) {
  4793. return chunk;
  4794. }
  4795. }
  4796. return null;
  4797. },
  4798. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4799. return !!this.loadedChunks[chunk];
  4800. },
  4801. get length() {
  4802. return this.end - this.start;
  4803. },
  4804. get isEmpty() {
  4805. return this.length === 0;
  4806. },
  4807. getByte: function ChunkedStream_getByte() {
  4808. var pos = this.pos;
  4809. if (pos >= this.end) {
  4810. return -1;
  4811. }
  4812. this.ensureByte(pos);
  4813. return this.bytes[this.pos++];
  4814. },
  4815. getUint16: function ChunkedStream_getUint16() {
  4816. var b0 = this.getByte();
  4817. var b1 = this.getByte();
  4818. if (b0 === -1 || b1 === -1) {
  4819. return -1;
  4820. }
  4821. return (b0 << 8) + b1;
  4822. },
  4823. getInt32: function ChunkedStream_getInt32() {
  4824. var b0 = this.getByte();
  4825. var b1 = this.getByte();
  4826. var b2 = this.getByte();
  4827. var b3 = this.getByte();
  4828. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4829. },
  4830. // returns subarray of original buffer
  4831. // should only be read
  4832. getBytes: function ChunkedStream_getBytes(length) {
  4833. var bytes = this.bytes;
  4834. var pos = this.pos;
  4835. var strEnd = this.end;
  4836. if (!length) {
  4837. this.ensureRange(pos, strEnd);
  4838. return bytes.subarray(pos, strEnd);
  4839. }
  4840. var end = pos + length;
  4841. if (end > strEnd) {
  4842. end = strEnd;
  4843. }
  4844. this.ensureRange(pos, end);
  4845. this.pos = end;
  4846. return bytes.subarray(pos, end);
  4847. },
  4848. peekByte: function ChunkedStream_peekByte() {
  4849. var peekedByte = this.getByte();
  4850. this.pos--;
  4851. return peekedByte;
  4852. },
  4853. peekBytes: function ChunkedStream_peekBytes(length) {
  4854. var bytes = this.getBytes(length);
  4855. this.pos -= bytes.length;
  4856. return bytes;
  4857. },
  4858. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4859. this.ensureRange(begin, end);
  4860. return this.bytes.subarray(begin, end);
  4861. },
  4862. skip: function ChunkedStream_skip(n) {
  4863. if (!n) {
  4864. n = 1;
  4865. }
  4866. this.pos += n;
  4867. },
  4868. reset: function ChunkedStream_reset() {
  4869. this.pos = this.start;
  4870. },
  4871. moveStart: function ChunkedStream_moveStart() {
  4872. this.start = this.pos;
  4873. },
  4874. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4875. this.ensureRange(start, start + length);
  4876. function ChunkedStreamSubstream() {}
  4877. ChunkedStreamSubstream.prototype = Object.create(this);
  4878. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4879. var chunkSize = this.chunkSize;
  4880. var beginChunk = Math.floor(this.start / chunkSize);
  4881. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4882. var missingChunks = [];
  4883. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4884. if (!this.loadedChunks[chunk]) {
  4885. missingChunks.push(chunk);
  4886. }
  4887. }
  4888. return missingChunks;
  4889. };
  4890. var subStream = new ChunkedStreamSubstream();
  4891. subStream.pos = subStream.start = start;
  4892. subStream.end = start + length || this.end;
  4893. subStream.dict = dict;
  4894. return subStream;
  4895. },
  4896. isStream: true
  4897. };
  4898. return ChunkedStream;
  4899. })();
  4900. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4901. function ChunkedStreamManager(pdfNetworkStream, args) {
  4902. var chunkSize = args.rangeChunkSize;
  4903. var length = args.length;
  4904. this.stream = new ChunkedStream(length, chunkSize, this);
  4905. this.length = length;
  4906. this.chunkSize = chunkSize;
  4907. this.pdfNetworkStream = pdfNetworkStream;
  4908. this.url = args.url;
  4909. this.disableAutoFetch = args.disableAutoFetch;
  4910. this.msgHandler = args.msgHandler;
  4911. this.currRequestId = 0;
  4912. this.chunksNeededByRequest = Object.create(null);
  4913. this.requestsByChunk = Object.create(null);
  4914. this.promisesByRequest = Object.create(null);
  4915. this.progressiveDataLength = 0;
  4916. this.aborted = false;
  4917. this._loadedStreamCapability = createPromiseCapability();
  4918. }
  4919. ChunkedStreamManager.prototype = {
  4920. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4921. return this._loadedStreamCapability.promise;
  4922. },
  4923. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  4924. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  4925. if (!rangeReader.isStreamingSupported) {
  4926. rangeReader.onProgress = this.onProgress.bind(this);
  4927. }
  4928. var chunks = [], loaded = 0;
  4929. var manager = this;
  4930. var promise = new Promise(function (resolve, reject) {
  4931. var readChunk = function (chunk) {
  4932. try {
  4933. if (!chunk.done) {
  4934. var data = chunk.value;
  4935. chunks.push(data);
  4936. loaded += arrayByteLength(data);
  4937. if (rangeReader.isStreamingSupported) {
  4938. manager.onProgress({loaded: loaded});
  4939. }
  4940. rangeReader.read().then(readChunk, reject);
  4941. return;
  4942. }
  4943. var chunkData = arraysToBytes(chunks);
  4944. chunks = null;
  4945. resolve(chunkData);
  4946. } catch (e) {
  4947. reject(e);
  4948. }
  4949. };
  4950. rangeReader.read().then(readChunk, reject);
  4951. });
  4952. promise.then(function (data) {
  4953. if (this.aborted) {
  4954. return; // ignoring any data after abort
  4955. }
  4956. this.onReceiveData({chunk: data, begin: begin});
  4957. }.bind(this));
  4958. // TODO check errors
  4959. },
  4960. // Get all the chunks that are not yet loaded and groups them into
  4961. // contiguous ranges to load in as few requests as possible
  4962. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4963. var missingChunks = this.stream.getMissingChunks();
  4964. this._requestChunks(missingChunks);
  4965. return this._loadedStreamCapability.promise;
  4966. },
  4967. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4968. var requestId = this.currRequestId++;
  4969. var i, ii;
  4970. var chunksNeeded = Object.create(null);
  4971. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4972. for (i = 0, ii = chunks.length; i < ii; i++) {
  4973. if (!this.stream.hasChunk(chunks[i])) {
  4974. chunksNeeded[chunks[i]] = true;
  4975. }
  4976. }
  4977. if (isEmptyObj(chunksNeeded)) {
  4978. return Promise.resolve();
  4979. }
  4980. var capability = createPromiseCapability();
  4981. this.promisesByRequest[requestId] = capability;
  4982. var chunksToRequest = [];
  4983. for (var chunk in chunksNeeded) {
  4984. chunk = chunk | 0;
  4985. if (!(chunk in this.requestsByChunk)) {
  4986. this.requestsByChunk[chunk] = [];
  4987. chunksToRequest.push(chunk);
  4988. }
  4989. this.requestsByChunk[chunk].push(requestId);
  4990. }
  4991. if (!chunksToRequest.length) {
  4992. return capability.promise;
  4993. }
  4994. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  4995. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  4996. var groupedChunk = groupedChunksToRequest[i];
  4997. var begin = groupedChunk.beginChunk * this.chunkSize;
  4998. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  4999. this.sendRequest(begin, end);
  5000. }
  5001. return capability.promise;
  5002. },
  5003. getStream: function ChunkedStreamManager_getStream() {
  5004. return this.stream;
  5005. },
  5006. // Loads any chunks in the requested range that are not yet loaded
  5007. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  5008. end = Math.min(end, this.length);
  5009. var beginChunk = this.getBeginChunk(begin);
  5010. var endChunk = this.getEndChunk(end);
  5011. var chunks = [];
  5012. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5013. chunks.push(chunk);
  5014. }
  5015. return this._requestChunks(chunks);
  5016. },
  5017. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  5018. ranges = ranges || [];
  5019. var chunksToRequest = [];
  5020. for (var i = 0; i < ranges.length; i++) {
  5021. var beginChunk = this.getBeginChunk(ranges[i].begin);
  5022. var endChunk = this.getEndChunk(ranges[i].end);
  5023. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5024. if (chunksToRequest.indexOf(chunk) < 0) {
  5025. chunksToRequest.push(chunk);
  5026. }
  5027. }
  5028. }
  5029. chunksToRequest.sort(function(a, b) { return a - b; });
  5030. return this._requestChunks(chunksToRequest);
  5031. },
  5032. // Groups a sorted array of chunks into as few contiguous larger
  5033. // chunks as possible
  5034. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  5035. var groupedChunks = [];
  5036. var beginChunk = -1;
  5037. var prevChunk = -1;
  5038. for (var i = 0; i < chunks.length; ++i) {
  5039. var chunk = chunks[i];
  5040. if (beginChunk < 0) {
  5041. beginChunk = chunk;
  5042. }
  5043. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  5044. groupedChunks.push({ beginChunk: beginChunk,
  5045. endChunk: prevChunk + 1 });
  5046. beginChunk = chunk;
  5047. }
  5048. if (i + 1 === chunks.length) {
  5049. groupedChunks.push({ beginChunk: beginChunk,
  5050. endChunk: chunk + 1 });
  5051. }
  5052. prevChunk = chunk;
  5053. }
  5054. return groupedChunks;
  5055. },
  5056. onProgress: function ChunkedStreamManager_onProgress(args) {
  5057. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  5058. args.loaded);
  5059. this.msgHandler.send('DocProgress', {
  5060. loaded: bytesLoaded,
  5061. total: this.length
  5062. });
  5063. },
  5064. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  5065. var chunk = args.chunk;
  5066. var isProgressive = args.begin === undefined;
  5067. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  5068. var end = begin + chunk.byteLength;
  5069. var beginChunk = Math.floor(begin / this.chunkSize);
  5070. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  5071. Math.ceil(end / this.chunkSize);
  5072. if (isProgressive) {
  5073. this.stream.onReceiveProgressiveData(chunk);
  5074. this.progressiveDataLength = end;
  5075. } else {
  5076. this.stream.onReceiveData(begin, chunk);
  5077. }
  5078. if (this.stream.allChunksLoaded()) {
  5079. this._loadedStreamCapability.resolve(this.stream);
  5080. }
  5081. var loadedRequests = [];
  5082. var i, requestId;
  5083. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  5084. // The server might return more chunks than requested
  5085. var requestIds = this.requestsByChunk[chunk] || [];
  5086. delete this.requestsByChunk[chunk];
  5087. for (i = 0; i < requestIds.length; ++i) {
  5088. requestId = requestIds[i];
  5089. var chunksNeeded = this.chunksNeededByRequest[requestId];
  5090. if (chunk in chunksNeeded) {
  5091. delete chunksNeeded[chunk];
  5092. }
  5093. if (!isEmptyObj(chunksNeeded)) {
  5094. continue;
  5095. }
  5096. loadedRequests.push(requestId);
  5097. }
  5098. }
  5099. // If there are no pending requests, automatically fetch the next
  5100. // unfetched chunk of the PDF
  5101. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  5102. var nextEmptyChunk;
  5103. if (this.stream.numChunksLoaded === 1) {
  5104. // This is a special optimization so that after fetching the first
  5105. // chunk, rather than fetching the second chunk, we fetch the last
  5106. // chunk.
  5107. var lastChunk = this.stream.numChunks - 1;
  5108. if (!this.stream.hasChunk(lastChunk)) {
  5109. nextEmptyChunk = lastChunk;
  5110. }
  5111. } else {
  5112. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  5113. }
  5114. if (isInt(nextEmptyChunk)) {
  5115. this._requestChunks([nextEmptyChunk]);
  5116. }
  5117. }
  5118. for (i = 0; i < loadedRequests.length; ++i) {
  5119. requestId = loadedRequests[i];
  5120. var capability = this.promisesByRequest[requestId];
  5121. delete this.promisesByRequest[requestId];
  5122. capability.resolve();
  5123. }
  5124. this.msgHandler.send('DocProgress', {
  5125. loaded: this.stream.numChunksLoaded * this.chunkSize,
  5126. total: this.length
  5127. });
  5128. },
  5129. onError: function ChunkedStreamManager_onError(err) {
  5130. this._loadedStreamCapability.reject(err);
  5131. },
  5132. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  5133. var chunk = Math.floor(begin / this.chunkSize);
  5134. return chunk;
  5135. },
  5136. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  5137. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  5138. return chunk;
  5139. },
  5140. abort: function ChunkedStreamManager_abort() {
  5141. this.aborted = true;
  5142. if (this.pdfNetworkStream) {
  5143. this.pdfNetworkStream.cancelAllRequests('abort');
  5144. }
  5145. for(var requestId in this.promisesByRequest) {
  5146. var capability = this.promisesByRequest[requestId];
  5147. capability.reject(new Error('Request was aborted'));
  5148. }
  5149. }
  5150. };
  5151. return ChunkedStreamManager;
  5152. })();
  5153. exports.ChunkedStream = ChunkedStream;
  5154. exports.ChunkedStreamManager = ChunkedStreamManager;
  5155. }));
  5156. (function (root, factory) {
  5157. {
  5158. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  5159. }
  5160. }(this, function (exports, sharedUtil) {
  5161. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  5162. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  5163. t['A'] = 0x0041;
  5164. t['AE'] = 0x00C6;
  5165. t['AEacute'] = 0x01FC;
  5166. t['AEmacron'] = 0x01E2;
  5167. t['AEsmall'] = 0xF7E6;
  5168. t['Aacute'] = 0x00C1;
  5169. t['Aacutesmall'] = 0xF7E1;
  5170. t['Abreve'] = 0x0102;
  5171. t['Abreveacute'] = 0x1EAE;
  5172. t['Abrevecyrillic'] = 0x04D0;
  5173. t['Abrevedotbelow'] = 0x1EB6;
  5174. t['Abrevegrave'] = 0x1EB0;
  5175. t['Abrevehookabove'] = 0x1EB2;
  5176. t['Abrevetilde'] = 0x1EB4;
  5177. t['Acaron'] = 0x01CD;
  5178. t['Acircle'] = 0x24B6;
  5179. t['Acircumflex'] = 0x00C2;
  5180. t['Acircumflexacute'] = 0x1EA4;
  5181. t['Acircumflexdotbelow'] = 0x1EAC;
  5182. t['Acircumflexgrave'] = 0x1EA6;
  5183. t['Acircumflexhookabove'] = 0x1EA8;
  5184. t['Acircumflexsmall'] = 0xF7E2;
  5185. t['Acircumflextilde'] = 0x1EAA;
  5186. t['Acute'] = 0xF6C9;
  5187. t['Acutesmall'] = 0xF7B4;
  5188. t['Acyrillic'] = 0x0410;
  5189. t['Adblgrave'] = 0x0200;
  5190. t['Adieresis'] = 0x00C4;
  5191. t['Adieresiscyrillic'] = 0x04D2;
  5192. t['Adieresismacron'] = 0x01DE;
  5193. t['Adieresissmall'] = 0xF7E4;
  5194. t['Adotbelow'] = 0x1EA0;
  5195. t['Adotmacron'] = 0x01E0;
  5196. t['Agrave'] = 0x00C0;
  5197. t['Agravesmall'] = 0xF7E0;
  5198. t['Ahookabove'] = 0x1EA2;
  5199. t['Aiecyrillic'] = 0x04D4;
  5200. t['Ainvertedbreve'] = 0x0202;
  5201. t['Alpha'] = 0x0391;
  5202. t['Alphatonos'] = 0x0386;
  5203. t['Amacron'] = 0x0100;
  5204. t['Amonospace'] = 0xFF21;
  5205. t['Aogonek'] = 0x0104;
  5206. t['Aring'] = 0x00C5;
  5207. t['Aringacute'] = 0x01FA;
  5208. t['Aringbelow'] = 0x1E00;
  5209. t['Aringsmall'] = 0xF7E5;
  5210. t['Asmall'] = 0xF761;
  5211. t['Atilde'] = 0x00C3;
  5212. t['Atildesmall'] = 0xF7E3;
  5213. t['Aybarmenian'] = 0x0531;
  5214. t['B'] = 0x0042;
  5215. t['Bcircle'] = 0x24B7;
  5216. t['Bdotaccent'] = 0x1E02;
  5217. t['Bdotbelow'] = 0x1E04;
  5218. t['Becyrillic'] = 0x0411;
  5219. t['Benarmenian'] = 0x0532;
  5220. t['Beta'] = 0x0392;
  5221. t['Bhook'] = 0x0181;
  5222. t['Blinebelow'] = 0x1E06;
  5223. t['Bmonospace'] = 0xFF22;
  5224. t['Brevesmall'] = 0xF6F4;
  5225. t['Bsmall'] = 0xF762;
  5226. t['Btopbar'] = 0x0182;
  5227. t['C'] = 0x0043;
  5228. t['Caarmenian'] = 0x053E;
  5229. t['Cacute'] = 0x0106;
  5230. t['Caron'] = 0xF6CA;
  5231. t['Caronsmall'] = 0xF6F5;
  5232. t['Ccaron'] = 0x010C;
  5233. t['Ccedilla'] = 0x00C7;
  5234. t['Ccedillaacute'] = 0x1E08;
  5235. t['Ccedillasmall'] = 0xF7E7;
  5236. t['Ccircle'] = 0x24B8;
  5237. t['Ccircumflex'] = 0x0108;
  5238. t['Cdot'] = 0x010A;
  5239. t['Cdotaccent'] = 0x010A;
  5240. t['Cedillasmall'] = 0xF7B8;
  5241. t['Chaarmenian'] = 0x0549;
  5242. t['Cheabkhasiancyrillic'] = 0x04BC;
  5243. t['Checyrillic'] = 0x0427;
  5244. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  5245. t['Chedescendercyrillic'] = 0x04B6;
  5246. t['Chedieresiscyrillic'] = 0x04F4;
  5247. t['Cheharmenian'] = 0x0543;
  5248. t['Chekhakassiancyrillic'] = 0x04CB;
  5249. t['Cheverticalstrokecyrillic'] = 0x04B8;
  5250. t['Chi'] = 0x03A7;
  5251. t['Chook'] = 0x0187;
  5252. t['Circumflexsmall'] = 0xF6F6;
  5253. t['Cmonospace'] = 0xFF23;
  5254. t['Coarmenian'] = 0x0551;
  5255. t['Csmall'] = 0xF763;
  5256. t['D'] = 0x0044;
  5257. t['DZ'] = 0x01F1;
  5258. t['DZcaron'] = 0x01C4;
  5259. t['Daarmenian'] = 0x0534;
  5260. t['Dafrican'] = 0x0189;
  5261. t['Dcaron'] = 0x010E;
  5262. t['Dcedilla'] = 0x1E10;
  5263. t['Dcircle'] = 0x24B9;
  5264. t['Dcircumflexbelow'] = 0x1E12;
  5265. t['Dcroat'] = 0x0110;
  5266. t['Ddotaccent'] = 0x1E0A;
  5267. t['Ddotbelow'] = 0x1E0C;
  5268. t['Decyrillic'] = 0x0414;
  5269. t['Deicoptic'] = 0x03EE;
  5270. t['Delta'] = 0x2206;
  5271. t['Deltagreek'] = 0x0394;
  5272. t['Dhook'] = 0x018A;
  5273. t['Dieresis'] = 0xF6CB;
  5274. t['DieresisAcute'] = 0xF6CC;
  5275. t['DieresisGrave'] = 0xF6CD;
  5276. t['Dieresissmall'] = 0xF7A8;
  5277. t['Digammagreek'] = 0x03DC;
  5278. t['Djecyrillic'] = 0x0402;
  5279. t['Dlinebelow'] = 0x1E0E;
  5280. t['Dmonospace'] = 0xFF24;
  5281. t['Dotaccentsmall'] = 0xF6F7;
  5282. t['Dslash'] = 0x0110;
  5283. t['Dsmall'] = 0xF764;
  5284. t['Dtopbar'] = 0x018B;
  5285. t['Dz'] = 0x01F2;
  5286. t['Dzcaron'] = 0x01C5;
  5287. t['Dzeabkhasiancyrillic'] = 0x04E0;
  5288. t['Dzecyrillic'] = 0x0405;
  5289. t['Dzhecyrillic'] = 0x040F;
  5290. t['E'] = 0x0045;
  5291. t['Eacute'] = 0x00C9;
  5292. t['Eacutesmall'] = 0xF7E9;
  5293. t['Ebreve'] = 0x0114;
  5294. t['Ecaron'] = 0x011A;
  5295. t['Ecedillabreve'] = 0x1E1C;
  5296. t['Echarmenian'] = 0x0535;
  5297. t['Ecircle'] = 0x24BA;
  5298. t['Ecircumflex'] = 0x00CA;
  5299. t['Ecircumflexacute'] = 0x1EBE;
  5300. t['Ecircumflexbelow'] = 0x1E18;
  5301. t['Ecircumflexdotbelow'] = 0x1EC6;
  5302. t['Ecircumflexgrave'] = 0x1EC0;
  5303. t['Ecircumflexhookabove'] = 0x1EC2;
  5304. t['Ecircumflexsmall'] = 0xF7EA;
  5305. t['Ecircumflextilde'] = 0x1EC4;
  5306. t['Ecyrillic'] = 0x0404;
  5307. t['Edblgrave'] = 0x0204;
  5308. t['Edieresis'] = 0x00CB;
  5309. t['Edieresissmall'] = 0xF7EB;
  5310. t['Edot'] = 0x0116;
  5311. t['Edotaccent'] = 0x0116;
  5312. t['Edotbelow'] = 0x1EB8;
  5313. t['Efcyrillic'] = 0x0424;
  5314. t['Egrave'] = 0x00C8;
  5315. t['Egravesmall'] = 0xF7E8;
  5316. t['Eharmenian'] = 0x0537;
  5317. t['Ehookabove'] = 0x1EBA;
  5318. t['Eightroman'] = 0x2167;
  5319. t['Einvertedbreve'] = 0x0206;
  5320. t['Eiotifiedcyrillic'] = 0x0464;
  5321. t['Elcyrillic'] = 0x041B;
  5322. t['Elevenroman'] = 0x216A;
  5323. t['Emacron'] = 0x0112;
  5324. t['Emacronacute'] = 0x1E16;
  5325. t['Emacrongrave'] = 0x1E14;
  5326. t['Emcyrillic'] = 0x041C;
  5327. t['Emonospace'] = 0xFF25;
  5328. t['Encyrillic'] = 0x041D;
  5329. t['Endescendercyrillic'] = 0x04A2;
  5330. t['Eng'] = 0x014A;
  5331. t['Enghecyrillic'] = 0x04A4;
  5332. t['Enhookcyrillic'] = 0x04C7;
  5333. t['Eogonek'] = 0x0118;
  5334. t['Eopen'] = 0x0190;
  5335. t['Epsilon'] = 0x0395;
  5336. t['Epsilontonos'] = 0x0388;
  5337. t['Ercyrillic'] = 0x0420;
  5338. t['Ereversed'] = 0x018E;
  5339. t['Ereversedcyrillic'] = 0x042D;
  5340. t['Escyrillic'] = 0x0421;
  5341. t['Esdescendercyrillic'] = 0x04AA;
  5342. t['Esh'] = 0x01A9;
  5343. t['Esmall'] = 0xF765;
  5344. t['Eta'] = 0x0397;
  5345. t['Etarmenian'] = 0x0538;
  5346. t['Etatonos'] = 0x0389;
  5347. t['Eth'] = 0x00D0;
  5348. t['Ethsmall'] = 0xF7F0;
  5349. t['Etilde'] = 0x1EBC;
  5350. t['Etildebelow'] = 0x1E1A;
  5351. t['Euro'] = 0x20AC;
  5352. t['Ezh'] = 0x01B7;
  5353. t['Ezhcaron'] = 0x01EE;
  5354. t['Ezhreversed'] = 0x01B8;
  5355. t['F'] = 0x0046;
  5356. t['Fcircle'] = 0x24BB;
  5357. t['Fdotaccent'] = 0x1E1E;
  5358. t['Feharmenian'] = 0x0556;
  5359. t['Feicoptic'] = 0x03E4;
  5360. t['Fhook'] = 0x0191;
  5361. t['Fitacyrillic'] = 0x0472;
  5362. t['Fiveroman'] = 0x2164;
  5363. t['Fmonospace'] = 0xFF26;
  5364. t['Fourroman'] = 0x2163;
  5365. t['Fsmall'] = 0xF766;
  5366. t['G'] = 0x0047;
  5367. t['GBsquare'] = 0x3387;
  5368. t['Gacute'] = 0x01F4;
  5369. t['Gamma'] = 0x0393;
  5370. t['Gammaafrican'] = 0x0194;
  5371. t['Gangiacoptic'] = 0x03EA;
  5372. t['Gbreve'] = 0x011E;
  5373. t['Gcaron'] = 0x01E6;
  5374. t['Gcedilla'] = 0x0122;
  5375. t['Gcircle'] = 0x24BC;
  5376. t['Gcircumflex'] = 0x011C;
  5377. t['Gcommaaccent'] = 0x0122;
  5378. t['Gdot'] = 0x0120;
  5379. t['Gdotaccent'] = 0x0120;
  5380. t['Gecyrillic'] = 0x0413;
  5381. t['Ghadarmenian'] = 0x0542;
  5382. t['Ghemiddlehookcyrillic'] = 0x0494;
  5383. t['Ghestrokecyrillic'] = 0x0492;
  5384. t['Gheupturncyrillic'] = 0x0490;
  5385. t['Ghook'] = 0x0193;
  5386. t['Gimarmenian'] = 0x0533;
  5387. t['Gjecyrillic'] = 0x0403;
  5388. t['Gmacron'] = 0x1E20;
  5389. t['Gmonospace'] = 0xFF27;
  5390. t['Grave'] = 0xF6CE;
  5391. t['Gravesmall'] = 0xF760;
  5392. t['Gsmall'] = 0xF767;
  5393. t['Gsmallhook'] = 0x029B;
  5394. t['Gstroke'] = 0x01E4;
  5395. t['H'] = 0x0048;
  5396. t['H18533'] = 0x25CF;
  5397. t['H18543'] = 0x25AA;
  5398. t['H18551'] = 0x25AB;
  5399. t['H22073'] = 0x25A1;
  5400. t['HPsquare'] = 0x33CB;
  5401. t['Haabkhasiancyrillic'] = 0x04A8;
  5402. t['Hadescendercyrillic'] = 0x04B2;
  5403. t['Hardsigncyrillic'] = 0x042A;
  5404. t['Hbar'] = 0x0126;
  5405. t['Hbrevebelow'] = 0x1E2A;
  5406. t['Hcedilla'] = 0x1E28;
  5407. t['Hcircle'] = 0x24BD;
  5408. t['Hcircumflex'] = 0x0124;
  5409. t['Hdieresis'] = 0x1E26;
  5410. t['Hdotaccent'] = 0x1E22;
  5411. t['Hdotbelow'] = 0x1E24;
  5412. t['Hmonospace'] = 0xFF28;
  5413. t['Hoarmenian'] = 0x0540;
  5414. t['Horicoptic'] = 0x03E8;
  5415. t['Hsmall'] = 0xF768;
  5416. t['Hungarumlaut'] = 0xF6CF;
  5417. t['Hungarumlautsmall'] = 0xF6F8;
  5418. t['Hzsquare'] = 0x3390;
  5419. t['I'] = 0x0049;
  5420. t['IAcyrillic'] = 0x042F;
  5421. t['IJ'] = 0x0132;
  5422. t['IUcyrillic'] = 0x042E;
  5423. t['Iacute'] = 0x00CD;
  5424. t['Iacutesmall'] = 0xF7ED;
  5425. t['Ibreve'] = 0x012C;
  5426. t['Icaron'] = 0x01CF;
  5427. t['Icircle'] = 0x24BE;
  5428. t['Icircumflex'] = 0x00CE;
  5429. t['Icircumflexsmall'] = 0xF7EE;
  5430. t['Icyrillic'] = 0x0406;
  5431. t['Idblgrave'] = 0x0208;
  5432. t['Idieresis'] = 0x00CF;
  5433. t['Idieresisacute'] = 0x1E2E;
  5434. t['Idieresiscyrillic'] = 0x04E4;
  5435. t['Idieresissmall'] = 0xF7EF;
  5436. t['Idot'] = 0x0130;
  5437. t['Idotaccent'] = 0x0130;
  5438. t['Idotbelow'] = 0x1ECA;
  5439. t['Iebrevecyrillic'] = 0x04D6;
  5440. t['Iecyrillic'] = 0x0415;
  5441. t['Ifraktur'] = 0x2111;
  5442. t['Igrave'] = 0x00CC;
  5443. t['Igravesmall'] = 0xF7EC;
  5444. t['Ihookabove'] = 0x1EC8;
  5445. t['Iicyrillic'] = 0x0418;
  5446. t['Iinvertedbreve'] = 0x020A;
  5447. t['Iishortcyrillic'] = 0x0419;
  5448. t['Imacron'] = 0x012A;
  5449. t['Imacroncyrillic'] = 0x04E2;
  5450. t['Imonospace'] = 0xFF29;
  5451. t['Iniarmenian'] = 0x053B;
  5452. t['Iocyrillic'] = 0x0401;
  5453. t['Iogonek'] = 0x012E;
  5454. t['Iota'] = 0x0399;
  5455. t['Iotaafrican'] = 0x0196;
  5456. t['Iotadieresis'] = 0x03AA;
  5457. t['Iotatonos'] = 0x038A;
  5458. t['Ismall'] = 0xF769;
  5459. t['Istroke'] = 0x0197;
  5460. t['Itilde'] = 0x0128;
  5461. t['Itildebelow'] = 0x1E2C;
  5462. t['Izhitsacyrillic'] = 0x0474;
  5463. t['Izhitsadblgravecyrillic'] = 0x0476;
  5464. t['J'] = 0x004A;
  5465. t['Jaarmenian'] = 0x0541;
  5466. t['Jcircle'] = 0x24BF;
  5467. t['Jcircumflex'] = 0x0134;
  5468. t['Jecyrillic'] = 0x0408;
  5469. t['Jheharmenian'] = 0x054B;
  5470. t['Jmonospace'] = 0xFF2A;
  5471. t['Jsmall'] = 0xF76A;
  5472. t['K'] = 0x004B;
  5473. t['KBsquare'] = 0x3385;
  5474. t['KKsquare'] = 0x33CD;
  5475. t['Kabashkircyrillic'] = 0x04A0;
  5476. t['Kacute'] = 0x1E30;
  5477. t['Kacyrillic'] = 0x041A;
  5478. t['Kadescendercyrillic'] = 0x049A;
  5479. t['Kahookcyrillic'] = 0x04C3;
  5480. t['Kappa'] = 0x039A;
  5481. t['Kastrokecyrillic'] = 0x049E;
  5482. t['Kaverticalstrokecyrillic'] = 0x049C;
  5483. t['Kcaron'] = 0x01E8;
  5484. t['Kcedilla'] = 0x0136;
  5485. t['Kcircle'] = 0x24C0;
  5486. t['Kcommaaccent'] = 0x0136;
  5487. t['Kdotbelow'] = 0x1E32;
  5488. t['Keharmenian'] = 0x0554;
  5489. t['Kenarmenian'] = 0x053F;
  5490. t['Khacyrillic'] = 0x0425;
  5491. t['Kheicoptic'] = 0x03E6;
  5492. t['Khook'] = 0x0198;
  5493. t['Kjecyrillic'] = 0x040C;
  5494. t['Klinebelow'] = 0x1E34;
  5495. t['Kmonospace'] = 0xFF2B;
  5496. t['Koppacyrillic'] = 0x0480;
  5497. t['Koppagreek'] = 0x03DE;
  5498. t['Ksicyrillic'] = 0x046E;
  5499. t['Ksmall'] = 0xF76B;
  5500. t['L'] = 0x004C;
  5501. t['LJ'] = 0x01C7;
  5502. t['LL'] = 0xF6BF;
  5503. t['Lacute'] = 0x0139;
  5504. t['Lambda'] = 0x039B;
  5505. t['Lcaron'] = 0x013D;
  5506. t['Lcedilla'] = 0x013B;
  5507. t['Lcircle'] = 0x24C1;
  5508. t['Lcircumflexbelow'] = 0x1E3C;
  5509. t['Lcommaaccent'] = 0x013B;
  5510. t['Ldot'] = 0x013F;
  5511. t['Ldotaccent'] = 0x013F;
  5512. t['Ldotbelow'] = 0x1E36;
  5513. t['Ldotbelowmacron'] = 0x1E38;
  5514. t['Liwnarmenian'] = 0x053C;
  5515. t['Lj'] = 0x01C8;
  5516. t['Ljecyrillic'] = 0x0409;
  5517. t['Llinebelow'] = 0x1E3A;
  5518. t['Lmonospace'] = 0xFF2C;
  5519. t['Lslash'] = 0x0141;
  5520. t['Lslashsmall'] = 0xF6F9;
  5521. t['Lsmall'] = 0xF76C;
  5522. t['M'] = 0x004D;
  5523. t['MBsquare'] = 0x3386;
  5524. t['Macron'] = 0xF6D0;
  5525. t['Macronsmall'] = 0xF7AF;
  5526. t['Macute'] = 0x1E3E;
  5527. t['Mcircle'] = 0x24C2;
  5528. t['Mdotaccent'] = 0x1E40;
  5529. t['Mdotbelow'] = 0x1E42;
  5530. t['Menarmenian'] = 0x0544;
  5531. t['Mmonospace'] = 0xFF2D;
  5532. t['Msmall'] = 0xF76D;
  5533. t['Mturned'] = 0x019C;
  5534. t['Mu'] = 0x039C;
  5535. t['N'] = 0x004E;
  5536. t['NJ'] = 0x01CA;
  5537. t['Nacute'] = 0x0143;
  5538. t['Ncaron'] = 0x0147;
  5539. t['Ncedilla'] = 0x0145;
  5540. t['Ncircle'] = 0x24C3;
  5541. t['Ncircumflexbelow'] = 0x1E4A;
  5542. t['Ncommaaccent'] = 0x0145;
  5543. t['Ndotaccent'] = 0x1E44;
  5544. t['Ndotbelow'] = 0x1E46;
  5545. t['Nhookleft'] = 0x019D;
  5546. t['Nineroman'] = 0x2168;
  5547. t['Nj'] = 0x01CB;
  5548. t['Njecyrillic'] = 0x040A;
  5549. t['Nlinebelow'] = 0x1E48;
  5550. t['Nmonospace'] = 0xFF2E;
  5551. t['Nowarmenian'] = 0x0546;
  5552. t['Nsmall'] = 0xF76E;
  5553. t['Ntilde'] = 0x00D1;
  5554. t['Ntildesmall'] = 0xF7F1;
  5555. t['Nu'] = 0x039D;
  5556. t['O'] = 0x004F;
  5557. t['OE'] = 0x0152;
  5558. t['OEsmall'] = 0xF6FA;
  5559. t['Oacute'] = 0x00D3;
  5560. t['Oacutesmall'] = 0xF7F3;
  5561. t['Obarredcyrillic'] = 0x04E8;
  5562. t['Obarreddieresiscyrillic'] = 0x04EA;
  5563. t['Obreve'] = 0x014E;
  5564. t['Ocaron'] = 0x01D1;
  5565. t['Ocenteredtilde'] = 0x019F;
  5566. t['Ocircle'] = 0x24C4;
  5567. t['Ocircumflex'] = 0x00D4;
  5568. t['Ocircumflexacute'] = 0x1ED0;
  5569. t['Ocircumflexdotbelow'] = 0x1ED8;
  5570. t['Ocircumflexgrave'] = 0x1ED2;
  5571. t['Ocircumflexhookabove'] = 0x1ED4;
  5572. t['Ocircumflexsmall'] = 0xF7F4;
  5573. t['Ocircumflextilde'] = 0x1ED6;
  5574. t['Ocyrillic'] = 0x041E;
  5575. t['Odblacute'] = 0x0150;
  5576. t['Odblgrave'] = 0x020C;
  5577. t['Odieresis'] = 0x00D6;
  5578. t['Odieresiscyrillic'] = 0x04E6;
  5579. t['Odieresissmall'] = 0xF7F6;
  5580. t['Odotbelow'] = 0x1ECC;
  5581. t['Ogoneksmall'] = 0xF6FB;
  5582. t['Ograve'] = 0x00D2;
  5583. t['Ogravesmall'] = 0xF7F2;
  5584. t['Oharmenian'] = 0x0555;
  5585. t['Ohm'] = 0x2126;
  5586. t['Ohookabove'] = 0x1ECE;
  5587. t['Ohorn'] = 0x01A0;
  5588. t['Ohornacute'] = 0x1EDA;
  5589. t['Ohorndotbelow'] = 0x1EE2;
  5590. t['Ohorngrave'] = 0x1EDC;
  5591. t['Ohornhookabove'] = 0x1EDE;
  5592. t['Ohorntilde'] = 0x1EE0;
  5593. t['Ohungarumlaut'] = 0x0150;
  5594. t['Oi'] = 0x01A2;
  5595. t['Oinvertedbreve'] = 0x020E;
  5596. t['Omacron'] = 0x014C;
  5597. t['Omacronacute'] = 0x1E52;
  5598. t['Omacrongrave'] = 0x1E50;
  5599. t['Omega'] = 0x2126;
  5600. t['Omegacyrillic'] = 0x0460;
  5601. t['Omegagreek'] = 0x03A9;
  5602. t['Omegaroundcyrillic'] = 0x047A;
  5603. t['Omegatitlocyrillic'] = 0x047C;
  5604. t['Omegatonos'] = 0x038F;
  5605. t['Omicron'] = 0x039F;
  5606. t['Omicrontonos'] = 0x038C;
  5607. t['Omonospace'] = 0xFF2F;
  5608. t['Oneroman'] = 0x2160;
  5609. t['Oogonek'] = 0x01EA;
  5610. t['Oogonekmacron'] = 0x01EC;
  5611. t['Oopen'] = 0x0186;
  5612. t['Oslash'] = 0x00D8;
  5613. t['Oslashacute'] = 0x01FE;
  5614. t['Oslashsmall'] = 0xF7F8;
  5615. t['Osmall'] = 0xF76F;
  5616. t['Ostrokeacute'] = 0x01FE;
  5617. t['Otcyrillic'] = 0x047E;
  5618. t['Otilde'] = 0x00D5;
  5619. t['Otildeacute'] = 0x1E4C;
  5620. t['Otildedieresis'] = 0x1E4E;
  5621. t['Otildesmall'] = 0xF7F5;
  5622. t['P'] = 0x0050;
  5623. t['Pacute'] = 0x1E54;
  5624. t['Pcircle'] = 0x24C5;
  5625. t['Pdotaccent'] = 0x1E56;
  5626. t['Pecyrillic'] = 0x041F;
  5627. t['Peharmenian'] = 0x054A;
  5628. t['Pemiddlehookcyrillic'] = 0x04A6;
  5629. t['Phi'] = 0x03A6;
  5630. t['Phook'] = 0x01A4;
  5631. t['Pi'] = 0x03A0;
  5632. t['Piwrarmenian'] = 0x0553;
  5633. t['Pmonospace'] = 0xFF30;
  5634. t['Psi'] = 0x03A8;
  5635. t['Psicyrillic'] = 0x0470;
  5636. t['Psmall'] = 0xF770;
  5637. t['Q'] = 0x0051;
  5638. t['Qcircle'] = 0x24C6;
  5639. t['Qmonospace'] = 0xFF31;
  5640. t['Qsmall'] = 0xF771;
  5641. t['R'] = 0x0052;
  5642. t['Raarmenian'] = 0x054C;
  5643. t['Racute'] = 0x0154;
  5644. t['Rcaron'] = 0x0158;
  5645. t['Rcedilla'] = 0x0156;
  5646. t['Rcircle'] = 0x24C7;
  5647. t['Rcommaaccent'] = 0x0156;
  5648. t['Rdblgrave'] = 0x0210;
  5649. t['Rdotaccent'] = 0x1E58;
  5650. t['Rdotbelow'] = 0x1E5A;
  5651. t['Rdotbelowmacron'] = 0x1E5C;
  5652. t['Reharmenian'] = 0x0550;
  5653. t['Rfraktur'] = 0x211C;
  5654. t['Rho'] = 0x03A1;
  5655. t['Ringsmall'] = 0xF6FC;
  5656. t['Rinvertedbreve'] = 0x0212;
  5657. t['Rlinebelow'] = 0x1E5E;
  5658. t['Rmonospace'] = 0xFF32;
  5659. t['Rsmall'] = 0xF772;
  5660. t['Rsmallinverted'] = 0x0281;
  5661. t['Rsmallinvertedsuperior'] = 0x02B6;
  5662. t['S'] = 0x0053;
  5663. t['SF010000'] = 0x250C;
  5664. t['SF020000'] = 0x2514;
  5665. t['SF030000'] = 0x2510;
  5666. t['SF040000'] = 0x2518;
  5667. t['SF050000'] = 0x253C;
  5668. t['SF060000'] = 0x252C;
  5669. t['SF070000'] = 0x2534;
  5670. t['SF080000'] = 0x251C;
  5671. t['SF090000'] = 0x2524;
  5672. t['SF100000'] = 0x2500;
  5673. t['SF110000'] = 0x2502;
  5674. t['SF190000'] = 0x2561;
  5675. t['SF200000'] = 0x2562;
  5676. t['SF210000'] = 0x2556;
  5677. t['SF220000'] = 0x2555;
  5678. t['SF230000'] = 0x2563;
  5679. t['SF240000'] = 0x2551;
  5680. t['SF250000'] = 0x2557;
  5681. t['SF260000'] = 0x255D;
  5682. t['SF270000'] = 0x255C;
  5683. t['SF280000'] = 0x255B;
  5684. t['SF360000'] = 0x255E;
  5685. t['SF370000'] = 0x255F;
  5686. t['SF380000'] = 0x255A;
  5687. t['SF390000'] = 0x2554;
  5688. t['SF400000'] = 0x2569;
  5689. t['SF410000'] = 0x2566;
  5690. t['SF420000'] = 0x2560;
  5691. t['SF430000'] = 0x2550;
  5692. t['SF440000'] = 0x256C;
  5693. t['SF450000'] = 0x2567;
  5694. t['SF460000'] = 0x2568;
  5695. t['SF470000'] = 0x2564;
  5696. t['SF480000'] = 0x2565;
  5697. t['SF490000'] = 0x2559;
  5698. t['SF500000'] = 0x2558;
  5699. t['SF510000'] = 0x2552;
  5700. t['SF520000'] = 0x2553;
  5701. t['SF530000'] = 0x256B;
  5702. t['SF540000'] = 0x256A;
  5703. t['Sacute'] = 0x015A;
  5704. t['Sacutedotaccent'] = 0x1E64;
  5705. t['Sampigreek'] = 0x03E0;
  5706. t['Scaron'] = 0x0160;
  5707. t['Scarondotaccent'] = 0x1E66;
  5708. t['Scaronsmall'] = 0xF6FD;
  5709. t['Scedilla'] = 0x015E;
  5710. t['Schwa'] = 0x018F;
  5711. t['Schwacyrillic'] = 0x04D8;
  5712. t['Schwadieresiscyrillic'] = 0x04DA;
  5713. t['Scircle'] = 0x24C8;
  5714. t['Scircumflex'] = 0x015C;
  5715. t['Scommaaccent'] = 0x0218;
  5716. t['Sdotaccent'] = 0x1E60;
  5717. t['Sdotbelow'] = 0x1E62;
  5718. t['Sdotbelowdotaccent'] = 0x1E68;
  5719. t['Seharmenian'] = 0x054D;
  5720. t['Sevenroman'] = 0x2166;
  5721. t['Shaarmenian'] = 0x0547;
  5722. t['Shacyrillic'] = 0x0428;
  5723. t['Shchacyrillic'] = 0x0429;
  5724. t['Sheicoptic'] = 0x03E2;
  5725. t['Shhacyrillic'] = 0x04BA;
  5726. t['Shimacoptic'] = 0x03EC;
  5727. t['Sigma'] = 0x03A3;
  5728. t['Sixroman'] = 0x2165;
  5729. t['Smonospace'] = 0xFF33;
  5730. t['Softsigncyrillic'] = 0x042C;
  5731. t['Ssmall'] = 0xF773;
  5732. t['Stigmagreek'] = 0x03DA;
  5733. t['T'] = 0x0054;
  5734. t['Tau'] = 0x03A4;
  5735. t['Tbar'] = 0x0166;
  5736. t['Tcaron'] = 0x0164;
  5737. t['Tcedilla'] = 0x0162;
  5738. t['Tcircle'] = 0x24C9;
  5739. t['Tcircumflexbelow'] = 0x1E70;
  5740. t['Tcommaaccent'] = 0x0162;
  5741. t['Tdotaccent'] = 0x1E6A;
  5742. t['Tdotbelow'] = 0x1E6C;
  5743. t['Tecyrillic'] = 0x0422;
  5744. t['Tedescendercyrillic'] = 0x04AC;
  5745. t['Tenroman'] = 0x2169;
  5746. t['Tetsecyrillic'] = 0x04B4;
  5747. t['Theta'] = 0x0398;
  5748. t['Thook'] = 0x01AC;
  5749. t['Thorn'] = 0x00DE;
  5750. t['Thornsmall'] = 0xF7FE;
  5751. t['Threeroman'] = 0x2162;
  5752. t['Tildesmall'] = 0xF6FE;
  5753. t['Tiwnarmenian'] = 0x054F;
  5754. t['Tlinebelow'] = 0x1E6E;
  5755. t['Tmonospace'] = 0xFF34;
  5756. t['Toarmenian'] = 0x0539;
  5757. t['Tonefive'] = 0x01BC;
  5758. t['Tonesix'] = 0x0184;
  5759. t['Tonetwo'] = 0x01A7;
  5760. t['Tretroflexhook'] = 0x01AE;
  5761. t['Tsecyrillic'] = 0x0426;
  5762. t['Tshecyrillic'] = 0x040B;
  5763. t['Tsmall'] = 0xF774;
  5764. t['Twelveroman'] = 0x216B;
  5765. t['Tworoman'] = 0x2161;
  5766. t['U'] = 0x0055;
  5767. t['Uacute'] = 0x00DA;
  5768. t['Uacutesmall'] = 0xF7FA;
  5769. t['Ubreve'] = 0x016C;
  5770. t['Ucaron'] = 0x01D3;
  5771. t['Ucircle'] = 0x24CA;
  5772. t['Ucircumflex'] = 0x00DB;
  5773. t['Ucircumflexbelow'] = 0x1E76;
  5774. t['Ucircumflexsmall'] = 0xF7FB;
  5775. t['Ucyrillic'] = 0x0423;
  5776. t['Udblacute'] = 0x0170;
  5777. t['Udblgrave'] = 0x0214;
  5778. t['Udieresis'] = 0x00DC;
  5779. t['Udieresisacute'] = 0x01D7;
  5780. t['Udieresisbelow'] = 0x1E72;
  5781. t['Udieresiscaron'] = 0x01D9;
  5782. t['Udieresiscyrillic'] = 0x04F0;
  5783. t['Udieresisgrave'] = 0x01DB;
  5784. t['Udieresismacron'] = 0x01D5;
  5785. t['Udieresissmall'] = 0xF7FC;
  5786. t['Udotbelow'] = 0x1EE4;
  5787. t['Ugrave'] = 0x00D9;
  5788. t['Ugravesmall'] = 0xF7F9;
  5789. t['Uhookabove'] = 0x1EE6;
  5790. t['Uhorn'] = 0x01AF;
  5791. t['Uhornacute'] = 0x1EE8;
  5792. t['Uhorndotbelow'] = 0x1EF0;
  5793. t['Uhorngrave'] = 0x1EEA;
  5794. t['Uhornhookabove'] = 0x1EEC;
  5795. t['Uhorntilde'] = 0x1EEE;
  5796. t['Uhungarumlaut'] = 0x0170;
  5797. t['Uhungarumlautcyrillic'] = 0x04F2;
  5798. t['Uinvertedbreve'] = 0x0216;
  5799. t['Ukcyrillic'] = 0x0478;
  5800. t['Umacron'] = 0x016A;
  5801. t['Umacroncyrillic'] = 0x04EE;
  5802. t['Umacrondieresis'] = 0x1E7A;
  5803. t['Umonospace'] = 0xFF35;
  5804. t['Uogonek'] = 0x0172;
  5805. t['Upsilon'] = 0x03A5;
  5806. t['Upsilon1'] = 0x03D2;
  5807. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5808. t['Upsilonafrican'] = 0x01B1;
  5809. t['Upsilondieresis'] = 0x03AB;
  5810. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5811. t['Upsilonhooksymbol'] = 0x03D2;
  5812. t['Upsilontonos'] = 0x038E;
  5813. t['Uring'] = 0x016E;
  5814. t['Ushortcyrillic'] = 0x040E;
  5815. t['Usmall'] = 0xF775;
  5816. t['Ustraightcyrillic'] = 0x04AE;
  5817. t['Ustraightstrokecyrillic'] = 0x04B0;
  5818. t['Utilde'] = 0x0168;
  5819. t['Utildeacute'] = 0x1E78;
  5820. t['Utildebelow'] = 0x1E74;
  5821. t['V'] = 0x0056;
  5822. t['Vcircle'] = 0x24CB;
  5823. t['Vdotbelow'] = 0x1E7E;
  5824. t['Vecyrillic'] = 0x0412;
  5825. t['Vewarmenian'] = 0x054E;
  5826. t['Vhook'] = 0x01B2;
  5827. t['Vmonospace'] = 0xFF36;
  5828. t['Voarmenian'] = 0x0548;
  5829. t['Vsmall'] = 0xF776;
  5830. t['Vtilde'] = 0x1E7C;
  5831. t['W'] = 0x0057;
  5832. t['Wacute'] = 0x1E82;
  5833. t['Wcircle'] = 0x24CC;
  5834. t['Wcircumflex'] = 0x0174;
  5835. t['Wdieresis'] = 0x1E84;
  5836. t['Wdotaccent'] = 0x1E86;
  5837. t['Wdotbelow'] = 0x1E88;
  5838. t['Wgrave'] = 0x1E80;
  5839. t['Wmonospace'] = 0xFF37;
  5840. t['Wsmall'] = 0xF777;
  5841. t['X'] = 0x0058;
  5842. t['Xcircle'] = 0x24CD;
  5843. t['Xdieresis'] = 0x1E8C;
  5844. t['Xdotaccent'] = 0x1E8A;
  5845. t['Xeharmenian'] = 0x053D;
  5846. t['Xi'] = 0x039E;
  5847. t['Xmonospace'] = 0xFF38;
  5848. t['Xsmall'] = 0xF778;
  5849. t['Y'] = 0x0059;
  5850. t['Yacute'] = 0x00DD;
  5851. t['Yacutesmall'] = 0xF7FD;
  5852. t['Yatcyrillic'] = 0x0462;
  5853. t['Ycircle'] = 0x24CE;
  5854. t['Ycircumflex'] = 0x0176;
  5855. t['Ydieresis'] = 0x0178;
  5856. t['Ydieresissmall'] = 0xF7FF;
  5857. t['Ydotaccent'] = 0x1E8E;
  5858. t['Ydotbelow'] = 0x1EF4;
  5859. t['Yericyrillic'] = 0x042B;
  5860. t['Yerudieresiscyrillic'] = 0x04F8;
  5861. t['Ygrave'] = 0x1EF2;
  5862. t['Yhook'] = 0x01B3;
  5863. t['Yhookabove'] = 0x1EF6;
  5864. t['Yiarmenian'] = 0x0545;
  5865. t['Yicyrillic'] = 0x0407;
  5866. t['Yiwnarmenian'] = 0x0552;
  5867. t['Ymonospace'] = 0xFF39;
  5868. t['Ysmall'] = 0xF779;
  5869. t['Ytilde'] = 0x1EF8;
  5870. t['Yusbigcyrillic'] = 0x046A;
  5871. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5872. t['Yuslittlecyrillic'] = 0x0466;
  5873. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5874. t['Z'] = 0x005A;
  5875. t['Zaarmenian'] = 0x0536;
  5876. t['Zacute'] = 0x0179;
  5877. t['Zcaron'] = 0x017D;
  5878. t['Zcaronsmall'] = 0xF6FF;
  5879. t['Zcircle'] = 0x24CF;
  5880. t['Zcircumflex'] = 0x1E90;
  5881. t['Zdot'] = 0x017B;
  5882. t['Zdotaccent'] = 0x017B;
  5883. t['Zdotbelow'] = 0x1E92;
  5884. t['Zecyrillic'] = 0x0417;
  5885. t['Zedescendercyrillic'] = 0x0498;
  5886. t['Zedieresiscyrillic'] = 0x04DE;
  5887. t['Zeta'] = 0x0396;
  5888. t['Zhearmenian'] = 0x053A;
  5889. t['Zhebrevecyrillic'] = 0x04C1;
  5890. t['Zhecyrillic'] = 0x0416;
  5891. t['Zhedescendercyrillic'] = 0x0496;
  5892. t['Zhedieresiscyrillic'] = 0x04DC;
  5893. t['Zlinebelow'] = 0x1E94;
  5894. t['Zmonospace'] = 0xFF3A;
  5895. t['Zsmall'] = 0xF77A;
  5896. t['Zstroke'] = 0x01B5;
  5897. t['a'] = 0x0061;
  5898. t['aabengali'] = 0x0986;
  5899. t['aacute'] = 0x00E1;
  5900. t['aadeva'] = 0x0906;
  5901. t['aagujarati'] = 0x0A86;
  5902. t['aagurmukhi'] = 0x0A06;
  5903. t['aamatragurmukhi'] = 0x0A3E;
  5904. t['aarusquare'] = 0x3303;
  5905. t['aavowelsignbengali'] = 0x09BE;
  5906. t['aavowelsigndeva'] = 0x093E;
  5907. t['aavowelsigngujarati'] = 0x0ABE;
  5908. t['abbreviationmarkarmenian'] = 0x055F;
  5909. t['abbreviationsigndeva'] = 0x0970;
  5910. t['abengali'] = 0x0985;
  5911. t['abopomofo'] = 0x311A;
  5912. t['abreve'] = 0x0103;
  5913. t['abreveacute'] = 0x1EAF;
  5914. t['abrevecyrillic'] = 0x04D1;
  5915. t['abrevedotbelow'] = 0x1EB7;
  5916. t['abrevegrave'] = 0x1EB1;
  5917. t['abrevehookabove'] = 0x1EB3;
  5918. t['abrevetilde'] = 0x1EB5;
  5919. t['acaron'] = 0x01CE;
  5920. t['acircle'] = 0x24D0;
  5921. t['acircumflex'] = 0x00E2;
  5922. t['acircumflexacute'] = 0x1EA5;
  5923. t['acircumflexdotbelow'] = 0x1EAD;
  5924. t['acircumflexgrave'] = 0x1EA7;
  5925. t['acircumflexhookabove'] = 0x1EA9;
  5926. t['acircumflextilde'] = 0x1EAB;
  5927. t['acute'] = 0x00B4;
  5928. t['acutebelowcmb'] = 0x0317;
  5929. t['acutecmb'] = 0x0301;
  5930. t['acutecomb'] = 0x0301;
  5931. t['acutedeva'] = 0x0954;
  5932. t['acutelowmod'] = 0x02CF;
  5933. t['acutetonecmb'] = 0x0341;
  5934. t['acyrillic'] = 0x0430;
  5935. t['adblgrave'] = 0x0201;
  5936. t['addakgurmukhi'] = 0x0A71;
  5937. t['adeva'] = 0x0905;
  5938. t['adieresis'] = 0x00E4;
  5939. t['adieresiscyrillic'] = 0x04D3;
  5940. t['adieresismacron'] = 0x01DF;
  5941. t['adotbelow'] = 0x1EA1;
  5942. t['adotmacron'] = 0x01E1;
  5943. t['ae'] = 0x00E6;
  5944. t['aeacute'] = 0x01FD;
  5945. t['aekorean'] = 0x3150;
  5946. t['aemacron'] = 0x01E3;
  5947. t['afii00208'] = 0x2015;
  5948. t['afii08941'] = 0x20A4;
  5949. t['afii10017'] = 0x0410;
  5950. t['afii10018'] = 0x0411;
  5951. t['afii10019'] = 0x0412;
  5952. t['afii10020'] = 0x0413;
  5953. t['afii10021'] = 0x0414;
  5954. t['afii10022'] = 0x0415;
  5955. t['afii10023'] = 0x0401;
  5956. t['afii10024'] = 0x0416;
  5957. t['afii10025'] = 0x0417;
  5958. t['afii10026'] = 0x0418;
  5959. t['afii10027'] = 0x0419;
  5960. t['afii10028'] = 0x041A;
  5961. t['afii10029'] = 0x041B;
  5962. t['afii10030'] = 0x041C;
  5963. t['afii10031'] = 0x041D;
  5964. t['afii10032'] = 0x041E;
  5965. t['afii10033'] = 0x041F;
  5966. t['afii10034'] = 0x0420;
  5967. t['afii10035'] = 0x0421;
  5968. t['afii10036'] = 0x0422;
  5969. t['afii10037'] = 0x0423;
  5970. t['afii10038'] = 0x0424;
  5971. t['afii10039'] = 0x0425;
  5972. t['afii10040'] = 0x0426;
  5973. t['afii10041'] = 0x0427;
  5974. t['afii10042'] = 0x0428;
  5975. t['afii10043'] = 0x0429;
  5976. t['afii10044'] = 0x042A;
  5977. t['afii10045'] = 0x042B;
  5978. t['afii10046'] = 0x042C;
  5979. t['afii10047'] = 0x042D;
  5980. t['afii10048'] = 0x042E;
  5981. t['afii10049'] = 0x042F;
  5982. t['afii10050'] = 0x0490;
  5983. t['afii10051'] = 0x0402;
  5984. t['afii10052'] = 0x0403;
  5985. t['afii10053'] = 0x0404;
  5986. t['afii10054'] = 0x0405;
  5987. t['afii10055'] = 0x0406;
  5988. t['afii10056'] = 0x0407;
  5989. t['afii10057'] = 0x0408;
  5990. t['afii10058'] = 0x0409;
  5991. t['afii10059'] = 0x040A;
  5992. t['afii10060'] = 0x040B;
  5993. t['afii10061'] = 0x040C;
  5994. t['afii10062'] = 0x040E;
  5995. t['afii10063'] = 0xF6C4;
  5996. t['afii10064'] = 0xF6C5;
  5997. t['afii10065'] = 0x0430;
  5998. t['afii10066'] = 0x0431;
  5999. t['afii10067'] = 0x0432;
  6000. t['afii10068'] = 0x0433;
  6001. t['afii10069'] = 0x0434;
  6002. t['afii10070'] = 0x0435;
  6003. t['afii10071'] = 0x0451;
  6004. t['afii10072'] = 0x0436;
  6005. t['afii10073'] = 0x0437;
  6006. t['afii10074'] = 0x0438;
  6007. t['afii10075'] = 0x0439;
  6008. t['afii10076'] = 0x043A;
  6009. t['afii10077'] = 0x043B;
  6010. t['afii10078'] = 0x043C;
  6011. t['afii10079'] = 0x043D;
  6012. t['afii10080'] = 0x043E;
  6013. t['afii10081'] = 0x043F;
  6014. t['afii10082'] = 0x0440;
  6015. t['afii10083'] = 0x0441;
  6016. t['afii10084'] = 0x0442;
  6017. t['afii10085'] = 0x0443;
  6018. t['afii10086'] = 0x0444;
  6019. t['afii10087'] = 0x0445;
  6020. t['afii10088'] = 0x0446;
  6021. t['afii10089'] = 0x0447;
  6022. t['afii10090'] = 0x0448;
  6023. t['afii10091'] = 0x0449;
  6024. t['afii10092'] = 0x044A;
  6025. t['afii10093'] = 0x044B;
  6026. t['afii10094'] = 0x044C;
  6027. t['afii10095'] = 0x044D;
  6028. t['afii10096'] = 0x044E;
  6029. t['afii10097'] = 0x044F;
  6030. t['afii10098'] = 0x0491;
  6031. t['afii10099'] = 0x0452;
  6032. t['afii10100'] = 0x0453;
  6033. t['afii10101'] = 0x0454;
  6034. t['afii10102'] = 0x0455;
  6035. t['afii10103'] = 0x0456;
  6036. t['afii10104'] = 0x0457;
  6037. t['afii10105'] = 0x0458;
  6038. t['afii10106'] = 0x0459;
  6039. t['afii10107'] = 0x045A;
  6040. t['afii10108'] = 0x045B;
  6041. t['afii10109'] = 0x045C;
  6042. t['afii10110'] = 0x045E;
  6043. t['afii10145'] = 0x040F;
  6044. t['afii10146'] = 0x0462;
  6045. t['afii10147'] = 0x0472;
  6046. t['afii10148'] = 0x0474;
  6047. t['afii10192'] = 0xF6C6;
  6048. t['afii10193'] = 0x045F;
  6049. t['afii10194'] = 0x0463;
  6050. t['afii10195'] = 0x0473;
  6051. t['afii10196'] = 0x0475;
  6052. t['afii10831'] = 0xF6C7;
  6053. t['afii10832'] = 0xF6C8;
  6054. t['afii10846'] = 0x04D9;
  6055. t['afii299'] = 0x200E;
  6056. t['afii300'] = 0x200F;
  6057. t['afii301'] = 0x200D;
  6058. t['afii57381'] = 0x066A;
  6059. t['afii57388'] = 0x060C;
  6060. t['afii57392'] = 0x0660;
  6061. t['afii57393'] = 0x0661;
  6062. t['afii57394'] = 0x0662;
  6063. t['afii57395'] = 0x0663;
  6064. t['afii57396'] = 0x0664;
  6065. t['afii57397'] = 0x0665;
  6066. t['afii57398'] = 0x0666;
  6067. t['afii57399'] = 0x0667;
  6068. t['afii57400'] = 0x0668;
  6069. t['afii57401'] = 0x0669;
  6070. t['afii57403'] = 0x061B;
  6071. t['afii57407'] = 0x061F;
  6072. t['afii57409'] = 0x0621;
  6073. t['afii57410'] = 0x0622;
  6074. t['afii57411'] = 0x0623;
  6075. t['afii57412'] = 0x0624;
  6076. t['afii57413'] = 0x0625;
  6077. t['afii57414'] = 0x0626;
  6078. t['afii57415'] = 0x0627;
  6079. t['afii57416'] = 0x0628;
  6080. t['afii57417'] = 0x0629;
  6081. t['afii57418'] = 0x062A;
  6082. t['afii57419'] = 0x062B;
  6083. t['afii57420'] = 0x062C;
  6084. t['afii57421'] = 0x062D;
  6085. t['afii57422'] = 0x062E;
  6086. t['afii57423'] = 0x062F;
  6087. t['afii57424'] = 0x0630;
  6088. t['afii57425'] = 0x0631;
  6089. t['afii57426'] = 0x0632;
  6090. t['afii57427'] = 0x0633;
  6091. t['afii57428'] = 0x0634;
  6092. t['afii57429'] = 0x0635;
  6093. t['afii57430'] = 0x0636;
  6094. t['afii57431'] = 0x0637;
  6095. t['afii57432'] = 0x0638;
  6096. t['afii57433'] = 0x0639;
  6097. t['afii57434'] = 0x063A;
  6098. t['afii57440'] = 0x0640;
  6099. t['afii57441'] = 0x0641;
  6100. t['afii57442'] = 0x0642;
  6101. t['afii57443'] = 0x0643;
  6102. t['afii57444'] = 0x0644;
  6103. t['afii57445'] = 0x0645;
  6104. t['afii57446'] = 0x0646;
  6105. t['afii57448'] = 0x0648;
  6106. t['afii57449'] = 0x0649;
  6107. t['afii57450'] = 0x064A;
  6108. t['afii57451'] = 0x064B;
  6109. t['afii57452'] = 0x064C;
  6110. t['afii57453'] = 0x064D;
  6111. t['afii57454'] = 0x064E;
  6112. t['afii57455'] = 0x064F;
  6113. t['afii57456'] = 0x0650;
  6114. t['afii57457'] = 0x0651;
  6115. t['afii57458'] = 0x0652;
  6116. t['afii57470'] = 0x0647;
  6117. t['afii57505'] = 0x06A4;
  6118. t['afii57506'] = 0x067E;
  6119. t['afii57507'] = 0x0686;
  6120. t['afii57508'] = 0x0698;
  6121. t['afii57509'] = 0x06AF;
  6122. t['afii57511'] = 0x0679;
  6123. t['afii57512'] = 0x0688;
  6124. t['afii57513'] = 0x0691;
  6125. t['afii57514'] = 0x06BA;
  6126. t['afii57519'] = 0x06D2;
  6127. t['afii57534'] = 0x06D5;
  6128. t['afii57636'] = 0x20AA;
  6129. t['afii57645'] = 0x05BE;
  6130. t['afii57658'] = 0x05C3;
  6131. t['afii57664'] = 0x05D0;
  6132. t['afii57665'] = 0x05D1;
  6133. t['afii57666'] = 0x05D2;
  6134. t['afii57667'] = 0x05D3;
  6135. t['afii57668'] = 0x05D4;
  6136. t['afii57669'] = 0x05D5;
  6137. t['afii57670'] = 0x05D6;
  6138. t['afii57671'] = 0x05D7;
  6139. t['afii57672'] = 0x05D8;
  6140. t['afii57673'] = 0x05D9;
  6141. t['afii57674'] = 0x05DA;
  6142. t['afii57675'] = 0x05DB;
  6143. t['afii57676'] = 0x05DC;
  6144. t['afii57677'] = 0x05DD;
  6145. t['afii57678'] = 0x05DE;
  6146. t['afii57679'] = 0x05DF;
  6147. t['afii57680'] = 0x05E0;
  6148. t['afii57681'] = 0x05E1;
  6149. t['afii57682'] = 0x05E2;
  6150. t['afii57683'] = 0x05E3;
  6151. t['afii57684'] = 0x05E4;
  6152. t['afii57685'] = 0x05E5;
  6153. t['afii57686'] = 0x05E6;
  6154. t['afii57687'] = 0x05E7;
  6155. t['afii57688'] = 0x05E8;
  6156. t['afii57689'] = 0x05E9;
  6157. t['afii57690'] = 0x05EA;
  6158. t['afii57694'] = 0xFB2A;
  6159. t['afii57695'] = 0xFB2B;
  6160. t['afii57700'] = 0xFB4B;
  6161. t['afii57705'] = 0xFB1F;
  6162. t['afii57716'] = 0x05F0;
  6163. t['afii57717'] = 0x05F1;
  6164. t['afii57718'] = 0x05F2;
  6165. t['afii57723'] = 0xFB35;
  6166. t['afii57793'] = 0x05B4;
  6167. t['afii57794'] = 0x05B5;
  6168. t['afii57795'] = 0x05B6;
  6169. t['afii57796'] = 0x05BB;
  6170. t['afii57797'] = 0x05B8;
  6171. t['afii57798'] = 0x05B7;
  6172. t['afii57799'] = 0x05B0;
  6173. t['afii57800'] = 0x05B2;
  6174. t['afii57801'] = 0x05B1;
  6175. t['afii57802'] = 0x05B3;
  6176. t['afii57803'] = 0x05C2;
  6177. t['afii57804'] = 0x05C1;
  6178. t['afii57806'] = 0x05B9;
  6179. t['afii57807'] = 0x05BC;
  6180. t['afii57839'] = 0x05BD;
  6181. t['afii57841'] = 0x05BF;
  6182. t['afii57842'] = 0x05C0;
  6183. t['afii57929'] = 0x02BC;
  6184. t['afii61248'] = 0x2105;
  6185. t['afii61289'] = 0x2113;
  6186. t['afii61352'] = 0x2116;
  6187. t['afii61573'] = 0x202C;
  6188. t['afii61574'] = 0x202D;
  6189. t['afii61575'] = 0x202E;
  6190. t['afii61664'] = 0x200C;
  6191. t['afii63167'] = 0x066D;
  6192. t['afii64937'] = 0x02BD;
  6193. t['agrave'] = 0x00E0;
  6194. t['agujarati'] = 0x0A85;
  6195. t['agurmukhi'] = 0x0A05;
  6196. t['ahiragana'] = 0x3042;
  6197. t['ahookabove'] = 0x1EA3;
  6198. t['aibengali'] = 0x0990;
  6199. t['aibopomofo'] = 0x311E;
  6200. t['aideva'] = 0x0910;
  6201. t['aiecyrillic'] = 0x04D5;
  6202. t['aigujarati'] = 0x0A90;
  6203. t['aigurmukhi'] = 0x0A10;
  6204. t['aimatragurmukhi'] = 0x0A48;
  6205. t['ainarabic'] = 0x0639;
  6206. t['ainfinalarabic'] = 0xFECA;
  6207. t['aininitialarabic'] = 0xFECB;
  6208. t['ainmedialarabic'] = 0xFECC;
  6209. t['ainvertedbreve'] = 0x0203;
  6210. t['aivowelsignbengali'] = 0x09C8;
  6211. t['aivowelsigndeva'] = 0x0948;
  6212. t['aivowelsigngujarati'] = 0x0AC8;
  6213. t['akatakana'] = 0x30A2;
  6214. t['akatakanahalfwidth'] = 0xFF71;
  6215. t['akorean'] = 0x314F;
  6216. t['alef'] = 0x05D0;
  6217. t['alefarabic'] = 0x0627;
  6218. t['alefdageshhebrew'] = 0xFB30;
  6219. t['aleffinalarabic'] = 0xFE8E;
  6220. t['alefhamzaabovearabic'] = 0x0623;
  6221. t['alefhamzaabovefinalarabic'] = 0xFE84;
  6222. t['alefhamzabelowarabic'] = 0x0625;
  6223. t['alefhamzabelowfinalarabic'] = 0xFE88;
  6224. t['alefhebrew'] = 0x05D0;
  6225. t['aleflamedhebrew'] = 0xFB4F;
  6226. t['alefmaddaabovearabic'] = 0x0622;
  6227. t['alefmaddaabovefinalarabic'] = 0xFE82;
  6228. t['alefmaksuraarabic'] = 0x0649;
  6229. t['alefmaksurafinalarabic'] = 0xFEF0;
  6230. t['alefmaksurainitialarabic'] = 0xFEF3;
  6231. t['alefmaksuramedialarabic'] = 0xFEF4;
  6232. t['alefpatahhebrew'] = 0xFB2E;
  6233. t['alefqamatshebrew'] = 0xFB2F;
  6234. t['aleph'] = 0x2135;
  6235. t['allequal'] = 0x224C;
  6236. t['alpha'] = 0x03B1;
  6237. t['alphatonos'] = 0x03AC;
  6238. t['amacron'] = 0x0101;
  6239. t['amonospace'] = 0xFF41;
  6240. t['ampersand'] = 0x0026;
  6241. t['ampersandmonospace'] = 0xFF06;
  6242. t['ampersandsmall'] = 0xF726;
  6243. t['amsquare'] = 0x33C2;
  6244. t['anbopomofo'] = 0x3122;
  6245. t['angbopomofo'] = 0x3124;
  6246. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  6247. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  6248. t['angkhankhuthai'] = 0x0E5A;
  6249. t['angle'] = 0x2220;
  6250. t['anglebracketleft'] = 0x3008;
  6251. t['anglebracketleftvertical'] = 0xFE3F;
  6252. t['anglebracketright'] = 0x3009;
  6253. t['anglebracketrightvertical'] = 0xFE40;
  6254. t['angleleft'] = 0x2329;
  6255. t['angleright'] = 0x232A;
  6256. t['angstrom'] = 0x212B;
  6257. t['anoteleia'] = 0x0387;
  6258. t['anudattadeva'] = 0x0952;
  6259. t['anusvarabengali'] = 0x0982;
  6260. t['anusvaradeva'] = 0x0902;
  6261. t['anusvaragujarati'] = 0x0A82;
  6262. t['aogonek'] = 0x0105;
  6263. t['apaatosquare'] = 0x3300;
  6264. t['aparen'] = 0x249C;
  6265. t['apostrophearmenian'] = 0x055A;
  6266. t['apostrophemod'] = 0x02BC;
  6267. t['apple'] = 0xF8FF;
  6268. t['approaches'] = 0x2250;
  6269. t['approxequal'] = 0x2248;
  6270. t['approxequalorimage'] = 0x2252;
  6271. t['approximatelyequal'] = 0x2245;
  6272. t['araeaekorean'] = 0x318E;
  6273. t['araeakorean'] = 0x318D;
  6274. t['arc'] = 0x2312;
  6275. t['arighthalfring'] = 0x1E9A;
  6276. t['aring'] = 0x00E5;
  6277. t['aringacute'] = 0x01FB;
  6278. t['aringbelow'] = 0x1E01;
  6279. t['arrowboth'] = 0x2194;
  6280. t['arrowdashdown'] = 0x21E3;
  6281. t['arrowdashleft'] = 0x21E0;
  6282. t['arrowdashright'] = 0x21E2;
  6283. t['arrowdashup'] = 0x21E1;
  6284. t['arrowdblboth'] = 0x21D4;
  6285. t['arrowdbldown'] = 0x21D3;
  6286. t['arrowdblleft'] = 0x21D0;
  6287. t['arrowdblright'] = 0x21D2;
  6288. t['arrowdblup'] = 0x21D1;
  6289. t['arrowdown'] = 0x2193;
  6290. t['arrowdownleft'] = 0x2199;
  6291. t['arrowdownright'] = 0x2198;
  6292. t['arrowdownwhite'] = 0x21E9;
  6293. t['arrowheaddownmod'] = 0x02C5;
  6294. t['arrowheadleftmod'] = 0x02C2;
  6295. t['arrowheadrightmod'] = 0x02C3;
  6296. t['arrowheadupmod'] = 0x02C4;
  6297. t['arrowhorizex'] = 0xF8E7;
  6298. t['arrowleft'] = 0x2190;
  6299. t['arrowleftdbl'] = 0x21D0;
  6300. t['arrowleftdblstroke'] = 0x21CD;
  6301. t['arrowleftoverright'] = 0x21C6;
  6302. t['arrowleftwhite'] = 0x21E6;
  6303. t['arrowright'] = 0x2192;
  6304. t['arrowrightdblstroke'] = 0x21CF;
  6305. t['arrowrightheavy'] = 0x279E;
  6306. t['arrowrightoverleft'] = 0x21C4;
  6307. t['arrowrightwhite'] = 0x21E8;
  6308. t['arrowtableft'] = 0x21E4;
  6309. t['arrowtabright'] = 0x21E5;
  6310. t['arrowup'] = 0x2191;
  6311. t['arrowupdn'] = 0x2195;
  6312. t['arrowupdnbse'] = 0x21A8;
  6313. t['arrowupdownbase'] = 0x21A8;
  6314. t['arrowupleft'] = 0x2196;
  6315. t['arrowupleftofdown'] = 0x21C5;
  6316. t['arrowupright'] = 0x2197;
  6317. t['arrowupwhite'] = 0x21E7;
  6318. t['arrowvertex'] = 0xF8E6;
  6319. t['asciicircum'] = 0x005E;
  6320. t['asciicircummonospace'] = 0xFF3E;
  6321. t['asciitilde'] = 0x007E;
  6322. t['asciitildemonospace'] = 0xFF5E;
  6323. t['ascript'] = 0x0251;
  6324. t['ascriptturned'] = 0x0252;
  6325. t['asmallhiragana'] = 0x3041;
  6326. t['asmallkatakana'] = 0x30A1;
  6327. t['asmallkatakanahalfwidth'] = 0xFF67;
  6328. t['asterisk'] = 0x002A;
  6329. t['asteriskaltonearabic'] = 0x066D;
  6330. t['asteriskarabic'] = 0x066D;
  6331. t['asteriskmath'] = 0x2217;
  6332. t['asteriskmonospace'] = 0xFF0A;
  6333. t['asterisksmall'] = 0xFE61;
  6334. t['asterism'] = 0x2042;
  6335. t['asuperior'] = 0xF6E9;
  6336. t['asymptoticallyequal'] = 0x2243;
  6337. t['at'] = 0x0040;
  6338. t['atilde'] = 0x00E3;
  6339. t['atmonospace'] = 0xFF20;
  6340. t['atsmall'] = 0xFE6B;
  6341. t['aturned'] = 0x0250;
  6342. t['aubengali'] = 0x0994;
  6343. t['aubopomofo'] = 0x3120;
  6344. t['audeva'] = 0x0914;
  6345. t['augujarati'] = 0x0A94;
  6346. t['augurmukhi'] = 0x0A14;
  6347. t['aulengthmarkbengali'] = 0x09D7;
  6348. t['aumatragurmukhi'] = 0x0A4C;
  6349. t['auvowelsignbengali'] = 0x09CC;
  6350. t['auvowelsigndeva'] = 0x094C;
  6351. t['auvowelsigngujarati'] = 0x0ACC;
  6352. t['avagrahadeva'] = 0x093D;
  6353. t['aybarmenian'] = 0x0561;
  6354. t['ayin'] = 0x05E2;
  6355. t['ayinaltonehebrew'] = 0xFB20;
  6356. t['ayinhebrew'] = 0x05E2;
  6357. t['b'] = 0x0062;
  6358. t['babengali'] = 0x09AC;
  6359. t['backslash'] = 0x005C;
  6360. t['backslashmonospace'] = 0xFF3C;
  6361. t['badeva'] = 0x092C;
  6362. t['bagujarati'] = 0x0AAC;
  6363. t['bagurmukhi'] = 0x0A2C;
  6364. t['bahiragana'] = 0x3070;
  6365. t['bahtthai'] = 0x0E3F;
  6366. t['bakatakana'] = 0x30D0;
  6367. t['bar'] = 0x007C;
  6368. t['barmonospace'] = 0xFF5C;
  6369. t['bbopomofo'] = 0x3105;
  6370. t['bcircle'] = 0x24D1;
  6371. t['bdotaccent'] = 0x1E03;
  6372. t['bdotbelow'] = 0x1E05;
  6373. t['beamedsixteenthnotes'] = 0x266C;
  6374. t['because'] = 0x2235;
  6375. t['becyrillic'] = 0x0431;
  6376. t['beharabic'] = 0x0628;
  6377. t['behfinalarabic'] = 0xFE90;
  6378. t['behinitialarabic'] = 0xFE91;
  6379. t['behiragana'] = 0x3079;
  6380. t['behmedialarabic'] = 0xFE92;
  6381. t['behmeeminitialarabic'] = 0xFC9F;
  6382. t['behmeemisolatedarabic'] = 0xFC08;
  6383. t['behnoonfinalarabic'] = 0xFC6D;
  6384. t['bekatakana'] = 0x30D9;
  6385. t['benarmenian'] = 0x0562;
  6386. t['bet'] = 0x05D1;
  6387. t['beta'] = 0x03B2;
  6388. t['betasymbolgreek'] = 0x03D0;
  6389. t['betdagesh'] = 0xFB31;
  6390. t['betdageshhebrew'] = 0xFB31;
  6391. t['bethebrew'] = 0x05D1;
  6392. t['betrafehebrew'] = 0xFB4C;
  6393. t['bhabengali'] = 0x09AD;
  6394. t['bhadeva'] = 0x092D;
  6395. t['bhagujarati'] = 0x0AAD;
  6396. t['bhagurmukhi'] = 0x0A2D;
  6397. t['bhook'] = 0x0253;
  6398. t['bihiragana'] = 0x3073;
  6399. t['bikatakana'] = 0x30D3;
  6400. t['bilabialclick'] = 0x0298;
  6401. t['bindigurmukhi'] = 0x0A02;
  6402. t['birusquare'] = 0x3331;
  6403. t['blackcircle'] = 0x25CF;
  6404. t['blackdiamond'] = 0x25C6;
  6405. t['blackdownpointingtriangle'] = 0x25BC;
  6406. t['blackleftpointingpointer'] = 0x25C4;
  6407. t['blackleftpointingtriangle'] = 0x25C0;
  6408. t['blacklenticularbracketleft'] = 0x3010;
  6409. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  6410. t['blacklenticularbracketright'] = 0x3011;
  6411. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  6412. t['blacklowerlefttriangle'] = 0x25E3;
  6413. t['blacklowerrighttriangle'] = 0x25E2;
  6414. t['blackrectangle'] = 0x25AC;
  6415. t['blackrightpointingpointer'] = 0x25BA;
  6416. t['blackrightpointingtriangle'] = 0x25B6;
  6417. t['blacksmallsquare'] = 0x25AA;
  6418. t['blacksmilingface'] = 0x263B;
  6419. t['blacksquare'] = 0x25A0;
  6420. t['blackstar'] = 0x2605;
  6421. t['blackupperlefttriangle'] = 0x25E4;
  6422. t['blackupperrighttriangle'] = 0x25E5;
  6423. t['blackuppointingsmalltriangle'] = 0x25B4;
  6424. t['blackuppointingtriangle'] = 0x25B2;
  6425. t['blank'] = 0x2423;
  6426. t['blinebelow'] = 0x1E07;
  6427. t['block'] = 0x2588;
  6428. t['bmonospace'] = 0xFF42;
  6429. t['bobaimaithai'] = 0x0E1A;
  6430. t['bohiragana'] = 0x307C;
  6431. t['bokatakana'] = 0x30DC;
  6432. t['bparen'] = 0x249D;
  6433. t['bqsquare'] = 0x33C3;
  6434. t['braceex'] = 0xF8F4;
  6435. t['braceleft'] = 0x007B;
  6436. t['braceleftbt'] = 0xF8F3;
  6437. t['braceleftmid'] = 0xF8F2;
  6438. t['braceleftmonospace'] = 0xFF5B;
  6439. t['braceleftsmall'] = 0xFE5B;
  6440. t['bracelefttp'] = 0xF8F1;
  6441. t['braceleftvertical'] = 0xFE37;
  6442. t['braceright'] = 0x007D;
  6443. t['bracerightbt'] = 0xF8FE;
  6444. t['bracerightmid'] = 0xF8FD;
  6445. t['bracerightmonospace'] = 0xFF5D;
  6446. t['bracerightsmall'] = 0xFE5C;
  6447. t['bracerighttp'] = 0xF8FC;
  6448. t['bracerightvertical'] = 0xFE38;
  6449. t['bracketleft'] = 0x005B;
  6450. t['bracketleftbt'] = 0xF8F0;
  6451. t['bracketleftex'] = 0xF8EF;
  6452. t['bracketleftmonospace'] = 0xFF3B;
  6453. t['bracketlefttp'] = 0xF8EE;
  6454. t['bracketright'] = 0x005D;
  6455. t['bracketrightbt'] = 0xF8FB;
  6456. t['bracketrightex'] = 0xF8FA;
  6457. t['bracketrightmonospace'] = 0xFF3D;
  6458. t['bracketrighttp'] = 0xF8F9;
  6459. t['breve'] = 0x02D8;
  6460. t['brevebelowcmb'] = 0x032E;
  6461. t['brevecmb'] = 0x0306;
  6462. t['breveinvertedbelowcmb'] = 0x032F;
  6463. t['breveinvertedcmb'] = 0x0311;
  6464. t['breveinverteddoublecmb'] = 0x0361;
  6465. t['bridgebelowcmb'] = 0x032A;
  6466. t['bridgeinvertedbelowcmb'] = 0x033A;
  6467. t['brokenbar'] = 0x00A6;
  6468. t['bstroke'] = 0x0180;
  6469. t['bsuperior'] = 0xF6EA;
  6470. t['btopbar'] = 0x0183;
  6471. t['buhiragana'] = 0x3076;
  6472. t['bukatakana'] = 0x30D6;
  6473. t['bullet'] = 0x2022;
  6474. t['bulletinverse'] = 0x25D8;
  6475. t['bulletoperator'] = 0x2219;
  6476. t['bullseye'] = 0x25CE;
  6477. t['c'] = 0x0063;
  6478. t['caarmenian'] = 0x056E;
  6479. t['cabengali'] = 0x099A;
  6480. t['cacute'] = 0x0107;
  6481. t['cadeva'] = 0x091A;
  6482. t['cagujarati'] = 0x0A9A;
  6483. t['cagurmukhi'] = 0x0A1A;
  6484. t['calsquare'] = 0x3388;
  6485. t['candrabindubengali'] = 0x0981;
  6486. t['candrabinducmb'] = 0x0310;
  6487. t['candrabindudeva'] = 0x0901;
  6488. t['candrabindugujarati'] = 0x0A81;
  6489. t['capslock'] = 0x21EA;
  6490. t['careof'] = 0x2105;
  6491. t['caron'] = 0x02C7;
  6492. t['caronbelowcmb'] = 0x032C;
  6493. t['caroncmb'] = 0x030C;
  6494. t['carriagereturn'] = 0x21B5;
  6495. t['cbopomofo'] = 0x3118;
  6496. t['ccaron'] = 0x010D;
  6497. t['ccedilla'] = 0x00E7;
  6498. t['ccedillaacute'] = 0x1E09;
  6499. t['ccircle'] = 0x24D2;
  6500. t['ccircumflex'] = 0x0109;
  6501. t['ccurl'] = 0x0255;
  6502. t['cdot'] = 0x010B;
  6503. t['cdotaccent'] = 0x010B;
  6504. t['cdsquare'] = 0x33C5;
  6505. t['cedilla'] = 0x00B8;
  6506. t['cedillacmb'] = 0x0327;
  6507. t['cent'] = 0x00A2;
  6508. t['centigrade'] = 0x2103;
  6509. t['centinferior'] = 0xF6DF;
  6510. t['centmonospace'] = 0xFFE0;
  6511. t['centoldstyle'] = 0xF7A2;
  6512. t['centsuperior'] = 0xF6E0;
  6513. t['chaarmenian'] = 0x0579;
  6514. t['chabengali'] = 0x099B;
  6515. t['chadeva'] = 0x091B;
  6516. t['chagujarati'] = 0x0A9B;
  6517. t['chagurmukhi'] = 0x0A1B;
  6518. t['chbopomofo'] = 0x3114;
  6519. t['cheabkhasiancyrillic'] = 0x04BD;
  6520. t['checkmark'] = 0x2713;
  6521. t['checyrillic'] = 0x0447;
  6522. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6523. t['chedescendercyrillic'] = 0x04B7;
  6524. t['chedieresiscyrillic'] = 0x04F5;
  6525. t['cheharmenian'] = 0x0573;
  6526. t['chekhakassiancyrillic'] = 0x04CC;
  6527. t['cheverticalstrokecyrillic'] = 0x04B9;
  6528. t['chi'] = 0x03C7;
  6529. t['chieuchacirclekorean'] = 0x3277;
  6530. t['chieuchaparenkorean'] = 0x3217;
  6531. t['chieuchcirclekorean'] = 0x3269;
  6532. t['chieuchkorean'] = 0x314A;
  6533. t['chieuchparenkorean'] = 0x3209;
  6534. t['chochangthai'] = 0x0E0A;
  6535. t['chochanthai'] = 0x0E08;
  6536. t['chochingthai'] = 0x0E09;
  6537. t['chochoethai'] = 0x0E0C;
  6538. t['chook'] = 0x0188;
  6539. t['cieucacirclekorean'] = 0x3276;
  6540. t['cieucaparenkorean'] = 0x3216;
  6541. t['cieuccirclekorean'] = 0x3268;
  6542. t['cieuckorean'] = 0x3148;
  6543. t['cieucparenkorean'] = 0x3208;
  6544. t['cieucuparenkorean'] = 0x321C;
  6545. t['circle'] = 0x25CB;
  6546. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6547. t['circlemultiply'] = 0x2297;
  6548. t['circleot'] = 0x2299;
  6549. t['circleplus'] = 0x2295;
  6550. t['circlepostalmark'] = 0x3036;
  6551. t['circlewithlefthalfblack'] = 0x25D0;
  6552. t['circlewithrighthalfblack'] = 0x25D1;
  6553. t['circumflex'] = 0x02C6;
  6554. t['circumflexbelowcmb'] = 0x032D;
  6555. t['circumflexcmb'] = 0x0302;
  6556. t['clear'] = 0x2327;
  6557. t['clickalveolar'] = 0x01C2;
  6558. t['clickdental'] = 0x01C0;
  6559. t['clicklateral'] = 0x01C1;
  6560. t['clickretroflex'] = 0x01C3;
  6561. t['club'] = 0x2663;
  6562. t['clubsuitblack'] = 0x2663;
  6563. t['clubsuitwhite'] = 0x2667;
  6564. t['cmcubedsquare'] = 0x33A4;
  6565. t['cmonospace'] = 0xFF43;
  6566. t['cmsquaredsquare'] = 0x33A0;
  6567. t['coarmenian'] = 0x0581;
  6568. t['colon'] = 0x003A;
  6569. t['colonmonetary'] = 0x20A1;
  6570. t['colonmonospace'] = 0xFF1A;
  6571. t['colonsign'] = 0x20A1;
  6572. t['colonsmall'] = 0xFE55;
  6573. t['colontriangularhalfmod'] = 0x02D1;
  6574. t['colontriangularmod'] = 0x02D0;
  6575. t['comma'] = 0x002C;
  6576. t['commaabovecmb'] = 0x0313;
  6577. t['commaaboverightcmb'] = 0x0315;
  6578. t['commaaccent'] = 0xF6C3;
  6579. t['commaarabic'] = 0x060C;
  6580. t['commaarmenian'] = 0x055D;
  6581. t['commainferior'] = 0xF6E1;
  6582. t['commamonospace'] = 0xFF0C;
  6583. t['commareversedabovecmb'] = 0x0314;
  6584. t['commareversedmod'] = 0x02BD;
  6585. t['commasmall'] = 0xFE50;
  6586. t['commasuperior'] = 0xF6E2;
  6587. t['commaturnedabovecmb'] = 0x0312;
  6588. t['commaturnedmod'] = 0x02BB;
  6589. t['compass'] = 0x263C;
  6590. t['congruent'] = 0x2245;
  6591. t['contourintegral'] = 0x222E;
  6592. t['control'] = 0x2303;
  6593. t['controlACK'] = 0x0006;
  6594. t['controlBEL'] = 0x0007;
  6595. t['controlBS'] = 0x0008;
  6596. t['controlCAN'] = 0x0018;
  6597. t['controlCR'] = 0x000D;
  6598. t['controlDC1'] = 0x0011;
  6599. t['controlDC2'] = 0x0012;
  6600. t['controlDC3'] = 0x0013;
  6601. t['controlDC4'] = 0x0014;
  6602. t['controlDEL'] = 0x007F;
  6603. t['controlDLE'] = 0x0010;
  6604. t['controlEM'] = 0x0019;
  6605. t['controlENQ'] = 0x0005;
  6606. t['controlEOT'] = 0x0004;
  6607. t['controlESC'] = 0x001B;
  6608. t['controlETB'] = 0x0017;
  6609. t['controlETX'] = 0x0003;
  6610. t['controlFF'] = 0x000C;
  6611. t['controlFS'] = 0x001C;
  6612. t['controlGS'] = 0x001D;
  6613. t['controlHT'] = 0x0009;
  6614. t['controlLF'] = 0x000A;
  6615. t['controlNAK'] = 0x0015;
  6616. t['controlRS'] = 0x001E;
  6617. t['controlSI'] = 0x000F;
  6618. t['controlSO'] = 0x000E;
  6619. t['controlSOT'] = 0x0002;
  6620. t['controlSTX'] = 0x0001;
  6621. t['controlSUB'] = 0x001A;
  6622. t['controlSYN'] = 0x0016;
  6623. t['controlUS'] = 0x001F;
  6624. t['controlVT'] = 0x000B;
  6625. t['copyright'] = 0x00A9;
  6626. t['copyrightsans'] = 0xF8E9;
  6627. t['copyrightserif'] = 0xF6D9;
  6628. t['cornerbracketleft'] = 0x300C;
  6629. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6630. t['cornerbracketleftvertical'] = 0xFE41;
  6631. t['cornerbracketright'] = 0x300D;
  6632. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6633. t['cornerbracketrightvertical'] = 0xFE42;
  6634. t['corporationsquare'] = 0x337F;
  6635. t['cosquare'] = 0x33C7;
  6636. t['coverkgsquare'] = 0x33C6;
  6637. t['cparen'] = 0x249E;
  6638. t['cruzeiro'] = 0x20A2;
  6639. t['cstretched'] = 0x0297;
  6640. t['curlyand'] = 0x22CF;
  6641. t['curlyor'] = 0x22CE;
  6642. t['currency'] = 0x00A4;
  6643. t['cyrBreve'] = 0xF6D1;
  6644. t['cyrFlex'] = 0xF6D2;
  6645. t['cyrbreve'] = 0xF6D4;
  6646. t['cyrflex'] = 0xF6D5;
  6647. t['d'] = 0x0064;
  6648. t['daarmenian'] = 0x0564;
  6649. t['dabengali'] = 0x09A6;
  6650. t['dadarabic'] = 0x0636;
  6651. t['dadeva'] = 0x0926;
  6652. t['dadfinalarabic'] = 0xFEBE;
  6653. t['dadinitialarabic'] = 0xFEBF;
  6654. t['dadmedialarabic'] = 0xFEC0;
  6655. t['dagesh'] = 0x05BC;
  6656. t['dageshhebrew'] = 0x05BC;
  6657. t['dagger'] = 0x2020;
  6658. t['daggerdbl'] = 0x2021;
  6659. t['dagujarati'] = 0x0AA6;
  6660. t['dagurmukhi'] = 0x0A26;
  6661. t['dahiragana'] = 0x3060;
  6662. t['dakatakana'] = 0x30C0;
  6663. t['dalarabic'] = 0x062F;
  6664. t['dalet'] = 0x05D3;
  6665. t['daletdagesh'] = 0xFB33;
  6666. t['daletdageshhebrew'] = 0xFB33;
  6667. t['dalethebrew'] = 0x05D3;
  6668. t['dalfinalarabic'] = 0xFEAA;
  6669. t['dammaarabic'] = 0x064F;
  6670. t['dammalowarabic'] = 0x064F;
  6671. t['dammatanaltonearabic'] = 0x064C;
  6672. t['dammatanarabic'] = 0x064C;
  6673. t['danda'] = 0x0964;
  6674. t['dargahebrew'] = 0x05A7;
  6675. t['dargalefthebrew'] = 0x05A7;
  6676. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6677. t['dblGrave'] = 0xF6D3;
  6678. t['dblanglebracketleft'] = 0x300A;
  6679. t['dblanglebracketleftvertical'] = 0xFE3D;
  6680. t['dblanglebracketright'] = 0x300B;
  6681. t['dblanglebracketrightvertical'] = 0xFE3E;
  6682. t['dblarchinvertedbelowcmb'] = 0x032B;
  6683. t['dblarrowleft'] = 0x21D4;
  6684. t['dblarrowright'] = 0x21D2;
  6685. t['dbldanda'] = 0x0965;
  6686. t['dblgrave'] = 0xF6D6;
  6687. t['dblgravecmb'] = 0x030F;
  6688. t['dblintegral'] = 0x222C;
  6689. t['dbllowline'] = 0x2017;
  6690. t['dbllowlinecmb'] = 0x0333;
  6691. t['dbloverlinecmb'] = 0x033F;
  6692. t['dblprimemod'] = 0x02BA;
  6693. t['dblverticalbar'] = 0x2016;
  6694. t['dblverticallineabovecmb'] = 0x030E;
  6695. t['dbopomofo'] = 0x3109;
  6696. t['dbsquare'] = 0x33C8;
  6697. t['dcaron'] = 0x010F;
  6698. t['dcedilla'] = 0x1E11;
  6699. t['dcircle'] = 0x24D3;
  6700. t['dcircumflexbelow'] = 0x1E13;
  6701. t['dcroat'] = 0x0111;
  6702. t['ddabengali'] = 0x09A1;
  6703. t['ddadeva'] = 0x0921;
  6704. t['ddagujarati'] = 0x0AA1;
  6705. t['ddagurmukhi'] = 0x0A21;
  6706. t['ddalarabic'] = 0x0688;
  6707. t['ddalfinalarabic'] = 0xFB89;
  6708. t['dddhadeva'] = 0x095C;
  6709. t['ddhabengali'] = 0x09A2;
  6710. t['ddhadeva'] = 0x0922;
  6711. t['ddhagujarati'] = 0x0AA2;
  6712. t['ddhagurmukhi'] = 0x0A22;
  6713. t['ddotaccent'] = 0x1E0B;
  6714. t['ddotbelow'] = 0x1E0D;
  6715. t['decimalseparatorarabic'] = 0x066B;
  6716. t['decimalseparatorpersian'] = 0x066B;
  6717. t['decyrillic'] = 0x0434;
  6718. t['degree'] = 0x00B0;
  6719. t['dehihebrew'] = 0x05AD;
  6720. t['dehiragana'] = 0x3067;
  6721. t['deicoptic'] = 0x03EF;
  6722. t['dekatakana'] = 0x30C7;
  6723. t['deleteleft'] = 0x232B;
  6724. t['deleteright'] = 0x2326;
  6725. t['delta'] = 0x03B4;
  6726. t['deltaturned'] = 0x018D;
  6727. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6728. t['dezh'] = 0x02A4;
  6729. t['dhabengali'] = 0x09A7;
  6730. t['dhadeva'] = 0x0927;
  6731. t['dhagujarati'] = 0x0AA7;
  6732. t['dhagurmukhi'] = 0x0A27;
  6733. t['dhook'] = 0x0257;
  6734. t['dialytikatonos'] = 0x0385;
  6735. t['dialytikatonoscmb'] = 0x0344;
  6736. t['diamond'] = 0x2666;
  6737. t['diamondsuitwhite'] = 0x2662;
  6738. t['dieresis'] = 0x00A8;
  6739. t['dieresisacute'] = 0xF6D7;
  6740. t['dieresisbelowcmb'] = 0x0324;
  6741. t['dieresiscmb'] = 0x0308;
  6742. t['dieresisgrave'] = 0xF6D8;
  6743. t['dieresistonos'] = 0x0385;
  6744. t['dihiragana'] = 0x3062;
  6745. t['dikatakana'] = 0x30C2;
  6746. t['dittomark'] = 0x3003;
  6747. t['divide'] = 0x00F7;
  6748. t['divides'] = 0x2223;
  6749. t['divisionslash'] = 0x2215;
  6750. t['djecyrillic'] = 0x0452;
  6751. t['dkshade'] = 0x2593;
  6752. t['dlinebelow'] = 0x1E0F;
  6753. t['dlsquare'] = 0x3397;
  6754. t['dmacron'] = 0x0111;
  6755. t['dmonospace'] = 0xFF44;
  6756. t['dnblock'] = 0x2584;
  6757. t['dochadathai'] = 0x0E0E;
  6758. t['dodekthai'] = 0x0E14;
  6759. t['dohiragana'] = 0x3069;
  6760. t['dokatakana'] = 0x30C9;
  6761. t['dollar'] = 0x0024;
  6762. t['dollarinferior'] = 0xF6E3;
  6763. t['dollarmonospace'] = 0xFF04;
  6764. t['dollaroldstyle'] = 0xF724;
  6765. t['dollarsmall'] = 0xFE69;
  6766. t['dollarsuperior'] = 0xF6E4;
  6767. t['dong'] = 0x20AB;
  6768. t['dorusquare'] = 0x3326;
  6769. t['dotaccent'] = 0x02D9;
  6770. t['dotaccentcmb'] = 0x0307;
  6771. t['dotbelowcmb'] = 0x0323;
  6772. t['dotbelowcomb'] = 0x0323;
  6773. t['dotkatakana'] = 0x30FB;
  6774. t['dotlessi'] = 0x0131;
  6775. t['dotlessj'] = 0xF6BE;
  6776. t['dotlessjstrokehook'] = 0x0284;
  6777. t['dotmath'] = 0x22C5;
  6778. t['dottedcircle'] = 0x25CC;
  6779. t['doubleyodpatah'] = 0xFB1F;
  6780. t['doubleyodpatahhebrew'] = 0xFB1F;
  6781. t['downtackbelowcmb'] = 0x031E;
  6782. t['downtackmod'] = 0x02D5;
  6783. t['dparen'] = 0x249F;
  6784. t['dsuperior'] = 0xF6EB;
  6785. t['dtail'] = 0x0256;
  6786. t['dtopbar'] = 0x018C;
  6787. t['duhiragana'] = 0x3065;
  6788. t['dukatakana'] = 0x30C5;
  6789. t['dz'] = 0x01F3;
  6790. t['dzaltone'] = 0x02A3;
  6791. t['dzcaron'] = 0x01C6;
  6792. t['dzcurl'] = 0x02A5;
  6793. t['dzeabkhasiancyrillic'] = 0x04E1;
  6794. t['dzecyrillic'] = 0x0455;
  6795. t['dzhecyrillic'] = 0x045F;
  6796. t['e'] = 0x0065;
  6797. t['eacute'] = 0x00E9;
  6798. t['earth'] = 0x2641;
  6799. t['ebengali'] = 0x098F;
  6800. t['ebopomofo'] = 0x311C;
  6801. t['ebreve'] = 0x0115;
  6802. t['ecandradeva'] = 0x090D;
  6803. t['ecandragujarati'] = 0x0A8D;
  6804. t['ecandravowelsigndeva'] = 0x0945;
  6805. t['ecandravowelsigngujarati'] = 0x0AC5;
  6806. t['ecaron'] = 0x011B;
  6807. t['ecedillabreve'] = 0x1E1D;
  6808. t['echarmenian'] = 0x0565;
  6809. t['echyiwnarmenian'] = 0x0587;
  6810. t['ecircle'] = 0x24D4;
  6811. t['ecircumflex'] = 0x00EA;
  6812. t['ecircumflexacute'] = 0x1EBF;
  6813. t['ecircumflexbelow'] = 0x1E19;
  6814. t['ecircumflexdotbelow'] = 0x1EC7;
  6815. t['ecircumflexgrave'] = 0x1EC1;
  6816. t['ecircumflexhookabove'] = 0x1EC3;
  6817. t['ecircumflextilde'] = 0x1EC5;
  6818. t['ecyrillic'] = 0x0454;
  6819. t['edblgrave'] = 0x0205;
  6820. t['edeva'] = 0x090F;
  6821. t['edieresis'] = 0x00EB;
  6822. t['edot'] = 0x0117;
  6823. t['edotaccent'] = 0x0117;
  6824. t['edotbelow'] = 0x1EB9;
  6825. t['eegurmukhi'] = 0x0A0F;
  6826. t['eematragurmukhi'] = 0x0A47;
  6827. t['efcyrillic'] = 0x0444;
  6828. t['egrave'] = 0x00E8;
  6829. t['egujarati'] = 0x0A8F;
  6830. t['eharmenian'] = 0x0567;
  6831. t['ehbopomofo'] = 0x311D;
  6832. t['ehiragana'] = 0x3048;
  6833. t['ehookabove'] = 0x1EBB;
  6834. t['eibopomofo'] = 0x311F;
  6835. t['eight'] = 0x0038;
  6836. t['eightarabic'] = 0x0668;
  6837. t['eightbengali'] = 0x09EE;
  6838. t['eightcircle'] = 0x2467;
  6839. t['eightcircleinversesansserif'] = 0x2791;
  6840. t['eightdeva'] = 0x096E;
  6841. t['eighteencircle'] = 0x2471;
  6842. t['eighteenparen'] = 0x2485;
  6843. t['eighteenperiod'] = 0x2499;
  6844. t['eightgujarati'] = 0x0AEE;
  6845. t['eightgurmukhi'] = 0x0A6E;
  6846. t['eighthackarabic'] = 0x0668;
  6847. t['eighthangzhou'] = 0x3028;
  6848. t['eighthnotebeamed'] = 0x266B;
  6849. t['eightideographicparen'] = 0x3227;
  6850. t['eightinferior'] = 0x2088;
  6851. t['eightmonospace'] = 0xFF18;
  6852. t['eightoldstyle'] = 0xF738;
  6853. t['eightparen'] = 0x247B;
  6854. t['eightperiod'] = 0x248F;
  6855. t['eightpersian'] = 0x06F8;
  6856. t['eightroman'] = 0x2177;
  6857. t['eightsuperior'] = 0x2078;
  6858. t['eightthai'] = 0x0E58;
  6859. t['einvertedbreve'] = 0x0207;
  6860. t['eiotifiedcyrillic'] = 0x0465;
  6861. t['ekatakana'] = 0x30A8;
  6862. t['ekatakanahalfwidth'] = 0xFF74;
  6863. t['ekonkargurmukhi'] = 0x0A74;
  6864. t['ekorean'] = 0x3154;
  6865. t['elcyrillic'] = 0x043B;
  6866. t['element'] = 0x2208;
  6867. t['elevencircle'] = 0x246A;
  6868. t['elevenparen'] = 0x247E;
  6869. t['elevenperiod'] = 0x2492;
  6870. t['elevenroman'] = 0x217A;
  6871. t['ellipsis'] = 0x2026;
  6872. t['ellipsisvertical'] = 0x22EE;
  6873. t['emacron'] = 0x0113;
  6874. t['emacronacute'] = 0x1E17;
  6875. t['emacrongrave'] = 0x1E15;
  6876. t['emcyrillic'] = 0x043C;
  6877. t['emdash'] = 0x2014;
  6878. t['emdashvertical'] = 0xFE31;
  6879. t['emonospace'] = 0xFF45;
  6880. t['emphasismarkarmenian'] = 0x055B;
  6881. t['emptyset'] = 0x2205;
  6882. t['enbopomofo'] = 0x3123;
  6883. t['encyrillic'] = 0x043D;
  6884. t['endash'] = 0x2013;
  6885. t['endashvertical'] = 0xFE32;
  6886. t['endescendercyrillic'] = 0x04A3;
  6887. t['eng'] = 0x014B;
  6888. t['engbopomofo'] = 0x3125;
  6889. t['enghecyrillic'] = 0x04A5;
  6890. t['enhookcyrillic'] = 0x04C8;
  6891. t['enspace'] = 0x2002;
  6892. t['eogonek'] = 0x0119;
  6893. t['eokorean'] = 0x3153;
  6894. t['eopen'] = 0x025B;
  6895. t['eopenclosed'] = 0x029A;
  6896. t['eopenreversed'] = 0x025C;
  6897. t['eopenreversedclosed'] = 0x025E;
  6898. t['eopenreversedhook'] = 0x025D;
  6899. t['eparen'] = 0x24A0;
  6900. t['epsilon'] = 0x03B5;
  6901. t['epsilontonos'] = 0x03AD;
  6902. t['equal'] = 0x003D;
  6903. t['equalmonospace'] = 0xFF1D;
  6904. t['equalsmall'] = 0xFE66;
  6905. t['equalsuperior'] = 0x207C;
  6906. t['equivalence'] = 0x2261;
  6907. t['erbopomofo'] = 0x3126;
  6908. t['ercyrillic'] = 0x0440;
  6909. t['ereversed'] = 0x0258;
  6910. t['ereversedcyrillic'] = 0x044D;
  6911. t['escyrillic'] = 0x0441;
  6912. t['esdescendercyrillic'] = 0x04AB;
  6913. t['esh'] = 0x0283;
  6914. t['eshcurl'] = 0x0286;
  6915. t['eshortdeva'] = 0x090E;
  6916. t['eshortvowelsigndeva'] = 0x0946;
  6917. t['eshreversedloop'] = 0x01AA;
  6918. t['eshsquatreversed'] = 0x0285;
  6919. t['esmallhiragana'] = 0x3047;
  6920. t['esmallkatakana'] = 0x30A7;
  6921. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6922. t['estimated'] = 0x212E;
  6923. t['esuperior'] = 0xF6EC;
  6924. t['eta'] = 0x03B7;
  6925. t['etarmenian'] = 0x0568;
  6926. t['etatonos'] = 0x03AE;
  6927. t['eth'] = 0x00F0;
  6928. t['etilde'] = 0x1EBD;
  6929. t['etildebelow'] = 0x1E1B;
  6930. t['etnahtafoukhhebrew'] = 0x0591;
  6931. t['etnahtafoukhlefthebrew'] = 0x0591;
  6932. t['etnahtahebrew'] = 0x0591;
  6933. t['etnahtalefthebrew'] = 0x0591;
  6934. t['eturned'] = 0x01DD;
  6935. t['eukorean'] = 0x3161;
  6936. t['euro'] = 0x20AC;
  6937. t['evowelsignbengali'] = 0x09C7;
  6938. t['evowelsigndeva'] = 0x0947;
  6939. t['evowelsigngujarati'] = 0x0AC7;
  6940. t['exclam'] = 0x0021;
  6941. t['exclamarmenian'] = 0x055C;
  6942. t['exclamdbl'] = 0x203C;
  6943. t['exclamdown'] = 0x00A1;
  6944. t['exclamdownsmall'] = 0xF7A1;
  6945. t['exclammonospace'] = 0xFF01;
  6946. t['exclamsmall'] = 0xF721;
  6947. t['existential'] = 0x2203;
  6948. t['ezh'] = 0x0292;
  6949. t['ezhcaron'] = 0x01EF;
  6950. t['ezhcurl'] = 0x0293;
  6951. t['ezhreversed'] = 0x01B9;
  6952. t['ezhtail'] = 0x01BA;
  6953. t['f'] = 0x0066;
  6954. t['fadeva'] = 0x095E;
  6955. t['fagurmukhi'] = 0x0A5E;
  6956. t['fahrenheit'] = 0x2109;
  6957. t['fathaarabic'] = 0x064E;
  6958. t['fathalowarabic'] = 0x064E;
  6959. t['fathatanarabic'] = 0x064B;
  6960. t['fbopomofo'] = 0x3108;
  6961. t['fcircle'] = 0x24D5;
  6962. t['fdotaccent'] = 0x1E1F;
  6963. t['feharabic'] = 0x0641;
  6964. t['feharmenian'] = 0x0586;
  6965. t['fehfinalarabic'] = 0xFED2;
  6966. t['fehinitialarabic'] = 0xFED3;
  6967. t['fehmedialarabic'] = 0xFED4;
  6968. t['feicoptic'] = 0x03E5;
  6969. t['female'] = 0x2640;
  6970. t['ff'] = 0xFB00;
  6971. t['ffi'] = 0xFB03;
  6972. t['ffl'] = 0xFB04;
  6973. t['fi'] = 0xFB01;
  6974. t['fifteencircle'] = 0x246E;
  6975. t['fifteenparen'] = 0x2482;
  6976. t['fifteenperiod'] = 0x2496;
  6977. t['figuredash'] = 0x2012;
  6978. t['filledbox'] = 0x25A0;
  6979. t['filledrect'] = 0x25AC;
  6980. t['finalkaf'] = 0x05DA;
  6981. t['finalkafdagesh'] = 0xFB3A;
  6982. t['finalkafdageshhebrew'] = 0xFB3A;
  6983. t['finalkafhebrew'] = 0x05DA;
  6984. t['finalmem'] = 0x05DD;
  6985. t['finalmemhebrew'] = 0x05DD;
  6986. t['finalnun'] = 0x05DF;
  6987. t['finalnunhebrew'] = 0x05DF;
  6988. t['finalpe'] = 0x05E3;
  6989. t['finalpehebrew'] = 0x05E3;
  6990. t['finaltsadi'] = 0x05E5;
  6991. t['finaltsadihebrew'] = 0x05E5;
  6992. t['firsttonechinese'] = 0x02C9;
  6993. t['fisheye'] = 0x25C9;
  6994. t['fitacyrillic'] = 0x0473;
  6995. t['five'] = 0x0035;
  6996. t['fivearabic'] = 0x0665;
  6997. t['fivebengali'] = 0x09EB;
  6998. t['fivecircle'] = 0x2464;
  6999. t['fivecircleinversesansserif'] = 0x278E;
  7000. t['fivedeva'] = 0x096B;
  7001. t['fiveeighths'] = 0x215D;
  7002. t['fivegujarati'] = 0x0AEB;
  7003. t['fivegurmukhi'] = 0x0A6B;
  7004. t['fivehackarabic'] = 0x0665;
  7005. t['fivehangzhou'] = 0x3025;
  7006. t['fiveideographicparen'] = 0x3224;
  7007. t['fiveinferior'] = 0x2085;
  7008. t['fivemonospace'] = 0xFF15;
  7009. t['fiveoldstyle'] = 0xF735;
  7010. t['fiveparen'] = 0x2478;
  7011. t['fiveperiod'] = 0x248C;
  7012. t['fivepersian'] = 0x06F5;
  7013. t['fiveroman'] = 0x2174;
  7014. t['fivesuperior'] = 0x2075;
  7015. t['fivethai'] = 0x0E55;
  7016. t['fl'] = 0xFB02;
  7017. t['florin'] = 0x0192;
  7018. t['fmonospace'] = 0xFF46;
  7019. t['fmsquare'] = 0x3399;
  7020. t['fofanthai'] = 0x0E1F;
  7021. t['fofathai'] = 0x0E1D;
  7022. t['fongmanthai'] = 0x0E4F;
  7023. t['forall'] = 0x2200;
  7024. t['four'] = 0x0034;
  7025. t['fourarabic'] = 0x0664;
  7026. t['fourbengali'] = 0x09EA;
  7027. t['fourcircle'] = 0x2463;
  7028. t['fourcircleinversesansserif'] = 0x278D;
  7029. t['fourdeva'] = 0x096A;
  7030. t['fourgujarati'] = 0x0AEA;
  7031. t['fourgurmukhi'] = 0x0A6A;
  7032. t['fourhackarabic'] = 0x0664;
  7033. t['fourhangzhou'] = 0x3024;
  7034. t['fourideographicparen'] = 0x3223;
  7035. t['fourinferior'] = 0x2084;
  7036. t['fourmonospace'] = 0xFF14;
  7037. t['fournumeratorbengali'] = 0x09F7;
  7038. t['fouroldstyle'] = 0xF734;
  7039. t['fourparen'] = 0x2477;
  7040. t['fourperiod'] = 0x248B;
  7041. t['fourpersian'] = 0x06F4;
  7042. t['fourroman'] = 0x2173;
  7043. t['foursuperior'] = 0x2074;
  7044. t['fourteencircle'] = 0x246D;
  7045. t['fourteenparen'] = 0x2481;
  7046. t['fourteenperiod'] = 0x2495;
  7047. t['fourthai'] = 0x0E54;
  7048. t['fourthtonechinese'] = 0x02CB;
  7049. t['fparen'] = 0x24A1;
  7050. t['fraction'] = 0x2044;
  7051. t['franc'] = 0x20A3;
  7052. t['g'] = 0x0067;
  7053. t['gabengali'] = 0x0997;
  7054. t['gacute'] = 0x01F5;
  7055. t['gadeva'] = 0x0917;
  7056. t['gafarabic'] = 0x06AF;
  7057. t['gaffinalarabic'] = 0xFB93;
  7058. t['gafinitialarabic'] = 0xFB94;
  7059. t['gafmedialarabic'] = 0xFB95;
  7060. t['gagujarati'] = 0x0A97;
  7061. t['gagurmukhi'] = 0x0A17;
  7062. t['gahiragana'] = 0x304C;
  7063. t['gakatakana'] = 0x30AC;
  7064. t['gamma'] = 0x03B3;
  7065. t['gammalatinsmall'] = 0x0263;
  7066. t['gammasuperior'] = 0x02E0;
  7067. t['gangiacoptic'] = 0x03EB;
  7068. t['gbopomofo'] = 0x310D;
  7069. t['gbreve'] = 0x011F;
  7070. t['gcaron'] = 0x01E7;
  7071. t['gcedilla'] = 0x0123;
  7072. t['gcircle'] = 0x24D6;
  7073. t['gcircumflex'] = 0x011D;
  7074. t['gcommaaccent'] = 0x0123;
  7075. t['gdot'] = 0x0121;
  7076. t['gdotaccent'] = 0x0121;
  7077. t['gecyrillic'] = 0x0433;
  7078. t['gehiragana'] = 0x3052;
  7079. t['gekatakana'] = 0x30B2;
  7080. t['geometricallyequal'] = 0x2251;
  7081. t['gereshaccenthebrew'] = 0x059C;
  7082. t['gereshhebrew'] = 0x05F3;
  7083. t['gereshmuqdamhebrew'] = 0x059D;
  7084. t['germandbls'] = 0x00DF;
  7085. t['gershayimaccenthebrew'] = 0x059E;
  7086. t['gershayimhebrew'] = 0x05F4;
  7087. t['getamark'] = 0x3013;
  7088. t['ghabengali'] = 0x0998;
  7089. t['ghadarmenian'] = 0x0572;
  7090. t['ghadeva'] = 0x0918;
  7091. t['ghagujarati'] = 0x0A98;
  7092. t['ghagurmukhi'] = 0x0A18;
  7093. t['ghainarabic'] = 0x063A;
  7094. t['ghainfinalarabic'] = 0xFECE;
  7095. t['ghaininitialarabic'] = 0xFECF;
  7096. t['ghainmedialarabic'] = 0xFED0;
  7097. t['ghemiddlehookcyrillic'] = 0x0495;
  7098. t['ghestrokecyrillic'] = 0x0493;
  7099. t['gheupturncyrillic'] = 0x0491;
  7100. t['ghhadeva'] = 0x095A;
  7101. t['ghhagurmukhi'] = 0x0A5A;
  7102. t['ghook'] = 0x0260;
  7103. t['ghzsquare'] = 0x3393;
  7104. t['gihiragana'] = 0x304E;
  7105. t['gikatakana'] = 0x30AE;
  7106. t['gimarmenian'] = 0x0563;
  7107. t['gimel'] = 0x05D2;
  7108. t['gimeldagesh'] = 0xFB32;
  7109. t['gimeldageshhebrew'] = 0xFB32;
  7110. t['gimelhebrew'] = 0x05D2;
  7111. t['gjecyrillic'] = 0x0453;
  7112. t['glottalinvertedstroke'] = 0x01BE;
  7113. t['glottalstop'] = 0x0294;
  7114. t['glottalstopinverted'] = 0x0296;
  7115. t['glottalstopmod'] = 0x02C0;
  7116. t['glottalstopreversed'] = 0x0295;
  7117. t['glottalstopreversedmod'] = 0x02C1;
  7118. t['glottalstopreversedsuperior'] = 0x02E4;
  7119. t['glottalstopstroke'] = 0x02A1;
  7120. t['glottalstopstrokereversed'] = 0x02A2;
  7121. t['gmacron'] = 0x1E21;
  7122. t['gmonospace'] = 0xFF47;
  7123. t['gohiragana'] = 0x3054;
  7124. t['gokatakana'] = 0x30B4;
  7125. t['gparen'] = 0x24A2;
  7126. t['gpasquare'] = 0x33AC;
  7127. t['gradient'] = 0x2207;
  7128. t['grave'] = 0x0060;
  7129. t['gravebelowcmb'] = 0x0316;
  7130. t['gravecmb'] = 0x0300;
  7131. t['gravecomb'] = 0x0300;
  7132. t['gravedeva'] = 0x0953;
  7133. t['gravelowmod'] = 0x02CE;
  7134. t['gravemonospace'] = 0xFF40;
  7135. t['gravetonecmb'] = 0x0340;
  7136. t['greater'] = 0x003E;
  7137. t['greaterequal'] = 0x2265;
  7138. t['greaterequalorless'] = 0x22DB;
  7139. t['greatermonospace'] = 0xFF1E;
  7140. t['greaterorequivalent'] = 0x2273;
  7141. t['greaterorless'] = 0x2277;
  7142. t['greateroverequal'] = 0x2267;
  7143. t['greatersmall'] = 0xFE65;
  7144. t['gscript'] = 0x0261;
  7145. t['gstroke'] = 0x01E5;
  7146. t['guhiragana'] = 0x3050;
  7147. t['guillemotleft'] = 0x00AB;
  7148. t['guillemotright'] = 0x00BB;
  7149. t['guilsinglleft'] = 0x2039;
  7150. t['guilsinglright'] = 0x203A;
  7151. t['gukatakana'] = 0x30B0;
  7152. t['guramusquare'] = 0x3318;
  7153. t['gysquare'] = 0x33C9;
  7154. t['h'] = 0x0068;
  7155. t['haabkhasiancyrillic'] = 0x04A9;
  7156. t['haaltonearabic'] = 0x06C1;
  7157. t['habengali'] = 0x09B9;
  7158. t['hadescendercyrillic'] = 0x04B3;
  7159. t['hadeva'] = 0x0939;
  7160. t['hagujarati'] = 0x0AB9;
  7161. t['hagurmukhi'] = 0x0A39;
  7162. t['haharabic'] = 0x062D;
  7163. t['hahfinalarabic'] = 0xFEA2;
  7164. t['hahinitialarabic'] = 0xFEA3;
  7165. t['hahiragana'] = 0x306F;
  7166. t['hahmedialarabic'] = 0xFEA4;
  7167. t['haitusquare'] = 0x332A;
  7168. t['hakatakana'] = 0x30CF;
  7169. t['hakatakanahalfwidth'] = 0xFF8A;
  7170. t['halantgurmukhi'] = 0x0A4D;
  7171. t['hamzaarabic'] = 0x0621;
  7172. t['hamzalowarabic'] = 0x0621;
  7173. t['hangulfiller'] = 0x3164;
  7174. t['hardsigncyrillic'] = 0x044A;
  7175. t['harpoonleftbarbup'] = 0x21BC;
  7176. t['harpoonrightbarbup'] = 0x21C0;
  7177. t['hasquare'] = 0x33CA;
  7178. t['hatafpatah'] = 0x05B2;
  7179. t['hatafpatah16'] = 0x05B2;
  7180. t['hatafpatah23'] = 0x05B2;
  7181. t['hatafpatah2f'] = 0x05B2;
  7182. t['hatafpatahhebrew'] = 0x05B2;
  7183. t['hatafpatahnarrowhebrew'] = 0x05B2;
  7184. t['hatafpatahquarterhebrew'] = 0x05B2;
  7185. t['hatafpatahwidehebrew'] = 0x05B2;
  7186. t['hatafqamats'] = 0x05B3;
  7187. t['hatafqamats1b'] = 0x05B3;
  7188. t['hatafqamats28'] = 0x05B3;
  7189. t['hatafqamats34'] = 0x05B3;
  7190. t['hatafqamatshebrew'] = 0x05B3;
  7191. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  7192. t['hatafqamatsquarterhebrew'] = 0x05B3;
  7193. t['hatafqamatswidehebrew'] = 0x05B3;
  7194. t['hatafsegol'] = 0x05B1;
  7195. t['hatafsegol17'] = 0x05B1;
  7196. t['hatafsegol24'] = 0x05B1;
  7197. t['hatafsegol30'] = 0x05B1;
  7198. t['hatafsegolhebrew'] = 0x05B1;
  7199. t['hatafsegolnarrowhebrew'] = 0x05B1;
  7200. t['hatafsegolquarterhebrew'] = 0x05B1;
  7201. t['hatafsegolwidehebrew'] = 0x05B1;
  7202. t['hbar'] = 0x0127;
  7203. t['hbopomofo'] = 0x310F;
  7204. t['hbrevebelow'] = 0x1E2B;
  7205. t['hcedilla'] = 0x1E29;
  7206. t['hcircle'] = 0x24D7;
  7207. t['hcircumflex'] = 0x0125;
  7208. t['hdieresis'] = 0x1E27;
  7209. t['hdotaccent'] = 0x1E23;
  7210. t['hdotbelow'] = 0x1E25;
  7211. t['he'] = 0x05D4;
  7212. t['heart'] = 0x2665;
  7213. t['heartsuitblack'] = 0x2665;
  7214. t['heartsuitwhite'] = 0x2661;
  7215. t['hedagesh'] = 0xFB34;
  7216. t['hedageshhebrew'] = 0xFB34;
  7217. t['hehaltonearabic'] = 0x06C1;
  7218. t['heharabic'] = 0x0647;
  7219. t['hehebrew'] = 0x05D4;
  7220. t['hehfinalaltonearabic'] = 0xFBA7;
  7221. t['hehfinalalttwoarabic'] = 0xFEEA;
  7222. t['hehfinalarabic'] = 0xFEEA;
  7223. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  7224. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  7225. t['hehinitialaltonearabic'] = 0xFBA8;
  7226. t['hehinitialarabic'] = 0xFEEB;
  7227. t['hehiragana'] = 0x3078;
  7228. t['hehmedialaltonearabic'] = 0xFBA9;
  7229. t['hehmedialarabic'] = 0xFEEC;
  7230. t['heiseierasquare'] = 0x337B;
  7231. t['hekatakana'] = 0x30D8;
  7232. t['hekatakanahalfwidth'] = 0xFF8D;
  7233. t['hekutaarusquare'] = 0x3336;
  7234. t['henghook'] = 0x0267;
  7235. t['herutusquare'] = 0x3339;
  7236. t['het'] = 0x05D7;
  7237. t['hethebrew'] = 0x05D7;
  7238. t['hhook'] = 0x0266;
  7239. t['hhooksuperior'] = 0x02B1;
  7240. t['hieuhacirclekorean'] = 0x327B;
  7241. t['hieuhaparenkorean'] = 0x321B;
  7242. t['hieuhcirclekorean'] = 0x326D;
  7243. t['hieuhkorean'] = 0x314E;
  7244. t['hieuhparenkorean'] = 0x320D;
  7245. t['hihiragana'] = 0x3072;
  7246. t['hikatakana'] = 0x30D2;
  7247. t['hikatakanahalfwidth'] = 0xFF8B;
  7248. t['hiriq'] = 0x05B4;
  7249. t['hiriq14'] = 0x05B4;
  7250. t['hiriq21'] = 0x05B4;
  7251. t['hiriq2d'] = 0x05B4;
  7252. t['hiriqhebrew'] = 0x05B4;
  7253. t['hiriqnarrowhebrew'] = 0x05B4;
  7254. t['hiriqquarterhebrew'] = 0x05B4;
  7255. t['hiriqwidehebrew'] = 0x05B4;
  7256. t['hlinebelow'] = 0x1E96;
  7257. t['hmonospace'] = 0xFF48;
  7258. t['hoarmenian'] = 0x0570;
  7259. t['hohipthai'] = 0x0E2B;
  7260. t['hohiragana'] = 0x307B;
  7261. t['hokatakana'] = 0x30DB;
  7262. t['hokatakanahalfwidth'] = 0xFF8E;
  7263. t['holam'] = 0x05B9;
  7264. t['holam19'] = 0x05B9;
  7265. t['holam26'] = 0x05B9;
  7266. t['holam32'] = 0x05B9;
  7267. t['holamhebrew'] = 0x05B9;
  7268. t['holamnarrowhebrew'] = 0x05B9;
  7269. t['holamquarterhebrew'] = 0x05B9;
  7270. t['holamwidehebrew'] = 0x05B9;
  7271. t['honokhukthai'] = 0x0E2E;
  7272. t['hookabovecomb'] = 0x0309;
  7273. t['hookcmb'] = 0x0309;
  7274. t['hookpalatalizedbelowcmb'] = 0x0321;
  7275. t['hookretroflexbelowcmb'] = 0x0322;
  7276. t['hoonsquare'] = 0x3342;
  7277. t['horicoptic'] = 0x03E9;
  7278. t['horizontalbar'] = 0x2015;
  7279. t['horncmb'] = 0x031B;
  7280. t['hotsprings'] = 0x2668;
  7281. t['house'] = 0x2302;
  7282. t['hparen'] = 0x24A3;
  7283. t['hsuperior'] = 0x02B0;
  7284. t['hturned'] = 0x0265;
  7285. t['huhiragana'] = 0x3075;
  7286. t['huiitosquare'] = 0x3333;
  7287. t['hukatakana'] = 0x30D5;
  7288. t['hukatakanahalfwidth'] = 0xFF8C;
  7289. t['hungarumlaut'] = 0x02DD;
  7290. t['hungarumlautcmb'] = 0x030B;
  7291. t['hv'] = 0x0195;
  7292. t['hyphen'] = 0x002D;
  7293. t['hypheninferior'] = 0xF6E5;
  7294. t['hyphenmonospace'] = 0xFF0D;
  7295. t['hyphensmall'] = 0xFE63;
  7296. t['hyphensuperior'] = 0xF6E6;
  7297. t['hyphentwo'] = 0x2010;
  7298. t['i'] = 0x0069;
  7299. t['iacute'] = 0x00ED;
  7300. t['iacyrillic'] = 0x044F;
  7301. t['ibengali'] = 0x0987;
  7302. t['ibopomofo'] = 0x3127;
  7303. t['ibreve'] = 0x012D;
  7304. t['icaron'] = 0x01D0;
  7305. t['icircle'] = 0x24D8;
  7306. t['icircumflex'] = 0x00EE;
  7307. t['icyrillic'] = 0x0456;
  7308. t['idblgrave'] = 0x0209;
  7309. t['ideographearthcircle'] = 0x328F;
  7310. t['ideographfirecircle'] = 0x328B;
  7311. t['ideographicallianceparen'] = 0x323F;
  7312. t['ideographiccallparen'] = 0x323A;
  7313. t['ideographiccentrecircle'] = 0x32A5;
  7314. t['ideographicclose'] = 0x3006;
  7315. t['ideographiccomma'] = 0x3001;
  7316. t['ideographiccommaleft'] = 0xFF64;
  7317. t['ideographiccongratulationparen'] = 0x3237;
  7318. t['ideographiccorrectcircle'] = 0x32A3;
  7319. t['ideographicearthparen'] = 0x322F;
  7320. t['ideographicenterpriseparen'] = 0x323D;
  7321. t['ideographicexcellentcircle'] = 0x329D;
  7322. t['ideographicfestivalparen'] = 0x3240;
  7323. t['ideographicfinancialcircle'] = 0x3296;
  7324. t['ideographicfinancialparen'] = 0x3236;
  7325. t['ideographicfireparen'] = 0x322B;
  7326. t['ideographichaveparen'] = 0x3232;
  7327. t['ideographichighcircle'] = 0x32A4;
  7328. t['ideographiciterationmark'] = 0x3005;
  7329. t['ideographiclaborcircle'] = 0x3298;
  7330. t['ideographiclaborparen'] = 0x3238;
  7331. t['ideographicleftcircle'] = 0x32A7;
  7332. t['ideographiclowcircle'] = 0x32A6;
  7333. t['ideographicmedicinecircle'] = 0x32A9;
  7334. t['ideographicmetalparen'] = 0x322E;
  7335. t['ideographicmoonparen'] = 0x322A;
  7336. t['ideographicnameparen'] = 0x3234;
  7337. t['ideographicperiod'] = 0x3002;
  7338. t['ideographicprintcircle'] = 0x329E;
  7339. t['ideographicreachparen'] = 0x3243;
  7340. t['ideographicrepresentparen'] = 0x3239;
  7341. t['ideographicresourceparen'] = 0x323E;
  7342. t['ideographicrightcircle'] = 0x32A8;
  7343. t['ideographicsecretcircle'] = 0x3299;
  7344. t['ideographicselfparen'] = 0x3242;
  7345. t['ideographicsocietyparen'] = 0x3233;
  7346. t['ideographicspace'] = 0x3000;
  7347. t['ideographicspecialparen'] = 0x3235;
  7348. t['ideographicstockparen'] = 0x3231;
  7349. t['ideographicstudyparen'] = 0x323B;
  7350. t['ideographicsunparen'] = 0x3230;
  7351. t['ideographicsuperviseparen'] = 0x323C;
  7352. t['ideographicwaterparen'] = 0x322C;
  7353. t['ideographicwoodparen'] = 0x322D;
  7354. t['ideographiczero'] = 0x3007;
  7355. t['ideographmetalcircle'] = 0x328E;
  7356. t['ideographmooncircle'] = 0x328A;
  7357. t['ideographnamecircle'] = 0x3294;
  7358. t['ideographsuncircle'] = 0x3290;
  7359. t['ideographwatercircle'] = 0x328C;
  7360. t['ideographwoodcircle'] = 0x328D;
  7361. t['ideva'] = 0x0907;
  7362. t['idieresis'] = 0x00EF;
  7363. t['idieresisacute'] = 0x1E2F;
  7364. t['idieresiscyrillic'] = 0x04E5;
  7365. t['idotbelow'] = 0x1ECB;
  7366. t['iebrevecyrillic'] = 0x04D7;
  7367. t['iecyrillic'] = 0x0435;
  7368. t['ieungacirclekorean'] = 0x3275;
  7369. t['ieungaparenkorean'] = 0x3215;
  7370. t['ieungcirclekorean'] = 0x3267;
  7371. t['ieungkorean'] = 0x3147;
  7372. t['ieungparenkorean'] = 0x3207;
  7373. t['igrave'] = 0x00EC;
  7374. t['igujarati'] = 0x0A87;
  7375. t['igurmukhi'] = 0x0A07;
  7376. t['ihiragana'] = 0x3044;
  7377. t['ihookabove'] = 0x1EC9;
  7378. t['iibengali'] = 0x0988;
  7379. t['iicyrillic'] = 0x0438;
  7380. t['iideva'] = 0x0908;
  7381. t['iigujarati'] = 0x0A88;
  7382. t['iigurmukhi'] = 0x0A08;
  7383. t['iimatragurmukhi'] = 0x0A40;
  7384. t['iinvertedbreve'] = 0x020B;
  7385. t['iishortcyrillic'] = 0x0439;
  7386. t['iivowelsignbengali'] = 0x09C0;
  7387. t['iivowelsigndeva'] = 0x0940;
  7388. t['iivowelsigngujarati'] = 0x0AC0;
  7389. t['ij'] = 0x0133;
  7390. t['ikatakana'] = 0x30A4;
  7391. t['ikatakanahalfwidth'] = 0xFF72;
  7392. t['ikorean'] = 0x3163;
  7393. t['ilde'] = 0x02DC;
  7394. t['iluyhebrew'] = 0x05AC;
  7395. t['imacron'] = 0x012B;
  7396. t['imacroncyrillic'] = 0x04E3;
  7397. t['imageorapproximatelyequal'] = 0x2253;
  7398. t['imatragurmukhi'] = 0x0A3F;
  7399. t['imonospace'] = 0xFF49;
  7400. t['increment'] = 0x2206;
  7401. t['infinity'] = 0x221E;
  7402. t['iniarmenian'] = 0x056B;
  7403. t['integral'] = 0x222B;
  7404. t['integralbottom'] = 0x2321;
  7405. t['integralbt'] = 0x2321;
  7406. t['integralex'] = 0xF8F5;
  7407. t['integraltop'] = 0x2320;
  7408. t['integraltp'] = 0x2320;
  7409. t['intersection'] = 0x2229;
  7410. t['intisquare'] = 0x3305;
  7411. t['invbullet'] = 0x25D8;
  7412. t['invcircle'] = 0x25D9;
  7413. t['invsmileface'] = 0x263B;
  7414. t['iocyrillic'] = 0x0451;
  7415. t['iogonek'] = 0x012F;
  7416. t['iota'] = 0x03B9;
  7417. t['iotadieresis'] = 0x03CA;
  7418. t['iotadieresistonos'] = 0x0390;
  7419. t['iotalatin'] = 0x0269;
  7420. t['iotatonos'] = 0x03AF;
  7421. t['iparen'] = 0x24A4;
  7422. t['irigurmukhi'] = 0x0A72;
  7423. t['ismallhiragana'] = 0x3043;
  7424. t['ismallkatakana'] = 0x30A3;
  7425. t['ismallkatakanahalfwidth'] = 0xFF68;
  7426. t['issharbengali'] = 0x09FA;
  7427. t['istroke'] = 0x0268;
  7428. t['isuperior'] = 0xF6ED;
  7429. t['iterationhiragana'] = 0x309D;
  7430. t['iterationkatakana'] = 0x30FD;
  7431. t['itilde'] = 0x0129;
  7432. t['itildebelow'] = 0x1E2D;
  7433. t['iubopomofo'] = 0x3129;
  7434. t['iucyrillic'] = 0x044E;
  7435. t['ivowelsignbengali'] = 0x09BF;
  7436. t['ivowelsigndeva'] = 0x093F;
  7437. t['ivowelsigngujarati'] = 0x0ABF;
  7438. t['izhitsacyrillic'] = 0x0475;
  7439. t['izhitsadblgravecyrillic'] = 0x0477;
  7440. t['j'] = 0x006A;
  7441. t['jaarmenian'] = 0x0571;
  7442. t['jabengali'] = 0x099C;
  7443. t['jadeva'] = 0x091C;
  7444. t['jagujarati'] = 0x0A9C;
  7445. t['jagurmukhi'] = 0x0A1C;
  7446. t['jbopomofo'] = 0x3110;
  7447. t['jcaron'] = 0x01F0;
  7448. t['jcircle'] = 0x24D9;
  7449. t['jcircumflex'] = 0x0135;
  7450. t['jcrossedtail'] = 0x029D;
  7451. t['jdotlessstroke'] = 0x025F;
  7452. t['jecyrillic'] = 0x0458;
  7453. t['jeemarabic'] = 0x062C;
  7454. t['jeemfinalarabic'] = 0xFE9E;
  7455. t['jeeminitialarabic'] = 0xFE9F;
  7456. t['jeemmedialarabic'] = 0xFEA0;
  7457. t['jeharabic'] = 0x0698;
  7458. t['jehfinalarabic'] = 0xFB8B;
  7459. t['jhabengali'] = 0x099D;
  7460. t['jhadeva'] = 0x091D;
  7461. t['jhagujarati'] = 0x0A9D;
  7462. t['jhagurmukhi'] = 0x0A1D;
  7463. t['jheharmenian'] = 0x057B;
  7464. t['jis'] = 0x3004;
  7465. t['jmonospace'] = 0xFF4A;
  7466. t['jparen'] = 0x24A5;
  7467. t['jsuperior'] = 0x02B2;
  7468. t['k'] = 0x006B;
  7469. t['kabashkircyrillic'] = 0x04A1;
  7470. t['kabengali'] = 0x0995;
  7471. t['kacute'] = 0x1E31;
  7472. t['kacyrillic'] = 0x043A;
  7473. t['kadescendercyrillic'] = 0x049B;
  7474. t['kadeva'] = 0x0915;
  7475. t['kaf'] = 0x05DB;
  7476. t['kafarabic'] = 0x0643;
  7477. t['kafdagesh'] = 0xFB3B;
  7478. t['kafdageshhebrew'] = 0xFB3B;
  7479. t['kaffinalarabic'] = 0xFEDA;
  7480. t['kafhebrew'] = 0x05DB;
  7481. t['kafinitialarabic'] = 0xFEDB;
  7482. t['kafmedialarabic'] = 0xFEDC;
  7483. t['kafrafehebrew'] = 0xFB4D;
  7484. t['kagujarati'] = 0x0A95;
  7485. t['kagurmukhi'] = 0x0A15;
  7486. t['kahiragana'] = 0x304B;
  7487. t['kahookcyrillic'] = 0x04C4;
  7488. t['kakatakana'] = 0x30AB;
  7489. t['kakatakanahalfwidth'] = 0xFF76;
  7490. t['kappa'] = 0x03BA;
  7491. t['kappasymbolgreek'] = 0x03F0;
  7492. t['kapyeounmieumkorean'] = 0x3171;
  7493. t['kapyeounphieuphkorean'] = 0x3184;
  7494. t['kapyeounpieupkorean'] = 0x3178;
  7495. t['kapyeounssangpieupkorean'] = 0x3179;
  7496. t['karoriisquare'] = 0x330D;
  7497. t['kashidaautoarabic'] = 0x0640;
  7498. t['kashidaautonosidebearingarabic'] = 0x0640;
  7499. t['kasmallkatakana'] = 0x30F5;
  7500. t['kasquare'] = 0x3384;
  7501. t['kasraarabic'] = 0x0650;
  7502. t['kasratanarabic'] = 0x064D;
  7503. t['kastrokecyrillic'] = 0x049F;
  7504. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7505. t['kaverticalstrokecyrillic'] = 0x049D;
  7506. t['kbopomofo'] = 0x310E;
  7507. t['kcalsquare'] = 0x3389;
  7508. t['kcaron'] = 0x01E9;
  7509. t['kcedilla'] = 0x0137;
  7510. t['kcircle'] = 0x24DA;
  7511. t['kcommaaccent'] = 0x0137;
  7512. t['kdotbelow'] = 0x1E33;
  7513. t['keharmenian'] = 0x0584;
  7514. t['kehiragana'] = 0x3051;
  7515. t['kekatakana'] = 0x30B1;
  7516. t['kekatakanahalfwidth'] = 0xFF79;
  7517. t['kenarmenian'] = 0x056F;
  7518. t['kesmallkatakana'] = 0x30F6;
  7519. t['kgreenlandic'] = 0x0138;
  7520. t['khabengali'] = 0x0996;
  7521. t['khacyrillic'] = 0x0445;
  7522. t['khadeva'] = 0x0916;
  7523. t['khagujarati'] = 0x0A96;
  7524. t['khagurmukhi'] = 0x0A16;
  7525. t['khaharabic'] = 0x062E;
  7526. t['khahfinalarabic'] = 0xFEA6;
  7527. t['khahinitialarabic'] = 0xFEA7;
  7528. t['khahmedialarabic'] = 0xFEA8;
  7529. t['kheicoptic'] = 0x03E7;
  7530. t['khhadeva'] = 0x0959;
  7531. t['khhagurmukhi'] = 0x0A59;
  7532. t['khieukhacirclekorean'] = 0x3278;
  7533. t['khieukhaparenkorean'] = 0x3218;
  7534. t['khieukhcirclekorean'] = 0x326A;
  7535. t['khieukhkorean'] = 0x314B;
  7536. t['khieukhparenkorean'] = 0x320A;
  7537. t['khokhaithai'] = 0x0E02;
  7538. t['khokhonthai'] = 0x0E05;
  7539. t['khokhuatthai'] = 0x0E03;
  7540. t['khokhwaithai'] = 0x0E04;
  7541. t['khomutthai'] = 0x0E5B;
  7542. t['khook'] = 0x0199;
  7543. t['khorakhangthai'] = 0x0E06;
  7544. t['khzsquare'] = 0x3391;
  7545. t['kihiragana'] = 0x304D;
  7546. t['kikatakana'] = 0x30AD;
  7547. t['kikatakanahalfwidth'] = 0xFF77;
  7548. t['kiroguramusquare'] = 0x3315;
  7549. t['kiromeetorusquare'] = 0x3316;
  7550. t['kirosquare'] = 0x3314;
  7551. t['kiyeokacirclekorean'] = 0x326E;
  7552. t['kiyeokaparenkorean'] = 0x320E;
  7553. t['kiyeokcirclekorean'] = 0x3260;
  7554. t['kiyeokkorean'] = 0x3131;
  7555. t['kiyeokparenkorean'] = 0x3200;
  7556. t['kiyeoksioskorean'] = 0x3133;
  7557. t['kjecyrillic'] = 0x045C;
  7558. t['klinebelow'] = 0x1E35;
  7559. t['klsquare'] = 0x3398;
  7560. t['kmcubedsquare'] = 0x33A6;
  7561. t['kmonospace'] = 0xFF4B;
  7562. t['kmsquaredsquare'] = 0x33A2;
  7563. t['kohiragana'] = 0x3053;
  7564. t['kohmsquare'] = 0x33C0;
  7565. t['kokaithai'] = 0x0E01;
  7566. t['kokatakana'] = 0x30B3;
  7567. t['kokatakanahalfwidth'] = 0xFF7A;
  7568. t['kooposquare'] = 0x331E;
  7569. t['koppacyrillic'] = 0x0481;
  7570. t['koreanstandardsymbol'] = 0x327F;
  7571. t['koroniscmb'] = 0x0343;
  7572. t['kparen'] = 0x24A6;
  7573. t['kpasquare'] = 0x33AA;
  7574. t['ksicyrillic'] = 0x046F;
  7575. t['ktsquare'] = 0x33CF;
  7576. t['kturned'] = 0x029E;
  7577. t['kuhiragana'] = 0x304F;
  7578. t['kukatakana'] = 0x30AF;
  7579. t['kukatakanahalfwidth'] = 0xFF78;
  7580. t['kvsquare'] = 0x33B8;
  7581. t['kwsquare'] = 0x33BE;
  7582. t['l'] = 0x006C;
  7583. t['labengali'] = 0x09B2;
  7584. t['lacute'] = 0x013A;
  7585. t['ladeva'] = 0x0932;
  7586. t['lagujarati'] = 0x0AB2;
  7587. t['lagurmukhi'] = 0x0A32;
  7588. t['lakkhangyaothai'] = 0x0E45;
  7589. t['lamaleffinalarabic'] = 0xFEFC;
  7590. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7591. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7592. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7593. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7594. t['lamalefisolatedarabic'] = 0xFEFB;
  7595. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7596. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7597. t['lamarabic'] = 0x0644;
  7598. t['lambda'] = 0x03BB;
  7599. t['lambdastroke'] = 0x019B;
  7600. t['lamed'] = 0x05DC;
  7601. t['lameddagesh'] = 0xFB3C;
  7602. t['lameddageshhebrew'] = 0xFB3C;
  7603. t['lamedhebrew'] = 0x05DC;
  7604. t['lamfinalarabic'] = 0xFEDE;
  7605. t['lamhahinitialarabic'] = 0xFCCA;
  7606. t['laminitialarabic'] = 0xFEDF;
  7607. t['lamjeeminitialarabic'] = 0xFCC9;
  7608. t['lamkhahinitialarabic'] = 0xFCCB;
  7609. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7610. t['lammedialarabic'] = 0xFEE0;
  7611. t['lammeemhahinitialarabic'] = 0xFD88;
  7612. t['lammeeminitialarabic'] = 0xFCCC;
  7613. t['largecircle'] = 0x25EF;
  7614. t['lbar'] = 0x019A;
  7615. t['lbelt'] = 0x026C;
  7616. t['lbopomofo'] = 0x310C;
  7617. t['lcaron'] = 0x013E;
  7618. t['lcedilla'] = 0x013C;
  7619. t['lcircle'] = 0x24DB;
  7620. t['lcircumflexbelow'] = 0x1E3D;
  7621. t['lcommaaccent'] = 0x013C;
  7622. t['ldot'] = 0x0140;
  7623. t['ldotaccent'] = 0x0140;
  7624. t['ldotbelow'] = 0x1E37;
  7625. t['ldotbelowmacron'] = 0x1E39;
  7626. t['leftangleabovecmb'] = 0x031A;
  7627. t['lefttackbelowcmb'] = 0x0318;
  7628. t['less'] = 0x003C;
  7629. t['lessequal'] = 0x2264;
  7630. t['lessequalorgreater'] = 0x22DA;
  7631. t['lessmonospace'] = 0xFF1C;
  7632. t['lessorequivalent'] = 0x2272;
  7633. t['lessorgreater'] = 0x2276;
  7634. t['lessoverequal'] = 0x2266;
  7635. t['lesssmall'] = 0xFE64;
  7636. t['lezh'] = 0x026E;
  7637. t['lfblock'] = 0x258C;
  7638. t['lhookretroflex'] = 0x026D;
  7639. t['lira'] = 0x20A4;
  7640. t['liwnarmenian'] = 0x056C;
  7641. t['lj'] = 0x01C9;
  7642. t['ljecyrillic'] = 0x0459;
  7643. t['ll'] = 0xF6C0;
  7644. t['lladeva'] = 0x0933;
  7645. t['llagujarati'] = 0x0AB3;
  7646. t['llinebelow'] = 0x1E3B;
  7647. t['llladeva'] = 0x0934;
  7648. t['llvocalicbengali'] = 0x09E1;
  7649. t['llvocalicdeva'] = 0x0961;
  7650. t['llvocalicvowelsignbengali'] = 0x09E3;
  7651. t['llvocalicvowelsigndeva'] = 0x0963;
  7652. t['lmiddletilde'] = 0x026B;
  7653. t['lmonospace'] = 0xFF4C;
  7654. t['lmsquare'] = 0x33D0;
  7655. t['lochulathai'] = 0x0E2C;
  7656. t['logicaland'] = 0x2227;
  7657. t['logicalnot'] = 0x00AC;
  7658. t['logicalnotreversed'] = 0x2310;
  7659. t['logicalor'] = 0x2228;
  7660. t['lolingthai'] = 0x0E25;
  7661. t['longs'] = 0x017F;
  7662. t['lowlinecenterline'] = 0xFE4E;
  7663. t['lowlinecmb'] = 0x0332;
  7664. t['lowlinedashed'] = 0xFE4D;
  7665. t['lozenge'] = 0x25CA;
  7666. t['lparen'] = 0x24A7;
  7667. t['lslash'] = 0x0142;
  7668. t['lsquare'] = 0x2113;
  7669. t['lsuperior'] = 0xF6EE;
  7670. t['ltshade'] = 0x2591;
  7671. t['luthai'] = 0x0E26;
  7672. t['lvocalicbengali'] = 0x098C;
  7673. t['lvocalicdeva'] = 0x090C;
  7674. t['lvocalicvowelsignbengali'] = 0x09E2;
  7675. t['lvocalicvowelsigndeva'] = 0x0962;
  7676. t['lxsquare'] = 0x33D3;
  7677. t['m'] = 0x006D;
  7678. t['mabengali'] = 0x09AE;
  7679. t['macron'] = 0x00AF;
  7680. t['macronbelowcmb'] = 0x0331;
  7681. t['macroncmb'] = 0x0304;
  7682. t['macronlowmod'] = 0x02CD;
  7683. t['macronmonospace'] = 0xFFE3;
  7684. t['macute'] = 0x1E3F;
  7685. t['madeva'] = 0x092E;
  7686. t['magujarati'] = 0x0AAE;
  7687. t['magurmukhi'] = 0x0A2E;
  7688. t['mahapakhhebrew'] = 0x05A4;
  7689. t['mahapakhlefthebrew'] = 0x05A4;
  7690. t['mahiragana'] = 0x307E;
  7691. t['maichattawalowleftthai'] = 0xF895;
  7692. t['maichattawalowrightthai'] = 0xF894;
  7693. t['maichattawathai'] = 0x0E4B;
  7694. t['maichattawaupperleftthai'] = 0xF893;
  7695. t['maieklowleftthai'] = 0xF88C;
  7696. t['maieklowrightthai'] = 0xF88B;
  7697. t['maiekthai'] = 0x0E48;
  7698. t['maiekupperleftthai'] = 0xF88A;
  7699. t['maihanakatleftthai'] = 0xF884;
  7700. t['maihanakatthai'] = 0x0E31;
  7701. t['maitaikhuleftthai'] = 0xF889;
  7702. t['maitaikhuthai'] = 0x0E47;
  7703. t['maitholowleftthai'] = 0xF88F;
  7704. t['maitholowrightthai'] = 0xF88E;
  7705. t['maithothai'] = 0x0E49;
  7706. t['maithoupperleftthai'] = 0xF88D;
  7707. t['maitrilowleftthai'] = 0xF892;
  7708. t['maitrilowrightthai'] = 0xF891;
  7709. t['maitrithai'] = 0x0E4A;
  7710. t['maitriupperleftthai'] = 0xF890;
  7711. t['maiyamokthai'] = 0x0E46;
  7712. t['makatakana'] = 0x30DE;
  7713. t['makatakanahalfwidth'] = 0xFF8F;
  7714. t['male'] = 0x2642;
  7715. t['mansyonsquare'] = 0x3347;
  7716. t['maqafhebrew'] = 0x05BE;
  7717. t['mars'] = 0x2642;
  7718. t['masoracirclehebrew'] = 0x05AF;
  7719. t['masquare'] = 0x3383;
  7720. t['mbopomofo'] = 0x3107;
  7721. t['mbsquare'] = 0x33D4;
  7722. t['mcircle'] = 0x24DC;
  7723. t['mcubedsquare'] = 0x33A5;
  7724. t['mdotaccent'] = 0x1E41;
  7725. t['mdotbelow'] = 0x1E43;
  7726. t['meemarabic'] = 0x0645;
  7727. t['meemfinalarabic'] = 0xFEE2;
  7728. t['meeminitialarabic'] = 0xFEE3;
  7729. t['meemmedialarabic'] = 0xFEE4;
  7730. t['meemmeeminitialarabic'] = 0xFCD1;
  7731. t['meemmeemisolatedarabic'] = 0xFC48;
  7732. t['meetorusquare'] = 0x334D;
  7733. t['mehiragana'] = 0x3081;
  7734. t['meizierasquare'] = 0x337E;
  7735. t['mekatakana'] = 0x30E1;
  7736. t['mekatakanahalfwidth'] = 0xFF92;
  7737. t['mem'] = 0x05DE;
  7738. t['memdagesh'] = 0xFB3E;
  7739. t['memdageshhebrew'] = 0xFB3E;
  7740. t['memhebrew'] = 0x05DE;
  7741. t['menarmenian'] = 0x0574;
  7742. t['merkhahebrew'] = 0x05A5;
  7743. t['merkhakefulahebrew'] = 0x05A6;
  7744. t['merkhakefulalefthebrew'] = 0x05A6;
  7745. t['merkhalefthebrew'] = 0x05A5;
  7746. t['mhook'] = 0x0271;
  7747. t['mhzsquare'] = 0x3392;
  7748. t['middledotkatakanahalfwidth'] = 0xFF65;
  7749. t['middot'] = 0x00B7;
  7750. t['mieumacirclekorean'] = 0x3272;
  7751. t['mieumaparenkorean'] = 0x3212;
  7752. t['mieumcirclekorean'] = 0x3264;
  7753. t['mieumkorean'] = 0x3141;
  7754. t['mieumpansioskorean'] = 0x3170;
  7755. t['mieumparenkorean'] = 0x3204;
  7756. t['mieumpieupkorean'] = 0x316E;
  7757. t['mieumsioskorean'] = 0x316F;
  7758. t['mihiragana'] = 0x307F;
  7759. t['mikatakana'] = 0x30DF;
  7760. t['mikatakanahalfwidth'] = 0xFF90;
  7761. t['minus'] = 0x2212;
  7762. t['minusbelowcmb'] = 0x0320;
  7763. t['minuscircle'] = 0x2296;
  7764. t['minusmod'] = 0x02D7;
  7765. t['minusplus'] = 0x2213;
  7766. t['minute'] = 0x2032;
  7767. t['miribaarusquare'] = 0x334A;
  7768. t['mirisquare'] = 0x3349;
  7769. t['mlonglegturned'] = 0x0270;
  7770. t['mlsquare'] = 0x3396;
  7771. t['mmcubedsquare'] = 0x33A3;
  7772. t['mmonospace'] = 0xFF4D;
  7773. t['mmsquaredsquare'] = 0x339F;
  7774. t['mohiragana'] = 0x3082;
  7775. t['mohmsquare'] = 0x33C1;
  7776. t['mokatakana'] = 0x30E2;
  7777. t['mokatakanahalfwidth'] = 0xFF93;
  7778. t['molsquare'] = 0x33D6;
  7779. t['momathai'] = 0x0E21;
  7780. t['moverssquare'] = 0x33A7;
  7781. t['moverssquaredsquare'] = 0x33A8;
  7782. t['mparen'] = 0x24A8;
  7783. t['mpasquare'] = 0x33AB;
  7784. t['mssquare'] = 0x33B3;
  7785. t['msuperior'] = 0xF6EF;
  7786. t['mturned'] = 0x026F;
  7787. t['mu'] = 0x00B5;
  7788. t['mu1'] = 0x00B5;
  7789. t['muasquare'] = 0x3382;
  7790. t['muchgreater'] = 0x226B;
  7791. t['muchless'] = 0x226A;
  7792. t['mufsquare'] = 0x338C;
  7793. t['mugreek'] = 0x03BC;
  7794. t['mugsquare'] = 0x338D;
  7795. t['muhiragana'] = 0x3080;
  7796. t['mukatakana'] = 0x30E0;
  7797. t['mukatakanahalfwidth'] = 0xFF91;
  7798. t['mulsquare'] = 0x3395;
  7799. t['multiply'] = 0x00D7;
  7800. t['mumsquare'] = 0x339B;
  7801. t['munahhebrew'] = 0x05A3;
  7802. t['munahlefthebrew'] = 0x05A3;
  7803. t['musicalnote'] = 0x266A;
  7804. t['musicalnotedbl'] = 0x266B;
  7805. t['musicflatsign'] = 0x266D;
  7806. t['musicsharpsign'] = 0x266F;
  7807. t['mussquare'] = 0x33B2;
  7808. t['muvsquare'] = 0x33B6;
  7809. t['muwsquare'] = 0x33BC;
  7810. t['mvmegasquare'] = 0x33B9;
  7811. t['mvsquare'] = 0x33B7;
  7812. t['mwmegasquare'] = 0x33BF;
  7813. t['mwsquare'] = 0x33BD;
  7814. t['n'] = 0x006E;
  7815. t['nabengali'] = 0x09A8;
  7816. t['nabla'] = 0x2207;
  7817. t['nacute'] = 0x0144;
  7818. t['nadeva'] = 0x0928;
  7819. t['nagujarati'] = 0x0AA8;
  7820. t['nagurmukhi'] = 0x0A28;
  7821. t['nahiragana'] = 0x306A;
  7822. t['nakatakana'] = 0x30CA;
  7823. t['nakatakanahalfwidth'] = 0xFF85;
  7824. t['napostrophe'] = 0x0149;
  7825. t['nasquare'] = 0x3381;
  7826. t['nbopomofo'] = 0x310B;
  7827. t['nbspace'] = 0x00A0;
  7828. t['ncaron'] = 0x0148;
  7829. t['ncedilla'] = 0x0146;
  7830. t['ncircle'] = 0x24DD;
  7831. t['ncircumflexbelow'] = 0x1E4B;
  7832. t['ncommaaccent'] = 0x0146;
  7833. t['ndotaccent'] = 0x1E45;
  7834. t['ndotbelow'] = 0x1E47;
  7835. t['nehiragana'] = 0x306D;
  7836. t['nekatakana'] = 0x30CD;
  7837. t['nekatakanahalfwidth'] = 0xFF88;
  7838. t['newsheqelsign'] = 0x20AA;
  7839. t['nfsquare'] = 0x338B;
  7840. t['ngabengali'] = 0x0999;
  7841. t['ngadeva'] = 0x0919;
  7842. t['ngagujarati'] = 0x0A99;
  7843. t['ngagurmukhi'] = 0x0A19;
  7844. t['ngonguthai'] = 0x0E07;
  7845. t['nhiragana'] = 0x3093;
  7846. t['nhookleft'] = 0x0272;
  7847. t['nhookretroflex'] = 0x0273;
  7848. t['nieunacirclekorean'] = 0x326F;
  7849. t['nieunaparenkorean'] = 0x320F;
  7850. t['nieuncieuckorean'] = 0x3135;
  7851. t['nieuncirclekorean'] = 0x3261;
  7852. t['nieunhieuhkorean'] = 0x3136;
  7853. t['nieunkorean'] = 0x3134;
  7854. t['nieunpansioskorean'] = 0x3168;
  7855. t['nieunparenkorean'] = 0x3201;
  7856. t['nieunsioskorean'] = 0x3167;
  7857. t['nieuntikeutkorean'] = 0x3166;
  7858. t['nihiragana'] = 0x306B;
  7859. t['nikatakana'] = 0x30CB;
  7860. t['nikatakanahalfwidth'] = 0xFF86;
  7861. t['nikhahitleftthai'] = 0xF899;
  7862. t['nikhahitthai'] = 0x0E4D;
  7863. t['nine'] = 0x0039;
  7864. t['ninearabic'] = 0x0669;
  7865. t['ninebengali'] = 0x09EF;
  7866. t['ninecircle'] = 0x2468;
  7867. t['ninecircleinversesansserif'] = 0x2792;
  7868. t['ninedeva'] = 0x096F;
  7869. t['ninegujarati'] = 0x0AEF;
  7870. t['ninegurmukhi'] = 0x0A6F;
  7871. t['ninehackarabic'] = 0x0669;
  7872. t['ninehangzhou'] = 0x3029;
  7873. t['nineideographicparen'] = 0x3228;
  7874. t['nineinferior'] = 0x2089;
  7875. t['ninemonospace'] = 0xFF19;
  7876. t['nineoldstyle'] = 0xF739;
  7877. t['nineparen'] = 0x247C;
  7878. t['nineperiod'] = 0x2490;
  7879. t['ninepersian'] = 0x06F9;
  7880. t['nineroman'] = 0x2178;
  7881. t['ninesuperior'] = 0x2079;
  7882. t['nineteencircle'] = 0x2472;
  7883. t['nineteenparen'] = 0x2486;
  7884. t['nineteenperiod'] = 0x249A;
  7885. t['ninethai'] = 0x0E59;
  7886. t['nj'] = 0x01CC;
  7887. t['njecyrillic'] = 0x045A;
  7888. t['nkatakana'] = 0x30F3;
  7889. t['nkatakanahalfwidth'] = 0xFF9D;
  7890. t['nlegrightlong'] = 0x019E;
  7891. t['nlinebelow'] = 0x1E49;
  7892. t['nmonospace'] = 0xFF4E;
  7893. t['nmsquare'] = 0x339A;
  7894. t['nnabengali'] = 0x09A3;
  7895. t['nnadeva'] = 0x0923;
  7896. t['nnagujarati'] = 0x0AA3;
  7897. t['nnagurmukhi'] = 0x0A23;
  7898. t['nnnadeva'] = 0x0929;
  7899. t['nohiragana'] = 0x306E;
  7900. t['nokatakana'] = 0x30CE;
  7901. t['nokatakanahalfwidth'] = 0xFF89;
  7902. t['nonbreakingspace'] = 0x00A0;
  7903. t['nonenthai'] = 0x0E13;
  7904. t['nonuthai'] = 0x0E19;
  7905. t['noonarabic'] = 0x0646;
  7906. t['noonfinalarabic'] = 0xFEE6;
  7907. t['noonghunnaarabic'] = 0x06BA;
  7908. t['noonghunnafinalarabic'] = 0xFB9F;
  7909. t['nooninitialarabic'] = 0xFEE7;
  7910. t['noonjeeminitialarabic'] = 0xFCD2;
  7911. t['noonjeemisolatedarabic'] = 0xFC4B;
  7912. t['noonmedialarabic'] = 0xFEE8;
  7913. t['noonmeeminitialarabic'] = 0xFCD5;
  7914. t['noonmeemisolatedarabic'] = 0xFC4E;
  7915. t['noonnoonfinalarabic'] = 0xFC8D;
  7916. t['notcontains'] = 0x220C;
  7917. t['notelement'] = 0x2209;
  7918. t['notelementof'] = 0x2209;
  7919. t['notequal'] = 0x2260;
  7920. t['notgreater'] = 0x226F;
  7921. t['notgreaternorequal'] = 0x2271;
  7922. t['notgreaternorless'] = 0x2279;
  7923. t['notidentical'] = 0x2262;
  7924. t['notless'] = 0x226E;
  7925. t['notlessnorequal'] = 0x2270;
  7926. t['notparallel'] = 0x2226;
  7927. t['notprecedes'] = 0x2280;
  7928. t['notsubset'] = 0x2284;
  7929. t['notsucceeds'] = 0x2281;
  7930. t['notsuperset'] = 0x2285;
  7931. t['nowarmenian'] = 0x0576;
  7932. t['nparen'] = 0x24A9;
  7933. t['nssquare'] = 0x33B1;
  7934. t['nsuperior'] = 0x207F;
  7935. t['ntilde'] = 0x00F1;
  7936. t['nu'] = 0x03BD;
  7937. t['nuhiragana'] = 0x306C;
  7938. t['nukatakana'] = 0x30CC;
  7939. t['nukatakanahalfwidth'] = 0xFF87;
  7940. t['nuktabengali'] = 0x09BC;
  7941. t['nuktadeva'] = 0x093C;
  7942. t['nuktagujarati'] = 0x0ABC;
  7943. t['nuktagurmukhi'] = 0x0A3C;
  7944. t['numbersign'] = 0x0023;
  7945. t['numbersignmonospace'] = 0xFF03;
  7946. t['numbersignsmall'] = 0xFE5F;
  7947. t['numeralsigngreek'] = 0x0374;
  7948. t['numeralsignlowergreek'] = 0x0375;
  7949. t['numero'] = 0x2116;
  7950. t['nun'] = 0x05E0;
  7951. t['nundagesh'] = 0xFB40;
  7952. t['nundageshhebrew'] = 0xFB40;
  7953. t['nunhebrew'] = 0x05E0;
  7954. t['nvsquare'] = 0x33B5;
  7955. t['nwsquare'] = 0x33BB;
  7956. t['nyabengali'] = 0x099E;
  7957. t['nyadeva'] = 0x091E;
  7958. t['nyagujarati'] = 0x0A9E;
  7959. t['nyagurmukhi'] = 0x0A1E;
  7960. t['o'] = 0x006F;
  7961. t['oacute'] = 0x00F3;
  7962. t['oangthai'] = 0x0E2D;
  7963. t['obarred'] = 0x0275;
  7964. t['obarredcyrillic'] = 0x04E9;
  7965. t['obarreddieresiscyrillic'] = 0x04EB;
  7966. t['obengali'] = 0x0993;
  7967. t['obopomofo'] = 0x311B;
  7968. t['obreve'] = 0x014F;
  7969. t['ocandradeva'] = 0x0911;
  7970. t['ocandragujarati'] = 0x0A91;
  7971. t['ocandravowelsigndeva'] = 0x0949;
  7972. t['ocandravowelsigngujarati'] = 0x0AC9;
  7973. t['ocaron'] = 0x01D2;
  7974. t['ocircle'] = 0x24DE;
  7975. t['ocircumflex'] = 0x00F4;
  7976. t['ocircumflexacute'] = 0x1ED1;
  7977. t['ocircumflexdotbelow'] = 0x1ED9;
  7978. t['ocircumflexgrave'] = 0x1ED3;
  7979. t['ocircumflexhookabove'] = 0x1ED5;
  7980. t['ocircumflextilde'] = 0x1ED7;
  7981. t['ocyrillic'] = 0x043E;
  7982. t['odblacute'] = 0x0151;
  7983. t['odblgrave'] = 0x020D;
  7984. t['odeva'] = 0x0913;
  7985. t['odieresis'] = 0x00F6;
  7986. t['odieresiscyrillic'] = 0x04E7;
  7987. t['odotbelow'] = 0x1ECD;
  7988. t['oe'] = 0x0153;
  7989. t['oekorean'] = 0x315A;
  7990. t['ogonek'] = 0x02DB;
  7991. t['ogonekcmb'] = 0x0328;
  7992. t['ograve'] = 0x00F2;
  7993. t['ogujarati'] = 0x0A93;
  7994. t['oharmenian'] = 0x0585;
  7995. t['ohiragana'] = 0x304A;
  7996. t['ohookabove'] = 0x1ECF;
  7997. t['ohorn'] = 0x01A1;
  7998. t['ohornacute'] = 0x1EDB;
  7999. t['ohorndotbelow'] = 0x1EE3;
  8000. t['ohorngrave'] = 0x1EDD;
  8001. t['ohornhookabove'] = 0x1EDF;
  8002. t['ohorntilde'] = 0x1EE1;
  8003. t['ohungarumlaut'] = 0x0151;
  8004. t['oi'] = 0x01A3;
  8005. t['oinvertedbreve'] = 0x020F;
  8006. t['okatakana'] = 0x30AA;
  8007. t['okatakanahalfwidth'] = 0xFF75;
  8008. t['okorean'] = 0x3157;
  8009. t['olehebrew'] = 0x05AB;
  8010. t['omacron'] = 0x014D;
  8011. t['omacronacute'] = 0x1E53;
  8012. t['omacrongrave'] = 0x1E51;
  8013. t['omdeva'] = 0x0950;
  8014. t['omega'] = 0x03C9;
  8015. t['omega1'] = 0x03D6;
  8016. t['omegacyrillic'] = 0x0461;
  8017. t['omegalatinclosed'] = 0x0277;
  8018. t['omegaroundcyrillic'] = 0x047B;
  8019. t['omegatitlocyrillic'] = 0x047D;
  8020. t['omegatonos'] = 0x03CE;
  8021. t['omgujarati'] = 0x0AD0;
  8022. t['omicron'] = 0x03BF;
  8023. t['omicrontonos'] = 0x03CC;
  8024. t['omonospace'] = 0xFF4F;
  8025. t['one'] = 0x0031;
  8026. t['onearabic'] = 0x0661;
  8027. t['onebengali'] = 0x09E7;
  8028. t['onecircle'] = 0x2460;
  8029. t['onecircleinversesansserif'] = 0x278A;
  8030. t['onedeva'] = 0x0967;
  8031. t['onedotenleader'] = 0x2024;
  8032. t['oneeighth'] = 0x215B;
  8033. t['onefitted'] = 0xF6DC;
  8034. t['onegujarati'] = 0x0AE7;
  8035. t['onegurmukhi'] = 0x0A67;
  8036. t['onehackarabic'] = 0x0661;
  8037. t['onehalf'] = 0x00BD;
  8038. t['onehangzhou'] = 0x3021;
  8039. t['oneideographicparen'] = 0x3220;
  8040. t['oneinferior'] = 0x2081;
  8041. t['onemonospace'] = 0xFF11;
  8042. t['onenumeratorbengali'] = 0x09F4;
  8043. t['oneoldstyle'] = 0xF731;
  8044. t['oneparen'] = 0x2474;
  8045. t['oneperiod'] = 0x2488;
  8046. t['onepersian'] = 0x06F1;
  8047. t['onequarter'] = 0x00BC;
  8048. t['oneroman'] = 0x2170;
  8049. t['onesuperior'] = 0x00B9;
  8050. t['onethai'] = 0x0E51;
  8051. t['onethird'] = 0x2153;
  8052. t['oogonek'] = 0x01EB;
  8053. t['oogonekmacron'] = 0x01ED;
  8054. t['oogurmukhi'] = 0x0A13;
  8055. t['oomatragurmukhi'] = 0x0A4B;
  8056. t['oopen'] = 0x0254;
  8057. t['oparen'] = 0x24AA;
  8058. t['openbullet'] = 0x25E6;
  8059. t['option'] = 0x2325;
  8060. t['ordfeminine'] = 0x00AA;
  8061. t['ordmasculine'] = 0x00BA;
  8062. t['orthogonal'] = 0x221F;
  8063. t['oshortdeva'] = 0x0912;
  8064. t['oshortvowelsigndeva'] = 0x094A;
  8065. t['oslash'] = 0x00F8;
  8066. t['oslashacute'] = 0x01FF;
  8067. t['osmallhiragana'] = 0x3049;
  8068. t['osmallkatakana'] = 0x30A9;
  8069. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8070. t['ostrokeacute'] = 0x01FF;
  8071. t['osuperior'] = 0xF6F0;
  8072. t['otcyrillic'] = 0x047F;
  8073. t['otilde'] = 0x00F5;
  8074. t['otildeacute'] = 0x1E4D;
  8075. t['otildedieresis'] = 0x1E4F;
  8076. t['oubopomofo'] = 0x3121;
  8077. t['overline'] = 0x203E;
  8078. t['overlinecenterline'] = 0xFE4A;
  8079. t['overlinecmb'] = 0x0305;
  8080. t['overlinedashed'] = 0xFE49;
  8081. t['overlinedblwavy'] = 0xFE4C;
  8082. t['overlinewavy'] = 0xFE4B;
  8083. t['overscore'] = 0x00AF;
  8084. t['ovowelsignbengali'] = 0x09CB;
  8085. t['ovowelsigndeva'] = 0x094B;
  8086. t['ovowelsigngujarati'] = 0x0ACB;
  8087. t['p'] = 0x0070;
  8088. t['paampssquare'] = 0x3380;
  8089. t['paasentosquare'] = 0x332B;
  8090. t['pabengali'] = 0x09AA;
  8091. t['pacute'] = 0x1E55;
  8092. t['padeva'] = 0x092A;
  8093. t['pagedown'] = 0x21DF;
  8094. t['pageup'] = 0x21DE;
  8095. t['pagujarati'] = 0x0AAA;
  8096. t['pagurmukhi'] = 0x0A2A;
  8097. t['pahiragana'] = 0x3071;
  8098. t['paiyannoithai'] = 0x0E2F;
  8099. t['pakatakana'] = 0x30D1;
  8100. t['palatalizationcyrilliccmb'] = 0x0484;
  8101. t['palochkacyrillic'] = 0x04C0;
  8102. t['pansioskorean'] = 0x317F;
  8103. t['paragraph'] = 0x00B6;
  8104. t['parallel'] = 0x2225;
  8105. t['parenleft'] = 0x0028;
  8106. t['parenleftaltonearabic'] = 0xFD3E;
  8107. t['parenleftbt'] = 0xF8ED;
  8108. t['parenleftex'] = 0xF8EC;
  8109. t['parenleftinferior'] = 0x208D;
  8110. t['parenleftmonospace'] = 0xFF08;
  8111. t['parenleftsmall'] = 0xFE59;
  8112. t['parenleftsuperior'] = 0x207D;
  8113. t['parenlefttp'] = 0xF8EB;
  8114. t['parenleftvertical'] = 0xFE35;
  8115. t['parenright'] = 0x0029;
  8116. t['parenrightaltonearabic'] = 0xFD3F;
  8117. t['parenrightbt'] = 0xF8F8;
  8118. t['parenrightex'] = 0xF8F7;
  8119. t['parenrightinferior'] = 0x208E;
  8120. t['parenrightmonospace'] = 0xFF09;
  8121. t['parenrightsmall'] = 0xFE5A;
  8122. t['parenrightsuperior'] = 0x207E;
  8123. t['parenrighttp'] = 0xF8F6;
  8124. t['parenrightvertical'] = 0xFE36;
  8125. t['partialdiff'] = 0x2202;
  8126. t['paseqhebrew'] = 0x05C0;
  8127. t['pashtahebrew'] = 0x0599;
  8128. t['pasquare'] = 0x33A9;
  8129. t['patah'] = 0x05B7;
  8130. t['patah11'] = 0x05B7;
  8131. t['patah1d'] = 0x05B7;
  8132. t['patah2a'] = 0x05B7;
  8133. t['patahhebrew'] = 0x05B7;
  8134. t['patahnarrowhebrew'] = 0x05B7;
  8135. t['patahquarterhebrew'] = 0x05B7;
  8136. t['patahwidehebrew'] = 0x05B7;
  8137. t['pazerhebrew'] = 0x05A1;
  8138. t['pbopomofo'] = 0x3106;
  8139. t['pcircle'] = 0x24DF;
  8140. t['pdotaccent'] = 0x1E57;
  8141. t['pe'] = 0x05E4;
  8142. t['pecyrillic'] = 0x043F;
  8143. t['pedagesh'] = 0xFB44;
  8144. t['pedageshhebrew'] = 0xFB44;
  8145. t['peezisquare'] = 0x333B;
  8146. t['pefinaldageshhebrew'] = 0xFB43;
  8147. t['peharabic'] = 0x067E;
  8148. t['peharmenian'] = 0x057A;
  8149. t['pehebrew'] = 0x05E4;
  8150. t['pehfinalarabic'] = 0xFB57;
  8151. t['pehinitialarabic'] = 0xFB58;
  8152. t['pehiragana'] = 0x307A;
  8153. t['pehmedialarabic'] = 0xFB59;
  8154. t['pekatakana'] = 0x30DA;
  8155. t['pemiddlehookcyrillic'] = 0x04A7;
  8156. t['perafehebrew'] = 0xFB4E;
  8157. t['percent'] = 0x0025;
  8158. t['percentarabic'] = 0x066A;
  8159. t['percentmonospace'] = 0xFF05;
  8160. t['percentsmall'] = 0xFE6A;
  8161. t['period'] = 0x002E;
  8162. t['periodarmenian'] = 0x0589;
  8163. t['periodcentered'] = 0x00B7;
  8164. t['periodhalfwidth'] = 0xFF61;
  8165. t['periodinferior'] = 0xF6E7;
  8166. t['periodmonospace'] = 0xFF0E;
  8167. t['periodsmall'] = 0xFE52;
  8168. t['periodsuperior'] = 0xF6E8;
  8169. t['perispomenigreekcmb'] = 0x0342;
  8170. t['perpendicular'] = 0x22A5;
  8171. t['perthousand'] = 0x2030;
  8172. t['peseta'] = 0x20A7;
  8173. t['pfsquare'] = 0x338A;
  8174. t['phabengali'] = 0x09AB;
  8175. t['phadeva'] = 0x092B;
  8176. t['phagujarati'] = 0x0AAB;
  8177. t['phagurmukhi'] = 0x0A2B;
  8178. t['phi'] = 0x03C6;
  8179. t['phi1'] = 0x03D5;
  8180. t['phieuphacirclekorean'] = 0x327A;
  8181. t['phieuphaparenkorean'] = 0x321A;
  8182. t['phieuphcirclekorean'] = 0x326C;
  8183. t['phieuphkorean'] = 0x314D;
  8184. t['phieuphparenkorean'] = 0x320C;
  8185. t['philatin'] = 0x0278;
  8186. t['phinthuthai'] = 0x0E3A;
  8187. t['phisymbolgreek'] = 0x03D5;
  8188. t['phook'] = 0x01A5;
  8189. t['phophanthai'] = 0x0E1E;
  8190. t['phophungthai'] = 0x0E1C;
  8191. t['phosamphaothai'] = 0x0E20;
  8192. t['pi'] = 0x03C0;
  8193. t['pieupacirclekorean'] = 0x3273;
  8194. t['pieupaparenkorean'] = 0x3213;
  8195. t['pieupcieuckorean'] = 0x3176;
  8196. t['pieupcirclekorean'] = 0x3265;
  8197. t['pieupkiyeokkorean'] = 0x3172;
  8198. t['pieupkorean'] = 0x3142;
  8199. t['pieupparenkorean'] = 0x3205;
  8200. t['pieupsioskiyeokkorean'] = 0x3174;
  8201. t['pieupsioskorean'] = 0x3144;
  8202. t['pieupsiostikeutkorean'] = 0x3175;
  8203. t['pieupthieuthkorean'] = 0x3177;
  8204. t['pieuptikeutkorean'] = 0x3173;
  8205. t['pihiragana'] = 0x3074;
  8206. t['pikatakana'] = 0x30D4;
  8207. t['pisymbolgreek'] = 0x03D6;
  8208. t['piwrarmenian'] = 0x0583;
  8209. t['plus'] = 0x002B;
  8210. t['plusbelowcmb'] = 0x031F;
  8211. t['pluscircle'] = 0x2295;
  8212. t['plusminus'] = 0x00B1;
  8213. t['plusmod'] = 0x02D6;
  8214. t['plusmonospace'] = 0xFF0B;
  8215. t['plussmall'] = 0xFE62;
  8216. t['plussuperior'] = 0x207A;
  8217. t['pmonospace'] = 0xFF50;
  8218. t['pmsquare'] = 0x33D8;
  8219. t['pohiragana'] = 0x307D;
  8220. t['pointingindexdownwhite'] = 0x261F;
  8221. t['pointingindexleftwhite'] = 0x261C;
  8222. t['pointingindexrightwhite'] = 0x261E;
  8223. t['pointingindexupwhite'] = 0x261D;
  8224. t['pokatakana'] = 0x30DD;
  8225. t['poplathai'] = 0x0E1B;
  8226. t['postalmark'] = 0x3012;
  8227. t['postalmarkface'] = 0x3020;
  8228. t['pparen'] = 0x24AB;
  8229. t['precedes'] = 0x227A;
  8230. t['prescription'] = 0x211E;
  8231. t['primemod'] = 0x02B9;
  8232. t['primereversed'] = 0x2035;
  8233. t['product'] = 0x220F;
  8234. t['projective'] = 0x2305;
  8235. t['prolongedkana'] = 0x30FC;
  8236. t['propellor'] = 0x2318;
  8237. t['propersubset'] = 0x2282;
  8238. t['propersuperset'] = 0x2283;
  8239. t['proportion'] = 0x2237;
  8240. t['proportional'] = 0x221D;
  8241. t['psi'] = 0x03C8;
  8242. t['psicyrillic'] = 0x0471;
  8243. t['psilipneumatacyrilliccmb'] = 0x0486;
  8244. t['pssquare'] = 0x33B0;
  8245. t['puhiragana'] = 0x3077;
  8246. t['pukatakana'] = 0x30D7;
  8247. t['pvsquare'] = 0x33B4;
  8248. t['pwsquare'] = 0x33BA;
  8249. t['q'] = 0x0071;
  8250. t['qadeva'] = 0x0958;
  8251. t['qadmahebrew'] = 0x05A8;
  8252. t['qafarabic'] = 0x0642;
  8253. t['qaffinalarabic'] = 0xFED6;
  8254. t['qafinitialarabic'] = 0xFED7;
  8255. t['qafmedialarabic'] = 0xFED8;
  8256. t['qamats'] = 0x05B8;
  8257. t['qamats10'] = 0x05B8;
  8258. t['qamats1a'] = 0x05B8;
  8259. t['qamats1c'] = 0x05B8;
  8260. t['qamats27'] = 0x05B8;
  8261. t['qamats29'] = 0x05B8;
  8262. t['qamats33'] = 0x05B8;
  8263. t['qamatsde'] = 0x05B8;
  8264. t['qamatshebrew'] = 0x05B8;
  8265. t['qamatsnarrowhebrew'] = 0x05B8;
  8266. t['qamatsqatanhebrew'] = 0x05B8;
  8267. t['qamatsqatannarrowhebrew'] = 0x05B8;
  8268. t['qamatsqatanquarterhebrew'] = 0x05B8;
  8269. t['qamatsqatanwidehebrew'] = 0x05B8;
  8270. t['qamatsquarterhebrew'] = 0x05B8;
  8271. t['qamatswidehebrew'] = 0x05B8;
  8272. t['qarneyparahebrew'] = 0x059F;
  8273. t['qbopomofo'] = 0x3111;
  8274. t['qcircle'] = 0x24E0;
  8275. t['qhook'] = 0x02A0;
  8276. t['qmonospace'] = 0xFF51;
  8277. t['qof'] = 0x05E7;
  8278. t['qofdagesh'] = 0xFB47;
  8279. t['qofdageshhebrew'] = 0xFB47;
  8280. t['qofhebrew'] = 0x05E7;
  8281. t['qparen'] = 0x24AC;
  8282. t['quarternote'] = 0x2669;
  8283. t['qubuts'] = 0x05BB;
  8284. t['qubuts18'] = 0x05BB;
  8285. t['qubuts25'] = 0x05BB;
  8286. t['qubuts31'] = 0x05BB;
  8287. t['qubutshebrew'] = 0x05BB;
  8288. t['qubutsnarrowhebrew'] = 0x05BB;
  8289. t['qubutsquarterhebrew'] = 0x05BB;
  8290. t['qubutswidehebrew'] = 0x05BB;
  8291. t['question'] = 0x003F;
  8292. t['questionarabic'] = 0x061F;
  8293. t['questionarmenian'] = 0x055E;
  8294. t['questiondown'] = 0x00BF;
  8295. t['questiondownsmall'] = 0xF7BF;
  8296. t['questiongreek'] = 0x037E;
  8297. t['questionmonospace'] = 0xFF1F;
  8298. t['questionsmall'] = 0xF73F;
  8299. t['quotedbl'] = 0x0022;
  8300. t['quotedblbase'] = 0x201E;
  8301. t['quotedblleft'] = 0x201C;
  8302. t['quotedblmonospace'] = 0xFF02;
  8303. t['quotedblprime'] = 0x301E;
  8304. t['quotedblprimereversed'] = 0x301D;
  8305. t['quotedblright'] = 0x201D;
  8306. t['quoteleft'] = 0x2018;
  8307. t['quoteleftreversed'] = 0x201B;
  8308. t['quotereversed'] = 0x201B;
  8309. t['quoteright'] = 0x2019;
  8310. t['quoterightn'] = 0x0149;
  8311. t['quotesinglbase'] = 0x201A;
  8312. t['quotesingle'] = 0x0027;
  8313. t['quotesinglemonospace'] = 0xFF07;
  8314. t['r'] = 0x0072;
  8315. t['raarmenian'] = 0x057C;
  8316. t['rabengali'] = 0x09B0;
  8317. t['racute'] = 0x0155;
  8318. t['radeva'] = 0x0930;
  8319. t['radical'] = 0x221A;
  8320. t['radicalex'] = 0xF8E5;
  8321. t['radoverssquare'] = 0x33AE;
  8322. t['radoverssquaredsquare'] = 0x33AF;
  8323. t['radsquare'] = 0x33AD;
  8324. t['rafe'] = 0x05BF;
  8325. t['rafehebrew'] = 0x05BF;
  8326. t['ragujarati'] = 0x0AB0;
  8327. t['ragurmukhi'] = 0x0A30;
  8328. t['rahiragana'] = 0x3089;
  8329. t['rakatakana'] = 0x30E9;
  8330. t['rakatakanahalfwidth'] = 0xFF97;
  8331. t['ralowerdiagonalbengali'] = 0x09F1;
  8332. t['ramiddlediagonalbengali'] = 0x09F0;
  8333. t['ramshorn'] = 0x0264;
  8334. t['ratio'] = 0x2236;
  8335. t['rbopomofo'] = 0x3116;
  8336. t['rcaron'] = 0x0159;
  8337. t['rcedilla'] = 0x0157;
  8338. t['rcircle'] = 0x24E1;
  8339. t['rcommaaccent'] = 0x0157;
  8340. t['rdblgrave'] = 0x0211;
  8341. t['rdotaccent'] = 0x1E59;
  8342. t['rdotbelow'] = 0x1E5B;
  8343. t['rdotbelowmacron'] = 0x1E5D;
  8344. t['referencemark'] = 0x203B;
  8345. t['reflexsubset'] = 0x2286;
  8346. t['reflexsuperset'] = 0x2287;
  8347. t['registered'] = 0x00AE;
  8348. t['registersans'] = 0xF8E8;
  8349. t['registerserif'] = 0xF6DA;
  8350. t['reharabic'] = 0x0631;
  8351. t['reharmenian'] = 0x0580;
  8352. t['rehfinalarabic'] = 0xFEAE;
  8353. t['rehiragana'] = 0x308C;
  8354. t['rekatakana'] = 0x30EC;
  8355. t['rekatakanahalfwidth'] = 0xFF9A;
  8356. t['resh'] = 0x05E8;
  8357. t['reshdageshhebrew'] = 0xFB48;
  8358. t['reshhebrew'] = 0x05E8;
  8359. t['reversedtilde'] = 0x223D;
  8360. t['reviahebrew'] = 0x0597;
  8361. t['reviamugrashhebrew'] = 0x0597;
  8362. t['revlogicalnot'] = 0x2310;
  8363. t['rfishhook'] = 0x027E;
  8364. t['rfishhookreversed'] = 0x027F;
  8365. t['rhabengali'] = 0x09DD;
  8366. t['rhadeva'] = 0x095D;
  8367. t['rho'] = 0x03C1;
  8368. t['rhook'] = 0x027D;
  8369. t['rhookturned'] = 0x027B;
  8370. t['rhookturnedsuperior'] = 0x02B5;
  8371. t['rhosymbolgreek'] = 0x03F1;
  8372. t['rhotichookmod'] = 0x02DE;
  8373. t['rieulacirclekorean'] = 0x3271;
  8374. t['rieulaparenkorean'] = 0x3211;
  8375. t['rieulcirclekorean'] = 0x3263;
  8376. t['rieulhieuhkorean'] = 0x3140;
  8377. t['rieulkiyeokkorean'] = 0x313A;
  8378. t['rieulkiyeoksioskorean'] = 0x3169;
  8379. t['rieulkorean'] = 0x3139;
  8380. t['rieulmieumkorean'] = 0x313B;
  8381. t['rieulpansioskorean'] = 0x316C;
  8382. t['rieulparenkorean'] = 0x3203;
  8383. t['rieulphieuphkorean'] = 0x313F;
  8384. t['rieulpieupkorean'] = 0x313C;
  8385. t['rieulpieupsioskorean'] = 0x316B;
  8386. t['rieulsioskorean'] = 0x313D;
  8387. t['rieulthieuthkorean'] = 0x313E;
  8388. t['rieultikeutkorean'] = 0x316A;
  8389. t['rieulyeorinhieuhkorean'] = 0x316D;
  8390. t['rightangle'] = 0x221F;
  8391. t['righttackbelowcmb'] = 0x0319;
  8392. t['righttriangle'] = 0x22BF;
  8393. t['rihiragana'] = 0x308A;
  8394. t['rikatakana'] = 0x30EA;
  8395. t['rikatakanahalfwidth'] = 0xFF98;
  8396. t['ring'] = 0x02DA;
  8397. t['ringbelowcmb'] = 0x0325;
  8398. t['ringcmb'] = 0x030A;
  8399. t['ringhalfleft'] = 0x02BF;
  8400. t['ringhalfleftarmenian'] = 0x0559;
  8401. t['ringhalfleftbelowcmb'] = 0x031C;
  8402. t['ringhalfleftcentered'] = 0x02D3;
  8403. t['ringhalfright'] = 0x02BE;
  8404. t['ringhalfrightbelowcmb'] = 0x0339;
  8405. t['ringhalfrightcentered'] = 0x02D2;
  8406. t['rinvertedbreve'] = 0x0213;
  8407. t['rittorusquare'] = 0x3351;
  8408. t['rlinebelow'] = 0x1E5F;
  8409. t['rlongleg'] = 0x027C;
  8410. t['rlonglegturned'] = 0x027A;
  8411. t['rmonospace'] = 0xFF52;
  8412. t['rohiragana'] = 0x308D;
  8413. t['rokatakana'] = 0x30ED;
  8414. t['rokatakanahalfwidth'] = 0xFF9B;
  8415. t['roruathai'] = 0x0E23;
  8416. t['rparen'] = 0x24AD;
  8417. t['rrabengali'] = 0x09DC;
  8418. t['rradeva'] = 0x0931;
  8419. t['rragurmukhi'] = 0x0A5C;
  8420. t['rreharabic'] = 0x0691;
  8421. t['rrehfinalarabic'] = 0xFB8D;
  8422. t['rrvocalicbengali'] = 0x09E0;
  8423. t['rrvocalicdeva'] = 0x0960;
  8424. t['rrvocalicgujarati'] = 0x0AE0;
  8425. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8426. t['rrvocalicvowelsigndeva'] = 0x0944;
  8427. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8428. t['rsuperior'] = 0xF6F1;
  8429. t['rtblock'] = 0x2590;
  8430. t['rturned'] = 0x0279;
  8431. t['rturnedsuperior'] = 0x02B4;
  8432. t['ruhiragana'] = 0x308B;
  8433. t['rukatakana'] = 0x30EB;
  8434. t['rukatakanahalfwidth'] = 0xFF99;
  8435. t['rupeemarkbengali'] = 0x09F2;
  8436. t['rupeesignbengali'] = 0x09F3;
  8437. t['rupiah'] = 0xF6DD;
  8438. t['ruthai'] = 0x0E24;
  8439. t['rvocalicbengali'] = 0x098B;
  8440. t['rvocalicdeva'] = 0x090B;
  8441. t['rvocalicgujarati'] = 0x0A8B;
  8442. t['rvocalicvowelsignbengali'] = 0x09C3;
  8443. t['rvocalicvowelsigndeva'] = 0x0943;
  8444. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8445. t['s'] = 0x0073;
  8446. t['sabengali'] = 0x09B8;
  8447. t['sacute'] = 0x015B;
  8448. t['sacutedotaccent'] = 0x1E65;
  8449. t['sadarabic'] = 0x0635;
  8450. t['sadeva'] = 0x0938;
  8451. t['sadfinalarabic'] = 0xFEBA;
  8452. t['sadinitialarabic'] = 0xFEBB;
  8453. t['sadmedialarabic'] = 0xFEBC;
  8454. t['sagujarati'] = 0x0AB8;
  8455. t['sagurmukhi'] = 0x0A38;
  8456. t['sahiragana'] = 0x3055;
  8457. t['sakatakana'] = 0x30B5;
  8458. t['sakatakanahalfwidth'] = 0xFF7B;
  8459. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8460. t['samekh'] = 0x05E1;
  8461. t['samekhdagesh'] = 0xFB41;
  8462. t['samekhdageshhebrew'] = 0xFB41;
  8463. t['samekhhebrew'] = 0x05E1;
  8464. t['saraaathai'] = 0x0E32;
  8465. t['saraaethai'] = 0x0E41;
  8466. t['saraaimaimalaithai'] = 0x0E44;
  8467. t['saraaimaimuanthai'] = 0x0E43;
  8468. t['saraamthai'] = 0x0E33;
  8469. t['saraathai'] = 0x0E30;
  8470. t['saraethai'] = 0x0E40;
  8471. t['saraiileftthai'] = 0xF886;
  8472. t['saraiithai'] = 0x0E35;
  8473. t['saraileftthai'] = 0xF885;
  8474. t['saraithai'] = 0x0E34;
  8475. t['saraothai'] = 0x0E42;
  8476. t['saraueeleftthai'] = 0xF888;
  8477. t['saraueethai'] = 0x0E37;
  8478. t['saraueleftthai'] = 0xF887;
  8479. t['sarauethai'] = 0x0E36;
  8480. t['sarauthai'] = 0x0E38;
  8481. t['sarauuthai'] = 0x0E39;
  8482. t['sbopomofo'] = 0x3119;
  8483. t['scaron'] = 0x0161;
  8484. t['scarondotaccent'] = 0x1E67;
  8485. t['scedilla'] = 0x015F;
  8486. t['schwa'] = 0x0259;
  8487. t['schwacyrillic'] = 0x04D9;
  8488. t['schwadieresiscyrillic'] = 0x04DB;
  8489. t['schwahook'] = 0x025A;
  8490. t['scircle'] = 0x24E2;
  8491. t['scircumflex'] = 0x015D;
  8492. t['scommaaccent'] = 0x0219;
  8493. t['sdotaccent'] = 0x1E61;
  8494. t['sdotbelow'] = 0x1E63;
  8495. t['sdotbelowdotaccent'] = 0x1E69;
  8496. t['seagullbelowcmb'] = 0x033C;
  8497. t['second'] = 0x2033;
  8498. t['secondtonechinese'] = 0x02CA;
  8499. t['section'] = 0x00A7;
  8500. t['seenarabic'] = 0x0633;
  8501. t['seenfinalarabic'] = 0xFEB2;
  8502. t['seeninitialarabic'] = 0xFEB3;
  8503. t['seenmedialarabic'] = 0xFEB4;
  8504. t['segol'] = 0x05B6;
  8505. t['segol13'] = 0x05B6;
  8506. t['segol1f'] = 0x05B6;
  8507. t['segol2c'] = 0x05B6;
  8508. t['segolhebrew'] = 0x05B6;
  8509. t['segolnarrowhebrew'] = 0x05B6;
  8510. t['segolquarterhebrew'] = 0x05B6;
  8511. t['segoltahebrew'] = 0x0592;
  8512. t['segolwidehebrew'] = 0x05B6;
  8513. t['seharmenian'] = 0x057D;
  8514. t['sehiragana'] = 0x305B;
  8515. t['sekatakana'] = 0x30BB;
  8516. t['sekatakanahalfwidth'] = 0xFF7E;
  8517. t['semicolon'] = 0x003B;
  8518. t['semicolonarabic'] = 0x061B;
  8519. t['semicolonmonospace'] = 0xFF1B;
  8520. t['semicolonsmall'] = 0xFE54;
  8521. t['semivoicedmarkkana'] = 0x309C;
  8522. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8523. t['sentisquare'] = 0x3322;
  8524. t['sentosquare'] = 0x3323;
  8525. t['seven'] = 0x0037;
  8526. t['sevenarabic'] = 0x0667;
  8527. t['sevenbengali'] = 0x09ED;
  8528. t['sevencircle'] = 0x2466;
  8529. t['sevencircleinversesansserif'] = 0x2790;
  8530. t['sevendeva'] = 0x096D;
  8531. t['seveneighths'] = 0x215E;
  8532. t['sevengujarati'] = 0x0AED;
  8533. t['sevengurmukhi'] = 0x0A6D;
  8534. t['sevenhackarabic'] = 0x0667;
  8535. t['sevenhangzhou'] = 0x3027;
  8536. t['sevenideographicparen'] = 0x3226;
  8537. t['seveninferior'] = 0x2087;
  8538. t['sevenmonospace'] = 0xFF17;
  8539. t['sevenoldstyle'] = 0xF737;
  8540. t['sevenparen'] = 0x247A;
  8541. t['sevenperiod'] = 0x248E;
  8542. t['sevenpersian'] = 0x06F7;
  8543. t['sevenroman'] = 0x2176;
  8544. t['sevensuperior'] = 0x2077;
  8545. t['seventeencircle'] = 0x2470;
  8546. t['seventeenparen'] = 0x2484;
  8547. t['seventeenperiod'] = 0x2498;
  8548. t['seventhai'] = 0x0E57;
  8549. t['sfthyphen'] = 0x00AD;
  8550. t['shaarmenian'] = 0x0577;
  8551. t['shabengali'] = 0x09B6;
  8552. t['shacyrillic'] = 0x0448;
  8553. t['shaddaarabic'] = 0x0651;
  8554. t['shaddadammaarabic'] = 0xFC61;
  8555. t['shaddadammatanarabic'] = 0xFC5E;
  8556. t['shaddafathaarabic'] = 0xFC60;
  8557. t['shaddakasraarabic'] = 0xFC62;
  8558. t['shaddakasratanarabic'] = 0xFC5F;
  8559. t['shade'] = 0x2592;
  8560. t['shadedark'] = 0x2593;
  8561. t['shadelight'] = 0x2591;
  8562. t['shademedium'] = 0x2592;
  8563. t['shadeva'] = 0x0936;
  8564. t['shagujarati'] = 0x0AB6;
  8565. t['shagurmukhi'] = 0x0A36;
  8566. t['shalshelethebrew'] = 0x0593;
  8567. t['shbopomofo'] = 0x3115;
  8568. t['shchacyrillic'] = 0x0449;
  8569. t['sheenarabic'] = 0x0634;
  8570. t['sheenfinalarabic'] = 0xFEB6;
  8571. t['sheeninitialarabic'] = 0xFEB7;
  8572. t['sheenmedialarabic'] = 0xFEB8;
  8573. t['sheicoptic'] = 0x03E3;
  8574. t['sheqel'] = 0x20AA;
  8575. t['sheqelhebrew'] = 0x20AA;
  8576. t['sheva'] = 0x05B0;
  8577. t['sheva115'] = 0x05B0;
  8578. t['sheva15'] = 0x05B0;
  8579. t['sheva22'] = 0x05B0;
  8580. t['sheva2e'] = 0x05B0;
  8581. t['shevahebrew'] = 0x05B0;
  8582. t['shevanarrowhebrew'] = 0x05B0;
  8583. t['shevaquarterhebrew'] = 0x05B0;
  8584. t['shevawidehebrew'] = 0x05B0;
  8585. t['shhacyrillic'] = 0x04BB;
  8586. t['shimacoptic'] = 0x03ED;
  8587. t['shin'] = 0x05E9;
  8588. t['shindagesh'] = 0xFB49;
  8589. t['shindageshhebrew'] = 0xFB49;
  8590. t['shindageshshindot'] = 0xFB2C;
  8591. t['shindageshshindothebrew'] = 0xFB2C;
  8592. t['shindageshsindot'] = 0xFB2D;
  8593. t['shindageshsindothebrew'] = 0xFB2D;
  8594. t['shindothebrew'] = 0x05C1;
  8595. t['shinhebrew'] = 0x05E9;
  8596. t['shinshindot'] = 0xFB2A;
  8597. t['shinshindothebrew'] = 0xFB2A;
  8598. t['shinsindot'] = 0xFB2B;
  8599. t['shinsindothebrew'] = 0xFB2B;
  8600. t['shook'] = 0x0282;
  8601. t['sigma'] = 0x03C3;
  8602. t['sigma1'] = 0x03C2;
  8603. t['sigmafinal'] = 0x03C2;
  8604. t['sigmalunatesymbolgreek'] = 0x03F2;
  8605. t['sihiragana'] = 0x3057;
  8606. t['sikatakana'] = 0x30B7;
  8607. t['sikatakanahalfwidth'] = 0xFF7C;
  8608. t['siluqhebrew'] = 0x05BD;
  8609. t['siluqlefthebrew'] = 0x05BD;
  8610. t['similar'] = 0x223C;
  8611. t['sindothebrew'] = 0x05C2;
  8612. t['siosacirclekorean'] = 0x3274;
  8613. t['siosaparenkorean'] = 0x3214;
  8614. t['sioscieuckorean'] = 0x317E;
  8615. t['sioscirclekorean'] = 0x3266;
  8616. t['sioskiyeokkorean'] = 0x317A;
  8617. t['sioskorean'] = 0x3145;
  8618. t['siosnieunkorean'] = 0x317B;
  8619. t['siosparenkorean'] = 0x3206;
  8620. t['siospieupkorean'] = 0x317D;
  8621. t['siostikeutkorean'] = 0x317C;
  8622. t['six'] = 0x0036;
  8623. t['sixarabic'] = 0x0666;
  8624. t['sixbengali'] = 0x09EC;
  8625. t['sixcircle'] = 0x2465;
  8626. t['sixcircleinversesansserif'] = 0x278F;
  8627. t['sixdeva'] = 0x096C;
  8628. t['sixgujarati'] = 0x0AEC;
  8629. t['sixgurmukhi'] = 0x0A6C;
  8630. t['sixhackarabic'] = 0x0666;
  8631. t['sixhangzhou'] = 0x3026;
  8632. t['sixideographicparen'] = 0x3225;
  8633. t['sixinferior'] = 0x2086;
  8634. t['sixmonospace'] = 0xFF16;
  8635. t['sixoldstyle'] = 0xF736;
  8636. t['sixparen'] = 0x2479;
  8637. t['sixperiod'] = 0x248D;
  8638. t['sixpersian'] = 0x06F6;
  8639. t['sixroman'] = 0x2175;
  8640. t['sixsuperior'] = 0x2076;
  8641. t['sixteencircle'] = 0x246F;
  8642. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8643. t['sixteenparen'] = 0x2483;
  8644. t['sixteenperiod'] = 0x2497;
  8645. t['sixthai'] = 0x0E56;
  8646. t['slash'] = 0x002F;
  8647. t['slashmonospace'] = 0xFF0F;
  8648. t['slong'] = 0x017F;
  8649. t['slongdotaccent'] = 0x1E9B;
  8650. t['smileface'] = 0x263A;
  8651. t['smonospace'] = 0xFF53;
  8652. t['sofpasuqhebrew'] = 0x05C3;
  8653. t['softhyphen'] = 0x00AD;
  8654. t['softsigncyrillic'] = 0x044C;
  8655. t['sohiragana'] = 0x305D;
  8656. t['sokatakana'] = 0x30BD;
  8657. t['sokatakanahalfwidth'] = 0xFF7F;
  8658. t['soliduslongoverlaycmb'] = 0x0338;
  8659. t['solidusshortoverlaycmb'] = 0x0337;
  8660. t['sorusithai'] = 0x0E29;
  8661. t['sosalathai'] = 0x0E28;
  8662. t['sosothai'] = 0x0E0B;
  8663. t['sosuathai'] = 0x0E2A;
  8664. t['space'] = 0x0020;
  8665. t['spacehackarabic'] = 0x0020;
  8666. t['spade'] = 0x2660;
  8667. t['spadesuitblack'] = 0x2660;
  8668. t['spadesuitwhite'] = 0x2664;
  8669. t['sparen'] = 0x24AE;
  8670. t['squarebelowcmb'] = 0x033B;
  8671. t['squarecc'] = 0x33C4;
  8672. t['squarecm'] = 0x339D;
  8673. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8674. t['squarehorizontalfill'] = 0x25A4;
  8675. t['squarekg'] = 0x338F;
  8676. t['squarekm'] = 0x339E;
  8677. t['squarekmcapital'] = 0x33CE;
  8678. t['squareln'] = 0x33D1;
  8679. t['squarelog'] = 0x33D2;
  8680. t['squaremg'] = 0x338E;
  8681. t['squaremil'] = 0x33D5;
  8682. t['squaremm'] = 0x339C;
  8683. t['squaremsquared'] = 0x33A1;
  8684. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8685. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8686. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8687. t['squareverticalfill'] = 0x25A5;
  8688. t['squarewhitewithsmallblack'] = 0x25A3;
  8689. t['srsquare'] = 0x33DB;
  8690. t['ssabengali'] = 0x09B7;
  8691. t['ssadeva'] = 0x0937;
  8692. t['ssagujarati'] = 0x0AB7;
  8693. t['ssangcieuckorean'] = 0x3149;
  8694. t['ssanghieuhkorean'] = 0x3185;
  8695. t['ssangieungkorean'] = 0x3180;
  8696. t['ssangkiyeokkorean'] = 0x3132;
  8697. t['ssangnieunkorean'] = 0x3165;
  8698. t['ssangpieupkorean'] = 0x3143;
  8699. t['ssangsioskorean'] = 0x3146;
  8700. t['ssangtikeutkorean'] = 0x3138;
  8701. t['ssuperior'] = 0xF6F2;
  8702. t['sterling'] = 0x00A3;
  8703. t['sterlingmonospace'] = 0xFFE1;
  8704. t['strokelongoverlaycmb'] = 0x0336;
  8705. t['strokeshortoverlaycmb'] = 0x0335;
  8706. t['subset'] = 0x2282;
  8707. t['subsetnotequal'] = 0x228A;
  8708. t['subsetorequal'] = 0x2286;
  8709. t['succeeds'] = 0x227B;
  8710. t['suchthat'] = 0x220B;
  8711. t['suhiragana'] = 0x3059;
  8712. t['sukatakana'] = 0x30B9;
  8713. t['sukatakanahalfwidth'] = 0xFF7D;
  8714. t['sukunarabic'] = 0x0652;
  8715. t['summation'] = 0x2211;
  8716. t['sun'] = 0x263C;
  8717. t['superset'] = 0x2283;
  8718. t['supersetnotequal'] = 0x228B;
  8719. t['supersetorequal'] = 0x2287;
  8720. t['svsquare'] = 0x33DC;
  8721. t['syouwaerasquare'] = 0x337C;
  8722. t['t'] = 0x0074;
  8723. t['tabengali'] = 0x09A4;
  8724. t['tackdown'] = 0x22A4;
  8725. t['tackleft'] = 0x22A3;
  8726. t['tadeva'] = 0x0924;
  8727. t['tagujarati'] = 0x0AA4;
  8728. t['tagurmukhi'] = 0x0A24;
  8729. t['taharabic'] = 0x0637;
  8730. t['tahfinalarabic'] = 0xFEC2;
  8731. t['tahinitialarabic'] = 0xFEC3;
  8732. t['tahiragana'] = 0x305F;
  8733. t['tahmedialarabic'] = 0xFEC4;
  8734. t['taisyouerasquare'] = 0x337D;
  8735. t['takatakana'] = 0x30BF;
  8736. t['takatakanahalfwidth'] = 0xFF80;
  8737. t['tatweelarabic'] = 0x0640;
  8738. t['tau'] = 0x03C4;
  8739. t['tav'] = 0x05EA;
  8740. t['tavdages'] = 0xFB4A;
  8741. t['tavdagesh'] = 0xFB4A;
  8742. t['tavdageshhebrew'] = 0xFB4A;
  8743. t['tavhebrew'] = 0x05EA;
  8744. t['tbar'] = 0x0167;
  8745. t['tbopomofo'] = 0x310A;
  8746. t['tcaron'] = 0x0165;
  8747. t['tccurl'] = 0x02A8;
  8748. t['tcedilla'] = 0x0163;
  8749. t['tcheharabic'] = 0x0686;
  8750. t['tchehfinalarabic'] = 0xFB7B;
  8751. t['tchehinitialarabic'] = 0xFB7C;
  8752. t['tchehmedialarabic'] = 0xFB7D;
  8753. t['tcircle'] = 0x24E3;
  8754. t['tcircumflexbelow'] = 0x1E71;
  8755. t['tcommaaccent'] = 0x0163;
  8756. t['tdieresis'] = 0x1E97;
  8757. t['tdotaccent'] = 0x1E6B;
  8758. t['tdotbelow'] = 0x1E6D;
  8759. t['tecyrillic'] = 0x0442;
  8760. t['tedescendercyrillic'] = 0x04AD;
  8761. t['teharabic'] = 0x062A;
  8762. t['tehfinalarabic'] = 0xFE96;
  8763. t['tehhahinitialarabic'] = 0xFCA2;
  8764. t['tehhahisolatedarabic'] = 0xFC0C;
  8765. t['tehinitialarabic'] = 0xFE97;
  8766. t['tehiragana'] = 0x3066;
  8767. t['tehjeeminitialarabic'] = 0xFCA1;
  8768. t['tehjeemisolatedarabic'] = 0xFC0B;
  8769. t['tehmarbutaarabic'] = 0x0629;
  8770. t['tehmarbutafinalarabic'] = 0xFE94;
  8771. t['tehmedialarabic'] = 0xFE98;
  8772. t['tehmeeminitialarabic'] = 0xFCA4;
  8773. t['tehmeemisolatedarabic'] = 0xFC0E;
  8774. t['tehnoonfinalarabic'] = 0xFC73;
  8775. t['tekatakana'] = 0x30C6;
  8776. t['tekatakanahalfwidth'] = 0xFF83;
  8777. t['telephone'] = 0x2121;
  8778. t['telephoneblack'] = 0x260E;
  8779. t['telishagedolahebrew'] = 0x05A0;
  8780. t['telishaqetanahebrew'] = 0x05A9;
  8781. t['tencircle'] = 0x2469;
  8782. t['tenideographicparen'] = 0x3229;
  8783. t['tenparen'] = 0x247D;
  8784. t['tenperiod'] = 0x2491;
  8785. t['tenroman'] = 0x2179;
  8786. t['tesh'] = 0x02A7;
  8787. t['tet'] = 0x05D8;
  8788. t['tetdagesh'] = 0xFB38;
  8789. t['tetdageshhebrew'] = 0xFB38;
  8790. t['tethebrew'] = 0x05D8;
  8791. t['tetsecyrillic'] = 0x04B5;
  8792. t['tevirhebrew'] = 0x059B;
  8793. t['tevirlefthebrew'] = 0x059B;
  8794. t['thabengali'] = 0x09A5;
  8795. t['thadeva'] = 0x0925;
  8796. t['thagujarati'] = 0x0AA5;
  8797. t['thagurmukhi'] = 0x0A25;
  8798. t['thalarabic'] = 0x0630;
  8799. t['thalfinalarabic'] = 0xFEAC;
  8800. t['thanthakhatlowleftthai'] = 0xF898;
  8801. t['thanthakhatlowrightthai'] = 0xF897;
  8802. t['thanthakhatthai'] = 0x0E4C;
  8803. t['thanthakhatupperleftthai'] = 0xF896;
  8804. t['theharabic'] = 0x062B;
  8805. t['thehfinalarabic'] = 0xFE9A;
  8806. t['thehinitialarabic'] = 0xFE9B;
  8807. t['thehmedialarabic'] = 0xFE9C;
  8808. t['thereexists'] = 0x2203;
  8809. t['therefore'] = 0x2234;
  8810. t['theta'] = 0x03B8;
  8811. t['theta1'] = 0x03D1;
  8812. t['thetasymbolgreek'] = 0x03D1;
  8813. t['thieuthacirclekorean'] = 0x3279;
  8814. t['thieuthaparenkorean'] = 0x3219;
  8815. t['thieuthcirclekorean'] = 0x326B;
  8816. t['thieuthkorean'] = 0x314C;
  8817. t['thieuthparenkorean'] = 0x320B;
  8818. t['thirteencircle'] = 0x246C;
  8819. t['thirteenparen'] = 0x2480;
  8820. t['thirteenperiod'] = 0x2494;
  8821. t['thonangmonthothai'] = 0x0E11;
  8822. t['thook'] = 0x01AD;
  8823. t['thophuthaothai'] = 0x0E12;
  8824. t['thorn'] = 0x00FE;
  8825. t['thothahanthai'] = 0x0E17;
  8826. t['thothanthai'] = 0x0E10;
  8827. t['thothongthai'] = 0x0E18;
  8828. t['thothungthai'] = 0x0E16;
  8829. t['thousandcyrillic'] = 0x0482;
  8830. t['thousandsseparatorarabic'] = 0x066C;
  8831. t['thousandsseparatorpersian'] = 0x066C;
  8832. t['three'] = 0x0033;
  8833. t['threearabic'] = 0x0663;
  8834. t['threebengali'] = 0x09E9;
  8835. t['threecircle'] = 0x2462;
  8836. t['threecircleinversesansserif'] = 0x278C;
  8837. t['threedeva'] = 0x0969;
  8838. t['threeeighths'] = 0x215C;
  8839. t['threegujarati'] = 0x0AE9;
  8840. t['threegurmukhi'] = 0x0A69;
  8841. t['threehackarabic'] = 0x0663;
  8842. t['threehangzhou'] = 0x3023;
  8843. t['threeideographicparen'] = 0x3222;
  8844. t['threeinferior'] = 0x2083;
  8845. t['threemonospace'] = 0xFF13;
  8846. t['threenumeratorbengali'] = 0x09F6;
  8847. t['threeoldstyle'] = 0xF733;
  8848. t['threeparen'] = 0x2476;
  8849. t['threeperiod'] = 0x248A;
  8850. t['threepersian'] = 0x06F3;
  8851. t['threequarters'] = 0x00BE;
  8852. t['threequartersemdash'] = 0xF6DE;
  8853. t['threeroman'] = 0x2172;
  8854. t['threesuperior'] = 0x00B3;
  8855. t['threethai'] = 0x0E53;
  8856. t['thzsquare'] = 0x3394;
  8857. t['tihiragana'] = 0x3061;
  8858. t['tikatakana'] = 0x30C1;
  8859. t['tikatakanahalfwidth'] = 0xFF81;
  8860. t['tikeutacirclekorean'] = 0x3270;
  8861. t['tikeutaparenkorean'] = 0x3210;
  8862. t['tikeutcirclekorean'] = 0x3262;
  8863. t['tikeutkorean'] = 0x3137;
  8864. t['tikeutparenkorean'] = 0x3202;
  8865. t['tilde'] = 0x02DC;
  8866. t['tildebelowcmb'] = 0x0330;
  8867. t['tildecmb'] = 0x0303;
  8868. t['tildecomb'] = 0x0303;
  8869. t['tildedoublecmb'] = 0x0360;
  8870. t['tildeoperator'] = 0x223C;
  8871. t['tildeoverlaycmb'] = 0x0334;
  8872. t['tildeverticalcmb'] = 0x033E;
  8873. t['timescircle'] = 0x2297;
  8874. t['tipehahebrew'] = 0x0596;
  8875. t['tipehalefthebrew'] = 0x0596;
  8876. t['tippigurmukhi'] = 0x0A70;
  8877. t['titlocyrilliccmb'] = 0x0483;
  8878. t['tiwnarmenian'] = 0x057F;
  8879. t['tlinebelow'] = 0x1E6F;
  8880. t['tmonospace'] = 0xFF54;
  8881. t['toarmenian'] = 0x0569;
  8882. t['tohiragana'] = 0x3068;
  8883. t['tokatakana'] = 0x30C8;
  8884. t['tokatakanahalfwidth'] = 0xFF84;
  8885. t['tonebarextrahighmod'] = 0x02E5;
  8886. t['tonebarextralowmod'] = 0x02E9;
  8887. t['tonebarhighmod'] = 0x02E6;
  8888. t['tonebarlowmod'] = 0x02E8;
  8889. t['tonebarmidmod'] = 0x02E7;
  8890. t['tonefive'] = 0x01BD;
  8891. t['tonesix'] = 0x0185;
  8892. t['tonetwo'] = 0x01A8;
  8893. t['tonos'] = 0x0384;
  8894. t['tonsquare'] = 0x3327;
  8895. t['topatakthai'] = 0x0E0F;
  8896. t['tortoiseshellbracketleft'] = 0x3014;
  8897. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8898. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8899. t['tortoiseshellbracketright'] = 0x3015;
  8900. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8901. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8902. t['totaothai'] = 0x0E15;
  8903. t['tpalatalhook'] = 0x01AB;
  8904. t['tparen'] = 0x24AF;
  8905. t['trademark'] = 0x2122;
  8906. t['trademarksans'] = 0xF8EA;
  8907. t['trademarkserif'] = 0xF6DB;
  8908. t['tretroflexhook'] = 0x0288;
  8909. t['triagdn'] = 0x25BC;
  8910. t['triaglf'] = 0x25C4;
  8911. t['triagrt'] = 0x25BA;
  8912. t['triagup'] = 0x25B2;
  8913. t['ts'] = 0x02A6;
  8914. t['tsadi'] = 0x05E6;
  8915. t['tsadidagesh'] = 0xFB46;
  8916. t['tsadidageshhebrew'] = 0xFB46;
  8917. t['tsadihebrew'] = 0x05E6;
  8918. t['tsecyrillic'] = 0x0446;
  8919. t['tsere'] = 0x05B5;
  8920. t['tsere12'] = 0x05B5;
  8921. t['tsere1e'] = 0x05B5;
  8922. t['tsere2b'] = 0x05B5;
  8923. t['tserehebrew'] = 0x05B5;
  8924. t['tserenarrowhebrew'] = 0x05B5;
  8925. t['tserequarterhebrew'] = 0x05B5;
  8926. t['tserewidehebrew'] = 0x05B5;
  8927. t['tshecyrillic'] = 0x045B;
  8928. t['tsuperior'] = 0xF6F3;
  8929. t['ttabengali'] = 0x099F;
  8930. t['ttadeva'] = 0x091F;
  8931. t['ttagujarati'] = 0x0A9F;
  8932. t['ttagurmukhi'] = 0x0A1F;
  8933. t['tteharabic'] = 0x0679;
  8934. t['ttehfinalarabic'] = 0xFB67;
  8935. t['ttehinitialarabic'] = 0xFB68;
  8936. t['ttehmedialarabic'] = 0xFB69;
  8937. t['tthabengali'] = 0x09A0;
  8938. t['tthadeva'] = 0x0920;
  8939. t['tthagujarati'] = 0x0AA0;
  8940. t['tthagurmukhi'] = 0x0A20;
  8941. t['tturned'] = 0x0287;
  8942. t['tuhiragana'] = 0x3064;
  8943. t['tukatakana'] = 0x30C4;
  8944. t['tukatakanahalfwidth'] = 0xFF82;
  8945. t['tusmallhiragana'] = 0x3063;
  8946. t['tusmallkatakana'] = 0x30C3;
  8947. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8948. t['twelvecircle'] = 0x246B;
  8949. t['twelveparen'] = 0x247F;
  8950. t['twelveperiod'] = 0x2493;
  8951. t['twelveroman'] = 0x217B;
  8952. t['twentycircle'] = 0x2473;
  8953. t['twentyhangzhou'] = 0x5344;
  8954. t['twentyparen'] = 0x2487;
  8955. t['twentyperiod'] = 0x249B;
  8956. t['two'] = 0x0032;
  8957. t['twoarabic'] = 0x0662;
  8958. t['twobengali'] = 0x09E8;
  8959. t['twocircle'] = 0x2461;
  8960. t['twocircleinversesansserif'] = 0x278B;
  8961. t['twodeva'] = 0x0968;
  8962. t['twodotenleader'] = 0x2025;
  8963. t['twodotleader'] = 0x2025;
  8964. t['twodotleadervertical'] = 0xFE30;
  8965. t['twogujarati'] = 0x0AE8;
  8966. t['twogurmukhi'] = 0x0A68;
  8967. t['twohackarabic'] = 0x0662;
  8968. t['twohangzhou'] = 0x3022;
  8969. t['twoideographicparen'] = 0x3221;
  8970. t['twoinferior'] = 0x2082;
  8971. t['twomonospace'] = 0xFF12;
  8972. t['twonumeratorbengali'] = 0x09F5;
  8973. t['twooldstyle'] = 0xF732;
  8974. t['twoparen'] = 0x2475;
  8975. t['twoperiod'] = 0x2489;
  8976. t['twopersian'] = 0x06F2;
  8977. t['tworoman'] = 0x2171;
  8978. t['twostroke'] = 0x01BB;
  8979. t['twosuperior'] = 0x00B2;
  8980. t['twothai'] = 0x0E52;
  8981. t['twothirds'] = 0x2154;
  8982. t['u'] = 0x0075;
  8983. t['uacute'] = 0x00FA;
  8984. t['ubar'] = 0x0289;
  8985. t['ubengali'] = 0x0989;
  8986. t['ubopomofo'] = 0x3128;
  8987. t['ubreve'] = 0x016D;
  8988. t['ucaron'] = 0x01D4;
  8989. t['ucircle'] = 0x24E4;
  8990. t['ucircumflex'] = 0x00FB;
  8991. t['ucircumflexbelow'] = 0x1E77;
  8992. t['ucyrillic'] = 0x0443;
  8993. t['udattadeva'] = 0x0951;
  8994. t['udblacute'] = 0x0171;
  8995. t['udblgrave'] = 0x0215;
  8996. t['udeva'] = 0x0909;
  8997. t['udieresis'] = 0x00FC;
  8998. t['udieresisacute'] = 0x01D8;
  8999. t['udieresisbelow'] = 0x1E73;
  9000. t['udieresiscaron'] = 0x01DA;
  9001. t['udieresiscyrillic'] = 0x04F1;
  9002. t['udieresisgrave'] = 0x01DC;
  9003. t['udieresismacron'] = 0x01D6;
  9004. t['udotbelow'] = 0x1EE5;
  9005. t['ugrave'] = 0x00F9;
  9006. t['ugujarati'] = 0x0A89;
  9007. t['ugurmukhi'] = 0x0A09;
  9008. t['uhiragana'] = 0x3046;
  9009. t['uhookabove'] = 0x1EE7;
  9010. t['uhorn'] = 0x01B0;
  9011. t['uhornacute'] = 0x1EE9;
  9012. t['uhorndotbelow'] = 0x1EF1;
  9013. t['uhorngrave'] = 0x1EEB;
  9014. t['uhornhookabove'] = 0x1EED;
  9015. t['uhorntilde'] = 0x1EEF;
  9016. t['uhungarumlaut'] = 0x0171;
  9017. t['uhungarumlautcyrillic'] = 0x04F3;
  9018. t['uinvertedbreve'] = 0x0217;
  9019. t['ukatakana'] = 0x30A6;
  9020. t['ukatakanahalfwidth'] = 0xFF73;
  9021. t['ukcyrillic'] = 0x0479;
  9022. t['ukorean'] = 0x315C;
  9023. t['umacron'] = 0x016B;
  9024. t['umacroncyrillic'] = 0x04EF;
  9025. t['umacrondieresis'] = 0x1E7B;
  9026. t['umatragurmukhi'] = 0x0A41;
  9027. t['umonospace'] = 0xFF55;
  9028. t['underscore'] = 0x005F;
  9029. t['underscoredbl'] = 0x2017;
  9030. t['underscoremonospace'] = 0xFF3F;
  9031. t['underscorevertical'] = 0xFE33;
  9032. t['underscorewavy'] = 0xFE4F;
  9033. t['union'] = 0x222A;
  9034. t['universal'] = 0x2200;
  9035. t['uogonek'] = 0x0173;
  9036. t['uparen'] = 0x24B0;
  9037. t['upblock'] = 0x2580;
  9038. t['upperdothebrew'] = 0x05C4;
  9039. t['upsilon'] = 0x03C5;
  9040. t['upsilondieresis'] = 0x03CB;
  9041. t['upsilondieresistonos'] = 0x03B0;
  9042. t['upsilonlatin'] = 0x028A;
  9043. t['upsilontonos'] = 0x03CD;
  9044. t['uptackbelowcmb'] = 0x031D;
  9045. t['uptackmod'] = 0x02D4;
  9046. t['uragurmukhi'] = 0x0A73;
  9047. t['uring'] = 0x016F;
  9048. t['ushortcyrillic'] = 0x045E;
  9049. t['usmallhiragana'] = 0x3045;
  9050. t['usmallkatakana'] = 0x30A5;
  9051. t['usmallkatakanahalfwidth'] = 0xFF69;
  9052. t['ustraightcyrillic'] = 0x04AF;
  9053. t['ustraightstrokecyrillic'] = 0x04B1;
  9054. t['utilde'] = 0x0169;
  9055. t['utildeacute'] = 0x1E79;
  9056. t['utildebelow'] = 0x1E75;
  9057. t['uubengali'] = 0x098A;
  9058. t['uudeva'] = 0x090A;
  9059. t['uugujarati'] = 0x0A8A;
  9060. t['uugurmukhi'] = 0x0A0A;
  9061. t['uumatragurmukhi'] = 0x0A42;
  9062. t['uuvowelsignbengali'] = 0x09C2;
  9063. t['uuvowelsigndeva'] = 0x0942;
  9064. t['uuvowelsigngujarati'] = 0x0AC2;
  9065. t['uvowelsignbengali'] = 0x09C1;
  9066. t['uvowelsigndeva'] = 0x0941;
  9067. t['uvowelsigngujarati'] = 0x0AC1;
  9068. t['v'] = 0x0076;
  9069. t['vadeva'] = 0x0935;
  9070. t['vagujarati'] = 0x0AB5;
  9071. t['vagurmukhi'] = 0x0A35;
  9072. t['vakatakana'] = 0x30F7;
  9073. t['vav'] = 0x05D5;
  9074. t['vavdagesh'] = 0xFB35;
  9075. t['vavdagesh65'] = 0xFB35;
  9076. t['vavdageshhebrew'] = 0xFB35;
  9077. t['vavhebrew'] = 0x05D5;
  9078. t['vavholam'] = 0xFB4B;
  9079. t['vavholamhebrew'] = 0xFB4B;
  9080. t['vavvavhebrew'] = 0x05F0;
  9081. t['vavyodhebrew'] = 0x05F1;
  9082. t['vcircle'] = 0x24E5;
  9083. t['vdotbelow'] = 0x1E7F;
  9084. t['vecyrillic'] = 0x0432;
  9085. t['veharabic'] = 0x06A4;
  9086. t['vehfinalarabic'] = 0xFB6B;
  9087. t['vehinitialarabic'] = 0xFB6C;
  9088. t['vehmedialarabic'] = 0xFB6D;
  9089. t['vekatakana'] = 0x30F9;
  9090. t['venus'] = 0x2640;
  9091. t['verticalbar'] = 0x007C;
  9092. t['verticallineabovecmb'] = 0x030D;
  9093. t['verticallinebelowcmb'] = 0x0329;
  9094. t['verticallinelowmod'] = 0x02CC;
  9095. t['verticallinemod'] = 0x02C8;
  9096. t['vewarmenian'] = 0x057E;
  9097. t['vhook'] = 0x028B;
  9098. t['vikatakana'] = 0x30F8;
  9099. t['viramabengali'] = 0x09CD;
  9100. t['viramadeva'] = 0x094D;
  9101. t['viramagujarati'] = 0x0ACD;
  9102. t['visargabengali'] = 0x0983;
  9103. t['visargadeva'] = 0x0903;
  9104. t['visargagujarati'] = 0x0A83;
  9105. t['vmonospace'] = 0xFF56;
  9106. t['voarmenian'] = 0x0578;
  9107. t['voicediterationhiragana'] = 0x309E;
  9108. t['voicediterationkatakana'] = 0x30FE;
  9109. t['voicedmarkkana'] = 0x309B;
  9110. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  9111. t['vokatakana'] = 0x30FA;
  9112. t['vparen'] = 0x24B1;
  9113. t['vtilde'] = 0x1E7D;
  9114. t['vturned'] = 0x028C;
  9115. t['vuhiragana'] = 0x3094;
  9116. t['vukatakana'] = 0x30F4;
  9117. t['w'] = 0x0077;
  9118. t['wacute'] = 0x1E83;
  9119. t['waekorean'] = 0x3159;
  9120. t['wahiragana'] = 0x308F;
  9121. t['wakatakana'] = 0x30EF;
  9122. t['wakatakanahalfwidth'] = 0xFF9C;
  9123. t['wakorean'] = 0x3158;
  9124. t['wasmallhiragana'] = 0x308E;
  9125. t['wasmallkatakana'] = 0x30EE;
  9126. t['wattosquare'] = 0x3357;
  9127. t['wavedash'] = 0x301C;
  9128. t['wavyunderscorevertical'] = 0xFE34;
  9129. t['wawarabic'] = 0x0648;
  9130. t['wawfinalarabic'] = 0xFEEE;
  9131. t['wawhamzaabovearabic'] = 0x0624;
  9132. t['wawhamzaabovefinalarabic'] = 0xFE86;
  9133. t['wbsquare'] = 0x33DD;
  9134. t['wcircle'] = 0x24E6;
  9135. t['wcircumflex'] = 0x0175;
  9136. t['wdieresis'] = 0x1E85;
  9137. t['wdotaccent'] = 0x1E87;
  9138. t['wdotbelow'] = 0x1E89;
  9139. t['wehiragana'] = 0x3091;
  9140. t['weierstrass'] = 0x2118;
  9141. t['wekatakana'] = 0x30F1;
  9142. t['wekorean'] = 0x315E;
  9143. t['weokorean'] = 0x315D;
  9144. t['wgrave'] = 0x1E81;
  9145. t['whitebullet'] = 0x25E6;
  9146. t['whitecircle'] = 0x25CB;
  9147. t['whitecircleinverse'] = 0x25D9;
  9148. t['whitecornerbracketleft'] = 0x300E;
  9149. t['whitecornerbracketleftvertical'] = 0xFE43;
  9150. t['whitecornerbracketright'] = 0x300F;
  9151. t['whitecornerbracketrightvertical'] = 0xFE44;
  9152. t['whitediamond'] = 0x25C7;
  9153. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  9154. t['whitedownpointingsmalltriangle'] = 0x25BF;
  9155. t['whitedownpointingtriangle'] = 0x25BD;
  9156. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  9157. t['whiteleftpointingtriangle'] = 0x25C1;
  9158. t['whitelenticularbracketleft'] = 0x3016;
  9159. t['whitelenticularbracketright'] = 0x3017;
  9160. t['whiterightpointingsmalltriangle'] = 0x25B9;
  9161. t['whiterightpointingtriangle'] = 0x25B7;
  9162. t['whitesmallsquare'] = 0x25AB;
  9163. t['whitesmilingface'] = 0x263A;
  9164. t['whitesquare'] = 0x25A1;
  9165. t['whitestar'] = 0x2606;
  9166. t['whitetelephone'] = 0x260F;
  9167. t['whitetortoiseshellbracketleft'] = 0x3018;
  9168. t['whitetortoiseshellbracketright'] = 0x3019;
  9169. t['whiteuppointingsmalltriangle'] = 0x25B5;
  9170. t['whiteuppointingtriangle'] = 0x25B3;
  9171. t['wihiragana'] = 0x3090;
  9172. t['wikatakana'] = 0x30F0;
  9173. t['wikorean'] = 0x315F;
  9174. t['wmonospace'] = 0xFF57;
  9175. t['wohiragana'] = 0x3092;
  9176. t['wokatakana'] = 0x30F2;
  9177. t['wokatakanahalfwidth'] = 0xFF66;
  9178. t['won'] = 0x20A9;
  9179. t['wonmonospace'] = 0xFFE6;
  9180. t['wowaenthai'] = 0x0E27;
  9181. t['wparen'] = 0x24B2;
  9182. t['wring'] = 0x1E98;
  9183. t['wsuperior'] = 0x02B7;
  9184. t['wturned'] = 0x028D;
  9185. t['wynn'] = 0x01BF;
  9186. t['x'] = 0x0078;
  9187. t['xabovecmb'] = 0x033D;
  9188. t['xbopomofo'] = 0x3112;
  9189. t['xcircle'] = 0x24E7;
  9190. t['xdieresis'] = 0x1E8D;
  9191. t['xdotaccent'] = 0x1E8B;
  9192. t['xeharmenian'] = 0x056D;
  9193. t['xi'] = 0x03BE;
  9194. t['xmonospace'] = 0xFF58;
  9195. t['xparen'] = 0x24B3;
  9196. t['xsuperior'] = 0x02E3;
  9197. t['y'] = 0x0079;
  9198. t['yaadosquare'] = 0x334E;
  9199. t['yabengali'] = 0x09AF;
  9200. t['yacute'] = 0x00FD;
  9201. t['yadeva'] = 0x092F;
  9202. t['yaekorean'] = 0x3152;
  9203. t['yagujarati'] = 0x0AAF;
  9204. t['yagurmukhi'] = 0x0A2F;
  9205. t['yahiragana'] = 0x3084;
  9206. t['yakatakana'] = 0x30E4;
  9207. t['yakatakanahalfwidth'] = 0xFF94;
  9208. t['yakorean'] = 0x3151;
  9209. t['yamakkanthai'] = 0x0E4E;
  9210. t['yasmallhiragana'] = 0x3083;
  9211. t['yasmallkatakana'] = 0x30E3;
  9212. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  9213. t['yatcyrillic'] = 0x0463;
  9214. t['ycircle'] = 0x24E8;
  9215. t['ycircumflex'] = 0x0177;
  9216. t['ydieresis'] = 0x00FF;
  9217. t['ydotaccent'] = 0x1E8F;
  9218. t['ydotbelow'] = 0x1EF5;
  9219. t['yeharabic'] = 0x064A;
  9220. t['yehbarreearabic'] = 0x06D2;
  9221. t['yehbarreefinalarabic'] = 0xFBAF;
  9222. t['yehfinalarabic'] = 0xFEF2;
  9223. t['yehhamzaabovearabic'] = 0x0626;
  9224. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  9225. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  9226. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  9227. t['yehinitialarabic'] = 0xFEF3;
  9228. t['yehmedialarabic'] = 0xFEF4;
  9229. t['yehmeeminitialarabic'] = 0xFCDD;
  9230. t['yehmeemisolatedarabic'] = 0xFC58;
  9231. t['yehnoonfinalarabic'] = 0xFC94;
  9232. t['yehthreedotsbelowarabic'] = 0x06D1;
  9233. t['yekorean'] = 0x3156;
  9234. t['yen'] = 0x00A5;
  9235. t['yenmonospace'] = 0xFFE5;
  9236. t['yeokorean'] = 0x3155;
  9237. t['yeorinhieuhkorean'] = 0x3186;
  9238. t['yerahbenyomohebrew'] = 0x05AA;
  9239. t['yerahbenyomolefthebrew'] = 0x05AA;
  9240. t['yericyrillic'] = 0x044B;
  9241. t['yerudieresiscyrillic'] = 0x04F9;
  9242. t['yesieungkorean'] = 0x3181;
  9243. t['yesieungpansioskorean'] = 0x3183;
  9244. t['yesieungsioskorean'] = 0x3182;
  9245. t['yetivhebrew'] = 0x059A;
  9246. t['ygrave'] = 0x1EF3;
  9247. t['yhook'] = 0x01B4;
  9248. t['yhookabove'] = 0x1EF7;
  9249. t['yiarmenian'] = 0x0575;
  9250. t['yicyrillic'] = 0x0457;
  9251. t['yikorean'] = 0x3162;
  9252. t['yinyang'] = 0x262F;
  9253. t['yiwnarmenian'] = 0x0582;
  9254. t['ymonospace'] = 0xFF59;
  9255. t['yod'] = 0x05D9;
  9256. t['yoddagesh'] = 0xFB39;
  9257. t['yoddageshhebrew'] = 0xFB39;
  9258. t['yodhebrew'] = 0x05D9;
  9259. t['yodyodhebrew'] = 0x05F2;
  9260. t['yodyodpatahhebrew'] = 0xFB1F;
  9261. t['yohiragana'] = 0x3088;
  9262. t['yoikorean'] = 0x3189;
  9263. t['yokatakana'] = 0x30E8;
  9264. t['yokatakanahalfwidth'] = 0xFF96;
  9265. t['yokorean'] = 0x315B;
  9266. t['yosmallhiragana'] = 0x3087;
  9267. t['yosmallkatakana'] = 0x30E7;
  9268. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  9269. t['yotgreek'] = 0x03F3;
  9270. t['yoyaekorean'] = 0x3188;
  9271. t['yoyakorean'] = 0x3187;
  9272. t['yoyakthai'] = 0x0E22;
  9273. t['yoyingthai'] = 0x0E0D;
  9274. t['yparen'] = 0x24B4;
  9275. t['ypogegrammeni'] = 0x037A;
  9276. t['ypogegrammenigreekcmb'] = 0x0345;
  9277. t['yr'] = 0x01A6;
  9278. t['yring'] = 0x1E99;
  9279. t['ysuperior'] = 0x02B8;
  9280. t['ytilde'] = 0x1EF9;
  9281. t['yturned'] = 0x028E;
  9282. t['yuhiragana'] = 0x3086;
  9283. t['yuikorean'] = 0x318C;
  9284. t['yukatakana'] = 0x30E6;
  9285. t['yukatakanahalfwidth'] = 0xFF95;
  9286. t['yukorean'] = 0x3160;
  9287. t['yusbigcyrillic'] = 0x046B;
  9288. t['yusbigiotifiedcyrillic'] = 0x046D;
  9289. t['yuslittlecyrillic'] = 0x0467;
  9290. t['yuslittleiotifiedcyrillic'] = 0x0469;
  9291. t['yusmallhiragana'] = 0x3085;
  9292. t['yusmallkatakana'] = 0x30E5;
  9293. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  9294. t['yuyekorean'] = 0x318B;
  9295. t['yuyeokorean'] = 0x318A;
  9296. t['yyabengali'] = 0x09DF;
  9297. t['yyadeva'] = 0x095F;
  9298. t['z'] = 0x007A;
  9299. t['zaarmenian'] = 0x0566;
  9300. t['zacute'] = 0x017A;
  9301. t['zadeva'] = 0x095B;
  9302. t['zagurmukhi'] = 0x0A5B;
  9303. t['zaharabic'] = 0x0638;
  9304. t['zahfinalarabic'] = 0xFEC6;
  9305. t['zahinitialarabic'] = 0xFEC7;
  9306. t['zahiragana'] = 0x3056;
  9307. t['zahmedialarabic'] = 0xFEC8;
  9308. t['zainarabic'] = 0x0632;
  9309. t['zainfinalarabic'] = 0xFEB0;
  9310. t['zakatakana'] = 0x30B6;
  9311. t['zaqefgadolhebrew'] = 0x0595;
  9312. t['zaqefqatanhebrew'] = 0x0594;
  9313. t['zarqahebrew'] = 0x0598;
  9314. t['zayin'] = 0x05D6;
  9315. t['zayindagesh'] = 0xFB36;
  9316. t['zayindageshhebrew'] = 0xFB36;
  9317. t['zayinhebrew'] = 0x05D6;
  9318. t['zbopomofo'] = 0x3117;
  9319. t['zcaron'] = 0x017E;
  9320. t['zcircle'] = 0x24E9;
  9321. t['zcircumflex'] = 0x1E91;
  9322. t['zcurl'] = 0x0291;
  9323. t['zdot'] = 0x017C;
  9324. t['zdotaccent'] = 0x017C;
  9325. t['zdotbelow'] = 0x1E93;
  9326. t['zecyrillic'] = 0x0437;
  9327. t['zedescendercyrillic'] = 0x0499;
  9328. t['zedieresiscyrillic'] = 0x04DF;
  9329. t['zehiragana'] = 0x305C;
  9330. t['zekatakana'] = 0x30BC;
  9331. t['zero'] = 0x0030;
  9332. t['zeroarabic'] = 0x0660;
  9333. t['zerobengali'] = 0x09E6;
  9334. t['zerodeva'] = 0x0966;
  9335. t['zerogujarati'] = 0x0AE6;
  9336. t['zerogurmukhi'] = 0x0A66;
  9337. t['zerohackarabic'] = 0x0660;
  9338. t['zeroinferior'] = 0x2080;
  9339. t['zeromonospace'] = 0xFF10;
  9340. t['zerooldstyle'] = 0xF730;
  9341. t['zeropersian'] = 0x06F0;
  9342. t['zerosuperior'] = 0x2070;
  9343. t['zerothai'] = 0x0E50;
  9344. t['zerowidthjoiner'] = 0xFEFF;
  9345. t['zerowidthnonjoiner'] = 0x200C;
  9346. t['zerowidthspace'] = 0x200B;
  9347. t['zeta'] = 0x03B6;
  9348. t['zhbopomofo'] = 0x3113;
  9349. t['zhearmenian'] = 0x056A;
  9350. t['zhebrevecyrillic'] = 0x04C2;
  9351. t['zhecyrillic'] = 0x0436;
  9352. t['zhedescendercyrillic'] = 0x0497;
  9353. t['zhedieresiscyrillic'] = 0x04DD;
  9354. t['zihiragana'] = 0x3058;
  9355. t['zikatakana'] = 0x30B8;
  9356. t['zinorhebrew'] = 0x05AE;
  9357. t['zlinebelow'] = 0x1E95;
  9358. t['zmonospace'] = 0xFF5A;
  9359. t['zohiragana'] = 0x305E;
  9360. t['zokatakana'] = 0x30BE;
  9361. t['zparen'] = 0x24B5;
  9362. t['zretroflexhook'] = 0x0290;
  9363. t['zstroke'] = 0x01B6;
  9364. t['zuhiragana'] = 0x305A;
  9365. t['zukatakana'] = 0x30BA;
  9366. t['.notdef'] = 0x0000;
  9367. });
  9368. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9369. t['space'] = 0x0020;
  9370. t['a1'] = 0x2701;
  9371. t['a2'] = 0x2702;
  9372. t['a202'] = 0x2703;
  9373. t['a3'] = 0x2704;
  9374. t['a4'] = 0x260E;
  9375. t['a5'] = 0x2706;
  9376. t['a119'] = 0x2707;
  9377. t['a118'] = 0x2708;
  9378. t['a117'] = 0x2709;
  9379. t['a11'] = 0x261B;
  9380. t['a12'] = 0x261E;
  9381. t['a13'] = 0x270C;
  9382. t['a14'] = 0x270D;
  9383. t['a15'] = 0x270E;
  9384. t['a16'] = 0x270F;
  9385. t['a105'] = 0x2710;
  9386. t['a17'] = 0x2711;
  9387. t['a18'] = 0x2712;
  9388. t['a19'] = 0x2713;
  9389. t['a20'] = 0x2714;
  9390. t['a21'] = 0x2715;
  9391. t['a22'] = 0x2716;
  9392. t['a23'] = 0x2717;
  9393. t['a24'] = 0x2718;
  9394. t['a25'] = 0x2719;
  9395. t['a26'] = 0x271A;
  9396. t['a27'] = 0x271B;
  9397. t['a28'] = 0x271C;
  9398. t['a6'] = 0x271D;
  9399. t['a7'] = 0x271E;
  9400. t['a8'] = 0x271F;
  9401. t['a9'] = 0x2720;
  9402. t['a10'] = 0x2721;
  9403. t['a29'] = 0x2722;
  9404. t['a30'] = 0x2723;
  9405. t['a31'] = 0x2724;
  9406. t['a32'] = 0x2725;
  9407. t['a33'] = 0x2726;
  9408. t['a34'] = 0x2727;
  9409. t['a35'] = 0x2605;
  9410. t['a36'] = 0x2729;
  9411. t['a37'] = 0x272A;
  9412. t['a38'] = 0x272B;
  9413. t['a39'] = 0x272C;
  9414. t['a40'] = 0x272D;
  9415. t['a41'] = 0x272E;
  9416. t['a42'] = 0x272F;
  9417. t['a43'] = 0x2730;
  9418. t['a44'] = 0x2731;
  9419. t['a45'] = 0x2732;
  9420. t['a46'] = 0x2733;
  9421. t['a47'] = 0x2734;
  9422. t['a48'] = 0x2735;
  9423. t['a49'] = 0x2736;
  9424. t['a50'] = 0x2737;
  9425. t['a51'] = 0x2738;
  9426. t['a52'] = 0x2739;
  9427. t['a53'] = 0x273A;
  9428. t['a54'] = 0x273B;
  9429. t['a55'] = 0x273C;
  9430. t['a56'] = 0x273D;
  9431. t['a57'] = 0x273E;
  9432. t['a58'] = 0x273F;
  9433. t['a59'] = 0x2740;
  9434. t['a60'] = 0x2741;
  9435. t['a61'] = 0x2742;
  9436. t['a62'] = 0x2743;
  9437. t['a63'] = 0x2744;
  9438. t['a64'] = 0x2745;
  9439. t['a65'] = 0x2746;
  9440. t['a66'] = 0x2747;
  9441. t['a67'] = 0x2748;
  9442. t['a68'] = 0x2749;
  9443. t['a69'] = 0x274A;
  9444. t['a70'] = 0x274B;
  9445. t['a71'] = 0x25CF;
  9446. t['a72'] = 0x274D;
  9447. t['a73'] = 0x25A0;
  9448. t['a74'] = 0x274F;
  9449. t['a203'] = 0x2750;
  9450. t['a75'] = 0x2751;
  9451. t['a204'] = 0x2752;
  9452. t['a76'] = 0x25B2;
  9453. t['a77'] = 0x25BC;
  9454. t['a78'] = 0x25C6;
  9455. t['a79'] = 0x2756;
  9456. t['a81'] = 0x25D7;
  9457. t['a82'] = 0x2758;
  9458. t['a83'] = 0x2759;
  9459. t['a84'] = 0x275A;
  9460. t['a97'] = 0x275B;
  9461. t['a98'] = 0x275C;
  9462. t['a99'] = 0x275D;
  9463. t['a100'] = 0x275E;
  9464. t['a101'] = 0x2761;
  9465. t['a102'] = 0x2762;
  9466. t['a103'] = 0x2763;
  9467. t['a104'] = 0x2764;
  9468. t['a106'] = 0x2765;
  9469. t['a107'] = 0x2766;
  9470. t['a108'] = 0x2767;
  9471. t['a112'] = 0x2663;
  9472. t['a111'] = 0x2666;
  9473. t['a110'] = 0x2665;
  9474. t['a109'] = 0x2660;
  9475. t['a120'] = 0x2460;
  9476. t['a121'] = 0x2461;
  9477. t['a122'] = 0x2462;
  9478. t['a123'] = 0x2463;
  9479. t['a124'] = 0x2464;
  9480. t['a125'] = 0x2465;
  9481. t['a126'] = 0x2466;
  9482. t['a127'] = 0x2467;
  9483. t['a128'] = 0x2468;
  9484. t['a129'] = 0x2469;
  9485. t['a130'] = 0x2776;
  9486. t['a131'] = 0x2777;
  9487. t['a132'] = 0x2778;
  9488. t['a133'] = 0x2779;
  9489. t['a134'] = 0x277A;
  9490. t['a135'] = 0x277B;
  9491. t['a136'] = 0x277C;
  9492. t['a137'] = 0x277D;
  9493. t['a138'] = 0x277E;
  9494. t['a139'] = 0x277F;
  9495. t['a140'] = 0x2780;
  9496. t['a141'] = 0x2781;
  9497. t['a142'] = 0x2782;
  9498. t['a143'] = 0x2783;
  9499. t['a144'] = 0x2784;
  9500. t['a145'] = 0x2785;
  9501. t['a146'] = 0x2786;
  9502. t['a147'] = 0x2787;
  9503. t['a148'] = 0x2788;
  9504. t['a149'] = 0x2789;
  9505. t['a150'] = 0x278A;
  9506. t['a151'] = 0x278B;
  9507. t['a152'] = 0x278C;
  9508. t['a153'] = 0x278D;
  9509. t['a154'] = 0x278E;
  9510. t['a155'] = 0x278F;
  9511. t['a156'] = 0x2790;
  9512. t['a157'] = 0x2791;
  9513. t['a158'] = 0x2792;
  9514. t['a159'] = 0x2793;
  9515. t['a160'] = 0x2794;
  9516. t['a161'] = 0x2192;
  9517. t['a163'] = 0x2194;
  9518. t['a164'] = 0x2195;
  9519. t['a196'] = 0x2798;
  9520. t['a165'] = 0x2799;
  9521. t['a192'] = 0x279A;
  9522. t['a166'] = 0x279B;
  9523. t['a167'] = 0x279C;
  9524. t['a168'] = 0x279D;
  9525. t['a169'] = 0x279E;
  9526. t['a170'] = 0x279F;
  9527. t['a171'] = 0x27A0;
  9528. t['a172'] = 0x27A1;
  9529. t['a173'] = 0x27A2;
  9530. t['a162'] = 0x27A3;
  9531. t['a174'] = 0x27A4;
  9532. t['a175'] = 0x27A5;
  9533. t['a176'] = 0x27A6;
  9534. t['a177'] = 0x27A7;
  9535. t['a178'] = 0x27A8;
  9536. t['a179'] = 0x27A9;
  9537. t['a193'] = 0x27AA;
  9538. t['a180'] = 0x27AB;
  9539. t['a199'] = 0x27AC;
  9540. t['a181'] = 0x27AD;
  9541. t['a200'] = 0x27AE;
  9542. t['a182'] = 0x27AF;
  9543. t['a201'] = 0x27B1;
  9544. t['a183'] = 0x27B2;
  9545. t['a184'] = 0x27B3;
  9546. t['a197'] = 0x27B4;
  9547. t['a185'] = 0x27B5;
  9548. t['a194'] = 0x27B6;
  9549. t['a198'] = 0x27B7;
  9550. t['a186'] = 0x27B8;
  9551. t['a195'] = 0x27B9;
  9552. t['a187'] = 0x27BA;
  9553. t['a188'] = 0x27BB;
  9554. t['a189'] = 0x27BC;
  9555. t['a190'] = 0x27BD;
  9556. t['a191'] = 0x27BE;
  9557. t['a89'] = 0x2768; // 0xF8D7
  9558. t['a90'] = 0x2769; // 0xF8D8
  9559. t['a93'] = 0x276A; // 0xF8D9
  9560. t['a94'] = 0x276B; // 0xF8DA
  9561. t['a91'] = 0x276C; // 0xF8DB
  9562. t['a92'] = 0x276D; // 0xF8DC
  9563. t['a205'] = 0x276E; // 0xF8DD
  9564. t['a85'] = 0x276F; // 0xF8DE
  9565. t['a206'] = 0x2770; // 0xF8DF
  9566. t['a86'] = 0x2771; // 0xF8E0
  9567. t['a87'] = 0x2772; // 0xF8E1
  9568. t['a88'] = 0x2773; // 0xF8E2
  9569. t['a95'] = 0x2774; // 0xF8E3
  9570. t['a96'] = 0x2775; // 0xF8E4
  9571. t['.notdef'] = 0x0000;
  9572. });
  9573. exports.getGlyphsUnicode = getGlyphsUnicode;
  9574. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9575. }));
  9576. (function (root, factory) {
  9577. {
  9578. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9579. root.pdfjsCoreArithmeticDecoder);
  9580. }
  9581. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9582. var error = sharedUtil.error;
  9583. var log2 = sharedUtil.log2;
  9584. var readInt8 = sharedUtil.readInt8;
  9585. var readUint16 = sharedUtil.readUint16;
  9586. var readUint32 = sharedUtil.readUint32;
  9587. var shadow = sharedUtil.shadow;
  9588. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9589. var Jbig2Image = (function Jbig2ImageClosure() {
  9590. // Utility data structures
  9591. function ContextCache() {}
  9592. ContextCache.prototype = {
  9593. getContexts: function(id) {
  9594. if (id in this) {
  9595. return this[id];
  9596. }
  9597. return (this[id] = new Int8Array(1 << 16));
  9598. }
  9599. };
  9600. function DecodingContext(data, start, end) {
  9601. this.data = data;
  9602. this.start = start;
  9603. this.end = end;
  9604. }
  9605. DecodingContext.prototype = {
  9606. get decoder() {
  9607. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9608. return shadow(this, 'decoder', decoder);
  9609. },
  9610. get contextCache() {
  9611. var cache = new ContextCache();
  9612. return shadow(this, 'contextCache', cache);
  9613. }
  9614. };
  9615. // Annex A. Arithmetic Integer Decoding Procedure
  9616. // A.2 Procedure for decoding values
  9617. function decodeInteger(contextCache, procedure, decoder) {
  9618. var contexts = contextCache.getContexts(procedure);
  9619. var prev = 1;
  9620. function readBits(length) {
  9621. var v = 0;
  9622. for (var i = 0; i < length; i++) {
  9623. var bit = decoder.readBit(contexts, prev);
  9624. prev = (prev < 256 ? (prev << 1) | bit :
  9625. (((prev << 1) | bit) & 511) | 256);
  9626. v = (v << 1) | bit;
  9627. }
  9628. return v >>> 0;
  9629. }
  9630. var sign = readBits(1);
  9631. var value = readBits(1) ?
  9632. (readBits(1) ?
  9633. (readBits(1) ?
  9634. (readBits(1) ?
  9635. (readBits(1) ?
  9636. (readBits(32) + 4436) :
  9637. readBits(12) + 340) :
  9638. readBits(8) + 84) :
  9639. readBits(6) + 20) :
  9640. readBits(4) + 4) :
  9641. readBits(2);
  9642. return (sign === 0 ? value : (value > 0 ? -value : null));
  9643. }
  9644. // A.3 The IAID decoding procedure
  9645. function decodeIAID(contextCache, decoder, codeLength) {
  9646. var contexts = contextCache.getContexts('IAID');
  9647. var prev = 1;
  9648. for (var i = 0; i < codeLength; i++) {
  9649. var bit = decoder.readBit(contexts, prev);
  9650. prev = (prev << 1) | bit;
  9651. }
  9652. if (codeLength < 31) {
  9653. return prev & ((1 << codeLength) - 1);
  9654. }
  9655. return prev & 0x7FFFFFFF;
  9656. }
  9657. // 7.3 Segment types
  9658. var SegmentTypes = [
  9659. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9660. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9661. null, null, null, null, null, 'patternDictionary', null, null, null,
  9662. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9663. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9664. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9665. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9666. 'IntermediateGenericRefinementRegion', null,
  9667. 'ImmediateGenericRefinementRegion',
  9668. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9669. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9670. 'Tables', null, null, null, null, null, null, null, null,
  9671. 'Extension'
  9672. ];
  9673. var CodingTemplates = [
  9674. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9675. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9676. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9677. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9678. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9679. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9680. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9681. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9682. {x: -1, y: 0}],
  9683. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9684. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9685. ];
  9686. var RefinementTemplates = [
  9687. {
  9688. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9689. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9690. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9691. },
  9692. {
  9693. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9694. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9695. {x: 0, y: 1}, {x: 1, y: 1}]
  9696. }
  9697. ];
  9698. // See 6.2.5.7 Decoding the bitmap.
  9699. var ReusedContexts = [
  9700. 0x9B25, // 10011 0110010 0101
  9701. 0x0795, // 0011 110010 101
  9702. 0x00E5, // 001 11001 01
  9703. 0x0195 // 011001 0101
  9704. ];
  9705. var RefinementReusedContexts = [
  9706. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9707. 0x0008 // '0000' + '001000'
  9708. ];
  9709. function decodeBitmapTemplate0(width, height, decodingContext) {
  9710. var decoder = decodingContext.decoder;
  9711. var contexts = decodingContext.contextCache.getContexts('GB');
  9712. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9713. // ...ooooo....
  9714. // ..ooooooo... Context template for current pixel (X)
  9715. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9716. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9717. for (i = 0; i < height; i++) {
  9718. row = bitmap[i] = new Uint8Array(width);
  9719. row1 = (i < 1) ? row : bitmap[i - 1];
  9720. row2 = (i < 2) ? row : bitmap[i - 2];
  9721. // At the beginning of each row:
  9722. // Fill contextLabel with pixels that are above/right of (X)
  9723. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9724. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9725. (row1[3] << 4);
  9726. for (j = 0; j < width; j++) {
  9727. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9728. // At each pixel: Clear contextLabel pixels that are shifted
  9729. // out of the context, then add new ones.
  9730. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9731. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9732. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9733. }
  9734. }
  9735. return bitmap;
  9736. }
  9737. // 6.2 Generic Region Decoding Procedure
  9738. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9739. decodingContext) {
  9740. if (mmr) {
  9741. error('JBIG2 error: MMR encoding is not supported');
  9742. }
  9743. // Use optimized version for the most common case
  9744. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9745. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9746. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9747. return decodeBitmapTemplate0(width, height, decodingContext);
  9748. }
  9749. var useskip = !!skip;
  9750. var template = CodingTemplates[templateIndex].concat(at);
  9751. // Sorting is non-standard, and it is not required. But sorting increases
  9752. // the number of template bits that can be reused from the previous
  9753. // contextLabel in the main loop.
  9754. template.sort(function (a, b) {
  9755. return (a.y - b.y) || (a.x - b.x);
  9756. });
  9757. var templateLength = template.length;
  9758. var templateX = new Int8Array(templateLength);
  9759. var templateY = new Int8Array(templateLength);
  9760. var changingTemplateEntries = [];
  9761. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9762. var c, k;
  9763. for (k = 0; k < templateLength; k++) {
  9764. templateX[k] = template[k].x;
  9765. templateY[k] = template[k].y;
  9766. minX = Math.min(minX, template[k].x);
  9767. maxX = Math.max(maxX, template[k].x);
  9768. minY = Math.min(minY, template[k].y);
  9769. // Check if the template pixel appears in two consecutive context labels,
  9770. // so it can be reused. Otherwise, we add it to the list of changing
  9771. // template entries.
  9772. if (k < templateLength - 1 &&
  9773. template[k].y === template[k + 1].y &&
  9774. template[k].x === template[k + 1].x - 1) {
  9775. reuseMask |= 1 << (templateLength - 1 - k);
  9776. } else {
  9777. changingTemplateEntries.push(k);
  9778. }
  9779. }
  9780. var changingEntriesLength = changingTemplateEntries.length;
  9781. var changingTemplateX = new Int8Array(changingEntriesLength);
  9782. var changingTemplateY = new Int8Array(changingEntriesLength);
  9783. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9784. for (c = 0; c < changingEntriesLength; c++) {
  9785. k = changingTemplateEntries[c];
  9786. changingTemplateX[c] = template[k].x;
  9787. changingTemplateY[c] = template[k].y;
  9788. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9789. }
  9790. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9791. var sbb_left = -minX;
  9792. var sbb_top = -minY;
  9793. var sbb_right = width - maxX;
  9794. var pseudoPixelContext = ReusedContexts[templateIndex];
  9795. var row = new Uint8Array(width);
  9796. var bitmap = [];
  9797. var decoder = decodingContext.decoder;
  9798. var contexts = decodingContext.contextCache.getContexts('GB');
  9799. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9800. for (var i = 0; i < height; i++) {
  9801. if (prediction) {
  9802. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9803. ltp ^= sltp;
  9804. if (ltp) {
  9805. bitmap.push(row); // duplicate previous row
  9806. continue;
  9807. }
  9808. }
  9809. row = new Uint8Array(row);
  9810. bitmap.push(row);
  9811. for (j = 0; j < width; j++) {
  9812. if (useskip && skip[i][j]) {
  9813. row[j] = 0;
  9814. continue;
  9815. }
  9816. // Are we in the middle of a scanline, so we can reuse contextLabel
  9817. // bits?
  9818. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9819. // If yes, we can just shift the bits that are reusable and only
  9820. // fetch the remaining ones.
  9821. contextLabel = (contextLabel << 1) & reuseMask;
  9822. for (k = 0; k < changingEntriesLength; k++) {
  9823. i0 = i + changingTemplateY[k];
  9824. j0 = j + changingTemplateX[k];
  9825. bit = bitmap[i0][j0];
  9826. if (bit) {
  9827. bit = changingTemplateBit[k];
  9828. contextLabel |= bit;
  9829. }
  9830. }
  9831. } else {
  9832. // compute the contextLabel from scratch
  9833. contextLabel = 0;
  9834. shift = templateLength - 1;
  9835. for (k = 0; k < templateLength; k++, shift--) {
  9836. j0 = j + templateX[k];
  9837. if (j0 >= 0 && j0 < width) {
  9838. i0 = i + templateY[k];
  9839. if (i0 >= 0) {
  9840. bit = bitmap[i0][j0];
  9841. if (bit) {
  9842. contextLabel |= bit << shift;
  9843. }
  9844. }
  9845. }
  9846. }
  9847. }
  9848. var pixel = decoder.readBit(contexts, contextLabel);
  9849. row[j] = pixel;
  9850. }
  9851. }
  9852. return bitmap;
  9853. }
  9854. // 6.3.2 Generic Refinement Region Decoding Procedure
  9855. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9856. offsetX, offsetY, prediction, at,
  9857. decodingContext) {
  9858. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9859. if (templateIndex === 0) {
  9860. codingTemplate = codingTemplate.concat([at[0]]);
  9861. }
  9862. var codingTemplateLength = codingTemplate.length;
  9863. var codingTemplateX = new Int32Array(codingTemplateLength);
  9864. var codingTemplateY = new Int32Array(codingTemplateLength);
  9865. var k;
  9866. for (k = 0; k < codingTemplateLength; k++) {
  9867. codingTemplateX[k] = codingTemplate[k].x;
  9868. codingTemplateY[k] = codingTemplate[k].y;
  9869. }
  9870. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9871. if (templateIndex === 0) {
  9872. referenceTemplate = referenceTemplate.concat([at[1]]);
  9873. }
  9874. var referenceTemplateLength = referenceTemplate.length;
  9875. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9876. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9877. for (k = 0; k < referenceTemplateLength; k++) {
  9878. referenceTemplateX[k] = referenceTemplate[k].x;
  9879. referenceTemplateY[k] = referenceTemplate[k].y;
  9880. }
  9881. var referenceWidth = referenceBitmap[0].length;
  9882. var referenceHeight = referenceBitmap.length;
  9883. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9884. var bitmap = [];
  9885. var decoder = decodingContext.decoder;
  9886. var contexts = decodingContext.contextCache.getContexts('GR');
  9887. var ltp = 0;
  9888. for (var i = 0; i < height; i++) {
  9889. if (prediction) {
  9890. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9891. ltp ^= sltp;
  9892. if (ltp) {
  9893. error('JBIG2 error: prediction is not supported');
  9894. }
  9895. }
  9896. var row = new Uint8Array(width);
  9897. bitmap.push(row);
  9898. for (var j = 0; j < width; j++) {
  9899. var i0, j0;
  9900. var contextLabel = 0;
  9901. for (k = 0; k < codingTemplateLength; k++) {
  9902. i0 = i + codingTemplateY[k];
  9903. j0 = j + codingTemplateX[k];
  9904. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9905. contextLabel <<= 1; // out of bound pixel
  9906. } else {
  9907. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9908. }
  9909. }
  9910. for (k = 0; k < referenceTemplateLength; k++) {
  9911. i0 = i + referenceTemplateY[k] + offsetY;
  9912. j0 = j + referenceTemplateX[k] + offsetX;
  9913. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9914. j0 >= referenceWidth) {
  9915. contextLabel <<= 1; // out of bound pixel
  9916. } else {
  9917. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9918. }
  9919. }
  9920. var pixel = decoder.readBit(contexts, contextLabel);
  9921. row[j] = pixel;
  9922. }
  9923. }
  9924. return bitmap;
  9925. }
  9926. // 6.5.5 Decoding the symbol dictionary
  9927. function decodeSymbolDictionary(huffman, refinement, symbols,
  9928. numberOfNewSymbols, numberOfExportedSymbols,
  9929. huffmanTables, templateIndex, at,
  9930. refinementTemplateIndex, refinementAt,
  9931. decodingContext) {
  9932. if (huffman) {
  9933. error('JBIG2 error: huffman is not supported');
  9934. }
  9935. var newSymbols = [];
  9936. var currentHeight = 0;
  9937. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9938. var decoder = decodingContext.decoder;
  9939. var contextCache = decodingContext.contextCache;
  9940. while (newSymbols.length < numberOfNewSymbols) {
  9941. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9942. currentHeight += deltaHeight;
  9943. var currentWidth = 0;
  9944. var totalWidth = 0;
  9945. while (true) {
  9946. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9947. if (deltaWidth === null) {
  9948. break; // OOB
  9949. }
  9950. currentWidth += deltaWidth;
  9951. totalWidth += currentWidth;
  9952. var bitmap;
  9953. if (refinement) {
  9954. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9955. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9956. if (numberOfInstances > 1) {
  9957. bitmap = decodeTextRegion(huffman, refinement,
  9958. currentWidth, currentHeight, 0,
  9959. numberOfInstances, 1, //strip size
  9960. symbols.concat(newSymbols),
  9961. symbolCodeLength,
  9962. 0, //transposed
  9963. 0, //ds offset
  9964. 1, //top left 7.4.3.1.1
  9965. 0, //OR operator
  9966. huffmanTables,
  9967. refinementTemplateIndex, refinementAt,
  9968. decodingContext);
  9969. } else {
  9970. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9971. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9972. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9973. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9974. newSymbols[symbolId - symbols.length]);
  9975. bitmap = decodeRefinement(currentWidth, currentHeight,
  9976. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9977. decodingContext);
  9978. }
  9979. } else {
  9980. // 6.5.8.1 Direct-coded symbol bitmap
  9981. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  9982. templateIndex, false, null, at, decodingContext);
  9983. }
  9984. newSymbols.push(bitmap);
  9985. }
  9986. }
  9987. // 6.5.10 Exported symbols
  9988. var exportedSymbols = [];
  9989. var flags = [], currentFlag = false;
  9990. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  9991. while (flags.length < totalSymbolsLength) {
  9992. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  9993. while (runLength--) {
  9994. flags.push(currentFlag);
  9995. }
  9996. currentFlag = !currentFlag;
  9997. }
  9998. for (var i = 0, ii = symbols.length; i < ii; i++) {
  9999. if (flags[i]) {
  10000. exportedSymbols.push(symbols[i]);
  10001. }
  10002. }
  10003. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10004. if (flags[i]) {
  10005. exportedSymbols.push(newSymbols[j]);
  10006. }
  10007. }
  10008. return exportedSymbols;
  10009. }
  10010. function decodeTextRegion(huffman, refinement, width, height,
  10011. defaultPixelValue, numberOfSymbolInstances,
  10012. stripSize, inputSymbols, symbolCodeLength,
  10013. transposed, dsOffset, referenceCorner,
  10014. combinationOperator, huffmanTables,
  10015. refinementTemplateIndex, refinementAt,
  10016. decodingContext) {
  10017. if (huffman) {
  10018. error('JBIG2 error: huffman is not supported');
  10019. }
  10020. // Prepare bitmap
  10021. var bitmap = [];
  10022. var i, row;
  10023. for (i = 0; i < height; i++) {
  10024. row = new Uint8Array(width);
  10025. if (defaultPixelValue) {
  10026. for (var j = 0; j < width; j++) {
  10027. row[j] = defaultPixelValue;
  10028. }
  10029. }
  10030. bitmap.push(row);
  10031. }
  10032. var decoder = decodingContext.decoder;
  10033. var contextCache = decodingContext.contextCache;
  10034. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10035. var firstS = 0;
  10036. i = 0;
  10037. while (i < numberOfSymbolInstances) {
  10038. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10039. stripT += deltaT;
  10040. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10041. firstS += deltaFirstS;
  10042. var currentS = firstS;
  10043. do {
  10044. var currentT = (stripSize === 1 ? 0 :
  10045. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10046. var t = stripSize * stripT + currentT;
  10047. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10048. var applyRefinement = (refinement &&
  10049. decodeInteger(contextCache, 'IARI', decoder));
  10050. var symbolBitmap = inputSymbols[symbolId];
  10051. var symbolWidth = symbolBitmap[0].length;
  10052. var symbolHeight = symbolBitmap.length;
  10053. if (applyRefinement) {
  10054. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10055. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10056. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10057. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10058. symbolWidth += rdw;
  10059. symbolHeight += rdh;
  10060. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10061. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10062. (rdh >> 1) + rdy, false, refinementAt,
  10063. decodingContext);
  10064. }
  10065. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10066. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10067. var s2, t2, symbolRow;
  10068. if (transposed) {
  10069. // Place Symbol Bitmap from T1,S1
  10070. for (s2 = 0; s2 < symbolHeight; s2++) {
  10071. row = bitmap[offsetS + s2];
  10072. if (!row) {
  10073. continue;
  10074. }
  10075. symbolRow = symbolBitmap[s2];
  10076. // To ignore Parts of Symbol bitmap which goes
  10077. // outside bitmap region
  10078. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10079. switch (combinationOperator) {
  10080. case 0: // OR
  10081. for (t2 = 0; t2 < maxWidth; t2++) {
  10082. row[offsetT + t2] |= symbolRow[t2];
  10083. }
  10084. break;
  10085. case 2: // XOR
  10086. for (t2 = 0; t2 < maxWidth; t2++) {
  10087. row[offsetT + t2] ^= symbolRow[t2];
  10088. }
  10089. break;
  10090. default:
  10091. error('JBIG2 error: operator ' + combinationOperator +
  10092. ' is not supported');
  10093. }
  10094. }
  10095. currentS += symbolHeight - 1;
  10096. } else {
  10097. for (t2 = 0; t2 < symbolHeight; t2++) {
  10098. row = bitmap[offsetT + t2];
  10099. if (!row) {
  10100. continue;
  10101. }
  10102. symbolRow = symbolBitmap[t2];
  10103. switch (combinationOperator) {
  10104. case 0: // OR
  10105. for (s2 = 0; s2 < symbolWidth; s2++) {
  10106. row[offsetS + s2] |= symbolRow[s2];
  10107. }
  10108. break;
  10109. case 2: // XOR
  10110. for (s2 = 0; s2 < symbolWidth; s2++) {
  10111. row[offsetS + s2] ^= symbolRow[s2];
  10112. }
  10113. break;
  10114. default:
  10115. error('JBIG2 error: operator ' + combinationOperator +
  10116. ' is not supported');
  10117. }
  10118. }
  10119. currentS += symbolWidth - 1;
  10120. }
  10121. i++;
  10122. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  10123. if (deltaS === null) {
  10124. break; // OOB
  10125. }
  10126. currentS += deltaS + dsOffset;
  10127. } while (true);
  10128. }
  10129. return bitmap;
  10130. }
  10131. function readSegmentHeader(data, start) {
  10132. var segmentHeader = {};
  10133. segmentHeader.number = readUint32(data, start);
  10134. var flags = data[start + 4];
  10135. var segmentType = flags & 0x3F;
  10136. if (!SegmentTypes[segmentType]) {
  10137. error('JBIG2 error: invalid segment type: ' + segmentType);
  10138. }
  10139. segmentHeader.type = segmentType;
  10140. segmentHeader.typeName = SegmentTypes[segmentType];
  10141. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  10142. var pageAssociationFieldSize = !!(flags & 0x40);
  10143. var referredFlags = data[start + 5];
  10144. var referredToCount = (referredFlags >> 5) & 7;
  10145. var retainBits = [referredFlags & 31];
  10146. var position = start + 6;
  10147. if (referredFlags === 7) {
  10148. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  10149. position += 3;
  10150. var bytes = (referredToCount + 7) >> 3;
  10151. retainBits[0] = data[position++];
  10152. while (--bytes > 0) {
  10153. retainBits.push(data[position++]);
  10154. }
  10155. } else if (referredFlags === 5 || referredFlags === 6) {
  10156. error('JBIG2 error: invalid referred-to flags');
  10157. }
  10158. segmentHeader.retainBits = retainBits;
  10159. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  10160. (segmentHeader.number <= 65536 ? 2 : 4));
  10161. var referredTo = [];
  10162. var i, ii;
  10163. for (i = 0; i < referredToCount; i++) {
  10164. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  10165. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  10166. readUint32(data, position)));
  10167. referredTo.push(number);
  10168. position += referredToSegmentNumberSize;
  10169. }
  10170. segmentHeader.referredTo = referredTo;
  10171. if (!pageAssociationFieldSize) {
  10172. segmentHeader.pageAssociation = data[position++];
  10173. } else {
  10174. segmentHeader.pageAssociation = readUint32(data, position);
  10175. position += 4;
  10176. }
  10177. segmentHeader.length = readUint32(data, position);
  10178. position += 4;
  10179. if (segmentHeader.length === 0xFFFFFFFF) {
  10180. // 7.2.7 Segment data length, unknown segment length
  10181. if (segmentType === 38) { // ImmediateGenericRegion
  10182. var genericRegionInfo = readRegionSegmentInformation(data, position);
  10183. var genericRegionSegmentFlags = data[position +
  10184. RegionSegmentInformationFieldLength];
  10185. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  10186. // searching for the segment end
  10187. var searchPatternLength = 6;
  10188. var searchPattern = new Uint8Array(searchPatternLength);
  10189. if (!genericRegionMmr) {
  10190. searchPattern[0] = 0xFF;
  10191. searchPattern[1] = 0xAC;
  10192. }
  10193. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  10194. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  10195. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  10196. searchPattern[5] = genericRegionInfo.height & 0xFF;
  10197. for (i = position, ii = data.length; i < ii; i++) {
  10198. var j = 0;
  10199. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  10200. j++;
  10201. }
  10202. if (j === searchPatternLength) {
  10203. segmentHeader.length = i + searchPatternLength;
  10204. break;
  10205. }
  10206. }
  10207. if (segmentHeader.length === 0xFFFFFFFF) {
  10208. error('JBIG2 error: segment end was not found');
  10209. }
  10210. } else {
  10211. error('JBIG2 error: invalid unknown segment length');
  10212. }
  10213. }
  10214. segmentHeader.headerEnd = position;
  10215. return segmentHeader;
  10216. }
  10217. function readSegments(header, data, start, end) {
  10218. var segments = [];
  10219. var position = start;
  10220. while (position < end) {
  10221. var segmentHeader = readSegmentHeader(data, position);
  10222. position = segmentHeader.headerEnd;
  10223. var segment = {
  10224. header: segmentHeader,
  10225. data: data
  10226. };
  10227. if (!header.randomAccess) {
  10228. segment.start = position;
  10229. position += segmentHeader.length;
  10230. segment.end = position;
  10231. }
  10232. segments.push(segment);
  10233. if (segmentHeader.type === 51) {
  10234. break; // end of file is found
  10235. }
  10236. }
  10237. if (header.randomAccess) {
  10238. for (var i = 0, ii = segments.length; i < ii; i++) {
  10239. segments[i].start = position;
  10240. position += segments[i].header.length;
  10241. segments[i].end = position;
  10242. }
  10243. }
  10244. return segments;
  10245. }
  10246. // 7.4.1 Region segment information field
  10247. function readRegionSegmentInformation(data, start) {
  10248. return {
  10249. width: readUint32(data, start),
  10250. height: readUint32(data, start + 4),
  10251. x: readUint32(data, start + 8),
  10252. y: readUint32(data, start + 12),
  10253. combinationOperator: data[start + 16] & 7
  10254. };
  10255. }
  10256. var RegionSegmentInformationFieldLength = 17;
  10257. function processSegment(segment, visitor) {
  10258. var header = segment.header;
  10259. var data = segment.data, position = segment.start, end = segment.end;
  10260. var args, at, i, atLength;
  10261. switch (header.type) {
  10262. case 0: // SymbolDictionary
  10263. // 7.4.2 Symbol dictionary segment syntax
  10264. var dictionary = {};
  10265. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  10266. dictionary.huffman = !!(dictionaryFlags & 1);
  10267. dictionary.refinement = !!(dictionaryFlags & 2);
  10268. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  10269. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  10270. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  10271. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  10272. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  10273. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  10274. dictionary.template = (dictionaryFlags >> 10) & 3;
  10275. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  10276. position += 2;
  10277. if (!dictionary.huffman) {
  10278. atLength = dictionary.template === 0 ? 4 : 1;
  10279. at = [];
  10280. for (i = 0; i < atLength; i++) {
  10281. at.push({
  10282. x: readInt8(data, position),
  10283. y: readInt8(data, position + 1)
  10284. });
  10285. position += 2;
  10286. }
  10287. dictionary.at = at;
  10288. }
  10289. if (dictionary.refinement && !dictionary.refinementTemplate) {
  10290. at = [];
  10291. for (i = 0; i < 2; i++) {
  10292. at.push({
  10293. x: readInt8(data, position),
  10294. y: readInt8(data, position + 1)
  10295. });
  10296. position += 2;
  10297. }
  10298. dictionary.refinementAt = at;
  10299. }
  10300. dictionary.numberOfExportedSymbols = readUint32(data, position);
  10301. position += 4;
  10302. dictionary.numberOfNewSymbols = readUint32(data, position);
  10303. position += 4;
  10304. args = [dictionary, header.number, header.referredTo,
  10305. data, position, end];
  10306. break;
  10307. case 6: // ImmediateTextRegion
  10308. case 7: // ImmediateLosslessTextRegion
  10309. var textRegion = {};
  10310. textRegion.info = readRegionSegmentInformation(data, position);
  10311. position += RegionSegmentInformationFieldLength;
  10312. var textRegionSegmentFlags = readUint16(data, position);
  10313. position += 2;
  10314. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  10315. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  10316. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  10317. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  10318. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  10319. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  10320. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  10321. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  10322. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  10323. if (textRegion.huffman) {
  10324. var textRegionHuffmanFlags = readUint16(data, position);
  10325. position += 2;
  10326. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  10327. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  10328. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  10329. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  10330. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  10331. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  10332. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  10333. textRegion.huffmanRefinementSizeSelector =
  10334. !!(textRegionHuffmanFlags & 14);
  10335. }
  10336. if (textRegion.refinement && !textRegion.refinementTemplate) {
  10337. at = [];
  10338. for (i = 0; i < 2; i++) {
  10339. at.push({
  10340. x: readInt8(data, position),
  10341. y: readInt8(data, position + 1)
  10342. });
  10343. position += 2;
  10344. }
  10345. textRegion.refinementAt = at;
  10346. }
  10347. textRegion.numberOfSymbolInstances = readUint32(data, position);
  10348. position += 4;
  10349. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  10350. if (textRegion.huffman) {
  10351. error('JBIG2 error: huffman is not supported');
  10352. }
  10353. args = [textRegion, header.referredTo, data, position, end];
  10354. break;
  10355. case 38: // ImmediateGenericRegion
  10356. case 39: // ImmediateLosslessGenericRegion
  10357. var genericRegion = {};
  10358. genericRegion.info = readRegionSegmentInformation(data, position);
  10359. position += RegionSegmentInformationFieldLength;
  10360. var genericRegionSegmentFlags = data[position++];
  10361. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  10362. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  10363. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  10364. if (!genericRegion.mmr) {
  10365. atLength = genericRegion.template === 0 ? 4 : 1;
  10366. at = [];
  10367. for (i = 0; i < atLength; i++) {
  10368. at.push({
  10369. x: readInt8(data, position),
  10370. y: readInt8(data, position + 1)
  10371. });
  10372. position += 2;
  10373. }
  10374. genericRegion.at = at;
  10375. }
  10376. args = [genericRegion, data, position, end];
  10377. break;
  10378. case 48: // PageInformation
  10379. var pageInfo = {
  10380. width: readUint32(data, position),
  10381. height: readUint32(data, position + 4),
  10382. resolutionX: readUint32(data, position + 8),
  10383. resolutionY: readUint32(data, position + 12)
  10384. };
  10385. if (pageInfo.height === 0xFFFFFFFF) {
  10386. delete pageInfo.height;
  10387. }
  10388. var pageSegmentFlags = data[position + 16];
  10389. var pageStripingInformation = readUint16(data, position + 17);
  10390. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10391. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10392. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10393. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10394. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10395. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10396. args = [pageInfo];
  10397. break;
  10398. case 49: // EndOfPage
  10399. break;
  10400. case 50: // EndOfStripe
  10401. break;
  10402. case 51: // EndOfFile
  10403. break;
  10404. case 62: // 7.4.15 defines 2 extension types which
  10405. // are comments and can be ignored.
  10406. break;
  10407. default:
  10408. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10409. header.type + ') is not implemented');
  10410. }
  10411. var callbackName = 'on' + header.typeName;
  10412. if (callbackName in visitor) {
  10413. visitor[callbackName].apply(visitor, args);
  10414. }
  10415. }
  10416. function processSegments(segments, visitor) {
  10417. for (var i = 0, ii = segments.length; i < ii; i++) {
  10418. processSegment(segments[i], visitor);
  10419. }
  10420. }
  10421. function parseJbig2(data, start, end) {
  10422. var position = start;
  10423. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10424. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10425. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10426. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10427. error('JBIG2 error: invalid header');
  10428. }
  10429. var header = {};
  10430. position += 8;
  10431. var flags = data[position++];
  10432. header.randomAccess = !(flags & 1);
  10433. if (!(flags & 2)) {
  10434. header.numberOfPages = readUint32(data, position);
  10435. position += 4;
  10436. }
  10437. var segments = readSegments(header, data, position, end);
  10438. error('Not implemented');
  10439. // processSegments(segments, new SimpleSegmentVisitor());
  10440. }
  10441. function parseJbig2Chunks(chunks) {
  10442. var visitor = new SimpleSegmentVisitor();
  10443. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10444. var chunk = chunks[i];
  10445. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10446. processSegments(segments, visitor);
  10447. }
  10448. return visitor.buffer;
  10449. }
  10450. function SimpleSegmentVisitor() {}
  10451. SimpleSegmentVisitor.prototype = {
  10452. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10453. this.currentPageInfo = info;
  10454. var rowSize = (info.width + 7) >> 3;
  10455. var buffer = new Uint8Array(rowSize * info.height);
  10456. // The contents of ArrayBuffers are initialized to 0.
  10457. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10458. if (info.defaultPixelValue) {
  10459. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10460. buffer[i] = 0xFF;
  10461. }
  10462. }
  10463. this.buffer = buffer;
  10464. },
  10465. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10466. var pageInfo = this.currentPageInfo;
  10467. var width = regionInfo.width, height = regionInfo.height;
  10468. var rowSize = (pageInfo.width + 7) >> 3;
  10469. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10470. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10471. var buffer = this.buffer;
  10472. var mask0 = 128 >> (regionInfo.x & 7);
  10473. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10474. var i, j, mask, offset;
  10475. switch (combinationOperator) {
  10476. case 0: // OR
  10477. for (i = 0; i < height; i++) {
  10478. mask = mask0;
  10479. offset = offset0;
  10480. for (j = 0; j < width; j++) {
  10481. if (bitmap[i][j]) {
  10482. buffer[offset] |= mask;
  10483. }
  10484. mask >>= 1;
  10485. if (!mask) {
  10486. mask = 128;
  10487. offset++;
  10488. }
  10489. }
  10490. offset0 += rowSize;
  10491. }
  10492. break;
  10493. case 2: // XOR
  10494. for (i = 0; i < height; i++) {
  10495. mask = mask0;
  10496. offset = offset0;
  10497. for (j = 0; j < width; j++) {
  10498. if (bitmap[i][j]) {
  10499. buffer[offset] ^= mask;
  10500. }
  10501. mask >>= 1;
  10502. if (!mask) {
  10503. mask = 128;
  10504. offset++;
  10505. }
  10506. }
  10507. offset0 += rowSize;
  10508. }
  10509. break;
  10510. default:
  10511. error('JBIG2 error: operator ' + combinationOperator +
  10512. ' is not supported');
  10513. }
  10514. },
  10515. onImmediateGenericRegion:
  10516. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10517. start, end) {
  10518. var regionInfo = region.info;
  10519. var decodingContext = new DecodingContext(data, start, end);
  10520. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10521. region.template, region.prediction, null,
  10522. region.at, decodingContext);
  10523. this.drawBitmap(regionInfo, bitmap);
  10524. },
  10525. onImmediateLosslessGenericRegion:
  10526. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10527. this.onImmediateGenericRegion.apply(this, arguments);
  10528. },
  10529. onSymbolDictionary:
  10530. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10531. currentSegment,
  10532. referredSegments,
  10533. data, start, end) {
  10534. var huffmanTables;
  10535. if (dictionary.huffman) {
  10536. error('JBIG2 error: huffman is not supported');
  10537. }
  10538. // Combines exported symbols from all referred segments
  10539. var symbols = this.symbols;
  10540. if (!symbols) {
  10541. this.symbols = symbols = {};
  10542. }
  10543. var inputSymbols = [];
  10544. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10545. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10546. }
  10547. var decodingContext = new DecodingContext(data, start, end);
  10548. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10549. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10550. dictionary.numberOfExportedSymbols, huffmanTables,
  10551. dictionary.template, dictionary.at,
  10552. dictionary.refinementTemplate, dictionary.refinementAt,
  10553. decodingContext);
  10554. },
  10555. onImmediateTextRegion:
  10556. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10557. referredSegments,
  10558. data, start, end) {
  10559. var regionInfo = region.info;
  10560. var huffmanTables;
  10561. // Combines exported symbols from all referred segments
  10562. var symbols = this.symbols;
  10563. var inputSymbols = [];
  10564. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10565. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10566. }
  10567. var symbolCodeLength = log2(inputSymbols.length);
  10568. var decodingContext = new DecodingContext(data, start, end);
  10569. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10570. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10571. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10572. symbolCodeLength, region.transposed, region.dsOffset,
  10573. region.referenceCorner, region.combinationOperator, huffmanTables,
  10574. region.refinementTemplate, region.refinementAt, decodingContext);
  10575. this.drawBitmap(regionInfo, bitmap);
  10576. },
  10577. onImmediateLosslessTextRegion:
  10578. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10579. this.onImmediateTextRegion.apply(this, arguments);
  10580. }
  10581. };
  10582. function Jbig2Image() {}
  10583. Jbig2Image.prototype = {
  10584. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10585. return parseJbig2Chunks(chunks);
  10586. }
  10587. };
  10588. return Jbig2Image;
  10589. })();
  10590. exports.Jbig2Image = Jbig2Image;
  10591. }));
  10592. (function (root, factory) {
  10593. {
  10594. factory((root.pdfjsCoreJpg = {}), root.pdfjsSharedUtil);
  10595. }
  10596. }(this, function (exports, sharedUtil) {
  10597. var error = sharedUtil.error;
  10598. /**
  10599. * This code was forked from https://github.com/notmasteryet/jpgjs.
  10600. * The original version was created by GitHub user notmasteryet.
  10601. *
  10602. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  10603. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  10604. * - The JFIF specification can be found in the JPEG File Interchange Format
  10605. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  10606. * - The Adobe Application-Specific JPEG markers in the
  10607. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  10608. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  10609. */
  10610. var JpegImage = (function jpegImage() {
  10611. var dctZigZag = new Uint8Array([
  10612. 0,
  10613. 1, 8,
  10614. 16, 9, 2,
  10615. 3, 10, 17, 24,
  10616. 32, 25, 18, 11, 4,
  10617. 5, 12, 19, 26, 33, 40,
  10618. 48, 41, 34, 27, 20, 13, 6,
  10619. 7, 14, 21, 28, 35, 42, 49, 56,
  10620. 57, 50, 43, 36, 29, 22, 15,
  10621. 23, 30, 37, 44, 51, 58,
  10622. 59, 52, 45, 38, 31,
  10623. 39, 46, 53, 60,
  10624. 61, 54, 47,
  10625. 55, 62,
  10626. 63
  10627. ]);
  10628. var dctCos1 = 4017; // cos(pi/16)
  10629. var dctSin1 = 799; // sin(pi/16)
  10630. var dctCos3 = 3406; // cos(3*pi/16)
  10631. var dctSin3 = 2276; // sin(3*pi/16)
  10632. var dctCos6 = 1567; // cos(6*pi/16)
  10633. var dctSin6 = 3784; // sin(6*pi/16)
  10634. var dctSqrt2 = 5793; // sqrt(2)
  10635. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  10636. function constructor() {
  10637. }
  10638. function buildHuffmanTable(codeLengths, values) {
  10639. var k = 0, code = [], i, j, length = 16;
  10640. while (length > 0 && !codeLengths[length - 1]) {
  10641. length--;
  10642. }
  10643. code.push({children: [], index: 0});
  10644. var p = code[0], q;
  10645. for (i = 0; i < length; i++) {
  10646. for (j = 0; j < codeLengths[i]; j++) {
  10647. p = code.pop();
  10648. p.children[p.index] = values[k];
  10649. while (p.index > 0) {
  10650. p = code.pop();
  10651. }
  10652. p.index++;
  10653. code.push(p);
  10654. while (code.length <= i) {
  10655. code.push(q = {children: [], index: 0});
  10656. p.children[p.index] = q.children;
  10657. p = q;
  10658. }
  10659. k++;
  10660. }
  10661. if (i + 1 < length) {
  10662. // p here points to last code
  10663. code.push(q = {children: [], index: 0});
  10664. p.children[p.index] = q.children;
  10665. p = q;
  10666. }
  10667. }
  10668. return code[0].children;
  10669. }
  10670. function getBlockBufferOffset(component, row, col) {
  10671. return 64 * ((component.blocksPerLine + 1) * row + col);
  10672. }
  10673. function decodeScan(data, offset, frame, components, resetInterval,
  10674. spectralStart, spectralEnd, successivePrev, successive) {
  10675. var mcusPerLine = frame.mcusPerLine;
  10676. var progressive = frame.progressive;
  10677. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10678. function readBit() {
  10679. if (bitsCount > 0) {
  10680. bitsCount--;
  10681. return (bitsData >> bitsCount) & 1;
  10682. }
  10683. bitsData = data[offset++];
  10684. if (bitsData === 0xFF) {
  10685. var nextByte = data[offset++];
  10686. if (nextByte) {
  10687. error('JPEG error: unexpected marker ' +
  10688. ((bitsData << 8) | nextByte).toString(16));
  10689. }
  10690. // unstuff 0
  10691. }
  10692. bitsCount = 7;
  10693. return bitsData >>> 7;
  10694. }
  10695. function decodeHuffman(tree) {
  10696. var node = tree;
  10697. while (true) {
  10698. node = node[readBit()];
  10699. if (typeof node === 'number') {
  10700. return node;
  10701. }
  10702. if (typeof node !== 'object') {
  10703. error('JPEG error: invalid huffman sequence');
  10704. }
  10705. }
  10706. }
  10707. function receive(length) {
  10708. var n = 0;
  10709. while (length > 0) {
  10710. n = (n << 1) | readBit();
  10711. length--;
  10712. }
  10713. return n;
  10714. }
  10715. function receiveAndExtend(length) {
  10716. if (length === 1) {
  10717. return readBit() === 1 ? 1 : -1;
  10718. }
  10719. var n = receive(length);
  10720. if (n >= 1 << (length - 1)) {
  10721. return n;
  10722. }
  10723. return n + (-1 << length) + 1;
  10724. }
  10725. function decodeBaseline(component, offset) {
  10726. var t = decodeHuffman(component.huffmanTableDC);
  10727. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10728. component.blockData[offset] = (component.pred += diff);
  10729. var k = 1;
  10730. while (k < 64) {
  10731. var rs = decodeHuffman(component.huffmanTableAC);
  10732. var s = rs & 15, r = rs >> 4;
  10733. if (s === 0) {
  10734. if (r < 15) {
  10735. break;
  10736. }
  10737. k += 16;
  10738. continue;
  10739. }
  10740. k += r;
  10741. var z = dctZigZag[k];
  10742. component.blockData[offset + z] = receiveAndExtend(s);
  10743. k++;
  10744. }
  10745. }
  10746. function decodeDCFirst(component, offset) {
  10747. var t = decodeHuffman(component.huffmanTableDC);
  10748. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10749. component.blockData[offset] = (component.pred += diff);
  10750. }
  10751. function decodeDCSuccessive(component, offset) {
  10752. component.blockData[offset] |= readBit() << successive;
  10753. }
  10754. var eobrun = 0;
  10755. function decodeACFirst(component, offset) {
  10756. if (eobrun > 0) {
  10757. eobrun--;
  10758. return;
  10759. }
  10760. var k = spectralStart, e = spectralEnd;
  10761. while (k <= e) {
  10762. var rs = decodeHuffman(component.huffmanTableAC);
  10763. var s = rs & 15, r = rs >> 4;
  10764. if (s === 0) {
  10765. if (r < 15) {
  10766. eobrun = receive(r) + (1 << r) - 1;
  10767. break;
  10768. }
  10769. k += 16;
  10770. continue;
  10771. }
  10772. k += r;
  10773. var z = dctZigZag[k];
  10774. component.blockData[offset + z] =
  10775. receiveAndExtend(s) * (1 << successive);
  10776. k++;
  10777. }
  10778. }
  10779. var successiveACState = 0, successiveACNextValue;
  10780. function decodeACSuccessive(component, offset) {
  10781. var k = spectralStart;
  10782. var e = spectralEnd;
  10783. var r = 0;
  10784. var s;
  10785. var rs;
  10786. while (k <= e) {
  10787. var z = dctZigZag[k];
  10788. switch (successiveACState) {
  10789. case 0: // initial state
  10790. rs = decodeHuffman(component.huffmanTableAC);
  10791. s = rs & 15;
  10792. r = rs >> 4;
  10793. if (s === 0) {
  10794. if (r < 15) {
  10795. eobrun = receive(r) + (1 << r);
  10796. successiveACState = 4;
  10797. } else {
  10798. r = 16;
  10799. successiveACState = 1;
  10800. }
  10801. } else {
  10802. if (s !== 1) {
  10803. error('JPEG error: invalid ACn encoding');
  10804. }
  10805. successiveACNextValue = receiveAndExtend(s);
  10806. successiveACState = r ? 2 : 3;
  10807. }
  10808. continue;
  10809. case 1: // skipping r zero items
  10810. case 2:
  10811. if (component.blockData[offset + z]) {
  10812. component.blockData[offset + z] += (readBit() << successive);
  10813. } else {
  10814. r--;
  10815. if (r === 0) {
  10816. successiveACState = successiveACState === 2 ? 3 : 0;
  10817. }
  10818. }
  10819. break;
  10820. case 3: // set value for a zero item
  10821. if (component.blockData[offset + z]) {
  10822. component.blockData[offset + z] += (readBit() << successive);
  10823. } else {
  10824. component.blockData[offset + z] =
  10825. successiveACNextValue << successive;
  10826. successiveACState = 0;
  10827. }
  10828. break;
  10829. case 4: // eob
  10830. if (component.blockData[offset + z]) {
  10831. component.blockData[offset + z] += (readBit() << successive);
  10832. }
  10833. break;
  10834. }
  10835. k++;
  10836. }
  10837. if (successiveACState === 4) {
  10838. eobrun--;
  10839. if (eobrun === 0) {
  10840. successiveACState = 0;
  10841. }
  10842. }
  10843. }
  10844. function decodeMcu(component, decode, mcu, row, col) {
  10845. var mcuRow = (mcu / mcusPerLine) | 0;
  10846. var mcuCol = mcu % mcusPerLine;
  10847. var blockRow = mcuRow * component.v + row;
  10848. var blockCol = mcuCol * component.h + col;
  10849. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10850. decode(component, offset);
  10851. }
  10852. function decodeBlock(component, decode, mcu) {
  10853. var blockRow = (mcu / component.blocksPerLine) | 0;
  10854. var blockCol = mcu % component.blocksPerLine;
  10855. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10856. decode(component, offset);
  10857. }
  10858. var componentsLength = components.length;
  10859. var component, i, j, k, n;
  10860. var decodeFn;
  10861. if (progressive) {
  10862. if (spectralStart === 0) {
  10863. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  10864. } else {
  10865. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  10866. }
  10867. } else {
  10868. decodeFn = decodeBaseline;
  10869. }
  10870. var mcu = 0, marker;
  10871. var mcuExpected;
  10872. if (componentsLength === 1) {
  10873. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  10874. } else {
  10875. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  10876. }
  10877. if (!resetInterval) {
  10878. resetInterval = mcuExpected;
  10879. }
  10880. var h, v;
  10881. while (mcu < mcuExpected) {
  10882. // reset interval stuff
  10883. for (i = 0; i < componentsLength; i++) {
  10884. components[i].pred = 0;
  10885. }
  10886. eobrun = 0;
  10887. if (componentsLength === 1) {
  10888. component = components[0];
  10889. for (n = 0; n < resetInterval; n++) {
  10890. decodeBlock(component, decodeFn, mcu);
  10891. mcu++;
  10892. }
  10893. } else {
  10894. for (n = 0; n < resetInterval; n++) {
  10895. for (i = 0; i < componentsLength; i++) {
  10896. component = components[i];
  10897. h = component.h;
  10898. v = component.v;
  10899. for (j = 0; j < v; j++) {
  10900. for (k = 0; k < h; k++) {
  10901. decodeMcu(component, decodeFn, mcu, j, k);
  10902. }
  10903. }
  10904. }
  10905. mcu++;
  10906. }
  10907. }
  10908. // find marker
  10909. bitsCount = 0;
  10910. marker = (data[offset] << 8) | data[offset + 1];
  10911. if (marker <= 0xFF00) {
  10912. error('JPEG error: marker was not found');
  10913. }
  10914. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  10915. offset += 2;
  10916. } else {
  10917. break;
  10918. }
  10919. }
  10920. return offset - startOffset;
  10921. }
  10922. // A port of poppler's IDCT method which in turn is taken from:
  10923. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  10924. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  10925. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  10926. // 988-991.
  10927. function quantizeAndInverse(component, blockBufferOffset, p) {
  10928. var qt = component.quantizationTable, blockData = component.blockData;
  10929. var v0, v1, v2, v3, v4, v5, v6, v7;
  10930. var p0, p1, p2, p3, p4, p5, p6, p7;
  10931. var t;
  10932. if (!qt) {
  10933. error('JPEG error: missing required Quantization Table.');
  10934. }
  10935. // inverse DCT on rows
  10936. for (var row = 0; row < 64; row += 8) {
  10937. // gather block data
  10938. p0 = blockData[blockBufferOffset + row];
  10939. p1 = blockData[blockBufferOffset + row + 1];
  10940. p2 = blockData[blockBufferOffset + row + 2];
  10941. p3 = blockData[blockBufferOffset + row + 3];
  10942. p4 = blockData[blockBufferOffset + row + 4];
  10943. p5 = blockData[blockBufferOffset + row + 5];
  10944. p6 = blockData[blockBufferOffset + row + 6];
  10945. p7 = blockData[blockBufferOffset + row + 7];
  10946. // dequant p0
  10947. p0 *= qt[row];
  10948. // check for all-zero AC coefficients
  10949. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  10950. t = (dctSqrt2 * p0 + 512) >> 10;
  10951. p[row] = t;
  10952. p[row + 1] = t;
  10953. p[row + 2] = t;
  10954. p[row + 3] = t;
  10955. p[row + 4] = t;
  10956. p[row + 5] = t;
  10957. p[row + 6] = t;
  10958. p[row + 7] = t;
  10959. continue;
  10960. }
  10961. // dequant p1 ... p7
  10962. p1 *= qt[row + 1];
  10963. p2 *= qt[row + 2];
  10964. p3 *= qt[row + 3];
  10965. p4 *= qt[row + 4];
  10966. p5 *= qt[row + 5];
  10967. p6 *= qt[row + 6];
  10968. p7 *= qt[row + 7];
  10969. // stage 4
  10970. v0 = (dctSqrt2 * p0 + 128) >> 8;
  10971. v1 = (dctSqrt2 * p4 + 128) >> 8;
  10972. v2 = p2;
  10973. v3 = p6;
  10974. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  10975. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  10976. v5 = p3 << 4;
  10977. v6 = p5 << 4;
  10978. // stage 3
  10979. v0 = (v0 + v1 + 1) >> 1;
  10980. v1 = v0 - v1;
  10981. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  10982. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  10983. v3 = t;
  10984. v4 = (v4 + v6 + 1) >> 1;
  10985. v6 = v4 - v6;
  10986. v7 = (v7 + v5 + 1) >> 1;
  10987. v5 = v7 - v5;
  10988. // stage 2
  10989. v0 = (v0 + v3 + 1) >> 1;
  10990. v3 = v0 - v3;
  10991. v1 = (v1 + v2 + 1) >> 1;
  10992. v2 = v1 - v2;
  10993. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  10994. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  10995. v7 = t;
  10996. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  10997. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  10998. v6 = t;
  10999. // stage 1
  11000. p[row] = v0 + v7;
  11001. p[row + 7] = v0 - v7;
  11002. p[row + 1] = v1 + v6;
  11003. p[row + 6] = v1 - v6;
  11004. p[row + 2] = v2 + v5;
  11005. p[row + 5] = v2 - v5;
  11006. p[row + 3] = v3 + v4;
  11007. p[row + 4] = v3 - v4;
  11008. }
  11009. // inverse DCT on columns
  11010. for (var col = 0; col < 8; ++col) {
  11011. p0 = p[col];
  11012. p1 = p[col + 8];
  11013. p2 = p[col + 16];
  11014. p3 = p[col + 24];
  11015. p4 = p[col + 32];
  11016. p5 = p[col + 40];
  11017. p6 = p[col + 48];
  11018. p7 = p[col + 56];
  11019. // check for all-zero AC coefficients
  11020. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11021. t = (dctSqrt2 * p0 + 8192) >> 14;
  11022. // convert to 8 bit
  11023. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11024. blockData[blockBufferOffset + col] = t;
  11025. blockData[blockBufferOffset + col + 8] = t;
  11026. blockData[blockBufferOffset + col + 16] = t;
  11027. blockData[blockBufferOffset + col + 24] = t;
  11028. blockData[blockBufferOffset + col + 32] = t;
  11029. blockData[blockBufferOffset + col + 40] = t;
  11030. blockData[blockBufferOffset + col + 48] = t;
  11031. blockData[blockBufferOffset + col + 56] = t;
  11032. continue;
  11033. }
  11034. // stage 4
  11035. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11036. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11037. v2 = p2;
  11038. v3 = p6;
  11039. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11040. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11041. v5 = p3;
  11042. v6 = p5;
  11043. // stage 3
  11044. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11045. // converting to UInt8 range later.
  11046. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11047. v1 = v0 - v1;
  11048. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11049. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11050. v3 = t;
  11051. v4 = (v4 + v6 + 1) >> 1;
  11052. v6 = v4 - v6;
  11053. v7 = (v7 + v5 + 1) >> 1;
  11054. v5 = v7 - v5;
  11055. // stage 2
  11056. v0 = (v0 + v3 + 1) >> 1;
  11057. v3 = v0 - v3;
  11058. v1 = (v1 + v2 + 1) >> 1;
  11059. v2 = v1 - v2;
  11060. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11061. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11062. v7 = t;
  11063. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11064. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11065. v6 = t;
  11066. // stage 1
  11067. p0 = v0 + v7;
  11068. p7 = v0 - v7;
  11069. p1 = v1 + v6;
  11070. p6 = v1 - v6;
  11071. p2 = v2 + v5;
  11072. p5 = v2 - v5;
  11073. p3 = v3 + v4;
  11074. p4 = v3 - v4;
  11075. // convert to 8-bit integers
  11076. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11077. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11078. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11079. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11080. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11081. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11082. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11083. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11084. // store block data
  11085. blockData[blockBufferOffset + col] = p0;
  11086. blockData[blockBufferOffset + col + 8] = p1;
  11087. blockData[blockBufferOffset + col + 16] = p2;
  11088. blockData[blockBufferOffset + col + 24] = p3;
  11089. blockData[blockBufferOffset + col + 32] = p4;
  11090. blockData[blockBufferOffset + col + 40] = p5;
  11091. blockData[blockBufferOffset + col + 48] = p6;
  11092. blockData[blockBufferOffset + col + 56] = p7;
  11093. }
  11094. }
  11095. function buildComponentData(frame, component) {
  11096. var blocksPerLine = component.blocksPerLine;
  11097. var blocksPerColumn = component.blocksPerColumn;
  11098. var computationBuffer = new Int16Array(64);
  11099. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11100. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11101. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11102. quantizeAndInverse(component, offset, computationBuffer);
  11103. }
  11104. }
  11105. return component.blockData;
  11106. }
  11107. function clamp0to255(a) {
  11108. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11109. }
  11110. constructor.prototype = {
  11111. parse: function parse(data) {
  11112. function readUint16() {
  11113. var value = (data[offset] << 8) | data[offset + 1];
  11114. offset += 2;
  11115. return value;
  11116. }
  11117. function readDataBlock() {
  11118. var length = readUint16();
  11119. var array = data.subarray(offset, offset + length - 2);
  11120. offset += array.length;
  11121. return array;
  11122. }
  11123. function prepareComponents(frame) {
  11124. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11125. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11126. for (var i = 0; i < frame.components.length; i++) {
  11127. component = frame.components[i];
  11128. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11129. component.h / frame.maxH);
  11130. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11131. component.v / frame.maxV);
  11132. var blocksPerLineForMcu = mcusPerLine * component.h;
  11133. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11134. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11135. (blocksPerLineForMcu + 1);
  11136. component.blockData = new Int16Array(blocksBufferSize);
  11137. component.blocksPerLine = blocksPerLine;
  11138. component.blocksPerColumn = blocksPerColumn;
  11139. }
  11140. frame.mcusPerLine = mcusPerLine;
  11141. frame.mcusPerColumn = mcusPerColumn;
  11142. }
  11143. var offset = 0;
  11144. var jfif = null;
  11145. var adobe = null;
  11146. var frame, resetInterval;
  11147. var quantizationTables = [];
  11148. var huffmanTablesAC = [], huffmanTablesDC = [];
  11149. var fileMarker = readUint16();
  11150. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11151. error('JPEG error: SOI not found');
  11152. }
  11153. fileMarker = readUint16();
  11154. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11155. var i, j, l;
  11156. switch(fileMarker) {
  11157. case 0xFFE0: // APP0 (Application Specific)
  11158. case 0xFFE1: // APP1
  11159. case 0xFFE2: // APP2
  11160. case 0xFFE3: // APP3
  11161. case 0xFFE4: // APP4
  11162. case 0xFFE5: // APP5
  11163. case 0xFFE6: // APP6
  11164. case 0xFFE7: // APP7
  11165. case 0xFFE8: // APP8
  11166. case 0xFFE9: // APP9
  11167. case 0xFFEA: // APP10
  11168. case 0xFFEB: // APP11
  11169. case 0xFFEC: // APP12
  11170. case 0xFFED: // APP13
  11171. case 0xFFEE: // APP14
  11172. case 0xFFEF: // APP15
  11173. case 0xFFFE: // COM (Comment)
  11174. var appData = readDataBlock();
  11175. if (fileMarker === 0xFFE0) {
  11176. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11177. appData[2] === 0x49 && appData[3] === 0x46 &&
  11178. appData[4] === 0) { // 'JFIF\x00'
  11179. jfif = {
  11180. version: { major: appData[5], minor: appData[6] },
  11181. densityUnits: appData[7],
  11182. xDensity: (appData[8] << 8) | appData[9],
  11183. yDensity: (appData[10] << 8) | appData[11],
  11184. thumbWidth: appData[12],
  11185. thumbHeight: appData[13],
  11186. thumbData: appData.subarray(14, 14 +
  11187. 3 * appData[12] * appData[13])
  11188. };
  11189. }
  11190. }
  11191. // TODO APP1 - Exif
  11192. if (fileMarker === 0xFFEE) {
  11193. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11194. appData[2] === 0x6F && appData[3] === 0x62 &&
  11195. appData[4] === 0x65) { // 'Adobe'
  11196. adobe = {
  11197. version: (appData[5] << 8) | appData[6],
  11198. flags0: (appData[7] << 8) | appData[8],
  11199. flags1: (appData[9] << 8) | appData[10],
  11200. transformCode: appData[11]
  11201. };
  11202. }
  11203. }
  11204. break;
  11205. case 0xFFDB: // DQT (Define Quantization Tables)
  11206. var quantizationTablesLength = readUint16();
  11207. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11208. var z;
  11209. while (offset < quantizationTablesEnd) {
  11210. var quantizationTableSpec = data[offset++];
  11211. var tableData = new Uint16Array(64);
  11212. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11213. for (j = 0; j < 64; j++) {
  11214. z = dctZigZag[j];
  11215. tableData[z] = data[offset++];
  11216. }
  11217. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11218. for (j = 0; j < 64; j++) {
  11219. z = dctZigZag[j];
  11220. tableData[z] = readUint16();
  11221. }
  11222. } else {
  11223. error('JPEG error: DQT - invalid table spec');
  11224. }
  11225. quantizationTables[quantizationTableSpec & 15] = tableData;
  11226. }
  11227. break;
  11228. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11229. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11230. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11231. if (frame) {
  11232. error('JPEG error: Only single frame JPEGs supported');
  11233. }
  11234. readUint16(); // skip data length
  11235. frame = {};
  11236. frame.extended = (fileMarker === 0xFFC1);
  11237. frame.progressive = (fileMarker === 0xFFC2);
  11238. frame.precision = data[offset++];
  11239. frame.scanLines = readUint16();
  11240. frame.samplesPerLine = readUint16();
  11241. frame.components = [];
  11242. frame.componentIds = {};
  11243. var componentsCount = data[offset++], componentId;
  11244. var maxH = 0, maxV = 0;
  11245. for (i = 0; i < componentsCount; i++) {
  11246. componentId = data[offset];
  11247. var h = data[offset + 1] >> 4;
  11248. var v = data[offset + 1] & 15;
  11249. if (maxH < h) {
  11250. maxH = h;
  11251. }
  11252. if (maxV < v) {
  11253. maxV = v;
  11254. }
  11255. var qId = data[offset + 2];
  11256. l = frame.components.push({
  11257. h: h,
  11258. v: v,
  11259. quantizationId: qId,
  11260. quantizationTable: null, // See comment below.
  11261. });
  11262. frame.componentIds[componentId] = l - 1;
  11263. offset += 3;
  11264. }
  11265. frame.maxH = maxH;
  11266. frame.maxV = maxV;
  11267. prepareComponents(frame);
  11268. break;
  11269. case 0xFFC4: // DHT (Define Huffman Tables)
  11270. var huffmanLength = readUint16();
  11271. for (i = 2; i < huffmanLength;) {
  11272. var huffmanTableSpec = data[offset++];
  11273. var codeLengths = new Uint8Array(16);
  11274. var codeLengthSum = 0;
  11275. for (j = 0; j < 16; j++, offset++) {
  11276. codeLengthSum += (codeLengths[j] = data[offset]);
  11277. }
  11278. var huffmanValues = new Uint8Array(codeLengthSum);
  11279. for (j = 0; j < codeLengthSum; j++, offset++) {
  11280. huffmanValues[j] = data[offset];
  11281. }
  11282. i += 17 + codeLengthSum;
  11283. ((huffmanTableSpec >> 4) === 0 ?
  11284. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11285. buildHuffmanTable(codeLengths, huffmanValues);
  11286. }
  11287. break;
  11288. case 0xFFDD: // DRI (Define Restart Interval)
  11289. readUint16(); // skip data length
  11290. resetInterval = readUint16();
  11291. break;
  11292. case 0xFFDA: // SOS (Start of Scan)
  11293. var scanLength = readUint16();
  11294. var selectorsCount = data[offset++];
  11295. var components = [], component;
  11296. for (i = 0; i < selectorsCount; i++) {
  11297. var componentIndex = frame.componentIds[data[offset++]];
  11298. component = frame.components[componentIndex];
  11299. var tableSpec = data[offset++];
  11300. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11301. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11302. components.push(component);
  11303. }
  11304. var spectralStart = data[offset++];
  11305. var spectralEnd = data[offset++];
  11306. var successiveApproximation = data[offset++];
  11307. var processed = decodeScan(data, offset,
  11308. frame, components, resetInterval,
  11309. spectralStart, spectralEnd,
  11310. successiveApproximation >> 4, successiveApproximation & 15);
  11311. offset += processed;
  11312. break;
  11313. case 0xFFFF: // Fill bytes
  11314. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11315. offset--;
  11316. }
  11317. break;
  11318. default:
  11319. if (data[offset - 3] === 0xFF &&
  11320. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11321. // could be incorrect encoding -- last 0xFF byte of the previous
  11322. // block was eaten by the encoder
  11323. offset -= 3;
  11324. break;
  11325. }
  11326. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11327. }
  11328. fileMarker = readUint16();
  11329. }
  11330. this.width = frame.samplesPerLine;
  11331. this.height = frame.scanLines;
  11332. this.jfif = jfif;
  11333. this.adobe = adobe;
  11334. this.components = [];
  11335. for (i = 0; i < frame.components.length; i++) {
  11336. component = frame.components[i];
  11337. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11338. // by assigning the `quantizationTable` entry after the entire image
  11339. // has been parsed (fixes issue7406.pdf).
  11340. var quantizationTable = quantizationTables[component.quantizationId];
  11341. if (quantizationTable) {
  11342. component.quantizationTable = quantizationTable;
  11343. }
  11344. this.components.push({
  11345. output: buildComponentData(frame, component),
  11346. scaleX: component.h / frame.maxH,
  11347. scaleY: component.v / frame.maxV,
  11348. blocksPerLine: component.blocksPerLine,
  11349. blocksPerColumn: component.blocksPerColumn
  11350. });
  11351. }
  11352. this.numComponents = this.components.length;
  11353. },
  11354. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11355. var scaleX = this.width / width, scaleY = this.height / height;
  11356. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11357. var x, y, i, j, k;
  11358. var index;
  11359. var offset = 0;
  11360. var output;
  11361. var numComponents = this.components.length;
  11362. var dataLength = width * height * numComponents;
  11363. var data = new Uint8Array(dataLength);
  11364. var xScaleBlockOffset = new Uint32Array(width);
  11365. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11366. for (i = 0; i < numComponents; i++) {
  11367. component = this.components[i];
  11368. componentScaleX = component.scaleX * scaleX;
  11369. componentScaleY = component.scaleY * scaleY;
  11370. offset = i;
  11371. output = component.output;
  11372. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11373. // precalculate the xScaleBlockOffset
  11374. for (x = 0; x < width; x++) {
  11375. j = 0 | (x * componentScaleX);
  11376. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11377. }
  11378. // linearize the blocks of the component
  11379. for (y = 0; y < height; y++) {
  11380. j = 0 | (y * componentScaleY);
  11381. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11382. for (x = 0; x < width; x++) {
  11383. data[offset] = output[index + xScaleBlockOffset[x]];
  11384. offset += numComponents;
  11385. }
  11386. }
  11387. }
  11388. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11389. var transform = this.decodeTransform;
  11390. if (transform) {
  11391. for (i = 0; i < dataLength;) {
  11392. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11393. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11394. }
  11395. }
  11396. }
  11397. return data;
  11398. },
  11399. _isColorConversionNeeded: function isColorConversionNeeded() {
  11400. if (this.adobe && this.adobe.transformCode) {
  11401. // The adobe transform marker overrides any previous setting
  11402. return true;
  11403. } else if (this.numComponents === 3) {
  11404. return true;
  11405. } else {
  11406. return false;
  11407. }
  11408. },
  11409. _convertYccToRgb: function convertYccToRgb(data) {
  11410. var Y, Cb, Cr;
  11411. for (var i = 0, length = data.length; i < length; i += 3) {
  11412. Y = data[i ];
  11413. Cb = data[i + 1];
  11414. Cr = data[i + 2];
  11415. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11416. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11417. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11418. }
  11419. return data;
  11420. },
  11421. _convertYcckToRgb: function convertYcckToRgb(data) {
  11422. var Y, Cb, Cr, k;
  11423. var offset = 0;
  11424. for (var i = 0, length = data.length; i < length; i += 4) {
  11425. Y = data[i];
  11426. Cb = data[i + 1];
  11427. Cr = data[i + 2];
  11428. k = data[i + 3];
  11429. var r = -122.67195406894 +
  11430. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11431. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11432. 0.154362151871126) +
  11433. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11434. 0.00477271405408747 * k + 1.53380253221734) +
  11435. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11436. 0.48357088451265) +
  11437. k * (-0.000336197177618394 * k + 0.484791561490776);
  11438. var g = 107.268039397724 +
  11439. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11440. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11441. 0.176491792462875) +
  11442. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11443. 0.000770482631801132 * k - 0.151051492775562) +
  11444. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11445. 0.25802910206845) +
  11446. k * (-0.000318913117588328 * k - 0.213742400323665);
  11447. var b = -20.810012546947 +
  11448. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11449. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11450. 0.814272968359295) +
  11451. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11452. 0.000560833691242812 * k - 0.195152027534049) +
  11453. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11454. 0.116935020465145) +
  11455. k * (-0.000343531996510555 * k + 0.24165260232407);
  11456. data[offset++] = clamp0to255(r);
  11457. data[offset++] = clamp0to255(g);
  11458. data[offset++] = clamp0to255(b);
  11459. }
  11460. return data;
  11461. },
  11462. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11463. var Y, Cb, Cr;
  11464. for (var i = 0, length = data.length; i < length; i += 4) {
  11465. Y = data[i];
  11466. Cb = data[i + 1];
  11467. Cr = data[i + 2];
  11468. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11469. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11470. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11471. // K in data[i + 3] is unchanged
  11472. }
  11473. return data;
  11474. },
  11475. _convertCmykToRgb: function convertCmykToRgb(data) {
  11476. var c, m, y, k;
  11477. var offset = 0;
  11478. var min = -255 * 255 * 255;
  11479. var scale = 1 / 255 / 255;
  11480. for (var i = 0, length = data.length; i < length; i += 4) {
  11481. c = data[i];
  11482. m = data[i + 1];
  11483. y = data[i + 2];
  11484. k = data[i + 3];
  11485. var r =
  11486. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11487. 18.82290502165302 * y + 212.25662451639585 * k -
  11488. 72734.4411664936) +
  11489. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11490. 17.873870861415444 * k - 1401.7366389350734) +
  11491. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11492. 4465.541406466231) -
  11493. k * (21.86122147463605 * k + 48317.86113160301);
  11494. var g =
  11495. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11496. 6.871425592049007 * y + 31.159100130055922 * k -
  11497. 20220.756542821975) +
  11498. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11499. 131.35250912493976 * k - 48691.05921601825) +
  11500. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11501. 6341.191035517494) -
  11502. k * (20.737325471181034 * k + 47890.15695978492);
  11503. var b =
  11504. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11505. 30.89978309703729 * y - 0.23883238689178934 * k -
  11506. 3616.812083916688) +
  11507. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11508. 50.606957656360734 * k - 28620.90484698408) +
  11509. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11510. 49363.43385999684) -
  11511. k * (22.33816807309886 * k + 45932.16563550634);
  11512. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11513. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11514. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11515. }
  11516. return data;
  11517. },
  11518. getData: function getData(width, height, forceRGBoutput) {
  11519. if (this.numComponents > 4) {
  11520. error('JPEG error: Unsupported color mode');
  11521. }
  11522. // type of data: Uint8Array(width * height * numComponents)
  11523. var data = this._getLinearizedBlockData(width, height);
  11524. if (this.numComponents === 1 && forceRGBoutput) {
  11525. var dataLength = data.length;
  11526. var rgbData = new Uint8Array(dataLength * 3);
  11527. var offset = 0;
  11528. for (var i = 0; i < dataLength; i++) {
  11529. var grayColor = data[i];
  11530. rgbData[offset++] = grayColor;
  11531. rgbData[offset++] = grayColor;
  11532. rgbData[offset++] = grayColor;
  11533. }
  11534. return rgbData;
  11535. } else if (this.numComponents === 3) {
  11536. return this._convertYccToRgb(data);
  11537. } else if (this.numComponents === 4) {
  11538. if (this._isColorConversionNeeded()) {
  11539. if (forceRGBoutput) {
  11540. return this._convertYcckToRgb(data);
  11541. } else {
  11542. return this._convertYcckToCmyk(data);
  11543. }
  11544. } else if (forceRGBoutput) {
  11545. return this._convertCmykToRgb(data);
  11546. }
  11547. }
  11548. return data;
  11549. }
  11550. };
  11551. return constructor;
  11552. })();
  11553. exports.JpegImage = JpegImage;
  11554. }));
  11555. (function (root, factory) {
  11556. {
  11557. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11558. root.pdfjsCoreArithmeticDecoder);
  11559. }
  11560. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11561. var info = sharedUtil.info;
  11562. var warn = sharedUtil.warn;
  11563. var error = sharedUtil.error;
  11564. var log2 = sharedUtil.log2;
  11565. var readUint16 = sharedUtil.readUint16;
  11566. var readUint32 = sharedUtil.readUint32;
  11567. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11568. var JpxImage = (function JpxImageClosure() {
  11569. // Table E.1
  11570. var SubbandsGainLog2 = {
  11571. 'LL': 0,
  11572. 'LH': 1,
  11573. 'HL': 1,
  11574. 'HH': 2
  11575. };
  11576. function JpxImage() {
  11577. this.failOnCorruptedImage = false;
  11578. }
  11579. JpxImage.prototype = {
  11580. parse: function JpxImage_parse(data) {
  11581. var head = readUint16(data, 0);
  11582. // No box header, immediate start of codestream (SOC)
  11583. if (head === 0xFF4F) {
  11584. this.parseCodestream(data, 0, data.length);
  11585. return;
  11586. }
  11587. var position = 0, length = data.length;
  11588. while (position < length) {
  11589. var headerSize = 8;
  11590. var lbox = readUint32(data, position);
  11591. var tbox = readUint32(data, position + 4);
  11592. position += headerSize;
  11593. if (lbox === 1) {
  11594. // XLBox: read UInt64 according to spec.
  11595. // JavaScript's int precision of 53 bit should be sufficient here.
  11596. lbox = readUint32(data, position) * 4294967296 +
  11597. readUint32(data, position + 4);
  11598. position += 8;
  11599. headerSize += 8;
  11600. }
  11601. if (lbox === 0) {
  11602. lbox = length - position + headerSize;
  11603. }
  11604. if (lbox < headerSize) {
  11605. error('JPX Error: Invalid box field size');
  11606. }
  11607. var dataLength = lbox - headerSize;
  11608. var jumpDataLength = true;
  11609. switch (tbox) {
  11610. case 0x6A703268: // 'jp2h'
  11611. jumpDataLength = false; // parsing child boxes
  11612. break;
  11613. case 0x636F6C72: // 'colr'
  11614. // Colorspaces are not used, the CS from the PDF is used.
  11615. var method = data[position];
  11616. if (method === 1) {
  11617. // enumerated colorspace
  11618. var colorspace = readUint32(data, position + 3);
  11619. switch (colorspace) {
  11620. case 16: // this indicates a sRGB colorspace
  11621. case 17: // this indicates a grayscale colorspace
  11622. case 18: // this indicates a YUV colorspace
  11623. break;
  11624. default:
  11625. warn('Unknown colorspace ' + colorspace);
  11626. break;
  11627. }
  11628. } else if (method === 2) {
  11629. info('ICC profile not supported');
  11630. }
  11631. break;
  11632. case 0x6A703263: // 'jp2c'
  11633. this.parseCodestream(data, position, position + dataLength);
  11634. break;
  11635. case 0x6A502020: // 'jP\024\024'
  11636. if (0x0d0a870a !== readUint32(data, position)) {
  11637. warn('Invalid JP2 signature');
  11638. }
  11639. break;
  11640. // The following header types are valid but currently not used:
  11641. case 0x6A501A1A: // 'jP\032\032'
  11642. case 0x66747970: // 'ftyp'
  11643. case 0x72726571: // 'rreq'
  11644. case 0x72657320: // 'res '
  11645. case 0x69686472: // 'ihdr'
  11646. break;
  11647. default:
  11648. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11649. (tbox >> 16) & 0xFF,
  11650. (tbox >> 8) & 0xFF,
  11651. tbox & 0xFF);
  11652. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11653. break;
  11654. }
  11655. if (jumpDataLength) {
  11656. position += dataLength;
  11657. }
  11658. }
  11659. },
  11660. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11661. var newByte = stream.getByte();
  11662. while (newByte >= 0) {
  11663. var oldByte = newByte;
  11664. newByte = stream.getByte();
  11665. var code = (oldByte << 8) | newByte;
  11666. // Image and tile size (SIZ)
  11667. if (code === 0xFF51) {
  11668. stream.skip(4);
  11669. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11670. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11671. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11672. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11673. stream.skip(16);
  11674. var Csiz = stream.getUint16(); // Byte 36
  11675. this.width = Xsiz - XOsiz;
  11676. this.height = Ysiz - YOsiz;
  11677. this.componentsCount = Csiz;
  11678. // Results are always returned as Uint8Arrays
  11679. this.bitsPerComponent = 8;
  11680. return;
  11681. }
  11682. }
  11683. error('JPX Error: No size marker found in JPX stream');
  11684. },
  11685. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11686. var context = {};
  11687. var doNotRecover = false;
  11688. try {
  11689. var position = start;
  11690. while (position + 1 < end) {
  11691. var code = readUint16(data, position);
  11692. position += 2;
  11693. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11694. switch (code) {
  11695. case 0xFF4F: // Start of codestream (SOC)
  11696. context.mainHeader = true;
  11697. break;
  11698. case 0xFFD9: // End of codestream (EOC)
  11699. break;
  11700. case 0xFF51: // Image and tile size (SIZ)
  11701. length = readUint16(data, position);
  11702. var siz = {};
  11703. siz.Xsiz = readUint32(data, position + 4);
  11704. siz.Ysiz = readUint32(data, position + 8);
  11705. siz.XOsiz = readUint32(data, position + 12);
  11706. siz.YOsiz = readUint32(data, position + 16);
  11707. siz.XTsiz = readUint32(data, position + 20);
  11708. siz.YTsiz = readUint32(data, position + 24);
  11709. siz.XTOsiz = readUint32(data, position + 28);
  11710. siz.YTOsiz = readUint32(data, position + 32);
  11711. var componentsCount = readUint16(data, position + 36);
  11712. siz.Csiz = componentsCount;
  11713. var components = [];
  11714. j = position + 38;
  11715. for (var i = 0; i < componentsCount; i++) {
  11716. var component = {
  11717. precision: (data[j] & 0x7F) + 1,
  11718. isSigned: !!(data[j] & 0x80),
  11719. XRsiz: data[j + 1],
  11720. YRsiz: data[j + 1]
  11721. };
  11722. calculateComponentDimensions(component, siz);
  11723. components.push(component);
  11724. }
  11725. context.SIZ = siz;
  11726. context.components = components;
  11727. calculateTileGrids(context, components);
  11728. context.QCC = [];
  11729. context.COC = [];
  11730. break;
  11731. case 0xFF5C: // Quantization default (QCD)
  11732. length = readUint16(data, position);
  11733. var qcd = {};
  11734. j = position + 2;
  11735. sqcd = data[j++];
  11736. switch (sqcd & 0x1F) {
  11737. case 0:
  11738. spqcdSize = 8;
  11739. scalarExpounded = true;
  11740. break;
  11741. case 1:
  11742. spqcdSize = 16;
  11743. scalarExpounded = false;
  11744. break;
  11745. case 2:
  11746. spqcdSize = 16;
  11747. scalarExpounded = true;
  11748. break;
  11749. default:
  11750. throw new Error('Invalid SQcd value ' + sqcd);
  11751. }
  11752. qcd.noQuantization = (spqcdSize === 8);
  11753. qcd.scalarExpounded = scalarExpounded;
  11754. qcd.guardBits = sqcd >> 5;
  11755. spqcds = [];
  11756. while (j < length + position) {
  11757. var spqcd = {};
  11758. if (spqcdSize === 8) {
  11759. spqcd.epsilon = data[j++] >> 3;
  11760. spqcd.mu = 0;
  11761. } else {
  11762. spqcd.epsilon = data[j] >> 3;
  11763. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11764. j += 2;
  11765. }
  11766. spqcds.push(spqcd);
  11767. }
  11768. qcd.SPqcds = spqcds;
  11769. if (context.mainHeader) {
  11770. context.QCD = qcd;
  11771. } else {
  11772. context.currentTile.QCD = qcd;
  11773. context.currentTile.QCC = [];
  11774. }
  11775. break;
  11776. case 0xFF5D: // Quantization component (QCC)
  11777. length = readUint16(data, position);
  11778. var qcc = {};
  11779. j = position + 2;
  11780. var cqcc;
  11781. if (context.SIZ.Csiz < 257) {
  11782. cqcc = data[j++];
  11783. } else {
  11784. cqcc = readUint16(data, j);
  11785. j += 2;
  11786. }
  11787. sqcd = data[j++];
  11788. switch (sqcd & 0x1F) {
  11789. case 0:
  11790. spqcdSize = 8;
  11791. scalarExpounded = true;
  11792. break;
  11793. case 1:
  11794. spqcdSize = 16;
  11795. scalarExpounded = false;
  11796. break;
  11797. case 2:
  11798. spqcdSize = 16;
  11799. scalarExpounded = true;
  11800. break;
  11801. default:
  11802. throw new Error('Invalid SQcd value ' + sqcd);
  11803. }
  11804. qcc.noQuantization = (spqcdSize === 8);
  11805. qcc.scalarExpounded = scalarExpounded;
  11806. qcc.guardBits = sqcd >> 5;
  11807. spqcds = [];
  11808. while (j < (length + position)) {
  11809. spqcd = {};
  11810. if (spqcdSize === 8) {
  11811. spqcd.epsilon = data[j++] >> 3;
  11812. spqcd.mu = 0;
  11813. } else {
  11814. spqcd.epsilon = data[j] >> 3;
  11815. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11816. j += 2;
  11817. }
  11818. spqcds.push(spqcd);
  11819. }
  11820. qcc.SPqcds = spqcds;
  11821. if (context.mainHeader) {
  11822. context.QCC[cqcc] = qcc;
  11823. } else {
  11824. context.currentTile.QCC[cqcc] = qcc;
  11825. }
  11826. break;
  11827. case 0xFF52: // Coding style default (COD)
  11828. length = readUint16(data, position);
  11829. var cod = {};
  11830. j = position + 2;
  11831. var scod = data[j++];
  11832. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11833. cod.sopMarkerUsed = !!(scod & 2);
  11834. cod.ephMarkerUsed = !!(scod & 4);
  11835. cod.progressionOrder = data[j++];
  11836. cod.layersCount = readUint16(data, j);
  11837. j += 2;
  11838. cod.multipleComponentTransform = data[j++];
  11839. cod.decompositionLevelsCount = data[j++];
  11840. cod.xcb = (data[j++] & 0xF) + 2;
  11841. cod.ycb = (data[j++] & 0xF) + 2;
  11842. var blockStyle = data[j++];
  11843. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11844. cod.resetContextProbabilities = !!(blockStyle & 2);
  11845. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11846. cod.verticalyStripe = !!(blockStyle & 8);
  11847. cod.predictableTermination = !!(blockStyle & 16);
  11848. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11849. cod.reversibleTransformation = data[j++];
  11850. if (cod.entropyCoderWithCustomPrecincts) {
  11851. var precinctsSizes = [];
  11852. while (j < length + position) {
  11853. var precinctsSize = data[j++];
  11854. precinctsSizes.push({
  11855. PPx: precinctsSize & 0xF,
  11856. PPy: precinctsSize >> 4
  11857. });
  11858. }
  11859. cod.precinctsSizes = precinctsSizes;
  11860. }
  11861. var unsupported = [];
  11862. if (cod.selectiveArithmeticCodingBypass) {
  11863. unsupported.push('selectiveArithmeticCodingBypass');
  11864. }
  11865. if (cod.resetContextProbabilities) {
  11866. unsupported.push('resetContextProbabilities');
  11867. }
  11868. if (cod.terminationOnEachCodingPass) {
  11869. unsupported.push('terminationOnEachCodingPass');
  11870. }
  11871. if (cod.verticalyStripe) {
  11872. unsupported.push('verticalyStripe');
  11873. }
  11874. if (cod.predictableTermination) {
  11875. unsupported.push('predictableTermination');
  11876. }
  11877. if (unsupported.length > 0) {
  11878. doNotRecover = true;
  11879. throw new Error('Unsupported COD options (' +
  11880. unsupported.join(', ') + ')');
  11881. }
  11882. if (context.mainHeader) {
  11883. context.COD = cod;
  11884. } else {
  11885. context.currentTile.COD = cod;
  11886. context.currentTile.COC = [];
  11887. }
  11888. break;
  11889. case 0xFF90: // Start of tile-part (SOT)
  11890. length = readUint16(data, position);
  11891. tile = {};
  11892. tile.index = readUint16(data, position + 2);
  11893. tile.length = readUint32(data, position + 4);
  11894. tile.dataEnd = tile.length + position - 2;
  11895. tile.partIndex = data[position + 8];
  11896. tile.partsCount = data[position + 9];
  11897. context.mainHeader = false;
  11898. if (tile.partIndex === 0) {
  11899. // reset component specific settings
  11900. tile.COD = context.COD;
  11901. tile.COC = context.COC.slice(0); // clone of the global COC
  11902. tile.QCD = context.QCD;
  11903. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11904. }
  11905. context.currentTile = tile;
  11906. break;
  11907. case 0xFF93: // Start of data (SOD)
  11908. tile = context.currentTile;
  11909. if (tile.partIndex === 0) {
  11910. initializeTile(context, tile.index);
  11911. buildPackets(context);
  11912. }
  11913. // moving to the end of the data
  11914. length = tile.dataEnd - position;
  11915. parseTilePackets(context, data, position, length);
  11916. break;
  11917. case 0xFF55: // Tile-part lengths, main header (TLM)
  11918. case 0xFF57: // Packet length, main header (PLM)
  11919. case 0xFF58: // Packet length, tile-part header (PLT)
  11920. case 0xFF64: // Comment (COM)
  11921. length = readUint16(data, position);
  11922. // skipping content
  11923. break;
  11924. case 0xFF53: // Coding style component (COC)
  11925. throw new Error('Codestream code 0xFF53 (COC) is ' +
  11926. 'not implemented');
  11927. default:
  11928. throw new Error('Unknown codestream code: ' + code.toString(16));
  11929. }
  11930. position += length;
  11931. }
  11932. } catch (e) {
  11933. if (doNotRecover || this.failOnCorruptedImage) {
  11934. error('JPX Error: ' + e.message);
  11935. } else {
  11936. warn('JPX: Trying to recover from: ' + e.message);
  11937. }
  11938. }
  11939. this.tiles = transformComponents(context);
  11940. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11941. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11942. this.componentsCount = context.SIZ.Csiz;
  11943. }
  11944. };
  11945. function calculateComponentDimensions(component, siz) {
  11946. // Section B.2 Component mapping
  11947. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11948. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11949. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11950. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11951. component.width = component.x1 - component.x0;
  11952. component.height = component.y1 - component.y0;
  11953. }
  11954. function calculateTileGrids(context, components) {
  11955. var siz = context.SIZ;
  11956. // Section B.3 Division into tile and tile-components
  11957. var tile, tiles = [];
  11958. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  11959. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  11960. for (var q = 0; q < numYtiles; q++) {
  11961. for (var p = 0; p < numXtiles; p++) {
  11962. tile = {};
  11963. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  11964. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  11965. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  11966. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  11967. tile.width = tile.tx1 - tile.tx0;
  11968. tile.height = tile.ty1 - tile.ty0;
  11969. tile.components = [];
  11970. tiles.push(tile);
  11971. }
  11972. }
  11973. context.tiles = tiles;
  11974. var componentsCount = siz.Csiz;
  11975. for (var i = 0, ii = componentsCount; i < ii; i++) {
  11976. var component = components[i];
  11977. for (var j = 0, jj = tiles.length; j < jj; j++) {
  11978. var tileComponent = {};
  11979. tile = tiles[j];
  11980. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  11981. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  11982. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  11983. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  11984. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  11985. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  11986. tile.components[i] = tileComponent;
  11987. }
  11988. }
  11989. }
  11990. function getBlocksDimensions(context, component, r) {
  11991. var codOrCoc = component.codingStyleParameters;
  11992. var result = {};
  11993. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  11994. result.PPx = 15;
  11995. result.PPy = 15;
  11996. } else {
  11997. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  11998. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  11999. }
  12000. // calculate codeblock size as described in section B.7
  12001. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12002. Math.min(codOrCoc.xcb, result.PPx));
  12003. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12004. Math.min(codOrCoc.ycb, result.PPy));
  12005. return result;
  12006. }
  12007. function buildPrecincts(context, resolution, dimensions) {
  12008. // Section B.6 Division resolution to precincts
  12009. var precinctWidth = 1 << dimensions.PPx;
  12010. var precinctHeight = 1 << dimensions.PPy;
  12011. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12012. // to precincts. Precinct partition divides a resolution according to width
  12013. // and height parameters. The subband that belongs to the resolution level
  12014. // has a different size than the level, unless it is the zero resolution.
  12015. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12016. // The precinct partitioning for a particular subband is derived from a
  12017. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12018. // resolution level)... The LL band associated with each resolution level is
  12019. // divided into precincts... Each of the resulting precinct regions is then
  12020. // mapped into its child subbands (if any) at the next lower resolution
  12021. // level. This is accomplished by using the coordinate transformation
  12022. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12023. // coordinates of a point in the LL band and child subband, respectively.
  12024. var isZeroRes = resolution.resLevel === 0;
  12025. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12026. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12027. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12028. Math.ceil(resolution.trx1 / precinctWidth) -
  12029. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12030. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12031. Math.ceil(resolution.try1 / precinctHeight) -
  12032. Math.floor(resolution.try0 / precinctHeight) : 0);
  12033. var numprecincts = numprecinctswide * numprecinctshigh;
  12034. resolution.precinctParameters = {
  12035. precinctWidth: precinctWidth,
  12036. precinctHeight: precinctHeight,
  12037. numprecinctswide: numprecinctswide,
  12038. numprecinctshigh: numprecinctshigh,
  12039. numprecincts: numprecincts,
  12040. precinctWidthInSubband: precinctWidthInSubband,
  12041. precinctHeightInSubband: precinctHeightInSubband
  12042. };
  12043. }
  12044. function buildCodeblocks(context, subband, dimensions) {
  12045. // Section B.7 Division sub-band into code-blocks
  12046. var xcb_ = dimensions.xcb_;
  12047. var ycb_ = dimensions.ycb_;
  12048. var codeblockWidth = 1 << xcb_;
  12049. var codeblockHeight = 1 << ycb_;
  12050. var cbx0 = subband.tbx0 >> xcb_;
  12051. var cby0 = subband.tby0 >> ycb_;
  12052. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12053. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12054. var precinctParameters = subband.resolution.precinctParameters;
  12055. var codeblocks = [];
  12056. var precincts = [];
  12057. var i, j, codeblock, precinctNumber;
  12058. for (j = cby0; j < cby1; j++) {
  12059. for (i = cbx0; i < cbx1; i++) {
  12060. codeblock = {
  12061. cbx: i,
  12062. cby: j,
  12063. tbx0: codeblockWidth * i,
  12064. tby0: codeblockHeight * j,
  12065. tbx1: codeblockWidth * (i + 1),
  12066. tby1: codeblockHeight * (j + 1)
  12067. };
  12068. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12069. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12070. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12071. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12072. // Calculate precinct number for this codeblock, codeblock position
  12073. // should be relative to its subband, use actual dimension and position
  12074. // See comment about codeblock group width and height
  12075. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12076. precinctParameters.precinctWidthInSubband);
  12077. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12078. precinctParameters.precinctHeightInSubband);
  12079. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12080. codeblock.precinctNumber = precinctNumber;
  12081. codeblock.subbandType = subband.type;
  12082. codeblock.Lblock = 3;
  12083. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12084. codeblock.tby1_ <= codeblock.tby0_) {
  12085. continue;
  12086. }
  12087. codeblocks.push(codeblock);
  12088. // building precinct for the sub-band
  12089. var precinct = precincts[precinctNumber];
  12090. if (precinct !== undefined) {
  12091. if (i < precinct.cbxMin) {
  12092. precinct.cbxMin = i;
  12093. } else if (i > precinct.cbxMax) {
  12094. precinct.cbxMax = i;
  12095. }
  12096. if (j < precinct.cbyMin) {
  12097. precinct.cbxMin = j;
  12098. } else if (j > precinct.cbyMax) {
  12099. precinct.cbyMax = j;
  12100. }
  12101. } else {
  12102. precincts[precinctNumber] = precinct = {
  12103. cbxMin: i,
  12104. cbyMin: j,
  12105. cbxMax: i,
  12106. cbyMax: j
  12107. };
  12108. }
  12109. codeblock.precinct = precinct;
  12110. }
  12111. }
  12112. subband.codeblockParameters = {
  12113. codeblockWidth: xcb_,
  12114. codeblockHeight: ycb_,
  12115. numcodeblockwide: cbx1 - cbx0 + 1,
  12116. numcodeblockhigh: cby1 - cby0 + 1
  12117. };
  12118. subband.codeblocks = codeblocks;
  12119. subband.precincts = precincts;
  12120. }
  12121. function createPacket(resolution, precinctNumber, layerNumber) {
  12122. var precinctCodeblocks = [];
  12123. // Section B.10.8 Order of info in packet
  12124. var subbands = resolution.subbands;
  12125. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12126. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12127. var subband = subbands[i];
  12128. var codeblocks = subband.codeblocks;
  12129. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12130. var codeblock = codeblocks[j];
  12131. if (codeblock.precinctNumber !== precinctNumber) {
  12132. continue;
  12133. }
  12134. precinctCodeblocks.push(codeblock);
  12135. }
  12136. }
  12137. return {
  12138. layerNumber: layerNumber,
  12139. codeblocks: precinctCodeblocks
  12140. };
  12141. }
  12142. function LayerResolutionComponentPositionIterator(context) {
  12143. var siz = context.SIZ;
  12144. var tileIndex = context.currentTile.index;
  12145. var tile = context.tiles[tileIndex];
  12146. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12147. var componentsCount = siz.Csiz;
  12148. var maxDecompositionLevelsCount = 0;
  12149. for (var q = 0; q < componentsCount; q++) {
  12150. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12151. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12152. }
  12153. var l = 0, r = 0, i = 0, k = 0;
  12154. this.nextPacket = function JpxImage_nextPacket() {
  12155. // Section B.12.1.1 Layer-resolution-component-position
  12156. for (; l < layersCount; l++) {
  12157. for (; r <= maxDecompositionLevelsCount; r++) {
  12158. for (; i < componentsCount; i++) {
  12159. var component = tile.components[i];
  12160. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12161. continue;
  12162. }
  12163. var resolution = component.resolutions[r];
  12164. var numprecincts = resolution.precinctParameters.numprecincts;
  12165. for (; k < numprecincts;) {
  12166. var packet = createPacket(resolution, k, l);
  12167. k++;
  12168. return packet;
  12169. }
  12170. k = 0;
  12171. }
  12172. i = 0;
  12173. }
  12174. r = 0;
  12175. }
  12176. error('JPX Error: Out of packets');
  12177. };
  12178. }
  12179. function ResolutionLayerComponentPositionIterator(context) {
  12180. var siz = context.SIZ;
  12181. var tileIndex = context.currentTile.index;
  12182. var tile = context.tiles[tileIndex];
  12183. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12184. var componentsCount = siz.Csiz;
  12185. var maxDecompositionLevelsCount = 0;
  12186. for (var q = 0; q < componentsCount; q++) {
  12187. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12188. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12189. }
  12190. var r = 0, l = 0, i = 0, k = 0;
  12191. this.nextPacket = function JpxImage_nextPacket() {
  12192. // Section B.12.1.2 Resolution-layer-component-position
  12193. for (; r <= maxDecompositionLevelsCount; r++) {
  12194. for (; l < layersCount; l++) {
  12195. for (; i < componentsCount; i++) {
  12196. var component = tile.components[i];
  12197. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12198. continue;
  12199. }
  12200. var resolution = component.resolutions[r];
  12201. var numprecincts = resolution.precinctParameters.numprecincts;
  12202. for (; k < numprecincts;) {
  12203. var packet = createPacket(resolution, k, l);
  12204. k++;
  12205. return packet;
  12206. }
  12207. k = 0;
  12208. }
  12209. i = 0;
  12210. }
  12211. l = 0;
  12212. }
  12213. error('JPX Error: Out of packets');
  12214. };
  12215. }
  12216. function ResolutionPositionComponentLayerIterator(context) {
  12217. var siz = context.SIZ;
  12218. var tileIndex = context.currentTile.index;
  12219. var tile = context.tiles[tileIndex];
  12220. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12221. var componentsCount = siz.Csiz;
  12222. var l, r, c, p;
  12223. var maxDecompositionLevelsCount = 0;
  12224. for (c = 0; c < componentsCount; c++) {
  12225. var component = tile.components[c];
  12226. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12227. component.codingStyleParameters.decompositionLevelsCount);
  12228. }
  12229. var maxNumPrecinctsInLevel = new Int32Array(
  12230. maxDecompositionLevelsCount + 1);
  12231. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12232. var maxNumPrecincts = 0;
  12233. for (c = 0; c < componentsCount; ++c) {
  12234. var resolutions = tile.components[c].resolutions;
  12235. if (r < resolutions.length) {
  12236. maxNumPrecincts = Math.max(maxNumPrecincts,
  12237. resolutions[r].precinctParameters.numprecincts);
  12238. }
  12239. }
  12240. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12241. }
  12242. l = 0;
  12243. r = 0;
  12244. c = 0;
  12245. p = 0;
  12246. this.nextPacket = function JpxImage_nextPacket() {
  12247. // Section B.12.1.3 Resolution-position-component-layer
  12248. for (; r <= maxDecompositionLevelsCount; r++) {
  12249. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12250. for (; c < componentsCount; c++) {
  12251. var component = tile.components[c];
  12252. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12253. continue;
  12254. }
  12255. var resolution = component.resolutions[r];
  12256. var numprecincts = resolution.precinctParameters.numprecincts;
  12257. if (p >= numprecincts) {
  12258. continue;
  12259. }
  12260. for (; l < layersCount;) {
  12261. var packet = createPacket(resolution, p, l);
  12262. l++;
  12263. return packet;
  12264. }
  12265. l = 0;
  12266. }
  12267. c = 0;
  12268. }
  12269. p = 0;
  12270. }
  12271. error('JPX Error: Out of packets');
  12272. };
  12273. }
  12274. function PositionComponentResolutionLayerIterator(context) {
  12275. var siz = context.SIZ;
  12276. var tileIndex = context.currentTile.index;
  12277. var tile = context.tiles[tileIndex];
  12278. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12279. var componentsCount = siz.Csiz;
  12280. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12281. var precinctsIterationSizes = precinctsSizes;
  12282. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12283. this.nextPacket = function JpxImage_nextPacket() {
  12284. // Section B.12.1.4 Position-component-resolution-layer
  12285. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12286. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12287. for (; c < componentsCount; c++) {
  12288. var component = tile.components[c];
  12289. var decompositionLevelsCount =
  12290. component.codingStyleParameters.decompositionLevelsCount;
  12291. for (; r <= decompositionLevelsCount; r++) {
  12292. var resolution = component.resolutions[r];
  12293. var sizeInImageScale =
  12294. precinctsSizes.components[c].resolutions[r];
  12295. var k = getPrecinctIndexIfExist(
  12296. px,
  12297. py,
  12298. sizeInImageScale,
  12299. precinctsIterationSizes,
  12300. resolution);
  12301. if (k === null) {
  12302. continue;
  12303. }
  12304. for (; l < layersCount;) {
  12305. var packet = createPacket(resolution, k, l);
  12306. l++;
  12307. return packet;
  12308. }
  12309. l = 0;
  12310. }
  12311. r = 0;
  12312. }
  12313. c = 0;
  12314. }
  12315. px = 0;
  12316. }
  12317. error('JPX Error: Out of packets');
  12318. };
  12319. }
  12320. function ComponentPositionResolutionLayerIterator(context) {
  12321. var siz = context.SIZ;
  12322. var tileIndex = context.currentTile.index;
  12323. var tile = context.tiles[tileIndex];
  12324. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12325. var componentsCount = siz.Csiz;
  12326. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12327. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12328. this.nextPacket = function JpxImage_nextPacket() {
  12329. // Section B.12.1.5 Component-position-resolution-layer
  12330. for (; c < componentsCount; ++c) {
  12331. var component = tile.components[c];
  12332. var precinctsIterationSizes = precinctsSizes.components[c];
  12333. var decompositionLevelsCount =
  12334. component.codingStyleParameters.decompositionLevelsCount;
  12335. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12336. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12337. for (; r <= decompositionLevelsCount; r++) {
  12338. var resolution = component.resolutions[r];
  12339. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12340. var k = getPrecinctIndexIfExist(
  12341. px,
  12342. py,
  12343. sizeInImageScale,
  12344. precinctsIterationSizes,
  12345. resolution);
  12346. if (k === null) {
  12347. continue;
  12348. }
  12349. for (; l < layersCount;) {
  12350. var packet = createPacket(resolution, k, l);
  12351. l++;
  12352. return packet;
  12353. }
  12354. l = 0;
  12355. }
  12356. r = 0;
  12357. }
  12358. px = 0;
  12359. }
  12360. py = 0;
  12361. }
  12362. error('JPX Error: Out of packets');
  12363. };
  12364. }
  12365. function getPrecinctIndexIfExist(
  12366. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12367. var posX = pxIndex * precinctIterationSizes.minWidth;
  12368. var posY = pyIndex * precinctIterationSizes.minHeight;
  12369. if (posX % sizeInImageScale.width !== 0 ||
  12370. posY % sizeInImageScale.height !== 0) {
  12371. return null;
  12372. }
  12373. var startPrecinctRowIndex =
  12374. (posY / sizeInImageScale.width) *
  12375. resolution.precinctParameters.numprecinctswide;
  12376. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12377. }
  12378. function getPrecinctSizesInImageScale(tile) {
  12379. var componentsCount = tile.components.length;
  12380. var minWidth = Number.MAX_VALUE;
  12381. var minHeight = Number.MAX_VALUE;
  12382. var maxNumWide = 0;
  12383. var maxNumHigh = 0;
  12384. var sizePerComponent = new Array(componentsCount);
  12385. for (var c = 0; c < componentsCount; c++) {
  12386. var component = tile.components[c];
  12387. var decompositionLevelsCount =
  12388. component.codingStyleParameters.decompositionLevelsCount;
  12389. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12390. var minWidthCurrentComponent = Number.MAX_VALUE;
  12391. var minHeightCurrentComponent = Number.MAX_VALUE;
  12392. var maxNumWideCurrentComponent = 0;
  12393. var maxNumHighCurrentComponent = 0;
  12394. var scale = 1;
  12395. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12396. var resolution = component.resolutions[r];
  12397. var widthCurrentResolution =
  12398. scale * resolution.precinctParameters.precinctWidth;
  12399. var heightCurrentResolution =
  12400. scale * resolution.precinctParameters.precinctHeight;
  12401. minWidthCurrentComponent = Math.min(
  12402. minWidthCurrentComponent,
  12403. widthCurrentResolution);
  12404. minHeightCurrentComponent = Math.min(
  12405. minHeightCurrentComponent,
  12406. heightCurrentResolution);
  12407. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12408. resolution.precinctParameters.numprecinctswide);
  12409. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12410. resolution.precinctParameters.numprecinctshigh);
  12411. sizePerResolution[r] = {
  12412. width: widthCurrentResolution,
  12413. height: heightCurrentResolution
  12414. };
  12415. scale <<= 1;
  12416. }
  12417. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12418. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12419. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12420. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12421. sizePerComponent[c] = {
  12422. resolutions: sizePerResolution,
  12423. minWidth: minWidthCurrentComponent,
  12424. minHeight: minHeightCurrentComponent,
  12425. maxNumWide: maxNumWideCurrentComponent,
  12426. maxNumHigh: maxNumHighCurrentComponent
  12427. };
  12428. }
  12429. return {
  12430. components: sizePerComponent,
  12431. minWidth: minWidth,
  12432. minHeight: minHeight,
  12433. maxNumWide: maxNumWide,
  12434. maxNumHigh: maxNumHigh
  12435. };
  12436. }
  12437. function buildPackets(context) {
  12438. var siz = context.SIZ;
  12439. var tileIndex = context.currentTile.index;
  12440. var tile = context.tiles[tileIndex];
  12441. var componentsCount = siz.Csiz;
  12442. // Creating resolutions and sub-bands for each component
  12443. for (var c = 0; c < componentsCount; c++) {
  12444. var component = tile.components[c];
  12445. var decompositionLevelsCount =
  12446. component.codingStyleParameters.decompositionLevelsCount;
  12447. // Section B.5 Resolution levels and sub-bands
  12448. var resolutions = [];
  12449. var subbands = [];
  12450. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12451. var blocksDimensions = getBlocksDimensions(context, component, r);
  12452. var resolution = {};
  12453. var scale = 1 << (decompositionLevelsCount - r);
  12454. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12455. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12456. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12457. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12458. resolution.resLevel = r;
  12459. buildPrecincts(context, resolution, blocksDimensions);
  12460. resolutions.push(resolution);
  12461. var subband;
  12462. if (r === 0) {
  12463. // one sub-band (LL) with last decomposition
  12464. subband = {};
  12465. subband.type = 'LL';
  12466. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12467. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12468. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12469. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12470. subband.resolution = resolution;
  12471. buildCodeblocks(context, subband, blocksDimensions);
  12472. subbands.push(subband);
  12473. resolution.subbands = [subband];
  12474. } else {
  12475. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12476. var resolutionSubbands = [];
  12477. // three sub-bands (HL, LH and HH) with rest of decompositions
  12478. subband = {};
  12479. subband.type = 'HL';
  12480. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12481. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12482. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12483. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12484. subband.resolution = resolution;
  12485. buildCodeblocks(context, subband, blocksDimensions);
  12486. subbands.push(subband);
  12487. resolutionSubbands.push(subband);
  12488. subband = {};
  12489. subband.type = 'LH';
  12490. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12491. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12492. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12493. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12494. subband.resolution = resolution;
  12495. buildCodeblocks(context, subband, blocksDimensions);
  12496. subbands.push(subband);
  12497. resolutionSubbands.push(subband);
  12498. subband = {};
  12499. subband.type = 'HH';
  12500. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12501. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12502. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12503. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12504. subband.resolution = resolution;
  12505. buildCodeblocks(context, subband, blocksDimensions);
  12506. subbands.push(subband);
  12507. resolutionSubbands.push(subband);
  12508. resolution.subbands = resolutionSubbands;
  12509. }
  12510. }
  12511. component.resolutions = resolutions;
  12512. component.subbands = subbands;
  12513. }
  12514. // Generate the packets sequence
  12515. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12516. switch (progressionOrder) {
  12517. case 0:
  12518. tile.packetsIterator =
  12519. new LayerResolutionComponentPositionIterator(context);
  12520. break;
  12521. case 1:
  12522. tile.packetsIterator =
  12523. new ResolutionLayerComponentPositionIterator(context);
  12524. break;
  12525. case 2:
  12526. tile.packetsIterator =
  12527. new ResolutionPositionComponentLayerIterator(context);
  12528. break;
  12529. case 3:
  12530. tile.packetsIterator =
  12531. new PositionComponentResolutionLayerIterator(context);
  12532. break;
  12533. case 4:
  12534. tile.packetsIterator =
  12535. new ComponentPositionResolutionLayerIterator(context);
  12536. break;
  12537. default:
  12538. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12539. }
  12540. }
  12541. function parseTilePackets(context, data, offset, dataLength) {
  12542. var position = 0;
  12543. var buffer, bufferSize = 0, skipNextBit = false;
  12544. function readBits(count) {
  12545. while (bufferSize < count) {
  12546. var b = data[offset + position];
  12547. position++;
  12548. if (skipNextBit) {
  12549. buffer = (buffer << 7) | b;
  12550. bufferSize += 7;
  12551. skipNextBit = false;
  12552. } else {
  12553. buffer = (buffer << 8) | b;
  12554. bufferSize += 8;
  12555. }
  12556. if (b === 0xFF) {
  12557. skipNextBit = true;
  12558. }
  12559. }
  12560. bufferSize -= count;
  12561. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12562. }
  12563. function skipMarkerIfEqual(value) {
  12564. if (data[offset + position - 1] === 0xFF &&
  12565. data[offset + position] === value) {
  12566. skipBytes(1);
  12567. return true;
  12568. } else if (data[offset + position] === 0xFF &&
  12569. data[offset + position + 1] === value) {
  12570. skipBytes(2);
  12571. return true;
  12572. }
  12573. return false;
  12574. }
  12575. function skipBytes(count) {
  12576. position += count;
  12577. }
  12578. function alignToByte() {
  12579. bufferSize = 0;
  12580. if (skipNextBit) {
  12581. position++;
  12582. skipNextBit = false;
  12583. }
  12584. }
  12585. function readCodingpasses() {
  12586. if (readBits(1) === 0) {
  12587. return 1;
  12588. }
  12589. if (readBits(1) === 0) {
  12590. return 2;
  12591. }
  12592. var value = readBits(2);
  12593. if (value < 3) {
  12594. return value + 3;
  12595. }
  12596. value = readBits(5);
  12597. if (value < 31) {
  12598. return value + 6;
  12599. }
  12600. value = readBits(7);
  12601. return value + 37;
  12602. }
  12603. var tileIndex = context.currentTile.index;
  12604. var tile = context.tiles[tileIndex];
  12605. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12606. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12607. var packetsIterator = tile.packetsIterator;
  12608. while (position < dataLength) {
  12609. alignToByte();
  12610. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12611. // Skip also marker segment length and packet sequence ID
  12612. skipBytes(4);
  12613. }
  12614. var packet = packetsIterator.nextPacket();
  12615. if (!readBits(1)) {
  12616. continue;
  12617. }
  12618. var layerNumber = packet.layerNumber;
  12619. var queue = [], codeblock;
  12620. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12621. codeblock = packet.codeblocks[i];
  12622. var precinct = codeblock.precinct;
  12623. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12624. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12625. var codeblockIncluded = false;
  12626. var firstTimeInclusion = false;
  12627. var valueReady;
  12628. if (codeblock['included'] !== undefined) {
  12629. codeblockIncluded = !!readBits(1);
  12630. } else {
  12631. // reading inclusion tree
  12632. precinct = codeblock.precinct;
  12633. var inclusionTree, zeroBitPlanesTree;
  12634. if (precinct['inclusionTree'] !== undefined) {
  12635. inclusionTree = precinct.inclusionTree;
  12636. } else {
  12637. // building inclusion and zero bit-planes trees
  12638. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12639. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12640. inclusionTree = new InclusionTree(width, height, layerNumber);
  12641. zeroBitPlanesTree = new TagTree(width, height);
  12642. precinct.inclusionTree = inclusionTree;
  12643. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12644. }
  12645. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12646. while (true) {
  12647. if (readBits(1)) {
  12648. valueReady = !inclusionTree.nextLevel();
  12649. if (valueReady) {
  12650. codeblock.included = true;
  12651. codeblockIncluded = firstTimeInclusion = true;
  12652. break;
  12653. }
  12654. } else {
  12655. inclusionTree.incrementValue(layerNumber);
  12656. break;
  12657. }
  12658. }
  12659. }
  12660. }
  12661. if (!codeblockIncluded) {
  12662. continue;
  12663. }
  12664. if (firstTimeInclusion) {
  12665. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12666. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12667. while (true) {
  12668. if (readBits(1)) {
  12669. valueReady = !zeroBitPlanesTree.nextLevel();
  12670. if (valueReady) {
  12671. break;
  12672. }
  12673. } else {
  12674. zeroBitPlanesTree.incrementValue();
  12675. }
  12676. }
  12677. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12678. }
  12679. var codingpasses = readCodingpasses();
  12680. while (readBits(1)) {
  12681. codeblock.Lblock++;
  12682. }
  12683. var codingpassesLog2 = log2(codingpasses);
  12684. // rounding down log2
  12685. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12686. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12687. var codedDataLength = readBits(bits);
  12688. queue.push({
  12689. codeblock: codeblock,
  12690. codingpasses: codingpasses,
  12691. dataLength: codedDataLength
  12692. });
  12693. }
  12694. alignToByte();
  12695. if (ephMarkerUsed) {
  12696. skipMarkerIfEqual(0x92);
  12697. }
  12698. while (queue.length > 0) {
  12699. var packetItem = queue.shift();
  12700. codeblock = packetItem.codeblock;
  12701. if (codeblock['data'] === undefined) {
  12702. codeblock.data = [];
  12703. }
  12704. codeblock.data.push({
  12705. data: data,
  12706. start: offset + position,
  12707. end: offset + position + packetItem.dataLength,
  12708. codingpasses: packetItem.codingpasses
  12709. });
  12710. position += packetItem.dataLength;
  12711. }
  12712. }
  12713. return position;
  12714. }
  12715. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12716. delta, mb, reversible, segmentationSymbolUsed) {
  12717. var x0 = subband.tbx0;
  12718. var y0 = subband.tby0;
  12719. var width = subband.tbx1 - subband.tbx0;
  12720. var codeblocks = subband.codeblocks;
  12721. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12722. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12723. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12724. var codeblock = codeblocks[i];
  12725. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12726. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12727. if (blockWidth === 0 || blockHeight === 0) {
  12728. continue;
  12729. }
  12730. if (codeblock['data'] === undefined) {
  12731. continue;
  12732. }
  12733. var bitModel, currentCodingpassType;
  12734. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12735. codeblock.zeroBitPlanes, mb);
  12736. currentCodingpassType = 2; // first bit plane starts from cleanup
  12737. // collect data
  12738. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12739. var j, jj, dataItem;
  12740. for (j = 0, jj = data.length; j < jj; j++) {
  12741. dataItem = data[j];
  12742. totalLength += dataItem.end - dataItem.start;
  12743. codingpasses += dataItem.codingpasses;
  12744. }
  12745. var encodedData = new Uint8Array(totalLength);
  12746. var position = 0;
  12747. for (j = 0, jj = data.length; j < jj; j++) {
  12748. dataItem = data[j];
  12749. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12750. encodedData.set(chunk, position);
  12751. position += chunk.length;
  12752. }
  12753. // decoding the item
  12754. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12755. bitModel.setDecoder(decoder);
  12756. for (j = 0; j < codingpasses; j++) {
  12757. switch (currentCodingpassType) {
  12758. case 0:
  12759. bitModel.runSignificancePropagationPass();
  12760. break;
  12761. case 1:
  12762. bitModel.runMagnitudeRefinementPass();
  12763. break;
  12764. case 2:
  12765. bitModel.runCleanupPass();
  12766. if (segmentationSymbolUsed) {
  12767. bitModel.checkSegmentationSymbol();
  12768. }
  12769. break;
  12770. }
  12771. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12772. }
  12773. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12774. var sign = bitModel.coefficentsSign;
  12775. var magnitude = bitModel.coefficentsMagnitude;
  12776. var bitsDecoded = bitModel.bitsDecoded;
  12777. var magnitudeCorrection = reversible ? 0 : 0.5;
  12778. var k, n, nb;
  12779. position = 0;
  12780. // Do the interleaving of Section F.3.3 here, so we do not need
  12781. // to copy later. LL level is not interleaved, just copied.
  12782. var interleave = (subband.type !== 'LL');
  12783. for (j = 0; j < blockHeight; j++) {
  12784. var row = (offset / width) | 0; // row in the non-interleaved subband
  12785. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12786. for (k = 0; k < blockWidth; k++) {
  12787. n = magnitude[position];
  12788. if (n !== 0) {
  12789. n = (n + magnitudeCorrection) * delta;
  12790. if (sign[position] !== 0) {
  12791. n = -n;
  12792. }
  12793. nb = bitsDecoded[position];
  12794. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12795. if (reversible && (nb >= mb)) {
  12796. coefficients[pos] = n;
  12797. } else {
  12798. coefficients[pos] = n * (1 << (mb - nb));
  12799. }
  12800. }
  12801. offset++;
  12802. position++;
  12803. }
  12804. offset += width - blockWidth;
  12805. }
  12806. }
  12807. }
  12808. function transformTile(context, tile, c) {
  12809. var component = tile.components[c];
  12810. var codingStyleParameters = component.codingStyleParameters;
  12811. var quantizationParameters = component.quantizationParameters;
  12812. var decompositionLevelsCount =
  12813. codingStyleParameters.decompositionLevelsCount;
  12814. var spqcds = quantizationParameters.SPqcds;
  12815. var scalarExpounded = quantizationParameters.scalarExpounded;
  12816. var guardBits = quantizationParameters.guardBits;
  12817. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12818. var precision = context.components[c].precision;
  12819. var reversible = codingStyleParameters.reversibleTransformation;
  12820. var transform = (reversible ? new ReversibleTransform() :
  12821. new IrreversibleTransform());
  12822. var subbandCoefficients = [];
  12823. var b = 0;
  12824. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12825. var resolution = component.resolutions[i];
  12826. var width = resolution.trx1 - resolution.trx0;
  12827. var height = resolution.try1 - resolution.try0;
  12828. // Allocate space for the whole sublevel.
  12829. var coefficients = new Float32Array(width * height);
  12830. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12831. var mu, epsilon;
  12832. if (!scalarExpounded) {
  12833. // formula E-5
  12834. mu = spqcds[0].mu;
  12835. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12836. } else {
  12837. mu = spqcds[b].mu;
  12838. epsilon = spqcds[b].epsilon;
  12839. b++;
  12840. }
  12841. var subband = resolution.subbands[j];
  12842. var gainLog2 = SubbandsGainLog2[subband.type];
  12843. // calculate quantization coefficient (Section E.1.1.1)
  12844. var delta = (reversible ? 1 :
  12845. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12846. var mb = (guardBits + epsilon - 1);
  12847. // In the first resolution level, copyCoefficients will fill the
  12848. // whole array with coefficients. In the succeeding passes,
  12849. // copyCoefficients will consecutively fill in the values that belong
  12850. // to the interleaved positions of the HL, LH, and HH coefficients.
  12851. // The LL coefficients will then be interleaved in Transform.iterate().
  12852. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12853. reversible, segmentationSymbolUsed);
  12854. }
  12855. subbandCoefficients.push({
  12856. width: width,
  12857. height: height,
  12858. items: coefficients
  12859. });
  12860. }
  12861. var result = transform.calculate(subbandCoefficients,
  12862. component.tcx0, component.tcy0);
  12863. return {
  12864. left: component.tcx0,
  12865. top: component.tcy0,
  12866. width: result.width,
  12867. height: result.height,
  12868. items: result.items
  12869. };
  12870. }
  12871. function transformComponents(context) {
  12872. var siz = context.SIZ;
  12873. var components = context.components;
  12874. var componentsCount = siz.Csiz;
  12875. var resultImages = [];
  12876. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12877. var tile = context.tiles[i];
  12878. var transformedTiles = [];
  12879. var c;
  12880. for (c = 0; c < componentsCount; c++) {
  12881. transformedTiles[c] = transformTile(context, tile, c);
  12882. }
  12883. var tile0 = transformedTiles[0];
  12884. var out = new Uint8Array(tile0.items.length * componentsCount);
  12885. var result = {
  12886. left: tile0.left,
  12887. top: tile0.top,
  12888. width: tile0.width,
  12889. height: tile0.height,
  12890. items: out
  12891. };
  12892. // Section G.2.2 Inverse multi component transform
  12893. var shift, offset, max, min, maxK;
  12894. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12895. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12896. var fourComponents = componentsCount === 4;
  12897. var y0items = transformedTiles[0].items;
  12898. var y1items = transformedTiles[1].items;
  12899. var y2items = transformedTiles[2].items;
  12900. var y3items = fourComponents ? transformedTiles[3].items : null;
  12901. // HACK: The multiple component transform formulas below assume that
  12902. // all components have the same precision. With this in mind, we
  12903. // compute shift and offset only once.
  12904. shift = components[0].precision - 8;
  12905. offset = (128 << shift) + 0.5;
  12906. max = 255 * (1 << shift);
  12907. maxK = max * 0.5;
  12908. min = -maxK;
  12909. var component0 = tile.components[0];
  12910. var alpha01 = componentsCount - 3;
  12911. jj = y0items.length;
  12912. if (!component0.codingStyleParameters.reversibleTransformation) {
  12913. // inverse irreversible multiple component transform
  12914. for (j = 0; j < jj; j++, pos += alpha01) {
  12915. y0 = y0items[j] + offset;
  12916. y1 = y1items[j];
  12917. y2 = y2items[j];
  12918. r = y0 + 1.402 * y2;
  12919. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12920. b = y0 + 1.772 * y1;
  12921. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12922. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12923. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12924. }
  12925. } else {
  12926. // inverse reversible multiple component transform
  12927. for (j = 0; j < jj; j++, pos += alpha01) {
  12928. y0 = y0items[j] + offset;
  12929. y1 = y1items[j];
  12930. y2 = y2items[j];
  12931. g = y0 - ((y2 + y1) >> 2);
  12932. r = g + y2;
  12933. b = g + y1;
  12934. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12935. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12936. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12937. }
  12938. }
  12939. if (fourComponents) {
  12940. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12941. k = y3items[j];
  12942. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12943. }
  12944. }
  12945. } else { // no multi-component transform
  12946. for (c = 0; c < componentsCount; c++) {
  12947. var items = transformedTiles[c].items;
  12948. shift = components[c].precision - 8;
  12949. offset = (128 << shift) + 0.5;
  12950. max = (127.5 * (1 << shift));
  12951. min = -max;
  12952. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12953. val = items[j];
  12954. out[pos] = val <= min ? 0 :
  12955. val >= max ? 255 : (val + offset) >> shift;
  12956. pos += componentsCount;
  12957. }
  12958. }
  12959. }
  12960. resultImages.push(result);
  12961. }
  12962. return resultImages;
  12963. }
  12964. function initializeTile(context, tileIndex) {
  12965. var siz = context.SIZ;
  12966. var componentsCount = siz.Csiz;
  12967. var tile = context.tiles[tileIndex];
  12968. for (var c = 0; c < componentsCount; c++) {
  12969. var component = tile.components[c];
  12970. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  12971. context.currentTile.QCC[c] : context.currentTile.QCD);
  12972. component.quantizationParameters = qcdOrQcc;
  12973. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  12974. context.currentTile.COC[c] : context.currentTile.COD);
  12975. component.codingStyleParameters = codOrCoc;
  12976. }
  12977. tile.codingStyleDefaultParameters = context.currentTile.COD;
  12978. }
  12979. // Section B.10.2 Tag trees
  12980. var TagTree = (function TagTreeClosure() {
  12981. function TagTree(width, height) {
  12982. var levelsLength = log2(Math.max(width, height)) + 1;
  12983. this.levels = [];
  12984. for (var i = 0; i < levelsLength; i++) {
  12985. var level = {
  12986. width: width,
  12987. height: height,
  12988. items: []
  12989. };
  12990. this.levels.push(level);
  12991. width = Math.ceil(width / 2);
  12992. height = Math.ceil(height / 2);
  12993. }
  12994. }
  12995. TagTree.prototype = {
  12996. reset: function TagTree_reset(i, j) {
  12997. var currentLevel = 0, value = 0, level;
  12998. while (currentLevel < this.levels.length) {
  12999. level = this.levels[currentLevel];
  13000. var index = i + j * level.width;
  13001. if (level.items[index] !== undefined) {
  13002. value = level.items[index];
  13003. break;
  13004. }
  13005. level.index = index;
  13006. i >>= 1;
  13007. j >>= 1;
  13008. currentLevel++;
  13009. }
  13010. currentLevel--;
  13011. level = this.levels[currentLevel];
  13012. level.items[level.index] = value;
  13013. this.currentLevel = currentLevel;
  13014. delete this.value;
  13015. },
  13016. incrementValue: function TagTree_incrementValue() {
  13017. var level = this.levels[this.currentLevel];
  13018. level.items[level.index]++;
  13019. },
  13020. nextLevel: function TagTree_nextLevel() {
  13021. var currentLevel = this.currentLevel;
  13022. var level = this.levels[currentLevel];
  13023. var value = level.items[level.index];
  13024. currentLevel--;
  13025. if (currentLevel < 0) {
  13026. this.value = value;
  13027. return false;
  13028. }
  13029. this.currentLevel = currentLevel;
  13030. level = this.levels[currentLevel];
  13031. level.items[level.index] = value;
  13032. return true;
  13033. }
  13034. };
  13035. return TagTree;
  13036. })();
  13037. var InclusionTree = (function InclusionTreeClosure() {
  13038. function InclusionTree(width, height, defaultValue) {
  13039. var levelsLength = log2(Math.max(width, height)) + 1;
  13040. this.levels = [];
  13041. for (var i = 0; i < levelsLength; i++) {
  13042. var items = new Uint8Array(width * height);
  13043. for (var j = 0, jj = items.length; j < jj; j++) {
  13044. items[j] = defaultValue;
  13045. }
  13046. var level = {
  13047. width: width,
  13048. height: height,
  13049. items: items
  13050. };
  13051. this.levels.push(level);
  13052. width = Math.ceil(width / 2);
  13053. height = Math.ceil(height / 2);
  13054. }
  13055. }
  13056. InclusionTree.prototype = {
  13057. reset: function InclusionTree_reset(i, j, stopValue) {
  13058. var currentLevel = 0;
  13059. while (currentLevel < this.levels.length) {
  13060. var level = this.levels[currentLevel];
  13061. var index = i + j * level.width;
  13062. level.index = index;
  13063. var value = level.items[index];
  13064. if (value === 0xFF) {
  13065. break;
  13066. }
  13067. if (value > stopValue) {
  13068. this.currentLevel = currentLevel;
  13069. // already know about this one, propagating the value to top levels
  13070. this.propagateValues();
  13071. return false;
  13072. }
  13073. i >>= 1;
  13074. j >>= 1;
  13075. currentLevel++;
  13076. }
  13077. this.currentLevel = currentLevel - 1;
  13078. return true;
  13079. },
  13080. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13081. var level = this.levels[this.currentLevel];
  13082. level.items[level.index] = stopValue + 1;
  13083. this.propagateValues();
  13084. },
  13085. propagateValues: function InclusionTree_propagateValues() {
  13086. var levelIndex = this.currentLevel;
  13087. var level = this.levels[levelIndex];
  13088. var currentValue = level.items[level.index];
  13089. while (--levelIndex >= 0) {
  13090. level = this.levels[levelIndex];
  13091. level.items[level.index] = currentValue;
  13092. }
  13093. },
  13094. nextLevel: function InclusionTree_nextLevel() {
  13095. var currentLevel = this.currentLevel;
  13096. var level = this.levels[currentLevel];
  13097. var value = level.items[level.index];
  13098. level.items[level.index] = 0xFF;
  13099. currentLevel--;
  13100. if (currentLevel < 0) {
  13101. return false;
  13102. }
  13103. this.currentLevel = currentLevel;
  13104. level = this.levels[currentLevel];
  13105. level.items[level.index] = value;
  13106. return true;
  13107. }
  13108. };
  13109. return InclusionTree;
  13110. })();
  13111. // Section D. Coefficient bit modeling
  13112. var BitModel = (function BitModelClosure() {
  13113. var UNIFORM_CONTEXT = 17;
  13114. var RUNLENGTH_CONTEXT = 18;
  13115. // Table D-1
  13116. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13117. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13118. var LLAndLHContextsLabel = new Uint8Array([
  13119. 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,
  13120. 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,
  13121. 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
  13122. ]);
  13123. var HLContextLabel = new Uint8Array([
  13124. 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,
  13125. 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,
  13126. 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
  13127. ]);
  13128. var HHContextLabel = new Uint8Array([
  13129. 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,
  13130. 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,
  13131. 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
  13132. ]);
  13133. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13134. this.width = width;
  13135. this.height = height;
  13136. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13137. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13138. var coefficientCount = width * height;
  13139. // coefficients outside the encoding region treated as insignificant
  13140. // add border state cells for significanceState
  13141. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13142. this.coefficentsSign = new Uint8Array(coefficientCount);
  13143. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13144. mb > 6 ? new Uint16Array(coefficientCount) :
  13145. new Uint8Array(coefficientCount);
  13146. this.processingFlags = new Uint8Array(coefficientCount);
  13147. var bitsDecoded = new Uint8Array(coefficientCount);
  13148. if (zeroBitPlanes !== 0) {
  13149. for (var i = 0; i < coefficientCount; i++) {
  13150. bitsDecoded[i] = zeroBitPlanes;
  13151. }
  13152. }
  13153. this.bitsDecoded = bitsDecoded;
  13154. this.reset();
  13155. }
  13156. BitModel.prototype = {
  13157. setDecoder: function BitModel_setDecoder(decoder) {
  13158. this.decoder = decoder;
  13159. },
  13160. reset: function BitModel_reset() {
  13161. // We have 17 contexts that are accessed via context labels,
  13162. // plus the uniform and runlength context.
  13163. this.contexts = new Int8Array(19);
  13164. // Contexts are packed into 1 byte:
  13165. // highest 7 bits carry the index, lowest bit carries mps
  13166. this.contexts[0] = (4 << 1) | 0;
  13167. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13168. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13169. },
  13170. setNeighborsSignificance:
  13171. function BitModel_setNeighborsSignificance(row, column, index) {
  13172. var neighborsSignificance = this.neighborsSignificance;
  13173. var width = this.width, height = this.height;
  13174. var left = (column > 0);
  13175. var right = (column + 1 < width);
  13176. var i;
  13177. if (row > 0) {
  13178. i = index - width;
  13179. if (left) {
  13180. neighborsSignificance[i - 1] += 0x10;
  13181. }
  13182. if (right) {
  13183. neighborsSignificance[i + 1] += 0x10;
  13184. }
  13185. neighborsSignificance[i] += 0x04;
  13186. }
  13187. if (row + 1 < height) {
  13188. i = index + width;
  13189. if (left) {
  13190. neighborsSignificance[i - 1] += 0x10;
  13191. }
  13192. if (right) {
  13193. neighborsSignificance[i + 1] += 0x10;
  13194. }
  13195. neighborsSignificance[i] += 0x04;
  13196. }
  13197. if (left) {
  13198. neighborsSignificance[index - 1] += 0x01;
  13199. }
  13200. if (right) {
  13201. neighborsSignificance[index + 1] += 0x01;
  13202. }
  13203. neighborsSignificance[index] |= 0x80;
  13204. },
  13205. runSignificancePropagationPass:
  13206. function BitModel_runSignificancePropagationPass() {
  13207. var decoder = this.decoder;
  13208. var width = this.width, height = this.height;
  13209. var coefficentsMagnitude = this.coefficentsMagnitude;
  13210. var coefficentsSign = this.coefficentsSign;
  13211. var neighborsSignificance = this.neighborsSignificance;
  13212. var processingFlags = this.processingFlags;
  13213. var contexts = this.contexts;
  13214. var labels = this.contextLabelTable;
  13215. var bitsDecoded = this.bitsDecoded;
  13216. var processedInverseMask = ~1;
  13217. var processedMask = 1;
  13218. var firstMagnitudeBitMask = 2;
  13219. for (var i0 = 0; i0 < height; i0 += 4) {
  13220. for (var j = 0; j < width; j++) {
  13221. var index = i0 * width + j;
  13222. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13223. var i = i0 + i1;
  13224. if (i >= height) {
  13225. break;
  13226. }
  13227. // clear processed flag first
  13228. processingFlags[index] &= processedInverseMask;
  13229. if (coefficentsMagnitude[index] ||
  13230. !neighborsSignificance[index]) {
  13231. continue;
  13232. }
  13233. var contextLabel = labels[neighborsSignificance[index]];
  13234. var decision = decoder.readBit(contexts, contextLabel);
  13235. if (decision) {
  13236. var sign = this.decodeSignBit(i, j, index);
  13237. coefficentsSign[index] = sign;
  13238. coefficentsMagnitude[index] = 1;
  13239. this.setNeighborsSignificance(i, j, index);
  13240. processingFlags[index] |= firstMagnitudeBitMask;
  13241. }
  13242. bitsDecoded[index]++;
  13243. processingFlags[index] |= processedMask;
  13244. }
  13245. }
  13246. }
  13247. },
  13248. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13249. var width = this.width, height = this.height;
  13250. var coefficentsMagnitude = this.coefficentsMagnitude;
  13251. var coefficentsSign = this.coefficentsSign;
  13252. var contribution, sign0, sign1, significance1;
  13253. var contextLabel, decoded;
  13254. // calculate horizontal contribution
  13255. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13256. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13257. sign1 = coefficentsSign[index + 1];
  13258. if (significance1) {
  13259. sign0 = coefficentsSign[index - 1];
  13260. contribution = 1 - sign1 - sign0;
  13261. } else {
  13262. contribution = 1 - sign1 - sign1;
  13263. }
  13264. } else if (significance1) {
  13265. sign0 = coefficentsSign[index - 1];
  13266. contribution = 1 - sign0 - sign0;
  13267. } else {
  13268. contribution = 0;
  13269. }
  13270. var horizontalContribution = 3 * contribution;
  13271. // calculate vertical contribution and combine with the horizontal
  13272. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13273. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13274. sign1 = coefficentsSign[index + width];
  13275. if (significance1) {
  13276. sign0 = coefficentsSign[index - width];
  13277. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13278. } else {
  13279. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13280. }
  13281. } else if (significance1) {
  13282. sign0 = coefficentsSign[index - width];
  13283. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13284. } else {
  13285. contribution = horizontalContribution;
  13286. }
  13287. if (contribution >= 0) {
  13288. contextLabel = 9 + contribution;
  13289. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13290. } else {
  13291. contextLabel = 9 - contribution;
  13292. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13293. }
  13294. return decoded;
  13295. },
  13296. runMagnitudeRefinementPass:
  13297. function BitModel_runMagnitudeRefinementPass() {
  13298. var decoder = this.decoder;
  13299. var width = this.width, height = this.height;
  13300. var coefficentsMagnitude = this.coefficentsMagnitude;
  13301. var neighborsSignificance = this.neighborsSignificance;
  13302. var contexts = this.contexts;
  13303. var bitsDecoded = this.bitsDecoded;
  13304. var processingFlags = this.processingFlags;
  13305. var processedMask = 1;
  13306. var firstMagnitudeBitMask = 2;
  13307. var length = width * height;
  13308. var width4 = width * 4;
  13309. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13310. indexNext = Math.min(length, index0 + width4);
  13311. for (var j = 0; j < width; j++) {
  13312. for (var index = index0 + j; index < indexNext; index += width) {
  13313. // significant but not those that have just become
  13314. if (!coefficentsMagnitude[index] ||
  13315. (processingFlags[index] & processedMask) !== 0) {
  13316. continue;
  13317. }
  13318. var contextLabel = 16;
  13319. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13320. processingFlags[index] ^= firstMagnitudeBitMask;
  13321. // first refinement
  13322. var significance = neighborsSignificance[index] & 127;
  13323. contextLabel = significance === 0 ? 15 : 14;
  13324. }
  13325. var bit = decoder.readBit(contexts, contextLabel);
  13326. coefficentsMagnitude[index] =
  13327. (coefficentsMagnitude[index] << 1) | bit;
  13328. bitsDecoded[index]++;
  13329. processingFlags[index] |= processedMask;
  13330. }
  13331. }
  13332. }
  13333. },
  13334. runCleanupPass: function BitModel_runCleanupPass() {
  13335. var decoder = this.decoder;
  13336. var width = this.width, height = this.height;
  13337. var neighborsSignificance = this.neighborsSignificance;
  13338. var coefficentsMagnitude = this.coefficentsMagnitude;
  13339. var coefficentsSign = this.coefficentsSign;
  13340. var contexts = this.contexts;
  13341. var labels = this.contextLabelTable;
  13342. var bitsDecoded = this.bitsDecoded;
  13343. var processingFlags = this.processingFlags;
  13344. var processedMask = 1;
  13345. var firstMagnitudeBitMask = 2;
  13346. var oneRowDown = width;
  13347. var twoRowsDown = width * 2;
  13348. var threeRowsDown = width * 3;
  13349. var iNext;
  13350. for (var i0 = 0; i0 < height; i0 = iNext) {
  13351. iNext = Math.min(i0 + 4, height);
  13352. var indexBase = i0 * width;
  13353. var checkAllEmpty = i0 + 3 < height;
  13354. for (var j = 0; j < width; j++) {
  13355. var index0 = indexBase + j;
  13356. // using the property: labels[neighborsSignificance[index]] === 0
  13357. // when neighborsSignificance[index] === 0
  13358. var allEmpty = (checkAllEmpty &&
  13359. processingFlags[index0] === 0 &&
  13360. processingFlags[index0 + oneRowDown] === 0 &&
  13361. processingFlags[index0 + twoRowsDown] === 0 &&
  13362. processingFlags[index0 + threeRowsDown] === 0 &&
  13363. neighborsSignificance[index0] === 0 &&
  13364. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13365. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13366. neighborsSignificance[index0 + threeRowsDown] === 0);
  13367. var i1 = 0, index = index0;
  13368. var i = i0, sign;
  13369. if (allEmpty) {
  13370. var hasSignificantCoefficent =
  13371. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13372. if (!hasSignificantCoefficent) {
  13373. bitsDecoded[index0]++;
  13374. bitsDecoded[index0 + oneRowDown]++;
  13375. bitsDecoded[index0 + twoRowsDown]++;
  13376. bitsDecoded[index0 + threeRowsDown]++;
  13377. continue; // next column
  13378. }
  13379. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13380. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13381. if (i1 !== 0) {
  13382. i = i0 + i1;
  13383. index += i1 * width;
  13384. }
  13385. sign = this.decodeSignBit(i, j, index);
  13386. coefficentsSign[index] = sign;
  13387. coefficentsMagnitude[index] = 1;
  13388. this.setNeighborsSignificance(i, j, index);
  13389. processingFlags[index] |= firstMagnitudeBitMask;
  13390. index = index0;
  13391. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13392. bitsDecoded[index]++;
  13393. }
  13394. i1++;
  13395. }
  13396. for (i = i0 + i1; i < iNext; i++, index += width) {
  13397. if (coefficentsMagnitude[index] ||
  13398. (processingFlags[index] & processedMask) !== 0) {
  13399. continue;
  13400. }
  13401. var contextLabel = labels[neighborsSignificance[index]];
  13402. var decision = decoder.readBit(contexts, contextLabel);
  13403. if (decision === 1) {
  13404. sign = this.decodeSignBit(i, j, index);
  13405. coefficentsSign[index] = sign;
  13406. coefficentsMagnitude[index] = 1;
  13407. this.setNeighborsSignificance(i, j, index);
  13408. processingFlags[index] |= firstMagnitudeBitMask;
  13409. }
  13410. bitsDecoded[index]++;
  13411. }
  13412. }
  13413. }
  13414. },
  13415. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13416. var decoder = this.decoder;
  13417. var contexts = this.contexts;
  13418. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13419. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13420. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13421. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13422. if (symbol !== 0xA) {
  13423. error('JPX Error: Invalid segmentation symbol');
  13424. }
  13425. }
  13426. };
  13427. return BitModel;
  13428. })();
  13429. // Section F, Discrete wavelet transformation
  13430. var Transform = (function TransformClosure() {
  13431. function Transform() {}
  13432. Transform.prototype.calculate =
  13433. function transformCalculate(subbands, u0, v0) {
  13434. var ll = subbands[0];
  13435. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13436. ll = this.iterate(ll, subbands[i], u0, v0);
  13437. }
  13438. return ll;
  13439. };
  13440. Transform.prototype.extend = function extend(buffer, offset, size) {
  13441. // Section F.3.7 extending... using max extension of 4
  13442. var i1 = offset - 1, j1 = offset + 1;
  13443. var i2 = offset + size - 2, j2 = offset + size;
  13444. buffer[i1--] = buffer[j1++];
  13445. buffer[j2++] = buffer[i2--];
  13446. buffer[i1--] = buffer[j1++];
  13447. buffer[j2++] = buffer[i2--];
  13448. buffer[i1--] = buffer[j1++];
  13449. buffer[j2++] = buffer[i2--];
  13450. buffer[i1] = buffer[j1];
  13451. buffer[j2] = buffer[i2];
  13452. };
  13453. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13454. u0, v0) {
  13455. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13456. var width = hl_lh_hh.width;
  13457. var height = hl_lh_hh.height;
  13458. var items = hl_lh_hh.items;
  13459. var i, j, k, l, u, v;
  13460. // Interleave LL according to Section F.3.3
  13461. for (k = 0, i = 0; i < llHeight; i++) {
  13462. l = i * 2 * width;
  13463. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13464. items[l] = llItems[k];
  13465. }
  13466. }
  13467. // The LL band is not needed anymore.
  13468. llItems = ll.items = null;
  13469. var bufferPadding = 4;
  13470. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13471. // Section F.3.4 HOR_SR
  13472. if (width === 1) {
  13473. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13474. if ((u0 & 1) !== 0) {
  13475. for (v = 0, k = 0; v < height; v++, k += width) {
  13476. items[k] *= 0.5;
  13477. }
  13478. }
  13479. } else {
  13480. for (v = 0, k = 0; v < height; v++, k += width) {
  13481. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13482. this.extend(rowBuffer, bufferPadding, width);
  13483. this.filter(rowBuffer, bufferPadding, width);
  13484. items.set(
  13485. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13486. k);
  13487. }
  13488. }
  13489. // Accesses to the items array can take long, because it may not fit into
  13490. // CPU cache and has to be fetched from main memory. Since subsequent
  13491. // accesses to the items array are not local when reading columns, we
  13492. // have a cache miss every time. To reduce cache misses, get up to
  13493. // 'numBuffers' items at a time and store them into the individual
  13494. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13495. var numBuffers = 16;
  13496. var colBuffers = [];
  13497. for (i = 0; i < numBuffers; i++) {
  13498. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13499. }
  13500. var b, currentBuffer = 0;
  13501. ll = bufferPadding + height;
  13502. // Section F.3.5 VER_SR
  13503. if (height === 1) {
  13504. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13505. if ((v0 & 1) !== 0) {
  13506. for (u = 0; u < width; u++) {
  13507. items[u] *= 0.5;
  13508. }
  13509. }
  13510. } else {
  13511. for (u = 0; u < width; u++) {
  13512. // if we ran out of buffers, copy several image columns at once
  13513. if (currentBuffer === 0) {
  13514. numBuffers = Math.min(width - u, numBuffers);
  13515. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13516. for (b = 0; b < numBuffers; b++) {
  13517. colBuffers[b][l] = items[k + b];
  13518. }
  13519. }
  13520. currentBuffer = numBuffers;
  13521. }
  13522. currentBuffer--;
  13523. var buffer = colBuffers[currentBuffer];
  13524. this.extend(buffer, bufferPadding, height);
  13525. this.filter(buffer, bufferPadding, height);
  13526. // If this is last buffer in this group of buffers, flush all buffers.
  13527. if (currentBuffer === 0) {
  13528. k = u - numBuffers + 1;
  13529. for (l = bufferPadding; l < ll; k += width, l++) {
  13530. for (b = 0; b < numBuffers; b++) {
  13531. items[k + b] = colBuffers[b][l];
  13532. }
  13533. }
  13534. }
  13535. }
  13536. }
  13537. return {
  13538. width: width,
  13539. height: height,
  13540. items: items
  13541. };
  13542. };
  13543. return Transform;
  13544. })();
  13545. // Section 3.8.2 Irreversible 9-7 filter
  13546. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13547. function IrreversibleTransform() {
  13548. Transform.call(this);
  13549. }
  13550. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13551. IrreversibleTransform.prototype.filter =
  13552. function irreversibleTransformFilter(x, offset, length) {
  13553. var len = length >> 1;
  13554. offset = offset | 0;
  13555. var j, n, current, next;
  13556. var alpha = -1.586134342059924;
  13557. var beta = -0.052980118572961;
  13558. var gamma = 0.882911075530934;
  13559. var delta = 0.443506852043971;
  13560. var K = 1.230174104914001;
  13561. var K_ = 1 / K;
  13562. // step 1 is combined with step 3
  13563. // step 2
  13564. j = offset - 3;
  13565. for (n = len + 4; n--; j += 2) {
  13566. x[j] *= K_;
  13567. }
  13568. // step 1 & 3
  13569. j = offset - 2;
  13570. current = delta * x[j -1];
  13571. for (n = len + 3; n--; j += 2) {
  13572. next = delta * x[j + 1];
  13573. x[j] = K * x[j] - current - next;
  13574. if (n--) {
  13575. j += 2;
  13576. current = delta * x[j + 1];
  13577. x[j] = K * x[j] - current - next;
  13578. } else {
  13579. break;
  13580. }
  13581. }
  13582. // step 4
  13583. j = offset - 1;
  13584. current = gamma * x[j - 1];
  13585. for (n = len + 2; n--; j += 2) {
  13586. next = gamma * x[j + 1];
  13587. x[j] -= current + next;
  13588. if (n--) {
  13589. j += 2;
  13590. current = gamma * x[j + 1];
  13591. x[j] -= current + next;
  13592. } else {
  13593. break;
  13594. }
  13595. }
  13596. // step 5
  13597. j = offset;
  13598. current = beta * x[j - 1];
  13599. for (n = len + 1; n--; j += 2) {
  13600. next = beta * x[j + 1];
  13601. x[j] -= current + next;
  13602. if (n--) {
  13603. j += 2;
  13604. current = beta * x[j + 1];
  13605. x[j] -= current + next;
  13606. } else {
  13607. break;
  13608. }
  13609. }
  13610. // step 6
  13611. if (len !== 0) {
  13612. j = offset + 1;
  13613. current = alpha * x[j - 1];
  13614. for (n = len; n--; j += 2) {
  13615. next = alpha * x[j + 1];
  13616. x[j] -= current + next;
  13617. if (n--) {
  13618. j += 2;
  13619. current = alpha * x[j + 1];
  13620. x[j] -= current + next;
  13621. } else {
  13622. break;
  13623. }
  13624. }
  13625. }
  13626. };
  13627. return IrreversibleTransform;
  13628. })();
  13629. // Section 3.8.1 Reversible 5-3 filter
  13630. var ReversibleTransform = (function ReversibleTransformClosure() {
  13631. function ReversibleTransform() {
  13632. Transform.call(this);
  13633. }
  13634. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13635. ReversibleTransform.prototype.filter =
  13636. function reversibleTransformFilter(x, offset, length) {
  13637. var len = length >> 1;
  13638. offset = offset | 0;
  13639. var j, n;
  13640. for (j = offset, n = len + 1; n--; j += 2) {
  13641. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13642. }
  13643. for (j = offset + 1, n = len; n--; j += 2) {
  13644. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13645. }
  13646. };
  13647. return ReversibleTransform;
  13648. })();
  13649. return JpxImage;
  13650. })();
  13651. exports.JpxImage = JpxImage;
  13652. }));
  13653. (function (root, factory) {
  13654. {
  13655. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13656. }
  13657. }(this, function (exports, sharedUtil) {
  13658. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13659. // The Metrics object contains glyph widths (in glyph space units).
  13660. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13661. // space unit corresponds to 1/1000th of text space unit.
  13662. var getMetrics = getLookupTableFactory(function (t) {
  13663. t['Courier'] = 600;
  13664. t['Courier-Bold'] = 600;
  13665. t['Courier-BoldOblique'] = 600;
  13666. t['Courier-Oblique'] = 600;
  13667. t['Helvetica'] = getLookupTableFactory(function (t) {
  13668. t['space'] = 278;
  13669. t['exclam'] = 278;
  13670. t['quotedbl'] = 355;
  13671. t['numbersign'] = 556;
  13672. t['dollar'] = 556;
  13673. t['percent'] = 889;
  13674. t['ampersand'] = 667;
  13675. t['quoteright'] = 222;
  13676. t['parenleft'] = 333;
  13677. t['parenright'] = 333;
  13678. t['asterisk'] = 389;
  13679. t['plus'] = 584;
  13680. t['comma'] = 278;
  13681. t['hyphen'] = 333;
  13682. t['period'] = 278;
  13683. t['slash'] = 278;
  13684. t['zero'] = 556;
  13685. t['one'] = 556;
  13686. t['two'] = 556;
  13687. t['three'] = 556;
  13688. t['four'] = 556;
  13689. t['five'] = 556;
  13690. t['six'] = 556;
  13691. t['seven'] = 556;
  13692. t['eight'] = 556;
  13693. t['nine'] = 556;
  13694. t['colon'] = 278;
  13695. t['semicolon'] = 278;
  13696. t['less'] = 584;
  13697. t['equal'] = 584;
  13698. t['greater'] = 584;
  13699. t['question'] = 556;
  13700. t['at'] = 1015;
  13701. t['A'] = 667;
  13702. t['B'] = 667;
  13703. t['C'] = 722;
  13704. t['D'] = 722;
  13705. t['E'] = 667;
  13706. t['F'] = 611;
  13707. t['G'] = 778;
  13708. t['H'] = 722;
  13709. t['I'] = 278;
  13710. t['J'] = 500;
  13711. t['K'] = 667;
  13712. t['L'] = 556;
  13713. t['M'] = 833;
  13714. t['N'] = 722;
  13715. t['O'] = 778;
  13716. t['P'] = 667;
  13717. t['Q'] = 778;
  13718. t['R'] = 722;
  13719. t['S'] = 667;
  13720. t['T'] = 611;
  13721. t['U'] = 722;
  13722. t['V'] = 667;
  13723. t['W'] = 944;
  13724. t['X'] = 667;
  13725. t['Y'] = 667;
  13726. t['Z'] = 611;
  13727. t['bracketleft'] = 278;
  13728. t['backslash'] = 278;
  13729. t['bracketright'] = 278;
  13730. t['asciicircum'] = 469;
  13731. t['underscore'] = 556;
  13732. t['quoteleft'] = 222;
  13733. t['a'] = 556;
  13734. t['b'] = 556;
  13735. t['c'] = 500;
  13736. t['d'] = 556;
  13737. t['e'] = 556;
  13738. t['f'] = 278;
  13739. t['g'] = 556;
  13740. t['h'] = 556;
  13741. t['i'] = 222;
  13742. t['j'] = 222;
  13743. t['k'] = 500;
  13744. t['l'] = 222;
  13745. t['m'] = 833;
  13746. t['n'] = 556;
  13747. t['o'] = 556;
  13748. t['p'] = 556;
  13749. t['q'] = 556;
  13750. t['r'] = 333;
  13751. t['s'] = 500;
  13752. t['t'] = 278;
  13753. t['u'] = 556;
  13754. t['v'] = 500;
  13755. t['w'] = 722;
  13756. t['x'] = 500;
  13757. t['y'] = 500;
  13758. t['z'] = 500;
  13759. t['braceleft'] = 334;
  13760. t['bar'] = 260;
  13761. t['braceright'] = 334;
  13762. t['asciitilde'] = 584;
  13763. t['exclamdown'] = 333;
  13764. t['cent'] = 556;
  13765. t['sterling'] = 556;
  13766. t['fraction'] = 167;
  13767. t['yen'] = 556;
  13768. t['florin'] = 556;
  13769. t['section'] = 556;
  13770. t['currency'] = 556;
  13771. t['quotesingle'] = 191;
  13772. t['quotedblleft'] = 333;
  13773. t['guillemotleft'] = 556;
  13774. t['guilsinglleft'] = 333;
  13775. t['guilsinglright'] = 333;
  13776. t['fi'] = 500;
  13777. t['fl'] = 500;
  13778. t['endash'] = 556;
  13779. t['dagger'] = 556;
  13780. t['daggerdbl'] = 556;
  13781. t['periodcentered'] = 278;
  13782. t['paragraph'] = 537;
  13783. t['bullet'] = 350;
  13784. t['quotesinglbase'] = 222;
  13785. t['quotedblbase'] = 333;
  13786. t['quotedblright'] = 333;
  13787. t['guillemotright'] = 556;
  13788. t['ellipsis'] = 1000;
  13789. t['perthousand'] = 1000;
  13790. t['questiondown'] = 611;
  13791. t['grave'] = 333;
  13792. t['acute'] = 333;
  13793. t['circumflex'] = 333;
  13794. t['tilde'] = 333;
  13795. t['macron'] = 333;
  13796. t['breve'] = 333;
  13797. t['dotaccent'] = 333;
  13798. t['dieresis'] = 333;
  13799. t['ring'] = 333;
  13800. t['cedilla'] = 333;
  13801. t['hungarumlaut'] = 333;
  13802. t['ogonek'] = 333;
  13803. t['caron'] = 333;
  13804. t['emdash'] = 1000;
  13805. t['AE'] = 1000;
  13806. t['ordfeminine'] = 370;
  13807. t['Lslash'] = 556;
  13808. t['Oslash'] = 778;
  13809. t['OE'] = 1000;
  13810. t['ordmasculine'] = 365;
  13811. t['ae'] = 889;
  13812. t['dotlessi'] = 278;
  13813. t['lslash'] = 222;
  13814. t['oslash'] = 611;
  13815. t['oe'] = 944;
  13816. t['germandbls'] = 611;
  13817. t['Idieresis'] = 278;
  13818. t['eacute'] = 556;
  13819. t['abreve'] = 556;
  13820. t['uhungarumlaut'] = 556;
  13821. t['ecaron'] = 556;
  13822. t['Ydieresis'] = 667;
  13823. t['divide'] = 584;
  13824. t['Yacute'] = 667;
  13825. t['Acircumflex'] = 667;
  13826. t['aacute'] = 556;
  13827. t['Ucircumflex'] = 722;
  13828. t['yacute'] = 500;
  13829. t['scommaaccent'] = 500;
  13830. t['ecircumflex'] = 556;
  13831. t['Uring'] = 722;
  13832. t['Udieresis'] = 722;
  13833. t['aogonek'] = 556;
  13834. t['Uacute'] = 722;
  13835. t['uogonek'] = 556;
  13836. t['Edieresis'] = 667;
  13837. t['Dcroat'] = 722;
  13838. t['commaaccent'] = 250;
  13839. t['copyright'] = 737;
  13840. t['Emacron'] = 667;
  13841. t['ccaron'] = 500;
  13842. t['aring'] = 556;
  13843. t['Ncommaaccent'] = 722;
  13844. t['lacute'] = 222;
  13845. t['agrave'] = 556;
  13846. t['Tcommaaccent'] = 611;
  13847. t['Cacute'] = 722;
  13848. t['atilde'] = 556;
  13849. t['Edotaccent'] = 667;
  13850. t['scaron'] = 500;
  13851. t['scedilla'] = 500;
  13852. t['iacute'] = 278;
  13853. t['lozenge'] = 471;
  13854. t['Rcaron'] = 722;
  13855. t['Gcommaaccent'] = 778;
  13856. t['ucircumflex'] = 556;
  13857. t['acircumflex'] = 556;
  13858. t['Amacron'] = 667;
  13859. t['rcaron'] = 333;
  13860. t['ccedilla'] = 500;
  13861. t['Zdotaccent'] = 611;
  13862. t['Thorn'] = 667;
  13863. t['Omacron'] = 778;
  13864. t['Racute'] = 722;
  13865. t['Sacute'] = 667;
  13866. t['dcaron'] = 643;
  13867. t['Umacron'] = 722;
  13868. t['uring'] = 556;
  13869. t['threesuperior'] = 333;
  13870. t['Ograve'] = 778;
  13871. t['Agrave'] = 667;
  13872. t['Abreve'] = 667;
  13873. t['multiply'] = 584;
  13874. t['uacute'] = 556;
  13875. t['Tcaron'] = 611;
  13876. t['partialdiff'] = 476;
  13877. t['ydieresis'] = 500;
  13878. t['Nacute'] = 722;
  13879. t['icircumflex'] = 278;
  13880. t['Ecircumflex'] = 667;
  13881. t['adieresis'] = 556;
  13882. t['edieresis'] = 556;
  13883. t['cacute'] = 500;
  13884. t['nacute'] = 556;
  13885. t['umacron'] = 556;
  13886. t['Ncaron'] = 722;
  13887. t['Iacute'] = 278;
  13888. t['plusminus'] = 584;
  13889. t['brokenbar'] = 260;
  13890. t['registered'] = 737;
  13891. t['Gbreve'] = 778;
  13892. t['Idotaccent'] = 278;
  13893. t['summation'] = 600;
  13894. t['Egrave'] = 667;
  13895. t['racute'] = 333;
  13896. t['omacron'] = 556;
  13897. t['Zacute'] = 611;
  13898. t['Zcaron'] = 611;
  13899. t['greaterequal'] = 549;
  13900. t['Eth'] = 722;
  13901. t['Ccedilla'] = 722;
  13902. t['lcommaaccent'] = 222;
  13903. t['tcaron'] = 317;
  13904. t['eogonek'] = 556;
  13905. t['Uogonek'] = 722;
  13906. t['Aacute'] = 667;
  13907. t['Adieresis'] = 667;
  13908. t['egrave'] = 556;
  13909. t['zacute'] = 500;
  13910. t['iogonek'] = 222;
  13911. t['Oacute'] = 778;
  13912. t['oacute'] = 556;
  13913. t['amacron'] = 556;
  13914. t['sacute'] = 500;
  13915. t['idieresis'] = 278;
  13916. t['Ocircumflex'] = 778;
  13917. t['Ugrave'] = 722;
  13918. t['Delta'] = 612;
  13919. t['thorn'] = 556;
  13920. t['twosuperior'] = 333;
  13921. t['Odieresis'] = 778;
  13922. t['mu'] = 556;
  13923. t['igrave'] = 278;
  13924. t['ohungarumlaut'] = 556;
  13925. t['Eogonek'] = 667;
  13926. t['dcroat'] = 556;
  13927. t['threequarters'] = 834;
  13928. t['Scedilla'] = 667;
  13929. t['lcaron'] = 299;
  13930. t['Kcommaaccent'] = 667;
  13931. t['Lacute'] = 556;
  13932. t['trademark'] = 1000;
  13933. t['edotaccent'] = 556;
  13934. t['Igrave'] = 278;
  13935. t['Imacron'] = 278;
  13936. t['Lcaron'] = 556;
  13937. t['onehalf'] = 834;
  13938. t['lessequal'] = 549;
  13939. t['ocircumflex'] = 556;
  13940. t['ntilde'] = 556;
  13941. t['Uhungarumlaut'] = 722;
  13942. t['Eacute'] = 667;
  13943. t['emacron'] = 556;
  13944. t['gbreve'] = 556;
  13945. t['onequarter'] = 834;
  13946. t['Scaron'] = 667;
  13947. t['Scommaaccent'] = 667;
  13948. t['Ohungarumlaut'] = 778;
  13949. t['degree'] = 400;
  13950. t['ograve'] = 556;
  13951. t['Ccaron'] = 722;
  13952. t['ugrave'] = 556;
  13953. t['radical'] = 453;
  13954. t['Dcaron'] = 722;
  13955. t['rcommaaccent'] = 333;
  13956. t['Ntilde'] = 722;
  13957. t['otilde'] = 556;
  13958. t['Rcommaaccent'] = 722;
  13959. t['Lcommaaccent'] = 556;
  13960. t['Atilde'] = 667;
  13961. t['Aogonek'] = 667;
  13962. t['Aring'] = 667;
  13963. t['Otilde'] = 778;
  13964. t['zdotaccent'] = 500;
  13965. t['Ecaron'] = 667;
  13966. t['Iogonek'] = 278;
  13967. t['kcommaaccent'] = 500;
  13968. t['minus'] = 584;
  13969. t['Icircumflex'] = 278;
  13970. t['ncaron'] = 556;
  13971. t['tcommaaccent'] = 278;
  13972. t['logicalnot'] = 584;
  13973. t['odieresis'] = 556;
  13974. t['udieresis'] = 556;
  13975. t['notequal'] = 549;
  13976. t['gcommaaccent'] = 556;
  13977. t['eth'] = 556;
  13978. t['zcaron'] = 500;
  13979. t['ncommaaccent'] = 556;
  13980. t['onesuperior'] = 333;
  13981. t['imacron'] = 278;
  13982. t['Euro'] = 556;
  13983. });
  13984. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  13985. t['space'] = 278;
  13986. t['exclam'] = 333;
  13987. t['quotedbl'] = 474;
  13988. t['numbersign'] = 556;
  13989. t['dollar'] = 556;
  13990. t['percent'] = 889;
  13991. t['ampersand'] = 722;
  13992. t['quoteright'] = 278;
  13993. t['parenleft'] = 333;
  13994. t['parenright'] = 333;
  13995. t['asterisk'] = 389;
  13996. t['plus'] = 584;
  13997. t['comma'] = 278;
  13998. t['hyphen'] = 333;
  13999. t['period'] = 278;
  14000. t['slash'] = 278;
  14001. t['zero'] = 556;
  14002. t['one'] = 556;
  14003. t['two'] = 556;
  14004. t['three'] = 556;
  14005. t['four'] = 556;
  14006. t['five'] = 556;
  14007. t['six'] = 556;
  14008. t['seven'] = 556;
  14009. t['eight'] = 556;
  14010. t['nine'] = 556;
  14011. t['colon'] = 333;
  14012. t['semicolon'] = 333;
  14013. t['less'] = 584;
  14014. t['equal'] = 584;
  14015. t['greater'] = 584;
  14016. t['question'] = 611;
  14017. t['at'] = 975;
  14018. t['A'] = 722;
  14019. t['B'] = 722;
  14020. t['C'] = 722;
  14021. t['D'] = 722;
  14022. t['E'] = 667;
  14023. t['F'] = 611;
  14024. t['G'] = 778;
  14025. t['H'] = 722;
  14026. t['I'] = 278;
  14027. t['J'] = 556;
  14028. t['K'] = 722;
  14029. t['L'] = 611;
  14030. t['M'] = 833;
  14031. t['N'] = 722;
  14032. t['O'] = 778;
  14033. t['P'] = 667;
  14034. t['Q'] = 778;
  14035. t['R'] = 722;
  14036. t['S'] = 667;
  14037. t['T'] = 611;
  14038. t['U'] = 722;
  14039. t['V'] = 667;
  14040. t['W'] = 944;
  14041. t['X'] = 667;
  14042. t['Y'] = 667;
  14043. t['Z'] = 611;
  14044. t['bracketleft'] = 333;
  14045. t['backslash'] = 278;
  14046. t['bracketright'] = 333;
  14047. t['asciicircum'] = 584;
  14048. t['underscore'] = 556;
  14049. t['quoteleft'] = 278;
  14050. t['a'] = 556;
  14051. t['b'] = 611;
  14052. t['c'] = 556;
  14053. t['d'] = 611;
  14054. t['e'] = 556;
  14055. t['f'] = 333;
  14056. t['g'] = 611;
  14057. t['h'] = 611;
  14058. t['i'] = 278;
  14059. t['j'] = 278;
  14060. t['k'] = 556;
  14061. t['l'] = 278;
  14062. t['m'] = 889;
  14063. t['n'] = 611;
  14064. t['o'] = 611;
  14065. t['p'] = 611;
  14066. t['q'] = 611;
  14067. t['r'] = 389;
  14068. t['s'] = 556;
  14069. t['t'] = 333;
  14070. t['u'] = 611;
  14071. t['v'] = 556;
  14072. t['w'] = 778;
  14073. t['x'] = 556;
  14074. t['y'] = 556;
  14075. t['z'] = 500;
  14076. t['braceleft'] = 389;
  14077. t['bar'] = 280;
  14078. t['braceright'] = 389;
  14079. t['asciitilde'] = 584;
  14080. t['exclamdown'] = 333;
  14081. t['cent'] = 556;
  14082. t['sterling'] = 556;
  14083. t['fraction'] = 167;
  14084. t['yen'] = 556;
  14085. t['florin'] = 556;
  14086. t['section'] = 556;
  14087. t['currency'] = 556;
  14088. t['quotesingle'] = 238;
  14089. t['quotedblleft'] = 500;
  14090. t['guillemotleft'] = 556;
  14091. t['guilsinglleft'] = 333;
  14092. t['guilsinglright'] = 333;
  14093. t['fi'] = 611;
  14094. t['fl'] = 611;
  14095. t['endash'] = 556;
  14096. t['dagger'] = 556;
  14097. t['daggerdbl'] = 556;
  14098. t['periodcentered'] = 278;
  14099. t['paragraph'] = 556;
  14100. t['bullet'] = 350;
  14101. t['quotesinglbase'] = 278;
  14102. t['quotedblbase'] = 500;
  14103. t['quotedblright'] = 500;
  14104. t['guillemotright'] = 556;
  14105. t['ellipsis'] = 1000;
  14106. t['perthousand'] = 1000;
  14107. t['questiondown'] = 611;
  14108. t['grave'] = 333;
  14109. t['acute'] = 333;
  14110. t['circumflex'] = 333;
  14111. t['tilde'] = 333;
  14112. t['macron'] = 333;
  14113. t['breve'] = 333;
  14114. t['dotaccent'] = 333;
  14115. t['dieresis'] = 333;
  14116. t['ring'] = 333;
  14117. t['cedilla'] = 333;
  14118. t['hungarumlaut'] = 333;
  14119. t['ogonek'] = 333;
  14120. t['caron'] = 333;
  14121. t['emdash'] = 1000;
  14122. t['AE'] = 1000;
  14123. t['ordfeminine'] = 370;
  14124. t['Lslash'] = 611;
  14125. t['Oslash'] = 778;
  14126. t['OE'] = 1000;
  14127. t['ordmasculine'] = 365;
  14128. t['ae'] = 889;
  14129. t['dotlessi'] = 278;
  14130. t['lslash'] = 278;
  14131. t['oslash'] = 611;
  14132. t['oe'] = 944;
  14133. t['germandbls'] = 611;
  14134. t['Idieresis'] = 278;
  14135. t['eacute'] = 556;
  14136. t['abreve'] = 556;
  14137. t['uhungarumlaut'] = 611;
  14138. t['ecaron'] = 556;
  14139. t['Ydieresis'] = 667;
  14140. t['divide'] = 584;
  14141. t['Yacute'] = 667;
  14142. t['Acircumflex'] = 722;
  14143. t['aacute'] = 556;
  14144. t['Ucircumflex'] = 722;
  14145. t['yacute'] = 556;
  14146. t['scommaaccent'] = 556;
  14147. t['ecircumflex'] = 556;
  14148. t['Uring'] = 722;
  14149. t['Udieresis'] = 722;
  14150. t['aogonek'] = 556;
  14151. t['Uacute'] = 722;
  14152. t['uogonek'] = 611;
  14153. t['Edieresis'] = 667;
  14154. t['Dcroat'] = 722;
  14155. t['commaaccent'] = 250;
  14156. t['copyright'] = 737;
  14157. t['Emacron'] = 667;
  14158. t['ccaron'] = 556;
  14159. t['aring'] = 556;
  14160. t['Ncommaaccent'] = 722;
  14161. t['lacute'] = 278;
  14162. t['agrave'] = 556;
  14163. t['Tcommaaccent'] = 611;
  14164. t['Cacute'] = 722;
  14165. t['atilde'] = 556;
  14166. t['Edotaccent'] = 667;
  14167. t['scaron'] = 556;
  14168. t['scedilla'] = 556;
  14169. t['iacute'] = 278;
  14170. t['lozenge'] = 494;
  14171. t['Rcaron'] = 722;
  14172. t['Gcommaaccent'] = 778;
  14173. t['ucircumflex'] = 611;
  14174. t['acircumflex'] = 556;
  14175. t['Amacron'] = 722;
  14176. t['rcaron'] = 389;
  14177. t['ccedilla'] = 556;
  14178. t['Zdotaccent'] = 611;
  14179. t['Thorn'] = 667;
  14180. t['Omacron'] = 778;
  14181. t['Racute'] = 722;
  14182. t['Sacute'] = 667;
  14183. t['dcaron'] = 743;
  14184. t['Umacron'] = 722;
  14185. t['uring'] = 611;
  14186. t['threesuperior'] = 333;
  14187. t['Ograve'] = 778;
  14188. t['Agrave'] = 722;
  14189. t['Abreve'] = 722;
  14190. t['multiply'] = 584;
  14191. t['uacute'] = 611;
  14192. t['Tcaron'] = 611;
  14193. t['partialdiff'] = 494;
  14194. t['ydieresis'] = 556;
  14195. t['Nacute'] = 722;
  14196. t['icircumflex'] = 278;
  14197. t['Ecircumflex'] = 667;
  14198. t['adieresis'] = 556;
  14199. t['edieresis'] = 556;
  14200. t['cacute'] = 556;
  14201. t['nacute'] = 611;
  14202. t['umacron'] = 611;
  14203. t['Ncaron'] = 722;
  14204. t['Iacute'] = 278;
  14205. t['plusminus'] = 584;
  14206. t['brokenbar'] = 280;
  14207. t['registered'] = 737;
  14208. t['Gbreve'] = 778;
  14209. t['Idotaccent'] = 278;
  14210. t['summation'] = 600;
  14211. t['Egrave'] = 667;
  14212. t['racute'] = 389;
  14213. t['omacron'] = 611;
  14214. t['Zacute'] = 611;
  14215. t['Zcaron'] = 611;
  14216. t['greaterequal'] = 549;
  14217. t['Eth'] = 722;
  14218. t['Ccedilla'] = 722;
  14219. t['lcommaaccent'] = 278;
  14220. t['tcaron'] = 389;
  14221. t['eogonek'] = 556;
  14222. t['Uogonek'] = 722;
  14223. t['Aacute'] = 722;
  14224. t['Adieresis'] = 722;
  14225. t['egrave'] = 556;
  14226. t['zacute'] = 500;
  14227. t['iogonek'] = 278;
  14228. t['Oacute'] = 778;
  14229. t['oacute'] = 611;
  14230. t['amacron'] = 556;
  14231. t['sacute'] = 556;
  14232. t['idieresis'] = 278;
  14233. t['Ocircumflex'] = 778;
  14234. t['Ugrave'] = 722;
  14235. t['Delta'] = 612;
  14236. t['thorn'] = 611;
  14237. t['twosuperior'] = 333;
  14238. t['Odieresis'] = 778;
  14239. t['mu'] = 611;
  14240. t['igrave'] = 278;
  14241. t['ohungarumlaut'] = 611;
  14242. t['Eogonek'] = 667;
  14243. t['dcroat'] = 611;
  14244. t['threequarters'] = 834;
  14245. t['Scedilla'] = 667;
  14246. t['lcaron'] = 400;
  14247. t['Kcommaaccent'] = 722;
  14248. t['Lacute'] = 611;
  14249. t['trademark'] = 1000;
  14250. t['edotaccent'] = 556;
  14251. t['Igrave'] = 278;
  14252. t['Imacron'] = 278;
  14253. t['Lcaron'] = 611;
  14254. t['onehalf'] = 834;
  14255. t['lessequal'] = 549;
  14256. t['ocircumflex'] = 611;
  14257. t['ntilde'] = 611;
  14258. t['Uhungarumlaut'] = 722;
  14259. t['Eacute'] = 667;
  14260. t['emacron'] = 556;
  14261. t['gbreve'] = 611;
  14262. t['onequarter'] = 834;
  14263. t['Scaron'] = 667;
  14264. t['Scommaaccent'] = 667;
  14265. t['Ohungarumlaut'] = 778;
  14266. t['degree'] = 400;
  14267. t['ograve'] = 611;
  14268. t['Ccaron'] = 722;
  14269. t['ugrave'] = 611;
  14270. t['radical'] = 549;
  14271. t['Dcaron'] = 722;
  14272. t['rcommaaccent'] = 389;
  14273. t['Ntilde'] = 722;
  14274. t['otilde'] = 611;
  14275. t['Rcommaaccent'] = 722;
  14276. t['Lcommaaccent'] = 611;
  14277. t['Atilde'] = 722;
  14278. t['Aogonek'] = 722;
  14279. t['Aring'] = 722;
  14280. t['Otilde'] = 778;
  14281. t['zdotaccent'] = 500;
  14282. t['Ecaron'] = 667;
  14283. t['Iogonek'] = 278;
  14284. t['kcommaaccent'] = 556;
  14285. t['minus'] = 584;
  14286. t['Icircumflex'] = 278;
  14287. t['ncaron'] = 611;
  14288. t['tcommaaccent'] = 333;
  14289. t['logicalnot'] = 584;
  14290. t['odieresis'] = 611;
  14291. t['udieresis'] = 611;
  14292. t['notequal'] = 549;
  14293. t['gcommaaccent'] = 611;
  14294. t['eth'] = 611;
  14295. t['zcaron'] = 500;
  14296. t['ncommaaccent'] = 611;
  14297. t['onesuperior'] = 333;
  14298. t['imacron'] = 278;
  14299. t['Euro'] = 556;
  14300. });
  14301. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14302. t['space'] = 278;
  14303. t['exclam'] = 333;
  14304. t['quotedbl'] = 474;
  14305. t['numbersign'] = 556;
  14306. t['dollar'] = 556;
  14307. t['percent'] = 889;
  14308. t['ampersand'] = 722;
  14309. t['quoteright'] = 278;
  14310. t['parenleft'] = 333;
  14311. t['parenright'] = 333;
  14312. t['asterisk'] = 389;
  14313. t['plus'] = 584;
  14314. t['comma'] = 278;
  14315. t['hyphen'] = 333;
  14316. t['period'] = 278;
  14317. t['slash'] = 278;
  14318. t['zero'] = 556;
  14319. t['one'] = 556;
  14320. t['two'] = 556;
  14321. t['three'] = 556;
  14322. t['four'] = 556;
  14323. t['five'] = 556;
  14324. t['six'] = 556;
  14325. t['seven'] = 556;
  14326. t['eight'] = 556;
  14327. t['nine'] = 556;
  14328. t['colon'] = 333;
  14329. t['semicolon'] = 333;
  14330. t['less'] = 584;
  14331. t['equal'] = 584;
  14332. t['greater'] = 584;
  14333. t['question'] = 611;
  14334. t['at'] = 975;
  14335. t['A'] = 722;
  14336. t['B'] = 722;
  14337. t['C'] = 722;
  14338. t['D'] = 722;
  14339. t['E'] = 667;
  14340. t['F'] = 611;
  14341. t['G'] = 778;
  14342. t['H'] = 722;
  14343. t['I'] = 278;
  14344. t['J'] = 556;
  14345. t['K'] = 722;
  14346. t['L'] = 611;
  14347. t['M'] = 833;
  14348. t['N'] = 722;
  14349. t['O'] = 778;
  14350. t['P'] = 667;
  14351. t['Q'] = 778;
  14352. t['R'] = 722;
  14353. t['S'] = 667;
  14354. t['T'] = 611;
  14355. t['U'] = 722;
  14356. t['V'] = 667;
  14357. t['W'] = 944;
  14358. t['X'] = 667;
  14359. t['Y'] = 667;
  14360. t['Z'] = 611;
  14361. t['bracketleft'] = 333;
  14362. t['backslash'] = 278;
  14363. t['bracketright'] = 333;
  14364. t['asciicircum'] = 584;
  14365. t['underscore'] = 556;
  14366. t['quoteleft'] = 278;
  14367. t['a'] = 556;
  14368. t['b'] = 611;
  14369. t['c'] = 556;
  14370. t['d'] = 611;
  14371. t['e'] = 556;
  14372. t['f'] = 333;
  14373. t['g'] = 611;
  14374. t['h'] = 611;
  14375. t['i'] = 278;
  14376. t['j'] = 278;
  14377. t['k'] = 556;
  14378. t['l'] = 278;
  14379. t['m'] = 889;
  14380. t['n'] = 611;
  14381. t['o'] = 611;
  14382. t['p'] = 611;
  14383. t['q'] = 611;
  14384. t['r'] = 389;
  14385. t['s'] = 556;
  14386. t['t'] = 333;
  14387. t['u'] = 611;
  14388. t['v'] = 556;
  14389. t['w'] = 778;
  14390. t['x'] = 556;
  14391. t['y'] = 556;
  14392. t['z'] = 500;
  14393. t['braceleft'] = 389;
  14394. t['bar'] = 280;
  14395. t['braceright'] = 389;
  14396. t['asciitilde'] = 584;
  14397. t['exclamdown'] = 333;
  14398. t['cent'] = 556;
  14399. t['sterling'] = 556;
  14400. t['fraction'] = 167;
  14401. t['yen'] = 556;
  14402. t['florin'] = 556;
  14403. t['section'] = 556;
  14404. t['currency'] = 556;
  14405. t['quotesingle'] = 238;
  14406. t['quotedblleft'] = 500;
  14407. t['guillemotleft'] = 556;
  14408. t['guilsinglleft'] = 333;
  14409. t['guilsinglright'] = 333;
  14410. t['fi'] = 611;
  14411. t['fl'] = 611;
  14412. t['endash'] = 556;
  14413. t['dagger'] = 556;
  14414. t['daggerdbl'] = 556;
  14415. t['periodcentered'] = 278;
  14416. t['paragraph'] = 556;
  14417. t['bullet'] = 350;
  14418. t['quotesinglbase'] = 278;
  14419. t['quotedblbase'] = 500;
  14420. t['quotedblright'] = 500;
  14421. t['guillemotright'] = 556;
  14422. t['ellipsis'] = 1000;
  14423. t['perthousand'] = 1000;
  14424. t['questiondown'] = 611;
  14425. t['grave'] = 333;
  14426. t['acute'] = 333;
  14427. t['circumflex'] = 333;
  14428. t['tilde'] = 333;
  14429. t['macron'] = 333;
  14430. t['breve'] = 333;
  14431. t['dotaccent'] = 333;
  14432. t['dieresis'] = 333;
  14433. t['ring'] = 333;
  14434. t['cedilla'] = 333;
  14435. t['hungarumlaut'] = 333;
  14436. t['ogonek'] = 333;
  14437. t['caron'] = 333;
  14438. t['emdash'] = 1000;
  14439. t['AE'] = 1000;
  14440. t['ordfeminine'] = 370;
  14441. t['Lslash'] = 611;
  14442. t['Oslash'] = 778;
  14443. t['OE'] = 1000;
  14444. t['ordmasculine'] = 365;
  14445. t['ae'] = 889;
  14446. t['dotlessi'] = 278;
  14447. t['lslash'] = 278;
  14448. t['oslash'] = 611;
  14449. t['oe'] = 944;
  14450. t['germandbls'] = 611;
  14451. t['Idieresis'] = 278;
  14452. t['eacute'] = 556;
  14453. t['abreve'] = 556;
  14454. t['uhungarumlaut'] = 611;
  14455. t['ecaron'] = 556;
  14456. t['Ydieresis'] = 667;
  14457. t['divide'] = 584;
  14458. t['Yacute'] = 667;
  14459. t['Acircumflex'] = 722;
  14460. t['aacute'] = 556;
  14461. t['Ucircumflex'] = 722;
  14462. t['yacute'] = 556;
  14463. t['scommaaccent'] = 556;
  14464. t['ecircumflex'] = 556;
  14465. t['Uring'] = 722;
  14466. t['Udieresis'] = 722;
  14467. t['aogonek'] = 556;
  14468. t['Uacute'] = 722;
  14469. t['uogonek'] = 611;
  14470. t['Edieresis'] = 667;
  14471. t['Dcroat'] = 722;
  14472. t['commaaccent'] = 250;
  14473. t['copyright'] = 737;
  14474. t['Emacron'] = 667;
  14475. t['ccaron'] = 556;
  14476. t['aring'] = 556;
  14477. t['Ncommaaccent'] = 722;
  14478. t['lacute'] = 278;
  14479. t['agrave'] = 556;
  14480. t['Tcommaaccent'] = 611;
  14481. t['Cacute'] = 722;
  14482. t['atilde'] = 556;
  14483. t['Edotaccent'] = 667;
  14484. t['scaron'] = 556;
  14485. t['scedilla'] = 556;
  14486. t['iacute'] = 278;
  14487. t['lozenge'] = 494;
  14488. t['Rcaron'] = 722;
  14489. t['Gcommaaccent'] = 778;
  14490. t['ucircumflex'] = 611;
  14491. t['acircumflex'] = 556;
  14492. t['Amacron'] = 722;
  14493. t['rcaron'] = 389;
  14494. t['ccedilla'] = 556;
  14495. t['Zdotaccent'] = 611;
  14496. t['Thorn'] = 667;
  14497. t['Omacron'] = 778;
  14498. t['Racute'] = 722;
  14499. t['Sacute'] = 667;
  14500. t['dcaron'] = 743;
  14501. t['Umacron'] = 722;
  14502. t['uring'] = 611;
  14503. t['threesuperior'] = 333;
  14504. t['Ograve'] = 778;
  14505. t['Agrave'] = 722;
  14506. t['Abreve'] = 722;
  14507. t['multiply'] = 584;
  14508. t['uacute'] = 611;
  14509. t['Tcaron'] = 611;
  14510. t['partialdiff'] = 494;
  14511. t['ydieresis'] = 556;
  14512. t['Nacute'] = 722;
  14513. t['icircumflex'] = 278;
  14514. t['Ecircumflex'] = 667;
  14515. t['adieresis'] = 556;
  14516. t['edieresis'] = 556;
  14517. t['cacute'] = 556;
  14518. t['nacute'] = 611;
  14519. t['umacron'] = 611;
  14520. t['Ncaron'] = 722;
  14521. t['Iacute'] = 278;
  14522. t['plusminus'] = 584;
  14523. t['brokenbar'] = 280;
  14524. t['registered'] = 737;
  14525. t['Gbreve'] = 778;
  14526. t['Idotaccent'] = 278;
  14527. t['summation'] = 600;
  14528. t['Egrave'] = 667;
  14529. t['racute'] = 389;
  14530. t['omacron'] = 611;
  14531. t['Zacute'] = 611;
  14532. t['Zcaron'] = 611;
  14533. t['greaterequal'] = 549;
  14534. t['Eth'] = 722;
  14535. t['Ccedilla'] = 722;
  14536. t['lcommaaccent'] = 278;
  14537. t['tcaron'] = 389;
  14538. t['eogonek'] = 556;
  14539. t['Uogonek'] = 722;
  14540. t['Aacute'] = 722;
  14541. t['Adieresis'] = 722;
  14542. t['egrave'] = 556;
  14543. t['zacute'] = 500;
  14544. t['iogonek'] = 278;
  14545. t['Oacute'] = 778;
  14546. t['oacute'] = 611;
  14547. t['amacron'] = 556;
  14548. t['sacute'] = 556;
  14549. t['idieresis'] = 278;
  14550. t['Ocircumflex'] = 778;
  14551. t['Ugrave'] = 722;
  14552. t['Delta'] = 612;
  14553. t['thorn'] = 611;
  14554. t['twosuperior'] = 333;
  14555. t['Odieresis'] = 778;
  14556. t['mu'] = 611;
  14557. t['igrave'] = 278;
  14558. t['ohungarumlaut'] = 611;
  14559. t['Eogonek'] = 667;
  14560. t['dcroat'] = 611;
  14561. t['threequarters'] = 834;
  14562. t['Scedilla'] = 667;
  14563. t['lcaron'] = 400;
  14564. t['Kcommaaccent'] = 722;
  14565. t['Lacute'] = 611;
  14566. t['trademark'] = 1000;
  14567. t['edotaccent'] = 556;
  14568. t['Igrave'] = 278;
  14569. t['Imacron'] = 278;
  14570. t['Lcaron'] = 611;
  14571. t['onehalf'] = 834;
  14572. t['lessequal'] = 549;
  14573. t['ocircumflex'] = 611;
  14574. t['ntilde'] = 611;
  14575. t['Uhungarumlaut'] = 722;
  14576. t['Eacute'] = 667;
  14577. t['emacron'] = 556;
  14578. t['gbreve'] = 611;
  14579. t['onequarter'] = 834;
  14580. t['Scaron'] = 667;
  14581. t['Scommaaccent'] = 667;
  14582. t['Ohungarumlaut'] = 778;
  14583. t['degree'] = 400;
  14584. t['ograve'] = 611;
  14585. t['Ccaron'] = 722;
  14586. t['ugrave'] = 611;
  14587. t['radical'] = 549;
  14588. t['Dcaron'] = 722;
  14589. t['rcommaaccent'] = 389;
  14590. t['Ntilde'] = 722;
  14591. t['otilde'] = 611;
  14592. t['Rcommaaccent'] = 722;
  14593. t['Lcommaaccent'] = 611;
  14594. t['Atilde'] = 722;
  14595. t['Aogonek'] = 722;
  14596. t['Aring'] = 722;
  14597. t['Otilde'] = 778;
  14598. t['zdotaccent'] = 500;
  14599. t['Ecaron'] = 667;
  14600. t['Iogonek'] = 278;
  14601. t['kcommaaccent'] = 556;
  14602. t['minus'] = 584;
  14603. t['Icircumflex'] = 278;
  14604. t['ncaron'] = 611;
  14605. t['tcommaaccent'] = 333;
  14606. t['logicalnot'] = 584;
  14607. t['odieresis'] = 611;
  14608. t['udieresis'] = 611;
  14609. t['notequal'] = 549;
  14610. t['gcommaaccent'] = 611;
  14611. t['eth'] = 611;
  14612. t['zcaron'] = 500;
  14613. t['ncommaaccent'] = 611;
  14614. t['onesuperior'] = 333;
  14615. t['imacron'] = 278;
  14616. t['Euro'] = 556;
  14617. });
  14618. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14619. t['space'] = 278;
  14620. t['exclam'] = 278;
  14621. t['quotedbl'] = 355;
  14622. t['numbersign'] = 556;
  14623. t['dollar'] = 556;
  14624. t['percent'] = 889;
  14625. t['ampersand'] = 667;
  14626. t['quoteright'] = 222;
  14627. t['parenleft'] = 333;
  14628. t['parenright'] = 333;
  14629. t['asterisk'] = 389;
  14630. t['plus'] = 584;
  14631. t['comma'] = 278;
  14632. t['hyphen'] = 333;
  14633. t['period'] = 278;
  14634. t['slash'] = 278;
  14635. t['zero'] = 556;
  14636. t['one'] = 556;
  14637. t['two'] = 556;
  14638. t['three'] = 556;
  14639. t['four'] = 556;
  14640. t['five'] = 556;
  14641. t['six'] = 556;
  14642. t['seven'] = 556;
  14643. t['eight'] = 556;
  14644. t['nine'] = 556;
  14645. t['colon'] = 278;
  14646. t['semicolon'] = 278;
  14647. t['less'] = 584;
  14648. t['equal'] = 584;
  14649. t['greater'] = 584;
  14650. t['question'] = 556;
  14651. t['at'] = 1015;
  14652. t['A'] = 667;
  14653. t['B'] = 667;
  14654. t['C'] = 722;
  14655. t['D'] = 722;
  14656. t['E'] = 667;
  14657. t['F'] = 611;
  14658. t['G'] = 778;
  14659. t['H'] = 722;
  14660. t['I'] = 278;
  14661. t['J'] = 500;
  14662. t['K'] = 667;
  14663. t['L'] = 556;
  14664. t['M'] = 833;
  14665. t['N'] = 722;
  14666. t['O'] = 778;
  14667. t['P'] = 667;
  14668. t['Q'] = 778;
  14669. t['R'] = 722;
  14670. t['S'] = 667;
  14671. t['T'] = 611;
  14672. t['U'] = 722;
  14673. t['V'] = 667;
  14674. t['W'] = 944;
  14675. t['X'] = 667;
  14676. t['Y'] = 667;
  14677. t['Z'] = 611;
  14678. t['bracketleft'] = 278;
  14679. t['backslash'] = 278;
  14680. t['bracketright'] = 278;
  14681. t['asciicircum'] = 469;
  14682. t['underscore'] = 556;
  14683. t['quoteleft'] = 222;
  14684. t['a'] = 556;
  14685. t['b'] = 556;
  14686. t['c'] = 500;
  14687. t['d'] = 556;
  14688. t['e'] = 556;
  14689. t['f'] = 278;
  14690. t['g'] = 556;
  14691. t['h'] = 556;
  14692. t['i'] = 222;
  14693. t['j'] = 222;
  14694. t['k'] = 500;
  14695. t['l'] = 222;
  14696. t['m'] = 833;
  14697. t['n'] = 556;
  14698. t['o'] = 556;
  14699. t['p'] = 556;
  14700. t['q'] = 556;
  14701. t['r'] = 333;
  14702. t['s'] = 500;
  14703. t['t'] = 278;
  14704. t['u'] = 556;
  14705. t['v'] = 500;
  14706. t['w'] = 722;
  14707. t['x'] = 500;
  14708. t['y'] = 500;
  14709. t['z'] = 500;
  14710. t['braceleft'] = 334;
  14711. t['bar'] = 260;
  14712. t['braceright'] = 334;
  14713. t['asciitilde'] = 584;
  14714. t['exclamdown'] = 333;
  14715. t['cent'] = 556;
  14716. t['sterling'] = 556;
  14717. t['fraction'] = 167;
  14718. t['yen'] = 556;
  14719. t['florin'] = 556;
  14720. t['section'] = 556;
  14721. t['currency'] = 556;
  14722. t['quotesingle'] = 191;
  14723. t['quotedblleft'] = 333;
  14724. t['guillemotleft'] = 556;
  14725. t['guilsinglleft'] = 333;
  14726. t['guilsinglright'] = 333;
  14727. t['fi'] = 500;
  14728. t['fl'] = 500;
  14729. t['endash'] = 556;
  14730. t['dagger'] = 556;
  14731. t['daggerdbl'] = 556;
  14732. t['periodcentered'] = 278;
  14733. t['paragraph'] = 537;
  14734. t['bullet'] = 350;
  14735. t['quotesinglbase'] = 222;
  14736. t['quotedblbase'] = 333;
  14737. t['quotedblright'] = 333;
  14738. t['guillemotright'] = 556;
  14739. t['ellipsis'] = 1000;
  14740. t['perthousand'] = 1000;
  14741. t['questiondown'] = 611;
  14742. t['grave'] = 333;
  14743. t['acute'] = 333;
  14744. t['circumflex'] = 333;
  14745. t['tilde'] = 333;
  14746. t['macron'] = 333;
  14747. t['breve'] = 333;
  14748. t['dotaccent'] = 333;
  14749. t['dieresis'] = 333;
  14750. t['ring'] = 333;
  14751. t['cedilla'] = 333;
  14752. t['hungarumlaut'] = 333;
  14753. t['ogonek'] = 333;
  14754. t['caron'] = 333;
  14755. t['emdash'] = 1000;
  14756. t['AE'] = 1000;
  14757. t['ordfeminine'] = 370;
  14758. t['Lslash'] = 556;
  14759. t['Oslash'] = 778;
  14760. t['OE'] = 1000;
  14761. t['ordmasculine'] = 365;
  14762. t['ae'] = 889;
  14763. t['dotlessi'] = 278;
  14764. t['lslash'] = 222;
  14765. t['oslash'] = 611;
  14766. t['oe'] = 944;
  14767. t['germandbls'] = 611;
  14768. t['Idieresis'] = 278;
  14769. t['eacute'] = 556;
  14770. t['abreve'] = 556;
  14771. t['uhungarumlaut'] = 556;
  14772. t['ecaron'] = 556;
  14773. t['Ydieresis'] = 667;
  14774. t['divide'] = 584;
  14775. t['Yacute'] = 667;
  14776. t['Acircumflex'] = 667;
  14777. t['aacute'] = 556;
  14778. t['Ucircumflex'] = 722;
  14779. t['yacute'] = 500;
  14780. t['scommaaccent'] = 500;
  14781. t['ecircumflex'] = 556;
  14782. t['Uring'] = 722;
  14783. t['Udieresis'] = 722;
  14784. t['aogonek'] = 556;
  14785. t['Uacute'] = 722;
  14786. t['uogonek'] = 556;
  14787. t['Edieresis'] = 667;
  14788. t['Dcroat'] = 722;
  14789. t['commaaccent'] = 250;
  14790. t['copyright'] = 737;
  14791. t['Emacron'] = 667;
  14792. t['ccaron'] = 500;
  14793. t['aring'] = 556;
  14794. t['Ncommaaccent'] = 722;
  14795. t['lacute'] = 222;
  14796. t['agrave'] = 556;
  14797. t['Tcommaaccent'] = 611;
  14798. t['Cacute'] = 722;
  14799. t['atilde'] = 556;
  14800. t['Edotaccent'] = 667;
  14801. t['scaron'] = 500;
  14802. t['scedilla'] = 500;
  14803. t['iacute'] = 278;
  14804. t['lozenge'] = 471;
  14805. t['Rcaron'] = 722;
  14806. t['Gcommaaccent'] = 778;
  14807. t['ucircumflex'] = 556;
  14808. t['acircumflex'] = 556;
  14809. t['Amacron'] = 667;
  14810. t['rcaron'] = 333;
  14811. t['ccedilla'] = 500;
  14812. t['Zdotaccent'] = 611;
  14813. t['Thorn'] = 667;
  14814. t['Omacron'] = 778;
  14815. t['Racute'] = 722;
  14816. t['Sacute'] = 667;
  14817. t['dcaron'] = 643;
  14818. t['Umacron'] = 722;
  14819. t['uring'] = 556;
  14820. t['threesuperior'] = 333;
  14821. t['Ograve'] = 778;
  14822. t['Agrave'] = 667;
  14823. t['Abreve'] = 667;
  14824. t['multiply'] = 584;
  14825. t['uacute'] = 556;
  14826. t['Tcaron'] = 611;
  14827. t['partialdiff'] = 476;
  14828. t['ydieresis'] = 500;
  14829. t['Nacute'] = 722;
  14830. t['icircumflex'] = 278;
  14831. t['Ecircumflex'] = 667;
  14832. t['adieresis'] = 556;
  14833. t['edieresis'] = 556;
  14834. t['cacute'] = 500;
  14835. t['nacute'] = 556;
  14836. t['umacron'] = 556;
  14837. t['Ncaron'] = 722;
  14838. t['Iacute'] = 278;
  14839. t['plusminus'] = 584;
  14840. t['brokenbar'] = 260;
  14841. t['registered'] = 737;
  14842. t['Gbreve'] = 778;
  14843. t['Idotaccent'] = 278;
  14844. t['summation'] = 600;
  14845. t['Egrave'] = 667;
  14846. t['racute'] = 333;
  14847. t['omacron'] = 556;
  14848. t['Zacute'] = 611;
  14849. t['Zcaron'] = 611;
  14850. t['greaterequal'] = 549;
  14851. t['Eth'] = 722;
  14852. t['Ccedilla'] = 722;
  14853. t['lcommaaccent'] = 222;
  14854. t['tcaron'] = 317;
  14855. t['eogonek'] = 556;
  14856. t['Uogonek'] = 722;
  14857. t['Aacute'] = 667;
  14858. t['Adieresis'] = 667;
  14859. t['egrave'] = 556;
  14860. t['zacute'] = 500;
  14861. t['iogonek'] = 222;
  14862. t['Oacute'] = 778;
  14863. t['oacute'] = 556;
  14864. t['amacron'] = 556;
  14865. t['sacute'] = 500;
  14866. t['idieresis'] = 278;
  14867. t['Ocircumflex'] = 778;
  14868. t['Ugrave'] = 722;
  14869. t['Delta'] = 612;
  14870. t['thorn'] = 556;
  14871. t['twosuperior'] = 333;
  14872. t['Odieresis'] = 778;
  14873. t['mu'] = 556;
  14874. t['igrave'] = 278;
  14875. t['ohungarumlaut'] = 556;
  14876. t['Eogonek'] = 667;
  14877. t['dcroat'] = 556;
  14878. t['threequarters'] = 834;
  14879. t['Scedilla'] = 667;
  14880. t['lcaron'] = 299;
  14881. t['Kcommaaccent'] = 667;
  14882. t['Lacute'] = 556;
  14883. t['trademark'] = 1000;
  14884. t['edotaccent'] = 556;
  14885. t['Igrave'] = 278;
  14886. t['Imacron'] = 278;
  14887. t['Lcaron'] = 556;
  14888. t['onehalf'] = 834;
  14889. t['lessequal'] = 549;
  14890. t['ocircumflex'] = 556;
  14891. t['ntilde'] = 556;
  14892. t['Uhungarumlaut'] = 722;
  14893. t['Eacute'] = 667;
  14894. t['emacron'] = 556;
  14895. t['gbreve'] = 556;
  14896. t['onequarter'] = 834;
  14897. t['Scaron'] = 667;
  14898. t['Scommaaccent'] = 667;
  14899. t['Ohungarumlaut'] = 778;
  14900. t['degree'] = 400;
  14901. t['ograve'] = 556;
  14902. t['Ccaron'] = 722;
  14903. t['ugrave'] = 556;
  14904. t['radical'] = 453;
  14905. t['Dcaron'] = 722;
  14906. t['rcommaaccent'] = 333;
  14907. t['Ntilde'] = 722;
  14908. t['otilde'] = 556;
  14909. t['Rcommaaccent'] = 722;
  14910. t['Lcommaaccent'] = 556;
  14911. t['Atilde'] = 667;
  14912. t['Aogonek'] = 667;
  14913. t['Aring'] = 667;
  14914. t['Otilde'] = 778;
  14915. t['zdotaccent'] = 500;
  14916. t['Ecaron'] = 667;
  14917. t['Iogonek'] = 278;
  14918. t['kcommaaccent'] = 500;
  14919. t['minus'] = 584;
  14920. t['Icircumflex'] = 278;
  14921. t['ncaron'] = 556;
  14922. t['tcommaaccent'] = 278;
  14923. t['logicalnot'] = 584;
  14924. t['odieresis'] = 556;
  14925. t['udieresis'] = 556;
  14926. t['notequal'] = 549;
  14927. t['gcommaaccent'] = 556;
  14928. t['eth'] = 556;
  14929. t['zcaron'] = 500;
  14930. t['ncommaaccent'] = 556;
  14931. t['onesuperior'] = 333;
  14932. t['imacron'] = 278;
  14933. t['Euro'] = 556;
  14934. });
  14935. t['Symbol'] = getLookupTableFactory(function (t) {
  14936. t['space'] = 250;
  14937. t['exclam'] = 333;
  14938. t['universal'] = 713;
  14939. t['numbersign'] = 500;
  14940. t['existential'] = 549;
  14941. t['percent'] = 833;
  14942. t['ampersand'] = 778;
  14943. t['suchthat'] = 439;
  14944. t['parenleft'] = 333;
  14945. t['parenright'] = 333;
  14946. t['asteriskmath'] = 500;
  14947. t['plus'] = 549;
  14948. t['comma'] = 250;
  14949. t['minus'] = 549;
  14950. t['period'] = 250;
  14951. t['slash'] = 278;
  14952. t['zero'] = 500;
  14953. t['one'] = 500;
  14954. t['two'] = 500;
  14955. t['three'] = 500;
  14956. t['four'] = 500;
  14957. t['five'] = 500;
  14958. t['six'] = 500;
  14959. t['seven'] = 500;
  14960. t['eight'] = 500;
  14961. t['nine'] = 500;
  14962. t['colon'] = 278;
  14963. t['semicolon'] = 278;
  14964. t['less'] = 549;
  14965. t['equal'] = 549;
  14966. t['greater'] = 549;
  14967. t['question'] = 444;
  14968. t['congruent'] = 549;
  14969. t['Alpha'] = 722;
  14970. t['Beta'] = 667;
  14971. t['Chi'] = 722;
  14972. t['Delta'] = 612;
  14973. t['Epsilon'] = 611;
  14974. t['Phi'] = 763;
  14975. t['Gamma'] = 603;
  14976. t['Eta'] = 722;
  14977. t['Iota'] = 333;
  14978. t['theta1'] = 631;
  14979. t['Kappa'] = 722;
  14980. t['Lambda'] = 686;
  14981. t['Mu'] = 889;
  14982. t['Nu'] = 722;
  14983. t['Omicron'] = 722;
  14984. t['Pi'] = 768;
  14985. t['Theta'] = 741;
  14986. t['Rho'] = 556;
  14987. t['Sigma'] = 592;
  14988. t['Tau'] = 611;
  14989. t['Upsilon'] = 690;
  14990. t['sigma1'] = 439;
  14991. t['Omega'] = 768;
  14992. t['Xi'] = 645;
  14993. t['Psi'] = 795;
  14994. t['Zeta'] = 611;
  14995. t['bracketleft'] = 333;
  14996. t['therefore'] = 863;
  14997. t['bracketright'] = 333;
  14998. t['perpendicular'] = 658;
  14999. t['underscore'] = 500;
  15000. t['radicalex'] = 500;
  15001. t['alpha'] = 631;
  15002. t['beta'] = 549;
  15003. t['chi'] = 549;
  15004. t['delta'] = 494;
  15005. t['epsilon'] = 439;
  15006. t['phi'] = 521;
  15007. t['gamma'] = 411;
  15008. t['eta'] = 603;
  15009. t['iota'] = 329;
  15010. t['phi1'] = 603;
  15011. t['kappa'] = 549;
  15012. t['lambda'] = 549;
  15013. t['mu'] = 576;
  15014. t['nu'] = 521;
  15015. t['omicron'] = 549;
  15016. t['pi'] = 549;
  15017. t['theta'] = 521;
  15018. t['rho'] = 549;
  15019. t['sigma'] = 603;
  15020. t['tau'] = 439;
  15021. t['upsilon'] = 576;
  15022. t['omega1'] = 713;
  15023. t['omega'] = 686;
  15024. t['xi'] = 493;
  15025. t['psi'] = 686;
  15026. t['zeta'] = 494;
  15027. t['braceleft'] = 480;
  15028. t['bar'] = 200;
  15029. t['braceright'] = 480;
  15030. t['similar'] = 549;
  15031. t['Euro'] = 750;
  15032. t['Upsilon1'] = 620;
  15033. t['minute'] = 247;
  15034. t['lessequal'] = 549;
  15035. t['fraction'] = 167;
  15036. t['infinity'] = 713;
  15037. t['florin'] = 500;
  15038. t['club'] = 753;
  15039. t['diamond'] = 753;
  15040. t['heart'] = 753;
  15041. t['spade'] = 753;
  15042. t['arrowboth'] = 1042;
  15043. t['arrowleft'] = 987;
  15044. t['arrowup'] = 603;
  15045. t['arrowright'] = 987;
  15046. t['arrowdown'] = 603;
  15047. t['degree'] = 400;
  15048. t['plusminus'] = 549;
  15049. t['second'] = 411;
  15050. t['greaterequal'] = 549;
  15051. t['multiply'] = 549;
  15052. t['proportional'] = 713;
  15053. t['partialdiff'] = 494;
  15054. t['bullet'] = 460;
  15055. t['divide'] = 549;
  15056. t['notequal'] = 549;
  15057. t['equivalence'] = 549;
  15058. t['approxequal'] = 549;
  15059. t['ellipsis'] = 1000;
  15060. t['arrowvertex'] = 603;
  15061. t['arrowhorizex'] = 1000;
  15062. t['carriagereturn'] = 658;
  15063. t['aleph'] = 823;
  15064. t['Ifraktur'] = 686;
  15065. t['Rfraktur'] = 795;
  15066. t['weierstrass'] = 987;
  15067. t['circlemultiply'] = 768;
  15068. t['circleplus'] = 768;
  15069. t['emptyset'] = 823;
  15070. t['intersection'] = 768;
  15071. t['union'] = 768;
  15072. t['propersuperset'] = 713;
  15073. t['reflexsuperset'] = 713;
  15074. t['notsubset'] = 713;
  15075. t['propersubset'] = 713;
  15076. t['reflexsubset'] = 713;
  15077. t['element'] = 713;
  15078. t['notelement'] = 713;
  15079. t['angle'] = 768;
  15080. t['gradient'] = 713;
  15081. t['registerserif'] = 790;
  15082. t['copyrightserif'] = 790;
  15083. t['trademarkserif'] = 890;
  15084. t['product'] = 823;
  15085. t['radical'] = 549;
  15086. t['dotmath'] = 250;
  15087. t['logicalnot'] = 713;
  15088. t['logicaland'] = 603;
  15089. t['logicalor'] = 603;
  15090. t['arrowdblboth'] = 1042;
  15091. t['arrowdblleft'] = 987;
  15092. t['arrowdblup'] = 603;
  15093. t['arrowdblright'] = 987;
  15094. t['arrowdbldown'] = 603;
  15095. t['lozenge'] = 494;
  15096. t['angleleft'] = 329;
  15097. t['registersans'] = 790;
  15098. t['copyrightsans'] = 790;
  15099. t['trademarksans'] = 786;
  15100. t['summation'] = 713;
  15101. t['parenlefttp'] = 384;
  15102. t['parenleftex'] = 384;
  15103. t['parenleftbt'] = 384;
  15104. t['bracketlefttp'] = 384;
  15105. t['bracketleftex'] = 384;
  15106. t['bracketleftbt'] = 384;
  15107. t['bracelefttp'] = 494;
  15108. t['braceleftmid'] = 494;
  15109. t['braceleftbt'] = 494;
  15110. t['braceex'] = 494;
  15111. t['angleright'] = 329;
  15112. t['integral'] = 274;
  15113. t['integraltp'] = 686;
  15114. t['integralex'] = 686;
  15115. t['integralbt'] = 686;
  15116. t['parenrighttp'] = 384;
  15117. t['parenrightex'] = 384;
  15118. t['parenrightbt'] = 384;
  15119. t['bracketrighttp'] = 384;
  15120. t['bracketrightex'] = 384;
  15121. t['bracketrightbt'] = 384;
  15122. t['bracerighttp'] = 494;
  15123. t['bracerightmid'] = 494;
  15124. t['bracerightbt'] = 494;
  15125. t['apple'] = 790;
  15126. });
  15127. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15128. t['space'] = 250;
  15129. t['exclam'] = 333;
  15130. t['quotedbl'] = 408;
  15131. t['numbersign'] = 500;
  15132. t['dollar'] = 500;
  15133. t['percent'] = 833;
  15134. t['ampersand'] = 778;
  15135. t['quoteright'] = 333;
  15136. t['parenleft'] = 333;
  15137. t['parenright'] = 333;
  15138. t['asterisk'] = 500;
  15139. t['plus'] = 564;
  15140. t['comma'] = 250;
  15141. t['hyphen'] = 333;
  15142. t['period'] = 250;
  15143. t['slash'] = 278;
  15144. t['zero'] = 500;
  15145. t['one'] = 500;
  15146. t['two'] = 500;
  15147. t['three'] = 500;
  15148. t['four'] = 500;
  15149. t['five'] = 500;
  15150. t['six'] = 500;
  15151. t['seven'] = 500;
  15152. t['eight'] = 500;
  15153. t['nine'] = 500;
  15154. t['colon'] = 278;
  15155. t['semicolon'] = 278;
  15156. t['less'] = 564;
  15157. t['equal'] = 564;
  15158. t['greater'] = 564;
  15159. t['question'] = 444;
  15160. t['at'] = 921;
  15161. t['A'] = 722;
  15162. t['B'] = 667;
  15163. t['C'] = 667;
  15164. t['D'] = 722;
  15165. t['E'] = 611;
  15166. t['F'] = 556;
  15167. t['G'] = 722;
  15168. t['H'] = 722;
  15169. t['I'] = 333;
  15170. t['J'] = 389;
  15171. t['K'] = 722;
  15172. t['L'] = 611;
  15173. t['M'] = 889;
  15174. t['N'] = 722;
  15175. t['O'] = 722;
  15176. t['P'] = 556;
  15177. t['Q'] = 722;
  15178. t['R'] = 667;
  15179. t['S'] = 556;
  15180. t['T'] = 611;
  15181. t['U'] = 722;
  15182. t['V'] = 722;
  15183. t['W'] = 944;
  15184. t['X'] = 722;
  15185. t['Y'] = 722;
  15186. t['Z'] = 611;
  15187. t['bracketleft'] = 333;
  15188. t['backslash'] = 278;
  15189. t['bracketright'] = 333;
  15190. t['asciicircum'] = 469;
  15191. t['underscore'] = 500;
  15192. t['quoteleft'] = 333;
  15193. t['a'] = 444;
  15194. t['b'] = 500;
  15195. t['c'] = 444;
  15196. t['d'] = 500;
  15197. t['e'] = 444;
  15198. t['f'] = 333;
  15199. t['g'] = 500;
  15200. t['h'] = 500;
  15201. t['i'] = 278;
  15202. t['j'] = 278;
  15203. t['k'] = 500;
  15204. t['l'] = 278;
  15205. t['m'] = 778;
  15206. t['n'] = 500;
  15207. t['o'] = 500;
  15208. t['p'] = 500;
  15209. t['q'] = 500;
  15210. t['r'] = 333;
  15211. t['s'] = 389;
  15212. t['t'] = 278;
  15213. t['u'] = 500;
  15214. t['v'] = 500;
  15215. t['w'] = 722;
  15216. t['x'] = 500;
  15217. t['y'] = 500;
  15218. t['z'] = 444;
  15219. t['braceleft'] = 480;
  15220. t['bar'] = 200;
  15221. t['braceright'] = 480;
  15222. t['asciitilde'] = 541;
  15223. t['exclamdown'] = 333;
  15224. t['cent'] = 500;
  15225. t['sterling'] = 500;
  15226. t['fraction'] = 167;
  15227. t['yen'] = 500;
  15228. t['florin'] = 500;
  15229. t['section'] = 500;
  15230. t['currency'] = 500;
  15231. t['quotesingle'] = 180;
  15232. t['quotedblleft'] = 444;
  15233. t['guillemotleft'] = 500;
  15234. t['guilsinglleft'] = 333;
  15235. t['guilsinglright'] = 333;
  15236. t['fi'] = 556;
  15237. t['fl'] = 556;
  15238. t['endash'] = 500;
  15239. t['dagger'] = 500;
  15240. t['daggerdbl'] = 500;
  15241. t['periodcentered'] = 250;
  15242. t['paragraph'] = 453;
  15243. t['bullet'] = 350;
  15244. t['quotesinglbase'] = 333;
  15245. t['quotedblbase'] = 444;
  15246. t['quotedblright'] = 444;
  15247. t['guillemotright'] = 500;
  15248. t['ellipsis'] = 1000;
  15249. t['perthousand'] = 1000;
  15250. t['questiondown'] = 444;
  15251. t['grave'] = 333;
  15252. t['acute'] = 333;
  15253. t['circumflex'] = 333;
  15254. t['tilde'] = 333;
  15255. t['macron'] = 333;
  15256. t['breve'] = 333;
  15257. t['dotaccent'] = 333;
  15258. t['dieresis'] = 333;
  15259. t['ring'] = 333;
  15260. t['cedilla'] = 333;
  15261. t['hungarumlaut'] = 333;
  15262. t['ogonek'] = 333;
  15263. t['caron'] = 333;
  15264. t['emdash'] = 1000;
  15265. t['AE'] = 889;
  15266. t['ordfeminine'] = 276;
  15267. t['Lslash'] = 611;
  15268. t['Oslash'] = 722;
  15269. t['OE'] = 889;
  15270. t['ordmasculine'] = 310;
  15271. t['ae'] = 667;
  15272. t['dotlessi'] = 278;
  15273. t['lslash'] = 278;
  15274. t['oslash'] = 500;
  15275. t['oe'] = 722;
  15276. t['germandbls'] = 500;
  15277. t['Idieresis'] = 333;
  15278. t['eacute'] = 444;
  15279. t['abreve'] = 444;
  15280. t['uhungarumlaut'] = 500;
  15281. t['ecaron'] = 444;
  15282. t['Ydieresis'] = 722;
  15283. t['divide'] = 564;
  15284. t['Yacute'] = 722;
  15285. t['Acircumflex'] = 722;
  15286. t['aacute'] = 444;
  15287. t['Ucircumflex'] = 722;
  15288. t['yacute'] = 500;
  15289. t['scommaaccent'] = 389;
  15290. t['ecircumflex'] = 444;
  15291. t['Uring'] = 722;
  15292. t['Udieresis'] = 722;
  15293. t['aogonek'] = 444;
  15294. t['Uacute'] = 722;
  15295. t['uogonek'] = 500;
  15296. t['Edieresis'] = 611;
  15297. t['Dcroat'] = 722;
  15298. t['commaaccent'] = 250;
  15299. t['copyright'] = 760;
  15300. t['Emacron'] = 611;
  15301. t['ccaron'] = 444;
  15302. t['aring'] = 444;
  15303. t['Ncommaaccent'] = 722;
  15304. t['lacute'] = 278;
  15305. t['agrave'] = 444;
  15306. t['Tcommaaccent'] = 611;
  15307. t['Cacute'] = 667;
  15308. t['atilde'] = 444;
  15309. t['Edotaccent'] = 611;
  15310. t['scaron'] = 389;
  15311. t['scedilla'] = 389;
  15312. t['iacute'] = 278;
  15313. t['lozenge'] = 471;
  15314. t['Rcaron'] = 667;
  15315. t['Gcommaaccent'] = 722;
  15316. t['ucircumflex'] = 500;
  15317. t['acircumflex'] = 444;
  15318. t['Amacron'] = 722;
  15319. t['rcaron'] = 333;
  15320. t['ccedilla'] = 444;
  15321. t['Zdotaccent'] = 611;
  15322. t['Thorn'] = 556;
  15323. t['Omacron'] = 722;
  15324. t['Racute'] = 667;
  15325. t['Sacute'] = 556;
  15326. t['dcaron'] = 588;
  15327. t['Umacron'] = 722;
  15328. t['uring'] = 500;
  15329. t['threesuperior'] = 300;
  15330. t['Ograve'] = 722;
  15331. t['Agrave'] = 722;
  15332. t['Abreve'] = 722;
  15333. t['multiply'] = 564;
  15334. t['uacute'] = 500;
  15335. t['Tcaron'] = 611;
  15336. t['partialdiff'] = 476;
  15337. t['ydieresis'] = 500;
  15338. t['Nacute'] = 722;
  15339. t['icircumflex'] = 278;
  15340. t['Ecircumflex'] = 611;
  15341. t['adieresis'] = 444;
  15342. t['edieresis'] = 444;
  15343. t['cacute'] = 444;
  15344. t['nacute'] = 500;
  15345. t['umacron'] = 500;
  15346. t['Ncaron'] = 722;
  15347. t['Iacute'] = 333;
  15348. t['plusminus'] = 564;
  15349. t['brokenbar'] = 200;
  15350. t['registered'] = 760;
  15351. t['Gbreve'] = 722;
  15352. t['Idotaccent'] = 333;
  15353. t['summation'] = 600;
  15354. t['Egrave'] = 611;
  15355. t['racute'] = 333;
  15356. t['omacron'] = 500;
  15357. t['Zacute'] = 611;
  15358. t['Zcaron'] = 611;
  15359. t['greaterequal'] = 549;
  15360. t['Eth'] = 722;
  15361. t['Ccedilla'] = 667;
  15362. t['lcommaaccent'] = 278;
  15363. t['tcaron'] = 326;
  15364. t['eogonek'] = 444;
  15365. t['Uogonek'] = 722;
  15366. t['Aacute'] = 722;
  15367. t['Adieresis'] = 722;
  15368. t['egrave'] = 444;
  15369. t['zacute'] = 444;
  15370. t['iogonek'] = 278;
  15371. t['Oacute'] = 722;
  15372. t['oacute'] = 500;
  15373. t['amacron'] = 444;
  15374. t['sacute'] = 389;
  15375. t['idieresis'] = 278;
  15376. t['Ocircumflex'] = 722;
  15377. t['Ugrave'] = 722;
  15378. t['Delta'] = 612;
  15379. t['thorn'] = 500;
  15380. t['twosuperior'] = 300;
  15381. t['Odieresis'] = 722;
  15382. t['mu'] = 500;
  15383. t['igrave'] = 278;
  15384. t['ohungarumlaut'] = 500;
  15385. t['Eogonek'] = 611;
  15386. t['dcroat'] = 500;
  15387. t['threequarters'] = 750;
  15388. t['Scedilla'] = 556;
  15389. t['lcaron'] = 344;
  15390. t['Kcommaaccent'] = 722;
  15391. t['Lacute'] = 611;
  15392. t['trademark'] = 980;
  15393. t['edotaccent'] = 444;
  15394. t['Igrave'] = 333;
  15395. t['Imacron'] = 333;
  15396. t['Lcaron'] = 611;
  15397. t['onehalf'] = 750;
  15398. t['lessequal'] = 549;
  15399. t['ocircumflex'] = 500;
  15400. t['ntilde'] = 500;
  15401. t['Uhungarumlaut'] = 722;
  15402. t['Eacute'] = 611;
  15403. t['emacron'] = 444;
  15404. t['gbreve'] = 500;
  15405. t['onequarter'] = 750;
  15406. t['Scaron'] = 556;
  15407. t['Scommaaccent'] = 556;
  15408. t['Ohungarumlaut'] = 722;
  15409. t['degree'] = 400;
  15410. t['ograve'] = 500;
  15411. t['Ccaron'] = 667;
  15412. t['ugrave'] = 500;
  15413. t['radical'] = 453;
  15414. t['Dcaron'] = 722;
  15415. t['rcommaaccent'] = 333;
  15416. t['Ntilde'] = 722;
  15417. t['otilde'] = 500;
  15418. t['Rcommaaccent'] = 667;
  15419. t['Lcommaaccent'] = 611;
  15420. t['Atilde'] = 722;
  15421. t['Aogonek'] = 722;
  15422. t['Aring'] = 722;
  15423. t['Otilde'] = 722;
  15424. t['zdotaccent'] = 444;
  15425. t['Ecaron'] = 611;
  15426. t['Iogonek'] = 333;
  15427. t['kcommaaccent'] = 500;
  15428. t['minus'] = 564;
  15429. t['Icircumflex'] = 333;
  15430. t['ncaron'] = 500;
  15431. t['tcommaaccent'] = 278;
  15432. t['logicalnot'] = 564;
  15433. t['odieresis'] = 500;
  15434. t['udieresis'] = 500;
  15435. t['notequal'] = 549;
  15436. t['gcommaaccent'] = 500;
  15437. t['eth'] = 500;
  15438. t['zcaron'] = 444;
  15439. t['ncommaaccent'] = 500;
  15440. t['onesuperior'] = 300;
  15441. t['imacron'] = 278;
  15442. t['Euro'] = 500;
  15443. });
  15444. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15445. t['space'] = 250;
  15446. t['exclam'] = 333;
  15447. t['quotedbl'] = 555;
  15448. t['numbersign'] = 500;
  15449. t['dollar'] = 500;
  15450. t['percent'] = 1000;
  15451. t['ampersand'] = 833;
  15452. t['quoteright'] = 333;
  15453. t['parenleft'] = 333;
  15454. t['parenright'] = 333;
  15455. t['asterisk'] = 500;
  15456. t['plus'] = 570;
  15457. t['comma'] = 250;
  15458. t['hyphen'] = 333;
  15459. t['period'] = 250;
  15460. t['slash'] = 278;
  15461. t['zero'] = 500;
  15462. t['one'] = 500;
  15463. t['two'] = 500;
  15464. t['three'] = 500;
  15465. t['four'] = 500;
  15466. t['five'] = 500;
  15467. t['six'] = 500;
  15468. t['seven'] = 500;
  15469. t['eight'] = 500;
  15470. t['nine'] = 500;
  15471. t['colon'] = 333;
  15472. t['semicolon'] = 333;
  15473. t['less'] = 570;
  15474. t['equal'] = 570;
  15475. t['greater'] = 570;
  15476. t['question'] = 500;
  15477. t['at'] = 930;
  15478. t['A'] = 722;
  15479. t['B'] = 667;
  15480. t['C'] = 722;
  15481. t['D'] = 722;
  15482. t['E'] = 667;
  15483. t['F'] = 611;
  15484. t['G'] = 778;
  15485. t['H'] = 778;
  15486. t['I'] = 389;
  15487. t['J'] = 500;
  15488. t['K'] = 778;
  15489. t['L'] = 667;
  15490. t['M'] = 944;
  15491. t['N'] = 722;
  15492. t['O'] = 778;
  15493. t['P'] = 611;
  15494. t['Q'] = 778;
  15495. t['R'] = 722;
  15496. t['S'] = 556;
  15497. t['T'] = 667;
  15498. t['U'] = 722;
  15499. t['V'] = 722;
  15500. t['W'] = 1000;
  15501. t['X'] = 722;
  15502. t['Y'] = 722;
  15503. t['Z'] = 667;
  15504. t['bracketleft'] = 333;
  15505. t['backslash'] = 278;
  15506. t['bracketright'] = 333;
  15507. t['asciicircum'] = 581;
  15508. t['underscore'] = 500;
  15509. t['quoteleft'] = 333;
  15510. t['a'] = 500;
  15511. t['b'] = 556;
  15512. t['c'] = 444;
  15513. t['d'] = 556;
  15514. t['e'] = 444;
  15515. t['f'] = 333;
  15516. t['g'] = 500;
  15517. t['h'] = 556;
  15518. t['i'] = 278;
  15519. t['j'] = 333;
  15520. t['k'] = 556;
  15521. t['l'] = 278;
  15522. t['m'] = 833;
  15523. t['n'] = 556;
  15524. t['o'] = 500;
  15525. t['p'] = 556;
  15526. t['q'] = 556;
  15527. t['r'] = 444;
  15528. t['s'] = 389;
  15529. t['t'] = 333;
  15530. t['u'] = 556;
  15531. t['v'] = 500;
  15532. t['w'] = 722;
  15533. t['x'] = 500;
  15534. t['y'] = 500;
  15535. t['z'] = 444;
  15536. t['braceleft'] = 394;
  15537. t['bar'] = 220;
  15538. t['braceright'] = 394;
  15539. t['asciitilde'] = 520;
  15540. t['exclamdown'] = 333;
  15541. t['cent'] = 500;
  15542. t['sterling'] = 500;
  15543. t['fraction'] = 167;
  15544. t['yen'] = 500;
  15545. t['florin'] = 500;
  15546. t['section'] = 500;
  15547. t['currency'] = 500;
  15548. t['quotesingle'] = 278;
  15549. t['quotedblleft'] = 500;
  15550. t['guillemotleft'] = 500;
  15551. t['guilsinglleft'] = 333;
  15552. t['guilsinglright'] = 333;
  15553. t['fi'] = 556;
  15554. t['fl'] = 556;
  15555. t['endash'] = 500;
  15556. t['dagger'] = 500;
  15557. t['daggerdbl'] = 500;
  15558. t['periodcentered'] = 250;
  15559. t['paragraph'] = 540;
  15560. t['bullet'] = 350;
  15561. t['quotesinglbase'] = 333;
  15562. t['quotedblbase'] = 500;
  15563. t['quotedblright'] = 500;
  15564. t['guillemotright'] = 500;
  15565. t['ellipsis'] = 1000;
  15566. t['perthousand'] = 1000;
  15567. t['questiondown'] = 500;
  15568. t['grave'] = 333;
  15569. t['acute'] = 333;
  15570. t['circumflex'] = 333;
  15571. t['tilde'] = 333;
  15572. t['macron'] = 333;
  15573. t['breve'] = 333;
  15574. t['dotaccent'] = 333;
  15575. t['dieresis'] = 333;
  15576. t['ring'] = 333;
  15577. t['cedilla'] = 333;
  15578. t['hungarumlaut'] = 333;
  15579. t['ogonek'] = 333;
  15580. t['caron'] = 333;
  15581. t['emdash'] = 1000;
  15582. t['AE'] = 1000;
  15583. t['ordfeminine'] = 300;
  15584. t['Lslash'] = 667;
  15585. t['Oslash'] = 778;
  15586. t['OE'] = 1000;
  15587. t['ordmasculine'] = 330;
  15588. t['ae'] = 722;
  15589. t['dotlessi'] = 278;
  15590. t['lslash'] = 278;
  15591. t['oslash'] = 500;
  15592. t['oe'] = 722;
  15593. t['germandbls'] = 556;
  15594. t['Idieresis'] = 389;
  15595. t['eacute'] = 444;
  15596. t['abreve'] = 500;
  15597. t['uhungarumlaut'] = 556;
  15598. t['ecaron'] = 444;
  15599. t['Ydieresis'] = 722;
  15600. t['divide'] = 570;
  15601. t['Yacute'] = 722;
  15602. t['Acircumflex'] = 722;
  15603. t['aacute'] = 500;
  15604. t['Ucircumflex'] = 722;
  15605. t['yacute'] = 500;
  15606. t['scommaaccent'] = 389;
  15607. t['ecircumflex'] = 444;
  15608. t['Uring'] = 722;
  15609. t['Udieresis'] = 722;
  15610. t['aogonek'] = 500;
  15611. t['Uacute'] = 722;
  15612. t['uogonek'] = 556;
  15613. t['Edieresis'] = 667;
  15614. t['Dcroat'] = 722;
  15615. t['commaaccent'] = 250;
  15616. t['copyright'] = 747;
  15617. t['Emacron'] = 667;
  15618. t['ccaron'] = 444;
  15619. t['aring'] = 500;
  15620. t['Ncommaaccent'] = 722;
  15621. t['lacute'] = 278;
  15622. t['agrave'] = 500;
  15623. t['Tcommaaccent'] = 667;
  15624. t['Cacute'] = 722;
  15625. t['atilde'] = 500;
  15626. t['Edotaccent'] = 667;
  15627. t['scaron'] = 389;
  15628. t['scedilla'] = 389;
  15629. t['iacute'] = 278;
  15630. t['lozenge'] = 494;
  15631. t['Rcaron'] = 722;
  15632. t['Gcommaaccent'] = 778;
  15633. t['ucircumflex'] = 556;
  15634. t['acircumflex'] = 500;
  15635. t['Amacron'] = 722;
  15636. t['rcaron'] = 444;
  15637. t['ccedilla'] = 444;
  15638. t['Zdotaccent'] = 667;
  15639. t['Thorn'] = 611;
  15640. t['Omacron'] = 778;
  15641. t['Racute'] = 722;
  15642. t['Sacute'] = 556;
  15643. t['dcaron'] = 672;
  15644. t['Umacron'] = 722;
  15645. t['uring'] = 556;
  15646. t['threesuperior'] = 300;
  15647. t['Ograve'] = 778;
  15648. t['Agrave'] = 722;
  15649. t['Abreve'] = 722;
  15650. t['multiply'] = 570;
  15651. t['uacute'] = 556;
  15652. t['Tcaron'] = 667;
  15653. t['partialdiff'] = 494;
  15654. t['ydieresis'] = 500;
  15655. t['Nacute'] = 722;
  15656. t['icircumflex'] = 278;
  15657. t['Ecircumflex'] = 667;
  15658. t['adieresis'] = 500;
  15659. t['edieresis'] = 444;
  15660. t['cacute'] = 444;
  15661. t['nacute'] = 556;
  15662. t['umacron'] = 556;
  15663. t['Ncaron'] = 722;
  15664. t['Iacute'] = 389;
  15665. t['plusminus'] = 570;
  15666. t['brokenbar'] = 220;
  15667. t['registered'] = 747;
  15668. t['Gbreve'] = 778;
  15669. t['Idotaccent'] = 389;
  15670. t['summation'] = 600;
  15671. t['Egrave'] = 667;
  15672. t['racute'] = 444;
  15673. t['omacron'] = 500;
  15674. t['Zacute'] = 667;
  15675. t['Zcaron'] = 667;
  15676. t['greaterequal'] = 549;
  15677. t['Eth'] = 722;
  15678. t['Ccedilla'] = 722;
  15679. t['lcommaaccent'] = 278;
  15680. t['tcaron'] = 416;
  15681. t['eogonek'] = 444;
  15682. t['Uogonek'] = 722;
  15683. t['Aacute'] = 722;
  15684. t['Adieresis'] = 722;
  15685. t['egrave'] = 444;
  15686. t['zacute'] = 444;
  15687. t['iogonek'] = 278;
  15688. t['Oacute'] = 778;
  15689. t['oacute'] = 500;
  15690. t['amacron'] = 500;
  15691. t['sacute'] = 389;
  15692. t['idieresis'] = 278;
  15693. t['Ocircumflex'] = 778;
  15694. t['Ugrave'] = 722;
  15695. t['Delta'] = 612;
  15696. t['thorn'] = 556;
  15697. t['twosuperior'] = 300;
  15698. t['Odieresis'] = 778;
  15699. t['mu'] = 556;
  15700. t['igrave'] = 278;
  15701. t['ohungarumlaut'] = 500;
  15702. t['Eogonek'] = 667;
  15703. t['dcroat'] = 556;
  15704. t['threequarters'] = 750;
  15705. t['Scedilla'] = 556;
  15706. t['lcaron'] = 394;
  15707. t['Kcommaaccent'] = 778;
  15708. t['Lacute'] = 667;
  15709. t['trademark'] = 1000;
  15710. t['edotaccent'] = 444;
  15711. t['Igrave'] = 389;
  15712. t['Imacron'] = 389;
  15713. t['Lcaron'] = 667;
  15714. t['onehalf'] = 750;
  15715. t['lessequal'] = 549;
  15716. t['ocircumflex'] = 500;
  15717. t['ntilde'] = 556;
  15718. t['Uhungarumlaut'] = 722;
  15719. t['Eacute'] = 667;
  15720. t['emacron'] = 444;
  15721. t['gbreve'] = 500;
  15722. t['onequarter'] = 750;
  15723. t['Scaron'] = 556;
  15724. t['Scommaaccent'] = 556;
  15725. t['Ohungarumlaut'] = 778;
  15726. t['degree'] = 400;
  15727. t['ograve'] = 500;
  15728. t['Ccaron'] = 722;
  15729. t['ugrave'] = 556;
  15730. t['radical'] = 549;
  15731. t['Dcaron'] = 722;
  15732. t['rcommaaccent'] = 444;
  15733. t['Ntilde'] = 722;
  15734. t['otilde'] = 500;
  15735. t['Rcommaaccent'] = 722;
  15736. t['Lcommaaccent'] = 667;
  15737. t['Atilde'] = 722;
  15738. t['Aogonek'] = 722;
  15739. t['Aring'] = 722;
  15740. t['Otilde'] = 778;
  15741. t['zdotaccent'] = 444;
  15742. t['Ecaron'] = 667;
  15743. t['Iogonek'] = 389;
  15744. t['kcommaaccent'] = 556;
  15745. t['minus'] = 570;
  15746. t['Icircumflex'] = 389;
  15747. t['ncaron'] = 556;
  15748. t['tcommaaccent'] = 333;
  15749. t['logicalnot'] = 570;
  15750. t['odieresis'] = 500;
  15751. t['udieresis'] = 556;
  15752. t['notequal'] = 549;
  15753. t['gcommaaccent'] = 500;
  15754. t['eth'] = 500;
  15755. t['zcaron'] = 444;
  15756. t['ncommaaccent'] = 556;
  15757. t['onesuperior'] = 300;
  15758. t['imacron'] = 278;
  15759. t['Euro'] = 500;
  15760. });
  15761. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15762. t['space'] = 250;
  15763. t['exclam'] = 389;
  15764. t['quotedbl'] = 555;
  15765. t['numbersign'] = 500;
  15766. t['dollar'] = 500;
  15767. t['percent'] = 833;
  15768. t['ampersand'] = 778;
  15769. t['quoteright'] = 333;
  15770. t['parenleft'] = 333;
  15771. t['parenright'] = 333;
  15772. t['asterisk'] = 500;
  15773. t['plus'] = 570;
  15774. t['comma'] = 250;
  15775. t['hyphen'] = 333;
  15776. t['period'] = 250;
  15777. t['slash'] = 278;
  15778. t['zero'] = 500;
  15779. t['one'] = 500;
  15780. t['two'] = 500;
  15781. t['three'] = 500;
  15782. t['four'] = 500;
  15783. t['five'] = 500;
  15784. t['six'] = 500;
  15785. t['seven'] = 500;
  15786. t['eight'] = 500;
  15787. t['nine'] = 500;
  15788. t['colon'] = 333;
  15789. t['semicolon'] = 333;
  15790. t['less'] = 570;
  15791. t['equal'] = 570;
  15792. t['greater'] = 570;
  15793. t['question'] = 500;
  15794. t['at'] = 832;
  15795. t['A'] = 667;
  15796. t['B'] = 667;
  15797. t['C'] = 667;
  15798. t['D'] = 722;
  15799. t['E'] = 667;
  15800. t['F'] = 667;
  15801. t['G'] = 722;
  15802. t['H'] = 778;
  15803. t['I'] = 389;
  15804. t['J'] = 500;
  15805. t['K'] = 667;
  15806. t['L'] = 611;
  15807. t['M'] = 889;
  15808. t['N'] = 722;
  15809. t['O'] = 722;
  15810. t['P'] = 611;
  15811. t['Q'] = 722;
  15812. t['R'] = 667;
  15813. t['S'] = 556;
  15814. t['T'] = 611;
  15815. t['U'] = 722;
  15816. t['V'] = 667;
  15817. t['W'] = 889;
  15818. t['X'] = 667;
  15819. t['Y'] = 611;
  15820. t['Z'] = 611;
  15821. t['bracketleft'] = 333;
  15822. t['backslash'] = 278;
  15823. t['bracketright'] = 333;
  15824. t['asciicircum'] = 570;
  15825. t['underscore'] = 500;
  15826. t['quoteleft'] = 333;
  15827. t['a'] = 500;
  15828. t['b'] = 500;
  15829. t['c'] = 444;
  15830. t['d'] = 500;
  15831. t['e'] = 444;
  15832. t['f'] = 333;
  15833. t['g'] = 500;
  15834. t['h'] = 556;
  15835. t['i'] = 278;
  15836. t['j'] = 278;
  15837. t['k'] = 500;
  15838. t['l'] = 278;
  15839. t['m'] = 778;
  15840. t['n'] = 556;
  15841. t['o'] = 500;
  15842. t['p'] = 500;
  15843. t['q'] = 500;
  15844. t['r'] = 389;
  15845. t['s'] = 389;
  15846. t['t'] = 278;
  15847. t['u'] = 556;
  15848. t['v'] = 444;
  15849. t['w'] = 667;
  15850. t['x'] = 500;
  15851. t['y'] = 444;
  15852. t['z'] = 389;
  15853. t['braceleft'] = 348;
  15854. t['bar'] = 220;
  15855. t['braceright'] = 348;
  15856. t['asciitilde'] = 570;
  15857. t['exclamdown'] = 389;
  15858. t['cent'] = 500;
  15859. t['sterling'] = 500;
  15860. t['fraction'] = 167;
  15861. t['yen'] = 500;
  15862. t['florin'] = 500;
  15863. t['section'] = 500;
  15864. t['currency'] = 500;
  15865. t['quotesingle'] = 278;
  15866. t['quotedblleft'] = 500;
  15867. t['guillemotleft'] = 500;
  15868. t['guilsinglleft'] = 333;
  15869. t['guilsinglright'] = 333;
  15870. t['fi'] = 556;
  15871. t['fl'] = 556;
  15872. t['endash'] = 500;
  15873. t['dagger'] = 500;
  15874. t['daggerdbl'] = 500;
  15875. t['periodcentered'] = 250;
  15876. t['paragraph'] = 500;
  15877. t['bullet'] = 350;
  15878. t['quotesinglbase'] = 333;
  15879. t['quotedblbase'] = 500;
  15880. t['quotedblright'] = 500;
  15881. t['guillemotright'] = 500;
  15882. t['ellipsis'] = 1000;
  15883. t['perthousand'] = 1000;
  15884. t['questiondown'] = 500;
  15885. t['grave'] = 333;
  15886. t['acute'] = 333;
  15887. t['circumflex'] = 333;
  15888. t['tilde'] = 333;
  15889. t['macron'] = 333;
  15890. t['breve'] = 333;
  15891. t['dotaccent'] = 333;
  15892. t['dieresis'] = 333;
  15893. t['ring'] = 333;
  15894. t['cedilla'] = 333;
  15895. t['hungarumlaut'] = 333;
  15896. t['ogonek'] = 333;
  15897. t['caron'] = 333;
  15898. t['emdash'] = 1000;
  15899. t['AE'] = 944;
  15900. t['ordfeminine'] = 266;
  15901. t['Lslash'] = 611;
  15902. t['Oslash'] = 722;
  15903. t['OE'] = 944;
  15904. t['ordmasculine'] = 300;
  15905. t['ae'] = 722;
  15906. t['dotlessi'] = 278;
  15907. t['lslash'] = 278;
  15908. t['oslash'] = 500;
  15909. t['oe'] = 722;
  15910. t['germandbls'] = 500;
  15911. t['Idieresis'] = 389;
  15912. t['eacute'] = 444;
  15913. t['abreve'] = 500;
  15914. t['uhungarumlaut'] = 556;
  15915. t['ecaron'] = 444;
  15916. t['Ydieresis'] = 611;
  15917. t['divide'] = 570;
  15918. t['Yacute'] = 611;
  15919. t['Acircumflex'] = 667;
  15920. t['aacute'] = 500;
  15921. t['Ucircumflex'] = 722;
  15922. t['yacute'] = 444;
  15923. t['scommaaccent'] = 389;
  15924. t['ecircumflex'] = 444;
  15925. t['Uring'] = 722;
  15926. t['Udieresis'] = 722;
  15927. t['aogonek'] = 500;
  15928. t['Uacute'] = 722;
  15929. t['uogonek'] = 556;
  15930. t['Edieresis'] = 667;
  15931. t['Dcroat'] = 722;
  15932. t['commaaccent'] = 250;
  15933. t['copyright'] = 747;
  15934. t['Emacron'] = 667;
  15935. t['ccaron'] = 444;
  15936. t['aring'] = 500;
  15937. t['Ncommaaccent'] = 722;
  15938. t['lacute'] = 278;
  15939. t['agrave'] = 500;
  15940. t['Tcommaaccent'] = 611;
  15941. t['Cacute'] = 667;
  15942. t['atilde'] = 500;
  15943. t['Edotaccent'] = 667;
  15944. t['scaron'] = 389;
  15945. t['scedilla'] = 389;
  15946. t['iacute'] = 278;
  15947. t['lozenge'] = 494;
  15948. t['Rcaron'] = 667;
  15949. t['Gcommaaccent'] = 722;
  15950. t['ucircumflex'] = 556;
  15951. t['acircumflex'] = 500;
  15952. t['Amacron'] = 667;
  15953. t['rcaron'] = 389;
  15954. t['ccedilla'] = 444;
  15955. t['Zdotaccent'] = 611;
  15956. t['Thorn'] = 611;
  15957. t['Omacron'] = 722;
  15958. t['Racute'] = 667;
  15959. t['Sacute'] = 556;
  15960. t['dcaron'] = 608;
  15961. t['Umacron'] = 722;
  15962. t['uring'] = 556;
  15963. t['threesuperior'] = 300;
  15964. t['Ograve'] = 722;
  15965. t['Agrave'] = 667;
  15966. t['Abreve'] = 667;
  15967. t['multiply'] = 570;
  15968. t['uacute'] = 556;
  15969. t['Tcaron'] = 611;
  15970. t['partialdiff'] = 494;
  15971. t['ydieresis'] = 444;
  15972. t['Nacute'] = 722;
  15973. t['icircumflex'] = 278;
  15974. t['Ecircumflex'] = 667;
  15975. t['adieresis'] = 500;
  15976. t['edieresis'] = 444;
  15977. t['cacute'] = 444;
  15978. t['nacute'] = 556;
  15979. t['umacron'] = 556;
  15980. t['Ncaron'] = 722;
  15981. t['Iacute'] = 389;
  15982. t['plusminus'] = 570;
  15983. t['brokenbar'] = 220;
  15984. t['registered'] = 747;
  15985. t['Gbreve'] = 722;
  15986. t['Idotaccent'] = 389;
  15987. t['summation'] = 600;
  15988. t['Egrave'] = 667;
  15989. t['racute'] = 389;
  15990. t['omacron'] = 500;
  15991. t['Zacute'] = 611;
  15992. t['Zcaron'] = 611;
  15993. t['greaterequal'] = 549;
  15994. t['Eth'] = 722;
  15995. t['Ccedilla'] = 667;
  15996. t['lcommaaccent'] = 278;
  15997. t['tcaron'] = 366;
  15998. t['eogonek'] = 444;
  15999. t['Uogonek'] = 722;
  16000. t['Aacute'] = 667;
  16001. t['Adieresis'] = 667;
  16002. t['egrave'] = 444;
  16003. t['zacute'] = 389;
  16004. t['iogonek'] = 278;
  16005. t['Oacute'] = 722;
  16006. t['oacute'] = 500;
  16007. t['amacron'] = 500;
  16008. t['sacute'] = 389;
  16009. t['idieresis'] = 278;
  16010. t['Ocircumflex'] = 722;
  16011. t['Ugrave'] = 722;
  16012. t['Delta'] = 612;
  16013. t['thorn'] = 500;
  16014. t['twosuperior'] = 300;
  16015. t['Odieresis'] = 722;
  16016. t['mu'] = 576;
  16017. t['igrave'] = 278;
  16018. t['ohungarumlaut'] = 500;
  16019. t['Eogonek'] = 667;
  16020. t['dcroat'] = 500;
  16021. t['threequarters'] = 750;
  16022. t['Scedilla'] = 556;
  16023. t['lcaron'] = 382;
  16024. t['Kcommaaccent'] = 667;
  16025. t['Lacute'] = 611;
  16026. t['trademark'] = 1000;
  16027. t['edotaccent'] = 444;
  16028. t['Igrave'] = 389;
  16029. t['Imacron'] = 389;
  16030. t['Lcaron'] = 611;
  16031. t['onehalf'] = 750;
  16032. t['lessequal'] = 549;
  16033. t['ocircumflex'] = 500;
  16034. t['ntilde'] = 556;
  16035. t['Uhungarumlaut'] = 722;
  16036. t['Eacute'] = 667;
  16037. t['emacron'] = 444;
  16038. t['gbreve'] = 500;
  16039. t['onequarter'] = 750;
  16040. t['Scaron'] = 556;
  16041. t['Scommaaccent'] = 556;
  16042. t['Ohungarumlaut'] = 722;
  16043. t['degree'] = 400;
  16044. t['ograve'] = 500;
  16045. t['Ccaron'] = 667;
  16046. t['ugrave'] = 556;
  16047. t['radical'] = 549;
  16048. t['Dcaron'] = 722;
  16049. t['rcommaaccent'] = 389;
  16050. t['Ntilde'] = 722;
  16051. t['otilde'] = 500;
  16052. t['Rcommaaccent'] = 667;
  16053. t['Lcommaaccent'] = 611;
  16054. t['Atilde'] = 667;
  16055. t['Aogonek'] = 667;
  16056. t['Aring'] = 667;
  16057. t['Otilde'] = 722;
  16058. t['zdotaccent'] = 389;
  16059. t['Ecaron'] = 667;
  16060. t['Iogonek'] = 389;
  16061. t['kcommaaccent'] = 500;
  16062. t['minus'] = 606;
  16063. t['Icircumflex'] = 389;
  16064. t['ncaron'] = 556;
  16065. t['tcommaaccent'] = 278;
  16066. t['logicalnot'] = 606;
  16067. t['odieresis'] = 500;
  16068. t['udieresis'] = 556;
  16069. t['notequal'] = 549;
  16070. t['gcommaaccent'] = 500;
  16071. t['eth'] = 500;
  16072. t['zcaron'] = 389;
  16073. t['ncommaaccent'] = 556;
  16074. t['onesuperior'] = 300;
  16075. t['imacron'] = 278;
  16076. t['Euro'] = 500;
  16077. });
  16078. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16079. t['space'] = 250;
  16080. t['exclam'] = 333;
  16081. t['quotedbl'] = 420;
  16082. t['numbersign'] = 500;
  16083. t['dollar'] = 500;
  16084. t['percent'] = 833;
  16085. t['ampersand'] = 778;
  16086. t['quoteright'] = 333;
  16087. t['parenleft'] = 333;
  16088. t['parenright'] = 333;
  16089. t['asterisk'] = 500;
  16090. t['plus'] = 675;
  16091. t['comma'] = 250;
  16092. t['hyphen'] = 333;
  16093. t['period'] = 250;
  16094. t['slash'] = 278;
  16095. t['zero'] = 500;
  16096. t['one'] = 500;
  16097. t['two'] = 500;
  16098. t['three'] = 500;
  16099. t['four'] = 500;
  16100. t['five'] = 500;
  16101. t['six'] = 500;
  16102. t['seven'] = 500;
  16103. t['eight'] = 500;
  16104. t['nine'] = 500;
  16105. t['colon'] = 333;
  16106. t['semicolon'] = 333;
  16107. t['less'] = 675;
  16108. t['equal'] = 675;
  16109. t['greater'] = 675;
  16110. t['question'] = 500;
  16111. t['at'] = 920;
  16112. t['A'] = 611;
  16113. t['B'] = 611;
  16114. t['C'] = 667;
  16115. t['D'] = 722;
  16116. t['E'] = 611;
  16117. t['F'] = 611;
  16118. t['G'] = 722;
  16119. t['H'] = 722;
  16120. t['I'] = 333;
  16121. t['J'] = 444;
  16122. t['K'] = 667;
  16123. t['L'] = 556;
  16124. t['M'] = 833;
  16125. t['N'] = 667;
  16126. t['O'] = 722;
  16127. t['P'] = 611;
  16128. t['Q'] = 722;
  16129. t['R'] = 611;
  16130. t['S'] = 500;
  16131. t['T'] = 556;
  16132. t['U'] = 722;
  16133. t['V'] = 611;
  16134. t['W'] = 833;
  16135. t['X'] = 611;
  16136. t['Y'] = 556;
  16137. t['Z'] = 556;
  16138. t['bracketleft'] = 389;
  16139. t['backslash'] = 278;
  16140. t['bracketright'] = 389;
  16141. t['asciicircum'] = 422;
  16142. t['underscore'] = 500;
  16143. t['quoteleft'] = 333;
  16144. t['a'] = 500;
  16145. t['b'] = 500;
  16146. t['c'] = 444;
  16147. t['d'] = 500;
  16148. t['e'] = 444;
  16149. t['f'] = 278;
  16150. t['g'] = 500;
  16151. t['h'] = 500;
  16152. t['i'] = 278;
  16153. t['j'] = 278;
  16154. t['k'] = 444;
  16155. t['l'] = 278;
  16156. t['m'] = 722;
  16157. t['n'] = 500;
  16158. t['o'] = 500;
  16159. t['p'] = 500;
  16160. t['q'] = 500;
  16161. t['r'] = 389;
  16162. t['s'] = 389;
  16163. t['t'] = 278;
  16164. t['u'] = 500;
  16165. t['v'] = 444;
  16166. t['w'] = 667;
  16167. t['x'] = 444;
  16168. t['y'] = 444;
  16169. t['z'] = 389;
  16170. t['braceleft'] = 400;
  16171. t['bar'] = 275;
  16172. t['braceright'] = 400;
  16173. t['asciitilde'] = 541;
  16174. t['exclamdown'] = 389;
  16175. t['cent'] = 500;
  16176. t['sterling'] = 500;
  16177. t['fraction'] = 167;
  16178. t['yen'] = 500;
  16179. t['florin'] = 500;
  16180. t['section'] = 500;
  16181. t['currency'] = 500;
  16182. t['quotesingle'] = 214;
  16183. t['quotedblleft'] = 556;
  16184. t['guillemotleft'] = 500;
  16185. t['guilsinglleft'] = 333;
  16186. t['guilsinglright'] = 333;
  16187. t['fi'] = 500;
  16188. t['fl'] = 500;
  16189. t['endash'] = 500;
  16190. t['dagger'] = 500;
  16191. t['daggerdbl'] = 500;
  16192. t['periodcentered'] = 250;
  16193. t['paragraph'] = 523;
  16194. t['bullet'] = 350;
  16195. t['quotesinglbase'] = 333;
  16196. t['quotedblbase'] = 556;
  16197. t['quotedblright'] = 556;
  16198. t['guillemotright'] = 500;
  16199. t['ellipsis'] = 889;
  16200. t['perthousand'] = 1000;
  16201. t['questiondown'] = 500;
  16202. t['grave'] = 333;
  16203. t['acute'] = 333;
  16204. t['circumflex'] = 333;
  16205. t['tilde'] = 333;
  16206. t['macron'] = 333;
  16207. t['breve'] = 333;
  16208. t['dotaccent'] = 333;
  16209. t['dieresis'] = 333;
  16210. t['ring'] = 333;
  16211. t['cedilla'] = 333;
  16212. t['hungarumlaut'] = 333;
  16213. t['ogonek'] = 333;
  16214. t['caron'] = 333;
  16215. t['emdash'] = 889;
  16216. t['AE'] = 889;
  16217. t['ordfeminine'] = 276;
  16218. t['Lslash'] = 556;
  16219. t['Oslash'] = 722;
  16220. t['OE'] = 944;
  16221. t['ordmasculine'] = 310;
  16222. t['ae'] = 667;
  16223. t['dotlessi'] = 278;
  16224. t['lslash'] = 278;
  16225. t['oslash'] = 500;
  16226. t['oe'] = 667;
  16227. t['germandbls'] = 500;
  16228. t['Idieresis'] = 333;
  16229. t['eacute'] = 444;
  16230. t['abreve'] = 500;
  16231. t['uhungarumlaut'] = 500;
  16232. t['ecaron'] = 444;
  16233. t['Ydieresis'] = 556;
  16234. t['divide'] = 675;
  16235. t['Yacute'] = 556;
  16236. t['Acircumflex'] = 611;
  16237. t['aacute'] = 500;
  16238. t['Ucircumflex'] = 722;
  16239. t['yacute'] = 444;
  16240. t['scommaaccent'] = 389;
  16241. t['ecircumflex'] = 444;
  16242. t['Uring'] = 722;
  16243. t['Udieresis'] = 722;
  16244. t['aogonek'] = 500;
  16245. t['Uacute'] = 722;
  16246. t['uogonek'] = 500;
  16247. t['Edieresis'] = 611;
  16248. t['Dcroat'] = 722;
  16249. t['commaaccent'] = 250;
  16250. t['copyright'] = 760;
  16251. t['Emacron'] = 611;
  16252. t['ccaron'] = 444;
  16253. t['aring'] = 500;
  16254. t['Ncommaaccent'] = 667;
  16255. t['lacute'] = 278;
  16256. t['agrave'] = 500;
  16257. t['Tcommaaccent'] = 556;
  16258. t['Cacute'] = 667;
  16259. t['atilde'] = 500;
  16260. t['Edotaccent'] = 611;
  16261. t['scaron'] = 389;
  16262. t['scedilla'] = 389;
  16263. t['iacute'] = 278;
  16264. t['lozenge'] = 471;
  16265. t['Rcaron'] = 611;
  16266. t['Gcommaaccent'] = 722;
  16267. t['ucircumflex'] = 500;
  16268. t['acircumflex'] = 500;
  16269. t['Amacron'] = 611;
  16270. t['rcaron'] = 389;
  16271. t['ccedilla'] = 444;
  16272. t['Zdotaccent'] = 556;
  16273. t['Thorn'] = 611;
  16274. t['Omacron'] = 722;
  16275. t['Racute'] = 611;
  16276. t['Sacute'] = 500;
  16277. t['dcaron'] = 544;
  16278. t['Umacron'] = 722;
  16279. t['uring'] = 500;
  16280. t['threesuperior'] = 300;
  16281. t['Ograve'] = 722;
  16282. t['Agrave'] = 611;
  16283. t['Abreve'] = 611;
  16284. t['multiply'] = 675;
  16285. t['uacute'] = 500;
  16286. t['Tcaron'] = 556;
  16287. t['partialdiff'] = 476;
  16288. t['ydieresis'] = 444;
  16289. t['Nacute'] = 667;
  16290. t['icircumflex'] = 278;
  16291. t['Ecircumflex'] = 611;
  16292. t['adieresis'] = 500;
  16293. t['edieresis'] = 444;
  16294. t['cacute'] = 444;
  16295. t['nacute'] = 500;
  16296. t['umacron'] = 500;
  16297. t['Ncaron'] = 667;
  16298. t['Iacute'] = 333;
  16299. t['plusminus'] = 675;
  16300. t['brokenbar'] = 275;
  16301. t['registered'] = 760;
  16302. t['Gbreve'] = 722;
  16303. t['Idotaccent'] = 333;
  16304. t['summation'] = 600;
  16305. t['Egrave'] = 611;
  16306. t['racute'] = 389;
  16307. t['omacron'] = 500;
  16308. t['Zacute'] = 556;
  16309. t['Zcaron'] = 556;
  16310. t['greaterequal'] = 549;
  16311. t['Eth'] = 722;
  16312. t['Ccedilla'] = 667;
  16313. t['lcommaaccent'] = 278;
  16314. t['tcaron'] = 300;
  16315. t['eogonek'] = 444;
  16316. t['Uogonek'] = 722;
  16317. t['Aacute'] = 611;
  16318. t['Adieresis'] = 611;
  16319. t['egrave'] = 444;
  16320. t['zacute'] = 389;
  16321. t['iogonek'] = 278;
  16322. t['Oacute'] = 722;
  16323. t['oacute'] = 500;
  16324. t['amacron'] = 500;
  16325. t['sacute'] = 389;
  16326. t['idieresis'] = 278;
  16327. t['Ocircumflex'] = 722;
  16328. t['Ugrave'] = 722;
  16329. t['Delta'] = 612;
  16330. t['thorn'] = 500;
  16331. t['twosuperior'] = 300;
  16332. t['Odieresis'] = 722;
  16333. t['mu'] = 500;
  16334. t['igrave'] = 278;
  16335. t['ohungarumlaut'] = 500;
  16336. t['Eogonek'] = 611;
  16337. t['dcroat'] = 500;
  16338. t['threequarters'] = 750;
  16339. t['Scedilla'] = 500;
  16340. t['lcaron'] = 300;
  16341. t['Kcommaaccent'] = 667;
  16342. t['Lacute'] = 556;
  16343. t['trademark'] = 980;
  16344. t['edotaccent'] = 444;
  16345. t['Igrave'] = 333;
  16346. t['Imacron'] = 333;
  16347. t['Lcaron'] = 611;
  16348. t['onehalf'] = 750;
  16349. t['lessequal'] = 549;
  16350. t['ocircumflex'] = 500;
  16351. t['ntilde'] = 500;
  16352. t['Uhungarumlaut'] = 722;
  16353. t['Eacute'] = 611;
  16354. t['emacron'] = 444;
  16355. t['gbreve'] = 500;
  16356. t['onequarter'] = 750;
  16357. t['Scaron'] = 500;
  16358. t['Scommaaccent'] = 500;
  16359. t['Ohungarumlaut'] = 722;
  16360. t['degree'] = 400;
  16361. t['ograve'] = 500;
  16362. t['Ccaron'] = 667;
  16363. t['ugrave'] = 500;
  16364. t['radical'] = 453;
  16365. t['Dcaron'] = 722;
  16366. t['rcommaaccent'] = 389;
  16367. t['Ntilde'] = 667;
  16368. t['otilde'] = 500;
  16369. t['Rcommaaccent'] = 611;
  16370. t['Lcommaaccent'] = 556;
  16371. t['Atilde'] = 611;
  16372. t['Aogonek'] = 611;
  16373. t['Aring'] = 611;
  16374. t['Otilde'] = 722;
  16375. t['zdotaccent'] = 389;
  16376. t['Ecaron'] = 611;
  16377. t['Iogonek'] = 333;
  16378. t['kcommaaccent'] = 444;
  16379. t['minus'] = 675;
  16380. t['Icircumflex'] = 333;
  16381. t['ncaron'] = 500;
  16382. t['tcommaaccent'] = 278;
  16383. t['logicalnot'] = 675;
  16384. t['odieresis'] = 500;
  16385. t['udieresis'] = 500;
  16386. t['notequal'] = 549;
  16387. t['gcommaaccent'] = 500;
  16388. t['eth'] = 500;
  16389. t['zcaron'] = 389;
  16390. t['ncommaaccent'] = 500;
  16391. t['onesuperior'] = 300;
  16392. t['imacron'] = 278;
  16393. t['Euro'] = 500;
  16394. });
  16395. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16396. t['space'] = 278;
  16397. t['a1'] = 974;
  16398. t['a2'] = 961;
  16399. t['a202'] = 974;
  16400. t['a3'] = 980;
  16401. t['a4'] = 719;
  16402. t['a5'] = 789;
  16403. t['a119'] = 790;
  16404. t['a118'] = 791;
  16405. t['a117'] = 690;
  16406. t['a11'] = 960;
  16407. t['a12'] = 939;
  16408. t['a13'] = 549;
  16409. t['a14'] = 855;
  16410. t['a15'] = 911;
  16411. t['a16'] = 933;
  16412. t['a105'] = 911;
  16413. t['a17'] = 945;
  16414. t['a18'] = 974;
  16415. t['a19'] = 755;
  16416. t['a20'] = 846;
  16417. t['a21'] = 762;
  16418. t['a22'] = 761;
  16419. t['a23'] = 571;
  16420. t['a24'] = 677;
  16421. t['a25'] = 763;
  16422. t['a26'] = 760;
  16423. t['a27'] = 759;
  16424. t['a28'] = 754;
  16425. t['a6'] = 494;
  16426. t['a7'] = 552;
  16427. t['a8'] = 537;
  16428. t['a9'] = 577;
  16429. t['a10'] = 692;
  16430. t['a29'] = 786;
  16431. t['a30'] = 788;
  16432. t['a31'] = 788;
  16433. t['a32'] = 790;
  16434. t['a33'] = 793;
  16435. t['a34'] = 794;
  16436. t['a35'] = 816;
  16437. t['a36'] = 823;
  16438. t['a37'] = 789;
  16439. t['a38'] = 841;
  16440. t['a39'] = 823;
  16441. t['a40'] = 833;
  16442. t['a41'] = 816;
  16443. t['a42'] = 831;
  16444. t['a43'] = 923;
  16445. t['a44'] = 744;
  16446. t['a45'] = 723;
  16447. t['a46'] = 749;
  16448. t['a47'] = 790;
  16449. t['a48'] = 792;
  16450. t['a49'] = 695;
  16451. t['a50'] = 776;
  16452. t['a51'] = 768;
  16453. t['a52'] = 792;
  16454. t['a53'] = 759;
  16455. t['a54'] = 707;
  16456. t['a55'] = 708;
  16457. t['a56'] = 682;
  16458. t['a57'] = 701;
  16459. t['a58'] = 826;
  16460. t['a59'] = 815;
  16461. t['a60'] = 789;
  16462. t['a61'] = 789;
  16463. t['a62'] = 707;
  16464. t['a63'] = 687;
  16465. t['a64'] = 696;
  16466. t['a65'] = 689;
  16467. t['a66'] = 786;
  16468. t['a67'] = 787;
  16469. t['a68'] = 713;
  16470. t['a69'] = 791;
  16471. t['a70'] = 785;
  16472. t['a71'] = 791;
  16473. t['a72'] = 873;
  16474. t['a73'] = 761;
  16475. t['a74'] = 762;
  16476. t['a203'] = 762;
  16477. t['a75'] = 759;
  16478. t['a204'] = 759;
  16479. t['a76'] = 892;
  16480. t['a77'] = 892;
  16481. t['a78'] = 788;
  16482. t['a79'] = 784;
  16483. t['a81'] = 438;
  16484. t['a82'] = 138;
  16485. t['a83'] = 277;
  16486. t['a84'] = 415;
  16487. t['a97'] = 392;
  16488. t['a98'] = 392;
  16489. t['a99'] = 668;
  16490. t['a100'] = 668;
  16491. t['a89'] = 390;
  16492. t['a90'] = 390;
  16493. t['a93'] = 317;
  16494. t['a94'] = 317;
  16495. t['a91'] = 276;
  16496. t['a92'] = 276;
  16497. t['a205'] = 509;
  16498. t['a85'] = 509;
  16499. t['a206'] = 410;
  16500. t['a86'] = 410;
  16501. t['a87'] = 234;
  16502. t['a88'] = 234;
  16503. t['a95'] = 334;
  16504. t['a96'] = 334;
  16505. t['a101'] = 732;
  16506. t['a102'] = 544;
  16507. t['a103'] = 544;
  16508. t['a104'] = 910;
  16509. t['a106'] = 667;
  16510. t['a107'] = 760;
  16511. t['a108'] = 760;
  16512. t['a112'] = 776;
  16513. t['a111'] = 595;
  16514. t['a110'] = 694;
  16515. t['a109'] = 626;
  16516. t['a120'] = 788;
  16517. t['a121'] = 788;
  16518. t['a122'] = 788;
  16519. t['a123'] = 788;
  16520. t['a124'] = 788;
  16521. t['a125'] = 788;
  16522. t['a126'] = 788;
  16523. t['a127'] = 788;
  16524. t['a128'] = 788;
  16525. t['a129'] = 788;
  16526. t['a130'] = 788;
  16527. t['a131'] = 788;
  16528. t['a132'] = 788;
  16529. t['a133'] = 788;
  16530. t['a134'] = 788;
  16531. t['a135'] = 788;
  16532. t['a136'] = 788;
  16533. t['a137'] = 788;
  16534. t['a138'] = 788;
  16535. t['a139'] = 788;
  16536. t['a140'] = 788;
  16537. t['a141'] = 788;
  16538. t['a142'] = 788;
  16539. t['a143'] = 788;
  16540. t['a144'] = 788;
  16541. t['a145'] = 788;
  16542. t['a146'] = 788;
  16543. t['a147'] = 788;
  16544. t['a148'] = 788;
  16545. t['a149'] = 788;
  16546. t['a150'] = 788;
  16547. t['a151'] = 788;
  16548. t['a152'] = 788;
  16549. t['a153'] = 788;
  16550. t['a154'] = 788;
  16551. t['a155'] = 788;
  16552. t['a156'] = 788;
  16553. t['a157'] = 788;
  16554. t['a158'] = 788;
  16555. t['a159'] = 788;
  16556. t['a160'] = 894;
  16557. t['a161'] = 838;
  16558. t['a163'] = 1016;
  16559. t['a164'] = 458;
  16560. t['a196'] = 748;
  16561. t['a165'] = 924;
  16562. t['a192'] = 748;
  16563. t['a166'] = 918;
  16564. t['a167'] = 927;
  16565. t['a168'] = 928;
  16566. t['a169'] = 928;
  16567. t['a170'] = 834;
  16568. t['a171'] = 873;
  16569. t['a172'] = 828;
  16570. t['a173'] = 924;
  16571. t['a162'] = 924;
  16572. t['a174'] = 917;
  16573. t['a175'] = 930;
  16574. t['a176'] = 931;
  16575. t['a177'] = 463;
  16576. t['a178'] = 883;
  16577. t['a179'] = 836;
  16578. t['a193'] = 836;
  16579. t['a180'] = 867;
  16580. t['a199'] = 867;
  16581. t['a181'] = 696;
  16582. t['a200'] = 696;
  16583. t['a182'] = 874;
  16584. t['a201'] = 874;
  16585. t['a183'] = 760;
  16586. t['a184'] = 946;
  16587. t['a197'] = 771;
  16588. t['a185'] = 865;
  16589. t['a194'] = 771;
  16590. t['a198'] = 888;
  16591. t['a186'] = 967;
  16592. t['a195'] = 888;
  16593. t['a187'] = 831;
  16594. t['a188'] = 873;
  16595. t['a189'] = 927;
  16596. t['a190'] = 970;
  16597. t['a191'] = 918;
  16598. });
  16599. });
  16600. exports.getMetrics = getMetrics;
  16601. }));
  16602. (function (root, factory) {
  16603. {
  16604. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16605. }
  16606. }(this, function (exports, sharedUtil) {
  16607. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16608. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16609. // Workaround for missing math precision in JS.
  16610. var MASK_HIGH = 0xffff0000;
  16611. var MASK_LOW = 0xffff;
  16612. function MurmurHash3_64 (seed) {
  16613. var SEED = 0xc3d2e1f0;
  16614. this.h1 = seed ? seed & 0xffffffff : SEED;
  16615. this.h2 = seed ? seed & 0xffffffff : SEED;
  16616. }
  16617. var alwaysUseUint32ArrayView = false;
  16618. // old webkits have issues with non-aligned arrays
  16619. try {
  16620. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16621. } catch (e) {
  16622. alwaysUseUint32ArrayView = true;
  16623. }
  16624. MurmurHash3_64.prototype = {
  16625. update: function MurmurHash3_64_update(input) {
  16626. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16627. var i;
  16628. if (typeof input === 'string') {
  16629. var data = new Uint8Array(input.length * 2);
  16630. var length = 0;
  16631. for (i = 0; i < input.length; i++) {
  16632. var code = input.charCodeAt(i);
  16633. if (code <= 0xff) {
  16634. data[length++] = code;
  16635. }
  16636. else {
  16637. data[length++] = code >>> 8;
  16638. data[length++] = code & 0xff;
  16639. }
  16640. }
  16641. } else if (input instanceof Uint8Array) {
  16642. data = input;
  16643. length = data.length;
  16644. } else if (typeof input === 'object' && ('length' in input)) {
  16645. // processing regular arrays as well, e.g. for IE9
  16646. data = input;
  16647. length = data.length;
  16648. useUint32ArrayView = true;
  16649. } else {
  16650. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16651. 'Input must be a string or array.');
  16652. }
  16653. var blockCounts = length >> 2;
  16654. var tailLength = length - blockCounts * 4;
  16655. // we don't care about endianness here
  16656. var dataUint32 = useUint32ArrayView ?
  16657. new Uint32ArrayView(data, blockCounts) :
  16658. new Uint32Array(data.buffer, 0, blockCounts);
  16659. var k1 = 0;
  16660. var k2 = 0;
  16661. var h1 = this.h1;
  16662. var h2 = this.h2;
  16663. var C1 = 0xcc9e2d51;
  16664. var C2 = 0x1b873593;
  16665. var C1_LOW = C1 & MASK_LOW;
  16666. var C2_LOW = C2 & MASK_LOW;
  16667. for (i = 0; i < blockCounts; i++) {
  16668. if (i & 1) {
  16669. k1 = dataUint32[i];
  16670. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16671. k1 = k1 << 15 | k1 >>> 17;
  16672. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16673. h1 ^= k1;
  16674. h1 = h1 << 13 | h1 >>> 19;
  16675. h1 = h1 * 5 + 0xe6546b64;
  16676. } else {
  16677. k2 = dataUint32[i];
  16678. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16679. k2 = k2 << 15 | k2 >>> 17;
  16680. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16681. h2 ^= k2;
  16682. h2 = h2 << 13 | h2 >>> 19;
  16683. h2 = h2 * 5 + 0xe6546b64;
  16684. }
  16685. }
  16686. k1 = 0;
  16687. switch (tailLength) {
  16688. case 3:
  16689. k1 ^= data[blockCounts * 4 + 2] << 16;
  16690. /* falls through */
  16691. case 2:
  16692. k1 ^= data[blockCounts * 4 + 1] << 8;
  16693. /* falls through */
  16694. case 1:
  16695. k1 ^= data[blockCounts * 4];
  16696. /* falls through */
  16697. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16698. k1 = k1 << 15 | k1 >>> 17;
  16699. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16700. if (blockCounts & 1) {
  16701. h1 ^= k1;
  16702. } else {
  16703. h2 ^= k1;
  16704. }
  16705. }
  16706. this.h1 = h1;
  16707. this.h2 = h2;
  16708. return this;
  16709. },
  16710. hexdigest: function MurmurHash3_64_hexdigest () {
  16711. var h1 = this.h1;
  16712. var h2 = this.h2;
  16713. h1 ^= h2 >>> 1;
  16714. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16715. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16716. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16717. h1 ^= h2 >>> 1;
  16718. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16719. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16720. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16721. h1 ^= h2 >>> 1;
  16722. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16723. var hex = (arr[i] >>> 0).toString(16);
  16724. while (hex.length < 8) {
  16725. hex = '0' + hex;
  16726. }
  16727. str += hex;
  16728. }
  16729. return str;
  16730. }
  16731. };
  16732. return MurmurHash3_64;
  16733. })();
  16734. exports.MurmurHash3_64 = MurmurHash3_64;
  16735. }));
  16736. (function (root, factory) {
  16737. {
  16738. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16739. }
  16740. }(this, function (exports, sharedUtil) {
  16741. var isArray = sharedUtil.isArray;
  16742. var Name = (function NameClosure() {
  16743. function Name(name) {
  16744. this.name = name;
  16745. }
  16746. Name.prototype = {};
  16747. var nameCache = Object.create(null);
  16748. Name.get = function Name_get(name) {
  16749. var nameValue = nameCache[name];
  16750. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16751. };
  16752. return Name;
  16753. })();
  16754. var Cmd = (function CmdClosure() {
  16755. function Cmd(cmd) {
  16756. this.cmd = cmd;
  16757. }
  16758. Cmd.prototype = {};
  16759. var cmdCache = Object.create(null);
  16760. Cmd.get = function Cmd_get(cmd) {
  16761. var cmdValue = cmdCache[cmd];
  16762. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16763. };
  16764. return Cmd;
  16765. })();
  16766. var Dict = (function DictClosure() {
  16767. var nonSerializable = function nonSerializableClosure() {
  16768. return nonSerializable; // creating closure on some variable
  16769. };
  16770. // xref is optional
  16771. function Dict(xref) {
  16772. // Map should only be used internally, use functions below to access.
  16773. this.map = Object.create(null);
  16774. this.xref = xref;
  16775. this.objId = null;
  16776. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16777. }
  16778. Dict.prototype = {
  16779. assignXref: function Dict_assignXref(newXref) {
  16780. this.xref = newXref;
  16781. },
  16782. // automatically dereferences Ref objects
  16783. get: function Dict_get(key1, key2, key3) {
  16784. var value;
  16785. var xref = this.xref;
  16786. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16787. typeof key2 === 'undefined') {
  16788. return xref ? xref.fetchIfRef(value) : value;
  16789. }
  16790. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16791. typeof key3 === 'undefined') {
  16792. return xref ? xref.fetchIfRef(value) : value;
  16793. }
  16794. value = this.map[key3] || null;
  16795. return xref ? xref.fetchIfRef(value) : value;
  16796. },
  16797. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16798. getAsync: function Dict_getAsync(key1, key2, key3) {
  16799. var value;
  16800. var xref = this.xref;
  16801. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16802. typeof key2 === 'undefined') {
  16803. if (xref) {
  16804. return xref.fetchIfRefAsync(value);
  16805. }
  16806. return Promise.resolve(value);
  16807. }
  16808. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16809. typeof key3 === 'undefined') {
  16810. if (xref) {
  16811. return xref.fetchIfRefAsync(value);
  16812. }
  16813. return Promise.resolve(value);
  16814. }
  16815. value = this.map[key3] || null;
  16816. if (xref) {
  16817. return xref.fetchIfRefAsync(value);
  16818. }
  16819. return Promise.resolve(value);
  16820. },
  16821. // Same as get(), but dereferences all elements if the result is an Array.
  16822. getArray: function Dict_getArray(key1, key2, key3) {
  16823. var value = this.get(key1, key2, key3);
  16824. var xref = this.xref;
  16825. if (!isArray(value) || !xref) {
  16826. return value;
  16827. }
  16828. value = value.slice(); // Ensure that we don't modify the Dict data.
  16829. for (var i = 0, ii = value.length; i < ii; i++) {
  16830. if (!isRef(value[i])) {
  16831. continue;
  16832. }
  16833. value[i] = xref.fetch(value[i]);
  16834. }
  16835. return value;
  16836. },
  16837. // no dereferencing
  16838. getRaw: function Dict_getRaw(key) {
  16839. return this.map[key];
  16840. },
  16841. getKeys: function Dict_getKeys() {
  16842. return Object.keys(this.map);
  16843. },
  16844. set: function Dict_set(key, value) {
  16845. this.map[key] = value;
  16846. },
  16847. has: function Dict_has(key) {
  16848. return key in this.map;
  16849. },
  16850. forEach: function Dict_forEach(callback) {
  16851. for (var key in this.map) {
  16852. callback(key, this.get(key));
  16853. }
  16854. }
  16855. };
  16856. Dict.empty = new Dict(null);
  16857. Dict.merge = function Dict_merge(xref, dictArray) {
  16858. var mergedDict = new Dict(xref);
  16859. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16860. var dict = dictArray[i];
  16861. if (!isDict(dict)) {
  16862. continue;
  16863. }
  16864. for (var keyName in dict.map) {
  16865. if (mergedDict.map[keyName]) {
  16866. continue;
  16867. }
  16868. mergedDict.map[keyName] = dict.map[keyName];
  16869. }
  16870. }
  16871. return mergedDict;
  16872. };
  16873. return Dict;
  16874. })();
  16875. var Ref = (function RefClosure() {
  16876. function Ref(num, gen) {
  16877. this.num = num;
  16878. this.gen = gen;
  16879. }
  16880. Ref.prototype = {
  16881. toString: function Ref_toString() {
  16882. // This function is hot, so we make the string as compact as possible.
  16883. // |this.gen| is almost always zero, so we treat that case specially.
  16884. var str = this.num + 'R';
  16885. if (this.gen !== 0) {
  16886. str += this.gen;
  16887. }
  16888. return str;
  16889. }
  16890. };
  16891. return Ref;
  16892. })();
  16893. // The reference is identified by number and generation.
  16894. // This structure stores only one instance of the reference.
  16895. var RefSet = (function RefSetClosure() {
  16896. function RefSet() {
  16897. this.dict = Object.create(null);
  16898. }
  16899. RefSet.prototype = {
  16900. has: function RefSet_has(ref) {
  16901. return ref.toString() in this.dict;
  16902. },
  16903. put: function RefSet_put(ref) {
  16904. this.dict[ref.toString()] = true;
  16905. },
  16906. remove: function RefSet_remove(ref) {
  16907. delete this.dict[ref.toString()];
  16908. }
  16909. };
  16910. return RefSet;
  16911. })();
  16912. var RefSetCache = (function RefSetCacheClosure() {
  16913. function RefSetCache() {
  16914. this.dict = Object.create(null);
  16915. }
  16916. RefSetCache.prototype = {
  16917. get: function RefSetCache_get(ref) {
  16918. return this.dict[ref.toString()];
  16919. },
  16920. has: function RefSetCache_has(ref) {
  16921. return ref.toString() in this.dict;
  16922. },
  16923. put: function RefSetCache_put(ref, obj) {
  16924. this.dict[ref.toString()] = obj;
  16925. },
  16926. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16927. this.dict[ref.toString()] = this.get(aliasRef);
  16928. },
  16929. forEach: function RefSetCache_forEach(fn, thisArg) {
  16930. for (var i in this.dict) {
  16931. fn.call(thisArg, this.dict[i]);
  16932. }
  16933. },
  16934. clear: function RefSetCache_clear() {
  16935. this.dict = Object.create(null);
  16936. }
  16937. };
  16938. return RefSetCache;
  16939. })();
  16940. function isName(v, name) {
  16941. return v instanceof Name && (name === undefined || v.name === name);
  16942. }
  16943. function isCmd(v, cmd) {
  16944. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16945. }
  16946. function isDict(v, type) {
  16947. return v instanceof Dict &&
  16948. (type === undefined || isName(v.get('Type'), type));
  16949. }
  16950. function isRef(v) {
  16951. return v instanceof Ref;
  16952. }
  16953. function isRefsEqual(v1, v2) {
  16954. return v1.num === v2.num && v1.gen === v2.gen;
  16955. }
  16956. function isStream(v) {
  16957. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  16958. }
  16959. exports.Cmd = Cmd;
  16960. exports.Dict = Dict;
  16961. exports.Name = Name;
  16962. exports.Ref = Ref;
  16963. exports.RefSet = RefSet;
  16964. exports.RefSetCache = RefSetCache;
  16965. exports.isCmd = isCmd;
  16966. exports.isDict = isDict;
  16967. exports.isName = isName;
  16968. exports.isRef = isRef;
  16969. exports.isRefsEqual = isRefsEqual;
  16970. exports.isStream = isStream;
  16971. }));
  16972. (function (root, factory) {
  16973. {
  16974. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  16975. }
  16976. }(this, function (exports, sharedUtil) {
  16977. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  16978. /**
  16979. * Hold a map of decoded fonts and of the standard fourteen Type1
  16980. * fonts and their acronyms.
  16981. */
  16982. var getStdFontMap = getLookupTableFactory(function (t) {
  16983. t['ArialNarrow'] = 'Helvetica';
  16984. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  16985. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  16986. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  16987. t['ArialBlack'] = 'Helvetica';
  16988. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  16989. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  16990. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  16991. t['Arial'] = 'Helvetica';
  16992. t['Arial-Bold'] = 'Helvetica-Bold';
  16993. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  16994. t['Arial-Italic'] = 'Helvetica-Oblique';
  16995. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  16996. t['Arial-BoldMT'] = 'Helvetica-Bold';
  16997. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  16998. t['ArialMT'] = 'Helvetica';
  16999. t['Courier-Bold'] = 'Courier-Bold';
  17000. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17001. t['Courier-Italic'] = 'Courier-Oblique';
  17002. t['CourierNew'] = 'Courier';
  17003. t['CourierNew-Bold'] = 'Courier-Bold';
  17004. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17005. t['CourierNew-Italic'] = 'Courier-Oblique';
  17006. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17007. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17008. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17009. t['CourierNewPSMT'] = 'Courier';
  17010. t['Helvetica'] = 'Helvetica';
  17011. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17012. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17013. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17014. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17015. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17016. t['Symbol-Bold'] = 'Symbol';
  17017. t['Symbol-BoldItalic'] = 'Symbol';
  17018. t['Symbol-Italic'] = 'Symbol';
  17019. t['TimesNewRoman'] = 'Times-Roman';
  17020. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17021. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17022. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17023. t['TimesNewRomanPS'] = 'Times-Roman';
  17024. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17025. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17026. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17027. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17028. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17029. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17030. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17031. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17032. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17033. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17034. });
  17035. /**
  17036. * Holds the map of the non-standard fonts that might be included as
  17037. * a standard fonts without glyph data.
  17038. */
  17039. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17040. t['CenturyGothic'] = 'Helvetica';
  17041. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17042. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17043. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17044. t['ComicSansMS'] = 'Comic Sans MS';
  17045. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17046. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17047. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17048. t['LucidaConsole'] = 'Courier';
  17049. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17050. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17051. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17052. t['MS-Gothic'] = 'MS Gothic';
  17053. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17054. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17055. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17056. t['MS-Mincho'] = 'MS Mincho';
  17057. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17058. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17059. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17060. t['MS-PGothic'] = 'MS PGothic';
  17061. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17062. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17063. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17064. t['MS-PMincho'] = 'MS PMincho';
  17065. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17066. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17067. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17068. t['Wingdings'] = 'ZapfDingbats';
  17069. });
  17070. var getSerifFonts = getLookupTableFactory(function (t) {
  17071. t['Adobe Jenson'] = true;
  17072. t['Adobe Text'] = true;
  17073. t['Albertus'] = true;
  17074. t['Aldus'] = true;
  17075. t['Alexandria'] = true;
  17076. t['Algerian'] = true;
  17077. t['American Typewriter'] = true;
  17078. t['Antiqua'] = true;
  17079. t['Apex'] = true;
  17080. t['Arno'] = true;
  17081. t['Aster'] = true;
  17082. t['Aurora'] = true;
  17083. t['Baskerville'] = true;
  17084. t['Bell'] = true;
  17085. t['Bembo'] = true;
  17086. t['Bembo Schoolbook'] = true;
  17087. t['Benguiat'] = true;
  17088. t['Berkeley Old Style'] = true;
  17089. t['Bernhard Modern'] = true;
  17090. t['Berthold City'] = true;
  17091. t['Bodoni'] = true;
  17092. t['Bauer Bodoni'] = true;
  17093. t['Book Antiqua'] = true;
  17094. t['Bookman'] = true;
  17095. t['Bordeaux Roman'] = true;
  17096. t['Californian FB'] = true;
  17097. t['Calisto'] = true;
  17098. t['Calvert'] = true;
  17099. t['Capitals'] = true;
  17100. t['Cambria'] = true;
  17101. t['Cartier'] = true;
  17102. t['Caslon'] = true;
  17103. t['Catull'] = true;
  17104. t['Centaur'] = true;
  17105. t['Century Old Style'] = true;
  17106. t['Century Schoolbook'] = true;
  17107. t['Chaparral'] = true;
  17108. t['Charis SIL'] = true;
  17109. t['Cheltenham'] = true;
  17110. t['Cholla Slab'] = true;
  17111. t['Clarendon'] = true;
  17112. t['Clearface'] = true;
  17113. t['Cochin'] = true;
  17114. t['Colonna'] = true;
  17115. t['Computer Modern'] = true;
  17116. t['Concrete Roman'] = true;
  17117. t['Constantia'] = true;
  17118. t['Cooper Black'] = true;
  17119. t['Corona'] = true;
  17120. t['Ecotype'] = true;
  17121. t['Egyptienne'] = true;
  17122. t['Elephant'] = true;
  17123. t['Excelsior'] = true;
  17124. t['Fairfield'] = true;
  17125. t['FF Scala'] = true;
  17126. t['Folkard'] = true;
  17127. t['Footlight'] = true;
  17128. t['FreeSerif'] = true;
  17129. t['Friz Quadrata'] = true;
  17130. t['Garamond'] = true;
  17131. t['Gentium'] = true;
  17132. t['Georgia'] = true;
  17133. t['Gloucester'] = true;
  17134. t['Goudy Old Style'] = true;
  17135. t['Goudy Schoolbook'] = true;
  17136. t['Goudy Pro Font'] = true;
  17137. t['Granjon'] = true;
  17138. t['Guardian Egyptian'] = true;
  17139. t['Heather'] = true;
  17140. t['Hercules'] = true;
  17141. t['High Tower Text'] = true;
  17142. t['Hiroshige'] = true;
  17143. t['Hoefler Text'] = true;
  17144. t['Humana Serif'] = true;
  17145. t['Imprint'] = true;
  17146. t['Ionic No. 5'] = true;
  17147. t['Janson'] = true;
  17148. t['Joanna'] = true;
  17149. t['Korinna'] = true;
  17150. t['Lexicon'] = true;
  17151. t['Liberation Serif'] = true;
  17152. t['Linux Libertine'] = true;
  17153. t['Literaturnaya'] = true;
  17154. t['Lucida'] = true;
  17155. t['Lucida Bright'] = true;
  17156. t['Melior'] = true;
  17157. t['Memphis'] = true;
  17158. t['Miller'] = true;
  17159. t['Minion'] = true;
  17160. t['Modern'] = true;
  17161. t['Mona Lisa'] = true;
  17162. t['Mrs Eaves'] = true;
  17163. t['MS Serif'] = true;
  17164. t['Museo Slab'] = true;
  17165. t['New York'] = true;
  17166. t['Nimbus Roman'] = true;
  17167. t['NPS Rawlinson Roadway'] = true;
  17168. t['Palatino'] = true;
  17169. t['Perpetua'] = true;
  17170. t['Plantin'] = true;
  17171. t['Plantin Schoolbook'] = true;
  17172. t['Playbill'] = true;
  17173. t['Poor Richard'] = true;
  17174. t['Rawlinson Roadway'] = true;
  17175. t['Renault'] = true;
  17176. t['Requiem'] = true;
  17177. t['Rockwell'] = true;
  17178. t['Roman'] = true;
  17179. t['Rotis Serif'] = true;
  17180. t['Sabon'] = true;
  17181. t['Scala'] = true;
  17182. t['Seagull'] = true;
  17183. t['Sistina'] = true;
  17184. t['Souvenir'] = true;
  17185. t['STIX'] = true;
  17186. t['Stone Informal'] = true;
  17187. t['Stone Serif'] = true;
  17188. t['Sylfaen'] = true;
  17189. t['Times'] = true;
  17190. t['Trajan'] = true;
  17191. t['Trinité'] = true;
  17192. t['Trump Mediaeval'] = true;
  17193. t['Utopia'] = true;
  17194. t['Vale Type'] = true;
  17195. t['Bitstream Vera'] = true;
  17196. t['Vera Serif'] = true;
  17197. t['Versailles'] = true;
  17198. t['Wanted'] = true;
  17199. t['Weiss'] = true;
  17200. t['Wide Latin'] = true;
  17201. t['Windsor'] = true;
  17202. t['XITS'] = true;
  17203. });
  17204. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17205. t['Dingbats'] = true;
  17206. t['Symbol'] = true;
  17207. t['ZapfDingbats'] = true;
  17208. });
  17209. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17210. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17211. // for all glyphs, but common for some set of the standard fonts.
  17212. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17213. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17214. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17215. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17216. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17217. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17218. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17219. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17220. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17221. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17222. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17223. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17224. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17225. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17226. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17227. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17228. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17229. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17230. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17231. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17232. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17233. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17234. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17235. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17236. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17237. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17238. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17239. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17240. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17241. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17242. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17243. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17244. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17245. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17246. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17247. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17248. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17249. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17250. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17251. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17252. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17253. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17254. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17255. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17256. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17257. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17258. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17259. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17260. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17261. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17262. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17263. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17264. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17265. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17266. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17267. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17268. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17269. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17270. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17271. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17272. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17273. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17274. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17275. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17276. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17277. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17278. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17279. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17280. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17281. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17282. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17283. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17284. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17285. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17286. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17287. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17288. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17289. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17290. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17291. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17292. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17293. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17294. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17295. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17296. t[3416] = 8377;
  17297. });
  17298. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17299. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17300. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17301. var getSupplementalGlyphMapForArialBlack =
  17302. getLookupTableFactory(function (t) {
  17303. t[227] = 322; t[264] = 261; t[291] = 346;
  17304. });
  17305. exports.getStdFontMap = getStdFontMap;
  17306. exports.getNonStdFontMap = getNonStdFontMap;
  17307. exports.getSerifFonts = getSerifFonts;
  17308. exports.getSymbolsFonts = getSymbolsFonts;
  17309. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17310. exports.getSupplementalGlyphMapForArialBlack =
  17311. getSupplementalGlyphMapForArialBlack;
  17312. }));
  17313. (function (root, factory) {
  17314. {
  17315. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17316. }
  17317. }(this, function (exports, sharedUtil) {
  17318. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17319. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17320. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17321. // chars to the similar equivalents in the normal characters range.
  17322. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17323. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17324. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17325. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17326. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17327. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17328. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17329. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17330. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17331. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17332. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17333. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17334. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17335. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17336. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17337. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17338. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17339. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17340. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17341. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17342. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17343. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17344. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17345. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17346. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17347. });
  17348. function mapSpecialUnicodeValues(code) {
  17349. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17350. return 0;
  17351. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17352. return (getSpecialPUASymbols()[code] || code);
  17353. }
  17354. return code;
  17355. }
  17356. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17357. var unicode = glyphsUnicodeMap[name];
  17358. if (unicode !== undefined) {
  17359. return unicode;
  17360. }
  17361. if (!name) {
  17362. return -1;
  17363. }
  17364. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17365. if (name[0] === 'u') {
  17366. var nameLen = name.length, hexStr;
  17367. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17368. hexStr = name.substr(3);
  17369. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17370. hexStr = name.substr(1);
  17371. } else {
  17372. return -1;
  17373. }
  17374. // Check for upper-case hexadecimal characters, to avoid false positives.
  17375. if (hexStr === hexStr.toUpperCase()) {
  17376. unicode = parseInt(hexStr, 16);
  17377. if (unicode >= 0) {
  17378. return unicode;
  17379. }
  17380. }
  17381. }
  17382. return -1;
  17383. }
  17384. var UnicodeRanges = [
  17385. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17386. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17387. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17388. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17389. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17390. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17391. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17392. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17393. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17394. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17395. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17396. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17397. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17398. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17399. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17400. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17401. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17402. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17403. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17404. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17405. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17406. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17407. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17408. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17409. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17410. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17411. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17412. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17413. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17414. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17415. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17416. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17417. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17418. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17419. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17420. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17421. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17422. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17423. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17424. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17425. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17426. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17427. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17428. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17429. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17430. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17431. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17432. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17433. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17434. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17435. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17436. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17437. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17438. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17439. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17440. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17441. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17442. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17443. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17444. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17445. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17446. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17447. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17448. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17449. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17450. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17451. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17452. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17453. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17454. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17455. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17456. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17457. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17458. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17459. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17460. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17461. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17462. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17463. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17464. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17465. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17466. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17467. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17468. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17469. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17470. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17471. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17472. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17473. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17474. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17475. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17476. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17477. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17478. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17479. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17480. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17481. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17482. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17483. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17484. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17485. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17486. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17487. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17488. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17489. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17490. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17491. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17492. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17493. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17494. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17495. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17496. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17497. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17498. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17499. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17500. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17501. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17502. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17503. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17504. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17505. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17506. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17507. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17508. ];
  17509. function getUnicodeRangeFor(value) {
  17510. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17511. var range = UnicodeRanges[i];
  17512. if (value >= range.begin && value < range.end) {
  17513. return i;
  17514. }
  17515. }
  17516. return -1;
  17517. }
  17518. function isRTLRangeFor(value) {
  17519. var range = UnicodeRanges[13];
  17520. if (value >= range.begin && value < range.end) {
  17521. return true;
  17522. }
  17523. range = UnicodeRanges[11];
  17524. if (value >= range.begin && value < range.end) {
  17525. return true;
  17526. }
  17527. return false;
  17528. }
  17529. // The normalization table is obtained by filtering the Unicode characters
  17530. // database with <compat> entries.
  17531. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17532. t['\u00A8'] = '\u0020\u0308';
  17533. t['\u00AF'] = '\u0020\u0304';
  17534. t['\u00B4'] = '\u0020\u0301';
  17535. t['\u00B5'] = '\u03BC';
  17536. t['\u00B8'] = '\u0020\u0327';
  17537. t['\u0132'] = '\u0049\u004A';
  17538. t['\u0133'] = '\u0069\u006A';
  17539. t['\u013F'] = '\u004C\u00B7';
  17540. t['\u0140'] = '\u006C\u00B7';
  17541. t['\u0149'] = '\u02BC\u006E';
  17542. t['\u017F'] = '\u0073';
  17543. t['\u01C4'] = '\u0044\u017D';
  17544. t['\u01C5'] = '\u0044\u017E';
  17545. t['\u01C6'] = '\u0064\u017E';
  17546. t['\u01C7'] = '\u004C\u004A';
  17547. t['\u01C8'] = '\u004C\u006A';
  17548. t['\u01C9'] = '\u006C\u006A';
  17549. t['\u01CA'] = '\u004E\u004A';
  17550. t['\u01CB'] = '\u004E\u006A';
  17551. t['\u01CC'] = '\u006E\u006A';
  17552. t['\u01F1'] = '\u0044\u005A';
  17553. t['\u01F2'] = '\u0044\u007A';
  17554. t['\u01F3'] = '\u0064\u007A';
  17555. t['\u02D8'] = '\u0020\u0306';
  17556. t['\u02D9'] = '\u0020\u0307';
  17557. t['\u02DA'] = '\u0020\u030A';
  17558. t['\u02DB'] = '\u0020\u0328';
  17559. t['\u02DC'] = '\u0020\u0303';
  17560. t['\u02DD'] = '\u0020\u030B';
  17561. t['\u037A'] = '\u0020\u0345';
  17562. t['\u0384'] = '\u0020\u0301';
  17563. t['\u03D0'] = '\u03B2';
  17564. t['\u03D1'] = '\u03B8';
  17565. t['\u03D2'] = '\u03A5';
  17566. t['\u03D5'] = '\u03C6';
  17567. t['\u03D6'] = '\u03C0';
  17568. t['\u03F0'] = '\u03BA';
  17569. t['\u03F1'] = '\u03C1';
  17570. t['\u03F2'] = '\u03C2';
  17571. t['\u03F4'] = '\u0398';
  17572. t['\u03F5'] = '\u03B5';
  17573. t['\u03F9'] = '\u03A3';
  17574. t['\u0587'] = '\u0565\u0582';
  17575. t['\u0675'] = '\u0627\u0674';
  17576. t['\u0676'] = '\u0648\u0674';
  17577. t['\u0677'] = '\u06C7\u0674';
  17578. t['\u0678'] = '\u064A\u0674';
  17579. t['\u0E33'] = '\u0E4D\u0E32';
  17580. t['\u0EB3'] = '\u0ECD\u0EB2';
  17581. t['\u0EDC'] = '\u0EAB\u0E99';
  17582. t['\u0EDD'] = '\u0EAB\u0EA1';
  17583. t['\u0F77'] = '\u0FB2\u0F81';
  17584. t['\u0F79'] = '\u0FB3\u0F81';
  17585. t['\u1E9A'] = '\u0061\u02BE';
  17586. t['\u1FBD'] = '\u0020\u0313';
  17587. t['\u1FBF'] = '\u0020\u0313';
  17588. t['\u1FC0'] = '\u0020\u0342';
  17589. t['\u1FFE'] = '\u0020\u0314';
  17590. t['\u2002'] = '\u0020';
  17591. t['\u2003'] = '\u0020';
  17592. t['\u2004'] = '\u0020';
  17593. t['\u2005'] = '\u0020';
  17594. t['\u2006'] = '\u0020';
  17595. t['\u2008'] = '\u0020';
  17596. t['\u2009'] = '\u0020';
  17597. t['\u200A'] = '\u0020';
  17598. t['\u2017'] = '\u0020\u0333';
  17599. t['\u2024'] = '\u002E';
  17600. t['\u2025'] = '\u002E\u002E';
  17601. t['\u2026'] = '\u002E\u002E\u002E';
  17602. t['\u2033'] = '\u2032\u2032';
  17603. t['\u2034'] = '\u2032\u2032\u2032';
  17604. t['\u2036'] = '\u2035\u2035';
  17605. t['\u2037'] = '\u2035\u2035\u2035';
  17606. t['\u203C'] = '\u0021\u0021';
  17607. t['\u203E'] = '\u0020\u0305';
  17608. t['\u2047'] = '\u003F\u003F';
  17609. t['\u2048'] = '\u003F\u0021';
  17610. t['\u2049'] = '\u0021\u003F';
  17611. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17612. t['\u205F'] = '\u0020';
  17613. t['\u20A8'] = '\u0052\u0073';
  17614. t['\u2100'] = '\u0061\u002F\u0063';
  17615. t['\u2101'] = '\u0061\u002F\u0073';
  17616. t['\u2103'] = '\u00B0\u0043';
  17617. t['\u2105'] = '\u0063\u002F\u006F';
  17618. t['\u2106'] = '\u0063\u002F\u0075';
  17619. t['\u2107'] = '\u0190';
  17620. t['\u2109'] = '\u00B0\u0046';
  17621. t['\u2116'] = '\u004E\u006F';
  17622. t['\u2121'] = '\u0054\u0045\u004C';
  17623. t['\u2135'] = '\u05D0';
  17624. t['\u2136'] = '\u05D1';
  17625. t['\u2137'] = '\u05D2';
  17626. t['\u2138'] = '\u05D3';
  17627. t['\u213B'] = '\u0046\u0041\u0058';
  17628. t['\u2160'] = '\u0049';
  17629. t['\u2161'] = '\u0049\u0049';
  17630. t['\u2162'] = '\u0049\u0049\u0049';
  17631. t['\u2163'] = '\u0049\u0056';
  17632. t['\u2164'] = '\u0056';
  17633. t['\u2165'] = '\u0056\u0049';
  17634. t['\u2166'] = '\u0056\u0049\u0049';
  17635. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17636. t['\u2168'] = '\u0049\u0058';
  17637. t['\u2169'] = '\u0058';
  17638. t['\u216A'] = '\u0058\u0049';
  17639. t['\u216B'] = '\u0058\u0049\u0049';
  17640. t['\u216C'] = '\u004C';
  17641. t['\u216D'] = '\u0043';
  17642. t['\u216E'] = '\u0044';
  17643. t['\u216F'] = '\u004D';
  17644. t['\u2170'] = '\u0069';
  17645. t['\u2171'] = '\u0069\u0069';
  17646. t['\u2172'] = '\u0069\u0069\u0069';
  17647. t['\u2173'] = '\u0069\u0076';
  17648. t['\u2174'] = '\u0076';
  17649. t['\u2175'] = '\u0076\u0069';
  17650. t['\u2176'] = '\u0076\u0069\u0069';
  17651. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17652. t['\u2178'] = '\u0069\u0078';
  17653. t['\u2179'] = '\u0078';
  17654. t['\u217A'] = '\u0078\u0069';
  17655. t['\u217B'] = '\u0078\u0069\u0069';
  17656. t['\u217C'] = '\u006C';
  17657. t['\u217D'] = '\u0063';
  17658. t['\u217E'] = '\u0064';
  17659. t['\u217F'] = '\u006D';
  17660. t['\u222C'] = '\u222B\u222B';
  17661. t['\u222D'] = '\u222B\u222B\u222B';
  17662. t['\u222F'] = '\u222E\u222E';
  17663. t['\u2230'] = '\u222E\u222E\u222E';
  17664. t['\u2474'] = '\u0028\u0031\u0029';
  17665. t['\u2475'] = '\u0028\u0032\u0029';
  17666. t['\u2476'] = '\u0028\u0033\u0029';
  17667. t['\u2477'] = '\u0028\u0034\u0029';
  17668. t['\u2478'] = '\u0028\u0035\u0029';
  17669. t['\u2479'] = '\u0028\u0036\u0029';
  17670. t['\u247A'] = '\u0028\u0037\u0029';
  17671. t['\u247B'] = '\u0028\u0038\u0029';
  17672. t['\u247C'] = '\u0028\u0039\u0029';
  17673. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17674. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17675. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17676. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17677. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17678. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17679. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17680. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17681. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17682. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17683. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17684. t['\u2488'] = '\u0031\u002E';
  17685. t['\u2489'] = '\u0032\u002E';
  17686. t['\u248A'] = '\u0033\u002E';
  17687. t['\u248B'] = '\u0034\u002E';
  17688. t['\u248C'] = '\u0035\u002E';
  17689. t['\u248D'] = '\u0036\u002E';
  17690. t['\u248E'] = '\u0037\u002E';
  17691. t['\u248F'] = '\u0038\u002E';
  17692. t['\u2490'] = '\u0039\u002E';
  17693. t['\u2491'] = '\u0031\u0030\u002E';
  17694. t['\u2492'] = '\u0031\u0031\u002E';
  17695. t['\u2493'] = '\u0031\u0032\u002E';
  17696. t['\u2494'] = '\u0031\u0033\u002E';
  17697. t['\u2495'] = '\u0031\u0034\u002E';
  17698. t['\u2496'] = '\u0031\u0035\u002E';
  17699. t['\u2497'] = '\u0031\u0036\u002E';
  17700. t['\u2498'] = '\u0031\u0037\u002E';
  17701. t['\u2499'] = '\u0031\u0038\u002E';
  17702. t['\u249A'] = '\u0031\u0039\u002E';
  17703. t['\u249B'] = '\u0032\u0030\u002E';
  17704. t['\u249C'] = '\u0028\u0061\u0029';
  17705. t['\u249D'] = '\u0028\u0062\u0029';
  17706. t['\u249E'] = '\u0028\u0063\u0029';
  17707. t['\u249F'] = '\u0028\u0064\u0029';
  17708. t['\u24A0'] = '\u0028\u0065\u0029';
  17709. t['\u24A1'] = '\u0028\u0066\u0029';
  17710. t['\u24A2'] = '\u0028\u0067\u0029';
  17711. t['\u24A3'] = '\u0028\u0068\u0029';
  17712. t['\u24A4'] = '\u0028\u0069\u0029';
  17713. t['\u24A5'] = '\u0028\u006A\u0029';
  17714. t['\u24A6'] = '\u0028\u006B\u0029';
  17715. t['\u24A7'] = '\u0028\u006C\u0029';
  17716. t['\u24A8'] = '\u0028\u006D\u0029';
  17717. t['\u24A9'] = '\u0028\u006E\u0029';
  17718. t['\u24AA'] = '\u0028\u006F\u0029';
  17719. t['\u24AB'] = '\u0028\u0070\u0029';
  17720. t['\u24AC'] = '\u0028\u0071\u0029';
  17721. t['\u24AD'] = '\u0028\u0072\u0029';
  17722. t['\u24AE'] = '\u0028\u0073\u0029';
  17723. t['\u24AF'] = '\u0028\u0074\u0029';
  17724. t['\u24B0'] = '\u0028\u0075\u0029';
  17725. t['\u24B1'] = '\u0028\u0076\u0029';
  17726. t['\u24B2'] = '\u0028\u0077\u0029';
  17727. t['\u24B3'] = '\u0028\u0078\u0029';
  17728. t['\u24B4'] = '\u0028\u0079\u0029';
  17729. t['\u24B5'] = '\u0028\u007A\u0029';
  17730. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17731. t['\u2A74'] = '\u003A\u003A\u003D';
  17732. t['\u2A75'] = '\u003D\u003D';
  17733. t['\u2A76'] = '\u003D\u003D\u003D';
  17734. t['\u2E9F'] = '\u6BCD';
  17735. t['\u2EF3'] = '\u9F9F';
  17736. t['\u2F00'] = '\u4E00';
  17737. t['\u2F01'] = '\u4E28';
  17738. t['\u2F02'] = '\u4E36';
  17739. t['\u2F03'] = '\u4E3F';
  17740. t['\u2F04'] = '\u4E59';
  17741. t['\u2F05'] = '\u4E85';
  17742. t['\u2F06'] = '\u4E8C';
  17743. t['\u2F07'] = '\u4EA0';
  17744. t['\u2F08'] = '\u4EBA';
  17745. t['\u2F09'] = '\u513F';
  17746. t['\u2F0A'] = '\u5165';
  17747. t['\u2F0B'] = '\u516B';
  17748. t['\u2F0C'] = '\u5182';
  17749. t['\u2F0D'] = '\u5196';
  17750. t['\u2F0E'] = '\u51AB';
  17751. t['\u2F0F'] = '\u51E0';
  17752. t['\u2F10'] = '\u51F5';
  17753. t['\u2F11'] = '\u5200';
  17754. t['\u2F12'] = '\u529B';
  17755. t['\u2F13'] = '\u52F9';
  17756. t['\u2F14'] = '\u5315';
  17757. t['\u2F15'] = '\u531A';
  17758. t['\u2F16'] = '\u5338';
  17759. t['\u2F17'] = '\u5341';
  17760. t['\u2F18'] = '\u535C';
  17761. t['\u2F19'] = '\u5369';
  17762. t['\u2F1A'] = '\u5382';
  17763. t['\u2F1B'] = '\u53B6';
  17764. t['\u2F1C'] = '\u53C8';
  17765. t['\u2F1D'] = '\u53E3';
  17766. t['\u2F1E'] = '\u56D7';
  17767. t['\u2F1F'] = '\u571F';
  17768. t['\u2F20'] = '\u58EB';
  17769. t['\u2F21'] = '\u5902';
  17770. t['\u2F22'] = '\u590A';
  17771. t['\u2F23'] = '\u5915';
  17772. t['\u2F24'] = '\u5927';
  17773. t['\u2F25'] = '\u5973';
  17774. t['\u2F26'] = '\u5B50';
  17775. t['\u2F27'] = '\u5B80';
  17776. t['\u2F28'] = '\u5BF8';
  17777. t['\u2F29'] = '\u5C0F';
  17778. t['\u2F2A'] = '\u5C22';
  17779. t['\u2F2B'] = '\u5C38';
  17780. t['\u2F2C'] = '\u5C6E';
  17781. t['\u2F2D'] = '\u5C71';
  17782. t['\u2F2E'] = '\u5DDB';
  17783. t['\u2F2F'] = '\u5DE5';
  17784. t['\u2F30'] = '\u5DF1';
  17785. t['\u2F31'] = '\u5DFE';
  17786. t['\u2F32'] = '\u5E72';
  17787. t['\u2F33'] = '\u5E7A';
  17788. t['\u2F34'] = '\u5E7F';
  17789. t['\u2F35'] = '\u5EF4';
  17790. t['\u2F36'] = '\u5EFE';
  17791. t['\u2F37'] = '\u5F0B';
  17792. t['\u2F38'] = '\u5F13';
  17793. t['\u2F39'] = '\u5F50';
  17794. t['\u2F3A'] = '\u5F61';
  17795. t['\u2F3B'] = '\u5F73';
  17796. t['\u2F3C'] = '\u5FC3';
  17797. t['\u2F3D'] = '\u6208';
  17798. t['\u2F3E'] = '\u6236';
  17799. t['\u2F3F'] = '\u624B';
  17800. t['\u2F40'] = '\u652F';
  17801. t['\u2F41'] = '\u6534';
  17802. t['\u2F42'] = '\u6587';
  17803. t['\u2F43'] = '\u6597';
  17804. t['\u2F44'] = '\u65A4';
  17805. t['\u2F45'] = '\u65B9';
  17806. t['\u2F46'] = '\u65E0';
  17807. t['\u2F47'] = '\u65E5';
  17808. t['\u2F48'] = '\u66F0';
  17809. t['\u2F49'] = '\u6708';
  17810. t['\u2F4A'] = '\u6728';
  17811. t['\u2F4B'] = '\u6B20';
  17812. t['\u2F4C'] = '\u6B62';
  17813. t['\u2F4D'] = '\u6B79';
  17814. t['\u2F4E'] = '\u6BB3';
  17815. t['\u2F4F'] = '\u6BCB';
  17816. t['\u2F50'] = '\u6BD4';
  17817. t['\u2F51'] = '\u6BDB';
  17818. t['\u2F52'] = '\u6C0F';
  17819. t['\u2F53'] = '\u6C14';
  17820. t['\u2F54'] = '\u6C34';
  17821. t['\u2F55'] = '\u706B';
  17822. t['\u2F56'] = '\u722A';
  17823. t['\u2F57'] = '\u7236';
  17824. t['\u2F58'] = '\u723B';
  17825. t['\u2F59'] = '\u723F';
  17826. t['\u2F5A'] = '\u7247';
  17827. t['\u2F5B'] = '\u7259';
  17828. t['\u2F5C'] = '\u725B';
  17829. t['\u2F5D'] = '\u72AC';
  17830. t['\u2F5E'] = '\u7384';
  17831. t['\u2F5F'] = '\u7389';
  17832. t['\u2F60'] = '\u74DC';
  17833. t['\u2F61'] = '\u74E6';
  17834. t['\u2F62'] = '\u7518';
  17835. t['\u2F63'] = '\u751F';
  17836. t['\u2F64'] = '\u7528';
  17837. t['\u2F65'] = '\u7530';
  17838. t['\u2F66'] = '\u758B';
  17839. t['\u2F67'] = '\u7592';
  17840. t['\u2F68'] = '\u7676';
  17841. t['\u2F69'] = '\u767D';
  17842. t['\u2F6A'] = '\u76AE';
  17843. t['\u2F6B'] = '\u76BF';
  17844. t['\u2F6C'] = '\u76EE';
  17845. t['\u2F6D'] = '\u77DB';
  17846. t['\u2F6E'] = '\u77E2';
  17847. t['\u2F6F'] = '\u77F3';
  17848. t['\u2F70'] = '\u793A';
  17849. t['\u2F71'] = '\u79B8';
  17850. t['\u2F72'] = '\u79BE';
  17851. t['\u2F73'] = '\u7A74';
  17852. t['\u2F74'] = '\u7ACB';
  17853. t['\u2F75'] = '\u7AF9';
  17854. t['\u2F76'] = '\u7C73';
  17855. t['\u2F77'] = '\u7CF8';
  17856. t['\u2F78'] = '\u7F36';
  17857. t['\u2F79'] = '\u7F51';
  17858. t['\u2F7A'] = '\u7F8A';
  17859. t['\u2F7B'] = '\u7FBD';
  17860. t['\u2F7C'] = '\u8001';
  17861. t['\u2F7D'] = '\u800C';
  17862. t['\u2F7E'] = '\u8012';
  17863. t['\u2F7F'] = '\u8033';
  17864. t['\u2F80'] = '\u807F';
  17865. t['\u2F81'] = '\u8089';
  17866. t['\u2F82'] = '\u81E3';
  17867. t['\u2F83'] = '\u81EA';
  17868. t['\u2F84'] = '\u81F3';
  17869. t['\u2F85'] = '\u81FC';
  17870. t['\u2F86'] = '\u820C';
  17871. t['\u2F87'] = '\u821B';
  17872. t['\u2F88'] = '\u821F';
  17873. t['\u2F89'] = '\u826E';
  17874. t['\u2F8A'] = '\u8272';
  17875. t['\u2F8B'] = '\u8278';
  17876. t['\u2F8C'] = '\u864D';
  17877. t['\u2F8D'] = '\u866B';
  17878. t['\u2F8E'] = '\u8840';
  17879. t['\u2F8F'] = '\u884C';
  17880. t['\u2F90'] = '\u8863';
  17881. t['\u2F91'] = '\u897E';
  17882. t['\u2F92'] = '\u898B';
  17883. t['\u2F93'] = '\u89D2';
  17884. t['\u2F94'] = '\u8A00';
  17885. t['\u2F95'] = '\u8C37';
  17886. t['\u2F96'] = '\u8C46';
  17887. t['\u2F97'] = '\u8C55';
  17888. t['\u2F98'] = '\u8C78';
  17889. t['\u2F99'] = '\u8C9D';
  17890. t['\u2F9A'] = '\u8D64';
  17891. t['\u2F9B'] = '\u8D70';
  17892. t['\u2F9C'] = '\u8DB3';
  17893. t['\u2F9D'] = '\u8EAB';
  17894. t['\u2F9E'] = '\u8ECA';
  17895. t['\u2F9F'] = '\u8F9B';
  17896. t['\u2FA0'] = '\u8FB0';
  17897. t['\u2FA1'] = '\u8FB5';
  17898. t['\u2FA2'] = '\u9091';
  17899. t['\u2FA3'] = '\u9149';
  17900. t['\u2FA4'] = '\u91C6';
  17901. t['\u2FA5'] = '\u91CC';
  17902. t['\u2FA6'] = '\u91D1';
  17903. t['\u2FA7'] = '\u9577';
  17904. t['\u2FA8'] = '\u9580';
  17905. t['\u2FA9'] = '\u961C';
  17906. t['\u2FAA'] = '\u96B6';
  17907. t['\u2FAB'] = '\u96B9';
  17908. t['\u2FAC'] = '\u96E8';
  17909. t['\u2FAD'] = '\u9751';
  17910. t['\u2FAE'] = '\u975E';
  17911. t['\u2FAF'] = '\u9762';
  17912. t['\u2FB0'] = '\u9769';
  17913. t['\u2FB1'] = '\u97CB';
  17914. t['\u2FB2'] = '\u97ED';
  17915. t['\u2FB3'] = '\u97F3';
  17916. t['\u2FB4'] = '\u9801';
  17917. t['\u2FB5'] = '\u98A8';
  17918. t['\u2FB6'] = '\u98DB';
  17919. t['\u2FB7'] = '\u98DF';
  17920. t['\u2FB8'] = '\u9996';
  17921. t['\u2FB9'] = '\u9999';
  17922. t['\u2FBA'] = '\u99AC';
  17923. t['\u2FBB'] = '\u9AA8';
  17924. t['\u2FBC'] = '\u9AD8';
  17925. t['\u2FBD'] = '\u9ADF';
  17926. t['\u2FBE'] = '\u9B25';
  17927. t['\u2FBF'] = '\u9B2F';
  17928. t['\u2FC0'] = '\u9B32';
  17929. t['\u2FC1'] = '\u9B3C';
  17930. t['\u2FC2'] = '\u9B5A';
  17931. t['\u2FC3'] = '\u9CE5';
  17932. t['\u2FC4'] = '\u9E75';
  17933. t['\u2FC5'] = '\u9E7F';
  17934. t['\u2FC6'] = '\u9EA5';
  17935. t['\u2FC7'] = '\u9EBB';
  17936. t['\u2FC8'] = '\u9EC3';
  17937. t['\u2FC9'] = '\u9ECD';
  17938. t['\u2FCA'] = '\u9ED1';
  17939. t['\u2FCB'] = '\u9EF9';
  17940. t['\u2FCC'] = '\u9EFD';
  17941. t['\u2FCD'] = '\u9F0E';
  17942. t['\u2FCE'] = '\u9F13';
  17943. t['\u2FCF'] = '\u9F20';
  17944. t['\u2FD0'] = '\u9F3B';
  17945. t['\u2FD1'] = '\u9F4A';
  17946. t['\u2FD2'] = '\u9F52';
  17947. t['\u2FD3'] = '\u9F8D';
  17948. t['\u2FD4'] = '\u9F9C';
  17949. t['\u2FD5'] = '\u9FA0';
  17950. t['\u3036'] = '\u3012';
  17951. t['\u3038'] = '\u5341';
  17952. t['\u3039'] = '\u5344';
  17953. t['\u303A'] = '\u5345';
  17954. t['\u309B'] = '\u0020\u3099';
  17955. t['\u309C'] = '\u0020\u309A';
  17956. t['\u3131'] = '\u1100';
  17957. t['\u3132'] = '\u1101';
  17958. t['\u3133'] = '\u11AA';
  17959. t['\u3134'] = '\u1102';
  17960. t['\u3135'] = '\u11AC';
  17961. t['\u3136'] = '\u11AD';
  17962. t['\u3137'] = '\u1103';
  17963. t['\u3138'] = '\u1104';
  17964. t['\u3139'] = '\u1105';
  17965. t['\u313A'] = '\u11B0';
  17966. t['\u313B'] = '\u11B1';
  17967. t['\u313C'] = '\u11B2';
  17968. t['\u313D'] = '\u11B3';
  17969. t['\u313E'] = '\u11B4';
  17970. t['\u313F'] = '\u11B5';
  17971. t['\u3140'] = '\u111A';
  17972. t['\u3141'] = '\u1106';
  17973. t['\u3142'] = '\u1107';
  17974. t['\u3143'] = '\u1108';
  17975. t['\u3144'] = '\u1121';
  17976. t['\u3145'] = '\u1109';
  17977. t['\u3146'] = '\u110A';
  17978. t['\u3147'] = '\u110B';
  17979. t['\u3148'] = '\u110C';
  17980. t['\u3149'] = '\u110D';
  17981. t['\u314A'] = '\u110E';
  17982. t['\u314B'] = '\u110F';
  17983. t['\u314C'] = '\u1110';
  17984. t['\u314D'] = '\u1111';
  17985. t['\u314E'] = '\u1112';
  17986. t['\u314F'] = '\u1161';
  17987. t['\u3150'] = '\u1162';
  17988. t['\u3151'] = '\u1163';
  17989. t['\u3152'] = '\u1164';
  17990. t['\u3153'] = '\u1165';
  17991. t['\u3154'] = '\u1166';
  17992. t['\u3155'] = '\u1167';
  17993. t['\u3156'] = '\u1168';
  17994. t['\u3157'] = '\u1169';
  17995. t['\u3158'] = '\u116A';
  17996. t['\u3159'] = '\u116B';
  17997. t['\u315A'] = '\u116C';
  17998. t['\u315B'] = '\u116D';
  17999. t['\u315C'] = '\u116E';
  18000. t['\u315D'] = '\u116F';
  18001. t['\u315E'] = '\u1170';
  18002. t['\u315F'] = '\u1171';
  18003. t['\u3160'] = '\u1172';
  18004. t['\u3161'] = '\u1173';
  18005. t['\u3162'] = '\u1174';
  18006. t['\u3163'] = '\u1175';
  18007. t['\u3164'] = '\u1160';
  18008. t['\u3165'] = '\u1114';
  18009. t['\u3166'] = '\u1115';
  18010. t['\u3167'] = '\u11C7';
  18011. t['\u3168'] = '\u11C8';
  18012. t['\u3169'] = '\u11CC';
  18013. t['\u316A'] = '\u11CE';
  18014. t['\u316B'] = '\u11D3';
  18015. t['\u316C'] = '\u11D7';
  18016. t['\u316D'] = '\u11D9';
  18017. t['\u316E'] = '\u111C';
  18018. t['\u316F'] = '\u11DD';
  18019. t['\u3170'] = '\u11DF';
  18020. t['\u3171'] = '\u111D';
  18021. t['\u3172'] = '\u111E';
  18022. t['\u3173'] = '\u1120';
  18023. t['\u3174'] = '\u1122';
  18024. t['\u3175'] = '\u1123';
  18025. t['\u3176'] = '\u1127';
  18026. t['\u3177'] = '\u1129';
  18027. t['\u3178'] = '\u112B';
  18028. t['\u3179'] = '\u112C';
  18029. t['\u317A'] = '\u112D';
  18030. t['\u317B'] = '\u112E';
  18031. t['\u317C'] = '\u112F';
  18032. t['\u317D'] = '\u1132';
  18033. t['\u317E'] = '\u1136';
  18034. t['\u317F'] = '\u1140';
  18035. t['\u3180'] = '\u1147';
  18036. t['\u3181'] = '\u114C';
  18037. t['\u3182'] = '\u11F1';
  18038. t['\u3183'] = '\u11F2';
  18039. t['\u3184'] = '\u1157';
  18040. t['\u3185'] = '\u1158';
  18041. t['\u3186'] = '\u1159';
  18042. t['\u3187'] = '\u1184';
  18043. t['\u3188'] = '\u1185';
  18044. t['\u3189'] = '\u1188';
  18045. t['\u318A'] = '\u1191';
  18046. t['\u318B'] = '\u1192';
  18047. t['\u318C'] = '\u1194';
  18048. t['\u318D'] = '\u119E';
  18049. t['\u318E'] = '\u11A1';
  18050. t['\u3200'] = '\u0028\u1100\u0029';
  18051. t['\u3201'] = '\u0028\u1102\u0029';
  18052. t['\u3202'] = '\u0028\u1103\u0029';
  18053. t['\u3203'] = '\u0028\u1105\u0029';
  18054. t['\u3204'] = '\u0028\u1106\u0029';
  18055. t['\u3205'] = '\u0028\u1107\u0029';
  18056. t['\u3206'] = '\u0028\u1109\u0029';
  18057. t['\u3207'] = '\u0028\u110B\u0029';
  18058. t['\u3208'] = '\u0028\u110C\u0029';
  18059. t['\u3209'] = '\u0028\u110E\u0029';
  18060. t['\u320A'] = '\u0028\u110F\u0029';
  18061. t['\u320B'] = '\u0028\u1110\u0029';
  18062. t['\u320C'] = '\u0028\u1111\u0029';
  18063. t['\u320D'] = '\u0028\u1112\u0029';
  18064. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18065. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18066. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18067. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18068. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18069. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18070. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18071. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18072. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18073. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18074. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18075. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18076. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18077. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18078. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18079. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18080. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18081. t['\u3220'] = '\u0028\u4E00\u0029';
  18082. t['\u3221'] = '\u0028\u4E8C\u0029';
  18083. t['\u3222'] = '\u0028\u4E09\u0029';
  18084. t['\u3223'] = '\u0028\u56DB\u0029';
  18085. t['\u3224'] = '\u0028\u4E94\u0029';
  18086. t['\u3225'] = '\u0028\u516D\u0029';
  18087. t['\u3226'] = '\u0028\u4E03\u0029';
  18088. t['\u3227'] = '\u0028\u516B\u0029';
  18089. t['\u3228'] = '\u0028\u4E5D\u0029';
  18090. t['\u3229'] = '\u0028\u5341\u0029';
  18091. t['\u322A'] = '\u0028\u6708\u0029';
  18092. t['\u322B'] = '\u0028\u706B\u0029';
  18093. t['\u322C'] = '\u0028\u6C34\u0029';
  18094. t['\u322D'] = '\u0028\u6728\u0029';
  18095. t['\u322E'] = '\u0028\u91D1\u0029';
  18096. t['\u322F'] = '\u0028\u571F\u0029';
  18097. t['\u3230'] = '\u0028\u65E5\u0029';
  18098. t['\u3231'] = '\u0028\u682A\u0029';
  18099. t['\u3232'] = '\u0028\u6709\u0029';
  18100. t['\u3233'] = '\u0028\u793E\u0029';
  18101. t['\u3234'] = '\u0028\u540D\u0029';
  18102. t['\u3235'] = '\u0028\u7279\u0029';
  18103. t['\u3236'] = '\u0028\u8CA1\u0029';
  18104. t['\u3237'] = '\u0028\u795D\u0029';
  18105. t['\u3238'] = '\u0028\u52B4\u0029';
  18106. t['\u3239'] = '\u0028\u4EE3\u0029';
  18107. t['\u323A'] = '\u0028\u547C\u0029';
  18108. t['\u323B'] = '\u0028\u5B66\u0029';
  18109. t['\u323C'] = '\u0028\u76E3\u0029';
  18110. t['\u323D'] = '\u0028\u4F01\u0029';
  18111. t['\u323E'] = '\u0028\u8CC7\u0029';
  18112. t['\u323F'] = '\u0028\u5354\u0029';
  18113. t['\u3240'] = '\u0028\u796D\u0029';
  18114. t['\u3241'] = '\u0028\u4F11\u0029';
  18115. t['\u3242'] = '\u0028\u81EA\u0029';
  18116. t['\u3243'] = '\u0028\u81F3\u0029';
  18117. t['\u32C0'] = '\u0031\u6708';
  18118. t['\u32C1'] = '\u0032\u6708';
  18119. t['\u32C2'] = '\u0033\u6708';
  18120. t['\u32C3'] = '\u0034\u6708';
  18121. t['\u32C4'] = '\u0035\u6708';
  18122. t['\u32C5'] = '\u0036\u6708';
  18123. t['\u32C6'] = '\u0037\u6708';
  18124. t['\u32C7'] = '\u0038\u6708';
  18125. t['\u32C8'] = '\u0039\u6708';
  18126. t['\u32C9'] = '\u0031\u0030\u6708';
  18127. t['\u32CA'] = '\u0031\u0031\u6708';
  18128. t['\u32CB'] = '\u0031\u0032\u6708';
  18129. t['\u3358'] = '\u0030\u70B9';
  18130. t['\u3359'] = '\u0031\u70B9';
  18131. t['\u335A'] = '\u0032\u70B9';
  18132. t['\u335B'] = '\u0033\u70B9';
  18133. t['\u335C'] = '\u0034\u70B9';
  18134. t['\u335D'] = '\u0035\u70B9';
  18135. t['\u335E'] = '\u0036\u70B9';
  18136. t['\u335F'] = '\u0037\u70B9';
  18137. t['\u3360'] = '\u0038\u70B9';
  18138. t['\u3361'] = '\u0039\u70B9';
  18139. t['\u3362'] = '\u0031\u0030\u70B9';
  18140. t['\u3363'] = '\u0031\u0031\u70B9';
  18141. t['\u3364'] = '\u0031\u0032\u70B9';
  18142. t['\u3365'] = '\u0031\u0033\u70B9';
  18143. t['\u3366'] = '\u0031\u0034\u70B9';
  18144. t['\u3367'] = '\u0031\u0035\u70B9';
  18145. t['\u3368'] = '\u0031\u0036\u70B9';
  18146. t['\u3369'] = '\u0031\u0037\u70B9';
  18147. t['\u336A'] = '\u0031\u0038\u70B9';
  18148. t['\u336B'] = '\u0031\u0039\u70B9';
  18149. t['\u336C'] = '\u0032\u0030\u70B9';
  18150. t['\u336D'] = '\u0032\u0031\u70B9';
  18151. t['\u336E'] = '\u0032\u0032\u70B9';
  18152. t['\u336F'] = '\u0032\u0033\u70B9';
  18153. t['\u3370'] = '\u0032\u0034\u70B9';
  18154. t['\u33E0'] = '\u0031\u65E5';
  18155. t['\u33E1'] = '\u0032\u65E5';
  18156. t['\u33E2'] = '\u0033\u65E5';
  18157. t['\u33E3'] = '\u0034\u65E5';
  18158. t['\u33E4'] = '\u0035\u65E5';
  18159. t['\u33E5'] = '\u0036\u65E5';
  18160. t['\u33E6'] = '\u0037\u65E5';
  18161. t['\u33E7'] = '\u0038\u65E5';
  18162. t['\u33E8'] = '\u0039\u65E5';
  18163. t['\u33E9'] = '\u0031\u0030\u65E5';
  18164. t['\u33EA'] = '\u0031\u0031\u65E5';
  18165. t['\u33EB'] = '\u0031\u0032\u65E5';
  18166. t['\u33EC'] = '\u0031\u0033\u65E5';
  18167. t['\u33ED'] = '\u0031\u0034\u65E5';
  18168. t['\u33EE'] = '\u0031\u0035\u65E5';
  18169. t['\u33EF'] = '\u0031\u0036\u65E5';
  18170. t['\u33F0'] = '\u0031\u0037\u65E5';
  18171. t['\u33F1'] = '\u0031\u0038\u65E5';
  18172. t['\u33F2'] = '\u0031\u0039\u65E5';
  18173. t['\u33F3'] = '\u0032\u0030\u65E5';
  18174. t['\u33F4'] = '\u0032\u0031\u65E5';
  18175. t['\u33F5'] = '\u0032\u0032\u65E5';
  18176. t['\u33F6'] = '\u0032\u0033\u65E5';
  18177. t['\u33F7'] = '\u0032\u0034\u65E5';
  18178. t['\u33F8'] = '\u0032\u0035\u65E5';
  18179. t['\u33F9'] = '\u0032\u0036\u65E5';
  18180. t['\u33FA'] = '\u0032\u0037\u65E5';
  18181. t['\u33FB'] = '\u0032\u0038\u65E5';
  18182. t['\u33FC'] = '\u0032\u0039\u65E5';
  18183. t['\u33FD'] = '\u0033\u0030\u65E5';
  18184. t['\u33FE'] = '\u0033\u0031\u65E5';
  18185. t['\uFB00'] = '\u0066\u0066';
  18186. t['\uFB01'] = '\u0066\u0069';
  18187. t['\uFB02'] = '\u0066\u006C';
  18188. t['\uFB03'] = '\u0066\u0066\u0069';
  18189. t['\uFB04'] = '\u0066\u0066\u006C';
  18190. t['\uFB05'] = '\u017F\u0074';
  18191. t['\uFB06'] = '\u0073\u0074';
  18192. t['\uFB13'] = '\u0574\u0576';
  18193. t['\uFB14'] = '\u0574\u0565';
  18194. t['\uFB15'] = '\u0574\u056B';
  18195. t['\uFB16'] = '\u057E\u0576';
  18196. t['\uFB17'] = '\u0574\u056D';
  18197. t['\uFB4F'] = '\u05D0\u05DC';
  18198. t['\uFB50'] = '\u0671';
  18199. t['\uFB51'] = '\u0671';
  18200. t['\uFB52'] = '\u067B';
  18201. t['\uFB53'] = '\u067B';
  18202. t['\uFB54'] = '\u067B';
  18203. t['\uFB55'] = '\u067B';
  18204. t['\uFB56'] = '\u067E';
  18205. t['\uFB57'] = '\u067E';
  18206. t['\uFB58'] = '\u067E';
  18207. t['\uFB59'] = '\u067E';
  18208. t['\uFB5A'] = '\u0680';
  18209. t['\uFB5B'] = '\u0680';
  18210. t['\uFB5C'] = '\u0680';
  18211. t['\uFB5D'] = '\u0680';
  18212. t['\uFB5E'] = '\u067A';
  18213. t['\uFB5F'] = '\u067A';
  18214. t['\uFB60'] = '\u067A';
  18215. t['\uFB61'] = '\u067A';
  18216. t['\uFB62'] = '\u067F';
  18217. t['\uFB63'] = '\u067F';
  18218. t['\uFB64'] = '\u067F';
  18219. t['\uFB65'] = '\u067F';
  18220. t['\uFB66'] = '\u0679';
  18221. t['\uFB67'] = '\u0679';
  18222. t['\uFB68'] = '\u0679';
  18223. t['\uFB69'] = '\u0679';
  18224. t['\uFB6A'] = '\u06A4';
  18225. t['\uFB6B'] = '\u06A4';
  18226. t['\uFB6C'] = '\u06A4';
  18227. t['\uFB6D'] = '\u06A4';
  18228. t['\uFB6E'] = '\u06A6';
  18229. t['\uFB6F'] = '\u06A6';
  18230. t['\uFB70'] = '\u06A6';
  18231. t['\uFB71'] = '\u06A6';
  18232. t['\uFB72'] = '\u0684';
  18233. t['\uFB73'] = '\u0684';
  18234. t['\uFB74'] = '\u0684';
  18235. t['\uFB75'] = '\u0684';
  18236. t['\uFB76'] = '\u0683';
  18237. t['\uFB77'] = '\u0683';
  18238. t['\uFB78'] = '\u0683';
  18239. t['\uFB79'] = '\u0683';
  18240. t['\uFB7A'] = '\u0686';
  18241. t['\uFB7B'] = '\u0686';
  18242. t['\uFB7C'] = '\u0686';
  18243. t['\uFB7D'] = '\u0686';
  18244. t['\uFB7E'] = '\u0687';
  18245. t['\uFB7F'] = '\u0687';
  18246. t['\uFB80'] = '\u0687';
  18247. t['\uFB81'] = '\u0687';
  18248. t['\uFB82'] = '\u068D';
  18249. t['\uFB83'] = '\u068D';
  18250. t['\uFB84'] = '\u068C';
  18251. t['\uFB85'] = '\u068C';
  18252. t['\uFB86'] = '\u068E';
  18253. t['\uFB87'] = '\u068E';
  18254. t['\uFB88'] = '\u0688';
  18255. t['\uFB89'] = '\u0688';
  18256. t['\uFB8A'] = '\u0698';
  18257. t['\uFB8B'] = '\u0698';
  18258. t['\uFB8C'] = '\u0691';
  18259. t['\uFB8D'] = '\u0691';
  18260. t['\uFB8E'] = '\u06A9';
  18261. t['\uFB8F'] = '\u06A9';
  18262. t['\uFB90'] = '\u06A9';
  18263. t['\uFB91'] = '\u06A9';
  18264. t['\uFB92'] = '\u06AF';
  18265. t['\uFB93'] = '\u06AF';
  18266. t['\uFB94'] = '\u06AF';
  18267. t['\uFB95'] = '\u06AF';
  18268. t['\uFB96'] = '\u06B3';
  18269. t['\uFB97'] = '\u06B3';
  18270. t['\uFB98'] = '\u06B3';
  18271. t['\uFB99'] = '\u06B3';
  18272. t['\uFB9A'] = '\u06B1';
  18273. t['\uFB9B'] = '\u06B1';
  18274. t['\uFB9C'] = '\u06B1';
  18275. t['\uFB9D'] = '\u06B1';
  18276. t['\uFB9E'] = '\u06BA';
  18277. t['\uFB9F'] = '\u06BA';
  18278. t['\uFBA0'] = '\u06BB';
  18279. t['\uFBA1'] = '\u06BB';
  18280. t['\uFBA2'] = '\u06BB';
  18281. t['\uFBA3'] = '\u06BB';
  18282. t['\uFBA4'] = '\u06C0';
  18283. t['\uFBA5'] = '\u06C0';
  18284. t['\uFBA6'] = '\u06C1';
  18285. t['\uFBA7'] = '\u06C1';
  18286. t['\uFBA8'] = '\u06C1';
  18287. t['\uFBA9'] = '\u06C1';
  18288. t['\uFBAA'] = '\u06BE';
  18289. t['\uFBAB'] = '\u06BE';
  18290. t['\uFBAC'] = '\u06BE';
  18291. t['\uFBAD'] = '\u06BE';
  18292. t['\uFBAE'] = '\u06D2';
  18293. t['\uFBAF'] = '\u06D2';
  18294. t['\uFBB0'] = '\u06D3';
  18295. t['\uFBB1'] = '\u06D3';
  18296. t['\uFBD3'] = '\u06AD';
  18297. t['\uFBD4'] = '\u06AD';
  18298. t['\uFBD5'] = '\u06AD';
  18299. t['\uFBD6'] = '\u06AD';
  18300. t['\uFBD7'] = '\u06C7';
  18301. t['\uFBD8'] = '\u06C7';
  18302. t['\uFBD9'] = '\u06C6';
  18303. t['\uFBDA'] = '\u06C6';
  18304. t['\uFBDB'] = '\u06C8';
  18305. t['\uFBDC'] = '\u06C8';
  18306. t['\uFBDD'] = '\u0677';
  18307. t['\uFBDE'] = '\u06CB';
  18308. t['\uFBDF'] = '\u06CB';
  18309. t['\uFBE0'] = '\u06C5';
  18310. t['\uFBE1'] = '\u06C5';
  18311. t['\uFBE2'] = '\u06C9';
  18312. t['\uFBE3'] = '\u06C9';
  18313. t['\uFBE4'] = '\u06D0';
  18314. t['\uFBE5'] = '\u06D0';
  18315. t['\uFBE6'] = '\u06D0';
  18316. t['\uFBE7'] = '\u06D0';
  18317. t['\uFBE8'] = '\u0649';
  18318. t['\uFBE9'] = '\u0649';
  18319. t['\uFBEA'] = '\u0626\u0627';
  18320. t['\uFBEB'] = '\u0626\u0627';
  18321. t['\uFBEC'] = '\u0626\u06D5';
  18322. t['\uFBED'] = '\u0626\u06D5';
  18323. t['\uFBEE'] = '\u0626\u0648';
  18324. t['\uFBEF'] = '\u0626\u0648';
  18325. t['\uFBF0'] = '\u0626\u06C7';
  18326. t['\uFBF1'] = '\u0626\u06C7';
  18327. t['\uFBF2'] = '\u0626\u06C6';
  18328. t['\uFBF3'] = '\u0626\u06C6';
  18329. t['\uFBF4'] = '\u0626\u06C8';
  18330. t['\uFBF5'] = '\u0626\u06C8';
  18331. t['\uFBF6'] = '\u0626\u06D0';
  18332. t['\uFBF7'] = '\u0626\u06D0';
  18333. t['\uFBF8'] = '\u0626\u06D0';
  18334. t['\uFBF9'] = '\u0626\u0649';
  18335. t['\uFBFA'] = '\u0626\u0649';
  18336. t['\uFBFB'] = '\u0626\u0649';
  18337. t['\uFBFC'] = '\u06CC';
  18338. t['\uFBFD'] = '\u06CC';
  18339. t['\uFBFE'] = '\u06CC';
  18340. t['\uFBFF'] = '\u06CC';
  18341. t['\uFC00'] = '\u0626\u062C';
  18342. t['\uFC01'] = '\u0626\u062D';
  18343. t['\uFC02'] = '\u0626\u0645';
  18344. t['\uFC03'] = '\u0626\u0649';
  18345. t['\uFC04'] = '\u0626\u064A';
  18346. t['\uFC05'] = '\u0628\u062C';
  18347. t['\uFC06'] = '\u0628\u062D';
  18348. t['\uFC07'] = '\u0628\u062E';
  18349. t['\uFC08'] = '\u0628\u0645';
  18350. t['\uFC09'] = '\u0628\u0649';
  18351. t['\uFC0A'] = '\u0628\u064A';
  18352. t['\uFC0B'] = '\u062A\u062C';
  18353. t['\uFC0C'] = '\u062A\u062D';
  18354. t['\uFC0D'] = '\u062A\u062E';
  18355. t['\uFC0E'] = '\u062A\u0645';
  18356. t['\uFC0F'] = '\u062A\u0649';
  18357. t['\uFC10'] = '\u062A\u064A';
  18358. t['\uFC11'] = '\u062B\u062C';
  18359. t['\uFC12'] = '\u062B\u0645';
  18360. t['\uFC13'] = '\u062B\u0649';
  18361. t['\uFC14'] = '\u062B\u064A';
  18362. t['\uFC15'] = '\u062C\u062D';
  18363. t['\uFC16'] = '\u062C\u0645';
  18364. t['\uFC17'] = '\u062D\u062C';
  18365. t['\uFC18'] = '\u062D\u0645';
  18366. t['\uFC19'] = '\u062E\u062C';
  18367. t['\uFC1A'] = '\u062E\u062D';
  18368. t['\uFC1B'] = '\u062E\u0645';
  18369. t['\uFC1C'] = '\u0633\u062C';
  18370. t['\uFC1D'] = '\u0633\u062D';
  18371. t['\uFC1E'] = '\u0633\u062E';
  18372. t['\uFC1F'] = '\u0633\u0645';
  18373. t['\uFC20'] = '\u0635\u062D';
  18374. t['\uFC21'] = '\u0635\u0645';
  18375. t['\uFC22'] = '\u0636\u062C';
  18376. t['\uFC23'] = '\u0636\u062D';
  18377. t['\uFC24'] = '\u0636\u062E';
  18378. t['\uFC25'] = '\u0636\u0645';
  18379. t['\uFC26'] = '\u0637\u062D';
  18380. t['\uFC27'] = '\u0637\u0645';
  18381. t['\uFC28'] = '\u0638\u0645';
  18382. t['\uFC29'] = '\u0639\u062C';
  18383. t['\uFC2A'] = '\u0639\u0645';
  18384. t['\uFC2B'] = '\u063A\u062C';
  18385. t['\uFC2C'] = '\u063A\u0645';
  18386. t['\uFC2D'] = '\u0641\u062C';
  18387. t['\uFC2E'] = '\u0641\u062D';
  18388. t['\uFC2F'] = '\u0641\u062E';
  18389. t['\uFC30'] = '\u0641\u0645';
  18390. t['\uFC31'] = '\u0641\u0649';
  18391. t['\uFC32'] = '\u0641\u064A';
  18392. t['\uFC33'] = '\u0642\u062D';
  18393. t['\uFC34'] = '\u0642\u0645';
  18394. t['\uFC35'] = '\u0642\u0649';
  18395. t['\uFC36'] = '\u0642\u064A';
  18396. t['\uFC37'] = '\u0643\u0627';
  18397. t['\uFC38'] = '\u0643\u062C';
  18398. t['\uFC39'] = '\u0643\u062D';
  18399. t['\uFC3A'] = '\u0643\u062E';
  18400. t['\uFC3B'] = '\u0643\u0644';
  18401. t['\uFC3C'] = '\u0643\u0645';
  18402. t['\uFC3D'] = '\u0643\u0649';
  18403. t['\uFC3E'] = '\u0643\u064A';
  18404. t['\uFC3F'] = '\u0644\u062C';
  18405. t['\uFC40'] = '\u0644\u062D';
  18406. t['\uFC41'] = '\u0644\u062E';
  18407. t['\uFC42'] = '\u0644\u0645';
  18408. t['\uFC43'] = '\u0644\u0649';
  18409. t['\uFC44'] = '\u0644\u064A';
  18410. t['\uFC45'] = '\u0645\u062C';
  18411. t['\uFC46'] = '\u0645\u062D';
  18412. t['\uFC47'] = '\u0645\u062E';
  18413. t['\uFC48'] = '\u0645\u0645';
  18414. t['\uFC49'] = '\u0645\u0649';
  18415. t['\uFC4A'] = '\u0645\u064A';
  18416. t['\uFC4B'] = '\u0646\u062C';
  18417. t['\uFC4C'] = '\u0646\u062D';
  18418. t['\uFC4D'] = '\u0646\u062E';
  18419. t['\uFC4E'] = '\u0646\u0645';
  18420. t['\uFC4F'] = '\u0646\u0649';
  18421. t['\uFC50'] = '\u0646\u064A';
  18422. t['\uFC51'] = '\u0647\u062C';
  18423. t['\uFC52'] = '\u0647\u0645';
  18424. t['\uFC53'] = '\u0647\u0649';
  18425. t['\uFC54'] = '\u0647\u064A';
  18426. t['\uFC55'] = '\u064A\u062C';
  18427. t['\uFC56'] = '\u064A\u062D';
  18428. t['\uFC57'] = '\u064A\u062E';
  18429. t['\uFC58'] = '\u064A\u0645';
  18430. t['\uFC59'] = '\u064A\u0649';
  18431. t['\uFC5A'] = '\u064A\u064A';
  18432. t['\uFC5B'] = '\u0630\u0670';
  18433. t['\uFC5C'] = '\u0631\u0670';
  18434. t['\uFC5D'] = '\u0649\u0670';
  18435. t['\uFC5E'] = '\u0020\u064C\u0651';
  18436. t['\uFC5F'] = '\u0020\u064D\u0651';
  18437. t['\uFC60'] = '\u0020\u064E\u0651';
  18438. t['\uFC61'] = '\u0020\u064F\u0651';
  18439. t['\uFC62'] = '\u0020\u0650\u0651';
  18440. t['\uFC63'] = '\u0020\u0651\u0670';
  18441. t['\uFC64'] = '\u0626\u0631';
  18442. t['\uFC65'] = '\u0626\u0632';
  18443. t['\uFC66'] = '\u0626\u0645';
  18444. t['\uFC67'] = '\u0626\u0646';
  18445. t['\uFC68'] = '\u0626\u0649';
  18446. t['\uFC69'] = '\u0626\u064A';
  18447. t['\uFC6A'] = '\u0628\u0631';
  18448. t['\uFC6B'] = '\u0628\u0632';
  18449. t['\uFC6C'] = '\u0628\u0645';
  18450. t['\uFC6D'] = '\u0628\u0646';
  18451. t['\uFC6E'] = '\u0628\u0649';
  18452. t['\uFC6F'] = '\u0628\u064A';
  18453. t['\uFC70'] = '\u062A\u0631';
  18454. t['\uFC71'] = '\u062A\u0632';
  18455. t['\uFC72'] = '\u062A\u0645';
  18456. t['\uFC73'] = '\u062A\u0646';
  18457. t['\uFC74'] = '\u062A\u0649';
  18458. t['\uFC75'] = '\u062A\u064A';
  18459. t['\uFC76'] = '\u062B\u0631';
  18460. t['\uFC77'] = '\u062B\u0632';
  18461. t['\uFC78'] = '\u062B\u0645';
  18462. t['\uFC79'] = '\u062B\u0646';
  18463. t['\uFC7A'] = '\u062B\u0649';
  18464. t['\uFC7B'] = '\u062B\u064A';
  18465. t['\uFC7C'] = '\u0641\u0649';
  18466. t['\uFC7D'] = '\u0641\u064A';
  18467. t['\uFC7E'] = '\u0642\u0649';
  18468. t['\uFC7F'] = '\u0642\u064A';
  18469. t['\uFC80'] = '\u0643\u0627';
  18470. t['\uFC81'] = '\u0643\u0644';
  18471. t['\uFC82'] = '\u0643\u0645';
  18472. t['\uFC83'] = '\u0643\u0649';
  18473. t['\uFC84'] = '\u0643\u064A';
  18474. t['\uFC85'] = '\u0644\u0645';
  18475. t['\uFC86'] = '\u0644\u0649';
  18476. t['\uFC87'] = '\u0644\u064A';
  18477. t['\uFC88'] = '\u0645\u0627';
  18478. t['\uFC89'] = '\u0645\u0645';
  18479. t['\uFC8A'] = '\u0646\u0631';
  18480. t['\uFC8B'] = '\u0646\u0632';
  18481. t['\uFC8C'] = '\u0646\u0645';
  18482. t['\uFC8D'] = '\u0646\u0646';
  18483. t['\uFC8E'] = '\u0646\u0649';
  18484. t['\uFC8F'] = '\u0646\u064A';
  18485. t['\uFC90'] = '\u0649\u0670';
  18486. t['\uFC91'] = '\u064A\u0631';
  18487. t['\uFC92'] = '\u064A\u0632';
  18488. t['\uFC93'] = '\u064A\u0645';
  18489. t['\uFC94'] = '\u064A\u0646';
  18490. t['\uFC95'] = '\u064A\u0649';
  18491. t['\uFC96'] = '\u064A\u064A';
  18492. t['\uFC97'] = '\u0626\u062C';
  18493. t['\uFC98'] = '\u0626\u062D';
  18494. t['\uFC99'] = '\u0626\u062E';
  18495. t['\uFC9A'] = '\u0626\u0645';
  18496. t['\uFC9B'] = '\u0626\u0647';
  18497. t['\uFC9C'] = '\u0628\u062C';
  18498. t['\uFC9D'] = '\u0628\u062D';
  18499. t['\uFC9E'] = '\u0628\u062E';
  18500. t['\uFC9F'] = '\u0628\u0645';
  18501. t['\uFCA0'] = '\u0628\u0647';
  18502. t['\uFCA1'] = '\u062A\u062C';
  18503. t['\uFCA2'] = '\u062A\u062D';
  18504. t['\uFCA3'] = '\u062A\u062E';
  18505. t['\uFCA4'] = '\u062A\u0645';
  18506. t['\uFCA5'] = '\u062A\u0647';
  18507. t['\uFCA6'] = '\u062B\u0645';
  18508. t['\uFCA7'] = '\u062C\u062D';
  18509. t['\uFCA8'] = '\u062C\u0645';
  18510. t['\uFCA9'] = '\u062D\u062C';
  18511. t['\uFCAA'] = '\u062D\u0645';
  18512. t['\uFCAB'] = '\u062E\u062C';
  18513. t['\uFCAC'] = '\u062E\u0645';
  18514. t['\uFCAD'] = '\u0633\u062C';
  18515. t['\uFCAE'] = '\u0633\u062D';
  18516. t['\uFCAF'] = '\u0633\u062E';
  18517. t['\uFCB0'] = '\u0633\u0645';
  18518. t['\uFCB1'] = '\u0635\u062D';
  18519. t['\uFCB2'] = '\u0635\u062E';
  18520. t['\uFCB3'] = '\u0635\u0645';
  18521. t['\uFCB4'] = '\u0636\u062C';
  18522. t['\uFCB5'] = '\u0636\u062D';
  18523. t['\uFCB6'] = '\u0636\u062E';
  18524. t['\uFCB7'] = '\u0636\u0645';
  18525. t['\uFCB8'] = '\u0637\u062D';
  18526. t['\uFCB9'] = '\u0638\u0645';
  18527. t['\uFCBA'] = '\u0639\u062C';
  18528. t['\uFCBB'] = '\u0639\u0645';
  18529. t['\uFCBC'] = '\u063A\u062C';
  18530. t['\uFCBD'] = '\u063A\u0645';
  18531. t['\uFCBE'] = '\u0641\u062C';
  18532. t['\uFCBF'] = '\u0641\u062D';
  18533. t['\uFCC0'] = '\u0641\u062E';
  18534. t['\uFCC1'] = '\u0641\u0645';
  18535. t['\uFCC2'] = '\u0642\u062D';
  18536. t['\uFCC3'] = '\u0642\u0645';
  18537. t['\uFCC4'] = '\u0643\u062C';
  18538. t['\uFCC5'] = '\u0643\u062D';
  18539. t['\uFCC6'] = '\u0643\u062E';
  18540. t['\uFCC7'] = '\u0643\u0644';
  18541. t['\uFCC8'] = '\u0643\u0645';
  18542. t['\uFCC9'] = '\u0644\u062C';
  18543. t['\uFCCA'] = '\u0644\u062D';
  18544. t['\uFCCB'] = '\u0644\u062E';
  18545. t['\uFCCC'] = '\u0644\u0645';
  18546. t['\uFCCD'] = '\u0644\u0647';
  18547. t['\uFCCE'] = '\u0645\u062C';
  18548. t['\uFCCF'] = '\u0645\u062D';
  18549. t['\uFCD0'] = '\u0645\u062E';
  18550. t['\uFCD1'] = '\u0645\u0645';
  18551. t['\uFCD2'] = '\u0646\u062C';
  18552. t['\uFCD3'] = '\u0646\u062D';
  18553. t['\uFCD4'] = '\u0646\u062E';
  18554. t['\uFCD5'] = '\u0646\u0645';
  18555. t['\uFCD6'] = '\u0646\u0647';
  18556. t['\uFCD7'] = '\u0647\u062C';
  18557. t['\uFCD8'] = '\u0647\u0645';
  18558. t['\uFCD9'] = '\u0647\u0670';
  18559. t['\uFCDA'] = '\u064A\u062C';
  18560. t['\uFCDB'] = '\u064A\u062D';
  18561. t['\uFCDC'] = '\u064A\u062E';
  18562. t['\uFCDD'] = '\u064A\u0645';
  18563. t['\uFCDE'] = '\u064A\u0647';
  18564. t['\uFCDF'] = '\u0626\u0645';
  18565. t['\uFCE0'] = '\u0626\u0647';
  18566. t['\uFCE1'] = '\u0628\u0645';
  18567. t['\uFCE2'] = '\u0628\u0647';
  18568. t['\uFCE3'] = '\u062A\u0645';
  18569. t['\uFCE4'] = '\u062A\u0647';
  18570. t['\uFCE5'] = '\u062B\u0645';
  18571. t['\uFCE6'] = '\u062B\u0647';
  18572. t['\uFCE7'] = '\u0633\u0645';
  18573. t['\uFCE8'] = '\u0633\u0647';
  18574. t['\uFCE9'] = '\u0634\u0645';
  18575. t['\uFCEA'] = '\u0634\u0647';
  18576. t['\uFCEB'] = '\u0643\u0644';
  18577. t['\uFCEC'] = '\u0643\u0645';
  18578. t['\uFCED'] = '\u0644\u0645';
  18579. t['\uFCEE'] = '\u0646\u0645';
  18580. t['\uFCEF'] = '\u0646\u0647';
  18581. t['\uFCF0'] = '\u064A\u0645';
  18582. t['\uFCF1'] = '\u064A\u0647';
  18583. t['\uFCF2'] = '\u0640\u064E\u0651';
  18584. t['\uFCF3'] = '\u0640\u064F\u0651';
  18585. t['\uFCF4'] = '\u0640\u0650\u0651';
  18586. t['\uFCF5'] = '\u0637\u0649';
  18587. t['\uFCF6'] = '\u0637\u064A';
  18588. t['\uFCF7'] = '\u0639\u0649';
  18589. t['\uFCF8'] = '\u0639\u064A';
  18590. t['\uFCF9'] = '\u063A\u0649';
  18591. t['\uFCFA'] = '\u063A\u064A';
  18592. t['\uFCFB'] = '\u0633\u0649';
  18593. t['\uFCFC'] = '\u0633\u064A';
  18594. t['\uFCFD'] = '\u0634\u0649';
  18595. t['\uFCFE'] = '\u0634\u064A';
  18596. t['\uFCFF'] = '\u062D\u0649';
  18597. t['\uFD00'] = '\u062D\u064A';
  18598. t['\uFD01'] = '\u062C\u0649';
  18599. t['\uFD02'] = '\u062C\u064A';
  18600. t['\uFD03'] = '\u062E\u0649';
  18601. t['\uFD04'] = '\u062E\u064A';
  18602. t['\uFD05'] = '\u0635\u0649';
  18603. t['\uFD06'] = '\u0635\u064A';
  18604. t['\uFD07'] = '\u0636\u0649';
  18605. t['\uFD08'] = '\u0636\u064A';
  18606. t['\uFD09'] = '\u0634\u062C';
  18607. t['\uFD0A'] = '\u0634\u062D';
  18608. t['\uFD0B'] = '\u0634\u062E';
  18609. t['\uFD0C'] = '\u0634\u0645';
  18610. t['\uFD0D'] = '\u0634\u0631';
  18611. t['\uFD0E'] = '\u0633\u0631';
  18612. t['\uFD0F'] = '\u0635\u0631';
  18613. t['\uFD10'] = '\u0636\u0631';
  18614. t['\uFD11'] = '\u0637\u0649';
  18615. t['\uFD12'] = '\u0637\u064A';
  18616. t['\uFD13'] = '\u0639\u0649';
  18617. t['\uFD14'] = '\u0639\u064A';
  18618. t['\uFD15'] = '\u063A\u0649';
  18619. t['\uFD16'] = '\u063A\u064A';
  18620. t['\uFD17'] = '\u0633\u0649';
  18621. t['\uFD18'] = '\u0633\u064A';
  18622. t['\uFD19'] = '\u0634\u0649';
  18623. t['\uFD1A'] = '\u0634\u064A';
  18624. t['\uFD1B'] = '\u062D\u0649';
  18625. t['\uFD1C'] = '\u062D\u064A';
  18626. t['\uFD1D'] = '\u062C\u0649';
  18627. t['\uFD1E'] = '\u062C\u064A';
  18628. t['\uFD1F'] = '\u062E\u0649';
  18629. t['\uFD20'] = '\u062E\u064A';
  18630. t['\uFD21'] = '\u0635\u0649';
  18631. t['\uFD22'] = '\u0635\u064A';
  18632. t['\uFD23'] = '\u0636\u0649';
  18633. t['\uFD24'] = '\u0636\u064A';
  18634. t['\uFD25'] = '\u0634\u062C';
  18635. t['\uFD26'] = '\u0634\u062D';
  18636. t['\uFD27'] = '\u0634\u062E';
  18637. t['\uFD28'] = '\u0634\u0645';
  18638. t['\uFD29'] = '\u0634\u0631';
  18639. t['\uFD2A'] = '\u0633\u0631';
  18640. t['\uFD2B'] = '\u0635\u0631';
  18641. t['\uFD2C'] = '\u0636\u0631';
  18642. t['\uFD2D'] = '\u0634\u062C';
  18643. t['\uFD2E'] = '\u0634\u062D';
  18644. t['\uFD2F'] = '\u0634\u062E';
  18645. t['\uFD30'] = '\u0634\u0645';
  18646. t['\uFD31'] = '\u0633\u0647';
  18647. t['\uFD32'] = '\u0634\u0647';
  18648. t['\uFD33'] = '\u0637\u0645';
  18649. t['\uFD34'] = '\u0633\u062C';
  18650. t['\uFD35'] = '\u0633\u062D';
  18651. t['\uFD36'] = '\u0633\u062E';
  18652. t['\uFD37'] = '\u0634\u062C';
  18653. t['\uFD38'] = '\u0634\u062D';
  18654. t['\uFD39'] = '\u0634\u062E';
  18655. t['\uFD3A'] = '\u0637\u0645';
  18656. t['\uFD3B'] = '\u0638\u0645';
  18657. t['\uFD3C'] = '\u0627\u064B';
  18658. t['\uFD3D'] = '\u0627\u064B';
  18659. t['\uFD50'] = '\u062A\u062C\u0645';
  18660. t['\uFD51'] = '\u062A\u062D\u062C';
  18661. t['\uFD52'] = '\u062A\u062D\u062C';
  18662. t['\uFD53'] = '\u062A\u062D\u0645';
  18663. t['\uFD54'] = '\u062A\u062E\u0645';
  18664. t['\uFD55'] = '\u062A\u0645\u062C';
  18665. t['\uFD56'] = '\u062A\u0645\u062D';
  18666. t['\uFD57'] = '\u062A\u0645\u062E';
  18667. t['\uFD58'] = '\u062C\u0645\u062D';
  18668. t['\uFD59'] = '\u062C\u0645\u062D';
  18669. t['\uFD5A'] = '\u062D\u0645\u064A';
  18670. t['\uFD5B'] = '\u062D\u0645\u0649';
  18671. t['\uFD5C'] = '\u0633\u062D\u062C';
  18672. t['\uFD5D'] = '\u0633\u062C\u062D';
  18673. t['\uFD5E'] = '\u0633\u062C\u0649';
  18674. t['\uFD5F'] = '\u0633\u0645\u062D';
  18675. t['\uFD60'] = '\u0633\u0645\u062D';
  18676. t['\uFD61'] = '\u0633\u0645\u062C';
  18677. t['\uFD62'] = '\u0633\u0645\u0645';
  18678. t['\uFD63'] = '\u0633\u0645\u0645';
  18679. t['\uFD64'] = '\u0635\u062D\u062D';
  18680. t['\uFD65'] = '\u0635\u062D\u062D';
  18681. t['\uFD66'] = '\u0635\u0645\u0645';
  18682. t['\uFD67'] = '\u0634\u062D\u0645';
  18683. t['\uFD68'] = '\u0634\u062D\u0645';
  18684. t['\uFD69'] = '\u0634\u062C\u064A';
  18685. t['\uFD6A'] = '\u0634\u0645\u062E';
  18686. t['\uFD6B'] = '\u0634\u0645\u062E';
  18687. t['\uFD6C'] = '\u0634\u0645\u0645';
  18688. t['\uFD6D'] = '\u0634\u0645\u0645';
  18689. t['\uFD6E'] = '\u0636\u062D\u0649';
  18690. t['\uFD6F'] = '\u0636\u062E\u0645';
  18691. t['\uFD70'] = '\u0636\u062E\u0645';
  18692. t['\uFD71'] = '\u0637\u0645\u062D';
  18693. t['\uFD72'] = '\u0637\u0645\u062D';
  18694. t['\uFD73'] = '\u0637\u0645\u0645';
  18695. t['\uFD74'] = '\u0637\u0645\u064A';
  18696. t['\uFD75'] = '\u0639\u062C\u0645';
  18697. t['\uFD76'] = '\u0639\u0645\u0645';
  18698. t['\uFD77'] = '\u0639\u0645\u0645';
  18699. t['\uFD78'] = '\u0639\u0645\u0649';
  18700. t['\uFD79'] = '\u063A\u0645\u0645';
  18701. t['\uFD7A'] = '\u063A\u0645\u064A';
  18702. t['\uFD7B'] = '\u063A\u0645\u0649';
  18703. t['\uFD7C'] = '\u0641\u062E\u0645';
  18704. t['\uFD7D'] = '\u0641\u062E\u0645';
  18705. t['\uFD7E'] = '\u0642\u0645\u062D';
  18706. t['\uFD7F'] = '\u0642\u0645\u0645';
  18707. t['\uFD80'] = '\u0644\u062D\u0645';
  18708. t['\uFD81'] = '\u0644\u062D\u064A';
  18709. t['\uFD82'] = '\u0644\u062D\u0649';
  18710. t['\uFD83'] = '\u0644\u062C\u062C';
  18711. t['\uFD84'] = '\u0644\u062C\u062C';
  18712. t['\uFD85'] = '\u0644\u062E\u0645';
  18713. t['\uFD86'] = '\u0644\u062E\u0645';
  18714. t['\uFD87'] = '\u0644\u0645\u062D';
  18715. t['\uFD88'] = '\u0644\u0645\u062D';
  18716. t['\uFD89'] = '\u0645\u062D\u062C';
  18717. t['\uFD8A'] = '\u0645\u062D\u0645';
  18718. t['\uFD8B'] = '\u0645\u062D\u064A';
  18719. t['\uFD8C'] = '\u0645\u062C\u062D';
  18720. t['\uFD8D'] = '\u0645\u062C\u0645';
  18721. t['\uFD8E'] = '\u0645\u062E\u062C';
  18722. t['\uFD8F'] = '\u0645\u062E\u0645';
  18723. t['\uFD92'] = '\u0645\u062C\u062E';
  18724. t['\uFD93'] = '\u0647\u0645\u062C';
  18725. t['\uFD94'] = '\u0647\u0645\u0645';
  18726. t['\uFD95'] = '\u0646\u062D\u0645';
  18727. t['\uFD96'] = '\u0646\u062D\u0649';
  18728. t['\uFD97'] = '\u0646\u062C\u0645';
  18729. t['\uFD98'] = '\u0646\u062C\u0645';
  18730. t['\uFD99'] = '\u0646\u062C\u0649';
  18731. t['\uFD9A'] = '\u0646\u0645\u064A';
  18732. t['\uFD9B'] = '\u0646\u0645\u0649';
  18733. t['\uFD9C'] = '\u064A\u0645\u0645';
  18734. t['\uFD9D'] = '\u064A\u0645\u0645';
  18735. t['\uFD9E'] = '\u0628\u062E\u064A';
  18736. t['\uFD9F'] = '\u062A\u062C\u064A';
  18737. t['\uFDA0'] = '\u062A\u062C\u0649';
  18738. t['\uFDA1'] = '\u062A\u062E\u064A';
  18739. t['\uFDA2'] = '\u062A\u062E\u0649';
  18740. t['\uFDA3'] = '\u062A\u0645\u064A';
  18741. t['\uFDA4'] = '\u062A\u0645\u0649';
  18742. t['\uFDA5'] = '\u062C\u0645\u064A';
  18743. t['\uFDA6'] = '\u062C\u062D\u0649';
  18744. t['\uFDA7'] = '\u062C\u0645\u0649';
  18745. t['\uFDA8'] = '\u0633\u062E\u0649';
  18746. t['\uFDA9'] = '\u0635\u062D\u064A';
  18747. t['\uFDAA'] = '\u0634\u062D\u064A';
  18748. t['\uFDAB'] = '\u0636\u062D\u064A';
  18749. t['\uFDAC'] = '\u0644\u062C\u064A';
  18750. t['\uFDAD'] = '\u0644\u0645\u064A';
  18751. t['\uFDAE'] = '\u064A\u062D\u064A';
  18752. t['\uFDAF'] = '\u064A\u062C\u064A';
  18753. t['\uFDB0'] = '\u064A\u0645\u064A';
  18754. t['\uFDB1'] = '\u0645\u0645\u064A';
  18755. t['\uFDB2'] = '\u0642\u0645\u064A';
  18756. t['\uFDB3'] = '\u0646\u062D\u064A';
  18757. t['\uFDB4'] = '\u0642\u0645\u062D';
  18758. t['\uFDB5'] = '\u0644\u062D\u0645';
  18759. t['\uFDB6'] = '\u0639\u0645\u064A';
  18760. t['\uFDB7'] = '\u0643\u0645\u064A';
  18761. t['\uFDB8'] = '\u0646\u062C\u062D';
  18762. t['\uFDB9'] = '\u0645\u062E\u064A';
  18763. t['\uFDBA'] = '\u0644\u062C\u0645';
  18764. t['\uFDBB'] = '\u0643\u0645\u0645';
  18765. t['\uFDBC'] = '\u0644\u062C\u0645';
  18766. t['\uFDBD'] = '\u0646\u062C\u062D';
  18767. t['\uFDBE'] = '\u062C\u062D\u064A';
  18768. t['\uFDBF'] = '\u062D\u062C\u064A';
  18769. t['\uFDC0'] = '\u0645\u062C\u064A';
  18770. t['\uFDC1'] = '\u0641\u0645\u064A';
  18771. t['\uFDC2'] = '\u0628\u062D\u064A';
  18772. t['\uFDC3'] = '\u0643\u0645\u0645';
  18773. t['\uFDC4'] = '\u0639\u062C\u0645';
  18774. t['\uFDC5'] = '\u0635\u0645\u0645';
  18775. t['\uFDC6'] = '\u0633\u062E\u064A';
  18776. t['\uFDC7'] = '\u0646\u062C\u064A';
  18777. t['\uFE49'] = '\u203E';
  18778. t['\uFE4A'] = '\u203E';
  18779. t['\uFE4B'] = '\u203E';
  18780. t['\uFE4C'] = '\u203E';
  18781. t['\uFE4D'] = '\u005F';
  18782. t['\uFE4E'] = '\u005F';
  18783. t['\uFE4F'] = '\u005F';
  18784. t['\uFE80'] = '\u0621';
  18785. t['\uFE81'] = '\u0622';
  18786. t['\uFE82'] = '\u0622';
  18787. t['\uFE83'] = '\u0623';
  18788. t['\uFE84'] = '\u0623';
  18789. t['\uFE85'] = '\u0624';
  18790. t['\uFE86'] = '\u0624';
  18791. t['\uFE87'] = '\u0625';
  18792. t['\uFE88'] = '\u0625';
  18793. t['\uFE89'] = '\u0626';
  18794. t['\uFE8A'] = '\u0626';
  18795. t['\uFE8B'] = '\u0626';
  18796. t['\uFE8C'] = '\u0626';
  18797. t['\uFE8D'] = '\u0627';
  18798. t['\uFE8E'] = '\u0627';
  18799. t['\uFE8F'] = '\u0628';
  18800. t['\uFE90'] = '\u0628';
  18801. t['\uFE91'] = '\u0628';
  18802. t['\uFE92'] = '\u0628';
  18803. t['\uFE93'] = '\u0629';
  18804. t['\uFE94'] = '\u0629';
  18805. t['\uFE95'] = '\u062A';
  18806. t['\uFE96'] = '\u062A';
  18807. t['\uFE97'] = '\u062A';
  18808. t['\uFE98'] = '\u062A';
  18809. t['\uFE99'] = '\u062B';
  18810. t['\uFE9A'] = '\u062B';
  18811. t['\uFE9B'] = '\u062B';
  18812. t['\uFE9C'] = '\u062B';
  18813. t['\uFE9D'] = '\u062C';
  18814. t['\uFE9E'] = '\u062C';
  18815. t['\uFE9F'] = '\u062C';
  18816. t['\uFEA0'] = '\u062C';
  18817. t['\uFEA1'] = '\u062D';
  18818. t['\uFEA2'] = '\u062D';
  18819. t['\uFEA3'] = '\u062D';
  18820. t['\uFEA4'] = '\u062D';
  18821. t['\uFEA5'] = '\u062E';
  18822. t['\uFEA6'] = '\u062E';
  18823. t['\uFEA7'] = '\u062E';
  18824. t['\uFEA8'] = '\u062E';
  18825. t['\uFEA9'] = '\u062F';
  18826. t['\uFEAA'] = '\u062F';
  18827. t['\uFEAB'] = '\u0630';
  18828. t['\uFEAC'] = '\u0630';
  18829. t['\uFEAD'] = '\u0631';
  18830. t['\uFEAE'] = '\u0631';
  18831. t['\uFEAF'] = '\u0632';
  18832. t['\uFEB0'] = '\u0632';
  18833. t['\uFEB1'] = '\u0633';
  18834. t['\uFEB2'] = '\u0633';
  18835. t['\uFEB3'] = '\u0633';
  18836. t['\uFEB4'] = '\u0633';
  18837. t['\uFEB5'] = '\u0634';
  18838. t['\uFEB6'] = '\u0634';
  18839. t['\uFEB7'] = '\u0634';
  18840. t['\uFEB8'] = '\u0634';
  18841. t['\uFEB9'] = '\u0635';
  18842. t['\uFEBA'] = '\u0635';
  18843. t['\uFEBB'] = '\u0635';
  18844. t['\uFEBC'] = '\u0635';
  18845. t['\uFEBD'] = '\u0636';
  18846. t['\uFEBE'] = '\u0636';
  18847. t['\uFEBF'] = '\u0636';
  18848. t['\uFEC0'] = '\u0636';
  18849. t['\uFEC1'] = '\u0637';
  18850. t['\uFEC2'] = '\u0637';
  18851. t['\uFEC3'] = '\u0637';
  18852. t['\uFEC4'] = '\u0637';
  18853. t['\uFEC5'] = '\u0638';
  18854. t['\uFEC6'] = '\u0638';
  18855. t['\uFEC7'] = '\u0638';
  18856. t['\uFEC8'] = '\u0638';
  18857. t['\uFEC9'] = '\u0639';
  18858. t['\uFECA'] = '\u0639';
  18859. t['\uFECB'] = '\u0639';
  18860. t['\uFECC'] = '\u0639';
  18861. t['\uFECD'] = '\u063A';
  18862. t['\uFECE'] = '\u063A';
  18863. t['\uFECF'] = '\u063A';
  18864. t['\uFED0'] = '\u063A';
  18865. t['\uFED1'] = '\u0641';
  18866. t['\uFED2'] = '\u0641';
  18867. t['\uFED3'] = '\u0641';
  18868. t['\uFED4'] = '\u0641';
  18869. t['\uFED5'] = '\u0642';
  18870. t['\uFED6'] = '\u0642';
  18871. t['\uFED7'] = '\u0642';
  18872. t['\uFED8'] = '\u0642';
  18873. t['\uFED9'] = '\u0643';
  18874. t['\uFEDA'] = '\u0643';
  18875. t['\uFEDB'] = '\u0643';
  18876. t['\uFEDC'] = '\u0643';
  18877. t['\uFEDD'] = '\u0644';
  18878. t['\uFEDE'] = '\u0644';
  18879. t['\uFEDF'] = '\u0644';
  18880. t['\uFEE0'] = '\u0644';
  18881. t['\uFEE1'] = '\u0645';
  18882. t['\uFEE2'] = '\u0645';
  18883. t['\uFEE3'] = '\u0645';
  18884. t['\uFEE4'] = '\u0645';
  18885. t['\uFEE5'] = '\u0646';
  18886. t['\uFEE6'] = '\u0646';
  18887. t['\uFEE7'] = '\u0646';
  18888. t['\uFEE8'] = '\u0646';
  18889. t['\uFEE9'] = '\u0647';
  18890. t['\uFEEA'] = '\u0647';
  18891. t['\uFEEB'] = '\u0647';
  18892. t['\uFEEC'] = '\u0647';
  18893. t['\uFEED'] = '\u0648';
  18894. t['\uFEEE'] = '\u0648';
  18895. t['\uFEEF'] = '\u0649';
  18896. t['\uFEF0'] = '\u0649';
  18897. t['\uFEF1'] = '\u064A';
  18898. t['\uFEF2'] = '\u064A';
  18899. t['\uFEF3'] = '\u064A';
  18900. t['\uFEF4'] = '\u064A';
  18901. t['\uFEF5'] = '\u0644\u0622';
  18902. t['\uFEF6'] = '\u0644\u0622';
  18903. t['\uFEF7'] = '\u0644\u0623';
  18904. t['\uFEF8'] = '\u0644\u0623';
  18905. t['\uFEF9'] = '\u0644\u0625';
  18906. t['\uFEFA'] = '\u0644\u0625';
  18907. t['\uFEFB'] = '\u0644\u0627';
  18908. t['\uFEFC'] = '\u0644\u0627';
  18909. });
  18910. function reverseIfRtl(chars) {
  18911. var charsLength = chars.length;
  18912. //reverse an arabic ligature
  18913. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18914. return chars;
  18915. }
  18916. var s = '';
  18917. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18918. s += chars[ii];
  18919. }
  18920. return s;
  18921. }
  18922. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18923. exports.reverseIfRtl = reverseIfRtl;
  18924. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18925. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18926. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18927. }));
  18928. (function (root, factory) {
  18929. {
  18930. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedUtil);
  18931. }
  18932. }(this, function (exports, sharedUtil) {
  18933. var removeNullCharacters = sharedUtil.removeNullCharacters;
  18934. var warn = sharedUtil.warn;
  18935. /**
  18936. * Optimised CSS custom property getter/setter.
  18937. * @class
  18938. */
  18939. var CustomStyle = (function CustomStyleClosure() {
  18940. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  18941. // animate-css-transforms-firefox-webkit.html
  18942. // in some versions of IE9 it is critical that ms appear in this list
  18943. // before Moz
  18944. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  18945. var _cache = Object.create(null);
  18946. function CustomStyle() {}
  18947. CustomStyle.getProp = function get(propName, element) {
  18948. // check cache only when no element is given
  18949. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  18950. return _cache[propName];
  18951. }
  18952. element = element || document.documentElement;
  18953. var style = element.style, prefixed, uPropName;
  18954. // test standard property first
  18955. if (typeof style[propName] === 'string') {
  18956. return (_cache[propName] = propName);
  18957. }
  18958. // capitalize
  18959. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  18960. // test vendor specific properties
  18961. for (var i = 0, l = prefixes.length; i < l; i++) {
  18962. prefixed = prefixes[i] + uPropName;
  18963. if (typeof style[prefixed] === 'string') {
  18964. return (_cache[propName] = prefixed);
  18965. }
  18966. }
  18967. //if all fails then set to undefined
  18968. return (_cache[propName] = 'undefined');
  18969. };
  18970. CustomStyle.setProp = function set(propName, element, str) {
  18971. var prop = this.getProp(propName);
  18972. if (prop !== 'undefined') {
  18973. element.style[prop] = str;
  18974. }
  18975. };
  18976. return CustomStyle;
  18977. })();
  18978. function hasCanvasTypedArrays() {
  18979. var canvas = document.createElement('canvas');
  18980. canvas.width = canvas.height = 1;
  18981. var ctx = canvas.getContext('2d');
  18982. var imageData = ctx.createImageData(1, 1);
  18983. return (typeof imageData.data.buffer !== 'undefined');
  18984. }
  18985. var LinkTarget = {
  18986. NONE: 0, // Default value.
  18987. SELF: 1,
  18988. BLANK: 2,
  18989. PARENT: 3,
  18990. TOP: 4,
  18991. };
  18992. var LinkTargetStringMap = [
  18993. '',
  18994. '_self',
  18995. '_blank',
  18996. '_parent',
  18997. '_top'
  18998. ];
  18999. /**
  19000. * @typedef ExternalLinkParameters
  19001. * @typedef {Object} ExternalLinkParameters
  19002. * @property {string} url - An absolute URL.
  19003. * @property {LinkTarget} target - The link target.
  19004. * @property {string} rel - The link relationship.
  19005. */
  19006. /**
  19007. * Adds various attributes (href, title, target, rel) to hyperlinks.
  19008. * @param {HTMLLinkElement} link - The link element.
  19009. * @param {ExternalLinkParameters} params
  19010. */
  19011. function addLinkAttributes(link, params) {
  19012. var url = params && params.url;
  19013. link.href = link.title = (url ? removeNullCharacters(url) : '');
  19014. if (url) {
  19015. var target = params.target;
  19016. if (typeof target === 'undefined') {
  19017. target = getDefaultSetting('externalLinkTarget');
  19018. }
  19019. link.target = LinkTargetStringMap[target];
  19020. var rel = params.rel;
  19021. if (typeof rel === 'undefined') {
  19022. rel = getDefaultSetting('externalLinkRel');
  19023. }
  19024. link.rel = rel;
  19025. }
  19026. }
  19027. // Gets the file name from a given URL.
  19028. function getFilenameFromUrl(url) {
  19029. var anchor = url.indexOf('#');
  19030. var query = url.indexOf('?');
  19031. var end = Math.min(
  19032. anchor > 0 ? anchor : url.length,
  19033. query > 0 ? query : url.length);
  19034. return url.substring(url.lastIndexOf('/', end) + 1, end);
  19035. }
  19036. function getDefaultSetting(id) {
  19037. // The list of the settings and their default is maintained for backward
  19038. // compatibility and shall not be extended or modified. See also global.js.
  19039. var globalSettings = sharedUtil.globalScope.PDFJS;
  19040. switch (id) {
  19041. case 'pdfBug':
  19042. return globalSettings ? globalSettings.pdfBug : false;
  19043. case 'disableAutoFetch':
  19044. return globalSettings ? globalSettings.disableAutoFetch : false;
  19045. case 'disableStream':
  19046. return globalSettings ? globalSettings.disableStream : false;
  19047. case 'disableRange':
  19048. return globalSettings ? globalSettings.disableRange : false;
  19049. case 'disableFontFace':
  19050. return globalSettings ? globalSettings.disableFontFace : false;
  19051. case 'disableCreateObjectURL':
  19052. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  19053. case 'disableWebGL':
  19054. return globalSettings ? globalSettings.disableWebGL : true;
  19055. case 'cMapUrl':
  19056. return globalSettings ? globalSettings.cMapUrl : null;
  19057. case 'cMapPacked':
  19058. return globalSettings ? globalSettings.cMapPacked : false;
  19059. case 'postMessageTransfers':
  19060. return globalSettings ? globalSettings.postMessageTransfers : true;
  19061. case 'workerSrc':
  19062. return globalSettings ? globalSettings.workerSrc : null;
  19063. case 'disableWorker':
  19064. return globalSettings ? globalSettings.disableWorker : false;
  19065. case 'maxImageSize':
  19066. return globalSettings ? globalSettings.maxImageSize : -1;
  19067. case 'imageResourcesPath':
  19068. return globalSettings ? globalSettings.imageResourcesPath : '';
  19069. case 'isEvalSupported':
  19070. return globalSettings ? globalSettings.isEvalSupported : true;
  19071. case 'externalLinkTarget':
  19072. if (!globalSettings) {
  19073. return LinkTarget.NONE;
  19074. }
  19075. switch (globalSettings.externalLinkTarget) {
  19076. case LinkTarget.NONE:
  19077. case LinkTarget.SELF:
  19078. case LinkTarget.BLANK:
  19079. case LinkTarget.PARENT:
  19080. case LinkTarget.TOP:
  19081. return globalSettings.externalLinkTarget;
  19082. }
  19083. warn('PDFJS.externalLinkTarget is invalid: ' +
  19084. globalSettings.externalLinkTarget);
  19085. // Reset the external link target, to suppress further warnings.
  19086. globalSettings.externalLinkTarget = LinkTarget.NONE;
  19087. return LinkTarget.NONE;
  19088. case 'externalLinkRel':
  19089. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  19090. case 'enableStats':
  19091. return !!(globalSettings && globalSettings.enableStats);
  19092. default:
  19093. throw new Error('Unknown default setting: ' + id);
  19094. }
  19095. }
  19096. function isExternalLinkTargetSet() {
  19097. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  19098. switch (externalLinkTarget) {
  19099. case LinkTarget.NONE:
  19100. return false;
  19101. case LinkTarget.SELF:
  19102. case LinkTarget.BLANK:
  19103. case LinkTarget.PARENT:
  19104. case LinkTarget.TOP:
  19105. return true;
  19106. }
  19107. }
  19108. exports.CustomStyle = CustomStyle;
  19109. exports.addLinkAttributes = addLinkAttributes;
  19110. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  19111. exports.getFilenameFromUrl = getFilenameFromUrl;
  19112. exports.LinkTarget = LinkTarget;
  19113. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  19114. exports.getDefaultSetting = getDefaultSetting;
  19115. }));
  19116. (function (root, factory) {
  19117. {
  19118. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil);
  19119. }
  19120. }(this, function (exports, sharedUtil) {
  19121. var assert = sharedUtil.assert;
  19122. var bytesToString = sharedUtil.bytesToString;
  19123. var string32 = sharedUtil.string32;
  19124. var shadow = sharedUtil.shadow;
  19125. var warn = sharedUtil.warn;
  19126. function FontLoader(docId) {
  19127. this.docId = docId;
  19128. this.styleElement = null;
  19129. this.nativeFontFaces = [];
  19130. this.loadTestFontId = 0;
  19131. this.loadingContext = {
  19132. requests: [],
  19133. nextRequestId: 0
  19134. };
  19135. }
  19136. FontLoader.prototype = {
  19137. insertRule: function fontLoaderInsertRule(rule) {
  19138. var styleElement = this.styleElement;
  19139. if (!styleElement) {
  19140. styleElement = this.styleElement = document.createElement('style');
  19141. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  19142. document.documentElement.getElementsByTagName('head')[0].appendChild(
  19143. styleElement);
  19144. }
  19145. var styleSheet = styleElement.sheet;
  19146. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  19147. },
  19148. clear: function fontLoaderClear() {
  19149. var styleElement = this.styleElement;
  19150. if (styleElement) {
  19151. styleElement.parentNode.removeChild(styleElement);
  19152. styleElement = this.styleElement = null;
  19153. }
  19154. this.nativeFontFaces.forEach(function(nativeFontFace) {
  19155. document.fonts.delete(nativeFontFace);
  19156. });
  19157. this.nativeFontFaces.length = 0;
  19158. },
  19159. get loadTestFont() {
  19160. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  19161. // height.
  19162. return shadow(this, 'loadTestFont', atob(
  19163. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  19164. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  19165. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  19166. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  19167. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  19168. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  19169. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  19170. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  19171. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  19172. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  19173. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  19174. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  19175. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  19176. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19177. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19178. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19179. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  19180. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  19181. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  19182. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  19183. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  19184. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  19185. ));
  19186. },
  19187. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  19188. this.nativeFontFaces.push(nativeFontFace);
  19189. document.fonts.add(nativeFontFace);
  19190. },
  19191. bind: function fontLoaderBind(fonts, callback) {
  19192. var rules = [];
  19193. var fontsToLoad = [];
  19194. var fontLoadPromises = [];
  19195. var getNativeFontPromise = function(nativeFontFace) {
  19196. // Return a promise that is always fulfilled, even when the font fails to
  19197. // load.
  19198. return nativeFontFace.loaded.catch(function(e) {
  19199. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  19200. });
  19201. };
  19202. for (var i = 0, ii = fonts.length; i < ii; i++) {
  19203. var font = fonts[i];
  19204. // Add the font to the DOM only once or skip if the font
  19205. // is already loaded.
  19206. if (font.attached || font.loading === false) {
  19207. continue;
  19208. }
  19209. font.attached = true;
  19210. if (FontLoader.isFontLoadingAPISupported) {
  19211. var nativeFontFace = font.createNativeFontFace();
  19212. if (nativeFontFace) {
  19213. this.addNativeFontFace(nativeFontFace);
  19214. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  19215. }
  19216. } else {
  19217. var rule = font.createFontFaceRule();
  19218. if (rule) {
  19219. this.insertRule(rule);
  19220. rules.push(rule);
  19221. fontsToLoad.push(font);
  19222. }
  19223. }
  19224. }
  19225. var request = this.queueLoadingCallback(callback);
  19226. if (FontLoader.isFontLoadingAPISupported) {
  19227. Promise.all(fontLoadPromises).then(function() {
  19228. request.complete();
  19229. });
  19230. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  19231. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  19232. } else {
  19233. request.complete();
  19234. }
  19235. },
  19236. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  19237. function LoadLoader_completeRequest() {
  19238. assert(!request.end, 'completeRequest() cannot be called twice');
  19239. request.end = Date.now();
  19240. // sending all completed requests in order how they were queued
  19241. while (context.requests.length > 0 && context.requests[0].end) {
  19242. var otherRequest = context.requests.shift();
  19243. setTimeout(otherRequest.callback, 0);
  19244. }
  19245. }
  19246. var context = this.loadingContext;
  19247. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  19248. var request = {
  19249. id: requestId,
  19250. complete: LoadLoader_completeRequest,
  19251. callback: callback,
  19252. started: Date.now()
  19253. };
  19254. context.requests.push(request);
  19255. return request;
  19256. },
  19257. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  19258. fonts,
  19259. request) {
  19260. /** Hack begin */
  19261. // There's currently no event when a font has finished downloading so the
  19262. // following code is a dirty hack to 'guess' when a font is
  19263. // ready. It's assumed fonts are loaded in order, so add a known test
  19264. // font after the desired fonts and then test for the loading of that
  19265. // test font.
  19266. function int32(data, offset) {
  19267. return (data.charCodeAt(offset) << 24) |
  19268. (data.charCodeAt(offset + 1) << 16) |
  19269. (data.charCodeAt(offset + 2) << 8) |
  19270. (data.charCodeAt(offset + 3) & 0xff);
  19271. }
  19272. function spliceString(s, offset, remove, insert) {
  19273. var chunk1 = s.substr(0, offset);
  19274. var chunk2 = s.substr(offset + remove);
  19275. return chunk1 + insert + chunk2;
  19276. }
  19277. var i, ii;
  19278. var canvas = document.createElement('canvas');
  19279. canvas.width = 1;
  19280. canvas.height = 1;
  19281. var ctx = canvas.getContext('2d');
  19282. var called = 0;
  19283. function isFontReady(name, callback) {
  19284. called++;
  19285. // With setTimeout clamping this gives the font ~100ms to load.
  19286. if(called > 30) {
  19287. warn('Load test font never loaded.');
  19288. callback();
  19289. return;
  19290. }
  19291. ctx.font = '30px ' + name;
  19292. ctx.fillText('.', 0, 20);
  19293. var imageData = ctx.getImageData(0, 0, 1, 1);
  19294. if (imageData.data[3] > 0) {
  19295. callback();
  19296. return;
  19297. }
  19298. setTimeout(isFontReady.bind(null, name, callback));
  19299. }
  19300. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  19301. // Chromium seems to cache fonts based on a hash of the actual font data,
  19302. // so the font must be modified for each load test else it will appear to
  19303. // be loaded already.
  19304. // TODO: This could maybe be made faster by avoiding the btoa of the full
  19305. // font by splitting it in chunks before hand and padding the font id.
  19306. var data = this.loadTestFont;
  19307. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  19308. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  19309. loadTestFontId);
  19310. // CFF checksum is important for IE, adjusting it
  19311. var CFF_CHECKSUM_OFFSET = 16;
  19312. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  19313. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  19314. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  19315. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  19316. }
  19317. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  19318. checksum = (checksum - XXXX_VALUE +
  19319. int32(loadTestFontId + 'XXX', i)) | 0;
  19320. }
  19321. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  19322. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  19323. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  19324. url + '}';
  19325. this.insertRule(rule);
  19326. var names = [];
  19327. for (i = 0, ii = fonts.length; i < ii; i++) {
  19328. names.push(fonts[i].loadedName);
  19329. }
  19330. names.push(loadTestFontId);
  19331. var div = document.createElement('div');
  19332. div.setAttribute('style',
  19333. 'visibility: hidden;' +
  19334. 'width: 10px; height: 10px;' +
  19335. 'position: absolute; top: 0px; left: 0px;');
  19336. for (i = 0, ii = names.length; i < ii; ++i) {
  19337. var span = document.createElement('span');
  19338. span.textContent = 'Hi';
  19339. span.style.fontFamily = names[i];
  19340. div.appendChild(span);
  19341. }
  19342. document.body.appendChild(div);
  19343. isFontReady(loadTestFontId, function() {
  19344. document.body.removeChild(div);
  19345. request.complete();
  19346. });
  19347. /** Hack end */
  19348. }
  19349. };
  19350. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
  19351. !!document.fonts;
  19352. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  19353. get: function () {
  19354. if (typeof navigator === 'undefined') {
  19355. // node.js - we can pretend sync font loading is supported.
  19356. return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
  19357. }
  19358. var supported = false;
  19359. // User agent string sniffing is bad, but there is no reliable way to tell
  19360. // if font is fully loaded and ready to be used with canvas.
  19361. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  19362. if (m && m[1] >= 14) {
  19363. supported = true;
  19364. }
  19365. // TODO other browsers
  19366. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  19367. },
  19368. enumerable: true,
  19369. configurable: true
  19370. });
  19371. var IsEvalSupportedCached = {
  19372. get value() {
  19373. return shadow(this, 'value', sharedUtil.isEvalSupported());
  19374. }
  19375. };
  19376. var FontFaceObject = (function FontFaceObjectClosure() {
  19377. function FontFaceObject(translatedData, options) {
  19378. this.compiledGlyphs = Object.create(null);
  19379. // importing translated data
  19380. for (var i in translatedData) {
  19381. this[i] = translatedData[i];
  19382. }
  19383. this.options = options;
  19384. }
  19385. FontFaceObject.prototype = {
  19386. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  19387. if (!this.data) {
  19388. return null;
  19389. }
  19390. if (this.options.disableFontFace) {
  19391. this.disableFontFace = true;
  19392. return null;
  19393. }
  19394. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  19395. if (this.options.fontRegistry) {
  19396. this.options.fontRegistry.registerFont(this);
  19397. }
  19398. return nativeFontFace;
  19399. },
  19400. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  19401. if (!this.data) {
  19402. return null;
  19403. }
  19404. if (this.options.disableFontFace) {
  19405. this.disableFontFace = true;
  19406. return null;
  19407. }
  19408. var data = bytesToString(new Uint8Array(this.data));
  19409. var fontName = this.loadedName;
  19410. // Add the font-face rule to the document
  19411. var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
  19412. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  19413. if (this.options.fontRegistry) {
  19414. this.options.fontRegistry.registerFont(this, url);
  19415. }
  19416. return rule;
  19417. },
  19418. getPathGenerator:
  19419. function FontFaceObject_getPathGenerator(objs, character) {
  19420. if (!(character in this.compiledGlyphs)) {
  19421. var cmds = objs.get(this.loadedName + '_path_' + character);
  19422. var current, i, len;
  19423. // If we can, compile cmds into JS for MAXIMUM SPEED
  19424. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  19425. var args, js = '';
  19426. for (i = 0, len = cmds.length; i < len; i++) {
  19427. current = cmds[i];
  19428. if (current.args !== undefined) {
  19429. args = current.args.join(',');
  19430. } else {
  19431. args = '';
  19432. }
  19433. js += 'c.' + current.cmd + '(' + args + ');\n';
  19434. }
  19435. /* jshint -W054 */
  19436. this.compiledGlyphs[character] = new Function('c', 'size', js);
  19437. } else {
  19438. // But fall back on using Function.prototype.apply() if we're
  19439. // blocked from using eval() for whatever reason (like CSP policies)
  19440. this.compiledGlyphs[character] = function(c, size) {
  19441. for (i = 0, len = cmds.length; i < len; i++) {
  19442. current = cmds[i];
  19443. if (current.cmd === 'scale') {
  19444. current.args = [size, -size];
  19445. }
  19446. c[current.cmd].apply(c, current.args);
  19447. }
  19448. };
  19449. }
  19450. }
  19451. return this.compiledGlyphs[character];
  19452. }
  19453. };
  19454. return FontFaceObject;
  19455. })();
  19456. exports.FontFaceObject = FontFaceObject;
  19457. exports.FontLoader = FontLoader;
  19458. }));
  19459. (function (root, factory) {
  19460. {
  19461. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  19462. }
  19463. }(this, function (exports, sharedUtil) {
  19464. var error = sharedUtil.error;
  19465. function fixMetadata(meta) {
  19466. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  19467. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  19468. function(code, d1, d2, d3) {
  19469. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  19470. });
  19471. var chars = '';
  19472. for (var i = 0; i < bytes.length; i += 2) {
  19473. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  19474. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  19475. code !== 38 && false ? String.fromCharCode(code) :
  19476. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  19477. }
  19478. return '>' + chars;
  19479. });
  19480. }
  19481. function Metadata(meta) {
  19482. if (typeof meta === 'string') {
  19483. // Ghostscript produces invalid metadata
  19484. meta = fixMetadata(meta);
  19485. var parser = new DOMParser();
  19486. meta = parser.parseFromString(meta, 'application/xml');
  19487. } else if (!(meta instanceof Document)) {
  19488. error('Metadata: Invalid metadata object');
  19489. }
  19490. this.metaDocument = meta;
  19491. this.metadata = Object.create(null);
  19492. this.parse();
  19493. }
  19494. Metadata.prototype = {
  19495. parse: function Metadata_parse() {
  19496. var doc = this.metaDocument;
  19497. var rdf = doc.documentElement;
  19498. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  19499. rdf = rdf.firstChild;
  19500. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  19501. rdf = rdf.nextSibling;
  19502. }
  19503. }
  19504. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  19505. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  19506. return;
  19507. }
  19508. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  19509. for (i = 0, length = children.length; i < length; i++) {
  19510. desc = children[i];
  19511. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  19512. continue;
  19513. }
  19514. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  19515. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  19516. entry = desc.childNodes[ii];
  19517. name = entry.nodeName.toLowerCase();
  19518. this.metadata[name] = entry.textContent.trim();
  19519. }
  19520. }
  19521. }
  19522. },
  19523. get: function Metadata_get(name) {
  19524. return this.metadata[name] || null;
  19525. },
  19526. has: function Metadata_has(name) {
  19527. return typeof this.metadata[name] !== 'undefined';
  19528. }
  19529. };
  19530. exports.Metadata = Metadata;
  19531. }));
  19532. (function (root, factory) {
  19533. {
  19534. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  19535. }
  19536. }(this, function (exports, sharedUtil) {
  19537. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  19538. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  19539. var ImageKind = sharedUtil.ImageKind;
  19540. var OPS = sharedUtil.OPS;
  19541. var Util = sharedUtil.Util;
  19542. var isNum = sharedUtil.isNum;
  19543. var isArray = sharedUtil.isArray;
  19544. var warn = sharedUtil.warn;
  19545. var createObjectURL = sharedUtil.createObjectURL;
  19546. var SVG_DEFAULTS = {
  19547. fontStyle: 'normal',
  19548. fontWeight: 'normal',
  19549. fillColor: '#000000'
  19550. };
  19551. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  19552. var PNG_HEADER =
  19553. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  19554. var CHUNK_WRAPPER_SIZE = 12;
  19555. var crcTable = new Int32Array(256);
  19556. for (var i = 0; i < 256; i++) {
  19557. var c = i;
  19558. for (var h = 0; h < 8; h++) {
  19559. if (c & 1) {
  19560. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  19561. } else {
  19562. c = (c >> 1) & 0x7fffffff;
  19563. }
  19564. }
  19565. crcTable[i] = c;
  19566. }
  19567. function crc32(data, start, end) {
  19568. var crc = -1;
  19569. for (var i = start; i < end; i++) {
  19570. var a = (crc ^ data[i]) & 0xff;
  19571. var b = crcTable[a];
  19572. crc = (crc >>> 8) ^ b;
  19573. }
  19574. return crc ^ -1;
  19575. }
  19576. function writePngChunk(type, body, data, offset) {
  19577. var p = offset;
  19578. var len = body.length;
  19579. data[p] = len >> 24 & 0xff;
  19580. data[p + 1] = len >> 16 & 0xff;
  19581. data[p + 2] = len >> 8 & 0xff;
  19582. data[p + 3] = len & 0xff;
  19583. p += 4;
  19584. data[p] = type.charCodeAt(0) & 0xff;
  19585. data[p + 1] = type.charCodeAt(1) & 0xff;
  19586. data[p + 2] = type.charCodeAt(2) & 0xff;
  19587. data[p + 3] = type.charCodeAt(3) & 0xff;
  19588. p += 4;
  19589. data.set(body, p);
  19590. p += body.length;
  19591. var crc = crc32(data, offset + 4, p);
  19592. data[p] = crc >> 24 & 0xff;
  19593. data[p + 1] = crc >> 16 & 0xff;
  19594. data[p + 2] = crc >> 8 & 0xff;
  19595. data[p + 3] = crc & 0xff;
  19596. }
  19597. function adler32(data, start, end) {
  19598. var a = 1;
  19599. var b = 0;
  19600. for (var i = start; i < end; ++i) {
  19601. a = (a + (data[i] & 0xff)) % 65521;
  19602. b = (b + a) % 65521;
  19603. }
  19604. return (b << 16) | a;
  19605. }
  19606. function encode(imgData, kind, forceDataSchema) {
  19607. var width = imgData.width;
  19608. var height = imgData.height;
  19609. var bitDepth, colorType, lineSize;
  19610. var bytes = imgData.data;
  19611. switch (kind) {
  19612. case ImageKind.GRAYSCALE_1BPP:
  19613. colorType = 0;
  19614. bitDepth = 1;
  19615. lineSize = (width + 7) >> 3;
  19616. break;
  19617. case ImageKind.RGB_24BPP:
  19618. colorType = 2;
  19619. bitDepth = 8;
  19620. lineSize = width * 3;
  19621. break;
  19622. case ImageKind.RGBA_32BPP:
  19623. colorType = 6;
  19624. bitDepth = 8;
  19625. lineSize = width * 4;
  19626. break;
  19627. default:
  19628. throw new Error('invalid format');
  19629. }
  19630. // prefix every row with predictor 0
  19631. var literals = new Uint8Array((1 + lineSize) * height);
  19632. var offsetLiterals = 0, offsetBytes = 0;
  19633. var y, i;
  19634. for (y = 0; y < height; ++y) {
  19635. literals[offsetLiterals++] = 0; // no prediction
  19636. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  19637. offsetLiterals);
  19638. offsetBytes += lineSize;
  19639. offsetLiterals += lineSize;
  19640. }
  19641. if (kind === ImageKind.GRAYSCALE_1BPP) {
  19642. // inverting for B/W
  19643. offsetLiterals = 0;
  19644. for (y = 0; y < height; y++) {
  19645. offsetLiterals++; // skipping predictor
  19646. for (i = 0; i < lineSize; i++) {
  19647. literals[offsetLiterals++] ^= 0xFF;
  19648. }
  19649. }
  19650. }
  19651. var ihdr = new Uint8Array([
  19652. width >> 24 & 0xff,
  19653. width >> 16 & 0xff,
  19654. width >> 8 & 0xff,
  19655. width & 0xff,
  19656. height >> 24 & 0xff,
  19657. height >> 16 & 0xff,
  19658. height >> 8 & 0xff,
  19659. height & 0xff,
  19660. bitDepth, // bit depth
  19661. colorType, // color type
  19662. 0x00, // compression method
  19663. 0x00, // filter method
  19664. 0x00 // interlace method
  19665. ]);
  19666. var len = literals.length;
  19667. var maxBlockLength = 0xFFFF;
  19668. var deflateBlocks = Math.ceil(len / maxBlockLength);
  19669. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  19670. var pi = 0;
  19671. idat[pi++] = 0x78; // compression method and flags
  19672. idat[pi++] = 0x9c; // flags
  19673. var pos = 0;
  19674. while (len > maxBlockLength) {
  19675. // writing non-final DEFLATE blocks type 0 and length of 65535
  19676. idat[pi++] = 0x00;
  19677. idat[pi++] = 0xff;
  19678. idat[pi++] = 0xff;
  19679. idat[pi++] = 0x00;
  19680. idat[pi++] = 0x00;
  19681. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  19682. pi += maxBlockLength;
  19683. pos += maxBlockLength;
  19684. len -= maxBlockLength;
  19685. }
  19686. // writing non-final DEFLATE blocks type 0
  19687. idat[pi++] = 0x01;
  19688. idat[pi++] = len & 0xff;
  19689. idat[pi++] = len >> 8 & 0xff;
  19690. idat[pi++] = (~len & 0xffff) & 0xff;
  19691. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  19692. idat.set(literals.subarray(pos), pi);
  19693. pi += literals.length - pos;
  19694. var adler = adler32(literals, 0, literals.length); // checksum
  19695. idat[pi++] = adler >> 24 & 0xff;
  19696. idat[pi++] = adler >> 16 & 0xff;
  19697. idat[pi++] = adler >> 8 & 0xff;
  19698. idat[pi++] = adler & 0xff;
  19699. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  19700. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  19701. ihdr.length + idat.length;
  19702. var data = new Uint8Array(pngLength);
  19703. var offset = 0;
  19704. data.set(PNG_HEADER, offset);
  19705. offset += PNG_HEADER.length;
  19706. writePngChunk('IHDR', ihdr, data, offset);
  19707. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  19708. writePngChunk('IDATA', idat, data, offset);
  19709. offset += CHUNK_WRAPPER_SIZE + idat.length;
  19710. writePngChunk('IEND', new Uint8Array(0), data, offset);
  19711. return createObjectURL(data, 'image/png', forceDataSchema);
  19712. }
  19713. return function convertImgDataToPng(imgData, forceDataSchema) {
  19714. var kind = (imgData.kind === undefined ?
  19715. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  19716. return encode(imgData, kind, forceDataSchema);
  19717. };
  19718. })();
  19719. var SVGExtraState = (function SVGExtraStateClosure() {
  19720. function SVGExtraState() {
  19721. this.fontSizeScale = 1;
  19722. this.fontWeight = SVG_DEFAULTS.fontWeight;
  19723. this.fontSize = 0;
  19724. this.textMatrix = IDENTITY_MATRIX;
  19725. this.fontMatrix = FONT_IDENTITY_MATRIX;
  19726. this.leading = 0;
  19727. // Current point (in user coordinates)
  19728. this.x = 0;
  19729. this.y = 0;
  19730. // Start of text line (in text coordinates)
  19731. this.lineX = 0;
  19732. this.lineY = 0;
  19733. // Character and word spacing
  19734. this.charSpacing = 0;
  19735. this.wordSpacing = 0;
  19736. this.textHScale = 1;
  19737. this.textRise = 0;
  19738. // Default foreground and background colors
  19739. this.fillColor = SVG_DEFAULTS.fillColor;
  19740. this.strokeColor = '#000000';
  19741. this.fillAlpha = 1;
  19742. this.strokeAlpha = 1;
  19743. this.lineWidth = 1;
  19744. this.lineJoin = '';
  19745. this.lineCap = '';
  19746. this.miterLimit = 0;
  19747. this.dashArray = [];
  19748. this.dashPhase = 0;
  19749. this.dependencies = [];
  19750. // Clipping
  19751. this.clipId = '';
  19752. this.pendingClip = false;
  19753. this.maskId = '';
  19754. }
  19755. SVGExtraState.prototype = {
  19756. clone: function SVGExtraState_clone() {
  19757. return Object.create(this);
  19758. },
  19759. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  19760. this.x = x;
  19761. this.y = y;
  19762. }
  19763. };
  19764. return SVGExtraState;
  19765. })();
  19766. var SVGGraphics = (function SVGGraphicsClosure() {
  19767. function createScratchSVG(width, height) {
  19768. var NS = 'http://www.w3.org/2000/svg';
  19769. var svg = document.createElementNS(NS, 'svg:svg');
  19770. svg.setAttributeNS(null, 'version', '1.1');
  19771. svg.setAttributeNS(null, 'width', width + 'px');
  19772. svg.setAttributeNS(null, 'height', height + 'px');
  19773. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  19774. return svg;
  19775. }
  19776. function opListToTree(opList) {
  19777. var opTree = [];
  19778. var tmp = [];
  19779. var opListLen = opList.length;
  19780. for (var x = 0; x < opListLen; x++) {
  19781. if (opList[x].fn === 'save') {
  19782. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  19783. tmp.push(opTree);
  19784. opTree = opTree[opTree.length - 1].items;
  19785. continue;
  19786. }
  19787. if(opList[x].fn === 'restore') {
  19788. opTree = tmp.pop();
  19789. } else {
  19790. opTree.push(opList[x]);
  19791. }
  19792. }
  19793. return opTree;
  19794. }
  19795. /**
  19796. * Formats float number.
  19797. * @param value {number} number to format.
  19798. * @returns {string}
  19799. */
  19800. function pf(value) {
  19801. if (value === (value | 0)) { // integer number
  19802. return value.toString();
  19803. }
  19804. var s = value.toFixed(10);
  19805. var i = s.length - 1;
  19806. if (s[i] !== '0') {
  19807. return s;
  19808. }
  19809. // removing trailing zeros
  19810. do {
  19811. i--;
  19812. } while (s[i] === '0');
  19813. return s.substr(0, s[i] === '.' ? i : i + 1);
  19814. }
  19815. /**
  19816. * Formats transform matrix. The standard rotation, scale and translate
  19817. * matrices are replaced by their shorter forms, and for identity matrix
  19818. * returns empty string to save the memory.
  19819. * @param m {Array} matrix to format.
  19820. * @returns {string}
  19821. */
  19822. function pm(m) {
  19823. if (m[4] === 0 && m[5] === 0) {
  19824. if (m[1] === 0 && m[2] === 0) {
  19825. if (m[0] === 1 && m[3] === 1) {
  19826. return '';
  19827. }
  19828. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  19829. }
  19830. if (m[0] === m[3] && m[1] === -m[2]) {
  19831. var a = Math.acos(m[0]) * 180 / Math.PI;
  19832. return 'rotate(' + pf(a) + ')';
  19833. }
  19834. } else {
  19835. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  19836. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19837. }
  19838. }
  19839. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  19840. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19841. }
  19842. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  19843. this.current = new SVGExtraState();
  19844. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  19845. this.transformStack = [];
  19846. this.extraStack = [];
  19847. this.commonObjs = commonObjs;
  19848. this.objs = objs;
  19849. this.pendingEOFill = false;
  19850. this.embedFonts = false;
  19851. this.embeddedFonts = Object.create(null);
  19852. this.cssStyle = null;
  19853. this.forceDataSchema = !!forceDataSchema;
  19854. }
  19855. var NS = 'http://www.w3.org/2000/svg';
  19856. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  19857. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  19858. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  19859. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  19860. var clipCount = 0;
  19861. var maskCount = 0;
  19862. SVGGraphics.prototype = {
  19863. save: function SVGGraphics_save() {
  19864. this.transformStack.push(this.transformMatrix);
  19865. var old = this.current;
  19866. this.extraStack.push(old);
  19867. this.current = old.clone();
  19868. },
  19869. restore: function SVGGraphics_restore() {
  19870. this.transformMatrix = this.transformStack.pop();
  19871. this.current = this.extraStack.pop();
  19872. this.tgrp = document.createElementNS(NS, 'svg:g');
  19873. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19874. this.pgrp.appendChild(this.tgrp);
  19875. },
  19876. group: function SVGGraphics_group(items) {
  19877. this.save();
  19878. this.executeOpTree(items);
  19879. this.restore();
  19880. },
  19881. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  19882. var fnArray = operatorList.fnArray;
  19883. var fnArrayLen = fnArray.length;
  19884. var argsArray = operatorList.argsArray;
  19885. var self = this;
  19886. for (var i = 0; i < fnArrayLen; i++) {
  19887. if (OPS.dependency === fnArray[i]) {
  19888. var deps = argsArray[i];
  19889. for (var n = 0, nn = deps.length; n < nn; n++) {
  19890. var obj = deps[n];
  19891. var common = obj.substring(0, 2) === 'g_';
  19892. var promise;
  19893. if (common) {
  19894. promise = new Promise(function(resolve) {
  19895. self.commonObjs.get(obj, resolve);
  19896. });
  19897. } else {
  19898. promise = new Promise(function(resolve) {
  19899. self.objs.get(obj, resolve);
  19900. });
  19901. }
  19902. this.current.dependencies.push(promise);
  19903. }
  19904. }
  19905. }
  19906. return Promise.all(this.current.dependencies);
  19907. },
  19908. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19909. var transformMatrix = [a, b, c, d, e, f];
  19910. this.transformMatrix = Util.transform(this.transformMatrix,
  19911. transformMatrix);
  19912. this.tgrp = document.createElementNS(NS, 'svg:g');
  19913. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19914. },
  19915. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19916. this.svg = createScratchSVG(viewport.width, viewport.height);
  19917. this.viewport = viewport;
  19918. return this.loadDependencies(operatorList).then(function () {
  19919. this.transformMatrix = IDENTITY_MATRIX;
  19920. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19921. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19922. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19923. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19924. this.defs = document.createElementNS(NS, 'svg:defs');
  19925. this.pgrp.appendChild(this.defs);
  19926. this.pgrp.appendChild(this.tgrp);
  19927. this.svg.appendChild(this.pgrp);
  19928. var opTree = this.convertOpList(operatorList);
  19929. this.executeOpTree(opTree);
  19930. return this.svg;
  19931. }.bind(this));
  19932. },
  19933. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19934. var argsArray = operatorList.argsArray;
  19935. var fnArray = operatorList.fnArray;
  19936. var fnArrayLen = fnArray.length;
  19937. var REVOPS = [];
  19938. var opList = [];
  19939. for (var op in OPS) {
  19940. REVOPS[OPS[op]] = op;
  19941. }
  19942. for (var x = 0; x < fnArrayLen; x++) {
  19943. var fnId = fnArray[x];
  19944. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19945. }
  19946. return opListToTree(opList);
  19947. },
  19948. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19949. var opTreeLen = opTree.length;
  19950. for(var x = 0; x < opTreeLen; x++) {
  19951. var fn = opTree[x].fn;
  19952. var fnId = opTree[x].fnId;
  19953. var args = opTree[x].args;
  19954. switch (fnId | 0) {
  19955. case OPS.beginText:
  19956. this.beginText();
  19957. break;
  19958. case OPS.setLeading:
  19959. this.setLeading(args);
  19960. break;
  19961. case OPS.setLeadingMoveText:
  19962. this.setLeadingMoveText(args[0], args[1]);
  19963. break;
  19964. case OPS.setFont:
  19965. this.setFont(args);
  19966. break;
  19967. case OPS.showText:
  19968. this.showText(args[0]);
  19969. break;
  19970. case OPS.showSpacedText:
  19971. this.showText(args[0]);
  19972. break;
  19973. case OPS.endText:
  19974. this.endText();
  19975. break;
  19976. case OPS.moveText:
  19977. this.moveText(args[0], args[1]);
  19978. break;
  19979. case OPS.setCharSpacing:
  19980. this.setCharSpacing(args[0]);
  19981. break;
  19982. case OPS.setWordSpacing:
  19983. this.setWordSpacing(args[0]);
  19984. break;
  19985. case OPS.setHScale:
  19986. this.setHScale(args[0]);
  19987. break;
  19988. case OPS.setTextMatrix:
  19989. this.setTextMatrix(args[0], args[1], args[2],
  19990. args[3], args[4], args[5]);
  19991. break;
  19992. case OPS.setLineWidth:
  19993. this.setLineWidth(args[0]);
  19994. break;
  19995. case OPS.setLineJoin:
  19996. this.setLineJoin(args[0]);
  19997. break;
  19998. case OPS.setLineCap:
  19999. this.setLineCap(args[0]);
  20000. break;
  20001. case OPS.setMiterLimit:
  20002. this.setMiterLimit(args[0]);
  20003. break;
  20004. case OPS.setFillRGBColor:
  20005. this.setFillRGBColor(args[0], args[1], args[2]);
  20006. break;
  20007. case OPS.setStrokeRGBColor:
  20008. this.setStrokeRGBColor(args[0], args[1], args[2]);
  20009. break;
  20010. case OPS.setDash:
  20011. this.setDash(args[0], args[1]);
  20012. break;
  20013. case OPS.setGState:
  20014. this.setGState(args[0]);
  20015. break;
  20016. case OPS.fill:
  20017. this.fill();
  20018. break;
  20019. case OPS.eoFill:
  20020. this.eoFill();
  20021. break;
  20022. case OPS.stroke:
  20023. this.stroke();
  20024. break;
  20025. case OPS.fillStroke:
  20026. this.fillStroke();
  20027. break;
  20028. case OPS.eoFillStroke:
  20029. this.eoFillStroke();
  20030. break;
  20031. case OPS.clip:
  20032. this.clip('nonzero');
  20033. break;
  20034. case OPS.eoClip:
  20035. this.clip('evenodd');
  20036. break;
  20037. case OPS.paintSolidColorImageMask:
  20038. this.paintSolidColorImageMask();
  20039. break;
  20040. case OPS.paintJpegXObject:
  20041. this.paintJpegXObject(args[0], args[1], args[2]);
  20042. break;
  20043. case OPS.paintImageXObject:
  20044. this.paintImageXObject(args[0]);
  20045. break;
  20046. case OPS.paintInlineImageXObject:
  20047. this.paintInlineImageXObject(args[0]);
  20048. break;
  20049. case OPS.paintImageMaskXObject:
  20050. this.paintImageMaskXObject(args[0]);
  20051. break;
  20052. case OPS.paintFormXObjectBegin:
  20053. this.paintFormXObjectBegin(args[0], args[1]);
  20054. break;
  20055. case OPS.paintFormXObjectEnd:
  20056. this.paintFormXObjectEnd();
  20057. break;
  20058. case OPS.closePath:
  20059. this.closePath();
  20060. break;
  20061. case OPS.closeStroke:
  20062. this.closeStroke();
  20063. break;
  20064. case OPS.closeFillStroke:
  20065. this.closeFillStroke();
  20066. break;
  20067. case OPS.nextLine:
  20068. this.nextLine();
  20069. break;
  20070. case OPS.transform:
  20071. this.transform(args[0], args[1], args[2], args[3],
  20072. args[4], args[5]);
  20073. break;
  20074. case OPS.constructPath:
  20075. this.constructPath(args[0], args[1]);
  20076. break;
  20077. case OPS.endPath:
  20078. this.endPath();
  20079. break;
  20080. case 92:
  20081. this.group(opTree[x].items);
  20082. break;
  20083. default:
  20084. warn('Unimplemented method '+ fn);
  20085. break;
  20086. }
  20087. }
  20088. },
  20089. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  20090. this.current.wordSpacing = wordSpacing;
  20091. },
  20092. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  20093. this.current.charSpacing = charSpacing;
  20094. },
  20095. nextLine: function SVGGraphics_nextLine() {
  20096. this.moveText(0, this.current.leading);
  20097. },
  20098. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  20099. var current = this.current;
  20100. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  20101. this.current.x = this.current.lineX = 0;
  20102. this.current.y = this.current.lineY = 0;
  20103. current.xcoords = [];
  20104. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20105. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20106. current.tspan.setAttributeNS(null, 'font-size',
  20107. pf(current.fontSize) + 'px');
  20108. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20109. current.txtElement = document.createElementNS(NS, 'svg:text');
  20110. current.txtElement.appendChild(current.tspan);
  20111. },
  20112. beginText: function SVGGraphics_beginText() {
  20113. this.current.x = this.current.lineX = 0;
  20114. this.current.y = this.current.lineY = 0;
  20115. this.current.textMatrix = IDENTITY_MATRIX;
  20116. this.current.lineMatrix = IDENTITY_MATRIX;
  20117. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20118. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  20119. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  20120. this.current.xcoords = [];
  20121. },
  20122. moveText: function SVGGraphics_moveText(x, y) {
  20123. var current = this.current;
  20124. this.current.x = this.current.lineX += x;
  20125. this.current.y = this.current.lineY += y;
  20126. current.xcoords = [];
  20127. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20128. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20129. current.tspan.setAttributeNS(null, 'font-size',
  20130. pf(current.fontSize) + 'px');
  20131. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20132. },
  20133. showText: function SVGGraphics_showText(glyphs) {
  20134. var current = this.current;
  20135. var font = current.font;
  20136. var fontSize = current.fontSize;
  20137. if (fontSize === 0) {
  20138. return;
  20139. }
  20140. var charSpacing = current.charSpacing;
  20141. var wordSpacing = current.wordSpacing;
  20142. var fontDirection = current.fontDirection;
  20143. var textHScale = current.textHScale * fontDirection;
  20144. var glyphsLength = glyphs.length;
  20145. var vertical = font.vertical;
  20146. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  20147. var x = 0, i;
  20148. for (i = 0; i < glyphsLength; ++i) {
  20149. var glyph = glyphs[i];
  20150. if (glyph === null) {
  20151. // word break
  20152. x += fontDirection * wordSpacing;
  20153. continue;
  20154. } else if (isNum(glyph)) {
  20155. x += -glyph * fontSize * 0.001;
  20156. continue;
  20157. }
  20158. current.xcoords.push(current.x + x * textHScale);
  20159. var width = glyph.width;
  20160. var character = glyph.fontChar;
  20161. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  20162. x += charWidth;
  20163. current.tspan.textContent += character;
  20164. }
  20165. if (vertical) {
  20166. current.y -= x * textHScale;
  20167. } else {
  20168. current.x += x * textHScale;
  20169. }
  20170. current.tspan.setAttributeNS(null, 'x',
  20171. current.xcoords.map(pf).join(' '));
  20172. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20173. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20174. current.tspan.setAttributeNS(null, 'font-size',
  20175. pf(current.fontSize) + 'px');
  20176. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  20177. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  20178. }
  20179. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  20180. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  20181. }
  20182. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  20183. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  20184. }
  20185. current.txtElement.setAttributeNS(null, 'transform',
  20186. pm(current.textMatrix) +
  20187. ' scale(1, -1)' );
  20188. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  20189. current.txtElement.appendChild(current.tspan);
  20190. current.txtgrp.appendChild(current.txtElement);
  20191. this.tgrp.appendChild(current.txtElement);
  20192. },
  20193. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  20194. this.setLeading(-y);
  20195. this.moveText(x, y);
  20196. },
  20197. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  20198. if (!this.cssStyle) {
  20199. this.cssStyle = document.createElementNS(NS, 'svg:style');
  20200. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  20201. this.defs.appendChild(this.cssStyle);
  20202. }
  20203. var url = createObjectURL(fontObj.data, fontObj.mimetype,
  20204. this.forceDataSchema);
  20205. this.cssStyle.textContent +=
  20206. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  20207. ' src: url(' + url + '); }\n';
  20208. },
  20209. setFont: function SVGGraphics_setFont(details) {
  20210. var current = this.current;
  20211. var fontObj = this.commonObjs.get(details[0]);
  20212. var size = details[1];
  20213. this.current.font = fontObj;
  20214. if (this.embedFonts && fontObj.data &&
  20215. !this.embeddedFonts[fontObj.loadedName]) {
  20216. this.addFontStyle(fontObj);
  20217. this.embeddedFonts[fontObj.loadedName] = fontObj;
  20218. }
  20219. current.fontMatrix = (fontObj.fontMatrix ?
  20220. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  20221. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  20222. (fontObj.bold ? 'bold' : 'normal');
  20223. var italic = fontObj.italic ? 'italic' : 'normal';
  20224. if (size < 0) {
  20225. size = -size;
  20226. current.fontDirection = -1;
  20227. } else {
  20228. current.fontDirection = 1;
  20229. }
  20230. current.fontSize = size;
  20231. current.fontFamily = fontObj.loadedName;
  20232. current.fontWeight = bold;
  20233. current.fontStyle = italic;
  20234. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20235. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20236. current.xcoords = [];
  20237. },
  20238. endText: function SVGGraphics_endText() {
  20239. if (this.current.pendingClip) {
  20240. this.cgrp.appendChild(this.tgrp);
  20241. this.pgrp.appendChild(this.cgrp);
  20242. } else {
  20243. this.pgrp.appendChild(this.tgrp);
  20244. }
  20245. this.tgrp = document.createElementNS(NS, 'svg:g');
  20246. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20247. },
  20248. // Path properties
  20249. setLineWidth: function SVGGraphics_setLineWidth(width) {
  20250. this.current.lineWidth = width;
  20251. },
  20252. setLineCap: function SVGGraphics_setLineCap(style) {
  20253. this.current.lineCap = LINE_CAP_STYLES[style];
  20254. },
  20255. setLineJoin: function SVGGraphics_setLineJoin(style) {
  20256. this.current.lineJoin = LINE_JOIN_STYLES[style];
  20257. },
  20258. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  20259. this.current.miterLimit = limit;
  20260. },
  20261. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  20262. var color = Util.makeCssRgb(r, g, b);
  20263. this.current.strokeColor = color;
  20264. },
  20265. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  20266. var color = Util.makeCssRgb(r, g, b);
  20267. this.current.fillColor = color;
  20268. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20269. this.current.xcoords = [];
  20270. },
  20271. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  20272. this.current.dashArray = dashArray;
  20273. this.current.dashPhase = dashPhase;
  20274. },
  20275. constructPath: function SVGGraphics_constructPath(ops, args) {
  20276. var current = this.current;
  20277. var x = current.x, y = current.y;
  20278. current.path = document.createElementNS(NS, 'svg:path');
  20279. var d = [];
  20280. var opLength = ops.length;
  20281. for (var i = 0, j = 0; i < opLength; i++) {
  20282. switch (ops[i] | 0) {
  20283. case OPS.rectangle:
  20284. x = args[j++];
  20285. y = args[j++];
  20286. var width = args[j++];
  20287. var height = args[j++];
  20288. var xw = x + width;
  20289. var yh = y + height;
  20290. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  20291. 'L', pf(x), pf(yh), 'Z');
  20292. break;
  20293. case OPS.moveTo:
  20294. x = args[j++];
  20295. y = args[j++];
  20296. d.push('M', pf(x), pf(y));
  20297. break;
  20298. case OPS.lineTo:
  20299. x = args[j++];
  20300. y = args[j++];
  20301. d.push('L', pf(x) , pf(y));
  20302. break;
  20303. case OPS.curveTo:
  20304. x = args[j + 4];
  20305. y = args[j + 5];
  20306. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  20307. pf(args[j + 3]), pf(x), pf(y));
  20308. j += 6;
  20309. break;
  20310. case OPS.curveTo2:
  20311. x = args[j + 2];
  20312. y = args[j + 3];
  20313. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  20314. pf(args[j + 2]), pf(args[j + 3]));
  20315. j += 4;
  20316. break;
  20317. case OPS.curveTo3:
  20318. x = args[j + 2];
  20319. y = args[j + 3];
  20320. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  20321. pf(x), pf(y));
  20322. j += 4;
  20323. break;
  20324. case OPS.closePath:
  20325. d.push('Z');
  20326. break;
  20327. }
  20328. }
  20329. current.path.setAttributeNS(null, 'd', d.join(' '));
  20330. current.path.setAttributeNS(null, 'stroke-miterlimit',
  20331. pf(current.miterLimit));
  20332. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  20333. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  20334. current.path.setAttributeNS(null, 'stroke-width',
  20335. pf(current.lineWidth) + 'px');
  20336. current.path.setAttributeNS(null, 'stroke-dasharray',
  20337. current.dashArray.map(pf).join(' '));
  20338. current.path.setAttributeNS(null, 'stroke-dashoffset',
  20339. pf(current.dashPhase) + 'px');
  20340. current.path.setAttributeNS(null, 'fill', 'none');
  20341. this.tgrp.appendChild(current.path);
  20342. if (current.pendingClip) {
  20343. this.cgrp.appendChild(this.tgrp);
  20344. this.pgrp.appendChild(this.cgrp);
  20345. } else {
  20346. this.pgrp.appendChild(this.tgrp);
  20347. }
  20348. // Saving a reference in current.element so that it can be addressed
  20349. // in 'fill' and 'stroke'
  20350. current.element = current.path;
  20351. current.setCurrentPoint(x, y);
  20352. },
  20353. endPath: function SVGGraphics_endPath() {
  20354. var current = this.current;
  20355. if (current.pendingClip) {
  20356. this.cgrp.appendChild(this.tgrp);
  20357. this.pgrp.appendChild(this.cgrp);
  20358. } else {
  20359. this.pgrp.appendChild(this.tgrp);
  20360. }
  20361. this.tgrp = document.createElementNS(NS, 'svg:g');
  20362. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20363. },
  20364. clip: function SVGGraphics_clip(type) {
  20365. var current = this.current;
  20366. // Add current path to clipping path
  20367. current.clipId = 'clippath' + clipCount;
  20368. clipCount++;
  20369. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  20370. this.clippath.setAttributeNS(null, 'id', current.clipId);
  20371. var clipElement = current.element.cloneNode();
  20372. if (type === 'evenodd') {
  20373. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  20374. } else {
  20375. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  20376. }
  20377. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20378. this.clippath.appendChild(clipElement);
  20379. this.defs.appendChild(this.clippath);
  20380. // Create a new group with that attribute
  20381. current.pendingClip = true;
  20382. this.cgrp = document.createElementNS(NS, 'svg:g');
  20383. this.cgrp.setAttributeNS(null, 'clip-path',
  20384. 'url(#' + current.clipId + ')');
  20385. this.pgrp.appendChild(this.cgrp);
  20386. },
  20387. closePath: function SVGGraphics_closePath() {
  20388. var current = this.current;
  20389. var d = current.path.getAttributeNS(null, 'd');
  20390. d += 'Z';
  20391. current.path.setAttributeNS(null, 'd', d);
  20392. },
  20393. setLeading: function SVGGraphics_setLeading(leading) {
  20394. this.current.leading = -leading;
  20395. },
  20396. setTextRise: function SVGGraphics_setTextRise(textRise) {
  20397. this.current.textRise = textRise;
  20398. },
  20399. setHScale: function SVGGraphics_setHScale(scale) {
  20400. this.current.textHScale = scale / 100;
  20401. },
  20402. setGState: function SVGGraphics_setGState(states) {
  20403. for (var i = 0, ii = states.length; i < ii; i++) {
  20404. var state = states[i];
  20405. var key = state[0];
  20406. var value = state[1];
  20407. switch (key) {
  20408. case 'LW':
  20409. this.setLineWidth(value);
  20410. break;
  20411. case 'LC':
  20412. this.setLineCap(value);
  20413. break;
  20414. case 'LJ':
  20415. this.setLineJoin(value);
  20416. break;
  20417. case 'ML':
  20418. this.setMiterLimit(value);
  20419. break;
  20420. case 'D':
  20421. this.setDash(value[0], value[1]);
  20422. break;
  20423. case 'RI':
  20424. break;
  20425. case 'FL':
  20426. break;
  20427. case 'Font':
  20428. this.setFont(value);
  20429. break;
  20430. case 'CA':
  20431. break;
  20432. case 'ca':
  20433. break;
  20434. case 'BM':
  20435. break;
  20436. case 'SMask':
  20437. break;
  20438. }
  20439. }
  20440. },
  20441. fill: function SVGGraphics_fill() {
  20442. var current = this.current;
  20443. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20444. },
  20445. stroke: function SVGGraphics_stroke() {
  20446. var current = this.current;
  20447. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  20448. current.element.setAttributeNS(null, 'fill', 'none');
  20449. },
  20450. eoFill: function SVGGraphics_eoFill() {
  20451. var current = this.current;
  20452. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20453. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20454. },
  20455. fillStroke: function SVGGraphics_fillStroke() {
  20456. // Order is important since stroke wants fill to be none.
  20457. // First stroke, then if fill needed, it will be overwritten.
  20458. this.stroke();
  20459. this.fill();
  20460. },
  20461. eoFillStroke: function SVGGraphics_eoFillStroke() {
  20462. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20463. this.fillStroke();
  20464. },
  20465. closeStroke: function SVGGraphics_closeStroke() {
  20466. this.closePath();
  20467. this.stroke();
  20468. },
  20469. closeFillStroke: function SVGGraphics_closeFillStroke() {
  20470. this.closePath();
  20471. this.fillStroke();
  20472. },
  20473. paintSolidColorImageMask:
  20474. function SVGGraphics_paintSolidColorImageMask() {
  20475. var current = this.current;
  20476. var rect = document.createElementNS(NS, 'svg:rect');
  20477. rect.setAttributeNS(null, 'x', '0');
  20478. rect.setAttributeNS(null, 'y', '0');
  20479. rect.setAttributeNS(null, 'width', '1px');
  20480. rect.setAttributeNS(null, 'height', '1px');
  20481. rect.setAttributeNS(null, 'fill', current.fillColor);
  20482. this.tgrp.appendChild(rect);
  20483. },
  20484. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  20485. var current = this.current;
  20486. var imgObj = this.objs.get(objId);
  20487. var imgEl = document.createElementNS(NS, 'svg:image');
  20488. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  20489. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  20490. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  20491. imgEl.setAttributeNS(null, 'x', '0');
  20492. imgEl.setAttributeNS(null, 'y', pf(-h));
  20493. imgEl.setAttributeNS(null, 'transform',
  20494. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  20495. this.tgrp.appendChild(imgEl);
  20496. if (current.pendingClip) {
  20497. this.cgrp.appendChild(this.tgrp);
  20498. this.pgrp.appendChild(this.cgrp);
  20499. } else {
  20500. this.pgrp.appendChild(this.tgrp);
  20501. }
  20502. },
  20503. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  20504. var imgData = this.objs.get(objId);
  20505. if (!imgData) {
  20506. warn('Dependent image isn\'t ready yet');
  20507. return;
  20508. }
  20509. this.paintInlineImageXObject(imgData);
  20510. },
  20511. paintInlineImageXObject:
  20512. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  20513. var current = this.current;
  20514. var width = imgData.width;
  20515. var height = imgData.height;
  20516. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  20517. var cliprect = document.createElementNS(NS, 'svg:rect');
  20518. cliprect.setAttributeNS(null, 'x', '0');
  20519. cliprect.setAttributeNS(null, 'y', '0');
  20520. cliprect.setAttributeNS(null, 'width', pf(width));
  20521. cliprect.setAttributeNS(null, 'height', pf(height));
  20522. current.element = cliprect;
  20523. this.clip('nonzero');
  20524. var imgEl = document.createElementNS(NS, 'svg:image');
  20525. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  20526. imgEl.setAttributeNS(null, 'x', '0');
  20527. imgEl.setAttributeNS(null, 'y', pf(-height));
  20528. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  20529. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  20530. imgEl.setAttributeNS(null, 'transform',
  20531. 'scale(' + pf(1 / width) + ' ' +
  20532. pf(-1 / height) + ')');
  20533. if (mask) {
  20534. mask.appendChild(imgEl);
  20535. } else {
  20536. this.tgrp.appendChild(imgEl);
  20537. }
  20538. if (current.pendingClip) {
  20539. this.cgrp.appendChild(this.tgrp);
  20540. this.pgrp.appendChild(this.cgrp);
  20541. } else {
  20542. this.pgrp.appendChild(this.tgrp);
  20543. }
  20544. },
  20545. paintImageMaskXObject:
  20546. function SVGGraphics_paintImageMaskXObject(imgData) {
  20547. var current = this.current;
  20548. var width = imgData.width;
  20549. var height = imgData.height;
  20550. var fillColor = current.fillColor;
  20551. current.maskId = 'mask' + maskCount++;
  20552. var mask = document.createElementNS(NS, 'svg:mask');
  20553. mask.setAttributeNS(null, 'id', current.maskId);
  20554. var rect = document.createElementNS(NS, 'svg:rect');
  20555. rect.setAttributeNS(null, 'x', '0');
  20556. rect.setAttributeNS(null, 'y', '0');
  20557. rect.setAttributeNS(null, 'width', pf(width));
  20558. rect.setAttributeNS(null, 'height', pf(height));
  20559. rect.setAttributeNS(null, 'fill', fillColor);
  20560. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  20561. this.defs.appendChild(mask);
  20562. this.tgrp.appendChild(rect);
  20563. this.paintInlineImageXObject(imgData, mask);
  20564. },
  20565. paintFormXObjectBegin:
  20566. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  20567. this.save();
  20568. if (isArray(matrix) && matrix.length === 6) {
  20569. this.transform(matrix[0], matrix[1], matrix[2],
  20570. matrix[3], matrix[4], matrix[5]);
  20571. }
  20572. if (isArray(bbox) && bbox.length === 4) {
  20573. var width = bbox[2] - bbox[0];
  20574. var height = bbox[3] - bbox[1];
  20575. var cliprect = document.createElementNS(NS, 'svg:rect');
  20576. cliprect.setAttributeNS(null, 'x', bbox[0]);
  20577. cliprect.setAttributeNS(null, 'y', bbox[1]);
  20578. cliprect.setAttributeNS(null, 'width', pf(width));
  20579. cliprect.setAttributeNS(null, 'height', pf(height));
  20580. this.current.element = cliprect;
  20581. this.clip('nonzero');
  20582. this.endPath();
  20583. }
  20584. },
  20585. paintFormXObjectEnd:
  20586. function SVGGraphics_paintFormXObjectEnd() {
  20587. this.restore();
  20588. }
  20589. };
  20590. return SVGGraphics;
  20591. })();
  20592. exports.SVGGraphics = SVGGraphics;
  20593. }));
  20594. (function (root, factory) {
  20595. {
  20596. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20597. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20598. root.pdfjsCoreJpx);
  20599. }
  20600. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20601. coreJpx) {
  20602. var Util = sharedUtil.Util;
  20603. var error = sharedUtil.error;
  20604. var info = sharedUtil.info;
  20605. var isArray = sharedUtil.isArray;
  20606. var createObjectURL = sharedUtil.createObjectURL;
  20607. var shadow = sharedUtil.shadow;
  20608. var warn = sharedUtil.warn;
  20609. var isSpace = sharedUtil.isSpace;
  20610. var Dict = corePrimitives.Dict;
  20611. var isDict = corePrimitives.isDict;
  20612. var Jbig2Image = coreJbig2.Jbig2Image;
  20613. var JpegImage = coreJpg.JpegImage;
  20614. var JpxImage = coreJpx.JpxImage;
  20615. var Stream = (function StreamClosure() {
  20616. function Stream(arrayBuffer, start, length, dict) {
  20617. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20618. arrayBuffer : new Uint8Array(arrayBuffer));
  20619. this.start = start || 0;
  20620. this.pos = this.start;
  20621. this.end = (start + length) || this.bytes.length;
  20622. this.dict = dict;
  20623. }
  20624. // required methods for a stream. if a particular stream does not
  20625. // implement these, an error should be thrown
  20626. Stream.prototype = {
  20627. get length() {
  20628. return this.end - this.start;
  20629. },
  20630. get isEmpty() {
  20631. return this.length === 0;
  20632. },
  20633. getByte: function Stream_getByte() {
  20634. if (this.pos >= this.end) {
  20635. return -1;
  20636. }
  20637. return this.bytes[this.pos++];
  20638. },
  20639. getUint16: function Stream_getUint16() {
  20640. var b0 = this.getByte();
  20641. var b1 = this.getByte();
  20642. if (b0 === -1 || b1 === -1) {
  20643. return -1;
  20644. }
  20645. return (b0 << 8) + b1;
  20646. },
  20647. getInt32: function Stream_getInt32() {
  20648. var b0 = this.getByte();
  20649. var b1 = this.getByte();
  20650. var b2 = this.getByte();
  20651. var b3 = this.getByte();
  20652. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20653. },
  20654. // returns subarray of original buffer
  20655. // should only be read
  20656. getBytes: function Stream_getBytes(length) {
  20657. var bytes = this.bytes;
  20658. var pos = this.pos;
  20659. var strEnd = this.end;
  20660. if (!length) {
  20661. return bytes.subarray(pos, strEnd);
  20662. }
  20663. var end = pos + length;
  20664. if (end > strEnd) {
  20665. end = strEnd;
  20666. }
  20667. this.pos = end;
  20668. return bytes.subarray(pos, end);
  20669. },
  20670. peekByte: function Stream_peekByte() {
  20671. var peekedByte = this.getByte();
  20672. this.pos--;
  20673. return peekedByte;
  20674. },
  20675. peekBytes: function Stream_peekBytes(length) {
  20676. var bytes = this.getBytes(length);
  20677. this.pos -= bytes.length;
  20678. return bytes;
  20679. },
  20680. skip: function Stream_skip(n) {
  20681. if (!n) {
  20682. n = 1;
  20683. }
  20684. this.pos += n;
  20685. },
  20686. reset: function Stream_reset() {
  20687. this.pos = this.start;
  20688. },
  20689. moveStart: function Stream_moveStart() {
  20690. this.start = this.pos;
  20691. },
  20692. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20693. return new Stream(this.bytes.buffer, start, length, dict);
  20694. },
  20695. isStream: true
  20696. };
  20697. return Stream;
  20698. })();
  20699. var StringStream = (function StringStreamClosure() {
  20700. function StringStream(str) {
  20701. var length = str.length;
  20702. var bytes = new Uint8Array(length);
  20703. for (var n = 0; n < length; ++n) {
  20704. bytes[n] = str.charCodeAt(n);
  20705. }
  20706. Stream.call(this, bytes);
  20707. }
  20708. StringStream.prototype = Stream.prototype;
  20709. return StringStream;
  20710. })();
  20711. // super class for the decoding streams
  20712. var DecodeStream = (function DecodeStreamClosure() {
  20713. // Lots of DecodeStreams are created whose buffers are never used. For these
  20714. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20715. // having special cases that would be required if we used |null| for an empty
  20716. // buffer.
  20717. var emptyBuffer = new Uint8Array(0);
  20718. function DecodeStream(maybeMinBufferLength) {
  20719. this.pos = 0;
  20720. this.bufferLength = 0;
  20721. this.eof = false;
  20722. this.buffer = emptyBuffer;
  20723. this.minBufferLength = 512;
  20724. if (maybeMinBufferLength) {
  20725. // Compute the first power of two that is as big as maybeMinBufferLength.
  20726. while (this.minBufferLength < maybeMinBufferLength) {
  20727. this.minBufferLength *= 2;
  20728. }
  20729. }
  20730. }
  20731. DecodeStream.prototype = {
  20732. get isEmpty() {
  20733. while (!this.eof && this.bufferLength === 0) {
  20734. this.readBlock();
  20735. }
  20736. return this.bufferLength === 0;
  20737. },
  20738. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20739. var buffer = this.buffer;
  20740. if (requested <= buffer.byteLength) {
  20741. return buffer;
  20742. }
  20743. var size = this.minBufferLength;
  20744. while (size < requested) {
  20745. size *= 2;
  20746. }
  20747. var buffer2 = new Uint8Array(size);
  20748. buffer2.set(buffer);
  20749. return (this.buffer = buffer2);
  20750. },
  20751. getByte: function DecodeStream_getByte() {
  20752. var pos = this.pos;
  20753. while (this.bufferLength <= pos) {
  20754. if (this.eof) {
  20755. return -1;
  20756. }
  20757. this.readBlock();
  20758. }
  20759. return this.buffer[this.pos++];
  20760. },
  20761. getUint16: function DecodeStream_getUint16() {
  20762. var b0 = this.getByte();
  20763. var b1 = this.getByte();
  20764. if (b0 === -1 || b1 === -1) {
  20765. return -1;
  20766. }
  20767. return (b0 << 8) + b1;
  20768. },
  20769. getInt32: function DecodeStream_getInt32() {
  20770. var b0 = this.getByte();
  20771. var b1 = this.getByte();
  20772. var b2 = this.getByte();
  20773. var b3 = this.getByte();
  20774. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20775. },
  20776. getBytes: function DecodeStream_getBytes(length) {
  20777. var end, pos = this.pos;
  20778. if (length) {
  20779. this.ensureBuffer(pos + length);
  20780. end = pos + length;
  20781. while (!this.eof && this.bufferLength < end) {
  20782. this.readBlock();
  20783. }
  20784. var bufEnd = this.bufferLength;
  20785. if (end > bufEnd) {
  20786. end = bufEnd;
  20787. }
  20788. } else {
  20789. while (!this.eof) {
  20790. this.readBlock();
  20791. }
  20792. end = this.bufferLength;
  20793. }
  20794. this.pos = end;
  20795. return this.buffer.subarray(pos, end);
  20796. },
  20797. peekByte: function DecodeStream_peekByte() {
  20798. var peekedByte = this.getByte();
  20799. this.pos--;
  20800. return peekedByte;
  20801. },
  20802. peekBytes: function DecodeStream_peekBytes(length) {
  20803. var bytes = this.getBytes(length);
  20804. this.pos -= bytes.length;
  20805. return bytes;
  20806. },
  20807. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20808. var end = start + length;
  20809. while (this.bufferLength <= end && !this.eof) {
  20810. this.readBlock();
  20811. }
  20812. return new Stream(this.buffer, start, length, dict);
  20813. },
  20814. skip: function DecodeStream_skip(n) {
  20815. if (!n) {
  20816. n = 1;
  20817. }
  20818. this.pos += n;
  20819. },
  20820. reset: function DecodeStream_reset() {
  20821. this.pos = 0;
  20822. },
  20823. getBaseStreams: function DecodeStream_getBaseStreams() {
  20824. if (this.str && this.str.getBaseStreams) {
  20825. return this.str.getBaseStreams();
  20826. }
  20827. return [];
  20828. }
  20829. };
  20830. return DecodeStream;
  20831. })();
  20832. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20833. function StreamsSequenceStream(streams) {
  20834. this.streams = streams;
  20835. DecodeStream.call(this, /* maybeLength = */ null);
  20836. }
  20837. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20838. StreamsSequenceStream.prototype.readBlock =
  20839. function streamSequenceStreamReadBlock() {
  20840. var streams = this.streams;
  20841. if (streams.length === 0) {
  20842. this.eof = true;
  20843. return;
  20844. }
  20845. var stream = streams.shift();
  20846. var chunk = stream.getBytes();
  20847. var bufferLength = this.bufferLength;
  20848. var newLength = bufferLength + chunk.length;
  20849. var buffer = this.ensureBuffer(newLength);
  20850. buffer.set(chunk, bufferLength);
  20851. this.bufferLength = newLength;
  20852. };
  20853. StreamsSequenceStream.prototype.getBaseStreams =
  20854. function StreamsSequenceStream_getBaseStreams() {
  20855. var baseStreams = [];
  20856. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20857. var stream = this.streams[i];
  20858. if (stream.getBaseStreams) {
  20859. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20860. }
  20861. }
  20862. return baseStreams;
  20863. };
  20864. return StreamsSequenceStream;
  20865. })();
  20866. var FlateStream = (function FlateStreamClosure() {
  20867. var codeLenCodeMap = new Int32Array([
  20868. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20869. ]);
  20870. var lengthDecode = new Int32Array([
  20871. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20872. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20873. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20874. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20875. ]);
  20876. var distDecode = new Int32Array([
  20877. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20878. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20879. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20880. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20881. ]);
  20882. var fixedLitCodeTab = [new Int32Array([
  20883. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20884. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20885. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20886. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20887. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20888. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20889. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20890. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20891. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20892. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20893. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20894. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20895. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20896. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20897. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20898. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20899. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20900. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20901. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20902. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20903. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20904. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20905. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20906. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20907. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20908. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20909. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20910. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20911. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20912. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20913. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20914. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20915. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20916. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20917. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20918. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20919. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20920. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20921. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20922. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20923. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20924. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20925. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20926. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20927. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20928. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20929. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20930. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20931. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20932. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20933. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20934. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20935. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20936. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20937. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20938. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20939. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20940. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20941. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20942. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20943. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20944. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20945. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20946. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20947. ]), 9];
  20948. var fixedDistCodeTab = [new Int32Array([
  20949. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20950. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20951. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20952. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  20953. ]), 5];
  20954. function FlateStream(str, maybeLength) {
  20955. this.str = str;
  20956. this.dict = str.dict;
  20957. var cmf = str.getByte();
  20958. var flg = str.getByte();
  20959. if (cmf === -1 || flg === -1) {
  20960. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  20961. }
  20962. if ((cmf & 0x0f) !== 0x08) {
  20963. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  20964. }
  20965. if ((((cmf << 8) + flg) % 31) !== 0) {
  20966. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  20967. }
  20968. if (flg & 0x20) {
  20969. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  20970. }
  20971. this.codeSize = 0;
  20972. this.codeBuf = 0;
  20973. DecodeStream.call(this, maybeLength);
  20974. }
  20975. FlateStream.prototype = Object.create(DecodeStream.prototype);
  20976. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  20977. var str = this.str;
  20978. var codeSize = this.codeSize;
  20979. var codeBuf = this.codeBuf;
  20980. var b;
  20981. while (codeSize < bits) {
  20982. if ((b = str.getByte()) === -1) {
  20983. error('Bad encoding in flate stream');
  20984. }
  20985. codeBuf |= b << codeSize;
  20986. codeSize += 8;
  20987. }
  20988. b = codeBuf & ((1 << bits) - 1);
  20989. this.codeBuf = codeBuf >> bits;
  20990. this.codeSize = codeSize -= bits;
  20991. return b;
  20992. };
  20993. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  20994. var str = this.str;
  20995. var codes = table[0];
  20996. var maxLen = table[1];
  20997. var codeSize = this.codeSize;
  20998. var codeBuf = this.codeBuf;
  20999. var b;
  21000. while (codeSize < maxLen) {
  21001. if ((b = str.getByte()) === -1) {
  21002. // premature end of stream. code might however still be valid.
  21003. // codeSize < codeLen check below guards against incomplete codeVal.
  21004. break;
  21005. }
  21006. codeBuf |= (b << codeSize);
  21007. codeSize += 8;
  21008. }
  21009. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  21010. var codeLen = code >> 16;
  21011. var codeVal = code & 0xffff;
  21012. if (codeLen < 1 || codeSize < codeLen) {
  21013. error('Bad encoding in flate stream');
  21014. }
  21015. this.codeBuf = (codeBuf >> codeLen);
  21016. this.codeSize = (codeSize - codeLen);
  21017. return codeVal;
  21018. };
  21019. FlateStream.prototype.generateHuffmanTable =
  21020. function flateStreamGenerateHuffmanTable(lengths) {
  21021. var n = lengths.length;
  21022. // find max code length
  21023. var maxLen = 0;
  21024. var i;
  21025. for (i = 0; i < n; ++i) {
  21026. if (lengths[i] > maxLen) {
  21027. maxLen = lengths[i];
  21028. }
  21029. }
  21030. // build the table
  21031. var size = 1 << maxLen;
  21032. var codes = new Int32Array(size);
  21033. for (var len = 1, code = 0, skip = 2;
  21034. len <= maxLen;
  21035. ++len, code <<= 1, skip <<= 1) {
  21036. for (var val = 0; val < n; ++val) {
  21037. if (lengths[val] === len) {
  21038. // bit-reverse the code
  21039. var code2 = 0;
  21040. var t = code;
  21041. for (i = 0; i < len; ++i) {
  21042. code2 = (code2 << 1) | (t & 1);
  21043. t >>= 1;
  21044. }
  21045. // fill the table entries
  21046. for (i = code2; i < size; i += skip) {
  21047. codes[i] = (len << 16) | val;
  21048. }
  21049. ++code;
  21050. }
  21051. }
  21052. }
  21053. return [codes, maxLen];
  21054. };
  21055. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  21056. var buffer, len;
  21057. var str = this.str;
  21058. // read block header
  21059. var hdr = this.getBits(3);
  21060. if (hdr & 1) {
  21061. this.eof = true;
  21062. }
  21063. hdr >>= 1;
  21064. if (hdr === 0) { // uncompressed block
  21065. var b;
  21066. if ((b = str.getByte()) === -1) {
  21067. error('Bad block header in flate stream');
  21068. }
  21069. var blockLen = b;
  21070. if ((b = str.getByte()) === -1) {
  21071. error('Bad block header in flate stream');
  21072. }
  21073. blockLen |= (b << 8);
  21074. if ((b = str.getByte()) === -1) {
  21075. error('Bad block header in flate stream');
  21076. }
  21077. var check = b;
  21078. if ((b = str.getByte()) === -1) {
  21079. error('Bad block header in flate stream');
  21080. }
  21081. check |= (b << 8);
  21082. if (check !== (~blockLen & 0xffff) &&
  21083. (blockLen !== 0 || check !== 0)) {
  21084. // Ignoring error for bad "empty" block (see issue 1277)
  21085. error('Bad uncompressed block length in flate stream');
  21086. }
  21087. this.codeBuf = 0;
  21088. this.codeSize = 0;
  21089. var bufferLength = this.bufferLength;
  21090. buffer = this.ensureBuffer(bufferLength + blockLen);
  21091. var end = bufferLength + blockLen;
  21092. this.bufferLength = end;
  21093. if (blockLen === 0) {
  21094. if (str.peekByte() === -1) {
  21095. this.eof = true;
  21096. }
  21097. } else {
  21098. for (var n = bufferLength; n < end; ++n) {
  21099. if ((b = str.getByte()) === -1) {
  21100. this.eof = true;
  21101. break;
  21102. }
  21103. buffer[n] = b;
  21104. }
  21105. }
  21106. return;
  21107. }
  21108. var litCodeTable;
  21109. var distCodeTable;
  21110. if (hdr === 1) { // compressed block, fixed codes
  21111. litCodeTable = fixedLitCodeTab;
  21112. distCodeTable = fixedDistCodeTab;
  21113. } else if (hdr === 2) { // compressed block, dynamic codes
  21114. var numLitCodes = this.getBits(5) + 257;
  21115. var numDistCodes = this.getBits(5) + 1;
  21116. var numCodeLenCodes = this.getBits(4) + 4;
  21117. // build the code lengths code table
  21118. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  21119. var i;
  21120. for (i = 0; i < numCodeLenCodes; ++i) {
  21121. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  21122. }
  21123. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  21124. // build the literal and distance code tables
  21125. len = 0;
  21126. i = 0;
  21127. var codes = numLitCodes + numDistCodes;
  21128. var codeLengths = new Uint8Array(codes);
  21129. var bitsLength, bitsOffset, what;
  21130. while (i < codes) {
  21131. var code = this.getCode(codeLenCodeTab);
  21132. if (code === 16) {
  21133. bitsLength = 2; bitsOffset = 3; what = len;
  21134. } else if (code === 17) {
  21135. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  21136. } else if (code === 18) {
  21137. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  21138. } else {
  21139. codeLengths[i++] = len = code;
  21140. continue;
  21141. }
  21142. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  21143. while (repeatLength-- > 0) {
  21144. codeLengths[i++] = what;
  21145. }
  21146. }
  21147. litCodeTable =
  21148. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  21149. distCodeTable =
  21150. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  21151. } else {
  21152. error('Unknown block type in flate stream');
  21153. }
  21154. buffer = this.buffer;
  21155. var limit = buffer ? buffer.length : 0;
  21156. var pos = this.bufferLength;
  21157. while (true) {
  21158. var code1 = this.getCode(litCodeTable);
  21159. if (code1 < 256) {
  21160. if (pos + 1 >= limit) {
  21161. buffer = this.ensureBuffer(pos + 1);
  21162. limit = buffer.length;
  21163. }
  21164. buffer[pos++] = code1;
  21165. continue;
  21166. }
  21167. if (code1 === 256) {
  21168. this.bufferLength = pos;
  21169. return;
  21170. }
  21171. code1 -= 257;
  21172. code1 = lengthDecode[code1];
  21173. var code2 = code1 >> 16;
  21174. if (code2 > 0) {
  21175. code2 = this.getBits(code2);
  21176. }
  21177. len = (code1 & 0xffff) + code2;
  21178. code1 = this.getCode(distCodeTable);
  21179. code1 = distDecode[code1];
  21180. code2 = code1 >> 16;
  21181. if (code2 > 0) {
  21182. code2 = this.getBits(code2);
  21183. }
  21184. var dist = (code1 & 0xffff) + code2;
  21185. if (pos + len >= limit) {
  21186. buffer = this.ensureBuffer(pos + len);
  21187. limit = buffer.length;
  21188. }
  21189. for (var k = 0; k < len; ++k, ++pos) {
  21190. buffer[pos] = buffer[pos - dist];
  21191. }
  21192. }
  21193. };
  21194. return FlateStream;
  21195. })();
  21196. var PredictorStream = (function PredictorStreamClosure() {
  21197. function PredictorStream(str, maybeLength, params) {
  21198. if (!isDict(params)) {
  21199. return str; // no prediction
  21200. }
  21201. var predictor = this.predictor = params.get('Predictor') || 1;
  21202. if (predictor <= 1) {
  21203. return str; // no prediction
  21204. }
  21205. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  21206. error('Unsupported predictor: ' + predictor);
  21207. }
  21208. if (predictor === 2) {
  21209. this.readBlock = this.readBlockTiff;
  21210. } else {
  21211. this.readBlock = this.readBlockPng;
  21212. }
  21213. this.str = str;
  21214. this.dict = str.dict;
  21215. var colors = this.colors = params.get('Colors') || 1;
  21216. var bits = this.bits = params.get('BitsPerComponent') || 8;
  21217. var columns = this.columns = params.get('Columns') || 1;
  21218. this.pixBytes = (colors * bits + 7) >> 3;
  21219. this.rowBytes = (columns * colors * bits + 7) >> 3;
  21220. DecodeStream.call(this, maybeLength);
  21221. return this;
  21222. }
  21223. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  21224. PredictorStream.prototype.readBlockTiff =
  21225. function predictorStreamReadBlockTiff() {
  21226. var rowBytes = this.rowBytes;
  21227. var bufferLength = this.bufferLength;
  21228. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21229. var bits = this.bits;
  21230. var colors = this.colors;
  21231. var rawBytes = this.str.getBytes(rowBytes);
  21232. this.eof = !rawBytes.length;
  21233. if (this.eof) {
  21234. return;
  21235. }
  21236. var inbuf = 0, outbuf = 0;
  21237. var inbits = 0, outbits = 0;
  21238. var pos = bufferLength;
  21239. var i;
  21240. if (bits === 1) {
  21241. for (i = 0; i < rowBytes; ++i) {
  21242. var c = rawBytes[i];
  21243. inbuf = (inbuf << 8) | c;
  21244. // bitwise addition is exclusive or
  21245. // first shift inbuf and then add
  21246. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  21247. // truncate inbuf (assumes colors < 16)
  21248. inbuf &= 0xFFFF;
  21249. }
  21250. } else if (bits === 8) {
  21251. for (i = 0; i < colors; ++i) {
  21252. buffer[pos++] = rawBytes[i];
  21253. }
  21254. for (; i < rowBytes; ++i) {
  21255. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  21256. pos++;
  21257. }
  21258. } else {
  21259. var compArray = new Uint8Array(colors + 1);
  21260. var bitMask = (1 << bits) - 1;
  21261. var j = 0, k = bufferLength;
  21262. var columns = this.columns;
  21263. for (i = 0; i < columns; ++i) {
  21264. for (var kk = 0; kk < colors; ++kk) {
  21265. if (inbits < bits) {
  21266. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21267. inbits += 8;
  21268. }
  21269. compArray[kk] = (compArray[kk] +
  21270. (inbuf >> (inbits - bits))) & bitMask;
  21271. inbits -= bits;
  21272. outbuf = (outbuf << bits) | compArray[kk];
  21273. outbits += bits;
  21274. if (outbits >= 8) {
  21275. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21276. outbits -= 8;
  21277. }
  21278. }
  21279. }
  21280. if (outbits > 0) {
  21281. buffer[k++] = (outbuf << (8 - outbits)) +
  21282. (inbuf & ((1 << (8 - outbits)) - 1));
  21283. }
  21284. }
  21285. this.bufferLength += rowBytes;
  21286. };
  21287. PredictorStream.prototype.readBlockPng =
  21288. function predictorStreamReadBlockPng() {
  21289. var rowBytes = this.rowBytes;
  21290. var pixBytes = this.pixBytes;
  21291. var predictor = this.str.getByte();
  21292. var rawBytes = this.str.getBytes(rowBytes);
  21293. this.eof = !rawBytes.length;
  21294. if (this.eof) {
  21295. return;
  21296. }
  21297. var bufferLength = this.bufferLength;
  21298. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21299. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21300. if (prevRow.length === 0) {
  21301. prevRow = new Uint8Array(rowBytes);
  21302. }
  21303. var i, j = bufferLength, up, c;
  21304. switch (predictor) {
  21305. case 0:
  21306. for (i = 0; i < rowBytes; ++i) {
  21307. buffer[j++] = rawBytes[i];
  21308. }
  21309. break;
  21310. case 1:
  21311. for (i = 0; i < pixBytes; ++i) {
  21312. buffer[j++] = rawBytes[i];
  21313. }
  21314. for (; i < rowBytes; ++i) {
  21315. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21316. j++;
  21317. }
  21318. break;
  21319. case 2:
  21320. for (i = 0; i < rowBytes; ++i) {
  21321. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21322. }
  21323. break;
  21324. case 3:
  21325. for (i = 0; i < pixBytes; ++i) {
  21326. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21327. }
  21328. for (; i < rowBytes; ++i) {
  21329. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21330. rawBytes[i]) & 0xFF;
  21331. j++;
  21332. }
  21333. break;
  21334. case 4:
  21335. // we need to save the up left pixels values. the simplest way
  21336. // is to create a new buffer
  21337. for (i = 0; i < pixBytes; ++i) {
  21338. up = prevRow[i];
  21339. c = rawBytes[i];
  21340. buffer[j++] = up + c;
  21341. }
  21342. for (; i < rowBytes; ++i) {
  21343. up = prevRow[i];
  21344. var upLeft = prevRow[i - pixBytes];
  21345. var left = buffer[j - pixBytes];
  21346. var p = left + up - upLeft;
  21347. var pa = p - left;
  21348. if (pa < 0) {
  21349. pa = -pa;
  21350. }
  21351. var pb = p - up;
  21352. if (pb < 0) {
  21353. pb = -pb;
  21354. }
  21355. var pc = p - upLeft;
  21356. if (pc < 0) {
  21357. pc = -pc;
  21358. }
  21359. c = rawBytes[i];
  21360. if (pa <= pb && pa <= pc) {
  21361. buffer[j++] = left + c;
  21362. } else if (pb <= pc) {
  21363. buffer[j++] = up + c;
  21364. } else {
  21365. buffer[j++] = upLeft + c;
  21366. }
  21367. }
  21368. break;
  21369. default:
  21370. error('Unsupported predictor: ' + predictor);
  21371. }
  21372. this.bufferLength += rowBytes;
  21373. };
  21374. return PredictorStream;
  21375. })();
  21376. /**
  21377. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21378. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21379. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21380. * a library to decode these images and the stream behaves like all the other
  21381. * DecodeStreams.
  21382. */
  21383. var JpegStream = (function JpegStreamClosure() {
  21384. function JpegStream(stream, maybeLength, dict, xref) {
  21385. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21386. // Note: this seems to mainly affect inline images.
  21387. var ch;
  21388. while ((ch = stream.getByte()) !== -1) {
  21389. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21390. stream.skip(-1); // Reset the stream position to the SOI.
  21391. break;
  21392. }
  21393. }
  21394. this.stream = stream;
  21395. this.maybeLength = maybeLength;
  21396. this.dict = dict;
  21397. DecodeStream.call(this, maybeLength);
  21398. }
  21399. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21400. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21401. get: function JpegStream_bytes() {
  21402. // If this.maybeLength is null, we'll get the entire stream.
  21403. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21404. },
  21405. configurable: true
  21406. });
  21407. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21408. if (this.bufferLength) {
  21409. return;
  21410. }
  21411. var jpegImage = new JpegImage();
  21412. // Checking if values need to be transformed before conversion.
  21413. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  21414. var decodeArr = this.dict.getArray('Decode');
  21415. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21416. var decodeArrLength = decodeArr.length;
  21417. var transform = new Int32Array(decodeArrLength);
  21418. var transformNeeded = false;
  21419. var maxValue = (1 << bitsPerComponent) - 1;
  21420. for (var i = 0; i < decodeArrLength; i += 2) {
  21421. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21422. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21423. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21424. transformNeeded = true;
  21425. }
  21426. }
  21427. if (transformNeeded) {
  21428. jpegImage.decodeTransform = transform;
  21429. }
  21430. }
  21431. jpegImage.parse(this.bytes);
  21432. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21433. this.forceRGB);
  21434. this.buffer = data;
  21435. this.bufferLength = data.length;
  21436. this.eof = true;
  21437. };
  21438. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21439. this.ensureBuffer();
  21440. return this.buffer;
  21441. };
  21442. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  21443. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  21444. };
  21445. return JpegStream;
  21446. })();
  21447. /**
  21448. * For JPEG 2000's we use a library to decode these images and
  21449. * the stream behaves like all the other DecodeStreams.
  21450. */
  21451. var JpxStream = (function JpxStreamClosure() {
  21452. function JpxStream(stream, maybeLength, dict) {
  21453. this.stream = stream;
  21454. this.maybeLength = maybeLength;
  21455. this.dict = dict;
  21456. DecodeStream.call(this, maybeLength);
  21457. }
  21458. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21459. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21460. get: function JpxStream_bytes() {
  21461. // If this.maybeLength is null, we'll get the entire stream.
  21462. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21463. },
  21464. configurable: true
  21465. });
  21466. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21467. if (this.bufferLength) {
  21468. return;
  21469. }
  21470. var jpxImage = new JpxImage();
  21471. jpxImage.parse(this.bytes);
  21472. var width = jpxImage.width;
  21473. var height = jpxImage.height;
  21474. var componentsCount = jpxImage.componentsCount;
  21475. var tileCount = jpxImage.tiles.length;
  21476. if (tileCount === 1) {
  21477. this.buffer = jpxImage.tiles[0].items;
  21478. } else {
  21479. var data = new Uint8Array(width * height * componentsCount);
  21480. for (var k = 0; k < tileCount; k++) {
  21481. var tileComponents = jpxImage.tiles[k];
  21482. var tileWidth = tileComponents.width;
  21483. var tileHeight = tileComponents.height;
  21484. var tileLeft = tileComponents.left;
  21485. var tileTop = tileComponents.top;
  21486. var src = tileComponents.items;
  21487. var srcPosition = 0;
  21488. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21489. var imgRowSize = width * componentsCount;
  21490. var tileRowSize = tileWidth * componentsCount;
  21491. for (var j = 0; j < tileHeight; j++) {
  21492. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21493. data.set(rowBytes, dataPosition);
  21494. srcPosition += tileRowSize;
  21495. dataPosition += imgRowSize;
  21496. }
  21497. }
  21498. this.buffer = data;
  21499. }
  21500. this.bufferLength = this.buffer.length;
  21501. this.eof = true;
  21502. };
  21503. return JpxStream;
  21504. })();
  21505. /**
  21506. * For JBIG2's we use a library to decode these images and
  21507. * the stream behaves like all the other DecodeStreams.
  21508. */
  21509. var Jbig2Stream = (function Jbig2StreamClosure() {
  21510. function Jbig2Stream(stream, maybeLength, dict) {
  21511. this.stream = stream;
  21512. this.maybeLength = maybeLength;
  21513. this.dict = dict;
  21514. DecodeStream.call(this, maybeLength);
  21515. }
  21516. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21517. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21518. get: function Jbig2Stream_bytes() {
  21519. // If this.maybeLength is null, we'll get the entire stream.
  21520. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21521. },
  21522. configurable: true
  21523. });
  21524. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21525. if (this.bufferLength) {
  21526. return;
  21527. }
  21528. var jbig2Image = new Jbig2Image();
  21529. var chunks = [];
  21530. var decodeParams = this.dict.getArray('DecodeParms');
  21531. // According to the PDF specification, DecodeParms can be either
  21532. // a dictionary, or an array whose elements are dictionaries.
  21533. if (isArray(decodeParams)) {
  21534. if (decodeParams.length > 1) {
  21535. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21536. 'not supported.');
  21537. }
  21538. decodeParams = decodeParams[0];
  21539. }
  21540. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21541. var globalsStream = decodeParams.get('JBIG2Globals');
  21542. var globals = globalsStream.getBytes();
  21543. chunks.push({data: globals, start: 0, end: globals.length});
  21544. }
  21545. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21546. var data = jbig2Image.parseChunks(chunks);
  21547. var dataLength = data.length;
  21548. // JBIG2 had black as 1 and white as 0, inverting the colors
  21549. for (var i = 0; i < dataLength; i++) {
  21550. data[i] ^= 0xFF;
  21551. }
  21552. this.buffer = data;
  21553. this.bufferLength = dataLength;
  21554. this.eof = true;
  21555. };
  21556. return Jbig2Stream;
  21557. })();
  21558. var DecryptStream = (function DecryptStreamClosure() {
  21559. function DecryptStream(str, maybeLength, decrypt) {
  21560. this.str = str;
  21561. this.dict = str.dict;
  21562. this.decrypt = decrypt;
  21563. this.nextChunk = null;
  21564. this.initialized = false;
  21565. DecodeStream.call(this, maybeLength);
  21566. }
  21567. var chunkSize = 512;
  21568. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21569. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21570. var chunk;
  21571. if (this.initialized) {
  21572. chunk = this.nextChunk;
  21573. } else {
  21574. chunk = this.str.getBytes(chunkSize);
  21575. this.initialized = true;
  21576. }
  21577. if (!chunk || chunk.length === 0) {
  21578. this.eof = true;
  21579. return;
  21580. }
  21581. this.nextChunk = this.str.getBytes(chunkSize);
  21582. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21583. var decrypt = this.decrypt;
  21584. chunk = decrypt(chunk, !hasMoreData);
  21585. var bufferLength = this.bufferLength;
  21586. var i, n = chunk.length;
  21587. var buffer = this.ensureBuffer(bufferLength + n);
  21588. for (i = 0; i < n; i++) {
  21589. buffer[bufferLength++] = chunk[i];
  21590. }
  21591. this.bufferLength = bufferLength;
  21592. };
  21593. return DecryptStream;
  21594. })();
  21595. var Ascii85Stream = (function Ascii85StreamClosure() {
  21596. function Ascii85Stream(str, maybeLength) {
  21597. this.str = str;
  21598. this.dict = str.dict;
  21599. this.input = new Uint8Array(5);
  21600. // Most streams increase in size when decoded, but Ascii85 streams
  21601. // typically shrink by ~20%.
  21602. if (maybeLength) {
  21603. maybeLength = 0.8 * maybeLength;
  21604. }
  21605. DecodeStream.call(this, maybeLength);
  21606. }
  21607. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21608. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21609. var TILDA_CHAR = 0x7E; // '~'
  21610. var Z_LOWER_CHAR = 0x7A; // 'z'
  21611. var EOF = -1;
  21612. var str = this.str;
  21613. var c = str.getByte();
  21614. while (isSpace(c)) {
  21615. c = str.getByte();
  21616. }
  21617. if (c === EOF || c === TILDA_CHAR) {
  21618. this.eof = true;
  21619. return;
  21620. }
  21621. var bufferLength = this.bufferLength, buffer;
  21622. var i;
  21623. // special code for z
  21624. if (c === Z_LOWER_CHAR) {
  21625. buffer = this.ensureBuffer(bufferLength + 4);
  21626. for (i = 0; i < 4; ++i) {
  21627. buffer[bufferLength + i] = 0;
  21628. }
  21629. this.bufferLength += 4;
  21630. } else {
  21631. var input = this.input;
  21632. input[0] = c;
  21633. for (i = 1; i < 5; ++i) {
  21634. c = str.getByte();
  21635. while (isSpace(c)) {
  21636. c = str.getByte();
  21637. }
  21638. input[i] = c;
  21639. if (c === EOF || c === TILDA_CHAR) {
  21640. break;
  21641. }
  21642. }
  21643. buffer = this.ensureBuffer(bufferLength + i - 1);
  21644. this.bufferLength += i - 1;
  21645. // partial ending;
  21646. if (i < 5) {
  21647. for (; i < 5; ++i) {
  21648. input[i] = 0x21 + 84;
  21649. }
  21650. this.eof = true;
  21651. }
  21652. var t = 0;
  21653. for (i = 0; i < 5; ++i) {
  21654. t = t * 85 + (input[i] - 0x21);
  21655. }
  21656. for (i = 3; i >= 0; --i) {
  21657. buffer[bufferLength + i] = t & 0xFF;
  21658. t >>= 8;
  21659. }
  21660. }
  21661. };
  21662. return Ascii85Stream;
  21663. })();
  21664. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21665. function AsciiHexStream(str, maybeLength) {
  21666. this.str = str;
  21667. this.dict = str.dict;
  21668. this.firstDigit = -1;
  21669. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21670. // by 50%.
  21671. if (maybeLength) {
  21672. maybeLength = 0.5 * maybeLength;
  21673. }
  21674. DecodeStream.call(this, maybeLength);
  21675. }
  21676. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21677. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21678. var UPSTREAM_BLOCK_SIZE = 8000;
  21679. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21680. if (!bytes.length) {
  21681. this.eof = true;
  21682. return;
  21683. }
  21684. var maxDecodeLength = (bytes.length + 1) >> 1;
  21685. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21686. var bufferLength = this.bufferLength;
  21687. var firstDigit = this.firstDigit;
  21688. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21689. var ch = bytes[i], digit;
  21690. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21691. digit = ch & 0x0F;
  21692. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21693. // 'A'-'Z', 'a'-'z'
  21694. digit = (ch & 0x0F) + 9;
  21695. } else if (ch === 0x3E) { // '>'
  21696. this.eof = true;
  21697. break;
  21698. } else { // probably whitespace
  21699. continue; // ignoring
  21700. }
  21701. if (firstDigit < 0) {
  21702. firstDigit = digit;
  21703. } else {
  21704. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21705. firstDigit = -1;
  21706. }
  21707. }
  21708. if (firstDigit >= 0 && this.eof) {
  21709. // incomplete byte
  21710. buffer[bufferLength++] = (firstDigit << 4);
  21711. firstDigit = -1;
  21712. }
  21713. this.firstDigit = firstDigit;
  21714. this.bufferLength = bufferLength;
  21715. };
  21716. return AsciiHexStream;
  21717. })();
  21718. var RunLengthStream = (function RunLengthStreamClosure() {
  21719. function RunLengthStream(str, maybeLength) {
  21720. this.str = str;
  21721. this.dict = str.dict;
  21722. DecodeStream.call(this, maybeLength);
  21723. }
  21724. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21725. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21726. // The repeatHeader has following format. The first byte defines type of run
  21727. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21728. // (in addition to the second byte from the header), n = 129 through 255 -
  21729. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21730. var repeatHeader = this.str.getBytes(2);
  21731. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21732. this.eof = true;
  21733. return;
  21734. }
  21735. var buffer;
  21736. var bufferLength = this.bufferLength;
  21737. var n = repeatHeader[0];
  21738. if (n < 128) {
  21739. // copy n bytes
  21740. buffer = this.ensureBuffer(bufferLength + n + 1);
  21741. buffer[bufferLength++] = repeatHeader[1];
  21742. if (n > 0) {
  21743. var source = this.str.getBytes(n);
  21744. buffer.set(source, bufferLength);
  21745. bufferLength += n;
  21746. }
  21747. } else {
  21748. n = 257 - n;
  21749. var b = repeatHeader[1];
  21750. buffer = this.ensureBuffer(bufferLength + n + 1);
  21751. for (var i = 0; i < n; i++) {
  21752. buffer[bufferLength++] = b;
  21753. }
  21754. }
  21755. this.bufferLength = bufferLength;
  21756. };
  21757. return RunLengthStream;
  21758. })();
  21759. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21760. var ccittEOL = -2;
  21761. var ccittEOF = -1;
  21762. var twoDimPass = 0;
  21763. var twoDimHoriz = 1;
  21764. var twoDimVert0 = 2;
  21765. var twoDimVertR1 = 3;
  21766. var twoDimVertL1 = 4;
  21767. var twoDimVertR2 = 5;
  21768. var twoDimVertL2 = 6;
  21769. var twoDimVertR3 = 7;
  21770. var twoDimVertL3 = 8;
  21771. var twoDimTable = [
  21772. [-1, -1], [-1, -1], // 000000x
  21773. [7, twoDimVertL3], // 0000010
  21774. [7, twoDimVertR3], // 0000011
  21775. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21776. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21777. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21778. [4, twoDimPass], [4, twoDimPass],
  21779. [4, twoDimPass], [4, twoDimPass],
  21780. [4, twoDimPass], [4, twoDimPass],
  21781. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21782. [3, twoDimHoriz], [3, twoDimHoriz],
  21783. [3, twoDimHoriz], [3, twoDimHoriz],
  21784. [3, twoDimHoriz], [3, twoDimHoriz],
  21785. [3, twoDimHoriz], [3, twoDimHoriz],
  21786. [3, twoDimHoriz], [3, twoDimHoriz],
  21787. [3, twoDimHoriz], [3, twoDimHoriz],
  21788. [3, twoDimHoriz], [3, twoDimHoriz],
  21789. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21790. [3, twoDimVertL1], [3, twoDimVertL1],
  21791. [3, twoDimVertL1], [3, twoDimVertL1],
  21792. [3, twoDimVertL1], [3, twoDimVertL1],
  21793. [3, twoDimVertL1], [3, twoDimVertL1],
  21794. [3, twoDimVertL1], [3, twoDimVertL1],
  21795. [3, twoDimVertL1], [3, twoDimVertL1],
  21796. [3, twoDimVertL1], [3, twoDimVertL1],
  21797. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21798. [3, twoDimVertR1], [3, twoDimVertR1],
  21799. [3, twoDimVertR1], [3, twoDimVertR1],
  21800. [3, twoDimVertR1], [3, twoDimVertR1],
  21801. [3, twoDimVertR1], [3, twoDimVertR1],
  21802. [3, twoDimVertR1], [3, twoDimVertR1],
  21803. [3, twoDimVertR1], [3, twoDimVertR1],
  21804. [3, twoDimVertR1], [3, twoDimVertR1],
  21805. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21806. [1, twoDimVert0], [1, twoDimVert0],
  21807. [1, twoDimVert0], [1, twoDimVert0],
  21808. [1, twoDimVert0], [1, twoDimVert0],
  21809. [1, twoDimVert0], [1, twoDimVert0],
  21810. [1, twoDimVert0], [1, twoDimVert0],
  21811. [1, twoDimVert0], [1, twoDimVert0],
  21812. [1, twoDimVert0], [1, twoDimVert0],
  21813. [1, twoDimVert0], [1, twoDimVert0],
  21814. [1, twoDimVert0], [1, twoDimVert0],
  21815. [1, twoDimVert0], [1, twoDimVert0],
  21816. [1, twoDimVert0], [1, twoDimVert0],
  21817. [1, twoDimVert0], [1, twoDimVert0],
  21818. [1, twoDimVert0], [1, twoDimVert0],
  21819. [1, twoDimVert0], [1, twoDimVert0],
  21820. [1, twoDimVert0], [1, twoDimVert0],
  21821. [1, twoDimVert0], [1, twoDimVert0],
  21822. [1, twoDimVert0], [1, twoDimVert0],
  21823. [1, twoDimVert0], [1, twoDimVert0],
  21824. [1, twoDimVert0], [1, twoDimVert0],
  21825. [1, twoDimVert0], [1, twoDimVert0],
  21826. [1, twoDimVert0], [1, twoDimVert0],
  21827. [1, twoDimVert0], [1, twoDimVert0],
  21828. [1, twoDimVert0], [1, twoDimVert0],
  21829. [1, twoDimVert0], [1, twoDimVert0],
  21830. [1, twoDimVert0], [1, twoDimVert0],
  21831. [1, twoDimVert0], [1, twoDimVert0],
  21832. [1, twoDimVert0], [1, twoDimVert0],
  21833. [1, twoDimVert0], [1, twoDimVert0],
  21834. [1, twoDimVert0], [1, twoDimVert0],
  21835. [1, twoDimVert0], [1, twoDimVert0],
  21836. [1, twoDimVert0], [1, twoDimVert0]
  21837. ];
  21838. var whiteTable1 = [
  21839. [-1, -1], // 00000
  21840. [12, ccittEOL], // 00001
  21841. [-1, -1], [-1, -1], // 0001x
  21842. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21843. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21844. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21845. [11, 1792], [11, 1792], // 1000x
  21846. [12, 1984], // 10010
  21847. [12, 2048], // 10011
  21848. [12, 2112], // 10100
  21849. [12, 2176], // 10101
  21850. [12, 2240], // 10110
  21851. [12, 2304], // 10111
  21852. [11, 1856], [11, 1856], // 1100x
  21853. [11, 1920], [11, 1920], // 1101x
  21854. [12, 2368], // 11100
  21855. [12, 2432], // 11101
  21856. [12, 2496], // 11110
  21857. [12, 2560] // 11111
  21858. ];
  21859. var whiteTable2 = [
  21860. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21861. [8, 29], [8, 29], // 00000010x
  21862. [8, 30], [8, 30], // 00000011x
  21863. [8, 45], [8, 45], // 00000100x
  21864. [8, 46], [8, 46], // 00000101x
  21865. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21866. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21867. [8, 47], [8, 47], // 00001010x
  21868. [8, 48], [8, 48], // 00001011x
  21869. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21870. [6, 13], [6, 13], [6, 13], [6, 13],
  21871. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21872. [8, 33], [8, 33], // 00010010x
  21873. [8, 34], [8, 34], // 00010011x
  21874. [8, 35], [8, 35], // 00010100x
  21875. [8, 36], [8, 36], // 00010101x
  21876. [8, 37], [8, 37], // 00010110x
  21877. [8, 38], [8, 38], // 00010111x
  21878. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21879. [8, 31], [8, 31], // 00011010x
  21880. [8, 32], [8, 32], // 00011011x
  21881. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21882. [6, 1], [6, 1], [6, 1], [6, 1],
  21883. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21884. [6, 12], [6, 12], [6, 12], [6, 12],
  21885. [8, 53], [8, 53], // 00100100x
  21886. [8, 54], [8, 54], // 00100101x
  21887. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21888. [8, 39], [8, 39], // 00101000x
  21889. [8, 40], [8, 40], // 00101001x
  21890. [8, 41], [8, 41], // 00101010x
  21891. [8, 42], [8, 42], // 00101011x
  21892. [8, 43], [8, 43], // 00101100x
  21893. [8, 44], [8, 44], // 00101101x
  21894. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21895. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21896. [8, 61], [8, 61], // 00110010x
  21897. [8, 62], [8, 62], // 00110011x
  21898. [8, 63], [8, 63], // 00110100x
  21899. [8, 0], [8, 0], // 00110101x
  21900. [8, 320], [8, 320], // 00110110x
  21901. [8, 384], [8, 384], // 00110111x
  21902. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21903. [5, 10], [5, 10], [5, 10], [5, 10],
  21904. [5, 10], [5, 10], [5, 10], [5, 10],
  21905. [5, 10], [5, 10], [5, 10], [5, 10],
  21906. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21907. [5, 11], [5, 11], [5, 11], [5, 11],
  21908. [5, 11], [5, 11], [5, 11], [5, 11],
  21909. [5, 11], [5, 11], [5, 11], [5, 11],
  21910. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21911. [8, 59], [8, 59], // 01001010x
  21912. [8, 60], [8, 60], // 01001011x
  21913. [9, 1472], // 010011000
  21914. [9, 1536], // 010011001
  21915. [9, 1600], // 010011010
  21916. [9, 1728], // 010011011
  21917. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21918. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21919. [8, 49], [8, 49], // 01010010x
  21920. [8, 50], [8, 50], // 01010011x
  21921. [8, 51], [8, 51], // 01010100x
  21922. [8, 52], [8, 52], // 01010101x
  21923. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21924. [8, 55], [8, 55], // 01011000x
  21925. [8, 56], [8, 56], // 01011001x
  21926. [8, 57], [8, 57], // 01011010x
  21927. [8, 58], [8, 58], // 01011011x
  21928. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21929. [6, 192], [6, 192], [6, 192], [6, 192],
  21930. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21931. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21932. [8, 448], [8, 448], // 01100100x
  21933. [8, 512], [8, 512], // 01100101x
  21934. [9, 704], // 011001100
  21935. [9, 768], // 011001101
  21936. [8, 640], [8, 640], // 01100111x
  21937. [8, 576], [8, 576], // 01101000x
  21938. [9, 832], // 011010010
  21939. [9, 896], // 011010011
  21940. [9, 960], // 011010100
  21941. [9, 1024], // 011010101
  21942. [9, 1088], // 011010110
  21943. [9, 1152], // 011010111
  21944. [9, 1216], // 011011000
  21945. [9, 1280], // 011011001
  21946. [9, 1344], // 011011010
  21947. [9, 1408], // 011011011
  21948. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  21949. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  21950. [4, 2], [4, 2], [4, 2], [4, 2],
  21951. [4, 2], [4, 2], [4, 2], [4, 2],
  21952. [4, 2], [4, 2], [4, 2], [4, 2],
  21953. [4, 2], [4, 2], [4, 2], [4, 2],
  21954. [4, 2], [4, 2], [4, 2], [4, 2],
  21955. [4, 2], [4, 2], [4, 2], [4, 2],
  21956. [4, 2], [4, 2], [4, 2], [4, 2],
  21957. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  21958. [4, 3], [4, 3], [4, 3], [4, 3],
  21959. [4, 3], [4, 3], [4, 3], [4, 3],
  21960. [4, 3], [4, 3], [4, 3], [4, 3],
  21961. [4, 3], [4, 3], [4, 3], [4, 3],
  21962. [4, 3], [4, 3], [4, 3], [4, 3],
  21963. [4, 3], [4, 3], [4, 3], [4, 3],
  21964. [4, 3], [4, 3], [4, 3], [4, 3],
  21965. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  21966. [5, 128], [5, 128], [5, 128], [5, 128],
  21967. [5, 128], [5, 128], [5, 128], [5, 128],
  21968. [5, 128], [5, 128], [5, 128], [5, 128],
  21969. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  21970. [5, 8], [5, 8], [5, 8], [5, 8],
  21971. [5, 8], [5, 8], [5, 8], [5, 8],
  21972. [5, 8], [5, 8], [5, 8], [5, 8],
  21973. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  21974. [5, 9], [5, 9], [5, 9], [5, 9],
  21975. [5, 9], [5, 9], [5, 9], [5, 9],
  21976. [5, 9], [5, 9], [5, 9], [5, 9],
  21977. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  21978. [6, 16], [6, 16], [6, 16], [6, 16],
  21979. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  21980. [6, 17], [6, 17], [6, 17], [6, 17],
  21981. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  21982. [4, 4], [4, 4], [4, 4], [4, 4],
  21983. [4, 4], [4, 4], [4, 4], [4, 4],
  21984. [4, 4], [4, 4], [4, 4], [4, 4],
  21985. [4, 4], [4, 4], [4, 4], [4, 4],
  21986. [4, 4], [4, 4], [4, 4], [4, 4],
  21987. [4, 4], [4, 4], [4, 4], [4, 4],
  21988. [4, 4], [4, 4], [4, 4], [4, 4],
  21989. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  21990. [4, 5], [4, 5], [4, 5], [4, 5],
  21991. [4, 5], [4, 5], [4, 5], [4, 5],
  21992. [4, 5], [4, 5], [4, 5], [4, 5],
  21993. [4, 5], [4, 5], [4, 5], [4, 5],
  21994. [4, 5], [4, 5], [4, 5], [4, 5],
  21995. [4, 5], [4, 5], [4, 5], [4, 5],
  21996. [4, 5], [4, 5], [4, 5], [4, 5],
  21997. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  21998. [6, 14], [6, 14], [6, 14], [6, 14],
  21999. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  22000. [6, 15], [6, 15], [6, 15], [6, 15],
  22001. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  22002. [5, 64], [5, 64], [5, 64], [5, 64],
  22003. [5, 64], [5, 64], [5, 64], [5, 64],
  22004. [5, 64], [5, 64], [5, 64], [5, 64],
  22005. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  22006. [4, 6], [4, 6], [4, 6], [4, 6],
  22007. [4, 6], [4, 6], [4, 6], [4, 6],
  22008. [4, 6], [4, 6], [4, 6], [4, 6],
  22009. [4, 6], [4, 6], [4, 6], [4, 6],
  22010. [4, 6], [4, 6], [4, 6], [4, 6],
  22011. [4, 6], [4, 6], [4, 6], [4, 6],
  22012. [4, 6], [4, 6], [4, 6], [4, 6],
  22013. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  22014. [4, 7], [4, 7], [4, 7], [4, 7],
  22015. [4, 7], [4, 7], [4, 7], [4, 7],
  22016. [4, 7], [4, 7], [4, 7], [4, 7],
  22017. [4, 7], [4, 7], [4, 7], [4, 7],
  22018. [4, 7], [4, 7], [4, 7], [4, 7],
  22019. [4, 7], [4, 7], [4, 7], [4, 7],
  22020. [4, 7], [4, 7], [4, 7], [4, 7]
  22021. ];
  22022. var blackTable1 = [
  22023. [-1, -1], [-1, -1], // 000000000000x
  22024. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  22025. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  22026. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  22027. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  22028. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  22029. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  22030. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  22031. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  22032. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  22033. [12, 1984], [12, 1984], // 000000010010x
  22034. [12, 2048], [12, 2048], // 000000010011x
  22035. [12, 2112], [12, 2112], // 000000010100x
  22036. [12, 2176], [12, 2176], // 000000010101x
  22037. [12, 2240], [12, 2240], // 000000010110x
  22038. [12, 2304], [12, 2304], // 000000010111x
  22039. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  22040. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  22041. [12, 2368], [12, 2368], // 000000011100x
  22042. [12, 2432], [12, 2432], // 000000011101x
  22043. [12, 2496], [12, 2496], // 000000011110x
  22044. [12, 2560], [12, 2560], // 000000011111x
  22045. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  22046. [10, 18], [10, 18], [10, 18], [10, 18],
  22047. [12, 52], [12, 52], // 000000100100x
  22048. [13, 640], // 0000001001010
  22049. [13, 704], // 0000001001011
  22050. [13, 768], // 0000001001100
  22051. [13, 832], // 0000001001101
  22052. [12, 55], [12, 55], // 000000100111x
  22053. [12, 56], [12, 56], // 000000101000x
  22054. [13, 1280], // 0000001010010
  22055. [13, 1344], // 0000001010011
  22056. [13, 1408], // 0000001010100
  22057. [13, 1472], // 0000001010101
  22058. [12, 59], [12, 59], // 000000101011x
  22059. [12, 60], [12, 60], // 000000101100x
  22060. [13, 1536], // 0000001011010
  22061. [13, 1600], // 0000001011011
  22062. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  22063. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  22064. [13, 1664], // 0000001100100
  22065. [13, 1728], // 0000001100101
  22066. [12, 320], [12, 320], // 000000110011x
  22067. [12, 384], [12, 384], // 000000110100x
  22068. [12, 448], [12, 448], // 000000110101x
  22069. [13, 512], // 0000001101100
  22070. [13, 576], // 0000001101101
  22071. [12, 53], [12, 53], // 000000110111x
  22072. [12, 54], [12, 54], // 000000111000x
  22073. [13, 896], // 0000001110010
  22074. [13, 960], // 0000001110011
  22075. [13, 1024], // 0000001110100
  22076. [13, 1088], // 0000001110101
  22077. [13, 1152], // 0000001110110
  22078. [13, 1216], // 0000001110111
  22079. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  22080. [10, 64], [10, 64], [10, 64], [10, 64]
  22081. ];
  22082. var blackTable2 = [
  22083. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  22084. [8, 13], [8, 13], [8, 13], [8, 13],
  22085. [8, 13], [8, 13], [8, 13], [8, 13],
  22086. [8, 13], [8, 13], [8, 13], [8, 13],
  22087. [11, 23], [11, 23], // 00000101000x
  22088. [12, 50], // 000001010010
  22089. [12, 51], // 000001010011
  22090. [12, 44], // 000001010100
  22091. [12, 45], // 000001010101
  22092. [12, 46], // 000001010110
  22093. [12, 47], // 000001010111
  22094. [12, 57], // 000001011000
  22095. [12, 58], // 000001011001
  22096. [12, 61], // 000001011010
  22097. [12, 256], // 000001011011
  22098. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  22099. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  22100. [12, 48], // 000001100100
  22101. [12, 49], // 000001100101
  22102. [12, 62], // 000001100110
  22103. [12, 63], // 000001100111
  22104. [12, 30], // 000001101000
  22105. [12, 31], // 000001101001
  22106. [12, 32], // 000001101010
  22107. [12, 33], // 000001101011
  22108. [12, 40], // 000001101100
  22109. [12, 41], // 000001101101
  22110. [11, 22], [11, 22], // 00000110111x
  22111. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  22112. [8, 14], [8, 14], [8, 14], [8, 14],
  22113. [8, 14], [8, 14], [8, 14], [8, 14],
  22114. [8, 14], [8, 14], [8, 14], [8, 14],
  22115. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  22116. [7, 10], [7, 10], [7, 10], [7, 10],
  22117. [7, 10], [7, 10], [7, 10], [7, 10],
  22118. [7, 10], [7, 10], [7, 10], [7, 10],
  22119. [7, 10], [7, 10], [7, 10], [7, 10],
  22120. [7, 10], [7, 10], [7, 10], [7, 10],
  22121. [7, 10], [7, 10], [7, 10], [7, 10],
  22122. [7, 10], [7, 10], [7, 10], [7, 10],
  22123. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  22124. [7, 11], [7, 11], [7, 11], [7, 11],
  22125. [7, 11], [7, 11], [7, 11], [7, 11],
  22126. [7, 11], [7, 11], [7, 11], [7, 11],
  22127. [7, 11], [7, 11], [7, 11], [7, 11],
  22128. [7, 11], [7, 11], [7, 11], [7, 11],
  22129. [7, 11], [7, 11], [7, 11], [7, 11],
  22130. [7, 11], [7, 11], [7, 11], [7, 11],
  22131. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  22132. [9, 15], [9, 15], [9, 15], [9, 15],
  22133. [12, 128], // 000011001000
  22134. [12, 192], // 000011001001
  22135. [12, 26], // 000011001010
  22136. [12, 27], // 000011001011
  22137. [12, 28], // 000011001100
  22138. [12, 29], // 000011001101
  22139. [11, 19], [11, 19], // 00001100111x
  22140. [11, 20], [11, 20], // 00001101000x
  22141. [12, 34], // 000011010010
  22142. [12, 35], // 000011010011
  22143. [12, 36], // 000011010100
  22144. [12, 37], // 000011010101
  22145. [12, 38], // 000011010110
  22146. [12, 39], // 000011010111
  22147. [11, 21], [11, 21], // 00001101100x
  22148. [12, 42], // 000011011010
  22149. [12, 43], // 000011011011
  22150. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  22151. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  22152. [7, 12], [7, 12], [7, 12], [7, 12],
  22153. [7, 12], [7, 12], [7, 12], [7, 12],
  22154. [7, 12], [7, 12], [7, 12], [7, 12],
  22155. [7, 12], [7, 12], [7, 12], [7, 12],
  22156. [7, 12], [7, 12], [7, 12], [7, 12],
  22157. [7, 12], [7, 12], [7, 12], [7, 12],
  22158. [7, 12], [7, 12], [7, 12], [7, 12]
  22159. ];
  22160. var blackTable3 = [
  22161. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  22162. [6, 9], // 000100
  22163. [6, 8], // 000101
  22164. [5, 7], [5, 7], // 00011x
  22165. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  22166. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  22167. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  22168. [3, 1], [3, 1], [3, 1], [3, 1],
  22169. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  22170. [3, 4], [3, 4], [3, 4], [3, 4],
  22171. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  22172. [2, 3], [2, 3], [2, 3], [2, 3],
  22173. [2, 3], [2, 3], [2, 3], [2, 3],
  22174. [2, 3], [2, 3], [2, 3], [2, 3],
  22175. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  22176. [2, 2], [2, 2], [2, 2], [2, 2],
  22177. [2, 2], [2, 2], [2, 2], [2, 2],
  22178. [2, 2], [2, 2], [2, 2], [2, 2]
  22179. ];
  22180. function CCITTFaxStream(str, maybeLength, params) {
  22181. this.str = str;
  22182. this.dict = str.dict;
  22183. params = params || Dict.empty;
  22184. this.encoding = params.get('K') || 0;
  22185. this.eoline = params.get('EndOfLine') || false;
  22186. this.byteAlign = params.get('EncodedByteAlign') || false;
  22187. this.columns = params.get('Columns') || 1728;
  22188. this.rows = params.get('Rows') || 0;
  22189. var eoblock = params.get('EndOfBlock');
  22190. if (eoblock === null || eoblock === undefined) {
  22191. eoblock = true;
  22192. }
  22193. this.eoblock = eoblock;
  22194. this.black = params.get('BlackIs1') || false;
  22195. this.codingLine = new Uint32Array(this.columns + 1);
  22196. this.refLine = new Uint32Array(this.columns + 2);
  22197. this.codingLine[0] = this.columns;
  22198. this.codingPos = 0;
  22199. this.row = 0;
  22200. this.nextLine2D = this.encoding < 0;
  22201. this.inputBits = 0;
  22202. this.inputBuf = 0;
  22203. this.outputBits = 0;
  22204. var code1;
  22205. while ((code1 = this.lookBits(12)) === 0) {
  22206. this.eatBits(1);
  22207. }
  22208. if (code1 === 1) {
  22209. this.eatBits(12);
  22210. }
  22211. if (this.encoding > 0) {
  22212. this.nextLine2D = !this.lookBits(1);
  22213. this.eatBits(1);
  22214. }
  22215. DecodeStream.call(this, maybeLength);
  22216. }
  22217. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  22218. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  22219. while (!this.eof) {
  22220. var c = this.lookChar();
  22221. this.ensureBuffer(this.bufferLength + 1);
  22222. this.buffer[this.bufferLength++] = c;
  22223. }
  22224. };
  22225. CCITTFaxStream.prototype.addPixels =
  22226. function ccittFaxStreamAddPixels(a1, blackPixels) {
  22227. var codingLine = this.codingLine;
  22228. var codingPos = this.codingPos;
  22229. if (a1 > codingLine[codingPos]) {
  22230. if (a1 > this.columns) {
  22231. info('row is wrong length');
  22232. this.err = true;
  22233. a1 = this.columns;
  22234. }
  22235. if ((codingPos & 1) ^ blackPixels) {
  22236. ++codingPos;
  22237. }
  22238. codingLine[codingPos] = a1;
  22239. }
  22240. this.codingPos = codingPos;
  22241. };
  22242. CCITTFaxStream.prototype.addPixelsNeg =
  22243. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22244. var codingLine = this.codingLine;
  22245. var codingPos = this.codingPos;
  22246. if (a1 > codingLine[codingPos]) {
  22247. if (a1 > this.columns) {
  22248. info('row is wrong length');
  22249. this.err = true;
  22250. a1 = this.columns;
  22251. }
  22252. if ((codingPos & 1) ^ blackPixels) {
  22253. ++codingPos;
  22254. }
  22255. codingLine[codingPos] = a1;
  22256. } else if (a1 < codingLine[codingPos]) {
  22257. if (a1 < 0) {
  22258. info('invalid code');
  22259. this.err = true;
  22260. a1 = 0;
  22261. }
  22262. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22263. --codingPos;
  22264. }
  22265. codingLine[codingPos] = a1;
  22266. }
  22267. this.codingPos = codingPos;
  22268. };
  22269. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22270. var refLine = this.refLine;
  22271. var codingLine = this.codingLine;
  22272. var columns = this.columns;
  22273. var refPos, blackPixels, bits, i;
  22274. if (this.outputBits === 0) {
  22275. if (this.eof) {
  22276. return null;
  22277. }
  22278. this.err = false;
  22279. var code1, code2, code3;
  22280. if (this.nextLine2D) {
  22281. for (i = 0; codingLine[i] < columns; ++i) {
  22282. refLine[i] = codingLine[i];
  22283. }
  22284. refLine[i++] = columns;
  22285. refLine[i] = columns;
  22286. codingLine[0] = 0;
  22287. this.codingPos = 0;
  22288. refPos = 0;
  22289. blackPixels = 0;
  22290. while (codingLine[this.codingPos] < columns) {
  22291. code1 = this.getTwoDimCode();
  22292. switch (code1) {
  22293. case twoDimPass:
  22294. this.addPixels(refLine[refPos + 1], blackPixels);
  22295. if (refLine[refPos + 1] < columns) {
  22296. refPos += 2;
  22297. }
  22298. break;
  22299. case twoDimHoriz:
  22300. code1 = code2 = 0;
  22301. if (blackPixels) {
  22302. do {
  22303. code1 += (code3 = this.getBlackCode());
  22304. } while (code3 >= 64);
  22305. do {
  22306. code2 += (code3 = this.getWhiteCode());
  22307. } while (code3 >= 64);
  22308. } else {
  22309. do {
  22310. code1 += (code3 = this.getWhiteCode());
  22311. } while (code3 >= 64);
  22312. do {
  22313. code2 += (code3 = this.getBlackCode());
  22314. } while (code3 >= 64);
  22315. }
  22316. this.addPixels(codingLine[this.codingPos] +
  22317. code1, blackPixels);
  22318. if (codingLine[this.codingPos] < columns) {
  22319. this.addPixels(codingLine[this.codingPos] + code2,
  22320. blackPixels ^ 1);
  22321. }
  22322. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22323. refLine[refPos] < columns) {
  22324. refPos += 2;
  22325. }
  22326. break;
  22327. case twoDimVertR3:
  22328. this.addPixels(refLine[refPos] + 3, blackPixels);
  22329. blackPixels ^= 1;
  22330. if (codingLine[this.codingPos] < columns) {
  22331. ++refPos;
  22332. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22333. refLine[refPos] < columns) {
  22334. refPos += 2;
  22335. }
  22336. }
  22337. break;
  22338. case twoDimVertR2:
  22339. this.addPixels(refLine[refPos] + 2, blackPixels);
  22340. blackPixels ^= 1;
  22341. if (codingLine[this.codingPos] < columns) {
  22342. ++refPos;
  22343. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22344. refLine[refPos] < columns) {
  22345. refPos += 2;
  22346. }
  22347. }
  22348. break;
  22349. case twoDimVertR1:
  22350. this.addPixels(refLine[refPos] + 1, blackPixels);
  22351. blackPixels ^= 1;
  22352. if (codingLine[this.codingPos] < columns) {
  22353. ++refPos;
  22354. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22355. refLine[refPos] < columns) {
  22356. refPos += 2;
  22357. }
  22358. }
  22359. break;
  22360. case twoDimVert0:
  22361. this.addPixels(refLine[refPos], blackPixels);
  22362. blackPixels ^= 1;
  22363. if (codingLine[this.codingPos] < columns) {
  22364. ++refPos;
  22365. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22366. refLine[refPos] < columns) {
  22367. refPos += 2;
  22368. }
  22369. }
  22370. break;
  22371. case twoDimVertL3:
  22372. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22373. blackPixels ^= 1;
  22374. if (codingLine[this.codingPos] < columns) {
  22375. if (refPos > 0) {
  22376. --refPos;
  22377. } else {
  22378. ++refPos;
  22379. }
  22380. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22381. refLine[refPos] < columns) {
  22382. refPos += 2;
  22383. }
  22384. }
  22385. break;
  22386. case twoDimVertL2:
  22387. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22388. blackPixels ^= 1;
  22389. if (codingLine[this.codingPos] < columns) {
  22390. if (refPos > 0) {
  22391. --refPos;
  22392. } else {
  22393. ++refPos;
  22394. }
  22395. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22396. refLine[refPos] < columns) {
  22397. refPos += 2;
  22398. }
  22399. }
  22400. break;
  22401. case twoDimVertL1:
  22402. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22403. blackPixels ^= 1;
  22404. if (codingLine[this.codingPos] < columns) {
  22405. if (refPos > 0) {
  22406. --refPos;
  22407. } else {
  22408. ++refPos;
  22409. }
  22410. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22411. refLine[refPos] < columns) {
  22412. refPos += 2;
  22413. }
  22414. }
  22415. break;
  22416. case ccittEOF:
  22417. this.addPixels(columns, 0);
  22418. this.eof = true;
  22419. break;
  22420. default:
  22421. info('bad 2d code');
  22422. this.addPixels(columns, 0);
  22423. this.err = true;
  22424. }
  22425. }
  22426. } else {
  22427. codingLine[0] = 0;
  22428. this.codingPos = 0;
  22429. blackPixels = 0;
  22430. while (codingLine[this.codingPos] < columns) {
  22431. code1 = 0;
  22432. if (blackPixels) {
  22433. do {
  22434. code1 += (code3 = this.getBlackCode());
  22435. } while (code3 >= 64);
  22436. } else {
  22437. do {
  22438. code1 += (code3 = this.getWhiteCode());
  22439. } while (code3 >= 64);
  22440. }
  22441. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22442. blackPixels ^= 1;
  22443. }
  22444. }
  22445. var gotEOL = false;
  22446. if (this.byteAlign) {
  22447. this.inputBits &= ~7;
  22448. }
  22449. if (!this.eoblock && this.row === this.rows - 1) {
  22450. this.eof = true;
  22451. } else {
  22452. code1 = this.lookBits(12);
  22453. if (this.eoline) {
  22454. while (code1 !== ccittEOF && code1 !== 1) {
  22455. this.eatBits(1);
  22456. code1 = this.lookBits(12);
  22457. }
  22458. } else {
  22459. while (code1 === 0) {
  22460. this.eatBits(1);
  22461. code1 = this.lookBits(12);
  22462. }
  22463. }
  22464. if (code1 === 1) {
  22465. this.eatBits(12);
  22466. gotEOL = true;
  22467. } else if (code1 === ccittEOF) {
  22468. this.eof = true;
  22469. }
  22470. }
  22471. if (!this.eof && this.encoding > 0) {
  22472. this.nextLine2D = !this.lookBits(1);
  22473. this.eatBits(1);
  22474. }
  22475. if (this.eoblock && gotEOL && this.byteAlign) {
  22476. code1 = this.lookBits(12);
  22477. if (code1 === 1) {
  22478. this.eatBits(12);
  22479. if (this.encoding > 0) {
  22480. this.lookBits(1);
  22481. this.eatBits(1);
  22482. }
  22483. if (this.encoding >= 0) {
  22484. for (i = 0; i < 4; ++i) {
  22485. code1 = this.lookBits(12);
  22486. if (code1 !== 1) {
  22487. info('bad rtc code: ' + code1);
  22488. }
  22489. this.eatBits(12);
  22490. if (this.encoding > 0) {
  22491. this.lookBits(1);
  22492. this.eatBits(1);
  22493. }
  22494. }
  22495. }
  22496. this.eof = true;
  22497. }
  22498. } else if (this.err && this.eoline) {
  22499. while (true) {
  22500. code1 = this.lookBits(13);
  22501. if (code1 === ccittEOF) {
  22502. this.eof = true;
  22503. return null;
  22504. }
  22505. if ((code1 >> 1) === 1) {
  22506. break;
  22507. }
  22508. this.eatBits(1);
  22509. }
  22510. this.eatBits(12);
  22511. if (this.encoding > 0) {
  22512. this.eatBits(1);
  22513. this.nextLine2D = !(code1 & 1);
  22514. }
  22515. }
  22516. if (codingLine[0] > 0) {
  22517. this.outputBits = codingLine[this.codingPos = 0];
  22518. } else {
  22519. this.outputBits = codingLine[this.codingPos = 1];
  22520. }
  22521. this.row++;
  22522. }
  22523. var c;
  22524. if (this.outputBits >= 8) {
  22525. c = (this.codingPos & 1) ? 0 : 0xFF;
  22526. this.outputBits -= 8;
  22527. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22528. this.codingPos++;
  22529. this.outputBits = (codingLine[this.codingPos] -
  22530. codingLine[this.codingPos - 1]);
  22531. }
  22532. } else {
  22533. bits = 8;
  22534. c = 0;
  22535. do {
  22536. if (this.outputBits > bits) {
  22537. c <<= bits;
  22538. if (!(this.codingPos & 1)) {
  22539. c |= 0xFF >> (8 - bits);
  22540. }
  22541. this.outputBits -= bits;
  22542. bits = 0;
  22543. } else {
  22544. c <<= this.outputBits;
  22545. if (!(this.codingPos & 1)) {
  22546. c |= 0xFF >> (8 - this.outputBits);
  22547. }
  22548. bits -= this.outputBits;
  22549. this.outputBits = 0;
  22550. if (codingLine[this.codingPos] < columns) {
  22551. this.codingPos++;
  22552. this.outputBits = (codingLine[this.codingPos] -
  22553. codingLine[this.codingPos - 1]);
  22554. } else if (bits > 0) {
  22555. c <<= bits;
  22556. bits = 0;
  22557. }
  22558. }
  22559. } while (bits);
  22560. }
  22561. if (this.black) {
  22562. c ^= 0xFF;
  22563. }
  22564. return c;
  22565. };
  22566. // This functions returns the code found from the table.
  22567. // The start and end parameters set the boundaries for searching the table.
  22568. // The limit parameter is optional. Function returns an array with three
  22569. // values. The first array element indicates whether a valid code is being
  22570. // returned. The second array element is the actual code. The third array
  22571. // element indicates whether EOF was reached.
  22572. CCITTFaxStream.prototype.findTableCode =
  22573. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22574. var limitValue = limit || 0;
  22575. for (var i = start; i <= end; ++i) {
  22576. var code = this.lookBits(i);
  22577. if (code === ccittEOF) {
  22578. return [true, 1, false];
  22579. }
  22580. if (i < end) {
  22581. code <<= end - i;
  22582. }
  22583. if (!limitValue || code >= limitValue) {
  22584. var p = table[code - limitValue];
  22585. if (p[0] === i) {
  22586. this.eatBits(i);
  22587. return [true, p[1], true];
  22588. }
  22589. }
  22590. }
  22591. return [false, 0, false];
  22592. };
  22593. CCITTFaxStream.prototype.getTwoDimCode =
  22594. function ccittFaxStreamGetTwoDimCode() {
  22595. var code = 0;
  22596. var p;
  22597. if (this.eoblock) {
  22598. code = this.lookBits(7);
  22599. p = twoDimTable[code];
  22600. if (p && p[0] > 0) {
  22601. this.eatBits(p[0]);
  22602. return p[1];
  22603. }
  22604. } else {
  22605. var result = this.findTableCode(1, 7, twoDimTable);
  22606. if (result[0] && result[2]) {
  22607. return result[1];
  22608. }
  22609. }
  22610. info('Bad two dim code');
  22611. return ccittEOF;
  22612. };
  22613. CCITTFaxStream.prototype.getWhiteCode =
  22614. function ccittFaxStreamGetWhiteCode() {
  22615. var code = 0;
  22616. var p;
  22617. if (this.eoblock) {
  22618. code = this.lookBits(12);
  22619. if (code === ccittEOF) {
  22620. return 1;
  22621. }
  22622. if ((code >> 5) === 0) {
  22623. p = whiteTable1[code];
  22624. } else {
  22625. p = whiteTable2[code >> 3];
  22626. }
  22627. if (p[0] > 0) {
  22628. this.eatBits(p[0]);
  22629. return p[1];
  22630. }
  22631. } else {
  22632. var result = this.findTableCode(1, 9, whiteTable2);
  22633. if (result[0]) {
  22634. return result[1];
  22635. }
  22636. result = this.findTableCode(11, 12, whiteTable1);
  22637. if (result[0]) {
  22638. return result[1];
  22639. }
  22640. }
  22641. info('bad white code');
  22642. this.eatBits(1);
  22643. return 1;
  22644. };
  22645. CCITTFaxStream.prototype.getBlackCode =
  22646. function ccittFaxStreamGetBlackCode() {
  22647. var code, p;
  22648. if (this.eoblock) {
  22649. code = this.lookBits(13);
  22650. if (code === ccittEOF) {
  22651. return 1;
  22652. }
  22653. if ((code >> 7) === 0) {
  22654. p = blackTable1[code];
  22655. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22656. p = blackTable2[(code >> 1) - 64];
  22657. } else {
  22658. p = blackTable3[code >> 7];
  22659. }
  22660. if (p[0] > 0) {
  22661. this.eatBits(p[0]);
  22662. return p[1];
  22663. }
  22664. } else {
  22665. var result = this.findTableCode(2, 6, blackTable3);
  22666. if (result[0]) {
  22667. return result[1];
  22668. }
  22669. result = this.findTableCode(7, 12, blackTable2, 64);
  22670. if (result[0]) {
  22671. return result[1];
  22672. }
  22673. result = this.findTableCode(10, 13, blackTable1);
  22674. if (result[0]) {
  22675. return result[1];
  22676. }
  22677. }
  22678. info('bad black code');
  22679. this.eatBits(1);
  22680. return 1;
  22681. };
  22682. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22683. var c;
  22684. while (this.inputBits < n) {
  22685. if ((c = this.str.getByte()) === -1) {
  22686. if (this.inputBits === 0) {
  22687. return ccittEOF;
  22688. }
  22689. return ((this.inputBuf << (n - this.inputBits)) &
  22690. (0xFFFF >> (16 - n)));
  22691. }
  22692. this.inputBuf = (this.inputBuf << 8) | c;
  22693. this.inputBits += 8;
  22694. }
  22695. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22696. };
  22697. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22698. if ((this.inputBits -= n) < 0) {
  22699. this.inputBits = 0;
  22700. }
  22701. };
  22702. return CCITTFaxStream;
  22703. })();
  22704. var LZWStream = (function LZWStreamClosure() {
  22705. function LZWStream(str, maybeLength, earlyChange) {
  22706. this.str = str;
  22707. this.dict = str.dict;
  22708. this.cachedData = 0;
  22709. this.bitsCached = 0;
  22710. var maxLzwDictionarySize = 4096;
  22711. var lzwState = {
  22712. earlyChange: earlyChange,
  22713. codeLength: 9,
  22714. nextCode: 258,
  22715. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22716. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22717. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22718. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22719. currentSequenceLength: 0
  22720. };
  22721. for (var i = 0; i < 256; ++i) {
  22722. lzwState.dictionaryValues[i] = i;
  22723. lzwState.dictionaryLengths[i] = 1;
  22724. }
  22725. this.lzwState = lzwState;
  22726. DecodeStream.call(this, maybeLength);
  22727. }
  22728. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22729. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22730. var bitsCached = this.bitsCached;
  22731. var cachedData = this.cachedData;
  22732. while (bitsCached < n) {
  22733. var c = this.str.getByte();
  22734. if (c === -1) {
  22735. this.eof = true;
  22736. return null;
  22737. }
  22738. cachedData = (cachedData << 8) | c;
  22739. bitsCached += 8;
  22740. }
  22741. this.bitsCached = (bitsCached -= n);
  22742. this.cachedData = cachedData;
  22743. this.lastCode = null;
  22744. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22745. };
  22746. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22747. var blockSize = 512;
  22748. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22749. var i, j, q;
  22750. var lzwState = this.lzwState;
  22751. if (!lzwState) {
  22752. return; // eof was found
  22753. }
  22754. var earlyChange = lzwState.earlyChange;
  22755. var nextCode = lzwState.nextCode;
  22756. var dictionaryValues = lzwState.dictionaryValues;
  22757. var dictionaryLengths = lzwState.dictionaryLengths;
  22758. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22759. var codeLength = lzwState.codeLength;
  22760. var prevCode = lzwState.prevCode;
  22761. var currentSequence = lzwState.currentSequence;
  22762. var currentSequenceLength = lzwState.currentSequenceLength;
  22763. var decodedLength = 0;
  22764. var currentBufferLength = this.bufferLength;
  22765. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22766. for (i = 0; i < blockSize; i++) {
  22767. var code = this.readBits(codeLength);
  22768. var hasPrev = currentSequenceLength > 0;
  22769. if (code < 256) {
  22770. currentSequence[0] = code;
  22771. currentSequenceLength = 1;
  22772. } else if (code >= 258) {
  22773. if (code < nextCode) {
  22774. currentSequenceLength = dictionaryLengths[code];
  22775. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22776. currentSequence[j] = dictionaryValues[q];
  22777. q = dictionaryPrevCodes[q];
  22778. }
  22779. } else {
  22780. currentSequence[currentSequenceLength++] = currentSequence[0];
  22781. }
  22782. } else if (code === 256) {
  22783. codeLength = 9;
  22784. nextCode = 258;
  22785. currentSequenceLength = 0;
  22786. continue;
  22787. } else {
  22788. this.eof = true;
  22789. delete this.lzwState;
  22790. break;
  22791. }
  22792. if (hasPrev) {
  22793. dictionaryPrevCodes[nextCode] = prevCode;
  22794. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22795. dictionaryValues[nextCode] = currentSequence[0];
  22796. nextCode++;
  22797. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22798. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22799. 0.6931471805599453 + 1, 12) | 0;
  22800. }
  22801. prevCode = code;
  22802. decodedLength += currentSequenceLength;
  22803. if (estimatedDecodedSize < decodedLength) {
  22804. do {
  22805. estimatedDecodedSize += decodedSizeDelta;
  22806. } while (estimatedDecodedSize < decodedLength);
  22807. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22808. }
  22809. for (j = 0; j < currentSequenceLength; j++) {
  22810. buffer[currentBufferLength++] = currentSequence[j];
  22811. }
  22812. }
  22813. lzwState.nextCode = nextCode;
  22814. lzwState.codeLength = codeLength;
  22815. lzwState.prevCode = prevCode;
  22816. lzwState.currentSequenceLength = currentSequenceLength;
  22817. this.bufferLength = currentBufferLength;
  22818. };
  22819. return LZWStream;
  22820. })();
  22821. var NullStream = (function NullStreamClosure() {
  22822. function NullStream() {
  22823. Stream.call(this, new Uint8Array(0));
  22824. }
  22825. NullStream.prototype = Stream.prototype;
  22826. return NullStream;
  22827. })();
  22828. exports.Ascii85Stream = Ascii85Stream;
  22829. exports.AsciiHexStream = AsciiHexStream;
  22830. exports.CCITTFaxStream = CCITTFaxStream;
  22831. exports.DecryptStream = DecryptStream;
  22832. exports.DecodeStream = DecodeStream;
  22833. exports.FlateStream = FlateStream;
  22834. exports.Jbig2Stream = Jbig2Stream;
  22835. exports.JpegStream = JpegStream;
  22836. exports.JpxStream = JpxStream;
  22837. exports.NullStream = NullStream;
  22838. exports.PredictorStream = PredictorStream;
  22839. exports.RunLengthStream = RunLengthStream;
  22840. exports.Stream = Stream;
  22841. exports.StreamsSequenceStream = StreamsSequenceStream;
  22842. exports.StringStream = StringStream;
  22843. exports.LZWStream = LZWStream;
  22844. }));
  22845. (function (root, factory) {
  22846. {
  22847. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  22848. root.pdfjsDisplayDOMUtils);
  22849. }
  22850. }(this, function (exports, sharedUtil, displayDOMUtils) {
  22851. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  22852. var AnnotationType = sharedUtil.AnnotationType;
  22853. var isInt = sharedUtil.isInt;
  22854. var Util = sharedUtil.Util;
  22855. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  22856. var LinkTarget = displayDOMUtils.LinkTarget;
  22857. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  22858. var warn = sharedUtil.warn;
  22859. var CustomStyle = displayDOMUtils.CustomStyle;
  22860. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  22861. /**
  22862. * @typedef {Object} AnnotationElementParameters
  22863. * @property {Object} data
  22864. * @property {HTMLDivElement} layer
  22865. * @property {PDFPage} page
  22866. * @property {PageViewport} viewport
  22867. * @property {IPDFLinkService} linkService
  22868. * @property {DownloadManager} downloadManager
  22869. * @property {string} imageResourcesPath
  22870. * @property {boolean} renderInteractiveForms
  22871. */
  22872. /**
  22873. * @class
  22874. * @alias AnnotationElementFactory
  22875. */
  22876. function AnnotationElementFactory() {}
  22877. AnnotationElementFactory.prototype =
  22878. /** @lends AnnotationElementFactory.prototype */ {
  22879. /**
  22880. * @param {AnnotationElementParameters} parameters
  22881. * @returns {AnnotationElement}
  22882. */
  22883. create: function AnnotationElementFactory_create(parameters) {
  22884. var subtype = parameters.data.annotationType;
  22885. switch (subtype) {
  22886. case AnnotationType.LINK:
  22887. return new LinkAnnotationElement(parameters);
  22888. case AnnotationType.TEXT:
  22889. return new TextAnnotationElement(parameters);
  22890. case AnnotationType.WIDGET:
  22891. var fieldType = parameters.data.fieldType;
  22892. switch (fieldType) {
  22893. case 'Tx':
  22894. return new TextWidgetAnnotationElement(parameters);
  22895. }
  22896. return new WidgetAnnotationElement(parameters);
  22897. case AnnotationType.POPUP:
  22898. return new PopupAnnotationElement(parameters);
  22899. case AnnotationType.HIGHLIGHT:
  22900. return new HighlightAnnotationElement(parameters);
  22901. case AnnotationType.UNDERLINE:
  22902. return new UnderlineAnnotationElement(parameters);
  22903. case AnnotationType.SQUIGGLY:
  22904. return new SquigglyAnnotationElement(parameters);
  22905. case AnnotationType.STRIKEOUT:
  22906. return new StrikeOutAnnotationElement(parameters);
  22907. case AnnotationType.FILEATTACHMENT:
  22908. return new FileAttachmentAnnotationElement(parameters);
  22909. default:
  22910. return new AnnotationElement(parameters);
  22911. }
  22912. }
  22913. };
  22914. /**
  22915. * @class
  22916. * @alias AnnotationElement
  22917. */
  22918. var AnnotationElement = (function AnnotationElementClosure() {
  22919. function AnnotationElement(parameters, isRenderable) {
  22920. this.isRenderable = isRenderable || false;
  22921. this.data = parameters.data;
  22922. this.layer = parameters.layer;
  22923. this.page = parameters.page;
  22924. this.viewport = parameters.viewport;
  22925. this.linkService = parameters.linkService;
  22926. this.downloadManager = parameters.downloadManager;
  22927. this.imageResourcesPath = parameters.imageResourcesPath;
  22928. this.renderInteractiveForms = parameters.renderInteractiveForms;
  22929. if (isRenderable) {
  22930. this.container = this._createContainer();
  22931. }
  22932. }
  22933. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  22934. /**
  22935. * Create an empty container for the annotation's HTML element.
  22936. *
  22937. * @private
  22938. * @memberof AnnotationElement
  22939. * @returns {HTMLSectionElement}
  22940. */
  22941. _createContainer: function AnnotationElement_createContainer() {
  22942. var data = this.data, page = this.page, viewport = this.viewport;
  22943. var container = document.createElement('section');
  22944. var width = data.rect[2] - data.rect[0];
  22945. var height = data.rect[3] - data.rect[1];
  22946. container.setAttribute('data-annotation-id', data.id);
  22947. // Do *not* modify `data.rect`, since that will corrupt the annotation
  22948. // position on subsequent calls to `_createContainer` (see issue 6804).
  22949. var rect = Util.normalizeRect([
  22950. data.rect[0],
  22951. page.view[3] - data.rect[1] + page.view[1],
  22952. data.rect[2],
  22953. page.view[3] - data.rect[3] + page.view[1]
  22954. ]);
  22955. CustomStyle.setProp('transform', container,
  22956. 'matrix(' + viewport.transform.join(',') + ')');
  22957. CustomStyle.setProp('transformOrigin', container,
  22958. -rect[0] + 'px ' + -rect[1] + 'px');
  22959. if (data.borderStyle.width > 0) {
  22960. container.style.borderWidth = data.borderStyle.width + 'px';
  22961. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  22962. // Underline styles only have a bottom border, so we do not need
  22963. // to adjust for all borders. This yields a similar result as
  22964. // Adobe Acrobat/Reader.
  22965. width = width - 2 * data.borderStyle.width;
  22966. height = height - 2 * data.borderStyle.width;
  22967. }
  22968. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  22969. var verticalRadius = data.borderStyle.verticalCornerRadius;
  22970. if (horizontalRadius > 0 || verticalRadius > 0) {
  22971. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  22972. CustomStyle.setProp('borderRadius', container, radius);
  22973. }
  22974. switch (data.borderStyle.style) {
  22975. case AnnotationBorderStyleType.SOLID:
  22976. container.style.borderStyle = 'solid';
  22977. break;
  22978. case AnnotationBorderStyleType.DASHED:
  22979. container.style.borderStyle = 'dashed';
  22980. break;
  22981. case AnnotationBorderStyleType.BEVELED:
  22982. warn('Unimplemented border style: beveled');
  22983. break;
  22984. case AnnotationBorderStyleType.INSET:
  22985. warn('Unimplemented border style: inset');
  22986. break;
  22987. case AnnotationBorderStyleType.UNDERLINE:
  22988. container.style.borderBottomStyle = 'solid';
  22989. break;
  22990. default:
  22991. break;
  22992. }
  22993. if (data.color) {
  22994. container.style.borderColor =
  22995. Util.makeCssRgb(data.color[0] | 0,
  22996. data.color[1] | 0,
  22997. data.color[2] | 0);
  22998. } else {
  22999. // Transparent (invisible) border, so do not draw it at all.
  23000. container.style.borderWidth = 0;
  23001. }
  23002. }
  23003. container.style.left = rect[0] + 'px';
  23004. container.style.top = rect[1] + 'px';
  23005. container.style.width = width + 'px';
  23006. container.style.height = height + 'px';
  23007. return container;
  23008. },
  23009. /**
  23010. * Create a popup for the annotation's HTML element. This is used for
  23011. * annotations that do not have a Popup entry in the dictionary, but
  23012. * are of a type that works with popups (such as Highlight annotations).
  23013. *
  23014. * @private
  23015. * @param {HTMLSectionElement} container
  23016. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  23017. * @param {Object} data
  23018. * @memberof AnnotationElement
  23019. */
  23020. _createPopup:
  23021. function AnnotationElement_createPopup(container, trigger, data) {
  23022. // If no trigger element is specified, create it.
  23023. if (!trigger) {
  23024. trigger = document.createElement('div');
  23025. trigger.style.height = container.style.height;
  23026. trigger.style.width = container.style.width;
  23027. container.appendChild(trigger);
  23028. }
  23029. var popupElement = new PopupElement({
  23030. container: container,
  23031. trigger: trigger,
  23032. color: data.color,
  23033. title: data.title,
  23034. contents: data.contents,
  23035. hideWrapper: true
  23036. });
  23037. var popup = popupElement.render();
  23038. // Position the popup next to the annotation's container.
  23039. popup.style.left = container.style.width;
  23040. container.appendChild(popup);
  23041. },
  23042. /**
  23043. * Render the annotation's HTML element in the empty container.
  23044. *
  23045. * @public
  23046. * @memberof AnnotationElement
  23047. */
  23048. render: function AnnotationElement_render() {
  23049. throw new Error('Abstract method AnnotationElement.render called');
  23050. }
  23051. };
  23052. return AnnotationElement;
  23053. })();
  23054. /**
  23055. * @class
  23056. * @alias LinkAnnotationElement
  23057. */
  23058. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  23059. function LinkAnnotationElement(parameters) {
  23060. AnnotationElement.call(this, parameters, true);
  23061. }
  23062. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  23063. /**
  23064. * Render the link annotation's HTML element in the empty container.
  23065. *
  23066. * @public
  23067. * @memberof LinkAnnotationElement
  23068. * @returns {HTMLSectionElement}
  23069. */
  23070. render: function LinkAnnotationElement_render() {
  23071. this.container.className = 'linkAnnotation';
  23072. var link = document.createElement('a');
  23073. addLinkAttributes(link, {
  23074. url: this.data.url,
  23075. target: (this.data.newWindow ? LinkTarget.BLANK : undefined),
  23076. });
  23077. if (!this.data.url) {
  23078. if (this.data.action) {
  23079. this._bindNamedAction(link, this.data.action);
  23080. } else {
  23081. this._bindLink(link, (this.data.dest || null));
  23082. }
  23083. }
  23084. this.container.appendChild(link);
  23085. return this.container;
  23086. },
  23087. /**
  23088. * Bind internal links to the link element.
  23089. *
  23090. * @private
  23091. * @param {Object} link
  23092. * @param {Object} destination
  23093. * @memberof LinkAnnotationElement
  23094. */
  23095. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  23096. var self = this;
  23097. link.href = this.linkService.getDestinationHash(destination);
  23098. link.onclick = function() {
  23099. if (destination) {
  23100. self.linkService.navigateTo(destination);
  23101. }
  23102. return false;
  23103. };
  23104. if (destination) {
  23105. link.className = 'internalLink';
  23106. }
  23107. },
  23108. /**
  23109. * Bind named actions to the link element.
  23110. *
  23111. * @private
  23112. * @param {Object} link
  23113. * @param {Object} action
  23114. * @memberof LinkAnnotationElement
  23115. */
  23116. _bindNamedAction:
  23117. function LinkAnnotationElement_bindNamedAction(link, action) {
  23118. var self = this;
  23119. link.href = this.linkService.getAnchorUrl('');
  23120. link.onclick = function() {
  23121. self.linkService.executeNamedAction(action);
  23122. return false;
  23123. };
  23124. link.className = 'internalLink';
  23125. }
  23126. });
  23127. return LinkAnnotationElement;
  23128. })();
  23129. /**
  23130. * @class
  23131. * @alias TextAnnotationElement
  23132. */
  23133. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  23134. function TextAnnotationElement(parameters) {
  23135. var isRenderable = !!(parameters.data.hasPopup ||
  23136. parameters.data.title || parameters.data.contents);
  23137. AnnotationElement.call(this, parameters, isRenderable);
  23138. }
  23139. Util.inherit(TextAnnotationElement, AnnotationElement, {
  23140. /**
  23141. * Render the text annotation's HTML element in the empty container.
  23142. *
  23143. * @public
  23144. * @memberof TextAnnotationElement
  23145. * @returns {HTMLSectionElement}
  23146. */
  23147. render: function TextAnnotationElement_render() {
  23148. this.container.className = 'textAnnotation';
  23149. var image = document.createElement('img');
  23150. image.style.height = this.container.style.height;
  23151. image.style.width = this.container.style.width;
  23152. image.src = this.imageResourcesPath + 'annotation-' +
  23153. this.data.name.toLowerCase() + '.svg';
  23154. image.alt = '[{{type}} Annotation]';
  23155. image.dataset.l10nId = 'text_annotation_type';
  23156. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  23157. if (!this.data.hasPopup) {
  23158. this._createPopup(this.container, image, this.data);
  23159. }
  23160. this.container.appendChild(image);
  23161. return this.container;
  23162. }
  23163. });
  23164. return TextAnnotationElement;
  23165. })();
  23166. /**
  23167. * @class
  23168. * @alias WidgetAnnotationElement
  23169. */
  23170. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  23171. function WidgetAnnotationElement(parameters) {
  23172. AnnotationElement.call(this, parameters, true);
  23173. }
  23174. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  23175. /**
  23176. * Render the widget annotation's HTML element in the empty container.
  23177. *
  23178. * @public
  23179. * @memberof WidgetAnnotationElement
  23180. * @returns {HTMLSectionElement}
  23181. */
  23182. render: function WidgetAnnotationElement_render() {
  23183. // Show only the container for unsupported field types.
  23184. return this.container;
  23185. }
  23186. });
  23187. return WidgetAnnotationElement;
  23188. })();
  23189. /**
  23190. * @class
  23191. * @alias TextWidgetAnnotationElement
  23192. */
  23193. var TextWidgetAnnotationElement = (
  23194. function TextWidgetAnnotationElementClosure() {
  23195. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  23196. function TextWidgetAnnotationElement(parameters) {
  23197. WidgetAnnotationElement.call(this, parameters);
  23198. }
  23199. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  23200. /**
  23201. * Render the text widget annotation's HTML element in the empty container.
  23202. *
  23203. * @public
  23204. * @memberof TextWidgetAnnotationElement
  23205. * @returns {HTMLSectionElement}
  23206. */
  23207. render: function TextWidgetAnnotationElement_render() {
  23208. this.container.className = 'textWidgetAnnotation';
  23209. var element = null;
  23210. if (this.renderInteractiveForms) {
  23211. element = document.createElement('input');
  23212. element.type = 'text';
  23213. element.value = this.data.fieldValue;
  23214. if (isInt(this.data.maxLen)) {
  23215. element.maxLength = this.data.maxLen;
  23216. }
  23217. } else {
  23218. element = document.createElement('div');
  23219. element.textContent = this.data.fieldValue;
  23220. element.style.verticalAlign = 'middle';
  23221. element.style.display = 'table-cell';
  23222. var font = null;
  23223. if (this.data.fontRefName) {
  23224. font = this.page.commonObjs.getData(this.data.fontRefName);
  23225. }
  23226. this._setTextStyle(element, font);
  23227. }
  23228. if (isInt(this.data.textAlignment)) {
  23229. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  23230. }
  23231. this.container.appendChild(element);
  23232. return this.container;
  23233. },
  23234. /**
  23235. * Apply text styles to the text in the element.
  23236. *
  23237. * @private
  23238. * @param {HTMLDivElement} element
  23239. * @param {Object} font
  23240. * @memberof TextWidgetAnnotationElement
  23241. */
  23242. _setTextStyle:
  23243. function TextWidgetAnnotationElement_setTextStyle(element, font) {
  23244. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  23245. var style = element.style;
  23246. style.fontSize = this.data.fontSize + 'px';
  23247. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  23248. if (!font) {
  23249. return;
  23250. }
  23251. style.fontWeight = (font.black ?
  23252. (font.bold ? '900' : 'bold') :
  23253. (font.bold ? 'bold' : 'normal'));
  23254. style.fontStyle = (font.italic ? 'italic' : 'normal');
  23255. // Use a reasonable default font if the font doesn't specify a fallback.
  23256. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  23257. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  23258. style.fontFamily = fontFamily + fallbackName;
  23259. }
  23260. });
  23261. return TextWidgetAnnotationElement;
  23262. })();
  23263. /**
  23264. * @class
  23265. * @alias PopupAnnotationElement
  23266. */
  23267. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  23268. function PopupAnnotationElement(parameters) {
  23269. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  23270. AnnotationElement.call(this, parameters, isRenderable);
  23271. }
  23272. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  23273. /**
  23274. * Render the popup annotation's HTML element in the empty container.
  23275. *
  23276. * @public
  23277. * @memberof PopupAnnotationElement
  23278. * @returns {HTMLSectionElement}
  23279. */
  23280. render: function PopupAnnotationElement_render() {
  23281. this.container.className = 'popupAnnotation';
  23282. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  23283. var parentElement = this.layer.querySelector(selector);
  23284. if (!parentElement) {
  23285. return this.container;
  23286. }
  23287. var popup = new PopupElement({
  23288. container: this.container,
  23289. trigger: parentElement,
  23290. color: this.data.color,
  23291. title: this.data.title,
  23292. contents: this.data.contents
  23293. });
  23294. // Position the popup next to the parent annotation's container.
  23295. // PDF viewers ignore a popup annotation's rectangle.
  23296. var parentLeft = parseFloat(parentElement.style.left);
  23297. var parentWidth = parseFloat(parentElement.style.width);
  23298. CustomStyle.setProp('transformOrigin', this.container,
  23299. -(parentLeft + parentWidth) + 'px -' +
  23300. parentElement.style.top);
  23301. this.container.style.left = (parentLeft + parentWidth) + 'px';
  23302. this.container.appendChild(popup.render());
  23303. return this.container;
  23304. }
  23305. });
  23306. return PopupAnnotationElement;
  23307. })();
  23308. /**
  23309. * @class
  23310. * @alias PopupElement
  23311. */
  23312. var PopupElement = (function PopupElementClosure() {
  23313. var BACKGROUND_ENLIGHT = 0.7;
  23314. function PopupElement(parameters) {
  23315. this.container = parameters.container;
  23316. this.trigger = parameters.trigger;
  23317. this.color = parameters.color;
  23318. this.title = parameters.title;
  23319. this.contents = parameters.contents;
  23320. this.hideWrapper = parameters.hideWrapper || false;
  23321. this.pinned = false;
  23322. }
  23323. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  23324. /**
  23325. * Render the popup's HTML element.
  23326. *
  23327. * @public
  23328. * @memberof PopupElement
  23329. * @returns {HTMLSectionElement}
  23330. */
  23331. render: function PopupElement_render() {
  23332. var wrapper = document.createElement('div');
  23333. wrapper.className = 'popupWrapper';
  23334. // For Popup annotations we hide the entire section because it contains
  23335. // only the popup. However, for Text annotations without a separate Popup
  23336. // annotation, we cannot hide the entire container as the image would
  23337. // disappear too. In that special case, hiding the wrapper suffices.
  23338. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  23339. this.hideElement.setAttribute('hidden', true);
  23340. var popup = document.createElement('div');
  23341. popup.className = 'popup';
  23342. var color = this.color;
  23343. if (color) {
  23344. // Enlighten the color.
  23345. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  23346. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  23347. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  23348. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  23349. }
  23350. var contents = this._formatContents(this.contents);
  23351. var title = document.createElement('h1');
  23352. title.textContent = this.title;
  23353. // Attach the event listeners to the trigger element.
  23354. this.trigger.addEventListener('click', this._toggle.bind(this));
  23355. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  23356. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  23357. popup.addEventListener('click', this._hide.bind(this, true));
  23358. popup.appendChild(title);
  23359. popup.appendChild(contents);
  23360. wrapper.appendChild(popup);
  23361. return wrapper;
  23362. },
  23363. /**
  23364. * Format the contents of the popup by adding newlines where necessary.
  23365. *
  23366. * @private
  23367. * @param {string} contents
  23368. * @memberof PopupElement
  23369. * @returns {HTMLParagraphElement}
  23370. */
  23371. _formatContents: function PopupElement_formatContents(contents) {
  23372. var p = document.createElement('p');
  23373. var lines = contents.split(/(?:\r\n?|\n)/);
  23374. for (var i = 0, ii = lines.length; i < ii; ++i) {
  23375. var line = lines[i];
  23376. p.appendChild(document.createTextNode(line));
  23377. if (i < (ii - 1)) {
  23378. p.appendChild(document.createElement('br'));
  23379. }
  23380. }
  23381. return p;
  23382. },
  23383. /**
  23384. * Toggle the visibility of the popup.
  23385. *
  23386. * @private
  23387. * @memberof PopupElement
  23388. */
  23389. _toggle: function PopupElement_toggle() {
  23390. if (this.pinned) {
  23391. this._hide(true);
  23392. } else {
  23393. this._show(true);
  23394. }
  23395. },
  23396. /**
  23397. * Show the popup.
  23398. *
  23399. * @private
  23400. * @param {boolean} pin
  23401. * @memberof PopupElement
  23402. */
  23403. _show: function PopupElement_show(pin) {
  23404. if (pin) {
  23405. this.pinned = true;
  23406. }
  23407. if (this.hideElement.hasAttribute('hidden')) {
  23408. this.hideElement.removeAttribute('hidden');
  23409. this.container.style.zIndex += 1;
  23410. }
  23411. },
  23412. /**
  23413. * Hide the popup.
  23414. *
  23415. * @private
  23416. * @param {boolean} unpin
  23417. * @memberof PopupElement
  23418. */
  23419. _hide: function PopupElement_hide(unpin) {
  23420. if (unpin) {
  23421. this.pinned = false;
  23422. }
  23423. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  23424. this.hideElement.setAttribute('hidden', true);
  23425. this.container.style.zIndex -= 1;
  23426. }
  23427. }
  23428. };
  23429. return PopupElement;
  23430. })();
  23431. /**
  23432. * @class
  23433. * @alias HighlightAnnotationElement
  23434. */
  23435. var HighlightAnnotationElement = (
  23436. function HighlightAnnotationElementClosure() {
  23437. function HighlightAnnotationElement(parameters) {
  23438. var isRenderable = !!(parameters.data.hasPopup ||
  23439. parameters.data.title || parameters.data.contents);
  23440. AnnotationElement.call(this, parameters, isRenderable);
  23441. }
  23442. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  23443. /**
  23444. * Render the highlight annotation's HTML element in the empty container.
  23445. *
  23446. * @public
  23447. * @memberof HighlightAnnotationElement
  23448. * @returns {HTMLSectionElement}
  23449. */
  23450. render: function HighlightAnnotationElement_render() {
  23451. this.container.className = 'highlightAnnotation';
  23452. if (!this.data.hasPopup) {
  23453. this._createPopup(this.container, null, this.data);
  23454. }
  23455. return this.container;
  23456. }
  23457. });
  23458. return HighlightAnnotationElement;
  23459. })();
  23460. /**
  23461. * @class
  23462. * @alias UnderlineAnnotationElement
  23463. */
  23464. var UnderlineAnnotationElement = (
  23465. function UnderlineAnnotationElementClosure() {
  23466. function UnderlineAnnotationElement(parameters) {
  23467. var isRenderable = !!(parameters.data.hasPopup ||
  23468. parameters.data.title || parameters.data.contents);
  23469. AnnotationElement.call(this, parameters, isRenderable);
  23470. }
  23471. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  23472. /**
  23473. * Render the underline annotation's HTML element in the empty container.
  23474. *
  23475. * @public
  23476. * @memberof UnderlineAnnotationElement
  23477. * @returns {HTMLSectionElement}
  23478. */
  23479. render: function UnderlineAnnotationElement_render() {
  23480. this.container.className = 'underlineAnnotation';
  23481. if (!this.data.hasPopup) {
  23482. this._createPopup(this.container, null, this.data);
  23483. }
  23484. return this.container;
  23485. }
  23486. });
  23487. return UnderlineAnnotationElement;
  23488. })();
  23489. /**
  23490. * @class
  23491. * @alias SquigglyAnnotationElement
  23492. */
  23493. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  23494. function SquigglyAnnotationElement(parameters) {
  23495. var isRenderable = !!(parameters.data.hasPopup ||
  23496. parameters.data.title || parameters.data.contents);
  23497. AnnotationElement.call(this, parameters, isRenderable);
  23498. }
  23499. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  23500. /**
  23501. * Render the squiggly annotation's HTML element in the empty container.
  23502. *
  23503. * @public
  23504. * @memberof SquigglyAnnotationElement
  23505. * @returns {HTMLSectionElement}
  23506. */
  23507. render: function SquigglyAnnotationElement_render() {
  23508. this.container.className = 'squigglyAnnotation';
  23509. if (!this.data.hasPopup) {
  23510. this._createPopup(this.container, null, this.data);
  23511. }
  23512. return this.container;
  23513. }
  23514. });
  23515. return SquigglyAnnotationElement;
  23516. })();
  23517. /**
  23518. * @class
  23519. * @alias StrikeOutAnnotationElement
  23520. */
  23521. var StrikeOutAnnotationElement = (
  23522. function StrikeOutAnnotationElementClosure() {
  23523. function StrikeOutAnnotationElement(parameters) {
  23524. var isRenderable = !!(parameters.data.hasPopup ||
  23525. parameters.data.title || parameters.data.contents);
  23526. AnnotationElement.call(this, parameters, isRenderable);
  23527. }
  23528. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  23529. /**
  23530. * Render the strikeout annotation's HTML element in the empty container.
  23531. *
  23532. * @public
  23533. * @memberof StrikeOutAnnotationElement
  23534. * @returns {HTMLSectionElement}
  23535. */
  23536. render: function StrikeOutAnnotationElement_render() {
  23537. this.container.className = 'strikeoutAnnotation';
  23538. if (!this.data.hasPopup) {
  23539. this._createPopup(this.container, null, this.data);
  23540. }
  23541. return this.container;
  23542. }
  23543. });
  23544. return StrikeOutAnnotationElement;
  23545. })();
  23546. /**
  23547. * @class
  23548. * @alias FileAttachmentAnnotationElement
  23549. */
  23550. var FileAttachmentAnnotationElement = (
  23551. function FileAttachmentAnnotationElementClosure() {
  23552. function FileAttachmentAnnotationElement(parameters) {
  23553. AnnotationElement.call(this, parameters, true);
  23554. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  23555. this.content = parameters.data.file.content;
  23556. }
  23557. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  23558. /**
  23559. * Render the file attachment annotation's HTML element in the empty
  23560. * container.
  23561. *
  23562. * @public
  23563. * @memberof FileAttachmentAnnotationElement
  23564. * @returns {HTMLSectionElement}
  23565. */
  23566. render: function FileAttachmentAnnotationElement_render() {
  23567. this.container.className = 'fileAttachmentAnnotation';
  23568. var trigger = document.createElement('div');
  23569. trigger.style.height = this.container.style.height;
  23570. trigger.style.width = this.container.style.width;
  23571. trigger.addEventListener('dblclick', this._download.bind(this));
  23572. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  23573. this._createPopup(this.container, trigger, this.data);
  23574. }
  23575. this.container.appendChild(trigger);
  23576. return this.container;
  23577. },
  23578. /**
  23579. * Download the file attachment associated with this annotation.
  23580. *
  23581. * @private
  23582. * @memberof FileAttachmentAnnotationElement
  23583. */
  23584. _download: function FileAttachmentAnnotationElement_download() {
  23585. if (!this.downloadManager) {
  23586. warn('Download cannot be started due to unavailable download manager');
  23587. return;
  23588. }
  23589. this.downloadManager.downloadData(this.content, this.filename, '');
  23590. }
  23591. });
  23592. return FileAttachmentAnnotationElement;
  23593. })();
  23594. /**
  23595. * @typedef {Object} AnnotationLayerParameters
  23596. * @property {PageViewport} viewport
  23597. * @property {HTMLDivElement} div
  23598. * @property {Array} annotations
  23599. * @property {PDFPage} page
  23600. * @property {IPDFLinkService} linkService
  23601. * @property {string} imageResourcesPath
  23602. * @property {boolean} renderInteractiveForms
  23603. */
  23604. /**
  23605. * @class
  23606. * @alias AnnotationLayer
  23607. */
  23608. var AnnotationLayer = (function AnnotationLayerClosure() {
  23609. return {
  23610. /**
  23611. * Render a new annotation layer with all annotation elements.
  23612. *
  23613. * @public
  23614. * @param {AnnotationLayerParameters} parameters
  23615. * @memberof AnnotationLayer
  23616. */
  23617. render: function AnnotationLayer_render(parameters) {
  23618. var annotationElementFactory = new AnnotationElementFactory();
  23619. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23620. var data = parameters.annotations[i];
  23621. if (!data) {
  23622. continue;
  23623. }
  23624. var properties = {
  23625. data: data,
  23626. layer: parameters.div,
  23627. page: parameters.page,
  23628. viewport: parameters.viewport,
  23629. linkService: parameters.linkService,
  23630. downloadManager: parameters.downloadManager,
  23631. imageResourcesPath: parameters.imageResourcesPath ||
  23632. getDefaultSetting('imageResourcesPath'),
  23633. renderInteractiveForms: parameters.renderInteractiveForms || false,
  23634. };
  23635. var element = annotationElementFactory.create(properties);
  23636. if (element.isRenderable) {
  23637. parameters.div.appendChild(element.render());
  23638. }
  23639. }
  23640. },
  23641. /**
  23642. * Update the annotation elements on existing annotation layer.
  23643. *
  23644. * @public
  23645. * @param {AnnotationLayerParameters} parameters
  23646. * @memberof AnnotationLayer
  23647. */
  23648. update: function AnnotationLayer_update(parameters) {
  23649. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23650. var data = parameters.annotations[i];
  23651. var element = parameters.div.querySelector(
  23652. '[data-annotation-id="' + data.id + '"]');
  23653. if (element) {
  23654. CustomStyle.setProp('transform', element,
  23655. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  23656. }
  23657. }
  23658. parameters.div.removeAttribute('hidden');
  23659. }
  23660. };
  23661. })();
  23662. exports.AnnotationLayer = AnnotationLayer;
  23663. }));
  23664. (function (root, factory) {
  23665. {
  23666. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  23667. root.pdfjsDisplayDOMUtils);
  23668. }
  23669. }(this, function (exports, sharedUtil, displayDOMUtils) {
  23670. var Util = sharedUtil.Util;
  23671. var createPromiseCapability = sharedUtil.createPromiseCapability;
  23672. var CustomStyle = displayDOMUtils.CustomStyle;
  23673. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  23674. /**
  23675. * Text layer render parameters.
  23676. *
  23677. * @typedef {Object} TextLayerRenderParameters
  23678. * @property {TextContent} textContent - Text content to render (the object is
  23679. * returned by the page's getTextContent() method).
  23680. * @property {HTMLElement} container - HTML element that will contain text runs.
  23681. * @property {PageViewport} viewport - The target viewport to properly
  23682. * layout the text runs.
  23683. * @property {Array} textDivs - (optional) HTML elements that are correspond
  23684. * the text items of the textContent input. This is output and shall be
  23685. * initially be set to empty array.
  23686. * @property {number} timeout - (optional) Delay in milliseconds before
  23687. * rendering of the text runs occurs.
  23688. * @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
  23689. * text selection enhancement.
  23690. */
  23691. var renderTextLayer = (function renderTextLayerClosure() {
  23692. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  23693. var NonWhitespaceRegexp = /\S/;
  23694. function isAllWhitespace(str) {
  23695. return !NonWhitespaceRegexp.test(str);
  23696. }
  23697. function appendText(task, geom, styles) {
  23698. // Initialize all used properties to keep the caches monomorphic.
  23699. var textDiv = document.createElement('div');
  23700. var textDivProperties = {
  23701. angle: 0,
  23702. canvasWidth: 0,
  23703. isWhitespace: false,
  23704. originalTransform: '',
  23705. paddingBottom: 0,
  23706. paddingLeft: 0,
  23707. paddingRight: 0,
  23708. paddingTop: 0,
  23709. scale: 1,
  23710. };
  23711. task._textDivs.push(textDiv);
  23712. if (isAllWhitespace(geom.str)) {
  23713. textDivProperties.isWhitespace = true;
  23714. task._textDivProperties.set(textDiv, textDivProperties);
  23715. return;
  23716. }
  23717. var tx = Util.transform(task._viewport.transform, geom.transform);
  23718. var angle = Math.atan2(tx[1], tx[0]);
  23719. var style = styles[geom.fontName];
  23720. if (style.vertical) {
  23721. angle += Math.PI / 2;
  23722. }
  23723. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  23724. var fontAscent = fontHeight;
  23725. if (style.ascent) {
  23726. fontAscent = style.ascent * fontAscent;
  23727. } else if (style.descent) {
  23728. fontAscent = (1 + style.descent) * fontAscent;
  23729. }
  23730. var left;
  23731. var top;
  23732. if (angle === 0) {
  23733. left = tx[4];
  23734. top = tx[5] - fontAscent;
  23735. } else {
  23736. left = tx[4] + (fontAscent * Math.sin(angle));
  23737. top = tx[5] - (fontAscent * Math.cos(angle));
  23738. }
  23739. textDiv.style.left = left + 'px';
  23740. textDiv.style.top = top + 'px';
  23741. textDiv.style.fontSize = fontHeight + 'px';
  23742. textDiv.style.fontFamily = style.fontFamily;
  23743. textDiv.textContent = geom.str;
  23744. // |fontName| is only used by the Font Inspector. This test will succeed
  23745. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  23746. // not worth the effort to do a more accurate test. We only use `dataset`
  23747. // here to make the font name available for the debugger.
  23748. if (getDefaultSetting('pdfBug')) {
  23749. textDiv.dataset.fontName = geom.fontName;
  23750. }
  23751. if (angle !== 0) {
  23752. textDivProperties.angle = angle * (180 / Math.PI);
  23753. }
  23754. // We don't bother scaling single-char text divs, because it has very
  23755. // little effect on text highlighting. This makes scrolling on docs with
  23756. // lots of such divs a lot faster.
  23757. if (geom.str.length > 1) {
  23758. if (style.vertical) {
  23759. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  23760. } else {
  23761. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  23762. }
  23763. }
  23764. task._textDivProperties.set(textDiv, textDivProperties);
  23765. if (task._enhanceTextSelection) {
  23766. var angleCos = 1, angleSin = 0;
  23767. if (angle !== 0) {
  23768. angleCos = Math.cos(angle);
  23769. angleSin = Math.sin(angle);
  23770. }
  23771. var divWidth = (style.vertical ? geom.height : geom.width) *
  23772. task._viewport.scale;
  23773. var divHeight = fontHeight;
  23774. var m, b;
  23775. if (angle !== 0) {
  23776. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  23777. b = Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  23778. } else {
  23779. b = [left, top, left + divWidth, top + divHeight];
  23780. }
  23781. task._bounds.push({
  23782. left: b[0],
  23783. top: b[1],
  23784. right: b[2],
  23785. bottom: b[3],
  23786. div: textDiv,
  23787. size: [divWidth, divHeight],
  23788. m: m
  23789. });
  23790. }
  23791. }
  23792. function render(task) {
  23793. if (task._canceled) {
  23794. return;
  23795. }
  23796. var textLayerFrag = task._container;
  23797. var textDivs = task._textDivs;
  23798. var capability = task._capability;
  23799. var textDivsLength = textDivs.length;
  23800. // No point in rendering many divs as it would make the browser
  23801. // unusable even after the divs are rendered.
  23802. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  23803. task._renderingDone = true;
  23804. capability.resolve();
  23805. return;
  23806. }
  23807. var canvas = document.createElement('canvas');
  23808. var ctx = canvas.getContext('2d', {alpha: false});
  23809. var lastFontSize;
  23810. var lastFontFamily;
  23811. for (var i = 0; i < textDivsLength; i++) {
  23812. var textDiv = textDivs[i];
  23813. var textDivProperties = task._textDivProperties.get(textDiv);
  23814. if (textDivProperties.isWhitespace) {
  23815. continue;
  23816. }
  23817. var fontSize = textDiv.style.fontSize;
  23818. var fontFamily = textDiv.style.fontFamily;
  23819. // Only build font string and set to context if different from last.
  23820. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  23821. ctx.font = fontSize + ' ' + fontFamily;
  23822. lastFontSize = fontSize;
  23823. lastFontFamily = fontFamily;
  23824. }
  23825. var width = ctx.measureText(textDiv.textContent).width;
  23826. textLayerFrag.appendChild(textDiv);
  23827. var transform = '';
  23828. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  23829. textDivProperties.scale = textDivProperties.canvasWidth / width;
  23830. transform = 'scaleX(' + textDivProperties.scale + ')';
  23831. }
  23832. if (textDivProperties.angle !== 0) {
  23833. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  23834. }
  23835. if (transform !== '') {
  23836. textDivProperties.originalTransform = transform;
  23837. CustomStyle.setProp('transform', textDiv, transform);
  23838. }
  23839. task._textDivProperties.set(textDiv, textDivProperties);
  23840. }
  23841. task._renderingDone = true;
  23842. capability.resolve();
  23843. }
  23844. function expand(task) {
  23845. var bounds = task._bounds;
  23846. var viewport = task._viewport;
  23847. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  23848. for (var i = 0; i < expanded.length; i++) {
  23849. var div = bounds[i].div;
  23850. var divProperties = task._textDivProperties.get(div);
  23851. if (divProperties.angle === 0) {
  23852. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  23853. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  23854. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  23855. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  23856. task._textDivProperties.set(div, divProperties);
  23857. continue;
  23858. }
  23859. // Box is rotated -- trying to find padding so rotated div will not
  23860. // exceed its expanded bounds.
  23861. var e = expanded[i], b = bounds[i];
  23862. var m = b.m, c = m[0], s = m[1];
  23863. // Finding intersections with expanded box.
  23864. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  23865. var ts = new Float64Array(64);
  23866. points.forEach(function (p, i) {
  23867. var t = Util.applyTransform(p, m);
  23868. ts[i + 0] = c && (e.left - t[0]) / c;
  23869. ts[i + 4] = s && (e.top - t[1]) / s;
  23870. ts[i + 8] = c && (e.right - t[0]) / c;
  23871. ts[i + 12] = s && (e.bottom - t[1]) / s;
  23872. ts[i + 16] = s && (e.left - t[0]) / -s;
  23873. ts[i + 20] = c && (e.top - t[1]) / c;
  23874. ts[i + 24] = s && (e.right - t[0]) / -s;
  23875. ts[i + 28] = c && (e.bottom - t[1]) / c;
  23876. ts[i + 32] = c && (e.left - t[0]) / -c;
  23877. ts[i + 36] = s && (e.top - t[1]) / -s;
  23878. ts[i + 40] = c && (e.right - t[0]) / -c;
  23879. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  23880. ts[i + 48] = s && (e.left - t[0]) / s;
  23881. ts[i + 52] = c && (e.top - t[1]) / -c;
  23882. ts[i + 56] = s && (e.right - t[0]) / s;
  23883. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  23884. });
  23885. var findPositiveMin = function (ts, offset, count) {
  23886. var result = 0;
  23887. for (var i = 0; i < count; i++) {
  23888. var t = ts[offset++];
  23889. if (t > 0) {
  23890. result = result ? Math.min(t, result) : t;
  23891. }
  23892. }
  23893. return result;
  23894. };
  23895. // Not based on math, but to simplify calculations, using cos and sin
  23896. // absolute values to not exceed the box (it can but insignificantly).
  23897. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  23898. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  23899. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  23900. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  23901. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  23902. task._textDivProperties.set(div, divProperties);
  23903. }
  23904. }
  23905. function expandBounds(width, height, boxes) {
  23906. var bounds = boxes.map(function (box, i) {
  23907. return {
  23908. x1: box.left,
  23909. y1: box.top,
  23910. x2: box.right,
  23911. y2: box.bottom,
  23912. index: i,
  23913. x1New: undefined,
  23914. x2New: undefined
  23915. };
  23916. });
  23917. expandBoundsLTR(width, bounds);
  23918. var expanded = new Array(boxes.length);
  23919. bounds.forEach(function (b) {
  23920. var i = b.index;
  23921. expanded[i] = {
  23922. left: b.x1New,
  23923. top: 0,
  23924. right: b.x2New,
  23925. bottom: 0
  23926. };
  23927. });
  23928. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  23929. // array and objects.
  23930. boxes.map(function (box, i) {
  23931. var e = expanded[i], b = bounds[i];
  23932. b.x1 = box.top;
  23933. b.y1 = width - e.right;
  23934. b.x2 = box.bottom;
  23935. b.y2 = width - e.left;
  23936. b.index = i;
  23937. b.x1New = undefined;
  23938. b.x2New = undefined;
  23939. });
  23940. expandBoundsLTR(height, bounds);
  23941. bounds.forEach(function (b) {
  23942. var i = b.index;
  23943. expanded[i].top = b.x1New;
  23944. expanded[i].bottom = b.x2New;
  23945. });
  23946. return expanded;
  23947. }
  23948. function expandBoundsLTR(width, bounds) {
  23949. // Sorting by x1 coordinate and walk by the bounds in the same order.
  23950. bounds.sort(function (a, b) { return a.x1 - b.x1 || a.index - b.index; });
  23951. // First we see on the horizon is a fake boundary.
  23952. var fakeBoundary = {
  23953. x1: -Infinity,
  23954. y1: -Infinity,
  23955. x2: 0,
  23956. y2: Infinity,
  23957. index: -1,
  23958. x1New: 0,
  23959. x2New: 0
  23960. };
  23961. var horizon = [{
  23962. start: -Infinity,
  23963. end: Infinity,
  23964. boundary: fakeBoundary
  23965. }];
  23966. bounds.forEach(function (boundary) {
  23967. // Searching for the affected part of horizon.
  23968. // TODO red-black tree or simple binary search
  23969. var i = 0;
  23970. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  23971. i++;
  23972. }
  23973. var j = horizon.length - 1;
  23974. while(j >= 0 && horizon[j].start >= boundary.y2) {
  23975. j--;
  23976. }
  23977. var horizonPart, affectedBoundary;
  23978. var q, k, maxXNew = -Infinity;
  23979. for (q = i; q <= j; q++) {
  23980. horizonPart = horizon[q];
  23981. affectedBoundary = horizonPart.boundary;
  23982. var xNew;
  23983. if (affectedBoundary.x2 > boundary.x1) {
  23984. // In the middle of the previous element, new x shall be at the
  23985. // boundary start. Extending if further if the affected bondary
  23986. // placed on top of the current one.
  23987. xNew = affectedBoundary.index > boundary.index ?
  23988. affectedBoundary.x1New : boundary.x1;
  23989. } else if (affectedBoundary.x2New === undefined) {
  23990. // We have some space in between, new x in middle will be a fair
  23991. // choice.
  23992. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  23993. } else {
  23994. // Affected boundary has x2new set, using it as new x.
  23995. xNew = affectedBoundary.x2New;
  23996. }
  23997. if (xNew > maxXNew) {
  23998. maxXNew = xNew;
  23999. }
  24000. }
  24001. // Set new x1 for current boundary.
  24002. boundary.x1New = maxXNew;
  24003. // Adjusts new x2 for the affected boundaries.
  24004. for (q = i; q <= j; q++) {
  24005. horizonPart = horizon[q];
  24006. affectedBoundary = horizonPart.boundary;
  24007. if (affectedBoundary.x2New === undefined) {
  24008. // Was not set yet, choosing new x if possible.
  24009. if (affectedBoundary.x2 > boundary.x1) {
  24010. // Current and affected boundaries intersect. If affected boundary
  24011. // is placed on top of the current, shrinking the affected.
  24012. if (affectedBoundary.index > boundary.index) {
  24013. affectedBoundary.x2New = affectedBoundary.x2;
  24014. }
  24015. } else {
  24016. affectedBoundary.x2New = maxXNew;
  24017. }
  24018. } else if (affectedBoundary.x2New > maxXNew) {
  24019. // Affected boundary is touching new x, pushing it back.
  24020. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  24021. }
  24022. }
  24023. // Fixing the horizon.
  24024. var changedHorizon = [], lastBoundary = null;
  24025. for (q = i; q <= j; q++) {
  24026. horizonPart = horizon[q];
  24027. affectedBoundary = horizonPart.boundary;
  24028. // Checking which boundary will be visible.
  24029. var useBoundary = affectedBoundary.x2 > boundary.x2 ?
  24030. affectedBoundary : boundary;
  24031. if (lastBoundary === useBoundary) {
  24032. // Merging with previous.
  24033. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  24034. } else {
  24035. changedHorizon.push({
  24036. start: horizonPart.start,
  24037. end: horizonPart.end,
  24038. boundary: useBoundary
  24039. });
  24040. lastBoundary = useBoundary;
  24041. }
  24042. }
  24043. if (horizon[i].start < boundary.y1) {
  24044. changedHorizon[0].start = boundary.y1;
  24045. changedHorizon.unshift({
  24046. start: horizon[i].start,
  24047. end: boundary.y1,
  24048. boundary: horizon[i].boundary
  24049. });
  24050. }
  24051. if (boundary.y2 < horizon[j].end) {
  24052. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  24053. changedHorizon.push({
  24054. start: boundary.y2,
  24055. end: horizon[j].end,
  24056. boundary: horizon[j].boundary
  24057. });
  24058. }
  24059. // Set x2 new of boundary that is no longer visible (see overlapping case
  24060. // above).
  24061. // TODO more efficient, e.g. via reference counting.
  24062. for (q = i; q <= j; q++) {
  24063. horizonPart = horizon[q];
  24064. affectedBoundary = horizonPart.boundary;
  24065. if (affectedBoundary.x2New !== undefined) {
  24066. continue;
  24067. }
  24068. var used = false;
  24069. for (k = i - 1; !used && k >= 0 &&
  24070. horizon[k].start >= affectedBoundary.y1; k--) {
  24071. used = horizon[k].boundary === affectedBoundary;
  24072. }
  24073. for (k = j + 1; !used && k < horizon.length &&
  24074. horizon[k].end <= affectedBoundary.y2; k++) {
  24075. used = horizon[k].boundary === affectedBoundary;
  24076. }
  24077. for (k = 0; !used && k < changedHorizon.length; k++) {
  24078. used = changedHorizon[k].boundary === affectedBoundary;
  24079. }
  24080. if (!used) {
  24081. affectedBoundary.x2New = maxXNew;
  24082. }
  24083. }
  24084. Array.prototype.splice.apply(horizon,
  24085. [i, j - i + 1].concat(changedHorizon));
  24086. });
  24087. // Set new x2 for all unset boundaries.
  24088. horizon.forEach(function (horizonPart) {
  24089. var affectedBoundary = horizonPart.boundary;
  24090. if (affectedBoundary.x2New === undefined) {
  24091. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  24092. }
  24093. });
  24094. }
  24095. /**
  24096. * Text layer rendering task.
  24097. *
  24098. * @param {TextContent} textContent
  24099. * @param {HTMLElement} container
  24100. * @param {PageViewport} viewport
  24101. * @param {Array} textDivs
  24102. * @param {boolean} enhanceTextSelection
  24103. * @private
  24104. */
  24105. function TextLayerRenderTask(textContent, container, viewport, textDivs,
  24106. enhanceTextSelection) {
  24107. this._textContent = textContent;
  24108. this._container = container;
  24109. this._viewport = viewport;
  24110. this._textDivs = textDivs || [];
  24111. this._textDivProperties = new WeakMap();
  24112. this._renderingDone = false;
  24113. this._canceled = false;
  24114. this._capability = createPromiseCapability();
  24115. this._renderTimer = null;
  24116. this._bounds = [];
  24117. this._enhanceTextSelection = !!enhanceTextSelection;
  24118. this._expanded = false;
  24119. }
  24120. TextLayerRenderTask.prototype = {
  24121. get promise() {
  24122. return this._capability.promise;
  24123. },
  24124. cancel: function TextLayer_cancel() {
  24125. this._canceled = true;
  24126. if (this._renderTimer !== null) {
  24127. clearTimeout(this._renderTimer);
  24128. this._renderTimer = null;
  24129. }
  24130. this._capability.reject('canceled');
  24131. },
  24132. _render: function TextLayer_render(timeout) {
  24133. var textItems = this._textContent.items;
  24134. var textStyles = this._textContent.styles;
  24135. for (var i = 0, len = textItems.length; i < len; i++) {
  24136. appendText(this, textItems[i], textStyles);
  24137. }
  24138. if (!timeout) { // Render right away
  24139. render(this);
  24140. } else { // Schedule
  24141. var self = this;
  24142. this._renderTimer = setTimeout(function() {
  24143. render(self);
  24144. self._renderTimer = null;
  24145. }, timeout);
  24146. }
  24147. },
  24148. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  24149. if (!this._enhanceTextSelection || !this._renderingDone) {
  24150. return;
  24151. }
  24152. if (!this._expanded) {
  24153. expand(this);
  24154. this._expanded = true;
  24155. this._bounds.length = 0;
  24156. }
  24157. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  24158. var div = this._textDivs[i];
  24159. var divProperties = this._textDivProperties.get(div);
  24160. if (expandDivs) {
  24161. var transform = '';
  24162. if (divProperties.scale !== 1) {
  24163. transform = 'scaleX(' + divProperties.scale + ')';
  24164. }
  24165. if (divProperties.angle !== 0) {
  24166. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  24167. }
  24168. if (divProperties.paddingLeft !== 0) {
  24169. div.style.paddingLeft =
  24170. (divProperties.paddingLeft / divProperties.scale) + 'px';
  24171. transform += ' translateX(' +
  24172. (-divProperties.paddingLeft / divProperties.scale) + 'px)';
  24173. }
  24174. if (divProperties.paddingTop !== 0) {
  24175. div.style.paddingTop = divProperties.paddingTop + 'px';
  24176. transform += ' translateY(' + (-divProperties.paddingTop) + 'px)';
  24177. }
  24178. if (divProperties.paddingRight !== 0) {
  24179. div.style.paddingRight =
  24180. (divProperties.paddingRight / divProperties.scale) + 'px';
  24181. }
  24182. if (divProperties.paddingBottom !== 0) {
  24183. div.style.paddingBottom = divProperties.paddingBottom + 'px';
  24184. }
  24185. if (transform !== '') {
  24186. CustomStyle.setProp('transform', div, transform);
  24187. }
  24188. } else {
  24189. div.style.padding = 0;
  24190. CustomStyle.setProp('transform', div,
  24191. divProperties.originalTransform);
  24192. }
  24193. }
  24194. },
  24195. };
  24196. /**
  24197. * Starts rendering of the text layer.
  24198. *
  24199. * @param {TextLayerRenderParameters} renderParameters
  24200. * @returns {TextLayerRenderTask}
  24201. */
  24202. function renderTextLayer(renderParameters) {
  24203. var task = new TextLayerRenderTask(renderParameters.textContent,
  24204. renderParameters.container,
  24205. renderParameters.viewport,
  24206. renderParameters.textDivs,
  24207. renderParameters.enhanceTextSelection);
  24208. task._render(renderParameters.timeout);
  24209. return task;
  24210. }
  24211. return renderTextLayer;
  24212. })();
  24213. exports.renderTextLayer = renderTextLayer;
  24214. }));
  24215. (function (root, factory) {
  24216. {
  24217. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil,
  24218. root.pdfjsDisplayDOMUtils);
  24219. }
  24220. }(this, function (exports, sharedUtil, displayDOMUtils) {
  24221. var shadow = sharedUtil.shadow;
  24222. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  24223. var WebGLUtils = (function WebGLUtilsClosure() {
  24224. function loadShader(gl, code, shaderType) {
  24225. var shader = gl.createShader(shaderType);
  24226. gl.shaderSource(shader, code);
  24227. gl.compileShader(shader);
  24228. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  24229. if (!compiled) {
  24230. var errorMsg = gl.getShaderInfoLog(shader);
  24231. throw new Error('Error during shader compilation: ' + errorMsg);
  24232. }
  24233. return shader;
  24234. }
  24235. function createVertexShader(gl, code) {
  24236. return loadShader(gl, code, gl.VERTEX_SHADER);
  24237. }
  24238. function createFragmentShader(gl, code) {
  24239. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  24240. }
  24241. function createProgram(gl, shaders) {
  24242. var program = gl.createProgram();
  24243. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  24244. gl.attachShader(program, shaders[i]);
  24245. }
  24246. gl.linkProgram(program);
  24247. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  24248. if (!linked) {
  24249. var errorMsg = gl.getProgramInfoLog(program);
  24250. throw new Error('Error during program linking: ' + errorMsg);
  24251. }
  24252. return program;
  24253. }
  24254. function createTexture(gl, image, textureId) {
  24255. gl.activeTexture(textureId);
  24256. var texture = gl.createTexture();
  24257. gl.bindTexture(gl.TEXTURE_2D, texture);
  24258. // Set the parameters so we can render any size image.
  24259. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  24260. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  24261. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  24262. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  24263. // Upload the image into the texture.
  24264. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  24265. return texture;
  24266. }
  24267. var currentGL, currentCanvas;
  24268. function generateGL() {
  24269. if (currentGL) {
  24270. return;
  24271. }
  24272. currentCanvas = document.createElement('canvas');
  24273. currentGL = currentCanvas.getContext('webgl',
  24274. { premultipliedalpha: false });
  24275. }
  24276. var smaskVertexShaderCode = '\
  24277. attribute vec2 a_position; \
  24278. attribute vec2 a_texCoord; \
  24279. \
  24280. uniform vec2 u_resolution; \
  24281. \
  24282. varying vec2 v_texCoord; \
  24283. \
  24284. void main() { \
  24285. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  24286. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24287. \
  24288. v_texCoord = a_texCoord; \
  24289. } ';
  24290. var smaskFragmentShaderCode = '\
  24291. precision mediump float; \
  24292. \
  24293. uniform vec4 u_backdrop; \
  24294. uniform int u_subtype; \
  24295. uniform sampler2D u_image; \
  24296. uniform sampler2D u_mask; \
  24297. \
  24298. varying vec2 v_texCoord; \
  24299. \
  24300. void main() { \
  24301. vec4 imageColor = texture2D(u_image, v_texCoord); \
  24302. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  24303. if (u_backdrop.a > 0.0) { \
  24304. maskColor.rgb = maskColor.rgb * maskColor.a + \
  24305. u_backdrop.rgb * (1.0 - maskColor.a); \
  24306. } \
  24307. float lum; \
  24308. if (u_subtype == 0) { \
  24309. lum = maskColor.a; \
  24310. } else { \
  24311. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  24312. maskColor.b * 0.11; \
  24313. } \
  24314. imageColor.a *= lum; \
  24315. imageColor.rgb *= imageColor.a; \
  24316. gl_FragColor = imageColor; \
  24317. } ';
  24318. var smaskCache = null;
  24319. function initSmaskGL() {
  24320. var canvas, gl;
  24321. generateGL();
  24322. canvas = currentCanvas;
  24323. currentCanvas = null;
  24324. gl = currentGL;
  24325. currentGL = null;
  24326. // setup a GLSL program
  24327. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  24328. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  24329. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24330. gl.useProgram(program);
  24331. var cache = {};
  24332. cache.gl = gl;
  24333. cache.canvas = canvas;
  24334. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24335. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24336. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  24337. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  24338. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  24339. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  24340. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  24341. // provide texture coordinates for the rectangle.
  24342. var texCoordBuffer = gl.createBuffer();
  24343. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  24344. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24345. 0.0, 0.0,
  24346. 1.0, 0.0,
  24347. 0.0, 1.0,
  24348. 0.0, 1.0,
  24349. 1.0, 0.0,
  24350. 1.0, 1.0]), gl.STATIC_DRAW);
  24351. gl.enableVertexAttribArray(texCoordLocation);
  24352. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  24353. gl.uniform1i(texLayerLocation, 0);
  24354. gl.uniform1i(texMaskLocation, 1);
  24355. smaskCache = cache;
  24356. }
  24357. function composeSMask(layer, mask, properties) {
  24358. var width = layer.width, height = layer.height;
  24359. if (!smaskCache) {
  24360. initSmaskGL();
  24361. }
  24362. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  24363. canvas.width = width;
  24364. canvas.height = height;
  24365. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24366. gl.uniform2f(cache.resolutionLocation, width, height);
  24367. if (properties.backdrop) {
  24368. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  24369. properties.backdrop[1], properties.backdrop[2], 1);
  24370. } else {
  24371. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  24372. }
  24373. gl.uniform1i(cache.subtypeLocation,
  24374. properties.subtype === 'Luminosity' ? 1 : 0);
  24375. // Create a textures
  24376. var texture = createTexture(gl, layer, gl.TEXTURE0);
  24377. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  24378. // Create a buffer and put a single clipspace rectangle in
  24379. // it (2 triangles)
  24380. var buffer = gl.createBuffer();
  24381. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  24382. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24383. 0, 0,
  24384. width, 0,
  24385. 0, height,
  24386. 0, height,
  24387. width, 0,
  24388. width, height]), gl.STATIC_DRAW);
  24389. gl.enableVertexAttribArray(cache.positionLocation);
  24390. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24391. // draw
  24392. gl.clearColor(0, 0, 0, 0);
  24393. gl.enable(gl.BLEND);
  24394. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  24395. gl.clear(gl.COLOR_BUFFER_BIT);
  24396. gl.drawArrays(gl.TRIANGLES, 0, 6);
  24397. gl.flush();
  24398. gl.deleteTexture(texture);
  24399. gl.deleteTexture(maskTexture);
  24400. gl.deleteBuffer(buffer);
  24401. return canvas;
  24402. }
  24403. var figuresVertexShaderCode = '\
  24404. attribute vec2 a_position; \
  24405. attribute vec3 a_color; \
  24406. \
  24407. uniform vec2 u_resolution; \
  24408. uniform vec2 u_scale; \
  24409. uniform vec2 u_offset; \
  24410. \
  24411. varying vec4 v_color; \
  24412. \
  24413. void main() { \
  24414. vec2 position = (a_position + u_offset) * u_scale; \
  24415. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  24416. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24417. \
  24418. v_color = vec4(a_color / 255.0, 1.0); \
  24419. } ';
  24420. var figuresFragmentShaderCode = '\
  24421. precision mediump float; \
  24422. \
  24423. varying vec4 v_color; \
  24424. \
  24425. void main() { \
  24426. gl_FragColor = v_color; \
  24427. } ';
  24428. var figuresCache = null;
  24429. function initFiguresGL() {
  24430. var canvas, gl;
  24431. generateGL();
  24432. canvas = currentCanvas;
  24433. currentCanvas = null;
  24434. gl = currentGL;
  24435. currentGL = null;
  24436. // setup a GLSL program
  24437. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  24438. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  24439. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24440. gl.useProgram(program);
  24441. var cache = {};
  24442. cache.gl = gl;
  24443. cache.canvas = canvas;
  24444. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24445. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  24446. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  24447. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24448. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  24449. figuresCache = cache;
  24450. }
  24451. function drawFigures(width, height, backgroundColor, figures, context) {
  24452. if (!figuresCache) {
  24453. initFiguresGL();
  24454. }
  24455. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  24456. canvas.width = width;
  24457. canvas.height = height;
  24458. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24459. gl.uniform2f(cache.resolutionLocation, width, height);
  24460. // count triangle points
  24461. var count = 0;
  24462. var i, ii, rows;
  24463. for (i = 0, ii = figures.length; i < ii; i++) {
  24464. switch (figures[i].type) {
  24465. case 'lattice':
  24466. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  24467. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  24468. break;
  24469. case 'triangles':
  24470. count += figures[i].coords.length;
  24471. break;
  24472. }
  24473. }
  24474. // transfer data
  24475. var coords = new Float32Array(count * 2);
  24476. var colors = new Uint8Array(count * 3);
  24477. var coordsMap = context.coords, colorsMap = context.colors;
  24478. var pIndex = 0, cIndex = 0;
  24479. for (i = 0, ii = figures.length; i < ii; i++) {
  24480. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  24481. switch (figure.type) {
  24482. case 'lattice':
  24483. var cols = figure.verticesPerRow;
  24484. rows = (ps.length / cols) | 0;
  24485. for (var row = 1; row < rows; row++) {
  24486. var offset = row * cols + 1;
  24487. for (var col = 1; col < cols; col++, offset++) {
  24488. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  24489. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  24490. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  24491. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  24492. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  24493. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  24494. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  24495. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  24496. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  24497. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  24498. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  24499. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  24500. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  24501. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  24502. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  24503. coords[pIndex + 6] = coords[pIndex + 2];
  24504. coords[pIndex + 7] = coords[pIndex + 3];
  24505. coords[pIndex + 8] = coords[pIndex + 4];
  24506. coords[pIndex + 9] = coords[pIndex + 5];
  24507. coords[pIndex + 10] = coordsMap[ps[offset]];
  24508. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  24509. colors[cIndex + 9] = colors[cIndex + 3];
  24510. colors[cIndex + 10] = colors[cIndex + 4];
  24511. colors[cIndex + 11] = colors[cIndex + 5];
  24512. colors[cIndex + 12] = colors[cIndex + 6];
  24513. colors[cIndex + 13] = colors[cIndex + 7];
  24514. colors[cIndex + 14] = colors[cIndex + 8];
  24515. colors[cIndex + 15] = colorsMap[cs[offset]];
  24516. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  24517. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  24518. pIndex += 12;
  24519. cIndex += 18;
  24520. }
  24521. }
  24522. break;
  24523. case 'triangles':
  24524. for (var j = 0, jj = ps.length; j < jj; j++) {
  24525. coords[pIndex] = coordsMap[ps[j]];
  24526. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  24527. colors[cIndex] = colorsMap[cs[j]];
  24528. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  24529. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  24530. pIndex += 2;
  24531. cIndex += 3;
  24532. }
  24533. break;
  24534. }
  24535. }
  24536. // draw
  24537. if (backgroundColor) {
  24538. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  24539. backgroundColor[2] / 255, 1.0);
  24540. } else {
  24541. gl.clearColor(0, 0, 0, 0);
  24542. }
  24543. gl.clear(gl.COLOR_BUFFER_BIT);
  24544. var coordsBuffer = gl.createBuffer();
  24545. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  24546. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  24547. gl.enableVertexAttribArray(cache.positionLocation);
  24548. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24549. var colorsBuffer = gl.createBuffer();
  24550. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  24551. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  24552. gl.enableVertexAttribArray(cache.colorLocation);
  24553. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  24554. 0, 0);
  24555. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  24556. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  24557. gl.drawArrays(gl.TRIANGLES, 0, count);
  24558. gl.flush();
  24559. gl.deleteBuffer(coordsBuffer);
  24560. gl.deleteBuffer(colorsBuffer);
  24561. return canvas;
  24562. }
  24563. function cleanup() {
  24564. if (smaskCache && smaskCache.canvas) {
  24565. smaskCache.canvas.width = 0;
  24566. smaskCache.canvas.height = 0;
  24567. }
  24568. if (figuresCache && figuresCache.canvas) {
  24569. figuresCache.canvas.width = 0;
  24570. figuresCache.canvas.height = 0;
  24571. }
  24572. smaskCache = null;
  24573. figuresCache = null;
  24574. }
  24575. return {
  24576. get isEnabled() {
  24577. if (getDefaultSetting('disableWebGL')) {
  24578. return false;
  24579. }
  24580. var enabled = false;
  24581. try {
  24582. generateGL();
  24583. enabled = !!currentGL;
  24584. } catch (e) { }
  24585. return shadow(this, 'isEnabled', enabled);
  24586. },
  24587. composeSMask: composeSMask,
  24588. drawFigures: drawFigures,
  24589. clear: cleanup
  24590. };
  24591. })();
  24592. exports.WebGLUtils = WebGLUtils;
  24593. }));
  24594. (function (root, factory) {
  24595. {
  24596. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  24597. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  24598. }
  24599. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  24600. var PasswordException = sharedUtil.PasswordException;
  24601. var PasswordResponses = sharedUtil.PasswordResponses;
  24602. var bytesToString = sharedUtil.bytesToString;
  24603. var error = sharedUtil.error;
  24604. var isInt = sharedUtil.isInt;
  24605. var stringToBytes = sharedUtil.stringToBytes;
  24606. var utf8StringToString = sharedUtil.utf8StringToString;
  24607. var warn = sharedUtil.warn;
  24608. var Name = corePrimitives.Name;
  24609. var isName = corePrimitives.isName;
  24610. var isDict = corePrimitives.isDict;
  24611. var DecryptStream = coreStream.DecryptStream;
  24612. var ARCFourCipher = (function ARCFourCipherClosure() {
  24613. function ARCFourCipher(key) {
  24614. this.a = 0;
  24615. this.b = 0;
  24616. var s = new Uint8Array(256);
  24617. var i, j = 0, tmp, keyLength = key.length;
  24618. for (i = 0; i < 256; ++i) {
  24619. s[i] = i;
  24620. }
  24621. for (i = 0; i < 256; ++i) {
  24622. tmp = s[i];
  24623. j = (j + tmp + key[i % keyLength]) & 0xFF;
  24624. s[i] = s[j];
  24625. s[j] = tmp;
  24626. }
  24627. this.s = s;
  24628. }
  24629. ARCFourCipher.prototype = {
  24630. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  24631. var i, n = data.length, tmp, tmp2;
  24632. var a = this.a, b = this.b, s = this.s;
  24633. var output = new Uint8Array(n);
  24634. for (i = 0; i < n; ++i) {
  24635. a = (a + 1) & 0xFF;
  24636. tmp = s[a];
  24637. b = (b + tmp) & 0xFF;
  24638. tmp2 = s[b];
  24639. s[a] = tmp2;
  24640. s[b] = tmp;
  24641. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  24642. }
  24643. this.a = a;
  24644. this.b = b;
  24645. return output;
  24646. }
  24647. };
  24648. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  24649. return ARCFourCipher;
  24650. })();
  24651. var calculateMD5 = (function calculateMD5Closure() {
  24652. var r = new Uint8Array([
  24653. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  24654. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  24655. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  24656. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  24657. var k = new Int32Array([
  24658. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  24659. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  24660. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  24661. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  24662. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  24663. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  24664. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  24665. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  24666. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  24667. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  24668. -145523070, -1120210379, 718787259, -343485551]);
  24669. function hash(data, offset, length) {
  24670. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  24671. // pre-processing
  24672. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  24673. var padded = new Uint8Array(paddedLength);
  24674. var i, j, n;
  24675. for (i = 0; i < length; ++i) {
  24676. padded[i] = data[offset++];
  24677. }
  24678. padded[i++] = 0x80;
  24679. n = paddedLength - 8;
  24680. while (i < n) {
  24681. padded[i++] = 0;
  24682. }
  24683. padded[i++] = (length << 3) & 0xFF;
  24684. padded[i++] = (length >> 5) & 0xFF;
  24685. padded[i++] = (length >> 13) & 0xFF;
  24686. padded[i++] = (length >> 21) & 0xFF;
  24687. padded[i++] = (length >>> 29) & 0xFF;
  24688. padded[i++] = 0;
  24689. padded[i++] = 0;
  24690. padded[i++] = 0;
  24691. var w = new Int32Array(16);
  24692. for (i = 0; i < paddedLength;) {
  24693. for (j = 0; j < 16; ++j, i += 4) {
  24694. w[j] = (padded[i] | (padded[i + 1] << 8) |
  24695. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  24696. }
  24697. var a = h0, b = h1, c = h2, d = h3, f, g;
  24698. for (j = 0; j < 64; ++j) {
  24699. if (j < 16) {
  24700. f = (b & c) | ((~b) & d);
  24701. g = j;
  24702. } else if (j < 32) {
  24703. f = (d & b) | ((~d) & c);
  24704. g = (5 * j + 1) & 15;
  24705. } else if (j < 48) {
  24706. f = b ^ c ^ d;
  24707. g = (3 * j + 5) & 15;
  24708. } else {
  24709. f = c ^ (b | (~d));
  24710. g = (7 * j) & 15;
  24711. }
  24712. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  24713. d = c;
  24714. c = b;
  24715. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  24716. a = tmp;
  24717. }
  24718. h0 = (h0 + a) | 0;
  24719. h1 = (h1 + b) | 0;
  24720. h2 = (h2 + c) | 0;
  24721. h3 = (h3 + d) | 0;
  24722. }
  24723. return new Uint8Array([
  24724. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  24725. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  24726. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  24727. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  24728. ]);
  24729. }
  24730. return hash;
  24731. })();
  24732. var Word64 = (function Word64Closure() {
  24733. function Word64(highInteger, lowInteger) {
  24734. this.high = highInteger | 0;
  24735. this.low = lowInteger | 0;
  24736. }
  24737. Word64.prototype = {
  24738. and: function Word64_and(word) {
  24739. this.high &= word.high;
  24740. this.low &= word.low;
  24741. },
  24742. xor: function Word64_xor(word) {
  24743. this.high ^= word.high;
  24744. this.low ^= word.low;
  24745. },
  24746. or: function Word64_or(word) {
  24747. this.high |= word.high;
  24748. this.low |= word.low;
  24749. },
  24750. shiftRight: function Word64_shiftRight(places) {
  24751. if (places >= 32) {
  24752. this.low = (this.high >>> (places - 32)) | 0;
  24753. this.high = 0;
  24754. } else {
  24755. this.low = (this.low >>> places) | (this.high << (32 - places));
  24756. this.high = (this.high >>> places) | 0;
  24757. }
  24758. },
  24759. shiftLeft: function Word64_shiftLeft(places) {
  24760. if (places >= 32) {
  24761. this.high = this.low << (places - 32);
  24762. this.low = 0;
  24763. } else {
  24764. this.high = (this.high << places) | (this.low >>> (32 - places));
  24765. this.low = this.low << places;
  24766. }
  24767. },
  24768. rotateRight: function Word64_rotateRight(places) {
  24769. var low, high;
  24770. if (places & 32) {
  24771. high = this.low;
  24772. low = this.high;
  24773. } else {
  24774. low = this.low;
  24775. high = this.high;
  24776. }
  24777. places &= 31;
  24778. this.low = (low >>> places) | (high << (32 - places));
  24779. this.high = (high >>> places) | (low << (32 - places));
  24780. },
  24781. not: function Word64_not() {
  24782. this.high = ~this.high;
  24783. this.low = ~this.low;
  24784. },
  24785. add: function Word64_add(word) {
  24786. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  24787. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  24788. if (lowAdd > 0xFFFFFFFF) {
  24789. highAdd += 1;
  24790. }
  24791. this.low = lowAdd | 0;
  24792. this.high = highAdd | 0;
  24793. },
  24794. copyTo: function Word64_copyTo(bytes, offset) {
  24795. bytes[offset] = (this.high >>> 24) & 0xFF;
  24796. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  24797. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  24798. bytes[offset + 3] = this.high & 0xFF;
  24799. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  24800. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  24801. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  24802. bytes[offset + 7] = this.low & 0xFF;
  24803. },
  24804. assign: function Word64_assign(word) {
  24805. this.high = word.high;
  24806. this.low = word.low;
  24807. }
  24808. };
  24809. return Word64;
  24810. })();
  24811. var calculateSHA256 = (function calculateSHA256Closure() {
  24812. function rotr(x, n) {
  24813. return (x >>> n) | (x << 32 - n);
  24814. }
  24815. function ch(x, y, z) {
  24816. return (x & y) ^ (~x & z);
  24817. }
  24818. function maj(x, y, z) {
  24819. return (x & y) ^ (x & z) ^ (y & z);
  24820. }
  24821. function sigma(x) {
  24822. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  24823. }
  24824. function sigmaPrime(x) {
  24825. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  24826. }
  24827. function littleSigma(x) {
  24828. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  24829. }
  24830. function littleSigmaPrime(x) {
  24831. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  24832. }
  24833. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  24834. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  24835. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  24836. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  24837. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  24838. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  24839. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  24840. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  24841. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  24842. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  24843. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  24844. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  24845. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  24846. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24847. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  24848. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  24849. function hash(data, offset, length) {
  24850. // initial hash values
  24851. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  24852. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  24853. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  24854. // pre-processing
  24855. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  24856. var padded = new Uint8Array(paddedLength);
  24857. var i, j, n;
  24858. for (i = 0; i < length; ++i) {
  24859. padded[i] = data[offset++];
  24860. }
  24861. padded[i++] = 0x80;
  24862. n = paddedLength - 8;
  24863. while (i < n) {
  24864. padded[i++] = 0;
  24865. }
  24866. padded[i++] = 0;
  24867. padded[i++] = 0;
  24868. padded[i++] = 0;
  24869. padded[i++] = (length >>> 29) & 0xFF;
  24870. padded[i++] = (length >> 21) & 0xFF;
  24871. padded[i++] = (length >> 13) & 0xFF;
  24872. padded[i++] = (length >> 5) & 0xFF;
  24873. padded[i++] = (length << 3) & 0xFF;
  24874. var w = new Uint32Array(64);
  24875. // for each 512 bit block
  24876. for (i = 0; i < paddedLength;) {
  24877. for (j = 0; j < 16; ++j) {
  24878. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  24879. (padded[i + 2] << 8) | (padded[i + 3]));
  24880. i += 4;
  24881. }
  24882. for (j = 16; j < 64; ++j) {
  24883. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  24884. littleSigma(w[j - 15]) + w[j - 16] | 0;
  24885. }
  24886. var a = h0, b = h1, c = h2, d = h3, e = h4,
  24887. f = h5, g = h6, h = h7, t1, t2;
  24888. for (j = 0; j < 64; ++j) {
  24889. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  24890. t2 = sigma(a) + maj(a, b, c);
  24891. h = g;
  24892. g = f;
  24893. f = e;
  24894. e = (d + t1) | 0;
  24895. d = c;
  24896. c = b;
  24897. b = a;
  24898. a = (t1 + t2) | 0;
  24899. }
  24900. h0 = (h0 + a) | 0;
  24901. h1 = (h1 + b) | 0;
  24902. h2 = (h2 + c) | 0;
  24903. h3 = (h3 + d) | 0;
  24904. h4 = (h4 + e) | 0;
  24905. h5 = (h5 + f) | 0;
  24906. h6 = (h6 + g) | 0;
  24907. h7 = (h7 + h) | 0;
  24908. }
  24909. return new Uint8Array([
  24910. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  24911. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  24912. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  24913. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  24914. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  24915. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  24916. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  24917. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  24918. ]);
  24919. }
  24920. return hash;
  24921. })();
  24922. var calculateSHA512 = (function calculateSHA512Closure() {
  24923. function ch(result, x, y, z, tmp) {
  24924. result.assign(x);
  24925. result.and(y);
  24926. tmp.assign(x);
  24927. tmp.not();
  24928. tmp.and(z);
  24929. result.xor(tmp);
  24930. }
  24931. function maj(result, x, y, z, tmp) {
  24932. result.assign(x);
  24933. result.and(y);
  24934. tmp.assign(x);
  24935. tmp.and(z);
  24936. result.xor(tmp);
  24937. tmp.assign(y);
  24938. tmp.and(z);
  24939. result.xor(tmp);
  24940. }
  24941. function sigma(result, x, tmp) {
  24942. result.assign(x);
  24943. result.rotateRight(28);
  24944. tmp.assign(x);
  24945. tmp.rotateRight(34);
  24946. result.xor(tmp);
  24947. tmp.assign(x);
  24948. tmp.rotateRight(39);
  24949. result.xor(tmp);
  24950. }
  24951. function sigmaPrime(result, x, tmp) {
  24952. result.assign(x);
  24953. result.rotateRight(14);
  24954. tmp.assign(x);
  24955. tmp.rotateRight(18);
  24956. result.xor(tmp);
  24957. tmp.assign(x);
  24958. tmp.rotateRight(41);
  24959. result.xor(tmp);
  24960. }
  24961. function littleSigma(result, x, tmp) {
  24962. result.assign(x);
  24963. result.rotateRight(1);
  24964. tmp.assign(x);
  24965. tmp.rotateRight(8);
  24966. result.xor(tmp);
  24967. tmp.assign(x);
  24968. tmp.shiftRight(7);
  24969. result.xor(tmp);
  24970. }
  24971. function littleSigmaPrime(result, x, tmp) {
  24972. result.assign(x);
  24973. result.rotateRight(19);
  24974. tmp.assign(x);
  24975. tmp.rotateRight(61);
  24976. result.xor(tmp);
  24977. tmp.assign(x);
  24978. tmp.shiftRight(6);
  24979. result.xor(tmp);
  24980. }
  24981. var k = [
  24982. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  24983. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  24984. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  24985. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  24986. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  24987. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  24988. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  24989. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  24990. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  24991. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  24992. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  24993. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  24994. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  24995. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  24996. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  24997. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  24998. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  24999. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  25000. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  25001. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  25002. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  25003. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  25004. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  25005. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  25006. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  25007. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  25008. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  25009. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  25010. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  25011. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  25012. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  25013. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  25014. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  25015. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  25016. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  25017. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  25018. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  25019. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  25020. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  25021. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  25022. function hash(data, offset, length, mode384) {
  25023. mode384 = !!mode384;
  25024. // initial hash values
  25025. var h0, h1, h2, h3, h4, h5, h6, h7;
  25026. if (!mode384) {
  25027. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  25028. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  25029. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  25030. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  25031. h4 = new Word64(0x510e527f, 0xade682d1);
  25032. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  25033. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  25034. h7 = new Word64(0x5be0cd19, 0x137e2179);
  25035. }
  25036. else {
  25037. // SHA384 is exactly the same
  25038. // except with different starting values and a trimmed result
  25039. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  25040. h1 = new Word64(0x629a292a, 0x367cd507);
  25041. h2 = new Word64(0x9159015a, 0x3070dd17);
  25042. h3 = new Word64(0x152fecd8, 0xf70e5939);
  25043. h4 = new Word64(0x67332667, 0xffc00b31);
  25044. h5 = new Word64(0x8eb44a87, 0x68581511);
  25045. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  25046. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  25047. }
  25048. // pre-processing
  25049. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  25050. var padded = new Uint8Array(paddedLength);
  25051. var i, j, n;
  25052. for (i = 0; i < length; ++i) {
  25053. padded[i] = data[offset++];
  25054. }
  25055. padded[i++] = 0x80;
  25056. n = paddedLength - 16;
  25057. while (i < n) {
  25058. padded[i++] = 0;
  25059. }
  25060. padded[i++] = 0;
  25061. padded[i++] = 0;
  25062. padded[i++] = 0;
  25063. padded[i++] = 0;
  25064. padded[i++] = 0;
  25065. padded[i++] = 0;
  25066. padded[i++] = 0;
  25067. padded[i++] = 0;
  25068. padded[i++] = 0;
  25069. padded[i++] = 0;
  25070. padded[i++] = 0;
  25071. padded[i++] = (length >>> 29) & 0xFF;
  25072. padded[i++] = (length >> 21) & 0xFF;
  25073. padded[i++] = (length >> 13) & 0xFF;
  25074. padded[i++] = (length >> 5) & 0xFF;
  25075. padded[i++] = (length << 3) & 0xFF;
  25076. var w = new Array(80);
  25077. for (i = 0; i < 80; i++) {
  25078. w[i] = new Word64(0, 0);
  25079. }
  25080. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  25081. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  25082. var g = new Word64(0, 0), h = new Word64(0, 0);
  25083. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  25084. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  25085. // for each 1024 bit block
  25086. for (i = 0; i < paddedLength;) {
  25087. for (j = 0; j < 16; ++j) {
  25088. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  25089. (padded[i + 2] << 8) | (padded[i + 3]);
  25090. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  25091. (padded[i + 6]) << 8 | (padded[i + 7]);
  25092. i += 8;
  25093. }
  25094. for (j = 16; j < 80; ++j) {
  25095. tmp3 = w[j];
  25096. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  25097. tmp3.add(w[j - 7]);
  25098. littleSigma(tmp1, w[j - 15], tmp2);
  25099. tmp3.add(tmp1);
  25100. tmp3.add(w[j - 16]);
  25101. }
  25102. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  25103. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  25104. for (j = 0; j < 80; ++j) {
  25105. t1.assign(h);
  25106. sigmaPrime(tmp1, e, tmp2);
  25107. t1.add(tmp1);
  25108. ch(tmp1, e, f, g, tmp2);
  25109. t1.add(tmp1);
  25110. t1.add(k[j]);
  25111. t1.add(w[j]);
  25112. sigma(t2, a, tmp2);
  25113. maj(tmp1, a, b, c, tmp2);
  25114. t2.add(tmp1);
  25115. tmp3 = h;
  25116. h = g;
  25117. g = f;
  25118. f = e;
  25119. d.add(t1);
  25120. e = d;
  25121. d = c;
  25122. c = b;
  25123. b = a;
  25124. tmp3.assign(t1);
  25125. tmp3.add(t2);
  25126. a = tmp3;
  25127. }
  25128. h0.add(a);
  25129. h1.add(b);
  25130. h2.add(c);
  25131. h3.add(d);
  25132. h4.add(e);
  25133. h5.add(f);
  25134. h6.add(g);
  25135. h7.add(h);
  25136. }
  25137. var result;
  25138. if (!mode384) {
  25139. result = new Uint8Array(64);
  25140. h0.copyTo(result,0);
  25141. h1.copyTo(result,8);
  25142. h2.copyTo(result,16);
  25143. h3.copyTo(result,24);
  25144. h4.copyTo(result,32);
  25145. h5.copyTo(result,40);
  25146. h6.copyTo(result,48);
  25147. h7.copyTo(result,56);
  25148. }
  25149. else {
  25150. result = new Uint8Array(48);
  25151. h0.copyTo(result,0);
  25152. h1.copyTo(result,8);
  25153. h2.copyTo(result,16);
  25154. h3.copyTo(result,24);
  25155. h4.copyTo(result,32);
  25156. h5.copyTo(result,40);
  25157. }
  25158. return result;
  25159. }
  25160. return hash;
  25161. })();
  25162. var calculateSHA384 = (function calculateSHA384Closure() {
  25163. function hash(data, offset, length) {
  25164. return calculateSHA512(data, offset, length, true);
  25165. }
  25166. return hash;
  25167. })();
  25168. var NullCipher = (function NullCipherClosure() {
  25169. function NullCipher() {
  25170. }
  25171. NullCipher.prototype = {
  25172. decryptBlock: function NullCipher_decryptBlock(data) {
  25173. return data;
  25174. }
  25175. };
  25176. return NullCipher;
  25177. })();
  25178. var AES128Cipher = (function AES128CipherClosure() {
  25179. var rcon = new Uint8Array([
  25180. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25181. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25182. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25183. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25184. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25185. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25186. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25187. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25188. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25189. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25190. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25191. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25192. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25193. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25194. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25195. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25196. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25197. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25198. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25199. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25200. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25201. 0x74, 0xe8, 0xcb, 0x8d]);
  25202. var s = new Uint8Array([
  25203. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25204. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25205. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25206. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25207. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25208. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25209. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25210. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25211. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25212. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25213. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25214. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25215. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25216. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25217. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25218. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25219. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25220. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25221. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25222. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25223. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25224. 0xb0, 0x54, 0xbb, 0x16]);
  25225. var inv_s = new Uint8Array([
  25226. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25227. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25228. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25229. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25230. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25231. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25232. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25233. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25234. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25235. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25236. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25237. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25238. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25239. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25240. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25241. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25242. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25243. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25244. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25245. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25246. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25247. 0x55, 0x21, 0x0c, 0x7d]);
  25248. var mixCol = new Uint8Array(256);
  25249. for (var i = 0; i < 256; i++) {
  25250. if (i < 128) {
  25251. mixCol[i] = i << 1;
  25252. } else {
  25253. mixCol[i] = (i << 1) ^ 0x1b;
  25254. }
  25255. }
  25256. var mix = new Uint32Array([
  25257. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25258. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25259. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25260. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25261. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25262. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25263. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25264. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25265. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25266. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25267. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25268. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25269. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25270. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25271. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25272. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25273. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25274. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25275. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25276. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25277. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25278. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25279. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25280. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25281. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25282. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25283. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25284. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25285. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25286. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25287. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25288. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25289. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25290. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25291. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25292. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25293. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25294. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25295. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25296. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25297. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25298. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25299. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25300. function expandKey128(cipherKey) {
  25301. var b = 176, result = new Uint8Array(b);
  25302. result.set(cipherKey);
  25303. for (var j = 16, i = 1; j < b; ++i) {
  25304. // RotWord
  25305. var t1 = result[j - 3], t2 = result[j - 2],
  25306. t3 = result[j - 1], t4 = result[j - 4];
  25307. // SubWord
  25308. t1 = s[t1];
  25309. t2 = s[t2];
  25310. t3 = s[t3];
  25311. t4 = s[t4];
  25312. // Rcon
  25313. t1 = t1 ^ rcon[i];
  25314. for (var n = 0; n < 4; ++n) {
  25315. result[j] = (t1 ^= result[j - 16]);
  25316. j++;
  25317. result[j] = (t2 ^= result[j - 16]);
  25318. j++;
  25319. result[j] = (t3 ^= result[j - 16]);
  25320. j++;
  25321. result[j] = (t4 ^= result[j - 16]);
  25322. j++;
  25323. }
  25324. }
  25325. return result;
  25326. }
  25327. function decrypt128(input, key) {
  25328. var state = new Uint8Array(16);
  25329. state.set(input);
  25330. var i, j, k;
  25331. var t, u, v;
  25332. // AddRoundKey
  25333. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25334. state[j] ^= key[k];
  25335. }
  25336. for (i = 9; i >= 1; --i) {
  25337. // InvShiftRows
  25338. t = state[13];
  25339. state[13] = state[9];
  25340. state[9] = state[5];
  25341. state[5] = state[1];
  25342. state[1] = t;
  25343. t = state[14];
  25344. u = state[10];
  25345. state[14] = state[6];
  25346. state[10] = state[2];
  25347. state[6] = t;
  25348. state[2] = u;
  25349. t = state[15];
  25350. u = state[11];
  25351. v = state[7];
  25352. state[15] = state[3];
  25353. state[11] = t;
  25354. state[7] = u;
  25355. state[3] = v;
  25356. // InvSubBytes
  25357. for (j = 0; j < 16; ++j) {
  25358. state[j] = inv_s[state[j]];
  25359. }
  25360. // AddRoundKey
  25361. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25362. state[j] ^= key[k];
  25363. }
  25364. // InvMixColumns
  25365. for (j = 0; j < 16; j += 4) {
  25366. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25367. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25368. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25369. (s3 >>> 24) ^ (s3 << 8));
  25370. state[j] = (t >>> 24) & 0xFF;
  25371. state[j + 1] = (t >> 16) & 0xFF;
  25372. state[j + 2] = (t >> 8) & 0xFF;
  25373. state[j + 3] = t & 0xFF;
  25374. }
  25375. }
  25376. // InvShiftRows
  25377. t = state[13];
  25378. state[13] = state[9];
  25379. state[9] = state[5];
  25380. state[5] = state[1];
  25381. state[1] = t;
  25382. t = state[14];
  25383. u = state[10];
  25384. state[14] = state[6];
  25385. state[10] = state[2];
  25386. state[6] = t;
  25387. state[2] = u;
  25388. t = state[15];
  25389. u = state[11];
  25390. v = state[7];
  25391. state[15] = state[3];
  25392. state[11] = t;
  25393. state[7] = u;
  25394. state[3] = v;
  25395. for (j = 0; j < 16; ++j) {
  25396. // InvSubBytes
  25397. state[j] = inv_s[state[j]];
  25398. // AddRoundKey
  25399. state[j] ^= key[j];
  25400. }
  25401. return state;
  25402. }
  25403. function encrypt128(input, key) {
  25404. var t, u, v, k;
  25405. var state = new Uint8Array(16);
  25406. state.set(input);
  25407. for (j = 0; j < 16; ++j) {
  25408. // AddRoundKey
  25409. state[j] ^= key[j];
  25410. }
  25411. for (i = 1; i < 10; i++) {
  25412. //SubBytes
  25413. for (j = 0; j < 16; ++j) {
  25414. state[j] = s[state[j]];
  25415. }
  25416. //ShiftRows
  25417. v = state[1];
  25418. state[1] = state[5];
  25419. state[5] = state[9];
  25420. state[9] = state[13];
  25421. state[13] = v;
  25422. v = state[2];
  25423. u = state[6];
  25424. state[2] = state[10];
  25425. state[6] = state[14];
  25426. state[10] = v;
  25427. state[14] = u;
  25428. v = state[3];
  25429. u = state[7];
  25430. t = state[11];
  25431. state[3] = state[15];
  25432. state[7] = v;
  25433. state[11] = u;
  25434. state[15] = t;
  25435. //MixColumns
  25436. for (var j = 0; j < 16; j += 4) {
  25437. var s0 = state[j + 0], s1 = state[j + 1];
  25438. var s2 = state[j + 2], s3 = state[j + 3];
  25439. t = s0 ^ s1 ^ s2 ^ s3;
  25440. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25441. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25442. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25443. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25444. }
  25445. //AddRoundKey
  25446. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25447. state[j] ^= key[k];
  25448. }
  25449. }
  25450. //SubBytes
  25451. for (j = 0; j < 16; ++j) {
  25452. state[j] = s[state[j]];
  25453. }
  25454. //ShiftRows
  25455. v = state[1];
  25456. state[1] = state[5];
  25457. state[5] = state[9];
  25458. state[9] = state[13];
  25459. state[13] = v;
  25460. v = state[2];
  25461. u = state[6];
  25462. state[2] = state[10];
  25463. state[6] = state[14];
  25464. state[10] = v;
  25465. state[14] = u;
  25466. v = state[3];
  25467. u = state[7];
  25468. t = state[11];
  25469. state[3] = state[15];
  25470. state[7] = v;
  25471. state[11] = u;
  25472. state[15] = t;
  25473. //AddRoundKey
  25474. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25475. state[j] ^= key[k];
  25476. }
  25477. return state;
  25478. }
  25479. function AES128Cipher(key) {
  25480. this.key = expandKey128(key);
  25481. this.buffer = new Uint8Array(16);
  25482. this.bufferPosition = 0;
  25483. }
  25484. function decryptBlock2(data, finalize) {
  25485. var i, j, ii, sourceLength = data.length,
  25486. buffer = this.buffer, bufferLength = this.bufferPosition,
  25487. result = [], iv = this.iv;
  25488. for (i = 0; i < sourceLength; ++i) {
  25489. buffer[bufferLength] = data[i];
  25490. ++bufferLength;
  25491. if (bufferLength < 16) {
  25492. continue;
  25493. }
  25494. // buffer is full, decrypting
  25495. var plain = decrypt128(buffer, this.key);
  25496. // xor-ing the IV vector to get plain text
  25497. for (j = 0; j < 16; ++j) {
  25498. plain[j] ^= iv[j];
  25499. }
  25500. iv = buffer;
  25501. result.push(plain);
  25502. buffer = new Uint8Array(16);
  25503. bufferLength = 0;
  25504. }
  25505. // saving incomplete buffer
  25506. this.buffer = buffer;
  25507. this.bufferLength = bufferLength;
  25508. this.iv = iv;
  25509. if (result.length === 0) {
  25510. return new Uint8Array([]);
  25511. }
  25512. // combining plain text blocks into one
  25513. var outputLength = 16 * result.length;
  25514. if (finalize) {
  25515. // undo a padding that is described in RFC 2898
  25516. var lastBlock = result[result.length - 1];
  25517. var psLen = lastBlock[15];
  25518. if (psLen <= 16) {
  25519. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25520. if (lastBlock[i] !== psLen) {
  25521. // Invalid padding, assume that the block has no padding.
  25522. psLen = 0;
  25523. break;
  25524. }
  25525. }
  25526. outputLength -= psLen;
  25527. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25528. }
  25529. }
  25530. var output = new Uint8Array(outputLength);
  25531. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25532. output.set(result[i], j);
  25533. }
  25534. return output;
  25535. }
  25536. AES128Cipher.prototype = {
  25537. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  25538. var i, sourceLength = data.length;
  25539. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25540. // waiting for IV values -- they are at the start of the stream
  25541. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  25542. buffer[bufferLength] = data[i];
  25543. }
  25544. if (bufferLength < 16) {
  25545. // need more data
  25546. this.bufferLength = bufferLength;
  25547. return new Uint8Array([]);
  25548. }
  25549. this.iv = buffer;
  25550. this.buffer = new Uint8Array(16);
  25551. this.bufferLength = 0;
  25552. // starting decryption
  25553. this.decryptBlock = decryptBlock2;
  25554. return this.decryptBlock(data.subarray(16), finalize);
  25555. },
  25556. encrypt: function AES128Cipher_encrypt(data, iv) {
  25557. var i, j, ii, sourceLength = data.length,
  25558. buffer = this.buffer, bufferLength = this.bufferPosition,
  25559. result = [];
  25560. if (!iv) {
  25561. iv = new Uint8Array(16);
  25562. }
  25563. for (i = 0; i < sourceLength; ++i) {
  25564. buffer[bufferLength] = data[i];
  25565. ++bufferLength;
  25566. if (bufferLength < 16) {
  25567. continue;
  25568. }
  25569. for (j = 0; j < 16; ++j) {
  25570. buffer[j] ^= iv[j];
  25571. }
  25572. // buffer is full, encrypting
  25573. var cipher = encrypt128(buffer, this.key);
  25574. iv = cipher;
  25575. result.push(cipher);
  25576. buffer = new Uint8Array(16);
  25577. bufferLength = 0;
  25578. }
  25579. // saving incomplete buffer
  25580. this.buffer = buffer;
  25581. this.bufferLength = bufferLength;
  25582. this.iv = iv;
  25583. if (result.length === 0) {
  25584. return new Uint8Array([]);
  25585. }
  25586. // combining plain text blocks into one
  25587. var outputLength = 16 * result.length;
  25588. var output = new Uint8Array(outputLength);
  25589. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25590. output.set(result[i], j);
  25591. }
  25592. return output;
  25593. }
  25594. };
  25595. return AES128Cipher;
  25596. })();
  25597. var AES256Cipher = (function AES256CipherClosure() {
  25598. var rcon = new Uint8Array([
  25599. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25600. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25601. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25602. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25603. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25604. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25605. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25606. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25607. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25608. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25609. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25610. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25611. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25612. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25613. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25614. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25615. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25616. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25617. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25618. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25619. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25620. 0x74, 0xe8, 0xcb, 0x8d]);
  25621. var s = new Uint8Array([
  25622. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25623. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25624. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25625. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25626. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25627. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25628. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25629. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25630. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25631. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25632. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25633. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25634. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25635. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25636. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25637. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25638. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25639. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25640. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25641. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25642. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25643. 0xb0, 0x54, 0xbb, 0x16]);
  25644. var inv_s = new Uint8Array([
  25645. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25646. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25647. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25648. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25649. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25650. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25651. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25652. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25653. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25654. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25655. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25656. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25657. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25658. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25659. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25660. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25661. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25662. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25663. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25664. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25665. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25666. 0x55, 0x21, 0x0c, 0x7d]);
  25667. var mixCol = new Uint8Array(256);
  25668. for (var i = 0; i < 256; i++) {
  25669. if (i < 128) {
  25670. mixCol[i] = i << 1;
  25671. } else {
  25672. mixCol[i] = (i << 1) ^ 0x1b;
  25673. }
  25674. }
  25675. var mix = new Uint32Array([
  25676. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25677. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25678. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25679. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25680. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25681. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25682. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25683. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25684. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25685. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25686. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25687. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25688. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25689. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25690. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25691. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25692. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25693. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25694. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25695. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25696. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25697. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25698. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25699. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25700. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25701. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25702. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25703. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25704. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25705. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25706. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25707. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25708. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25709. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25710. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25711. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25712. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25713. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25714. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25715. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25716. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25717. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25718. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25719. function expandKey256(cipherKey) {
  25720. var b = 240, result = new Uint8Array(b);
  25721. var r = 1;
  25722. result.set(cipherKey);
  25723. for (var j = 32, i = 1; j < b; ++i) {
  25724. if (j % 32 === 16) {
  25725. t1 = s[t1];
  25726. t2 = s[t2];
  25727. t3 = s[t3];
  25728. t4 = s[t4];
  25729. } else if (j % 32 === 0) {
  25730. // RotWord
  25731. var t1 = result[j - 3], t2 = result[j - 2],
  25732. t3 = result[j - 1], t4 = result[j - 4];
  25733. // SubWord
  25734. t1 = s[t1];
  25735. t2 = s[t2];
  25736. t3 = s[t3];
  25737. t4 = s[t4];
  25738. // Rcon
  25739. t1 = t1 ^ r;
  25740. if ((r <<= 1) >= 256) {
  25741. r = (r ^ 0x1b) & 0xFF;
  25742. }
  25743. }
  25744. for (var n = 0; n < 4; ++n) {
  25745. result[j] = (t1 ^= result[j - 32]);
  25746. j++;
  25747. result[j] = (t2 ^= result[j - 32]);
  25748. j++;
  25749. result[j] = (t3 ^= result[j - 32]);
  25750. j++;
  25751. result[j] = (t4 ^= result[j - 32]);
  25752. j++;
  25753. }
  25754. }
  25755. return result;
  25756. }
  25757. function decrypt256(input, key) {
  25758. var state = new Uint8Array(16);
  25759. state.set(input);
  25760. var i, j, k;
  25761. var t, u, v;
  25762. // AddRoundKey
  25763. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25764. state[j] ^= key[k];
  25765. }
  25766. for (i = 13; i >= 1; --i) {
  25767. // InvShiftRows
  25768. t = state[13];
  25769. state[13] = state[9];
  25770. state[9] = state[5];
  25771. state[5] = state[1];
  25772. state[1] = t;
  25773. t = state[14];
  25774. u = state[10];
  25775. state[14] = state[6];
  25776. state[10] = state[2];
  25777. state[6] = t;
  25778. state[2] = u;
  25779. t = state[15];
  25780. u = state[11];
  25781. v = state[7];
  25782. state[15] = state[3];
  25783. state[11] = t;
  25784. state[7] = u;
  25785. state[3] = v;
  25786. // InvSubBytes
  25787. for (j = 0; j < 16; ++j) {
  25788. state[j] = inv_s[state[j]];
  25789. }
  25790. // AddRoundKey
  25791. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25792. state[j] ^= key[k];
  25793. }
  25794. // InvMixColumns
  25795. for (j = 0; j < 16; j += 4) {
  25796. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25797. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25798. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25799. (s3 >>> 24) ^ (s3 << 8));
  25800. state[j] = (t >>> 24) & 0xFF;
  25801. state[j + 1] = (t >> 16) & 0xFF;
  25802. state[j + 2] = (t >> 8) & 0xFF;
  25803. state[j + 3] = t & 0xFF;
  25804. }
  25805. }
  25806. // InvShiftRows
  25807. t = state[13];
  25808. state[13] = state[9];
  25809. state[9] = state[5];
  25810. state[5] = state[1];
  25811. state[1] = t;
  25812. t = state[14];
  25813. u = state[10];
  25814. state[14] = state[6];
  25815. state[10] = state[2];
  25816. state[6] = t;
  25817. state[2] = u;
  25818. t = state[15];
  25819. u = state[11];
  25820. v = state[7];
  25821. state[15] = state[3];
  25822. state[11] = t;
  25823. state[7] = u;
  25824. state[3] = v;
  25825. for (j = 0; j < 16; ++j) {
  25826. // InvSubBytes
  25827. state[j] = inv_s[state[j]];
  25828. // AddRoundKey
  25829. state[j] ^= key[j];
  25830. }
  25831. return state;
  25832. }
  25833. function encrypt256(input, key) {
  25834. var t, u, v, k;
  25835. var state = new Uint8Array(16);
  25836. state.set(input);
  25837. for (j = 0; j < 16; ++j) {
  25838. // AddRoundKey
  25839. state[j] ^= key[j];
  25840. }
  25841. for (i = 1; i < 14; i++) {
  25842. //SubBytes
  25843. for (j = 0; j < 16; ++j) {
  25844. state[j] = s[state[j]];
  25845. }
  25846. //ShiftRows
  25847. v = state[1];
  25848. state[1] = state[5];
  25849. state[5] = state[9];
  25850. state[9] = state[13];
  25851. state[13] = v;
  25852. v = state[2];
  25853. u = state[6];
  25854. state[2] = state[10];
  25855. state[6] = state[14];
  25856. state[10] = v;
  25857. state[14] = u;
  25858. v = state[3];
  25859. u = state[7];
  25860. t = state[11];
  25861. state[3] = state[15];
  25862. state[7] = v;
  25863. state[11] = u;
  25864. state[15] = t;
  25865. //MixColumns
  25866. for (var j = 0; j < 16; j += 4) {
  25867. var s0 = state[j + 0], s1 = state[j + 1];
  25868. var s2 = state[j + 2], s3 = state[j + 3];
  25869. t = s0 ^ s1 ^ s2 ^ s3;
  25870. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25871. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25872. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25873. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25874. }
  25875. //AddRoundKey
  25876. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25877. state[j] ^= key[k];
  25878. }
  25879. }
  25880. //SubBytes
  25881. for (j = 0; j < 16; ++j) {
  25882. state[j] = s[state[j]];
  25883. }
  25884. //ShiftRows
  25885. v = state[1];
  25886. state[1] = state[5];
  25887. state[5] = state[9];
  25888. state[9] = state[13];
  25889. state[13] = v;
  25890. v = state[2];
  25891. u = state[6];
  25892. state[2] = state[10];
  25893. state[6] = state[14];
  25894. state[10] = v;
  25895. state[14] = u;
  25896. v = state[3];
  25897. u = state[7];
  25898. t = state[11];
  25899. state[3] = state[15];
  25900. state[7] = v;
  25901. state[11] = u;
  25902. state[15] = t;
  25903. //AddRoundKey
  25904. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25905. state[j] ^= key[k];
  25906. }
  25907. return state;
  25908. }
  25909. function AES256Cipher(key) {
  25910. this.key = expandKey256(key);
  25911. this.buffer = new Uint8Array(16);
  25912. this.bufferPosition = 0;
  25913. }
  25914. function decryptBlock2(data, finalize) {
  25915. var i, j, ii, sourceLength = data.length,
  25916. buffer = this.buffer, bufferLength = this.bufferPosition,
  25917. result = [], iv = this.iv;
  25918. for (i = 0; i < sourceLength; ++i) {
  25919. buffer[bufferLength] = data[i];
  25920. ++bufferLength;
  25921. if (bufferLength < 16) {
  25922. continue;
  25923. }
  25924. // buffer is full, decrypting
  25925. var plain = decrypt256(buffer, this.key);
  25926. // xor-ing the IV vector to get plain text
  25927. for (j = 0; j < 16; ++j) {
  25928. plain[j] ^= iv[j];
  25929. }
  25930. iv = buffer;
  25931. result.push(plain);
  25932. buffer = new Uint8Array(16);
  25933. bufferLength = 0;
  25934. }
  25935. // saving incomplete buffer
  25936. this.buffer = buffer;
  25937. this.bufferLength = bufferLength;
  25938. this.iv = iv;
  25939. if (result.length === 0) {
  25940. return new Uint8Array([]);
  25941. }
  25942. // combining plain text blocks into one
  25943. var outputLength = 16 * result.length;
  25944. if (finalize) {
  25945. // undo a padding that is described in RFC 2898
  25946. var lastBlock = result[result.length - 1];
  25947. var psLen = lastBlock[15];
  25948. if (psLen <= 16) {
  25949. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25950. if (lastBlock[i] !== psLen) {
  25951. // Invalid padding, assume that the block has no padding.
  25952. psLen = 0;
  25953. break;
  25954. }
  25955. }
  25956. outputLength -= psLen;
  25957. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25958. }
  25959. }
  25960. var output = new Uint8Array(outputLength);
  25961. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25962. output.set(result[i], j);
  25963. }
  25964. return output;
  25965. }
  25966. AES256Cipher.prototype = {
  25967. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  25968. var i, sourceLength = data.length;
  25969. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25970. // if not supplied an IV wait for IV values
  25971. // they are at the start of the stream
  25972. if (iv) {
  25973. this.iv = iv;
  25974. } else {
  25975. for (i = 0; bufferLength < 16 &&
  25976. i < sourceLength; ++i, ++bufferLength) {
  25977. buffer[bufferLength] = data[i];
  25978. }
  25979. if (bufferLength < 16) {
  25980. //need more data
  25981. this.bufferLength = bufferLength;
  25982. return new Uint8Array([]);
  25983. }
  25984. this.iv = buffer;
  25985. data = data.subarray(16);
  25986. }
  25987. this.buffer = new Uint8Array(16);
  25988. this.bufferLength = 0;
  25989. // starting decryption
  25990. this.decryptBlock = decryptBlock2;
  25991. return this.decryptBlock(data, finalize);
  25992. },
  25993. encrypt: function AES256Cipher_encrypt(data, iv) {
  25994. var i, j, ii, sourceLength = data.length,
  25995. buffer = this.buffer, bufferLength = this.bufferPosition,
  25996. result = [];
  25997. if (!iv) {
  25998. iv = new Uint8Array(16);
  25999. }
  26000. for (i = 0; i < sourceLength; ++i) {
  26001. buffer[bufferLength] = data[i];
  26002. ++bufferLength;
  26003. if (bufferLength < 16) {
  26004. continue;
  26005. }
  26006. for (j = 0; j < 16; ++j) {
  26007. buffer[j] ^= iv[j];
  26008. }
  26009. // buffer is full, encrypting
  26010. var cipher = encrypt256(buffer, this.key);
  26011. this.iv = cipher;
  26012. result.push(cipher);
  26013. buffer = new Uint8Array(16);
  26014. bufferLength = 0;
  26015. }
  26016. // saving incomplete buffer
  26017. this.buffer = buffer;
  26018. this.bufferLength = bufferLength;
  26019. this.iv = iv;
  26020. if (result.length === 0) {
  26021. return new Uint8Array([]);
  26022. }
  26023. // combining plain text blocks into one
  26024. var outputLength = 16 * result.length;
  26025. var output = new Uint8Array(outputLength);
  26026. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  26027. output.set(result[i], j);
  26028. }
  26029. return output;
  26030. }
  26031. };
  26032. return AES256Cipher;
  26033. })();
  26034. var PDF17 = (function PDF17Closure() {
  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. function PDF17() {
  26047. }
  26048. PDF17.prototype = {
  26049. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  26050. ownerValidationSalt,
  26051. userBytes,
  26052. ownerPassword) {
  26053. var hashData = new Uint8Array(password.length + 56);
  26054. hashData.set(password, 0);
  26055. hashData.set(ownerValidationSalt, password.length);
  26056. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26057. var result = calculateSHA256(hashData, 0, hashData.length);
  26058. return compareByteArrays(result, ownerPassword);
  26059. },
  26060. checkUserPassword: function PDF17_checkUserPassword(password,
  26061. userValidationSalt,
  26062. userPassword) {
  26063. var hashData = new Uint8Array(password.length + 8);
  26064. hashData.set(password, 0);
  26065. hashData.set(userValidationSalt, password.length);
  26066. var result = calculateSHA256(hashData, 0, hashData.length);
  26067. return compareByteArrays(result, userPassword);
  26068. },
  26069. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  26070. ownerEncryption) {
  26071. var hashData = new Uint8Array(password.length + 56);
  26072. hashData.set(password, 0);
  26073. hashData.set(ownerKeySalt, password.length);
  26074. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26075. var key = calculateSHA256(hashData, 0, hashData.length);
  26076. var cipher = new AES256Cipher(key);
  26077. return cipher.decryptBlock(ownerEncryption,
  26078. false,
  26079. new Uint8Array(16));
  26080. },
  26081. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  26082. userEncryption) {
  26083. var hashData = new Uint8Array(password.length + 8);
  26084. hashData.set(password, 0);
  26085. hashData.set(userKeySalt, password.length);
  26086. //key is the decryption key for the UE string
  26087. var key = calculateSHA256(hashData, 0, hashData.length);
  26088. var cipher = new AES256Cipher(key);
  26089. return cipher.decryptBlock(userEncryption,
  26090. false,
  26091. new Uint8Array(16));
  26092. }
  26093. };
  26094. return PDF17;
  26095. })();
  26096. var PDF20 = (function PDF20Closure() {
  26097. function concatArrays(array1, array2) {
  26098. var t = new Uint8Array(array1.length + array2.length);
  26099. t.set(array1, 0);
  26100. t.set(array2, array1.length);
  26101. return t;
  26102. }
  26103. function calculatePDF20Hash(password, input, userBytes) {
  26104. //This refers to Algorithm 2.B as defined in ISO 32000-2
  26105. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  26106. var e = [0];
  26107. var i = 0;
  26108. while (i < 64 || e[e.length - 1] > i - 32) {
  26109. var arrayLength = password.length + k.length + userBytes.length;
  26110. var k1 = new Uint8Array(arrayLength * 64);
  26111. var array = concatArrays(password, k);
  26112. array = concatArrays(array, userBytes);
  26113. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  26114. k1.set(array, pos);
  26115. }
  26116. //AES128 CBC NO PADDING with
  26117. //first 16 bytes of k as the key and the second 16 as the iv.
  26118. var cipher = new AES128Cipher(k.subarray(0, 16));
  26119. e = cipher.encrypt(k1, k.subarray(16, 32));
  26120. //Now we have to take the first 16 bytes of an unsigned
  26121. //big endian integer... and compute the remainder
  26122. //modulo 3.... That is a fairly large number and
  26123. //JavaScript isn't going to handle that well...
  26124. //So we're using a trick that allows us to perform
  26125. //modulo math byte by byte
  26126. var remainder = 0;
  26127. for (var z = 0; z < 16; z++) {
  26128. remainder *= (256 % 3);
  26129. remainder %= 3;
  26130. remainder += ((e[z] >>> 0) % 3);
  26131. remainder %= 3;
  26132. }
  26133. if (remainder === 0) {
  26134. k = calculateSHA256(e, 0, e.length);
  26135. }
  26136. else if (remainder === 1) {
  26137. k = calculateSHA384(e, 0, e.length);
  26138. }
  26139. else if (remainder === 2) {
  26140. k = calculateSHA512(e, 0, e.length);
  26141. }
  26142. i++;
  26143. }
  26144. return k.subarray(0, 32);
  26145. }
  26146. function PDF20() {
  26147. }
  26148. function compareByteArrays(array1, array2) {
  26149. if (array1.length !== array2.length) {
  26150. return false;
  26151. }
  26152. for (var i = 0; i < array1.length; i++) {
  26153. if (array1[i] !== array2[i]) {
  26154. return false;
  26155. }
  26156. }
  26157. return true;
  26158. }
  26159. PDF20.prototype = {
  26160. hash: function PDF20_hash(password, concatBytes, userBytes) {
  26161. return calculatePDF20Hash(password, concatBytes, userBytes);
  26162. },
  26163. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  26164. ownerValidationSalt,
  26165. userBytes,
  26166. ownerPassword) {
  26167. var hashData = new Uint8Array(password.length + 56);
  26168. hashData.set(password, 0);
  26169. hashData.set(ownerValidationSalt, password.length);
  26170. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26171. var result = calculatePDF20Hash(password, hashData, userBytes);
  26172. return compareByteArrays(result, ownerPassword);
  26173. },
  26174. checkUserPassword: function PDF20_checkUserPassword(password,
  26175. userValidationSalt,
  26176. userPassword) {
  26177. var hashData = new Uint8Array(password.length + 8);
  26178. hashData.set(password, 0);
  26179. hashData.set(userValidationSalt, password.length);
  26180. var result = calculatePDF20Hash(password, hashData, []);
  26181. return compareByteArrays(result, userPassword);
  26182. },
  26183. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  26184. ownerEncryption) {
  26185. var hashData = new Uint8Array(password.length + 56);
  26186. hashData.set(password, 0);
  26187. hashData.set(ownerKeySalt, password.length);
  26188. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26189. var key = calculatePDF20Hash(password, hashData, userBytes);
  26190. var cipher = new AES256Cipher(key);
  26191. return cipher.decryptBlock(ownerEncryption,
  26192. false,
  26193. new Uint8Array(16));
  26194. },
  26195. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  26196. userEncryption) {
  26197. var hashData = new Uint8Array(password.length + 8);
  26198. hashData.set(password, 0);
  26199. hashData.set(userKeySalt, password.length);
  26200. //key is the decryption key for the UE string
  26201. var key = calculatePDF20Hash(password, hashData, []);
  26202. var cipher = new AES256Cipher(key);
  26203. return cipher.decryptBlock(userEncryption,
  26204. false,
  26205. new Uint8Array(16));
  26206. }
  26207. };
  26208. return PDF20;
  26209. })();
  26210. var CipherTransform = (function CipherTransformClosure() {
  26211. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  26212. this.stringCipherConstructor = stringCipherConstructor;
  26213. this.streamCipherConstructor = streamCipherConstructor;
  26214. }
  26215. CipherTransform.prototype = {
  26216. createStream: function CipherTransform_createStream(stream, length) {
  26217. var cipher = new this.streamCipherConstructor();
  26218. return new DecryptStream(stream, length,
  26219. function cipherTransformDecryptStream(data, finalize) {
  26220. return cipher.decryptBlock(data, finalize);
  26221. }
  26222. );
  26223. },
  26224. decryptString: function CipherTransform_decryptString(s) {
  26225. var cipher = new this.stringCipherConstructor();
  26226. var data = stringToBytes(s);
  26227. data = cipher.decryptBlock(data, true);
  26228. return bytesToString(data);
  26229. }
  26230. };
  26231. return CipherTransform;
  26232. })();
  26233. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  26234. var defaultPasswordBytes = new Uint8Array([
  26235. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  26236. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  26237. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  26238. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  26239. function createEncryptionKey20(revision, password, ownerPassword,
  26240. ownerValidationSalt, ownerKeySalt, uBytes,
  26241. userPassword, userValidationSalt, userKeySalt,
  26242. ownerEncryption, userEncryption, perms) {
  26243. if (password) {
  26244. var passwordLength = Math.min(127, password.length);
  26245. password = password.subarray(0, passwordLength);
  26246. } else {
  26247. password = [];
  26248. }
  26249. var pdfAlgorithm;
  26250. if (revision === 6) {
  26251. pdfAlgorithm = new PDF20();
  26252. } else {
  26253. pdfAlgorithm = new PDF17();
  26254. }
  26255. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  26256. userPassword)) {
  26257. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  26258. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  26259. ownerValidationSalt,
  26260. uBytes,
  26261. ownerPassword)) {
  26262. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  26263. ownerEncryption);
  26264. }
  26265. return null;
  26266. }
  26267. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  26268. flags, revision, keyLength, encryptMetadata) {
  26269. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  26270. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  26271. if (password) {
  26272. n = Math.min(32, password.length);
  26273. for (; i < n; ++i) {
  26274. hashData[i] = password[i];
  26275. }
  26276. }
  26277. j = 0;
  26278. while (i < 32) {
  26279. hashData[i++] = defaultPasswordBytes[j++];
  26280. }
  26281. // as now the padded password in the hashData[0..i]
  26282. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  26283. hashData[i++] = ownerPassword[j];
  26284. }
  26285. hashData[i++] = flags & 0xFF;
  26286. hashData[i++] = (flags >> 8) & 0xFF;
  26287. hashData[i++] = (flags >> 16) & 0xFF;
  26288. hashData[i++] = (flags >>> 24) & 0xFF;
  26289. for (j = 0, n = fileId.length; j < n; ++j) {
  26290. hashData[i++] = fileId[j];
  26291. }
  26292. if (revision >= 4 && !encryptMetadata) {
  26293. hashData[i++] = 0xFF;
  26294. hashData[i++] = 0xFF;
  26295. hashData[i++] = 0xFF;
  26296. hashData[i++] = 0xFF;
  26297. }
  26298. var hash = calculateMD5(hashData, 0, i);
  26299. var keyLengthInBytes = keyLength >> 3;
  26300. if (revision >= 3) {
  26301. for (j = 0; j < 50; ++j) {
  26302. hash = calculateMD5(hash, 0, keyLengthInBytes);
  26303. }
  26304. }
  26305. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  26306. var cipher, checkData;
  26307. if (revision >= 3) {
  26308. for (i = 0; i < 32; ++i) {
  26309. hashData[i] = defaultPasswordBytes[i];
  26310. }
  26311. for (j = 0, n = fileId.length; j < n; ++j) {
  26312. hashData[i++] = fileId[j];
  26313. }
  26314. cipher = new ARCFourCipher(encryptionKey);
  26315. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  26316. n = encryptionKey.length;
  26317. var derivedKey = new Uint8Array(n), k;
  26318. for (j = 1; j <= 19; ++j) {
  26319. for (k = 0; k < n; ++k) {
  26320. derivedKey[k] = encryptionKey[k] ^ j;
  26321. }
  26322. cipher = new ARCFourCipher(derivedKey);
  26323. checkData = cipher.encryptBlock(checkData);
  26324. }
  26325. for (j = 0, n = checkData.length; j < n; ++j) {
  26326. if (userPassword[j] !== checkData[j]) {
  26327. return null;
  26328. }
  26329. }
  26330. } else {
  26331. cipher = new ARCFourCipher(encryptionKey);
  26332. checkData = cipher.encryptBlock(defaultPasswordBytes);
  26333. for (j = 0, n = checkData.length; j < n; ++j) {
  26334. if (userPassword[j] !== checkData[j]) {
  26335. return null;
  26336. }
  26337. }
  26338. }
  26339. return encryptionKey;
  26340. }
  26341. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  26342. var hashData = new Uint8Array(32), i = 0, j, n;
  26343. n = Math.min(32, password.length);
  26344. for (; i < n; ++i) {
  26345. hashData[i] = password[i];
  26346. }
  26347. j = 0;
  26348. while (i < 32) {
  26349. hashData[i++] = defaultPasswordBytes[j++];
  26350. }
  26351. var hash = calculateMD5(hashData, 0, i);
  26352. var keyLengthInBytes = keyLength >> 3;
  26353. if (revision >= 3) {
  26354. for (j = 0; j < 50; ++j) {
  26355. hash = calculateMD5(hash, 0, hash.length);
  26356. }
  26357. }
  26358. var cipher, userPassword;
  26359. if (revision >= 3) {
  26360. userPassword = ownerPassword;
  26361. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  26362. for (j = 19; j >= 0; j--) {
  26363. for (k = 0; k < keyLengthInBytes; ++k) {
  26364. derivedKey[k] = hash[k] ^ j;
  26365. }
  26366. cipher = new ARCFourCipher(derivedKey);
  26367. userPassword = cipher.encryptBlock(userPassword);
  26368. }
  26369. } else {
  26370. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  26371. userPassword = cipher.encryptBlock(ownerPassword);
  26372. }
  26373. return userPassword;
  26374. }
  26375. var identityName = Name.get('Identity');
  26376. function CipherTransformFactory(dict, fileId, password) {
  26377. var filter = dict.get('Filter');
  26378. if (!isName(filter, 'Standard')) {
  26379. error('unknown encryption method');
  26380. }
  26381. this.dict = dict;
  26382. var algorithm = dict.get('V');
  26383. if (!isInt(algorithm) ||
  26384. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  26385. algorithm !== 5)) {
  26386. error('unsupported encryption algorithm');
  26387. }
  26388. this.algorithm = algorithm;
  26389. var keyLength = dict.get('Length');
  26390. if (!keyLength) {
  26391. // Spec asks to rely on encryption dictionary's Length entry, however
  26392. // some PDFs don't have it. Trying to recover.
  26393. if (algorithm <= 3) {
  26394. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  26395. keyLength = 40;
  26396. } else {
  26397. // Trying to find default handler -- it usually has Length.
  26398. var cfDict = dict.get('CF');
  26399. var streamCryptoName = dict.get('StmF');
  26400. if (isDict(cfDict) && isName(streamCryptoName)) {
  26401. var handlerDict = cfDict.get(streamCryptoName.name);
  26402. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  26403. if (keyLength < 40) {
  26404. // Sometimes it's incorrect value of bits, generators specify bytes.
  26405. keyLength <<= 3;
  26406. }
  26407. }
  26408. }
  26409. }
  26410. if (!isInt(keyLength) ||
  26411. keyLength < 40 || (keyLength % 8) !== 0) {
  26412. error('invalid key length');
  26413. }
  26414. // prepare keys
  26415. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  26416. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  26417. var flags = dict.get('P');
  26418. var revision = dict.get('R');
  26419. // meaningful when V is 4 or 5
  26420. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  26421. dict.get('EncryptMetadata') !== false);
  26422. this.encryptMetadata = encryptMetadata;
  26423. var fileIdBytes = stringToBytes(fileId);
  26424. var passwordBytes;
  26425. if (password) {
  26426. if (revision === 6) {
  26427. try {
  26428. password = utf8StringToString(password);
  26429. } catch (ex) {
  26430. warn('CipherTransformFactory: ' +
  26431. 'Unable to convert UTF8 encoded password.');
  26432. }
  26433. }
  26434. passwordBytes = stringToBytes(password);
  26435. }
  26436. var encryptionKey;
  26437. if (algorithm !== 5) {
  26438. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  26439. ownerPassword, userPassword, flags,
  26440. revision, keyLength, encryptMetadata);
  26441. }
  26442. else {
  26443. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  26444. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  26445. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  26446. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  26447. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  26448. var ownerEncryption = stringToBytes(dict.get('OE'));
  26449. var userEncryption = stringToBytes(dict.get('UE'));
  26450. var perms = stringToBytes(dict.get('Perms'));
  26451. encryptionKey =
  26452. createEncryptionKey20(revision, passwordBytes,
  26453. ownerPassword, ownerValidationSalt,
  26454. ownerKeySalt, uBytes,
  26455. userPassword, userValidationSalt,
  26456. userKeySalt, ownerEncryption,
  26457. userEncryption, perms);
  26458. }
  26459. if (!encryptionKey && !password) {
  26460. throw new PasswordException('No password given',
  26461. PasswordResponses.NEED_PASSWORD);
  26462. } else if (!encryptionKey && password) {
  26463. // Attempting use the password as an owner password
  26464. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  26465. revision, keyLength);
  26466. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  26467. ownerPassword, userPassword, flags,
  26468. revision, keyLength, encryptMetadata);
  26469. }
  26470. if (!encryptionKey) {
  26471. throw new PasswordException('Incorrect Password',
  26472. PasswordResponses.INCORRECT_PASSWORD);
  26473. }
  26474. this.encryptionKey = encryptionKey;
  26475. if (algorithm >= 4) {
  26476. this.cf = dict.get('CF');
  26477. this.stmf = dict.get('StmF') || identityName;
  26478. this.strf = dict.get('StrF') || identityName;
  26479. this.eff = dict.get('EFF') || this.stmf;
  26480. }
  26481. }
  26482. function buildObjectKey(num, gen, encryptionKey, isAes) {
  26483. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  26484. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  26485. key[i] = encryptionKey[i];
  26486. }
  26487. key[i++] = num & 0xFF;
  26488. key[i++] = (num >> 8) & 0xFF;
  26489. key[i++] = (num >> 16) & 0xFF;
  26490. key[i++] = gen & 0xFF;
  26491. key[i++] = (gen >> 8) & 0xFF;
  26492. if (isAes) {
  26493. key[i++] = 0x73;
  26494. key[i++] = 0x41;
  26495. key[i++] = 0x6C;
  26496. key[i++] = 0x54;
  26497. }
  26498. var hash = calculateMD5(key, 0, i);
  26499. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  26500. }
  26501. function buildCipherConstructor(cf, name, num, gen, key) {
  26502. var cryptFilter = cf.get(name.name);
  26503. var cfm;
  26504. if (cryptFilter !== null && cryptFilter !== undefined) {
  26505. cfm = cryptFilter.get('CFM');
  26506. }
  26507. if (!cfm || cfm.name === 'None') {
  26508. return function cipherTransformFactoryBuildCipherConstructorNone() {
  26509. return new NullCipher();
  26510. };
  26511. }
  26512. if ('V2' === cfm.name) {
  26513. return function cipherTransformFactoryBuildCipherConstructorV2() {
  26514. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  26515. };
  26516. }
  26517. if ('AESV2' === cfm.name) {
  26518. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  26519. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  26520. };
  26521. }
  26522. if ('AESV3' === cfm.name) {
  26523. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  26524. return new AES256Cipher(key);
  26525. };
  26526. }
  26527. error('Unknown crypto method');
  26528. }
  26529. CipherTransformFactory.prototype = {
  26530. createCipherTransform:
  26531. function CipherTransformFactory_createCipherTransform(num, gen) {
  26532. if (this.algorithm === 4 || this.algorithm === 5) {
  26533. return new CipherTransform(
  26534. buildCipherConstructor(this.cf, this.stmf,
  26535. num, gen, this.encryptionKey),
  26536. buildCipherConstructor(this.cf, this.strf,
  26537. num, gen, this.encryptionKey));
  26538. }
  26539. // algorithms 1 and 2
  26540. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  26541. var cipherConstructor = function buildCipherCipherConstructor() {
  26542. return new ARCFourCipher(key);
  26543. };
  26544. return new CipherTransform(cipherConstructor, cipherConstructor);
  26545. }
  26546. };
  26547. return CipherTransformFactory;
  26548. })();
  26549. exports.AES128Cipher = AES128Cipher;
  26550. exports.AES256Cipher = AES256Cipher;
  26551. exports.ARCFourCipher = ARCFourCipher;
  26552. exports.CipherTransformFactory = CipherTransformFactory;
  26553. exports.PDF17 = PDF17;
  26554. exports.PDF20 = PDF20;
  26555. exports.calculateMD5 = calculateMD5;
  26556. exports.calculateSHA256 = calculateSHA256;
  26557. exports.calculateSHA384 = calculateSHA384;
  26558. exports.calculateSHA512 = calculateSHA512;
  26559. }));
  26560. (function (root, factory) {
  26561. {
  26562. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  26563. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  26564. root.pdfjsCoreCFFParser);
  26565. }
  26566. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  26567. coreEncodings, coreCFFParser) {
  26568. var Util = sharedUtil.Util;
  26569. var bytesToString = sharedUtil.bytesToString;
  26570. var error = sharedUtil.error;
  26571. var Stream = coreStream.Stream;
  26572. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26573. var StandardEncoding = coreEncodings.StandardEncoding;
  26574. var CFFParser = coreCFFParser.CFFParser;
  26575. var FontRendererFactory = (function FontRendererFactoryClosure() {
  26576. function getLong(data, offset) {
  26577. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26578. (data[offset + 2] << 8) | data[offset + 3];
  26579. }
  26580. function getUshort(data, offset) {
  26581. return (data[offset] << 8) | data[offset + 1];
  26582. }
  26583. function parseCmap(data, start, end) {
  26584. var offset = (getUshort(data, start + 2) === 1 ?
  26585. getLong(data, start + 8) : getLong(data, start + 16));
  26586. var format = getUshort(data, start + offset);
  26587. var length, ranges, p, i;
  26588. if (format === 4) {
  26589. length = getUshort(data, start + offset + 2);
  26590. var segCount = getUshort(data, start + offset + 6) >> 1;
  26591. p = start + offset + 14;
  26592. ranges = [];
  26593. for (i = 0; i < segCount; i++, p += 2) {
  26594. ranges[i] = {end: getUshort(data, p)};
  26595. }
  26596. p += 2;
  26597. for (i = 0; i < segCount; i++, p += 2) {
  26598. ranges[i].start = getUshort(data, p);
  26599. }
  26600. for (i = 0; i < segCount; i++, p += 2) {
  26601. ranges[i].idDelta = getUshort(data, p);
  26602. }
  26603. for (i = 0; i < segCount; i++, p += 2) {
  26604. var idOffset = getUshort(data, p);
  26605. if (idOffset === 0) {
  26606. continue;
  26607. }
  26608. ranges[i].ids = [];
  26609. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  26610. ranges[i].ids[j] = getUshort(data, p + idOffset);
  26611. idOffset += 2;
  26612. }
  26613. }
  26614. return ranges;
  26615. } else if (format === 12) {
  26616. length = getLong(data, start + offset + 4);
  26617. var groups = getLong(data, start + offset + 12);
  26618. p = start + offset + 16;
  26619. ranges = [];
  26620. for (i = 0; i < groups; i++) {
  26621. ranges.push({
  26622. start: getLong(data, p),
  26623. end: getLong(data, p + 4),
  26624. idDelta: getLong(data, p + 8) - getLong(data, p)
  26625. });
  26626. p += 12;
  26627. }
  26628. return ranges;
  26629. }
  26630. error('not supported cmap: ' + format);
  26631. }
  26632. function parseCff(data, start, end, seacAnalysisEnabled) {
  26633. var properties = {};
  26634. var parser = new CFFParser(new Stream(data, start, end - start),
  26635. properties, seacAnalysisEnabled);
  26636. var cff = parser.parse();
  26637. return {
  26638. glyphs: cff.charStrings.objects,
  26639. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  26640. cff.topDict.privateDict.subrsIndex.objects),
  26641. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  26642. };
  26643. }
  26644. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  26645. var itemSize, itemDecode;
  26646. if (isGlyphLocationsLong) {
  26647. itemSize = 4;
  26648. itemDecode = function fontItemDecodeLong(data, offset) {
  26649. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26650. (data[offset + 2] << 8) | data[offset + 3];
  26651. };
  26652. } else {
  26653. itemSize = 2;
  26654. itemDecode = function fontItemDecode(data, offset) {
  26655. return (data[offset] << 9) | (data[offset + 1] << 1);
  26656. };
  26657. }
  26658. var glyphs = [];
  26659. var startOffset = itemDecode(loca, 0);
  26660. for (var j = itemSize; j < loca.length; j += itemSize) {
  26661. var endOffset = itemDecode(loca, j);
  26662. glyphs.push(glyf.subarray(startOffset, endOffset));
  26663. startOffset = endOffset;
  26664. }
  26665. return glyphs;
  26666. }
  26667. function lookupCmap(ranges, unicode) {
  26668. var code = unicode.charCodeAt(0), gid = 0;
  26669. var l = 0, r = ranges.length - 1;
  26670. while (l < r) {
  26671. var c = (l + r + 1) >> 1;
  26672. if (code < ranges[c].start) {
  26673. r = c - 1;
  26674. } else {
  26675. l = c;
  26676. }
  26677. }
  26678. if (ranges[l].start <= code && code <= ranges[l].end) {
  26679. gid = (ranges[l].idDelta + (ranges[l].ids ?
  26680. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  26681. }
  26682. return {
  26683. charCode: code,
  26684. glyphId: gid,
  26685. };
  26686. }
  26687. function compileGlyf(code, cmds, font) {
  26688. function moveTo(x, y) {
  26689. cmds.push({cmd: 'moveTo', args: [x, y]});
  26690. }
  26691. function lineTo(x, y) {
  26692. cmds.push({cmd: 'lineTo', args: [x, y]});
  26693. }
  26694. function quadraticCurveTo(xa, ya, x, y) {
  26695. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  26696. }
  26697. var i = 0;
  26698. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26699. var flags;
  26700. var x = 0, y = 0;
  26701. i += 10;
  26702. if (numberOfContours < 0) {
  26703. // composite glyph
  26704. do {
  26705. flags = (code[i] << 8) | code[i + 1];
  26706. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  26707. i += 4;
  26708. var arg1, arg2;
  26709. if ((flags & 0x01)) {
  26710. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26711. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  26712. i += 4;
  26713. } else {
  26714. arg1 = code[i++]; arg2 = code[i++];
  26715. }
  26716. if ((flags & 0x02)) {
  26717. x = arg1;
  26718. y = arg2;
  26719. } else {
  26720. x = 0; y = 0; // TODO "they are points" ?
  26721. }
  26722. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  26723. if ((flags & 0x08)) {
  26724. scaleX =
  26725. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26726. i += 2;
  26727. } else if ((flags & 0x40)) {
  26728. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26729. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26730. i += 4;
  26731. } else if ((flags & 0x80)) {
  26732. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26733. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26734. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  26735. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  26736. i += 8;
  26737. }
  26738. var subglyph = font.glyphs[glyphIndex];
  26739. if (subglyph) {
  26740. cmds.push({cmd: 'save'});
  26741. cmds.push({cmd: 'transform',
  26742. args: [scaleX, scale01, scale10, scaleY, x, y]});
  26743. compileGlyf(subglyph, cmds, font);
  26744. cmds.push({cmd: 'restore'});
  26745. }
  26746. } while ((flags & 0x20));
  26747. } else {
  26748. // simple glyph
  26749. var endPtsOfContours = [];
  26750. var j, jj;
  26751. for (j = 0; j < numberOfContours; j++) {
  26752. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  26753. i += 2;
  26754. }
  26755. var instructionLength = (code[i] << 8) | code[i + 1];
  26756. i += 2 + instructionLength; // skipping the instructions
  26757. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  26758. var points = [];
  26759. while (points.length < numberOfPoints) {
  26760. flags = code[i++];
  26761. var repeat = 1;
  26762. if ((flags & 0x08)) {
  26763. repeat += code[i++];
  26764. }
  26765. while (repeat-- > 0) {
  26766. points.push({flags: flags});
  26767. }
  26768. }
  26769. for (j = 0; j < numberOfPoints; j++) {
  26770. switch (points[j].flags & 0x12) {
  26771. case 0x00:
  26772. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26773. i += 2;
  26774. break;
  26775. case 0x02:
  26776. x -= code[i++];
  26777. break;
  26778. case 0x12:
  26779. x += code[i++];
  26780. break;
  26781. }
  26782. points[j].x = x;
  26783. }
  26784. for (j = 0; j < numberOfPoints; j++) {
  26785. switch (points[j].flags & 0x24) {
  26786. case 0x00:
  26787. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26788. i += 2;
  26789. break;
  26790. case 0x04:
  26791. y -= code[i++];
  26792. break;
  26793. case 0x24:
  26794. y += code[i++];
  26795. break;
  26796. }
  26797. points[j].y = y;
  26798. }
  26799. var startPoint = 0;
  26800. for (i = 0; i < numberOfContours; i++) {
  26801. var endPoint = endPtsOfContours[i];
  26802. // contours might have implicit points, which is located in the middle
  26803. // between two neighboring off-curve points
  26804. var contour = points.slice(startPoint, endPoint + 1);
  26805. if ((contour[0].flags & 1)) {
  26806. contour.push(contour[0]); // using start point at the contour end
  26807. } else if ((contour[contour.length - 1].flags & 1)) {
  26808. // first is off-curve point, trying to use one from the end
  26809. contour.unshift(contour[contour.length - 1]);
  26810. } else {
  26811. // start and end are off-curve points, creating implicit one
  26812. var p = {
  26813. flags: 1,
  26814. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26815. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26816. };
  26817. contour.unshift(p);
  26818. contour.push(p);
  26819. }
  26820. moveTo(contour[0].x, contour[0].y);
  26821. for (j = 1, jj = contour.length; j < jj; j++) {
  26822. if ((contour[j].flags & 1)) {
  26823. lineTo(contour[j].x, contour[j].y);
  26824. } else if ((contour[j + 1].flags & 1)){
  26825. quadraticCurveTo(contour[j].x, contour[j].y,
  26826. contour[j + 1].x, contour[j + 1].y);
  26827. j++;
  26828. } else {
  26829. quadraticCurveTo(contour[j].x, contour[j].y,
  26830. (contour[j].x + contour[j + 1].x) / 2,
  26831. (contour[j].y + contour[j + 1].y) / 2);
  26832. }
  26833. }
  26834. startPoint = endPoint + 1;
  26835. }
  26836. }
  26837. }
  26838. function compileCharString(code, cmds, font) {
  26839. var stack = [];
  26840. var x = 0, y = 0;
  26841. var stems = 0;
  26842. function moveTo(x, y) {
  26843. cmds.push({cmd: 'moveTo', args: [x, y]});
  26844. }
  26845. function lineTo(x, y) {
  26846. cmds.push({cmd: 'lineTo', args: [x, y]});
  26847. }
  26848. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26849. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26850. }
  26851. function parse(code) {
  26852. var i = 0;
  26853. while (i < code.length) {
  26854. var stackClean = false;
  26855. var v = code[i++];
  26856. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26857. switch (v) {
  26858. case 1: // hstem
  26859. stems += stack.length >> 1;
  26860. stackClean = true;
  26861. break;
  26862. case 3: // vstem
  26863. stems += stack.length >> 1;
  26864. stackClean = true;
  26865. break;
  26866. case 4: // vmoveto
  26867. y += stack.pop();
  26868. moveTo(x, y);
  26869. stackClean = true;
  26870. break;
  26871. case 5: // rlineto
  26872. while (stack.length > 0) {
  26873. x += stack.shift();
  26874. y += stack.shift();
  26875. lineTo(x, y);
  26876. }
  26877. break;
  26878. case 6: // hlineto
  26879. while (stack.length > 0) {
  26880. x += stack.shift();
  26881. lineTo(x, y);
  26882. if (stack.length === 0) {
  26883. break;
  26884. }
  26885. y += stack.shift();
  26886. lineTo(x, y);
  26887. }
  26888. break;
  26889. case 7: // vlineto
  26890. while (stack.length > 0) {
  26891. y += stack.shift();
  26892. lineTo(x, y);
  26893. if (stack.length === 0) {
  26894. break;
  26895. }
  26896. x += stack.shift();
  26897. lineTo(x, y);
  26898. }
  26899. break;
  26900. case 8: // rrcurveto
  26901. while (stack.length > 0) {
  26902. xa = x + stack.shift(); ya = y + stack.shift();
  26903. xb = xa + stack.shift(); yb = ya + stack.shift();
  26904. x = xb + stack.shift(); y = yb + stack.shift();
  26905. bezierCurveTo(xa, ya, xb, yb, x, y);
  26906. }
  26907. break;
  26908. case 10: // callsubr
  26909. n = stack.pop() + font.subrsBias;
  26910. subrCode = font.subrs[n];
  26911. if (subrCode) {
  26912. parse(subrCode);
  26913. }
  26914. break;
  26915. case 11: // return
  26916. return;
  26917. case 12:
  26918. v = code[i++];
  26919. switch (v) {
  26920. case 34: // flex
  26921. xa = x + stack.shift();
  26922. xb = xa + stack.shift(); y1 = y + stack.shift();
  26923. x = xb + stack.shift();
  26924. bezierCurveTo(xa, y, xb, y1, x, y1);
  26925. xa = x + stack.shift();
  26926. xb = xa + stack.shift();
  26927. x = xb + stack.shift();
  26928. bezierCurveTo(xa, y1, xb, y, x, y);
  26929. break;
  26930. case 35: // flex
  26931. xa = x + stack.shift(); ya = y + stack.shift();
  26932. xb = xa + stack.shift(); yb = ya + stack.shift();
  26933. x = xb + stack.shift(); y = yb + stack.shift();
  26934. bezierCurveTo(xa, ya, xb, yb, x, y);
  26935. xa = x + stack.shift(); ya = y + stack.shift();
  26936. xb = xa + stack.shift(); yb = ya + stack.shift();
  26937. x = xb + stack.shift(); y = yb + stack.shift();
  26938. bezierCurveTo(xa, ya, xb, yb, x, y);
  26939. stack.pop(); // fd
  26940. break;
  26941. case 36: // hflex1
  26942. xa = x + stack.shift(); y1 = y + stack.shift();
  26943. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26944. x = xb + stack.shift();
  26945. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26946. xa = x + stack.shift();
  26947. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26948. x = xb + stack.shift();
  26949. bezierCurveTo(xa, y2, xb, y3, x, y);
  26950. break;
  26951. case 37: // flex1
  26952. var x0 = x, y0 = y;
  26953. xa = x + stack.shift(); ya = y + stack.shift();
  26954. xb = xa + stack.shift(); yb = ya + stack.shift();
  26955. x = xb + stack.shift(); y = yb + stack.shift();
  26956. bezierCurveTo(xa, ya, xb, yb, x, y);
  26957. xa = x + stack.shift(); ya = y + stack.shift();
  26958. xb = xa + stack.shift(); yb = ya + stack.shift();
  26959. x = xb; y = yb;
  26960. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  26961. x += stack.shift();
  26962. } else {
  26963. y += stack.shift();
  26964. }
  26965. bezierCurveTo(xa, ya, xb, yb, x, y);
  26966. break;
  26967. default:
  26968. error('unknown operator: 12 ' + v);
  26969. }
  26970. break;
  26971. case 14: // endchar
  26972. if (stack.length >= 4) {
  26973. var achar = stack.pop();
  26974. var bchar = stack.pop();
  26975. y = stack.pop();
  26976. x = stack.pop();
  26977. cmds.push({cmd: 'save'});
  26978. cmds.push({cmd: 'translate', args: [x, y]});
  26979. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  26980. font.glyphNameMap[StandardEncoding[achar]]));
  26981. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  26982. cmds.push({cmd: 'restore'});
  26983. cmap = lookupCmap(font.cmap, String.fromCharCode(
  26984. font.glyphNameMap[StandardEncoding[bchar]]));
  26985. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  26986. }
  26987. return;
  26988. case 18: // hstemhm
  26989. stems += stack.length >> 1;
  26990. stackClean = true;
  26991. break;
  26992. case 19: // hintmask
  26993. stems += stack.length >> 1;
  26994. i += (stems + 7) >> 3;
  26995. stackClean = true;
  26996. break;
  26997. case 20: // cntrmask
  26998. stems += stack.length >> 1;
  26999. i += (stems + 7) >> 3;
  27000. stackClean = true;
  27001. break;
  27002. case 21: // rmoveto
  27003. y += stack.pop();
  27004. x += stack.pop();
  27005. moveTo(x, y);
  27006. stackClean = true;
  27007. break;
  27008. case 22: // hmoveto
  27009. x += stack.pop();
  27010. moveTo(x, y);
  27011. stackClean = true;
  27012. break;
  27013. case 23: // vstemhm
  27014. stems += stack.length >> 1;
  27015. stackClean = true;
  27016. break;
  27017. case 24: // rcurveline
  27018. while (stack.length > 2) {
  27019. xa = x + stack.shift(); ya = y + stack.shift();
  27020. xb = xa + stack.shift(); yb = ya + stack.shift();
  27021. x = xb + stack.shift(); y = yb + stack.shift();
  27022. bezierCurveTo(xa, ya, xb, yb, x, y);
  27023. }
  27024. x += stack.shift();
  27025. y += stack.shift();
  27026. lineTo(x, y);
  27027. break;
  27028. case 25: // rlinecurve
  27029. while (stack.length > 6) {
  27030. x += stack.shift();
  27031. y += stack.shift();
  27032. lineTo(x, y);
  27033. }
  27034. xa = x + stack.shift(); ya = y + stack.shift();
  27035. xb = xa + stack.shift(); yb = ya + stack.shift();
  27036. x = xb + stack.shift(); y = yb + stack.shift();
  27037. bezierCurveTo(xa, ya, xb, yb, x, y);
  27038. break;
  27039. case 26: // vvcurveto
  27040. if (stack.length % 2) {
  27041. x += stack.shift();
  27042. }
  27043. while (stack.length > 0) {
  27044. xa = x; ya = y + stack.shift();
  27045. xb = xa + stack.shift(); yb = ya + stack.shift();
  27046. x = xb; y = yb + stack.shift();
  27047. bezierCurveTo(xa, ya, xb, yb, x, y);
  27048. }
  27049. break;
  27050. case 27: // hhcurveto
  27051. if (stack.length % 2) {
  27052. y += stack.shift();
  27053. }
  27054. while (stack.length > 0) {
  27055. xa = x + stack.shift(); ya = y;
  27056. xb = xa + stack.shift(); yb = ya + stack.shift();
  27057. x = xb + stack.shift(); y = yb;
  27058. bezierCurveTo(xa, ya, xb, yb, x, y);
  27059. }
  27060. break;
  27061. case 28:
  27062. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  27063. i += 2;
  27064. break;
  27065. case 29: // callgsubr
  27066. n = stack.pop() + font.gsubrsBias;
  27067. subrCode = font.gsubrs[n];
  27068. if (subrCode) {
  27069. parse(subrCode);
  27070. }
  27071. break;
  27072. case 30: // vhcurveto
  27073. while (stack.length > 0) {
  27074. xa = x; ya = y + stack.shift();
  27075. xb = xa + stack.shift(); yb = ya + stack.shift();
  27076. x = xb + stack.shift();
  27077. y = yb + (stack.length === 1 ? stack.shift() : 0);
  27078. bezierCurveTo(xa, ya, xb, yb, x, y);
  27079. if (stack.length === 0) {
  27080. break;
  27081. }
  27082. xa = x + stack.shift(); ya = y;
  27083. xb = xa + stack.shift(); yb = ya + stack.shift();
  27084. y = yb + stack.shift();
  27085. x = xb + (stack.length === 1 ? stack.shift() : 0);
  27086. bezierCurveTo(xa, ya, xb, yb, x, y);
  27087. }
  27088. break;
  27089. case 31: // hvcurveto
  27090. while (stack.length > 0) {
  27091. xa = x + stack.shift(); ya = y;
  27092. xb = xa + stack.shift(); yb = ya + stack.shift();
  27093. y = yb + stack.shift();
  27094. x = xb + (stack.length === 1 ? stack.shift() : 0);
  27095. bezierCurveTo(xa, ya, xb, yb, x, y);
  27096. if (stack.length === 0) {
  27097. break;
  27098. }
  27099. xa = x; ya = y + stack.shift();
  27100. xb = xa + stack.shift(); yb = ya + stack.shift();
  27101. x = xb + stack.shift();
  27102. y = yb + (stack.length === 1 ? stack.shift() : 0);
  27103. bezierCurveTo(xa, ya, xb, yb, x, y);
  27104. }
  27105. break;
  27106. default:
  27107. if (v < 32) {
  27108. error('unknown operator: ' + v);
  27109. }
  27110. if (v < 247) {
  27111. stack.push(v - 139);
  27112. } else if (v < 251) {
  27113. stack.push((v - 247) * 256 + code[i++] + 108);
  27114. } else if (v < 255) {
  27115. stack.push(-(v - 251) * 256 - code[i++] - 108);
  27116. } else {
  27117. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  27118. (code[i + 2] << 8) | code[i + 3]) / 65536);
  27119. i += 4;
  27120. }
  27121. break;
  27122. }
  27123. if (stackClean) {
  27124. stack.length = 0;
  27125. }
  27126. }
  27127. }
  27128. parse(code);
  27129. }
  27130. var noop = '';
  27131. function CompiledFont(fontMatrix) {
  27132. this.compiledGlyphs = Object.create(null);
  27133. this.compiledCharCodeToGlyphId = Object.create(null);
  27134. this.fontMatrix = fontMatrix;
  27135. }
  27136. CompiledFont.prototype = {
  27137. getPathJs: function (unicode) {
  27138. var cmap = lookupCmap(this.cmap, unicode);
  27139. var fn = this.compiledGlyphs[cmap.glyphId];
  27140. if (!fn) {
  27141. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  27142. this.compiledGlyphs[cmap.glyphId] = fn;
  27143. }
  27144. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  27145. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  27146. }
  27147. return fn;
  27148. },
  27149. compileGlyph: function (code) {
  27150. if (!code || code.length === 0 || code[0] === 14) {
  27151. return noop;
  27152. }
  27153. var cmds = [];
  27154. cmds.push({cmd: 'save'});
  27155. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  27156. cmds.push({cmd: 'scale', args: ['size', '-size']});
  27157. this.compileGlyphImpl(code, cmds);
  27158. cmds.push({cmd: 'restore'});
  27159. return cmds;
  27160. },
  27161. compileGlyphImpl: function () {
  27162. error('Children classes should implement this.');
  27163. },
  27164. hasBuiltPath: function (unicode) {
  27165. var cmap = lookupCmap(this.cmap, unicode);
  27166. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  27167. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  27168. }
  27169. };
  27170. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  27171. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  27172. CompiledFont.call(this, fontMatrix);
  27173. this.glyphs = glyphs;
  27174. this.cmap = cmap;
  27175. }
  27176. Util.inherit(TrueTypeCompiled, CompiledFont, {
  27177. compileGlyphImpl: function (code, cmds) {
  27178. compileGlyf(code, cmds, this);
  27179. }
  27180. });
  27181. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  27182. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  27183. CompiledFont.call(this, fontMatrix);
  27184. this.glyphs = cffInfo.glyphs;
  27185. this.gsubrs = cffInfo.gsubrs || [];
  27186. this.subrs = cffInfo.subrs || [];
  27187. this.cmap = cmap;
  27188. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  27189. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  27190. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  27191. this.subrsBias = (this.subrs.length < 1240 ?
  27192. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  27193. }
  27194. Util.inherit(Type2Compiled, CompiledFont, {
  27195. compileGlyphImpl: function (code, cmds) {
  27196. compileCharString(code, cmds, this);
  27197. }
  27198. });
  27199. return {
  27200. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  27201. var data = new Uint8Array(font.data);
  27202. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  27203. var numTables = getUshort(data, 4);
  27204. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  27205. var tag = bytesToString(data.subarray(p, p + 4));
  27206. var offset = getLong(data, p + 8);
  27207. var length = getLong(data, p + 12);
  27208. switch (tag) {
  27209. case 'cmap':
  27210. cmap = parseCmap(data, offset, offset + length);
  27211. break;
  27212. case 'glyf':
  27213. glyf = data.subarray(offset, offset + length);
  27214. break;
  27215. case 'loca':
  27216. loca = data.subarray(offset, offset + length);
  27217. break;
  27218. case 'head':
  27219. unitsPerEm = getUshort(data, offset + 18);
  27220. indexToLocFormat = getUshort(data, offset + 50);
  27221. break;
  27222. case 'CFF ':
  27223. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  27224. break;
  27225. }
  27226. }
  27227. if (glyf) {
  27228. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  27229. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  27230. return new TrueTypeCompiled(
  27231. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  27232. } else {
  27233. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  27234. }
  27235. }
  27236. };
  27237. })();
  27238. exports.FontRendererFactory = FontRendererFactory;
  27239. }));
  27240. (function (root, factory) {
  27241. {
  27242. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  27243. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  27244. }
  27245. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  27246. var MissingDataException = sharedUtil.MissingDataException;
  27247. var StreamType = sharedUtil.StreamType;
  27248. var assert = sharedUtil.assert;
  27249. var error = sharedUtil.error;
  27250. var info = sharedUtil.info;
  27251. var isArray = sharedUtil.isArray;
  27252. var isInt = sharedUtil.isInt;
  27253. var isNum = sharedUtil.isNum;
  27254. var isString = sharedUtil.isString;
  27255. var warn = sharedUtil.warn;
  27256. var Cmd = corePrimitives.Cmd;
  27257. var Dict = corePrimitives.Dict;
  27258. var Name = corePrimitives.Name;
  27259. var Ref = corePrimitives.Ref;
  27260. var isCmd = corePrimitives.isCmd;
  27261. var isDict = corePrimitives.isDict;
  27262. var isName = corePrimitives.isName;
  27263. var Ascii85Stream = coreStream.Ascii85Stream;
  27264. var AsciiHexStream = coreStream.AsciiHexStream;
  27265. var CCITTFaxStream = coreStream.CCITTFaxStream;
  27266. var FlateStream = coreStream.FlateStream;
  27267. var Jbig2Stream = coreStream.Jbig2Stream;
  27268. var JpegStream = coreStream.JpegStream;
  27269. var JpxStream = coreStream.JpxStream;
  27270. var LZWStream = coreStream.LZWStream;
  27271. var NullStream = coreStream.NullStream;
  27272. var PredictorStream = coreStream.PredictorStream;
  27273. var RunLengthStream = coreStream.RunLengthStream;
  27274. var EOF = {};
  27275. function isEOF(v) {
  27276. return (v === EOF);
  27277. }
  27278. var MAX_LENGTH_TO_CACHE = 1000;
  27279. var Parser = (function ParserClosure() {
  27280. function Parser(lexer, allowStreams, xref, recoveryMode) {
  27281. this.lexer = lexer;
  27282. this.allowStreams = allowStreams;
  27283. this.xref = xref;
  27284. this.recoveryMode = recoveryMode || false;
  27285. this.imageCache = Object.create(null);
  27286. this.refill();
  27287. }
  27288. Parser.prototype = {
  27289. refill: function Parser_refill() {
  27290. this.buf1 = this.lexer.getObj();
  27291. this.buf2 = this.lexer.getObj();
  27292. },
  27293. shift: function Parser_shift() {
  27294. if (isCmd(this.buf2, 'ID')) {
  27295. this.buf1 = this.buf2;
  27296. this.buf2 = null;
  27297. } else {
  27298. this.buf1 = this.buf2;
  27299. this.buf2 = this.lexer.getObj();
  27300. }
  27301. },
  27302. tryShift: function Parser_tryShift() {
  27303. try {
  27304. this.shift();
  27305. return true;
  27306. } catch (e) {
  27307. if (e instanceof MissingDataException) {
  27308. throw e;
  27309. }
  27310. // Upon failure, the caller should reset this.lexer.pos to a known good
  27311. // state and call this.shift() twice to reset the buffers.
  27312. return false;
  27313. }
  27314. },
  27315. getObj: function Parser_getObj(cipherTransform) {
  27316. var buf1 = this.buf1;
  27317. this.shift();
  27318. if (buf1 instanceof Cmd) {
  27319. switch (buf1.cmd) {
  27320. case 'BI': // inline image
  27321. return this.makeInlineImage(cipherTransform);
  27322. case '[': // array
  27323. var array = [];
  27324. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  27325. array.push(this.getObj(cipherTransform));
  27326. }
  27327. if (isEOF(this.buf1)) {
  27328. if (!this.recoveryMode) {
  27329. error('End of file inside array');
  27330. }
  27331. return array;
  27332. }
  27333. this.shift();
  27334. return array;
  27335. case '<<': // dictionary or stream
  27336. var dict = new Dict(this.xref);
  27337. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  27338. if (!isName(this.buf1)) {
  27339. info('Malformed dictionary: key must be a name object');
  27340. this.shift();
  27341. continue;
  27342. }
  27343. var key = this.buf1.name;
  27344. this.shift();
  27345. if (isEOF(this.buf1)) {
  27346. break;
  27347. }
  27348. dict.set(key, this.getObj(cipherTransform));
  27349. }
  27350. if (isEOF(this.buf1)) {
  27351. if (!this.recoveryMode) {
  27352. error('End of file inside dictionary');
  27353. }
  27354. return dict;
  27355. }
  27356. // Stream objects are not allowed inside content streams or
  27357. // object streams.
  27358. if (isCmd(this.buf2, 'stream')) {
  27359. return (this.allowStreams ?
  27360. this.makeStream(dict, cipherTransform) : dict);
  27361. }
  27362. this.shift();
  27363. return dict;
  27364. default: // simple object
  27365. return buf1;
  27366. }
  27367. }
  27368. if (isInt(buf1)) { // indirect reference or integer
  27369. var num = buf1;
  27370. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  27371. var ref = new Ref(num, this.buf1);
  27372. this.shift();
  27373. this.shift();
  27374. return ref;
  27375. }
  27376. return num;
  27377. }
  27378. if (isString(buf1)) { // string
  27379. var str = buf1;
  27380. if (cipherTransform) {
  27381. str = cipherTransform.decryptString(str);
  27382. }
  27383. return str;
  27384. }
  27385. // simple object
  27386. return buf1;
  27387. },
  27388. /**
  27389. * Find the end of the stream by searching for the /EI\s/.
  27390. * @returns {number} The inline stream length.
  27391. */
  27392. findDefaultInlineStreamEnd:
  27393. function Parser_findDefaultInlineStreamEnd(stream) {
  27394. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  27395. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  27396. while ((ch = stream.getByte()) !== -1) {
  27397. if (state === 0) {
  27398. state = (ch === E) ? 1 : 0;
  27399. } else if (state === 1) {
  27400. state = (ch === I) ? 2 : 0;
  27401. } else {
  27402. assert(state === 2);
  27403. if (ch === SPACE || ch === LF || ch === CR) {
  27404. // Let's check the next five bytes are ASCII... just be sure.
  27405. n = 5;
  27406. followingBytes = stream.peekBytes(n);
  27407. for (i = 0; i < n; i++) {
  27408. ch = followingBytes[i];
  27409. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  27410. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  27411. // it's binary stuff. Resetting the state.
  27412. state = 0;
  27413. break;
  27414. }
  27415. }
  27416. if (state === 2) {
  27417. break; // Finished!
  27418. }
  27419. } else {
  27420. state = 0;
  27421. }
  27422. }
  27423. }
  27424. return ((stream.pos - 4) - startPos);
  27425. },
  27426. /**
  27427. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  27428. * @returns {number} The inline stream length.
  27429. */
  27430. findDCTDecodeInlineStreamEnd:
  27431. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  27432. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  27433. while ((b = stream.getByte()) !== -1) {
  27434. if (b !== 0xFF) { // Not a valid marker.
  27435. continue;
  27436. }
  27437. switch (stream.getByte()) {
  27438. case 0x00: // Byte stuffing.
  27439. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  27440. break;
  27441. case 0xFF: // Fill byte.
  27442. // Avoid skipping a valid marker, resetting the stream position.
  27443. stream.skip(-1);
  27444. break;
  27445. case 0xD9: // EOI
  27446. foundEOI = true;
  27447. break;
  27448. case 0xC0: // SOF0
  27449. case 0xC1: // SOF1
  27450. case 0xC2: // SOF2
  27451. case 0xC3: // SOF3
  27452. case 0xC5: // SOF5
  27453. case 0xC6: // SOF6
  27454. case 0xC7: // SOF7
  27455. case 0xC9: // SOF9
  27456. case 0xCA: // SOF10
  27457. case 0xCB: // SOF11
  27458. case 0xCD: // SOF13
  27459. case 0xCE: // SOF14
  27460. case 0xCF: // SOF15
  27461. case 0xC4: // DHT
  27462. case 0xCC: // DAC
  27463. case 0xDA: // SOS
  27464. case 0xDB: // DQT
  27465. case 0xDC: // DNL
  27466. case 0xDD: // DRI
  27467. case 0xDE: // DHP
  27468. case 0xDF: // EXP
  27469. case 0xE0: // APP0
  27470. case 0xE1: // APP1
  27471. case 0xE2: // APP2
  27472. case 0xE3: // APP3
  27473. case 0xE4: // APP4
  27474. case 0xE5: // APP5
  27475. case 0xE6: // APP6
  27476. case 0xE7: // APP7
  27477. case 0xE8: // APP8
  27478. case 0xE9: // APP9
  27479. case 0xEA: // APP10
  27480. case 0xEB: // APP11
  27481. case 0xEC: // APP12
  27482. case 0xED: // APP13
  27483. case 0xEE: // APP14
  27484. case 0xEF: // APP15
  27485. case 0xFE: // COM
  27486. // The marker should be followed by the length of the segment.
  27487. markerLength = stream.getUint16();
  27488. if (markerLength > 2) {
  27489. // |markerLength| contains the byte length of the marker segment,
  27490. // including its own length (2 bytes) and excluding the marker.
  27491. stream.skip(markerLength - 2); // Jump to the next marker.
  27492. } else {
  27493. // The marker length is invalid, resetting the stream position.
  27494. stream.skip(-2);
  27495. }
  27496. break;
  27497. }
  27498. if (foundEOI) {
  27499. break;
  27500. }
  27501. }
  27502. length = stream.pos - startPos;
  27503. if (b === -1) {
  27504. warn('Inline DCTDecode image stream: ' +
  27505. 'EOI marker not found, searching for /EI/ instead.');
  27506. stream.skip(-length); // Reset the stream position.
  27507. return this.findDefaultInlineStreamEnd(stream);
  27508. }
  27509. this.inlineStreamSkipEI(stream);
  27510. return length;
  27511. },
  27512. /**
  27513. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  27514. * @returns {number} The inline stream length.
  27515. */
  27516. findASCII85DecodeInlineStreamEnd:
  27517. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  27518. var TILDE = 0x7E, GT = 0x3E;
  27519. var startPos = stream.pos, ch, length;
  27520. while ((ch = stream.getByte()) !== -1) {
  27521. if (ch === TILDE && stream.peekByte() === GT) {
  27522. stream.skip();
  27523. break;
  27524. }
  27525. }
  27526. length = stream.pos - startPos;
  27527. if (ch === -1) {
  27528. warn('Inline ASCII85Decode image stream: ' +
  27529. 'EOD marker not found, searching for /EI/ instead.');
  27530. stream.skip(-length); // Reset the stream position.
  27531. return this.findDefaultInlineStreamEnd(stream);
  27532. }
  27533. this.inlineStreamSkipEI(stream);
  27534. return length;
  27535. },
  27536. /**
  27537. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  27538. * @returns {number} The inline stream length.
  27539. */
  27540. findASCIIHexDecodeInlineStreamEnd:
  27541. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  27542. var GT = 0x3E;
  27543. var startPos = stream.pos, ch, length;
  27544. while ((ch = stream.getByte()) !== -1) {
  27545. if (ch === GT) {
  27546. break;
  27547. }
  27548. }
  27549. length = stream.pos - startPos;
  27550. if (ch === -1) {
  27551. warn('Inline ASCIIHexDecode image stream: ' +
  27552. 'EOD marker not found, searching for /EI/ instead.');
  27553. stream.skip(-length); // Reset the stream position.
  27554. return this.findDefaultInlineStreamEnd(stream);
  27555. }
  27556. this.inlineStreamSkipEI(stream);
  27557. return length;
  27558. },
  27559. /**
  27560. * Skip over the /EI/ for streams where we search for an EOD marker.
  27561. */
  27562. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  27563. var E = 0x45, I = 0x49;
  27564. var state = 0, ch;
  27565. while ((ch = stream.getByte()) !== -1) {
  27566. if (state === 0) {
  27567. state = (ch === E) ? 1 : 0;
  27568. } else if (state === 1) {
  27569. state = (ch === I) ? 2 : 0;
  27570. } else if (state === 2) {
  27571. break;
  27572. }
  27573. }
  27574. },
  27575. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27576. var lexer = this.lexer;
  27577. var stream = lexer.stream;
  27578. // Parse dictionary.
  27579. var dict = new Dict(this.xref);
  27580. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27581. if (!isName(this.buf1)) {
  27582. error('Dictionary key must be a name object');
  27583. }
  27584. var key = this.buf1.name;
  27585. this.shift();
  27586. if (isEOF(this.buf1)) {
  27587. break;
  27588. }
  27589. dict.set(key, this.getObj(cipherTransform));
  27590. }
  27591. // Extract the name of the first (i.e. the current) image filter.
  27592. var filter = dict.get('Filter', 'F'), filterName;
  27593. if (isName(filter)) {
  27594. filterName = filter.name;
  27595. } else if (isArray(filter) && isName(filter[0])) {
  27596. filterName = filter[0].name;
  27597. }
  27598. // Parse image stream.
  27599. var startPos = stream.pos, length, i, ii;
  27600. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  27601. length = this.findDCTDecodeInlineStreamEnd(stream);
  27602. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  27603. length = this.findASCII85DecodeInlineStreamEnd(stream);
  27604. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  27605. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  27606. } else {
  27607. length = this.findDefaultInlineStreamEnd(stream);
  27608. }
  27609. var imageStream = stream.makeSubStream(startPos, length, dict);
  27610. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  27611. // adler32 checksum.
  27612. var adler32;
  27613. if (length < MAX_LENGTH_TO_CACHE) {
  27614. var imageBytes = imageStream.getBytes();
  27615. imageStream.reset();
  27616. var a = 1;
  27617. var b = 0;
  27618. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27619. // No modulo required in the loop if imageBytes.length < 5552.
  27620. a += imageBytes[i] & 0xff;
  27621. b += a;
  27622. }
  27623. adler32 = ((b % 65521) << 16) | (a % 65521);
  27624. if (this.imageCache.adler32 === adler32) {
  27625. this.buf2 = Cmd.get('EI');
  27626. this.shift();
  27627. this.imageCache[adler32].reset();
  27628. return this.imageCache[adler32];
  27629. }
  27630. }
  27631. if (cipherTransform) {
  27632. imageStream = cipherTransform.createStream(imageStream, length);
  27633. }
  27634. imageStream = this.filter(imageStream, dict, length);
  27635. imageStream.dict = dict;
  27636. if (adler32 !== undefined) {
  27637. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27638. this.imageCache[adler32] = imageStream;
  27639. }
  27640. this.buf2 = Cmd.get('EI');
  27641. this.shift();
  27642. return imageStream;
  27643. },
  27644. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27645. var lexer = this.lexer;
  27646. var stream = lexer.stream;
  27647. // get stream start position
  27648. lexer.skipToNextLine();
  27649. var pos = stream.pos - 1;
  27650. // get length
  27651. var length = dict.get('Length');
  27652. if (!isInt(length)) {
  27653. info('Bad ' + length + ' attribute in stream');
  27654. length = 0;
  27655. }
  27656. // skip over the stream data
  27657. stream.pos = pos + length;
  27658. lexer.nextChar();
  27659. // Shift '>>' and check whether the new object marks the end of the stream
  27660. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  27661. this.shift(); // 'stream'
  27662. } else {
  27663. // bad stream length, scanning for endstream
  27664. stream.pos = pos;
  27665. var SCAN_BLOCK_SIZE = 2048;
  27666. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27667. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27668. 0x61, 0x6D];
  27669. var skipped = 0, found = false, i, j;
  27670. while (stream.pos < stream.end) {
  27671. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27672. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27673. if (scanLength <= 0) {
  27674. break;
  27675. }
  27676. found = false;
  27677. i = 0;
  27678. while (i < scanLength) {
  27679. j = 0;
  27680. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  27681. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  27682. j++;
  27683. }
  27684. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27685. found = true;
  27686. break;
  27687. }
  27688. i++;
  27689. }
  27690. if (found) {
  27691. skipped += i;
  27692. stream.pos += i;
  27693. break;
  27694. }
  27695. skipped += scanLength;
  27696. stream.pos += scanLength;
  27697. }
  27698. if (!found) {
  27699. error('Missing endstream');
  27700. }
  27701. length = skipped;
  27702. lexer.nextChar();
  27703. this.shift();
  27704. this.shift();
  27705. }
  27706. this.shift(); // 'endstream'
  27707. stream = stream.makeSubStream(pos, length, dict);
  27708. if (cipherTransform) {
  27709. stream = cipherTransform.createStream(stream, length);
  27710. }
  27711. stream = this.filter(stream, dict, length);
  27712. stream.dict = dict;
  27713. return stream;
  27714. },
  27715. filter: function Parser_filter(stream, dict, length) {
  27716. var filter = dict.get('Filter', 'F');
  27717. var params = dict.get('DecodeParms', 'DP');
  27718. if (isName(filter)) {
  27719. return this.makeFilter(stream, filter.name, length, params);
  27720. }
  27721. var maybeLength = length;
  27722. if (isArray(filter)) {
  27723. var filterArray = filter;
  27724. var paramsArray = params;
  27725. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  27726. filter = filterArray[i];
  27727. if (!isName(filter)) {
  27728. error('Bad filter name: ' + filter);
  27729. }
  27730. params = null;
  27731. if (isArray(paramsArray) && (i in paramsArray)) {
  27732. params = paramsArray[i];
  27733. }
  27734. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  27735. // after the first stream the length variable is invalid
  27736. maybeLength = null;
  27737. }
  27738. }
  27739. return stream;
  27740. },
  27741. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  27742. if (stream.dict.get('Length') === 0 && !maybeLength) {
  27743. warn('Empty "' + name + '" stream.');
  27744. return new NullStream(stream);
  27745. }
  27746. try {
  27747. if (params && this.xref) {
  27748. params = this.xref.fetchIfRef(params);
  27749. }
  27750. var xrefStreamStats = this.xref.stats.streamTypes;
  27751. if (name === 'FlateDecode' || name === 'Fl') {
  27752. xrefStreamStats[StreamType.FLATE] = true;
  27753. if (params) {
  27754. return new PredictorStream(new FlateStream(stream, maybeLength),
  27755. maybeLength, params);
  27756. }
  27757. return new FlateStream(stream, maybeLength);
  27758. }
  27759. if (name === 'LZWDecode' || name === 'LZW') {
  27760. xrefStreamStats[StreamType.LZW] = true;
  27761. var earlyChange = 1;
  27762. if (params) {
  27763. if (params.has('EarlyChange')) {
  27764. earlyChange = params.get('EarlyChange');
  27765. }
  27766. return new PredictorStream(
  27767. new LZWStream(stream, maybeLength, earlyChange),
  27768. maybeLength, params);
  27769. }
  27770. return new LZWStream(stream, maybeLength, earlyChange);
  27771. }
  27772. if (name === 'DCTDecode' || name === 'DCT') {
  27773. xrefStreamStats[StreamType.DCT] = true;
  27774. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  27775. }
  27776. if (name === 'JPXDecode' || name === 'JPX') {
  27777. xrefStreamStats[StreamType.JPX] = true;
  27778. return new JpxStream(stream, maybeLength, stream.dict);
  27779. }
  27780. if (name === 'ASCII85Decode' || name === 'A85') {
  27781. xrefStreamStats[StreamType.A85] = true;
  27782. return new Ascii85Stream(stream, maybeLength);
  27783. }
  27784. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  27785. xrefStreamStats[StreamType.AHX] = true;
  27786. return new AsciiHexStream(stream, maybeLength);
  27787. }
  27788. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  27789. xrefStreamStats[StreamType.CCF] = true;
  27790. return new CCITTFaxStream(stream, maybeLength, params);
  27791. }
  27792. if (name === 'RunLengthDecode' || name === 'RL') {
  27793. xrefStreamStats[StreamType.RL] = true;
  27794. return new RunLengthStream(stream, maybeLength);
  27795. }
  27796. if (name === 'JBIG2Decode') {
  27797. xrefStreamStats[StreamType.JBIG] = true;
  27798. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27799. }
  27800. warn('filter "' + name + '" not supported yet');
  27801. return stream;
  27802. } catch (ex) {
  27803. if (ex instanceof MissingDataException) {
  27804. throw ex;
  27805. }
  27806. warn('Invalid stream: \"' + ex + '\"');
  27807. return new NullStream(stream);
  27808. }
  27809. }
  27810. };
  27811. return Parser;
  27812. })();
  27813. var Lexer = (function LexerClosure() {
  27814. function Lexer(stream, knownCommands) {
  27815. this.stream = stream;
  27816. this.nextChar();
  27817. // While lexing, we build up many strings one char at a time. Using += for
  27818. // this can result in lots of garbage strings. It's better to build an
  27819. // array of single-char strings and then join() them together at the end.
  27820. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27821. // purpose uses less memory than using a new array for each string.
  27822. this.strBuf = [];
  27823. // The PDFs might have "glued" commands with other commands, operands or
  27824. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27825. // commands and their prefixes. The prefixes are built the following way:
  27826. // if there a command that is a prefix of the other valid command or
  27827. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27828. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27829. // other commands or literals as a prefix. The knowCommands is optional.
  27830. this.knownCommands = knownCommands;
  27831. }
  27832. // A '1' in this array means the character is white space. A '1' or
  27833. // '2' means the character ends a name or command.
  27834. var specialChars = [
  27835. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27837. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27851. ];
  27852. function toHexDigit(ch) {
  27853. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27854. return ch & 0x0F;
  27855. }
  27856. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27857. // 'A'-'F', 'a'-'f'
  27858. return (ch & 0x0F) + 9;
  27859. }
  27860. return -1;
  27861. }
  27862. Lexer.prototype = {
  27863. nextChar: function Lexer_nextChar() {
  27864. return (this.currentChar = this.stream.getByte());
  27865. },
  27866. peekChar: function Lexer_peekChar() {
  27867. return this.stream.peekByte();
  27868. },
  27869. getNumber: function Lexer_getNumber() {
  27870. var ch = this.currentChar;
  27871. var eNotation = false;
  27872. var divideBy = 0; // different from 0 if it's a floating point value
  27873. var sign = 1;
  27874. if (ch === 0x2D) { // '-'
  27875. sign = -1;
  27876. ch = this.nextChar();
  27877. if (ch === 0x2D) { // '-'
  27878. // Ignore double negative (this is consistent with Adobe Reader).
  27879. ch = this.nextChar();
  27880. }
  27881. } else if (ch === 0x2B) { // '+'
  27882. ch = this.nextChar();
  27883. }
  27884. if (ch === 0x2E) { // '.'
  27885. divideBy = 10;
  27886. ch = this.nextChar();
  27887. }
  27888. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27889. error('Invalid number: ' + String.fromCharCode(ch));
  27890. return 0;
  27891. }
  27892. var baseValue = ch - 0x30; // '0'
  27893. var powerValue = 0;
  27894. var powerValueSign = 1;
  27895. while ((ch = this.nextChar()) >= 0) {
  27896. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27897. var currentDigit = ch - 0x30; // '0'
  27898. if (eNotation) { // We are after an 'e' or 'E'
  27899. powerValue = powerValue * 10 + currentDigit;
  27900. } else {
  27901. if (divideBy !== 0) { // We are after a point
  27902. divideBy *= 10;
  27903. }
  27904. baseValue = baseValue * 10 + currentDigit;
  27905. }
  27906. } else if (ch === 0x2E) { // '.'
  27907. if (divideBy === 0) {
  27908. divideBy = 1;
  27909. } else {
  27910. // A number can have only one '.'
  27911. break;
  27912. }
  27913. } else if (ch === 0x2D) { // '-'
  27914. // ignore minus signs in the middle of numbers to match
  27915. // Adobe's behavior
  27916. warn('Badly formatted number');
  27917. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27918. // 'E' can be either a scientific notation or the beginning of a new
  27919. // operator
  27920. ch = this.peekChar();
  27921. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27922. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27923. this.nextChar(); // Consume the sign character
  27924. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27925. // The 'E' must be the beginning of a new operator
  27926. break;
  27927. }
  27928. eNotation = true;
  27929. } else {
  27930. // the last character doesn't belong to us
  27931. break;
  27932. }
  27933. }
  27934. if (divideBy !== 0) {
  27935. baseValue /= divideBy;
  27936. }
  27937. if (eNotation) {
  27938. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27939. }
  27940. return sign * baseValue;
  27941. },
  27942. getString: function Lexer_getString() {
  27943. var numParen = 1;
  27944. var done = false;
  27945. var strBuf = this.strBuf;
  27946. strBuf.length = 0;
  27947. var ch = this.nextChar();
  27948. while (true) {
  27949. var charBuffered = false;
  27950. switch (ch | 0) {
  27951. case -1:
  27952. warn('Unterminated string');
  27953. done = true;
  27954. break;
  27955. case 0x28: // '('
  27956. ++numParen;
  27957. strBuf.push('(');
  27958. break;
  27959. case 0x29: // ')'
  27960. if (--numParen === 0) {
  27961. this.nextChar(); // consume strings ')'
  27962. done = true;
  27963. } else {
  27964. strBuf.push(')');
  27965. }
  27966. break;
  27967. case 0x5C: // '\\'
  27968. ch = this.nextChar();
  27969. switch (ch) {
  27970. case -1:
  27971. warn('Unterminated string');
  27972. done = true;
  27973. break;
  27974. case 0x6E: // 'n'
  27975. strBuf.push('\n');
  27976. break;
  27977. case 0x72: // 'r'
  27978. strBuf.push('\r');
  27979. break;
  27980. case 0x74: // 't'
  27981. strBuf.push('\t');
  27982. break;
  27983. case 0x62: // 'b'
  27984. strBuf.push('\b');
  27985. break;
  27986. case 0x66: // 'f'
  27987. strBuf.push('\f');
  27988. break;
  27989. case 0x5C: // '\'
  27990. case 0x28: // '('
  27991. case 0x29: // ')'
  27992. strBuf.push(String.fromCharCode(ch));
  27993. break;
  27994. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  27995. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  27996. var x = ch & 0x0F;
  27997. ch = this.nextChar();
  27998. charBuffered = true;
  27999. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28000. x = (x << 3) + (ch & 0x0F);
  28001. ch = this.nextChar();
  28002. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28003. charBuffered = false;
  28004. x = (x << 3) + (ch & 0x0F);
  28005. }
  28006. }
  28007. strBuf.push(String.fromCharCode(x));
  28008. break;
  28009. case 0x0D: // CR
  28010. if (this.peekChar() === 0x0A) { // LF
  28011. this.nextChar();
  28012. }
  28013. break;
  28014. case 0x0A: // LF
  28015. break;
  28016. default:
  28017. strBuf.push(String.fromCharCode(ch));
  28018. break;
  28019. }
  28020. break;
  28021. default:
  28022. strBuf.push(String.fromCharCode(ch));
  28023. break;
  28024. }
  28025. if (done) {
  28026. break;
  28027. }
  28028. if (!charBuffered) {
  28029. ch = this.nextChar();
  28030. }
  28031. }
  28032. return strBuf.join('');
  28033. },
  28034. getName: function Lexer_getName() {
  28035. var ch, previousCh;
  28036. var strBuf = this.strBuf;
  28037. strBuf.length = 0;
  28038. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28039. if (ch === 0x23) { // '#'
  28040. ch = this.nextChar();
  28041. if (specialChars[ch]) {
  28042. warn('Lexer_getName: ' +
  28043. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  28044. strBuf.push('#');
  28045. break;
  28046. }
  28047. var x = toHexDigit(ch);
  28048. if (x !== -1) {
  28049. previousCh = ch;
  28050. ch = this.nextChar();
  28051. var x2 = toHexDigit(ch);
  28052. if (x2 === -1) {
  28053. warn('Lexer_getName: Illegal digit (' +
  28054. String.fromCharCode(ch) +') in hexadecimal number.');
  28055. strBuf.push('#', String.fromCharCode(previousCh));
  28056. if (specialChars[ch]) {
  28057. break;
  28058. }
  28059. strBuf.push(String.fromCharCode(ch));
  28060. continue;
  28061. }
  28062. strBuf.push(String.fromCharCode((x << 4) | x2));
  28063. } else {
  28064. strBuf.push('#', String.fromCharCode(ch));
  28065. }
  28066. } else {
  28067. strBuf.push(String.fromCharCode(ch));
  28068. }
  28069. }
  28070. if (strBuf.length > 127) {
  28071. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  28072. }
  28073. return Name.get(strBuf.join(''));
  28074. },
  28075. getHexString: function Lexer_getHexString() {
  28076. var strBuf = this.strBuf;
  28077. strBuf.length = 0;
  28078. var ch = this.currentChar;
  28079. var isFirstHex = true;
  28080. var firstDigit;
  28081. var secondDigit;
  28082. while (true) {
  28083. if (ch < 0) {
  28084. warn('Unterminated hex string');
  28085. break;
  28086. } else if (ch === 0x3E) { // '>'
  28087. this.nextChar();
  28088. break;
  28089. } else if (specialChars[ch] === 1) {
  28090. ch = this.nextChar();
  28091. continue;
  28092. } else {
  28093. if (isFirstHex) {
  28094. firstDigit = toHexDigit(ch);
  28095. if (firstDigit === -1) {
  28096. warn('Ignoring invalid character "' + ch + '" in hex string');
  28097. ch = this.nextChar();
  28098. continue;
  28099. }
  28100. } else {
  28101. secondDigit = toHexDigit(ch);
  28102. if (secondDigit === -1) {
  28103. warn('Ignoring invalid character "' + ch + '" in hex string');
  28104. ch = this.nextChar();
  28105. continue;
  28106. }
  28107. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28108. }
  28109. isFirstHex = !isFirstHex;
  28110. ch = this.nextChar();
  28111. }
  28112. }
  28113. return strBuf.join('');
  28114. },
  28115. getObj: function Lexer_getObj() {
  28116. // skip whitespace and comments
  28117. var comment = false;
  28118. var ch = this.currentChar;
  28119. while (true) {
  28120. if (ch < 0) {
  28121. return EOF;
  28122. }
  28123. if (comment) {
  28124. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28125. comment = false;
  28126. }
  28127. } else if (ch === 0x25) { // '%'
  28128. comment = true;
  28129. } else if (specialChars[ch] !== 1) {
  28130. break;
  28131. }
  28132. ch = this.nextChar();
  28133. }
  28134. // start reading token
  28135. switch (ch | 0) {
  28136. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28137. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28138. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28139. return this.getNumber();
  28140. case 0x28: // '('
  28141. return this.getString();
  28142. case 0x2F: // '/'
  28143. return this.getName();
  28144. // array punctuation
  28145. case 0x5B: // '['
  28146. this.nextChar();
  28147. return Cmd.get('[');
  28148. case 0x5D: // ']'
  28149. this.nextChar();
  28150. return Cmd.get(']');
  28151. // hex string or dict punctuation
  28152. case 0x3C: // '<'
  28153. ch = this.nextChar();
  28154. if (ch === 0x3C) {
  28155. // dict punctuation
  28156. this.nextChar();
  28157. return Cmd.get('<<');
  28158. }
  28159. return this.getHexString();
  28160. // dict punctuation
  28161. case 0x3E: // '>'
  28162. ch = this.nextChar();
  28163. if (ch === 0x3E) {
  28164. this.nextChar();
  28165. return Cmd.get('>>');
  28166. }
  28167. return Cmd.get('>');
  28168. case 0x7B: // '{'
  28169. this.nextChar();
  28170. return Cmd.get('{');
  28171. case 0x7D: // '}'
  28172. this.nextChar();
  28173. return Cmd.get('}');
  28174. case 0x29: // ')'
  28175. error('Illegal character: ' + ch);
  28176. break;
  28177. }
  28178. // command
  28179. var str = String.fromCharCode(ch);
  28180. var knownCommands = this.knownCommands;
  28181. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28182. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28183. // stop if known command is found and next character does not make
  28184. // the str a command
  28185. var possibleCommand = str + String.fromCharCode(ch);
  28186. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28187. break;
  28188. }
  28189. if (str.length === 128) {
  28190. error('Command token too long: ' + str.length);
  28191. }
  28192. str = possibleCommand;
  28193. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28194. }
  28195. if (str === 'true') {
  28196. return true;
  28197. }
  28198. if (str === 'false') {
  28199. return false;
  28200. }
  28201. if (str === 'null') {
  28202. return null;
  28203. }
  28204. return Cmd.get(str);
  28205. },
  28206. skipToNextLine: function Lexer_skipToNextLine() {
  28207. var ch = this.currentChar;
  28208. while (ch >= 0) {
  28209. if (ch === 0x0D) { // CR
  28210. ch = this.nextChar();
  28211. if (ch === 0x0A) { // LF
  28212. this.nextChar();
  28213. }
  28214. break;
  28215. } else if (ch === 0x0A) { // LF
  28216. this.nextChar();
  28217. break;
  28218. }
  28219. ch = this.nextChar();
  28220. }
  28221. }
  28222. };
  28223. return Lexer;
  28224. })();
  28225. var Linearization = {
  28226. create: function LinearizationCreate(stream) {
  28227. function getInt(name, allowZeroValue) {
  28228. var obj = linDict.get(name);
  28229. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28230. return obj;
  28231. }
  28232. throw new Error('The "' + name + '" parameter in the linearization ' +
  28233. 'dictionary is invalid.');
  28234. }
  28235. function getHints() {
  28236. var hints = linDict.get('H'), hintsLength, item;
  28237. if (isArray(hints) &&
  28238. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28239. for (var index = 0; index < hintsLength; index++) {
  28240. if (!(isInt(item = hints[index]) && item > 0)) {
  28241. throw new Error('Hint (' + index +
  28242. ') in the linearization dictionary is invalid.');
  28243. }
  28244. }
  28245. return hints;
  28246. }
  28247. throw new Error('Hint array in the linearization dictionary is invalid.');
  28248. }
  28249. var parser = new Parser(new Lexer(stream), false, null);
  28250. var obj1 = parser.getObj();
  28251. var obj2 = parser.getObj();
  28252. var obj3 = parser.getObj();
  28253. var linDict = parser.getObj();
  28254. var obj, length;
  28255. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28256. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28257. return null; // No valid linearization dictionary found.
  28258. } else if ((length = getInt('L')) !== stream.length) {
  28259. throw new Error('The "L" parameter in the linearization dictionary ' +
  28260. 'does not equal the stream length.');
  28261. }
  28262. return {
  28263. length: length,
  28264. hints: getHints(),
  28265. objectNumberFirst: getInt('O'),
  28266. endFirst: getInt('E'),
  28267. numPages: getInt('N'),
  28268. mainXRefEntriesOffset: getInt('T'),
  28269. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28270. };
  28271. }
  28272. };
  28273. exports.EOF = EOF;
  28274. exports.Lexer = Lexer;
  28275. exports.Linearization = Linearization;
  28276. exports.Parser = Parser;
  28277. exports.isEOF = isEOF;
  28278. }));
  28279. (function (root, factory) {
  28280. {
  28281. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  28282. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  28283. }
  28284. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  28285. var warn = sharedUtil.warn;
  28286. var isSpace = sharedUtil.isSpace;
  28287. var Stream = coreStream.Stream;
  28288. var getEncoding = coreEncodings.getEncoding;
  28289. // Hinting is currently disabled due to unknown problems on windows
  28290. // in tracemonkey and various other pdfs with type1 fonts.
  28291. var HINTING_ENABLED = false;
  28292. /*
  28293. * CharStrings are encoded following the the CharString Encoding sequence
  28294. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  28295. * The value in a byte indicates a command, a number, or subsequent bytes
  28296. * that are to be interpreted in a special way.
  28297. *
  28298. * CharString Number Encoding:
  28299. * A CharString byte containing the values from 32 through 255 inclusive
  28300. * indicate an integer. These values are decoded in four ranges.
  28301. *
  28302. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  28303. * indicate the integer v - 139. Thus, the integer values from -107 through
  28304. * 107 inclusive may be encoded in single byte.
  28305. *
  28306. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  28307. * indicates an integer involving the next byte, w, according to the formula:
  28308. * [(v - 247) x 256] + w + 108
  28309. *
  28310. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  28311. * indicates an integer involving the next byte, w, according to the formula:
  28312. * -[(v - 251) * 256] - w - 108
  28313. *
  28314. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  28315. * are a two complement signed integer. The first of these bytes contains the
  28316. * highest order bits, the second byte contains the next higher order bits
  28317. * and the fourth byte contain the lowest order bits.
  28318. *
  28319. *
  28320. * CharString Command Encoding:
  28321. * CharStrings commands are encoded in 1 or 2 bytes.
  28322. *
  28323. * Single byte commands are encoded in 1 byte that contains a value between
  28324. * 0 and 31 inclusive.
  28325. * If a command byte contains the value 12, then the value in the next byte
  28326. * indicates a command. This "escape" mechanism allows many extra commands
  28327. * to be encoded and this encoding technique helps to minimize the length of
  28328. * the charStrings.
  28329. */
  28330. var Type1CharString = (function Type1CharStringClosure() {
  28331. var COMMAND_MAP = {
  28332. 'hstem': [1],
  28333. 'vstem': [3],
  28334. 'vmoveto': [4],
  28335. 'rlineto': [5],
  28336. 'hlineto': [6],
  28337. 'vlineto': [7],
  28338. 'rrcurveto': [8],
  28339. 'callsubr': [10],
  28340. 'flex': [12, 35],
  28341. 'drop' : [12, 18],
  28342. 'endchar': [14],
  28343. 'rmoveto': [21],
  28344. 'hmoveto': [22],
  28345. 'vhcurveto': [30],
  28346. 'hvcurveto': [31]
  28347. };
  28348. function Type1CharString() {
  28349. this.width = 0;
  28350. this.lsb = 0;
  28351. this.flexing = false;
  28352. this.output = [];
  28353. this.stack = [];
  28354. }
  28355. Type1CharString.prototype = {
  28356. convert: function Type1CharString_convert(encoded, subrs,
  28357. seacAnalysisEnabled) {
  28358. var count = encoded.length;
  28359. var error = false;
  28360. var wx, sbx, subrNumber;
  28361. for (var i = 0; i < count; i++) {
  28362. var value = encoded[i];
  28363. if (value < 32) {
  28364. if (value === 12) {
  28365. value = (value << 8) + encoded[++i];
  28366. }
  28367. switch (value) {
  28368. case 1: // hstem
  28369. if (!HINTING_ENABLED) {
  28370. this.stack = [];
  28371. break;
  28372. }
  28373. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28374. break;
  28375. case 3: // vstem
  28376. if (!HINTING_ENABLED) {
  28377. this.stack = [];
  28378. break;
  28379. }
  28380. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28381. break;
  28382. case 4: // vmoveto
  28383. if (this.flexing) {
  28384. if (this.stack.length < 1) {
  28385. error = true;
  28386. break;
  28387. }
  28388. // Add the dx for flex and but also swap the values so they are
  28389. // the right order.
  28390. var dy = this.stack.pop();
  28391. this.stack.push(0, dy);
  28392. break;
  28393. }
  28394. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  28395. break;
  28396. case 5: // rlineto
  28397. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  28398. break;
  28399. case 6: // hlineto
  28400. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  28401. break;
  28402. case 7: // vlineto
  28403. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  28404. break;
  28405. case 8: // rrcurveto
  28406. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  28407. break;
  28408. case 9: // closepath
  28409. // closepath is a Type1 command that does not take argument and is
  28410. // useless in Type2 and it can simply be ignored.
  28411. this.stack = [];
  28412. break;
  28413. case 10: // callsubr
  28414. if (this.stack.length < 1) {
  28415. error = true;
  28416. break;
  28417. }
  28418. subrNumber = this.stack.pop();
  28419. error = this.convert(subrs[subrNumber], subrs,
  28420. seacAnalysisEnabled);
  28421. break;
  28422. case 11: // return
  28423. return error;
  28424. case 13: // hsbw
  28425. if (this.stack.length < 2) {
  28426. error = true;
  28427. break;
  28428. }
  28429. // To convert to type2 we have to move the width value to the
  28430. // first part of the charstring and then use hmoveto with lsb.
  28431. wx = this.stack.pop();
  28432. sbx = this.stack.pop();
  28433. this.lsb = sbx;
  28434. this.width = wx;
  28435. this.stack.push(wx, sbx);
  28436. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28437. break;
  28438. case 14: // endchar
  28439. this.output.push(COMMAND_MAP.endchar[0]);
  28440. break;
  28441. case 21: // rmoveto
  28442. if (this.flexing) {
  28443. break;
  28444. }
  28445. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28446. break;
  28447. case 22: // hmoveto
  28448. if (this.flexing) {
  28449. // Add the dy for flex.
  28450. this.stack.push(0);
  28451. break;
  28452. }
  28453. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28454. break;
  28455. case 30: // vhcurveto
  28456. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28457. break;
  28458. case 31: // hvcurveto
  28459. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28460. break;
  28461. case (12 << 8) + 0: // dotsection
  28462. // dotsection is a Type1 command to specify some hinting feature
  28463. // for dots that do not take a parameter and it can safely be
  28464. // ignored for Type2.
  28465. this.stack = [];
  28466. break;
  28467. case (12 << 8) + 1: // vstem3
  28468. if (!HINTING_ENABLED) {
  28469. this.stack = [];
  28470. break;
  28471. }
  28472. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28473. // multiple parameters, so instead of returning [vh]stem3 take a
  28474. // shortcut and return [vhstem] instead.
  28475. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28476. break;
  28477. case (12 << 8) + 2: // hstem3
  28478. if (!HINTING_ENABLED) {
  28479. this.stack = [];
  28480. break;
  28481. }
  28482. // See vstem3.
  28483. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28484. break;
  28485. case (12 << 8) + 6: // seac
  28486. // seac is like type 2's special endchar but it doesn't use the
  28487. // first argument asb, so remove it.
  28488. if (seacAnalysisEnabled) {
  28489. this.seac = this.stack.splice(-4, 4);
  28490. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28491. } else {
  28492. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28493. }
  28494. break;
  28495. case (12 << 8) + 7: // sbw
  28496. if (this.stack.length < 4) {
  28497. error = true;
  28498. break;
  28499. }
  28500. // To convert to type2 we have to move the width value to the
  28501. // first part of the charstring and then use rmoveto with
  28502. // (dx, dy). The height argument will not be used for vmtx and
  28503. // vhea tables reconstruction -- ignoring it.
  28504. var wy = this.stack.pop();
  28505. wx = this.stack.pop();
  28506. var sby = this.stack.pop();
  28507. sbx = this.stack.pop();
  28508. this.lsb = sbx;
  28509. this.width = wx;
  28510. this.stack.push(wx, sbx, sby);
  28511. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28512. break;
  28513. case (12 << 8) + 12: // div
  28514. if (this.stack.length < 2) {
  28515. error = true;
  28516. break;
  28517. }
  28518. var num2 = this.stack.pop();
  28519. var num1 = this.stack.pop();
  28520. this.stack.push(num1 / num2);
  28521. break;
  28522. case (12 << 8) + 16: // callothersubr
  28523. if (this.stack.length < 2) {
  28524. error = true;
  28525. break;
  28526. }
  28527. subrNumber = this.stack.pop();
  28528. var numArgs = this.stack.pop();
  28529. if (subrNumber === 0 && numArgs === 3) {
  28530. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28531. this.stack.push(
  28532. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28533. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28534. flexArgs[4], // bcp2x
  28535. flexArgs[5], // bcp2y
  28536. flexArgs[6], // p2x
  28537. flexArgs[7], // p2y
  28538. flexArgs[8], // bcp3x
  28539. flexArgs[9], // bcp3y
  28540. flexArgs[10], // bcp4x
  28541. flexArgs[11], // bcp4y
  28542. flexArgs[12], // p3x
  28543. flexArgs[13], // p3y
  28544. flexArgs[14] // flexDepth
  28545. // 15 = finalx unused by flex
  28546. // 16 = finaly unused by flex
  28547. );
  28548. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28549. this.flexing = false;
  28550. this.stack.push(flexArgs[15], flexArgs[16]);
  28551. } else if (subrNumber === 1 && numArgs === 0) {
  28552. this.flexing = true;
  28553. }
  28554. break;
  28555. case (12 << 8) + 17: // pop
  28556. // Ignore this since it is only used with othersubr.
  28557. break;
  28558. case (12 << 8) + 33: // setcurrentpoint
  28559. // Ignore for now.
  28560. this.stack = [];
  28561. break;
  28562. default:
  28563. warn('Unknown type 1 charstring command of "' + value + '"');
  28564. break;
  28565. }
  28566. if (error) {
  28567. break;
  28568. }
  28569. continue;
  28570. } else if (value <= 246) {
  28571. value = value - 139;
  28572. } else if (value <= 250) {
  28573. value = ((value - 247) * 256) + encoded[++i] + 108;
  28574. } else if (value <= 254) {
  28575. value = -((value - 251) * 256) - encoded[++i] - 108;
  28576. } else {
  28577. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28578. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28579. }
  28580. this.stack.push(value);
  28581. }
  28582. return error;
  28583. },
  28584. executeCommand: function(howManyArgs, command, keepStack) {
  28585. var stackLength = this.stack.length;
  28586. if (howManyArgs > stackLength) {
  28587. return true;
  28588. }
  28589. var start = stackLength - howManyArgs;
  28590. for (var i = start; i < stackLength; i++) {
  28591. var value = this.stack[i];
  28592. if (value === (value | 0)) { // int
  28593. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28594. } else { // fixed point
  28595. value = (65536 * value) | 0;
  28596. this.output.push(255,
  28597. (value >> 24) & 0xFF,
  28598. (value >> 16) & 0xFF,
  28599. (value >> 8) & 0xFF,
  28600. value & 0xFF);
  28601. }
  28602. }
  28603. this.output.push.apply(this.output, command);
  28604. if (keepStack) {
  28605. this.stack.splice(start, howManyArgs);
  28606. } else {
  28607. this.stack.length = 0;
  28608. }
  28609. return false;
  28610. }
  28611. };
  28612. return Type1CharString;
  28613. })();
  28614. /*
  28615. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28616. * program. Some of its logic depends on the Type2 charstrings
  28617. * structure.
  28618. * Note: this doesn't really parse the font since that would require evaluation
  28619. * of PostScript, but it is possible in most cases to extract what we need
  28620. * without a full parse.
  28621. */
  28622. var Type1Parser = (function Type1ParserClosure() {
  28623. /*
  28624. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28625. * of Plaintext Bytes. The function took a key as a parameter which can be
  28626. * for decrypting the eexec block of for decoding charStrings.
  28627. */
  28628. var EEXEC_ENCRYPT_KEY = 55665;
  28629. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28630. function isHexDigit(code) {
  28631. return code >= 48 && code <= 57 || // '0'-'9'
  28632. code >= 65 && code <= 70 || // 'A'-'F'
  28633. code >= 97 && code <= 102; // 'a'-'f'
  28634. }
  28635. function decrypt(data, key, discardNumber) {
  28636. if (discardNumber >= data.length) {
  28637. return new Uint8Array(0);
  28638. }
  28639. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  28640. for (i = 0; i < discardNumber; i++) {
  28641. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  28642. }
  28643. var count = data.length - discardNumber;
  28644. var decrypted = new Uint8Array(count);
  28645. for (i = discardNumber, j = 0; j < count; i++, j++) {
  28646. var value = data[i];
  28647. decrypted[j] = value ^ (r >> 8);
  28648. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28649. }
  28650. return decrypted;
  28651. }
  28652. function decryptAscii(data, key, discardNumber) {
  28653. var r = key | 0, c1 = 52845, c2 = 22719;
  28654. var count = data.length, maybeLength = count >>> 1;
  28655. var decrypted = new Uint8Array(maybeLength);
  28656. var i, j;
  28657. for (i = 0, j = 0; i < count; i++) {
  28658. var digit1 = data[i];
  28659. if (!isHexDigit(digit1)) {
  28660. continue;
  28661. }
  28662. i++;
  28663. var digit2;
  28664. while (i < count && !isHexDigit(digit2 = data[i])) {
  28665. i++;
  28666. }
  28667. if (i < count) {
  28668. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28669. decrypted[j++] = value ^ (r >> 8);
  28670. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28671. }
  28672. }
  28673. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28674. }
  28675. function isSpecial(c) {
  28676. return c === 0x2F || // '/'
  28677. c === 0x5B || c === 0x5D || // '[', ']'
  28678. c === 0x7B || c === 0x7D || // '{', '}'
  28679. c === 0x28 || c === 0x29; // '(', ')'
  28680. }
  28681. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  28682. if (encrypted) {
  28683. var data = stream.getBytes();
  28684. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28685. isHexDigit(data[2]) && isHexDigit(data[3]));
  28686. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28687. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28688. }
  28689. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  28690. this.stream = stream;
  28691. this.nextChar();
  28692. }
  28693. Type1Parser.prototype = {
  28694. readNumberArray: function Type1Parser_readNumberArray() {
  28695. this.getToken(); // read '[' or '{' (arrays can start with either)
  28696. var array = [];
  28697. while (true) {
  28698. var token = this.getToken();
  28699. if (token === null || token === ']' || token === '}') {
  28700. break;
  28701. }
  28702. array.push(parseFloat(token || 0));
  28703. }
  28704. return array;
  28705. },
  28706. readNumber: function Type1Parser_readNumber() {
  28707. var token = this.getToken();
  28708. return parseFloat(token || 0);
  28709. },
  28710. readInt: function Type1Parser_readInt() {
  28711. // Use '| 0' to prevent setting a double into length such as the double
  28712. // does not flow into the loop variable.
  28713. var token = this.getToken();
  28714. return parseInt(token || 0, 10) | 0;
  28715. },
  28716. readBoolean: function Type1Parser_readBoolean() {
  28717. var token = this.getToken();
  28718. // Use 1 and 0 since that's what type2 charstrings use.
  28719. return token === 'true' ? 1 : 0;
  28720. },
  28721. nextChar : function Type1_nextChar() {
  28722. return (this.currentChar = this.stream.getByte());
  28723. },
  28724. getToken: function Type1Parser_getToken() {
  28725. // Eat whitespace and comments.
  28726. var comment = false;
  28727. var ch = this.currentChar;
  28728. while (true) {
  28729. if (ch === -1) {
  28730. return null;
  28731. }
  28732. if (comment) {
  28733. if (ch === 0x0A || ch === 0x0D) {
  28734. comment = false;
  28735. }
  28736. } else if (ch === 0x25) { // '%'
  28737. comment = true;
  28738. } else if (!isSpace(ch)) {
  28739. break;
  28740. }
  28741. ch = this.nextChar();
  28742. }
  28743. if (isSpecial(ch)) {
  28744. this.nextChar();
  28745. return String.fromCharCode(ch);
  28746. }
  28747. var token = '';
  28748. do {
  28749. token += String.fromCharCode(ch);
  28750. ch = this.nextChar();
  28751. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  28752. return token;
  28753. },
  28754. /*
  28755. * Returns an object containing a Subrs array and a CharStrings
  28756. * array extracted from and eexec encrypted block of data
  28757. */
  28758. extractFontProgram: function Type1Parser_extractFontProgram() {
  28759. var stream = this.stream;
  28760. var subrs = [], charstrings = [];
  28761. var privateData = Object.create(null);
  28762. privateData['lenIV'] = 4;
  28763. var program = {
  28764. subrs: [],
  28765. charstrings: [],
  28766. properties: {
  28767. 'privateData': privateData
  28768. }
  28769. };
  28770. var token, length, data, lenIV, encoded;
  28771. while ((token = this.getToken()) !== null) {
  28772. if (token !== '/') {
  28773. continue;
  28774. }
  28775. token = this.getToken();
  28776. switch (token) {
  28777. case 'CharStrings':
  28778. // The number immediately following CharStrings must be greater or
  28779. // equal to the number of CharStrings.
  28780. this.getToken();
  28781. this.getToken(); // read in 'dict'
  28782. this.getToken(); // read in 'dup'
  28783. this.getToken(); // read in 'begin'
  28784. while(true) {
  28785. token = this.getToken();
  28786. if (token === null || token === 'end') {
  28787. break;
  28788. }
  28789. if (token !== '/') {
  28790. continue;
  28791. }
  28792. var glyph = this.getToken();
  28793. length = this.readInt();
  28794. this.getToken(); // read in 'RD' or '-|'
  28795. data = stream.makeSubStream(stream.pos, length);
  28796. lenIV = program.properties.privateData['lenIV'];
  28797. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28798. // Skip past the required space and binary data.
  28799. stream.skip(length);
  28800. this.nextChar();
  28801. token = this.getToken(); // read in 'ND' or '|-'
  28802. if (token === 'noaccess') {
  28803. this.getToken(); // read in 'def'
  28804. }
  28805. charstrings.push({
  28806. glyph: glyph,
  28807. encoded: encoded
  28808. });
  28809. }
  28810. break;
  28811. case 'Subrs':
  28812. var num = this.readInt();
  28813. this.getToken(); // read in 'array'
  28814. while ((token = this.getToken()) === 'dup') {
  28815. var index = this.readInt();
  28816. length = this.readInt();
  28817. this.getToken(); // read in 'RD' or '-|'
  28818. data = stream.makeSubStream(stream.pos, length);
  28819. lenIV = program.properties.privateData['lenIV'];
  28820. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28821. // Skip past the required space and binary data.
  28822. stream.skip(length);
  28823. this.nextChar();
  28824. token = this.getToken(); // read in 'NP' or '|'
  28825. if (token === 'noaccess') {
  28826. this.getToken(); // read in 'put'
  28827. }
  28828. subrs[index] = encoded;
  28829. }
  28830. break;
  28831. case 'BlueValues':
  28832. case 'OtherBlues':
  28833. case 'FamilyBlues':
  28834. case 'FamilyOtherBlues':
  28835. var blueArray = this.readNumberArray();
  28836. // *Blue* values may contain invalid data: disables reading of
  28837. // those values when hinting is disabled.
  28838. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28839. HINTING_ENABLED) {
  28840. program.properties.privateData[token] = blueArray;
  28841. }
  28842. break;
  28843. case 'StemSnapH':
  28844. case 'StemSnapV':
  28845. program.properties.privateData[token] = this.readNumberArray();
  28846. break;
  28847. case 'StdHW':
  28848. case 'StdVW':
  28849. program.properties.privateData[token] =
  28850. this.readNumberArray()[0];
  28851. break;
  28852. case 'BlueShift':
  28853. case 'lenIV':
  28854. case 'BlueFuzz':
  28855. case 'BlueScale':
  28856. case 'LanguageGroup':
  28857. case 'ExpansionFactor':
  28858. program.properties.privateData[token] = this.readNumber();
  28859. break;
  28860. case 'ForceBold':
  28861. program.properties.privateData[token] = this.readBoolean();
  28862. break;
  28863. }
  28864. }
  28865. for (var i = 0; i < charstrings.length; i++) {
  28866. glyph = charstrings[i].glyph;
  28867. encoded = charstrings[i].encoded;
  28868. var charString = new Type1CharString();
  28869. var error = charString.convert(encoded, subrs,
  28870. this.seacAnalysisEnabled);
  28871. var output = charString.output;
  28872. if (error) {
  28873. // It seems when FreeType encounters an error while evaluating a glyph
  28874. // that it completely ignores the glyph so we'll mimic that behaviour
  28875. // here and put an endchar to make the validator happy.
  28876. output = [14];
  28877. }
  28878. program.charstrings.push({
  28879. glyphName: glyph,
  28880. charstring: output,
  28881. width: charString.width,
  28882. lsb: charString.lsb,
  28883. seac: charString.seac
  28884. });
  28885. }
  28886. return program;
  28887. },
  28888. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28889. var token;
  28890. while ((token = this.getToken()) !== null) {
  28891. if (token !== '/') {
  28892. continue;
  28893. }
  28894. token = this.getToken();
  28895. switch (token) {
  28896. case 'FontMatrix':
  28897. var matrix = this.readNumberArray();
  28898. properties.fontMatrix = matrix;
  28899. break;
  28900. case 'Encoding':
  28901. var encodingArg = this.getToken();
  28902. var encoding;
  28903. if (!/^\d+$/.test(encodingArg)) {
  28904. // encoding name is specified
  28905. encoding = getEncoding(encodingArg);
  28906. } else {
  28907. encoding = [];
  28908. var size = parseInt(encodingArg, 10) | 0;
  28909. this.getToken(); // read in 'array'
  28910. for (var j = 0; j < size; j++) {
  28911. token = this.getToken();
  28912. // skipping till first dup or def (e.g. ignoring for statement)
  28913. while (token !== 'dup' && token !== 'def') {
  28914. token = this.getToken();
  28915. if (token === null) {
  28916. return; // invalid header
  28917. }
  28918. }
  28919. if (token === 'def') {
  28920. break; // read all array data
  28921. }
  28922. var index = this.readInt();
  28923. this.getToken(); // read in '/'
  28924. var glyph = this.getToken();
  28925. encoding[index] = glyph;
  28926. this.getToken(); // read the in 'put'
  28927. }
  28928. }
  28929. properties.builtInEncoding = encoding;
  28930. break;
  28931. case 'FontBBox':
  28932. var fontBBox = this.readNumberArray();
  28933. // adjusting ascent/descent
  28934. properties.ascent = fontBBox[3];
  28935. properties.descent = fontBBox[1];
  28936. properties.ascentScaled = true;
  28937. break;
  28938. }
  28939. }
  28940. }
  28941. };
  28942. return Type1Parser;
  28943. })();
  28944. exports.Type1Parser = Type1Parser;
  28945. }));
  28946. (function (root, factory) {
  28947. {
  28948. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  28949. root.pdfjsDisplayWebGL);
  28950. }
  28951. }(this, function (exports, sharedUtil, displayWebGL) {
  28952. var Util = sharedUtil.Util;
  28953. var info = sharedUtil.info;
  28954. var isArray = sharedUtil.isArray;
  28955. var error = sharedUtil.error;
  28956. var WebGLUtils = displayWebGL.WebGLUtils;
  28957. var ShadingIRs = {};
  28958. ShadingIRs.RadialAxial = {
  28959. fromIR: function RadialAxial_fromIR(raw) {
  28960. var type = raw[1];
  28961. var colorStops = raw[2];
  28962. var p0 = raw[3];
  28963. var p1 = raw[4];
  28964. var r0 = raw[5];
  28965. var r1 = raw[6];
  28966. return {
  28967. type: 'Pattern',
  28968. getPattern: function RadialAxial_getPattern(ctx) {
  28969. var grad;
  28970. if (type === 'axial') {
  28971. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  28972. } else if (type === 'radial') {
  28973. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  28974. }
  28975. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  28976. var c = colorStops[i];
  28977. grad.addColorStop(c[0], c[1]);
  28978. }
  28979. return grad;
  28980. }
  28981. };
  28982. }
  28983. };
  28984. var createMeshCanvas = (function createMeshCanvasClosure() {
  28985. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  28986. // Very basic Gouraud-shaded triangle rasterization algorithm.
  28987. var coords = context.coords, colors = context.colors;
  28988. var bytes = data.data, rowSize = data.width * 4;
  28989. var tmp;
  28990. if (coords[p1 + 1] > coords[p2 + 1]) {
  28991. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  28992. }
  28993. if (coords[p2 + 1] > coords[p3 + 1]) {
  28994. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  28995. }
  28996. if (coords[p1 + 1] > coords[p2 + 1]) {
  28997. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  28998. }
  28999. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  29000. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  29001. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  29002. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  29003. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  29004. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  29005. if (y1 >= y3) {
  29006. return;
  29007. }
  29008. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  29009. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  29010. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  29011. var minY = Math.round(y1), maxY = Math.round(y3);
  29012. var xa, car, cag, cab;
  29013. var xb, cbr, cbg, cbb;
  29014. var k;
  29015. for (var y = minY; y <= maxY; y++) {
  29016. if (y < y2) {
  29017. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  29018. xa = x1 - (x1 - x2) * k;
  29019. car = c1r - (c1r - c2r) * k;
  29020. cag = c1g - (c1g - c2g) * k;
  29021. cab = c1b - (c1b - c2b) * k;
  29022. } else {
  29023. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  29024. xa = x2 - (x2 - x3) * k;
  29025. car = c2r - (c2r - c3r) * k;
  29026. cag = c2g - (c2g - c3g) * k;
  29027. cab = c2b - (c2b - c3b) * k;
  29028. }
  29029. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  29030. xb = x1 - (x1 - x3) * k;
  29031. cbr = c1r - (c1r - c3r) * k;
  29032. cbg = c1g - (c1g - c3g) * k;
  29033. cbb = c1b - (c1b - c3b) * k;
  29034. var x1_ = Math.round(Math.min(xa, xb));
  29035. var x2_ = Math.round(Math.max(xa, xb));
  29036. var j = rowSize * y + x1_ * 4;
  29037. for (var x = x1_; x <= x2_; x++) {
  29038. k = (xa - x) / (xa - xb);
  29039. k = k < 0 ? 0 : k > 1 ? 1 : k;
  29040. bytes[j++] = (car - (car - cbr) * k) | 0;
  29041. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  29042. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  29043. bytes[j++] = 255;
  29044. }
  29045. }
  29046. }
  29047. function drawFigure(data, figure, context) {
  29048. var ps = figure.coords;
  29049. var cs = figure.colors;
  29050. var i, ii;
  29051. switch (figure.type) {
  29052. case 'lattice':
  29053. var verticesPerRow = figure.verticesPerRow;
  29054. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  29055. var cols = verticesPerRow - 1;
  29056. for (i = 0; i < rows; i++) {
  29057. var q = i * verticesPerRow;
  29058. for (var j = 0; j < cols; j++, q++) {
  29059. drawTriangle(data, context,
  29060. ps[q], ps[q + 1], ps[q + verticesPerRow],
  29061. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  29062. drawTriangle(data, context,
  29063. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  29064. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  29065. }
  29066. }
  29067. break;
  29068. case 'triangles':
  29069. for (i = 0, ii = ps.length; i < ii; i += 3) {
  29070. drawTriangle(data, context,
  29071. ps[i], ps[i + 1], ps[i + 2],
  29072. cs[i], cs[i + 1], cs[i + 2]);
  29073. }
  29074. break;
  29075. default:
  29076. error('illigal figure');
  29077. break;
  29078. }
  29079. }
  29080. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  29081. backgroundColor, cachedCanvases) {
  29082. // we will increase scale on some weird factor to let antialiasing take
  29083. // care of "rough" edges
  29084. var EXPECTED_SCALE = 1.1;
  29085. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29086. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29087. // We need to keep transparent border around our pattern for fill():
  29088. // createPattern with 'no-repeat' will bleed edges across entire area.
  29089. var BORDER_SIZE = 2;
  29090. var offsetX = Math.floor(bounds[0]);
  29091. var offsetY = Math.floor(bounds[1]);
  29092. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  29093. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  29094. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  29095. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  29096. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  29097. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  29098. var scaleX = boundsWidth / width;
  29099. var scaleY = boundsHeight / height;
  29100. var context = {
  29101. coords: coords,
  29102. colors: colors,
  29103. offsetX: -offsetX,
  29104. offsetY: -offsetY,
  29105. scaleX: 1 / scaleX,
  29106. scaleY: 1 / scaleY
  29107. };
  29108. var paddedWidth = width + BORDER_SIZE * 2;
  29109. var paddedHeight = height + BORDER_SIZE * 2;
  29110. var canvas, tmpCanvas, i, ii;
  29111. if (WebGLUtils.isEnabled) {
  29112. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  29113. figures, context);
  29114. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  29115. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29116. false);
  29117. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  29118. canvas = tmpCanvas.canvas;
  29119. } else {
  29120. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29121. false);
  29122. var tmpCtx = tmpCanvas.context;
  29123. var data = tmpCtx.createImageData(width, height);
  29124. if (backgroundColor) {
  29125. var bytes = data.data;
  29126. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  29127. bytes[i] = backgroundColor[0];
  29128. bytes[i + 1] = backgroundColor[1];
  29129. bytes[i + 2] = backgroundColor[2];
  29130. bytes[i + 3] = 255;
  29131. }
  29132. }
  29133. for (i = 0; i < figures.length; i++) {
  29134. drawFigure(data, figures[i], context);
  29135. }
  29136. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  29137. canvas = tmpCanvas.canvas;
  29138. }
  29139. return {canvas: canvas,
  29140. offsetX: offsetX - BORDER_SIZE * scaleX,
  29141. offsetY: offsetY - BORDER_SIZE * scaleY,
  29142. scaleX: scaleX, scaleY: scaleY};
  29143. }
  29144. return createMeshCanvas;
  29145. })();
  29146. ShadingIRs.Mesh = {
  29147. fromIR: function Mesh_fromIR(raw) {
  29148. //var type = raw[1];
  29149. var coords = raw[2];
  29150. var colors = raw[3];
  29151. var figures = raw[4];
  29152. var bounds = raw[5];
  29153. var matrix = raw[6];
  29154. //var bbox = raw[7];
  29155. var background = raw[8];
  29156. return {
  29157. type: 'Pattern',
  29158. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  29159. var scale;
  29160. if (shadingFill) {
  29161. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  29162. } else {
  29163. // Obtain scale from matrix and current transformation matrix.
  29164. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  29165. if (matrix) {
  29166. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  29167. scale = [scale[0] * matrixScale[0],
  29168. scale[1] * matrixScale[1]];
  29169. }
  29170. }
  29171. // Rasterizing on the main thread since sending/queue large canvases
  29172. // might cause OOM.
  29173. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  29174. colors, figures, shadingFill ? null : background,
  29175. owner.cachedCanvases);
  29176. if (!shadingFill) {
  29177. ctx.setTransform.apply(ctx, owner.baseTransform);
  29178. if (matrix) {
  29179. ctx.transform.apply(ctx, matrix);
  29180. }
  29181. }
  29182. ctx.translate(temporaryPatternCanvas.offsetX,
  29183. temporaryPatternCanvas.offsetY);
  29184. ctx.scale(temporaryPatternCanvas.scaleX,
  29185. temporaryPatternCanvas.scaleY);
  29186. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  29187. }
  29188. };
  29189. }
  29190. };
  29191. ShadingIRs.Dummy = {
  29192. fromIR: function Dummy_fromIR() {
  29193. return {
  29194. type: 'Pattern',
  29195. getPattern: function Dummy_fromIR_getPattern() {
  29196. return 'hotpink';
  29197. }
  29198. };
  29199. }
  29200. };
  29201. function getShadingPatternFromIR(raw) {
  29202. var shadingIR = ShadingIRs[raw[0]];
  29203. if (!shadingIR) {
  29204. error('Unknown IR type: ' + raw[0]);
  29205. }
  29206. return shadingIR.fromIR(raw);
  29207. }
  29208. var TilingPattern = (function TilingPatternClosure() {
  29209. var PaintType = {
  29210. COLORED: 1,
  29211. UNCOLORED: 2
  29212. };
  29213. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29214. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  29215. this.operatorList = IR[2];
  29216. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  29217. this.bbox = IR[4];
  29218. this.xstep = IR[5];
  29219. this.ystep = IR[6];
  29220. this.paintType = IR[7];
  29221. this.tilingType = IR[8];
  29222. this.color = color;
  29223. this.canvasGraphicsFactory = canvasGraphicsFactory;
  29224. this.baseTransform = baseTransform;
  29225. this.type = 'Pattern';
  29226. this.ctx = ctx;
  29227. }
  29228. TilingPattern.prototype = {
  29229. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  29230. var operatorList = this.operatorList;
  29231. var bbox = this.bbox;
  29232. var xstep = this.xstep;
  29233. var ystep = this.ystep;
  29234. var paintType = this.paintType;
  29235. var tilingType = this.tilingType;
  29236. var color = this.color;
  29237. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  29238. info('TilingType: ' + tilingType);
  29239. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  29240. var topLeft = [x0, y0];
  29241. // we want the canvas to be as large as the step size
  29242. var botRight = [x0 + xstep, y0 + ystep];
  29243. var width = botRight[0] - topLeft[0];
  29244. var height = botRight[1] - topLeft[1];
  29245. // Obtain scale from matrix and current transformation matrix.
  29246. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  29247. var curMatrixScale = Util.singularValueDecompose2dScale(
  29248. this.baseTransform);
  29249. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  29250. matrixScale[1] * curMatrixScale[1]];
  29251. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29252. // Use width and height values that are as close as possible to the end
  29253. // result when the pattern is used. Too low value makes the pattern look
  29254. // blurry. Too large value makes it look too crispy.
  29255. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  29256. MAX_PATTERN_SIZE);
  29257. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  29258. MAX_PATTERN_SIZE);
  29259. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  29260. width, height, true);
  29261. var tmpCtx = tmpCanvas.context;
  29262. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  29263. graphics.groupLevel = owner.groupLevel;
  29264. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  29265. this.setScale(width, height, xstep, ystep);
  29266. this.transformToScale(graphics);
  29267. // transform coordinates to pattern space
  29268. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  29269. graphics.transform.apply(graphics, tmpTranslate);
  29270. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  29271. graphics.executeOperatorList(operatorList);
  29272. return tmpCanvas.canvas;
  29273. },
  29274. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  29275. this.scale = [width / xstep, height / ystep];
  29276. },
  29277. transformToScale: function TilingPattern_transformToScale(graphics) {
  29278. var scale = this.scale;
  29279. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  29280. graphics.transform.apply(graphics, tmpScale);
  29281. },
  29282. scaleToContext: function TilingPattern_scaleToContext() {
  29283. var scale = this.scale;
  29284. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  29285. },
  29286. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  29287. if (bbox && isArray(bbox) && bbox.length === 4) {
  29288. var bboxWidth = x1 - x0;
  29289. var bboxHeight = y1 - y0;
  29290. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  29291. graphics.clip();
  29292. graphics.endPath();
  29293. }
  29294. },
  29295. setFillAndStrokeStyleToContext:
  29296. function setFillAndStrokeStyleToContext(context, paintType, color) {
  29297. switch (paintType) {
  29298. case PaintType.COLORED:
  29299. var ctx = this.ctx;
  29300. context.fillStyle = ctx.fillStyle;
  29301. context.strokeStyle = ctx.strokeStyle;
  29302. break;
  29303. case PaintType.UNCOLORED:
  29304. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  29305. context.fillStyle = cssColor;
  29306. context.strokeStyle = cssColor;
  29307. break;
  29308. default:
  29309. error('Unsupported paint type: ' + paintType);
  29310. }
  29311. },
  29312. getPattern: function TilingPattern_getPattern(ctx, owner) {
  29313. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  29314. ctx = this.ctx;
  29315. ctx.setTransform.apply(ctx, this.baseTransform);
  29316. ctx.transform.apply(ctx, this.matrix);
  29317. this.scaleToContext();
  29318. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  29319. }
  29320. };
  29321. return TilingPattern;
  29322. })();
  29323. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  29324. exports.TilingPattern = TilingPattern;
  29325. }));
  29326. (function (root, factory) {
  29327. {
  29328. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  29329. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  29330. }
  29331. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  29332. var Util = sharedUtil.Util;
  29333. var assert = sharedUtil.assert;
  29334. var warn = sharedUtil.warn;
  29335. var error = sharedUtil.error;
  29336. var isInt = sharedUtil.isInt;
  29337. var isString = sharedUtil.isString;
  29338. var MissingDataException = sharedUtil.MissingDataException;
  29339. var isName = corePrimitives.isName;
  29340. var isCmd = corePrimitives.isCmd;
  29341. var isStream = corePrimitives.isStream;
  29342. var StringStream = coreStream.StringStream;
  29343. var Lexer = coreParser.Lexer;
  29344. var isEOF = coreParser.isEOF;
  29345. var BUILT_IN_CMAPS = [
  29346. // << Start unicode maps.
  29347. 'Adobe-GB1-UCS2',
  29348. 'Adobe-CNS1-UCS2',
  29349. 'Adobe-Japan1-UCS2',
  29350. 'Adobe-Korea1-UCS2',
  29351. // >> End unicode maps.
  29352. '78-EUC-H',
  29353. '78-EUC-V',
  29354. '78-H',
  29355. '78-RKSJ-H',
  29356. '78-RKSJ-V',
  29357. '78-V',
  29358. '78ms-RKSJ-H',
  29359. '78ms-RKSJ-V',
  29360. '83pv-RKSJ-H',
  29361. '90ms-RKSJ-H',
  29362. '90ms-RKSJ-V',
  29363. '90msp-RKSJ-H',
  29364. '90msp-RKSJ-V',
  29365. '90pv-RKSJ-H',
  29366. '90pv-RKSJ-V',
  29367. 'Add-H',
  29368. 'Add-RKSJ-H',
  29369. 'Add-RKSJ-V',
  29370. 'Add-V',
  29371. 'Adobe-CNS1-0',
  29372. 'Adobe-CNS1-1',
  29373. 'Adobe-CNS1-2',
  29374. 'Adobe-CNS1-3',
  29375. 'Adobe-CNS1-4',
  29376. 'Adobe-CNS1-5',
  29377. 'Adobe-CNS1-6',
  29378. 'Adobe-GB1-0',
  29379. 'Adobe-GB1-1',
  29380. 'Adobe-GB1-2',
  29381. 'Adobe-GB1-3',
  29382. 'Adobe-GB1-4',
  29383. 'Adobe-GB1-5',
  29384. 'Adobe-Japan1-0',
  29385. 'Adobe-Japan1-1',
  29386. 'Adobe-Japan1-2',
  29387. 'Adobe-Japan1-3',
  29388. 'Adobe-Japan1-4',
  29389. 'Adobe-Japan1-5',
  29390. 'Adobe-Japan1-6',
  29391. 'Adobe-Korea1-0',
  29392. 'Adobe-Korea1-1',
  29393. 'Adobe-Korea1-2',
  29394. 'B5-H',
  29395. 'B5-V',
  29396. 'B5pc-H',
  29397. 'B5pc-V',
  29398. 'CNS-EUC-H',
  29399. 'CNS-EUC-V',
  29400. 'CNS1-H',
  29401. 'CNS1-V',
  29402. 'CNS2-H',
  29403. 'CNS2-V',
  29404. 'ETHK-B5-H',
  29405. 'ETHK-B5-V',
  29406. 'ETen-B5-H',
  29407. 'ETen-B5-V',
  29408. 'ETenms-B5-H',
  29409. 'ETenms-B5-V',
  29410. 'EUC-H',
  29411. 'EUC-V',
  29412. 'Ext-H',
  29413. 'Ext-RKSJ-H',
  29414. 'Ext-RKSJ-V',
  29415. 'Ext-V',
  29416. 'GB-EUC-H',
  29417. 'GB-EUC-V',
  29418. 'GB-H',
  29419. 'GB-V',
  29420. 'GBK-EUC-H',
  29421. 'GBK-EUC-V',
  29422. 'GBK2K-H',
  29423. 'GBK2K-V',
  29424. 'GBKp-EUC-H',
  29425. 'GBKp-EUC-V',
  29426. 'GBT-EUC-H',
  29427. 'GBT-EUC-V',
  29428. 'GBT-H',
  29429. 'GBT-V',
  29430. 'GBTpc-EUC-H',
  29431. 'GBTpc-EUC-V',
  29432. 'GBpc-EUC-H',
  29433. 'GBpc-EUC-V',
  29434. 'H',
  29435. 'HKdla-B5-H',
  29436. 'HKdla-B5-V',
  29437. 'HKdlb-B5-H',
  29438. 'HKdlb-B5-V',
  29439. 'HKgccs-B5-H',
  29440. 'HKgccs-B5-V',
  29441. 'HKm314-B5-H',
  29442. 'HKm314-B5-V',
  29443. 'HKm471-B5-H',
  29444. 'HKm471-B5-V',
  29445. 'HKscs-B5-H',
  29446. 'HKscs-B5-V',
  29447. 'Hankaku',
  29448. 'Hiragana',
  29449. 'KSC-EUC-H',
  29450. 'KSC-EUC-V',
  29451. 'KSC-H',
  29452. 'KSC-Johab-H',
  29453. 'KSC-Johab-V',
  29454. 'KSC-V',
  29455. 'KSCms-UHC-H',
  29456. 'KSCms-UHC-HW-H',
  29457. 'KSCms-UHC-HW-V',
  29458. 'KSCms-UHC-V',
  29459. 'KSCpc-EUC-H',
  29460. 'KSCpc-EUC-V',
  29461. 'Katakana',
  29462. 'NWP-H',
  29463. 'NWP-V',
  29464. 'RKSJ-H',
  29465. 'RKSJ-V',
  29466. 'Roman',
  29467. 'UniCNS-UCS2-H',
  29468. 'UniCNS-UCS2-V',
  29469. 'UniCNS-UTF16-H',
  29470. 'UniCNS-UTF16-V',
  29471. 'UniCNS-UTF32-H',
  29472. 'UniCNS-UTF32-V',
  29473. 'UniCNS-UTF8-H',
  29474. 'UniCNS-UTF8-V',
  29475. 'UniGB-UCS2-H',
  29476. 'UniGB-UCS2-V',
  29477. 'UniGB-UTF16-H',
  29478. 'UniGB-UTF16-V',
  29479. 'UniGB-UTF32-H',
  29480. 'UniGB-UTF32-V',
  29481. 'UniGB-UTF8-H',
  29482. 'UniGB-UTF8-V',
  29483. 'UniJIS-UCS2-H',
  29484. 'UniJIS-UCS2-HW-H',
  29485. 'UniJIS-UCS2-HW-V',
  29486. 'UniJIS-UCS2-V',
  29487. 'UniJIS-UTF16-H',
  29488. 'UniJIS-UTF16-V',
  29489. 'UniJIS-UTF32-H',
  29490. 'UniJIS-UTF32-V',
  29491. 'UniJIS-UTF8-H',
  29492. 'UniJIS-UTF8-V',
  29493. 'UniJIS2004-UTF16-H',
  29494. 'UniJIS2004-UTF16-V',
  29495. 'UniJIS2004-UTF32-H',
  29496. 'UniJIS2004-UTF32-V',
  29497. 'UniJIS2004-UTF8-H',
  29498. 'UniJIS2004-UTF8-V',
  29499. 'UniJISPro-UCS2-HW-V',
  29500. 'UniJISPro-UCS2-V',
  29501. 'UniJISPro-UTF8-V',
  29502. 'UniJISX0213-UTF32-H',
  29503. 'UniJISX0213-UTF32-V',
  29504. 'UniJISX02132004-UTF32-H',
  29505. 'UniJISX02132004-UTF32-V',
  29506. 'UniKS-UCS2-H',
  29507. 'UniKS-UCS2-V',
  29508. 'UniKS-UTF16-H',
  29509. 'UniKS-UTF16-V',
  29510. 'UniKS-UTF32-H',
  29511. 'UniKS-UTF32-V',
  29512. 'UniKS-UTF8-H',
  29513. 'UniKS-UTF8-V',
  29514. 'V',
  29515. 'WP-Symbol'];
  29516. // CMap, not to be confused with TrueType's cmap.
  29517. var CMap = (function CMapClosure() {
  29518. function CMap(builtInCMap) {
  29519. // Codespace ranges are stored as follows:
  29520. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  29521. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  29522. this.codespaceRanges = [[], [], [], []];
  29523. this.numCodespaceRanges = 0;
  29524. // Map entries have one of two forms.
  29525. // - cid chars are 16-bit unsigned integers, stored as integers.
  29526. // - bf chars are variable-length byte sequences, stored as strings, with
  29527. // one byte per character.
  29528. this._map = [];
  29529. this.name = '';
  29530. this.vertical = false;
  29531. this.useCMap = null;
  29532. this.builtInCMap = builtInCMap;
  29533. }
  29534. CMap.prototype = {
  29535. addCodespaceRange: function(n, low, high) {
  29536. this.codespaceRanges[n - 1].push(low, high);
  29537. this.numCodespaceRanges++;
  29538. },
  29539. mapCidRange: function(low, high, dstLow) {
  29540. while (low <= high) {
  29541. this._map[low++] = dstLow++;
  29542. }
  29543. },
  29544. mapBfRange: function(low, high, dstLow) {
  29545. var lastByte = dstLow.length - 1;
  29546. while (low <= high) {
  29547. this._map[low++] = dstLow;
  29548. // Only the last byte has to be incremented.
  29549. dstLow = dstLow.substr(0, lastByte) +
  29550. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  29551. }
  29552. },
  29553. mapBfRangeToArray: function(low, high, array) {
  29554. var i = 0, ii = array.length;
  29555. while (low <= high && i < ii) {
  29556. this._map[low] = array[i++];
  29557. ++low;
  29558. }
  29559. },
  29560. // This is used for both bf and cid chars.
  29561. mapOne: function(src, dst) {
  29562. this._map[src] = dst;
  29563. },
  29564. lookup: function(code) {
  29565. return this._map[code];
  29566. },
  29567. contains: function(code) {
  29568. return this._map[code] !== undefined;
  29569. },
  29570. forEach: function(callback) {
  29571. // Most maps have fewer than 65536 entries, and for those we use normal
  29572. // array iteration. But really sparse tables are possible -- e.g. with
  29573. // indices in the *billions*. For such tables we use for..in, which isn't
  29574. // ideal because it stringifies the indices for all present elements, but
  29575. // it does avoid iterating over every undefined entry.
  29576. var map = this._map;
  29577. var length = map.length;
  29578. var i;
  29579. if (length <= 0x10000) {
  29580. for (i = 0; i < length; i++) {
  29581. if (map[i] !== undefined) {
  29582. callback(i, map[i]);
  29583. }
  29584. }
  29585. } else {
  29586. for (i in this._map) {
  29587. callback(i, map[i]);
  29588. }
  29589. }
  29590. },
  29591. charCodeOf: function(value) {
  29592. return this._map.indexOf(value);
  29593. },
  29594. getMap: function() {
  29595. return this._map;
  29596. },
  29597. readCharCode: function(str, offset, out) {
  29598. var c = 0;
  29599. var codespaceRanges = this.codespaceRanges;
  29600. var codespaceRangesLen = this.codespaceRanges.length;
  29601. // 9.7.6.2 CMap Mapping
  29602. // The code length is at most 4.
  29603. for (var n = 0; n < codespaceRangesLen; n++) {
  29604. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  29605. // Check each codespace range to see if it falls within.
  29606. var codespaceRange = codespaceRanges[n];
  29607. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  29608. var low = codespaceRange[k++];
  29609. var high = codespaceRange[k++];
  29610. if (c >= low && c <= high) {
  29611. out.charcode = c;
  29612. out.length = n + 1;
  29613. return;
  29614. }
  29615. }
  29616. }
  29617. out.charcode = 0;
  29618. out.length = 1;
  29619. },
  29620. get length() {
  29621. return this._map.length;
  29622. },
  29623. get isIdentityCMap() {
  29624. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  29625. return false;
  29626. }
  29627. if (this._map.length !== 0x10000) {
  29628. return false;
  29629. }
  29630. for (var i = 0; i < 0x10000; i++) {
  29631. if (this._map[i] !== i) {
  29632. return false;
  29633. }
  29634. }
  29635. return true;
  29636. }
  29637. };
  29638. return CMap;
  29639. })();
  29640. // A special case of CMap, where the _map array implicitly has a length of
  29641. // 65536 and each element is equal to its index.
  29642. var IdentityCMap = (function IdentityCMapClosure() {
  29643. function IdentityCMap(vertical, n) {
  29644. CMap.call(this);
  29645. this.vertical = vertical;
  29646. this.addCodespaceRange(n, 0, 0xffff);
  29647. }
  29648. Util.inherit(IdentityCMap, CMap, {});
  29649. IdentityCMap.prototype = {
  29650. addCodespaceRange: CMap.prototype.addCodespaceRange,
  29651. mapCidRange: function(low, high, dstLow) {
  29652. error('should not call mapCidRange');
  29653. },
  29654. mapBfRange: function(low, high, dstLow) {
  29655. error('should not call mapBfRange');
  29656. },
  29657. mapBfRangeToArray: function(low, high, array) {
  29658. error('should not call mapBfRangeToArray');
  29659. },
  29660. mapOne: function(src, dst) {
  29661. error('should not call mapCidOne');
  29662. },
  29663. lookup: function(code) {
  29664. return (isInt(code) && code <= 0xffff) ? code : undefined;
  29665. },
  29666. contains: function(code) {
  29667. return isInt(code) && code <= 0xffff;
  29668. },
  29669. forEach: function(callback) {
  29670. for (var i = 0; i <= 0xffff; i++) {
  29671. callback(i, i);
  29672. }
  29673. },
  29674. charCodeOf: function(value) {
  29675. return (isInt(value) && value <= 0xffff) ? value : -1;
  29676. },
  29677. getMap: function() {
  29678. // Sometimes identity maps must be instantiated, but it's rare.
  29679. var map = new Array(0x10000);
  29680. for (var i = 0; i <= 0xffff; i++) {
  29681. map[i] = i;
  29682. }
  29683. return map;
  29684. },
  29685. readCharCode: CMap.prototype.readCharCode,
  29686. get length() {
  29687. return 0x10000;
  29688. },
  29689. get isIdentityCMap() {
  29690. error('should not access .isIdentityCMap');
  29691. }
  29692. };
  29693. return IdentityCMap;
  29694. })();
  29695. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  29696. function fetchBinaryData(url) {
  29697. return new Promise(function (resolve, reject) {
  29698. var request = new XMLHttpRequest();
  29699. request.open('GET', url, true);
  29700. request.responseType = 'arraybuffer';
  29701. request.onreadystatechange = function () {
  29702. if (request.readyState === XMLHttpRequest.DONE) {
  29703. if (!request.response || request.status !== 200 &&
  29704. request.status !== 0) {
  29705. reject(new Error('Unable to get binary cMap at: ' + url));
  29706. } else {
  29707. resolve(new Uint8Array(request.response));
  29708. }
  29709. }
  29710. };
  29711. request.send(null);
  29712. });
  29713. }
  29714. function hexToInt(a, size) {
  29715. var n = 0;
  29716. for (var i = 0; i <= size; i++) {
  29717. n = (n << 8) | a[i];
  29718. }
  29719. return n >>> 0;
  29720. }
  29721. function hexToStr(a, size) {
  29722. // This code is hot. Special-case some common values to avoid creating an
  29723. // object with subarray().
  29724. if (size === 1) {
  29725. return String.fromCharCode(a[0], a[1]);
  29726. }
  29727. if (size === 3) {
  29728. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29729. }
  29730. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29731. }
  29732. function addHex(a, b, size) {
  29733. var c = 0;
  29734. for (var i = size; i >= 0; i--) {
  29735. c += a[i] + b[i];
  29736. a[i] = c & 255;
  29737. c >>= 8;
  29738. }
  29739. }
  29740. function incHex(a, size) {
  29741. var c = 1;
  29742. for (var i = size; i >= 0 && c > 0; i--) {
  29743. c += a[i];
  29744. a[i] = c & 255;
  29745. c >>= 8;
  29746. }
  29747. }
  29748. var MAX_NUM_SIZE = 16;
  29749. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29750. function BinaryCMapStream(data) {
  29751. this.buffer = data;
  29752. this.pos = 0;
  29753. this.end = data.length;
  29754. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29755. }
  29756. BinaryCMapStream.prototype = {
  29757. readByte: function () {
  29758. if (this.pos >= this.end) {
  29759. return -1;
  29760. }
  29761. return this.buffer[this.pos++];
  29762. },
  29763. readNumber: function () {
  29764. var n = 0;
  29765. var last;
  29766. do {
  29767. var b = this.readByte();
  29768. if (b < 0) {
  29769. error('unexpected EOF in bcmap');
  29770. }
  29771. last = !(b & 0x80);
  29772. n = (n << 7) | (b & 0x7F);
  29773. } while (!last);
  29774. return n;
  29775. },
  29776. readSigned: function () {
  29777. var n = this.readNumber();
  29778. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29779. },
  29780. readHex: function (num, size) {
  29781. num.set(this.buffer.subarray(this.pos,
  29782. this.pos + size + 1));
  29783. this.pos += size + 1;
  29784. },
  29785. readHexNumber: function (num, size) {
  29786. var last;
  29787. var stack = this.tmpBuf, sp = 0;
  29788. do {
  29789. var b = this.readByte();
  29790. if (b < 0) {
  29791. error('unexpected EOF in bcmap');
  29792. }
  29793. last = !(b & 0x80);
  29794. stack[sp++] = b & 0x7F;
  29795. } while (!last);
  29796. var i = size, buffer = 0, bufferSize = 0;
  29797. while (i >= 0) {
  29798. while (bufferSize < 8 && stack.length > 0) {
  29799. buffer = (stack[--sp] << bufferSize) | buffer;
  29800. bufferSize += 7;
  29801. }
  29802. num[i] = buffer & 255;
  29803. i--;
  29804. buffer >>= 8;
  29805. bufferSize -= 8;
  29806. }
  29807. },
  29808. readHexSigned: function (num, size) {
  29809. this.readHexNumber(num, size);
  29810. var sign = num[size] & 1 ? 255 : 0;
  29811. var c = 0;
  29812. for (var i = 0; i <= size; i++) {
  29813. c = ((c & 1) << 8) | num[i];
  29814. num[i] = (c >> 1) ^ sign;
  29815. }
  29816. },
  29817. readString: function () {
  29818. var len = this.readNumber();
  29819. var s = '';
  29820. for (var i = 0; i < len; i++) {
  29821. s += String.fromCharCode(this.readNumber());
  29822. }
  29823. return s;
  29824. }
  29825. };
  29826. function processBinaryCMap(url, cMap, extend) {
  29827. return fetchBinaryData(url).then(function (data) {
  29828. var stream = new BinaryCMapStream(data);
  29829. var header = stream.readByte();
  29830. cMap.vertical = !!(header & 1);
  29831. var useCMap = null;
  29832. var start = new Uint8Array(MAX_NUM_SIZE);
  29833. var end = new Uint8Array(MAX_NUM_SIZE);
  29834. var char = new Uint8Array(MAX_NUM_SIZE);
  29835. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29836. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29837. var code;
  29838. var b;
  29839. while ((b = stream.readByte()) >= 0) {
  29840. var type = b >> 5;
  29841. if (type === 7) { // metadata, e.g. comment or usecmap
  29842. switch (b & 0x1F) {
  29843. case 0:
  29844. stream.readString(); // skipping comment
  29845. break;
  29846. case 1:
  29847. useCMap = stream.readString();
  29848. break;
  29849. }
  29850. continue;
  29851. }
  29852. var sequence = !!(b & 0x10);
  29853. var dataSize = b & 15;
  29854. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29855. var ucs2DataSize = 1;
  29856. var subitemsCount = stream.readNumber();
  29857. var i;
  29858. switch (type) {
  29859. case 0: // codespacerange
  29860. stream.readHex(start, dataSize);
  29861. stream.readHexNumber(end, dataSize);
  29862. addHex(end, start, dataSize);
  29863. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29864. hexToInt(end, dataSize));
  29865. for (i = 1; i < subitemsCount; i++) {
  29866. incHex(end, dataSize);
  29867. stream.readHexNumber(start, dataSize);
  29868. addHex(start, end, dataSize);
  29869. stream.readHexNumber(end, dataSize);
  29870. addHex(end, start, dataSize);
  29871. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29872. hexToInt(end, dataSize));
  29873. }
  29874. break;
  29875. case 1: // notdefrange
  29876. stream.readHex(start, dataSize);
  29877. stream.readHexNumber(end, dataSize);
  29878. addHex(end, start, dataSize);
  29879. code = stream.readNumber();
  29880. // undefined range, skipping
  29881. for (i = 1; i < subitemsCount; i++) {
  29882. incHex(end, dataSize);
  29883. stream.readHexNumber(start, dataSize);
  29884. addHex(start, end, dataSize);
  29885. stream.readHexNumber(end, dataSize);
  29886. addHex(end, start, dataSize);
  29887. code = stream.readNumber();
  29888. // nop
  29889. }
  29890. break;
  29891. case 2: // cidchar
  29892. stream.readHex(char, dataSize);
  29893. code = stream.readNumber();
  29894. cMap.mapOne(hexToInt(char, dataSize), code);
  29895. for (i = 1; i < subitemsCount; i++) {
  29896. incHex(char, dataSize);
  29897. if (!sequence) {
  29898. stream.readHexNumber(tmp, dataSize);
  29899. addHex(char, tmp, dataSize);
  29900. }
  29901. code = stream.readSigned() + (code + 1);
  29902. cMap.mapOne(hexToInt(char, dataSize), code);
  29903. }
  29904. break;
  29905. case 3: // cidrange
  29906. stream.readHex(start, dataSize);
  29907. stream.readHexNumber(end, dataSize);
  29908. addHex(end, start, dataSize);
  29909. code = stream.readNumber();
  29910. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29911. code);
  29912. for (i = 1; i < subitemsCount; i++) {
  29913. incHex(end, dataSize);
  29914. if (!sequence) {
  29915. stream.readHexNumber(start, dataSize);
  29916. addHex(start, end, dataSize);
  29917. } else {
  29918. start.set(end);
  29919. }
  29920. stream.readHexNumber(end, dataSize);
  29921. addHex(end, start, dataSize);
  29922. code = stream.readNumber();
  29923. cMap.mapCidRange(hexToInt(start, dataSize),
  29924. hexToInt(end, dataSize), code);
  29925. }
  29926. break;
  29927. case 4: // bfchar
  29928. stream.readHex(char, ucs2DataSize);
  29929. stream.readHex(charCode, dataSize);
  29930. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29931. hexToStr(charCode, dataSize));
  29932. for (i = 1; i < subitemsCount; i++) {
  29933. incHex(char, ucs2DataSize);
  29934. if (!sequence) {
  29935. stream.readHexNumber(tmp, ucs2DataSize);
  29936. addHex(char, tmp, ucs2DataSize);
  29937. }
  29938. incHex(charCode, dataSize);
  29939. stream.readHexSigned(tmp, dataSize);
  29940. addHex(charCode, tmp, dataSize);
  29941. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29942. hexToStr(charCode, dataSize));
  29943. }
  29944. break;
  29945. case 5: // bfrange
  29946. stream.readHex(start, ucs2DataSize);
  29947. stream.readHexNumber(end, ucs2DataSize);
  29948. addHex(end, start, ucs2DataSize);
  29949. stream.readHex(charCode, dataSize);
  29950. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29951. hexToInt(end, ucs2DataSize),
  29952. hexToStr(charCode, dataSize));
  29953. for (i = 1; i < subitemsCount; i++) {
  29954. incHex(end, ucs2DataSize);
  29955. if (!sequence) {
  29956. stream.readHexNumber(start, ucs2DataSize);
  29957. addHex(start, end, ucs2DataSize);
  29958. } else {
  29959. start.set(end);
  29960. }
  29961. stream.readHexNumber(end, ucs2DataSize);
  29962. addHex(end, start, ucs2DataSize);
  29963. stream.readHex(charCode, dataSize);
  29964. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29965. hexToInt(end, ucs2DataSize),
  29966. hexToStr(charCode, dataSize));
  29967. }
  29968. break;
  29969. default:
  29970. error('Unknown type: ' + type);
  29971. break;
  29972. }
  29973. }
  29974. if (useCMap) {
  29975. return extend(useCMap);
  29976. }
  29977. return cMap;
  29978. });
  29979. }
  29980. function BinaryCMapReader() {}
  29981. BinaryCMapReader.prototype = {
  29982. read: processBinaryCMap
  29983. };
  29984. return BinaryCMapReader;
  29985. })();
  29986. var CMapFactory = (function CMapFactoryClosure() {
  29987. function strToInt(str) {
  29988. var a = 0;
  29989. for (var i = 0; i < str.length; i++) {
  29990. a = (a << 8) | str.charCodeAt(i);
  29991. }
  29992. return a >>> 0;
  29993. }
  29994. function expectString(obj) {
  29995. if (!isString(obj)) {
  29996. error('Malformed CMap: expected string.');
  29997. }
  29998. }
  29999. function expectInt(obj) {
  30000. if (!isInt(obj)) {
  30001. error('Malformed CMap: expected int.');
  30002. }
  30003. }
  30004. function parseBfChar(cMap, lexer) {
  30005. while (true) {
  30006. var obj = lexer.getObj();
  30007. if (isEOF(obj)) {
  30008. break;
  30009. }
  30010. if (isCmd(obj, 'endbfchar')) {
  30011. return;
  30012. }
  30013. expectString(obj);
  30014. var src = strToInt(obj);
  30015. obj = lexer.getObj();
  30016. // TODO are /dstName used?
  30017. expectString(obj);
  30018. var dst = obj;
  30019. cMap.mapOne(src, dst);
  30020. }
  30021. }
  30022. function parseBfRange(cMap, lexer) {
  30023. while (true) {
  30024. var obj = lexer.getObj();
  30025. if (isEOF(obj)) {
  30026. break;
  30027. }
  30028. if (isCmd(obj, 'endbfrange')) {
  30029. return;
  30030. }
  30031. expectString(obj);
  30032. var low = strToInt(obj);
  30033. obj = lexer.getObj();
  30034. expectString(obj);
  30035. var high = strToInt(obj);
  30036. obj = lexer.getObj();
  30037. if (isInt(obj) || isString(obj)) {
  30038. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  30039. cMap.mapBfRange(low, high, dstLow);
  30040. } else if (isCmd(obj, '[')) {
  30041. obj = lexer.getObj();
  30042. var array = [];
  30043. while (!isCmd(obj, ']') && !isEOF(obj)) {
  30044. array.push(obj);
  30045. obj = lexer.getObj();
  30046. }
  30047. cMap.mapBfRangeToArray(low, high, array);
  30048. } else {
  30049. break;
  30050. }
  30051. }
  30052. error('Invalid bf range.');
  30053. }
  30054. function parseCidChar(cMap, lexer) {
  30055. while (true) {
  30056. var obj = lexer.getObj();
  30057. if (isEOF(obj)) {
  30058. break;
  30059. }
  30060. if (isCmd(obj, 'endcidchar')) {
  30061. return;
  30062. }
  30063. expectString(obj);
  30064. var src = strToInt(obj);
  30065. obj = lexer.getObj();
  30066. expectInt(obj);
  30067. var dst = obj;
  30068. cMap.mapOne(src, dst);
  30069. }
  30070. }
  30071. function parseCidRange(cMap, lexer) {
  30072. while (true) {
  30073. var obj = lexer.getObj();
  30074. if (isEOF(obj)) {
  30075. break;
  30076. }
  30077. if (isCmd(obj, 'endcidrange')) {
  30078. return;
  30079. }
  30080. expectString(obj);
  30081. var low = strToInt(obj);
  30082. obj = lexer.getObj();
  30083. expectString(obj);
  30084. var high = strToInt(obj);
  30085. obj = lexer.getObj();
  30086. expectInt(obj);
  30087. var dstLow = obj;
  30088. cMap.mapCidRange(low, high, dstLow);
  30089. }
  30090. }
  30091. function parseCodespaceRange(cMap, lexer) {
  30092. while (true) {
  30093. var obj = lexer.getObj();
  30094. if (isEOF(obj)) {
  30095. break;
  30096. }
  30097. if (isCmd(obj, 'endcodespacerange')) {
  30098. return;
  30099. }
  30100. if (!isString(obj)) {
  30101. break;
  30102. }
  30103. var low = strToInt(obj);
  30104. obj = lexer.getObj();
  30105. if (!isString(obj)) {
  30106. break;
  30107. }
  30108. var high = strToInt(obj);
  30109. cMap.addCodespaceRange(obj.length, low, high);
  30110. }
  30111. error('Invalid codespace range.');
  30112. }
  30113. function parseWMode(cMap, lexer) {
  30114. var obj = lexer.getObj();
  30115. if (isInt(obj)) {
  30116. cMap.vertical = !!obj;
  30117. }
  30118. }
  30119. function parseCMapName(cMap, lexer) {
  30120. var obj = lexer.getObj();
  30121. if (isName(obj) && isString(obj.name)) {
  30122. cMap.name = obj.name;
  30123. }
  30124. }
  30125. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  30126. var previous;
  30127. var embededUseCMap;
  30128. objLoop: while (true) {
  30129. try {
  30130. var obj = lexer.getObj();
  30131. if (isEOF(obj)) {
  30132. break;
  30133. } else if (isName(obj)) {
  30134. if (obj.name === 'WMode') {
  30135. parseWMode(cMap, lexer);
  30136. } else if (obj.name === 'CMapName') {
  30137. parseCMapName(cMap, lexer);
  30138. }
  30139. previous = obj;
  30140. } else if (isCmd(obj)) {
  30141. switch (obj.cmd) {
  30142. case 'endcmap':
  30143. break objLoop;
  30144. case 'usecmap':
  30145. if (isName(previous)) {
  30146. embededUseCMap = previous.name;
  30147. }
  30148. break;
  30149. case 'begincodespacerange':
  30150. parseCodespaceRange(cMap, lexer);
  30151. break;
  30152. case 'beginbfchar':
  30153. parseBfChar(cMap, lexer);
  30154. break;
  30155. case 'begincidchar':
  30156. parseCidChar(cMap, lexer);
  30157. break;
  30158. case 'beginbfrange':
  30159. parseBfRange(cMap, lexer);
  30160. break;
  30161. case 'begincidrange':
  30162. parseCidRange(cMap, lexer);
  30163. break;
  30164. }
  30165. }
  30166. } catch (ex) {
  30167. if (ex instanceof MissingDataException) {
  30168. throw ex;
  30169. }
  30170. warn('Invalid cMap data: ' + ex);
  30171. continue;
  30172. }
  30173. }
  30174. if (!useCMap && embededUseCMap) {
  30175. // Load the usecmap definition from the file only if there wasn't one
  30176. // specified.
  30177. useCMap = embededUseCMap;
  30178. }
  30179. if (useCMap) {
  30180. return extendCMap(cMap, builtInCMapParams, useCMap);
  30181. }
  30182. return Promise.resolve(cMap);
  30183. }
  30184. function extendCMap(cMap, builtInCMapParams, useCMap) {
  30185. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  30186. function(newCMap) {
  30187. cMap.useCMap = newCMap;
  30188. // If there aren't any code space ranges defined clone all the parent ones
  30189. // into this cMap.
  30190. if (cMap.numCodespaceRanges === 0) {
  30191. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  30192. for (var i = 0; i < useCodespaceRanges.length; i++) {
  30193. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  30194. }
  30195. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  30196. }
  30197. // Merge the map into the current one, making sure not to override
  30198. // any previously defined entries.
  30199. cMap.useCMap.forEach(function(key, value) {
  30200. if (!cMap.contains(key)) {
  30201. cMap.mapOne(key, cMap.useCMap.lookup(key));
  30202. }
  30203. });
  30204. return cMap;
  30205. });
  30206. }
  30207. function parseBinaryCMap(name, builtInCMapParams) {
  30208. var url = builtInCMapParams.url + name + '.bcmap';
  30209. var cMap = new CMap(true);
  30210. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  30211. return extendCMap(cMap, builtInCMapParams, useCMap);
  30212. });
  30213. }
  30214. function createBuiltInCMap(name, builtInCMapParams) {
  30215. if (name === 'Identity-H') {
  30216. return Promise.resolve(new IdentityCMap(false, 2));
  30217. } else if (name === 'Identity-V') {
  30218. return Promise.resolve(new IdentityCMap(true, 2));
  30219. }
  30220. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  30221. return Promise.reject(new Error('Unknown cMap name: ' + name));
  30222. }
  30223. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  30224. if (builtInCMapParams.packed) {
  30225. return parseBinaryCMap(name, builtInCMapParams);
  30226. }
  30227. return new Promise(function (resolve, reject) {
  30228. var url = builtInCMapParams.url + name;
  30229. var request = new XMLHttpRequest();
  30230. request.onreadystatechange = function () {
  30231. if (request.readyState === XMLHttpRequest.DONE) {
  30232. if (request.status === 200 || request.status === 0) {
  30233. var cMap = new CMap(true);
  30234. var lexer = new Lexer(new StringStream(request.responseText));
  30235. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  30236. function (parsedCMap) {
  30237. resolve(parsedCMap);
  30238. });
  30239. } else {
  30240. reject(new Error('Unable to get cMap at: ' + url));
  30241. }
  30242. }
  30243. };
  30244. request.open('GET', url, true);
  30245. request.send(null);
  30246. });
  30247. }
  30248. return {
  30249. create: function (encoding, builtInCMapParams, useCMap) {
  30250. if (isName(encoding)) {
  30251. return createBuiltInCMap(encoding.name, builtInCMapParams);
  30252. } else if (isStream(encoding)) {
  30253. var cMap = new CMap();
  30254. var lexer = new Lexer(encoding);
  30255. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  30256. function (parsedCMap) {
  30257. if (parsedCMap.isIdentityCMap) {
  30258. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  30259. }
  30260. return parsedCMap;
  30261. });
  30262. }
  30263. return Promise.reject(new Error('Encoding required.'));
  30264. }
  30265. };
  30266. })();
  30267. exports.CMap = CMap;
  30268. exports.CMapFactory = CMapFactory;
  30269. exports.IdentityCMap = IdentityCMap;
  30270. }));
  30271. (function (root, factory) {
  30272. {
  30273. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  30274. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  30275. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  30276. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  30277. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  30278. }
  30279. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  30280. coreGlyphList, coreFontRenderer, coreEncodings,
  30281. coreStandardFonts, coreUnicode, coreType1Parser,
  30282. coreCFFParser) {
  30283. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30284. var FontType = sharedUtil.FontType;
  30285. var assert = sharedUtil.assert;
  30286. var bytesToString = sharedUtil.bytesToString;
  30287. var error = sharedUtil.error;
  30288. var info = sharedUtil.info;
  30289. var isArray = sharedUtil.isArray;
  30290. var isInt = sharedUtil.isInt;
  30291. var isNum = sharedUtil.isNum;
  30292. var readUint32 = sharedUtil.readUint32;
  30293. var shadow = sharedUtil.shadow;
  30294. var string32 = sharedUtil.string32;
  30295. var warn = sharedUtil.warn;
  30296. var MissingDataException = sharedUtil.MissingDataException;
  30297. var isSpace = sharedUtil.isSpace;
  30298. var Stream = coreStream.Stream;
  30299. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  30300. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  30301. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30302. var StandardEncoding = coreEncodings.StandardEncoding;
  30303. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  30304. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  30305. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  30306. var getEncoding = coreEncodings.getEncoding;
  30307. var getStdFontMap = coreStandardFonts.getStdFontMap;
  30308. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  30309. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  30310. var getSupplementalGlyphMapForArialBlack =
  30311. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  30312. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  30313. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  30314. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  30315. var Type1Parser = coreType1Parser.Type1Parser;
  30316. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  30317. var CFFParser = coreCFFParser.CFFParser;
  30318. var CFFCompiler = coreCFFParser.CFFCompiler;
  30319. var CFF = coreCFFParser.CFF;
  30320. var CFFHeader = coreCFFParser.CFFHeader;
  30321. var CFFTopDict = coreCFFParser.CFFTopDict;
  30322. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  30323. var CFFStrings = coreCFFParser.CFFStrings;
  30324. var CFFIndex = coreCFFParser.CFFIndex;
  30325. var CFFCharset = coreCFFParser.CFFCharset;
  30326. // Unicode Private Use Area
  30327. var PRIVATE_USE_OFFSET_START = 0xE000;
  30328. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30329. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30330. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30331. // except for Type 3 fonts
  30332. var PDF_GLYPH_SPACE_UNITS = 1000;
  30333. // Accented charactars are not displayed properly on Windows, using this flag
  30334. // to control analysis of seac charstrings.
  30335. var SEAC_ANALYSIS_ENABLED = false;
  30336. var FontFlags = {
  30337. FixedPitch: 1,
  30338. Serif: 2,
  30339. Symbolic: 4,
  30340. Script: 8,
  30341. Nonsymbolic: 32,
  30342. Italic: 64,
  30343. AllCap: 65536,
  30344. SmallCap: 131072,
  30345. ForceBold: 262144
  30346. };
  30347. var MacStandardGlyphOrdering = [
  30348. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30349. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30350. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30351. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30352. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30353. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30354. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30355. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30356. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30357. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30358. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30359. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30360. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30361. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30362. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30363. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30364. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30365. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30366. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30367. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30368. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30369. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30370. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30371. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30372. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30373. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30374. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30375. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30376. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30377. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30378. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30379. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30380. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30381. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30382. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30383. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30384. function adjustWidths(properties) {
  30385. if (!properties.fontMatrix) {
  30386. return;
  30387. }
  30388. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  30389. return;
  30390. }
  30391. // adjusting width to fontMatrix scale
  30392. var scale = 0.001 / properties.fontMatrix[0];
  30393. var glyphsWidths = properties.widths;
  30394. for (var glyph in glyphsWidths) {
  30395. glyphsWidths[glyph] *= scale;
  30396. }
  30397. properties.defaultWidth *= scale;
  30398. }
  30399. function getFontType(type, subtype) {
  30400. switch (type) {
  30401. case 'Type1':
  30402. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  30403. case 'CIDFontType0':
  30404. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  30405. FontType.CIDFONTTYPE0;
  30406. case 'OpenType':
  30407. return FontType.OPENTYPE;
  30408. case 'TrueType':
  30409. return FontType.TRUETYPE;
  30410. case 'CIDFontType2':
  30411. return FontType.CIDFONTTYPE2;
  30412. case 'MMType1':
  30413. return FontType.MMTYPE1;
  30414. case 'Type0':
  30415. return FontType.TYPE0;
  30416. default:
  30417. return FontType.UNKNOWN;
  30418. }
  30419. }
  30420. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  30421. // in a 'uniXXXX' format -- attempting to recover proper ones.
  30422. function recoverGlyphName(name, glyphsUnicodeMap) {
  30423. if (glyphsUnicodeMap[name] !== undefined) {
  30424. return name;
  30425. }
  30426. // The glyph name is non-standard, trying to recover.
  30427. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  30428. if (unicode !== -1) {
  30429. for (var key in glyphsUnicodeMap) {
  30430. if (glyphsUnicodeMap[key] === unicode) {
  30431. return key;
  30432. }
  30433. }
  30434. }
  30435. info('Unable to recover a standard glyph name for: ' + name);
  30436. return name;
  30437. }
  30438. var Glyph = (function GlyphClosure() {
  30439. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  30440. isSpace, isInFont) {
  30441. this.fontChar = fontChar;
  30442. this.unicode = unicode;
  30443. this.accent = accent;
  30444. this.width = width;
  30445. this.vmetric = vmetric;
  30446. this.operatorListId = operatorListId;
  30447. this.isSpace = isSpace;
  30448. this.isInFont = isInFont;
  30449. }
  30450. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  30451. vmetric, operatorListId, isSpace,
  30452. isInFont) {
  30453. return this.fontChar === fontChar &&
  30454. this.unicode === unicode &&
  30455. this.accent === accent &&
  30456. this.width === width &&
  30457. this.vmetric === vmetric &&
  30458. this.operatorListId === operatorListId &&
  30459. this.isSpace === isSpace &&
  30460. this.isInFont === isInFont;
  30461. };
  30462. return Glyph;
  30463. })();
  30464. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  30465. function ToUnicodeMap(cmap) {
  30466. // The elements of this._map can be integers or strings, depending on how
  30467. // |cmap| was created.
  30468. this._map = cmap;
  30469. }
  30470. ToUnicodeMap.prototype = {
  30471. get length() {
  30472. return this._map.length;
  30473. },
  30474. forEach: function(callback) {
  30475. for (var charCode in this._map) {
  30476. callback(charCode, this._map[charCode].charCodeAt(0));
  30477. }
  30478. },
  30479. has: function(i) {
  30480. return this._map[i] !== undefined;
  30481. },
  30482. get: function(i) {
  30483. return this._map[i];
  30484. },
  30485. charCodeOf: function(v) {
  30486. return this._map.indexOf(v);
  30487. }
  30488. };
  30489. return ToUnicodeMap;
  30490. })();
  30491. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  30492. function IdentityToUnicodeMap(firstChar, lastChar) {
  30493. this.firstChar = firstChar;
  30494. this.lastChar = lastChar;
  30495. }
  30496. IdentityToUnicodeMap.prototype = {
  30497. get length() {
  30498. return (this.lastChar + 1) - this.firstChar;
  30499. },
  30500. forEach: function (callback) {
  30501. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  30502. callback(i, i);
  30503. }
  30504. },
  30505. has: function (i) {
  30506. return this.firstChar <= i && i <= this.lastChar;
  30507. },
  30508. get: function (i) {
  30509. if (this.firstChar <= i && i <= this.lastChar) {
  30510. return String.fromCharCode(i);
  30511. }
  30512. return undefined;
  30513. },
  30514. charCodeOf: function (v) {
  30515. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  30516. }
  30517. };
  30518. return IdentityToUnicodeMap;
  30519. })();
  30520. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  30521. function writeInt16(dest, offset, num) {
  30522. dest[offset] = (num >> 8) & 0xFF;
  30523. dest[offset + 1] = num & 0xFF;
  30524. }
  30525. function writeInt32(dest, offset, num) {
  30526. dest[offset] = (num >> 24) & 0xFF;
  30527. dest[offset + 1] = (num >> 16) & 0xFF;
  30528. dest[offset + 2] = (num >> 8) & 0xFF;
  30529. dest[offset + 3] = num & 0xFF;
  30530. }
  30531. function writeData(dest, offset, data) {
  30532. var i, ii;
  30533. if (data instanceof Uint8Array) {
  30534. dest.set(data, offset);
  30535. } else if (typeof data === 'string') {
  30536. for (i = 0, ii = data.length; i < ii; i++) {
  30537. dest[offset++] = data.charCodeAt(i) & 0xFF;
  30538. }
  30539. } else {
  30540. // treating everything else as array
  30541. for (i = 0, ii = data.length; i < ii; i++) {
  30542. dest[offset++] = data[i] & 0xFF;
  30543. }
  30544. }
  30545. }
  30546. function OpenTypeFileBuilder(sfnt) {
  30547. this.sfnt = sfnt;
  30548. this.tables = Object.create(null);
  30549. }
  30550. OpenTypeFileBuilder.getSearchParams =
  30551. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  30552. var maxPower2 = 1, log2 = 0;
  30553. while ((maxPower2 ^ entriesCount) > maxPower2) {
  30554. maxPower2 <<= 1;
  30555. log2++;
  30556. }
  30557. var searchRange = maxPower2 * entrySize;
  30558. return {
  30559. range: searchRange,
  30560. entry: log2,
  30561. rangeShift: entrySize * entriesCount - searchRange
  30562. };
  30563. };
  30564. var OTF_HEADER_SIZE = 12;
  30565. var OTF_TABLE_ENTRY_SIZE = 16;
  30566. OpenTypeFileBuilder.prototype = {
  30567. toArray: function OpenTypeFileBuilder_toArray() {
  30568. var sfnt = this.sfnt;
  30569. // Tables needs to be written by ascendant alphabetic order
  30570. var tables = this.tables;
  30571. var tablesNames = Object.keys(tables);
  30572. tablesNames.sort();
  30573. var numTables = tablesNames.length;
  30574. var i, j, jj, table, tableName;
  30575. // layout the tables data
  30576. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  30577. var tableOffsets = [offset];
  30578. for (i = 0; i < numTables; i++) {
  30579. table = tables[tablesNames[i]];
  30580. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  30581. offset += paddedLength;
  30582. tableOffsets.push(offset);
  30583. }
  30584. var file = new Uint8Array(offset);
  30585. // write the table data first (mostly for checksum)
  30586. for (i = 0; i < numTables; i++) {
  30587. table = tables[tablesNames[i]];
  30588. writeData(file, tableOffsets[i], table);
  30589. }
  30590. // sfnt version (4 bytes)
  30591. if (sfnt === 'true') {
  30592. // Windows hates the Mac TrueType sfnt version number
  30593. sfnt = string32(0x00010000);
  30594. }
  30595. file[0] = sfnt.charCodeAt(0) & 0xFF;
  30596. file[1] = sfnt.charCodeAt(1) & 0xFF;
  30597. file[2] = sfnt.charCodeAt(2) & 0xFF;
  30598. file[3] = sfnt.charCodeAt(3) & 0xFF;
  30599. // numTables (2 bytes)
  30600. writeInt16(file, 4, numTables);
  30601. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  30602. // searchRange (2 bytes)
  30603. writeInt16(file, 6, searchParams.range);
  30604. // entrySelector (2 bytes)
  30605. writeInt16(file, 8, searchParams.entry);
  30606. // rangeShift (2 bytes)
  30607. writeInt16(file, 10, searchParams.rangeShift);
  30608. offset = OTF_HEADER_SIZE;
  30609. // writing table entries
  30610. for (i = 0; i < numTables; i++) {
  30611. tableName = tablesNames[i];
  30612. file[offset] = tableName.charCodeAt(0) & 0xFF;
  30613. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  30614. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  30615. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  30616. // checksum
  30617. var checksum = 0;
  30618. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  30619. var quad = readUint32(file, j);
  30620. checksum = (checksum + quad) >>> 0;
  30621. }
  30622. writeInt32(file, offset + 4, checksum);
  30623. // offset
  30624. writeInt32(file, offset + 8, tableOffsets[i]);
  30625. // length
  30626. writeInt32(file, offset + 12, tables[tableName].length);
  30627. offset += OTF_TABLE_ENTRY_SIZE;
  30628. }
  30629. return file;
  30630. },
  30631. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  30632. if (tag in this.tables) {
  30633. throw new Error('Table ' + tag + ' already exists');
  30634. }
  30635. this.tables[tag] = data;
  30636. }
  30637. };
  30638. return OpenTypeFileBuilder;
  30639. })();
  30640. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  30641. // issues when they are painted on the canvas, e.g. complex-script shaping or
  30642. // control/whitespace characters. The ranges are listed in pairs: the first item
  30643. // is a code of the first problematic code, the second one is the next
  30644. // non-problematic code. The ranges must be in sorted order.
  30645. var ProblematicCharRanges = new Int32Array([
  30646. // Control characters.
  30647. 0x0000, 0x0020,
  30648. 0x007F, 0x00A1,
  30649. 0x00AD, 0x00AE,
  30650. // Chars that is used in complex-script shaping.
  30651. 0x0600, 0x0780,
  30652. 0x08A0, 0x10A0,
  30653. 0x1780, 0x1800,
  30654. 0x1C00, 0x1C50,
  30655. // General punctuation chars.
  30656. 0x2000, 0x2010,
  30657. 0x2011, 0x2012,
  30658. 0x2028, 0x2030,
  30659. 0x205F, 0x2070,
  30660. 0x25CC, 0x25CD,
  30661. 0x3000, 0x3001,
  30662. // Chars that is used in complex-script shaping.
  30663. 0xAA60, 0xAA80,
  30664. // Specials Unicode block.
  30665. 0xFFF0, 0x10000
  30666. ]);
  30667. /**
  30668. * 'Font' is the class the outside world should use, it encapsulate all the font
  30669. * decoding logics whatever type it is (assuming the font type is supported).
  30670. *
  30671. * For example to read a Type1 font and to attach it to the document:
  30672. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  30673. * type1Font.bind();
  30674. */
  30675. var Font = (function FontClosure() {
  30676. function Font(name, file, properties) {
  30677. var charCode, glyphName, unicode;
  30678. this.name = name;
  30679. this.loadedName = properties.loadedName;
  30680. this.isType3Font = properties.isType3Font;
  30681. this.sizes = [];
  30682. this.missingFile = false;
  30683. this.glyphCache = Object.create(null);
  30684. var names = name.split('+');
  30685. names = names.length > 1 ? names[1] : names[0];
  30686. names = names.split(/[-,_]/g)[0];
  30687. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  30688. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  30689. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  30690. var type = properties.type;
  30691. var subtype = properties.subtype;
  30692. this.type = type;
  30693. this.fallbackName = (this.isMonospace ? 'monospace' :
  30694. (this.isSerifFont ? 'serif' : 'sans-serif'));
  30695. this.differences = properties.differences;
  30696. this.widths = properties.widths;
  30697. this.defaultWidth = properties.defaultWidth;
  30698. this.composite = properties.composite;
  30699. this.wideChars = properties.wideChars;
  30700. this.cMap = properties.cMap;
  30701. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  30702. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  30703. this.fontMatrix = properties.fontMatrix;
  30704. this.bbox = properties.bbox;
  30705. this.toUnicode = properties.toUnicode;
  30706. this.toFontChar = [];
  30707. if (properties.type === 'Type3') {
  30708. for (charCode = 0; charCode < 256; charCode++) {
  30709. this.toFontChar[charCode] = (this.differences[charCode] ||
  30710. properties.defaultEncoding[charCode]);
  30711. }
  30712. this.fontType = FontType.TYPE3;
  30713. return;
  30714. }
  30715. this.cidEncoding = properties.cidEncoding;
  30716. this.vertical = properties.vertical;
  30717. if (this.vertical) {
  30718. this.vmetrics = properties.vmetrics;
  30719. this.defaultVMetrics = properties.defaultVMetrics;
  30720. }
  30721. var glyphsUnicodeMap;
  30722. if (!file || file.isEmpty) {
  30723. if (file) {
  30724. // Some bad PDF generators will include empty font files,
  30725. // attempting to recover by assuming that no file exists.
  30726. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  30727. }
  30728. this.missingFile = true;
  30729. // The file data is not specified. Trying to fix the font name
  30730. // to be used with the canvas.font.
  30731. var fontName = name.replace(/[,_]/g, '-');
  30732. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  30733. var isStandardFont = !!stdFontMap[fontName] ||
  30734. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  30735. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  30736. this.bold = (fontName.search(/bold/gi) !== -1);
  30737. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  30738. (fontName.search(/italic/gi) !== -1));
  30739. // Use 'name' instead of 'fontName' here because the original
  30740. // name ArialBlack for example will be replaced by Helvetica.
  30741. this.black = (name.search(/Black/g) !== -1);
  30742. // if at least one width is present, remeasure all chars when exists
  30743. this.remeasure = Object.keys(this.widths).length > 0;
  30744. if (isStandardFont && type === 'CIDFontType2' &&
  30745. properties.cidEncoding.indexOf('Identity-') === 0) {
  30746. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  30747. // Standard fonts might be embedded as CID font without glyph mapping.
  30748. // Building one based on GlyphMapForStandardFonts.
  30749. var map = [];
  30750. for (charCode in GlyphMapForStandardFonts) {
  30751. map[+charCode] = GlyphMapForStandardFonts[charCode];
  30752. }
  30753. if (/ArialBlack/i.test(name)) {
  30754. var SupplementalGlyphMapForArialBlack =
  30755. getSupplementalGlyphMapForArialBlack();
  30756. for (charCode in SupplementalGlyphMapForArialBlack) {
  30757. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  30758. }
  30759. }
  30760. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  30761. if (!isIdentityUnicode) {
  30762. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30763. map[+charCode] = unicodeCharCode;
  30764. });
  30765. }
  30766. this.toFontChar = map;
  30767. this.toUnicode = new ToUnicodeMap(map);
  30768. } else if (/Symbol/i.test(fontName)) {
  30769. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  30770. properties.differences);
  30771. } else if (/Dingbats/i.test(fontName)) {
  30772. if (/Wingdings/i.test(name)) {
  30773. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  30774. }
  30775. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  30776. getDingbatsGlyphsUnicode(),
  30777. properties.differences);
  30778. } else if (isStandardFont) {
  30779. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  30780. getGlyphsUnicode(),
  30781. properties.differences);
  30782. } else {
  30783. glyphsUnicodeMap = getGlyphsUnicode();
  30784. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30785. if (!this.composite) {
  30786. glyphName = (properties.differences[charCode] ||
  30787. properties.defaultEncoding[charCode]);
  30788. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  30789. if (unicode !== -1) {
  30790. unicodeCharCode = unicode;
  30791. }
  30792. }
  30793. this.toFontChar[charCode] = unicodeCharCode;
  30794. }.bind(this));
  30795. }
  30796. this.loadedName = fontName.split('-')[0];
  30797. this.loading = false;
  30798. this.fontType = getFontType(type, subtype);
  30799. return;
  30800. }
  30801. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  30802. if (subtype === 'Type1C') {
  30803. if (type !== 'Type1' && type !== 'MMType1') {
  30804. // Some TrueType fonts by mistake claim Type1C
  30805. if (isTrueTypeFile(file)) {
  30806. subtype = 'TrueType';
  30807. } else {
  30808. type = 'Type1';
  30809. }
  30810. } else if (isOpenTypeFile(file)) {
  30811. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  30812. type = subtype = 'OpenType';
  30813. }
  30814. }
  30815. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  30816. type = 'CIDFontType0';
  30817. }
  30818. if (subtype === 'OpenType') {
  30819. type = 'OpenType';
  30820. }
  30821. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  30822. if (type === 'CIDFontType0') {
  30823. if (isType1File(file)) {
  30824. subtype = 'CIDFontType0';
  30825. } else if (isOpenTypeFile(file)) {
  30826. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  30827. type = subtype = 'OpenType';
  30828. } else {
  30829. subtype = 'CIDFontType0C';
  30830. }
  30831. }
  30832. var data;
  30833. switch (type) {
  30834. case 'MMType1':
  30835. info('MMType1 font (' + name + '), falling back to Type1.');
  30836. /* falls through */
  30837. case 'Type1':
  30838. case 'CIDFontType0':
  30839. this.mimetype = 'font/opentype';
  30840. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  30841. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  30842. adjustWidths(properties);
  30843. // Wrap the CFF data inside an OTF font file
  30844. data = this.convert(name, cff, properties);
  30845. break;
  30846. case 'OpenType':
  30847. case 'TrueType':
  30848. case 'CIDFontType2':
  30849. this.mimetype = 'font/opentype';
  30850. // Repair the TrueType file. It is can be damaged in the point of
  30851. // view of the sanitizer
  30852. data = this.checkAndRepair(name, file, properties);
  30853. if (this.isOpenType) {
  30854. adjustWidths(properties);
  30855. type = 'OpenType';
  30856. }
  30857. break;
  30858. default:
  30859. error('Font ' + type + ' is not supported');
  30860. break;
  30861. }
  30862. this.data = data;
  30863. this.fontType = getFontType(type, subtype);
  30864. // Transfer some properties again that could change during font conversion
  30865. this.fontMatrix = properties.fontMatrix;
  30866. this.widths = properties.widths;
  30867. this.defaultWidth = properties.defaultWidth;
  30868. this.encoding = properties.baseEncoding;
  30869. this.seacMap = properties.seacMap;
  30870. this.loading = true;
  30871. }
  30872. Font.getFontID = (function () {
  30873. var ID = 1;
  30874. return function Font_getFontID() {
  30875. return String(ID++);
  30876. };
  30877. })();
  30878. function int16(b0, b1) {
  30879. return (b0 << 8) + b1;
  30880. }
  30881. function signedInt16(b0, b1) {
  30882. var value = (b0 << 8) + b1;
  30883. return value & (1 << 15) ? value - 0x10000 : value;
  30884. }
  30885. function int32(b0, b1, b2, b3) {
  30886. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30887. }
  30888. function string16(value) {
  30889. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  30890. }
  30891. function safeString16(value) {
  30892. // clamp value to the 16-bit int range
  30893. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  30894. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  30895. }
  30896. function isTrueTypeFile(file) {
  30897. var header = file.peekBytes(4);
  30898. return readUint32(header, 0) === 0x00010000;
  30899. }
  30900. function isOpenTypeFile(file) {
  30901. var header = file.peekBytes(4);
  30902. return bytesToString(header) === 'OTTO';
  30903. }
  30904. function isType1File(file) {
  30905. var header = file.peekBytes(2);
  30906. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  30907. if (header[0] === 0x25 && header[1] === 0x21) {
  30908. return true;
  30909. }
  30910. // ... obviously some fonts violate that part of the specification,
  30911. // please refer to the comment in |Type1Font| below.
  30912. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  30913. return true;
  30914. }
  30915. return false;
  30916. }
  30917. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  30918. var toFontChar = [], unicode;
  30919. for (var i = 0, ii = encoding.length; i < ii; i++) {
  30920. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  30921. if (unicode !== -1) {
  30922. toFontChar[i] = unicode;
  30923. }
  30924. }
  30925. for (var charCode in differences) {
  30926. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  30927. if (unicode !== -1) {
  30928. toFontChar[+charCode] = unicode;
  30929. }
  30930. }
  30931. return toFontChar;
  30932. }
  30933. /**
  30934. * Helper function for |adjustMapping|.
  30935. * @return {boolean}
  30936. */
  30937. function isProblematicUnicodeLocation(code) {
  30938. // Using binary search to find a range start.
  30939. var i = 0, j = ProblematicCharRanges.length - 1;
  30940. while (i < j) {
  30941. var c = (i + j + 1) >> 1;
  30942. if (code < ProblematicCharRanges[c]) {
  30943. j = c - 1;
  30944. } else {
  30945. i = c;
  30946. }
  30947. }
  30948. // Even index means code in problematic range.
  30949. return !(i & 1);
  30950. }
  30951. /**
  30952. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  30953. * with their unicode value. It also moves char codes that are in known
  30954. * problematic locations.
  30955. * @return {Object} Two properties:
  30956. * 'toFontChar' - maps original char codes(the value that will be read
  30957. * from commands such as show text) to the char codes that will be used in the
  30958. * font that we build
  30959. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  30960. */
  30961. function adjustMapping(charCodeToGlyphId, properties) {
  30962. var toUnicode = properties.toUnicode;
  30963. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  30964. var isIdentityUnicode =
  30965. properties.toUnicode instanceof IdentityToUnicodeMap;
  30966. var newMap = Object.create(null);
  30967. var toFontChar = [];
  30968. var usedFontCharCodes = [];
  30969. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  30970. for (var originalCharCode in charCodeToGlyphId) {
  30971. originalCharCode |= 0;
  30972. var glyphId = charCodeToGlyphId[originalCharCode];
  30973. var fontCharCode = originalCharCode;
  30974. // First try to map the value to a unicode position if a non identity map
  30975. // was created.
  30976. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  30977. var unicode = toUnicode.get(fontCharCode);
  30978. // TODO: Try to map ligatures to the correct spot.
  30979. if (unicode.length === 1) {
  30980. fontCharCode = unicode.charCodeAt(0);
  30981. }
  30982. }
  30983. // Try to move control characters, special characters and already mapped
  30984. // characters to the private use area since they will not be drawn by
  30985. // canvas if left in their current position. Also, move characters if the
  30986. // font was symbolic and there is only an identity unicode map since the
  30987. // characters probably aren't in the correct position (fixes an issue
  30988. // with firefox and thuluthfont).
  30989. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  30990. isProblematicUnicodeLocation(fontCharCode) ||
  30991. (isSymbolic && isIdentityUnicode)) &&
  30992. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  30993. // Loop to try and find a free spot in the private use area.
  30994. do {
  30995. fontCharCode = nextAvailableFontCharCode++;
  30996. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  30997. fontCharCode = 0xF020;
  30998. nextAvailableFontCharCode = fontCharCode + 1;
  30999. }
  31000. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  31001. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  31002. }
  31003. newMap[fontCharCode] = glyphId;
  31004. toFontChar[originalCharCode] = fontCharCode;
  31005. usedFontCharCodes[fontCharCode] = true;
  31006. }
  31007. return {
  31008. toFontChar: toFontChar,
  31009. charCodeToGlyphId: newMap,
  31010. nextAvailableFontCharCode: nextAvailableFontCharCode
  31011. };
  31012. }
  31013. function getRanges(glyphs, numGlyphs) {
  31014. // Array.sort() sorts by characters, not numerically, so convert to an
  31015. // array of characters.
  31016. var codes = [];
  31017. for (var charCode in glyphs) {
  31018. // Remove an invalid glyph ID mappings to make OTS happy.
  31019. if (glyphs[charCode] >= numGlyphs) {
  31020. continue;
  31021. }
  31022. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  31023. }
  31024. codes.sort(function fontGetRangesSort(a, b) {
  31025. return a.fontCharCode - b.fontCharCode;
  31026. });
  31027. // Split the sorted codes into ranges.
  31028. var ranges = [];
  31029. var length = codes.length;
  31030. for (var n = 0; n < length; ) {
  31031. var start = codes[n].fontCharCode;
  31032. var codeIndices = [codes[n].glyphId];
  31033. ++n;
  31034. var end = start;
  31035. while (n < length && end + 1 === codes[n].fontCharCode) {
  31036. codeIndices.push(codes[n].glyphId);
  31037. ++end;
  31038. ++n;
  31039. if (end === 0xFFFF) {
  31040. break;
  31041. }
  31042. }
  31043. ranges.push([start, end, codeIndices]);
  31044. }
  31045. return ranges;
  31046. }
  31047. function createCmapTable(glyphs, numGlyphs) {
  31048. var ranges = getRanges(glyphs, numGlyphs);
  31049. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  31050. var cmap = '\x00\x00' + // version
  31051. string16(numTables) + // numTables
  31052. '\x00\x03' + // platformID
  31053. '\x00\x01' + // encodingID
  31054. string32(4 + numTables * 8); // start of the table record
  31055. var i, ii, j, jj;
  31056. for (i = ranges.length - 1; i >= 0; --i) {
  31057. if (ranges[i][0] <= 0xFFFF) { break; }
  31058. }
  31059. var bmpLength = i + 1;
  31060. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  31061. ranges[i][1] = 0xFFFE;
  31062. }
  31063. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  31064. var segCount = bmpLength + trailingRangesCount;
  31065. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  31066. // Fill up the 4 parallel arrays describing the segments.
  31067. var startCount = '';
  31068. var endCount = '';
  31069. var idDeltas = '';
  31070. var idRangeOffsets = '';
  31071. var glyphsIds = '';
  31072. var bias = 0;
  31073. var range, start, end, codes;
  31074. for (i = 0, ii = bmpLength; i < ii; i++) {
  31075. range = ranges[i];
  31076. start = range[0];
  31077. end = range[1];
  31078. startCount += string16(start);
  31079. endCount += string16(end);
  31080. codes = range[2];
  31081. var contiguous = true;
  31082. for (j = 1, jj = codes.length; j < jj; ++j) {
  31083. if (codes[j] !== codes[j - 1] + 1) {
  31084. contiguous = false;
  31085. break;
  31086. }
  31087. }
  31088. if (!contiguous) {
  31089. var offset = (segCount - i) * 2 + bias * 2;
  31090. bias += (end - start + 1);
  31091. idDeltas += string16(0);
  31092. idRangeOffsets += string16(offset);
  31093. for (j = 0, jj = codes.length; j < jj; ++j) {
  31094. glyphsIds += string16(codes[j]);
  31095. }
  31096. } else {
  31097. var startCode = codes[0];
  31098. idDeltas += string16((startCode - start) & 0xFFFF);
  31099. idRangeOffsets += string16(0);
  31100. }
  31101. }
  31102. if (trailingRangesCount > 0) {
  31103. endCount += '\xFF\xFF';
  31104. startCount += '\xFF\xFF';
  31105. idDeltas += '\x00\x01';
  31106. idRangeOffsets += '\x00\x00';
  31107. }
  31108. var format314 = '\x00\x00' + // language
  31109. string16(2 * segCount) +
  31110. string16(searchParams.range) +
  31111. string16(searchParams.entry) +
  31112. string16(searchParams.rangeShift) +
  31113. endCount + '\x00\x00' + startCount +
  31114. idDeltas + idRangeOffsets + glyphsIds;
  31115. var format31012 = '';
  31116. var header31012 = '';
  31117. if (numTables > 1) {
  31118. cmap += '\x00\x03' + // platformID
  31119. '\x00\x0A' + // encodingID
  31120. string32(4 + numTables * 8 +
  31121. 4 + format314.length); // start of the table record
  31122. format31012 = '';
  31123. for (i = 0, ii = ranges.length; i < ii; i++) {
  31124. range = ranges[i];
  31125. start = range[0];
  31126. codes = range[2];
  31127. var code = codes[0];
  31128. for (j = 1, jj = codes.length; j < jj; ++j) {
  31129. if (codes[j] !== codes[j - 1] + 1) {
  31130. end = range[0] + j - 1;
  31131. format31012 += string32(start) + // startCharCode
  31132. string32(end) + // endCharCode
  31133. string32(code); // startGlyphID
  31134. start = end + 1;
  31135. code = codes[j];
  31136. }
  31137. }
  31138. format31012 += string32(start) + // startCharCode
  31139. string32(range[1]) + // endCharCode
  31140. string32(code); // startGlyphID
  31141. }
  31142. header31012 = '\x00\x0C' + // format
  31143. '\x00\x00' + // reserved
  31144. string32(format31012.length + 16) + // length
  31145. '\x00\x00\x00\x00' + // language
  31146. string32(format31012.length / 12); // nGroups
  31147. }
  31148. return cmap + '\x00\x04' + // format
  31149. string16(format314.length + 4) + // length
  31150. format314 + header31012 + format31012;
  31151. }
  31152. function validateOS2Table(os2) {
  31153. var stream = new Stream(os2.data);
  31154. var version = stream.getUint16();
  31155. // TODO verify all OS/2 tables fields, but currently we validate only those
  31156. // that give us issues
  31157. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  31158. var selection = stream.getUint16();
  31159. if (version < 4 && (selection & 0x0300)) {
  31160. return false;
  31161. }
  31162. var firstChar = stream.getUint16();
  31163. var lastChar = stream.getUint16();
  31164. if (firstChar > lastChar) {
  31165. return false;
  31166. }
  31167. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  31168. var usWinAscent = stream.getUint16();
  31169. if (usWinAscent === 0) { // makes font unreadable by windows
  31170. return false;
  31171. }
  31172. // OS/2 appears to be valid, resetting some fields
  31173. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  31174. return true;
  31175. }
  31176. function createOS2Table(properties, charstrings, override) {
  31177. override = override || {
  31178. unitsPerEm: 0,
  31179. yMax: 0,
  31180. yMin: 0,
  31181. ascent: 0,
  31182. descent: 0
  31183. };
  31184. var ulUnicodeRange1 = 0;
  31185. var ulUnicodeRange2 = 0;
  31186. var ulUnicodeRange3 = 0;
  31187. var ulUnicodeRange4 = 0;
  31188. var firstCharIndex = null;
  31189. var lastCharIndex = 0;
  31190. if (charstrings) {
  31191. for (var code in charstrings) {
  31192. code |= 0;
  31193. if (firstCharIndex > code || !firstCharIndex) {
  31194. firstCharIndex = code;
  31195. }
  31196. if (lastCharIndex < code) {
  31197. lastCharIndex = code;
  31198. }
  31199. var position = getUnicodeRangeFor(code);
  31200. if (position < 32) {
  31201. ulUnicodeRange1 |= 1 << position;
  31202. } else if (position < 64) {
  31203. ulUnicodeRange2 |= 1 << position - 32;
  31204. } else if (position < 96) {
  31205. ulUnicodeRange3 |= 1 << position - 64;
  31206. } else if (position < 123) {
  31207. ulUnicodeRange4 |= 1 << position - 96;
  31208. } else {
  31209. error('Unicode ranges Bits > 123 are reserved for internal usage');
  31210. }
  31211. }
  31212. } else {
  31213. // TODO
  31214. firstCharIndex = 0;
  31215. lastCharIndex = 255;
  31216. }
  31217. var bbox = properties.bbox || [0, 0, 0, 0];
  31218. var unitsPerEm = (override.unitsPerEm ||
  31219. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  31220. // if the font units differ to the PDF glyph space units
  31221. // then scale up the values
  31222. var scale = (properties.ascentScaled ? 1.0 :
  31223. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  31224. var typoAscent = (override.ascent ||
  31225. Math.round(scale * (properties.ascent || bbox[3])));
  31226. var typoDescent = (override.descent ||
  31227. Math.round(scale * (properties.descent || bbox[1])));
  31228. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  31229. typoDescent = -typoDescent; // fixing incorrect descent
  31230. }
  31231. var winAscent = override.yMax || typoAscent;
  31232. var winDescent = -override.yMin || -typoDescent;
  31233. return '\x00\x03' + // version
  31234. '\x02\x24' + // xAvgCharWidth
  31235. '\x01\xF4' + // usWeightClass
  31236. '\x00\x05' + // usWidthClass
  31237. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  31238. '\x02\x8A' + // ySubscriptXSize
  31239. '\x02\xBB' + // ySubscriptYSize
  31240. '\x00\x00' + // ySubscriptXOffset
  31241. '\x00\x8C' + // ySubscriptYOffset
  31242. '\x02\x8A' + // ySuperScriptXSize
  31243. '\x02\xBB' + // ySuperScriptYSize
  31244. '\x00\x00' + // ySuperScriptXOffset
  31245. '\x01\xDF' + // ySuperScriptYOffset
  31246. '\x00\x31' + // yStrikeOutSize
  31247. '\x01\x02' + // yStrikeOutPosition
  31248. '\x00\x00' + // sFamilyClass
  31249. '\x00\x00\x06' +
  31250. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  31251. '\x00\x00\x00\x00\x00\x00' + // Panose
  31252. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  31253. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  31254. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  31255. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  31256. '\x2A\x32\x31\x2A' + // achVendID
  31257. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  31258. string16(firstCharIndex ||
  31259. properties.firstChar) + // usFirstCharIndex
  31260. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  31261. string16(typoAscent) + // sTypoAscender
  31262. string16(typoDescent) + // sTypoDescender
  31263. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  31264. string16(winAscent) + // usWinAscent
  31265. string16(winDescent) + // usWinDescent
  31266. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  31267. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  31268. string16(properties.xHeight) + // sxHeight
  31269. string16(properties.capHeight) + // sCapHeight
  31270. string16(0) + // usDefaultChar
  31271. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  31272. '\x00\x03'; // usMaxContext
  31273. }
  31274. function createPostTable(properties) {
  31275. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  31276. return ('\x00\x03\x00\x00' + // Version number
  31277. string32(angle) + // italicAngle
  31278. '\x00\x00' + // underlinePosition
  31279. '\x00\x00' + // underlineThickness
  31280. string32(properties.fixedPitch) + // isFixedPitch
  31281. '\x00\x00\x00\x00' + // minMemType42
  31282. '\x00\x00\x00\x00' + // maxMemType42
  31283. '\x00\x00\x00\x00' + // minMemType1
  31284. '\x00\x00\x00\x00'); // maxMemType1
  31285. }
  31286. function createNameTable(name, proto) {
  31287. if (!proto) {
  31288. proto = [[], []]; // no strings and unicode strings
  31289. }
  31290. var strings = [
  31291. proto[0][0] || 'Original licence', // 0.Copyright
  31292. proto[0][1] || name, // 1.Font family
  31293. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  31294. proto[0][3] || 'uniqueID', // 3.Unique ID
  31295. proto[0][4] || name, // 4.Full font name
  31296. proto[0][5] || 'Version 0.11', // 5.Version
  31297. proto[0][6] || '', // 6.Postscript name
  31298. proto[0][7] || 'Unknown', // 7.Trademark
  31299. proto[0][8] || 'Unknown', // 8.Manufacturer
  31300. proto[0][9] || 'Unknown' // 9.Designer
  31301. ];
  31302. // Mac want 1-byte per character strings while Windows want
  31303. // 2-bytes per character, so duplicate the names table
  31304. var stringsUnicode = [];
  31305. var i, ii, j, jj, str;
  31306. for (i = 0, ii = strings.length; i < ii; i++) {
  31307. str = proto[1][i] || strings[i];
  31308. var strBufUnicode = [];
  31309. for (j = 0, jj = str.length; j < jj; j++) {
  31310. strBufUnicode.push(string16(str.charCodeAt(j)));
  31311. }
  31312. stringsUnicode.push(strBufUnicode.join(''));
  31313. }
  31314. var names = [strings, stringsUnicode];
  31315. var platforms = ['\x00\x01', '\x00\x03'];
  31316. var encodings = ['\x00\x00', '\x00\x01'];
  31317. var languages = ['\x00\x00', '\x04\x09'];
  31318. var namesRecordCount = strings.length * platforms.length;
  31319. var nameTable =
  31320. '\x00\x00' + // format
  31321. string16(namesRecordCount) + // Number of names Record
  31322. string16(namesRecordCount * 12 + 6); // Storage
  31323. // Build the name records field
  31324. var strOffset = 0;
  31325. for (i = 0, ii = platforms.length; i < ii; i++) {
  31326. var strs = names[i];
  31327. for (j = 0, jj = strs.length; j < jj; j++) {
  31328. str = strs[j];
  31329. var nameRecord =
  31330. platforms[i] + // platform ID
  31331. encodings[i] + // encoding ID
  31332. languages[i] + // language ID
  31333. string16(j) + // name ID
  31334. string16(str.length) +
  31335. string16(strOffset);
  31336. nameTable += nameRecord;
  31337. strOffset += str.length;
  31338. }
  31339. }
  31340. nameTable += strings.join('') + stringsUnicode.join('');
  31341. return nameTable;
  31342. }
  31343. Font.prototype = {
  31344. name: null,
  31345. font: null,
  31346. mimetype: null,
  31347. encoding: null,
  31348. get renderer() {
  31349. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  31350. return shadow(this, 'renderer', renderer);
  31351. },
  31352. exportData: function Font_exportData() {
  31353. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  31354. var data = {};
  31355. for (var i in this) {
  31356. if (this.hasOwnProperty(i)) {
  31357. data[i] = this[i];
  31358. }
  31359. }
  31360. return data;
  31361. },
  31362. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  31363. function readTableEntry(file) {
  31364. var tag = bytesToString(file.getBytes(4));
  31365. var checksum = file.getInt32() >>> 0;
  31366. var offset = file.getInt32() >>> 0;
  31367. var length = file.getInt32() >>> 0;
  31368. // Read the table associated data
  31369. var previousPosition = file.pos;
  31370. file.pos = file.start ? file.start : 0;
  31371. file.skip(offset);
  31372. var data = file.getBytes(length);
  31373. file.pos = previousPosition;
  31374. if (tag === 'head') {
  31375. // clearing checksum adjustment
  31376. data[8] = data[9] = data[10] = data[11] = 0;
  31377. data[17] |= 0x20; //Set font optimized for cleartype flag
  31378. }
  31379. return {
  31380. tag: tag,
  31381. checksum: checksum,
  31382. length: length,
  31383. offset: offset,
  31384. data: data
  31385. };
  31386. }
  31387. function readOpenTypeHeader(ttf) {
  31388. return {
  31389. version: bytesToString(ttf.getBytes(4)),
  31390. numTables: ttf.getUint16(),
  31391. searchRange: ttf.getUint16(),
  31392. entrySelector: ttf.getUint16(),
  31393. rangeShift: ttf.getUint16()
  31394. };
  31395. }
  31396. /**
  31397. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  31398. * PDF spec
  31399. */
  31400. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  31401. if (!cmap) {
  31402. warn('No cmap table available.');
  31403. return {
  31404. platformId: -1,
  31405. encodingId: -1,
  31406. mappings: [],
  31407. hasShortCmap: false
  31408. };
  31409. }
  31410. var segment;
  31411. var start = (font.start ? font.start : 0) + cmap.offset;
  31412. font.pos = start;
  31413. var version = font.getUint16();
  31414. var numTables = font.getUint16();
  31415. var potentialTable;
  31416. var canBreak = false;
  31417. // There's an order of preference in terms of which cmap subtable to
  31418. // use:
  31419. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  31420. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  31421. // The following takes advantage of the fact that the tables are sorted
  31422. // to work.
  31423. for (var i = 0; i < numTables; i++) {
  31424. var platformId = font.getUint16();
  31425. var encodingId = font.getUint16();
  31426. var offset = font.getInt32() >>> 0;
  31427. var useTable = false;
  31428. if (platformId === 0 && encodingId === 0) {
  31429. useTable = true;
  31430. // Continue the loop since there still may be a higher priority
  31431. // table.
  31432. } else if (platformId === 1 && encodingId === 0) {
  31433. useTable = true;
  31434. // Continue the loop since there still may be a higher priority
  31435. // table.
  31436. } else if (platformId === 3 && encodingId === 1 &&
  31437. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  31438. useTable = true;
  31439. if (!isSymbolicFont) {
  31440. canBreak = true;
  31441. }
  31442. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  31443. useTable = true;
  31444. canBreak = true;
  31445. }
  31446. if (useTable) {
  31447. potentialTable = {
  31448. platformId: platformId,
  31449. encodingId: encodingId,
  31450. offset: offset
  31451. };
  31452. }
  31453. if (canBreak) {
  31454. break;
  31455. }
  31456. }
  31457. if (potentialTable) {
  31458. font.pos = start + potentialTable.offset;
  31459. }
  31460. if (!potentialTable || font.peekByte() === -1) {
  31461. warn('Could not find a preferred cmap table.');
  31462. return {
  31463. platformId: -1,
  31464. encodingId: -1,
  31465. mappings: [],
  31466. hasShortCmap: false
  31467. };
  31468. }
  31469. var format = font.getUint16();
  31470. var length = font.getUint16();
  31471. var language = font.getUint16();
  31472. var hasShortCmap = false;
  31473. var mappings = [];
  31474. var j, glyphId;
  31475. // TODO(mack): refactor this cmap subtable reading logic out
  31476. if (format === 0) {
  31477. for (j = 0; j < 256; j++) {
  31478. var index = font.getByte();
  31479. if (!index) {
  31480. continue;
  31481. }
  31482. mappings.push({
  31483. charCode: j,
  31484. glyphId: index
  31485. });
  31486. }
  31487. hasShortCmap = true;
  31488. } else if (format === 4) {
  31489. // re-creating the table in format 4 since the encoding
  31490. // might be changed
  31491. var segCount = (font.getUint16() >> 1);
  31492. font.getBytes(6); // skipping range fields
  31493. var segIndex, segments = [];
  31494. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31495. segments.push({ end: font.getUint16() });
  31496. }
  31497. font.getUint16();
  31498. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31499. segments[segIndex].start = font.getUint16();
  31500. }
  31501. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31502. segments[segIndex].delta = font.getUint16();
  31503. }
  31504. var offsetsCount = 0;
  31505. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31506. segment = segments[segIndex];
  31507. var rangeOffset = font.getUint16();
  31508. if (!rangeOffset) {
  31509. segment.offsetIndex = -1;
  31510. continue;
  31511. }
  31512. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  31513. segment.offsetIndex = offsetIndex;
  31514. offsetsCount = Math.max(offsetsCount, offsetIndex +
  31515. segment.end - segment.start + 1);
  31516. }
  31517. var offsets = [];
  31518. for (j = 0; j < offsetsCount; j++) {
  31519. offsets.push(font.getUint16());
  31520. }
  31521. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31522. segment = segments[segIndex];
  31523. start = segment.start;
  31524. var end = segment.end;
  31525. var delta = segment.delta;
  31526. offsetIndex = segment.offsetIndex;
  31527. for (j = start; j <= end; j++) {
  31528. if (j === 0xFFFF) {
  31529. continue;
  31530. }
  31531. glyphId = (offsetIndex < 0 ?
  31532. j : offsets[offsetIndex + j - start]);
  31533. glyphId = (glyphId + delta) & 0xFFFF;
  31534. if (glyphId === 0) {
  31535. continue;
  31536. }
  31537. mappings.push({
  31538. charCode: j,
  31539. glyphId: glyphId
  31540. });
  31541. }
  31542. }
  31543. } else if (format === 6) {
  31544. // Format 6 is a 2-bytes dense mapping, which means the font data
  31545. // lives glue together even if they are pretty far in the unicode
  31546. // table. (This looks weird, so I can have missed something), this
  31547. // works on Linux but seems to fails on Mac so let's rewrite the
  31548. // cmap table to a 3-1-4 style
  31549. var firstCode = font.getUint16();
  31550. var entryCount = font.getUint16();
  31551. for (j = 0; j < entryCount; j++) {
  31552. glyphId = font.getUint16();
  31553. var charCode = firstCode + j;
  31554. mappings.push({
  31555. charCode: charCode,
  31556. glyphId: glyphId
  31557. });
  31558. }
  31559. } else {
  31560. warn('cmap table has unsupported format: ' + format);
  31561. return {
  31562. platformId: -1,
  31563. encodingId: -1,
  31564. mappings: [],
  31565. hasShortCmap: false
  31566. };
  31567. }
  31568. // removing duplicate entries
  31569. mappings.sort(function (a, b) {
  31570. return a.charCode - b.charCode;
  31571. });
  31572. for (i = 1; i < mappings.length; i++) {
  31573. if (mappings[i - 1].charCode === mappings[i].charCode) {
  31574. mappings.splice(i, 1);
  31575. i--;
  31576. }
  31577. }
  31578. return {
  31579. platformId: potentialTable.platformId,
  31580. encodingId: potentialTable.encodingId,
  31581. mappings: mappings,
  31582. hasShortCmap: hasShortCmap
  31583. };
  31584. }
  31585. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  31586. if (!header) {
  31587. if (metrics) {
  31588. metrics.data = null;
  31589. }
  31590. return;
  31591. }
  31592. font.pos = (font.start ? font.start : 0) + header.offset;
  31593. font.pos += header.length - 2;
  31594. var numOfMetrics = font.getUint16();
  31595. if (numOfMetrics > numGlyphs) {
  31596. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  31597. 'greater than the numGlyphs (' + numGlyphs + ')');
  31598. // Reduce numOfMetrics if it is greater than numGlyphs
  31599. numOfMetrics = numGlyphs;
  31600. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  31601. header.data[35] = numOfMetrics & 0x00ff;
  31602. }
  31603. var numOfSidebearings = numGlyphs - numOfMetrics;
  31604. var numMissing = numOfSidebearings -
  31605. ((metrics.length - numOfMetrics * 4) >> 1);
  31606. if (numMissing > 0) {
  31607. // For each missing glyph, we set both the width and lsb to 0 (zero).
  31608. // Since we need to add two properties for each glyph, this explains
  31609. // the use of |numMissing * 2| when initializing the typed array.
  31610. var entries = new Uint8Array(metrics.length + numMissing * 2);
  31611. entries.set(metrics.data);
  31612. metrics.data = entries;
  31613. }
  31614. }
  31615. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  31616. hintsValid) {
  31617. if (sourceEnd - sourceStart <= 12) {
  31618. // glyph with data less than 12 is invalid one
  31619. return 0;
  31620. }
  31621. var glyf = source.subarray(sourceStart, sourceEnd);
  31622. var contoursCount = (glyf[0] << 8) | glyf[1];
  31623. if (contoursCount & 0x8000) {
  31624. // complex glyph, writing as is
  31625. dest.set(glyf, destStart);
  31626. return glyf.length;
  31627. }
  31628. var i, j = 10, flagsCount = 0;
  31629. for (i = 0; i < contoursCount; i++) {
  31630. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  31631. flagsCount = endPoint + 1;
  31632. j += 2;
  31633. }
  31634. // skipping instructions
  31635. var instructionsStart = j;
  31636. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  31637. j += 2 + instructionsLength;
  31638. var instructionsEnd = j;
  31639. // validating flags
  31640. var coordinatesLength = 0;
  31641. for (i = 0; i < flagsCount; i++) {
  31642. var flag = glyf[j++];
  31643. if (flag & 0xC0) {
  31644. // reserved flags must be zero, cleaning up
  31645. glyf[j - 1] = flag & 0x3F;
  31646. }
  31647. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  31648. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  31649. coordinatesLength += xyLength;
  31650. if (flag & 8) {
  31651. var repeat = glyf[j++];
  31652. i += repeat;
  31653. coordinatesLength += repeat * xyLength;
  31654. }
  31655. }
  31656. // glyph without coordinates will be rejected
  31657. if (coordinatesLength === 0) {
  31658. return 0;
  31659. }
  31660. var glyphDataLength = j + coordinatesLength;
  31661. if (glyphDataLength > glyf.length) {
  31662. // not enough data for coordinates
  31663. return 0;
  31664. }
  31665. if (!hintsValid && instructionsLength > 0) {
  31666. dest.set(glyf.subarray(0, instructionsStart), destStart);
  31667. dest.set([0, 0], destStart + instructionsStart);
  31668. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  31669. destStart + instructionsStart + 2);
  31670. glyphDataLength -= instructionsLength;
  31671. if (glyf.length - glyphDataLength > 3) {
  31672. glyphDataLength = (glyphDataLength + 3) & ~3;
  31673. }
  31674. return glyphDataLength;
  31675. }
  31676. if (glyf.length - glyphDataLength > 3) {
  31677. // truncating and aligning to 4 bytes the long glyph data
  31678. glyphDataLength = (glyphDataLength + 3) & ~3;
  31679. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  31680. return glyphDataLength;
  31681. }
  31682. // glyph data is fine
  31683. dest.set(glyf, destStart);
  31684. return glyf.length;
  31685. }
  31686. function sanitizeHead(head, numGlyphs, locaLength) {
  31687. var data = head.data;
  31688. // Validate version:
  31689. // Should always be 0x00010000
  31690. var version = int32(data[0], data[1], data[2], data[3]);
  31691. if (version >> 16 !== 1) {
  31692. info('Attempting to fix invalid version in head table: ' + version);
  31693. data[0] = 0;
  31694. data[1] = 1;
  31695. data[2] = 0;
  31696. data[3] = 0;
  31697. }
  31698. var indexToLocFormat = int16(data[50], data[51]);
  31699. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  31700. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  31701. indexToLocFormat);
  31702. // The value of indexToLocFormat should be 0 if the loca table
  31703. // consists of short offsets, and should be 1 if the loca table
  31704. // consists of long offsets.
  31705. //
  31706. // The number of entries in the loca table should be numGlyphs + 1.
  31707. //
  31708. // Using this information, we can work backwards to deduce if the
  31709. // size of each offset in the loca table, and thus figure out the
  31710. // appropriate value for indexToLocFormat.
  31711. var numGlyphsPlusOne = numGlyphs + 1;
  31712. if (locaLength === numGlyphsPlusOne << 1) {
  31713. // 0x0000 indicates the loca table consists of short offsets
  31714. data[50] = 0;
  31715. data[51] = 0;
  31716. } else if (locaLength === numGlyphsPlusOne << 2) {
  31717. // 0x0001 indicates the loca table consists of long offsets
  31718. data[50] = 0;
  31719. data[51] = 1;
  31720. } else {
  31721. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  31722. }
  31723. }
  31724. }
  31725. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  31726. isGlyphLocationsLong, hintsValid,
  31727. dupFirstEntry) {
  31728. var itemSize, itemDecode, itemEncode;
  31729. if (isGlyphLocationsLong) {
  31730. itemSize = 4;
  31731. itemDecode = function fontItemDecodeLong(data, offset) {
  31732. return (data[offset] << 24) | (data[offset + 1] << 16) |
  31733. (data[offset + 2] << 8) | data[offset + 3];
  31734. };
  31735. itemEncode = function fontItemEncodeLong(data, offset, value) {
  31736. data[offset] = (value >>> 24) & 0xFF;
  31737. data[offset + 1] = (value >> 16) & 0xFF;
  31738. data[offset + 2] = (value >> 8) & 0xFF;
  31739. data[offset + 3] = value & 0xFF;
  31740. };
  31741. } else {
  31742. itemSize = 2;
  31743. itemDecode = function fontItemDecode(data, offset) {
  31744. return (data[offset] << 9) | (data[offset + 1] << 1);
  31745. };
  31746. itemEncode = function fontItemEncode(data, offset, value) {
  31747. data[offset] = (value >> 9) & 0xFF;
  31748. data[offset + 1] = (value >> 1) & 0xFF;
  31749. };
  31750. }
  31751. var locaData = loca.data;
  31752. var locaDataSize = itemSize * (1 + numGlyphs);
  31753. // is loca.data too short or long?
  31754. if (locaData.length !== locaDataSize) {
  31755. locaData = new Uint8Array(locaDataSize);
  31756. locaData.set(loca.data.subarray(0, locaDataSize));
  31757. loca.data = locaData;
  31758. }
  31759. // removing the invalid glyphs
  31760. var oldGlyfData = glyf.data;
  31761. var oldGlyfDataLength = oldGlyfData.length;
  31762. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  31763. var startOffset = itemDecode(locaData, 0);
  31764. var writeOffset = 0;
  31765. var missingGlyphData = Object.create(null);
  31766. itemEncode(locaData, 0, writeOffset);
  31767. var i, j;
  31768. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31769. var endOffset = itemDecode(locaData, j);
  31770. if (endOffset > oldGlyfDataLength &&
  31771. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  31772. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  31773. // the glyf table size, which makes last glyph out of range.
  31774. endOffset = oldGlyfDataLength;
  31775. }
  31776. if (endOffset > oldGlyfDataLength) {
  31777. // glyph end offset points outside glyf data, rejecting the glyph
  31778. itemEncode(locaData, j, writeOffset);
  31779. startOffset = endOffset;
  31780. continue;
  31781. }
  31782. if (startOffset === endOffset) {
  31783. missingGlyphData[i] = true;
  31784. }
  31785. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  31786. newGlyfData, writeOffset, hintsValid);
  31787. writeOffset += newLength;
  31788. itemEncode(locaData, j, writeOffset);
  31789. startOffset = endOffset;
  31790. }
  31791. if (writeOffset === 0) {
  31792. // glyf table cannot be empty -- redoing the glyf and loca tables
  31793. // to have single glyph with one point
  31794. var simpleGlyph = new Uint8Array(
  31795. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  31796. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31797. itemEncode(locaData, j, simpleGlyph.length);
  31798. }
  31799. glyf.data = simpleGlyph;
  31800. return missingGlyphData;
  31801. }
  31802. if (dupFirstEntry) {
  31803. var firstEntryLength = itemDecode(locaData, itemSize);
  31804. if (newGlyfData.length > firstEntryLength + writeOffset) {
  31805. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  31806. } else {
  31807. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  31808. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  31809. }
  31810. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  31811. itemEncode(loca.data, locaData.length - itemSize,
  31812. writeOffset + firstEntryLength);
  31813. } else {
  31814. glyf.data = newGlyfData.subarray(0, writeOffset);
  31815. }
  31816. return missingGlyphData;
  31817. }
  31818. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  31819. var start = (font.start ? font.start : 0) + post.offset;
  31820. font.pos = start;
  31821. var length = post.length, end = start + length;
  31822. var version = font.getInt32();
  31823. // skip rest to the tables
  31824. font.getBytes(28);
  31825. var glyphNames;
  31826. var valid = true;
  31827. var i;
  31828. switch (version) {
  31829. case 0x00010000:
  31830. glyphNames = MacStandardGlyphOrdering;
  31831. break;
  31832. case 0x00020000:
  31833. var numGlyphs = font.getUint16();
  31834. if (numGlyphs !== maxpNumGlyphs) {
  31835. valid = false;
  31836. break;
  31837. }
  31838. var glyphNameIndexes = [];
  31839. for (i = 0; i < numGlyphs; ++i) {
  31840. var index = font.getUint16();
  31841. if (index >= 32768) {
  31842. valid = false;
  31843. break;
  31844. }
  31845. glyphNameIndexes.push(index);
  31846. }
  31847. if (!valid) {
  31848. break;
  31849. }
  31850. var customNames = [];
  31851. var strBuf = [];
  31852. while (font.pos < end) {
  31853. var stringLength = font.getByte();
  31854. strBuf.length = stringLength;
  31855. for (i = 0; i < stringLength; ++i) {
  31856. strBuf[i] = String.fromCharCode(font.getByte());
  31857. }
  31858. customNames.push(strBuf.join(''));
  31859. }
  31860. glyphNames = [];
  31861. for (i = 0; i < numGlyphs; ++i) {
  31862. var j = glyphNameIndexes[i];
  31863. if (j < 258) {
  31864. glyphNames.push(MacStandardGlyphOrdering[j]);
  31865. continue;
  31866. }
  31867. glyphNames.push(customNames[j - 258]);
  31868. }
  31869. break;
  31870. case 0x00030000:
  31871. break;
  31872. default:
  31873. warn('Unknown/unsupported post table version ' + version);
  31874. valid = false;
  31875. if (properties.defaultEncoding) {
  31876. glyphNames = properties.defaultEncoding;
  31877. }
  31878. break;
  31879. }
  31880. properties.glyphNames = glyphNames;
  31881. return valid;
  31882. }
  31883. function readNameTable(nameTable) {
  31884. var start = (font.start ? font.start : 0) + nameTable.offset;
  31885. font.pos = start;
  31886. var names = [[], []];
  31887. var length = nameTable.length, end = start + length;
  31888. var format = font.getUint16();
  31889. var FORMAT_0_HEADER_LENGTH = 6;
  31890. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  31891. // unsupported name table format or table "too" small
  31892. return names;
  31893. }
  31894. var numRecords = font.getUint16();
  31895. var stringsStart = font.getUint16();
  31896. var records = [];
  31897. var NAME_RECORD_LENGTH = 12;
  31898. var i, ii;
  31899. for (i = 0; i < numRecords &&
  31900. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  31901. var r = {
  31902. platform: font.getUint16(),
  31903. encoding: font.getUint16(),
  31904. language: font.getUint16(),
  31905. name: font.getUint16(),
  31906. length: font.getUint16(),
  31907. offset: font.getUint16()
  31908. };
  31909. // using only Macintosh and Windows platform/encoding names
  31910. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  31911. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  31912. records.push(r);
  31913. }
  31914. }
  31915. for (i = 0, ii = records.length; i < ii; i++) {
  31916. var record = records[i];
  31917. if (record.length <= 0) {
  31918. continue; // Nothing to process, ignoring.
  31919. }
  31920. var pos = start + stringsStart + record.offset;
  31921. if (pos + record.length > end) {
  31922. continue; // outside of name table, ignoring
  31923. }
  31924. font.pos = pos;
  31925. var nameIndex = record.name;
  31926. if (record.encoding) {
  31927. // unicode
  31928. var str = '';
  31929. for (var j = 0, jj = record.length; j < jj; j += 2) {
  31930. str += String.fromCharCode(font.getUint16());
  31931. }
  31932. names[1][nameIndex] = str;
  31933. } else {
  31934. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  31935. }
  31936. }
  31937. return names;
  31938. }
  31939. var TTOpsStackDeltas = [
  31940. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  31941. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  31942. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  31943. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  31944. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  31945. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  31946. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  31947. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  31948. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  31949. // 0xC0-DF == -1 and 0xE0-FF == -2
  31950. function sanitizeTTProgram(table, ttContext) {
  31951. var data = table.data;
  31952. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  31953. var stack = [];
  31954. var callstack = [];
  31955. var functionsCalled = [];
  31956. var tooComplexToFollowFunctions =
  31957. ttContext.tooComplexToFollowFunctions;
  31958. var inFDEF = false, ifLevel = 0, inELSE = 0;
  31959. for (var ii = data.length; i < ii;) {
  31960. var op = data[i++];
  31961. // The TrueType instruction set docs can be found at
  31962. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  31963. if (op === 0x40) { // NPUSHB - pushes n bytes
  31964. n = data[i++];
  31965. if (inFDEF || inELSE) {
  31966. i += n;
  31967. } else {
  31968. for (j = 0; j < n; j++) {
  31969. stack.push(data[i++]);
  31970. }
  31971. }
  31972. } else if (op === 0x41) { // NPUSHW - pushes n words
  31973. n = data[i++];
  31974. if (inFDEF || inELSE) {
  31975. i += n * 2;
  31976. } else {
  31977. for (j = 0; j < n; j++) {
  31978. b = data[i++];
  31979. stack.push((b << 8) | data[i++]);
  31980. }
  31981. }
  31982. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  31983. n = op - 0xB0 + 1;
  31984. if (inFDEF || inELSE) {
  31985. i += n;
  31986. } else {
  31987. for (j = 0; j < n; j++) {
  31988. stack.push(data[i++]);
  31989. }
  31990. }
  31991. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  31992. n = op - 0xB8 + 1;
  31993. if (inFDEF || inELSE) {
  31994. i += n * 2;
  31995. } else {
  31996. for (j = 0; j < n; j++) {
  31997. b = data[i++];
  31998. stack.push((b << 8) | data[i++]);
  31999. }
  32000. }
  32001. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  32002. if (!inFDEF && !inELSE) {
  32003. // collecting inforamtion about which functions are used
  32004. funcId = stack[stack.length - 1];
  32005. ttContext.functionsUsed[funcId] = true;
  32006. if (funcId in ttContext.functionsStackDeltas) {
  32007. stack.length += ttContext.functionsStackDeltas[funcId];
  32008. } else if (funcId in ttContext.functionsDefined &&
  32009. functionsCalled.indexOf(funcId) < 0) {
  32010. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  32011. functionsCalled.push(funcId);
  32012. pc = ttContext.functionsDefined[funcId];
  32013. if (!pc) {
  32014. warn('TT: CALL non-existent function');
  32015. ttContext.hintsValid = false;
  32016. return;
  32017. }
  32018. data = pc.data;
  32019. i = pc.i;
  32020. }
  32021. }
  32022. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  32023. if (inFDEF || inELSE) {
  32024. warn('TT: nested FDEFs not allowed');
  32025. tooComplexToFollowFunctions = true;
  32026. }
  32027. inFDEF = true;
  32028. // collecting inforamtion about which functions are defined
  32029. lastDeff = i;
  32030. funcId = stack.pop();
  32031. ttContext.functionsDefined[funcId] = {data: data, i: i};
  32032. } else if (op === 0x2D) { // ENDF - end of function
  32033. if (inFDEF) {
  32034. inFDEF = false;
  32035. lastEndf = i;
  32036. } else {
  32037. pc = callstack.pop();
  32038. if (!pc) {
  32039. warn('TT: ENDF bad stack');
  32040. ttContext.hintsValid = false;
  32041. return;
  32042. }
  32043. funcId = functionsCalled.pop();
  32044. data = pc.data;
  32045. i = pc.i;
  32046. ttContext.functionsStackDeltas[funcId] =
  32047. stack.length - pc.stackTop;
  32048. }
  32049. } else if (op === 0x89) { // IDEF - instruction definition
  32050. if (inFDEF || inELSE) {
  32051. warn('TT: nested IDEFs not allowed');
  32052. tooComplexToFollowFunctions = true;
  32053. }
  32054. inFDEF = true;
  32055. // recording it as a function to track ENDF
  32056. lastDeff = i;
  32057. } else if (op === 0x58) { // IF
  32058. ++ifLevel;
  32059. } else if (op === 0x1B) { // ELSE
  32060. inELSE = ifLevel;
  32061. } else if (op === 0x59) { // EIF
  32062. if (inELSE === ifLevel) {
  32063. inELSE = 0;
  32064. }
  32065. --ifLevel;
  32066. } else if (op === 0x1C) { // JMPR
  32067. if (!inFDEF && !inELSE) {
  32068. var offset = stack[stack.length - 1];
  32069. // only jumping forward to prevent infinite loop
  32070. if (offset > 0) {
  32071. i += offset - 1;
  32072. }
  32073. }
  32074. }
  32075. // Adjusting stack not extactly, but just enough to get function id
  32076. if (!inFDEF && !inELSE) {
  32077. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  32078. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  32079. if (op >= 0x71 && op <= 0x75) {
  32080. n = stack.pop();
  32081. if (n === n) {
  32082. stackDelta = -n * 2;
  32083. }
  32084. }
  32085. while (stackDelta < 0 && stack.length > 0) {
  32086. stack.pop();
  32087. stackDelta++;
  32088. }
  32089. while (stackDelta > 0) {
  32090. stack.push(NaN); // pushing any number into stack
  32091. stackDelta--;
  32092. }
  32093. }
  32094. }
  32095. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  32096. var content = [data];
  32097. if (i > data.length) {
  32098. content.push(new Uint8Array(i - data.length));
  32099. }
  32100. if (lastDeff > lastEndf) {
  32101. warn('TT: complementing a missing function tail');
  32102. // new function definition started, but not finished
  32103. // complete function by [CLEAR, ENDF]
  32104. content.push(new Uint8Array([0x22, 0x2D]));
  32105. }
  32106. foldTTTable(table, content);
  32107. }
  32108. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  32109. if (ttContext.tooComplexToFollowFunctions) {
  32110. return;
  32111. }
  32112. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  32113. warn('TT: more functions defined than expected');
  32114. ttContext.hintsValid = false;
  32115. return;
  32116. }
  32117. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  32118. if (j > maxFunctionDefs) {
  32119. warn('TT: invalid function id: ' + j);
  32120. ttContext.hintsValid = false;
  32121. return;
  32122. }
  32123. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  32124. warn('TT: undefined function: ' + j);
  32125. ttContext.hintsValid = false;
  32126. return;
  32127. }
  32128. }
  32129. }
  32130. function foldTTTable(table, content) {
  32131. if (content.length > 1) {
  32132. // concatenating the content items
  32133. var newLength = 0;
  32134. var j, jj;
  32135. for (j = 0, jj = content.length; j < jj; j++) {
  32136. newLength += content[j].length;
  32137. }
  32138. newLength = (newLength + 3) & ~3;
  32139. var result = new Uint8Array(newLength);
  32140. var pos = 0;
  32141. for (j = 0, jj = content.length; j < jj; j++) {
  32142. result.set(content[j], pos);
  32143. pos += content[j].length;
  32144. }
  32145. table.data = result;
  32146. table.length = newLength;
  32147. }
  32148. }
  32149. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  32150. var ttContext = {
  32151. functionsDefined: [],
  32152. functionsUsed: [],
  32153. functionsStackDeltas: [],
  32154. tooComplexToFollowFunctions: false,
  32155. hintsValid: true
  32156. };
  32157. if (fpgm) {
  32158. sanitizeTTProgram(fpgm, ttContext);
  32159. }
  32160. if (prep) {
  32161. sanitizeTTProgram(prep, ttContext);
  32162. }
  32163. if (fpgm) {
  32164. checkInvalidFunctions(ttContext, maxFunctionDefs);
  32165. }
  32166. if (cvt && (cvt.length & 1)) {
  32167. var cvtData = new Uint8Array(cvt.length + 1);
  32168. cvtData.set(cvt.data);
  32169. cvt.data = cvtData;
  32170. }
  32171. return ttContext.hintsValid;
  32172. }
  32173. // The following steps modify the original font data, making copy
  32174. font = new Stream(new Uint8Array(font.getBytes()));
  32175. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  32176. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  32177. var header = readOpenTypeHeader(font);
  32178. var numTables = header.numTables;
  32179. var cff, cffFile;
  32180. var tables = Object.create(null);
  32181. tables['OS/2'] = null;
  32182. tables['cmap'] = null;
  32183. tables['head'] = null;
  32184. tables['hhea'] = null;
  32185. tables['hmtx'] = null;
  32186. tables['maxp'] = null;
  32187. tables['name'] = null;
  32188. tables['post'] = null;
  32189. var table;
  32190. for (var i = 0; i < numTables; i++) {
  32191. table = readTableEntry(font);
  32192. if (VALID_TABLES.indexOf(table.tag) < 0) {
  32193. continue; // skipping table if it's not a required or optional table
  32194. }
  32195. if (table.length === 0) {
  32196. continue; // skipping empty tables
  32197. }
  32198. tables[table.tag] = table;
  32199. }
  32200. var isTrueType = !tables['CFF '];
  32201. if (!isTrueType) {
  32202. // OpenType font
  32203. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  32204. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  32205. !tables['post']) {
  32206. // no major tables: throwing everything at CFFFont
  32207. cffFile = new Stream(tables['CFF '].data);
  32208. cff = new CFFFont(cffFile, properties);
  32209. adjustWidths(properties);
  32210. return this.convert(name, cff, properties);
  32211. }
  32212. delete tables['glyf'];
  32213. delete tables['loca'];
  32214. delete tables['fpgm'];
  32215. delete tables['prep'];
  32216. delete tables['cvt '];
  32217. this.isOpenType = true;
  32218. } else {
  32219. if (!tables['loca']) {
  32220. error('Required "loca" table is not found');
  32221. }
  32222. if (!tables['glyf']) {
  32223. warn('Required "glyf" table is not found -- trying to recover.');
  32224. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  32225. tables['glyf'] = {
  32226. tag: 'glyf',
  32227. data: new Uint8Array(0),
  32228. };
  32229. }
  32230. this.isOpenType = false;
  32231. }
  32232. if (!tables['maxp']) {
  32233. error('Required "maxp" table is not found');
  32234. }
  32235. font.pos = (font.start || 0) + tables['maxp'].offset;
  32236. var version = font.getInt32();
  32237. var numGlyphs = font.getUint16();
  32238. var maxFunctionDefs = 0;
  32239. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  32240. // maxZones can be invalid
  32241. font.pos += 8;
  32242. var maxZones = font.getUint16();
  32243. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  32244. tables['maxp'].data[14] = 0;
  32245. tables['maxp'].data[15] = 2;
  32246. }
  32247. font.pos += 4;
  32248. maxFunctionDefs = font.getUint16();
  32249. }
  32250. var dupFirstEntry = false;
  32251. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  32252. properties.toUnicode.get(0) > '\u0000') {
  32253. // oracle's defect (see 3427), duplicating first entry
  32254. dupFirstEntry = true;
  32255. numGlyphs++;
  32256. tables['maxp'].data[4] = numGlyphs >> 8;
  32257. tables['maxp'].data[5] = numGlyphs & 255;
  32258. }
  32259. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  32260. tables['cvt '], maxFunctionDefs);
  32261. if (!hintsValid) {
  32262. delete tables['fpgm'];
  32263. delete tables['prep'];
  32264. delete tables['cvt '];
  32265. }
  32266. // Ensure the hmtx table contains the advance width and
  32267. // sidebearings information for numGlyphs in the maxp table
  32268. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  32269. if (!tables['head']) {
  32270. error('Required "head" table is not found');
  32271. }
  32272. sanitizeHead(tables['head'], numGlyphs,
  32273. isTrueType ? tables['loca'].length : 0);
  32274. var missingGlyphs = Object.create(null);
  32275. if (isTrueType) {
  32276. var isGlyphLocationsLong = int16(tables['head'].data[50],
  32277. tables['head'].data[51]);
  32278. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  32279. numGlyphs, isGlyphLocationsLong,
  32280. hintsValid, dupFirstEntry);
  32281. }
  32282. if (!tables['hhea']) {
  32283. error('Required "hhea" table is not found');
  32284. }
  32285. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  32286. // Sometimes it's 0. That needs to be fixed
  32287. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  32288. tables['hhea'].data[10] = 0xFF;
  32289. tables['hhea'].data[11] = 0xFF;
  32290. }
  32291. // Extract some more font properties from the OpenType head and
  32292. // hhea tables; yMin and descent value are always negative.
  32293. var metricsOverride = {
  32294. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  32295. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  32296. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  32297. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  32298. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  32299. };
  32300. // PDF FontDescriptor metrics lie -- using data from actual font.
  32301. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  32302. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  32303. // The 'post' table has glyphs names.
  32304. if (tables['post']) {
  32305. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  32306. if (!valid) {
  32307. tables['post'] = null;
  32308. }
  32309. }
  32310. var charCodeToGlyphId = [], charCode;
  32311. var toUnicode = properties.toUnicode, widths = properties.widths;
  32312. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  32313. toUnicode.length === 0x10000);
  32314. // Helper function to try to skip mapping of empty glyphs.
  32315. // Note: In some cases, just relying on the glyph data doesn't work,
  32316. // hence we also use a few heuristics to fix various PDF files.
  32317. function hasGlyph(glyphId, charCode, widthCode) {
  32318. if (!missingGlyphs[glyphId]) {
  32319. return true;
  32320. }
  32321. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  32322. return true;
  32323. }
  32324. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  32325. return true;
  32326. }
  32327. return false;
  32328. }
  32329. if (properties.type === 'CIDFontType2') {
  32330. var cidToGidMap = properties.cidToGidMap || [];
  32331. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  32332. properties.cMap.forEach(function(charCode, cid) {
  32333. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  32334. var glyphId = -1;
  32335. if (isCidToGidMapEmpty) {
  32336. glyphId = cid;
  32337. } else if (cidToGidMap[cid] !== undefined) {
  32338. glyphId = cidToGidMap[cid];
  32339. }
  32340. if (glyphId >= 0 && glyphId < numGlyphs &&
  32341. hasGlyph(glyphId, charCode, cid)) {
  32342. charCodeToGlyphId[charCode] = glyphId;
  32343. }
  32344. });
  32345. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  32346. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  32347. // if the font has a `CIDToGIDMap` which has already mapped the first
  32348. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  32349. charCodeToGlyphId[0] = numGlyphs - 1;
  32350. }
  32351. } else {
  32352. // Most of the following logic in this code branch is based on the
  32353. // 9.6.6.4 of the PDF spec.
  32354. var hasEncoding =
  32355. properties.differences.length > 0 || !!properties.baseEncodingName;
  32356. var cmapTable =
  32357. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  32358. var cmapPlatformId = cmapTable.platformId;
  32359. var cmapEncodingId = cmapTable.encodingId;
  32360. var cmapMappings = cmapTable.mappings;
  32361. var cmapMappingsLength = cmapMappings.length;
  32362. // The spec seems to imply that if the font is symbolic the encoding
  32363. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  32364. // where the the font is symbolic and it has an encoding.
  32365. if (hasEncoding &&
  32366. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  32367. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  32368. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  32369. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  32370. // When no preferred cmap table was found and |baseEncodingName| is
  32371. // one of the predefined encodings, we seem to obtain a better
  32372. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  32373. // TODO: Note that this is a hack which should be removed as soon as
  32374. // we have proper support for more exotic cmap tables.
  32375. var baseEncoding = [];
  32376. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  32377. properties.baseEncodingName === 'WinAnsiEncoding') {
  32378. baseEncoding = getEncoding(properties.baseEncodingName);
  32379. }
  32380. var glyphsUnicodeMap = getGlyphsUnicode();
  32381. for (charCode = 0; charCode < 256; charCode++) {
  32382. var glyphName, standardGlyphName;
  32383. if (this.differences && charCode in this.differences) {
  32384. glyphName = this.differences[charCode];
  32385. } else if (charCode in baseEncoding &&
  32386. baseEncoding[charCode] !== '') {
  32387. glyphName = baseEncoding[charCode];
  32388. } else {
  32389. glyphName = StandardEncoding[charCode];
  32390. }
  32391. if (!glyphName) {
  32392. continue;
  32393. }
  32394. // Ensure that non-standard glyph names are resolved to valid ones.
  32395. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32396. var unicodeOrCharCode, isUnicode = false;
  32397. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  32398. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  32399. isUnicode = true;
  32400. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  32401. // TODO: the encoding needs to be updated with mac os table.
  32402. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  32403. }
  32404. var found = false;
  32405. for (i = 0; i < cmapMappingsLength; ++i) {
  32406. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  32407. continue;
  32408. }
  32409. var code = isUnicode ? charCode : unicodeOrCharCode;
  32410. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  32411. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32412. found = true;
  32413. break;
  32414. }
  32415. }
  32416. if (!found && properties.glyphNames) {
  32417. // Try to map using the post table.
  32418. var glyphId = properties.glyphNames.indexOf(glyphName);
  32419. // The post table ought to use the same kind of glyph names as the
  32420. // `differences` array, but check the standard ones as a fallback.
  32421. if (glyphId === -1 && standardGlyphName !== glyphName) {
  32422. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  32423. }
  32424. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  32425. charCodeToGlyphId[charCode] = glyphId;
  32426. found = true;
  32427. }
  32428. }
  32429. if (!found) {
  32430. charCodeToGlyphId[charCode] = 0; // notdef
  32431. }
  32432. }
  32433. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  32434. // Default Unicode semantics, use the charcodes as is.
  32435. for (i = 0; i < cmapMappingsLength; ++i) {
  32436. charCodeToGlyphId[cmapMappings[i].charCode] =
  32437. cmapMappings[i].glyphId;
  32438. }
  32439. } else {
  32440. // For (3, 0) cmap tables:
  32441. // The charcode key being stored in charCodeToGlyphId is the lower
  32442. // byte of the two-byte charcodes of the cmap table since according to
  32443. // the spec: 'each byte from the string shall be prepended with the
  32444. // high byte of the range [of charcodes in the cmap table], to form
  32445. // a two-byte character, which shall be used to select the
  32446. // associated glyph description from the subtable'.
  32447. //
  32448. // For (1, 0) cmap tables:
  32449. // 'single bytes from the string shall be used to look up the
  32450. // associated glyph descriptions from the subtable'. This means
  32451. // charcodes in the cmap will be single bytes, so no-op since
  32452. // glyph.charCode & 0xFF === glyph.charCode
  32453. for (i = 0; i < cmapMappingsLength; ++i) {
  32454. charCode = cmapMappings[i].charCode & 0xFF;
  32455. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32456. }
  32457. }
  32458. }
  32459. if (charCodeToGlyphId.length === 0) {
  32460. // defines at least one glyph
  32461. charCodeToGlyphId[0] = 0;
  32462. }
  32463. // Converting glyphs and ids into font's cmap table
  32464. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  32465. this.toFontChar = newMapping.toFontChar;
  32466. tables['cmap'] = {
  32467. tag: 'cmap',
  32468. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  32469. };
  32470. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  32471. tables['OS/2'] = {
  32472. tag: 'OS/2',
  32473. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  32474. metricsOverride)
  32475. };
  32476. }
  32477. // Rewrite the 'post' table if needed
  32478. if (!tables['post']) {
  32479. tables['post'] = {
  32480. tag: 'post',
  32481. data: createPostTable(properties)
  32482. };
  32483. }
  32484. if (!isTrueType) {
  32485. try {
  32486. // Trying to repair CFF file
  32487. cffFile = new Stream(tables['CFF '].data);
  32488. var parser = new CFFParser(cffFile, properties,
  32489. SEAC_ANALYSIS_ENABLED);
  32490. cff = parser.parse();
  32491. var compiler = new CFFCompiler(cff);
  32492. tables['CFF '].data = compiler.compile();
  32493. } catch (e) {
  32494. warn('Failed to compile font ' + properties.loadedName);
  32495. }
  32496. }
  32497. // Re-creating 'name' table
  32498. if (!tables['name']) {
  32499. tables['name'] = {
  32500. tag: 'name',
  32501. data: createNameTable(this.name)
  32502. };
  32503. } else {
  32504. // ... using existing 'name' table as prototype
  32505. var namePrototype = readNameTable(tables['name']);
  32506. tables['name'].data = createNameTable(name, namePrototype);
  32507. }
  32508. var builder = new OpenTypeFileBuilder(header.version);
  32509. for (var tableTag in tables) {
  32510. builder.addTable(tableTag, tables[tableTag].data);
  32511. }
  32512. return builder.toArray();
  32513. },
  32514. convert: function Font_convert(fontName, font, properties) {
  32515. // TODO: Check the charstring widths to determine this.
  32516. properties.fixedPitch = false;
  32517. var mapping = font.getGlyphMapping(properties);
  32518. var newMapping = adjustMapping(mapping, properties);
  32519. this.toFontChar = newMapping.toFontChar;
  32520. var numGlyphs = font.numGlyphs;
  32521. function getCharCodes(charCodeToGlyphId, glyphId) {
  32522. var charCodes = null;
  32523. for (var charCode in charCodeToGlyphId) {
  32524. if (glyphId === charCodeToGlyphId[charCode]) {
  32525. if (!charCodes) {
  32526. charCodes = [];
  32527. }
  32528. charCodes.push(charCode | 0);
  32529. }
  32530. }
  32531. return charCodes;
  32532. }
  32533. function createCharCode(charCodeToGlyphId, glyphId) {
  32534. for (var charCode in charCodeToGlyphId) {
  32535. if (glyphId === charCodeToGlyphId[charCode]) {
  32536. return charCode | 0;
  32537. }
  32538. }
  32539. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  32540. glyphId;
  32541. return newMapping.nextAvailableFontCharCode++;
  32542. }
  32543. var seacs = font.seacs;
  32544. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  32545. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  32546. var charset = font.getCharset();
  32547. var seacMap = Object.create(null);
  32548. for (var glyphId in seacs) {
  32549. glyphId |= 0;
  32550. var seac = seacs[glyphId];
  32551. var baseGlyphName = StandardEncoding[seac[2]];
  32552. var accentGlyphName = StandardEncoding[seac[3]];
  32553. var baseGlyphId = charset.indexOf(baseGlyphName);
  32554. var accentGlyphId = charset.indexOf(accentGlyphName);
  32555. if (baseGlyphId < 0 || accentGlyphId < 0) {
  32556. continue;
  32557. }
  32558. var accentOffset = {
  32559. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  32560. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  32561. };
  32562. var charCodes = getCharCodes(mapping, glyphId);
  32563. if (!charCodes) {
  32564. // There's no point in mapping it if the char code was never mapped
  32565. // to begin with.
  32566. continue;
  32567. }
  32568. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  32569. var charCode = charCodes[i];
  32570. // Find a fontCharCode that maps to the base and accent glyphs.
  32571. // If one doesn't exists, create it.
  32572. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  32573. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  32574. baseGlyphId);
  32575. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  32576. accentGlyphId);
  32577. seacMap[charCode] = {
  32578. baseFontCharCode: baseFontCharCode,
  32579. accentFontCharCode: accentFontCharCode,
  32580. accentOffset: accentOffset
  32581. };
  32582. }
  32583. }
  32584. properties.seacMap = seacMap;
  32585. }
  32586. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  32587. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  32588. // PostScript Font Program
  32589. builder.addTable('CFF ', font.data);
  32590. // OS/2 and Windows Specific metrics
  32591. builder.addTable('OS/2', createOS2Table(properties,
  32592. newMapping.charCodeToGlyphId));
  32593. // Character to glyphs mapping
  32594. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  32595. numGlyphs));
  32596. // Font header
  32597. builder.addTable('head',
  32598. '\x00\x01\x00\x00' + // Version number
  32599. '\x00\x00\x10\x00' + // fontRevision
  32600. '\x00\x00\x00\x00' + // checksumAdjustement
  32601. '\x5F\x0F\x3C\xF5' + // magicNumber
  32602. '\x00\x00' + // Flags
  32603. safeString16(unitsPerEm) + // unitsPerEM
  32604. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  32605. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  32606. '\x00\x00' + // xMin
  32607. safeString16(properties.descent) + // yMin
  32608. '\x0F\xFF' + // xMax
  32609. safeString16(properties.ascent) + // yMax
  32610. string16(properties.italicAngle ? 2 : 0) + // macStyle
  32611. '\x00\x11' + // lowestRecPPEM
  32612. '\x00\x00' + // fontDirectionHint
  32613. '\x00\x00' + // indexToLocFormat
  32614. '\x00\x00'); // glyphDataFormat
  32615. // Horizontal header
  32616. builder.addTable('hhea',
  32617. '\x00\x01\x00\x00' + // Version number
  32618. safeString16(properties.ascent) + // Typographic Ascent
  32619. safeString16(properties.descent) + // Typographic Descent
  32620. '\x00\x00' + // Line Gap
  32621. '\xFF\xFF' + // advanceWidthMax
  32622. '\x00\x00' + // minLeftSidebearing
  32623. '\x00\x00' + // minRightSidebearing
  32624. '\x00\x00' + // xMaxExtent
  32625. safeString16(properties.capHeight) + // caretSlopeRise
  32626. safeString16(Math.tan(properties.italicAngle) *
  32627. properties.xHeight) + // caretSlopeRun
  32628. '\x00\x00' + // caretOffset
  32629. '\x00\x00' + // -reserved-
  32630. '\x00\x00' + // -reserved-
  32631. '\x00\x00' + // -reserved-
  32632. '\x00\x00' + // -reserved-
  32633. '\x00\x00' + // metricDataFormat
  32634. string16(numGlyphs)); // Number of HMetrics
  32635. // Horizontal metrics
  32636. builder.addTable('hmtx', (function fontFieldsHmtx() {
  32637. var charstrings = font.charstrings;
  32638. var cffWidths = font.cff ? font.cff.widths : null;
  32639. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  32640. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  32641. var width = 0;
  32642. if (charstrings) {
  32643. var charstring = charstrings[i - 1];
  32644. width = 'width' in charstring ? charstring.width : 0;
  32645. } else if (cffWidths) {
  32646. width = Math.ceil(cffWidths[i] || 0);
  32647. }
  32648. hmtx += string16(width) + string16(0);
  32649. }
  32650. return hmtx;
  32651. })());
  32652. // Maximum profile
  32653. builder.addTable('maxp',
  32654. '\x00\x00\x50\x00' + // Version number
  32655. string16(numGlyphs)); // Num of glyphs
  32656. // Naming tables
  32657. builder.addTable('name', createNameTable(fontName));
  32658. // PostScript information
  32659. builder.addTable('post', createPostTable(properties));
  32660. return builder.toArray();
  32661. },
  32662. get spaceWidth() {
  32663. if ('_shadowWidth' in this) {
  32664. return this._shadowWidth;
  32665. }
  32666. // trying to estimate space character width
  32667. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  32668. var width;
  32669. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  32670. var glyphName = possibleSpaceReplacements[i];
  32671. // if possible, getting width by glyph name
  32672. if (glyphName in this.widths) {
  32673. width = this.widths[glyphName];
  32674. break;
  32675. }
  32676. var glyphsUnicodeMap = getGlyphsUnicode();
  32677. var glyphUnicode = glyphsUnicodeMap[glyphName];
  32678. // finding the charcode via unicodeToCID map
  32679. var charcode = 0;
  32680. if (this.composite) {
  32681. if (this.cMap.contains(glyphUnicode)) {
  32682. charcode = this.cMap.lookup(glyphUnicode);
  32683. }
  32684. }
  32685. // ... via toUnicode map
  32686. if (!charcode && this.toUnicode) {
  32687. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  32688. }
  32689. // setting it to unicode if negative or undefined
  32690. if (charcode <= 0) {
  32691. charcode = glyphUnicode;
  32692. }
  32693. // trying to get width via charcode
  32694. width = this.widths[charcode];
  32695. if (width) {
  32696. break; // the non-zero width found
  32697. }
  32698. }
  32699. width = width || this.defaultWidth;
  32700. // Do not shadow the property here. See discussion:
  32701. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  32702. this._shadowWidth = width;
  32703. return width;
  32704. },
  32705. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  32706. var fontCharCode, width, operatorListId;
  32707. var widthCode = charcode;
  32708. if (this.cMap && this.cMap.contains(charcode)) {
  32709. widthCode = this.cMap.lookup(charcode);
  32710. }
  32711. width = this.widths[widthCode];
  32712. width = isNum(width) ? width : this.defaultWidth;
  32713. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  32714. var unicode = this.toUnicode.get(charcode) || charcode;
  32715. if (typeof unicode === 'number') {
  32716. unicode = String.fromCharCode(unicode);
  32717. }
  32718. var isInFont = charcode in this.toFontChar;
  32719. // First try the toFontChar map, if it's not there then try falling
  32720. // back to the char code.
  32721. fontCharCode = this.toFontChar[charcode] || charcode;
  32722. if (this.missingFile) {
  32723. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  32724. }
  32725. if (this.isType3Font) {
  32726. // Font char code in this case is actually a glyph name.
  32727. operatorListId = fontCharCode;
  32728. }
  32729. var accent = null;
  32730. if (this.seacMap && this.seacMap[charcode]) {
  32731. isInFont = true;
  32732. var seac = this.seacMap[charcode];
  32733. fontCharCode = seac.baseFontCharCode;
  32734. accent = {
  32735. fontChar: String.fromCharCode(seac.accentFontCharCode),
  32736. offset: seac.accentOffset
  32737. };
  32738. }
  32739. var fontChar = String.fromCharCode(fontCharCode);
  32740. var glyph = this.glyphCache[charcode];
  32741. if (!glyph ||
  32742. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  32743. operatorListId, isSpace, isInFont)) {
  32744. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  32745. operatorListId, isSpace, isInFont);
  32746. this.glyphCache[charcode] = glyph;
  32747. }
  32748. return glyph;
  32749. },
  32750. charsToGlyphs: function Font_charsToGlyphs(chars) {
  32751. var charsCache = this.charsCache;
  32752. var glyphs, glyph, charcode;
  32753. // if we translated this string before, just grab it from the cache
  32754. if (charsCache) {
  32755. glyphs = charsCache[chars];
  32756. if (glyphs) {
  32757. return glyphs;
  32758. }
  32759. }
  32760. // lazily create the translation cache
  32761. if (!charsCache) {
  32762. charsCache = this.charsCache = Object.create(null);
  32763. }
  32764. glyphs = [];
  32765. var charsCacheKey = chars;
  32766. var i = 0, ii;
  32767. if (this.cMap) {
  32768. // composite fonts have multi-byte strings convert the string from
  32769. // single-byte to multi-byte
  32770. var c = Object.create(null);
  32771. while (i < chars.length) {
  32772. this.cMap.readCharCode(chars, i, c);
  32773. charcode = c.charcode;
  32774. var length = c.length;
  32775. i += length;
  32776. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  32777. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  32778. glyph = this.charToGlyph(charcode, isSpace);
  32779. glyphs.push(glyph);
  32780. }
  32781. } else {
  32782. for (i = 0, ii = chars.length; i < ii; ++i) {
  32783. charcode = chars.charCodeAt(i);
  32784. glyph = this.charToGlyph(charcode, charcode === 0x20);
  32785. glyphs.push(glyph);
  32786. }
  32787. }
  32788. // Enter the translated string into the cache
  32789. return (charsCache[charsCacheKey] = glyphs);
  32790. }
  32791. };
  32792. return Font;
  32793. })();
  32794. var ErrorFont = (function ErrorFontClosure() {
  32795. function ErrorFont(error) {
  32796. this.error = error;
  32797. this.loadedName = 'g_font_error';
  32798. this.loading = false;
  32799. }
  32800. ErrorFont.prototype = {
  32801. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  32802. return [];
  32803. },
  32804. exportData: function ErrorFont_exportData() {
  32805. return {error: this.error};
  32806. }
  32807. };
  32808. return ErrorFont;
  32809. })();
  32810. /**
  32811. * Shared logic for building a char code to glyph id mapping for Type1 and
  32812. * simple CFF fonts. See section 9.6.6.2 of the spec.
  32813. * @param {Object} properties Font properties object.
  32814. * @param {Object} builtInEncoding The encoding contained within the actual font
  32815. * data.
  32816. * @param {Array} glyphNames Array of glyph names where the index is the
  32817. * glyph ID.
  32818. * @returns {Object} A char code to glyph ID map.
  32819. */
  32820. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  32821. var charCodeToGlyphId = Object.create(null);
  32822. var glyphId, charCode, baseEncoding;
  32823. if (properties.baseEncodingName) {
  32824. // If a valid base encoding name was used, the mapping is initialized with
  32825. // that.
  32826. baseEncoding = getEncoding(properties.baseEncodingName);
  32827. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32828. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32829. if (glyphId >= 0) {
  32830. charCodeToGlyphId[charCode] = glyphId;
  32831. } else {
  32832. charCodeToGlyphId[charCode] = 0; // notdef
  32833. }
  32834. }
  32835. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  32836. // For a symbolic font the encoding should be the fonts built-in
  32837. // encoding.
  32838. for (charCode in builtInEncoding) {
  32839. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  32840. }
  32841. } else {
  32842. // For non-symbolic fonts that don't have a base encoding the standard
  32843. // encoding should be used.
  32844. baseEncoding = StandardEncoding;
  32845. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32846. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32847. if (glyphId >= 0) {
  32848. charCodeToGlyphId[charCode] = glyphId;
  32849. } else {
  32850. charCodeToGlyphId[charCode] = 0; // notdef
  32851. }
  32852. }
  32853. }
  32854. // Lastly, merge in the differences.
  32855. var differences = properties.differences, glyphsUnicodeMap;
  32856. if (differences) {
  32857. for (charCode in differences) {
  32858. var glyphName = differences[charCode];
  32859. glyphId = glyphNames.indexOf(glyphName);
  32860. if (glyphId === -1) {
  32861. if (!glyphsUnicodeMap) {
  32862. glyphsUnicodeMap = getGlyphsUnicode();
  32863. }
  32864. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32865. if (standardGlyphName !== glyphName) {
  32866. glyphId = glyphNames.indexOf(standardGlyphName);
  32867. }
  32868. }
  32869. if (glyphId >= 0) {
  32870. charCodeToGlyphId[charCode] = glyphId;
  32871. } else {
  32872. charCodeToGlyphId[charCode] = 0; // notdef
  32873. }
  32874. }
  32875. }
  32876. return charCodeToGlyphId;
  32877. }
  32878. // Type1Font is also a CIDFontType0.
  32879. var Type1Font = (function Type1FontClosure() {
  32880. function findBlock(streamBytes, signature, startIndex) {
  32881. var streamBytesLength = streamBytes.length;
  32882. var signatureLength = signature.length;
  32883. var scanLength = streamBytesLength - signatureLength;
  32884. var i = startIndex, j, found = false;
  32885. while (i < scanLength) {
  32886. j = 0;
  32887. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  32888. j++;
  32889. }
  32890. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  32891. i += j;
  32892. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  32893. i++;
  32894. }
  32895. found = true;
  32896. break;
  32897. }
  32898. i++;
  32899. }
  32900. return {
  32901. found: found,
  32902. length: i,
  32903. };
  32904. }
  32905. function getHeaderBlock(stream, suggestedLength) {
  32906. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  32907. var streamStartPos = stream.pos; // Save the initial stream position.
  32908. var headerBytes, headerBytesLength, block;
  32909. try {
  32910. headerBytes = stream.getBytes(suggestedLength);
  32911. headerBytesLength = headerBytes.length;
  32912. } catch (ex) {
  32913. if (ex instanceof MissingDataException) {
  32914. throw ex;
  32915. }
  32916. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  32917. // cannot hold the result of `getBytes`, and fallback to simply checking
  32918. // the entire stream (fixes issue3928.pdf).
  32919. }
  32920. if (headerBytesLength === suggestedLength) {
  32921. // Most of the time `suggestedLength` is correct, so to speed things up we
  32922. // initially only check the last few bytes to see if the header was found.
  32923. // Otherwise we (potentially) check the entire stream to prevent errors in
  32924. // `Type1Parser` (fixes issue5686.pdf).
  32925. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  32926. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  32927. if (block.found && block.length === suggestedLength) {
  32928. return {
  32929. stream: new Stream(headerBytes),
  32930. length: suggestedLength,
  32931. };
  32932. }
  32933. }
  32934. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  32935. stream.pos = streamStartPos; // Reset the stream position.
  32936. var SCAN_BLOCK_LENGTH = 2048;
  32937. var actualLength;
  32938. while (true) {
  32939. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  32940. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  32941. if (block.length === 0) {
  32942. break;
  32943. }
  32944. stream.pos += block.length; // Update the stream position.
  32945. if (block.found) {
  32946. actualLength = stream.pos - streamStartPos;
  32947. break;
  32948. }
  32949. }
  32950. stream.pos = streamStartPos; // Reset the stream position.
  32951. if (actualLength) {
  32952. return {
  32953. stream: new Stream(stream.getBytes(actualLength)),
  32954. length: actualLength,
  32955. };
  32956. }
  32957. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  32958. return {
  32959. stream: new Stream(stream.getBytes(suggestedLength)),
  32960. length: suggestedLength,
  32961. };
  32962. }
  32963. function getEexecBlock(stream, suggestedLength) {
  32964. // We should ideally parse the eexec block to ensure that `suggestedLength`
  32965. // is correct, so we don't truncate the block data if it's too small.
  32966. // However, this would also require checking if the fixed-content portion
  32967. // exists (using the 'Length3' property), and ensuring that it's valid.
  32968. //
  32969. // Given that `suggestedLength` almost always is correct, all the validation
  32970. // would require a great deal of unnecessary parsing for most fonts.
  32971. // To save time, we always fetch the entire stream instead, which also avoid
  32972. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  32973. //
  32974. // NOTE: This means that the function can include the fixed-content portion
  32975. // in the returned eexec block. In practice this does *not* seem to matter,
  32976. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  32977. var eexecBytes = stream.getBytes();
  32978. return {
  32979. stream: new Stream(eexecBytes),
  32980. length: eexecBytes.length,
  32981. };
  32982. }
  32983. function Type1Font(name, file, properties) {
  32984. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  32985. // Also, length1 and length2 might be off by 6 bytes as well.
  32986. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  32987. var PFB_HEADER_SIZE = 6;
  32988. var headerBlockLength = properties.length1;
  32989. var eexecBlockLength = properties.length2;
  32990. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  32991. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  32992. if (pfbHeaderPresent) {
  32993. file.skip(PFB_HEADER_SIZE);
  32994. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  32995. (pfbHeader[3] << 8) | pfbHeader[2];
  32996. }
  32997. // Get the data block containing glyphs and subrs information
  32998. var headerBlock = getHeaderBlock(file, headerBlockLength);
  32999. headerBlockLength = headerBlock.length;
  33000. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  33001. SEAC_ANALYSIS_ENABLED);
  33002. headerBlockParser.extractFontHeader(properties);
  33003. if (pfbHeaderPresent) {
  33004. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  33005. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  33006. (pfbHeader[3] << 8) | pfbHeader[2];
  33007. }
  33008. // Decrypt the data blocks and retrieve it's content
  33009. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  33010. eexecBlockLength = eexecBlock.length;
  33011. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  33012. SEAC_ANALYSIS_ENABLED);
  33013. var data = eexecBlockParser.extractFontProgram();
  33014. for (var info in data.properties) {
  33015. properties[info] = data.properties[info];
  33016. }
  33017. var charstrings = data.charstrings;
  33018. var type2Charstrings = this.getType2Charstrings(charstrings);
  33019. var subrs = this.getType2Subrs(data.subrs);
  33020. this.charstrings = charstrings;
  33021. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  33022. subrs, properties);
  33023. this.seacs = this.getSeacs(data.charstrings);
  33024. }
  33025. Type1Font.prototype = {
  33026. get numGlyphs() {
  33027. return this.charstrings.length + 1;
  33028. },
  33029. getCharset: function Type1Font_getCharset() {
  33030. var charset = ['.notdef'];
  33031. var charstrings = this.charstrings;
  33032. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  33033. charset.push(charstrings[glyphId].glyphName);
  33034. }
  33035. return charset;
  33036. },
  33037. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  33038. var charstrings = this.charstrings;
  33039. var glyphNames = ['.notdef'], glyphId;
  33040. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  33041. glyphNames.push(charstrings[glyphId].glyphName);
  33042. }
  33043. var encoding = properties.builtInEncoding;
  33044. if (encoding) {
  33045. var builtInEncoding = Object.create(null);
  33046. for (var charCode in encoding) {
  33047. glyphId = glyphNames.indexOf(encoding[charCode]);
  33048. if (glyphId >= 0) {
  33049. builtInEncoding[charCode] = glyphId;
  33050. }
  33051. }
  33052. }
  33053. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  33054. },
  33055. getSeacs: function Type1Font_getSeacs(charstrings) {
  33056. var i, ii;
  33057. var seacMap = [];
  33058. for (i = 0, ii = charstrings.length; i < ii; i++) {
  33059. var charstring = charstrings[i];
  33060. if (charstring.seac) {
  33061. // Offset by 1 for .notdef
  33062. seacMap[i + 1] = charstring.seac;
  33063. }
  33064. }
  33065. return seacMap;
  33066. },
  33067. getType2Charstrings: function Type1Font_getType2Charstrings(
  33068. type1Charstrings) {
  33069. var type2Charstrings = [];
  33070. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  33071. type2Charstrings.push(type1Charstrings[i].charstring);
  33072. }
  33073. return type2Charstrings;
  33074. },
  33075. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  33076. var bias = 0;
  33077. var count = type1Subrs.length;
  33078. if (count < 1133) {
  33079. bias = 107;
  33080. } else if (count < 33769) {
  33081. bias = 1131;
  33082. } else {
  33083. bias = 32768;
  33084. }
  33085. // Add a bunch of empty subrs to deal with the Type2 bias
  33086. var type2Subrs = [];
  33087. var i;
  33088. for (i = 0; i < bias; i++) {
  33089. type2Subrs.push([0x0B]);
  33090. }
  33091. for (i = 0; i < count; i++) {
  33092. type2Subrs.push(type1Subrs[i]);
  33093. }
  33094. return type2Subrs;
  33095. },
  33096. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  33097. properties) {
  33098. var cff = new CFF();
  33099. cff.header = new CFFHeader(1, 0, 4, 4);
  33100. cff.names = [name];
  33101. var topDict = new CFFTopDict();
  33102. // CFF strings IDs 0...390 are predefined names, so refering
  33103. // to entries in our own String INDEX starts at SID 391.
  33104. topDict.setByName('version', 391);
  33105. topDict.setByName('Notice', 392);
  33106. topDict.setByName('FullName', 393);
  33107. topDict.setByName('FamilyName', 394);
  33108. topDict.setByName('Weight', 395);
  33109. topDict.setByName('Encoding', null); // placeholder
  33110. topDict.setByName('FontMatrix', properties.fontMatrix);
  33111. topDict.setByName('FontBBox', properties.bbox);
  33112. topDict.setByName('charset', null); // placeholder
  33113. topDict.setByName('CharStrings', null); // placeholder
  33114. topDict.setByName('Private', null); // placeholder
  33115. cff.topDict = topDict;
  33116. var strings = new CFFStrings();
  33117. strings.add('Version 0.11'); // Version
  33118. strings.add('See original notice'); // Notice
  33119. strings.add(name); // FullName
  33120. strings.add(name); // FamilyName
  33121. strings.add('Medium'); // Weight
  33122. cff.strings = strings;
  33123. cff.globalSubrIndex = new CFFIndex();
  33124. var count = glyphs.length;
  33125. var charsetArray = [0];
  33126. var i, ii;
  33127. for (i = 0; i < count; i++) {
  33128. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  33129. // TODO: Insert the string and correctly map it. Previously it was
  33130. // thought mapping names that aren't in the standard strings to .notdef
  33131. // was fine, however in issue818 when mapping them all to .notdef the
  33132. // adieresis glyph no longer worked.
  33133. if (index === -1) {
  33134. index = 0;
  33135. }
  33136. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  33137. }
  33138. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  33139. var charStringsIndex = new CFFIndex();
  33140. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  33141. for (i = 0; i < count; i++) {
  33142. charStringsIndex.add(glyphs[i]);
  33143. }
  33144. cff.charStrings = charStringsIndex;
  33145. var privateDict = new CFFPrivateDict();
  33146. privateDict.setByName('Subrs', null); // placeholder
  33147. var fields = [
  33148. 'BlueValues',
  33149. 'OtherBlues',
  33150. 'FamilyBlues',
  33151. 'FamilyOtherBlues',
  33152. 'StemSnapH',
  33153. 'StemSnapV',
  33154. 'BlueShift',
  33155. 'BlueFuzz',
  33156. 'BlueScale',
  33157. 'LanguageGroup',
  33158. 'ExpansionFactor',
  33159. 'ForceBold',
  33160. 'StdHW',
  33161. 'StdVW'
  33162. ];
  33163. for (i = 0, ii = fields.length; i < ii; i++) {
  33164. var field = fields[i];
  33165. if (!(field in properties.privateData)) {
  33166. continue;
  33167. }
  33168. var value = properties.privateData[field];
  33169. if (isArray(value)) {
  33170. // All of the private dictionary array data in CFF must be stored as
  33171. // "delta-encoded" numbers.
  33172. for (var j = value.length - 1; j > 0; j--) {
  33173. value[j] -= value[j - 1]; // ... difference from previous value
  33174. }
  33175. }
  33176. privateDict.setByName(field, value);
  33177. }
  33178. cff.topDict.privateDict = privateDict;
  33179. var subrIndex = new CFFIndex();
  33180. for (i = 0, ii = subrs.length; i < ii; i++) {
  33181. subrIndex.add(subrs[i]);
  33182. }
  33183. privateDict.subrsIndex = subrIndex;
  33184. var compiler = new CFFCompiler(cff);
  33185. return compiler.compile();
  33186. }
  33187. };
  33188. return Type1Font;
  33189. })();
  33190. var CFFFont = (function CFFFontClosure() {
  33191. function CFFFont(file, properties) {
  33192. this.properties = properties;
  33193. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  33194. this.cff = parser.parse();
  33195. var compiler = new CFFCompiler(this.cff);
  33196. this.seacs = this.cff.seacs;
  33197. try {
  33198. this.data = compiler.compile();
  33199. } catch (e) {
  33200. warn('Failed to compile font ' + properties.loadedName);
  33201. // There may have just been an issue with the compiler, set the data
  33202. // anyway and hope the font loaded.
  33203. this.data = file;
  33204. }
  33205. }
  33206. CFFFont.prototype = {
  33207. get numGlyphs() {
  33208. return this.cff.charStrings.count;
  33209. },
  33210. getCharset: function CFFFont_getCharset() {
  33211. return this.cff.charset.charset;
  33212. },
  33213. getGlyphMapping: function CFFFont_getGlyphMapping() {
  33214. var cff = this.cff;
  33215. var properties = this.properties;
  33216. var charsets = cff.charset.charset;
  33217. var charCodeToGlyphId;
  33218. var glyphId;
  33219. if (properties.composite) {
  33220. charCodeToGlyphId = Object.create(null);
  33221. if (cff.isCIDFont) {
  33222. // If the font is actually a CID font then we should use the charset
  33223. // to map CIDs to GIDs.
  33224. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  33225. var cid = charsets[glyphId];
  33226. var charCode = properties.cMap.charCodeOf(cid);
  33227. charCodeToGlyphId[charCode] = glyphId;
  33228. }
  33229. } else {
  33230. // If it is NOT actually a CID font then CIDs should be mapped
  33231. // directly to GIDs.
  33232. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  33233. charCodeToGlyphId[glyphId] = glyphId;
  33234. }
  33235. }
  33236. return charCodeToGlyphId;
  33237. }
  33238. var encoding = cff.encoding ? cff.encoding.encoding : null;
  33239. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  33240. return charCodeToGlyphId;
  33241. }
  33242. };
  33243. return CFFFont;
  33244. })();
  33245. // Workaround for seac on Windows.
  33246. (function checkSeacSupport() {
  33247. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  33248. SEAC_ANALYSIS_ENABLED = true;
  33249. }
  33250. })();
  33251. // Workaround for Private Use Area characters in Chrome on Windows
  33252. // http://code.google.com/p/chromium/issues/detail?id=122465
  33253. // https://github.com/mozilla/pdf.js/issues/1689
  33254. (function checkChromeWindows() {
  33255. if (typeof navigator !== 'undefined' &&
  33256. /Windows.*Chrome/.test(navigator.userAgent)) {
  33257. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  33258. }
  33259. })();
  33260. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  33261. exports.ErrorFont = ErrorFont;
  33262. exports.Font = Font;
  33263. exports.FontFlags = FontFlags;
  33264. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  33265. exports.ToUnicodeMap = ToUnicodeMap;
  33266. exports.getFontType = getFontType;
  33267. }));
  33268. (function (root, factory) {
  33269. {
  33270. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  33271. root.pdfjsCoreParser);
  33272. }
  33273. }(this, function (exports, sharedUtil, coreParser) {
  33274. var error = sharedUtil.error;
  33275. var isSpace = sharedUtil.isSpace;
  33276. var EOF = coreParser.EOF;
  33277. var PostScriptParser = (function PostScriptParserClosure() {
  33278. function PostScriptParser(lexer) {
  33279. this.lexer = lexer;
  33280. this.operators = [];
  33281. this.token = null;
  33282. this.prev = null;
  33283. }
  33284. PostScriptParser.prototype = {
  33285. nextToken: function PostScriptParser_nextToken() {
  33286. this.prev = this.token;
  33287. this.token = this.lexer.getToken();
  33288. },
  33289. accept: function PostScriptParser_accept(type) {
  33290. if (this.token.type === type) {
  33291. this.nextToken();
  33292. return true;
  33293. }
  33294. return false;
  33295. },
  33296. expect: function PostScriptParser_expect(type) {
  33297. if (this.accept(type)) {
  33298. return true;
  33299. }
  33300. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  33301. type + '.');
  33302. },
  33303. parse: function PostScriptParser_parse() {
  33304. this.nextToken();
  33305. this.expect(PostScriptTokenTypes.LBRACE);
  33306. this.parseBlock();
  33307. this.expect(PostScriptTokenTypes.RBRACE);
  33308. return this.operators;
  33309. },
  33310. parseBlock: function PostScriptParser_parseBlock() {
  33311. while (true) {
  33312. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  33313. this.operators.push(this.prev.value);
  33314. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  33315. this.operators.push(this.prev.value);
  33316. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33317. this.parseCondition();
  33318. } else {
  33319. return;
  33320. }
  33321. }
  33322. },
  33323. parseCondition: function PostScriptParser_parseCondition() {
  33324. // Add two place holders that will be updated later
  33325. var conditionLocation = this.operators.length;
  33326. this.operators.push(null, null);
  33327. this.parseBlock();
  33328. this.expect(PostScriptTokenTypes.RBRACE);
  33329. if (this.accept(PostScriptTokenTypes.IF)) {
  33330. // The true block is right after the 'if' so it just falls through on
  33331. // true else it jumps and skips the true block.
  33332. this.operators[conditionLocation] = this.operators.length;
  33333. this.operators[conditionLocation + 1] = 'jz';
  33334. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33335. var jumpLocation = this.operators.length;
  33336. this.operators.push(null, null);
  33337. var endOfTrue = this.operators.length;
  33338. this.parseBlock();
  33339. this.expect(PostScriptTokenTypes.RBRACE);
  33340. this.expect(PostScriptTokenTypes.IFELSE);
  33341. // The jump is added at the end of the true block to skip the false
  33342. // block.
  33343. this.operators[jumpLocation] = this.operators.length;
  33344. this.operators[jumpLocation + 1] = 'j';
  33345. this.operators[conditionLocation] = endOfTrue;
  33346. this.operators[conditionLocation + 1] = 'jz';
  33347. } else {
  33348. error('PS Function: error parsing conditional.');
  33349. }
  33350. }
  33351. };
  33352. return PostScriptParser;
  33353. })();
  33354. var PostScriptTokenTypes = {
  33355. LBRACE: 0,
  33356. RBRACE: 1,
  33357. NUMBER: 2,
  33358. OPERATOR: 3,
  33359. IF: 4,
  33360. IFELSE: 5
  33361. };
  33362. var PostScriptToken = (function PostScriptTokenClosure() {
  33363. function PostScriptToken(type, value) {
  33364. this.type = type;
  33365. this.value = value;
  33366. }
  33367. var opCache = Object.create(null);
  33368. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  33369. var opValue = opCache[op];
  33370. if (opValue) {
  33371. return opValue;
  33372. }
  33373. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  33374. };
  33375. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  33376. '{');
  33377. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  33378. '}');
  33379. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  33380. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  33381. 'IFELSE');
  33382. return PostScriptToken;
  33383. })();
  33384. var PostScriptLexer = (function PostScriptLexerClosure() {
  33385. function PostScriptLexer(stream) {
  33386. this.stream = stream;
  33387. this.nextChar();
  33388. this.strBuf = [];
  33389. }
  33390. PostScriptLexer.prototype = {
  33391. nextChar: function PostScriptLexer_nextChar() {
  33392. return (this.currentChar = this.stream.getByte());
  33393. },
  33394. getToken: function PostScriptLexer_getToken() {
  33395. var comment = false;
  33396. var ch = this.currentChar;
  33397. // skip comments
  33398. while (true) {
  33399. if (ch < 0) {
  33400. return EOF;
  33401. }
  33402. if (comment) {
  33403. if (ch === 0x0A || ch === 0x0D) {
  33404. comment = false;
  33405. }
  33406. } else if (ch === 0x25) { // '%'
  33407. comment = true;
  33408. } else if (!isSpace(ch)) {
  33409. break;
  33410. }
  33411. ch = this.nextChar();
  33412. }
  33413. switch (ch | 0) {
  33414. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  33415. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  33416. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  33417. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  33418. this.getNumber());
  33419. case 0x7B: // '{'
  33420. this.nextChar();
  33421. return PostScriptToken.LBRACE;
  33422. case 0x7D: // '}'
  33423. this.nextChar();
  33424. return PostScriptToken.RBRACE;
  33425. }
  33426. // operator
  33427. var strBuf = this.strBuf;
  33428. strBuf.length = 0;
  33429. strBuf[0] = String.fromCharCode(ch);
  33430. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  33431. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  33432. strBuf.push(String.fromCharCode(ch));
  33433. }
  33434. var str = strBuf.join('');
  33435. switch (str.toLowerCase()) {
  33436. case 'if':
  33437. return PostScriptToken.IF;
  33438. case 'ifelse':
  33439. return PostScriptToken.IFELSE;
  33440. default:
  33441. return PostScriptToken.getOperator(str);
  33442. }
  33443. },
  33444. getNumber: function PostScriptLexer_getNumber() {
  33445. var ch = this.currentChar;
  33446. var strBuf = this.strBuf;
  33447. strBuf.length = 0;
  33448. strBuf[0] = String.fromCharCode(ch);
  33449. while ((ch = this.nextChar()) >= 0) {
  33450. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  33451. ch === 0x2D || ch === 0x2E) { // '-', '.'
  33452. strBuf.push(String.fromCharCode(ch));
  33453. } else {
  33454. break;
  33455. }
  33456. }
  33457. var value = parseFloat(strBuf.join(''));
  33458. if (isNaN(value)) {
  33459. error('Invalid floating point number: ' + value);
  33460. }
  33461. return value;
  33462. }
  33463. };
  33464. return PostScriptLexer;
  33465. })();
  33466. exports.PostScriptLexer = PostScriptLexer;
  33467. exports.PostScriptParser = PostScriptParser;
  33468. }));
  33469. (function (root, factory) {
  33470. {
  33471. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  33472. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper,
  33473. root.pdfjsDisplayWebGL);
  33474. }
  33475. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper,
  33476. displayWebGL) {
  33477. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33478. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33479. var ImageKind = sharedUtil.ImageKind;
  33480. var OPS = sharedUtil.OPS;
  33481. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33482. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  33483. var Util = sharedUtil.Util;
  33484. var assert = sharedUtil.assert;
  33485. var info = sharedUtil.info;
  33486. var isNum = sharedUtil.isNum;
  33487. var isArray = sharedUtil.isArray;
  33488. var isLittleEndian = sharedUtil.isLittleEndian;
  33489. var error = sharedUtil.error;
  33490. var shadow = sharedUtil.shadow;
  33491. var warn = sharedUtil.warn;
  33492. var TilingPattern = displayPatternHelper.TilingPattern;
  33493. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  33494. var WebGLUtils = displayWebGL.WebGLUtils;
  33495. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  33496. // <canvas> contexts store most of the state we need natively.
  33497. // However, PDF needs a bit more state, which we store here.
  33498. // Minimal font size that would be used during canvas fillText operations.
  33499. var MIN_FONT_SIZE = 16;
  33500. // Maximum font size that would be used during canvas fillText operations.
  33501. var MAX_FONT_SIZE = 100;
  33502. var MAX_GROUP_SIZE = 4096;
  33503. // Heuristic value used when enforcing minimum line widths.
  33504. var MIN_WIDTH_FACTOR = 0.65;
  33505. var COMPILE_TYPE3_GLYPHS = true;
  33506. var MAX_SIZE_TO_COMPILE = 1000;
  33507. var FULL_CHUNK_HEIGHT = 16;
  33508. var HasCanvasTypedArraysCached = {
  33509. get value() {
  33510. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  33511. }
  33512. };
  33513. var IsLittleEndianCached = {
  33514. get value() {
  33515. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  33516. }
  33517. };
  33518. function createScratchCanvas(width, height) {
  33519. var canvas = document.createElement('canvas');
  33520. canvas.width = width;
  33521. canvas.height = height;
  33522. return canvas;
  33523. }
  33524. function addContextCurrentTransform(ctx) {
  33525. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  33526. if (!ctx.mozCurrentTransform) {
  33527. ctx._originalSave = ctx.save;
  33528. ctx._originalRestore = ctx.restore;
  33529. ctx._originalRotate = ctx.rotate;
  33530. ctx._originalScale = ctx.scale;
  33531. ctx._originalTranslate = ctx.translate;
  33532. ctx._originalTransform = ctx.transform;
  33533. ctx._originalSetTransform = ctx.setTransform;
  33534. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  33535. ctx._transformStack = [];
  33536. Object.defineProperty(ctx, 'mozCurrentTransform', {
  33537. get: function getCurrentTransform() {
  33538. return this._transformMatrix;
  33539. }
  33540. });
  33541. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  33542. get: function getCurrentTransformInverse() {
  33543. // Calculation done using WolframAlpha:
  33544. // http://www.wolframalpha.com/input/?
  33545. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  33546. var m = this._transformMatrix;
  33547. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  33548. var ad_bc = a * d - b * c;
  33549. var bc_ad = b * c - a * d;
  33550. return [
  33551. d / ad_bc,
  33552. b / bc_ad,
  33553. c / bc_ad,
  33554. a / ad_bc,
  33555. (d * e - c * f) / bc_ad,
  33556. (b * e - a * f) / ad_bc
  33557. ];
  33558. }
  33559. });
  33560. ctx.save = function ctxSave() {
  33561. var old = this._transformMatrix;
  33562. this._transformStack.push(old);
  33563. this._transformMatrix = old.slice(0, 6);
  33564. this._originalSave();
  33565. };
  33566. ctx.restore = function ctxRestore() {
  33567. var prev = this._transformStack.pop();
  33568. if (prev) {
  33569. this._transformMatrix = prev;
  33570. this._originalRestore();
  33571. }
  33572. };
  33573. ctx.translate = function ctxTranslate(x, y) {
  33574. var m = this._transformMatrix;
  33575. m[4] = m[0] * x + m[2] * y + m[4];
  33576. m[5] = m[1] * x + m[3] * y + m[5];
  33577. this._originalTranslate(x, y);
  33578. };
  33579. ctx.scale = function ctxScale(x, y) {
  33580. var m = this._transformMatrix;
  33581. m[0] = m[0] * x;
  33582. m[1] = m[1] * x;
  33583. m[2] = m[2] * y;
  33584. m[3] = m[3] * y;
  33585. this._originalScale(x, y);
  33586. };
  33587. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  33588. var m = this._transformMatrix;
  33589. this._transformMatrix = [
  33590. m[0] * a + m[2] * b,
  33591. m[1] * a + m[3] * b,
  33592. m[0] * c + m[2] * d,
  33593. m[1] * c + m[3] * d,
  33594. m[0] * e + m[2] * f + m[4],
  33595. m[1] * e + m[3] * f + m[5]
  33596. ];
  33597. ctx._originalTransform(a, b, c, d, e, f);
  33598. };
  33599. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  33600. this._transformMatrix = [a, b, c, d, e, f];
  33601. ctx._originalSetTransform(a, b, c, d, e, f);
  33602. };
  33603. ctx.rotate = function ctxRotate(angle) {
  33604. var cosValue = Math.cos(angle);
  33605. var sinValue = Math.sin(angle);
  33606. var m = this._transformMatrix;
  33607. this._transformMatrix = [
  33608. m[0] * cosValue + m[2] * sinValue,
  33609. m[1] * cosValue + m[3] * sinValue,
  33610. m[0] * (-sinValue) + m[2] * cosValue,
  33611. m[1] * (-sinValue) + m[3] * cosValue,
  33612. m[4],
  33613. m[5]
  33614. ];
  33615. this._originalRotate(angle);
  33616. };
  33617. }
  33618. }
  33619. var CachedCanvases = (function CachedCanvasesClosure() {
  33620. function CachedCanvases() {
  33621. this.cache = Object.create(null);
  33622. }
  33623. CachedCanvases.prototype = {
  33624. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  33625. trackTransform) {
  33626. var canvasEntry;
  33627. if (this.cache[id] !== undefined) {
  33628. canvasEntry = this.cache[id];
  33629. canvasEntry.canvas.width = width;
  33630. canvasEntry.canvas.height = height;
  33631. // reset canvas transform for emulated mozCurrentTransform, if needed
  33632. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  33633. } else {
  33634. var canvas = createScratchCanvas(width, height);
  33635. var ctx = canvas.getContext('2d');
  33636. if (trackTransform) {
  33637. addContextCurrentTransform(ctx);
  33638. }
  33639. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  33640. }
  33641. return canvasEntry;
  33642. },
  33643. clear: function () {
  33644. for (var id in this.cache) {
  33645. var canvasEntry = this.cache[id];
  33646. // Zeroing the width and height causes Firefox to release graphics
  33647. // resources immediately, which can greatly reduce memory consumption.
  33648. canvasEntry.canvas.width = 0;
  33649. canvasEntry.canvas.height = 0;
  33650. delete this.cache[id];
  33651. }
  33652. }
  33653. };
  33654. return CachedCanvases;
  33655. })();
  33656. function compileType3Glyph(imgData) {
  33657. var POINT_TO_PROCESS_LIMIT = 1000;
  33658. var width = imgData.width, height = imgData.height;
  33659. var i, j, j0, width1 = width + 1;
  33660. var points = new Uint8Array(width1 * (height + 1));
  33661. var POINT_TYPES =
  33662. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  33663. // decodes bit-packed mask data
  33664. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  33665. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  33666. for (i = 0, ii = data0.length; i < ii; i++) {
  33667. var mask = 128, elem = data0[i];
  33668. while (mask > 0) {
  33669. data[pos++] = (elem & mask) ? 0 : 255;
  33670. mask >>= 1;
  33671. }
  33672. }
  33673. // finding iteresting points: every point is located between mask pixels,
  33674. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  33675. // will have flags assigned based on neighboring mask pixels:
  33676. // 4 | 8
  33677. // --P--
  33678. // 2 | 1
  33679. // We are interested only in points with the flags:
  33680. // - outside corners: 1, 2, 4, 8;
  33681. // - inside corners: 7, 11, 13, 14;
  33682. // - and, intersections: 5, 10.
  33683. var count = 0;
  33684. pos = 0;
  33685. if (data[pos] !== 0) {
  33686. points[0] = 1;
  33687. ++count;
  33688. }
  33689. for (j = 1; j < width; j++) {
  33690. if (data[pos] !== data[pos + 1]) {
  33691. points[j] = data[pos] ? 2 : 1;
  33692. ++count;
  33693. }
  33694. pos++;
  33695. }
  33696. if (data[pos] !== 0) {
  33697. points[j] = 2;
  33698. ++count;
  33699. }
  33700. for (i = 1; i < height; i++) {
  33701. pos = i * lineSize;
  33702. j0 = i * width1;
  33703. if (data[pos - lineSize] !== data[pos]) {
  33704. points[j0] = data[pos] ? 1 : 8;
  33705. ++count;
  33706. }
  33707. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  33708. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  33709. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  33710. for (j = 1; j < width; j++) {
  33711. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  33712. (data[pos - lineSize + 1] ? 8 : 0);
  33713. if (POINT_TYPES[sum]) {
  33714. points[j0 + j] = POINT_TYPES[sum];
  33715. ++count;
  33716. }
  33717. pos++;
  33718. }
  33719. if (data[pos - lineSize] !== data[pos]) {
  33720. points[j0 + j] = data[pos] ? 2 : 4;
  33721. ++count;
  33722. }
  33723. if (count > POINT_TO_PROCESS_LIMIT) {
  33724. return null;
  33725. }
  33726. }
  33727. pos = lineSize * (height - 1);
  33728. j0 = i * width1;
  33729. if (data[pos] !== 0) {
  33730. points[j0] = 8;
  33731. ++count;
  33732. }
  33733. for (j = 1; j < width; j++) {
  33734. if (data[pos] !== data[pos + 1]) {
  33735. points[j0 + j] = data[pos] ? 4 : 8;
  33736. ++count;
  33737. }
  33738. pos++;
  33739. }
  33740. if (data[pos] !== 0) {
  33741. points[j0 + j] = 4;
  33742. ++count;
  33743. }
  33744. if (count > POINT_TO_PROCESS_LIMIT) {
  33745. return null;
  33746. }
  33747. // building outlines
  33748. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  33749. var outlines = [];
  33750. for (i = 0; count && i <= height; i++) {
  33751. var p = i * width1;
  33752. var end = p + width;
  33753. while (p < end && !points[p]) {
  33754. p++;
  33755. }
  33756. if (p === end) {
  33757. continue;
  33758. }
  33759. var coords = [p % width1, i];
  33760. var type = points[p], p0 = p, pp;
  33761. do {
  33762. var step = steps[type];
  33763. do {
  33764. p += step;
  33765. } while (!points[p]);
  33766. pp = points[p];
  33767. if (pp !== 5 && pp !== 10) {
  33768. // set new direction
  33769. type = pp;
  33770. // delete mark
  33771. points[p] = 0;
  33772. } else { // type is 5 or 10, ie, a crossing
  33773. // set new direction
  33774. type = pp & ((0x33 * type) >> 4);
  33775. // set new type for "future hit"
  33776. points[p] &= (type >> 2 | type << 2);
  33777. }
  33778. coords.push(p % width1);
  33779. coords.push((p / width1) | 0);
  33780. --count;
  33781. } while (p0 !== p);
  33782. outlines.push(coords);
  33783. --i;
  33784. }
  33785. var drawOutline = function(c) {
  33786. c.save();
  33787. // the path shall be painted in [0..1]x[0..1] space
  33788. c.scale(1 / width, -1 / height);
  33789. c.translate(0, -height);
  33790. c.beginPath();
  33791. for (var i = 0, ii = outlines.length; i < ii; i++) {
  33792. var o = outlines[i];
  33793. c.moveTo(o[0], o[1]);
  33794. for (var j = 2, jj = o.length; j < jj; j += 2) {
  33795. c.lineTo(o[j], o[j+1]);
  33796. }
  33797. }
  33798. c.fill();
  33799. c.beginPath();
  33800. c.restore();
  33801. };
  33802. return drawOutline;
  33803. }
  33804. var CanvasExtraState = (function CanvasExtraStateClosure() {
  33805. function CanvasExtraState(old) {
  33806. // Are soft masks and alpha values shapes or opacities?
  33807. this.alphaIsShape = false;
  33808. this.fontSize = 0;
  33809. this.fontSizeScale = 1;
  33810. this.textMatrix = IDENTITY_MATRIX;
  33811. this.textMatrixScale = 1;
  33812. this.fontMatrix = FONT_IDENTITY_MATRIX;
  33813. this.leading = 0;
  33814. // Current point (in user coordinates)
  33815. this.x = 0;
  33816. this.y = 0;
  33817. // Start of text line (in text coordinates)
  33818. this.lineX = 0;
  33819. this.lineY = 0;
  33820. // Character and word spacing
  33821. this.charSpacing = 0;
  33822. this.wordSpacing = 0;
  33823. this.textHScale = 1;
  33824. this.textRenderingMode = TextRenderingMode.FILL;
  33825. this.textRise = 0;
  33826. // Default fore and background colors
  33827. this.fillColor = '#000000';
  33828. this.strokeColor = '#000000';
  33829. this.patternFill = false;
  33830. // Note: fill alpha applies to all non-stroking operations
  33831. this.fillAlpha = 1;
  33832. this.strokeAlpha = 1;
  33833. this.lineWidth = 1;
  33834. this.activeSMask = null;
  33835. this.resumeSMaskCtx = null; // nonclonable field (see the save method below)
  33836. this.old = old;
  33837. }
  33838. CanvasExtraState.prototype = {
  33839. clone: function CanvasExtraState_clone() {
  33840. return Object.create(this);
  33841. },
  33842. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  33843. this.x = x;
  33844. this.y = y;
  33845. }
  33846. };
  33847. return CanvasExtraState;
  33848. })();
  33849. var CanvasGraphics = (function CanvasGraphicsClosure() {
  33850. // Defines the time the executeOperatorList is going to be executing
  33851. // before it stops and shedules a continue of execution.
  33852. var EXECUTION_TIME = 15;
  33853. // Defines the number of steps before checking the execution time
  33854. var EXECUTION_STEPS = 10;
  33855. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  33856. this.ctx = canvasCtx;
  33857. this.current = new CanvasExtraState();
  33858. this.stateStack = [];
  33859. this.pendingClip = null;
  33860. this.pendingEOFill = false;
  33861. this.res = null;
  33862. this.xobjs = null;
  33863. this.commonObjs = commonObjs;
  33864. this.objs = objs;
  33865. this.imageLayer = imageLayer;
  33866. this.groupStack = [];
  33867. this.processingType3 = null;
  33868. // Patterns are painted relative to the initial page/form transform, see pdf
  33869. // spec 8.7.2 NOTE 1.
  33870. this.baseTransform = null;
  33871. this.baseTransformStack = [];
  33872. this.groupLevel = 0;
  33873. this.smaskStack = [];
  33874. this.smaskCounter = 0;
  33875. this.tempSMask = null;
  33876. this.cachedCanvases = new CachedCanvases();
  33877. if (canvasCtx) {
  33878. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  33879. // the transformation must already be set in canvasCtx._transformMatrix.
  33880. addContextCurrentTransform(canvasCtx);
  33881. }
  33882. this.cachedGetSinglePixelWidth = null;
  33883. }
  33884. function putBinaryImageData(ctx, imgData) {
  33885. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  33886. ctx.putImageData(imgData, 0, 0);
  33887. return;
  33888. }
  33889. // Put the image data to the canvas in chunks, rather than putting the
  33890. // whole image at once. This saves JS memory, because the ImageData object
  33891. // is smaller. It also possibly saves C++ memory within the implementation
  33892. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  33893. // the data passed to putImageData()). |n| shouldn't be too small, however,
  33894. // because too many putImageData() calls will slow things down.
  33895. //
  33896. // Note: as written, if the last chunk is partial, the putImageData() call
  33897. // will (conceptually) put pixels past the bounds of the canvas. But
  33898. // that's ok; any such pixels are ignored.
  33899. var height = imgData.height, width = imgData.width;
  33900. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  33901. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  33902. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  33903. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  33904. var srcPos = 0, destPos;
  33905. var src = imgData.data;
  33906. var dest = chunkImgData.data;
  33907. var i, j, thisChunkHeight, elemsInThisChunk;
  33908. // There are multiple forms in which the pixel data can be passed, and
  33909. // imgData.kind tells us which one this is.
  33910. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  33911. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  33912. var srcLength = src.byteLength;
  33913. var dest32 = HasCanvasTypedArraysCached.value ?
  33914. new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  33915. var dest32DataLength = dest32.length;
  33916. var fullSrcDiff = (width + 7) >> 3;
  33917. var white = 0xFFFFFFFF;
  33918. var black = (IsLittleEndianCached.value ||
  33919. !HasCanvasTypedArraysCached.value) ? 0xFF000000 : 0x000000FF;
  33920. for (i = 0; i < totalChunks; i++) {
  33921. thisChunkHeight =
  33922. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  33923. destPos = 0;
  33924. for (j = 0; j < thisChunkHeight; j++) {
  33925. var srcDiff = srcLength - srcPos;
  33926. var k = 0;
  33927. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  33928. var kEndUnrolled = kEnd & ~7;
  33929. var mask = 0;
  33930. var srcByte = 0;
  33931. for (; k < kEndUnrolled; k += 8) {
  33932. srcByte = src[srcPos++];
  33933. dest32[destPos++] = (srcByte & 128) ? white : black;
  33934. dest32[destPos++] = (srcByte & 64) ? white : black;
  33935. dest32[destPos++] = (srcByte & 32) ? white : black;
  33936. dest32[destPos++] = (srcByte & 16) ? white : black;
  33937. dest32[destPos++] = (srcByte & 8) ? white : black;
  33938. dest32[destPos++] = (srcByte & 4) ? white : black;
  33939. dest32[destPos++] = (srcByte & 2) ? white : black;
  33940. dest32[destPos++] = (srcByte & 1) ? white : black;
  33941. }
  33942. for (; k < kEnd; k++) {
  33943. if (mask === 0) {
  33944. srcByte = src[srcPos++];
  33945. mask = 128;
  33946. }
  33947. dest32[destPos++] = (srcByte & mask) ? white : black;
  33948. mask >>= 1;
  33949. }
  33950. }
  33951. // We ran out of input. Make all remaining pixels transparent.
  33952. while (destPos < dest32DataLength) {
  33953. dest32[destPos++] = 0;
  33954. }
  33955. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  33956. }
  33957. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  33958. // RGBA, 32-bits per pixel.
  33959. j = 0;
  33960. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  33961. for (i = 0; i < fullChunks; i++) {
  33962. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  33963. srcPos += elemsInThisChunk;
  33964. ctx.putImageData(chunkImgData, 0, j);
  33965. j += FULL_CHUNK_HEIGHT;
  33966. }
  33967. if (i < totalChunks) {
  33968. elemsInThisChunk = width * partialChunkHeight * 4;
  33969. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  33970. ctx.putImageData(chunkImgData, 0, j);
  33971. }
  33972. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  33973. // RGB, 24-bits per pixel.
  33974. thisChunkHeight = FULL_CHUNK_HEIGHT;
  33975. elemsInThisChunk = width * thisChunkHeight;
  33976. for (i = 0; i < totalChunks; i++) {
  33977. if (i >= fullChunks) {
  33978. thisChunkHeight = partialChunkHeight;
  33979. elemsInThisChunk = width * thisChunkHeight;
  33980. }
  33981. destPos = 0;
  33982. for (j = elemsInThisChunk; j--;) {
  33983. dest[destPos++] = src[srcPos++];
  33984. dest[destPos++] = src[srcPos++];
  33985. dest[destPos++] = src[srcPos++];
  33986. dest[destPos++] = 255;
  33987. }
  33988. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  33989. }
  33990. } else {
  33991. error('bad image kind: ' + imgData.kind);
  33992. }
  33993. }
  33994. function putBinaryImageMask(ctx, imgData) {
  33995. var height = imgData.height, width = imgData.width;
  33996. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  33997. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  33998. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  33999. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  34000. var srcPos = 0;
  34001. var src = imgData.data;
  34002. var dest = chunkImgData.data;
  34003. for (var i = 0; i < totalChunks; i++) {
  34004. var thisChunkHeight =
  34005. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  34006. // Expand the mask so it can be used by the canvas. Any required
  34007. // inversion has already been handled.
  34008. var destPos = 3; // alpha component offset
  34009. for (var j = 0; j < thisChunkHeight; j++) {
  34010. var mask = 0;
  34011. for (var k = 0; k < width; k++) {
  34012. if (!mask) {
  34013. var elem = src[srcPos++];
  34014. mask = 128;
  34015. }
  34016. dest[destPos] = (elem & mask) ? 0 : 255;
  34017. destPos += 4;
  34018. mask >>= 1;
  34019. }
  34020. }
  34021. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34022. }
  34023. }
  34024. function copyCtxState(sourceCtx, destCtx) {
  34025. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  34026. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  34027. 'globalCompositeOperation', 'font'];
  34028. for (var i = 0, ii = properties.length; i < ii; i++) {
  34029. var property = properties[i];
  34030. if (sourceCtx[property] !== undefined) {
  34031. destCtx[property] = sourceCtx[property];
  34032. }
  34033. }
  34034. if (sourceCtx.setLineDash !== undefined) {
  34035. destCtx.setLineDash(sourceCtx.getLineDash());
  34036. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  34037. } else if (sourceCtx.mozDashOffset !== undefined) {
  34038. destCtx.mozDash = sourceCtx.mozDash;
  34039. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  34040. }
  34041. }
  34042. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  34043. var length = bytes.length;
  34044. for (var i = 3; i < length; i += 4) {
  34045. var alpha = bytes[i];
  34046. if (alpha === 0) {
  34047. bytes[i - 3] = r0;
  34048. bytes[i - 2] = g0;
  34049. bytes[i - 1] = b0;
  34050. } else if (alpha < 255) {
  34051. var alpha_ = 255 - alpha;
  34052. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  34053. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  34054. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  34055. }
  34056. }
  34057. }
  34058. function composeSMaskAlpha(maskData, layerData, transferMap) {
  34059. var length = maskData.length;
  34060. var scale = 1 / 255;
  34061. for (var i = 3; i < length; i += 4) {
  34062. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  34063. layerData[i] = (layerData[i] * alpha * scale) | 0;
  34064. }
  34065. }
  34066. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  34067. var length = maskData.length;
  34068. for (var i = 3; i < length; i += 4) {
  34069. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  34070. (maskData[i - 2] * 152) + // * 0.59 ....
  34071. (maskData[i - 1] * 28); // * 0.11 ....
  34072. layerData[i] = transferMap ?
  34073. (layerData[i] * transferMap[y >> 8]) >> 8 :
  34074. (layerData[i] * y) >> 16;
  34075. }
  34076. }
  34077. function genericComposeSMask(maskCtx, layerCtx, width, height,
  34078. subtype, backdrop, transferMap) {
  34079. var hasBackdrop = !!backdrop;
  34080. var r0 = hasBackdrop ? backdrop[0] : 0;
  34081. var g0 = hasBackdrop ? backdrop[1] : 0;
  34082. var b0 = hasBackdrop ? backdrop[2] : 0;
  34083. var composeFn;
  34084. if (subtype === 'Luminosity') {
  34085. composeFn = composeSMaskLuminosity;
  34086. } else {
  34087. composeFn = composeSMaskAlpha;
  34088. }
  34089. // processing image in chunks to save memory
  34090. var PIXELS_TO_PROCESS = 1048576;
  34091. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  34092. for (var row = 0; row < height; row += chunkSize) {
  34093. var chunkHeight = Math.min(chunkSize, height - row);
  34094. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  34095. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  34096. if (hasBackdrop) {
  34097. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  34098. }
  34099. composeFn(maskData.data, layerData.data, transferMap);
  34100. maskCtx.putImageData(layerData, 0, row);
  34101. }
  34102. }
  34103. function composeSMask(ctx, smask, layerCtx) {
  34104. var mask = smask.canvas;
  34105. var maskCtx = smask.context;
  34106. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  34107. smask.offsetX, smask.offsetY);
  34108. var backdrop = smask.backdrop || null;
  34109. if (!smask.transferMap && WebGLUtils.isEnabled) {
  34110. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  34111. {subtype: smask.subtype, backdrop: backdrop});
  34112. ctx.setTransform(1, 0, 0, 1, 0, 0);
  34113. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  34114. return;
  34115. }
  34116. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  34117. smask.subtype, backdrop, smask.transferMap);
  34118. ctx.drawImage(mask, 0, 0);
  34119. }
  34120. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  34121. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  34122. var NORMAL_CLIP = {};
  34123. var EO_CLIP = {};
  34124. CanvasGraphics.prototype = {
  34125. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  34126. transparency) {
  34127. // For pdfs that use blend modes we have to clear the canvas else certain
  34128. // blend modes can look wrong since we'd be blending with a white
  34129. // backdrop. The problem with a transparent backdrop though is we then
  34130. // don't get sub pixel anti aliasing on text, creating temporary
  34131. // transparent canvas when we have blend modes.
  34132. var width = this.ctx.canvas.width;
  34133. var height = this.ctx.canvas.height;
  34134. this.ctx.save();
  34135. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  34136. this.ctx.fillRect(0, 0, width, height);
  34137. this.ctx.restore();
  34138. if (transparency) {
  34139. var transparentCanvas = this.cachedCanvases.getCanvas(
  34140. 'transparent', width, height, true);
  34141. this.compositeCtx = this.ctx;
  34142. this.transparentCanvas = transparentCanvas.canvas;
  34143. this.ctx = transparentCanvas.context;
  34144. this.ctx.save();
  34145. // The transform can be applied before rendering, transferring it to
  34146. // the new canvas.
  34147. this.ctx.transform.apply(this.ctx,
  34148. this.compositeCtx.mozCurrentTransform);
  34149. }
  34150. this.ctx.save();
  34151. if (transform) {
  34152. this.ctx.transform.apply(this.ctx, transform);
  34153. }
  34154. this.ctx.transform.apply(this.ctx, viewport.transform);
  34155. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  34156. if (this.imageLayer) {
  34157. this.imageLayer.beginLayout();
  34158. }
  34159. },
  34160. executeOperatorList: function CanvasGraphics_executeOperatorList(
  34161. operatorList,
  34162. executionStartIdx, continueCallback,
  34163. stepper) {
  34164. var argsArray = operatorList.argsArray;
  34165. var fnArray = operatorList.fnArray;
  34166. var i = executionStartIdx || 0;
  34167. var argsArrayLen = argsArray.length;
  34168. // Sometimes the OperatorList to execute is empty.
  34169. if (argsArrayLen === i) {
  34170. return i;
  34171. }
  34172. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  34173. typeof continueCallback === 'function');
  34174. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  34175. var steps = 0;
  34176. var commonObjs = this.commonObjs;
  34177. var objs = this.objs;
  34178. var fnId;
  34179. while (true) {
  34180. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  34181. stepper.breakIt(i, continueCallback);
  34182. return i;
  34183. }
  34184. fnId = fnArray[i];
  34185. if (fnId !== OPS.dependency) {
  34186. this[fnId].apply(this, argsArray[i]);
  34187. } else {
  34188. var deps = argsArray[i];
  34189. for (var n = 0, nn = deps.length; n < nn; n++) {
  34190. var depObjId = deps[n];
  34191. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  34192. var objsPool = common ? commonObjs : objs;
  34193. // If the promise isn't resolved yet, add the continueCallback
  34194. // to the promise and bail out.
  34195. if (!objsPool.isResolved(depObjId)) {
  34196. objsPool.get(depObjId, continueCallback);
  34197. return i;
  34198. }
  34199. }
  34200. }
  34201. i++;
  34202. // If the entire operatorList was executed, stop as were done.
  34203. if (i === argsArrayLen) {
  34204. return i;
  34205. }
  34206. // If the execution took longer then a certain amount of time and
  34207. // `continueCallback` is specified, interrupt the execution.
  34208. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  34209. if (Date.now() > endTime) {
  34210. continueCallback();
  34211. return i;
  34212. }
  34213. steps = 0;
  34214. }
  34215. // If the operatorList isn't executed completely yet OR the execution
  34216. // time was short enough, do another execution round.
  34217. }
  34218. },
  34219. endDrawing: function CanvasGraphics_endDrawing() {
  34220. // Finishing all opened operations such as SMask group painting.
  34221. if (this.current.activeSMask !== null) {
  34222. this.endSMaskGroup();
  34223. }
  34224. this.ctx.restore();
  34225. if (this.transparentCanvas) {
  34226. this.ctx = this.compositeCtx;
  34227. this.ctx.save();
  34228. this.ctx.setTransform(1, 0, 0, 1, 0, 0); // Avoid apply transform twice
  34229. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  34230. this.ctx.restore();
  34231. this.transparentCanvas = null;
  34232. }
  34233. this.cachedCanvases.clear();
  34234. WebGLUtils.clear();
  34235. if (this.imageLayer) {
  34236. this.imageLayer.endLayout();
  34237. }
  34238. },
  34239. // Graphics state
  34240. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  34241. this.current.lineWidth = width;
  34242. this.ctx.lineWidth = width;
  34243. },
  34244. setLineCap: function CanvasGraphics_setLineCap(style) {
  34245. this.ctx.lineCap = LINE_CAP_STYLES[style];
  34246. },
  34247. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  34248. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  34249. },
  34250. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  34251. this.ctx.miterLimit = limit;
  34252. },
  34253. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  34254. var ctx = this.ctx;
  34255. if (ctx.setLineDash !== undefined) {
  34256. ctx.setLineDash(dashArray);
  34257. ctx.lineDashOffset = dashPhase;
  34258. } else {
  34259. ctx.mozDash = dashArray;
  34260. ctx.mozDashOffset = dashPhase;
  34261. }
  34262. },
  34263. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  34264. // Maybe if we one day fully support color spaces this will be important
  34265. // for now we can ignore.
  34266. // TODO set rendering intent?
  34267. },
  34268. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  34269. // There's no way to control this with canvas, but we can safely ignore.
  34270. // TODO set flatness?
  34271. },
  34272. setGState: function CanvasGraphics_setGState(states) {
  34273. for (var i = 0, ii = states.length; i < ii; i++) {
  34274. var state = states[i];
  34275. var key = state[0];
  34276. var value = state[1];
  34277. switch (key) {
  34278. case 'LW':
  34279. this.setLineWidth(value);
  34280. break;
  34281. case 'LC':
  34282. this.setLineCap(value);
  34283. break;
  34284. case 'LJ':
  34285. this.setLineJoin(value);
  34286. break;
  34287. case 'ML':
  34288. this.setMiterLimit(value);
  34289. break;
  34290. case 'D':
  34291. this.setDash(value[0], value[1]);
  34292. break;
  34293. case 'RI':
  34294. this.setRenderingIntent(value);
  34295. break;
  34296. case 'FL':
  34297. this.setFlatness(value);
  34298. break;
  34299. case 'Font':
  34300. this.setFont(value[0], value[1]);
  34301. break;
  34302. case 'CA':
  34303. this.current.strokeAlpha = state[1];
  34304. break;
  34305. case 'ca':
  34306. this.current.fillAlpha = state[1];
  34307. this.ctx.globalAlpha = state[1];
  34308. break;
  34309. case 'BM':
  34310. if (value && value.name && (value.name !== 'Normal')) {
  34311. var mode = value.name.replace(/([A-Z])/g,
  34312. function(c) {
  34313. return '-' + c.toLowerCase();
  34314. }
  34315. ).substring(1);
  34316. this.ctx.globalCompositeOperation = mode;
  34317. if (this.ctx.globalCompositeOperation !== mode) {
  34318. warn('globalCompositeOperation "' + mode +
  34319. '" is not supported');
  34320. }
  34321. } else {
  34322. this.ctx.globalCompositeOperation = 'source-over';
  34323. }
  34324. break;
  34325. case 'SMask':
  34326. if (this.current.activeSMask) {
  34327. // If SMask is currrenly used, it needs to be suspended or
  34328. // finished. Suspend only makes sense when at least one save()
  34329. // was performed and state needs to be reverted on restore().
  34330. if (this.stateStack.length > 0 &&
  34331. (this.stateStack[this.stateStack.length - 1].activeSMask ===
  34332. this.current.activeSMask)) {
  34333. this.suspendSMaskGroup();
  34334. } else {
  34335. this.endSMaskGroup();
  34336. }
  34337. }
  34338. this.current.activeSMask = value ? this.tempSMask : null;
  34339. if (this.current.activeSMask) {
  34340. this.beginSMaskGroup();
  34341. }
  34342. this.tempSMask = null;
  34343. break;
  34344. }
  34345. }
  34346. },
  34347. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  34348. var activeSMask = this.current.activeSMask;
  34349. var drawnWidth = activeSMask.canvas.width;
  34350. var drawnHeight = activeSMask.canvas.height;
  34351. var cacheId = 'smaskGroupAt' + this.groupLevel;
  34352. var scratchCanvas = this.cachedCanvases.getCanvas(
  34353. cacheId, drawnWidth, drawnHeight, true);
  34354. var currentCtx = this.ctx;
  34355. var currentTransform = currentCtx.mozCurrentTransform;
  34356. this.ctx.save();
  34357. var groupCtx = scratchCanvas.context;
  34358. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  34359. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  34360. groupCtx.transform.apply(groupCtx, currentTransform);
  34361. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  34362. copyCtxState(currentCtx, groupCtx);
  34363. this.ctx = groupCtx;
  34364. this.setGState([
  34365. ['BM', 'Normal'],
  34366. ['ca', 1],
  34367. ['CA', 1]
  34368. ]);
  34369. this.groupStack.push(currentCtx);
  34370. this.groupLevel++;
  34371. },
  34372. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34373. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  34374. // and future ctx state restored.
  34375. var groupCtx = this.ctx;
  34376. this.groupLevel--;
  34377. this.ctx = this.groupStack.pop();
  34378. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34379. this.ctx.restore();
  34380. this.ctx.save(); // save is needed since SMask will be resumed.
  34381. copyCtxState(groupCtx, this.ctx);
  34382. // Saving state for resuming.
  34383. this.current.resumeSMaskCtx = groupCtx;
  34384. // Transform was changed in the SMask canvas, reflecting this change on
  34385. // this.ctx.
  34386. var deltaTransform = Util.transform(
  34387. this.current.activeSMask.startTransformInverse,
  34388. groupCtx.mozCurrentTransform);
  34389. this.ctx.transform.apply(this.ctx, deltaTransform);
  34390. // SMask was composed, the results at the groupCtx can be cleared.
  34391. groupCtx.save();
  34392. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  34393. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  34394. groupCtx.restore();
  34395. },
  34396. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34397. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  34398. // any groupCtx state since restore() command (the only caller) will do
  34399. // that for us. See also beginSMaskGroup.
  34400. var groupCtx = this.current.resumeSMaskCtx;
  34401. var currentCtx = this.ctx;
  34402. this.ctx = groupCtx;
  34403. this.groupStack.push(currentCtx);
  34404. this.groupLevel++;
  34405. },
  34406. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34407. var groupCtx = this.ctx;
  34408. this.groupLevel--;
  34409. this.ctx = this.groupStack.pop();
  34410. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34411. this.ctx.restore();
  34412. copyCtxState(groupCtx, this.ctx);
  34413. // Transform was changed in the SMask canvas, reflecting this change on
  34414. // this.ctx.
  34415. var deltaTransform = Util.transform(
  34416. this.current.activeSMask.startTransformInverse,
  34417. groupCtx.mozCurrentTransform);
  34418. this.ctx.transform.apply(this.ctx, deltaTransform);
  34419. },
  34420. save: function CanvasGraphics_save() {
  34421. this.ctx.save();
  34422. var old = this.current;
  34423. this.stateStack.push(old);
  34424. this.current = old.clone();
  34425. this.current.resumeSMaskCtx = null;
  34426. },
  34427. restore: function CanvasGraphics_restore() {
  34428. // SMask was suspended, we just need to resume it.
  34429. if (this.current.resumeSMaskCtx) {
  34430. this.resumeSMaskGroup();
  34431. }
  34432. // SMask has to be finished once there is no states that are using the
  34433. // same SMask.
  34434. if (this.current.activeSMask !== null && (this.stateStack.length === 0 ||
  34435. this.stateStack[this.stateStack.length - 1].activeSMask !==
  34436. this.current.activeSMask)) {
  34437. this.endSMaskGroup();
  34438. }
  34439. if (this.stateStack.length !== 0) {
  34440. this.current = this.stateStack.pop();
  34441. this.ctx.restore();
  34442. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  34443. this.pendingClip = null;
  34444. this.cachedGetSinglePixelWidth = null;
  34445. }
  34446. },
  34447. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  34448. this.ctx.transform(a, b, c, d, e, f);
  34449. this.cachedGetSinglePixelWidth = null;
  34450. },
  34451. // Path
  34452. constructPath: function CanvasGraphics_constructPath(ops, args) {
  34453. var ctx = this.ctx;
  34454. var current = this.current;
  34455. var x = current.x, y = current.y;
  34456. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  34457. switch (ops[i] | 0) {
  34458. case OPS.rectangle:
  34459. x = args[j++];
  34460. y = args[j++];
  34461. var width = args[j++];
  34462. var height = args[j++];
  34463. if (width === 0) {
  34464. width = this.getSinglePixelWidth();
  34465. }
  34466. if (height === 0) {
  34467. height = this.getSinglePixelWidth();
  34468. }
  34469. var xw = x + width;
  34470. var yh = y + height;
  34471. this.ctx.moveTo(x, y);
  34472. this.ctx.lineTo(xw, y);
  34473. this.ctx.lineTo(xw, yh);
  34474. this.ctx.lineTo(x, yh);
  34475. this.ctx.lineTo(x, y);
  34476. this.ctx.closePath();
  34477. break;
  34478. case OPS.moveTo:
  34479. x = args[j++];
  34480. y = args[j++];
  34481. ctx.moveTo(x, y);
  34482. break;
  34483. case OPS.lineTo:
  34484. x = args[j++];
  34485. y = args[j++];
  34486. ctx.lineTo(x, y);
  34487. break;
  34488. case OPS.curveTo:
  34489. x = args[j + 4];
  34490. y = args[j + 5];
  34491. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  34492. x, y);
  34493. j += 6;
  34494. break;
  34495. case OPS.curveTo2:
  34496. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  34497. args[j + 2], args[j + 3]);
  34498. x = args[j + 2];
  34499. y = args[j + 3];
  34500. j += 4;
  34501. break;
  34502. case OPS.curveTo3:
  34503. x = args[j + 2];
  34504. y = args[j + 3];
  34505. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  34506. j += 4;
  34507. break;
  34508. case OPS.closePath:
  34509. ctx.closePath();
  34510. break;
  34511. }
  34512. }
  34513. current.setCurrentPoint(x, y);
  34514. },
  34515. closePath: function CanvasGraphics_closePath() {
  34516. this.ctx.closePath();
  34517. },
  34518. stroke: function CanvasGraphics_stroke(consumePath) {
  34519. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34520. var ctx = this.ctx;
  34521. var strokeColor = this.current.strokeColor;
  34522. // Prevent drawing too thin lines by enforcing a minimum line width.
  34523. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  34524. this.current.lineWidth);
  34525. // For stroke we want to temporarily change the global alpha to the
  34526. // stroking alpha.
  34527. ctx.globalAlpha = this.current.strokeAlpha;
  34528. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  34529. strokeColor.type === 'Pattern') {
  34530. // for patterns, we transform to pattern space, calculate
  34531. // the pattern, call stroke, and restore to user space
  34532. ctx.save();
  34533. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  34534. ctx.stroke();
  34535. ctx.restore();
  34536. } else {
  34537. ctx.stroke();
  34538. }
  34539. if (consumePath) {
  34540. this.consumePath();
  34541. }
  34542. // Restore the global alpha to the fill alpha
  34543. ctx.globalAlpha = this.current.fillAlpha;
  34544. },
  34545. closeStroke: function CanvasGraphics_closeStroke() {
  34546. this.closePath();
  34547. this.stroke();
  34548. },
  34549. fill: function CanvasGraphics_fill(consumePath) {
  34550. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34551. var ctx = this.ctx;
  34552. var fillColor = this.current.fillColor;
  34553. var isPatternFill = this.current.patternFill;
  34554. var needRestore = false;
  34555. if (isPatternFill) {
  34556. ctx.save();
  34557. if (this.baseTransform) {
  34558. ctx.setTransform.apply(ctx, this.baseTransform);
  34559. }
  34560. ctx.fillStyle = fillColor.getPattern(ctx, this);
  34561. needRestore = true;
  34562. }
  34563. if (this.pendingEOFill) {
  34564. if (ctx.mozFillRule !== undefined) {
  34565. ctx.mozFillRule = 'evenodd';
  34566. ctx.fill();
  34567. ctx.mozFillRule = 'nonzero';
  34568. } else {
  34569. ctx.fill('evenodd');
  34570. }
  34571. this.pendingEOFill = false;
  34572. } else {
  34573. ctx.fill();
  34574. }
  34575. if (needRestore) {
  34576. ctx.restore();
  34577. }
  34578. if (consumePath) {
  34579. this.consumePath();
  34580. }
  34581. },
  34582. eoFill: function CanvasGraphics_eoFill() {
  34583. this.pendingEOFill = true;
  34584. this.fill();
  34585. },
  34586. fillStroke: function CanvasGraphics_fillStroke() {
  34587. this.fill(false);
  34588. this.stroke(false);
  34589. this.consumePath();
  34590. },
  34591. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  34592. this.pendingEOFill = true;
  34593. this.fillStroke();
  34594. },
  34595. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  34596. this.closePath();
  34597. this.fillStroke();
  34598. },
  34599. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  34600. this.pendingEOFill = true;
  34601. this.closePath();
  34602. this.fillStroke();
  34603. },
  34604. endPath: function CanvasGraphics_endPath() {
  34605. this.consumePath();
  34606. },
  34607. // Clipping
  34608. clip: function CanvasGraphics_clip() {
  34609. this.pendingClip = NORMAL_CLIP;
  34610. },
  34611. eoClip: function CanvasGraphics_eoClip() {
  34612. this.pendingClip = EO_CLIP;
  34613. },
  34614. // Text
  34615. beginText: function CanvasGraphics_beginText() {
  34616. this.current.textMatrix = IDENTITY_MATRIX;
  34617. this.current.textMatrixScale = 1;
  34618. this.current.x = this.current.lineX = 0;
  34619. this.current.y = this.current.lineY = 0;
  34620. },
  34621. endText: function CanvasGraphics_endText() {
  34622. var paths = this.pendingTextPaths;
  34623. var ctx = this.ctx;
  34624. if (paths === undefined) {
  34625. ctx.beginPath();
  34626. return;
  34627. }
  34628. ctx.save();
  34629. ctx.beginPath();
  34630. for (var i = 0; i < paths.length; i++) {
  34631. var path = paths[i];
  34632. ctx.setTransform.apply(ctx, path.transform);
  34633. ctx.translate(path.x, path.y);
  34634. path.addToPath(ctx, path.fontSize);
  34635. }
  34636. ctx.restore();
  34637. ctx.clip();
  34638. ctx.beginPath();
  34639. delete this.pendingTextPaths;
  34640. },
  34641. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  34642. this.current.charSpacing = spacing;
  34643. },
  34644. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  34645. this.current.wordSpacing = spacing;
  34646. },
  34647. setHScale: function CanvasGraphics_setHScale(scale) {
  34648. this.current.textHScale = scale / 100;
  34649. },
  34650. setLeading: function CanvasGraphics_setLeading(leading) {
  34651. this.current.leading = -leading;
  34652. },
  34653. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  34654. var fontObj = this.commonObjs.get(fontRefName);
  34655. var current = this.current;
  34656. if (!fontObj) {
  34657. error('Can\'t find font for ' + fontRefName);
  34658. }
  34659. current.fontMatrix = (fontObj.fontMatrix ?
  34660. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  34661. // A valid matrix needs all main diagonal elements to be non-zero
  34662. // This also ensures we bypass FF bugzilla bug #719844.
  34663. if (current.fontMatrix[0] === 0 ||
  34664. current.fontMatrix[3] === 0) {
  34665. warn('Invalid font matrix for font ' + fontRefName);
  34666. }
  34667. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  34668. // and in some docs this can be negative (inverted x-y axes).
  34669. if (size < 0) {
  34670. size = -size;
  34671. current.fontDirection = -1;
  34672. } else {
  34673. current.fontDirection = 1;
  34674. }
  34675. this.current.font = fontObj;
  34676. this.current.fontSize = size;
  34677. if (fontObj.isType3Font) {
  34678. return; // we don't need ctx.font for Type3 fonts
  34679. }
  34680. var name = fontObj.loadedName || 'sans-serif';
  34681. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  34682. (fontObj.bold ? 'bold' : 'normal');
  34683. var italic = fontObj.italic ? 'italic' : 'normal';
  34684. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  34685. // Some font backends cannot handle fonts below certain size.
  34686. // Keeping the font at minimal size and using the fontSizeScale to change
  34687. // the current transformation matrix before the fillText/strokeText.
  34688. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  34689. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  34690. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  34691. this.current.fontSizeScale = size / browserFontSize;
  34692. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  34693. this.ctx.font = rule;
  34694. },
  34695. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  34696. this.current.textRenderingMode = mode;
  34697. },
  34698. setTextRise: function CanvasGraphics_setTextRise(rise) {
  34699. this.current.textRise = rise;
  34700. },
  34701. moveText: function CanvasGraphics_moveText(x, y) {
  34702. this.current.x = this.current.lineX += x;
  34703. this.current.y = this.current.lineY += y;
  34704. },
  34705. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  34706. this.setLeading(-y);
  34707. this.moveText(x, y);
  34708. },
  34709. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  34710. this.current.textMatrix = [a, b, c, d, e, f];
  34711. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  34712. this.current.x = this.current.lineX = 0;
  34713. this.current.y = this.current.lineY = 0;
  34714. },
  34715. nextLine: function CanvasGraphics_nextLine() {
  34716. this.moveText(0, this.current.leading);
  34717. },
  34718. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  34719. var ctx = this.ctx;
  34720. var current = this.current;
  34721. var font = current.font;
  34722. var textRenderingMode = current.textRenderingMode;
  34723. var fontSize = current.fontSize / current.fontSizeScale;
  34724. var fillStrokeMode = textRenderingMode &
  34725. TextRenderingMode.FILL_STROKE_MASK;
  34726. var isAddToPathSet = !!(textRenderingMode &
  34727. TextRenderingMode.ADD_TO_PATH_FLAG);
  34728. var addToPath;
  34729. if (font.disableFontFace || isAddToPathSet) {
  34730. addToPath = font.getPathGenerator(this.commonObjs, character);
  34731. }
  34732. if (font.disableFontFace) {
  34733. ctx.save();
  34734. ctx.translate(x, y);
  34735. ctx.beginPath();
  34736. addToPath(ctx, fontSize);
  34737. if (fillStrokeMode === TextRenderingMode.FILL ||
  34738. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34739. ctx.fill();
  34740. }
  34741. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34742. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34743. ctx.stroke();
  34744. }
  34745. ctx.restore();
  34746. } else {
  34747. if (fillStrokeMode === TextRenderingMode.FILL ||
  34748. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34749. ctx.fillText(character, x, y);
  34750. }
  34751. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34752. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34753. ctx.strokeText(character, x, y);
  34754. }
  34755. }
  34756. if (isAddToPathSet) {
  34757. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  34758. paths.push({
  34759. transform: ctx.mozCurrentTransform,
  34760. x: x,
  34761. y: y,
  34762. fontSize: fontSize,
  34763. addToPath: addToPath
  34764. });
  34765. }
  34766. },
  34767. get isFontSubpixelAAEnabled() {
  34768. // Checks if anti-aliasing is enabled when scaled text is painted.
  34769. // On Windows GDI scaled fonts looks bad.
  34770. var ctx = document.createElement('canvas').getContext('2d');
  34771. ctx.scale(1.5, 1);
  34772. ctx.fillText('I', 0, 10);
  34773. var data = ctx.getImageData(0, 0, 10, 10).data;
  34774. var enabled = false;
  34775. for (var i = 3; i < data.length; i += 4) {
  34776. if (data[i] > 0 && data[i] < 255) {
  34777. enabled = true;
  34778. break;
  34779. }
  34780. }
  34781. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  34782. },
  34783. showText: function CanvasGraphics_showText(glyphs) {
  34784. var current = this.current;
  34785. var font = current.font;
  34786. if (font.isType3Font) {
  34787. return this.showType3Text(glyphs);
  34788. }
  34789. var fontSize = current.fontSize;
  34790. if (fontSize === 0) {
  34791. return;
  34792. }
  34793. var ctx = this.ctx;
  34794. var fontSizeScale = current.fontSizeScale;
  34795. var charSpacing = current.charSpacing;
  34796. var wordSpacing = current.wordSpacing;
  34797. var fontDirection = current.fontDirection;
  34798. var textHScale = current.textHScale * fontDirection;
  34799. var glyphsLength = glyphs.length;
  34800. var vertical = font.vertical;
  34801. var spacingDir = vertical ? 1 : -1;
  34802. var defaultVMetrics = font.defaultVMetrics;
  34803. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  34804. var simpleFillText =
  34805. current.textRenderingMode === TextRenderingMode.FILL &&
  34806. !font.disableFontFace;
  34807. ctx.save();
  34808. ctx.transform.apply(ctx, current.textMatrix);
  34809. ctx.translate(current.x, current.y + current.textRise);
  34810. if (current.patternFill) {
  34811. // TODO: Some shading patterns are not applied correctly to text,
  34812. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  34813. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  34814. }
  34815. if (fontDirection > 0) {
  34816. ctx.scale(textHScale, -1);
  34817. } else {
  34818. ctx.scale(textHScale, 1);
  34819. }
  34820. var lineWidth = current.lineWidth;
  34821. var scale = current.textMatrixScale;
  34822. if (scale === 0 || lineWidth === 0) {
  34823. var fillStrokeMode = current.textRenderingMode &
  34824. TextRenderingMode.FILL_STROKE_MASK;
  34825. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34826. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34827. this.cachedGetSinglePixelWidth = null;
  34828. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  34829. }
  34830. } else {
  34831. lineWidth /= scale;
  34832. }
  34833. if (fontSizeScale !== 1.0) {
  34834. ctx.scale(fontSizeScale, fontSizeScale);
  34835. lineWidth /= fontSizeScale;
  34836. }
  34837. ctx.lineWidth = lineWidth;
  34838. var x = 0, i;
  34839. for (i = 0; i < glyphsLength; ++i) {
  34840. var glyph = glyphs[i];
  34841. if (isNum(glyph)) {
  34842. x += spacingDir * glyph * fontSize / 1000;
  34843. continue;
  34844. }
  34845. var restoreNeeded = false;
  34846. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  34847. var character = glyph.fontChar;
  34848. var accent = glyph.accent;
  34849. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  34850. var width = glyph.width;
  34851. if (vertical) {
  34852. var vmetric, vx, vy;
  34853. vmetric = glyph.vmetric || defaultVMetrics;
  34854. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  34855. vx = -vx * widthAdvanceScale;
  34856. vy = vmetric[2] * widthAdvanceScale;
  34857. width = vmetric ? -vmetric[0] : width;
  34858. scaledX = vx / fontSizeScale;
  34859. scaledY = (x + vy) / fontSizeScale;
  34860. } else {
  34861. scaledX = x / fontSizeScale;
  34862. scaledY = 0;
  34863. }
  34864. if (font.remeasure && width > 0) {
  34865. // Some standard fonts may not have the exact width: rescale per
  34866. // character if measured width is greater than expected glyph width
  34867. // and subpixel-aa is enabled, otherwise just center the glyph.
  34868. var measuredWidth = ctx.measureText(character).width * 1000 /
  34869. fontSize * fontSizeScale;
  34870. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  34871. var characterScaleX = width / measuredWidth;
  34872. restoreNeeded = true;
  34873. ctx.save();
  34874. ctx.scale(characterScaleX, 1);
  34875. scaledX /= characterScaleX;
  34876. } else if (width !== measuredWidth) {
  34877. scaledX += (width - measuredWidth) / 2000 *
  34878. fontSize / fontSizeScale;
  34879. }
  34880. }
  34881. // Only attempt to draw the glyph if it is actually in the embedded font
  34882. // file or if there isn't a font file so the fallback font is shown.
  34883. if (glyph.isInFont || font.missingFile) {
  34884. if (simpleFillText && !accent) {
  34885. // common case
  34886. ctx.fillText(character, scaledX, scaledY);
  34887. } else {
  34888. this.paintChar(character, scaledX, scaledY);
  34889. if (accent) {
  34890. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  34891. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  34892. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  34893. }
  34894. }
  34895. }
  34896. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  34897. x += charWidth;
  34898. if (restoreNeeded) {
  34899. ctx.restore();
  34900. }
  34901. }
  34902. if (vertical) {
  34903. current.y -= x * textHScale;
  34904. } else {
  34905. current.x += x * textHScale;
  34906. }
  34907. ctx.restore();
  34908. },
  34909. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  34910. // Type3 fonts - each glyph is a "mini-PDF"
  34911. var ctx = this.ctx;
  34912. var current = this.current;
  34913. var font = current.font;
  34914. var fontSize = current.fontSize;
  34915. var fontDirection = current.fontDirection;
  34916. var spacingDir = font.vertical ? 1 : -1;
  34917. var charSpacing = current.charSpacing;
  34918. var wordSpacing = current.wordSpacing;
  34919. var textHScale = current.textHScale * fontDirection;
  34920. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  34921. var glyphsLength = glyphs.length;
  34922. var isTextInvisible =
  34923. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  34924. var i, glyph, width, spacingLength;
  34925. if (isTextInvisible || fontSize === 0) {
  34926. return;
  34927. }
  34928. this.cachedGetSinglePixelWidth = null;
  34929. ctx.save();
  34930. ctx.transform.apply(ctx, current.textMatrix);
  34931. ctx.translate(current.x, current.y);
  34932. ctx.scale(textHScale, fontDirection);
  34933. for (i = 0; i < glyphsLength; ++i) {
  34934. glyph = glyphs[i];
  34935. if (isNum(glyph)) {
  34936. spacingLength = spacingDir * glyph * fontSize / 1000;
  34937. this.ctx.translate(spacingLength, 0);
  34938. current.x += spacingLength * textHScale;
  34939. continue;
  34940. }
  34941. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  34942. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  34943. if (!operatorList) {
  34944. warn('Type3 character \"' + glyph.operatorListId +
  34945. '\" is not available');
  34946. continue;
  34947. }
  34948. this.processingType3 = glyph;
  34949. this.save();
  34950. ctx.scale(fontSize, fontSize);
  34951. ctx.transform.apply(ctx, fontMatrix);
  34952. this.executeOperatorList(operatorList);
  34953. this.restore();
  34954. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  34955. width = transformed[0] * fontSize + spacing;
  34956. ctx.translate(width, 0);
  34957. current.x += width * textHScale;
  34958. }
  34959. ctx.restore();
  34960. this.processingType3 = null;
  34961. },
  34962. // Type3 fonts
  34963. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  34964. // We can safely ignore this since the width should be the same
  34965. // as the width in the Widths array.
  34966. },
  34967. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  34968. yWidth,
  34969. llx,
  34970. lly,
  34971. urx,
  34972. ury) {
  34973. // TODO According to the spec we're also suppose to ignore any operators
  34974. // that set color or include images while processing this type3 font.
  34975. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  34976. this.clip();
  34977. this.endPath();
  34978. },
  34979. // Color
  34980. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  34981. var pattern;
  34982. if (IR[0] === 'TilingPattern') {
  34983. var color = IR[1];
  34984. var baseTransform = this.baseTransform ||
  34985. this.ctx.mozCurrentTransform.slice();
  34986. var self = this;
  34987. var canvasGraphicsFactory = {
  34988. createCanvasGraphics: function (ctx) {
  34989. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  34990. }
  34991. };
  34992. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  34993. baseTransform);
  34994. } else {
  34995. pattern = getShadingPatternFromIR(IR);
  34996. }
  34997. return pattern;
  34998. },
  34999. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  35000. this.current.strokeColor = this.getColorN_Pattern(arguments);
  35001. },
  35002. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  35003. this.current.fillColor = this.getColorN_Pattern(arguments);
  35004. this.current.patternFill = true;
  35005. },
  35006. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  35007. var color = Util.makeCssRgb(r, g, b);
  35008. this.ctx.strokeStyle = color;
  35009. this.current.strokeColor = color;
  35010. },
  35011. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  35012. var color = Util.makeCssRgb(r, g, b);
  35013. this.ctx.fillStyle = color;
  35014. this.current.fillColor = color;
  35015. this.current.patternFill = false;
  35016. },
  35017. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  35018. var ctx = this.ctx;
  35019. this.save();
  35020. var pattern = getShadingPatternFromIR(patternIR);
  35021. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  35022. var inv = ctx.mozCurrentTransformInverse;
  35023. if (inv) {
  35024. var canvas = ctx.canvas;
  35025. var width = canvas.width;
  35026. var height = canvas.height;
  35027. var bl = Util.applyTransform([0, 0], inv);
  35028. var br = Util.applyTransform([0, height], inv);
  35029. var ul = Util.applyTransform([width, 0], inv);
  35030. var ur = Util.applyTransform([width, height], inv);
  35031. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  35032. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  35033. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  35034. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  35035. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  35036. } else {
  35037. // HACK to draw the gradient onto an infinite rectangle.
  35038. // PDF gradients are drawn across the entire image while
  35039. // Canvas only allows gradients to be drawn in a rectangle
  35040. // The following bug should allow us to remove this.
  35041. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  35042. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  35043. }
  35044. this.restore();
  35045. },
  35046. // Images
  35047. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  35048. error('Should not call beginInlineImage');
  35049. },
  35050. beginImageData: function CanvasGraphics_beginImageData() {
  35051. error('Should not call beginImageData');
  35052. },
  35053. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  35054. bbox) {
  35055. this.save();
  35056. this.baseTransformStack.push(this.baseTransform);
  35057. if (isArray(matrix) && 6 === matrix.length) {
  35058. this.transform.apply(this, matrix);
  35059. }
  35060. this.baseTransform = this.ctx.mozCurrentTransform;
  35061. if (isArray(bbox) && 4 === bbox.length) {
  35062. var width = bbox[2] - bbox[0];
  35063. var height = bbox[3] - bbox[1];
  35064. this.ctx.rect(bbox[0], bbox[1], width, height);
  35065. this.clip();
  35066. this.endPath();
  35067. }
  35068. },
  35069. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  35070. this.restore();
  35071. this.baseTransform = this.baseTransformStack.pop();
  35072. },
  35073. beginGroup: function CanvasGraphics_beginGroup(group) {
  35074. this.save();
  35075. var currentCtx = this.ctx;
  35076. // TODO non-isolated groups - according to Rik at adobe non-isolated
  35077. // group results aren't usually that different and they even have tools
  35078. // that ignore this setting. Notes from Rik on implementing:
  35079. // - When you encounter an transparency group, create a new canvas with
  35080. // the dimensions of the bbox
  35081. // - copy the content from the previous canvas to the new canvas
  35082. // - draw as usual
  35083. // - remove the backdrop alpha:
  35084. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  35085. // value of your transparency group and 'alphaBackdrop' the alpha of the
  35086. // backdrop
  35087. // - remove background color:
  35088. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  35089. if (!group.isolated) {
  35090. info('TODO: Support non-isolated groups.');
  35091. }
  35092. // TODO knockout - supposedly possible with the clever use of compositing
  35093. // modes.
  35094. if (group.knockout) {
  35095. warn('Knockout groups not supported.');
  35096. }
  35097. var currentTransform = currentCtx.mozCurrentTransform;
  35098. if (group.matrix) {
  35099. currentCtx.transform.apply(currentCtx, group.matrix);
  35100. }
  35101. assert(group.bbox, 'Bounding box is required.');
  35102. // Based on the current transform figure out how big the bounding box
  35103. // will actually be.
  35104. var bounds = Util.getAxialAlignedBoundingBox(
  35105. group.bbox,
  35106. currentCtx.mozCurrentTransform);
  35107. // Clip the bounding box to the current canvas.
  35108. var canvasBounds = [0,
  35109. 0,
  35110. currentCtx.canvas.width,
  35111. currentCtx.canvas.height];
  35112. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  35113. // Use ceil in case we're between sizes so we don't create canvas that is
  35114. // too small and make the canvas at least 1x1 pixels.
  35115. var offsetX = Math.floor(bounds[0]);
  35116. var offsetY = Math.floor(bounds[1]);
  35117. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  35118. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  35119. var scaleX = 1, scaleY = 1;
  35120. if (drawnWidth > MAX_GROUP_SIZE) {
  35121. scaleX = drawnWidth / MAX_GROUP_SIZE;
  35122. drawnWidth = MAX_GROUP_SIZE;
  35123. }
  35124. if (drawnHeight > MAX_GROUP_SIZE) {
  35125. scaleY = drawnHeight / MAX_GROUP_SIZE;
  35126. drawnHeight = MAX_GROUP_SIZE;
  35127. }
  35128. var cacheId = 'groupAt' + this.groupLevel;
  35129. if (group.smask) {
  35130. // Using two cache entries is case if masks are used one after another.
  35131. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  35132. }
  35133. var scratchCanvas = this.cachedCanvases.getCanvas(
  35134. cacheId, drawnWidth, drawnHeight, true);
  35135. var groupCtx = scratchCanvas.context;
  35136. // Since we created a new canvas that is just the size of the bounding box
  35137. // we have to translate the group ctx.
  35138. groupCtx.scale(1 / scaleX, 1 / scaleY);
  35139. groupCtx.translate(-offsetX, -offsetY);
  35140. groupCtx.transform.apply(groupCtx, currentTransform);
  35141. if (group.smask) {
  35142. // Saving state and cached mask to be used in setGState.
  35143. this.smaskStack.push({
  35144. canvas: scratchCanvas.canvas,
  35145. context: groupCtx,
  35146. offsetX: offsetX,
  35147. offsetY: offsetY,
  35148. scaleX: scaleX,
  35149. scaleY: scaleY,
  35150. subtype: group.smask.subtype,
  35151. backdrop: group.smask.backdrop,
  35152. transferMap: group.smask.transferMap || null,
  35153. startTransformInverse: null, // used during suspend operation
  35154. });
  35155. } else {
  35156. // Setup the current ctx so when the group is popped we draw it at the
  35157. // right location.
  35158. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  35159. currentCtx.translate(offsetX, offsetY);
  35160. currentCtx.scale(scaleX, scaleY);
  35161. }
  35162. // The transparency group inherits all off the current graphics state
  35163. // except the blend mode, soft mask, and alpha constants.
  35164. copyCtxState(currentCtx, groupCtx);
  35165. this.ctx = groupCtx;
  35166. this.setGState([
  35167. ['BM', 'Normal'],
  35168. ['ca', 1],
  35169. ['CA', 1]
  35170. ]);
  35171. this.groupStack.push(currentCtx);
  35172. this.groupLevel++;
  35173. // Reseting mask state, masks will be applied on restore of the group.
  35174. this.current.activeSMask = null;
  35175. },
  35176. endGroup: function CanvasGraphics_endGroup(group) {
  35177. this.groupLevel--;
  35178. var groupCtx = this.ctx;
  35179. this.ctx = this.groupStack.pop();
  35180. // Turn off image smoothing to avoid sub pixel interpolation which can
  35181. // look kind of blurry for some pdfs.
  35182. if (this.ctx.imageSmoothingEnabled !== undefined) {
  35183. this.ctx.imageSmoothingEnabled = false;
  35184. } else {
  35185. this.ctx.mozImageSmoothingEnabled = false;
  35186. }
  35187. if (group.smask) {
  35188. this.tempSMask = this.smaskStack.pop();
  35189. } else {
  35190. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  35191. }
  35192. this.restore();
  35193. },
  35194. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  35195. this.save();
  35196. this.current = new CanvasExtraState();
  35197. if (this.baseTransform) {
  35198. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  35199. }
  35200. },
  35201. endAnnotations: function CanvasGraphics_endAnnotations() {
  35202. this.restore();
  35203. },
  35204. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  35205. matrix) {
  35206. this.save();
  35207. if (isArray(rect) && 4 === rect.length) {
  35208. var width = rect[2] - rect[0];
  35209. var height = rect[3] - rect[1];
  35210. this.ctx.rect(rect[0], rect[1], width, height);
  35211. this.clip();
  35212. this.endPath();
  35213. }
  35214. this.transform.apply(this, transform);
  35215. this.transform.apply(this, matrix);
  35216. },
  35217. endAnnotation: function CanvasGraphics_endAnnotation() {
  35218. this.restore();
  35219. },
  35220. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  35221. var domImage = this.objs.get(objId);
  35222. if (!domImage) {
  35223. warn('Dependent image isn\'t ready yet');
  35224. return;
  35225. }
  35226. this.save();
  35227. var ctx = this.ctx;
  35228. // scale the image to the unit square
  35229. ctx.scale(1 / w, -1 / h);
  35230. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  35231. 0, -h, w, h);
  35232. if (this.imageLayer) {
  35233. var currentTransform = ctx.mozCurrentTransformInverse;
  35234. var position = this.getCanvasPosition(0, 0);
  35235. this.imageLayer.appendImage({
  35236. objId: objId,
  35237. left: position[0],
  35238. top: position[1],
  35239. width: w / currentTransform[0],
  35240. height: h / currentTransform[3]
  35241. });
  35242. }
  35243. this.restore();
  35244. },
  35245. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  35246. var ctx = this.ctx;
  35247. var width = img.width, height = img.height;
  35248. var fillColor = this.current.fillColor;
  35249. var isPatternFill = this.current.patternFill;
  35250. var glyph = this.processingType3;
  35251. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  35252. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  35253. glyph.compiled =
  35254. compileType3Glyph({data: img.data, width: width, height: height});
  35255. } else {
  35256. glyph.compiled = null;
  35257. }
  35258. }
  35259. if (glyph && glyph.compiled) {
  35260. glyph.compiled(ctx);
  35261. return;
  35262. }
  35263. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35264. width, height);
  35265. var maskCtx = maskCanvas.context;
  35266. maskCtx.save();
  35267. putBinaryImageMask(maskCtx, img);
  35268. maskCtx.globalCompositeOperation = 'source-in';
  35269. maskCtx.fillStyle = isPatternFill ?
  35270. fillColor.getPattern(maskCtx, this) : fillColor;
  35271. maskCtx.fillRect(0, 0, width, height);
  35272. maskCtx.restore();
  35273. this.paintInlineImageXObject(maskCanvas.canvas);
  35274. },
  35275. paintImageMaskXObjectRepeat:
  35276. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  35277. scaleY, positions) {
  35278. var width = imgData.width;
  35279. var height = imgData.height;
  35280. var fillColor = this.current.fillColor;
  35281. var isPatternFill = this.current.patternFill;
  35282. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35283. width, height);
  35284. var maskCtx = maskCanvas.context;
  35285. maskCtx.save();
  35286. putBinaryImageMask(maskCtx, imgData);
  35287. maskCtx.globalCompositeOperation = 'source-in';
  35288. maskCtx.fillStyle = isPatternFill ?
  35289. fillColor.getPattern(maskCtx, this) : fillColor;
  35290. maskCtx.fillRect(0, 0, width, height);
  35291. maskCtx.restore();
  35292. var ctx = this.ctx;
  35293. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35294. ctx.save();
  35295. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  35296. ctx.scale(1, -1);
  35297. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35298. 0, -1, 1, 1);
  35299. ctx.restore();
  35300. }
  35301. },
  35302. paintImageMaskXObjectGroup:
  35303. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  35304. var ctx = this.ctx;
  35305. var fillColor = this.current.fillColor;
  35306. var isPatternFill = this.current.patternFill;
  35307. for (var i = 0, ii = images.length; i < ii; i++) {
  35308. var image = images[i];
  35309. var width = image.width, height = image.height;
  35310. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35311. width, height);
  35312. var maskCtx = maskCanvas.context;
  35313. maskCtx.save();
  35314. putBinaryImageMask(maskCtx, image);
  35315. maskCtx.globalCompositeOperation = 'source-in';
  35316. maskCtx.fillStyle = isPatternFill ?
  35317. fillColor.getPattern(maskCtx, this) : fillColor;
  35318. maskCtx.fillRect(0, 0, width, height);
  35319. maskCtx.restore();
  35320. ctx.save();
  35321. ctx.transform.apply(ctx, image.transform);
  35322. ctx.scale(1, -1);
  35323. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35324. 0, -1, 1, 1);
  35325. ctx.restore();
  35326. }
  35327. },
  35328. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  35329. var imgData = this.objs.get(objId);
  35330. if (!imgData) {
  35331. warn('Dependent image isn\'t ready yet');
  35332. return;
  35333. }
  35334. this.paintInlineImageXObject(imgData);
  35335. },
  35336. paintImageXObjectRepeat:
  35337. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  35338. positions) {
  35339. var imgData = this.objs.get(objId);
  35340. if (!imgData) {
  35341. warn('Dependent image isn\'t ready yet');
  35342. return;
  35343. }
  35344. var width = imgData.width;
  35345. var height = imgData.height;
  35346. var map = [];
  35347. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35348. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  35349. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  35350. }
  35351. this.paintInlineImageXObjectGroup(imgData, map);
  35352. },
  35353. paintInlineImageXObject:
  35354. function CanvasGraphics_paintInlineImageXObject(imgData) {
  35355. var width = imgData.width;
  35356. var height = imgData.height;
  35357. var ctx = this.ctx;
  35358. this.save();
  35359. // scale the image to the unit square
  35360. ctx.scale(1 / width, -1 / height);
  35361. var currentTransform = ctx.mozCurrentTransformInverse;
  35362. var a = currentTransform[0], b = currentTransform[1];
  35363. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  35364. var c = currentTransform[2], d = currentTransform[3];
  35365. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  35366. var imgToPaint, tmpCanvas;
  35367. // instanceof HTMLElement does not work in jsdom node.js module
  35368. if (imgData instanceof HTMLElement || !imgData.data) {
  35369. imgToPaint = imgData;
  35370. } else {
  35371. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  35372. width, height);
  35373. var tmpCtx = tmpCanvas.context;
  35374. putBinaryImageData(tmpCtx, imgData);
  35375. imgToPaint = tmpCanvas.canvas;
  35376. }
  35377. var paintWidth = width, paintHeight = height;
  35378. var tmpCanvasId = 'prescale1';
  35379. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  35380. // pixels during drawImage operation, painting on the temporary canvas(es)
  35381. // that are twice smaller in size
  35382. while ((widthScale > 2 && paintWidth > 1) ||
  35383. (heightScale > 2 && paintHeight > 1)) {
  35384. var newWidth = paintWidth, newHeight = paintHeight;
  35385. if (widthScale > 2 && paintWidth > 1) {
  35386. newWidth = Math.ceil(paintWidth / 2);
  35387. widthScale /= paintWidth / newWidth;
  35388. }
  35389. if (heightScale > 2 && paintHeight > 1) {
  35390. newHeight = Math.ceil(paintHeight / 2);
  35391. heightScale /= paintHeight / newHeight;
  35392. }
  35393. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  35394. newWidth, newHeight);
  35395. tmpCtx = tmpCanvas.context;
  35396. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  35397. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35398. 0, 0, newWidth, newHeight);
  35399. imgToPaint = tmpCanvas.canvas;
  35400. paintWidth = newWidth;
  35401. paintHeight = newHeight;
  35402. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  35403. }
  35404. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35405. 0, -height, width, height);
  35406. if (this.imageLayer) {
  35407. var position = this.getCanvasPosition(0, -height);
  35408. this.imageLayer.appendImage({
  35409. imgData: imgData,
  35410. left: position[0],
  35411. top: position[1],
  35412. width: width / currentTransform[0],
  35413. height: height / currentTransform[3]
  35414. });
  35415. }
  35416. this.restore();
  35417. },
  35418. paintInlineImageXObjectGroup:
  35419. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  35420. var ctx = this.ctx;
  35421. var w = imgData.width;
  35422. var h = imgData.height;
  35423. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  35424. var tmpCtx = tmpCanvas.context;
  35425. putBinaryImageData(tmpCtx, imgData);
  35426. for (var i = 0, ii = map.length; i < ii; i++) {
  35427. var entry = map[i];
  35428. ctx.save();
  35429. ctx.transform.apply(ctx, entry.transform);
  35430. ctx.scale(1, -1);
  35431. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  35432. 0, -1, 1, 1);
  35433. if (this.imageLayer) {
  35434. var position = this.getCanvasPosition(entry.x, entry.y);
  35435. this.imageLayer.appendImage({
  35436. imgData: imgData,
  35437. left: position[0],
  35438. top: position[1],
  35439. width: w,
  35440. height: h
  35441. });
  35442. }
  35443. ctx.restore();
  35444. }
  35445. },
  35446. paintSolidColorImageMask:
  35447. function CanvasGraphics_paintSolidColorImageMask() {
  35448. this.ctx.fillRect(0, 0, 1, 1);
  35449. },
  35450. paintXObject: function CanvasGraphics_paintXObject() {
  35451. warn('Unsupported \'paintXObject\' command.');
  35452. },
  35453. // Marked content
  35454. markPoint: function CanvasGraphics_markPoint(tag) {
  35455. // TODO Marked content.
  35456. },
  35457. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  35458. // TODO Marked content.
  35459. },
  35460. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  35461. // TODO Marked content.
  35462. },
  35463. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  35464. tag, properties) {
  35465. // TODO Marked content.
  35466. },
  35467. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  35468. // TODO Marked content.
  35469. },
  35470. // Compatibility
  35471. beginCompat: function CanvasGraphics_beginCompat() {
  35472. // TODO ignore undefined operators (should we do that anyway?)
  35473. },
  35474. endCompat: function CanvasGraphics_endCompat() {
  35475. // TODO stop ignoring undefined operators
  35476. },
  35477. // Helper functions
  35478. consumePath: function CanvasGraphics_consumePath() {
  35479. var ctx = this.ctx;
  35480. if (this.pendingClip) {
  35481. if (this.pendingClip === EO_CLIP) {
  35482. if (ctx.mozFillRule !== undefined) {
  35483. ctx.mozFillRule = 'evenodd';
  35484. ctx.clip();
  35485. ctx.mozFillRule = 'nonzero';
  35486. } else {
  35487. ctx.clip('evenodd');
  35488. }
  35489. } else {
  35490. ctx.clip();
  35491. }
  35492. this.pendingClip = null;
  35493. }
  35494. ctx.beginPath();
  35495. },
  35496. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  35497. if (this.cachedGetSinglePixelWidth === null) {
  35498. // NOTE: The `save` and `restore` commands used below is a workaround
  35499. // that is necessary in order to prevent `mozCurrentTransformInverse`
  35500. // from intermittently returning incorrect values in Firefox, see:
  35501. // https://github.com/mozilla/pdf.js/issues/7188.
  35502. this.ctx.save();
  35503. var inverse = this.ctx.mozCurrentTransformInverse;
  35504. this.ctx.restore();
  35505. // max of the current horizontal and vertical scale
  35506. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  35507. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  35508. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  35509. }
  35510. return this.cachedGetSinglePixelWidth;
  35511. },
  35512. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  35513. var transform = this.ctx.mozCurrentTransform;
  35514. return [
  35515. transform[0] * x + transform[2] * y + transform[4],
  35516. transform[1] * x + transform[3] * y + transform[5]
  35517. ];
  35518. }
  35519. };
  35520. for (var op in OPS) {
  35521. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  35522. }
  35523. return CanvasGraphics;
  35524. })();
  35525. exports.CanvasGraphics = CanvasGraphics;
  35526. exports.createScratchCanvas = createScratchCanvas;
  35527. }));
  35528. (function (root, factory) {
  35529. {
  35530. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  35531. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  35532. }
  35533. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  35534. var error = sharedUtil.error;
  35535. var info = sharedUtil.info;
  35536. var isArray = sharedUtil.isArray;
  35537. var isBool = sharedUtil.isBool;
  35538. var isDict = corePrimitives.isDict;
  35539. var isStream = corePrimitives.isStream;
  35540. var PostScriptLexer = corePsParser.PostScriptLexer;
  35541. var PostScriptParser = corePsParser.PostScriptParser;
  35542. var PDFFunction = (function PDFFunctionClosure() {
  35543. var CONSTRUCT_SAMPLED = 0;
  35544. var CONSTRUCT_INTERPOLATED = 2;
  35545. var CONSTRUCT_STICHED = 3;
  35546. var CONSTRUCT_POSTSCRIPT = 4;
  35547. return {
  35548. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  35549. str) {
  35550. var i, ii;
  35551. var length = 1;
  35552. for (i = 0, ii = size.length; i < ii; i++) {
  35553. length *= size[i];
  35554. }
  35555. length *= outputSize;
  35556. var array = new Array(length);
  35557. var codeSize = 0;
  35558. var codeBuf = 0;
  35559. // 32 is a valid bps so shifting won't work
  35560. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  35561. var strBytes = str.getBytes((length * bps + 7) / 8);
  35562. var strIdx = 0;
  35563. for (i = 0; i < length; i++) {
  35564. while (codeSize < bps) {
  35565. codeBuf <<= 8;
  35566. codeBuf |= strBytes[strIdx++];
  35567. codeSize += 8;
  35568. }
  35569. codeSize -= bps;
  35570. array[i] = (codeBuf >> codeSize) * sampleMul;
  35571. codeBuf &= (1 << codeSize) - 1;
  35572. }
  35573. return array;
  35574. },
  35575. getIR: function PDFFunction_getIR(xref, fn) {
  35576. var dict = fn.dict;
  35577. if (!dict) {
  35578. dict = fn;
  35579. }
  35580. var types = [this.constructSampled,
  35581. null,
  35582. this.constructInterpolated,
  35583. this.constructStiched,
  35584. this.constructPostScript];
  35585. var typeNum = dict.get('FunctionType');
  35586. var typeFn = types[typeNum];
  35587. if (!typeFn) {
  35588. error('Unknown type of function');
  35589. }
  35590. return typeFn.call(this, fn, dict, xref);
  35591. },
  35592. fromIR: function PDFFunction_fromIR(IR) {
  35593. var type = IR[0];
  35594. switch (type) {
  35595. case CONSTRUCT_SAMPLED:
  35596. return this.constructSampledFromIR(IR);
  35597. case CONSTRUCT_INTERPOLATED:
  35598. return this.constructInterpolatedFromIR(IR);
  35599. case CONSTRUCT_STICHED:
  35600. return this.constructStichedFromIR(IR);
  35601. //case CONSTRUCT_POSTSCRIPT:
  35602. default:
  35603. return this.constructPostScriptFromIR(IR);
  35604. }
  35605. },
  35606. parse: function PDFFunction_parse(xref, fn) {
  35607. var IR = this.getIR(xref, fn);
  35608. return this.fromIR(IR);
  35609. },
  35610. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  35611. if (!isArray(fnObj)) {
  35612. // not an array -- parsing as regular function
  35613. return this.parse(xref, fnObj);
  35614. }
  35615. var fnArray = [];
  35616. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  35617. var obj = xref.fetchIfRef(fnObj[j]);
  35618. fnArray.push(PDFFunction.parse(xref, obj));
  35619. }
  35620. return function (src, srcOffset, dest, destOffset) {
  35621. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  35622. fnArray[i](src, srcOffset, dest, destOffset + i);
  35623. }
  35624. };
  35625. },
  35626. constructSampled: function PDFFunction_constructSampled(str, dict) {
  35627. function toMultiArray(arr) {
  35628. var inputLength = arr.length;
  35629. var out = [];
  35630. var index = 0;
  35631. for (var i = 0; i < inputLength; i += 2) {
  35632. out[index] = [arr[i], arr[i + 1]];
  35633. ++index;
  35634. }
  35635. return out;
  35636. }
  35637. var domain = dict.getArray('Domain');
  35638. var range = dict.getArray('Range');
  35639. if (!domain || !range) {
  35640. error('No domain or range');
  35641. }
  35642. var inputSize = domain.length / 2;
  35643. var outputSize = range.length / 2;
  35644. domain = toMultiArray(domain);
  35645. range = toMultiArray(range);
  35646. var size = dict.get('Size');
  35647. var bps = dict.get('BitsPerSample');
  35648. var order = dict.get('Order') || 1;
  35649. if (order !== 1) {
  35650. // No description how cubic spline interpolation works in PDF32000:2008
  35651. // As in poppler, ignoring order, linear interpolation may work as good
  35652. info('No support for cubic spline interpolation: ' + order);
  35653. }
  35654. var encode = dict.getArray('Encode');
  35655. if (!encode) {
  35656. encode = [];
  35657. for (var i = 0; i < inputSize; ++i) {
  35658. encode.push(0);
  35659. encode.push(size[i] - 1);
  35660. }
  35661. }
  35662. encode = toMultiArray(encode);
  35663. var decode = dict.getArray('Decode');
  35664. if (!decode) {
  35665. decode = range;
  35666. } else {
  35667. decode = toMultiArray(decode);
  35668. }
  35669. var samples = this.getSampleArray(size, outputSize, bps, str);
  35670. return [
  35671. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  35672. outputSize, Math.pow(2, bps) - 1, range
  35673. ];
  35674. },
  35675. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  35676. // See chapter 3, page 109 of the PDF reference
  35677. function interpolate(x, xmin, xmax, ymin, ymax) {
  35678. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  35679. }
  35680. return function constructSampledFromIRResult(src, srcOffset,
  35681. dest, destOffset) {
  35682. // See chapter 3, page 110 of the PDF reference.
  35683. var m = IR[1];
  35684. var domain = IR[2];
  35685. var encode = IR[3];
  35686. var decode = IR[4];
  35687. var samples = IR[5];
  35688. var size = IR[6];
  35689. var n = IR[7];
  35690. //var mask = IR[8];
  35691. var range = IR[9];
  35692. // Building the cube vertices: its part and sample index
  35693. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  35694. var cubeVertices = 1 << m;
  35695. var cubeN = new Float64Array(cubeVertices);
  35696. var cubeVertex = new Uint32Array(cubeVertices);
  35697. var i, j;
  35698. for (j = 0; j < cubeVertices; j++) {
  35699. cubeN[j] = 1;
  35700. }
  35701. var k = n, pos = 1;
  35702. // Map x_i to y_j for 0 <= i < m using the sampled function.
  35703. for (i = 0; i < m; ++i) {
  35704. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  35705. var domain_2i = domain[i][0];
  35706. var domain_2i_1 = domain[i][1];
  35707. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  35708. domain_2i_1);
  35709. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  35710. // Encode_2i, Encode_2i+1)
  35711. var e = interpolate(xi, domain_2i, domain_2i_1,
  35712. encode[i][0], encode[i][1]);
  35713. // e_i' = min(max(e_i, 0), Size_i - 1)
  35714. var size_i = size[i];
  35715. e = Math.min(Math.max(e, 0), size_i - 1);
  35716. // Adjusting the cube: N and vertex sample index
  35717. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  35718. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  35719. var n1 = e - e0; // (e - e0) / (e1 - e0);
  35720. var offset0 = e0 * k;
  35721. var offset1 = offset0 + k; // e1 * k
  35722. for (j = 0; j < cubeVertices; j++) {
  35723. if (j & pos) {
  35724. cubeN[j] *= n1;
  35725. cubeVertex[j] += offset1;
  35726. } else {
  35727. cubeN[j] *= n0;
  35728. cubeVertex[j] += offset0;
  35729. }
  35730. }
  35731. k *= size_i;
  35732. pos <<= 1;
  35733. }
  35734. for (j = 0; j < n; ++j) {
  35735. // Sum all cube vertices' samples portions
  35736. var rj = 0;
  35737. for (i = 0; i < cubeVertices; i++) {
  35738. rj += samples[cubeVertex[i] + j] * cubeN[i];
  35739. }
  35740. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  35741. // Decode_2j, Decode_2j+1)
  35742. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  35743. // y_j = min(max(r_j, range_2j), range_2j+1)
  35744. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  35745. range[j][1]);
  35746. }
  35747. };
  35748. },
  35749. constructInterpolated: function PDFFunction_constructInterpolated(str,
  35750. dict) {
  35751. var c0 = dict.getArray('C0') || [0];
  35752. var c1 = dict.getArray('C1') || [1];
  35753. var n = dict.get('N');
  35754. if (!isArray(c0) || !isArray(c1)) {
  35755. error('Illegal dictionary for interpolated function');
  35756. }
  35757. var length = c0.length;
  35758. var diff = [];
  35759. for (var i = 0; i < length; ++i) {
  35760. diff.push(c1[i] - c0[i]);
  35761. }
  35762. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  35763. },
  35764. constructInterpolatedFromIR:
  35765. function PDFFunction_constructInterpolatedFromIR(IR) {
  35766. var c0 = IR[1];
  35767. var diff = IR[2];
  35768. var n = IR[3];
  35769. var length = diff.length;
  35770. return function constructInterpolatedFromIRResult(src, srcOffset,
  35771. dest, destOffset) {
  35772. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  35773. for (var j = 0; j < length; ++j) {
  35774. dest[destOffset + j] = c0[j] + (x * diff[j]);
  35775. }
  35776. };
  35777. },
  35778. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  35779. var domain = dict.getArray('Domain');
  35780. if (!domain) {
  35781. error('No domain');
  35782. }
  35783. var inputSize = domain.length / 2;
  35784. if (inputSize !== 1) {
  35785. error('Bad domain for stiched function');
  35786. }
  35787. var fnRefs = dict.get('Functions');
  35788. var fns = [];
  35789. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  35790. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  35791. }
  35792. var bounds = dict.getArray('Bounds');
  35793. var encode = dict.getArray('Encode');
  35794. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  35795. },
  35796. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  35797. var domain = IR[1];
  35798. var bounds = IR[2];
  35799. var encode = IR[3];
  35800. var fnsIR = IR[4];
  35801. var fns = [];
  35802. var tmpBuf = new Float32Array(1);
  35803. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  35804. fns.push(PDFFunction.fromIR(fnsIR[i]));
  35805. }
  35806. return function constructStichedFromIRResult(src, srcOffset,
  35807. dest, destOffset) {
  35808. var clip = function constructStichedFromIRClip(v, min, max) {
  35809. if (v > max) {
  35810. v = max;
  35811. } else if (v < min) {
  35812. v = min;
  35813. }
  35814. return v;
  35815. };
  35816. // clip to domain
  35817. var v = clip(src[srcOffset], domain[0], domain[1]);
  35818. // calculate which bound the value is in
  35819. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  35820. if (v < bounds[i]) {
  35821. break;
  35822. }
  35823. }
  35824. // encode value into domain of function
  35825. var dmin = domain[0];
  35826. if (i > 0) {
  35827. dmin = bounds[i - 1];
  35828. }
  35829. var dmax = domain[1];
  35830. if (i < bounds.length) {
  35831. dmax = bounds[i];
  35832. }
  35833. var rmin = encode[2 * i];
  35834. var rmax = encode[2 * i + 1];
  35835. // Prevent the value from becoming NaN as a result
  35836. // of division by zero (fixes issue6113.pdf).
  35837. tmpBuf[0] = dmin === dmax ? rmin :
  35838. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  35839. // call the appropriate function
  35840. fns[i](tmpBuf, 0, dest, destOffset);
  35841. };
  35842. },
  35843. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  35844. xref) {
  35845. var domain = dict.getArray('Domain');
  35846. var range = dict.getArray('Range');
  35847. if (!domain) {
  35848. error('No domain.');
  35849. }
  35850. if (!range) {
  35851. error('No range.');
  35852. }
  35853. var lexer = new PostScriptLexer(fn);
  35854. var parser = new PostScriptParser(lexer);
  35855. var code = parser.parse();
  35856. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  35857. },
  35858. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  35859. IR) {
  35860. var domain = IR[1];
  35861. var range = IR[2];
  35862. var code = IR[3];
  35863. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  35864. if (compiled) {
  35865. // Compiled function consists of simple expressions such as addition,
  35866. // subtraction, Math.max, and also contains 'var' and 'return'
  35867. // statements. See the generation in the PostScriptCompiler below.
  35868. /*jshint -W054 */
  35869. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  35870. }
  35871. info('Unable to compile PS function');
  35872. var numOutputs = range.length >> 1;
  35873. var numInputs = domain.length >> 1;
  35874. var evaluator = new PostScriptEvaluator(code);
  35875. // Cache the values for a big speed up, the cache size is limited though
  35876. // since the number of possible values can be huge from a PS function.
  35877. var cache = Object.create(null);
  35878. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  35879. // seen in our tests.
  35880. var MAX_CACHE_SIZE = 2048 * 4;
  35881. var cache_available = MAX_CACHE_SIZE;
  35882. var tmpBuf = new Float32Array(numInputs);
  35883. return function constructPostScriptFromIRResult(src, srcOffset,
  35884. dest, destOffset) {
  35885. var i, value;
  35886. var key = '';
  35887. var input = tmpBuf;
  35888. for (i = 0; i < numInputs; i++) {
  35889. value = src[srcOffset + i];
  35890. input[i] = value;
  35891. key += value + '_';
  35892. }
  35893. var cachedValue = cache[key];
  35894. if (cachedValue !== undefined) {
  35895. dest.set(cachedValue, destOffset);
  35896. return;
  35897. }
  35898. var output = new Float32Array(numOutputs);
  35899. var stack = evaluator.execute(input);
  35900. var stackIndex = stack.length - numOutputs;
  35901. for (i = 0; i < numOutputs; i++) {
  35902. value = stack[stackIndex + i];
  35903. var bound = range[i * 2];
  35904. if (value < bound) {
  35905. value = bound;
  35906. } else {
  35907. bound = range[i * 2 +1];
  35908. if (value > bound) {
  35909. value = bound;
  35910. }
  35911. }
  35912. output[i] = value;
  35913. }
  35914. if (cache_available > 0) {
  35915. cache_available--;
  35916. cache[key] = output;
  35917. }
  35918. dest.set(output, destOffset);
  35919. };
  35920. }
  35921. };
  35922. })();
  35923. function isPDFFunction(v) {
  35924. var fnDict;
  35925. if (typeof v !== 'object') {
  35926. return false;
  35927. } else if (isDict(v)) {
  35928. fnDict = v;
  35929. } else if (isStream(v)) {
  35930. fnDict = v.dict;
  35931. } else {
  35932. return false;
  35933. }
  35934. return fnDict.has('FunctionType');
  35935. }
  35936. var PostScriptStack = (function PostScriptStackClosure() {
  35937. var MAX_STACK_SIZE = 100;
  35938. function PostScriptStack(initialStack) {
  35939. this.stack = !initialStack ? [] :
  35940. Array.prototype.slice.call(initialStack, 0);
  35941. }
  35942. PostScriptStack.prototype = {
  35943. push: function PostScriptStack_push(value) {
  35944. if (this.stack.length >= MAX_STACK_SIZE) {
  35945. error('PostScript function stack overflow.');
  35946. }
  35947. this.stack.push(value);
  35948. },
  35949. pop: function PostScriptStack_pop() {
  35950. if (this.stack.length <= 0) {
  35951. error('PostScript function stack underflow.');
  35952. }
  35953. return this.stack.pop();
  35954. },
  35955. copy: function PostScriptStack_copy(n) {
  35956. if (this.stack.length + n >= MAX_STACK_SIZE) {
  35957. error('PostScript function stack overflow.');
  35958. }
  35959. var stack = this.stack;
  35960. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  35961. stack.push(stack[i]);
  35962. }
  35963. },
  35964. index: function PostScriptStack_index(n) {
  35965. this.push(this.stack[this.stack.length - n - 1]);
  35966. },
  35967. // rotate the last n stack elements p times
  35968. roll: function PostScriptStack_roll(n, p) {
  35969. var stack = this.stack;
  35970. var l = stack.length - n;
  35971. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  35972. for (i = l, j = r; i < j; i++, j--) {
  35973. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35974. }
  35975. for (i = l, j = c - 1; i < j; i++, j--) {
  35976. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35977. }
  35978. for (i = c, j = r; i < j; i++, j--) {
  35979. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35980. }
  35981. }
  35982. };
  35983. return PostScriptStack;
  35984. })();
  35985. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  35986. function PostScriptEvaluator(operators) {
  35987. this.operators = operators;
  35988. }
  35989. PostScriptEvaluator.prototype = {
  35990. execute: function PostScriptEvaluator_execute(initialStack) {
  35991. var stack = new PostScriptStack(initialStack);
  35992. var counter = 0;
  35993. var operators = this.operators;
  35994. var length = operators.length;
  35995. var operator, a, b;
  35996. while (counter < length) {
  35997. operator = operators[counter++];
  35998. if (typeof operator === 'number') {
  35999. // Operator is really an operand and should be pushed to the stack.
  36000. stack.push(operator);
  36001. continue;
  36002. }
  36003. switch (operator) {
  36004. // non standard ps operators
  36005. case 'jz': // jump if false
  36006. b = stack.pop();
  36007. a = stack.pop();
  36008. if (!a) {
  36009. counter = b;
  36010. }
  36011. break;
  36012. case 'j': // jump
  36013. a = stack.pop();
  36014. counter = a;
  36015. break;
  36016. // all ps operators in alphabetical order (excluding if/ifelse)
  36017. case 'abs':
  36018. a = stack.pop();
  36019. stack.push(Math.abs(a));
  36020. break;
  36021. case 'add':
  36022. b = stack.pop();
  36023. a = stack.pop();
  36024. stack.push(a + b);
  36025. break;
  36026. case 'and':
  36027. b = stack.pop();
  36028. a = stack.pop();
  36029. if (isBool(a) && isBool(b)) {
  36030. stack.push(a && b);
  36031. } else {
  36032. stack.push(a & b);
  36033. }
  36034. break;
  36035. case 'atan':
  36036. a = stack.pop();
  36037. stack.push(Math.atan(a));
  36038. break;
  36039. case 'bitshift':
  36040. b = stack.pop();
  36041. a = stack.pop();
  36042. if (a > 0) {
  36043. stack.push(a << b);
  36044. } else {
  36045. stack.push(a >> b);
  36046. }
  36047. break;
  36048. case 'ceiling':
  36049. a = stack.pop();
  36050. stack.push(Math.ceil(a));
  36051. break;
  36052. case 'copy':
  36053. a = stack.pop();
  36054. stack.copy(a);
  36055. break;
  36056. case 'cos':
  36057. a = stack.pop();
  36058. stack.push(Math.cos(a));
  36059. break;
  36060. case 'cvi':
  36061. a = stack.pop() | 0;
  36062. stack.push(a);
  36063. break;
  36064. case 'cvr':
  36065. // noop
  36066. break;
  36067. case 'div':
  36068. b = stack.pop();
  36069. a = stack.pop();
  36070. stack.push(a / b);
  36071. break;
  36072. case 'dup':
  36073. stack.copy(1);
  36074. break;
  36075. case 'eq':
  36076. b = stack.pop();
  36077. a = stack.pop();
  36078. stack.push(a === b);
  36079. break;
  36080. case 'exch':
  36081. stack.roll(2, 1);
  36082. break;
  36083. case 'exp':
  36084. b = stack.pop();
  36085. a = stack.pop();
  36086. stack.push(Math.pow(a, b));
  36087. break;
  36088. case 'false':
  36089. stack.push(false);
  36090. break;
  36091. case 'floor':
  36092. a = stack.pop();
  36093. stack.push(Math.floor(a));
  36094. break;
  36095. case 'ge':
  36096. b = stack.pop();
  36097. a = stack.pop();
  36098. stack.push(a >= b);
  36099. break;
  36100. case 'gt':
  36101. b = stack.pop();
  36102. a = stack.pop();
  36103. stack.push(a > b);
  36104. break;
  36105. case 'idiv':
  36106. b = stack.pop();
  36107. a = stack.pop();
  36108. stack.push((a / b) | 0);
  36109. break;
  36110. case 'index':
  36111. a = stack.pop();
  36112. stack.index(a);
  36113. break;
  36114. case 'le':
  36115. b = stack.pop();
  36116. a = stack.pop();
  36117. stack.push(a <= b);
  36118. break;
  36119. case 'ln':
  36120. a = stack.pop();
  36121. stack.push(Math.log(a));
  36122. break;
  36123. case 'log':
  36124. a = stack.pop();
  36125. stack.push(Math.log(a) / Math.LN10);
  36126. break;
  36127. case 'lt':
  36128. b = stack.pop();
  36129. a = stack.pop();
  36130. stack.push(a < b);
  36131. break;
  36132. case 'mod':
  36133. b = stack.pop();
  36134. a = stack.pop();
  36135. stack.push(a % b);
  36136. break;
  36137. case 'mul':
  36138. b = stack.pop();
  36139. a = stack.pop();
  36140. stack.push(a * b);
  36141. break;
  36142. case 'ne':
  36143. b = stack.pop();
  36144. a = stack.pop();
  36145. stack.push(a !== b);
  36146. break;
  36147. case 'neg':
  36148. a = stack.pop();
  36149. stack.push(-a);
  36150. break;
  36151. case 'not':
  36152. a = stack.pop();
  36153. if (isBool(a)) {
  36154. stack.push(!a);
  36155. } else {
  36156. stack.push(~a);
  36157. }
  36158. break;
  36159. case 'or':
  36160. b = stack.pop();
  36161. a = stack.pop();
  36162. if (isBool(a) && isBool(b)) {
  36163. stack.push(a || b);
  36164. } else {
  36165. stack.push(a | b);
  36166. }
  36167. break;
  36168. case 'pop':
  36169. stack.pop();
  36170. break;
  36171. case 'roll':
  36172. b = stack.pop();
  36173. a = stack.pop();
  36174. stack.roll(a, b);
  36175. break;
  36176. case 'round':
  36177. a = stack.pop();
  36178. stack.push(Math.round(a));
  36179. break;
  36180. case 'sin':
  36181. a = stack.pop();
  36182. stack.push(Math.sin(a));
  36183. break;
  36184. case 'sqrt':
  36185. a = stack.pop();
  36186. stack.push(Math.sqrt(a));
  36187. break;
  36188. case 'sub':
  36189. b = stack.pop();
  36190. a = stack.pop();
  36191. stack.push(a - b);
  36192. break;
  36193. case 'true':
  36194. stack.push(true);
  36195. break;
  36196. case 'truncate':
  36197. a = stack.pop();
  36198. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  36199. stack.push(a);
  36200. break;
  36201. case 'xor':
  36202. b = stack.pop();
  36203. a = stack.pop();
  36204. if (isBool(a) && isBool(b)) {
  36205. stack.push(a !== b);
  36206. } else {
  36207. stack.push(a ^ b);
  36208. }
  36209. break;
  36210. default:
  36211. error('Unknown operator ' + operator);
  36212. break;
  36213. }
  36214. }
  36215. return stack.stack;
  36216. }
  36217. };
  36218. return PostScriptEvaluator;
  36219. })();
  36220. // Most of the PDFs functions consist of simple operations such as:
  36221. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  36222. //
  36223. // We can compile most of such programs, and at the same moment, we can
  36224. // optimize some expressions using basic math properties. Keeping track of
  36225. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  36226. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  36227. function AstNode(type) {
  36228. this.type = type;
  36229. }
  36230. AstNode.prototype.visit = function (visitor) {
  36231. throw new Error('abstract method');
  36232. };
  36233. function AstArgument(index, min, max) {
  36234. AstNode.call(this, 'args');
  36235. this.index = index;
  36236. this.min = min;
  36237. this.max = max;
  36238. }
  36239. AstArgument.prototype = Object.create(AstNode.prototype);
  36240. AstArgument.prototype.visit = function (visitor) {
  36241. visitor.visitArgument(this);
  36242. };
  36243. function AstLiteral(number) {
  36244. AstNode.call(this, 'literal');
  36245. this.number = number;
  36246. this.min = number;
  36247. this.max = number;
  36248. }
  36249. AstLiteral.prototype = Object.create(AstNode.prototype);
  36250. AstLiteral.prototype.visit = function (visitor) {
  36251. visitor.visitLiteral(this);
  36252. };
  36253. function AstBinaryOperation(op, arg1, arg2, min, max) {
  36254. AstNode.call(this, 'binary');
  36255. this.op = op;
  36256. this.arg1 = arg1;
  36257. this.arg2 = arg2;
  36258. this.min = min;
  36259. this.max = max;
  36260. }
  36261. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  36262. AstBinaryOperation.prototype.visit = function (visitor) {
  36263. visitor.visitBinaryOperation(this);
  36264. };
  36265. function AstMin(arg, max) {
  36266. AstNode.call(this, 'max');
  36267. this.arg = arg;
  36268. this.min = arg.min;
  36269. this.max = max;
  36270. }
  36271. AstMin.prototype = Object.create(AstNode.prototype);
  36272. AstMin.prototype.visit = function (visitor) {
  36273. visitor.visitMin(this);
  36274. };
  36275. function AstVariable(index, min, max) {
  36276. AstNode.call(this, 'var');
  36277. this.index = index;
  36278. this.min = min;
  36279. this.max = max;
  36280. }
  36281. AstVariable.prototype = Object.create(AstNode.prototype);
  36282. AstVariable.prototype.visit = function (visitor) {
  36283. visitor.visitVariable(this);
  36284. };
  36285. function AstVariableDefinition(variable, arg) {
  36286. AstNode.call(this, 'definition');
  36287. this.variable = variable;
  36288. this.arg = arg;
  36289. }
  36290. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  36291. AstVariableDefinition.prototype.visit = function (visitor) {
  36292. visitor.visitVariableDefinition(this);
  36293. };
  36294. function ExpressionBuilderVisitor() {
  36295. this.parts = [];
  36296. }
  36297. ExpressionBuilderVisitor.prototype = {
  36298. visitArgument: function (arg) {
  36299. this.parts.push('Math.max(', arg.min, ', Math.min(',
  36300. arg.max, ', src[srcOffset + ', arg.index, ']))');
  36301. },
  36302. visitVariable: function (variable) {
  36303. this.parts.push('v', variable.index);
  36304. },
  36305. visitLiteral: function (literal) {
  36306. this.parts.push(literal.number);
  36307. },
  36308. visitBinaryOperation: function (operation) {
  36309. this.parts.push('(');
  36310. operation.arg1.visit(this);
  36311. this.parts.push(' ', operation.op, ' ');
  36312. operation.arg2.visit(this);
  36313. this.parts.push(')');
  36314. },
  36315. visitVariableDefinition: function (definition) {
  36316. this.parts.push('var ');
  36317. definition.variable.visit(this);
  36318. this.parts.push(' = ');
  36319. definition.arg.visit(this);
  36320. this.parts.push(';');
  36321. },
  36322. visitMin: function (max) {
  36323. this.parts.push('Math.min(');
  36324. max.arg.visit(this);
  36325. this.parts.push(', ', max.max, ')');
  36326. },
  36327. toString: function () {
  36328. return this.parts.join('');
  36329. }
  36330. };
  36331. function buildAddOperation(num1, num2) {
  36332. if (num2.type === 'literal' && num2.number === 0) {
  36333. // optimization: second operand is 0
  36334. return num1;
  36335. }
  36336. if (num1.type === 'literal' && num1.number === 0) {
  36337. // optimization: first operand is 0
  36338. return num2;
  36339. }
  36340. if (num2.type === 'literal' && num1.type === 'literal') {
  36341. // optimization: operands operand are literals
  36342. return new AstLiteral(num1.number + num2.number);
  36343. }
  36344. return new AstBinaryOperation('+', num1, num2,
  36345. num1.min + num2.min, num1.max + num2.max);
  36346. }
  36347. function buildMulOperation(num1, num2) {
  36348. if (num2.type === 'literal') {
  36349. // optimization: second operands is a literal...
  36350. if (num2.number === 0) {
  36351. return new AstLiteral(0); // and it's 0
  36352. } else if (num2.number === 1) {
  36353. return num1; // and it's 1
  36354. } else if (num1.type === 'literal') {
  36355. // ... and first operands is a literal too
  36356. return new AstLiteral(num1.number * num2.number);
  36357. }
  36358. }
  36359. if (num1.type === 'literal') {
  36360. // optimization: first operands is a literal...
  36361. if (num1.number === 0) {
  36362. return new AstLiteral(0); // and it's 0
  36363. } else if (num1.number === 1) {
  36364. return num2; // and it's 1
  36365. }
  36366. }
  36367. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  36368. num1.max * num2.min, num1.max * num2.max);
  36369. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  36370. num1.max * num2.min, num1.max * num2.max);
  36371. return new AstBinaryOperation('*', num1, num2, min, max);
  36372. }
  36373. function buildSubOperation(num1, num2) {
  36374. if (num2.type === 'literal') {
  36375. // optimization: second operands is a literal...
  36376. if (num2.number === 0) {
  36377. return num1; // ... and it's 0
  36378. } else if (num1.type === 'literal') {
  36379. // ... and first operands is a literal too
  36380. return new AstLiteral(num1.number - num2.number);
  36381. }
  36382. }
  36383. if (num2.type === 'binary' && num2.op === '-' &&
  36384. num1.type === 'literal' && num1.number === 1 &&
  36385. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  36386. // optimization for case: 1 - (1 - x)
  36387. return num2.arg2;
  36388. }
  36389. return new AstBinaryOperation('-', num1, num2,
  36390. num1.min - num2.max, num1.max - num2.min);
  36391. }
  36392. function buildMinOperation(num1, max) {
  36393. if (num1.min >= max) {
  36394. // optimization: num1 min value is not less than required max
  36395. return new AstLiteral(max); // just returning max
  36396. } else if (num1.max <= max) {
  36397. // optimization: num1 max value is not greater than required max
  36398. return num1; // just returning an argument
  36399. }
  36400. return new AstMin(num1, max);
  36401. }
  36402. function PostScriptCompiler() {}
  36403. PostScriptCompiler.prototype = {
  36404. compile: function PostScriptCompiler_compile(code, domain, range) {
  36405. var stack = [];
  36406. var i, ii;
  36407. var instructions = [];
  36408. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  36409. var lastRegister = 0;
  36410. var n, j;
  36411. var num1, num2, ast1, ast2, tmpVar, item;
  36412. for (i = 0; i < inputSize; i++) {
  36413. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  36414. }
  36415. for (i = 0, ii = code.length; i < ii; i++) {
  36416. item = code[i];
  36417. if (typeof item === 'number') {
  36418. stack.push(new AstLiteral(item));
  36419. continue;
  36420. }
  36421. switch (item) {
  36422. case 'add':
  36423. if (stack.length < 2) {
  36424. return null;
  36425. }
  36426. num2 = stack.pop();
  36427. num1 = stack.pop();
  36428. stack.push(buildAddOperation(num1, num2));
  36429. break;
  36430. case 'cvr':
  36431. if (stack.length < 1) {
  36432. return null;
  36433. }
  36434. break;
  36435. case 'mul':
  36436. if (stack.length < 2) {
  36437. return null;
  36438. }
  36439. num2 = stack.pop();
  36440. num1 = stack.pop();
  36441. stack.push(buildMulOperation(num1, num2));
  36442. break;
  36443. case 'sub':
  36444. if (stack.length < 2) {
  36445. return null;
  36446. }
  36447. num2 = stack.pop();
  36448. num1 = stack.pop();
  36449. stack.push(buildSubOperation(num1, num2));
  36450. break;
  36451. case 'exch':
  36452. if (stack.length < 2) {
  36453. return null;
  36454. }
  36455. ast1 = stack.pop(); ast2 = stack.pop();
  36456. stack.push(ast1, ast2);
  36457. break;
  36458. case 'pop':
  36459. if (stack.length < 1) {
  36460. return null;
  36461. }
  36462. stack.pop();
  36463. break;
  36464. case 'index':
  36465. if (stack.length < 1) {
  36466. return null;
  36467. }
  36468. num1 = stack.pop();
  36469. if (num1.type !== 'literal') {
  36470. return null;
  36471. }
  36472. n = num1.number;
  36473. if (n < 0 || (n|0) !== n || stack.length < n) {
  36474. return null;
  36475. }
  36476. ast1 = stack[stack.length - n - 1];
  36477. if (ast1.type === 'literal' || ast1.type === 'var') {
  36478. stack.push(ast1);
  36479. break;
  36480. }
  36481. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36482. stack[stack.length - n - 1] = tmpVar;
  36483. stack.push(tmpVar);
  36484. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36485. break;
  36486. case 'dup':
  36487. if (stack.length < 1) {
  36488. return null;
  36489. }
  36490. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  36491. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  36492. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  36493. // special case of the commands sequence for the min operation
  36494. num1 = stack.pop();
  36495. stack.push(buildMinOperation(num1, code[i + 1]));
  36496. i += 6;
  36497. break;
  36498. }
  36499. ast1 = stack[stack.length - 1];
  36500. if (ast1.type === 'literal' || ast1.type === 'var') {
  36501. // we don't have to save into intermediate variable a literal or
  36502. // variable.
  36503. stack.push(ast1);
  36504. break;
  36505. }
  36506. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36507. stack[stack.length - 1] = tmpVar;
  36508. stack.push(tmpVar);
  36509. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36510. break;
  36511. case 'roll':
  36512. if (stack.length < 2) {
  36513. return null;
  36514. }
  36515. num2 = stack.pop();
  36516. num1 = stack.pop();
  36517. if (num2.type !== 'literal' || num1.type !== 'literal') {
  36518. // both roll operands must be numbers
  36519. return null;
  36520. }
  36521. j = num2.number;
  36522. n = num1.number;
  36523. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  36524. // ... and integers
  36525. return null;
  36526. }
  36527. j = ((j % n) + n) % n;
  36528. if (j === 0) {
  36529. break; // just skipping -- there are nothing to rotate
  36530. }
  36531. Array.prototype.push.apply(stack,
  36532. stack.splice(stack.length - n, n - j));
  36533. break;
  36534. default:
  36535. return null; // unsupported operator
  36536. }
  36537. }
  36538. if (stack.length !== outputSize) {
  36539. return null;
  36540. }
  36541. var result = [];
  36542. instructions.forEach(function (instruction) {
  36543. var statementBuilder = new ExpressionBuilderVisitor();
  36544. instruction.visit(statementBuilder);
  36545. result.push(statementBuilder.toString());
  36546. });
  36547. stack.forEach(function (expr, i) {
  36548. var statementBuilder = new ExpressionBuilderVisitor();
  36549. expr.visit(statementBuilder);
  36550. var min = range[i * 2], max = range[i * 2 + 1];
  36551. var out = [statementBuilder.toString()];
  36552. if (min > expr.min) {
  36553. out.unshift('Math.max(', min, ', ');
  36554. out.push(')');
  36555. }
  36556. if (max < expr.max) {
  36557. out.unshift('Math.min(', max, ', ');
  36558. out.push(')');
  36559. }
  36560. out.unshift('dest[destOffset + ', i, '] = ');
  36561. out.push(';');
  36562. result.push(out.join(''));
  36563. });
  36564. return result.join('\n');
  36565. }
  36566. };
  36567. return PostScriptCompiler;
  36568. })();
  36569. exports.isPDFFunction = isPDFFunction;
  36570. exports.PDFFunction = PDFFunction;
  36571. exports.PostScriptEvaluator = PostScriptEvaluator;
  36572. exports.PostScriptCompiler = PostScriptCompiler;
  36573. }));
  36574. (function (root, factory) {
  36575. {
  36576. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  36577. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  36578. root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  36579. }
  36580. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  36581. displayMetadata, displayDOMUtils, amdRequire) {
  36582. var InvalidPDFException = sharedUtil.InvalidPDFException;
  36583. var MessageHandler = sharedUtil.MessageHandler;
  36584. var MissingPDFException = sharedUtil.MissingPDFException;
  36585. var PageViewport = sharedUtil.PageViewport;
  36586. var PasswordResponses = sharedUtil.PasswordResponses;
  36587. var PasswordException = sharedUtil.PasswordException;
  36588. var StatTimer = sharedUtil.StatTimer;
  36589. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  36590. var UnknownErrorException = sharedUtil.UnknownErrorException;
  36591. var Util = sharedUtil.Util;
  36592. var createPromiseCapability = sharedUtil.createPromiseCapability;
  36593. var error = sharedUtil.error;
  36594. var deprecated = sharedUtil.deprecated;
  36595. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  36596. var info = sharedUtil.info;
  36597. var isInt = sharedUtil.isInt;
  36598. var isArray = sharedUtil.isArray;
  36599. var isArrayBuffer = sharedUtil.isArrayBuffer;
  36600. var isSameOrigin = sharedUtil.isSameOrigin;
  36601. var loadJpegStream = sharedUtil.loadJpegStream;
  36602. var stringToBytes = sharedUtil.stringToBytes;
  36603. var globalScope = sharedUtil.globalScope;
  36604. var warn = sharedUtil.warn;
  36605. var FontFaceObject = displayFontLoader.FontFaceObject;
  36606. var FontLoader = displayFontLoader.FontLoader;
  36607. var CanvasGraphics = displayCanvas.CanvasGraphics;
  36608. var createScratchCanvas = displayCanvas.createScratchCanvas;
  36609. var Metadata = displayMetadata.Metadata;
  36610. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  36611. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  36612. var isWorkerDisabled = false;
  36613. var workerSrc;
  36614. var isPostMessageTransfersDisabled = false;
  36615. /**
  36616. * Document initialization / loading parameters object.
  36617. *
  36618. * @typedef {Object} DocumentInitParameters
  36619. * @property {string} url - The URL of the PDF.
  36620. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  36621. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  36622. * use atob() to convert it to a binary string first.
  36623. * @property {Object} httpHeaders - Basic authentication headers.
  36624. * @property {boolean} withCredentials - Indicates whether or not cross-site
  36625. * Access-Control requests should be made using credentials such as cookies
  36626. * or authorization headers. The default is false.
  36627. * @property {string} password - For decrypting password-protected PDFs.
  36628. * @property {TypedArray} initialData - A typed array with the first portion or
  36629. * all of the pdf data. Used by the extension since some data is already
  36630. * loaded before the switch to range requests.
  36631. * @property {number} length - The PDF file length. It's used for progress
  36632. * reports and range requests operations.
  36633. * @property {PDFDataRangeTransport} range
  36634. * @property {number} rangeChunkSize - Optional parameter to specify
  36635. * maximum number of bytes fetched per range request. The default value is
  36636. * 2^16 = 65536.
  36637. * @property {PDFWorker} worker - The worker that will be used for the loading
  36638. * and parsing of the PDF data.
  36639. */
  36640. /**
  36641. * @typedef {Object} PDFDocumentStats
  36642. * @property {Array} streamTypes - Used stream types in the document (an item
  36643. * is set to true if specific stream ID was used in the document).
  36644. * @property {Array} fontTypes - Used font type in the document (an item is set
  36645. * to true if specific font ID was used in the document).
  36646. */
  36647. /**
  36648. * This is the main entry point for loading a PDF and interacting with it.
  36649. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  36650. * is used, which means it must follow the same origin rules that any XHR does
  36651. * e.g. No cross domain requests without CORS.
  36652. *
  36653. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  36654. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  36655. * already populated with data or parameter object.
  36656. *
  36657. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  36658. * if you want to manually serve range requests for data in the PDF.
  36659. *
  36660. * @param {function} passwordCallback (deprecated) It is used to request a
  36661. * password if wrong or no password was provided. The callback receives two
  36662. * parameters: function that needs to be called with new password and reason
  36663. * (see {PasswordResponses}).
  36664. *
  36665. * @param {function} progressCallback (deprecated) It is used to be able to
  36666. * monitor the loading progress of the PDF file (necessary to implement e.g.
  36667. * a loading bar). The callback receives an {Object} with the properties:
  36668. * {number} loaded and {number} total.
  36669. *
  36670. * @return {PDFDocumentLoadingTask}
  36671. */
  36672. function getDocument(src, pdfDataRangeTransport,
  36673. passwordCallback, progressCallback) {
  36674. var task = new PDFDocumentLoadingTask();
  36675. // Support of the obsolete arguments (for compatibility with API v1.0)
  36676. if (arguments.length > 1) {
  36677. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  36678. 'passwordCallback or progressCallback argument');
  36679. }
  36680. if (pdfDataRangeTransport) {
  36681. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  36682. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  36683. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  36684. pdfDataRangeTransport.length = src.length;
  36685. pdfDataRangeTransport.initialData = src.initialData;
  36686. if (!pdfDataRangeTransport.abort) {
  36687. pdfDataRangeTransport.abort = function () {};
  36688. }
  36689. }
  36690. src = Object.create(src);
  36691. src.range = pdfDataRangeTransport;
  36692. }
  36693. task.onPassword = passwordCallback || null;
  36694. task.onProgress = progressCallback || null;
  36695. var source;
  36696. if (typeof src === 'string') {
  36697. source = { url: src };
  36698. } else if (isArrayBuffer(src)) {
  36699. source = { data: src };
  36700. } else if (src instanceof PDFDataRangeTransport) {
  36701. source = { range: src };
  36702. } else {
  36703. if (typeof src !== 'object') {
  36704. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  36705. 'string or a parameter object');
  36706. }
  36707. if (!src.url && !src.data && !src.range) {
  36708. error('Invalid parameter object: need either .data, .range or .url');
  36709. }
  36710. source = src;
  36711. }
  36712. var params = {};
  36713. var rangeTransport = null;
  36714. var worker = null;
  36715. for (var key in source) {
  36716. if (key === 'url' && typeof window !== 'undefined') {
  36717. // The full path is required in the 'url' field.
  36718. params[key] = new URL(source[key], window.location).href;
  36719. continue;
  36720. } else if (key === 'range') {
  36721. rangeTransport = source[key];
  36722. continue;
  36723. } else if (key === 'worker') {
  36724. worker = source[key];
  36725. continue;
  36726. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  36727. // Converting string or array-like data to Uint8Array.
  36728. var pdfBytes = source[key];
  36729. if (typeof pdfBytes === 'string') {
  36730. params[key] = stringToBytes(pdfBytes);
  36731. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  36732. !isNaN(pdfBytes.length)) {
  36733. params[key] = new Uint8Array(pdfBytes);
  36734. } else if (isArrayBuffer(pdfBytes)) {
  36735. params[key] = new Uint8Array(pdfBytes);
  36736. } else {
  36737. error('Invalid PDF binary data: either typed array, string or ' +
  36738. 'array-like object is expected in the data property.');
  36739. }
  36740. continue;
  36741. }
  36742. params[key] = source[key];
  36743. }
  36744. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  36745. if (!worker) {
  36746. // Worker was not provided -- creating and owning our own.
  36747. worker = new PDFWorker();
  36748. task._worker = worker;
  36749. }
  36750. var docId = task.docId;
  36751. worker.promise.then(function () {
  36752. if (task.destroyed) {
  36753. throw new Error('Loading aborted');
  36754. }
  36755. return _fetchDocument(worker, params, rangeTransport, docId).then(
  36756. function (workerId) {
  36757. if (task.destroyed) {
  36758. throw new Error('Loading aborted');
  36759. }
  36760. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  36761. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  36762. task._transport = transport;
  36763. messageHandler.send('Ready', null);
  36764. });
  36765. }).catch(task._capability.reject);
  36766. return task;
  36767. }
  36768. /**
  36769. * Starts fetching of specified PDF document/data.
  36770. * @param {PDFWorker} worker
  36771. * @param {Object} source
  36772. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  36773. * @param {string} docId Unique document id, used as MessageHandler id.
  36774. * @returns {Promise} The promise, which is resolved when worker id of
  36775. * MessageHandler is known.
  36776. * @private
  36777. */
  36778. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  36779. if (worker.destroyed) {
  36780. return Promise.reject(new Error('Worker was destroyed'));
  36781. }
  36782. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  36783. source.disableStream = getDefaultSetting('disableStream');
  36784. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  36785. if (pdfDataRangeTransport) {
  36786. source.length = pdfDataRangeTransport.length;
  36787. source.initialData = pdfDataRangeTransport.initialData;
  36788. }
  36789. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  36790. docId: docId,
  36791. source: source,
  36792. disableRange: getDefaultSetting('disableRange'),
  36793. maxImageSize: getDefaultSetting('maxImageSize'),
  36794. cMapUrl: getDefaultSetting('cMapUrl'),
  36795. cMapPacked: getDefaultSetting('cMapPacked'),
  36796. disableFontFace: getDefaultSetting('disableFontFace'),
  36797. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  36798. postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
  36799. !isPostMessageTransfersDisabled,
  36800. }).then(function (workerId) {
  36801. if (worker.destroyed) {
  36802. throw new Error('Worker was destroyed');
  36803. }
  36804. return workerId;
  36805. });
  36806. }
  36807. /**
  36808. * PDF document loading operation.
  36809. * @class
  36810. * @alias PDFDocumentLoadingTask
  36811. */
  36812. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  36813. var nextDocumentId = 0;
  36814. /** @constructs PDFDocumentLoadingTask */
  36815. function PDFDocumentLoadingTask() {
  36816. this._capability = createPromiseCapability();
  36817. this._transport = null;
  36818. this._worker = null;
  36819. /**
  36820. * Unique document loading task id -- used in MessageHandlers.
  36821. * @type {string}
  36822. */
  36823. this.docId = 'd' + (nextDocumentId++);
  36824. /**
  36825. * Shows if loading task is destroyed.
  36826. * @type {boolean}
  36827. */
  36828. this.destroyed = false;
  36829. /**
  36830. * Callback to request a password if wrong or no password was provided.
  36831. * The callback receives two parameters: function that needs to be called
  36832. * with new password and reason (see {PasswordResponses}).
  36833. */
  36834. this.onPassword = null;
  36835. /**
  36836. * Callback to be able to monitor the loading progress of the PDF file
  36837. * (necessary to implement e.g. a loading bar). The callback receives
  36838. * an {Object} with the properties: {number} loaded and {number} total.
  36839. */
  36840. this.onProgress = null;
  36841. /**
  36842. * Callback to when unsupported feature is used. The callback receives
  36843. * an {UNSUPPORTED_FEATURES} argument.
  36844. */
  36845. this.onUnsupportedFeature = null;
  36846. }
  36847. PDFDocumentLoadingTask.prototype =
  36848. /** @lends PDFDocumentLoadingTask.prototype */ {
  36849. /**
  36850. * @return {Promise}
  36851. */
  36852. get promise() {
  36853. return this._capability.promise;
  36854. },
  36855. /**
  36856. * Aborts all network requests and destroys worker.
  36857. * @return {Promise} A promise that is resolved after destruction activity
  36858. * is completed.
  36859. */
  36860. destroy: function () {
  36861. this.destroyed = true;
  36862. var transportDestroyed = !this._transport ? Promise.resolve() :
  36863. this._transport.destroy();
  36864. return transportDestroyed.then(function () {
  36865. this._transport = null;
  36866. if (this._worker) {
  36867. this._worker.destroy();
  36868. this._worker = null;
  36869. }
  36870. }.bind(this));
  36871. },
  36872. /**
  36873. * Registers callbacks to indicate the document loading completion.
  36874. *
  36875. * @param {function} onFulfilled The callback for the loading completion.
  36876. * @param {function} onRejected The callback for the loading failure.
  36877. * @return {Promise} A promise that is resolved after the onFulfilled or
  36878. * onRejected callback.
  36879. */
  36880. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  36881. return this.promise.then.apply(this.promise, arguments);
  36882. }
  36883. };
  36884. return PDFDocumentLoadingTask;
  36885. })();
  36886. /**
  36887. * Abstract class to support range requests file loading.
  36888. * @class
  36889. * @alias PDFDataRangeTransport
  36890. * @param {number} length
  36891. * @param {Uint8Array} initialData
  36892. */
  36893. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  36894. function PDFDataRangeTransport(length, initialData) {
  36895. this.length = length;
  36896. this.initialData = initialData;
  36897. this._rangeListeners = [];
  36898. this._progressListeners = [];
  36899. this._progressiveReadListeners = [];
  36900. this._readyCapability = createPromiseCapability();
  36901. }
  36902. PDFDataRangeTransport.prototype =
  36903. /** @lends PDFDataRangeTransport.prototype */ {
  36904. addRangeListener:
  36905. function PDFDataRangeTransport_addRangeListener(listener) {
  36906. this._rangeListeners.push(listener);
  36907. },
  36908. addProgressListener:
  36909. function PDFDataRangeTransport_addProgressListener(listener) {
  36910. this._progressListeners.push(listener);
  36911. },
  36912. addProgressiveReadListener:
  36913. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  36914. this._progressiveReadListeners.push(listener);
  36915. },
  36916. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  36917. var listeners = this._rangeListeners;
  36918. for (var i = 0, n = listeners.length; i < n; ++i) {
  36919. listeners[i](begin, chunk);
  36920. }
  36921. },
  36922. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  36923. this._readyCapability.promise.then(function () {
  36924. var listeners = this._progressListeners;
  36925. for (var i = 0, n = listeners.length; i < n; ++i) {
  36926. listeners[i](loaded);
  36927. }
  36928. }.bind(this));
  36929. },
  36930. onDataProgressiveRead:
  36931. function PDFDataRangeTransport_onDataProgress(chunk) {
  36932. this._readyCapability.promise.then(function () {
  36933. var listeners = this._progressiveReadListeners;
  36934. for (var i = 0, n = listeners.length; i < n; ++i) {
  36935. listeners[i](chunk);
  36936. }
  36937. }.bind(this));
  36938. },
  36939. transportReady: function PDFDataRangeTransport_transportReady() {
  36940. this._readyCapability.resolve();
  36941. },
  36942. requestDataRange:
  36943. function PDFDataRangeTransport_requestDataRange(begin, end) {
  36944. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  36945. },
  36946. abort: function PDFDataRangeTransport_abort() {
  36947. }
  36948. };
  36949. return PDFDataRangeTransport;
  36950. })();
  36951. /**
  36952. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  36953. * properties that can be read synchronously.
  36954. * @class
  36955. * @alias PDFDocumentProxy
  36956. */
  36957. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  36958. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  36959. this.pdfInfo = pdfInfo;
  36960. this.transport = transport;
  36961. this.loadingTask = loadingTask;
  36962. }
  36963. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  36964. /**
  36965. * @return {number} Total number of pages the PDF contains.
  36966. */
  36967. get numPages() {
  36968. return this.pdfInfo.numPages;
  36969. },
  36970. /**
  36971. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  36972. * unique.
  36973. */
  36974. get fingerprint() {
  36975. return this.pdfInfo.fingerprint;
  36976. },
  36977. /**
  36978. * @param {number} pageNumber The page number to get. The first page is 1.
  36979. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  36980. * object.
  36981. */
  36982. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  36983. return this.transport.getPage(pageNumber);
  36984. },
  36985. /**
  36986. * @param {{num: number, gen: number}} ref The page reference. Must have
  36987. * the 'num' and 'gen' properties.
  36988. * @return {Promise} A promise that is resolved with the page index that is
  36989. * associated with the reference.
  36990. */
  36991. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  36992. return this.transport.getPageIndex(ref);
  36993. },
  36994. /**
  36995. * @return {Promise} A promise that is resolved with a lookup table for
  36996. * mapping named destinations to reference numbers.
  36997. *
  36998. * This can be slow for large documents: use getDestination instead
  36999. */
  37000. getDestinations: function PDFDocumentProxy_getDestinations() {
  37001. return this.transport.getDestinations();
  37002. },
  37003. /**
  37004. * @param {string} id The named destination to get.
  37005. * @return {Promise} A promise that is resolved with all information
  37006. * of the given named destination.
  37007. */
  37008. getDestination: function PDFDocumentProxy_getDestination(id) {
  37009. return this.transport.getDestination(id);
  37010. },
  37011. /**
  37012. * @return {Promise} A promise that is resolved with:
  37013. * an Array containing the pageLabels that correspond to the pageIndexes,
  37014. * or `null` when no pageLabels are present in the PDF file.
  37015. */
  37016. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  37017. return this.transport.getPageLabels();
  37018. },
  37019. /**
  37020. * @return {Promise} A promise that is resolved with a lookup table for
  37021. * mapping named attachments to their content.
  37022. */
  37023. getAttachments: function PDFDocumentProxy_getAttachments() {
  37024. return this.transport.getAttachments();
  37025. },
  37026. /**
  37027. * @return {Promise} A promise that is resolved with an array of all the
  37028. * JavaScript strings in the name tree.
  37029. */
  37030. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  37031. return this.transport.getJavaScript();
  37032. },
  37033. /**
  37034. * @return {Promise} A promise that is resolved with an {Array} that is a
  37035. * tree outline (if it has one) of the PDF. The tree is in the format of:
  37036. * [
  37037. * {
  37038. * title: string,
  37039. * bold: boolean,
  37040. * italic: boolean,
  37041. * color: rgb Uint8Array,
  37042. * dest: dest obj,
  37043. * url: string,
  37044. * items: array of more items like this
  37045. * },
  37046. * ...
  37047. * ].
  37048. */
  37049. getOutline: function PDFDocumentProxy_getOutline() {
  37050. return this.transport.getOutline();
  37051. },
  37052. /**
  37053. * @return {Promise} A promise that is resolved with an {Object} that has
  37054. * info and metadata properties. Info is an {Object} filled with anything
  37055. * available in the information dictionary and similarly metadata is a
  37056. * {Metadata} object with information from the metadata section of the PDF.
  37057. */
  37058. getMetadata: function PDFDocumentProxy_getMetadata() {
  37059. return this.transport.getMetadata();
  37060. },
  37061. /**
  37062. * @return {Promise} A promise that is resolved with a TypedArray that has
  37063. * the raw data from the PDF.
  37064. */
  37065. getData: function PDFDocumentProxy_getData() {
  37066. return this.transport.getData();
  37067. },
  37068. /**
  37069. * @return {Promise} A promise that is resolved when the document's data
  37070. * is loaded. It is resolved with an {Object} that contains the length
  37071. * property that indicates size of the PDF data in bytes.
  37072. */
  37073. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  37074. return this.transport.downloadInfoCapability.promise;
  37075. },
  37076. /**
  37077. * @return {Promise} A promise this is resolved with current stats about
  37078. * document structures (see {@link PDFDocumentStats}).
  37079. */
  37080. getStats: function PDFDocumentProxy_getStats() {
  37081. return this.transport.getStats();
  37082. },
  37083. /**
  37084. * Cleans up resources allocated by the document, e.g. created @font-face.
  37085. */
  37086. cleanup: function PDFDocumentProxy_cleanup() {
  37087. this.transport.startCleanup();
  37088. },
  37089. /**
  37090. * Destroys current document instance and terminates worker.
  37091. */
  37092. destroy: function PDFDocumentProxy_destroy() {
  37093. return this.loadingTask.destroy();
  37094. }
  37095. };
  37096. return PDFDocumentProxy;
  37097. })();
  37098. /**
  37099. * Page getTextContent parameters.
  37100. *
  37101. * @typedef {Object} getTextContentParameters
  37102. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  37103. * whitespace with standard spaces (0x20). The default value is `false`.
  37104. * @param {boolean} disableCombineTextItems - do not attempt to combine
  37105. * same line {@link TextItem}'s. The default value is `false`.
  37106. */
  37107. /**
  37108. * Page text content.
  37109. *
  37110. * @typedef {Object} TextContent
  37111. * @property {array} items - array of {@link TextItem}
  37112. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  37113. * name.
  37114. */
  37115. /**
  37116. * Page text content part.
  37117. *
  37118. * @typedef {Object} TextItem
  37119. * @property {string} str - text content.
  37120. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  37121. * @property {array} transform - transformation matrix.
  37122. * @property {number} width - width in device space.
  37123. * @property {number} height - height in device space.
  37124. * @property {string} fontName - font name used by pdf.js for converted font.
  37125. */
  37126. /**
  37127. * Text style.
  37128. *
  37129. * @typedef {Object} TextStyle
  37130. * @property {number} ascent - font ascent.
  37131. * @property {number} descent - font descent.
  37132. * @property {boolean} vertical - text is in vertical mode.
  37133. * @property {string} fontFamily - possible font family
  37134. */
  37135. /**
  37136. * Page annotation parameters.
  37137. *
  37138. * @typedef {Object} GetAnnotationsParameters
  37139. * @param {string} intent - Determines the annotations that will be fetched,
  37140. * can be either 'display' (viewable annotations) or 'print'
  37141. * (printable annotations).
  37142. * If the parameter is omitted, all annotations are fetched.
  37143. */
  37144. /**
  37145. * Page render parameters.
  37146. *
  37147. * @typedef {Object} RenderParameters
  37148. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  37149. * @property {PageViewport} viewport - Rendering viewport obtained by
  37150. * calling of PDFPage.getViewport method.
  37151. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  37152. * (default value is 'display').
  37153. * @property {Array} transform - (optional) Additional transform, applied
  37154. * just before viewport transform.
  37155. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  37156. * endLayout and appendImage functions.
  37157. * @property {function} continueCallback - (deprecated) A function that will be
  37158. * called each time the rendering is paused. To continue
  37159. * rendering call the function that is the first argument
  37160. * to the callback.
  37161. */
  37162. /**
  37163. * PDF page operator list.
  37164. *
  37165. * @typedef {Object} PDFOperatorList
  37166. * @property {Array} fnArray - Array containing the operator functions.
  37167. * @property {Array} argsArray - Array containing the arguments of the
  37168. * functions.
  37169. */
  37170. /**
  37171. * Proxy to a PDFPage in the worker thread.
  37172. * @class
  37173. * @alias PDFPageProxy
  37174. */
  37175. var PDFPageProxy = (function PDFPageProxyClosure() {
  37176. function PDFPageProxy(pageIndex, pageInfo, transport) {
  37177. this.pageIndex = pageIndex;
  37178. this.pageInfo = pageInfo;
  37179. this.transport = transport;
  37180. this.stats = new StatTimer();
  37181. this.stats.enabled = getDefaultSetting('enableStats');
  37182. this.commonObjs = transport.commonObjs;
  37183. this.objs = new PDFObjects();
  37184. this.cleanupAfterRender = false;
  37185. this.pendingCleanup = false;
  37186. this.intentStates = Object.create(null);
  37187. this.destroyed = false;
  37188. }
  37189. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  37190. /**
  37191. * @return {number} Page number of the page. First page is 1.
  37192. */
  37193. get pageNumber() {
  37194. return this.pageIndex + 1;
  37195. },
  37196. /**
  37197. * @return {number} The number of degrees the page is rotated clockwise.
  37198. */
  37199. get rotate() {
  37200. return this.pageInfo.rotate;
  37201. },
  37202. /**
  37203. * @return {Object} The reference that points to this page. It has 'num' and
  37204. * 'gen' properties.
  37205. */
  37206. get ref() {
  37207. return this.pageInfo.ref;
  37208. },
  37209. /**
  37210. * @return {Array} An array of the visible portion of the PDF page in the
  37211. * user space units - [x1, y1, x2, y2].
  37212. */
  37213. get view() {
  37214. return this.pageInfo.view;
  37215. },
  37216. /**
  37217. * @param {number} scale The desired scale of the viewport.
  37218. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  37219. * defaults to the page rotation.
  37220. * @return {PageViewport} Contains 'width' and 'height' properties
  37221. * along with transforms required for rendering.
  37222. */
  37223. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  37224. if (arguments.length < 2) {
  37225. rotate = this.rotate;
  37226. }
  37227. return new PageViewport(this.view, scale, rotate, 0, 0);
  37228. },
  37229. /**
  37230. * @param {GetAnnotationsParameters} params - Annotation parameters.
  37231. * @return {Promise} A promise that is resolved with an {Array} of the
  37232. * annotation objects.
  37233. */
  37234. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  37235. var intent = (params && params.intent) || null;
  37236. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  37237. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  37238. intent);
  37239. this.annotationsIntent = intent;
  37240. }
  37241. return this.annotationsPromise;
  37242. },
  37243. /**
  37244. * Begins the process of rendering a page to the desired context.
  37245. * @param {RenderParameters} params Page render parameters.
  37246. * @return {RenderTask} An object that contains the promise, which
  37247. * is resolved when the page finishes rendering.
  37248. */
  37249. render: function PDFPageProxy_render(params) {
  37250. var stats = this.stats;
  37251. stats.time('Overall');
  37252. // If there was a pending destroy cancel it so no cleanup happens during
  37253. // this call to render.
  37254. this.pendingCleanup = false;
  37255. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  37256. if (!this.intentStates[renderingIntent]) {
  37257. this.intentStates[renderingIntent] = Object.create(null);
  37258. }
  37259. var intentState = this.intentStates[renderingIntent];
  37260. // If there's no displayReadyCapability yet, then the operatorList
  37261. // was never requested before. Make the request and create the promise.
  37262. if (!intentState.displayReadyCapability) {
  37263. intentState.receivingOperatorList = true;
  37264. intentState.displayReadyCapability = createPromiseCapability();
  37265. intentState.operatorList = {
  37266. fnArray: [],
  37267. argsArray: [],
  37268. lastChunk: false
  37269. };
  37270. this.stats.time('Page Request');
  37271. this.transport.messageHandler.send('RenderPageRequest', {
  37272. pageIndex: this.pageNumber - 1,
  37273. intent: renderingIntent
  37274. });
  37275. }
  37276. var internalRenderTask = new InternalRenderTask(complete, params,
  37277. this.objs,
  37278. this.commonObjs,
  37279. intentState.operatorList,
  37280. this.pageNumber);
  37281. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  37282. if (!intentState.renderTasks) {
  37283. intentState.renderTasks = [];
  37284. }
  37285. intentState.renderTasks.push(internalRenderTask);
  37286. var renderTask = internalRenderTask.task;
  37287. // Obsolete parameter support
  37288. if (params.continueCallback) {
  37289. deprecated('render is used with continueCallback parameter');
  37290. renderTask.onContinue = params.continueCallback;
  37291. }
  37292. var self = this;
  37293. intentState.displayReadyCapability.promise.then(
  37294. function pageDisplayReadyPromise(transparency) {
  37295. if (self.pendingCleanup) {
  37296. complete();
  37297. return;
  37298. }
  37299. stats.time('Rendering');
  37300. internalRenderTask.initializeGraphics(transparency);
  37301. internalRenderTask.operatorListChanged();
  37302. },
  37303. function pageDisplayReadPromiseError(reason) {
  37304. complete(reason);
  37305. }
  37306. );
  37307. function complete(error) {
  37308. var i = intentState.renderTasks.indexOf(internalRenderTask);
  37309. if (i >= 0) {
  37310. intentState.renderTasks.splice(i, 1);
  37311. }
  37312. if (self.cleanupAfterRender) {
  37313. self.pendingCleanup = true;
  37314. }
  37315. self._tryCleanup();
  37316. if (error) {
  37317. internalRenderTask.capability.reject(error);
  37318. } else {
  37319. internalRenderTask.capability.resolve();
  37320. }
  37321. stats.timeEnd('Rendering');
  37322. stats.timeEnd('Overall');
  37323. }
  37324. return renderTask;
  37325. },
  37326. /**
  37327. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  37328. * object that represents page's operator list.
  37329. */
  37330. getOperatorList: function PDFPageProxy_getOperatorList() {
  37331. function operatorListChanged() {
  37332. if (intentState.operatorList.lastChunk) {
  37333. intentState.opListReadCapability.resolve(intentState.operatorList);
  37334. var i = intentState.renderTasks.indexOf(opListTask);
  37335. if (i >= 0) {
  37336. intentState.renderTasks.splice(i, 1);
  37337. }
  37338. }
  37339. }
  37340. var renderingIntent = 'oplist';
  37341. if (!this.intentStates[renderingIntent]) {
  37342. this.intentStates[renderingIntent] = Object.create(null);
  37343. }
  37344. var intentState = this.intentStates[renderingIntent];
  37345. var opListTask;
  37346. if (!intentState.opListReadCapability) {
  37347. opListTask = {};
  37348. opListTask.operatorListChanged = operatorListChanged;
  37349. intentState.receivingOperatorList = true;
  37350. intentState.opListReadCapability = createPromiseCapability();
  37351. intentState.renderTasks = [];
  37352. intentState.renderTasks.push(opListTask);
  37353. intentState.operatorList = {
  37354. fnArray: [],
  37355. argsArray: [],
  37356. lastChunk: false
  37357. };
  37358. this.transport.messageHandler.send('RenderPageRequest', {
  37359. pageIndex: this.pageIndex,
  37360. intent: renderingIntent
  37361. });
  37362. }
  37363. return intentState.opListReadCapability.promise;
  37364. },
  37365. /**
  37366. * @param {getTextContentParameters} params - getTextContent parameters.
  37367. * @return {Promise} That is resolved a {@link TextContent}
  37368. * object that represent the page text content.
  37369. */
  37370. getTextContent: function PDFPageProxy_getTextContent(params) {
  37371. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  37372. pageIndex: this.pageNumber - 1,
  37373. normalizeWhitespace: (params && params.normalizeWhitespace === true ?
  37374. true : /* Default */ false),
  37375. combineTextItems: (params && params.disableCombineTextItems === true ?
  37376. false : /* Default */ true),
  37377. });
  37378. },
  37379. /**
  37380. * Destroys page object.
  37381. */
  37382. _destroy: function PDFPageProxy_destroy() {
  37383. this.destroyed = true;
  37384. this.transport.pageCache[this.pageIndex] = null;
  37385. var waitOn = [];
  37386. Object.keys(this.intentStates).forEach(function(intent) {
  37387. if (intent === 'oplist') {
  37388. // Avoid errors below, since the renderTasks are just stubs.
  37389. return;
  37390. }
  37391. var intentState = this.intentStates[intent];
  37392. intentState.renderTasks.forEach(function(renderTask) {
  37393. var renderCompleted = renderTask.capability.promise.
  37394. catch(function () {}); // ignoring failures
  37395. waitOn.push(renderCompleted);
  37396. renderTask.cancel();
  37397. });
  37398. }, this);
  37399. this.objs.clear();
  37400. this.annotationsPromise = null;
  37401. this.pendingCleanup = false;
  37402. return Promise.all(waitOn);
  37403. },
  37404. /**
  37405. * Cleans up resources allocated by the page. (deprecated)
  37406. */
  37407. destroy: function() {
  37408. deprecated('page destroy method, use cleanup() instead');
  37409. this.cleanup();
  37410. },
  37411. /**
  37412. * Cleans up resources allocated by the page.
  37413. */
  37414. cleanup: function PDFPageProxy_cleanup() {
  37415. this.pendingCleanup = true;
  37416. this._tryCleanup();
  37417. },
  37418. /**
  37419. * For internal use only. Attempts to clean up if rendering is in a state
  37420. * where that's possible.
  37421. * @ignore
  37422. */
  37423. _tryCleanup: function PDFPageProxy_tryCleanup() {
  37424. if (!this.pendingCleanup ||
  37425. Object.keys(this.intentStates).some(function(intent) {
  37426. var intentState = this.intentStates[intent];
  37427. return (intentState.renderTasks.length !== 0 ||
  37428. intentState.receivingOperatorList);
  37429. }, this)) {
  37430. return;
  37431. }
  37432. Object.keys(this.intentStates).forEach(function(intent) {
  37433. delete this.intentStates[intent];
  37434. }, this);
  37435. this.objs.clear();
  37436. this.annotationsPromise = null;
  37437. this.pendingCleanup = false;
  37438. },
  37439. /**
  37440. * For internal use only.
  37441. * @ignore
  37442. */
  37443. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  37444. intent) {
  37445. var intentState = this.intentStates[intent];
  37446. // TODO Refactor RenderPageRequest to separate rendering
  37447. // and operator list logic
  37448. if (intentState.displayReadyCapability) {
  37449. intentState.displayReadyCapability.resolve(transparency);
  37450. }
  37451. },
  37452. /**
  37453. * For internal use only.
  37454. * @ignore
  37455. */
  37456. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  37457. intent) {
  37458. var intentState = this.intentStates[intent];
  37459. var i, ii;
  37460. // Add the new chunk to the current operator list.
  37461. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  37462. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  37463. intentState.operatorList.argsArray.push(
  37464. operatorListChunk.argsArray[i]);
  37465. }
  37466. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  37467. // Notify all the rendering tasks there are more operators to be consumed.
  37468. for (i = 0; i < intentState.renderTasks.length; i++) {
  37469. intentState.renderTasks[i].operatorListChanged();
  37470. }
  37471. if (operatorListChunk.lastChunk) {
  37472. intentState.receivingOperatorList = false;
  37473. this._tryCleanup();
  37474. }
  37475. }
  37476. };
  37477. return PDFPageProxy;
  37478. })();
  37479. /**
  37480. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  37481. * WorkerTransport for them. If creation of a web worker is not possible,
  37482. * a "fake" worker will be used instead.
  37483. * @class
  37484. */
  37485. var PDFWorker = (function PDFWorkerClosure() {
  37486. var nextFakeWorkerId = 0;
  37487. function getWorkerSrc() {
  37488. if (typeof workerSrc !== 'undefined') {
  37489. return workerSrc;
  37490. }
  37491. if (getDefaultSetting('workerSrc')) {
  37492. return getDefaultSetting('workerSrc');
  37493. }
  37494. if (pdfjsFilePath) {
  37495. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  37496. }
  37497. error('No PDFJS.workerSrc specified');
  37498. }
  37499. var fakeWorkerFilesLoadedCapability;
  37500. // Loads worker code into main thread.
  37501. function setupFakeWorkerGlobal() {
  37502. var WorkerMessageHandler;
  37503. if (!fakeWorkerFilesLoadedCapability) {
  37504. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  37505. // In the developer build load worker_loader which in turn loads all the
  37506. // other files and resolves the promise. In production only the
  37507. // pdf.worker.js file is needed.
  37508. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  37509. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  37510. }
  37511. return fakeWorkerFilesLoadedCapability.promise;
  37512. }
  37513. function FakeWorkerPort(defer) {
  37514. this._listeners = [];
  37515. this._defer = defer;
  37516. this._deferred = Promise.resolve(undefined);
  37517. }
  37518. FakeWorkerPort.prototype = {
  37519. postMessage: function (obj, transfers) {
  37520. function cloneValue(value) {
  37521. // Trying to perform a structured clone close to the spec, including
  37522. // transfers.
  37523. if (typeof value !== 'object' || value === null) {
  37524. return value;
  37525. }
  37526. if (cloned.has(value)) { // already cloned the object
  37527. return cloned.get(value);
  37528. }
  37529. var result;
  37530. var buffer;
  37531. if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
  37532. // We found object with ArrayBuffer (typed array).
  37533. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  37534. if (value === buffer) {
  37535. // Special case when we are faking typed arrays in compatibility.js.
  37536. result = value;
  37537. } else if (transferable) {
  37538. result = new value.constructor(buffer, value.byteOffset,
  37539. value.byteLength);
  37540. } else {
  37541. result = new value.constructor(value);
  37542. }
  37543. cloned.set(value, result);
  37544. return result;
  37545. }
  37546. result = isArray(value) ? [] : {};
  37547. cloned.set(value, result); // adding to cache now for cyclic references
  37548. // Cloning all value and object properties, however ignoring properties
  37549. // defined via getter.
  37550. for (var i in value) {
  37551. var desc, p = value;
  37552. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  37553. p = Object.getPrototypeOf(p);
  37554. }
  37555. if (typeof desc.value === 'undefined' ||
  37556. typeof desc.value === 'function') {
  37557. continue;
  37558. }
  37559. result[i] = cloneValue(desc.value);
  37560. }
  37561. return result;
  37562. }
  37563. if (!this._defer) {
  37564. this._listeners.forEach(function (listener) {
  37565. listener.call(this, {data: obj});
  37566. }, this);
  37567. return;
  37568. }
  37569. var cloned = new WeakMap();
  37570. var e = {data: cloneValue(obj)};
  37571. this._deferred.then(function () {
  37572. this._listeners.forEach(function (listener) {
  37573. listener.call(this, e);
  37574. }, this);
  37575. }.bind(this));
  37576. },
  37577. addEventListener: function (name, listener) {
  37578. this._listeners.push(listener);
  37579. },
  37580. removeEventListener: function (name, listener) {
  37581. var i = this._listeners.indexOf(listener);
  37582. this._listeners.splice(i, 1);
  37583. },
  37584. terminate: function () {
  37585. this._listeners = [];
  37586. }
  37587. };
  37588. function createCDNWrapper(url) {
  37589. // We will rely on blob URL's property to specify origin.
  37590. // We want this function to fail in case if createObjectURL or Blob do not
  37591. // exist or fail for some reason -- our Worker creation will fail anyway.
  37592. var wrapper = 'importScripts(\'' + url + '\');';
  37593. return URL.createObjectURL(new Blob([wrapper]));
  37594. }
  37595. function PDFWorker(name) {
  37596. this.name = name;
  37597. this.destroyed = false;
  37598. this._readyCapability = createPromiseCapability();
  37599. this._port = null;
  37600. this._webWorker = null;
  37601. this._messageHandler = null;
  37602. this._initialize();
  37603. }
  37604. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  37605. get promise() {
  37606. return this._readyCapability.promise;
  37607. },
  37608. get port() {
  37609. return this._port;
  37610. },
  37611. get messageHandler() {
  37612. return this._messageHandler;
  37613. },
  37614. _initialize: function PDFWorker_initialize() {
  37615. // If worker support isn't disabled explicit and the browser has worker
  37616. // support, create a new web worker and test if it/the browser fulfills
  37617. // all requirements to run parts of pdf.js in a web worker.
  37618. // Right now, the requirement is, that an Uint8Array is still an
  37619. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  37620. // Either workers are disabled, not supported or have thrown an exception.
  37621. // Thus, we fallback to a faked worker.
  37622. this._setupFakeWorker();
  37623. },
  37624. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  37625. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  37626. warn('Setting up fake worker.');
  37627. isWorkerDisabled = true;
  37628. }
  37629. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  37630. if (this.destroyed) {
  37631. this._readyCapability.reject(new Error('Worker was destroyed'));
  37632. return;
  37633. }
  37634. // We cannot turn on proper fake port simulation (this includes
  37635. // structured cloning) when typed arrays are not supported. Relying
  37636. // on a chance that messages will be sent in proper order.
  37637. var isTypedArraysPresent = Uint8Array !== Float32Array;
  37638. var port = new FakeWorkerPort(isTypedArraysPresent);
  37639. this._port = port;
  37640. // All fake workers use the same port, making id unique.
  37641. var id = 'fake' + (nextFakeWorkerId++);
  37642. // If the main thread is our worker, setup the handling for the
  37643. // messages -- the main thread sends to it self.
  37644. var workerHandler = new MessageHandler(id + '_worker', id, port);
  37645. WorkerMessageHandler.setup(workerHandler, port);
  37646. var messageHandler = new MessageHandler(id, id + '_worker', port);
  37647. this._messageHandler = messageHandler;
  37648. this._readyCapability.resolve();
  37649. }.bind(this));
  37650. },
  37651. /**
  37652. * Destroys the worker instance.
  37653. */
  37654. destroy: function PDFWorker_destroy() {
  37655. this.destroyed = true;
  37656. if (this._webWorker) {
  37657. // We need to terminate only web worker created resource.
  37658. this._webWorker.terminate();
  37659. this._webWorker = null;
  37660. }
  37661. this._port = null;
  37662. if (this._messageHandler) {
  37663. this._messageHandler.destroy();
  37664. this._messageHandler = null;
  37665. }
  37666. }
  37667. };
  37668. return PDFWorker;
  37669. })();
  37670. /**
  37671. * For internal use only.
  37672. * @ignore
  37673. */
  37674. var WorkerTransport = (function WorkerTransportClosure() {
  37675. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  37676. this.messageHandler = messageHandler;
  37677. this.loadingTask = loadingTask;
  37678. this.pdfDataRangeTransport = pdfDataRangeTransport;
  37679. this.commonObjs = new PDFObjects();
  37680. this.fontLoader = new FontLoader(loadingTask.docId);
  37681. this.destroyed = false;
  37682. this.destroyCapability = null;
  37683. this.pageCache = [];
  37684. this.pagePromises = [];
  37685. this.downloadInfoCapability = createPromiseCapability();
  37686. this.setupMessageHandler();
  37687. }
  37688. WorkerTransport.prototype = {
  37689. destroy: function WorkerTransport_destroy() {
  37690. if (this.destroyCapability) {
  37691. return this.destroyCapability.promise;
  37692. }
  37693. this.destroyed = true;
  37694. this.destroyCapability = createPromiseCapability();
  37695. var waitOn = [];
  37696. // We need to wait for all renderings to be completed, e.g.
  37697. // timeout/rAF can take a long time.
  37698. this.pageCache.forEach(function (page) {
  37699. if (page) {
  37700. waitOn.push(page._destroy());
  37701. }
  37702. });
  37703. this.pageCache = [];
  37704. this.pagePromises = [];
  37705. var self = this;
  37706. // We also need to wait for the worker to finish its long running tasks.
  37707. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  37708. waitOn.push(terminated);
  37709. Promise.all(waitOn).then(function () {
  37710. self.fontLoader.clear();
  37711. if (self.pdfDataRangeTransport) {
  37712. self.pdfDataRangeTransport.abort();
  37713. self.pdfDataRangeTransport = null;
  37714. }
  37715. if (self.messageHandler) {
  37716. self.messageHandler.destroy();
  37717. self.messageHandler = null;
  37718. }
  37719. self.destroyCapability.resolve();
  37720. }, this.destroyCapability.reject);
  37721. return this.destroyCapability.promise;
  37722. },
  37723. setupMessageHandler:
  37724. function WorkerTransport_setupMessageHandler() {
  37725. var messageHandler = this.messageHandler;
  37726. function updatePassword(password) {
  37727. messageHandler.send('UpdatePassword', password);
  37728. }
  37729. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  37730. if (pdfDataRangeTransport) {
  37731. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  37732. messageHandler.send('OnDataRange', {
  37733. begin: begin,
  37734. chunk: chunk
  37735. });
  37736. });
  37737. pdfDataRangeTransport.addProgressListener(function(loaded) {
  37738. messageHandler.send('OnDataProgress', {
  37739. loaded: loaded
  37740. });
  37741. });
  37742. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  37743. messageHandler.send('OnDataRange', {
  37744. chunk: chunk
  37745. });
  37746. });
  37747. messageHandler.on('RequestDataRange',
  37748. function transportDataRange(data) {
  37749. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  37750. }, this);
  37751. }
  37752. messageHandler.on('GetDoc', function transportDoc(data) {
  37753. var pdfInfo = data.pdfInfo;
  37754. this.numPages = data.pdfInfo.numPages;
  37755. var loadingTask = this.loadingTask;
  37756. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  37757. this.pdfDocument = pdfDocument;
  37758. loadingTask._capability.resolve(pdfDocument);
  37759. }, this);
  37760. messageHandler.on('NeedPassword',
  37761. function transportNeedPassword(exception) {
  37762. var loadingTask = this.loadingTask;
  37763. if (loadingTask.onPassword) {
  37764. return loadingTask.onPassword(updatePassword,
  37765. PasswordResponses.NEED_PASSWORD);
  37766. }
  37767. loadingTask._capability.reject(
  37768. new PasswordException(exception.message, exception.code));
  37769. }, this);
  37770. messageHandler.on('IncorrectPassword',
  37771. function transportIncorrectPassword(exception) {
  37772. var loadingTask = this.loadingTask;
  37773. if (loadingTask.onPassword) {
  37774. return loadingTask.onPassword(updatePassword,
  37775. PasswordResponses.INCORRECT_PASSWORD);
  37776. }
  37777. loadingTask._capability.reject(
  37778. new PasswordException(exception.message, exception.code));
  37779. }, this);
  37780. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  37781. this.loadingTask._capability.reject(
  37782. new InvalidPDFException(exception.message));
  37783. }, this);
  37784. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  37785. this.loadingTask._capability.reject(
  37786. new MissingPDFException(exception.message));
  37787. }, this);
  37788. messageHandler.on('UnexpectedResponse',
  37789. function transportUnexpectedResponse(exception) {
  37790. this.loadingTask._capability.reject(
  37791. new UnexpectedResponseException(exception.message, exception.status));
  37792. }, this);
  37793. messageHandler.on('UnknownError',
  37794. function transportUnknownError(exception) {
  37795. this.loadingTask._capability.reject(
  37796. new UnknownErrorException(exception.message, exception.details));
  37797. }, this);
  37798. messageHandler.on('DataLoaded', function transportPage(data) {
  37799. this.downloadInfoCapability.resolve(data);
  37800. }, this);
  37801. messageHandler.on('PDFManagerReady', function transportPage(data) {
  37802. if (this.pdfDataRangeTransport) {
  37803. this.pdfDataRangeTransport.transportReady();
  37804. }
  37805. }, this);
  37806. messageHandler.on('StartRenderPage', function transportRender(data) {
  37807. if (this.destroyed) {
  37808. return; // Ignore any pending requests if the worker was terminated.
  37809. }
  37810. var page = this.pageCache[data.pageIndex];
  37811. page.stats.timeEnd('Page Request');
  37812. page._startRenderPage(data.transparency, data.intent);
  37813. }, this);
  37814. messageHandler.on('RenderPageChunk', function transportRender(data) {
  37815. if (this.destroyed) {
  37816. return; // Ignore any pending requests if the worker was terminated.
  37817. }
  37818. var page = this.pageCache[data.pageIndex];
  37819. page._renderPageChunk(data.operatorList, data.intent);
  37820. }, this);
  37821. messageHandler.on('commonobj', function transportObj(data) {
  37822. if (this.destroyed) {
  37823. return; // Ignore any pending requests if the worker was terminated.
  37824. }
  37825. var id = data[0];
  37826. var type = data[1];
  37827. if (this.commonObjs.hasData(id)) {
  37828. return;
  37829. }
  37830. switch (type) {
  37831. case 'Font':
  37832. var exportedData = data[2];
  37833. if ('error' in exportedData) {
  37834. var exportedError = exportedData.error;
  37835. warn('Error during font loading: ' + exportedError);
  37836. this.commonObjs.resolve(id, exportedError);
  37837. break;
  37838. }
  37839. var fontRegistry = null;
  37840. if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
  37841. globalScope['FontInspector'].enabled) {
  37842. fontRegistry = {
  37843. registerFont: function (font, url) {
  37844. globalScope['FontInspector'].fontAdded(font, url);
  37845. }
  37846. };
  37847. }
  37848. var font = new FontFaceObject(exportedData, {
  37849. isEvalSuported: getDefaultSetting('isEvalSupported'),
  37850. disableFontFace: getDefaultSetting('disableFontFace'),
  37851. fontRegistry: fontRegistry
  37852. });
  37853. this.fontLoader.bind(
  37854. [font],
  37855. function fontReady(fontObjs) {
  37856. this.commonObjs.resolve(id, font);
  37857. }.bind(this)
  37858. );
  37859. break;
  37860. case 'FontPath':
  37861. this.commonObjs.resolve(id, data[2]);
  37862. break;
  37863. default:
  37864. error('Got unknown common object type ' + type);
  37865. }
  37866. }, this);
  37867. messageHandler.on('obj', function transportObj(data) {
  37868. if (this.destroyed) {
  37869. return; // Ignore any pending requests if the worker was terminated.
  37870. }
  37871. var id = data[0];
  37872. var pageIndex = data[1];
  37873. var type = data[2];
  37874. var pageProxy = this.pageCache[pageIndex];
  37875. var imageData;
  37876. if (pageProxy.objs.hasData(id)) {
  37877. return;
  37878. }
  37879. switch (type) {
  37880. case 'JpegStream':
  37881. imageData = data[3];
  37882. loadJpegStream(id, imageData, pageProxy.objs);
  37883. break;
  37884. case 'Image':
  37885. imageData = data[3];
  37886. pageProxy.objs.resolve(id, imageData);
  37887. // heuristics that will allow not to store large data
  37888. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  37889. if (imageData && 'data' in imageData &&
  37890. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  37891. pageProxy.cleanupAfterRender = true;
  37892. }
  37893. break;
  37894. default:
  37895. error('Got unknown object type ' + type);
  37896. }
  37897. }, this);
  37898. messageHandler.on('DocProgress', function transportDocProgress(data) {
  37899. if (this.destroyed) {
  37900. return; // Ignore any pending requests if the worker was terminated.
  37901. }
  37902. var loadingTask = this.loadingTask;
  37903. if (loadingTask.onProgress) {
  37904. loadingTask.onProgress({
  37905. loaded: data.loaded,
  37906. total: data.total
  37907. });
  37908. }
  37909. }, this);
  37910. messageHandler.on('PageError', function transportError(data) {
  37911. if (this.destroyed) {
  37912. return; // Ignore any pending requests if the worker was terminated.
  37913. }
  37914. var page = this.pageCache[data.pageNum - 1];
  37915. var intentState = page.intentStates[data.intent];
  37916. if (intentState.displayReadyCapability) {
  37917. intentState.displayReadyCapability.reject(data.error);
  37918. } else {
  37919. error(data.error);
  37920. }
  37921. if (intentState.operatorList) {
  37922. // Mark operator list as complete.
  37923. intentState.operatorList.lastChunk = true;
  37924. for (var i = 0; i < intentState.renderTasks.length; i++) {
  37925. intentState.renderTasks[i].operatorListChanged();
  37926. }
  37927. }
  37928. }, this);
  37929. messageHandler.on('UnsupportedFeature',
  37930. function transportUnsupportedFeature(data) {
  37931. if (this.destroyed) {
  37932. return; // Ignore any pending requests if the worker was terminated.
  37933. }
  37934. var featureId = data.featureId;
  37935. var loadingTask = this.loadingTask;
  37936. if (loadingTask.onUnsupportedFeature) {
  37937. loadingTask.onUnsupportedFeature(featureId);
  37938. }
  37939. _UnsupportedManager.notify(featureId);
  37940. }, this);
  37941. messageHandler.on('JpegDecode', function(data) {
  37942. if (this.destroyed) {
  37943. return Promise.reject(new Error('Worker was destroyed'));
  37944. }
  37945. var imageUrl = data[0];
  37946. var components = data[1];
  37947. if (components !== 3 && components !== 1) {
  37948. return Promise.reject(
  37949. new Error('Only 3 components or 1 component can be returned'));
  37950. }
  37951. return new Promise(function (resolve, reject) {
  37952. var img = new Image();
  37953. img.onload = function () {
  37954. var width = img.width;
  37955. var height = img.height;
  37956. var size = width * height;
  37957. var rgbaLength = size * 4;
  37958. var buf = new Uint8Array(size * components);
  37959. var tmpCanvas = createScratchCanvas(width, height);
  37960. var tmpCtx = tmpCanvas.getContext('2d');
  37961. tmpCtx.drawImage(img, 0, 0);
  37962. var data = tmpCtx.getImageData(0, 0, width, height).data;
  37963. var i, j;
  37964. if (components === 3) {
  37965. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  37966. buf[j] = data[i];
  37967. buf[j + 1] = data[i + 1];
  37968. buf[j + 2] = data[i + 2];
  37969. }
  37970. } else if (components === 1) {
  37971. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  37972. buf[j] = data[i];
  37973. }
  37974. }
  37975. resolve({ data: buf, width: width, height: height});
  37976. };
  37977. img.onerror = function () {
  37978. reject(new Error('JpegDecode failed to load image'));
  37979. };
  37980. img.src = imageUrl;
  37981. });
  37982. }, this);
  37983. },
  37984. getData: function WorkerTransport_getData() {
  37985. return this.messageHandler.sendWithPromise('GetData', null);
  37986. },
  37987. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  37988. if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  37989. return Promise.reject(new Error('Invalid page request'));
  37990. }
  37991. var pageIndex = pageNumber - 1;
  37992. if (pageIndex in this.pagePromises) {
  37993. return this.pagePromises[pageIndex];
  37994. }
  37995. var promise = this.messageHandler.sendWithPromise('GetPage', {
  37996. pageIndex: pageIndex
  37997. }).then(function (pageInfo) {
  37998. if (this.destroyed) {
  37999. throw new Error('Transport destroyed');
  38000. }
  38001. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  38002. this.pageCache[pageIndex] = page;
  38003. return page;
  38004. }.bind(this));
  38005. this.pagePromises[pageIndex] = promise;
  38006. return promise;
  38007. },
  38008. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  38009. return this.messageHandler.sendWithPromise('GetPageIndex', {
  38010. ref: ref,
  38011. }).catch(function (reason) {
  38012. return Promise.reject(new Error(reason));
  38013. });
  38014. },
  38015. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  38016. return this.messageHandler.sendWithPromise('GetAnnotations', {
  38017. pageIndex: pageIndex,
  38018. intent: intent,
  38019. });
  38020. },
  38021. getDestinations: function WorkerTransport_getDestinations() {
  38022. return this.messageHandler.sendWithPromise('GetDestinations', null);
  38023. },
  38024. getDestination: function WorkerTransport_getDestination(id) {
  38025. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  38026. },
  38027. getPageLabels: function WorkerTransport_getPageLabels() {
  38028. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  38029. },
  38030. getAttachments: function WorkerTransport_getAttachments() {
  38031. return this.messageHandler.sendWithPromise('GetAttachments', null);
  38032. },
  38033. getJavaScript: function WorkerTransport_getJavaScript() {
  38034. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  38035. },
  38036. getOutline: function WorkerTransport_getOutline() {
  38037. return this.messageHandler.sendWithPromise('GetOutline', null);
  38038. },
  38039. getMetadata: function WorkerTransport_getMetadata() {
  38040. return this.messageHandler.sendWithPromise('GetMetadata', null).
  38041. then(function transportMetadata(results) {
  38042. return {
  38043. info: results[0],
  38044. metadata: (results[1] ? new Metadata(results[1]) : null)
  38045. };
  38046. });
  38047. },
  38048. getStats: function WorkerTransport_getStats() {
  38049. return this.messageHandler.sendWithPromise('GetStats', null);
  38050. },
  38051. startCleanup: function WorkerTransport_startCleanup() {
  38052. this.messageHandler.sendWithPromise('Cleanup', null).
  38053. then(function endCleanup() {
  38054. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  38055. var page = this.pageCache[i];
  38056. if (page) {
  38057. page.cleanup();
  38058. }
  38059. }
  38060. this.commonObjs.clear();
  38061. this.fontLoader.clear();
  38062. }.bind(this));
  38063. }
  38064. };
  38065. return WorkerTransport;
  38066. })();
  38067. /**
  38068. * A PDF document and page is built of many objects. E.g. there are objects
  38069. * for fonts, images, rendering code and such. These objects might get processed
  38070. * inside of a worker. The `PDFObjects` implements some basic functions to
  38071. * manage these objects.
  38072. * @ignore
  38073. */
  38074. var PDFObjects = (function PDFObjectsClosure() {
  38075. function PDFObjects() {
  38076. this.objs = Object.create(null);
  38077. }
  38078. PDFObjects.prototype = {
  38079. /**
  38080. * Internal function.
  38081. * Ensures there is an object defined for `objId`.
  38082. */
  38083. ensureObj: function PDFObjects_ensureObj(objId) {
  38084. if (this.objs[objId]) {
  38085. return this.objs[objId];
  38086. }
  38087. var obj = {
  38088. capability: createPromiseCapability(),
  38089. data: null,
  38090. resolved: false
  38091. };
  38092. this.objs[objId] = obj;
  38093. return obj;
  38094. },
  38095. /**
  38096. * If called *without* callback, this returns the data of `objId` but the
  38097. * object needs to be resolved. If it isn't, this function throws.
  38098. *
  38099. * If called *with* a callback, the callback is called with the data of the
  38100. * object once the object is resolved. That means, if you call this
  38101. * function and the object is already resolved, the callback gets called
  38102. * right away.
  38103. */
  38104. get: function PDFObjects_get(objId, callback) {
  38105. // If there is a callback, then the get can be async and the object is
  38106. // not required to be resolved right now
  38107. if (callback) {
  38108. this.ensureObj(objId).capability.promise.then(callback);
  38109. return null;
  38110. }
  38111. // If there isn't a callback, the user expects to get the resolved data
  38112. // directly.
  38113. var obj = this.objs[objId];
  38114. // If there isn't an object yet or the object isn't resolved, then the
  38115. // data isn't ready yet!
  38116. if (!obj || !obj.resolved) {
  38117. error('Requesting object that isn\'t resolved yet ' + objId);
  38118. }
  38119. return obj.data;
  38120. },
  38121. /**
  38122. * Resolves the object `objId` with optional `data`.
  38123. */
  38124. resolve: function PDFObjects_resolve(objId, data) {
  38125. var obj = this.ensureObj(objId);
  38126. obj.resolved = true;
  38127. obj.data = data;
  38128. obj.capability.resolve(data);
  38129. },
  38130. isResolved: function PDFObjects_isResolved(objId) {
  38131. var objs = this.objs;
  38132. if (!objs[objId]) {
  38133. return false;
  38134. } else {
  38135. return objs[objId].resolved;
  38136. }
  38137. },
  38138. hasData: function PDFObjects_hasData(objId) {
  38139. return this.isResolved(objId);
  38140. },
  38141. /**
  38142. * Returns the data of `objId` if object exists, null otherwise.
  38143. */
  38144. getData: function PDFObjects_getData(objId) {
  38145. var objs = this.objs;
  38146. if (!objs[objId] || !objs[objId].resolved) {
  38147. return null;
  38148. } else {
  38149. return objs[objId].data;
  38150. }
  38151. },
  38152. clear: function PDFObjects_clear() {
  38153. this.objs = Object.create(null);
  38154. }
  38155. };
  38156. return PDFObjects;
  38157. })();
  38158. /**
  38159. * Allows controlling of the rendering tasks.
  38160. * @class
  38161. * @alias RenderTask
  38162. */
  38163. var RenderTask = (function RenderTaskClosure() {
  38164. function RenderTask(internalRenderTask) {
  38165. this._internalRenderTask = internalRenderTask;
  38166. /**
  38167. * Callback for incremental rendering -- a function that will be called
  38168. * each time the rendering is paused. To continue rendering call the
  38169. * function that is the first argument to the callback.
  38170. * @type {function}
  38171. */
  38172. this.onContinue = null;
  38173. }
  38174. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  38175. /**
  38176. * Promise for rendering task completion.
  38177. * @return {Promise}
  38178. */
  38179. get promise() {
  38180. return this._internalRenderTask.capability.promise;
  38181. },
  38182. /**
  38183. * Cancels the rendering task. If the task is currently rendering it will
  38184. * not be cancelled until graphics pauses with a timeout. The promise that
  38185. * this object extends will resolved when cancelled.
  38186. */
  38187. cancel: function RenderTask_cancel() {
  38188. this._internalRenderTask.cancel();
  38189. },
  38190. /**
  38191. * Registers callbacks to indicate the rendering task completion.
  38192. *
  38193. * @param {function} onFulfilled The callback for the rendering completion.
  38194. * @param {function} onRejected The callback for the rendering failure.
  38195. * @return {Promise} A promise that is resolved after the onFulfilled or
  38196. * onRejected callback.
  38197. */
  38198. then: function RenderTask_then(onFulfilled, onRejected) {
  38199. return this.promise.then.apply(this.promise, arguments);
  38200. }
  38201. };
  38202. return RenderTask;
  38203. })();
  38204. /**
  38205. * For internal use only.
  38206. * @ignore
  38207. */
  38208. var InternalRenderTask = (function InternalRenderTaskClosure() {
  38209. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  38210. pageNumber) {
  38211. this.callback = callback;
  38212. this.params = params;
  38213. this.objs = objs;
  38214. this.commonObjs = commonObjs;
  38215. this.operatorListIdx = null;
  38216. this.operatorList = operatorList;
  38217. this.pageNumber = pageNumber;
  38218. this.running = false;
  38219. this.graphicsReadyCallback = null;
  38220. this.graphicsReady = false;
  38221. this.useRequestAnimationFrame = false;
  38222. this.cancelled = false;
  38223. this.capability = createPromiseCapability();
  38224. this.task = new RenderTask(this);
  38225. // caching this-bound methods
  38226. this._continueBound = this._continue.bind(this);
  38227. this._scheduleNextBound = this._scheduleNext.bind(this);
  38228. this._nextBound = this._next.bind(this);
  38229. }
  38230. InternalRenderTask.prototype = {
  38231. initializeGraphics:
  38232. function InternalRenderTask_initializeGraphics(transparency) {
  38233. if (this.cancelled) {
  38234. return;
  38235. }
  38236. if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
  38237. globalScope.StepperManager.enabled) {
  38238. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  38239. this.stepper.init(this.operatorList);
  38240. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  38241. }
  38242. var params = this.params;
  38243. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  38244. this.objs, params.imageLayer);
  38245. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  38246. this.operatorListIdx = 0;
  38247. this.graphicsReady = true;
  38248. if (this.graphicsReadyCallback) {
  38249. this.graphicsReadyCallback();
  38250. }
  38251. },
  38252. cancel: function InternalRenderTask_cancel() {
  38253. this.running = false;
  38254. this.cancelled = true;
  38255. this.callback('cancelled');
  38256. },
  38257. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  38258. if (!this.graphicsReady) {
  38259. if (!this.graphicsReadyCallback) {
  38260. this.graphicsReadyCallback = this._continueBound;
  38261. }
  38262. return;
  38263. }
  38264. if (this.stepper) {
  38265. this.stepper.updateOperatorList(this.operatorList);
  38266. }
  38267. if (this.running) {
  38268. return;
  38269. }
  38270. this._continue();
  38271. },
  38272. _continue: function InternalRenderTask__continue() {
  38273. this.running = true;
  38274. if (this.cancelled) {
  38275. return;
  38276. }
  38277. if (this.task.onContinue) {
  38278. this.task.onContinue.call(this.task, this._scheduleNextBound);
  38279. } else {
  38280. this._scheduleNext();
  38281. }
  38282. },
  38283. _scheduleNext: function InternalRenderTask__scheduleNext() {
  38284. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  38285. window.requestAnimationFrame(this._nextBound);
  38286. } else {
  38287. Promise.resolve(undefined).then(this._nextBound);
  38288. }
  38289. },
  38290. _next: function InternalRenderTask__next() {
  38291. if (this.cancelled) {
  38292. return;
  38293. }
  38294. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  38295. this.operatorListIdx,
  38296. this._continueBound,
  38297. this.stepper);
  38298. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  38299. this.running = false;
  38300. if (this.operatorList.lastChunk) {
  38301. this.gfx.endDrawing();
  38302. this.callback();
  38303. }
  38304. }
  38305. }
  38306. };
  38307. return InternalRenderTask;
  38308. })();
  38309. /**
  38310. * (Deprecated) Global observer of unsupported feature usages. Use
  38311. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  38312. */
  38313. var _UnsupportedManager = (function UnsupportedManagerClosure() {
  38314. var listeners = [];
  38315. return {
  38316. listen: function (cb) {
  38317. deprecated('Global UnsupportedManager.listen is used: ' +
  38318. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  38319. listeners.push(cb);
  38320. },
  38321. notify: function (featureId) {
  38322. for (var i = 0, ii = listeners.length; i < ii; i++) {
  38323. listeners[i](featureId);
  38324. }
  38325. }
  38326. };
  38327. })();
  38328. if (typeof pdfjsVersion !== 'undefined') {
  38329. exports.version = pdfjsVersion;
  38330. }
  38331. if (typeof pdfjsBuild !== 'undefined') {
  38332. exports.build = pdfjsBuild;
  38333. }
  38334. exports.getDocument = getDocument;
  38335. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  38336. exports.PDFWorker = PDFWorker;
  38337. exports.PDFDocumentProxy = PDFDocumentProxy;
  38338. exports.PDFPageProxy = PDFPageProxy;
  38339. exports._UnsupportedManager = _UnsupportedManager;
  38340. }));
  38341. (function (root, factory) {
  38342. {
  38343. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38344. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  38345. }
  38346. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  38347. var error = sharedUtil.error;
  38348. var info = sharedUtil.info;
  38349. var isArray = sharedUtil.isArray;
  38350. var isString = sharedUtil.isString;
  38351. var shadow = sharedUtil.shadow;
  38352. var warn = sharedUtil.warn;
  38353. var isDict = corePrimitives.isDict;
  38354. var isName = corePrimitives.isName;
  38355. var isStream = corePrimitives.isStream;
  38356. var PDFFunction = coreFunction.PDFFunction;
  38357. var ColorSpace = (function ColorSpaceClosure() {
  38358. /**
  38359. * Resizes an RGB image with 3 components.
  38360. * @param {TypedArray} src - The source buffer.
  38361. * @param {Number} bpc - Number of bits per component.
  38362. * @param {Number} w1 - Original width.
  38363. * @param {Number} h1 - Original height.
  38364. * @param {Number} w2 - New width.
  38365. * @param {Number} h2 - New height.
  38366. * @param {Number} alpha01 - Size reserved for the alpha channel.
  38367. * @param {TypedArray} dest - The destination buffer.
  38368. */
  38369. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  38370. var COMPONENTS = 3;
  38371. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  38372. var xRatio = w1 / w2;
  38373. var yRatio = h1 / h2;
  38374. var i, j, py, newIndex = 0, oldIndex;
  38375. var xScaled = new Uint16Array(w2);
  38376. var w1Scanline = w1 * COMPONENTS;
  38377. for (i = 0; i < w2; i++) {
  38378. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  38379. }
  38380. for (i = 0; i < h2; i++) {
  38381. py = Math.floor(i * yRatio) * w1Scanline;
  38382. for (j = 0; j < w2; j++) {
  38383. oldIndex = py + xScaled[j];
  38384. dest[newIndex++] = src[oldIndex++];
  38385. dest[newIndex++] = src[oldIndex++];
  38386. dest[newIndex++] = src[oldIndex++];
  38387. newIndex += alpha01;
  38388. }
  38389. }
  38390. }
  38391. // Constructor should define this.numComps, this.defaultColor, this.name
  38392. function ColorSpace() {
  38393. error('should not call ColorSpace constructor');
  38394. }
  38395. ColorSpace.prototype = {
  38396. /**
  38397. * Converts the color value to the RGB color. The color components are
  38398. * located in the src array starting from the srcOffset. Returns the array
  38399. * of the rgb components, each value ranging from [0,255].
  38400. */
  38401. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38402. var rgb = new Uint8Array(3);
  38403. this.getRgbItem(src, srcOffset, rgb, 0);
  38404. return rgb;
  38405. },
  38406. /**
  38407. * Converts the color value to the RGB color, similar to the getRgb method.
  38408. * The result placed into the dest array starting from the destOffset.
  38409. */
  38410. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38411. dest, destOffset) {
  38412. error('Should not call ColorSpace.getRgbItem');
  38413. },
  38414. /**
  38415. * Converts the specified number of the color values to the RGB colors.
  38416. * The colors are located in the src array starting from the srcOffset.
  38417. * The result is placed into the dest array starting from the destOffset.
  38418. * The src array items shall be in [0,2^bits) range, the dest array items
  38419. * will be in [0,255] range. alpha01 indicates how many alpha components
  38420. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38421. * array).
  38422. */
  38423. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38424. dest, destOffset, bits,
  38425. alpha01) {
  38426. error('Should not call ColorSpace.getRgbBuffer');
  38427. },
  38428. /**
  38429. * Determines the number of bytes required to store the result of the
  38430. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38431. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38432. */
  38433. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38434. alpha01) {
  38435. error('Should not call ColorSpace.getOutputLength');
  38436. },
  38437. /**
  38438. * Returns true if source data will be equal the result/output data.
  38439. */
  38440. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38441. return false;
  38442. },
  38443. /**
  38444. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38445. * how many alpha components there are in the dest array; it will be either
  38446. * 0 (RGB array) or 1 (RGBA array).
  38447. */
  38448. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38449. originalHeight, width, height,
  38450. actualHeight, bpc, comps, alpha01) {
  38451. var count = originalWidth * originalHeight;
  38452. var rgbBuf = null;
  38453. var numComponentColors = 1 << bpc;
  38454. var needsResizing = originalHeight !== height || originalWidth !== width;
  38455. var i, ii;
  38456. if (this.isPassthrough(bpc)) {
  38457. rgbBuf = comps;
  38458. } else if (this.numComps === 1 && count > numComponentColors &&
  38459. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38460. // Optimization: create a color map when there is just one component and
  38461. // we are converting more colors than the size of the color map. We
  38462. // don't build the map if the colorspace is gray or rgb since those
  38463. // methods are faster than building a map. This mainly offers big speed
  38464. // ups for indexed and alternate colorspaces.
  38465. //
  38466. // TODO it may be worth while to cache the color map. While running
  38467. // testing I never hit a cache so I will leave that out for now (perhaps
  38468. // we are reparsing colorspaces too much?).
  38469. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38470. new Uint16Array(numComponentColors);
  38471. var key;
  38472. for (i = 0; i < numComponentColors; i++) {
  38473. allColors[i] = i;
  38474. }
  38475. var colorMap = new Uint8Array(numComponentColors * 3);
  38476. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38477. /* alpha01 = */ 0);
  38478. var destPos, rgbPos;
  38479. if (!needsResizing) {
  38480. // Fill in the RGB values directly into |dest|.
  38481. destPos = 0;
  38482. for (i = 0; i < count; ++i) {
  38483. key = comps[i] * 3;
  38484. dest[destPos++] = colorMap[key];
  38485. dest[destPos++] = colorMap[key + 1];
  38486. dest[destPos++] = colorMap[key + 2];
  38487. destPos += alpha01;
  38488. }
  38489. } else {
  38490. rgbBuf = new Uint8Array(count * 3);
  38491. rgbPos = 0;
  38492. for (i = 0; i < count; ++i) {
  38493. key = comps[i] * 3;
  38494. rgbBuf[rgbPos++] = colorMap[key];
  38495. rgbBuf[rgbPos++] = colorMap[key + 1];
  38496. rgbBuf[rgbPos++] = colorMap[key + 2];
  38497. }
  38498. }
  38499. } else {
  38500. if (!needsResizing) {
  38501. // Fill in the RGB values directly into |dest|.
  38502. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38503. alpha01);
  38504. } else {
  38505. rgbBuf = new Uint8Array(count * 3);
  38506. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38507. /* alpha01 = */ 0);
  38508. }
  38509. }
  38510. if (rgbBuf) {
  38511. if (needsResizing) {
  38512. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  38513. width, height, alpha01, dest);
  38514. } else {
  38515. rgbPos = 0;
  38516. destPos = 0;
  38517. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38518. dest[destPos++] = rgbBuf[rgbPos++];
  38519. dest[destPos++] = rgbBuf[rgbPos++];
  38520. dest[destPos++] = rgbBuf[rgbPos++];
  38521. destPos += alpha01;
  38522. }
  38523. }
  38524. }
  38525. },
  38526. /**
  38527. * True if the colorspace has components in the default range of [0, 1].
  38528. * This should be true for all colorspaces except for lab color spaces
  38529. * which are [0,100], [-128, 127], [-128, 127].
  38530. */
  38531. usesZeroToOneRange: true
  38532. };
  38533. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38534. var IR = ColorSpace.parseToIR(cs, xref, res);
  38535. if (IR instanceof AlternateCS) {
  38536. return IR;
  38537. }
  38538. return ColorSpace.fromIR(IR);
  38539. };
  38540. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38541. var name = isArray(IR) ? IR[0] : IR;
  38542. var whitePoint, blackPoint, gamma;
  38543. switch (name) {
  38544. case 'DeviceGrayCS':
  38545. return this.singletons.gray;
  38546. case 'DeviceRgbCS':
  38547. return this.singletons.rgb;
  38548. case 'DeviceCmykCS':
  38549. return this.singletons.cmyk;
  38550. case 'CalGrayCS':
  38551. whitePoint = IR[1];
  38552. blackPoint = IR[2];
  38553. gamma = IR[3];
  38554. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38555. case 'CalRGBCS':
  38556. whitePoint = IR[1];
  38557. blackPoint = IR[2];
  38558. gamma = IR[3];
  38559. var matrix = IR[4];
  38560. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38561. case 'PatternCS':
  38562. var basePatternCS = IR[1];
  38563. if (basePatternCS) {
  38564. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38565. }
  38566. return new PatternCS(basePatternCS);
  38567. case 'IndexedCS':
  38568. var baseIndexedCS = IR[1];
  38569. var hiVal = IR[2];
  38570. var lookup = IR[3];
  38571. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38572. case 'AlternateCS':
  38573. var numComps = IR[1];
  38574. var alt = IR[2];
  38575. var tintFnIR = IR[3];
  38576. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38577. PDFFunction.fromIR(tintFnIR));
  38578. case 'LabCS':
  38579. whitePoint = IR[1];
  38580. blackPoint = IR[2];
  38581. var range = IR[3];
  38582. return new LabCS(whitePoint, blackPoint, range);
  38583. default:
  38584. error('Unknown name ' + name);
  38585. }
  38586. return null;
  38587. };
  38588. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38589. if (isName(cs)) {
  38590. var colorSpaces = res.get('ColorSpace');
  38591. if (isDict(colorSpaces)) {
  38592. var refcs = colorSpaces.get(cs.name);
  38593. if (refcs) {
  38594. cs = refcs;
  38595. }
  38596. }
  38597. }
  38598. cs = xref.fetchIfRef(cs);
  38599. var mode;
  38600. if (isName(cs)) {
  38601. mode = cs.name;
  38602. this.mode = mode;
  38603. switch (mode) {
  38604. case 'DeviceGray':
  38605. case 'G':
  38606. return 'DeviceGrayCS';
  38607. case 'DeviceRGB':
  38608. case 'RGB':
  38609. return 'DeviceRgbCS';
  38610. case 'DeviceCMYK':
  38611. case 'CMYK':
  38612. return 'DeviceCmykCS';
  38613. case 'Pattern':
  38614. return ['PatternCS', null];
  38615. default:
  38616. error('unrecognized colorspace ' + mode);
  38617. }
  38618. } else if (isArray(cs)) {
  38619. mode = xref.fetchIfRef(cs[0]).name;
  38620. this.mode = mode;
  38621. var numComps, params, alt, whitePoint, blackPoint, gamma;
  38622. switch (mode) {
  38623. case 'DeviceGray':
  38624. case 'G':
  38625. return 'DeviceGrayCS';
  38626. case 'DeviceRGB':
  38627. case 'RGB':
  38628. return 'DeviceRgbCS';
  38629. case 'DeviceCMYK':
  38630. case 'CMYK':
  38631. return 'DeviceCmykCS';
  38632. case 'CalGray':
  38633. params = xref.fetchIfRef(cs[1]);
  38634. whitePoint = params.getArray('WhitePoint');
  38635. blackPoint = params.getArray('BlackPoint');
  38636. gamma = params.get('Gamma');
  38637. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38638. case 'CalRGB':
  38639. params = xref.fetchIfRef(cs[1]);
  38640. whitePoint = params.getArray('WhitePoint');
  38641. blackPoint = params.getArray('BlackPoint');
  38642. gamma = params.getArray('Gamma');
  38643. var matrix = params.getArray('Matrix');
  38644. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38645. case 'ICCBased':
  38646. var stream = xref.fetchIfRef(cs[1]);
  38647. var dict = stream.dict;
  38648. numComps = dict.get('N');
  38649. alt = dict.get('Alternate');
  38650. if (alt) {
  38651. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38652. // Parse the /Alternate CS to ensure that the number of components
  38653. // are correct, and also (indirectly) that it is not a PatternCS.
  38654. var altCS = ColorSpace.fromIR(altIR);
  38655. if (altCS.numComps === numComps) {
  38656. return altIR;
  38657. }
  38658. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38659. }
  38660. if (numComps === 1) {
  38661. return 'DeviceGrayCS';
  38662. } else if (numComps === 3) {
  38663. return 'DeviceRgbCS';
  38664. } else if (numComps === 4) {
  38665. return 'DeviceCmykCS';
  38666. }
  38667. break;
  38668. case 'Pattern':
  38669. var basePatternCS = cs[1] || null;
  38670. if (basePatternCS) {
  38671. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38672. }
  38673. return ['PatternCS', basePatternCS];
  38674. case 'Indexed':
  38675. case 'I':
  38676. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38677. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38678. var lookup = xref.fetchIfRef(cs[3]);
  38679. if (isStream(lookup)) {
  38680. lookup = lookup.getBytes();
  38681. }
  38682. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38683. case 'Separation':
  38684. case 'DeviceN':
  38685. var name = xref.fetchIfRef(cs[1]);
  38686. numComps = 1;
  38687. if (isName(name)) {
  38688. numComps = 1;
  38689. } else if (isArray(name)) {
  38690. numComps = name.length;
  38691. }
  38692. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38693. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38694. return ['AlternateCS', numComps, alt, tintFnIR];
  38695. case 'Lab':
  38696. params = xref.fetchIfRef(cs[1]);
  38697. whitePoint = params.getArray('WhitePoint');
  38698. blackPoint = params.getArray('BlackPoint');
  38699. var range = params.getArray('Range');
  38700. return ['LabCS', whitePoint, blackPoint, range];
  38701. default:
  38702. error('unimplemented color space object "' + mode + '"');
  38703. }
  38704. } else {
  38705. error('unrecognized color space object: "' + cs + '"');
  38706. }
  38707. return null;
  38708. };
  38709. /**
  38710. * Checks if a decode map matches the default decode map for a color space.
  38711. * This handles the general decode maps where there are two values per
  38712. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38713. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38714. * slightly different.
  38715. * @param {Array} decode Decode map (usually from an image).
  38716. * @param {Number} n Number of components the color space has.
  38717. */
  38718. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38719. if (!isArray(decode)) {
  38720. return true;
  38721. }
  38722. if (n * 2 !== decode.length) {
  38723. warn('The decode map is not the correct length');
  38724. return true;
  38725. }
  38726. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38727. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38728. return false;
  38729. }
  38730. }
  38731. return true;
  38732. };
  38733. ColorSpace.singletons = {
  38734. get gray() {
  38735. return shadow(this, 'gray', new DeviceGrayCS());
  38736. },
  38737. get rgb() {
  38738. return shadow(this, 'rgb', new DeviceRgbCS());
  38739. },
  38740. get cmyk() {
  38741. return shadow(this, 'cmyk', new DeviceCmykCS());
  38742. }
  38743. };
  38744. return ColorSpace;
  38745. })();
  38746. /**
  38747. * Alternate color space handles both Separation and DeviceN color spaces. A
  38748. * Separation color space is actually just a DeviceN with one color component.
  38749. * Both color spaces use a tinting function to convert colors to a base color
  38750. * space.
  38751. */
  38752. var AlternateCS = (function AlternateCSClosure() {
  38753. function AlternateCS(numComps, base, tintFn) {
  38754. this.name = 'Alternate';
  38755. this.numComps = numComps;
  38756. this.defaultColor = new Float32Array(numComps);
  38757. for (var i = 0; i < numComps; ++i) {
  38758. this.defaultColor[i] = 1;
  38759. }
  38760. this.base = base;
  38761. this.tintFn = tintFn;
  38762. this.tmpBuf = new Float32Array(base.numComps);
  38763. }
  38764. AlternateCS.prototype = {
  38765. getRgb: ColorSpace.prototype.getRgb,
  38766. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38767. dest, destOffset) {
  38768. var tmpBuf = this.tmpBuf;
  38769. this.tintFn(src, srcOffset, tmpBuf, 0);
  38770. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38771. },
  38772. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38773. dest, destOffset, bits,
  38774. alpha01) {
  38775. var tintFn = this.tintFn;
  38776. var base = this.base;
  38777. var scale = 1 / ((1 << bits) - 1);
  38778. var baseNumComps = base.numComps;
  38779. var usesZeroToOneRange = base.usesZeroToOneRange;
  38780. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38781. alpha01 === 0;
  38782. var pos = isPassthrough ? destOffset : 0;
  38783. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38784. var numComps = this.numComps;
  38785. var scaled = new Float32Array(numComps);
  38786. var tinted = new Float32Array(baseNumComps);
  38787. var i, j;
  38788. if (usesZeroToOneRange) {
  38789. for (i = 0; i < count; i++) {
  38790. for (j = 0; j < numComps; j++) {
  38791. scaled[j] = src[srcOffset++] * scale;
  38792. }
  38793. tintFn(scaled, 0, tinted, 0);
  38794. for (j = 0; j < baseNumComps; j++) {
  38795. baseBuf[pos++] = tinted[j] * 255;
  38796. }
  38797. }
  38798. } else {
  38799. for (i = 0; i < count; i++) {
  38800. for (j = 0; j < numComps; j++) {
  38801. scaled[j] = src[srcOffset++] * scale;
  38802. }
  38803. tintFn(scaled, 0, tinted, 0);
  38804. base.getRgbItem(tinted, 0, baseBuf, pos);
  38805. pos += baseNumComps;
  38806. }
  38807. }
  38808. if (!isPassthrough) {
  38809. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38810. }
  38811. },
  38812. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38813. alpha01) {
  38814. return this.base.getOutputLength(inputLength *
  38815. this.base.numComps / this.numComps,
  38816. alpha01);
  38817. },
  38818. isPassthrough: ColorSpace.prototype.isPassthrough,
  38819. fillRgb: ColorSpace.prototype.fillRgb,
  38820. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38821. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38822. },
  38823. usesZeroToOneRange: true
  38824. };
  38825. return AlternateCS;
  38826. })();
  38827. var PatternCS = (function PatternCSClosure() {
  38828. function PatternCS(baseCS) {
  38829. this.name = 'Pattern';
  38830. this.base = baseCS;
  38831. }
  38832. PatternCS.prototype = {};
  38833. return PatternCS;
  38834. })();
  38835. var IndexedCS = (function IndexedCSClosure() {
  38836. function IndexedCS(base, highVal, lookup) {
  38837. this.name = 'Indexed';
  38838. this.numComps = 1;
  38839. this.defaultColor = new Uint8Array([0]);
  38840. this.base = base;
  38841. this.highVal = highVal;
  38842. var baseNumComps = base.numComps;
  38843. var length = baseNumComps * highVal;
  38844. var lookupArray;
  38845. if (isStream(lookup)) {
  38846. lookupArray = new Uint8Array(length);
  38847. var bytes = lookup.getBytes(length);
  38848. lookupArray.set(bytes);
  38849. } else if (isString(lookup)) {
  38850. lookupArray = new Uint8Array(length);
  38851. for (var i = 0; i < length; ++i) {
  38852. lookupArray[i] = lookup.charCodeAt(i);
  38853. }
  38854. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38855. lookupArray = lookup;
  38856. } else {
  38857. error('Unrecognized lookup table: ' + lookup);
  38858. }
  38859. this.lookup = lookupArray;
  38860. }
  38861. IndexedCS.prototype = {
  38862. getRgb: ColorSpace.prototype.getRgb,
  38863. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38864. dest, destOffset) {
  38865. var numComps = this.base.numComps;
  38866. var start = src[srcOffset] * numComps;
  38867. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38868. },
  38869. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38870. dest, destOffset, bits,
  38871. alpha01) {
  38872. var base = this.base;
  38873. var numComps = base.numComps;
  38874. var outputDelta = base.getOutputLength(numComps, alpha01);
  38875. var lookup = this.lookup;
  38876. for (var i = 0; i < count; ++i) {
  38877. var lookupPos = src[srcOffset++] * numComps;
  38878. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38879. destOffset += outputDelta;
  38880. }
  38881. },
  38882. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38883. return this.base.getOutputLength(inputLength * this.base.numComps,
  38884. alpha01);
  38885. },
  38886. isPassthrough: ColorSpace.prototype.isPassthrough,
  38887. fillRgb: ColorSpace.prototype.fillRgb,
  38888. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38889. // indexed color maps shouldn't be changed
  38890. return true;
  38891. },
  38892. usesZeroToOneRange: true
  38893. };
  38894. return IndexedCS;
  38895. })();
  38896. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38897. function DeviceGrayCS() {
  38898. this.name = 'DeviceGray';
  38899. this.numComps = 1;
  38900. this.defaultColor = new Float32Array([0]);
  38901. }
  38902. DeviceGrayCS.prototype = {
  38903. getRgb: ColorSpace.prototype.getRgb,
  38904. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38905. dest, destOffset) {
  38906. var c = (src[srcOffset] * 255) | 0;
  38907. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38908. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38909. },
  38910. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38911. dest, destOffset, bits,
  38912. alpha01) {
  38913. var scale = 255 / ((1 << bits) - 1);
  38914. var j = srcOffset, q = destOffset;
  38915. for (var i = 0; i < count; ++i) {
  38916. var c = (scale * src[j++]) | 0;
  38917. dest[q++] = c;
  38918. dest[q++] = c;
  38919. dest[q++] = c;
  38920. q += alpha01;
  38921. }
  38922. },
  38923. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38924. alpha01) {
  38925. return inputLength * (3 + alpha01);
  38926. },
  38927. isPassthrough: ColorSpace.prototype.isPassthrough,
  38928. fillRgb: ColorSpace.prototype.fillRgb,
  38929. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38930. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38931. },
  38932. usesZeroToOneRange: true
  38933. };
  38934. return DeviceGrayCS;
  38935. })();
  38936. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38937. function DeviceRgbCS() {
  38938. this.name = 'DeviceRGB';
  38939. this.numComps = 3;
  38940. this.defaultColor = new Float32Array([0, 0, 0]);
  38941. }
  38942. DeviceRgbCS.prototype = {
  38943. getRgb: ColorSpace.prototype.getRgb,
  38944. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38945. dest, destOffset) {
  38946. var r = (src[srcOffset] * 255) | 0;
  38947. var g = (src[srcOffset + 1] * 255) | 0;
  38948. var b = (src[srcOffset + 2] * 255) | 0;
  38949. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38950. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38951. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38952. },
  38953. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38954. dest, destOffset, bits,
  38955. alpha01) {
  38956. if (bits === 8 && alpha01 === 0) {
  38957. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38958. return;
  38959. }
  38960. var scale = 255 / ((1 << bits) - 1);
  38961. var j = srcOffset, q = destOffset;
  38962. for (var i = 0; i < count; ++i) {
  38963. dest[q++] = (scale * src[j++]) | 0;
  38964. dest[q++] = (scale * src[j++]) | 0;
  38965. dest[q++] = (scale * src[j++]) | 0;
  38966. q += alpha01;
  38967. }
  38968. },
  38969. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38970. alpha01) {
  38971. return (inputLength * (3 + alpha01) / 3) | 0;
  38972. },
  38973. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38974. return bits === 8;
  38975. },
  38976. fillRgb: ColorSpace.prototype.fillRgb,
  38977. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38978. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38979. },
  38980. usesZeroToOneRange: true
  38981. };
  38982. return DeviceRgbCS;
  38983. })();
  38984. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38985. // The coefficients below was found using numerical analysis: the method of
  38986. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38987. // where color_value is the tabular value from the table of sampled RGB colors
  38988. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38989. // CMYK color conversion using the estimation below:
  38990. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38991. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38992. var c = src[srcOffset + 0] * srcScale;
  38993. var m = src[srcOffset + 1] * srcScale;
  38994. var y = src[srcOffset + 2] * srcScale;
  38995. var k = src[srcOffset + 3] * srcScale;
  38996. var r =
  38997. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38998. 18.82290502165302 * y + 212.25662451639585 * k +
  38999. -285.2331026137004) +
  39000. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  39001. -17.873870861415444 * k - 5.497006427196366) +
  39002. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39003. 17.5119270841813) +
  39004. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  39005. var g =
  39006. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  39007. 6.871425592049007 * y + 31.159100130055922 * k +
  39008. -79.2970844816548) +
  39009. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39010. 131.35250912493976 * k - 190.9453302588951) +
  39011. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  39012. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  39013. var b =
  39014. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39015. 30.89978309703729 * y - 0.23883238689178934 * k +
  39016. -14.183576799673286) +
  39017. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39018. 50.606957656360734 * k - 112.23884253719248) +
  39019. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  39020. -193.58209356861505) +
  39021. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  39022. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  39023. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  39024. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  39025. }
  39026. function DeviceCmykCS() {
  39027. this.name = 'DeviceCMYK';
  39028. this.numComps = 4;
  39029. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  39030. }
  39031. DeviceCmykCS.prototype = {
  39032. getRgb: ColorSpace.prototype.getRgb,
  39033. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  39034. dest, destOffset) {
  39035. convertToRgb(src, srcOffset, 1, dest, destOffset);
  39036. },
  39037. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  39038. dest, destOffset, bits,
  39039. alpha01) {
  39040. var scale = 1 / ((1 << bits) - 1);
  39041. for (var i = 0; i < count; i++) {
  39042. convertToRgb(src, srcOffset, scale, dest, destOffset);
  39043. srcOffset += 4;
  39044. destOffset += 3 + alpha01;
  39045. }
  39046. },
  39047. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  39048. alpha01) {
  39049. return (inputLength / 4 * (3 + alpha01)) | 0;
  39050. },
  39051. isPassthrough: ColorSpace.prototype.isPassthrough,
  39052. fillRgb: ColorSpace.prototype.fillRgb,
  39053. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  39054. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39055. },
  39056. usesZeroToOneRange: true
  39057. };
  39058. return DeviceCmykCS;
  39059. })();
  39060. //
  39061. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  39062. //
  39063. var CalGrayCS = (function CalGrayCSClosure() {
  39064. function CalGrayCS(whitePoint, blackPoint, gamma) {
  39065. this.name = 'CalGray';
  39066. this.numComps = 1;
  39067. this.defaultColor = new Float32Array([0]);
  39068. if (!whitePoint) {
  39069. error('WhitePoint missing - required for color space CalGray');
  39070. }
  39071. blackPoint = blackPoint || [0, 0, 0];
  39072. gamma = gamma || 1;
  39073. // Translate arguments to spec variables.
  39074. this.XW = whitePoint[0];
  39075. this.YW = whitePoint[1];
  39076. this.ZW = whitePoint[2];
  39077. this.XB = blackPoint[0];
  39078. this.YB = blackPoint[1];
  39079. this.ZB = blackPoint[2];
  39080. this.G = gamma;
  39081. // Validate variables as per spec.
  39082. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39083. error('Invalid WhitePoint components for ' + this.name +
  39084. ', no fallback available');
  39085. }
  39086. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39087. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  39088. this.XB = this.YB = this.ZB = 0;
  39089. }
  39090. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  39091. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  39092. ', ZB: ' + this.ZB + ', only default values are supported.');
  39093. }
  39094. if (this.G < 1) {
  39095. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  39096. ', falling back to default');
  39097. this.G = 1;
  39098. }
  39099. }
  39100. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39101. // A represents a gray component of a calibrated gray space.
  39102. // A <---> AG in the spec
  39103. var A = src[srcOffset] * scale;
  39104. var AG = Math.pow(A, cs.G);
  39105. // Computes L as per spec. ( = cs.YW * AG )
  39106. // Except if other than default BlackPoint values are used.
  39107. var L = cs.YW * AG;
  39108. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  39109. // Convert values to rgb range [0, 255].
  39110. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  39111. dest[destOffset] = val;
  39112. dest[destOffset + 1] = val;
  39113. dest[destOffset + 2] = val;
  39114. }
  39115. CalGrayCS.prototype = {
  39116. getRgb: ColorSpace.prototype.getRgb,
  39117. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  39118. dest, destOffset) {
  39119. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39120. },
  39121. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  39122. dest, destOffset, bits,
  39123. alpha01) {
  39124. var scale = 1 / ((1 << bits) - 1);
  39125. for (var i = 0; i < count; ++i) {
  39126. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39127. srcOffset += 1;
  39128. destOffset += 3 + alpha01;
  39129. }
  39130. },
  39131. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  39132. return inputLength * (3 + alpha01);
  39133. },
  39134. isPassthrough: ColorSpace.prototype.isPassthrough,
  39135. fillRgb: ColorSpace.prototype.fillRgb,
  39136. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  39137. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39138. },
  39139. usesZeroToOneRange: true
  39140. };
  39141. return CalGrayCS;
  39142. })();
  39143. //
  39144. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  39145. //
  39146. var CalRGBCS = (function CalRGBCSClosure() {
  39147. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  39148. // matrices.
  39149. var BRADFORD_SCALE_MATRIX = new Float32Array([
  39150. 0.8951, 0.2664, -0.1614,
  39151. -0.7502, 1.7135, 0.0367,
  39152. 0.0389, -0.0685, 1.0296]);
  39153. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  39154. 0.9869929, -0.1470543, 0.1599627,
  39155. 0.4323053, 0.5183603, 0.0492912,
  39156. -0.0085287, 0.0400428, 0.9684867]);
  39157. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  39158. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  39159. 3.2404542, -1.5371385, -0.4985314,
  39160. -0.9692660, 1.8760108, 0.0415560,
  39161. 0.0556434, -0.2040259, 1.0572252]);
  39162. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  39163. var tempNormalizeMatrix = new Float32Array(3);
  39164. var tempConvertMatrix1 = new Float32Array(3);
  39165. var tempConvertMatrix2 = new Float32Array(3);
  39166. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  39167. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  39168. this.name = 'CalRGB';
  39169. this.numComps = 3;
  39170. this.defaultColor = new Float32Array(3);
  39171. if (!whitePoint) {
  39172. error('WhitePoint missing - required for color space CalRGB');
  39173. }
  39174. blackPoint = blackPoint || new Float32Array(3);
  39175. gamma = gamma || new Float32Array([1, 1, 1]);
  39176. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  39177. // Translate arguments to spec variables.
  39178. var XW = whitePoint[0];
  39179. var YW = whitePoint[1];
  39180. var ZW = whitePoint[2];
  39181. this.whitePoint = whitePoint;
  39182. var XB = blackPoint[0];
  39183. var YB = blackPoint[1];
  39184. var ZB = blackPoint[2];
  39185. this.blackPoint = blackPoint;
  39186. this.GR = gamma[0];
  39187. this.GG = gamma[1];
  39188. this.GB = gamma[2];
  39189. this.MXA = matrix[0];
  39190. this.MYA = matrix[1];
  39191. this.MZA = matrix[2];
  39192. this.MXB = matrix[3];
  39193. this.MYB = matrix[4];
  39194. this.MZB = matrix[5];
  39195. this.MXC = matrix[6];
  39196. this.MYC = matrix[7];
  39197. this.MZC = matrix[8];
  39198. // Validate variables as per spec.
  39199. if (XW < 0 || ZW < 0 || YW !== 1) {
  39200. error('Invalid WhitePoint components for ' + this.name +
  39201. ', no fallback available');
  39202. }
  39203. if (XB < 0 || YB < 0 || ZB < 0) {
  39204. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  39205. ', ' + ZB + '], falling back to default');
  39206. this.blackPoint = new Float32Array(3);
  39207. }
  39208. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  39209. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  39210. '] for ' + this.name + ', falling back to default');
  39211. this.GR = this.GG = this.GB = 1;
  39212. }
  39213. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  39214. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  39215. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  39216. info('Invalid Matrix for ' + this.name + ' [' +
  39217. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  39218. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  39219. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  39220. '], falling back to default');
  39221. this.MXA = this.MYB = this.MZC = 1;
  39222. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  39223. }
  39224. }
  39225. function matrixProduct(a, b, result) {
  39226. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  39227. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  39228. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  39229. }
  39230. function convertToFlat(sourceWhitePoint, LMS, result) {
  39231. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  39232. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  39233. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  39234. }
  39235. function convertToD65(sourceWhitePoint, LMS, result) {
  39236. var D65X = 0.95047;
  39237. var D65Y = 1;
  39238. var D65Z = 1.08883;
  39239. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  39240. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  39241. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  39242. }
  39243. function sRGBTransferFunction(color) {
  39244. // See http://en.wikipedia.org/wiki/SRGB.
  39245. if (color <= 0.0031308){
  39246. return adjustToRange(0, 1, 12.92 * color);
  39247. }
  39248. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  39249. }
  39250. function adjustToRange(min, max, value) {
  39251. return Math.max(min, Math.min(max, value));
  39252. }
  39253. function decodeL(L) {
  39254. if (L < 0) {
  39255. return -decodeL(-L);
  39256. }
  39257. if (L > 8.0) {
  39258. return Math.pow(((L + 16) / 116), 3);
  39259. }
  39260. return L * DECODE_L_CONSTANT;
  39261. }
  39262. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  39263. // In case the blackPoint is already the default blackPoint then there is
  39264. // no need to do compensation.
  39265. if (sourceBlackPoint[0] === 0 &&
  39266. sourceBlackPoint[1] === 0 &&
  39267. sourceBlackPoint[2] === 0) {
  39268. result[0] = XYZ_Flat[0];
  39269. result[1] = XYZ_Flat[1];
  39270. result[2] = XYZ_Flat[2];
  39271. return;
  39272. }
  39273. // For the blackPoint calculation details, please see
  39274. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39275. // AdobeBPC.pdf.
  39276. // The destination blackPoint is the default blackPoint [0, 0, 0].
  39277. var zeroDecodeL = decodeL(0);
  39278. var X_DST = zeroDecodeL;
  39279. var X_SRC = decodeL(sourceBlackPoint[0]);
  39280. var Y_DST = zeroDecodeL;
  39281. var Y_SRC = decodeL(sourceBlackPoint[1]);
  39282. var Z_DST = zeroDecodeL;
  39283. var Z_SRC = decodeL(sourceBlackPoint[2]);
  39284. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  39285. var X_Offset = 1 - X_Scale;
  39286. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  39287. var Y_Offset = 1 - Y_Scale;
  39288. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  39289. var Z_Offset = 1 - Z_Scale;
  39290. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  39291. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  39292. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  39293. }
  39294. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  39295. // In case the whitePoint is already flat then there is no need to do
  39296. // normalization.
  39297. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  39298. result[0] = XYZ_In[0];
  39299. result[1] = XYZ_In[1];
  39300. result[2] = XYZ_In[2];
  39301. return;
  39302. }
  39303. var LMS = result;
  39304. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39305. var LMS_Flat = tempNormalizeMatrix;
  39306. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  39307. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  39308. }
  39309. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  39310. var LMS = result;
  39311. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39312. var LMS_D65 = tempNormalizeMatrix;
  39313. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  39314. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  39315. }
  39316. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39317. // A, B and C represent a red, green and blue components of a calibrated
  39318. // rgb space.
  39319. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  39320. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  39321. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  39322. // A <---> AGR in the spec
  39323. // B <---> BGG in the spec
  39324. // C <---> CGB in the spec
  39325. var AGR = Math.pow(A, cs.GR);
  39326. var BGG = Math.pow(B, cs.GG);
  39327. var CGB = Math.pow(C, cs.GB);
  39328. // Computes intermediate variables L, M, N as per spec.
  39329. // To decode X, Y, Z values map L, M, N directly to them.
  39330. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  39331. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  39332. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  39333. // The following calculations are based on this document:
  39334. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39335. // AdobeBPC.pdf.
  39336. var XYZ = tempConvertMatrix1;
  39337. XYZ[0] = X;
  39338. XYZ[1] = Y;
  39339. XYZ[2] = Z;
  39340. var XYZ_Flat = tempConvertMatrix2;
  39341. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  39342. var XYZ_Black = tempConvertMatrix1;
  39343. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  39344. var XYZ_D65 = tempConvertMatrix2;
  39345. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  39346. var SRGB = tempConvertMatrix1;
  39347. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  39348. var sR = sRGBTransferFunction(SRGB[0]);
  39349. var sG = sRGBTransferFunction(SRGB[1]);
  39350. var sB = sRGBTransferFunction(SRGB[2]);
  39351. // Convert the values to rgb range [0, 255].
  39352. dest[destOffset] = Math.round(sR * 255);
  39353. dest[destOffset + 1] = Math.round(sG * 255);
  39354. dest[destOffset + 2] = Math.round(sB * 255);
  39355. }
  39356. CalRGBCS.prototype = {
  39357. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39358. var rgb = new Uint8Array(3);
  39359. this.getRgbItem(src, srcOffset, rgb, 0);
  39360. return rgb;
  39361. },
  39362. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39363. dest, destOffset) {
  39364. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39365. },
  39366. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39367. dest, destOffset, bits,
  39368. alpha01) {
  39369. var scale = 1 / ((1 << bits) - 1);
  39370. for (var i = 0; i < count; ++i) {
  39371. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39372. srcOffset += 3;
  39373. destOffset += 3 + alpha01;
  39374. }
  39375. },
  39376. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39377. return (inputLength * (3 + alpha01) / 3) | 0;
  39378. },
  39379. isPassthrough: ColorSpace.prototype.isPassthrough,
  39380. fillRgb: ColorSpace.prototype.fillRgb,
  39381. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39382. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39383. },
  39384. usesZeroToOneRange: true
  39385. };
  39386. return CalRGBCS;
  39387. })();
  39388. //
  39389. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39390. //
  39391. var LabCS = (function LabCSClosure() {
  39392. function LabCS(whitePoint, blackPoint, range) {
  39393. this.name = 'Lab';
  39394. this.numComps = 3;
  39395. this.defaultColor = new Float32Array([0, 0, 0]);
  39396. if (!whitePoint) {
  39397. error('WhitePoint missing - required for color space Lab');
  39398. }
  39399. blackPoint = blackPoint || [0, 0, 0];
  39400. range = range || [-100, 100, -100, 100];
  39401. // Translate args to spec variables
  39402. this.XW = whitePoint[0];
  39403. this.YW = whitePoint[1];
  39404. this.ZW = whitePoint[2];
  39405. this.amin = range[0];
  39406. this.amax = range[1];
  39407. this.bmin = range[2];
  39408. this.bmax = range[3];
  39409. // These are here just for completeness - the spec doesn't offer any
  39410. // formulas that use BlackPoint in Lab
  39411. this.XB = blackPoint[0];
  39412. this.YB = blackPoint[1];
  39413. this.ZB = blackPoint[2];
  39414. // Validate vars as per spec
  39415. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39416. error('Invalid WhitePoint components, no fallback available');
  39417. }
  39418. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39419. info('Invalid BlackPoint, falling back to default');
  39420. this.XB = this.YB = this.ZB = 0;
  39421. }
  39422. if (this.amin > this.amax || this.bmin > this.bmax) {
  39423. info('Invalid Range, falling back to defaults');
  39424. this.amin = -100;
  39425. this.amax = 100;
  39426. this.bmin = -100;
  39427. this.bmax = 100;
  39428. }
  39429. }
  39430. // Function g(x) from spec
  39431. function fn_g(x) {
  39432. if (x >= 6 / 29) {
  39433. return x * x * x;
  39434. } else {
  39435. return (108 / 841) * (x - 4 / 29);
  39436. }
  39437. }
  39438. function decode(value, high1, low2, high2) {
  39439. return low2 + (value) * (high2 - low2) / (high1);
  39440. }
  39441. // If decoding is needed maxVal should be 2^bits per component - 1.
  39442. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39443. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39444. // not the usual [0, 1]. If a command like setFillColor is used the src
  39445. // values will already be within the correct range. However, if we are
  39446. // converting an image we have to map the values to the correct range given
  39447. // above.
  39448. // Ls,as,bs <---> L*,a*,b* in the spec
  39449. var Ls = src[srcOffset];
  39450. var as = src[srcOffset + 1];
  39451. var bs = src[srcOffset + 2];
  39452. if (maxVal !== false) {
  39453. Ls = decode(Ls, maxVal, 0, 100);
  39454. as = decode(as, maxVal, cs.amin, cs.amax);
  39455. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39456. }
  39457. // Adjust limits of 'as' and 'bs'
  39458. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39459. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39460. // Computes intermediate variables X,Y,Z as per spec
  39461. var M = (Ls + 16) / 116;
  39462. var L = M + (as / 500);
  39463. var N = M - (bs / 200);
  39464. var X = cs.XW * fn_g(L);
  39465. var Y = cs.YW * fn_g(M);
  39466. var Z = cs.ZW * fn_g(N);
  39467. var r, g, b;
  39468. // Using different conversions for D50 and D65 white points,
  39469. // per http://www.color.org/srgb.pdf
  39470. if (cs.ZW < 1) {
  39471. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39472. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39473. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39474. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39475. } else {
  39476. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39477. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39478. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39479. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39480. }
  39481. // clamp color values to [0,1] range then convert to [0,255] range.
  39482. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39483. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39484. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39485. }
  39486. LabCS.prototype = {
  39487. getRgb: ColorSpace.prototype.getRgb,
  39488. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39489. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39490. },
  39491. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39492. dest, destOffset, bits,
  39493. alpha01) {
  39494. var maxVal = (1 << bits) - 1;
  39495. for (var i = 0; i < count; i++) {
  39496. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39497. srcOffset += 3;
  39498. destOffset += 3 + alpha01;
  39499. }
  39500. },
  39501. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39502. return (inputLength * (3 + alpha01) / 3) | 0;
  39503. },
  39504. isPassthrough: ColorSpace.prototype.isPassthrough,
  39505. fillRgb: ColorSpace.prototype.fillRgb,
  39506. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39507. // XXX: Decoding is handled with the lab conversion because of the strange
  39508. // ranges that are used.
  39509. return true;
  39510. },
  39511. usesZeroToOneRange: false
  39512. };
  39513. return LabCS;
  39514. })();
  39515. exports.ColorSpace = ColorSpace;
  39516. }));
  39517. (function (root, factory) {
  39518. {
  39519. factory((root.pdfjsDisplayGlobal = {}), root.pdfjsSharedUtil,
  39520. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI,
  39521. root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer,
  39522. root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  39523. }
  39524. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI,
  39525. displayAnnotationLayer, displayTextLayer, displayMetadata,
  39526. displaySVG) {
  39527. var globalScope = sharedUtil.globalScope;
  39528. var deprecated = sharedUtil.deprecated;
  39529. var warn = sharedUtil.warn;
  39530. var LinkTarget = displayDOMUtils.LinkTarget;
  39531. var isWorker = (typeof window === 'undefined');
  39532. // The global PDFJS object is now deprecated and will not be supported in
  39533. // the future. The members below are maintained for backward compatibility
  39534. // and shall not be extended or modified. If the global.js is included as
  39535. // a module, we will create a global PDFJS object instance or use existing.
  39536. if (!globalScope.PDFJS) {
  39537. globalScope.PDFJS = {};
  39538. }
  39539. var PDFJS = globalScope.PDFJS;
  39540. if (typeof pdfjsVersion !== 'undefined') {
  39541. PDFJS.version = pdfjsVersion;
  39542. }
  39543. if (typeof pdfjsBuild !== 'undefined') {
  39544. PDFJS.build = pdfjsBuild;
  39545. }
  39546. PDFJS.pdfBug = false;
  39547. if (PDFJS.verbosity !== undefined) {
  39548. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  39549. }
  39550. delete PDFJS.verbosity;
  39551. Object.defineProperty(PDFJS, 'verbosity', {
  39552. get: function () { return sharedUtil.getVerbosityLevel(); },
  39553. set: function (level) { sharedUtil.setVerbosityLevel(level); },
  39554. enumerable: true,
  39555. configurable: true
  39556. });
  39557. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  39558. PDFJS.OPS = sharedUtil.OPS;
  39559. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39560. PDFJS.isValidUrl = sharedUtil.isValidUrl;
  39561. PDFJS.shadow = sharedUtil.shadow;
  39562. PDFJS.createBlob = sharedUtil.createBlob;
  39563. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  39564. return sharedUtil.createObjectURL(data, contentType,
  39565. PDFJS.disableCreateObjectURL);
  39566. };
  39567. Object.defineProperty(PDFJS, 'isLittleEndian', {
  39568. configurable: true,
  39569. get: function PDFJS_isLittleEndian() {
  39570. var value = sharedUtil.isLittleEndian();
  39571. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  39572. }
  39573. });
  39574. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  39575. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  39576. PDFJS.PasswordException = sharedUtil.PasswordException;
  39577. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  39578. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  39579. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  39580. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39581. PDFJS.Util = sharedUtil.Util;
  39582. PDFJS.PageViewport = sharedUtil.PageViewport;
  39583. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  39584. /**
  39585. * The maximum allowed image size in total pixels e.g. width * height. Images
  39586. * above this value will not be drawn. Use -1 for no limit.
  39587. * @var {number}
  39588. */
  39589. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  39590. -1 : PDFJS.maxImageSize);
  39591. /**
  39592. * The url of where the predefined Adobe CMaps are located. Include trailing
  39593. * slash.
  39594. * @var {string}
  39595. */
  39596. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  39597. /**
  39598. * Specifies if CMaps are binary packed.
  39599. * @var {boolean}
  39600. */
  39601. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  39602. /**
  39603. * By default fonts are converted to OpenType fonts and loaded via font face
  39604. * rules. If disabled, the font will be rendered using a built in font
  39605. * renderer that constructs the glyphs with primitive path commands.
  39606. * @var {boolean}
  39607. */
  39608. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  39609. false : PDFJS.disableFontFace);
  39610. /**
  39611. * Path for image resources, mainly for annotation icons. Include trailing
  39612. * slash.
  39613. * @var {string}
  39614. */
  39615. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  39616. '' : PDFJS.imageResourcesPath);
  39617. /**
  39618. * Disable the web worker and run all code on the main thread. This will
  39619. * happen automatically if the browser doesn't support workers or sending
  39620. * typed arrays to workers.
  39621. * @var {boolean}
  39622. */
  39623. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  39624. false : PDFJS.disableWorker);
  39625. /**
  39626. * Path and filename of the worker file. Required when the worker is enabled
  39627. * in development mode. If unspecified in the production build, the worker
  39628. * will be loaded based on the location of the pdf.js file. It is recommended
  39629. * that the workerSrc is set in a custom application to prevent issues caused
  39630. * by third-party frameworks and libraries.
  39631. * @var {string}
  39632. */
  39633. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  39634. /**
  39635. * Disable range request loading of PDF files. When enabled and if the server
  39636. * supports partial content requests then the PDF will be fetched in chunks.
  39637. * Enabled (false) by default.
  39638. * @var {boolean}
  39639. */
  39640. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  39641. false : PDFJS.disableRange);
  39642. /**
  39643. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  39644. * in chunks. This default behavior can be disabled.
  39645. * @var {boolean}
  39646. */
  39647. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  39648. false : PDFJS.disableStream);
  39649. /**
  39650. * Disable pre-fetching of PDF file data. When range requests are enabled
  39651. * PDF.js will automatically keep fetching more data even if it isn't needed
  39652. * to display the current page. This default behavior can be disabled.
  39653. *
  39654. * NOTE: It is also necessary to disable streaming, see above,
  39655. * in order for disabling of pre-fetching to work correctly.
  39656. * @var {boolean}
  39657. */
  39658. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  39659. false : PDFJS.disableAutoFetch);
  39660. /**
  39661. * Enables special hooks for debugging PDF.js.
  39662. * @var {boolean}
  39663. */
  39664. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  39665. /**
  39666. * Enables transfer usage in postMessage for ArrayBuffers.
  39667. * @var {boolean}
  39668. */
  39669. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  39670. true : PDFJS.postMessageTransfers);
  39671. /**
  39672. * Disables URL.createObjectURL usage.
  39673. * @var {boolean}
  39674. */
  39675. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  39676. false : PDFJS.disableCreateObjectURL);
  39677. /**
  39678. * Disables WebGL usage.
  39679. * @var {boolean}
  39680. */
  39681. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  39682. true : PDFJS.disableWebGL);
  39683. /**
  39684. * Specifies the |target| attribute for external links.
  39685. * The constants from PDFJS.LinkTarget should be used:
  39686. * - NONE [default]
  39687. * - SELF
  39688. * - BLANK
  39689. * - PARENT
  39690. * - TOP
  39691. * @var {number}
  39692. */
  39693. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  39694. LinkTarget.NONE : PDFJS.externalLinkTarget);
  39695. /**
  39696. * Specifies the |rel| attribute for external links. Defaults to stripping
  39697. * the referrer.
  39698. * @var {string}
  39699. */
  39700. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  39701. 'noreferrer' : PDFJS.externalLinkRel);
  39702. /**
  39703. * Determines if we can eval strings as JS. Primarily used to improve
  39704. * performance for font rendering.
  39705. * @var {boolean}
  39706. */
  39707. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  39708. true : PDFJS.isEvalSupported);
  39709. /**
  39710. * Renders interactive form elements.
  39711. * @var {boolean}
  39712. */
  39713. PDFJS.renderInteractiveForms = (PDFJS.renderInteractiveForms === undefined ?
  39714. false : PDFJS.renderInteractiveForms);
  39715. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  39716. delete PDFJS.openExternalLinksInNewWindow;
  39717. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  39718. get: function () {
  39719. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  39720. },
  39721. set: function (value) {
  39722. if (value) {
  39723. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  39724. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  39725. }
  39726. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  39727. warn('PDFJS.externalLinkTarget is already initialized');
  39728. return;
  39729. }
  39730. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  39731. },
  39732. enumerable: true,
  39733. configurable: true
  39734. });
  39735. if (savedOpenExternalLinksInNewWindow) {
  39736. /**
  39737. * (Deprecated) Opens external links in a new window if enabled.
  39738. * The default behavior opens external links in the PDF.js window.
  39739. *
  39740. * NOTE: This property has been deprecated, please use
  39741. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  39742. * @var {boolean}
  39743. */
  39744. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  39745. }
  39746. PDFJS.getDocument = displayAPI.getDocument;
  39747. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  39748. PDFJS.PDFWorker = displayAPI.PDFWorker;
  39749. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  39750. configurable: true,
  39751. get: function PDFJS_hasCanvasTypedArrays() {
  39752. var value = displayDOMUtils.hasCanvasTypedArrays();
  39753. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  39754. }
  39755. });
  39756. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  39757. PDFJS.LinkTarget = LinkTarget;
  39758. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  39759. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  39760. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  39761. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  39762. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  39763. PDFJS.Metadata = displayMetadata.Metadata;
  39764. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  39765. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  39766. exports.globalScope = globalScope;
  39767. exports.isWorker = isWorker;
  39768. exports.PDFJS = globalScope.PDFJS;
  39769. }));
  39770. (function (root, factory) {
  39771. {
  39772. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39773. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39774. root.pdfjsCoreJpx);
  39775. }
  39776. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39777. coreStream, coreJpx) {
  39778. var ImageKind = sharedUtil.ImageKind;
  39779. var assert = sharedUtil.assert;
  39780. var error = sharedUtil.error;
  39781. var info = sharedUtil.info;
  39782. var isArray = sharedUtil.isArray;
  39783. var warn = sharedUtil.warn;
  39784. var Name = corePrimitives.Name;
  39785. var isStream = corePrimitives.isStream;
  39786. var ColorSpace = coreColorSpace.ColorSpace;
  39787. var DecodeStream = coreStream.DecodeStream;
  39788. var JpegStream = coreStream.JpegStream;
  39789. var JpxImage = coreJpx.JpxImage;
  39790. var PDFImage = (function PDFImageClosure() {
  39791. /**
  39792. * Decodes the image using native decoder if possible. Resolves the promise
  39793. * when the image data is ready.
  39794. */
  39795. function handleImageData(image, nativeDecoder) {
  39796. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  39797. return nativeDecoder.decode(image);
  39798. } else {
  39799. return Promise.resolve(image);
  39800. }
  39801. }
  39802. /**
  39803. * Decode and clamp a value. The formula is different from the spec because we
  39804. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39805. */
  39806. function decodeAndClamp(value, addend, coefficient, max) {
  39807. value = addend + value * coefficient;
  39808. // Clamp the value to the range
  39809. return (value < 0 ? 0 : (value > max ? max : value));
  39810. }
  39811. /**
  39812. * Resizes an image mask with 1 component.
  39813. * @param {TypedArray} src - The source buffer.
  39814. * @param {Number} bpc - Number of bits per component.
  39815. * @param {Number} w1 - Original width.
  39816. * @param {Number} h1 - Original height.
  39817. * @param {Number} w2 - New width.
  39818. * @param {Number} h2 - New height.
  39819. * @returns {TypedArray} The resized image mask buffer.
  39820. */
  39821. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  39822. var length = w2 * h2;
  39823. var dest = (bpc <= 8 ? new Uint8Array(length) :
  39824. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39825. var xRatio = w1 / w2;
  39826. var yRatio = h1 / h2;
  39827. var i, j, py, newIndex = 0, oldIndex;
  39828. var xScaled = new Uint16Array(w2);
  39829. var w1Scanline = w1;
  39830. for (i = 0; i < w2; i++) {
  39831. xScaled[i] = Math.floor(i * xRatio);
  39832. }
  39833. for (i = 0; i < h2; i++) {
  39834. py = Math.floor(i * yRatio) * w1Scanline;
  39835. for (j = 0; j < w2; j++) {
  39836. oldIndex = py + xScaled[j];
  39837. dest[newIndex++] = src[oldIndex];
  39838. }
  39839. }
  39840. return dest;
  39841. }
  39842. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39843. this.image = image;
  39844. var dict = image.dict;
  39845. if (dict.has('Filter')) {
  39846. var filter = dict.get('Filter').name;
  39847. if (filter === 'JPXDecode') {
  39848. var jpxImage = new JpxImage();
  39849. jpxImage.parseImageProperties(image.stream);
  39850. image.stream.reset();
  39851. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39852. image.numComps = jpxImage.componentsCount;
  39853. } else if (filter === 'JBIG2Decode') {
  39854. image.bitsPerComponent = 1;
  39855. image.numComps = 1;
  39856. }
  39857. }
  39858. // TODO cache rendered images?
  39859. this.width = dict.get('Width', 'W');
  39860. this.height = dict.get('Height', 'H');
  39861. if (this.width < 1 || this.height < 1) {
  39862. error('Invalid image width: ' + this.width + ' or height: ' +
  39863. this.height);
  39864. }
  39865. this.interpolate = dict.get('Interpolate', 'I') || false;
  39866. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39867. this.matte = dict.get('Matte') || false;
  39868. var bitsPerComponent = image.bitsPerComponent;
  39869. if (!bitsPerComponent) {
  39870. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39871. if (!bitsPerComponent) {
  39872. if (this.imageMask) {
  39873. bitsPerComponent = 1;
  39874. } else {
  39875. error('Bits per component missing in image: ' + this.imageMask);
  39876. }
  39877. }
  39878. }
  39879. this.bpc = bitsPerComponent;
  39880. if (!this.imageMask) {
  39881. var colorSpace = dict.get('ColorSpace', 'CS');
  39882. if (!colorSpace) {
  39883. info('JPX images (which do not require color spaces)');
  39884. switch (image.numComps) {
  39885. case 1:
  39886. colorSpace = Name.get('DeviceGray');
  39887. break;
  39888. case 3:
  39889. colorSpace = Name.get('DeviceRGB');
  39890. break;
  39891. case 4:
  39892. colorSpace = Name.get('DeviceCMYK');
  39893. break;
  39894. default:
  39895. error('JPX images with ' + this.numComps +
  39896. ' color components not supported.');
  39897. }
  39898. }
  39899. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39900. this.numComps = this.colorSpace.numComps;
  39901. }
  39902. this.decode = dict.getArray('Decode', 'D');
  39903. this.needsDecode = false;
  39904. if (this.decode &&
  39905. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39906. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39907. this.needsDecode = true;
  39908. // Do some preprocessing to avoid more math.
  39909. var max = (1 << bitsPerComponent) - 1;
  39910. this.decodeCoefficients = [];
  39911. this.decodeAddends = [];
  39912. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39913. var dmin = this.decode[i];
  39914. var dmax = this.decode[i + 1];
  39915. this.decodeCoefficients[j] = dmax - dmin;
  39916. this.decodeAddends[j] = max * dmin;
  39917. }
  39918. }
  39919. if (smask) {
  39920. this.smask = new PDFImage(xref, res, smask, false);
  39921. } else if (mask) {
  39922. if (isStream(mask)) {
  39923. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39924. if (!imageMask) {
  39925. warn('Ignoring /Mask in image without /ImageMask.');
  39926. } else {
  39927. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39928. }
  39929. } else {
  39930. // Color key mask (just an array).
  39931. this.mask = mask;
  39932. }
  39933. }
  39934. }
  39935. /**
  39936. * Handles processing of image data and returns the Promise that is resolved
  39937. * with a PDFImage when the image is ready to be used.
  39938. */
  39939. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39940. res, image, inline,
  39941. nativeDecoder) {
  39942. var imagePromise = handleImageData(image, nativeDecoder);
  39943. var smaskPromise;
  39944. var maskPromise;
  39945. var smask = image.dict.get('SMask');
  39946. var mask = image.dict.get('Mask');
  39947. if (smask) {
  39948. smaskPromise = handleImageData(smask, nativeDecoder);
  39949. maskPromise = Promise.resolve(null);
  39950. } else {
  39951. smaskPromise = Promise.resolve(null);
  39952. if (mask) {
  39953. if (isStream(mask)) {
  39954. maskPromise = handleImageData(mask, nativeDecoder);
  39955. } else if (isArray(mask)) {
  39956. maskPromise = Promise.resolve(mask);
  39957. } else {
  39958. warn('Unsupported mask format.');
  39959. maskPromise = Promise.resolve(null);
  39960. }
  39961. } else {
  39962. maskPromise = Promise.resolve(null);
  39963. }
  39964. }
  39965. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39966. function(results) {
  39967. var imageData = results[0];
  39968. var smaskData = results[1];
  39969. var maskData = results[2];
  39970. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39971. });
  39972. };
  39973. PDFImage.createMask =
  39974. function PDFImage_createMask(imgArray, width, height,
  39975. imageIsFromDecodeStream, inverseDecode) {
  39976. // |imgArray| might not contain full data for every pixel of the mask, so
  39977. // we need to distinguish between |computedLength| and |actualLength|.
  39978. // In particular, if inverseDecode is true, then the array we return must
  39979. // have a length of |computedLength|.
  39980. var computedLength = ((width + 7) >> 3) * height;
  39981. var actualLength = imgArray.byteLength;
  39982. var haveFullData = computedLength === actualLength;
  39983. var data, i;
  39984. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39985. // imgArray came from a DecodeStream and its data is in an appropriate
  39986. // form, so we can just transfer it.
  39987. data = imgArray;
  39988. } else if (!inverseDecode) {
  39989. data = new Uint8Array(actualLength);
  39990. data.set(imgArray);
  39991. } else {
  39992. data = new Uint8Array(computedLength);
  39993. data.set(imgArray);
  39994. for (i = actualLength; i < computedLength; i++) {
  39995. data[i] = 0xff;
  39996. }
  39997. }
  39998. // If necessary, invert the original mask data (but not any extra we might
  39999. // have added above). It's safe to modify the array -- whether it's the
  40000. // original or a copy, we're about to transfer it anyway, so nothing else
  40001. // in this thread can be relying on its contents.
  40002. if (inverseDecode) {
  40003. for (i = 0; i < actualLength; i++) {
  40004. data[i] = ~data[i];
  40005. }
  40006. }
  40007. return {data: data, width: width, height: height};
  40008. };
  40009. PDFImage.prototype = {
  40010. get drawWidth() {
  40011. return Math.max(this.width,
  40012. this.smask && this.smask.width || 0,
  40013. this.mask && this.mask.width || 0);
  40014. },
  40015. get drawHeight() {
  40016. return Math.max(this.height,
  40017. this.smask && this.smask.height || 0,
  40018. this.mask && this.mask.height || 0);
  40019. },
  40020. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  40021. var bpc = this.bpc;
  40022. var numComps = this.numComps;
  40023. var decodeAddends = this.decodeAddends;
  40024. var decodeCoefficients = this.decodeCoefficients;
  40025. var max = (1 << bpc) - 1;
  40026. var i, ii;
  40027. if (bpc === 1) {
  40028. // If the buffer needed decode that means it just needs to be inverted.
  40029. for (i = 0, ii = buffer.length; i < ii; i++) {
  40030. buffer[i] = +!(buffer[i]);
  40031. }
  40032. return;
  40033. }
  40034. var index = 0;
  40035. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  40036. for (var j = 0; j < numComps; j++) {
  40037. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  40038. decodeCoefficients[j], max);
  40039. index++;
  40040. }
  40041. }
  40042. },
  40043. getComponents: function PDFImage_getComponents(buffer) {
  40044. var bpc = this.bpc;
  40045. // This image doesn't require any extra work.
  40046. if (bpc === 8) {
  40047. return buffer;
  40048. }
  40049. var width = this.width;
  40050. var height = this.height;
  40051. var numComps = this.numComps;
  40052. var length = width * height * numComps;
  40053. var bufferPos = 0;
  40054. var output = (bpc <= 8 ? new Uint8Array(length) :
  40055. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40056. var rowComps = width * numComps;
  40057. var max = (1 << bpc) - 1;
  40058. var i = 0, ii, buf;
  40059. if (bpc === 1) {
  40060. // Optimization for reading 1 bpc images.
  40061. var mask, loop1End, loop2End;
  40062. for (var j = 0; j < height; j++) {
  40063. loop1End = i + (rowComps & ~7);
  40064. loop2End = i + rowComps;
  40065. // unroll loop for all full bytes
  40066. while (i < loop1End) {
  40067. buf = buffer[bufferPos++];
  40068. output[i] = (buf >> 7) & 1;
  40069. output[i + 1] = (buf >> 6) & 1;
  40070. output[i + 2] = (buf >> 5) & 1;
  40071. output[i + 3] = (buf >> 4) & 1;
  40072. output[i + 4] = (buf >> 3) & 1;
  40073. output[i + 5] = (buf >> 2) & 1;
  40074. output[i + 6] = (buf >> 1) & 1;
  40075. output[i + 7] = buf & 1;
  40076. i += 8;
  40077. }
  40078. // handle remaining bits
  40079. if (i < loop2End) {
  40080. buf = buffer[bufferPos++];
  40081. mask = 128;
  40082. while (i < loop2End) {
  40083. output[i++] = +!!(buf & mask);
  40084. mask >>= 1;
  40085. }
  40086. }
  40087. }
  40088. } else {
  40089. // The general case that handles all other bpc values.
  40090. var bits = 0;
  40091. buf = 0;
  40092. for (i = 0, ii = length; i < ii; ++i) {
  40093. if (i % rowComps === 0) {
  40094. buf = 0;
  40095. bits = 0;
  40096. }
  40097. while (bits < bpc) {
  40098. buf = (buf << 8) | buffer[bufferPos++];
  40099. bits += 8;
  40100. }
  40101. var remainingBits = bits - bpc;
  40102. var value = buf >> remainingBits;
  40103. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  40104. buf = buf & ((1 << remainingBits) - 1);
  40105. bits = remainingBits;
  40106. }
  40107. }
  40108. return output;
  40109. },
  40110. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  40111. actualHeight, image) {
  40112. var smask = this.smask;
  40113. var mask = this.mask;
  40114. var alphaBuf, sw, sh, i, ii, j;
  40115. if (smask) {
  40116. sw = smask.width;
  40117. sh = smask.height;
  40118. alphaBuf = new Uint8Array(sw * sh);
  40119. smask.fillGrayBuffer(alphaBuf);
  40120. if (sw !== width || sh !== height) {
  40121. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  40122. width, height);
  40123. }
  40124. } else if (mask) {
  40125. if (mask instanceof PDFImage) {
  40126. sw = mask.width;
  40127. sh = mask.height;
  40128. alphaBuf = new Uint8Array(sw * sh);
  40129. mask.numComps = 1;
  40130. mask.fillGrayBuffer(alphaBuf);
  40131. // Need to invert values in rgbaBuf
  40132. for (i = 0, ii = sw * sh; i < ii; ++i) {
  40133. alphaBuf[i] = 255 - alphaBuf[i];
  40134. }
  40135. if (sw !== width || sh !== height) {
  40136. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  40137. width, height);
  40138. }
  40139. } else if (isArray(mask)) {
  40140. // Color key mask: if any of the components are outside the range
  40141. // then they should be painted.
  40142. alphaBuf = new Uint8Array(width * height);
  40143. var numComps = this.numComps;
  40144. for (i = 0, ii = width * height; i < ii; ++i) {
  40145. var opacity = 0;
  40146. var imageOffset = i * numComps;
  40147. for (j = 0; j < numComps; ++j) {
  40148. var color = image[imageOffset + j];
  40149. var maskOffset = j * 2;
  40150. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  40151. opacity = 255;
  40152. break;
  40153. }
  40154. }
  40155. alphaBuf[i] = opacity;
  40156. }
  40157. } else {
  40158. error('Unknown mask format.');
  40159. }
  40160. }
  40161. if (alphaBuf) {
  40162. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40163. rgbaBuf[j] = alphaBuf[i];
  40164. }
  40165. } else {
  40166. // No mask.
  40167. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40168. rgbaBuf[j] = 255;
  40169. }
  40170. }
  40171. },
  40172. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  40173. var matte = this.smask && this.smask.matte;
  40174. if (!matte) {
  40175. return;
  40176. }
  40177. var matteRgb = this.colorSpace.getRgb(matte, 0);
  40178. var matteR = matteRgb[0];
  40179. var matteG = matteRgb[1];
  40180. var matteB = matteRgb[2];
  40181. var length = width * height * 4;
  40182. var r, g, b;
  40183. for (var i = 0; i < length; i += 4) {
  40184. var alpha = buffer[i + 3];
  40185. if (alpha === 0) {
  40186. // according formula we have to get Infinity in all components
  40187. // making it white (typical paper color) should be okay
  40188. buffer[i] = 255;
  40189. buffer[i + 1] = 255;
  40190. buffer[i + 2] = 255;
  40191. continue;
  40192. }
  40193. var k = 255 / alpha;
  40194. r = (buffer[i] - matteR) * k + matteR;
  40195. g = (buffer[i + 1] - matteG) * k + matteG;
  40196. b = (buffer[i + 2] - matteB) * k + matteB;
  40197. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  40198. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  40199. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  40200. }
  40201. },
  40202. createImageData: function PDFImage_createImageData(forceRGBA) {
  40203. var drawWidth = this.drawWidth;
  40204. var drawHeight = this.drawHeight;
  40205. var imgData = { // other fields are filled in below
  40206. width: drawWidth,
  40207. height: drawHeight
  40208. };
  40209. var numComps = this.numComps;
  40210. var originalWidth = this.width;
  40211. var originalHeight = this.height;
  40212. var bpc = this.bpc;
  40213. // Rows start at byte boundary.
  40214. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  40215. var imgArray;
  40216. if (!forceRGBA) {
  40217. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  40218. // without any complications, we pass a same-sized copy to the main
  40219. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  40220. // of memory for many scanned documents. It's also much faster.
  40221. //
  40222. // Similarly, if it is a 24-bit-per pixel RGB image without any
  40223. // complications, we avoid expanding by 1.333x to RGBA form.
  40224. var kind;
  40225. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  40226. kind = ImageKind.GRAYSCALE_1BPP;
  40227. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  40228. !this.needsDecode) {
  40229. kind = ImageKind.RGB_24BPP;
  40230. }
  40231. if (kind && !this.smask && !this.mask &&
  40232. drawWidth === originalWidth && drawHeight === originalHeight) {
  40233. imgData.kind = kind;
  40234. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40235. // If imgArray came from a DecodeStream, we're safe to transfer it
  40236. // (and thus detach its underlying buffer) because it will constitute
  40237. // the entire DecodeStream's data. But if it came from a Stream, we
  40238. // need to copy it because it'll only be a portion of the Stream's
  40239. // data, and the rest will be read later on.
  40240. if (this.image instanceof DecodeStream) {
  40241. imgData.data = imgArray;
  40242. } else {
  40243. var newArray = new Uint8Array(imgArray.length);
  40244. newArray.set(imgArray);
  40245. imgData.data = newArray;
  40246. }
  40247. if (this.needsDecode) {
  40248. // Invert the buffer (which must be grayscale if we reached here).
  40249. assert(kind === ImageKind.GRAYSCALE_1BPP);
  40250. var buffer = imgData.data;
  40251. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40252. buffer[i] ^= 0xff;
  40253. }
  40254. }
  40255. return imgData;
  40256. }
  40257. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  40258. (this.colorSpace.name === 'DeviceGray' ||
  40259. this.colorSpace.name === 'DeviceRGB' ||
  40260. this.colorSpace.name === 'DeviceCMYK')) {
  40261. imgData.kind = ImageKind.RGB_24BPP;
  40262. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  40263. drawWidth, drawHeight, true);
  40264. return imgData;
  40265. }
  40266. }
  40267. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40268. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  40269. var actualHeight = 0 | (imgArray.length / rowBytes *
  40270. drawHeight / originalHeight);
  40271. var comps = this.getComponents(imgArray);
  40272. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  40273. // more compact RGB_24BPP form if allowable.
  40274. var alpha01, maybeUndoPreblend;
  40275. if (!forceRGBA && !this.smask && !this.mask) {
  40276. imgData.kind = ImageKind.RGB_24BPP;
  40277. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  40278. alpha01 = 0;
  40279. maybeUndoPreblend = false;
  40280. } else {
  40281. imgData.kind = ImageKind.RGBA_32BPP;
  40282. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  40283. alpha01 = 1;
  40284. maybeUndoPreblend = true;
  40285. // Color key masking (opacity) must be performed before decoding.
  40286. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  40287. comps);
  40288. }
  40289. if (this.needsDecode) {
  40290. this.decodeBuffer(comps);
  40291. }
  40292. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  40293. drawWidth, drawHeight, actualHeight, bpc, comps,
  40294. alpha01);
  40295. if (maybeUndoPreblend) {
  40296. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  40297. }
  40298. return imgData;
  40299. },
  40300. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  40301. var numComps = this.numComps;
  40302. if (numComps !== 1) {
  40303. error('Reading gray scale from a color image: ' + numComps);
  40304. }
  40305. var width = this.width;
  40306. var height = this.height;
  40307. var bpc = this.bpc;
  40308. // rows start at byte boundary
  40309. var rowBytes = (width * numComps * bpc + 7) >> 3;
  40310. var imgArray = this.getImageBytes(height * rowBytes);
  40311. var comps = this.getComponents(imgArray);
  40312. var i, length;
  40313. if (bpc === 1) {
  40314. // inline decoding (= inversion) for 1 bpc images
  40315. length = width * height;
  40316. if (this.needsDecode) {
  40317. // invert and scale to {0, 255}
  40318. for (i = 0; i < length; ++i) {
  40319. buffer[i] = (comps[i] - 1) & 255;
  40320. }
  40321. } else {
  40322. // scale to {0, 255}
  40323. for (i = 0; i < length; ++i) {
  40324. buffer[i] = (-comps[i]) & 255;
  40325. }
  40326. }
  40327. return;
  40328. }
  40329. if (this.needsDecode) {
  40330. this.decodeBuffer(comps);
  40331. }
  40332. length = width * height;
  40333. // we aren't using a colorspace so we need to scale the value
  40334. var scale = 255 / ((1 << bpc) - 1);
  40335. for (i = 0; i < length; ++i) {
  40336. buffer[i] = (scale * comps[i]) | 0;
  40337. }
  40338. },
  40339. getImageBytes: function PDFImage_getImageBytes(length,
  40340. drawWidth, drawHeight,
  40341. forceRGB) {
  40342. this.image.reset();
  40343. this.image.drawWidth = drawWidth || this.width;
  40344. this.image.drawHeight = drawHeight || this.height;
  40345. this.image.forceRGB = !!forceRGB;
  40346. return this.image.getBytes(length);
  40347. }
  40348. };
  40349. return PDFImage;
  40350. })();
  40351. exports.PDFImage = PDFImage;
  40352. }));
  40353. (function (root, factory) {
  40354. {
  40355. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  40356. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  40357. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  40358. }
  40359. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  40360. coreChunkedStream, coreColorSpace) {
  40361. var InvalidPDFException = sharedUtil.InvalidPDFException;
  40362. var MissingDataException = sharedUtil.MissingDataException;
  40363. var XRefParseException = sharedUtil.XRefParseException;
  40364. var assert = sharedUtil.assert;
  40365. var bytesToString = sharedUtil.bytesToString;
  40366. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40367. var error = sharedUtil.error;
  40368. var info = sharedUtil.info;
  40369. var isArray = sharedUtil.isArray;
  40370. var isInt = sharedUtil.isInt;
  40371. var isString = sharedUtil.isString;
  40372. var shadow = sharedUtil.shadow;
  40373. var stringToPDFString = sharedUtil.stringToPDFString;
  40374. var stringToUTF8String = sharedUtil.stringToUTF8String;
  40375. var warn = sharedUtil.warn;
  40376. var isValidUrl = sharedUtil.isValidUrl;
  40377. var Util = sharedUtil.Util;
  40378. var Ref = corePrimitives.Ref;
  40379. var RefSet = corePrimitives.RefSet;
  40380. var RefSetCache = corePrimitives.RefSetCache;
  40381. var isName = corePrimitives.isName;
  40382. var isCmd = corePrimitives.isCmd;
  40383. var isDict = corePrimitives.isDict;
  40384. var isRef = corePrimitives.isRef;
  40385. var isRefsEqual = corePrimitives.isRefsEqual;
  40386. var isStream = corePrimitives.isStream;
  40387. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  40388. var Lexer = coreParser.Lexer;
  40389. var Parser = coreParser.Parser;
  40390. var ChunkedStream = coreChunkedStream.ChunkedStream;
  40391. var ColorSpace = coreColorSpace.ColorSpace;
  40392. var Catalog = (function CatalogClosure() {
  40393. function Catalog(pdfManager, xref, pageFactory) {
  40394. this.pdfManager = pdfManager;
  40395. this.xref = xref;
  40396. this.catDict = xref.getCatalogObj();
  40397. this.fontCache = new RefSetCache();
  40398. assert(isDict(this.catDict),
  40399. 'catalog object is not a dictionary');
  40400. // TODO refactor to move getPage() to the PDFDocument.
  40401. this.pageFactory = pageFactory;
  40402. this.pagePromises = [];
  40403. }
  40404. Catalog.prototype = {
  40405. get metadata() {
  40406. var streamRef = this.catDict.getRaw('Metadata');
  40407. if (!isRef(streamRef)) {
  40408. return shadow(this, 'metadata', null);
  40409. }
  40410. var encryptMetadata = (!this.xref.encrypt ? false :
  40411. this.xref.encrypt.encryptMetadata);
  40412. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  40413. var metadata;
  40414. if (stream && isDict(stream.dict)) {
  40415. var type = stream.dict.get('Type');
  40416. var subtype = stream.dict.get('Subtype');
  40417. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  40418. // XXX: This should examine the charset the XML document defines,
  40419. // however since there are currently no real means to decode
  40420. // arbitrary charsets, let's just hope that the author of the PDF
  40421. // was reasonable enough to stick with the XML default charset,
  40422. // which is UTF-8.
  40423. try {
  40424. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  40425. } catch (e) {
  40426. info('Skipping invalid metadata.');
  40427. }
  40428. }
  40429. }
  40430. return shadow(this, 'metadata', metadata);
  40431. },
  40432. get toplevelPagesDict() {
  40433. var pagesObj = this.catDict.get('Pages');
  40434. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  40435. // shadow the prototype getter
  40436. return shadow(this, 'toplevelPagesDict', pagesObj);
  40437. },
  40438. get documentOutline() {
  40439. var obj = null;
  40440. try {
  40441. obj = this.readDocumentOutline();
  40442. } catch (ex) {
  40443. if (ex instanceof MissingDataException) {
  40444. throw ex;
  40445. }
  40446. warn('Unable to read document outline');
  40447. }
  40448. return shadow(this, 'documentOutline', obj);
  40449. },
  40450. readDocumentOutline: function Catalog_readDocumentOutline() {
  40451. var obj = this.catDict.get('Outlines');
  40452. if (!isDict(obj)) {
  40453. return null;
  40454. }
  40455. obj = obj.getRaw('First');
  40456. if (!isRef(obj)) {
  40457. return null;
  40458. }
  40459. var root = { items: [] };
  40460. var queue = [{obj: obj, parent: root}];
  40461. // To avoid recursion, keep track of the already processed items.
  40462. var processed = new RefSet();
  40463. processed.put(obj);
  40464. var xref = this.xref, blackColor = new Uint8Array(3);
  40465. while (queue.length > 0) {
  40466. var i = queue.shift();
  40467. var outlineDict = xref.fetchIfRef(i.obj);
  40468. if (outlineDict === null) {
  40469. continue;
  40470. }
  40471. assert(outlineDict.has('Title'), 'Invalid outline item');
  40472. var actionDict = outlineDict.get('A'), dest = null, url = null;
  40473. if (actionDict) {
  40474. var destEntry = actionDict.get('D');
  40475. if (destEntry) {
  40476. dest = destEntry;
  40477. } else {
  40478. var uriEntry = actionDict.get('URI');
  40479. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  40480. url = uriEntry;
  40481. }
  40482. }
  40483. } else if (outlineDict.has('Dest')) {
  40484. dest = outlineDict.getRaw('Dest');
  40485. if (isName(dest)) {
  40486. dest = dest.name;
  40487. }
  40488. }
  40489. var title = outlineDict.get('Title');
  40490. var flags = outlineDict.get('F') || 0;
  40491. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  40492. // We only need to parse the color when it's valid, and non-default.
  40493. if (isArray(color) && color.length === 3 &&
  40494. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  40495. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  40496. }
  40497. var outlineItem = {
  40498. dest: dest,
  40499. url: url,
  40500. title: stringToPDFString(title),
  40501. color: rgbColor,
  40502. count: outlineDict.get('Count'),
  40503. bold: !!(flags & 2),
  40504. italic: !!(flags & 1),
  40505. items: []
  40506. };
  40507. i.parent.items.push(outlineItem);
  40508. obj = outlineDict.getRaw('First');
  40509. if (isRef(obj) && !processed.has(obj)) {
  40510. queue.push({obj: obj, parent: outlineItem});
  40511. processed.put(obj);
  40512. }
  40513. obj = outlineDict.getRaw('Next');
  40514. if (isRef(obj) && !processed.has(obj)) {
  40515. queue.push({obj: obj, parent: i.parent});
  40516. processed.put(obj);
  40517. }
  40518. }
  40519. return (root.items.length > 0 ? root.items : null);
  40520. },
  40521. get numPages() {
  40522. var obj = this.toplevelPagesDict.get('Count');
  40523. assert(
  40524. isInt(obj),
  40525. 'page count in top level pages object is not an integer'
  40526. );
  40527. // shadow the prototype getter
  40528. return shadow(this, 'num', obj);
  40529. },
  40530. get destinations() {
  40531. function fetchDestination(dest) {
  40532. return isDict(dest) ? dest.get('D') : dest;
  40533. }
  40534. var xref = this.xref;
  40535. var dests = {}, nameTreeRef, nameDictionaryRef;
  40536. var obj = this.catDict.get('Names');
  40537. if (obj && obj.has('Dests')) {
  40538. nameTreeRef = obj.getRaw('Dests');
  40539. } else if (this.catDict.has('Dests')) {
  40540. nameDictionaryRef = this.catDict.get('Dests');
  40541. }
  40542. if (nameDictionaryRef) {
  40543. // reading simple destination dictionary
  40544. obj = nameDictionaryRef;
  40545. obj.forEach(function catalogForEach(key, value) {
  40546. if (!value) {
  40547. return;
  40548. }
  40549. dests[key] = fetchDestination(value);
  40550. });
  40551. }
  40552. if (nameTreeRef) {
  40553. var nameTree = new NameTree(nameTreeRef, xref);
  40554. var names = nameTree.getAll();
  40555. for (var name in names) {
  40556. dests[name] = fetchDestination(names[name]);
  40557. }
  40558. }
  40559. return shadow(this, 'destinations', dests);
  40560. },
  40561. getDestination: function Catalog_getDestination(destinationId) {
  40562. function fetchDestination(dest) {
  40563. return isDict(dest) ? dest.get('D') : dest;
  40564. }
  40565. var xref = this.xref;
  40566. var dest = null, nameTreeRef, nameDictionaryRef;
  40567. var obj = this.catDict.get('Names');
  40568. if (obj && obj.has('Dests')) {
  40569. nameTreeRef = obj.getRaw('Dests');
  40570. } else if (this.catDict.has('Dests')) {
  40571. nameDictionaryRef = this.catDict.get('Dests');
  40572. }
  40573. if (nameDictionaryRef) { // Simple destination dictionary.
  40574. var value = nameDictionaryRef.get(destinationId);
  40575. if (value) {
  40576. dest = fetchDestination(value);
  40577. }
  40578. }
  40579. if (nameTreeRef) {
  40580. var nameTree = new NameTree(nameTreeRef, xref);
  40581. dest = fetchDestination(nameTree.get(destinationId));
  40582. }
  40583. return dest;
  40584. },
  40585. get pageLabels() {
  40586. var obj = null;
  40587. try {
  40588. obj = this.readPageLabels();
  40589. } catch (ex) {
  40590. if (ex instanceof MissingDataException) {
  40591. throw ex;
  40592. }
  40593. warn('Unable to read page labels.');
  40594. }
  40595. return shadow(this, 'pageLabels', obj);
  40596. },
  40597. readPageLabels: function Catalog_readPageLabels() {
  40598. var obj = this.catDict.getRaw('PageLabels');
  40599. if (!obj) {
  40600. return null;
  40601. }
  40602. var pageLabels = new Array(this.numPages);
  40603. var style = null;
  40604. var prefix = '';
  40605. var start = 1;
  40606. var numberTree = new NumberTree(obj, this.xref);
  40607. var nums = numberTree.getAll();
  40608. var currentLabel = '', currentIndex = 1;
  40609. for (var i = 0, ii = this.numPages; i < ii; i++) {
  40610. if (i in nums) {
  40611. var labelDict = nums[i];
  40612. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  40613. var type = labelDict.get('Type');
  40614. assert(!type || isName(type, 'PageLabel'),
  40615. 'Invalid type in PageLabel dictionary.');
  40616. var s = labelDict.get('S');
  40617. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  40618. style = (s ? s.name : null);
  40619. prefix = labelDict.get('P') || '';
  40620. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  40621. start = labelDict.get('St') || 1;
  40622. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  40623. currentIndex = start;
  40624. }
  40625. switch (style) {
  40626. case 'D':
  40627. currentLabel = currentIndex;
  40628. break;
  40629. case 'R':
  40630. case 'r':
  40631. currentLabel = Util.toRoman(currentIndex, style === 'r');
  40632. break;
  40633. case 'A':
  40634. case 'a':
  40635. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  40636. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  40637. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  40638. var letterIndex = currentIndex - 1;
  40639. var character = String.fromCharCode(baseCharCode +
  40640. (letterIndex % LIMIT));
  40641. var charBuf = [];
  40642. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  40643. charBuf.push(character);
  40644. }
  40645. currentLabel = charBuf.join('');
  40646. break;
  40647. default:
  40648. assert(!style,
  40649. 'Invalid style "' + style + '" in PageLabel dictionary.');
  40650. }
  40651. pageLabels[i] = prefix + currentLabel;
  40652. currentLabel = '';
  40653. currentIndex++;
  40654. }
  40655. return pageLabels;
  40656. },
  40657. get attachments() {
  40658. var xref = this.xref;
  40659. var attachments = null, nameTreeRef;
  40660. var obj = this.catDict.get('Names');
  40661. if (obj) {
  40662. nameTreeRef = obj.getRaw('EmbeddedFiles');
  40663. }
  40664. if (nameTreeRef) {
  40665. var nameTree = new NameTree(nameTreeRef, xref);
  40666. var names = nameTree.getAll();
  40667. for (var name in names) {
  40668. var fs = new FileSpec(names[name], xref);
  40669. if (!attachments) {
  40670. attachments = Object.create(null);
  40671. }
  40672. attachments[stringToPDFString(name)] = fs.serializable;
  40673. }
  40674. }
  40675. return shadow(this, 'attachments', attachments);
  40676. },
  40677. get javaScript() {
  40678. var xref = this.xref;
  40679. var obj = this.catDict.get('Names');
  40680. var javaScript = [];
  40681. function appendIfJavaScriptDict(jsDict) {
  40682. var type = jsDict.get('S');
  40683. if (!isName(type, 'JavaScript')) {
  40684. return;
  40685. }
  40686. var js = jsDict.get('JS');
  40687. if (isStream(js)) {
  40688. js = bytesToString(js.getBytes());
  40689. } else if (!isString(js)) {
  40690. return;
  40691. }
  40692. javaScript.push(stringToPDFString(js));
  40693. }
  40694. if (obj && obj.has('JavaScript')) {
  40695. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  40696. var names = nameTree.getAll();
  40697. for (var name in names) {
  40698. // We don't really use the JavaScript right now. This code is
  40699. // defensive so we don't cause errors on document load.
  40700. var jsDict = names[name];
  40701. if (isDict(jsDict)) {
  40702. appendIfJavaScriptDict(jsDict);
  40703. }
  40704. }
  40705. }
  40706. // Append OpenAction actions to javaScript array
  40707. var openactionDict = this.catDict.get('OpenAction');
  40708. if (isDict(openactionDict, 'Action')) {
  40709. var actionType = openactionDict.get('S');
  40710. if (isName(actionType, 'Named')) {
  40711. // The named Print action is not a part of the PDF 1.7 specification,
  40712. // but is supported by many PDF readers/writers (including Adobe's).
  40713. var action = openactionDict.get('N');
  40714. if (isName(action, 'Print')) {
  40715. javaScript.push('print({});');
  40716. }
  40717. } else {
  40718. appendIfJavaScriptDict(openactionDict);
  40719. }
  40720. }
  40721. return shadow(this, 'javaScript', javaScript);
  40722. },
  40723. cleanup: function Catalog_cleanup() {
  40724. var promises = [];
  40725. this.fontCache.forEach(function (promise) {
  40726. promises.push(promise);
  40727. });
  40728. return Promise.all(promises).then(function (translatedFonts) {
  40729. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  40730. var font = translatedFonts[i].dict;
  40731. delete font.translated;
  40732. }
  40733. this.fontCache.clear();
  40734. }.bind(this));
  40735. },
  40736. getPage: function Catalog_getPage(pageIndex) {
  40737. if (!(pageIndex in this.pagePromises)) {
  40738. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  40739. function (a) {
  40740. var dict = a[0];
  40741. var ref = a[1];
  40742. return this.pageFactory.createPage(pageIndex, dict, ref,
  40743. this.fontCache);
  40744. }.bind(this)
  40745. );
  40746. }
  40747. return this.pagePromises[pageIndex];
  40748. },
  40749. getPageDict: function Catalog_getPageDict(pageIndex) {
  40750. var capability = createPromiseCapability();
  40751. var nodesToVisit = [this.catDict.getRaw('Pages')];
  40752. var currentPageIndex = 0;
  40753. var xref = this.xref;
  40754. var checkAllKids = false;
  40755. function next() {
  40756. while (nodesToVisit.length) {
  40757. var currentNode = nodesToVisit.pop();
  40758. if (isRef(currentNode)) {
  40759. xref.fetchAsync(currentNode).then(function (obj) {
  40760. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  40761. if (pageIndex === currentPageIndex) {
  40762. capability.resolve([obj, currentNode]);
  40763. } else {
  40764. currentPageIndex++;
  40765. next();
  40766. }
  40767. return;
  40768. }
  40769. nodesToVisit.push(obj);
  40770. next();
  40771. }, capability.reject);
  40772. return;
  40773. }
  40774. // Must be a child page dictionary.
  40775. assert(
  40776. isDict(currentNode),
  40777. 'page dictionary kid reference points to wrong type of object'
  40778. );
  40779. var count = currentNode.get('Count');
  40780. // If the current node doesn't have any children, avoid getting stuck
  40781. // in an empty node further down in the tree (see issue5644.pdf).
  40782. if (count === 0) {
  40783. checkAllKids = true;
  40784. }
  40785. // Skip nodes where the page can't be.
  40786. if (currentPageIndex + count <= pageIndex) {
  40787. currentPageIndex += count;
  40788. continue;
  40789. }
  40790. var kids = currentNode.get('Kids');
  40791. assert(isArray(kids), 'page dictionary kids object is not an array');
  40792. if (!checkAllKids && count === kids.length) {
  40793. // Nodes that don't have the page have been skipped and this is the
  40794. // bottom of the tree which means the page requested must be a
  40795. // descendant of this pages node. Ideally we would just resolve the
  40796. // promise with the page ref here, but there is the case where more
  40797. // pages nodes could link to single a page (see issue 3666 pdf). To
  40798. // handle this push it back on the queue so if it is a pages node it
  40799. // will be descended into.
  40800. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  40801. currentPageIndex = pageIndex;
  40802. continue;
  40803. } else {
  40804. for (var last = kids.length - 1; last >= 0; last--) {
  40805. nodesToVisit.push(kids[last]);
  40806. }
  40807. }
  40808. }
  40809. capability.reject('Page index ' + pageIndex + ' not found.');
  40810. }
  40811. next();
  40812. return capability.promise;
  40813. },
  40814. getPageIndex: function Catalog_getPageIndex(pageRef) {
  40815. // The page tree nodes have the count of all the leaves below them. To get
  40816. // how many pages are before we just have to walk up the tree and keep
  40817. // adding the count of siblings to the left of the node.
  40818. var xref = this.xref;
  40819. function pagesBeforeRef(kidRef) {
  40820. var total = 0;
  40821. var parentRef;
  40822. return xref.fetchAsync(kidRef).then(function (node) {
  40823. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  40824. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  40825. throw new Error('The reference does not point to a /Page Dict.');
  40826. }
  40827. if (!node) {
  40828. return null;
  40829. }
  40830. assert(isDict(node), 'node must be a Dict.');
  40831. parentRef = node.getRaw('Parent');
  40832. return node.getAsync('Parent');
  40833. }).then(function (parent) {
  40834. if (!parent) {
  40835. return null;
  40836. }
  40837. assert(isDict(parent), 'parent must be a Dict.');
  40838. return parent.getAsync('Kids');
  40839. }).then(function (kids) {
  40840. if (!kids) {
  40841. return null;
  40842. }
  40843. var kidPromises = [];
  40844. var found = false;
  40845. for (var i = 0; i < kids.length; i++) {
  40846. var kid = kids[i];
  40847. assert(isRef(kid), 'kid must be a Ref.');
  40848. if (kid.num === kidRef.num) {
  40849. found = true;
  40850. break;
  40851. }
  40852. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  40853. if (kid.has('Count')) {
  40854. var count = kid.get('Count');
  40855. total += count;
  40856. } else { // page leaf node
  40857. total++;
  40858. }
  40859. }));
  40860. }
  40861. if (!found) {
  40862. error('kid ref not found in parents kids');
  40863. }
  40864. return Promise.all(kidPromises).then(function () {
  40865. return [total, parentRef];
  40866. });
  40867. });
  40868. }
  40869. var total = 0;
  40870. function next(ref) {
  40871. return pagesBeforeRef(ref).then(function (args) {
  40872. if (!args) {
  40873. return total;
  40874. }
  40875. var count = args[0];
  40876. var parentRef = args[1];
  40877. total += count;
  40878. return next(parentRef);
  40879. });
  40880. }
  40881. return next(pageRef);
  40882. }
  40883. };
  40884. return Catalog;
  40885. })();
  40886. var XRef = (function XRefClosure() {
  40887. function XRef(stream, password) {
  40888. this.stream = stream;
  40889. this.entries = [];
  40890. this.xrefstms = Object.create(null);
  40891. // prepare the XRef cache
  40892. this.cache = [];
  40893. this.password = password;
  40894. this.stats = {
  40895. streamTypes: [],
  40896. fontTypes: []
  40897. };
  40898. }
  40899. XRef.prototype = {
  40900. setStartXRef: function XRef_setStartXRef(startXRef) {
  40901. // Store the starting positions of xref tables as we process them
  40902. // so we can recover from missing data errors
  40903. this.startXRefQueue = [startXRef];
  40904. },
  40905. parse: function XRef_parse(recoveryMode) {
  40906. var trailerDict;
  40907. if (!recoveryMode) {
  40908. trailerDict = this.readXRef();
  40909. } else {
  40910. warn('Indexing all PDF objects');
  40911. trailerDict = this.indexObjects();
  40912. }
  40913. trailerDict.assignXref(this);
  40914. this.trailer = trailerDict;
  40915. var encrypt = trailerDict.get('Encrypt');
  40916. if (encrypt) {
  40917. var ids = trailerDict.get('ID');
  40918. var fileId = (ids && ids.length) ? ids[0] : '';
  40919. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  40920. this.password);
  40921. }
  40922. // get the root dictionary (catalog) object
  40923. if (!(this.root = trailerDict.get('Root'))) {
  40924. error('Invalid root reference');
  40925. }
  40926. },
  40927. processXRefTable: function XRef_processXRefTable(parser) {
  40928. if (!('tableState' in this)) {
  40929. // Stores state of the table as we process it so we can resume
  40930. // from middle of table in case of missing data error
  40931. this.tableState = {
  40932. entryNum: 0,
  40933. streamPos: parser.lexer.stream.pos,
  40934. parserBuf1: parser.buf1,
  40935. parserBuf2: parser.buf2
  40936. };
  40937. }
  40938. var obj = this.readXRefTable(parser);
  40939. // Sanity check
  40940. if (!isCmd(obj, 'trailer')) {
  40941. error('Invalid XRef table: could not find trailer dictionary');
  40942. }
  40943. // Read trailer dictionary, e.g.
  40944. // trailer
  40945. // << /Size 22
  40946. // /Root 20R
  40947. // /Info 10R
  40948. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  40949. // >>
  40950. // The parser goes through the entire stream << ... >> and provides
  40951. // a getter interface for the key-value table
  40952. var dict = parser.getObj();
  40953. // The pdflib PDF generator can generate a nested trailer dictionary
  40954. if (!isDict(dict) && dict.dict) {
  40955. dict = dict.dict;
  40956. }
  40957. if (!isDict(dict)) {
  40958. error('Invalid XRef table: could not parse trailer dictionary');
  40959. }
  40960. delete this.tableState;
  40961. return dict;
  40962. },
  40963. readXRefTable: function XRef_readXRefTable(parser) {
  40964. // Example of cross-reference table:
  40965. // xref
  40966. // 0 1 <-- subsection header (first obj #, obj count)
  40967. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  40968. // 23 2 <-- subsection header ... and so on ...
  40969. // 0000025518 00002 n
  40970. // 0000025635 00000 n
  40971. // trailer
  40972. // ...
  40973. var stream = parser.lexer.stream;
  40974. var tableState = this.tableState;
  40975. stream.pos = tableState.streamPos;
  40976. parser.buf1 = tableState.parserBuf1;
  40977. parser.buf2 = tableState.parserBuf2;
  40978. // Outer loop is over subsection headers
  40979. var obj;
  40980. while (true) {
  40981. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  40982. if (isCmd(obj = parser.getObj(), 'trailer')) {
  40983. break;
  40984. }
  40985. tableState.firstEntryNum = obj;
  40986. tableState.entryCount = parser.getObj();
  40987. }
  40988. var first = tableState.firstEntryNum;
  40989. var count = tableState.entryCount;
  40990. if (!isInt(first) || !isInt(count)) {
  40991. error('Invalid XRef table: wrong types in subsection header');
  40992. }
  40993. // Inner loop is over objects themselves
  40994. for (var i = tableState.entryNum; i < count; i++) {
  40995. tableState.streamPos = stream.pos;
  40996. tableState.entryNum = i;
  40997. tableState.parserBuf1 = parser.buf1;
  40998. tableState.parserBuf2 = parser.buf2;
  40999. var entry = {};
  41000. entry.offset = parser.getObj();
  41001. entry.gen = parser.getObj();
  41002. var type = parser.getObj();
  41003. if (isCmd(type, 'f')) {
  41004. entry.free = true;
  41005. } else if (isCmd(type, 'n')) {
  41006. entry.uncompressed = true;
  41007. }
  41008. // Validate entry obj
  41009. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  41010. !(entry.free || entry.uncompressed)) {
  41011. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  41012. }
  41013. // The first xref table entry, i.e. obj 0, should be free. Attempting
  41014. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  41015. if (i === 0 && entry.free && first === 1) {
  41016. first = 0;
  41017. }
  41018. if (!this.entries[i + first]) {
  41019. this.entries[i + first] = entry;
  41020. }
  41021. }
  41022. tableState.entryNum = 0;
  41023. tableState.streamPos = stream.pos;
  41024. tableState.parserBuf1 = parser.buf1;
  41025. tableState.parserBuf2 = parser.buf2;
  41026. delete tableState.firstEntryNum;
  41027. delete tableState.entryCount;
  41028. }
  41029. // Sanity check: as per spec, first object must be free
  41030. if (this.entries[0] && !this.entries[0].free) {
  41031. error('Invalid XRef table: unexpected first object');
  41032. }
  41033. return obj;
  41034. },
  41035. processXRefStream: function XRef_processXRefStream(stream) {
  41036. if (!('streamState' in this)) {
  41037. // Stores state of the stream as we process it so we can resume
  41038. // from middle of stream in case of missing data error
  41039. var streamParameters = stream.dict;
  41040. var byteWidths = streamParameters.get('W');
  41041. var range = streamParameters.get('Index');
  41042. if (!range) {
  41043. range = [0, streamParameters.get('Size')];
  41044. }
  41045. this.streamState = {
  41046. entryRanges: range,
  41047. byteWidths: byteWidths,
  41048. entryNum: 0,
  41049. streamPos: stream.pos
  41050. };
  41051. }
  41052. this.readXRefStream(stream);
  41053. delete this.streamState;
  41054. return stream.dict;
  41055. },
  41056. readXRefStream: function XRef_readXRefStream(stream) {
  41057. var i, j;
  41058. var streamState = this.streamState;
  41059. stream.pos = streamState.streamPos;
  41060. var byteWidths = streamState.byteWidths;
  41061. var typeFieldWidth = byteWidths[0];
  41062. var offsetFieldWidth = byteWidths[1];
  41063. var generationFieldWidth = byteWidths[2];
  41064. var entryRanges = streamState.entryRanges;
  41065. while (entryRanges.length > 0) {
  41066. var first = entryRanges[0];
  41067. var n = entryRanges[1];
  41068. if (!isInt(first) || !isInt(n)) {
  41069. error('Invalid XRef range fields: ' + first + ', ' + n);
  41070. }
  41071. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  41072. !isInt(generationFieldWidth)) {
  41073. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  41074. }
  41075. for (i = streamState.entryNum; i < n; ++i) {
  41076. streamState.entryNum = i;
  41077. streamState.streamPos = stream.pos;
  41078. var type = 0, offset = 0, generation = 0;
  41079. for (j = 0; j < typeFieldWidth; ++j) {
  41080. type = (type << 8) | stream.getByte();
  41081. }
  41082. // if type field is absent, its default value is 1
  41083. if (typeFieldWidth === 0) {
  41084. type = 1;
  41085. }
  41086. for (j = 0; j < offsetFieldWidth; ++j) {
  41087. offset = (offset << 8) | stream.getByte();
  41088. }
  41089. for (j = 0; j < generationFieldWidth; ++j) {
  41090. generation = (generation << 8) | stream.getByte();
  41091. }
  41092. var entry = {};
  41093. entry.offset = offset;
  41094. entry.gen = generation;
  41095. switch (type) {
  41096. case 0:
  41097. entry.free = true;
  41098. break;
  41099. case 1:
  41100. entry.uncompressed = true;
  41101. break;
  41102. case 2:
  41103. break;
  41104. default:
  41105. error('Invalid XRef entry type: ' + type);
  41106. }
  41107. if (!this.entries[first + i]) {
  41108. this.entries[first + i] = entry;
  41109. }
  41110. }
  41111. streamState.entryNum = 0;
  41112. streamState.streamPos = stream.pos;
  41113. entryRanges.splice(0, 2);
  41114. }
  41115. },
  41116. indexObjects: function XRef_indexObjects() {
  41117. // Simple scan through the PDF content to find objects,
  41118. // trailers and XRef streams.
  41119. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  41120. var PERCENT = 0x25, LT = 0x3C;
  41121. function readToken(data, offset) {
  41122. var token = '', ch = data[offset];
  41123. while (ch !== LF && ch !== CR && ch !== LT) {
  41124. if (++offset >= data.length) {
  41125. break;
  41126. }
  41127. token += String.fromCharCode(ch);
  41128. ch = data[offset];
  41129. }
  41130. return token;
  41131. }
  41132. function skipUntil(data, offset, what) {
  41133. var length = what.length, dataLength = data.length;
  41134. var skipped = 0;
  41135. // finding byte sequence
  41136. while (offset < dataLength) {
  41137. var i = 0;
  41138. while (i < length && data[offset + i] === what[i]) {
  41139. ++i;
  41140. }
  41141. if (i >= length) {
  41142. break; // sequence found
  41143. }
  41144. offset++;
  41145. skipped++;
  41146. }
  41147. return skipped;
  41148. }
  41149. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  41150. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  41151. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  41152. 101, 102]);
  41153. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  41154. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  41155. // Clear out any existing entries, since they may be bogus.
  41156. this.entries.length = 0;
  41157. var stream = this.stream;
  41158. stream.pos = 0;
  41159. var buffer = stream.getBytes();
  41160. var position = stream.start, length = buffer.length;
  41161. var trailers = [], xrefStms = [];
  41162. while (position < length) {
  41163. var ch = buffer[position];
  41164. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  41165. ++position;
  41166. continue;
  41167. }
  41168. if (ch === PERCENT) { // %-comment
  41169. do {
  41170. ++position;
  41171. if (position >= length) {
  41172. break;
  41173. }
  41174. ch = buffer[position];
  41175. } while (ch !== LF && ch !== CR);
  41176. continue;
  41177. }
  41178. var token = readToken(buffer, position);
  41179. var m;
  41180. if (token.indexOf('xref') === 0 &&
  41181. (token.length === 4 || /\s/.test(token[4]))) {
  41182. position += skipUntil(buffer, position, trailerBytes);
  41183. trailers.push(position);
  41184. position += skipUntil(buffer, position, startxrefBytes);
  41185. } else if ((m = objRegExp.exec(token))) {
  41186. if (typeof this.entries[m[1]] === 'undefined') {
  41187. this.entries[m[1]] = {
  41188. offset: position - stream.start,
  41189. gen: m[2] | 0,
  41190. uncompressed: true
  41191. };
  41192. }
  41193. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  41194. var content = buffer.subarray(position, position + contentLength);
  41195. // checking XRef stream suspect
  41196. // (it shall have '/XRef' and next char is not a letter)
  41197. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  41198. if (xrefTagOffset < contentLength &&
  41199. content[xrefTagOffset + 5] < 64) {
  41200. xrefStms.push(position - stream.start);
  41201. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  41202. }
  41203. position += contentLength;
  41204. } else if (token.indexOf('trailer') === 0 &&
  41205. (token.length === 7 || /\s/.test(token[7]))) {
  41206. trailers.push(position);
  41207. position += skipUntil(buffer, position, startxrefBytes);
  41208. } else {
  41209. position += token.length + 1;
  41210. }
  41211. }
  41212. // reading XRef streams
  41213. var i, ii;
  41214. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  41215. this.startXRefQueue.push(xrefStms[i]);
  41216. this.readXRef(/* recoveryMode */ true);
  41217. }
  41218. // finding main trailer
  41219. var dict;
  41220. for (i = 0, ii = trailers.length; i < ii; ++i) {
  41221. stream.pos = trailers[i];
  41222. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  41223. /* xref = */ this, /* recoveryMode = */ true);
  41224. var obj = parser.getObj();
  41225. if (!isCmd(obj, 'trailer')) {
  41226. continue;
  41227. }
  41228. // read the trailer dictionary
  41229. dict = parser.getObj();
  41230. if (!isDict(dict)) {
  41231. continue;
  41232. }
  41233. // taking the first one with 'ID'
  41234. if (dict.has('ID')) {
  41235. return dict;
  41236. }
  41237. }
  41238. // no tailer with 'ID', taking last one (if exists)
  41239. if (dict) {
  41240. return dict;
  41241. }
  41242. // nothing helps
  41243. // calling error() would reject worker with an UnknownErrorException.
  41244. throw new InvalidPDFException('Invalid PDF structure');
  41245. },
  41246. readXRef: function XRef_readXRef(recoveryMode) {
  41247. var stream = this.stream;
  41248. try {
  41249. while (this.startXRefQueue.length) {
  41250. var startXRef = this.startXRefQueue[0];
  41251. stream.pos = startXRef + stream.start;
  41252. var parser = new Parser(new Lexer(stream), true, this);
  41253. var obj = parser.getObj();
  41254. var dict;
  41255. // Get dictionary
  41256. if (isCmd(obj, 'xref')) {
  41257. // Parse end-of-file XRef
  41258. dict = this.processXRefTable(parser);
  41259. if (!this.topDict) {
  41260. this.topDict = dict;
  41261. }
  41262. // Recursively get other XRefs 'XRefStm', if any
  41263. obj = dict.get('XRefStm');
  41264. if (isInt(obj)) {
  41265. var pos = obj;
  41266. // ignore previously loaded xref streams
  41267. // (possible infinite recursion)
  41268. if (!(pos in this.xrefstms)) {
  41269. this.xrefstms[pos] = 1;
  41270. this.startXRefQueue.push(pos);
  41271. }
  41272. }
  41273. } else if (isInt(obj)) {
  41274. // Parse in-stream XRef
  41275. if (!isInt(parser.getObj()) ||
  41276. !isCmd(parser.getObj(), 'obj') ||
  41277. !isStream(obj = parser.getObj())) {
  41278. error('Invalid XRef stream');
  41279. }
  41280. dict = this.processXRefStream(obj);
  41281. if (!this.topDict) {
  41282. this.topDict = dict;
  41283. }
  41284. if (!dict) {
  41285. error('Failed to read XRef stream');
  41286. }
  41287. } else {
  41288. error('Invalid XRef stream header');
  41289. }
  41290. // Recursively get previous dictionary, if any
  41291. obj = dict.get('Prev');
  41292. if (isInt(obj)) {
  41293. this.startXRefQueue.push(obj);
  41294. } else if (isRef(obj)) {
  41295. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  41296. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  41297. this.startXRefQueue.push(obj.num);
  41298. }
  41299. this.startXRefQueue.shift();
  41300. }
  41301. return this.topDict;
  41302. } catch (e) {
  41303. if (e instanceof MissingDataException) {
  41304. throw e;
  41305. }
  41306. info('(while reading XRef): ' + e);
  41307. }
  41308. if (recoveryMode) {
  41309. return;
  41310. }
  41311. throw new XRefParseException();
  41312. },
  41313. getEntry: function XRef_getEntry(i) {
  41314. var xrefEntry = this.entries[i];
  41315. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  41316. return xrefEntry;
  41317. }
  41318. return null;
  41319. },
  41320. fetchIfRef: function XRef_fetchIfRef(obj) {
  41321. if (!isRef(obj)) {
  41322. return obj;
  41323. }
  41324. return this.fetch(obj);
  41325. },
  41326. fetch: function XRef_fetch(ref, suppressEncryption) {
  41327. assert(isRef(ref), 'ref object is not a reference');
  41328. var num = ref.num;
  41329. if (num in this.cache) {
  41330. var cacheEntry = this.cache[num];
  41331. return cacheEntry;
  41332. }
  41333. var xrefEntry = this.getEntry(num);
  41334. // the referenced entry can be free
  41335. if (xrefEntry === null) {
  41336. return (this.cache[num] = null);
  41337. }
  41338. if (xrefEntry.uncompressed) {
  41339. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  41340. } else {
  41341. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  41342. }
  41343. if (isDict(xrefEntry)){
  41344. xrefEntry.objId = ref.toString();
  41345. } else if (isStream(xrefEntry)) {
  41346. xrefEntry.dict.objId = ref.toString();
  41347. }
  41348. return xrefEntry;
  41349. },
  41350. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  41351. suppressEncryption) {
  41352. var gen = ref.gen;
  41353. var num = ref.num;
  41354. if (xrefEntry.gen !== gen) {
  41355. error('inconsistent generation in XRef');
  41356. }
  41357. var stream = this.stream.makeSubStream(xrefEntry.offset +
  41358. this.stream.start);
  41359. var parser = new Parser(new Lexer(stream), true, this);
  41360. var obj1 = parser.getObj();
  41361. var obj2 = parser.getObj();
  41362. var obj3 = parser.getObj();
  41363. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  41364. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  41365. !isCmd(obj3)) {
  41366. error('bad XRef entry');
  41367. }
  41368. if (!isCmd(obj3, 'obj')) {
  41369. // some bad PDFs use "obj1234" and really mean 1234
  41370. if (obj3.cmd.indexOf('obj') === 0) {
  41371. num = parseInt(obj3.cmd.substring(3), 10);
  41372. if (!isNaN(num)) {
  41373. return num;
  41374. }
  41375. }
  41376. error('bad XRef entry');
  41377. }
  41378. if (this.encrypt && !suppressEncryption) {
  41379. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  41380. } else {
  41381. xrefEntry = parser.getObj();
  41382. }
  41383. if (!isStream(xrefEntry)) {
  41384. this.cache[num] = xrefEntry;
  41385. }
  41386. return xrefEntry;
  41387. },
  41388. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  41389. suppressEncryption) {
  41390. var tableOffset = xrefEntry.offset;
  41391. var stream = this.fetch(new Ref(tableOffset, 0));
  41392. if (!isStream(stream)) {
  41393. error('bad ObjStm stream');
  41394. }
  41395. var first = stream.dict.get('First');
  41396. var n = stream.dict.get('N');
  41397. if (!isInt(first) || !isInt(n)) {
  41398. error('invalid first and n parameters for ObjStm stream');
  41399. }
  41400. var parser = new Parser(new Lexer(stream), false, this);
  41401. parser.allowStreams = true;
  41402. var i, entries = [], num, nums = [];
  41403. // read the object numbers to populate cache
  41404. for (i = 0; i < n; ++i) {
  41405. num = parser.getObj();
  41406. if (!isInt(num)) {
  41407. error('invalid object number in the ObjStm stream: ' + num);
  41408. }
  41409. nums.push(num);
  41410. var offset = parser.getObj();
  41411. if (!isInt(offset)) {
  41412. error('invalid object offset in the ObjStm stream: ' + offset);
  41413. }
  41414. }
  41415. // read stream objects for cache
  41416. for (i = 0; i < n; ++i) {
  41417. entries.push(parser.getObj());
  41418. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  41419. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  41420. if (isCmd(parser.buf1, 'endobj')) {
  41421. parser.shift();
  41422. }
  41423. num = nums[i];
  41424. var entry = this.entries[num];
  41425. if (entry && entry.offset === tableOffset && entry.gen === i) {
  41426. this.cache[num] = entries[i];
  41427. }
  41428. }
  41429. xrefEntry = entries[xrefEntry.gen];
  41430. if (xrefEntry === undefined) {
  41431. error('bad XRef entry for compressed object');
  41432. }
  41433. return xrefEntry;
  41434. },
  41435. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  41436. if (!isRef(obj)) {
  41437. return Promise.resolve(obj);
  41438. }
  41439. return this.fetchAsync(obj);
  41440. },
  41441. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  41442. var streamManager = this.stream.manager;
  41443. var xref = this;
  41444. return new Promise(function tryFetch(resolve, reject) {
  41445. try {
  41446. resolve(xref.fetch(ref, suppressEncryption));
  41447. } catch (e) {
  41448. if (e instanceof MissingDataException) {
  41449. streamManager.requestRange(e.begin, e.end).then(function () {
  41450. tryFetch(resolve, reject);
  41451. }, reject);
  41452. return;
  41453. }
  41454. reject(e);
  41455. }
  41456. });
  41457. },
  41458. getCatalogObj: function XRef_getCatalogObj() {
  41459. return this.root;
  41460. }
  41461. };
  41462. return XRef;
  41463. })();
  41464. /**
  41465. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  41466. * see the specification (7.9.6 and 7.9.7) for additional details.
  41467. * TODO: implement all the Dict functions and make this more efficient.
  41468. */
  41469. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  41470. function NameOrNumberTree(root, xref) {
  41471. throw new Error('Cannot initialize NameOrNumberTree.');
  41472. }
  41473. NameOrNumberTree.prototype = {
  41474. getAll: function NameOrNumberTree_getAll() {
  41475. var dict = Object.create(null);
  41476. if (!this.root) {
  41477. return dict;
  41478. }
  41479. var xref = this.xref;
  41480. // Reading Name/Number tree.
  41481. var processed = new RefSet();
  41482. processed.put(this.root);
  41483. var queue = [this.root];
  41484. while (queue.length > 0) {
  41485. var i, n;
  41486. var obj = xref.fetchIfRef(queue.shift());
  41487. if (!isDict(obj)) {
  41488. continue;
  41489. }
  41490. if (obj.has('Kids')) {
  41491. var kids = obj.get('Kids');
  41492. for (i = 0, n = kids.length; i < n; i++) {
  41493. var kid = kids[i];
  41494. assert(!processed.has(kid),
  41495. 'Duplicate entry in "' + this._type + '" tree.');
  41496. queue.push(kid);
  41497. processed.put(kid);
  41498. }
  41499. continue;
  41500. }
  41501. var entries = obj.get(this._type);
  41502. if (isArray(entries)) {
  41503. for (i = 0, n = entries.length; i < n; i += 2) {
  41504. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  41505. }
  41506. }
  41507. }
  41508. return dict;
  41509. },
  41510. get: function NameOrNumberTree_get(key) {
  41511. if (!this.root) {
  41512. return null;
  41513. }
  41514. var xref = this.xref;
  41515. var kidsOrEntries = xref.fetchIfRef(this.root);
  41516. var loopCount = 0;
  41517. var MAX_LEVELS = 10;
  41518. var l, r, m;
  41519. // Perform a binary search to quickly find the entry that
  41520. // contains the key we are looking for.
  41521. while (kidsOrEntries.has('Kids')) {
  41522. if (++loopCount > MAX_LEVELS) {
  41523. warn('Search depth limit reached for "' + this._type + '" tree.');
  41524. return null;
  41525. }
  41526. var kids = kidsOrEntries.get('Kids');
  41527. if (!isArray(kids)) {
  41528. return null;
  41529. }
  41530. l = 0;
  41531. r = kids.length - 1;
  41532. while (l <= r) {
  41533. m = (l + r) >> 1;
  41534. var kid = xref.fetchIfRef(kids[m]);
  41535. var limits = kid.get('Limits');
  41536. if (key < xref.fetchIfRef(limits[0])) {
  41537. r = m - 1;
  41538. } else if (key > xref.fetchIfRef(limits[1])) {
  41539. l = m + 1;
  41540. } else {
  41541. kidsOrEntries = xref.fetchIfRef(kids[m]);
  41542. break;
  41543. }
  41544. }
  41545. if (l > r) {
  41546. return null;
  41547. }
  41548. }
  41549. // If we get here, then we have found the right entry. Now go through the
  41550. // entries in the dictionary until we find the key we're looking for.
  41551. var entries = kidsOrEntries.get(this._type);
  41552. if (isArray(entries)) {
  41553. // Perform a binary search to reduce the lookup time.
  41554. l = 0;
  41555. r = entries.length - 2;
  41556. while (l <= r) {
  41557. // Check only even indices (0, 2, 4, ...) because the
  41558. // odd indices contain the actual data.
  41559. m = (l + r) & ~1;
  41560. var currentKey = xref.fetchIfRef(entries[m]);
  41561. if (key < currentKey) {
  41562. r = m - 2;
  41563. } else if (key > currentKey) {
  41564. l = m + 2;
  41565. } else {
  41566. return xref.fetchIfRef(entries[m + 1]);
  41567. }
  41568. }
  41569. }
  41570. return null;
  41571. }
  41572. };
  41573. return NameOrNumberTree;
  41574. })();
  41575. var NameTree = (function NameTreeClosure() {
  41576. function NameTree(root, xref) {
  41577. this.root = root;
  41578. this.xref = xref;
  41579. this._type = 'Names';
  41580. }
  41581. Util.inherit(NameTree, NameOrNumberTree, {});
  41582. return NameTree;
  41583. })();
  41584. var NumberTree = (function NumberTreeClosure() {
  41585. function NumberTree(root, xref) {
  41586. this.root = root;
  41587. this.xref = xref;
  41588. this._type = 'Nums';
  41589. }
  41590. Util.inherit(NumberTree, NameOrNumberTree, {});
  41591. return NumberTree;
  41592. })();
  41593. /**
  41594. * "A PDF file can refer to the contents of another file by using a File
  41595. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  41596. * NOTE: Only embedded files are supported (as part of the attachments support)
  41597. * TODO: support the 'URL' file system (with caching if !/V), portable
  41598. * collections attributes and related files (/RF)
  41599. */
  41600. var FileSpec = (function FileSpecClosure() {
  41601. function FileSpec(root, xref) {
  41602. if (!root || !isDict(root)) {
  41603. return;
  41604. }
  41605. this.xref = xref;
  41606. this.root = root;
  41607. if (root.has('FS')) {
  41608. this.fs = root.get('FS');
  41609. }
  41610. this.description = root.has('Desc') ?
  41611. stringToPDFString(root.get('Desc')) :
  41612. '';
  41613. if (root.has('RF')) {
  41614. warn('Related file specifications are not supported');
  41615. }
  41616. this.contentAvailable = true;
  41617. if (!root.has('EF')) {
  41618. this.contentAvailable = false;
  41619. warn('Non-embedded file specifications are not supported');
  41620. }
  41621. }
  41622. function pickPlatformItem(dict) {
  41623. // Look for the filename in this order:
  41624. // UF, F, Unix, Mac, DOS
  41625. if (dict.has('UF')) {
  41626. return dict.get('UF');
  41627. } else if (dict.has('F')) {
  41628. return dict.get('F');
  41629. } else if (dict.has('Unix')) {
  41630. return dict.get('Unix');
  41631. } else if (dict.has('Mac')) {
  41632. return dict.get('Mac');
  41633. } else if (dict.has('DOS')) {
  41634. return dict.get('DOS');
  41635. } else {
  41636. return null;
  41637. }
  41638. }
  41639. FileSpec.prototype = {
  41640. get filename() {
  41641. if (!this._filename && this.root) {
  41642. var filename = pickPlatformItem(this.root) || 'unnamed';
  41643. this._filename = stringToPDFString(filename).
  41644. replace(/\\\\/g, '\\').
  41645. replace(/\\\//g, '/').
  41646. replace(/\\/g, '/');
  41647. }
  41648. return this._filename;
  41649. },
  41650. get content() {
  41651. if (!this.contentAvailable) {
  41652. return null;
  41653. }
  41654. if (!this.contentRef && this.root) {
  41655. this.contentRef = pickPlatformItem(this.root.get('EF'));
  41656. }
  41657. var content = null;
  41658. if (this.contentRef) {
  41659. var xref = this.xref;
  41660. var fileObj = xref.fetchIfRef(this.contentRef);
  41661. if (fileObj && isStream(fileObj)) {
  41662. content = fileObj.getBytes();
  41663. } else {
  41664. warn('Embedded file specification points to non-existing/invalid ' +
  41665. 'content');
  41666. }
  41667. } else {
  41668. warn('Embedded file specification does not have a content');
  41669. }
  41670. return content;
  41671. },
  41672. get serializable() {
  41673. return {
  41674. filename: this.filename,
  41675. content: this.content
  41676. };
  41677. }
  41678. };
  41679. return FileSpec;
  41680. })();
  41681. /**
  41682. * A helper for loading missing data in object graphs. It traverses the graph
  41683. * depth first and queues up any objects that have missing data. Once it has
  41684. * has traversed as many objects that are available it attempts to bundle the
  41685. * missing data requests and then resume from the nodes that weren't ready.
  41686. *
  41687. * NOTE: It provides protection from circular references by keeping track of
  41688. * of loaded references. However, you must be careful not to load any graphs
  41689. * that have references to the catalog or other pages since that will cause the
  41690. * entire PDF document object graph to be traversed.
  41691. */
  41692. var ObjectLoader = (function() {
  41693. function mayHaveChildren(value) {
  41694. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  41695. }
  41696. function addChildren(node, nodesToVisit) {
  41697. var value;
  41698. if (isDict(node) || isStream(node)) {
  41699. var map;
  41700. if (isDict(node)) {
  41701. map = node.map;
  41702. } else {
  41703. map = node.dict.map;
  41704. }
  41705. for (var key in map) {
  41706. value = map[key];
  41707. if (mayHaveChildren(value)) {
  41708. nodesToVisit.push(value);
  41709. }
  41710. }
  41711. } else if (isArray(node)) {
  41712. for (var i = 0, ii = node.length; i < ii; i++) {
  41713. value = node[i];
  41714. if (mayHaveChildren(value)) {
  41715. nodesToVisit.push(value);
  41716. }
  41717. }
  41718. }
  41719. }
  41720. function ObjectLoader(obj, keys, xref) {
  41721. this.obj = obj;
  41722. this.keys = keys;
  41723. this.xref = xref;
  41724. this.refSet = null;
  41725. this.capability = null;
  41726. }
  41727. ObjectLoader.prototype = {
  41728. load: function ObjectLoader_load() {
  41729. var keys = this.keys;
  41730. this.capability = createPromiseCapability();
  41731. // Don't walk the graph if all the data is already loaded.
  41732. if (!(this.xref.stream instanceof ChunkedStream) ||
  41733. this.xref.stream.getMissingChunks().length === 0) {
  41734. this.capability.resolve();
  41735. return this.capability.promise;
  41736. }
  41737. this.refSet = new RefSet();
  41738. // Setup the initial nodes to visit.
  41739. var nodesToVisit = [];
  41740. for (var i = 0; i < keys.length; i++) {
  41741. nodesToVisit.push(this.obj[keys[i]]);
  41742. }
  41743. this._walk(nodesToVisit);
  41744. return this.capability.promise;
  41745. },
  41746. _walk: function ObjectLoader_walk(nodesToVisit) {
  41747. var nodesToRevisit = [];
  41748. var pendingRequests = [];
  41749. // DFS walk of the object graph.
  41750. while (nodesToVisit.length) {
  41751. var currentNode = nodesToVisit.pop();
  41752. // Only references or chunked streams can cause missing data exceptions.
  41753. if (isRef(currentNode)) {
  41754. // Skip nodes that have already been visited.
  41755. if (this.refSet.has(currentNode)) {
  41756. continue;
  41757. }
  41758. try {
  41759. var ref = currentNode;
  41760. this.refSet.put(ref);
  41761. currentNode = this.xref.fetch(currentNode);
  41762. } catch (e) {
  41763. if (!(e instanceof MissingDataException)) {
  41764. throw e;
  41765. }
  41766. nodesToRevisit.push(currentNode);
  41767. pendingRequests.push({ begin: e.begin, end: e.end });
  41768. }
  41769. }
  41770. if (currentNode && currentNode.getBaseStreams) {
  41771. var baseStreams = currentNode.getBaseStreams();
  41772. var foundMissingData = false;
  41773. for (var i = 0; i < baseStreams.length; i++) {
  41774. var stream = baseStreams[i];
  41775. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  41776. foundMissingData = true;
  41777. pendingRequests.push({
  41778. begin: stream.start,
  41779. end: stream.end
  41780. });
  41781. }
  41782. }
  41783. if (foundMissingData) {
  41784. nodesToRevisit.push(currentNode);
  41785. }
  41786. }
  41787. addChildren(currentNode, nodesToVisit);
  41788. }
  41789. if (pendingRequests.length) {
  41790. this.xref.stream.manager.requestRanges(pendingRequests).then(
  41791. function pendingRequestCallback() {
  41792. nodesToVisit = nodesToRevisit;
  41793. for (var i = 0; i < nodesToRevisit.length; i++) {
  41794. var node = nodesToRevisit[i];
  41795. // Remove any reference nodes from the currrent refset so they
  41796. // aren't skipped when we revist them.
  41797. if (isRef(node)) {
  41798. this.refSet.remove(node);
  41799. }
  41800. }
  41801. this._walk(nodesToVisit);
  41802. }.bind(this), this.capability.reject);
  41803. return;
  41804. }
  41805. // Everything is loaded.
  41806. this.refSet = null;
  41807. this.capability.resolve();
  41808. }
  41809. };
  41810. return ObjectLoader;
  41811. })();
  41812. exports.Catalog = Catalog;
  41813. exports.ObjectLoader = ObjectLoader;
  41814. exports.XRef = XRef;
  41815. exports.FileSpec = FileSpec;
  41816. }));
  41817. (function (root, factory) {
  41818. {
  41819. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41820. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41821. root.pdfjsCoreColorSpace);
  41822. }
  41823. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41824. coreColorSpace) {
  41825. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41826. var MissingDataException = sharedUtil.MissingDataException;
  41827. var Util = sharedUtil.Util;
  41828. var assert = sharedUtil.assert;
  41829. var error = sharedUtil.error;
  41830. var info = sharedUtil.info;
  41831. var warn = sharedUtil.warn;
  41832. var isStream = corePrimitives.isStream;
  41833. var PDFFunction = coreFunction.PDFFunction;
  41834. var ColorSpace = coreColorSpace.ColorSpace;
  41835. var ShadingType = {
  41836. FUNCTION_BASED: 1,
  41837. AXIAL: 2,
  41838. RADIAL: 3,
  41839. FREE_FORM_MESH: 4,
  41840. LATTICE_FORM_MESH: 5,
  41841. COONS_PATCH_MESH: 6,
  41842. TENSOR_PATCH_MESH: 7
  41843. };
  41844. var Pattern = (function PatternClosure() {
  41845. // Constructor should define this.getPattern
  41846. function Pattern() {
  41847. error('should not call Pattern constructor');
  41848. }
  41849. Pattern.prototype = {
  41850. // Input: current Canvas context
  41851. // Output: the appropriate fillStyle or strokeStyle
  41852. getPattern: function Pattern_getPattern(ctx) {
  41853. error('Should not call Pattern.getStyle: ' + ctx);
  41854. }
  41855. };
  41856. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41857. res, handler) {
  41858. var dict = isStream(shading) ? shading.dict : shading;
  41859. var type = dict.get('ShadingType');
  41860. try {
  41861. switch (type) {
  41862. case ShadingType.AXIAL:
  41863. case ShadingType.RADIAL:
  41864. // Both radial and axial shadings are handled by RadialAxial shading.
  41865. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41866. case ShadingType.FREE_FORM_MESH:
  41867. case ShadingType.LATTICE_FORM_MESH:
  41868. case ShadingType.COONS_PATCH_MESH:
  41869. case ShadingType.TENSOR_PATCH_MESH:
  41870. return new Shadings.Mesh(shading, matrix, xref, res);
  41871. default:
  41872. throw new Error('Unsupported ShadingType: ' + type);
  41873. }
  41874. } catch (ex) {
  41875. if (ex instanceof MissingDataException) {
  41876. throw ex;
  41877. }
  41878. handler.send('UnsupportedFeature',
  41879. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41880. warn(ex);
  41881. return new Shadings.Dummy();
  41882. }
  41883. };
  41884. return Pattern;
  41885. })();
  41886. var Shadings = {};
  41887. // A small number to offset the first/last color stops so we can insert ones to
  41888. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41889. Shadings.SMALL_NUMBER = 1e-6;
  41890. // Radial and axial shading have very similar implementations
  41891. // If needed, the implementations can be broken into two classes
  41892. Shadings.RadialAxial = (function RadialAxialClosure() {
  41893. function RadialAxial(dict, matrix, xref, res) {
  41894. this.matrix = matrix;
  41895. this.coordsArr = dict.getArray('Coords');
  41896. this.shadingType = dict.get('ShadingType');
  41897. this.type = 'Pattern';
  41898. var cs = dict.get('ColorSpace', 'CS');
  41899. cs = ColorSpace.parse(cs, xref, res);
  41900. this.cs = cs;
  41901. var t0 = 0.0, t1 = 1.0;
  41902. if (dict.has('Domain')) {
  41903. var domainArr = dict.getArray('Domain');
  41904. t0 = domainArr[0];
  41905. t1 = domainArr[1];
  41906. }
  41907. var extendStart = false, extendEnd = false;
  41908. if (dict.has('Extend')) {
  41909. var extendArr = dict.getArray('Extend');
  41910. extendStart = extendArr[0];
  41911. extendEnd = extendArr[1];
  41912. }
  41913. if (this.shadingType === ShadingType.RADIAL &&
  41914. (!extendStart || !extendEnd)) {
  41915. // Radial gradient only currently works if either circle is fully within
  41916. // the other circle.
  41917. var x1 = this.coordsArr[0];
  41918. var y1 = this.coordsArr[1];
  41919. var r1 = this.coordsArr[2];
  41920. var x2 = this.coordsArr[3];
  41921. var y2 = this.coordsArr[4];
  41922. var r2 = this.coordsArr[5];
  41923. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  41924. if (r1 <= r2 + distance &&
  41925. r2 <= r1 + distance) {
  41926. warn('Unsupported radial gradient.');
  41927. }
  41928. }
  41929. this.extendStart = extendStart;
  41930. this.extendEnd = extendEnd;
  41931. var fnObj = dict.get('Function');
  41932. var fn = PDFFunction.parseArray(xref, fnObj);
  41933. // 10 samples seems good enough for now, but probably won't work
  41934. // if there are sharp color changes. Ideally, we would implement
  41935. // the spec faithfully and add lossless optimizations.
  41936. var diff = t1 - t0;
  41937. var step = diff / 10;
  41938. var colorStops = this.colorStops = [];
  41939. // Protect against bad domains so we don't end up in an infinte loop below.
  41940. if (t0 >= t1 || step <= 0) {
  41941. // Acrobat doesn't seem to handle these cases so we'll ignore for
  41942. // now.
  41943. info('Bad shading domain.');
  41944. return;
  41945. }
  41946. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  41947. var rgbColor;
  41948. for (var i = t0; i <= t1; i += step) {
  41949. ratio[0] = i;
  41950. fn(ratio, 0, color, 0);
  41951. rgbColor = cs.getRgb(color, 0);
  41952. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41953. colorStops.push([(i - t0) / diff, cssColor]);
  41954. }
  41955. var background = 'transparent';
  41956. if (dict.has('Background')) {
  41957. rgbColor = cs.getRgb(dict.get('Background'), 0);
  41958. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41959. }
  41960. if (!extendStart) {
  41961. // Insert a color stop at the front and offset the first real color stop
  41962. // so it doesn't conflict with the one we insert.
  41963. colorStops.unshift([0, background]);
  41964. colorStops[1][0] += Shadings.SMALL_NUMBER;
  41965. }
  41966. if (!extendEnd) {
  41967. // Same idea as above in extendStart but for the end.
  41968. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  41969. colorStops.push([1, background]);
  41970. }
  41971. this.colorStops = colorStops;
  41972. }
  41973. RadialAxial.prototype = {
  41974. getIR: function RadialAxial_getIR() {
  41975. var coordsArr = this.coordsArr;
  41976. var shadingType = this.shadingType;
  41977. var type, p0, p1, r0, r1;
  41978. if (shadingType === ShadingType.AXIAL) {
  41979. p0 = [coordsArr[0], coordsArr[1]];
  41980. p1 = [coordsArr[2], coordsArr[3]];
  41981. r0 = null;
  41982. r1 = null;
  41983. type = 'axial';
  41984. } else if (shadingType === ShadingType.RADIAL) {
  41985. p0 = [coordsArr[0], coordsArr[1]];
  41986. p1 = [coordsArr[3], coordsArr[4]];
  41987. r0 = coordsArr[2];
  41988. r1 = coordsArr[5];
  41989. type = 'radial';
  41990. } else {
  41991. error('getPattern type unknown: ' + shadingType);
  41992. }
  41993. var matrix = this.matrix;
  41994. if (matrix) {
  41995. p0 = Util.applyTransform(p0, matrix);
  41996. p1 = Util.applyTransform(p1, matrix);
  41997. if (shadingType === ShadingType.RADIAL) {
  41998. var scale = Util.singularValueDecompose2dScale(matrix);
  41999. r0 *= scale[0];
  42000. r1 *= scale[1];
  42001. }
  42002. }
  42003. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  42004. }
  42005. };
  42006. return RadialAxial;
  42007. })();
  42008. // All mesh shading. For now, they will be presented as set of the triangles
  42009. // to be drawn on the canvas and rgb color for each vertex.
  42010. Shadings.Mesh = (function MeshClosure() {
  42011. function MeshStreamReader(stream, context) {
  42012. this.stream = stream;
  42013. this.context = context;
  42014. this.buffer = 0;
  42015. this.bufferLength = 0;
  42016. var numComps = context.numComps;
  42017. this.tmpCompsBuf = new Float32Array(numComps);
  42018. var csNumComps = context.colorSpace.numComps;
  42019. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  42020. this.tmpCompsBuf;
  42021. }
  42022. MeshStreamReader.prototype = {
  42023. get hasData() {
  42024. if (this.stream.end) {
  42025. return this.stream.pos < this.stream.end;
  42026. }
  42027. if (this.bufferLength > 0) {
  42028. return true;
  42029. }
  42030. var nextByte = this.stream.getByte();
  42031. if (nextByte < 0) {
  42032. return false;
  42033. }
  42034. this.buffer = nextByte;
  42035. this.bufferLength = 8;
  42036. return true;
  42037. },
  42038. readBits: function MeshStreamReader_readBits(n) {
  42039. var buffer = this.buffer;
  42040. var bufferLength = this.bufferLength;
  42041. if (n === 32) {
  42042. if (bufferLength === 0) {
  42043. return ((this.stream.getByte() << 24) |
  42044. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  42045. this.stream.getByte()) >>> 0;
  42046. }
  42047. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  42048. (this.stream.getByte() << 8) | this.stream.getByte();
  42049. var nextByte = this.stream.getByte();
  42050. this.buffer = nextByte & ((1 << bufferLength) - 1);
  42051. return ((buffer << (8 - bufferLength)) |
  42052. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  42053. }
  42054. if (n === 8 && bufferLength === 0) {
  42055. return this.stream.getByte();
  42056. }
  42057. while (bufferLength < n) {
  42058. buffer = (buffer << 8) | this.stream.getByte();
  42059. bufferLength += 8;
  42060. }
  42061. bufferLength -= n;
  42062. this.bufferLength = bufferLength;
  42063. this.buffer = buffer & ((1 << bufferLength) - 1);
  42064. return buffer >> bufferLength;
  42065. },
  42066. align: function MeshStreamReader_align() {
  42067. this.buffer = 0;
  42068. this.bufferLength = 0;
  42069. },
  42070. readFlag: function MeshStreamReader_readFlag() {
  42071. return this.readBits(this.context.bitsPerFlag);
  42072. },
  42073. readCoordinate: function MeshStreamReader_readCoordinate() {
  42074. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  42075. var xi = this.readBits(bitsPerCoordinate);
  42076. var yi = this.readBits(bitsPerCoordinate);
  42077. var decode = this.context.decode;
  42078. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  42079. 2.3283064365386963e-10; // 2 ^ -32
  42080. return [
  42081. xi * scale * (decode[1] - decode[0]) + decode[0],
  42082. yi * scale * (decode[3] - decode[2]) + decode[2]
  42083. ];
  42084. },
  42085. readComponents: function MeshStreamReader_readComponents() {
  42086. var numComps = this.context.numComps;
  42087. var bitsPerComponent = this.context.bitsPerComponent;
  42088. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  42089. 2.3283064365386963e-10; // 2 ^ -32
  42090. var decode = this.context.decode;
  42091. var components = this.tmpCompsBuf;
  42092. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  42093. var ci = this.readBits(bitsPerComponent);
  42094. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  42095. }
  42096. var color = this.tmpCsCompsBuf;
  42097. if (this.context.colorFn) {
  42098. this.context.colorFn(components, 0, color, 0);
  42099. }
  42100. return this.context.colorSpace.getRgb(color, 0);
  42101. }
  42102. };
  42103. function decodeType4Shading(mesh, reader) {
  42104. var coords = mesh.coords;
  42105. var colors = mesh.colors;
  42106. var operators = [];
  42107. var ps = []; // not maintaining cs since that will match ps
  42108. var verticesLeft = 0; // assuming we have all data to start a new triangle
  42109. while (reader.hasData) {
  42110. var f = reader.readFlag();
  42111. var coord = reader.readCoordinate();
  42112. var color = reader.readComponents();
  42113. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  42114. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  42115. switch (f) {
  42116. case 0:
  42117. verticesLeft = 3;
  42118. break;
  42119. case 1:
  42120. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  42121. verticesLeft = 1;
  42122. break;
  42123. case 2:
  42124. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  42125. verticesLeft = 1;
  42126. break;
  42127. }
  42128. operators.push(f);
  42129. }
  42130. ps.push(coords.length);
  42131. coords.push(coord);
  42132. colors.push(color);
  42133. verticesLeft--;
  42134. reader.align();
  42135. }
  42136. mesh.figures.push({
  42137. type: 'triangles',
  42138. coords: new Int32Array(ps),
  42139. colors: new Int32Array(ps),
  42140. });
  42141. }
  42142. function decodeType5Shading(mesh, reader, verticesPerRow) {
  42143. var coords = mesh.coords;
  42144. var colors = mesh.colors;
  42145. var ps = []; // not maintaining cs since that will match ps
  42146. while (reader.hasData) {
  42147. var coord = reader.readCoordinate();
  42148. var color = reader.readComponents();
  42149. ps.push(coords.length);
  42150. coords.push(coord);
  42151. colors.push(color);
  42152. }
  42153. mesh.figures.push({
  42154. type: 'lattice',
  42155. coords: new Int32Array(ps),
  42156. colors: new Int32Array(ps),
  42157. verticesPerRow: verticesPerRow
  42158. });
  42159. }
  42160. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  42161. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  42162. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  42163. var getB = (function getBClosure() {
  42164. function buildB(count) {
  42165. var lut = [];
  42166. for (var i = 0; i <= count; i++) {
  42167. var t = i / count, t_ = 1 - t;
  42168. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  42169. 3 * t * t * t_, t * t * t]));
  42170. }
  42171. return lut;
  42172. }
  42173. var cache = [];
  42174. return function getB(count) {
  42175. if (!cache[count]) {
  42176. cache[count] = buildB(count);
  42177. }
  42178. return cache[count];
  42179. };
  42180. })();
  42181. function buildFigureFromPatch(mesh, index) {
  42182. var figure = mesh.figures[index];
  42183. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  42184. var coords = mesh.coords, colors = mesh.colors;
  42185. var pi = figure.coords;
  42186. var ci = figure.colors;
  42187. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  42188. coords[pi[12]][0], coords[pi[15]][0]);
  42189. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  42190. coords[pi[12]][1], coords[pi[15]][1]);
  42191. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  42192. coords[pi[12]][0], coords[pi[15]][0]);
  42193. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  42194. coords[pi[12]][1], coords[pi[15]][1]);
  42195. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  42196. (mesh.bounds[2] - mesh.bounds[0]));
  42197. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42198. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  42199. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  42200. (mesh.bounds[3] - mesh.bounds[1]));
  42201. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42202. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  42203. var verticesPerRow = splitXBy + 1;
  42204. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  42205. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  42206. var k = 0;
  42207. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  42208. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  42209. c2 = colors[ci[2]], c3 = colors[ci[3]];
  42210. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  42211. for (var row = 0; row <= splitYBy; row++) {
  42212. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  42213. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  42214. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  42215. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  42216. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  42217. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  42218. for (var col = 0; col <= splitXBy; col++, k++) {
  42219. if ((row === 0 || row === splitYBy) &&
  42220. (col === 0 || col === splitXBy)) {
  42221. continue;
  42222. }
  42223. var x = 0, y = 0;
  42224. var q = 0;
  42225. for (var i = 0; i <= 3; i++) {
  42226. for (var j = 0; j <= 3; j++, q++) {
  42227. var m = bRow[row][i] * bCol[col][j];
  42228. x += coords[pi[q]][0] * m;
  42229. y += coords[pi[q]][1] * m;
  42230. }
  42231. }
  42232. figureCoords[k] = coords.length;
  42233. coords.push([x, y]);
  42234. figureColors[k] = colors.length;
  42235. var newColor = new Uint8Array(3);
  42236. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  42237. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  42238. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  42239. colors.push(newColor);
  42240. }
  42241. }
  42242. figureCoords[0] = pi[0];
  42243. figureColors[0] = ci[0];
  42244. figureCoords[splitXBy] = pi[3];
  42245. figureColors[splitXBy] = ci[1];
  42246. figureCoords[verticesPerRow * splitYBy] = pi[12];
  42247. figureColors[verticesPerRow * splitYBy] = ci[2];
  42248. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  42249. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  42250. mesh.figures[index] = {
  42251. type: 'lattice',
  42252. coords: figureCoords,
  42253. colors: figureColors,
  42254. verticesPerRow: verticesPerRow
  42255. };
  42256. }
  42257. function decodeType6Shading(mesh, reader) {
  42258. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  42259. var coords = mesh.coords;
  42260. var colors = mesh.colors;
  42261. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42262. var cs = new Int32Array(4); // c00, c30, c03, c33
  42263. while (reader.hasData) {
  42264. var f = reader.readFlag();
  42265. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  42266. var i, ii;
  42267. var pi = coords.length;
  42268. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  42269. coords.push(reader.readCoordinate());
  42270. }
  42271. var ci = colors.length;
  42272. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42273. colors.push(reader.readComponents());
  42274. }
  42275. var tmp1, tmp2, tmp3, tmp4;
  42276. switch (f) {
  42277. case 0:
  42278. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42279. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  42280. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  42281. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42282. cs[2] = ci + 1; cs[3] = ci + 2;
  42283. cs[0] = ci; cs[1] = ci + 3;
  42284. break;
  42285. case 1:
  42286. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42287. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42288. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42289. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42290. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42291. tmp1 = cs[2]; tmp2 = cs[3];
  42292. cs[2] = tmp2; cs[3] = ci;
  42293. cs[0] = tmp1; cs[1] = ci + 1;
  42294. break;
  42295. case 2:
  42296. tmp1 = ps[15];
  42297. tmp2 = ps[11];
  42298. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42299. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42300. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42301. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42302. tmp1 = cs[3];
  42303. cs[2] = cs[1]; cs[3] = ci;
  42304. cs[0] = tmp1; cs[1] = ci + 1;
  42305. break;
  42306. case 3:
  42307. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42308. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42309. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  42310. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42311. cs[2] = cs[0]; cs[3] = ci;
  42312. cs[0] = cs[1]; cs[1] = ci + 1;
  42313. break;
  42314. }
  42315. // set p11, p12, p21, p22
  42316. ps[5] = coords.length;
  42317. coords.push([
  42318. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  42319. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  42320. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42321. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  42322. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  42323. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  42324. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42325. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  42326. ]);
  42327. ps[6] = coords.length;
  42328. coords.push([
  42329. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  42330. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  42331. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42332. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  42333. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  42334. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  42335. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42336. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  42337. ]);
  42338. ps[9] = coords.length;
  42339. coords.push([
  42340. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  42341. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  42342. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42343. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  42344. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  42345. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  42346. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42347. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  42348. ]);
  42349. ps[10] = coords.length;
  42350. coords.push([
  42351. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  42352. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  42353. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42354. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  42355. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  42356. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  42357. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42358. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  42359. ]);
  42360. mesh.figures.push({
  42361. type: 'patch',
  42362. coords: new Int32Array(ps), // making copies of ps and cs
  42363. colors: new Int32Array(cs)
  42364. });
  42365. }
  42366. }
  42367. function decodeType7Shading(mesh, reader) {
  42368. var coords = mesh.coords;
  42369. var colors = mesh.colors;
  42370. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42371. var cs = new Int32Array(4); // c00, c30, c03, c33
  42372. while (reader.hasData) {
  42373. var f = reader.readFlag();
  42374. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  42375. var i, ii;
  42376. var pi = coords.length;
  42377. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  42378. coords.push(reader.readCoordinate());
  42379. }
  42380. var ci = colors.length;
  42381. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42382. colors.push(reader.readComponents());
  42383. }
  42384. var tmp1, tmp2, tmp3, tmp4;
  42385. switch (f) {
  42386. case 0:
  42387. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42388. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  42389. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  42390. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42391. cs[2] = ci + 1; cs[3] = ci + 2;
  42392. cs[0] = ci; cs[1] = ci + 3;
  42393. break;
  42394. case 1:
  42395. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42396. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42397. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42398. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42399. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42400. tmp1 = cs[2]; tmp2 = cs[3];
  42401. cs[2] = tmp2; cs[3] = ci;
  42402. cs[0] = tmp1; cs[1] = ci + 1;
  42403. break;
  42404. case 2:
  42405. tmp1 = ps[15];
  42406. tmp2 = ps[11];
  42407. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42408. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42409. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42410. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42411. tmp1 = cs[3];
  42412. cs[2] = cs[1]; cs[3] = ci;
  42413. cs[0] = tmp1; cs[1] = ci + 1;
  42414. break;
  42415. case 3:
  42416. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42417. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42418. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42419. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42420. cs[2] = cs[0]; cs[3] = ci;
  42421. cs[0] = cs[1]; cs[1] = ci + 1;
  42422. break;
  42423. }
  42424. mesh.figures.push({
  42425. type: 'patch',
  42426. coords: new Int32Array(ps), // making copies of ps and cs
  42427. colors: new Int32Array(cs)
  42428. });
  42429. }
  42430. }
  42431. function updateBounds(mesh) {
  42432. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  42433. maxX = minX, maxY = minY;
  42434. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  42435. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  42436. minX = minX > x ? x : minX;
  42437. minY = minY > y ? y : minY;
  42438. maxX = maxX < x ? x : maxX;
  42439. maxY = maxY < y ? y : maxY;
  42440. }
  42441. mesh.bounds = [minX, minY, maxX, maxY];
  42442. }
  42443. function packData(mesh) {
  42444. var i, ii, j, jj;
  42445. var coords = mesh.coords;
  42446. var coordsPacked = new Float32Array(coords.length * 2);
  42447. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  42448. var xy = coords[i];
  42449. coordsPacked[j++] = xy[0];
  42450. coordsPacked[j++] = xy[1];
  42451. }
  42452. mesh.coords = coordsPacked;
  42453. var colors = mesh.colors;
  42454. var colorsPacked = new Uint8Array(colors.length * 3);
  42455. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  42456. var c = colors[i];
  42457. colorsPacked[j++] = c[0];
  42458. colorsPacked[j++] = c[1];
  42459. colorsPacked[j++] = c[2];
  42460. }
  42461. mesh.colors = colorsPacked;
  42462. var figures = mesh.figures;
  42463. for (i = 0, ii = figures.length; i < ii; i++) {
  42464. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  42465. for (j = 0, jj = ps.length; j < jj; j++) {
  42466. ps[j] *= 2;
  42467. cs[j] *= 3;
  42468. }
  42469. }
  42470. }
  42471. function Mesh(stream, matrix, xref, res) {
  42472. assert(isStream(stream), 'Mesh data is not a stream');
  42473. var dict = stream.dict;
  42474. this.matrix = matrix;
  42475. this.shadingType = dict.get('ShadingType');
  42476. this.type = 'Pattern';
  42477. this.bbox = dict.getArray('BBox');
  42478. var cs = dict.get('ColorSpace', 'CS');
  42479. cs = ColorSpace.parse(cs, xref, res);
  42480. this.cs = cs;
  42481. this.background = dict.has('Background') ?
  42482. cs.getRgb(dict.get('Background'), 0) : null;
  42483. var fnObj = dict.get('Function');
  42484. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  42485. this.coords = [];
  42486. this.colors = [];
  42487. this.figures = [];
  42488. var decodeContext = {
  42489. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  42490. bitsPerComponent: dict.get('BitsPerComponent'),
  42491. bitsPerFlag: dict.get('BitsPerFlag'),
  42492. decode: dict.getArray('Decode'),
  42493. colorFn: fn,
  42494. colorSpace: cs,
  42495. numComps: fn ? 1 : cs.numComps
  42496. };
  42497. var reader = new MeshStreamReader(stream, decodeContext);
  42498. var patchMesh = false;
  42499. switch (this.shadingType) {
  42500. case ShadingType.FREE_FORM_MESH:
  42501. decodeType4Shading(this, reader);
  42502. break;
  42503. case ShadingType.LATTICE_FORM_MESH:
  42504. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  42505. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  42506. decodeType5Shading(this, reader, verticesPerRow);
  42507. break;
  42508. case ShadingType.COONS_PATCH_MESH:
  42509. decodeType6Shading(this, reader);
  42510. patchMesh = true;
  42511. break;
  42512. case ShadingType.TENSOR_PATCH_MESH:
  42513. decodeType7Shading(this, reader);
  42514. patchMesh = true;
  42515. break;
  42516. default:
  42517. error('Unsupported mesh type.');
  42518. break;
  42519. }
  42520. if (patchMesh) {
  42521. // dirty bounds calculation for determining, how dense shall be triangles
  42522. updateBounds(this);
  42523. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  42524. buildFigureFromPatch(this, i);
  42525. }
  42526. }
  42527. // calculate bounds
  42528. updateBounds(this);
  42529. packData(this);
  42530. }
  42531. Mesh.prototype = {
  42532. getIR: function Mesh_getIR() {
  42533. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  42534. this.bounds, this.matrix, this.bbox, this.background];
  42535. }
  42536. };
  42537. return Mesh;
  42538. })();
  42539. Shadings.Dummy = (function DummyClosure() {
  42540. function Dummy() {
  42541. this.type = 'Pattern';
  42542. }
  42543. Dummy.prototype = {
  42544. getIR: function Dummy_getIR() {
  42545. return ['Dummy'];
  42546. }
  42547. };
  42548. return Dummy;
  42549. })();
  42550. function getTilingPatternIR(operatorList, dict, args) {
  42551. var matrix = dict.getArray('Matrix');
  42552. var bbox = dict.getArray('BBox');
  42553. var xstep = dict.get('XStep');
  42554. var ystep = dict.get('YStep');
  42555. var paintType = dict.get('PaintType');
  42556. var tilingType = dict.get('TilingType');
  42557. return [
  42558. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  42559. paintType, tilingType
  42560. ];
  42561. }
  42562. exports.Pattern = Pattern;
  42563. exports.getTilingPatternIR = getTilingPatternIR;
  42564. }));
  42565. (function (root, factory) {
  42566. {
  42567. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  42568. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  42569. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  42570. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  42571. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  42572. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  42573. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  42574. }
  42575. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  42576. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  42577. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  42578. coreEncodings, coreStandardFonts, coreUnicode,
  42579. coreGlyphList) {
  42580. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42581. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  42582. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  42583. var ImageKind = sharedUtil.ImageKind;
  42584. var OPS = sharedUtil.OPS;
  42585. var TextRenderingMode = sharedUtil.TextRenderingMode;
  42586. var Util = sharedUtil.Util;
  42587. var assert = sharedUtil.assert;
  42588. var createPromiseCapability = sharedUtil.createPromiseCapability;
  42589. var error = sharedUtil.error;
  42590. var info = sharedUtil.info;
  42591. var isArray = sharedUtil.isArray;
  42592. var isNum = sharedUtil.isNum;
  42593. var isString = sharedUtil.isString;
  42594. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  42595. var warn = sharedUtil.warn;
  42596. var Dict = corePrimitives.Dict;
  42597. var Name = corePrimitives.Name;
  42598. var isCmd = corePrimitives.isCmd;
  42599. var isDict = corePrimitives.isDict;
  42600. var isName = corePrimitives.isName;
  42601. var isRef = corePrimitives.isRef;
  42602. var isStream = corePrimitives.isStream;
  42603. var DecodeStream = coreStream.DecodeStream;
  42604. var JpegStream = coreStream.JpegStream;
  42605. var Stream = coreStream.Stream;
  42606. var Lexer = coreParser.Lexer;
  42607. var Parser = coreParser.Parser;
  42608. var isEOF = coreParser.isEOF;
  42609. var PDFImage = coreImage.PDFImage;
  42610. var ColorSpace = coreColorSpace.ColorSpace;
  42611. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  42612. var ErrorFont = coreFonts.ErrorFont;
  42613. var FontFlags = coreFonts.FontFlags;
  42614. var Font = coreFonts.Font;
  42615. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  42616. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  42617. var getFontType = coreFonts.getFontType;
  42618. var isPDFFunction = coreFunction.isPDFFunction;
  42619. var PDFFunction = coreFunction.PDFFunction;
  42620. var Pattern = corePattern.Pattern;
  42621. var getTilingPatternIR = corePattern.getTilingPatternIR;
  42622. var CMapFactory = coreCMap.CMapFactory;
  42623. var IdentityCMap = coreCMap.IdentityCMap;
  42624. var getMetrics = coreMetrics.getMetrics;
  42625. var bidi = coreBidi.bidi;
  42626. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  42627. var StandardEncoding = coreEncodings.StandardEncoding;
  42628. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42629. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42630. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42631. var getEncoding = coreEncodings.getEncoding;
  42632. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42633. var getSerifFonts = coreStandardFonts.getSerifFonts;
  42634. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  42635. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  42636. var reverseIfRtl = coreUnicode.reverseIfRtl;
  42637. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42638. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42639. var PartialEvaluator = (function PartialEvaluatorClosure() {
  42640. var DefaultPartialEvaluatorOptions = {
  42641. forceDataSchema: false,
  42642. maxImageSize: -1,
  42643. disableFontFace: false,
  42644. cMapOptions: { url: null, packed: false }
  42645. };
  42646. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  42647. this.xref = xref;
  42648. this.resources = resources;
  42649. this.handler = handler;
  42650. this.forceDataSchema = forceDataSchema;
  42651. }
  42652. NativeImageDecoder.prototype = {
  42653. canDecode: function (image) {
  42654. return image instanceof JpegStream &&
  42655. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  42656. },
  42657. decode: function (image) {
  42658. // For natively supported JPEGs send them to the main thread for decoding.
  42659. var dict = image.dict;
  42660. var colorSpace = dict.get('ColorSpace', 'CS');
  42661. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  42662. var numComps = colorSpace.numComps;
  42663. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  42664. [image.getIR(this.forceDataSchema), numComps]);
  42665. return decodePromise.then(function (message) {
  42666. var data = message.data;
  42667. return new Stream(data, 0, data.length, image.dict);
  42668. });
  42669. }
  42670. };
  42671. /**
  42672. * Checks if the image can be decoded and displayed by the browser without any
  42673. * further processing such as color space conversions.
  42674. */
  42675. NativeImageDecoder.isSupported =
  42676. function NativeImageDecoder_isSupported(image, xref, res) {
  42677. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  42678. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  42679. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  42680. };
  42681. /**
  42682. * Checks if the image can be decoded by the browser.
  42683. */
  42684. NativeImageDecoder.isDecodable =
  42685. function NativeImageDecoder_isDecodable(image, xref, res) {
  42686. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  42687. return (cs.numComps === 1 || cs.numComps === 3) &&
  42688. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  42689. };
  42690. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  42691. uniquePrefix, idCounters, fontCache, options) {
  42692. this.pdfManager = pdfManager;
  42693. this.xref = xref;
  42694. this.handler = handler;
  42695. this.pageIndex = pageIndex;
  42696. this.uniquePrefix = uniquePrefix;
  42697. this.idCounters = idCounters;
  42698. this.fontCache = fontCache;
  42699. this.options = options || DefaultPartialEvaluatorOptions;
  42700. }
  42701. // Trying to minimize Date.now() usage and check every 100 time
  42702. var TIME_SLOT_DURATION_MS = 20;
  42703. var CHECK_TIME_EVERY = 100;
  42704. function TimeSlotManager() {
  42705. this.reset();
  42706. }
  42707. TimeSlotManager.prototype = {
  42708. check: function TimeSlotManager_check() {
  42709. if (++this.checked < CHECK_TIME_EVERY) {
  42710. return false;
  42711. }
  42712. this.checked = 0;
  42713. return this.endTime <= Date.now();
  42714. },
  42715. reset: function TimeSlotManager_reset() {
  42716. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  42717. this.checked = 0;
  42718. }
  42719. };
  42720. var deferred = Promise.resolve();
  42721. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  42722. PartialEvaluator.prototype = {
  42723. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  42724. if (!isDict(resources)) {
  42725. return false;
  42726. }
  42727. var processed = Object.create(null);
  42728. if (resources.objId) {
  42729. processed[resources.objId] = true;
  42730. }
  42731. var nodes = [resources], xref = this.xref;
  42732. while (nodes.length) {
  42733. var key, i, ii;
  42734. var node = nodes.shift();
  42735. // First check the current resources for blend modes.
  42736. var graphicStates = node.get('ExtGState');
  42737. if (isDict(graphicStates)) {
  42738. var graphicStatesKeys = graphicStates.getKeys();
  42739. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  42740. key = graphicStatesKeys[i];
  42741. var graphicState = graphicStates.get(key);
  42742. var bm = graphicState.get('BM');
  42743. if (isName(bm) && bm.name !== 'Normal') {
  42744. return true;
  42745. }
  42746. }
  42747. }
  42748. // Descend into the XObjects to look for more resources and blend modes.
  42749. var xObjects = node.get('XObject');
  42750. if (!isDict(xObjects)) {
  42751. continue;
  42752. }
  42753. var xObjectsKeys = xObjects.getKeys();
  42754. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  42755. key = xObjectsKeys[i];
  42756. var xObject = xObjects.getRaw(key);
  42757. if (isRef(xObject)) {
  42758. if (processed[xObject.toString()]) {
  42759. // The XObject has already been processed, and by avoiding a
  42760. // redundant `xref.fetch` we can *significantly* reduce the load
  42761. // time for badly generated PDF files (fixes issue6961.pdf).
  42762. continue;
  42763. }
  42764. xObject = xref.fetch(xObject);
  42765. }
  42766. if (!isStream(xObject)) {
  42767. continue;
  42768. }
  42769. if (xObject.dict.objId) {
  42770. if (processed[xObject.dict.objId]) {
  42771. // stream has objId and is processed already
  42772. continue;
  42773. }
  42774. processed[xObject.dict.objId] = true;
  42775. }
  42776. var xResources = xObject.dict.get('Resources');
  42777. // Checking objId to detect an infinite loop.
  42778. if (isDict(xResources) &&
  42779. (!xResources.objId || !processed[xResources.objId])) {
  42780. nodes.push(xResources);
  42781. if (xResources.objId) {
  42782. processed[xResources.objId] = true;
  42783. }
  42784. }
  42785. }
  42786. }
  42787. return false;
  42788. },
  42789. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  42790. xobj, smask,
  42791. operatorList,
  42792. task,
  42793. initialState) {
  42794. var matrix = xobj.dict.getArray('Matrix');
  42795. var bbox = xobj.dict.getArray('BBox');
  42796. var group = xobj.dict.get('Group');
  42797. if (group) {
  42798. var groupOptions = {
  42799. matrix: matrix,
  42800. bbox: bbox,
  42801. smask: smask,
  42802. isolated: false,
  42803. knockout: false
  42804. };
  42805. var groupSubtype = group.get('S');
  42806. var colorSpace;
  42807. if (isName(groupSubtype, 'Transparency')) {
  42808. groupOptions.isolated = (group.get('I') || false);
  42809. groupOptions.knockout = (group.get('K') || false);
  42810. colorSpace = (group.has('CS') ?
  42811. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  42812. }
  42813. if (smask && smask.backdrop) {
  42814. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  42815. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  42816. }
  42817. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  42818. }
  42819. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  42820. return this.getOperatorList(xobj, task,
  42821. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  42822. then(function () {
  42823. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  42824. if (group) {
  42825. operatorList.addOp(OPS.endGroup, [groupOptions]);
  42826. }
  42827. });
  42828. },
  42829. buildPaintImageXObject:
  42830. function PartialEvaluator_buildPaintImageXObject(resources, image,
  42831. inline, operatorList,
  42832. cacheKey, imageCache) {
  42833. var self = this;
  42834. var dict = image.dict;
  42835. var w = dict.get('Width', 'W');
  42836. var h = dict.get('Height', 'H');
  42837. if (!(w && isNum(w)) || !(h && isNum(h))) {
  42838. warn('Image dimensions are missing, or not numbers.');
  42839. return;
  42840. }
  42841. var maxImageSize = this.options.maxImageSize;
  42842. if (maxImageSize !== -1 && w * h > maxImageSize) {
  42843. warn('Image exceeded maximum allowed size and was removed.');
  42844. return;
  42845. }
  42846. var imageMask = (dict.get('ImageMask', 'IM') || false);
  42847. var imgData, args;
  42848. if (imageMask) {
  42849. // This depends on a tmpCanvas being filled with the
  42850. // current fillStyle, such that processing the pixel
  42851. // data can't be done here. Instead of creating a
  42852. // complete PDFImage, only read the information needed
  42853. // for later.
  42854. var width = dict.get('Width', 'W');
  42855. var height = dict.get('Height', 'H');
  42856. var bitStrideLength = (width + 7) >> 3;
  42857. var imgArray = image.getBytes(bitStrideLength * height);
  42858. var decode = dict.getArray('Decode', 'D');
  42859. var inverseDecode = (!!decode && decode[0] > 0);
  42860. imgData = PDFImage.createMask(imgArray, width, height,
  42861. image instanceof DecodeStream,
  42862. inverseDecode);
  42863. imgData.cached = true;
  42864. args = [imgData];
  42865. operatorList.addOp(OPS.paintImageMaskXObject, args);
  42866. if (cacheKey) {
  42867. imageCache[cacheKey] = {
  42868. fn: OPS.paintImageMaskXObject,
  42869. args: args
  42870. };
  42871. }
  42872. return;
  42873. }
  42874. var softMask = (dict.get('SMask', 'SM') || false);
  42875. var mask = (dict.get('Mask') || false);
  42876. var SMALL_IMAGE_DIMENSIONS = 200;
  42877. // Inlining small images into the queue as RGB data
  42878. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  42879. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  42880. var imageObj = new PDFImage(this.xref, resources, image,
  42881. inline, null, null);
  42882. // We force the use of RGBA_32BPP images here, because we can't handle
  42883. // any other kind.
  42884. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  42885. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  42886. return;
  42887. }
  42888. // If there is no imageMask, create the PDFImage and a lot
  42889. // of image processing can be done here.
  42890. var uniquePrefix = (this.uniquePrefix || '');
  42891. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  42892. operatorList.addDependency(objId);
  42893. args = [objId, w, h];
  42894. if (!softMask && !mask && image instanceof JpegStream &&
  42895. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  42896. // These JPEGs don't need any more processing so we can just send it.
  42897. operatorList.addOp(OPS.paintJpegXObject, args);
  42898. this.handler.send('obj',
  42899. [objId, this.pageIndex, 'JpegStream',
  42900. image.getIR(this.options.forceDataSchema)]);
  42901. return;
  42902. }
  42903. // Creates native image decoder only if a JPEG image or mask is present.
  42904. var nativeImageDecoder = null;
  42905. if (image instanceof JpegStream || mask instanceof JpegStream ||
  42906. softMask instanceof JpegStream) {
  42907. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  42908. self.handler, self.options.forceDataSchema);
  42909. }
  42910. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  42911. nativeImageDecoder).
  42912. then(function(imageObj) {
  42913. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  42914. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  42915. [imgData.data.buffer]);
  42916. }).then(undefined, function (reason) {
  42917. warn('Unable to decode image: ' + reason);
  42918. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  42919. });
  42920. operatorList.addOp(OPS.paintImageXObject, args);
  42921. if (cacheKey) {
  42922. imageCache[cacheKey] = {
  42923. fn: OPS.paintImageXObject,
  42924. args: args
  42925. };
  42926. }
  42927. },
  42928. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  42929. operatorList, task,
  42930. stateManager) {
  42931. var smaskContent = smask.get('G');
  42932. var smaskOptions = {
  42933. subtype: smask.get('S').name,
  42934. backdrop: smask.get('BC')
  42935. };
  42936. // The SMask might have a alpha/luminosity value transfer function --
  42937. // we will build a map of integer values in range 0..255 to be fast.
  42938. var transferObj = smask.get('TR');
  42939. if (isPDFFunction(transferObj)) {
  42940. var transferFn = PDFFunction.parse(this.xref, transferObj);
  42941. var transferMap = new Uint8Array(256);
  42942. var tmp = new Float32Array(1);
  42943. for (var i = 0; i < 256; i++) {
  42944. tmp[0] = i / 255;
  42945. transferFn(tmp, 0, tmp, 0);
  42946. transferMap[i] = (tmp[0] * 255) | 0;
  42947. }
  42948. smaskOptions.transferMap = transferMap;
  42949. }
  42950. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  42951. operatorList, task, stateManager.state.clone());
  42952. },
  42953. handleTilingType:
  42954. function PartialEvaluator_handleTilingType(fn, args, resources,
  42955. pattern, patternDict,
  42956. operatorList, task) {
  42957. // Create an IR of the pattern code.
  42958. var tilingOpList = new OperatorList();
  42959. // Merge the available resources, to prevent issues when the patternDict
  42960. // is missing some /Resources entries (fixes issue6541.pdf).
  42961. var resourcesArray = [patternDict.get('Resources'), resources];
  42962. var patternResources = Dict.merge(this.xref, resourcesArray);
  42963. return this.getOperatorList(pattern, task, patternResources,
  42964. tilingOpList).then(function () {
  42965. // Add the dependencies to the parent operator list so they are
  42966. // resolved before sub operator list is executed synchronously.
  42967. operatorList.addDependencies(tilingOpList.dependencies);
  42968. operatorList.addOp(fn, getTilingPatternIR({
  42969. fnArray: tilingOpList.fnArray,
  42970. argsArray: tilingOpList.argsArray
  42971. }, patternDict, args));
  42972. });
  42973. },
  42974. handleSetFont:
  42975. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  42976. operatorList, task, state) {
  42977. // TODO(mack): Not needed?
  42978. var fontName;
  42979. if (fontArgs) {
  42980. fontArgs = fontArgs.slice();
  42981. fontName = fontArgs[0].name;
  42982. }
  42983. var self = this;
  42984. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  42985. function (translated) {
  42986. if (!translated.font.isType3Font) {
  42987. return translated;
  42988. }
  42989. return translated.loadType3Data(self, resources, operatorList, task).
  42990. then(function () {
  42991. return translated;
  42992. }, function (reason) {
  42993. // Error in the font data -- sending unsupported feature notification.
  42994. self.handler.send('UnsupportedFeature',
  42995. {featureId: UNSUPPORTED_FEATURES.font});
  42996. return new TranslatedFont('g_font_error',
  42997. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  42998. });
  42999. }).then(function (translated) {
  43000. state.font = translated.font;
  43001. translated.send(self.handler);
  43002. return translated.loadedName;
  43003. });
  43004. },
  43005. handleText: function PartialEvaluator_handleText(chars, state) {
  43006. var font = state.font;
  43007. var glyphs = font.charsToGlyphs(chars);
  43008. var isAddToPathSet = !!(state.textRenderingMode &
  43009. TextRenderingMode.ADD_TO_PATH_FLAG);
  43010. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  43011. var buildPath = function (fontChar) {
  43012. if (!font.renderer.hasBuiltPath(fontChar)) {
  43013. var path = font.renderer.getPathJs(fontChar);
  43014. this.handler.send('commonobj', [
  43015. font.loadedName + '_path_' + fontChar,
  43016. 'FontPath',
  43017. path
  43018. ]);
  43019. }
  43020. }.bind(this);
  43021. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  43022. var glyph = glyphs[i];
  43023. buildPath(glyph.fontChar);
  43024. // If the glyph has an accent we need to build a path for its
  43025. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  43026. var accent = glyph.accent;
  43027. if (accent && accent.fontChar) {
  43028. buildPath(accent.fontChar);
  43029. }
  43030. }
  43031. }
  43032. return glyphs;
  43033. },
  43034. setGState: function PartialEvaluator_setGState(resources, gState,
  43035. operatorList, task,
  43036. xref, stateManager) {
  43037. // This array holds the converted/processed state data.
  43038. var gStateObj = [];
  43039. var gStateKeys = gState.getKeys();
  43040. var self = this;
  43041. var promise = Promise.resolve();
  43042. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  43043. var key = gStateKeys[i];
  43044. var value = gState.get(key);
  43045. switch (key) {
  43046. case 'Type':
  43047. break;
  43048. case 'LW':
  43049. case 'LC':
  43050. case 'LJ':
  43051. case 'ML':
  43052. case 'D':
  43053. case 'RI':
  43054. case 'FL':
  43055. case 'CA':
  43056. case 'ca':
  43057. gStateObj.push([key, value]);
  43058. break;
  43059. case 'Font':
  43060. promise = promise.then(function () {
  43061. return self.handleSetFont(resources, null, value[0], operatorList,
  43062. task, stateManager.state).
  43063. then(function (loadedName) {
  43064. operatorList.addDependency(loadedName);
  43065. gStateObj.push([key, [loadedName, value[1]]]);
  43066. });
  43067. });
  43068. break;
  43069. case 'BM':
  43070. gStateObj.push([key, value]);
  43071. break;
  43072. case 'SMask':
  43073. if (isName(value, 'None')) {
  43074. gStateObj.push([key, false]);
  43075. break;
  43076. }
  43077. if (isDict(value)) {
  43078. promise = promise.then(function (dict) {
  43079. return self.handleSMask(dict, resources, operatorList,
  43080. task, stateManager);
  43081. }.bind(this, value));
  43082. gStateObj.push([key, true]);
  43083. } else {
  43084. warn('Unsupported SMask type');
  43085. }
  43086. break;
  43087. // Only generate info log messages for the following since
  43088. // they are unlikely to have a big impact on the rendering.
  43089. case 'OP':
  43090. case 'op':
  43091. case 'OPM':
  43092. case 'BG':
  43093. case 'BG2':
  43094. case 'UCR':
  43095. case 'UCR2':
  43096. case 'TR':
  43097. case 'TR2':
  43098. case 'HT':
  43099. case 'SM':
  43100. case 'SA':
  43101. case 'AIS':
  43102. case 'TK':
  43103. // TODO implement these operators.
  43104. info('graphic state operator ' + key);
  43105. break;
  43106. default:
  43107. info('Unknown graphic state operator ' + key);
  43108. break;
  43109. }
  43110. }
  43111. return promise.then(function () {
  43112. if (gStateObj.length > 0) {
  43113. operatorList.addOp(OPS.setGState, [gStateObj]);
  43114. }
  43115. });
  43116. },
  43117. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  43118. resources) {
  43119. function errorFont() {
  43120. return Promise.resolve(new TranslatedFont('g_font_error',
  43121. new ErrorFont('Font ' + fontName + ' is not available'), font));
  43122. }
  43123. var fontRef;
  43124. if (font) { // Loading by ref.
  43125. assert(isRef(font));
  43126. fontRef = font;
  43127. } else { // Loading by name.
  43128. var fontRes = resources.get('Font');
  43129. if (fontRes) {
  43130. fontRef = fontRes.getRaw(fontName);
  43131. } else {
  43132. warn('fontRes not available');
  43133. return errorFont();
  43134. }
  43135. }
  43136. if (!fontRef) {
  43137. warn('fontRef not available');
  43138. return errorFont();
  43139. }
  43140. if (this.fontCache.has(fontRef)) {
  43141. return this.fontCache.get(fontRef);
  43142. }
  43143. font = xref.fetchIfRef(fontRef);
  43144. if (!isDict(font)) {
  43145. return errorFont();
  43146. }
  43147. // We are holding `font.translated` references just for `fontRef`s that
  43148. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  43149. if (font.translated) {
  43150. return font.translated;
  43151. }
  43152. var fontCapability = createPromiseCapability();
  43153. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  43154. var descriptor = preEvaluatedFont.descriptor;
  43155. var fontRefIsRef = isRef(fontRef), fontID;
  43156. if (fontRefIsRef) {
  43157. fontID = fontRef.toString();
  43158. }
  43159. if (isDict(descriptor)) {
  43160. if (!descriptor.fontAliases) {
  43161. descriptor.fontAliases = Object.create(null);
  43162. }
  43163. var fontAliases = descriptor.fontAliases;
  43164. var hash = preEvaluatedFont.hash;
  43165. if (fontAliases[hash]) {
  43166. var aliasFontRef = fontAliases[hash].aliasRef;
  43167. if (fontRefIsRef && aliasFontRef &&
  43168. this.fontCache.has(aliasFontRef)) {
  43169. this.fontCache.putAlias(fontRef, aliasFontRef);
  43170. return this.fontCache.get(fontRef);
  43171. }
  43172. } else {
  43173. fontAliases[hash] = {
  43174. fontID: Font.getFontID()
  43175. };
  43176. }
  43177. if (fontRefIsRef) {
  43178. fontAliases[hash].aliasRef = fontRef;
  43179. }
  43180. fontID = fontAliases[hash].fontID;
  43181. }
  43182. // Workaround for bad PDF generators that reference fonts incorrectly,
  43183. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  43184. // In this case we should not put the font into `this.fontCache` (which is
  43185. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  43186. //
  43187. // However, if we don't cache the font it's not possible to remove it
  43188. // when `cleanup` is triggered from the API, which causes issues on
  43189. // subsequent rendering operations (see issue7403.pdf).
  43190. // A simple workaround would be to just not hold `font.translated`
  43191. // references in this case, but this would force us to unnecessarily load
  43192. // the same fonts over and over.
  43193. //
  43194. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  43195. // key in `this.fontCache`, to allow the font to be cached.
  43196. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  43197. // keys. Also, since `fontRef` is used when getting cached fonts,
  43198. // we'll not accidentally match fonts cached with the `fontID`.
  43199. if (fontRefIsRef) {
  43200. this.fontCache.put(fontRef, fontCapability.promise);
  43201. } else {
  43202. if (!fontID) {
  43203. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  43204. }
  43205. this.fontCache.put('id_' + fontID, fontCapability.promise);
  43206. }
  43207. assert(fontID, 'The "fontID" must be defined.');
  43208. // Keep track of each font we translated so the caller can
  43209. // load them asynchronously before calling display on a page.
  43210. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  43211. font.translated = fontCapability.promise;
  43212. // TODO move promises into translate font
  43213. var translatedPromise;
  43214. try {
  43215. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  43216. } catch (e) {
  43217. translatedPromise = Promise.reject(e);
  43218. }
  43219. var self = this;
  43220. translatedPromise.then(function (translatedFont) {
  43221. if (translatedFont.fontType !== undefined) {
  43222. var xrefFontStats = xref.stats.fontTypes;
  43223. xrefFontStats[translatedFont.fontType] = true;
  43224. }
  43225. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43226. translatedFont, font));
  43227. }, function (reason) {
  43228. // TODO fontCapability.reject?
  43229. // Error in the font data -- sending unsupported feature notification.
  43230. self.handler.send('UnsupportedFeature',
  43231. {featureId: UNSUPPORTED_FEATURES.font});
  43232. try {
  43233. // error, but it's still nice to have font type reported
  43234. var descriptor = preEvaluatedFont.descriptor;
  43235. var fontFile3 = descriptor && descriptor.get('FontFile3');
  43236. var subtype = fontFile3 && fontFile3.get('Subtype');
  43237. var fontType = getFontType(preEvaluatedFont.type,
  43238. subtype && subtype.name);
  43239. var xrefFontStats = xref.stats.fontTypes;
  43240. xrefFontStats[fontType] = true;
  43241. } catch (ex) { }
  43242. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43243. new ErrorFont(reason instanceof Error ? reason.message : reason),
  43244. font));
  43245. });
  43246. return fontCapability.promise;
  43247. },
  43248. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  43249. var lastIndex = operatorList.length - 1;
  43250. if (!args) {
  43251. args = [];
  43252. }
  43253. if (lastIndex < 0 ||
  43254. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  43255. operatorList.addOp(OPS.constructPath, [[fn], args]);
  43256. } else {
  43257. var opArgs = operatorList.argsArray[lastIndex];
  43258. opArgs[0].push(fn);
  43259. Array.prototype.push.apply(opArgs[1], args);
  43260. }
  43261. },
  43262. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  43263. cs, patterns, resources, task, xref) {
  43264. // compile tiling patterns
  43265. var patternName = args[args.length - 1];
  43266. // SCN/scn applies patterns along with normal colors
  43267. var pattern;
  43268. if (isName(patternName) &&
  43269. (pattern = patterns.get(patternName.name))) {
  43270. var dict = (isStream(pattern) ? pattern.dict : pattern);
  43271. var typeNum = dict.get('PatternType');
  43272. if (typeNum === TILING_PATTERN) {
  43273. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  43274. return this.handleTilingType(fn, color, resources, pattern,
  43275. dict, operatorList, task);
  43276. } else if (typeNum === SHADING_PATTERN) {
  43277. var shading = dict.get('Shading');
  43278. var matrix = dict.getArray('Matrix');
  43279. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  43280. this.handler);
  43281. operatorList.addOp(fn, pattern.getIR());
  43282. return Promise.resolve();
  43283. } else {
  43284. return Promise.reject('Unknown PatternType: ' + typeNum);
  43285. }
  43286. }
  43287. // TODO shall we fail here?
  43288. operatorList.addOp(fn, args);
  43289. return Promise.resolve();
  43290. },
  43291. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  43292. task,
  43293. resources,
  43294. operatorList,
  43295. initialState) {
  43296. var self = this;
  43297. var xref = this.xref;
  43298. var imageCache = Object.create(null);
  43299. assert(operatorList);
  43300. resources = (resources || Dict.empty);
  43301. var xobjs = (resources.get('XObject') || Dict.empty);
  43302. var patterns = (resources.get('Pattern') || Dict.empty);
  43303. var stateManager = new StateManager(initialState || new EvalState());
  43304. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43305. var timeSlotManager = new TimeSlotManager();
  43306. return new Promise(function promiseBody(resolve, reject) {
  43307. var next = function (promise) {
  43308. promise.then(function () {
  43309. try {
  43310. promiseBody(resolve, reject);
  43311. } catch (ex) {
  43312. reject(ex);
  43313. }
  43314. }, reject);
  43315. };
  43316. task.ensureNotTerminated();
  43317. timeSlotManager.reset();
  43318. var stop, operation = {}, i, ii, cs;
  43319. while (!(stop = timeSlotManager.check())) {
  43320. // The arguments parsed by read() are used beyond this loop, so we
  43321. // cannot reuse the same array on each iteration. Therefore we pass
  43322. // in |null| as the initial value (see the comment on
  43323. // EvaluatorPreprocessor_read() for why).
  43324. operation.args = null;
  43325. if (!(preprocessor.read(operation))) {
  43326. break;
  43327. }
  43328. var args = operation.args;
  43329. var fn = operation.fn;
  43330. switch (fn | 0) {
  43331. case OPS.paintXObject:
  43332. if (args[0].code) {
  43333. break;
  43334. }
  43335. // eagerly compile XForm objects
  43336. var name = args[0].name;
  43337. if (!name) {
  43338. warn('XObject must be referred to by name.');
  43339. continue;
  43340. }
  43341. if (imageCache[name] !== undefined) {
  43342. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  43343. args = null;
  43344. continue;
  43345. }
  43346. var xobj = xobjs.get(name);
  43347. if (xobj) {
  43348. assert(isStream(xobj), 'XObject should be a stream');
  43349. var type = xobj.dict.get('Subtype');
  43350. assert(isName(type), 'XObject should have a Name subtype');
  43351. if (type.name === 'Form') {
  43352. stateManager.save();
  43353. next(self.buildFormXObject(resources, xobj, null,
  43354. operatorList, task,
  43355. stateManager.state.clone()).
  43356. then(function () {
  43357. stateManager.restore();
  43358. }));
  43359. return;
  43360. } else if (type.name === 'Image') {
  43361. self.buildPaintImageXObject(resources, xobj, false,
  43362. operatorList, name, imageCache);
  43363. args = null;
  43364. continue;
  43365. } else if (type.name === 'PS') {
  43366. // PostScript XObjects are unused when viewing documents.
  43367. // See section 4.7.1 of Adobe's PDF reference.
  43368. info('Ignored XObject subtype PS');
  43369. continue;
  43370. } else {
  43371. error('Unhandled XObject subtype ' + type.name);
  43372. }
  43373. }
  43374. break;
  43375. case OPS.setFont:
  43376. var fontSize = args[1];
  43377. // eagerly collect all fonts
  43378. next(self.handleSetFont(resources, args, null, operatorList,
  43379. task, stateManager.state).
  43380. then(function (loadedName) {
  43381. operatorList.addDependency(loadedName);
  43382. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  43383. }));
  43384. return;
  43385. case OPS.endInlineImage:
  43386. var cacheKey = args[0].cacheKey;
  43387. if (cacheKey) {
  43388. var cacheEntry = imageCache[cacheKey];
  43389. if (cacheEntry !== undefined) {
  43390. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  43391. args = null;
  43392. continue;
  43393. }
  43394. }
  43395. self.buildPaintImageXObject(resources, args[0], true,
  43396. operatorList, cacheKey, imageCache);
  43397. args = null;
  43398. continue;
  43399. case OPS.showText:
  43400. args[0] = self.handleText(args[0], stateManager.state);
  43401. break;
  43402. case OPS.showSpacedText:
  43403. var arr = args[0];
  43404. var combinedGlyphs = [];
  43405. var arrLength = arr.length;
  43406. var state = stateManager.state;
  43407. for (i = 0; i < arrLength; ++i) {
  43408. var arrItem = arr[i];
  43409. if (isString(arrItem)) {
  43410. Array.prototype.push.apply(combinedGlyphs,
  43411. self.handleText(arrItem, state));
  43412. } else if (isNum(arrItem)) {
  43413. combinedGlyphs.push(arrItem);
  43414. }
  43415. }
  43416. args[0] = combinedGlyphs;
  43417. fn = OPS.showText;
  43418. break;
  43419. case OPS.nextLineShowText:
  43420. operatorList.addOp(OPS.nextLine);
  43421. args[0] = self.handleText(args[0], stateManager.state);
  43422. fn = OPS.showText;
  43423. break;
  43424. case OPS.nextLineSetSpacingShowText:
  43425. operatorList.addOp(OPS.nextLine);
  43426. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  43427. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  43428. args[0] = self.handleText(args[0], stateManager.state);
  43429. fn = OPS.showText;
  43430. break;
  43431. case OPS.setTextRenderingMode:
  43432. stateManager.state.textRenderingMode = args[0];
  43433. break;
  43434. case OPS.setFillColorSpace:
  43435. stateManager.state.fillColorSpace =
  43436. ColorSpace.parse(args[0], xref, resources);
  43437. continue;
  43438. case OPS.setStrokeColorSpace:
  43439. stateManager.state.strokeColorSpace =
  43440. ColorSpace.parse(args[0], xref, resources);
  43441. continue;
  43442. case OPS.setFillColor:
  43443. cs = stateManager.state.fillColorSpace;
  43444. args = cs.getRgb(args, 0);
  43445. fn = OPS.setFillRGBColor;
  43446. break;
  43447. case OPS.setStrokeColor:
  43448. cs = stateManager.state.strokeColorSpace;
  43449. args = cs.getRgb(args, 0);
  43450. fn = OPS.setStrokeRGBColor;
  43451. break;
  43452. case OPS.setFillGray:
  43453. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  43454. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43455. fn = OPS.setFillRGBColor;
  43456. break;
  43457. case OPS.setStrokeGray:
  43458. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  43459. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43460. fn = OPS.setStrokeRGBColor;
  43461. break;
  43462. case OPS.setFillCMYKColor:
  43463. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  43464. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43465. fn = OPS.setFillRGBColor;
  43466. break;
  43467. case OPS.setStrokeCMYKColor:
  43468. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  43469. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43470. fn = OPS.setStrokeRGBColor;
  43471. break;
  43472. case OPS.setFillRGBColor:
  43473. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  43474. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43475. break;
  43476. case OPS.setStrokeRGBColor:
  43477. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  43478. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43479. break;
  43480. case OPS.setFillColorN:
  43481. cs = stateManager.state.fillColorSpace;
  43482. if (cs.name === 'Pattern') {
  43483. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  43484. cs, patterns, resources, task, xref));
  43485. return;
  43486. }
  43487. args = cs.getRgb(args, 0);
  43488. fn = OPS.setFillRGBColor;
  43489. break;
  43490. case OPS.setStrokeColorN:
  43491. cs = stateManager.state.strokeColorSpace;
  43492. if (cs.name === 'Pattern') {
  43493. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  43494. cs, patterns, resources, task, xref));
  43495. return;
  43496. }
  43497. args = cs.getRgb(args, 0);
  43498. fn = OPS.setStrokeRGBColor;
  43499. break;
  43500. case OPS.shadingFill:
  43501. var shadingRes = resources.get('Shading');
  43502. if (!shadingRes) {
  43503. error('No shading resource found');
  43504. }
  43505. var shading = shadingRes.get(args[0].name);
  43506. if (!shading) {
  43507. error('No shading object found');
  43508. }
  43509. var shadingFill = Pattern.parseShading(shading, null, xref,
  43510. resources, self.handler);
  43511. var patternIR = shadingFill.getIR();
  43512. args = [patternIR];
  43513. fn = OPS.shadingFill;
  43514. break;
  43515. case OPS.setGState:
  43516. var dictName = args[0];
  43517. var extGState = resources.get('ExtGState');
  43518. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43519. break;
  43520. }
  43521. var gState = extGState.get(dictName.name);
  43522. next(self.setGState(resources, gState, operatorList, task, xref,
  43523. stateManager));
  43524. return;
  43525. case OPS.moveTo:
  43526. case OPS.lineTo:
  43527. case OPS.curveTo:
  43528. case OPS.curveTo2:
  43529. case OPS.curveTo3:
  43530. case OPS.closePath:
  43531. self.buildPath(operatorList, fn, args);
  43532. continue;
  43533. case OPS.rectangle:
  43534. self.buildPath(operatorList, fn, args);
  43535. continue;
  43536. case OPS.markPoint:
  43537. case OPS.markPointProps:
  43538. case OPS.beginMarkedContent:
  43539. case OPS.beginMarkedContentProps:
  43540. case OPS.endMarkedContent:
  43541. case OPS.beginCompat:
  43542. case OPS.endCompat:
  43543. // Ignore operators where the corresponding handlers are known to
  43544. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  43545. // serialization errors and is also a bit more efficient.
  43546. // We could also try to serialize all objects in a general way,
  43547. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  43548. // but doing so is meaningless without knowing the semantics.
  43549. continue;
  43550. default:
  43551. // Note: Ignore the operator if it has `Dict` arguments, since
  43552. // those are non-serializable, otherwise postMessage will throw
  43553. // "An object could not be cloned.".
  43554. if (args !== null) {
  43555. for (i = 0, ii = args.length; i < ii; i++) {
  43556. if (args[i] instanceof Dict) {
  43557. break;
  43558. }
  43559. }
  43560. if (i < ii) {
  43561. warn('getOperatorList - ignoring operator: ' + fn);
  43562. continue;
  43563. }
  43564. }
  43565. }
  43566. operatorList.addOp(fn, args);
  43567. }
  43568. if (stop) {
  43569. next(deferred);
  43570. return;
  43571. }
  43572. // Some PDFs don't close all restores inside object/form.
  43573. // Closing those for them.
  43574. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  43575. operatorList.addOp(OPS.restore, []);
  43576. }
  43577. resolve();
  43578. });
  43579. },
  43580. getTextContent:
  43581. function PartialEvaluator_getTextContent(stream, task, resources,
  43582. stateManager,
  43583. normalizeWhitespace,
  43584. combineTextItems) {
  43585. stateManager = (stateManager || new StateManager(new TextState()));
  43586. var WhitespaceRegexp = /\s/g;
  43587. var textContent = {
  43588. items: [],
  43589. styles: Object.create(null)
  43590. };
  43591. var textContentItem = {
  43592. initialized: false,
  43593. str: [],
  43594. width: 0,
  43595. height: 0,
  43596. vertical: false,
  43597. lastAdvanceWidth: 0,
  43598. lastAdvanceHeight: 0,
  43599. textAdvanceScale: 0,
  43600. spaceWidth: 0,
  43601. fakeSpaceMin: Infinity,
  43602. fakeMultiSpaceMin: Infinity,
  43603. fakeMultiSpaceMax: -0,
  43604. textRunBreakAllowed: false,
  43605. transform: null,
  43606. fontName: null
  43607. };
  43608. var SPACE_FACTOR = 0.3;
  43609. var MULTI_SPACE_FACTOR = 1.5;
  43610. var MULTI_SPACE_FACTOR_MAX = 4;
  43611. var self = this;
  43612. var xref = this.xref;
  43613. resources = (xref.fetchIfRef(resources) || Dict.empty);
  43614. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  43615. var xobjs = null;
  43616. var xobjsCache = Object.create(null);
  43617. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43618. var textState;
  43619. function ensureTextContentItem() {
  43620. if (textContentItem.initialized) {
  43621. return textContentItem;
  43622. }
  43623. var font = textState.font;
  43624. if (!(font.loadedName in textContent.styles)) {
  43625. textContent.styles[font.loadedName] = {
  43626. fontFamily: font.fallbackName,
  43627. ascent: font.ascent,
  43628. descent: font.descent,
  43629. vertical: font.vertical
  43630. };
  43631. }
  43632. textContentItem.fontName = font.loadedName;
  43633. // 9.4.4 Text Space Details
  43634. var tsm = [textState.fontSize * textState.textHScale, 0,
  43635. 0, textState.fontSize,
  43636. 0, textState.textRise];
  43637. if (font.isType3Font &&
  43638. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  43639. textState.fontSize === 1) {
  43640. var glyphHeight = font.bbox[3] - font.bbox[1];
  43641. if (glyphHeight > 0) {
  43642. glyphHeight = glyphHeight * textState.fontMatrix[3];
  43643. tsm[3] *= glyphHeight;
  43644. }
  43645. }
  43646. var trm = Util.transform(textState.ctm,
  43647. Util.transform(textState.textMatrix, tsm));
  43648. textContentItem.transform = trm;
  43649. if (!font.vertical) {
  43650. textContentItem.width = 0;
  43651. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  43652. textContentItem.vertical = false;
  43653. } else {
  43654. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  43655. textContentItem.height = 0;
  43656. textContentItem.vertical = true;
  43657. }
  43658. var a = textState.textLineMatrix[0];
  43659. var b = textState.textLineMatrix[1];
  43660. var scaleLineX = Math.sqrt(a * a + b * b);
  43661. a = textState.ctm[0];
  43662. b = textState.ctm[1];
  43663. var scaleCtmX = Math.sqrt(a * a + b * b);
  43664. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  43665. textContentItem.lastAdvanceWidth = 0;
  43666. textContentItem.lastAdvanceHeight = 0;
  43667. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  43668. if (spaceWidth) {
  43669. textContentItem.spaceWidth = spaceWidth;
  43670. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  43671. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  43672. textContentItem.fakeMultiSpaceMax =
  43673. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  43674. // It's okay for monospace fonts to fake as much space as needed.
  43675. textContentItem.textRunBreakAllowed = !font.isMonospace;
  43676. } else {
  43677. textContentItem.spaceWidth = 0;
  43678. textContentItem.fakeSpaceMin = Infinity;
  43679. textContentItem.fakeMultiSpaceMin = Infinity;
  43680. textContentItem.fakeMultiSpaceMax = 0;
  43681. textContentItem.textRunBreakAllowed = false;
  43682. }
  43683. textContentItem.initialized = true;
  43684. return textContentItem;
  43685. }
  43686. function replaceWhitespace(str) {
  43687. // Replaces all whitespaces with standard spaces (0x20), to avoid
  43688. // alignment issues between the textLayer and the canvas if the text
  43689. // contains e.g. tabs (fixes issue6612.pdf).
  43690. var i = 0, ii = str.length, code;
  43691. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  43692. i++;
  43693. }
  43694. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  43695. }
  43696. function runBidiTransform(textChunk) {
  43697. var str = textChunk.str.join('');
  43698. var bidiResult = bidi(str, -1, textChunk.vertical);
  43699. return {
  43700. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  43701. bidiResult.str),
  43702. dir: bidiResult.dir,
  43703. width: textChunk.width,
  43704. height: textChunk.height,
  43705. transform: textChunk.transform,
  43706. fontName: textChunk.fontName
  43707. };
  43708. }
  43709. function handleSetFont(fontName, fontRef) {
  43710. return self.loadFont(fontName, fontRef, xref, resources).
  43711. then(function (translated) {
  43712. textState.font = translated.font;
  43713. textState.fontMatrix = translated.font.fontMatrix ||
  43714. FONT_IDENTITY_MATRIX;
  43715. });
  43716. }
  43717. function buildTextContentItem(chars) {
  43718. var font = textState.font;
  43719. var textChunk = ensureTextContentItem();
  43720. var width = 0;
  43721. var height = 0;
  43722. var glyphs = font.charsToGlyphs(chars);
  43723. var defaultVMetrics = font.defaultVMetrics;
  43724. for (var i = 0; i < glyphs.length; i++) {
  43725. var glyph = glyphs[i];
  43726. var vMetricX = null;
  43727. var vMetricY = null;
  43728. var glyphWidth = null;
  43729. if (font.vertical) {
  43730. if (glyph.vmetric) {
  43731. glyphWidth = glyph.vmetric[0];
  43732. vMetricX = glyph.vmetric[1];
  43733. vMetricY = glyph.vmetric[2];
  43734. } else {
  43735. glyphWidth = glyph.width;
  43736. vMetricX = glyph.width * 0.5;
  43737. vMetricY = defaultVMetrics[2];
  43738. }
  43739. } else {
  43740. glyphWidth = glyph.width;
  43741. }
  43742. var glyphUnicode = glyph.unicode;
  43743. var NormalizedUnicodes = getNormalizedUnicodes();
  43744. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  43745. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  43746. }
  43747. glyphUnicode = reverseIfRtl(glyphUnicode);
  43748. // The following will calculate the x and y of the individual glyphs.
  43749. // if (font.vertical) {
  43750. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  43751. // textState.fontMatrix[0];
  43752. // tsm[5] -= vMetricY * textState.fontSize *
  43753. // textState.fontMatrix[0];
  43754. // }
  43755. // var trm = Util.transform(textState.textMatrix, tsm);
  43756. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  43757. // var x = pt[0];
  43758. // var y = pt[1];
  43759. var charSpacing = textState.charSpacing;
  43760. if (glyph.isSpace) {
  43761. var wordSpacing = textState.wordSpacing;
  43762. charSpacing += wordSpacing;
  43763. if (wordSpacing > 0) {
  43764. addFakeSpaces(wordSpacing, textChunk.str);
  43765. }
  43766. }
  43767. var tx = 0;
  43768. var ty = 0;
  43769. if (!font.vertical) {
  43770. var w0 = glyphWidth * textState.fontMatrix[0];
  43771. tx = (w0 * textState.fontSize + charSpacing) *
  43772. textState.textHScale;
  43773. width += tx;
  43774. } else {
  43775. var w1 = glyphWidth * textState.fontMatrix[0];
  43776. ty = w1 * textState.fontSize + charSpacing;
  43777. height += ty;
  43778. }
  43779. textState.translateTextMatrix(tx, ty);
  43780. textChunk.str.push(glyphUnicode);
  43781. }
  43782. if (!font.vertical) {
  43783. textChunk.lastAdvanceWidth = width;
  43784. textChunk.width += width * textChunk.textAdvanceScale;
  43785. } else {
  43786. textChunk.lastAdvanceHeight = height;
  43787. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  43788. }
  43789. return textChunk;
  43790. }
  43791. function addFakeSpaces(width, strBuf) {
  43792. if (width < textContentItem.fakeSpaceMin) {
  43793. return;
  43794. }
  43795. if (width < textContentItem.fakeMultiSpaceMin) {
  43796. strBuf.push(' ');
  43797. return;
  43798. }
  43799. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  43800. while (fakeSpaces-- > 0) {
  43801. strBuf.push(' ');
  43802. }
  43803. }
  43804. function flushTextContentItem() {
  43805. if (!textContentItem.initialized) {
  43806. return;
  43807. }
  43808. textContent.items.push(runBidiTransform(textContentItem));
  43809. textContentItem.initialized = false;
  43810. textContentItem.str.length = 0;
  43811. }
  43812. var timeSlotManager = new TimeSlotManager();
  43813. return new Promise(function promiseBody(resolve, reject) {
  43814. var next = function (promise) {
  43815. promise.then(function () {
  43816. try {
  43817. promiseBody(resolve, reject);
  43818. } catch (ex) {
  43819. reject(ex);
  43820. }
  43821. }, reject);
  43822. };
  43823. task.ensureNotTerminated();
  43824. timeSlotManager.reset();
  43825. var stop, operation = {}, args = [];
  43826. while (!(stop = timeSlotManager.check())) {
  43827. // The arguments parsed by read() are not used beyond this loop, so
  43828. // we can reuse the same array on every iteration, thus avoiding
  43829. // unnecessary allocations.
  43830. args.length = 0;
  43831. operation.args = args;
  43832. if (!(preprocessor.read(operation))) {
  43833. break;
  43834. }
  43835. textState = stateManager.state;
  43836. var fn = operation.fn;
  43837. args = operation.args;
  43838. var advance, diff;
  43839. switch (fn | 0) {
  43840. case OPS.setFont:
  43841. // Optimization to ignore multiple identical Tf commands.
  43842. var fontNameArg = args[0].name, fontSizeArg = args[1];
  43843. if (textState.font && fontNameArg === textState.fontName &&
  43844. fontSizeArg === textState.fontSize) {
  43845. break;
  43846. }
  43847. flushTextContentItem();
  43848. textState.fontName = fontNameArg;
  43849. textState.fontSize = fontSizeArg;
  43850. next(handleSetFont(fontNameArg, null));
  43851. return;
  43852. case OPS.setTextRise:
  43853. flushTextContentItem();
  43854. textState.textRise = args[0];
  43855. break;
  43856. case OPS.setHScale:
  43857. flushTextContentItem();
  43858. textState.textHScale = args[0] / 100;
  43859. break;
  43860. case OPS.setLeading:
  43861. flushTextContentItem();
  43862. textState.leading = args[0];
  43863. break;
  43864. case OPS.moveText:
  43865. // Optimization to treat same line movement as advance
  43866. var isSameTextLine = !textState.font ? false :
  43867. ((textState.font.vertical ? args[0] : args[1]) === 0);
  43868. advance = args[0] - args[1];
  43869. if (combineTextItems &&
  43870. isSameTextLine && textContentItem.initialized &&
  43871. advance > 0 &&
  43872. advance <= textContentItem.fakeMultiSpaceMax) {
  43873. textState.translateTextLineMatrix(args[0], args[1]);
  43874. textContentItem.width +=
  43875. (args[0] - textContentItem.lastAdvanceWidth);
  43876. textContentItem.height +=
  43877. (args[1] - textContentItem.lastAdvanceHeight);
  43878. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  43879. (args[1] - textContentItem.lastAdvanceHeight);
  43880. addFakeSpaces(diff, textContentItem.str);
  43881. break;
  43882. }
  43883. flushTextContentItem();
  43884. textState.translateTextLineMatrix(args[0], args[1]);
  43885. textState.textMatrix = textState.textLineMatrix.slice();
  43886. break;
  43887. case OPS.setLeadingMoveText:
  43888. flushTextContentItem();
  43889. textState.leading = -args[1];
  43890. textState.translateTextLineMatrix(args[0], args[1]);
  43891. textState.textMatrix = textState.textLineMatrix.slice();
  43892. break;
  43893. case OPS.nextLine:
  43894. flushTextContentItem();
  43895. textState.carriageReturn();
  43896. break;
  43897. case OPS.setTextMatrix:
  43898. // Optimization to treat same line movement as advance.
  43899. advance = textState.calcTextLineMatrixAdvance(
  43900. args[0], args[1], args[2], args[3], args[4], args[5]);
  43901. if (combineTextItems &&
  43902. advance !== null && textContentItem.initialized &&
  43903. advance.value > 0 &&
  43904. advance.value <= textContentItem.fakeMultiSpaceMax) {
  43905. textState.translateTextLineMatrix(advance.width,
  43906. advance.height);
  43907. textContentItem.width +=
  43908. (advance.width - textContentItem.lastAdvanceWidth);
  43909. textContentItem.height +=
  43910. (advance.height - textContentItem.lastAdvanceHeight);
  43911. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  43912. (advance.height - textContentItem.lastAdvanceHeight);
  43913. addFakeSpaces(diff, textContentItem.str);
  43914. break;
  43915. }
  43916. flushTextContentItem();
  43917. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  43918. args[4], args[5]);
  43919. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  43920. args[4], args[5]);
  43921. break;
  43922. case OPS.setCharSpacing:
  43923. textState.charSpacing = args[0];
  43924. break;
  43925. case OPS.setWordSpacing:
  43926. textState.wordSpacing = args[0];
  43927. break;
  43928. case OPS.beginText:
  43929. flushTextContentItem();
  43930. textState.textMatrix = IDENTITY_MATRIX.slice();
  43931. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  43932. break;
  43933. case OPS.showSpacedText:
  43934. var items = args[0];
  43935. var offset;
  43936. for (var j = 0, jj = items.length; j < jj; j++) {
  43937. if (typeof items[j] === 'string') {
  43938. buildTextContentItem(items[j]);
  43939. } else {
  43940. ensureTextContentItem();
  43941. // PDF Specification 5.3.2 states:
  43942. // The number is expressed in thousandths of a unit of text
  43943. // space.
  43944. // This amount is subtracted from the current horizontal or
  43945. // vertical coordinate, depending on the writing mode.
  43946. // In the default coordinate system, a positive adjustment
  43947. // has the effect of moving the next glyph painted either to
  43948. // the left or down by the given amount.
  43949. advance = items[j] * textState.fontSize / 1000;
  43950. var breakTextRun = false;
  43951. if (textState.font.vertical) {
  43952. offset = advance *
  43953. (textState.textHScale * textState.textMatrix[2] +
  43954. textState.textMatrix[3]);
  43955. textState.translateTextMatrix(0, advance);
  43956. breakTextRun = textContentItem.textRunBreakAllowed &&
  43957. advance > textContentItem.fakeMultiSpaceMax;
  43958. if (!breakTextRun) {
  43959. // Value needs to be added to height to paint down.
  43960. textContentItem.height += offset;
  43961. }
  43962. } else {
  43963. advance = -advance;
  43964. offset = advance * (
  43965. textState.textHScale * textState.textMatrix[0] +
  43966. textState.textMatrix[1]);
  43967. textState.translateTextMatrix(advance, 0);
  43968. breakTextRun = textContentItem.textRunBreakAllowed &&
  43969. advance > textContentItem.fakeMultiSpaceMax;
  43970. if (!breakTextRun) {
  43971. // Value needs to be subtracted from width to paint left.
  43972. textContentItem.width += offset;
  43973. }
  43974. }
  43975. if (breakTextRun) {
  43976. flushTextContentItem();
  43977. } else if (advance > 0) {
  43978. addFakeSpaces(advance, textContentItem.str);
  43979. }
  43980. }
  43981. }
  43982. break;
  43983. case OPS.showText:
  43984. buildTextContentItem(args[0]);
  43985. break;
  43986. case OPS.nextLineShowText:
  43987. flushTextContentItem();
  43988. textState.carriageReturn();
  43989. buildTextContentItem(args[0]);
  43990. break;
  43991. case OPS.nextLineSetSpacingShowText:
  43992. flushTextContentItem();
  43993. textState.wordSpacing = args[0];
  43994. textState.charSpacing = args[1];
  43995. textState.carriageReturn();
  43996. buildTextContentItem(args[2]);
  43997. break;
  43998. case OPS.paintXObject:
  43999. flushTextContentItem();
  44000. if (args[0].code) {
  44001. break;
  44002. }
  44003. if (!xobjs) {
  44004. xobjs = (resources.get('XObject') || Dict.empty);
  44005. }
  44006. var name = args[0].name;
  44007. if (xobjsCache.key === name) {
  44008. if (xobjsCache.texts) {
  44009. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  44010. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  44011. }
  44012. break;
  44013. }
  44014. var xobj = xobjs.get(name);
  44015. if (!xobj) {
  44016. break;
  44017. }
  44018. assert(isStream(xobj), 'XObject should be a stream');
  44019. var type = xobj.dict.get('Subtype');
  44020. assert(isName(type), 'XObject should have a Name subtype');
  44021. if ('Form' !== type.name) {
  44022. xobjsCache.key = name;
  44023. xobjsCache.texts = null;
  44024. break;
  44025. }
  44026. stateManager.save();
  44027. var matrix = xobj.dict.getArray('Matrix');
  44028. if (isArray(matrix) && matrix.length === 6) {
  44029. stateManager.transform(matrix);
  44030. }
  44031. next(self.getTextContent(xobj, task,
  44032. xobj.dict.get('Resources') || resources, stateManager,
  44033. normalizeWhitespace, combineTextItems).then(
  44034. function (formTextContent) {
  44035. Util.appendToArray(textContent.items, formTextContent.items);
  44036. Util.extendObj(textContent.styles, formTextContent.styles);
  44037. stateManager.restore();
  44038. xobjsCache.key = name;
  44039. xobjsCache.texts = formTextContent;
  44040. }));
  44041. return;
  44042. case OPS.setGState:
  44043. flushTextContentItem();
  44044. var dictName = args[0];
  44045. var extGState = resources.get('ExtGState');
  44046. if (!isDict(extGState) || !isName(dictName)) {
  44047. break;
  44048. }
  44049. var gState = extGState.get(dictName.name);
  44050. if (!isDict(gState)) {
  44051. break;
  44052. }
  44053. var gStateFont = gState.get('Font');
  44054. if (gStateFont) {
  44055. textState.fontName = null;
  44056. textState.fontSize = gStateFont[1];
  44057. next(handleSetFont(null, gStateFont[0]));
  44058. return;
  44059. }
  44060. break;
  44061. } // switch
  44062. } // while
  44063. if (stop) {
  44064. next(deferred);
  44065. return;
  44066. }
  44067. flushTextContentItem();
  44068. resolve(textContent);
  44069. });
  44070. },
  44071. extractDataStructures:
  44072. function PartialEvaluator_extractDataStructures(dict, baseDict,
  44073. xref, properties) {
  44074. // 9.10.2
  44075. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  44076. var toUnicodePromise = toUnicode ?
  44077. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  44078. if (properties.composite) {
  44079. // CIDSystemInfo helps to match CID to glyphs
  44080. var cidSystemInfo = dict.get('CIDSystemInfo');
  44081. if (isDict(cidSystemInfo)) {
  44082. properties.cidSystemInfo = {
  44083. registry: cidSystemInfo.get('Registry'),
  44084. ordering: cidSystemInfo.get('Ordering'),
  44085. supplement: cidSystemInfo.get('Supplement')
  44086. };
  44087. }
  44088. var cidToGidMap = dict.get('CIDToGIDMap');
  44089. if (isStream(cidToGidMap)) {
  44090. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  44091. }
  44092. }
  44093. // Based on 9.6.6 of the spec the encoding can come from multiple places
  44094. // and depends on the font type. The base encoding and differences are
  44095. // read here, but the encoding that is actually used is chosen during
  44096. // glyph mapping in the font.
  44097. // TODO: Loading the built in encoding in the font would allow the
  44098. // differences to be merged in here not require us to hold on to it.
  44099. var differences = [];
  44100. var baseEncodingName = null;
  44101. var encoding;
  44102. if (dict.has('Encoding')) {
  44103. encoding = dict.get('Encoding');
  44104. if (isDict(encoding)) {
  44105. baseEncodingName = encoding.get('BaseEncoding');
  44106. baseEncodingName = (isName(baseEncodingName) ?
  44107. baseEncodingName.name : null);
  44108. // Load the differences between the base and original
  44109. if (encoding.has('Differences')) {
  44110. var diffEncoding = encoding.get('Differences');
  44111. var index = 0;
  44112. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  44113. var data = xref.fetchIfRef(diffEncoding[j]);
  44114. if (isNum(data)) {
  44115. index = data;
  44116. } else if (isName(data)) {
  44117. differences[index++] = data.name;
  44118. } else {
  44119. error('Invalid entry in \'Differences\' array: ' + data);
  44120. }
  44121. }
  44122. }
  44123. } else if (isName(encoding)) {
  44124. baseEncodingName = encoding.name;
  44125. } else {
  44126. error('Encoding is not a Name nor a Dict');
  44127. }
  44128. // According to table 114 if the encoding is a named encoding it must be
  44129. // one of these predefined encodings.
  44130. if ((baseEncodingName !== 'MacRomanEncoding' &&
  44131. baseEncodingName !== 'MacExpertEncoding' &&
  44132. baseEncodingName !== 'WinAnsiEncoding')) {
  44133. baseEncodingName = null;
  44134. }
  44135. }
  44136. if (baseEncodingName) {
  44137. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  44138. } else {
  44139. encoding = (properties.type === 'TrueType' ?
  44140. WinAnsiEncoding : StandardEncoding);
  44141. // The Symbolic attribute can be misused for regular fonts
  44142. // Heuristic: we have to check if the font is a standard one also
  44143. if (!!(properties.flags & FontFlags.Symbolic)) {
  44144. encoding = MacRomanEncoding;
  44145. if (!properties.file) {
  44146. if (/Symbol/i.test(properties.name)) {
  44147. encoding = SymbolSetEncoding;
  44148. } else if (/Dingbats/i.test(properties.name)) {
  44149. encoding = ZapfDingbatsEncoding;
  44150. }
  44151. }
  44152. }
  44153. properties.defaultEncoding = encoding;
  44154. }
  44155. properties.differences = differences;
  44156. properties.baseEncodingName = baseEncodingName;
  44157. properties.dict = dict;
  44158. return toUnicodePromise.then(function(toUnicode) {
  44159. properties.toUnicode = toUnicode;
  44160. return this.buildToUnicode(properties);
  44161. }.bind(this)).then(function (toUnicode) {
  44162. properties.toUnicode = toUnicode;
  44163. return properties;
  44164. });
  44165. },
  44166. /**
  44167. * Builds a char code to unicode map based on section 9.10 of the spec.
  44168. * @param {Object} properties Font properties object.
  44169. * @return {Promise} A Promise that is resolved with a
  44170. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  44171. */
  44172. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  44173. // Section 9.10.2 Mapping Character Codes to Unicode Values
  44174. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  44175. return Promise.resolve(properties.toUnicode);
  44176. }
  44177. // According to the spec if the font is a simple font we should only map
  44178. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  44179. // the differences array only contains adobe standard or symbol set names,
  44180. // in pratice it seems better to always try to create a toUnicode
  44181. // map based of the default encoding.
  44182. var toUnicode, charcode, glyphName;
  44183. if (!properties.composite /* is simple font */) {
  44184. toUnicode = [];
  44185. var encoding = properties.defaultEncoding.slice();
  44186. var baseEncodingName = properties.baseEncodingName;
  44187. // Merge in the differences array.
  44188. var differences = properties.differences;
  44189. for (charcode in differences) {
  44190. glyphName = differences[charcode];
  44191. if (glyphName === '.notdef') {
  44192. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  44193. // where there should be spaces (fixes issue5256.pdf).
  44194. continue;
  44195. }
  44196. encoding[charcode] = glyphName;
  44197. }
  44198. var glyphsUnicodeMap = getGlyphsUnicode();
  44199. for (charcode in encoding) {
  44200. // a) Map the character code to a character name.
  44201. glyphName = encoding[charcode];
  44202. // b) Look up the character name in the Adobe Glyph List (see the
  44203. // Bibliography) to obtain the corresponding Unicode value.
  44204. if (glyphName === '') {
  44205. continue;
  44206. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  44207. // (undocumented) c) Few heuristics to recognize unknown glyphs
  44208. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  44209. var code = 0;
  44210. switch (glyphName[0]) {
  44211. case 'G': // Gxx glyph
  44212. if (glyphName.length === 3) {
  44213. code = parseInt(glyphName.substr(1), 16);
  44214. }
  44215. break;
  44216. case 'g': // g00xx glyph
  44217. if (glyphName.length === 5) {
  44218. code = parseInt(glyphName.substr(1), 16);
  44219. }
  44220. break;
  44221. case 'C': // Cddd glyph
  44222. case 'c': // cddd glyph
  44223. if (glyphName.length >= 3) {
  44224. code = +glyphName.substr(1);
  44225. }
  44226. break;
  44227. default:
  44228. // 'uniXXXX'/'uXXXX{XX}' glyphs
  44229. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  44230. if (unicode !== -1) {
  44231. code = unicode;
  44232. }
  44233. }
  44234. if (code) {
  44235. // If |baseEncodingName| is one the predefined encodings,
  44236. // and |code| equals |charcode|, using the glyph defined in the
  44237. // baseEncoding seems to yield a better |toUnicode| mapping
  44238. // (fixes issue 5070).
  44239. if (baseEncodingName && code === +charcode) {
  44240. var baseEncoding = getEncoding(baseEncodingName);
  44241. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  44242. toUnicode[charcode] =
  44243. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44244. continue;
  44245. }
  44246. }
  44247. toUnicode[charcode] = String.fromCharCode(code);
  44248. }
  44249. continue;
  44250. }
  44251. toUnicode[charcode] =
  44252. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44253. }
  44254. return Promise.resolve(new ToUnicodeMap(toUnicode));
  44255. }
  44256. // If the font is a composite font that uses one of the predefined CMaps
  44257. // listed in Table 118 (except Identity–H and Identity–V) or whose
  44258. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  44259. // Adobe-Korea1 character collection:
  44260. if (properties.composite && (
  44261. (properties.cMap.builtInCMap &&
  44262. !(properties.cMap instanceof IdentityCMap)) ||
  44263. (properties.cidSystemInfo.registry === 'Adobe' &&
  44264. (properties.cidSystemInfo.ordering === 'GB1' ||
  44265. properties.cidSystemInfo.ordering === 'CNS1' ||
  44266. properties.cidSystemInfo.ordering === 'Japan1' ||
  44267. properties.cidSystemInfo.ordering === 'Korea1')))) {
  44268. // Then:
  44269. // a) Map the character code to a character identifier (CID) according
  44270. // to the font’s CMap.
  44271. // b) Obtain the registry and ordering of the character collection used
  44272. // by the font’s CMap (for example, Adobe and Japan1) from its
  44273. // CIDSystemInfo dictionary.
  44274. var registry = properties.cidSystemInfo.registry;
  44275. var ordering = properties.cidSystemInfo.ordering;
  44276. // c) Construct a second CMap name by concatenating the registry and
  44277. // ordering obtained in step (b) in the format registry–ordering–UCS2
  44278. // (for example, Adobe–Japan1–UCS2).
  44279. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  44280. // d) Obtain the CMap with the name constructed in step (c) (available
  44281. // from the ASN Web site; see the Bibliography).
  44282. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  44283. null).then(
  44284. function (ucs2CMap) {
  44285. var cMap = properties.cMap;
  44286. toUnicode = [];
  44287. cMap.forEach(function(charcode, cid) {
  44288. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  44289. // e) Map the CID obtained in step (a) according to the CMap
  44290. // obtained in step (d), producing a Unicode value.
  44291. var ucs2 = ucs2CMap.lookup(cid);
  44292. if (ucs2) {
  44293. toUnicode[charcode] =
  44294. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  44295. ucs2.charCodeAt(1));
  44296. }
  44297. });
  44298. return new ToUnicodeMap(toUnicode);
  44299. });
  44300. }
  44301. // The viewer's choice, just use an identity map.
  44302. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  44303. properties.lastChar));
  44304. },
  44305. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  44306. var cmapObj = toUnicode;
  44307. if (isName(cmapObj)) {
  44308. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44309. function (cmap) {
  44310. if (cmap instanceof IdentityCMap) {
  44311. return new IdentityToUnicodeMap(0, 0xFFFF);
  44312. }
  44313. return new ToUnicodeMap(cmap.getMap());
  44314. });
  44315. } else if (isStream(cmapObj)) {
  44316. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44317. function (cmap) {
  44318. if (cmap instanceof IdentityCMap) {
  44319. return new IdentityToUnicodeMap(0, 0xFFFF);
  44320. }
  44321. var map = new Array(cmap.length);
  44322. // Convert UTF-16BE
  44323. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  44324. // to iterate over all keys.
  44325. cmap.forEach(function(charCode, token) {
  44326. var str = [];
  44327. for (var k = 0; k < token.length; k += 2) {
  44328. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44329. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  44330. str.push(w1);
  44331. continue;
  44332. }
  44333. k += 2;
  44334. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44335. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  44336. }
  44337. map[charCode] = String.fromCharCode.apply(String, str);
  44338. });
  44339. return new ToUnicodeMap(map);
  44340. });
  44341. }
  44342. return Promise.resolve(null);
  44343. },
  44344. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  44345. // Extract the encoding from the CIDToGIDMap
  44346. var glyphsData = cidToGidStream.getBytes();
  44347. // Set encoding 0 to later verify the font has an encoding
  44348. var result = [];
  44349. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  44350. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  44351. if (glyphID === 0) {
  44352. continue;
  44353. }
  44354. var code = j >> 1;
  44355. result[code] = glyphID;
  44356. }
  44357. return result;
  44358. },
  44359. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  44360. descriptor,
  44361. properties) {
  44362. var glyphsWidths = [];
  44363. var defaultWidth = 0;
  44364. var glyphsVMetrics = [];
  44365. var defaultVMetrics;
  44366. var i, ii, j, jj, start, code, widths;
  44367. if (properties.composite) {
  44368. defaultWidth = dict.get('DW') || 1000;
  44369. widths = dict.get('W');
  44370. if (widths) {
  44371. for (i = 0, ii = widths.length; i < ii; i++) {
  44372. start = widths[i++];
  44373. code = xref.fetchIfRef(widths[i]);
  44374. if (isArray(code)) {
  44375. for (j = 0, jj = code.length; j < jj; j++) {
  44376. glyphsWidths[start++] = code[j];
  44377. }
  44378. } else {
  44379. var width = widths[++i];
  44380. for (j = start; j <= code; j++) {
  44381. glyphsWidths[j] = width;
  44382. }
  44383. }
  44384. }
  44385. }
  44386. if (properties.vertical) {
  44387. var vmetrics = (dict.get('DW2') || [880, -1000]);
  44388. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  44389. vmetrics = dict.get('W2');
  44390. if (vmetrics) {
  44391. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  44392. start = vmetrics[i++];
  44393. code = xref.fetchIfRef(vmetrics[i]);
  44394. if (isArray(code)) {
  44395. for (j = 0, jj = code.length; j < jj; j++) {
  44396. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  44397. }
  44398. } else {
  44399. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  44400. for (j = start; j <= code; j++) {
  44401. glyphsVMetrics[j] = vmetric;
  44402. }
  44403. }
  44404. }
  44405. }
  44406. }
  44407. } else {
  44408. var firstChar = properties.firstChar;
  44409. widths = dict.get('Widths');
  44410. if (widths) {
  44411. j = firstChar;
  44412. for (i = 0, ii = widths.length; i < ii; i++) {
  44413. glyphsWidths[j++] = widths[i];
  44414. }
  44415. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  44416. } else {
  44417. // Trying get the BaseFont metrics (see comment above).
  44418. var baseFontName = dict.get('BaseFont');
  44419. if (isName(baseFontName)) {
  44420. var metrics = this.getBaseFontMetrics(baseFontName.name);
  44421. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  44422. properties);
  44423. defaultWidth = metrics.defaultWidth;
  44424. }
  44425. }
  44426. }
  44427. // Heuristic: detection of monospace font by checking all non-zero widths
  44428. var isMonospace = true;
  44429. var firstWidth = defaultWidth;
  44430. for (var glyph in glyphsWidths) {
  44431. var glyphWidth = glyphsWidths[glyph];
  44432. if (!glyphWidth) {
  44433. continue;
  44434. }
  44435. if (!firstWidth) {
  44436. firstWidth = glyphWidth;
  44437. continue;
  44438. }
  44439. if (firstWidth !== glyphWidth) {
  44440. isMonospace = false;
  44441. break;
  44442. }
  44443. }
  44444. if (isMonospace) {
  44445. properties.flags |= FontFlags.FixedPitch;
  44446. }
  44447. properties.defaultWidth = defaultWidth;
  44448. properties.widths = glyphsWidths;
  44449. properties.defaultVMetrics = defaultVMetrics;
  44450. properties.vmetrics = glyphsVMetrics;
  44451. },
  44452. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  44453. // Simulating descriptor flags attribute
  44454. var fontNameWoStyle = baseFontName.split('-')[0];
  44455. return (fontNameWoStyle in getSerifFonts()) ||
  44456. (fontNameWoStyle.search(/serif/gi) !== -1);
  44457. },
  44458. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  44459. var defaultWidth = 0;
  44460. var widths = [];
  44461. var monospace = false;
  44462. var stdFontMap = getStdFontMap();
  44463. var lookupName = (stdFontMap[name] || name);
  44464. var Metrics = getMetrics();
  44465. if (!(lookupName in Metrics)) {
  44466. // Use default fonts for looking up font metrics if the passed
  44467. // font is not a base font
  44468. if (this.isSerifFont(name)) {
  44469. lookupName = 'Times-Roman';
  44470. } else {
  44471. lookupName = 'Helvetica';
  44472. }
  44473. }
  44474. var glyphWidths = Metrics[lookupName];
  44475. if (isNum(glyphWidths)) {
  44476. defaultWidth = glyphWidths;
  44477. monospace = true;
  44478. } else {
  44479. widths = glyphWidths(); // expand lazy widths array
  44480. }
  44481. return {
  44482. defaultWidth: defaultWidth,
  44483. monospace: monospace,
  44484. widths: widths
  44485. };
  44486. },
  44487. buildCharCodeToWidth:
  44488. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  44489. properties) {
  44490. var widths = Object.create(null);
  44491. var differences = properties.differences;
  44492. var encoding = properties.defaultEncoding;
  44493. for (var charCode = 0; charCode < 256; charCode++) {
  44494. if (charCode in differences &&
  44495. widthsByGlyphName[differences[charCode]]) {
  44496. widths[charCode] = widthsByGlyphName[differences[charCode]];
  44497. continue;
  44498. }
  44499. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  44500. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  44501. continue;
  44502. }
  44503. }
  44504. return widths;
  44505. },
  44506. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  44507. var baseDict = dict;
  44508. var type = dict.get('Subtype');
  44509. assert(isName(type), 'invalid font Subtype');
  44510. var composite = false;
  44511. var uint8array;
  44512. if (type.name === 'Type0') {
  44513. // If font is a composite
  44514. // - get the descendant font
  44515. // - set the type according to the descendant font
  44516. // - get the FontDescriptor from the descendant font
  44517. var df = dict.get('DescendantFonts');
  44518. if (!df) {
  44519. error('Descendant fonts are not specified');
  44520. }
  44521. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  44522. type = dict.get('Subtype');
  44523. assert(isName(type), 'invalid font Subtype');
  44524. composite = true;
  44525. }
  44526. var descriptor = dict.get('FontDescriptor');
  44527. if (descriptor) {
  44528. var hash = new MurmurHash3_64();
  44529. var encoding = baseDict.getRaw('Encoding');
  44530. if (isName(encoding)) {
  44531. hash.update(encoding.name);
  44532. } else if (isRef(encoding)) {
  44533. hash.update(encoding.toString());
  44534. } else if (isDict(encoding)) {
  44535. var keys = encoding.getKeys();
  44536. for (var i = 0, ii = keys.length; i < ii; i++) {
  44537. var entry = encoding.getRaw(keys[i]);
  44538. if (isName(entry)) {
  44539. hash.update(entry.name);
  44540. } else if (isRef(entry)) {
  44541. hash.update(entry.toString());
  44542. } else if (isArray(entry)) { // 'Differences' entry.
  44543. // Ideally we should check the contents of the array, but to avoid
  44544. // parsing it here and then again in |extractDataStructures|,
  44545. // we only use the array length for now (fixes bug1157493.pdf).
  44546. hash.update(entry.length.toString());
  44547. }
  44548. }
  44549. }
  44550. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  44551. if (isStream(toUnicode)) {
  44552. var stream = toUnicode.str || toUnicode;
  44553. uint8array = stream.buffer ?
  44554. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  44555. new Uint8Array(stream.bytes.buffer,
  44556. stream.start, stream.end - stream.start);
  44557. hash.update(uint8array);
  44558. } else if (isName(toUnicode)) {
  44559. hash.update(toUnicode.name);
  44560. }
  44561. var widths = dict.get('Widths') || baseDict.get('Widths');
  44562. if (widths) {
  44563. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  44564. hash.update(uint8array);
  44565. }
  44566. }
  44567. return {
  44568. descriptor: descriptor,
  44569. dict: dict,
  44570. baseDict: baseDict,
  44571. composite: composite,
  44572. type: type.name,
  44573. hash: hash ? hash.hexdigest() : ''
  44574. };
  44575. },
  44576. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  44577. xref) {
  44578. var baseDict = preEvaluatedFont.baseDict;
  44579. var dict = preEvaluatedFont.dict;
  44580. var composite = preEvaluatedFont.composite;
  44581. var descriptor = preEvaluatedFont.descriptor;
  44582. var type = preEvaluatedFont.type;
  44583. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  44584. var cMapOptions = this.options.cMapOptions;
  44585. var properties;
  44586. if (!descriptor) {
  44587. if (type === 'Type3') {
  44588. // FontDescriptor is only required for Type3 fonts when the document
  44589. // is a tagged pdf. Create a barbebones one to get by.
  44590. descriptor = new Dict(null);
  44591. descriptor.set('FontName', Name.get(type));
  44592. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  44593. } else {
  44594. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  44595. // FontDescriptor was not required.
  44596. // This case is here for compatibility.
  44597. var baseFontName = dict.get('BaseFont');
  44598. if (!isName(baseFontName)) {
  44599. error('Base font is not specified');
  44600. }
  44601. // Using base font name as a font name.
  44602. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  44603. var metrics = this.getBaseFontMetrics(baseFontName);
  44604. // Simulating descriptor flags attribute
  44605. var fontNameWoStyle = baseFontName.split('-')[0];
  44606. var flags =
  44607. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  44608. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  44609. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  44610. FontFlags.Nonsymbolic);
  44611. properties = {
  44612. type: type,
  44613. name: baseFontName,
  44614. widths: metrics.widths,
  44615. defaultWidth: metrics.defaultWidth,
  44616. flags: flags,
  44617. firstChar: 0,
  44618. lastChar: maxCharIndex
  44619. };
  44620. return this.extractDataStructures(dict, dict, xref, properties).then(
  44621. function (properties) {
  44622. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  44623. properties);
  44624. return new Font(baseFontName, null, properties);
  44625. }.bind(this));
  44626. }
  44627. }
  44628. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  44629. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  44630. // to ignore this rule when a variant of a standard font is used.
  44631. // TODO Fill the width array depending on which of the base font this is
  44632. // a variant.
  44633. var firstChar = (dict.get('FirstChar') || 0);
  44634. var lastChar = (dict.get('LastChar') || maxCharIndex);
  44635. var fontName = descriptor.get('FontName');
  44636. var baseFont = dict.get('BaseFont');
  44637. // Some bad PDFs have a string as the font name.
  44638. if (isString(fontName)) {
  44639. fontName = Name.get(fontName);
  44640. }
  44641. if (isString(baseFont)) {
  44642. baseFont = Name.get(baseFont);
  44643. }
  44644. if (type !== 'Type3') {
  44645. var fontNameStr = fontName && fontName.name;
  44646. var baseFontStr = baseFont && baseFont.name;
  44647. if (fontNameStr !== baseFontStr) {
  44648. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  44649. '" but should be the same as the Font\'s BaseFont "' +
  44650. baseFontStr + '"');
  44651. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  44652. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  44653. if (fontNameStr && baseFontStr &&
  44654. baseFontStr.indexOf(fontNameStr) === 0) {
  44655. fontName = baseFont;
  44656. }
  44657. }
  44658. }
  44659. fontName = (fontName || baseFont);
  44660. assert(isName(fontName), 'invalid font name');
  44661. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  44662. if (fontFile) {
  44663. if (fontFile.dict) {
  44664. var subtype = fontFile.dict.get('Subtype');
  44665. if (subtype) {
  44666. subtype = subtype.name;
  44667. }
  44668. var length1 = fontFile.dict.get('Length1');
  44669. var length2 = fontFile.dict.get('Length2');
  44670. var length3 = fontFile.dict.get('Length3');
  44671. }
  44672. }
  44673. properties = {
  44674. type: type,
  44675. name: fontName.name,
  44676. subtype: subtype,
  44677. file: fontFile,
  44678. length1: length1,
  44679. length2: length2,
  44680. length3: length3,
  44681. loadedName: baseDict.loadedName,
  44682. composite: composite,
  44683. wideChars: composite,
  44684. fixedPitch: false,
  44685. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  44686. firstChar: firstChar || 0,
  44687. lastChar: (lastChar || maxCharIndex),
  44688. bbox: descriptor.getArray('FontBBox'),
  44689. ascent: descriptor.get('Ascent'),
  44690. descent: descriptor.get('Descent'),
  44691. xHeight: descriptor.get('XHeight'),
  44692. capHeight: descriptor.get('CapHeight'),
  44693. flags: descriptor.get('Flags'),
  44694. italicAngle: descriptor.get('ItalicAngle'),
  44695. coded: false
  44696. };
  44697. var cMapPromise;
  44698. if (composite) {
  44699. var cidEncoding = baseDict.get('Encoding');
  44700. if (isName(cidEncoding)) {
  44701. properties.cidEncoding = cidEncoding.name;
  44702. }
  44703. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  44704. function (cMap) {
  44705. properties.cMap = cMap;
  44706. properties.vertical = properties.cMap.vertical;
  44707. });
  44708. } else {
  44709. cMapPromise = Promise.resolve(undefined);
  44710. }
  44711. return cMapPromise.then(function () {
  44712. return this.extractDataStructures(dict, baseDict, xref, properties);
  44713. }.bind(this)).then(function (properties) {
  44714. this.extractWidths(dict, xref, descriptor, properties);
  44715. if (type === 'Type3') {
  44716. properties.isType3Font = true;
  44717. }
  44718. return new Font(fontName.name, fontFile, properties);
  44719. }.bind(this));
  44720. }
  44721. };
  44722. return PartialEvaluator;
  44723. })();
  44724. var TranslatedFont = (function TranslatedFontClosure() {
  44725. function TranslatedFont(loadedName, font, dict) {
  44726. this.loadedName = loadedName;
  44727. this.font = font;
  44728. this.dict = dict;
  44729. this.type3Loaded = null;
  44730. this.sent = false;
  44731. }
  44732. TranslatedFont.prototype = {
  44733. send: function (handler) {
  44734. if (this.sent) {
  44735. return;
  44736. }
  44737. var fontData = this.font.exportData();
  44738. handler.send('commonobj', [
  44739. this.loadedName,
  44740. 'Font',
  44741. fontData
  44742. ]);
  44743. this.sent = true;
  44744. },
  44745. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  44746. assert(this.font.isType3Font);
  44747. if (this.type3Loaded) {
  44748. return this.type3Loaded;
  44749. }
  44750. var translatedFont = this.font;
  44751. var loadCharProcsPromise = Promise.resolve();
  44752. var charProcs = this.dict.get('CharProcs');
  44753. var fontResources = this.dict.get('Resources') || resources;
  44754. var charProcKeys = charProcs.getKeys();
  44755. var charProcOperatorList = Object.create(null);
  44756. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  44757. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  44758. var glyphStream = charProcs.get(key);
  44759. var operatorList = new OperatorList();
  44760. return evaluator.getOperatorList(glyphStream, task, fontResources,
  44761. operatorList).then(function () {
  44762. charProcOperatorList[key] = operatorList.getIR();
  44763. // Add the dependencies to the parent operator list so they are
  44764. // resolved before sub operator list is executed synchronously.
  44765. parentOperatorList.addDependencies(operatorList.dependencies);
  44766. }, function (reason) {
  44767. warn('Type3 font resource \"' + key + '\" is not available');
  44768. var operatorList = new OperatorList();
  44769. charProcOperatorList[key] = operatorList.getIR();
  44770. });
  44771. }.bind(this, charProcKeys[i]));
  44772. }
  44773. this.type3Loaded = loadCharProcsPromise.then(function () {
  44774. translatedFont.charProcOperatorList = charProcOperatorList;
  44775. });
  44776. return this.type3Loaded;
  44777. }
  44778. };
  44779. return TranslatedFont;
  44780. })();
  44781. var OperatorList = (function OperatorListClosure() {
  44782. var CHUNK_SIZE = 1000;
  44783. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  44784. function getTransfers(queue) {
  44785. var transfers = [];
  44786. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44787. for (var i = 0, ii = queue.length; i < ii; i++) {
  44788. switch (fnArray[i]) {
  44789. case OPS.paintInlineImageXObject:
  44790. case OPS.paintInlineImageXObjectGroup:
  44791. case OPS.paintImageMaskXObject:
  44792. var arg = argsArray[i][0]; // first param in imgData
  44793. if (!arg.cached) {
  44794. transfers.push(arg.data.buffer);
  44795. }
  44796. break;
  44797. }
  44798. }
  44799. return transfers;
  44800. }
  44801. function OperatorList(intent, messageHandler, pageIndex) {
  44802. this.messageHandler = messageHandler;
  44803. this.fnArray = [];
  44804. this.argsArray = [];
  44805. this.dependencies = Object.create(null);
  44806. this._totalLength = 0;
  44807. this.pageIndex = pageIndex;
  44808. this.intent = intent;
  44809. }
  44810. OperatorList.prototype = {
  44811. get length() {
  44812. return this.argsArray.length;
  44813. },
  44814. /**
  44815. * @returns {number} The total length of the entire operator list,
  44816. * since `this.length === 0` after flushing.
  44817. */
  44818. get totalLength() {
  44819. return (this._totalLength + this.length);
  44820. },
  44821. addOp: function(fn, args) {
  44822. this.fnArray.push(fn);
  44823. this.argsArray.push(args);
  44824. if (this.messageHandler) {
  44825. if (this.fnArray.length >= CHUNK_SIZE) {
  44826. this.flush();
  44827. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  44828. (fn === OPS.restore || fn === OPS.endText)) {
  44829. // heuristic to flush on boundary of restore or endText
  44830. this.flush();
  44831. }
  44832. }
  44833. },
  44834. addDependency: function(dependency) {
  44835. if (dependency in this.dependencies) {
  44836. return;
  44837. }
  44838. this.dependencies[dependency] = true;
  44839. this.addOp(OPS.dependency, [dependency]);
  44840. },
  44841. addDependencies: function(dependencies) {
  44842. for (var key in dependencies) {
  44843. this.addDependency(key);
  44844. }
  44845. },
  44846. addOpList: function(opList) {
  44847. Util.extendObj(this.dependencies, opList.dependencies);
  44848. for (var i = 0, ii = opList.length; i < ii; i++) {
  44849. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  44850. }
  44851. },
  44852. getIR: function() {
  44853. return {
  44854. fnArray: this.fnArray,
  44855. argsArray: this.argsArray,
  44856. length: this.length
  44857. };
  44858. },
  44859. flush: function(lastChunk) {
  44860. if (this.intent !== 'oplist') {
  44861. new QueueOptimizer().optimize(this);
  44862. }
  44863. var transfers = getTransfers(this);
  44864. var length = this.length;
  44865. this._totalLength += length;
  44866. this.messageHandler.send('RenderPageChunk', {
  44867. operatorList: {
  44868. fnArray: this.fnArray,
  44869. argsArray: this.argsArray,
  44870. lastChunk: lastChunk,
  44871. length: length
  44872. },
  44873. pageIndex: this.pageIndex,
  44874. intent: this.intent
  44875. }, transfers);
  44876. this.dependencies = Object.create(null);
  44877. this.fnArray.length = 0;
  44878. this.argsArray.length = 0;
  44879. }
  44880. };
  44881. return OperatorList;
  44882. })();
  44883. var StateManager = (function StateManagerClosure() {
  44884. function StateManager(initialState) {
  44885. this.state = initialState;
  44886. this.stateStack = [];
  44887. }
  44888. StateManager.prototype = {
  44889. save: function () {
  44890. var old = this.state;
  44891. this.stateStack.push(this.state);
  44892. this.state = old.clone();
  44893. },
  44894. restore: function () {
  44895. var prev = this.stateStack.pop();
  44896. if (prev) {
  44897. this.state = prev;
  44898. }
  44899. },
  44900. transform: function (args) {
  44901. this.state.ctm = Util.transform(this.state.ctm, args);
  44902. }
  44903. };
  44904. return StateManager;
  44905. })();
  44906. var TextState = (function TextStateClosure() {
  44907. function TextState() {
  44908. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44909. this.fontName = null;
  44910. this.fontSize = 0;
  44911. this.font = null;
  44912. this.fontMatrix = FONT_IDENTITY_MATRIX;
  44913. this.textMatrix = IDENTITY_MATRIX.slice();
  44914. this.textLineMatrix = IDENTITY_MATRIX.slice();
  44915. this.charSpacing = 0;
  44916. this.wordSpacing = 0;
  44917. this.leading = 0;
  44918. this.textHScale = 1;
  44919. this.textRise = 0;
  44920. }
  44921. TextState.prototype = {
  44922. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  44923. var m = this.textMatrix;
  44924. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  44925. },
  44926. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  44927. var m = this.textLineMatrix;
  44928. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  44929. },
  44930. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  44931. var m = this.textMatrix;
  44932. m[4] = m[0] * x + m[2] * y + m[4];
  44933. m[5] = m[1] * x + m[3] * y + m[5];
  44934. },
  44935. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  44936. var m = this.textLineMatrix;
  44937. m[4] = m[0] * x + m[2] * y + m[4];
  44938. m[5] = m[1] * x + m[3] * y + m[5];
  44939. },
  44940. calcTextLineMatrixAdvance:
  44941. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  44942. var font = this.font;
  44943. if (!font) {
  44944. return null;
  44945. }
  44946. var m = this.textLineMatrix;
  44947. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  44948. return null;
  44949. }
  44950. var txDiff = e - m[4], tyDiff = f - m[5];
  44951. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  44952. return null;
  44953. }
  44954. var tx, ty, denominator = a * d - b * c;
  44955. if (font.vertical) {
  44956. tx = -tyDiff * c / denominator;
  44957. ty = tyDiff * a / denominator;
  44958. } else {
  44959. tx = txDiff * d / denominator;
  44960. ty = -txDiff * b / denominator;
  44961. }
  44962. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  44963. },
  44964. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  44965. // 9.4.4 Text Space Details
  44966. var tsm = [this.fontSize * this.textHScale, 0,
  44967. 0, this.fontSize,
  44968. 0, this.textRise];
  44969. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  44970. },
  44971. carriageReturn: function TextState_carriageReturn() {
  44972. this.translateTextLineMatrix(0, -this.leading);
  44973. this.textMatrix = this.textLineMatrix.slice();
  44974. },
  44975. clone: function TextState_clone() {
  44976. var clone = Object.create(this);
  44977. clone.textMatrix = this.textMatrix.slice();
  44978. clone.textLineMatrix = this.textLineMatrix.slice();
  44979. clone.fontMatrix = this.fontMatrix.slice();
  44980. return clone;
  44981. }
  44982. };
  44983. return TextState;
  44984. })();
  44985. var EvalState = (function EvalStateClosure() {
  44986. function EvalState() {
  44987. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44988. this.font = null;
  44989. this.textRenderingMode = TextRenderingMode.FILL;
  44990. this.fillColorSpace = ColorSpace.singletons.gray;
  44991. this.strokeColorSpace = ColorSpace.singletons.gray;
  44992. }
  44993. EvalState.prototype = {
  44994. clone: function CanvasExtraState_clone() {
  44995. return Object.create(this);
  44996. },
  44997. };
  44998. return EvalState;
  44999. })();
  45000. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  45001. // Specifies properties for each command
  45002. //
  45003. // If variableArgs === true: [0, `numArgs`] expected
  45004. // If variableArgs === false: exactly `numArgs` expected
  45005. var getOPMap = getLookupTableFactory(function (t) {
  45006. // Graphic state
  45007. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  45008. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  45009. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  45010. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  45011. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  45012. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  45013. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  45014. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  45015. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  45016. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  45017. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  45018. // Path
  45019. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  45020. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  45021. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  45022. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  45023. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  45024. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  45025. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  45026. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  45027. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  45028. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  45029. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  45030. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  45031. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  45032. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  45033. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  45034. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  45035. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  45036. // Clipping
  45037. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  45038. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  45039. // Text
  45040. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  45041. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  45042. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  45043. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  45044. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  45045. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  45046. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  45047. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  45048. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  45049. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  45050. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  45051. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  45052. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  45053. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  45054. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  45055. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  45056. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  45057. variableArgs: false };
  45058. // Type3 fonts
  45059. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  45060. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  45061. variableArgs: false };
  45062. // Color
  45063. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  45064. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  45065. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  45066. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  45067. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  45068. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  45069. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  45070. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  45071. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  45072. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  45073. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  45074. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  45075. // Shading
  45076. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  45077. // Images
  45078. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  45079. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  45080. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  45081. // XObjects
  45082. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  45083. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  45084. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  45085. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  45086. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  45087. variableArgs: false };
  45088. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  45089. // Compatibility
  45090. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  45091. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  45092. // (reserved partial commands for the lexer)
  45093. t['BM'] = null;
  45094. t['BD'] = null;
  45095. t['true'] = null;
  45096. t['fa'] = null;
  45097. t['fal'] = null;
  45098. t['fals'] = null;
  45099. t['false'] = null;
  45100. t['nu'] = null;
  45101. t['nul'] = null;
  45102. t['null'] = null;
  45103. });
  45104. function EvaluatorPreprocessor(stream, xref, stateManager) {
  45105. this.opMap = getOPMap();
  45106. // TODO(mduan): pass array of knownCommands rather than this.opMap
  45107. // dictionary
  45108. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  45109. this.stateManager = stateManager;
  45110. this.nonProcessedArgs = [];
  45111. }
  45112. EvaluatorPreprocessor.prototype = {
  45113. get savedStatesDepth() {
  45114. return this.stateManager.stateStack.length;
  45115. },
  45116. // |operation| is an object with two fields:
  45117. //
  45118. // - |fn| is an out param.
  45119. //
  45120. // - |args| is an inout param. On entry, it should have one of two values.
  45121. //
  45122. // - An empty array. This indicates that the caller is providing the
  45123. // array in which the args will be stored in. The caller should use
  45124. // this value if it can reuse a single array for each call to read().
  45125. //
  45126. // - |null|. This indicates that the caller needs this function to create
  45127. // the array in which any args are stored in. If there are zero args,
  45128. // this function will leave |operation.args| as |null| (thus avoiding
  45129. // allocations that would occur if we used an empty array to represent
  45130. // zero arguments). Otherwise, it will replace |null| with a new array
  45131. // containing the arguments. The caller should use this value if it
  45132. // cannot reuse an array for each call to read().
  45133. //
  45134. // These two modes are present because this function is very hot and so
  45135. // avoiding allocations where possible is worthwhile.
  45136. //
  45137. read: function EvaluatorPreprocessor_read(operation) {
  45138. var args = operation.args;
  45139. while (true) {
  45140. var obj = this.parser.getObj();
  45141. if (isCmd(obj)) {
  45142. var cmd = obj.cmd;
  45143. // Check that the command is valid
  45144. var opSpec = this.opMap[cmd];
  45145. if (!opSpec) {
  45146. warn('Unknown command "' + cmd + '"');
  45147. continue;
  45148. }
  45149. var fn = opSpec.id;
  45150. var numArgs = opSpec.numArgs;
  45151. var argsLength = args !== null ? args.length : 0;
  45152. if (!opSpec.variableArgs) {
  45153. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  45154. if (argsLength !== numArgs) {
  45155. var nonProcessedArgs = this.nonProcessedArgs;
  45156. while (argsLength > numArgs) {
  45157. nonProcessedArgs.push(args.shift());
  45158. argsLength--;
  45159. }
  45160. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  45161. if (!args) {
  45162. args = [];
  45163. }
  45164. args.unshift(nonProcessedArgs.pop());
  45165. argsLength++;
  45166. }
  45167. }
  45168. if (argsLength < numArgs) {
  45169. // If we receive too few args, it's not possible to possible
  45170. // to execute the command, so skip the command
  45171. info('Command ' + fn + ': because expected ' +
  45172. numArgs + ' args, but received ' + argsLength +
  45173. ' args; skipping');
  45174. args = null;
  45175. continue;
  45176. }
  45177. } else if (argsLength > numArgs) {
  45178. info('Command ' + fn + ': expected [0,' + numArgs +
  45179. '] args, but received ' + argsLength + ' args');
  45180. }
  45181. // TODO figure out how to type-check vararg functions
  45182. this.preprocessCommand(fn, args);
  45183. operation.fn = fn;
  45184. operation.args = args;
  45185. return true;
  45186. } else {
  45187. if (isEOF(obj)) {
  45188. return false; // no more commands
  45189. }
  45190. // argument
  45191. if (obj !== null) {
  45192. if (!args) {
  45193. args = [];
  45194. }
  45195. args.push(obj);
  45196. assert(args.length <= 33, 'Too many arguments');
  45197. }
  45198. }
  45199. }
  45200. },
  45201. preprocessCommand:
  45202. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  45203. switch (fn | 0) {
  45204. case OPS.save:
  45205. this.stateManager.save();
  45206. break;
  45207. case OPS.restore:
  45208. this.stateManager.restore();
  45209. break;
  45210. case OPS.transform:
  45211. this.stateManager.transform(args);
  45212. break;
  45213. }
  45214. }
  45215. };
  45216. return EvaluatorPreprocessor;
  45217. })();
  45218. var QueueOptimizer = (function QueueOptimizerClosure() {
  45219. function addState(parentState, pattern, fn) {
  45220. var state = parentState;
  45221. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  45222. var item = pattern[i];
  45223. state = (state[item] || (state[item] = []));
  45224. }
  45225. state[pattern[pattern.length - 1]] = fn;
  45226. }
  45227. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45228. argsArray) {
  45229. // Handles special case of mainly LaTeX documents which use image masks to
  45230. // draw lines with the current fill style.
  45231. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  45232. // have been found at iFirstSave.
  45233. var iFirstPIMXO = iFirstSave + 2;
  45234. for (var i = 0; i < count; i++) {
  45235. var arg = argsArray[iFirstPIMXO + 4 * i];
  45236. var imageMask = arg.length === 1 && arg[0];
  45237. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  45238. (!imageMask.data.length ||
  45239. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  45240. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  45241. continue;
  45242. }
  45243. break;
  45244. }
  45245. return count - i;
  45246. }
  45247. var InitialState = [];
  45248. // This replaces (save, transform, paintInlineImageXObject, restore)+
  45249. // sequences with one |paintInlineImageXObjectGroup| operation.
  45250. addState(InitialState,
  45251. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  45252. function foundInlineImageGroup(context) {
  45253. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  45254. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  45255. var MAX_WIDTH = 1000;
  45256. var IMAGE_PADDING = 1;
  45257. var fnArray = context.fnArray, argsArray = context.argsArray;
  45258. var curr = context.iCurr;
  45259. var iFirstSave = curr - 3;
  45260. var iFirstTransform = curr - 2;
  45261. var iFirstPIIXO = curr - 1;
  45262. // Look for the quartets.
  45263. var i = iFirstSave + 4;
  45264. var ii = fnArray.length;
  45265. while (i + 3 < ii) {
  45266. if (fnArray[i] !== OPS.save ||
  45267. fnArray[i + 1] !== OPS.transform ||
  45268. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  45269. fnArray[i + 3] !== OPS.restore) {
  45270. break; // ops don't match
  45271. }
  45272. i += 4;
  45273. }
  45274. // At this point, i is the index of the first op past the last valid
  45275. // quartet.
  45276. var count = Math.min((i - iFirstSave) / 4,
  45277. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  45278. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  45279. return i;
  45280. }
  45281. // assuming that heights of those image is too small (~1 pixel)
  45282. // packing as much as possible by lines
  45283. var maxX = 0;
  45284. var map = [], maxLineHeight = 0;
  45285. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  45286. var q;
  45287. for (q = 0; q < count; q++) {
  45288. var transform = argsArray[iFirstTransform + (q << 2)];
  45289. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  45290. if (currentX + img.width > MAX_WIDTH) {
  45291. // starting new line
  45292. maxX = Math.max(maxX, currentX);
  45293. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  45294. currentX = 0;
  45295. maxLineHeight = 0;
  45296. }
  45297. map.push({
  45298. transform: transform,
  45299. x: currentX, y: currentY,
  45300. w: img.width, h: img.height
  45301. });
  45302. currentX += img.width + 2 * IMAGE_PADDING;
  45303. maxLineHeight = Math.max(maxLineHeight, img.height);
  45304. }
  45305. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  45306. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  45307. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  45308. var imgRowSize = imgWidth << 2;
  45309. for (q = 0; q < count; q++) {
  45310. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  45311. // Copy image by lines and extends pixels into padding.
  45312. var rowSize = map[q].w << 2;
  45313. var dataOffset = 0;
  45314. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  45315. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  45316. for (var k = 0, kk = map[q].h; k < kk; k++) {
  45317. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  45318. dataOffset += rowSize;
  45319. offset += imgRowSize;
  45320. }
  45321. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  45322. while (offset >= 0) {
  45323. data[offset - 4] = data[offset];
  45324. data[offset - 3] = data[offset + 1];
  45325. data[offset - 2] = data[offset + 2];
  45326. data[offset - 1] = data[offset + 3];
  45327. data[offset + rowSize] = data[offset + rowSize - 4];
  45328. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  45329. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  45330. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  45331. offset -= imgRowSize;
  45332. }
  45333. }
  45334. // Replace queue items.
  45335. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  45336. argsArray.splice(iFirstSave, count * 4,
  45337. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  45338. data: imgData }, map]);
  45339. return iFirstSave + 1;
  45340. });
  45341. // This replaces (save, transform, paintImageMaskXObject, restore)+
  45342. // sequences with one |paintImageMaskXObjectGroup| or one
  45343. // |paintImageMaskXObjectRepeat| operation.
  45344. addState(InitialState,
  45345. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  45346. function foundImageMaskGroup(context) {
  45347. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  45348. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  45349. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  45350. var fnArray = context.fnArray, argsArray = context.argsArray;
  45351. var curr = context.iCurr;
  45352. var iFirstSave = curr - 3;
  45353. var iFirstTransform = curr - 2;
  45354. var iFirstPIMXO = curr - 1;
  45355. // Look for the quartets.
  45356. var i = iFirstSave + 4;
  45357. var ii = fnArray.length;
  45358. while (i + 3 < ii) {
  45359. if (fnArray[i] !== OPS.save ||
  45360. fnArray[i + 1] !== OPS.transform ||
  45361. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  45362. fnArray[i + 3] !== OPS.restore) {
  45363. break; // ops don't match
  45364. }
  45365. i += 4;
  45366. }
  45367. // At this point, i is the index of the first op past the last valid
  45368. // quartet.
  45369. var count = (i - iFirstSave) / 4;
  45370. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45371. argsArray);
  45372. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  45373. return i;
  45374. }
  45375. var q;
  45376. var isSameImage = false;
  45377. var iTransform, transformArgs;
  45378. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  45379. if (argsArray[iFirstTransform][1] === 0 &&
  45380. argsArray[iFirstTransform][2] === 0) {
  45381. isSameImage = true;
  45382. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45383. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45384. iTransform = iFirstTransform + 4;
  45385. var iPIMXO = iFirstPIMXO + 4;
  45386. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  45387. transformArgs = argsArray[iTransform];
  45388. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  45389. transformArgs[0] !== firstTransformArg0 ||
  45390. transformArgs[1] !== 0 ||
  45391. transformArgs[2] !== 0 ||
  45392. transformArgs[3] !== firstTransformArg3) {
  45393. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  45394. isSameImage = false;
  45395. } else {
  45396. count = q;
  45397. }
  45398. break; // different image or transform
  45399. }
  45400. }
  45401. }
  45402. if (isSameImage) {
  45403. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  45404. var positions = new Float32Array(count * 2);
  45405. iTransform = iFirstTransform;
  45406. for (q = 0; q < count; q++, iTransform += 4) {
  45407. transformArgs = argsArray[iTransform];
  45408. positions[(q << 1)] = transformArgs[4];
  45409. positions[(q << 1) + 1] = transformArgs[5];
  45410. }
  45411. // Replace queue items.
  45412. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  45413. argsArray.splice(iFirstSave, count * 4,
  45414. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  45415. } else {
  45416. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  45417. var images = [];
  45418. for (q = 0; q < count; q++) {
  45419. transformArgs = argsArray[iFirstTransform + (q << 2)];
  45420. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  45421. images.push({ data: maskParams.data, width: maskParams.width,
  45422. height: maskParams.height,
  45423. transform: transformArgs });
  45424. }
  45425. // Replace queue items.
  45426. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  45427. argsArray.splice(iFirstSave, count * 4, [images]);
  45428. }
  45429. return iFirstSave + 1;
  45430. });
  45431. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  45432. // with one paintImageXObjectRepeat operation, if the |transform| and
  45433. // |paintImageXObjectRepeat| ops are appropriate.
  45434. addState(InitialState,
  45435. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  45436. function (context) {
  45437. var MIN_IMAGES_IN_BLOCK = 3;
  45438. var MAX_IMAGES_IN_BLOCK = 1000;
  45439. var fnArray = context.fnArray, argsArray = context.argsArray;
  45440. var curr = context.iCurr;
  45441. var iFirstSave = curr - 3;
  45442. var iFirstTransform = curr - 2;
  45443. var iFirstPIXO = curr - 1;
  45444. var iFirstRestore = curr;
  45445. if (argsArray[iFirstTransform][1] !== 0 ||
  45446. argsArray[iFirstTransform][2] !== 0) {
  45447. return iFirstRestore + 1; // transform has the wrong form
  45448. }
  45449. // Look for the quartets.
  45450. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  45451. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45452. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45453. var i = iFirstSave + 4;
  45454. var ii = fnArray.length;
  45455. while (i + 3 < ii) {
  45456. if (fnArray[i] !== OPS.save ||
  45457. fnArray[i + 1] !== OPS.transform ||
  45458. fnArray[i + 2] !== OPS.paintImageXObject ||
  45459. fnArray[i + 3] !== OPS.restore) {
  45460. break; // ops don't match
  45461. }
  45462. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  45463. argsArray[i + 1][1] !== 0 ||
  45464. argsArray[i + 1][2] !== 0 ||
  45465. argsArray[i + 1][3] !== firstTransformArg3) {
  45466. break; // transforms don't match
  45467. }
  45468. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  45469. break; // images don't match
  45470. }
  45471. i += 4;
  45472. }
  45473. // At this point, i is the index of the first op past the last valid
  45474. // quartet.
  45475. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  45476. if (count < MIN_IMAGES_IN_BLOCK) {
  45477. return i;
  45478. }
  45479. // Extract the (x,y) positions from all of the matching transforms.
  45480. var positions = new Float32Array(count * 2);
  45481. var iTransform = iFirstTransform;
  45482. for (var q = 0; q < count; q++, iTransform += 4) {
  45483. var transformArgs = argsArray[iTransform];
  45484. positions[(q << 1)] = transformArgs[4];
  45485. positions[(q << 1) + 1] = transformArgs[5];
  45486. }
  45487. // Replace queue items.
  45488. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  45489. positions];
  45490. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  45491. argsArray.splice(iFirstSave, count * 4, args);
  45492. return iFirstSave + 1;
  45493. });
  45494. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  45495. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  45496. // sequences, if the font for each one is the same.
  45497. addState(InitialState,
  45498. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  45499. function (context) {
  45500. var MIN_CHARS_IN_BLOCK = 3;
  45501. var MAX_CHARS_IN_BLOCK = 1000;
  45502. var fnArray = context.fnArray, argsArray = context.argsArray;
  45503. var curr = context.iCurr;
  45504. var iFirstBeginText = curr - 4;
  45505. var iFirstSetFont = curr - 3;
  45506. var iFirstSetTextMatrix = curr - 2;
  45507. var iFirstShowText = curr - 1;
  45508. var iFirstEndText = curr;
  45509. // Look for the quintets.
  45510. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  45511. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  45512. var i = iFirstBeginText + 5;
  45513. var ii = fnArray.length;
  45514. while (i + 4 < ii) {
  45515. if (fnArray[i] !== OPS.beginText ||
  45516. fnArray[i + 1] !== OPS.setFont ||
  45517. fnArray[i + 2] !== OPS.setTextMatrix ||
  45518. fnArray[i + 3] !== OPS.showText ||
  45519. fnArray[i + 4] !== OPS.endText) {
  45520. break; // ops don't match
  45521. }
  45522. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  45523. argsArray[i + 1][1] !== firstSetFontArg1) {
  45524. break; // fonts don't match
  45525. }
  45526. i += 5;
  45527. }
  45528. // At this point, i is the index of the first op past the last valid
  45529. // quintet.
  45530. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  45531. if (count < MIN_CHARS_IN_BLOCK) {
  45532. return i;
  45533. }
  45534. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  45535. // showText, endText), include that as well. (E.g. <something> might be
  45536. // |dependency|.)
  45537. var iFirst = iFirstBeginText;
  45538. if (iFirstBeginText >= 4 &&
  45539. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  45540. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  45541. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  45542. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  45543. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  45544. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  45545. count++;
  45546. iFirst -= 5;
  45547. }
  45548. // Remove (endText, beginText, setFont) trios.
  45549. var iEndText = iFirst + 4;
  45550. for (var q = 1; q < count; q++) {
  45551. fnArray.splice(iEndText, 3);
  45552. argsArray.splice(iEndText, 3);
  45553. iEndText += 2;
  45554. }
  45555. return iEndText + 1;
  45556. });
  45557. function QueueOptimizer() {}
  45558. QueueOptimizer.prototype = {
  45559. optimize: function QueueOptimizer_optimize(queue) {
  45560. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  45561. var context = {
  45562. iCurr: 0,
  45563. fnArray: fnArray,
  45564. argsArray: argsArray
  45565. };
  45566. var state;
  45567. var i = 0, ii = fnArray.length;
  45568. while (i < ii) {
  45569. state = (state || InitialState)[fnArray[i]];
  45570. if (typeof state === 'function') { // we found some handler
  45571. context.iCurr = i;
  45572. // state() returns the index of the first non-matching op (if we
  45573. // didn't match) or the first op past the modified ops (if we did
  45574. // match and replace).
  45575. i = state(context);
  45576. state = undefined; // reset the state machine
  45577. ii = context.fnArray.length;
  45578. } else {
  45579. i++;
  45580. }
  45581. }
  45582. }
  45583. };
  45584. return QueueOptimizer;
  45585. })();
  45586. exports.OperatorList = OperatorList;
  45587. exports.PartialEvaluator = PartialEvaluator;
  45588. }));
  45589. (function (root, factory) {
  45590. {
  45591. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  45592. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  45593. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  45594. }
  45595. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  45596. coreColorSpace, coreObj, coreEvaluator) {
  45597. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  45598. var AnnotationFlag = sharedUtil.AnnotationFlag;
  45599. var AnnotationType = sharedUtil.AnnotationType;
  45600. var OPS = sharedUtil.OPS;
  45601. var Util = sharedUtil.Util;
  45602. var isBool = sharedUtil.isBool;
  45603. var isString = sharedUtil.isString;
  45604. var isArray = sharedUtil.isArray;
  45605. var isInt = sharedUtil.isInt;
  45606. var isValidUrl = sharedUtil.isValidUrl;
  45607. var stringToBytes = sharedUtil.stringToBytes;
  45608. var stringToPDFString = sharedUtil.stringToPDFString;
  45609. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45610. var warn = sharedUtil.warn;
  45611. var Dict = corePrimitives.Dict;
  45612. var isDict = corePrimitives.isDict;
  45613. var isName = corePrimitives.isName;
  45614. var isRef = corePrimitives.isRef;
  45615. var Stream = coreStream.Stream;
  45616. var ColorSpace = coreColorSpace.ColorSpace;
  45617. var ObjectLoader = coreObj.ObjectLoader;
  45618. var FileSpec = coreObj.FileSpec;
  45619. var OperatorList = coreEvaluator.OperatorList;
  45620. /**
  45621. * @class
  45622. * @alias AnnotationFactory
  45623. */
  45624. function AnnotationFactory() {}
  45625. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  45626. /**
  45627. * @param {XRef} xref
  45628. * @param {Object} ref
  45629. * @returns {Annotation}
  45630. */
  45631. create: function AnnotationFactory_create(xref, ref,
  45632. uniquePrefix, idCounters) {
  45633. var dict = xref.fetchIfRef(ref);
  45634. if (!isDict(dict)) {
  45635. return;
  45636. }
  45637. var id = isRef(ref) ? ref.toString() :
  45638. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  45639. // Determine the annotation's subtype.
  45640. var subtype = dict.get('Subtype');
  45641. subtype = isName(subtype) ? subtype.name : null;
  45642. // Return the right annotation object based on the subtype and field type.
  45643. var parameters = {
  45644. xref: xref,
  45645. dict: dict,
  45646. ref: isRef(ref) ? ref : null,
  45647. subtype: subtype,
  45648. id: id,
  45649. };
  45650. switch (subtype) {
  45651. case 'Link':
  45652. return new LinkAnnotation(parameters);
  45653. case 'Text':
  45654. return new TextAnnotation(parameters);
  45655. case 'Widget':
  45656. var fieldType = Util.getInheritableProperty(dict, 'FT');
  45657. fieldType = isName(fieldType) ? fieldType.name : null;
  45658. switch (fieldType) {
  45659. case 'Tx':
  45660. return new TextWidgetAnnotation(parameters);
  45661. }
  45662. warn('Unimplemented widget field type "' + fieldType + '", ' +
  45663. 'falling back to base field type.');
  45664. return new WidgetAnnotation(parameters);
  45665. case 'Popup':
  45666. return new PopupAnnotation(parameters);
  45667. case 'Highlight':
  45668. return new HighlightAnnotation(parameters);
  45669. case 'Underline':
  45670. return new UnderlineAnnotation(parameters);
  45671. case 'Squiggly':
  45672. return new SquigglyAnnotation(parameters);
  45673. case 'StrikeOut':
  45674. return new StrikeOutAnnotation(parameters);
  45675. case 'FileAttachment':
  45676. return new FileAttachmentAnnotation(parameters);
  45677. default:
  45678. if (!subtype) {
  45679. warn('Annotation is missing the required /Subtype.');
  45680. } else {
  45681. warn('Unimplemented annotation type "' + subtype + '", ' +
  45682. 'falling back to base annotation.');
  45683. }
  45684. return new Annotation(parameters);
  45685. }
  45686. }
  45687. };
  45688. var Annotation = (function AnnotationClosure() {
  45689. // 12.5.5: Algorithm: Appearance streams
  45690. function getTransformMatrix(rect, bbox, matrix) {
  45691. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  45692. var minX = bounds[0];
  45693. var minY = bounds[1];
  45694. var maxX = bounds[2];
  45695. var maxY = bounds[3];
  45696. if (minX === maxX || minY === maxY) {
  45697. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  45698. // just apply the transform for rect
  45699. return [1, 0, 0, 1, rect[0], rect[1]];
  45700. }
  45701. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  45702. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  45703. return [
  45704. xRatio,
  45705. 0,
  45706. 0,
  45707. yRatio,
  45708. rect[0] - minX * xRatio,
  45709. rect[1] - minY * yRatio
  45710. ];
  45711. }
  45712. function getDefaultAppearance(dict) {
  45713. var appearanceState = dict.get('AP');
  45714. if (!isDict(appearanceState)) {
  45715. return;
  45716. }
  45717. var appearance;
  45718. var appearances = appearanceState.get('N');
  45719. if (isDict(appearances)) {
  45720. var as = dict.get('AS');
  45721. if (as && appearances.has(as.name)) {
  45722. appearance = appearances.get(as.name);
  45723. }
  45724. } else {
  45725. appearance = appearances;
  45726. }
  45727. return appearance;
  45728. }
  45729. function Annotation(params) {
  45730. var dict = params.dict;
  45731. this.setFlags(dict.get('F'));
  45732. this.setRectangle(dict.getArray('Rect'));
  45733. this.setColor(dict.getArray('C'));
  45734. this.setBorderStyle(dict);
  45735. this.appearance = getDefaultAppearance(dict);
  45736. // Expose public properties using a data object.
  45737. this.data = {};
  45738. this.data.id = params.id;
  45739. this.data.subtype = params.subtype;
  45740. this.data.annotationFlags = this.flags;
  45741. this.data.rect = this.rectangle;
  45742. this.data.color = this.color;
  45743. this.data.borderStyle = this.borderStyle;
  45744. this.data.hasAppearance = !!this.appearance;
  45745. }
  45746. Annotation.prototype = {
  45747. /**
  45748. * @private
  45749. */
  45750. _hasFlag: function Annotation_hasFlag(flags, flag) {
  45751. return !!(flags & flag);
  45752. },
  45753. /**
  45754. * @private
  45755. */
  45756. _isViewable: function Annotation_isViewable(flags) {
  45757. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45758. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  45759. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  45760. },
  45761. /**
  45762. * @private
  45763. */
  45764. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  45765. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  45766. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45767. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  45768. },
  45769. /**
  45770. * @return {boolean}
  45771. */
  45772. get viewable() {
  45773. if (this.flags === 0) {
  45774. return true;
  45775. }
  45776. return this._isViewable(this.flags);
  45777. },
  45778. /**
  45779. * @return {boolean}
  45780. */
  45781. get printable() {
  45782. if (this.flags === 0) {
  45783. return false;
  45784. }
  45785. return this._isPrintable(this.flags);
  45786. },
  45787. /**
  45788. * Set the flags.
  45789. *
  45790. * @public
  45791. * @memberof Annotation
  45792. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  45793. * characteristics
  45794. * @see {@link shared/util.js}
  45795. */
  45796. setFlags: function Annotation_setFlags(flags) {
  45797. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  45798. },
  45799. /**
  45800. * Check if a provided flag is set.
  45801. *
  45802. * @public
  45803. * @memberof Annotation
  45804. * @param {number} flag - Hexadecimal representation for an annotation
  45805. * characteristic
  45806. * @return {boolean}
  45807. * @see {@link shared/util.js}
  45808. */
  45809. hasFlag: function Annotation_hasFlag(flag) {
  45810. return this._hasFlag(this.flags, flag);
  45811. },
  45812. /**
  45813. * Set the rectangle.
  45814. *
  45815. * @public
  45816. * @memberof Annotation
  45817. * @param {Array} rectangle - The rectangle array with exactly four entries
  45818. */
  45819. setRectangle: function Annotation_setRectangle(rectangle) {
  45820. if (isArray(rectangle) && rectangle.length === 4) {
  45821. this.rectangle = Util.normalizeRect(rectangle);
  45822. } else {
  45823. this.rectangle = [0, 0, 0, 0];
  45824. }
  45825. },
  45826. /**
  45827. * Set the color and take care of color space conversion.
  45828. *
  45829. * @public
  45830. * @memberof Annotation
  45831. * @param {Array} color - The color array containing either 0
  45832. * (transparent), 1 (grayscale), 3 (RGB) or
  45833. * 4 (CMYK) elements
  45834. */
  45835. setColor: function Annotation_setColor(color) {
  45836. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  45837. if (!isArray(color)) {
  45838. this.color = rgbColor;
  45839. return;
  45840. }
  45841. switch (color.length) {
  45842. case 0: // Transparent, which we indicate with a null value
  45843. this.color = null;
  45844. break;
  45845. case 1: // Convert grayscale to RGB
  45846. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  45847. this.color = rgbColor;
  45848. break;
  45849. case 3: // Convert RGB percentages to RGB
  45850. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  45851. this.color = rgbColor;
  45852. break;
  45853. case 4: // Convert CMYK to RGB
  45854. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  45855. this.color = rgbColor;
  45856. break;
  45857. default:
  45858. this.color = rgbColor;
  45859. break;
  45860. }
  45861. },
  45862. /**
  45863. * Set the border style (as AnnotationBorderStyle object).
  45864. *
  45865. * @public
  45866. * @memberof Annotation
  45867. * @param {Dict} borderStyle - The border style dictionary
  45868. */
  45869. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  45870. this.borderStyle = new AnnotationBorderStyle();
  45871. if (!isDict(borderStyle)) {
  45872. return;
  45873. }
  45874. if (borderStyle.has('BS')) {
  45875. var dict = borderStyle.get('BS');
  45876. var dictType = dict.get('Type');
  45877. if (!dictType || isName(dictType, 'Border')) {
  45878. this.borderStyle.setWidth(dict.get('W'));
  45879. this.borderStyle.setStyle(dict.get('S'));
  45880. this.borderStyle.setDashArray(dict.getArray('D'));
  45881. }
  45882. } else if (borderStyle.has('Border')) {
  45883. var array = borderStyle.getArray('Border');
  45884. if (isArray(array) && array.length >= 3) {
  45885. this.borderStyle.setHorizontalCornerRadius(array[0]);
  45886. this.borderStyle.setVerticalCornerRadius(array[1]);
  45887. this.borderStyle.setWidth(array[2]);
  45888. if (array.length === 4) { // Dash array available
  45889. this.borderStyle.setDashArray(array[3]);
  45890. }
  45891. }
  45892. } else {
  45893. // There are no border entries in the dictionary. According to the
  45894. // specification, we should draw a solid border of width 1 in that
  45895. // case, but Adobe Reader did not implement that part of the
  45896. // specification and instead draws no border at all, so we do the same.
  45897. // See also https://github.com/mozilla/pdf.js/issues/6179.
  45898. this.borderStyle.setWidth(0);
  45899. }
  45900. },
  45901. /**
  45902. * Prepare the annotation for working with a popup in the display layer.
  45903. *
  45904. * @private
  45905. * @memberof Annotation
  45906. * @param {Dict} dict - The annotation's data dictionary
  45907. */
  45908. _preparePopup: function Annotation_preparePopup(dict) {
  45909. if (!dict.has('C')) {
  45910. // Fall back to the default background color.
  45911. this.data.color = null;
  45912. }
  45913. this.data.hasPopup = dict.has('Popup');
  45914. this.data.title = stringToPDFString(dict.get('T') || '');
  45915. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  45916. },
  45917. loadResources: function Annotation_loadResources(keys) {
  45918. return new Promise(function (resolve, reject) {
  45919. this.appearance.dict.getAsync('Resources').then(function (resources) {
  45920. if (!resources) {
  45921. resolve();
  45922. return;
  45923. }
  45924. var objectLoader = new ObjectLoader(resources.map,
  45925. keys,
  45926. resources.xref);
  45927. objectLoader.load().then(function() {
  45928. resolve(resources);
  45929. }, reject);
  45930. }, reject);
  45931. }.bind(this));
  45932. },
  45933. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  45934. if (!this.appearance) {
  45935. return Promise.resolve(new OperatorList());
  45936. }
  45937. var data = this.data;
  45938. var appearanceDict = this.appearance.dict;
  45939. var resourcesPromise = this.loadResources([
  45940. 'ExtGState',
  45941. 'ColorSpace',
  45942. 'Pattern',
  45943. 'Shading',
  45944. 'XObject',
  45945. 'Font'
  45946. // ProcSet
  45947. // Properties
  45948. ]);
  45949. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  45950. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  45951. var transform = getTransformMatrix(data.rect, bbox, matrix);
  45952. var self = this;
  45953. return resourcesPromise.then(function(resources) {
  45954. var opList = new OperatorList();
  45955. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  45956. return evaluator.getOperatorList(self.appearance, task,
  45957. resources, opList).
  45958. then(function () {
  45959. opList.addOp(OPS.endAnnotation, []);
  45960. self.appearance.reset();
  45961. return opList;
  45962. });
  45963. });
  45964. }
  45965. };
  45966. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  45967. annotations, opList, partialEvaluator, task, intent) {
  45968. var annotationPromises = [];
  45969. for (var i = 0, n = annotations.length; i < n; ++i) {
  45970. if ((intent === 'display' && annotations[i].viewable) ||
  45971. (intent === 'print' && annotations[i].printable)) {
  45972. annotationPromises.push(
  45973. annotations[i].getOperatorList(partialEvaluator, task));
  45974. }
  45975. }
  45976. return Promise.all(annotationPromises).then(function(operatorLists) {
  45977. opList.addOp(OPS.beginAnnotations, []);
  45978. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  45979. opList.addOpList(operatorLists[i]);
  45980. }
  45981. opList.addOp(OPS.endAnnotations, []);
  45982. });
  45983. };
  45984. return Annotation;
  45985. })();
  45986. /**
  45987. * Contains all data regarding an annotation's border style.
  45988. *
  45989. * @class
  45990. */
  45991. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  45992. /**
  45993. * @constructor
  45994. * @private
  45995. */
  45996. function AnnotationBorderStyle() {
  45997. this.width = 1;
  45998. this.style = AnnotationBorderStyleType.SOLID;
  45999. this.dashArray = [3];
  46000. this.horizontalCornerRadius = 0;
  46001. this.verticalCornerRadius = 0;
  46002. }
  46003. AnnotationBorderStyle.prototype = {
  46004. /**
  46005. * Set the width.
  46006. *
  46007. * @public
  46008. * @memberof AnnotationBorderStyle
  46009. * @param {integer} width - The width
  46010. */
  46011. setWidth: function AnnotationBorderStyle_setWidth(width) {
  46012. if (width === (width | 0)) {
  46013. this.width = width;
  46014. }
  46015. },
  46016. /**
  46017. * Set the style.
  46018. *
  46019. * @public
  46020. * @memberof AnnotationBorderStyle
  46021. * @param {Object} style - The style object
  46022. * @see {@link shared/util.js}
  46023. */
  46024. setStyle: function AnnotationBorderStyle_setStyle(style) {
  46025. if (!style) {
  46026. return;
  46027. }
  46028. switch (style.name) {
  46029. case 'S':
  46030. this.style = AnnotationBorderStyleType.SOLID;
  46031. break;
  46032. case 'D':
  46033. this.style = AnnotationBorderStyleType.DASHED;
  46034. break;
  46035. case 'B':
  46036. this.style = AnnotationBorderStyleType.BEVELED;
  46037. break;
  46038. case 'I':
  46039. this.style = AnnotationBorderStyleType.INSET;
  46040. break;
  46041. case 'U':
  46042. this.style = AnnotationBorderStyleType.UNDERLINE;
  46043. break;
  46044. default:
  46045. break;
  46046. }
  46047. },
  46048. /**
  46049. * Set the dash array.
  46050. *
  46051. * @public
  46052. * @memberof AnnotationBorderStyle
  46053. * @param {Array} dashArray - The dash array with at least one element
  46054. */
  46055. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  46056. // We validate the dash array, but we do not use it because CSS does not
  46057. // allow us to change spacing of dashes. For more information, visit
  46058. // http://www.w3.org/TR/css3-background/#the-border-style.
  46059. if (isArray(dashArray) && dashArray.length > 0) {
  46060. // According to the PDF specification: the elements in a dashArray
  46061. // shall be numbers that are nonnegative and not all equal to zero.
  46062. var isValid = true;
  46063. var allZeros = true;
  46064. for (var i = 0, len = dashArray.length; i < len; i++) {
  46065. var element = dashArray[i];
  46066. var validNumber = (+element >= 0);
  46067. if (!validNumber) {
  46068. isValid = false;
  46069. break;
  46070. } else if (element > 0) {
  46071. allZeros = false;
  46072. }
  46073. }
  46074. if (isValid && !allZeros) {
  46075. this.dashArray = dashArray;
  46076. } else {
  46077. this.width = 0; // Adobe behavior when the array is invalid.
  46078. }
  46079. } else if (dashArray) {
  46080. this.width = 0; // Adobe behavior when the array is invalid.
  46081. }
  46082. },
  46083. /**
  46084. * Set the horizontal corner radius (from a Border dictionary).
  46085. *
  46086. * @public
  46087. * @memberof AnnotationBorderStyle
  46088. * @param {integer} radius - The horizontal corner radius
  46089. */
  46090. setHorizontalCornerRadius:
  46091. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  46092. if (radius === (radius | 0)) {
  46093. this.horizontalCornerRadius = radius;
  46094. }
  46095. },
  46096. /**
  46097. * Set the vertical corner radius (from a Border dictionary).
  46098. *
  46099. * @public
  46100. * @memberof AnnotationBorderStyle
  46101. * @param {integer} radius - The vertical corner radius
  46102. */
  46103. setVerticalCornerRadius:
  46104. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  46105. if (radius === (radius | 0)) {
  46106. this.verticalCornerRadius = radius;
  46107. }
  46108. }
  46109. };
  46110. return AnnotationBorderStyle;
  46111. })();
  46112. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  46113. function WidgetAnnotation(params) {
  46114. Annotation.call(this, params);
  46115. var dict = params.dict;
  46116. var data = this.data;
  46117. data.annotationType = AnnotationType.WIDGET;
  46118. data.fieldValue = stringToPDFString(
  46119. Util.getInheritableProperty(dict, 'V') || '');
  46120. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  46121. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  46122. var fieldType = Util.getInheritableProperty(dict, 'FT');
  46123. data.fieldType = isName(fieldType) ? fieldType.name : null;
  46124. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  46125. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  46126. // Hide signatures because we cannot validate them.
  46127. if (data.fieldType === 'Sig') {
  46128. this.setFlags(AnnotationFlag.HIDDEN);
  46129. }
  46130. // Building the full field name by collecting the field and
  46131. // its ancestors 'T' data and joining them using '.'.
  46132. var fieldName = [];
  46133. var namedItem = dict;
  46134. var ref = params.ref;
  46135. while (namedItem) {
  46136. var parent = namedItem.get('Parent');
  46137. var parentRef = namedItem.getRaw('Parent');
  46138. var name = namedItem.get('T');
  46139. if (name) {
  46140. fieldName.unshift(stringToPDFString(name));
  46141. } else if (parent && ref) {
  46142. // The field name is absent, that means more than one field
  46143. // with the same name may exist. Replacing the empty name
  46144. // with the '`' plus index in the parent's 'Kids' array.
  46145. // This is not in the PDF spec but necessary to id the
  46146. // the input controls.
  46147. var kids = parent.get('Kids');
  46148. var j, jj;
  46149. for (j = 0, jj = kids.length; j < jj; j++) {
  46150. var kidRef = kids[j];
  46151. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  46152. break;
  46153. }
  46154. }
  46155. fieldName.unshift('`' + j);
  46156. }
  46157. namedItem = parent;
  46158. ref = parentRef;
  46159. }
  46160. data.fullName = fieldName.join('.');
  46161. }
  46162. Util.inherit(WidgetAnnotation, Annotation, {});
  46163. return WidgetAnnotation;
  46164. })();
  46165. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  46166. function TextWidgetAnnotation(params) {
  46167. WidgetAnnotation.call(this, params);
  46168. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  46169. this.data.maxLen = Util.getInheritableProperty(params.dict, 'MaxLen');
  46170. }
  46171. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  46172. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  46173. task) {
  46174. if (this.appearance) {
  46175. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  46176. }
  46177. var opList = new OperatorList();
  46178. var data = this.data;
  46179. // Even if there is an appearance stream, ignore it. This is the
  46180. // behaviour used by Adobe Reader.
  46181. if (!data.defaultAppearance) {
  46182. return Promise.resolve(opList);
  46183. }
  46184. var stream = new Stream(stringToBytes(data.defaultAppearance));
  46185. return evaluator.getOperatorList(stream, task,
  46186. this.fieldResources, opList).
  46187. then(function () {
  46188. return opList;
  46189. });
  46190. }
  46191. });
  46192. return TextWidgetAnnotation;
  46193. })();
  46194. var TextAnnotation = (function TextAnnotationClosure() {
  46195. var DEFAULT_ICON_SIZE = 22; // px
  46196. function TextAnnotation(parameters) {
  46197. Annotation.call(this, parameters);
  46198. this.data.annotationType = AnnotationType.TEXT;
  46199. if (this.data.hasAppearance) {
  46200. this.data.name = 'NoIcon';
  46201. } else {
  46202. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  46203. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  46204. this.data.name = parameters.dict.has('Name') ?
  46205. parameters.dict.get('Name').name : 'Note';
  46206. }
  46207. this._preparePopup(parameters.dict);
  46208. }
  46209. Util.inherit(TextAnnotation, Annotation, {});
  46210. return TextAnnotation;
  46211. })();
  46212. var LinkAnnotation = (function LinkAnnotationClosure() {
  46213. function LinkAnnotation(params) {
  46214. Annotation.call(this, params);
  46215. var dict = params.dict;
  46216. var data = this.data;
  46217. data.annotationType = AnnotationType.LINK;
  46218. var action = dict.get('A'), url, dest;
  46219. if (action && isDict(action)) {
  46220. var linkType = action.get('S').name;
  46221. switch (linkType) {
  46222. case 'URI':
  46223. url = action.get('URI');
  46224. if (isName(url)) {
  46225. // Some bad PDFs do not put parentheses around relative URLs.
  46226. url = '/' + url.name;
  46227. } else if (url) {
  46228. url = addDefaultProtocolToUrl(url);
  46229. }
  46230. // TODO: pdf spec mentions urls can be relative to a Base
  46231. // entry in the dictionary.
  46232. break;
  46233. case 'GoTo':
  46234. dest = action.get('D');
  46235. break;
  46236. case 'GoToR':
  46237. var urlDict = action.get('F');
  46238. if (isDict(urlDict)) {
  46239. // We assume that we found a FileSpec dictionary
  46240. // and fetch the URL without checking any further.
  46241. url = urlDict.get('F') || null;
  46242. } else if (isString(urlDict)) {
  46243. url = urlDict;
  46244. }
  46245. // NOTE: the destination is relative to the *remote* document.
  46246. var remoteDest = action.get('D');
  46247. if (remoteDest) {
  46248. if (isName(remoteDest)) {
  46249. remoteDest = remoteDest.name;
  46250. }
  46251. if (isString(url)) {
  46252. var baseUrl = url.split('#')[0];
  46253. if (isString(remoteDest)) {
  46254. // In practice, a named destination may contain only a number.
  46255. // If that happens, use the '#nameddest=' form to avoid the link
  46256. // redirecting to a page, instead of the correct destination.
  46257. url = baseUrl + '#' +
  46258. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  46259. } else if (isArray(remoteDest)) {
  46260. url = baseUrl + '#' + JSON.stringify(remoteDest);
  46261. }
  46262. }
  46263. }
  46264. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  46265. var newWindow = action.get('NewWindow');
  46266. if (isBool(newWindow)) {
  46267. data.newWindow = newWindow;
  46268. }
  46269. break;
  46270. case 'Named':
  46271. data.action = action.get('N').name;
  46272. break;
  46273. default:
  46274. warn('unrecognized link type: ' + linkType);
  46275. }
  46276. } else if (dict.has('Dest')) { // Simple destination link.
  46277. dest = dict.get('Dest');
  46278. }
  46279. if (url) {
  46280. if (isValidUrl(url, /* allowRelative = */ false)) {
  46281. data.url = tryConvertUrlEncoding(url);
  46282. }
  46283. }
  46284. if (dest) {
  46285. data.dest = isName(dest) ? dest.name : dest;
  46286. }
  46287. }
  46288. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  46289. function addDefaultProtocolToUrl(url) {
  46290. if (isString(url) && url.indexOf('www.') === 0) {
  46291. return ('http://' + url);
  46292. }
  46293. return url;
  46294. }
  46295. function tryConvertUrlEncoding(url) {
  46296. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  46297. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  46298. try {
  46299. return stringToUTF8String(url);
  46300. } catch (e) {
  46301. return url;
  46302. }
  46303. }
  46304. Util.inherit(LinkAnnotation, Annotation, {});
  46305. return LinkAnnotation;
  46306. })();
  46307. var PopupAnnotation = (function PopupAnnotationClosure() {
  46308. function PopupAnnotation(parameters) {
  46309. Annotation.call(this, parameters);
  46310. this.data.annotationType = AnnotationType.POPUP;
  46311. var dict = parameters.dict;
  46312. var parentItem = dict.get('Parent');
  46313. if (!parentItem) {
  46314. warn('Popup annotation has a missing or invalid parent annotation.');
  46315. return;
  46316. }
  46317. this.data.parentId = dict.getRaw('Parent').toString();
  46318. this.data.title = stringToPDFString(parentItem.get('T') || '');
  46319. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  46320. if (!parentItem.has('C')) {
  46321. // Fall back to the default background color.
  46322. this.data.color = null;
  46323. } else {
  46324. this.setColor(parentItem.getArray('C'));
  46325. this.data.color = this.color;
  46326. }
  46327. // If the Popup annotation is not viewable, but the parent annotation is,
  46328. // that is most likely a bug. Fallback to inherit the flags from the parent
  46329. // annotation (this is consistent with the behaviour in Adobe Reader).
  46330. if (!this.viewable) {
  46331. var parentFlags = parentItem.get('F');
  46332. if (this._isViewable(parentFlags)) {
  46333. this.setFlags(parentFlags);
  46334. }
  46335. }
  46336. }
  46337. Util.inherit(PopupAnnotation, Annotation, {});
  46338. return PopupAnnotation;
  46339. })();
  46340. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  46341. function HighlightAnnotation(parameters) {
  46342. Annotation.call(this, parameters);
  46343. this.data.annotationType = AnnotationType.HIGHLIGHT;
  46344. this._preparePopup(parameters.dict);
  46345. // PDF viewers completely ignore any border styles.
  46346. this.data.borderStyle.setWidth(0);
  46347. }
  46348. Util.inherit(HighlightAnnotation, Annotation, {});
  46349. return HighlightAnnotation;
  46350. })();
  46351. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  46352. function UnderlineAnnotation(parameters) {
  46353. Annotation.call(this, parameters);
  46354. this.data.annotationType = AnnotationType.UNDERLINE;
  46355. this._preparePopup(parameters.dict);
  46356. // PDF viewers completely ignore any border styles.
  46357. this.data.borderStyle.setWidth(0);
  46358. }
  46359. Util.inherit(UnderlineAnnotation, Annotation, {});
  46360. return UnderlineAnnotation;
  46361. })();
  46362. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  46363. function SquigglyAnnotation(parameters) {
  46364. Annotation.call(this, parameters);
  46365. this.data.annotationType = AnnotationType.SQUIGGLY;
  46366. this._preparePopup(parameters.dict);
  46367. // PDF viewers completely ignore any border styles.
  46368. this.data.borderStyle.setWidth(0);
  46369. }
  46370. Util.inherit(SquigglyAnnotation, Annotation, {});
  46371. return SquigglyAnnotation;
  46372. })();
  46373. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  46374. function StrikeOutAnnotation(parameters) {
  46375. Annotation.call(this, parameters);
  46376. this.data.annotationType = AnnotationType.STRIKEOUT;
  46377. this._preparePopup(parameters.dict);
  46378. // PDF viewers completely ignore any border styles.
  46379. this.data.borderStyle.setWidth(0);
  46380. }
  46381. Util.inherit(StrikeOutAnnotation, Annotation, {});
  46382. return StrikeOutAnnotation;
  46383. })();
  46384. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  46385. function FileAttachmentAnnotation(parameters) {
  46386. Annotation.call(this, parameters);
  46387. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  46388. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  46389. this.data.file = file.serializable;
  46390. this._preparePopup(parameters.dict);
  46391. }
  46392. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  46393. return FileAttachmentAnnotation;
  46394. })();
  46395. exports.Annotation = Annotation;
  46396. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  46397. exports.AnnotationFactory = AnnotationFactory;
  46398. }));
  46399. (function (root, factory) {
  46400. {
  46401. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  46402. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  46403. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  46404. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  46405. }
  46406. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  46407. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  46408. var MissingDataException = sharedUtil.MissingDataException;
  46409. var Util = sharedUtil.Util;
  46410. var assert = sharedUtil.assert;
  46411. var error = sharedUtil.error;
  46412. var info = sharedUtil.info;
  46413. var isArray = sharedUtil.isArray;
  46414. var isArrayBuffer = sharedUtil.isArrayBuffer;
  46415. var isString = sharedUtil.isString;
  46416. var shadow = sharedUtil.shadow;
  46417. var stringToBytes = sharedUtil.stringToBytes;
  46418. var stringToPDFString = sharedUtil.stringToPDFString;
  46419. var warn = sharedUtil.warn;
  46420. var isSpace = sharedUtil.isSpace;
  46421. var Dict = corePrimitives.Dict;
  46422. var isDict = corePrimitives.isDict;
  46423. var isName = corePrimitives.isName;
  46424. var isStream = corePrimitives.isStream;
  46425. var NullStream = coreStream.NullStream;
  46426. var Stream = coreStream.Stream;
  46427. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  46428. var Catalog = coreObj.Catalog;
  46429. var ObjectLoader = coreObj.ObjectLoader;
  46430. var XRef = coreObj.XRef;
  46431. var Linearization = coreParser.Linearization;
  46432. var calculateMD5 = coreCrypto.calculateMD5;
  46433. var OperatorList = coreEvaluator.OperatorList;
  46434. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  46435. var Annotation = coreAnnotation.Annotation;
  46436. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  46437. var Page = (function PageClosure() {
  46438. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  46439. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  46440. this.pdfManager = pdfManager;
  46441. this.pageIndex = pageIndex;
  46442. this.pageDict = pageDict;
  46443. this.xref = xref;
  46444. this.ref = ref;
  46445. this.fontCache = fontCache;
  46446. this.uniquePrefix = 'p' + this.pageIndex + '_';
  46447. this.idCounters = {
  46448. obj: 0
  46449. };
  46450. this.evaluatorOptions = pdfManager.evaluatorOptions;
  46451. this.resourcesPromise = null;
  46452. }
  46453. Page.prototype = {
  46454. getPageProp: function Page_getPageProp(key) {
  46455. return this.pageDict.get(key);
  46456. },
  46457. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  46458. var dict = this.pageDict, valueArray = null, loopCount = 0;
  46459. var MAX_LOOP_COUNT = 100;
  46460. // Always walk up the entire parent chain, to be able to find
  46461. // e.g. \Resources placed on multiple levels of the tree.
  46462. while (dict) {
  46463. var value = dict.get(key);
  46464. if (value) {
  46465. if (!valueArray) {
  46466. valueArray = [];
  46467. }
  46468. valueArray.push(value);
  46469. }
  46470. if (++loopCount > MAX_LOOP_COUNT) {
  46471. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  46472. break;
  46473. }
  46474. dict = dict.get('Parent');
  46475. }
  46476. if (!valueArray) {
  46477. return Dict.empty;
  46478. }
  46479. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  46480. loopCount > MAX_LOOP_COUNT) {
  46481. return valueArray[0];
  46482. }
  46483. return Dict.merge(this.xref, valueArray);
  46484. },
  46485. get content() {
  46486. return this.getPageProp('Contents');
  46487. },
  46488. get resources() {
  46489. // For robustness: The spec states that a \Resources entry has to be
  46490. // present, but can be empty. Some document omit it still, in this case
  46491. // we return an empty dictionary.
  46492. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  46493. },
  46494. get mediaBox() {
  46495. var obj = this.getInheritedPageProp('MediaBox');
  46496. // Reset invalid media box to letter size.
  46497. if (!isArray(obj) || obj.length !== 4) {
  46498. obj = LETTER_SIZE_MEDIABOX;
  46499. }
  46500. return shadow(this, 'mediaBox', obj);
  46501. },
  46502. get view() {
  46503. var mediaBox = this.mediaBox;
  46504. var cropBox = this.getInheritedPageProp('CropBox');
  46505. if (!isArray(cropBox) || cropBox.length !== 4) {
  46506. return shadow(this, 'view', mediaBox);
  46507. }
  46508. // From the spec, 6th ed., p.963:
  46509. // "The crop, bleed, trim, and art boxes should not ordinarily
  46510. // extend beyond the boundaries of the media box. If they do, they are
  46511. // effectively reduced to their intersection with the media box."
  46512. cropBox = Util.intersect(cropBox, mediaBox);
  46513. if (!cropBox) {
  46514. return shadow(this, 'view', mediaBox);
  46515. }
  46516. return shadow(this, 'view', cropBox);
  46517. },
  46518. get rotate() {
  46519. var rotate = this.getInheritedPageProp('Rotate') || 0;
  46520. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  46521. if (rotate % 90 !== 0) {
  46522. rotate = 0;
  46523. } else if (rotate >= 360) {
  46524. rotate = rotate % 360;
  46525. } else if (rotate < 0) {
  46526. // The spec doesn't cover negatives, assume its counterclockwise
  46527. // rotation. The following is the other implementation of modulo.
  46528. rotate = ((rotate % 360) + 360) % 360;
  46529. }
  46530. return shadow(this, 'rotate', rotate);
  46531. },
  46532. getContentStream: function Page_getContentStream() {
  46533. var content = this.content;
  46534. var stream;
  46535. if (isArray(content)) {
  46536. // fetching items
  46537. var xref = this.xref;
  46538. var i, n = content.length;
  46539. var streams = [];
  46540. for (i = 0; i < n; ++i) {
  46541. streams.push(xref.fetchIfRef(content[i]));
  46542. }
  46543. stream = new StreamsSequenceStream(streams);
  46544. } else if (isStream(content)) {
  46545. stream = content;
  46546. } else {
  46547. // replacing non-existent page content with empty one
  46548. stream = new NullStream();
  46549. }
  46550. return stream;
  46551. },
  46552. loadResources: function Page_loadResources(keys) {
  46553. if (!this.resourcesPromise) {
  46554. // TODO: add async getInheritedPageProp and remove this.
  46555. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  46556. }
  46557. return this.resourcesPromise.then(function resourceSuccess() {
  46558. var objectLoader = new ObjectLoader(this.resources.map,
  46559. keys,
  46560. this.xref);
  46561. return objectLoader.load();
  46562. }.bind(this));
  46563. },
  46564. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  46565. var self = this;
  46566. var pdfManager = this.pdfManager;
  46567. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46568. []);
  46569. var resourcesPromise = this.loadResources([
  46570. 'ExtGState',
  46571. 'ColorSpace',
  46572. 'Pattern',
  46573. 'Shading',
  46574. 'XObject',
  46575. 'Font'
  46576. // ProcSet
  46577. // Properties
  46578. ]);
  46579. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  46580. handler, this.pageIndex,
  46581. this.uniquePrefix,
  46582. this.idCounters,
  46583. this.fontCache,
  46584. this.evaluatorOptions);
  46585. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  46586. var pageListPromise = dataPromises.then(function(data) {
  46587. var contentStream = data[0];
  46588. var opList = new OperatorList(intent, handler, self.pageIndex);
  46589. handler.send('StartRenderPage', {
  46590. transparency: partialEvaluator.hasBlendModes(self.resources),
  46591. pageIndex: self.pageIndex,
  46592. intent: intent
  46593. });
  46594. return partialEvaluator.getOperatorList(contentStream, task,
  46595. self.resources, opList).then(function () {
  46596. return opList;
  46597. });
  46598. });
  46599. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  46600. return Promise.all([pageListPromise, annotationsPromise]).then(
  46601. function(datas) {
  46602. var pageOpList = datas[0];
  46603. var annotations = datas[1];
  46604. if (annotations.length === 0) {
  46605. pageOpList.flush(true);
  46606. return pageOpList;
  46607. }
  46608. var annotationsReadyPromise = Annotation.appendToOperatorList(
  46609. annotations, pageOpList, partialEvaluator, task, intent);
  46610. return annotationsReadyPromise.then(function () {
  46611. pageOpList.flush(true);
  46612. return pageOpList;
  46613. });
  46614. });
  46615. },
  46616. extractTextContent: function Page_extractTextContent(task,
  46617. normalizeWhitespace,
  46618. combineTextItems) {
  46619. var handler = {
  46620. on: function nullHandlerOn() {},
  46621. send: function nullHandlerSend() {}
  46622. };
  46623. var self = this;
  46624. var pdfManager = this.pdfManager;
  46625. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46626. []);
  46627. var resourcesPromise = this.loadResources([
  46628. 'ExtGState',
  46629. 'XObject',
  46630. 'Font'
  46631. ]);
  46632. var dataPromises = Promise.all([contentStreamPromise,
  46633. resourcesPromise]);
  46634. return dataPromises.then(function(data) {
  46635. var contentStream = data[0];
  46636. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  46637. handler, self.pageIndex,
  46638. self.uniquePrefix,
  46639. self.idCounters,
  46640. self.fontCache,
  46641. self.evaluatorOptions);
  46642. return partialEvaluator.getTextContent(contentStream,
  46643. task,
  46644. self.resources,
  46645. /* stateManager = */ null,
  46646. normalizeWhitespace,
  46647. combineTextItems);
  46648. });
  46649. },
  46650. getAnnotationsData: function Page_getAnnotationsData(intent) {
  46651. var annotations = this.annotations;
  46652. var annotationsData = [];
  46653. for (var i = 0, n = annotations.length; i < n; ++i) {
  46654. if (intent) {
  46655. if (!(intent === 'display' && annotations[i].viewable) &&
  46656. !(intent === 'print' && annotations[i].printable)) {
  46657. continue;
  46658. }
  46659. }
  46660. annotationsData.push(annotations[i].data);
  46661. }
  46662. return annotationsData;
  46663. },
  46664. get annotations() {
  46665. var annotations = [];
  46666. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  46667. var annotationFactory = new AnnotationFactory();
  46668. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  46669. var annotationRef = annotationRefs[i];
  46670. var annotation = annotationFactory.create(this.xref, annotationRef,
  46671. this.uniquePrefix,
  46672. this.idCounters);
  46673. if (annotation) {
  46674. annotations.push(annotation);
  46675. }
  46676. }
  46677. return shadow(this, 'annotations', annotations);
  46678. }
  46679. };
  46680. return Page;
  46681. })();
  46682. /**
  46683. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  46684. * `PDFDoc`, this one doesn't have any job management code.
  46685. * Right now there exists one PDFDocument on the main thread + one object
  46686. * for each worker. If there is no worker support enabled, there are two
  46687. * `PDFDocument` objects on the main thread created.
  46688. */
  46689. var PDFDocument = (function PDFDocumentClosure() {
  46690. var FINGERPRINT_FIRST_BYTES = 1024;
  46691. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  46692. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  46693. function PDFDocument(pdfManager, arg, password) {
  46694. if (isStream(arg)) {
  46695. init.call(this, pdfManager, arg, password);
  46696. } else if (isArrayBuffer(arg)) {
  46697. init.call(this, pdfManager, new Stream(arg), password);
  46698. } else {
  46699. error('PDFDocument: Unknown argument type');
  46700. }
  46701. }
  46702. function init(pdfManager, stream, password) {
  46703. assert(stream.length > 0, 'stream must have data');
  46704. this.pdfManager = pdfManager;
  46705. this.stream = stream;
  46706. var xref = new XRef(this.stream, password, pdfManager);
  46707. this.xref = xref;
  46708. }
  46709. function find(stream, needle, limit, backwards) {
  46710. var pos = stream.pos;
  46711. var end = stream.end;
  46712. var strBuf = [];
  46713. if (pos + limit > end) {
  46714. limit = end - pos;
  46715. }
  46716. for (var n = 0; n < limit; ++n) {
  46717. strBuf.push(String.fromCharCode(stream.getByte()));
  46718. }
  46719. var str = strBuf.join('');
  46720. stream.pos = pos;
  46721. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  46722. if (index === -1) {
  46723. return false; /* not found */
  46724. }
  46725. stream.pos += index;
  46726. return true; /* found */
  46727. }
  46728. var DocumentInfoValidators = {
  46729. get entries() {
  46730. // Lazily build this since all the validation functions below are not
  46731. // defined until after this file loads.
  46732. return shadow(this, 'entries', {
  46733. Title: isString,
  46734. Author: isString,
  46735. Subject: isString,
  46736. Keywords: isString,
  46737. Creator: isString,
  46738. Producer: isString,
  46739. CreationDate: isString,
  46740. ModDate: isString,
  46741. Trapped: isName
  46742. });
  46743. }
  46744. };
  46745. PDFDocument.prototype = {
  46746. parse: function PDFDocument_parse(recoveryMode) {
  46747. this.setup(recoveryMode);
  46748. var version = this.catalog.catDict.get('Version');
  46749. if (isName(version)) {
  46750. this.pdfFormatVersion = version.name;
  46751. }
  46752. try {
  46753. // checking if AcroForm is present
  46754. this.acroForm = this.catalog.catDict.get('AcroForm');
  46755. if (this.acroForm) {
  46756. this.xfa = this.acroForm.get('XFA');
  46757. var fields = this.acroForm.get('Fields');
  46758. if ((!fields || !isArray(fields) || fields.length === 0) &&
  46759. !this.xfa) {
  46760. // no fields and no XFA -- not a form (?)
  46761. this.acroForm = null;
  46762. }
  46763. }
  46764. } catch (ex) {
  46765. info('Something wrong with AcroForm entry');
  46766. this.acroForm = null;
  46767. }
  46768. },
  46769. get linearization() {
  46770. var linearization = null;
  46771. if (this.stream.length) {
  46772. try {
  46773. linearization = Linearization.create(this.stream);
  46774. } catch (err) {
  46775. if (err instanceof MissingDataException) {
  46776. throw err;
  46777. }
  46778. info(err);
  46779. }
  46780. }
  46781. // shadow the prototype getter with a data property
  46782. return shadow(this, 'linearization', linearization);
  46783. },
  46784. get startXRef() {
  46785. var stream = this.stream;
  46786. var startXRef = 0;
  46787. var linearization = this.linearization;
  46788. if (linearization) {
  46789. // Find end of first obj.
  46790. stream.reset();
  46791. if (find(stream, 'endobj', 1024)) {
  46792. startXRef = stream.pos + 6;
  46793. }
  46794. } else {
  46795. // Find startxref by jumping backward from the end of the file.
  46796. var step = 1024;
  46797. var found = false, pos = stream.end;
  46798. while (!found && pos > 0) {
  46799. pos -= step - 'startxref'.length;
  46800. if (pos < 0) {
  46801. pos = 0;
  46802. }
  46803. stream.pos = pos;
  46804. found = find(stream, 'startxref', step, true);
  46805. }
  46806. if (found) {
  46807. stream.skip(9);
  46808. var ch;
  46809. do {
  46810. ch = stream.getByte();
  46811. } while (isSpace(ch));
  46812. var str = '';
  46813. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  46814. str += String.fromCharCode(ch);
  46815. ch = stream.getByte();
  46816. }
  46817. startXRef = parseInt(str, 10);
  46818. if (isNaN(startXRef)) {
  46819. startXRef = 0;
  46820. }
  46821. }
  46822. }
  46823. // shadow the prototype getter with a data property
  46824. return shadow(this, 'startXRef', startXRef);
  46825. },
  46826. get mainXRefEntriesOffset() {
  46827. var mainXRefEntriesOffset = 0;
  46828. var linearization = this.linearization;
  46829. if (linearization) {
  46830. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  46831. }
  46832. // shadow the prototype getter with a data property
  46833. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  46834. },
  46835. // Find the header, remove leading garbage and setup the stream
  46836. // starting from the header.
  46837. checkHeader: function PDFDocument_checkHeader() {
  46838. var stream = this.stream;
  46839. stream.reset();
  46840. if (find(stream, '%PDF-', 1024)) {
  46841. // Found the header, trim off any garbage before it.
  46842. stream.moveStart();
  46843. // Reading file format version
  46844. var MAX_VERSION_LENGTH = 12;
  46845. var version = '', ch;
  46846. while ((ch = stream.getByte()) > 0x20) { // SPACE
  46847. if (version.length >= MAX_VERSION_LENGTH) {
  46848. break;
  46849. }
  46850. version += String.fromCharCode(ch);
  46851. }
  46852. if (!this.pdfFormatVersion) {
  46853. // removing "%PDF-"-prefix
  46854. this.pdfFormatVersion = version.substring(5);
  46855. }
  46856. return;
  46857. }
  46858. // May not be a PDF file, continue anyway.
  46859. },
  46860. parseStartXRef: function PDFDocument_parseStartXRef() {
  46861. var startXRef = this.startXRef;
  46862. this.xref.setStartXRef(startXRef);
  46863. },
  46864. setup: function PDFDocument_setup(recoveryMode) {
  46865. this.xref.parse(recoveryMode);
  46866. var self = this;
  46867. var pageFactory = {
  46868. createPage: function (pageIndex, dict, ref, fontCache) {
  46869. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  46870. fontCache);
  46871. }
  46872. };
  46873. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  46874. },
  46875. get numPages() {
  46876. var linearization = this.linearization;
  46877. var num = linearization ? linearization.numPages : this.catalog.numPages;
  46878. // shadow the prototype getter
  46879. return shadow(this, 'numPages', num);
  46880. },
  46881. get documentInfo() {
  46882. var docInfo = {
  46883. PDFFormatVersion: this.pdfFormatVersion,
  46884. IsAcroFormPresent: !!this.acroForm,
  46885. IsXFAPresent: !!this.xfa
  46886. };
  46887. var infoDict;
  46888. try {
  46889. infoDict = this.xref.trailer.get('Info');
  46890. } catch (err) {
  46891. info('The document information dictionary is invalid.');
  46892. }
  46893. if (infoDict) {
  46894. var validEntries = DocumentInfoValidators.entries;
  46895. // Only fill the document info with valid entries from the spec.
  46896. for (var key in validEntries) {
  46897. if (infoDict.has(key)) {
  46898. var value = infoDict.get(key);
  46899. // Make sure the value conforms to the spec.
  46900. if (validEntries[key](value)) {
  46901. docInfo[key] = (typeof value !== 'string' ?
  46902. value : stringToPDFString(value));
  46903. } else {
  46904. info('Bad value in document info for "' + key + '"');
  46905. }
  46906. }
  46907. }
  46908. }
  46909. return shadow(this, 'documentInfo', docInfo);
  46910. },
  46911. get fingerprint() {
  46912. var xref = this.xref, hash, fileID = '';
  46913. var idArray = xref.trailer.get('ID');
  46914. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  46915. idArray[0] !== EMPTY_FINGERPRINT) {
  46916. hash = stringToBytes(idArray[0]);
  46917. } else {
  46918. if (this.stream.ensureRange) {
  46919. this.stream.ensureRange(0,
  46920. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  46921. }
  46922. hash = calculateMD5(this.stream.bytes.subarray(0,
  46923. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  46924. }
  46925. for (var i = 0, n = hash.length; i < n; i++) {
  46926. var hex = hash[i].toString(16);
  46927. fileID += hex.length === 1 ? '0' + hex : hex;
  46928. }
  46929. return shadow(this, 'fingerprint', fileID);
  46930. },
  46931. getPage: function PDFDocument_getPage(pageIndex) {
  46932. return this.catalog.getPage(pageIndex);
  46933. },
  46934. cleanup: function PDFDocument_cleanup() {
  46935. return this.catalog.cleanup();
  46936. }
  46937. };
  46938. return PDFDocument;
  46939. })();
  46940. exports.Page = Page;
  46941. exports.PDFDocument = PDFDocument;
  46942. }));
  46943. (function (root, factory) {
  46944. {
  46945. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  46946. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  46947. root.pdfjsCoreDocument);
  46948. }
  46949. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  46950. coreDocument) {
  46951. var NotImplementedException = sharedUtil.NotImplementedException;
  46952. var MissingDataException = sharedUtil.MissingDataException;
  46953. var createPromiseCapability = sharedUtil.createPromiseCapability;
  46954. var Util = sharedUtil.Util;
  46955. var Stream = coreStream.Stream;
  46956. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  46957. var PDFDocument = coreDocument.PDFDocument;
  46958. var BasePdfManager = (function BasePdfManagerClosure() {
  46959. function BasePdfManager() {
  46960. throw new Error('Cannot initialize BaseManagerManager');
  46961. }
  46962. BasePdfManager.prototype = {
  46963. get docId() {
  46964. return this._docId;
  46965. },
  46966. onLoadedStream: function BasePdfManager_onLoadedStream() {
  46967. throw new NotImplementedException();
  46968. },
  46969. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  46970. return this.ensure(this.pdfDocument, prop, args);
  46971. },
  46972. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  46973. return this.ensure(this.pdfDocument.xref, prop, args);
  46974. },
  46975. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  46976. return this.ensure(this.pdfDocument.catalog, prop, args);
  46977. },
  46978. getPage: function BasePdfManager_getPage(pageIndex) {
  46979. return this.pdfDocument.getPage(pageIndex);
  46980. },
  46981. cleanup: function BasePdfManager_cleanup() {
  46982. return this.pdfDocument.cleanup();
  46983. },
  46984. ensure: function BasePdfManager_ensure(obj, prop, args) {
  46985. return new NotImplementedException();
  46986. },
  46987. requestRange: function BasePdfManager_requestRange(begin, end) {
  46988. return new NotImplementedException();
  46989. },
  46990. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  46991. return new NotImplementedException();
  46992. },
  46993. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  46994. return new NotImplementedException();
  46995. },
  46996. updatePassword: function BasePdfManager_updatePassword(password) {
  46997. this.pdfDocument.xref.password = this.password = password;
  46998. if (this._passwordChangedCapability) {
  46999. this._passwordChangedCapability.resolve();
  47000. }
  47001. },
  47002. passwordChanged: function BasePdfManager_passwordChanged() {
  47003. this._passwordChangedCapability = createPromiseCapability();
  47004. return this._passwordChangedCapability.promise;
  47005. },
  47006. terminate: function BasePdfManager_terminate() {
  47007. return new NotImplementedException();
  47008. }
  47009. };
  47010. return BasePdfManager;
  47011. })();
  47012. var LocalPdfManager = (function LocalPdfManagerClosure() {
  47013. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  47014. this._docId = docId;
  47015. this.evaluatorOptions = evaluatorOptions;
  47016. var stream = new Stream(data);
  47017. this.pdfDocument = new PDFDocument(this, stream, password);
  47018. this._loadedStreamCapability = createPromiseCapability();
  47019. this._loadedStreamCapability.resolve(stream);
  47020. }
  47021. Util.inherit(LocalPdfManager, BasePdfManager, {
  47022. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  47023. return new Promise(function (resolve, reject) {
  47024. try {
  47025. var value = obj[prop];
  47026. var result;
  47027. if (typeof value === 'function') {
  47028. result = value.apply(obj, args);
  47029. } else {
  47030. result = value;
  47031. }
  47032. resolve(result);
  47033. } catch (e) {
  47034. reject(e);
  47035. }
  47036. });
  47037. },
  47038. requestRange: function LocalPdfManager_requestRange(begin, end) {
  47039. return Promise.resolve();
  47040. },
  47041. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  47042. return;
  47043. },
  47044. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  47045. return this._loadedStreamCapability.promise;
  47046. },
  47047. terminate: function LocalPdfManager_terminate() {
  47048. return;
  47049. }
  47050. });
  47051. return LocalPdfManager;
  47052. })();
  47053. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  47054. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  47055. this._docId = docId;
  47056. this.msgHandler = args.msgHandler;
  47057. this.evaluatorOptions = evaluatorOptions;
  47058. var params = {
  47059. msgHandler: args.msgHandler,
  47060. url: args.url,
  47061. length: args.length,
  47062. disableAutoFetch: args.disableAutoFetch,
  47063. rangeChunkSize: args.rangeChunkSize
  47064. };
  47065. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  47066. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  47067. args.password);
  47068. }
  47069. Util.inherit(NetworkPdfManager, BasePdfManager, {
  47070. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  47071. var pdfManager = this;
  47072. return new Promise(function (resolve, reject) {
  47073. function ensureHelper() {
  47074. try {
  47075. var result;
  47076. var value = obj[prop];
  47077. if (typeof value === 'function') {
  47078. result = value.apply(obj, args);
  47079. } else {
  47080. result = value;
  47081. }
  47082. resolve(result);
  47083. } catch(e) {
  47084. if (!(e instanceof MissingDataException)) {
  47085. reject(e);
  47086. return;
  47087. }
  47088. pdfManager.streamManager.requestRange(e.begin, e.end).
  47089. then(ensureHelper, reject);
  47090. }
  47091. }
  47092. ensureHelper();
  47093. });
  47094. },
  47095. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  47096. return this.streamManager.requestRange(begin, end);
  47097. },
  47098. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  47099. this.streamManager.requestAllChunks();
  47100. },
  47101. sendProgressiveData:
  47102. function NetworkPdfManager_sendProgressiveData(chunk) {
  47103. this.streamManager.onReceiveData({ chunk: chunk });
  47104. },
  47105. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  47106. return this.streamManager.onLoadedStream();
  47107. },
  47108. terminate: function NetworkPdfManager_terminate() {
  47109. this.streamManager.abort();
  47110. }
  47111. });
  47112. return NetworkPdfManager;
  47113. })();
  47114. exports.LocalPdfManager = LocalPdfManager;
  47115. exports.NetworkPdfManager = NetworkPdfManager;
  47116. }));
  47117. (function (root, factory) {
  47118. {
  47119. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  47120. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  47121. }
  47122. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  47123. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47124. var InvalidPDFException = sharedUtil.InvalidPDFException;
  47125. var MessageHandler = sharedUtil.MessageHandler;
  47126. var MissingPDFException = sharedUtil.MissingPDFException;
  47127. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  47128. var PasswordException = sharedUtil.PasswordException;
  47129. var PasswordResponses = sharedUtil.PasswordResponses;
  47130. var UnknownErrorException = sharedUtil.UnknownErrorException;
  47131. var XRefParseException = sharedUtil.XRefParseException;
  47132. var arrayByteLength = sharedUtil.arrayByteLength;
  47133. var arraysToBytes = sharedUtil.arraysToBytes;
  47134. var assert = sharedUtil.assert;
  47135. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47136. var error = sharedUtil.error;
  47137. var info = sharedUtil.info;
  47138. var warn = sharedUtil.warn;
  47139. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  47140. var Ref = corePrimitives.Ref;
  47141. var LocalPdfManager = corePdfManager.LocalPdfManager;
  47142. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  47143. var globalScope = sharedUtil.globalScope;
  47144. var WorkerTask = (function WorkerTaskClosure() {
  47145. function WorkerTask(name) {
  47146. this.name = name;
  47147. this.terminated = false;
  47148. this._capability = createPromiseCapability();
  47149. }
  47150. WorkerTask.prototype = {
  47151. get finished() {
  47152. return this._capability.promise;
  47153. },
  47154. finish: function () {
  47155. this._capability.resolve();
  47156. },
  47157. terminate: function () {
  47158. this.terminated = true;
  47159. },
  47160. ensureNotTerminated: function () {
  47161. if (this.terminated) {
  47162. throw new Error('Worker task was terminated');
  47163. }
  47164. }
  47165. };
  47166. return WorkerTask;
  47167. })();
  47168. /** @implements {IPDFStream} */
  47169. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  47170. function PDFWorkerStream(params, msgHandler) {
  47171. this._queuedChunks = [];
  47172. var initialData = params.initialData;
  47173. if (initialData && initialData.length > 0) {
  47174. this._queuedChunks.push(initialData);
  47175. }
  47176. this._msgHandler = msgHandler;
  47177. this._isRangeSupported = !(params.disableRange);
  47178. this._isStreamingSupported = !(params.disableStream);
  47179. this._contentLength = params.length;
  47180. this._fullRequestReader = null;
  47181. this._rangeReaders = [];
  47182. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  47183. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  47184. }
  47185. PDFWorkerStream.prototype = {
  47186. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  47187. if (args.begin === undefined) {
  47188. if (this._fullRequestReader) {
  47189. this._fullRequestReader._enqueue(args.chunk);
  47190. } else {
  47191. this._queuedChunks.push(args.chunk);
  47192. }
  47193. } else {
  47194. var found = this._rangeReaders.some(function (rangeReader) {
  47195. if (rangeReader._begin !== args.begin) {
  47196. return false;
  47197. }
  47198. rangeReader._enqueue(args.chunk);
  47199. return true;
  47200. });
  47201. assert(found);
  47202. }
  47203. },
  47204. _onProgress: function PDFWorkerStream_onProgress(evt) {
  47205. if (this._rangeReaders.length > 0) {
  47206. // Reporting to first range reader.
  47207. var firstReader = this._rangeReaders[0];
  47208. if (firstReader.onProgress) {
  47209. firstReader.onProgress({loaded: evt.loaded});
  47210. }
  47211. }
  47212. },
  47213. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  47214. var i = this._rangeReaders.indexOf(reader);
  47215. if (i >= 0) {
  47216. this._rangeReaders.splice(i, 1);
  47217. }
  47218. },
  47219. getFullReader: function PDFWorkerStream_getFullReader() {
  47220. assert(!this._fullRequestReader);
  47221. var queuedChunks = this._queuedChunks;
  47222. this._queuedChunks = null;
  47223. return new PDFWorkerStreamReader(this, queuedChunks);
  47224. },
  47225. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  47226. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  47227. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  47228. this._rangeReaders.push(reader);
  47229. return reader;
  47230. },
  47231. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  47232. if (this._fullRequestReader) {
  47233. this._fullRequestReader.cancel(reason);
  47234. }
  47235. var readers = this._rangeReaders.slice(0);
  47236. readers.forEach(function (rangeReader) {
  47237. rangeReader.cancel(reason);
  47238. });
  47239. }
  47240. };
  47241. /** @implements {IPDFStreamReader} */
  47242. function PDFWorkerStreamReader(stream, queuedChunks) {
  47243. this._stream = stream;
  47244. this._done = false;
  47245. this._queuedChunks = queuedChunks || [];
  47246. this._requests = [];
  47247. this._headersReady = Promise.resolve();
  47248. stream._fullRequestReader = this;
  47249. this.onProgress = null; // not used
  47250. }
  47251. PDFWorkerStreamReader.prototype = {
  47252. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  47253. if (this._done) {
  47254. return; // ignore new data
  47255. }
  47256. if (this._requests.length > 0) {
  47257. var requestCapability = this._requests.shift();
  47258. requestCapability.resolve({value: chunk, done: false});
  47259. return;
  47260. }
  47261. this._queuedChunks.push(chunk);
  47262. },
  47263. get headersReady() {
  47264. return this._headersReady;
  47265. },
  47266. get isRangeSupported() {
  47267. return this._stream._isRangeSupported;
  47268. },
  47269. get isStreamingSupported() {
  47270. return this._stream._isStreamingSupported;
  47271. },
  47272. get contentLength() {
  47273. return this._stream._contentLength;
  47274. },
  47275. read: function PDFWorkerStreamReader_read() {
  47276. if (this._queuedChunks.length > 0) {
  47277. var chunk = this._queuedChunks.shift();
  47278. return Promise.resolve({value: chunk, done: false});
  47279. }
  47280. if (this._done) {
  47281. return Promise.resolve({value: undefined, done: true});
  47282. }
  47283. var requestCapability = createPromiseCapability();
  47284. this._requests.push(requestCapability);
  47285. return requestCapability.promise;
  47286. },
  47287. cancel: function PDFWorkerStreamReader_cancel(reason) {
  47288. this._done = true;
  47289. this._requests.forEach(function (requestCapability) {
  47290. requestCapability.resolve({value: undefined, done: true});
  47291. });
  47292. this._requests = [];
  47293. }
  47294. };
  47295. /** @implements {IPDFStreamRangeReader} */
  47296. function PDFWorkerStreamRangeReader(stream, begin, end) {
  47297. this._stream = stream;
  47298. this._begin = begin;
  47299. this._end = end;
  47300. this._queuedChunk = null;
  47301. this._requests = [];
  47302. this._done = false;
  47303. this.onProgress = null;
  47304. }
  47305. PDFWorkerStreamRangeReader.prototype = {
  47306. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  47307. if (this._done) {
  47308. return; // ignore new data
  47309. }
  47310. if (this._requests.length === 0) {
  47311. this._queuedChunk = chunk;
  47312. } else {
  47313. var requestsCapability = this._requests.shift();
  47314. requestsCapability.resolve({value: chunk, done: false});
  47315. this._requests.forEach(function (requestCapability) {
  47316. requestCapability.resolve({value: undefined, done: true});
  47317. });
  47318. this._requests = [];
  47319. }
  47320. this._done = true;
  47321. this._stream._removeRangeReader(this);
  47322. },
  47323. get isStreamingSupported() {
  47324. return false;
  47325. },
  47326. read: function PDFWorkerStreamRangeReader_read() {
  47327. if (this._queuedChunk) {
  47328. return Promise.resolve({value: this._queuedChunk, done: false});
  47329. }
  47330. if (this._done) {
  47331. return Promise.resolve({value: undefined, done: true});
  47332. }
  47333. var requestCapability = createPromiseCapability();
  47334. this._requests.push(requestCapability);
  47335. return requestCapability.promise;
  47336. },
  47337. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  47338. this._done = true;
  47339. this._requests.forEach(function (requestCapability) {
  47340. requestCapability.resolve({value: undefined, done: true});
  47341. });
  47342. this._requests = [];
  47343. this._stream._removeRangeReader(this);
  47344. }
  47345. };
  47346. return PDFWorkerStream;
  47347. })();
  47348. /** @type IPDFStream */
  47349. var PDFNetworkStream;
  47350. /**
  47351. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  47352. * @param {IPDFStream} cls - the PDF data transport.
  47353. */
  47354. function setPDFNetworkStreamClass(cls) {
  47355. PDFNetworkStream = cls;
  47356. }
  47357. var WorkerMessageHandler = {
  47358. setup: function wphSetup(handler, port) {
  47359. var testMessageProcessed = false;
  47360. handler.on('test', function wphSetupTest(data) {
  47361. if (testMessageProcessed) {
  47362. return; // we already processed 'test' message once
  47363. }
  47364. testMessageProcessed = true;
  47365. // check if Uint8Array can be sent to worker
  47366. if (!(data instanceof Uint8Array)) {
  47367. handler.send('test', 'main', false);
  47368. return;
  47369. }
  47370. // making sure postMessage transfers are working
  47371. var supportTransfers = data[0] === 255;
  47372. handler.postMessageTransfers = supportTransfers;
  47373. // check if the response property is supported by xhr
  47374. var xhr = new XMLHttpRequest();
  47375. var responseExists = 'response' in xhr;
  47376. // check if the property is actually implemented
  47377. try {
  47378. var dummy = xhr.responseType;
  47379. } catch (e) {
  47380. responseExists = false;
  47381. }
  47382. if (!responseExists) {
  47383. handler.send('test', false);
  47384. return;
  47385. }
  47386. handler.send('test', {
  47387. supportTypedArray: true,
  47388. supportTransfers: supportTransfers
  47389. });
  47390. });
  47391. handler.on('configure', function wphConfigure(data) {
  47392. setVerbosityLevel(data.verbosity);
  47393. });
  47394. handler.on('GetDocRequest', function wphSetupDoc(data) {
  47395. return WorkerMessageHandler.createDocumentHandler(data, port);
  47396. });
  47397. },
  47398. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  47399. // This context is actually holds references on pdfManager and handler,
  47400. // until the latter is destroyed.
  47401. var pdfManager;
  47402. var terminated = false;
  47403. var cancelXHRs = null;
  47404. var WorkerTasks = [];
  47405. var docId = docParams.docId;
  47406. var workerHandlerName = docParams.docId + '_worker';
  47407. var handler = new MessageHandler(workerHandlerName, docId, port);
  47408. // Ensure that postMessage transfers are correctly enabled/disabled,
  47409. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  47410. handler.postMessageTransfers = docParams.postMessageTransfers;
  47411. function ensureNotTerminated() {
  47412. if (terminated) {
  47413. throw new Error('Worker was terminated');
  47414. }
  47415. }
  47416. function startWorkerTask(task) {
  47417. WorkerTasks.push(task);
  47418. }
  47419. function finishWorkerTask(task) {
  47420. task.finish();
  47421. var i = WorkerTasks.indexOf(task);
  47422. WorkerTasks.splice(i, 1);
  47423. }
  47424. function loadDocument(recoveryMode) {
  47425. var loadDocumentCapability = createPromiseCapability();
  47426. var parseSuccess = function parseSuccess() {
  47427. var numPagesPromise = pdfManager.ensureDoc('numPages');
  47428. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  47429. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  47430. Promise.all([numPagesPromise, fingerprintPromise,
  47431. encryptedPromise]).then(function onDocReady(results) {
  47432. var doc = {
  47433. numPages: results[0],
  47434. fingerprint: results[1],
  47435. encrypted: !!results[2],
  47436. };
  47437. loadDocumentCapability.resolve(doc);
  47438. },
  47439. parseFailure);
  47440. };
  47441. var parseFailure = function parseFailure(e) {
  47442. loadDocumentCapability.reject(e);
  47443. };
  47444. pdfManager.ensureDoc('checkHeader', []).then(function() {
  47445. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  47446. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  47447. parseSuccess, parseFailure);
  47448. }, parseFailure);
  47449. }, parseFailure);
  47450. return loadDocumentCapability.promise;
  47451. }
  47452. function getPdfManager(data, evaluatorOptions) {
  47453. var pdfManagerCapability = createPromiseCapability();
  47454. var pdfManager;
  47455. var source = data.source;
  47456. if (source.data) {
  47457. try {
  47458. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  47459. evaluatorOptions);
  47460. pdfManagerCapability.resolve(pdfManager);
  47461. } catch (ex) {
  47462. pdfManagerCapability.reject(ex);
  47463. }
  47464. return pdfManagerCapability.promise;
  47465. }
  47466. var pdfStream;
  47467. try {
  47468. if (source.chunkedViewerLoading) {
  47469. pdfStream = new PDFWorkerStream(source, handler);
  47470. } else {
  47471. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  47472. pdfStream = new PDFNetworkStream(data);
  47473. }
  47474. } catch (ex) {
  47475. pdfManagerCapability.reject(ex);
  47476. return pdfManagerCapability.promise;
  47477. }
  47478. var fullRequest = pdfStream.getFullReader();
  47479. fullRequest.headersReady.then(function () {
  47480. if (!fullRequest.isStreamingSupported ||
  47481. !fullRequest.isRangeSupported) {
  47482. // If stream or range are disabled, it's our only way to report
  47483. // loading progress.
  47484. fullRequest.onProgress = function (evt) {
  47485. handler.send('DocProgress', {
  47486. loaded: evt.loaded,
  47487. total: evt.total
  47488. });
  47489. };
  47490. }
  47491. if (!fullRequest.isRangeSupported) {
  47492. return;
  47493. }
  47494. // We don't need auto-fetch when streaming is enabled.
  47495. var disableAutoFetch = source.disableAutoFetch ||
  47496. fullRequest.isStreamingSupported;
  47497. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  47498. msgHandler: handler,
  47499. url: source.url,
  47500. password: source.password,
  47501. length: fullRequest.contentLength,
  47502. disableAutoFetch: disableAutoFetch,
  47503. rangeChunkSize: source.rangeChunkSize
  47504. }, evaluatorOptions);
  47505. pdfManagerCapability.resolve(pdfManager);
  47506. cancelXHRs = null;
  47507. }).catch(function (reason) {
  47508. pdfManagerCapability.reject(reason);
  47509. cancelXHRs = null;
  47510. });
  47511. var cachedChunks = [], loaded = 0;
  47512. var flushChunks = function () {
  47513. var pdfFile = arraysToBytes(cachedChunks);
  47514. if (source.length && pdfFile.length !== source.length) {
  47515. warn('reported HTTP length is different from actual');
  47516. }
  47517. // the data is array, instantiating directly from it
  47518. try {
  47519. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  47520. evaluatorOptions);
  47521. pdfManagerCapability.resolve(pdfManager);
  47522. } catch (ex) {
  47523. pdfManagerCapability.reject(ex);
  47524. }
  47525. cachedChunks = [];
  47526. };
  47527. var readPromise = new Promise(function (resolve, reject) {
  47528. var readChunk = function (chunk) {
  47529. try {
  47530. ensureNotTerminated();
  47531. if (chunk.done) {
  47532. if (!pdfManager) {
  47533. flushChunks();
  47534. }
  47535. cancelXHRs = null;
  47536. return;
  47537. }
  47538. var data = chunk.value;
  47539. loaded += arrayByteLength(data);
  47540. if (!fullRequest.isStreamingSupported) {
  47541. handler.send('DocProgress', {
  47542. loaded: loaded,
  47543. total: Math.max(loaded, fullRequest.contentLength || 0)
  47544. });
  47545. }
  47546. if (pdfManager) {
  47547. pdfManager.sendProgressiveData(data);
  47548. } else {
  47549. cachedChunks.push(data);
  47550. }
  47551. fullRequest.read().then(readChunk, reject);
  47552. } catch (e) {
  47553. reject(e);
  47554. }
  47555. };
  47556. fullRequest.read().then(readChunk, reject);
  47557. });
  47558. readPromise.catch(function (e) {
  47559. pdfManagerCapability.reject(e);
  47560. cancelXHRs = null;
  47561. });
  47562. cancelXHRs = function () {
  47563. pdfStream.cancelAllRequests('abort');
  47564. };
  47565. return pdfManagerCapability.promise;
  47566. }
  47567. var setupDoc = function(data) {
  47568. var onSuccess = function(doc) {
  47569. ensureNotTerminated();
  47570. handler.send('GetDoc', { pdfInfo: doc });
  47571. };
  47572. var onFailure = function(e) {
  47573. if (e instanceof PasswordException) {
  47574. if (e.code === PasswordResponses.NEED_PASSWORD) {
  47575. handler.send('NeedPassword', e);
  47576. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  47577. handler.send('IncorrectPassword', e);
  47578. }
  47579. } else if (e instanceof InvalidPDFException) {
  47580. handler.send('InvalidPDF', e);
  47581. } else if (e instanceof MissingPDFException) {
  47582. handler.send('MissingPDF', e);
  47583. } else if (e instanceof UnexpectedResponseException) {
  47584. handler.send('UnexpectedResponse', e);
  47585. } else {
  47586. handler.send('UnknownError',
  47587. new UnknownErrorException(e.message, e.toString()));
  47588. }
  47589. };
  47590. ensureNotTerminated();
  47591. var cMapOptions = {
  47592. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  47593. packed: data.cMapPacked === true
  47594. };
  47595. var evaluatorOptions = {
  47596. forceDataSchema: data.disableCreateObjectURL,
  47597. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  47598. disableFontFace: data.disableFontFace,
  47599. cMapOptions: cMapOptions
  47600. };
  47601. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  47602. if (terminated) {
  47603. // We were in a process of setting up the manager, but it got
  47604. // terminated in the middle.
  47605. newPdfManager.terminate();
  47606. throw new Error('Worker was terminated');
  47607. }
  47608. pdfManager = newPdfManager;
  47609. handler.send('PDFManagerReady', null);
  47610. pdfManager.onLoadedStream().then(function(stream) {
  47611. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  47612. });
  47613. }).then(function pdfManagerReady() {
  47614. ensureNotTerminated();
  47615. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  47616. ensureNotTerminated();
  47617. // Try again with recoveryMode == true
  47618. if (!(ex instanceof XRefParseException)) {
  47619. if (ex instanceof PasswordException) {
  47620. // after password exception prepare to receive a new password
  47621. // to repeat loading
  47622. pdfManager.passwordChanged().then(pdfManagerReady);
  47623. }
  47624. onFailure(ex);
  47625. return;
  47626. }
  47627. pdfManager.requestLoadedStream();
  47628. pdfManager.onLoadedStream().then(function() {
  47629. ensureNotTerminated();
  47630. loadDocument(true).then(onSuccess, onFailure);
  47631. });
  47632. }, onFailure);
  47633. }, onFailure);
  47634. };
  47635. handler.on('GetPage', function wphSetupGetPage(data) {
  47636. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47637. var rotatePromise = pdfManager.ensure(page, 'rotate');
  47638. var refPromise = pdfManager.ensure(page, 'ref');
  47639. var viewPromise = pdfManager.ensure(page, 'view');
  47640. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  47641. function(results) {
  47642. return {
  47643. rotate: results[0],
  47644. ref: results[1],
  47645. view: results[2]
  47646. };
  47647. });
  47648. });
  47649. });
  47650. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  47651. var ref = new Ref(data.ref.num, data.ref.gen);
  47652. var catalog = pdfManager.pdfDocument.catalog;
  47653. return catalog.getPageIndex(ref);
  47654. });
  47655. handler.on('GetDestinations',
  47656. function wphSetupGetDestinations(data) {
  47657. return pdfManager.ensureCatalog('destinations');
  47658. }
  47659. );
  47660. handler.on('GetDestination',
  47661. function wphSetupGetDestination(data) {
  47662. return pdfManager.ensureCatalog('getDestination', [data.id]);
  47663. }
  47664. );
  47665. handler.on('GetPageLabels',
  47666. function wphSetupGetPageLabels(data) {
  47667. return pdfManager.ensureCatalog('pageLabels');
  47668. }
  47669. );
  47670. handler.on('GetAttachments',
  47671. function wphSetupGetAttachments(data) {
  47672. return pdfManager.ensureCatalog('attachments');
  47673. }
  47674. );
  47675. handler.on('GetJavaScript',
  47676. function wphSetupGetJavaScript(data) {
  47677. return pdfManager.ensureCatalog('javaScript');
  47678. }
  47679. );
  47680. handler.on('GetOutline',
  47681. function wphSetupGetOutline(data) {
  47682. return pdfManager.ensureCatalog('documentOutline');
  47683. }
  47684. );
  47685. handler.on('GetMetadata',
  47686. function wphSetupGetMetadata(data) {
  47687. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  47688. pdfManager.ensureCatalog('metadata')]);
  47689. }
  47690. );
  47691. handler.on('GetData', function wphSetupGetData(data) {
  47692. pdfManager.requestLoadedStream();
  47693. return pdfManager.onLoadedStream().then(function(stream) {
  47694. return stream.bytes;
  47695. });
  47696. });
  47697. handler.on('GetStats',
  47698. function wphSetupGetStats(data) {
  47699. return pdfManager.pdfDocument.xref.stats;
  47700. }
  47701. );
  47702. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  47703. pdfManager.updatePassword(data);
  47704. });
  47705. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  47706. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47707. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  47708. });
  47709. });
  47710. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  47711. var pageIndex = data.pageIndex;
  47712. pdfManager.getPage(pageIndex).then(function(page) {
  47713. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  47714. startWorkerTask(task);
  47715. var pageNum = pageIndex + 1;
  47716. var start = Date.now();
  47717. // Pre compile the pdf page and fetch the fonts/images.
  47718. page.getOperatorList(handler, task, data.intent).then(
  47719. function(operatorList) {
  47720. finishWorkerTask(task);
  47721. info('page=' + pageNum + ' - getOperatorList: time=' +
  47722. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  47723. }, function(e) {
  47724. finishWorkerTask(task);
  47725. if (task.terminated) {
  47726. return; // ignoring errors from the terminated thread
  47727. }
  47728. // For compatibility with older behavior, generating unknown
  47729. // unsupported feature notification on errors.
  47730. handler.send('UnsupportedFeature',
  47731. {featureId: UNSUPPORTED_FEATURES.unknown});
  47732. var minimumStackMessage =
  47733. 'worker.js: while trying to getPage() and getOperatorList()';
  47734. var wrappedException;
  47735. // Turn the error into an obj that can be serialized
  47736. if (typeof e === 'string') {
  47737. wrappedException = {
  47738. message: e,
  47739. stack: minimumStackMessage
  47740. };
  47741. } else if (typeof e === 'object') {
  47742. wrappedException = {
  47743. message: e.message || e.toString(),
  47744. stack: e.stack || minimumStackMessage
  47745. };
  47746. } else {
  47747. wrappedException = {
  47748. message: 'Unknown exception type: ' + (typeof e),
  47749. stack: minimumStackMessage
  47750. };
  47751. }
  47752. handler.send('PageError', {
  47753. pageNum: pageNum,
  47754. error: wrappedException,
  47755. intent: data.intent
  47756. });
  47757. });
  47758. });
  47759. }, this);
  47760. handler.on('GetTextContent', function wphExtractText(data) {
  47761. var pageIndex = data.pageIndex;
  47762. var normalizeWhitespace = data.normalizeWhitespace;
  47763. var combineTextItems = data.combineTextItems;
  47764. return pdfManager.getPage(pageIndex).then(function(page) {
  47765. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  47766. startWorkerTask(task);
  47767. var pageNum = pageIndex + 1;
  47768. var start = Date.now();
  47769. return page.extractTextContent(task, normalizeWhitespace,
  47770. combineTextItems).then(
  47771. function(textContent) {
  47772. finishWorkerTask(task);
  47773. info('text indexing: page=' + pageNum + ' - time=' +
  47774. (Date.now() - start) + 'ms');
  47775. return textContent;
  47776. }, function (reason) {
  47777. finishWorkerTask(task);
  47778. if (task.terminated) {
  47779. return; // ignoring errors from the terminated thread
  47780. }
  47781. throw reason;
  47782. });
  47783. });
  47784. });
  47785. handler.on('Cleanup', function wphCleanup(data) {
  47786. return pdfManager.cleanup();
  47787. });
  47788. handler.on('Terminate', function wphTerminate(data) {
  47789. terminated = true;
  47790. if (pdfManager) {
  47791. pdfManager.terminate();
  47792. pdfManager = null;
  47793. }
  47794. if (cancelXHRs) {
  47795. cancelXHRs();
  47796. }
  47797. var waitOn = [];
  47798. WorkerTasks.forEach(function (task) {
  47799. waitOn.push(task.finished);
  47800. task.terminate();
  47801. });
  47802. return Promise.all(waitOn).then(function () {
  47803. // Notice that even if we destroying handler, resolved response promise
  47804. // must be sent back.
  47805. handler.destroy();
  47806. handler = null;
  47807. });
  47808. });
  47809. handler.on('Ready', function wphReady(data) {
  47810. setupDoc(docParams);
  47811. docParams = null; // we don't need docParams anymore -- saving memory.
  47812. });
  47813. return workerHandlerName;
  47814. }
  47815. };
  47816. function initializeWorker() {
  47817. if (!('console' in globalScope)) {
  47818. var consoleTimer = {};
  47819. var workerConsole = {
  47820. log: function log() {
  47821. var args = Array.prototype.slice.call(arguments);
  47822. globalScope.postMessage({
  47823. targetName: 'main',
  47824. action: 'console_log',
  47825. data: args
  47826. });
  47827. },
  47828. error: function error() {
  47829. var args = Array.prototype.slice.call(arguments);
  47830. globalScope.postMessage({
  47831. targetName: 'main',
  47832. action: 'console_error',
  47833. data: args
  47834. });
  47835. throw 'pdf.js execution error';
  47836. },
  47837. time: function time(name) {
  47838. consoleTimer[name] = Date.now();
  47839. },
  47840. timeEnd: function timeEnd(name) {
  47841. var time = consoleTimer[name];
  47842. if (!time) {
  47843. error('Unknown timer name ' + name);
  47844. }
  47845. this.log('Timer:', name, Date.now() - time);
  47846. }
  47847. };
  47848. globalScope.console = workerConsole;
  47849. }
  47850. var handler = new MessageHandler('worker', 'main', self);
  47851. WorkerMessageHandler.setup(handler, self);
  47852. handler.send('ready', null);
  47853. }
  47854. // Worker thread (and not node.js)?
  47855. if (typeof window === 'undefined' &&
  47856. !(typeof module !== 'undefined' && module.require)) {
  47857. initializeWorker();
  47858. }
  47859. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  47860. exports.WorkerTask = WorkerTask;
  47861. exports.WorkerMessageHandler = WorkerMessageHandler;
  47862. }));
  47863. var NetworkManager = (function NetworkManagerClosure() {
  47864. var OK_RESPONSE = 200;
  47865. var PARTIAL_CONTENT_RESPONSE = 206;
  47866. function NetworkManager(url, args) {
  47867. this.url = url;
  47868. args = args || {};
  47869. this.isHttp = /^https?:/i.test(url);
  47870. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  47871. this.withCredentials = args.withCredentials || false;
  47872. this.getXhr = args.getXhr ||
  47873. function NetworkManager_getXhr() {
  47874. return new XMLHttpRequest();
  47875. };
  47876. this.currXhrId = 0;
  47877. this.pendingRequests = Object.create(null);
  47878. this.loadedRequests = Object.create(null);
  47879. }
  47880. function getArrayBuffer(xhr) {
  47881. var data = xhr.response;
  47882. if (typeof data !== 'string') {
  47883. return data;
  47884. }
  47885. var length = data.length;
  47886. var array = new Uint8Array(length);
  47887. for (var i = 0; i < length; i++) {
  47888. array[i] = data.charCodeAt(i) & 0xFF;
  47889. }
  47890. return array.buffer;
  47891. }
  47892. var supportsMozChunked = (function supportsMozChunkedClosure() {
  47893. try {
  47894. var x = new XMLHttpRequest();
  47895. // Firefox 37- required .open() to be called before setting responseType.
  47896. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  47897. // Even though the URL is not visited, .open() could fail if the URL is
  47898. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  47899. // When this error occurs, this feature detection method will mistakenly
  47900. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  47901. x.open('GET', 'https://example.com');
  47902. x.responseType = 'moz-chunked-arraybuffer';
  47903. return x.responseType === 'moz-chunked-arraybuffer';
  47904. } catch (e) {
  47905. return false;
  47906. }
  47907. })();
  47908. NetworkManager.prototype = {
  47909. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  47910. var args = {
  47911. begin: begin,
  47912. end: end
  47913. };
  47914. for (var prop in listeners) {
  47915. args[prop] = listeners[prop];
  47916. }
  47917. return this.request(args);
  47918. },
  47919. requestFull: function NetworkManager_requestFull(listeners) {
  47920. return this.request(listeners);
  47921. },
  47922. request: function NetworkManager_request(args) {
  47923. var xhr = this.getXhr();
  47924. var xhrId = this.currXhrId++;
  47925. var pendingRequest = this.pendingRequests[xhrId] = {
  47926. xhr: xhr
  47927. };
  47928. xhr.open('GET', this.url);
  47929. xhr.withCredentials = this.withCredentials;
  47930. for (var property in this.httpHeaders) {
  47931. var value = this.httpHeaders[property];
  47932. if (typeof value === 'undefined') {
  47933. continue;
  47934. }
  47935. xhr.setRequestHeader(property, value);
  47936. }
  47937. if (this.isHttp && 'begin' in args && 'end' in args) {
  47938. var rangeStr = args.begin + '-' + (args.end - 1);
  47939. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  47940. pendingRequest.expectedStatus = 206;
  47941. } else {
  47942. pendingRequest.expectedStatus = 200;
  47943. }
  47944. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  47945. if (useMozChunkedLoading) {
  47946. xhr.responseType = 'moz-chunked-arraybuffer';
  47947. pendingRequest.onProgressiveData = args.onProgressiveData;
  47948. pendingRequest.mozChunked = true;
  47949. } else {
  47950. xhr.responseType = 'arraybuffer';
  47951. }
  47952. if (args.onError) {
  47953. xhr.onerror = function(evt) {
  47954. args.onError(xhr.status);
  47955. };
  47956. }
  47957. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  47958. xhr.onprogress = this.onProgress.bind(this, xhrId);
  47959. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  47960. pendingRequest.onDone = args.onDone;
  47961. pendingRequest.onError = args.onError;
  47962. pendingRequest.onProgress = args.onProgress;
  47963. xhr.send(null);
  47964. return xhrId;
  47965. },
  47966. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  47967. var pendingRequest = this.pendingRequests[xhrId];
  47968. if (!pendingRequest) {
  47969. // Maybe abortRequest was called...
  47970. return;
  47971. }
  47972. if (pendingRequest.mozChunked) {
  47973. var chunk = getArrayBuffer(pendingRequest.xhr);
  47974. pendingRequest.onProgressiveData(chunk);
  47975. }
  47976. var onProgress = pendingRequest.onProgress;
  47977. if (onProgress) {
  47978. onProgress(evt);
  47979. }
  47980. },
  47981. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  47982. var pendingRequest = this.pendingRequests[xhrId];
  47983. if (!pendingRequest) {
  47984. // Maybe abortRequest was called...
  47985. return;
  47986. }
  47987. var xhr = pendingRequest.xhr;
  47988. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  47989. pendingRequest.onHeadersReceived();
  47990. delete pendingRequest.onHeadersReceived;
  47991. }
  47992. if (xhr.readyState !== 4) {
  47993. return;
  47994. }
  47995. if (!(xhrId in this.pendingRequests)) {
  47996. // The XHR request might have been aborted in onHeadersReceived()
  47997. // callback, in which case we should abort request
  47998. return;
  47999. }
  48000. delete this.pendingRequests[xhrId];
  48001. // success status == 0 can be on ftp, file and other protocols
  48002. if (xhr.status === 0 && this.isHttp) {
  48003. if (pendingRequest.onError) {
  48004. pendingRequest.onError(xhr.status);
  48005. }
  48006. return;
  48007. }
  48008. var xhrStatus = xhr.status || OK_RESPONSE;
  48009. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  48010. // "A server MAY ignore the Range header". This means it's possible to
  48011. // get a 200 rather than a 206 response from a range request.
  48012. var ok_response_on_range_request =
  48013. xhrStatus === OK_RESPONSE &&
  48014. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  48015. if (!ok_response_on_range_request &&
  48016. xhrStatus !== pendingRequest.expectedStatus) {
  48017. if (pendingRequest.onError) {
  48018. pendingRequest.onError(xhr.status);
  48019. }
  48020. return;
  48021. }
  48022. this.loadedRequests[xhrId] = true;
  48023. var chunk = getArrayBuffer(xhr);
  48024. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  48025. var rangeHeader = xhr.getResponseHeader('Content-Range');
  48026. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  48027. var begin = parseInt(matches[1], 10);
  48028. pendingRequest.onDone({
  48029. begin: begin,
  48030. chunk: chunk
  48031. });
  48032. } else if (pendingRequest.onProgressiveData) {
  48033. pendingRequest.onDone(null);
  48034. } else if (chunk) {
  48035. pendingRequest.onDone({
  48036. begin: 0,
  48037. chunk: chunk
  48038. });
  48039. } else if (pendingRequest.onError) {
  48040. pendingRequest.onError(xhr.status);
  48041. }
  48042. },
  48043. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  48044. for (var xhrId in this.pendingRequests) {
  48045. return true;
  48046. }
  48047. return false;
  48048. },
  48049. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  48050. return this.pendingRequests[xhrId].xhr;
  48051. },
  48052. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  48053. return !!(this.pendingRequests[xhrId].onProgressiveData);
  48054. },
  48055. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  48056. return xhrId in this.pendingRequests;
  48057. },
  48058. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  48059. return xhrId in this.loadedRequests;
  48060. },
  48061. abortAllRequests: function NetworkManager_abortAllRequests() {
  48062. for (var xhrId in this.pendingRequests) {
  48063. this.abortRequest(xhrId | 0);
  48064. }
  48065. },
  48066. abortRequest: function NetworkManager_abortRequest(xhrId) {
  48067. var xhr = this.pendingRequests[xhrId].xhr;
  48068. delete this.pendingRequests[xhrId];
  48069. xhr.abort();
  48070. }
  48071. };
  48072. return NetworkManager;
  48073. })();
  48074. (function (root, factory) {
  48075. {
  48076. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  48077. root.pdfjsCoreWorker);
  48078. }
  48079. }(this, function (exports, sharedUtil, coreWorker) {
  48080. var assert = sharedUtil.assert;
  48081. var createPromiseCapability = sharedUtil.createPromiseCapability;
  48082. var isInt = sharedUtil.isInt;
  48083. var MissingPDFException = sharedUtil.MissingPDFException;
  48084. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  48085. /** @implements {IPDFStream} */
  48086. function PDFNetworkStream(options) {
  48087. this._options = options;
  48088. var source = options.source;
  48089. this._manager = new NetworkManager(source.url, {
  48090. httpHeaders: source.httpHeaders,
  48091. withCredentials: source.withCredentials
  48092. });
  48093. this._rangeChunkSize = source.rangeChunkSize;
  48094. this._fullRequestReader = null;
  48095. this._rangeRequestReaders = [];
  48096. }
  48097. PDFNetworkStream.prototype = {
  48098. _onRangeRequestReaderClosed:
  48099. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  48100. var i = this._rangeRequestReaders.indexOf(reader);
  48101. if (i >= 0) {
  48102. this._rangeRequestReaders.splice(i, 1);
  48103. }
  48104. },
  48105. getFullReader: function PDFNetworkStream_getFullReader() {
  48106. assert(!this._fullRequestReader);
  48107. this._fullRequestReader =
  48108. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  48109. return this._fullRequestReader;
  48110. },
  48111. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  48112. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  48113. begin, end);
  48114. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  48115. this._rangeRequestReaders.push(reader);
  48116. return reader;
  48117. },
  48118. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  48119. if (this._fullRequestReader) {
  48120. this._fullRequestReader.cancel(reason);
  48121. }
  48122. var readers = this._rangeRequestReaders.slice(0);
  48123. readers.forEach(function (reader) {
  48124. reader.cancel(reason);
  48125. });
  48126. }
  48127. };
  48128. /** @implements {IPDFStreamReader} */
  48129. function PDFNetworkStreamFullRequestReader(manager, options) {
  48130. this._manager = manager;
  48131. var source = options.source;
  48132. var args = {
  48133. onHeadersReceived: this._onHeadersReceived.bind(this),
  48134. onProgressiveData: source.disableStream ? null :
  48135. this._onProgressiveData.bind(this),
  48136. onDone: this._onDone.bind(this),
  48137. onError: this._onError.bind(this),
  48138. onProgress: this._onProgress.bind(this)
  48139. };
  48140. this._url = source.url;
  48141. this._fullRequestId = manager.requestFull(args);
  48142. this._headersReceivedCapability = createPromiseCapability();
  48143. this._disableRange = options.disableRange || false;
  48144. this._contentLength = source.length; // optional
  48145. this._rangeChunkSize = source.rangeChunkSize;
  48146. if (!this._rangeChunkSize && !this._disableRange) {
  48147. this._disableRange = true;
  48148. }
  48149. this._isStreamingSupported = false;
  48150. this._isRangeSupported = false;
  48151. this._cachedChunks = [];
  48152. this._requests = [];
  48153. this._done = false;
  48154. this._storedError = undefined;
  48155. this.onProgress = null;
  48156. }
  48157. PDFNetworkStreamFullRequestReader.prototype = {
  48158. _validateRangeRequestCapabilities: function
  48159. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  48160. if (this._disableRange) {
  48161. return false;
  48162. }
  48163. var networkManager = this._manager;
  48164. var fullRequestXhrId = this._fullRequestId;
  48165. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  48166. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  48167. return false;
  48168. }
  48169. var contentEncoding =
  48170. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  48171. if (contentEncoding !== 'identity') {
  48172. return false;
  48173. }
  48174. var length = fullRequestXhr.getResponseHeader('Content-Length');
  48175. length = parseInt(length, 10);
  48176. if (!isInt(length)) {
  48177. return false;
  48178. }
  48179. this._contentLength = length; // setting right content length
  48180. if (length <= 2 * this._rangeChunkSize) {
  48181. // The file size is smaller than the size of two chunks, so it does
  48182. // not make any sense to abort the request and retry with a range
  48183. // request.
  48184. return false;
  48185. }
  48186. return true;
  48187. },
  48188. _onHeadersReceived:
  48189. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  48190. if (this._validateRangeRequestCapabilities()) {
  48191. this._isRangeSupported = true;
  48192. }
  48193. var networkManager = this._manager;
  48194. var fullRequestXhrId = this._fullRequestId;
  48195. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  48196. // We can continue fetching when progressive loading is enabled,
  48197. // and we don't need the autoFetch feature.
  48198. this._isStreamingSupported = true;
  48199. } else if (this._isRangeSupported) {
  48200. // NOTE: by cancelling the full request, and then issuing range
  48201. // requests, there will be an issue for sites where you can only
  48202. // request the pdf once. However, if this is the case, then the
  48203. // server should not be returning that it can support range
  48204. // requests.
  48205. networkManager.abortRequest(fullRequestXhrId);
  48206. }
  48207. this._headersReceivedCapability.resolve();
  48208. },
  48209. _onProgressiveData:
  48210. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  48211. if (this._requests.length > 0) {
  48212. var requestCapability = this._requests.shift();
  48213. requestCapability.resolve({value: chunk, done: false});
  48214. } else {
  48215. this._cachedChunks.push(chunk);
  48216. }
  48217. },
  48218. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  48219. if (args) {
  48220. this._onProgressiveData(args.chunk);
  48221. }
  48222. this._done = true;
  48223. if (this._cachedChunks.length > 0) {
  48224. return;
  48225. }
  48226. this._requests.forEach(function (requestCapability) {
  48227. requestCapability.resolve({value: undefined, done: true});
  48228. });
  48229. this._requests = [];
  48230. },
  48231. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  48232. var url = this._url;
  48233. var exception;
  48234. if (status === 404 || status === 0 && /^file:/.test(url)) {
  48235. exception = new MissingPDFException('Missing PDF "' + url + '".');
  48236. } else {
  48237. exception = new UnexpectedResponseException(
  48238. 'Unexpected server response (' + status +
  48239. ') while retrieving PDF "' + url + '".', status);
  48240. }
  48241. this._storedError = exception;
  48242. this._headersReceivedCapability.reject(exception);
  48243. this._requests.forEach(function (requestCapability) {
  48244. requestCapability.reject(exception);
  48245. });
  48246. this._requests = [];
  48247. this._cachedChunks = [];
  48248. },
  48249. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  48250. if (this.onProgress) {
  48251. this.onProgress({
  48252. loaded: data.loaded,
  48253. total: data.lengthComputable ? data.total : this._contentLength
  48254. });
  48255. }
  48256. },
  48257. get isRangeSupported() {
  48258. return this._isRangeSupported;
  48259. },
  48260. get isStreamingSupported() {
  48261. return this._isStreamingSupported;
  48262. },
  48263. get contentLength() {
  48264. return this._contentLength;
  48265. },
  48266. get headersReady() {
  48267. return this._headersReceivedCapability.promise;
  48268. },
  48269. read: function PDFNetworkStreamFullRequestReader_read() {
  48270. if (this._storedError) {
  48271. return Promise.reject(this._storedError);
  48272. }
  48273. if (this._cachedChunks.length > 0) {
  48274. var chunk = this._cachedChunks.shift();
  48275. return Promise.resolve(chunk);
  48276. }
  48277. if (this._done) {
  48278. return Promise.resolve({value: undefined, done: true});
  48279. }
  48280. var requestCapability = createPromiseCapability();
  48281. this._requests.push(requestCapability);
  48282. return requestCapability.promise;
  48283. },
  48284. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  48285. this._done = true;
  48286. this._headersReceivedCapability.reject(reason);
  48287. this._requests.forEach(function (requestCapability) {
  48288. requestCapability.resolve({value: undefined, done: true});
  48289. });
  48290. this._requests = [];
  48291. if (this._manager.isPendingRequest(this._fullRequestId)) {
  48292. this._manager.abortRequest(this._fullRequestId);
  48293. }
  48294. this._fullRequestReader = null;
  48295. }
  48296. };
  48297. /** @implements {IPDFStreamRangeReader} */
  48298. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  48299. this._manager = manager;
  48300. var args = {
  48301. onDone: this._onDone.bind(this),
  48302. onProgress: this._onProgress.bind(this)
  48303. };
  48304. this._requestId = manager.requestRange(begin, end, args);
  48305. this._requests = [];
  48306. this._queuedChunk = null;
  48307. this._done = false;
  48308. this.onProgress = null;
  48309. this.onClosed = null;
  48310. }
  48311. PDFNetworkStreamRangeRequestReader.prototype = {
  48312. _close: function PDFNetworkStreamRangeRequestReader_close() {
  48313. if (this.onClosed) {
  48314. this.onClosed(this);
  48315. }
  48316. },
  48317. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  48318. var chunk = data.chunk;
  48319. if (this._requests.length > 0) {
  48320. var requestCapability = this._requests.shift();
  48321. requestCapability.resolve({value: chunk, done: false});
  48322. } else {
  48323. this._queuedChunk = chunk;
  48324. }
  48325. this._done = true;
  48326. this._requests.forEach(function (requestCapability) {
  48327. requestCapability.resolve({value: undefined, done: true});
  48328. });
  48329. this._requests = [];
  48330. this._close();
  48331. },
  48332. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  48333. if (!this.isStreamingSupported && this.onProgress) {
  48334. this.onProgress({
  48335. loaded: evt.loaded
  48336. });
  48337. }
  48338. },
  48339. get isStreamingSupported() {
  48340. return false; // TODO allow progressive range bytes loading
  48341. },
  48342. read: function PDFNetworkStreamRangeRequestReader_read() {
  48343. if (this._queuedChunk !== null) {
  48344. var chunk = this._queuedChunk;
  48345. this._queuedChunk = null;
  48346. return Promise.resolve({value: chunk, done: false});
  48347. }
  48348. if (this._done) {
  48349. return Promise.resolve({value: undefined, done: true});
  48350. }
  48351. var requestCapability = createPromiseCapability();
  48352. this._requests.push(requestCapability);
  48353. return requestCapability.promise;
  48354. },
  48355. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  48356. this._done = true;
  48357. this._requests.forEach(function (requestCapability) {
  48358. requestCapability.resolve({value: undefined, done: true});
  48359. });
  48360. this._requests = [];
  48361. if (this._manager.isPendingRequest(this._requestId)) {
  48362. this._manager.abortRequest(this._requestId);
  48363. }
  48364. this._close();
  48365. }
  48366. };
  48367. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  48368. exports.PDFNetworkStream = PDFNetworkStream;
  48369. exports.NetworkManager = NetworkManager;
  48370. }));
  48371. }).call(pdfjsLibs);
  48372. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  48373. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  48374. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  48375. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  48376. exports.PDFDataRangeTransport =
  48377. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  48378. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  48379. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  48380. exports.AnnotationLayer =
  48381. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  48382. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  48383. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  48384. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  48385. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  48386. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  48387. exports.UnexpectedResponseException =
  48388. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  48389. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  48390. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  48391. exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
  48392. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  48393. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  48394. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  48395. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  48396. exports.getFilenameFromUrl =
  48397. pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  48398. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  48399. }));