From 7227223c4e384de0c42f98535b37522271c8d555 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 22 Oct 2018 12:33:07 +0200 Subject: Initial commit --- .gitignore | 8 ++ fontgenerator.ico | Bin 0 -> 137040 bytes fontgenerator.lpi | 76 ++++++++++++++++++ fontgenerator.lpr | 21 +++++ fontgenerator.lps | 160 +++++++++++++++++++++++++++++++++++++ fontgenerator.res | Bin 0 -> 138932 bytes unit1.lfm | 104 ++++++++++++++++++++++++ unit1.pas | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 599 insertions(+) create mode 100644 .gitignore create mode 100644 fontgenerator.ico create mode 100644 fontgenerator.lpi create mode 100644 fontgenerator.lpr create mode 100644 fontgenerator.lps create mode 100644 fontgenerator.res create mode 100644 unit1.lfm create mode 100644 unit1.pas diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eadc06e --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.bak +*.ppu +*.o +*.tar.gz +*~ +fontgenerator +lib +backup diff --git a/fontgenerator.ico b/fontgenerator.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/fontgenerator.ico differ diff --git a/fontgenerator.lpi b/fontgenerator.lpi new file mode 100644 index 0000000..0c31f01 --- /dev/null +++ b/fontgenerator.lpi @@ -0,0 +1,76 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="fontgenerator.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="fontgenerator"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/fontgenerator.lpr b/fontgenerator.lpr new file mode 100644 index 0000000..bab3990 --- /dev/null +++ b/fontgenerator.lpr @@ -0,0 +1,21 @@ +program fontgenerator; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/fontgenerator.lps b/fontgenerator.lps new file mode 100644 index 0000000..3a14f8a --- /dev/null +++ b/fontgenerator.lps @@ -0,0 +1,160 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CONFIG> + <ProjectSession> + <Version Value="10"/> + <BuildModes Active="Default"/> + <Units Count="3"> + <Unit0> + <Filename Value="fontgenerator.lpr"/> + <IsPartOfProject Value="True"/> + <EditorIndex Value="-1"/> + <WindowIndex Value="-1"/> + <TopLine Value="-1"/> + <CursorPos X="-1" Y="-1"/> + <UsageCount Value="20"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + <IsVisibleTab Value="True"/> + <TopLine Value="137"/> + <CursorPos X="6" Y="157"/> + <UsageCount Value="20"/> + <Loaded Value="True"/> + <LoadedDesigner Value="True"/> + </Unit1> + <Unit2> + <Filename Value="/usr/lib/lazarus/lcl/include/customimage.inc"/> + <EditorIndex Value="-1"/> + <TopLine Value="25"/> + <CursorPos Y="46"/> + <UsageCount Value="10"/> + </Unit2> + </Units> + <JumpHistory Count="30" HistoryIndex="29"> + <Position1> + <Filename Value="unit1.pas"/> + <Caret Line="105" Column="30" TopLine="71"/> + </Position1> + <Position2> + <Filename Value="unit1.pas"/> + <Caret Line="104" Column="120" TopLine="93"/> + </Position2> + <Position3> + <Filename Value="unit1.pas"/> + <Caret Line="50" Column="28" TopLine="39"/> + </Position3> + <Position4> + <Filename Value="unit1.pas"/> + <Caret Line="71" Column="76" TopLine="52"/> + </Position4> + <Position5> + <Filename Value="unit1.pas"/> + <Caret Line="91" Column="39" TopLine="75"/> + </Position5> + <Position6> + <Filename Value="unit1.pas"/> + <Caret Line="162" TopLine="130"/> + </Position6> + <Position7> + <Filename Value="unit1.pas"/> + <Caret Line="159" Column="14" TopLine="135"/> + </Position7> + <Position8> + <Filename Value="unit1.pas"/> + <Caret Line="162" Column="43" TopLine="133"/> + </Position8> + <Position9> + <Filename Value="unit1.pas"/> + <Caret Line="154" TopLine="133"/> + </Position9> + <Position10> + <Filename Value="unit1.pas"/> + <Caret Line="155" TopLine="133"/> + </Position10> + <Position11> + <Filename Value="unit1.pas"/> + <Caret Line="156" TopLine="133"/> + </Position11> + <Position12> + <Filename Value="unit1.pas"/> + <Caret Line="157" TopLine="133"/> + </Position12> + <Position13> + <Filename Value="unit1.pas"/> + <Caret Line="158" TopLine="133"/> + </Position13> + <Position14> + <Filename Value="unit1.pas"/> + <Caret Line="159" TopLine="133"/> + </Position14> + <Position15> + <Filename Value="unit1.pas"/> + <Caret Line="160" TopLine="133"/> + </Position15> + <Position16> + <Filename Value="unit1.pas"/> + <Caret Line="161" TopLine="133"/> + </Position16> + <Position17> + <Filename Value="unit1.pas"/> + <Caret Line="162" TopLine="133"/> + </Position17> + <Position18> + <Filename Value="unit1.pas"/> + <Caret Line="164" TopLine="133"/> + </Position18> + <Position19> + <Filename Value="unit1.pas"/> + <Caret Line="165" TopLine="133"/> + </Position19> + <Position20> + <Filename Value="unit1.pas"/> + <Caret Line="52" TopLine="37"/> + </Position20> + <Position21> + <Filename Value="unit1.pas"/> + <Caret Line="160" Column="31" TopLine="135"/> + </Position21> + <Position22> + <Filename Value="unit1.pas"/> + <Caret Line="159" Column="43" TopLine="135"/> + </Position22> + <Position23> + <Filename Value="unit1.pas"/> + <Caret Line="163" TopLine="134"/> + </Position23> + <Position24> + <Filename Value="unit1.pas"/> + <Caret Line="161" Column="36" TopLine="134"/> + </Position24> + <Position25> + <Filename Value="unit1.pas"/> + <Caret Line="162" Column="3" TopLine="134"/> + </Position25> + <Position26> + <Filename Value="unit1.pas"/> + <Caret Line="155" Column="15" TopLine="134"/> + </Position26> + <Position27> + <Filename Value="unit1.pas"/> + <Caret Line="70" TopLine="52"/> + </Position27> + <Position28> + <Filename Value="unit1.pas"/> + <Caret Line="72" TopLine="54"/> + </Position28> + <Position29> + <Filename Value="unit1.pas"/> + <Caret Line="157" Column="55" TopLine="144"/> + </Position29> + <Position30> + <Filename Value="unit1.pas"/> + <Caret Line="156" Column="6" TopLine="136"/> + </Position30> + </JumpHistory> + </ProjectSession> +</CONFIG> diff --git a/fontgenerator.res b/fontgenerator.res new file mode 100644 index 0000000..877868c Binary files /dev/null and b/fontgenerator.res differ diff --git a/unit1.lfm b/unit1.lfm new file mode 100644 index 0000000..a72bf7c --- /dev/null +++ b/unit1.lfm @@ -0,0 +1,104 @@ +object Form1: TForm1 + Left = 264 + Height = 242 + Top = 211 + Width = 318 + Caption = 'Form1' + ClientHeight = 242 + ClientWidth = 318 + OnResize = FormResize + LCLVersion = '1.8.4.0' + object Image1: TImage + Left = 104 + Height = 232 + Top = 0 + Width = 210 + OnClick = Image1Click + end + object Button1: TButton + Left = 0 + Height = 25 + Top = 112 + Width = 100 + Caption = 'Speichern' + OnClick = Button1Click + TabOrder = 0 + end + object SpinEdit1: TSpinEdit + Left = 0 + Height = 27 + Top = 80 + Width = 100 + OnChange = SpinEdit1Change + TabOrder = 1 + Value = 8 + end + object ListBox1: TListBox + Left = 0 + Height = 80 + Top = 0 + Width = 100 + Items.Strings = ( + 'Bitmap' + 'C-Header' + ) + ItemHeight = 25 + ScrollWidth = 96 + TabOrder = 2 + end + object Button2: TButton + Left = 0 + Height = 25 + Top = 136 + Width = 100 + Caption = 'Laden' + OnClick = Button2Click + TabOrder = 3 + end + object SpinEdit2: TSpinEdit + Left = 0 + Height = 27 + Top = 167 + Width = 50 + OnChange = SpinEdit2Change + TabOrder = 4 + end + object SpinEdit3: TSpinEdit + Left = 50 + Height = 27 + Top = 167 + Width = 50 + OnChange = SpinEdit2Change + TabOrder = 5 + end + object SpinEdit4: TSpinEdit + Left = 0 + Height = 27 + Top = 195 + Width = 50 + OnChange = SpinEdit2Change + TabOrder = 6 + end + object SpinEdit5: TSpinEdit + Left = 50 + Height = 27 + Top = 195 + Width = 50 + OnChange = SpinEdit2Change + TabOrder = 7 + end + object SaveDialog1: TSaveDialog + left = 128 + top = 32 + end + object FontDialog1: TFontDialog + MinFontSize = 0 + MaxFontSize = 0 + left = 136 + top = 104 + end + object OpenDialog1: TOpenDialog + left = 184 + top = 160 + end +end 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. + -- cgit v1.2.3-70-g09d2