1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 18:52:15 -05:00

Adding TextToFontBitmap and TextToFontTPA.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@456 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2010-01-24 00:19:27 +00:00
parent 6cf5e3e1d8
commit 778b81a9ae
5 changed files with 912 additions and 714 deletions

View File

@ -30,15 +30,15 @@
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<Units Count="27">
<Units Count="29">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="1" Y="210"/>
<TopLine Value="184"/>
<CursorPos X="45" Y="90"/>
<TopLine Value="72"/>
<EditorIndex Value="0"/>
<UsageCount Value="74"/>
<UsageCount Value="83"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -46,15 +46,15 @@
<UnitName Value="CustApp"/>
<CursorPos X="15" Y="51"/>
<TopLine Value="32"/>
<UsageCount Value="7"/>
<UsageCount Value="6"/>
</Unit1>
<Unit2>
<Filename Value="../../Units/MMLCore/client.pas"/>
<UnitName Value="Client"/>
<CursorPos X="21" Y="51"/>
<CursorPos X="21" Y="53"/>
<TopLine Value="35"/>
<EditorIndex Value="9"/>
<UsageCount Value="31"/>
<UsageCount Value="36"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
@ -62,24 +62,22 @@
<UnitName Value="windowutil"/>
<CursorPos X="110" Y="30"/>
<TopLine Value="3"/>
<UsageCount Value="7"/>
<UsageCount Value="6"/>
</Unit3>
<Unit4>
<Filename Value="../../Units/MMLCore/window.pas"/>
<UnitName Value="Window"/>
<CursorPos X="55" Y="251"/>
<TopLine Value="236"/>
<EditorIndex Value="12"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
<UsageCount Value="29"/>
</Unit4>
<Unit5>
<Filename Value="../../Units/MMLCore/colour_conv.pas"/>
<UnitName Value="colour_conv"/>
<CursorPos X="18" Y="346"/>
<CursorPos X="18" Y="332"/>
<TopLine Value="309"/>
<EditorIndex Value="4"/>
<UsageCount Value="11"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
@ -88,7 +86,7 @@
<CursorPos X="31" Y="1907"/>
<TopLine Value="1890"/>
<EditorIndex Value="2"/>
<UsageCount Value="34"/>
<UsageCount Value="39"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
@ -96,9 +94,7 @@
<UnitName Value="Input"/>
<CursorPos X="56" Y="49"/>
<TopLine Value="24"/>
<EditorIndex Value="8"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
<UsageCount Value="29"/>
</Unit7>
<Unit8>
<Filename Value="../../Units/MMLCore/mufasatypes.pas"/>
@ -106,81 +102,79 @@
<CursorPos X="1" Y="1"/>
<TopLine Value="34"/>
<EditorIndex Value="3"/>
<UsageCount Value="32"/>
<UsageCount Value="37"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<UnitName Value="ocr"/>
<CursorPos X="53" Y="31"/>
<TopLine Value="24"/>
<CursorPos X="7" Y="729"/>
<TopLine Value="713"/>
<EditorIndex Value="10"/>
<UsageCount Value="31"/>
<UsageCount Value="36"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="../../../Documents/fpc/rtl/objpas/sysutils/diskh.inc"/>
<CursorPos X="10" Y="18"/>
<TopLine Value="1"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit10>
<Unit11>
<Filename Value="../../Units/MMLCore/files.pas"/>
<UnitName Value="files"/>
<CursorPos X="5" Y="42"/>
<TopLine Value="27"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit11>
<Unit12>
<Filename Value="../../../Documents/lazarus/lcl/graphics.pp"/>
<UnitName Value="Graphics"/>
<CursorPos X="3" Y="1426"/>
<TopLine Value="1411"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit12>
<Unit13>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<UnitName Value="bitmaps"/>
<CursorPos X="32" Y="835"/>
<TopLine Value="850"/>
<CursorPos X="51" Y="867"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="29"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="../../../Documents/fpc/rtl/inc/objpash.inc"/>
<CursorPos X="22" Y="177"/>
<TopLine Value="162"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit14>
<Unit15>
<Filename Value="../../../Documents/lazarus/lcl/intfgraphics.pas"/>
<UnitName Value="IntfGraphics"/>
<CursorPos X="30" Y="2975"/>
<TopLine Value="2959"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit15>
<Unit16>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<UnitName Value="mmlpsthread"/>
<CursorPos X="3" Y="154"/>
<TopLine Value="235"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit16>
<Unit17>
<Filename Value="../../../Documents/fpc/rtl/i386/mmx.pp"/>
<UnitName Value="mmx"/>
<CursorPos X="80" Y="15"/>
<TopLine Value="71"/>
<UsageCount Value="8"/>
<UsageCount Value="7"/>
</Unit17>
<Unit18>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/ocr.inc"/>
<CursorPos X="20" Y="4"/>
<TopLine Value="1"/>
<EditorIndex Value="11"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
@ -188,7 +182,7 @@
<CursorPos X="29" Y="31"/>
<TopLine Value="411"/>
<EditorIndex Value="6"/>
<UsageCount Value="27"/>
<UsageCount Value="32"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
@ -197,7 +191,7 @@
<CursorPos X="1" Y="89"/>
<TopLine Value="1"/>
<EditorIndex Value="5"/>
<UsageCount Value="23"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
@ -205,15 +199,15 @@
<UnitName Value="CustApp"/>
<CursorPos X="59" Y="48"/>
<TopLine Value="18"/>
<UsageCount Value="9"/>
<UsageCount Value="8"/>
</Unit21>
<Unit22>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<UnitName Value="ocrutil"/>
<CursorPos X="48" Y="417"/>
<TopLine Value="395"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="7"/>
<UsageCount Value="11"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit22>
<Unit23>
@ -221,147 +215,165 @@
<UnitName Value="colourpicker"/>
<CursorPos X="49" Y="288"/>
<TopLine Value="265"/>
<UsageCount Value="10"/>
<UsageCount Value="9"/>
</Unit23>
<Unit24>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<CursorPos X="116" Y="38"/>
<TopLine Value="12"/>
<UsageCount Value="10"/>
<UsageCount Value="9"/>
</Unit24>
<Unit25>
<Filename Value="../../Units/MMLAddon/PSInc/psdefines.inc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="2"/>
<UsageCount Value="10"/>
<UsageCount Value="9"/>
</Unit25>
<Unit26>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="10"/>
<UsageCount Value="9"/>
</Unit26>
<Unit27>
<Filename Value="../../Units/MMLCore/os_linux.pas"/>
<UnitName Value="os_linux"/>
<CursorPos X="66" Y="54"/>
<TopLine Value="24"/>
<EditorIndex Value="11"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit27>
<Unit28>
<Filename Value="../../Units/MMLCore/fontloader.pas"/>
<UnitName Value="fontloader"/>
<CursorPos X="53" Y="62"/>
<TopLine Value="34"/>
<EditorIndex Value="8"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit28>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="31" Column="54" TopLine="13"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="18" Column="48" TopLine="1"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="8" Column="38" TopLine="1"/>
<Caret Line="55" Column="47" TopLine="37"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLCore/colour_conv.pas"/>
<Caret Line="47" Column="31" TopLine="27"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="56" Column="74" TopLine="37"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="31" Column="53" TopLine="24"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="156" Column="24" TopLine="133"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="85" Column="74" TopLine="75"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="31" Column="66" TopLine="25"/>
</Position5>
<Position6>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="2027" Column="29" TopLine="2002"/>
<Filename Value="project1.lpr"/>
<Caret Line="89" Column="15" TopLine="67"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="2028" Column="37" TopLine="2009"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="53" Column="21" TopLine="35"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="2021" Column="75" TopLine="2004"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="740" Column="27" TopLine="722"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1832" Column="28" TopLine="1827"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="742" Column="39" TopLine="722"/>
</Position9>
<Position10>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1822" Column="1" TopLine="1808"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="713" Column="14" TopLine="708"/>
</Position10>
<Position11>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1877" Column="23" TopLine="1867"/>
<Filename Value="project1.lpr"/>
<Caret Line="86" Column="16" TopLine="67"/>
</Position11>
<Position12>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="62" Column="31" TopLine="44"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="40" Column="31" TopLine="22"/>
</Position12>
<Position13>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1893" Column="88" TopLine="1867"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="751" Column="17" TopLine="722"/>
</Position13>
<Position14>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="2033" Column="30" TopLine="2002"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="55" Column="23" TopLine="37"/>
</Position14>
<Position15>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1934" Column="32" TopLine="1916"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="761" Column="40" TopLine="702"/>
</Position15>
<Position16>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="2007" Column="29" TopLine="1989"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="763" Column="36" TopLine="735"/>
</Position16>
<Position17>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="87" Column="28" TopLine="78"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="737" Column="13" TopLine="724"/>
</Position17>
<Position18>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="2010" Column="81" TopLine="1989"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="734" Column="74" TopLine="712"/>
</Position18>
<Position19>
<Filename Value="project1.lpr"/>
<Caret Line="111" Column="22" TopLine="101"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="741" Column="39" TopLine="716"/>
</Position19>
<Position20>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="31" Column="24" TopLine="12"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="726" Column="62" TopLine="716"/>
</Position20>
<Position21>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="158" Column="46" TopLine="133"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="741" Column="39" TopLine="723"/>
</Position21>
<Position22>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="148" Column="33" TopLine="119"/>
<Filename Value="project1.lpr"/>
<Caret Line="88" Column="36" TopLine="72"/>
</Position22>
<Position23>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="31" Column="30" TopLine="1"/>
<Filename Value="project1.lpr"/>
<Caret Line="84" Column="48" TopLine="72"/>
</Position23>
<Position24>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1898" Column="99" TopLine="1878"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="29" Column="12" TopLine="1"/>
</Position24>
<Position25>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1902" Column="65" TopLine="1884"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="67" Column="9" TopLine="49"/>
</Position25>
<Position26>
<Filename Value="project1.lpr"/>
<Caret Line="51" Column="35" TopLine="34"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="68" Column="61" TopLine="49"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="77" Column="5" TopLine="49"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="159" Column="42" TopLine="141"/>
</Position27>
<Position28>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="31" Column="29" TopLine="1"/>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="216" Column="25" TopLine="198"/>
</Position28>
<Position29>
<Filename Value="project1.lpr"/>
<Caret Line="128" Column="41" TopLine="109"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="732" Column="24" TopLine="710"/>
</Position29>
<Position30>
<Filename Value="project1.lpr"/>
<Caret Line="62" Column="83" TopLine="38"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="741" Column="10" TopLine="711"/>
</Position30>
</JumpHistory>
</ProjectOptions>
@ -372,9 +384,15 @@
<OtherUnitFiles Value="$(ProjPath)/../../Units/MMLCore/;$(ProjPath)/../../Units/Misc/;$(ProjPath)/../../Units/MMLAddon/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/;$(ProjPath)/../../Units/Linux/;$(LazarusDir)/components/mouseandkeyinput/"/>
</SearchPaths>
<CodeGeneration>
<Checks>
<IOChecks Value="True"/>
<RangeChecks Value="True"/>
<OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks>
<VerifyObjMethodCallValidity Value="True"/>
<Optimizations>
<VariablesInRegisters Value="True"/>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Other>

