Merge pull request #13169 from Snuffleupagus/DefaultAppearanceEvaluator-fontName
[api-minor] Change the format of the `fontName`-property, in `defaultAppearanceData`, on Annotation-instances (PR 12831 follow-up)
This commit is contained in:
commit
5cf116a958
@ -1470,7 +1470,7 @@ class WidgetAnnotation extends Annotation {
|
|||||||
const { fontName, fontSize } = this.data.defaultAppearanceData;
|
const { fontName, fontSize } = this.data.defaultAppearanceData;
|
||||||
await evaluator.handleSetFont(
|
await evaluator.handleSetFont(
|
||||||
this._fieldResources.mergedResources,
|
this._fieldResources.mergedResources,
|
||||||
[fontName, fontSize],
|
[fontName && Name.get(fontName), fontSize],
|
||||||
/* fontRef = */ null,
|
/* fontRef = */ null,
|
||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
@ -1565,26 +1565,26 @@ class WidgetAnnotation extends Annotation {
|
|||||||
acroFormResources,
|
acroFormResources,
|
||||||
} = this._fieldResources;
|
} = this._fieldResources;
|
||||||
|
|
||||||
const fontNameStr =
|
const fontName =
|
||||||
this.data.defaultAppearanceData &&
|
this.data.defaultAppearanceData &&
|
||||||
this.data.defaultAppearanceData.fontName.name;
|
this.data.defaultAppearanceData.fontName;
|
||||||
if (!fontNameStr) {
|
if (!fontName) {
|
||||||
return localResources || Dict.empty;
|
return localResources || Dict.empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const resources of [localResources, appearanceResources]) {
|
for (const resources of [localResources, appearanceResources]) {
|
||||||
if (resources instanceof Dict) {
|
if (resources instanceof Dict) {
|
||||||
const localFont = resources.get("Font");
|
const localFont = resources.get("Font");
|
||||||
if (localFont instanceof Dict && localFont.has(fontNameStr)) {
|
if (localFont instanceof Dict && localFont.has(fontName)) {
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (acroFormResources instanceof Dict) {
|
if (acroFormResources instanceof Dict) {
|
||||||
const acroFormFont = acroFormResources.get("Font");
|
const acroFormFont = acroFormResources.get("Font");
|
||||||
if (acroFormFont instanceof Dict && acroFormFont.has(fontNameStr)) {
|
if (acroFormFont instanceof Dict && acroFormFont.has(fontName)) {
|
||||||
const subFontDict = new Dict(xref);
|
const subFontDict = new Dict(xref);
|
||||||
subFontDict.set(fontNameStr, acroFormFont.getRaw(fontNameStr));
|
subFontDict.set(fontName, acroFormFont.getRaw(fontName));
|
||||||
|
|
||||||
const subResourcesDict = new Dict(xref);
|
const subResourcesDict = new Dict(xref);
|
||||||
subResourcesDict.set("Font", subFontDict);
|
subResourcesDict.set("Font", subFontDict);
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isName, Name } from "./primitives.js";
|
|
||||||
import { OPS, warn } from "../shared/util.js";
|
import { OPS, warn } from "../shared/util.js";
|
||||||
import { ColorSpace } from "./colorspace.js";
|
import { ColorSpace } from "./colorspace.js";
|
||||||
import { escapePDFName } from "./core_utils.js";
|
import { escapePDFName } from "./core_utils.js";
|
||||||
import { EvaluatorPreprocessor } from "./evaluator.js";
|
import { EvaluatorPreprocessor } from "./evaluator.js";
|
||||||
|
import { Name } from "./primitives.js";
|
||||||
import { StringStream } from "./stream.js";
|
import { StringStream } from "./stream.js";
|
||||||
|
|
||||||
class DefaultAppearanceEvaluator extends EvaluatorPreprocessor {
|
class DefaultAppearanceEvaluator extends EvaluatorPreprocessor {
|
||||||
@ -32,8 +32,8 @@ class DefaultAppearanceEvaluator extends EvaluatorPreprocessor {
|
|||||||
};
|
};
|
||||||
const result = {
|
const result = {
|
||||||
fontSize: 0,
|
fontSize: 0,
|
||||||
fontName: Name.get(""),
|
fontName: "",
|
||||||
fontColor: new Uint8ClampedArray([0, 0, 0]) /* black */,
|
fontColor: /* black = */ new Uint8ClampedArray(3),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -51,8 +51,8 @@ class DefaultAppearanceEvaluator extends EvaluatorPreprocessor {
|
|||||||
switch (fn | 0) {
|
switch (fn | 0) {
|
||||||
case OPS.setFont:
|
case OPS.setFont:
|
||||||
const [fontName, fontSize] = args;
|
const [fontName, fontSize] = args;
|
||||||
if (isName(fontName)) {
|
if (fontName instanceof Name) {
|
||||||
result.fontName = fontName;
|
result.fontName = fontName.name;
|
||||||
}
|
}
|
||||||
if (typeof fontSize === "number" && fontSize > 0) {
|
if (typeof fontSize === "number" && fontSize > 0) {
|
||||||
result.fontSize = fontSize;
|
result.fontSize = fontSize;
|
||||||
@ -93,7 +93,7 @@ function createDefaultAppearance({ fontSize, fontName, fontColor }) {
|
|||||||
.map(c => (c / 255).toFixed(2))
|
.map(c => (c / 255).toFixed(2))
|
||||||
.join(" ") + " rg";
|
.join(" ") + " rg";
|
||||||
}
|
}
|
||||||
return `/${escapePDFName(fontName.name)} ${fontSize} Tf ${colorCmd}`;
|
return `/${escapePDFName(fontName)} ${fontSize} Tf ${colorCmd}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { createDefaultAppearance, parseDefaultAppearance };
|
export { createDefaultAppearance, parseDefaultAppearance };
|
||||||
|
@ -794,12 +794,8 @@ class PartialEvaluator {
|
|||||||
state,
|
state,
|
||||||
fallbackFontDict = null
|
fallbackFontDict = null
|
||||||
) {
|
) {
|
||||||
// TODO(mack): Not needed?
|
const fontName =
|
||||||
var fontName;
|
fontArgs && fontArgs[0] instanceof Name ? fontArgs[0].name : null;
|
||||||
if (fontArgs) {
|
|
||||||
fontArgs = fontArgs.slice();
|
|
||||||
fontName = fontArgs[0].name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.loadFont(fontName, fontRef, resources, fallbackFontDict)
|
return this.loadFont(fontName, fontRef, resources, fallbackFontDict)
|
||||||
.then(translated => {
|
.then(translated => {
|
||||||
|
@ -17,7 +17,6 @@ import {
|
|||||||
createDefaultAppearance,
|
createDefaultAppearance,
|
||||||
parseDefaultAppearance,
|
parseDefaultAppearance,
|
||||||
} from "../../src/core/default_appearance.js";
|
} from "../../src/core/default_appearance.js";
|
||||||
import { Name } from "../../src/core/primitives.js";
|
|
||||||
|
|
||||||
describe("Default appearance", function () {
|
describe("Default appearance", function () {
|
||||||
describe("parseDefaultAppearance and createDefaultAppearance", function () {
|
describe("parseDefaultAppearance and createDefaultAppearance", function () {
|
||||||
@ -25,7 +24,7 @@ describe("Default appearance", function () {
|
|||||||
const da = "/F1 12 Tf 0.10 0.20 0.30 rg";
|
const da = "/F1 12 Tf 0.10 0.20 0.30 rg";
|
||||||
const result = {
|
const result = {
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontName: Name.get("F1"),
|
fontName: "F1",
|
||||||
fontColor: new Uint8ClampedArray([26, 51, 76]),
|
fontColor: new Uint8ClampedArray([26, 51, 76]),
|
||||||
};
|
};
|
||||||
expect(parseDefaultAppearance(da)).toEqual(result);
|
expect(parseDefaultAppearance(da)).toEqual(result);
|
||||||
@ -37,7 +36,7 @@ describe("Default appearance", function () {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontName: Name.get("F2"),
|
fontName: "F2",
|
||||||
fontColor: new Uint8ClampedArray([76, 51, 26]),
|
fontColor: new Uint8ClampedArray([76, 51, 26]),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -47,7 +46,7 @@ describe("Default appearance", function () {
|
|||||||
"q Q 0.10 0.20 0.30 rg /F1 12 Tf q 0.30 0.20 0.10 rg /F2 13 Tf Q";
|
"q Q 0.10 0.20 0.30 rg /F1 12 Tf q 0.30 0.20 0.10 rg /F2 13 Tf Q";
|
||||||
expect(parseDefaultAppearance(da)).toEqual({
|
expect(parseDefaultAppearance(da)).toEqual({
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontName: Name.get("F1"),
|
fontName: "F1",
|
||||||
fontColor: new Uint8ClampedArray([26, 51, 76]),
|
fontColor: new Uint8ClampedArray([26, 51, 76]),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user