From f0ee31dc93813808a59a0fe576da120de2caf074 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Thu, 4 Oct 2012 06:52:13 +0300 Subject: QTextBoundaryFinder: Introduce BoundaryReason::MandatoryBreak flag that will be returned by boundaryReasons() when the boundary finder is at the line end position (CR, LF, NewLine Function, End of Text, etc.). The MandatoryBreak flag, if set, means the text should be wrapped at a given position. Change-Id: I32d4f570935d2e015bfc5f18915396a15f009fde Reviewed-by: Konstantin Ritt Reviewed-by: Lars Knoll --- src/corelib/tools/qtextboundaryfinder.cpp | 7 ++++++- src/corelib/tools/qtextboundaryfinder.h | 7 ++++--- src/corelib/tools/qunicodetools.cpp | 6 +++--- src/corelib/tools/qunicodetools_p.h | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/tools/qtextboundaryfinder.cpp index 7f120323fe..416a14a35a 100644 --- a/src/corelib/tools/qtextboundaryfinder.cpp +++ b/src/corelib/tools/qtextboundaryfinder.cpp @@ -162,6 +162,8 @@ static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int \value NotAtBoundary The boundary finder is not at a boundary position. \value StartWord The boundary finder is at the start of a word. \value EndWord The boundary finder is at the end of a word. + \value MandatoryBreak Since 5.0. The boundary finder is at the end of line + (can occur for a Line boundary type only). \value SoftHyphen The boundary finder is at the soft hyphen (can occur for a Line boundary type only). */ @@ -477,7 +479,10 @@ QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() cons reasons |= EndWord; break; case Line: - if (pos > 0 && chars[pos - 1].unicode() == QChar::SoftHyphen) + // ### TR#14 LB2 prohibits break at sot + if (d->attributes[pos].mandatoryBreak || pos == 0) + reasons |= MandatoryBreak; + else if (pos > 0 && chars[pos - 1].unicode() == QChar::SoftHyphen) reasons |= SoftHyphen; // fall through case Grapheme: diff --git a/src/corelib/tools/qtextboundaryfinder.h b/src/corelib/tools/qtextboundaryfinder.h index 57c2fda3ea..c752623844 100644 --- a/src/corelib/tools/qtextboundaryfinder.h +++ b/src/corelib/tools/qtextboundaryfinder.h @@ -69,9 +69,10 @@ public: enum BoundaryReason { NotAtBoundary = 0, - StartWord = 1, - EndWord = 2, - SoftHyphen = 4 + StartWord = 0x10, + EndWord = 0x20, + MandatoryBreak = 0x40, + SoftHyphen = 0x80 }; Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason ) diff --git a/src/corelib/tools/qunicodetools.cpp b/src/corelib/tools/qunicodetools.cpp index 1f45575016..3d58f16d19 100644 --- a/src/corelib/tools/qunicodetools.cpp +++ b/src/corelib/tools/qunicodetools.cpp @@ -497,7 +497,7 @@ static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *at if (Q_UNLIKELY(lcls >= QUnicodeTables::LineBreak_CR)) { // LB4: BK!, LB5: (CRxLF|CR|LF|NL)! if (lcls > QUnicodeTables::LineBreak_CR || ncls != QUnicodeTables::LineBreak_LF) - attributes[pos].lineBreak = true; + attributes[pos].lineBreak = attributes[pos].mandatoryBreak = true; goto next; } @@ -547,8 +547,8 @@ static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *at attributes[j].lineBreak = false; } - attributes[0].lineBreak = false; // LB2 - attributes[len].lineBreak = true; // LB3 + attributes[0].lineBreak = attributes[0].mandatoryBreak = false; // LB2 + attributes[len].lineBreak = attributes[len].mandatoryBreak = true; // LB3 } diff --git a/src/corelib/tools/qunicodetools_p.h b/src/corelib/tools/qunicodetools_p.h index b1e9127662..143a4fd7be 100644 --- a/src/corelib/tools/qunicodetools_p.h +++ b/src/corelib/tools/qunicodetools_p.h @@ -66,7 +66,7 @@ struct Q_PACKED QCharAttributes uchar whiteSpace : 1; uchar wordStart : 1; uchar wordEnd : 1; - uchar unused : 1; + uchar mandatoryBreak : 1; }; Q_DECLARE_TYPEINFO(QCharAttributes, Q_PRIMITIVE_TYPE); -- cgit v1.2.3