mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 718266 - Simplify dasharray code. r=jwatt
This commit is contained in:
parent
23660a956c
commit
85497421d0
@ -100,73 +100,49 @@ nsSVGGeometryFrame::GetStrokeWidth()
|
|||||||
GetStyleSVG()->mStrokeWidth);
|
GetStyleSVG()->mStrokeWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
bool
|
||||||
nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount)
|
nsSVGGeometryFrame::GetStrokeDashData(FallibleTArray<gfxFloat>& dashes,
|
||||||
|
gfxFloat *dashOffset)
|
||||||
{
|
{
|
||||||
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
|
||||||
(mContent->IsNodeOfType(nsINode::eTEXT) ?
|
|
||||||
mContent->GetParent() : mContent);
|
|
||||||
*aDashes = nsnull;
|
|
||||||
*aCount = 0;
|
|
||||||
|
|
||||||
PRUint32 count = GetStyleSVG()->mStrokeDasharrayLength;
|
PRUint32 count = GetStyleSVG()->mStrokeDasharrayLength;
|
||||||
gfxFloat *dashes = nsnull;
|
if (!count || !dashes.SetLength(count)) {
|
||||||
|
return false;
|
||||||
if (count) {
|
|
||||||
const nsStyleCoord *dasharray = GetStyleSVG()->mStrokeDasharray;
|
|
||||||
nsPresContext *presContext = PresContext();
|
|
||||||
gfxFloat totalLength = 0.0f;
|
|
||||||
|
|
||||||
gfxFloat pathScale = 1.0;
|
|
||||||
|
|
||||||
if (mContent->Tag() == nsGkAtoms::path) {
|
|
||||||
pathScale = static_cast<nsSVGPathElement*>(mContent)->
|
|
||||||
GetPathLengthScale(nsSVGPathElement::eForStroking);
|
|
||||||
if (pathScale <= 0) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dashes = new gfxFloat[count];
|
|
||||||
if (dashes) {
|
|
||||||
for (PRUint32 i = 0; i < count; i++) {
|
|
||||||
dashes[i] =
|
|
||||||
nsSVGUtils::CoordToFloat(presContext,
|
|
||||||
ctx,
|
|
||||||
dasharray[i]) * pathScale;
|
|
||||||
if (dashes[i] < 0.0f) {
|
|
||||||
delete [] dashes;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
totalLength += dashes[i];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalLength == 0.0f) {
|
|
||||||
delete [] dashes;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aDashes = dashes;
|
|
||||||
*aCount = count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
gfxFloat pathScale = 1.0;
|
||||||
}
|
|
||||||
|
|
||||||
float
|
if (mContent->Tag() == nsGkAtoms::path) {
|
||||||
nsSVGGeometryFrame::GetStrokeDashoffset()
|
pathScale = static_cast<nsSVGPathElement*>(mContent)->
|
||||||
{
|
GetPathLengthScale(nsSVGPathElement::eForStroking);
|
||||||
|
if (pathScale <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
||||||
(mContent->IsNodeOfType(nsINode::eTEXT) ?
|
(mContent->IsNodeOfType(nsINode::eTEXT) ?
|
||||||
mContent->GetParent() : mContent);
|
mContent->GetParent() : mContent);
|
||||||
|
|
||||||
return
|
const nsStyleCoord *dasharray = GetStyleSVG()->mStrokeDasharray;
|
||||||
nsSVGUtils::CoordToFloat(PresContext(),
|
nsPresContext *presContext = PresContext();
|
||||||
ctx,
|
gfxFloat totalLength = 0.0;
|
||||||
GetStyleSVG()->mStrokeDashoffset);
|
|
||||||
|
for (PRUint32 i = 0; i < count; i++) {
|
||||||
|
dashes[i] =
|
||||||
|
nsSVGUtils::CoordToFloat(presContext,
|
||||||
|
ctx,
|
||||||
|
dasharray[i]) * pathScale;
|
||||||
|
if (dashes[i] < 0.0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
totalLength += dashes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
*dashOffset = nsSVGUtils::CoordToFloat(presContext,
|
||||||
|
ctx,
|
||||||
|
GetStyleSVG()->mStrokeDashoffset);
|
||||||
|
|
||||||
|
return (totalLength > 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PRUint16
|
PRUint16
|
||||||
@ -304,12 +280,10 @@ nsSVGGeometryFrame::SetupCairoStrokeHitGeometry(gfxContext *aContext)
|
|||||||
{
|
{
|
||||||
SetupCairoStrokeGeometry(aContext);
|
SetupCairoStrokeGeometry(aContext);
|
||||||
|
|
||||||
gfxFloat *dashArray;
|
AutoFallibleTArray<gfxFloat, 10> dashes;
|
||||||
PRUint32 count;
|
gfxFloat dashOffset;
|
||||||
GetStrokeDashArray(&dashArray, &count);
|
if (GetStrokeDashData(dashes, &dashOffset)) {
|
||||||
if (count > 0) {
|
aContext->SetDash(dashes.Elements(), dashes.Length(), dashOffset);
|
||||||
aContext->SetDash(dashArray, count, GetStrokeDashoffset());
|
|
||||||
delete [] dashArray;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,7 @@ protected:
|
|||||||
virtual PRUint16 GetHitTestFlags();
|
virtual PRUint16 GetHitTestFlags();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsresult GetStrokeDashArray(double **arr, PRUint32 *count);
|
bool GetStrokeDashData(FallibleTArray<gfxFloat>& dashes, gfxFloat *dashOffset);
|
||||||
float GetStrokeDashoffset();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the given 'fill-opacity' or 'stroke-opacity' value multiplied by
|
* Returns the given 'fill-opacity' or 'stroke-opacity' value multiplied by
|
||||||
|
Loading…
Reference in New Issue
Block a user