[Libreoffice-commits] core.git: sw/CppunitTest_sw_odfexport.mk sw/qa xmloff/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Nov 28 18:33:16 UTC 2017


 sw/CppunitTest_sw_odfexport.mk                      |    5 +
 sw/qa/extras/odfexport/data/embedded-font-props.odt |binary
 sw/qa/extras/odfexport/odfexport.cxx                |   20 +++++
 xmloff/source/style/XMLFontAutoStylePool.cxx        |   70 +++++++++++++++++---
 4 files changed, 87 insertions(+), 8 deletions(-)

New commits:
commit 9914ca04ac6a63f14adcd0fe58b2be44b84ee15f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 28 14:27:59 2017 +0100

    ODF export: expose font style and weight of embedded fonts
    
    We don't need this info ourselves, but when converting the flat ODF
    output to other formats, this information is hard to find out, so state
    them explicitly. Names correspond to existing CSS ones, where it's
    necessary to state these explicitly. The EPUB export will make use of
    these attributes.
    
    (It is unclear why the test fails on the windows_msc_dbgutil_32 slave,
    it works for me locally.)
    
    Change-Id: I05030b6a14aca842e5a740786f3743e9ae838293
    Reviewed-on: https://gerrit.libreoffice.org/45384
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/CppunitTest_sw_odfexport.mk b/sw/CppunitTest_sw_odfexport.mk
index e8c43ad931c9..da931c3f3006 100644
--- a/sw/CppunitTest_sw_odfexport.mk
+++ b/sw/CppunitTest_sw_odfexport.mk
@@ -54,4 +54,9 @@ $(eval $(call gb_CppunitTest_use_custom_headers,sw_odfexport,\
 
 $(eval $(call gb_CppunitTest_use_configuration,sw_odfexport))
 
+ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),)
+$(call gb_CppunitTest_get_target,sw_odfexport): \
+    $(call gb_ExternalPackage_get_target,fonts_liberation)
+endif
+
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/extras/odfexport/data/embedded-font-props.odt b/sw/qa/extras/odfexport/data/embedded-font-props.odt
new file mode 100644
index 000000000000..6eb073e29fe0
Binary files /dev/null and b/sw/qa/extras/odfexport/data/embedded-font-props.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 60a1ceef489f..eea19faccea8 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -1668,6 +1668,26 @@ DECLARE_ODFEXPORT_TEST(testImageMimetype, "image-mimetype.odt")
     }
 }
 
+DECLARE_ODFEXPORT_TEST(testEmbeddedFontProps, "embedded-font-props.odt")
+{
+#if !defined(WNT)
+    // Test that font style/weight of embedded fonts is exposed.
+    // Test file is a normal ODT, except EmbedFonts is set to true in settings.xml.
+    if (xmlDocPtr pXmlDoc = parseExport("content.xml"))
+    {
+        // These failed, the attributes were missing.
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-style", "normal");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-weight", "normal");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-style", "normal");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-weight", "bold");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-style", "italic");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-weight", "normal");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-style", "italic");
+        assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-weight", "bold");
+    }
+#endif
+}
+
 DECLARE_ODFEXPORT_TEST(testTdf100492, "tdf100492.odt")
 {
     uno::Reference<drawing::XShape> xShape = getShape(1);
diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx
index a484921051f9..cbf55e707bba 100644
--- a/xmloff/source/style/XMLFontAutoStylePool.cxx
+++ b/xmloff/source/style/XMLFontAutoStylePool.cxx
@@ -239,6 +239,50 @@ OUString lcl_checkFontFile( const OUString &fileUrl )
     return OUString();
 }
 
