diff --git a/gfx/thebes/public/Makefile.in b/gfx/thebes/public/Makefile.in index f70bba8f8274..bb5d49b70780 100644 --- a/gfx/thebes/public/Makefile.in +++ b/gfx/thebes/public/Makefile.in @@ -27,7 +27,7 @@ EXPORTS += gfxWindowsSurface.h endif ifeq ($(MOZ_GFX_TOOLKIT),gtk2) -EXPORTS += gfxXlibSurface.h +EXPORTS += gfxXlibSurface.h endif include $(topsrcdir)/config/rules.mk diff --git a/gfx/thebes/public/gfxASurface.h b/gfx/thebes/public/gfxASurface.h index 15dfddcf31e2..0c8fc3fa7657 100644 --- a/gfx/thebes/public/gfxASurface.h +++ b/gfx/thebes/public/gfxASurface.h @@ -50,11 +50,14 @@ public: cairo_surface_t* CairoSurface() { return mSurface; } protected: - void Init(cairo_surface_t *surface) { + cairo_surface_t* mSurface; + + void Init(cairo_surface_t* surface) { mDestroyed = PR_FALSE; mSurface = surface; } + PRBool mDestroyed; void Destroy() { if (mDestroyed) { NS_WARNING("Calling Destroy on an already-destroyed surface!"); @@ -70,10 +73,6 @@ protected: NS_WARNING("gfxASurface::~gfxASurface called, but cairo surface was not destroyed! (Did someone forget to call Destroy()?)"); } } - -protected: - cairo_surface_t *mSurface; - PRBool mDestroyed; }; #endif /* GFX_ASURFACE_H */ diff --git a/gfx/thebes/public/gfxColor.h b/gfx/thebes/public/gfxColor.h index 36db8fe7876f..49f70d955a2b 100644 --- a/gfx/thebes/public/gfxColor.h +++ b/gfx/thebes/public/gfxColor.h @@ -49,10 +49,10 @@ struct gfxRGBA { gfxRGBA(const gfxRGBA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {} gfxRGBA(gfxFloat _r, gfxFloat _g, gfxFloat _b, gfxFloat _a=1.0) : r(_r), g(_g), b(_b), a(_a) {} gfxRGBA(PRUint32 c) { - a = (c & 0xff) / 255.0; - r = ((c >> 8) & 0xff) / 255.0; - g = ((c >> 16) & 0xff) / 255.0; - b = ((c >> 24) & 0xff) / 255.0; + r = ((c >> 0) & 0xff) / 255.0; + g = ((c >> 8) & 0xff) / 255.0; + b = ((c >> 16) & 0xff) / 255.0; + a = ((c >> 24) & 0xff) / 255.0; } gfxRGBA(const char* str) { a = 1.0; diff --git a/gfx/thebes/public/gfxContext.h b/gfx/thebes/public/gfxContext.h index a131036eaa76..6662eb4653b2 100644 --- a/gfx/thebes/public/gfxContext.h +++ b/gfx/thebes/public/gfxContext.h @@ -127,8 +127,10 @@ public: gfxPoint DeviceToUser(gfxPoint point) const; gfxSize DeviceToUser(gfxSize size) const; + gfxRect DeviceToUser(gfxRect rect) const; gfxPoint UserToDevice(gfxPoint point) const; gfxSize UserToDevice(gfxSize size) const; + gfxRect UserToDevice(gfxRect rect) const; /** ** Painting sources @@ -139,7 +141,7 @@ public: void SetSource(gfxASurface *surface) { SetSource(surface, gfxPoint(0, 0)); } - void SetSource(gfxASurface* surface, gfxPoint origin); + void SetSource(gfxASurface* surface, gfxPoint offset); /** ** Painting diff --git a/gfx/thebes/public/gfxMatrix.h b/gfx/thebes/public/gfxMatrix.h index 3d82f26d2ad1..954d4061e59e 100644 --- a/gfx/thebes/public/gfxMatrix.h +++ b/gfx/thebes/public/gfxMatrix.h @@ -136,11 +136,11 @@ public: cairo_matrix_transform_point(&mat, x, y); } - gfxSize GetScale() const { + gfxSize GetScaling() const { return gfxSize(mat.xx, mat.yy); } - gfxPoint GetTranslate() const { + gfxPoint GetTranslation() const { return gfxPoint(mat.x0, mat.y0); } diff --git a/gfx/thebes/public/gfxPoint.h b/gfx/thebes/public/gfxPoint.h index aceef7963343..1d454cbdccc0 100644 --- a/gfx/thebes/public/gfxPoint.h +++ b/gfx/thebes/public/gfxPoint.h @@ -60,6 +60,9 @@ struct gfxSize { gfxSize operator+(const gfxSize& s) const { return gfxSize(width + s.width, height + s.height); } + gfxSize operator-() const { + return gfxSize(- width, - height); + } }; struct gfxPoint { @@ -89,6 +92,16 @@ struct gfxPoint { gfxPoint operator-(const gfxSize& s) const { return gfxPoint(x - s.width, y - s.height); } + gfxPoint operator-(const gfxPoint& p) const { + return gfxPoint(x - p.x, y - p.y); + } + gfxPoint operator-(const gfxSize& s) const { + return gfxPoint(x - s.width, y - s.height); + } + gfxPoint operator-() const { + return gfxPoint(- x, - y); + } + gfxPoint& round() { x = ::floor(x + 0.5); y = ::floor(y + 0.5); diff --git a/gfx/thebes/src/gfxContext.cpp b/gfx/thebes/src/gfxContext.cpp index 082a4f0975d6..ad996dcc0010 100644 --- a/gfx/thebes/src/gfxContext.cpp +++ b/gfx/thebes/src/gfxContext.cpp @@ -267,6 +267,14 @@ gfxSize gfxContext::DeviceToUser(gfxSize size) const return ret; } +gfxRect gfxContext::DeviceToUser(gfxRect rect) const +{ + gfxRect ret = rect; + cairo_device_to_user(mCairo, &ret.pos.x, &ret.pos.y); + cairo_device_to_user_distance(mCairo, &ret.size.width, &ret.size.height); + return ret; +} + gfxPoint gfxContext::UserToDevice(gfxPoint point) const { gfxPoint ret = point; @@ -281,6 +289,14 @@ gfxSize gfxContext::UserToDevice(gfxSize size) const return ret; } +gfxRect gfxContext::UserToDevice(gfxRect rect) const +{ + gfxRect ret = rect; + cairo_user_to_device(mCairo, &ret.pos.x, &ret.pos.y); + cairo_user_to_device_distance(mCairo, &ret.size.width, &ret.size.height); + return ret; +} + void gfxContext::SetAntialiasMode(AntialiasMode mode) { // XXX implement me @@ -376,7 +392,7 @@ void gfxContext::Clip(const gfxRegion& region) void gfxContext::Clip() { - cairo_clip(mCairo); + cairo_clip_preserve(mCairo); } void gfxContext::ResetClip() @@ -397,9 +413,9 @@ void gfxContext::SetPattern(gfxPattern *pattern) cairo_set_source(mCairo, pattern->CairoPattern()); } -void gfxContext::SetSource(gfxASurface *surface, gfxPoint origin) +void gfxContext::SetSource(gfxASurface *surface, gfxPoint offset) { - cairo_set_source_surface(mCairo, surface->CairoSurface(), origin.x, origin.y); + cairo_set_source_surface(mCairo, surface->CairoSurface(), offset.x, offset.y); } // fonts? diff --git a/gfx/thebes/src/gfxPattern.cpp b/gfx/thebes/src/gfxPattern.cpp new file mode 100644 index 000000000000..88751a4cf69c --- /dev/null +++ b/gfx/thebes/src/gfxPattern.cpp @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * ***** 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 Oracle Corporation code. + * + * The Initial Developer of the Original Code is Oracle Corporation. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Stuart Parmenter + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 ***** */ + +#include "gfxPattern.h" + +THEBES_IMPL_REFCOUNTING(gfxPattern)