fpvectorial: Removes TvColor and now uses TFPColor

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1684 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2011-06-16 10:32:44 +00:00
parent 3ccb5e6a96
commit c924f3011e
5 changed files with 74 additions and 118 deletions

View File

@ -49,7 +49,7 @@ type
TPolylineElement = record
X, Y: Double;
Color: TvColor;
Color: TFPColor;
end;
TSPLineElement = record
@ -104,7 +104,7 @@ type
procedure ReadENTITIES_POINT(ATokens: TDXFTokens; AData: TvVectorialDocument);
function GetCoordinateValue(AStr: shortstring): Double;
//
function DXFColorIndexToVColor(AColorIndex: Integer): TvColor;
function DXFColorIndexToFPColor(AColorIndex: Integer): TFPColor;
public
{ General reading methods }
Tokenizer: TDXFTokenizer;
@ -146,24 +146,24 @@ const
// Obtained from http://www.generalcadd.com/pdf/LivingWithAutoCAD_v4.pdf
// Valid for DXF up to AutoCad 2004, after that RGB is available
AUTOCAD_COLOR_PALETTE: array[0..15] of TvColor =
AUTOCAD_COLOR_PALETTE: array[0..15] of TFPColor =
(
(Red: $00; Green: $00; Blue: $00; Alpha: FPValphaOpaque), // 0 - Black
(Red: $00; Green: $00; Blue: $80; Alpha: FPValphaOpaque), // 1 - Dark blue
(Red: $00; Green: $80; Blue: $00; Alpha: FPValphaOpaque), // 2 - Dark green
(Red: $00; Green: $80; Blue: $80; Alpha: FPValphaOpaque), // 3 - Dark cyan
(Red: $80; Green: $00; Blue: $00; Alpha: FPValphaOpaque), // 4 - Dark red
(Red: $80; Green: $00; Blue: $80; Alpha: FPValphaOpaque), // 5 - Dark Magenta
(Red: $80; Green: $80; Blue: $00; Alpha: FPValphaOpaque), // 6 - Dark
(Red: $c0; Green: $c0; Blue: $c0; Alpha: FPValphaOpaque), // 7 - Light Gray
(Red: $80; Green: $80; Blue: $80; Alpha: FPValphaOpaque), // 8 - Medium Gray
(Red: $00; Green: $00; Blue: $ff; Alpha: FPValphaOpaque), // 9 - Light blue
(Red: $00; Green: $ff; Blue: $00; Alpha: FPValphaOpaque), // 10 - Light green
(Red: $00; Green: $ff; Blue: $ff; Alpha: FPValphaOpaque), // 11 - Light cyan
(Red: $ff; Green: $00; Blue: $00; Alpha: FPValphaOpaque), // 12 - Light red
(Red: $ff; Green: $00; Blue: $ff; Alpha: FPValphaOpaque), // 13 - Light Magenta
(Red: $ff; Green: $ff; Blue: $00; Alpha: FPValphaOpaque), // 14 - Light Yellow
(Red: $ff; Green: $ff; Blue: $ff; Alpha: FPValphaOpaque) // 15 - White
(Red: $0000; Green: $0000; Blue: $0000; Alpha: FPValphaOpaque), // 0 - Black
(Red: $0000; Green: $0000; Blue: $8080; Alpha: FPValphaOpaque), // 1 - Dark blue
(Red: $0000; Green: $8080; Blue: $0000; Alpha: FPValphaOpaque), // 2 - Dark green
(Red: $0000; Green: $8080; Blue: $8080; Alpha: FPValphaOpaque), // 3 - Dark cyan
(Red: $8080; Green: $0000; Blue: $0000; Alpha: FPValphaOpaque), // 4 - Dark red
(Red: $8080; Green: $0000; Blue: $8080; Alpha: FPValphaOpaque), // 5 - Dark Magenta
(Red: $8080; Green: $8080; Blue: $0000; Alpha: FPValphaOpaque), // 6 - Dark
(Red: $c0c0; Green: $c0c0; Blue: $c0c0; Alpha: FPValphaOpaque), // 7 - Light Gray
(Red: $8080; Green: $8080; Blue: $8080; Alpha: FPValphaOpaque), // 8 - Medium Gray
(Red: $0000; Green: $0000; Blue: $ffff; Alpha: FPValphaOpaque), // 9 - Light blue
(Red: $0000; Green: $ffff; Blue: $0000; Alpha: FPValphaOpaque), // 10 - Light green
(Red: $0000; Green: $ffff; Blue: $ffff; Alpha: FPValphaOpaque), // 11 - Light cyan
(Red: $ffff; Green: $0000; Blue: $0000; Alpha: FPValphaOpaque), // 12 - Light red
(Red: $ffff; Green: $0000; Blue: $ffff; Alpha: FPValphaOpaque), // 13 - Light Magenta
(Red: $ffff; Green: $ffff; Blue: $0000; Alpha: FPValphaOpaque), // 14 - Light Yellow
(Red: $ffff; Green: $ffff; Blue: $ffff; Alpha: FPValphaOpaque) // 15 - White
);
{ TDXFToken }
@ -478,7 +478,7 @@ var
// LINE
LineStartX, LineStartY, LineStartZ: Double;
LineEndX, LineEndY, LineEndZ: Double;
LLineColor: TvColor;
LLineColor: TFPColor;
begin
// Initial values
LineStartX := 0;
@ -487,7 +487,7 @@ begin
LineEndX := 0;
LineEndY := 0;
LineEndZ := 0;
LLineColor := clvBlack;
LLineColor := colBlack;
for i := 0 to ATokens.Count - 1 do
begin
@ -507,7 +507,7 @@ begin
11: LineEndX := CurToken.FloatValue;
21: LineEndY := CurToken.FloatValue;
31: LineEndZ := CurToken.FloatValue;
62: LLineColor := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
62: LLineColor := DXFColorIndexToFPColor(Trunc(CurToken.FloatValue));
end;
end;
@ -546,7 +546,7 @@ var
CurToken: TDXFToken;
i: Integer;
CenterX, CenterY, CenterZ, Radius, StartAngle, EndAngle: Double;
LColor: TvColor;
LColor: TFPColor;
begin
CenterX := 0.0;
CenterY := 0.0;
@ -554,7 +554,7 @@ begin
Radius := 0.0;
StartAngle := 0.0;
EndAngle := 0.0;
LColor := clvBlack;
LColor := colBlack;
for i := 0 to ATokens.Count - 1 do
begin
@ -574,7 +574,7 @@ begin
40: Radius := CurToken.FloatValue;
50: StartAngle := CurToken.FloatValue;
51: EndAngle := CurToken.FloatValue;
62: LColor := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
62: LColor := DXFColorIndexToFPColor(Trunc(CurToken.FloatValue));
end;
end;
@ -1053,7 +1053,7 @@ begin
SetLength(Polyline, curPoint+1);
Polyline[curPoint].X := 0;
Polyline[curPoint].Y := 0;
Polyline[curPoint].Color := clvBlack;
Polyline[curPoint].Color := colBlack;
for i := 0 to ATokens.Count - 1 do
begin
@ -1071,7 +1071,7 @@ begin
case CurToken.GroupCode of
10: Polyline[curPoint].X := CurToken.FloatValue - DOC_OFFSET.X;
20: Polyline[curPoint].Y := CurToken.FloatValue - DOC_OFFSET.Y;
62: Polyline[curPoint].Color := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
62: Polyline[curPoint].Color := DXFColorIndexToFPColor(Trunc(CurToken.FloatValue));
end;
end;
end;
@ -1192,8 +1192,7 @@ begin
Result := StrToFloat(Copy(AStr, 2, Length(AStr) - 1));}
end;
function TvDXFVectorialReader.DXFColorIndexToVColor(AColorIndex: Integer
): TvColor;
function TvDXFVectorialReader.DXFColorIndexToFPColor(AColorIndex: Integer): TFPColor;
begin
if (AColorIndex >= 0) and (AColorIndex <= 15) then
Result := AUTOCAD_COLOR_PALETTE[AColorIndex]

