blob: bd361be7afcfe1b5add4e5f841cf6b41d99ae4f1 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2019 The Chromium Authors
Etienne Bergeron29c38742019-03-27 19:53:232// 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 Lee7d17d5572024-11-10 13:52:458#include "base/component_export.h"
Etienne Bergeron29c38742019-03-27 19:53:239#include "ui/gfx/font.h"
Etienne Bergeron29c38742019-03-27 19:53:2310
11namespace gfx {
12namespace win {
13
14// Represents an optional override of system font and scale.
15struct FontAdjustment {
Jan Wilken Dörrie461e1d72020-10-03 09:51:0916 std::wstring font_family_override;
Etienne Bergeron29c38742019-03-27 19:53:2317 double font_scale = 1.0;
18};
19
20// Identifiers for Windows-specific fonts described in the NONCLIENTMETRICS
21// struct.
22enum 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.
26typedef int (*GetMinimumFontSizeCallback)();
Kalvin Lee7d17d5572024-11-10 13:52:4527COMPONENT_EXPORT(GFX)
28void SetGetMinimumFontSizeCallback(GetMinimumFontSizeCallback callback);
Etienne Bergeron29c38742019-03-27 19:53:2329
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 Kasting0d0322b2023-08-08 19:24:2334typedef void (*AdjustFontCallback)(FontAdjustment& font_adjustment);
Kalvin Lee7d17d5572024-11-10 13:52:4535COMPONENT_EXPORT(GFX) void SetAdjustFontCallback(AdjustFontCallback callback);
Etienne Bergeron29c38742019-03-27 19:53:2336
Etienne Bergeron08a619e02019-08-03 02:49:2937// Returns the specified Windows default system font. By default, this is the
38// font used for message boxes (see struct NONCLIENTMETRICS).
Kalvin Lee7d17d5572024-11-10 13:52:4539COMPONENT_EXPORT(GFX) const Font& GetDefaultSystemFont();
Etienne Bergeron08a619e02019-08-03 02:49:2940
Etienne Bergeron29c38742019-03-27 19:53:2341// Returns the specified Windows system font, suitable for drawing on screen
42// elements.
Kalvin Lee7d17d5572024-11-10 13:52:4543COMPONENT_EXPORT(GFX) const Font& GetSystemFont(SystemFont system_font);
Etienne Bergeron29c38742019-03-27 19:53:2344
Etienne Bergeron29c38742019-03-27 19:53:2345// 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 Lee7d17d5572024-11-10 13:52:4550COMPONENT_EXPORT(GFX) int AdjustFontSize(int lf_height, int size_delta);
Etienne Bergeron29c38742019-03-27 19:53:2351
52// Adjusts a LOGFONT structure for optional size scale and face override.
Kalvin Lee7d17d5572024-11-10 13:52:4553COMPONENT_EXPORT(GFX)
54void AdjustLOGFONTForTesting(const FontAdjustment& font_adjustment,
55 LOGFONT* logfont);
Etienne Bergeron30137022019-06-07 18:25:3056
Etienne Bergeron728cd3a2019-08-02 22:34:2557// Retrieves a FONT from a LOGFONT structure.
Kalvin Lee7d17d5572024-11-10 13:52:4558COMPONENT_EXPORT(GFX) Font GetFontFromLOGFONTForTesting(const LOGFONT& logfont);
Etienne Bergeron728cd3a2019-08-02 22:34:2559
60// Clears the system fonts cache. SystemFonts is keeping a global state that
Etienne Bergeron30137022019-06-07 18:25:3061// must be reset in unittests when using |GetMinimumFontSizeCallback| or
62// |SetAdjustFontCallback|.
Kalvin Lee7d17d5572024-11-10 13:52:4563COMPONENT_EXPORT(GFX) void ResetSystemFontsForTesting();
Etienne Bergeron30137022019-06-07 18:25:3064
Etienne Bergeron29c38742019-03-27 19:53:2365} // namespace win
66} // namespace gfx
67
68#endif // UI_GFX_SYSTEM_FONTS_WIN_H_