-- $Date: 2004/03/08 10:53:28 $
-- $Revision: 1.4 $
-- $Author: jcrocholl $
-- $Hash: 50f430c1f853b6476f3d61c0925aa9a8 $

-- This file was automatically created with ado.php.
-- Manual changes will be lost when it is updated.

with Choices.SVG;

package body Font_Loaders is

   -- Constructor for instances.
   function Create
     (Path    : in String;     -- The initial path.
      Special : in Percent)    -- The initial special.
     return Font_Loader_Access -- The newly created font loader.
   is
      Result : Font_Loader_Access := new Font_Loader;
   begin
      To_String_Access(Path, Result.Path);
      Result.Special := Special;
      Result.Choices := Choice_Hash_Tables.Create;
      return Result;
   end Create;

   -- Accessor to read the path of a font loader.
   function Get_Path
     (This : access Font_Loader-- The font loader to read from.
     return String is            -- The path of that font loader.
   begin
      return To_String(This.Path);
   end Get_Path;

   -- Accessor to read the special of a font loader.
   function Get_Special
     (This : access Font_Loader-- The font loader to read from.
     return Percent is           -- The special of that font loader.
   begin
      return This.Special;
   end Get_Special;

   function Glyph_Filename
     (This       : access Font_Loader-- The font loader object instance.
      Glyph_Name : in String)          -- Subdirectory and file name.
     return String is                  -- Full path of the SVG file.
   begin
      return
        To_String(This.Path) & '/' &
        Glyph_Name & ".svg";
   end Glyph_Filename;

   function Load_Glyph
     (This       : access Font_Loader-- The font loader object instance.
      Glyph_Name : in String)          -- Name of the glyph.
     return Glyph_Access               -- The newly created glyph.
   is
      use Choice_Hash_Tables;
      Choice : Choice_Access;
      Found  : Boolean;
   begin
      Get(This.Choices, Glyph_Name, Choice, Found);
      if not Found then
         Choice := SVG.Read(Glyph_Filename(This, Glyph_Name));
         Put(This.Choices, Glyph_Name, Choice);
      end if;
      return Choose(Choice, This.Special);
   exception
   when Ada.IO_Exceptions.Name_Error =>
      Raise_Exception(Glyph_Not_Found'Identity,
        Glyph_Filename(This, Glyph_Name));
   end Load_Glyph;

end Font_Loaders;