[fbreader] Center justified images

This commit is contained in:
Slava Monich 2015-08-04 18:33:10 +03:00
parent 99100be8d7
commit 2457795ce8

View file

@ -67,11 +67,24 @@ void ZLTextArea::prepareTextLine(Style &style, const ZLTextLineInfo &info, int y
bool wordOccured = false; bool wordOccured = false;
bool endsWithLineBreak = false; bool endsWithLineBreak = false;
bool onlyImage = false;
if (info.RealStart < info.End) { if (info.RealStart < info.End) {
ZLTextWordCursor last(info.End); ZLTextWordCursor last(info.End);
last.previousWord(); last.previousWord();
if (last.element().kind() == ZLTextElement::LINE_BREAK_ELEMENT) { while (last.element().kind() == ZLTextElement::CONTROL_ELEMENT && info.RealStart < last) {
last.previousWord();
}
switch (last.element().kind()) {
case ZLTextElement::LINE_BREAK_ELEMENT:
endsWithLineBreak = true; endsWithLineBreak = true;
break;
case ZLTextElement::IMAGE_ELEMENT:
if (last == info.RealStart) {
onlyImage = true;
}
break;
default:
break;
} }
} }
@ -94,14 +107,17 @@ void ZLTextArea::prepareTextLine(Style &style, const ZLTextLineInfo &info, int y
break; break;
case ALIGN_LINESTART: case ALIGN_LINESTART:
break; break;
case ALIGN_CENTER:
x += (metrics.FullWidth - style.textStyle()->lineEndIndent(metrics, isRtl()) - info.Width) / 2;
break;
case ALIGN_JUSTIFY: case ALIGN_JUSTIFY:
if (!onlyImage) {
if (!endsWithLineBreak && !endOfParagraph && info.End.element().kind() != ZLTextElement::AFTER_PARAGRAPH_ELEMENT) { if (!endsWithLineBreak && !endOfParagraph && info.End.element().kind() != ZLTextElement::AFTER_PARAGRAPH_ELEMENT) {
fullCorrection = metrics.FullWidth - style.textStyle()->lineEndIndent(metrics, isRtl()) - info.Width; fullCorrection = metrics.FullWidth - style.textStyle()->lineEndIndent(metrics, isRtl()) - info.Width;
} }
break; break;
}
// Fall through to center "justified" images
case ALIGN_CENTER:
x += (metrics.FullWidth - style.textStyle()->lineEndIndent(metrics, isRtl()) - info.Width) / 2;
break;
case ALIGN_UNDEFINED: case ALIGN_UNDEFINED:
break; break;
} }