Bug 1533428 - patch 2 - Move the Orientation enum from gfxFont to nsFontMetrics to enable some #include-elimination, in particular to avoid including gfxTextRun.h in nsFontMetrics.h. r=jwatt

Differential Revision: https://phabricator.services.mozilla.com/D22913

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jonathan Kew 2019-04-01 14:32:19 +00:00
Родитель 243b72de64
Коммит a978a2a32d
14 изменённых файлов: 105 добавлений и 83 удалений

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

@ -10,7 +10,7 @@
#include "nsCoreUtils.h" #include "nsCoreUtils.h"
#include "StyleInfo.h" #include "StyleInfo.h"
#include "gfxFont.h" #include "gfxTextRun.h"
#include "nsFontMetrics.h" #include "nsFontMetrics.h"
#include "nsLayoutUtils.h" #include "nsLayoutUtils.h"
#include "nsContainerFrame.h" #include "nsContainerFrame.h"

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

@ -16,7 +16,7 @@
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsLayoutUtils.h" #include "nsLayoutUtils.h"
#include "nsRange.h" #include "nsRange.h"
#include "gfxFont.h" #include "gfxTextRun.h"
#include "nsIAccessibleTypes.h" #include "nsIAccessibleTypes.h"
#include "mozilla/gfx/2D.h" #include "mozilla/gfx/2D.h"

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

