|
|
@ -4197,8 +4197,31 @@ var PartialEvaluator = (function() { |
|
|
|
extractEncoding: function(dict, xref, properties) { |
|
|
|
extractEncoding: function(dict, xref, properties) { |
|
|
|
var type = properties.type; |
|
|
|
var type = properties.type; |
|
|
|
if (properties.composite) { |
|
|
|
if (properties.composite) { |
|
|
|
// XXX only CIDFontType2 supported for now
|
|
|
|
|
|
|
|
if (type == 'CIDFontType2') { |
|
|
|
if (type == 'CIDFontType2') { |
|
|
|
|
|
|
|
var defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000; |
|
|
|
|
|
|
|
properties.defaultWidth = defaultWidth; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var glyphsWidths = {}; |
|
|
|
|
|
|
|
var widths = xref.fetchIfRef(dict.get('W')); |
|
|
|
|
|
|
|
if (widths) { |
|
|
|
|
|
|
|
var start = 0, end = 0; |
|
|
|
|
|
|
|
for (var i = 0; i < widths.length; i++) { |
|
|
|
|
|
|
|
var code = widths[i]; |
|
|
|
|
|
|
|
if (IsArray(code)) { |
|
|
|
|
|
|
|
for (var j = 0; j < code.length; j++) |
|
|
|
|
|
|
|
glyphsWidths[start++] = code[j]; |
|
|
|
|
|
|
|
start = 0; |
|
|
|
|
|
|
|
} else if (start) { |
|
|
|
|
|
|
|
for (var j = start; j <= code; j++) |
|
|
|
|
|
|
|
glyphsWidths[j] = widths[++i]; |
|
|
|
|
|
|
|
start = 0; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
start = code; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
properties.widths = glyphsWidths; |
|
|
|
|
|
|
|
|
|
|
|
var cidToGidMap = dict.get('CIDToGIDMap'); |
|
|
|
var cidToGidMap = dict.get('CIDToGIDMap'); |
|
|
|
if (!cidToGidMap || !IsRef(cidToGidMap)) |
|
|
|
if (!cidToGidMap || !IsRef(cidToGidMap)) |
|
|
|
return GlyphsUnicode; |
|
|
|
return GlyphsUnicode; |
|
|
@ -4211,15 +4234,16 @@ var PartialEvaluator = (function() { |
|
|
|
var encoding = properties.encoding; |
|
|
|
var encoding = properties.encoding; |
|
|
|
|
|
|
|
|
|
|
|
// Set encoding 0 to later verify the font has an encoding
|
|
|
|
// Set encoding 0 to later verify the font has an encoding
|
|
|
|
encoding[0] = { unicode: 0 }; |
|
|
|
encoding[0] = { unicode: 0, width: 0 }; |
|
|
|
for (var j = 0; j < glyphsData.length; j++) { |
|
|
|
for (var j = 0; j < glyphsData.length; j++) { |
|
|
|
var glyphID = (glyphsData[j++] << 8) | glyphsData[j]; |
|
|
|
var glyphID = (glyphsData[j++] << 8) | glyphsData[j]; |
|
|
|
if (glyphID == 0) |
|
|
|
if (glyphID == 0) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
encoding[j >> 1] = { |
|
|
|
var code = j >> 1; |
|
|
|
|
|
|
|
encoding[code] = { |
|
|
|
unicode: glyphID, |
|
|
|
unicode: glyphID, |
|
|
|
width: 0 |
|
|
|
width: glyphsWidths[code] || defaultWidth |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (type == 'CIDFontType0') { |
|
|
|
} else if (type == 'CIDFontType0') { |
|
|
@ -4287,22 +4311,24 @@ var PartialEvaluator = (function() { |
|
|
|
var glyphs = {}; |
|
|
|
var glyphs = {}; |
|
|
|
for (var i = firstChar; i <= lastChar; i++) { |
|
|
|
for (var i = firstChar; i <= lastChar; i++) { |
|
|
|
var glyph = differences[i] || baseEncoding[i]; |
|
|
|
var glyph = differences[i] || baseEncoding[i]; |
|
|
|
if (glyph) { |
|
|
|
var index = GlyphsUnicode[glyph] || i; |
|
|
|
var index = GlyphsUnicode[glyph] || i; |
|
|
|
var width = properties.widths[i] || properties.widths[glyph]; |
|
|
|
glyphs[glyph] = map[i] = { |
|
|
|
map[i] = { |
|
|
|
unicode: index, |
|
|
|
unicode: index, |
|
|
|
width: properties.widths[i - firstChar] || properties.defaultWidth |
|
|
|
width: width || properties.defaultWidth |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// If there is no file, the character mapping can't be modified
|
|
|
|
|
|
|
|
// but this is unlikely that there is any standard encoding with
|
|
|
|
|
|
|
|
// chars below 0x1f, so that's fine.
|
|
|
|
|
|
|
|
if (!properties.file) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index <= 0x1f || (index >= 127 && index <= 255)) |
|
|
|
if (glyph) |
|
|
|
map[i].unicode += kCmapGlyphOffset; |
|
|
|
glyphs[glyph] = map[i]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If there is no file, the character mapping can't be modified
|
|
|
|
|
|
|
|
// but this is unlikely that there is any standard encoding with
|
|
|
|
|
|
|
|
// chars below 0x1f, so that's fine.
|
|
|
|
|
|
|
|
if (!properties.file) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index <= 0x1f || (index >= 127 && index <= 255)) |
|
|
|
|
|
|
|
map[i].unicode += kCmapGlyphOffset; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (type == 'TrueType' && dict.has('ToUnicode') && differences) { |
|
|
|
if (type == 'TrueType' && dict.has('ToUnicode') && differences) { |
|
|
@ -4339,10 +4365,9 @@ var PartialEvaluator = (function() { |
|
|
|
var endRange = tokens[j + 1]; |
|
|
|
var endRange = tokens[j + 1]; |
|
|
|
var code = tokens[j + 2]; |
|
|
|
var code = tokens[j + 2]; |
|
|
|
while (startRange < endRange) { |
|
|
|
while (startRange < endRange) { |
|
|
|
map[startRange] = { |
|
|
|
var mapping = map[startRange] || {}; |
|
|
|
unicode: code++, |
|
|
|
mapping.unicode = code++; |
|
|
|
width: 0 |
|
|
|
map[startRange] = mapping; |
|
|
|
} |
|
|
|
|
|
|
|
++startRange; |
|
|
|
++startRange; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -4353,10 +4378,9 @@ var PartialEvaluator = (function() { |
|
|
|
for (var j = 0; j < tokens.length; j += 2) { |
|
|
|
for (var j = 0; j < tokens.length; j += 2) { |
|
|
|
var index = tokens[j]; |
|
|
|
var index = tokens[j]; |
|
|
|
var code = tokens[j + 1]; |
|
|
|
var code = tokens[j + 1]; |
|
|
|
map[index] = { |
|
|
|
var mapping = map[index] || {}; |
|
|
|
unicode: code, |
|
|
|
mapping.unicode = code; |
|
|
|
width: 0 |
|
|
|
map[index] = mapping; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
@ -4425,7 +4449,8 @@ var PartialEvaluator = (function() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Before PDF 1.5 if the font was one of the base 14 fonts, having a
|
|
|
|
// Before PDF 1.5 if the font was one of the base 14 fonts, having a
|
|
|
|
// FontDescriptor was not required. This case is here for compatibility.
|
|
|
|
// FontDescriptor was not required.
|
|
|
|
|
|
|
|
// This case is here for compatibility.
|
|
|
|
var descriptor = xref.fetchIfRef(dict.get('FontDescriptor')); |
|
|
|
var descriptor = xref.fetchIfRef(dict.get('FontDescriptor')); |
|
|
|
if (!descriptor) { |
|
|
|
if (!descriptor) { |
|
|
|
var baseFontName = dict.get('BaseFont'); |
|
|
|
var baseFontName = dict.get('BaseFont'); |
|
|
@ -4445,11 +4470,18 @@ var PartialEvaluator = (function() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var defaultWidth = 0; |
|
|
|
|
|
|
|
var widths = Metrics[stdFontMap[baseFontName] || baseFontName]; |
|
|
|
|
|
|
|
if (IsNum(widths)) { |
|
|
|
|
|
|
|
defaultWidth = widths; |
|
|
|
|
|
|
|
widths = null; |
|
|
|
|
|
|
|
} |
|
|
|
var properties = { |
|
|
|
var properties = { |
|
|
|
type: type.name, |
|
|
|
type: type.name, |
|
|
|
encoding: map, |
|
|
|
encoding: map, |
|
|
|
differences: [], |
|
|
|
differences: [], |
|
|
|
widths: {}, |
|
|
|
widths: widths, |
|
|
|
|
|
|
|
defaultWidth: defaultWidth, |
|
|
|
firstChar: 0, |
|
|
|
firstChar: 0, |
|
|
|
lastChar: 256 |
|
|
|
lastChar: 256 |
|
|
|
}; |
|
|
|
}; |
|
|
@ -4508,13 +4540,13 @@ var PartialEvaluator = (function() { |
|
|
|
descent: descriptor.get('Descent'), |
|
|
|
descent: descriptor.get('Descent'), |
|
|
|
xHeight: descriptor.get('XHeight'), |
|
|
|
xHeight: descriptor.get('XHeight'), |
|
|
|
capHeight: descriptor.get('CapHeight'), |
|
|
|
capHeight: descriptor.get('CapHeight'), |
|
|
|
defaultWidth: descriptor.get('MissingWidth') || 0, |
|
|
|
defaultWidth: parseFloat(descriptor.get('MissingWidth')) || 0, |
|
|
|
flags: descriptor.get('Flags'), |
|
|
|
flags: descriptor.get('Flags'), |
|
|
|
italicAngle: descriptor.get('ItalicAngle'), |
|
|
|
italicAngle: descriptor.get('ItalicAngle'), |
|
|
|
differences: [], |
|
|
|
differences: [], |
|
|
|
widths: (function() { |
|
|
|
widths: (function() { |
|
|
|
var glyphWidths = {}; |
|
|
|
var glyphWidths = {}; |
|
|
|
for (var i = 0; i <= widths.length; i++) |
|
|
|
for (var i = 0; i < widths.length; i++) |
|
|
|
glyphWidths[firstChar++] = widths[i]; |
|
|
|
glyphWidths[firstChar++] = widths[i]; |
|
|
|
return glyphWidths; |
|
|
|
return glyphWidths; |
|
|
|
})(), |
|
|
|
})(), |
|
|
@ -4903,6 +4935,7 @@ var CanvasGraphics = (function() { |
|
|
|
showText: function(text) { |
|
|
|
showText: function(text) { |
|
|
|
var ctx = this.ctx; |
|
|
|
var ctx = this.ctx; |
|
|
|
var current = this.current; |
|
|
|
var current = this.current; |
|
|
|
|
|
|
|
var originalText = text; |
|
|
|
|
|
|
|
|
|
|
|
ctx.save(); |
|
|
|
ctx.save(); |
|
|
|
ctx.transform.apply(ctx, current.textMatrix); |
|
|
|
ctx.transform.apply(ctx, current.textMatrix); |
|
|
@ -4921,26 +4954,21 @@ var CanvasGraphics = (function() { |
|
|
|
text = font.charsToUnicode(text); |
|
|
|
text = font.charsToUnicode(text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var size = current.fontSize; |
|
|
|
var charSpacing = current.charSpacing; |
|
|
|
var charSpacing = current.charSpacing; |
|
|
|
var wordSpacing = current.wordSpacing; |
|
|
|
var wordSpacing = current.wordSpacing; |
|
|
|
var textHScale = current.textHScale; |
|
|
|
var textHScale = current.textHScale; |
|
|
|
|
|
|
|
|
|
|
|
// This is a poor simulation for Arial Narrow while font-stretch
|
|
|
|
|
|
|
|
// is not implemented (bug 3512)
|
|
|
|
|
|
|
|
if (current.font.narrow) { |
|
|
|
|
|
|
|
textHScale += 0.2; |
|
|
|
|
|
|
|
charSpacing -= (0.09 * current.fontSize); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (charSpacing != 0 || wordSpacing != 0 || textHScale != 1) { |
|
|
|
if (charSpacing != 0 || wordSpacing != 0 || textHScale != 1) { |
|
|
|
scaleFactorX *= textHScale; |
|
|
|
scaleFactorX *= textHScale; |
|
|
|
ctx.scale(1 / textHScale, 1); |
|
|
|
ctx.scale(1 / textHScale, 1); |
|
|
|
var width = 0; |
|
|
|
var width = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0, ii = text.length; i < ii; ++i) { |
|
|
|
for (var i = 0, ii = text.length; i < ii; ++i) { |
|
|
|
var c = text.charAt(i); |
|
|
|
ctx.fillText(text.charAt(i), 0, 0); |
|
|
|
ctx.fillText(c, 0, 0); |
|
|
|
var c = originalText.charAt(i); |
|
|
|
var charWidth = FontMeasure.measureText(c) + charSpacing; |
|
|
|
var charWidth = FontMeasure.measureText(c, font, size); |
|
|
|
|
|
|
|
charWidth += charSpacing; |
|
|
|
if (c.charCodeAt(0) == 32) |
|
|
|
if (c.charCodeAt(0) == 32) |
|
|
|
charWidth += wordSpacing; |
|
|
|
charWidth += wordSpacing; |
|
|
|
ctx.translate(charWidth * scaleFactorX, 0); |
|
|
|
ctx.translate(charWidth * scaleFactorX, 0); |
|
|
@ -4949,7 +4977,7 @@ var CanvasGraphics = (function() { |
|
|
|
current.x += width; |
|
|
|
current.x += width; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.fillText(text, 0, 0); |
|
|
|
ctx.fillText(text, 0, 0); |
|
|
|
current.x += FontMeasure.measureText(text); |
|
|
|
current.x += FontMeasure.measureText(originalText, font, size); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.ctx.restore(); |
|
|
|
this.ctx.restore(); |
|
|
|