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_
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#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
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTransformedTextRun* MakeTextRun(const uint8_t* aString, uint32_t aLength,
|
2009-01-16 00:17:46 -08:00
|
|
|
const gfxFontGroup::Parameters* aParams,
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxFontGroup* aFontGroup, uint32_t aFlags,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleContext** aStyles, bool aOwnsFactory = true);
|
2014-01-04 07:02:17 -08:00
|
|
|
nsTransformedTextRun* MakeTextRun(const char16_t* aString, uint32_t aLength,
|
2009-01-16 00:17:46 -08:00
|
|
|
const gfxFontGroup::Parameters* aParams,
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxFontGroup* aFontGroup, uint32_t 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:
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) MOZ_OVERRIDE;
|
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) {}
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) MOZ_OVERRIDE;
|
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,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aString, uint32_t aLength,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetCapitalization(uint32_t aStart, uint32_t aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCapitalization,
|
2009-01-08 16:23:28 -08:00
|
|
|
gfxContext* aRefContext);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool SetPotentialLineBreaks(uint32_t aStart, uint32_t aLength,
|
|
|
|
uint8_t* 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
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) MOZ_MUST_OVERRIDE;
|
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) MOZ_MUST_OVERRIDE;
|
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,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aString, uint32_t aLength,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t 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);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-11-15 17:43:47 -08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-12-02 08:49:27 -08:00
|
|
|
/**
|
|
|
|
* Copy a given textrun, but merge certain characters into a single logical
|
|
|
|
* character. Glyphs for a character are added to the glyph list for the previous
|
|
|
|
* character and then the merged character is eliminated. Visually the results
|
|
|
|
* are identical.
|
|
|
|
*
|
|
|
|
* This is used for text-transform:uppercase when we encounter a SZLIG,
|
|
|
|
* whose uppercase form is "SS", or other ligature or precomposed form
|
|
|
|
* that expands to multiple codepoints during case transformation,
|
|
|
|
* and for Greek text when combining diacritics have been deleted.
|
|
|
|
*
|
|
|
|
* This function is unable to merge characters when they occur in different
|
|
|
|
* glyph runs. This only happens in tricky edge cases where a character was
|
|
|
|
* decomposed by case-mapping (e.g. there's no precomposed uppercase version
|
|
|
|
* of an accented lowercase letter), and then font-matching caused the
|
|
|
|
* diacritics to be assigned to a different font than the base character.
|
|
|
|
* In this situation, the diacritic(s) get discarded, which is less than
|
|
|
|
* ideal, but they probably weren't going to render very well anyway.
|
|
|
|
* Bug 543200 will improve this by making font-matching operate on entire
|
|
|
|
* clusters instead of individual codepoints.
|
|
|
|
*
|
|
|
|
* For simplicity, this produces a textrun containing all DetailedGlyphs,
|
|
|
|
* no simple glyphs. So don't call it unless you really have merging to do.
|
|
|
|
*
|
|
|
|
* @param aCharsToMerge when aCharsToMerge[i] is true, this character in aSrc
|
|
|
|
* is merged into the previous character
|
|
|
|
*
|
|
|
|
* @param aDeletedChars when aDeletedChars[i] is true, the character at this
|
|
|
|
* position in aDest was deleted (has no corresponding char in aSrc)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
MergeCharactersInTextRun(gfxTextRun* aDest, gfxTextRun* aSrc,
|
|
|
|
const bool* aCharsToMerge, const bool* aDeletedChars);
|
|
|
|
|
|
|
|
gfxTextRunFactory::Parameters
|
|
|
|
GetParametersForInner(nsTransformedTextRun* aTextRun, uint32_t* aFlags,
|
|
|
|
gfxContext* aRefContext);
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /*NSTEXTRUNTRANSFORMATIONS_H_*/
|