vcl/CppunitTest_vcl_unx_generic.mk         |   60 +++++++++++++++++++++++++++++
 vcl/Module_vcl.mk                          |    8 +++
 vcl/qa/unx/generic/generic.cxx             |   60 +++++++++++++++++++++++++++++
 vcl/unx/generic/fontmanager/fontconfig.cxx |   16 +++++++
 4 files changed, 144 insertions(+)

New commits:
commit e621b6fefef307048c035298649e7cc5159945ae
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Jul 18 15:35:49 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jul 22 19:57:47 2024 +0200

    tdf#162072 vcl, fontconfig: consider font-family-generic for substitute
    
    Open the bugdoc, it has two paragraphs: first with a sans font, second
    with a serif font. These fonts are missing, but their metadata clearly
    state that they are sans vs serif. Still, Writer renders both as sans.
    
    Investigating a bit, the ODT case imports the "font-family-generic" of
    these fonts fine, but in the Linux case the fontconfig code ignored this
    info when building the search pattern for the font fallback.
    
    Fix the problem by extending vcl's PrintFontManager::Substitute() to
    also take the vcl-level "family type" into account, which is about sans
    vs serif (roman vs swiss). Note that FC_FAMILY is a string list, so once
    the actual font name is added to the pattern, the next "add" will append
    to this list, not drop the already added font name.
    
    The same problem is still there with the DOCX equivalent.
    
    Change-Id: I61f31ae73e524471a5261ac9426e5b566454a09c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170681
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 6dfac38bacd449c64a13363797b56aff49cf8f52)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170661
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/vcl/CppunitTest_vcl_unx_generic.mk 
b/vcl/CppunitTest_vcl_unx_generic.mk
new file mode 100644
index 000000000000..231be2aec7ec
--- /dev/null
+++ b/vcl/CppunitTest_vcl_unx_generic.mk
@@ -0,0 +1,60 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_unx_generic))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_unx_generic,\
+    boost_headers \
+    harfbuzz \
+))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_unx_generic,\
+    -I$(SRCDIR)/vcl/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_unx_generic, \
+    vcl/qa/unx/generic/generic \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_unx_generic, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    subsequenttest \
+    test \
+    tl \
+    unotest \
+    utl \
+    vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_unx_generic))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_unx_generic))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_unx_generic))
+
+$(eval $(call gb_CppunitTest_use_rdb,vcl_unx_generic,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,vcl_unx_generic,\
+       officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_unx_generic))
+
+# Note that this is intentionally 'deny' and not 'abort', so we allow font 
fallback (we want to to
+# test that code), but we want predictable results, so not considering system 
fonts.
+$(eval $(call 
gb_CppunitTest_set_non_application_font_use,vcl_unx_generic,deny))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,vcl_unx_generic))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 35c6427b4ed1..c0a624acdc95 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -293,4 +293,12 @@ $(eval $(call gb_Module_add_slowcheck_targets,vcl,\
 ))
 endif
 
+ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),)
+ifeq ($(OS),LINUX)
+$(eval $(call gb_Module_add_slowcheck_targets,vcl,\
+    CppunitTest_vcl_unx_generic \
+))
+endif
+endif
+
 # vim: set noet sw=4 ts=4:
diff --git a/vcl/qa/unx/generic/generic.cxx b/vcl/qa/unx/generic/generic.cxx
new file mode 100644
index 000000000000..60f91266e067
--- /dev/null
+++ b/vcl/qa/unx/generic/generic.cxx
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/unoapi_test.hxx>
+
+#include <vcl/font.hxx>
+
+#include <font/FontSelectPattern.hxx>
+#include <unx/fontmanager.hxx>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+/// Covers vcl/unx/generic/ fixes.
+class Test : public UnoApiTest
+{
+public:
+    Test()
+        : UnoApiTest(u"/vcl/qa/unx/generic/data/"_ustr)
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testFontFallbackSerif)
+{
+    // Given a font select pattern with a font name we don't bundle and with a 
serif family:
+    vcl::Font aFont;
+    aFont.SetFamilyName("IBM Plex Serif");
+    aFont.SetFamily(FAMILY_ROMAN);
+    Size aSize(0, 3840);
+    float fExactHeight = 3840;
+    bool bNonAntialias = false;
+    vcl::font::FontSelectPattern aPattern(aFont, aFont.GetFamilyName(), aSize, 
fExactHeight,
+                                          bNonAntialias);
+    aPattern.maTargetName = aFont.GetFamilyName();
+    psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
+    OUString aMissingCodes;
+
+    // When substituting that font:
+    rMgr.Substitute(aPattern, aMissingCodes);
+
+    // Then make sure we get a serif fallback:
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: Noto Serif (or DejaVu Serif)
+    // - Actual  : Noto Kufi Arabic
+    // i.e. we got a sans fallback for a serif pattern, which is clearly poor.
+    CPPUNIT_ASSERT(aPattern.maSearchName.endsWith(u"Serif"));
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx 
b/vcl/unx/generic/fontmanager/fontconfig.cxx
index ceb4b2b1be58..2bd59dc2d348 100644
--- a/vcl/unx/generic/fontmanager/fontconfig.cxx
+++ b/vcl/unx/generic/fontmanager/fontconfig.cxx
@@ -984,6 +984,22 @@ void 
PrintFontManager::Substitute(vcl::font::FontSelectPattern &rPattern, OUStri
     const FcChar8* pTargetNameUtf8 = reinterpret_cast<FcChar8 const 
*>(aTargetName.getStr());
     FcPatternAddString(pPattern, FC_FAMILY, pTargetNameUtf8);
 
+    // Try to map tools FontFamily to fontconfig FC_FAMILY. Note that 
FcPatternAddString() appends
+    // to a list, so it won't overwrite the previous 
FcPatternAddString(FC_FAMILY), this way we can
+    // express that we wanted a certain font, and otherwise a given family 
style.
+    FontFamily eFamilyType = rPattern.GetFamilyType();
+    switch (eFamilyType)
+    {
+        case FAMILY_ROMAN:
+            FcPatternAddString(pPattern, FC_FAMILY, reinterpret_cast<const 
FcChar8*>("serif"));
+            break;
+        case FAMILY_SWISS:
+            FcPatternAddString(pPattern, FC_FAMILY, reinterpret_cast<const 
FcChar8*>("sans"));
+            break;
+        default:
+            break;
+    }
+
     LanguageTag aLangTag(rPattern.meLanguage);
     OString aLangAttrib = mapToFontConfigLangTag(aLangTag);
 

Reply via email to