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 thebes gfx code.
17 * The Initial Developer of the Original Code is Mozilla Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
22 * Vladimir Vukicevic <vladimir@pobox.com>
23 * Masayuki Nakano <masayuki@d-toybox.com>
24 * John Daggett <jdaggett@mozilla.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef GFX_ATSUIFONTS_H
41 #define GFX_ATSUIFONTS_H
46 #include "gfxFontUtils.h"
47 #include "gfxPlatform.h"
49 #include <Carbon/Carbon.h>
51 class gfxAtsuiFontGroup
;
54 class MacOSFamilyEntry
;
56 class gfxAtsuiFont
: public gfxFont
{
59 gfxAtsuiFont(MacOSFontEntry
*aFontEntry
,
60 const gfxFontStyle
*fontStyle
, PRBool aNeedsBold
);
62 virtual ~gfxAtsuiFont();
64 virtual const gfxFont::Metrics
& GetMetrics();
66 float GetCharWidth(PRUnichar c
, PRUint32
*aGlyphID
= nsnull
);
67 float GetCharHeight(PRUnichar c
);
69 ATSUFontID
GetATSUFontID();
71 cairo_font_face_t
*CairoFontFace() { return mFontFace
; }
72 cairo_scaled_font_t
*CairoScaledFont() { return mScaledFont
; }
74 ATSUStyle
GetATSUStyle() { return mATSUStyle
; }
76 virtual nsString
GetUniqueName();
78 virtual PRUint32
GetSpaceGlyph() { return mSpaceGlyph
; }
80 PRBool
HasMirroringInfo();
82 virtual void SetupGlyphExtents(gfxContext
*aContext
, PRUint32 aGlyphID
,
83 PRBool aNeedTight
, gfxGlyphExtents
*aExtents
);
85 PRBool
TestCharacterMap(PRUint32 aCh
);
87 MacOSFontEntry
* GetFontEntry();
88 PRBool
Valid() { return mIsValid
; }
91 const gfxFontStyle
*mFontStyle
;
96 PRBool mHasMirroringLookedUp
;
100 cairo_font_face_t
*mFontFace
;
101 cairo_scaled_font_t
*mScaledFont
;
103 gfxFont::Metrics mMetrics
;
105 gfxFloat mAdjustedSize
;
106 PRUint32 mSpaceGlyph
;
108 void InitMetrics(ATSUFontID aFontID
, ATSFontRef aFontRef
);
110 virtual PRBool
SetupCairoFont(gfxContext
*aContext
);
113 class THEBES_API gfxAtsuiFontGroup
: public gfxFontGroup
{
115 gfxAtsuiFontGroup(const nsAString
& families
,
116 const gfxFontStyle
*aStyle
,
117 gfxUserFontSet
*aUserFontSet
);
118 virtual ~gfxAtsuiFontGroup() {};
120 virtual gfxFontGroup
*Copy(const gfxFontStyle
*aStyle
);
122 virtual gfxTextRun
*MakeTextRun(const PRUnichar
* aString
, PRUint32 aLength
,
123 const Parameters
* aParams
, PRUint32 aFlags
);
124 virtual gfxTextRun
*MakeTextRun(const PRUint8
* aString
, PRUint32 aLength
,
125 const Parameters
* aParams
, PRUint32 aFlags
);
126 // When aWrapped is true, the string includes bidi control
127 // characters. The first character will be LRO or LRO to force setting the
128 // direction for all characters, the last character is PDF, and the
129 // second to last character is a non-whitespace character --- to ensure
130 // that there is no "trailing whitespace" in the string, see
131 // http://weblogs.mozillazine.org/roc/archives/2007/02/superlaser_targ.html#comments
132 void MakeTextRunInternal(const PRUnichar
*aString
, PRUint32 aLength
,
133 PRBool aWrapped
, gfxTextRun
*aTextRun
);
135 gfxAtsuiFont
* GetFontAt(PRInt32 aFontIndex
) {
136 // If it turns out to be hard for all clients that cache font
137 // groups to call UpdateFontList at appropriate times, we could
138 // instead consider just calling UpdateFontList from someplace
139 // more central (such as here).
140 NS_ASSERTION(!mUserFontSet
|| mCurrGeneration
== GetGeneration(),
141 "Whoever was caching this font group should have "
142 "called UpdateFontList on it");
144 return static_cast<gfxAtsuiFont
*>(static_cast<gfxFont
*>(mFonts
[aFontIndex
]));
147 PRBool
HasFont(ATSUFontID fid
);
149 inline gfxAtsuiFont
* WhichFontSupportsChar(nsTArray
< nsRefPtr
<gfxFont
> >& aFontList
,
152 PRUint32 len
= aFontList
.Length();
153 for (PRUint32 i
= 0; i
< len
; i
++) {
154 gfxAtsuiFont
* font
= static_cast<gfxAtsuiFont
*>(aFontList
.ElementAt(i
).get());
155 if (font
->TestCharacterMap(aCh
))
161 // search through pref fonts for a character, return nsnull if no matching pref font
162 already_AddRefed
<gfxFont
> WhichPrefFontSupportsChar(PRUint32 aCh
);
164 already_AddRefed
<gfxFont
> WhichSystemFontSupportsChar(PRUint32 aCh
);
166 void UpdateFontList();
169 static PRBool
FindATSUFont(const nsAString
& aName
,
170 const nsACString
& aGenericName
,
173 PRUint32
GuessMaximumStringLength();
176 * @param aRun the text run to fill in
177 * @param aString the complete text including all wrapper characters
178 * @param aLength the length of aString
179 * @param aLayoutStart the first character of aString that should be
180 * at the start of the ATSUI layout; this skips any wrapper character
181 * used to override direction
182 * @param aLayoutLength the length of the characters that should be
183 * in the ATSUI layout; this excludes any trailing wrapper character
184 * used to override direction
185 * @param aTrailingCharsToIgnore the number of trailing characters
186 * in the ATSUI layout that are not part of the text run
187 * (characters added to ensure correct RTL and kerning behaviour)
188 * @param aTextRunOffset the character offset in the textrun where
189 * the glyph data from the ATSUI layout should be copied
190 * @return true for success
192 PRBool
InitTextRun(gfxTextRun
*aRun
,
193 const PRUnichar
*aString
, PRUint32 aLength
,
194 PRUint32 aLayoutStart
, PRUint32 aLayoutLength
,
195 PRUint32 aOffsetInTextRun
, PRUint32 aLengthInTextRun
);
197 // cache the most recent pref font to avoid general pref font lookup
198 nsRefPtr
<MacOSFamilyEntry
> mLastPrefFamily
;
199 nsRefPtr
<gfxAtsuiFont
> mLastPrefFont
;
200 eFontPrefLang mLastPrefLang
; // lang group for last pref font
201 PRBool mLastPrefFirstFont
; // is this the first font in the list of pref fonts for this lang group?
202 eFontPrefLang mPageLang
;
204 #endif /* GFX_ATSUIFONTS_H */