Commit 8056c107 authored by Victor Yacovlev's avatar Victor Yacovlev

DocBookViewer: fixed rendering on dark screen theme

parent 964bd6f2
......@@ -138,6 +138,9 @@ QString ContentView::renderArticle(ModelPtr data) const
QString ContentView::wrapHTML(const QString &body) const
{
const QPalette pal = palette();
const QColor fg = pal.brush(QPalette::Text).color();
const QColor bg = pal.brush(QPalette::Background).color();
return QString() +
"<html><head>"
"<style type=\"text/css\">"
......@@ -170,6 +173,11 @@ QString ContentView::wrapHTML(const QString &body) const
" font-family: " + CodeFontFamily + ";"
" font-size: " + CodeFontSize + ";"
"}"
"th {"
" font-weight: bold;"
" color: " + bg.name() + ";"
" background-color: " + fg.name() + ";"
"}"
"h2 {"
" align: center;"
" margin: 30;"
......@@ -177,6 +185,7 @@ QString ContentView::wrapHTML(const QString &body) const
"kbd {"
" font-family: " + GuiElementsFontFamily + ";"
" background-color: lightgray;"
" color: black;"
"}"
"</style></head>"
"<body>\n" + body +"\n</body></html>";
......@@ -479,7 +488,7 @@ QString ContentView::renderTableContent(ModelPtr data) const
QString ContentView::renderTHead(ModelPtr data) const
{
QString result;
result += "<thead>\n";
result += "<thead class='table-head'>\n";
result += renderChilds(data);
result += "</thead>\n";
return result;
......@@ -512,7 +521,7 @@ QString ContentView::renderRow(ModelPtr data) const
}
QString result;
if (inTableHead) {
result += "<tr valign='center' bgcolor='lightgray'>\n";
result += "<tr valign='center'>\n";
}
else {
result += "<tr valign='center'>\n";
......@@ -539,15 +548,19 @@ QString ContentView::renderEntry(ModelPtr data) const
parent = parent->parent();
}
QString result;
result += "<td align='center' valign='center'>\n";
if (inTableHead) {
result += "<b>";
result += "<th align='center' valign='center'>\n";
}
else {
result += "<td align='center' valign='center'>\n";
}
result += renderChilds(data);
if (inTableHead) {
result += "</b>";
result += "</th>\n";
}
else {
result += "</td>\n";
}
result += "</td>\n";
return result;
}
......
......@@ -10,6 +10,7 @@ static const qreal MIN_FONT_SIZE = 9.0; /* pt */
static const int GRAPHICS_SPACING = 1; /* px */
static const int REGULAR_LINE_WIDTH = 2; /* px */
static const int FRAC_LINE_WIDTH = 1; /* px */
static const int SQRT_LINE_WIDTH = 1; /* px */
MathMLRenderer* MathMLRenderer::self()
{
......@@ -21,6 +22,9 @@ const QImage& MathMLRenderer::render(ModelPtr data)
{
if (data->cachedImage_.isNull()) {
font_ = mathFont(BASE_FONT_SIZE);
const QPalette pal = qApp->palette();
fgColor_ = pal.brush(QPalette::Text).color();
bgColor_ = pal.brush(QPalette::Background).color();
data->cachedImage_ = renderBlock(data);
}
return data->cachedImage_;
......@@ -154,6 +158,7 @@ QImage MathMLRenderer::renderOperator(ModelPtr element)
result.fill(0);
QPainter painter(&result);
painter.setFont(font);
painter.setPen(fgColor_);
painter.drawText(0, result.height() - fm.descent() - fm.leading(), op);
painter.end();
}
......@@ -170,6 +175,8 @@ QImage MathMLRenderer::renderPlainText(ModelPtr element)
image.fill(0);
QPainter painter(&image);
painter.setFont(font_);
painter.setPen(fgColor_);
painter.setRenderHint(QPainter::TextAntialiasing, true);
painter.drawText(1, image.height() - fm.descent() - fm.leading(), plainText);
painter.end();
return image;
......@@ -187,8 +194,9 @@ QImage MathMLRenderer::renderSqrt(ModelPtr element)
result.fill(0);
QPainter painter(&result);
QPen pen;
pen.setColor(Qt::black);
pen.setWidth(REGULAR_LINE_WIDTH);
pen.setColor(fgColor_);
pen.setWidth(SQRT_LINE_WIDTH);
painter.setPen(pen);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawLine(0, result.height() - sqrtSymbolHeight,
sqrtSymbolWidth / 2, result.height());
......@@ -225,7 +233,7 @@ QImage MathMLRenderer::renderFrac(ModelPtr element)
firstImage.height() + 2 * GRAPHICS_SPACING +
FRAC_LINE_WIDTH, secondImage);
QPen pen;
pen.setColor(Qt::black);
pen.setColor(fgColor_);
pen.setWidth(FRAC_LINE_WIDTH);
painter.setPen(pen);
painter.drawLine(0,
......
......@@ -6,6 +6,7 @@
#include <QtGlobal>
#include <QImage>
#include <QFont>
#include <QColor>
namespace DocBookViewer {
......@@ -36,6 +37,8 @@ private:
MathMLRenderer();
QFont font_;
QColor fgColor_;
QColor bgColor_;
};
} // namespace DocBookViewer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment