[Libreoffice-commits] core.git: vcl/source

Khaled Hosny khaledhosny at eglug.org
Sun Dec 25 00:37:51 UTC 2016


 vcl/source/font/PhysicalFontCollection.cxx |   35 ++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

New commits:
commit f16d17df9d33ad96d053abe2d9212b0c2850c19f
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Wed Dec 21 20:16:14 2016 +0200

    Make sure we use bundled metric-compatible fonts
    
    We were relying on FontConfig knowing about these replacements, but this
    does not work on Mac and might not even work on Linux if FontConfig is
    not configured to know these replacements. Since we bundle these fonts,
    we better making sure they end up being used.
    
    Change-Id: I26e72e8d1e5c902132e1260791e20017a92a5475
    Reviewed-on: https://gerrit.libreoffice.org/32299
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Khaled Hosny <khaledhosny at eglug.org>

diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx
index 3a7da59..f0249c0 100644
--- a/vcl/source/font/PhysicalFontCollection.cxx
+++ b/vcl/source/font/PhysicalFontCollection.cxx
@@ -17,6 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <map>
+
 #include <i18nlangtag/mslangid.hxx>
 #include <unotools/configmgr.hxx>
 #include <unotools/fontdefs.hxx>
@@ -968,6 +970,33 @@ ImplDeviceFontSizeList* PhysicalFontCollection::GetDeviceFontSizeList( const OUS
     return pDeviceFontSizeList;
 }
 
+// These are the metric-compatible replacement fonts that are bundled with
+// LibreOffice, we prefer them over generic substitutions that might be
+// provided by the system.
+static const std::map<OUString, OUString> aMetricCompatibleMap =
+{
+    { "Times New Roman", "Liberation Serif" },
+    { "Arial",           "Liberation Sans" },
+    { "Arial Narrow",    "Liberation Sans Narrow" },
+    { "Courier New",     "Liberation Mono" },
+    { "Cambria",         "Caladea" },
+    { "Calibri",         "Carlito" },
+};
+
+static bool FindMetricCompatibleFont(FontSelectPattern& rFontSelData)
+{
+    for (const auto& aSub : aMetricCompatibleMap)
+    {
+        if (rFontSelData.maSearchName == GetEnglishSearchFontName(aSub.first))
+        {
+            rFontSelData.maSearchName = aSub.second;
+            return true;
+        }
+    }
+
+    return false;
+}
+
 PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& rFSD ) const
 {
     // give up if no fonts are available
@@ -1053,10 +1082,10 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r
                 return pFoundData;
         }
 
-        if( mpPreMatchHook )
+        if (FindMetricCompatibleFont(rFSD) ||
+            (mpPreMatchHook && mpPreMatchHook->FindFontSubstitute(rFSD)))
         {
-            if( mpPreMatchHook->FindFontSubstitute( rFSD ) )
-                aSearchName = GetEnglishSearchFontName( aSearchName );
+            aSearchName = GetEnglishSearchFontName(aSearchName);
         }
 
         // the prematch hook uses the target name to search, but we now need


More information about the Libreoffice-commits mailing list