Improve the word wrapping a bit. This should eventually use the LocalKit when
it's ready. For now, I just tried to fix stuff like breaking before punctuations. I had trouble wrapping my mind around the wrapping code, so I didn't include as much cases as I wanted. Basically, the wrapping code assumes that a spot where CanEndLine() returns true must be a white space character, which wouldn't be the case. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30075 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -100,7 +100,9 @@ static const uint32 kFlattenedTextRunArrayVersion = 0;
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
B_SEPARATOR_CHARACTER,
|
B_SEPARATOR_CHARACTER,
|
||||||
B_OTHER_CHARACTER
|
B_PUNCTUATION_CHARACTER,
|
||||||
|
B_OTHER_CHARACTER,
|
||||||
|
B_END_OF_TEXT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1953,8 +1955,35 @@ BTextView::FindWord(int32 inOffset, int32 *outFromOffset, int32 *outToOffset)
|
|||||||
bool
|
bool
|
||||||
BTextView::CanEndLine(int32 offset)
|
BTextView::CanEndLine(int32 offset)
|
||||||
{
|
{
|
||||||
// TODO: Could be improved, the bebook says there are other checks to do
|
// TODO: This has to be improved a lot, but also the wrapping code.
|
||||||
return (_CharClassification(offset) == B_SEPARATOR_CHARACTER);
|
// It should use the forthcomming LocalKit.
|
||||||
|
uint32 classification = _CharClassification(offset);
|
||||||
|
if (classification == B_END_OF_TEXT
|
||||||
|
|| classification == B_SEPARATOR_CHARACTER) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 nextClassification = _CharClassification(offset + 1);
|
||||||
|
if (nextClassification == B_END_OF_TEXT)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (classification == B_PUNCTUATION_CHARACTER
|
||||||
|
&& nextClassification == B_OTHER_CHARACTER) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: This cannot be enabled, since the wrapping code things the char
|
||||||
|
// is a trailing space or something. Otherwise it would allow to treat
|
||||||
|
// something like "..." as a word.
|
||||||
|
// uint32 nextNextClassification = _CharClassification(offset + 2);
|
||||||
|
//
|
||||||
|
// if (classification == B_OTHER_CHARACTER
|
||||||
|
// && nextClassification == B_PUNCTUATION_CHARACTER
|
||||||
|
// && nextClassification == nextNextClassification) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3679,9 +3708,9 @@ BTextView::_FindLineBreak(int32 fromOffset, float *outAscent, float *outDescent,
|
|||||||
|
|
||||||
int32 offset = fromOffset;
|
int32 offset = fromOffset;
|
||||||
|
|
||||||
|
if (!fWrap) {
|
||||||
// Text wrapping is turned off.
|
// Text wrapping is turned off.
|
||||||
// Just find the offset of the first \n character
|
// Just find the offset of the first \n character
|
||||||
if (!fWrap) {
|
|
||||||
offset = limit - fromOffset;
|
offset = limit - fromOffset;
|
||||||
fText->FindChar(B_ENTER, fromOffset, &offset);
|
fText->FindChar(B_ENTER, fromOffset, &offset);
|
||||||
offset += fromOffset;
|
offset += fromOffset;
|
||||||
@@ -4829,10 +4858,11 @@ BTextView::_CharClassification(int32 offset) const
|
|||||||
// for separator characters ?
|
// for separator characters ?
|
||||||
// Andrew suggested to have a look at UnicodeBlockObject.h
|
// Andrew suggested to have a look at UnicodeBlockObject.h
|
||||||
switch (fText->RealCharAt(offset)) {
|
switch (fText->RealCharAt(offset)) {
|
||||||
|
case '\0':
|
||||||
|
return B_END_OF_TEXT;
|
||||||
|
|
||||||
case B_SPACE:
|
case B_SPACE:
|
||||||
case '_':
|
case '_':
|
||||||
case '.':
|
|
||||||
case '\0':
|
|
||||||
case B_TAB:
|
case B_TAB:
|
||||||
case B_ENTER:
|
case B_ENTER:
|
||||||
case '&':
|
case '&':
|
||||||
@@ -4847,6 +4877,11 @@ BTextView::_CharClassification(int32 offset) const
|
|||||||
case '^':
|
case '^':
|
||||||
case '|':
|
case '|':
|
||||||
return B_SEPARATOR_CHARACTER;
|
return B_SEPARATOR_CHARACTER;
|
||||||
|
|
||||||
|
case '.':
|
||||||
|
case ',':
|
||||||
|
return B_PUNCTUATION_CHARACTER;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_OTHER_CHARACTER;
|
return B_OTHER_CHARACTER;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user