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"
|
2016-08-17 11:26:11 +03:00
|
|
|
#include "nsString.h"
|
2016-01-05 13:08:56 +03:00
|
|
|
|
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
|
|
|
|
|
2016-09-03 01:00:29 +03:00
|
|
|
#include "HelpersWinFonts.h"
|
|
|
|
|
2011-11-18 08:00:37 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2017-03-30 01:22:06 +03:00
|
|
|
ScaledFontWin::ScaledFontWin(const 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;
|
|
|
|
}
|
|
|
|
|
2017-03-30 01:22:06 +03:00
|
|
|
aDataCallback(fontData.get(), tableSize, 0, mSize, 0, nullptr, aBaton);
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-05 13:08:58 +03:00
|
|
|
|
2017-03-30 01:22:06 +03:00
|
|
|
bool
|
|
|
|
ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
|
|
|
|
{
|
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
|
2016-01-05 13:08:58 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:23:25 +03:00
|
|
|
bool
|
|
|
|
ScaledFontWin::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton)
|
|
|
|
{
|
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), mSize, aBaton);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:01:12 +03:00
|
|
|
already_AddRefed<ScaledFont>
|
|
|
|
ScaledFontWin::CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength, Float aSize)
|
|
|
|
{
|
|
|
|
NativeFont nativeFont;
|
|
|
|
nativeFont.mType = NativeFontType::GDI_FONT_FACE;
|
|
|
|
nativeFont.mFont = (void*)aData;
|
|
|
|
|
|
|
|
RefPtr<ScaledFont> font =
|
|
|
|
Factory::CreateScaledFontForNativeFont(nativeFont, aSize);
|
|
|
|
|
|
|
|
#ifdef USE_CAIRO_SCALED_FONT
|
|
|
|
static_cast<ScaledFontBase*>(font.get())->PopulateCairoScaledFont();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
2016-09-03 01:00:29 +03:00
|
|
|
AntialiasMode
|
|
|
|
ScaledFontWin::GetDefaultAAMode()
|
|
|
|
{
|
|
|
|
return GetSystemDefaultAAMode();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|