View File

@ -19,7 +19,7 @@ interface
uses
Classes, SysUtils, Math,
fpcanvas;
fpcanvas, fpimage;
type
TvVectorialFormat = (
@ -44,19 +44,14 @@ const
STR_ENCAPSULATEDPOSTSCRIPT_EXTENSION = '.eps';
type
{@@ We need our own format because TFPColor is too big for our needs and TColor has no Alpha }
TvColor = packed record
Red, Green, Blue, Alpha: Byte;
end;
TvPen = record
Color: TvColor;
Color: TFPColor;
Style: TFPPenStyle;
Width: Integer;
end;
TvBrush = record
Color: TvColor;
Color: TFPColor;
Style: TFPBrushStyle;
end;
@ -64,9 +59,6 @@ const
FPValphaTransparent = $00;
FPValphaOpaque = $FF;
clvBlack: TvColor = (Red: $00; Green: $00; Blue: $00; Alpha: FPValphaOpaque);
clvBlue: TvColor = (Red: $00; Green: $00; Blue: $FF; Alpha: FPValphaOpaque);
type
T3DPoint = record
X, Y, Z: Double;
@ -154,7 +146,7 @@ type
end;
TvFont = record
Color: TvColor;
Color: TFPColor;
Size: integer;
Name: utf8string;
{@@
@ -290,21 +282,21 @@ type
procedure StartPath(); overload;
procedure AddMoveToPath(AX, AY: Double);
procedure AddLineToPath(AX, AY: Double); overload;
procedure AddLineToPath(AX, AY: Double; AColor: TvColor); overload;
procedure AddLineToPath(AX, AY: Double; AColor: TFPColor); overload;
procedure AddLineToPath(AX, AY, AZ: Double); overload;
procedure GetCurrenPathPenPos(var AX, AY: Double);
procedure AddBezierToPath(AX1, AY1, AX2, AY2, AX3, AY3: Double); overload;
procedure AddBezierToPath(AX1, AY1, AZ1, AX2, AY2, AZ2, AX3, AY3, AZ3: Double); overload;
procedure SetBrushColor(AColor: TvColor);
procedure SetBrushColor(AColor: TFPColor);
procedure SetBrushStyle(AStyle: TFPBrushStyle);
procedure SetPenColor(AColor: TvColor);
procedure SetPenColor(AColor: TFPColor);
procedure SetPenStyle(AStyle: TFPPenStyle);
procedure SetPenWidth(AWidth: Integer);
procedure EndPath();
procedure AddText(AX, AY, AZ: Double; FontName: string; FontSize: integer; AText: utf8string); overload;
procedure AddText(AX, AY, AZ: Double; AStr: utf8string); overload;
procedure AddCircle(ACenterX, ACenterY, ACenterZ, ARadius: Double);
procedure AddCircularArc(ACenterX, ACenterY, ACenterZ, ARadius, AStartAngle, AEndAngle: Double; AColor: TvColor);
procedure AddCircularArc(ACenterX, ACenterY, ACenterZ, ARadius, AStartAngle, AEndAngle: Double; AColor: TFPColor);
procedure AddEllipse(CenterX, CenterY, CenterZ, MajorHalfAxis, MinorHalfAxis, Angle: Double);
// Dimensions
procedure AddAlignedDimension(BaseLeft, BaseRight, DimLeft, DimRight: T3DPoint);
@ -467,9 +459,9 @@ end;
constructor TvEntity.Create;
begin
Pen.Style := psSolid;
Pen.Color := clvBlack;
Pen.Color := colBlack;
Brush.Style := bsClear;
Brush.Color := clvBlue;
Brush.Color := colBlue;
end;
{ TvEllipse }
@ -636,7 +628,7 @@ begin
AppendSegmentToTmpPath(segment);
end;
procedure TvVectorialDocument.AddLineToPath(AX, AY: Double; AColor: TvColor);
procedure TvVectorialDocument.AddLineToPath(AX, AY: Double; AColor: TFPColor);
var
segment: T2DSegmentWithPen;
begin
@ -716,7 +708,7 @@ begin
AppendSegmentToTmpPath(segment);
end;
procedure TvVectorialDocument.SetBrushColor(AColor: TvColor);
procedure TvVectorialDocument.SetBrushColor(AColor: TFPColor);
begin
FTmPPath.Brush.Color := AColor;
end;
@ -726,7 +718,7 @@ begin
FTmPPath.Brush.Style := AStyle;
end;
procedure TvVectorialDocument.SetPenColor(AColor: TvColor);
procedure TvVectorialDocument.SetPenColor(AColor: TFPColor);
begin
FTmPPath.Pen.Color := AColor;
end;
@ -790,7 +782,7 @@ begin
end;
procedure TvVectorialDocument.AddCircularArc(ACenterX, ACenterY, ACenterZ,
ARadius, AStartAngle, AEndAngle: Double; AColor: TvColor);
ARadius, AStartAngle, AEndAngle: Double; AColor: TFPColor);
var
lCircularArc: TvCircularArc;
begin
@ -893,9 +885,9 @@ begin
FTmpPath.Points := nil;
FTmpPath.PointsEnd := nil;
FTmpPath.Len := 0;
FTmpPath.Brush.Color := clvBlue;
FTmpPath.Brush.Color := colBlue;
FTmpPath.Brush.Style := bsClear;
FTmpPath.Pen.Color := clvBlack;
FTmpPath.Pen.Color := colBlack;
FTmpPath.Pen.Style := psSolid;
FTmpPath.Pen.Width := 1;
end;

View File

@ -35,18 +35,6 @@ implementation
{$define FPVECTORIALDEBUG}
{$endif}
{$ifdef USE_LCL_CANVAS}
function VColorToTColor(AVColor: TvColor): TColor; inline;
begin
Result := RGBToColor(AVColor.Red, AVColor.Green, AVColor.Blue);
end;
{$endif}
function VColorToFPColor(AVColor: TvColor): TFPColor; inline;
begin
Result := FPColor(AVColor.Red*$100, AVColor.Green*$100, AVColor.Blue*$100);
end;
function Rotate2DPoint(P,Fix :TPoint; alpha:double): TPoint;
var
sinus, cosinus : Extended;
@ -173,13 +161,8 @@ begin
ADest.Pen.Style := CurPath.Pen.Style;
ADest.Pen.Width := CurPath.Pen.Width;
ADest.Brush.Style := CurPath.Brush.Style;
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(CurPath.Pen.Color);
ADest.Brush.Color := VColorToTColor(CurPath.Brush.Color);
{$else}
ADest.Pen.FPColor := VColorToFPColor(CurPath.Pen.Color);
ADest.Brush.FPColor := VColorToFPColor(CurPath.Brush.Color);
{$endif}
ADest.Pen.FPColor := CurPath.Pen.Color;
ADest.Brush.FPColor := CurPath.Brush.Color;
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
Write(Format('[Path] ID=%d', [i]));
@ -201,15 +184,12 @@ begin
// This element can override temporarely the Pen
st2DLineWithPen:
begin
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(T2DSegmentWithPen(Cur2DSegment).Pen.Color);
{$endif}
ADest.Pen.FPColor := T2DSegmentWithPen(Cur2DSegment).Pen.Color;
ADest.LineTo(CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y));
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(CurPath.Pen.Color);
{$endif}
ADest.Pen.FPColor := CurPath.Pen.Color;
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
Write(Format(' L%d,%d', [CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y)]));
{$endif}
@ -285,13 +265,8 @@ begin
ADest.Brush.Style := CurEntity.Brush.Style;
ADest.Pen.Style := CurEntity.Pen.Style;
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(CurEntity.Pen.Color);
ADest.Brush.Color := VColorToTColor(CurEntity.Brush.Color);
{$else}
ADest.Pen.FPColor := VColorToFPColor(CurEntity.Pen.Color);
ADest.Brush.FPColor := VColorToFPColor(CurEntity.Brush.Color);
{$endif}
ADest.Pen.FPColor := CurEntity.Pen.Color;
ADest.Brush.FPColor := CurEntity.Brush.Color;
if CurEntity is TvCircle then
begin
@ -355,7 +330,7 @@ begin
WriteLn(Format('Drawing Arc Center=%f,%f Radius=%f StartAngle=%f AngleLength=%f',
[CurArc.CenterX, CurArc.CenterY, CurArc.Radius, IntStartAngle/16, IntAngleLength/16]));
{$endif}
ADest.Pen.Color := {$ifdef USE_LCL_CANVAS}VColorToTColor(CurArc.Pen.Color);{$else}VColorToFPColor(CurArc.Pen.Color);{$endif}
ADest.Pen.FPColor := CurArc.Pen.Color;
ADest.Arc(
BoundsLeft, BoundsTop, BoundsRight, BoundsBottom,
IntStartAngle, IntAngleLength

View File

@ -25,41 +25,29 @@ type
T10Strings = array[0..9] of shortstring;
// Color Conversion routines
function VColorToFPColor(AVColor: TvColor): TFPColor; inline;
function FPColorToVColor(AFPColor: TFPColor): TvColor;
function VColorToRGBHexString(AVColor: TvColor): string;
function RGBToVColor(AR, AG, AB: Byte): TvColor; inline;
function SeparateString(AString: string; ASeparator: Char): T10Strings;
function FPColorToRGBHexString(AColor: TFPColor): string;
function RGBToFPColor(AR, AG, AB: byte): TFPColor; inline;
function SeparateString(AString: string; ASeparator: char): T10Strings;
implementation
function VColorToFPColor(AVColor: TvColor): TFPColor; inline;
function FPColorToRGBHexString(AColor: TFPColor): string;
begin
Result.Red := AVColor.Red shl 8;
Result.Green := AVColor.Green shl 8;
Result.Blue := AVColor.Blue shl 8;
Result.Alpha := AVColor.Alpha shl 8;
Result := Format('%.2x%.2x%.2x', [AColor.Red shr 8, AColor.Green shr 8, AColor.Blue shr 8]);
end;
function FPColorToVColor(AFPColor: TFPColor): TvColor;
function RGBToFPColor(AR, AG, AB: byte): TFPColor; inline;
begin
Result.Red := AFPColor.Red shr 8;
Result.Green := AFPColor.Green shr 8;
Result.Blue := AFPColor.Blue shr 8;
Result.Alpha := AFPColor.Alpha shr 8;
end;
if AR > $100 then Result.Red := (AR shl 8) + $FF
else Result.Red := AR shl 8;
function VColorToRGBHexString(AVColor: TvColor): string;
begin
Result := Format('%.2x%.2x%.2x', [AVColor.Red, AVColor.Green, AVColor.Blue]);
end;
if AR > $100 then Result.Green := (AG shl 8) + $FF
else Result.Green := AG shl 8;
function RGBToVColor(AR, AG, AB: Byte): TvColor; inline;
begin
Result.Red := AR;
Result.Green := AG;
Result.Blue := AB;
Result.Alpha := 255;
if AR > $100 then Result.Blue := (AB shl 8) + $FF
else Result.Blue := AB shl 8;
Result.Alpha := $FFFF;
end;
{@@
@ -71,14 +59,15 @@ end;
Number of substrings: 10 (indexed 0 to 9)
Length of each substring: 255 (they are shortstrings)
}
function SeparateString(AString: string; ASeparator: Char): T10Strings;
function SeparateString(AString: string; ASeparator: char): T10Strings;
var
i, CurrentPart: Integer;
i, CurrentPart: integer;
begin
CurrentPart := 0;
{ Clears the result }
for i := 0 to 9 do Result[i] := '';
for i := 0 to 9 do
Result[i] := '';
{ Iterates througth the string, filling strings }
for i := 1 to Length(AString) do
@ -88,7 +77,8 @@ begin
Inc(CurrentPart);
{ Verifies if the string capacity wasn't exceeded }
if CurrentPart > 9 then Exit;
if CurrentPart > 9 then
Exit;
end
else
Result[CurrentPart] := Result[CurrentPart] + Copy(AString, i, 1);

View File

@ -175,11 +175,11 @@ begin
// Get the Pen Color and Style
if APath.Pen.Style = psClear then lPenColor := 'none'
else lPenColor := '#' + VColorToRGBHexString(APath.Pen.Color);
else lPenColor := '#' + FPColorToRGBHexString(APath.Pen.Color);
// Get the Brush color and style
if APath.Brush.Style = bsClear then lFillColor := 'none'
else lFillColor := '#' + VColorToRGBHexString(APath.Brush.Color);
else lFillColor := '#' + FPColorToRGBHexString(APath.Brush.Color);
// Now effectively write the path
AStrings.Add(' <path');