View File

@ -82,21 +82,26 @@ begin
end;
{ add your program here }
C := TClient.Create;
C := TClient.Create('.');
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/Fonts/');
bmp := TMufasaBitmap.Create;
bmp := C.MOCR.TextToFontBitmap('Danke schon', 'SmallChars');
bmp.SaveToFile('/tmp/wat.bmp');
{ bmp := TMufasaBitmap.Create;
bmp.SetSize(CW,CH);
Writeln(Format('Client W/H: %d, %d', [CW, CH]));
FillChar(bmp.FData[0],sizeof(trgb32)*CW*CH, 0);
Randomize;
for i := 0 to 500 do
bmp.fastsetpixel(random(CW), random(CH), 255);
bmp.fastsetpixel(random(CW), random(CH), 255); }
{ bmp.FastSetPixel(8,8,255);
bmp.FastSetPixel(9,9,255);
bmp.FastSetPixel(7,7,255);
bmp.FastSetPixel(9,8,255);
bmp.FastSetPixel(8,9,255); }
C.MWindow.SetTarget(bmp);
// C.MWindow.SetTarget(bmp);
{ initdtm(dtm, 5);
@ -110,7 +115,7 @@ begin
dtm.asz[1] := 1;
dtm.ash[1] := dtm_Rectangle; }
dtm := randomdtm(10);
{ dtm := randomdtm(10);
// setlength(p, 1);
C.MFinder.SetToleranceSpeed(1);
@ -125,14 +130,14 @@ begin
writeln(inttostr(length(p))+ ' points found');
setlength(p,0);
PrintpDTM(tdtmtopDTM(pDTMToTDTM(dtm)));
PrintpDTM(tdtmtopDTM(pDTMToTDTM(dtm))); }
{for i := 0 to high(p) do
writeln(format('%d: (%d, %d)', [i, p[i].x, p[i].y])); }
//bmp.OnDestroy:=nil;
bmp.Free;
//bmp.Free;
C.Free;
// stop program loop

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,11 @@ uses
procedure FilterShadowBitmap(bmp: TMufasaBitmap);
procedure FilterCharsBitmap(bmp: TMufasaBitmap);
function GetTextAt(atX, atY, font, minspacing, maxspacing, color, len: integer): string;
function TextToFontTPA(Text, font: String; var w, h: integer): TPointArray;
function TextToFontBitmap(Text, font: String): TMufasaBitmap;
{$IFDEF OCRDEBUG}
procedure DebugToBmp(bmp: TMufasaBitmap; hmod,h: integer);
{$ENDIF}
@ -695,5 +700,71 @@ begin
result := GetUpTextAtEx(atX, atY, false);
end;
function TMOCR.GetTextAt(atX, atY, font, minspacing, maxspacing, color, len: integer): string;
begin
end;
function TMOCR.TextToFontTPA(Text, font: String; var w, h: integer): TPointArray;
var
fontD: TOcrData;
c, i, x, y, off: Integer;
d: TocrGlyphMetric;
an: integer;
begin
fontD := Fonts.GetFont(font);
c := 0;
off := 0;
setlength(result, 0);
for i := 1 to length(text) do
begin
writeln(text[i]);
an := Ord(text[i]);
if not InRange(an, 0, 255) then
begin
writeln('WARNING: Invalid character passed to TextToFontTPA');
continue;
end;
d := fontD.ascii[an];
{writeln(format('xoff, yoff: %d, %d', [d.xoff, d.yoff]));
writeln(format('bmp w,h: %d, %d', [d.width, d.height]));
writeln(format('font w,h: %d, %d', [fontD.width, fontD.height])); }
setlength(result, c+d.width*d.height);
for y := 0 to fontD.height - 1 do
for x := 0 to fontD.width - 1 do
begin
if fontD.pos[fontD.ascii[an].index][x + y * fontD.width] = 1 then
// if fontD.pos[an][x + y * fontD.width] = 1 then
begin
result[c] := Point(x + off +d.xoff, y+d.yoff);
inc(c);
end;
end;
setlength(result, c);
off := off + d.width;
end;
w := off;
h := d.height;
{ writeln('C: ' + inttostr(c)); }
end;
function TMOCR.TextToFontBitmap(Text, font: String): TMufasaBitmap;
var
TPA: TPointArray;
w,h: integer;
bmp: TMufasaBitmap;
begin
TPA := TextToFontTPA(text, font, w, h);
bmp := TMufasaBitmap.Create;
writeln(format('b: %d, %d', [w, h]));
bmp.SetSize(w, h);
bmp.DrawTPA(TPA, clWhite);
result := bmp;
end;
end.

View File

@ -233,7 +233,8 @@ begin
begin
result.pos[i][c]:= 1;
inc(pos);
end;
end else
result.pos[i][c] := 0;
end;
end;
for c:= 0 to size-1 do