📄 flyweightunit1.pas
字号:
unit Flyweightunit1;
interface
uses Forms, graphics;
const
NCHARCODES = 128;
type
TGlyphContext = class;
TBTree = class;
TGlyPh = class
protected
constructor Create; virtual;
public
destructor Destroy; virtual;
procedure Draw(aWindow: TForm; aGlyphContext: TGlyphContext); virtual;
procedure SetFont(aFont: TFont; aGlyphContext: TGlyphContext); virtual;
function GetFont(aGlyphContext: TGlyphContext): TFont; virtual;
procedure First(aGlyphContext: TGlyphContext); virtual;
procedure Next(aGlyphContext: TGlyphContext); virtual;
function IsDone(aGlyphContext: TGlyphContext): Boolean; virtual;
function Current(aGlyphContext: TGlyphContext): TGlyph; virtual;
procedure Insert(aGlyph: TGlyph; aGlyphContext: TGlyphContext); virtual;
procedure Remove(aGlyphContext: TGlyphContext); virtual;
end;
TCharacter = class(TGlyPh)
private
F_Charcode: Char;
public
constructor Create(C: Char); overload;
procedure Draw(aWindow: TForm; aGlyphContext: TGlyphContext); virtual;
end;
TRow = class(TGlyPh)
public
constructor Create;
//......
end;
TColumn = class(TGlyPh)
public
constructor Create();
//......
end;
TGlyphContext = class
private
F_index: word;
F_font: TBTree;
public
constructor Create;
destructor Destroy; virtual;
procedure Next(step: word = 1); virtual;
procedure Insert(step: word = 1); virtual;
function GetFont(): TFont; virtual;
procedure SetFont(aFont: TFont; span: word = 1); virtual;
end;
TBTree = class
public
constructor Create;
end;
TGlyphFactory = class
private
f_character: array[1..NCHARCODES] of TCharacter;
public
constructor Create;
destructor Destroy; virtual;
function CreaterCharacter(C: Char): TCharacter; virtual;
function CreateRow(): TRow; virtual;
function CreateColumn(): TColumn; virtual;
//......
end;
implementation
constructor TGlyPh.Create;
begin
//...
end;
procedure TGlyPh.Draw(aWindow: TForm; aGlyphContext: TGlyphContext);
begin
//...
end;
procedure TGlyPh.SetFont(aFont: TFont; aGlyphContext: TGlyphContext);
begin
//...
end;
function TGlyPh.GetFont(aGlyphContext: TGlyphContext): TFont;
begin
//...
end;
procedure TGlyPh.First(aGlyphContext: TGlyphContext);
begin
//...
end;
procedure TGlyPh.Next(aGlyphContext: TGlyphContext);
begin
//...
end;
function TGlyPh.IsDone(aGlyphContext: TGlyphContext): Boolean;
begin
//...
end;
function TGlyPh.Current(aGlyphContext: TGlyphContext): TGlyph;
begin
//...
end;
procedure TGlyPh.Insert(aGlyph: TGlyph; aGlyphContext: TGlyphContext);
begin
//...
end;
procedure TGlyPh.Remove(aGlyphContext: TGlyphContext);
begin
//...
end;
destructor TGlyPh.Destroy;
begin
//...
end;
constructor TGlyphContext.Create;
begin
//....
end;
constructor TCharacter.Create(C: Char);
begin
//....
end;
procedure TCharacter.Draw(aWindow: TForm; aGlyphContext: TGlyphContext);
begin
//....
end;
destructor TGlyphContext.Destroy;
begin
//....
end;
procedure TGlyphContext.Next(step: word = 1);
begin
//....
end;
procedure TGlyphContext.Insert(step: word = 1);
begin
//....
end;
function TGlyphContext.GetFont(): TFont;
begin
//....
end;
procedure TGlyphContext.SetFont(aFont: TFont; span: word = 1);
begin
//....
end;
constructor TBTree.Create;
begin
//....
end;
constructor TGlyphFactory.Create;
var
i: word;
begin
for i := 0 to NCHARCODES - 1 do
f_character[i] := nil;
//....
end;
destructor TGlyphFactory.Destroy;
begin
//....
end;
function TGlyphFactory.CreaterCharacter(C: Char): TCharacter;
var
i, j: word;
isExist: Boolean;
begin
isExist := false;
for i := 0 to NCHARCODES - 1 do
begin
if f_character[i].F_Charcode = c then
begin
isExist := true;
j := i;
Exit;
end
else
if f_character[i] = nil then
begin
j := i;
Exit;
end;
end;
if not isExist then
f_character[j] := TCharacter.Create(c);
Result := f_character[j];
//....
end;
function TGlyphFactory.CreateRow(): TRow;
begin
Result := TRow.Create;
//....
end;
function TGlyphFactory.CreateColumn(): TColumn;
begin
Result := TColumn.Create;
//....
end;
constructor TRow.Create;
begin
//....
end;
constructor TColumn.Create;
begin
//....
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -