Skip to content

Commit

Permalink
Fix the font alias name to lower case handling (#1385) (#1485)
Browse files Browse the repository at this point in the history
* Fix the font alias name to lower case handling (#1385)

* Improved loop handling of merge method
  • Loading branch information
speckyspooky authored Nov 5, 2023
1 parent 3f1bfd7 commit eacaa00
Showing 1 changed file with 69 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,60 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
* Font mapping configuration class
*
* @since 3.3
*
*/
public class FontMappingConfig {

protected Set fontPaths = new HashSet();
protected Set<String> fontPaths = new HashSet<String>();

/** The font-family replacement */
protected HashMap fontAliases = new HashMap();
protected HashMap<String, String> fontAliases = new HashMap<String, String>();

/** The encoding for the fonts */
protected HashMap fontEncodings = new HashMap();
protected HashMap<String, String> fontEncodings = new HashMap<String, String>();

/** the global sequences defined for composite fonts */
protected HashMap searchSequences = new HashMap();
protected HashMap<String, String[]> searchSequences = new HashMap<String, String[]>();

/**
* composite fonts is constructed by multiple physical fonts which may cover
* large amount of glyph
*/
protected HashMap compositeFonts = new HashMap();
protected HashMap<String, CompositeFontConfig> compositeFonts = new HashMap<String, CompositeFontConfig>();

/**
* Constructor
*/
public FontMappingConfig() {
}

/**
* merge the font configuration to the existing font setup
*
* @param config font mapping configuration
*/
public void merge(FontMappingConfig config) {
fontPaths.addAll(config.fontPaths);
fontAliases.putAll(config.fontAliases);

// merge alias fonts, special handling in addFontAlias()
for (Map.Entry<String, String> fontAliasEntry : config.fontAliases.entrySet()) {
this.addFontAlias(fontAliasEntry.getKey(), fontAliasEntry.getValue());
}
fontEncodings.putAll(config.fontEncodings);
searchSequences.putAll(config.searchSequences);

// merge the composite fonts
Iterator iter = config.compositeFonts.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String fontName = (String) entry.getKey();
CompositeFontConfig newConfig = (CompositeFontConfig) entry.getValue();
CompositeFontConfig oldConfig = (CompositeFontConfig) compositeFonts.get(fontName);
for (Map.Entry<String, CompositeFontConfig> compositeFontEntry : config.compositeFonts.entrySet()) {
String fontName = compositeFontEntry.getKey();
CompositeFontConfig newConfig = compositeFontEntry.getValue();
CompositeFontConfig oldConfig = compositeFonts.get(fontName);
if (oldConfig != null) {
oldConfig.merge(newConfig);
} else {
Expand All @@ -64,33 +79,69 @@ public void merge(FontMappingConfig config) {
}
}

/**
* Add the font path to the path map
*
* @param fontPath font path
*/
public void addFontPath(String fontPath) {
fontPaths.add(fontPath);
}

/** The font-family replacement */
/**
* The font-family replacement
*
* @param alias alias name of the font
* @param fontName original font name
*/
public void addFontAlias(String alias, String fontName) {
fontAliases.put(alias, fontName);
fontAliases.put(alias.toLowerCase(), fontName);
}

/** The encoding for the fonts */
/**
* The encoding for the fonts
*
* @param fontName font name
* @param fontEncoding font encoding
*/
public void addFontEncoding(String fontName, String fontEncoding) {
fontEncodings.put(fontName, fontEncoding);
}

/**
* Add search sequence of font
*
* @param localeKey local key
* @param sequence search sequence
*/
public void addSearchSequence(String localeKey, String[] sequence) {
searchSequences.put(localeKey, sequence);
}

public Map getSearchSequences() {
/**
* Get the map of the search sequences of the fonts
*
* @return Return the map of the search sequences of the fontsReturn
*/
public HashMap<String, String[]> getSearchSequences() {
return searchSequences;
}

/**
* Add the composite font
*
* @param fontConfig composite font configuration
*/
public void addCompositeFont(CompositeFontConfig fontConfig) {
compositeFonts.put(fontConfig.fontName, fontConfig);
}

public Collection getAllCompositeFonts() {
/**
* Get all composite fonts
*
* @return Return all composite fonts
*/
public Collection<CompositeFontConfig> getAllCompositeFonts() {
return compositeFonts.values();
}
}

0 comments on commit eacaa00

Please sign in to comment.