1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:27:45 +00:00

Everywhere: codepoint => code point

This commit is contained in:
Andreas Kling 2021-06-01 10:01:11 +02:00
parent a8ae8b24de
commit 12a42edd13
18 changed files with 240 additions and 240 deletions

View file

@ -75,72 +75,72 @@ Optional<Cmap::Subtable> Cmap::subtable(u32 index) const
}
// FIXME: This only handles formats 4 (SegmentToDelta) and 12 (SegmentedCoverage) for now.
u32 Cmap::Subtable::glyph_id_for_codepoint(u32 codepoint) const
u32 Cmap::Subtable::glyph_id_for_code_point(u32 code_point) const
{
switch (format()) {
case Format::SegmentToDelta:
return glyph_id_for_codepoint_table_4(codepoint);
return glyph_id_for_code_point_table_4(code_point);
case Format::SegmentedCoverage:
return glyph_id_for_codepoint_table_12(codepoint);
return glyph_id_for_code_point_table_12(code_point);
default:
return 0;
}
}
u32 Cmap::Subtable::glyph_id_for_codepoint_table_4(u32 codepoint) const
u32 Cmap::Subtable::glyph_id_for_code_point_table_4(u32 code_point) const
{
u32 segcount_x2 = be_u16(m_slice.offset_pointer((u32)Table4Offsets::SegCountX2));
if (m_slice.size() < segcount_x2 * (u32)Table4Sizes::NonConstMultiplier + (u32)Table4Sizes::Constant) {
return 0;
}
for (u32 offset = 0; offset < segcount_x2; offset += 2) {
u32 end_codepoint = be_u16(m_slice.offset_pointer((u32)Table4Offsets::EndConstBase + offset));
if (codepoint > end_codepoint) {
u32 end_code_point = be_u16(m_slice.offset_pointer((u32)Table4Offsets::EndConstBase + offset));
if (code_point > end_code_point) {
continue;
}
u32 start_codepoint = be_u16(m_slice.offset_pointer((u32)Table4Offsets::StartConstBase + segcount_x2 + offset));
if (codepoint < start_codepoint) {
u32 start_code_point = be_u16(m_slice.offset_pointer((u32)Table4Offsets::StartConstBase + segcount_x2 + offset));
if (code_point < start_code_point) {
break;
}
u32 delta = be_u16(m_slice.offset_pointer((u32)Table4Offsets::DeltaConstBase + segcount_x2 * 2 + offset));
u32 range = be_u16(m_slice.offset_pointer((u32)Table4Offsets::RangeConstBase + segcount_x2 * 3 + offset));
if (range == 0) {
return (codepoint + delta) & 0xffff;
return (code_point + delta) & 0xffff;
}
u32 glyph_offset = (u32)Table4Offsets::GlyphOffsetConstBase + segcount_x2 * 3 + offset + range + (codepoint - start_codepoint) * 2;
u32 glyph_offset = (u32)Table4Offsets::GlyphOffsetConstBase + segcount_x2 * 3 + offset + range + (code_point - start_code_point) * 2;
VERIFY(glyph_offset + 2 <= m_slice.size());
return (be_u16(m_slice.offset_pointer(glyph_offset)) + delta) & 0xffff;
}
return 0;
}
u32 Cmap::Subtable::glyph_id_for_codepoint_table_12(u32 codepoint) const
u32 Cmap::Subtable::glyph_id_for_code_point_table_12(u32 code_point) const
{
u32 num_groups = be_u32(m_slice.offset_pointer((u32)Table12Offsets::NumGroups));
VERIFY(m_slice.size() >= (u32)Table12Sizes::Header + (u32)Table12Sizes::Record * num_groups);
for (u32 offset = 0; offset < num_groups * (u32)Table12Sizes::Record; offset += (u32)Table12Sizes::Record) {
u32 start_codepoint = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_StartCode + offset));
if (codepoint < start_codepoint) {
u32 start_code_point = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_StartCode + offset));
if (code_point < start_code_point) {
break;
}
u32 end_codepoint = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_EndCode + offset));
if (codepoint > end_codepoint) {
u32 end_code_point = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_EndCode + offset));
if (code_point > end_code_point) {
continue;
}
u32 glyph_offset = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_StartGlyph + offset));
return codepoint - start_codepoint + glyph_offset;
return code_point - start_code_point + glyph_offset;
}
return 0;
}
u32 Cmap::glyph_id_for_codepoint(u32 codepoint) const
u32 Cmap::glyph_id_for_code_point(u32 code_point) const
{
auto opt_subtable = subtable(m_active_index);
if (!opt_subtable.has_value()) {
return 0;
}
auto subtable = opt_subtable.value();
return subtable.glyph_id_for_codepoint(codepoint);
return subtable.glyph_id_for_code_point(code_point);
}
Optional<Cmap> Cmap::from_slice(const ReadonlyBytes& slice)

View file

