-
Notifications
You must be signed in to change notification settings - Fork 0
/
frxComponents.pas
150 lines (122 loc) · 3.29 KB
/
frxComponents.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{ ******************************************************* }
{ Samer Assil }
{ frxComponents.pas }
{ email: [email protected] }
{ 2021 }
{ ******************************************************* }
unit frxComponents;
interface
uses
System.SysUtils, System.Classes, System.StrUtils, Vcl.Graphics, frxClass,
frxDsgnIntf, frxRes,
frxDesgn;
type
TAutoFontSize = class(TPersistent)
private
FActive: boolean;
FSizeMax: integer;
FSizeMin: integer;
published
property Active: boolean read FActive write FActive;
property SizeMax: integer read FSizeMax write FSizeMax default 40;
property SizeMin: integer read FSizeMin write FSizeMin default 4;
end;
TfrxMemoViewEx = class(TfrxMemoView)
private
FAutoFontSize: TAutoFontSize;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function CamelCase(aText: String): String;
class function GetDescription: string; override;
private
procedure AdjustHeight;
procedure AdjustWidth;
published
procedure Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX,
OffsetY: Extended); override;
property AutoFontSize: TAutoFontSize read FAutoFontSize write FAutoFontSize;
end;
implementation
{ TfrxTestComp }
procedure TfrxMemoViewEx.AdjustHeight;
begin
while CalcHeight < Height - (gapy * 2) do
begin
font.size := font.size + 1;
if font.size > AutoFontSize.SizeMax then
break;
end;
end;
procedure TfrxMemoViewEx.AdjustWidth;
begin
while CalcWidth > width - (gapx * 2) do
begin
font.size := font.size - 1;
if font.size > AutoFontSize.SizeMax then
break;
end;
end;
function TfrxMemoViewEx.CamelCase(aText: String): String;
var
flag: boolean;
i: integer;
len: integer;
begin
flag := true;
i := 0;
len := length(Text);
for i := 0 to len - 1 do
begin
if flag then
aText[i] := UpCase(Text[i]);
flag := aText[i] = ' ';
end;
end;
constructor TfrxMemoViewEx.Create(AOwner: TComponent);
begin
inherited;
FAutoFontSize := TAutoFontSize.Create;
FAutoFontSize.FSizeMax := 40;
FAutoFontSize.FSizeMin := 4;
end;
destructor TfrxMemoViewEx.Destroy;
begin
FAutoFontSize.Free;
inherited;
end;
procedure TfrxMemoViewEx.Draw(Canvas: TCanvas;
ScaleX, ScaleY, OffsetX, OffsetY: Extended);
begin
if AutoFontSize.Active then
begin
font.size := AutoFontSize.SizeMin;
AdjustHeight;
var txt: String;
// becouse Text is a WideString so "Length(Text) = 3" to check if the text is a one Character
if (not WordWrap) or ( Length(Text) = 3 ) then
begin
AdjustWidth;
font.size := font.size + 1;
end;
// text := length(txt).ToString + text;
font.size := font.size - 1;
if font.size < AutoFontSize.SizeMin then
font.size := AutoFontSize.SizeMin;
end;
inherited; // must be at the end - do not remove it
end;
class function TfrxMemoViewEx.GetDescription: string;
begin
result := 'Text Object Ex';
end;
var
Bmp: TBitmap;
initialization
Bmp := TBitmap.Create;
Bmp.LoadFromResourceName(hInstance, 'frxMemoViewEx');
frxObjects.RegisterObject(TfrxMemoViewEx, Bmp);
finalization
frxObjects.Unregister(TfrxMemoViewEx);
Bmp.Free;
end.