Added a new font loader.

Fonts are loaded at the first script start.



git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@330 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-12-24 11:04:53 +00:00
parent 5a28193dce
commit d5ee9fdbc5
9 changed files with 685 additions and 455 deletions

View File

@ -7,7 +7,7 @@
<TargetFileExt Value=""/>
<Icon Value="0"/>
<UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="0"/>
<ActiveEditorIndexAtStart Value="7"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -31,12 +31,12 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="19">
<Units Count="20">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<UsageCount Value="59"/>
<UsageCount Value="67"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
@ -44,10 +44,10 @@
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
<CursorPos X="30" Y="85"/>
<TopLine Value="66"/>
<CursorPos X="103" Y="81"/>
<TopLine Value="67"/>
<EditorIndex Value="0"/>
<UsageCount Value="59"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
@ -76,16 +76,16 @@
<CursorPos X="25" Y="50"/>
<TopLine Value="31"/>
<EditorIndex Value="4"/>
<UsageCount Value="30"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<UnitName Value="ocr"/>
<CursorPos X="10" Y="583"/>
<TopLine Value="387"/>
<CursorPos X="73" Y="16"/>
<TopLine Value="1"/>
<EditorIndex Value="6"/>
<UsageCount Value="30"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
@ -93,17 +93,17 @@
<UnitName Value="bitmaps"/>
<CursorPos X="18" Y="81"/>
<TopLine Value="47"/>
<EditorIndex Value="11"/>
<UsageCount Value="29"/>
<EditorIndex Value="12"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<UnitName Value="ocrutil"/>
<CursorPos X="45" Y="281"/>
<TopLine Value="249"/>
<CursorPos X="39" Y="208"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="29"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
@ -117,8 +117,8 @@
<UnitName Value="tpa"/>
<CursorPos X="5" Y="557"/>
<TopLine Value="535"/>
<EditorIndex Value="10"/>
<UsageCount Value="27"/>
<EditorIndex Value="11"/>
<UsageCount Value="31"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
@ -126,8 +126,8 @@
<UnitName Value="mufasatypesutil"/>
<CursorPos X="25" Y="8"/>
<TopLine Value="1"/>
<EditorIndex Value="8"/>
<UsageCount Value="26"/>
<EditorIndex Value="9"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
@ -136,7 +136,7 @@
<CursorPos X="78" Y="455"/>
<TopLine Value="432"/>
<EditorIndex Value="5"/>
<UsageCount Value="23"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
</Unit11>
<Unit12>
@ -155,9 +155,9 @@
<Filename Value="../../Units/MMLCore/files.pas"/>
<UnitName Value="files"/>
<CursorPos X="7" Y="103"/>
<TopLine Value="73"/>
<EditorIndex Value="7"/>
<UsageCount Value="20"/>
<TopLine Value="34"/>
<EditorIndex Value="8"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
@ -172,17 +172,17 @@
<UnitName Value="windowselector"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="9"/>
<UsageCount Value="12"/>
<EditorIndex Value="10"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit16>
<Unit17>
<Filename Value="../../Units/MMLCore/window.pas"/>
<UnitName Value="Window"/>
<CursorPos X="8" Y="612"/>
<TopLine Value="598"/>
<CursorPos X="94" Y="338"/>
<TopLine Value="323"/>
<EditorIndex Value="2"/>
<UsageCount Value="11"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
@ -191,130 +191,140 @@
<CursorPos X="1" Y="1"/>
<TopLine Value="277"/>
<EditorIndex Value="1"/>
<UsageCount Value="10"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fontloader"/>
<CursorPos X="34" Y="121"/>
<TopLine Value="89"/>
<EditorIndex Value="7"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit19>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="53" Column="20" TopLine="15"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="191" Column="50" TopLine="183"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="45" Column="65" TopLine="39"/>
<Caret Line="9" Column="66" TopLine="1"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="119" Column="5" TopLine="93"/>
<Caret Line="34" Column="16" TopLine="1"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="30" Column="68" TopLine="6"/>
<Caret Line="149" Column="13" TopLine="117"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="105" Column="3" TopLine="73"/>
<Caret Line="135" Column="69" TopLine="124"/>
</Position5>
<Position6>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="12" Column="77" TopLine="1"/>
<Caret Line="340" Column="78" TopLine="325"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="37" Column="77" TopLine="26"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="62" Column="64" TopLine="46"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="619" Column="28" TopLine="592"/>
<Filename Value="unit1.pas"/>
<Caret Line="91" Column="43" TopLine="74"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="527" Column="41" TopLine="496"/>
<Filename Value="unit1.pas"/>
<Caret Line="89" Column="13" TopLine="71"/>
</Position9>
<Position10>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="57" Column="21" TopLine="37"/>
<Filename Value="../../Units/MMLCore/mufasatypesutil.pas"/>
<Caret Line="8" Column="25" TopLine="1"/>
</Position10>
<Position11>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="467" Column="18" TopLine="448"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="71" Column="47" TopLine="51"/>
</Position11>
<Position12>
<Filename Value="../../Units/MMLAddon/tpa.pas"/>
<Caret Line="50" Column="33" TopLine="30"/>
<Filename Value="unit1.pas"/>
<Caret Line="91" Column="1" TopLine="67"/>
</Position12>
<Position13>
<Filename Value="unit1.pas"/>
<Caret Line="111" Column="35" TopLine="97"/>
<Caret Line="85" Column="41" TopLine="66"/>
</Position13>
<Position14>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="468" Column="38" TopLine="445"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="46" Column="37" TopLine="16"/>
</Position14>
<Position15>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="469" Column="26" TopLine="445"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="40" Column="1" TopLine="16"/>
</Position15>
<Position16>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="486" Column="18" TopLine="467"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="54" Column="20" TopLine="23"/>
</Position16>
<Position17>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="634" Column="41" TopLine="293"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="59" Column="1" TopLine="25"/>
</Position17>
<Position18>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="191" Column="50" TopLine="183"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="63" Column="22" TopLine="28"/>
</Position18>
<Position19>
<Filename Value="unit1.pas"/>
<Caret Line="9" Column="66" TopLine="1"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="60" Column="28" TopLine="31"/>
</Position19>
<Position20>
<Filename Value="unit1.pas"/>
<Caret Line="34" Column="16" TopLine="1"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="79" Column="59" TopLine="58"/>
</Position20>
<Position21>
<Filename Value="unit1.pas"/>
<Caret Line="149" Column="13" TopLine="117"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="101" Column="18" TopLine="71"/>
</Position21>
<Position22>
<Filename Value="unit1.pas"/>
<Caret Line="135" Column="69" TopLine="124"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="65" Column="13" TopLine="56"/>
</Position22>
<Position23>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="340" Column="78" TopLine="325"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="128" Column="18" TopLine="100"/>
</Position23>
<Position24>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="62" Column="64" TopLine="46"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="57" Column="21" TopLine="39"/>
</Position24>
<Position25>
<Filename Value="unit1.pas"/>
<Caret Line="91" Column="43" TopLine="74"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="143" Column="16" TopLine="109"/>
</Position25>
<Position26>
<Filename Value="unit1.pas"/>
<Caret Line="89" Column="13" TopLine="71"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="114" Column="30" TopLine="96"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLCore/mufasatypesutil.pas"/>
<Caret Line="8" Column="25" TopLine="1"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="105" Column="14" TopLine="78"/>
</Position27>
<Position28>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="71" Column="47" TopLine="51"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="103" Column="9" TopLine="85"/>
</Position28>
<Position29>
<Filename Value="unit1.pas"/>
<Caret Line="91" Column="1" TopLine="67"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="176" Column="56" TopLine="145"/>
</Position29>
<Position30>
<Filename Value="unit1.pas"/>
<Caret Line="85" Column="41" TopLine="66"/>
<Caret Line="80" Column="59" TopLine="40"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -7,7 +7,7 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Unit1, LResources
Forms, Unit1, LResources, fontloader
{ you can add units after this };
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

