mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
namespace processing cleanup; 'inherit' font size
This commit is contained in:
parent
5e68f8602f
commit
2df68ca1ee
14 changed files with 53 additions and 48 deletions
7
TODO.1.5
7
TODO.1.5
|
@ -10,7 +10,7 @@ litres: author photos
|
|||
* ePub:
|
||||
DONE reference resolver (Имя розы)
|
||||
** reverence shortening in native code (like java code shortening)
|
||||
** large covers (cover mark for images in native code)
|
||||
DONE large covers (cover mark for images in native code)
|
||||
* "modes" for wallpapers: tile, fullscreen, etc.
|
||||
* zip: re-use open files
|
||||
DONE Screen orientation by default: not selected?
|
||||
|
@ -39,7 +39,8 @@ DONE encodings list for native plugins
|
|||
** metrics: screen height & width
|
||||
DONE font size
|
||||
DONE font size: smaller and larger
|
||||
** font size: inherit
|
||||
** font modifier: smallcaps
|
||||
DONE font size: inherit
|
||||
DONE underline
|
||||
DONE strikethrough
|
||||
** embedded fonts
|
||||
|
@ -49,7 +50,7 @@ DONE encodings list for native plugins
|
|||
** embedded tags in selectors (h2 p { font-family: helvetica })
|
||||
** colors
|
||||
** backgrounds
|
||||
** don't apply "fbreader internal" font size settings before CSS "smaller" or "larger"
|
||||
DONE don't apply "fbreader internal" font size settings before CSS "smaller" or "larger"
|
||||
* предупреждение "не могу открыть зашифрованный файл"
|
||||
* API от Paragon
|
||||
* Two-page view
|
||||
|
|
|
@ -221,6 +221,9 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &
|
|||
size = 144;
|
||||
} else if (fontSize[0] == "xx-large") {
|
||||
size = 173;
|
||||
} else if (fontSize[0] == "inherit") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_INHERIT, true);
|
||||
doSetFontSize = false;
|
||||
} else if (fontSize[0] == "smaller") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_SMALLER, true);
|
||||
doSetFontSize = false;
|
||||
|
|
|
@ -58,6 +58,10 @@ void FB2BookReader::characterDataHandler(const char *text, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
bool FB2BookReader::processNamespaces() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
||||
const char *id = attributeValue(xmlattributes, "id");
|
||||
if (id != 0 && tag != _BINARY) {
|
||||
|
@ -158,8 +162,7 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
|||
break;
|
||||
case _A:
|
||||
{
|
||||
const std::string hrefName = xlinkNamespace() + ":href";
|
||||
const char *ref = attributeValue(xmlattributes, hrefName.c_str());
|
||||
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
|
||||
if (ref != 0) {
|
||||
if (ref[0] == '#') {
|
||||
const char *type = attributeValue(xmlattributes, "type");
|
||||
|
@ -182,8 +185,7 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
|||
}
|
||||
case _IMAGE:
|
||||
{
|
||||
const std::string hrefName = xlinkNamespace() + ":href";
|
||||
const char *ref = attributeValue(xmlattributes, hrefName.c_str());
|
||||
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
|
||||
const char *vOffset = attributeValue(xmlattributes, "voffset");
|
||||
char offset = (vOffset != 0) ? atoi(vOffset) : 0;
|
||||
if ((ref != 0) && (*ref == '#')) {
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
FB2BookReader(BookModel &model);
|
||||
bool readBook();
|
||||
|
||||
bool processNamespaces() const;
|
||||
void startElementHandler(int tag, const char **attributes);
|
||||
void endElementHandler(int tag);
|
||||
void characterDataHandler(const char *text, size_t len);
|
||||
|
|
|
@ -37,6 +37,10 @@ shared_ptr<const ZLImage> FB2CoverReader::readCover() {
|
|||
return myImage;
|
||||
}
|
||||
|
||||
bool FB2CoverReader::processNamespaces() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void FB2CoverReader::startElementHandler(int tag, const char **attributes) {
|
||||
switch (tag) {
|
||||
case _COVERPAGE:
|
||||
|
@ -44,8 +48,7 @@ void FB2CoverReader::startElementHandler(int tag, const char **attributes) {
|
|||
break;
|
||||
case _IMAGE:
|
||||
if (myReadCoverPage) {
|
||||
const std::string hrefName = xlinkNamespace() + ":href";
|
||||
const char *ref = attributeValue(attributes, hrefName.c_str());
|
||||
const char *ref = attributeValue(attributes, myHrefPredicate);
|
||||
if (ref != 0 && *ref == '#' && *(ref + 1) != '\0') {
|
||||
myImageId = ref + 1;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
shared_ptr<const ZLImage> readCover();
|
||||
|
||||
private:
|
||||
bool processNamespaces() const;
|
||||
void startElementHandler(int tag, const char **attributes);
|
||||
void endElementHandler(int tag);
|
||||
void characterDataHandler(const char *text, size_t len);
|
||||
|
|
|
@ -20,12 +20,14 @@
|
|||
#include <cstring>
|
||||
|
||||
#include <ZLibrary.h>
|
||||
|
||||
#include <ZLStringUtil.h>
|
||||
#include <ZLXMLNamespace.h>
|
||||
|
||||
#include "FB2Reader.h"
|
||||
|
||||
FB2Reader::FB2Reader() : myHrefPredicate(ZLXMLNamespace::XLink, "href") {
|
||||
}
|
||||
|
||||
void FB2Reader::startElementHandler(const char *t, const char **attributes) {
|
||||
startElementHandler(tag(t), attributes);
|
||||
}
|
||||
|
@ -80,21 +82,6 @@ int FB2Reader::tag(const char *name) {
|
|||
}
|
||||
}
|
||||
|
||||
bool FB2Reader::processNamespaces() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void FB2Reader::namespaceListChangedHandler() {
|
||||
const std::map<std::string,std::string> namespaceMap = namespaces();
|
||||
for (std::map<std::string,std::string>::const_iterator it = namespaceMap.begin(); it != namespaceMap.end(); ++it) {
|
||||
if (it->second == ZLXMLNamespace::XLink) {
|
||||
myXLinkNamespace = it->first;
|
||||
return;
|
||||
}
|
||||
}
|
||||
myXLinkNamespace.erase();
|
||||
}
|
||||
|
||||
void FB2Reader::collectExternalEntities(std::map<std::string,std::string> &entityMap) {
|
||||
entityMap["FBReaderVersion"] = ZLibrary::Version();
|
||||
}
|
||||
|
|
|
@ -36,13 +36,9 @@ protected:
|
|||
virtual void startElementHandler(int tag, const char **attributes) = 0;
|
||||
virtual void endElementHandler(int tag) = 0;
|
||||
|
||||
const std::string &xlinkNamespace() const;
|
||||
|
||||
private:
|
||||
void startElementHandler(const char *tag, const char **attributes);
|
||||
void endElementHandler(const char *tag);
|
||||
bool processNamespaces() const;
|
||||
void namespaceListChangedHandler();
|
||||
|
||||
void collectExternalEntities(std::map<std::string,std::string> &entityMap);
|
||||
|
||||
|
@ -89,12 +85,10 @@ protected:
|
|||
FB2Reader();
|
||||
~FB2Reader();
|
||||
|
||||
private:
|
||||
std::string myXLinkNamespace;
|
||||
protected:
|
||||
const NamespaceAttributeNamePredicate myHrefPredicate;
|
||||
};
|
||||
|
||||
inline FB2Reader::FB2Reader() {}
|
||||
inline FB2Reader::~FB2Reader() {}
|
||||
inline const std::string &FB2Reader::xlinkNamespace() const { return myXLinkNamespace; }
|
||||
|
||||
#endif /* __FB2READER_H__ */
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <ZLFile.h>
|
||||
#include <ZLFileImage.h>
|
||||
#include <ZLXMLNamespace.h>
|
||||
|
||||
#include "XHTMLImageFinder.h"
|
||||
#include "../util/MiscUtil.h"
|
||||
|
@ -33,13 +34,18 @@ shared_ptr<const ZLImage> XHTMLImageFinder::readImage(const ZLFile &file) {
|
|||
return myImage;
|
||||
}
|
||||
|
||||
bool XHTMLImageFinder::processNamespaces() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void XHTMLImageFinder::startElementHandler(const char *tag, const char **attributes) {
|
||||
const char *reference = 0;
|
||||
if (TAG_IMG == tag) {
|
||||
reference = attributeValue(attributes, "src");
|
||||
} else if (TAG_IMAGE == tag) {
|
||||
//href = getAttributeValue(attributes, XMLNamespaces.XLink, "href");
|
||||
reference = attributeValue(attributes, "href");
|
||||
reference = attributeValue(
|
||||
attributes, NamespaceAttributeNamePredicate(ZLXMLNamespace::XLink, "href")
|
||||
);
|
||||
}
|
||||
if (reference != 0) {
|
||||
myImage = new ZLFileImage(ZLFile(myPathPrefix + reference), "", 0);
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
shared_ptr<const ZLImage> readImage(const ZLFile &file);
|
||||
|
||||
private:
|
||||
bool processNamespaces() const;
|
||||
void startElementHandler(const char *tag, const char **attributes);
|
||||
|
||||
private:
|
||||
|
|
|
@ -60,9 +60,6 @@ bool ZLXMLReaderHandler::handleBuffer(const char *data, size_t len) {
|
|||
return myReader.readFromBuffer(data, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static const size_t BUFFER_SIZE = 2048;
|
||||
|
||||
void ZLXMLReader::startElementHandler(const char*, const char**) {
|
||||
|
@ -184,13 +181,17 @@ ZLXMLReader::NamespaceAttributeNamePredicate::NamespaceAttributeNamePredicate(co
|
|||
}
|
||||
|
||||
bool ZLXMLReader::NamespaceAttributeNamePredicate::accepts(const ZLXMLReader &reader, const char *name) const {
|
||||
const std::string full(name);
|
||||
const size_t index = full.find(':');
|
||||
const std::string namespaceId =
|
||||
index == std::string::npos ? std::string() : full.substr(0, index);
|
||||
|
||||
const nsMap &namespaces = reader.namespaces();
|
||||
for (nsMap::const_iterator it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
if (it->second == myNamespaceName) {
|
||||
return it->first + ':' + myAttributeName == name;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
nsMap::const_iterator it = namespaces.find(namespaceId);
|
||||
return
|
||||
it != namespaces.end() &&
|
||||
it->second == myNamespaceName &&
|
||||
full.substr(index + 1) == myAttributeName;
|
||||
}
|
||||
|
||||
const char *ZLXMLReader::attributeValue(const char **xmlattributes, const AttributeNamePredicate &predicate) {
|
||||
|
|
|
@ -51,8 +51,9 @@ public:
|
|||
FONT_MODIFIER_UNDERLINED = 1 << 2,
|
||||
FONT_MODIFIER_STRIKEDTHROUGH = 1 << 3,
|
||||
FONT_MODIFIER_SMALLCAPS = 1 << 4,
|
||||
FONT_MODIFIER_SMALLER = 1 << 5,
|
||||
FONT_MODIFIER_LARGER = 1 << 6,
|
||||
FONT_MODIFIER_INHERIT = 1 << 5,
|
||||
FONT_MODIFIER_SMALLER = 1 << 6,
|
||||
FONT_MODIFIER_LARGER = 1 << 7,
|
||||
};
|
||||
|
||||
enum Feature {
|
||||
|
|
|
@ -41,8 +41,9 @@ public final class ZLTextStyleEntry {
|
|||
byte FONT_MODIFIER_UNDERLINED = 1 << 2;
|
||||
byte FONT_MODIFIER_STRIKEDTHROUGH = 1 << 3;
|
||||
byte FONT_MODIFIER_SMALLCAPS = 1 << 4;
|
||||
byte FONT_MODIFIER_SMALLER = 1 << 5;
|
||||
byte FONT_MODIFIER_LARGER = 1 << 6;
|
||||
byte FONT_MODIFIER_INHERIT = 1 << 5;
|
||||
byte FONT_MODIFIER_SMALLER = 1 << 6;
|
||||
byte FONT_MODIFIER_LARGER = (byte)(1 << 7);
|
||||
}
|
||||
|
||||
public interface SizeUnit {
|
||||
|
|
|
@ -42,6 +42,9 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTex
|
|||
}
|
||||
public int getFontSize(ZLTextMetrics metrics) {
|
||||
if (myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||
if (myEntry.getFontModifier(FONT_MODIFIER_INHERIT) == ZLBoolean3.B3_TRUE) {
|
||||
return Base.Base.getFontSize(metrics);
|
||||
}
|
||||
if (myEntry.getFontModifier(FONT_MODIFIER_LARGER) == ZLBoolean3.B3_TRUE) {
|
||||
return Base.Base.getFontSize(metrics) * 120 / 100;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue