1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsTextFrameUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,168 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NSTEXTFRAMEUTILS_H_ 1.10 +#define NSTEXTFRAMEUTILS_H_ 1.11 + 1.12 +#include "gfxSkipChars.h" 1.13 + 1.14 +class nsIContent; 1.15 +struct nsStyleText; 1.16 + 1.17 +#define BIG_TEXT_NODE_SIZE 4096 1.18 + 1.19 +#define CH_NBSP 160 1.20 +#define CH_SHY 173 1.21 +#define CH_CJKSP 12288 // U+3000 IDEOGRAPHIC SPACE (CJK Full-Width Space) 1.22 + 1.23 +class nsTextFrameUtils { 1.24 +public: 1.25 + // These constants are used as textrun flags for textframe textruns. 1.26 + enum { 1.27 + // The following flags are set by TransformText 1.28 + 1.29 + // the text has at least one untransformed tab character 1.30 + TEXT_HAS_TAB = 0x010000, 1.31 + // the original text has at least one soft hyphen character 1.32 + TEXT_HAS_SHY = 0x020000, 1.33 + TEXT_WAS_TRANSFORMED = 0x040000, 1.34 + TEXT_UNUSED_FLAG = 0x080000, 1.35 + 1.36 + // The following flags are set by nsTextFrame 1.37 + 1.38 + TEXT_IS_SIMPLE_FLOW = 0x100000, 1.39 + TEXT_INCOMING_WHITESPACE = 0x200000, 1.40 + TEXT_TRAILING_WHITESPACE = 0x400000, 1.41 + TEXT_COMPRESSED_LEADING_WHITESPACE = 0x800000, 1.42 + TEXT_NO_BREAKS = 0x1000000, 1.43 + TEXT_IS_TRANSFORMED = 0x2000000, 1.44 + // This gets set if there's a break opportunity at the end of the textrun. 1.45 + // We normally don't use this break opportunity because the following text 1.46 + // will have a break opportunity at the start, but it's useful for line 1.47 + // layout to know about it in case the following content is not text 1.48 + TEXT_HAS_TRAILING_BREAK = 0x4000000, 1.49 + 1.50 + // This is set if the textrun was created for a textframe whose 1.51 + // NS_FRAME_IS_IN_SINGLE_CHAR_MI flag is set. This occurs if the textframe 1.52 + // belongs to a MathML <mi> element whose embedded text consists of a 1.53 + // single character. 1.54 + TEXT_IS_SINGLE_CHAR_MI = 0x8000000 1.55 + 1.56 + // The following are defined by gfxTextRunWordCache rather than here, 1.57 + // so that it also has access to the _INCOMING flag 1.58 + // TEXT_TRAILING_ARABICCHAR 1.59 + // TEXT_INCOMING_ARABICCHAR 1.60 + 1.61 + // This is defined in gfxTextRunFactory to allow access in gfxFont. 1.62 + // TEXT_USE_MATH_SCRIPT 1.63 + }; 1.64 + 1.65 + // These constants are used in TransformText to represent context information 1.66 + // from previous textruns. 1.67 + enum { 1.68 + INCOMING_NONE = 0, 1.69 + INCOMING_WHITESPACE = 1, 1.70 + INCOMING_ARABICCHAR = 2 1.71 + }; 1.72 + 1.73 + /** 1.74 + * Returns true if aChars/aLength are something that make a space 1.75 + * character not be whitespace when they follow the space character. 1.76 + * For now, this is true if and only if aChars starts with a ZWJ. (This 1.77 + * is what Uniscribe assumes.) 1.78 + */ 1.79 + static bool 1.80 + IsSpaceCombiningSequenceTail(const char16_t* aChars, int32_t aLength) { 1.81 + return aLength > 0 && aChars[0] == 0x200D; // ZWJ 1.82 + } 1.83 + 1.84 + enum CompressionMode { 1.85 + COMPRESS_NONE, 1.86 + COMPRESS_WHITESPACE, 1.87 + COMPRESS_WHITESPACE_NEWLINE, 1.88 + DISCARD_NEWLINE 1.89 + }; 1.90 + 1.91 + /** 1.92 + * Create a text run from a run of Unicode text. The text may have whitespace 1.93 + * compressed. A preformatted tab is sent to the text run as a single space. 1.94 + * (Tab spacing must be performed by textframe later.) Certain other 1.95 + * characters are discarded. 1.96 + * 1.97 + * @param aCompressWhitespace control what is compressed to a 1.98 + * single space character: no compression, compress spaces (not followed 1.99 + * by combining mark) and tabs, compress those plus newlines, or 1.100 + * no compression except newlines are discarded. 1.101 + * @param aIncomingFlags a flag indicating whether there was whitespace 1.102 + * or an Arabic character preceding this text. We set it to indicate if 1.103 + * there's an Arabic character or whitespace preceding the end of this text. 1.104 + */ 1.105 + static char16_t* TransformText(const char16_t* aText, uint32_t aLength, 1.106 + char16_t* aOutput, 1.107 + CompressionMode aCompression, 1.108 + uint8_t * aIncomingFlags, 1.109 + gfxSkipChars* aSkipChars, 1.110 + uint32_t* aAnalysisFlags); 1.111 + 1.112 + static uint8_t* TransformText(const uint8_t* aText, uint32_t aLength, 1.113 + uint8_t* aOutput, 1.114 + CompressionMode aCompression, 1.115 + uint8_t * aIncomingFlags, 1.116 + gfxSkipChars* aSkipChars, 1.117 + uint32_t* aAnalysisFlags); 1.118 + 1.119 + static void 1.120 + AppendLineBreakOffset(nsTArray<uint32_t>* aArray, uint32_t aOffset) 1.121 + { 1.122 + if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset) 1.123 + return; 1.124 + aArray->AppendElement(aOffset); 1.125 + } 1.126 + 1.127 + static uint32_t 1.128 + ComputeApproximateLengthWithWhitespaceCompression(nsIContent *aContent, 1.129 + const nsStyleText 1.130 + *aStyleText); 1.131 +}; 1.132 + 1.133 +class nsSkipCharsRunIterator { 1.134 +public: 1.135 + enum LengthMode { 1.136 + LENGTH_UNSKIPPED_ONLY = false, 1.137 + LENGTH_INCLUDES_SKIPPED = true 1.138 + }; 1.139 + nsSkipCharsRunIterator(const gfxSkipCharsIterator& aStart, 1.140 + LengthMode aLengthIncludesSkipped, uint32_t aLength) 1.141 + : mIterator(aStart), mRemainingLength(aLength), mRunLength(0), 1.142 + mVisitSkipped(false), 1.143 + mLengthIncludesSkipped(aLengthIncludesSkipped) { 1.144 + } 1.145 + void SetVisitSkipped() { mVisitSkipped = true; } 1.146 + void SetOriginalOffset(int32_t aOffset) { 1.147 + mIterator.SetOriginalOffset(aOffset); 1.148 + } 1.149 + void SetSkippedOffset(uint32_t aOffset) { 1.150 + mIterator.SetSkippedOffset(aOffset); 1.151 + } 1.152 + 1.153 + // guaranteed to return only positive-length runs 1.154 + bool NextRun(); 1.155 + bool IsSkipped() const { return mSkipped; } 1.156 + // Always returns something > 0 1.157 + int32_t GetRunLength() const { return mRunLength; } 1.158 + const gfxSkipCharsIterator& GetPos() const { return mIterator; } 1.159 + int32_t GetOriginalOffset() const { return mIterator.GetOriginalOffset(); } 1.160 + uint32_t GetSkippedOffset() const { return mIterator.GetSkippedOffset(); } 1.161 + 1.162 +private: 1.163 + gfxSkipCharsIterator mIterator; 1.164 + int32_t mRemainingLength; 1.165 + int32_t mRunLength; 1.166 + bool mSkipped; 1.167 + bool mVisitSkipped; 1.168 + bool mLengthIncludesSkipped; 1.169 +}; 1.170 + 1.171 +#endif /*NSTEXTFRAMEUTILS_H_*/