2007-03-22 10:30:00 -07:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
|
* License.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is IBM Corporation.
|
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
*
|
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
|
*
|
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
2009-04-02 13:29:31 -07:00
|
|
|
|
// include nsSVGUtils.h first to ensure definition of M_SQRT1_2 is picked up
|
|
|
|
|
#include "nsSVGUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
|
#include "nsIDOMSVGElement.h"
|
|
|
|
|
#include "nsIDOMSVGSVGElement.h"
|
|
|
|
|
#include "nsStyleCoord.h"
|
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
#include "nsSVGSVGElement.h"
|
|
|
|
|
#include "nsIContent.h"
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
#include "nsIURI.h"
|
|
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
#include "nsISVGGlyphFragmentLeaf.h"
|
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
#include "nsFrameList.h"
|
|
|
|
|
#include "nsISVGChildFrame.h"
|
|
|
|
|
#include "nsContentDLF.h"
|
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
#include "nsSVGFilterFrame.h"
|
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
2009-04-24 16:17:43 -07:00
|
|
|
|
#include "nsSVGInnerSVGFrame.h"
|
2009-01-04 17:19:38 -08:00
|
|
|
|
#include "nsSVGPreserveAspectRatio.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsSVGMatrix.h"
|
|
|
|
|
#include "nsSVGClipPathFrame.h"
|
|
|
|
|
#include "nsSVGMaskFrame.h"
|
|
|
|
|
#include "nsSVGContainerFrame.h"
|
2010-08-07 02:38:11 -07:00
|
|
|
|
#include "nsSVGTextContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsSVGLength2.h"
|
|
|
|
|
#include "nsGenericElement.h"
|
2009-06-26 13:13:07 -07:00
|
|
|
|
#include "nsSVGGraphicElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsAttrValue.h"
|
|
|
|
|
#include "nsSVGGeometryFrame.h"
|
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
|
#include "gfxRect.h"
|
|
|
|
|
#include "gfxImageSurface.h"
|
2007-04-18 14:09:31 -07:00
|
|
|
|
#include "gfxPlatform.h"
|
2007-05-16 08:14:19 -07:00
|
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
2007-06-25 09:12:35 -07:00
|
|
|
|
#include "nsIFontMetrics.h"
|
2007-12-03 20:40:52 -08:00
|
|
|
|
#include "nsIDOMSVGUnitTypes.h"
|
2008-08-07 18:34:43 -07:00
|
|
|
|
#include "nsSVGEffects.h"
|
2009-10-26 18:43:55 -07:00
|
|
|
|
#include "nsMathUtils.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2009-03-31 05:19:39 -07:00
|
|
|
|
#include "nsSVGGeometryFrame.h"
|
2009-08-20 14:52:47 -07:00
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2009-10-21 04:32:57 -07:00
|
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2009-12-28 22:34:27 -08:00
|
|
|
|
#include "prdtoa.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
|
#include "mozilla/dom/Element.h"
|
2010-11-24 01:35:21 -08:00
|
|
|
|
#include "gfxUtils.h"
|
2010-04-30 06:12:06 -07:00
|
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
2010-06-18 02:21:13 -07:00
|
|
|
|
gfxASurface *nsSVGUtils::gThebesComputationalSurface = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
// c = n / 255
|
|
|
|
|
// (c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055) * 255 + 0.5
|
|
|
|
|
static const PRUint8 glinearRGBTosRGBMap[256] = {
|
|
|
|
|
0, 13, 22, 28, 34, 38, 42, 46,
|
|
|
|
|
50, 53, 56, 59, 61, 64, 66, 69,
|
|
|
|
|
71, 73, 75, 77, 79, 81, 83, 85,
|
|
|
|
|
86, 88, 90, 92, 93, 95, 96, 98,
|
|
|
|
|
99, 101, 102, 104, 105, 106, 108, 109,
|
|
|
|
|
110, 112, 113, 114, 115, 117, 118, 119,
|
|
|
|
|
120, 121, 122, 124, 125, 126, 127, 128,
|
|
|
|
|
129, 130, 131, 132, 133, 134, 135, 136,
|
|
|
|
|
137, 138, 139, 140, 141, 142, 143, 144,
|
|
|
|
|
145, 146, 147, 148, 148, 149, 150, 151,
|
|
|
|
|
152, 153, 154, 155, 155, 156, 157, 158,
|
|
|
|
|
159, 159, 160, 161, 162, 163, 163, 164,
|
|
|
|
|
165, 166, 167, 167, 168, 169, 170, 170,
|
|
|
|
|
171, 172, 173, 173, 174, 175, 175, 176,
|
|
|
|
|
177, 178, 178, 179, 180, 180, 181, 182,
|
|
|
|
|
182, 183, 184, 185, 185, 186, 187, 187,
|
|
|
|
|
188, 189, 189, 190, 190, 191, 192, 192,
|
|
|
|
|
193, 194, 194, 195, 196, 196, 197, 197,
|
|
|
|
|
198, 199, 199, 200, 200, 201, 202, 202,
|
|
|
|
|
203, 203, 204, 205, 205, 206, 206, 207,
|
|
|
|
|
208, 208, 209, 209, 210, 210, 211, 212,
|
|
|
|
|
212, 213, 213, 214, 214, 215, 215, 216,
|
|
|
|
|
216, 217, 218, 218, 219, 219, 220, 220,
|
|
|
|
|
221, 221, 222, 222, 223, 223, 224, 224,
|
|
|
|
|
225, 226, 226, 227, 227, 228, 228, 229,
|
|
|
|
|
229, 230, 230, 231, 231, 232, 232, 233,
|
|
|
|
|
233, 234, 234, 235, 235, 236, 236, 237,
|
|
|
|
|
237, 238, 238, 238, 239, 239, 240, 240,
|
|
|
|
|
241, 241, 242, 242, 243, 243, 244, 244,
|
|
|
|
|
245, 245, 246, 246, 246, 247, 247, 248,
|
|
|
|
|
248, 249, 249, 250, 250, 251, 251, 251,
|
|
|
|
|
252, 252, 253, 253, 254, 254, 255, 255
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// c = n / 255
|
|
|
|
|
// c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4)) * 255 + 0.5
|
|
|
|
|
static const PRUint8 gsRGBToLinearRGBMap[256] = {
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 1,
|
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
|
1, 1, 2, 2, 2, 2, 2, 2,
|
|
|
|
|
2, 2, 3, 3, 3, 3, 3, 3,
|
|
|
|
|
4, 4, 4, 4, 4, 5, 5, 5,
|
|
|
|
|
5, 6, 6, 6, 6, 7, 7, 7,
|
|
|
|
|
8, 8, 8, 8, 9, 9, 9, 10,
|
|
|
|
|
10, 10, 11, 11, 12, 12, 12, 13,
|
|
|
|
|
13, 13, 14, 14, 15, 15, 16, 16,
|
|
|
|
|
17, 17, 17, 18, 18, 19, 19, 20,
|
|
|
|
|
20, 21, 22, 22, 23, 23, 24, 24,
|
|
|
|
|
25, 25, 26, 27, 27, 28, 29, 29,
|
|
|
|
|
30, 30, 31, 32, 32, 33, 34, 35,
|
|
|
|
|
35, 36, 37, 37, 38, 39, 40, 41,
|
|
|
|
|
41, 42, 43, 44, 45, 45, 46, 47,
|
|
|
|
|
48, 49, 50, 51, 51, 52, 53, 54,
|
|
|
|
|
55, 56, 57, 58, 59, 60, 61, 62,
|
|
|
|
|
63, 64, 65, 66, 67, 68, 69, 70,
|
|
|
|
|
71, 72, 73, 74, 76, 77, 78, 79,
|
|
|
|
|
80, 81, 82, 84, 85, 86, 87, 88,
|
|
|
|
|
90, 91, 92, 93, 95, 96, 97, 99,
|
|
|
|
|
100, 101, 103, 104, 105, 107, 108, 109,
|
|
|
|
|
111, 112, 114, 115, 116, 118, 119, 121,
|
|
|
|
|
122, 124, 125, 127, 128, 130, 131, 133,
|
|
|
|
|
134, 136, 138, 139, 141, 142, 144, 146,
|
|
|
|
|
147, 149, 151, 152, 154, 156, 157, 159,
|
|
|
|
|
161, 163, 164, 166, 168, 170, 171, 173,
|
|
|
|
|
175, 177, 179, 181, 183, 184, 186, 188,
|
|
|
|
|
190, 192, 194, 196, 198, 200, 202, 204,
|
|
|
|
|
206, 208, 210, 212, 214, 216, 218, 220,
|
|
|
|
|
222, 224, 226, 229, 231, 233, 235, 237,
|
|
|
|
|
239, 242, 244, 246, 248, 250, 253, 255
|
|
|
|
|
};
|
|
|
|
|
|
2009-03-09 18:20:17 -07:00
|
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
|
static PRBool gSMILEnabled;
|
|
|
|
|
static const char SMIL_PREF_STR[] = "svg.smil.enabled";
|
|
|
|
|
#endif // MOZ_SMIL
|
|
|
|
|
|
|
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
|
static int
|
|
|
|
|
SMILPrefChanged(const char *aPref, void *aClosure)
|
|
|
|
|
{
|
|
|
|
|
PRBool prefVal = nsContentUtils::GetBoolPref(SMIL_PREF_STR);
|
|
|
|
|
gSMILEnabled = prefVal;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
|
NS_SMILEnabled()
|
|
|
|
|
{
|
|
|
|
|
static PRBool sInitialized = PR_FALSE;
|
|
|
|
|
|
|
|
|
|
if (!sInitialized) {
|
|
|
|
|
/* check and register ourselves with the pref */
|
|
|
|
|
gSMILEnabled = nsContentUtils::GetBoolPref(SMIL_PREF_STR);
|
|
|
|
|
nsContentUtils::RegisterPrefCallback(SMIL_PREF_STR, SMILPrefChanged, nsnull);
|
|
|
|
|
|
|
|
|
|
sInitialized = PR_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gSMILEnabled;
|
|
|
|
|
}
|
|
|
|
|
#endif // MOZ_SMIL
|
|
|
|
|
|
2010-05-14 10:04:51 -07:00
|
|
|
|
Element*
|
2009-03-09 06:14:35 -07:00
|
|
|
|
nsSVGUtils::GetParentElement(nsIContent *aContent)
|
|
|
|
|
{
|
|
|
|
|
// XXXbz I _think_ this is right. We want to be using the binding manager
|
|
|
|
|
// that would have attached the binding that gives us our anonymous parent.
|
|
|
|
|
// That's the binding manager for the document we actually belong to, which
|
|
|
|
|
// is our owner doc.
|
|
|
|
|
nsIDocument* ownerDoc = aContent->GetOwnerDoc();
|
|
|
|
|
nsBindingManager* bindingManager =
|
|
|
|
|
ownerDoc ? ownerDoc->BindingManager() : nsnull;
|
|
|
|
|
|
|
|
|
|
if (bindingManager) {
|
|
|
|
|
// if we have a binding manager -- do we have an anonymous parent?
|
|
|
|
|
nsIContent *result = bindingManager->GetInsertionParent(aContent);
|
|
|
|
|
if (result) {
|
2010-05-14 10:04:51 -07:00
|
|
|
|
return result->AsElement();
|
2009-03-09 06:14:35 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// otherewise use the explicit one, whether it's null or not...
|
2010-05-14 10:04:51 -07:00
|
|
|
|
nsIContent* parent = aContent->GetParent();
|
2010-05-17 11:18:25 -07:00
|
|
|
|
return parent && parent->IsElement() ? parent->AsElement() : nsnull;
|
2009-03-09 06:14:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:12:35 -07:00
|
|
|
|
float
|
2010-04-30 06:12:06 -07:00
|
|
|
|
nsSVGUtils::GetFontSize(Element *aElement)
|
2007-06-25 09:12:35 -07:00
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
|
if (!aElement)
|
2009-09-14 13:12:37 -07:00
|
|
|
|
return 1.0f;
|
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
|
nsRefPtr<nsStyleContext> styleContext =
|
2010-04-30 06:12:06 -07:00
|
|
|
|
nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
|
|
|
|
|
nsnull, nsnull);
|
2009-08-20 14:52:47 -07:00
|
|
|
|
if (!styleContext) {
|
2010-07-16 14:42:12 -07:00
|
|
|
|
// ReportToConsole
|
2009-08-20 14:52:47 -07:00
|
|
|
|
NS_WARNING("Couldn't get style context for content in GetFontStyle");
|
2007-06-25 09:12:35 -07:00
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
|
return GetFontSize(styleContext);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::GetFontSize(nsIFrame *aFrame)
|
|
|
|
|
{
|
2009-08-20 14:52:47 -07:00
|
|
|
|
NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontSize");
|
|
|
|
|
return GetFontSize(aFrame->GetStyleContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::GetFontSize(nsStyleContext *aStyleContext)
|
|
|
|
|
{
|
|
|
|
|
NS_ABORT_IF_FALSE(aStyleContext, "NULL style context in GetFontSize");
|
|
|
|
|
|
|
|
|
|
nsPresContext *presContext = aStyleContext->PresContext();
|
|
|
|
|
NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontSize");
|
|
|
|
|
|
|
|
|
|
nscoord fontSize = aStyleContext->GetStyleFont()->mSize;
|
|
|
|
|
return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) /
|
|
|
|
|
presContext->TextZoom();
|
2007-06-25 09:12:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
2010-04-30 06:12:06 -07:00
|
|
|
|
nsSVGUtils::GetFontXHeight(Element *aElement)
|
2007-06-25 09:12:35 -07:00
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
|
if (!aElement)
|
2009-09-14 13:12:37 -07:00
|
|
|
|
return 1.0f;
|
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
|
nsRefPtr<nsStyleContext> styleContext =
|
2010-04-30 06:12:06 -07:00
|
|
|
|
nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
|
|
|
|
|
nsnull, nsnull);
|
2009-08-20 14:52:47 -07:00
|
|
|
|
if (!styleContext) {
|
2010-07-16 14:42:12 -07:00
|
|
|
|
// ReportToConsole
|
2009-08-20 14:52:47 -07:00
|
|
|
|
NS_WARNING("Couldn't get style context for content in GetFontStyle");
|
2007-06-25 09:12:35 -07:00
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
|
return GetFontXHeight(styleContext);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::GetFontXHeight(nsIFrame *aFrame)
|
|
|
|
|
{
|
2009-08-20 14:52:47 -07:00
|
|
|
|
NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontXHeight");
|
|
|
|
|
return GetFontXHeight(aFrame->GetStyleContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::GetFontXHeight(nsStyleContext *aStyleContext)
|
|
|
|
|
{
|
|
|
|
|
NS_ABORT_IF_FALSE(aStyleContext, "NULL style context in GetFontXHeight");
|
|
|
|
|
|
|
|
|
|
nsPresContext *presContext = aStyleContext->PresContext();
|
|
|
|
|
NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontXHeight");
|
|
|
|
|
|
2007-08-17 16:49:01 -07:00
|
|
|
|
nsCOMPtr<nsIFontMetrics> fontMetrics;
|
2009-08-20 14:52:47 -07:00
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
|
|
|
|
|
getter_AddRefs(fontMetrics));
|
2007-06-25 09:12:35 -07:00
|
|
|
|
|
|
|
|
|
if (!fontMetrics) {
|
2010-07-16 14:42:12 -07:00
|
|
|
|
// ReportToConsole
|
2007-06-25 09:12:35 -07:00
|
|
|
|
NS_WARNING("no FontMetrics in GetFontXHeight()");
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord xHeight;
|
|
|
|
|
fontMetrics->GetXHeight(xHeight);
|
2007-08-17 16:49:01 -07:00
|
|
|
|
return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) /
|
2009-08-20 14:52:47 -07:00
|
|
|
|
presContext->TextZoom();
|
2007-06-25 09:12:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::UnPremultiplyImageDataAlpha(PRUint8 *data,
|
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
for (PRInt32 y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
|
for (PRInt32 x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
|
PRUint8 *pixel = data + stride * y + 4 * x;
|
|
|
|
|
|
|
|
|
|
PRUint8 a = pixel[GFX_ARGB32_OFFSET_A];
|
|
|
|
|
if (a == 255)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (a) {
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] = (255 * pixel[GFX_ARGB32_OFFSET_B]) / a;
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] = (255 * pixel[GFX_ARGB32_OFFSET_G]) / a;
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] = (255 * pixel[GFX_ARGB32_OFFSET_R]) / a;
|
|
|
|
|
} else {
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] = 0;
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] = 0;
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::PremultiplyImageDataAlpha(PRUint8 *data,
|
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
for (PRInt32 y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
|
for (PRInt32 x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
|
PRUint8 *pixel = data + stride * y + 4 * x;
|
|
|
|
|
|
|
|
|
|
PRUint8 a = pixel[GFX_ARGB32_OFFSET_A];
|
|
|
|
|
if (a == 255)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_B],
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] * a);
|
|
|
|
|
FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_G],
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] * a);
|
|
|
|
|
FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_R],
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] * a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::ConvertImageDataToLinearRGB(PRUint8 *data,
|
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
for (PRInt32 y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
|
for (PRInt32 x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
|
PRUint8 *pixel = data + stride * y + 4 * x;
|
|
|
|
|
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] =
|
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_B]];
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] =
|
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] =
|
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::ConvertImageDataFromLinearRGB(PRUint8 *data,
|
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
for (PRInt32 y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
|
for (PRInt32 x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
|
PRUint8 *pixel = data + stride * y + 4 * x;
|
|
|
|
|
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] =
|
|
|
|
|
glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_B]];
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] =
|
|
|
|
|
glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] =
|
|
|
|
|
glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
|
nsSVGUtils::ReportToConsole(nsIDocument* doc,
|
|
|
|
|
const char* aWarning,
|
|
|
|
|
const PRUnichar **aParams,
|
|
|
|
|
PRUint32 aParamsLength)
|
|
|
|
|
{
|
|
|
|
|
return nsContentUtils::ReportToConsole(nsContentUtils::eSVG_PROPERTIES,
|
|
|
|
|
aWarning,
|
|
|
|
|
aParams, aParamsLength,
|
|
|
|
|
doc ? doc->GetDocumentURI() : nsnull,
|
|
|
|
|
EmptyString(), 0, 0,
|
|
|
|
|
nsIScriptError::warningFlag,
|
|
|
|
|
"SVG");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
|
|
|
|
|
nsSVGElement *aContent,
|
|
|
|
|
const nsStyleCoord &aCoord)
|
|
|
|
|
{
|
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
|
case eStyleUnit_Factor:
|
|
|
|
|
// user units
|
2009-01-16 00:02:40 -08:00
|
|
|
|
return aCoord.GetFactorValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
2009-01-16 00:02:40 -08:00
|
|
|
|
return nsPresContext::AppUnitsToFloatCSSPixels(aCoord.GetCoordValue());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
case eStyleUnit_Percent: {
|
2009-01-16 00:02:40 -08:00
|
|
|
|
nsSVGSVGElement* ctx = aContent->GetCtx();
|
|
|
|
|
return ctx ? aCoord.GetPercentValue() * ctx->GetLength(nsSVGUtils::XY) : 0.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
default:
|
2009-01-16 00:02:40 -08:00
|
|
|
|
return 0.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
PRBool
|
|
|
|
|
nsSVGUtils::EstablishesViewport(nsIContent *aContent)
|
2008-01-10 03:26:25 -08:00
|
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return aContent && aContent->GetNameSpaceID() == kNameSpaceID_SVG &&
|
|
|
|
|
(aContent->Tag() == nsGkAtoms::svg ||
|
|
|
|
|
aContent->Tag() == nsGkAtoms::image ||
|
|
|
|
|
aContent->Tag() == nsGkAtoms::foreignObject ||
|
|
|
|
|
aContent->Tag() == nsGkAtoms::symbol);
|
|
|
|
|
}
|
2009-07-21 15:55:48 -07:00
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
already_AddRefed<nsIDOMSVGElement>
|
|
|
|
|
nsSVGUtils::GetNearestViewportElement(nsIContent *aContent)
|
|
|
|
|
{
|
|
|
|
|
nsIContent *element = GetParentElement(aContent);
|
2009-07-21 15:55:48 -07:00
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
while (element && element->GetNameSpaceID() == kNameSpaceID_SVG) {
|
|
|
|
|
if (EstablishesViewport(element)) {
|
|
|
|
|
if (element->Tag() == nsGkAtoms::foreignObject) {
|
|
|
|
|
return nsnull;
|
|
|
|
|
}
|
|
|
|
|
return nsCOMPtr<nsIDOMSVGElement>(do_QueryInterface(element)).forget();
|
2008-01-10 03:26:25 -08:00
|
|
|
|
}
|
2009-07-23 01:35:59 -07:00
|
|
|
|
element = GetParentElement(element);
|
2008-01-10 03:26:25 -08:00
|
|
|
|
}
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return nsnull;
|
2008-01-10 03:26:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
already_AddRefed<nsIDOMSVGElement>
|
|
|
|
|
nsSVGUtils::GetFarthestViewportElement(nsIContent *aContent)
|
|
|
|
|
{
|
|
|
|
|
nsIContent *element = nsnull;
|
2009-06-26 13:13:07 -07:00
|
|
|
|
nsIContent *ancestor = GetParentElement(aContent);
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
while (ancestor && ancestor->GetNameSpaceID() == kNameSpaceID_SVG &&
|
|
|
|
|
ancestor->Tag() != nsGkAtoms::foreignObject) {
|
|
|
|
|
element = ancestor;
|
|
|
|
|
ancestor = GetParentElement(element);
|
2009-06-26 13:13:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
if (element && element->Tag() == nsGkAtoms::svg) {
|
|
|
|
|
return nsCOMPtr<nsIDOMSVGElement>(do_QueryInterface(element)).forget();
|
|
|
|
|
}
|
|
|
|
|
return nsnull;
|
2009-07-21 15:55:48 -07:00
|
|
|
|
}
|
2009-06-26 13:13:07 -07:00
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix
|
|
|
|
|
nsSVGUtils::GetCTM(nsSVGElement *aElement, PRBool aScreenCTM)
|
2009-07-21 15:55:48 -07:00
|
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
|
nsIDocument* currentDoc = aElement->GetCurrentDoc();
|
2009-07-21 15:55:48 -07:00
|
|
|
|
if (currentDoc) {
|
2009-07-23 01:35:59 -07:00
|
|
|
|
// Flush all pending notifications so that our frames are up to date
|
2009-07-21 15:55:48 -07:00
|
|
|
|
currentDoc->FlushPendingNotifications(Flush_Layout);
|
2009-07-21 13:34:37 -07:00
|
|
|
|
}
|
2009-07-21 15:55:48 -07:00
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix matrix = aElement->PrependLocalTransformTo(gfxMatrix());
|
|
|
|
|
nsSVGElement *element = aElement;
|
|
|
|
|
nsIContent *ancestor = GetParentElement(aElement);
|
2009-07-21 15:55:48 -07:00
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
while (ancestor && ancestor->GetNameSpaceID() == kNameSpaceID_SVG &&
|
|
|
|
|
ancestor->Tag() != nsGkAtoms::foreignObject) {
|
2009-08-31 03:33:29 -07:00
|
|
|
|
// ignore unknown XML elements in the SVG namespace
|
|
|
|
|
if (ancestor->IsNodeOfType(nsINode::eSVG)) {
|
|
|
|
|
element = static_cast<nsSVGElement*>(ancestor);
|
|
|
|
|
matrix *= element->PrependLocalTransformTo(gfxMatrix()); // i.e. *A*ppend
|
|
|
|
|
if (!aScreenCTM && EstablishesViewport(element)) {
|
|
|
|
|
if (!element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG) &&
|
|
|
|
|
!element->NodeInfo()->Equals(nsGkAtoms::symbol, kNameSpaceID_SVG)) {
|
|
|
|
|
NS_ERROR("New (SVG > 1.1) SVG viewport establishing element?");
|
|
|
|
|
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
|
|
|
|
|
}
|
|
|
|
|
// XXX spec seems to say x,y translation should be undone for IsInnerSVG
|
|
|
|
|
return matrix;
|
2009-07-23 01:35:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-31 03:33:29 -07:00
|
|
|
|
ancestor = GetParentElement(ancestor);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
}
|
|
|
|
|
if (!aScreenCTM) {
|
|
|
|
|
// didn't find a nearestViewportElement
|
|
|
|
|
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
|
|
|
|
|
}
|
2010-04-30 06:12:06 -07:00
|
|
|
|
if (!ancestor || !ancestor->IsElement()) {
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return matrix;
|
|
|
|
|
}
|
|
|
|
|
if (ancestor->GetNameSpaceID() == kNameSpaceID_SVG) {
|
|
|
|
|
if (element->Tag() != nsGkAtoms::svg) {
|
|
|
|
|
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
|
|
|
|
|
}
|
|
|
|
|
return matrix * GetCTM(static_cast<nsSVGElement*>(ancestor), PR_TRUE);
|
|
|
|
|
}
|
|
|
|
|
// XXX this does not take into account CSS transform, or that the non-SVG
|
|
|
|
|
// content that we've hit may itself be inside an SVG foreignObject higher up
|
|
|
|
|
float x = 0.0f, y = 0.0f;
|
2009-09-10 13:25:48 -07:00
|
|
|
|
if (currentDoc && element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG)) {
|
2010-06-25 06:59:57 -07:00
|
|
|
|
nsIPresShell *presShell = currentDoc->GetShell();
|
2009-09-10 13:25:48 -07:00
|
|
|
|
if (presShell) {
|
2009-12-24 13:20:06 -08:00
|
|
|
|
nsIFrame* frame = element->GetPrimaryFrame();
|
|
|
|
|
nsIFrame* ancestorFrame = presShell->GetRootFrame();
|
|
|
|
|
if (frame && ancestorFrame) {
|
|
|
|
|
nsPoint point = frame->GetOffsetTo(ancestorFrame);
|
|
|
|
|
x = nsPresContext::AppUnitsToFloatCSSPixels(point.x);
|
|
|
|
|
y = nsPresContext::AppUnitsToFloatCSSPixels(point.y);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return matrix * gfxMatrix().Translate(gfxPoint(x, y));
|
2009-06-26 13:13:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-24 16:17:43 -07:00
|
|
|
|
nsSVGDisplayContainerFrame*
|
|
|
|
|
nsSVGUtils::GetNearestSVGViewport(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
|
|
|
|
return nsnull;
|
|
|
|
|
}
|
|
|
|
|
while ((aFrame = aFrame->GetParent())) {
|
|
|
|
|
NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgInnerSVGFrame ||
|
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
|
|
|
|
return do_QueryFrame(aFrame);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NS_NOTREACHED("This is not reached. It's only needed to compile.");
|
|
|
|
|
return nsnull;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsRect
|
2008-07-22 19:15:27 -07:00
|
|
|
|
nsSVGUtils::FindFilterInvalidation(nsIFrame *aFrame, const nsRect& aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-09-16 04:54:30 -07:00
|
|
|
|
PRInt32 appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2009-05-07 19:31:04 -07:00
|
|
|
|
nsIntRect rect = aRect.ToOutsidePixels(appUnitsPerDevPixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
while (aFrame) {
|
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG)
|
|
|
|
|
break;
|
|
|
|
|
|
2008-10-11 05:55:11 -07:00
|
|
|
|
nsSVGFilterFrame *filter = nsSVGEffects::GetFilterFrame(aFrame);
|
|
|
|
|
if (filter) {
|
2009-04-24 16:17:43 -07:00
|
|
|
|
// When we are under AttributeChanged, we can no longer get the old bbox
|
|
|
|
|
// by calling GetBBox(), and we need that to set up the filter region
|
|
|
|
|
// with the correct position. :-(
|
|
|
|
|
//rect = filter->GetInvalidationBBox(aFrame, rect);
|
|
|
|
|
|
|
|
|
|
// XXX [perf] As a horrible workaround, for now we just invalidate the
|
|
|
|
|
// entire area of the nearest viewport establishing frame that doesnt
|
|
|
|
|
// have overflow:visible. See bug 463939.
|
|
|
|
|
nsSVGDisplayContainerFrame* viewportFrame = GetNearestSVGViewport(aFrame);
|
|
|
|
|
while (viewportFrame && !viewportFrame->GetStyleDisplay()->IsScrollableOverflow()) {
|
|
|
|
|
viewportFrame = GetNearestSVGViewport(viewportFrame);
|
|
|
|
|
}
|
|
|
|
|
if (!viewportFrame) {
|
|
|
|
|
viewportFrame = GetOuterSVGFrame(aFrame);
|
|
|
|
|
}
|
|
|
|
|
if (viewportFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
2010-10-06 21:25:47 -07:00
|
|
|
|
nsRect r = viewportFrame->GetVisualOverflowRect();
|
2009-04-24 16:17:43 -07:00
|
|
|
|
// GetOverflowRect is relative to our border box, but we need it
|
|
|
|
|
// relative to our content box.
|
2010-05-12 14:41:47 -07:00
|
|
|
|
r.MoveBy(viewportFrame->GetPosition() - viewportFrame->GetContentRect().TopLeft());
|
2009-04-24 16:17:43 -07:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
NS_ASSERTION(viewportFrame->GetType() == nsGkAtoms::svgInnerSVGFrame,
|
|
|
|
|
"Wrong frame type");
|
|
|
|
|
nsSVGInnerSVGFrame* innerSvg = do_QueryFrame(static_cast<nsIFrame*>(viewportFrame));
|
|
|
|
|
nsSVGDisplayContainerFrame* innerSvgParent = do_QueryFrame(viewportFrame->GetParent());
|
|
|
|
|
float x, y, width, height;
|
|
|
|
|
static_cast<nsSVGSVGElement*>(innerSvg->GetContent())->
|
|
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, nsnull);
|
2009-04-28 21:31:34 -07:00
|
|
|
|
gfxRect bounds = nsSVGUtils::GetCanvasTM(innerSvgParent).
|
|
|
|
|
TransformBounds(gfxRect(x, y, width, height));
|
2009-04-24 16:17:43 -07:00
|
|
|
|
bounds.RoundOut();
|
|
|
|
|
nsIntRect r;
|
2010-11-24 01:35:21 -08:00
|
|
|
|
if (gfxUtils::GfxRectToIntRect(bounds, &r)) {
|
2009-04-24 16:17:43 -07:00
|
|
|
|
rect = r;
|
|
|
|
|
} else {
|
|
|
|
|
NS_NOTREACHED("Not going to invalidate the correct area");
|
|
|
|
|
}
|
|
|
|
|
aFrame = viewportFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-12 14:41:47 -07:00
|
|
|
|
nsRect r = rect.ToAppUnits(appUnitsPerDevPixel);
|
|
|
|
|
if (aFrame) {
|
|
|
|
|
NS_ASSERTION(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG,
|
|
|
|
|
"outer SVG frame expected");
|
|
|
|
|
r.MoveBy(aFrame->GetContentRect().TopLeft() - aFrame->GetPosition());
|
|
|
|
|
}
|
|
|
|
|
return r;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-04 10:17:45 -08:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::InvalidateCoveredRegion(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nsSVGOuterSVGFrame* outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(aFrame);
|
|
|
|
|
NS_ASSERTION(outerSVGFrame, "no outer svg frame");
|
|
|
|
|
if (outerSVGFrame)
|
|
|
|
|
outerSVGFrame->InvalidateCoveredRegion(aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::UpdateGraphic(nsISVGChildFrame *aSVGFrame)
|
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsIFrame *frame = do_QueryFrame(aSVGFrame);
|
2008-04-08 05:51:19 -07:00
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
|
nsSVGEffects::InvalidateRenderingObservers(frame);
|
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
|
if (frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nsSVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(frame);
|
|
|
|
|
if (!outerSVGFrame) {
|
|
|
|
|
NS_ERROR("null outerSVGFrame");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (outerSVGFrame->IsRedrawSuspended()) {
|
|
|
|
|
frame->AddStateBits(NS_STATE_SVG_DIRTY);
|
|
|
|
|
} else {
|
|
|
|
|
frame->RemoveStateBits(NS_STATE_SVG_DIRTY);
|
|
|
|
|
|
2008-07-22 19:15:27 -07:00
|
|
|
|
PRBool changed = outerSVGFrame->UpdateAndInvalidateCoveredRegion(frame);
|
|
|
|
|
if (changed) {
|
|
|
|
|
NotifyAncestorsOfFilterRegionChange(frame);
|
|
|
|
|
}
|
2008-04-08 05:51:19 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-03-19 14:27:33 -07:00
|
|
|
|
nsSVGUtils::NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame)
|
|
|
|
|
{
|
2008-04-15 01:31:06 -07:00
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
|
|
|
|
|
// It would be better if we couldn't get here
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-19 14:27:33 -07:00
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
|
|
|
|
|
while (aFrame) {
|
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG)
|
|
|
|
|
return;
|
|
|
|
|
|
2008-08-07 18:34:43 -07:00
|
|
|
|
nsSVGFilterProperty *property = nsSVGEffects::GetFilterProperty(aFrame);
|
2008-08-05 17:25:33 -07:00
|
|
|
|
if (property) {
|
2008-03-19 14:27:33 -07:00
|
|
|
|
property->Invalidate();
|
|
|
|
|
}
|
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-15 01:46:54 -07:00
|
|
|
|
double
|
|
|
|
|
nsSVGUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
|
|
|
|
|
{
|
|
|
|
|
return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
float
|
2009-06-11 08:21:03 -07:00
|
|
|
|
nsSVGUtils::ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
float fraction, axis;
|
|
|
|
|
|
|
|
|
|
switch (aLength->GetCtxType()) {
|
|
|
|
|
case X:
|
2009-06-11 08:21:03 -07:00
|
|
|
|
axis = aRect.Width();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
case Y:
|
2009-06-11 08:21:03 -07:00
|
|
|
|
axis = aRect.Height();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
case XY:
|
2009-06-11 08:21:03 -07:00
|
|
|
|
axis = float(ComputeNormalizedHypotenuse(aRect.Width(), aRect.Height()));
|
2009-12-12 22:27:30 -08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("unexpected ctx type");
|
|
|
|
|
axis = 0.0f;
|
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
|
if (aLength->IsPercentage()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
fraction = aLength->GetAnimValInSpecifiedUnits() / 100;
|
2009-12-12 22:27:30 -08:00
|
|
|
|
} else {
|
2007-07-08 00:08:04 -07:00
|
|
|
|
fraction = aLength->GetAnimValue(static_cast<nsSVGSVGElement*>
|
|
|
|
|
(nsnull));
|
2009-12-12 22:27:30 -08:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
return fraction * axis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
2008-09-10 17:24:16 -07:00
|
|
|
|
nsSVGUtils::UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
return aLength->GetAnimValue(aSVGElement);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::UserSpace(nsIFrame *aNonSVGContext, const nsSVGLength2 *aLength)
|
|
|
|
|
{
|
|
|
|
|
return aLength->GetAnimValue(aNonSVGContext);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
float
|
|
|
|
|
nsSVGUtils::AngleBisect(float a1, float a2)
|
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
|
float delta = fmod(a2 - a1, static_cast<float>(2*M_PI));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (delta < 0) {
|
|
|
|
|
delta += 2*M_PI;
|
|
|
|
|
}
|
|
|
|
|
/* delta is now the angle from a1 around to a2, in the range [0, 2*M_PI) */
|
|
|
|
|
float r = a1 + delta/2;
|
|
|
|
|
if (delta >= M_PI) {
|
|
|
|
|
/* the arc from a2 to a1 is smaller, so use the ray on that side */
|
|
|
|
|
r += M_PI;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsSVGOuterSVGFrame *
|
|
|
|
|
nsSVGUtils::GetOuterSVGFrame(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
while (aFrame) {
|
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
|
2007-07-08 00:08:04 -07:00
|
|
|
|
return static_cast<nsSVGOuterSVGFrame*>(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 15:32:54 -07:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect)
|
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsISVGChildFrame* svg = do_QueryFrame(aFrame);
|
2007-05-30 15:32:54 -07:00
|
|
|
|
if (!svg)
|
|
|
|
|
return nsnull;
|
|
|
|
|
*aRect = svg->GetCoveredRegion();
|
|
|
|
|
return GetOuterSVGFrame(aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix
|
2010-02-07 18:28:01 -08:00
|
|
|
|
nsSVGUtils::GetViewBoxTransform(nsSVGElement* aElement,
|
|
|
|
|
float aViewportWidth, float aViewportHeight,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
float aViewboxX, float aViewboxY,
|
|
|
|
|
float aViewboxWidth, float aViewboxHeight,
|
2010-07-18 03:06:03 -07:00
|
|
|
|
const nsSVGPreserveAspectRatio &aPreserveAspectRatio)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-21 09:43:25 -08:00
|
|
|
|
NS_ASSERTION(aViewboxWidth > 0, "viewBox width must be greater than zero!");
|
|
|
|
|
NS_ASSERTION(aViewboxHeight > 0, "viewBox height must be greater than zero!");
|
|
|
|
|
|
2010-02-25 10:20:43 -08:00
|
|
|
|
PRUint16 align = aPreserveAspectRatio.GetAnimValue().GetAlign();
|
|
|
|
|
PRUint16 meetOrSlice = aPreserveAspectRatio.GetAnimValue().GetMeetOrSlice();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
// default to the defaults
|
|
|
|
|
if (align == nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_UNKNOWN)
|
|
|
|
|
align = nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID;
|
|
|
|
|
if (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_UNKNOWN)
|
|
|
|
|
meetOrSlice = nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET;
|
|
|
|
|
|
|
|
|
|
float a, d, e, f;
|
|
|
|
|
a = aViewportWidth / aViewboxWidth;
|
|
|
|
|
d = aViewportHeight / aViewboxHeight;
|
|
|
|
|
e = 0.0f;
|
|
|
|
|
f = 0.0f;
|
|
|
|
|
|
|
|
|
|
if (align != nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE &&
|
|
|
|
|
a != d) {
|
2008-09-15 08:40:25 -07:00
|
|
|
|
if ((meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET &&
|
|
|
|
|
a < d) ||
|
|
|
|
|
(meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE &&
|
|
|
|
|
d < a)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
d = a;
|
|
|
|
|
switch (align) {
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
|
|
|
|
|
break;
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
|
|
|
|
|
f = (aViewportHeight - a * aViewboxHeight) / 2.0f;
|
|
|
|
|
break;
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
|
|
|
|
|
f = aViewportHeight - a * aViewboxHeight;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("Unknown value for align");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (
|
2008-09-15 08:40:25 -07:00
|
|
|
|
(meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET &&
|
|
|
|
|
d < a) ||
|
|
|
|
|
(meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE &&
|
|
|
|
|
a < d)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
a = d;
|
|
|
|
|
switch (align) {
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
|
|
|
|
|
break;
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
|
|
|
|
|
e = (aViewportWidth - a * aViewboxWidth) / 2.0f;
|
|
|
|
|
break;
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
|
|
|
|
|
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
|
|
|
|
|
e = aViewportWidth - a * aViewboxWidth;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("Unknown value for align");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else NS_NOTREACHED("Unknown value for meetOrSlice");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aViewboxX) e += -a * aViewboxX;
|
|
|
|
|
if (aViewboxY) f += -d * aViewboxY;
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return gfxMatrix(a, 0.0f, 0.0f, d, e, f);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
|
gfxMatrix
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsSVGUtils::GetCanvasTM(nsIFrame *aFrame)
|
|
|
|
|
{
|
2009-04-28 21:31:34 -07:00
|
|
|
|
// XXX yuck, we really need a common interface for GetCanvasTM
|
|
|
|
|
|
|
|
|
|
if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return nsSVGIntegrationUtils::GetInitialMatrix(aFrame);
|
2009-04-28 21:31:34 -07:00
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
|
2009-03-04 04:55:28 -08:00
|
|
|
|
nsIAtom* type = aFrame->GetType();
|
2009-04-28 21:31:34 -07:00
|
|
|
|
if (type == nsGkAtoms::svgForeignObjectFrame) {
|
|
|
|
|
return static_cast<nsSVGForeignObjectFrame*>(aFrame)->GetCanvasTM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsSVGContainerFrame *containerFrame = do_QueryFrame(aFrame);
|
|
|
|
|
if (containerFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return containerFrame->GetCanvasTM();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
|
return static_cast<nsSVGGeometryFrame*>(aFrame)->GetCanvasTM();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-20 06:26:34 -08:00
|
|
|
|
void
|
2008-01-25 01:27:03 -08:00
|
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(nsIFrame *aFrame, PRUint32 aFlags)
|
2007-12-20 06:26:34 -08:00
|
|
|
|
{
|
2010-01-13 03:09:58 -08:00
|
|
|
|
nsIFrame *kid = aFrame->GetFirstChild(nsnull);
|
2007-12-20 06:26:34 -08:00
|
|
|
|
|
2010-01-13 03:09:58 -08:00
|
|
|
|
while (kid) {
|
|
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2007-12-20 06:26:34 -08:00
|
|
|
|
if (SVGFrame) {
|
2008-01-25 01:27:03 -08:00
|
|
|
|
SVGFrame->NotifySVGChanged(aFlags);
|
2007-12-20 06:26:34 -08:00
|
|
|
|
} else {
|
2010-01-13 03:09:58 -08:00
|
|
|
|
NS_ASSERTION(kid->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
2007-12-20 06:26:34 -08:00
|
|
|
|
// recurse into the children of container frames e.g. <clipPath>, <mask>
|
|
|
|
|
// in case they have child frames with transformation matrices
|
2010-01-13 03:09:58 -08:00
|
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(kid, aFlags);
|
2007-12-20 06:26:34 -08:00
|
|
|
|
}
|
2010-01-13 03:09:58 -08:00
|
|
|
|
kid = kid->GetNextSibling();
|
2007-12-20 06:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// ************************************************************
|
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
|
class SVGPaintCallback : public nsSVGFilterPaintCallback
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual void Paint(nsSVGRenderState *aContext, nsIFrame *aTarget,
|
2008-10-16 00:55:10 -07:00
|
|
|
|
const nsIntRect* aDirtyRect)
|
2008-09-10 17:24:16 -07:00
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aTarget);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
NS_ASSERTION(svgChildFrame, "Expected SVG frame here");
|
2008-10-16 00:55:10 -07:00
|
|
|
|
|
|
|
|
|
nsIntRect* dirtyRect = nsnull;
|
|
|
|
|
nsIntRect tmpDirtyRect;
|
|
|
|
|
|
|
|
|
|
// aDirtyRect is in user-space pixels, we need to convert to
|
|
|
|
|
// outer-SVG-frame-relative device pixels.
|
|
|
|
|
if (aDirtyRect) {
|
2009-04-28 21:31:34 -07:00
|
|
|
|
gfxMatrix userToDeviceSpace = nsSVGUtils::GetCanvasTM(aTarget);
|
|
|
|
|
if (userToDeviceSpace.IsSingular()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-02-09 16:54:28 -08:00
|
|
|
|
gfxRect dirtyBounds = userToDeviceSpace.TransformBounds(
|
2008-10-16 00:55:10 -07:00
|
|
|
|
gfxRect(aDirtyRect->x, aDirtyRect->y, aDirtyRect->width, aDirtyRect->height));
|
|
|
|
|
dirtyBounds.RoundOut();
|
2010-11-24 01:35:21 -08:00
|
|
|
|
if (gfxUtils::GfxRectToIntRect(dirtyBounds, &tmpDirtyRect)) {
|
2008-10-16 00:55:10 -07:00
|
|
|
|
dirtyRect = &tmpDirtyRect;
|
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 00:55:10 -07:00
|
|
|
|
svgChildFrame->PaintSVG(aContext, dirtyRect);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
2008-10-20 01:42:03 -07:00
|
|
|
|
nsSVGUtils::PaintFrameWithEffects(nsSVGRenderState *aContext,
|
|
|
|
|
const nsIntRect *aDirtyRect,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsIFrame *aFrame)
|
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (!svgChildFrame)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
float opacity = aFrame->GetStyleDisplay()->mOpacity;
|
|
|
|
|
if (opacity == 0.0f)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Properties are added lazily and may have been removed by a restyle,
|
|
|
|
|
so make sure all applicable ones are set again. */
|
|
|
|
|
|
2008-08-07 18:34:43 -07:00
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
|
PRBool isOK = PR_TRUE;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
nsSVGFilterFrame *filterFrame = effectProperties.GetFilterFrame(&isOK);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
|
|
|
|
|
/* Check if we need to draw anything. HasValidCoveredRect only returns
|
|
|
|
|
* true for path geometry and glyphs, so basically we're traversing
|
|
|
|
|
* all containers and we can only skip leaves here.
|
|
|
|
|
*/
|
2008-07-22 19:15:27 -07:00
|
|
|
|
if (aDirtyRect && svgChildFrame->HasValidCoveredRect()) {
|
2008-09-10 17:24:16 -07:00
|
|
|
|
if (filterFrame) {
|
|
|
|
|
if (!aDirtyRect->Intersects(filterFrame->GetFilterBBox(aFrame, nsnull)))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return;
|
2008-07-22 19:15:27 -07:00
|
|
|
|
} else {
|
2009-05-07 19:31:04 -07:00
|
|
|
|
nsRect rect = aDirtyRect->ToAppUnits(aFrame->PresContext()->AppUnitsPerDevPixel());
|
2008-08-25 02:23:54 -07:00
|
|
|
|
if (!rect.Intersects(aFrame->GetRect()))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* SVG defines the following rendering model:
|
|
|
|
|
*
|
2009-10-26 10:17:49 -07:00
|
|
|
|
* 1. Render fill
|
|
|
|
|
* 2. Render stroke
|
|
|
|
|
* 3. Render markers
|
|
|
|
|
* 4. Apply filter
|
|
|
|
|
* 5. Apply clipping, masking, group opacity
|
2007-03-22 10:30:00 -07:00
|
|
|
|
*
|
2007-04-26 01:36:16 -07:00
|
|
|
|
* We follow this, but perform a couple of optimizations:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
*
|
|
|
|
|
* + Use cairo's clipPath when representable natively (single object
|
|
|
|
|
* clip region).
|
|
|
|
|
*
|
|
|
|
|
* + Merge opacity and masking if both used together.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-04-26 01:36:16 -07:00
|
|
|
|
if (opacity != 1.0f && CanOptimizeOpacity(aFrame))
|
|
|
|
|
opacity = 1.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
gfxContext *gfx = aContext->GetGfxContext();
|
2007-05-22 12:31:04 -07:00
|
|
|
|
PRBool complexEffects = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
|
nsSVGMaskFrame *maskFrame = effectProperties.GetMaskFrame(&isOK);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
2008-08-05 17:25:33 -07:00
|
|
|
|
PRBool isTrivialClip = clipPathFrame ? clipPathFrame->IsTrivial() : PR_TRUE;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
2008-08-05 17:25:33 -07:00
|
|
|
|
if (!isOK) {
|
|
|
|
|
// Some resource is missing. We shouldn't paint anything.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix matrix;
|
|
|
|
|
if (clipPathFrame || maskFrame)
|
|
|
|
|
matrix = GetCanvasTM(aFrame);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
/* Check if we need to do additional operations on this child's
|
|
|
|
|
* rendering, which necessitates rendering into another surface. */
|
2007-04-26 01:36:16 -07:00
|
|
|
|
if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)) {
|
2007-05-22 12:31:04 -07:00
|
|
|
|
complexEffects = PR_TRUE;
|
|
|
|
|
gfx->Save();
|
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If this frame has only a trivial clipPath, set up cairo's clipping now so
|
|
|
|
|
* we can just do normal painting and get it clipped appropriately.
|
|
|
|
|
*/
|
2007-04-26 01:36:16 -07:00
|
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
gfx->Save();
|
2008-09-10 17:24:16 -07:00
|
|
|
|
clipPathFrame->ClipPaint(aContext, aFrame, matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Paint the child */
|
2007-04-26 01:36:16 -07:00
|
|
|
|
if (filterFrame) {
|
2008-09-10 17:24:16 -07:00
|
|
|
|
SVGPaintCallback paintCallback;
|
|
|
|
|
filterFrame->FilterPaint(aContext, aFrame, &paintCallback, aDirtyRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
} else {
|
|
|
|
|
svgChildFrame->PaintSVG(aContext, aDirtyRect);
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-26 01:36:16 -07:00
|
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
gfx->Restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* No more effects, we're done. */
|
2007-05-22 12:31:04 -07:00
|
|
|
|
if (!complexEffects)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->PopGroupToSource();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
|
nsRefPtr<gfxPattern> maskSurface =
|
2008-09-10 17:24:16 -07:00
|
|
|
|
maskFrame ? maskFrame->ComputeMaskAlpha(aContext, aFrame,
|
2007-04-26 01:36:16 -07:00
|
|
|
|
matrix, opacity) : nsnull;
|
|
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
|
nsRefPtr<gfxPattern> clipMaskSurface;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
if (clipPathFrame && !isTrivialClip) {
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
|
nsresult rv = clipPathFrame->ClipPaint(aContext, aFrame, matrix);
|
2007-05-22 12:31:04 -07:00
|
|
|
|
clipMaskSurface = gfx->PopGroup();
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && clipMaskSurface) {
|
|
|
|
|
// Still more set after clipping, so clip to another surface
|
|
|
|
|
if (maskSurface || opacity != 1.0f) {
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
|
gfx->Mask(clipMaskSurface);
|
|
|
|
|
gfx->PopGroupToSource();
|
2007-04-26 01:36:16 -07:00
|
|
|
|
} else {
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->Mask(clipMaskSurface);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maskSurface) {
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->Mask(maskSurface);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
} else if (opacity != 1.0f) {
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->Paint(opacity);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
|
gfx->Restore();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PRBool
|
2008-08-25 02:23:54 -07:00
|
|
|
|
nsSVGUtils::HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-08-07 18:34:43 -07:00
|
|
|
|
nsSVGEffects::EffectProperties props =
|
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
2008-08-05 17:25:33 -07:00
|
|
|
|
if (!props.mClipPath)
|
|
|
|
|
return PR_TRUE;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
2010-03-02 01:31:07 -08:00
|
|
|
|
PRBool isOK = PR_TRUE;
|
|
|
|
|
nsSVGClipPathFrame *clipPathFrame = props.GetClipPathFrame(&isOK);
|
|
|
|
|
if (!clipPathFrame || !isOK) {
|
2008-08-05 17:25:33 -07:00
|
|
|
|
// clipPath is not a valid resource, so nothing gets painted, so
|
|
|
|
|
// hit-testing must fail.
|
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return clipPathFrame->ClipHitTest(aFrame, GetCanvasTM(aFrame), aPoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
|
nsIFrame *
|
|
|
|
|
nsSVGUtils::HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2009-10-02 09:31:45 -07:00
|
|
|
|
// Traverse the list in reverse order, so that if we get a hit we know that's
|
|
|
|
|
// the topmost frame that intersects the point; then we can just return it.
|
2008-08-25 02:23:54 -07:00
|
|
|
|
nsIFrame* result = nsnull;
|
2009-10-02 09:31:45 -07:00
|
|
|
|
for (nsIFrame* current = aFrame->GetChildList(nsnull).LastChild();
|
|
|
|
|
current;
|
|
|
|
|
current = current->GetPrevSibling()) {
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(current);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (SVGFrame) {
|
2008-08-25 02:23:54 -07:00
|
|
|
|
result = SVGFrame->GetFrameForPoint(aPoint);
|
|
|
|
|
if (result)
|
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
|
if (result && !HitTestClip(aFrame, aPoint))
|
|
|
|
|
result = nsnull;
|
|
|
|
|
|
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
|
nsSVGUtils::GetCoveredRegion(const nsFrameList &aFrames)
|
|
|
|
|
{
|
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
|
|
for (nsIFrame* kid = aFrames.FirstChild();
|
|
|
|
|
kid;
|
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsISVGChildFrame* child = do_QueryFrame(kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (child) {
|
|
|
|
|
nsRect childRect = child->GetCoveredRegion();
|
|
|
|
|
rect.UnionRect(rect, childRect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect
|
2008-08-25 02:23:54 -07:00
|
|
|
|
nsSVGUtils::ToAppPixelRect(nsPresContext *aPresContext,
|
|
|
|
|
double xmin, double ymin,
|
|
|
|
|
double xmax, double ymax)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-08-25 02:23:54 -07:00
|
|
|
|
return ToAppPixelRect(aPresContext,
|
|
|
|
|
gfxRect(xmin, ymin, xmax - xmin, ymax - ymin));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect
|
2008-08-25 02:23:54 -07:00
|
|
|
|
nsSVGUtils::ToAppPixelRect(nsPresContext *aPresContext, const gfxRect& rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-08-25 02:23:54 -07:00
|
|
|
|
return nsRect(aPresContext->DevPixelsToAppUnits(NSToIntFloor(rect.X())),
|
|
|
|
|
aPresContext->DevPixelsToAppUnits(NSToIntFloor(rect.Y())),
|
|
|
|
|
aPresContext->DevPixelsToAppUnits(NSToIntCeil(rect.XMost()) - NSToIntFloor(rect.X())),
|
|
|
|
|
aPresContext->DevPixelsToAppUnits(NSToIntCeil(rect.YMost()) - NSToIntFloor(rect.Y())));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxMatrix
|
|
|
|
|
nsSVGUtils::ConvertSVGMatrixToThebes(nsIDOMSVGMatrix *aMatrix)
|
|
|
|
|
{
|
2009-04-28 21:31:34 -07:00
|
|
|
|
if (!aMatrix) {
|
|
|
|
|
return gfxMatrix();
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
float A, B, C, D, E, F;
|
|
|
|
|
aMatrix->GetA(&A);
|
|
|
|
|
aMatrix->GetB(&B);
|
|
|
|
|
aMatrix->GetC(&C);
|
|
|
|
|
aMatrix->GetD(&D);
|
|
|
|
|
aMatrix->GetE(&E);
|
|
|
|
|
aMatrix->GetF(&F);
|
|
|
|
|
return gfxMatrix(A, B, C, D, E, F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PRBool
|
2009-07-23 01:35:59 -07:00
|
|
|
|
nsSVGUtils::HitTestRect(const gfxMatrix &aMatrix,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
float aRX, float aRY, float aRWidth, float aRHeight,
|
|
|
|
|
float aX, float aY)
|
|
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
|
if (aMatrix.IsSingular()) {
|
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2010-08-20 12:29:01 -07:00
|
|
|
|
gfxContext ctx(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
2009-07-23 01:35:59 -07:00
|
|
|
|
ctx.SetMatrix(aMatrix);
|
|
|
|
|
ctx.NewPath();
|
|
|
|
|
ctx.Rectangle(gfxRect(aRX, aRY, aRWidth, aRHeight));
|
|
|
|
|
ctx.IdentityMatrix();
|
|
|
|
|
return ctx.PointInFill(gfxPoint(aX, aY));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 13:51:40 -07:00
|
|
|
|
gfxRect
|
|
|
|
|
nsSVGUtils::GetClipRectForFrame(nsIFrame *aFrame,
|
|
|
|
|
float aX, float aY, float aWidth, float aHeight)
|
|
|
|
|
{
|
|
|
|
|
const nsStyleDisplay* disp = aFrame->GetStyleDisplay();
|
|
|
|
|
|
|
|
|
|
if (!(disp->mClipFlags & NS_STYLE_CLIP_RECT)) {
|
|
|
|
|
NS_ASSERTION(disp->mClipFlags == NS_STYLE_CLIP_AUTO,
|
|
|
|
|
"We don't know about this type of clip.");
|
|
|
|
|
return gfxRect(aX, aY, aWidth, aHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disp->mOverflowX == NS_STYLE_OVERFLOW_HIDDEN ||
|
|
|
|
|
disp->mOverflowY == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
|
|
|
|
|
nsIntRect clipPxRect =
|
|
|
|
|
disp->mClip.ToOutsidePixels(aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
gfxRect clipRect =
|
|
|
|
|
gfxRect(clipPxRect.x, clipPxRect.y, clipPxRect.width, clipPxRect.height);
|
|
|
|
|
|
|
|
|
|
if (NS_STYLE_CLIP_RIGHT_AUTO & disp->mClipFlags) {
|
|
|
|
|
clipRect.size.width = aWidth - clipRect.X();
|
|
|
|
|
}
|
|
|
|
|
if (NS_STYLE_CLIP_BOTTOM_AUTO & disp->mClipFlags) {
|
|
|
|
|
clipRect.size.height = aHeight - clipRect.Y();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disp->mOverflowX != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
clipRect.pos.x = aX;
|
|
|
|
|
clipRect.size.width = aWidth;
|
|
|
|
|
}
|
|
|
|
|
if (disp->mOverflowY != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
clipRect.pos.y = aY;
|
|
|
|
|
clipRect.size.height = aHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return clipRect;
|
|
|
|
|
}
|
|
|
|
|
return gfxRect(aX, aY, aWidth, aHeight);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::CompositeSurfaceMatrix(gfxContext *aContext,
|
|
|
|
|
gfxASurface *aSurface,
|
2009-07-23 01:35:59 -07:00
|
|
|
|
const gfxMatrix &aCTM, float aOpacity)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
|
if (aCTM.IsSingular())
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
aContext->Save();
|
2009-07-23 01:35:59 -07:00
|
|
|
|
aContext->Multiply(aCTM);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
aContext->SetSource(aSurface);
|
|
|
|
|
aContext->Paint(aOpacity);
|
|
|
|
|
aContext->Restore();
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-05 22:51:13 -08:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::CompositePatternMatrix(gfxContext *aContext,
|
|
|
|
|
gfxPattern *aPattern,
|
2009-07-23 01:35:59 -07:00
|
|
|
|
const gfxMatrix &aCTM, float aWidth, float aHeight, float aOpacity)
|
2008-03-05 22:51:13 -08:00
|
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
|
if (aCTM.IsSingular())
|
2008-03-05 22:51:13 -08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
aContext->Save();
|
2009-07-23 01:35:59 -07:00
|
|
|
|
SetClipRect(aContext, aCTM, gfxRect(0, 0, aWidth, aHeight));
|
|
|
|
|
aContext->Multiply(aCTM);
|
2008-03-05 22:51:13 -08:00
|
|
|
|
aContext->SetPattern(aPattern);
|
|
|
|
|
aContext->Paint(aOpacity);
|
|
|
|
|
aContext->Restore();
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::SetClipRect(gfxContext *aContext,
|
2009-06-18 04:31:25 -07:00
|
|
|
|
const gfxMatrix &aCTM,
|
2009-06-17 13:51:40 -07:00
|
|
|
|
const gfxRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2009-06-18 04:31:25 -07:00
|
|
|
|
if (aCTM.IsSingular())
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gfxMatrix oldMatrix = aContext->CurrentMatrix();
|
2009-06-18 04:31:25 -07:00
|
|
|
|
aContext->Multiply(aCTM);
|
2009-06-17 13:51:40 -07:00
|
|
|
|
aContext->Clip(aRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
aContext->SetMatrix(oldMatrix);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-13 18:21:25 -07:00
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect)
|
|
|
|
|
{
|
|
|
|
|
gfxRect r = aGfxRect;
|
|
|
|
|
r.RoundOut();
|
|
|
|
|
gfxRect r2(aRect->x, aRect->y, aRect->width, aRect->height);
|
|
|
|
|
r = r.Intersect(r2);
|
|
|
|
|
*aRect = nsIntRect(PRInt32(r.X()), PRInt32(r.Y()),
|
|
|
|
|
PRInt32(r.Width()), PRInt32(r.Height()));
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-11 08:21:03 -07:00
|
|
|
|
gfxRect
|
2008-09-10 17:24:16 -07:00
|
|
|
|
nsSVGUtils::GetBBox(nsIFrame *aFrame)
|
|
|
|
|
{
|
2010-08-07 02:38:11 -07:00
|
|
|
|
if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
}
|
2009-06-11 08:21:03 -07:00
|
|
|
|
gfxRect bbox;
|
2009-01-12 11:20:59 -08:00
|
|
|
|
nsISVGChildFrame *svg = do_QueryFrame(aFrame);
|
2009-06-11 08:21:03 -07:00
|
|
|
|
if (svg) {
|
2010-08-07 02:38:11 -07:00
|
|
|
|
// It is possible to apply a gradient, pattern, clipping path, mask or
|
|
|
|
|
// filter to text. When one of these facilities is applied to text
|
|
|
|
|
// the bounding box is the entire <20>text<78> element in all
|
|
|
|
|
// cases.
|
2010-10-08 09:49:39 -07:00
|
|
|
|
nsSVGTextContainerFrame* metrics = do_QueryFrame(
|
|
|
|
|
GetFirstNonAAncestorFrame(aFrame));
|
2010-08-07 02:38:11 -07:00
|
|
|
|
if (metrics) {
|
|
|
|
|
while (aFrame->GetType() != nsGkAtoms::svgTextFrame) {
|
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
}
|
|
|
|
|
svg = do_QueryFrame(aFrame);
|
|
|
|
|
}
|
2009-06-11 08:21:03 -07:00
|
|
|
|
bbox = svg->GetBBoxContribution(gfxMatrix());
|
|
|
|
|
} else {
|
|
|
|
|
bbox = nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(aFrame);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
}
|
2009-06-11 08:21:03 -07:00
|
|
|
|
NS_ASSERTION(bbox.Width() >= 0.0 && bbox.Height() >= 0.0, "Invalid bbox!");
|
|
|
|
|
return bbox;
|
2008-09-10 17:24:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxRect
|
|
|
|
|
nsSVGUtils::GetRelativeRect(PRUint16 aUnits, const nsSVGLength2 *aXYWH,
|
2009-06-11 08:21:03 -07:00
|
|
|
|
const gfxRect &aBBox, nsIFrame *aFrame)
|
2008-09-10 17:24:16 -07:00
|
|
|
|
{
|
|
|
|
|
float x, y, width, height;
|
|
|
|
|
if (aUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2009-06-11 08:21:03 -07:00
|
|
|
|
x = aBBox.X() + ObjectSpace(aBBox, &aXYWH[0]);
|
|
|
|
|
y = aBBox.Y() + ObjectSpace(aBBox, &aXYWH[1]);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
width = ObjectSpace(aBBox, &aXYWH[2]);
|
|
|
|
|
height = ObjectSpace(aBBox, &aXYWH[3]);
|
|
|
|
|
} else {
|
|
|
|
|
x = nsSVGUtils::UserSpace(aFrame, &aXYWH[0]);
|
|
|
|
|
y = nsSVGUtils::UserSpace(aFrame, &aXYWH[1]);
|
|
|
|
|
width = nsSVGUtils::UserSpace(aFrame, &aXYWH[2]);
|
|
|
|
|
height = nsSVGUtils::UserSpace(aFrame, &aXYWH[3]);
|
|
|
|
|
}
|
|
|
|
|
return gfxRect(x, y, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
PRBool
|
|
|
|
|
nsSVGUtils::CanOptimizeOpacity(nsIFrame *aFrame)
|
|
|
|
|
{
|
2009-10-26 10:17:49 -07:00
|
|
|
|
nsIAtom *type = aFrame->GetType();
|
|
|
|
|
if (type != nsGkAtoms::svgImageFrame &&
|
|
|
|
|
type != nsGkAtoms::svgPathGeometryFrame) {
|
|
|
|
|
return PR_FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (aFrame->GetStyleSVGReset()->mFilter) {
|
|
|
|
|
return PR_FALSE;
|
|
|
|
|
}
|
|
|
|
|
// XXX The SVG WG is intending to allow fill, stroke and markers on <image>
|
|
|
|
|
if (type == nsGkAtoms::svgImageFrame) {
|
|
|
|
|
return PR_TRUE;
|
|
|
|
|
}
|
|
|
|
|
const nsStyleSVG *style = aFrame->GetStyleSVG();
|
|
|
|
|
if (style->mMarkerStart || style->mMarkerMid || style->mMarkerEnd) {
|
|
|
|
|
return PR_FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (style->mFill.mType == eStyleSVGPaintType_None ||
|
|
|
|
|
style->mFillOpacity <= 0 ||
|
|
|
|
|
!static_cast<nsSVGPathGeometryFrame*>(aFrame)->HasStroke()) {
|
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
return PR_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-02 07:57:47 -07:00
|
|
|
|
float
|
2009-07-23 01:35:59 -07:00
|
|
|
|
nsSVGUtils::MaxExpansion(const gfxMatrix &aMatrix)
|
2007-10-02 07:57:47 -07:00
|
|
|
|
{
|
|
|
|
|
// maximum expansion derivation from
|
|
|
|
|
// http://lists.cairographics.org/archives/cairo/2004-October/001980.html
|
2009-07-23 01:35:59 -07:00
|
|
|
|
// and also implemented in cairo_matrix_transformed_circle_major_axis
|
|
|
|
|
double a = aMatrix.xx;
|
|
|
|
|
double b = aMatrix.yx;
|
|
|
|
|
double c = aMatrix.xy;
|
|
|
|
|
double d = aMatrix.yy;
|
|
|
|
|
double f = (a * a + b * b + c * c + d * d) / 2;
|
|
|
|
|
double g = (a * a + b * b - c * c - d * d) / 2;
|
|
|
|
|
double h = a * c + b * d;
|
2007-10-02 07:57:47 -07:00
|
|
|
|
return sqrt(f + sqrt(g * g + h * h));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix
|
|
|
|
|
nsSVGUtils::AdjustMatrixForUnits(const gfxMatrix &aMatrix,
|
2007-12-03 20:40:52 -08:00
|
|
|
|
nsSVGEnum *aUnits,
|
2008-09-10 17:24:16 -07:00
|
|
|
|
nsIFrame *aFrame)
|
2007-12-03 20:40:52 -08:00
|
|
|
|
{
|
|
|
|
|
if (aFrame &&
|
2010-02-25 10:20:43 -08:00
|
|
|
|
aUnits->GetAnimValue() ==
|
2010-01-23 10:58:47 -08:00
|
|
|
|
nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2009-06-11 08:21:03 -07:00
|
|
|
|
gfxRect bbox = GetBBox(aFrame);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return gfxMatrix().Scale(bbox.Width(), bbox.Height()) *
|
|
|
|
|
gfxMatrix().Translate(gfxPoint(bbox.X(), bbox.Y())) *
|
|
|
|
|
aMatrix;
|
2007-12-03 20:40:52 -08:00
|
|
|
|
}
|
2009-07-23 01:35:59 -07:00
|
|
|
|
return aMatrix;
|
2007-12-03 20:40:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsSVGUtils::GetFirstNonAAncestorFrame(nsIFrame* aStartFrame)
|
|
|
|
|
{
|
|
|
|
|
for (nsIFrame *ancestorFrame = aStartFrame; ancestorFrame;
|
|
|
|
|
ancestorFrame = ancestorFrame->GetParent()) {
|
|
|
|
|
if (ancestorFrame->GetType() != nsGkAtoms::svgAFrame) {
|
|
|
|
|
return ancestorFrame;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nsnull;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-17 08:20:35 -07:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
void
|
|
|
|
|
nsSVGUtils::WritePPM(const char *fname, gfxImageSurface *aSurface)
|
|
|
|
|
{
|
|
|
|
|
FILE *f = fopen(fname, "wb");
|
|
|
|
|
if (!f)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gfxIntSize size = aSurface->GetSize();
|
|
|
|
|
fprintf(f, "P6\n%d %d\n255\n", size.width, size.height);
|
|
|
|
|
unsigned char *data = aSurface->Data();
|
|
|
|
|
PRInt32 stride = aSurface->Stride();
|
|
|
|
|
for (int y=0; y<size.height; y++) {
|
|
|
|
|
for (int x=0; x<size.width; x++) {
|
|
|
|
|
fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_R, 1, 1, f);
|
|
|
|
|
fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_G, 1, 1, f);
|
|
|
|
|
fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_B, 1, 1, f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-03-31 05:19:39 -07:00
|
|
|
|
/*static*/ gfxRect
|
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
|
|
|
|
nsSVGGeometryFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
// The logic here comes from _cairo_stroke_style_max_distance_from_path
|
|
|
|
|
|
|
|
|
|
double style_expansion = 0.5;
|
|
|
|
|
|
|
|
|
|
const nsStyleSVG* style = aFrame->GetStyleSVG();
|
|
|
|
|
|
|
|
|
|
if (style->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_SQUARE) {
|
|
|
|
|
style_expansion = M_SQRT1_2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (style->mStrokeLinejoin == NS_STYLE_STROKE_LINEJOIN_MITER &&
|
|
|
|
|
style_expansion < style->mStrokeMiterlimit) {
|
|
|
|
|
style_expansion = style->mStrokeMiterlimit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
style_expansion *= aFrame->GetStrokeWidth();
|
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
|
gfxMatrix ctm = aFrame->GetCanvasTM();
|
|
|
|
|
|
|
|
|
|
double dx = style_expansion * (fabs(ctm.xx) + fabs(ctm.xy));
|
|
|
|
|
double dy = style_expansion * (fabs(ctm.yy) + fabs(ctm.yx));
|
2009-03-31 05:19:39 -07:00
|
|
|
|
|
|
|
|
|
gfxRect strokeExtents = aPathExtents;
|
|
|
|
|
strokeExtents.Outset(dy, dx, dy, dx);
|
|
|
|
|
return strokeExtents;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
/* static */ PRBool
|
|
|
|
|
nsSVGUtils::IsInnerSVG(nsIContent* aContent)
|
|
|
|
|
{
|
|
|
|
|
if (!aContent->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG)) {
|
|
|
|
|
return PR_FALSE;
|
|
|
|
|
}
|
|
|
|
|
nsIContent *ancestor = GetParentElement(aContent);
|
|
|
|
|
return ancestor && ancestor->GetNameSpaceID() == kNameSpaceID_SVG &&
|
|
|
|
|
ancestor->Tag() != nsGkAtoms::foreignObject;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
nsSVGRenderState::nsSVGRenderState(nsIRenderingContext *aContext) :
|
2010-10-14 18:03:45 -07:00
|
|
|
|
mRenderMode(NORMAL), mRenderingContext(aContext), mPaintingToWindow(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2007-12-18 15:01:15 -08:00
|
|
|
|
mGfxContext = aContext->ThebesContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 06:32:27 -07:00
|
|
|
|
nsSVGRenderState::nsSVGRenderState(gfxContext *aContext) :
|
2010-10-14 18:03:45 -07:00
|
|
|
|
mRenderMode(NORMAL), mGfxContext(aContext), mPaintingToWindow(PR_FALSE)
|
2010-08-13 06:32:27 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-12 01:36:51 -07:00
|
|
|
|
nsSVGRenderState::nsSVGRenderState(gfxASurface *aSurface) :
|
2010-10-14 18:03:45 -07:00
|
|
|
|
mRenderMode(NORMAL), mPaintingToWindow(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-08-12 01:36:51 -07:00
|
|
|
|
mGfxContext = new gfxContext(aSurface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIRenderingContext*
|
|
|
|
|
nsSVGRenderState::GetRenderingContext(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!mRenderingContext) {
|
|
|
|
|
nsIDeviceContext* devCtx = aFrame->PresContext()->DeviceContext();
|
|
|
|
|
devCtx->CreateRenderingContextInstance(*getter_AddRefs(mRenderingContext));
|
2008-09-10 17:24:16 -07:00
|
|
|
|
if (!mRenderingContext)
|
|
|
|
|
return nsnull;
|
2008-08-12 01:36:51 -07:00
|
|
|
|
mRenderingContext->Init(devCtx, mGfxContext);
|
|
|
|
|
}
|
|
|
|
|
return mRenderingContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2009-06-11 08:21:03 -07:00
|
|
|
|
|
2010-10-06 15:18:52 -07:00
|
|
|
|
/* static */ PRBool
|
|
|
|
|
nsSVGUtils::RootSVGElementHasViewbox(const nsIContent *aRootSVGElem)
|
|
|
|
|
{
|
|
|
|
|
if (aRootSVGElem->GetNameSpaceID() != kNameSpaceID_SVG ||
|
|
|
|
|
aRootSVGElem->Tag() != nsGkAtoms::svg) {
|
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "Expecting an SVG <svg> node");
|
|
|
|
|
return PR_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nsSVGSVGElement *svgSvgElem =
|
|
|
|
|
static_cast<const nsSVGSVGElement*>(aRootSVGElem);
|
|
|
|
|
|
|
|
|
|
return svgSvgElem->HasValidViewbox();
|
|
|
|
|
}
|