Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4606,6 +4606,10 @@ class PartialEvaluator {
if (typeof italicAngle !== "number") {
italicAngle = 0;
}
let fontWeight = descriptor.get("FontWeight");
if (typeof fontWeight !== "number") {
fontWeight = 400;
}

const properties = {
type,
Expand All @@ -4630,6 +4634,7 @@ class PartialEvaluator {
capHeight,
flags,
italicAngle,
fontWeight,
isType3Font,
cssFontInfo,
scaleFactors: glyphScaleFactors,
Expand Down
10 changes: 10 additions & 0 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,16 @@ class Font {
this.fontMatrix = properties.fontMatrix;
this.bbox = properties.bbox;
this.defaultEncoding = properties.defaultEncoding;
if (typeof properties.fontWeight === "number") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to make sure that this behavior can't regress in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have rebased the branch and added a regression test, if interested

if (properties.fontWeight === 900) {
this.black = true;
} else if (properties.fontWeight >= 700) {
this.bold = true;
}
}
if (typeof properties.italicAngle === "number" && properties.italicAngle) {
this.italic = true;
}

this.toUnicode = properties.toUnicode;
this.toFontChar = [];
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,4 @@
!bug1937438_af_from_latex.pdf
!bug1937438_from_word.pdf
!bug1937438_mml_from_latex.pdf
!translated_fonts_weight.pdf
Binary file added test/pdfs/translated_fonts_weight.pdf
Binary file not shown.
40 changes: 40 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,46 @@ describe("api", function () {
await loadingTask.destroy();
});
});

describe("Fonts", function () {
it("set black/bold/italic properties to translated fonts", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("translated_fonts_weight.pdf")
);
const pdfDoc = await loadingTask.promise;
const page = await pdfDoc.getPage(1);
await page.getOperatorList();

const fontsMap = Array.from(page.commonObjs);
const fonts = fontsMap.map(entry => entry[1]);

expect(fonts[0].black).toEqual(undefined);
expect(fonts[0].bold).toEqual(undefined);
expect(fonts[0].italic).toEqual(undefined);

expect(fonts[1].black).toEqual(undefined);
expect(fonts[1].bold).toEqual(true);
expect(fonts[1].italic).toEqual(undefined);

expect(fonts[2].black).toEqual(undefined);
expect(fonts[2].bold).toEqual(undefined);
expect(fonts[2].italic).toEqual(true);

expect(fonts[3].black).toEqual(undefined);
expect(fonts[3].bold).toEqual(true);
expect(fonts[3].italic).toEqual(true);

expect(fonts[4].black).toEqual(true);
expect(fonts[4].bold).toEqual(undefined);
expect(fonts[4].italic).toEqual(undefined);

expect(fonts[5].black).toEqual(true);
expect(fonts[5].bold).toEqual(undefined);
expect(fonts[5].italic).toEqual(true);

await loadingTask.destroy();
});
});
});

describe("Page", function () {
Expand Down
Loading