New graphics API. The future is here.

This commit is contained in:
pavlov%pavlov.net 2005-04-06 01:54:26 +00:00
Родитель e188c9c6d6
Коммит 428e04ae5d
17 изменённых файлов: 1411 добавлений и 0 удалений

13
gfx/thebes/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,13 @@
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = thebes
DIRS = public src
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,27 @@
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = thebes
EXPORTS = gfxASurface.h \
gfxColor.h \
gfxContext.h \
gfxFilter.h \
gfxImageSurface.h \
gfxMatrix.h \
gfxPattern.h \
gfxPoint.h \
gfxRegion.h \
gfxTextRun.h \
$(NULL)
ifeq ($(MOZ_GFX_TOOLKIT),windows)
EXPORTS += gfxWindowsSurface.h
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef GFXASURFACE_H
#define GFXASURFACE_H
#include <cairo.h>
// this key can be used to look up a Surface object given a cairo_surface_t
#ifdef CURRENT_VERSION_OF_CAIRO
static cairo_user_data_key_t gSurfaceMapKey;
#endif
class gfxASurface {
public:
// <insert refcount stuff here>
cairo_surface_t *CairoSurface() { return mSurface; }
static gfxASurface* LookupSurface(cairo_surface_t* surface) {
#ifdef CURRENT_VERSION_OF_CAIRO
return static_cast<gfxASurface*>(cairo_surface_get_user_data(surface, &gSurfaceMapKey));
#else
return 0;
#endif
}
protected:
void Init(cairo_surface_t* surface) {
mSurface = surface;
#ifdef CURRENT_VERSION_OF_CAIRO
cairo_surface_set_user_data(mSurface, &gSurfaceMapKey, static_cast<void*>(this), 0);
#endif
}
virtual ~gfxASurface() {
cairo_surface_destroy(mSurface);
}
private:
cairo_surface_t* mSurface;
};
#endif /* GFXASURFACE_H */

Просмотреть файл

@ -0,0 +1,72 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef GFXCOLOR_H
#define GFXCOLOR_H
struct gfxRGBA {
double r, g, b, a;
gfxRGBA() { }
gfxRGBA(const gfxRGBA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}
gfxRGBA(double _r, double _g, double _b, double _a=1.0) : r(_r), g(_g), b(_b), a(_a) {}
gfxRGBA(unsigned long c) {
a = (c & 0xff) / 255.0;
r = ((c >> 8) & 0xff) / 255.0;
g = ((c >> 16) & 0xff) / 255.0;
b = ((c >> 24) & 0xff) / 255.0;
}
gfxRGBA(const char* str) {
a = 1.0;
// if aString[0] is a #, parse it as hex
// if aString[0] is a letter, parse it as a color name
// if aString[0] is a number, parse it loosely as hex
}
unsigned long Packed() {
return (((unsigned char)(a * 255.0) << 24) |
((unsigned char)(b * 255.0) << 16) |
((unsigned char)(g * 255.0) << 8) |
((unsigned char)(r * 255.0)));
}
const char* Hex() const {
}
};
#endif /* GFXCOLOR_H */

Просмотреть файл

