summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-11-28 14:27:59 +0100
committerAndras Timar <andras.timar@collabora.com>2018-03-15 23:03:51 +0100
commit7f84b2881fb80837f62fe6f210593571a07ee035 (patch)
treeffd486516a4eff599e27d4917e8fb3acf5cdafa9 /xmloff
parentbb64f2facdb9b5fd5d3e62c6af4023932783de7c (diff)
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@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> (cherry picked from commit 9914ca04ac6a63f14adcd0fe58b2be44b84ee15f)
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/style/XMLFontAutoStylePool.cxx70
1 files changed, 62 insertions, 8 deletions
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 );
}