You've already forked lazarus-ccr
fpspreadsheet: Fix worsheetgrid respecting font color defined by number format code
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4225 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -171,7 +171,7 @@ type
|
|||||||
procedure InternalDrawTextInCell(AText: String; ARect: TRect;
|
procedure InternalDrawTextInCell(AText: String; ARect: TRect;
|
||||||
ACellHorAlign: TsHorAlignment; ACellVertAlign: TsVertAlignment;
|
ACellHorAlign: TsHorAlignment; ACellVertAlign: TsVertAlignment;
|
||||||
ATextRot: TsTextRotation; ATextWrap: Boolean; AFontIndex: Integer;
|
ATextRot: TsTextRotation; ATextWrap: Boolean; AFontIndex: Integer;
|
||||||
ARichTextParams: TsRichTextParams);
|
AOverrideTextColor: TColor; ARichTextParams: TsRichTextParams);
|
||||||
{
|
{
|
||||||
procedure InternalDrawTextInCell(AText, AMeasureText: String; ARect: TRect;
|
procedure InternalDrawTextInCell(AText, AMeasureText: String; ARect: TRect;
|
||||||
AJustification: Byte; ACellHorAlign: TsHorAlignment;
|
AJustification: Byte; ACellHorAlign: TsHorAlignment;
|
||||||
@ -1437,6 +1437,9 @@ begin
|
|||||||
if fssStrikeout in fnt.Style then Include(style, fsStrikeout);
|
if fssStrikeout in fnt.Style then Include(style, fsStrikeout);
|
||||||
Canvas.Font.Style := style;
|
Canvas.Font.Style := style;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Text color is handled by "InternalDrawRichText"
|
||||||
|
{
|
||||||
// Read text color from number format if available
|
// Read text color from number format if available
|
||||||
if not IsNaN(lCell^.NumberValue) and (numFmt <> nil) then
|
if not IsNaN(lCell^.NumberValue) and (numFmt <> nil) then
|
||||||
begin
|
begin
|
||||||
@ -1452,6 +1455,8 @@ begin
|
|||||||
Canvas.Font.Color := clr and $00FFFFFF;
|
Canvas.Font.Color := clr and $00FFFFFF;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
}
|
||||||
|
|
||||||
// Wordwrap, text alignment and text rotation are handled by "DrawTextInCell".
|
// Wordwrap, text alignment and text rotation are handled by "DrawTextInCell".
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -2089,8 +2094,10 @@ var
|
|||||||
txtRot: TsTextRotation;
|
txtRot: TsTextRotation;
|
||||||
fntIndex: Integer;
|
fntIndex: Integer;
|
||||||
lCell: PCell;
|
lCell: PCell;
|
||||||
// justif: Byte;
|
|
||||||
fmt: PsCellFormat;
|
fmt: PsCellFormat;
|
||||||
|
numfmt: TsNumFormatParams;
|
||||||
|
numFmtColor: TColor;
|
||||||
|
sidx: Integer; // number format section index
|
||||||
begin
|
begin
|
||||||
if (Worksheet = nil) then
|
if (Worksheet = nil) then
|
||||||
exit;
|
exit;
|
||||||
@ -2115,16 +2122,26 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Cells
|
// Cells
|
||||||
|
txt := GetCellText(GetGridRow(lCell^.Col), GetGridCol(lCell^.Row));
|
||||||
|
if txt = '' then
|
||||||
|
exit;
|
||||||
|
|
||||||
fmt := Workbook.GetPointerToCellFormat(lCell^.FormatIndex);
|
fmt := Workbook.GetPointerToCellFormat(lCell^.FormatIndex);
|
||||||
wrapped := (uffWordWrap in fmt^.UsedFormattingFields) or (fmt^.TextRotation = rtStacked);
|
wrapped := (uffWordWrap in fmt^.UsedFormattingFields) or (fmt^.TextRotation = rtStacked);
|
||||||
|
|
||||||
|
// Text rotation
|
||||||
if (uffTextRotation in fmt^.UsedFormattingFields)
|
if (uffTextRotation in fmt^.UsedFormattingFields)
|
||||||
then txtRot := fmt^.TextRotation
|
then txtRot := fmt^.TextRotation
|
||||||
else txtRot := trHorizontal;
|
else txtRot := trHorizontal;
|
||||||
|
|
||||||
|
// vertical alignment
|
||||||
if (uffVertAlign in fmt^.UsedFormattingFields)
|
if (uffVertAlign in fmt^.UsedFormattingFields)
|
||||||
then vertAlign := fmt^.VertAlignment
|
then vertAlign := fmt^.VertAlignment
|
||||||
else vertAlign := vaDefault;
|
else vertAlign := vaDefault;
|
||||||
if vertAlign = vaDefault then
|
if vertAlign = vaDefault then
|
||||||
vertAlign := vaBottom;
|
vertAlign := vaBottom;
|
||||||
|
|
||||||
|
// Horizontal alignment
|
||||||
if (uffHorAlign in fmt^.UsedFormattingFields)
|
if (uffHorAlign in fmt^.UsedFormattingFields)
|
||||||
then horAlign := fmt^.HorAlignment
|
then horAlign := fmt^.HorAlignment
|
||||||
else horAlign := haDefault;
|
else horAlign := haDefault;
|
||||||
@ -2138,54 +2155,34 @@ begin
|
|||||||
else
|
else
|
||||||
horAlign := haLeft;
|
horAlign := haLeft;
|
||||||
end;
|
end;
|
||||||
{
|
|
||||||
fmt^.HorAlignment <> haDefault then
|
|
||||||
horAlign := fmt^.HorAlignment
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
if (lCell^.ContentType in [cctNumber, cctDateTime]) then
|
|
||||||
horAlign := haRight
|
|
||||||
else
|
|
||||||
horAlign := haLeft;
|
|
||||||
end; }
|
|
||||||
|
|
||||||
|
// Font index
|
||||||
if (uffFont in fmt^.UsedFormattingFields)
|
if (uffFont in fmt^.UsedFormattingFields)
|
||||||
then fntIndex := fmt^.FontIndex
|
then fntIndex := fmt^.FontIndex
|
||||||
else fntIndex := DEFAULT_FONTINDEX;
|
else fntIndex := DEFAULT_FONTINDEX;
|
||||||
|
|
||||||
|
// Font color as derived from number format
|
||||||
|
numFmtColor := clNone;
|
||||||
|
if not IsNaN(lCell^.NumberValue) and (uffNumberFormat in fmt^.UsedFormattingFields) then
|
||||||
|
begin
|
||||||
|
numFmt := Workbook.GetNumberFormat(fmt^.NumberFormatIndex);
|
||||||
|
if numFmt <> nil then
|
||||||
|
begin
|
||||||
|
sidx := 0;
|
||||||
|
if (Length(numFmt.Sections) > 1) and (lCell^.NumberValue < 0) then
|
||||||
|
sidx := 1
|
||||||
|
else
|
||||||
|
if (Length(numFmt.Sections) > 2) and (lCell^.NumberValue = 0) then
|
||||||
|
sidx := 2;
|
||||||
|
if (nfkHasColor in numFmt.Sections[sidx].Kind) then
|
||||||
|
numFmtColor := numFmt.Sections[sidx].Color and $00FFFFFF;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
InflateRect(ARect, -constCellPadding, -constCellPadding);
|
InflateRect(ARect, -constCellPadding, -constCellPadding);
|
||||||
|
|
||||||
txt := GetCellText(GetGridRow(lCell^.Col), GetGridCol(lCell^.Row));
|
|
||||||
if txt = '' then
|
|
||||||
exit;
|
|
||||||
{
|
|
||||||
case txtRot of
|
|
||||||
trHorizontal:
|
|
||||||
case horAlign of
|
|
||||||
haLeft : justif := 0;
|
|
||||||
haCenter : justif := 1;
|
|
||||||
haRight : justif := 2;
|
|
||||||
end;
|
|
||||||
rtStacked,
|
|
||||||
rt90DegreeClockwiseRotation:
|
|
||||||
case vertAlign of
|
|
||||||
vaTop : justif := 0;
|
|
||||||
vaCenter: justif := 1;
|
|
||||||
vaBottom: justif := 2;
|
|
||||||
end;
|
|
||||||
rt90DegreeCounterClockwiseRotation:
|
|
||||||
case vertAlign of
|
|
||||||
vaTop : justif := 2;
|
|
||||||
vaCenter: justif := 1;
|
|
||||||
vaBottom: justif := 0;
|
|
||||||
end;
|
|
||||||
end; }
|
|
||||||
InternalDrawTextInCell(txt, ARect, horAlign, vertAlign, txtRot, wrapped,
|
InternalDrawTextInCell(txt, ARect, horAlign, vertAlign, txtRot, wrapped,
|
||||||
fntIndex, lCell^.RichTextParams);
|
fntIndex, numfmtColor, lCell^.RichTextParams);
|
||||||
{
|
|
||||||
InternalDrawTextInCell(txt, txt, ARect, justif, horAlign, vertAlign,
|
|
||||||
txtRot, wrapped, false, lCell^.RichTextParams);
|
|
||||||
}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@ -3158,7 +3155,7 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.InternalDrawTextInCell(AText: String;
|
procedure TsCustomWorksheetGrid.InternalDrawTextInCell(AText: String;
|
||||||
ARect: TRect; ACellHorAlign: TsHorAlignment; ACellVertAlign: TsVertAlignment;
|
ARect: TRect; ACellHorAlign: TsHorAlignment; ACellVertAlign: TsVertAlignment;
|
||||||
ATextRot: TsTextRotation; ATextWrap: Boolean; AFontIndex: Integer;
|
ATextRot: TsTextRotation; ATextWrap: Boolean; AFontIndex: Integer;
|
||||||
ARichTextParams: TsRichTextParams);
|
AOverrideTextColor: TColor; ARichTextParams: TsRichTextParams);
|
||||||
begin
|
begin
|
||||||
// Since - due to the rich-text mode - characters are drawn individually their
|
// Since - due to the rich-text mode - characters are drawn individually their
|
||||||
// background occasionally overpaints the prev characters (italic). To avoid
|
// background occasionally overpaints the prev characters (italic). To avoid
|
||||||
@ -3167,7 +3164,7 @@ begin
|
|||||||
|
|
||||||
// Work horse for text drawing, both standard text and rich-text
|
// Work horse for text drawing, both standard text and rich-text
|
||||||
DrawRichText(Canvas, Workbook, ARect, AText, AFontIndex, ARichTextParams,
|
DrawRichText(Canvas, Workbook, ARect, AText, AFontIndex, ARichTextParams,
|
||||||
ATextWrap, ACellHorAlign, ACellVertAlign, ATextRot);
|
ATextWrap, ACellHorAlign, ACellVertAlign, ATextRot, AOverrideTextColor);
|
||||||
end;
|
end;
|
||||||
(*
|
(*
|
||||||
procedure TsCustomWorksheetGrid.InternalDrawTextInCell(AText, AMeasureText: String;
|
procedure TsCustomWorksheetGrid.InternalDrawTextInCell(AText, AMeasureText: String;
|
||||||
|
@ -19,7 +19,7 @@ function WrapText(ACanvas: TCanvas; const AText: string; AMaxWidth: integer): st
|
|||||||
procedure DrawRichText(ACanvas: TCanvas; AWorkbook: TsWorkbook; const ARect: TRect;
|
procedure DrawRichText(ACanvas: TCanvas; AWorkbook: TsWorkbook; const ARect: TRect;
|
||||||
const AText: String; AFontIndex: Integer; ARichTextParams: TsRichTextParams;
|
const AText: String; AFontIndex: Integer; ARichTextParams: TsRichTextParams;
|
||||||
AWordwrap: Boolean; AHorAlignment: TsHorAlignment; AVertAlignment: TsVertAlignment;
|
AWordwrap: Boolean; AHorAlignment: TsHorAlignment; AVertAlignment: TsVertAlignment;
|
||||||
ARotation: TsTextRotation);
|
ARotation: TsTextRotation; AOverrideTextColor: TColor);
|
||||||
|
|
||||||
function RichTextWidth(ACanvas: TCanvas; AWorkbook: TsWorkbook; AMaxRect: TRect;
|
function RichTextWidth(ACanvas: TCanvas; AWorkbook: TsWorkbook; AMaxRect: TRect;
|
||||||
const AText: String; AFontIndex: Integer; ARichTextParams: TsRichTextParams;
|
const AText: String; AFontIndex: Integer; ARichTextParams: TsRichTextParams;
|
||||||
@ -176,7 +176,8 @@ procedure InternalDrawRichText(ACanvas: TCanvas; AWorkbook: TsWorkbook;
|
|||||||
const ARect: TRect; const AText: String; AFontIndex: Integer;
|
const ARect: TRect; const AText: String; AFontIndex: Integer;
|
||||||
ARichTextParams: TsRichTextParams; AWordwrap: Boolean;
|
ARichTextParams: TsRichTextParams; AWordwrap: Boolean;
|
||||||
AHorAlignment: TsHorAlignment; AVertAlignment: TsVertAlignment;
|
AHorAlignment: TsHorAlignment; AVertAlignment: TsVertAlignment;
|
||||||
ARotation: TsTextRotation; var Width,Height: Integer; AMeasureOnly: Boolean);
|
ARotation: TsTextRotation; AOverrideTextColor: TColor;
|
||||||
|
var Width,Height: Integer; AMeasureOnly: Boolean);
|
||||||
type
|
type
|
||||||
TLineInfo = record
|
TLineInfo = record
|
||||||
pStart, pEnd: PChar;
|
pStart, pEnd: PChar;
|
||||||
@ -376,6 +377,8 @@ var
|
|||||||
while p^ <> #0 do begin
|
while p^ <> #0 do begin
|
||||||
s := UnicodeToUTF8(UTF8CharacterToUnicode(p, charLen));
|
s := UnicodeToUTF8(UTF8CharacterToUnicode(p, charLen));
|
||||||
UpdateFont(p, rtState, PendingRtpIndex, h, fntpos);
|
UpdateFont(p, rtState, PendingRtpIndex, h, fntpos);
|
||||||
|
if AOverrideTextColor <> clNone then
|
||||||
|
ACanvas.Font.Color := AOverrideTextColor;
|
||||||
case ARotation of
|
case ARotation of
|
||||||
trHorizontal:
|
trHorizontal:
|
||||||
begin
|
begin
|
||||||
@ -441,6 +444,7 @@ begin
|
|||||||
linelen := 0;
|
linelen := 0;
|
||||||
|
|
||||||
Convert_sFont_to_Font(AWorkbook.GetFont(AFontIndex), ACanvas.Font);
|
Convert_sFont_to_Font(AWorkbook.GetFont(AFontIndex), ACanvas.Font);
|
||||||
|
|
||||||
if ARotation = rtStacked then
|
if ARotation = rtStacked then
|
||||||
stackPeriod := ACanvas.TextWidth('M') * 2;
|
stackPeriod := ACanvas.TextWidth('M') * 2;
|
||||||
|
|
||||||
@ -565,13 +569,13 @@ end;
|
|||||||
procedure DrawRichText(ACanvas: TCanvas; AWorkbook: TsWorkbook; const ARect: TRect;
|
procedure DrawRichText(ACanvas: TCanvas; AWorkbook: TsWorkbook; const ARect: TRect;
|
||||||
const AText: String; AFontIndex: Integer; ARichTextParams: TsRichTextParams;
|
const AText: String; AFontIndex: Integer; ARichTextParams: TsRichTextParams;
|
||||||
AWordwrap: Boolean; AHorAlignment: TsHorAlignment; AVertAlignment: TsVertAlignment;
|
AWordwrap: Boolean; AHorAlignment: TsHorAlignment; AVertAlignment: TsVertAlignment;
|
||||||
ARotation: TsTextRotation);
|
ARotation: TsTextRotation; AOverrideTextColor: TColor);
|
||||||
var
|
var
|
||||||
w,h: Integer;
|
w,h: Integer;
|
||||||
begin
|
begin
|
||||||
InternalDrawRichText(ACanvas, AWorkbook, ARect, AText, AFontIndex,
|
InternalDrawRichText(ACanvas, AWorkbook, ARect, AText, AFontIndex,
|
||||||
ARichTextParams, AWordWrap, AHorAlignment, AVertAlignment, ARotation,
|
ARichTextParams, AWordWrap, AHorAlignment, AVertAlignment, ARotation,
|
||||||
w, h, false);
|
AOverrideTextColor, w, h, false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RichTextWidth(ACanvas: TCanvas; AWorkbook: TsWorkbook; AMaxRect: TRect;
|
function RichTextWidth(ACanvas: TCanvas; AWorkbook: TsWorkbook; AMaxRect: TRect;
|
||||||
@ -581,7 +585,7 @@ var
|
|||||||
h, w: Integer;
|
h, w: Integer;
|
||||||
begin
|
begin
|
||||||
InternalDrawRichText(ACanvas, AWorkbook, AMaxRect, AText, AFontIndex,
|
InternalDrawRichText(ACanvas, AWorkbook, AMaxRect, AText, AFontIndex,
|
||||||
ARichTextParams, AWordWrap, haLeft, vaTop, ATextRotation,
|
ARichTextParams, AWordWrap, haLeft, vaTop, ATextRotation, clNone,
|
||||||
w, h, true);
|
w, h, true);
|
||||||
case ATextRotation of
|
case ATextRotation of
|
||||||
trHorizontal, rtStacked:
|
trHorizontal, rtStacked:
|
||||||
@ -598,7 +602,7 @@ var
|
|||||||
h, w: Integer;
|
h, w: Integer;
|
||||||
begin
|
begin
|
||||||
InternalDrawRichText(ACanvas, AWorkbook, AMaxRect, AText, AFontIndex,
|
InternalDrawRichText(ACanvas, AWorkbook, AMaxRect, AText, AFontIndex,
|
||||||
ARichTextParams, AWordWrap, haLeft, vaTop, ATextRotation,
|
ARichTextParams, AWordWrap, haLeft, vaTop, ATextRotation, clNone,
|
||||||
w, h, true);
|
w, h, true);
|
||||||
case ATextRotation of
|
case ATextRotation of
|
||||||
trHorizontal:
|
trHorizontal:
|
||||||
|
Reference in New Issue
Block a user