Ticket #732: patch_fonts2

File patch_fonts2, 10.0 KB (added by stpere, 16 years ago)
Line 
1Index: src/servers/app/ServerApp.h
2===================================================================
3--- src/servers/app/ServerApp.h (révision 30265)
4+++ src/servers/app/ServerApp.h (copie de travail)
5@@ -8,11 +8,13 @@
6 * Stephan Aßmus <superstippi@gmx.de>
7 * Stefano Ceccherini (burton666@libero.it)
8 * Axel Dörfler, axeld@pinc-software.de
9+ * Philippe Saint-Pierre, stpere@gmail.com
10 */
11 #ifndef SERVER_APP_H
12 #define SERVER_APP_H
13
14
15+#include "ServerFont.h"
16 #include "ClientMemoryAllocator.h"
17 #include "MessageLooper.h"
18
19@@ -84,6 +86,8 @@
20
21 Desktop* GetDesktop() const { return fDesktop; }
22
23+ status_t GetFont(char *which, ServerFont& font);
24+
25 BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; }
26
27 private:
28@@ -111,6 +115,10 @@
29 BString fSignature;
30 team_id fClientTeam;
31
32+ ServerFont fPlainFont;
33+ ServerFont fBoldFont;
34+ ServerFont fFixedFont;
35+
36 mutable BLocker fWindowListLock;
37 BObjectList<ServerWindow> fWindowList;
38 BPrivate::BTokenSpace fViewTokens;
39Index: src/servers/app/ServerApp.cpp
40===================================================================
41--- src/servers/app/ServerApp.cpp (révision 30265)
42+++ src/servers/app/ServerApp.cpp (copie de travail)
43@@ -10,6 +10,7 @@
44 * Axel Dörfler, axeld@pinc-software.de
45 * Jérôme Duval, jerome.duval@free.fr
46 * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk>
47+ * Philippe Saint-Pierre, stpere@gmail.com
48 */
49
50 /*!
51@@ -123,6 +124,14 @@
52 fInitialWorkspace = desktop->CurrentWorkspace();
53 // TODO: this should probably be retrieved when the app is loaded!
54
55+ // record the current system wide fonts..
56+ desktop->LockSingleWindow();
57+ DesktopSettings settings(desktop);
58+ settings.GetDefaultPlainFont(fPlainFont);
59+ settings.GetDefaultBoldFont(fBoldFont);
60+ settings.GetDefaultFixedFont(fFixedFont);
61+ desktop->UnlockSingleWindow();
62+
63 STRACE(("ServerApp %s:\n", Signature()));
64 STRACE(("\tBApp port: %ld\n", fClientReplyPort));
65 STRACE(("\tReceiver port: %ld\n", fMessagePort));
66@@ -390,6 +399,36 @@
67 }
68
69
70+// Helper function to attach the fonts attribute to a link
71+// Could be made a method of the link itself, I suppose
72+
73+void
74+_AttachFont(BPrivate::PortLink& fLink, ServerFont& font)
75+{
76+ fLink.Attach<uint16>(font.FamilyID());
77+ fLink.Attach<uint16>(font.StyleID());
78+ fLink.Attach<float>(font.Size());
79+ fLink.Attach<uint16>(font.Face());
80+ fLink.Attach<uint32>(font.Flags());
81+}
82+
83+
84+status_t
85+ServerApp::GetFont(char *which, ServerFont& font)
86+{
87+ if (!strcmp(which, "plain")) {
88+ font = fPlainFont;
89+ } else if (!strcmp(which, "bold")) {
90+ font = fBoldFont;
91+ } else if (!strcmp(which, "fixed")) {
92+ font = fFixedFont;
93+ } else
94+ return B_BAD_VALUE;
95+
96+ return B_OK;
97+}
98+
99+
100 /*!
101 \brief Handler function for BApplication API messages
102 \param code Identifier code for the message. Equivalent to BMessage::what
103@@ -1123,8 +1162,44 @@
104
105 /* font messages */
106
107+ case AS_GET_SYSTEM_FONT:
108+ {
109+ FTRACE(("ServerApp %s: AS_GET_SYSTEM_FONT\n", Signature()));
110+ // gets :
111+ // 1) string - font type ("plain", ...)
112+
113+ char type[B_OS_NAME_LENGTH];
114+ ServerFont font;
115+
116+ status_t status = link.ReadString(type, sizeof(type));
117+
118+ if (status == B_OK) {
119+ if (!strcmp(type, "plain")) {
120+ fLink.StartMessage(B_OK);
121+ _AttachFont(fLink, fPlainFont);
122+ } else if (!strcmp(type, "bold")) {
123+ fLink.StartMessage(B_OK);
124+ _AttachFont(fLink, fBoldFont);
125+ } else if (!strcmp(type, "fixed")) {
126+ fLink.StartMessage(B_OK);
127+ _AttachFont(fLink, fFixedFont);
128+ } else {
129+ FTRACE(("Font name not found : %s\n", type));
130+ status = B_BAD_VALUE;
131+ }
132+ }
133+
134+ if (status != B_OK) {
135+ fLink.StartMessage(status);
136+ }
137+
138+ fLink.Flush();
139+ break;
140+ }
141+
142 case AS_SET_SYSTEM_FONT:
143 {
144+ FTRACE(("ServerApp %s: AS_SET_SYSTEM_FONT\n", Signature()));
145 // gets:
146 // 1) string - font type ("plain", ...)
147 // 2) string - family
148@@ -1209,40 +1284,17 @@
149 // 4) uint16 - face flags
150 // 5) uint32 - font flags
151
152- if (!fDesktop->LockSingleWindow()) {
153- fLink.StartMessage(B_OK);
154- fLink.Flush();
155- break;
156- }
157-
158- DesktopSettings settings(fDesktop);
159 fLink.StartMessage(B_OK);
160
161- for (int32 i = 0; i < 3; i++) {
162- ServerFont font;
163- switch (i) {
164- case 0:
165- settings.GetDefaultPlainFont(font);
166- fLink.AttachString("plain");
167- break;
168- case 1:
169- settings.GetDefaultBoldFont(font);
170- fLink.AttachString("bold");
171- break;
172- case 2:
173- settings.GetDefaultFixedFont(font);
174- fLink.AttachString("fixed");
175- break;
176- }
177+ fLink.AttachString("plain");
178+ _AttachFont(fLink, fPlainFont);
179
180- fLink.Attach<uint16>(font.FamilyID());
181- fLink.Attach<uint16>(font.StyleID());
182- fLink.Attach<float>(font.Size());
183- fLink.Attach<uint16>(font.Face());
184- fLink.Attach<uint32>(font.Flags());
185- }
186+ fLink.AttachString("bold");
187+ _AttachFont(fLink, fBoldFont);
188
189- fDesktop->UnlockSingleWindow();
190+ fLink.AttachString("fixed");
191+ _AttachFont(fLink, fFixedFont);
192+
193 fLink.Flush();
194 break;
195 }
196Index: src/servers/app/ServerWindow.cpp
197===================================================================
198--- src/servers/app/ServerWindow.cpp (révision 30265)
199+++ src/servers/app/ServerWindow.cpp (copie de travail)
200@@ -9,6 +9,7 @@
201 * Stefano Ceccherini (burton666@libero.it)
202 * Axel Dörfler, axeld@pinc-software.de
203 * Artur Wyszynski <harakash@gmail.com>
204+ * Philippe Saint-Pierre, stpere@gmail.com
205 */
206
207 /*!
208@@ -618,11 +619,12 @@
209 // fDesktop->LockSingleWindow();
210 }
211
212- // TODO: default fonts should be created and stored in the Application
213- DesktopSettings settings(fDesktop);
214 ServerFont font;
215- settings.GetDefaultPlainFont(font);
216- newView->CurrentState()->SetFont(font);
217+ if (App()->GetFont("plain", font) == B_OK) {
218+ newView->CurrentState()->SetFont(font);
219+ } else {
220+ debug_printf("Plain font not found!\n");
221+ }
222
223 if (_parent) {
224 View *parent;
225Index: src/kits/app/Application.cpp
226===================================================================
227--- src/kits/app/Application.cpp (révision 30265)
228+++ src/kits/app/Application.cpp (copie de travail)
229@@ -31,6 +31,7 @@
230 #include <Resources.h>
231 #include <Roster.h>
232 #include <Window.h>
233+#include <Font.h>
234
235 #include <AppMisc.h>
236 #include <AppServerLink.h>
237@@ -250,6 +251,11 @@
238
239 // uninitialize be_app, the be_app_messenger is invalidated automatically
240 be_app = NULL;
241+
242+ // free the fonts symbols (they are application specific)
243+ delete be_plain_font;
244+ delete be_bold_font;
245+ delete be_fixed_font;
246 }
247
248
249@@ -433,8 +439,12 @@
250
251 #ifndef RUN_WITHOUT_APP_SERVER
252 // app server connection and IK initialization
253- if (initGUI)
254+ if (initGUI) {
255 fInitError = _InitGUIContext();
256+ be_plain_font = new BFont("plain");
257+ be_bold_font = new BFont("bold");
258+ be_fixed_font = new BFont("fixed");
259+ }
260 #endif // RUN_WITHOUT_APP_SERVER
261 }
262
263Index: src/kits/interface/Font.cpp
264===================================================================
265--- src/kits/interface/Font.cpp (révision 30265)
266+++ src/kits/interface/Font.cpp (copie de travail)
267@@ -12,6 +12,7 @@
268
269
270 #include <AppServerLink.h>
271+#include <Application.h>
272 #include <FontPrivate.h>
273 #include <ObjectList.h>
274 #include <ServerProtocol.h>
275@@ -36,16 +37,17 @@
276 const float kUninitializedAscent = INFINITY;
277 const uint32 kUninitializedExtraFlags = 0xffffffff;
278
279-// The actual objects which the globals point to
280+// Backup fonts (used when no BApplication is present) - legacy behaviour
281 static BFont sPlainFont;
282 static BFont sBoldFont;
283 static BFont sFixedFont;
284
285+// Font symbols - these are specific to every application
286+// they will be changed at BApplication initialization
287 const BFont *be_plain_font = &sPlainFont;
288 const BFont *be_bold_font = &sBoldFont;
289 const BFont *be_fixed_font = &sFixedFont;
290
291-
292 struct style {
293 BString name;
294 uint16 face;
295@@ -349,11 +351,13 @@
296 {
297 }
298
299+
300 status_t get_font_cache_info(uint32 id, void *set)
301 {
302 return B_ERROR;
303 }
304
305+
306 status_t set_font_cache_info(uint32 id, void *set)
307 {
308 return B_ERROR;
309@@ -501,6 +505,7 @@
310 // #pragma mark -
311
312
313+
314 BFont::BFont()
315 :
316 // initialise for be_plain_font (avoid circular definition)
317@@ -526,6 +531,52 @@
318 }
319
320
321+BFont::BFont(const char *which)
322+ :
323+ fFamilyID(0),
324+ fStyleID(0),
325+ fSize(10.0),
326+ fShear(90.0),
327+ fRotation(0.0),
328+ fFalseBoldWidth(0.0),
329+ fSpacing(0),
330+ fEncoding(0),
331+ fFace(0),
332+ fFlags(0),
333+ fExtraFlags(kUninitializedExtraFlags)
334+{
335+ if (be_app
336+ && (!strcmp(which, "plain")
337+ || !strcmp(which, "bold")
338+ || !strcmp(which, "fixed"))) {
339+
340+ BPrivate::AppServerLink link;
341+
342+ link.StartMessage(AS_GET_SYSTEM_FONT);
343+ link.AttachString(which, B_OS_NAME_LENGTH);
344+
345+ int32 code;
346+ link.FlushWithReply(code);
347+
348+ if (code == B_OK) {
349+ link.Read<uint16>(&fFamilyID);
350+ link.Read<uint16>(&fStyleID);
351+ link.Read<float>(&fSize);
352+ link.Read<uint16>(&fFace);
353+ link.Read<uint32>(&fFlags);
354+
355+ fHeight.ascent = kUninitializedAscent;
356+ fExtraFlags = kUninitializedExtraFlags;
357+ return;
358+ }
359+ }
360+ // else...
361+ fHeight.ascent = 7.0;
362+ fHeight.descent = 2.0;
363+ fHeight.leading = 13.0;
364+}
365+
366+
367 BFont::BFont(const BFont &font)
368 {
369 *this = font;
370@@ -536,8 +587,10 @@
371 {
372 if (font)
373 *this = *font;
374+ else if (be_plain_font)
375+ *this = *be_plain_font;
376 else
377- *this = *be_plain_font;
378+ *this = BFont("plain");
379 }
380
381
382Index: headers/os/interface/Font.h
383===================================================================
384--- headers/os/interface/Font.h (révision 30265)
385+++ headers/os/interface/Font.h (copie de travail)
386@@ -148,6 +148,7 @@
387 class BFont {
388 public:
389 BFont();
390+ BFont(const char *which);
391 BFont(const BFont &font);
392 BFont(const BFont *font);
393
394Index: headers/private/app/ServerProtocol.h
395===================================================================
396--- headers/private/app/ServerProtocol.h (révision 30265)
397+++ headers/private/app/ServerProtocol.h (copie de travail)
398@@ -108,6 +108,7 @@
399
400 // Font-related server communications
401 AS_SET_SYSTEM_FONT,
402+ AS_GET_SYSTEM_FONT,
403 AS_GET_SYSTEM_FONTS,
404 AS_GET_SYSTEM_DEFAULT_FONT,
405 AS_SYSTEM_FONT_CHANGED,