summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Suo <suokunlong@126.com>2021-06-30 18:17:36 +0800
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-07-14 09:07:09 +0200
commitfe28633ee6edc5986220c934dfb04aa7b0d065ad (patch)
treecbdec2442da42fef9345adc2f0e1c39889c0e182
parenttdf#141964 writerfilter CN: only one style per outline level (diff)
downloadcore-fe28633ee6edc5986220c934dfb04aa7b0d065ad.tar.gz
core-fe28633ee6edc5986220c934dfb04aa7b0d065ad.zip
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>
-rw-r--r--sdext/source/pdfimport/tree/drawtreevisiting.cxx15
-rw-r--r--sdext/source/pdfimport/tree/pdfiprocessor.cxx15
-rw-r--r--sdext/source/pdfimport/tree/writertreevisiting.cxx28
3 files changed, 41 insertions, 17 deletions
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
index ebce9efc896b..69f70001f6d6 100644
--- a/sdext/source/pdfimport/tree/drawtreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
@@ -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);
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
index ed2eaf6510b9..d63ab04e97fd 100644
--- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx
+++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
@@ -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;
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx
index 0aab0c9a7261..0ac805acd6ab 100644
--- a/sdext/source/pdfimport/tree/writertreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx
@@ -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 );