fb2 support
This commit is contained in:
18 files changed
+2352
-54
No files matched your search
@@ -17,6 +17,7 @@ struct StyleContext {
|
||||
qreal textIndent = 0;
|
||||
qreal lineHeight = 0;
|
||||
bool preformatted = false;
|
||||
bool isHeading = false;
|
||||
};
|
||||
|
||||
QString localName(const QDomElement &e)
|
||||
@@ -152,6 +153,28 @@ void applyCssDeclarations(const QVector<Css::Declaration> &decls,
|
||||
auto m = Css::parseLength(val, lenCtx); if (m) box.marginLeft = *m;
|
||||
} else if (prop == QLatin1String("margin-right")) {
|
||||
auto m = Css::parseLength(val, lenCtx); if (m) box.marginRight = *m;
|
||||
} else if (prop == QLatin1String("margin")) {
|
||||
const QStringList tokens = Css::splitValue(val);
|
||||
QVector<qreal> vals;
|
||||
for (const QString &tok : tokens) {
|
||||
auto m = Css::parseLength(tok, lenCtx);
|
||||
if (m) vals.append(*m);
|
||||
}
|
||||
if (vals.size() == 1) {
|
||||
box.marginTop = box.marginRight = box.marginBottom = box.marginLeft = vals[0];
|
||||
} else if (vals.size() == 2) {
|
||||
box.marginTop = box.marginBottom = vals[0];
|
||||
box.marginRight = box.marginLeft = vals[1];
|
||||
} else if (vals.size() == 3) {
|
||||
box.marginTop = vals[0];
|
||||
box.marginRight = box.marginLeft = vals[1];
|
||||
box.marginBottom = vals[2];
|
||||
} else if (vals.size() >= 4) {
|
||||
box.marginTop = vals[0];
|
||||
box.marginRight = vals[1];
|
||||
box.marginBottom = vals[2];
|
||||
box.marginLeft = vals[3];
|
||||
}
|
||||
} else if (prop == QLatin1String("padding-top")) {
|
||||
auto p = Css::parseLength(val, lenCtx); if (p) box.paddingTop = *p;
|
||||
} else if (prop == QLatin1String("padding-bottom")) {
|
||||
@@ -160,6 +183,28 @@ void applyCssDeclarations(const QVector<Css::Declaration> &decls,
|
||||
auto p = Css::parseLength(val, lenCtx); if (p) box.paddingLeft = *p;
|
||||
} else if (prop == QLatin1String("padding-right")) {
|
||||
auto p = Css::parseLength(val, lenCtx); if (p) box.paddingRight = *p;
|
||||
} else if (prop == QLatin1String("padding")) {
|
||||
const QStringList tokens = Css::splitValue(val);
|
||||
QVector<qreal> vals;
|
||||
for (const QString &tok : tokens) {
|
||||
auto p = Css::parseLength(tok, lenCtx);
|
||||
if (p) vals.append(*p);
|
||||
}
|
||||
if (vals.size() == 1) {
|
||||
box.paddingTop = box.paddingRight = box.paddingBottom = box.paddingLeft = vals[0];
|
||||
} else if (vals.size() == 2) {
|
||||
box.paddingTop = box.paddingBottom = vals[0];
|
||||
box.paddingRight = box.paddingLeft = vals[1];
|
||||
} else if (vals.size() == 3) {
|
||||
box.paddingTop = vals[0];
|
||||
box.paddingRight = box.paddingLeft = vals[1];
|
||||
box.paddingBottom = vals[2];
|
||||
} else if (vals.size() >= 4) {
|
||||
box.paddingTop = vals[0];
|
||||
box.paddingRight = vals[1];
|
||||
box.paddingBottom = vals[2];
|
||||
box.paddingLeft = vals[3];
|
||||
}
|
||||
} else if (prop == QLatin1String("border")) {
|
||||
auto b = Css::parseBorderSide(val, lenCtx);
|
||||
if (b.width) {
|
||||
@@ -374,30 +419,42 @@ private:
|
||||
ctx.text.fontSize = m_params.baseFontSize * 1.8;
|
||||
ctx.text.weight = 700;
|
||||
ctx.textIndent = 0;
|
||||
ctx.align = TextAlign::Left;
|
||||
ctx.isHeading = true;
|
||||
box.marginTop = m_params.baseFontSize * 1.0;
|
||||
box.marginBottom = m_params.baseFontSize * 0.5;
|
||||
} else if (tag == QLatin1String("h2")) {
|
||||
ctx.text.fontSize = m_params.baseFontSize * 1.5;
|
||||
ctx.text.weight = 700;
|
||||
ctx.textIndent = 0;
|
||||
ctx.align = TextAlign::Left;
|
||||
ctx.isHeading = true;
|
||||
box.marginTop = m_params.baseFontSize * 0.8;
|
||||
box.marginBottom = m_params.baseFontSize * 0.4;
|
||||
} else if (tag == QLatin1String("h3")) {
|
||||
ctx.text.fontSize = m_params.baseFontSize * 1.3;
|
||||
ctx.text.weight = 700;
|
||||
ctx.textIndent = 0;
|
||||
ctx.align = TextAlign::Left;
|
||||
ctx.isHeading = true;
|
||||
box.marginTop = m_params.baseFontSize * 0.6;
|
||||
box.marginBottom = m_params.baseFontSize * 0.3;
|
||||
} else if (tag == QLatin1String("h4") || tag == QLatin1String("h5") || tag == QLatin1String("h6")) {
|
||||
ctx.text.fontSize = m_params.baseFontSize * 1.1;
|
||||
ctx.text.weight = 700;
|
||||
ctx.textIndent = 0;
|
||||
ctx.align = TextAlign::Left;
|
||||
ctx.isHeading = true;
|
||||
box.marginTop = m_params.baseFontSize * 0.5;
|
||||
box.marginBottom = m_params.baseFontSize * 0.25;
|
||||
} else if (tag == QLatin1String("p")) {
|
||||
box.marginTop = m_params.baseFontSize * 0.25;
|
||||
box.marginBottom = m_params.baseFontSize * 0.5;
|
||||
ctx.textIndent = m_params.baseFontSize * 1.25;
|
||||
box.marginTop = 0;
|
||||
box.marginBottom = 0;
|
||||
if (!ctx.isHeading) {
|
||||
ctx.textIndent = m_params.baseFontSize * 2.0;
|
||||
} else {
|
||||
ctx.textIndent = 0;
|
||||
}
|
||||
} else if (tag == QLatin1String("blockquote")) {
|
||||
box.marginLeft = m_params.baseFontSize * 1.5;
|
||||
box.marginRight = m_params.baseFontSize * 1.0;
|
||||
|
||||
Reference in new issue
Block a user