layout/generic/nsTextRunTransformations.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef NSTEXTRUNTRANSFORMATIONS_H_
michael@0 7 #define NSTEXTRUNTRANSFORMATIONS_H_
michael@0 8
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "mozilla/MemoryReporting.h"
michael@0 11 #include "gfxFont.h"
michael@0 12
michael@0 13 class nsTransformedTextRun;
michael@0 14 class nsStyleContext;
michael@0 15
michael@0 16 class nsTransformingTextRunFactory {
michael@0 17 public:
michael@0 18 virtual ~nsTransformingTextRunFactory() {}
michael@0 19
michael@0 20 // Default 8-bit path just transforms to Unicode and takes that path
michael@0 21 nsTransformedTextRun* MakeTextRun(const uint8_t* aString, uint32_t aLength,
michael@0 22 const gfxFontGroup::Parameters* aParams,
michael@0 23 gfxFontGroup* aFontGroup, uint32_t aFlags,
michael@0 24 nsStyleContext** aStyles, bool aOwnsFactory = true);
michael@0 25 nsTransformedTextRun* MakeTextRun(const char16_t* aString, uint32_t aLength,
michael@0 26 const gfxFontGroup::Parameters* aParams,
michael@0 27 gfxFontGroup* aFontGroup, uint32_t aFlags,
michael@0 28 nsStyleContext** aStyles, bool aOwnsFactory = true);
michael@0 29
michael@0 30 virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) = 0;
michael@0 31 };
michael@0 32
michael@0 33 /**
michael@0 34 * Builds textruns that render their text using a font-variant (i.e.,
michael@0 35 * smallcaps).
michael@0 36 */
michael@0 37 class nsFontVariantTextRunFactory : public nsTransformingTextRunFactory {
michael@0 38 public:
michael@0 39 virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) MOZ_OVERRIDE;
michael@0 40 };
michael@0 41
michael@0 42 /**
michael@0 43 * Builds textruns that transform the text in some way (e.g., capitalize)
michael@0 44 * and then render the text using some other textrun implementation.
michael@0 45 */
michael@0 46 class nsCaseTransformTextRunFactory : public nsTransformingTextRunFactory {
michael@0 47 public:
michael@0 48 // We could add an optimization here so that when there is no inner
michael@0 49 // factory, no title-case conversion, and no upper-casing of SZLIG, we override
michael@0 50 // MakeTextRun (after making it virtual in the superclass) and have it
michael@0 51 // just convert the string to uppercase or lowercase and create the textrun
michael@0 52 // via the fontgroup.
michael@0 53
michael@0 54 // Takes ownership of aInnerTransformTextRunFactory
michael@0 55 nsCaseTransformTextRunFactory(nsTransformingTextRunFactory* aInnerTransformingTextRunFactory,
michael@0 56 bool aAllUppercase = false)
michael@0 57 : mInnerTransformingTextRunFactory(aInnerTransformingTextRunFactory),
michael@0 58 mAllUppercase(aAllUppercase) {}
michael@0 59
michael@0 60 virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) MOZ_OVERRIDE;
michael@0 61
michael@0 62 protected:
michael@0 63 nsAutoPtr<nsTransformingTextRunFactory> mInnerTransformingTextRunFactory;
michael@0 64 bool mAllUppercase;
michael@0 65 };
michael@0 66
michael@0 67 /**
michael@0 68 * So that we can reshape as necessary, we store enough information
michael@0 69 * to fully rebuild the textrun contents.
michael@0 70 */
michael@0 71 class nsTransformedTextRun : public gfxTextRun {
michael@0 72 public:
michael@0 73 static nsTransformedTextRun *Create(const gfxTextRunFactory::Parameters* aParams,
michael@0 74 nsTransformingTextRunFactory* aFactory,
michael@0 75 gfxFontGroup* aFontGroup,
michael@0 76 const char16_t* aString, uint32_t aLength,
michael@0 77 const uint32_t aFlags, nsStyleContext** aStyles,
michael@0 78 bool aOwnsFactory);
michael@0 79
michael@0 80 ~nsTransformedTextRun() {
michael@0 81 if (mOwnsFactory) {
michael@0 82 delete mFactory;
michael@0 83 }
michael@0 84 }
michael@0 85
michael@0 86 void SetCapitalization(uint32_t aStart, uint32_t aLength,
michael@0 87 bool* aCapitalization,
michael@0 88 gfxContext* aRefContext);
michael@0 89 virtual bool SetPotentialLineBreaks(uint32_t aStart, uint32_t aLength,
michael@0 90 uint8_t* aBreakBefore,
michael@0 91 gfxContext* aRefContext);
michael@0 92 /**
michael@0 93 * Called after SetCapitalization and SetPotentialLineBreaks
michael@0 94 * are done and before we request any data from the textrun. Also always
michael@0 95 * called after a Create.
michael@0 96 */
michael@0 97 void FinishSettingProperties(gfxContext* aRefContext)
michael@0 98 {
michael@0 99 if (mNeedsRebuild) {
michael@0 100 mNeedsRebuild = false;
michael@0 101 mFactory->RebuildTextRun(this, aRefContext);
michael@0 102 }
michael@0 103 }
michael@0 104
michael@0 105 // override the gfxTextRun impls to account for additional members here
michael@0 106 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) MOZ_MUST_OVERRIDE;
michael@0 107 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) MOZ_MUST_OVERRIDE;
michael@0 108
michael@0 109 nsTransformingTextRunFactory *mFactory;
michael@0 110 nsTArray<nsRefPtr<nsStyleContext> > mStyles;
michael@0 111 nsTArray<bool> mCapitalize;
michael@0 112 nsString mString;
michael@0 113 bool mOwnsFactory;
michael@0 114 bool mNeedsRebuild;
michael@0 115
michael@0 116 private:
michael@0 117 nsTransformedTextRun(const gfxTextRunFactory::Parameters* aParams,
michael@0 118 nsTransformingTextRunFactory* aFactory,
michael@0 119 gfxFontGroup* aFontGroup,
michael@0 120 const char16_t* aString, uint32_t aLength,
michael@0 121 const uint32_t aFlags, nsStyleContext** aStyles,
michael@0 122 bool aOwnsFactory)
michael@0 123 : gfxTextRun(aParams, aLength, aFontGroup, aFlags),
michael@0 124 mFactory(aFactory), mString(aString, aLength),
michael@0 125 mOwnsFactory(aOwnsFactory), mNeedsRebuild(true)
michael@0 126 {
michael@0 127 mCharacterGlyphs = reinterpret_cast<CompressedGlyph*>(this + 1);
michael@0 128
michael@0 129 uint32_t i;
michael@0 130 for (i = 0; i < aLength; ++i) {
michael@0 131 mStyles.AppendElement(aStyles[i]);
michael@0 132 }
michael@0 133 }
michael@0 134 };
michael@0 135
michael@0 136 /**
michael@0 137 * Copy a given textrun, but merge certain characters into a single logical
michael@0 138 * character. Glyphs for a character are added to the glyph list for the previous
michael@0 139 * character and then the merged character is eliminated. Visually the results
michael@0 140 * are identical.
michael@0 141 *
michael@0 142 * This is used for text-transform:uppercase when we encounter a SZLIG,
michael@0 143 * whose uppercase form is "SS", or other ligature or precomposed form
michael@0 144 * that expands to multiple codepoints during case transformation,
michael@0 145 * and for Greek text when combining diacritics have been deleted.
michael@0 146 *
michael@0 147 * This function is unable to merge characters when they occur in different
michael@0 148 * glyph runs. This only happens in tricky edge cases where a character was
michael@0 149 * decomposed by case-mapping (e.g. there's no precomposed uppercase version
michael@0 150 * of an accented lowercase letter), and then font-matching caused the
michael@0 151 * diacritics to be assigned to a different font than the base character.
michael@0 152 * In this situation, the diacritic(s) get discarded, which is less than
michael@0 153 * ideal, but they probably weren't going to render very well anyway.
michael@0 154 * Bug 543200 will improve this by making font-matching operate on entire
michael@0 155 * clusters instead of individual codepoints.
michael@0 156 *
michael@0 157 * For simplicity, this produces a textrun containing all DetailedGlyphs,
michael@0 158 * no simple glyphs. So don't call it unless you really have merging to do.
michael@0 159 *
michael@0 160 * @param aCharsToMerge when aCharsToMerge[i] is true, this character in aSrc
michael@0 161 * is merged into the previous character
michael@0 162 *
michael@0 163 * @param aDeletedChars when aDeletedChars[i] is true, the character at this
michael@0 164 * position in aDest was deleted (has no corresponding char in aSrc)
michael@0 165 */
michael@0 166 void
michael@0 167 MergeCharactersInTextRun(gfxTextRun* aDest, gfxTextRun* aSrc,
michael@0 168 const bool* aCharsToMerge, const bool* aDeletedChars);
michael@0 169
michael@0 170 gfxTextRunFactory::Parameters
michael@0 171 GetParametersForInner(nsTransformedTextRun* aTextRun, uint32_t* aFlags,
michael@0 172 gfxContext* aRefContext);
michael@0 173
michael@0 174
michael@0 175 #endif /*NSTEXTRUNTRANSFORMATIONS_H_*/

mercurial