aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-02-10 15:50:33 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-02-10 10:06:15 +0100
commitb1e25a64dee20f7eb5b7fc15414fb69a7b0ace1d (patch)
tree4a3fa888b9bf10495425536409f09316f86624cd /src
parent08e2184c9f77fa627d33c2de08addae934a2308f (diff)
downloadkristall-b1e25a64dee20f7eb5b7fc15414fb69a7b0ace1d.tar.gz
geminirenderer: readibility improvements
Values are hard-coded at the moment. Need preferences
Diffstat (limited to 'src')
-rw-r--r--src/renderers/geminirenderer.cpp16
-rw-r--r--src/renderers/textstyleinstance.cpp20
-rw-r--r--src/renderers/textstyleinstance.hpp3
3 files changed, 35 insertions, 4 deletions
diff --git a/src/renderers/geminirenderer.cpp b/src/renderers/geminirenderer.cpp
index e7d18b5..1887dab 100644
--- a/src/renderers/geminirenderer.cpp
+++ b/src/renderers/geminirenderer.cpp
@@ -77,6 +77,7 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
{
if (current_list == nullptr)
{
+ cursor.setBlockFormat(text_style.list_format);
cursor.deletePreviousChar();
current_list = cursor.insertList(QTextListFormat::ListDisc);
}
@@ -129,7 +130,9 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
fmt.setAnchor(true);
fmt.setAnchorNames(QStringList { id });
- cursor.insertText(heading + "\n", fmt);
+ cursor.setBlockFormat(text_style.heading_format);
+ cursor.insertText(heading, fmt);
+ cursor.insertText("\n", text_style.standard);
outline.appendH3(heading, id);
}
else if (line.startsWith("##"))
@@ -141,7 +144,9 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
fmt.setAnchor(true);
fmt.setAnchorNames(QStringList { id });
- cursor.insertText(heading + "\n", fmt);
+ cursor.setBlockFormat(text_style.heading_format);
+ cursor.insertText(heading, fmt);
+ cursor.insertText("\n", text_style.standard);
outline.appendH2(heading, id);
}
else if (line.startsWith("#"))
@@ -153,7 +158,9 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
fmt.setAnchor(true);
fmt.setAnchorNames(QStringList { id });
- cursor.insertText(heading + "\n", fmt);
+ cursor.setBlockFormat(text_style.heading_format);
+ cursor.insertText(heading, fmt);
+ cursor.insertText("\n", text_style.standard);
outline.appendH1(heading, id);
// Use first heading as the page's title.
@@ -220,6 +227,7 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
fmt.setAnchor(true);
fmt.setAnchorHref(absolute_url.toString());
+ cursor.setBlockFormat(text_style.link_format);
cursor.insertText(prefix + title + suffix + "\n", fmt);
}
else if (line.startsWith("```"))
@@ -228,6 +236,8 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
}
else
{
+ cursor.setBlockFormat(text_style.standard_format);
+
if(emit_fancy_text)
{
// TODO: Fix UTF-8 encoding here… Don't emit single characters but always spans!
diff --git a/src/renderers/textstyleinstance.cpp b/src/renderers/textstyleinstance.cpp
index 6d734f1..0a99625 100644
--- a/src/renderers/textstyleinstance.cpp
+++ b/src/renderers/textstyleinstance.cpp
@@ -28,6 +28,24 @@ TextStyleInstance::TextStyleInstance(DocumentStyle const & themed_style)
preformatted_format.setNonBreakableLines(true);
- block_quote_format.setIndent(1);
+ block_quote_format.setIndent(2);
block_quote_format.setBackground(themed_style.blockquote_color);
+
+ // Other alignments
+ standard_format.setAlignment(Qt::AlignJustify);
+ standard_format.setLineHeight(5, QTextBlockFormat::LineDistanceHeight);
+ standard_format.setIndent(1);
+
+ link_format.setLineHeight(5, QTextBlockFormat::LineDistanceHeight);
+
+ block_quote_format.setAlignment(Qt::AlignJustify);
+ block_quote_format.setLineHeight(5, QTextBlockFormat::LineDistanceHeight);
+
+ list_format.setAlignment(Qt::AlignJustify);
+ list_format.setLineHeight(5, QTextBlockFormat::LineDistanceHeight);
+ list_format.setIndent(2);
+
+ preformatted_format.setIndent(1);
+
+ heading_format.setLineHeight(0, QTextBlockFormat::LineDistanceHeight);
}
diff --git a/src/renderers/textstyleinstance.hpp b/src/renderers/textstyleinstance.hpp
index eb8b513..043ddcb 100644
--- a/src/renderers/textstyleinstance.hpp
+++ b/src/renderers/textstyleinstance.hpp
@@ -20,6 +20,9 @@ struct TextStyleInstance
QTextBlockFormat standard_format;
QTextBlockFormat preformatted_format;
QTextBlockFormat block_quote_format;
+ QTextBlockFormat heading_format;
+ QTextBlockFormat link_format;
+ QTextBlockFormat list_format;
explicit TextStyleInstance(DocumentStyle const & style);
};