Bug 857142 - implement -moz-font-smoothing. r=dbaron

This commit is contained in:
John Daggett 2013-07-29 17:33:35 +09:00
Родитель 965c4e2b47
Коммит 8b8b4b7b5f
15 изменённых файлов: 74 добавлений и 3 удалений

Просмотреть файл

@ -22,6 +22,7 @@ nsFont::nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
weight = aWeight;
stretch = aStretch;
decorations = aDecoration;
smoothing = NS_FONT_SMOOTHING_AUTO;
size = aSize;
sizeAdjust = 0.0;
kerning = NS_FONT_KERNING_AUTO;
@ -46,6 +47,7 @@ nsFont::nsFont(const nsSubstring& aName, uint8_t aStyle, uint8_t aVariant,
weight = aWeight;
stretch = aStretch;
decorations = aDecoration;
smoothing = NS_FONT_SMOOTHING_AUTO;
size = aSize;
sizeAdjust = 0.0;
kerning = NS_FONT_KERNING_AUTO;
@ -68,6 +70,7 @@ nsFont::nsFont(const nsFont& aOther)
weight = aOther.weight;
stretch = aOther.stretch;
decorations = aOther.decorations;
smoothing = aOther.smoothing;
size = aOther.size;
sizeAdjust = aOther.sizeAdjust;
kerning = aOther.kerning;
@ -122,7 +125,8 @@ bool nsFont::Equals(const nsFont& aOther) const
{
if (BaseEquals(aOther) &&
(variant == aOther.variant) &&
(decorations == aOther.decorations)) {
(decorations == aOther.decorations) &&
(smoothing == aOther.smoothing)) {
return true;
}
return false;
@ -137,6 +141,7 @@ nsFont& nsFont::operator=(const nsFont& aOther)
weight = aOther.weight;
stretch = aOther.stretch;
decorations = aOther.decorations;
smoothing = aOther.smoothing;
size = aOther.size;
sizeAdjust = aOther.sizeAdjust;
kerning = aOther.kerning;
@ -416,6 +421,11 @@ void nsFont::AddFontFeaturesToStyle(gfxFontStyle *aStyle) const
// add in features from font-feature-settings
aStyle->featureSettings.AppendElements(fontFeatureSettings);
// enable grayscale antialiasing for text
if (smoothing == NS_FONT_SMOOTHING_ANTIALIASED) {
aStyle->useGrayscaleAntialiasing = true;
}
}
static bool FontEnumCallback(const nsString& aFamily, bool aGeneric, void *aData)

Просмотреть файл

@ -71,6 +71,9 @@ struct NS_GFX nsFont {
// line-through). The decorations can be binary or'd together.
uint8_t decorations;
// Smoothing - controls subpixel-antialiasing (currently OSX only)
uint8_t smoothing;
// The weight of the font; see gfxFontConstants.h.
uint16_t weight;

Просмотреть файл

@ -5012,7 +5012,7 @@ gfxFontStyle::gfxFontStyle() :
size(DEFAULT_PIXEL_FONT_SIZE), sizeAdjust(0.0f),
languageOverride(NO_FONT_LANGUAGE_OVERRIDE),
weight(NS_FONT_WEIGHT_NORMAL), stretch(NS_FONT_STRETCH_NORMAL),
systemFont(true), printerFont(false),
systemFont(true), printerFont(false), useGrayscaleAntialiasing(false),
style(NS_FONT_STYLE_NORMAL)
{
}
@ -5027,7 +5027,7 @@ gfxFontStyle::gfxFontStyle(uint8_t aStyle, uint16_t aWeight, int16_t aStretch,
languageOverride(ParseFontLanguageOverride(aLanguageOverride)),
weight(aWeight), stretch(aStretch),
systemFont(aSystemFont), printerFont(aPrinterFont),
style(aStyle)
useGrayscaleAntialiasing(false), style(aStyle)
{
MOZ_ASSERT(!mozilla::IsNaN(size));
MOZ_ASSERT(!mozilla::IsNaN(sizeAdjust));
@ -5058,6 +5058,7 @@ gfxFontStyle::gfxFontStyle(const gfxFontStyle& aStyle) :
languageOverride(aStyle.languageOverride),
weight(aStyle.weight), stretch(aStyle.stretch),
systemFont(aStyle.systemFont), printerFont(aStyle.printerFont),
useGrayscaleAntialiasing(aStyle.useGrayscaleAntialiasing),
style(aStyle.style)
{
featureSettings.AppendElements(aStyle.featureSettings);

Просмотреть файл

@ -127,6 +127,9 @@ struct gfxFontStyle {
// Say that this font is used for print or print preview.
bool printerFont : 1;
// Used to imitate -webkit-font-smoothing: antialiased
bool useGrayscaleAntialiasing : 1;
// The style of font (normal, italic, oblique)
uint8_t style : 2;
@ -153,6 +156,7 @@ struct gfxFontStyle {
(style == other.style) &&
(systemFont == other.systemFont) &&
(printerFont == other.printerFont) &&
(useGrayscaleAntialiasing == other.useGrayscaleAntialiasing) &&
(weight == other.weight) &&
(stretch == other.stretch) &&
(language == other.language) &&

Просмотреть файл

@ -30,6 +30,9 @@
#define NS_FONT_STRETCH_EXTRA_EXPANDED 3
#define NS_FONT_STRETCH_ULTRA_EXPANDED 4
#define NS_FONT_SMOOTHING_AUTO 0
#define NS_FONT_SMOOTHING_ANTIALIASED 1
#define NS_FONT_KERNING_AUTO 0
#define NS_FONT_KERNING_NONE 1
#define NS_FONT_KERNING_NORMAL 2

Просмотреть файл

@ -84,6 +84,8 @@ gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyl
if (mAdjustedSize <=
(gfxFloat)gfxPlatformMac::GetPlatform()->GetAntiAliasingThreshold()) {
cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_NONE);
} else if (mStyle.useGrayscaleAntialiasing) {
cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_GRAY);
}
mScaledFont = cairo_scaled_font_create(mFontFace, &sizeMatrix, &ctm,

Просмотреть файл

@ -169,6 +169,7 @@ CSS_KEY(alpha, alpha)
CSS_KEY(alternate, alternate)
CSS_KEY(alternate-reverse, alternate_reverse)
CSS_KEY(always, always)
CSS_KEY(antialiased, antialiased)
CSS_KEY(annotation, annotation)
CSS_KEY(appworkspace, appworkspace)
CSS_KEY(armenian, armenian)

Просмотреть файл

@ -1760,6 +1760,18 @@ CSS_PROP_FONT(
nullptr,
offsetof(nsStyleFont, mFont.sizeAdjust),
eStyleAnimType_float)
CSS_PROP_FONT(
-moz-font-smoothing,
font_smoothing,
CSS_PROP_DOMPROP_PREFIXED(FontSmoothing),
CSS_PROPERTY_PARSE_VALUE |
CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE |
CSS_PROPERTY_APPLIES_TO_PLACEHOLDER,
"",
VARIANT_HK,
kFontSmoothingKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
CSS_PROP_FONT(
font-stretch,
font_stretch,

Просмотреть файл

@ -1042,6 +1042,12 @@ const int32_t nsCSSProps::kFontSizeKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kFontSmoothingKTable[] = {
eCSSKeyword_auto, NS_FONT_SMOOTHING_AUTO,
eCSSKeyword_antialiased, NS_FONT_SMOOTHING_ANTIALIASED,
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kFontStretchKTable[] = {
eCSSKeyword_ultra_condensed, NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED,
eCSSKeyword_extra_condensed, NS_STYLE_FONT_STRETCH_EXTRA_CONDENSED,

Просмотреть файл

@ -481,6 +481,7 @@ public:
static const int32_t kFontKTable[];
static const int32_t kFontKerningKTable[];
static const int32_t kFontSizeKTable[];
static const int32_t kFontSmoothingKTable[];
static const int32_t kFontStretchKTable[];
static const int32_t kFontStyleKTable[];
static const int32_t kFontSynthesisKTable[];

Просмотреть файл

@ -1276,6 +1276,15 @@ nsComputedDOMStyle::DoGetFontSizeAdjust()
return val;
}
CSSValue*
nsComputedDOMStyle::DoGetFontSmoothing()
{
nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.smoothing,
nsCSSProps::kFontSmoothingKTable));
return val;
}
CSSValue*
nsComputedDOMStyle::DoGetFontStretch()
{
@ -5133,6 +5142,7 @@ nsComputedDOMStyle::GetQueryablePropertyMap(uint32_t* aLength)
COMPUTED_STYLE_MAP_ENTRY(float_edge, FloatEdge),
COMPUTED_STYLE_MAP_ENTRY(font_feature_settings, FontFeatureSettings),
COMPUTED_STYLE_MAP_ENTRY(font_language_override, FontLanguageOverride),
COMPUTED_STYLE_MAP_ENTRY(font_smoothing, FontSmoothing),
COMPUTED_STYLE_MAP_ENTRY(force_broken_image_icon, ForceBrokenImageIcon),
COMPUTED_STYLE_MAP_ENTRY(hyphens, Hyphens),
COMPUTED_STYLE_MAP_ENTRY(image_region, ImageRegion),

Просмотреть файл

@ -194,6 +194,7 @@ private:
mozilla::dom::CSSValue* DoGetFontLanguageOverride();
mozilla::dom::CSSValue* DoGetFontSize();
mozilla::dom::CSSValue* DoGetFontSizeAdjust();
mozilla::dom::CSSValue* DoGetFontSmoothing();
mozilla::dom::CSSValue* DoGetFontStretch();
mozilla::dom::CSSValue* DoGetFontStyle();
mozilla::dom::CSSValue* DoGetFontSynthesis();

Просмотреть файл

@ -3197,6 +3197,14 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
aFont->mGenericID = aGenericFontID;
}
// font-smoothing: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForFontSmoothing(),
aFont->mFont.smoothing, aCanStoreInRuleTree,
SETDSC_ENUMERATED,
aParentFont->mFont.smoothing,
defaultVariableFont->smoothing,
0, 0, 0, 0);
// font-style: enum, inherit, initial, -moz-system-font
SetDiscrete(*aRuleData->ValueForFontStyle(),
aFont->mFont.style, aCanStoreInRuleTree,

Просмотреть файл

@ -215,6 +215,7 @@ nsChangeHint nsStyleFont::CalcFontDifference(const nsFont& aFont1, const nsFont&
(aFont1.variant == aFont2.variant) &&
(aFont1.weight == aFont2.weight) &&
(aFont1.stretch == aFont2.stretch) &&
(aFont1.smoothing == aFont2.smoothing) &&
(aFont1.name == aFont2.name) &&
(aFont1.kerning == aFont2.kerning) &&
(aFont1.synthesis == aFont2.synthesis) &&

Просмотреть файл

@ -2466,6 +2466,14 @@ var gCSSProperties = {
other_values: [ "0.3", "0.5", "0.7" ],
invalid_values: []
},
"-moz-font-smoothing": {
domProp: "MozFontSmoothing",
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "auto" ],
other_values: [ "antialiased" ],
invalid_values: [ "none", "subpixel-antialiased" ]
},
"font-stretch": {
domProp: "fontStretch",
inherited: true,