diff --git a/components/gridprinter/source/gridprn.pas b/components/gridprinter/source/gridprn.pas index 5a21d2326..e5307803a 100644 --- a/components/gridprinter/source/gridprn.pas +++ b/components/gridprinter/source/gridprn.pas @@ -177,6 +177,9 @@ type procedure DoPrepareCanvas(ACol, ARow: Integer); virtual; procedure DoUpdatePreview; virtual; procedure Execute(ACanvas: TCanvas); + function GetBrushColor(AColor: TColor): TColor; + function GetFontColor(AColor: TColor): TColor; + function GetPenColor(AColor: TCOlor): TColor; procedure LayoutPagebreaks; procedure Measure(APageWidth, APageHeight, XDpi, YDpi: Integer); procedure NewPage; @@ -625,6 +628,32 @@ begin Result := mm2px(FBorderLineWidth, FPixelsPerInchX); 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; begin @@ -850,7 +879,6 @@ end; procedure TGridPrinter.PrepareCanvas(ACanvas: TCanvas; ACol, ARow: Integer); var lGrid: TGridAccess; - color, alternateColor: TColor; textStyle: TTextStyle; begin lGrid := TGridAccess(FGrid); @@ -858,18 +886,18 @@ begin // Background color ACanvas.Brush.Style := bsSolid; 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 begin - color := ColorToRGB(lGrid.Color); - alternateColor := ColorToRGB(lGrid.AlternateColor); - if (color <> alternateColor) and not Odd(ARow) then - ACanvas.Brush.Color := alternateColor + if Odd(ARow) then + ACanvas.Brush.Color := GetBrushColor(lGrid.Color) else - ACanvas.Brush.Color := color; + ACanvas.Brush.Color := GetBrushColor(lGrid.AlternateColor); end; // Font SelectFont(ACanvas, lGrid.Font); + ACanvas.Font.Color := GetFontColor(lGrid.Font.Color); + FixFontSize(ACanvas.Font); // Text style textStyle := DefaultTextStyle; if (goCellEllipsis in lGrid.Options) then @@ -878,11 +906,6 @@ begin // Fire the event OnPrepareCanvas DoPrepareCanvas(ACol, ARow); - - // Fix zero font size and monochrome text color - FixFontSize(ACanvas.Font); - if FMonochrome then - ACanvas.Font.Color := clBlack; end; procedure TGridPrinter.Print; @@ -1198,6 +1221,7 @@ begin exit; SelectFont(ACanvas, FFooter.Font); + ACanvas.Font.Color := GetFontColor(FFooter.Font.Color); printableWidth := FPageRect.Width; if (FFooter.SectionText[hfsLeft] <> '') and (FFooter.SectionText[hfsCenter] = '') and (FFooter.SectionText[hfsRight] = '') then Width[hfsLeft] := printableWidth @@ -1264,8 +1288,7 @@ begin // Print inner grid lines ACanvas.Pen.EndCap := pecFlat; ACanvas.Pen.Style := lGrid.GridLineStyle; - ACanvas.Pen.Color := IfThen(FMonoChrome, clBlack, - IfThen(FGridLineColor = clDefault, lGrid.GridLineColor, FGridLineColor)); + ACanvas.Pen.Color := GetPenColor(IfThen(FGridLineColor = clDefault, lGrid.GridLineColor, FGridLineColor)); // ... vertical fixed cell lines if (goFixedVertLine in lGrid.Options) then begin @@ -1349,7 +1372,7 @@ begin // Print header border lines between fixed and normal cells // ... horizontal ACanvas.Pen.Style := psSolid; - ACanvas.Pen.Color := IfThen(FMonochrome or (FFixedLineColor = clDefault), clBlack, FFixedLineColor); + ACanvas.Pen.Color := GetPenColor(FFixedLineColor); ACanvas.Pen.Width := GetFixedLineWidthHor; ACanvas.Line(FLeftMargin, FFixedRowPos, XEnd, FFixedRowPos); // ... vertical @@ -1359,8 +1382,7 @@ begin // Print outer border lines ACanvas.Pen.EndCap := pecRound; ACanvas.Pen.Style := psSolid; - ACanvas.Pen.Color := IfThen(FMonochrome, clBlack, - IfThen(FBorderLineColor = clDefault, clBlack, ColorToRGB(FBorderLineColor))); + ACanvas.Pen.Color := GetPenColor(FBorderLineColor); // ... horizontal ACanvas.Pen.Width := GetBorderLineWidthHor; ACanvas.Line(FLeftMargin, FTopMargin, XEnd, FTopMargin); @@ -1384,6 +1406,7 @@ begin exit; SelectFont(ACanvas, FHeader.Font); + ACanvas.Font.Color := GetFontColor(FHeader.Font.Color); printableWidth := FPageRect.Width; if (FHeader.SectionText[hfsLeft] <> '') and (FHeader.SectionText[hfsCenter] = '') and (FHeader.SectionText[hfsRight] = '') then Width[hfsLeft] := printableWidth