Lines 83-93
Link Here
|
83 |
NS_IMETHOD_(void) GetSubBoundingBox(PRUint32 charoffset, PRUint32 count, |
83 |
NS_IMETHOD_(void) GetSubBoundingBox(PRUint32 charoffset, PRUint32 count, |
84 |
nsIDOMSVGRect * *aBoundingBox); |
84 |
nsIDOMSVGRect * *aBoundingBox); |
85 |
|
85 |
|
86 |
NS_IMETHOD_(cairo_font_t*)GetFont() { return mFont; } |
86 |
NS_IMETHOD_(void) SelectFont(cairo_t *ctx); |
87 |
|
87 |
|
88 |
private: |
88 |
private: |
89 |
cairo_t *mCT; |
89 |
cairo_t *mCT; |
90 |
cairo_font_t *mFont; |
|
|
91 |
cairo_text_extents_t mExtents; |
90 |
cairo_text_extents_t mExtents; |
92 |
nsCOMPtr<nsISVGGlyphMetricsSource> mSource; |
91 |
nsCOMPtr<nsISVGGlyphMetricsSource> mSource; |
93 |
}; |
92 |
}; |
Lines 98-106
Link Here
|
98 |
// implementation: |
97 |
// implementation: |
99 |
|
98 |
|
100 |
nsSVGCairoGlyphMetrics::nsSVGCairoGlyphMetrics(nsISVGGlyphMetricsSource *src) |
99 |
nsSVGCairoGlyphMetrics::nsSVGCairoGlyphMetrics(nsISVGGlyphMetricsSource *src) |
101 |
: mFont(NULL), mSource(src) |
100 |
: mSource(src) |
102 |
{ |
101 |
{ |
103 |
mCT = cairo_create(); |
102 |
mCT = cairo_create(0); |
104 |
} |
103 |
} |
105 |
|
104 |
|
106 |
nsSVGCairoGlyphMetrics::~nsSVGCairoGlyphMetrics() |
105 |
nsSVGCairoGlyphMetrics::~nsSVGCairoGlyphMetrics() |
Lines 203-211
Link Here
|
203 |
nsAutoString text; |
202 |
nsAutoString text; |
204 |
mSource->GetCharacterData(text); |
203 |
mSource->GetCharacterData(text); |
205 |
cairo_text_extents(mCT, |
204 |
cairo_text_extents(mCT, |
206 |
(unsigned char *)NS_ConvertUCS2toUTF8(Substring(text, |
205 |
NS_ConvertUCS2toUTF8(Substring(text, |
207 |
charoffset, |
206 |
charoffset, |
208 |
count)).get(), |
207 |
count)).get(), |
209 |
&extents); |
208 |
&extents); |
210 |
|
209 |
|
211 |
|
210 |
|
Lines 255-261
Link Here
|
255 |
mSource->GetCharacterData(text); |
254 |
mSource->GetCharacterData(text); |
256 |
glyph.index = text[charnum]; |
255 |
glyph.index = text[charnum]; |
257 |
|
256 |
|
258 |
cairo_set_font(mCT, mFont); |
257 |
SelectFont(mCT); |
259 |
cairo_glyph_extents(mCT, &glyph, 1, &extent); |
258 |
cairo_glyph_extents(mCT, &glyph, 1, &extent); |
260 |
|
259 |
|
261 |
nsCOMPtr<nsIDOMSVGRect> rect = do_CreateInstance(NS_SVGRECT_CONTRACTID); |
260 |
nsCOMPtr<nsIDOMSVGRect> rect = do_CreateInstance(NS_SVGRECT_CONTRACTID); |
Lines 285-298
Link Here
|
285 |
} |
284 |
} |
286 |
|
285 |
|
287 |
if (updatemask & nsISVGGlyphMetricsSource::UPDATEMASK_FONT) { |
286 |
if (updatemask & nsISVGGlyphMetricsSource::UPDATEMASK_FONT) { |
288 |
if (mFont) { |
|
|
289 |
// don't delete mFont because we're just pointing at the ctx copy |
290 |
mFont = NULL; |
291 |
} |
292 |
*_retval = PR_TRUE; |
287 |
*_retval = PR_TRUE; |
293 |
} |
288 |
} |
294 |
|
289 |
|
295 |
if (!mFont) { |
290 |
SelectFont(mCT); |
|
|
291 |
|
292 |
nsAutoString text; |
293 |
mSource->GetCharacterData(text); |
294 |
cairo_text_extents(mCT, |
295 |
NS_ConvertUCS2toUTF8(text).get(), |
296 |
&mExtents); |
297 |
|
298 |
return NS_OK; |
299 |
} |
300 |
|
301 |
NS_IMETHODIMP_(void) |
302 |
nsSVGCairoGlyphMetrics::SelectFont(cairo_t *ctx) |
303 |
{ |
296 |
nsFont font; |
304 |
nsFont font; |
297 |
mSource->GetFont(&font); |
305 |
mSource->GetFont(&font); |
298 |
|
306 |
|
Lines 313-319
Link Here
|
313 |
|
321 |
|
314 |
if (font.weight % 100 == 0) { |
322 |
if (font.weight % 100 == 0) { |
315 |
if (font.weight >= 600) |
323 |
if (font.weight >= 600) |
316 |
weight = CAIRO_FONT_WEIGHT_BOLD; |
324 |
weight = CAIRO_FONT_WEIGHT_BOLD; |
317 |
} else if (font.weight % 100 < 50) { |
325 |
} else if (font.weight % 100 < 50) { |
318 |
weight = CAIRO_FONT_WEIGHT_BOLD; |
326 |
weight = CAIRO_FONT_WEIGHT_BOLD; |
319 |
} |
327 |
} |
Lines 321-342
Link Here
|
321 |
nsString family; |
329 |
nsString family; |
322 |
font.GetFirstFamily(family); |
330 |
font.GetFirstFamily(family); |
323 |
char *f = ToNewCString(family); |
331 |
char *f = ToNewCString(family); |
324 |
cairo_select_font(mCT, f, slant, weight); |
332 |
cairo_select_font_face(ctx, f, slant, weight); |
325 |
free(f); |
333 |
nsMemory::Free(f); |
326 |
mFont = cairo_current_font(mCT); |
|
|
327 |
|
334 |
|
328 |
nsCOMPtr<nsIPresContext> presContext; |
335 |
nsCOMPtr<nsIPresContext> presContext; |
329 |
mSource->GetPresContext(getter_AddRefs(presContext)); |
336 |
mSource->GetPresContext(getter_AddRefs(presContext)); |
330 |
float pxPerTwips; |
337 |
float pxPerTwips; |
331 |
pxPerTwips = presContext->TwipsToPixels(); |
338 |
pxPerTwips = presContext->TwipsToPixels(); |
332 |
cairo_scale_font(mCT, font.size*pxPerTwips); |
339 |
cairo_set_font_size(ctx, font.size*pxPerTwips); |
333 |
|
|
|
334 |
nsAutoString text; |
335 |
mSource->GetCharacterData(text); |
336 |
cairo_text_extents(mCT, |
337 |
(unsigned char*)NS_ConvertUCS2toUTF8(text).get(), |
338 |
&mExtents); |
339 |
} |
340 |
|
341 |
return NS_OK; |
342 |
} |
340 |
} |