2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsFont.h"
|
2013-09-01 15:21:01 -07:00
|
|
|
#include "gfxFont.h" // for gfxFontStyle
|
|
|
|
#include "gfxFontConstants.h" // for NS_FONT_KERNING_AUTO, etc
|
|
|
|
#include "gfxFontFeatures.h" // for gfxFontFeature, etc
|
|
|
|
#include "gfxFontUtils.h" // for TRUETYPE_TAG
|
|
|
|
#include "nsCRT.h" // for nsCRT
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsISupports.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsUnicharUtils.h"
|
2014-01-04 07:02:17 -08:00
|
|
|
#include "nscore.h" // for char16_t
|
2014-01-30 10:26:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-10-07 16:15:59 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsFont::nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
|
|
|
|
uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
|
2013-05-19 19:59:20 -07:00
|
|
|
nscoord aSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aName && IsASCII(nsDependentCString(aName)),
|
|
|
|
"Must only pass ASCII names here");
|
|
|
|
name.AssignASCII(aName);
|
|
|
|
style = aStyle;
|
2011-10-17 07:59:28 -07:00
|
|
|
systemFont = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
variant = aVariant;
|
|
|
|
weight = aWeight;
|
2009-01-29 12:39:18 -08:00
|
|
|
stretch = aStretch;
|
2007-03-22 10:30:00 -07:00
|
|
|
decorations = aDecoration;
|
2013-07-29 13:00:41 -07:00
|
|
|
smoothing = NS_FONT_SMOOTHING_AUTO;
|
2007-03-22 10:30:00 -07:00
|
|
|
size = aSize;
|
2013-05-19 19:59:20 -07:00
|
|
|
sizeAdjust = 0.0;
|
|
|
|
kerning = NS_FONT_KERNING_AUTO;
|
|
|
|
synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE;
|
|
|
|
|
|
|
|
variantAlternates = 0;
|
|
|
|
variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
|
|
|
|
variantEastAsian = 0;
|
|
|
|
variantLigatures = 0;
|
|
|
|
variantNumeric = 0;
|
|
|
|
variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-19 19:59:20 -07:00
|
|
|
nsFont::nsFont(const nsSubstring& aName, uint8_t aStyle, uint8_t aVariant,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
|
2013-05-19 19:59:20 -07:00
|
|
|
nscoord aSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
: name(aName)
|
|
|
|
{
|
|
|
|
style = aStyle;
|
2011-10-17 07:59:28 -07:00
|
|
|
systemFont = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
variant = aVariant;
|
|
|
|
weight = aWeight;
|
2009-01-29 12:39:18 -08:00
|
|
|
stretch = aStretch;
|
2007-03-22 10:30:00 -07:00
|
|
|
decorations = aDecoration;
|
2013-07-29 13:00:41 -07:00
|
|
|
smoothing = NS_FONT_SMOOTHING_AUTO;
|
2007-03-22 10:30:00 -07:00
|
|
|
size = aSize;
|
2013-05-19 19:59:20 -07:00
|
|
|
sizeAdjust = 0.0;
|
|
|
|
kerning = NS_FONT_KERNING_AUTO;
|
|
|
|
synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE;
|
|
|
|
|
|
|
|
variantAlternates = 0;
|
|
|
|
variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
|
|
|
|
variantEastAsian = 0;
|
|
|
|
variantLigatures = 0;
|
|
|
|
variantNumeric = 0;
|
|
|
|
variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFont::nsFont(const nsFont& aOther)
|
|
|
|
: name(aOther.name)
|
|
|
|
{
|
|
|
|
style = aOther.style;
|
|
|
|
systemFont = aOther.systemFont;
|
|
|
|
variant = aOther.variant;
|
|
|
|
weight = aOther.weight;
|
2009-01-29 12:39:18 -08:00
|
|
|
stretch = aOther.stretch;
|
2007-03-22 10:30:00 -07:00
|
|
|
decorations = aOther.decorations;
|
2013-07-29 13:00:41 -07:00
|
|
|
smoothing = aOther.smoothing;
|
2007-03-22 10:30:00 -07:00
|
|
|
size = aOther.size;
|
|
|
|
sizeAdjust = aOther.sizeAdjust;
|
2013-05-19 19:59:20 -07:00
|
|
|
kerning = aOther.kerning;
|
|
|
|
synthesis = aOther.synthesis;
|
2013-05-19 11:23:19 -07:00
|
|
|
fontFeatureSettings = aOther.fontFeatureSettings;
|
2013-05-19 19:59:20 -07:00
|
|
|
languageOverride = aOther.languageOverride;
|
|
|
|
variantAlternates = aOther.variantAlternates;
|
|
|
|
variantCaps = aOther.variantCaps;
|
|
|
|
variantEastAsian = aOther.variantEastAsian;
|
|
|
|
variantLigatures = aOther.variantLigatures;
|
|
|
|
variantNumeric = aOther.variantNumeric;
|
|
|
|
variantPosition = aOther.variantPosition;
|
|
|
|
alternateValues = aOther.alternateValues;
|
|
|
|
featureValueLookup = aOther.featureValueLookup;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFont::nsFont()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFont::~nsFont()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsFont::BaseEquals(const nsFont& aOther) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if ((style == aOther.style) &&
|
|
|
|
(systemFont == aOther.systemFont) &&
|
|
|
|
(weight == aOther.weight) &&
|
2009-01-29 12:39:18 -08:00
|
|
|
(stretch == aOther.stretch) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(size == aOther.size) &&
|
|
|
|
(sizeAdjust == aOther.sizeAdjust) &&
|
2010-07-13 13:30:42 -07:00
|
|
|
name.Equals(aOther.name, nsCaseInsensitiveStringComparator()) &&
|
2013-05-19 19:59:20 -07:00
|
|
|
(kerning == aOther.kerning) &&
|
|
|
|
(synthesis == aOther.synthesis) &&
|
|
|
|
(fontFeatureSettings == aOther.fontFeatureSettings) &&
|
2012-04-25 23:22:24 -07:00
|
|
|
(languageOverride == aOther.languageOverride) &&
|
2013-05-19 19:59:20 -07:00
|
|
|
(variantAlternates == aOther.variantAlternates) &&
|
|
|
|
(variantCaps == aOther.variantCaps) &&
|
|
|
|
(variantEastAsian == aOther.variantEastAsian) &&
|
|
|
|
(variantLigatures == aOther.variantLigatures) &&
|
|
|
|
(variantNumeric == aOther.variantNumeric) &&
|
|
|
|
(variantPosition == aOther.variantPosition) &&
|
|
|
|
(alternateValues == aOther.alternateValues) &&
|
2013-08-03 00:58:53 -07:00
|
|
|
(featureValueLookup == aOther.featureValueLookup) &&
|
|
|
|
(smoothing == aOther.smoothing)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsFont::Equals(const nsFont& aOther) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (BaseEquals(aOther) &&
|
|
|
|
(variant == aOther.variant) &&
|
2013-08-03 00:58:53 -07:00
|
|
|
(decorations == aOther.decorations)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFont& nsFont::operator=(const nsFont& aOther)
|
|
|
|
{
|
|
|
|
name = aOther.name;
|
|
|
|
style = aOther.style;
|
|
|
|
systemFont = aOther.systemFont;
|
|
|
|
variant = aOther.variant;
|
|
|
|
weight = aOther.weight;
|
2009-01-29 12:39:18 -08:00
|
|
|
stretch = aOther.stretch;
|
2007-03-22 10:30:00 -07:00
|
|
|
decorations = aOther.decorations;
|
2013-07-29 13:00:41 -07:00
|
|
|
smoothing = aOther.smoothing;
|
2007-03-22 10:30:00 -07:00
|
|
|
size = aOther.size;
|
|
|
|
sizeAdjust = aOther.sizeAdjust;
|
2013-05-19 19:59:20 -07:00
|
|
|
kerning = aOther.kerning;
|
|
|
|
synthesis = aOther.synthesis;
|
2013-05-19 11:23:19 -07:00
|
|
|
fontFeatureSettings = aOther.fontFeatureSettings;
|
2013-05-19 19:59:20 -07:00
|
|
|
languageOverride = aOther.languageOverride;
|
|
|
|
variantAlternates = aOther.variantAlternates;
|
|
|
|
variantCaps = aOther.variantCaps;
|
|
|
|
variantEastAsian = aOther.variantEastAsian;
|
|
|
|
variantLigatures = aOther.variantLigatures;
|
|
|
|
variantNumeric = aOther.variantNumeric;
|
|
|
|
variantPosition = aOther.variantPosition;
|
|
|
|
alternateValues = aOther.alternateValues;
|
|
|
|
featureValueLookup = aOther.featureValueLookup;
|
2007-03-22 10:30:00 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-05-13 02:45:37 -07:00
|
|
|
void
|
2013-05-19 19:59:20 -07:00
|
|
|
nsFont::CopyAlternates(const nsFont& aOther)
|
2013-05-13 02:45:37 -07:00
|
|
|
{
|
2013-05-19 19:59:20 -07:00
|
|
|
variantAlternates = aOther.variantAlternates;
|
|
|
|
alternateValues = aOther.alternateValues;
|
|
|
|
featureValueLookup = aOther.featureValueLookup;
|
2013-05-13 02:45:37 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsGenericFontFamily(const nsString& aFamily)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t generic;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFont::GetGenericID(aFamily, &generic);
|
|
|
|
return generic != kGenericFont_NONE;
|
|
|
|
}
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t kSingleQuote = char16_t('\'');
|
|
|
|
const char16_t kDoubleQuote = char16_t('\"');
|
|
|
|
const char16_t kComma = char16_t(',');
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsFont::EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *p, *p_end;
|
2007-03-22 10:30:00 -07:00
|
|
|
name.BeginReading(p);
|
|
|
|
name.EndReading(p_end);
|
|
|
|
nsAutoString family;
|
|
|
|
|
|
|
|
while (p < p_end) {
|
|
|
|
while (nsCRT::IsAsciiSpace(*p))
|
|
|
|
if (++p == p_end)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool generic;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (*p == kSingleQuote || *p == kDoubleQuote) {
|
|
|
|
// quoted font family
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t quoteMark = *p;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (++p == p_end)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *nameStart = p;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX What about CSS character escapes?
|
|
|
|
while (*p != quoteMark)
|
|
|
|
if (++p == p_end)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
family = Substring(nameStart, p);
|
2011-10-17 07:59:28 -07:00
|
|
|
generic = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// unquoted font family
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *nameStart = p;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
|
|
|
|
|
|
|
family = Substring(nameStart, p);
|
2011-10-17 07:59:28 -07:00
|
|
|
family.CompressWhitespace(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
generic = IsGenericFontFamily(family);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!family.IsEmpty() && !(*aFunc)(family, generic, aData))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
++p; // may advance past p_end
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-19 19:59:20 -07:00
|
|
|
// mapping from bitflag to font feature tag/value pair
|
|
|
|
//
|
|
|
|
// these need to be kept in sync with the constants listed
|
|
|
|
// in gfxFontConstants.h (e.g. NS_FONT_VARIANT_EAST_ASIAN_JIS78)
|
|
|
|
|
|
|
|
// NS_FONT_VARIANT_EAST_ASIAN_xxx values
|
|
|
|
const gfxFontFeature eastAsianDefaults[] = {
|
|
|
|
{ TRUETYPE_TAG('j','p','7','8'), 1 },
|
|
|
|
{ TRUETYPE_TAG('j','p','8','3'), 1 },
|
|
|
|
{ TRUETYPE_TAG('j','p','9','0'), 1 },
|
|
|
|
{ TRUETYPE_TAG('j','p','0','4'), 1 },
|
|
|
|
{ TRUETYPE_TAG('s','m','p','l'), 1 },
|
|
|
|
{ TRUETYPE_TAG('t','r','a','d'), 1 },
|
|
|
|
{ TRUETYPE_TAG('f','w','i','d'), 1 },
|
|
|
|
{ TRUETYPE_TAG('p','w','i','d'), 1 },
|
|
|
|
{ TRUETYPE_TAG('r','u','b','y'), 1 }
|
|
|
|
};
|
|
|
|
|
2014-01-30 10:26:54 -08:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(eastAsianDefaults) ==
|
2013-10-20 00:25:20 -07:00
|
|
|
eFeatureEastAsian_numFeatures,
|
|
|
|
"eFeatureEastAsian_numFeatures should be correct");
|
2013-05-19 19:59:20 -07:00
|
|
|
|
|
|
|
// NS_FONT_VARIANT_LIGATURES_xxx values
|
|
|
|
const gfxFontFeature ligDefaults[] = {
|
2013-11-18 20:30:25 -08:00
|
|
|
{ TRUETYPE_TAG('l','i','g','a'), 0 }, // none value means all off
|
2013-05-19 19:59:20 -07:00
|
|
|
{ TRUETYPE_TAG('l','i','g','a'), 1 },
|
|
|
|
{ TRUETYPE_TAG('l','i','g','a'), 0 },
|
|
|
|
{ TRUETYPE_TAG('d','l','i','g'), 1 },
|
|
|
|
{ TRUETYPE_TAG('d','l','i','g'), 0 },
|
|
|
|
{ TRUETYPE_TAG('h','l','i','g'), 1 },
|
|
|
|
{ TRUETYPE_TAG('h','l','i','g'), 0 },
|
|
|
|
{ TRUETYPE_TAG('c','a','l','t'), 1 },
|
|
|
|
{ TRUETYPE_TAG('c','a','l','t'), 0 }
|
|
|
|
};
|
|
|
|
|
2014-01-30 10:26:54 -08:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(ligDefaults) ==
|
2013-10-20 00:25:20 -07:00
|
|
|
eFeatureLigatures_numFeatures,
|
|
|
|
"eFeatureLigatures_numFeatures should be correct");
|
2013-05-19 19:59:20 -07:00
|
|
|
|
|
|
|
// NS_FONT_VARIANT_NUMERIC_xxx values
|
|
|
|
const gfxFontFeature numericDefaults[] = {
|
|
|
|
{ TRUETYPE_TAG('l','n','u','m'), 1 },
|
|
|
|
{ TRUETYPE_TAG('o','n','u','m'), 1 },
|
|
|
|
{ TRUETYPE_TAG('p','n','u','m'), 1 },
|
|
|
|
{ TRUETYPE_TAG('t','n','u','m'), 1 },
|
|
|
|
{ TRUETYPE_TAG('f','r','a','c'), 1 },
|
|
|
|
{ TRUETYPE_TAG('a','f','r','c'), 1 },
|
|
|
|
{ TRUETYPE_TAG('z','e','r','o'), 1 },
|
|
|
|
{ TRUETYPE_TAG('o','r','d','n'), 1 }
|
|
|
|
};
|
|
|
|
|
2014-01-30 10:26:54 -08:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(numericDefaults) ==
|
2013-10-20 00:25:20 -07:00
|
|
|
eFeatureNumeric_numFeatures,
|
|
|
|
"eFeatureNumeric_numFeatures should be correct");
|
2013-05-19 19:59:20 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
AddFontFeaturesBitmask(uint32_t aValue, uint32_t aMin, uint32_t aMax,
|
|
|
|
const gfxFontFeature aFeatureDefaults[],
|
|
|
|
nsTArray<gfxFontFeature>& aFeaturesOut)
|
|
|
|
|
|
|
|
{
|
|
|
|
uint32_t i, m;
|
|
|
|
|
|
|
|
for (i = 0, m = aMin; m <= aMax; i++, m <<= 1) {
|
|
|
|
if (m & aValue) {
|
|
|
|
const gfxFontFeature& feature = aFeatureDefaults[i];
|
|
|
|
aFeaturesOut.AppendElement(feature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFont::AddFontFeaturesToStyle(gfxFontStyle *aStyle) const
|
|
|
|
{
|
|
|
|
// add in font-variant features
|
|
|
|
gfxFontFeature setting;
|
|
|
|
|
|
|
|
// -- kerning
|
|
|
|
setting.mTag = TRUETYPE_TAG('k','e','r','n');
|
|
|
|
switch (kerning) {
|
|
|
|
case NS_FONT_KERNING_NONE:
|
|
|
|
setting.mValue = 0;
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
case NS_FONT_KERNING_NORMAL:
|
|
|
|
setting.mValue = 1;
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// auto case implies use user agent default
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- alternates
|
|
|
|
if (variantAlternates & NS_FONT_VARIANT_ALTERNATES_HISTORICAL) {
|
|
|
|
setting.mValue = 1;
|
|
|
|
setting.mTag = TRUETYPE_TAG('h','i','s','t');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -- copy font-specific alternate info into style
|
|
|
|
// (this will be resolved after font-matching occurs)
|
|
|
|
aStyle->alternateValues.AppendElements(alternateValues);
|
|
|
|
aStyle->featureValueLookup = featureValueLookup;
|
|
|
|
|
|
|
|
// -- caps
|
|
|
|
setting.mValue = 1;
|
|
|
|
switch (variantCaps) {
|
|
|
|
case NS_FONT_VARIANT_CAPS_ALLSMALL:
|
|
|
|
setting.mTag = TRUETYPE_TAG('c','2','s','c');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
// fall through to the small-caps case
|
|
|
|
case NS_FONT_VARIANT_CAPS_SMALLCAPS:
|
|
|
|
setting.mTag = TRUETYPE_TAG('s','m','c','p');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_FONT_VARIANT_CAPS_ALLPETITE:
|
|
|
|
setting.mTag = TRUETYPE_TAG('c','2','p','c');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
// fall through to the petite-caps case
|
|
|
|
case NS_FONT_VARIANT_CAPS_PETITECAPS:
|
|
|
|
setting.mTag = TRUETYPE_TAG('p','c','a','p');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_FONT_VARIANT_CAPS_TITLING:
|
|
|
|
setting.mTag = TRUETYPE_TAG('t','i','t','l');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_FONT_VARIANT_CAPS_UNICASE:
|
|
|
|
setting.mTag = TRUETYPE_TAG('u','n','i','c');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- east-asian
|
|
|
|
if (variantEastAsian) {
|
|
|
|
AddFontFeaturesBitmask(variantEastAsian,
|
|
|
|
NS_FONT_VARIANT_EAST_ASIAN_JIS78,
|
|
|
|
NS_FONT_VARIANT_EAST_ASIAN_RUBY,
|
|
|
|
eastAsianDefaults, aStyle->featureSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- ligatures
|
|
|
|
if (variantLigatures) {
|
|
|
|
AddFontFeaturesBitmask(variantLigatures,
|
2013-11-18 20:30:25 -08:00
|
|
|
NS_FONT_VARIANT_LIGATURES_NONE,
|
2013-05-19 19:59:20 -07:00
|
|
|
NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL,
|
|
|
|
ligDefaults, aStyle->featureSettings);
|
|
|
|
|
|
|
|
if (variantLigatures & NS_FONT_VARIANT_LIGATURES_COMMON) {
|
2013-11-18 20:30:25 -08:00
|
|
|
// liga already enabled, need to enable clig also
|
2013-05-19 19:59:20 -07:00
|
|
|
setting.mTag = TRUETYPE_TAG('c','l','i','g');
|
|
|
|
setting.mValue = 1;
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
} else if (variantLigatures & NS_FONT_VARIANT_LIGATURES_NO_COMMON) {
|
2013-11-18 20:30:25 -08:00
|
|
|
// liga already disabled, need to disable clig also
|
2013-05-19 19:59:20 -07:00
|
|
|
setting.mTag = TRUETYPE_TAG('c','l','i','g');
|
|
|
|
setting.mValue = 0;
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
2013-11-18 20:30:25 -08:00
|
|
|
} else if (variantLigatures & NS_FONT_VARIANT_LIGATURES_NONE) {
|
|
|
|
// liga already disabled, need to disable dlig, hlig, calt, clig
|
|
|
|
setting.mValue = 0;
|
|
|
|
setting.mTag = TRUETYPE_TAG('d','l','i','g');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
setting.mTag = TRUETYPE_TAG('h','l','i','g');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
setting.mTag = TRUETYPE_TAG('c','a','l','t');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
setting.mTag = TRUETYPE_TAG('c','l','i','g');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
2013-05-19 19:59:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- numeric
|
|
|
|
if (variantNumeric) {
|
|
|
|
AddFontFeaturesBitmask(variantNumeric,
|
|
|
|
NS_FONT_VARIANT_NUMERIC_LINING,
|
|
|
|
NS_FONT_VARIANT_NUMERIC_ORDINAL,
|
|
|
|
numericDefaults, aStyle->featureSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- position
|
|
|
|
setting.mTag = 0;
|
|
|
|
setting.mValue = 1;
|
|
|
|
switch (variantPosition) {
|
|
|
|
case NS_FONT_VARIANT_POSITION_SUPER:
|
|
|
|
setting.mTag = TRUETYPE_TAG('s','u','p','s');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_FONT_VARIANT_POSITION_SUB:
|
|
|
|
setting.mTag = TRUETYPE_TAG('s','u','b','s');
|
|
|
|
aStyle->featureSettings.AppendElement(setting);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add in features from font-feature-settings
|
|
|
|
aStyle->featureSettings.AppendElements(fontFeatureSettings);
|
2013-07-29 13:00:41 -07:00
|
|
|
|
|
|
|
// enable grayscale antialiasing for text
|
2013-07-29 13:01:14 -07:00
|
|
|
if (smoothing == NS_FONT_SMOOTHING_GRAYSCALE) {
|
2013-07-29 13:00:41 -07:00
|
|
|
aStyle->useGrayscaleAntialiasing = true;
|
|
|
|
}
|
2013-05-19 19:59:20 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool FontEnumCallback(const nsString& aFamily, bool aGeneric, void *aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*((nsString*)aData) = aFamily;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsFont::GetFirstFamily(nsString& aFamily) const
|
|
|
|
{
|
|
|
|
EnumerateFamilies(FontEnumCallback, &aFamily);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/
|
2012-08-22 08:56:38 -07:00
|
|
|
void nsFont::GetGenericID(const nsString& aGeneric, uint8_t* aID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aID = kGenericFont_NONE;
|
|
|
|
if (aGeneric.LowerCaseEqualsLiteral("-moz-fixed")) *aID = kGenericFont_moz_fixed;
|
|
|
|
else if (aGeneric.LowerCaseEqualsLiteral("serif")) *aID = kGenericFont_serif;
|
|
|
|
else if (aGeneric.LowerCaseEqualsLiteral("sans-serif")) *aID = kGenericFont_sans_serif;
|
|
|
|
else if (aGeneric.LowerCaseEqualsLiteral("cursive")) *aID = kGenericFont_cursive;
|
|
|
|
else if (aGeneric.LowerCaseEqualsLiteral("fantasy")) *aID = kGenericFont_fantasy;
|
|
|
|
else if (aGeneric.LowerCaseEqualsLiteral("monospace")) *aID = kGenericFont_monospace;
|
|
|
|
}
|