-- $Date: 2004/01/13 03:33:26 $
-- $Revision: 1.3 $
-- $Author: jcrocholl $

with Ada.Command_Line; use Ada.Command_Line;

with Glyphs; use Glyphs;
with EPS;
with Glyph_Images; use Glyph_Images;
with Gray_Images; use Gray_Images;
with Real_Numbers; use Real_Numbers;
with Real_Strings; use Real_Strings;
with Messages; use Messages;
with PGM;

procedure Glyph2PGM is
   Index    : Positive-- Command line argument index.
   Exit_Now : Boolean;  -- Exit program instantly?

   Staff_Height : Real;

   G : Glyph;
   I : Glyph_Image;
begin
   User_Friendly("glyph2pgm", "",
     (
     -"Read an EPS (Encapsulated PostScript) from standard input.",
     -"Render it to grayscale raster graphics, with anti-alias.",
     -"Write a PGM (Portable Graymap) to standard output."),
     (1 =>
     -" Staff height in pixels."),
     No_Strings,
     Index, Exit_Now);
   if Exit_Now then return; end if;

   while Index < Argument_Count loop
      -- Debug("arg: " & Argument(Index));
      if Argument(Index) = "-q" or Argument(Index) = "--quiet" then null;
      else
         Invalid_Option(Index);
         return;
      end if;
      Index := Index + 1;
   end loop;

   if Index > Argument_Count then
      Too_Few_Arguments;
      return;
   end if;

   Staff_Height := To_Number(Argument(Index));

   Message("reading EPS from standard input");
   G := EPS.Read;

   Message("rendering glyph");
   I := Get_Image(G, Staff_Height, 1.0, 4);

   Message("writing PGM to standard output");
   PGM.Write(Gray_Image(I));

   Message("finished successfully");
end Glyph2PGM;