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

more styles in css; vertical-align property

This commit is contained in:
Nikolay Pultsin 2014-06-06 02:51:07 +01:00
parent 0bb2314e8c
commit fb574f159a
14 changed files with 126 additions and 105 deletions

View file

@ -180,3 +180,27 @@ dd {
fbreader-name: "Definition Description";
font-style: italic;
}
footnote {
fbreader-id: 16;
fbreader-name: "Footnote";
font-size: 0.7em;
vertical-align: 0.5em;
hyphens: none;
}
sup {
fbreader-id: 20;
fbreader-name: "Superscript";
font-size: 0.7em;
vertical-align: 0.5em;
hyphens: none;
}
sub {
fbreader-id: 19;
fbreader-name: "Subscript";
font-size: 0.7em;
vertical-align: -0.5em;
hyphens: none;
}

View file

@ -9,8 +9,4 @@
<style id="13" name="Author" leftIndent="20" allowHyphenations="false"/>
<style id="14" name="Date" leftIndent="40" allowHyphenations="false"/>
<style id="8" name="Verse" leftIndent="20" alignment="left" allowHyphenations="false"/>
<style id="16" partial="true" name="Footnote" fontSizeDelta="-5" vShift="7" allowHyphenations="false"/>
<style id="19" partial="true" name="Subscript" fontSizeDelta="-4" vShift="-4" allowHyphenations="false"/>
<style id="20" partial="true" name="Superscript" fontSizeDelta="-4" vShift="10" allowHyphenations="false"/>
</DefaultStyles>

View file

