P/Invoke and ChooseFont (Comdlg32.dll)

Mister Goodcat wrote a good article a little while ago about using P/Invoke in Silverlight 5 to display the native font chooser dialog with the ChooseFont function. I couldn’t get the code working for a 64-bit executable, however, as the definition of the CHOOSEFONT structure on MSDN he used as a basis for the managed implementation doesn’t match with what’s in the Windows SDK. I’ve created a page on PInvoke.net for the function that includes a definition of CHOOSEFONT that works in both 32-bit and 64-bit versions of Windows.

Screenshot of Font Chooser Dialog

Office 2013: Further Evidence of the Demise of ClearType?

Poking around the Office 2013 Customer Preview, one thing that caught my eye immediately was the lack of ClearType font smoothing. Nearly all user interface elements use ‘greyscale’ font smoothing (as opposed to ClearType’s sub-pixel smoothing). I’ve highlighted the parts of Word 2013 that still use ClearType:

Screenshot of ClearType in Microsoft Word 2013Screenshot of ClearType in Microsoft Word 2013

The text in cells in Excel 2013 still respects the system’s ClearType setting, and Outlook 2013 is a real mess (about half-and-half). OneNote 2013 seems to have retained ClearType in most places (outside the ribbon control).

Long Zheng earlier noted the absence of ClearType from the Metro environment and there are several possible reasons for it falling out of favour at Microsoft. Sub-pixel anti-aliasing isn’t necessarily suited to tablets that need to support multiple orientations (unless different sub-pixel orderings are taken into account), and screens with high pixel densities can get away with greyscale font smoothing.

I fear that this is another case of the tablet tail wagging the Microsoft dog – desktop and laptop users of Office 2013 (and Metro-style apps in Windows 8) will have to deal with lower quality text due to the new hardware Microsoft is targeting with its upcoming releases.

The Office 2013 Customer Preview is, of course, just that, and things might change before RTM. Regrettably this wasn’t fixed for the Office 2013 RTM.

More on Segoe UI in Windows 8

Note: the following is based on the Windows 8 Release Preview (build 8400) and may not accurately reflect the final version of Windows 8. I’ll update this post if there are changes in future builds.

Updated: The fonts have been updated in the public beta (Windows Consumer Preview) and release candidate (Windows Release Preview) and I’ve changed the tables below to reflect this. I was also made aware of some additional information about changes to Segoe UI, including new stylistic sets and support for ligatures: you can read more at Subacme.

Further to my earlier post about Segoe UI Light in Windows 8, I’ve done some more research into the changes to the Segoe family of fonts. The Fonts class in the .NET Framework was helpful for retrieving information about the fonts.

First off, Segoe Print and Segoe Script and their bold variants have not been modified and are still labelled version 5.02 and 5.00, respectively. All existing variants of Segoe UI have been updated, and there is one new variant: Segoe UI Semilight. The latter is in fact used as the caption and small caption font in Windows 8 – Windows Vista and Windows 7 used Segoe UI (Regular). The Windows Phone 7 platform includes Segoe WP Semilight, and Segoe UI Semilight seems to be a superset of that font.

Apparently new in the Windows 8 Release Preview are three italic variants: Segoe UI Light Italic, Segoe UI Semibold Italic and Segoe UI Semilight Italic.

The following tables summarise the differences in glyph and character counts between the Windows 7 and Windows 8 versions of the Segoe UI font family:

Segoe UI Regular

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.12 5.16 5.24
Glyphs 2899 4281 4490 4516
Characters 2658 3283 3423 3404

Segoe UI Bold

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.12 5.15 5.24
Glyphs 2899 4290 4428 4442
Characters 2658 3283 3421 3401

Segoe UI Italic

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.10 5.15 5.22
Glyphs 2381 2478 2597 3077
Characters 2130 2180 2299 2525

Segoe UI Bold Italic

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.10 5.15 5.22
Glyphs 2381 2478 2597 3077
Characters 2130 2180 2299 2525

Segoe UI Light

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.00 5.12 5.15 5.25
Glyphs 2380 4036 4178 4236
Characters 2131 3090 3230 3211

Segoe UI Light Italic

  Windows 8 Release Preview
Version 5.22
Glyphs 3089
Characters 2525

Segoe UI Semibold

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.00 5.12 5.16 5.24
Glyphs 2380 4089 4228 4242
Characters 2131 3144 3231 3211

Segoe UI Semibold Italic

  Windows 8 Release Preview
Version 5.22
Glyphs 3089
Characters 2525

Segoe UI Semilight

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version N/A 5.12 5.15 5.24
Glyphs N/A 4034 4175 4189
Characters N/A 3090 3230 3210

Segoe UI Semilight Italic

  Windows 8 Release Preview
Version 5.23
Glyphs 3089
Characters 2525

Segoe UI Symbol

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.00 5.33 5.46 5.55
Glyphs 3090 5122 6785 6846
Characters 2864 4547 5092 5217

Supported Unicode Blocks

For further information about which Unicode blocks are supported by the Segoe family of fonts, you can download my extended analysis here:

segoe-analysis.7z
2,825 bytes; SHA-1: DFFA40934DB3305054C40AF3FD6E7224F5CF1EFB

Segoe UI Light Improvements in Windows 8

Windows 7 comes with Segoe UI Light version 5.00/0.90. Windows 8 (as of the Windows Consumer Preview) comes with version 5.15, which has been hinted at various sizes. This comes as a very welcome change, especially with Microsoft using Segoe UI Light all over the place in its latest webpage designs. I recommend grabbing the updated versions of Segoe UI from Windows 8 for your Windows 7 or Windows Vista machines.

As others have complained, the lack of hinting in version 5.00 is particularly noticeable with lowercase bs, ds, ps and qs, the ‘round parts’ of which don’t line up well with other characters. The heights of numerals are also variable at some sizes.

Have a look at the following screenshots for a better idea of the differences (click the images to see the full sizes).

Version 5.00

Screenshot of Segoe UI Light 5.00

Version 5.15

Screenshot of Segoe UI Light 5.15

Difference

Screenshot of the difference between Segoe UI Light 5.15 and Segoe UI Light 5.00

Theming & Visual Styles in Windows 8

The following is based on the Windows Developer Preview and might not accurately represent the final version of Windows 8.

A significant change in Windows 8 is the removal of support for Windows classic theming. In the Windows Developer Preview, there is no Windows Classic theme, and all themes (including Windows Basic and the four high contrast themes) use the Desktop Window Manager (DWM) for desktop composition (in Windows Vista and Windows 7, it was only enabled for Aero themes).

While some users may miss the Windows Classic theme (it might return in later builds, of course), this is definitely a positive development. All themes will receive the benefits of hardware acceleration, and there will no longer be the need to maintain a separate code path for when the DWM is disabled (as long as the program targets only Windows 8 or later).

In order to maintain compatibility with earlier versions of Windows, when a high contrast theme is selected, Windows 8 will simulate the Windows classic theming model unless an application specifies Windows 8 as a supported OS in its application manifest. The sample program I made for the previous post did not include such a manifest, so it doesn’t work correctly in the Windows Developer Preview with high contrast themes:WPF sample without manifest

Compare this to a task dialog:

Task Dialog (High Contrast #1)

(The button in the WPF window is also drawn incorrectly, but presumably that will be fixed in .NET 4.5.)

Adding the appropriate manifest to the application causes it to work as it should:

WPF sample with manifest

I’ve updated the sample code in the previous post to include the manifest file.

Windows Theme Fonts Redux & Sample Code

View source on GitHub.

In a post earlier this year, I investigated how to retrieve information about theme fonts in Windows. Briefly, the Visual Styles APIs can be used when visual styles are enabled, but values need to be hard-coded (to some extent) otherwise.

Andrew Powell commented on my previous post noting difficulties in implementing the GetThemeFont function in managed code. In this post, I’ll demonstrate how to implement the relevant functions in a simple WPF project. In particular, I’ll focus on displaying information about the ‘main instruction’ text style as seen in Task Dialogs.

Read on for details.

Continue reading “Windows Theme Fonts Redux & Sample Code”

Windows Theme Fonts

View source on GitHub.

Update: See this post for a sample implementation in WPF.

Screenshot of Task Dialog (Aero)

Have you ever wondered how to access the various font colours and styles found throughout Windows, such as that of the ‘Main Instruction’ text in the Task Dialog shown above?

If you are using WPF, the SystemFonts class might sound promising at first. However, this class only exposes the following: the icon font, caption font, small caption font, menu font, message font and status font. These aren’t very exciting – in fact, they are all simply 9pt Segoe UI in Windows Vista/7 Aero. (Aside: early Windows 8 builds use 11pt Segoe UI Semilight as the caption (and small caption) font.) For those using Win32 directly, the SystemFonts class wraps around the SystemParametersInfo function (specifically with the messages SPI_GETNONCLIENTMETRICS and SPI_GETICONTITLELOGFONT) the GetThemeSysFont function.

MSDN offers some guidance on default fonts and colours in Windows Vista/7: apparently ‘Main Instruction’ text is 12pt #003399 Segoe UI. This table, while helpful, is not comprehensive, and in general it’s not a good idea to hard-code this kind of thing, as themes/visual styles are liable to change.

The keys lie in the Visual Styles APIs, introduced in Windows XP. In particular, the GetThemeFont function and GetThemeColor function (with the TMT_TEXTCOLOR property identifier), both found in UxTheme.dll. We simply need to specify the ‘part and state’ of the control in question (these are defined in Vsstyle.h and Vssym32.h). ‘Main Instruction’ text, for example, is referenced by the TEXT_MAININSTRUCTION part in the TEXTSTYLE class.

Screenshot of Task Dialog (Classic)

Regrettably, visual styles APIs only work when visual styles are enabled (who’d have thought it?). That is to say, we can’t rely on them with classic themes (Windows Classic and the High Contrast themes).

I emailed the very knowledgeable Larry Osterman about this, and he was kind enough to respond:

AeroStyle.xml tells which metrics to ask for which theme parts (for the OS that matches the version of the SDK it’s in), but there’s no theme API support for classic modes.

Basically they get the metric they’re looking for from the AeroStyle.xml file.

AeroStyle.xml is included in the latest versions of the Windows SDK. It contains the same classes and parts and states mentioned earlier in an XML format. The ‘MainInstruction’ part in the ‘TextStyle’ class looks like this, for instance:

Of interest are the ‘ClassicValue’ elements. When visual styles are disabled, it seems that ‘Main Instruction’ text uses the caption font (8pt bold Microsoft Sans Serif, as it happens).

In closing: you can use GetThemeFont and GetThemeColor if visual styles are enabled, but you will need look at AeroStyle.xml and hard-code the classic theme fall-back values.