summaryrefslogtreecommitdiffstats
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2013-06-25 14:47:48 +0200
committerMiklos Vajna <vmiklos@suse.cz>2013-06-25 15:35:02 +0200
commita8ee2ee7529900628b1c533d77c039618917bc97 (patch)
tree5a44972976e3ce1c9dee77863a29ad04d4fd0745 /writerfilter
parentTry to help the Windows tinderbox. (diff)
downloadcore-a8ee2ee7529900628b1c533d77c039618917bc97.tar.gz
core-a8ee2ee7529900628b1c533d77c039618917bc97.zip
fdo#66040 RTF import: initial groupshape support
There are two cases here: if the shapes contain tables (or other Writer-specific features), we should use text frames and we should not create the actual group shape, as Writer textframes can't be part of such group shapes. The other case is when the shapes contain simple text, OTOH there are groupshape-level transformations defined, in that case we should choose drawinglayer rectangles and actually create a group shape. This commit implements support for the first case only. Change-Id: I9dc99b0711ce5c7a29ea0b14539df0121f9de3d0
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx9
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx2
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.cxx52
3 files changed, 57 insertions, 6 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 7c4f5455ed15..76ab7eaea2da 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1667,6 +1667,10 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
m_aStates.top().nDestinationState = DESTINATION_BACKGROUND;
m_aStates.top().bInBackground = true;
break;
+ case RTF_SHPGRP:
+ m_aStates.top().nDestinationState = DESTINATION_SHAPEGROUP;
+ m_aStates.top().bInShapeGroup = true;
+ break;
default:
SAL_INFO("writerfilter", "TODO handle destination '" << lcl_RtfToString(nKeyword) << "'");
// Make sure we skip destinations (even without \*) till we don't handle them
@@ -3876,7 +3880,7 @@ int RTFDocumentImpl::popState()
break;
case DESTINATION_PICPROP:
case DESTINATION_SHAPEINSTRUCTION:
- if (!m_bObject && !aState.bInListpicture && !m_aStates.top().bHadShapeText)
+ if (!m_bObject && !aState.bInListpicture && !m_aStates.top().bHadShapeText && !m_aStates.top().bInShapeGroup)
m_pSdrImport->resolve(m_aStates.top().aShape, true);
break;
case DESTINATION_BOOKMARKSTART:
@@ -4711,7 +4715,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl)
bHasTableStyle(false),
bInListpicture(false),
bInBackground(false),
- bHadShapeText(false)
+ bHadShapeText(false),
+ bInShapeGroup(false)
{
}
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 7ca1c24fb86d..b8783095f628 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -164,6 +164,7 @@ namespace writerfilter {
DESTINATION_UPR,
DESTINATION_LFOLEVEL,
DESTINATION_BACKGROUND,
+ DESTINATION_SHAPEGROUP,
};
enum RTFBorderState
@@ -406,6 +407,7 @@ namespace writerfilter {
bool bInBackground;
bool bHadShapeText;
+ bool bInShapeGroup; ///< If we're inside a \shpgrp group.
};
class RTFTokenizer;
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index 6cac9c1cceb0..c47a29b796a3 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -36,6 +36,8 @@
#include <oox/drawingml/shapepropertymap.hxx>
#include <oox/helper/propertyset.hxx>
+#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
+
namespace writerfilter {
namespace rtftok {
@@ -201,6 +203,9 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
// Default line width is 0.75 pt (26 mm100) in Word, 0 in Writer.
uno::Any aLineWidth = uno::makeAny(sal_Int32(26));
text::WritingMode eWritingMode = text::WritingMode_LR_TB;
+ // Groupshape support
+ boost::optional<sal_Int32> oGroupLeft, oGroupTop, oGroupRight, oGroupBottom;
+ boost::optional<sal_Int32> oRelLeft, oRelTop, oRelRight, oRelBottom;
// Importing these are not trivial, let the VML import do the hard work.
oox::vml::FillModel aFillModel; // Gradient.
@@ -483,6 +488,22 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
break;
}
}
+ else if (i->first == "groupLeft")
+ oGroupLeft.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "groupTop")
+ oGroupTop.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "groupRight")
+ oGroupRight.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "groupBottom")
+ oGroupBottom.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "relLeft")
+ oRelLeft.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "relTop")
+ oRelTop.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "relRight")
+ oRelRight.reset(TWIP_TO_MM100(i->second.toInt32()));
+ else if (i->first == "relBottom")
+ oRelBottom.reset(TWIP_TO_MM100(i->second.toInt32()));
else
SAL_INFO("writerfilter", "TODO handle shape property '" << i->first << "':'" << i->second << "'");
}
@@ -563,14 +584,37 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
// Set position and size
if (xShape.is())
{
+ sal_Int32 nLeft = rShape.nLeft;
+ sal_Int32 nTop = rShape.nTop;
+
+ bool bInShapeGroup = oGroupLeft && oGroupTop && oGroupRight && oGroupBottom
+ && oRelLeft && oRelTop && oRelRight && oRelBottom;
+ if (bInShapeGroup)
+ {
+ // See lclGetAbsPoint() in the VML import: rShape is the group shape, oGroup is its coordinate system, oRel is the relative child shape.
+ sal_Int32 nShapeWidth = rShape.nRight - rShape.nLeft;
+ sal_Int32 nShapeHeight = rShape.nBottom - rShape.nTop;
+ sal_Int32 nCoordSysWidth = *oGroupRight - *oGroupLeft;
+ sal_Int32 nCoordSysHeight = *oGroupBottom - *oGroupTop;
+ double fWidthRatio = static_cast< double >( nShapeWidth ) / nCoordSysWidth;
+ double fHeightRatio = static_cast< double >( nShapeHeight ) / nCoordSysHeight;
+ nLeft = static_cast< sal_Int32 >( rShape.nLeft + fWidthRatio * (*oRelLeft - *oGroupLeft) );
+ nTop = static_cast< sal_Int32 >( rShape.nTop + fHeightRatio * (*oRelTop - *oGroupTop) );
+ }
+
if (bTextFrame)
{
- xPropertySet->setPropertyValue("HoriOrientPosition", uno::makeAny(rShape.nLeft));
- xPropertySet->setPropertyValue("VertOrientPosition", uno::makeAny(rShape.nTop));
+ xPropertySet->setPropertyValue("HoriOrientPosition", uno::makeAny(nLeft));
+ xPropertySet->setPropertyValue("VertOrientPosition", uno::makeAny(nTop));
}
else
- xShape->setPosition(awt::Point(rShape.nLeft, rShape.nTop));
- xShape->setSize(awt::Size(rShape.nRight - rShape.nLeft, rShape.nBottom - rShape.nTop));
+ xShape->setPosition(awt::Point(nLeft, nTop));
+
+ if (bInShapeGroup)
+ xShape->setSize(awt::Size(*oRelRight - *oRelLeft, *oRelBottom - *oRelTop));
+ else
+ xShape->setSize(awt::Size(rShape.nRight - rShape.nLeft, rShape.nBottom - rShape.nTop));
+
if (rShape.nHoriOrientRelation != 0)
xPropertySet->setPropertyValue("HoriOrientRelation", uno::makeAny(rShape.nHoriOrientRelation));
if (rShape.nVertOrientRelation != 0)