Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #11

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions examples/ImageInsert/ImageInsert.lpi
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="ImageInsert"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="fpOdf"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="ImageInsert.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ImageInsert"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="ImageInsert"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>
95 changes: 95 additions & 0 deletions examples/ImageInsert/ImageInsert.lpr
@@ -0,0 +1,95 @@
{ fpOdf "Image Insert" Example

Copyright (c) 2013-2019 Daniel F.Gaspary

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
}

program ImageInsert;

uses
classes, odf_types, base64;

const
cStyle = 'Standard';

cInputFile = '/tmp/image1.png';
cOutputFile = '/tmp/output.fodt';

function EncodeStreamBase64(AInputStream: TStream):String;
var
Outstream : TStringStream;
Encoder : TBase64EncodingStream;
begin
Outstream:=TStringStream.Create('');
try
Encoder:=TBase64EncodingStream.create(outstream);
try
Encoder.CopyFrom(AInputStream, AInputStream.Size);
finally
Encoder.Free;
end;
Result:=Outstream.DataString;
finally
Outstream.free;
end;
end;

var
doc: TOdfTextDocument;
p: TOdfParagraph;
eDrawFrame, eDrawImage, eBinaryData: TOdfElement;

fs: TFileStream;
s: string;
begin
doc:=TOdfTextDocument.Create;

doc.AddParagraph(cStyle).TextContent:='p1';
p:=doc.AddParagraph(cStyle);

eDrawFrame:=p.AppendOdfElement(oetDrawFrame);

eDrawFrame.SetAttributes(
[oatDrawStyleName, oatDrawName, oatTextAnchorType, oatSvgWidth, oatSvgHeight, oatDrawZIndex],
['fr1', 'Image1', 'paragraph', '5.80in', '3.6in', '0']);

eDrawImage:=eDrawFrame.AppendOdfElement(oetDrawImage);

eBinaryData:=eDrawImage.AppendOdfElement(oetOfficeBinaryData);

try
fs:=TFileStream.Create(cInputFile, fmOpenRead);
s:=EncodeStreamBase64(fs);
finally
fs.Free;
end;

eBinaryData.TextContent:=s;

doc.AddParagraph(cStyle).TextContent:='p2';

try
doc.SaveToSingleXml(cOutputFile);

finally
doc.Free;
end;
end.

41 changes: 41 additions & 0 deletions examples/ImageInsert/ImageInsert.lps
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="9"/>
<BuildModes Active="Default"/>
<Units Count="3">
<Unit0>
<Filename Value="ImageInsert.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="66"/>
<CursorPos X="25" Y="93"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="../../odf_types.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="1333"/>
<CursorPos X="6" Y="1335"/>
<UsageCount Value="10"/>
</Unit1>
<Unit2>
<Filename Value="/usr/share/fpcsrc/2.7.1/packages/fcl-base/src/base64.pp"/>
<EditorIndex Value="-1"/>
<TopLine Value="148"/>
<UsageCount Value="10"/>
</Unit2>
</Units>
<JumpHistory Count="2" HistoryIndex="1">
<Position1>
<Filename Value="ImageInsert.lpr"/>
<Caret Line="8" Column="26"/>
</Position1>
<Position2>
<Filename Value="ImageInsert.lpr"/>
<Caret Line="63" Column="33" TopLine="43"/>
</Position2>
</JumpHistory>
</ProjectSession>
</CONFIG>
69 changes: 69 additions & 0 deletions examples/TableInsert/TableInsert.lpi
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="TableInsert"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="fpOdf"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="TableInsert.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TableInsert"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="TableInsert"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>