33 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
44 * obtain one at http://mozilla.org/MPL/2.0/
55 *
6- * Copyright (C) 2006-2014 , Peter Johnson (www.delphidabbler.com).
6+ * Copyright (C) 2006-2015 , Peter Johnson (www.delphidabbler.com).
77 *
88 * $Rev$
99 * $Date$
@@ -80,25 +80,21 @@ TFontHelper = class(TNoConstructObject)
8080 }
8181 strict private
8282 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
8585
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
8890
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
9395
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
10298 end ;
10399
104100
@@ -109,7 +105,7 @@ implementation
109105 // Delphi
110106 SysUtils, Windows, Forms,
111107 // Project
112- UGraphicUtils, UStrUtils, USystemInfo ;
108+ UGraphicUtils, UStrUtils;
113109
114110
115111{ TFontHelper }
@@ -193,28 +189,25 @@ class procedure TFontHelper.SetContentFont(const Font: TFont);
193189 @param Font [in] Font to be set.
194190 }
195191begin
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
201196 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;
208204 end
209205 else
210206 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;
217209 end ;
210+ Font.Style := [];
218211end ;
219212
220213class procedure TFontHelper.SetDefaultBaseFont (const BaseFont: TFont);
@@ -233,7 +226,7 @@ class procedure TFontHelper.SetDefaultBaseFont(const BaseFont: TFont);
233226 SetDefaultFont(DefaultFont);
234227 // font delta is difference between normal default font size and that used
235228 // 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 ;
237230 // change base font name and size as required
238231 BaseFont.Name := DefaultFont.Name ;
239232 BaseFont.Size := BaseFont.Size + FontDelta;
@@ -255,28 +248,25 @@ class procedure TFontHelper.SetDefaultFont(const Font: TFont);
255248 @param Font [in] Font to be set.
256249 }
257250begin
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
263260 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;
270263 end
271264 else
272265 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;
279268 end ;
269+ Font.Style := [];
280270end ;
281271
282272class procedure TFontHelper.SetDefaultFonts (const Fonts: array of TFont);
0 commit comments