fpvectorial: Advances a lot the new background color support

git-svn-id: trunk@39716 -
This commit is contained in:
sekelsenmat 2013-01-01 21:41:58 +00:00
parent 7fb826fb84
commit 4dd594eaaf
2 changed files with 113 additions and 96 deletions

View File

@ -212,7 +212,6 @@ type
public public
X, Y, Z: Double; X, Y, Z: Double;
Name: string; Name: string;
Page: TvVectorialPage;
constructor Create; virtual; constructor Create; virtual;
procedure Clear; virtual; procedure Clear; virtual;
// in CalculateBoundingBox always remember to treat correctly the case of ADest=nil!!! // in CalculateBoundingBox always remember to treat correctly the case of ADest=nil!!!
@ -224,8 +223,9 @@ type
procedure Move(ADeltaX, ADeltaY: Double); virtual; procedure Move(ADeltaX, ADeltaY: Double); virtual;
procedure MoveSubpart(ADeltaX, ADeltaY: Double; ASubpart: Cardinal); virtual; procedure MoveSubpart(ADeltaX, ADeltaY: Double; ASubpart: Cardinal); virtual;
function GetSubpartCount: Integer; virtual; function GetSubpartCount: Integer; virtual;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); virtual; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); virtual;
function AdjustColorToBackground(AColor, ABackgroundColor: TFPColor): TFPColor;
function GetNormalizedPos(APage: TvVectorialPage; ANewMin, ANewMax: Double): T3DPoint; function GetNormalizedPos(APage: TvVectorialPage; ANewMin, ANewMax: Double): T3DPoint;
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual; function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual;
end; end;
@ -240,8 +240,8 @@ type
elements might be able to override this setting. } elements might be able to override this setting. }
Pen: TvPen; Pen: TvPen;
constructor Create; override; constructor Create; override;
procedure ApplyPenToCanvas(ADest: TFPCustomCanvas); procedure ApplyPenToCanvas(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor);
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -254,7 +254,7 @@ type
Brush: TvBrush; Brush: TvBrush;
constructor Create; override; constructor Create; override;
procedure ApplyBrushToCanvas(ADest: TFPCustomCanvas); procedure ApplyBrushToCanvas(ADest: TFPCustomCanvas);
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -287,7 +287,7 @@ type
procedure MoveSubpart(ADeltaX, ADeltaY: Double; ASubpart: Cardinal); override; procedure MoveSubpart(ADeltaX, ADeltaY: Double; ASubpart: Cardinal); override;
function MoveToSubpart(ASubpart: Cardinal): TPathSegment; function MoveToSubpart(ASubpart: Cardinal): TPathSegment;
function GetSubpartCount: Integer; override; function GetSubpartCount: Integer; override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -308,7 +308,7 @@ type
constructor Create; override; constructor Create; override;
destructor Destroy; override; destructor Destroy; override;
function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override; function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -320,7 +320,7 @@ type
TvCircle = class(TvEntityWithPenAndBrush) TvCircle = class(TvEntityWithPenAndBrush)
public public
Radius: Double; Radius: Double;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -334,7 +334,7 @@ type
Radius: Double; Radius: Double;
{@@ The Angle is measured in degrees in relation to the positive X axis } {@@ The Angle is measured in degrees in relation to the positive X axis }
StartAngle, EndAngle: Double; StartAngle, EndAngle: Double;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -351,7 +351,7 @@ type
{@@ The Angle is measured in degrees in relation to the positive X axis } {@@ The Angle is measured in degrees in relation to the positive X axis }
Angle: Double; Angle: Double;
procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override; procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -362,7 +362,7 @@ type
// Mandatory fields // Mandatory fields
CX, CY, CZ: Double; CX, CY, CZ: Double;
procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override; procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -380,7 +380,7 @@ type
public public
// Mandatory fields // Mandatory fields
BaseLeft, BaseRight, DimensionLeft, DimensionRight: T3DPoint; BaseLeft, BaseRight, DimensionLeft, DimensionRight: T3DPoint;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -395,7 +395,7 @@ type
// Mandatory fields // Mandatory fields
IsDiameter: Boolean; // If false, it is a radius, if true, it is a diameter IsDiameter: Boolean; // If false, it is a radius, if true, it is a diameter
Center, DimensionLeft, DimensionRight: T3DPoint; // Diameter uses both, Radius uses only DImensionLeft Center, DimensionLeft, DimensionRight: T3DPoint; // Diameter uses both, Radius uses only DImensionLeft
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -447,7 +447,7 @@ type
ArrowLength: Double; ArrowLength: Double;
ArrowBaseLength: Double; ArrowBaseLength: Double;
procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override; procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -496,7 +496,7 @@ type
function CalculateHeight(ADest: TFPCustomCanvas): Double; // in milimeters function CalculateHeight(ADest: TFPCustomCanvas): Double; // in milimeters
function CalculateWidth(ADest: TFPCustomCanvas): Double; // in milimeters function CalculateWidth(ADest: TFPCustomCanvas): Double; // in milimeters
function AsText: string; function AsText: string;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); virtual; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); virtual;
procedure GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer); virtual; procedure GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer); virtual;
end; end;
@ -526,7 +526,7 @@ type
function CalculateWidth(ADest: TFPCustomCanvas): Double; // in milimeters function CalculateWidth(ADest: TFPCustomCanvas): Double; // in milimeters
procedure PositionElements(ADest: TFPCustomCanvas; ABaseX, ABaseY: Double); procedure PositionElements(ADest: TFPCustomCanvas; ABaseX, ABaseY: Double);
procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override; procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override; function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override;
end; end;
@ -547,7 +547,7 @@ type
function GetNextEntity: TvEntity; function GetNextEntity: TvEntity;
procedure AddEntity(AEntity: TvEntity); procedure AddEntity(AEntity: TvEntity);
procedure Clear; override; procedure Clear; override;
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -560,7 +560,7 @@ type
TvBlock = class(TvEntityWithSubEntities) TvBlock = class(TvEntityWithSubEntities)
public public
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -573,7 +573,7 @@ type
TvInsert = class(TvEntity) TvInsert = class(TvEntity)
public public
Block: TvBlock; // The block to be inserted Block: TvBlock; // The block to be inserted
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0; procedure Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer = 0;
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
end; end;
@ -712,8 +712,8 @@ type
function AddPoint(AX, AY, AZ: Double): TvPoint; function AddPoint(AX, AY, AZ: Double): TvPoint;
{ Drawing methods } { Drawing methods }
procedure DrawBackground(ADest: TFPCustomCanvas); procedure DrawBackground(ADest: TFPCustomCanvas);
function GetInvertedBackgroundColor: TFPColor; procedure Render(ADest: TFPCustomCanvas;
function GetContranstingColor: TFPColor; ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
{ Debug methods } { Debug methods }
procedure GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer); procedure GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer);
// //
@ -969,12 +969,26 @@ begin
Result := 0; Result := 0;
end; end;
procedure TvEntity.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvEntity.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
begin begin
end; end;
function TvEntity.AdjustColorToBackground(AColor, ABackgroundColor: TFPColor
): TFPColor;
begin
Result := AColor;
if (Abs(AColor.Red - ABackgroundColor.Red) < $100) and
(Abs(AColor.Green - ABackgroundColor.Green) < $100) and
(Abs(AColor.Blue - ABackgroundColor.Blue) < $100) then
begin
if (ABackgroundColor.Red <= $1000) and (ABackgroundColor.Green <= $1000) and (ABackgroundColor.Blue <= $1000) then
Result := colWhite
else Result := colBlack;
end;
end;
function TvEntity.GetNormalizedPos(APage: TvVectorialPage; ANewMin, function TvEntity.GetNormalizedPos(APage: TvVectorialPage; ANewMin,
ANewMax: Double): T3DPoint; ANewMax: Double): T3DPoint;
begin begin
@ -1002,18 +1016,18 @@ begin
Pen.Width := 1; Pen.Width := 1;
end; end;
procedure TvEntityWithPen.ApplyPenToCanvas(ADest: TFPCustomCanvas); procedure TvEntityWithPen.ApplyPenToCanvas(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor);
begin begin
ADest.Pen.FPColor := Pen.Color; ADest.Pen.FPColor := AdjustColorToBackground(Pen.Color, ABackgroundColor);
ADest.Pen.Width := 1;//Pen.Width; ADest.Pen.Width := 1;//Pen.Width;
ADest.Pen.Style := Pen.Style; ADest.Pen.Style := Pen.Style;
end; end;
procedure TvEntityWithPen.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvEntityWithPen.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
ApplyPenToCanvas(ADest); ApplyPenToCanvas(ADest, ABackgroundColor);
end; end;
{ TvEntityWithPenAndBrush } { TvEntityWithPenAndBrush }
@ -1032,9 +1046,9 @@ begin
end; end;
procedure TvEntityWithPenAndBrush.Render(ADest: TFPCustomCanvas; procedure TvEntityWithPenAndBrush.Render(ADest: TFPCustomCanvas;
ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double); ABackgroundColor: TFPColor; ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double);
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
ApplyBrushToCanvas(ADest); ApplyBrushToCanvas(ADest);
end; end;
@ -1259,7 +1273,7 @@ begin
Result := Len; Result := Len;
end; end;
procedure TPath.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TPath.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1304,7 +1318,7 @@ begin
if ADest.Pen.Width < 1 then ADest.Pen.Width := 1; if ADest.Pen.Width < 1 then ADest.Pen.Width := 1;
if (Pen.Width <= 2) and (ADest.Pen.Width > 2) then ADest.Pen.Width := 2; if (Pen.Width <= 2) and (ADest.Pen.Width > 2) then ADest.Pen.Width := 2;
if (Pen.Width <= 5) and (ADest.Pen.Width > 5) then ADest.Pen.Width := 5; if (Pen.Width <= 5) and (ADest.Pen.Width > 5) then ADest.Pen.Width := 5;
ADest.Pen.FPColor := Pen.Color; ADest.Pen.FPColor := AdjustColorToBackground(Pen.Color, ABackgroundColor);
ADest.Brush.FPColor := Brush.Color; ADest.Brush.FPColor := Brush.Color;
// Prepare the Clipping Region, if any // Prepare the Clipping Region, if any
@ -1386,7 +1400,7 @@ begin
// This element can override temporarely the Pen // This element can override temporarely the Pen
st2DLineWithPen: st2DLineWithPen:
begin begin
ADest.Pen.FPColor := T2DSegmentWithPen(Cur2DSegment).Pen.Color; ADest.Pen.FPColor := AdjustColorToBackground(T2DSegmentWithPen(Cur2DSegment).Pen.Color, ABackgroundColor);
CoordX := CoordToCanvasX(PosX); CoordX := CoordToCanvasX(PosX);
CoordY := CoordToCanvasY(PosY); CoordY := CoordToCanvasY(PosY);
@ -1492,7 +1506,7 @@ begin
else Result := vfrNotFound; else Result := vfrNotFound;
end; end;
procedure TvText.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvText.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1513,7 +1527,7 @@ var
// //
LowerDim: T3DPoint; LowerDim: T3DPoint;
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
ADest.Font.Size := Round(AmulX * Font.Size); ADest.Font.Size := Round(AmulX * Font.Size);
{ ADest.Pen.Style := psSolid; { ADest.Pen.Style := psSolid;
@ -1541,7 +1555,7 @@ end;
{ TvCircle } { TvCircle }
procedure TvCircle.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvCircle.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1555,7 +1569,7 @@ procedure TvCircle.Render(ADest: TFPCustomCanvas; ADestX: Integer;
end; end;
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
ADest.Ellipse( ADest.Ellipse(
CoordToCanvasX(X - Radius), CoordToCanvasX(X - Radius),
CoordToCanvasY(Y - Radius), CoordToCanvasY(Y - Radius),
@ -1566,7 +1580,7 @@ end;
{ TvCircularArc } { TvCircularArc }
procedure TvCircularArc.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvCircularArc.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1587,6 +1601,7 @@ var
ALCLDest: TCanvas absolute ADest; ALCLDest: TCanvas absolute ADest;
{$endif} {$endif}
begin begin
inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
{$ifdef USE_LCL_CANVAS} {$ifdef USE_LCL_CANVAS}
// ToDo: Consider a X axis inversion // ToDo: Consider a X axis inversion
// If the Y axis is inverted, then we need to mirror our angles as well // If the Y axis is inverted, then we need to mirror our angles as well
@ -1631,12 +1646,10 @@ begin
// WriteLn(Format('Drawing Arc Center=%f,%f Radius=%f StartAngle=%f AngleLength=%f', // WriteLn(Format('Drawing Arc Center=%f,%f Radius=%f StartAngle=%f AngleLength=%f',
// [CurArc.CenterX, CurArc.CenterY, CurArc.Radius, IntStartAngle/16, IntAngleLength/16])); // [CurArc.CenterX, CurArc.CenterY, CurArc.Radius, IntStartAngle/16, IntAngleLength/16]));
{$endif} {$endif}
ADest.Pen.FPColor := Pen.Color;
ALCLDest.Arc( ALCLDest.Arc(
BoundsLeft, BoundsTop, BoundsRight, BoundsBottom, BoundsLeft, BoundsTop, BoundsRight, BoundsBottom,
IntStartAngle, IntAngleLength IntStartAngle, IntAngleLength
); );
ADest.Pen.FPColor := Page.GetContranstingColor();
// Debug info // Debug info
// {$define FPVECTORIALDEBUG} // {$define FPVECTORIALDEBUG}
// {$ifdef FPVECTORIALDEBUG} // {$ifdef FPVECTORIALDEBUG}
@ -1693,7 +1706,7 @@ begin
end; end;
end; end;
procedure TvEllipse.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvEllipse.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1715,7 +1728,7 @@ var
ALCLDest: TCanvas absolute ADest; ALCLDest: TCanvas absolute ADest;
{$endif} {$endif}
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
CalculateBoundingBox(ADest, fx1, fy1, fx2, fy2); CalculateBoundingBox(ADest, fx1, fy1, fx2, fy2);
x1 := CoordToCanvasX(fx1); x1 := CoordToCanvasX(fx1);
@ -1762,7 +1775,7 @@ begin
ABottom := Y + CY; ABottom := Y + CY;
end; end;
procedure TvRectangle.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvRectangle.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1779,7 +1792,7 @@ var
x1, x2, y1, y2: Integer; x1, x2, y1, y2: Integer;
fx1, fy1, fx2, fy2: Double; fx1, fy1, fx2, fy2: Double;
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
CalculateBoundingBox(ADest, fx1, fy1, fx2, fy2); CalculateBoundingBox(ADest, fx1, fy1, fx2, fy2);
x1 := CoordToCanvasX(fx1); x1 := CoordToCanvasX(fx1);
@ -1792,7 +1805,7 @@ end;
{ TvAlignedDimension } { TvAlignedDimension }
procedure TvAlignedDimension.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvAlignedDimension.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1812,7 +1825,7 @@ var
ALCLDest: TCanvas absolute ADest; ALCLDest: TCanvas absolute ADest;
{$endif} {$endif}
begin begin
ADest.Pen.FPColor := Page.GetContranstingColor(); ADest.Pen.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
// //
// Draws this shape: // Draws this shape:
// horizontal vertical // horizontal vertical
@ -1829,7 +1842,7 @@ begin
SetLength(Points, 3); SetLength(Points, 3);
if DimensionRight.Y = DimensionLeft.Y then if DimensionRight.Y = DimensionLeft.Y then
begin begin
ADest.Brush.FPColor := Page.GetContranstingColor(); ADest.Brush.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
// Left arrow // Left arrow
Points[0] := Point(CoordToCanvasX(DimensionLeft.X), CoordToCanvasY(DimensionLeft.Y)); Points[0] := Point(CoordToCanvasX(DimensionLeft.X), CoordToCanvasY(DimensionLeft.Y));
@ -1848,12 +1861,12 @@ begin
LowerDim.X := DimensionRight.X-DimensionLeft.X; LowerDim.X := DimensionRight.X-DimensionLeft.X;
ADest.Font.Size := 10; ADest.Font.Size := 10;
ADest.Font.Orientation := 0; ADest.Font.Orientation := 0;
ADest.Font.FPColor := Page.GetContranstingColor(); ADest.Font.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.TextOut(Points[0].X, Points[0].Y-Round(ADest.Font.Size*1.5), Format('%.1f', [LowerDim.X])); ADest.TextOut(Points[0].X, Points[0].Y-Round(ADest.Font.Size*1.5), Format('%.1f', [LowerDim.X]));
end end
else else
begin begin
ADest.Brush.FPColor := Page.GetContranstingColor(); ADest.Brush.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
// There is no upper/lower preference for DimensionLeft/Right, so we need to check // There is no upper/lower preference for DimensionLeft/Right, so we need to check
if DimensionLeft.Y > DimensionRight.Y then if DimensionLeft.Y > DimensionRight.Y then
@ -1884,7 +1897,7 @@ begin
if LowerDim.Y < 0 then LowerDim.Y := -1 * LowerDim.Y; if LowerDim.Y < 0 then LowerDim.Y := -1 * LowerDim.Y;
ADest.Font.Size := 10; ADest.Font.Size := 10;
ADest.Font.Orientation := 900; ADest.Font.Orientation := 900;
ADest.Font.FPColor := Page.GetContranstingColor(); ADest.Font.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.TextOut(Points[0].X-Round(ADest.Font.Size*1.5), Points[0].Y, Format('%.1f', [LowerDim.Y])); ADest.TextOut(Points[0].X-Round(ADest.Font.Size*1.5), Points[0].Y, Format('%.1f', [LowerDim.Y]));
ADest.Font.Orientation := 0; ADest.Font.Orientation := 0;
end; end;
@ -1904,7 +1917,7 @@ end;
{ TvRadialDimension } { TvRadialDimension }
procedure TvRadialDimension.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvRadialDimension.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -1924,7 +1937,7 @@ var
ALCLDest: TCanvas absolute ADest; ALCLDest: TCanvas absolute ADest;
{$endif} {$endif}
begin begin
ADest.Pen.FPColor := Page.GetContranstingColor(); ADest.Pen.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
// The size of the radius of the circle // The size of the radius of the circle
lRadius := sqrt(sqr(Center.X - DimensionLeft.X) + sqr(Center.Y - DimensionLeft.Y)); lRadius := sqrt(sqr(Center.X - DimensionLeft.X) + sqr(Center.Y - DimensionLeft.Y));
@ -1933,7 +1946,7 @@ begin
// Get an arrow in the right part of the circle // Get an arrow in the right part of the circle
SetLength(Points, 3); SetLength(Points, 3);
ADest.Brush.FPColor := Page.GetContranstingColor(); ADest.Brush.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
Points[0] := Point(CoordToCanvasX(Center.X + lRadius), CoordToCanvasY(Center.Y)); Points[0] := Point(CoordToCanvasX(Center.X + lRadius), CoordToCanvasY(Center.Y));
Points[1] := Point(CoordToCanvasX(Center.X + lRadius*0.8), CoordToCanvasY(Center.Y - lRadius*0.1)); Points[1] := Point(CoordToCanvasX(Center.X + lRadius*0.8), CoordToCanvasY(Center.Y - lRadius*0.1));
@ -1957,7 +1970,7 @@ begin
Points[0].X := CoordToCanvasX(Center.X); Points[0].X := CoordToCanvasX(Center.X);
Points[0].Y := CoordToCanvasY(Center.Y); Points[0].Y := CoordToCanvasY(Center.Y);
ADest.Font.Size := 10; ADest.Font.Size := 10;
ADest.Font.FPColor := Page.GetContranstingColor(); ADest.Font.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.TextOut(Points[0].X, Points[0].Y, Format('%.1f', [lRadius])); ADest.TextOut(Points[0].X, Points[0].Y, Format('%.1f', [lRadius]));
end end
else else
@ -1986,7 +1999,7 @@ begin
Points[0].X := CoordToCanvasX(Center.X); Points[0].X := CoordToCanvasX(Center.X);
Points[0].Y := CoordToCanvasY(Center.Y); Points[0].Y := CoordToCanvasY(Center.Y);
ADest.Font.Size := 10; ADest.Font.Size := 10;
ADest.Font.FPColor := Page.GetContranstingColor(); ADest.Font.FPColor := AdjustColorToBackground(colBlack, ABackgroundColor);
ADest.TextOut(Points[0].X, Points[0].Y, Format('%.1f', [lRadius * 2])); ADest.TextOut(Points[0].X, Points[0].Y, Format('%.1f', [lRadius * 2]));
end; end;
@ -2050,7 +2063,7 @@ begin
end; end;
procedure TvArrow.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvArrow.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -2069,7 +2082,7 @@ var
lPoints: array[0..2] of TPoint; lPoints: array[0..2] of TPoint;
AlfaAngle: Double; AlfaAngle: Double;
begin begin
ApplyPenToCanvas(ADest); ApplyPenToCanvas(ADest, ABackgroundColor);
ApplyBrushToCanvas(ADest); ApplyBrushToCanvas(ADest);
lArrow.X := CoordToCanvasX(X); lArrow.X := CoordToCanvasX(X);
@ -2219,7 +2232,7 @@ begin
end; end;
end; end;
procedure TvFormulaElement.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvFormulaElement.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
function CoordToCanvasX(ACoord: Double): Integer; function CoordToCanvasX(ACoord: Double): Integer;
@ -2258,8 +2271,8 @@ begin
fekGreaterOrEqualThan: ADest.TextOut(LeftC, TopC, '≥'); fekGreaterOrEqualThan: ADest.TextOut(LeftC, TopC, '≥');
fekFraction: fekFraction:
begin begin
Formula.Render(ADest, ADestX, ADestY, AMulX, AMulY); Formula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
AdjacentFormula.Render(ADest, ADestX, ADestY, AMulX, AMulY); AdjacentFormula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
// Division line // Division line
lPt[0].X := CoordToCanvasX(Formula.Left); lPt[0].X := CoordToCanvasX(Formula.Left);
@ -2270,7 +2283,7 @@ begin
end; end;
fekRoot: fekRoot:
begin begin
Formula.Render(ADest, ADestX, ADestY, AMulX, AMulY); Formula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
// Root drawing // Root drawing
lPt[0].X := CoordToCanvasX(Left); lPt[0].X := CoordToCanvasX(Left);
@ -2289,22 +2302,22 @@ begin
end; end;
fekPower: fekPower:
begin begin
Formula.Render(ADest, ADestX, ADestY, AMulX, AMulY); Formula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
// The superscripted power // The superscripted power
lOldFontSize := ADest.Font.Size; lOldFontSize := ADest.Font.Size;
if lOldFontSize = 0 then ADest.Font.Size := 5 if lOldFontSize = 0 then ADest.Font.Size := 5
else ADest.Font.Size := lOldFontSize div 2; else ADest.Font.Size := lOldFontSize div 2;
AdjacentFormula.Render(ADest, ADestX, ADestY, AMulX, AMulY); AdjacentFormula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
ADest.Font.Size := lOldFontSize; ADest.Font.Size := lOldFontSize;
end; end;
fekSubscript: fekSubscript:
begin begin
Formula.Render(ADest, ADestX, ADestY, AMulX, AMulY); Formula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
// The subscripted item // The subscripted item
lOldFontSize := ADest.Font.Size; lOldFontSize := ADest.Font.Size;
if lOldFontSize = 0 then ADest.Font.Size := 5 if lOldFontSize = 0 then ADest.Font.Size := 5
else ADest.Font.Size := lOldFontSize div 2; else ADest.Font.Size := lOldFontSize div 2;
AdjacentFormula.Render(ADest, ADestX, ADestY, AMulX, AMulY); AdjacentFormula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
ADest.Font.Size := lOldFontSize; ADest.Font.Size := lOldFontSize;
end; end;
fekSummation: fekSummation:
@ -2317,10 +2330,10 @@ begin
ADest.Font.Size := lOldFontSize; ADest.Font.Size := lOldFontSize;
// Draw the bottom/main formula // Draw the bottom/main formula
Formula.Render(ADest, ADestX, ADestY, AMulX, AMulY); Formula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
// Draw the top formula // Draw the top formula
AdjacentFormula.Render(ADest, ADestX, ADestY, AMulX, AMulY); AdjacentFormula.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
end; end;
end; end;
end; end;
@ -2560,7 +2573,7 @@ begin
ABottom := Y + ABottom; ABottom := Y + ABottom;
end; end;
procedure TvFormula.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvFormula.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
var var
lElement: TvFormulaElement; lElement: TvFormulaElement;
@ -2573,7 +2586,7 @@ begin
if lElement = nil then Exit; if lElement = nil then Exit;
while lElement <> nil do while lElement <> nil do
begin begin
lElement.Render(ADest, ADestX, ADestY, AMulX, AMulY); lElement.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
lElement := GetNextElement(); lElement := GetNextElement();
end; end;
@ -2643,12 +2656,12 @@ begin
FElements.Clear; FElements.Clear;
end; end;
procedure TvEntityWithSubEntities.Render(ADest: TFPCustomCanvas; procedure TvEntityWithSubEntities.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor;
ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double); ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double);
var var
lEntity: TvEntity; lEntity: TvEntity;
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
lEntity := GetFirstEntity(); lEntity := GetFirstEntity();
while lEntity <> nil do while lEntity <> nil do
begin begin
@ -2658,7 +2671,7 @@ begin
{$ENDIF} {$ENDIF}
// Render // Render
lEntity.Render(ADest, ADestX, ADestY, AMulX, AMuly); lEntity.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMuly);
lEntity := GetNextEntity(); lEntity := GetNextEntity();
end; end;
@ -2666,12 +2679,12 @@ end;
{ TvInsert } { TvInsert }
procedure TvInsert.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvInsert.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
var var
lEntity: TvEntity; lEntity: TvEntity;
begin begin
inherited Render(ADest, ADestX, ADestY, AMulX, AMulY); inherited Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMulY);
if Block = nil then Exit; if Block = nil then Exit;
lEntity := Block.GetFirstEntity(); lEntity := Block.GetFirstEntity();
while lEntity <> nil do while lEntity <> nil do
@ -2684,7 +2697,7 @@ begin
// Alter the position of the elements to consider the positioning of the BLOCK and of the INSERT // Alter the position of the elements to consider the positioning of the BLOCK and of the INSERT
lEntity.Move(Block.X + X, Block.Y + Y); lEntity.Move(Block.X + X, Block.Y + Y);
// Render // Render
lEntity.Render(ADest, ADestX, ADestY, AMulX, AMuly); lEntity.Render(ADest, ABackgroundColor, ADestX, ADestY, AMulX, AMuly);
// Change them back // Change them back
lEntity.Move(- Block.X - X, - Block.Y - Y); lEntity.Move(- Block.X - X, - Block.Y - Y);
@ -2694,7 +2707,7 @@ end;
{ TvBlock } { TvBlock }
procedure TvBlock.Render(ADest: TFPCustomCanvas; ADestX: Integer; procedure TvBlock.Render(ADest: TFPCustomCanvas; ABackgroundColor: TFPColor; ADestX: Integer;
ADestY: Integer; AMulX: Double; AMulY: Double); ADestY: Integer; AMulX: Double; AMulY: Double);
begin begin
// TvBlock.Render must be empty! Because blocks are invisible by themselves // TvBlock.Render must be empty! Because blocks are invisible by themselves
@ -2860,8 +2873,6 @@ end;
} }
function TvVectorialPage.AddEntity(AEntity: TvEntity): Integer; function TvVectorialPage.AddEntity(AEntity: TvEntity): Integer;
begin begin
AEntity.Page := Self;
if FCurrentLayer = nil then if FCurrentLayer = nil then
begin begin
Result := FEntities.Count; Result := FEntities.Count;
@ -3247,19 +3258,30 @@ begin
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
end; end;
function TvVectorialPage.GetInvertedBackgroundColor: TFPColor; procedure TvVectorialPage.Render(ADest: TFPCustomCanvas;
ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double);
var
i: Integer;
CurEntity: TvEntity;
begin begin
Result.Red := $FFFF-BackgroundColor.Red; {$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
Result.Green := $FFFF-BackgroundColor.Green; WriteLn(':>DrawFPVectorialToCanvas');
Result.Blue := $FFFF-BackgroundColor.Blue; {$endif}
Result.Alpha := BackgroundColor.Alpha;
end;
function TvVectorialPage.GetContranstingColor: TFPColor; for i := 0 to GetEntitiesCount - 1 do
begin begin
if (BackgroundColor.Red <= $1000) and (BackgroundColor.Green <= $1000) and (BackgroundColor.Blue <= $1000) then {$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
Result := colWhite Write(Format('[Path] ID=%d', [i]));
else Result := colBlack; {$endif}
CurEntity := GetEntity(i);
CurEntity.Render(ADest, BackgroundColor, ADestX, ADestY, AMulX, AMulY);
end;
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
WriteLn(':<DrawFPVectorialToCanvas');
{$endif}
end; end;
procedure TvVectorialPage.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; procedure TvVectorialPage.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc;

View File

@ -76,26 +76,21 @@ procedure DrawFPVPathToCanvas(ASource: TvVectorialPage; CurPath: TPath;
ADest: TFPCustomCanvas; ADest: TFPCustomCanvas;
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
begin begin
CurPath.Render(ADest, ADestX, ADestY, AMulX, AMulY); CurPath.Render(ADest, colWhite, ADestX, ADestY, AMulX, AMulY);
end; end;
procedure DrawFPVEntityToCanvas(ASource: TvVectorialPage; CurEntity: TvEntity; procedure DrawFPVEntityToCanvas(ASource: TvVectorialPage; CurEntity: TvEntity;
ADest: TFPCustomCanvas; ADest: TFPCustomCanvas;
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
begin begin
if CurEntity is TvEntityWithPenAndBrush then CurEntity.Render(ADest, colWhite, ADestX, ADestY, AMulX, AMulY);
TvEntityWithPenAndBrush(CurEntity).ApplyBrushToCanvas(ADest);
if CurEntity is TvEntityWithPen then
TvEntityWithPen(CurEntity).ApplyPenToCanvas(ADest);
CurEntity.Render(ADest, ADestX, ADestY, AMulX, AMulY);
end; end;
procedure DrawFPVTextToCanvas(ASource: TvVectorialPage; CurText: TvText; procedure DrawFPVTextToCanvas(ASource: TvVectorialPage; CurText: TvText;
ADest: TFPCustomCanvas; ADest: TFPCustomCanvas;
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
begin begin
CurText.Render(ADest, ADestX, ADestY, AMulX, AMulY); CurText.Render(ADest, colWhite, ADestX, ADestY, AMulX, AMulY);
end; end;
end. end.