@ -296,13 +296,10 @@ public class PreferenceActivity extends ZLPreferenceActivity {
continue;
}
final ZLTextStyleDecoration decoration = collection.getDecoration(styles[i]);
final ZLTextFullStyleDecoration decoration = collection.getDecoration(styles[i]);
if (decoration == null) {
continue;
}
ZLTextFullStyleDecoration fullDecoration =
decoration instanceof ZLTextFullStyleDecoration
? (ZLTextFullStyleDecoration)decoration : null;
final Screen formatScreen = moreStylesScreen.createPreferenceScreen(decoration.getName());
formatScreen.addPreference(new FontPreference(
@ -329,53 +326,49 @@ public class PreferenceActivity extends ZLPreferenceActivity {
this, textScreen.Resource, "strikedThrough",
decoration.StrikeThroughOption
));
if (fullDecoration != null) {
final String[] allAlignments = { "unchanged", "left", "right", "center", "justify" };
formatScreen.addPreference(new ZLChoicePreference(
this, textScreen.Resource, "alignment",
fullDecoration.AlignmentOption, allAlignments
));
}
final String[] allAlignments = { "unchanged", "left", "right", "center", "justify" };
formatScreen.addPreference(new ZLChoicePreference(
this, textScreen.Resource, "alignment",
decoration.AlignmentOption, allAlignments
));
formatScreen.addPreference(new ZLBoolean3Preference(
this, textScreen.Resource, "allowHyphenations",
decoration.AllowHyphenationsOption
));
if (fullDecoration != null) {
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("spaceBefore"),
fullDecoration.SpaceBeforeOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("spaceAfter"),
fullDecoration.SpaceAfterOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("leftIndent"),
fullDecoration.LeftIndentOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("rightIndent"),
fullDecoration.RightIndentOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("firstLineIndent"),
fullDecoration.FirstLineIndentDeltaOption
));
final ZLIntegerOption spacePercentOption = fullDecoration.LineSpacePercentOption;
final int[] spacingValues = new int[17];
final String[] spacingKeys = new String[17];
spacingValues[0] = -1;
spacingKeys[0] = "unchanged";
for (int j = 1; j < spacingValues.length; ++j) {
final int val = 4 + j;
spacingValues[j] = 10 * val;
spacingKeys[j] = (char)(val / 10 + '0') + decimalSeparator + (char)(val % 10 + '0');
}
formatScreen.addPreference(new ZLIntegerChoicePreference(
this, textScreen.Resource, "lineSpacing",
spacePercentOption, spacingValues, spacingKeys
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("spaceBefore"),
decoration.SpaceBeforeOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("spaceAfter"),
decoration.SpaceAfterOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("leftIndent"),
decoration.LeftIndentOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("rightIndent"),
decoration.RightIndentOption
));
formatScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("firstLineIndent"),
decoration.FirstLineIndentDeltaOption
));
final ZLIntegerOption spacePercentOption = decoration.LineSpacePercentOption;
final int[] spacingValues = new int[17];
final String[] spacingKeys = new String[17];
spacingValues[0] = -1;
spacingKeys[0] = "unchanged";
for (int j = 1; j < spacingValues.length; ++j) {
final int val = 4 + j;
spacingValues[j] = 10 * val;
spacingKeys[j] = (char)(val / 10 + '0') + decimalSeparator + (char)(val % 10 + '0');
}
formatScreen.addPreference(new ZLIntegerChoicePreference(
this, textScreen.Resource, "lineSpacing",
spacePercentOption, spacingValues, spacingKeys
));
}
final PreferenceSet footerPreferences = new PreferenceSet.Enabler() {

View file

@ -45,7 +45,7 @@ public abstract class ZLTextStyle {
public abstract int getRightIndent();
public abstract int getFirstLineIndentDelta();
public abstract int getLineSpacePercent();
public abstract int getVerticalShift();
public abstract int getVerticalAlign(ZLTextMetrics metrics);
public abstract int getSpaceBefore(ZLTextMetrics metrics);
public abstract int getSpaceAfter(ZLTextMetrics metrics);
public abstract byte getAlignment();

View file

@ -892,7 +892,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
setTextStyle(area.Style);
}
final int areaX = area.XStart;
final int areaY = area.YEnd - getElementDescent(element) - getTextStyle().getVerticalShift();
final int areaY = area.YEnd - getElementDescent(element) - getTextStyle().getVerticalAlign(metrics());
if (element instanceof ZLTextWord) {
drawWord(
areaX, areaY, (ZLTextWord)element, charIndex, -1, false,
@ -953,7 +953,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
final int len = info.EndCharIndex - start;
final ZLTextWord word = (ZLTextWord)paragraph.getElement(info.EndElementIndex);
drawWord(
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalShift(),
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalAlign(metrics()),
word, start, len, area.AddHyphenationSign,
mySelection.isAreaSelected(area)
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)

View file

@ -68,7 +68,7 @@ abstract class ZLTextViewBase extends ZLView {
final int getWordHeight() {
if (myWordHeight == -1) {
final ZLTextStyle textStyle = myTextStyle;
myWordHeight = getContext().getStringHeight() * textStyle.getLineSpacePercent() / 100 + textStyle.getVerticalShift();
myWordHeight = getContext().getStringHeight() * textStyle.getLineSpacePercent() / 100 + textStyle.getVerticalAlign(metrics());
}
return myWordHeight;
}
@ -154,7 +154,11 @@ abstract class ZLTextViewBase extends ZLView {
final ZLTextNGStyleDescription description =
getTextStyleCollection().getDescription(control.Kind);
if (description != null) {
setTextStyle(new ZLTextNGStyle(myTextStyle, description));
if (control instanceof ZLTextHyperlinkControlElement) {
setTextStyle(new ZLTextNGStyle(myTextStyle, description, ((ZLTextHyperlinkControlElement)control).Hyperlink));
} else {
setTextStyle(new ZLTextNGStyle(myTextStyle, description, null));
}
} else {
final ZLTextStyleDecoration decoration =
getTextStyleCollection().getDecoration(control.Kind);

View file

@ -131,7 +131,7 @@ public class ZLTextBaseStyle extends ZLTextStyle {
}
@Override
public int getVerticalShift() {
public int getVerticalAlign(ZLTextMetrics metrics) {
return 0;
}

View file

@ -35,13 +35,13 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
private boolean myIsBold;
private boolean myIsUnderline;
private boolean myIsStrikeThrough;
private int myVerticalShift;
private boolean myIsNotCached = true;
private int myFontSize;
private int mySpaceBefore;
private int mySpaceAfter;
private int myVerticalAlign;
private ZLTextMetrics myMetrics;
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
@ -57,7 +57,6 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
myIsBold = isBoldInternal();
myIsUnderline = isUnderlineInternal();
myIsStrikeThrough = isStrikeThroughInternal();
myVerticalShift = getVerticalShiftInternal();
myIsNotCached = false;
}
@ -67,6 +66,7 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
myFontSize = getFontSizeInternal(metrics);
mySpaceBefore = getSpaceBeforeInternal(metrics, myFontSize);
mySpaceAfter = getSpaceAfterInternal(metrics, myFontSize);
myVerticalAlign = getVerticalAlignInternal(metrics, myFontSize);
}
@Override
@ -142,11 +142,11 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
protected abstract boolean isStrikeThroughInternal();
@Override
public final int getVerticalShift() {
if (myIsNotCached) {
initCache();
public final int getVerticalAlign(ZLTextMetrics metrics) {
if (!metrics.equals(myMetrics)) {
initMetricsCache(metrics);
}
return myVerticalShift;
return myVerticalAlign;
}
protected abstract int getVerticalShiftInternal();
protected abstract int getVerticalAlignInternal(ZLTextMetrics metrics, int fontSize);
}

View file

@ -151,9 +151,9 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
return Parent.getLineSpacePercent();
}
@Override
protected int getVerticalShiftInternal() {
protected int getVerticalAlignInternal(ZLTextMetrics metrics, int fontSize) {
// TODO: implement
return Parent.getVerticalShift();
return Parent.getVerticalAlign(metrics);
}
@Override
protected int getSpaceBeforeInternal(ZLTextMetrics metrics, int fontSize) {

View file

@ -26,13 +26,14 @@ import org.geometerplus.zlibrary.core.fonts.FontEntry;
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
public class ZLTextNGStyle extends ZLTextDecoratedStyle {
private final ZLTextNGStyleDescription myDescription;
public ZLTextNGStyle(ZLTextStyle parent, ZLTextNGStyleDescription description) {
super(parent, parent.Hyperlink);
public ZLTextNGStyle(ZLTextStyle parent, ZLTextNGStyleDescription description, ZLTextHyperlink hyperlink) {
super(parent, hyperlink);
myDescription = description;
}
@ -120,9 +121,8 @@ public class ZLTextNGStyle extends ZLTextDecoratedStyle {
return Parent.getLineSpacePercent();
}
@Override
protected int getVerticalShiftInternal() {
// TODO: implement
return Parent.getVerticalShift();
protected int getVerticalAlignInternal(ZLTextMetrics metrics, int fontSize) {
return myDescription.getVerticalAlign(metrics, Parent.getVerticalAlign(metrics), fontSize);
}
@Override
protected int getSpaceBeforeInternal(ZLTextMetrics metrics, int fontSize) {

View file

@ -38,6 +38,7 @@ public class ZLTextNGStyleDescription {
public final ZLStringOption MarginTopOption;
public final ZLStringOption MarginBottomOption;
public final ZLStringOption AlignmentOption;
public final ZLStringOption VerticalAlignOption;
private static ZLStringOption createOption(String selector, String name, Map<String,String> valueMap) {
return new ZLStringOption("Style", selector + "::" + name, valueMap.get(name));
@ -55,6 +56,7 @@ public class ZLTextNGStyleDescription {
MarginTopOption = createOption(selector, "margin-top", valueMap);
MarginBottomOption = createOption(selector, "margin-bottom", valueMap);
AlignmentOption = createOption(selector, "text-align", valueMap);
VerticalAlignOption = createOption(selector, "vertical-align", valueMap);
}
int getFontSize(ZLTextMetrics metrics, int baseFontSize) {
@ -67,6 +69,17 @@ public class ZLTextNGStyleDescription {
);
}
int getVerticalAlign(ZLTextMetrics metrics, int base, int fontSize) {
final ZLTextStyleEntry.Length length = parseLength(VerticalAlignOption.getValue());
if (length == null) {
return base;
}
return ZLTextStyleEntry.compute(
// TODO: add new length for vertical alignment
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

@ -126,8 +126,8 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
}
@Override
protected int getVerticalShiftInternal() {
return Parent.getVerticalShift() + myDecoration.VerticalShiftOption.getValue();
protected int getVerticalAlignInternal(ZLTextMetrics metrics, int fontSize) {
return Parent.getVerticalAlign(metrics) + myDecoration.VerticalAlignOption.getValue();
}
@Override

View file

@ -32,7 +32,7 @@ public class ZLTextStyleCollection {
private int myDefaultFontSize;
private ZLTextBaseStyle myBaseStyle;
private final ZLTextNGStyleDescription[] myDescriptionMap = new ZLTextNGStyleDescription[256];
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
private final ZLTextFullStyleDecoration[] myDecorationMap = new ZLTextFullStyleDecoration[256];
public ZLTextStyleCollection(String screen) {
Screen = screen;
@ -56,7 +56,7 @@ public class ZLTextStyleCollection {
return myDescriptionMap[kind & 0xFF];
}
public ZLTextStyleDecoration getDecoration(byte kind) {
public ZLTextFullStyleDecoration getDecoration(byte kind) {
return myDecorationMap[kind & 0xFF];
}
@ -109,45 +109,36 @@ public class ZLTextStyleCollection {
} else if (STYLE.equals(tag)) {
String idString = attributes.getValue("id");
String name = attributes.getValue("name");
if ((idString != null) && (name != null)) {
if (idString != null && name != null) {
byte id = Byte.parseByte(idString);
ZLTextStyleDecoration decoration;
final String fontFamily = attributes.getValue("family");
final int fontSizeDelta = intValue(attributes, "fontSizeDelta", 0);
final ZLBoolean3 bold = b3Value(attributes, "bold");
final ZLBoolean3 italic = b3Value(attributes, "italic");
final int verticalShift = intValue(attributes, "vShift", 0);
final ZLBoolean3 allowHyphenations = b3Value(attributes, "allowHyphenations");
if (booleanValue(attributes, "partial")) {
decoration = new ZLTextStyleDecoration(name, fontFamily, fontSizeDelta, bold, italic, ZLBoolean3.B3_UNDEFINED, ZLBoolean3.B3_UNDEFINED, verticalShift, allowHyphenations);
} else {
int spaceBefore = intValue(attributes, "spaceBefore", 0);
int spaceAfter = intValue(attributes, "spaceAfter", 0);
int leftIndent = intValue(attributes, "leftIndent", 0);
int rightIndent = intValue(attributes, "rightIndent", 0);
int firstLineIndentDelta = intValue(attributes, "firstLineIndentDelta", 0);
int spaceBefore = intValue(attributes, "spaceBefore", 0);
int spaceAfter = intValue(attributes, "spaceAfter", 0);
int leftIndent = intValue(attributes, "leftIndent", 0);
int rightIndent = intValue(attributes, "rightIndent", 0);
int firstLineIndentDelta = intValue(attributes, "firstLineIndentDelta", 0);
byte alignment = ZLTextAlignmentType.ALIGN_UNDEFINED;
String alignmentString = attributes.getValue("alignment");
if (alignmentString != null) {
if (alignmentString.equals("left")) {
alignment = ZLTextAlignmentType.ALIGN_LEFT;
} else if (alignmentString.equals("right")) {
alignment = ZLTextAlignmentType.ALIGN_RIGHT;
} else if (alignmentString.equals("center")) {
alignment = ZLTextAlignmentType.ALIGN_CENTER;
} else if (alignmentString.equals("justify")) {
alignment = ZLTextAlignmentType.ALIGN_JUSTIFY;
}
byte alignment = ZLTextAlignmentType.ALIGN_UNDEFINED;
String alignmentString = attributes.getValue("alignment");
if (alignmentString != null) {
if (alignmentString.equals("left")) {
alignment = ZLTextAlignmentType.ALIGN_LEFT;
} else if (alignmentString.equals("right")) {
alignment = ZLTextAlignmentType.ALIGN_RIGHT;
} else if (alignmentString.equals("center")) {
alignment = ZLTextAlignmentType.ALIGN_CENTER;
} else if (alignmentString.equals("justify")) {
alignment = ZLTextAlignmentType.ALIGN_JUSTIFY;
}
final int lineSpacePercent = intValue(attributes, "lineSpacingPercent", -1);
decoration = new ZLTextFullStyleDecoration(name, fontFamily, fontSizeDelta, bold, italic, ZLBoolean3.B3_UNDEFINED, ZLBoolean3.B3_UNDEFINED, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, verticalShift, alignment, lineSpacePercent, allowHyphenations);
}
final int lineSpacePercent = intValue(attributes, "lineSpacingPercent", -1);
myDecorationMap[id & 0xFF] = decoration;
myDecorationMap[id & 0xFF] = new ZLTextFullStyleDecoration(name, null, fontSizeDelta, bold, italic, ZLBoolean3.B3_UNDEFINED, ZLBoolean3.B3_UNDEFINED, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, 0, alignment, lineSpacePercent, allowHyphenations);
}
}
return false;

View file

@ -34,12 +34,12 @@ public class ZLTextStyleDecoration {
public final ZLBoolean3Option ItalicOption;
public final ZLBoolean3Option UnderlineOption;
public final ZLBoolean3Option StrikeThroughOption;
public final ZLIntegerOption VerticalShiftOption;
public final ZLIntegerOption VerticalAlignOption;
public final ZLBoolean3Option AllowHyphenationsOption;
private final String myName;
public ZLTextStyleDecoration(String name, String fontFamily, int fontSizeDelta, ZLBoolean3 bold, ZLBoolean3 italic, ZLBoolean3 underline, ZLBoolean3 strikeThrough, int verticalShift, ZLBoolean3 allowHyphenations) {
public ZLTextStyleDecoration(String name, String fontFamily, int fontSizeDelta, ZLBoolean3 bold, ZLBoolean3 italic, ZLBoolean3 underline, ZLBoolean3 strikeThrough, int verticalAlign, ZLBoolean3 allowHyphenations) {
myName = name;
FontFamilyOption = new ZLStringOption(STYLE, name + ":fontFamily", fontFamily);
FontSizeDeltaOption = new ZLIntegerRangeOption(STYLE, name + ":fontSize", -16, 16, fontSizeDelta);
@ -47,7 +47,7 @@ public class ZLTextStyleDecoration {
ItalicOption = new ZLBoolean3Option(STYLE, name + ":italic", italic);
UnderlineOption = new ZLBoolean3Option(STYLE, name + ":underline", underline);
StrikeThroughOption = new ZLBoolean3Option(STYLE, name + ":strikeThrough", strikeThrough);
VerticalShiftOption = new ZLIntegerOption(STYLE, name + ":vShift", verticalShift);
VerticalAlignOption = new ZLIntegerOption(STYLE, name + ":vShift", verticalAlign);
AllowHyphenationsOption = new ZLBoolean3Option(STYLE, name + ":allowHyphenations", allowHyphenations);
}