summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2024-01-03 19:32:25 +0100
committerJaume Pujantell <jaume.pujantell@collabora.com>2024-01-12 09:01:20 +0100
commit49c49d2b1687172216a37dfdbb8f7ed1583e6d75 (patch)
tree9c03a4b197df1ae0a9b098053b5a47219f5f1842
parente8ca2d11cf62d78ba1bc3aa9afb57b010a9002cf (diff)
sw: search for alternative weights when embeding on docx
Sometimes a docx document might come whith a font with niether normal or bold weight embedded as regular, so when embedding a font in docx search for alternative weights if neither a normal or bold matching font has been found. Change-Id: I95cf2634c392cec6e97e5dd12a90de6e50228ac1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161566 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Ashod Nakashian <ash@collabora.com>
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx29
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx2
2 files changed, 19 insertions, 12 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index a70bee00967a..2d6ed05c3247 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7857,10 +7857,16 @@ void DocxAttributeOutput::EmbedFont( std::u16string_view name, FontFamily family
{
if( !m_rExport.m_rDoc.getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
return; // no font embedding with this document
- EmbedFontStyle( name, XML_embedRegular, family, ITALIC_NONE, WEIGHT_NORMAL, pitch );
- EmbedFontStyle( name, XML_embedBold, family, ITALIC_NONE, WEIGHT_BOLD, pitch );
- EmbedFontStyle( name, XML_embedItalic, family, ITALIC_NORMAL, WEIGHT_NORMAL, pitch );
- EmbedFontStyle( name, XML_embedBoldItalic, family, ITALIC_NORMAL, WEIGHT_BOLD, pitch );
+ bool foundFont
+ = EmbedFontStyle(name, XML_embedRegular, family, ITALIC_NONE, WEIGHT_NORMAL, pitch);
+ foundFont
+ = EmbedFontStyle(name, XML_embedBold, family, ITALIC_NONE, WEIGHT_BOLD, pitch) || foundFont;
+ foundFont = EmbedFontStyle(name, XML_embedItalic, family, ITALIC_NORMAL, WEIGHT_NORMAL, pitch)
+ || foundFont;
+ foundFont = EmbedFontStyle(name, XML_embedBoldItalic, family, ITALIC_NORMAL, WEIGHT_BOLD, pitch)
+ || foundFont;
+ if (!foundFont)
+ EmbedFontStyle(name, XML_embedRegular, family, ITALIC_NONE, WEIGHT_DONTKNOW, pitch);
}
static char toHexChar( int value )
@@ -7868,21 +7874,21 @@ static char toHexChar( int value )
return value >= 10 ? value + 'A' - 10 : value + '0';
}
-void DocxAttributeOutput::EmbedFontStyle( std::u16string_view name, int tag, FontFamily family, FontItalic italic,
- FontWeight weight, FontPitch pitch )
+bool DocxAttributeOutput::EmbedFontStyle(std::u16string_view name, int tag, FontFamily family,
+ FontItalic italic, FontWeight weight, FontPitch pitch)
{
// Embed font if at least viewing is allowed (in which case the opening app must check
// the font license rights too and open either read-only or not use the font for editing).
OUString fontUrl = EmbeddedFontsHelper::fontFileUrl( name, family, italic, weight, pitch,
EmbeddedFontsHelper::FontRights::ViewingAllowed );
if( fontUrl.isEmpty())
- return;
+ return false;
// TODO IDocumentSettingAccess::EMBED_SYSTEM_FONTS
if( !fontFilesMap.count( fontUrl ))
{
osl::File file( fontUrl );
if( file.open( osl_File_OpenFlag_Read ) != osl::File::E_None )
- return;
+ return false;
uno::Reference< css::io::XOutputStream > xOutStream = m_rExport.GetFilter().openFragmentStream(
"word/fonts/font" + OUString::number(m_nextFontId) + ".odttf",
"application/vnd.openxmlformats-officedocument.obfuscatedFont" );
@@ -7901,7 +7907,7 @@ void DocxAttributeOutput::EmbedFontStyle( std::u16string_view name, int tag, Fon
{
SAL_WARN( "sw.ww8", "Font file size too small (" << fontUrl << ")" );
xOutStream->closeOutput();
- return;
+ return false;
}
for( int i = 0;
i < 16;
@@ -7918,7 +7924,7 @@ void DocxAttributeOutput::EmbedFontStyle( std::u16string_view name, int tag, Fon
{
SAL_WARN( "sw.ww8", "Error reading font file " << fontUrl );
xOutStream->closeOutput();
- return;
+ return false;
}
if( eof )
break;
@@ -7926,7 +7932,7 @@ void DocxAttributeOutput::EmbedFontStyle( std::u16string_view name, int tag, Fon
{
SAL_WARN( "sw.ww8", "Error reading font file " << fontUrl );
xOutStream->closeOutput();
- return;
+ return false;
}
if( readSize == 0 )
break;
@@ -7946,6 +7952,7 @@ void DocxAttributeOutput::EmbedFontStyle( std::u16string_view name, int tag, Fon
m_pSerializer->singleElementNS( XML_w, tag,
FSNS( XML_r, XML_id ), fontFilesMap[ fontUrl ].relId,
FSNS( XML_w, XML_fontKey ), fontFilesMap[ fontUrl ].fontKey );
+ return true;
}
OString DocxAttributeOutput::TransHighlightColor( sal_uInt8 nIco )
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 26f977539cae..9efd51a9af93 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -478,7 +478,7 @@ private:
void WriteFFData( const FieldInfos& rInfos );
void WritePendingPlaceholder();
- void EmbedFontStyle( std::u16string_view name, int tag, FontFamily family, FontItalic italic, FontWeight weight,
+ bool EmbedFontStyle( std::u16string_view name, int tag, FontFamily family, FontItalic italic, FontWeight weight,
FontPitch pitch );
/**