mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-06 13:45:56 +02:00
fpvectorial: Now the table contents already render as they should
git-svn-id: trunk@47856 -
This commit is contained in:
parent
69febc0389
commit
f198c69aea
@ -1018,6 +1018,7 @@ type
|
|||||||
TvRichText = class(TvEntityWithSubEntities)
|
TvRichText = class(TvEntityWithSubEntities)
|
||||||
public
|
public
|
||||||
Width, Height: Double;
|
Width, Height: Double;
|
||||||
|
SpacingLeft, SpacingRight, SpacingTop, SpacingBottom: Double; // space around each side
|
||||||
AutoExpand: TvRichTextAutoExpand;
|
AutoExpand: TvRichTextAutoExpand;
|
||||||
constructor Create(APage: TvPage); override;
|
constructor Create(APage: TvPage); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -1028,8 +1029,8 @@ type
|
|||||||
function AddEmbeddedVectorialDoc: TvEmbeddedVectorialDoc;
|
function AddEmbeddedVectorialDoc: TvEmbeddedVectorialDoc;
|
||||||
function AddRasterImage: TvRasterImage;
|
function AddRasterImage: TvRasterImage;
|
||||||
// Functions for rendering and calculating sizes
|
// Functions for rendering and calculating sizes
|
||||||
function CalculateCellHeight_ForWidth(ADest: TFPCustomCanvas; AWidth: Double): Double;
|
function CalculateCellHeight_ForWidth(ADest: TFPCustomCanvas; AWidth: Double): Double; virtual;
|
||||||
//
|
function CalculateMaxNeededWidth(ADest: TFPCustomCanvas): Double; virtual;
|
||||||
function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override;
|
function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override;
|
||||||
procedure Render(ADest: TFPCustomCanvas; var ARenderInfo: TvRenderInfo; ADestX: Integer = 0;
|
procedure Render(ADest: TFPCustomCanvas; var ARenderInfo: TvRenderInfo; ADestX: Integer = 0;
|
||||||
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
|
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
|
||||||
@ -1078,11 +1079,11 @@ type
|
|||||||
// added to TvRichText if odt supports paragraph
|
// added to TvRichText if odt supports paragraph
|
||||||
// borders, in which case we can refactor a little and
|
// borders, in which case we can refactor a little and
|
||||||
// rename TvTableBorders
|
// rename TvTableBorders
|
||||||
Borders : TvTableBorders; // Defaults to be ignored (tbtDefault)
|
Borders: TvTableBorders; // Defaults to be ignored (tbtDefault)
|
||||||
PreferredWidth : TvDimension; // Optional
|
PreferredWidth: TvDimension; // Optional
|
||||||
VerticalAlignment : TvVerticalAlignment; // Defaults to vaTop
|
VerticalAlignment: TvVerticalAlignment; // Defaults to vaTop
|
||||||
BackgroundColor : TFPColor; // Optional
|
BackgroundColor: TFPColor; // Optional
|
||||||
SpannedCols : Integer; // For merging horiz cells. Default 1.
|
SpannedCols: Integer; // For merging horiz cells. Default 1.
|
||||||
// See diagram above TvTable Class
|
// See diagram above TvTable Class
|
||||||
|
|
||||||
constructor Create(APage: TvPage); override;
|
constructor Create(APage: TvPage); override;
|
||||||
@ -1092,22 +1093,26 @@ type
|
|||||||
|
|
||||||
TvTableRow = Class(TvNamedEntity)
|
TvTableRow = Class(TvNamedEntity)
|
||||||
private
|
private
|
||||||
Cells : TFPList;
|
Cells: TFPList; // of TvTableCell
|
||||||
Public
|
Public
|
||||||
Height : Double; // Units mm. Use 0 for default height
|
Table: TvTable; // Link to the parent table
|
||||||
|
Height: Double; // Units mm. Use 0 for default height
|
||||||
CellSpacing : Double; // Units mm. Gap between Cells.
|
CellSpacing : Double; // Units mm. Gap between Cells.
|
||||||
|
|
||||||
Header : Boolean; // Repeat row across pages
|
Header: Boolean; // Repeat row across pages
|
||||||
AllowSplitAcrossPage : Boolean; // Can this Row split across multiple pages?
|
AllowSplitAcrossPage : Boolean;// Can this Row split across multiple pages?
|
||||||
BackgroundColor : TFPColor; // Optional
|
BackgroundColor : TFPColor; // Optional
|
||||||
|
|
||||||
constructor create(APage : TvPage); override;
|
constructor create(APage : TvPage); override;
|
||||||
destructor destroy; override;
|
destructor destroy; override;
|
||||||
|
|
||||||
function AddCell : TvTableCell;
|
function AddCell: TvTableCell;
|
||||||
function GetCellCount: Integer;
|
function GetCellCount: Integer;
|
||||||
function GetCell(AIndex: Integer) : TvTableCell;
|
function GetCell(AIndex: Integer): TvTableCell;
|
||||||
//
|
//
|
||||||
|
procedure CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double); override;
|
||||||
|
procedure Render(ADest: TFPCustomCanvas; var ARenderInfo: TvRenderInfo; ADestX: Integer = 0;
|
||||||
|
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
|
||||||
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override;
|
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1666,6 +1671,11 @@ begin
|
|||||||
Borders.InsideHoriz.LineType:=tbtDefault;
|
Borders.InsideHoriz.LineType:=tbtDefault;
|
||||||
Borders.InsideVert.LineType:=tbtDefault;
|
Borders.InsideVert.LineType:=tbtDefault;
|
||||||
|
|
||||||
|
SpacingLeft := 2;
|
||||||
|
SpacingRight := 2;
|
||||||
|
SpacingTop := 2;
|
||||||
|
SpacingBottom := 2;
|
||||||
|
|
||||||
SpannedCols := 1;
|
SpannedCols := 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1676,8 +1686,10 @@ procedure TvTable.CalculateColWidths(ADest: TFPCustomCanvas);
|
|||||||
var
|
var
|
||||||
CurRow: TvTableRow;
|
CurRow: TvTableRow;
|
||||||
CurCell: TvTableCell;
|
CurCell: TvTableCell;
|
||||||
lLeft, lTop, lRight, lBottom: Double;
|
lLeft, lTop, lRight, lBottom, lWidth: Double;
|
||||||
col, row: Integer;
|
col, row: Integer;
|
||||||
|
//DebugStr: string;
|
||||||
|
OriginalColWidthsInMM: array of Double;
|
||||||
begin
|
begin
|
||||||
SetLength(ColWidthsInMM, GetRowCount());
|
SetLength(ColWidthsInMM, GetRowCount());
|
||||||
|
|
||||||
@ -1690,6 +1702,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Process initial value for non-predefined widths
|
// Process initial value for non-predefined widths
|
||||||
|
OriginalColWidthsInMM := Copy(ColWidthsInMM, 0, Length(ColWidthsInMM));
|
||||||
TableWidth := 0;
|
TableWidth := 0;
|
||||||
for row := 0 to GetRowCount()-1 do
|
for row := 0 to GetRowCount()-1 do
|
||||||
begin
|
begin
|
||||||
@ -1698,15 +1711,16 @@ begin
|
|||||||
for col := 0 to CurRow.GetCellCount()-1 do
|
for col := 0 to CurRow.GetCellCount()-1 do
|
||||||
begin
|
begin
|
||||||
CurCell := CurRow.GetCell(col);
|
CurCell := CurRow.GetCell(col);
|
||||||
|
//DebugStr := ((CurCell.GetFirstEntity() as TvParagraph).GetFirstEntity() as TvText).Value.Text;
|
||||||
|
|
||||||
if ColWidthsInMM[col] > 0 then
|
if OriginalColWidthsInMM[col] > 0 then
|
||||||
begin
|
begin
|
||||||
TableWidth := TableWidth + ColWidthsInMM[col];
|
TableWidth := TableWidth + ColWidthsInMM[col];
|
||||||
Continue;
|
Continue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
CurRow.CalculateBoundingBox(ADest, lLeft, lTop, lRight, lBottom);
|
lWidth := CurCell.CalculateMaxNeededWidth(ADest);
|
||||||
ColWidthsInMM[col] := Max(ColWidthsInMM[col], lRight);
|
ColWidthsInMM[col] := Max(ColWidthsInMM[col], lWidth);
|
||||||
TableWidth := TableWidth + ColWidthsInMM[col];
|
TableWidth := TableWidth + ColWidthsInMM[col];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1769,6 +1783,7 @@ end;
|
|||||||
function TvTable.AddRow: TvTableRow;
|
function TvTable.AddRow: TvTableRow;
|
||||||
begin
|
begin
|
||||||
Result := TvTableRow.create(FPage);
|
Result := TvTableRow.create(FPage);
|
||||||
|
Result.Table := Self;
|
||||||
Rows.Add(result);
|
Rows.Add(result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2140,6 +2155,42 @@ begin
|
|||||||
Result := TvTableCell(Cells[AIndex]);
|
Result := TvTableCell(Cells[AIndex]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TvTableRow.CalculateBoundingBox(ADest: TFPCustomCanvas; var ALeft, ATop, ARight, ABottom: Double);
|
||||||
|
begin
|
||||||
|
ALeft := X;
|
||||||
|
ATop := Y;
|
||||||
|
ARight := X + FPage.Width;
|
||||||
|
ABottom := Y + Height;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TvTableRow.Render(ADest: TFPCustomCanvas; var ARenderInfo: TvRenderInfo; ADestX: Integer = 0;
|
||||||
|
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||||
|
|
||||||
|
function CoordToCanvasX(ACoord: Double): Integer;
|
||||||
|
begin
|
||||||
|
Result := Round(ADestX + AmulX * ACoord);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CoordToCanvasY(ACoord: Double): Integer;
|
||||||
|
begin
|
||||||
|
Result := Round(ADestY + AmulY * ACoord);
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
CurCell: TvTableCell;
|
||||||
|
i: Integer;
|
||||||
|
CurX: Double = 0.0;
|
||||||
|
begin
|
||||||
|
for i := 0 to GetCellCount()-1 do
|
||||||
|
begin
|
||||||
|
CurCell := GetCell(i);
|
||||||
|
CurCell.X := CurX;
|
||||||
|
CurCell.Render(ADest, ARenderInfo, ADestX, ADestY, AMulX, AMulY);
|
||||||
|
if (Table <> nil) and (Length(Table.ColWidthsInMM) > i) then
|
||||||
|
CurX := CurX + Table.ColWidthsInMM[i];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TvTableRow.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc;
|
function TvTableRow.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc;
|
||||||
APageItem: Pointer): Pointer;
|
APageItem: Pointer): Pointer;
|
||||||
var
|
var
|
||||||
@ -5688,6 +5739,17 @@ end;
|
|||||||
|
|
||||||
procedure TvParagraph.Render(ADest: TFPCustomCanvas; var ARenderInfo: TvRenderInfo;
|
procedure TvParagraph.Render(ADest: TFPCustomCanvas; var ARenderInfo: TvRenderInfo;
|
||||||
ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double);
|
ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double);
|
||||||
|
|
||||||
|
function CoordToCanvasX(ACoord: Double): Integer;
|
||||||
|
begin
|
||||||
|
Result := Round(ADestX + AmulX * ACoord);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CoordToCanvasY(ACoord: Double): Integer;
|
||||||
|
begin
|
||||||
|
Result := Round(ADestY + AmulY * ACoord);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
lCurWidth: Double = 0.0;
|
lCurWidth: Double = 0.0;
|
||||||
lLeft, lTop, lRight, lBottom: Double;
|
lLeft, lTop, lRight, lBottom: Double;
|
||||||
@ -5722,7 +5784,7 @@ begin
|
|||||||
|
|
||||||
OldTextX := lText.X;
|
OldTextX := lText.X;
|
||||||
OldTextY := lText.Y;
|
OldTextY := lText.Y;
|
||||||
lText.X := lText.X + X + lCurWidth;
|
lText.X := CoordToCanvasX(lText.X + X + lCurWidth);
|
||||||
lText.Y := lText.Y + Y;
|
lText.Y := lText.Y + Y;
|
||||||
lText.Render_Use_NextText_X := not lFirstText;
|
lText.Render_Use_NextText_X := not lFirstText;
|
||||||
if lText.Render_Use_NextText_X then
|
if lText.Render_Use_NextText_X then
|
||||||
@ -5863,6 +5925,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
lEntity := GetNextEntity();
|
lEntity := GetNextEntity();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Result := Result + SpacingTop + SpacingBottom;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TvRichText.CalculateMaxNeededWidth(ADest: TFPCustomCanvas): Double;
|
||||||
|
var
|
||||||
|
lLeft, lTop, lRight, lBottom: Double;
|
||||||
|
lEntity: TvEntity;
|
||||||
|
lParagraph: TvParagraph absolute lEntity;
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
|
||||||
|
// if the width is not yet known, calculate it
|
||||||
|
if Width <= 0 then
|
||||||
|
begin
|
||||||
|
lEntity := GetFirstEntity();
|
||||||
|
while lEntity <> nil do
|
||||||
|
begin
|
||||||
|
if lEntity is TvParagraph then
|
||||||
|
begin
|
||||||
|
lParagraph.X := X;
|
||||||
|
lParagraph.Y := Y + Result;
|
||||||
|
lParagraph.CalculateBoundingBox(ADest, lLeft, lTop, lRight, lBottom);
|
||||||
|
Result := Max(Result, (lRight - lLeft));
|
||||||
|
end;
|
||||||
|
lEntity := GetNextEntity();
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := Result + SpacingLeft + SpacingRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TvRichText.TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult;
|
function TvRichText.TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult;
|
||||||
|
@ -226,7 +226,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
CurCell := CurRow.AddCell();
|
CurCell := CurRow.AddCell();
|
||||||
CurCellPara := CurCell.AddParagraph();
|
CurCellPara := CurCell.AddParagraph();
|
||||||
CurCellPara.Style := ADoc.StyleHeading4;
|
CurCellPara.Style := ADoc.StyleTextSpanBold;
|
||||||
CurCellPara.AddText(GetTextContentFromNode(lCurNode));
|
CurCellPara.AddText(GetTextContentFromNode(lCurNode));
|
||||||
end;
|
end;
|
||||||
'td':
|
'td':
|
||||||
|
Loading…
Reference in New Issue
Block a user