Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxor committed Mar 25, 2015
1 parent b8b27bf commit 1dba32e
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 163 deletions.
8 changes: 4 additions & 4 deletions BukvoezhkaCrossplatform/BukvoezhkaCrossplatform.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ uses
uMain in 'uMain.pas' {FormMain},
uTextConvertRoutines in '..\BukvoezhkaDesktop\uTextConvertRoutines.pas',
uTextConverter in '..\BukvoezhkaDesktop\uTextConverter.pas',
uStringsHelper in '..\BukvoezhkaDesktop\uStringsHelper.pas',
uFixedASCIIdecorator in '..\BukvoezhkaDesktop\uFixedASCIIdecorator.pas',
uFixedASCIIartFonts in '..\BukvoezhkaDesktop\uFixedASCIIartFonts.pas',
uCharacterSets in '..\BukvoezhkaDesktop\uCharacterSets.pas',
uStringListTypesConverter in '..\BukvoezhkaDesktop\uStringListTypesConverter.pas',
uFixedASCIIartMaker in '..\BukvoezhkaDesktop\uFixedASCIIartMaker.pas',
uConstASCIIartFonts in '..\BukvoezhkaDesktop\uConstASCIIartFonts.pas',
uConstCharArrays in '..\BukvoezhkaDesktop\uConstCharArrays.pas',
uAbout in 'uAbout.pas' {FormAbout};

{$R *.res}
Expand Down
32 changes: 16 additions & 16 deletions BukvoezhkaCrossplatform/BukvoezhkaCrossplatform.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<MainSource>BukvoezhkaCrossplatform.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Release</Config>
<Platform Condition="'$(Platform)'==''">OSX32</Platform>
<Platform Condition="'$(Platform)'==''">Win64</Platform>
<TargetedPlatforms>95</TargetedPlatforms>
<AppType>Application</AppType>
</PropertyGroup>
Expand Down Expand Up @@ -291,10 +291,10 @@
</DCCReference>
<DCCReference Include="..\BukvoezhkaDesktop\uTextConvertRoutines.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uTextConverter.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uStringsHelper.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uFixedASCIIdecorator.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uFixedASCIIartFonts.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uCharacterSets.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uStringListTypesConverter.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uFixedASCIIartMaker.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uConstASCIIartFonts.pas"/>
<DCCReference Include="..\BukvoezhkaDesktop\uConstCharArrays.pas"/>
<DCCReference Include="uAbout.pas">
<Form>FormAbout</Form>
<FormType>fmx</FormType>
Expand Down Expand Up @@ -325,15 +325,15 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment>
<DeployFile LocalName="Win32\Debug\BukvoezhkaCrossplatform.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>BukvoezhkaCrossplatform.exe</RemoteName>
<DeployFile LocalName="BukvoezhkaCrossplatform_Icns1.icns" Configuration="Release" Class="ProjectOSXResource">
<Platform Name="OSX32">
<RemoteName>BukvoezhkaCrossplatform.icns</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="OSX32\Debug\BukvoezhkaCrossplatform" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="OSX32\Release\BukvoezhkaCrossplatform.info.plist" Configuration="Release" Class="ProjectOSXInfoPList">
<Platform Name="OSX32">
<RemoteName>BukvoezhkaCrossplatform</RemoteName>
<RemoteName>Info.plist</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
Expand Down Expand Up @@ -368,9 +368,9 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="BukvoezhkaCrossplatform_Icns1.icns" Configuration="Release" Class="ProjectOSXResource">
<DeployFile LocalName="OSX32\Release\BukvoezhkaCrossplatform" Configuration="Release" Class="ProjectOutput">
<Platform Name="OSX32">
<RemoteName>BukvoezhkaCrossplatform.icns</RemoteName>
<RemoteName>BukvoezhkaCrossplatform</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
Expand All @@ -385,13 +385,13 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="OSX32\Release\BukvoezhkaCrossplatform.info.plist" Configuration="Release" Class="ProjectOSXInfoPList">
<Platform Name="OSX32">
<RemoteName>Info.plist</RemoteName>
<DeployFile LocalName="Win32\Debug\BukvoezhkaCrossplatform.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>BukvoezhkaCrossplatform.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="OSX32\Release\BukvoezhkaCrossplatform" Configuration="Release" Class="ProjectOutput">
<DeployFile LocalName="OSX32\Debug\BukvoezhkaCrossplatform" Configuration="Debug" Class="ProjectOutput">
<Platform Name="OSX32">
<RemoteName>BukvoezhkaCrossplatform</RemoteName>
<Overwrite>true</Overwrite>
Expand Down
Binary file modified BukvoezhkaCrossplatform/BukvoezhkaCrossplatform.res
Binary file not shown.
2 changes: 2 additions & 0 deletions BukvoezhkaCrossplatform/uMain.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ object FormMain: TFormMain
TabOrder = 1
TextSettings.Font.Family = 'Lucida Console'
TextSettings.Font.Size = 16.000000000000000000
TextSettings.WordWrap = True
StyledSettings = [Style, FontColor]
end
object MemoOutput: TMemo
Expand All @@ -924,6 +925,7 @@ object FormMain: TFormMain
TabOrder = 2
TextSettings.Font.Family = 'Lucida Console'
TextSettings.Font.Size = 16.000000000000000000
TextSettings.WordWrap = True
StyledSettings = [Style, FontColor]
end
object SplitterInOut: TSplitter
Expand Down
22 changes: 11 additions & 11 deletions BukvoezhkaCrossplatform/uMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ TFormMain = class(TForm)
procedure ViewFontNameChange(Sender: TObject);
procedure ViewFontSizeChange(Sender: TObject);
private
ReplaceMethodItemIndex: integer;
ViewFontItemIndex: integer;
FReplaceMethodItemIndex: integer;
FViewFontItemIndex: integer;
public
{ Public declarations }
end;
Expand All @@ -92,19 +92,19 @@ implementation

{$R *.fmx}

uses uTextConverter, uFixedASCIIdecorator, uAbout;
uses uTextConverter, uFixedASCIIartMaker, uAbout;

procedure TFormMain.ReplaceMethodItemIndexChange(Sender: TObject);
begin
ReplaceMethodItemIndex := (Sender as TRadioButton).Tag;
FReplaceMethodItemIndex := (Sender as TRadioButton).Tag;
ButtonGoClick(Sender);
end;

procedure TFormMain.ViewFontNameChange(Sender: TObject);
// ïåðåäåëàòü íà äèíàìè÷åñêèé ïîèñê ïî òåãó ViewFontItemIndex ó äî÷åðíèõ êîì-â GroupBoxViewFontName
begin
ViewFontItemIndex := (Sender as TRadioButton).Tag;
case ViewFontItemIndex of
FViewFontItemIndex := (Sender as TRadioButton).Tag;
case FViewFontItemIndex of
0:
begin
MemoInput.TextSettings.Font.Family := RadioButtonVFTahoma.Text;
Expand Down Expand Up @@ -176,9 +176,9 @@ procedure TFormMain.TextDecorate(Sender: TObject);
end;

procedure TFormMain.ButtonSymbolsReplaceClick(Sender: TObject);
procedure GoTransform(TransformMethod: integer);
procedure TextConvert(ConvertMethod: integer);
begin
case TransformMethod of
case ConvertMethod of
0:
MemoOutput.Text := TTextConverter.MakeASCII(MemoInput.Text);
1:
Expand Down Expand Up @@ -216,15 +216,15 @@ procedure TFormMain.ButtonSymbolsReplaceClick(Sender: TObject);
MemoOutput.WordWrap := True;
// MemoOutput.ScrollBars := ssVertical;
//
GoTransform(ReplaceMethodItemIndex);
TextConvert(FReplaceMethodItemIndex);
MemoOutput.SelectAll;
MemoOutput.CopyToClipboard;
end;

procedure TFormMain.FormCreate(Sender: TObject);
begin
ReplaceMethodItemIndex := 6;
ViewFontItemIndex := 2;
FReplaceMethodItemIndex := 6;
FViewFontItemIndex := 2;
end;

procedure TFormMain.ButtonAboutClick(Sender: TObject);
Expand Down
14 changes: 7 additions & 7 deletions BukvoezhkaDesktop/BukvoezhkaDesktop.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

