mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Annotation] Take into account the stroke alpha for a FreeText without appearance
This commit is contained in:
parent
ecd86ccffc
commit
a25895bf72
5 changed files with 30 additions and 4 deletions
|
@ -3511,8 +3511,8 @@ class FreeTextAnnotation extends MarkupAnnotation {
|
|||
const { xref } = params;
|
||||
this.data.annotationType = AnnotationType.FREETEXT;
|
||||
this.setDefaultAppearance(params);
|
||||
|
||||
if (!this.appearance && this._isOffscreenCanvasSupported) {
|
||||
const strokeAlpha = params.dict.get("CA");
|
||||
const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
|
||||
const fontData = this.data.defaultAppearanceData;
|
||||
this.appearance = fakeUnicodeFont.createAppearance(
|
||||
|
@ -3520,7 +3520,8 @@ class FreeTextAnnotation extends MarkupAnnotation {
|
|||
this.rectangle,
|
||||
this.rotation,
|
||||
fontData.fontSize || 10,
|
||||
fontData.fontColor
|
||||
fontData.fontColor,
|
||||
strokeAlpha
|
||||
);
|
||||
this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream);
|
||||
} else if (!this._isOffscreenCanvasSupported) {
|
||||
|
|
|
@ -264,7 +264,7 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
|
|||
return this.resources;
|
||||
}
|
||||
|
||||
createAppearance(text, rect, rotation, fontSize, bgColor) {
|
||||
createAppearance(text, rect, rotation, fontSize, bgColor, strokeAlpha) {
|
||||
const ctx = this._createContext();
|
||||
const lines = [];
|
||||
let maxWidth = -Infinity;
|
||||
|
@ -321,6 +321,23 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
|
|||
`/${this.fontName.name} ${numberToString(newFontSize)} Tf`,
|
||||
];
|
||||
|
||||
const { resources } = this;
|
||||
strokeAlpha =
|
||||
typeof strokeAlpha === "number" && strokeAlpha >= 0 && strokeAlpha <= 1
|
||||
? strokeAlpha
|
||||
: 1;
|
||||
|
||||
if (strokeAlpha !== 1) {
|
||||
buffer.push("/R0 gs");
|
||||
const extGState = new Dict(this.xref);
|
||||
const r0 = new Dict(this.xref);
|
||||
r0.set("ca", strokeAlpha);
|
||||
r0.set("CA", strokeAlpha);
|
||||
r0.set("Type", Name.get("ExtGState"));
|
||||
extGState.set("R0", r0);
|
||||
resources.set("ExtGState", extGState);
|
||||
}
|
||||
|
||||
const vShift = numberToString(lineHeight);
|
||||
for (const line of lines) {
|
||||
buffer.push(`0 -${vShift} Td <${stringToUTF16HexString(line)}> Tj`);
|
||||
|
@ -333,7 +350,7 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
|
|||
appearanceStreamDict.set("Type", Name.get("XObject"));
|
||||
appearanceStreamDict.set("BBox", [0, 0, w, h]);
|
||||
appearanceStreamDict.set("Length", appearance.length);
|
||||
appearanceStreamDict.set("Resources", this.resources);
|
||||
appearanceStreamDict.set("Resources", resources);
|
||||
|
||||
if (rotation) {
|
||||
const matrix = getRotationMatrix(rotation, w, h);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue