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:
parent
6b133d0ad8
commit
2a82b3df34
9 changed files with 108 additions and 33 deletions
|
@ -41,9 +41,9 @@ public abstract class ZLTextStyle {
|
||||||
public abstract boolean isUnderline();
|
public abstract boolean isUnderline();
|
||||||
public abstract boolean isStrikeThrough();
|
public abstract boolean isStrikeThrough();
|
||||||
|
|
||||||
public abstract int getLeftIndent();
|
public abstract int getLeftIndent(ZLTextMetrics metrics);
|
||||||
public abstract int getRightIndent();
|
public abstract int getRightIndent(ZLTextMetrics metrics);
|
||||||
public abstract int getFirstLineIndentDelta();
|
public abstract int getFirstLineIndent(ZLTextMetrics metrics);
|
||||||
public abstract int getLineSpacePercent();
|
public abstract int getLineSpacePercent();
|
||||||
public abstract int getVerticalAlign(ZLTextMetrics metrics);
|
public abstract int getVerticalAlign(ZLTextMetrics metrics);
|
||||||
public abstract int getSpaceBefore(ZLTextMetrics metrics);
|
public abstract int getSpaceBefore(ZLTextMetrics metrics);
|
||||||
|
|
|
@ -1061,9 +1061,9 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
|
|
||||||
ZLTextStyle storedStyle = getTextStyle();
|
ZLTextStyle storedStyle = getTextStyle();
|
||||||
|
|
||||||
info.LeftIndent = getTextStyle().getLeftIndent();
|
info.LeftIndent = getTextStyle().getLeftIndent(metrics());
|
||||||
if (isFirstLine) {
|
if (isFirstLine) {
|
||||||
info.LeftIndent += getTextStyle().getFirstLineIndentDelta();
|
info.LeftIndent = getTextStyle().getFirstLineIndent(metrics());
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Width = info.LeftIndent;
|
info.Width = info.LeftIndent;
|
||||||
|
@ -1244,14 +1244,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
final int maxWidth = page.getTextWidth();
|
final int maxWidth = page.getTextWidth();
|
||||||
switch (getTextStyle().getAlignment()) {
|
switch (getTextStyle().getAlignment()) {
|
||||||
case ZLTextAlignmentType.ALIGN_RIGHT:
|
case ZLTextAlignmentType.ALIGN_RIGHT:
|
||||||
x += maxWidth - getTextStyle().getRightIndent() - info.Width;
|
x += maxWidth - getTextStyle().getRightIndent(metrics()) - info.Width;
|
||||||
break;
|
break;
|
||||||
case ZLTextAlignmentType.ALIGN_CENTER:
|
case ZLTextAlignmentType.ALIGN_CENTER:
|
||||||
x += (maxWidth - getTextStyle().getRightIndent() - info.Width) / 2;
|
x += (maxWidth - getTextStyle().getRightIndent(metrics()) - info.Width) / 2;
|
||||||
break;
|
break;
|
||||||
case ZLTextAlignmentType.ALIGN_JUSTIFY:
|
case ZLTextAlignmentType.ALIGN_JUSTIFY:
|
||||||
if (!endOfParagraph && (paragraphCursor.getElement(info.EndElementIndex) != ZLTextElement.AfterParagraph)) {
|
if (!endOfParagraph && (paragraphCursor.getElement(info.EndElementIndex) != ZLTextElement.AfterParagraph)) {
|
||||||
fullCorrection = maxWidth - getTextStyle().getRightIndent() - info.Width;
|
fullCorrection = maxWidth - getTextStyle().getRightIndent(metrics()) - info.Width;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZLTextAlignmentType.ALIGN_LEFT:
|
case ZLTextAlignmentType.ALIGN_LEFT:
|
||||||
|
|
|
@ -203,7 +203,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
} else if (element instanceof ZLTextVideoElement) {
|
} else if (element instanceof ZLTextVideoElement) {
|
||||||
return Math.min(300, getTextColumnWidth());
|
return Math.min(300, getTextColumnWidth());
|
||||||
} else if (element == ZLTextElement.Indent) {
|
} else if (element == ZLTextElement.Indent) {
|
||||||
return myTextStyle.getFirstLineIndentDelta();
|
return myTextStyle.getFirstLineIndent(metrics());
|
||||||
} else if (element instanceof ZLTextFixedHSpaceElement) {
|
} else if (element instanceof ZLTextFixedHSpaceElement) {
|
||||||
return getContext().getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length;
|
return getContext().getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,17 +111,17 @@ public class ZLTextBaseStyle extends ZLTextStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLeftIndent() {
|
public int getLeftIndent(ZLTextMetrics metrics) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRightIndent() {
|
public int getRightIndent(ZLTextMetrics metrics) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstLineIndentDelta() {
|
public int getFirstLineIndent(ZLTextMetrics metrics) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
private int mySpaceBefore;
|
private int mySpaceBefore;
|
||||||
private int mySpaceAfter;
|
private int mySpaceAfter;
|
||||||
private int myVerticalAlign;
|
private int myVerticalAlign;
|
||||||
|
private int myLeftIndent;
|
||||||
|
private int myRightIndent;
|
||||||
|
private int myFirstLineIndent;
|
||||||
private ZLTextMetrics myMetrics;
|
private ZLTextMetrics myMetrics;
|
||||||
|
|
||||||
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
|
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
|
||||||
|
@ -67,6 +70,9 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
mySpaceBefore = getSpaceBeforeInternal(metrics, myFontSize);
|
mySpaceBefore = getSpaceBeforeInternal(metrics, myFontSize);
|
||||||
mySpaceAfter = getSpaceAfterInternal(metrics, myFontSize);
|
mySpaceAfter = getSpaceAfterInternal(metrics, myFontSize);
|
||||||
myVerticalAlign = getVerticalAlignInternal(metrics, myFontSize);
|
myVerticalAlign = getVerticalAlignInternal(metrics, myFontSize);
|
||||||
|
myLeftIndent = getLeftIndentInternal(metrics, myFontSize);
|
||||||
|
myRightIndent = getRightIndentInternal(metrics, myFontSize);
|
||||||
|
myFirstLineIndent = getFirstLineIndentInternal(metrics, myFontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,4 +155,31 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
return myVerticalAlign;
|
return myVerticalAlign;
|
||||||
}
|
}
|
||||||
protected abstract int getVerticalAlignInternal(ZLTextMetrics metrics, int fontSize);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,17 +134,20 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeftIndent() {
|
@Override
|
||||||
|
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Parent.getLeftIndent();
|
return Parent.getLeftIndent(metrics);
|
||||||
}
|
}
|
||||||
public int getRightIndent() {
|
@Override
|
||||||
|
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Parent.getRightIndent();
|
return Parent.getRightIndent(metrics);
|
||||||
}
|
}
|
||||||
public int getFirstLineIndentDelta() {
|
@Override
|
||||||
|
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Parent.getFirstLineIndentDelta();
|
return Parent.getFirstLineIndent(metrics);
|
||||||
}
|
}
|
||||||
public int getLineSpacePercent() {
|
public int getLineSpacePercent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
|
@ -104,17 +104,17 @@ public class ZLTextNGStyle extends ZLTextDecoratedStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeftIndent() {
|
@Override
|
||||||
// TODO: implement
|
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
return Parent.getLeftIndent();
|
return myDescription.getLeftIndent(metrics, Parent.getLeftIndent(metrics), fontSize);
|
||||||
}
|
}
|
||||||
public int getRightIndent() {
|
@Override
|
||||||
// TODO: implement
|
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
return Parent.getRightIndent();
|
return myDescription.getRightIndent(metrics, Parent.getRightIndent(metrics), fontSize);
|
||||||
}
|
}
|
||||||
public int getFirstLineIndentDelta() {
|
@Override
|
||||||
// TODO: implement
|
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
return Parent.getFirstLineIndentDelta();
|
return myDescription.getFirstLineIndent(metrics, Parent.getFirstLineIndent(metrics), fontSize);
|
||||||
}
|
}
|
||||||
public int getLineSpacePercent() {
|
public int getLineSpacePercent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
|
@ -37,6 +37,9 @@ public class ZLTextNGStyleDescription {
|
||||||
public final ZLStringOption HyphenationOption;
|
public final ZLStringOption HyphenationOption;
|
||||||
public final ZLStringOption MarginTopOption;
|
public final ZLStringOption MarginTopOption;
|
||||||
public final ZLStringOption MarginBottomOption;
|
public final ZLStringOption MarginBottomOption;
|
||||||
|
public final ZLStringOption MarginLeftOption;
|
||||||
|
public final ZLStringOption MarginRightOption;
|
||||||
|
public final ZLStringOption TextIndentOption;
|
||||||
public final ZLStringOption AlignmentOption;
|
public final ZLStringOption AlignmentOption;
|
||||||
public final ZLStringOption VerticalAlignOption;
|
public final ZLStringOption VerticalAlignOption;
|
||||||
|
|
||||||
|
@ -55,6 +58,9 @@ public class ZLTextNGStyleDescription {
|
||||||
HyphenationOption = createOption(selector, "hyphens", valueMap);
|
HyphenationOption = createOption(selector, "hyphens", valueMap);
|
||||||
MarginTopOption = createOption(selector, "margin-top", valueMap);
|
MarginTopOption = createOption(selector, "margin-top", valueMap);
|
||||||
MarginBottomOption = createOption(selector, "margin-bottom", 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);
|
AlignmentOption = createOption(selector, "text-align", valueMap);
|
||||||
VerticalAlignOption = createOption(selector, "vertical-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) {
|
int getSpaceBefore(ZLTextMetrics metrics, int base, int fontSize) {
|
||||||
final ZLTextStyleEntry.Length length = parseLength(MarginTopOption.getValue());
|
final ZLTextStyleEntry.Length length = parseLength(MarginTopOption.getValue());
|
||||||
if (length == null) {
|
if (length == null) {
|
||||||
|
|
|
@ -124,18 +124,18 @@ public class ZLTextSimpleDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLeftIndent() {
|
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
return Parent.getLeftIndent() + myDecoration.LeftIndentOption.getValue();
|
return Parent.getLeftIndent(metrics) + myDecoration.LeftIndentOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRightIndent() {
|
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
return Parent.getRightIndent() + myDecoration.RightIndentOption.getValue();
|
return Parent.getRightIndent(metrics) + myDecoration.RightIndentOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstLineIndentDelta() {
|
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
return (getAlignment() == ZLTextAlignmentType.ALIGN_CENTER) ? 0 : Parent.getFirstLineIndentDelta() + myDecoration.FirstLineIndentDeltaOption.getValue();
|
return getAlignment() == ZLTextAlignmentType.ALIGN_CENTER ? 0 : Parent.getFirstLineIndent(metrics) + myDecoration.FirstLineIndentDeltaOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue