-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLBitmapFontNFW.pas
180 lines (148 loc) · 4.73 KB
/
GLBitmapFontNFW.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{
Äëÿ èñïîëüçîâàíèÿ íóæíî â TGLCustomBitmapFont
procedure ResetCharWidths(w : Integer = -1);
and
procedure OnGlyphsChanged(Sender : TObject);
îïðåäåëèòü êàê âèðòóàë, ïîòîìó êàê èõ îâåððàéäèì
ôîðìàò ôàéëà nfw:
0. Âûñîòà
1. Øèðèíà
2. êîë-âî ñèìâîëîâ
3. ñèìâîëüíàÿ ñòðîêà
4.... ñèìâîëû
Íó è êàê âñåãäà â GLSceneRegister äîáàâëÿåì:
1. Â uses -> GLBitmapFontNFW
2. â GLRegisterPropertiesInCategories ->
RegisterPropertiesInCategory(sVisualCategoryName,
[TypeInfo(TGLBitmapFontNFW), TypeInfo(TTextLayout)]);
RegisterPropertiesInCategory(sLocalizableCategoryName,
[TypeInfo(TGLBitmapFontNFW)]);
RegisterPropertiesInCategory(sLayoutCategoryName, TGLBitmapFontNFW,
['Char*', '*Interval*', '*Space']);
RegisterPropertiesInCategory(sLocalizableCategoryName, TGLBitmapFontNFW,
['Glyphs']);
RegisterPropertiesInCategory(sVisualCategoryName, TGLBitmapFontNFW,
['Char*', '*Interval*', '*Space', 'Glyphs']);
3. â Register
RegisterComponents('GLScene',[TGLBitmapFontNFW]);
Âîîáùåì âñ¸ êàê ó TGLBitmapFont.
}
unit GLBitmapFontNFW; // NFW = Not Fixed Width
interface
uses Classes, GLScene, VectorGeometry, GLContext, GLCrossPlatform,
GLTexture, GLState, GLUtils, GLGraphics, GLBitmapFont, SysUtils{, QStrings};
{------------------------------------------------------------------------------}
type
{------------------------------------------------------------------------------}
TGLCustomBitmapFontNFW = class (TGLCustomBitmapFont)
private
FPathGGFnt: String;
procedure SetPathGGFnt(const val : String);
procedure ResetCharWidths(w : Integer = -1); override;
procedure OnGlyphsChanged(Sender : TObject); override;
protected
public
property PathGGFnt : String read FPathGGFnt write SetPathGGFnt;
end;
{------------------------------------------------------------------------------}
TGLBitmapFontNFW = class (TGLCustomBitmapFontNFW)
private
published
property Glyphs;
property GlyphsIntervalX;
property GlyphsIntervalY;
property Ranges;
property CharWidth;
property CharHeight;
property HSpace;
property VSpace;
property MagFilter;
property MinFilter;
property GlyphsAlpha;
property PathGGFnt;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
implementation
uses Dialogs, StrUtils;
{------------------------------------------------------------------------------}
function GetStr(const s: String): String;
var tmps: String;
begin
tmps := s;
Delete(tmps,1,2);
Result := tmps;
end;
{------------------------------------------------------------------------------}
procedure TGLCustomBitmapFontNFW.OnGlyphsChanged(Sender: TObject);
var
SaveMF: TGLMagFilter;
begin
inherited;
SaveMF := MagFilter;
if MagFilter = maLinear then
MagFilter := maNearest
else
MagFilter := maLinear;
MagFilter := SaveMF;
end;
{------------------------------------------------------------------------------}
procedure TGLCustomBitmapFontNFW.ResetCharWidths(w : Integer = -1);
var
i, cnt, L: Integer;
SL: TStrings;
s: string;
ch_beg, ch_end, ch_cur: Char;
begin
inherited;
if FPathGGFnt<>'' then
begin
if FileExists(PathGGFnt) then
begin
SL := TStringList.Create;
SL.LoadFromFile(FPathGGFnt);
CharWidth := StrToInt(SL[0]);
CharHeight := StrToInt(SL[1]);
cnt := StrToInt(SL[2]);
// etc.
for i:=4 to cnt-1 do
begin
s := SL[i][1];
CharWidths[Integer(s[1])] := StrToInt(GetStr(SL[i]));
end;
Ranges.Clear;
s := SL[3];
L := Length(s);
ch_beg := s[1];
cnt := 0;
for i:=1 to L do
begin
ch_cur := s[i];
ch_end := s[i+1];
if Integer(ch_end)-Integer(ch_cur)<>1 then
begin
Ranges.Add(ch_beg, ch_cur).StartGlyphIdx := cnt;
ch_beg := ch_end;
cnt := i;
end;
end;
SL.Free;
end;
end;
end;
{------------------------------------------------------------------------------}
procedure TGLCustomBitmapFontNFW.SetPathGGFnt(const val: String);
begin
FPathGGFnt:=val;
InvalidateUsers;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
initialization
// class registrations
RegisterClasses([TGLBitmapFontNFW, TGLFlatText]);
end.