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

Unicode: s/codepoint/code_point/g

Unicode calls them "code points" so let's follow their style.
This commit is contained in:
Andreas Kling 2020-08-03 19:06:41 +02:00
parent b139fb9f38
commit ea9ac3155d
45 changed files with 449 additions and 449 deletions

View file

@ -33,21 +33,21 @@ namespace Gfx {
static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis;
const Bitmap* Emoji::emoji_for_codepoint(u32 codepoint)
const Bitmap* Emoji::emoji_for_code_points(u32 code_points)
{
auto it = s_emojis.find(codepoint);
auto it = s_emojis.find(code_points);
if (it != s_emojis.end())
return (*it).value.ptr();
String path = String::format("/res/emoji/U+%X.png", codepoint);
String path = String::format("/res/emoji/U+%X.png", code_points);
auto bitmap = Bitmap::load_from_file(path);
if (!bitmap) {
s_emojis.set(codepoint, nullptr);
s_emojis.set(code_points, nullptr);
return nullptr;
}
s_emojis.set(codepoint, bitmap);
s_emojis.set(code_points, bitmap);
return bitmap.ptr();
}

View file

@ -34,7 +34,7 @@ class Bitmap;
class Emoji {
public:
static const Gfx::Bitmap* emoji_for_codepoint(u32 codepoint);
static const Gfx::Bitmap* emoji_for_code_points(u32 code_points);
};
}

View file

@ -255,20 +255,20 @@ bool Font::write_to_file(const StringView& path)
return true;
}
GlyphBitmap Font::glyph_bitmap(u32 codepoint) const
GlyphBitmap Font::glyph_bitmap(u32 code_points) const
{
return GlyphBitmap(&m_rows[codepoint * m_glyph_height], { glyph_width(codepoint), m_glyph_height });
return GlyphBitmap(&m_rows[code_points * m_glyph_height], { glyph_width(code_points), m_glyph_height });
}
int Font::glyph_or_emoji_width(u32 codepoint) const
int Font::glyph_or_emoji_width(u32 code_points) const
{
if (codepoint < m_glyph_count)
return glyph_width(codepoint);
if (code_points < m_glyph_count)
return glyph_width(code_points);
if (m_fixed_width)
return m_glyph_width;
auto* emoji = Emoji::emoji_for_codepoint(codepoint);
auto* emoji = Emoji::emoji_for_code_points(code_points);
if (emoji == nullptr)
return glyph_width('?');
return emoji->size().width();
@ -285,11 +285,11 @@ int Font::width(const Utf8View& utf8) const
bool first = true;
int width = 0;
for (u32 codepoint : utf8) {
for (u32 code_points : utf8) {
if (!first)
width += glyph_spacing();
first = false;
width += glyph_or_emoji_width(codepoint);
width += glyph_or_emoji_width(code_points);
}
return width;
@ -301,7 +301,7 @@ int Font::width(const Utf32View& view) const
return 0;
int width = (view.length() - 1) * glyph_spacing();
for (size_t i = 0; i < view.length(); ++i)
width += glyph_or_emoji_width(view.codepoints()[i]);
width += glyph_or_emoji_width(view.code_pointss()[i]);
return width;
}

View file

@ -89,10 +89,10 @@ public:
~Font();
GlyphBitmap glyph_bitmap(u32 codepoint) const;
GlyphBitmap glyph_bitmap(u32 code_points) const;
u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; }
int glyph_or_emoji_width(u32 codepoint) const;
int glyph_or_emoji_width(u32 code_points) const;
u8 glyph_height() const { return m_glyph_height; }
u8 min_glyph_width() const { return m_min_glyph_width; }
u8 max_glyph_width() const { return m_max_glyph_width; }

View file

