You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
541 lines
15 KiB
541 lines
15 KiB
15 years ago
|
/*
|
||
|
Copyright (C) 2001-2003 KSVG Team
|
||
|
This file is part of the KDE project
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <cfloat>
|
||
|
|
||
|
#include <kdebug.h>
|
||
14 years ago
|
#include <tqimage.h>
|
||
15 years ago
|
|
||
|
#include "SVGMaskElement.h"
|
||
|
|
||
|
#include "SVGRectImpl.h"
|
||
|
#include "SVGDocumentImpl.h"
|
||
|
#include "SVGSVGElementImpl.h"
|
||
|
#include "SVGMaskElementImpl.h"
|
||
|
#include "SVGAnimatedLengthImpl.h"
|
||
|
#include "SVGAnimatedEnumerationImpl.h"
|
||
|
#include "SVGUnitConverter.h"
|
||
|
#include "SVGShapeImpl.h"
|
||
|
#include "SVGMatrixImpl.h"
|
||
|
#include "KSVGCanvas.h"
|
||
|
#include "CanvasItems.h"
|
||
|
#include "CanvasFactory.h"
|
||
|
#include "KSVGHelper.h"
|
||
|
|
||
|
#include <X11/Xos.h>
|
||
|
|
||
|
using namespace KSVG;
|
||
|
|
||
|
#include "SVGMaskElementImpl.lut.h"
|
||
|
#include "ksvg_scriptinterpreter.h"
|
||
|
#include "ksvg_ecma.h"
|
||
|
|
||
|
SVGMaskElementImpl::SVGMaskElementImpl(DOM::ElementImpl *impl) : SVGElementImpl(impl), SVGTestsImpl(), SVGLangSpaceImpl(), SVGExternalResourcesRequiredImpl(), SVGStylableImpl(this), SVGBBoxTarget()
|
||
|
{
|
||
|
KSVG_EMPTY_FLAGS
|
||
|
|
||
|
m_x = new SVGAnimatedLengthImpl(LENGTHMODE_WIDTH, this);
|
||
|
m_x->ref();
|
||
|
|
||
|
m_y = new SVGAnimatedLengthImpl(LENGTHMODE_HEIGHT, this);
|
||
|
m_y->ref();
|
||
|
|
||
|
m_width = new SVGAnimatedLengthImpl(LENGTHMODE_WIDTH, this);
|
||
|
m_width->ref();
|
||
|
|
||
|
m_height = new SVGAnimatedLengthImpl(LENGTHMODE_HEIGHT, this);
|
||
|
m_height->ref();
|
||
|
|
||
14 years ago
|
m_maskUnits = new SVGAnimatedEnumerationImpl();
|
||
|
m_maskUnits->ref();
|
||
15 years ago
|
|
||
14 years ago
|
m_maskContentUnits = new SVGAnimatedEnumerationImpl();
|
||
|
m_maskContentUnits->ref();
|
||
15 years ago
|
|
||
|
m_converter = new SVGUnitConverter();
|
||
|
m_converter->add(m_x);
|
||
|
m_converter->add(m_y);
|
||
|
m_converter->add(m_width);
|
||
|
m_converter->add(m_height);
|
||
|
|
||
|
m_canvas = 0;
|
||
|
|
||
14 years ago
|
m_maskCache.setMaxTotalCost(1024 * 1024);
|
||
15 years ago
|
}
|
||
|
|
||
|
SVGMaskElementImpl::~SVGMaskElementImpl()
|
||
|
{
|
||
|
if(m_x)
|
||
|
m_x->deref();
|
||
|
if(m_y)
|
||
|
m_y->deref();
|
||
|
if(m_width)
|
||
|
m_width->deref();
|
||
|
if(m_height)
|
||
|
m_height->deref();
|
||
14 years ago
|
if(m_maskUnits)
|
||
|
m_maskContentUnits->deref();
|
||
|
if(m_maskUnits)
|
||
|
m_maskContentUnits->deref();
|
||
15 years ago
|
delete m_converter;
|
||
|
if(m_canvas)
|
||
|
delete m_canvas;
|
||
|
}
|
||
|
|
||
14 years ago
|
SVGAnimatedEnumerationImpl *SVGMaskElementImpl::maskUnits() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return m_maskUnits;
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
SVGAnimatedEnumerationImpl *SVGMaskElementImpl::maskContentUnits() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return m_maskContentUnits;
|
||
15 years ago
|
}
|
||
|
|
||
|
SVGAnimatedLengthImpl *SVGMaskElementImpl::x() const
|
||
|
{
|
||
|
return m_x;
|
||
|
}
|
||
|
|
||
|
SVGAnimatedLengthImpl *SVGMaskElementImpl::y() const
|
||
|
{
|
||
|
return m_y;
|
||
|
}
|
||
|
|
||
|
SVGAnimatedLengthImpl *SVGMaskElementImpl::width() const
|
||
|
{
|
||
|
return m_width;
|
||
|
}
|
||
|
|
||
|
SVGAnimatedLengthImpl *SVGMaskElementImpl::height() const
|
||
|
{
|
||
|
return m_height;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
@namespace KSVG
|
||
|
@begin SVGMaskElementImpl::s_hashTable 7
|
||
14 years ago
|
maskUnits SVGMaskElementImpl::MaskUnits DontDelete|ReadOnly
|
||
|
maskContentUnits SVGMaskElementImpl::MaskContentUnits DontDelete|ReadOnly
|
||
15 years ago
|
x SVGMaskElementImpl::X DontDelete|ReadOnly
|
||
|
y SVGMaskElementImpl::Y DontDelete|ReadOnly
|
||
|
width SVGMaskElementImpl::Width DontDelete|ReadOnly
|
||
|
height SVGMaskElementImpl::Height DontDelete|ReadOnly
|
||
|
@end
|
||
|
*/
|
||
|
Value SVGMaskElementImpl::getValueProperty(ExecState *exec, int token) const
|
||
|
{
|
||
|
KSVG_CHECK_ATTRIBUTE
|
||
|
|
||
|
switch(token)
|
||
|
{
|
||
|
case MaskUnits:
|
||
|
if(!attributeMode)
|
||
14 years ago
|
return m_maskUnits->cache(exec);
|
||
15 years ago
|
else
|
||
14 years ago
|
return Number(m_maskUnits->baseVal());
|
||
15 years ago
|
case MaskContentUnits:
|
||
|
if(!attributeMode)
|
||
14 years ago
|
return m_maskContentUnits->cache(exec);
|
||
15 years ago
|
else
|
||
14 years ago
|
return Number(m_maskContentUnits->baseVal());
|
||
15 years ago
|
case X:
|
||
|
if(!attributeMode)
|
||
|
return m_x->cache(exec);
|
||
|
else
|
||
|
return Number(m_x->baseVal()->value());
|
||
|
case Y:
|
||
|
if(!attributeMode)
|
||
|
return m_y->cache(exec);
|
||
|
else
|
||
|
return Number(m_y->baseVal()->value());
|
||
|
case Width:
|
||
|
if(!attributeMode)
|
||
|
return m_width->cache(exec);
|
||
|
else
|
||
|
return Number(m_width->baseVal()->value());
|
||
|
|
||
|
case Height:
|
||
|
if(!attributeMode)
|
||
|
return m_height->cache(exec);
|
||
|
else
|
||
|
return Number(m_height->baseVal()->value());
|
||
|
default:
|
||
|
kdWarning() << "Unhandled token in " << k_funcinfo << " : " << token << endl;
|
||
|
return Undefined();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void SVGMaskElementImpl::putValueProperty(ExecState *exec, int token, const Value &value, int attr)
|
||
|
{
|
||
|
// This class has just ReadOnly properties, only with the Internal flag set
|
||
|
// it's allowed to modify those.
|
||
|
if(!(attr & KJS::Internal))
|
||
|
return;
|
||
|
|
||
|
switch(token)
|
||
|
{
|
||
|
case MaskUnits:
|
||
|
if(value.toString(exec).qstring() == "objectBoundingBox")
|
||
14 years ago
|
m_maskUnits->setBaseVal(SVGMaskElement::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
|
||
15 years ago
|
else
|
||
14 years ago
|
m_maskUnits->setBaseVal(SVGMaskElement::SVG_UNIT_TYPE_USERSPACEONUSE);
|
||
15 years ago
|
break;
|
||
|
case MaskContentUnits:
|
||
|
if(value.toString(exec).qstring() == "objectBoundingBox")
|
||
14 years ago
|
m_maskContentUnits->setBaseVal(SVGMaskElement::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
|
||
15 years ago
|
else
|
||
14 years ago
|
m_maskContentUnits->setBaseVal(SVGMaskElement::SVG_UNIT_TYPE_USERSPACEONUSE);
|
||
15 years ago
|
break;
|
||
|
case X:
|
||
|
converter()->modify(x(), value.toString(exec).qstring());
|
||
|
break;
|
||
|
case Y:
|
||
|
converter()->modify(y(), value.toString(exec).qstring());
|
||
|
break;
|
||
|
case Width:
|
||
|
converter()->modify(width(), value.toString(exec).qstring());
|
||
|
break;
|
||
|
case Height:
|
||
|
converter()->modify(height(), value.toString(exec).qstring());
|
||
|
break;
|
||
|
default:
|
||
|
kdWarning() << "Unhandled token in " << k_funcinfo << " : " << token << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
SVGRectImpl *SVGMaskElementImpl::getBBox()
|
||
|
{
|
||
|
SVGRectImpl *ret = SVGSVGElementImpl::createSVGRect();
|
||
|
ret->setX(m_x->baseVal()->value());
|
||
|
ret->setY(m_y->baseVal()->value());
|
||
|
ret->setWidth(m_width->baseVal()->value());
|
||
|
ret->setHeight(m_height->baseVal()->value());
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
void SVGMaskElementImpl::setAttributes()
|
||
|
{
|
||
|
SVGElementImpl::setAttributes();
|
||
|
|
||
|
// Spec: if attribute not specified, use objectBoundingBox
|
||
|
if(KSVG_TOKEN_NOT_PARSED(MaskUnits))
|
||
|
KSVG_SET_ALT_ATTRIBUTE(MaskUnits, "objectBoundingBox")
|
||
|
|
||
|
// Spec: if attribute not specified, use userSpaceOnUse
|
||
|
if(KSVG_TOKEN_NOT_PARSED(MaskContentUnits))
|
||
|
KSVG_SET_ALT_ATTRIBUTE(MaskContentUnits, "userSpaceOnUse")
|
||
|
|
||
|
// Spec: if attribute not specified, use "-10%"
|
||
|
if(KSVG_TOKEN_NOT_PARSED(X))
|
||
|
KSVG_SET_ALT_ATTRIBUTE(X, "-10%");
|
||
|
|
||
|
// Spec: if attribute not specified, use "-10%"
|
||
|
if(KSVG_TOKEN_NOT_PARSED(Y))
|
||
|
KSVG_SET_ALT_ATTRIBUTE(Y, "-10%");
|
||
|
|
||
|
// Spec: if attribute not specified, use "120%"
|
||
|
if(KSVG_TOKEN_NOT_PARSED(Width))
|
||
|
KSVG_SET_ALT_ATTRIBUTE(Width, "120%");
|
||
|
|
||
|
// Spec: if attribute not specified, use "120%"
|
||
|
if(KSVG_TOKEN_NOT_PARSED(Height))
|
||
|
KSVG_SET_ALT_ATTRIBUTE(Height, "120%");
|
||
|
}
|
||
|
|
||
|
SVGMaskElementImpl::Mask SVGMaskElementImpl::createMask(SVGShapeImpl *referencingElement, int imageWidth, int imageHeight)
|
||
|
{
|
||
14 years ago
|
converter()->finalize(referencingElement, ownerSVGElement(), maskUnits()->baseVal());
|
||
15 years ago
|
|
||
14 years ago
|
TQ_UINT32 *imageBits = new TQ_UINT32[imageWidth * imageHeight];
|
||
15 years ago
|
|
||
|
if(m_canvas == 0)
|
||
|
m_canvas = CanvasFactory::self()->loadCanvas(imageWidth, imageHeight);
|
||
|
|
||
|
m_canvas->setup(reinterpret_cast<unsigned char *>(imageBits), imageWidth, imageHeight);
|
||
14 years ago
|
m_canvas->setBackgroundColor(tqRgba(0, 0, 0, 0));
|
||
15 years ago
|
|
||
|
SVGMatrixImpl *baseMatrix = SVGSVGElementImpl::createSVGMatrix();
|
||
|
|
||
13 years ago
|
// Set the scale to map the mask onto the image
|
||
15 years ago
|
double xScale = static_cast<double>(imageWidth) / width()->baseVal()->value();
|
||
|
double yScale = static_cast<double>(imageHeight) / height()->baseVal()->value();
|
||
|
|
||
|
baseMatrix->scaleNonUniform(xScale, yScale);
|
||
|
|
||
|
SVGRectImpl *bbox = referencingElement->getBBox();
|
||
|
|
||
14 years ago
|
if(maskUnits()->baseVal() == SVGMaskElement::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
|
||
15 years ago
|
baseMatrix->translate(-(bbox->x() + x()->baseVal()->value()), -(bbox->y() + y()->baseVal()->value()));
|
||
|
else
|
||
|
baseMatrix->translate(-x()->baseVal()->value(), -y()->baseVal()->value());
|
||
|
|
||
14 years ago
|
if(maskContentUnits()->baseVal() == SVGMaskElement::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
|
||
15 years ago
|
{
|
||
|
baseMatrix->translate(bbox->x(), bbox->y());
|
||
|
baseMatrix->scaleNonUniform(bbox->width(), bbox->height());
|
||
|
}
|
||
|
|
||
|
for(DOM::Node node = firstChild(); !node.isNull(); node = node.nextSibling())
|
||
|
{
|
||
|
SVGElementImpl *element = ownerDoc()->getElementFromHandle(node.handle());
|
||
13 years ago
|
SVGShapeImpl *shape = dynamic_cast<SVGShapeImpl *>(element);
|
||
15 years ago
|
SVGTestsImpl *tests = dynamic_cast<SVGTestsImpl *>(element);
|
||
|
SVGStylableImpl *style = dynamic_cast<SVGStylableImpl *>(element);
|
||
|
|
||
|
bool ok = tests ? tests->ok() : true;
|
||
13 years ago
|
if(element && shape && style && ok && style->getVisible() && style->getDisplay())
|
||
15 years ago
|
{
|
||
|
SVGLocatableImpl *locatable = dynamic_cast<SVGLocatableImpl *>(element);
|
||
|
if(locatable)
|
||
|
locatable->updateCachedScreenCTM(baseMatrix);
|
||
|
|
||
|
element->createItem(m_canvas);
|
||
13 years ago
|
if(shape->item())
|
||
15 years ago
|
{
|
||
13 years ago
|
shape->item()->setReferenced(true);
|
||
|
m_canvas->invalidate(shape->item(), true);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
m_canvas->update(float(1));
|
||
|
|
||
|
for(DOM::Node node = firstChild(); !node.isNull(); node = node.nextSibling())
|
||
|
{
|
||
|
SVGElementImpl *element = ownerDoc()->getElementFromHandle(node.handle());
|
||
13 years ago
|
SVGShapeImpl *shape = dynamic_cast<SVGShapeImpl *>(element);
|
||
15 years ago
|
SVGTestsImpl *tests = dynamic_cast<SVGTestsImpl *>(element);
|
||
|
SVGStylableImpl *style = dynamic_cast<SVGStylableImpl *>(element);
|
||
|
|
||
|
bool ok = tests ? tests->ok() : true;
|
||
13 years ago
|
if(element && shape && style && ok && style->getVisible() && style->getDisplay())
|
||
15 years ago
|
{
|
||
13 years ago
|
if(shape)
|
||
|
shape->removeItem(m_canvas);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
{
|
||
|
// Note: r and b reversed
|
||
14 years ago
|
//TQImage maskImage(reinterpret_cast<unsigned char *>(imageBits), imageWidth, imageHeight, 32, 0, 0, TQImage::IgnoreEndian);
|
||
|
//maskImage.setAlphaBuffer(true);
|
||
13 years ago
|
//maskImage.save("mask.png", "PNG");
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQByteArray maskData(imageWidth * imageHeight);
|
||
15 years ago
|
const double epsilon = DBL_EPSILON;
|
||
|
|
||
13 years ago
|
// Convert the rgba image into an 8-bit mask, according to the specs.
|
||
15 years ago
|
for(int i = 0; i < imageWidth * imageHeight; i++)
|
||
|
{
|
||
14 years ago
|
TQ_UINT32 rgba = imageBits[i];
|
||
15 years ago
|
|
||
|
#if X_BYTE_ORDER == X_LITTLE_ENDIAN
|
||
|
double r = (rgba & 0xff) / 255.0;
|
||
|
double g = ((rgba >> 8) & 0xff) / 255.0;
|
||
|
double b = ((rgba >> 16) & 0xff) / 255.0;
|
||
|
double a = ((rgba >> 24) & 0xff) / 255.0;
|
||
|
#else
|
||
|
double a = (rgba & 0xff) / 255.0;
|
||
|
double b = ((rgba >> 8) & 0xff) / 255.0;
|
||
|
double g = ((rgba >> 16) & 0xff) / 255.0;
|
||
|
double r = ((rgba >> 24) & 0xff) / 255.0;
|
||
|
#endif
|
||
|
|
||
|
// Remove pre-multiplication by alpha.
|
||
|
if(a > epsilon)
|
||
|
{
|
||
|
r /= a;
|
||
|
g /= a;
|
||
|
b /= a;
|
||
|
}
|
||
|
|
||
|
// Convert to linear RGB
|
||
|
r = KSVGHelper::linearRGBFromsRGB(int(r * 255 + 0.5)) / 255.0;
|
||
|
g = KSVGHelper::linearRGBFromsRGB(int(g * 255 + 0.5)) / 255.0;
|
||
|
b = KSVGHelper::linearRGBFromsRGB(int(b * 255 + 0.5)) / 255.0;
|
||
|
|
||
|
// Convert 'luminance to alpha'
|
||
|
double luminanceAlpha = 0.2125 * r + 0.7154 * g + 0.0721 * b;
|
||
|
|
||
|
// Multiply by alpha.
|
||
14 years ago
|
double maskValue = luminanceAlpha * a;
|
||
15 years ago
|
|
||
14 years ago
|
maskData[i] = static_cast<unsigned char>(maskValue * 255 + 0.5);
|
||
15 years ago
|
}
|
||
|
|
||
|
delete [] imageBits;
|
||
|
|
||
|
baseMatrix->deref();
|
||
|
bbox->deref();
|
||
|
|
||
13 years ago
|
// The screenToMask matrix is calculated each time the mask is used so we don't
|
||
15 years ago
|
// need to set it here.
|
||
14 years ago
|
TQWMatrix tempMatrix;
|
||
15 years ago
|
|
||
14 years ago
|
return Mask(maskData, tempMatrix, imageWidth, imageHeight);
|
||
15 years ago
|
}
|
||
|
|
||
|
SVGMaskElementImpl::Mask SVGMaskElementImpl::createMask(SVGShapeImpl *referencingElement)
|
||
|
{
|
||
14 years ago
|
converter()->finalize(referencingElement, ownerSVGElement(), maskUnits()->baseVal());
|
||
15 years ago
|
|
||
|
SVGMatrixImpl *refCTM = 0;
|
||
|
SVGLocatableImpl *locatableRef = dynamic_cast<SVGLocatableImpl *>(referencingElement);
|
||
|
if(locatableRef)
|
||
|
refCTM = locatableRef->getScreenCTM();
|
||
|
else
|
||
|
refCTM = SVGSVGElementImpl::createSVGMatrix();
|
||
|
|
||
|
double xScale, yScale;
|
||
|
|
||
|
refCTM->removeScale(&xScale, &yScale);
|
||
|
refCTM->deref();
|
||
|
|
||
|
int imageWidth = static_cast<int>(width()->baseVal()->value() * xScale + 0.5);
|
||
|
int imageHeight = static_cast<int>(height()->baseVal()->value() * yScale + 0.5);
|
||
|
|
||
13 years ago
|
Mask mask;
|
||
15 years ago
|
|
||
|
if(imageWidth > 0 && imageHeight > 0)
|
||
|
{
|
||
|
CacheKey key(referencingElement, imageWidth, imageHeight);
|
||
|
|
||
13 years ago
|
if(!m_maskCache.find(key, mask))
|
||
15 years ago
|
{
|
||
13 years ago
|
mask = createMask(referencingElement, imageWidth, imageHeight);
|
||
|
m_maskCache.insert(key, mask, imageWidth * imageHeight);
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
// Generate a mask-coordinates to screen-coordinates matrix
|
||
15 years ago
|
SVGMatrixImpl *matrix = 0;
|
||
|
if(locatableRef)
|
||
|
matrix = locatableRef->getScreenCTM();
|
||
|
else
|
||
|
matrix = SVGSVGElementImpl::createSVGMatrix();
|
||
|
|
||
14 years ago
|
if(maskUnits()->baseVal() == SVGMaskElement::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
|
||
15 years ago
|
{
|
||
|
SVGRectImpl *bbox = referencingElement->getBBox();
|
||
|
matrix->translate(bbox->x() + x()->baseVal()->value(), bbox->y() + y()->baseVal()->value());
|
||
|
bbox->deref();
|
||
|
}
|
||
|
else
|
||
|
matrix->translate(x()->baseVal()->value(), y()->baseVal()->value());
|
||
|
|
||
|
matrix->scaleNonUniform(1 / xScale, 1 / yScale);
|
||
|
|
||
14 years ago
|
TQWMatrix screenToMask = matrix->qmatrix().invert();
|
||
15 years ago
|
matrix->deref();
|
||
|
|
||
13 years ago
|
mask.setScreenToMask(screenToMask);
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
return mask;
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
TQByteArray SVGMaskElementImpl::maskRectangle(SVGShapeImpl *shape, const TQRect& screenRectangle)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQByteArray cumulativeMask;
|
||
15 years ago
|
|
||
|
do
|
||
|
{
|
||
13 years ago
|
SVGStylableImpl *style = dynamic_cast<SVGStylableImpl *>(shape);
|
||
15 years ago
|
|
||
|
if(style && style->hasMask())
|
||
|
{
|
||
13 years ago
|
SVGElementImpl *element = shape->ownerDoc()->rootElement()->getElementById(style->getMask());
|
||
15 years ago
|
|
||
|
if(element)
|
||
|
{
|
||
14 years ago
|
SVGMaskElementImpl *maskElement = dynamic_cast<SVGMaskElementImpl *>(element);
|
||
15 years ago
|
|
||
14 years ago
|
if(maskElement)
|
||
15 years ago
|
{
|
||
13 years ago
|
SVGMaskElementImpl::Mask mask = maskElement->createMask(shape);
|
||
15 years ago
|
|
||
13 years ago
|
if(!mask.isEmpty())
|
||
15 years ago
|
{
|
||
13 years ago
|
TQByteArray maskData = mask.rectangle(screenRectangle);
|
||
15 years ago
|
|
||
|
if(cumulativeMask.size() == 0)
|
||
14 years ago
|
cumulativeMask = maskData;
|
||
15 years ago
|
else
|
||
|
{
|
||
|
int size = cumulativeMask.size();
|
||
|
|
||
13 years ago
|
// Multiply into the cumulative mask (using fast divide by 255)
|
||
15 years ago
|
for(int i = 0; i < size; i++)
|
||
|
{
|
||
14 years ago
|
int tmp = maskData[i] * cumulativeMask[i] + 0x80;
|
||
15 years ago
|
cumulativeMask[i] = (tmp + (tmp >> 8)) >> 8;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
DOM::Node parentNode = shape->parentNode();
|
||
15 years ago
|
|
||
14 years ago
|
if(!parentNode.isNull())
|
||
15 years ago
|
{
|
||
13 years ago
|
SVGElementImpl *parent = shape->ownerDoc()->getElementFromHandle(parentNode.handle());
|
||
15 years ago
|
|
||
13 years ago
|
if(parent)
|
||
13 years ago
|
shape = dynamic_cast<SVGShapeImpl *>(parent);
|
||
15 years ago
|
else
|
||
13 years ago
|
shape = 0;
|
||
15 years ago
|
}
|
||
|
else
|
||
13 years ago
|
shape = 0;
|
||
15 years ago
|
|
||
13 years ago
|
} while(shape);
|
||
15 years ago
|
|
||
|
return cumulativeMask;
|
||
|
}
|
||
|
|
||
13 years ago
|
SVGMaskElementImpl::Mask::Mask(const TQByteArray& mask, const TQWMatrix& screenToMask, int width, int height)
|
||
|
: m_width(width), m_height(height), m_mask(mask), m_screenToMask(screenToMask)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
TQByteArray SVGMaskElementImpl::Mask::rectangle(int screenX, int screenY, int width, int height)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQByteArray rect(width * height);
|
||
15 years ago
|
|
||
|
for(int x = 0; x < width; x++)
|
||
|
{
|
||
|
for(int y = 0; y < height; y++)
|
||
|
{
|
||
|
rect[x + y * width] = value(screenX + x, screenY + y);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return rect;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQByteArray SVGMaskElementImpl::Mask::rectangle(const TQRect& rect)
|
||
15 years ago
|
{
|
||
|
return rectangle(rect.x(), rect.y(), rect.width(), rect.height());
|
||
|
}
|