fpspreadsheet: Add haJustify as new horizontal alignment option.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9347 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-05-09 17:08:43 +00:00
parent 8fdb399acd
commit 611cd2c347
12 changed files with 77 additions and 51 deletions

View File

@ -67,6 +67,7 @@
</Parsing>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
<UseExternalDbgSyms Value="True"/>
</Debugging>
<Options>

View File

@ -897,9 +897,9 @@ begin
'left' : FCurrCellFormat.HorAlignment := haLeft;
'center' : FCurrCellFormat.HorAlignment := haCenter;
'right' : FCurrCellFormat.HorAlignment := haRight;
'justify': FCurrCellFormat.HorAlignment := haJustify;
// -- not implemented in fps
// 'justify'
// 'char"
// 'char'
else exit;
end;
Include(FCurrCellFormat.UsedFormattingFields, uffHorAlign);
@ -1382,6 +1382,7 @@ begin
haLeft : Result := 'text-align:left;';
haCenter : Result := 'text-align:center;';
haRight : Result := 'text-align:right;';
haJustify: Result := 'text-align:justify;';
end;
end;

View File

@ -5273,21 +5273,22 @@ var
begin
// Horizontal text alignment
s := GetAttrValue(ANode, 'fo:text-align');
if s = 'start' then
AFormat.HorAlignment := haLeft
else if s = 'end' then
AFormat.HorAlignment := haRight
else if s = 'center' then
AFormat.HorAlignment := haCenter;
case s of
'start' : AFormat.HorAlignment := haLeft;
'end' : AFormat.HorAlignment := haRight;
'center' : AFormat.HorAlignment := haCenter;
'justify': AFormat.HorAlignment := haJustify;
else AFormat.HorAlignment := haDefault;
end;
if AFormat.HorAlignment <> haDefault then
Include(AFormat.UsedFormattingFields, uffHorAlign);
// BiDi mode
s := GetAttrValue(ANode, 'style:writing-mode');
if s = 'lr-tb' then
AFormat.BiDiMode := bdRTL
else if s = 'rl-tb' then
AFormat.BiDiMode := bdRTL;
case s of
'lr-tb': AFormat.BiDiMode := bdRTL;
'rl-tb': AFormat.BiDiMode := bdRTL;
end;
if AFormat.BiDiMode <> bdDefault then
Include(AFormat.UsedFormattingFields, uffBiDi);
end;
@ -8841,6 +8842,7 @@ begin
haLeft : Result := 'fo:text-align="start" ';
haCenter : Result := 'fo:text-align="center" ';
haRight : Result := 'fo:text-align="end" ';
haJustify: Result := 'fo:text-align="justify" ';
end;
end;

View File