@ -0,0 +1,174 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef GFXCONTEXT_H
#define GFXCONTEXT_H
#include <cairo.h>
#include "gfxColor.h"
#include "gfxPattern.h"
#include "gfxPoint.h"
class gfxASurface;
class gfxMatrix;
class gfxRegion;
class gfxRect;
class gfxFilter;
class gfxTextRun;
class gfxContext {
public:
gfxContext();
~gfxContext();
// <insert refcount stuff here>
void SetSurface(gfxASurface* surface);
gfxASurface* CurrentSurface();
// state
void Save();
void Restore();
// drawing
void NewPath();
void ClosePath();
void Stroke();
void Fill();
void MoveTo(double x, double y);
void LineTo(double x, double y);
void CurveTo(double x1, double y1,
double x2, double y2,
double x3, double y3);
void Arc(double xc, double yc,
double radius,
double angle1, double angle2);
void Rectangle(double x, double y, double width, double height);
void Polygon(const gfxPoint points[], unsigned long numPoints);
void DrawSurface(gfxASurface *surface, double width, double height);
// transform stuff
void Translate(double x, double y);
void Scale(double x, double y);
void Rotate(double angle);
void SetMatrix(const gfxMatrix& matrix);
gfxMatrix CurrentMatrix() const;
// properties
void SetColor(const gfxRGBA& c);
gfxRGBA CurrentColor() const;
void SetDash(double* dashes, int ndash, double offset);
//void getDash() const;
void SetLineWidth(double width);
double CurrentLineWidth() const;
// define enum for operators (clear, src, dst, etc)
enum GraphicsOperator {
OPERATOR_CLEAR,
OPERATOR_SRC,
OPERATOR_DST,
OPERATOR_OVER,
OPERATOR_OVER_REVERSE,
OPERATOR_IN,
OPERATOR_IN_REVERSE,
OPERATOR_OUT,
OPERATOR_OUT_REVERSE,
OPERATOR_ATOP,
OPERATOR_ATOP_REVERSE,
OPERATOR_XOR,
OPERATOR_ADD,
OPERATOR_SATURATE
};
void SetOperator(GraphicsOperator op);
GraphicsOperator CurrentOperator() const;
enum GraphicsLineCap {
LINE_CAP_BUTT,
LINE_CAP_ROUND,
LINE_CAP_SQUARE
};
void SetLineCap(GraphicsLineCap cap);
GraphicsLineCap CurrentLineCap() const;
enum GraphicsLineJoin {
LINE_JOIN_MITER,
LINE_JOIN_ROUND,
LINE_JOIN_BEVEL
};
void SetLineJoin(GraphicsLineJoin join);
GraphicsLineJoin CurrentLineJoin() const;
void SetMiterLimit(double limit);
double CurrentMiterLimit() const;
// clipping
void Clip(const gfxRect& rect); // will clip to a rect
void Clip(const gfxRegion& region); // will clip to a region
void Clip(); // will clip the last path you've drawn
void ResetClip();
// patterns
void SetPattern(gfxPattern& pattern);
// fonts?
void DrawString(gfxTextRun& text, int pos, int len);
// filters
// Start rendering under the filter. We guarantee not to draw outside 'maxArea'.
void PushFilter(gfxFilter& filter, gfxRect& maxArea);
// Completed rendering under the filter, composite what we rendered back to the
// underlying surface using the filter.
void PopFilter();
private:
cairo_t *mCairo;
};
#endif /* GFXCONTEXT_H */

Просмотреть файл

@ -0,0 +1,46 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef GFXFILTER_H
#define GFXFILTER_H
class gfxFilter {
static gfxFilter* CreateOpacityFilter(double alpha);
// CreateGaussianFilter, etc
};
#endif /* GFXFILTER_H */

Просмотреть файл

@ -0,0 +1,66 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef GFXSURFACEIMAGE_H
#define GFXSURFACEIMAGE_H
#include "gfxASurface.h"
#include "gfxPoint.h"
// ARGB -- raw buffer.. wont be changed.. good for storing data.
class gfxImageSurface : public gfxASurface {
public:
ImageSurface(int format, long width, long height);
virtual ~ImageSurface();
// <insert refcount stuff here>
// ImageSurface methods
int Format() const { return 0; }
long Width() const { return mWidth; }
long Height() const { return mHeight; }
unsigned char* GetData() { return mData; } // delete this data under us and die.
private:
unsigned char* mData;
int mFormat;
long mWidth;
long mHeight;
};
#endif /* GFXSURFACEIMAGE_H */

Просмотреть файл

