mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 20:22:13 +00:00
LibWeb: Scale the font when painting the text on buttons
Button text was staying the same size at all zoom levels. :^)
This commit is contained in:
parent
20132da88d
commit
5146b9b35e
4 changed files with 29 additions and 18 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibWeb/FontCache.h>
|
||||
|
||||
|
@ -21,6 +22,22 @@ RefPtr<Gfx::Font const> FontCache::get(FontSelector const& font_selector) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Gfx::Font const> FontCache::scaled_font(Gfx::Font const& font, float scale_factor)
|
||||
{
|
||||
auto device_font_pt_size = font.point_size() * scale_factor;
|
||||
FontSelector font_selector = { FlyString::from_deprecated_fly_string(font.family()).release_value_but_fixme_should_propagate_errors(), device_font_pt_size, font.weight(), font.width(), font.slope() };
|
||||
if (auto cached_font = FontCache::the().get(font_selector)) {
|
||||
return *cached_font;
|
||||
}
|
||||
|
||||
if (auto font_with_device_pt_size = font.with_size(device_font_pt_size)) {
|
||||
set(font_selector, *font_with_device_pt_size);
|
||||
return font_with_device_pt_size.release_nonnull();
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
void FontCache::set(FontSelector const& font_selector, NonnullRefPtr<Gfx::Font const> font)
|
||||
{
|
||||
m_fonts.set(font_selector, move(font));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue