2007-01-16 23:51:52 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
#ifndef NSTEXTRUNTRANSFORMATIONS_H_
|
|
|
|
#define NSTEXTRUNTRANSFORMATIONS_H_
|
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-07-08 09:08:00 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2014-05-26 17:23:32 +04:00
|
|
|
#include "nsStyleContext.h"
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2007-03-23 02:13:12 +03:00
|
|
|
class nsTransformedTextRun;
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
struct nsTransformedCharStyle final {
|
2015-02-10 13:30:25 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsTransformedCharStyle)
|
|
|
|
|
|
|
|
explicit nsTransformedCharStyle(nsStyleContext* aContext)
|
|
|
|
: mFont(aContext->StyleFont()->mFont)
|
|
|
|
, mLanguage(aContext->StyleFont()->mLanguage)
|
|
|
|
, mPresContext(aContext->PresContext())
|
|
|
|
, mScriptSizeMultiplier(aContext->StyleFont()->mScriptSizeMultiplier)
|
|
|
|
, mTextTransform(aContext->StyleText()->mTextTransform)
|
|
|
|
, mMathVariant(aContext->StyleFont()->mMathVariant)
|
|
|
|
, mExplicitLanguage(aContext->StyleFont()->mExplicitLanguage) {}
|
|
|
|
|
|
|
|
nsFont mFont;
|
|
|
|
nsCOMPtr<nsIAtom> mLanguage;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> mPresContext;
|
2015-02-10 13:30:25 +03:00
|
|
|
float mScriptSizeMultiplier;
|
|
|
|
uint8_t mTextTransform;
|
|
|
|
uint8_t mMathVariant;
|
|
|
|
bool mExplicitLanguage;
|
2016-04-22 02:18:41 +03:00
|
|
|
bool mForceNonFullWidth = false;
|
2015-02-10 13:30:25 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
~nsTransformedCharStyle() {}
|
|
|
|
nsTransformedCharStyle(const nsTransformedCharStyle& aOther) = delete;
|
|
|
|
nsTransformedCharStyle& operator=(const nsTransformedCharStyle& aOther) = delete;
|
|
|
|
};
|
|
|
|
|
2007-03-23 02:13:12 +03:00
|
|
|
class nsTransformingTextRunFactory {
|
2007-01-16 23:51:52 +03:00
|
|
|
public:
|
2007-03-23 02:13:12 +03:00
|
|
|
virtual ~nsTransformingTextRunFactory() {}
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
// Default 8-bit path just transforms to Unicode and takes that path
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<nsTransformedTextRun>
|
2016-04-19 19:13:28 +03:00
|
|
|
MakeTextRun(const uint8_t* aString, uint32_t aLength,
|
|
|
|
const gfxFontGroup::Parameters* aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
2016-04-19 19:13:28 +03:00
|
|
|
nsTArray<RefPtr<nsTransformedCharStyle>>&& aStyles,
|
|
|
|
bool aOwnsFactory);
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<nsTransformedTextRun>
|
2016-04-19 19:13:28 +03:00
|
|
|
MakeTextRun(const char16_t* aString, uint32_t aLength,
|
|
|
|
const gfxFontGroup::Parameters* aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
2016-04-19 19:13:28 +03:00
|
|
|
nsTArray<RefPtr<nsTransformedCharStyle>>&& aStyles,
|
|
|
|
bool aOwnsFactory);
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun,
|
2015-12-16 00:56:41 +03:00
|
|
|
mozilla::gfx::DrawTarget* aRefDrawTarget,
|
2014-12-22 19:35:54 +03:00
|
|
|
gfxMissingFontRecorder* aMFR) = 0;
|
2007-01-16 23:51:52 +03: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-23 02:13:12 +03: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-15 07:56:47 +04:00
|
|
|
// Takes ownership of aInnerTransformTextRunFactory
|
2016-12-01 01:50:22 +03:00
|
|
|
explicit nsCaseTransformTextRunFactory(mozilla::UniquePtr<nsTransformingTextRunFactory> aInnerTransformingTextRunFactory,
|
2014-08-20 08:58:22 +04:00
|
|
|
bool aAllUppercase = false)
|
2016-07-08 09:08:00 +03:00
|
|
|
: mInnerTransformingTextRunFactory(Move(aInnerTransformingTextRunFactory)),
|
2007-01-16 23:51:52 +03:00
|
|
|
mAllUppercase(aAllUppercase) {}
|
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun,
|
2015-12-16 00:56:41 +03:00
|
|
|
mozilla::gfx::DrawTarget* aRefDrawTarget,
|
2015-03-21 19:28:04 +03:00
|
|
|
gfxMissingFontRecorder* aMFR) override;
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2014-05-26 17:23:30 +04:00
|
|
|
// Perform a transformation on the given string, writing the result into
|
|
|
|
// aConvertedString. If aAllUppercase is true, the transform is (global)
|
|
|
|
// upper-casing, and aLanguage is used to determine any language-specific
|
|
|
|
// behavior; otherwise, an nsTransformedTextRun should be passed in
|
|
|
|
// as aTextRun and its styles will be used to determine the transform(s)
|
|
|
|
// to be applied.
|
|
|
|
// If such an input textrun is provided, then its line-breaks and styles
|
|
|
|
// will be copied to the output arrays, which must also be provided by
|
|
|
|
// the caller. For the global upper-casing usage (no input textrun),
|
|
|
|
// these are ignored.
|
|
|
|
static bool TransformString(const nsAString& aString,
|
|
|
|
nsString& aConvertedString,
|
|
|
|
bool aAllUppercase,
|
|
|
|
const nsIAtom* aLanguage,
|
|
|
|
nsTArray<bool>& aCharsToMergeArray,
|
|
|
|
nsTArray<bool>& aDeletedCharsArray,
|
2016-08-20 02:08:24 +03:00
|
|
|
const nsTransformedTextRun* aTextRun = nullptr,
|
|
|
|
uint32_t aOffsetInTextRun = 0,
|
2014-05-26 17:23:30 +04:00
|
|
|
nsTArray<uint8_t>* aCanBreakBeforeArray = nullptr,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsTransformedCharStyle>>* aStyleArray = nullptr);
|
2014-05-26 17:23:30 +04:00
|
|
|
|
2007-03-23 02:13:12 +03:00
|
|
|
protected:
|
2016-07-08 09:08:00 +03:00
|
|
|
mozilla::UniquePtr<nsTransformingTextRunFactory> mInnerTransformingTextRunFactory;
|
|
|
|
bool mAllUppercase;
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
|
2007-11-12 04:51:31 +03:00
|
|
|
/**
|
|
|
|
* So that we can reshape as necessary, we store enough information
|
|
|
|
* to fully rebuild the textrun contents.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsTransformedTextRun final : public gfxTextRun {
|
2007-11-12 04:51:31 +03:00
|
|
|
public:
|
2015-02-10 13:30:25 +03:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
static already_AddRefed<nsTransformedTextRun>
|
2016-04-19 19:13:28 +03:00
|
|
|
Create(const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
nsTransformingTextRunFactory* aFactory,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const char16_t* aString, uint32_t aLength,
|
2017-05-05 00:27:05 +03:00
|
|
|
const mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
const nsTextFrameUtils::Flags aFlags2,
|
2016-04-19 19:13:28 +03:00
|
|
|
nsTArray<RefPtr<nsTransformedCharStyle>>&& aStyles,
|
|
|
|
bool aOwnsFactory);
|
2007-11-16 04:43:47 +03:00
|
|
|
|
2007-11-12 04:51:31 +03:00
|
|
|
~nsTransformedTextRun() {
|
|
|
|
if (mOwnsFactory) {
|
|
|
|
delete mFactory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetCapitalization(uint32_t aStart, uint32_t aLength,
|
2015-12-16 00:56:40 +03:00
|
|
|
bool* aCapitalization);
|
2016-10-11 15:47:11 +03:00
|
|
|
virtual bool SetPotentialLineBreaks(Range aRange,
|
|
|
|
const uint8_t* aBreakBefore);
|
2009-01-09 03:23:28 +03:00
|
|
|
/**
|
|
|
|
* Called after SetCapitalization and SetPotentialLineBreaks
|
|
|
|
* are done and before we request any data from the textrun. Also always
|
|
|
|
* called after a Create.
|
|
|
|
*/
|
2015-12-16 00:56:41 +03:00
|
|
|
void FinishSettingProperties(mozilla::gfx::DrawTarget* aRefDrawTarget,
|
2014-12-22 19:35:54 +03:00
|
|
|
gfxMissingFontRecorder* aMFR)
|
2009-01-09 03:23:28 +03:00
|
|
|
{
|
|
|
|
if (mNeedsRebuild) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsRebuild = false;
|
2015-12-16 00:56:41 +03:00
|
|
|
mFactory->RebuildTextRun(this, aRefDrawTarget, aMFR);
|
2009-01-09 03:23:28 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-12 04:51:31 +03:00
|
|
|
|
2011-11-28 07:03:14 +04:00
|
|
|
// override the gfxTextRun impls to account for additional members here
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) MOZ_MUST_OVERRIDE;
|
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) MOZ_MUST_OVERRIDE;
|
2011-10-14 11:06:35 +04:00
|
|
|
|
2007-11-12 04:51:31 +03:00
|
|
|
nsTransformingTextRunFactory *mFactory;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsTransformedCharStyle>> mStyles;
|
2011-12-06 16:39:19 +04:00
|
|
|
nsTArray<bool> mCapitalize;
|
|
|
|
nsString mString;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOwnsFactory;
|
|
|
|
bool mNeedsRebuild;
|
2007-11-16 04:43:47 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsTransformedTextRun(const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
nsTransformingTextRunFactory* aFactory,
|
|
|
|
gfxFontGroup* aFontGroup,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aString, uint32_t aLength,
|
2017-05-05 00:27:05 +03:00
|
|
|
const mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
const nsTextFrameUtils::Flags aFlags2,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsTransformedCharStyle>>&& aStyles,
|
2012-01-05 15:54:45 +04:00
|
|
|
bool aOwnsFactory)
|
2017-05-05 00:25:16 +03:00
|
|
|
: gfxTextRun(aParams, aLength, aFontGroup, aFlags, aFlags2),
|
2015-02-10 13:30:25 +03:00
|
|
|
mFactory(aFactory), mStyles(aStyles), mString(aString, aLength),
|
2011-12-06 16:39:19 +04:00
|
|
|
mOwnsFactory(aOwnsFactory), mNeedsRebuild(true)
|
2007-11-16 04:43:47 +03:00
|
|
|
{
|
2012-01-05 15:54:45 +04:00
|
|
|
mCharacterGlyphs = reinterpret_cast<CompressedGlyph*>(this + 1);
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2007-11-12 04:51:31 +03:00
|
|
|
};
|
|
|
|
|
2013-12-02 20:49:27 +04: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
|
2017-05-05 00:25:16 +03:00
|
|
|
GetParametersForInner(nsTransformedTextRun* aTextRun,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags* aFlags,
|
2015-12-16 00:56:41 +03:00
|
|
|
mozilla::gfx::DrawTarget* aRefDrawTarget);
|
2013-12-02 20:49:27 +04:00
|
|
|
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
#endif /*NSTEXTRUNTRANSFORMATIONS_H_*/
|