diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 51ef580aa2..6b070580f7 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -2,6 +2,7 @@ * Copyright (c) 2020, Srimanta Barua * Copyright (c) 2021-2023, Andreas Kling * Copyright (c) 2022, Jelle Raaijmakers + * Copyright (c) 2023, Lukas Affolter * * SPDX-License-Identifier: BSD-2-Clause */ @@ -988,6 +989,27 @@ RefPtr Font::color_bitmap(u32 glyph_id) const Optional GPOS::glyph_kerning(u16 left_glyph_id, u16 right_glyph_id) const { + auto read_value_record = [&](u16 value_format, FixedMemoryStream& stream) -> ValueRecord { + ValueRecord value_record; + if (value_format & static_cast(ValueFormat::X_PLACEMENT)) + value_record.x_placement = stream.read_value>().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::Y_PLACEMENT)) + value_record.y_placement = stream.read_value>().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::X_ADVANCE)) + value_record.x_advance = stream.read_value>().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::Y_ADVANCE)) + value_record.y_advance = stream.read_value>().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::X_PLACEMENT_DEVICE)) + value_record.x_placement_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::Y_PLACEMENT_DEVICE)) + value_record.y_placement_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::X_ADVANCE_DEVICE)) + value_record.x_advance_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); + if (value_format & static_cast(ValueFormat::Y_ADVANCE_DEVICE)) + value_record.y_advance_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); + return value_record; + }; + auto const& header = this->header(); dbgln_if(OPENTYPE_GPOS_DEBUG, "GPOS header:"); dbgln_if(OPENTYPE_GPOS_DEBUG, " Version: {}.{}", header.major_version, header.minor_version); @@ -1178,29 +1200,8 @@ Optional GPOS::glyph_kerning(u16 left_glyph_id, u16 right_glyph_id) const auto item_slice = pair_pos_format_slice.slice(sizeof(PairPosFormat2) + item_offset); FixedMemoryStream stream(item_slice); - auto read_value_record = [&](u16 value_format) -> ValueRecord { - ValueRecord value_record; - if (value_format & static_cast(ValueFormat::X_PLACEMENT)) - value_record.x_placement = stream.read_value>().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::Y_PLACEMENT)) - value_record.y_placement = stream.read_value>().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::X_ADVANCE)) - value_record.x_advance = stream.read_value>().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::Y_ADVANCE)) - value_record.y_advance = stream.read_value>().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::X_PLACEMENT_DEVICE)) - value_record.x_placement_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::Y_PLACEMENT_DEVICE)) - value_record.y_placement_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::X_ADVANCE_DEVICE)) - value_record.x_advance_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); - if (value_format & static_cast(ValueFormat::Y_ADVANCE_DEVICE)) - value_record.y_advance_device_offset = stream.read_value().release_value_but_fixme_should_propagate_errors(); - return value_record; - }; - - [[maybe_unused]] auto value_record1 = read_value_record(pair_pos_format2.value_format1); - [[maybe_unused]] auto value_record2 = read_value_record(pair_pos_format2.value_format2); + [[maybe_unused]] auto value_record1 = read_value_record(pair_pos_format2.value_format1, stream); + [[maybe_unused]] auto value_record2 = read_value_record(pair_pos_format2.value_format2, stream); dbgln_if(OPENTYPE_GPOS_DEBUG, "Returning x advance {}", value_record1.x_advance); return value_record1.x_advance;