po: update French translation
[xcsoar.git] / src / Screen / Fonts.cpp
blob24208d67d013bbb1dcd8183736e9c7055cff3ba9
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2012 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 "Screen/Fonts.hpp"
25 #include "Screen/Font.hpp"
26 #include "Screen/Layout.hpp"
28 /// values inside infoboxes like numbers, etc.
29 Font Fonts::infobox;
30 Font Fonts::infobox_small;
31 #ifndef GNAV
32 Font Fonts::infobox_units;
33 #endif
34 /// Titles of infoboxes like Next, WP L/D etc.
35 Font Fonts::title;
36 /// vario display, runway informations
37 Font Fonts::cdi;
38 Font Fonts::monospace;
39 /// text names on the map
40 Font Fonts::map;
41 /// menu buttons, waypoint selection, messages, etc.
42 Font Fonts::map_bold;
43 /// Flarm Traffic draweing and stats, map labels in italic
44 Font Fonts::map_label;
45 /// font labels for important labels (e.g. big/medium cities)
46 Font Fonts::map_label_important;
48 // these are the non-custom parameters
49 LOGFONT log_infobox;
50 #ifndef GNAV
51 LOGFONT log_infobox_units;
52 #endif
53 LOGFONT log_title;
54 LOGFONT log_map;
55 LOGFONT log_infobox_small;
56 LOGFONT log_map_bold;
57 LOGFONT log_cdi;
58 LOGFONT log_map_label;
59 LOGFONT log_map_label_important;
60 static LOGFONT log_monospace;
62 static const TCHAR *
63 GetStandardMonospaceFontFace()
65 if (IsAndroid())
66 return _T("Droid Sans Mono");
68 return _T("Courier");
71 static void
72 InitialiseLogfont(LOGFONT* font, const TCHAR* facename, UPixelScalar height,
73 bool bold = false, bool italic = false,
74 bool variable_pitch = true)
76 memset((char *)font, 0, sizeof(LOGFONT));
78 _tcscpy(font->lfFaceName, facename);
80 font->lfPitchAndFamily = (variable_pitch ? VARIABLE_PITCH : FIXED_PITCH)
81 | FF_DONTCARE;
83 font->lfHeight = (long)height;
84 font->lfWeight = (long)(bold ? FW_BOLD : FW_MEDIUM);
85 font->lfItalic = italic;
87 #ifdef WIN32
88 if (IsAltair())
89 font->lfQuality = NONANTIALIASED_QUALITY;
90 else
91 font->lfQuality = ANTIALIASED_QUALITY;
92 #endif
95 static void
96 LoadAltairLogFonts()
98 InitialiseLogfont(&log_infobox, _T("RasterGothicTwentyFourCond"), 24, true);
99 InitialiseLogfont(&log_title, _T("RasterGothicNineCond"), 10);
100 InitialiseLogfont(&log_cdi, _T("RasterGothicEighteenCond"), 19, true);
101 InitialiseLogfont(&log_map_label, _T("RasterGothicTwelveCond"), 13);
102 InitialiseLogfont(&log_map_label_important,
103 _T("RasterGothicTwelveCond"), 13, true);
104 InitialiseLogfont(&log_map, _T("RasterGothicFourteenCond"), 15);
105 InitialiseLogfont(&log_map_bold, _T("RasterGothicFourteenCond"), 15, true);
106 InitialiseLogfont(&log_infobox_small, _T("RasterGothicEighteenCond"), 19, true);
107 InitialiseLogfont(&log_monospace, GetStandardMonospaceFontFace(),
108 10, false, false, false);
111 static void
112 SizeLogFont(LOGFONT &logfont, UPixelScalar width, const TCHAR* str)
114 // JMW algorithm to auto-size info window font.
115 // this is still required in case title font property doesn't exist.
116 PixelSize tsize;
117 do {
118 --logfont.lfHeight;
120 Font font;
121 if (!font.Set(logfont))
122 break;
124 tsize = font.TextSize(str);
125 } while ((unsigned)tsize.cx > width);
127 ++logfont.lfHeight;
130 static void
131 InitialiseLogFonts()
133 if (IsAltair()) {
134 LoadAltairLogFonts();
135 return;
138 #ifndef USE_GDI
139 UPixelScalar FontHeight = Layout::SmallScale(IsAndroid() ? 30 : 24);
140 #else
141 UPixelScalar FontHeight = Layout::SmallScale(35);
142 #endif
144 // oversize first so can then scale down
145 InitialiseLogfont(&log_infobox, Fonts::GetStandardFontFace(),
146 (int)(FontHeight * 1.4), true, false, true);
148 #ifdef WIN32
149 log_infobox.lfCharSet = ANSI_CHARSET;
150 #endif
152 InitialiseLogfont(&log_title, Fonts::GetStandardFontFace(),
153 FontHeight / 3, true);
155 // new font for CDI Scale
156 InitialiseLogfont(&log_cdi, Fonts::GetStandardFontFace(),
157 UPixelScalar(FontHeight * 0.6), false, false, false);
159 // new font for map labels
160 InitialiseLogfont(&log_map_label, Fonts::GetStandardFontFace(),
161 UPixelScalar(FontHeight * 0.39), false, true);
163 // new font for map labels big/medium cities
164 InitialiseLogfont(&log_map_label_important, Fonts::GetStandardFontFace(),
165 UPixelScalar(FontHeight * 0.39), true, true);
167 // new font for map labels
168 InitialiseLogfont(&log_map, Fonts::GetStandardFontFace(),
169 UPixelScalar(FontHeight * 0.507));
171 // Font for map bold text
172 InitialiseLogfont(&log_map_bold, Fonts::GetStandardFontFace(),
173 UPixelScalar(FontHeight * 0.507), true);
175 InitialiseLogfont(&log_infobox_small, Fonts::GetStandardFontFace(),
176 Layout::Scale(20));
178 InitialiseLogfont(&log_infobox_small, Fonts::GetStandardFontFace(),
179 (int)(FontHeight * 0.56), true);
181 InitialiseLogfont(&log_monospace, GetStandardMonospaceFontFace(),
182 UPixelScalar(FontHeight * 0.39), false, false, false);
185 bool
186 Fonts::Initialize()
188 InitialiseLogFonts();
190 title.Set(log_title);
191 cdi.Set(log_cdi);
192 map_label.Set(log_map_label);
193 map_label_important.Set(log_map_label_important);
194 map.Set(log_map);
195 map_bold.Set(log_map_bold);
196 monospace.Set(log_monospace);
198 return title.IsDefined() && cdi.IsDefined() &&
199 map_label.IsDefined() && map_label_important.IsDefined() &&
200 map.IsDefined() && map_bold.IsDefined() &&
201 monospace.IsDefined();
204 void
205 Fonts::SizeInfoboxFont(UPixelScalar control_width)
207 LOGFONT lf = log_infobox;
209 if (!IsAltair())
210 SizeLogFont(lf, control_width, _T("1234m"));
211 infobox.Set(lf);
213 #ifndef GNAV
214 unsigned height = lf.lfHeight;
215 lf = log_infobox_units;
216 lf.lfHeight = (height * 2) / 5;
217 infobox_units.Set(lf);
218 #endif
220 lf = log_infobox_small;
221 if (!IsAltair())
222 SizeLogFont(lf, control_width, _T("12345m"));
223 infobox_small.Set(lf);
226 void
227 Fonts::Deinitialize()
229 infobox.Reset();
230 infobox_small.Reset();
231 #ifndef GNAV
232 infobox_units.Reset();
233 #endif
234 title.Reset();
235 map.Reset();
236 map_bold.Reset();
237 cdi.Reset();
238 map_label.Reset();
239 map_label_important.Reset();
240 monospace.Reset();
243 const TCHAR*
244 Fonts::GetStandardFontFace()
246 if (IsAltair())
247 return _T("RasterGothicFourteenCond");
249 if (IsAndroid())
250 return _T("Droid Sans");
252 return _T("Tahoma");