1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 Oracle Corporation code.
16 : *
17 : * The Initial Developer of the Original Code is Oracle Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2005
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Stuart Parmenter <stuart@mozilla.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef GFX_PATTERN_H
39 : #define GFX_PATTERN_H
40 :
41 : #include "gfxTypes.h"
42 :
43 : #include "gfxColor.h"
44 : #include "gfxMatrix.h"
45 : #include "nsISupportsImpl.h"
46 : #include "nsAutoPtr.h"
47 : #include "mozilla/gfx/2D.h"
48 : #include "mozilla/Util.h"
49 :
50 : class gfxContext;
51 : class gfxASurface;
52 : typedef struct _cairo_pattern cairo_pattern_t;
53 :
54 :
55 : class THEBES_API gfxPattern {
56 0 : NS_INLINE_DECL_REFCOUNTING(gfxPattern)
57 :
58 : public:
59 : gfxPattern(cairo_pattern_t *aPattern);
60 : gfxPattern(const gfxRGBA& aColor);
61 : gfxPattern(gfxASurface *surface); // from another surface
62 : // linear
63 : gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
64 : gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
65 : gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
66 : gfxPattern(mozilla::gfx::SourceSurface *aSurface,
67 : const mozilla::gfx::Matrix &aTransform); // Azure
68 : virtual ~gfxPattern();
69 :
70 : cairo_pattern_t *CairoPattern();
71 : void AddColorStop(gfxFloat offset, const gfxRGBA& c);
72 :
73 : void SetMatrix(const gfxMatrix& matrix);
74 : gfxMatrix GetMatrix() const;
75 :
76 : mozilla::gfx::Pattern *GetPattern(mozilla::gfx::DrawTarget *aTarget);
77 : bool IsOpaque();
78 :
79 : enum GraphicsExtend {
80 : EXTEND_NONE,
81 : EXTEND_REPEAT,
82 : EXTEND_REFLECT,
83 : EXTEND_PAD,
84 :
85 : // Our own private flag for setting either NONE or PAD,
86 : // depending on what the platform does for NONE. This is only
87 : // relevant for surface patterns; for all other patterns, it
88 : // behaves identical to PAD. On MacOS X, this becomes "NONE",
89 : // because Quartz does the thing that we want at image edges;
90 : // similarily on the win32 printing surface, since
91 : // everything's done with GDI there. On other platforms, it
92 : // usually becomes PAD.
93 : EXTEND_PAD_EDGE = 1000
94 : };
95 :
96 : // none, repeat, reflect
97 : void SetExtend(GraphicsExtend extend);
98 : GraphicsExtend Extend() const;
99 :
100 : enum GraphicsPatternType {
101 : PATTERN_SOLID,
102 : PATTERN_SURFACE,
103 : PATTERN_LINEAR,
104 : PATTERN_RADIAL
105 : };
106 :
107 : GraphicsPatternType GetType() const;
108 :
109 : int CairoStatus();
110 :
111 : enum GraphicsFilter {
112 : FILTER_FAST,
113 : FILTER_GOOD,
114 : FILTER_BEST,
115 : FILTER_NEAREST,
116 : FILTER_BILINEAR,
117 : FILTER_GAUSSIAN
118 : };
119 :
120 : void SetFilter(GraphicsFilter filter);
121 : GraphicsFilter Filter() const;
122 :
123 : /* returns TRUE if it succeeded */
124 : bool GetSolidColor(gfxRGBA& aColor);
125 :
126 : already_AddRefed<gfxASurface> GetSurface();
127 :
128 : protected:
129 : cairo_pattern_t *mPattern;
130 :
131 : union {
132 : mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
133 : mozilla::AlignedStorage2<mozilla::gfx::LinearGradientPattern> mLinearGradientPattern;
134 : mozilla::AlignedStorage2<mozilla::gfx::RadialGradientPattern> mRadialGradientPattern;
135 : mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
136 : };
137 :
138 : mozilla::gfx::Pattern *mGfxPattern;
139 :
140 : mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
141 : mozilla::gfx::Matrix mTransform;
142 : mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
143 : mozilla::gfx::ExtendMode mExtend;
144 : mozilla::gfx::Filter mFilter;
145 : };
146 :
147 : #endif /* GFX_PATTERN_H */
|