mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
Everywhere: codepoint => code point
This commit is contained in:
parent
a8ae8b24de
commit
12a42edd13
18 changed files with 240 additions and 240 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue