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 NSTEXTFRAMEUTILS_H_
|
|
|
|
#define NSTEXTFRAMEUTILS_H_
|
|
|
|
|
|
|
|
#include "gfxSkipChars.h"
|
|
|
|
|
2012-04-16 15:32:12 -07:00
|
|
|
class nsIContent;
|
|
|
|
struct nsStyleText;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define BIG_TEXT_NODE_SIZE 4096
|
|
|
|
|
2007-07-02 16:36:59 -07:00
|
|
|
#define CH_NBSP 160
|
|
|
|
#define CH_SHY 173
|
|
|
|
#define CH_CJKSP 12288 // U+3000 IDEOGRAPHIC SPACE (CJK Full-Width Space)
|
|
|
|
|
2007-03-22 10:30:00 -07: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-09 15:04:56 -07:00
|
|
|
TEXT_WAS_TRANSFORMED = 0x040000,
|
2009-01-08 16:23:28 -08:00
|
|
|
TEXT_UNUSED_FLAG = 0x080000,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The following flags are set by nsTextFrame
|
|
|
|
|
|
|
|
TEXT_IS_SIMPLE_FLOW = 0x100000,
|
2007-05-09 15:04:56 -07:00
|
|
|
TEXT_INCOMING_WHITESPACE = 0x200000,
|
|
|
|
TEXT_TRAILING_WHITESPACE = 0x400000,
|
2007-05-30 15:27:27 -07:00
|
|
|
TEXT_COMPRESSED_LEADING_WHITESPACE = 0x800000,
|
2007-11-11 17:51:31 -08:00
|
|
|
TEXT_NO_BREAKS = 0x1000000,
|
2007-12-03 00:22:07 -08: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 08:49:27 -08:00
|
|
|
TEXT_HAS_TRAILING_BREAK = 0x4000000,
|
|
|
|
|
|
|
|
// This is set if the textrun was created for a textframe whose
|
2014-01-15 21:10:09 -08:00
|
|
|
// NS_FRAME_IS_IN_SINGLE_CHAR_MI flag is set. This occurs if the textframe
|
2013-12-02 08:49:27 -08:00
|
|
|
// belongs to a MathML <mi> element whose embedded text consists of a
|
|
|
|
// single character.
|
|
|
|
TEXT_IS_SINGLE_CHAR_MI = 0x8000000
|
2009-01-01 05:04:13 -08: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 07:59:16 -08:00
|
|
|
|
|
|
|
// This is defined in gfxTextRunFactory to allow access in gfxFont.
|
|
|
|
// TEXT_USE_MATH_SCRIPT
|
2008-12-18 12:12:53 -08: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-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if aChars/aLength are something that make a space
|
2007-03-22 10:30:00 -07:00
|
|
|
* character not be whitespace when they follow the space character.
|
|
|
|
* For now, this is true if and only if aChars starts with a ZWJ. (This
|
|
|
|
* is what Uniscribe assumes.)
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2014-01-04 07:02:17 -08:00
|
|
|
IsSpaceCombiningSequenceTail(const char16_t* aChars, int32_t aLength) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return aLength > 0 && aChars[0] == 0x200D; // ZWJ
|
|
|
|
}
|
|
|
|
|
2008-08-12 01:31:56 -07:00
|
|
|
enum CompressionMode {
|
|
|
|
COMPRESS_NONE,
|
|
|
|
COMPRESS_WHITESPACE,
|
2012-09-06 22:42:19 -07:00
|
|
|
COMPRESS_WHITESPACE_NEWLINE,
|
|
|
|
DISCARD_NEWLINE
|
2008-08-12 01:31:56 -07:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*
|
2008-08-12 01:31:56 -07:00
|
|
|
* @param aCompressWhitespace control what is compressed to a
|
|
|
|
* single space character: no compression, compress spaces (not followed
|
2012-09-06 22:42:19 -07:00
|
|
|
* by combining mark) and tabs, compress those plus newlines, or
|
|
|
|
* no compression except newlines are discarded.
|
2008-12-18 12:12:53 -08: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-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-01-04 07:02:17 -08:00
|
|
|
static char16_t* TransformText(const char16_t* aText, uint32_t aLength,
|
|
|
|
char16_t* aOutput,
|
2008-08-12 01:31:56 -07:00
|
|
|
CompressionMode aCompression,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t * aIncomingFlags,
|
2014-01-10 01:42:05 -08:00
|
|
|
gfxSkipChars* aSkipChars,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aAnalysisFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint8_t* TransformText(const uint8_t* aText, uint32_t aLength,
|
|
|
|
uint8_t* aOutput,
|
2008-08-12 01:31:56 -07:00
|
|
|
CompressionMode aCompression,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t * aIncomingFlags,
|
2014-01-10 01:42:05 -08:00
|
|
|
gfxSkipChars* aSkipChars,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aAnalysisFlags);
|
2007-11-26 00:27:06 -08:00
|
|
|
|
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
AppendLineBreakOffset(nsTArray<uint32_t>* aArray, uint32_t aOffset)
|
2007-11-26 00:27:06 -08:00
|
|
|
{
|
|
|
|
if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset)
|
|
|
|
return;
|
|
|
|
aArray->AppendElement(aOffset);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t
|
2012-04-16 15:32:12 -07:00
|
|
|
ComputeApproximateLengthWithWhitespaceCompression(nsIContent *aContent,
|
|
|
|
const nsStyleText
|
|
|
|
*aStyleText);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsSkipCharsRunIterator {
|
|
|
|
public:
|
|
|
|
enum LengthMode {
|
2011-10-17 07:59:28 -07:00
|
|
|
LENGTH_UNSKIPPED_ONLY = false,
|
|
|
|
LENGTH_INCLUDES_SKIPPED = true
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
nsSkipCharsRunIterator(const gfxSkipCharsIterator& aStart,
|
2012-08-22 08:56:38 -07:00
|
|
|
LengthMode aLengthIncludesSkipped, uint32_t aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mIterator(aStart), mRemainingLength(aLength), mRunLength(0),
|
2011-10-17 07:59:28 -07:00
|
|
|
mVisitSkipped(false),
|
2007-03-22 10:30:00 -07:00
|
|
|
mLengthIncludesSkipped(aLengthIncludesSkipped) {
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
void SetVisitSkipped() { mVisitSkipped = true; }
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetOriginalOffset(int32_t aOffset) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mIterator.SetOriginalOffset(aOffset);
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetSkippedOffset(uint32_t aOffset) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mIterator.SetSkippedOffset(aOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// guaranteed to return only positive-length runs
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NextRun();
|
|
|
|
bool IsSkipped() const { return mSkipped; }
|
2007-03-22 10:30:00 -07:00
|
|
|
// Always returns something > 0
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetRunLength() const { return mRunLength; }
|
2007-03-22 10:30:00 -07:00
|
|
|
const gfxSkipCharsIterator& GetPos() const { return mIterator; }
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetOriginalOffset() const { return mIterator.GetOriginalOffset(); }
|
|
|
|
uint32_t GetSkippedOffset() const { return mIterator.GetSkippedOffset(); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
gfxSkipCharsIterator mIterator;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRemainingLength;
|
|
|
|
int32_t mRunLength;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mSkipped;
|
|
|
|
bool mVisitSkipped;
|
|
|
|
bool mLengthIncludesSkipped;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*NSTEXTFRAMEUTILS_H_*/
|