[Libreoffice-commits] core.git: 2 commits - writerfilter/source
Miklos Vajna
vmiklos at suse.cz
Sat Jun 15 15:35:46 PDT 2013
writerfilter/source/rtftok/rtfdocumentimpl.cxx | 41 ++++++--
writerfilter/source/rtftok/rtfdocumentimpl.hxx | 5 -
writerfilter/source/rtftok/rtfsdrimport.cxx | 117 ++++++++++++++-----------
writerfilter/source/rtftok/rtfsdrimport.hxx | 6 +
4 files changed, 108 insertions(+), 61 deletions(-)
New commits:
commit 4ab658b56f5c6ff0082d38d8ace1924d11e30e96
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Sun Jun 16 00:14:51 2013 +0200
RTF import: implement support for tables inside text frames
Change-Id: I6088adad20212cdbcc03b193cc079c51a305602a
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 3606700..e1bba04 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1450,10 +1450,11 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
case RTF_SHPTXT:
case RTF_DPTXBXTEXT:
m_aStates.top().nDestinationState = DESTINATION_SHAPETEXT;
+ checkFirstRun();
dispatchFlag(RTF_PARD);
m_bNeedPap = true;
- OSL_ENSURE(!m_aShapetextBuffer.size(), "shapetext buffer is not empty");
- m_aStates.top().pCurrentBuffer = &m_aShapetextBuffer;
+ if (nKeyword == RTF_SHPTXT)
+ m_pSdrImport->resolve(m_aStates.top().aShape, false);
break;
case RTF_FORMFIELD:
if (m_aStates.top().nDestinationState == DESTINATION_FIELDINSTRUCTION)
@@ -2236,7 +2237,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
// Reset everything.
m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms;
m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes;
- if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT)
+ if (m_aStates.top().pCurrentBuffer != &m_aShapetextBuffer)
m_aStates.top().pCurrentBuffer = 0;
}
else
@@ -2557,6 +2558,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
std::vector<beans::PropertyValue> aDefaults = m_pSdrImport->getTextFrameDefaults(false);
for (size_t i = 0; i < aDefaults.size(); ++i)
m_aStates.top().aDrawingObject.aPendingProperties.push_back(aDefaults[i]);
+ checkFirstRun();
+ Mapper().startShape(m_aStates.top().aDrawingObject.xShape);
+ m_aStates.top().aDrawingObject.bHadShapeText = true;
}
break;
default:
@@ -3872,12 +3876,16 @@ int RTFDocumentImpl::popState()
break;
case DESTINATION_SHAPEPROPERTYVALUE:
if (aState.aShape.aProperties.size())
+ {
aState.aShape.aProperties.back().second = m_aStates.top().aDestinationText.makeStringAndClear();
+ if (m_aStates.top().bHadShapeText)
+ m_pSdrImport->append(aState.aShape.aProperties.back().first, aState.aShape.aProperties.back().second);
+ }
break;
case DESTINATION_PICPROP:
case DESTINATION_SHAPEINSTRUCTION:
- if (!m_bObject && !aState.bInListpicture)
- m_pSdrImport->resolve(m_aStates.top().aShape);
+ if (!m_bObject && !aState.bInListpicture && !m_aStates.top().bHadShapeText)
+ m_pSdrImport->resolve(m_aStates.top().aShape, true);
break;
case DESTINATION_BOOKMARKSTART:
{
@@ -4136,8 +4144,11 @@ int RTFDocumentImpl::popState()
m_pSdrImport->resolveFLine(xPropertySet, rDrawing.nFLine);
- Mapper().startShape(xShape);
- replayShapetext();
+ if (!m_aStates.top().aDrawingObject.bHadShapeText)
+ {
+ Mapper().startShape(xShape);
+ replayShapetext();
+ }
Mapper().endShape();
}
break;
@@ -4581,6 +4592,14 @@ int RTFDocumentImpl::popState()
m_xDocumentProperties->setTitle(aState.aDestinationText.makeStringAndClear());
}
break;
+ case DESTINATION_SHAPETEXT:
+ // If we're leaving the shapetext group (it may have nested ones) and this is a shape, not an old drawingobject.
+ if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT && !m_aStates.top().aDrawingObject.bHadShapeText)
+ {
+ m_aStates.top().bHadShapeText = true;
+ m_pSdrImport->close();
+ }
+ break;
default:
{
if (m_aStates.size() && m_aStates.top().nDestinationState == DESTINATION_PICT)
@@ -4713,7 +4732,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl)
pCurrentBuffer(0),
bHasTableStyle(false),
bInListpicture(false),
- bInBackground(false)
+ bInBackground(false),
+ bHadShapeText(false)
{
}
@@ -4767,7 +4787,8 @@ RTFDrawingObject::RTFDrawingObject()
bHasFillColor(false),
nDhgt(0),
nFLine(-1),
- nPolyLineCount(0)
+ nPolyLineCount(0),
+ bHadShapeText(false)
{
}
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 0ba51b6..e59fac2 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -265,6 +265,7 @@ namespace writerfilter {
sal_Int32 nFLine;
sal_Int32 nPolyLineCount;
uno::Sequence<awt::Point> aPolyLinePoints;
+ bool bHadShapeText;
};
/// Stores the properties of a picture.
@@ -403,6 +404,8 @@ namespace writerfilter {
/// If we're inside a \background group.
bool bInBackground;
+
+ bool bHadShapeText;
};
class RTFTokenizer;
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index 9e0efd8..d0178ff 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -166,7 +166,7 @@ void RTFSdrImport::applyProperty(uno::Reference<drawing::XShape> xShape, OUStrin
xPropertySet->setPropertyValue("VertOrient", uno::makeAny(nVertOrient));
}
-void RTFSdrImport::resolve(RTFShape& rShape)
+void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
{
int nType = -1;
bool bPib = false;
@@ -204,7 +204,7 @@ void RTFSdrImport::resolve(RTFShape& rShape)
break;
case ESCHER_ShpInst_Rectangle:
case ESCHER_ShpInst_TextBox:
- if (!m_rImport.getShapetextBuffer().empty())
+ if (!bClose)
{
createShape("com.sun.star.text.TextFrame", xShape, xPropertySet);
bTextFrame = true;
@@ -594,10 +594,24 @@ void RTFSdrImport::resolve(RTFShape& rShape)
// Send it to dmapper
m_rImport.Mapper().startShape(xShape);
- m_rImport.replayShapetext();
+ if (bClose)
+ {
+ m_rImport.replayShapetext();
+ m_rImport.Mapper().endShape();
+ }
+ m_xShape = xShape;
+}
+
+void RTFSdrImport::close()
+{
m_rImport.Mapper().endShape();
}
+void RTFSdrImport::append(OUString aKey, OUString aValue)
+{
+ applyProperty(m_xShape, aKey, aValue);
+}
+
} // namespace rtftok
} // namespace writerfilter
diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx
index e9a93cb..ab3c44c 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.hxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.hxx
@@ -21,7 +21,9 @@ namespace writerfilter {
RTFSdrImport(RTFDocumentImpl& rImport, uno::Reference<lang::XComponent> const& xDstDoc);
virtual ~RTFSdrImport();
- void resolve(RTFShape& rShape);
+ void resolve(RTFShape& rShape, bool bClose);
+ void close();
+ void append(OUString aKey, OUString aValue);
void resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder);
void resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nFLine);
/**
@@ -36,6 +38,7 @@ namespace writerfilter {
RTFDocumentImpl& m_rImport;
uno::Reference<drawing::XDrawPage> m_xDrawPage;
+ uno::Reference<drawing::XShape> m_xShape;
};
} // namespace rtftok
} // namespace writerfilter
commit 2fc088afdf6dcb2defbd462a9e64ba7e53ba5caf
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Sat Jun 15 23:12:24 2013 +0200
Factor out RTFSdrImport::applyProperty() from RTFSdrImport::resolve()
Change-Id: Idd352e712e20e6e64c80490daf4b2a5e74d47a97
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 7559b72..3606700 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -4750,9 +4750,7 @@ RTFShape::RTFShape()
nTop(0),
nRight(0),
nBottom(0),
- nHoriOrient(0),
nHoriOrientRelation(0),
- nVertOrient(0),
nVertOrientRelation(0),
nWrap(-1)
{
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 2ad163e..0ba51b6 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -244,9 +244,7 @@ namespace writerfilter {
sal_Int32 nRight;
sal_Int32 nBottom;
boost::optional<sal_Int32> oZ; ///< Z-Order of the shape.
- sal_Int16 nHoriOrient;
sal_Int16 nHoriOrientRelation;
- sal_Int16 nVertOrient;
sal_Int16 nVertOrientRelation;
int nWrap;
};
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index af00d97..9e0efd8 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -115,6 +115,57 @@ void RTFSdrImport::resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet
xPropertySet->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_NONE));
}
+void RTFSdrImport::applyProperty(uno::Reference<drawing::XShape> xShape, OUString aKey, OUString aValue)
+{
+ uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
+ sal_Int16 nHoriOrient = 0;
+ sal_Int16 nVertOrient = 0;
+ if (aKey == "posh")
+ {
+ switch (aValue.toInt32())
+ {
+ case 1:
+ nHoriOrient = text::HoriOrientation::LEFT;
+ break;
+ case 2:
+ nHoriOrient = text::HoriOrientation::CENTER;
+ break;
+ case 3:
+ nHoriOrient = text::HoriOrientation::RIGHT;
+ break;
+ case 4:
+ nHoriOrient = text::HoriOrientation::INSIDE;
+ break;
+ case 5:
+ nHoriOrient = text::HoriOrientation::OUTSIDE;
+ break;
+ default:
+ break;
+ }
+ }
+ else if (aKey == "posv")
+ {
+ switch (aValue.toInt32())
+ {
+ case 1:
+ nVertOrient = text::VertOrientation::TOP;
+ break;
+ case 2:
+ nVertOrient = text::VertOrientation::CENTER;
+ break;
+ case 3:
+ nVertOrient = text::VertOrientation::BOTTOM;
+ break;
+ default:
+ break;
+ }
+ }
+ if (nHoriOrient != 0)
+ xPropertySet->setPropertyValue("HoriOrient", uno::makeAny(nHoriOrient));
+ if (nVertOrient != 0)
+ xPropertySet->setPropertyValue("VertOrient", uno::makeAny(nVertOrient));
+}
+
void RTFSdrImport::resolve(RTFShape& rShape)
{
int nType = -1;
@@ -393,46 +444,8 @@ void RTFSdrImport::resolve(RTFShape& rShape)
else if (i->first == "shadowOffsetX")
// EMUs to points
aShadowModel.moOffset.set(OUString::number(i->second.toDouble() / 12700) + "pt");
- else if (i->first == "posh")
- {
- switch(i->second.toInt32())
- {
- case 1:
- rShape.nHoriOrient = text::HoriOrientation::LEFT;
- break;
- case 2:
- rShape.nHoriOrient = text::HoriOrientation::CENTER;
- break;
- case 3:
- rShape.nHoriOrient = text::HoriOrientation::RIGHT;
- break;
- case 4:
- rShape.nHoriOrient = text::HoriOrientation::INSIDE;
- break;
- case 5:
- rShape.nHoriOrient = text::HoriOrientation::OUTSIDE;
- break;
- default:
- break;
- }
- }
- else if (i->first == "posv")
- {
- switch(i->second.toInt32())
- {
- case 1:
- rShape.nVertOrient = text::VertOrientation::TOP;
- break;
- case 2:
- rShape.nVertOrient = text::VertOrientation::CENTER;
- break;
- case 3:
- rShape.nVertOrient = text::VertOrientation::BOTTOM;
- break;
- default:
- break;
- }
- }
+ else if (i->first == "posh" || i->first == "posv")
+ applyProperty(xShape, i->first, i->second);
else if (i->first == "posrelh")
{
switch (i->second.toInt32())
@@ -543,12 +556,8 @@ void RTFSdrImport::resolve(RTFShape& rShape)
else
xShape->setPosition(awt::Point(rShape.nLeft, rShape.nTop));
xShape->setSize(awt::Size(rShape.nRight - rShape.nLeft, rShape.nBottom - rShape.nTop));
- if (rShape.nHoriOrient != 0)
- xPropertySet->setPropertyValue("HoriOrient", uno::makeAny(rShape.nHoriOrient));
if (rShape.nHoriOrientRelation != 0)
xPropertySet->setPropertyValue("HoriOrientRelation", uno::makeAny(rShape.nHoriOrientRelation));
- if (rShape.nVertOrient != 0)
- xPropertySet->setPropertyValue("VertOrient", uno::makeAny(rShape.nVertOrient));
if (rShape.nVertOrientRelation != 0)
xPropertySet->setPropertyValue("VertOrientRelation", uno::makeAny(rShape.nVertOrientRelation));
if (rShape.nWrap != -1)
diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx
index 165c86f..e9a93cb 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.hxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.hxx
@@ -32,6 +32,7 @@ namespace writerfilter {
std::vector<beans::PropertyValue> getTextFrameDefaults(bool bNew);
private:
void createShape(OUString aService, uno::Reference<drawing::XShape>& xShape, uno::Reference<beans::XPropertySet>& xPropertySet);
+ void applyProperty(uno::Reference<drawing::XShape> xShape, OUString aKey, OUString aValue);
RTFDocumentImpl& m_rImport;
uno::Reference<drawing::XDrawPage> m_xDrawPage;
More information about the Libreoffice-commits
mailing list