1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 23:05:07 +00:00
serenity/Userland/Libraries/LibGfx/Font/VectorFont.h
Andreas Kling 69c33bd4ca LibGfx/OpenType: Load x-height metrics from OS/2 table if available
Before this change we always returned the font's point size as the
x-height which was basically never correct.

We now get it from the OS/2 table (if one with version >= 2 is available
in the file). Otherwise we fall back to using the ascent of the 'x'
glyph. Most fonts appear to have a sufficiently modern OS/2 table.
2023-06-10 21:46:33 +02:00

54 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Noncopyable.h>
#include <AK/RefCounted.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Forward.h>
namespace Gfx {
struct ScaledFontMetrics {
float ascender { 0 };
float descender { 0 };
float line_gap { 0 };
float x_height { 0 };
float height() const
{
return ascender + descender;
}
};
struct ScaledGlyphMetrics {
float ascender;
float descender;
float advance_width;
float left_side_bearing;
};
class VectorFont : public RefCounted<VectorFont> {
public:
virtual ~VectorFont() { }
virtual ScaledFontMetrics metrics(float x_scale, float y_scale) const = 0;
virtual ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0;
virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const = 0;
virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, GlyphSubpixelOffset) const = 0;
virtual u32 glyph_count() const = 0;
virtual u16 units_per_em() const = 0;
virtual u32 glyph_id_for_code_point(u32 code_point) const = 0;
virtual DeprecatedString family() const = 0;
virtual DeprecatedString variant() const = 0;
virtual u16 weight() const = 0;
virtual u16 width() const = 0;
virtual u8 slope() const = 0;
virtual bool is_fixed_width() const = 0;
virtual bool has_color_bitmaps() const = 0;
};
}