Hosted by
|
with Render_Glyphs; use Render_Glyphs;
with Nocurves; use Nocurves;
with Integer_Vectors;
with Gray_Images; use Gray_Images;
package body Glyphs is
function Create
return Glyph_Access
is
Result : Glyph_Access := new Glyph;
begin
Result.Outlines := Outline_Lists.Create;
return Result;
end Create;
function Get_Bounds
(This : access Glyph)
return Rectangle is
begin
return This.Bounds;
end Get_Bounds;
function Get_Outlines
(This : access Glyph)
return Outline_List_Access is
begin
return This.Outlines;
end Get_Outlines;
procedure Add_Outline
(This : access Glyph;
Add : in Outline_Access) is
begin
Outline_Lists.Push(This.Outlines, Add);
end Add_Outline;
procedure Update_Image
(This : access Glyph;
Staff_Height : in Real;
Aspect_Ratio : in Real;
Anti_Alias : in Positive) is
begin
if This.Image = null
or else This.Image.Staff_Height /= Staff_Height
or else This.Image.Aspect_Ratio /= Aspect_Ratio
or else This.Image.Anti_Alias /= Anti_Alias
then
Make_Straight(This, 0.1);
This.Image := Render(This, Staff_Height, Aspect_Ratio, Anti_Alias);
end if;
end Update_Image;
function Get_Image
(This : access Glyph;
Staff_Height : in Real;
Aspect_Ratio : in Real;
Anti_Alias : in Positive)
return Glyph_Image_Access is
begin
Update_Image(This, Staff_Height, Aspect_Ratio, Anti_Alias);
return This.Image;
end Get_Image;
procedure Set_Bounds
(This : access Glyph;
Left, Top : in Real;
Right, Bottom : in Real) is
begin
This.Bounds := Rectangle'(Left, Top, Right, Bottom);
end Set_Bounds;
function Get_Width
(This : access Glyph)
return Real is
begin
return Get_Width(This.Bounds);
end Get_Width;
function Get_Height
(This : access Glyph)
return Real is
begin
return Get_Height(This.Bounds);
end Get_Height;
procedure Print
(This : access Glyph;
Image : access Glyph_Image;
Center : in Vector)
is
Target : Integer_Vectors.Vector;
begin
Update_Image(This, Image.Staff_Height, Image.Aspect_Ratio, Image.Anti_Alias);
for Y in This.Image.Pixels'Range(1) loop
Target.Y := Integer(Center.Y * Image.Staff_Height / 400.0 +
Real(Y) + Image.Center.Y - This.Image.Center.Y);
if Target.Y in Image.Pixels'Range(1) then
for X in This.Image.Pixels'Range(2) loop
Target.X := Integer(Center.X * Image.Staff_Height / 400.0 +
Real(X) + Image.Center.X - This.Image.Center.X);
if Target.X in Image.Pixels'Range(2) then
if Darker(This.Image.Pixels(Y, X), Image.Pixels(Target.Y, Target.X)) then
Image.Pixels(Target.Y, Target.X) := This.Image.Pixels(Y, X);
end if;
end if;
end loop;
end if;
end loop;
end Print;
end Glyphs;
|