2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef NSTEXTRUNTRANSFORMATIONS_H_
|
|
|
|
#define NSTEXTRUNTRANSFORMATIONS_H_
|
|
|
|
|
|
|
|
#include "gfxFont.h"
|
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
class nsTransformedTextRun;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsStyleContext;
|
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
class nsTransformingTextRunFactory {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2007-03-22 16:13:12 -07:00
|
|
|
virtual ~nsTransformingTextRunFactory() {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Default 8-bit path just transforms to Unicode and takes that path
|
2009-01-16 00:17:46 -08:00
|
|
|
nsTransformedTextRun* MakeTextRun(const PRUint8* aString, PRUint32 aLength,
|
|
|
|
const gfxFontGroup::Parameters* aParams,
|
|
|
|
gfxFontGroup* aFontGroup, PRUint32 aFlags,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleContext** aStyles, bool aOwnsFactory = true);
|
2009-01-16 00:17:46 -08:00
|
|
|
nsTransformedTextRun* MakeTextRun(const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
const gfxFontGroup::Parameters* aParams,
|
|
|
|
gfxFontGroup* aFontGroup, PRUint32 aFlags,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleContext** aStyles, bool aOwnsFactory = true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-26 21:22:21 -07:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds textruns that render their text using a font-variant (i.e.,
|
|
|
|
* smallcaps).
|
|
|
|
*/
|
|
|
|
class nsFontVariantTextRunFactory : public nsTransformingTextRunFactory {
|
|
|
|
public:
|
2007-06-26 21:22:21 -07:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds textruns that transform the text in some way (e.g., capitalize)
|
|
|
|
* and then render the text using some other textrun implementation.
|
|
|
|
*/
|
|
|
|
class nsCaseTransformTextRunFactory : public nsTransformingTextRunFactory {
|
|
|
|
public:
|
2007-03-22 16:13:12 -07:00
|
|
|
// We could add an optimization here so that when there is no inner
|
|
|
|
// factory, no title-case conversion, and no upper-casing of SZLIG, we override
|
|
|
|
// MakeTextRun (after making it virtual in the superclass) and have it
|
|
|
|
// just convert the string to uppercase or lowercase and create the textrun
|
|
|
|
// via the fontgroup.
|
|
|
|
|
2007-05-14 20:56:47 -07:00
|
|
|
// Takes ownership of aInnerTransformTextRunFactory
|
2007-05-09 15:04:56 -07:00
|
|
|
nsCaseTransformTextRunFactory(nsTransformingTextRunFactory* aInnerTransformingTextRunFactory,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllUppercase = false)
|
2007-05-09 15:04:56 -07:00
|
|
|
: mInnerTransformingTextRunFactory(aInnerTransformingTextRunFactory),
|
2007-03-22 10:30:00 -07:00
|
|
|
mAllUppercase(aAllUppercase) {}
|
|
|
|
|
2007-06-26 21:22:21 -07:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
protected:
|
|
|
|
nsAutoPtr<nsTransformingTextRunFactory> mInnerTransformingTextRunFactory;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAllUppercase;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-11-11 17:51:31 -08:00
|
|
|
/**
|
|
|
|
* So that we can reshape as necessary, we store enough information
|
|
|
|
* to fully rebuild the textrun contents.
|
|
|
|
*/
|
|
|
|
class nsTransformedTextRun : public gfxTextRun {
|
|
|
|
public:
|
2007-11-15 17:43:47 -08:00
|
|
|
static nsTransformedTextRun *Create(const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
nsTransformingTextRunFactory* aFactory,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
const PRUint32 aFlags, nsStyleContext** aStyles,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aOwnsFactory);
|
2007-11-15 17:43:47 -08:00
|
|
|
|
2007-11-11 17:51:31 -08:00
|
|
|
~nsTransformedTextRun() {
|
|
|
|
if (mOwnsFactory) {
|
|
|
|
delete mFactory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:23:28 -08:00
|
|
|
void SetCapitalization(PRUint32 aStart, PRUint32 aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCapitalization,
|
2009-01-08 16:23:28 -08:00
|
|
|
gfxContext* aRefContext);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength,
|
2011-08-01 18:20:52 -07:00
|
|
|
PRUint8* aBreakBefore,
|
2007-11-11 17:51:31 -08:00
|
|
|
gfxContext* aRefContext);
|
2009-01-08 16:23:28 -08:00
|
|
|
/**
|
|
|
|
* Called after SetCapitalization and SetPotentialLineBreaks
|
|
|
|
* are done and before we request any data from the textrun. Also always
|
|
|
|
* called after a Create.
|
|
|
|
*/
|
|
|
|
void FinishSettingProperties(gfxContext* aRefContext)
|
|
|
|
{
|
|
|
|
if (mNeedsRebuild) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsRebuild = false;
|
2009-01-08 16:23:28 -08:00
|
|
|
mFactory->RebuildTextRun(this, aRefContext);
|
|
|
|
}
|
|
|
|
}
|
2007-11-11 17:51:31 -08:00
|
|
|
|
2011-11-27 19:03:14 -08:00
|
|
|
// override the gfxTextRun impls to account for additional members here
|
|
|
|
virtual NS_MUST_OVERRIDE size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
|
|
|
virtual NS_MUST_OVERRIDE size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
2011-10-14 00:06:35 -07:00
|
|
|
|
2007-11-11 17:51:31 -08:00
|
|
|
nsTransformingTextRunFactory *mFactory;
|
|
|
|
nsTArray<nsRefPtr<nsStyleContext> > mStyles;
|
2011-12-06 04:39:19 -08:00
|
|
|
nsTArray<bool> mCapitalize;
|
|
|
|
nsString mString;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mOwnsFactory;
|
|
|
|
bool mNeedsRebuild;
|
2007-11-15 17:43:47 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsTransformedTextRun(const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
nsTransformingTextRunFactory* aFactory,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
const PRUint32 aFlags, nsStyleContext** aStyles,
|
2012-01-05 03:54:45 -08:00
|
|
|
bool aOwnsFactory)
|
2012-03-15 02:03:51 -07:00
|
|
|
: gfxTextRun(aParams, aLength, aFontGroup, aFlags),
|
2011-12-06 04:39:19 -08:00
|
|
|
mFactory(aFactory), mString(aString, aLength),
|
|
|
|
mOwnsFactory(aOwnsFactory), mNeedsRebuild(true)
|
2007-11-15 17:43:47 -08:00
|
|
|
{
|
2012-01-05 03:54:45 -08:00
|
|
|
mCharacterGlyphs = reinterpret_cast<CompressedGlyph*>(this + 1);
|
|
|
|
|
2007-11-15 17:43:47 -08:00
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < aLength; ++i) {
|
|
|
|
mStyles.AppendElement(aStyles[i]);
|
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
}
|
2007-11-11 17:51:31 -08:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /*NSTEXTRUNTRANSFORMATIONS_H_*/
|