FontPlatformDataWin.cpp [plain text]
#include "config.h"
#include "FontPlatformData.h"
#include "HWndDC.h"
#include "SharedBuffer.h"
#include <wtf/HashMap.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
#if USE(DIRECT2D)
#include <dwrite_3.h>
#endif
using std::min;
namespace WebCore {
FontPlatformData::FontPlatformData(GDIObject<HFONT> font, float size, bool bold, bool oblique, bool useGDI)
: m_font(SharedGDIObject<HFONT>::create(WTFMove(font)))
, m_size(size)
, m_syntheticBold(bold)
, m_syntheticOblique(oblique)
, m_useGDI(useGDI)
{
HWndDC hdc(0);
SaveDC(hdc);
::SelectObject(hdc, m_font->get());
wchar_t faceName[LF_FACESIZE];
GetTextFace(hdc, LF_FACESIZE, faceName);
platformDataInit(m_font->get(), size, hdc, faceName);
RestoreDC(hdc, -1);
}
RefPtr<SharedBuffer> FontPlatformData::platformOpenTypeTable(uint32_t table) const
{
HWndDC hdc(0);
HGDIOBJ oldFont = SelectObject(hdc, hfont());
DWORD size = GetFontData(hdc, table, 0, 0, 0);
RefPtr<SharedBuffer> buffer;
if (size != GDI_ERROR) {
Vector<char> data(size);
DWORD result = GetFontData(hdc, table, 0, (PVOID)data.data(), size);
ASSERT_UNUSED(result, result == size);
buffer = SharedBuffer::create(WTFMove(data));
}
SelectObject(hdc, oldFont);
return buffer;
}
}