tdf81484 Draw and Writer pdf import: SimSun bold font is shown as "outline"

Case 1: As discussed in the bug report, SimSun does not have a
 "bold" font. In PDF it uses fill+stroke rendering mode (i.e.,
 Text Render Mode is 2), see CoreTextStyle::CoreTextStyle, as a
 faux bold (fake bold) feature. For faux bold, the text render
 fill color is the same as the stroke color.

Case 2: Also, it is noted that if you apply real "outline"
 characters in Writer and export to PDF, on Draw PDF import
 the text render mode is also 2, but the text render fill color
 is different than the stroke color.
 However, I would argue that for this case on PDF export Writer
 should set the render mode as 1, not 2, per PDF specs, which is
 another issue to be improved.

The old code treated all these two cases as "outline".

This patch:
1) treats render mode 2 as faux bold if the stroke color is the
 same as the fill color; and
2) still treat it as outline if the fill color and stroke color
 are different.

This way, the real outline remains as outline characters while
 the faux bold (fake bold) becomes bold again on pdf import.

This patch Also fixed some incorrect use of <style:text-properties>
 attributes per OpenDocument specification.

This patch depends on change-ID I50a510ab9e5483f859ea2a767ea977ea3f065a2e
 which guesses the bold/italic if the font indentifaction had failed
 for whatever reason.

Change-Id: Idabb22ea9b01ba53733c3acbd9de843790ebe8ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118156
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Kevin Suo
2021-07-14 09:07:09 +02:00
committed by Noel Grandin
parent 7c7dcdb513
commit fe28633ee6
3 changed files with 41 additions and 17 deletions
@@ -16,8 +16,7 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/log.hxx>
#include <pdfiprocessor.hxx>
#include <xmlemitter.hxx>
#include <pdfihelper.hxx>
@@ -828,23 +827,28 @@ void DrawXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_pt
PropertyMap aFontProps;
// family name
// TODO: tdf#143095: use system font name rather than PSName
SAL_INFO("sdext.pdfimport", "The font used in xml is: " << rFont.familyName);
aFontProps[ "fo:font-family" ] = rFont.familyName;
aFontProps[ "style:font-family-asia" ] = rFont.familyName;
aFontProps[ "style:font-family-complex" ] = rFont.familyName;
// bold
if( rFont.isBold )
{
aFontProps[ "fo:font-weight" ] = "bold";
aFontProps[ "fo:font-weight-asian" ] = "bold";
aFontProps[ "style:font-weight-asian" ] = "bold";
aFontProps[ "style:font-weight-complex" ] = "bold";
}
// italic
if( rFont.isItalic )
{
aFontProps[ "fo:font-style" ] = "italic";
aFontProps[ "fo:font-style-asian" ] = "italic";
aFontProps[ "style:font-style-asian" ] = "italic";
aFontProps[ "style:font-style-complex" ] = "italic";
}
// underline
if( rFont.isUnderline )
{
@@ -852,11 +856,10 @@ void DrawXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_pt
aFontProps[ "style:text-underline-width" ] = "auto";
aFontProps[ "style:text-underline-color" ] = "font-color";
}
// outline
if( rFont.isOutline )
{
aFontProps[ "style:text-outline" ] = "true";
}
// size
SetFontsizeProperties(aFontProps, rFont.size);
+14 -1
View File
@@ -147,7 +147,20 @@ void PDFIProcessor::setFont( const FontAttributes& i_rFont )
FontAttributes aChangedFont( i_rFont );
GraphicsContext& rGC=getCurrentContext();
// for text render modes, please see PDF reference manual
aChangedFont.isOutline = ( (rGC.TextRenderMode == 1) || (rGC. TextRenderMode == 2) );
if (rGC.TextRenderMode == 1)
{
aChangedFont.isOutline = true;
}
else if (rGC.TextRenderMode == 2)
{
// tdf#81484: faux bold is represented as "stroke+fill" (while using the same color for both stroke and fill) in pdf.
// Convert to bold instead if the stroke color is the same as the fill color,
// otherwise it should be outline.
if (getCurrentContext().LineColor == getCurrentContext().FillColor)
aChangedFont.isBold = true;
else
aChangedFont.isOutline = true;
}
FontToIdMap::const_iterator it = m_aFontToId.find( aChangedFont );
if( it != m_aFontToId.end() )
rGC.FontId = it->second;
@@ -18,7 +18,7 @@
*/
#include <sal/config.h>
#include <sal/log.hxx>
#include <string_view>
#include <pdfiprocessor.hxx>
@@ -899,21 +899,28 @@ void WriterXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_
PropertyMap aFontProps;
// family name
// TODO: tdf#143095: use system font name rather than PSName
SAL_INFO("sdext.pdfimport", "The font used in xml is: " << rFont.familyName);
aFontProps[ "fo:font-family" ] = rFont.familyName;
aFontProps[ "style:font-family-asia" ] = rFont.familyName;
aFontProps[ "style:font-family-complex" ] = rFont.familyName;
// bold
if( rFont.isBold )
{
aFontProps[ "fo:font-weight" ] = "bold";
aFontProps[ "fo:font-weight-asian" ] = "bold";
aFontProps[ "fo:font-weight-complex" ] = "bold";
aFontProps[ "fo:font-weight" ] = "bold";
aFontProps[ "style:font-weight-asian" ] = "bold";
aFontProps[ "style:font-weight-complex" ] = "bold";
}
// italic
if( rFont.isItalic )
{
aFontProps[ "fo:font-style" ] = "italic";
aFontProps[ "fo:font-style-asian" ] = "italic";
aFontProps[ "fo:font-style-complex" ] = "italic";
aFontProps[ "fo:font-style" ] = "italic";
aFontProps[ "style:font-style-asian" ] = "italic";
aFontProps[ "style:font-style-complex" ] = "italic";
}
// underline
if( rFont.isUnderline )
{
@@ -921,19 +928,20 @@ void WriterXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_
aFontProps[ "style:text-underline-width" ] = "auto";
aFontProps[ "style:text-underline-color" ] = "font-color";
}
// outline
if( rFont.isOutline )
{
aFontProps[ "style:text-outline" ] = "true";
}
// size
OUString aFSize = OUString::number( rFont.size*72/PDFI_OUTDEV_RESOLUTION ) + "pt";
aFontProps[ "fo:font-size" ] = aFSize;
aFontProps[ "style:font-size-asian" ] = aFSize;
aFontProps[ "style:font-size-complex" ] = aFSize;
// color
const GraphicsContext& rGC = m_rProcessor.getGraphicsContext( elem.GCId );
aFontProps[ "fo:color" ] = getColorString( rFont.isOutline ? rGC.LineColor : rGC.FillColor );
aFontProps[ "fo:color" ] = getColorString( rFont.isOutline ? rGC.LineColor : rGC.FillColor );
StyleContainer::Style aStyle( "style:style", aProps );
StyleContainer::Style aSubStyle( "style:text-properties", aFontProps );