@ -3744,7 +3744,8 @@ nsresult CanvasRenderingContext2D::DrawOrMeasureText(
processor.mFontgrp processor.mFontgrp
->UpdateUserFonts(); // ensure user font generation is current ->UpdateUserFonts(); // ensure user font generation is current
const gfxFont::Metrics& fontMetrics = const gfxFont::Metrics& fontMetrics =
processor.mFontgrp->GetFirstValidFont()->GetMetrics(gfxFont::eHorizontal); processor.mFontgrp->GetFirstValidFont()->GetMetrics(
nsFontMetrics::eHorizontal);
gfxFloat baselineAnchor; gfxFloat baselineAnchor;

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

@ -8,9 +8,9 @@
#include <algorithm> // for max #include <algorithm> // for max
#include "gfxASurface.h" // for gfxASurface, etc #include "gfxASurface.h" // for gfxASurface, etc
#include "gfxContext.h" #include "gfxContext.h"
#include "gfxFont.h" // for gfxFontGroup
#include "gfxImageSurface.h" // for gfxImageSurface #include "gfxImageSurface.h" // for gfxImageSurface
#include "gfxPoint.h" // for gfxSize #include "gfxPoint.h" // for gfxSize
#include "gfxTextRun.h" // for gfxFontGroup
#include "mozilla/Attributes.h" // for final #include "mozilla/Attributes.h" // for final
#include "mozilla/gfx/PathHelpers.h" #include "mozilla/gfx/PathHelpers.h"
#include "mozilla/gfx/PrintTarget.h" #include "mozilla/gfx/PrintTarget.h"

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

@ -11,6 +11,7 @@
#include "gfxPlatform.h" // for gfxPlatform #include "gfxPlatform.h" // for gfxPlatform
#include "gfxPoint.h" // for gfxPoint #include "gfxPoint.h" // for gfxPoint
#include "gfxRect.h" // for gfxRect #include "gfxRect.h" // for gfxRect
#include "gfxTextRun.h" // for gfxFontGroup
#include "gfxTypes.h" // for gfxFloat #include "gfxTypes.h" // for gfxFloat
#include "nsBoundingMetrics.h" // for nsBoundingMetrics #include "nsBoundingMetrics.h" // for nsBoundingMetrics
#include "nsDebug.h" // for NS_ERROR #include "nsDebug.h" // for NS_ERROR
@ -123,7 +124,7 @@ nsFontMetrics::nsFontMetrics(const nsFont& aFont, const Params& aParams,
aFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT, aFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT,
aFont.synthesis & NS_FONT_SYNTHESIS_STYLE, aFont.languageOverride); aFont.synthesis & NS_FONT_SYNTHESIS_STYLE, aFont.languageOverride);
aFont.AddFontFeaturesToStyle(&style, mOrientation == gfxFont::eVertical); aFont.AddFontFeaturesToStyle(&style, mOrientation == eVertical);
style.featureValueLookup = aParams.featureValueLookup; style.featureValueLookup = aParams.featureValueLookup;
aFont.AddFontVariationsToStyle(&style); aFont.AddFontVariationsToStyle(&style);
@ -148,36 +149,42 @@ void nsFontMetrics::Destroy() { mDeviceContext = nullptr; }
#define ROUND_TO_TWIPS(x) (nscoord) floor(((x)*mP2A) + 0.5) #define ROUND_TO_TWIPS(x) (nscoord) floor(((x)*mP2A) + 0.5)
#define CEIL_TO_TWIPS(x) (nscoord) ceil((x)*mP2A) #define CEIL_TO_TWIPS(x) (nscoord) ceil((x)*mP2A)
const gfxFont::Metrics& nsFontMetrics::GetMetrics( static const gfxFont::Metrics& GetMetrics(
gfxFont::Orientation aOrientation) const { nsFontMetrics* aFontMetrics, nsFontMetrics::FontOrientation aOrientation) {
return mFontGroup->GetFirstValidFont()->GetMetrics(aOrientation); return aFontMetrics->GetThebesFontGroup()->GetFirstValidFont()->GetMetrics(
aOrientation);
}
static const gfxFont::Metrics& GetMetrics(nsFontMetrics* aFontMetrics) {
return GetMetrics(aFontMetrics, aFontMetrics->Orientation());
} }
nscoord nsFontMetrics::XHeight() { nscoord nsFontMetrics::XHeight() {
return ROUND_TO_TWIPS(GetMetrics().xHeight); return ROUND_TO_TWIPS(GetMetrics(this).xHeight);
} }
nscoord nsFontMetrics::CapHeight() { nscoord nsFontMetrics::CapHeight() {
return ROUND_TO_TWIPS(GetMetrics().capHeight); return ROUND_TO_TWIPS(GetMetrics(this).capHeight);
} }
nscoord nsFontMetrics::SuperscriptOffset() { nscoord nsFontMetrics::SuperscriptOffset() {
return ROUND_TO_TWIPS(GetMetrics().emHeight * return ROUND_TO_TWIPS(GetMetrics(this).emHeight *
NS_FONT_SUPERSCRIPT_OFFSET_RATIO); NS_FONT_SUPERSCRIPT_OFFSET_RATIO);
} }
nscoord nsFontMetrics::SubscriptOffset() { nscoord nsFontMetrics::SubscriptOffset() {
return ROUND_TO_TWIPS(GetMetrics().emHeight * NS_FONT_SUBSCRIPT_OFFSET_RATIO); return ROUND_TO_TWIPS(GetMetrics(this).emHeight *
NS_FONT_SUBSCRIPT_OFFSET_RATIO);
} }
void nsFontMetrics::GetStrikeout(nscoord& aOffset, nscoord& aSize) { void nsFontMetrics::GetStrikeout(nscoord& aOffset, nscoord& aSize) {
aOffset = ROUND_TO_TWIPS(GetMetrics().strikeoutOffset); aOffset = ROUND_TO_TWIPS(GetMetrics(this).strikeoutOffset);
aSize = ROUND_TO_TWIPS(GetMetrics().strikeoutSize); aSize = ROUND_TO_TWIPS(GetMetrics(this).strikeoutSize);
} }
void nsFontMetrics::GetUnderline(nscoord& aOffset, nscoord& aSize) { void nsFontMetrics::GetUnderline(nscoord& aOffset, nscoord& aSize) {
aOffset = ROUND_TO_TWIPS(mFontGroup->GetUnderlineOffset()); aOffset = ROUND_TO_TWIPS(mFontGroup->GetUnderlineOffset());
aSize = ROUND_TO_TWIPS(GetMetrics().underlineSize); aSize = ROUND_TO_TWIPS(GetMetrics(this).underlineSize);
} }
// GetMaxAscent/GetMaxDescent/GetMaxHeight must contain the // GetMaxAscent/GetMaxDescent/GetMaxHeight must contain the
@ -198,45 +205,45 @@ static gfxFloat ComputeMaxAscent(const gfxFont::Metrics& aMetrics) {
} }
nscoord nsFontMetrics::InternalLeading() { nscoord nsFontMetrics::InternalLeading() {
return ROUND_TO_TWIPS(GetMetrics().internalLeading); return ROUND_TO_TWIPS(GetMetrics(this).internalLeading);
} }
nscoord nsFontMetrics::ExternalLeading() { nscoord nsFontMetrics::ExternalLeading() {
return ROUND_TO_TWIPS(GetMetrics().externalLeading); return ROUND_TO_TWIPS(GetMetrics(this).externalLeading);
} }
nscoord nsFontMetrics::EmHeight() { nscoord nsFontMetrics::EmHeight() {
return ROUND_TO_TWIPS(GetMetrics().emHeight); return ROUND_TO_TWIPS(GetMetrics(this).emHeight);
} }
nscoord nsFontMetrics::EmAscent() { nscoord nsFontMetrics::EmAscent() {
return ROUND_TO_TWIPS(GetMetrics().emAscent); return ROUND_TO_TWIPS(GetMetrics(this).emAscent);
} }
nscoord nsFontMetrics::EmDescent() { nscoord nsFontMetrics::EmDescent() {
return ROUND_TO_TWIPS(GetMetrics().emDescent); return ROUND_TO_TWIPS(GetMetrics(this).emDescent);
} }
nscoord nsFontMetrics::MaxHeight() { nscoord nsFontMetrics::MaxHeight() {
return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())) + return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics(this))) +
CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup)); CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(this), mFontGroup));
} }
nscoord nsFontMetrics::MaxAscent() { nscoord nsFontMetrics::MaxAscent() {
return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())); return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics(this)));
} }
nscoord nsFontMetrics::MaxDescent() { nscoord nsFontMetrics::MaxDescent() {
return CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup)); return CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(this), mFontGroup));
} }
nscoord nsFontMetrics::MaxAdvance() { nscoord nsFontMetrics::MaxAdvance() {
return CEIL_TO_TWIPS(GetMetrics().maxAdvance); return CEIL_TO_TWIPS(GetMetrics(this).maxAdvance);
} }
nscoord nsFontMetrics::AveCharWidth() { nscoord nsFontMetrics::AveCharWidth() {
// Use CEIL instead of ROUND for consistency with GetMaxAdvance // Use CEIL instead of ROUND for consistency with GetMaxAdvance
return CEIL_TO_TWIPS(GetMetrics().aveCharWidth); return CEIL_TO_TWIPS(GetMetrics(this).aveCharWidth);
} }
nscoord nsFontMetrics::SpaceWidth() { nscoord nsFontMetrics::SpaceWidth() {
@ -244,15 +251,15 @@ nscoord nsFontMetrics::SpaceWidth() {
// width of a horizontal space (even if we're using vertical line-spacing // width of a horizontal space (even if we're using vertical line-spacing
// metrics, as with "writing-mode:vertical-*;text-orientation:mixed"). // metrics, as with "writing-mode:vertical-*;text-orientation:mixed").
return CEIL_TO_TWIPS( return CEIL_TO_TWIPS(
GetMetrics(mVertical && GetMetrics(this, mVertical && mTextOrientation ==
mTextOrientation == NS_STYLE_TEXT_ORIENTATION_UPRIGHT NS_STYLE_TEXT_ORIENTATION_UPRIGHT
? gfxFont::eVertical ? eVertical
: gfxFont::eHorizontal) : eHorizontal)
.spaceWidth); .spaceWidth);
} }
int32_t nsFontMetrics::GetMaxStringLength() { int32_t nsFontMetrics::GetMaxStringLength() {
const gfxFont::Metrics& m = GetMetrics(); const gfxFont::Metrics& m = GetMetrics(this);
const double x = 32767.0 / std::max(1.0, m.maxAdvance); const double x = 32767.0 / std::max(1.0, m.maxAdvance);
int32_t len = (int32_t)floor(x); int32_t len = (int32_t)floor(x);
return std::max(1, len); return std::max(1, len);
@ -268,7 +275,7 @@ nscoord nsFontMetrics::GetWidth(const char* aString, uint32_t aLength,
AutoTextRun textRun(this, aDrawTarget, aString, aLength); AutoTextRun textRun(this, aDrawTarget, aString, aLength);
if (textRun.get()) { if (textRun.get()) {
return NSToCoordRound( return NSToCoordRound(
textRun->GetAdvanceWidth(Range(0, aLength), &provider)); textRun->GetAdvanceWidth(gfxTextRun::Range(0, aLength), &provider));
} }
return 0; return 0;
} }
@ -283,7 +290,7 @@ nscoord nsFontMetrics::GetWidth(const char16_t* aString, uint32_t aLength,
AutoTextRun textRun(this, aDrawTarget, aString, aLength); AutoTextRun textRun(this, aDrawTarget, aString, aLength);
if (textRun.get()) { if (textRun.get()) {
return NSToCoordRound( return NSToCoordRound(
textRun->GetAdvanceWidth(Range(0, aLength), &provider)); textRun->GetAdvanceWidth(gfxTextRun::Range(0, aLength), &provider));
} }
return 0; return 0;
} }
@ -299,7 +306,7 @@ void nsFontMetrics::DrawString(const char* aString, uint32_t aLength,
return; return;
} }
gfx::Point pt(aX, aY); gfx::Point pt(aX, aY);
Range range(0, aLength); gfxTextRun::Range range(0, aLength);
if (mTextRunRTL) { if (mTextRunRTL) {
if (mVertical) { if (mVertical) {
pt.y += textRun->GetAdvanceWidth(range, &provider); pt.y += textRun->GetAdvanceWidth(range, &provider);
@ -323,7 +330,7 @@ void nsFontMetrics::DrawString(const char16_t* aString, uint32_t aLength,
return; return;
} }
gfx::Point pt(aX, aY); gfx::Point pt(aX, aY);
Range range(0, aLength); gfxTextRun::Range range(0, aLength);
if (mTextRunRTL) { if (mTextRunRTL) {
if (mVertical) { if (mVertical) {
pt.y += textRun->GetAdvanceWidth(range, &provider); pt.y += textRun->GetAdvanceWidth(range, &provider);
@ -369,3 +376,7 @@ nsBoundingMetrics nsFontMetrics::GetInkBoundsForVisualOverflow(
return GetTextBoundingMetrics(this, aString, aLength, aDrawTarget, return GetTextBoundingMetrics(this, aString, aLength, aDrawTarget,
gfxFont::LOOSE_INK_EXTENTS); gfxFont::LOOSE_INK_EXTENTS);
} }
gfxUserFontSet* nsFontMetrics::GetUserFontSet() const {
return mFontGroup->GetUserFontSet();
}

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

@ -8,7 +8,6 @@
#include <stdint.h> // for uint32_t #include <stdint.h> // for uint32_t
#include <sys/types.h> // for int32_t #include <sys/types.h> // for int32_t
#include "gfxTextRun.h" // for gfxFont, gfxFontGroup
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
#include "mozilla/RefPtr.h" // for RefPtr #include "mozilla/RefPtr.h" // for RefPtr
#include "nsCOMPtr.h" // for nsCOMPtr #include "nsCOMPtr.h" // for nsCOMPtr
@ -19,12 +18,19 @@
#include "nscore.h" // for char16_t #include "nscore.h" // for char16_t
class gfxContext; class gfxContext;
class gfxFontGroup;
class gfxUserFontSet; class gfxUserFontSet;
class gfxTextPerfMetrics; class gfxTextPerfMetrics;
class nsDeviceContext; class nsDeviceContext;
class nsAtom; class nsAtom;
struct nsBoundingMetrics; struct nsBoundingMetrics;
namespace mozilla {
namespace gfx {
class DrawTarget;
} // namespace gfx
} // namespace mozilla
/** /**
* Font metrics * Font metrics
* *
@ -45,13 +51,14 @@ struct nsBoundingMetrics;
*/ */
class nsFontMetrics final { class nsFontMetrics final {
public: public:
typedef gfxTextRun::Range Range;
typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::DrawTarget DrawTarget;
enum FontOrientation { eHorizontal, eVertical };
struct MOZ_STACK_CLASS Params { struct MOZ_STACK_CLASS Params {
nsAtom* language = nullptr; nsAtom* language = nullptr;
bool explicitLanguage = false; bool explicitLanguage = false;
gfxFont::Orientation orientation = gfxFont::eHorizontal; FontOrientation orientation = eHorizontal;
gfxUserFontSet* userFontSet = nullptr; gfxUserFontSet* userFontSet = nullptr;
gfxTextPerfMetrics* textPerf = nullptr; gfxTextPerfMetrics* textPerf = nullptr;
gfxFontFeatureValueSet* featureValueLookup = nullptr; gfxFontFeatureValueSet* featureValueLookup = nullptr;
@ -184,7 +191,7 @@ class nsFontMetrics final {
/** /**
* Returns the orientation (horizontal/vertical) of these metrics. * Returns the orientation (horizontal/vertical) of these metrics.
*/ */
gfxFont::Orientation Orientation() const { return mOrientation; } FontOrientation Orientation() const { return mOrientation; }
int32_t GetMaxStringLength(); int32_t GetMaxStringLength();
@ -225,9 +232,7 @@ class nsFontMetrics final {
uint8_t GetTextOrientation() const { return mTextOrientation; } uint8_t GetTextOrientation() const { return mTextOrientation; }
gfxFontGroup* GetThebesFontGroup() const { return mFontGroup; } gfxFontGroup* GetThebesFontGroup() const { return mFontGroup; }
gfxUserFontSet* GetUserFontSet() const { gfxUserFontSet* GetUserFontSet() const;
return mFontGroup->GetUserFontSet();
}
int32_t AppUnitsPerDevPixel() const { return mP2A; } int32_t AppUnitsPerDevPixel() const { return mP2A; }
@ -235,13 +240,6 @@ class nsFontMetrics final {
// Private destructor, to discourage deletion outside of Release(): // Private destructor, to discourage deletion outside of Release():
~nsFontMetrics(); ~nsFontMetrics();
const gfxFont::Metrics& GetMetrics() const {
return GetMetrics(mOrientation);
}
const gfxFont::Metrics& GetMetrics(
const gfxFont::Orientation aFontOrientation) const;
nsFont mFont; nsFont mFont;
RefPtr<gfxFontGroup> mFontGroup; RefPtr<gfxFontGroup> mFontGroup;
RefPtr<nsAtom> mLanguage; RefPtr<nsAtom> mLanguage;
@ -253,7 +251,7 @@ class nsFontMetrics final {
// The font orientation (horizontal or vertical) for which these metrics // The font orientation (horizontal or vertical) for which these metrics
// have been initialized. This determines which line metrics (ascent and // have been initialized. This determines which line metrics (ascent and
// descent) they will return. // descent) they will return.
gfxFont::Orientation mOrientation; FontOrientation mOrientation;
// These fields may be set by clients to control the behavior of methods // These fields may be set by clients to control the behavior of methods
// like GetWidth and DrawString according to the writing mode, direction // like GetWidth and DrawString according to the writing mode, direction

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

@ -536,7 +536,8 @@ double gfxFontconfigFontEntry::GetAspect() {
s.size = 100.0; // pick large size to avoid possible hinting artifacts s.size = 100.0; // pick large size to avoid possible hinting artifacts
RefPtr<gfxFont> font = FindOrMakeFont(&s); RefPtr<gfxFont> font = FindOrMakeFont(&s);
if (font) { if (font) {
const gfxFont::Metrics& metrics = font->GetMetrics(gfxFont::eHorizontal); const gfxFont::Metrics& metrics =
font->GetMetrics(nsFontMetrics::eHorizontal);
// The factor of 0.1 ensures that xHeight is sane so fonts don't // The factor of 0.1 ensures that xHeight is sane so fonts don't
// become huge. Strictly ">" ensures that xHeight and emHeight are // become huge. Strictly ">" ensures that xHeight and emHeight are

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

@ -635,7 +635,7 @@ void gfxShapedText::SetMissingGlyph(uint32_t aIndex, uint32_t aChar,
details->mAdvance = 0; details->mAdvance = 0;
} else { } else {
gfxFloat width = gfxFloat width =
std::max(aFont->GetMetrics(gfxFont::eHorizontal).aveCharWidth, std::max(aFont->GetMetrics(nsFontMetrics::eHorizontal).aveCharWidth,
gfxFloat(gfxFontMissingGlyphs::GetDesiredMinWidth( gfxFloat(gfxFontMissingGlyphs::GetDesiredMinWidth(
aChar, mAppUnitsPerDevUnit))); aChar, mAppUnitsPerDevUnit)));
details->mAdvance = uint32_t(width * mAppUnitsPerDevUnit); details->mAdvance = uint32_t(width * mAppUnitsPerDevUnit);
@ -889,7 +889,7 @@ gfxFloat gfxFont::GetGlyphHAdvance(DrawTarget* aDrawTarget, uint16_t aGID) {
return GetGlyphWidth(aGID) / 65536.0; return GetGlyphWidth(aGID) / 65536.0;
} }
if (mFUnitsConvFactor < 0.0f) { if (mFUnitsConvFactor < 0.0f) {
GetMetrics(eHorizontal); GetMetrics(nsFontMetrics::eHorizontal);
} }
NS_ASSERTION(mFUnitsConvFactor >= 0.0f, NS_ASSERTION(mFUnitsConvFactor >= 0.0f,
"missing font unit conversion factor"); "missing font unit conversion factor");
@ -1970,7 +1970,7 @@ bool gfxFont::DrawMissingGlyph(const TextRunDrawParams& aRunParams,
Point pt(Float(ToDeviceUnits(aPt.x, aRunParams.devPerApp)), Point pt(Float(ToDeviceUnits(aPt.x, aRunParams.devPerApp)),
Float(ToDeviceUnits(aPt.y, aRunParams.devPerApp))); Float(ToDeviceUnits(aPt.y, aRunParams.devPerApp)));
Float advanceDevUnits = Float(ToDeviceUnits(advance, aRunParams.devPerApp)); Float advanceDevUnits = Float(ToDeviceUnits(advance, aRunParams.devPerApp));
Float height = GetMetrics(eHorizontal).maxAscent; Float height = GetMetrics(nsFontMetrics::eHorizontal).maxAscent;
// Horizontally center if drawing vertically upright with no sideways // Horizontally center if drawing vertically upright with no sideways
// transform. // transform.
Rect glyphRect = Rect glyphRect =
@ -2170,7 +2170,7 @@ void gfxFont::Draw(const gfxTextRun* aTextRun, uint32_t aStart, uint32_t aEnd,
// those if available. // those if available.
// [1] See http://www.microsoft.com/typography/otspec/base.htm // [1] See http://www.microsoft.com/typography/otspec/base.htm
if (aTextRun->UseCenterBaseline()) { if (aTextRun->UseCenterBaseline()) {
const Metrics& metrics = GetMetrics(eHorizontal); const Metrics& metrics = GetMetrics(nsFontMetrics::eHorizontal);
float baseAdj = (metrics.emAscent - metrics.emDescent) / 2; float baseAdj = (metrics.emAscent - metrics.emDescent) / 2;
baseline += baseAdj * aTextRun->GetAppUnitsPerDevUnit() * baselineDir; baseline += baseAdj * aTextRun->GetAppUnitsPerDevUnit() * baselineDir;
} }
@ -2411,14 +2411,15 @@ gfxFont::RunMetrics gfxFont::Measure(const gfxTextRun* aTextRun,
const int32_t appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit(); const int32_t appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit();
// Current position in appunits // Current position in appunits
gfxFont::Orientation orientation = Orientation orientation =
aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT
? eVertical ? nsFontMetrics::eVertical
: eHorizontal; : nsFontMetrics::eHorizontal;
const gfxFont::Metrics& fontMetrics = GetMetrics(orientation); const gfxFont::Metrics& fontMetrics = GetMetrics(orientation);
gfxFloat baselineOffset = 0; gfxFloat baselineOffset = 0;
if (aTextRun->UseCenterBaseline() && orientation == eHorizontal) { if (aTextRun->UseCenterBaseline() &&
orientation == nsFontMetrics::eHorizontal) {
// For a horizontal font being used in vertical writing mode with // For a horizontal font being used in vertical writing mode with
// text-orientation:mixed, the overall metrics we're accumulating // text-orientation:mixed, the overall metrics we're accumulating
// will be aimed at a center baseline. But this font's metrics were // will be aimed at a center baseline. But this font's metrics were
@ -2775,7 +2776,8 @@ void gfxFont::PostShapingFixup(DrawTarget* aDrawTarget, const char16_t* aText,
uint32_t aOffset, uint32_t aLength, uint32_t aOffset, uint32_t aLength,
bool aVertical, gfxShapedText* aShapedText) { bool aVertical, gfxShapedText* aShapedText) {
if (IsSyntheticBold()) { if (IsSyntheticBold()) {
const Metrics& metrics = GetMetrics(aVertical ? eVertical : eHorizontal); const Metrics& metrics = GetMetrics(aVertical ? nsFontMetrics::eVertical
: nsFontMetrics::eHorizontal);
if (metrics.maxAdvance > metrics.aveCharWidth) { if (metrics.maxAdvance > metrics.aveCharWidth) {
float synBoldOffset = GetSyntheticBoldOffset() * CalcXScale(aDrawTarget); float synBoldOffset = GetSyntheticBoldOffset() * CalcXScale(aDrawTarget);
aShapedText->AdjustAdvancesForSyntheticBold(synBoldOffset, aOffset, aShapedText->AdjustAdvancesForSyntheticBold(synBoldOffset, aOffset,
@ -3373,7 +3375,7 @@ void gfxFont::SetupGlyphExtents(DrawTarget* aDrawTarget, uint32_t aGlyphID,
aDrawTarget->GetGlyphRasterizationMetrics(sf, &glyphIndex, 1, &metrics); aDrawTarget->GetGlyphRasterizationMetrics(sf, &glyphIndex, 1, &metrics);
} }
const Metrics& fontMetrics = GetMetrics(eHorizontal); const Metrics& fontMetrics = GetMetrics(nsFontMetrics::eHorizontal);
int32_t appUnitsPerDevUnit = aExtents->GetAppUnitsPerDevUnit(); int32_t appUnitsPerDevUnit = aExtents->GetAppUnitsPerDevUnit();
if (!aNeedTight && metrics.mXBearing >= 0.0 && if (!aNeedTight && metrics.mXBearing >= 0.0 &&
metrics.mYBearing >= -fontMetrics.maxAscent && metrics.mYBearing >= -fontMetrics.maxAscent &&
@ -3818,9 +3820,11 @@ gfxFloat gfxFont::SynthesizeSpaceWidth(uint32_t aCh) {
case 0x2006: case 0x2006:
return GetAdjustedSize() / 6; // six-per-em space return GetAdjustedSize() / 6; // six-per-em space
case 0x2007: case 0x2007:
return GetMetrics(eHorizontal).ZeroOrAveCharWidth(); // figure space return GetMetrics(nsFontMetrics::eHorizontal)
.ZeroOrAveCharWidth(); // figure space
case 0x2008: case 0x2008:
return GetMetrics(eHorizontal).spaceWidth; // punctuation space return GetMetrics(nsFontMetrics::eHorizontal)
.spaceWidth; // punctuation space
case 0x2009: case 0x2009:
return GetAdjustedSize() / 5; // thin space return GetAdjustedSize() / 5; // thin space
case 0x200a: case 0x200a:

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

@ -34,11 +34,11 @@
#include "harfbuzz/hb.h" #include "harfbuzz/hb.h"
#include "mozilla/gfx/2D.h" #include "mozilla/gfx/2D.h"
#include "nsColor.h" #include "nsColor.h"
#include "nsFontMetrics.h"
#include "mozilla/ServoUtils.h" #include "mozilla/ServoUtils.h"
typedef struct _cairo cairo_t; typedef struct _cairo cairo_t;
typedef struct _cairo_scaled_font cairo_scaled_font_t; typedef struct _cairo_scaled_font cairo_scaled_font_t;
// typedef struct gr_face gr_face;
#ifdef DEBUG #ifdef DEBUG
# include <stdio.h> # include <stdio.h>
@ -1548,10 +1548,10 @@ class gfxFont {
} }
}; };
enum Orientation { eHorizontal, eVertical }; typedef nsFontMetrics::FontOrientation Orientation;
const Metrics& GetMetrics(Orientation aOrientation) { const Metrics& GetMetrics(Orientation aOrientation) {
if (aOrientation == eHorizontal) { if (aOrientation == nsFontMetrics::eHorizontal) {
return GetHorizontalMetrics(); return GetHorizontalMetrics();
} }
if (!mVerticalMetrics) { if (!mVerticalMetrics) {

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

@ -310,7 +310,8 @@ hb_position_t gfxHarfBuzzShaper::GetGlyphVAdvance(hb_codepoint_t glyph) const {
if (!mVmtxTable) { if (!mVmtxTable) {
// Must be a "vertical" font that doesn't actually have vertical metrics; // Must be a "vertical" font that doesn't actually have vertical metrics;
// use a fixed advance. // use a fixed advance.
return FloatToFixed(mFont->GetMetrics(gfxFont::eVertical).aveCharWidth); return FloatToFixed(
mFont->GetMetrics(nsFontMetrics::eVertical).aveCharWidth);
} }
NS_ASSERTION(mNumLongVMetrics > 0, NS_ASSERTION(mNumLongVMetrics > 0,
@ -473,7 +474,8 @@ void gfxHarfBuzzShaper::GetGlyphVOrigin(hb_codepoint_t aGlyph,
// Last resort, for non-sfnt fonts: get the horizontal metrics and // Last resort, for non-sfnt fonts: get the horizontal metrics and
// compute a default VOrg from their ascent and descent. // compute a default VOrg from their ascent and descent.
const gfxFont::Metrics &mtx = mFont->GetHorizontalMetrics(); const gfxFont::Metrics &mtx = mFont->GetHorizontalMetrics();
gfxFloat advance = mFont->GetMetrics(gfxFont::eVertical).aveCharWidth; gfxFloat advance =
mFont->GetMetrics(nsFontMetrics::eVertical).aveCharWidth;
gfxFloat ascent = mtx.emAscent; gfxFloat ascent = mtx.emAscent;
gfxFloat height = ascent + mtx.emDescent; gfxFloat height = ascent + mtx.emDescent;
// vOrigin that will place the glyph so that its origin is shifted // vOrigin that will place the glyph so that its origin is shifted

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

@ -1552,8 +1552,8 @@ bool gfxTextRun::SetSpaceGlyphIfSimple(gfxFont* aFont, uint32_t aCharIndex,
gfxFont::Orientation fontOrientation = gfxFont::Orientation fontOrientation =
(aOrientation & gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT) (aOrientation & gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT)
? gfxFont::eVertical ? nsFontMetrics::eVertical
: gfxFont::eHorizontal; : nsFontMetrics::eHorizontal;
uint32_t spaceWidthAppUnits = NS_lroundf( uint32_t spaceWidthAppUnits = NS_lroundf(
aFont->GetMetrics(fontOrientation).spaceWidth * mAppUnitsPerDevUnit); aFont->GetMetrics(fontOrientation).spaceWidth * mAppUnitsPerDevUnit);
if (!CompressedGlyph::IsSimpleAdvance(spaceWidthAppUnits)) { if (!CompressedGlyph::IsSimpleAdvance(spaceWidthAppUnits)) {
@ -2644,9 +2644,10 @@ gfxFloat gfxFontGroup::GetUnderlineOffset() {
if (!font) { if (!font) {
continue; continue;
} }
gfxFloat bad = font->GetMetrics(gfxFont::eHorizontal).underlineOffset; gfxFloat bad =
font->GetMetrics(nsFontMetrics::eHorizontal).underlineOffset;
gfxFloat first = GetFirstValidFont() gfxFloat first = GetFirstValidFont()
->GetMetrics(gfxFont::eHorizontal) ->GetMetrics(nsFontMetrics::eHorizontal)
.underlineOffset; .underlineOffset;
mUnderlineOffset = std::min(first, bad); mUnderlineOffset = std::min(first, bad);
return mUnderlineOffset; return mUnderlineOffset;
@ -2654,8 +2655,9 @@ gfxFloat gfxFontGroup::GetUnderlineOffset() {
} }
// no bad underline fonts, use the first valid font's metric // no bad underline fonts, use the first valid font's metric
mUnderlineOffset = mUnderlineOffset = GetFirstValidFont()
GetFirstValidFont()->GetMetrics(gfxFont::eHorizontal).underlineOffset; ->GetMetrics(nsFontMetrics::eHorizontal)
.underlineOffset;
} }
return mUnderlineOffset; return mUnderlineOffset;

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

@ -4564,8 +4564,8 @@ already_AddRefed<nsFontMetrics> nsLayoutUtils::GetFontMetricsForComputedStyle(
params.language = styleFont->mLanguage; params.language = styleFont->mLanguage;
params.explicitLanguage = styleFont->mExplicitLanguage; params.explicitLanguage = styleFont->mExplicitLanguage;
params.orientation = wm.IsVertical() && !wm.IsSideways() params.orientation = wm.IsVertical() && !wm.IsSideways()
? gfxFont::eVertical ? nsFontMetrics::eVertical
: gfxFont::eHorizontal; : nsFontMetrics::eHorizontal;
// pass the user font set object into the device context to // pass the user font set object into the device context to
// pass along to CreateFontGroup // pass along to CreateFontGroup
params.userFontSet = aPresContext->GetUserFontSet(); params.userFontSet = aPresContext->GetUserFontSet();
@ -9728,7 +9728,7 @@ already_AddRefed<nsFontMetrics> nsLayoutUtils::GetMetricsFor(
nsFont font = aStyleFont->mFont; nsFont font = aStyleFont->mFont;
font.size = aFontSize; font.size = aFontSize;
gfxFont::Orientation orientation = gfxFont::Orientation orientation =
aIsVertical ? gfxFont::eVertical : gfxFont::eHorizontal; aIsVertical ? nsFontMetrics::eVertical : nsFontMetrics::eHorizontal;
nsFontMetrics::Params params; nsFontMetrics::Params params;
params.language = aStyleFont->mLanguage; params.language = aStyleFont->mLanguage;
params.explicitLanguage = aStyleFont->mExplicitLanguage; params.explicitLanguage = aStyleFont->mExplicitLanguage;

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

@ -1725,8 +1725,8 @@ static gfxFont::Metrics GetFirstFontMetrics(gfxFontGroup* aFontGroup,
bool aVerticalMetrics) { bool aVerticalMetrics) {
if (!aFontGroup) return gfxFont::Metrics(); if (!aFontGroup) return gfxFont::Metrics();
gfxFont* font = aFontGroup->GetFirstValidFont(); gfxFont* font = aFontGroup->GetFirstValidFont();
return font->GetMetrics(aVerticalMetrics ? gfxFont::eVertical return font->GetMetrics(aVerticalMetrics ? nsFontMetrics::eVertical
: gfxFont::eHorizontal); : nsFontMetrics::eHorizontal);
} }
static nscoord GetSpaceWidthAppUnits(const gfxTextRun* aTextRun) { static nscoord GetSpaceWidthAppUnits(const gfxTextRun* aTextRun) {
@ -6416,8 +6416,9 @@ void nsTextFrame::PaintTextSelectionDecorations(
const auto kDecoration = rightUnderline ? StyleTextDecorationLine_OVERLINE const auto kDecoration = rightUnderline ? StyleTextDecorationLine_OVERLINE
: StyleTextDecorationLine_UNDERLINE; : StyleTextDecorationLine_UNDERLINE;
bool useVerticalMetrics = verticalRun && mTextRun->UseCenterBaseline(); bool useVerticalMetrics = verticalRun && mTextRun->UseCenterBaseline();
gfxFont::Metrics decorationMetrics(firstFont->GetMetrics( gfxFont::Metrics decorationMetrics(
useVerticalMetrics ? gfxFont::eVertical : gfxFont::eHorizontal)); firstFont->GetMetrics(useVerticalMetrics ? nsFontMetrics::eVertical
: nsFontMetrics::eHorizontal));
if (!useVerticalMetrics) { if (!useVerticalMetrics) {
// The potential adjustment from using gfxFontGroup::GetUnderlineOffset // The potential adjustment from using gfxFontGroup::GetUnderlineOffset
// is only valid for horizontal font metrics. // is only valid for horizontal font metrics.
@ -7351,8 +7352,9 @@ bool nsTextFrame::CombineSelectionUnderlineRect(nsPresContext* aPresContext,
WritingMode wm = GetWritingMode(); WritingMode wm = GetWritingMode();
bool verticalRun = wm.IsVertical(); bool verticalRun = wm.IsVertical();
bool useVerticalMetrics = verticalRun && !wm.IsSideways(); bool useVerticalMetrics = verticalRun && !wm.IsSideways();
const gfxFont::Metrics& metrics = firstFont->GetMetrics( const gfxFont::Metrics& metrics =
useVerticalMetrics ? gfxFont::eVertical : gfxFont::eHorizontal); firstFont->GetMetrics(useVerticalMetrics ? nsFontMetrics::eVertical
: nsFontMetrics::eHorizontal);
nsCSSRendering::DecorationRectParams params; nsCSSRendering::DecorationRectParams params;
params.ascent = aPresContext->AppUnitsToGfxUnits(mAscent); params.ascent = aPresContext->AppUnitsToGfxUnits(mAscent);

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

@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include "gfxContext.h" #include "gfxContext.h"
#include "gfxMathTable.h" #include "gfxMathTable.h"
#include "gfxTextRun.h"
using namespace mozilla; using namespace mozilla;