Files
palemoon27/gfx/src/nsFont.cpp
T
roytam1 e4c23c8471 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 966986 - Part 1: Fix format of DataTransfer.getData(text/x-moz-url) and return each text and URL as a separated item on Mac. r=smichaud, vlad (4de2b9ee3f)
- Bug 966986 - Part 2: Return true from nsDragService::IsDataFlavorSupported for text/x-moz-url-desc and text/x-moz-url-data on Mac. r=smichaud, vlad (210fb284cc)
- Bug 1167834 - Fix -Wwritable-strings warnings in widget/cocoa/. r=smichaud (933fa44bb4)
- Bug 1206766 - Show meaningful module offsets in stack traces even when no symbol found. r=spohl (406e2019dc)
- Bug 1205399 - Remove some leftover Growl strings. r=mstange (44dd51e2cd)
- Bug 1205399 - OS X: Implement disabling Notifications for the site from the native notifications. r=mstange (4c5c3c3c41)
- Bug 1208685 - Dedupe alert.css and cleanup alert.js heading. r=bgrins (669f2f5347)
- Bug 1208295 - Show an additional action on OS X notifications to open notification settings. r=mstange (4562ca98f5)
- Bug 935434 - Make XUL alertNotifcations use dir/bidi parameter by setting the according css direction attribute. Set lang attribute for labels. r=jaws (0e1e045f28)
- Bug 1202933, Part 1 - Show the origin for XUL notifications. r=MattN,wchen (836ca78e53)
- Bug 1202933, Part 2 - Show the origin for OS X notifications. r=MattN,wchen (468b702443)
- Bug 1201397 - New layout of XUL Notifications. r=MattN (1133670c5d)
- Bug 1209602 - XUL: Implement disabling notifications for a site. r=MattN (980f441952)
- Bug 1218315 - Replace NS_LITERAL_STRING(...).get() with MOZ_UTF16(...) on widget. r=nfroyd (4605f28ee6)
- Bug 1221449: Add null ptr check and fix variable shadowing in OSXNotificationCenter.mm. r=spohl (6064ea34ec)
- Bug 1052776 - fix role=alert usage and ensure alert events fire, r=MattN (45cb398d87)
- Bug 1217621 - Show settings action for XUL notifications. r=jaws (9cb70137c2)
- Bug 1205172 - Do Not Disturb Button for Push Notifications on Windows. r=MattN (16b068c676)
- Bug 1219458 - Remove the notification animation until we have better transparency support. r=MattN (bcd89030e2)
- Bug 1214029 - Use double-quotes for strings in alert.js. r=MattN (a8b2a60ab6)
- Bug 1213421 - Truncate long body and title text in notifications. r=MattN (b91c55cb1b)
- Bug 1213421 - Follow-up, set the bodyText even when text is not being truncated. r=MattN (47212a10ca)
- Bug 1216161 - XUL notifications on Linux can't be closed. r=MattN (0ad4abe149)
- Bug 1218781 - Padding on the right side of notifications is missing when an icon is supplied. r=MattN (b0661b491c)
- Bug 1218785 - Remove top and bottom margins on images in notifications. r=MattN (fb5f74249c)
- Bug 1218780 - Notifications shouldn't use a hand cursor. r=MattN (be6da71ee0)
- Bug 1218789 - Close button and gear button are misaligned in notifications. r=MattN (a6d684f008)
- fix misspatch (e9a9840e80)
- Bug 1148933 - Remove old storageservice.js and tests. r=gps (6308b7230f)
- reorder (2095058419)
- Don't mix GPU adapters across processes. (bug 1183910 part 10, r=jmuizelaar) (fa313da63d)
- Don't attempt to use WARP after D3D11CreateDevice crashes. (bug 1201202, r=bas) (10d8424a75)
- Bug 1207437 (part 1) - Don't recompute Windows feature levels. r=dvander. (0b0d3c11a1)
- Bug 1207437 (part 2) - Don't re-get D3D11CreateDevice. r=dvander. It's always obtained during gfxWindowPlatform initialization and put into sD3D11CreateDeviceFn. (db99647c33)
- Bug 1207437 (part 3) - Fix and disallow warnings in gfx/thebes/. r=dvander. (4cf28c971d)
- Bug 1207437 - Extra qualification fixup. (05ab331aaa)
- Search for a matching DXGI adapter in content processes. (bug 1225283 part 2, r=jrmuizel) (c1f715dd91)
- Add IPC helpers to marshal DXGI_ADAPTER_DESC. (bug 1225283 part 1, r=mattwoodrow) (932804aab6)
- Bug 1208465 - Part 1: Fix some reftest annotations. r=jrmuizel (725601b236)
- Bug 1208465 - Part 2: Disable using Direct2D when 1.1 is unavailable. r=jrmuizel (2ad1fc80bd)
- Bug 1196335 - Disambiguate the strings for scoped gfx reporter and D2D1.1. r=dvander (0cb2c1534c)
- Bug 1222569 - fix -Wformat warning in gfxWindowsPlatform.cpp; r=Bas (95f339a567)
- Bug 1195844: When checking for old DisplayLink versions, look for a few other DLLs. r=jrmuizel (8a316e876f)
- Bug 1197296. Check for errors more during bug testing. r=Bas (21405bfe27)
- Don't assume D3D11CreateDevice() gives back non-null devices. (bug 1209268, r=milan) (7208b1e52d)
- Bug 1222569 - fix initialization order in gfxWindowsPlatform.cpp; r=Bas (530f2510b7)
- Don't use Direct 2D 1.0 if Direct3D11 is using WARP. (bug 1207665 part 2, r=jmuizelaar) (a6f6aef92a)
- Bug 1207258 - Give back the ability to run direct write without D2D, but only with a *force* preference. r=dvander (283454081b)
- Bug 1097321 - Fix DoesD3D11TextureSharingWorkInternal to handle Intel/AMD configurations. r=Bas (efa1d2eeef)
- Bug 1223002 - Always call ReleaseGrFace to balance GetGrFace, even if the face is null. r=jdaggett (06cb8447ba)
- Bug 1225125: If all drawing is just clipped out anyway, just push a regular group, blending mode won't matter. r=jrmuizel (78a90991d4)
- Bug 1223440 - Implement NativePanZoomController::setIsLongpressEnabled so long-press detection can be disabled during testing. r=kats (b8e31ab26a)
- Bug 1202050 - Use UntransformTo in a few more places in APZ code. r=botond (6c43dda3c3)
- Bug 1228501 patch 1 - Remove decorations parameter to nsFont constructors. r=jdaggett (ea43ab6167)
- Bug 1228501 patch 2 - Remove nsFont::decorations member variable. r=jdaggett (57f9cc2520)
- Bug 1228501 patch 3 - Remove nsFont::BaseEquals. r=jdaggett BaseEquals and Equals were made the same by patch 2, so BaseEquals can be removed. (925a469540)
- Bug 576927 - Use saturating multiply when calculating zoomed app units to avoid integer overflow. r=roc (ab0caaa9c7)
- Bug 1228501 patch 4 - Remove nsStyleFont::CalcFontDifference, which now duplicates the list of tests in nsFont::Equals. r=jdaggett (46523eaf4c)
- Bug 1228501 patch 5 - Remove NS_FONT_DECORATION_* constants. r=jdaggett Decorations in Gecko are associated with the CSS 'text-decoration' property, so the constants should live in nsStyleConsts.h, as they largely already do (since the names defined there are the vast majority of the uses). (2895dfb610)
2023-02-22 08:19:53 +08:00

