1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

[Editor] Guess font size and color from the AS of FreeText annotations

This commit is contained in:
Calixte Denizet 2023-06-05 12:15:41 +02:00
parent 77fb6834d6
commit ba8c996623
3 changed files with 238 additions and 5 deletions

View file

@ -48,6 +48,7 @@ import {
createDefaultAppearance,
FakeUnicodeFont,
getPdfColor,
parseAppearanceStream,
parseDefaultAppearance,
} from "./default_appearance.js";
import { Dict, isName, Name, Ref, RefSet } from "./primitives.js";
@ -3545,20 +3546,25 @@ class FreeTextAnnotation extends MarkupAnnotation {
const { xref } = params;
this.data.annotationType = AnnotationType.FREETEXT;
this.setDefaultAppearance(params);
if (!this.appearance && this._isOffscreenCanvasSupported) {
if (this.appearance) {
const { fontColor, fontSize } = parseAppearanceStream(this.appearance);
this.data.defaultAppearanceData.fontColor = fontColor;
this.data.defaultAppearanceData.fontSize = fontSize || 10;
} else if (this._isOffscreenCanvasSupported) {
const strokeAlpha = params.dict.get("CA");
const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
const fontData = this.data.defaultAppearanceData;
this.data.defaultAppearanceData.fontSize ||= 10;
const { fontColor, fontSize } = this.data.defaultAppearanceData;
this.appearance = fakeUnicodeFont.createAppearance(
this._contents.str,
this.rectangle,
this.rotation,
fontData.fontSize || 10,
fontData.fontColor,
fontSize,
fontColor,
strokeAlpha
);
this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream);
} else if (!this._isOffscreenCanvasSupported) {
} else {
warn(
"FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly."
);