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
|
|
|
|
#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
|
|
|
|
#include "nsDebug.h" // for NS_ERROR, NS_ABORT_IF_FALSE
|
|
|
|
#include "nsDeviceContext.h" // for nsDeviceContext
|
|
|
|
#include "nsIAtom.h" // for nsIAtom
|
|
|
|
#include "nsMathUtils.h" // for NS_round
|
|
|
|
#include "nsRenderingContext.h" // for nsRenderingContext
|
2013-09-23 17:25:00 +00:00
|
|
|
#include "nsString.h" // for nsString
|
2013-09-01 22:21:01 +00:00
|
|
|
#include "nsStyleConsts.h" // for NS_STYLE_HYPHENS_NONE
|
|
|
|
|
|
|
|
class gfxUserFontSet;
|
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:
|
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC,
|
2012-08-22 15:56:38 +00:00
|
|
|
const char* aString, int32_t aLength)
|
2011-12-06 12:39:18 +00:00
|
|
|
{
|
|
|
|
mTextRun = aMetrics->GetThebesFontGroup()->MakeTextRun(
|
2012-08-22 15:56:38 +00:00
|
|
|
reinterpret_cast<const uint8_t*>(aString), aLength,
|
2011-12-06 12:39:18 +00:00
|
|
|
aRC->ThebesContext(),
|
2011-04-08 01:05:26 +00:00
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
2011-12-06 12:39:18 +00:00
|
|
|
ComputeFlags(aMetrics));
|
|
|
|
}
|
2011-04-08 04:18:43 +00:00
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* aString, int32_t aLength)
|
2011-12-06 12:39:18 +00:00
|
|
|
{
|
|
|
|
mTextRun = aMetrics->GetThebesFontGroup()->MakeTextRun(
|
|
|
|
aString, aLength,
|
2011-04-08 01:05:26 +00:00
|
|
|
aRC->ThebesContext(),
|
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
2011-12-06 12:39:18 +00:00
|
|
|
ComputeFlags(aMetrics));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun *get() { return mTextRun; }
|
|
|
|
gfxTextRun *operator->() { return mTextRun; }
|
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;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
2011-12-06 12:39:18 +00:00
|
|
|
|
|
|
|
nsAutoPtr<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:
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual void GetHyphenationBreaks(uint32_t aStart, uint32_t aLength,
|
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;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual void GetSpacing(uint32_t aStart, uint32_t aLength,
|
2011-04-08 04:18:43 +00:00
|
|
|
Spacing* aSpacing) {
|
|
|
|
NS_ERROR("This shouldn't be called because we never enable spacing");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::nsFontMetrics()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mDeviceContext(nullptr), mP2A(0), mTextRunRTL(false)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::~nsFontMetrics()
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2009-08-14 20:51:30 +00:00
|
|
|
if (mDeviceContext)
|
|
|
|
mDeviceContext->FontMetricsDeleted(this);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::Init(const nsFont& aFont, nsIAtom* aLanguage,
|
2011-04-17 01:22:42 +00:00
|
|
|
nsDeviceContext *aContext,
|
2013-11-25 04:59:56 +00:00
|
|
|
gfxUserFontSet *aUserFontSet,
|
|
|
|
gfxTextPerfMetrics *aTextPerf)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2011-08-11 23:19:03 +00:00
|
|
|
NS_ABORT_IF_FALSE(mP2A == 0, "already initialized");
|
2011-04-08 15:32:29 +00:00
|
|
|
|
2005-01-22 16:00:07 +00:00
|
|
|
mFont = aFont;
|
2010-02-24 17:57:44 +00:00
|
|
|
mLanguage = aLanguage;
|
2011-04-17 01:22:42 +00:00
|
|
|
mDeviceContext = aContext;
|
2007-02-07 07:46:44 +00:00
|
|
|
mP2A = mDeviceContext->AppUnitsPerDevPixel();
|
2011-04-08 15:32:29 +00:00
|
|
|
|
|
|
|
gfxFontStyle style(aFont.style,
|
|
|
|
aFont.weight,
|
|
|
|
aFont.stretch,
|
|
|
|
gfxFloat(aFont.size) / mP2A,
|
|
|
|
aLanguage,
|
|
|
|
aFont.sizeAdjust,
|
|
|
|
aFont.systemFont,
|
|
|
|
mDeviceContext->IsPrinterSurface(),
|
|
|
|
aFont.languageOverride);
|
|
|
|
|
2012-04-26 06:25:29 +00:00
|
|
|
aFont.AddFontFeaturesToStyle(&style);
|
|
|
|
|
2011-04-08 15:32:29 +00:00
|
|
|
mFontGroup = gfxPlatform::GetPlatform()->
|
|
|
|
CreateFontGroup(aFont.name, &style, aUserFontSet);
|
2013-11-25 04:59:56 +00:00
|
|
|
mFontGroup->SetTextPerfMetrics(aTextPerf);
|
2011-04-08 01:05:26 +00:00
|
|
|
if (mFontGroup->FontListLength() < 1)
|
2009-01-23 06:24:29 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2004-08-14 01:01:16 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
const gfxFont::Metrics& nsFontMetrics::GetMetrics() const
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2006-03-03 05:54:47 +00:00
|
|
|
return mFontGroup->GetFontAt(0)->GetMetrics();
|
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
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().superscriptOffset);
|
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
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return ROUND_TO_TWIPS(GetMetrics().subscriptOffset);
|
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);
|
2011-05-30 19:08:55 +00:00
|
|
|
gfxFloat minDescent = floor(offset + size + 0.5);
|
2013-01-15 12:22:03 +00:00
|
|
|
return std::max(minDescent, aMetrics.maxDescent);
|
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
|
|
|
{
|
2011-04-08 04:18:43 +00:00
|
|
|
return CEIL_TO_TWIPS(GetMetrics().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,
|
2011-04-08 01:05:26 +00:00
|
|
|
nsRenderingContext *aContext)
|
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;
|
2007-11-09 06:27:23 +00:00
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
2012-02-28 21:34:45 +00:00
|
|
|
return textRun.get() ?
|
|
|
|
NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider)) : 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,
|
2011-04-08 01:05:26 +00:00
|
|
|
nsRenderingContext *aContext)
|
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;
|
2007-11-09 06:27:23 +00:00
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
2012-02-28 21:34:45 +00:00
|
|
|
return textRun.get() ?
|
|
|
|
NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider)) : 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;
|
|
|
|
AutoTextRun textRun(this, aContext, 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);
|
|
|
|
if (mTextRunRTL) {
|
|
|
|
pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
|
2006-04-08 00:41:08 +00:00
|
|
|
}
|
2013-10-01 21:02:16 +00:00
|
|
|
textRun->Draw(aContext->ThebesContext(), pt, DrawMode::GLYPH_FILL, 0, aLength,
|
2012-07-30 14:20:58 +00:00
|
|
|
&provider, nullptr, nullptr);
|
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,
|
|
|
|
nsRenderingContext *aTextRunConstructionContext)
|
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;
|
2011-01-16 20:23:33 +00:00
|
|
|
AutoTextRun textRun(this, aTextRunConstructionContext, 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);
|
|
|
|
if (mTextRunRTL) {
|
|
|
|
pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
|
2006-04-08 00:41:08 +00:00
|
|
|
}
|
2013-10-01 21:02:16 +00:00
|
|
|
textRun->Draw(aContext->ThebesContext(), pt, DrawMode::GLYPH_FILL, 0, aLength,
|
2012-07-30 14:20:58 +00:00
|
|
|
&provider, nullptr, nullptr);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 00:24:54 +00:00
|
|
|
static nsBoundingMetrics
|
2014-01-04 15:02:17 +00:00
|
|
|
GetTextBoundingMetrics(nsFontMetrics* aMetrics, const char16_t *aString, uint32_t aLength,
|
2012-04-27 00:24:54 +00:00
|
|
|
nsRenderingContext *aContext, 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;
|
2012-04-27 00:24:54 +00:00
|
|
|
AutoTextRun textRun(aMetrics, aContext, aString, aLength);
|
2011-04-08 04:18:43 +00:00
|
|
|
nsBoundingMetrics m;
|
2012-02-28 21:34:45 +00:00
|
|
|
if (textRun.get()) {
|
|
|
|
gfxTextRun::Metrics theMetrics =
|
|
|
|
textRun->MeasureText(0, aLength,
|
2012-04-27 00:24:54 +00:00
|
|
|
aType,
|
2012-02-28 21:34:45 +00:00
|
|
|
aContext->ThebesContext(), &provider);
|
|
|
|
|
|
|
|
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,
|
2012-04-27 00:24:54 +00:00
|
|
|
nsRenderingContext *aContext)
|
|
|
|
{
|
|
|
|
return GetTextBoundingMetrics(this, aString, aLength, aContext, gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBoundingMetrics
|
2014-01-04 15:02:17 +00:00
|
|
|
nsFontMetrics::GetInkBoundsForVisualOverflow(const char16_t *aString, uint32_t aLength,
|
2012-04-27 00:24:54 +00:00
|
|
|
nsRenderingContext *aContext)
|
|
|
|
{
|
|
|
|
return GetTextBoundingMetrics(this, aString, aLength, aContext, gfxFont::LOOSE_INK_EXTENTS);
|
|
|
|
}
|
|
|
|
|