@ -507,8 +507,9 @@ type
@value haDefault Default text alignment (left for alphanumeric, right for numbers and dates)
@value haLeft Left-aligned cell text
@value haCenter Centered cell text
@value haRight Right-aligned cell text }
TsHorAlignment = (haDefault, haLeft, haCenter, haRight);
@value haRight Right-aligned cell text
@value haJustify Adjust spaces to fill entire cell width. }
TsHorAlignment = (haDefault, haLeft, haCenter, haRight, haJustify);
{@@ Indicates vertical text alignment in cells
@value vaDefault Default vertical alignment (bottom)

View File

@ -700,12 +700,14 @@ begin
BIFF3: w := WordLEToN(rec.Align_TextBreak_ParentXF_3) and MASK_XF_HOR_ALIGN;
BIFF4: w := rec.Align_TextBreak_Orientation_4 AND MASK_XF_HOR_ALIGN;
end;
if (w <= ord(High(TsHorAlignment))) then
begin
fmt.HorAlignment := TsHorAlignment(w);
if fmt.HorAlignment <> haDefault then
Include(fmt.UsedFormattingFields, uffHorAlign);
case w of
MASK_XF_HOR_ALIGN_LEFT : fmt.HorAlignment := haLeft;
MASK_XF_HOR_ALIGN_CENTER : fmt.HorAlignment := haCenter;
MASK_XF_HOR_ALIGN_RIGHT : fmt.HorAlignment := haRight;
MASK_XF_HOR_ALIGN_JUSTIFIED: fmt.HorAlignment := haJustify;
end;
if fmt.HorAlignment <> haDefault then
Include(fmt.UsedFormattingFields, uffHorAlign);
// Vertical text alignment
if FFormat = BIFF4 then

View File

@ -888,12 +888,15 @@ begin
// Horizontal text alignment
b := rec.Align_TextBreak AND MASK_XF_HOR_ALIGN;
if (b <= ord(High(TsHorAlignment))) then
begin
fmt.HorAlignment := TsHorAlignment(b);
if fmt.HorAlignment <> haDefault then
Include(fmt.UsedFormattingFields, uffHorAlign);
b := rec.Align_TextBreak AND MASK_XF_HOR_ALIGN;
case b of
MASK_XF_HOR_ALIGN_LEFT : fmt.HorAlignment := haLeft;
MASK_XF_HOR_ALIGN_CENTER : fmt.HorAlignment := haCenter;
MASK_XF_HOR_ALIGN_RIGHT : fmt.HorAlignment := haRight;
MASK_XF_HOR_ALIGN_JUSTIFIED: fmt.HorAlignment := haJustify;
end;
if fmt.HorAlignment <> haDefault then
Include(fmt.UsedFormattingFields, uffHorAlign);
// Vertical text alignment
b := (rec.Align_TextBreak AND MASK_XF_VERT_ALIGN) shr 4;
@ -2250,6 +2253,7 @@ begin
haLeft : b := b or MASK_XF_HOR_ALIGN_LEFT;
haCenter : b := b or MASK_XF_HOR_ALIGN_CENTER;
haRight : b := b or MASK_XF_HOR_ALIGN_RIGHT;
haJustify: b := b or MASK_XF_HOR_ALIGN_JUSTIFIED;
haDefault: ;
end;
// Since the default vertical alignment is vaDefault but "0" corresponds

View File

@ -2011,12 +2011,14 @@ begin
// Horizontal text alignment
b := rec.Align_TextBreak AND MASK_XF_HOR_ALIGN;
if (b <= ord(High(TsHorAlignment))) then
begin
fmt.HorAlignment := TsHorAlignment(b);
if fmt.HorAlignment <> haDefault then
Include(fmt.UsedFormattingFields, uffHorAlign);
case b of
MASK_XF_HOR_ALIGN_LEFT : fmt.HorAlignment := haLeft;
MASK_XF_HOR_ALIGN_CENTER : fmt.HorAlignment := haCenter;
MASK_XF_HOR_ALIGN_RIGHT : fmt.HorAlignment := haRight;
MASK_XF_HOR_ALIGN_JUSTIFIED: fmt.HorAlignment := haJustify;
end;
if fmt.HorAlignment <> haDefault then
Include(fmt.UsedFormattingFields, uffHorAlign);
// Vertical text alignment
b := (rec.Align_TextBreak AND MASK_XF_VERT_ALIGN) shr 4;
@ -3096,9 +3098,11 @@ procedure TsSpreadBIFF8Writer.WriteComments(AStream: TStream;
var
index: Integer;
comment: PsComment;
c: Pscomment;
sheet: TsWorksheet;
begin
exit; // Remove after comments can be written correctly
(*
exit; // Remove after comments can be written correctly
{$warning TODO: Fix writing of cell comments in BIFF8 (file is readable by OpenOffice, but not by Excel)}
sheet := AWorksheet as TsWorksheet;
@ -3125,6 +3129,7 @@ begin
WriteNOTE(AStream, comment, index);
inc(index);
end;
*)
end;
{@@ ----------------------------------------------------------------------------
@ -4941,6 +4946,7 @@ begin
haLeft : b := b or MASK_XF_HOR_ALIGN_LEFT;
haCenter : b := b or MASK_XF_HOR_ALIGN_CENTER;
haRight : b := b or MASK_XF_HOR_ALIGN_RIGHT;
haJustify: b := b or MASK_XF_HOR_ALIGN_JUSTIFIED;
end;
// Since the default vertical alignment is vaDefault but "0" corresponds
// to vaTop, we alwys have to write the vertical alignment.

View File

@ -525,6 +525,8 @@ begin
HorAlignment := haCenter;
'Right':
HorAlignment := haRight;
'Justify':
HorAlignment := haJustify;
else
Exclude(UsedFormattingFields, uffHorAlign);
end;
@ -3261,6 +3263,7 @@ begin
haLeft : fmtHor := 'ss:Horizontal="Left" ';
haCenter : fmtHor := 'ss:Horizontal="Center" ';
haRight : fmtHor := 'ss:Horizontal="Right" ';
haJustify: fmtHor := 'ss:Horizontal="Justify" ';
else
raise EFPSpreadsheetWriter.Create('[TsSpreadXMLWriter.WriteStyle] Horizontal alignment cannot be handled.');
end;

View File

@ -1492,24 +1492,21 @@ begin
nodeName := childNode.NodeName;
if (nodeName = 'alignment') or (nodeName = 'x:alignment') then begin
s1 := GetAttrValue(childNode, 'horizontal');
if s1 = 'left' then
fmt.HorAlignment := haLeft
else
if s1 = 'center' then
fmt.HorAlignment := haCenter
else
if s1 = 'right' then
fmt.HorAlignment := haRight;
case s1 of
'left' : fmt.HorAlignment := haLeft;
'center' : fmt.HorAlignment := haCenter;
'right' : fmt.HorAlignment := haRight;
'justify': fmt.HorAlignment := haJustify;
else fmt.HorAlignment := haDefault;
end;
s1 := GetAttrValue(childNode, 'vertical');
if s1 = 'top' then
fmt.VertAlignment := vaTop
else
if s1 = 'center' then
fmt.VertAlignment := vaCenter
else
if s1 = 'bottom' then
fmt.VertAlignment := vaBottom;
case s1 of
'top': fmt.VertAlignment := vaTop;
'center': fmt.VertAlignment := vaCenter;
'bottom': fmt.VertAlignment := vaBottom;
else fmt.VertAlignment := vaDefault;
end;
s1 := GetAttrValue(childNode, 'readingOrder');
if (s1 = '1') or (s1 = '2') then
@ -6364,9 +6361,10 @@ begin
if (uffHorAlign in AFormat^.UsedFormattingFields) and (AFormat^.HorAlignment <> haDefault)
then
case AFormat^.HorAlignment of
haLeft : sAlign := sAlign + 'horizontal="left" ';
haCenter: sAlign := sAlign + 'horizontal="center" ';
haRight : sAlign := sAlign + 'horizontal="right" ';
haLeft : sAlign := sAlign + 'horizontal="left" ';
haCenter : sAlign := sAlign + 'horizontal="center" ';
haRight : sAlign := sAlign + 'horizontal="right" ';
haJustify: sAlign := sAlign + 'horizontal="justify" ';
end;
if (uffVertAlign in AFormat^.UsedFormattingFields) and (AFormat^.VertAlignment <> vaDefault)

View File

@ -1760,7 +1760,9 @@ begin
ACol2 := ACol;
r := GetWorksheetRow(ARow);
case txtalign of
haLeft, haDefault:
haLeft,
haJustify, // to do: get a separate option for haJustify; adjust widths of spaces to fill the entire cell.
haDefault:
// overflow to the right
while (len > ARect.Right - ARect.Left) and (ACol2 < ColCount-1) do
begin

View File

@ -458,12 +458,14 @@ begin
// xpos is x coordinate of left edge of first character
if FRightToLeft then
case FHorAlignment of
haJustify,
haLeft : xpos := FRect.Left + lineinfo.Width;
haCenter : xpos := (FRect.Left + FRect.Right + lineinfo.Width) div 2;
haRight : xpos := FRect.Right;
end
else
case FHorAlignment of
haJustify,
haLeft : xpos := FRect.Left;
haCenter : xpos := (FRect.Left + FRect.Right - lineinfo.Width) div 2;
haRight : xpos := FRect.Right - lineinfo.Width;
@ -536,12 +538,14 @@ begin
dx := lineInfo.Height;
if FRightToLeft then
case FHorAlignment of
haJustify,
haLeft : xpos := FRect.Left + FTotalHeight + dx;
haCenter : xpos := (FRect.Left + FRect.Right + FTotalHeight) div 2 - dx;
haRight : xpos := FRect.Right - dx;
end
else
case FHorAlignment of
haJustify,
haLeft : xpos := FRect.Left + dx;
haCenter : xpos := (FRect.Left + FRect.Right - FTotalHeight) div 2;
haRight : xpos := FRect.Right - FTotalHeight + dx;
@ -656,6 +660,7 @@ begin
w := FCanvas.TextWidth(ch);
// x is at the center of the character here
case FHorAlignment of
haJustify,
haLeft : FCanvas.TextOut(Pt.x - w div 2, Pt.y, ch);
haCenter : FCanvas.TextOut(Pt.x - w div 2, Pt.y, ch);
haRight : FCanvas.TextOut(Pt.x - w div 2, Pt.y, ch);
@ -679,6 +684,7 @@ var
begin
// (1) Get starting point
case FHorAlignment of
haJustify,
haLeft : xpos := IfThen(AClockwise, FRect.Left + FTotalHeight, FRect.Left);
haCenter : xpos := (FRect.Left + FRect.Right + FTotalHeight*SGN[AClockwise]) div 2;
haRight : xpos := IfThen(AClockwise, FRect.Right, FRect.Right - FTotalHeight);

View File

@ -608,7 +608,7 @@ end;
procedure TSpreadWriteReadFormatTests.TestWriteRead_Alignment(AFormat: TsSpreadsheetFormat);
const
HORALIGN_TEXT: Array[TsHorAlignment] of String = ('haDefault', 'haLeft', 'haCenter', 'haRight');
HORALIGN_TEXT: Array[TsHorAlignment] of String = ('haDefault', 'haLeft', 'haCenter', 'haRight', 'haJustify');
VERTALIGN_TEXT: Array[TsVertAlignment] of String = ('vaDefault', 'vaTop', 'vaCenter', 'vaBottom');
var
MyWorksheet: TsWorksheet;