configure.ac                 |   19 +++++++++++++-
 src/Makefile.am              |    4 ++
 src/lib/MSPUBCollector.cpp   |    5 +--
 src/test/.gitignore          |    8 +++++
 src/test/Makefile.am         |   26 +++++++++++++++++++
 src/test/data/fdo59355-1.pub |binary
 src/test/importtest.cpp      |   58 +++++++++++++++++++++++++++++++++++++++++++
 src/test/test.cpp            |   36 ++++++++++++++++++++++++++
 8 files changed, 152 insertions(+), 4 deletions(-)

New commits:
commit 9b32c97796db2cb01ecc8cfc78afaad5908289cd
Author:     Miodrag Obradovic <[email protected]>
AuthorDate: Wed Oct 14 11:05:30 2026 +0200
Commit:     Ilmari Lauhakangas <[email protected]>
CommitDate: Wed Nov 4 15:07:08 2026 +0100

    related tdf#160489 pass font size in points
    
    fo:font-size was inserted as a bare double, i.e. in inches. The ODF
    generator writes it with its unit, but pub2xhtml's SVG generator takes
    the number as is, so the 28.7 pt "ADVERTISEMENT HEADING" in the bug's
    attachment became font-size="0.3986" and the text in the SVG was too
    small to see.
    
    Insert the size in points, as libvisio and libcdr do. LibreOffice
    renders the Apache POI publisher samples and the bug's attachment
    pixel-identical before and after; in the SVG the text now has its real
    size. Line breaks and alignment inside text boxes are still missing in
    the SVG output, that part of the bug is in the SVG generator.
    
    libmspub had no unit tests, so this adds a CppUnit setup like
    libvisio's (configure --enable-tests, then make check) and one test
    that converts fdo59355-1.pub to SVG. That file is a single 10 pt text
    box from LibreOffice's writerperfect test data. Without the fix the
    test fails with "Expected: 10, Actual: 0.1389". Tests are off by
    default because LibreOffice's build of libmspub does not pass
    --disable-tests.
    
    Fix and test written with the help of Claude Opus 5.5 agent mode.
    
    Change-Id: I7810f70fe4021ebb9339deda6a8c27a218a2105b
    Reviewed-on: https://gerrit.libreoffice.org/c/libmspub/+/212269
    Tested-by: Hossein <[email protected]>
    Reviewed-by: Hossein <[email protected]>

diff --git a/configure.ac b/configure.ac
index e79c007..3f41080 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,7 +68,22 @@ AC_ARG_ENABLE([fuzzers],
 )
 AM_CONDITIONAL(BUILD_FUZZERS, [test "x$enable_fuzzers" = "xyes"])
 
