fixed up minor bugs

This commit is contained in:
sbarman 2011-07-07 17:15:53 -07:00
parent 8ac2367fa0
commit c39eae3ce9
2 changed files with 14 additions and 17 deletions

View File

@ -31,11 +31,13 @@ var Fonts = (function Fonts() {
ctx.scale(1 / kScalePrecision, 1);
}
function FontInfo(name, data, properties, id) {
var fontCount = 0;
function FontInfo(name, data, properties) {
this.name = name;
this.data = data;
this.properties = properties;
this.id = id;
this.id = fontCount++;
this.loading = true;
this.charsCache = Object.create(null);
this.sizes = [];
@ -45,12 +47,11 @@ var Fonts = (function Fonts() {
var charsCache;
var measureCache;
var fontCount = 0;
return {
registerFont: function fonts_registerFont(fontName, data, properties) {
fonts.push(new FontInfo(fontName, data, properties, fontCount));
return fontCount++;
var font = new FontInfo(fontName, data, properties);
fonts.push(font);
return font.id;
},
blacklistFont: function fonts_blacklistFont(fontName) {
var id = registerFont(fontName, null, {});
@ -122,8 +123,8 @@ var FontLoader = {
bind: function(fonts, callback) {
function checkFontsLoaded() {
for (var i = 0; i < fonts.length; i++) {
var id = fonts[i].fontDict.fontObj.id;
for (var i = 0; i < allIds.length; i++) {
var id = allIds[i];
if (Fonts.lookupById(id).loading) {
return false;
}
@ -136,12 +137,15 @@ var FontLoader = {
return true;
}
var allIds = [];
var rules = [], names = [], ids = [];
for (var i = 0; i < fonts.length; i++) {
var font = fonts[i];
var obj = new Font(font.name, font.file, font.properties);
font.fontDict.fontObj = obj;
allIds.push(obj.id);
var str = '';
var data = Fonts.lookupById(obj.id).data;
@ -160,7 +164,7 @@ var FontLoader = {
if (!isWorker && rules.length) {
FontLoader.prepareFontLoadEvent(rules, names, ids);
}
if (!checkFontsLoaded()) {
document.documentElement.addEventListener(
'pdfjsFontLoad', checkFontsLoaded, false);
@ -407,12 +411,6 @@ var Font = (function() {
this.name = name;
this.encoding = properties.encoding;
// If the font has already been decoded simply return it
//if (Fonts.lookup(name)) {
// this.font = Fonts.lookup(name).data;
// return;
//}
// If the font is to be ignored, register it like an already loaded font
// to avoid the cost of waiting for it be be loaded by the platform.
if (properties.ignore) {

3
pdf.js
View File

@ -3687,7 +3687,6 @@ var CanvasGraphics = (function() {
var font = xref.fetchIfRef(fontRes.get(args[0].name));
assertWellFormed(IsDict(font));
if (!font.translated) {
// sbarman marker
font.translated = this.translateFont(font, xref, resources);
if (fonts && font.translated) {
// keep track of each font we translated so the caller can
@ -3886,7 +3885,7 @@ var CanvasGraphics = (function() {
this.ctx.$setFont(fontName, size);
} else {
this.ctx.font = size + 'px "' + fontName + '"';
Fonts.setActive(font, size);
Fonts.setActive(fontObj, size);
}
},
setTextRenderingMode: function(mode) {