mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
overlap bottom margin area of top element with top margin area of bottom element
This commit is contained in:
parent
8a0c09c934
commit
e4280c88ec
2 changed files with 61 additions and 17 deletions
|
@ -35,7 +35,9 @@ final class ZLTextLineInfo {
|
||||||
int Width;
|
int Width;
|
||||||
int Height;
|
int Height;
|
||||||
int Descent;
|
int Descent;
|
||||||
|
int VSpaceBefore;
|
||||||
int VSpaceAfter;
|
int VSpaceAfter;
|
||||||
|
boolean PreviousInfoUsed;
|
||||||
int SpaceCounter;
|
int SpaceCounter;
|
||||||
ZLTextStyle StartStyle;
|
ZLTextStyle StartStyle;
|
||||||
|
|
||||||
|
@ -57,6 +59,14 @@ final class ZLTextLineInfo {
|
||||||
return EndElementIndex == ParagraphCursorLength;
|
return EndElementIndex == ParagraphCursorLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void adjust(ZLTextLineInfo previous) {
|
||||||
|
if (!PreviousInfoUsed && previous != null) {
|
||||||
|
Height -= Math.min(previous.VSpaceAfter, VSpaceBefore);
|
||||||
|
PreviousInfoUsed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
ZLTextLineInfo info = (ZLTextLineInfo)o;
|
ZLTextLineInfo info = (ZLTextLineInfo)o;
|
||||||
return
|
return
|
||||||
|
@ -65,6 +75,7 @@ final class ZLTextLineInfo {
|
||||||
(StartCharIndex == info.StartCharIndex);
|
(StartCharIndex == info.StartCharIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ParagraphCursor.hashCode() + StartElementIndex + 239 * StartCharIndex;
|
return ParagraphCursor.hashCode() + StartElementIndex + 239 * StartCharIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -495,7 +495,9 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
int x = getLeftMargin();
|
int x = getLeftMargin();
|
||||||
int y = getTopMargin();
|
int y = getTopMargin();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
ZLTextLineInfo previousInfo = null;
|
||||||
for (ZLTextLineInfo info : lineInfos) {
|
for (ZLTextLineInfo info : lineInfos) {
|
||||||
|
info.adjust(previousInfo);
|
||||||
prepareTextLine(page, info, x, y);
|
prepareTextLine(page, info, x, y);
|
||||||
y += info.Height + info.Descent + info.VSpaceAfter;
|
y += info.Height + info.Descent + info.VSpaceAfter;
|
||||||
labels[++index] = page.TextElementMap.size();
|
labels[++index] = page.TextElementMap.size();
|
||||||
|
@ -503,6 +505,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
y = getTopMargin();
|
y = getTopMargin();
|
||||||
x += page.getTextWidth() + getSpaceBetweenColumns();
|
x += page.getTextWidth() + getSpaceBetweenColumns();
|
||||||
}
|
}
|
||||||
|
previousInfo = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = getLeftMargin();
|
x = getLeftMargin();
|
||||||
|
@ -967,15 +970,17 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
page.LineInfos.clear();
|
page.LineInfos.clear();
|
||||||
page.Column0Height = 0;
|
page.Column0Height = 0;
|
||||||
boolean nextParagraph;
|
boolean nextParagraph;
|
||||||
|
ZLTextLineInfo info = null;
|
||||||
do {
|
do {
|
||||||
|
final ZLTextLineInfo previousInfo = info;
|
||||||
resetTextStyle();
|
resetTextStyle();
|
||||||
final ZLTextParagraphCursor paragraphCursor = result.getParagraphCursor();
|
final ZLTextParagraphCursor paragraphCursor = result.getParagraphCursor();
|
||||||
final int wordIndex = result.getElementIndex();
|
final int wordIndex = result.getElementIndex();
|
||||||
applyStyleChanges(paragraphCursor, 0, wordIndex);
|
applyStyleChanges(paragraphCursor, 0, wordIndex);
|
||||||
ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, wordIndex, result.getCharIndex(), getTextStyle());
|
info = new ZLTextLineInfo(paragraphCursor, wordIndex, result.getCharIndex(), getTextStyle());
|
||||||
final int endIndex = info.ParagraphCursorLength;
|
final int endIndex = info.ParagraphCursorLength;
|
||||||
while (info.EndElementIndex != endIndex) {
|
while (info.EndElementIndex != endIndex) {
|
||||||
info = processTextLine(page, paragraphCursor, info.EndElementIndex, info.EndCharIndex, endIndex);
|
info = processTextLine(page, paragraphCursor, info.EndElementIndex, info.EndCharIndex, endIndex, previousInfo);
|
||||||
textAreaHeight -= info.Height + info.Descent;
|
textAreaHeight -= info.Height + info.Descent;
|
||||||
if (textAreaHeight < 0 && page.LineInfos.size() > page.Column0Height) {
|
if (textAreaHeight < 0 && page.LineInfos.size() > page.Column0Height) {
|
||||||
if (page.Column0Height == 0 && page.twoColumnView()) {
|
if (page.Column0Height == 0 && page.twoColumnView()) {
|
||||||
|
@ -1022,12 +1027,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
ZLTextParagraphCursor paragraphCursor,
|
ZLTextParagraphCursor paragraphCursor,
|
||||||
final int startIndex,
|
final int startIndex,
|
||||||
final int startCharIndex,
|
final int startCharIndex,
|
||||||
final int endIndex
|
final int endIndex,
|
||||||
|
ZLTextLineInfo previousInfo
|
||||||
) {
|
) {
|
||||||
final ZLPaintContext context = getContext();
|
final ZLPaintContext context = getContext();
|
||||||
final ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, startIndex, startCharIndex, getTextStyle());
|
final ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, startIndex, startCharIndex, getTextStyle());
|
||||||
final ZLTextLineInfo cachedInfo = myLineInfoCache.get(info);
|
final ZLTextLineInfo cachedInfo = myLineInfoCache.get(info);
|
||||||
if (cachedInfo != null) {
|
if (cachedInfo != null) {
|
||||||
|
cachedInfo.adjust(previousInfo);
|
||||||
applyStyleChanges(paragraphCursor, startIndex, cachedInfo.EndElementIndex);
|
applyStyleChanges(paragraphCursor, startIndex, cachedInfo.EndElementIndex);
|
||||||
return cachedInfo;
|
return cachedInfo;
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1207,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
setTextStyle(storedStyle);
|
setTextStyle(storedStyle);
|
||||||
|
|
||||||
if (isFirstLine) {
|
if (isFirstLine) {
|
||||||
info.Height += info.StartStyle.getSpaceBefore(metrics());
|
info.VSpaceBefore = info.StartStyle.getSpaceBefore(metrics());
|
||||||
|
if (previousInfo != null) {
|
||||||
|
info.PreviousInfoUsed = true;
|
||||||
|
info.Height += Math.max(0, info.VSpaceBefore - previousInfo.VSpaceAfter);
|
||||||
|
} else {
|
||||||
|
info.PreviousInfoUsed = false;
|
||||||
|
info.Height += info.VSpaceBefore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (info.isEndOfParagraph()) {
|
if (info.isEndOfParagraph()) {
|
||||||
info.VSpaceAfter = getTextStyle().getSpaceAfter(metrics());
|
info.VSpaceAfter = getTextStyle().getSpaceAfter(metrics());
|
||||||
|
@ -1520,25 +1534,37 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return (unit == SizeUnit.PIXEL_UNIT) ? (info.Height + info.Descent + info.VSpaceAfter) : (info.IsVisible ? 1 : 0);
|
return (unit == SizeUnit.PIXEL_UNIT) ? (info.Height + info.Descent + info.VSpaceAfter) : (info.IsVisible ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int paragraphSize(ZLTextPage page, ZLTextWordCursor cursor, boolean beforeCurrentPosition, int unit) {
|
private static class ParagraphSize {
|
||||||
|
public int Height;
|
||||||
|
public int TopMargin;
|
||||||
|
public int BottomMargin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ParagraphSize paragraphSize(ZLTextPage page, ZLTextWordCursor cursor, boolean beforeCurrentPosition, int unit) {
|
||||||
|
final ParagraphSize size = new ParagraphSize();
|
||||||
|
|
||||||
final ZLTextParagraphCursor paragraphCursor = cursor.getParagraphCursor();
|
final ZLTextParagraphCursor paragraphCursor = cursor.getParagraphCursor();
|
||||||
if (paragraphCursor == null) {
|
if (paragraphCursor == null) {
|
||||||
return 0;
|
return size;
|
||||||
}
|
}
|
||||||
final int endElementIndex =
|
final int endElementIndex =
|
||||||
beforeCurrentPosition ? cursor.getElementIndex() : paragraphCursor.getParagraphLength();
|
beforeCurrentPosition ? cursor.getElementIndex() : paragraphCursor.getParagraphLength();
|
||||||
|
|
||||||
resetTextStyle();
|
resetTextStyle();
|
||||||
|
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
int wordIndex = 0;
|
int wordIndex = 0;
|
||||||
int charIndex = 0;
|
int charIndex = 0;
|
||||||
|
ZLTextLineInfo info = null;
|
||||||
while (wordIndex != endElementIndex) {
|
while (wordIndex != endElementIndex) {
|
||||||
ZLTextLineInfo info = processTextLine(page, paragraphCursor, wordIndex, charIndex, endElementIndex);
|
final ZLTextLineInfo prev = info;
|
||||||
|
info = processTextLine(page, paragraphCursor, wordIndex, charIndex, endElementIndex, prev);
|
||||||
wordIndex = info.EndElementIndex;
|
wordIndex = info.EndElementIndex;
|
||||||
charIndex = info.EndCharIndex;
|
charIndex = info.EndCharIndex;
|
||||||
size += infoSize(info, unit);
|
size.Height += infoSize(info, unit);
|
||||||
|
if (prev == null) {
|
||||||
|
size.TopMargin = info.VSpaceBefore;
|
||||||
|
}
|
||||||
|
size.BottomMargin = info.VSpaceAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
|
@ -1554,8 +1580,9 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
resetTextStyle();
|
resetTextStyle();
|
||||||
applyStyleChanges(paragraphCursor, 0, cursor.getElementIndex());
|
applyStyleChanges(paragraphCursor, 0, cursor.getElementIndex());
|
||||||
|
|
||||||
while (!cursor.isEndOfParagraph() && (size > 0)) {
|
ZLTextLineInfo info = null;
|
||||||
ZLTextLineInfo info = processTextLine(page, paragraphCursor, cursor.getElementIndex(), cursor.getCharIndex(), endElementIndex);
|
while (!cursor.isEndOfParagraph() && size > 0) {
|
||||||
|
info = processTextLine(page, paragraphCursor, cursor.getElementIndex(), cursor.getCharIndex(), endElementIndex, info);
|
||||||
cursor.moveTo(info.EndElementIndex, info.EndCharIndex);
|
cursor.moveTo(info.EndElementIndex, info.EndCharIndex);
|
||||||
size -= infoSize(info, unit);
|
size -= infoSize(info, unit);
|
||||||
}
|
}
|
||||||
|
@ -1569,12 +1596,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLTextWordCursor findStart(ZLTextPage page, ZLTextWordCursor end, int unit, int size) {
|
private ZLTextWordCursor findStart(ZLTextPage page, ZLTextWordCursor end, int unit, int height) {
|
||||||
final ZLTextWordCursor start = new ZLTextWordCursor(end);
|
final ZLTextWordCursor start = new ZLTextWordCursor(end);
|
||||||
size -= paragraphSize(page, start, true, unit);
|
ParagraphSize size = paragraphSize(page, start, true, unit);
|
||||||
|
height -= size.Height;
|
||||||
boolean positionChanged = !start.isStartOfParagraph();
|
boolean positionChanged = !start.isStartOfParagraph();
|
||||||
start.moveToParagraphStart();
|
start.moveToParagraphStart();
|
||||||
while (size > 0) {
|
while (height > 0) {
|
||||||
|
final ParagraphSize previousSize = size;
|
||||||
if (positionChanged && start.getParagraphCursor().isEndOfSection()) {
|
if (positionChanged && start.getParagraphCursor().isEndOfSection()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1584,9 +1613,13 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
if (!start.getParagraphCursor().isEndOfSection()) {
|
if (!start.getParagraphCursor().isEndOfSection()) {
|
||||||
positionChanged = true;
|
positionChanged = true;
|
||||||
}
|
}
|
||||||
size -= paragraphSize(page, start, false, unit);
|
size = paragraphSize(page, start, false, unit);
|
||||||
|
height -= size.Height;
|
||||||
|
if (previousSize != null) {
|
||||||
|
height += Math.min(size.BottomMargin, previousSize.TopMargin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
skip(page, start, unit, -size);
|
skip(page, start, unit, -height);
|
||||||
|
|
||||||
if (unit == SizeUnit.PIXEL_UNIT) {
|
if (unit == SizeUnit.PIXEL_UNIT) {
|
||||||
boolean sameStart = start.samePositionAs(end);
|
boolean sameStart = start.samePositionAs(end);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue