2017-04-07 00:41:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_
|
|
|
|
#define MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_
|
|
|
|
|
|
|
|
#include <cairo-ft.h>
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class UnscaledFontFreeType : public UnscaledFont
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontFreeType, override)
|
2017-04-14 21:11:00 +03:00
|
|
|
explicit UnscaledFontFreeType(FT_Face aFace,
|
|
|
|
bool aOwnsFace = false)
|
2017-04-07 00:41:02 +03:00
|
|
|
: mFace(aFace)
|
2017-04-14 21:11:00 +03:00
|
|
|
, mOwnsFace(aOwnsFace)
|
2017-04-07 00:41:02 +03:00
|
|
|
, mIndex(0)
|
|
|
|
{}
|
|
|
|
explicit UnscaledFontFreeType(const char* aFile,
|
|
|
|
uint32_t aIndex = 0)
|
|
|
|
: mFace(nullptr)
|
2017-04-14 21:11:00 +03:00
|
|
|
, mOwnsFace(false)
|
2017-04-07 00:41:02 +03:00
|
|
|
, mFile(aFile)
|
|
|
|
, mIndex(aIndex)
|
|
|
|
{}
|
2017-04-14 21:11:00 +03:00
|
|
|
~UnscaledFontFreeType()
|
|
|
|
{
|
|
|
|
if (mOwnsFace) {
|
2017-05-18 04:56:24 +03:00
|
|
|
Factory::ReleaseFTFace(mFace);
|
2017-04-14 21:11:00 +03:00
|
|
|
}
|
|
|
|
}
|
2017-04-07 00:41:02 +03:00
|
|
|
|
|
|
|
FontType GetType() const override { return FontType::FREETYPE; }
|
|
|
|
|
|
|
|
FT_Face GetFace() const { return mFace; }
|
|
|
|
const char* GetFile() const { return mFile.c_str(); }
|
|
|
|
uint32_t GetIndex() const { return mIndex; }
|
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
struct FontDescriptor
|
|
|
|
{
|
|
|
|
uint32_t mPathLength;
|
|
|
|
uint32_t mIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override;
|
|
|
|
|
|
|
|
bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
|
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
private:
|
|
|
|
FT_Face mFace;
|
2017-04-14 21:11:00 +03:00
|
|
|
bool mOwnsFace;
|
2017-04-07 00:41:02 +03:00
|
|
|
std::string mFile;
|
|
|
|
uint32_t mIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
class UnscaledFontFontconfig : public UnscaledFontFreeType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontFontconfig, override)
|
2017-04-14 21:11:00 +03:00
|
|
|
explicit UnscaledFontFontconfig(FT_Face aFace,
|
|
|
|
bool aOwnsFace = false)
|
|
|
|
: UnscaledFontFreeType(aFace, aOwnsFace)
|
2017-04-07 00:41:02 +03:00
|
|
|
{}
|
|
|
|
explicit UnscaledFontFontconfig(const char* aFile,
|
|
|
|
uint32_t aIndex = 0)
|
|
|
|
: UnscaledFontFreeType(aFile, aIndex)
|
|
|
|
{}
|
2017-05-04 21:05:01 +03:00
|
|
|
UnscaledFontFontconfig(FT_Face aFace,
|
|
|
|
NativeFontResource* aNativeFontResource)
|
|
|
|
: UnscaledFontFreeType(aFace, false)
|
|
|
|
, mNativeFontResource(aNativeFontResource)
|
|
|
|
{}
|
2017-04-07 00:41:02 +03:00
|
|
|
|
|
|
|
FontType GetType() const override { return FontType::FONTCONFIG; }
|
2017-04-14 21:11:00 +03:00
|
|
|
|
|
|
|
static already_AddRefed<UnscaledFont>
|
|
|
|
CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength);
|
|
|
|
|
|
|
|
already_AddRefed<ScaledFont>
|
|
|
|
CreateScaledFont(Float aGlyphSize,
|
|
|
|
const uint8_t* aInstanceData,
|
|
|
|
uint32_t aInstanceDataLength) override;
|
2017-05-04 21:05:01 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<NativeFontResource> mNativeFontResource;
|
2017-04-07 00:41:02 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_ */
|
|
|
|
|