summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2016-12-21 20:16:14 +0200
committerKhaled Hosny <khaledhosny@eglug.org>2016-12-25 00:37:30 +0000
commitf16d17df9d33ad96d053abe2d9212b0c2850c19f (patch)
tree1b5c64b49b09a3b7c3a75120b59ccd7e03a31c21 /vcl
parent85a621be87c88d8c317eb0fa296ae64f2b3253a5 (diff)
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@libreoffice.org> Reviewed-by: Khaled Hosny <khaledhosny@eglug.org>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/font/PhysicalFontCollection.cxx35
1 files changed, 32 insertions, 3 deletions
diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx
index 3a7da5921b62..f0249c081500 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