summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/CppunitTest_sw_odfexport.mk5
-rw-r--r--sw/qa/extras/odfexport/data/embedded-font-props.odtbin0 -> 8097 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx20
-rw-r--r--xmloff/source/style/XMLFontAutoStylePool.cxx70
4 files changed, 87 insertions, 8 deletions
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
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/embedded-font-props.odt
Binary files 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 );
}