@ -0,0 +1,140 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef MATRIX_H
#define MATRIX_H
#ifdef _MSC_VER
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#include <cairo.h>
class gfxMatrix {
private:
double m0, m1, m2, m3, m4, m5;
public:
gfxMatrix() { Reset(); }
gfxMatrix(const gfxMatrix& m) :
m0(m.m0), m1(m.m1), m2(m.m2), m3(m.m3), m4(m.m4), m5(m.m5) {}
gfxMatrix(double a, double b, double c, double d, double tx, double ty) :
m0(a), m1(b), m2(c), m3(d), m4(tx), m5(ty) {}
gfxMatrix(const cairo_matrix_t* m) {
cairo_matrix_get_affine(const_cast<cairo_matrix_t*>(m),
&m0, &m1, &m2, &m3, &m4, &m5);
}
gfxMatrix& operator=(const cairo_matrix_t* m) {
cairo_matrix_get_affine(const_cast<cairo_matrix_t*>(m),
&m0, &m1, &m2, &m3, &m4, &m5);
return *this;
}
const gfxMatrix& operator *= (const gfxMatrix& m) {
return Multiply(m);
}
gfxMatrix operator * (const gfxMatrix& m) {
return gfxMatrix(*this).Multiply(m);
}
// this name sucks ass. pick something better
void FillInCairoMatrix(cairo_matrix_t* m) const {
cairo_matrix_set_affine(m, m0, m1, m2, m3, m4, m5);
}
const gfxMatrix& Reset() {
m0 = m3 = 1.0;
m1 = m2 = m4 = m5 = 0.0;
return *this;
}
const gfxMatrix& Invert() {
// impl me
return *this;
}
const gfxMatrix& Scale(double x, double y) {
gfxMatrix t(x, 0, 0, y, 0, 0);
return *this = t.Multiply(*this);
}
const gfxMatrix& Translate(double x, double y) {
gfxMatrix t(1, 0, 0, 1, x, y);
return *this = t.Multiply(*this);
}
const gfxMatrix& Rotate(double radians) {
double s = sin(radians);
double c = cos(radians);
gfxMatrix t( c, s,
-s, c,
0, 0);
return *this = t.Multiply(*this);
}
const gfxMatrix& Multiply(const gfxMatrix& m) {
double t0 = m0 * m.m0 + m1 * m.m2;
double t2 = m2 * m.m0 + m3 * m.m2;
double t4 = m4 * m.m0 + m5 * m.m2 + m.m4;
m1 = m0 * m.m1 + m1 * m.m3;
m3 = m2 * m.m1 + m3 * m.m3;
m5 = m4 * m.m1 + m5 * m.m3 + m.m5;
m0 = t0;
m2 = t2;
m4 = t4;
return *this;
}
void TransformDistance(double *dx, double *dy) const {
double new_x = m0 * *dx + m2 * *dy;
double new_y = m1 * *dx + m3 * *dy;
*dx = new_x;
*dy = new_y;
}
void TransformPoint(double *x, double *y) const {
TransformDistance(x, y);
*x += m4;
*y += m5;
}
};
#endif /* MATRIX_H */

Просмотреть файл

