1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 Novell code.
17 * The Initial Developer of the Original Code is Novell Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
22 * robert@ocallahan.org
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef NSTEXTRUNTRANSFORMATIONS_H_
39 #define NSTEXTRUNTRANSFORMATIONS_H_
43 class nsTransformedTextRun
;
46 class nsTransformingTextRunFactory
{
48 virtual ~nsTransformingTextRunFactory() {}
50 // Default 8-bit path just transforms to Unicode and takes that path
51 nsTransformedTextRun
* MakeTextRun(const PRUint8
* aString
, PRUint32 aLength
,
52 const gfxFontGroup::Parameters
* aParams
,
53 gfxFontGroup
* aFontGroup
, PRUint32 aFlags
,
54 nsStyleContext
** aStyles
, PRBool aOwnsFactory
= PR_TRUE
);
55 nsTransformedTextRun
* MakeTextRun(const PRUnichar
* aString
, PRUint32 aLength
,
56 const gfxFontGroup::Parameters
* aParams
,
57 gfxFontGroup
* aFontGroup
, PRUint32 aFlags
,
58 nsStyleContext
** aStyles
, PRBool aOwnsFactory
= PR_TRUE
);
60 virtual void RebuildTextRun(nsTransformedTextRun
* aTextRun
, gfxContext
* aRefContext
) = 0;
64 * Builds textruns that render their text using a font-variant (i.e.,
67 class nsFontVariantTextRunFactory
: public nsTransformingTextRunFactory
{
69 virtual void RebuildTextRun(nsTransformedTextRun
* aTextRun
, gfxContext
* aRefContext
);
73 * Builds textruns that transform the text in some way (e.g., capitalize)
74 * and then render the text using some other textrun implementation.
76 class nsCaseTransformTextRunFactory
: public nsTransformingTextRunFactory
{
78 // We could add an optimization here so that when there is no inner
79 // factory, no title-case conversion, and no upper-casing of SZLIG, we override
80 // MakeTextRun (after making it virtual in the superclass) and have it
81 // just convert the string to uppercase or lowercase and create the textrun
84 // Takes ownership of aInnerTransformTextRunFactory
85 nsCaseTransformTextRunFactory(nsTransformingTextRunFactory
* aInnerTransformingTextRunFactory
,
86 PRBool aAllUppercase
= PR_FALSE
)
87 : mInnerTransformingTextRunFactory(aInnerTransformingTextRunFactory
),
88 mAllUppercase(aAllUppercase
) {}
90 virtual void RebuildTextRun(nsTransformedTextRun
* aTextRun
, gfxContext
* aRefContext
);
93 nsAutoPtr
<nsTransformingTextRunFactory
> mInnerTransformingTextRunFactory
;
94 PRPackedBool mAllUppercase
;
98 * So that we can reshape as necessary, we store enough information
99 * to fully rebuild the textrun contents.
101 class nsTransformedTextRun
: public gfxTextRun
{
103 static nsTransformedTextRun
*Create(const gfxTextRunFactory::Parameters
* aParams
,
104 nsTransformingTextRunFactory
* aFactory
,
105 gfxFontGroup
* aFontGroup
,
106 const PRUnichar
* aString
, PRUint32 aLength
,
107 const PRUint32 aFlags
, nsStyleContext
** aStyles
,
108 PRBool aOwnsFactory
);
110 ~nsTransformedTextRun() {
116 void SetCapitalization(PRUint32 aStart
, PRUint32 aLength
,
117 PRPackedBool
* aCapitalization
,
118 gfxContext
* aRefContext
);
119 virtual PRBool
SetPotentialLineBreaks(PRUint32 aStart
, PRUint32 aLength
,
120 PRPackedBool
* aBreakBefore
,
121 gfxContext
* aRefContext
);
123 * Called after SetCapitalization and SetPotentialLineBreaks
124 * are done and before we request any data from the textrun. Also always
125 * called after a Create.
127 void FinishSettingProperties(gfxContext
* aRefContext
)
130 mNeedsRebuild
= PR_FALSE
;
131 mFactory
->RebuildTextRun(this, aRefContext
);
135 nsTransformingTextRunFactory
*mFactory
;
136 nsTArray
<nsRefPtr
<nsStyleContext
> > mStyles
;
137 nsTArray
<PRPackedBool
> mCapitalize
;
138 PRPackedBool mOwnsFactory
;
139 PRPackedBool mNeedsRebuild
;
142 nsTransformedTextRun(const gfxTextRunFactory::Parameters
* aParams
,
143 nsTransformingTextRunFactory
* aFactory
,
144 gfxFontGroup
* aFontGroup
,
145 const PRUnichar
* aString
, PRUint32 aLength
,
146 const PRUint32 aFlags
, nsStyleContext
** aStyles
,
148 CompressedGlyph
*aGlyphStorage
)
149 : gfxTextRun(aParams
, aString
, aLength
, aFontGroup
, aFlags
, aGlyphStorage
),
150 mFactory(aFactory
), mOwnsFactory(aOwnsFactory
), mNeedsRebuild(PR_TRUE
)
153 for (i
= 0; i
< aLength
; ++i
) {
154 mStyles
.AppendElement(aStyles
[i
]);
159 #endif /*NSTEXTRUNTRANSFORMATIONS_H_*/