Support multiple inline styles

This commit is contained in:
Slava Monich 2015-07-04 02:37:30 +03:00
parent c787512e99
commit a6a5773fb6
3 changed files with 50 additions and 7 deletions

View file

@ -516,6 +516,7 @@ shared_ptr<ZLTextStyleEntry> XHTMLReader::addStyleEntry(shared_ptr<ZLTextStyleEn
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
static const std::string HASH = "#";
static const std::string EMPTY;
const char *id = attributeValue(attributes, "id");
if (id != 0) {
myModelReader.addHyperlinkLabel(myReferenceName + HASH + id);
@ -524,7 +525,13 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
const std::string sTag = ZLUnicodeUtil::toLower(tag);
const char *aClass = attributeValue(attributes, "class");
const std::string sClass = (aClass != 0) ? aClass : "";
std::vector<std::string> classes;
if (aClass != 0) {
classes = ZLStringUtil::splitString(aClass, ", \n");
}
if (classes.empty()) {
classes.push_back(EMPTY);
}
shared_ptr<ZLTextStyleEntry> inlineStyle;
const char *style = attributeValue(attributes, "style");
@ -532,11 +539,26 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
if (style != 0) {
inlineStyle = myStyleParser.parseString(style, &pageBreakBefore, &pageBreakAfter);
}
if (pageBreakBefore == B3_TRUE || (pageBreakBefore == B3_UNDEFINED && myStyleSheetTable.doBreakBefore(sTag, sClass))) {
if (pageBreakBefore == B3_UNDEFINED) {
for (unsigned int i=0; i<classes.size(); i++) {
if (myStyleSheetTable.doBreakBefore(sTag, classes[i])) {
pageBreakBefore = B3_TRUE;
break;
}
}
}
if (pageBreakAfter == B3_UNDEFINED) {
for (unsigned int i=0; i<classes.size(); i++) {
if (myStyleSheetTable.doBreakAfter(sTag, classes[i])) {
pageBreakAfter = B3_TRUE;
break;
}
}
}
if (pageBreakBefore == B3_TRUE) {
myModelReader.insertEndOfSectionParagraph();
}
myDoPageBreakAfterStack.push_back(pageBreakAfter == B3_TRUE || (pageBreakAfter == B3_UNDEFINED && myStyleSheetTable.doBreakAfter(sTag, sClass)));
myDoPageBreakAfterStack.push_back(pageBreakAfter == B3_TRUE);
XHTMLTagAction *action = ourTagActions[sTag];
if (action != 0) {
@ -544,9 +566,14 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
}
shared_ptr<ZLTextStyleEntry> entry;
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, ""));
entry = addStyleEntry(entry, myStyleSheetTable.control("", sClass));
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, sClass));
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, EMPTY));
for (unsigned int i=0; i<classes.size(); i++) {
std::string klass = classes[i];
entry = addStyleEntry(entry, myStyleSheetTable.control(EMPTY, klass));
if (!klass.empty()) {
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, klass));
}
}
entry = addStyleEntry(entry, inlineStyle);
if (!entry.isNull()) {
myModelReader.addControl(*entry);

View file

@ -21,6 +21,7 @@
#include <cstdio>
#include <cstdlib>
#include <locale.h>
#include <string.h>
#include "ZLStringUtil.h"
@ -90,6 +91,20 @@ void ZLStringUtil::stripWhiteSpaces(std::string &str) {
str.erase(r_counter, length - r_counter);
}
std::vector<std::string> ZLStringUtil::splitString(const std::string &str, const char* delim)
{
std::vector<std::string> tokens;
char *buf = strdup(str.c_str());
char *saveptr;
char *token = strtok_r(buf, delim, &saveptr);
while (token) {
tokens.push_back(std::string(token));
token = strtok_r(NULL, delim, &saveptr);
}
free(buf);
return tokens;
}
std::string ZLStringUtil::printf(const std::string &format, const std::string &arg0) {
int index = format.find("%s");
if (index == -1) {

View file

@ -34,6 +34,7 @@ public:
static void appendNumber(std::string &str, unsigned int n);
static void append(std::string &str, const std::vector<std::string> &buffer);
static void stripWhiteSpaces(std::string &str);
static std::vector<std::string> splitString(const std::string &str, const char* delim);
static std::string printf(const std::string &format, const std::string &arg0);