@ -44,7 +44,7 @@ public:
{
}
// Returns 0 if glyph not found. This corresponds to the "missing glyph"
u32 glyph_id_for_codepoint(u32 codepoint) const;
u32 glyph_id_for_code_point(u32 code_point) const;
Platform platform_id() const;
u16 encoding_id() const { return m_encoding_id; }
Format format() const;
@ -73,8 +73,8 @@ public:
Record = 12,
};
u32 glyph_id_for_codepoint_table_4(u32 codepoint) const;
u32 glyph_id_for_codepoint_table_12(u32 codepoint) const;
u32 glyph_id_for_code_point_table_4(u32 code_point) const;
u32 glyph_id_for_code_point_table_12(u32 code_point) const;
ReadonlyBytes m_slice;
u16 m_raw_platform_id { 0 };
@ -86,7 +86,7 @@ public:
Optional<Subtable> subtable(u32 index) const;
void set_active_index(u32 index) { m_active_index = index; }
// Returns 0 if glyph not found. This corresponds to the "missing glyph"
u32 glyph_id_for_codepoint(u32 codepoint) const;
u32 glyph_id_for_code_point(u32 code_point) const;
private:
enum class Offsets {

View file

@ -501,7 +501,7 @@ bool Font::is_fixed_width() const
{
// FIXME: Read this information from the font file itself.
// FIXME: Although, it appears some application do similar hacks
return glyph_metrics(glyph_id_for_codepoint('.'), 1, 1).advance_width == glyph_metrics(glyph_id_for_codepoint('X'), 1, 1).advance_width;
return glyph_metrics(glyph_id_for_code_point('.'), 1, 1).advance_width == glyph_metrics(glyph_id_for_code_point('X'), 1, 1).advance_width;
}
int ScaledFont::width(const StringView& string) const
@ -513,8 +513,8 @@ int ScaledFont::width(const StringView& string) const
int ScaledFont::width(const Utf8View& utf8) const
{
int width = 0;
for (u32 codepoint : utf8) {
u32 glyph_id = glyph_id_for_codepoint(codepoint);
for (u32 code_point : utf8) {
u32 glyph_id = glyph_id_for_code_point(code_point);
auto metrics = glyph_metrics(glyph_id);
width += metrics.advance_width;
}
@ -525,7 +525,7 @@ int ScaledFont::width(const Utf32View& utf32) const
{
int width = 0;
for (size_t i = 0; i < utf32.length(); i++) {
u32 glyph_id = glyph_id_for_codepoint(utf32.code_points()[i]);
u32 glyph_id = glyph_id_for_code_point(utf32.code_points()[i]);
auto metrics = glyph_metrics(glyph_id);
width += metrics.advance_width;
}
@ -545,7 +545,7 @@ RefPtr<Gfx::Bitmap> ScaledFont::raster_glyph(u32 glyph_id) const
Gfx::Glyph ScaledFont::glyph(u32 code_point) const
{
auto id = glyph_id_for_codepoint(code_point);
auto id = glyph_id_for_code_point(code_point);
auto bitmap = raster_glyph(id);
auto metrics = glyph_metrics(id);
return Gfx::Glyph(bitmap, metrics.left_side_bearing, metrics.advance_width, metrics.ascender);
@ -553,21 +553,21 @@ Gfx::Glyph ScaledFont::glyph(u32 code_point) const
u8 ScaledFont::glyph_width(size_t code_point) const
{
auto id = glyph_id_for_codepoint(code_point);
auto id = glyph_id_for_code_point(code_point);
auto metrics = glyph_metrics(id);
return metrics.advance_width;
}
int ScaledFont::glyph_or_emoji_width(u32 code_point) const
{
auto id = glyph_id_for_codepoint(code_point);
auto id = glyph_id_for_code_point(code_point);
auto metrics = glyph_metrics(id);
return metrics.advance_width;
}
u8 ScaledFont::glyph_fixed_width() const
{
return glyph_metrics(glyph_id_for_codepoint(' ')).advance_width;
return glyph_metrics(glyph_id_for_code_point(' ')).advance_width;
}
}

View file

@ -54,7 +54,7 @@ public:
RefPtr<Gfx::Bitmap> raster_glyph(u32 glyph_id, float x_scale, float y_scale) const;
u32 glyph_count() const;
u16 units_per_em() const;
u32 glyph_id_for_codepoint(u32 codepoint) const { return m_cmap.glyph_id_for_codepoint(codepoint); }
u32 glyph_id_for_code_point(u32 code_point) const { return m_cmap.glyph_id_for_code_point(code_point); }
String family() const;
String variant() const;
u16 weight() const;
@ -110,7 +110,7 @@ public:
m_x_scale = (point_width * dpi_x) / (POINTS_PER_INCH * units_per_em);
m_y_scale = (point_height * dpi_y) / (POINTS_PER_INCH * units_per_em);
}
u32 glyph_id_for_codepoint(u32 codepoint) const { return m_font->glyph_id_for_codepoint(codepoint); }
u32 glyph_id_for_code_point(u32 code_point) const { return m_font->glyph_id_for_code_point(code_point); }
ScaledFontMetrics metrics() const { return m_font->metrics(m_x_scale, m_y_scale); }
ScaledGlyphMetrics glyph_metrics(u32 glyph_id) const { return m_font->glyph_metrics(glyph_id, m_x_scale, m_y_scale); }
RefPtr<Gfx::Bitmap> raster_glyph(u32 glyph_id) const;
@ -120,7 +120,7 @@ public:
virtual u8 presentation_size() const override { return m_point_height; }
virtual u16 weight() const override { return m_font->weight(); }
virtual Gfx::Glyph glyph(u32 code_point) const override;
virtual bool contains_glyph(u32 code_point) const override { return m_font->glyph_id_for_codepoint(code_point) > 0; }
virtual bool contains_glyph(u32 code_point) const override { return m_font->glyph_id_for_code_point(code_point) > 0; }
virtual u8 glyph_width(size_t ch) const override;
virtual int glyph_or_emoji_width(u32 code_point) const override;
virtual u8 glyph_height() const override { return m_point_height; }