Browse Source

Remove cmap format 100, fixes some nits to merge with upstream

Vivien Nicolas 14 years ago
parent
commit
3e78538c1c
  1. 27
      fonts.js
  2. 9
      pdf.js
  3. 7
      utils/fonts_utils.js

27
fonts.js

@ -437,25 +437,14 @@ var Font = (function () { @@ -437,25 +437,14 @@ var Font = (function () {
glyphs.push({ unicode: 0x0000 });
var ranges = getRanges(glyphs);
var numTables = 2;
var kFormat100ArraySize = 256;
var numTables = 1;
var cmap = "\x00\x00" + // version
string16(numTables) + // numTables
"\x00\x01" + // platformID
"\x00\x00" + // encodingID
string32(4 + numTables * 8) + // start of the table record
"\x00\x03" + // platformID
"\x00\x01" + // encodingID
string32(4 + numTables * 8 + 6 + kFormat100ArraySize); // start of the table record
string32(4 + numTables * 8); // start of the table record
var format100 = "\x00\x00" + // format
string16(6 + kFormat100ArraySize) + // length
"\x00\x00"; // language
for (var i = 0; i < kFormat100ArraySize; i++)
format100 += String.fromCharCode(i);
var headerSize = (12 * 2 + (ranges.length * 4 * 2));
var headerSize = (12 * 2 + (ranges.length * 5 * 2));
var segCount = ranges.length + 1;
var segCount2 = segCount * 2;
var searchRange = FontsUtils.getMaxPower2(segCount) * 2;
@ -481,7 +470,7 @@ var Font = (function () { @@ -481,7 +470,7 @@ var Font = (function () {
var range = ranges[i];
var start = range[0];
var end = range[1];
var delta = (((start - 1) - bias) ^ 0xffff);
var delta = (bias - start) % 0xffff;
bias += (end - start + 1);
startCount += string16(start);
@ -489,7 +478,7 @@ var Font = (function () { @@ -489,7 +478,7 @@ var Font = (function () {
idDeltas += string16(delta);
idRangeOffsets += string16(0);
for (var j = start; j < end; j++) {
for (var j = start; j <= end; j++) {
glyphsIds += string16(j);
}
}
@ -501,7 +490,7 @@ var Font = (function () { @@ -501,7 +490,7 @@ var Font = (function () {
format314 += endCount + "\x00\x00" + startCount +
idDeltas + idRangeOffsets + glyphsIds;
return stringToArray(cmap + format100 + format314);
return stringToArray(cmap + format314);
};
function createOS2Table(properties) {
@ -541,7 +530,7 @@ var Font = (function () { @@ -541,7 +530,7 @@ var Font = (function () {
"\x02\x24" + // xAvgCharWidth
"\x01\xF4" + // usWeightClass
"\x00\x05" + // usWidthClass
"\x00\x02" + // fstype
"\x00\x00" + // fstype (0 to let the font loads via font-face on IE)
"\x02\x8A" + // ySubscriptXSize
"\x02\xBB" + // ySubscriptYSize
"\x00\x00" + // ySubscriptXOffset
@ -1075,7 +1064,7 @@ var Font = (function () { @@ -1075,7 +1064,7 @@ var Font = (function () {
var url = "url(data:" + this.mimetype + ";base64," + window.btoa(data) + ");";
var rule = "@font-face { font-family:'" + fontName + "';src:" + url + "}";
var styleSheet = document.styleSheets[0];
styleSheet.insertRule(rule, styleSheet.length);
styleSheet.insertRule(rule, styleSheet.cssRules.length);
}
};

9
pdf.js

@ -3545,7 +3545,7 @@ var CanvasGraphics = (function() { @@ -3545,7 +3545,7 @@ var CanvasGraphics = (function() {
flags: descriptor.get("Flags"),
italicAngle: descriptor.get("ItalicAngle"),
fixedPitch: false,
textMatrix: IDENTITY_MATRIX.slice()
textMatrix: IDENTITY_MATRIX
};
return {
@ -3870,8 +3870,11 @@ var CanvasGraphics = (function() { @@ -3870,8 +3870,11 @@ var CanvasGraphics = (function() {
} else {
text = Fonts.charsToUnicode(text);
this.ctx.translate(this.current.x, -1 * this.current.y);
var matrix = Fonts.lookup(this.current.fontName).properties.textMatrix;
this.ctx.transform.apply(this.ctx, matrix);
var font = Fonts.lookup(this.current.fontName);
if (font)
this.ctx.transform.apply(this.ctx, font.properties.textMatrix);
this.ctx.fillText(text, 0, 0);
this.current.x += Fonts.measureText(text);
}

7
utils/fonts_utils.js

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
"use strict";
/**
* The Type2 reader code below is only used for debugging purpose since Type2
* is only a CharString format and is never used directly as a Font file.
@ -376,6 +378,9 @@ var Type2Parser = function(aFilePath) { @@ -376,6 +378,9 @@ var Type2Parser = function(aFilePath) {
* writeToFile(fontData, "/tmp/pdf.js." + fontCount + ".cff");
*/
function writeToFile(aBytes, aFilePath) {
if (!("netscape" in window))
return;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var Cc = Components.classes,
Ci = Components.interfaces;
@ -384,7 +389,7 @@ function writeToFile(aBytes, aFilePath) { @@ -384,7 +389,7 @@ function writeToFile(aBytes, aFilePath) {
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
stream.init(file, 0x04 | 0x08 | 0x20, 0600, 0);
stream.init(file, 0x04 | 0x08 | 0x20, 0x180, 0);
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
.createInstance(Ci.nsIBinaryOutputStream);

Loading…
Cancel
Save