/* -*- Mode: C++; tab-width: 20; 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"nsFontMetrics.h" #include <math.h> // for floor, ceil #include <algorithm> // for max #include"gfxContext.h"// for gfxContext #include"gfxFontConstants.h"// for NS_FONT_SYNTHESIS_* #include"gfxPlatform.h"// for gfxPlatform #include"gfxPoint.h"// for gfxPoint #include"gfxRect.h"// for gfxRect #include"gfxTextRun.h"// for gfxFontGroup #include"gfxTypes.h"// for gfxFloat #include"nsAtom.h"// for nsAtom #include"nsBoundingMetrics.h"// for nsBoundingMetrics #include"nsDebug.h"// for NS_ERROR #include"nsDeviceContext.h"// for nsDeviceContext #include"nsMathUtils.h"// for NS_round #include"nsPresContext.h"// for nsPresContext #include"nsString.h"// for nsString #include"nsStyleConsts.h"// for StyleHyphens::None #include"mozilla/Assertions.h"// for MOZ_ASSERT #include"mozilla/UniquePtr.h"// for UniquePtr
class gfxUserFontSet; usingnamespace mozilla;
namespace {
class AutoTextRun { public: typedef mozilla::gfx::DrawTarget DrawTarget;
private: static gfx::ShapedTextFlags ComputeFlags(const nsFontMetrics* aMetrics) {
gfx::ShapedTextFlags flags = gfx::ShapedTextFlags(); if (aMetrics->GetTextRunRTL()) {
flags |= gfx::ShapedTextFlags::TEXT_IS_RTL;
} if (aMetrics->GetVertical()) { switch (aMetrics->GetTextOrientation()) { case StyleTextOrientation::Mixed:
flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED; break; case StyleTextOrientation::Upright:
flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT; break; case StyleTextOrientation::Sideways:
flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT; break;
}
} return flags;
}
RefPtr<gfxTextRun> mTextRun;
};
class StubPropertyProvider final : public gfxTextRun::PropertyProvider { public: void GetHyphenationBreaks(
gfxTextRun::Range aRange,
gfxTextRun::HyphenType* aBreakBefore) const override {
NS_ERROR( "This shouldn't be called because we never call BreakAndMeasureText");
}
mozilla::StyleHyphens GetHyphensOption() const override {
NS_ERROR( "This shouldn't be called because we never call BreakAndMeasureText"); return mozilla::StyleHyphens::None;
}
gfxFloat GetHyphenWidth() const override {
NS_ERROR("This shouldn't be called because we never enable hyphens"); return 0;
}
already_AddRefed<mozilla::gfx::DrawTarget> GetDrawTarget() const override {
NS_ERROR("This shouldn't be called because we never enable hyphens"); return nullptr;
}
uint32_t GetAppUnitsPerDevUnit() const override {
NS_ERROR("This shouldn't be called because we never enable hyphens"); return 60;
} void GetSpacing(gfxTextRun::Range aRange, Spacing* aSpacing) const override {
NS_ERROR("This shouldn't be called because we never enable spacing");
}
gfx::ShapedTextFlags GetShapedTextFlags() const override {
NS_ERROR("This shouldn't be called because we never enable hyphens"); return gfx::ShapedTextFlags();
}
};
nsFontMetrics::~nsFontMetrics() { // Should not be dropped by stylo
MOZ_ASSERT(NS_IsMainThread()); if (mPresContext) {
mPresContext->FontMetricsDeleted(this);
}
}
// GetMaxAscent/GetMaxDescent/GetMaxHeight must contain the // text-decoration lines drawable area. See bug 421353. // BE CAREFUL for rounding each values. The logic MUST be same as // nsCSSRendering::GetTextDecorationRectInternal's.
nscoord nsFontMetrics::AveCharWidth() const { // Use CEIL instead of ROUND for consistency with GetMaxAdvance return CEIL_TO_TWIPS(GetMetrics(this).aveCharWidth);
}
nscoord nsFontMetrics::SpaceWidth() const { // For vertical text with mixed or sideways orientation, we want the // width of a horizontal space (even if we're using vertical line-spacing // metrics, as with "writing-mode:vertical-*;text-orientation:mixed"). return CEIL_TO_TWIPS(
GetMetrics(this,
mVertical && mTextOrientation == StyleTextOrientation::Upright
? eVertical
: eHorizontal)
.spaceWidth);
}
int32_t nsFontMetrics::GetMaxStringLength() const { constdouble x = 32767.0 / std::max(1.0, GetMetrics(this).maxAdvance);
int32_t len = (int32_t)floor(x); return std::max(1, len);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.