1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

CSS support (in progress)

This commit is contained in:
Nikolay Pultsin 2012-05-08 00:51:25 +01:00
parent 74cb4cf7be
commit 9017ad8ea4
4 changed files with 49 additions and 7 deletions

View file

@ -189,8 +189,15 @@ void StyleSheetParser::processWordWithoutComments(const std::string &word) {
myMap[myAttributeName].clear(); myMap[myAttributeName].clear();
break; break;
case ATTRIBUTE_VALUE: case ATTRIBUTE_VALUE:
myMap[myAttributeName].push_back(word); {
const size_t l = word.length();
if (l >= 2 && (word[0] == '"' || word[0] == '\'') && word[0] == word[l - 1]) {
myMap[myAttributeName].push_back(word.substr(1, l - 2));
} else {
myMap[myAttributeName].push_back(word);
}
break; break;
}
case BROKEN: case BROKEN:
break; break;
} }

View file

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <ZLStringUtil.h> #include <ZLStringUtil.h>
#include <ZLLogger.h>
#include "StyleSheetTable.h" #include "StyleSheetTable.h"
@ -185,6 +186,7 @@ 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");

View file

@ -195,12 +195,17 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
} }
if (ZLTextStyleEntry.isFeatureSupported(mask, ALIGNMENT_TYPE) || if (ZLTextStyleEntry.isFeatureSupported(mask, ALIGNMENT_TYPE) ||
ZLTextStyleEntry.isFeatureSupported(mask, FONT_SIZE_MAGNIFICATION)) { ZLTextStyleEntry.isFeatureSupported(mask, FONT_SIZE_MAGNIFICATION)) {
// TODO: read alignment type and/or font size magnification final short value = (short)data[dataOffset++];
dataOffset += 1; if (ZLTextStyleEntry.isFeatureSupported(mask, ALIGNMENT_TYPE)) {
entry.setAlignmentType((byte)(value & 0xFF));
}
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_SIZE_MAGNIFICATION)) {
entry.setFontSizeMagnification((byte)((value >> 8) & 0xFF));
}
} }
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) { if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) {
final short familyLength = (short)data[dataOffset++]; final short familyLength = (short)data[dataOffset++];
// TODO: read font family entry.setFontFamily(new String(data, dataOffset, familyLength));
dataOffset += familyLength; dataOffset += familyLength;
} }
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) { if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {

View file

@ -34,6 +34,9 @@ public final class ZLTextStyleEntry {
} }
private short myFeatureMask; private short myFeatureMask;
private byte myAlignmentType;
private byte myFontSizeMagnification;
private String myFontFamily;
static boolean isFeatureSupported(short mask, int featureId) { static boolean isFeatureSupported(short mask, int featureId) {
return (mask & (1 << featureId)) != 0; return (mask & (1 << featureId)) != 0;
@ -45,8 +48,7 @@ public final class ZLTextStyleEntry {
//private short myLeftIndent; //private short myLeftIndent;
//private short myRightIndent; //private short myRightIndent;
//private byte myAlignmentType;
public ZLTextStyleEntry() { public ZLTextStyleEntry() {
} }
@ -58,9 +60,35 @@ public final class ZLTextStyleEntry {
public short getRightIndent() { public short getRightIndent() {
return myRightIndent; return myRightIndent;
} }
*/
void setAlignmentType(byte alignmentType) {
myFeatureMask |= 1 << Feature.ALIGNMENT_TYPE;
System.err.println("setting alignment to " + alignmentType);
myAlignmentType = alignmentType;
}
public byte getAlignmentType() { public byte getAlignmentType() {
return myAlignmentType; return myAlignmentType;
} }
*/
void setFontSizeMagnification(byte fontSizeMagnification) {
myFeatureMask |= 1 << Feature.FONT_SIZE_MAGNIFICATION;
System.err.println("setting font size magnification to " + fontSizeMagnification);
myFontSizeMagnification = fontSizeMagnification;
}
public byte getFontSizeMagnification() {
return myFontSizeMagnification;
}
void setFontFamily(String fontFamily) {
myFeatureMask |= 1 << Feature.FONT_FAMILY;
System.err.println("setting font family to " + fontFamily);
myFontFamily = fontFamily;
}
public String getFontFamily() {
return myFontFamily;
}
} }