@ -0,0 +1,110 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef PATTERN_H
#define PATTERN_H
#include <cairo.h>
#include "gfxColor.h"
#include "gfxASurface.h"
#include "gfxMatrix.h"
class gfxPattern {
public:
// from another surface
gfxPattern(gfxASurface& surface) {
mPattern = cairo_pattern_create_for_surface(surface.CairoSurface());
}
// linear
gfxPattern(double x0, double y0, double x1, double y1) {
mPattern = cairo_pattern_create_linear(x0, y0, x1, y1);
}
// radial
gfxPattern(double cx0, double cy0, double radius0,
double cx1, double cy1, double radius1) {
mPattern = cairo_pattern_create_radial(cx0, cy0, radius0,
cx1, cy1, radius1);
}
~gfxPattern() {
cairo_pattern_destroy(mPattern);
}
cairo_pattern_t *CairoPattern() {
return mPattern;
}
void AddColorStop(double offset, const gfxRGBA& c) {
cairo_pattern_add_color_stop(mPattern, offset, c.r, c.g, c.b, c.a);
}
void SetMatrix(const gfxMatrix& matrix) {
cairo_matrix_t *t = cairo_matrix_create();
matrix.FillInCairoMatrix(t);
cairo_pattern_set_matrix(mPattern, t); // this does a copy
cairo_matrix_destroy(t);
}
gfxMatrix CurrentMatrix() const {
gfxMatrix matrix;
cairo_matrix_t *t = cairo_matrix_create();
cairo_pattern_get_matrix(mPattern, t);
matrix = t;
cairo_matrix_destroy(t);
return matrix;
}
// none, repeat, reflect
void SetExtend(int extend) {
cairo_pattern_set_extend(mPattern, (cairo_extend_t)extend);
}
int Extend() const {
return (int)cairo_pattern_get_extend(mPattern);
}
void SetFilter(int filter) {
cairo_pattern_set_filter(mPattern, (cairo_filter_t)filter);
}
int Filter() const {
return (int)cairo_pattern_get_filter(mPattern);
}
private:
gfxPattern(cairo_pattern_t *pattern) : mPattern(pattern) {}
cairo_pattern_t *mPattern;
};
#endif /* PATTERN_H */

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef POINT_H
#define POINT_H
struct gfxSize {
double width, height;
gfxSize() {}
gfxSize(const gfxSize& s) : width(s.width), height(s.height) {}
gfxSize(double _width, double _height) : width(_width), height(_height) {}
void SizeTo(double _width, double _height) {width = _width; height = _height;}
int operator==(const gfxSize& s) const {
return ((width == s.width) && (height == s.height));
}
int operator!=(const gfxSize& s) const {
return ((width != s.width) || (height != s.height));
}
};
struct gfxPoint {
double x, y;
gfxPoint() { }
gfxPoint(const gfxPoint& p) : x(p.x), y(p.y) {}
gfxPoint(double _x, double _y) : x(_x), y(_y) {}
void MoveTo(double aX, double aY) { x = aX; y = aY; }
int operator==(const gfxPoint& p) const {
return ((x == p.x) && (y == p.y));
}
int operator!=(const gfxPoint& p) const {
return ((x != p.x) || (y != p.y));
}
};
#endif /* POINT_H */

Просмотреть файл

@ -0,0 +1,80 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
/*
* *********************************************************
* This file is under construction. Ignore it for a while.
* *********************************************************
*/
class gfxRegion {
public:
gfxRegion(const gfxRegion& r);
gfxRegion(const gfxRect& r);
gfxRegion& operator=(const gfxRegion& r);
gfxRegion& operator=(const gfxRect& r);
int operator==(const gfxRegion& r) const;
int operator!=(const gfxRegion& r) const;
gfxPoint& operator+=(const gfxRegion& r); // Union
gfxPoint& operator+=(const gfxRect& r); // Union
gfxPoint& operator-=(const gfxRegion& r); // Subtract
gfxPoint& operator-=(const gfxRect& r); // Subtract
void SetTo(const nsIRegion &aRegion);
void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
void Intersect(const nsIRegion &aRegion);
void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
void Union(const nsIRegion &aRegion);
void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
void Subtract(const nsIRegion &aRegion);
void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
PRBool IsEmpty(void);
PRBool IsEqual(const nsIRegion &aRegion);
void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight);
void Offset(PRInt32 aXOffset, PRInt32 aYOffset);
PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
void GetRects(nsRegionRectSet **aRects);
void FreeRects(nsRegionRectSet *aRects);
void GetNativeRegion(void *&aRegion) const;
void GetRegionComplexity(nsRegionComplexity &aComplexity) const;
void GetNumRects(PRUint32 *aRects) const;
};

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
class gfxTextRun {
// these do not copy the text
gfxTextRun(const char* ASCII, int length);
gfxTextRun(const PRUnichar* unicode, int length);
void SetFont(nsFont* font, nsIAtom* language);
enum { ClusterStart = 0x1 } CharFlags;
// ClusterStart: character is the first character of a cluster/glyph
void GetCharacterFlags(int pos, int len, CharFlags* flags);
struct Dimensions {
double ascent, descent, width, leftBearing, rightBearing;
};
Dimensions MeasureText(int pos, int len);
// Compute how many characters from this string starting at
// character 'pos' and up to length 'len' fit
// into the given width. 'breakflags' indicates our
// preferences about where we allow breaks.
// We will usually want to call MeasureText right afterwards,
// the implementor could optimize for that.
int GetCharsFit(int pos, int len, double width, int breakflags);
int GetPositionInString(gfxPoint pt);
};

