You've already forked lazarus-ccr
GridPrinter: Fix colors for dark mode
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8600 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -177,6 +177,9 @@ type
|
|||||||
procedure DoPrepareCanvas(ACol, ARow: Integer); virtual;
|
procedure DoPrepareCanvas(ACol, ARow: Integer); virtual;
|
||||||
procedure DoUpdatePreview; virtual;
|
procedure DoUpdatePreview; virtual;
|
||||||
procedure Execute(ACanvas: TCanvas);
|
procedure Execute(ACanvas: TCanvas);
|
||||||
|
function GetBrushColor(AColor: TColor): TColor;
|
||||||
|
function GetFontColor(AColor: TColor): TColor;
|
||||||
|
function GetPenColor(AColor: TCOlor): TColor;
|
||||||
procedure LayoutPagebreaks;
|
procedure LayoutPagebreaks;
|
||||||
procedure Measure(APageWidth, APageHeight, XDpi, YDpi: Integer);
|
procedure Measure(APageWidth, APageHeight, XDpi, YDpi: Integer);
|
||||||
procedure NewPage;
|
procedure NewPage;
|
||||||
@ -625,6 +628,32 @@ begin
|
|||||||
Result := mm2px(FBorderLineWidth, FPixelsPerInchX);
|
Result := mm2px(FBorderLineWidth, FPixelsPerInchX);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Returns a bright brush even in dark mode
|
||||||
|
function TGridPrinter.GetBrushColor(AColor: TColor): TColor;
|
||||||
|
begin
|
||||||
|
if (AColor = clDefault) or (AColor = clWindow) or FMonochrome then
|
||||||
|
Result := clWhite
|
||||||
|
else
|
||||||
|
Result := ColorToRGB(AColor);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Returns a dark pen, even in dark mode
|
||||||
|
function TGridPrinter.GetFontColor(AColor: TColor): TColor;
|
||||||
|
begin
|
||||||
|
if (AColor = clDefault) or (AColor = clWindowText) or FMonochrome then
|
||||||
|
Result := clBlack
|
||||||
|
else
|
||||||
|
Result := ColorToRGB(AColor);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Returns a dark font, even in dark mode
|
||||||
|
function TGridPrinter.GetPenColor(AColor: TCOlor): TColor;
|
||||||
|
begin
|
||||||
|
if (AColor = clDefault) or (AColor = clWindowText) or FMonochrome then
|
||||||
|
Result := clBlack
|
||||||
|
else
|
||||||
|
Result := ColorToRGB(AColor);
|
||||||
|
end;
|
||||||
|
|
||||||
function TGridPrinter.GetCanvas: TCanvas;
|
function TGridPrinter.GetCanvas: TCanvas;
|
||||||
begin
|
begin
|
||||||
@ -850,7 +879,6 @@ end;
|
|||||||
procedure TGridPrinter.PrepareCanvas(ACanvas: TCanvas; ACol, ARow: Integer);
|
procedure TGridPrinter.PrepareCanvas(ACanvas: TCanvas; ACol, ARow: Integer);
|
||||||
var
|
var
|
||||||
lGrid: TGridAccess;
|
lGrid: TGridAccess;
|
||||||
color, alternateColor: TColor;
|
|
||||||
textStyle: TTextStyle;
|
textStyle: TTextStyle;
|
||||||
begin
|
begin
|
||||||
lGrid := TGridAccess(FGrid);
|
lGrid := TGridAccess(FGrid);
|
||||||
@ -858,18 +886,18 @@ begin
|
|||||||
// Background color
|
// Background color
|
||||||
ACanvas.Brush.Style := bsSolid;
|
ACanvas.Brush.Style := bsSolid;
|
||||||
if (ACol < FFixedCols) or (ARow < FFixedRows) then
|
if (ACol < FFixedCols) or (ARow < FFixedRows) then
|
||||||
ACanvas.Brush.Color := ColorToRGB(lGrid.FixedColor)
|
ACanvas.Brush.Color := GetBrushColor(IfThen(lGrid.FixedColor = clBtnFace, $E0E0E0, lGrid.FixedColor))
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
color := ColorToRGB(lGrid.Color);
|
if Odd(ARow) then
|
||||||
alternateColor := ColorToRGB(lGrid.AlternateColor);
|
ACanvas.Brush.Color := GetBrushColor(lGrid.Color)
|
||||||
if (color <> alternateColor) and not Odd(ARow) then
|
|
||||||
ACanvas.Brush.Color := alternateColor
|
|
||||||
else
|
else
|
||||||
ACanvas.Brush.Color := color;
|
ACanvas.Brush.Color := GetBrushColor(lGrid.AlternateColor);
|
||||||
end;
|
end;
|
||||||
// Font
|
// Font
|
||||||
SelectFont(ACanvas, lGrid.Font);
|
SelectFont(ACanvas, lGrid.Font);
|
||||||
|
ACanvas.Font.Color := GetFontColor(lGrid.Font.Color);
|
||||||
|
FixFontSize(ACanvas.Font);
|
||||||
// Text style
|
// Text style
|
||||||
textStyle := DefaultTextStyle;
|
textStyle := DefaultTextStyle;
|
||||||
if (goCellEllipsis in lGrid.Options) then
|
if (goCellEllipsis in lGrid.Options) then
|
||||||
@ -878,11 +906,6 @@ begin
|
|||||||
|
|
||||||
// Fire the event OnPrepareCanvas
|
// Fire the event OnPrepareCanvas
|
||||||
DoPrepareCanvas(ACol, ARow);
|
DoPrepareCanvas(ACol, ARow);
|
||||||
|
|
||||||
// Fix zero font size and monochrome text color
|
|
||||||
FixFontSize(ACanvas.Font);
|
|
||||||
if FMonochrome then
|
|
||||||
ACanvas.Font.Color := clBlack;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGridPrinter.Print;
|
procedure TGridPrinter.Print;
|
||||||
@ -1198,6 +1221,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
SelectFont(ACanvas, FFooter.Font);
|
SelectFont(ACanvas, FFooter.Font);
|
||||||
|
ACanvas.Font.Color := GetFontColor(FFooter.Font.Color);
|
||||||
printableWidth := FPageRect.Width;
|
printableWidth := FPageRect.Width;
|
||||||
if (FFooter.SectionText[hfsLeft] <> '') and (FFooter.SectionText[hfsCenter] = '') and (FFooter.SectionText[hfsRight] = '') then
|
if (FFooter.SectionText[hfsLeft] <> '') and (FFooter.SectionText[hfsCenter] = '') and (FFooter.SectionText[hfsRight] = '') then
|
||||||
Width[hfsLeft] := printableWidth
|
Width[hfsLeft] := printableWidth
|
||||||
@ -1264,8 +1288,7 @@ begin
|
|||||||
// Print inner grid lines
|
// Print inner grid lines
|
||||||
ACanvas.Pen.EndCap := pecFlat;
|
ACanvas.Pen.EndCap := pecFlat;
|
||||||
ACanvas.Pen.Style := lGrid.GridLineStyle;
|
ACanvas.Pen.Style := lGrid.GridLineStyle;
|
||||||
ACanvas.Pen.Color := IfThen(FMonoChrome, clBlack,
|
ACanvas.Pen.Color := GetPenColor(IfThen(FGridLineColor = clDefault, lGrid.GridLineColor, FGridLineColor));
|
||||||
IfThen(FGridLineColor = clDefault, lGrid.GridLineColor, FGridLineColor));
|
|
||||||
// ... vertical fixed cell lines
|
// ... vertical fixed cell lines
|
||||||
if (goFixedVertLine in lGrid.Options) then
|
if (goFixedVertLine in lGrid.Options) then
|
||||||
begin
|
begin
|
||||||
@ -1349,7 +1372,7 @@ begin
|
|||||||
// Print header border lines between fixed and normal cells
|
// Print header border lines between fixed and normal cells
|
||||||
// ... horizontal
|
// ... horizontal
|
||||||
ACanvas.Pen.Style := psSolid;
|
ACanvas.Pen.Style := psSolid;
|
||||||
ACanvas.Pen.Color := IfThen(FMonochrome or (FFixedLineColor = clDefault), clBlack, FFixedLineColor);
|
ACanvas.Pen.Color := GetPenColor(FFixedLineColor);
|
||||||
ACanvas.Pen.Width := GetFixedLineWidthHor;
|
ACanvas.Pen.Width := GetFixedLineWidthHor;
|
||||||
ACanvas.Line(FLeftMargin, FFixedRowPos, XEnd, FFixedRowPos);
|
ACanvas.Line(FLeftMargin, FFixedRowPos, XEnd, FFixedRowPos);
|
||||||
// ... vertical
|
// ... vertical
|
||||||
@ -1359,8 +1382,7 @@ begin
|
|||||||
// Print outer border lines
|
// Print outer border lines
|
||||||
ACanvas.Pen.EndCap := pecRound;
|
ACanvas.Pen.EndCap := pecRound;
|
||||||
ACanvas.Pen.Style := psSolid;
|
ACanvas.Pen.Style := psSolid;
|
||||||
ACanvas.Pen.Color := IfThen(FMonochrome, clBlack,
|
ACanvas.Pen.Color := GetPenColor(FBorderLineColor);
|
||||||
IfThen(FBorderLineColor = clDefault, clBlack, ColorToRGB(FBorderLineColor)));
|
|
||||||
// ... horizontal
|
// ... horizontal
|
||||||
ACanvas.Pen.Width := GetBorderLineWidthHor;
|
ACanvas.Pen.Width := GetBorderLineWidthHor;
|
||||||
ACanvas.Line(FLeftMargin, FTopMargin, XEnd, FTopMargin);
|
ACanvas.Line(FLeftMargin, FTopMargin, XEnd, FTopMargin);
|
||||||
@ -1384,6 +1406,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
SelectFont(ACanvas, FHeader.Font);
|
SelectFont(ACanvas, FHeader.Font);
|
||||||
|
ACanvas.Font.Color := GetFontColor(FHeader.Font.Color);
|
||||||
printableWidth := FPageRect.Width;
|
printableWidth := FPageRect.Width;
|
||||||
if (FHeader.SectionText[hfsLeft] <> '') and (FHeader.SectionText[hfsCenter] = '') and (FHeader.SectionText[hfsRight] = '') then
|
if (FHeader.SectionText[hfsLeft] <> '') and (FHeader.SectionText[hfsCenter] = '') and (FHeader.SectionText[hfsRight] = '') then
|
||||||
Width[hfsLeft] := printableWidth
|
Width[hfsLeft] := printableWidth
|
||||||
|
Reference in New Issue
Block a user