writerfilter: fix indentation in rtfsdrimport

Change-Id: Ibecedba7a8a6e6b3218f64aefdd05897a6612a71
This commit is contained in:
Miklos Vajna
2014-04-21 11:47:05 +02:00
parent 164c89b5f4
commit fdb9807a10
2 changed files with 158 additions and 153 deletions

View File

@@ -40,13 +40,15 @@
#include <oox/drawingml/shapepropertymap.hxx> #include <oox/drawingml/shapepropertymap.hxx>
#include <oox/helper/propertyset.hxx> #include <oox/helper/propertyset.hxx>
namespace writerfilter { namespace writerfilter
namespace rtftok { {
namespace rtftok
{
RTFSdrImport::RTFSdrImport(RTFDocumentImpl& rDocument, RTFSdrImport::RTFSdrImport(RTFDocumentImpl& rDocument,
uno::Reference<lang::XComponent> const& xDstDoc) uno::Reference<lang::XComponent> const& xDstDoc)
: m_rImport(rDocument), : m_rImport(rDocument),
m_bTextFrame(false) m_bTextFrame(false)
{ {
uno::Reference<drawing::XDrawPageSupplier> xDrawings(xDstDoc, uno::UNO_QUERY); uno::Reference<drawing::XDrawPageSupplier> xDrawings(xDstDoc, uno::UNO_QUERY);
if (xDrawings.is()) if (xDrawings.is())
@@ -145,40 +147,40 @@ void RTFSdrImport::applyProperty(uno::Reference<drawing::XShape> xShape, const O
{ {
switch (aValue.toInt32()) switch (aValue.toInt32())
{ {
case 1: case 1:
nHoriOrient = text::HoriOrientation::LEFT; nHoriOrient = text::HoriOrientation::LEFT;
break; break;
case 2: case 2:
nHoriOrient = text::HoriOrientation::CENTER; nHoriOrient = text::HoriOrientation::CENTER;
break; break;
case 3: case 3:
nHoriOrient = text::HoriOrientation::RIGHT; nHoriOrient = text::HoriOrientation::RIGHT;
break; break;
case 4: case 4:
nHoriOrient = text::HoriOrientation::INSIDE; nHoriOrient = text::HoriOrientation::INSIDE;
break; break;
case 5: case 5:
nHoriOrient = text::HoriOrientation::OUTSIDE; nHoriOrient = text::HoriOrientation::OUTSIDE;
break; break;
default: default:
break; break;
} }
} }
else if (aKey == "posv") else if (aKey == "posv")
{ {
switch (aValue.toInt32()) switch (aValue.toInt32())
{ {
case 1: case 1:
nVertOrient = text::VertOrientation::TOP; nVertOrient = text::VertOrientation::TOP;
break; break;
case 2: case 2:
nVertOrient = text::VertOrientation::CENTER; nVertOrient = text::VertOrientation::CENTER;
break; break;
case 3: case 3:
nVertOrient = text::VertOrientation::BOTTOM; nVertOrient = text::VertOrientation::BOTTOM;
break; break;
default: default:
break; break;
} }
} }
else if (aKey == "fFitShapeToText") else if (aKey == "fFitShapeToText")
@@ -247,39 +249,39 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
// The spec doesn't state what is the default for shapeType, Word seems to implement it as a rectangle. // The spec doesn't state what is the default for shapeType, Word seems to implement it as a rectangle.
if (std::find_if(rShape.aProperties.begin(), if (std::find_if(rShape.aProperties.begin(),
rShape.aProperties.end(), rShape.aProperties.end(),
boost::bind(&OUString::equals, boost::bind(&std::pair<OUString, OUString>::first, _1), OUString("shapeType"))) boost::bind(&OUString::equals, boost::bind(&std::pair<OUString, OUString>::first, _1), OUString("shapeType")))
== rShape.aProperties.end()) == rShape.aProperties.end())
rShape.aProperties.insert(rShape.aProperties.begin(), std::pair<OUString, OUString>("shapeType", OUString::number(ESCHER_ShpInst_Rectangle))); rShape.aProperties.insert(rShape.aProperties.begin(), std::pair<OUString, OUString>("shapeType", OUString::number(ESCHER_ShpInst_Rectangle)));
for (std::vector< std::pair<OUString, OUString> >::iterator i = rShape.aProperties.begin(); for (std::vector< std::pair<OUString, OUString> >::iterator i = rShape.aProperties.begin();
i != rShape.aProperties.end(); ++i) i != rShape.aProperties.end(); ++i)
{ {
if ( i->first == "shapeType" ) if (i->first == "shapeType")
{ {
nType = i->second.toInt32(); nType = i->second.toInt32();
switch (nType) switch (nType)
{ {
case ESCHER_ShpInst_Line: case ESCHER_ShpInst_Line:
createShape("com.sun.star.drawing.LineShape", xShape, xPropertySet); createShape("com.sun.star.drawing.LineShape", xShape, xPropertySet);
break; break;
case ESCHER_ShpInst_Rectangle: case ESCHER_ShpInst_Rectangle:
case ESCHER_ShpInst_TextBox: case ESCHER_ShpInst_TextBox:
// If we're inside a groupshape, can't use text frames. // If we're inside a groupshape, can't use text frames.
if (!bClose && m_aParents.size() == 1) if (!bClose && m_aParents.size() == 1)
{ {
createShape("com.sun.star.text.TextFrame", xShape, xPropertySet); createShape("com.sun.star.text.TextFrame", xShape, xPropertySet);
m_bTextFrame = true; m_bTextFrame = true;
std::vector<beans::PropertyValue> aDefaults = getTextFrameDefaults(true); std::vector<beans::PropertyValue> aDefaults = getTextFrameDefaults(true);
for (size_t j = 0; j < aDefaults.size(); ++j) for (size_t j = 0; j < aDefaults.size(); ++j)
xPropertySet->setPropertyValue(aDefaults[j].Name, aDefaults[j].Value); xPropertySet->setPropertyValue(aDefaults[j].Name, aDefaults[j].Value);
} }
else else
bCustom = true;
break;
default:
bCustom = true; bCustom = true;
break; break;
default:
bCustom = true;
break;
} }
// Defaults // Defaults
@@ -287,7 +289,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
if (xPropertySet.is() && !m_bTextFrame) if (xPropertySet.is() && !m_bTextFrame)
xPropertySet->setPropertyValue("FillColor", aAny); xPropertySet->setPropertyValue("FillColor", aAny);
} }
else if ( i->first == "wzName" ) else if (i->first == "wzName")
{ {
if (m_bTextFrame) if (m_bTextFrame)
{ {
@@ -297,9 +299,9 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
else else
xPropertySet->setPropertyValue("Name", uno::makeAny(i->second)); xPropertySet->setPropertyValue("Name", uno::makeAny(i->second));
} }
else if ( i->first == "wzDescription" ) else if (i->first == "wzDescription")
xPropertySet->setPropertyValue("Description", uno::makeAny(i->second)); xPropertySet->setPropertyValue("Description", uno::makeAny(i->second));
else if ( i->first == "pib" ) else if (i->first == "pib")
{ {
m_rImport.setDestinationText(i->second); m_rImport.setDestinationText(i->second);
bPib = true; bPib = true;
@@ -315,12 +317,12 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
// fillType will decide, possible it'll be the start color of a gradient. // fillType will decide, possible it'll be the start color of a gradient.
aFillModel.moColor.set(OUString("#") + OStringToOUString(msfilter::util::ConvertColor(aAny.get<sal_Int32>()), RTL_TEXTENCODING_UTF8)); aFillModel.moColor.set(OUString("#") + OStringToOUString(msfilter::util::ConvertColor(aAny.get<sal_Int32>()), RTL_TEXTENCODING_UTF8));
} }
else if ( i->first == "fillBackColor" ) else if (i->first == "fillBackColor")
// fillType will decide, possible it'll be the end color of a gradient. // fillType will decide, possible it'll be the end color of a gradient.
aFillModel.moColor2.set(OUString("#") + OStringToOUString(msfilter::util::ConvertColor(msfilter::util::BGRToRGB(i->second.toInt32())), RTL_TEXTENCODING_UTF8)); aFillModel.moColor2.set(OUString("#") + OStringToOUString(msfilter::util::ConvertColor(msfilter::util::BGRToRGB(i->second.toInt32())), RTL_TEXTENCODING_UTF8));
else if (i->first == "lineColor") else if (i->first == "lineColor")
aLineColor <<= msfilter::util::BGRToRGB(i->second.toInt32()); aLineColor <<= msfilter::util::BGRToRGB(i->second.toInt32());
else if ( i->first == "lineBackColor" ) else if (i->first == "lineBackColor")
; // Ignore: complementer of lineColor ; // Ignore: complementer of lineColor
else if (i->first == "txflTextFlow" && xPropertySet.is()) else if (i->first == "txflTextFlow" && xPropertySet.is())
{ {
@@ -331,13 +333,13 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
resolveFLine(xPropertySet, i->second.toInt32()); resolveFLine(xPropertySet, i->second.toInt32());
else if (i->first == "fillOpacity" && xPropertySet.is()) else if (i->first == "fillOpacity" && xPropertySet.is())
{ {
int opacity = 100 - (i->second.toInt32())*100/65536; int opacity = 100 - (i->second.toInt32())*100/65536;
aAny <<= uno::makeAny(sal_uInt32(opacity)); aAny <<= uno::makeAny(sal_uInt32(opacity));
xPropertySet->setPropertyValue("FillTransparence", aAny); xPropertySet->setPropertyValue("FillTransparence", aAny);
} }
else if (i->first == "lineWidth") else if (i->first == "lineWidth")
aLineWidth <<= i->second.toInt32()/360; aLineWidth <<= i->second.toInt32()/360;
else if ( i->first == "pVerticies" ) else if (i->first == "pVerticies")
{ {
uno::Sequence<drawing::EnhancedCustomShapeParameterPair> aCoordinates; uno::Sequence<drawing::EnhancedCustomShapeParameterPair> aCoordinates;
sal_Int32 nSize = 0; // Size of a token (its value is hardwired in the exporter) sal_Int32 nSize = 0; // Size of a token (its value is hardwired in the exporter)
@@ -380,7 +382,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
aPropertyValue.Value <<= aCoordinates; aPropertyValue.Value <<= aCoordinates;
aPathPropVec.push_back(aPropertyValue); aPathPropVec.push_back(aPropertyValue);
} }
else if ( i->first == "pSegmentInfo" ) else if (i->first == "pSegmentInfo")
{ {
uno::Sequence<drawing::EnhancedCustomShapeSegment> aSegments; uno::Sequence<drawing::EnhancedCustomShapeSegment> aSegments;
sal_Int32 nSize = 0; sal_Int32 nSize = 0;
@@ -408,35 +410,35 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
switch (nSeg) switch (nSeg)
{ {
case 0x0001: // lineto case 0x0001: // lineto
aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::LINETO; aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::LINETO;
aSegments[nIndex].Count = sal_Int32(1); aSegments[nIndex].Count = sal_Int32(1);
break; break;
case 0x4000: // moveto case 0x4000: // moveto
aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::MOVETO; aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::MOVETO;
aSegments[nIndex].Count = sal_Int32(1); aSegments[nIndex].Count = sal_Int32(1);
break; break;
case 0x2000: // curveto case 0x2000: // curveto
aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::CURVETO; aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::CURVETO;
aSegments[nIndex].Count = sal_Int32(nPoints); aSegments[nIndex].Count = sal_Int32(nPoints);
break; break;
case 0xb300: // arcto case 0xb300: // arcto
aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::ARCTO; aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::ARCTO;
aSegments[nIndex].Count = sal_Int32(0); aSegments[nIndex].Count = sal_Int32(0);
break; break;
case 0xac00: case 0xac00:
case 0xaa00: // nofill case 0xaa00: // nofill
case 0xab00: // nostroke case 0xab00: // nostroke
case 0x6001: // close case 0x6001: // close
break; break;
case 0x8000: // end case 0x8000: // end
aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH; aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
aSegments[nIndex].Count = sal_Int32(0); aSegments[nIndex].Count = sal_Int32(0);
break; break;
default: // given number of lineto elements default: // given number of lineto elements
aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::LINETO; aSegments[nIndex].Command = drawing::EnhancedCustomShapeSegmentCommand::LINETO;
aSegments[nIndex].Count = nSeg; aSegments[nIndex].Count = nSeg;
break; break;
} }
nIndex++; nIndex++;
} }
@@ -446,15 +448,15 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
aPropertyValue.Value <<= aSegments; aPropertyValue.Value <<= aSegments;
aPathPropVec.push_back(aPropertyValue); aPathPropVec.push_back(aPropertyValue);
} }
else if ( i->first == "geoLeft" ) else if (i->first == "geoLeft")
aViewBox.X = i->second.toInt32(); aViewBox.X = i->second.toInt32();
else if ( i->first == "geoTop" ) else if (i->first == "geoTop")
aViewBox.Y = i->second.toInt32(); aViewBox.Y = i->second.toInt32();
else if ( i->first == "geoRight" ) else if (i->first == "geoRight")
aViewBox.Width = i->second.toInt32(); aViewBox.Width = i->second.toInt32();
else if ( i->first == "geoBottom" ) else if (i->first == "geoBottom")
aViewBox.Height = i->second.toInt32(); aViewBox.Height = i->second.toInt32();
else if ( i->first == "dhgt" ) else if (i->first == "dhgt")
{ {
// dhgt is Word 2007, \shpz is Word 97-2003, the later has priority. // dhgt is Word 2007, \shpz is Word 97-2003, the later has priority.
if (!rShape.oZ) if (!rShape.oZ)
@@ -481,11 +483,11 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
{ {
switch (i->second.toInt32()) switch (i->second.toInt32())
{ {
case 7: // Shade using the fillAngle case 7: // Shade using the fillAngle
aFillModel.moType.set(oox::XML_gradient); aFillModel.moType.set(oox::XML_gradient);
break; break;
default: default:
SAL_INFO("writerfilter", "TODO handle fillType value '" << i->second << "'"); SAL_INFO("writerfilter", "TODO handle fillType value '" << i->second << "'");
break; break;
} }
} }
@@ -507,22 +509,22 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
{ {
switch (i->second.toInt32()) switch (i->second.toInt32())
{ {
case 1: case 1:
rShape.nHoriOrientRelation = text::RelOrientation::PAGE_FRAME; rShape.nHoriOrientRelation = text::RelOrientation::PAGE_FRAME;
break; break;
default: default:
break; break;
} }
} }
else if (i->first == "posrelv") else if (i->first == "posrelv")
{ {
switch (i->second.toInt32()) switch (i->second.toInt32())
{ {
case 1: case 1:
rShape.nVertOrientRelation = text::RelOrientation::PAGE_FRAME; rShape.nVertOrientRelation = text::RelOrientation::PAGE_FRAME;
break; break;
default: default:
break; break;
} }
} }
else if (i->first == "groupLeft") else if (i->first == "groupLeft")
@@ -599,7 +601,8 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
} }
else else
{ {
static const OUString aBorders[] = { static const OUString aBorders[] =
{
OUString("TopBorder"), OUString("LeftBorder"), OUString("BottomBorder"), OUString("RightBorder") OUString("TopBorder"), OUString("LeftBorder"), OUString("BottomBorder"), OUString("RightBorder")
}; };
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aBorders); ++i) for (unsigned int i = 0; i < SAL_N_ELEMENTS(aBorders); ++i)
@@ -670,7 +673,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
sal_Int32 nTop = rShape.nTop; sal_Int32 nTop = rShape.nTop;
bool bInShapeGroup = oGroupLeft && oGroupTop && oGroupRight && oGroupBottom bool bInShapeGroup = oGroupLeft && oGroupTop && oGroupRight && oGroupBottom
&& oRelLeft && oRelTop && oRelRight && oRelBottom; && oRelLeft && oRelTop && oRelRight && oRelBottom;
if (bInShapeGroup) if (bInShapeGroup)
{ {
// See lclGetAbsPoint() in the VML import: rShape is the group shape, oGroup is its coordinate system, oRel is the relative child shape. // See lclGetAbsPoint() in the VML import: rShape is the group shape, oGroup is its coordinate system, oRel is the relative child shape.
@@ -678,10 +681,10 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
sal_Int32 nShapeHeight = rShape.nBottom - rShape.nTop; sal_Int32 nShapeHeight = rShape.nBottom - rShape.nTop;
sal_Int32 nCoordSysWidth = *oGroupRight - *oGroupLeft; sal_Int32 nCoordSysWidth = *oGroupRight - *oGroupLeft;
sal_Int32 nCoordSysHeight = *oGroupBottom - *oGroupTop; sal_Int32 nCoordSysHeight = *oGroupBottom - *oGroupTop;
double fWidthRatio = static_cast< double >( nShapeWidth ) / nCoordSysWidth; double fWidthRatio = static_cast< double >(nShapeWidth) / nCoordSysWidth;
double fHeightRatio = static_cast< double >( nShapeHeight ) / nCoordSysHeight; double fHeightRatio = static_cast< double >(nShapeHeight) / nCoordSysHeight;
nLeft = static_cast< sal_Int32 >( rShape.nLeft + fWidthRatio * (*oRelLeft - *oGroupLeft) ); nLeft = static_cast< sal_Int32 >(rShape.nLeft + fWidthRatio * (*oRelLeft - *oGroupLeft));
nTop = static_cast< sal_Int32 >( rShape.nTop + fHeightRatio * (*oRelTop - *oGroupTop) ); nTop = static_cast< sal_Int32 >(rShape.nTop + fHeightRatio * (*oRelTop - *oGroupTop));
} }
if (m_bTextFrame) if (m_bTextFrame)

View File

@@ -14,43 +14,45 @@
#include <rtfdocumentimpl.hxx> #include <rtfdocumentimpl.hxx>
namespace writerfilter { namespace writerfilter
namespace rtftok { {
/// Handles the import of drawings using RTF markup. namespace rtftok
class RTFSdrImport {
{ /// Handles the import of drawings using RTF markup.
public: class RTFSdrImport
RTFSdrImport(RTFDocumentImpl& rImport, uno::Reference<lang::XComponent> const& xDstDoc); {
virtual ~RTFSdrImport(); public:
RTFSdrImport(RTFDocumentImpl& rImport, uno::Reference<lang::XComponent> const& xDstDoc);
virtual ~RTFSdrImport();
void resolve(RTFShape& rShape, bool bClose); void resolve(RTFShape& rShape, bool bClose);
void close(); void close();
void append(const OUString& aKey, const OUString& aValue); void append(const OUString& aKey, const OUString& aValue);
/// Append property on the current parent. /// Append property on the current parent.
void appendGroupProperty(const OUString& aKey, const OUString& aValue); void appendGroupProperty(const OUString& aKey, const OUString& aValue);
void resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder, bool bOldStyle); void resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder, bool bOldStyle);
void resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nFLine); void resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nFLine);
/** /**
* These are the default in Word, but not in Writer. * These are the default in Word, but not in Writer.
* *
* @param bNew if the frame is new-style or old-style. * @param bNew if the frame is new-style or old-style.
*/ */
std::vector<beans::PropertyValue> getTextFrameDefaults(bool bNew); std::vector<beans::PropertyValue> getTextFrameDefaults(bool bNew);
/// Push a new group shape to the parent stack. /// Push a new group shape to the parent stack.
void pushParent(uno::Reference<drawing::XShapes> xParent); void pushParent(uno::Reference<drawing::XShapes> xParent);
/// Pop the current group shape from the parent stack. /// Pop the current group shape from the parent stack.
void popParent(); void popParent();
private: private:
void createShape(const OUString& aService, uno::Reference<drawing::XShape>& xShape, uno::Reference<beans::XPropertySet>& xPropertySet); void createShape(const OUString& aService, uno::Reference<drawing::XShape>& xShape, uno::Reference<beans::XPropertySet>& xPropertySet);
void applyProperty(uno::Reference<drawing::XShape> xShape, const OUString& aKey, const OUString& aValue); void applyProperty(uno::Reference<drawing::XShape> xShape, const OUString& aKey, const OUString& aValue);
RTFDocumentImpl& m_rImport; RTFDocumentImpl& m_rImport;
std::stack< uno::Reference<drawing::XShapes> > m_aParents; std::stack< uno::Reference<drawing::XShapes> > m_aParents;
uno::Reference<drawing::XShape> m_xShape; uno::Reference<drawing::XShape> m_xShape;
/// If m_xShape is imported as a Writer text frame (instead of a drawinglayer rectangle). /// If m_xShape is imported as a Writer text frame (instead of a drawinglayer rectangle).
bool m_bTextFrame; bool m_bTextFrame;
}; };
} // namespace rtftok } // namespace rtftok
} // namespace writerfilter } // namespace writerfilter
#endif // _RTFSDRIPORT_HXX_ #endif // _RTFSDRIPORT_HXX_