Просмотреть файл

@ -0,0 +1,55 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 ***** */
#ifndef WINDOWSSURFACE_H
#define WINDOWSSURFACE_H
#include "gfxASurface.h"
#include "gfxPoint.h"
#define CAIRO_HAS_WIN32_SURFACE 1
#include <cairo-win32.h>
class gfxWindowsSurface : public gfxASurface {
public:
gfxWindowsSurface(HDC dc);
virtual ~gfxWindowsSurface();
// <insert refcount stuff here>
};
#endif /* WINDOWSSURFACE_H */

Просмотреть файл

@ -0,0 +1,28 @@
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = thebes
LIBRARY_NAME = libthebes
LIBXUL_LIBRARY = 1
REQUIRES = cairo libpixman
CPPSRCS = \
gfxContext.cpp \
gfxImageSurface.cpp
ifeq ($(MOZ_GFX_TOOLKIT),windows)
CPPSRCS += gfxWindowsSurface.cpp
endif
FORCE_STATIC_LIB = 1
# This library is used by other shared libs in a static build
FORCE_USE_PIC = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,282 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 "gfxContext.h"
#include "gfxColor.h"
#include "gfxMatrix.h"
#include "gfxASurface.h"
#include "gfxPattern.h"
gfxContext::gfxContext()
{
mCairo = cairo_create();
}
gfxContext::~gfxContext()
{
cairo_destroy(mCairo);
}
void gfxContext::SetSurface(gfxASurface* surface)
{
cairo_set_target_surface(mCairo, surface->CairoSurface());
}
gfxASurface* gfxContext::CurrentSurface()
{
// XXX refcounting of get_target_surface may change
cairo_surface_t *surface = cairo_current_target_surface(mCairo);
return gfxASurface::LookupSurface(surface);
}
void gfxContext::Save()
{
cairo_save(mCairo);
}
void gfxContext::Restore()
{
cairo_restore(mCairo);
}
// drawing
void gfxContext::NewPath()
{
cairo_new_path(mCairo);
}
void gfxContext::ClosePath()
{
cairo_close_path(mCairo);
}
void gfxContext::Stroke()
{
cairo_stroke(mCairo);
}
void gfxContext::Fill()
{
cairo_fill(mCairo);
}
void gfxContext::MoveTo(double x, double y)
{
cairo_move_to(mCairo, x, y);
}
void gfxContext::LineTo(double x, double y)
{
cairo_line_to(mCairo, x, y);
}
void gfxContext::CurveTo(double x1, double y1,
double x2, double y2,
double x3, double y3)
{
cairo_curve_to(mCairo, x1, y1, x2, y2, x3, y3);
}
void gfxContext::Arc(double xc, double yc,
double radius,
double angle1, double angle2)
{
cairo_arc(mCairo, xc, yc, radius, angle1, angle2);
}
void gfxContext::Rectangle(double x, double y, double width, double height)
{
cairo_rectangle(mCairo, x, y, width, height);
}
void gfxContext::Polygon(const gfxPoint points[], unsigned long numPoints)
{
cairo_new_path(mCairo);
cairo_move_to(mCairo, (double)points[0].x, (double)points[0].y);
for (unsigned long i = 1; i < numPoints; ++i) {
cairo_line_to(mCairo, (double)points[i].x, (double)points[i].y);
}
}
void gfxContext::DrawSurface(gfxASurface *surface, double width, double height)
{
cairo_show_surface(mCairo, surface->CairoSurface(),
(int)width, (int)height);
}
// transform stuff
void gfxContext::Translate(double x, double y)
{
cairo_translate(mCairo, x, y);
}
void gfxContext::Scale(double x, double y)
{
cairo_scale(mCairo, x, y);
}
void gfxContext::Rotate(double angle)
{
cairo_rotate(mCairo, angle);
}
void gfxContext::SetMatrix(const gfxMatrix& matrix)
{
cairo_matrix_t *t = cairo_matrix_create();
matrix.FillInCairoMatrix(t);
cairo_set_matrix(mCairo, t); // this does a copy
cairo_matrix_destroy(t);
}
gfxMatrix gfxContext::CurrentMatrix() const
{
gfxMatrix matrix;
cairo_matrix_t *t = cairo_matrix_create();
cairo_current_matrix(mCairo, t);
matrix = t;
cairo_matrix_destroy(t);
return matrix;
}
// properties
void gfxContext::SetColor(const gfxRGBA& c)
{
cairo_set_rgb_color(mCairo, c.r, c.g, c.b);
cairo_set_alpha(mCairo, c.a);
}
gfxRGBA gfxContext::CurrentColor() const
{
gfxRGBA c;
cairo_current_rgb_color(mCairo, &c.r, &c.b, &c.b);
c.a = cairo_current_alpha(mCairo);
return c;
}
void gfxContext::SetDash(double* dashes, int ndash, double offset)
{
cairo_set_dash(mCairo, dashes, ndash, offset);
}
//void getDash() const;
void gfxContext::SetLineWidth(double width)
{
cairo_set_line_width(mCairo, width);
}
double gfxContext::CurrentLineWidth() const
{
return cairo_current_line_width(mCairo);
}
void gfxContext::SetOperator(GraphicsOperator op)
{
cairo_set_operator(mCairo, (cairo_operator_t)op);
}
gfxContext::GraphicsOperator gfxContext::CurrentOperator() const
{
return (GraphicsOperator)cairo_current_operator(mCairo);
}
void gfxContext::SetLineCap(GraphicsLineCap cap)
{
cairo_set_line_cap(mCairo, (cairo_line_cap_t)cap);
}
gfxContext::GraphicsLineCap gfxContext::CurrentLineCap() const
{
return (GraphicsLineCap)cairo_current_line_cap(mCairo);
}
void gfxContext::SetLineJoin(GraphicsLineJoin join)
{
cairo_set_line_join(mCairo, (cairo_line_join_t)join);
}
gfxContext::GraphicsLineJoin gfxContext::CurrentLineJoin() const
{
return (GraphicsLineJoin)cairo_current_line_join(mCairo);
}
void gfxContext::SetMiterLimit(double limit)
{
cairo_set_miter_limit(mCairo, limit);
}
double gfxContext::CurrentMiterLimit() const
{
return cairo_current_miter_limit(mCairo);
}
// clipping
void gfxContext::Clip(const gfxRect& rect)
{
/*
cairo_new_path();
cairo_rectangle(mCairo, rect.x, rect.y, rect.width, rect.height);
cairo_clip();
*/
}
void gfxContext::Clip(const gfxRegion& region)
{
}
void gfxContext::Clip()
{
cairo_clip(mCairo);
}
void gfxContext::ResetClip()
{
cairo_init_clip(mCairo);
}
// patterns
void gfxContext::SetPattern(gfxPattern& pattern)
{
cairo_set_pattern(mCairo, pattern.CairoPattern());
}
// fonts?
void gfxContext::DrawString(gfxTextRun& text, int pos, int len)
{
}
// filters
void gfxContext::PushFilter(gfxFilter& filter, gfxRect& maxArea)
{
}
void gfxContext::PopFilter()
{
}

Просмотреть файл

@ -0,0 +1,56 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 "ImageSurface.h"
ImageSurface::ImageSurface(int format, long width, long height) :
mFormat(format), mWidth(width), mHeight(height)
{
mData = new unsigned char[width * height * 4];
Init(cairo_image_surface_create_for_data((char*)mData,
CAIRO_FORMAT_ARGB32,
width,
height,
width * 4));
}
ImageSurface::~ImageSurface()
{
delete[] mData;
}

Просмотреть файл

@ -0,0 +1,47 @@
/* -*- 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 <pavlov@pavlov.net>
*
* 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 "WindowsSurface.h"
WindowsSurface::WindowsSurface(HDC dc)
{
Init(cairo_win32_surface_create(dc));
}
WindowsSurface::~WindowsSurface()
{
}