2012-05-30 08:42:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-01-27 04:26:49 +03:00
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "gfxPattern.h"
|
|
|
|
#include "gfxASurface.h"
|
2007-11-09 21:14:59 +03:00
|
|
|
#include "gfxPlatform.h"
|
2007-01-27 04:26:49 +03:00
|
|
|
|
|
|
|
#include "cairo.h"
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern::gfxPattern(cairo_pattern_t *aPattern)
|
2012-01-05 11:17:51 +04:00
|
|
|
: mGfxPattern(NULL)
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
|
|
|
mPattern = cairo_pattern_reference(aPattern);
|
|
|
|
}
|
|
|
|
|
2007-02-08 23:47:48 +03:00
|
|
|
gfxPattern::gfxPattern(const gfxRGBA& aColor)
|
2012-01-05 11:17:51 +04:00
|
|
|
: mGfxPattern(NULL)
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
|
|
|
mPattern = cairo_pattern_create_rgba(aColor.r, aColor.g, aColor.b, aColor.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
// from another surface
|
|
|
|
gfxPattern::gfxPattern(gfxASurface *surface)
|
2012-01-05 11:17:51 +04:00
|
|
|
: mGfxPattern(NULL)
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
|
|
|
mPattern = cairo_pattern_create_for_surface(surface->CairoSurface());
|
|
|
|
}
|
|
|
|
|
|
|
|
// linear
|
|
|
|
gfxPattern::gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1)
|
2012-01-05 11:17:51 +04:00
|
|
|
: mGfxPattern(NULL)
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
|
|
|
mPattern = cairo_pattern_create_linear(x0, y0, x1, y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// radial
|
|
|
|
gfxPattern::gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
|
|
|
|
gfxFloat cx1, gfxFloat cy1, gfxFloat radius1)
|
2012-01-05 11:17:51 +04:00
|
|
|
: mGfxPattern(NULL)
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
|
|
|
mPattern = cairo_pattern_create_radial(cx0, cy0, radius0,
|
|
|
|
cx1, cy1, radius1);
|
|
|
|
}
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
// Azure
|
|
|
|
gfxPattern::gfxPattern(SourceSurface *aSurface, const Matrix &aTransform)
|
|
|
|
: mPattern(NULL)
|
|
|
|
, mGfxPattern(NULL)
|
|
|
|
, mSourceSurface(aSurface)
|
|
|
|
, mTransform(aTransform)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern::~gfxPattern()
|
|
|
|
{
|
|
|
|
cairo_pattern_destroy(mPattern);
|
2012-01-05 11:17:51 +04:00
|
|
|
|
|
|
|
if (mGfxPattern) {
|
|
|
|
mGfxPattern->~Pattern();
|
|
|
|
}
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_pattern_t *
|
|
|
|
gfxPattern::CairoPattern()
|
|
|
|
{
|
|
|
|
return mPattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPattern::AddColorStop(gfxFloat offset, const gfxRGBA& c)
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
|
|
|
mStops = NULL;
|
2008-08-12 08:55:36 +04:00
|
|
|
if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
|
2008-09-11 06:21:03 +04:00
|
|
|
gfxRGBA cms;
|
|
|
|
gfxPlatform::TransformPixel(c, cms, gfxPlatform::GetCMSRGBTransform());
|
|
|
|
|
|
|
|
// Use the original alpha to avoid unnecessary float->byte->float
|
|
|
|
// conversion errors
|
|
|
|
cairo_pattern_add_color_stop_rgba(mPattern, offset,
|
|
|
|
cms.r, cms.g, cms.b, c.a);
|
2007-11-09 21:14:59 +03:00
|
|
|
}
|
2008-09-11 06:21:03 +04:00
|
|
|
else
|
|
|
|
cairo_pattern_add_color_stop_rgba(mPattern, offset, c.r, c.g, c.b, c.a);
|
2012-01-05 11:17:51 +04:00
|
|
|
}
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPattern::SetMatrix(const gfxMatrix& matrix)
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2007-01-27 04:26:49 +03:00
|
|
|
cairo_matrix_t mat = *reinterpret_cast<const cairo_matrix_t*>(&matrix);
|
|
|
|
cairo_pattern_set_matrix(mPattern, &mat);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
mTransform = ToMatrix(matrix);
|
2012-04-23 21:30:46 +04:00
|
|
|
// Cairo-pattern matrices specify the conversion from DrawTarget to pattern
|
|
|
|
// space. Azure pattern matrices specify the conversion from pattern to
|
|
|
|
// DrawTarget space.
|
|
|
|
mTransform.Invert();
|
2012-01-05 11:17:51 +04:00
|
|
|
}
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix
|
2007-03-03 03:18:34 +03:00
|
|
|
gfxPattern::GetMatrix() const
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2007-01-27 04:26:49 +03:00
|
|
|
cairo_matrix_t mat;
|
|
|
|
cairo_pattern_get_matrix(mPattern, &mat);
|
|
|
|
return gfxMatrix(*reinterpret_cast<gfxMatrix*>(&mat));
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
return ThebesMatrix(mTransform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pattern*
|
2012-03-29 22:53:43 +04:00
|
|
|
gfxPattern::GetPattern(DrawTarget *aTarget, Matrix *aPatternTransform)
|
2012-01-05 11:17:51 +04:00
|
|
|
{
|
2012-05-30 08:42:41 +04:00
|
|
|
if (mGfxPattern) {
|
|
|
|
mGfxPattern->~Pattern();
|
2012-07-30 18:20:58 +04:00
|
|
|
mGfxPattern = nullptr;
|
2012-05-30 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
if (!mPattern) {
|
|
|
|
mGfxPattern = new (mSurfacePattern.addr())
|
|
|
|
SurfacePattern(mSourceSurface, EXTEND_CLAMP, mTransform);
|
|
|
|
return mGfxPattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsExtend extend = (GraphicsExtend)cairo_pattern_get_extend(mPattern);
|
|
|
|
|
|
|
|
switch (cairo_pattern_get_type(mPattern)) {
|
2012-03-29 22:53:43 +04:00
|
|
|
case CAIRO_PATTERN_TYPE_SOLID:
|
|
|
|
{
|
|
|
|
double r, g, b, a;
|
|
|
|
cairo_pattern_get_rgba(mPattern, &r, &g, &b, &a);
|
|
|
|
|
|
|
|
new (mColorPattern.addr()) ColorPattern(Color(r, g, b, a));
|
|
|
|
return mColorPattern.addr();
|
|
|
|
}
|
2012-01-05 11:17:51 +04:00
|
|
|
case CAIRO_PATTERN_TYPE_SURFACE:
|
|
|
|
{
|
|
|
|
GraphicsFilter filter = (GraphicsFilter)cairo_pattern_get_filter(mPattern);
|
|
|
|
cairo_matrix_t mat;
|
|
|
|
cairo_pattern_get_matrix(mPattern, &mat);
|
|
|
|
gfxMatrix matrix(*reinterpret_cast<gfxMatrix*>(&mat));
|
|
|
|
|
|
|
|
cairo_surface_t *surf = NULL;
|
|
|
|
cairo_pattern_get_surface(mPattern, &surf);
|
|
|
|
|
|
|
|
if (!mSourceSurface) {
|
|
|
|
nsRefPtr<gfxASurface> gfxSurf = gfxASurface::Wrap(surf);
|
2012-05-21 19:27:32 +04:00
|
|
|
// The underlying surface here will be kept around by the gfxPattern.
|
|
|
|
// This function is intended to be used right away.
|
2012-01-05 11:17:51 +04:00
|
|
|
mSourceSurface =
|
|
|
|
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(aTarget, gfxSurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSourceSurface) {
|
|
|
|
Matrix newMat = ToMatrix(matrix);
|
2012-03-29 22:53:43 +04:00
|
|
|
|
|
|
|
AdjustTransformForPattern(newMat, aTarget->GetTransform(), aPatternTransform);
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
double x, y;
|
|
|
|
cairo_surface_get_device_offset(surf, &x, &y);
|
|
|
|
newMat.Translate(-x, -y);
|
|
|
|
mGfxPattern = new (mSurfacePattern.addr())
|
|
|
|
SurfacePattern(mSourceSurface, ToExtendMode(extend), newMat, ToFilter(filter));
|
|
|
|
return mGfxPattern;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CAIRO_PATTERN_TYPE_LINEAR:
|
|
|
|
{
|
|
|
|
double x1, y1, x2, y2;
|
|
|
|
cairo_pattern_get_linear_points(mPattern, &x1, &y1, &x2, &y2);
|
|
|
|
if (!mStops) {
|
|
|
|
int count = 0;
|
|
|
|
cairo_pattern_get_color_stop_count(mPattern, &count);
|
|
|
|
|
|
|
|
std::vector<GradientStop> stops;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
GradientStop stop;
|
|
|
|
double r, g, b, a, offset;
|
|
|
|
cairo_pattern_get_color_stop_rgba(mPattern, i, &offset, &r, &g, &b, &a);
|
|
|
|
|
|
|
|
stop.offset = offset;
|
|
|
|
stop.color = Color(Float(r), Float(g), Float(b), Float(a));
|
|
|
|
stops.push_back(stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
mStops = aTarget->CreateGradientStops(&stops.front(), count, ToExtendMode(extend));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStops) {
|
|
|
|
cairo_matrix_t mat;
|
|
|
|
cairo_pattern_get_matrix(mPattern, &mat);
|
|
|
|
gfxMatrix matrix(*reinterpret_cast<gfxMatrix*>(&mat));
|
|
|
|
|
|
|
|
Matrix newMat = ToMatrix(matrix);
|
2012-03-29 22:53:43 +04:00
|
|
|
|
|
|
|
AdjustTransformForPattern(newMat, aTarget->GetTransform(), aPatternTransform);
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
mGfxPattern = new (mLinearGradientPattern.addr())
|
|
|
|
LinearGradientPattern(Point(x1, y1), Point(x2, y2), mStops, newMat);
|
|
|
|
|
|
|
|
return mGfxPattern;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CAIRO_PATTERN_TYPE_RADIAL:
|
|
|
|
{
|
|
|
|
if (!mStops) {
|
|
|
|
int count = 0;
|
|
|
|
cairo_pattern_get_color_stop_count(mPattern, &count);
|
|
|
|
|
|
|
|
std::vector<GradientStop> stops;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
GradientStop stop;
|
|
|
|
double r, g, b, a, offset;
|
|
|
|
cairo_pattern_get_color_stop_rgba(mPattern, i, &offset, &r, &g, &b, &a);
|
|
|
|
|
|
|
|
stop.offset = offset;
|
|
|
|
stop.color = Color(Float(r), Float(g), Float(b), Float(a));
|
|
|
|
stops.push_back(stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
mStops = aTarget->CreateGradientStops(&stops.front(), count, ToExtendMode(extend));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStops) {
|
|
|
|
cairo_matrix_t mat;
|
|
|
|
cairo_pattern_get_matrix(mPattern, &mat);
|
|
|
|
gfxMatrix matrix(*reinterpret_cast<gfxMatrix*>(&mat));
|
|
|
|
|
|
|
|
Matrix newMat = ToMatrix(matrix);
|
2012-03-29 22:53:43 +04:00
|
|
|
|
|
|
|
AdjustTransformForPattern(newMat, aTarget->GetTransform(), aPatternTransform);
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
double x1, y1, x2, y2, r1, r2;
|
|
|
|
cairo_pattern_get_radial_circles(mPattern, &x1, &y1, &r1, &x2, &y2, &r2);
|
|
|
|
mGfxPattern = new (mRadialGradientPattern.addr())
|
|
|
|
RadialGradientPattern(Point(x1, y1), Point(x2, y2), r1, r2, mStops, newMat);
|
|
|
|
|
|
|
|
return mGfxPattern;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-02-04 16:22:47 +04:00
|
|
|
default:
|
|
|
|
/* Reassure the compiler we are handling all the enum values. */
|
|
|
|
break;
|
2012-01-05 11:17:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
new (mColorPattern.addr()) ColorPattern(Color(0, 0, 0, 0));
|
|
|
|
return mColorPattern.addr();
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPattern::SetExtend(GraphicsExtend extend)
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
|
|
|
mStops = NULL;
|
2008-09-25 23:49:55 +04:00
|
|
|
if (extend == EXTEND_PAD_EDGE) {
|
|
|
|
if (cairo_pattern_get_type(mPattern) == CAIRO_PATTERN_TYPE_SURFACE) {
|
|
|
|
cairo_surface_t *surf = NULL;
|
|
|
|
|
|
|
|
cairo_pattern_get_surface (mPattern, &surf);
|
|
|
|
if (surf) {
|
|
|
|
switch (cairo_surface_get_type(surf)) {
|
|
|
|
case CAIRO_SURFACE_TYPE_WIN32_PRINTING:
|
|
|
|
case CAIRO_SURFACE_TYPE_QUARTZ:
|
|
|
|
extend = EXTEND_NONE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAIRO_SURFACE_TYPE_WIN32:
|
2008-09-26 02:25:00 +04:00
|
|
|
case CAIRO_SURFACE_TYPE_XLIB:
|
2008-09-25 23:49:55 +04:00
|
|
|
default:
|
|
|
|
extend = EXTEND_PAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if something went wrong, or not a surface pattern, use PAD
|
|
|
|
if (extend == EXTEND_PAD_EDGE)
|
|
|
|
extend = EXTEND_PAD;
|
|
|
|
}
|
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
cairo_pattern_set_extend(mPattern, (cairo_extend_t)extend);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
// This is always a surface pattern and will default to EXTEND_PAD
|
|
|
|
// for EXTEND_PAD_EDGE.
|
|
|
|
mExtend = ToExtendMode(extend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
gfxPattern::IsOpaque()
|
|
|
|
{
|
|
|
|
if (mPattern) {
|
|
|
|
switch (cairo_pattern_get_type(mPattern)) {
|
|
|
|
case CAIRO_PATTERN_TYPE_SURFACE:
|
|
|
|
{
|
|
|
|
cairo_surface_t *surf = NULL;
|
|
|
|
cairo_pattern_get_surface(mPattern, &surf);
|
|
|
|
|
|
|
|
if (cairo_surface_get_content(surf) == CAIRO_CONTENT_COLOR) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-04 16:22:47 +04:00
|
|
|
default:
|
|
|
|
return false;
|
2012-01-05 11:17:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSourceSurface->GetFormat() == FORMAT_B8G8R8X8) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPattern::GraphicsExtend
|
|
|
|
gfxPattern::Extend() const
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2007-01-27 04:26:49 +03:00
|
|
|
return (GraphicsExtend)cairo_pattern_get_extend(mPattern);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
return ThebesExtend(mExtend);
|
|
|
|
}
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-21 18:36:38 +03:00
|
|
|
gfxPattern::SetFilter(GraphicsFilter filter)
|
2007-01-27 04:26:49 +03:00
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2007-01-27 04:26:49 +03:00
|
|
|
cairo_pattern_set_filter(mPattern, (cairo_filter_t)filter);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
mFilter = ToFilter(filter);
|
|
|
|
}
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
2009-03-21 18:36:38 +03:00
|
|
|
gfxPattern::GraphicsFilter
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern::Filter() const
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2009-03-21 18:36:38 +03:00
|
|
|
return (GraphicsFilter)cairo_pattern_get_filter(mPattern);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
return ThebesFilter(mFilter);
|
|
|
|
}
|
2007-01-27 04:26:49 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern::GetSolidColor(gfxRGBA& aColor)
|
|
|
|
{
|
|
|
|
return cairo_pattern_get_rgba(mPattern,
|
|
|
|
&aColor.r,
|
|
|
|
&aColor.g,
|
|
|
|
&aColor.b,
|
|
|
|
&aColor.a) == CAIRO_STATUS_SUCCESS;
|
|
|
|
}
|
2007-03-03 03:18:34 +03:00
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPattern::GetSurface()
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2012-07-30 18:20:58 +04:00
|
|
|
cairo_surface_t *surf = nullptr;
|
2007-03-03 03:18:34 +03:00
|
|
|
|
|
|
|
if (cairo_pattern_get_surface (mPattern, &surf) != CAIRO_STATUS_SUCCESS)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-03-03 03:18:34 +03:00
|
|
|
|
|
|
|
return gfxASurface::Wrap(surf);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
// We should never be trying to get the surface off an Azure gfx Pattern.
|
|
|
|
NS_ERROR("Attempt to get surface off an Azure gfxPattern!");
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-03-03 03:18:34 +03:00
|
|
|
}
|
2008-03-06 09:51:13 +03:00
|
|
|
|
|
|
|
gfxPattern::GraphicsPatternType
|
|
|
|
gfxPattern::GetType() const
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2008-03-06 09:51:13 +03:00
|
|
|
return (GraphicsPatternType) cairo_pattern_get_type(mPattern);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
// We should never be trying to get the type off an Azure gfx Pattern.
|
|
|
|
MOZ_ASSERT(0);
|
|
|
|
return PATTERN_SURFACE;
|
|
|
|
}
|
2008-03-06 09:51:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gfxPattern::CairoStatus()
|
|
|
|
{
|
2012-01-05 11:17:51 +04:00
|
|
|
if (mPattern) {
|
2008-03-06 09:51:13 +03:00
|
|
|
return cairo_pattern_status(mPattern);
|
2012-01-05 11:17:51 +04:00
|
|
|
} else {
|
|
|
|
// An Azure pattern as this point is never in error status.
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
}
|
2008-03-06 09:51:13 +03:00
|
|
|
}
|
2012-03-29 22:53:43 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxPattern::AdjustTransformForPattern(Matrix &aPatternTransform,
|
|
|
|
const Matrix &aCurrentTransform,
|
|
|
|
const Matrix *aOriginalTransform)
|
|
|
|
{
|
2012-06-14 02:40:43 +04:00
|
|
|
aPatternTransform.Invert();
|
2012-03-29 22:53:43 +04:00
|
|
|
if (!aOriginalTransform) {
|
2012-09-12 09:13:12 +04:00
|
|
|
// User space is unchanged, so to get from pattern space to user space,
|
|
|
|
// just invert the cairo matrix.
|
2012-09-07 16:32:21 +04:00
|
|
|
aPatternTransform.NudgeToIntegers();
|
2012-03-29 22:53:43 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-09-12 09:13:12 +04:00
|
|
|
// aPatternTransform now maps from pattern space to the user space defined
|
|
|
|
// by *aOriginalTransform.
|
2012-03-29 22:53:43 +04:00
|
|
|
|
2012-06-14 02:40:43 +04:00
|
|
|
Matrix mat = aCurrentTransform;
|
2012-03-29 22:53:43 +04:00
|
|
|
mat.Invert();
|
2012-09-12 09:13:12 +04:00
|
|
|
// mat maps from device space to current user space
|
2012-03-29 22:53:43 +04:00
|
|
|
|
2012-09-12 09:13:12 +04:00
|
|
|
// First, transform from pattern space to original user space. Then transform
|
|
|
|
// from original user space to device space. Then transform from
|
|
|
|
// device space to current user space.
|
2012-06-14 02:40:43 +04:00
|
|
|
aPatternTransform = aPatternTransform * *aOriginalTransform * mat;
|
2012-09-07 16:32:21 +04:00
|
|
|
aPatternTransform.NudgeToIntegers();
|
2012-03-29 22:53:43 +04:00
|
|
|
}
|