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-08 01:04:40 +00:00
|
|
|
#include "nsThebesDeviceContext.h"
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
class AutoTextRun {
|
|
|
|
public:
|
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC,
|
|
|
|
const char* aString, PRInt32 aLength) {
|
|
|
|
mTextRun = gfxTextRunCache::MakeTextRun(
|
|
|
|
reinterpret_cast<const PRUint8*>(aString), aLength,
|
|
|
|
aMetrics->GetThebesFontGroup(), aRC->ThebesContext(),
|
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
|
|
|
ComputeFlags(aMetrics));
|
|
|
|
}
|
|
|
|
AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC,
|
|
|
|
const PRUnichar* aString, PRInt32 aLength) {
|
|
|
|
mTextRun = gfxTextRunCache::MakeTextRun(
|
|
|
|
aString, aLength, aMetrics->GetThebesFontGroup(),
|
|
|
|
aRC->ThebesContext(),
|
|
|
|
aMetrics->AppUnitsPerDevPixel(),
|
|
|
|
ComputeFlags(aMetrics));
|
|
|
|
}
|
|
|
|
gfxTextRun* operator->() { return mTextRun.get(); }
|
|
|
|
gfxTextRun* get() { return mTextRun.get(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfxTextRunCache::AutoTextRun mTextRun;
|
|
|
|
|
|
|
|
static PRUint32 ComputeFlags(nsFontMetrics* aMetrics) {
|
|
|
|
PRUint32 flags = 0;
|
|
|
|
if (aMetrics->GetRightToLeftTextRunMode()) {
|
|
|
|
flags |= gfxTextRunFactory::TEXT_IS_RTL;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
mFontStyle = nsnull;
|
|
|
|
mFontGroup = nsnull;
|
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);
|
2005-10-08 05:09:42 +00:00
|
|
|
delete mFontStyle;
|
2006-10-14 07:26:36 +00:00
|
|
|
//delete mFontGroup;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::Init(const nsFont& aFont, nsIAtom* aLanguage,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-01-22 16:00:07 +00:00
|
|
|
mFont = aFont;
|
2010-02-24 17:57:44 +00:00
|
|
|
mLanguage = aLanguage;
|
2005-10-08 05:09:42 +00:00
|
|
|
mDeviceContext = (nsThebesDeviceContext*)aContext;
|
2007-02-07 07:46:44 +00:00
|
|
|
mP2A = mDeviceContext->AppUnitsPerDevPixel();
|
2007-01-23 08:45:52 +00:00
|
|
|
mIsRightToLeft = PR_FALSE;
|
|
|
|
mTextRunRTL = PR_FALSE;
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2007-08-22 11:13:46 +00:00
|
|
|
gfxFloat size = gfxFloat(aFont.size) / mP2A;
|
2005-11-08 20:06:16 +00:00
|
|
|
|
2008-12-17 03:17:50 +00:00
|
|
|
PRBool printerFont = mDeviceContext->IsPrinterSurface();
|
2009-01-29 20:39:18 +00:00
|
|
|
mFontStyle = new gfxFontStyle(aFont.style, aFont.weight, aFont.stretch,
|
2010-02-24 17:57:57 +00:00
|
|
|
size, aLanguage,
|
2007-05-21 02:18:04 +00:00
|
|
|
aFont.sizeAdjust, aFont.systemFont,
|
2010-07-13 20:30:42 +00:00
|
|
|
printerFont,
|
|
|
|
aFont.featureSettings,
|
|
|
|
aFont.languageOverride);
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2007-04-02 19:06:16 +00:00
|
|
|
mFontGroup =
|
2011-04-08 01:05:26 +00:00
|
|
|
gfxPlatform::GetPlatform()->CreateFontGroup(aFont.name, mFontStyle,
|
2008-10-01 03:01:53 +00:00
|
|
|
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 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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)
|
2007-06-10 23:04:27 +00:00
|
|
|
#define CEIL_TO_TWIPS(x) (nscoord)NS_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 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetXHeight(nscoord& aResult)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aResult = ROUND_TO_TWIPS(GetMetrics().xHeight);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetSuperscriptOffset(nscoord& aResult)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aResult = ROUND_TO_TWIPS(GetMetrics().superscriptOffset);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetSubscriptOffset(nscoord& aResult)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aResult = ROUND_TO_TWIPS(GetMetrics().subscriptOffset);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
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
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-29 21:25:15 +00:00
|
|
|
// GetHeight/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.
|
|
|
|
|
|
|
|
static gfxFloat ComputeMaxDescent(const gfxFont::Metrics& aMetrics,
|
|
|
|
gfxFontGroup* aFontGroup)
|
|
|
|
{
|
|
|
|
gfxFloat offset = NS_floor(-aFontGroup->GetUnderlineOffset() + 0.5);
|
|
|
|
gfxFloat size = NS_round(aMetrics.underlineSize);
|
|
|
|
gfxFloat minDescent = NS_floor(offset + size + 0.5);
|
|
|
|
return PR_MAX(minDescent, aMetrics.maxDescent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gfxFloat ComputeMaxAscent(const gfxFont::Metrics& aMetrics)
|
|
|
|
{
|
|
|
|
return NS_floor(aMetrics.maxAscent + 0.5);
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetHeight(nscoord &aHeight)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-03-29 21:25:15 +00:00
|
|
|
aHeight = CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())) +
|
|
|
|
CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup));
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetInternalLeading(nscoord &aLeading)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aLeading = ROUND_TO_TWIPS(GetMetrics().internalLeading);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetExternalLeading(nscoord &aLeading)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aLeading = ROUND_TO_TWIPS(GetMetrics().externalLeading);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetEmHeight(nscoord &aHeight)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aHeight = ROUND_TO_TWIPS(GetMetrics().emHeight);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetEmAscent(nscoord &aAscent)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aAscent = ROUND_TO_TWIPS(GetMetrics().emAscent);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetEmDescent(nscoord &aDescent)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
aDescent = ROUND_TO_TWIPS(GetMetrics().emDescent);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetMaxHeight(nscoord &aHeight)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-03-29 21:25:15 +00:00
|
|
|
aHeight = CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())) +
|
|
|
|
CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup));
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetMaxAscent(nscoord &aAscent)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-03-29 21:25:15 +00:00
|
|
|
aAscent = CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics()));
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetMaxDescent(nscoord &aDescent)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-03-29 21:25:15 +00:00
|
|
|
aDescent = CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup));
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetMaxAdvance(nscoord &aAdvance)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2007-06-10 23:04:27 +00:00
|
|
|
aAdvance = CEIL_TO_TWIPS(GetMetrics().maxAdvance);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetLanguage(nsIAtom** aLanguage)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2010-02-24 17:57:44 +00:00
|
|
|
*aLanguage = mLanguage;
|
|
|
|
NS_IF_ADDREF(*aLanguage);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetFontHandle(nsFontHandle &aHandle)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetAveCharWidth(nscoord& aAveCharWidth)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-04-15 23:34:06 +00:00
|
|
|
// Use CEIL instead of ROUND for consistency with GetMaxAdvance
|
|
|
|
aAveCharWidth = CEIL_TO_TWIPS(GetMetrics().aveCharWidth);
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetSpaceWidth(nscoord& aSpaceCharWidth)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2008-04-15 23:34:06 +00:00
|
|
|
aSpaceCharWidth = CEIL_TO_TWIPS(GetMetrics().spaceWidth);
|
2005-10-08 05:09:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
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);
|
2006-06-26 22:18:23 +00:00
|
|
|
return PR_MAX(1, len);
|
|
|
|
}
|
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
class StubPropertyProvider : public gfxTextRun::PropertyProvider {
|
|
|
|
public:
|
|
|
|
virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PRPackedBool* aBreakBefore) {
|
|
|
|
NS_ERROR("This shouldn't be called because we never call BreakAndMeasureText");
|
|
|
|
}
|
|
|
|
virtual gfxFloat GetHyphenWidth() {
|
2007-11-09 06:27:23 +00:00
|
|
|
NS_ERROR("This shouldn't be called because we never enable hyphens");
|
2007-01-23 08:45:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
virtual void GetSpacing(PRUint32 aStart, PRUint32 aLength,
|
2007-11-09 06:27:23 +00:00
|
|
|
Spacing* aSpacing) {
|
|
|
|
NS_ERROR("This shouldn't be called because we never enable spacing");
|
2007-11-08 07:41:06 +00:00
|
|
|
}
|
2007-11-09 06:27:23 +00:00
|
|
|
};
|
2007-11-08 07:41:06 +00:00
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
nsresult
|
|
|
|
nsFontMetrics::GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth,
|
|
|
|
nsRenderingContext *aContext)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2006-03-07 23:45:52 +00:00
|
|
|
if (aLength == 0) {
|
|
|
|
aWidth = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-17 23:45:21 +00:00
|
|
|
// callers that hit this should not be so stupid
|
|
|
|
if ((aLength == 1) && (aString[0] == ' '))
|
|
|
|
return GetSpaceWidth(aWidth);
|
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
StubPropertyProvider provider;
|
2007-11-09 06:27:23 +00:00
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
2007-01-23 08:45:52 +00:00
|
|
|
if (!textRun.get())
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-02-28 22:11:01 +00:00
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
aWidth = NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider));
|
2006-02-28 22:11:01 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2005-10-08 05:09:42 +00:00
|
|
|
}
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetWidth(const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
nscoord& aWidth, PRInt32 *aFontID,
|
|
|
|
nsRenderingContext *aContext)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2006-03-07 23:45:52 +00:00
|
|
|
if (aLength == 0) {
|
|
|
|
aWidth = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-17 23:45:21 +00:00
|
|
|
// callers that hit this should not be so stupid
|
|
|
|
if ((aLength == 1) && (aString[0] == ' '))
|
|
|
|
return GetSpaceWidth(aWidth);
|
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
StubPropertyProvider provider;
|
2007-11-09 06:27:23 +00:00
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
2007-01-23 08:45:52 +00:00
|
|
|
if (!textRun.get())
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-11-29 20:12:29 +00:00
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
aWidth = NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider));
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
return NS_OK;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
// Get the text dimensions for this string
|
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetTextDimensions(const PRUnichar* aString,
|
|
|
|
PRUint32 aLength,
|
|
|
|
nsTextDimensions& aDimensions,
|
|
|
|
PRInt32* aFontID)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetTextDimensions(const char* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
PRInt32 aAvailWidth,
|
|
|
|
PRInt32* aBreaks,
|
|
|
|
PRInt32 aNumBreaks,
|
|
|
|
nsTextDimensions& aDimensions,
|
|
|
|
PRInt32& aNumCharsFit,
|
|
|
|
nsTextDimensions& aLastWordDimensions,
|
|
|
|
PRInt32* aFontID)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetTextDimensions(const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
PRInt32 aAvailWidth,
|
|
|
|
PRInt32* aBreaks,
|
|
|
|
PRInt32 aNumBreaks,
|
|
|
|
nsTextDimensions& aDimensions,
|
|
|
|
PRInt32& aNumCharsFit,
|
|
|
|
nsTextDimensions& aLastWordDimensions,
|
|
|
|
PRInt32* aFontID)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2005-10-08 05:09:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
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.
|
2005-10-08 05:09:42 +00:00
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::DrawString(const char *aString, PRUint32 aLength,
|
|
|
|
nscoord aX, nscoord aY,
|
|
|
|
const nscoord* aSpacing,
|
|
|
|
nsRenderingContext *aContext)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2006-03-07 23:45:52 +00:00
|
|
|
if (aLength == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-11-09 06:27:23 +00:00
|
|
|
NS_ASSERTION(!aSpacing, "Spacing not supported here");
|
|
|
|
StubPropertyProvider provider;
|
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
2007-01-23 08:45:52 +00:00
|
|
|
if (!textRun.get())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
gfxPoint pt(aX, aY);
|
|
|
|
if (mTextRunRTL) {
|
|
|
|
pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
|
2006-04-08 00:41:08 +00:00
|
|
|
}
|
2007-12-18 23:01:15 +00:00
|
|
|
textRun->Draw(aContext->ThebesContext(), pt, 0, aLength,
|
2011-01-11 11:17:00 +00:00
|
|
|
&provider, nsnull);
|
2006-02-28 22:11:01 +00:00
|
|
|
return NS_OK;
|
2005-10-08 05:09:42 +00:00
|
|
|
}
|
2004-08-14 01:01:16 +00:00
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
nsresult
|
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)
|
|
|
|
return NS_OK;
|
|
|
|
|
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
|
|
|
if (!textRun.get())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
gfxPoint pt(aX, aY);
|
|
|
|
if (mTextRunRTL) {
|
|
|
|
pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
|
2006-04-08 00:41:08 +00:00
|
|
|
}
|
2007-12-18 23:01:15 +00:00
|
|
|
textRun->Draw(aContext->ThebesContext(), pt, 0, aLength,
|
2011-01-11 11:17:00 +00:00
|
|
|
&provider, nsnull);
|
2005-10-08 05:09:42 +00:00
|
|
|
return NS_OK;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
#ifdef MOZ_MATHML
|
2007-11-12 04:39:17 +00:00
|
|
|
|
|
|
|
static void
|
2011-04-08 01:05:26 +00:00
|
|
|
GetTextRunBoundingMetrics(gfxTextRun *aTextRun,
|
|
|
|
PRUint32 aStart, PRUint32 aLength,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext *aContext,
|
2007-11-12 04:39:17 +00:00
|
|
|
nsBoundingMetrics &aBoundingMetrics)
|
|
|
|
{
|
|
|
|
StubPropertyProvider provider;
|
|
|
|
gfxTextRun::Metrics theMetrics =
|
2011-04-08 01:05:26 +00:00
|
|
|
aTextRun->MeasureText(aStart, aLength,
|
|
|
|
gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS,
|
2009-02-24 08:32:58 +00:00
|
|
|
aContext->ThebesContext(), &provider);
|
2011-04-08 01:05:26 +00:00
|
|
|
// note that TIGHT_HINTED_OUTLINE_EXTENTS can be expensive (on Windows)
|
|
|
|
// but this is only used for MathML positioning so it's not critical
|
2007-11-12 04:39:17 +00:00
|
|
|
|
|
|
|
aBoundingMetrics.leftBearing = NSToCoordFloor(theMetrics.mBoundingBox.X());
|
|
|
|
aBoundingMetrics.rightBearing = NSToCoordCeil(theMetrics.mBoundingBox.XMost());
|
|
|
|
aBoundingMetrics.width = NSToCoordRound(theMetrics.mAdvanceWidth);
|
|
|
|
aBoundingMetrics.ascent = NSToCoordCeil(- theMetrics.mBoundingBox.Y());
|
|
|
|
aBoundingMetrics.descent = NSToCoordCeil(theMetrics.mBoundingBox.YMost());
|
|
|
|
}
|
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetBoundingMetrics(const char *aString, PRUint32 aLength,
|
|
|
|
nsRenderingContext *aContext,
|
|
|
|
nsBoundingMetrics &aBoundingMetrics)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2007-11-12 04:39:17 +00:00
|
|
|
if (aLength == 0) {
|
2011-04-08 01:04:40 +00:00
|
|
|
aBoundingMetrics = nsBoundingMetrics();
|
2007-11-12 04:39:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
|
|
|
if (!textRun.get())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
GetTextRunBoundingMetrics(textRun.get(), 0, aLength, aContext,
|
|
|
|
aBoundingMetrics);
|
2007-11-12 04:39:17 +00:00
|
|
|
return NS_OK;
|
2004-08-14 01:01:16 +00:00
|
|
|
}
|
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLength,
|
|
|
|
nsRenderingContext *aContext,
|
|
|
|
nsBoundingMetrics &aBoundingMetrics)
|
2005-10-08 05:09:42 +00:00
|
|
|
{
|
2007-11-12 04:39:17 +00:00
|
|
|
if (aLength == 0) {
|
2011-04-08 01:04:40 +00:00
|
|
|
aBoundingMetrics = nsBoundingMetrics();
|
2007-11-12 04:39:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoTextRun textRun(this, aContext, aString, aLength);
|
|
|
|
if (!textRun.get())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
GetTextRunBoundingMetrics(textRun.get(), 0, aLength, aContext,
|
|
|
|
aBoundingMetrics);
|
2007-11-12 04:39:17 +00:00
|
|
|
return NS_OK;
|
2005-10-08 05:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZ_MATHML */
|
|
|
|
|
|
|
|
// Set the direction of the text rendering
|
|
|
|
nsresult
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::SetRightToLeftText(PRBool aIsRTL)
|
2004-08-14 01:01:16 +00:00
|
|
|
{
|
2007-01-23 08:45:52 +00:00
|
|
|
mIsRightToLeft = aIsRTL;
|
2004-08-14 01:01:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2006-06-09 03:29:32 +00:00
|
|
|
// Set the direction of the text rendering
|
|
|
|
PRBool
|
2011-04-08 01:05:26 +00:00
|
|
|
nsFontMetrics::GetRightToLeftText()
|
2006-06-09 03:29:32 +00:00
|
|
|
{
|
2007-01-23 08:45:52 +00:00
|
|
|
return mIsRightToLeft;
|
2006-06-09 03:29:32 +00:00
|
|
|
}
|
2008-11-25 23:22:39 +00:00
|
|
|
|
2011-04-08 01:05:26 +00:00
|
|
|
gfxUserFontSet*
|
|
|
|
nsFontMetrics::GetUserFontSet()
|
2008-11-25 23:22:39 +00:00
|
|
|
{
|
|
|
|
return mFontGroup->GetUserFontSet();
|
|
|
|
}
|