summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/oox/drawingml/drawingmltypes.hxx8
-rw-r--r--include/oox/export/drawingml.hxx1
-rw-r--r--oox/source/drawingml/drawingmltypes.cxx115
-rw-r--r--oox/source/export/drawingml.cxx28
-rw-r--r--sw/qa/extras/ooxmlexport/data/dml-shape-fillpattern.docxbin0 -> 27380 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx80
6 files changed, 224 insertions, 8 deletions
diff --git a/include/oox/drawingml/drawingmltypes.hxx b/include/oox/drawingml/drawingmltypes.hxx
index bd4f8f47615c..4500428de628 100644
--- a/include/oox/drawingml/drawingmltypes.hxx
+++ b/include/oox/drawingml/drawingmltypes.hxx
@@ -23,6 +23,7 @@
#include <boost/shared_ptr.hpp>
#include <com/sun/star/style/TabAlign.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
+#include <com/sun/star/drawing/Hatch.hpp>
#include <com/sun/star/geometry/IntegerRectangle2D.hpp>
#include <com/sun/star/awt/Point.hpp>
#include <com/sun/star/awt/Size.hpp>
@@ -128,12 +129,15 @@ sal_Int16 GetCaseMap( sal_Int32 nToken );
/** converts a paragraph align to a ParaAdjust */
sal_Int16 GetParaAdjust( sal_Int32 nAlign );
-// Convert vertical adjust tokens to a TextVerticalAdjust item
+// Converts vertical adjust tokens to a TextVerticalAdjust item
::com::sun::star::drawing::TextVerticalAdjust GetTextVerticalAdjust( sal_Int32 nToken );
-// Convert a TextVerticalAdjust item to string value appearing in ooxml
+// Converts a TextVerticalAdjust item to string value appearing in ooxml
OOX_DLLPUBLIC const char* GetTextVerticalAdjust( ::com::sun::star::drawing::TextVerticalAdjust eAdjust );
+// Converts a Hatch object to an ooxml pattern.
+const char* GetHatchPattern( const ::com::sun::star::drawing::Hatch& rHatch );
+
// ============================================================================
// CT_IndexRange
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 570048633111..4fe42ccd8e01 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -141,6 +141,7 @@ public:
void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, OUString sURLPropName );
void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
OUString sURLPropName, sal_Int32 nXmlNamespace );
+ void WritePattFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
void WriteSrcRect( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, const OUString& );
void WriteOutline( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
void WriteStretch( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, const OUString& rURL );
diff --git a/oox/source/drawingml/drawingmltypes.cxx b/oox/source/drawingml/drawingmltypes.cxx
index a96eaf382ffd..70216f979ef9 100644
--- a/oox/source/drawingml/drawingmltypes.cxx
+++ b/oox/source/drawingml/drawingmltypes.cxx
@@ -252,7 +252,120 @@ TabAlign GetTabAlign( sal_Int32 aToken )
return nEnum;
}
-// --------------------------------------------------------------------
+const char* GetHatchPattern( const Hatch& rHatch )
+{
+ const char* sPattern = 0;
+ const sal_Int32 nAngle = rHatch.Angle > 1800 ? rHatch.Angle - 1800 : rHatch.Angle;
+ // Angle ~ 0° (horizontal)
+ if( (nAngle >= 0 && nAngle < 225) || nAngle >= 1575 )
+ {
+ switch( rHatch.Style )
+ {
+ case HatchStyle_SINGLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "ltHorz";
+ else
+ sPattern = "horz";
+
+ break;
+ }
+ case HatchStyle_DOUBLE:
+ case HatchStyle_TRIPLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "smGrid";
+ else
+ sPattern = "lgGrid";
+
+ break;
+ }
+ default: break;
+ }
+ }
+ // Angle ~ 45° (upward diagonal)
+ else if( nAngle < 675 )
+ {
+ switch( rHatch.Style )
+ {
+ case HatchStyle_SINGLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "ltUpDiag";
+ else
+ sPattern = "wdUpDiag";
+
+ break;
+ }
+ case HatchStyle_DOUBLE:
+ case HatchStyle_TRIPLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "smCheck";
+ else
+ sPattern = "openDmnd";
+
+ break;
+ }
+ default: break;
+ }
+ }
+ // Angle ~ 90° (vertical)
+ else if( nAngle < 1125 )
+ {
+ switch( rHatch.Style )
+ {
+ case HatchStyle_SINGLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "ltVert";
+ else
+ sPattern = "vert";
+
+ break;
+ }
+ case HatchStyle_DOUBLE:
+ case HatchStyle_TRIPLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "smGrid";
+ else
+ sPattern = "lgGrid";
+
+ break;
+ }
+ default: break;
+ }
+ }
+ // Angle ~ 135° (downward diagonal)
+ else if( nAngle < 1575 )
+ {
+ switch( rHatch.Style )
+ {
+ case HatchStyle_SINGLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "ltDnDiag";
+ else
+ sPattern = "wdDnDiag";
+
+ break;
+ }
+ case HatchStyle_DOUBLE:
+ case HatchStyle_TRIPLE:
+ {
+ if( rHatch.Distance < 75 )
+ sPattern = "smCheck";
+ else
+ sPattern = "openDmnd";
+
+ break;
+ }
+ default: break;
+ }
+ }
+ return sPattern;
+}
/** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
IntegerRectangle2D GetRelativeRect( const Reference< XFastAttributeList >& xAttribs )
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 3e869854adcf..bdec63d80e1a 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -881,6 +881,28 @@ void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sBi
}
}
+void DrawingML::WritePattFill( Reference< XPropertySet > rXPropSet )
+{
+ if ( GetProperty( rXPropSet, "FillHatch" ) )
+ {
+ drawing::Hatch aHatch;
+ mAny >>= aHatch;
+
+ mpFS->startElementNS( XML_a , XML_pattFill, XML_prst, GetHatchPattern(aHatch), FSEND );
+
+ mpFS->startElementNS( XML_a , XML_fgClr, FSEND );
+ WriteColor(aHatch.Color);
+ mpFS->endElementNS( XML_a , XML_fgClr );
+
+ // In Writer hatching has no background so use white as a default value.
+ mpFS->startElementNS( XML_a , XML_bgClr, FSEND );
+ WriteColor(COL_WHITE);
+ mpFS->endElementNS( XML_a , XML_bgClr );
+
+ mpFS->endElementNS( XML_a , XML_pattFill );
+ }
+}
+
void DrawingML::WriteSrcRect( Reference< XPropertySet > rXPropSet, const OUString& rURL )
{
Size aOriginalSize( GraphicObject::CreateGraphicObjectFromURL( rURL ).GetPrefSize() );
@@ -1885,9 +1907,6 @@ void DrawingML::WriteFill( Reference< XPropertySet > xPropSet )
FillStyle aFillStyle( FillStyle_NONE );
xPropSet->getPropertyValue( "FillStyle" ) >>= aFillStyle;
- if( aFillStyle == FillStyle_HATCH )
- return;
-
if ( aFillStyle == FillStyle_SOLID && GetProperty( xPropSet, "FillTransparence" ) )
{
// map full transparent background to no fill
@@ -1908,6 +1927,9 @@ void DrawingML::WriteFill( Reference< XPropertySet > xPropSet )
case FillStyle_BITMAP :
WriteBlipFill( xPropSet, "FillBitmapURL" );
break;
+ case FillStyle_HATCH :
+ WritePattFill( xPropSet );
+ break;
case FillStyle_NONE:
mpFS->singleElementNS( XML_a, XML_noFill, FSEND );
break;
diff --git a/sw/qa/extras/ooxmlexport/data/dml-shape-fillpattern.docx b/sw/qa/extras/ooxmlexport/data/dml-shape-fillpattern.docx
new file mode 100644
index 000000000000..9878c9964122
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/dml-shape-fillpattern.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index e4789edc39fa..4c437bac178a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -50,6 +50,7 @@
#include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
+#include <com/sun/star/drawing/Hatch.hpp>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
@@ -2949,7 +2950,6 @@ DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillBitmapCrop, "dml-shape-fillbitmapcrop.d
// 1st shape has some cropping
text::GraphicCrop aGraphicCropStruct = getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop");
-
CPPUNIT_ASSERT_EQUAL( sal_Int32( 454 ), aGraphicCropStruct.Left );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 367 ), aGraphicCropStruct.Right );
CPPUNIT_ASSERT_EQUAL( sal_Int32( -454 ), aGraphicCropStruct.Top );
@@ -2957,7 +2957,6 @@ DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillBitmapCrop, "dml-shape-fillbitmapcrop.d
// 2nd shape has no cropping
aGraphicCropStruct = getProperty<text::GraphicCrop>(getShape(2), "GraphicCrop");
-
CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Left );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Right );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Top );
@@ -3038,6 +3037,83 @@ DECLARE_OOXMLEXPORT_TEST(testColumnBreak_ColumnCountIsZero,"fdo74153.docx")
assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[1]/w:br","type","column");
}
+DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillPattern, "dml-shape-fillpattern.docx")
+{
+ // Hatching was ignored by the export.
+
+ // 1st shape: light horizontal pattern (ltHorz)
+ drawing::Hatch aHatch = getProperty<drawing::Hatch>(getShape(1), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0x99FF66), aHatch.Color);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 2nd shape: horizontal pattern (horz)
+ aHatch = getProperty<drawing::Hatch>(getShape(2), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 3rd shape: light vertical pattern (ltVert)
+ aHatch = getProperty<drawing::Hatch>(getShape(3), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(900), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 4th shape: vertical pattern (vert)
+ aHatch = getProperty<drawing::Hatch>(getShape(4), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(900), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 5th shape: light upward diagonal pattern (ltUpDiag)
+ aHatch = getProperty<drawing::Hatch>(getShape(5), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(450), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 6th shape: wide upward diagonal pattern (wdUpDiag)
+ aHatch = getProperty<drawing::Hatch>(getShape(6), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(450), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 7th shape: light downward diagonal pattern (ltDnDiag)
+ aHatch = getProperty<drawing::Hatch>(getShape(7), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1350), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 8th shape: wide downward diagonal pattern (wdDnDiag)
+ aHatch = getProperty<drawing::Hatch>(getShape(8), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1350), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_SINGLE, aHatch.Style);
+
+ // 9th shape: small grid pattern (smGrid)
+ aHatch = getProperty<drawing::Hatch>(getShape(9), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_DOUBLE, aHatch.Style);
+
+ // 10th shape: large grid pattern (lgGrid)
+ aHatch = getProperty<drawing::Hatch>(getShape(10), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_DOUBLE, aHatch.Style);
+
+ // 11th shape: small checker board pattern (smCheck)
+ aHatch = getProperty<drawing::Hatch>(getShape(11), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(450), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_DOUBLE, aHatch.Style);
+
+ // 12th shape: outlined diamond pattern (openDmnd)
+ aHatch = getProperty<drawing::Hatch>(getShape(12), "FillHatch");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(450), aHatch.Angle);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance);
+ CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_DOUBLE, aHatch.Style);
+}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();