/src/serenity/Userland/Libraries/LibGfx/Font/VectorFont.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/HashMap.h> |
10 | | #include <AK/Noncopyable.h> |
11 | | #include <AK/RefCounted.h> |
12 | | #include <LibGfx/Font/Font.h> |
13 | | #include <LibGfx/Forward.h> |
14 | | #include <LibGfx/Path.h> |
15 | | |
16 | 0 | #define POINTS_PER_INCH 72.0f |
17 | 0 | #define DEFAULT_DPI 96 |
18 | | |
19 | | namespace Gfx { |
20 | | |
21 | | class ScaledFont; |
22 | | |
23 | | struct ScaledFontMetrics { |
24 | | float ascender { 0 }; |
25 | | float descender { 0 }; |
26 | | float line_gap { 0 }; |
27 | | float x_height { 0 }; |
28 | | |
29 | | float height() const |
30 | 0 | { |
31 | 0 | return ascender + descender; |
32 | 0 | } |
33 | | }; |
34 | | |
35 | | struct ScaledGlyphMetrics { |
36 | | float ascender; |
37 | | float descender; |
38 | | float advance_width; |
39 | | float left_side_bearing; |
40 | | }; |
41 | | |
42 | | class VectorFont : public RefCounted<VectorFont> { |
43 | | public: |
44 | | virtual ~VectorFont(); |
45 | | virtual ScaledFontMetrics metrics(float x_scale, float y_scale) const = 0; |
46 | | virtual ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0; |
47 | | virtual float glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0; |
48 | | virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const = 0; |
49 | | virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, GlyphSubpixelOffset) const = 0; |
50 | | virtual bool append_glyph_path_to(Gfx::Path&, u32 glyph_id, float x_scale, float y_scale) const = 0; |
51 | | |
52 | | virtual u32 glyph_count() const = 0; |
53 | | virtual u16 units_per_em() const = 0; |
54 | | virtual u32 glyph_id_for_code_point(u32 code_point) const = 0; |
55 | | virtual String family() const = 0; |
56 | | virtual String variant() const = 0; |
57 | | virtual u16 weight() const = 0; |
58 | | virtual u16 width() const = 0; |
59 | | virtual u8 slope() const = 0; |
60 | | virtual bool is_fixed_width() const = 0; |
61 | | virtual bool has_color_bitmaps() const = 0; |
62 | | |
63 | | [[nodiscard]] NonnullRefPtr<ScaledFont> scaled_font(float point_size) const; |
64 | | |
65 | | protected: |
66 | | VectorFont(); |
67 | | |
68 | | private: |
69 | | mutable HashMap<float, NonnullRefPtr<ScaledFont>> m_scaled_fonts; |
70 | | }; |
71 | | |
72 | | } |