diff options
author | Vort <vvort@yandex.ru> | 2014-04-18 08:07:17 +0300 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-04-18 09:20:49 +0000 |
commit | efaa53bc980c92054ae39f4317b8acc607fd6a34 (patch) | |
tree | 5af88d1a21af7a7fb5761b481fc0e7066065a2d3 | |
parent | b6cbb15026e2df1e985f19c5bb723f64a26f2658 (diff) |
fdo#69051 fdo#72028 PDF Import: text fixes
1. Set font size not only on text span, but also on text frame.
2. Some copy-paste from Draw import code to Writer import code:
2.1. Set frame's auto-size properties.
2.2. Set correctly line joins and caps.
Change-Id: I6beecfb50aa7f45d20cc3cb3740e415172394638
Reviewed-on: https://gerrit.libreoffice.org/9091
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sdext/source/pdfimport/tree/drawtreevisiting.cxx | 53 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/genericelements.hxx | 2 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/pdfiprocessor.cxx | 1 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/writertreevisiting.cxx | 51 |
4 files changed, 89 insertions, 18 deletions
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx b/sdext/source/pdfimport/tree/drawtreevisiting.cxx index 723d0910b61d..237baff83623 100644 --- a/sdext/source/pdfimport/tree/drawtreevisiting.cxx +++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx @@ -198,6 +198,9 @@ void DrawXmlEmitter::fillFrameProps( DrawElement& rElem, rProps[ "svg:width" ] = convertPixelToUnitString( rElem.w ); rProps[ "svg:height" ] = convertPixelToUnitString( rElem.h ); + if (rElem.IsForText) + rProps["draw:text-style-name"] = rEmitContext.rStyles.getStyleName(rElem.TextStyleId); + const GraphicsContext& rGC = rEmitContext.rProcessor.getGraphicsContext( rElem.GCId ); if( rGC.Transformation.isIdentity() || bWasTransformed ) @@ -862,6 +865,17 @@ void DrawXmlFinalizer::visit( HyperlinkElement&, const std::list< Element* >::co { } +void SetFontsizeProperties(PropertyMap& props, double fontSize) +{ + OUStringBuffer aBuf(32); + aBuf.append(fontSize * 72 / PDFI_OUTDEV_RESOLUTION); + aBuf.appendAscii("pt"); + OUString aFSize = aBuf.makeStringAndClear(); + props["fo:font-size"] = aFSize; + props["style:font-size-asian"] = aFSize; + props["style:font-size-complex"] = aFSize; +} + void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::const_iterator& ) { const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId ); @@ -900,14 +914,9 @@ void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::co { aFontProps[ "style:text-outline" ] = "true"; } + // size - OUStringBuffer aBuf( 32 ); - aBuf.append( rFont.size*72/PDFI_OUTDEV_RESOLUTION ); - aBuf.appendAscii( "pt" ); - OUString aFSize = aBuf.makeStringAndClear(); - aFontProps[ "fo:font-size" ] = aFSize; - aFontProps[ "style:font-size-asian" ] = aFSize; - aFontProps[ "style:font-size-complex" ] = aFSize; + SetFontsizeProperties(aFontProps, rFont.size); // color const GraphicsContext& rGC = m_rProcessor.getGraphicsContext( elem.GCId ); @@ -921,6 +930,7 @@ void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::co if (((textScale >= 1) && (textScale <= 99)) || ((textScale >= 101) && (textScale <= 999))) { + OUStringBuffer aBuf(32); aBuf.append(textScale); aBuf.appendAscii("%"); aFontProps[ "style:text-scale" ] = aBuf.makeStringAndClear(); @@ -959,9 +969,9 @@ void DrawXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element* void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator&) { - PropertyMap aProps; - aProps[ "style:family" ] = "graphic"; - aProps[ "style:parent-style-name" ] = "standard"; + PropertyMap props1; + props1[ "style:family" ] = "graphic"; + props1[ "style:parent-style-name" ] = "standard"; // generate standard graphic style if necessary m_rStyleContainer.getStandardStyleId( "graphic" ); @@ -987,11 +997,26 @@ void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::c if( elem.MirrorVertical ) aGCProps[ "style:mirror" ] = "horizontal"; - StyleContainer::Style aStyle( "style:style", aProps ); - StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps ); - aStyle.SubStyles.push_back( &aSubStyle ); + StyleContainer::Style style1( "style:style", props1 ); + StyleContainer::Style subStyle1( "style:graphic-properties", aGCProps ); + style1.SubStyles.push_back(&subStyle1); + + elem.StyleId = m_rStyleContainer.getStyleId(style1); + + if (elem.IsForText) + { + PropertyMap props2; + props2["style:family"] = "paragraph"; + + PropertyMap textProps; + SetFontsizeProperties(textProps, elem.FontSize); + + StyleContainer::Style style2("style:style", props2); + StyleContainer::Style subStyle2("style:text-properties", textProps); + style2.SubStyles.push_back(&subStyle2); + elem.TextStyleId = m_rStyleContainer.getStyleId(style2); + } - elem.StyleId = m_rStyleContainer.getStyleId( aStyle ); elem.applyToChildren(*this); } diff --git a/sdext/source/pdfimport/tree/genericelements.hxx b/sdext/source/pdfimport/tree/genericelements.hxx index 78f85dfa024f..810e10adc4ca 100644 --- a/sdext/source/pdfimport/tree/genericelements.hxx +++ b/sdext/source/pdfimport/tree/genericelements.hxx @@ -133,6 +133,8 @@ namespace pdfi sal_Int32 GCId; bool MirrorVertical; bool IsForText; + double FontSize; + sal_Int32 TextStyleId; }; struct DrawElement : public GraphicalElement diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx index 779a9130848e..487ba20c01ed 100644 --- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx +++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx @@ -243,6 +243,7 @@ void PDFIProcessor::processGlyphLine() getGCId(m_GlyphsList[0].getGC())); frame->ZOrder = m_nNextZOrder++; frame->IsForText = true; + frame->FontSize = getFont(m_GlyphsList[0].getGC().FontId).size; ParagraphElement* para = m_pElFactory->createParagraphElement(frame); for (size_t i = 0; i < m_GlyphsList.size(); i++) diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx index 707caf8cc1a7..c4aeffd371ad 100644 --- a/sdext/source/pdfimport/tree/writertreevisiting.cxx +++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx @@ -26,9 +26,12 @@ #include "writertreevisiting.hxx" #include "genericelements.hxx" -#include <basegfx/polygon/b2dpolypolygontools.hxx> -#include <basegfx/range/b2drange.hxx> +#include "basegfx/polygon/b2dpolypolygontools.hxx" +#include "basegfx/range/b2drange.hxx" +#include "com/sun/star/rendering/PathCapType.hpp" +#include "com/sun/star/rendering/PathJoinType.hpp" +using namespace ::com::sun::star; namespace pdfi { @@ -858,6 +861,36 @@ void WriterXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* aGCProps[ "svg:stroke-width" ] = OUString::number( aVec.getLength() ); } + OUString strokeLinejoinValue; + OUString strokeLinecapValue; + switch (rGC.LineJoin) + { + default: + case rendering::PathJoinType::MITER: + strokeLinejoinValue = "miter"; + break; + case rendering::PathJoinType::ROUND: + strokeLinejoinValue = "round"; + break; + case rendering::PathJoinType::BEVEL: + strokeLinejoinValue = "bevel"; + break; + } + switch (rGC.LineCap) + { + default: + case rendering::PathCapType::BUTT: + strokeLinecapValue = "butt"; + break; + case rendering::PathCapType::ROUND: + strokeLinecapValue = "round"; + break; + case rendering::PathCapType::SQUARE: + strokeLinecapValue = "square"; + break; + } + aGCProps[ "draw:stroke-linejoin" ] = strokeLinejoinValue; + aGCProps[ "svg:stroke-linecap" ] = strokeLinecapValue; } else { @@ -1019,8 +1052,18 @@ void WriterXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >: PropertyMap aGCProps; - aGCProps[ "draw:stroke" ] = "none"; - aGCProps[ "draw:fill" ] = "none"; + aGCProps[ "draw:stroke" ] = "none"; + aGCProps[ "draw:fill" ] = "none"; + aGCProps[ "draw:auto-grow-height" ] = "true"; + aGCProps[ "draw:auto-grow-width" ] = "true"; + aGCProps[ "draw:textarea-horizontal-align" ] = "left"; + aGCProps[ "draw:textarea-vertical-align" ] = "top"; + aGCProps[ "fo:min-height"] = "0cm"; + aGCProps[ "fo:min-width"] = "0cm"; + aGCProps[ "fo:padding-top" ] = "0cm"; + aGCProps[ "fo:padding-left" ] = "0cm"; + aGCProps[ "fo:padding-right" ] = "0cm"; + aGCProps[ "fo:padding-bottom" ] = "0cm"; StyleContainer::Style aStyle( "style:style", aProps ); StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps ); |