Hosted by
 |
with Ada.Command_Line; use Ada.Command_Line;
with Real_Numbers; use Real_Numbers;
with Real_Strings; use Real_Strings;
with Messages; use Messages;
with Glyphs; use Glyphs;
with Read_PBM; use Read_PBM;
with Stairs; use Stairs;
with Curves; use Curves;
with Transforms; use Transforms;
with EPS; use EPS;
procedure PBM2Glyph is
Index : Positive;
Exit_Now : Boolean;
Staff_Height : Real;
Center_X : Real;
Center_Y : Real;
Pixels : Boolean := False;
Straight : Boolean := False;
Debug : Boolean := False;
G : Glyph;
begin
User_Friendly("pbm2glyph", " ",
(
-"Read a PBM (Portable Bitmap) from standard input.",
-"Create an EPS (Encapsulated PostScript) from it.",
-"Perform some optimization, write to standard output."),
(
-" Staff height in pixels.",
-" Pixels from left to center.",
-" Pixels from top to center."),
(
-"-p, --pixels Don't remove pixel stairs, implies -s.",
-"-s, --straight Don't create cubic bezier curves.",
-"-d, --debug Add debugging markers in EPS output."),
Index, Exit_Now);
if Exit_Now then return; end if;
while Index <= Argument_Count - 3 loop
if Argument(Index) = "-q" or Argument(Index) = "--quiet" then null;
elsif Argument(Index) = "-p" or Argument(Index) = "--pixels" then Pixels := True;
elsif Argument(Index) = "-s" or Argument(Index) = "--straight" then Straight := True;
elsif Argument(Index) = "-d" or Argument(Index) = "--debug" then Debug := True;
else
Invalid_Option(Index);
return;
end if;
Index := Index + 1;
end loop;
if Index > Argument_Count - 2 then
Too_Few_Arguments;
return;
end if;
Staff_Height := To_Number(Argument(Index));
Center_X := To_Number(Argument(Index + 1));
Center_Y := To_Number(Argument(Index + 2));
Message("reading PBM from standard input");
G := Read_Current_Input;
if Outline_Lists.Count(Get_Outlines(G)) = 0 then
Message("no black pixels found");
Set_Exit_Status(Failure);
return;
end if;
if not Pixels then
Message("removing pixel stairs");
Stairs.Remove_Stairs(G, 2.5);
if not Straight then
Message("making cubic bezier curves");
Curves.Make_Cubic(G, 0.1);
Curves.Make_Cubic(G, 0.2);
Curves.Make_Cubic(G, 0.3);
Curves.Make_Cubic(G, 0.4);
Curves.Make_Cubic(G, 0.5);
end if;
end if;
Message("translating to center");
Translate(G, (-Center_X, Center_Y - Get_Height(G)));
Message("scaling to interline space");
Scale(G, 400.0 / Staff_Height);
Message("writing EPS to standard output");
Write(G, Debug);
Message("finished successfully");
end PBM2Glyph;
|