VectorFont.h 1.9 KB

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