You've already forked lazarus-ccr
fpvectorial: starts implementing color support
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1555 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -30,7 +30,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Math,
|
Classes, SysUtils, Math,
|
||||||
fpvectorial;
|
fpvectorial, fpimage;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ Used by tcutils.SeparateString }
|
{ Used by tcutils.SeparateString }
|
||||||
@@ -52,6 +52,7 @@ type
|
|||||||
|
|
||||||
TPolylineElement = record
|
TPolylineElement = record
|
||||||
X, Y: Double;
|
X, Y: Double;
|
||||||
|
Color: TFPColor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TSPLineElement = record
|
TSPLineElement = record
|
||||||
@@ -106,6 +107,8 @@ type
|
|||||||
procedure ReadENTITIES_MTEXT(ATokens: TDXFTokens; AData: TvVectorialDocument);
|
procedure ReadENTITIES_MTEXT(ATokens: TDXFTokens; AData: TvVectorialDocument);
|
||||||
procedure ReadENTITIES_POINT(ATokens: TDXFTokens; AData: TvVectorialDocument);
|
procedure ReadENTITIES_POINT(ATokens: TDXFTokens; AData: TvVectorialDocument);
|
||||||
function GetCoordinateValue(AStr: shortstring): Double;
|
function GetCoordinateValue(AStr: shortstring): Double;
|
||||||
|
//
|
||||||
|
function DXFColorIndexToFPColor(AColorIndex: Integer): TFPColor;
|
||||||
public
|
public
|
||||||
{ General reading methods }
|
{ General reading methods }
|
||||||
Tokenizer: TDXFTokenizer;
|
Tokenizer: TDXFTokenizer;
|
||||||
@@ -145,6 +148,28 @@ const
|
|||||||
DXF_ENTITIES_MODEL_OR_PAPER_SPACE = 67; // default=0=model, 1=paper
|
DXF_ENTITIES_MODEL_OR_PAPER_SPACE = 67; // default=0=model, 1=paper
|
||||||
DXF_ENTITIES_VISIBILITY = 60; // default=0 = Visible, 1 = Invisible
|
DXF_ENTITIES_VISIBILITY = 60; // default=0 = Visible, 1 = Invisible
|
||||||
|
|
||||||
|
// 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 =
|
||||||
|
(
|
||||||
|
(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
|
||||||
|
);
|
||||||
|
|
||||||
{ TDXFToken }
|
{ TDXFToken }
|
||||||
|
|
||||||
constructor TDXFToken.Create;
|
constructor TDXFToken.Create;
|
||||||
@@ -1057,6 +1082,9 @@ begin
|
|||||||
|
|
||||||
curPoint := Length(Polyline);
|
curPoint := Length(Polyline);
|
||||||
SetLength(Polyline, curPoint+1);
|
SetLength(Polyline, curPoint+1);
|
||||||
|
Polyline[curPoint].X := 0;
|
||||||
|
Polyline[curPoint].Y := 0;
|
||||||
|
Polyline[curPoint].Color := colBlack;
|
||||||
|
|
||||||
for i := 0 to ATokens.Count - 1 do
|
for i := 0 to ATokens.Count - 1 do
|
||||||
begin
|
begin
|
||||||
@@ -1064,7 +1092,7 @@ begin
|
|||||||
CurToken := TDXFToken(ATokens.Items[i]);
|
CurToken := TDXFToken(ATokens.Items[i]);
|
||||||
|
|
||||||
// Avoid an exception by previously checking if the conversion can be made
|
// Avoid an exception by previously checking if the conversion can be made
|
||||||
if CurToken.GroupCode in [10, 20, 30] then
|
if CurToken.GroupCode in [10, 20, 30, 62] then
|
||||||
begin
|
begin
|
||||||
CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue), FPointSeparator);
|
CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue), FPointSeparator);
|
||||||
end;
|
end;
|
||||||
@@ -1074,6 +1102,11 @@ begin
|
|||||||
case CurToken.GroupCode of
|
case CurToken.GroupCode of
|
||||||
10: Polyline[curPoint].X := CurToken.FloatValue - DOC_OFFSET.X;
|
10: Polyline[curPoint].X := CurToken.FloatValue - DOC_OFFSET.X;
|
||||||
20: Polyline[curPoint].Y := CurToken.FloatValue - DOC_OFFSET.Y;
|
20: Polyline[curPoint].Y := CurToken.FloatValue - DOC_OFFSET.Y;
|
||||||
|
62:
|
||||||
|
begin
|
||||||
|
if (CurToken.FloatValue >= 0) and (CurToken.FloatValue <= 15) then
|
||||||
|
Polyline[curPoint].Color := DXFColorIndexToFPColor(Trunc(CurToken.FloatValue));
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -1194,6 +1227,12 @@ begin
|
|||||||
Result := StrToFloat(Copy(AStr, 2, Length(AStr) - 1));}
|
Result := StrToFloat(Copy(AStr, 2, Length(AStr) - 1));}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TvDXFVectorialReader.DXFColorIndexToFPColor(AColorIndex: Integer
|
||||||
|
): TFPColor;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TvDXFVectorialReader.Create;
|
constructor TvDXFVectorialReader.Create;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
@@ -38,6 +38,16 @@ const
|
|||||||
STR_CORELDRAW_EXTENSION = '.cdr';
|
STR_CORELDRAW_EXTENSION = '.cdr';
|
||||||
STR_WINMETAFILE_EXTENSION = '.wmf';
|
STR_WINMETAFILE_EXTENSION = '.wmf';
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
const
|
||||||
|
FPValphaTransparent = $00;
|
||||||
|
FPValphaOpaque = $FF;
|
||||||
|
|
||||||
type
|
type
|
||||||
T3DPoint = record
|
T3DPoint = record
|
||||||
X, Y, Z: Double;
|
X, Y, Z: Double;
|
||||||
@@ -74,6 +84,7 @@ type
|
|||||||
T2DSegment = class(TPathSegment)
|
T2DSegment = class(TPathSegment)
|
||||||
public
|
public
|
||||||
X, Y: Double;
|
X, Y: Double;
|
||||||
|
Color: TvColor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@
|
{@@
|
||||||
@@ -224,6 +235,7 @@ type
|
|||||||
procedure AddPath(APath: TPath);
|
procedure AddPath(APath: TPath);
|
||||||
procedure StartPath(AX, AY: Double);
|
procedure StartPath(AX, AY: Double);
|
||||||
procedure AddLineToPath(AX, AY: Double); overload;
|
procedure AddLineToPath(AX, AY: Double); overload;
|
||||||
|
procedure AddLineToPath(AX, AY: Double; AColor: TvColor); overload;
|
||||||
procedure AddLineToPath(AX, AY, AZ: Double); overload;
|
procedure AddLineToPath(AX, AY, AZ: Double); overload;
|
||||||
procedure AddBezierToPath(AX1, AY1, AX2, AY2, AX3, AY3: Double); overload;
|
procedure AddBezierToPath(AX1, AY1, AX2, AY2, AX3, AY3: Double); overload;
|
||||||
procedure AddBezierToPath(AX1, AY1, AZ1, AX2, AY2, AZ2, AX3, AY3, AZ3: Double); overload;
|
procedure AddBezierToPath(AX1, AY1, AZ1, AX2, AY2, AZ2, AX3, AY3, AZ3: Double); overload;
|
||||||
@@ -528,6 +540,19 @@ begin
|
|||||||
AppendSegmentToTmpPath(segment);
|
AppendSegmentToTmpPath(segment);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TvVectorialDocument.AddLineToPath(AX, AY: Double; AColor: TvColor);
|
||||||
|
var
|
||||||
|
segment: T2DSegment;
|
||||||
|
begin
|
||||||
|
segment := T2DSegment.Create;
|
||||||
|
segment.SegmentType := st2DLine;
|
||||||
|
segment.X := AX;
|
||||||
|
segment.Y := AY;
|
||||||
|
segment.Color := AColor;
|
||||||
|
|
||||||
|
AppendSegmentToTmpPath(segment);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TvVectorialDocument.AddLineToPath(AX, AY, AZ: Double);
|
procedure TvVectorialDocument.AddLineToPath(AX, AY, AZ: Double);
|
||||||
var
|
var
|
||||||
segment: T3DSegment;
|
segment: T3DSegment;
|
||||||
|
Reference in New Issue
Block a user