2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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 04:00:37 +00:00
|
|
|
|
|
|
|
#include "ScaledFontWin.h"
|
2017-04-14 18:11:00 +00:00
|
|
|
#include "UnscaledFontGDI.h"
|
2015-12-21 20:33:13 +00:00
|
|
|
|
2016-01-05 10:08:58 +00:00
|
|
|
#include "AutoHelpersWin.h"
|
2016-01-05 10:08:56 +00:00
|
|
|
#include "Logging.h"
|
2016-08-17 08:26:11 +00:00
|
|
|
#include "nsString.h"
|
2016-01-05 10:08:56 +00:00
|
|
|
|
2012-01-09 18:54:44 +00:00
|
|
|
#ifdef USE_SKIA
|
2015-07-29 20:31:40 +00:00
|
|
|
# include "skia/include/ports/SkTypeface_win.h"
|
2012-01-09 18:54:44 +00:00
|
|
|
#endif
|
2011-11-18 04:00:37 +00:00
|
|
|
|
2016-01-05 10:08:56 +00:00
|
|
|
#ifdef USE_CAIRO_SCALED_FONT
|
|
|
|
# include "cairo-win32.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-02 22:00:29 +00:00
|
|
|
#include "HelpersWinFonts.h"
|
|
|
|
|
2011-11-18 04:00:37 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2017-04-06 21:41:02 +00:00
|
|
|
ScaledFontWin::ScaledFontWin(const LOGFONT* aFont,
|
|
|
|
const RefPtr<UnscaledFont>& aUnscaledFont,
|
|
|
|
Float aSize)
|
|
|
|
: ScaledFontBase(aUnscaledFont, aSize), mLogFont(*aFont) {}
|
2011-11-18 04:00:37 +00:00
|
|
|
|
2017-04-14 18:11:00 +00:00
|
|
|
bool UnscaledFontGDI::GetFontFileData(FontFileDataOutput aDataCallback,
|
|
|
|
void* aBaton) {
|
2016-01-05 10:08:58 +00:00
|
|
|
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-04-14 18:11:00 +00:00
|
|
|
aDataCallback(fontData.get(), tableSize, 0, aBaton);
|
2017-03-29 22:22:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-01-05 10:08:58 +00:00
|
|
|
|
2017-03-29 22:22:06 +00:00
|
|
|
bool ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb,
|
|
|
|
void* aBaton) {
|
2017-09-18 01:21:15 +00:00
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), nullptr, 0,
|
|
|
|
aBaton);
|
2016-01-05 10:08:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-17 14:59:31 +00:00
|
|
|
bool UnscaledFontGDI::GetFontInstanceData(FontInstanceDataOutput aCb,
|
|
|
|
void* aBaton) {
|
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-14 18:11:00 +00:00
|
|
|
bool UnscaledFontGDI::GetFontDescriptor(FontDescriptorOutput aCb,
|
|
|
|
void* aBaton) {
|
2017-11-07 01:19:46 +00:00
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), 0, aBaton);
|
2016-04-22 12:23:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-07 01:19:46 +00:00
|
|
|
already_AddRefed<UnscaledFont> UnscaledFontGDI::CreateFromFontDescriptor(
|
|
|
|
const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex) {
|
2017-04-14 18:11:00 +00:00
|
|
|
if (aDataLength < sizeof(LOGFONT)) {
|
|
|
|
gfxWarning() << "GDI font descriptor is truncated.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LOGFONT* logFont = reinterpret_cast<const LOGFONT*>(aData);
|
|
|
|
RefPtr<UnscaledFont> unscaledFont = new UnscaledFontGDI(*logFont);
|
|
|
|
return unscaledFont.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ScaledFont> UnscaledFontGDI::CreateScaledFont(
|
|
|
|
Float aGlyphSize, const uint8_t* aInstanceData,
|
2017-09-18 01:21:15 +00:00
|
|
|
uint32_t aInstanceDataLength, const FontVariation* aVariations,
|
|
|
|
uint32_t aNumVariations) {
|
2017-04-14 18:11:00 +00:00
|
|
|
if (aInstanceDataLength < sizeof(LOGFONT)) {
|
|
|
|
gfxWarning() << "GDI unscaled font instance data is truncated.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-04 19:01:12 +00:00
|
|
|
NativeFont nativeFont;
|
2018-06-14 23:42:56 +00:00
|
|
|
nativeFont.mType = NativeFontType::GDI_LOGFONT;
|
2017-04-14 18:11:00 +00:00
|
|
|
nativeFont.mFont = (void*)aInstanceData;
|
2017-01-04 19:01:12 +00:00
|
|
|
|
2018-06-14 23:42:56 +00:00
|
|
|
return Factory::CreateScaledFontForNativeFont(nativeFont, this, aGlyphSize);
|
2017-01-04 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 22:00:29 +00:00
|
|
|
AntialiasMode ScaledFontWin::GetDefaultAAMode() {
|
|
|
|
return GetSystemDefaultAAMode();
|
|
|
|
}
|
|
|
|
|
2012-01-09 18:54:44 +00:00
|
|
|
#ifdef USE_SKIA
|
2018-08-23 18:58:21 +00:00
|
|
|
SkTypeface* ScaledFontWin::CreateSkTypeface() {
|
|
|
|
return SkCreateTypefaceFromLOGFONT(mLogFont);
|
2012-01-09 18:54:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-05 10:08:56 +00: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 18:54:44 +00:00
|
|
|
|
2011-11-18 04:00:37 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|