1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Merge remote branch 'upstream/master'

This commit is contained in:
Vivien Nicolas 2011-06-18 21:53:52 +02:00
commit 8b88ee0338
9 changed files with 295 additions and 1603 deletions

View file

@ -30,6 +30,7 @@ var fontCount = 0;
*/
var Fonts = {
_active: null,
get active() {
return this._active;
},
@ -38,12 +39,34 @@ var Fonts = {
this._active = this[aName];
},
unicodeFromCode: function fonts_unicodeFromCode(aCode) {
chars2Unicode: function(chars) {
var active = this._active;
if (!active || !active.properties.encoding)
return aCode;
if (!active)
return chars;
return GlyphsUnicode[active.properties.encoding[aCode]];
// if we translated this string before, just grab it from the cache
var ret = active.cache[chars];
if (ret)
return ret;
// translate the string using the font's encoding
var encoding = active.properties.encoding;
if (!encoding)
return chars;
var ret = "";
for (var i = 0; i < chars.length; ++i) {
var ch = chars.charCodeAt(i);
var uc = encoding[ch];
if (uc instanceof Name) // we didn't convert the glyph yet
uc = encoding[ch] = GlyphsUnicode[uc.name];
ret += String.fromCharCode(uc);
}
// enter the translated string into the cache
active.cache[chars] = ret;
return ret;
}
};
@ -83,7 +106,8 @@ var Font = function(aName, aFile, aProperties) {
encoding: {},
charset: null
},
loading: false
loading: false,
cache: Object.create(null)
};
this.mimetype = "font/ttf";
@ -99,7 +123,8 @@ var Font = function(aName, aFile, aProperties) {
Fonts[aName] = {
data: this.font,
properties: aProperties,
loading: true
loading: true,
cache: Object.create(null)
}
// Attach the font to the document
@ -1076,6 +1101,64 @@ var Type1Parser = function() {
}
};
const CFFStrings = [
".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand",
"quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period",
"slash","zero","one","two","three","four","five","six","seven","eight","nine",
"colon","semicolon","less","equal","greater","question","at","A","B","C","D","E",
"F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y",
"Z","bracketleft","backslash","bracketright","asciicircum","underscore",
"quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q",
"r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde",
"exclamdown","cent","sterling","fraction","yen","florin","section","currency",
"quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright",
"fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet",
"quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis",
"perthousand","questiondown","grave","acute","circumflex","tilde","macron",
"breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron",
"emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi",
"lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark",
"Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree",
"thorn","threequarters","twosuperior","registered","minus","eth","multiply",
"threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring",
"Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute",
"Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis",
"Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute",
"Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde",
"ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex",
"idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve",
"otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute",
"ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle",
"dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior",
"parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle",
"twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle",
"sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior",
"threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior",
"centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior",
"nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl",
"parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior",
"Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall",
"Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall",
"Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall",
"Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall",
"centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall",
"Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash",
"hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall",
"oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds",
"zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior",
"eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior",
"threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior",
"eightinferior","nineinferior","centinferior","dollarinferior","periodinferior",
"commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall",
"Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall",
"Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall",
"Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall",
"Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall",
"Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall",
"Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002",
"001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"
];
/**
* Take a Type1 file as input and wrap it into a Compact Font Format (CFF)
* wrapping Type2 charstrings.