1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ScaledFontWin.h"
8 #include "UnscaledFontGDI.h"
10 #include "AutoHelpersWin.h"
14 #include "skia/include/ports/SkTypeface_win.h"
16 #include "cairo-win32.h"
18 #include "HelpersWinFonts.h"
23 ScaledFontWin::ScaledFontWin(const LOGFONT
* aFont
,
24 const RefPtr
<UnscaledFont
>& aUnscaledFont
,
26 : ScaledFontBase(aUnscaledFont
, aSize
), mLogFont(*aFont
) {}
28 bool UnscaledFontGDI::GetFontFileData(FontFileDataOutput aDataCallback
,
31 AutoSelectFont
font(dc
.GetDC(), &mLogFont
);
33 // Check for a font collection first.
34 uint32_t table
= 0x66637474; // 'ttcf'
35 uint32_t tableSize
= ::GetFontData(dc
.GetDC(), table
, 0, nullptr, 0);
36 if (tableSize
== GDI_ERROR
) {
37 // Try as if just a single font.
39 tableSize
= ::GetFontData(dc
.GetDC(), table
, 0, nullptr, 0);
40 if (tableSize
== GDI_ERROR
) {
45 UniquePtr
<uint8_t[]> fontData(new uint8_t[tableSize
]);
48 ::GetFontData(dc
.GetDC(), table
, 0, fontData
.get(), tableSize
);
49 if (sizeGot
!= tableSize
) {
53 aDataCallback(fontData
.get(), tableSize
, 0, aBaton
);
57 bool ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb
,
59 aCb(reinterpret_cast<uint8_t*>(&mLogFont
), sizeof(mLogFont
), nullptr, 0,
64 bool UnscaledFontGDI::GetFontInstanceData(FontInstanceDataOutput aCb
,
66 aCb(reinterpret_cast<uint8_t*>(&mLogFont
), sizeof(mLogFont
), aBaton
);
70 bool UnscaledFontGDI::GetFontDescriptor(FontDescriptorOutput aCb
,
72 // Because all the callers of this function are preparing a recorded
73 // event to be played back in another process, it's not helpful to ever
74 // return a font descriptor, since it isn't meaningful in another
75 // process. Those callers will always need to send full font data, and
76 // returning false here will ensure that that happens.
80 already_AddRefed
<UnscaledFont
> UnscaledFontGDI::CreateFromFontDescriptor(
81 const uint8_t* aData
, uint32_t aDataLength
, uint32_t aIndex
) {
82 if (aDataLength
< sizeof(LOGFONT
)) {
83 gfxWarning() << "GDI font descriptor is truncated.";
87 const LOGFONT
* logFont
= reinterpret_cast<const LOGFONT
*>(aData
);
88 RefPtr
<UnscaledFont
> unscaledFont
= new UnscaledFontGDI(*logFont
);
89 return unscaledFont
.forget();
92 already_AddRefed
<ScaledFont
> UnscaledFontGDI::CreateScaledFont(
93 Float aGlyphSize
, const uint8_t* aInstanceData
,
94 uint32_t aInstanceDataLength
, const FontVariation
* aVariations
,
95 uint32_t aNumVariations
) {
96 if (aInstanceDataLength
< sizeof(LOGFONT
)) {
97 gfxWarning() << "GDI unscaled font instance data is truncated.";
100 return MakeAndAddRef
<ScaledFontWin
>(
101 reinterpret_cast<const LOGFONT
*>(aInstanceData
), this, aGlyphSize
);
104 AntialiasMode
ScaledFontWin::GetDefaultAAMode() {
105 return GetSystemDefaultAAMode();
108 SkTypeface
* ScaledFontWin::CreateSkTypeface() {
109 return SkCreateTypefaceFromLOGFONT(mLogFont
).release();
112 cairo_font_face_t
* ScaledFontWin::CreateCairoFontFace(
113 cairo_font_options_t
* aFontOptions
) {
114 if (mLogFont
.lfFaceName
[0] == 0) {
117 return cairo_win32_font_face_create_for_logfontw(&mLogFont
);
121 } // namespace mozilla