if (!font) return NS_OK;
metrics->SelectFont(ctx);
nsSVGCairoGlyphGeometry::GetCoveredRegion(nsISVGRendererRegion **_retval){  *_retval = nsnull;  cairo_t *ctx = cairo_create();  /* get the metrics */  nsCOMPtr<nsISVGCairoGlyphMetrics> metrics;  {    nsCOMPtr<nsISVGRendererGlyphMetrics> xpmetrics;    mSource->GetMetrics(getter_AddRefs(xpmetrics));    metrics = do_QueryInterface(xpmetrics);    NS_ASSERTION(metrics, "wrong metrics object!");    if (!metrics)      return NS_ERROR_FAILURE;  }  cairo_font_t *font = metrics->GetFont();  if (!font)    return NS_OK;  cairo_set_font(ctx, font);  GetGlobalTransform(ctx);  float x,y;  mSource->GetX(&x);  mSource->GetY(&y);  cairo_move_to(ctx, x, y);  PRUint16 type;    mSource->GetFillPaintType(&type);  PRBool hasCoveredFill = type != nsISVGGeometrySource::PAINT_TYPE_NONE;  mSource->GetStrokePaintType(&type);  bool hasCoveredStroke = type != nsISVGGeometrySource::PAINT_TYPE_NONE;  if (!hasCoveredFill && !hasCoveredStroke) return NS_OK;  nsAutoString text;  mSource->GetCharacterData(text);  cairo_text_path(ctx, (unsigned char*)NS_ConvertUCS2toUTF8(text).get());  double xmin, ymin, xmax, ymax;  if (hasCoveredStroke) {    float width;    mSource->GetStrokeWidth(&width);    cairo_set_line_width(ctx, double(width));        PRUint16 capStyle;    mSource->GetStrokeLinecap(&capStyle);    switch (capStyle) {    case nsISVGGeometrySource::STROKE_LINECAP_BUTT:      cairo_set_line_cap(ctx, CAIRO_LINE_CAP_BUTT);      break;    case nsISVGGeometrySource::STROKE_LINECAP_ROUND:      cairo_set_line_cap(ctx, CAIRO_LINE_CAP_ROUND);      break;    case nsISVGGeometrySource::STROKE_LINECAP_SQUARE:      cairo_set_line_cap(ctx, CAIRO_LINE_CAP_SQUARE);      break;    }        float miterlimit;    mSource->GetStrokeMiterlimit(&miterlimit);    cairo_set_miter_limit(ctx, double(miterlimit));        PRUint16 joinStyle;    mSource->GetStrokeLinejoin(&joinStyle);    switch(joinStyle) {    case nsISVGGeometrySource::STROKE_LINEJOIN_MITER:      cairo_set_line_join(ctx, CAIRO_LINE_JOIN_MITER);      break;    case nsISVGGeometrySource::STROKE_LINEJOIN_ROUND:      cairo_set_line_join(ctx, CAIRO_LINE_JOIN_ROUND);      break;    case nsISVGGeometrySource::STROKE_LINEJOIN_BEVEL:      cairo_set_line_join(ctx, CAIRO_LINE_JOIN_BEVEL);      break;    }        cairo_stroke_extents(ctx, &xmin, &ymin, &xmax, &ymax);  } else {    cairo_fill_extents(ctx, &xmin, &ymin, &xmax, &ymax);  }  cairo_transform_point(ctx, &xmin, &ymin);  cairo_transform_point(ctx, &xmax, &ymax);  cairo_destroy(ctx);  return NS_NewSVGCairoRectRegion(_retval, xmin, ymin, xmax-xmin, ymax-ymin);}