1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

new properties in default styles css: margin-left, margin-right & text-indent

This commit is contained in:
Nikolay Pultsin 2014-06-06 07:10:22 +01:00
parent 6b133d0ad8
commit 2a82b3df34
9 changed files with 108 additions and 33 deletions

View file

@ -41,9 +41,9 @@ public abstract class ZLTextStyle {
public abstract boolean isUnderline();
public abstract boolean isStrikeThrough();
public abstract int getLeftIndent();
public abstract int getRightIndent();
public abstract int getFirstLineIndentDelta();
public abstract int getLeftIndent(ZLTextMetrics metrics);
public abstract int getRightIndent(ZLTextMetrics metrics);
public abstract int getFirstLineIndent(ZLTextMetrics metrics);
public abstract int getLineSpacePercent();
public abstract int getVerticalAlign(ZLTextMetrics metrics);
public abstract int getSpaceBefore(ZLTextMetrics metrics);

View file

@ -1061,9 +1061,9 @@ public abstract class ZLTextView extends ZLTextViewBase {
ZLTextStyle storedStyle = getTextStyle();
info.LeftIndent = getTextStyle().getLeftIndent();
info.LeftIndent = getTextStyle().getLeftIndent(metrics());
if (isFirstLine) {
info.LeftIndent += getTextStyle().getFirstLineIndentDelta();
info.LeftIndent = getTextStyle().getFirstLineIndent(metrics());
}
info.Width = info.LeftIndent;
@ -1244,14 +1244,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
final int maxWidth = page.getTextWidth();
switch (getTextStyle().getAlignment()) {
case ZLTextAlignmentType.ALIGN_RIGHT:
x += maxWidth - getTextStyle().getRightIndent() - info.Width;
x += maxWidth - getTextStyle().getRightIndent(metrics()) - info.Width;
break;
case ZLTextAlignmentType.ALIGN_CENTER:
x += (maxWidth - getTextStyle().getRightIndent() - info.Width) / 2;
x += (maxWidth - getTextStyle().getRightIndent(metrics()) - info.Width) / 2;
break;
case ZLTextAlignmentType.ALIGN_JUSTIFY:
if (!endOfParagraph && (paragraphCursor.getElement(info.EndElementIndex) != ZLTextElement.AfterParagraph)) {
fullCorrection = maxWidth - getTextStyle().getRightIndent() - info.Width;
fullCorrection = maxWidth - getTextStyle().getRightIndent(metrics()) - info.Width;
}
break;
case ZLTextAlignmentType.ALIGN_LEFT:

View file

@ -203,7 +203,7 @@ abstract class ZLTextViewBase extends ZLView {
} else if (element instanceof ZLTextVideoElement) {
return Math.min(300, getTextColumnWidth());
} else if (element == ZLTextElement.Indent) {
return myTextStyle.getFirstLineIndentDelta();
return myTextStyle.getFirstLineIndent(metrics());
} else if (element instanceof ZLTextFixedHSpaceElement) {
return getContext().getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length;
}

View file

@ -111,17 +111,17 @@ public class ZLTextBaseStyle extends ZLTextStyle {
}
@Override
public int getLeftIndent() {
public int getLeftIndent(ZLTextMetrics metrics) {
return 0;
}
@Override
public int getRightIndent() {
public int getRightIndent(ZLTextMetrics metrics) {
return 0;
}
@Override
public int getFirstLineIndentDelta() {
public int getFirstLineIndent(ZLTextMetrics metrics) {
return 0;
}

View file

@ -42,6 +42,9 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
private int mySpaceBefore;
private int mySpaceAfter;
private int myVerticalAlign;
private int myLeftIndent;
private int myRightIndent;
private int myFirstLineIndent;
private ZLTextMetrics myMetrics;
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
@ -67,6 +70,9 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
mySpaceBefore = getSpaceBeforeInternal(metrics, myFontSize);
mySpaceAfter = getSpaceAfterInternal(metrics, myFontSize);
myVerticalAlign = getVerticalAlignInternal(metrics, myFontSize);
myLeftIndent = getLeftIndentInternal(metrics, myFontSize);
myRightIndent = getRightIndentInternal(metrics, myFontSize);
myFirstLineIndent = getFirstLineIndentInternal(metrics, myFontSize);
}
@Override
@ -149,4 +155,31 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
return myVerticalAlign;
}
protected abstract int getVerticalAlignInternal(ZLTextMetrics metrics, int fontSize);
@Override
public final int getLeftIndent(ZLTextMetrics metrics) {
if (!metrics.equals(myMetrics)) {
initMetricsCache(metrics);
}
return myLeftIndent;
}
protected abstract int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize);
@Override
public final int getRightIndent(ZLTextMetrics metrics) {
if (!metrics.equals(myMetrics)) {
initMetricsCache(metrics);
}
return myRightIndent;
}
protected abstract int getRightIndentInternal(ZLTextMetrics metrics, int fontSize);
@Override
public final int getFirstLineIndent(ZLTextMetrics metrics) {
if (!metrics.equals(myMetrics)) {
initMetricsCache(metrics);
}
return myFirstLineIndent;
}
protected abstract int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize);
}

View file

@ -134,17 +134,20 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
}
}
public int getLeftIndent() {
@Override
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
// TODO: implement
return Parent.getLeftIndent();
return Parent.getLeftIndent(metrics);
}
public int getRightIndent() {
@Override
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
// TODO: implement
return Parent.getRightIndent();
return Parent.getRightIndent(metrics);
}
public int getFirstLineIndentDelta() {
@Override
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
// TODO: implement
return Parent.getFirstLineIndentDelta();
return Parent.getFirstLineIndent(metrics);
}
public int getLineSpacePercent() {
// TODO: implement

View file

@ -104,17 +104,17 @@ public class ZLTextNGStyle extends ZLTextDecoratedStyle {
}
}
public int getLeftIndent() {
// TODO: implement
return Parent.getLeftIndent();
@Override
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
return myDescription.getLeftIndent(metrics, Parent.getLeftIndent(metrics), fontSize);
}
public int getRightIndent() {
// TODO: implement
return Parent.getRightIndent();
@Override
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
return myDescription.getRightIndent(metrics, Parent.getRightIndent(metrics), fontSize);
}
public int getFirstLineIndentDelta() {
// TODO: implement
return Parent.getFirstLineIndentDelta();
@Override
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
return myDescription.getFirstLineIndent(metrics, Parent.getFirstLineIndent(metrics), fontSize);
}
public int getLineSpacePercent() {
// TODO: implement

View file

@ -37,6 +37,9 @@ public class ZLTextNGStyleDescription {
public final ZLStringOption HyphenationOption;
public final ZLStringOption MarginTopOption;
public final ZLStringOption MarginBottomOption;
public final ZLStringOption MarginLeftOption;
public final ZLStringOption MarginRightOption;
public final ZLStringOption TextIndentOption;
public final ZLStringOption AlignmentOption;
public final ZLStringOption VerticalAlignOption;
@ -55,6 +58,9 @@ public class ZLTextNGStyleDescription {
HyphenationOption = createOption(selector, "hyphens", valueMap);
MarginTopOption = createOption(selector, "margin-top", valueMap);
MarginBottomOption = createOption(selector, "margin-bottom", valueMap);
MarginLeftOption = createOption(selector, "margin-left", valueMap);
MarginRightOption = createOption(selector, "margin-right", valueMap);
TextIndentOption = createOption(selector, "text-indent", valueMap);
AlignmentOption = createOption(selector, "text-align", valueMap);
VerticalAlignOption = createOption(selector, "vertical-align", valueMap);
}
@ -80,6 +86,39 @@ public class ZLTextNGStyleDescription {
);
}
int getLeftIndent(ZLTextMetrics metrics, int base, int fontSize) {
final ZLTextStyleEntry.Length length = parseLength(MarginLeftOption.getValue());
if (length == null) {
return base;
}
return ZLTextStyleEntry.compute(
// TODO: add new length for line indent
length, metrics, fontSize, ZLTextStyleEntry.Feature.LENGTH_FONT_SIZE
);
}
int getRightIndent(ZLTextMetrics metrics, int base, int fontSize) {
final ZLTextStyleEntry.Length length = parseLength(MarginRightOption.getValue());
if (length == null) {
return base;
}
return ZLTextStyleEntry.compute(
// TODO: add new length for line indent
length, metrics, fontSize, ZLTextStyleEntry.Feature.LENGTH_FONT_SIZE
);
}
int getFirstLineIndent(ZLTextMetrics metrics, int base, int fontSize) {
final ZLTextStyleEntry.Length length = parseLength(TextIndentOption.getValue());
if (length == null) {
return base;
}
return ZLTextStyleEntry.compute(
// TODO: add new length for line indent
length, metrics, fontSize, ZLTextStyleEntry.Feature.LENGTH_FONT_SIZE
);
}
int getSpaceBefore(ZLTextMetrics metrics, int base, int fontSize) {
final ZLTextStyleEntry.Length length = parseLength(MarginTopOption.getValue());
if (length == null) {

View file

@ -124,18 +124,18 @@ public class ZLTextSimpleDecoratedStyle extends ZLTextDecoratedStyle {
}
@Override
public int getLeftIndent() {
return Parent.getLeftIndent() + myDecoration.LeftIndentOption.getValue();
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
return Parent.getLeftIndent(metrics) + myDecoration.LeftIndentOption.getValue();
}
@Override
public int getRightIndent() {
return Parent.getRightIndent() + myDecoration.RightIndentOption.getValue();
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
return Parent.getRightIndent(metrics) + myDecoration.RightIndentOption.getValue();
}
@Override
public int getFirstLineIndentDelta() {
return (getAlignment() == ZLTextAlignmentType.ALIGN_CENTER) ? 0 : Parent.getFirstLineIndentDelta() + myDecoration.FirstLineIndentDeltaOption.getValue();
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
return getAlignment() == ZLTextAlignmentType.ALIGN_CENTER ? 0 : Parent.getFirstLineIndent(metrics) + myDecoration.FirstLineIndentDeltaOption.getValue();
}
@Override