mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 17:55:37 +02:00
Implements vertical writing
This commit is contained in:
parent
4247339d28
commit
c5b8ee6a91
9 changed files with 112 additions and 29 deletions
|
@ -896,6 +896,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
var textSelection = textLayer && !skipTextSelection ? true : false;
|
||||
var textRenderingMode = current.textRenderingMode;
|
||||
var canvasWidth = 0.0;
|
||||
var vertical = font.vertical;
|
||||
var defaultVMetrics = font.defaultVMetrics;
|
||||
|
||||
// Type3 fonts - each glyph is a "mini-PDF"
|
||||
if (font.coded) {
|
||||
|
@ -969,25 +971,37 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
}
|
||||
|
||||
var character = glyph.fontChar;
|
||||
var charWidth = glyph.width * fontSize * current.fontMatrix[0] +
|
||||
var vmetric = glyph.vmetric || defaultVMetrics;
|
||||
if (vertical) {
|
||||
var vx = vmetric[1] * fontSize * current.fontMatrix[0];
|
||||
var vy = vmetric[2] * fontSize * current.fontMatrix[0];
|
||||
}
|
||||
var width = vmetric ? -vmetric[0] : glyph.width;
|
||||
var charWidth = width * fontSize * current.fontMatrix[0] +
|
||||
charSpacing * current.fontDirection;
|
||||
|
||||
if (!glyph.disabled) {
|
||||
var scaledX = x / fontSizeScale;
|
||||
if (vertical) {
|
||||
var scaledX = vx / fontSizeScale;
|
||||
var scaledY = (x + vy) / fontSizeScale;
|
||||
} else {
|
||||
var scaledX = x / fontSizeScale;
|
||||
var scaledY = 0;
|
||||
}
|
||||
switch (textRenderingMode) {
|
||||
default: // other unsupported rendering modes
|
||||
case TextRenderingMode.FILL:
|
||||
case TextRenderingMode.FILL_ADD_TO_PATH:
|
||||
ctx.fillText(character, scaledX, 0);
|
||||
ctx.fillText(character, scaledX, scaledY);
|
||||
break;
|
||||
case TextRenderingMode.STROKE:
|
||||
case TextRenderingMode.STROKE_ADD_TO_PATH:
|
||||
ctx.strokeText(character, scaledX, 0);
|
||||
ctx.strokeText(character, scaledX, scaledY);
|
||||
break;
|
||||
case TextRenderingMode.FILL_STROKE:
|
||||
case TextRenderingMode.FILL_STROKE_ADD_TO_PATH:
|
||||
ctx.fillText(character, scaledX, 0);
|
||||
ctx.strokeText(character, scaledX, 0);
|
||||
ctx.fillText(character, scaledX, scaledY);
|
||||
ctx.strokeText(character, scaledX, scaledY);
|
||||
break;
|
||||
case TextRenderingMode.INVISIBLE:
|
||||
case TextRenderingMode.ADD_TO_PATH:
|
||||
|
@ -995,7 +1009,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
}
|
||||
if (textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG) {
|
||||
var clipCtx = this.getCurrentTextClipping();
|
||||
clipCtx.fillText(character, scaledX, 0);
|
||||
clipCtx.fillText(character, scaledX, scaledY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1003,12 +1017,23 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
|
||||
canvasWidth += charWidth;
|
||||
}
|
||||
current.x += x * textHScale;
|
||||
if (vertical) {
|
||||
current.y -= x * textHScale;
|
||||
} else {
|
||||
current.x += x * textHScale;
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
if (textSelection) {
|
||||
geom.canvasWidth = canvasWidth;
|
||||
if (vertical) {
|
||||
var vmetric = font.defaultVMetrics;
|
||||
geom.x -= vmetric[1] * fontSize * current.fontMatrix[0] /
|
||||
fontSizeScale * geom.hScale;
|
||||
geom.y += vmetric[2] * fontSize * current.fontMatrix[0] /
|
||||
fontSizeScale * geom.vScale;
|
||||
}
|
||||
this.textLayer.appendText(geom);
|
||||
}
|
||||
|
||||
|
@ -1027,6 +1052,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
var geom;
|
||||
var canvasWidth = 0.0;
|
||||
var textSelection = textLayer ? true : false;
|
||||
var vertical = font.vertical;
|
||||
|
||||
if (textSelection) {
|
||||
ctx.save();
|
||||
|
@ -1039,7 +1065,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
var e = arr[i];
|
||||
if (isNum(e)) {
|
||||
var spacingLength = -e * fontSize * textHScale;
|
||||
current.x += spacingLength;
|
||||
if (vertical) {
|
||||
current.y += spacingLength;
|
||||
} else {
|
||||
current.x += spacingLength;
|
||||
}
|
||||
|
||||
if (textSelection)
|
||||
canvasWidth += spacingLength;
|
||||
|
@ -1055,6 +1085,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
|
||||
if (textSelection) {
|
||||
geom.canvasWidth = canvasWidth;
|
||||
if (vertical) {
|
||||
var fontSizeScale = current.fontSizeScale;
|
||||
var vmetric = font.defaultVMetrics;
|
||||
geom.x -= vmetric[1] * fontSize * current.fontMatrix[0] /
|
||||
fontSizeScale * geom.hScale;
|
||||
geom.y += vmetric[2] * fontSize * current.fontMatrix[0] /
|
||||
fontSizeScale * geom.vScale;
|
||||
}
|
||||
this.textLayer.appendText(geom);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue