Merge pull request #2220 from yurydelendik/fix-font-debugger
Fixes font debugger; text builder api refactoring
This commit is contained in:
commit
7511cde219
@ -646,7 +646,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
ctx.transform.apply(ctx, fontMatrix);
|
ctx.transform.apply(ctx, fontMatrix);
|
||||||
ctx.scale(textHScale, 1);
|
ctx.scale(textHScale, 1);
|
||||||
},
|
},
|
||||||
getTextGeometry: function CanvasGraphics_getTextGeometry() {
|
createTextGeometry: function CanvasGraphics_createTextGeometry() {
|
||||||
var geometry = {};
|
var geometry = {};
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var font = this.current.font;
|
var font = this.current.font;
|
||||||
@ -660,6 +660,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
geometry.vScale = tr[1] - bl[1];
|
geometry.vScale = tr[1] - bl[1];
|
||||||
}
|
}
|
||||||
geometry.spaceWidth = font.spaceWidth;
|
geometry.spaceWidth = font.spaceWidth;
|
||||||
|
geometry.fontName = font.loadedName;
|
||||||
|
geometry.fontFamily = font.fallbackName;
|
||||||
|
geometry.fontSize = this.current.fontSize;
|
||||||
return geometry;
|
return geometry;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -693,7 +696,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
if (textSelection) {
|
if (textSelection) {
|
||||||
this.save();
|
this.save();
|
||||||
ctx.scale(1, -1);
|
ctx.scale(1, -1);
|
||||||
geom = this.getTextGeometry();
|
geom = this.createTextGeometry();
|
||||||
this.restore();
|
this.restore();
|
||||||
}
|
}
|
||||||
for (var i = 0; i < glyphsLength; ++i) {
|
for (var i = 0; i < glyphsLength; ++i) {
|
||||||
@ -734,7 +737,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
lineWidth /= scale;
|
lineWidth /= scale;
|
||||||
|
|
||||||
if (textSelection)
|
if (textSelection)
|
||||||
geom = this.getTextGeometry();
|
geom = this.createTextGeometry();
|
||||||
|
|
||||||
if (fontSizeScale != 1.0) {
|
if (fontSizeScale != 1.0) {
|
||||||
ctx.scale(fontSizeScale, fontSizeScale);
|
ctx.scale(fontSizeScale, fontSizeScale);
|
||||||
@ -792,7 +795,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
|
|
||||||
if (textSelection) {
|
if (textSelection) {
|
||||||
geom.canvasWidth = canvasWidth;
|
geom.canvasWidth = canvasWidth;
|
||||||
this.textLayer.appendText(font.fallbackName, fontSize, geom);
|
this.textLayer.appendText(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
return canvasWidth;
|
return canvasWidth;
|
||||||
@ -821,7 +824,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
ctx.scale(textHScale, 1);
|
ctx.scale(textHScale, 1);
|
||||||
} else
|
} else
|
||||||
this.applyTextTransforms();
|
this.applyTextTransforms();
|
||||||
geom = this.getTextGeometry();
|
geom = this.createTextGeometry();
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,7 +848,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
|
|
||||||
if (textSelection) {
|
if (textSelection) {
|
||||||
geom.canvasWidth = canvasWidth;
|
geom.canvasWidth = canvasWidth;
|
||||||
this.textLayer.appendText(font.fallbackName, fontSize, geom);
|
this.textLayer.appendText(geom);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nextLineShowText: function CanvasGraphics_nextLineShowText(text) {
|
nextLineShowText: function CanvasGraphics_nextLineShowText(text) {
|
||||||
|
@ -168,11 +168,10 @@ SimpleTextLayerBuilder.prototype = {
|
|||||||
endLayout: function SimpleTextLayerBuilder_EndLayout() {
|
endLayout: function SimpleTextLayerBuilder_EndLayout() {
|
||||||
this.ctx.restore();
|
this.ctx.restore();
|
||||||
},
|
},
|
||||||
appendText: function SimpleTextLayerBuilder_AppendText(fontName, fontSize,
|
appendText: function SimpleTextLayerBuilder_AppendText(geom) {
|
||||||
geom) {
|
|
||||||
var ctx = this.ctx, viewport = this.viewport;
|
var ctx = this.ctx, viewport = this.viewport;
|
||||||
// vScale and hScale already contain the scaling to pixel units
|
// vScale and hScale already contain the scaling to pixel units
|
||||||
var fontHeight = fontSize * geom.vScale;
|
var fontHeight = geom.fontSize * geom.vScale;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.strokeStyle = 'red';
|
ctx.strokeStyle = 'red';
|
||||||
ctx.fillStyle = 'yellow';
|
ctx.fillStyle = 'yellow';
|
||||||
@ -182,7 +181,7 @@ SimpleTextLayerBuilder.prototype = {
|
|||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
|
||||||
var textContent = this.textContent.bidiTexts[this.textCounter].str;
|
var textContent = this.textContent.bidiTexts[this.textCounter].str;
|
||||||
ctx.font = fontHeight + 'px ' + fontName;
|
ctx.font = fontHeight + 'px ' + geom.fontFamily;
|
||||||
ctx.fillStyle = 'black';
|
ctx.fillStyle = 'black';
|
||||||
ctx.fillText(textContent, geom.x, geom.y);
|
ctx.fillText(textContent, geom.x, geom.y);
|
||||||
|
|
||||||
|
@ -2303,17 +2303,16 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.appendText = function textLayerBuilderAppendText(fontName, fontSize,
|
this.appendText = function textLayerBuilderAppendText(geom) {
|
||||||
geom) {
|
|
||||||
var textDiv = document.createElement('div');
|
var textDiv = document.createElement('div');
|
||||||
|
|
||||||
// vScale and hScale already contain the scaling to pixel units
|
// vScale and hScale already contain the scaling to pixel units
|
||||||
var fontHeight = fontSize * geom.vScale;
|
var fontHeight = geom.fontSize * geom.vScale;
|
||||||
textDiv.dataset.canvasWidth = geom.canvasWidth * geom.hScale;
|
textDiv.dataset.canvasWidth = geom.canvasWidth * geom.hScale;
|
||||||
textDiv.dataset.fontName = fontName;
|
textDiv.dataset.fontName = geom.fontName;
|
||||||
|
|
||||||
textDiv.style.fontSize = fontHeight + 'px';
|
textDiv.style.fontSize = fontHeight + 'px';
|
||||||
textDiv.style.fontFamily = fontName;
|
textDiv.style.fontFamily = geom.fontFamily;
|
||||||
textDiv.style.left = geom.x + 'px';
|
textDiv.style.left = geom.x + 'px';
|
||||||
textDiv.style.top = (geom.y - fontHeight) + 'px';
|
textDiv.style.top = (geom.y - fontHeight) + 'px';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user