program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp,
Graphics,
LCLType, LCLIntf;
type
{ TMyApplication }
TMyApplication = class(TCustomApplication)
protected
procedure DoRun; override;
private
{ Private declarations }
procedure GenerateImages(fonts: array of string; texts: array of string; fontSize: Integer; folderName: string);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
{ TMyApplication }
procedure TMyApplication.DoRun;
var ErrorMsg: String;
begin
// quick check parameters
ErrorMsg:=CheckOptions('h', 'help');
if ErrorMsg<>'' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
// parse parameters
if HasOption('h', 'help') then begin
WriteHelp;
Terminate;
Exit;
end;
{ add your program here }
// stop program loop
Terminate;
end;
constructor TMyApplication.Create(TheOwner: TComponent);
inherited Create(TheOwner);
// První
const
fonts1: array[0..4] of string = ('Verdana', 'Roboto', 'Arial', 'Helvetica', 'sans-serif');
texts1: array[0..5] of string = ('Psalm 91:1', 'Slovo', 'AHK pro', 'Vygenerování zkušebních obrázků.', 'Vygenerování zkušebních obrázků.', 'Včera ráno, dnes odpoledne a v neděli večer');
fontSize1: Integer = 22;
folderName1: string = 'TestImages_22.4px';
// Druhý
const
fonts2: array[0..4] of string = ('Verdana', 'Roboto', 'Arial', 'Helvetica', 'sans-serif');
texts2: array[0..5] of string = ('Text analysis', 'Slovo', 'AHK pro', 'Vygenerování zkušebních obrázků.', 'Vygenerování zkušebních obrázků.', 'Včera ráno, dnes odpoledne a v neděli večer');
fontSize2: Integer = 16;
folderName2: string = 'TestImages_16px';
// Třetí
const
fonts3: array[0..2] of string = ('Arial', 'Helvetica', 'Sans-serif');
texts3: array[0..8] of string = ('Strong''s', 'Hebrew', 'English', 'Morphology', 'Slovo', 'AHK pro', 'Vygenerování zkušebních obrázků.', 'Vygenerování zkušebních obrázků.', 'Včera ráno, dnes odpoledne a v neděli večer');
fontSize3: Integer = 12;
folderName3: string = 'TestImages_12px';
const
const
fonts4: array[0..2] of string = ('Arial', 'Helvetica', 'Sans-serif');
texts4: array[0..5] of string = ('Go to Parallel Hebrew', 'Slovo', 'AHK pro', 'Vygenerování zkušebních obrázků.', 'Vygenerování zkušebních obrázků.', 'Včera ráno, dnes odpoledne a v neděli večer');
fontSize4: Integer = 16;
folderName4: string = 'TestImages_16px';
StopOnException:=True;
GenerateImages(fonts1, texts1, fontSize1, folderName1);
ShowMessage('První dávka zkušebních obrázků (22.4px) byla uložena do složky "' + folderName1 + '".');
GenerateImages(fonts2, texts2, fontSize2, folderName2);
ShowMessage('Druhá dávka zkušebních obrázků (16px) byla uložena do složky "' + folderName2 + '".');
GenerateImages(fonts3, texts3, fontSize3, folderName3);
ShowMessage('Třetí dávka zkušebních obrázků (12px) byla uložena do složky "' + folderName3 + '".');
GenerateImages(fonts4, texts4, fontSize4, folderName4);
ShowMessage('Čtvrtá dávka zkušebních obrázků (16px) byla uložena do složky "' + folderName4 + '".');
end;
destructor TMyApplication.Destroy;
begin
inherited Destroy;
end;
procedure TMyApplication.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ', ExeName, ' -h');
end;
procedure TMyApplication.GenerateImages(fonts: array of string; texts: array of string; fontSize: Integer; folderName: string);
var
bmp: TBitmap;
rect: TRect;
fileName: string;
i, j: Integer;
begin
bmp := TBitmap.Create;
try
for i := 0 to High(fonts) do
begin
for j := 0 to High(texts) do
begin
bmp.Width := 500;
bmp.Height := 100;
bmp.Canvas.Font.Name := fonts[i];
bmp.Canvas.Font.Size := fontSize;
fileName := IncludeTrailingPathDelimiter(folderName) + fonts[i] + ' ' + Copy(texts[j], 1, Pos(' ', texts[j]) - 1) + '.bmp';
bmp.Canvas.Brush.Color := clWhite;
bmp.Canvas.FillRect(bmp.Canvas.ClipRect);
bmp.Canvas.TextOut(0, 0, texts[j]);
bmp.SaveToFile(fileName);
end;
end;
finally
bmp.Free;
end;
end;
var
Application: TMyApplication;
begin
Application:=TMyApplication.Create(nil);
Application.Title:='My Application';
Application.Run;
Application.Free;
end.