#1 2015-10-03 19:57:42

hsauro
Member
Registered: 2015-10-03
Posts: 1

Gradients drawn by GDI+ bleed out of shape

I've been trying out the synpdf libray and I noticed that if I draw a shape and fill with either vertical or horizontal gradients the gradient bleeds out the shape. On screen it looks ok, but the pdf file is not right. Oddly enough a radial gradient works fine. See screens shots below. I'm using GDI+ top do my drawing. Are there any limitations to synpdf or is there something I should be doing to fix this?

To draw the shapes, eg ellipse,  I create a path using GdipAddPathEllipse() then use FillPath with a linearGradientBursh to fill the shape.

Update 1: I should mention that for historical reasons I am using the GDI+ library from http://www.progdigy.com. Perhaps I should be using synGdiPlus? 

Update 2: Must be something I'm doing because on a small test application I get:

Screen and PDF views

Am investigating.

Update 3: The shape I am trying to draw is a round rectangle which requires me to describe it using a path. It seems that gradients, other than radial, do not confine themselves to the path in synPdf, the following code will create the image shown:

procedure TCircle.paint (canvas : TCanvas);
var path : TGPGraphicsPath;
     Graphics: TGPGraphics;
     linearBrush: TGPLinearGradientBrush;
     pen : TGPPen;
     r : TGPRectF;
begin
  graphics := TGPGraphics.Create(canvas.Handle);
  path := TGPGraphicsPath.Create;
  pen := TGPPen.Create (MakeColor(160, 10, 100));
  try
    pen.setWidth(2);
    r := makeRect(20., 20, 180, 180);
    linearBrush := TGPLinearGradientBrush.Create(r, GPColor (clWebRed), GPColor (clWebYellow), LinearGradientModeVertical);

    path.addEllipse(r);
    graphics.fillPath(linearBrush, path);
    graphics.drawPath (pen, path);
  finally
    graphics.Free;
    pen.Free;
    path.Free;
  end;
end;

Works ok on screen but produces the following in the pdf output:

PDF pf above code

Any ideas?

Screen and PDF views

Last edited by hsauro (2015-10-03 22:52:01)

Offline

Board footer

Powered by FluxBB