uses
Forms,
uMain in 'uMain.pas' {FormMain},
uFormMain in 'uFormMain.pas' {FormMain},
uTextConvertRoutines in 'uTextConvertRoutines.pas',
uCharacterSets in 'uCharacterSets.pas',
uConstCharArrays in 'uConstCharArrays.pas',
uTextConverter in 'uTextConverter.pas',
uAbout in 'uAbout.pas' {FormAbout},
uStringsHelper in 'uStringsHelper.pas',
uASCIIdecorator in 'uASCIIdecorator.pas',
uFixedASCIIartFonts in 'uFixedASCIIartFonts.pas',
uFixedASCIIdecorator in 'uFixedASCIIdecorator.pas';
uFormAbout in 'uFormAbout.pas' {FormAbout},
uStringListTypesConverter in 'uStringListTypesConverter.pas',
uASCIIartMaker in 'uASCIIartMaker.pas',
uConstASCIIartFonts in 'uConstASCIIartFonts.pas',
uFixedASCIIartMaker in 'uFixedASCIIartMaker.pas';

{$R *.res}

Expand Down
30 changes: 21 additions & 9 deletions BukvoezhkaDesktop/BukvoezhkaDesktop.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Build>33</VerInfo_Build>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.2.0.33;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.2;Comments=;LastCompiledTime=2015.03.22 02:46:35</VerInfo_Keys>
<VerInfo_Build>38</VerInfo_Build>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.2.0.38;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.2;Comments=;LastCompiledTime=2015.03.25 11:43:35</VerInfo_Keys>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="uMain.pas">
<DCCReference Include="uFormMain.pas">
<Form>FormMain</Form>
</DCCReference>
<DCCReference Include="uTextConvertRoutines.pas"/>
<DCCReference Include="uCharacterSets.pas"/>
<DCCReference Include="uConstCharArrays.pas"/>
<DCCReference Include="uTextConverter.pas"/>
<DCCReference Include="uAbout.pas">
<DCCReference Include="uFormAbout.pas">
<Form>FormAbout</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="uStringsHelper.pas"/>
<DCCReference Include="uASCIIdecorator.pas"/>
<DCCReference Include="uFixedASCIIartFonts.pas"/>
<DCCReference Include="uFixedASCIIdecorator.pas"/>
<DCCReference Include="uStringListTypesConverter.pas"/>
<DCCReference Include="uASCIIartMaker.pas"/>
<DCCReference Include="uConstASCIIartFonts.pas"/>
<DCCReference Include="uFixedASCIIartMaker.pas"/>
<None Include="BukvoezhkaDesktop.todo"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
Expand Down Expand Up @@ -233,6 +233,18 @@
</Platform>
</DeployFile>
<DeployFile LocalName="ProjectBukvoezhkaDesktop.todo" Configuration="Debug" Class="ProjectFile"/>
<DeployFile LocalName="BukvoezhkaDesktop.todo" Configuration="Release" Class="ProjectFile">
<Platform Name="Win64">
<RemoteDir>.\</RemoteDir>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Release\Win64\BukvoezhkaDesktop.exe" Configuration="Release" Class="ProjectOutput">
<Platform Name="Win64">
<RemoteName>BukvoezhkaDesktop.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployClass Required="true" Name="DependencyPackage">
<Platform Name="iOSDevice">
<Operation>1</Operation>
Expand Down
Binary file modified BukvoezhkaDesktop/BukvoezhkaDesktop.res
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unit uASCIIdecorator;
unit uASCIIartMaker;

// Автор оригинального алгоритма преобразования картинки в текст - fabiin
// (2003, http://codes-sources.commentcamarche.net/source/12384-ascii-t-petit-soft-d-ascii-art)
Expand All @@ -8,16 +8,16 @@ interface
uses Windows, Graphics, Classes;

type
TDen = record // тип символа по цветовому тону
Car: Char; // символ
D: integer; // тон
TCharDensity = record // тип символа по цветовому тону
FChar: Char; // символ
FDensity: integer; // тон
end;

