mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Forces to measure "standard" fonts
This commit is contained in:
parent
a081c2d0f1
commit
9278abe738
2 changed files with 25 additions and 0 deletions
|
@ -1030,6 +1030,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
continue;
|
||||
}
|
||||
|
||||
var restoreNeeded = false;
|
||||
var character = glyph.fontChar;
|
||||
var vmetric = glyph.vmetric || defaultVMetrics;
|
||||
if (vertical) {
|
||||
|
@ -1055,6 +1056,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
|
||||
scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
|
||||
}
|
||||
|
||||
if (font.remeasure && width > 0) {
|
||||
// some standard fonts may not have the exact width, trying to
|
||||
// rescale per character
|
||||
var measuredWidth = ctx.measureText(character).width * 1000 /
|
||||
current.fontSize * current.fontSizeScale;
|
||||
var characterScaleX = width / measuredWidth;
|
||||
restoreNeeded = true;
|
||||
ctx.save();
|
||||
ctx.scale(characterScaleX, 1);
|
||||
scaledX /= characterScaleX;
|
||||
if (accent) {
|
||||
scaledAccentX /= characterScaleX;
|
||||
}
|
||||
}
|
||||
|
||||
switch (textRenderingMode) {
|
||||
default: // other unsupported rendering modes
|
||||
case TextRenderingMode.FILL:
|
||||
|
@ -1096,6 +1113,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
x += charWidth;
|
||||
|
||||
canvasWidth += charWidth;
|
||||
|
||||
if (restoreNeeded) {
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
if (vertical) {
|
||||
current.y -= x * textHScale;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue