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

embedded fonts processing (in progress)

This commit is contained in:
Nikolay Pultsin 2014-03-30 11:20:27 +03:00
parent 06e46d4c33
commit 59639078ea
12 changed files with 209 additions and 84 deletions

View file

@ -22,6 +22,7 @@
#include <ZLStringUtil.h>
#include "StyleSheetTable.h"
#include "StyleSheetUtil.h"
bool StyleSheetTable::isEmpty() const {
return myControlMap.empty() && myPageBreakBeforeMap.empty() && myPageBreakAfterMap.empty();
@ -138,53 +139,6 @@ const std::string &StyleSheetTable::value(const AttributeMap &map, const std::st
return emptyString;
}
static std::string strip(const std::string &data) {
std::string res = data;
ZLStringUtil::stripWhiteSpaces(res);
if (res.size() > 1 && (res[0] == '"' || res[0] == '\'') && res[0] == res[res.size() - 1]) {
return res.substr(1, res.size() - 2);
} else {
return res;
}
}
static std::vector<std::string> splitCommaSeparatedList(const std::string &data) {
std::vector<std::string> split;
enum {
S_QUOTED,
D_QUOTED,
NORMAL
} state = NORMAL;
std::size_t start = 0;
for (std::size_t i = 0; i < data.size(); ++i) {
const char ch = data[i];
switch (state) {
case NORMAL:
if (ch == ',') {
if (i > start) {
split.push_back(strip(data.substr(start, i - start)));
}
start = i + 1;
}
break;
case S_QUOTED:
if (ch == '\'') {
state = NORMAL;
}
break;
case D_QUOTED:
if (ch == '"') {
state = NORMAL;
}
break;
}
}
return split;
}
shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &styles) {
shared_ptr<ZLTextStyleEntry> entry = new ZLTextStyleEntry(ZLTextStyleEntry::STYLE_CSS_ENTRY);
@ -240,7 +194,7 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &
const std::string &fontFamily = value(styles, "font-family");
if (!fontFamily.empty()) {
std::vector<std::string> families = splitCommaSeparatedList(fontFamily);
std::vector<std::string> families = StyleSheetUtil::splitCommaSeparatedList(fontFamily);
// TODO: use all families
if (!families.empty()) {
entry->setFontFamily(families[0]);