VectorFont.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #define POINTS_PER_INCH 72.0f
  13. #define DEFAULT_DPI 96
  14. namespace Gfx {
  15. class ScaledFont;
  16. struct ScaledFontMetrics {
  17. float ascender { 0 };
  18. float descender { 0 };
  19. float line_gap { 0 };
  20. float x_height { 0 };
  21. float height() const
  22. {
  23. return ascender + descender;
  24. }
  25. };
  26. struct ScaledGlyphMetrics {
  27. float ascender;
  28. float descender;
  29. float advance_width;
  30. float left_side_bearing;
  31. };
  32. class VectorFont : public RefCounted<VectorFont> {
  33. public:
  34. virtual ~VectorFont();
  35. virtual ScaledFontMetrics metrics(float x_scale, float y_scale) const = 0;
  36. virtual ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0;
  37. virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const = 0;
  38. virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, GlyphSubpixelOffset) const = 0;
  39. virtual bool append_glyph_path_to(Gfx::Path&, u32 glyph_id, float x_scale, float y_scale) const = 0;
  40. virtual u32 glyph_count() const = 0;
  41. virtual u16 units_per_em() const = 0;
  42. virtual u32 glyph_id_for_code_point(u32 code_point) const = 0;
  43. virtual String family() const = 0;
  44. virtual String variant() const = 0;
  45. virtual u16 weight() const = 0;
  46. virtual u16 width() const = 0;
  47. virtual u8 slope() const = 0;
  48. virtual bool is_fixed_width() const = 0;
  49. virtual bool has_color_bitmaps() const = 0;
  50. [[nodiscard]] NonnullRefPtr<ScaledFont> scaled_font(float point_size) const;
  51. protected:
  52. VectorFont();
  53. private:
  54. mutable HashMap<float, NonnullRefPtr<ScaledFont>> m_scaled_fonts;
  55. };
  56. }