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 "NativeFontResourceGDI.h"
10 #include "mozilla/RefPtr.h"
11 #include "ScaledFontWin.h"
12 #include "UnscaledFontGDI.h"
18 already_AddRefed
<NativeFontResourceGDI
> NativeFontResourceGDI::Create(
19 uint8_t* aFontData
, uint32_t aDataLength
) {
20 DWORD numberOfFontsAdded
;
21 HANDLE fontResourceHandle
=
22 ::AddFontMemResourceEx(aFontData
, aDataLength
, 0, &numberOfFontsAdded
);
23 if (!fontResourceHandle
) {
24 gfxWarning() << "Failed to add memory font resource.";
28 RefPtr
<NativeFontResourceGDI
> fontResouce
=
29 new NativeFontResourceGDI(fontResourceHandle
, aDataLength
);
31 return fontResouce
.forget();
34 NativeFontResourceGDI::~NativeFontResourceGDI() {
35 ::RemoveFontMemResourceEx(mFontResourceHandle
);
38 already_AddRefed
<UnscaledFont
> NativeFontResourceGDI::CreateUnscaledFont(
39 uint32_t aIndex
, const uint8_t* aInstanceData
,
40 uint32_t aInstanceDataLength
) {
41 if (aInstanceDataLength
< sizeof(LOGFONT
)) {
42 gfxWarning() << "GDI unscaled font instance data is truncated.";
46 const LOGFONT
* logFont
= reinterpret_cast<const LOGFONT
*>(aInstanceData
);
47 RefPtr
<UnscaledFont
> unscaledFont
= new UnscaledFontGDI(*logFont
);
48 return unscaledFont
.forget();
52 } // namespace mozilla