2004-12-01 22:27:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-08-14 01:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-12-01 22:27:03 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* mozilla.org.
|
2005-10-08 05:09:42 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
2004-12-01 22:27:03 +00:00
|
|
|
* the Initial Developer. All Rights Reserved.
|
2004-08-14 01:01:16 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2004-12-01 22:27:03 +00:00
|
|
|
* Stuart Parmenter <pavlov@pavlov.net>
|
2004-08-14 01:01:16 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2004-12-01 22:27:03 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
#include "nsFontMetrics.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsBoundingMetrics.h"
|
2011-04-08 01:05:26 +00:00
|
|
|
#include "nsRenderingContext.h"
|
2011-04-17 01:22:42 +00:00
|
|
|
#include "nsDeviceContext.h"
|
2011-05-04 11:29:56 +00:00
|
|
|
#include "nsStyleConsts.h"
|
2011-04-08 04:18:43 +00:00
|
|
|
#include "gfxTextRunCache.h"
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AutoTextRun : public gfxTextRunCache::AutoTextRun {
|
2011-04-08 01:05:26 +00:00
|
|
|
public:
|
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC,
|
2011-04-08 04:18:43 +00:00
|
|
|
const char* aString, PRInt32 aLength)
|
|
|
|
: gfxTextRunCache::AutoTextRun(gfxTextRunCache::MakeTextRun(
|
2011-04-08 01:05:26 +00:00
|
|
|
reinterpret_cast<const PRUint8*>(aString), aLength,
|
|
|
|
aMetrics->GetThebesFontGroup(), aRC->ThebesContext(),
|
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
2011-04-08 04:18:43 +00:00
|
|
|
ComputeFlags(aMetrics)))
|
|
|
|
{}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC,
|
2011-04-08 04:18:43 +00:00
|
|
|
const PRUnichar* aString, PRInt32 aLength)
|
|
|
|
: gfxTextRunCache::AutoTextRun(gfxTextRunCache::MakeTextRun(
|
2011-04-08 01:05:26 +00:00
|
|
|
aString, aLength, aMetrics->GetThebesFontGroup(),
|
|
|
|
aRC->ThebesContext(),
|
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
2011-04-08 04:18:43 +00:00
|
|
|
ComputeFlags(aMetrics)))
|
|
|
|
{}
|
2011-04-08 01:05:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static PRUint32 ComputeFlags(nsFontMetrics* aMetrics) {
|
|
|
|
PRUint32 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;
|
|
|
|
}
|
|
|
|
};
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
class StubPropertyProvider : public gfxTextRun::PropertyProvider {
|
|
|
|
public:
|
|
|
|
virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 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");
|
|
|
|
}
|
2011-05-04 11:29:56 +00:00
|
|
|
virtual PRInt8 GetHyphensOption() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
virtual void GetSpacing(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
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()
|
2011-08-11 23:19:03 +00:00
|
|
|
: mDeviceContext(nsnull), mP2A(0), mTextRunRTL(PR_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,
|
2011-04-08 01:05:26 +00:00
|
|
|
gfxUserFontSet *aUserFontSet)
|
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.featureSettings,
|
|
|
|
aFont.languageOverride);
|
|
|
|
|
|
|
|
mFontGroup = gfxPlatform::GetPlatform()->
|
|
|
|
CreateFontGroup(aFont.name, &style, aUserFontSet);
|
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
|
|
|
{
|
2009-08-14 20:51:30 +00:00
|
|
|
mDeviceContext = nsnull;
|
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);
|
2011-06-25 14:06:02 +00:00
|
|
|
return NS_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
|
|
|
}
|
|
|
|
|
2006-06-26 22:18:23 +00:00
|
|
|
PRInt32
|
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;
|
|
|
|
PRInt32 len = (PRInt32)floor(x);
|
2011-06-25 14:06:02 +00:00
|
|
|
return NS_MAX(1, len);
|
2006-06-26 22:18:23 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord
|
|
|
|
nsFontMetrics::GetWidth(const char* aString, PRUint32 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);
|
2011-04-08 04:18:43 +00:00
|
|
|
return NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider));
|
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
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetWidth(const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
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);
|
2011-04-08 04:18:43 +00:00
|
|
|
return NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider));
|
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
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::DrawString(const char *aString, PRUint32 aLength,
|
|
|
|
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);
|
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
|
|
|
}
|
2011-04-08 04:18:43 +00:00
|
|
|
textRun->Draw(aContext->ThebesContext(), pt, 0, aLength, &provider, nsnull);
|
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
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::DrawString(const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
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);
|
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
|
|
|
}
|
2011-04-08 04:18:43 +00:00
|
|
|
textRun->Draw(aContext->ThebesContext(), pt, 0, aLength, &provider, nsnull);
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nsBoundingMetrics
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLength,
|
2011-04-08 04:18:43 +00:00
|
|
|
nsRenderingContext *aContext)
|
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;
|
2011-04-08 04:18:43 +00:00
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
2011-04-08 03:07:27 +00:00
|
|
|
gfxTextRun::Metrics theMetrics =
|
|
|
|
textRun->MeasureText(0, aLength,
|
|
|
|
gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS,
|
|
|
|
aContext->ThebesContext(), &provider);
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nsBoundingMetrics m;
|
|
|
|
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);
|
|
|
|
return m;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|