Kaydet (Commit) 1351d5b9 authored tarafından Balazs Varga's avatar Balazs Varga Kaydeden (comit) Miklos Vajna

tdf#108104 OOXML Import: Fix Hatch fill in Charts

Sets an explicit fill hatch, or creates a named fill hatch
and stored in a global container. With this patch the
SUPPORTED MS Office hatch styles by LibreOffice, or the custom
LibreOffice hatches will be appeared correctly instead of the
previous display as horizontal lines in LibreOffice.
(The background color of the hatch styles are not imported correcty,
but that is another BUG.)

Change-Id: Ifda9dc805dd08f58db10b35f40d7f511a8614f77
Reviewed-on: https://gerrit.libreoffice.org/62681
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst b0da1ca2
......@@ -71,6 +71,7 @@ public:
void testTdf106217();
void testAutoBackgroundXLSX();
void testChartAreaStyleBackgroundXLSX();
void testChartHatchFillXLSX();
void testAxisTextRotationXLSX();
// void testTextCanOverlapXLSX(); // TODO : temporarily disabled.
void testNumberFormatsXLSX();
......@@ -144,6 +145,7 @@ public:
CPPUNIT_TEST(testTdf106217);
CPPUNIT_TEST(testAutoBackgroundXLSX);
CPPUNIT_TEST(testChartAreaStyleBackgroundXLSX);
CPPUNIT_TEST(testChartHatchFillXLSX);
CPPUNIT_TEST(testAxisTextRotationXLSX);
// CPPUNIT_TEST(testTextCanOverlapXLSX); // TODO : temporarily disabled.
CPPUNIT_TEST(testNumberFormatsXLSX);
......@@ -896,6 +898,28 @@ void Chart2ImportTest::testChartAreaStyleBackgroundXLSX()
sal_Int32(0), nColor);
}
void Chart2ImportTest::testChartHatchFillXLSX()
{
load("/chart2/qa/extras/data/xlsx/", "chart-hatch-fill.xlsx");
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
CPPUNIT_ASSERT(xPropSet.is());
drawing::FillStyle eStyle = xPropSet->getPropertyValue("FillStyle").get<drawing::FillStyle>();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Chart background fill in this xlsx should be loaded as hatch fill.",
drawing::FillStyle_HATCH, eStyle);
uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
CPPUNIT_ASSERT(xDataSeries.is());
uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW);
OUString sHatchName;
xPropertySet->getPropertyValue("HatchName") >>= sHatchName;
CPPUNIT_ASSERT(!sHatchName.isEmpty());
}
void Chart2ImportTest::testAxisTextRotationXLSX()
{
load("/chart2/qa/extras/data/xlsx/", "axis-label-rotation.xlsx");
......
......@@ -71,7 +71,7 @@ enum class ShapeProperty
FillBitmapOffsetX,
FillBitmapOffsetY,
FillBitmapRectanglePoint,
FillHatch,
FillHatch, /// Explicit fill hatch or name of a fill hatch stored in a global container.
ShadowXDistance,
FillBitmapName,
FillBackground,
......@@ -87,12 +87,13 @@ struct OOX_DLLPUBLIC ShapePropertyInfo
bool const mbNamedLineDash; /// True = use named line dash instead of explicit line dash.
bool const mbNamedFillGradient; /// True = use named fill gradient instead of explicit fill gradient.
bool const mbNamedFillBitmap; /// True = use named fill bitmap instead of explicit fill bitmap.
bool const mbNamedFillHatch; /// True = use named fill hatch instead of explicit fill hatch.
static ShapePropertyInfo DEFAULT; /// Default property info (used as default parameter of other methods).
explicit ShapePropertyInfo(const ShapePropertyIds& rnPropertyIds,
bool bNamedLineMarker, bool bNamedLineDash,
bool bNamedFillGradient, bool bNamedFillBitmap);
bool bNamedFillGradient, bool bNamedFillBitmap, bool bNamedFillHatch);
bool has(ShapeProperty ePropId) const
{
......@@ -147,6 +148,8 @@ private:
bool setFillBitmap( sal_Int32 nPropId, const css::uno::Any& rValue );
/** Sets an explicit fill bitmap and pushes the name to FillBitmapName */
bool setFillBitmapName( const css::uno::Any& rValue );
/** Sets an explicit fill hatch, or creates a named fill hatch. */
bool setFillHatch( sal_Int32 nPropId, const css::uno::Any& rValue );
// not implemented, to prevent implicit conversion from enum to int
css::uno::Any& operator[]( ShapeProperty ePropId ) = delete;
......
......@@ -32,6 +32,7 @@ namespace com { namespace sun { namespace star {
namespace graphic { class XGraphic; }
namespace container { class XNameContainer; }
namespace drawing { struct LineDash; }
namespace drawing { struct Hatch; }
namespace drawing { struct PolyPolygonBezierCoords; }
namespace lang { class XMultiServiceFactory; }
} } }
......@@ -105,6 +106,8 @@ public:
OUString insertTransGrandient( const css::awt::Gradient& rGradient );
OUString insertFillHatch( const css::drawing::Hatch& rHatch );
/** Inserts a new named fill graphic, returns the bitmap name, based on
an internal constant name with a new unused index appended. */
OUString insertFillBitmapXGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
......@@ -117,6 +120,7 @@ private:
ObjectContainer maGradientContainer; ///< Contains all named fill gradients.
ObjectContainer maTransGradContainer; ///< Contains all named transparency Gradients.
ObjectContainer maBitmapUrlContainer; ///< Contains all named fill bitmap URLs.
ObjectContainer maHatchContainer; ///< Contains all named fill hatches.
};
......
......@@ -449,7 +449,8 @@ static const ShapePropertyIds spnCommonPropIds =
PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_INVALID, PROP_FillGradientName,
PROP_FillBitmapName, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint
PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint,
PROP_FillHatchName
};
static const ShapePropertyIds spnLinearPropIds =
......@@ -458,7 +459,8 @@ static const ShapePropertyIds spnLinearPropIds =
PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
PROP_INVALID, PROP_INVALID, PROP_INVALID
PROP_INVALID, PROP_INVALID, PROP_INVALID,
PROP_INVALID
};
static const ShapePropertyIds spnFilledPropIds =
......@@ -487,15 +489,15 @@ static const ShapePropertyIds spnFilledPropIds =
PROP_FillBitmapPositionOffsetX,
PROP_FillBitmapPositionOffsetY,
PROP_FillBitmapRectanglePoint,
PROP_FillHatch
PROP_HatchName
};
/** Property info for common chart objects, to be used in ShapePropertyMap. */
static const ShapePropertyInfo saCommonPropInfo( spnCommonPropIds, false, true, true, true );
static const ShapePropertyInfo saCommonPropInfo( spnCommonPropIds, false, true, true, true, true );
/** Property info for linear data series, to be used in ShapePropertyMap. */
static const ShapePropertyInfo saLinearPropInfo( spnLinearPropIds, false, true, true, true );
static const ShapePropertyInfo saLinearPropInfo( spnLinearPropIds, false, true, true, true, true );
/** Property info for filled data series, to be used in ShapePropertyMap. */
static const ShapePropertyInfo saFilledPropInfo( spnFilledPropIds, false, true, true, true );
static const ShapePropertyInfo saFilledPropInfo( spnFilledPropIds, false, true, true, true, true );
/** Contains information about formatting of a specific chart object type. */
struct ObjectTypeFormatEntry
......
......@@ -22,6 +22,7 @@
#include <com/sun/star/awt/Gradient.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/drawing/LineDash.hpp>
#include <com/sun/star/drawing/Hatch.hpp>
#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
......@@ -53,15 +54,16 @@ static const ShapePropertyIds spnDefaultShapeIds =
} // namespace
ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false, false );
ShapePropertyInfo::ShapePropertyInfo( const ShapePropertyIds& rnPropertyIds,
bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmap ) :
bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmap, bool bNamedFillHatch ) :
mrPropertyIds(rnPropertyIds),
mbNamedLineMarker( bNamedLineMarker ),
mbNamedLineDash( bNamedLineDash ),
mbNamedFillGradient( bNamedFillGradient ),
mbNamedFillBitmap( bNamedFillBitmap )
mbNamedFillBitmap( bNamedFillBitmap ),
mbNamedFillHatch( bNamedFillHatch )
{
}
......@@ -109,6 +111,9 @@ bool ShapePropertyMap::setAnyProperty( ShapeProperty ePropId, const Any& rValue
case ShapeProperty::FillBitmapName:
return setFillBitmapName(rValue);
case ShapeProperty::FillHatch:
return setFillHatch( nPropId, rValue );
default:; // suppress compiler warnings
}
......@@ -168,6 +173,22 @@ bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
return false;
}
bool ShapePropertyMap::setFillHatch( sal_Int32 nPropId, const Any& rValue )
{
// push hatch explicitly
if( !maShapePropInfo.mbNamedFillHatch )
return setAnyProperty( nPropId, rValue );
// create named hatch and push its name
if( rValue.has< Hatch >() )
{
OUString aHatchName = mrModelObjHelper.insertFillHatch( rValue.get< Hatch >() );
return !aHatchName.isEmpty() && setProperty( nPropId, aHatchName );
}
return false;
}
bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
{
// create named gradient and push its name
......
......@@ -22,6 +22,7 @@
#include <com/sun/star/awt/Gradient.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/drawing/LineDash.hpp>
#include <com/sun/star/drawing/Hatch.hpp>
#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
......@@ -92,13 +93,15 @@ static const OUStringLiteral gaDashNameBase( "msLineDash " ); ///< Bas
static const OUStringLiteral gaGradientNameBase( "msFillGradient " ); ///< Base name for all named fill gradients.
static const OUStringLiteral gaTransGradNameBase( "msTransGradient " ); ///< Base name for all named fill gradients.
static const OUStringLiteral gaBitmapUrlNameBase( "msFillBitmap " ); ///< Base name for all named fill bitmap URLs.
static const OUStringLiteral gaHatchNameBase( "msFillHatch " ); ///< Base name for all named fill hatches.
ModelObjectHelper::ModelObjectHelper( const Reference< XMultiServiceFactory >& rxModelFactory ) :
maMarkerContainer( rxModelFactory, "com.sun.star.drawing.MarkerTable" ),
maDashContainer( rxModelFactory, "com.sun.star.drawing.DashTable" ),
maGradientContainer( rxModelFactory, "com.sun.star.drawing.GradientTable" ),
maTransGradContainer( rxModelFactory, "com.sun.star.drawing.TransparencyGradientTable" ),
maBitmapUrlContainer( rxModelFactory, "com.sun.star.drawing.BitmapTable" )
maTransGradContainer( rxModelFactory, "com.sun.star.drawing.TransparencyGradientTable" ),
maBitmapUrlContainer( rxModelFactory, "com.sun.star.drawing.BitmapTable" ),
maHatchContainer( rxModelFactory, "com.sun.star.drawing.HatchTable" )
{
}
......@@ -138,6 +141,11 @@ OUString ModelObjectHelper::insertFillBitmapXGraphic(uno::Reference<graphic::XGr
return OUString();
}
OUString ModelObjectHelper::insertFillHatch( const Hatch& rHatch )
{
return maHatchContainer.insertObject( gaHatchNameBase, Any( rHatch ), true );
}
uno::Reference<awt::XBitmap> ModelObjectHelper::getFillBitmap(OUString const & rGraphicName)
{
uno::Reference<awt::XBitmap> xBitmap;
......
......@@ -172,7 +172,7 @@ void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
oox::drawingml::ShapePropertyIds aPropertyIds = oox::drawingml::ShapePropertyInfo::DEFAULT.mrPropertyIds;
aPropertyIds[oox::drawingml::ShapeProperty::FillGradient] = PROP_FillGradientName;
oox::drawingml::ShapePropertyInfo aPropInfo( aPropertyIds, true, false, true, false );
oox::drawingml::ShapePropertyInfo aPropInfo( aPropertyIds, true, false, true, false, false );
oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper(), aPropInfo );
mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
......
......@@ -171,6 +171,7 @@ FillColor
FillGradient
FillGradientName
FillHatch
FillHatchName
FillStyle
FillTransparence
FillTransparenceGradient
......@@ -202,6 +203,7 @@ GapwidthSequence
GenerateVbaEvents
Geometry3D
GradientName
HatchName
Graphic
GraphicBitmap
GraphicColorMode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment