Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_GFX_SYSTEM_FONTS_WIN_H_ |
| 6 | #define UI_GFX_SYSTEM_FONTS_WIN_H_ |
| 7 | |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 8 | #include "base/component_export.h" |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 9 | #include "ui/gfx/font.h" |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 10 | |
| 11 | namespace gfx { |
| 12 | namespace win { |
| 13 | |
| 14 | // Represents an optional override of system font and scale. |
| 15 | struct FontAdjustment { |
Jan Wilken Dörrie | 461e1d7 | 2020-10-03 09:51:09 | [diff] [blame] | 16 | std::wstring font_family_override; |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 17 | double font_scale = 1.0; |
| 18 | }; |
| 19 | |
| 20 | // Identifiers for Windows-specific fonts described in the NONCLIENTMETRICS |
| 21 | // struct. |
| 22 | enum class SystemFont { kCaption = 0, kSmallCaption, kMenu, kStatus, kMessage }; |
| 23 | |
| 24 | // Callback that returns the minimum height that should be used for |
| 25 | // gfx::Fonts. Optional. If not specified, the minimum font size is 0. |
| 26 | typedef int (*GetMinimumFontSizeCallback)(); |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 27 | COMPONENT_EXPORT(GFX) |
| 28 | void SetGetMinimumFontSizeCallback(GetMinimumFontSizeCallback callback); |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 29 | |
| 30 | // Callback that adjusts a FontAdjustment to meet suitability requirements |
| 31 | // of the embedding application. Optional. If not specified, no adjustments |
| 32 | // are performed other than clamping to a minimum font size if |
| 33 | // |get_minimum_font_size_callback| is specified. |
Peter Kasting | 0d0322b | 2023-08-08 19:24:23 | [diff] [blame] | 34 | typedef void (*AdjustFontCallback)(FontAdjustment& font_adjustment); |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 35 | COMPONENT_EXPORT(GFX) void SetAdjustFontCallback(AdjustFontCallback callback); |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 36 | |
Etienne Bergeron | 08a619e0 | 2019-08-03 02:49:29 | [diff] [blame] | 37 | // Returns the specified Windows default system font. By default, this is the |
| 38 | // font used for message boxes (see struct NONCLIENTMETRICS). |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 39 | COMPONENT_EXPORT(GFX) const Font& GetDefaultSystemFont(); |
Etienne Bergeron | 08a619e0 | 2019-08-03 02:49:29 | [diff] [blame] | 40 | |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 41 | // Returns the specified Windows system font, suitable for drawing on screen |
| 42 | // elements. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 43 | COMPONENT_EXPORT(GFX) const Font& GetSystemFont(SystemFont system_font); |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 44 | |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 45 | // Computes and returns the adjusted size of a font, subject to the global |
| 46 | // minimum size. |lf_height| is the height as reported by the LOGFONT structure, |
| 47 | // and may be positive or negative (but is typically negative, indicating |
| 48 | // character size rather than cell size). The absolute value of |lf_size| will |
| 49 | // be adjusted by |size_delta| and then returned with the original sign. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 50 | COMPONENT_EXPORT(GFX) int AdjustFontSize(int lf_height, int size_delta); |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 51 | |
| 52 | // Adjusts a LOGFONT structure for optional size scale and face override. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 53 | COMPONENT_EXPORT(GFX) |
| 54 | void AdjustLOGFONTForTesting(const FontAdjustment& font_adjustment, |
| 55 | LOGFONT* logfont); |
Etienne Bergeron | 3013702 | 2019-06-07 18:25:30 | [diff] [blame] | 56 | |
Etienne Bergeron | 728cd3a | 2019-08-02 22:34:25 | [diff] [blame] | 57 | // Retrieves a FONT from a LOGFONT structure. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 58 | COMPONENT_EXPORT(GFX) Font GetFontFromLOGFONTForTesting(const LOGFONT& logfont); |
Etienne Bergeron | 728cd3a | 2019-08-02 22:34:25 | [diff] [blame] | 59 | |
| 60 | // Clears the system fonts cache. SystemFonts is keeping a global state that |
Etienne Bergeron | 3013702 | 2019-06-07 18:25:30 | [diff] [blame] | 61 | // must be reset in unittests when using |GetMinimumFontSizeCallback| or |
| 62 | // |SetAdjustFontCallback|. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 63 | COMPONENT_EXPORT(GFX) void ResetSystemFontsForTesting(); |
Etienne Bergeron | 3013702 | 2019-06-07 18:25:30 | [diff] [blame] | 64 | |
Etienne Bergeron | 29c3874 | 2019-03-27 19:53:23 | [diff] [blame] | 65 | } // namespace win |
| 66 | } // namespace gfx |
| 67 | |
| 68 | #endif // UI_GFX_SYSTEM_FONTS_WIN_H_ |