3
3
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
4
* obtain one at http://mozilla.org/MPL/2.0/
5
5
*
6
- * Copyright (C) 2006-2014 , Peter Johnson (www.delphidabbler.com).
6
+ * Copyright (C) 2006-2015 , Peter Johnson (www.delphidabbler.com).
7
7
*
8
8
* $Rev$
9
9
* $Date$
@@ -80,25 +80,21 @@ TFontHelper = class(TNoConstructObject)
80
80
}
81
81
strict private
82
82
const
83
- DefaultFontName = ' Arial' ; // Default font name
84
- DefaultFontSize = 8 ; // Default font size
83
+ FallbackFontName = ' Arial' ; // Fallback font name
84
+ FallbackFontSize = 8 ; // Fallback font size
85
85
86
- DefaultContentFontName = DefaultFontName; // Default content font name
87
- DefaultContentFontSize = DefaultFontSize; // Default content font size
86
+ VistaFontName = ' Segoe UI' ; // Vista default font name
87
+ VistaFontSize = 9 ; // Vista default font size
88
+ VistaContentFontName = ' Calibri' ; // Vista content font name
89
+ VistaContentFontSize = 10 ; // Vista content font size
88
90
89
- VistaFontName = ' Segoe UI ' ; // Vista default font name
90
- VistaFontSize = 9 ; // Vista default font size
91
- VistaContentFontName = ' Calibri ' ; // Vista content font name
92
- VistaContentFontSize = 10 ; // Vista content font size
91
+ XPFontName = ' Tahoma ' ; // XP default font name
92
+ XPFontSize = FallbackFontSize ; // XP default font size
93
+ XPContentFontName = ' Verdana ' ; // XP content font name
94
+ XPContentFontSize = FallbackFontSize ; // XP content font size
93
95
94
- XPFontName = ' Tahoma' ; // XP default font name
95
- XPFontSize = DefaultFontSize; // XP default font size
96
- XPContentFontName = ' Verdana' ; // XP content font name
97
- XPContentFontSize // XP content font size
98
- = DefaultContentFontSize;
99
-
100
- DefaultMonoFontName = ' Courier New' ; // Default mono font name
101
- DefaultMonoFontSize = 8 ; // Default mono font size
96
+ DefaultMonoFontName = ' Courier New' ; // Default mono font name
97
+ DefaultMonoFontSize = 8 ; // Default mono font size
102
98
end ;
103
99
104
100
@@ -109,7 +105,7 @@ implementation
109
105
// Delphi
110
106
SysUtils, Windows, Forms,
111
107
// Project
112
- UGraphicUtils, UStrUtils, USystemInfo ;
108
+ UGraphicUtils, UStrUtils;
113
109
114
110
115
111
{ TFontHelper }
@@ -193,28 +189,25 @@ class procedure TFontHelper.SetContentFont(const Font: TFont);
193
189
@param Font [in] Font to be set.
194
190
}
195
191
begin
196
- // Set default content font, size and style
197
- Font.Name := DefaultContentFontName;
198
- Font.Size := DefaultContentFontSize;
199
- Font.Style := [];
200
- if TOSInfo.IsReallyWindowsVistaOrGreater then
192
+ // Try Vista & later content font. If that fails try XP/Win2k font. One of the
193
+ // two should always work, but in case fonts have been uninstalled, use a
194
+ // fallback font.
195
+ if FontExists(VistaContentFontName) then
201
196
begin
202
- // We have Vista or later - use Calibri if installed
203
- if FontExists(VistaContentFontName) then
204
- begin
205
- Font.Name := VistaContentFontName;
206
- Font.Size := VistaContentFontSize;
207
- end ;
197
+ Font.Name := VistaContentFontName;
198
+ Font.Size := VistaContentFontSize;
199
+ end
200
+ else if FontExists(XPContentFontName) then
201
+ begin
202
+ Font.Name := XPContentFontName;
203
+ Font.Size := XPContentFontSize;
208
204
end
209
205
else
210
206
begin
211
- // Earlier OS than Vista (i.e. 2000 or XP)
212
- if FontExists(XPContentFontName) then
213
- begin
214
- Font.Name := XPContentFontName;
215
- Font.Size := XPContentFontSize;
216
- end ;
207
+ Font.Name := FallbackFontName;
208
+ Font.Size := FallbackFontSize;
217
209
end ;
210
+ Font.Style := [];
218
211
end ;
219
212
220
213
class procedure TFontHelper.SetDefaultBaseFont (const BaseFont: TFont);
@@ -233,7 +226,7 @@ class procedure TFontHelper.SetDefaultBaseFont(const BaseFont: TFont);
233
226
SetDefaultFont(DefaultFont);
234
227
// font delta is difference between normal default font size and that used
235
228
// on a specific OS (e.g. Vista uses Segoe UI 9 rather than MS Sans Serif 8)
236
- FontDelta := DefaultFont.Size - DefaultFontSize ;
229
+ FontDelta := DefaultFont.Size - FallbackFontSize ;
237
230
// change base font name and size as required
238
231
BaseFont.Name := DefaultFont.Name ;
239
232
BaseFont.Size := BaseFont.Size + FontDelta;
@@ -255,28 +248,25 @@ class procedure TFontHelper.SetDefaultFont(const Font: TFont);
255
248
@param Font [in] Font to be set.
256
249
}
257
250
begin
258
- // Set default font, size and style
259
- Font.Name := DefaultFontName;
260
- Font.Size := DefaultFontSize;
261
- Font.Style := [];
262
- if TOSInfo.IsReallyWindowsVistaOrGreater then
251
+ // Try Vista & later default font. If that fails try XP/Win2k font. One of the
252
+ // two should always work, but in case fonts have been uninstalled, use a
253
+ // fallback font.
254
+ if FontExists(VistaFontName) then
255
+ begin
256
+ Font.Name := VistaFontName;
257
+ Font.Size := VistaFontSize;
258
+ end
259
+ else if FontExists(XPFontName) then
263
260
begin
264
- // Vista or later
265
- if FontExists(VistaFontName) then
266
- begin
267
- Font.Name := VistaFontName;
268
- Font.Size := VistaFontSize;
269
- end ;
261
+ Font.Name := XPFontName;
262
+ Font.Size := XPFontSize;
270
263
end
271
264
else
272
265
begin
273
- // Earlier OS than Vista (i.e. 2000 or XP)
274
- if FontExists(XPFontName) then
275
- begin
276
- Font.Name := XPFontName;
277
- Font.Size := XPFontSize;
278
- end ;
266
+ Font.Name := FallbackFontName;
267
+ Font.Size := FallbackFontSize;
279
268
end ;
269
+ Font.Style := [];
280
270
end ;
281
271
282
272
class procedure TFontHelper.SetDefaultFonts (const Fonts: array of TFont);
0 commit comments