mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 05:39:17 +02:00
fpvectorial: Patch from Michael Thompson, improves docx and text document
git-svn-id: trunk@42417 -
This commit is contained in:
parent
783de691c9
commit
a2b44d51fa
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1266,6 +1266,8 @@ components/fpvectorial/examples/fpvmodifytest.lpi svneol=native#text/plain
|
|||||||
components/fpvectorial/examples/fpvmodifytest.pas svneol=native#text/plain
|
components/fpvectorial/examples/fpvmodifytest.pas svneol=native#text/plain
|
||||||
components/fpvectorial/examples/fpvtextwritetest.lpi svneol=native#text/plain
|
components/fpvectorial/examples/fpvtextwritetest.lpi svneol=native#text/plain
|
||||||
components/fpvectorial/examples/fpvtextwritetest.pas svneol=native#text/plain
|
components/fpvectorial/examples/fpvtextwritetest.pas svneol=native#text/plain
|
||||||
|
components/fpvectorial/examples/fpvtextwritetest2.lpi svneol=native#text/plain
|
||||||
|
components/fpvectorial/examples/fpvtextwritetest2.pas svneol=native#text/plain
|
||||||
components/fpvectorial/examples/fpvwritetest.lpi svneol=native#text/plain
|
components/fpvectorial/examples/fpvwritetest.lpi svneol=native#text/plain
|
||||||
components/fpvectorial/examples/fpvwritetest.pas svneol=native#text/plain
|
components/fpvectorial/examples/fpvwritetest.pas svneol=native#text/plain
|
||||||
components/fpvectorial/fpvectbuildunit.pas svneol=native#text/plain
|
components/fpvectorial/fpvectbuildunit.pas svneol=native#text/plain
|
||||||
|
File diff suppressed because it is too large
Load Diff
80
components/fpvectorial/examples/fpvtextwritetest2.lpi
Normal file
80
components/fpvectorial/examples/fpvtextwritetest2.lpi
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="fpvtextwritetest2"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
<UseXPManifest Value="True"/>
|
||||||
|
</General>
|
||||||
|
<i18n>
|
||||||
|
<EnableI18N LFM="False"/>
|
||||||
|
</i18n>
|
||||||
|
<VersionInfo>
|
||||||
|
<StringTable ProductVersion=""/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
|
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="1">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="fpvectorialpkg"/>
|
||||||
|
<DefaultFilename Value="..\fpvectorialpkg.lpk" Prefer="True"/>
|
||||||
|
</Item1>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="fpvtextwritetest2.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="fpvtextwritetest2"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="fpvtextwritetest2"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
151
components/fpvectorial/examples/fpvtextwritetest2.pas
Normal file
151
components/fpvectorial/examples/fpvtextwritetest2.pas
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
{
|
||||||
|
FPVectorial example application for writing a text document file to disk.
|
||||||
|
|
||||||
|
Author: Felipe Monteiro de Carvalho
|
||||||
|
|
||||||
|
License: Public Domain
|
||||||
|
}
|
||||||
|
Program fpvtextwritetest2;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
Uses
|
||||||
|
fpvectorial,
|
||||||
|
odtvectorialwriter,
|
||||||
|
fpvutils,
|
||||||
|
fpvectorialpkg,
|
||||||
|
SysUtils;
|
||||||
|
|
||||||
|
{$R *.res}
|
||||||
|
|
||||||
|
Var
|
||||||
|
Vec: TvVectorialDocument;
|
||||||
|
Page: TvTextPageSequence;
|
||||||
|
CurParagraph: TvParagraph;
|
||||||
|
BoldStyle: TvStyle;
|
||||||
|
CenterStyle: TvStyle;
|
||||||
|
Begin
|
||||||
|
Vec := TvVectorialDocument.Create;
|
||||||
|
Try
|
||||||
|
// A4 -> 210mm x 297mm
|
||||||
|
Vec.Width := 210;
|
||||||
|
Vec.Height := 297;
|
||||||
|
|
||||||
|
Vec.AddStandardODTTextDocumentStyles();
|
||||||
|
|
||||||
|
// Until a Template is available, create the Bold Style ourselves
|
||||||
|
BoldStyle := Vec.AddStyle();
|
||||||
|
|
||||||
|
// This implies this style should not be applied to Paragraphs
|
||||||
|
BoldStyle.Kind := vskTextSpan;
|
||||||
|
BoldStyle.Name := 'Bold';
|
||||||
|
BoldStyle.Font.Bold := True;
|
||||||
|
BoldStyle.SetElements := BoldStyle.SetElements + [spbfFontBold];
|
||||||
|
|
||||||
|
CenterStyle := Vec.AddStyle();
|
||||||
|
CenterStyle.ApplyOver(Vec.StyleTextBody);
|
||||||
|
CenterStyle.Name := 'Text Body Centered';
|
||||||
|
CenterStyle.Alignment := vsaCenter;
|
||||||
|
CenterStyle.SetElements := CenterStyle.SetElements + [spbfAlignment];
|
||||||
|
|
||||||
|
// First page sequence
|
||||||
|
Page := Vec.AddTextPageSequence();
|
||||||
|
Page.Width := 210;
|
||||||
|
Page.Height := 297;
|
||||||
|
|
||||||
|
// Set the Header
|
||||||
|
CurParagraph := Page.Header.AddParagraph;
|
||||||
|
CurParagraph.Style := CenterStyle;
|
||||||
|
CurParagraph.AddText('Introduction to Lazarus and FreePascal').Style := BoldStyle;
|
||||||
|
|
||||||
|
// Set the Footer
|
||||||
|
CurParagraph := Page.Footer.AddParagraph;
|
||||||
|
CurParagraph.Style := CenterStyle;
|
||||||
|
CurParagraph.AddText('Confidential' + #11 + 'Page x of y' + #11 +
|
||||||
|
DateTimeToStr(Now)).Style :=
|
||||||
|
BoldStyle;
|
||||||
|
|
||||||
|
// Title
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleHeading1;
|
||||||
|
CurParagraph.AddText('Lazarus');
|
||||||
|
|
||||||
|
// paragraph
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleTextBody;
|
||||||
|
With CurParagraph Do
|
||||||
|
Begin
|
||||||
|
AddText('Lazarus ').Style := BoldStyle;
|
||||||
|
// Adding the Paragraph as a long string
|
||||||
|
AddText('is a free and open source development tool for the ' +
|
||||||
|
'Free Pascal compiler, which is also free and open source.');
|
||||||
|
End;
|
||||||
|
|
||||||
|
// Empty line
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleTextBody;
|
||||||
|
|
||||||
|
// Title
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleHeading2;
|
||||||
|
CurParagraph.AddText('Overview');
|
||||||
|
|
||||||
|
// paragraph
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleTextBody;
|
||||||
|
With CurParagraph Do
|
||||||
|
Begin
|
||||||
|
// Adding the Paragraph as a series of TvText's
|
||||||
|
// trailing space required
|
||||||
|
// Each TvText gets added as it's own text run inside the Word Doc
|
||||||
|
AddText('Lazarus ').Style := BoldStyle;
|
||||||
|
AddText('is a free cross-platform visual integrated development ');
|
||||||
|
AddText('environment (IDE) for rapid application development (RAD) ');
|
||||||
|
AddText('using the Free Pascal compiler supported dialects of Object ');
|
||||||
|
AddText('Pascal. Developers use ');
|
||||||
|
AddText('Lazarus ').Style := BoldStyle;
|
||||||
|
AddText('to create native code console ');
|
||||||
|
AddText('and graphical user interface (GUI) applications for the desktop ');
|
||||||
|
AddText('along with mobile devices, web applications, web services, ');
|
||||||
|
AddText('and visual components and function libraries (.so, .dll, etc) ');
|
||||||
|
AddText('for use by other programs for any platform the Free Pascal ');
|
||||||
|
AddText('compiler supports( Mac, Unix, Linux, Windows, etc). ');
|
||||||
|
End;
|
||||||
|
|
||||||
|
// Empty line
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleTextBody;
|
||||||
|
|
||||||
|
|
||||||
|
// Second page sequence
|
||||||
|
Page := Vec.AddTextPageSequence();
|
||||||
|
Page.Height := 210; // Switched to enforce Landscape
|
||||||
|
Page.Width := 297;
|
||||||
|
|
||||||
|
// Set the Header
|
||||||
|
CurParagraph := Page.Header.AddParagraph;
|
||||||
|
CurParagraph.Style := CenterStyle;
|
||||||
|
CurParagraph.AddText('Testing Concepts').Style := BoldStyle;
|
||||||
|
|
||||||
|
// Title
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleHeading2;
|
||||||
|
CurParagraph.AddText('Testing Strings');
|
||||||
|
|
||||||
|
// Test for XML tags
|
||||||
|
CurParagraph := Page.AddParagraph();
|
||||||
|
CurParagraph.Style := Vec.StyleTextBody;
|
||||||
|
// Adding to the Paragraph by extending the TStringList inside a single TvText
|
||||||
|
// Each line will be added inside a new text run inside the Word Doc
|
||||||
|
// with a Soft Return inserted at the end of each line
|
||||||
|
With CurParagraph.AddText('').Value Do
|
||||||
|
Begin
|
||||||
|
Add(#11 + '<test>&"This shouldn''t break the resulting document."</test>' + #11);
|
||||||
|
Add(#11 + '<test>!@#$%^&*()_+=-~`;:{}[],./|\?</test>' + #11);
|
||||||
|
End;
|
||||||
|
|
||||||
|
Vec.WriteToFile('text_output.docx', vfDOCX);
|
||||||
|
Finally
|
||||||
|
Vec.Free;
|
||||||
|
End;
|
||||||
|
End.
|
@ -133,8 +133,9 @@ type
|
|||||||
TvSetPenBrushAndFontElement = (
|
TvSetPenBrushAndFontElement = (
|
||||||
spbfPenColor, spbfPenStyle, spbfPenWidth,
|
spbfPenColor, spbfPenStyle, spbfPenWidth,
|
||||||
spbfBrushColor, spbfBrushStyle, spbfBrushGradient,
|
spbfBrushColor, spbfBrushStyle, spbfBrushGradient,
|
||||||
spbfFontColor, spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic
|
spbfFontColor, spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic,
|
||||||
);
|
spbfFontUnderline, spbfFontStrikeThrough, spbfAlignment);
|
||||||
|
|
||||||
TvSetPenBrushAndFontElements = set of TvSetPenBrushAndFontElement;
|
TvSetPenBrushAndFontElements = set of TvSetPenBrushAndFontElement;
|
||||||
|
|
||||||
TvStyleKind = (
|
TvStyleKind = (
|
||||||
@ -143,12 +144,15 @@ type
|
|||||||
// Text-span kind
|
// Text-span kind
|
||||||
vskTextSpan);
|
vskTextSpan);
|
||||||
|
|
||||||
|
TvStyleAlignment = (vsaLeft, vsaRight, vsaJustifed, vsaCenter);
|
||||||
|
|
||||||
{ TvStyle }
|
{ TvStyle }
|
||||||
|
|
||||||
TvStyle = class
|
TvStyle = class
|
||||||
Name: string;
|
Name: string;
|
||||||
Parent: TvStyle; // Can be nil
|
Parent: TvStyle; // Can be nil
|
||||||
Kind: TvStyleKind;
|
Kind: TvStyleKind;
|
||||||
|
Alignment: TvStyleAlignment;
|
||||||
//
|
//
|
||||||
Pen: TvPen;
|
Pen: TvPen;
|
||||||
Brush: TvBrush;
|
Brush: TvBrush;
|
||||||
@ -1032,6 +1036,7 @@ type
|
|||||||
|
|
||||||
TvTextPageSequence = class(TvPage)
|
TvTextPageSequence = class(TvPage)
|
||||||
public
|
public
|
||||||
|
Width, Height: Double; // in millimeters, may be 0 to use TvVectorialDocument defaults
|
||||||
Footer, Header: TvRichText;
|
Footer, Header: TvRichText;
|
||||||
MainText: TvRichText;
|
MainText: TvRichText;
|
||||||
{ Base methods }
|
{ Base methods }
|
||||||
@ -1218,6 +1223,8 @@ begin
|
|||||||
Name := '';
|
Name := '';
|
||||||
Parent := nil;
|
Parent := nil;
|
||||||
Kind := vskTextBody;
|
Kind := vskTextBody;
|
||||||
|
Alignment := vsaLeft;
|
||||||
|
|
||||||
//
|
//
|
||||||
{Pen.Color := col;
|
{Pen.Color := col;
|
||||||
Brush := nil;
|
Brush := nil;
|
||||||
@ -1263,6 +1270,14 @@ begin
|
|||||||
Font.Bold := AFrom.Font.Bold;
|
Font.Bold := AFrom.Font.Bold;
|
||||||
if spbfFontItalic in AFrom.SetElements then
|
if spbfFontItalic in AFrom.SetElements then
|
||||||
Font.Italic := AFrom.Font.Italic;
|
Font.Italic := AFrom.Font.Italic;
|
||||||
|
If spbfFontUnderline in AFrom.SetElements then
|
||||||
|
Font.Underline := AFrom.Font.Underline;
|
||||||
|
If spbfFontStrikeThrough in AFrom.SetElements then
|
||||||
|
Font.StrikeThrough := AFrom.Font.StrikeThrough;
|
||||||
|
If spbfAlignment in AFrom.SetElements then
|
||||||
|
Alignment := AFrom.Alignment;
|
||||||
|
|
||||||
|
SetElements:=AFrom.SetElements;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ T2DEllipticalArcSegment }
|
{ T2DEllipticalArcSegment }
|
||||||
@ -5481,7 +5496,8 @@ begin
|
|||||||
lTextBody.Kind := vskTextBody;
|
lTextBody.Kind := vskTextBody;
|
||||||
lTextBody.Font.Size := 12;
|
lTextBody.Font.Size := 12;
|
||||||
lTextBody.Font.Name := 'Times New Roman';
|
lTextBody.Font.Name := 'Times New Roman';
|
||||||
lTextBody.SetElements := [spbfFontSize, spbfFontName];
|
lTextBody.Alignment := vsaJustifed;
|
||||||
|
lTextBody.SetElements := [spbfFontSize, spbfFontName, spbfAlignment];
|
||||||
lTextBody.MarginTop := 0;
|
lTextBody.MarginTop := 0;
|
||||||
lTextBody.MarginBottom := 2.12;
|
lTextBody.MarginBottom := 2.12;
|
||||||
StyleTextBody := lTextBody;
|
StyleTextBody := lTextBody;
|
||||||
|
Loading…
Reference in New Issue
Block a user