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"
48
#include <Carbon/Carbon.h>
50
class gfxAtsuiFontGroup;
53
class gfxAtsuiFont : public gfxFont {
55
gfxAtsuiFont(ATSUFontID fontID,
56
const nsAString& name,
57
const gfxFontStyle *fontStyle);
58
virtual ~gfxAtsuiFont();
60
virtual const gfxFont::Metrics& GetMetrics();
62
float GetCharWidth(PRUnichar c, PRUint32 *aGlyphID = nsnull);
63
float GetCharHeight(PRUnichar c);
65
ATSUFontID GetATSUFontID() { return mATSUFontID; }
67
cairo_font_face_t *CairoFontFace() { return mFontFace; }
68
cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; }
70
ATSUStyle GetATSUStyle() { return mATSUStyle; }
72
virtual nsString GetUniqueName();
74
virtual PRUint32 GetSpaceGlyph() { return mSpaceGlyph; }
76
PRBool HasMirroringInfo();
78
virtual void SetupGlyphExtents(gfxContext *aContext, PRUint32 aGlyphID,
79
PRBool aNeedTight, gfxGlyphExtents *aExtents);
81
PRBool TestCharacterMap(PRUint32 aCh);
84
const gfxFontStyle *mFontStyle;
86
ATSUFontID mATSUFontID;
89
nsRefPtr<FontEntry> mFontEntry;
92
PRBool mHasMirroringLookedUp;
96
cairo_font_face_t *mFontFace;
97
cairo_scaled_font_t *mScaledFont;
99
gfxFont::Metrics mMetrics;
101
gfxFloat mAdjustedSize;
102
PRUint32 mSpaceGlyph;
104
void InitMetrics(ATSUFontID aFontID, ATSFontRef aFontRef);
106
virtual PRBool SetupCairoFont(gfxContext *aContext);
109
class THEBES_API gfxAtsuiFontGroup : public gfxFontGroup {
111
gfxAtsuiFontGroup(const nsAString& families,
112
const gfxFontStyle *aStyle);
113
virtual ~gfxAtsuiFontGroup() {};
115
virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);
117
virtual gfxTextRun *MakeTextRun(const PRUnichar* aString, PRUint32 aLength,
118
const Parameters* aParams, PRUint32 aFlags);
119
virtual gfxTextRun *MakeTextRun(const PRUint8* aString, PRUint32 aLength,
120
const Parameters* aParams, PRUint32 aFlags);
121
// When aWrapped is true, the string includes bidi control
122
// characters. The first character will be LRO or LRO to force setting the
123
// direction for all characters, the last character is PDF, and the
124
// second to last character is a non-whitespace character --- to ensure
125
// that there is no "trailing whitespace" in the string, see
126
// http://weblogs.mozillazine.org/roc/archives/2007/02/superlaser_targ.html#comments
127
void MakeTextRunInternal(const PRUnichar *aString, PRUint32 aLength,
128
PRBool aWrapped, gfxTextRun *aTextRun);
130
gfxAtsuiFont* GetFontAt(PRInt32 aFontIndex) {
131
return static_cast<gfxAtsuiFont*>(static_cast<gfxFont*>(mFonts[aFontIndex]));
134
gfxAtsuiFont* FindFontFor(ATSUFontID fid);
136
PRBool HasFont(ATSUFontID fid);
138
inline gfxAtsuiFont* WhichFontSupportsChar(nsTArray< nsRefPtr<gfxFont> >& aFontList, PRUint32 aCh) {
139
PRUint32 len = aFontList.Length();
140
for (PRUint32 i = 0; i < len; i++) {
141
gfxAtsuiFont* font = static_cast<gfxAtsuiFont*>(aFontList.ElementAt(i).get());
142
if (font->TestCharacterMap(aCh))
148
already_AddRefed<gfxAtsuiFont> FindFontForChar(PRUint32 aCh, PRUint32 aPrevCh, PRUint32 aNextCh, gfxAtsuiFont* aPrevMatchedFont);
151
static PRBool FindATSUFont(const nsAString& aName,
152
const nsACString& aGenericName,
155
PRUint32 GuessMaximumStringLength();
157
/** Returns true for success */
158
PRBool InitTextRun(gfxTextRun *aRun, const PRUnichar *aString, PRUint32 aLength,
159
PRBool aWrapped, PRUint32 aSegmentStart, PRUint32 aSegmentLength);
162
#endif /* GFX_ATSUIFONTS_H */