Hosted by
|
with Readers; use Readers;
with Token_Readers; use Token_Readers;
with Writers; use Writers;
with Indent_Writers; use Indent_Writers;
with Real_Vectors; use Real_Vectors;
with Real_Strings; use Real_Strings;
with Integer_Strings; use Integer_Strings;
with Messages; use Messages;
with Lines; use Lines;
with Outlines; use Outlines;
with Outlines.SVG; use Outlines.SVG;
with Glyphs; use Glyphs;
package body Glyphs.SVG is
procedure Read_Outlines
(XML : access XML_Reader;
This : access Glyph) is
begin
Skip_Whitespace(XML); Assert_Char(XML, '=');
Skip_Whitespace(XML); Assert_Char(XML, '"');
loop
Add_Outline(This, Read(XML));
exit when Found_Char(XML, 'Z');
end loop;
Get(XML);
Assert_Char(XML, '"');
end Read_Outlines;
procedure Read_Bounds
(XML : access XML_Reader;
This : access Glyph)
is
Left, Bottom, Right, Top : Real;
begin
Skip_Whitespace(XML); Assert_Char(XML, '=');
Skip_Whitespace(XML); Assert_Char(XML, '"');
Left := Read_Real(XML);
Bottom := Read_Real(XML);
Right := Read_Real(XML);
Top := Read_Real(XML);
Set_Bounds(This, Left, Bottom, Right, Top);
Assert_Char(XML, '"');
end Read_Bounds;
function Read
(XML : access XML_Reader)
return Glyph_Access
is
Result : Glyph_Access := Create;
begin
while not End_Of_Tag(XML) loop
Read_Attribute_Name(XML);
if Found(XML, "transform") then
Read_Attribute_Value(XML);
elsif Found(XML, "roemer:bounds") then
Read_Bounds(XML, Result);
elsif Found(XML, "d") then
Read_Outlines(XML, Result);
else
XML_Expect_Error(XML, "", "transform" / "roemer:bounds" / "d");
end if;
end loop;
Exit_Tag(XML);
return Result;
end Read;
procedure Write
(XML : access XML_Writer;
This : access Glyph;
Tolerance : in Real;
Translate : in Vector)
is
use Glyphs.Outline_Lists;
Outlines : Outline_List_Access;
Outline : Outline_Access;
Bounds : Rectangle := Get_Bounds(This);
begin
Start_Tag(XML, "path");
Write_Attribute(XML, "transform", "translate(" &
To_String(Translate.X - (Bounds.Left + Bounds.Right) / 2.0, Tolerance) & " " &
To_String(Translate.Y - (Bounds.Bottom + Bounds.Top) / 2.0, Tolerance) & ")");
Write_Attribute(XML, "roemer:bounds", To_String(Bounds, Tolerance));
Write_Attribute_Name(XML, "d");
Put_Line(XML, "=""");
Outlines := Get_Outlines(This);
Reset(Outlines);
while Next(Outlines) loop
Outline := Current(Outlines);
Write(XML, Outline, Tolerance);
end loop;
Close_Tag(XML, "Z"" /");
New_Line(XML);
end Write;
end Glyphs.SVG;
|