TAChart: Invert Y axis when drawing to fpvectorial back-end

git-svn-id: trunk@31253 -
This commit is contained in:
ask 2011-06-16 12:19:58 +00:00
parent d449d6153b
commit 96e208066b
2 changed files with 38 additions and 20 deletions

View File

@ -48,10 +48,10 @@ begin
d := TvVectorialDocument.Create; d := TvVectorialDocument.Create;
d.Width := AChart.Width; d.Width := AChart.Width;
d.Height := AChart.Height; d.Height := AChart.Height;
v := TFPVectorialDrawer.Create(d); v := TFPVectorialDrawer.Create(d, 0, AChart.Height);
v.DoChartColorToFPColor := @ChartColorSysToFPColor; v.DoChartColorToFPColor := @ChartColorSysToFPColor;
with AChart do with AChart do
Draw(v, Rect(0, 0, Width, Height)); Draw(v, Rect(0, 10, Width, Height));
d.WriteToFile('test.' + ext[AFormat], AFormat); d.WriteToFile('test.' + ext[AFormat], AFormat);
end; end;

View File

@ -28,11 +28,16 @@ type
TFPVectorialDrawer = class(TBasicDrawer, IChartDrawer) TFPVectorialDrawer = class(TBasicDrawer, IChartDrawer)
strict private strict private
FBottom: Integer;
FBrushColor: TFPColor; FBrushColor: TFPColor;
FBrushStyle: TFPBrushStyle; FBrushStyle: TFPBrushStyle;
FCanvas: TvVectorialDocument; FCanvas: TvVectorialDocument;
FFontSize: Integer; FFontSize: Integer;
FPenColor: TFPColor; FPenColor: TFPColor;
FTop: Integer;
procedure AddLine(AX, AY: Integer);
function InvertY(AY: Integer): Integer; inline;
strict protected strict protected
function GetFontAngle: Double; override; function GetFontAngle: Double; override;
procedure SetBrush(ABrush: TFPCustomBrush); procedure SetBrush(ABrush: TFPCustomBrush);
@ -41,7 +46,7 @@ type
function SimpleTextExtent(const AText: String): TPoint; override; function SimpleTextExtent(const AText: String): TPoint; override;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override; procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
public public
constructor Create(ACanvas: TvVectorialDocument); constructor Create(ACanvas: TvVectorialDocument; ATop, ABottom: Integer);
public public
procedure AddToFontOrientation(ADelta: Integer); procedure AddToFontOrientation(ADelta: Integer);
procedure ClippingStart; procedure ClippingStart;
@ -76,9 +81,14 @@ uses
{ TFPVectorialDrawer } { TFPVectorialDrawer }
procedure TFPVectorialDrawer.AddLine(AX, AY: Integer);
begin
FCanvas.AddLineToPath(AX, InvertY(AY));
end;
procedure TFPVectorialDrawer.AddToFontOrientation(ADelta: Integer); procedure TFPVectorialDrawer.AddToFontOrientation(ADelta: Integer);
begin begin
// Not implemented.
end; end;
procedure TFPVectorialDrawer.ClippingStart(const AClipRect: TRect); procedure TFPVectorialDrawer.ClippingStart(const AClipRect: TRect);
@ -96,10 +106,13 @@ begin
// Not implemented. // Not implemented.
end; end;
constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialDocument); constructor TFPVectorialDrawer.Create(
ACanvas: TvVectorialDocument; ATop, ABottom: Integer);
begin begin
inherited Create; inherited Create;
FCanvas := ACanvas; FCanvas := ACanvas;
FTop := ATop;
FBottom := ABottom;
end; end;
procedure TFPVectorialDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer); procedure TFPVectorialDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
@ -107,16 +120,16 @@ var
cx, cy, rx, ry: Integer; cx, cy, rx, ry: Integer;
begin begin
BoundingBoxToCenterAndHalfRadius(AX1, AY1, AX2, AY2, cx, cy, rx, ry); BoundingBoxToCenterAndHalfRadius(AX1, AY1, AX2, AY2, cx, cy, rx, ry);
FCanvas.AddEllipse(cx, cy, 0, rx, ry, 0.0); FCanvas.AddEllipse(cx, InvertY(cy), 0, rx, ry, 0.0);
end; end;
procedure TFPVectorialDrawer.FillRect(AX1, AY1, AX2, AY2: Integer); procedure TFPVectorialDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);
begin begin
MoveTo(AX1, AY1); MoveTo(AX1, AY1);
FCanvas.AddLineToPath(AX2, AY1); AddLine(AX2, AY1);
FCanvas.AddLineToPath(AX2, AY2); AddLine(AX2, AY2);
FCanvas.AddLineToPath(AX1, AY2); AddLine(AX1, AY2);
FCanvas.AddLineToPath(AX1, AY1); AddLine(AX1, AY1);
FCanvas.SetBrushStyle(bsClear); FCanvas.SetBrushStyle(bsClear);
FCanvas.SetPenColor(FPenColor); FCanvas.SetPenColor(FPenColor);
FCanvas.EndPath(); FCanvas.EndPath();
@ -132,10 +145,15 @@ begin
Result := 0.0; Result := 0.0;
end; end;
function TFPVectorialDrawer.InvertY(AY: Integer): Integer;
begin
Result := FTop + FBottom - AY;
end;
procedure TFPVectorialDrawer.Line(AX1, AY1, AX2, AY2: Integer); procedure TFPVectorialDrawer.Line(AX1, AY1, AX2, AY2: Integer);
begin begin
FCanvas.StartPath(AX1, AY1); FCanvas.StartPath(AX1, InvertY(AY1));
FCanvas.AddLineToPath(AX2, AY2); AddLine(AX2, AY2);
FCanvas.SetPenColor(FPenColor); FCanvas.SetPenColor(FPenColor);
FCanvas.EndPath(); FCanvas.EndPath();
end; end;
@ -147,13 +165,13 @@ end;
procedure TFPVectorialDrawer.LineTo(AX, AY: Integer); procedure TFPVectorialDrawer.LineTo(AX, AY: Integer);
begin begin
FCanvas.AddLineToPath(AX, AY, FPenColor); FCanvas.AddLineToPath(AX, InvertY(AY), FPenColor);
end; end;
procedure TFPVectorialDrawer.MoveTo(AX, AY: Integer); procedure TFPVectorialDrawer.MoveTo(AX, AY: Integer);
begin begin
FCanvas.EndPath(); FCanvas.EndPath();
FCanvas.StartPath(AX, AY); FCanvas.StartPath(AX, InvertY(AY));
end; end;
procedure TFPVectorialDrawer.Polygon( procedure TFPVectorialDrawer.Polygon(
@ -164,7 +182,7 @@ begin
MoveTo(APoints[AStartIndex]); MoveTo(APoints[AStartIndex]);
for i := 1 to ANumPts - 1 do for i := 1 to ANumPts - 1 do
with APoints[i + AStartIndex] do with APoints[i + AStartIndex] do
FCanvas.AddLineToPath(X, Y); AddLine(X, Y);
FCanvas.SetBrushColor(FBrushColor); FCanvas.SetBrushColor(FBrushColor);
FCanvas.SetPenColor(FPenColor); FCanvas.SetPenColor(FPenColor);
FCanvas.EndPath(); FCanvas.EndPath();
@ -197,10 +215,10 @@ end;
procedure TFPVectorialDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer); procedure TFPVectorialDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer);
begin begin
MoveTo(AX1, AY1); MoveTo(AX1, AY1);
FCanvas.AddLineToPath(AX2, AY1); AddLine(AX2, AY1);
FCanvas.AddLineToPath(AX2, AY2); AddLine(AX2, AY2);
FCanvas.AddLineToPath(AX1, AY2); AddLine(AX1, AY2);
FCanvas.AddLineToPath(AX1, AY1); AddLine(AX1, AY1);
FCanvas.SetBrushColor(FBrushColor); FCanvas.SetBrushColor(FBrushColor);
FCanvas.SetBrushStyle(FBrushStyle); FCanvas.SetBrushStyle(FBrushStyle);
FCanvas.SetPenColor(FPenColor); FCanvas.SetPenColor(FPenColor);
@ -257,7 +275,7 @@ end;
procedure TFPVectorialDrawer.SimpleTextOut( procedure TFPVectorialDrawer.SimpleTextOut(
AX, AY: Integer; const AText: String); AX, AY: Integer; const AText: String);
begin begin
FCanvas.AddText(AX, AY, 0, AText); FCanvas.AddText(AX, InvertY(AY), 0, AText);
end; end;
end. end.