mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 03:41:41 +02:00
fpvectorial: Starts adding support for styles
git-svn-id: trunk@42245 -
This commit is contained in:
parent
45db0258ac
commit
e9a3b8461f
@ -12,24 +12,24 @@ program fpvtextwritetest;
|
|||||||
uses
|
uses
|
||||||
fpvectorial, odtvectorialwriter, fpvutils, fpvectorialpkg;
|
fpvectorial, odtvectorialwriter, fpvutils, fpvectorialpkg;
|
||||||
|
|
||||||
|
{$R *.res}
|
||||||
|
|
||||||
var
|
var
|
||||||
Vec: TvVectorialDocument;
|
Vec: TvVectorialDocument;
|
||||||
Page: TvTextPageSequence;
|
Page: TvTextPageSequence;
|
||||||
|
CurParagraph: TvRichText;
|
||||||
{$R *.res}
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Vec := TvVectorialDocument.Create;
|
Vec := TvVectorialDocument.Create;
|
||||||
try
|
try
|
||||||
// A4 -> 210mm x 297mm
|
// A4 -> 210mm x 297mm
|
||||||
Vec.Width := 210;
|
Vec.Width := 210;
|
||||||
Vec.Height := 297;
|
Vec.Height := 297;
|
||||||
Page := Vec.AddTextPageSequence();
|
Vec.AddStandardTextDocumentStyles();
|
||||||
|
|
||||||
// First page sequence
|
// First page sequence
|
||||||
{Page.StartPath(0, 20);
|
Page := Vec.AddTextPageSequence();
|
||||||
Page.AddLineToPath(30, 30);
|
CurParagraph := Page.AddParagraph();
|
||||||
Page.EndPath();}
|
|
||||||
|
|
||||||
Vec.WriteToFile('text_output.odt', vfODT);
|
Vec.WriteToFile('text_output.odt', vfODT);
|
||||||
finally
|
finally
|
||||||
|
@ -132,10 +132,20 @@ type
|
|||||||
TvSetPenBrushAndFontElement = (
|
TvSetPenBrushAndFontElement = (
|
||||||
spbfPenColor, spbfPenStyle, spbfPenWidth,
|
spbfPenColor, spbfPenStyle, spbfPenWidth,
|
||||||
spbfBrushColor, spbfBrushStyle, spbfBrushGradient,
|
spbfBrushColor, spbfBrushStyle, spbfBrushGradient,
|
||||||
spbfFontColor, spbfFontSize
|
spbfFontColor, spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic
|
||||||
);
|
);
|
||||||
TvSetPenBrushAndFontElements = set of TvSetPenBrushAndFontElement;
|
TvSetPenBrushAndFontElements = set of TvSetPenBrushAndFontElement;
|
||||||
|
|
||||||
|
TvStyle = class
|
||||||
|
Name: string;
|
||||||
|
Pen: TvPen;
|
||||||
|
Brush: TvBrush;
|
||||||
|
Font: TvFont;
|
||||||
|
SetElements: TvSetPenBrushAndFontElements;
|
||||||
|
//
|
||||||
|
MarginTop, MarginBottom, MarginLeft, MarginRight: Double; // in mm
|
||||||
|
end;
|
||||||
|
|
||||||
{ Coordinates and polyline segments }
|
{ Coordinates and polyline segments }
|
||||||
|
|
||||||
T3DPoint = record
|
T3DPoint = record
|
||||||
@ -770,8 +780,10 @@ type
|
|||||||
public
|
public
|
||||||
Width, Height: Double;
|
Width, Height: Double;
|
||||||
AutoExpand: TvRichTextAutoExpand;
|
AutoExpand: TvRichTextAutoExpand;
|
||||||
|
Style: string;
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
function AddText: TvText;
|
||||||
function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override;
|
function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override;
|
||||||
procedure Render(ADest: TFPCustomCanvas; ARenderInfo: TvRenderInfo; ADestX: Integer = 0;
|
procedure Render(ADest: TFPCustomCanvas; 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;
|
||||||
@ -784,6 +796,7 @@ type
|
|||||||
private
|
private
|
||||||
FOnProgress: TvProgressEvent;
|
FOnProgress: TvProgressEvent;
|
||||||
FPages: TFPList;
|
FPages: TFPList;
|
||||||
|
FStyles: TFPList;
|
||||||
FCurrentPageIndex: Integer;
|
FCurrentPageIndex: Integer;
|
||||||
function CreateVectorialWriter(AFormat: TvVectorialFormat): TvCustomVectorialWriter;
|
function CreateVectorialWriter(AFormat: TvVectorialFormat): TvCustomVectorialWriter;
|
||||||
function CreateVectorialReader(AFormat: TvVectorialFormat): TvCustomVectorialReader;
|
function CreateVectorialReader(AFormat: TvVectorialFormat): TvCustomVectorialReader;
|
||||||
@ -820,6 +833,11 @@ type
|
|||||||
procedure SetCurrentPage(AIndex: Integer);
|
procedure SetCurrentPage(AIndex: Integer);
|
||||||
function AddPage(): TvVectorialPage;
|
function AddPage(): TvVectorialPage;
|
||||||
function AddTextPageSequence(): TvTextPageSequence;
|
function AddTextPageSequence(): TvTextPageSequence;
|
||||||
|
{ Style methods }
|
||||||
|
function AddStyle(): TvStyle;
|
||||||
|
procedure AddStandardTextDocumentStyles;
|
||||||
|
function GetStyleCount: Integer;
|
||||||
|
function GetStyle(AIndex: Integer): TvStyle;
|
||||||
{ Data removing methods }
|
{ Data removing methods }
|
||||||
procedure Clear; virtual;
|
procedure Clear; virtual;
|
||||||
{ Debug methods }
|
{ Debug methods }
|
||||||
@ -926,6 +944,8 @@ type
|
|||||||
constructor Create(AOwner: TvVectorialDocument); override;
|
constructor Create(AOwner: TvVectorialDocument); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Assign(ASource: TvVectorialPage); override;
|
procedure Assign(ASource: TvVectorialPage); override;
|
||||||
|
{ Data writing methods }
|
||||||
|
function AddParagraph: TvRichText;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ TvVectorialReader class reference type }
|
{@@ TvVectorialReader class reference type }
|
||||||
@ -3960,6 +3980,12 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TvRichText.AddText: TvText;
|
||||||
|
begin
|
||||||
|
Result := TvText.Create;
|
||||||
|
AddEntity(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
function TvRichText.TryToSelect(APos: TPoint; var ASubpart: Cardinal
|
function TvRichText.TryToSelect(APos: TPoint; var ASubpart: Cardinal
|
||||||
): TvFindEntityResult;
|
): TvFindEntityResult;
|
||||||
begin
|
begin
|
||||||
@ -4668,6 +4694,12 @@ begin
|
|||||||
inherited Assign(ASource);
|
inherited Assign(ASource);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TvTextPageSequence.AddParagraph: TvRichText;
|
||||||
|
begin
|
||||||
|
Result := TvRichText.Create;
|
||||||
|
AddEntity(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TvVectorialDocument }
|
{ TvVectorialDocument }
|
||||||
|
|
||||||
{@@
|
{@@
|
||||||
@ -4679,6 +4711,7 @@ begin
|
|||||||
|
|
||||||
FPages := TFPList.Create;
|
FPages := TFPList.Create;
|
||||||
FCurrentPageIndex := -1;
|
FCurrentPageIndex := -1;
|
||||||
|
FStyles := TFPList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@
|
{@@
|
||||||
@ -4690,6 +4723,8 @@ begin
|
|||||||
|
|
||||||
FPages.Free;
|
FPages.Free;
|
||||||
FPages := nil;
|
FPages := nil;
|
||||||
|
FStyles.Free;
|
||||||
|
FStyles := nil;
|
||||||
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
@ -4971,6 +5006,53 @@ begin
|
|||||||
if FCurrentPageIndex < 0 then FCurrentPageIndex := FPages.Count-1;
|
if FCurrentPageIndex < 0 then FCurrentPageIndex := FPages.Count-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TvVectorialDocument.AddStyle: TvStyle;
|
||||||
|
begin
|
||||||
|
Result := TvStyle.Create;
|
||||||
|
FStyles.Add(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TvVectorialDocument.AddStandardTextDocumentStyles;
|
||||||
|
var
|
||||||
|
lCurStyle: TvStyle;
|
||||||
|
begin
|
||||||
|
lCurStyle.Name := 'Text Body';
|
||||||
|
lCurStyle.Font.Size := 12;
|
||||||
|
lCurStyle.Font.Name := 'Times New Roman';
|
||||||
|
lCurStyle.MarginTop := 0;
|
||||||
|
lCurStyle.MarginBottom := 2.12;
|
||||||
|
lCurStyle.SetElements := [spbfFontSize, spbfFontName];
|
||||||
|
|
||||||
|
lCurStyle := AddStyle();
|
||||||
|
lCurStyle.Name := 'Heading 1';
|
||||||
|
lCurStyle.Font.Size := 16;
|
||||||
|
lCurStyle.Font.Name := 'Arial';
|
||||||
|
lCurStyle.Font.Bold := True;
|
||||||
|
lCurStyle.MarginTop := 4.23;
|
||||||
|
lCurStyle.MarginBottom := 2.12;
|
||||||
|
lCurStyle.MarginTop := 4.23;
|
||||||
|
lCurStyle.MarginBottom := 2.12;
|
||||||
|
lCurStyle.SetElements := [spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic];
|
||||||
|
|
||||||
|
lCurStyle := AddStyle();
|
||||||
|
lCurStyle.Name := 'Heading 2';
|
||||||
|
lCurStyle.Font.Size := 14;
|
||||||
|
lCurStyle.Font.Name := 'Arial';
|
||||||
|
lCurStyle.Font.Bold := True;
|
||||||
|
lCurStyle.Font.Italic := True;
|
||||||
|
lCurStyle.SetElements := [spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TvVectorialDocument.GetStyleCount: Integer;
|
||||||
|
begin
|
||||||
|
Result := FStyles.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TvVectorialDocument.GetStyle(AIndex: Integer): TvStyle;
|
||||||
|
begin
|
||||||
|
Result := TvStyle(FStyles.Items[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
{@@
|
{@@
|
||||||
Clears all data in the document
|
Clears all data in the document
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user