gecko-dev/gfx/2d/ScaledFontWin.cpp
Daniel Holbert 126bd9e1a4 Bug 1412427 part 8: (automated patch) Switch a bunch of C++ files in gfx to use our standard mode lines. r=jrmuizel
This patch was generated automatically by the "modeline.py" script, available
here: https://github.com/amccreight/moz-source-tools/blob/master/modeline.py

For every file that is modified in this patch, the changes are as follows:
 (1) The patch changes the file to use the exact C++ mode lines from the
     Mozilla coding style guide, available here:
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#Mode_Line

 (2) The patch deletes any blank lines between the mode line & the MPL
     boilerplate comment.

 (3) If the file previously had the mode lines and MPL boilerplate in a
     single contiguous C++ comment, then the patch splits them into
     separate C++ comments, to match the boilerplate in the coding style.

MozReview-Commit-ID: 77D61xpSmIl

--HG--
extra : rebase_source : c6162fa3cf539a07177a19838324bf368faa162b
2017-10-27 16:10:06 -07:00

154 lines
3.8 KiB
C++

/* -*- 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
* 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/. */
#include "ScaledFontWin.h"
#include "UnscaledFontGDI.h"
#include "AutoHelpersWin.h"
#include "Logging.h"
#include "nsString.h"
#ifdef USE_SKIA
#include "skia/include/ports/SkTypeface_win.h"
#endif
#ifdef USE_CAIRO_SCALED_FONT
#include "cairo-win32.h"
#endif
#include "HelpersWinFonts.h"
namespace mozilla {
namespace gfx {
ScaledFontWin::ScaledFontWin(const LOGFONT* aFont,
const RefPtr<UnscaledFont>& aUnscaledFont,
Float aSize)
: ScaledFontBase(aUnscaledFont, aSize)
, mLogFont(*aFont)
{
}
bool
UnscaledFontGDI::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;
}
aDataCallback(fontData.get(), tableSize, 0, aBaton);
return true;
}
bool
ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
{
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), nullptr, 0, aBaton);
return true;
}
bool
UnscaledFontGDI::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
{
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
return true;
}
bool
UnscaledFontGDI::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton)
{
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
return true;
}
already_AddRefed<UnscaledFont>
UnscaledFontGDI::CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength)
{
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,
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations)
{
if (aInstanceDataLength < sizeof(LOGFONT)) {
gfxWarning() << "GDI unscaled font instance data is truncated.";
return nullptr;
}
NativeFont nativeFont;
nativeFont.mType = NativeFontType::GDI_FONT_FACE;
nativeFont.mFont = (void*)aInstanceData;
RefPtr<ScaledFont> font =
Factory::CreateScaledFontForNativeFont(nativeFont, this, aGlyphSize);
#ifdef USE_CAIRO_SCALED_FONT
static_cast<ScaledFontBase*>(font.get())->PopulateCairoScaledFont();
#endif
return font.forget();
}
AntialiasMode
ScaledFontWin::GetDefaultAAMode()
{
return GetSystemDefaultAAMode();
}
#ifdef USE_SKIA
SkTypeface* ScaledFontWin::GetSkTypeface()
{
if (!mTypeface) {
mTypeface = SkCreateTypefaceFromLOGFONT(mLogFont);
}
return mTypeface;
}
#endif
#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
}
}