Look/Fonts: Revert the recent font changes for topography labels
[xcsoar.git] / src / Look / Fonts.cpp
blob6470e798a5949aa059b9d8e75bd7e94dba13e268
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Fonts.hpp"
25 #include "StandardFonts.hpp"
26 #include "Screen/Font.hpp"
27 #include "Screen/Layout.hpp"
29 #ifdef ENABLE_OPENGL
30 #include "Screen/OpenGL/Cache.hpp"
31 #endif
33 #include <string.h>
35 /// values inside infoboxes like numbers, etc.
36 Font Fonts::infobox;
37 Font Fonts::infobox_small;
38 #ifndef GNAV
39 Font Fonts::infobox_units;
40 #endif
41 /// Titles of infoboxes like Next, WP L/D etc.
42 Font Fonts::title;
43 /// vario display, runway informations
44 Font Fonts::cdi;
45 Font Fonts::monospace;
46 /// text names on the map
47 Font Fonts::map;
48 /// menu buttons, waypoint selection, messages, etc.
49 Font Fonts::map_bold;
50 /// Flarm Traffic draweing and stats, map labels in italic
51 Font Fonts::map_label;
52 /// font labels for important labels (e.g. big/medium cities)
53 Font Fonts::map_label_important;
55 // these are the non-custom parameters
56 LOGFONT log_infobox;
57 #ifndef GNAV
58 LOGFONT log_infobox_units;
59 #endif
60 LOGFONT log_title;
61 LOGFONT log_map;
62 LOGFONT log_infobox_small;
63 LOGFONT log_map_bold;
64 LOGFONT log_cdi;
65 LOGFONT log_map_label;
66 LOGFONT log_map_label_important;
67 static LOGFONT log_monospace;
69 static void
70 InitialiseLogfont(LOGFONT* font, const TCHAR* facename, UPixelScalar height,
71 bool bold = false, bool italic = false,
72 bool variable_pitch = true)
74 memset((char *)font, 0, sizeof(LOGFONT));
76 _tcscpy(font->lfFaceName, facename);
78 font->lfPitchAndFamily = (variable_pitch ? VARIABLE_PITCH : FIXED_PITCH)
79 | FF_DONTCARE;
81 font->lfHeight = (long)height;
82 font->lfWeight = (long)(bold ? FW_BOLD : FW_MEDIUM);
83 font->lfItalic = italic;
85 #ifdef WIN32
86 if (IsAltair())
87 font->lfQuality = NONANTIALIASED_QUALITY;
88 else
89 font->lfQuality = ANTIALIASED_QUALITY;
90 #endif
93 static void
94 LoadAltairLogFonts()
96 InitialiseLogfont(&log_infobox, _T("RasterGothicTwentyFourCond"), 24, true);
97 InitialiseLogfont(&log_title, _T("RasterGothicNineCond"), 10);
98 InitialiseLogfont(&log_cdi, _T("RasterGothicEighteenCond"), 19, true);
99 InitialiseLogfont(&log_map_label, _T("RasterGothicTwelveCond"), 13);
100 InitialiseLogfont(&log_map_label_important,
101 _T("RasterGothicTwelveCond"), 13);
102 InitialiseLogfont(&log_map, _T("RasterGothicFourteenCond"), 15);
103 InitialiseLogfont(&log_map_bold, _T("RasterGothicFourteenCond"), 15, true);
104 InitialiseLogfont(&log_infobox_small, _T("RasterGothicEighteenCond"), 19, true);
105 InitialiseLogfont(&log_monospace, GetStandardMonospaceFontFace(),
106 10, false, false, false);
109 static void
110 SizeLogFont(LOGFONT &logfont, UPixelScalar width, const TCHAR* str)
112 // JMW algorithm to auto-size info window font.
113 // this is still required in case title font property doesn't exist.
114 PixelSize tsize;
115 do {
116 --logfont.lfHeight;
118 Font font;
119 if (!font.Load(logfont))
120 break;
122 tsize = font.TextSize(str);
123 } while ((unsigned)tsize.cx > width);
125 ++logfont.lfHeight;
128 static void
129 InitialiseLogFonts()
131 if (IsAltair()) {
132 LoadAltairLogFonts();
133 return;
136 #ifndef USE_GDI
137 UPixelScalar font_height = Layout::SmallScale(IsAndroid() ? 30 : 24);
138 #else
139 UPixelScalar font_height = Layout::SmallScale(35);
140 #endif
142 // oversize first so can then scale down
143 InitialiseLogfont(&log_infobox, GetStandardFontFace(),
144 (int)(font_height * 1.4), true, false, true);
146 #ifdef WIN32
147 log_infobox.lfCharSet = ANSI_CHARSET;
148 #endif
150 InitialiseLogfont(&log_title, GetStandardFontFace(), font_height / 3);
152 // new font for CDI Scale
153 InitialiseLogfont(&log_cdi, GetStandardFontFace(),
154 UPixelScalar(font_height * 0.6), false, false, false);
156 // new font for map labels
157 InitialiseLogfont(&log_map_label, GetStandardFontFace(),
158 UPixelScalar(font_height * 0.39), false, true);
160 // new font for map labels big/medium cities
161 InitialiseLogfont(&log_map_label_important, GetStandardFontFace(),
162 UPixelScalar(font_height * 0.39), false, true);
164 // new font for map labels
165 InitialiseLogfont(&log_map, GetStandardFontFace(),
166 UPixelScalar(font_height * 0.507));
168 // Font for map bold text
169 InitialiseLogfont(&log_map_bold, GetStandardFontFace(),
170 UPixelScalar(font_height * 0.507), true);
172 InitialiseLogfont(&log_infobox_small, GetStandardFontFace(),
173 Layout::Scale(20));
175 #ifndef GNAV
176 InitialiseLogfont(&log_infobox_units, GetStandardFontFace(),
177 (int)(font_height * 0.56));
178 #endif
180 InitialiseLogfont(&log_monospace, GetStandardMonospaceFontFace(),
181 UPixelScalar(font_height * 0.39), false, false, false);
184 bool
185 Fonts::Initialize()
187 InitialiseLogFonts();
189 title.Load(log_title);
190 cdi.Load(log_cdi);
191 map_label.Load(log_map_label);
192 map_label_important.Load(log_map_label_important);
193 map.Load(log_map);
194 map_bold.Load(log_map_bold);
195 monospace.Load(log_monospace);
197 return title.IsDefined() && cdi.IsDefined() &&
198 map_label.IsDefined() && map_label_important.IsDefined() &&
199 map.IsDefined() && map_bold.IsDefined() &&
200 monospace.IsDefined();
203 void
204 Fonts::SizeInfoboxFont(UPixelScalar control_width)
206 LOGFONT lf = log_infobox;
208 if (!IsAltair())
209 SizeLogFont(lf, control_width, _T("1234m"));
210 infobox.Load(lf);
212 #ifndef GNAV
213 unsigned height = lf.lfHeight;
214 lf = log_infobox_units;
215 lf.lfHeight = (height * 2) / 5;
216 infobox_units.Load(lf);
217 #endif
219 lf = log_infobox_small;
220 if (!IsAltair())
221 SizeLogFont(lf, control_width, _T("12345m"));
222 infobox_small.Load(lf);
224 #ifdef ENABLE_OPENGL
225 TextCache::Flush();
226 #endif
229 void
230 Fonts::Deinitialize()
232 infobox.Destroy();
233 infobox_small.Destroy();
234 #ifndef GNAV
235 infobox_units.Destroy();
236 #endif
237 title.Destroy();
238 map.Destroy();
239 map_bold.Destroy();
240 cdi.Destroy();
241 map_label.Destroy();
242 map_label_important.Destroy();
243 monospace.Destroy();