2009-10-31 02:13:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2009-10-31 02:13:41 +03:00
|
|
|
|
|
|
|
#include "gfxFT2FontBase.h"
|
|
|
|
#include "gfxFT2Utils.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2017-05-10 18:26:43 +03:00
|
|
|
|
2009-11-27 03:21:31 +03:00
|
|
|
#ifdef HAVE_FONTCONFIG_FCFREETYPE_H
|
2009-11-06 10:12:36 +03:00
|
|
|
#include <fontconfig/fcfreetype.h>
|
|
|
|
#endif
|
|
|
|
|
2018-04-26 19:08:18 +03:00
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_MULTIPLE_MASTERS_H
|
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
#include "prlink.h"
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
|
|
|
gfxFT2LockedFace::GetGlyph(uint32_t aCharCode)
|
2009-10-31 02:13:41 +03:00
|
|
|
{
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!mFace))
|
2009-10-31 02:13:41 +03:00
|
|
|
return 0;
|
|
|
|
|
2009-11-27 03:21:31 +03:00
|
|
|
#ifdef HAVE_FONTCONFIG_FCFREETYPE_H
|
2009-11-06 10:12:36 +03:00
|
|
|
// FcFreeTypeCharIndex will search starting from the most recently
|
|
|
|
// selected charmap. This can cause non-determistic behavior when more
|
|
|
|
// than one charmap supports a character but with different glyphs, as
|
|
|
|
// with older versions of MS Gothic, for example. Always prefer a Unicode
|
|
|
|
// charmap, if there is one. (FcFreeTypeCharIndex usually does the
|
|
|
|
// appropriate Unicode conversion, but some fonts have non-Roman glyphs
|
|
|
|
// for FT_ENCODING_APPLE_ROMAN characters.)
|
|
|
|
if (!mFace->charmap || mFace->charmap->encoding != FT_ENCODING_UNICODE) {
|
|
|
|
FT_Select_Charmap(mFace, FT_ENCODING_UNICODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FcFreeTypeCharIndex(mFace, aCharCode);
|
|
|
|
#else
|
2009-10-31 02:13:41 +03:00
|
|
|
return FT_Get_Char_Index(mFace, aCharCode);
|
2009-11-06 10:12:36 +03:00
|
|
|
#endif
|
2009-10-31 02:13:41 +03:00
|
|
|
}
|
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
typedef FT_UInt (*GetCharVariantFunction)(FT_Face face,
|
|
|
|
FT_ULong charcode,
|
|
|
|
FT_ULong variantSelector);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
|
|
|
gfxFT2LockedFace::GetUVSGlyph(uint32_t aCharCode, uint32_t aVariantSelector)
|
2010-12-09 10:28:51 +03:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aVariantSelector, "aVariantSelector should not be NULL");
|
2010-12-09 10:28:51 +03:00
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!mFace))
|
2010-12-09 10:28:51 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// This function is available from FreeType 2.3.6 (June 2008).
|
2010-12-13 22:44:55 +03:00
|
|
|
static CharVariantFunction sGetCharVariantPtr = FindCharVariantFunction();
|
2010-12-09 10:28:51 +03:00
|
|
|
if (!sGetCharVariantPtr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifdef HAVE_FONTCONFIG_FCFREETYPE_H
|
|
|
|
// FcFreeTypeCharIndex may have changed the selected charmap.
|
|
|
|
// FT_Face_GetCharVariantIndex needs a unicode charmap.
|
|
|
|
if (!mFace->charmap || mFace->charmap->encoding != FT_ENCODING_UNICODE) {
|
|
|
|
FT_Select_Charmap(mFace, FT_ENCODING_UNICODE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (*sGetCharVariantPtr)(mFace, aCharCode, aVariantSelector);
|
|
|
|
}
|
|
|
|
|
2010-12-13 22:44:55 +03:00
|
|
|
gfxFT2LockedFace::CharVariantFunction
|
|
|
|
gfxFT2LockedFace::FindCharVariantFunction()
|
|
|
|
{
|
|
|
|
// This function is available from FreeType 2.3.6 (June 2008).
|
2012-07-30 18:20:58 +04:00
|
|
|
PRLibrary *lib = nullptr;
|
2010-12-13 22:44:55 +03:00
|
|
|
CharVariantFunction function =
|
|
|
|
reinterpret_cast<CharVariantFunction>
|
|
|
|
(PR_FindFunctionSymbolAndLibrary("FT_Face_GetCharVariantIndex", &lib));
|
|
|
|
if (!lib) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-12-13 22:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FT_Int major;
|
|
|
|
FT_Int minor;
|
|
|
|
FT_Int patch;
|
|
|
|
FT_Library_Version(mFace->glyph->library, &major, &minor, &patch);
|
|
|
|
|
|
|
|
// Versions 2.4.0 to 2.4.3 crash if configured with
|
|
|
|
// FT_CONFIG_OPTION_OLD_INTERNALS. Presence of the symbol FT_Alloc
|
|
|
|
// indicates FT_CONFIG_OPTION_OLD_INTERNALS.
|
|
|
|
if (major == 2 && minor == 4 && patch < 4 &&
|
|
|
|
PR_FindFunctionSymbol(lib, "FT_Alloc")) {
|
2012-07-30 18:20:58 +04:00
|
|
|
function = nullptr;
|
2010-12-13 22:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decrement the reference count incremented in
|
|
|
|
// PR_FindFunctionSymbolAndLibrary.
|
|
|
|
PR_UnloadLibrary(lib);
|
|
|
|
|
|
|
|
return function;
|
|
|
|
}
|
2018-04-26 19:08:18 +03:00
|
|
|
|
|
|
|
/*static*/
|
|
|
|
void
|
|
|
|
gfxFT2Utils::GetVariationAxes(const FT_MM_Var* aMMVar,
|
|
|
|
nsTArray<gfxFontVariationAxis>& aAxes)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAxes.IsEmpty());
|
|
|
|
if (!aMMVar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aAxes.SetCapacity(aMMVar->num_axis);
|
|
|
|
for (unsigned i = 0; i < aMMVar->num_axis; i++) {
|
|
|
|
const auto& a = aMMVar->axis[i];
|
|
|
|
gfxFontVariationAxis axis;
|
|
|
|
axis.mMinValue = a.minimum / 65536.0;
|
|
|
|
axis.mMaxValue = a.maximum / 65536.0;
|
|
|
|
axis.mDefaultValue = a.def / 65536.0;
|
|
|
|
axis.mTag = a.tag;
|
|
|
|
axis.mName.Assign(NS_ConvertUTF8toUTF16(a.name));
|
|
|
|
aAxes.AppendElement(axis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/
|
|
|
|
void
|
|
|
|
gfxFT2Utils::GetVariationInstances(
|
|
|
|
gfxFontEntry* aFontEntry,
|
|
|
|
const FT_MM_Var* aMMVar,
|
|
|
|
nsTArray<gfxFontVariationInstance>& aInstances)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aInstances.IsEmpty());
|
|
|
|
if (!aMMVar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hb_blob_t* nameTable =
|
|
|
|
aFontEntry->GetFontTable(TRUETYPE_TAG('n','a','m','e'));
|
|
|
|
if (!nameTable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aInstances.SetCapacity(aMMVar->num_namedstyles);
|
|
|
|
for (unsigned i = 0; i < aMMVar->num_namedstyles; i++) {
|
|
|
|
const auto& ns = aMMVar->namedstyle[i];
|
|
|
|
gfxFontVariationInstance inst;
|
|
|
|
nsresult rv =
|
|
|
|
gfxFontUtils::ReadCanonicalName(nameTable, ns.strid, inst.mName);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
inst.mValues.SetCapacity(aMMVar->num_axis);
|
|
|
|
for (unsigned j = 0; j < aMMVar->num_axis; j++) {
|
|
|
|
gfxFontVariationValue value;
|
|
|
|
value.mAxis = aMMVar->axis[j].tag;
|
|
|
|
value.mValue = ns.coords[j] / 65536.0;
|
|
|
|
inst.mValues.AppendElement(value);
|
|
|
|
}
|
|
|
|
aInstances.AppendElement(inst);
|
|
|
|
}
|
|
|
|
hb_blob_destroy(nameTable);
|
|
|
|
}
|