Skip to content

Commit

Permalink
Use widths defined by font for standard fonts.
Browse files Browse the repository at this point in the history
There doesn't seem to be anything definitive about this in
the spec, but from experimenting, it seems acrobat let's
PDF's override the widths of the standard fonts.
  • Loading branch information
brendandahl committed Dec 10, 2020
1 parent 00b4f86 commit ae181d3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,11 +1319,12 @@ var Font = (function FontClosure() {
let fontName = name.replace(/[,_]/g, "-").replace(/\s/g, "");
var stdFontMap = getStdFontMap(),
nonStdFontMap = getNonStdFontMap();
var isStandardFont =
!!stdFontMap[fontName] ||
!!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
const isStandardFont = !!stdFontMap[fontName];
const isMappedToStandardFont = !!(
nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]
);

fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
this.bold = fontName.search(/bold/gi) !== -1;
this.italic =
fontName.search(/oblique/gi) !== -1 ||
Expand All @@ -1334,9 +1335,9 @@ var Font = (function FontClosure() {
this.black = name.search(/Black/g) !== -1;

// if at least one width is present, remeasure all chars when exists
this.remeasure = Object.keys(this.widths).length > 0;
this.remeasure = !isStandardFont && Object.keys(this.widths).length > 0;
if (
isStandardFont &&
(isStandardFont || isMappedToStandardFont) &&
type === "CIDFontType2" &&
this.cidEncoding.startsWith("Identity-")
) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
!issue6298.pdf
!issue6889.pdf
!bug1001080.pdf
!bug1671312_reduced.pdf
!issue6108.pdf
!issue6113.pdf
!openoffice.pdf
Expand Down
Binary file added test/pdfs/bug1671312_reduced.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,12 @@
"link": false,
"type": "text"
},
{ "id": "bug1671312_reduced",
"file": "pdfs/bug1671312_reduced.pdf",
"md5": "db13fe3f03a7d0bd0e248f5c2bcb2a5d",
"rounds": 1,
"type": "eq"
},
{ "id": "issue7020",
"file": "pdfs/issue7020.pdf",
"md5": "93b464e21c649e64ae92eeafe99fc31b",
Expand Down

0 comments on commit ae181d3

Please sign in to comment.