-AS_IF([test "x$enable_tools" = "xyes" -o "x$enable_fuzzers" = "xyes"], [
+# =====
+# Tests
+# =====
+AC_ARG_ENABLE([tests],
+       [AS_HELP_STRING([--enable-tests], [Build and run unit tests])],
+       [enable_tests="$enableval"],
+       [enable_tests=no]
+)
+AS_IF([test "x$enable_tests" = "xyes"], [
+       PKG_CHECK_MODULES([CPPUNIT],[cppunit])
+])
+AC_SUBST([CPPUNIT_CFLAGS])
+AC_SUBST([CPPUNIT_LIBS])
+AM_CONDITIONAL(ENABLE_TESTS, [test "x$enable_tests" = "xyes"])
+
+AS_IF([test "x$enable_tools" = "xyes" -o "x$enable_fuzzers" = "xyes" -o 
"x$enable_tests" = "xyes"], [
        PKG_CHECK_MODULES([REVENGE_STREAM],[
                librevenge-stream-0.0
        ])
@@ -300,6 +315,7 @@ src/conv/svg/pub2xhtml.rc
 src/fuzz/Makefile
 src/lib/Makefile
 src/lib/libmspub.rc
+src/test/Makefile
 inc/Makefile
 inc/libmspub/Makefile
 build/Makefile
@@ -319,6 +335,7 @@ Build configuration:
        debug:           ${enable_debug}
        docs:            ${build_docs}
        fuzzers:         ${enable_fuzzers}
+       tests:           ${enable_tests}
        tools:           ${enable_tools}
        werror:          ${enable_werror}
 ==============================================================================
diff --git a/src/Makefile.am b/src/Makefile.am
index c83c78c..3a73c20 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,3 +7,7 @@ endif
 if BUILD_FUZZERS
 SUBDIRS += fuzz
 endif
+
+if ENABLE_TESTS
+SUBDIRS += test
+endif
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index f83ed22..0adb1fd 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -1666,12 +1666,11 @@ librevenge::RVNGPropertyList 
MSPUBCollector::getCharStyleProps(const CharacterSt
     ret.insert("fo:text-scale", get(defaultCharStyle.textScale), 
librevenge::RVNG_PERCENT);
   if (bool(style.textSizeInPt))
   {
-    ret.insert("fo:font-size", style.textSizeInPt.get() / POINTS_IN_INCH);
+    ret.insert("fo:font-size", style.textSizeInPt.get(), 
librevenge::RVNG_POINT);
   }
   else if (bool(defaultCharStyle.textSizeInPt))
   {
-    ret.insert("fo:font-size", defaultCharStyle.textSizeInPt.get()
-               / POINTS_IN_INCH);
+    ret.insert("fo:font-size", defaultCharStyle.textSizeInPt.get(), 
librevenge::RVNG_POINT);
   }
   if (style.colorIndex >= 0 && (size_t)style.colorIndex < m_textColors.size())
   {
diff --git a/src/test/.gitignore b/src/test/.gitignore
new file mode 100644
index 0000000..43932e5
--- /dev/null
+++ b/src/test/.gitignore
@@ -0,0 +1,8 @@
+.deps
+.libs
+*.log
+*.o
+*.trs
+Makefile
+Makefile.in
+importtest
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
new file mode 100644
index 0000000..4616ea5
--- /dev/null
+++ b/src/test/Makefile.am
@@ -0,0 +1,26 @@
+tests = importtest
+
+check_PROGRAMS = $(tests)
+
+importtest_CPPFLAGS = \
+       -DTDOC=\"$(top_srcdir)/src/test/data\" \
+       -I$(top_srcdir)/inc \
+       $(REVENGE_CFLAGS) \
+       $(REVENGE_STREAM_CFLAGS) \
+       $(CPPUNIT_CFLAGS) \
+       $(DEBUG_CXXFLAGS)
+
+importtest_LDADD = \
+       
$(top_builddir)/src/lib/libmspub-@MSPUB_MAJOR_VERSION@.@[email protected] 
\
+       $(REVENGE_LIBS) \
+       $(REVENGE_STREAM_LIBS) \
+       $(CPPUNIT_LIBS)
+
+importtest_SOURCES = \
+       importtest.cpp \
+       test.cpp
+
+EXTRA_DIST = \
+       data/fdo59355-1.pub
+
+TESTS = $(tests)
diff --git a/src/test/data/fdo59355-1.pub b/src/test/data/fdo59355-1.pub
new file mode 100644
index 0000000..607a07a
Binary files /dev/null and b/src/test/data/fdo59355-1.pub differ
diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp
new file mode 100644
index 0000000..6e6c1f7
--- /dev/null
+++ b/src/test/importtest.cpp
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libmspub 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 <cstdlib>
+#include <string>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <librevenge/librevenge.h>
+#include <librevenge-stream/librevenge-stream.h>
+#include <libmspub/libmspub.h>
+
+namespace
+{
+
+/// Converts a test document to SVG the way pub2xhtml does and returns the 
first page.
+std::string convertToSVG(const char *filename)
+{
+  librevenge::RVNGFileStream input((std::string(TDOC "/") + filename).c_str());
+  CPPUNIT_ASSERT(libmspub::MSPUBDocument::isSupported(&input));
+  librevenge::RVNGStringVector pages;
+  librevenge::RVNGSVGDrawingGenerator generator(pages, "svg");
+  CPPUNIT_ASSERT(libmspub::MSPUBDocument::parse(&input, &generator));
+  CPPUNIT_ASSERT(!pages.empty());
+  return pages[0].cstr();
+}
+
+}
+
+class ImportTest : public CPPUNIT_NS::TestFixture
+{
+  CPPUNIT_TEST_SUITE(ImportTest);
+  CPPUNIT_TEST(testFontSizeInPoints);
+  CPPUNIT_TEST_SUITE_END();
+
+  void testFontSizeInPoints();
+};
+
+void ImportTest::testFontSizeInPoints()
+{
+  // tdf#160489 the SVG generator writes fo:font-size as a bare number, so the
+  // 10 pt text in this file used to come out as font-size="0.1389"
+  const std::string svg = convertToSVG("fdo59355-1.pub");
+  const std::string attribute("font-size=\"");
+  const std::string::size_type pos = svg.find(attribute);
+  CPPUNIT_ASSERT(pos != std::string::npos);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, std::atof(svg.c_str() + pos + 
attribute.size()), 0.001);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest);
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/test/test.cpp b/src/test/test.cpp
new file mode 100644
index 0000000..c690f1a
--- /dev/null
+++ b/src/test/test.cpp
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libmspub 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 <iostream>
+#include <cppunit/TestRunner.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/CompilerOutputter.h>
+
+int main()
+{
+  CPPUNIT_NS::TestResult controller;
+  CPPUNIT_NS::TestResultCollector result;
+  controller.addListener(&result);
+  CPPUNIT_NS::BriefTestProgressListener progress;
+  controller.addListener(&progress);
+
+  CPPUNIT_NS::TestRunner runner;
+  runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
+  runner.run(controller);
+
+  CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr);
+  outputter.write();
+
+  return result.wasSuccessful() ? 0 : 1;
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Reply via email to