summaryrefslogtreecommitdiff
path: root/unit1.pas
diff options
context:
space:
mode:
Diffstat (limited to 'unit1.pas')
-rw-r--r--unit1.pas230
1 files changed, 230 insertions, 0 deletions
diff --git a/unit1.pas b/unit1.pas
new file mode 100644
index 0000000..a7e6ec7
--- /dev/null
+++ b/unit1.pas
@@ -0,0 +1,230 @@
+unit Unit1;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
+ ExtCtrls, Spin;
+
+type
+
+ { TForm1 }
+
+ TForm1 = class(TForm)
+ Button1: TButton;
+ Button2: TButton;
+ FontDialog1: TFontDialog;
+ Image1: TImage;
+ ListBox1: TListBox;
+ OpenDialog1: TOpenDialog;
+ SaveDialog1: TSaveDialog;
+ SpinEdit1: TSpinEdit;
+ SpinEdit2: TSpinEdit;
+ SpinEdit3: TSpinEdit;
+ SpinEdit4: TSpinEdit;
+ SpinEdit5: TSpinEdit;
+ procedure Button1Click(Sender: TObject);
+ procedure Button2Click(Sender: TObject);
+ procedure FormResize(Sender: TObject);
+ procedure Image1Click(Sender: TObject);
+ procedure SpinEdit1Change(Sender: TObject);
+ procedure SpinEdit2Change(Sender: TObject);
+ private
+ w,h,
+ xMinMin,xMaxMax,
+ yMinMin,yMaxMax,
+ xMin,xMax,
+ yMin,yMax: longint;
+ public
+
+ end;
+
+var
+ Form1: TForm1;
+
+implementation
+
+{$R *.lfm}
+
+uses math;
+
+{ TForm1 }
+
+procedure TForm1.SpinEdit1Change(Sender: TObject);
+var
+ c: char;
+ i,j,
+ xOf,yOf: longint;
+ b: boolean;
+begin
+ image1.canvas.font.size:=spinEdit1.value;
+ h:=image1.canvas.textHeight('X');
+ w:=image1.canvas.textWidth('X');
+ xMin:=w div 2;
+ xMax:=w div 2;
+ yMin:=h div 2;
+ yMax:=h div 2;
+ xMinMin:=-(w div 2);
+ xMaxMax:=w + (w div 2);
+ yMinMin:=-(h div 2);
+ yMaxMax:=h + (h div 2);
+ image1.canvas.rectangle(-1,-1,image1.width+1,image1.height+1);
+ for c:=#32 to #126 do begin
+ xOf:=2*w*(ord(c) mod 16)+w;
+ yOf:=2*h*(ord(c) div 16)+h;
+ image1.canvas.textOut(xOf,yOf,c);
+ if not (c in ['0'..'9','a'..'z','A'..'Z']) then
+ continue;
+ for i:=xMin downto xMinMin do begin
+ b:=false;
+ for j:=yMinMin to yMaxMax do
+ b:=b or (image1.picture.bitmap.canvas.pixels[xOf+i,yOf+j]<>$ffffff);
+ if not b then begin
+ xMin:=min(xMin,i+1);
+ break;
+ end;
+ end;
+ for i:=xMax to xMaxMax do begin
+ b:=false;
+ for j:=yMinMin to yMaxMax do
+ b:=b or (image1.picture.bitmap.canvas.pixels[xOf+i,yOf+j]<>$ffffff);
+ if not b then begin
+ xMax:=max(xMax,i-1);
+ break;
+ end;
+ end;
+ for i:=yMin downto yMinMin do begin
+ b:=false;
+ for j:=xMinMin to xMaxMax do
+ b:=b or (image1.picture.bitmap.canvas.pixels[xOf+j,yOf+i]<>$ffffff);
+ if not b then begin
+ yMin:=min(yMin,i+1);
+ break;
+ end;
+ end;
+ for i:=yMax to yMaxMax do begin
+ b:=false;
+ for j:=xMinMin to xMaxMax do
+ b:=b or (image1.picture.bitmap.canvas.pixels[xOf+j,yOf+i]<>$ffffff);
+ if not b then begin
+ yMax:=max(yMax,i-1);
+ break;
+ end;
+ end;
+ end;
+ form1.caption:=intToStr(w)+'x'+intToStr(h)+' ('+intToStr(xMin)+'..'+intToStr(xMax)+'x'+intToStr(yMin)+'..'+intToStr(yMax)+')';
+end;
+
+procedure TForm1.SpinEdit2Change(Sender: TObject);
+var
+ c: char;
+ i,j,xOf,yOf: longint;
+ warn: byte;
+ s: string;
+begin
+ s:='';
+ for c:=#32 to #126 do begin
+ xOf:=2*w*(ord(c) mod 16)+w+spinEdit2.value;
+ yOf:=2*h*(ord(c) div 16)+h+spinEdit3.value;
+ warn:=0;
+ for i:=xMinMin to -1 do
+ for j:=yMinMin to yMaxMax do
+ warn:=warn or byte(image1.picture.bitmap.canvas.pixels[xOf+i,yOf+j]<>$ffffff);
+ if spinEdit4.value>0 then
+ for i:=spinEdit4.value to xMaxMax do
+ for j:=yMinMin to yMaxMax do
+ warn:=warn or (byte(image1.picture.bitmap.canvas.pixels[xOf+i,yOf+j]<>$ffffff) shl 2);
+ for i:=yMinMin to -1 do
+ for j:=xMinMin to xMaxMax do
+ warn:=warn or (byte(image1.picture.bitmap.canvas.pixels[xOf+j,yOf+i]<>$ffffff) shl 3);
+ if spinEdit5.value>0 then
+ for i:=spinEdit5.value to yMaxMax do
+ for j:=xMinMin to xMaxMax do
+ warn:=warn or (byte(image1.picture.bitmap.canvas.pixels[xOf+j,yOf+i]<>$ffffff) shl 1);
+ if warn<>0 then
+ s:=s+''''+c+''': '+intToStr(warn)+#13;
+ end;
+ if s<>'' then
+ messageDlg(s,mtInformation,[mbOk],0);
+end;
+
+procedure TForm1.Button1Click(Sender: TObject);
+var
+ f: textFile;
+ c,d: char;
+ i,j,xOf,yOf: longint;
+begin
+ if saveDialog1.execute then
+ case listBox1.itemIndex of
+ 0:
+ image1.picture.saveToFile(saveDialog1.fileName);
+ 1: begin
+ assignFile(f,saveDialog1.fileName);
+ rewrite(f);
+ writeln(f,'char const symbols['+intToStr(126+1-32)+'*'+intToStr(spinEdit4.value)+'] = {');
+ for c:=#32 to #126 do begin
+ xOf:=2*w*(ord(c) mod 16)+w+spinEdit2.value;
+ yOf:=2*h*(ord(c) div 16)+h+spinEdit3.value;
+ write(f,' ');
+ for i:=0 to spinEdit4.value-1 do begin
+ d:=#0;
+ for j:=0 to min(7,spinEdit5.value) do
+ if image1.picture.bitmap.canvas.pixels[xOf+i,yOf+j] and $ff<$80 then
+ d:=char(ord(d) or (1 shl j));
+ write(f,'0x'+intToHex(ord(d),2));
+ if i<w-1 then
+ write(f,',');
+ end;
+ if c<#126 then
+ write(f,',')
+ else
+ write(f,' ');
+ write(f,' // ');
+ case c of
+ ' ': writeln(f,'space');
+ '\': writeln(f,'backslash');
+ else writeln(f,c);
+ end{of case};
+ end;
+ writeln(f,'};');
+ closeFile(f);
+ end;
+ end{of case};
+end;
+
+procedure TForm1.Button2Click(Sender: TObject);
+begin
+ if openDialog1.execute then begin
+ image1.picture.loadFromFile(openDialog1.fileName);
+ spinEdit2.onChange(sender);
+ end;
+end;
+
+procedure TForm1.FormResize(Sender: TObject);
+var
+ i: tImage;
+begin
+ i:=tImage.create(form1);
+ i.top:=image1.top;
+ i.left:=image1.left;
+ i.onClick:=image1.onClick;
+ i.width:=form1.clientWidth-i.left;
+ i.height:=form1.clientHeight-i.top;
+ i.parent:=image1.parent;
+ i.canvas.font:=image1.canvas.font;
+ image1.free;
+ image1:=i;
+ spinEdit1.onChange(sender);
+end;
+
+procedure TForm1.Image1Click(Sender: TObject);
+begin
+ if fontDialog1.execute then
+ image1.canvas.font:=fontDialog1.font;
+ spinEdit1.onChange(sender);
+end;
+
+end.
+