Title: [254295] trunk/Source/WebCore
- Revision
- 254295
- Author
- wenson_hs...@apple.com
- Date
- 2020-01-09 13:56:02 -0800 (Thu, 09 Jan 2020)
Log Message
Implement encoders and decoders for more font-related entities
https://bugs.webkit.org/show_bug.cgi?id=205952
Reviewed by Dean Jackson.
Implement encode/decode template methods for more font-rendering-related objects in WebCore.
* platform/graphics/FontDescription.h:
(WebCore::FontDescription::encode const):
(WebCore::FontDescription::decode):
* platform/graphics/FontSelectionAlgorithm.h:
(WebCore::FontSelectionValue::encode const):
(WebCore::FontSelectionValue::decode):
(WebCore::FontSelectionRange::encode const):
(WebCore::FontSelectionRange::decode):
(WebCore::FontSelectionSpecifiedCapabilities::encode const):
(WebCore::FontSelectionSpecifiedCapabilities::decode):
* platform/graphics/FontTaggedSettings.h:
(WebCore::FontTaggedSetting<T>::encode const):
(WebCore::FontTaggedSetting<T>::decode):
We cast from `uint8_t` to `char` and back when encoding and decoding because IPC encoders are currently only
able to encode `uint8_t`s, rather than `char`s. We could alternately address this in a future patch by adding
encode/decode functions for `char` to `Encoder.h`.
(WebCore::FontTaggedSettings<T>::encode const):
(WebCore::FontTaggedSettings<T>::decode):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (254294 => 254295)
--- trunk/Source/WebCore/ChangeLog 2020-01-09 21:39:42 UTC (rev 254294)
+++ trunk/Source/WebCore/ChangeLog 2020-01-09 21:56:02 UTC (rev 254295)
@@ -1,3 +1,33 @@
+2020-01-09 Wenson Hsieh <wenson_hs...@apple.com>
+
+ Implement encoders and decoders for more font-related entities
+ https://bugs.webkit.org/show_bug.cgi?id=205952
+
+ Reviewed by Dean Jackson.
+
+ Implement encode/decode template methods for more font-rendering-related objects in WebCore.
+
+ * platform/graphics/FontDescription.h:
+ (WebCore::FontDescription::encode const):
+ (WebCore::FontDescription::decode):
+ * platform/graphics/FontSelectionAlgorithm.h:
+ (WebCore::FontSelectionValue::encode const):
+ (WebCore::FontSelectionValue::decode):
+ (WebCore::FontSelectionRange::encode const):
+ (WebCore::FontSelectionRange::decode):
+ (WebCore::FontSelectionSpecifiedCapabilities::encode const):
+ (WebCore::FontSelectionSpecifiedCapabilities::decode):
+ * platform/graphics/FontTaggedSettings.h:
+ (WebCore::FontTaggedSetting<T>::encode const):
+ (WebCore::FontTaggedSetting<T>::decode):
+
+ We cast from `uint8_t` to `char` and back when encoding and decoding because IPC encoders are currently only
+ able to encode `uint8_t`s, rather than `char`s. We could alternately address this in a future patch by adding
+ encode/decode functions for `char` to `Encoder.h`.
+
+ (WebCore::FontTaggedSettings<T>::encode const):
+ (WebCore::FontTaggedSettings<T>::decode):
+
2020-01-09 John Wilander <wilan...@apple.com>
Resource Load Statistics: Flip experimental website data removal setting from an enable to a disable
Modified: trunk/Source/WebCore/platform/graphics/FontDescription.h (254294 => 254295)
--- trunk/Source/WebCore/platform/graphics/FontDescription.h 2020-01-09 21:39:42 UTC (rev 254294)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.h 2020-01-09 21:56:02 UTC (rev 254295)
@@ -106,7 +106,7 @@
void setOrientation(FontOrientation orientation) { m_orientation = static_cast<unsigned>(orientation); }
void setNonCJKGlyphOrientation(NonCJKGlyphOrientation orientation) { m_nonCJKGlyphOrientation = static_cast<unsigned>(orientation); }
void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = static_cast<unsigned>(widthVariant); } // Make sure new callers of this sync with FontPlatformData::isForTextCombine()!
- void setLocale(const AtomString&);
+ WEBCORE_EXPORT void setLocale(const AtomString&);
void setFeatureSettings(FontFeatureSettings&& settings) { m_featureSettings = WTFMove(settings); }
#if ENABLE(VARIATION_FONTS)
void setVariationSettings(FontVariationSettings&& settings) { m_variationSettings = WTFMove(settings); }
@@ -133,6 +133,12 @@
static AtomString platformResolveGenericFamily(UScriptCode, const AtomString& locale, const AtomString& familyName);
+ template<class Encoder>
+ void encode(Encoder&) const;
+
+ template<class Decoder>
+ static Optional<FontDescription> decode(Decoder&);
+
private:
// FIXME: Investigate moving these into their own object on the heap (to save memory).
FontFeatureSettings m_featureSettings;
@@ -203,4 +209,240 @@
&& m_shouldAllowUserInstalledFonts == other.m_shouldAllowUserInstalledFonts;
}
+template<class Encoder>
+void FontDescription::encode(Encoder& encoder) const
+{
+ encoder << featureSettings();
+#if ENABLE(VARIATION_FONTS)
+ encoder << variationSettings();
+#endif
+ encoder << locale();
+ encoder << italic();
+ encoder << stretch();
+ encoder << weight();
+ encoder << m_computedSize;
+ encoder << orientation();
+ encoder << nonCJKGlyphOrientation();
+ encoder << widthVariant();
+ encoder << renderingMode();
+ encoder << textRenderingMode();
+ encoder << fontSynthesis();
+ encoder << variantCommonLigatures();
+ encoder << variantDiscretionaryLigatures();
+ encoder << variantHistoricalLigatures();
+ encoder << variantContextualAlternates();
+ encoder << variantPosition();
+ encoder << variantCaps();
+ encoder << variantNumericFigure();
+ encoder << variantNumericSpacing();
+ encoder << variantNumericFraction();
+ encoder << variantNumericOrdinal();
+ encoder << variantNumericSlashedZero();
+ encoder << variantAlternates();
+ encoder << variantEastAsianVariant();
+ encoder << variantEastAsianWidth();
+ encoder << variantEastAsianRuby();
+ encoder << opticalSizing();
+ encoder << fontStyleAxis();
+ encoder << shouldAllowUserInstalledFonts();
}
+
+template<class Decoder>
+Optional<FontDescription> FontDescription::decode(Decoder& decoder)
+{
+ FontDescription fontDescription;
+ Optional<FontFeatureSettings> featureSettings;
+ decoder >> featureSettings;
+ if (!featureSettings)
+ return WTF::nullopt;
+
+#if ENABLE(VARIATION_FONTS)
+ Optional<FontVariationSettings> variationSettings;
+ decoder >> variationSettings;
+ if (!variationSettings)
+ return WTF::nullopt;
+#endif
+
+ Optional<AtomString> locale;
+ decoder >> locale;
+ if (!locale)
+ return WTF::nullopt;
+
+ Optional<Optional<FontSelectionValue>> italic;
+ decoder >> italic;
+ if (!italic)
+ return WTF::nullopt;
+
+ Optional<FontSelectionValue> stretch;
+ decoder >> stretch;
+ if (!stretch)
+ return WTF::nullopt;
+
+ Optional<FontSelectionValue> weight;
+ decoder >> weight;
+ if (!weight)
+ return WTF::nullopt;
+
+ Optional<float> computedSize;
+ decoder >> computedSize;
+ if (!computedSize)
+ return WTF::nullopt;
+
+ Optional<FontOrientation> orientation;
+ decoder >> orientation;
+ if (!orientation)
+ return WTF::nullopt;
+
+ Optional<NonCJKGlyphOrientation> nonCJKGlyphOrientation;
+ decoder >> nonCJKGlyphOrientation;
+ if (!nonCJKGlyphOrientation)
+ return WTF::nullopt;
+
+ Optional<FontWidthVariant> widthVariant;
+ decoder >> widthVariant;
+ if (!widthVariant)
+ return WTF::nullopt;
+
+ Optional<FontRenderingMode> renderingMode;
+ decoder >> renderingMode;
+ if (!renderingMode)
+ return WTF::nullopt;
+
+ Optional<TextRenderingMode> textRenderingMode;
+ decoder >> textRenderingMode;
+ if (!textRenderingMode)
+ return WTF::nullopt;
+
+ Optional<FontSynthesis> fontSynthesis;
+ decoder >> fontSynthesis;
+ if (!fontSynthesis)
+ return WTF::nullopt;
+
+ Optional<FontVariantLigatures> variantCommonLigatures;
+ decoder >> variantCommonLigatures;
+ if (!variantCommonLigatures)
+ return WTF::nullopt;
+
+ Optional<FontVariantLigatures> variantDiscretionaryLigatures;
+ decoder >> variantDiscretionaryLigatures;
+ if (!variantDiscretionaryLigatures)
+ return WTF::nullopt;
+
+ Optional<FontVariantLigatures> variantHistoricalLigatures;
+ decoder >> variantHistoricalLigatures;
+ if (!variantHistoricalLigatures)
+ return WTF::nullopt;
+
+ Optional<FontVariantLigatures> variantContextualAlternates;
+ decoder >> variantContextualAlternates;
+ if (!variantContextualAlternates)
+ return WTF::nullopt;
+
+ Optional<FontVariantPosition> variantPosition;
+ decoder >> variantPosition;
+ if (!variantPosition)
+ return WTF::nullopt;
+
+ Optional<FontVariantCaps> variantCaps;
+ decoder >> variantCaps;
+ if (!variantCaps)
+ return WTF::nullopt;
+
+ Optional<FontVariantNumericFigure> variantNumericFigure;
+ decoder >> variantNumericFigure;
+ if (!variantNumericFigure)
+ return WTF::nullopt;
+
+ Optional<FontVariantNumericSpacing> variantNumericSpacing;
+ decoder >> variantNumericSpacing;
+ if (!variantNumericSpacing)
+ return WTF::nullopt;
+
+ Optional<FontVariantNumericFraction> variantNumericFraction;
+ decoder >> variantNumericFraction;
+ if (!variantNumericFraction)
+ return WTF::nullopt;
+
+ Optional<FontVariantNumericOrdinal> variantNumericOrdinal;
+ decoder >> variantNumericOrdinal;
+ if (!variantNumericOrdinal)
+ return WTF::nullopt;
+
+ Optional<FontVariantNumericSlashedZero> variantNumericSlashedZero;
+ decoder >> variantNumericSlashedZero;
+ if (!variantNumericSlashedZero)
+ return WTF::nullopt;
+
+ Optional<FontVariantAlternates> variantAlternates;
+ decoder >> variantAlternates;
+ if (!variantAlternates)
+ return WTF::nullopt;
+
+ Optional<FontVariantEastAsianVariant> variantEastAsianVariant;
+ decoder >> variantEastAsianVariant;
+ if (!variantEastAsianVariant)
+ return WTF::nullopt;
+
+ Optional<FontVariantEastAsianWidth> variantEastAsianWidth;
+ decoder >> variantEastAsianWidth;
+ if (!variantEastAsianWidth)
+ return WTF::nullopt;
+
+ Optional<FontVariantEastAsianRuby> variantEastAsianRuby;
+ decoder >> variantEastAsianRuby;
+ if (!variantEastAsianRuby)
+ return WTF::nullopt;
+
+ Optional<FontOpticalSizing> opticalSizing;
+ decoder >> opticalSizing;
+ if (!opticalSizing)
+ return WTF::nullopt;
+
+ Optional<FontStyleAxis> fontStyleAxis;
+ decoder >> fontStyleAxis;
+ if (!fontStyleAxis)
+ return WTF::nullopt;
+
+ Optional<AllowUserInstalledFonts> shouldAllowUserInstalledFonts;
+ decoder >> shouldAllowUserInstalledFonts;
+ if (!shouldAllowUserInstalledFonts)
+ return WTF::nullopt;
+
+ fontDescription.setFeatureSettings(WTFMove(*featureSettings));
+#if ENABLE(VARIATION_FONTS)
+ fontDescription.setVariationSettings(WTFMove(*variationSettings));
+#endif
+ fontDescription.setLocale(*locale);
+ fontDescription.setItalic(*italic);
+ fontDescription.setStretch(*stretch);
+ fontDescription.setWeight(*weight);
+ fontDescription.setComputedSize(*computedSize);
+ fontDescription.setOrientation(*orientation);
+ fontDescription.setNonCJKGlyphOrientation(*nonCJKGlyphOrientation);
+ fontDescription.setWidthVariant(*widthVariant);
+ fontDescription.setRenderingMode(*renderingMode);
+ fontDescription.setTextRenderingMode(*textRenderingMode);
+ fontDescription.setFontSynthesis(*fontSynthesis);
+ fontDescription.setVariantCommonLigatures(*variantCommonLigatures);
+ fontDescription.setVariantDiscretionaryLigatures(*variantDiscretionaryLigatures);
+ fontDescription.setVariantHistoricalLigatures(*variantHistoricalLigatures);
+ fontDescription.setVariantContextualAlternates(*variantContextualAlternates);
+ fontDescription.setVariantPosition(*variantPosition);
+ fontDescription.setVariantCaps(*variantCaps);
+ fontDescription.setVariantNumericFigure(*variantNumericFigure);
+ fontDescription.setVariantNumericSpacing(*variantNumericSpacing);
+ fontDescription.setVariantNumericFraction(*variantNumericFraction);
+ fontDescription.setVariantNumericOrdinal(*variantNumericOrdinal);
+ fontDescription.setVariantNumericSlashedZero(*variantNumericSlashedZero);
+ fontDescription.setVariantAlternates(*variantAlternates);
+ fontDescription.setVariantEastAsianVariant(*variantEastAsianVariant);
+ fontDescription.setVariantEastAsianWidth(*variantEastAsianWidth);
+ fontDescription.setVariantEastAsianRuby(*variantEastAsianRuby);
+ fontDescription.setOpticalSizing(*opticalSizing);
+ fontDescription.setFontStyleAxis(*fontStyleAxis);
+ fontDescription.setShouldAllowUserInstalledFonts(*shouldAllowUserInstalledFonts);
+
+ return fontDescription;
+}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h (254294 => 254295)
--- trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h 2020-01-09 21:39:42 UTC (rev 254294)
+++ trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h 2020-01-09 21:56:02 UTC (rev 254295)
@@ -66,6 +66,12 @@
constexpr BackingType rawValue() const { return m_backing; }
+ template<class Encoder>
+ void encode(Encoder&) const;
+
+ template<class Decoder>
+ static Optional<FontSelectionValue> decode(Decoder&);
+
private:
enum class RawTag { RawTag };
constexpr FontSelectionValue(int, RawTag);
@@ -74,6 +80,25 @@
BackingType m_backing { 0 };
};
+template<class Encoder>
+void FontSelectionValue::encode(Encoder& encoder) const
+{
+ encoder << m_backing;
+}
+
+template<class Decoder>
+Optional<FontSelectionValue> FontSelectionValue::decode(Decoder& decoder)
+{
+ Optional<FontSelectionValue::BackingType> backing;
+ decoder >> backing;
+ if (!backing)
+ return WTF::nullopt;
+
+ FontSelectionValue result;
+ result.m_backing = *backing;
+ return result;
+}
+
constexpr FontSelectionValue::FontSelectionValue(int x)
: m_backing(x * fractionalEntropy)
{
@@ -317,10 +342,39 @@
return minimum.rawValue() << 16 | maximum.rawValue();
}
+ template<class Encoder>
+ void encode(Encoder&) const;
+
+ template<class Decoder>
+ static Optional<FontSelectionRange> decode(Decoder&);
+
Value minimum { 1 };
Value maximum { 0 };
};
+template<class Encoder>
+void FontSelectionRange::encode(Encoder& encoder) const
+{
+ encoder << minimum;
+ encoder << maximum;
+}
+
+template<class Decoder>
+Optional<FontSelectionRange> FontSelectionRange::decode(Decoder& decoder)
+{
+ Optional<FontSelectionRange::Value> minimum;
+ decoder >> minimum;
+ if (!minimum)
+ return WTF::nullopt;
+
+ Optional<FontSelectionRange::Value> maximum;
+ decoder >> maximum;
+ if (!maximum)
+ return WTF::nullopt;
+
+ return {{ *minimum, *maximum }};
+}
+
inline void add(Hasher& hasher, const FontSelectionRange& range)
{
add(hasher, range.uniqueValue());
@@ -445,11 +499,46 @@
return slope.valueOr(Range { normalItalicValue() });
}
+ template<class Encoder>
+ void encode(Encoder&) const;
+
+ template<class Decoder>
+ static Optional<FontSelectionSpecifiedCapabilities> decode(Decoder&);
+
OptionalRange weight;
OptionalRange width;
OptionalRange slope;
};
+template<class Encoder>
+void FontSelectionSpecifiedCapabilities::encode(Encoder& encoder) const
+{
+ encoder << weight;
+ encoder << width;
+ encoder << slope;
+}
+
+template<class Decoder>
+Optional<FontSelectionSpecifiedCapabilities> FontSelectionSpecifiedCapabilities::decode(Decoder& decoder)
+{
+ Optional<OptionalRange> weight;
+ decoder >> weight;
+ if (!weight)
+ return WTF::nullopt;
+
+ Optional<OptionalRange> width;
+ decoder >> width;
+ if (!width)
+ return WTF::nullopt;
+
+ Optional<OptionalRange> slope;
+ decoder >> slope;
+ if (!slope)
+ return WTF::nullopt;
+
+ return {{ *weight, *width, *slope }};
+}
+
constexpr bool operator==(const FontSelectionSpecifiedCapabilities& a, const FontSelectionSpecifiedCapabilities& b)
{
return a.tied() == b.tied();
Modified: trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h (254294 => 254295)
--- trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h 2020-01-09 21:39:42 UTC (rev 254294)
+++ trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h 2020-01-09 21:56:02 UTC (rev 254295)
@@ -70,6 +70,9 @@
T value() const { return m_value; }
bool enabled() const { return value(); }
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<FontTaggedSetting<T>> decode(Decoder&);
+
private:
FontTag m_tag;
T m_value;
@@ -102,6 +105,54 @@
}
template <typename T>
+template <class Encoder>
+void FontTaggedSetting<T>::encode(Encoder& encoder) const
+{
+ encoder << static_cast<uint8_t>(m_tag[0]);
+ encoder << static_cast<uint8_t>(m_tag[1]);
+ encoder << static_cast<uint8_t>(m_tag[2]);
+ encoder << static_cast<uint8_t>(m_tag[3]);
+ encoder << m_value;
+}
+
+template <typename T>
+template <class Decoder>
+Optional<FontTaggedSetting<T>> FontTaggedSetting<T>::decode(Decoder& decoder)
+{
+ Optional<uint8_t> char0;
+ decoder >> char0;
+ if (!char0)
+ return WTF::nullopt;
+
+ Optional<uint8_t> char1;
+ decoder >> char1;
+ if (!char1)
+ return WTF::nullopt;
+
+ Optional<uint8_t> char2;
+ decoder >> char2;
+ if (!char2)
+ return WTF::nullopt;
+
+ Optional<uint8_t> char3;
+ decoder >> char3;
+ if (!char3)
+ return WTF::nullopt;
+
+ Optional<T> value;
+ decoder >> value;
+ if (!value)
+ return WTF::nullopt;
+
+ return FontTaggedSetting<T>({{
+ static_cast<char>(*char0),
+ static_cast<char>(*char1),
+ static_cast<char>(*char2),
+ static_cast<char>(*char3)
+ }}, *value);
+}
+
+template <typename T>
class FontTaggedSettings {
public:
void insert(FontTaggedSetting<T>&&);
@@ -118,6 +169,9 @@
unsigned hash() const;
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<FontTaggedSettings<T>> decode(Decoder&);
+
private:
Vector<FontTaggedSetting<T>> m_list;
};
@@ -136,6 +190,27 @@
m_list.insert(i, WTFMove(feature));
}
+template <typename T>
+template <class Encoder>
+void FontTaggedSettings<T>::encode(Encoder& encoder) const
+{
+ encoder << m_list;
+}
+
+template <typename T>
+template <class Decoder>
+Optional<FontTaggedSettings<T>> FontTaggedSettings<T>::decode(Decoder& decoder)
+{
+ Optional<Vector<FontTaggedSetting<T>>> list;
+ decoder >> list;
+ if (!list)
+ return WTF::nullopt;
+
+ FontTaggedSettings result;
+ result.m_list = WTFMove(*list);
+ return result;
+}
+
typedef FontTaggedSetting<int> FontFeature;
typedef FontTaggedSettings<int> FontFeatureSettings;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes