RTF import: implement support for tables inside text frames

Change-Id: I6088adad20212cdbcc03b193cc079c51a305602a
This commit is contained in:
Miklos Vajna
2013-06-16 00:14:51 +02:00
parent 2fc088afdf
commit 4ab658b56f
4 changed files with 54 additions and 13 deletions

View File

@@ -1450,10 +1450,11 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
case RTF_SHPTXT: case RTF_SHPTXT:
case RTF_DPTXBXTEXT: case RTF_DPTXBXTEXT:
m_aStates.top().nDestinationState = DESTINATION_SHAPETEXT; m_aStates.top().nDestinationState = DESTINATION_SHAPETEXT;
checkFirstRun();
dispatchFlag(RTF_PARD); dispatchFlag(RTF_PARD);
m_bNeedPap = true; m_bNeedPap = true;
OSL_ENSURE(!m_aShapetextBuffer.size(), "shapetext buffer is not empty"); if (nKeyword == RTF_SHPTXT)
m_aStates.top().pCurrentBuffer = &m_aShapetextBuffer; m_pSdrImport->resolve(m_aStates.top().aShape, false);
break; break;
case RTF_FORMFIELD: case RTF_FORMFIELD:
if (m_aStates.top().nDestinationState == DESTINATION_FIELDINSTRUCTION) if (m_aStates.top().nDestinationState == DESTINATION_FIELDINSTRUCTION)
@@ -2236,7 +2237,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
// Reset everything. // Reset everything.
m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms; m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms;
m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes; 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; m_aStates.top().pCurrentBuffer = 0;
} }
else else
@@ -2557,6 +2558,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
std::vector<beans::PropertyValue> aDefaults = m_pSdrImport->getTextFrameDefaults(false); std::vector<beans::PropertyValue> aDefaults = m_pSdrImport->getTextFrameDefaults(false);
for (size_t i = 0; i < aDefaults.size(); ++i) for (size_t i = 0; i < aDefaults.size(); ++i)
m_aStates.top().aDrawingObject.aPendingProperties.push_back(aDefaults[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; break;
default: default:
@@ -3872,12 +3876,16 @@ int RTFDocumentImpl::popState()
break; break;
case DESTINATION_SHAPEPROPERTYVALUE: case DESTINATION_SHAPEPROPERTYVALUE:
if (aState.aShape.aProperties.size()) if (aState.aShape.aProperties.size())
{
aState.aShape.aProperties.back().second = m_aStates.top().aDestinationText.makeStringAndClear(); 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; break;
case DESTINATION_PICPROP: case DESTINATION_PICPROP:
case DESTINATION_SHAPEINSTRUCTION: case DESTINATION_SHAPEINSTRUCTION:
if (!m_bObject && !aState.bInListpicture) if (!m_bObject && !aState.bInListpicture && !m_aStates.top().bHadShapeText)
m_pSdrImport->resolve(m_aStates.top().aShape); m_pSdrImport->resolve(m_aStates.top().aShape, true);
break; break;
case DESTINATION_BOOKMARKSTART: case DESTINATION_BOOKMARKSTART:
{ {
@@ -4136,8 +4144,11 @@ int RTFDocumentImpl::popState()
m_pSdrImport->resolveFLine(xPropertySet, rDrawing.nFLine); m_pSdrImport->resolveFLine(xPropertySet, rDrawing.nFLine);
Mapper().startShape(xShape); if (!m_aStates.top().aDrawingObject.bHadShapeText)
replayShapetext(); {
Mapper().startShape(xShape);
replayShapetext();
}
Mapper().endShape(); Mapper().endShape();
} }
break; break;
@@ -4581,6 +4592,14 @@ int RTFDocumentImpl::popState()
m_xDocumentProperties->setTitle(aState.aDestinationText.makeStringAndClear()); m_xDocumentProperties->setTitle(aState.aDestinationText.makeStringAndClear());
} }
break; 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: default:
{ {
if (m_aStates.size() && m_aStates.top().nDestinationState == DESTINATION_PICT) if (m_aStates.size() && m_aStates.top().nDestinationState == DESTINATION_PICT)
@@ -4713,7 +4732,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl)
pCurrentBuffer(0), pCurrentBuffer(0),
bHasTableStyle(false), bHasTableStyle(false),
bInListpicture(false), bInListpicture(false),
bInBackground(false) bInBackground(false),
bHadShapeText(false)
{ {
} }
@@ -4767,7 +4787,8 @@ RTFDrawingObject::RTFDrawingObject()
bHasFillColor(false), bHasFillColor(false),
nDhgt(0), nDhgt(0),
nFLine(-1), nFLine(-1),
nPolyLineCount(0) nPolyLineCount(0),
bHadShapeText(false)
{ {
} }

View File

@@ -265,6 +265,7 @@ namespace writerfilter {
sal_Int32 nFLine; sal_Int32 nFLine;
sal_Int32 nPolyLineCount; sal_Int32 nPolyLineCount;
uno::Sequence<awt::Point> aPolyLinePoints; uno::Sequence<awt::Point> aPolyLinePoints;
bool bHadShapeText;
}; };
/// Stores the properties of a picture. /// Stores the properties of a picture.
@@ -403,6 +404,8 @@ namespace writerfilter {
/// If we're inside a \background group. /// If we're inside a \background group.
bool bInBackground; bool bInBackground;
bool bHadShapeText;
}; };
class RTFTokenizer; class RTFTokenizer;