type
TASCIIdecorator = class(TComponent)
TASCIIartMaker = class(TComponent)
private
var
Densite: array of TDen; // Массив символов со значениями их яркости
Densite: array of TCharDensity; // Массив символов со значениями их яркости
procedure QuickSort(iLo, iHi: integer);
function MakeASCIIfromBitmap(SrcBitmap: TBitmap; DonorFont: string = 'Lucida Console';
contrast: integer = 255; zoom: integer = 0; IsNegative: boolean = false;
Expand All @@ -33,21 +33,21 @@ implementation

uses SysUtils;

procedure TASCIIdecorator.QuickSort(iLo, iHi: integer);
procedure TASCIIartMaker.QuickSort(iLo, iHi: integer);
var
Lo, Hi: integer;
Mid: single;
T: TDen;
T: TCharDensity;
begin
Lo := iLo;
Hi := iHi;
if (Hi + Lo) <= 0 then
exit;
Mid := Densite[(Hi + Lo) div 2].D;
Mid := Densite[(Hi + Lo) div 2].FDensity;
repeat
while Densite[Lo].D < Mid do
while Densite[Lo].FDensity < Mid do
Inc(Lo);
while Densite[Hi].D > Mid do
while Densite[Hi].FDensity > Mid do
Dec(Hi);
if Lo <= Hi then
begin
Expand All @@ -66,7 +66,7 @@ procedure TASCIIdecorator.QuickSort(iLo, iHi: integer);
// if Terminated then Exit;
end;

function TASCIIdecorator.MakeASCIIfromBitmap(SrcBitmap: TBitmap;
function TASCIIartMaker.MakeASCIIfromBitmap(SrcBitmap: TBitmap;
DonorFont: string = 'Lucida Console'; contrast: integer = 255; zoom: integer = 0;
IsNegative: boolean = false; CharacterSet: Byte = 0): string;

Expand Down Expand Up @@ -144,8 +144,8 @@ function TASCIIdecorator.MakeASCIIfromBitmap(SrcBitmap: TBitmap;
// Составляем массив символов
for c := low(Densite) to high(Densite) do
begin
Densite[c - low(Densite)].Car := charactersArr[c]; // записываем символ в массив "шрифта"
Densite[c - low(Densite)].D := 0;
Densite[c - low(Densite)].FChar := charactersArr[c]; // записываем символ в массив "шрифта"
Densite[c - low(Densite)].FDensity := 0;
// рисуем символ
TmpB.Canvas.Rectangle(0, 0, TmpB.Width, TmpB.Height);
TmpB.Canvas.TextOut(0, 0, charactersArr[c]);
Expand All @@ -155,7 +155,7 @@ function TASCIIdecorator.MakeASCIIfromBitmap(SrcBitmap: TBitmap;
for b := 1 to 20 do
begin
if TmpB.Canvas.Pixels[a, b] = clwhite then
Densite[c - low(Densite)].D := Densite[c - low(Densite)].D + 1;
Densite[c - low(Densite)].FDensity := Densite[c - low(Densite)].FDensity + 1;
end;
end;
end;
Expand Down Expand Up @@ -250,7 +250,7 @@ function TASCIIdecorator.MakeASCIIfromBitmap(SrcBitmap: TBitmap;
// Вычислить конечную плотность (отношение 255 к 95)
MoyCol := round(MoyCol * ((Length(Densite) - 1) / 255));

TmpStr := TmpStr + Densite[MoyCol].Car; // добавить следующий символ (?)
TmpStr := TmpStr + Densite[MoyCol].FChar; // добавить следующий символ (?)

Inc(a, 8);
end;
Expand All @@ -262,7 +262,7 @@ function TASCIIdecorator.MakeASCIIfromBitmap(SrcBitmap: TBitmap;
Result := TmpStr;
end;

function TASCIIdecorator.MakeASCIIfromText(SrcText: string; DonorFont: string = 'Lucida Console';
function TASCIIartMaker.MakeASCIIfromText(SrcText: string; DonorFont: string = 'Lucida Console';
contrast: integer = 255; zoom: integer = 0; IsNegative: boolean = false; CharacterSet: Byte = 0;
RenderFontSize: integer = 100): string;
var
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
unit uFixedASCIIartFonts;
unit uConstASCIIartFonts;

interface

uses uCharacterSets;
uses uConstCharArrays;

var
C_First_Font_RU: ArrArrStr =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unit uCharacterSets;
unit uConstCharArrays;

interface

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
unit uFixedASCIIdecorator;
unit uFixedASCIIartMaker;

interface

uses uCharacterSets;
uses uConstCharArrays;

type
TFixedASCIIdecorator = class
Expand All @@ -16,7 +16,7 @@ TFixedASCIIdecorator = class

implementation

uses System.RegularExpressions, uFixedASCIIartFonts;
uses System.RegularExpressions, uConstASCIIartFonts;

class function TFixedASCIIdecorator.MakeFixedASCIIfromText(InputTxt: string;
SrcSet, DestASCIIFontSet: ArrArrStr): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@ object FormAbout: TFormAbout
ParentFont = False
ReadOnly = True
TabOrder = 1
ExplicitTop = 71
end
end
Loading

0 comments on commit 1dba32e

Please sign in to comment.