WebCoreArgumentCodersWin.cpp [plain text]
#include "config.h"
#include "WebCoreArgumentCoders.h"
#include <WebCore/Font.h>
#include <WebCore/FontAttributes.h>
#include <WebCore/FontCache.h>
#include <WebCore/FontDescription.h>
#include <wtf/win/GDIObject.h>
namespace IPC {
using namespace WebCore;
void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
{
ASSERT_NOT_REACHED();
}
Optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
{
ASSERT_NOT_REACHED();
return WTF::nullopt;
}
void ArgumentCoder<Ref<Font>>::encodePlatformData(Encoder& encoder, const Ref<Font>& font)
{
const auto& platformData = font->platformData();
encoder << platformData.orientation();
encoder << platformData.widthVariant();
encoder << platformData.textRenderingMode();
encoder << platformData.size();
encoder << platformData.syntheticBold();
encoder << platformData.syntheticOblique();
encoder << platformData.familyName();
}
Optional<FontPlatformData> ArgumentCoder<Ref<Font>>::decodePlatformData(Decoder& decoder)
{
Optional<FontOrientation> orientation;
decoder >> orientation;
if (!orientation.hasValue())
return WTF::nullopt;
Optional<FontWidthVariant> widthVariant;
decoder >> widthVariant;
if (!widthVariant.hasValue())
return WTF::nullopt;
Optional<TextRenderingMode> textRenderingMode;
decoder >> textRenderingMode;
if (!textRenderingMode.hasValue())
return WTF::nullopt;
Optional<float> size;
decoder >> size;
if (!size.hasValue())
return WTF::nullopt;
Optional<bool> syntheticBold;
decoder >> syntheticBold;
if (!syntheticBold.hasValue())
return WTF::nullopt;
Optional<bool> syntheticOblique;
decoder >> syntheticOblique;
if (!syntheticOblique.hasValue())
return WTF::nullopt;
Optional<String> familyName;
decoder >> familyName;
if (!familyName.hasValue())
return WTF::nullopt;
FontDescription description;
description.setOrientation(*orientation);
description.setWidthVariant(*widthVariant);
description.setTextRenderingMode(*textRenderingMode);
description.setComputedSize(*size);
RefPtr<Font> font = FontCache::singleton().fontForFamily(description, *familyName);
if (!font)
return WTF::nullopt;
LOGFONT logFont;
GetObject(font->platformData().hfont(), sizeof logFont, &logFont);
auto gdiFont = adoptGDIObject(CreateFontIndirect(&logFont));
if (!gdiFont)
return WTF::nullopt;
return FontPlatformData(WTFMove(gdiFont), *size, *syntheticBold, *syntheticOblique, false);
}
}