procedure DrawColorTextToCanvas(AText:
String; ACanvas: TCanvas; APos: TPoint);
var LLeft, LPos, LLastPos, LCount: Integer;
LStr2, LWord:
String;
LColorList: TStringlist;
LColor: TColor;
begin
LColorList := TStringList.Create;
LPos := 1;
LLastPos := 1;
LPos := PosEx('
\c', AText, LPos);
while LPos > 0
do
begin
LStr2 := copy(AText, LPos + 2, 6);
if length(LStr2) = 6
then
begin
LColor :=
RGB(StrToInt('
$' + copy(AText, LPos + 2, 2)),
StrToInt('
$' + copy(AText, LPos + 4, 2)),
StrToInt('
$' + copy(AText, LPos + 6, 2)));
LStr2 := copy(AText, LLastPos, LPos - LLastPos);
LColorList.AddObject(LStr2, TObject(LColor));
LWord := LWord + LStr2;
end;
LLastPos := LPos + 8;
LPos := PosEx('
\c', AText, LLastPos);
end;
LStr2 := copy(AText, LLastPos, length(AText) - LLastPos + 1);
if LStr2 <> '
'
then
begin
LColorList.AddObject(LStr2,
nil);
LWord := LWord + LStr2;
end;
LLeft := APos.X;
for LCount := 0
to LColorList.Count - 1
do
begin
ACanvas.TextOut(LLeft, APos.Y, LColorList.Strings[LCount]);
ACanvas.Font.Color := TColor(LColorList.Objects[LCount]);
LLeft := LLeft + ACanvas.TextWidth(LColorList.Strings[LCount]);
end;
LColorList.Free;
end;