blob: 7d5e2ffb5017ed7353f689ff899f2600fc711ad2 [file] [log] [blame]
Keren Zhufcfdc102023-06-30 15:52:461// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ui/gfx/platform_font.h"
6
7#include "ui/gfx/font_list.h"
8
9namespace gfx {
10
11// static
12int PlatformFont::GetFontSizeDeltaIgnoringUserOrLocaleSettings(
13 int desired_font_size) {
14 int size_delta = desired_font_size - gfx::PlatformFont::kDefaultBaseFontSize;
15 gfx::FontList base_font = gfx::FontList().DeriveWithSizeDelta(size_delta);
16
17 // The default font may not actually be kDefaultBaseFontSize if, for example,
18 // the user has changed their system font sizes or the current locale has been
19 // overridden to use a different default font size. Adjust for the difference
20 // in default font sizes.
21 int user_or_locale_delta = 0;
22 if (base_font.GetFontSize() != desired_font_size) {
23 user_or_locale_delta = desired_font_size - base_font.GetFontSize();
24 base_font =
25 gfx::FontList().DeriveWithSizeDelta(size_delta + user_or_locale_delta);
26 }
27 DCHECK_EQ(desired_font_size, base_font.GetFontSize());
28
29 // To ensure a subsequent request from the ResourceBundle ignores the delta
30 // due to user or locale settings, include it here.
31 return base_font.GetFontSize() - gfx::PlatformFont::kDefaultBaseFontSize +
32 user_or_locale_delta;
33}
34
35} // namespace gfx