2011-11-18 08:00:37 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 08:00:37 +04:00
|
|
|
|
|
|
|
#include "ScaledFontWin.h"
|
2015-12-21 23:33:13 +03:00
|
|
|
|
2016-01-05 13:08:58 +03:00
|
|
|
#include "AutoHelpersWin.h"
|
2016-01-05 13:08:56 +03:00
|
|
|
#include "Logging.h"
|
|
|
|
#include "SFNTData.h"
|
|
|
|
|
2012-01-09 22:54:44 +04:00
|
|
|
#ifdef USE_SKIA
|
2015-07-29 23:31:40 +03:00
|
|
|
#include "skia/include/ports/SkTypeface_win.h"
|
2012-01-09 22:54:44 +04:00
|
|
|
#endif
|
2011-11-18 08:00:37 +04:00
|
|
|
|
2016-01-05 13:08:56 +03:00
|
|
|
#ifdef USE_CAIRO_SCALED_FONT
|
|
|
|
#include "cairo-win32.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-18 08:00:37 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2012-03-05 04:12:15 +04:00
|
|
|
ScaledFontWin::ScaledFontWin(LOGFONT* aFont, Float aSize)
|
2012-01-09 22:54:44 +04:00
|
|
|
: ScaledFontBase(aSize)
|
2012-03-05 04:12:15 +04:00
|
|
|
, mLogFont(*aFont)
|
2011-11-18 08:00:37 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-05 13:08:58 +03:00
|
|
|
bool
|
|
|
|
ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
|
|
|
|
{
|
|
|
|
AutoDC dc;
|
|
|
|
AutoSelectFont font(dc.GetDC(), &mLogFont);
|
|
|
|
|
|
|
|
// Check for a font collection first.
|
|
|
|
uint32_t table = 0x66637474; // 'ttcf'
|
|
|
|
uint32_t tableSize = ::GetFontData(dc.GetDC(), table, 0, nullptr, 0);
|
|
|
|
if (tableSize == GDI_ERROR) {
|
|
|
|
// Try as if just a single font.
|
|
|
|
table = 0;
|
|
|
|
tableSize = ::GetFontData(dc.GetDC(), table, 0, nullptr, 0);
|
|
|
|
if (tableSize == GDI_ERROR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<uint8_t[]> fontData(new uint8_t[tableSize]);
|
|
|
|
|
|
|
|
uint32_t sizeGot =
|
|
|
|
::GetFontData(dc.GetDC(), table, 0, fontData.get(), tableSize);
|
|
|
|
if (sizeGot != tableSize) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's a font collection then attempt to get the index.
|
|
|
|
uint32_t index = 0;
|
|
|
|
if (table != 0) {
|
|
|
|
UniquePtr<SFNTData> sfntData = SFNTData::Create(fontData.get(),
|
|
|
|
tableSize);
|
|
|
|
if (!sfntData) {
|
2016-04-22 15:23:25 +03:00
|
|
|
gfxWarning() << "Failed to create SFNTData for GetFontFileData.";
|
2016-01-05 13:08:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cast here because for VS2015 char16_t != wchar_t, even though they are
|
|
|
|
// both 16 bit.
|
|
|
|
if (!sfntData->GetIndexForU16Name(
|
|
|
|
reinterpret_cast<char16_t*>(mLogFont.lfFaceName), &index)) {
|
2016-04-22 15:23:25 +03:00
|
|
|
gfxWarning() << "Failed to get index for face name.";
|
2016-01-05 13:08:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aDataCallback(fontData.get(), tableSize, index, mSize, aBaton);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-09 22:54:44 +04:00
|
|
|
#ifdef USE_SKIA
|
|
|
|
SkTypeface* ScaledFontWin::GetSkTypeface()
|
|
|
|
{
|
|
|
|
if (!mTypeface) {
|
2012-04-13 06:10:22 +04:00
|
|
|
mTypeface = SkCreateTypefaceFromLOGFONT(mLogFont);
|
2012-01-09 22:54:44 +04:00
|
|
|
}
|
|
|
|
return mTypeface;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-05 13:08:56 +03:00
|
|
|
#ifdef USE_CAIRO_SCALED_FONT
|
|
|
|
cairo_font_face_t*
|
|
|
|
ScaledFontWin::GetCairoFontFace()
|
|
|
|
{
|
|
|
|
if (mLogFont.lfFaceName[0] == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return cairo_win32_font_face_create_for_logfontw(&mLogFont);
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-09 22:54:44 +04:00
|
|
|
|
2011-11-18 08:00:37 +04:00
|
|
|
}
|
|
|
|
}
|