fpspreadsheet: Fix painting of "hair" border line (densely dotted) in WorksheetGrid

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4472 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-01-25 22:55:31 +00:00
parent 16e6614574
commit 1184e0ce26

View File

@@ -865,7 +865,7 @@ begin
FillPatternFgColor := AFgColor; FillPatternFgColor := AFgColor;
end; end;
(*
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Helper procedure which draws a densely dotted horizontal line. In Excel Helper procedure which draws a densely dotted horizontal line. In Excel
this is called a "hair line". this is called a "hair line".
@@ -906,7 +906,7 @@ begin
ACanvas.Pixels[x, y] := clr; ACanvas.Pixels[x, y] := clr;
inc(y, 2); inc(y, 2);
end; end;
end; end; *)
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Calculates a background color for selected cells. The procedures takes the Calculates a background color for selected cells. The procedures takes the
@@ -1781,30 +1781,41 @@ const
procedure DrawBorderLine(ACoord: Integer; ARect: TRect; ADrawDirection: Byte; procedure DrawBorderLine(ACoord: Integer; ARect: TRect; ADrawDirection: Byte;
ABorderStyle: TsCellBorderStyle); ABorderStyle: TsCellBorderStyle);
const const
// TsLineStyle = (lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair); //TsLineStyle = (
// lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair,
// lsMediumDash, lsDashDot, lsMediumDashDot, lsDashDotDot, lsMediumDashDotDot,
// lsSlantDashDot);
PEN_STYLES: array[TsLineStyle] of TPenStyle = PEN_STYLES: array[TsLineStyle] of TPenStyle =
(psSolid, psSolid, psDash, psDot, psSolid, psSolid, psSolid, (psSolid, psSolid, psDash, psDot, psSolid, psSolid, psDot,
psDash, psDashDot, psDashDot, psDashDotDot, psDashDotDot, psDashDot); psDash, psDashDot, psDashDot, psDashDotDot, psDashDotDot,
psDashDot);
PEN_WIDTHS: array[TsLineStyle] of Integer = PEN_WIDTHS: array[TsLineStyle] of Integer =
(1, 2, 1, 1, 3, 1, 1, (1, 2, 1, 1, 3, 1, 1,
2, 1, 2, 1, 2, 2); 2, 1, 2, 1, 2,
2);
var var
width3: Boolean; // line is 3 pixels wide width3: Boolean; // line is 3 pixels wide
deltax, deltay: Integer; deltax, deltay: Integer;
angle: Double; angle: Double;
savedCosmetic: Boolean;
begin begin
savedCosmetic := Canvas.Pen.Cosmetic;
width3 := (ABorderStyle.LineStyle in [lsThick, lsDouble]);
Canvas.Pen.Style := PEN_STYLES[ABorderStyle.LineStyle]; Canvas.Pen.Style := PEN_STYLES[ABorderStyle.LineStyle];
Canvas.Pen.Width := PEN_WIDTHS[ABorderStyle.LineStyle]; Canvas.Pen.Width := PEN_WIDTHS[ABorderStyle.LineStyle];
Canvas.Pen.Color := ABorderStyle.Color and $00FFFFFF; Canvas.Pen.Color := ABorderStyle.Color and $00FFFFFF;
Canvas.Pen.EndCap := pecSquare; Canvas.Pen.EndCap := pecSquare;
width3 := (ABorderStyle.LineStyle in [lsThick, lsDouble]); if ABorderStyle.LineStyle = lsHair then Canvas.Pen.Cosmetic := false;
// Workaround until efficient drawing procedures for diagonal "hair" lines // Workaround until efficient drawing procedures for diagonal "hair" lines
// is available // is available
{
if (ADrawDirection in [drawDiagUp, drawDiagDown]) and if (ADrawDirection in [drawDiagUp, drawDiagDown]) and
(ABorderStyle.LineStyle = lsHair) (ABorderStyle.LineStyle = lsHair)
then then
ABorderStyle.LineStyle := lsDotted; ABorderStyle.LineStyle := lsDotted;
}
// Tuning the rectangle to avoid issues at the grid borders and to get nice corners // Tuning the rectangle to avoid issues at the grid borders and to get nice corners
if (ABorderStyle.LineStyle in [lsMedium, lsMediumDash, lsMediumDashDot, if (ABorderStyle.LineStyle in [lsMedium, lsMediumDash, lsMediumDashDot,
@@ -1824,25 +1835,30 @@ const
end; end;
end; end;
if ABorderStyle.LineStyle in [lsMedium, lsMediumDash, lsMediumDashDot, if ABorderStyle.LineStyle in [lsMedium, lsMediumDash, lsMediumDashDot,
lsMediumDashDotDot, lsSlantDashDot, lsThick] then lsMediumDashDotDot, lsSlantDashDot, lsThick, lsHair] then
begin begin
if (ADrawDirection = drawHor) then if (ADrawDirection = drawHor) then
dec(ARect.Right, 1) dec(ARect.Right, 1)
else if (ADrawDirection = drawVert) then else if (ADrawDirection = drawVert) then
dec(ARect.Bottom, 1)
else if (ADrawDirection in [drawDiagUp, drawDiagDown]) then
begin
dec(ARect.Right, 1);
dec(ARect.Bottom, 1); dec(ARect.Bottom, 1);
end;
end; end;
// Painting // Painting
case ABorderStyle.LineStyle of case ABorderStyle.LineStyle of
lsThin, lsMedium, lsThick, lsDotted, lsDashed, lsDashDot, lsDashDotDot, lsThin, lsMedium, lsThick, lsDotted, lsDashed, lsDashDot, lsDashDotDot,
lsMediumDash, lsMediumDashDot, lsMediumDashDotDot, lsSlantDashDot: lsMediumDash, lsMediumDashDot, lsMediumDashDotDot, lsSlantDashDot, lsHair:
case ADrawDirection of case ADrawDirection of
drawHor : Canvas.Line(ARect.Left, ACoord, ARect.Right, ACoord); drawHor : Canvas.Line(ARect.Left, ACoord, ARect.Right, ACoord);
drawVert : Canvas.Line(ACoord, ARect.Top, ACoord, ARect.Bottom); drawVert : Canvas.Line(ACoord, ARect.Top, ACoord, ARect.Bottom);
drawDiagUp : Canvas.Line(ARect.Left, ARect.Bottom, ARect.Right, ARect.Top); drawDiagUp : Canvas.Line(ARect.Left, ARect.Bottom, ARect.Right, ARect.Top);
drawDiagDown: Canvas.Line(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); drawDiagDown: Canvas.Line(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
end; end;
{
lsHair: lsHair:
case ADrawDirection of case ADrawDirection of
drawHor : DrawHairLineHor(Canvas, ARect.Left, ARect.Right, ACoord); drawHor : DrawHairLineHor(Canvas, ARect.Left, ARect.Right, ACoord);
@@ -1850,7 +1866,7 @@ const
drawDiagUp : ; drawDiagUp : ;
drawDiagDown: ; drawDiagDown: ;
end; end;
}
lsDouble: lsDouble:
case ADrawDirection of case ADrawDirection of
drawHor: drawHor:
@@ -1891,6 +1907,7 @@ const
end; end;
end; end;
end; end;
Canvas.Pen.Cosmetic := savedCosmetic;
end; end;
var var