View File

@ -1,7 +1,7 @@
object Form1: TForm1
Left = 462
Left = 474
Height = 306
Top = 264
Top = 430
Width = 609
ActiveControl = BitmapButton
Caption = 'Form1'

View File

@ -1,169 +1,170 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Client, MufasaTypes, Bitmaps, ocr, windowselector,window;
type
{ TForm1 }
TForm1 = class(TForm)
BitmapButton: TButton;
FShadow: TCheckBox;
PathButton: TButton;
OCRButton: TButton;
Image1: TImage;
OCRFileOpen: TOpenDialog;
ClientButton: TToggleBox;
UpCharsDialog: TSelectDirectoryDialog;
procedure BitmapButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OCRButtonClick(Sender: TObject);
procedure PathButtonClick(Sender: TObject);
procedure SelectClient(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
BitmapPath: String;
FontPath: String;
CliW: TMWindow;
UseClient: Boolean;
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
uses
lclintf, lcltype;
{ TForm1 }
procedure TForm1.OCRButtonClick(Sender: TObject);
Var
C: TClient;
bmp: TMufasaBitmap;
x,y: integer;
s: string;
Shadow: boolean;
t: dword;
begin
if not FileExists(BitmapPath) and not UseClient then
begin
MessageBox(0,pchar('You did not set a valid bitmap'), Pchar('Bitmap Error'),
MB_OK);
if OCRFileOpen.Execute then
BitmapPath := OCRFileOpen.FileName;
Exit;
end;
if not DirectoryExists(FontPath) then
begin
MessageBox(0,pchar('You did not set a FontPath' ), Pchar('Path Error'),
MB_OK);
if UpCharsDialog.Execute then
FontPath := UpCharsDialog.FileName;
Exit;
end;
Form1.Image1.Canvas.Brush.Color := 0;
Form1.Image1.Canvas.Rectangle(0, 0, Form1.Image1.Canvas.Width, Form1.Image1.Canvas.Height);
// create and init client
C := TClient.Create;
bmp := TMufasaBitmap.Create;
if UseClient then
C.MWindow.SetWindow(CliW)
else
begin
bmp.LoadFromFile(BitmapPath);
C.MWindow.SetTarget(bmp);
end;
Shadow :=FShadow.Checked;
// DS + .. + DS because InitOCR wants the directory of the Fonts, not UpChars
// only.
C.MOCR.InitTOCR(FontPath + DS, Shadow);
t:=gettickcount;
s := C.MOCR.GetUpTextAtEx(7, 7, Shadow);
writeln(inttostr(gettickcount-t));
// write to debugbmp
{$IFDEF OCRDEBUG}
for y := 0 to C.MOCR.debugbmp.Height - 1 do
for x := 0 to C.MOCR.debugbmp.Width -1 do
Form1.Image1.Canvas.Pixels[x,y] := C.MOCR.debugbmp.FastGetPixel(x,y);
// print ocr'ed text
Form1.Image1.Canvas.Font.Color:=clRed;
Form1.Image1.Canvas.TextOut(0, C.MOCR.debugbmp.Height, s);
C.MOCR.debugbmp.Free;
{$ELSE}
Form1.Image1.Canvas.Font.Color:=clRed;
Form1.Image1.Canvas.TextOut(0, 0, s);
{$ENDIF}
{$IFDEF OCRDEBUG}
Form1.Image1.Picture.SaveToFile(OCRDebugPath + 'ocrbench.bmp');
{$ENDIF}
bmp.Free;
C.Free;
Application.ProcessMessages;
end;
procedure TForm1.BitmapButtonClick(Sender: TObject);
begin
if OCRFileOpen.Execute then
begin
BitmapPath := OCRFileOpen.FileName;
UseClient:=False;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
UseClient := False;
{BitmapPath := '/home/merlijn/Programs/mufasa/pics/uptext4.bmp'; }
FontPath := '/home/merlijn/Programs/mufasa/Fonts/';
end;
procedure TForm1.PathButtonClick(Sender: TObject);
begin
if UpCharsDialog.Execute then
FontPath := UpCharsDialog.FileName;
end;
procedure TForm1.SelectClient(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var
WS: TMWindowSelector;
begin
UseClient := True;
if not assigned(CliW) then
CliW := TMWindow.Create;
WS := TMWindowSelector.Create(CliW);
CliW.SetTarget(WS.Drag{$IFDEF WINDOWS},w_Window{$ENDIF});
end;
initialization
{$I unit1.lrs}
end.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Client, MufasaTypes, Bitmaps, ocr, windowselector,window;
type
{ TForm1 }
TForm1 = class(TForm)
BitmapButton: TButton;
FShadow: TCheckBox;
PathButton: TButton;
OCRButton: TButton;
Image1: TImage;
OCRFileOpen: TOpenDialog;
ClientButton: TToggleBox;
UpCharsDialog: TSelectDirectoryDialog;
procedure BitmapButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OCRButtonClick(Sender: TObject);
procedure PathButtonClick(Sender: TObject);
procedure SelectClient(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
BitmapPath: String;
FontPath: String;
CliW: TMWindow;
UseClient: Boolean;
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
uses
lclintf, lcltype;
{ TForm1 }
procedure TForm1.OCRButtonClick(Sender: TObject);
Var
C: TClient;
bmp: TMufasaBitmap;
x,y: integer;
s: string;
Shadow: boolean;
t: dword;
begin
if not FileExists(BitmapPath) and not UseClient then
begin
MessageBox(0,pchar('You did not set a valid bitmap'), Pchar('Bitmap Error'),
MB_OK);
if OCRFileOpen.Execute then
BitmapPath := OCRFileOpen.FileName;
Exit;
end;
if not DirectoryExists(FontPath) then
begin
MessageBox(0,pchar('You did not set a FontPath' ), Pchar('Path Error'),
MB_OK);
if UpCharsDialog.Execute then
FontPath := UpCharsDialog.FileName;
Exit;
end;
Form1.Image1.Canvas.Brush.Color := 0;
Form1.Image1.Canvas.Rectangle(0, 0, Form1.Image1.Canvas.Width, Form1.Image1.Canvas.Height);
// create and init client
C := TClient.Create;
bmp := TMufasaBitmap.Create;
if UseClient then
C.MWindow.SetWindow(CliW)
else
begin
bmp.LoadFromFile(BitmapPath);
C.MWindow.SetTarget(bmp);
end;
Shadow :=FShadow.Checked;
// DS + .. + DS because InitOCR wants the directory of the Fonts, not UpChars
// only.
C.MOCR.InitTOCR(FontPath + DS);
C.MOCR.SetFonts(C.MOCR.GetFonts);
t:=gettickcount;
s := C.MOCR.GetUpTextAtEx(7, 7, Shadow);
writeln(inttostr(gettickcount-t));
// write to debugbmp
{$IFDEF OCRDEBUG}
for y := 0 to C.MOCR.debugbmp.Height - 1 do
for x := 0 to C.MOCR.debugbmp.Width -1 do
Form1.Image1.Canvas.Pixels[x,y] := C.MOCR.debugbmp.FastGetPixel(x,y);
// print ocr'ed text
Form1.Image1.Canvas.Font.Color:=clRed;
Form1.Image1.Canvas.TextOut(0, C.MOCR.debugbmp.Height, s);
C.MOCR.debugbmp.Free;
{$ELSE}
Form1.Image1.Canvas.Font.Color:=clRed;
Form1.Image1.Canvas.TextOut(0, 0, s);
{$ENDIF}
{$IFDEF OCRDEBUG}
Form1.Image1.Picture.SaveToFile(OCRDebugPath + 'ocrbench.bmp');
{$ENDIF}
bmp.Free;
C.Free;
Application.ProcessMessages;
end;
procedure TForm1.BitmapButtonClick(Sender: TObject);
begin
if OCRFileOpen.Execute then
begin
BitmapPath := OCRFileOpen.FileName;
UseClient:=False;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
UseClient := False;
{BitmapPath := '/home/merlijn/Programs/mufasa/pics/uptext4.bmp'; }
FontPath := '/home/merlijn/Programs/mufasa/Fonts/';
end;
procedure TForm1.PathButtonClick(Sender: TObject);
begin
if UpCharsDialog.Execute then
FontPath := UpCharsDialog.FileName;
end;
procedure TForm1.SelectClient(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var
WS: TMWindowSelector;
begin
UseClient := True;
if not assigned(CliW) then
CliW := TMWindow.Create;
WS := TMWindowSelector.Create(CliW);
CliW.SetTarget(WS.Drag{$IFDEF WINDOWS},w_Window{$ENDIF});
end;
initialization
{$I unit1.lrs}
end.

View File

@ -10,7 +10,7 @@
<TargetFileExt Value=""/>
<Title Value="Mufasa Stand Alone"/>
<UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="7"/>
<ActiveEditorIndexAtStart Value="8"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -36,14 +36,14 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="267">
<Units Count="270">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="100" Y="21"/>
<TopLine Value="6"/>
<EditorIndex Value="18"/>
<TopLine Value="1"/>
<EditorIndex Value="16"/>
<UsageCount Value="205"/>
<Loaded Value="True"/>
</Unit0>
@ -139,9 +139,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/>
<CursorPos X="39" Y="668"/>
<TopLine Value="656"/>
<EditorIndex Value="6"/>
<CursorPos X="57" Y="467"/>
<TopLine Value="449"/>
<EditorIndex Value="5"/>
<UsageCount Value="202"/>
<Loaded Value="True"/>
</Unit13>
@ -197,8 +197,8 @@
<IsPartOfProject Value="True"/>
<UnitName Value="Client"/>
<CursorPos X="101" Y="48"/>
<TopLine Value="48"/>
<EditorIndex Value="1"/>
<TopLine Value="46"/>
<EditorIndex Value="0"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit21>
@ -206,9 +206,9 @@
<Filename Value="../../Units/MMLCore/mufasatypes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="MufasaTypes"/>
<CursorPos X="32" Y="100"/>
<TopLine Value="100"/>
<EditorIndex Value="0"/>
<CursorPos X="3" Y="34"/>
<TopLine Value="16"/>
<EditorIndex Value="6"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit22>
@ -233,7 +233,7 @@
<UnitName Value="Window"/>
<CursorPos X="22" Y="63"/>
<TopLine Value="44"/>
<EditorIndex Value="3"/>
<EditorIndex Value="2"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit25>
@ -247,10 +247,10 @@
<Unit27>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<UnitName Value="windowutil"/>
<CursorPos X="23" Y="8"/>
<CursorPos X="56" Y="17"/>
<TopLine Value="1"/>
<EditorIndex Value="22"/>
<UsageCount Value="94"/>
<EditorIndex Value="20"/>
<UsageCount Value="95"/>
<Loaded Value="True"/>
</Unit27>
<Unit28>
@ -266,7 +266,7 @@
<UnitName Value="finder"/>
<CursorPos X="58" Y="23"/>
<TopLine Value="1"/>
<EditorIndex Value="13"/>
<EditorIndex Value="11"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit29>
@ -350,7 +350,7 @@
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<CursorPos X="117" Y="32"/>
<TopLine Value="4"/>
<EditorIndex Value="20"/>
<EditorIndex Value="18"/>
<UsageCount Value="100"/>
<Loaded Value="True"/>
</Unit41>
@ -372,7 +372,7 @@
<UnitName Value="bitmaps"/>
<CursorPos X="14" Y="82"/>
<TopLine Value="63"/>
<EditorIndex Value="2"/>
<EditorIndex Value="1"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit44>
@ -539,9 +539,7 @@
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/other.inc"/>
<CursorPos X="56" Y="46"/>
<TopLine Value="25"/>
<EditorIndex Value="10"/>
<UsageCount Value="46"/>
<Loaded Value="True"/>
</Unit69>
<Unit70>
<Filename Value="../../Units/PascalScript/uPSCompiler.pas"/>
@ -653,8 +651,8 @@
<IsPartOfProject Value="True"/>
<UnitName Value="dtm"/>
<CursorPos X="62" Y="135"/>
<TopLine Value="1"/>
<EditorIndex Value="19"/>
<TopLine Value="12"/>
<EditorIndex Value="17"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit86>
@ -671,7 +669,7 @@
<UnitName Value="colourpicker"/>
<CursorPos X="93" Y="170"/>
<TopLine Value="155"/>
<EditorIndex Value="16"/>
<EditorIndex Value="13"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit88>
@ -698,7 +696,7 @@
<UnitName Value="windowselector"/>
<CursorPos X="54" Y="139"/>
<TopLine Value="116"/>
<EditorIndex Value="15"/>
<EditorIndex Value="12"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit91>
@ -734,7 +732,7 @@
<UnitName Value="dtmutil"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="151"/>
<EditorIndex Value="17"/>
<EditorIndex Value="15"/>
<UsageCount Value="206"/>
<Loaded Value="True"/>
</Unit96>
@ -749,8 +747,8 @@
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/dtm.inc"/>
<CursorPos X="33" Y="34"/>
<TopLine Value="30"/>
<EditorIndex Value="21"/>
<UsageCount Value="53"/>
<EditorIndex Value="19"/>
<UsageCount Value="54"/>
<Loaded Value="True"/>
</Unit98>
<Unit99>
@ -814,9 +812,9 @@
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ocr"/>
<CursorPos X="51" Y="251"/>
<TopLine Value="14"/>
<EditorIndex Value="11"/>
<CursorPos X="24" Y="161"/>
<TopLine Value="145"/>
<EditorIndex Value="7"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit107>
@ -886,10 +884,8 @@
<Unit118>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/window.inc"/>
<CursorPos X="50" Y="41"/>
<TopLine Value="26"/>
<EditorIndex Value="9"/>
<TopLine Value="20"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit118>
<Unit119>
<Filename Value="../../../FPC/FPCCheckout/rtl/objpas/classes/compon.inc"/>
@ -1141,9 +1137,7 @@
<UnitName Value="framescript"/>
<CursorPos X="59" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="8"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit151>
<Unit152>
<Filename Value="framesynedit.lrs"/>
@ -1363,10 +1357,10 @@
</Unit184>
<Unit185>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/ocr.inc"/>
<CursorPos X="55" Y="5"/>
<CursorPos X="55" Y="4"/>
<TopLine Value="1"/>
<EditorIndex Value="12"/>
<UsageCount Value="41"/>
<EditorIndex Value="10"/>
<UsageCount Value="42"/>
<Loaded Value="True"/>
</Unit185>
<Unit186>
@ -1458,9 +1452,9 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="colourhistory"/>
<CursorPos X="81" Y="189"/>
<TopLine Value="174"/>
<EditorIndex Value="4"/>
<UsageCount Value="162"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="164"/>
<Loaded Value="True"/>
</Unit198>
<Unit199>
@ -1711,7 +1705,7 @@
<UnitName Value="about"/>
<CursorPos X="44" Y="21"/>
<TopLine Value="4"/>
<UsageCount Value="125"/>
<UsageCount Value="127"/>
</Unit235>
<Unit236>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/file.inc"/>
@ -1725,7 +1719,7 @@
<UnitName Value="internets"/>
<CursorPos X="87" Y="3"/>
<TopLine Value="1"/>
<UsageCount Value="119"/>
<UsageCount Value="121"/>
</Unit237>
<Unit238>
<Filename Value="debugimageform.pas"/>
@ -1734,7 +1728,7 @@
<UnitName Value="debugimageform"/>
<CursorPos X="20" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="106"/>
<UsageCount Value="108"/>
</Unit238>
<Unit239>
<Filename Value="debugimage.pas"/>
@ -1744,8 +1738,8 @@
<UnitName Value="debugimage"/>
<CursorPos X="59" Y="23"/>
<TopLine Value="37"/>
<EditorIndex Value="5"/>
<UsageCount Value="105"/>
<EditorIndex Value="4"/>
<UsageCount Value="107"/>
<Loaded Value="True"/>
</Unit239>
<Unit240>
@ -1817,10 +1811,10 @@
<Unit250>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<UnitName Value="ocrutil"/>
<CursorPos X="57" Y="165"/>
<TopLine Value="145"/>
<EditorIndex Value="14"/>
<UsageCount Value="41"/>
<CursorPos X="78" Y="32"/>
<TopLine Value="1"/>
<EditorIndex Value="9"/>
<UsageCount Value="42"/>
<Loaded Value="True"/>
</Unit250>
<Unit251>
@ -1909,11 +1903,9 @@
<ComponentName Value="FunctionListFrame"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="framefunctionlist"/>
<CursorPos X="103" Y="54"/>
<TopLine Value="50"/>
<EditorIndex Value="7"/>
<UsageCount Value="26"/>
<Loaded Value="True"/>
<CursorPos X="46" Y="76"/>
<TopLine Value="45"/>
<UsageCount Value="28"/>
</Unit263>
<Unit264>
<Filename Value="../../../../../../usr/local/share/lazarus/lcl/comctrls.pp"/>
@ -1935,127 +1927,152 @@
<TopLine Value="1"/>
<UsageCount Value="10"/>
</Unit266>
<Unit267>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<UnitName Value="fontloader"/>
<CursorPos X="58" Y="217"/>
<TopLine Value="185"/>
<EditorIndex Value="8"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit267>
<Unit268>
<Filename Value="../../Units/MMLCore/mufasatypesutil.pas"/>
<UnitName Value="mufasatypesutil"/>
<CursorPos X="69" Y="43"/>
<TopLine Value="23"/>
<EditorIndex Value="14"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit268>
<Unit269>
<Filename Value="../../Units/MMLCore/ocrold.pas"/>
<UnitName Value="ocr"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="441"/>
<UsageCount Value="10"/>
</Unit269>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="testunit.pas"/>
<Caret Line="348" Column="20" TopLine="336"/>
<Caret Line="1237" Column="46" TopLine="1225"/>
</Position1>
<Position2>
<Filename Value="testunit.pas"/>
<Caret Line="1086" Column="3" TopLine="1084"/>
<Caret Line="1251" Column="43" TopLine="1239"/>
</Position2>
<Position3>
<Filename Value="testunit.pas"/>
<Caret Line="1076" Column="43" TopLine="1070"/>
<Caret Line="1261" Column="63" TopLine="1239"/>
</Position3>
<Position4>
<Filename Value="testunit.pas"/>
<Caret Line="1056" Column="3" TopLine="1054"/>
<Caret Line="1271" Column="41" TopLine="1259"/>
</Position4>
<Position5>
<Filename Value="testunit.pas"/>
<Caret Line="1066" Column="3" TopLine="1064"/>
<Caret Line="1276" Column="43" TopLine="1259"/>
</Position5>
<Position6>
<Filename Value="testunit.pas"/>
<Caret Line="1073" Column="3" TopLine="1070"/>
<Caret Line="33" Column="82" TopLine="25"/>
</Position6>
<Position7>
<Filename Value="testunit.pas"/>
<Caret Line="3" Column="110" TopLine="1"/>
<Caret Line="3" Column="50" TopLine="1"/>
</Position7>
<Position8>
<Filename Value="testunit.pas"/>
<Caret Line="290" Column="23" TopLine="278"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="77" Column="57" TopLine="58"/>
</Position8>
<Position9>
<Filename Value="testunit.pas"/>
<Caret Line="630" Column="26" TopLine="618"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="31" Column="28" TopLine="1"/>
</Position9>
<Position10>
<Filename Value="testunit.pas"/>
<Caret Line="789" Column="13" TopLine="777"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="114" Column="45" TopLine="79"/>
</Position10>
<Position11>
<Filename Value="testunit.pas"/>
<Caret Line="791" Column="13" TopLine="777"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="134" Column="19" TopLine="115"/>
</Position11>
<Position12>
<Filename Value="framefunctionlist.pas"/>
<Caret Line="41" Column="19" TopLine="31"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="200" Column="15" TopLine="178"/>
</Position12>
<Position13>
<Filename Value="framefunctionlist.pas"/>
<Caret Line="48" Column="57" TopLine="39"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="150" Column="41" TopLine="132"/>
</Position13>
<Position14>
<Filename Value="testunit.pas"/>
<Caret Line="988" Column="13" TopLine="987"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="153" Column="52" TopLine="132"/>
</Position14>
<Position15>
<Filename Value="testunit.pas"/>
<Caret Line="987" Column="13" TopLine="987"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="40" Column="72" TopLine="23"/>
</Position15>
<Position16>
<Filename Value="testunit.pas"/>
<Caret Line="992" Column="23" TopLine="987"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="560" Column="40" TopLine="542"/>
</Position16>
<Position17>
<Filename Value="testunit.pas"/>
<Caret Line="991" Column="23" TopLine="987"/>
<Caret Line="5" Column="123" TopLine="1"/>
</Position17>
<Position18>
<Filename Value="framefunctionlist.pas"/>
<Caret Line="40" Column="48" TopLine="30"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="150" Column="32" TopLine="132"/>
</Position18>
<Position19>
<Filename Value="framefunctionlist.pas"/>
<Caret Line="53" Column="7" TopLine="31"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="187" Column="37" TopLine="170"/>
</Position19>
<Position20>
<Filename Value="testunit.pas"/>
<Caret Line="7" Column="113" TopLine="5"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="145" Column="72" TopLine="132"/>
</Position20>
<Position21>
<Filename Value="testunit.pas"/>
<Caret Line="1222" Column="48" TopLine="1210"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="148" Column="30" TopLine="124"/>
</Position21>
<Position22>
<Filename Value="testunit.pas"/>
<Caret Line="1237" Column="46" TopLine="1225"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="72" Column="10" TopLine="56"/>
</Position22>
<Position23>
<Filename Value="testunit.pas"/>
<Caret Line="1251" Column="43" TopLine="1239"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="159" Column="1" TopLine="144"/>
</Position23>
<Position24>
<Filename Value="testunit.pas"/>
<Caret Line="1261" Column="63" TopLine="1239"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="41" Column="24" TopLine="21"/>
</Position24>
<Position25>
<Filename Value="testunit.pas"/>
<Caret Line="1271" Column="41" TopLine="1259"/>
<Caret Line="467" Column="57" TopLine="441"/>
</Position25>
<Position26>
<Filename Value="testunit.pas"/>
<Caret Line="1276" Column="43" TopLine="1259"/>
<Caret Line="454" Column="44" TopLine="446"/>
</Position26>
<Position27>
<Filename Value="framefunctionlist.pas"/>
<Caret Line="32" Column="31" TopLine="9"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="161" Column="24" TopLine="145"/>
</Position27>
<Position28>
<Filename Value="testunit.pas"/>
<Caret Line="33" Column="82" TopLine="25"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="101" Column="11" TopLine="79"/>
</Position28>
<Position29>
<Filename Value="testunit.pas"/>
<Caret Line="3" Column="50" TopLine="1"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="117" Column="3" TopLine="103"/>
</Position29>
<Position30>
<Filename Value="framefunctionlist.pas"/>
<Caret Line="53" Column="36" TopLine="41"/>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<Caret Line="114" Column="2" TopLine="94"/>
</Position30>
</JumpHistory>
</ProjectOptions>
@ -2076,7 +2093,8 @@
</CodeGeneration>
<Other>
<CustomOptions Value="-dUseCThreads
-dM_MEMORY_DEBUG"/>
-dM_MEMORY_DEBUG
-dFONTDEBUG"/>
<CompilerPath Value="$(CompPath)"/>
<CreateMakefileOnBuild Value="True"/>
</Other>

View File

@ -37,7 +37,8 @@ uses
window, // for the comp picker and selector
colourpicker, framescript, windowselector, lcltype, ActnList, StdActns,
SynEditKeyCmds, SynEditHighlighter, SynEditMarkupSpecialLine,SynEditMarkupHighAll,
SynEditMiscClasses, LMessages, Buttons, PairSplitter,about, framefunctionlist;
SynEditMiscClasses, LMessages, Buttons, PairSplitter,about, framefunctionlist,
ocr;
type
@ -269,6 +270,7 @@ type
CurrTab : TMufasaTab; //The current TMufasaTab
Tabs : TList;
Window: TMWindow;
OCR_Fonts: TMOCR;
Picker: TMColorPicker;
Selector: TMWindowSelector;
property ScriptState : TScriptState read GetScriptState write SetScriptState;
@ -456,10 +458,17 @@ begin
// only copies the current set window handle.
ScriptThread.Client.MWindow.SetWindow(Self.Window);
// we MUST set the OCR Path
writeln(IncludeTrailingPathDelimiter('TestUnit: OCR Path... ' +
ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + DS + 'Fonts' + DS);
ScriptThread.Client.MOCR.InitTOCR(IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + 'Fonts' + DS, false);
// Copy our current fonts
if not assigned(Self.OCR_Fonts) then
begin
Self.OCR_Fonts :=TMOCR.Create(ScriptThread.Client);
OCR_Fonts.InitTOCR(IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + 'Fonts' + DS);
end;
ScriptThread.Client.MOCR.SetFonts(OCR_Fonts.GetFonts);
// writeln(IncludeTrailingPathDelimiter('TestUnit: OCR Path... ' +
{ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + DS + 'Fonts' + DS);
ScriptThread.Client.MOCR.InitTOCR(IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + 'Fonts' + DS, false);}
ScriptThread.OnTerminate:=@ScriptThreadTerminate;
ScriptState:= ss_Running;

View File

@ -1,5 +1,4 @@
function rs_GetUpText: String;
begin
// why the hell does it still not use shadows?
Result := CurrThread.Client.MOCR.GetUpTextAtEx(7, 7, true);
end;

View File

@ -0,0 +1,221 @@
{
This file is part of the Mufasa Macro Library (MML)
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
MML is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MML is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MML. If not, see <http://www.gnu.org/licenses/>.
See the file COPYING, included in this distribution,
for details about the copyright.
Fonts class for the Mufasa Macro Library
}
unit fontloader;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
ocrutil; // contains the actual `loading'
{
We will not give any access to actual indices.
}
type
TMFont = class(TObject)
constructor Create;
destructor Destroy; override;
function Copy: TMFont;
public
Name: String;
Data: TOcrData;
end;
type
TMFonts = class(TObject)
constructor Create;
destructor Destroy; override;
function GetFont(Name: String): TOcrData;
function FreeFont(Name: String): boolean;
function LoadFont(Name: String; Shadow: Boolean): boolean;
procedure SetPath(aPath: String);
function GetPath: String;
function Copy: TMFonts;
private
function GetFontIndex(Name: String): Integer;
private
Fonts: TList;
Path: String;
end;
implementation
uses
files, MufasaTypes;
constructor TMFont.Create;
begin
inherited;
Name:='';
end;
destructor TMFont.Destroy;
begin
Name:='';
inherited;
end;
function TMFont.Copy: TMFont;
var
i, l, ll:integer;
begin
Result := TMFont.Create;
Result.Name := Self.Name;
Move(Self.Data.ascii[0], Self.Data.ascii[0], length(Self.Data.ascii) * SizeOf(Integer));
l := Length(Self.Data.Pos);
SetLength(Result.Data.pos, l);
for i := 0 to l - 1 do
begin
ll := length(Self.Data.Pos[i]);
setlength(Result.Data.Pos[i], ll);
Move(Self.Data.Pos[i][0], Result.Data.Pos[i][0], ll*SizeOf(Integer));
end;
SetLength(Result.Data.pos_adj, length(Self.Data.pos_adj));
Move(Self.Data.pos_adj[0], Result.Data.pos_adj[0], length(Self.Data.pos_adj) * SizeOf(real));
l := Length(Self.Data.neg);
SetLength(Result.Data.neg, l);
for i := 0 to l - 1 do
begin
ll := length(Self.Data.neg[i]);
setlength(Result.Data.neg[i], ll);
Move(Self.Data.neg[i][0], Result.Data.neg[i][0], ll*SizeOf(Integer));
end;
SetLength(Result.Data.neg_adj, length(Self.Data.neg_adj));
Move(Self.Data.neg_adj[0], Result.Data.neg_adj[0], length(Self.Data.neg_adj) * SizeOf(real));
SetLength(Result.Data.map, length(Self.Data.map));
Move(Self.Data.map[0], Result.Data.map[0], length(Self.Data.map) * SizeOf(char));
Result.Data.Width := Self.Data.Width;
Result.Data.Height := Self.Data.Height;
Result.Data.inputs := Self.Data.inputs;
Result.Data.outputs := Self.Data.outputs;
end;
constructor TMFonts.Create;
begin
inherited;
Fonts := TList.Create;
end;
destructor TMFonts.Destroy;
begin
Fonts.Free;
inherited;
end;
procedure TMFonts.SetPath(aPath: String);
begin
Path := aPath;
end;
function TMFonts.GetPath: String;
begin
Exit(Path);
end;
function TMFonts.GetFontIndex(Name: String): Integer;
var
i: integer;
begin
for i := 0 to Fonts.Count - 1 do
begin
if Name = TMFont(Fonts.Items[i]).Name then
Exit(i);
end;
raise Exception.Create('Font [' + Name + '] not found.');
Exit(-1);
end;
function TMFonts.GetFont(Name: String): TOcrData;
var
i: integer;
begin
i := GetFontIndex(Name);
Exit(TMFont(Fonts.Items[i]).Data);
end;
function TMFonts.FreeFont(Name: String): boolean;
var
i: integer;
begin
i := GetFontIndex(Name);
Fonts.Delete(i);
end;
function TMFonts.LoadFont(Name: String; Shadow: Boolean): boolean;
var
f: TMFont;
ocrdata: TOcrData;
begin
if not DirectoryExists(Path + Name) then
begin
raise Exception.Create('LoadFont: Directory ' + Path + Name + ' does not exists.');
Exit(False);
end;
ocrdata := InitOCR(Path + Name + DS, Shadow);
f:=TMFont.Create;
f.Name := Name;
if Shadow then
F.Name := F.Name + '_s';
f.Data := ocrdata;
Fonts.Add(f);
{$IFDEF FONTDEBUG}
writeln('Loaded Font ' + f.Name);
{$ENDIF}
end;
function TMFonts.Copy: TMFonts;
var
i:integer;
begin
Result := TMFonts.Create;
Result.Path := Self.GetPath();
for i := 0 to Self.Fonts.Count -1 do
Result.Fonts.Add(TMFont(Self.Fonts.Items[i]).Copy());
end;
end.

View File

@ -28,7 +28,7 @@ unit ocr;
interface
uses
Classes, SysUtils, MufasaTypes, bitmaps, math, ocrutil,
Classes, SysUtils, MufasaTypes, bitmaps, math, ocrutil, fontloader,
{Begin To-Remove units. Replace ReadBmp with TMufasaBitmap stuff later.}
graphtype, intfgraphics,graphics;
{End To-Remove unit}
@ -37,9 +37,9 @@ uses
TMOCR = class(TObject)
constructor Create(Owner: TObject);
destructor Destroy; override;
function InitTOCR(path: string; shadow: Boolean): boolean;
function GetFontIndex(FontName: string): integer;
function GetFont(FontName: string): TocrData;
function InitTOCR(path: string): boolean;
function GetFonts:TMFonts;
procedure SetFonts(NewFonts: TMFonts);
function getTextPointsIn(sx, sy, w, h: Integer; shadow: boolean;
var _chars, _shadows: T2DPointArray): Boolean;
@ -50,14 +50,13 @@ uses
procedure FilterUpTextByCharacteristics(bmp: TMufasaBitmap; w,h: integer);
procedure FilterShadowBitmap(bmp: TMufasaBitmap);
procedure FilterCharsBitmap(bmp: TMufasaBitmap);
{$IFDEF OCRDEBUG}
procedure DebugToBmp(bmp: TMufasaBitmap; hmod,h: integer);
{$ENDIF}
private
Client: TObject;
OCRData: TocrDataArray;
OCRNames: Array Of String;
OCRPath: string;
Fonts: TMFonts;
{$IFDEF OCRDEBUG}
public
debugbmp: TMufasaBitmap;
@ -118,6 +117,56 @@ We can also just split the chars, and then use their shadow.
constructor TMOCR.Create(Owner: TObject);
var
files: TStringArray;
begin
inherited Create;
Self.Client := Owner;
Self.Fonts := TMFonts.Create;
end;
destructor TMOCR.Destroy;
begin
Self.Fonts.Free;
inherited Destroy;
end;
function TMOCR.InitTOCR(path: string): boolean;
var
dirs: array of string;
i: longint;
dir: string;
begin
// We're going to load all fonts now
Fonts.SetPath(path);
dirs := GetDirectories(path);
for i := 0 to high(dirs) do
begin
Fonts.LoadFont(dirs[i], false);
{$IFDEF FONTDEBUG}
writeln('Loading ' + dirs[i]);
{$ENDIF}
end;
If DirectoryExists(path + 'UpChars') then
Fonts.LoadFont('UpChars', true); // shadow
end;
function TMOCR.GetFonts:TMFonts;
begin
Exit(Self.Fonts);
end;
procedure TMOCR.SetFonts(NewFonts: TMFonts);
begin
Self.Fonts := NewFonts.Copy();
end;
{
Non optimised. ;-)
@ -491,83 +540,6 @@ begin
shadowsbmp.Free;
end;
constructor TMOCR.Create(Owner: TObject);
var
files: TStringArray;
begin
inherited Create;
Self.Client := Owner;
SetLength(OCRData, 0);
SetLength(OCRNames, 0);
end;
destructor TMOCR.Destroy;
begin
SetLength(OCRData, 0);
SetLength(OCRNames, 0);
inherited Destroy;
end;
function TMOCR.InitTOCR(path: string; shadow: boolean): boolean;
var
dirs: array of string;
i: longint;
dir: string;
begin
{ This must be dynamic }
writeln(path);
dirs := GetDirectories(path);
SetLength(OCRData, length(dirs) * 2);
SetLength(OCRNames, length(dirs) * 2);
for i := 0 to high(dirs) do
begin
OCRData[i] := ocrutil.InitOCR(path + dirs[i] + DS, false);
OCRNames[i] := dirs[i];
OCRData[i+length(dirs)] := ocrutil.InitOCR(path + dirs[i] + DS, true);
OCRNames[i+length(dirs)] := dirs[i] + '_s';
{writeln('Loaded Font ' + OCRNames[i]);
writeln('Loaded Font ' + OCRNames[i+1]);}
end;
Result := (length(OCRData) > 0);
OCRPath := path;
end;
function TMOCR.GetFontIndex(FontName: string): integer;
var
i: integer;
begin
if length(OCRNames) <> length(OCRData) then
raise Exception.Create('Internal OCR error. Len(OCRData) <> Len(OCRNames)');
for i := 0 to high(OCRNames) do
if FontName = OCRNames[i] then
begin
Exit(i);
end;
raise Exception.Create('Font ' + FontName + ' is not loaded.');
end;
function TMOCR.GetFont(FontName: string): TocrData;
var
i: integer;
begin
if length(OCRNames) <> length(OCRData) then
raise Exception.Create('Internal OCR error. Len(OCRData) <> Len(OCRNames)');
for i := 0 to high(OCRNames) do
if FontName = OCRNames[i] then
begin
Exit(OCRData[i]);
end;
raise Exception.Create('Font ' + FontName + ' is not loaded.');
end;
function TMOCR.GetUpTextAtEx(atX, atY: integer; shadow: boolean): string;
var
@ -582,13 +554,12 @@ var
begin
ww := 400;
hh := 20;
getTextPointsIn(atX, atY, ww, hh, shadow, chars, shadows);
// only shadow!
//shadow:=true;
if shadow then
begin
font := GetFont('UpChars_s');
font := Fonts.GetFont('UpChars_s');
thachars := shadows;
{$IFDEF OCRDEBUG}
writeln('using shadows');
@ -596,7 +567,7 @@ begin
end
else
begin
font := GetFont('UpChars');
font := Fonts.GetFont('UpChars');
thachars := chars;
{$IFDEF OCRDEBUG}
writeln('not using shadows');
@ -619,6 +590,7 @@ begin
lbset:=true;
end else
begin
// spacing
if b.x1 - lb.x2 > 5 then
result:=result+' ';
lb:=b;