Bug 280454 - adjust svg cairo renderer to handle cairo > 0.3.0.

This commit is contained in:
tor%cs.brown.edu 2005-01-31 15:06:15 +00:00
parent 7bf57c30ca
commit ec0a347c63
4 changed files with 31 additions and 43 deletions

View File

@ -5653,7 +5653,7 @@ MOZ_CAIRO_CFLAGS=
MOZ_CAIRO_LIBS=
if test "$MOZ_SVG_RENDERER_CAIRO" -o "$MOZ_ENABLE_CAIRO" ; then
PKG_CHECK_MODULES(CAIRO, cairo = $CAIRO_VERSION)
PKG_CHECK_MODULES(CAIRO, cairo >= $CAIRO_VERSION)
MOZ_CAIRO_CFLAGS=$CAIRO_CFLAGS
MOZ_CAIRO_LIBS=$CAIRO_LIBS
fi

View File

@ -45,10 +45,8 @@
#include "nsISVGRendererGlyphMetrics.h"
#include <cairo.h>
// 193e2d48-3898-4bf3-b6bf-d7c00a8aba1f
#define NS_ISVGCAIROGLYPHMETRICS_IID \
{ 0x193e2d48, 0x3898, 0x4bf3, { 0xb6, 0xbf, 0xd7, 0xc0, 0x0a, 0x8a, 0xba, 0x1f } }
{ 0x6e335395, 0x5627, 0x4179, { 0x96, 0x88, 0x6a, 0xb7, 0x14, 0xd3, 0x9b, 0x83 } }
/**
* \addtogroup gdiplus_renderer Cairo Rendering Engine
@ -65,7 +63,7 @@ public:
NS_IMETHOD_(void) GetSubBoundingBox(PRUint32 charoffset, PRUint32 count, nsIDOMSVGRect * *aBoundingBox)=0;
NS_IMETHOD_(cairo_font_t*) GetFont() = 0;
NS_IMETHOD_(void) SelectFont(cairo_t *ctx) = 0;
};
/** @} */

View File

@ -171,8 +171,6 @@ nsSVGCairoGlyphGeometry::Render(nsISVGRendererCanvas *canvas)
return NS_ERROR_FAILURE;
}
cairo_font_t *font = metrics->GetFont();
PRUint16 renderMode;
cairo_matrix_t *matrix;
canvas->GetRenderMode(&renderMode);
@ -185,10 +183,10 @@ nsSVGCairoGlyphGeometry::Render(nsISVGRendererCanvas *canvas)
cairo_current_matrix(ctx, matrix);
}
cairo_set_font(ctx, font);
GetGlobalTransform(ctx);
metrics->SelectFont(ctx);
float x,y;
mSource->GetX(&x);
mSource->GetY(&y);
@ -407,14 +405,10 @@ nsSVGCairoGlyphGeometry::GetCoveredRegion(nsISVGRendererRegion **_retval)
return NS_ERROR_FAILURE;
}
cairo_font_t *font = metrics->GetFont();
if (!font)
return NS_OK;
cairo_set_font(ctx, font);
GetGlobalTransform(ctx);
metrics->SelectFont(ctx);
float x,y;
mSource->GetX(&x);
mSource->GetY(&y);
@ -508,13 +502,13 @@ nsSVGCairoGlyphGeometry::ContainsPoint(float x, float y, PRBool *_retval)
return NS_ERROR_FAILURE;
}
cairo_font_t *font = metrics->GetFont();
cairo_t *ctx = cairo_create();
cairo_set_tolerance(ctx, 1.0);
cairo_set_font(ctx, font);
GetGlobalTransform(ctx);
metrics->SelectFont(ctx);
nsAutoString text;
mSource->GetCharacterData(text);
cairo_text_path(ctx, (unsigned char*)NS_ConvertUCS2toUTF8(text).get());

View File

@ -82,11 +82,10 @@ public:
NS_IMETHOD_(void) GetSubBoundingBox(PRUint32 charoffset, PRUint32 count,
nsIDOMSVGRect * *aBoundingBox);
NS_IMETHOD_(cairo_font_t*)GetFont() { return mFont; }
NS_IMETHOD_(void) SelectFont(cairo_t *ctx);
private:
cairo_t *mCT;
cairo_font_t *mFont;
cairo_text_extents_t mExtents;
nsCOMPtr<nsISVGGlyphMetricsSource> mSource;
};
@ -97,14 +96,13 @@ private:
// implementation:
nsSVGCairoGlyphMetrics::nsSVGCairoGlyphMetrics(nsISVGGlyphMetricsSource *src)
: mFont(NULL), mSource(src)
: mSource(src)
{
mCT = cairo_create();
}
nsSVGCairoGlyphMetrics::~nsSVGCairoGlyphMetrics()
{
// don't delete mFont because the cairo_destroy takes it down
cairo_destroy(mCT);
}
@ -254,7 +252,7 @@ nsSVGCairoGlyphMetrics::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retva
mSource->GetCharacterData(text);
glyph.index = text[charnum];
cairo_set_font(mCT, mFont);
SelectFont(mCT);
cairo_glyph_extents(mCT, &glyph, 1, &extent);
nsCOMPtr<nsIDOMSVGRect> rect = do_CreateInstance(NS_SVGRECT_CONTRACTID);
@ -284,14 +282,23 @@ nsSVGCairoGlyphMetrics::Update(PRUint32 updatemask, PRBool *_retval)
}
if (updatemask & nsISVGGlyphMetricsSource::UPDATEMASK_FONT) {
if (mFont) {
// don't delete mFont because we're just pointing at the ctx copy
mFont = NULL;
}
*_retval = PR_TRUE;
}
if (!mFont) {
SelectFont(mCT);
nsAutoString text;
mSource->GetCharacterData(text);
cairo_text_extents(mCT,
(unsigned char*)NS_ConvertUCS2toUTF8(text).get(),
&mExtents);
return NS_OK;
}
NS_IMETHODIMP_(void)
nsSVGCairoGlyphMetrics::SelectFont(cairo_t *ctx)
{
nsFont font;
mSource->GetFont(&font);
@ -320,23 +327,12 @@ nsSVGCairoGlyphMetrics::Update(PRUint32 updatemask, PRBool *_retval)
nsString family;
font.GetFirstFamily(family);
char *f = ToNewCString(family);
cairo_select_font(mCT, f, slant, weight);
free(f);
cairo_select_font(ctx, f, slant, weight);
nsMemory::Free(f);
nsCOMPtr<nsPresContext> presContext;
mSource->GetPresContext(getter_AddRefs(presContext));
float pxPerTwips;
pxPerTwips = presContext->TwipsToPixels();
cairo_scale_font(mCT, font.size*pxPerTwips);
mFont = cairo_current_font(mCT);
nsAutoString text;
mSource->GetCharacterData(text);
cairo_text_extents(mCT,
(unsigned char*)NS_ConvertUCS2toUTF8(text).get(),
&mExtents);
}
return NS_OK;
cairo_scale_font(ctx, font.size*pxPerTwips);
}