View File

@@ -166,7 +166,7 @@ void RTFSdrImport::applyProperty(uno::Reference<drawing::XShape> xShape, OUStrin
xPropertySet->setPropertyValue("VertOrient", uno::makeAny(nVertOrient)); xPropertySet->setPropertyValue("VertOrient", uno::makeAny(nVertOrient));
} }
void RTFSdrImport::resolve(RTFShape& rShape) void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
{ {
int nType = -1; int nType = -1;
bool bPib = false; bool bPib = false;
@@ -204,7 +204,7 @@ void RTFSdrImport::resolve(RTFShape& rShape)
break; break;
case ESCHER_ShpInst_Rectangle: case ESCHER_ShpInst_Rectangle:
case ESCHER_ShpInst_TextBox: case ESCHER_ShpInst_TextBox:
if (!m_rImport.getShapetextBuffer().empty()) if (!bClose)
{ {
createShape("com.sun.star.text.TextFrame", xShape, xPropertySet); createShape("com.sun.star.text.TextFrame", xShape, xPropertySet);
bTextFrame = true; bTextFrame = true;
@@ -594,10 +594,24 @@ void RTFSdrImport::resolve(RTFShape& rShape)
// Send it to dmapper // Send it to dmapper
m_rImport.Mapper().startShape(xShape); 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(); m_rImport.Mapper().endShape();
} }
void RTFSdrImport::append(OUString aKey, OUString aValue)
{
applyProperty(m_xShape, aKey, aValue);
}
} // namespace rtftok } // namespace rtftok
} // namespace writerfilter } // namespace writerfilter

View File

@@ -21,7 +21,9 @@ namespace writerfilter {
RTFSdrImport(RTFDocumentImpl& rImport, uno::Reference<lang::XComponent> const& xDstDoc); RTFSdrImport(RTFDocumentImpl& rImport, uno::Reference<lang::XComponent> const& xDstDoc);
virtual ~RTFSdrImport(); 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 resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder);
void resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nFLine); void resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nFLine);
/** /**
@@ -36,6 +38,7 @@ namespace writerfilter {
RTFDocumentImpl& m_rImport; RTFDocumentImpl& m_rImport;
uno::Reference<drawing::XDrawPage> m_xDrawPage; uno::Reference<drawing::XDrawPage> m_xDrawPage;
uno::Reference<drawing::XShape> m_xShape;
}; };
} // namespace rtftok } // namespace rtftok
} // namespace writerfilter } // namespace writerfilter