summaryrefslogtreecommitdiff
path: root/drawinglayer/source/texture
diff options
context:
space:
mode:
authorArmin Le Grand <alg@apache.org>2012-10-16 08:44:02 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-06-11 20:00:34 +0100
commit37aa7d81aacaae12dfe0fd2ade2779235bbf72f1 (patch)
treebaf84cf5f8fcf62221dd75869d507d2396ae690b /drawinglayer/source/texture
parente72e1c110ad42b779afbe74b47ca35c1849e06b2 (diff)
Resolves: #i121194# Better support for graphic fill styles...
which are not bitmaps (svg, metafiles, ..) (cherry picked from commit 7a652a2b2ab5e0d37e32185c8c5fac3af482bb76) Conflicts: drawinglayer/Library_drawinglayer.mk drawinglayer/Package_inc.mk drawinglayer/inc/drawinglayer/attribute/fillgraphicattribute.hxx drawinglayer/inc/drawinglayer/attribute/sdrfillattribute.hxx drawinglayer/inc/drawinglayer/attribute/sdrfillgraphicattribute.hxx drawinglayer/inc/drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx drawinglayer/inc/drawinglayer/primitive2d/fillgraphicprimitive2d.hxx drawinglayer/inc/drawinglayer/primitive2d/polypolygonprimitive2d.hxx drawinglayer/inc/drawinglayer/primitive3d/textureprimitive3d.hxx drawinglayer/inc/drawinglayer/processor2d/vclprocessor2d.hxx drawinglayer/inc/drawinglayer/texture/texture.hxx drawinglayer/inc/drawinglayer/texture/texture3d.hxx drawinglayer/source/attribute/fillbitmapattribute.cxx drawinglayer/source/attribute/sdrfillattribute.cxx drawinglayer/source/attribute/sdrfillgraphicattribute.cxx drawinglayer/source/primitive2d/fillbitmapprimitive2d.cxx drawinglayer/source/primitive2d/graphicprimitive2d.cxx drawinglayer/source/primitive2d/polypolygonprimitive2d.cxx drawinglayer/source/processor2d/canvasprocessor.cxx svx/inc/svx/sdr/primitive2d/sdrattributecreator.hxx svx/source/sdr/contact/objectcontacttools.cxx vcl/inc/vcl/graph.hxx unused file _vclmetafileprocessor2d.cxx deleted, was added by error (cherry picked from commit ed0d53f8283cd3ce579a90b599118884d0db6119) Conflicts: drawinglayer/source/processor2d/_vclmetafileprocessor2d.cxx Corrected canvasProcessor usage (cherry picked from commit 7903c33f31c457eb6ff506958c4233f2a5d39bcf) Conflicts: svx/source/sdr/contact/objectcontacttools.cxx Change-Id: I80008050b98dafc92fde043524843c13a75fe22c d2fa667d7c127b4d735334e56093d1d4553b0a5b e20c60c7d6472da1295a162d9a629be998861f62
Diffstat (limited to 'drawinglayer/source/texture')
-rw-r--r--drawinglayer/source/texture/texture.cxx129
-rw-r--r--drawinglayer/source/texture/texture3d.cxx217
2 files changed, 270 insertions, 76 deletions
diff --git a/drawinglayer/source/texture/texture.cxx b/drawinglayer/source/texture/texture.cxx
index f69c9736ac40..d11026143c5f 100644
--- a/drawinglayer/source/texture/texture.cxx
+++ b/drawinglayer/source/texture/texture.cxx
@@ -603,19 +603,16 @@ namespace drawinglayer
namespace texture
{
GeoTexSvxTiled::GeoTexSvxTiled(
- const basegfx::B2DPoint& rTopLeft,
- const basegfx::B2DVector& rSize)
- : maTopLeft(rTopLeft),
- maSize(rSize)
+ const basegfx::B2DRange& rRange,
+ double fOffsetX,
+ double fOffsetY)
+ : maRange(rRange),
+ mfOffsetX(basegfx::clamp(fOffsetX, 0.0, 1.0)),
+ mfOffsetY(basegfx::clamp(fOffsetY, 0.0, 1.0))
{
- if(basegfx::fTools::lessOrEqual(maSize.getX(), 0.0))
- {
- maSize.setX(1.0);
- }
-
- if(basegfx::fTools::lessOrEqual(maSize.getY(), 0.0))
+ if(!basegfx::fTools::equalZero(mfOffsetX))
{
- maSize.setY(1.0);
+ mfOffsetY = 0.0;
}
}
@@ -626,48 +623,92 @@ namespace drawinglayer
bool GeoTexSvxTiled::operator==(const GeoTexSvx& rGeoTexSvx) const
{
const GeoTexSvxTiled* pCompare = dynamic_cast< const GeoTexSvxTiled* >(&rGeoTexSvx);
+
return (pCompare
- && maTopLeft == pCompare->maTopLeft
- && maSize == pCompare->maSize);
+ && maRange == pCompare->maRange
+ && mfOffsetX == pCompare->mfOffsetX
+ && mfOffsetY == pCompare->mfOffsetY);
}
void GeoTexSvxTiled::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
{
- double fStartX(maTopLeft.getX());
- double fStartY(maTopLeft.getY());
+ const double fWidth(maRange.getWidth());
- if(basegfx::fTools::more(fStartX, 0.0))
+ if(!basegfx::fTools::equalZero(fWidth))
{
- fStartX -= (floor(fStartX / maSize.getX()) + 1.0) * maSize.getX();
- }
-
- if(basegfx::fTools::less(fStartX + maSize.getX(), 0.0))
- {
- fStartX += floor(-fStartX / maSize.getX()) * maSize.getX();
- }
+ const double fHeight(maRange.getHeight());
- if(basegfx::fTools::more(fStartY, 0.0))
- {
- fStartY -= (floor(fStartY / maSize.getY()) + 1.0) * maSize.getY();
- }
-
- if(basegfx::fTools::less(fStartY + maSize.getY(), 0.0))
- {
- fStartY += floor(-fStartY / maSize.getY()) * maSize.getY();
- }
-
- for(double fPosY(fStartY); basegfx::fTools::less(fPosY, 1.0); fPosY += maSize.getY())
- {
- for(double fPosX(fStartX); basegfx::fTools::less(fPosX, 1.0); fPosX += maSize.getX())
+ if(!basegfx::fTools::equalZero(fHeight))
{
- basegfx::B2DHomMatrix aNew;
-
- aNew.set(0, 0, maSize.getX());
- aNew.set(1, 1, maSize.getY());
- aNew.set(0, 2, fPosX);
- aNew.set(1, 2, fPosY);
-
- rMatrices.push_back(aNew);
+ double fStartX(maRange.getMinX());
+ double fStartY(maRange.getMinY());
+ sal_Int32 nPosX(0);
+ sal_Int32 nPosY(0);
+
+ if(basegfx::fTools::more(fStartX, 0.0))
+ {
+ const sal_Int32 nDiff(static_cast<sal_Int32>(floor(fStartX / fWidth)) + 1);
+
+ nPosX -= nDiff;
+ fStartX -= nDiff * fWidth;
+ }
+
+ if(basegfx::fTools::less(fStartX + fWidth, 0.0))
+ {
+ const sal_Int32 nDiff(static_cast<sal_Int32>(floor(-fStartX / fWidth)));
+
+ nPosX += nDiff;
+ fStartX += nDiff * fWidth;
+ }
+
+ if(basegfx::fTools::more(fStartY, 0.0))
+ {
+ const sal_Int32 nDiff(static_cast<sal_Int32>(floor(fStartY / fHeight)) + 1);
+
+ nPosY -= nDiff;
+ fStartY -= nDiff * fHeight;
+ }
+
+ if(basegfx::fTools::less(fStartY + fHeight, 0.0))
+ {
+ const sal_Int32 nDiff(static_cast<sal_Int32>(floor(-fStartY / fHeight)));
+
+ nPosY += nDiff;
+ fStartY += nDiff * fHeight;
+ }
+
+ if(!basegfx::fTools::equalZero(mfOffsetY))
+ {
+ for(double fPosX(fStartX); basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth, nPosX++)
+ {
+ for(double fPosY(nPosX % 2 ? fStartY - fHeight + (mfOffsetY * fHeight) : fStartY);
+ basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight)
+ {
+ rMatrices.push_back(
+ basegfx::tools::createScaleTranslateB2DHomMatrix(
+ fWidth,
+ fHeight,
+ fPosX,
+ fPosY));
+ }
+ }
+ }
+ else
+ {
+ for(double fPosY(fStartY); basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight, nPosY++)
+ {
+ for(double fPosX(nPosY % 2 ? fStartX - fWidth + (mfOffsetX * fWidth) : fStartX);
+ basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth)
+ {
+ rMatrices.push_back(
+ basegfx::tools::createScaleTranslateB2DHomMatrix(
+ fWidth,
+ fHeight,
+ fPosX,
+ fPosY));
+ }
+ }
+ }
}
}
}
diff --git a/drawinglayer/source/texture/texture3d.cxx b/drawinglayer/source/texture/texture3d.cxx
index 88fa8bb6a6be..2e46508dbd71 100644
--- a/drawinglayer/source/texture/texture3d.cxx
+++ b/drawinglayer/source/texture/texture3d.cxx
@@ -27,7 +27,9 @@ namespace drawinglayer
{
namespace texture
{
- GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
+ GeoTexSvxMono::GeoTexSvxMono(
+ const basegfx::BColor& rSingleColor,
+ double fOpacity)
: maSingleColor(rSingleColor),
mfOpacity(fOpacity)
{
@@ -36,6 +38,7 @@ namespace drawinglayer
bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
{
const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
+
return (pCompare
&& maSingleColor == pCompare->maSingleColor
&& mfOpacity == pCompare->mfOpacity);
@@ -59,56 +62,144 @@ namespace drawinglayer
{
namespace texture
{
- GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
- : maBitmap(rBitmap),
- mpRead(0L),
- maTopLeft(rTopLeft),
- maSize(rSize),
+ GeoTexSvxBitmapEx::GeoTexSvxBitmapEx(
+ const BitmapEx& rBitmapEx,
+ const basegfx::B2DRange& rRange)
+ : maBitmapEx(rBitmapEx),
+ mpReadBitmap(0),
+ maTransparence(),
+ mpReadTransparence(0),
+ maTopLeft(rRange.getMinimum()),
+ maSize(rRange.getRange()),
mfMulX(0.0),
- mfMulY(0.0)
+ mfMulY(0.0),
+ mbIsAlpha(false),
+ mbIsTransparent(maBitmapEx.IsTransparent())
+ {
+ // #121194# Todo: use alpha channel, too (for 3d)
+ mpReadBitmap = maBitmapEx.GetBitmap().AcquireReadAccess();
+ OSL_ENSURE(mpReadBitmap, "GeoTexSvxBitmapEx: Got no read access to Bitmap (!)");
+
+ if(mbIsTransparent)
+ {
+ if(maBitmapEx.IsAlpha())
+ {
+ mbIsAlpha = true;
+ maTransparence = rBitmapEx.GetAlpha().GetBitmap();
+ }
+ else
+ {
+ maTransparence = rBitmapEx.GetMask();
+ }
+
+ mpReadTransparence = maTransparence.AcquireReadAccess();
+ }
+
+ mfMulX = (double)mpReadBitmap->Width() / maSize.getX();
+ mfMulY = (double)mpReadBitmap->Height() / maSize.getY();
+
+ if(maSize.getX() <= 1.0)
+ {
+ maSize.setX(1.0);
+ }
+
+ if(maSize.getY() <= 1.0)
+ {
+ maSize.setY(1.0);
+ }
+ }
+
+ GeoTexSvxBitmapEx::~GeoTexSvxBitmapEx()
{
- mpRead = maBitmap.AcquireReadAccess();
- OSL_ENSURE(mpRead, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
- mfMulX = (double)mpRead->Width() / maSize.getX();
- mfMulY = (double)mpRead->Height() / maSize.getY();
+ delete mpReadTransparence;
+ delete mpReadBitmap;
}
- GeoTexSvxBitmap::~GeoTexSvxBitmap()
+ sal_uInt8 GeoTexSvxBitmapEx::impGetTransparence(sal_Int32& rX, sal_Int32& rY) const
{
- delete mpRead;
+ switch(maBitmapEx.GetTransparentType())
+ {
+ case TRANSPARENT_NONE:
+ {
+ break;
+ }
+ case TRANSPARENT_COLOR:
+ {
+ const Color aColor(mpReadBitmap->GetColor(rY, rX));
+
+ if(maBitmapEx.GetTransparentColor() == aColor)
+ {
+ return 255;
+ }
+
+ break;
+ }
+ case TRANSPARENT_BITMAP:
+ {
+ OSL_ENSURE(mpReadTransparence, "OOps, transparence type Bitmap, but no read access created in the constructor (?)");
+ const BitmapColor aBitmapColor(mpReadTransparence->GetPixel(rY, rX));
+
+ if(mbIsAlpha)
+ {
+ return aBitmapColor.GetIndex();
+ }
+ else
+ {
+ if(0x00 != aBitmapColor.GetIndex())
+ {
+ return 255;
+ }
+ }
+ break;
+ }
+ }
+
+ return 0;
}
- bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
+ bool GeoTexSvxBitmapEx::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
{
- if(mpRead)
+ if(mpReadBitmap)
{
rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
- if(rX >= 0L && rX < mpRead->Width())
+ if(rX >= 0L && rX < mpReadBitmap->Width())
{
rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
- return (rY >= 0L && rY < mpRead->Height());
+ return (rY >= 0L && rY < mpReadBitmap->Height());
}
}
return false;
}
- void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
+ void GeoTexSvxBitmapEx::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
{
sal_Int32 nX, nY;
if(impIsValid(rUV, nX, nY))
{
const double fConvertColor(1.0 / 255.0);
- const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
+ const BitmapColor aBMCol(mpReadBitmap->GetColor(nY, nX));
const basegfx::BColor aBSource(
(double)aBMCol.GetRed() * fConvertColor,
(double)aBMCol.GetGreen() * fConvertColor,
(double)aBMCol.GetBlue() * fConvertColor);
rBColor = aBSource;
+
+ if(mbIsTransparent)
+ {
+ // when we have a transparence, make use of it
+ const sal_uInt8 aLuminance(impGetTransparence(nX, nY));
+
+ rfOpacity = ((double)(0xff - aLuminance) * (1.0 / 255.0));
+ }
+ else
+ {
+ rfOpacity = 1.0;
+ }
}
else
{
@@ -116,16 +207,28 @@ namespace drawinglayer
}
}
- void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
+ void GeoTexSvxBitmapEx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
{
sal_Int32 nX, nY;
if(impIsValid(rUV, nX, nY))
{
- const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
- const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
+ if(mbIsTransparent)
+ {
+ // this texture has an alpha part, use it
+ const sal_uInt8 aLuminance(impGetTransparence(nX, nY));
+ const double fNewOpacity((double)(0xff - aLuminance) * (1.0 / 255.0));
+
+ rfOpacity = 1.0 - ((1.0 - fNewOpacity) * (1.0 - rfOpacity));
+ }
+ else
+ {
+ // this texture is a color bitmap used as transparence map
+ const BitmapColor aBMCol(mpReadBitmap->GetColor(nY, nX));
+ const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
- rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
+ rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
+ }
}
else
{
@@ -141,24 +244,72 @@ namespace drawinglayer
{
namespace texture
{
- GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
- : GeoTexSvxBitmap(rBitmap, rTopLeft, rSize)
+ basegfx::B2DPoint GeoTexSvxBitmapExTiled::impGetCorrected(const basegfx::B2DPoint& rUV) const
+ {
+ double fX(rUV.getX() - maTopLeft.getX());
+ double fY(rUV.getY() - maTopLeft.getY());
+
+ if(mbUseOffsetX)
+ {
+ const sal_Int32 nCol(static_cast< sal_Int32 >((fY < 0.0 ? maSize.getY() -fY : fY) / maSize.getY()));
+
+ if(nCol % 2)
+ {
+ fX += mfOffsetX * maSize.getX();
+ }
+ }
+ else if(mbUseOffsetY)
+ {
+ const sal_Int32 nRow(static_cast< sal_Int32 >((fX < 0.0 ? maSize.getX() -fX : fX) / maSize.getX()));
+
+ if(nRow % 2)
+ {
+ fY += mfOffsetY * maSize.getY();
+ }
+ }
+
+ fX = fmod(fX, maSize.getX());
+ fY = fmod(fY, maSize.getY());
+
+ if(fX < 0.0)
+ {
+ fX += maSize.getX();
+ }
+
+ if(fY < 0.0)
+ {
+ fY += maSize.getY();
+ }
+
+ return basegfx::B2DPoint(fX + maTopLeft.getX(), fY + maTopLeft.getY());
+ }
+
+ GeoTexSvxBitmapExTiled::GeoTexSvxBitmapExTiled(
+ const BitmapEx& rBitmapEx,
+ const basegfx::B2DRange& rRange,
+ double fOffsetX,
+ double fOffsetY)
+ : GeoTexSvxBitmapEx(rBitmapEx, rRange),
+ mfOffsetX(basegfx::clamp(fOffsetX, 0.0, 1.0)),
+ mfOffsetY(basegfx::clamp(fOffsetY, 0.0, 1.0)),
+ mbUseOffsetX(!basegfx::fTools::equalZero(mfOffsetX)),
+ mbUseOffsetY(!mbUseOffsetX && !basegfx::fTools::equalZero(mfOffsetY))
{
}
- void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
+ void GeoTexSvxBitmapExTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
{
- if(mpRead)
+ if(mpReadBitmap)
{
- GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
+ GeoTexSvxBitmapEx::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
}
}
- void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
+ void GeoTexSvxBitmapExTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
{
- if(mpRead)
+ if(mpReadBitmap)
{
- GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
+ GeoTexSvxBitmapEx::modifyOpacity(impGetCorrected(rUV), rfOpacity);
}
}
} // end of namespace texture
@@ -170,7 +321,9 @@ namespace drawinglayer
{
namespace texture
{
- GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
+ GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(
+ const primitive3d::HatchTexturePrimitive3D& rPrimitive,
+ double fLogicPixelSize)
: mfLogicPixelSize(fLogicPixelSize),
mp0(0L),
mp1(0L),