cairo_set_source(ctx, gradient); cairo_fill_preserve(ctx); cairo_pattern_destroy(gradient);
if (gradient) { cairo_set_source(ctx, gradient); cairo_fill_preserve(ctx); cairo_pattern_destroy(gradient); }
nsSVGCairoPathGeometry::Render(nsISVGRendererCanvas *canvas){  nsCOMPtr<nsISVGCairoCanvas> cairoCanvas = do_QueryInterface(canvas);  NS_ASSERTION(cairoCanvas, "wrong svg render context for geometry!");  if (!cairoCanvas) return NS_ERROR_FAILURE;  cairo_t *ctx = cairoCanvas->GetContext();  PRUint16 renderMode;  canvas->GetRenderMode(&renderMode);  cairo_matrix_t matrix;  if (renderMode == nsISVGRendererCanvas::SVG_RENDER_MODE_NORMAL) {    cairo_new_path(ctx);    /* save/pop the state so we don't screw up the xform */    cairo_save(ctx);  } else {    cairo_get_matrix(ctx, &matrix);  }  GeneratePath(ctx, cairoCanvas);  if (renderMode != nsISVGRendererCanvas::SVG_RENDER_MODE_NORMAL) {    PRUint16 rule;    mSource->GetClipRule(&rule);    if (rule == nsISVGGeometrySource::FILL_RULE_EVENODD)      cairo_set_fill_rule(ctx, CAIRO_FILL_RULE_EVEN_ODD);    else      cairo_set_fill_rule(ctx, CAIRO_FILL_RULE_WINDING);    cairo_set_matrix(ctx, &matrix);    return NS_OK;  }  PRUint16 shapeMode;  mSource->GetShapeRendering(&shapeMode);  switch (shapeMode) {  case nsISVGPathGeometrySource::SHAPE_RENDERING_OPTIMIZESPEED:  case nsISVGPathGeometrySource::SHAPE_RENDERING_CRISPEDGES:    cairo_set_antialias(ctx, CAIRO_ANTIALIAS_NONE);    break;  default:    cairo_set_antialias(ctx, CAIRO_ANTIALIAS_DEFAULT);    break;  }  PRUint16 strokeType, fillType;  PRUint16 strokeServerType = 0;  PRBool bStroking = PR_FALSE;  mSource->GetStrokePaintType(&strokeType);  if (strokeType != nsISVGGeometrySource::PAINT_TYPE_NONE) {    bStroking = PR_TRUE;    if (strokeType == nsISVGGeometrySource::PAINT_TYPE_SERVER) {      if (NS_FAILED(mSource->GetStrokePaintServerType(&strokeServerType)))        // unknown type or missing frame        bStroking = PR_FALSE;    }  }  mSource->GetFillPaintType(&fillType);  PRUint16 fillServerType = 0;  if (fillType == nsISVGGeometrySource::PAINT_TYPE_SERVER) {    if (NS_FAILED(mSource->GetFillPaintServerType(&fillServerType)))      // unknown type or missing frame      fillType = nsISVGGeometrySource::PAINT_TYPE_NONE;  }  if (fillType != nsISVGGeometrySource::PAINT_TYPE_NONE) {    nscolor rgb;    mSource->GetFillPaint(&rgb);    float opacity;    mSource->GetFillOpacity(&opacity);    cairo_set_source_rgba(ctx,                          NS_GET_R(rgb)/255.0,                          NS_GET_G(rgb)/255.0,                          NS_GET_B(rgb)/255.0,                          opacity);    if (fillType == nsISVGGeometrySource::PAINT_TYPE_SOLID_COLOR) {      cairo_fill_preserve(ctx);    } else if (fillType == nsISVGGeometrySource::PAINT_TYPE_SERVER) {      if (fillServerType == nsISVGGeometrySource::PAINT_TYPE_GRADIENT) {        nsCOMPtr<nsISVGGradient> aGrad;        mSource->GetFillGradient(getter_AddRefs(aGrad));        cairo_pattern_t *gradient = CairoGradient(ctx, aGrad, mSource);        cairo_set_source(ctx, gradient);        cairo_fill_preserve(ctx);        cairo_pattern_destroy(gradient);      } else if (fillServerType == nsISVGGeometrySource::PAINT_TYPE_PATTERN) {        nsCOMPtr<nsISVGPattern> aPat;        mSource->GetFillPattern(getter_AddRefs(aPat));        // Paint the pattern -- note that because we will call back into the        // layout layer to paint, we need to pass the canvas, not just the context        cairo_pattern_t *pattern = CairoPattern(canvas, aPat, mSource);        if (pattern) {          cairo_set_source(ctx, pattern);          cairo_fill_preserve(ctx);          cairo_pattern_destroy(pattern);        }      } else {        cairo_fill_preserve(ctx);      }    }    if (!bStroking)      cairo_new_path(ctx);  }  if (bStroking) {    nscolor rgb;    mSource->GetStrokePaint(&rgb);    float opacity;    mSource->GetStrokeOpacity(&opacity);    cairo_set_source_rgba(ctx,                          NS_GET_R(rgb)/255.0,                          NS_GET_G(rgb)/255.0,                          NS_GET_B(rgb)/255.0,                          opacity);    if (strokeType == nsISVGGeometrySource::PAINT_TYPE_SOLID_COLOR) {      cairo_stroke(ctx);    } else if (strokeType == nsISVGGeometrySource::PAINT_TYPE_SERVER) {      if (strokeServerType == nsISVGGeometrySource::PAINT_TYPE_GRADIENT) {        nsCOMPtr<nsISVGGradient> aGrad;        mSource->GetStrokeGradient(getter_AddRefs(aGrad));        cairo_pattern_t *gradient = CairoGradient(ctx, aGrad, mSource);        cairo_set_source(ctx, gradient);        cairo_stroke(ctx);        cairo_pattern_destroy(gradient);      } else if (strokeServerType == nsISVGGeometrySource::PAINT_TYPE_PATTERN) {        nsCOMPtr<nsISVGPattern> aPat;        mSource->GetStrokePattern(getter_AddRefs(aPat));        // Paint the pattern -- note that because we will call back into the        // layout layer to paint, we need to pass the canvas, not just the context        cairo_pattern_t *pattern = CairoPattern(canvas, aPat, mSource);        if (pattern) {          cairo_set_source(ctx, pattern);          cairo_stroke(ctx);          cairo_pattern_destroy(pattern);        }      } else {        cairo_stroke(ctx);      }    }  }  cairo_restore(ctx);  return NS_OK;}