fpvectorial: Patch from Michael Thompson, improves docx and text document

git-svn-id: trunk@42417 -
This commit is contained in:
sekelsenmat 2013-08-18 06:58:31 +00:00
parent 783de691c9
commit a2b44d51fa
5 changed files with 965 additions and 313 deletions

2
.gitattributes vendored
View File

@ -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/fpvtextwritetest.lpi 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.pas svneol=native#text/plain
components/fpvectorial/fpvectbuildunit.pas svneol=native#text/plain

File diff suppressed because it is too large Load Diff

View 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>

View 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.

View File

@ -133,8 +133,9 @@ type
TvSetPenBrushAndFontElement = (
spbfPenColor, spbfPenStyle, spbfPenWidth,
spbfBrushColor, spbfBrushStyle, spbfBrushGradient,
spbfFontColor, spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic
);
spbfFontColor, spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic,
spbfFontUnderline, spbfFontStrikeThrough, spbfAlignment);
TvSetPenBrushAndFontElements = set of TvSetPenBrushAndFontElement;
TvStyleKind = (
@ -143,12 +144,15 @@ type
// Text-span kind
vskTextSpan);
TvStyleAlignment = (vsaLeft, vsaRight, vsaJustifed, vsaCenter);
{ TvStyle }
TvStyle = class
Name: string;
Parent: TvStyle; // Can be nil
Kind: TvStyleKind;
Alignment: TvStyleAlignment;
//
Pen: TvPen;
Brush: TvBrush;
@ -1032,6 +1036,7 @@ type
TvTextPageSequence = class(TvPage)
public
Width, Height: Double; // in millimeters, may be 0 to use TvVectorialDocument defaults
Footer, Header: TvRichText;
MainText: TvRichText;
{ Base methods }
@ -1218,6 +1223,8 @@ begin
Name := '';
Parent := nil;
Kind := vskTextBody;
Alignment := vsaLeft;
//
{Pen.Color := col;
Brush := nil;
@ -1263,6 +1270,14 @@ begin
Font.Bold := AFrom.Font.Bold;
if spbfFontItalic in AFrom.SetElements then
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;
{ T2DEllipticalArcSegment }
@ -5481,7 +5496,8 @@ begin
lTextBody.Kind := vskTextBody;
lTextBody.Font.Size := 12;
lTextBody.Font.Name := 'Times New Roman';
lTextBody.SetElements := [spbfFontSize, spbfFontName];
lTextBody.Alignment := vsaJustifed;
lTextBody.SetElements := [spbfFontSize, spbfFontName, spbfAlignment];
lTextBody.MarginTop := 0;
lTextBody.MarginBottom := 2.12;
StyleTextBody := lTextBody;