You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2022/09/17 13:27:13 UTC

svn commit: r1904125 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java

Author: tilman
Date: Sat Sep 17 13:27:13 2022
New Revision: 1904125

URL: http://svn.apache.org/viewvc?rev=1904125&view=rev
Log:
PDFBOX-5514: case insensitive font lookup, by Oliver Schmidtmer

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java?rev=1904125&r1=1904124&r2=1904125&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java Sat Sep 17 13:27:13 2022
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.PriorityQueue;
 import java.util.Set;
@@ -57,49 +58,49 @@ final class FontMapperImpl implements Fo
     FontMapperImpl()
     {
         // substitutes for standard 14 fonts
-        substitutes.put("Courier",
+        addSubstitutes("Courier",
                 new ArrayList<String>(Arrays.asList("CourierNew", "CourierNewPSMT", "LiberationMono",
                         "NimbusMonL-Regu")));
-        substitutes.put("Courier-Bold",
+        addSubstitutes("Courier-Bold",
                 new ArrayList<String>(Arrays.asList("CourierNewPS-BoldMT", "CourierNew-Bold",
                         "LiberationMono-Bold", "NimbusMonL-Bold")));
-        substitutes.put("Courier-Oblique",
+        addSubstitutes("Courier-Oblique",
                 new ArrayList<String>(Arrays.asList("CourierNewPS-ItalicMT","CourierNew-Italic",
                         "LiberationMono-Italic", "NimbusMonL-ReguObli")));
-        substitutes.put("Courier-BoldOblique",
-                new ArrayList<String>(Arrays.asList("CourierNewPS-BoldItalicMT", 
+        addSubstitutes("Courier-BoldOblique",
+                new ArrayList<String>(Arrays.asList("CourierNewPS-BoldItalicMT",
                         "CourierNew-BoldItalic", "LiberationMono-BoldItalic",
                         "NimbusMonL-BoldObli")));
-        substitutes.put("Helvetica",
-                new ArrayList<String>(Arrays.asList("ArialMT", "Arial", "LiberationSans", 
+        addSubstitutes("Helvetica",
+                new ArrayList<String>(Arrays.asList("ArialMT", "Arial", "LiberationSans",
                         "NimbusSanL-Regu")));
-        substitutes.put("Helvetica-Bold",
+        addSubstitutes("Helvetica-Bold",
                 new ArrayList<String>(Arrays.asList("Arial-BoldMT", "Arial-Bold",
                         "LiberationSans-Bold", "NimbusSanL-Bold")));
-        substitutes.put("Helvetica-Oblique",
+        addSubstitutes("Helvetica-Oblique",
                 new ArrayList<String>(Arrays.asList("Arial-ItalicMT", "Arial-Italic",
                         "Helvetica-Italic", "LiberationSans-Italic", "NimbusSanL-ReguItal")));
-        substitutes.put("Helvetica-BoldOblique",
+        addSubstitutes("Helvetica-BoldOblique",
                 new ArrayList<String>(Arrays.asList("Arial-BoldItalicMT", "Helvetica-BoldItalic",
                         "LiberationSans-BoldItalic", "NimbusSanL-BoldItal")));
-        substitutes.put("Times-Roman",
+        addSubstitutes("Times-Roman",
                 new ArrayList<String>(Arrays.asList("TimesNewRomanPSMT", "TimesNewRoman",
                         "TimesNewRomanPS", "LiberationSerif", "NimbusRomNo9L-Regu")));
-        substitutes.put("Times-Bold",
+        addSubstitutes("Times-Bold",
                 new ArrayList<String>(Arrays.asList("TimesNewRomanPS-BoldMT", "TimesNewRomanPS-Bold",
                         "TimesNewRoman-Bold", "LiberationSerif-Bold",
                         "NimbusRomNo9L-Medi")));
-        substitutes.put("Times-Italic",
-                new ArrayList<String>(Arrays.asList("TimesNewRomanPS-ItalicMT", 
+        addSubstitutes("Times-Italic",
+                new ArrayList<String>(Arrays.asList("TimesNewRomanPS-ItalicMT",
                         "TimesNewRomanPS-Italic", "TimesNewRoman-Italic", "LiberationSerif-Italic",
                         "NimbusRomNo9L-ReguItal")));
-        substitutes.put("Times-BoldItalic",
-                new ArrayList<String>(Arrays.asList("TimesNewRomanPS-BoldItalicMT", 
+        addSubstitutes("Times-BoldItalic",
+                new ArrayList<String>(Arrays.asList("TimesNewRomanPS-BoldItalicMT",
                         "TimesNewRomanPS-BoldItalic", "TimesNewRoman-BoldItalic",
                         "LiberationSerif-BoldItalic", "NimbusRomNo9L-MediItal")));
-        substitutes.put("Symbol", 
+        addSubstitutes("Symbol",
                 new ArrayList<String>(Arrays.asList("Symbol", "SymbolMT", "StandardSymL")));
-        substitutes.put("ZapfDingbats", new ArrayList<String>(
+        addSubstitutes("ZapfDingbats", new ArrayList<String>(
                 Arrays.asList("ZapfDingbatsITCbyBT-Regular", "ZapfDingbatsITC", "Dingbats", 
                         "MS-Gothic")));
 
@@ -107,10 +108,10 @@ final class FontMapperImpl implements Fo
         // these include names such as "Arial" and "TimesNewRoman"
         for (String baseName : Standard14Fonts.getNames())
         {
-            if (!substitutes.containsKey(baseName))
+            if (getSubstitutes(baseName).isEmpty())
             {
                 String mappedName = Standard14Fonts.getMappedFontName(baseName);
-                substitutes.put(baseName, copySubstitutes(mappedName));
+                addSubstitutes(baseName, copySubstitutes(mappedName.toLowerCase(Locale.ENGLISH)));
             }
         }
         
@@ -177,7 +178,7 @@ final class FontMapperImpl implements Fo
         {
             for (String name : getPostScriptNames(info.getPostScriptName()))
             {
-                map.put(name, info);
+                map.put(name.toLowerCase(Locale.ENGLISH), info);
             }
         }
         return map;
@@ -215,11 +216,17 @@ final class FontMapperImpl implements Fo
      */
     public void addSubstitute(String match, String replace)
     {
-        if (!substitutes.containsKey(match))
+        String lowerCaseMatch = match.toLowerCase(Locale.ENGLISH);
+        if (!substitutes.containsKey(lowerCaseMatch))
         {
-            substitutes.put(match, new ArrayList<String>());
+            substitutes.put(lowerCaseMatch, new ArrayList<String>());
         }
-        substitutes.get(match).add(replace);
+        substitutes.get(lowerCaseMatch).add(replace);
+    }
+
+    private void addSubstitutes(String match, List<String> replacements)
+    {
+        substitutes.put(match.toLowerCase(Locale.ENGLISH), replacements);
     }
 
     /**
@@ -227,7 +234,7 @@ final class FontMapperImpl implements Fo
      */
     private List<String> getSubstitutes(String postScriptName)
     {
-        List<String> subs = substitutes.get(postScriptName.replace(" ", ""));
+        List<String> subs = substitutes.get(postScriptName.replace(" ", "").toLowerCase(Locale.ENGLISH));
         if (subs != null)
         {
             return subs;
@@ -476,7 +483,7 @@ final class FontMapperImpl implements Fo
         }
         
         // look up the PostScript name
-        FontInfo info = fontInfoByName.get(postScriptName);
+        FontInfo info = fontInfoByName.get(postScriptName.toLowerCase(Locale.ENGLISH));
         if (info != null && info.getFormat() == format)
         {
             if (LOG.isDebugEnabled())