mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-06 19:06:11 +02:00
fpvectorial: First commit for ODT writing support and text document support
git-svn-id: trunk@42215 -
This commit is contained in:
parent
365e113758
commit
b05e1e1ab1
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1273,6 +1273,7 @@ components/fpvectorial/lasvectorialreader.pas svneol=native#text/plain
|
||||
components/fpvectorial/lazvectorialreader.pas svneol=native#text/plain
|
||||
components/fpvectorial/mathmlvectorialreader.pas svneol=native#text/plain
|
||||
components/fpvectorial/odgvectorialreader.pas svneol=native#text/pascal
|
||||
components/fpvectorial/odtvectorialwriter.pas svneol=native#text/plain
|
||||
components/fpvectorial/pdfvectorialreader.pas svneol=native#text/plain
|
||||
components/fpvectorial/pdfvrlexico.pas svneol=native#text/plain
|
||||
components/fpvectorial/pdfvrsemantico.pas svneol=native#text/plain
|
||||
|
@ -51,6 +51,8 @@ type
|
||||
vfGCodeAvisoCNCPrototipoV5, vfGCodeAvisoCNCPrototipoV6,
|
||||
{ Formula formats }
|
||||
vfMathML,
|
||||
{ Text Document formats }
|
||||
vfODT,
|
||||
{ Raster Image formats }
|
||||
vfRAW
|
||||
);
|
||||
@ -88,6 +90,7 @@ type
|
||||
TvCustomVectorialWriter = class;
|
||||
TvCustomVectorialReader = class;
|
||||
TvVectorialPage = class;
|
||||
TvTextDocumentPage = class;
|
||||
|
||||
{ Pen, Brush and Font }
|
||||
|
||||
@ -751,6 +754,30 @@ type
|
||||
public
|
||||
end;
|
||||
|
||||
{@@
|
||||
TvRichText represents a sequence of elements ordered as characters.
|
||||
The elements might be richly formatted text, but also any other elements.
|
||||
|
||||
The basic element to build the sequence is TvText. Note that the X, Y positions
|
||||
of elements will be all adjusted to fit the TvRichText area
|
||||
}
|
||||
|
||||
TvRichTextAutoExpand = (rtaeNone, etaeWidth, etaeHeight);
|
||||
|
||||
{ TvRichText }
|
||||
|
||||
TvRichText = class(TvEntityWithSubEntities)
|
||||
public
|
||||
Width, Height: Double;
|
||||
AutoExpand: TvRichTextAutoExpand;
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
function TryToSelect(APos: TPoint; var ASubpart: Cardinal): TvFindEntityResult; override;
|
||||
procedure Render(ADest: TFPCustomCanvas; 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;
|
||||
end;
|
||||
|
||||
{ TvVectorialDocument }
|
||||
|
||||
TvVectorialDocument = class
|
||||
@ -792,6 +819,7 @@ type
|
||||
function GetCurrentPage: TvVectorialPage;
|
||||
procedure SetCurrentPage(AIndex: Integer);
|
||||
function AddPage(): TvVectorialPage;
|
||||
function AddTextPage(): TvTextDocumentPage;
|
||||
{ Data removing methods }
|
||||
procedure Clear; virtual;
|
||||
{ Debug methods }
|
||||
@ -825,7 +853,7 @@ type
|
||||
{ Base methods }
|
||||
constructor Create(AOwner: TvVectorialDocument); virtual;
|
||||
destructor Destroy; override;
|
||||
procedure Assign(ASource: TvVectorialPage);
|
||||
procedure Assign(ASource: TvVectorialPage); virtual;
|
||||
{ Data reading methods }
|
||||
function GetEntity(ANum: Cardinal): TvEntity;
|
||||
function GetEntitiesCount: Integer;
|
||||
@ -888,6 +916,18 @@ type
|
||||
property Entities[AIndex: Cardinal]: TvEntity read GetEntity;
|
||||
end;
|
||||
|
||||
{ TvTextDocumentPage }
|
||||
|
||||
TvTextDocumentPage = class(TvVectorialPage)
|
||||
public
|
||||
Footer, Header: TvRichText;
|
||||
MainText: TvRichText;
|
||||
{ Base methods }
|
||||
constructor Create(AOwner: TvVectorialDocument); override;
|
||||
destructor Destroy; override;
|
||||
procedure Assign(ASource: TvVectorialPage); override;
|
||||
end;
|
||||
|
||||
{@@ TvVectorialReader class reference type }
|
||||
|
||||
TvVectorialReaderClass = class of TvCustomVectorialReader;
|
||||
@ -3908,6 +3948,36 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TvRichText }
|
||||
|
||||
constructor TvRichText.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
end;
|
||||
|
||||
destructor TvRichText.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TvRichText.TryToSelect(APos: TPoint; var ASubpart: Cardinal
|
||||
): TvFindEntityResult;
|
||||
begin
|
||||
Result:=inherited TryToSelect(APos, ASubpart);
|
||||
end;
|
||||
|
||||
procedure TvRichText.Render(ADest: TFPCustomCanvas; ARenderInfo: TvRenderInfo;
|
||||
ADestX: Integer; ADestY: Integer; AMulX: Double; AMulY: Double);
|
||||
begin
|
||||
inherited Render(ADest, ARenderInfo, ADestX, ADestY, AMulX, AMulY);
|
||||
end;
|
||||
|
||||
function TvRichText.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc;
|
||||
APageItem: Pointer): Pointer;
|
||||
begin
|
||||
Result:=inherited GenerateDebugTree(ADestRoutine, APageItem);
|
||||
end;
|
||||
|
||||
{ TvVectorialPage }
|
||||
|
||||
procedure TvVectorialPage.ClearTmpPath;
|
||||
@ -4581,7 +4651,24 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TsWorksheet }
|
||||
{ TvTextDocumentPage }
|
||||
|
||||
constructor TvTextDocumentPage.Create(AOwner: TvVectorialDocument);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
end;
|
||||
|
||||
destructor TvTextDocumentPage.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TvTextDocumentPage.Assign(ASource: TvVectorialPage);
|
||||
begin
|
||||
inherited Assign(ASource);
|
||||
end;
|
||||
|
||||
{ TvVectorialDocument }
|
||||
|
||||
{@@
|
||||
Constructor.
|
||||
@ -4877,6 +4964,13 @@ begin
|
||||
if FCurrentPageIndex < 0 then FCurrentPageIndex := FPages.Count-1;
|
||||
end;
|
||||
|
||||
function TvVectorialDocument.AddTextPage: TvTextDocumentPage;
|
||||
begin
|
||||
Result := TvTextDocumentPage.Create(Self);
|
||||
FPages.Add(Result);
|
||||
if FCurrentPageIndex < 0 then FCurrentPageIndex := FPages.Count-1;
|
||||
end;
|
||||
|
||||
{@@
|
||||
Clears all data in the document
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Files Count="18">
|
||||
<Files Count="19">
|
||||
<Item1>
|
||||
<Filename Value="fpvectorial.pas"/>
|
||||
<UnitName Value="fpvectorial"/>
|
||||
@ -85,6 +85,10 @@
|
||||
<Filename Value="svgzvectorialreader.pas"/>
|
||||
<UnitName Value="svgzvectorialreader"/>
|
||||
</Item18>
|
||||
<Item19>
|
||||
<Filename Value="odtvectorialwriter.pas"/>
|
||||
<UnitName Value="odtvectorialwriter"/>
|
||||
</Item19>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="2">
|
||||
|
@ -12,7 +12,7 @@ uses
|
||||
dxfvectorialreader, epsvectorialreader, lasvectorialreader,
|
||||
lazvectorialreader, mathmlvectorialreader, odgvectorialreader,
|
||||
rawvectorialreadwrite, svgvectorialreader, svgvectorialwriter,
|
||||
svgzvectorialreader, LazarusPackageIntf;
|
||||
svgzvectorialreader, odtvectorialwriter, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
@ -49,7 +49,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, math,
|
||||
zipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.8 is released}
|
||||
zipper, {NOTE: might require zipper from FPC 2.6.2+ }
|
||||
xmlread, DOM, AVL_Tree,
|
||||
fpimage, fpcanvas, fgl,
|
||||
fpvectorial, fpvutils, lazutf8;
|
||||
|
155
components/fpvectorial/odtvectorialwriter.pas
Normal file
155
components/fpvectorial/odtvectorialwriter.pas
Normal file
@ -0,0 +1,155 @@
|
||||
{
|
||||
Writes an ODT Document
|
||||
|
||||
License: The same modified LGPL as the Free Pascal RTL
|
||||
See the file COPYING.modifiedLGPL for more details
|
||||
|
||||
An OpenDocument document is a compressed ZIP file with the following files inside:
|
||||
|
||||
content.xml - Actual contents
|
||||
meta.xml - Authoring data
|
||||
settings.xml - User persistent viewing information, such as zoom, cursor position, etc.
|
||||
styles.xml - Styles, which are the only way to do formatting
|
||||
mimetype - application/vnd.oasis.opendocument.text
|
||||
META-INF\manifest.xml - Describes the other files in the archive
|
||||
|
||||
Specifications obtained from:
|
||||
|
||||
http://docs.oasis-open.org/office/v1.1/OS/OpenDocument-v1.1.pdf
|
||||
|
||||
Example of content.xml structure:
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" .....>
|
||||
<office:scripts/>
|
||||
<office:automatic-styles>
|
||||
<style:style style:name="dp1" style:family="drawing-page"/>
|
||||
<style:style style:name="gr1" style:family="graphic" style:parent-style-name="standard">
|
||||
....
|
||||
</office:automatic-styles>
|
||||
<office:body>
|
||||
<office:drawing>
|
||||
<draw:page draw:name="page1" draw:style-name="dp1" draw:master-page-name="Oletus">
|
||||
<draw:ellipse draw:style-name="gr2" draw:text-style-name="P1" draw:layer="layout" svg:width="11cm" svg:height="3cm" svg:x="5.5cm" svg:y="6.5cm">
|
||||
<text:p/>
|
||||
</draw:ellipse>
|
||||
... other elements in the page...
|
||||
</draw:page>
|
||||
</office:drawing>
|
||||
</office:body>
|
||||
</office:document-content>
|
||||
|
||||
AUTHORS: Felipe Monteiro de Carvalho
|
||||
}
|
||||
unit odtvectorialwriter;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, math,
|
||||
zipper, {NOTE: might require zipper from FPC 2.6.2+ }
|
||||
fpimage, fpcanvas, fgl,
|
||||
fpvectorial, fpvutils, lazutf8;
|
||||
|
||||
type
|
||||
{ TvODTVectorialWriter }
|
||||
|
||||
TvODTVectorialWriter = class(TvCustomVectorialWriter)
|
||||
private
|
||||
FPointSeparator, FCommaSeparator: TFormatSettings;
|
||||
public
|
||||
{ General reading methods }
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
procedure WriteToFile(AFileName: string; AData: TvVectorialDocument); override;
|
||||
procedure WriteToStream(AStream: TStream; AData: TvVectorialDocument); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
{ OpenDocument general XML constants }
|
||||
XML_HEADER = '<?xml version="1.0" encoding="utf-8" ?>';
|
||||
|
||||
{ OpenDocument Directory structure constants }
|
||||
OPENDOC_PATH_CONTENT = 'content.xml';
|
||||
OPENDOC_PATH_META = 'meta.xml';
|
||||
OPENDOC_PATH_SETTINGS = 'settings.xml';
|
||||
OPENDOC_PATH_STYLES = 'styles.xml';
|
||||
OPENDOC_PATH_MIMETYPE = 'mimetype';
|
||||
OPENDOC_PATH_METAINF = 'META-INF' + '/';
|
||||
OPENDOC_PATH_METAINF_MANIFEST = 'META-INF' + '/' + 'manifest.xml';
|
||||
|
||||
{ OpenDocument schemas constants }
|
||||
SCHEMAS_XMLNS_OFFICE = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0';
|
||||
SCHEMAS_XMLNS_DCTERMS = 'http://purl.org/dc/terms/';
|
||||
SCHEMAS_XMLNS_META = 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0';
|
||||
SCHEMAS_XMLNS = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties';
|
||||
SCHEMAS_XMLNS_CONFIG = 'urn:oasis:names:tc:opendocument:xmlns:config:1.0';
|
||||
SCHEMAS_XMLNS_OOO = 'http://openoffice.org/2004/office';
|
||||
SCHEMAS_XMLNS_MANIFEST = 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0';
|
||||
SCHEMAS_XMLNS_FO = 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0';
|
||||
SCHEMAS_XMLNS_STYLE = 'urn:oasis:names:tc:opendocument:xmlns:style:1.0';
|
||||
SCHEMAS_XMLNS_SVG = 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0';
|
||||
SCHEMAS_XMLNS_TABLE = 'urn:oasis:names:tc:opendocument:xmlns:table:1.0';
|
||||
SCHEMAS_XMLNS_TEXT = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0';
|
||||
SCHEMAS_XMLNS_V = 'urn:schemas-microsoft-com:vml';
|
||||
SCHEMAS_XMLNS_NUMBER = 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0';
|
||||
SCHEMAS_XMLNS_CHART = 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0';
|
||||
SCHEMAS_XMLNS_DR3D = 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0';
|
||||
SCHEMAS_XMLNS_MATH = 'http://www.w3.org/1998/Math/MathML';
|
||||
SCHEMAS_XMLNS_FORM = 'urn:oasis:names:tc:opendocument:xmlns:form:1.0';
|
||||
SCHEMAS_XMLNS_SCRIPT = 'urn:oasis:names:tc:opendocument:xmlns:script:1.0';
|
||||
SCHEMAS_XMLNS_OOOW = 'http://openoffice.org/2004/writer';
|
||||
SCHEMAS_XMLNS_OOOC = 'http://openoffice.org/2004/calc';
|
||||
SCHEMAS_XMLNS_DOM = 'http://www.w3.org/2001/xml-events';
|
||||
SCHEMAS_XMLNS_XFORMS = 'http://www.w3.org/2002/xforms';
|
||||
SCHEMAS_XMLNS_XSD = 'http://www.w3.org/2001/XMLSchema';
|
||||
SCHEMAS_XMLNS_XSI = 'http://www.w3.org/2001/XMLSchema-instance';
|
||||
|
||||
// SVG requires hardcoding a DPI value
|
||||
|
||||
// The Opera Browser and Inkscape use 90 DPI, so we follow that
|
||||
|
||||
// 1 Inch = 25.4 milimiters
|
||||
// 90 inches per pixel = (1 / 90) * 25.4 = 0.2822
|
||||
// FLOAT_MILIMETERS_PER_PIXEL = 0.3528; // DPI 72 = 1 / 72 inches per pixel
|
||||
|
||||
FLOAT_MILIMETERS_PER_PIXEL = 0.2822; // DPI 90 = 1 / 90 inches per pixel
|
||||
FLOAT_PIXELS_PER_MILIMETER = 3.5433; // DPI 90 = 1 / 90 inches per pixel
|
||||
|
||||
constructor TvODTVectorialWriter.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
FPointSeparator := DefaultFormatSettings;
|
||||
FPointSeparator.DecimalSeparator := '.';
|
||||
FPointSeparator.ThousandSeparator := '#';// disable the thousand separator
|
||||
end;
|
||||
|
||||
destructor TvODTVectorialWriter.Destroy;
|
||||
begin
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TvODTVectorialWriter.WriteToFile(AFileName: string;
|
||||
AData: TvVectorialDocument);
|
||||
begin
|
||||
inherited WriteToFile(AFileName, AData);
|
||||
end;
|
||||
|
||||
procedure TvODTVectorialWriter.WriteToStream(AStream: TStream;
|
||||
AData: TvVectorialDocument);
|
||||
begin
|
||||
//inherited WriteToStream(AStream, AData);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
RegisterVectorialWriter(TvODTVectorialWriter, vfODT);
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user