Skip to content

Commit

Permalink
Add warning about duplicated glyph name
Browse files Browse the repository at this point in the history
in CFFType1FontProgram
  • Loading branch information
MaximPlusov committed Dec 22, 2023
1 parent 631c3f1 commit 7938f8f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main/java/org/verapdf/pd/font/cff/CFFType1FontProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Instance of this class represent a Type1 font from FontSet of
Expand All @@ -35,6 +37,10 @@
*/
public class CFFType1FontProgram extends CFFFontBaseParser implements FontProgram {

private static final Logger LOGGER = Logger.getLogger(CFFType1FontProgram.class.getCanonicalName());

private static final String DUPLICATED_GLYPH_NAME_MESSAGE = "CFF Type1 FontProgram contains duplicated glyph name %s";

private static final String NOTDEF_STRING = ".notdef";

private final CMap externalCMap; // in case if font is embedded into Type0 font
Expand Down Expand Up @@ -181,8 +187,12 @@ private void readCharSet() throws IOException {
case 0:
for (int i = 1; i < nGlyphs; ++i) {
int sid = this.readCard16();
this.charSet.put(this.getStringBySID(sid), i);
this.inverseCharSet.put(i, this.getStringBySID(sid));
String stringBySID = this.getStringBySID(sid);
if (charSet.containsKey(stringBySID)) {
LOGGER.log(Level.WARNING, String.format(DUPLICATED_GLYPH_NAME_MESSAGE, stringBySID));
}
this.charSet.put(stringBySID, i);
this.inverseCharSet.put(i, stringBySID);
}
break;
case 1:
Expand All @@ -198,10 +208,12 @@ private void readCharSet() throws IOException {
nLeft = this.readCard16();
}
for (int i = 0; i <= nLeft; ++i) {
this.charSet.put(this.getStringBySID(first + i),
charSetPointer);
this.inverseCharSet.put(charSetPointer++,
this.getStringBySID(first + i));
String stringBySID = this.getStringBySID(first + i);
if (charSet.containsKey(stringBySID)) {
LOGGER.log(Level.WARNING, String.format(DUPLICATED_GLYPH_NAME_MESSAGE, stringBySID));
}
this.charSet.put(stringBySID, charSetPointer);
this.inverseCharSet.put(charSetPointer++, stringBySID);
}
}
} catch (ArrayIndexOutOfBoundsException e) {
Expand Down

0 comments on commit 7938f8f

Please sign in to comment.