Merge pull request #279 from sbarman/spacing
char spacing, word spacing and horozontal scaling
This commit is contained in:
commit
4efe54fb7b
44
pdf.js
44
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;
|
||||||
@ -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;
|
||||||
},
|
},
|
||||||
setLeading: function(leading) {
|
setLeading: function(leading) {
|
||||||
this.current.leading = leading;
|
this.current.leading = leading;
|
||||||
@ -4196,17 +4196,39 @@ var CanvasGraphics = (function() {
|
|||||||
ctx.transform.apply(ctx, current.textMatrix);
|
ctx.transform.apply(ctx, current.textMatrix);
|
||||||
ctx.scale(1, -1);
|
ctx.scale(1, -1);
|
||||||
|
|
||||||
if (this.ctx.$showText) {
|
|
||||||
ctx.$showText(current.y, text);
|
|
||||||
} else {
|
|
||||||
ctx.translate(current.x, -1 * current.y);
|
ctx.translate(current.x, -1 * current.y);
|
||||||
|
|
||||||
|
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) {
|
||||||
ctx.transform(1 / kScalePrecision, 0, 0, 1 / kScalePrecision, 0, 0);
|
scaleFactorX = scaleFactorY = kScalePrecision;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var charSpacing = current.charSpacing;
|
||||||
|
var wordSpacing = current.wordSpacing;
|
||||||
|
var textHScale = current.textHScale;
|
||||||
|
|
||||||
|
if (charSpacing != 0 || wordSpacing != 0 || textHScale != 1) {
|
||||||
|
scaleFactorX *= textHScale;
|
||||||
|
ctx.scale(1 / textHScale, 1);
|
||||||
|
var width = 0;
|
||||||
|
|
||||||
|
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 * scaleFactorX, 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);
|
||||||
}
|
}
|
||||||
@ -4220,7 +4242,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…
Reference in New Issue
Block a user