Browse Source

added texthscale support

sbarman 14 years ago
parent
commit
47dcd1f94b
  1. 22
      pdf.js

22
pdf.js

@ -3448,7 +3448,7 @@ var EvalState = (function() {
// Character and word spacing // Character and word spacing
this.charSpace = 0; this.charSpace = 0;
this.wordSpace = 0; this.wordSpace = 0;
this.textHScale = 100; this.textHScale = 1;
// Color spaces // Color spaces
this.fillColorSpace = null; this.fillColorSpace = null;
this.strokeColorSpace = null; this.strokeColorSpace = null;
@ -3866,7 +3866,7 @@ var CanvasExtraState = (function() {
// Character and word spacing // Character and word spacing
this.charSpace = 0; this.charSpace = 0;
this.wordSpace = 0; this.wordSpace = 0;
this.textHScale = 100; this.textHScale = 1;
// Color spaces // Color spaces
this.fillColorSpaceObj = null; this.fillColorSpaceObj = null;
this.strokeColorSpaceObj = null; this.strokeColorSpaceObj = null;
@ -4120,7 +4120,7 @@ var CanvasGraphics = (function() {
this.current.wordSpacing = spacing; this.current.wordSpacing = spacing;
}, },
setHScale: function(scale) { setHScale: function(scale) {
this.current.textHScale = (scale % 100) * 0.01; this.current.textHScale = scale / 100;
}, },
setLeading: function(leading) { setLeading: function(leading) {
this.current.leading = leading; this.current.leading = leading;
@ -4198,12 +4198,12 @@ var CanvasGraphics = (function() {
ctx.translate(current.x, -1 * current.y); ctx.translate(current.x, -1 * current.y);
var scaleFactor = 1; var scaleFactorX = 1, scaleFactorY = 1;
var font = this.current.font; var font = this.current.font;
if (font) { if (font) {
if (this.current.fontSize < kRasterizerMin) { if (this.current.fontSize < kRasterizerMin) {
scaleFactor = 1 / kScalePrecision; scaleFactorX = scaleFactorY = kScalePrecision;
ctx.scale(scaleFactor, scaleFactor); ctx.scale(1 / scaleFactorX, 1 / scaleFactorY);
} }
ctx.transform.apply(ctx, font.textMatrix); ctx.transform.apply(ctx, font.textMatrix);
text = font.charsToUnicode(text); text = font.charsToUnicode(text);
@ -4213,9 +4213,9 @@ var CanvasGraphics = (function() {
var wordSpacing = current.wordSpacing; var wordSpacing = current.wordSpacing;
var textHScale = current.textHScale; var textHScale = current.textHScale;
if (charSpacing || wordSpacing || textHScale) { if (charSpacing != 0 || wordSpacing != 0 || textHScale != 1) {
charSpacing = charSpacing || 0; scaleFactorX *= textHScale;
wordSpacing = wordSpacing || 0; 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) {
@ -4225,7 +4225,7 @@ var CanvasGraphics = (function() {
if (c.charCodeAt(0) == 32) if (c.charCodeAt(0) == 32)
charWidth += wordSpacing; charWidth += wordSpacing;
ctx.translate(charWidth / scaleFactor, 0); ctx.translate(charWidth * scaleFactorX, 0);
width += charWidth; width += charWidth;
} }
current.x += width; current.x += width;
@ -4243,7 +4243,7 @@ var CanvasGraphics = (function() {
if (this.ctx.$addCurrentX) { if (this.ctx.$addCurrentX) {
this.ctx.$addCurrentX(-e * 0.001 * this.current.fontSize); this.ctx.$addCurrentX(-e * 0.001 * this.current.fontSize);
} else { } else {
this.current.x -= e * 0.001 * this.current.fontSize; this.current.x -= e * 0.001 * this.current.fontSize * this.current.textHScale;
} }
} else if (IsString(e)) { } else if (IsString(e)) {
this.showText(e); this.showText(e);

Loading…
Cancel
Save