1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
23 * Stuart Parmenter <pavlov@pavlov.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef NSTHEBESFONTMETRICS__H__
40 #define NSTHEBESFONTMETRICS__H__
42 #include "nsIThebesFontMetrics.h"
43 #include "nsThebesRenderingContext.h"
45 #include "nsThebesDeviceContext.h"
49 #include "gfxTextRunCache.h"
51 class nsThebesFontMetrics
: public nsIThebesFontMetrics
54 nsThebesFontMetrics();
55 virtual ~nsThebesFontMetrics();
59 NS_IMETHOD
Init(const nsFont
& aFont
, nsIAtom
* aLangGroup
,
60 nsIDeviceContext
*aContext
,
61 gfxUserFontSet
*aUserFontSet
= nsnull
);
63 NS_IMETHOD
GetXHeight(nscoord
& aResult
);
64 NS_IMETHOD
GetSuperscriptOffset(nscoord
& aResult
);
65 NS_IMETHOD
GetSubscriptOffset(nscoord
& aResult
);
66 NS_IMETHOD
GetStrikeout(nscoord
& aOffset
, nscoord
& aSize
);
67 NS_IMETHOD
GetUnderline(nscoord
& aOffset
, nscoord
& aSize
);
68 NS_IMETHOD
GetHeight(nscoord
&aHeight
);
69 NS_IMETHOD
GetInternalLeading(nscoord
&aLeading
);
70 NS_IMETHOD
GetExternalLeading(nscoord
&aLeading
);
71 NS_IMETHOD
GetEmHeight(nscoord
&aHeight
);
72 NS_IMETHOD
GetEmAscent(nscoord
&aAscent
);
73 NS_IMETHOD
GetEmDescent(nscoord
&aDescent
);
74 NS_IMETHOD
GetMaxHeight(nscoord
&aHeight
);
75 NS_IMETHOD
GetMaxAscent(nscoord
&aAscent
);
76 NS_IMETHOD
GetMaxDescent(nscoord
&aDescent
);
77 NS_IMETHOD
GetMaxAdvance(nscoord
&aAdvance
);
78 NS_IMETHOD
GetLangGroup(nsIAtom
** aLangGroup
);
79 NS_IMETHOD
GetFontHandle(nsFontHandle
&aHandle
);
80 NS_IMETHOD
GetAveCharWidth(nscoord
& aAveCharWidth
);
81 NS_IMETHOD
GetSpaceWidth(nscoord
& aSpaceCharWidth
);
82 virtual PRInt32
GetMaxStringLength();
85 virtual nsresult
GetWidth(const char* aString
, PRUint32 aLength
, nscoord
& aWidth
,
86 nsThebesRenderingContext
*aContext
);
87 virtual nsresult
GetWidth(const PRUnichar
* aString
, PRUint32 aLength
,
88 nscoord
& aWidth
, PRInt32
*aFontID
,
89 nsThebesRenderingContext
*aContext
);
91 // Get the text dimensions for this string
92 virtual nsresult
GetTextDimensions(const PRUnichar
* aString
,
94 nsTextDimensions
& aDimensions
,
96 virtual nsresult
GetTextDimensions(const char* aString
,
101 nsTextDimensions
& aDimensions
,
102 PRInt32
& aNumCharsFit
,
103 nsTextDimensions
& aLastWordDimensions
,
105 virtual nsresult
GetTextDimensions(const PRUnichar
* aString
,
110 nsTextDimensions
& aDimensions
,
111 PRInt32
& aNumCharsFit
,
112 nsTextDimensions
& aLastWordDimensions
,
115 // Draw a string using this font handle on the surface passed in.
116 virtual nsresult
DrawString(const char *aString
, PRUint32 aLength
,
117 nscoord aX
, nscoord aY
,
118 const nscoord
* aSpacing
,
119 nsThebesRenderingContext
*aContext
);
120 virtual nsresult
DrawString(const PRUnichar
* aString
, PRUint32 aLength
,
121 nscoord aX
, nscoord aY
,
123 const nscoord
* aSpacing
,
124 nsThebesRenderingContext
*aContext
);
127 // These two functions get the bounding metrics for this handle,
128 // updating the aBoundingMetrics in app units.
129 virtual nsresult
GetBoundingMetrics(const char *aString
, PRUint32 aLength
,
130 nsThebesRenderingContext
*aContext
,
131 nsBoundingMetrics
&aBoundingMetrics
);
132 virtual nsresult
GetBoundingMetrics(const PRUnichar
*aString
,
134 nsThebesRenderingContext
*aContext
,
135 nsBoundingMetrics
&aBoundingMetrics
);
136 #endif /* MOZ_MATHML */
138 // Set the direction of the text rendering
139 virtual nsresult
SetRightToLeftText(PRBool aIsRTL
);
140 virtual PRBool
GetRightToLeftText();
141 virtual void SetTextRunRTL(PRBool aIsRTL
) { mTextRunRTL
= aIsRTL
; }
143 virtual gfxFontGroup
* GetThebesFontGroup() { return mFontGroup
; }
145 PRBool
GetRightToLeftTextRunMode() {
151 const gfxFont::Metrics
& GetMetrics() const;
155 AutoTextRun(nsThebesFontMetrics
* aMetrics
, nsIRenderingContext
* aRC
,
156 const char* aString
, PRInt32 aLength
) {
157 mTextRun
= gfxTextRunCache::MakeTextRun(
158 reinterpret_cast<const PRUint8
*>(aString
), aLength
,
159 aMetrics
->mFontGroup
, aRC
->ThebesContext(),
161 ComputeFlags(aMetrics
));
163 AutoTextRun(nsThebesFontMetrics
* aMetrics
, nsIRenderingContext
* aRC
,
164 const PRUnichar
* aString
, PRInt32 aLength
) {
165 mTextRun
= gfxTextRunCache::MakeTextRun(
166 aString
, aLength
, aMetrics
->mFontGroup
,
167 aRC
->ThebesContext(),
169 ComputeFlags(aMetrics
));
171 gfxTextRun
* operator->() { return mTextRun
.get(); }
172 gfxTextRun
* get() { return mTextRun
.get(); }
175 gfxTextRunCache::AutoTextRun mTextRun
;
177 static PRUint32
ComputeFlags(nsThebesFontMetrics
* aMetrics
) {
179 if (aMetrics
->GetRightToLeftTextRunMode()) {
180 flags
|= gfxTextRunFactory::TEXT_IS_RTL
;
185 friend class AutoTextRun
;
187 nsRefPtr
<gfxFontGroup
> mFontGroup
;
188 gfxFontStyle
*mFontStyle
;
191 nsThebesDeviceContext
*mDeviceContext
;
192 nsCOMPtr
<nsIAtom
> mLangGroup
;
194 PRPackedBool mIsRightToLeft
;
195 PRPackedBool mTextRunRTL
;
198 #endif /* NSTHEBESFONTMETRICS__H__ */