Problem: 1610435

Title: Initialize system and application font procedurally

Received: Dec 6 1996 11:59AM


Since extensions may change the default system and application font but can be specified using Font manager constants, MacApp's initialization of system and application font styles should be performed procedurally instead of via resources. Since we can rely on Font Manager constants for these, we should use them instead of on TxSt resources.

I would suggest replacing these lines in DoInitUMacApp:

   gSystemStyle = MAGetTextStyle(kSystemFontTextStyle);
   gApplicationStyle = MAGetTextStyle(kApplFont12TextStyle);
   gApplicationStyle9 = MAGetTextStyle(kApplFont9TextStyle);
with these lines: (for r11; similar for 3.3)
   gSystemStyle = CTextStyle(systemFont, plain, 0, gRGBBlack);
   gApplicationStyle = CTextStyle(applFont, plain, 0, gRGBBlack);
   gApplicationStyle9 = CTextStyle(applFont, plain, 9, gRGBBlack);

Some background on this:

I don't know if this is a bug or a feature ;) This is in MacApp 3.3 and r11. I am seeing a strange interaction between MacApp's use of font numbers and our appearance extension, which changes the system font. I think that the MacApp code is not doing the best thing. Here is the background.

A text style object (struct TextStyle in 3.3, class CTextStyle in r11) describes a font/size/style/color. These are often built by reading a TxSt resource.

The difference between a TxSt resource and a text style in memory is that the font name in the resource is converted to a font num via GetFontNum() in the routine MAGetTextStyle (UMacAppUtilities). Font nums are not to be hardcoded at compile time. You should always convert a font name to a font num at runtime. Two exceptions: the system font num is 0 (systemFont); the application font num is 1 (applFont). Also, font size 0 means to use the "application" point size (typically 12). So for Chicago 12 you should use font num 0, font size 0, unless you really mean specifically "Chicago" and "12" rather than the system font and default size.

MacApp maintains 3 global text styles for commonly needed styles, which come from TxSt resources 128, 129, and 130:

OK, so here is the thing. MacApp uses GetFontNum to convert an empty string (in TxSt 128) or the string "a" (in TxSt 129/130. Must be Font Manager magic I've never heard about) into font nums for these 3 globals. My gSystemStyle.tsFont is getting a number like 9841.

The problem is this: When replacing the system font, and MacApp sets the port's font to the gSystemStyle, I get lied to by QuickDraw when doing things like calculating font metrics with StringWidth and GetFontInfo. If I hack it to use tsFont = systemFont rather than the font num obtained via GetFontNum, I get the correct metrics from QuickDraw. Shouldn't MacApp simply set the tsFont of these global text styles to systemFont and applFont, rather than actually using TxSt resources and converting these wacky strings ("\p" and "\pa") through GetFontNum?

I would suggest replacing these lines in DoInitUMacApp:

   gSystemStyle = MAGetTextStyle(kSystemFontTextStyle);
   gApplicationStyle = MAGetTextStyle(kApplFont12TextStyle);
   gApplicationStyle9 = MAGetTextStyle(kApplFont9TextStyle);
with these lines: (for r11; similar for 3.3)
   gSystemStyle = CTextStyle(systemFont, plain, 0, gRGBBlack);
   gApplicationStyle = CTextStyle(applFont, plain, 0, gRGBBlack);
   gApplicationStyle9 = CTextStyle(applFont, plain, 9, gRGBBlack);

Fix:

Fixed as follows: