Fix pattern-filled text
This commit is contained in:
parent
3e34eb31d9
commit
06d083b04b
@ -586,7 +586,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var glyphs = font.charsToGlyphs(chars);
|
var glyphs = font.charsToGlyphs(chars);
|
||||||
var isAddToPathSet = !!(state.textRenderingMode &
|
var isAddToPathSet = !!(state.textRenderingMode &
|
||||||
TextRenderingMode.ADD_TO_PATH_FLAG);
|
TextRenderingMode.ADD_TO_PATH_FLAG);
|
||||||
if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
|
if (font.data && (isAddToPathSet || this.options.disableFontFace ||
|
||||||
|
state.fillColorSpace.name === 'Pattern')) {
|
||||||
var buildPath = (fontChar) => {
|
var buildPath = (fontChar) => {
|
||||||
if (!font.renderer.hasBuiltPath(fontChar)) {
|
if (!font.renderer.hasBuiltPath(fontChar)) {
|
||||||
var path = font.renderer.getPathJs(fontChar);
|
var path = font.renderer.getPathJs(fontChar);
|
||||||
|
@ -1355,7 +1355,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.moveText(0, this.current.leading);
|
this.moveText(0, this.current.leading);
|
||||||
},
|
},
|
||||||
|
|
||||||
paintChar: function CanvasGraphics_paintChar(character, x, y) {
|
paintChar(character, x, y, patternTransform) {
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
var font = current.font;
|
var font = current.font;
|
||||||
@ -1365,17 +1365,21 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
TextRenderingMode.FILL_STROKE_MASK;
|
TextRenderingMode.FILL_STROKE_MASK;
|
||||||
var isAddToPathSet = !!(textRenderingMode &
|
var isAddToPathSet = !!(textRenderingMode &
|
||||||
TextRenderingMode.ADD_TO_PATH_FLAG);
|
TextRenderingMode.ADD_TO_PATH_FLAG);
|
||||||
|
let patternFill = current.patternFill && font.data;
|
||||||
|
|
||||||
var addToPath;
|
var addToPath;
|
||||||
if (font.disableFontFace || isAddToPathSet) {
|
if (font.disableFontFace || isAddToPathSet || patternFill) {
|
||||||
addToPath = font.getPathGenerator(this.commonObjs, character);
|
addToPath = font.getPathGenerator(this.commonObjs, character);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (font.disableFontFace) {
|
if (font.disableFontFace || patternFill) {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(x, y);
|
ctx.translate(x, y);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
addToPath(ctx, fontSize);
|
addToPath(ctx, fontSize);
|
||||||
|
if (patternTransform) {
|
||||||
|
ctx.setTransform.apply(ctx, patternTransform);
|
||||||
|
}
|
||||||
if (fillStrokeMode === TextRenderingMode.FILL ||
|
if (fillStrokeMode === TextRenderingMode.FILL ||
|
||||||
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
|
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
@ -1451,18 +1455,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
|
|
||||||
var simpleFillText =
|
var simpleFillText =
|
||||||
current.textRenderingMode === TextRenderingMode.FILL &&
|
current.textRenderingMode === TextRenderingMode.FILL &&
|
||||||
!font.disableFontFace;
|
!font.disableFontFace && !current.patternFill;
|
||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
let patternTransform;
|
||||||
|
if (current.patternFill) {
|
||||||
|
// TODO: Patterns are not applied correctly to text if a non-embedded
|
||||||
|
// font is used. E.g. issue 8111 and ShowText-ShadingPattern.pdf.
|
||||||
|
ctx.save();
|
||||||
|
let pattern = current.fillColor.getPattern(ctx, this);
|
||||||
|
patternTransform = ctx.mozCurrentTransform;
|
||||||
|
ctx.restore();
|
||||||
|
ctx.fillStyle = pattern;
|
||||||
|
}
|
||||||
ctx.transform.apply(ctx, current.textMatrix);
|
ctx.transform.apply(ctx, current.textMatrix);
|
||||||
ctx.translate(current.x, current.y + current.textRise);
|
ctx.translate(current.x, current.y + current.textRise);
|
||||||
|
|
||||||
if (current.patternFill) {
|
|
||||||
// TODO: Some shading patterns are not applied correctly to text,
|
|
||||||
// e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
|
|
||||||
ctx.fillStyle = current.fillColor.getPattern(ctx, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fontDirection > 0) {
|
if (fontDirection > 0) {
|
||||||
ctx.scale(textHScale, -1);
|
ctx.scale(textHScale, -1);
|
||||||
} else {
|
} else {
|
||||||
@ -1544,11 +1552,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
// common case
|
// common case
|
||||||
ctx.fillText(character, scaledX, scaledY);
|
ctx.fillText(character, scaledX, scaledY);
|
||||||
} else {
|
} else {
|
||||||
this.paintChar(character, scaledX, scaledY);
|
this.paintChar(character, scaledX, scaledY, patternTransform);
|
||||||
if (accent) {
|
if (accent) {
|
||||||
scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
|
scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
|
||||||
scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
|
scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
|
||||||
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
|
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY,
|
||||||
|
patternTransform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -124,6 +124,7 @@
|
|||||||
!issue5954.pdf
|
!issue5954.pdf
|
||||||
!issue6612.pdf
|
!issue6612.pdf
|
||||||
!alphatrans.pdf
|
!alphatrans.pdf
|
||||||
|
!pattern_text_embedded_font.pdf
|
||||||
!devicen.pdf
|
!devicen.pdf
|
||||||
!cmykjpeg.pdf
|
!cmykjpeg.pdf
|
||||||
!issue840.pdf
|
!issue840.pdf
|
||||||
|
BIN
test/pdfs/pattern_text_embedded_font.pdf
Normal file
BIN
test/pdfs/pattern_text_embedded_font.pdf
Normal file
Binary file not shown.
@ -2704,6 +2704,12 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "pattern_text_embedded_font",
|
||||||
|
"file": "pdfs/pattern_text_embedded_font.pdf",
|
||||||
|
"md5": "763b1b9efaecb2b5aefea71c39233f56",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue6113",
|
{ "id": "issue6113",
|
||||||
"file": "pdfs/issue6113.pdf",
|
"file": "pdfs/issue6113.pdf",
|
||||||
"md5": "365fa2d369c51ee3ff195dae907b6e25",
|
"md5": "365fa2d369c51ee3ff195dae907b6e25",
|
||||||
|
Loading…
Reference in New Issue
Block a user