2022-04-09 08:14:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
2022-04-09 08:14:58 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-10-26 13:45:34 +00:00
|
|
|
#include <AK/FlyString.h>
|
2022-04-09 08:14:58 +00:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2024-06-28 18:27:00 +00:00
|
|
|
#include <LibGfx/Font/Typeface.h>
|
2022-04-09 08:14:58 +00:00
|
|
|
|
2024-07-25 18:59:30 +00:00
|
|
|
class SkFont;
|
|
|
|
|
2022-04-09 08:14:58 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2023-01-16 08:26:01 +00:00
|
|
|
class ScaledFont final : public Gfx::Font {
|
2022-04-09 08:14:58 +00:00
|
|
|
public:
|
2024-06-28 18:27:00 +00:00
|
|
|
ScaledFont(NonnullRefPtr<Typeface>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
|
2024-09-04 15:29:01 +00:00
|
|
|
ScaledFontMetrics metrics() const;
|
2022-04-09 08:14:58 +00:00
|
|
|
|
|
|
|
// ^Gfx::Font
|
2023-03-15 09:46:06 +00:00
|
|
|
virtual float point_size() const override;
|
2023-03-03 18:30:55 +00:00
|
|
|
virtual float pixel_size() const override;
|
|
|
|
virtual int pixel_size_rounded_up() const override;
|
2022-04-09 08:14:58 +00:00
|
|
|
virtual Gfx::FontPixelMetrics pixel_metrics() const override;
|
2024-07-12 12:08:40 +00:00
|
|
|
virtual u8 slope() const override { return m_typeface->slope(); }
|
|
|
|
virtual u16 weight() const override { return m_typeface->weight(); }
|
|
|
|
virtual bool contains_glyph(u32 code_point) const override { return m_typeface->glyph_id_for_code_point(code_point) > 0; }
|
2023-01-03 13:55:48 +00:00
|
|
|
virtual float glyph_width(u32 code_point) const override;
|
2024-07-12 12:08:40 +00:00
|
|
|
virtual u32 glyph_id_for_code_point(u32 code_point) const override { return m_typeface->glyph_id_for_code_point(code_point); }
|
2023-01-05 16:13:55 +00:00
|
|
|
virtual float preferred_line_height() const override { return metrics().height() + metrics().line_gap; }
|
2024-06-04 13:38:47 +00:00
|
|
|
virtual int x_height() const override { return m_point_height; } // FIXME: Read from font
|
2022-04-09 08:14:58 +00:00
|
|
|
virtual u8 baseline() const override { return m_point_height; } // FIXME: Read from font
|
2023-01-03 13:43:07 +00:00
|
|
|
virtual float width(StringView) const override;
|
|
|
|
virtual float width(Utf8View const&) const override;
|
2024-10-26 21:27:21 +00:00
|
|
|
virtual FlyString const& family() const override { return m_typeface->family(); }
|
2022-04-09 08:14:58 +00:00
|
|
|
|
2024-03-01 13:06:42 +00:00
|
|
|
virtual NonnullRefPtr<ScaledFont> scaled_with_size(float point_size) const;
|
2024-05-06 17:12:16 +00:00
|
|
|
virtual NonnullRefPtr<Font> with_size(float point_size) const override;
|
2023-02-09 08:55:05 +00:00
|
|
|
|
2024-07-25 18:59:30 +00:00
|
|
|
virtual Typeface const& typeface() const override { return m_typeface; }
|
|
|
|
|
|
|
|
SkFont skia_font(float scale) const;
|
|
|
|
|
2022-04-09 08:14:58 +00:00
|
|
|
private:
|
2024-07-12 12:08:40 +00:00
|
|
|
NonnullRefPtr<Typeface> m_typeface;
|
2022-04-09 08:14:58 +00:00
|
|
|
float m_x_scale { 0.0f };
|
|
|
|
float m_y_scale { 0.0f };
|
|
|
|
float m_point_width { 0.0f };
|
|
|
|
float m_point_height { 0.0f };
|
2023-01-16 08:26:01 +00:00
|
|
|
Gfx::FontPixelMetrics m_pixel_metrics;
|
2022-04-09 08:14:58 +00:00
|
|
|
|
2023-03-03 18:30:55 +00:00
|
|
|
float m_pixel_size { 0.0f };
|
|
|
|
int m_pixel_size_rounded_up { 0 };
|
2022-04-09 08:14:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|