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 NSTEXTFRAMEUTILS_H_
|
|
|
|
#define NSTEXTFRAMEUTILS_H_
|
|
|
|
|
|
|
|
#include "gfxSkipChars.h"
|
2014-09-24 21:10:56 +04:00
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsUnicodeProperties.h"
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2012-04-17 02:32:12 +04:00
|
|
|
class nsIContent;
|
|
|
|
struct nsStyleText;
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
#define BIG_TEXT_NODE_SIZE 4096
|
|
|
|
|
2007-07-03 03:36:59 +04:00
|
|
|
#define CH_NBSP 160
|
|
|
|
#define CH_SHY 173
|
|
|
|
#define CH_CJKSP 12288 // U+3000 IDEOGRAPHIC SPACE (CJK Full-Width Space)
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
class nsTextFrameUtils {
|
|
|
|
public:
|
|
|
|
// These constants are used as textrun flags for textframe textruns.
|
|
|
|
enum {
|
|
|
|
// The following flags are set by TransformText
|
|
|
|
|
|
|
|
// the text has at least one untransformed tab character
|
|
|
|
TEXT_HAS_TAB = 0x010000,
|
|
|
|
// the original text has at least one soft hyphen character
|
|
|
|
TEXT_HAS_SHY = 0x020000,
|
2007-05-10 02:04:56 +04:00
|
|
|
TEXT_WAS_TRANSFORMED = 0x040000,
|
2009-01-09 03:23:28 +03:00
|
|
|
TEXT_UNUSED_FLAG = 0x080000,
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
// The following flags are set by nsTextFrame
|
|
|
|
|
|
|
|
TEXT_IS_SIMPLE_FLOW = 0x100000,
|
2007-05-10 02:04:56 +04:00
|
|
|
TEXT_INCOMING_WHITESPACE = 0x200000,
|
|
|
|
TEXT_TRAILING_WHITESPACE = 0x400000,
|
2007-05-31 02:27:27 +04:00
|
|
|
TEXT_COMPRESSED_LEADING_WHITESPACE = 0x800000,
|
2007-11-12 04:51:31 +03:00
|
|
|
TEXT_NO_BREAKS = 0x1000000,
|
2007-12-03 11:22:07 +03:00
|
|
|
TEXT_IS_TRANSFORMED = 0x2000000,
|
|
|
|
// This gets set if there's a break opportunity at the end of the textrun.
|
|
|
|
// We normally don't use this break opportunity because the following text
|
|
|
|
// will have a break opportunity at the start, but it's useful for line
|
|
|
|
// layout to know about it in case the following content is not text
|
2013-12-02 20:49:27 +04:00
|
|
|
TEXT_HAS_TRAILING_BREAK = 0x4000000,
|
|
|
|
|
|
|
|
// This is set if the textrun was created for a textframe whose
|
2014-01-16 09:10:09 +04:00
|
|
|
// NS_FRAME_IS_IN_SINGLE_CHAR_MI flag is set. This occurs if the textframe
|
2013-12-02 20:49:27 +04:00
|
|
|
// belongs to a MathML <mi> element whose embedded text consists of a
|
|
|
|
// single character.
|
2016-07-24 12:40:01 +03:00
|
|
|
TEXT_IS_SINGLE_CHAR_MI = 0x8000000,
|
|
|
|
|
|
|
|
// This is set if the text run might be observing for glyph changes.
|
|
|
|
TEXT_MIGHT_HAVE_GLYPH_CHANGES = 0x10000000,
|
2009-01-01 16:04:13 +03:00
|
|
|
|
|
|
|
// The following are defined by gfxTextRunWordCache rather than here,
|
|
|
|
// so that it also has access to the _INCOMING flag
|
|
|
|
// TEXT_TRAILING_ARABICCHAR
|
|
|
|
// TEXT_INCOMING_ARABICCHAR
|
2014-01-30 19:59:16 +04:00
|
|
|
|
|
|
|
// This is defined in gfxTextRunFactory to allow access in gfxFont.
|
|
|
|
// TEXT_USE_MATH_SCRIPT
|
2008-12-18 23:12:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// These constants are used in TransformText to represent context information
|
|
|
|
// from previous textruns.
|
|
|
|
enum {
|
|
|
|
INCOMING_NONE = 0,
|
|
|
|
INCOMING_WHITESPACE = 1,
|
|
|
|
INCOMING_ARABICCHAR = 2
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-10-17 18:59:28 +04:00
|
|
|
* Returns true if aChars/aLength are something that make a space
|
2014-09-24 21:10:56 +04:00
|
|
|
* character not be whitespace when they follow the space character
|
|
|
|
* (combining mark or join control, ignoring intervening direction
|
|
|
|
* controls).
|
2007-01-16 23:51:52 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2014-01-04 19:02:17 +04:00
|
|
|
IsSpaceCombiningSequenceTail(const char16_t* aChars, int32_t aLength) {
|
2014-09-24 21:10:56 +04:00
|
|
|
return aLength > 0 &&
|
|
|
|
(mozilla::unicode::IsClusterExtender(aChars[0]) ||
|
|
|
|
(IsBidiControl(aChars[0]) &&
|
|
|
|
IsSpaceCombiningSequenceTail(aChars + 1, aLength - 1)
|
|
|
|
)
|
|
|
|
);
|
2007-01-16 23:51:52 +03:00
|
|
|
}
|
2017-01-12 04:27:02 +03:00
|
|
|
static bool
|
|
|
|
IsSpaceCombiningSequenceTail(const uint8_t* aChars, int32_t aLength) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2008-08-12 12:31:56 +04:00
|
|
|
enum CompressionMode {
|
|
|
|
COMPRESS_NONE,
|
|
|
|
COMPRESS_WHITESPACE,
|
2012-09-07 09:42:19 +04:00
|
|
|
COMPRESS_WHITESPACE_NEWLINE,
|
2014-06-05 07:25:15 +04:00
|
|
|
COMPRESS_NONE_TRANSFORM_TO_SPACE
|
2008-08-12 12:31:56 +04:00
|
|
|
};
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
/**
|
|
|
|
* Create a text run from a run of Unicode text. The text may have whitespace
|
|
|
|
* compressed. A preformatted tab is sent to the text run as a single space.
|
|
|
|
* (Tab spacing must be performed by textframe later.) Certain other
|
|
|
|
* characters are discarded.
|
2017-01-12 04:27:01 +03:00
|
|
|
*
|
2016-11-28 15:45:37 +03:00
|
|
|
* @param aCompression control what is compressed to a
|
2008-08-12 12:31:56 +04:00
|
|
|
* single space character: no compression, compress spaces (not followed
|
2012-09-07 09:42:19 +04:00
|
|
|
* by combining mark) and tabs, compress those plus newlines, or
|
|
|
|
* no compression except newlines are discarded.
|
2008-12-18 23:12:53 +03:00
|
|
|
* @param aIncomingFlags a flag indicating whether there was whitespace
|
|
|
|
* or an Arabic character preceding this text. We set it to indicate if
|
|
|
|
* there's an Arabic character or whitespace preceding the end of this text.
|
2007-01-16 23:51:52 +03:00
|
|
|
*/
|
2017-01-12 04:27:02 +03:00
|
|
|
template<class CharT>
|
|
|
|
static CharT* TransformText(const CharT* aText, uint32_t aLength,
|
|
|
|
CharT* aOutput,
|
|
|
|
CompressionMode aCompression,
|
|
|
|
uint8_t* aIncomingFlags,
|
|
|
|
gfxSkipChars* aSkipChars,
|
|
|
|
uint32_t* aAnalysisFlags);
|
2007-11-26 11:27:06 +03:00
|
|
|
|
2017-01-17 08:45:43 +03:00
|
|
|
/**
|
|
|
|
* Returns whether aChar is a character that nsTextFrameUtils::TransformText
|
|
|
|
* might mark as skipped. This is used by
|
|
|
|
* SVGTextContentElement::GetNumberOfChars to know whether reflowing frames,
|
|
|
|
* so that we have the results of TransformText, is required, or whether we
|
|
|
|
* can use a fast path instead.
|
|
|
|
*/
|
|
|
|
template<class CharT>
|
|
|
|
static bool IsSkippableCharacterForTransformText(CharT aChar);
|
|
|
|
|
2007-11-26 11:27:06 +03:00
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
AppendLineBreakOffset(nsTArray<uint32_t>* aArray, uint32_t aOffset)
|
2007-11-26 11:27:06 +03:00
|
|
|
{
|
|
|
|
if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset)
|
|
|
|
return;
|
|
|
|
aArray->AppendElement(aOffset);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t
|
2012-04-17 02:32:12 +04:00
|
|
|
ComputeApproximateLengthWithWhitespaceCompression(nsIContent *aContent,
|
2016-11-28 15:45:37 +03:00
|
|
|
const nsStyleText*
|
|
|
|
aStyleText);
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsSkipCharsRunIterator {
|
|
|
|
public:
|
|
|
|
enum LengthMode {
|
2011-10-17 18:59:28 +04:00
|
|
|
LENGTH_UNSKIPPED_ONLY = false,
|
|
|
|
LENGTH_INCLUDES_SKIPPED = true
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
nsSkipCharsRunIterator(const gfxSkipCharsIterator& aStart,
|
2012-08-22 19:56:38 +04:00
|
|
|
LengthMode aLengthIncludesSkipped, uint32_t aLength)
|
2007-01-16 23:51:52 +03:00
|
|
|
: mIterator(aStart), mRemainingLength(aLength), mRunLength(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mVisitSkipped(false),
|
2007-01-16 23:51:52 +03:00
|
|
|
mLengthIncludesSkipped(aLengthIncludesSkipped) {
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
void SetVisitSkipped() { mVisitSkipped = true; }
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetOriginalOffset(int32_t aOffset) {
|
2007-01-16 23:51:52 +03:00
|
|
|
mIterator.SetOriginalOffset(aOffset);
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetSkippedOffset(uint32_t aOffset) {
|
2007-01-16 23:51:52 +03:00
|
|
|
mIterator.SetSkippedOffset(aOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// guaranteed to return only positive-length runs
|
2011-09-29 10:19:26 +04:00
|
|
|
bool NextRun();
|
|
|
|
bool IsSkipped() const { return mSkipped; }
|
2007-01-16 23:51:52 +03:00
|
|
|
// Always returns something > 0
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetRunLength() const { return mRunLength; }
|
2007-01-16 23:51:52 +03:00
|
|
|
const gfxSkipCharsIterator& GetPos() const { return mIterator; }
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetOriginalOffset() const { return mIterator.GetOriginalOffset(); }
|
|
|
|
uint32_t GetSkippedOffset() const { return mIterator.GetSkippedOffset(); }
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
gfxSkipCharsIterator mIterator;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRemainingLength;
|
|
|
|
int32_t mRunLength;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSkipped;
|
|
|
|
bool mVisitSkipped;
|
|
|
|
bool mLengthIncludesSkipped;
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*NSTEXTFRAMEUTILS_H_*/
|