summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-01-10 14:24:40 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-12 09:52:41 +0000
commitbedf6e33cc4c07f541de815119a2c1346a77422f (patch)
treef859dd1cda400b5dd6468cc5b8a950e9c7df9c0a /src/gui/text
parenta318de3f404d06b70b9403377256e1edf26d68e9 (diff)
Use QTextCharFormat::fontFixedPitch to remember Markdown backtick spans
If the editing app (like qtbase/examples/widgets/richtext/textedit) has controls only for setting a specific font, and someone uses it to write markdown "from scratch", then we need to detect that they chose Courier or some other fixed-pitch font, and write the backticks, because Markdown has no syntax for selecting a specific font family. If the user loads markdown into such an application, the font is set to QFontDatabase::systemFont(QFontDatabase::FixedFont). Round-trip editing was already working, as long as such a font exists. QTextCharFormat::setFont() calls setFontFixedPitch(font.fixedPitch()), but for the chosen "mono" font, font.fixedPitch() can be false. For semantic completeness and separation of concerns, we now set fontFixedPitch explicitly if a `backtick` span is encountered. As a followup to f1e60de66540b198d696253ab5148de4fcbff319 this should get its autotest passing reliably. Fixes: QTBUG-99676 Change-Id: I4987a1f0f819f82ec64546bdc3ef53e7d29933de Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> (cherry picked from commit 17dca04a613b632d6c0d4340eedbdc86e250c455) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextmarkdownimporter.cpp1
-rw-r--r--src/gui/text/qtextmarkdownwriter.cpp2
2 files changed, 2 insertions, 1 deletions
diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp
index 35feb0b3b1..2758d558a2 100644
--- a/src/gui/text/qtextmarkdownimporter.cpp
+++ b/src/gui/text/qtextmarkdownimporter.cpp
@@ -426,6 +426,7 @@ int QTextMarkdownImporter::cbEnterSpan(int spanType, void *det)
}
case MD_SPAN_CODE:
charFmt.setFont(m_monoFont);
+ charFmt.setFontFixedPitch(true);
break;
case MD_SPAN_DEL:
charFmt.setFontStrikeOut(true);
diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp
index e99242218c..fc14e28767 100644
--- a/src/gui/text/qtextmarkdownwriter.cpp
+++ b/src/gui/text/qtextmarkdownwriter.cpp
@@ -532,7 +532,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign
col += s.length();
} else {
QFontInfo fontInfo(fmt.font());
- bool monoFrag = fontInfo.fixedPitch();
+ bool monoFrag = fontInfo.fixedPitch() || fmt.fontFixedPitch();
QString markers;
if (!ignoreFormat) {
if (monoFrag != mono && !m_indentedCodeBlock && !m_fencedCodeBlock) {