2016-01-05 13:08:58 +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
|
|
|
|
* 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 "NativeFontResourceGDI.h"
|
|
|
|
|
|
|
|
#include "Logging.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "ScaledFontWin.h"
|
2017-04-14 21:11:00 +03:00
|
|
|
#include "UnscaledFontGDI.h"
|
2016-01-05 13:08:58 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<NativeFontResourceGDI> NativeFontResourceGDI::Create(
|
2017-04-14 21:11:00 +03:00
|
|
|
uint8_t* aFontData, uint32_t aDataLength) {
|
2016-01-05 13:08:58 +03:00
|
|
|
DWORD numberOfFontsAdded;
|
|
|
|
HANDLE fontResourceHandle =
|
|
|
|
::AddFontMemResourceEx(aFontData, aDataLength, 0, &numberOfFontsAdded);
|
|
|
|
if (!fontResourceHandle) {
|
|
|
|
gfxWarning() << "Failed to add memory font resource.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<NativeFontResourceGDI> fontResouce =
|
2020-05-21 23:32:10 +03:00
|
|
|
new NativeFontResourceGDI(fontResourceHandle, aDataLength);
|
2016-01-05 13:08:58 +03:00
|
|
|
|
|
|
|
return fontResouce.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeFontResourceGDI::~NativeFontResourceGDI() {
|
|
|
|
::RemoveFontMemResourceEx(mFontResourceHandle);
|
|
|
|
}
|
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
already_AddRefed<UnscaledFont> NativeFontResourceGDI::CreateUnscaledFont(
|
|
|
|
uint32_t aIndex, const uint8_t* aInstanceData,
|
|
|
|
uint32_t aInstanceDataLength) {
|
2017-03-30 01:22:06 +03:00
|
|
|
if (aInstanceDataLength < sizeof(LOGFONT)) {
|
2017-04-14 21:11:00 +03:00
|
|
|
gfxWarning() << "GDI unscaled font instance data is truncated.";
|
2016-01-05 13:08:58 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-30 01:22:06 +03:00
|
|
|
const LOGFONT* logFont = reinterpret_cast<const LOGFONT*>(aInstanceData);
|
2017-04-14 21:11:00 +03:00
|
|
|
RefPtr<UnscaledFont> unscaledFont = new UnscaledFontGDI(*logFont);
|
|
|
|
return unscaledFont.forget();
|
2016-01-05 13:08:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|