2004-12-01 22:27:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
#include "nsFontMetrics.h"
|
2013-09-01 22:21:01 +00:00
|
|
|
#include <math.h> // for floor, ceil
|
|
|
|
#include <algorithm> // for max
|
2014-06-19 07:08:55 +00:00
|
|
|
#include "gfxFontConstants.h" // for NS_FONT_SYNTHESIS_*
|
2013-09-01 22:21:01 +00:00
|
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
|
|
|
#include "gfxPoint.h" // for gfxPoint
|
|
|
|
#include "gfxRect.h" // for gfxRect
|
|
|
|
#include "gfxTypes.h" // for gfxFloat
|
|
|
|
#include "nsBoundingMetrics.h" // for nsBoundingMetrics
|
2015-02-09 22:34:50 +00:00
|
|
|
#include "nsDebug.h" // for NS_ERROR
|
2013-09-01 22:21:01 +00:00
|
|
|
#include "nsDeviceContext.h" // for nsDeviceContext
|
|
|
|
#include "nsIAtom.h" // for nsIAtom
|
|
|
|
#include "nsMathUtils.h" // for NS_round
|
|
|
|
#include "nsRenderingContext.h" // for nsRenderingContext
|
2015-02-09 22:34:50 +00:00
|
|
|
#include "nsString.h" // for nsString
|
2013-09-01 22:21:01 +00:00
|
|
|
#include "nsStyleConsts.h" // for NS_STYLE_HYPHENS_NONE
|
2015-02-09 22:34:50 +00:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT
|
2016-04-13 14:08:41 +00:00
|
|
|
#include "mozilla/UniquePtr.h" // for UniquePtr
|
2013-09-01 22:21:01 +00:00
|
|
|
|
|
|
|
class gfxUserFontSet;
|
2016-04-13 14:08:41 +00:00
|
|
|
using namespace mozilla;
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
namespace {
|
|
|
|
|
2011-12-06 12:39:18 +00:00
|
|
|
class AutoTextRun {
|
2011-04-08 01:05:26 +00:00
|
|
|
public:
|
2015-12-15 21:56:41 +00:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
|
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, DrawTarget* aDrawTarget,
|
2012-08-22 15:56:38 +00:00
|
|
|
const char* aString, int32_t aLength)
|
2011-12-06 12:39:18 +00:00
|
|
|
{
|
2016-04-19 16:13:28 +00:00
|
|
|
mTextRun = aMetrics->GetThebesFontGroup()->MakeTextRun(
|
2012-08-22 15:56:38 +00:00
|
|
|
reinterpret_cast<const uint8_t*>(aString), aLength,
|
2015-12-15 21:56:41 +00:00
|
|
|
aDrawTarget,
|
2011-04-08 01:05:26 +00:00
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
2014-12-22 16:35:54 +00:00
|
|
|
ComputeFlags(aMetrics),
|
2016-04-19 16:13:28 +00:00
|
|
|
nullptr);
|
2011-12-06 12:39:18 +00:00
|
|
|
}
|
2011-04-08 04:18:43 +00:00
|
|
|
|
2015-12-15 21:56:41 +00:00
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, DrawTarget* aDrawTarget,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* aString, int32_t aLength)
|
2011-12-06 12:39:18 +00:00
|
|
|
{
|
2016-04-19 16:13:28 +00:00
|
|
|
mTextRun = aMetrics->GetThebesFontGroup()->MakeTextRun(
|
2011-12-06 12:39:18 +00:00
|
|
|
aString, aLength,
|
2015-12-15 21:56:41 +00:00
|
|
|
aDrawTarget,
|
2011-04-08 01:05:26 +00:00
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
2014-12-22 16:35:54 +00:00
|
|
|
ComputeFlags(aMetrics),
|
2016-04-19 16:13:28 +00:00
|
|
|
nullptr);
|
2011-12-06 12:39:18 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 14:08:41 +00:00
|
|
|
gfxTextRun *get() { return mTextRun.get(); }
|
|
|
|
gfxTextRun *operator->() { return mTextRun.get(); }
|
2011-04-08 01:05:26 +00:00
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t ComputeFlags(nsFontMetrics* aMetrics) {
|
|
|
|
uint32_t flags = 0;
|
2011-04-08 15:32:29 +00:00
|
|
|
if (aMetrics->GetTextRunRTL()) {
|
2011-04-08 01:05:26 +00:00
|
|
|
flags |= gfxTextRunFactory::TEXT_IS_RTL;
|
|
|
|
}
|
2015-01-06 20:56:03 +00:00
|
|
|
if (aMetrics->GetVertical()) {
|
|
|
|
switch (aMetrics->GetTextOrientation()) {
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_MIXED:
|
|
|
|
flags |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_UPRIGHT:
|
|
|
|
flags |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
|
|
|
break;
|
2015-09-23 21:16:01 +00:00
|
|
|
case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS:
|
2015-01-06 20:56:03 +00:00
|
|
|
flags |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-08 01:05:26 +00:00
|
|
|
return flags;
|
|
|
|
}
|
2011-12-06 12:39:18 +00:00
|
|
|
|
2016-04-13 14:08:41 +00:00
|
|
|
UniquePtr<gfxTextRun> mTextRun;
|
2011-04-08 01:05:26 +00:00
|
|
|
};
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
class StubPropertyProvider : public gfxTextRun::PropertyProvider {
|
|
|
|
public:
|
2016-03-08 07:56:18 +00:00
|
|
|
virtual void GetHyphenationBreaks(gfxTextRun::Range aRange,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aBreakBefore) {
|
2011-04-08 04:18:43 +00:00
|
|
|
NS_ERROR("This shouldn't be called because we never call BreakAndMeasureText");
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual int8_t GetHyphensOption() {
|
2011-05-04 11:29:56 +00:00
|
|
|
NS_ERROR("This shouldn't be called because we never call BreakAndMeasureText");
|
|
|
|
return NS_STYLE_HYPHENS_NONE;
|
|
|
|
}
|
2011-04-08 04:18:43 +00:00
|
|
|
virtual gfxFloat GetHyphenWidth() {
|
|
|
|
NS_ERROR("This shouldn't be called because we never enable hyphens");
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-15 21:56:41 +00:00
|
|
|
virtual already_AddRefed<mozilla::gfx::DrawTarget> GetDrawTarget() {
|
2014-03-31 10:53:09 +00:00
|
|
|
NS_ERROR("This shouldn't be called because we never enable hyphens");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual uint32_t GetAppUnitsPerDevUnit() {
|
|
|
|
NS_ERROR("This shouldn't be called because we never enable hyphens");
|
|
|
|
return 60;
|
|
|
|
}
|
2016-03-08 07:56:18 +00:00
|
|
|
virtual void GetSpacing(gfxTextRun::Range aRange, Spacing* aSpacing) {
|
2011-04-08 04:18:43 +00:00
|
|
|
NS_ERROR("This shouldn't be called because we never enable spacing");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2011-04-08 04:18:43 +00:00
|
|
|
|
2016-03-17 02:12:27 +00:00
|
|
|
nsFontMetrics::nsFontMetrics(const nsFont& aFont, const Params& aParams,
|
|
|
|
nsDeviceContext *aContext)
|
|
|
|
: mFont(aFont)
|
|
|
|
, mLanguage(aParams.language)
|
|
|
|
, mDeviceContext(aContext)
|
|
|
|
, mP2A(aContext->AppUnitsPerDevPixel())
|
|
|
|
, mOrientation(aParams.orientation)
|
|
|
|
, mTextRunRTL(false)
|
|
|
|
, mVertical(false)
|
|
|
|
, mTextOrientation(0)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 15:32:29 +00:00
|
|
|
gfxFontStyle style(aFont.style,
|
|
|
|
aFont.weight,
|
|
|
|
aFont.stretch,
|
|
|
|
gfxFloat(aFont.size) / mP2A,
|
2016-03-21 03:59:36 +00:00
|
|
|
aParams.language,
|
|
|
|
aParams.explicitLanguage,
|
2011-04-08 15:32:29 +00:00
|
|
|
aFont.sizeAdjust,
|
|
|
|
aFont.systemFont,
|
|
|
|
mDeviceContext->IsPrinterSurface(),
|
2014-06-19 07:08:55 +00:00
|
|
|
aFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT,
|
|
|
|
aFont.synthesis & NS_FONT_SYNTHESIS_STYLE,
|
2011-04-08 15:32:29 +00:00
|
|
|
aFont.languageOverride);
|
|
|
|
|
2012-04-26 06:25:29 +00:00
|
|
|
aFont.AddFontFeaturesToStyle(&style);
|
|
|
|
|
2015-11-20 13:01:12 +00:00
|
|
|
gfxFloat devToCssSize = gfxFloat(mP2A) /
|
|
|
|
gfxFloat(mDeviceContext->AppUnitsPerCSSPixel());
|
2011-04-08 15:32:29 +00:00
|
|
|
mFontGroup = gfxPlatform::GetPlatform()->
|
2016-03-21 03:59:36 +00:00
|
|
|
CreateFontGroup(aFont.fontlist, &style, aParams.textPerf,
|
|
|
|
aParams.userFontSet, devToCssSize);
|
2016-03-17 02:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFontMetrics::~nsFontMetrics()
|
|
|
|
{
|
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->FontMetricsDeleted(this);
|
|
|
|
}
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
void
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::Destroy()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mDeviceContext = nullptr;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
// XXXTODO get rid of this macro
|
|
|
|
#define ROUND_TO_TWIPS(x) (nscoord)floor(((x) * mP2A) + 0.5)
|
2011-05-30 19:08:55 +00:00
|
|
|
#define CEIL_TO_TWIPS(x) (nscoord)ceil((x) * mP2A)
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2015-01-06 20:56:03 +00:00
|
|
|
const gfxFont::Metrics&
|
|
|
|
nsFontMetrics::GetMetrics(gfxFont::Orientation aOrientation) const
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2015-01-06 20:56:03 +00:00
|
|
|
return mFontGroup->GetFirstValidFont()->GetMetrics(aOrientation);
|
2005-10-08 05:09:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::XHeight()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().xHeight);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::SuperscriptOffset()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2014-06-28 06:40:35 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().emHeight *
|
|
|
|
NS_FONT_SUPERSCRIPT_OFFSET_RATIO);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::SubscriptOffset()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2014-06-28 06:40:35 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().emHeight *
|
|
|
|
NS_FONT_SUBSCRIPT_OFFSET_RATIO);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
void
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetStrikeout(nscoord& aOffset, nscoord& aSize)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aOffset = ROUND_TO_TWIPS(GetMetrics().strikeoutOffset);
|
|
|
|
aSize = ROUND_TO_TWIPS(GetMetrics().strikeoutSize);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
void
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetUnderline(nscoord& aOffset, nscoord& aSize)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-03-29 21:25:15 +00:00
|
|
|
aOffset = ROUND_TO_TWIPS(mFontGroup->GetUnderlineOffset());
|
2005-10-08 05:09:42 +00:00
|
|
|
aSize = ROUND_TO_TWIPS(GetMetrics().underlineSize);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 03:07:27 +00:00
|
|
|
// GetMaxAscent/GetMaxDescent/GetMaxHeight must contain the
|
2008-03-29 21:25:15 +00:00
|
|
|
// text-decoration lines drawable area. See bug 421353.
|
|
|
|
// BE CAREFUL for rounding each values. The logic MUST be same as
|
|
|
|
// nsCSSRendering::GetTextDecorationRectInternal's.
|
|
|
|
|
|
|
|
static gfxFloat ComputeMaxDescent(const gfxFont::Metrics& aMetrics,
|
|
|
|
gfxFontGroup* aFontGroup)
|
|
|
|
{
|
2011-05-30 19:08:55 +00:00
|
|
|
gfxFloat offset = floor(-aFontGroup->GetUnderlineOffset() + 0.5);
|
2008-03-29 21:25:15 +00:00
|
|
|
gfxFloat size = NS_round(aMetrics.underlineSize);
|
2015-03-12 10:47:50 +00:00
|
|
|
gfxFloat minDescent = offset + size;
|
|
|
|
return floor(std::max(minDescent, aMetrics.maxDescent) + 0.5);
|
2008-03-29 21:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gfxFloat ComputeMaxAscent(const gfxFont::Metrics& aMetrics)
|
|
|
|
{
|
2011-05-30 19:08:55 +00:00
|
|
|
return floor(aMetrics.maxAscent + 0.5);
|
2008-03-29 21:25:15 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::InternalLeading()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().internalLeading);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::ExternalLeading()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().externalLeading);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::EmHeight()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().emHeight);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::EmAscent()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().emAscent);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::EmDescent()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().emDescent);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::MaxHeight()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())) +
|
2008-03-29 21:25:15 +00:00
|
|
|
CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup));
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::MaxAscent()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics()));
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::MaxDescent()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup));
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::MaxAdvance()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return CEIL_TO_TWIPS(GetMetrics().maxAdvance);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::AveCharWidth()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
// Use CEIL instead of ROUND for consistency with GetMaxAdvance
|
|
|
|
return CEIL_TO_TWIPS(GetMetrics().aveCharWidth);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::SpaceWidth()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2015-01-06 20:56:03 +00:00
|
|
|
// 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(mVertical &&
|
|
|
|
mTextOrientation == NS_STYLE_TEXT_ORIENTATION_UPRIGHT
|
|
|
|
? gfxFont::eVertical
|
|
|
|
: gfxFont::eHorizontal).spaceWidth);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetMaxStringLength()
|
2006-06-26 22:18:23 +00:00
|
|
|
{
|
2006-07-17 23:45:21 +00:00
|
|
|
const gfxFont::Metrics& m = GetMetrics();
|
|
|
|
const double x = 32767.0 / m.maxAdvance;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = (int32_t)floor(x);
|
2013-01-15 12:22:03 +00:00
|
|
|
return std::max(1, len);
|
2006-06-26 22:18:23 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
2012-08-22 15:56:38 +00:00
|
|
|
nsFontMetrics::GetWidth(const char* aString, uint32_t aLength,
|
2015-12-15 21:56:41 +00:00
|
|
|
DrawTarget* aDrawTarget)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
if (aLength == 0)
|
|
|
|
return 0;
|
2006-03-07 23:45:52 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
if (aLength == 1 && aString[0] == ' ')
|
|
|
|
return SpaceWidth();
|
2006-07-17 23:45:21 +00:00
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
StubPropertyProvider provider;
|
2015-12-15 21:56:41 +00:00
|
|
|
AutoTextRun textRun(this, aDrawTarget, aString, aLength);
|
2016-03-08 07:56:18 +00:00
|
|
|
if (textRun.get()) {
|
|
|
|
return NSToCoordRound(
|
|
|
|
textRun->GetAdvanceWidth(Range(0, aLength), &provider));
|
|
|
|
}
|
|
|
|
return 0;
|
2005-10-08 05:09:42 +00:00
|
|
|
}
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
2014-01-04 15:02:17 +00:00
|
|
|
nsFontMetrics::GetWidth(const char16_t* aString, uint32_t aLength,
|
2015-12-15 21:56:41 +00:00
|
|
|
DrawTarget* aDrawTarget)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
if (aLength == 0)
|
|
|
|
return 0;
|
2006-03-07 23:45:52 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
if (aLength == 1 && aString[0] == ' ')
|
|
|
|
return SpaceWidth();
|
2006-07-17 23:45:21 +00:00
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
StubPropertyProvider provider;
|
2015-12-15 21:56:41 +00:00
|
|
|
AutoTextRun textRun(this, aDrawTarget, aString, aLength);
|
2016-03-08 07:56:18 +00:00
|
|
|
if (textRun.get()) {
|
|
|
|
return NSToCoordRound(
|
|
|
|
textRun->GetAdvanceWidth(Range(0, aLength), &provider));
|
|
|
|
}
|
|
|
|
return 0;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
// Draw a string using this font handle on the surface passed in.
|
2011-04-08 04:18:43 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsFontMetrics::DrawString(const char *aString, uint32_t aLength,
|
2011-04-08 01:05:26 +00:00
|
|
|
nscoord aX, nscoord aY,
|
|
|
|
nsRenderingContext *aContext)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2006-03-07 23:45:52 +00:00
|
|
|
if (aLength == 0)
|
2011-04-08 04:18:43 +00:00
|
|
|
return;
|
2006-03-07 23:45:52 +00:00
|
|
|
|
2007-11-09 06:27:23 +00:00
|
|
|
StubPropertyProvider provider;
|
2015-12-15 21:56:41 +00:00
|
|
|
AutoTextRun textRun(this, aContext->GetDrawTarget(), aString, aLength);
|
2012-02-28 21:34:45 +00:00
|
|
|
if (!textRun.get()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-01-23 08:45:52 +00:00
|
|
|
gfxPoint pt(aX, aY);
|
2016-03-08 07:56:18 +00:00
|
|
|
Range range(0, aLength);
|
2007-01-23 08:45:52 +00:00
|
|
|
if (mTextRunRTL) {
|
2015-01-06 20:56:03 +00:00
|
|
|
if (mVertical) {
|
2016-03-08 07:56:18 +00:00
|
|
|
pt.y += textRun->GetAdvanceWidth(range, &provider);
|
2015-01-06 20:56:03 +00:00
|
|
|
} else {
|
2016-03-08 07:56:18 +00:00
|
|
|
pt.x += textRun->GetAdvanceWidth(range, &provider);
|
2015-01-06 20:56:03 +00:00
|
|
|
}
|
2006-04-08 00:41:08 +00:00
|
|
|
}
|
2016-03-08 07:56:18 +00:00
|
|
|
gfxTextRun::DrawParams params(aContext->ThebesContext());
|
|
|
|
params.provider = &provider;
|
|
|
|
textRun->Draw(range, pt, params);
|
2005-10-08 05:09:42 +00:00
|
|
|
}
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
void
|
2014-01-04 15:02:17 +00:00
|
|
|
nsFontMetrics::DrawString(const char16_t* aString, uint32_t aLength,
|
2011-04-08 01:05:26 +00:00
|
|
|
nscoord aX, nscoord aY,
|
|
|
|
nsRenderingContext *aContext,
|
2015-12-15 21:56:41 +00:00
|
|
|
DrawTarget* aTextRunConstructionDrawTarget)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2006-03-07 23:45:52 +00:00
|
|
|
if (aLength == 0)
|
2011-04-08 04:18:43 +00:00
|
|
|
return;
|
2006-03-07 23:45:52 +00:00
|
|
|
|
2007-11-09 06:27:23 +00:00
|
|
|
StubPropertyProvider provider;
|
2015-12-15 21:56:41 +00:00
|
|
|
AutoTextRun textRun(this, aTextRunConstructionDrawTarget, aString, aLength);
|
2012-02-28 21:34:45 +00:00
|
|
|
if (!textRun.get()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-01-23 08:45:52 +00:00
|
|
|
gfxPoint pt(aX, aY);
|
2016-03-08 07:56:18 +00:00
|
|
|
Range range(0, aLength);
|
2007-01-23 08:45:52 +00:00
|
|
|
if (mTextRunRTL) {
|
2015-01-06 20:56:03 +00:00
|
|
|
if (mVertical) {
|
2016-03-08 07:56:18 +00:00
|
|
|
pt.y += textRun->GetAdvanceWidth(range, &provider);
|
2015-01-06 20:56:03 +00:00
|
|
|
} else {
|
2016-03-08 07:56:18 +00:00
|
|
|
pt.x += textRun->GetAdvanceWidth(range, &provider);
|
2015-01-06 20:56:03 +00:00
|
|
|
}
|
2006-04-08 00:41:08 +00:00
|
|
|
}
|
2016-03-08 07:56:18 +00:00
|
|
|
gfxTextRun::DrawParams params(aContext->ThebesContext());
|
|
|
|
params.provider = &provider;
|
|
|
|
textRun->Draw(range, pt, params);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 00:24:54 +00:00
|
|
|
static nsBoundingMetrics
|
2015-12-15 21:56:41 +00:00
|
|
|
GetTextBoundingMetrics(nsFontMetrics* aMetrics, const char16_t* aString,
|
|
|
|
uint32_t aLength, mozilla::gfx::DrawTarget* aDrawTarget,
|
|
|
|
gfxFont::BoundingBoxType aType)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
if (aLength == 0)
|
|
|
|
return nsBoundingMetrics();
|
2007-11-12 04:39:17 +00:00
|
|
|
|
2011-04-08 03:07:27 +00:00
|
|
|
StubPropertyProvider provider;
|
2015-12-15 21:56:41 +00:00
|
|
|
AutoTextRun textRun(aMetrics, aDrawTarget, aString, aLength);
|
2011-04-08 04:18:43 +00:00
|
|
|
nsBoundingMetrics m;
|
2012-02-28 21:34:45 +00:00
|
|
|
if (textRun.get()) {
|
2016-03-08 07:56:18 +00:00
|
|
|
gfxTextRun::Metrics theMetrics = textRun->MeasureText(
|
|
|
|
gfxTextRun::Range(0, aLength), aType, aDrawTarget, &provider);
|
2012-02-28 21:34:45 +00:00
|
|
|
|
|
|
|
m.leftBearing = NSToCoordFloor( theMetrics.mBoundingBox.X());
|
|
|
|
m.rightBearing = NSToCoordCeil( theMetrics.mBoundingBox.XMost());
|
|
|
|
m.ascent = NSToCoordCeil( -theMetrics.mBoundingBox.Y());
|
|
|
|
m.descent = NSToCoordCeil( theMetrics.mBoundingBox.YMost());
|
|
|
|
m.width = NSToCoordRound( theMetrics.mAdvanceWidth);
|
|
|
|
}
|
2011-04-08 04:18:43 +00:00
|
|
|
return m;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
2012-04-27 00:24:54 +00:00
|
|
|
|
|
|
|
nsBoundingMetrics
|
2014-01-04 15:02:17 +00:00
|
|
|
nsFontMetrics::GetBoundingMetrics(const char16_t *aString, uint32_t aLength,
|
2015-12-15 21:56:41 +00:00
|
|
|
DrawTarget* aDrawTarget)
|
2012-04-27 00:24:54 +00:00
|
|
|
{
|
2015-12-15 21:56:41 +00:00
|
|
|
return GetTextBoundingMetrics(this, aString, aLength, aDrawTarget,
|
|
|
|
gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS);
|
2012-04-27 00:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBoundingMetrics
|
2014-01-04 15:02:17 +00:00
|
|
|
nsFontMetrics::GetInkBoundsForVisualOverflow(const char16_t *aString, uint32_t aLength,
|
2015-12-15 21:56:41 +00:00
|
|
|
DrawTarget* aDrawTarget)
|
2012-04-27 00:24:54 +00:00
|
|
|
{
|
2015-12-15 21:56:41 +00:00
|
|
|
return GetTextBoundingMetrics(this, aString, aLength, aDrawTarget,
|
|
|
|
gfxFont::LOOSE_INK_EXTENTS);
|
2012-04-27 00:24:54 +00:00
|
|
|
}
|
|
|
|
|