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
33 changes: 31 additions & 2 deletions src/main/java/org/verapdf/pd/font/PDFontDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.verapdf.cos.*;
import org.verapdf.pd.PDObject;
import org.verapdf.pd.font.stdmetrics.StandardFontMetrics;
import org.verapdf.tools.FontConstants;

import java.util.Iterator;
import java.util.Map;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -122,6 +122,35 @@ public String getFontFamily() {
return fontFamily;
}

public static String extractFontFamilyFromFontName(String fontNameWithoutSubset) {
if (fontNameWithoutSubset == null || fontNameWithoutSubset.isEmpty()) return null;

String name = fontNameWithoutSubset.trim();
name = name.replaceAll("\\*\\d+", "");
Comment thread
coderabbitai[bot] marked this conversation as resolved.

boolean changed = true;
while (changed) {
changed = false;
for (String suffix : FontConstants.STYLE_SUFFIXES) {
String lowerName = name.toLowerCase();
String lowerSuffix = suffix.toLowerCase();
if (lowerName.endsWith(lowerSuffix)) {
name = name.substring(0, name.length() - suffix.length());
if (name.endsWith("-")) {
name = name.substring(0, name.length() - 1);
}
changed = true;
break;
}
}
}

String spaced = name.replaceAll("([a-z])([A-Z])", "$1 $2");
spaced = spaced.trim().replaceAll("\\s+", " ");

return spaced.isEmpty() ? null : spaced;
}

/**
* @return the font stretch value.
*/
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/org/verapdf/tools/FontConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.verapdf.tools;

import java.util.Arrays;
import java.util.List;

public class FontConstants {
public static final List<String> STYLE_SUFFIXES = Arrays.asList(
// ---- Weight ----
"Hairline", "Thin",
"ExtraLight", "ExtLt", "Extra Light", "Extra-Light",
"UltraLight", "UltLt", "Ultra Light", "Ultra-Light",
"Light", "Lt",
"Book",
"Normal",
"Regular", "Rg", "Roman",
"Medium", "Md",
"Demi", "DemiBold", "Demi Bold", "Demi-Bold",
"SemiBold", "Semibold", "SemiBd", "Semi Bold", "Semi-Bold",
"Bold", "Bd",
"ExtraBold", "ExtBd", "Extra Bold", "Extra-Bold",
"UltraBold", "UltBd", "Ultra Bold", "Ultra-Bold",
"Black", "Blk",
"Heavy", "Hv",
"Ultra", "Fat", "Poster",

// ---- Slope ----
"Italic", "Ita", "It",
"Oblique", "Obl", "Caps", "CapsI",
"Backslant",

// ---- Width ----
"Compressed",
"ExtraCondensed", "UltraCondensed",
"Condensed", "Cond", "Cn",
"SemiCondensed",
"Narrow",
"SemiExpanded",
"Expanded", "Exp", "Extended",
"ExtraExpanded", "UltraExpanded",
"Wide",

// ---- Optical size ----
"Caption", "Text", "Subhead", "Deck", "Display", "Titling",

// ---- Weight + Italic/Oblique (common combinations) ----
"ThinItalic", "ThinIt",
"LightItalic", "LightOblique", "LightIt",
"BookItalic", "BookOblique",
"MediumItalic", "MediumOblique", "MediumIt",
"DemiItalic", "DemiOblique",
"SemiBoldItalic", "SemiboldItalic", "SemiBoldIt", "SemiboldIt",
"BoldItalic", "BoldIt", "BoldOblique", "BoldObl",
"ExtraBoldItalic", "ExtraBoldIt",
"BlackItalic", "BlackIt", "HeavyItalic",

// ---- Width + Weight / Slope (common combos) ----
"BoldCondensed", "BoldCond", "BoldCn",
"BoldExpanded", "BoldExp", "BoldExtended",
"BoldSemiExt", "SemiExt",
"LightCondensed", "LightCond",
"MediumCondensed", "MediumCond",
"CondensedBold", "CondBold",
"CondensedLight",
"ExpandedBold", "ExtendedBold",

// ---- SmallCaps & other variants ----
"SmallCaps", "SC", "PetiteCaps",
"RomanSmallCaps",
"BoldSmallCaps",
"Inline", "Outline", "Shadow",
"Engraved", "Stencil", "Swash",
"SuppSwashCaps", "SwashCaps",
"Ornaments", "Symbols", "Icons", "Supp", "Small",

// ---- Foundry / vendor tags ----
"Std", "MT", "PS", "LT", "Com", "W1G", "EF", "CE"
);
}
Loading