@ -802,14 +802,14 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s
}
}
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, Color color)
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_points, Color color)
{
draw_glyph(point, codepoint, font(), color);
draw_glyph(point, code_points, font(), color);
}
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, const Font& font, Color color)
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_points, const Font& font, Color color)
{
draw_bitmap(point, font.glyph_bitmap(codepoint), color);
draw_bitmap(point, font.glyph_bitmap(code_points), color);
}
void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const Font& font)
@ -827,19 +827,19 @@ void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const
}
}
void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 codepoint, const Font& font, Color color)
void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 code_points, const Font& font, Color color)
{
if (codepoint < (u32)font.glyph_count()) {
if (code_points < (u32)font.glyph_count()) {
// This looks like a regular character.
draw_glyph(point, (size_t)codepoint, font, color);
draw_glyph(point, (size_t)code_points, font, color);
return;
}
// Perhaps it's an emoji?
auto* emoji = Emoji::emoji_for_codepoint(codepoint);
auto* emoji = Emoji::emoji_for_code_points(code_points);
if (emoji == nullptr) {
#ifdef EMOJI_DEBUG
dbg() << "Failed to find an emoji for codepoint " << codepoint;
dbg() << "Failed to find an emoji for code_points " << code_points;
#endif
draw_glyph(point, '?', font, color);
return;
@ -861,8 +861,8 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf8View& text, const
int new_width = font.width("...");
if (new_width < text_width) {
for (auto it = final_text.begin(); it != final_text.end(); ++it) {
u32 codepoint = *it;
int glyph_width = font.glyph_or_emoji_width(codepoint);
u32 code_points = *it;
int glyph_width = font.glyph_or_emoji_width(code_points);
// NOTE: Glyph spacing should not be added after the last glyph on the line,
// but since we are here because the last glyph does not actually fit on the line,
// we don't have to worry about spacing.
@ -903,13 +903,13 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf8View& text, const
auto point = rect.location();
int space_width = font.glyph_width(' ') + font.glyph_spacing();
for (u32 codepoint : final_text) {
if (codepoint == ' ') {
for (u32 code_points : final_text) {
if (code_points == ' ') {
point.move_by(space_width, 0);
continue;
}
draw_glyph_or_emoji(point, codepoint, font, color);
point.move_by(font.glyph_or_emoji_width(codepoint) + font.glyph_spacing(), 0);
draw_glyph_or_emoji(point, code_points, font, color);
point.move_by(font.glyph_or_emoji_width(code_points) + font.glyph_spacing(), 0);
}
}
@ -926,8 +926,8 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const
if (new_width < text_width) {
size_t i = 0;
for (; i < text.length(); ++i) {
u32 codepoint = text.codepoints()[i];
int glyph_width = font.glyph_or_emoji_width(codepoint);
u32 code_points = text.code_pointss()[i];
int glyph_width = font.glyph_or_emoji_width(code_points);
// NOTE: Glyph spacing should not be added after the last glyph on the line,
// but since we are here because the last glyph does not actually fit on the line,
// we don't have to worry about spacing.
@ -937,7 +937,7 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const
new_width += glyph_width + glyph_spacing;
}
elided_text.clear();
elided_text.append(final_text.codepoints(), i);
elided_text.append(final_text.code_pointss(), i);
elided_text.append('.');
elided_text.append('.');
elided_text.append('.');
@ -969,13 +969,13 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const
int space_width = font.glyph_width(' ') + font.glyph_spacing();
for (size_t i = 0; i < final_text.length(); ++i) {
auto codepoint = final_text.codepoints()[i];
if (codepoint == ' ') {
auto code_points = final_text.code_pointss()[i];
if (code_points == ' ') {
point.move_by(space_width, 0);
continue;
}
draw_glyph_or_emoji(point, codepoint, font, color);
point.move_by(font.glyph_or_emoji_width(codepoint) + font.glyph_spacing(), 0);
draw_glyph_or_emoji(point, code_points, font, color);
point.move_by(font.glyph_or_emoji_width(code_points) + font.glyph_spacing(), 0);
}
}
@ -996,8 +996,8 @@ void Painter::draw_text(const IntRect& rect, const StringView& raw_text, const F
int start_of_current_line = 0;
for (auto it = text.begin(); it != text.end(); ++it) {
u32 codepoint = *it;
if (codepoint == '\n') {
u32 code_points = *it;
if (code_points == '\n') {
int byte_offset = text.byte_offset_of(it);
Utf8View line = text.substring_view(start_of_current_line, byte_offset - start_of_current_line);
lines.append(line);
@ -1054,8 +1054,8 @@ void Painter::draw_text(const IntRect& rect, const Utf32View& text, const Font&
size_t start_of_current_line = 0;
for (size_t i = 0; i < text.length(); ++i) {
u32 codepoint = text.codepoints()[i];
if (codepoint == '\n') {
u32 code_points = text.code_pointss()[i];
if (code_points == '\n') {
Utf32View line = text.substring_view(start_of_current_line, i - start_of_current_line);
lines.append(line);
start_of_current_line = i + 1;

View file

@ -81,7 +81,7 @@ public:
void draw_glyph(const IntPoint&, u32, Color);
void draw_glyph(const IntPoint&, u32, const Font&, Color);
void draw_emoji(const IntPoint&, const Gfx::Bitmap&, const Font&);
void draw_glyph_or_emoji(const IntPoint&, u32 codepoint, const Font&, Color);
void draw_glyph_or_emoji(const IntPoint&, u32 code_points, const Font&, Color);
static void for_each_line_segment_on_bezier_curve(const FloatPoint& control_point, const FloatPoint& p1, const FloatPoint& p2, Function<void(const FloatPoint&, const FloatPoint&)>&);
static void for_each_line_segment_on_bezier_curve(const FloatPoint& control_point, const FloatPoint& p1, const FloatPoint& p2, Function<void(const FloatPoint&, const FloatPoint&)>&&);