mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 10:09:32 +02:00
aggpas: started svg loading
git-svn-id: trunk@23015 -
This commit is contained in:
parent
6b083a813f
commit
be2b1bc884
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -87,6 +87,8 @@ components/aggpas/lazarus/example/AggPasInLCLDemo1.lpr svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/AggPasInLCLDemo1.lrs svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/AggPasInLCLDemo2.lpi svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/AggPasInLCLDemo2.lpr svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/LoadSVGDemo1.lpi svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/LoadSVGDemo1.lpr svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/unit1.lfm svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/unit1.lrs svneol=native#text/plain
|
||||
components/aggpas/lazarus/example/unit1.pas svneol=native#text/plain
|
||||
|
@ -2927,9 +2927,7 @@ begin
|
||||
if @parser.m_characterDataHandler <> NIL then
|
||||
begin
|
||||
c:=XML_Char($A );
|
||||
|
||||
parser.m_characterDataHandler(parser.m_handlerArg ,@c ,1 );
|
||||
|
||||
end
|
||||
else
|
||||
if @parser.m_defaultHandler <> NIL then
|
||||
|
@ -7,7 +7,7 @@
|
||||
<Version Value="8"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="../src/"/>
|
||||
<OtherUnitFiles Value="../src/;../src/util/;../src/svg/;../src/ctrl/;../expat-pas/"/>
|
||||
<OtherUnitFiles Value="../;../src/;../src/util/;../src/svg/;../src/ctrl/;../expat-pas/"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
|
66
components/aggpas/lazarus/example/LoadSVGDemo1.lpi
Normal file
66
components/aggpas/lazarus/example/LoadSVGDemo1.lpi
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<SessionStorage Value="InIDEConfig"/>
|
||||
<MainUnit Value="0"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<Title Value="LoadSVGDemo1"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<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"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="AggPasLCL"/>
|
||||
<MinVersion Major="1" Valid="True"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="LoadSVGDemo1.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="LoadSVGDemo1"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="unit3.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="Unit3"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="8"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)/"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
18
components/aggpas/lazarus/example/LoadSVGDemo1.lpr
Normal file
18
components/aggpas/lazarus/example/LoadSVGDemo1.lpr
Normal file
@ -0,0 +1,18 @@
|
||||
program LoadSVGDemo1;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, Unit3, AggPasLCL
|
||||
{ you can add units after this };
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
@ -51,6 +51,9 @@ const
|
||||
|
||||
type
|
||||
parser_ptr = ^parser;
|
||||
|
||||
{ parser }
|
||||
|
||||
parser = object
|
||||
m_path : path_renderer_ptr;
|
||||
m_tokenizer : path_tokenizer;
|
||||
@ -72,7 +75,8 @@ type
|
||||
constructor Construct(path : path_renderer_ptr );
|
||||
destructor Destruct;
|
||||
|
||||
procedure parse(fname : string );
|
||||
procedure parse(fname : string ); overload; // UTF8
|
||||
procedure parse(sourcestream: TStream); overload;
|
||||
function title : char_ptr;
|
||||
|
||||
// XML event handlers
|
||||
@ -617,7 +621,7 @@ begin
|
||||
end;
|
||||
|
||||
{ CONSTRUCT }
|
||||
constructor parser.Construct;
|
||||
constructor parser.Construct(path : path_renderer_ptr );
|
||||
begin
|
||||
m_path:=path;
|
||||
|
||||
@ -653,83 +657,70 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
{ PARSE }
|
||||
procedure parser.parse(fname : string );
|
||||
procedure parser.parse(fname: string);
|
||||
var
|
||||
msg : array[0..1023 ] of char;
|
||||
fs: TFileStream;
|
||||
begin
|
||||
fs:=TFileStream.Create(UTF8ToSys(fname),fmOpenRead+fmShareDenyWrite);
|
||||
try
|
||||
parse(fs);
|
||||
finally
|
||||
fs.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ PARSE }
|
||||
procedure parser.parse(sourcestream: TStream);
|
||||
var
|
||||
p : XML_Parser;
|
||||
ts : char_ptr;
|
||||
|
||||
done : boolean;
|
||||
len : int;
|
||||
|
||||
fs: TFileStream;
|
||||
Msg : ansistring;
|
||||
begin
|
||||
p:=XML_ParserCreate(NIL );
|
||||
|
||||
if p = NIL then
|
||||
raise svg_exception.Construct(PChar('Couldn''t allocate memory for parser' ) );
|
||||
|
||||
XML_SetUserData (p ,@self );
|
||||
XML_SetElementHandler (p ,@start_element ,@end_element );
|
||||
XML_SetCharacterDataHandler(p ,@content );
|
||||
|
||||
try
|
||||
fs:=TFileStream.Create(fname,fmOpenRead+fmShareDenyWrite);
|
||||
except
|
||||
sprintf(@msg[0 ] ,'Couldn''t open file %s' ,unsigned(@fname[1 ] ) );
|
||||
|
||||
XML_ParserFree(p );
|
||||
|
||||
raise svg_exception.Construct(PChar(@msg[0 ] ) );
|
||||
end;
|
||||
try
|
||||
XML_SetUserData (p ,@self );
|
||||
XML_SetElementHandler (p ,@start_element ,@end_element );
|
||||
XML_SetCharacterDataHandler(p ,@content );
|
||||
|
||||
done:=false;
|
||||
|
||||
repeat
|
||||
len:=fs.Read(m_buf^,buf_size);
|
||||
len:=sourcestream.Read(m_buf^,buf_size);
|
||||
|
||||
done:=len < buf_size;
|
||||
|
||||
if XML_Parse(p ,pointer(m_buf ) ,len ,int(done ) ) = XML_STATUS_ERROR then
|
||||
begin
|
||||
XML_ParserFree(p );
|
||||
|
||||
sprintf(
|
||||
@msg[0 ] ,
|
||||
'%s at line ' ,
|
||||
unsigned(
|
||||
XML_ErrorString(
|
||||
XML_GetErrorCode(p ) ) ) );
|
||||
|
||||
sprintf(
|
||||
@msg[StrLen(msg ) ] ,
|
||||
'%d'#13 ,
|
||||
XML_GetCurrentLineNumber(p ) );
|
||||
|
||||
raise svg_exception.Construct(PChar(@msg[0 ] ) );
|
||||
Msg:=PChar(XML_ErrorString(XML_GetErrorCode(p)));
|
||||
Msg:=' at line '+IntToStr(XML_GetCurrentLineNumber(p));
|
||||
raise svg_exception.Construct(PChar(Msg) );
|
||||
|
||||
end;
|
||||
|
||||
until done;
|
||||
|
||||
ts:=m_title;
|
||||
|
||||
while ts^ <> #0 do
|
||||
begin
|
||||
if byte(ts^ ) < byte(' ' ) then
|
||||
ts^:=' ';
|
||||
|
||||
inc(ptrcomp(ts ) );
|
||||
|
||||
end;
|
||||
|
||||
finally
|
||||
fs.Free;
|
||||
XML_ParserFree(p );
|
||||
end;
|
||||
XML_ParserFree(p );
|
||||
|
||||
ts:=m_title;
|
||||
|
||||
while ts^ <> #0 do
|
||||
begin
|
||||
if byte(ts^ ) < byte(' ' ) then
|
||||
ts^:=' ';
|
||||
|
||||
inc(ptrcomp(ts ) );
|
||||
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
{ TITLE }
|
||||
|
@ -5,6 +5,7 @@
|
||||
//
|
||||
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
|
||||
//
|
||||
{$mode delphi}
|
||||
program
|
||||
svg_test ;
|
||||
|
||||
@ -37,9 +38,9 @@ uses
|
||||
agg_svg_parser ,
|
||||
agg_svg_path_renderer ,
|
||||
agg_svg_exception ,
|
||||
file_utils_ ;
|
||||
file_utils_, AggPasLCL ;
|
||||
|
||||
{$I agg_mode.inc }
|
||||
{$I src/agg_mode.inc }
|
||||
|
||||
const
|
||||
flip_y = false;
|
||||
@ -436,4 +437,4 @@ BEGIN
|
||||
Esc:
|
||||
app.Destruct;
|
||||
|
||||
END.
|
||||
END.
|
||||
|
Loading…
Reference in New Issue
Block a user