322 lines
10 KiB
C++

/* -*- Mode: C++; tab-width: 2; 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/. */
#include "nsFont.h"
#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"
#include "nsUnicharUtils.h"
#include "nscore.h" // for char16_t
#include "mozilla/ArrayUtils.h"
#include "mozilla/gfx/2D.h"
using namespace mozilla;
nsFont::nsFont(const FontFamilyList& aFontlist, uint8_t aStyle,
uint16_t aWeight, int16_t aStretch, nscoord aSize)
: fontlist(aFontlist)
{
Init();
style = aStyle;
weight = aWeight;
stretch = aStretch;
size = aSize;
}
nsFont::nsFont(FontFamilyType aGenericType, uint8_t aStyle,
uint16_t aWeight, int16_t aStretch, nscoord aSize)
: fontlist(aGenericType)
{
Init();
style = aStyle;
weight = aWeight;
stretch = aStretch;
size = aSize;
}
void
nsFont::Init()
{
systemFont = false;
smoothing = NS_FONT_SMOOTHING_AUTO;
sizeAdjust = -1.0f;
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;
}
nsFont::nsFont(const nsFont& aOther)
: fontlist(aOther.fontlist)
{
style = aOther.style;
systemFont = aOther.systemFont;
weight = aOther.weight;
stretch = aOther.stretch;
smoothing = aOther.smoothing;
size = aOther.size;
sizeAdjust = aOther.sizeAdjust;
kerning = aOther.kerning;
synthesis = aOther.synthesis;
fontFeatureSettings = aOther.fontFeatureSettings;
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;
}
nsFont::nsFont()
{
}
nsFont::~nsFont()
{
}
bool nsFont::Equals(const nsFont& aOther) const
{
if ((style == aOther.style) &&
(systemFont == aOther.systemFont) &&
(weight == aOther.weight) &&
(stretch == aOther.stretch) &&
(size == aOther.size) &&
(sizeAdjust == aOther.sizeAdjust) &&
(fontlist == aOther.fontlist) &&
(kerning == aOther.kerning) &&
(synthesis == aOther.synthesis) &&
(fontFeatureSettings == aOther.fontFeatureSettings) &&
(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) &&
(smoothing == aOther.smoothing)) {
return true;
}
return false;
}
nsFont& nsFont::operator=(const nsFont& aOther)
{
fontlist = aOther.fontlist;
style = aOther.style;
systemFont = aOther.systemFont;
weight = aOther.weight;
stretch = aOther.stretch;
smoothing = aOther.smoothing;
size = aOther.size;
sizeAdjust = aOther.sizeAdjust;
kerning = aOther.kerning;
synthesis = aOther.synthesis;
fontFeatureSettings = aOther.fontFeatureSettings;
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;
return *this;
}
void
nsFont::CopyAlternates(const nsFont& aOther)
{
variantAlternates = aOther.variantAlternates;
alternateValues = aOther.alternateValues;
featureValueLookup = aOther.featureValueLookup;
}
// 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 }
};
static_assert(MOZ_ARRAY_LENGTH(eastAsianDefaults) ==
eFeatureEastAsian_numFeatures,
"eFeatureEastAsian_numFeatures should be correct");
// NS_FONT_VARIANT_LIGATURES_xxx values
const gfxFontFeature ligDefaults[] = {
{ TRUETYPE_TAG('l','i','g','a'), 0 }, // none value means all off
{ 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 }
};
static_assert(MOZ_ARRAY_LENGTH(ligDefaults) ==
eFeatureLigatures_numFeatures,
"eFeatureLigatures_numFeatures should be correct");
// 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 }
};
static_assert(MOZ_ARRAY_LENGTH(numericDefaults) ==
eFeatureNumeric_numFeatures,
"eFeatureNumeric_numFeatures should be correct");
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
aStyle->variantCaps = variantCaps;
// -- 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,
NS_FONT_VARIANT_LIGATURES_NONE,
NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL,
ligDefaults, aStyle->featureSettings);
if (variantLigatures & NS_FONT_VARIANT_LIGATURES_COMMON) {
// liga already enabled, need to enable clig also
setting.mTag = TRUETYPE_TAG('c','l','i','g');
setting.mValue = 1;
aStyle->featureSettings.AppendElement(setting);
} else if (variantLigatures & NS_FONT_VARIANT_LIGATURES_NO_COMMON) {
// liga already disabled, need to disable clig also
setting.mTag = TRUETYPE_TAG('c','l','i','g');
setting.mValue = 0;
aStyle->featureSettings.AppendElement(setting);
} 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);
}
}
// -- numeric
if (variantNumeric) {
AddFontFeaturesBitmask(variantNumeric,
NS_FONT_VARIANT_NUMERIC_LINING,
NS_FONT_VARIANT_NUMERIC_ORDINAL,
numericDefaults, aStyle->featureSettings);
}
// -- position
aStyle->variantSubSuper = variantPosition;
// indicate common-path case when neither variantCaps or variantSubSuper are set
aStyle->noFallbackVariantFeatures =
(aStyle->variantCaps == NS_FONT_VARIANT_CAPS_NORMAL) &&
(variantPosition == NS_FONT_VARIANT_POSITION_NORMAL);
// add in features from font-feature-settings
aStyle->featureSettings.AppendElements(fontFeatureSettings);
// enable grayscale antialiasing for text
if (smoothing == NS_FONT_SMOOTHING_GRAYSCALE) {
aStyle->useGrayscaleAntialiasing = true;
}
}