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>
This commit is contained in:
Khaled Hosny 2016-12-21 20:16:14 +02:00
parent 85a621be87
commit f16d17df9d

View file

@ -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