2017-10-28 02:10:06 +03: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 15:12:37 +04: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 08:00:37 +04:00
|
|
|
|
|
|
|
#include "ScaledFontWin.h"
|
2017-04-14 21:11:00 +03:00
|
|
|
#include "UnscaledFontGDI.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-04-07 00:41:02 +03:00
|
|
|
ScaledFontWin::ScaledFontWin(const LOGFONT* aFont,
|
|
|
|
const RefPtr<UnscaledFont>& aUnscaledFont,
|
|
|
|
Float aSize)
|
|
|
|
: ScaledFontBase(aUnscaledFont, aSize), mLogFont(*aFont) {}
|
2011-11-18 08:00:37 +04:00
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
bool UnscaledFontGDI::GetFontFileData(FontFileDataOutput aDataCallback,
|
|
|
|
void* aBaton) {
|
2016-01-05 13:08:58 +03: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 21:11:00 +03:00
|
|
|
aDataCallback(fontData.get(), tableSize, 0, aBaton);
|
2017-03-30 01:22:06 +03:00
|
|
|
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) {
|
2017-09-18 04:21:15 +03:00
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), nullptr, 0,
|
|
|
|
aBaton);
|
2016-01-05 13:08:58 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-17 17:59:31 +03:00
|
|
|
bool UnscaledFontGDI::GetFontInstanceData(FontInstanceDataOutput aCb,
|
|
|
|
void* aBaton) {
|
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
bool UnscaledFontGDI::GetFontDescriptor(FontDescriptorOutput aCb,
|
|
|
|
void* aBaton) {
|
2017-11-07 04:19:46 +03:00
|
|
|
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), 0, aBaton);
|
2016-04-22 15:23:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:19:46 +03:00
|
|
|
already_AddRefed<UnscaledFont> UnscaledFontGDI::CreateFromFontDescriptor(
|
|
|
|
const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex) {
|
2017-04-14 21:11:00 +03: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 04:21:15 +03:00
|
|
|
uint32_t aInstanceDataLength, const FontVariation* aVariations,
|
|
|
|
uint32_t aNumVariations) {
|
2017-04-14 21:11:00 +03:00
|
|
|
if (aInstanceDataLength < sizeof(LOGFONT)) {
|
|
|
|
gfxWarning() << "GDI unscaled font instance data is truncated.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-10-02 00:56:30 +03:00
|
|
|
return MakeAndAddRef<ScaledFontWin>(
|
|
|
|
reinterpret_cast<const LOGFONT*>(aInstanceData), this, aGlyphSize);
|
2017-01-04 22:01:12 +03:00
|
|
|
}
|
|
|
|
|
2016-09-03 01:00:29 +03:00
|
|
|
AntialiasMode ScaledFontWin::GetDefaultAAMode() {
|
|
|
|
return GetSystemDefaultAAMode();
|
|
|
|
}
|
|
|
|
|
2012-01-09 22:54:44 +04:00
|
|
|
#ifdef USE_SKIA
|
2018-08-23 21:58:21 +03:00
|
|
|
SkTypeface* ScaledFontWin::CreateSkTypeface() {
|
|
|
|
return SkCreateTypefaceFromLOGFONT(mLogFont);
|
2012-01-09 22:54:44 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-05 13:08:56 +03:00
|
|
|
#ifdef USE_CAIRO_SCALED_FONT
|
2019-10-02 00:56:30 +03:00
|
|
|
cairo_font_face_t* ScaledFontWin::CreateCairoFontFace(
|
|
|
|
cairo_font_options_t* aFontOptions) {
|
2016-01-05 13:08:56 +03:00
|
|
|
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
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|