mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
CSS: bold & italic
This commit is contained in:
parent
094afe8652
commit
74434ce274
6 changed files with 98 additions and 27 deletions
2
TODO.1.5
2
TODO.1.5
|
@ -28,7 +28,7 @@ DONE Chinese/Tamil UTF16 files
|
||||||
DONE encodings list for native plugins
|
DONE encodings list for native plugins
|
||||||
* native: CSS!
|
* native: CSS!
|
||||||
* CSS: parse tag lists like 'h1,h2,h3'
|
* CSS: parse tag lists like 'h1,h2,h3'
|
||||||
* embedded fonts (ePub)
|
* CSS: embedded fonts
|
||||||
* предупреждение "не могу открыть зашифрованный файл"
|
* предупреждение "не могу открыть зашифрованный файл"
|
||||||
* API от Paragon
|
* API от Paragon
|
||||||
* Two-page view
|
* Two-page view
|
||||||
|
|
|
@ -156,6 +156,7 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &
|
||||||
|
|
||||||
const std::vector<std::string> &bold = values(styles, "font-weight");
|
const std::vector<std::string> &bold = values(styles, "font-weight");
|
||||||
if (!bold.empty()) {
|
if (!bold.empty()) {
|
||||||
|
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, "bold: " + bold[0]);
|
||||||
int num = -1;
|
int num = -1;
|
||||||
if (bold[0] == "bold") {
|
if (bold[0] == "bold") {
|
||||||
num = 700;
|
num = 700;
|
||||||
|
@ -186,7 +187,6 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &
|
||||||
const std::vector<std::string> &fontFamily = values(styles, "font-family");
|
const std::vector<std::string> &fontFamily = values(styles, "font-family");
|
||||||
if (!fontFamily.empty() && !fontFamily[0].empty()) {
|
if (!fontFamily.empty() && !fontFamily[0].empty()) {
|
||||||
entry->setFontFamily(fontFamily[0]);
|
entry->setFontFamily(fontFamily[0]);
|
||||||
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, "font family: " + fontFamily[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string> &fontSize = values(styles, "font-size");
|
const std::vector<std::string> &fontSize = values(styles, "font-size");
|
||||||
|
|
|
@ -137,7 +137,7 @@ inline ZLBoolean3 ZLTextStyleEntry::fontModifier(FontModifier modifier) const {
|
||||||
return (myFontModifier & modifier) == 0 ? B3_FALSE : B3_TRUE;
|
return (myFontModifier & modifier) == 0 ? B3_FALSE : B3_TRUE;
|
||||||
}
|
}
|
||||||
inline void ZLTextStyleEntry::setFontModifier(FontModifier modifier, bool on) {
|
inline void ZLTextStyleEntry::setFontModifier(FontModifier modifier, bool on) {
|
||||||
myFeatureMask |= FONT_STYLE_MODIFIER;
|
myFeatureMask |= 1 << FONT_STYLE_MODIFIER;
|
||||||
mySupportedFontModifier |= modifier;
|
mySupportedFontModifier |= modifier;
|
||||||
if (on) {
|
if (on) {
|
||||||
myFontModifier |= modifier;
|
myFontModifier |= modifier;
|
||||||
|
@ -148,13 +148,13 @@ inline void ZLTextStyleEntry::setFontModifier(FontModifier modifier, bool on) {
|
||||||
|
|
||||||
inline signed char ZLTextStyleEntry::fontSizeMagnification() const { return myFontSizeMagnification; }
|
inline signed char ZLTextStyleEntry::fontSizeMagnification() const { return myFontSizeMagnification; }
|
||||||
inline void ZLTextStyleEntry::setFontSizeMagnification(signed char fontSizeMagnification) {
|
inline void ZLTextStyleEntry::setFontSizeMagnification(signed char fontSizeMagnification) {
|
||||||
myFeatureMask |= FONT_SIZE_MAGNIFICATION;
|
myFeatureMask |= 1 << FONT_SIZE_MAGNIFICATION;
|
||||||
myFontSizeMagnification = fontSizeMagnification;
|
myFontSizeMagnification = fontSizeMagnification;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string &ZLTextStyleEntry::fontFamily() const { return myFontFamily; }
|
inline const std::string &ZLTextStyleEntry::fontFamily() const { return myFontFamily; }
|
||||||
inline void ZLTextStyleEntry::setFontFamily(const std::string &fontFamily) {
|
inline void ZLTextStyleEntry::setFontFamily(const std::string &fontFamily) {
|
||||||
myFeatureMask |= FONT_FAMILY;
|
myFeatureMask |= 1 << FONT_FAMILY;
|
||||||
myFontFamily = fontFamily;
|
myFontFamily = fontFamily;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,8 +209,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
dataOffset += familyLength;
|
dataOffset += familyLength;
|
||||||
}
|
}
|
||||||
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {
|
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {
|
||||||
// TODO: read font modifiers
|
final short value = (short)data[dataOffset++];
|
||||||
dataOffset += 1;
|
entry.setFontModifiers((byte)(value & 0xFF), (byte)((value >> 8) & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
myStyleEntry = entry;
|
myStyleEntry = entry;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.model;
|
package org.geometerplus.zlibrary.text.model;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
||||||
|
|
||||||
public final class ZLTextStyleEntry {
|
public final class ZLTextStyleEntry {
|
||||||
public interface Feature {
|
public interface Feature {
|
||||||
int LENGTH_LEFT_INDENT = 0;
|
int LENGTH_LEFT_INDENT = 0;
|
||||||
|
@ -33,10 +35,20 @@ public final class ZLTextStyleEntry {
|
||||||
int FONT_STYLE_MODIFIER = NUMBER_OF_LENGTHS + 3;
|
int FONT_STYLE_MODIFIER = NUMBER_OF_LENGTHS + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface FontModifier {
|
||||||
|
byte FONT_MODIFIER_BOLD = 1 << 0;
|
||||||
|
byte FONT_MODIFIER_ITALIC = 1 << 1;
|
||||||
|
byte FONT_MODIFIER_UNDERLINED = 1 << 2;
|
||||||
|
byte FONT_MODIFIER_STRIKEDTHROUGH = 1 << 3;
|
||||||
|
byte FONT_MODIFIER_SMALLCAPS = 1 << 4;
|
||||||
|
}
|
||||||
|
|
||||||
private short myFeatureMask;
|
private short myFeatureMask;
|
||||||
private byte myAlignmentType;
|
private byte myAlignmentType;
|
||||||
private byte myFontSizeMagnification;
|
private byte myFontSizeMagnification;
|
||||||
private String myFontFamily;
|
private String myFontFamily;
|
||||||
|
private byte mySupportedFontModifiers;
|
||||||
|
private byte myFontModifiers;
|
||||||
|
|
||||||
static boolean isFeatureSupported(short mask, int featureId) {
|
static boolean isFeatureSupported(short mask, int featureId) {
|
||||||
return (mask & (1 << featureId)) != 0;
|
return (mask & (1 << featureId)) != 0;
|
||||||
|
@ -82,11 +94,34 @@ public final class ZLTextStyleEntry {
|
||||||
|
|
||||||
void setFontFamily(String fontFamily) {
|
void setFontFamily(String fontFamily) {
|
||||||
myFeatureMask |= 1 << Feature.FONT_FAMILY;
|
myFeatureMask |= 1 << Feature.FONT_FAMILY;
|
||||||
System.err.println("setting font family to " + fontFamily);
|
|
||||||
myFontFamily = fontFamily;
|
myFontFamily = fontFamily;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFontFamily() {
|
public String getFontFamily() {
|
||||||
return myFontFamily;
|
return myFontFamily;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setFontModifiers(byte supported, byte values) {
|
||||||
|
System.err.println("setting font modifiers to " + supported + "/" + values);
|
||||||
|
myFeatureMask |= 1 << Feature.FONT_STYLE_MODIFIER;
|
||||||
|
mySupportedFontModifiers = supported;
|
||||||
|
myFontModifiers = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFontModifier(byte modifier, boolean on) {
|
||||||
|
myFeatureMask |= 1 << Feature.FONT_STYLE_MODIFIER;
|
||||||
|
mySupportedFontModifiers |= modifier;
|
||||||
|
if (on) {
|
||||||
|
myFontModifiers |= modifier;
|
||||||
|
} else {
|
||||||
|
myFontModifiers &= ~modifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLBoolean3 getFontModifier(byte modifier) {
|
||||||
|
if ((mySupportedFontModifiers & modifier) == 0) {
|
||||||
|
return ZLBoolean3.B3_UNDEFINED;
|
||||||
|
}
|
||||||
|
return (myFontModifiers & modifier) == 0 ? ZLBoolean3.B3_FALSE : ZLBoolean3.B3_TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.geometerplus.zlibrary.text.view.style;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextStyleEntry;
|
import org.geometerplus.zlibrary.text.model.ZLTextStyleEntry;
|
||||||
|
|
||||||
public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTextStyleEntry.Feature {
|
public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTextStyleEntry.Feature, ZLTextStyleEntry.FontModifier {
|
||||||
private final ZLTextStyleEntry myEntry;
|
private final ZLTextStyleEntry myEntry;
|
||||||
|
|
||||||
public ZLTextExplicitlyDecoratedStyle(ZLTextStyle base, ZLTextStyleEntry entry) {
|
public ZLTextExplicitlyDecoratedStyle(ZLTextStyle base, ZLTextStyleEntry entry) {
|
||||||
|
@ -40,21 +40,57 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTex
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBold() {
|
public boolean isBold() {
|
||||||
// TODO: implement
|
if (!myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||||
return Base.isBold();
|
return Base.isBold();
|
||||||
}
|
}
|
||||||
|
switch (myEntry.getFontModifier(FONT_MODIFIER_BOLD)) {
|
||||||
|
case B3_TRUE:
|
||||||
|
return true;
|
||||||
|
case B3_FALSE:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return Base.isBold();
|
||||||
|
}
|
||||||
|
}
|
||||||
public boolean isItalic() {
|
public boolean isItalic() {
|
||||||
// TODO: implement
|
if (!myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||||
return Base.isItalic();
|
return Base.isItalic();
|
||||||
}
|
}
|
||||||
|
switch (myEntry.getFontModifier(FONT_MODIFIER_ITALIC)) {
|
||||||
|
case B3_TRUE:
|
||||||
|
return true;
|
||||||
|
case B3_FALSE:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return Base.isItalic();
|
||||||
|
}
|
||||||
|
}
|
||||||
public boolean isUnderline() {
|
public boolean isUnderline() {
|
||||||
// TODO: implement
|
if (!myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||||
return Base.isUnderline();
|
return Base.isUnderline();
|
||||||
}
|
}
|
||||||
|
switch (myEntry.getFontModifier(FONT_MODIFIER_UNDERLINED)) {
|
||||||
|
case B3_TRUE:
|
||||||
|
return true;
|
||||||
|
case B3_FALSE:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return Base.isUnderline();
|
||||||
|
}
|
||||||
|
}
|
||||||
public boolean isStrikeThrough() {
|
public boolean isStrikeThrough() {
|
||||||
// TODO: implement
|
if (!myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||||
return Base.isStrikeThrough();
|
return Base.isStrikeThrough();
|
||||||
}
|
}
|
||||||
|
switch (myEntry.getFontModifier(FONT_MODIFIER_STRIKEDTHROUGH)) {
|
||||||
|
case B3_TRUE:
|
||||||
|
return true;
|
||||||
|
case B3_FALSE:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return Base.isStrikeThrough();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getLeftIndent() {
|
public int getLeftIndent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue