Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pdfjs.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"stableVersion": "5.4.449",
"stableVersion": "5.4.530",
"baseVersion": "1b427a3af5e0a40c296a3cafb08edbd36d973ff1",
"versionPrefix": "5.4."
}
3 changes: 3 additions & 0 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class CFFParser {
const charStringOffset = topDict.getByName("CharStrings");
const charStringIndex = this.parseIndex(charStringOffset).obj;

cff.charStringCount = charStringIndex.count;

const fontMatrix = topDict.getByName("FontMatrix");
if (fontMatrix) {
properties.fontMatrix = fontMatrix;
Expand Down Expand Up @@ -1005,6 +1007,7 @@ class CFF {
this.fdSelect = null;

this.isCIDFont = false;
this.charStringCount = 0;
}

duplicateFirstGlyph() {
Expand Down
60 changes: 30 additions & 30 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import { CFFFont } from "./cff_font.js";
import { FontRendererFactory } from "./font_renderer.js";
import { getFontBasicMetrics } from "./metrics.js";
import { GlyfTable } from "./glyf.js";
import { IdentityCMap } from "./cmap.js";
import { OpenTypeFileBuilder } from "./opentype_file_builder.js";
import { readUint32 } from "./core_utils.js";
import { Stream } from "./stream.js";
Expand Down Expand Up @@ -2638,27 +2637,23 @@ class Font {
header = readOpenTypeHeader(font);
tables = readTables(font, header.numTables);
}
let cff, cffFile;

const isTrueType = !tables["CFF "];
if (!isTrueType) {
const isComposite =
properties.composite &&
(properties.cidToGidMap?.length > 0 ||
!(properties.cMap instanceof IdentityCMap));
// OpenType font (skip composite fonts with non-default glyph mapping).
if (
(header.version === "OTTO" && !isComposite) ||
(header.version === "OTTO" && !properties.composite) ||
!tables.head ||
!tables.hhea ||
!tables.maxp ||
!tables.post
) {
// No major tables: throwing everything at `CFFFont`.
cffFile = new Stream(tables["CFF "].data);
cff = new CFFFont(cffFile, properties);

return this.convert(name, cff, properties);
return this.convert(
name,
new CFFFont(new Stream(tables["CFF "].data), properties),
properties
);
}

delete tables.glyf;
Expand Down Expand Up @@ -2686,9 +2681,32 @@ class Font {
throw new FormatError('Required "maxp" table is not found');
}

let numGlyphsFromCFF;
if (!isTrueType) {
try {
// Trying to repair CFF file
const parser = new CFFParser(
new Stream(tables["CFF "].data),
properties,
SEAC_ANALYSIS_ENABLED
);
const cff = parser.parse();
cff.duplicateFirstGlyph();
const compiler = new CFFCompiler(cff);
tables["CFF "].data = compiler.compile();
numGlyphsFromCFF = cff.charStringCount;
} catch {
warn("Failed to compile font " + properties.loadedName);
}
}

font.pos = (font.start || 0) + tables.maxp.offset;
let version = font.getInt32();
const numGlyphs = font.getUint16();
const numGlyphs = numGlyphsFromCFF ?? font.getUint16();
if (version === 0x00005000 && tables.maxp.length !== 6) {
tables.maxp.data = tables.maxp.data.subarray(0, 6);
tables.maxp.length = 6;
}

if (version !== 0x00010000 && version !== 0x00005000) {
// https://learn.microsoft.com/en-us/typography/opentype/spec/maxp
Expand Down Expand Up @@ -3099,24 +3117,6 @@ class Font {
}
}

if (!isTrueType) {
try {
// Trying to repair CFF file
cffFile = new Stream(tables["CFF "].data);
const parser = new CFFParser(
cffFile,
properties,
SEAC_ANALYSIS_ENABLED
);
cff = parser.parse();
cff.duplicateFirstGlyph();
const compiler = new CFFCompiler(cff);
tables["CFF "].data = compiler.compile();
} catch {
warn("Failed to compile font " + properties.loadedName);
}
}

// Re-creating 'name' table
if (!tables.name) {
tables.name = {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue18062.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/15274065/1.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13123,5 +13123,13 @@
"rounds": 1,
"link": true,
"type": "eq"
},
{
"id": "issue18062",
"file": "pdfs/issue18062.pdf",
"md5": "b8fb6d5622f0a2f45be8e26da7de969c",
"rounds": 1,
"link": true,
"type": "eq"
}
]
Loading