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
|
||||
Classes, SysUtils, Math,
|
||||
fpvectorial;
|
||||
fpvectorial, fpimage;
|
||||
|
||||
type
|
||||
{ Used by tcutils.SeparateString }
|
||||
@@ -52,6 +52,7 @@ type
|
||||
|
||||
TPolylineElement = record
|
||||
X, Y: Double;
|
||||
Color: TFPColor;
|
||||
end;
|
||||
|
||||
TSPLineElement = record
|
||||
@@ -106,6 +107,8 @@ type
|
||||
procedure ReadENTITIES_MTEXT(ATokens: TDXFTokens; AData: TvVectorialDocument);
|
||||
procedure ReadENTITIES_POINT(ATokens: TDXFTokens; AData: TvVectorialDocument);
|
||||
function GetCoordinateValue(AStr: shortstring): Double;
|
||||
//
|
||||
function DXFColorIndexToFPColor(AColorIndex: Integer): TFPColor;
|
||||
public
|
||||
{ General reading methods }
|
||||
Tokenizer: TDXFTokenizer;
|
||||
@@ -145,6 +148,28 @@ const
|
||||
DXF_ENTITIES_MODEL_OR_PAPER_SPACE = 67; // default=0=model, 1=paper
|
||||
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 }
|
||||
|
||||
constructor TDXFToken.Create;
|
||||
@@ -1057,6 +1082,9 @@ begin
|
||||
|
||||
curPoint := Length(Polyline);
|
||||
SetLength(Polyline, curPoint+1);
|
||||
Polyline[curPoint].X := 0;
|
||||
Polyline[curPoint].Y := 0;
|
||||
Polyline[curPoint].Color := colBlack;
|
||||
|
||||
for i := 0 to ATokens.Count - 1 do
|
||||
begin
|
||||
@@ -1064,7 +1092,7 @@ begin
|
||||
CurToken := TDXFToken(ATokens.Items[i]);
|
||||
|
||||
// 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
|
||||
CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue), FPointSeparator);
|
||||
end;
|
||||
@@ -1074,6 +1102,11 @@ begin
|
||||
case CurToken.GroupCode of
|
||||
10: Polyline[curPoint].X := CurToken.FloatValue - DOC_OFFSET.X;
|
||||
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;
|
||||
@@ -1194,6 +1227,12 @@ begin
|
||||
Result := StrToFloat(Copy(AStr, 2, Length(AStr) - 1));}
|
||||
end;
|
||||
|
||||
function TvDXFVectorialReader.DXFColorIndexToFPColor(AColorIndex: Integer
|
||||
): TFPColor;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
constructor TvDXFVectorialReader.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
|
@@ -38,6 +38,16 @@ const
|
||||
STR_CORELDRAW_EXTENSION = '.cdr';
|
||||
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
|
||||
T3DPoint = record
|
||||
X, Y, Z: Double;
|
||||
@@ -74,6 +84,7 @@ type
|
||||
T2DSegment = class(TPathSegment)
|
||||
public
|
||||
X, Y: Double;
|
||||
Color: TvColor;
|
||||
end;
|
||||
|
||||
{@@
|
||||
@@ -224,6 +235,7 @@ type
|
||||
procedure AddPath(APath: TPath);
|
||||
procedure StartPath(AX, AY: Double);
|
||||
procedure AddLineToPath(AX, AY: Double); overload;
|
||||
procedure AddLineToPath(AX, AY: Double; AColor: TvColor); overload;
|
||||
procedure AddLineToPath(AX, AY, AZ: 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;
|
||||
@@ -528,6 +540,19 @@ begin
|
||||
AppendSegmentToTmpPath(segment);
|
||||
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);
|
||||
var
|
||||
segment: T3DSegment;
|
||||
|
Reference in New Issue
Block a user