LCOV - code coverage report
Current view: directory - layout/svg/base/src - nsSVGUtils.h (source / functions) Found Hit Coverage
Test: app.info Lines: 3 0 0.0 %
Date: 2012-06-02 Functions: 2 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is the Mozilla SVG project.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is IBM Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      25                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #ifndef NS_SVGUTILS_H
      38                 : #define NS_SVGUTILS_H
      39                 : 
      40                 : // include math.h to pick up definition of M_SQRT1_2 if the platform defines it
      41                 : #define _USE_MATH_DEFINES
      42                 : #include <math.h>
      43                 : 
      44                 : #include "nscore.h"
      45                 : #include "nsCOMPtr.h"
      46                 : #include "nsRect.h"
      47                 : #include "gfxContext.h"
      48                 : #include "nsRenderingContext.h"
      49                 : #include "gfxRect.h"
      50                 : #include "gfxMatrix.h"
      51                 : #include "nsStyleStruct.h"
      52                 : 
      53                 : class nsIDocument;
      54                 : class nsPresContext;
      55                 : class nsIContent;
      56                 : class nsStyleContext;
      57                 : class nsStyleCoord;
      58                 : class nsFrameList;
      59                 : class nsIFrame;
      60                 : struct nsStyleSVGPaint;
      61                 : class nsIDOMSVGElement;
      62                 : class nsIDOMSVGLength;
      63                 : class nsIURI;
      64                 : class nsSVGOuterSVGFrame;
      65                 : class nsIAtom;
      66                 : class nsSVGLength2;
      67                 : class nsSVGElement;
      68                 : class nsSVGSVGElement;
      69                 : class nsAttrValue;
      70                 : class gfxContext;
      71                 : class gfxASurface;
      72                 : class gfxPattern;
      73                 : class gfxImageSurface;
      74                 : struct gfxSize;
      75                 : struct nsStyleFont;
      76                 : class nsSVGEnum;
      77                 : class nsISVGChildFrame;
      78                 : class nsSVGGeometryFrame;
      79                 : class nsSVGPathGeometryFrame;
      80                 : class nsSVGDisplayContainerFrame;
      81                 : 
      82                 : namespace mozilla {
      83                 : class SVGAnimatedPreserveAspectRatio;
      84                 : class SVGPreserveAspectRatio;
      85                 : namespace dom {
      86                 : class Element;
      87                 : } // namespace dom
      88                 : } // namespace mozilla
      89                 : 
      90                 : #ifndef M_PI
      91                 : #define M_PI 3.14159265358979323846
      92                 : #endif
      93                 : 
      94                 : // SVG Frame state bits
      95                 : #define NS_STATE_IS_OUTER_SVG                    NS_FRAME_STATE_BIT(20)
      96                 : 
      97                 : #define NS_STATE_SVG_DIRTY                       NS_FRAME_STATE_BIT(21)
      98                 : 
      99                 : /* are we the child of a non-display container? */
     100                 : #define NS_STATE_SVG_NONDISPLAY_CHILD            NS_FRAME_STATE_BIT(22)
     101                 : 
     102                 : // If this bit is set, we are a <clipPath> element or descendant.
     103                 : #define NS_STATE_SVG_CLIPPATH_CHILD              NS_FRAME_STATE_BIT(23)
     104                 : 
     105                 : // If this bit is set, redraw is suspended.
     106                 : #define NS_STATE_SVG_REDRAW_SUSPENDED            NS_FRAME_STATE_BIT(24)
     107                 : 
     108                 : /**
     109                 :  * Byte offsets of channels in a native packed gfxColor or cairo image surface.
     110                 :  */
     111                 : #ifdef IS_BIG_ENDIAN
     112                 : #define GFX_ARGB32_OFFSET_A 0
     113                 : #define GFX_ARGB32_OFFSET_R 1
     114                 : #define GFX_ARGB32_OFFSET_G 2
     115                 : #define GFX_ARGB32_OFFSET_B 3
     116                 : #else
     117                 : #define GFX_ARGB32_OFFSET_A 3
     118                 : #define GFX_ARGB32_OFFSET_R 2
     119                 : #define GFX_ARGB32_OFFSET_G 1
     120                 : #define GFX_ARGB32_OFFSET_B 0
     121                 : #endif
     122                 : 
     123                 : // maximum dimension of an offscreen surface - choose so that
     124                 : // the surface size doesn't overflow a 32-bit signed int using
     125                 : // 4 bytes per pixel; in line with gfxASurface::CheckSurfaceSize
     126                 : // In fact Macs can't even manage that
     127                 : #define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
     128                 : 
     129                 : #define SVG_WSP_DELIM       "\x20\x9\xD\xA"
     130                 : #define SVG_COMMA_WSP_DELIM "," SVG_WSP_DELIM
     131                 : 
     132                 : inline bool
     133                 : IsSVGWhitespace(char aChar)
     134                 : {
     135                 :   return aChar == '\x20' || aChar == '\x9' ||
     136                 :          aChar == '\xD'  || aChar == '\xA';
     137                 : }
     138                 : 
     139                 : inline bool
     140                 : IsSVGWhitespace(PRUnichar aChar)
     141                 : {
     142                 :   return aChar == PRUnichar('\x20') || aChar == PRUnichar('\x9') ||
     143                 :          aChar == PRUnichar('\xD')  || aChar == PRUnichar('\xA');
     144                 : }
     145                 : 
     146                 : /*
     147                 :  * Checks the smil enabled preference.  Declared as a function to match
     148                 :  * NS_SVGEnabled().
     149                 :  */
     150                 : bool NS_SMILEnabled();
     151                 : 
     152                 : 
     153                 : // GRRR WINDOWS HATE HATE HATE
     154                 : #undef CLIP_MASK
     155                 : 
     156                 : class NS_STACK_CLASS SVGAutoRenderState
     157                 : {
     158                 : public:
     159                 :   enum RenderMode { NORMAL, CLIP, CLIP_MASK };
     160                 : 
     161                 :   SVGAutoRenderState(nsRenderingContext *aContext, RenderMode aMode);
     162                 :   ~SVGAutoRenderState();
     163                 : 
     164                 :   void SetPaintingToWindow(bool aPaintingToWindow);
     165                 : 
     166                 :   static RenderMode GetRenderMode(nsRenderingContext *aContext);
     167                 :   static bool IsPaintingToWindow(nsRenderingContext *aContext);
     168                 : 
     169                 : private:
     170                 :   nsRenderingContext *mContext;
     171                 :   void *mOriginalRenderState;
     172                 :   RenderMode mMode;
     173                 :   bool mPaintingToWindow;
     174                 : };
     175                 : 
     176                 : 
     177                 : #define NS_ISVGFILTERPROPERTY_IID \
     178                 : { 0x9744ee20, 0x1bcf, 0x4c62, \
     179                 :  { 0x86, 0x7d, 0xd3, 0x7a, 0x91, 0x60, 0x3e, 0xef } }
     180                 : 
     181                 : class nsISVGFilterProperty : public nsISupports
     182               0 : {
     183                 : public:
     184                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGFILTERPROPERTY_IID)
     185                 :   virtual void Invalidate() = 0;
     186                 : };
     187                 : 
     188                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterProperty, NS_ISVGFILTERPROPERTY_IID)
     189                 : 
     190                 : class nsSVGUtils
     191                 : {
     192                 : public:
     193                 :   typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
     194                 :   typedef mozilla::SVGPreserveAspectRatio SVGPreserveAspectRatio;
     195                 : 
     196                 :   /*
     197                 :    * Get the parent element of an nsIContent
     198                 :    */
     199                 :   static mozilla::dom::Element *GetParentElement(nsIContent *aContent);
     200                 : 
     201                 :   /*
     202                 :    * Get the outer SVG element of an nsIContent
     203                 :    */
     204                 :   static nsSVGSVGElement *GetOuterSVGElement(nsSVGElement *aSVGElement);
     205                 : 
     206                 :   /*
     207                 :    * Get the number of CSS px (user units) per em (i.e. the em-height in user
     208                 :    * units) for an nsIContent
     209                 :    *
     210                 :    * XXX document the conditions under which these may fail, and what they
     211                 :    * return in those cases.
     212                 :    */
     213                 :   static float GetFontSize(mozilla::dom::Element *aElement);
     214                 :   static float GetFontSize(nsIFrame *aFrame);
     215                 :   static float GetFontSize(nsStyleContext *aStyleContext);
     216                 :   /*
     217                 :    * Get the number of CSS px (user units) per ex (i.e. the x-height in user
     218                 :    * units) for an nsIContent
     219                 :    *
     220                 :    * XXX document the conditions under which these may fail, and what they
     221                 :    * return in those cases.
     222                 :    */
     223                 :   static float GetFontXHeight(mozilla::dom::Element *aElement);
     224                 :   static float GetFontXHeight(nsIFrame *aFrame);
     225                 :   static float GetFontXHeight(nsStyleContext *aStyleContext);
     226                 : 
     227                 :   /*
     228                 :    * Converts image data from premultipled to unpremultiplied alpha
     229                 :    */
     230                 :   static void UnPremultiplyImageDataAlpha(PRUint8 *data, 
     231                 :                                           PRInt32 stride, 
     232                 :                                           const nsIntRect &rect);
     233                 :   /*
     234                 :    * Converts image data from unpremultipled to premultiplied alpha
     235                 :    */
     236                 :   static void PremultiplyImageDataAlpha(PRUint8 *data, 
     237                 :                                         PRInt32 stride, 
     238                 :                                         const nsIntRect &rect);
     239                 :   /*
     240                 :    * Converts image data from premultiplied sRGB to Linear RGB
     241                 :    */
     242                 :   static void ConvertImageDataToLinearRGB(PRUint8 *data, 
     243                 :                                           PRInt32 stride, 
     244                 :                                           const nsIntRect &rect);
     245                 :   /*
     246                 :    * Converts image data from LinearRGB to premultiplied sRGB
     247                 :    */
     248                 :   static void ConvertImageDataFromLinearRGB(PRUint8 *data, 
     249                 :                                             PRInt32 stride, 
     250                 :                                             const nsIntRect &rect);
     251                 : 
     252                 :   /*
     253                 :    * Report a localized error message to the error console.
     254                 :    */
     255                 :   static nsresult ReportToConsole(nsIDocument* doc,
     256                 :                                   const char* aWarning,
     257                 :                                   const PRUnichar **aParams,
     258                 :                                   PRUint32 aParamsLength);
     259                 : 
     260                 :   /*
     261                 :    * Converts a nsStyleCoord into a userspace value.  Handles units
     262                 :    * Factor (straight userspace), Coord (dimensioned), and Percent (of
     263                 :    * the current SVG viewport)
     264                 :    */
     265                 :   static float CoordToFloat(nsPresContext *aPresContext,
     266                 :                             nsSVGElement *aContent,
     267                 :                             const nsStyleCoord &aCoord);
     268                 : 
     269                 :   static gfxMatrix GetCTM(nsSVGElement *aElement, bool aScreenCTM);
     270                 : 
     271                 :   /**
     272                 :    * Check if this is one of the SVG elements that SVG 1.1 Full says
     273                 :    * establishes a viewport: svg, symbol, image or foreignObject.
     274                 :    */
     275                 :   static bool EstablishesViewport(nsIContent *aContent);
     276                 : 
     277                 :   static already_AddRefed<nsIDOMSVGElement>
     278                 :   GetNearestViewportElement(nsIContent *aContent);
     279                 : 
     280                 :   /**
     281                 :    * Gets the nearest nsSVGInnerSVGFrame or nsSVGOuterSVGFrame frame. aFrame
     282                 :    * must be an SVG frame. If aFrame is of type nsGkAtoms::svgOuterSVGFrame,
     283                 :    * returns nsnull.
     284                 :    */
     285                 :   static nsSVGDisplayContainerFrame* GetNearestSVGViewport(nsIFrame *aFrame);
     286                 :   
     287                 :   /**
     288                 :    * Figures out the worst case invalidation area for a frame, taking
     289                 :    * filters into account.
     290                 :    * Note that the caller is responsible for making sure that any cached
     291                 :    * covered regions in the frame tree rooted at aFrame are up to date.
     292                 :    * @param aRect the area in app units that needs to be invalidated in aFrame
     293                 :    * @return the rect in app units that should be invalidated, taking
     294                 :    * filters into account. Will return aRect when no filters are present.
     295                 :    */
     296                 :   static nsRect FindFilterInvalidation(nsIFrame *aFrame, const nsRect& aRect);
     297                 : 
     298                 :   /**
     299                 :    * Invalidates the area covered by the frame
     300                 :    */
     301                 :   static void InvalidateCoveredRegion(nsIFrame *aFrame);
     302                 : 
     303                 :   /*
     304                 :    * Update the area covered by the frame allowing for the frame to
     305                 :    * have moved.
     306                 :    */
     307                 :   static void UpdateGraphic(nsIFrame *aFrame);
     308                 : 
     309                 :   /*
     310                 :    * Update the filter invalidation region for ancestor frames, if relevant.
     311                 :    */
     312                 :   static void NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame);
     313                 : 
     314                 :   /* enum for specifying coordinate direction for ObjectSpace/UserSpace */
     315                 :   enum ctxDirection { X, Y, XY };
     316                 : 
     317                 :   /**
     318                 :    * Computes sqrt((aWidth^2 + aHeight^2)/2);
     319                 :    */
     320                 :   static double ComputeNormalizedHypotenuse(double aWidth, double aHeight);
     321                 : 
     322                 :   /* Computes the input length in terms of object space coordinates.
     323                 :      Input: rect - bounding box
     324                 :             length - length to be converted
     325                 :   */
     326                 :   static float ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength);
     327                 : 
     328                 :   /* Computes the input length in terms of user space coordinates.
     329                 :      Input: content - object to be used for determining user space
     330                 :      Input: length - length to be converted
     331                 :   */
     332                 :   static float UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength);
     333                 : 
     334                 :   /* Computes the input length in terms of user space coordinates.
     335                 :      Input: aFrame - object to be used for determining user space
     336                 :             length - length to be converted
     337                 :   */
     338                 :   static float UserSpace(nsIFrame *aFrame, const nsSVGLength2 *aLength);
     339                 : 
     340                 :   /* Returns the angle halfway between the two specified angles */
     341                 :   static float
     342                 :   AngleBisect(float a1, float a2);
     343                 : 
     344                 :   /* Find the outermost SVG frame of the passed frame */
     345                 :   static nsSVGOuterSVGFrame *
     346                 :   GetOuterSVGFrame(nsIFrame *aFrame);
     347                 : 
     348                 :   /**
     349                 :    * Get the covered region for a frame. Return null if it's not an SVG frame.
     350                 :    * @param aRect gets a rectangle in app units
     351                 :    * @return the outer SVG frame which aRect is relative to
     352                 :    */
     353                 :   static nsIFrame*
     354                 :   GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect);
     355                 : 
     356                 :   /* Generate a viewbox to viewport tranformation matrix */
     357                 : 
     358                 :   static gfxMatrix
     359                 :   GetViewBoxTransform(const nsSVGElement* aElement,
     360                 :                       float aViewportWidth, float aViewportHeight,
     361                 :                       float aViewboxX, float aViewboxY,
     362                 :                       float aViewboxWidth, float aViewboxHeight,
     363                 :                       const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio);
     364                 : 
     365                 :   static gfxMatrix
     366                 :   GetViewBoxTransform(const nsSVGElement* aElement,
     367                 :                       float aViewportWidth, float aViewportHeight,
     368                 :                       float aViewboxX, float aViewboxY,
     369                 :                       float aViewboxWidth, float aViewboxHeight,
     370                 :                       const SVGPreserveAspectRatio &aPreserveAspectRatio);
     371                 : 
     372                 :   /* Paint SVG frame with SVG effects - aDirtyRect is the area being
     373                 :    * redrawn, in device pixel coordinates relative to the outer svg */
     374                 :   static void
     375                 :   PaintFrameWithEffects(nsRenderingContext *aContext,
     376                 :                         const nsIntRect *aDirtyRect,
     377                 :                         nsIFrame *aFrame);
     378                 : 
     379                 :   /* Hit testing - check if point hits the clipPath of indicated
     380                 :    * frame.  Returns true if no clipPath set. */
     381                 :   static bool
     382                 :   HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint);
     383                 :   
     384                 :   /* Hit testing - check if point hits any children of frame. */
     385                 : 
     386                 :   static nsIFrame *
     387                 :   HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint);
     388                 : 
     389                 :   /*
     390                 :    * Returns the CanvasTM of the indicated frame, whether it's a
     391                 :    * child SVG frame, container SVG frame, or a regular frame.
     392                 :    * For regular frames, we just return an identity matrix.
     393                 :    */
     394                 :   static gfxMatrix GetCanvasTM(nsIFrame* aFrame);
     395                 : 
     396                 :   /*
     397                 :    * Tells child frames that something that might affect them has changed
     398                 :    */
     399                 :   static void
     400                 :   NotifyChildrenOfSVGChange(nsIFrame *aFrame, PRUint32 aFlags);
     401                 : 
     402                 :   /*
     403                 :    * Tells child frames that redraw is suspended
     404                 :    */
     405                 :   static void
     406                 :   NotifyRedrawSuspended(nsIFrame *aFrame);
     407                 : 
     408                 :   /*
     409                 :    * Tells child frames that redraw is no longer suspended
     410                 :    * @return true if any of the child frames are dirty
     411                 :    */
     412                 :   static void
     413                 :   NotifyRedrawUnsuspended(nsIFrame *aFrame);
     414                 : 
     415                 :   /*
     416                 :    * Get frame's covered region by walking the children and doing union.
     417                 :    */
     418                 :   static nsRect
     419                 :   GetCoveredRegion(const nsFrameList &aFrames);
     420                 : 
     421                 :   // Converts aPoint from an app unit point in outer-<svg> content rect space
     422                 :   // to an app unit point in a frame's SVG userspace. 
     423                 :   // This is a temporary helper we should no longer need after bug 614732 is
     424                 :   // fixed.
     425                 :   static nsPoint
     426                 :   TransformOuterSVGPointToChildFrame(nsPoint aPoint,
     427                 :                                      const gfxMatrix& aFrameToCanvasTM,
     428                 :                                      nsPresContext* aPresContext);
     429                 : 
     430                 :   static nsRect
     431                 :   TransformFrameRectToOuterSVG(const nsRect& aRect,
     432                 :                                const gfxMatrix& aMatrix,
     433                 :                                nsPresContext* aPresContext);
     434                 : 
     435                 :   /*
     436                 :    * Convert a surface size to an integer for use by thebes
     437                 :    * possibly making it smaller in the process so the surface does not
     438                 :    * use excessive memory.
     439                 :    *
     440                 :    * @param aSize the desired surface size
     441                 :    * @param aResultOverflows true if the desired surface size is too big
     442                 :    * @return the surface size to use
     443                 :    */
     444                 :   static gfxIntSize ConvertToSurfaceSize(const gfxSize& aSize,
     445                 :                                          bool *aResultOverflows);
     446                 : 
     447                 :   /*
     448                 :    * Hit test a given rectangle/matrix.
     449                 :    */
     450                 :   static bool
     451                 :   HitTestRect(const gfxMatrix &aMatrix,
     452                 :               float aRX, float aRY, float aRWidth, float aRHeight,
     453                 :               float aX, float aY);
     454                 : 
     455                 : 
     456                 :   /**
     457                 :    * Get the clip rect for the given frame, taking into account the CSS 'clip'
     458                 :    * property. See:
     459                 :    * http://www.w3.org/TR/SVG11/masking.html#OverflowAndClipProperties
     460                 :    * The arguments for aX, aY, aWidth and aHeight should be the dimensions of
     461                 :    * the viewport established by aFrame.
     462                 :    */
     463                 :   static gfxRect
     464                 :   GetClipRectForFrame(nsIFrame *aFrame,
     465                 :                       float aX, float aY, float aWidth, float aHeight);
     466                 : 
     467                 :   static void CompositeSurfaceMatrix(gfxContext *aContext,
     468                 :                                      gfxASurface *aSurface,
     469                 :                                      const gfxMatrix &aCTM, float aOpacity);
     470                 : 
     471                 :   static void CompositePatternMatrix(gfxContext *aContext,
     472                 :                                      gfxPattern *aPattern,
     473                 :                                      const gfxMatrix &aCTM, float aWidth, float aHeight, float aOpacity);
     474                 : 
     475                 :   static void SetClipRect(gfxContext *aContext,
     476                 :                           const gfxMatrix &aCTM,
     477                 :                           const gfxRect &aRect);
     478                 : 
     479                 :   /**
     480                 :    * Restricts aRect to pixels that intersect aGfxRect.
     481                 :    */
     482                 :   static void ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect);
     483                 : 
     484                 :   /* Using group opacity instead of fill or stroke opacity on a
     485                 :    * geometry object seems to be a common authoring mistake.  If we're
     486                 :    * not applying filters and not both stroking and filling, we can
     487                 :    * generate the same result without going through the overhead of a
     488                 :    * push/pop group. */
     489                 :   static bool
     490                 :   CanOptimizeOpacity(nsIFrame *aFrame);
     491                 : 
     492                 :   /* Calculate the maximum expansion of a matrix */
     493                 :   static float
     494                 :   MaxExpansion(const gfxMatrix &aMatrix);
     495                 : 
     496                 :   /**
     497                 :    * Take the CTM to userspace for an element, and adjust it to a CTM to its
     498                 :    * object bounding box space if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX.
     499                 :    * (I.e. so that [0,0] is at the top left of its bbox, and [1,1] is at the
     500                 :    * bottom right of its bbox).
     501                 :    *
     502                 :    * If the bbox is empty, this will return a singular matrix.
     503                 :    */
     504                 :   static gfxMatrix
     505                 :   AdjustMatrixForUnits(const gfxMatrix &aMatrix,
     506                 :                        nsSVGEnum *aUnits,
     507                 :                        nsIFrame *aFrame);
     508                 : 
     509                 :   enum BBoxFlags {
     510                 :     eBBoxIncludeFill          = 1 << 0,
     511                 :     eBBoxIgnoreFillIfNone     = 1 << 1,
     512                 :     eBBoxIncludeStroke        = 1 << 2,
     513                 :     eBBoxIgnoreStrokeIfNone   = 1 << 3,
     514                 :     eBBoxIncludeMarkers       = 1 << 4
     515                 :   };
     516                 :   /**
     517                 :    * Get the SVG bbox (the SVG spec's simplified idea of bounds) of aFrame in
     518                 :    * aFrame's userspace.
     519                 :    */
     520                 :   static gfxRect GetBBox(nsIFrame *aFrame, PRUint32 aFlags = eBBoxIncludeFill);
     521                 : 
     522                 :   /**
     523                 :    * Compute a rectangle in userSpaceOnUse or objectBoundingBoxUnits.
     524                 :    * @param aXYWH pointer to 4 consecutive nsSVGLength2 objects containing
     525                 :    * the x, y, width and height values in that order
     526                 :    * @param aBBox the bounding box of the object the rect is relative to;
     527                 :    * may be null if aUnits is not SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
     528                 :    * @param aFrame the object in which to interpret user-space units;
     529                 :    * may be null if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
     530                 :    */
     531                 :   static gfxRect
     532                 :   GetRelativeRect(PRUint16 aUnits, const nsSVGLength2 *aXYWH,
     533                 :                   const gfxRect &aBBox, nsIFrame *aFrame);
     534                 : 
     535                 :   /**
     536                 :    * Find the first frame, starting with aStartFrame and going up its
     537                 :    * parent chain, that is not an svgAFrame.
     538                 :    */
     539                 :   static nsIFrame* GetFirstNonAAncestorFrame(nsIFrame* aStartFrame);
     540                 : 
     541                 : #ifdef DEBUG
     542                 :   static void
     543                 :   WritePPM(const char *fname, gfxImageSurface *aSurface);
     544                 : #endif
     545                 : 
     546                 :   /**
     547                 :    * Compute the maximum possible device space stroke extents of a path given
     548                 :    * the path's device space path extents, its stroke style and its ctm.
     549                 :    *
     550                 :    * This is a workaround for the lack of suitable cairo API for getting the
     551                 :    * tight device space stroke extents of a path. This basically gives us the
     552                 :    * tightest extents that we can guarantee fully enclose the inked stroke
     553                 :    * without doing the calculations for the actual tight extents. We exploit
     554                 :    * the fact that cairo does have an API for getting the tight device space
     555                 :    * fill/path extents.
     556                 :    *
     557                 :    * This should die once bug 478152 is fixed.
     558                 :    */
     559                 :   static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
     560                 :                                                nsSVGGeometryFrame* aFrame,
     561                 :                                                const gfxMatrix& aMatrix);
     562                 :   static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
     563                 :                                                nsSVGPathGeometryFrame* aFrame,
     564                 :                                                const gfxMatrix& aMatrix);
     565                 : 
     566                 :   /**
     567                 :    * Convert a floating-point value to a 32-bit integer value, clamping to
     568                 :    * the range of valid integers.
     569                 :    */
     570               0 :   static PRInt32 ClampToInt(double aVal)
     571                 :   {
     572                 :     return NS_lround(NS_MAX(double(PR_INT32_MIN),
     573               0 :                             NS_MIN(double(PR_INT32_MAX), aVal)));
     574                 :   }
     575                 : 
     576                 :   /**
     577                 :    * Given a nsIContent* that is actually an nsSVGSVGElement*, this method
     578                 :    * checks whether it currently has a valid viewBox, and returns true if so.
     579                 :    *
     580                 :    * No other type of element should be passed to this method.
     581                 :    * (In debug builds, anything non-<svg> will trigger an abort; in non-debug
     582                 :    * builds, it will trigger a false return-value as a safe fallback.)
     583                 :    */
     584                 :   static bool RootSVGElementHasViewbox(const nsIContent *aRootSVGElem);
     585                 : 
     586                 :   static void GetFallbackOrPaintColor(gfxContext *aContext,
     587                 :                                       nsStyleContext *aStyleContext,
     588                 :                                       nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
     589                 :                                       float *aOpacity, nscolor *color);
     590                 : };
     591                 : 
     592                 : #endif

Generated by: LCOV version 1.7