LibGfx: Add IPC serialization for FontVariationSettings

The compositor IPC path needs variable-font axes to survive transport
with the font data that owns them. Add LibGfx-local specializations for
FontVariationSettings, compile the new implementation into LibGfx, and
expose the stored settings from Font so later font serializers can read
them without reaching into the class internals.

This is preparatory work required to add IPC between the main and
compositor threads.
This commit is contained in:
Aliaksandr Kalenik 2026-05-20 23:51:31 +02:00 committed by Alexander Kalenik
parent 34a9f36e25
commit e181686f7e
4 changed files with 51 additions and 0 deletions

View file

@ -13,6 +13,7 @@ set(SOURCES
Font/Font.cpp
Font/FontDatabase.cpp
Font/FontSupport.cpp
Font/FontVariationSettings.cpp
Font/PathFontProvider.cpp
Font/Typeface.cpp
Font/TypefaceSkia.cpp

View file

@ -75,6 +75,7 @@ public:
Font const& bold_variant() const;
hb_font_t* harfbuzz_font() const;
FontVariationSettings const& variation_settings() const { return m_font_variation_settings; }
ShapeFeatures const& features() const { return m_shape_features; }
struct ShapingCache {

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Font/FontVariationSettings.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
namespace IPC {
template<>
ErrorOr<void> encode(Encoder& encoder, Gfx::FontVariationSettings const& settings)
{
TRY(encoder.encode_size(settings.axes.size()));
for (auto const& axis : settings.axes) {
TRY(encoder.encode(axis.key.to_u32()));
TRY(encoder.encode(axis.value));
}
return {};
}
template<>
ErrorOr<Gfx::FontVariationSettings> decode(Decoder& decoder)
{
auto axis_count = TRY(decoder.decode_size());
Gfx::FontVariationSettings settings;
TRY(settings.axes.try_ensure_capacity(axis_count));
for (size_t i = 0; i < axis_count; ++i) {
auto tag = Gfx::FourCC::from_u32(TRY(decoder.decode<u32>()));
auto value = TRY(decoder.decode<float>());
TRY(settings.axes.try_set(tag, value));
}
return settings;
}
}

View file

@ -10,6 +10,7 @@
#include <AK/QuickSort.h>
#include <AK/Vector.h>
#include <LibGfx/FourCC.h>
#include <LibIPC/Forward.h>
namespace Gfx {
@ -72,3 +73,13 @@ struct FontVariationSettings {
};
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, Gfx::FontVariationSettings const&);
template<>
ErrorOr<Gfx::FontVariationSettings> decode(Decoder&);
}