Merge pull request #9090 from janpe2/pattern-text

Fix pattern-filled text (embedded fonts only)
This commit is contained in:
Jonas Jenwald 2017-11-28 20:38:58 +01:00 committed by GitHub
commit e78fe842c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 13 deletions

View File

@ -586,7 +586,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var glyphs = font.charsToGlyphs(chars);
var isAddToPathSet = !!(state.textRenderingMode &
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) => {
if (!font.renderer.hasBuiltPath(fontChar)) {
var path = font.renderer.getPathJs(fontChar);

View File

@ -1355,7 +1355,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.moveText(0, this.current.leading);
},
paintChar: function CanvasGraphics_paintChar(character, x, y) {
paintChar(character, x, y, patternTransform) {
var ctx = this.ctx;
var current = this.current;
var font = current.font;
@ -1365,17 +1365,21 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
TextRenderingMode.FILL_STROKE_MASK;
var isAddToPathSet = !!(textRenderingMode &
TextRenderingMode.ADD_TO_PATH_FLAG);
let patternFill = current.patternFill && font.data;
var addToPath;
if (font.disableFontFace || isAddToPathSet) {
if (font.disableFontFace || isAddToPathSet || patternFill) {
addToPath = font.getPathGenerator(this.commonObjs, character);
}
if (font.disableFontFace) {
if (font.disableFontFace || patternFill) {
ctx.save();
ctx.translate(x, y);
ctx.beginPath();
addToPath(ctx, fontSize);
if (patternTransform) {
ctx.setTransform.apply(ctx, patternTransform);
}
if (fillStrokeMode === TextRenderingMode.FILL ||
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
ctx.fill();
@ -1451,18 +1455,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var simpleFillText =
current.textRenderingMode === TextRenderingMode.FILL &&
!font.disableFontFace;
!font.disableFontFace && !current.patternFill;
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.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) {
ctx.scale(textHScale, -1);
} else {
@ -1544,11 +1552,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// common case
ctx.fillText(character, scaledX, scaledY);
} else {
this.paintChar(character, scaledX, scaledY);
this.paintChar(character, scaledX, scaledY, patternTransform);
if (accent) {
scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY,
patternTransform);
}
}
}

View File

@ -124,6 +124,7 @@
!issue5954.pdf
!issue6612.pdf
!alphatrans.pdf
!pattern_text_embedded_font.pdf
!devicen.pdf
!cmykjpeg.pdf
!issue840.pdf

Binary file not shown.

View File

@ -2704,6 +2704,12 @@
"rounds": 1,
"type": "eq"
},
{ "id": "pattern_text_embedded_font",
"file": "pdfs/pattern_text_embedded_font.pdf",
"md5": "763b1b9efaecb2b5aefea71c39233f56",
"rounds": 1,
"type": "eq"
},
{ "id": "issue6113",
"file": "pdfs/issue6113.pdf",
"md5": "365fa2d369c51ee3ff195dae907b6e25",