Browse Source

initial impl of char spacing and word spacing

sbarman 14 years ago
parent
commit
c58aa5f232
  1. 49
      pdf.js

49
pdf.js

@ -4114,13 +4114,13 @@ var CanvasGraphics = (function() {
endText: function() { endText: function() {
}, },
setCharSpacing: function(spacing) { setCharSpacing: function(spacing) {
this.ctx.charSpacing = spacing; this.current.charSpacing = spacing;
}, },
setWordSpacing: function(spacing) { setWordSpacing: function(spacing) {
this.ctx.wordSpacing = spacing; this.current.wordSpacing = spacing;
}, },
setHScale: function(scale) { setHScale: function(scale) {
this.ctx.textHScale = (scale % 100) * 0.01; this.current.textHScale = (scale % 100) * 0.01;
}, },
setLeading: function(leading) { setLeading: function(leading) {
this.current.leading = leading; this.current.leading = leading;
@ -4195,18 +4195,41 @@ var CanvasGraphics = (function() {
ctx.save(); ctx.save();
ctx.transform.apply(ctx, current.textMatrix); ctx.transform.apply(ctx, current.textMatrix);
ctx.scale(1, -1); ctx.scale(1, -1);
ctx.translate(current.x, -1 * current.y);
var scaleFactor = 1;
var font = this.current.font;
if (font) {
if (this.current.fontSize < kRasterizerMin) {
scaleFactor = 1 / kScalePrecision;
ctx.scale(scaleFactor, scaleFactor);
}
ctx.transform.apply(ctx, font.textMatrix);
text = font.charsToUnicode(text);
}
if (this.ctx.$showText) { var charSpacing = current.charSpacing;
ctx.$showText(current.y, text); var wordSpacing = current.wordSpacing;
} else { var textHScale = current.textHScale;
ctx.translate(current.x, -1 * current.y);
var font = this.current.font; if (charSpacing || wordSpacing || textHScale) {
if (font) { charSpacing = charSpacing || 0;
if (this.current.fontSize < kRasterizerMin) wordSpacing = wordSpacing || 0;
ctx.transform(1 / kScalePrecision, 0, 0, 1 / kScalePrecision, 0, 0); var width = 0;
ctx.transform.apply(ctx, font.textMatrix);
text = font.charsToUnicode(text); for (var i = 0, ii = text.length; i < ii; ++i) {
var c = text.charAt(i);
ctx.fillText(c, 0, 0);
var charWidth = FontMeasure.measureText(c) + charSpacing;
if (c.charCodeAt(0) == 32)
charWidth += wordSpacing;
ctx.translate(charWidth / scaleFactor, 0);
width += charWidth;
} }
current.x += width;
} else {
ctx.fillText(text, 0, 0); ctx.fillText(text, 0, 0);
current.x += FontMeasure.measureText(text); current.x += FontMeasure.measureText(text);
} }

Loading…
Cancel
Save