+/// Contains information about a single variant of an embedded font.
+struct EmbeddedFontInfo
+{
+    OUString aURL;
+    FontWeight eWeight = WEIGHT_NORMAL;
+    FontItalic eItalic = ITALIC_NONE;
+};
+
+/// Converts FontWeight to CSS-compatible string representation.
+OUString FontWeightToString(FontWeight eWeight)
+{
+    OUString aRet;
+
+    switch (eWeight)
+    {
+    case WEIGHT_BOLD:
+        aRet = "bold";
+        break;
+    default:
+        aRet = "normal";
+        break;
+    }
+
+    return aRet;
+}
+
+/// Converts FontItalic to CSS-compatible string representation.
+OUString FontItalicToString(FontItalic eWeight)
+{
+    OUString aRet;
+
+    switch (eWeight)
+    {
+    case ITALIC_NORMAL:
+        aRet = "italic";
+        break;
+    default:
+        aRet = "normal";
+        break;
+    }
+
+    return aRet;
+}
+
 }
 
 void XMLFontAutoStylePool::exportXML()
@@ -296,7 +340,7 @@ void XMLFontAutoStylePool::exportXML()
         if( tryToEmbedFonts )
         {
             const bool bExportFlat( GetExport().getExportFlags() & SvXMLExportFlags::EMBEDDED );
-            std::vector< OUString > fileUrls;
+            std::vector< EmbeddedFontInfo > aEmbeddedFonts;
             static const FontWeight weight[] = { WEIGHT_NORMAL, WEIGHT_BOLD, WEIGHT_NORMAL, WEIGHT_BOLD };
             static const FontItalic italic[] = { ITALIC_NONE, ITALIC_NONE, ITALIC_NORMAL, ITALIC_NORMAL };
             assert( SAL_N_ELEMENTS( weight ) == SAL_N_ELEMENTS( italic ));
@@ -319,23 +363,33 @@ void XMLFontAutoStylePool::exportXML()
                     else
                         continue; // --> failed to embed
                 }
-                fileUrls.push_back( fileUrl );
+                EmbeddedFontInfo aEmbeddedFont;
+                aEmbeddedFont.aURL = fileUrl;
+                aEmbeddedFont.eWeight = weight[j];
+                aEmbeddedFont.eItalic = italic[j];
+                aEmbeddedFonts.push_back(aEmbeddedFont);
             }
-            if( !fileUrls.empty())
+            if (!aEmbeddedFonts.empty())
             {
                 SvXMLElementExport fontFaceSrc( GetExport(), XML_NAMESPACE_SVG,
                     XML_FONT_FACE_SRC, true, true );
-                for( std::vector< OUString >::const_iterator it = fileUrls.begin();
-                     it != fileUrls.end();
+                for( auto it = aEmbeddedFonts.begin();
+                     it != aEmbeddedFonts.end();
                      ++it )
                 {
-                    if( fontFilesMap.count( *it ))
+                    if (fontFilesMap.count(it->aURL))
                     {
                         if( !bExportFlat )
                         {
-                            GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, fontFilesMap[ *it ] );
+                            GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, fontFilesMap[it->aURL]);
                             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, "simple" );
                         }
+
+                        // Help consumers of our output by telling them which
+                        // font file is which one.
+                        GetExport().AddAttribute( XML_NAMESPACE_LO_EXT, XML_FONT_STYLE, FontItalicToString(it->eItalic) );
+                        GetExport().AddAttribute( XML_NAMESPACE_LO_EXT, XML_FONT_WEIGHT, FontWeightToString(it->eWeight) );
+
                         SvXMLElementExport fontFaceUri( GetExport(), XML_NAMESPACE_SVG,
                             XML_FONT_FACE_URI, true, true );
 
@@ -344,7 +398,7 @@ void XMLFontAutoStylePool::exportXML()
                             const uno::Reference< ucb::XSimpleFileAccess > xFileAccess( ucb::SimpleFileAccess::create( GetExport().getComponentContext() ) );
                             try
                             {
-                                const uno::Reference< io::XInputStream > xInput( xFileAccess->openFileRead( fontFilesMap[ *it ] ) );
+                                const uno::Reference< io::XInputStream > xInput( xFileAccess->openFileRead( fontFilesMap[ it->aURL ] ) );
                                 XMLBase64Export aBase64Exp( GetExport() );
                                 aBase64Exp.exportOfficeBinaryDataElement( xInput );
                             }


More information about the Libreoffice-commits mailing list