Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsFont.h" |
michael@0 | 7 | #include "gfxFont.h" // for gfxFontStyle |
michael@0 | 8 | #include "gfxFontConstants.h" // for NS_FONT_KERNING_AUTO, etc |
michael@0 | 9 | #include "gfxFontFeatures.h" // for gfxFontFeature, etc |
michael@0 | 10 | #include "gfxFontUtils.h" // for TRUETYPE_TAG |
michael@0 | 11 | #include "nsCRT.h" // for nsCRT |
michael@0 | 12 | #include "nsDebug.h" // for NS_ASSERTION |
michael@0 | 13 | #include "nsISupports.h" |
michael@0 | 14 | #include "nsUnicharUtils.h" |
michael@0 | 15 | #include "nscore.h" // for char16_t |
michael@0 | 16 | #include "mozilla/ArrayUtils.h" |
michael@0 | 17 | #include "mozilla/gfx/2D.h" |
michael@0 | 18 | |
michael@0 | 19 | nsFont::nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant, |
michael@0 | 20 | uint16_t aWeight, int16_t aStretch, uint8_t aDecoration, |
michael@0 | 21 | nscoord aSize) |
michael@0 | 22 | { |
michael@0 | 23 | NS_ASSERTION(aName && IsASCII(nsDependentCString(aName)), |
michael@0 | 24 | "Must only pass ASCII names here"); |
michael@0 | 25 | name.AssignASCII(aName); |
michael@0 | 26 | style = aStyle; |
michael@0 | 27 | systemFont = false; |
michael@0 | 28 | variant = aVariant; |
michael@0 | 29 | weight = aWeight; |
michael@0 | 30 | stretch = aStretch; |
michael@0 | 31 | decorations = aDecoration; |
michael@0 | 32 | smoothing = NS_FONT_SMOOTHING_AUTO; |
michael@0 | 33 | size = aSize; |
michael@0 | 34 | sizeAdjust = 0.0; |
michael@0 | 35 | kerning = NS_FONT_KERNING_AUTO; |
michael@0 | 36 | synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE; |
michael@0 | 37 | |
michael@0 | 38 | variantAlternates = 0; |
michael@0 | 39 | variantCaps = NS_FONT_VARIANT_CAPS_NORMAL; |
michael@0 | 40 | variantEastAsian = 0; |
michael@0 | 41 | variantLigatures = 0; |
michael@0 | 42 | variantNumeric = 0; |
michael@0 | 43 | variantPosition = NS_FONT_VARIANT_POSITION_NORMAL; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | nsFont::nsFont(const nsSubstring& aName, uint8_t aStyle, uint8_t aVariant, |
michael@0 | 47 | uint16_t aWeight, int16_t aStretch, uint8_t aDecoration, |
michael@0 | 48 | nscoord aSize) |
michael@0 | 49 | : name(aName) |
michael@0 | 50 | { |
michael@0 | 51 | style = aStyle; |
michael@0 | 52 | systemFont = false; |
michael@0 | 53 | variant = aVariant; |
michael@0 | 54 | weight = aWeight; |
michael@0 | 55 | stretch = aStretch; |
michael@0 | 56 | decorations = aDecoration; |
michael@0 | 57 | smoothing = NS_FONT_SMOOTHING_AUTO; |
michael@0 | 58 | size = aSize; |
michael@0 | 59 | sizeAdjust = 0.0; |
michael@0 | 60 | kerning = NS_FONT_KERNING_AUTO; |
michael@0 | 61 | synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE; |
michael@0 | 62 | |
michael@0 | 63 | variantAlternates = 0; |
michael@0 | 64 | variantCaps = NS_FONT_VARIANT_CAPS_NORMAL; |
michael@0 | 65 | variantEastAsian = 0; |
michael@0 | 66 | variantLigatures = 0; |
michael@0 | 67 | variantNumeric = 0; |
michael@0 | 68 | variantPosition = NS_FONT_VARIANT_POSITION_NORMAL; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | nsFont::nsFont(const nsFont& aOther) |
michael@0 | 72 | : name(aOther.name) |
michael@0 | 73 | { |
michael@0 | 74 | style = aOther.style; |
michael@0 | 75 | systemFont = aOther.systemFont; |
michael@0 | 76 | variant = aOther.variant; |
michael@0 | 77 | weight = aOther.weight; |
michael@0 | 78 | stretch = aOther.stretch; |
michael@0 | 79 | decorations = aOther.decorations; |
michael@0 | 80 | smoothing = aOther.smoothing; |
michael@0 | 81 | size = aOther.size; |
michael@0 | 82 | sizeAdjust = aOther.sizeAdjust; |
michael@0 | 83 | kerning = aOther.kerning; |
michael@0 | 84 | synthesis = aOther.synthesis; |
michael@0 | 85 | fontFeatureSettings = aOther.fontFeatureSettings; |
michael@0 | 86 | languageOverride = aOther.languageOverride; |
michael@0 | 87 | variantAlternates = aOther.variantAlternates; |
michael@0 | 88 | variantCaps = aOther.variantCaps; |
michael@0 | 89 | variantEastAsian = aOther.variantEastAsian; |
michael@0 | 90 | variantLigatures = aOther.variantLigatures; |
michael@0 | 91 | variantNumeric = aOther.variantNumeric; |
michael@0 | 92 | variantPosition = aOther.variantPosition; |
michael@0 | 93 | alternateValues = aOther.alternateValues; |
michael@0 | 94 | featureValueLookup = aOther.featureValueLookup; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | nsFont::nsFont() |
michael@0 | 98 | { |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | nsFont::~nsFont() |
michael@0 | 102 | { |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | bool nsFont::BaseEquals(const nsFont& aOther) const |
michael@0 | 106 | { |
michael@0 | 107 | if ((style == aOther.style) && |
michael@0 | 108 | (systemFont == aOther.systemFont) && |
michael@0 | 109 | (weight == aOther.weight) && |
michael@0 | 110 | (stretch == aOther.stretch) && |
michael@0 | 111 | (size == aOther.size) && |
michael@0 | 112 | (sizeAdjust == aOther.sizeAdjust) && |
michael@0 | 113 | name.Equals(aOther.name, nsCaseInsensitiveStringComparator()) && |
michael@0 | 114 | (kerning == aOther.kerning) && |
michael@0 | 115 | (synthesis == aOther.synthesis) && |
michael@0 | 116 | (fontFeatureSettings == aOther.fontFeatureSettings) && |
michael@0 | 117 | (languageOverride == aOther.languageOverride) && |
michael@0 | 118 | (variantAlternates == aOther.variantAlternates) && |
michael@0 | 119 | (variantCaps == aOther.variantCaps) && |
michael@0 | 120 | (variantEastAsian == aOther.variantEastAsian) && |
michael@0 | 121 | (variantLigatures == aOther.variantLigatures) && |
michael@0 | 122 | (variantNumeric == aOther.variantNumeric) && |
michael@0 | 123 | (variantPosition == aOther.variantPosition) && |
michael@0 | 124 | (alternateValues == aOther.alternateValues) && |
michael@0 | 125 | (featureValueLookup == aOther.featureValueLookup) && |
michael@0 | 126 | (smoothing == aOther.smoothing)) { |
michael@0 | 127 | return true; |
michael@0 | 128 | } |
michael@0 | 129 | return false; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | bool nsFont::Equals(const nsFont& aOther) const |
michael@0 | 133 | { |
michael@0 | 134 | if (BaseEquals(aOther) && |
michael@0 | 135 | (variant == aOther.variant) && |
michael@0 | 136 | (decorations == aOther.decorations)) { |
michael@0 | 137 | return true; |
michael@0 | 138 | } |
michael@0 | 139 | return false; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | nsFont& nsFont::operator=(const nsFont& aOther) |
michael@0 | 143 | { |
michael@0 | 144 | name = aOther.name; |
michael@0 | 145 | style = aOther.style; |
michael@0 | 146 | systemFont = aOther.systemFont; |
michael@0 | 147 | variant = aOther.variant; |
michael@0 | 148 | weight = aOther.weight; |
michael@0 | 149 | stretch = aOther.stretch; |
michael@0 | 150 | decorations = aOther.decorations; |
michael@0 | 151 | smoothing = aOther.smoothing; |
michael@0 | 152 | size = aOther.size; |
michael@0 | 153 | sizeAdjust = aOther.sizeAdjust; |
michael@0 | 154 | kerning = aOther.kerning; |
michael@0 | 155 | synthesis = aOther.synthesis; |
michael@0 | 156 | fontFeatureSettings = aOther.fontFeatureSettings; |
michael@0 | 157 | languageOverride = aOther.languageOverride; |
michael@0 | 158 | variantAlternates = aOther.variantAlternates; |
michael@0 | 159 | variantCaps = aOther.variantCaps; |
michael@0 | 160 | variantEastAsian = aOther.variantEastAsian; |
michael@0 | 161 | variantLigatures = aOther.variantLigatures; |
michael@0 | 162 | variantNumeric = aOther.variantNumeric; |
michael@0 | 163 | variantPosition = aOther.variantPosition; |
michael@0 | 164 | alternateValues = aOther.alternateValues; |
michael@0 | 165 | featureValueLookup = aOther.featureValueLookup; |
michael@0 | 166 | return *this; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | void |
michael@0 | 170 | nsFont::CopyAlternates(const nsFont& aOther) |
michael@0 | 171 | { |
michael@0 | 172 | variantAlternates = aOther.variantAlternates; |
michael@0 | 173 | alternateValues = aOther.alternateValues; |
michael@0 | 174 | featureValueLookup = aOther.featureValueLookup; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | static bool IsGenericFontFamily(const nsString& aFamily) |
michael@0 | 178 | { |
michael@0 | 179 | uint8_t generic; |
michael@0 | 180 | nsFont::GetGenericID(aFamily, &generic); |
michael@0 | 181 | return generic != kGenericFont_NONE; |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | const char16_t kSingleQuote = char16_t('\''); |
michael@0 | 185 | const char16_t kDoubleQuote = char16_t('\"'); |
michael@0 | 186 | const char16_t kComma = char16_t(','); |
michael@0 | 187 | |
michael@0 | 188 | bool nsFont::EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const |
michael@0 | 189 | { |
michael@0 | 190 | const char16_t *p, *p_end; |
michael@0 | 191 | name.BeginReading(p); |
michael@0 | 192 | name.EndReading(p_end); |
michael@0 | 193 | nsAutoString family; |
michael@0 | 194 | |
michael@0 | 195 | while (p < p_end) { |
michael@0 | 196 | while (nsCRT::IsAsciiSpace(*p)) |
michael@0 | 197 | if (++p == p_end) |
michael@0 | 198 | return true; |
michael@0 | 199 | |
michael@0 | 200 | bool generic; |
michael@0 | 201 | if (*p == kSingleQuote || *p == kDoubleQuote) { |
michael@0 | 202 | // quoted font family |
michael@0 | 203 | char16_t quoteMark = *p; |
michael@0 | 204 | if (++p == p_end) |
michael@0 | 205 | return true; |
michael@0 | 206 | const char16_t *nameStart = p; |
michael@0 | 207 | |
michael@0 | 208 | // XXX What about CSS character escapes? |
michael@0 | 209 | while (*p != quoteMark) |
michael@0 | 210 | if (++p == p_end) |
michael@0 | 211 | return true; |
michael@0 | 212 | |
michael@0 | 213 | family = Substring(nameStart, p); |
michael@0 | 214 | generic = false; |
michael@0 | 215 | |
michael@0 | 216 | while (++p != p_end && *p != kComma) |
michael@0 | 217 | /* nothing */ ; |
michael@0 | 218 | |
michael@0 | 219 | } else { |
michael@0 | 220 | // unquoted font family |
michael@0 | 221 | const char16_t *nameStart = p; |
michael@0 | 222 | while (++p != p_end && *p != kComma) |
michael@0 | 223 | /* nothing */ ; |
michael@0 | 224 | |
michael@0 | 225 | family = Substring(nameStart, p); |
michael@0 | 226 | family.CompressWhitespace(false, true); |
michael@0 | 227 | generic = IsGenericFontFamily(family); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | if (!family.IsEmpty() && !(*aFunc)(family, generic, aData)) |
michael@0 | 231 | return false; |
michael@0 | 232 | |
michael@0 | 233 | ++p; // may advance past p_end |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | return true; |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | // mapping from bitflag to font feature tag/value pair |
michael@0 | 240 | // |
michael@0 | 241 | // these need to be kept in sync with the constants listed |
michael@0 | 242 | // in gfxFontConstants.h (e.g. NS_FONT_VARIANT_EAST_ASIAN_JIS78) |
michael@0 | 243 | |
michael@0 | 244 | // NS_FONT_VARIANT_EAST_ASIAN_xxx values |
michael@0 | 245 | const gfxFontFeature eastAsianDefaults[] = { |
michael@0 | 246 | { TRUETYPE_TAG('j','p','7','8'), 1 }, |
michael@0 | 247 | { TRUETYPE_TAG('j','p','8','3'), 1 }, |
michael@0 | 248 | { TRUETYPE_TAG('j','p','9','0'), 1 }, |
michael@0 | 249 | { TRUETYPE_TAG('j','p','0','4'), 1 }, |
michael@0 | 250 | { TRUETYPE_TAG('s','m','p','l'), 1 }, |
michael@0 | 251 | { TRUETYPE_TAG('t','r','a','d'), 1 }, |
michael@0 | 252 | { TRUETYPE_TAG('f','w','i','d'), 1 }, |
michael@0 | 253 | { TRUETYPE_TAG('p','w','i','d'), 1 }, |
michael@0 | 254 | { TRUETYPE_TAG('r','u','b','y'), 1 } |
michael@0 | 255 | }; |
michael@0 | 256 | |
michael@0 | 257 | static_assert(MOZ_ARRAY_LENGTH(eastAsianDefaults) == |
michael@0 | 258 | eFeatureEastAsian_numFeatures, |
michael@0 | 259 | "eFeatureEastAsian_numFeatures should be correct"); |
michael@0 | 260 | |
michael@0 | 261 | // NS_FONT_VARIANT_LIGATURES_xxx values |
michael@0 | 262 | const gfxFontFeature ligDefaults[] = { |
michael@0 | 263 | { TRUETYPE_TAG('l','i','g','a'), 0 }, // none value means all off |
michael@0 | 264 | { TRUETYPE_TAG('l','i','g','a'), 1 }, |
michael@0 | 265 | { TRUETYPE_TAG('l','i','g','a'), 0 }, |
michael@0 | 266 | { TRUETYPE_TAG('d','l','i','g'), 1 }, |
michael@0 | 267 | { TRUETYPE_TAG('d','l','i','g'), 0 }, |
michael@0 | 268 | { TRUETYPE_TAG('h','l','i','g'), 1 }, |
michael@0 | 269 | { TRUETYPE_TAG('h','l','i','g'), 0 }, |
michael@0 | 270 | { TRUETYPE_TAG('c','a','l','t'), 1 }, |
michael@0 | 271 | { TRUETYPE_TAG('c','a','l','t'), 0 } |
michael@0 | 272 | }; |
michael@0 | 273 | |
michael@0 | 274 | static_assert(MOZ_ARRAY_LENGTH(ligDefaults) == |
michael@0 | 275 | eFeatureLigatures_numFeatures, |
michael@0 | 276 | "eFeatureLigatures_numFeatures should be correct"); |
michael@0 | 277 | |
michael@0 | 278 | // NS_FONT_VARIANT_NUMERIC_xxx values |
michael@0 | 279 | const gfxFontFeature numericDefaults[] = { |
michael@0 | 280 | { TRUETYPE_TAG('l','n','u','m'), 1 }, |
michael@0 | 281 | { TRUETYPE_TAG('o','n','u','m'), 1 }, |
michael@0 | 282 | { TRUETYPE_TAG('p','n','u','m'), 1 }, |
michael@0 | 283 | { TRUETYPE_TAG('t','n','u','m'), 1 }, |
michael@0 | 284 | { TRUETYPE_TAG('f','r','a','c'), 1 }, |
michael@0 | 285 | { TRUETYPE_TAG('a','f','r','c'), 1 }, |
michael@0 | 286 | { TRUETYPE_TAG('z','e','r','o'), 1 }, |
michael@0 | 287 | { TRUETYPE_TAG('o','r','d','n'), 1 } |
michael@0 | 288 | }; |
michael@0 | 289 | |
michael@0 | 290 | static_assert(MOZ_ARRAY_LENGTH(numericDefaults) == |
michael@0 | 291 | eFeatureNumeric_numFeatures, |
michael@0 | 292 | "eFeatureNumeric_numFeatures should be correct"); |
michael@0 | 293 | |
michael@0 | 294 | static void |
michael@0 | 295 | AddFontFeaturesBitmask(uint32_t aValue, uint32_t aMin, uint32_t aMax, |
michael@0 | 296 | const gfxFontFeature aFeatureDefaults[], |
michael@0 | 297 | nsTArray<gfxFontFeature>& aFeaturesOut) |
michael@0 | 298 | |
michael@0 | 299 | { |
michael@0 | 300 | uint32_t i, m; |
michael@0 | 301 | |
michael@0 | 302 | for (i = 0, m = aMin; m <= aMax; i++, m <<= 1) { |
michael@0 | 303 | if (m & aValue) { |
michael@0 | 304 | const gfxFontFeature& feature = aFeatureDefaults[i]; |
michael@0 | 305 | aFeaturesOut.AppendElement(feature); |
michael@0 | 306 | } |
michael@0 | 307 | } |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | void nsFont::AddFontFeaturesToStyle(gfxFontStyle *aStyle) const |
michael@0 | 311 | { |
michael@0 | 312 | // add in font-variant features |
michael@0 | 313 | gfxFontFeature setting; |
michael@0 | 314 | |
michael@0 | 315 | // -- kerning |
michael@0 | 316 | setting.mTag = TRUETYPE_TAG('k','e','r','n'); |
michael@0 | 317 | switch (kerning) { |
michael@0 | 318 | case NS_FONT_KERNING_NONE: |
michael@0 | 319 | setting.mValue = 0; |
michael@0 | 320 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 321 | break; |
michael@0 | 322 | case NS_FONT_KERNING_NORMAL: |
michael@0 | 323 | setting.mValue = 1; |
michael@0 | 324 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 325 | break; |
michael@0 | 326 | default: |
michael@0 | 327 | // auto case implies use user agent default |
michael@0 | 328 | break; |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | // -- alternates |
michael@0 | 332 | if (variantAlternates & NS_FONT_VARIANT_ALTERNATES_HISTORICAL) { |
michael@0 | 333 | setting.mValue = 1; |
michael@0 | 334 | setting.mTag = TRUETYPE_TAG('h','i','s','t'); |
michael@0 | 335 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | |
michael@0 | 339 | // -- copy font-specific alternate info into style |
michael@0 | 340 | // (this will be resolved after font-matching occurs) |
michael@0 | 341 | aStyle->alternateValues.AppendElements(alternateValues); |
michael@0 | 342 | aStyle->featureValueLookup = featureValueLookup; |
michael@0 | 343 | |
michael@0 | 344 | // -- caps |
michael@0 | 345 | setting.mValue = 1; |
michael@0 | 346 | switch (variantCaps) { |
michael@0 | 347 | case NS_FONT_VARIANT_CAPS_ALLSMALL: |
michael@0 | 348 | setting.mTag = TRUETYPE_TAG('c','2','s','c'); |
michael@0 | 349 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 350 | // fall through to the small-caps case |
michael@0 | 351 | case NS_FONT_VARIANT_CAPS_SMALLCAPS: |
michael@0 | 352 | setting.mTag = TRUETYPE_TAG('s','m','c','p'); |
michael@0 | 353 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 354 | break; |
michael@0 | 355 | |
michael@0 | 356 | case NS_FONT_VARIANT_CAPS_ALLPETITE: |
michael@0 | 357 | setting.mTag = TRUETYPE_TAG('c','2','p','c'); |
michael@0 | 358 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 359 | // fall through to the petite-caps case |
michael@0 | 360 | case NS_FONT_VARIANT_CAPS_PETITECAPS: |
michael@0 | 361 | setting.mTag = TRUETYPE_TAG('p','c','a','p'); |
michael@0 | 362 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 363 | break; |
michael@0 | 364 | |
michael@0 | 365 | case NS_FONT_VARIANT_CAPS_TITLING: |
michael@0 | 366 | setting.mTag = TRUETYPE_TAG('t','i','t','l'); |
michael@0 | 367 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 368 | break; |
michael@0 | 369 | |
michael@0 | 370 | case NS_FONT_VARIANT_CAPS_UNICASE: |
michael@0 | 371 | setting.mTag = TRUETYPE_TAG('u','n','i','c'); |
michael@0 | 372 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 373 | break; |
michael@0 | 374 | |
michael@0 | 375 | default: |
michael@0 | 376 | break; |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | // -- east-asian |
michael@0 | 380 | if (variantEastAsian) { |
michael@0 | 381 | AddFontFeaturesBitmask(variantEastAsian, |
michael@0 | 382 | NS_FONT_VARIANT_EAST_ASIAN_JIS78, |
michael@0 | 383 | NS_FONT_VARIANT_EAST_ASIAN_RUBY, |
michael@0 | 384 | eastAsianDefaults, aStyle->featureSettings); |
michael@0 | 385 | } |
michael@0 | 386 | |
michael@0 | 387 | // -- ligatures |
michael@0 | 388 | if (variantLigatures) { |
michael@0 | 389 | AddFontFeaturesBitmask(variantLigatures, |
michael@0 | 390 | NS_FONT_VARIANT_LIGATURES_NONE, |
michael@0 | 391 | NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL, |
michael@0 | 392 | ligDefaults, aStyle->featureSettings); |
michael@0 | 393 | |
michael@0 | 394 | if (variantLigatures & NS_FONT_VARIANT_LIGATURES_COMMON) { |
michael@0 | 395 | // liga already enabled, need to enable clig also |
michael@0 | 396 | setting.mTag = TRUETYPE_TAG('c','l','i','g'); |
michael@0 | 397 | setting.mValue = 1; |
michael@0 | 398 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 399 | } else if (variantLigatures & NS_FONT_VARIANT_LIGATURES_NO_COMMON) { |
michael@0 | 400 | // liga already disabled, need to disable clig also |
michael@0 | 401 | setting.mTag = TRUETYPE_TAG('c','l','i','g'); |
michael@0 | 402 | setting.mValue = 0; |
michael@0 | 403 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 404 | } else if (variantLigatures & NS_FONT_VARIANT_LIGATURES_NONE) { |
michael@0 | 405 | // liga already disabled, need to disable dlig, hlig, calt, clig |
michael@0 | 406 | setting.mValue = 0; |
michael@0 | 407 | setting.mTag = TRUETYPE_TAG('d','l','i','g'); |
michael@0 | 408 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 409 | setting.mTag = TRUETYPE_TAG('h','l','i','g'); |
michael@0 | 410 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 411 | setting.mTag = TRUETYPE_TAG('c','a','l','t'); |
michael@0 | 412 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 413 | setting.mTag = TRUETYPE_TAG('c','l','i','g'); |
michael@0 | 414 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 415 | } |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | // -- numeric |
michael@0 | 419 | if (variantNumeric) { |
michael@0 | 420 | AddFontFeaturesBitmask(variantNumeric, |
michael@0 | 421 | NS_FONT_VARIANT_NUMERIC_LINING, |
michael@0 | 422 | NS_FONT_VARIANT_NUMERIC_ORDINAL, |
michael@0 | 423 | numericDefaults, aStyle->featureSettings); |
michael@0 | 424 | } |
michael@0 | 425 | |
michael@0 | 426 | // -- position |
michael@0 | 427 | setting.mTag = 0; |
michael@0 | 428 | setting.mValue = 1; |
michael@0 | 429 | switch (variantPosition) { |
michael@0 | 430 | case NS_FONT_VARIANT_POSITION_SUPER: |
michael@0 | 431 | setting.mTag = TRUETYPE_TAG('s','u','p','s'); |
michael@0 | 432 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 433 | break; |
michael@0 | 434 | |
michael@0 | 435 | case NS_FONT_VARIANT_POSITION_SUB: |
michael@0 | 436 | setting.mTag = TRUETYPE_TAG('s','u','b','s'); |
michael@0 | 437 | aStyle->featureSettings.AppendElement(setting); |
michael@0 | 438 | break; |
michael@0 | 439 | |
michael@0 | 440 | default: |
michael@0 | 441 | break; |
michael@0 | 442 | } |
michael@0 | 443 | |
michael@0 | 444 | // add in features from font-feature-settings |
michael@0 | 445 | aStyle->featureSettings.AppendElements(fontFeatureSettings); |
michael@0 | 446 | |
michael@0 | 447 | // enable grayscale antialiasing for text |
michael@0 | 448 | if (smoothing == NS_FONT_SMOOTHING_GRAYSCALE) { |
michael@0 | 449 | aStyle->useGrayscaleAntialiasing = true; |
michael@0 | 450 | } |
michael@0 | 451 | } |
michael@0 | 452 | |
michael@0 | 453 | static bool FontEnumCallback(const nsString& aFamily, bool aGeneric, void *aData) |
michael@0 | 454 | { |
michael@0 | 455 | *((nsString*)aData) = aFamily; |
michael@0 | 456 | return false; |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | void nsFont::GetFirstFamily(nsString& aFamily) const |
michael@0 | 460 | { |
michael@0 | 461 | EnumerateFamilies(FontEnumCallback, &aFamily); |
michael@0 | 462 | } |
michael@0 | 463 | |
michael@0 | 464 | /*static*/ |
michael@0 | 465 | void nsFont::GetGenericID(const nsString& aGeneric, uint8_t* aID) |
michael@0 | 466 | { |
michael@0 | 467 | *aID = kGenericFont_NONE; |
michael@0 | 468 | if (aGeneric.LowerCaseEqualsLiteral("-moz-fixed")) *aID = kGenericFont_moz_fixed; |
michael@0 | 469 | else if (aGeneric.LowerCaseEqualsLiteral("serif")) *aID = kGenericFont_serif; |
michael@0 | 470 | else if (aGeneric.LowerCaseEqualsLiteral("sans-serif")) *aID = kGenericFont_sans_serif; |
michael@0 | 471 | else if (aGeneric.LowerCaseEqualsLiteral("cursive")) *aID = kGenericFont_cursive; |
michael@0 | 472 | else if (aGeneric.LowerCaseEqualsLiteral("fantasy")) *aID = kGenericFont_fantasy; |
michael@0 | 473 | else if (aGeneric.LowerCaseEqualsLiteral("monospace")) *aID = kGenericFont_monospace; |
michael@0 | 474 | } |