Skip to content

Commit 5bead02

Browse files
committed
fix(export): size wkhtmltopdf MathJax via scale, not the no-op minScale
Follow-up to c3e72cf. That commit plumbed a MathJax `minScale` option to floor the auto font-match at 1.0 for the wkhtmltopdf export, based on a wrong premise: MathJax v3's SVG output has no matchFontHeight, so `minScale` never takes effect there. Measuring rendered equation height across scale/minScale combinations in Chromium (the same engine VNote's WebEngine uses to render the math that is then handed to wkhtmltopdf) confirmed it: minScale 0.5, 1.0 and 1.25 render identically, while the math size tracks `scale` exactly (ratio == scale). So the only real effect of the previous change was dropping scale 2.5 -> 1.0, which shrank math to Latin-text size -- too small next to CJK glyphs in CJK-heavy notes. - Revert the no-op mathJaxMinScale plumbing (struct fields in MarkdownWebGlobalOptions and MarkdownParas, the toJavascriptObject() emit, both generateMarkdownViewerTemplate builders, and the mathjax.js svg block). - Set mathJaxScale = 1.5 for the wkhtmltopdf path only, so math renders at 1.5x body text: readable in print without the old 2.5x excess. Preview and Qt WebEngine printToPdf stay at the MathJax default (-1). - Document in-code that scale is the only effective lever for SVG output so minScale is not reintroduced.
1 parent c3e72cf commit 5bead02

5 files changed

Lines changed: 11 additions & 17 deletions

File tree

src/core/htmltemplatehelper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ QString HtmlTemplateHelper::generateMarkdownViewerTemplate(const MarkdownEditorC
211211
opts.m_bodyHeight = p_paras.m_bodyHeight;
212212
opts.m_transformSvgToPngEnabled = p_paras.m_transformSvgToPngEnabled;
213213
opts.m_mathJaxScale = p_paras.m_mathJaxScale;
214-
opts.m_mathJaxMinScale = p_paras.m_mathJaxMinScale;
215214
opts.m_removeCodeToolBarEnabled = p_paras.m_removeCodeToolBarEnabled;
216215
fillGlobalOptions(htmlTemplate, opts);
217216
}

src/core/htmltemplatehelper.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ struct MarkdownWebGlobalOptions {
5454
// This is just a hint not mandatory. For now, PlantUML and Graphviz needs this.
5555
bool m_transformSvgToPngEnabled = false;
5656

57-
// wkhtmltopdf mis-measures ex-height, shrinking MathJax to its minScale floor.
58-
// m_mathJaxScale: global scale factor (-1 => MathJax default 1).
57+
// wkhtmltopdf renders MathJax at the surrounding (Latin) text size, which looks too
58+
// small next to CJK glyphs; the export path scales it up. -1 => MathJax default 1.
59+
// NOTE: MathJax v3 SVG output has no matchFontHeight, so its `minScale` option is a
60+
// no-op -- `scale` is the only effective lever (verified by measuring rendered height).
5961
qreal m_mathJaxScale = -1;
60-
// m_mathJaxMinScale: floor for MathJax's text-matching scale (-1 => MathJax default 0.5).
61-
// Set to 1 for wkhtmltopdf export so math is not shrunk below text size.
62-
qreal m_mathJaxMinScale = -1;
6362

6463
// Whether remove the tool bar of code blocks added by Prism.js.
6564
bool m_removeCodeToolBarEnabled = false;
@@ -87,8 +86,6 @@ class HtmlTemplateHelper {
8786

8887
qreal m_mathJaxScale = -1;
8988

90-
qreal m_mathJaxMinScale = -1;
91-
9289
bool m_removeCodeToolBarEnabled = false;
9390
};
9491

src/core/markdownwebglobaloptions.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ QString MarkdownWebGlobalOptions::toJavascriptObject() const {
3737
QStringLiteral("transformSvgToPngEnabled: %1,\n")
3838
.arg(Utils::boolToString(m_transformSvgToPngEnabled)) +
3939
QStringLiteral("mathJaxScale: %1,\n").arg(m_mathJaxScale) +
40-
QStringLiteral("mathJaxMinScale: %1,\n").arg(m_mathJaxMinScale) +
4140
QStringLiteral("removeCodeToolBarEnabled: %1,\n")
4241
.arg(Utils::boolToString(m_removeCodeToolBarEnabled)) +
4342
QStringLiteral("sectionNumberBaseLevel: %1\n").arg(m_sectionNumberBaseLevel) +

src/data/extra/web/js/mathjax.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ window.MathJax = {
1919
svg: {
2020
// Make SVG self-contained.
2121
fontCache: 'local',
22-
scale: window.vxOptions.mathJaxScale > 0 ? window.vxOptions.mathJaxScale : 1,
23-
minScale: window.vxOptions.mathJaxMinScale > 0 ? window.vxOptions.mathJaxMinScale : 0.5
22+
scale: window.vxOptions.mathJaxScale > 0 ? window.vxOptions.mathJaxScale : 1
2423
}
2524
};
2625

src/export/webviewexporter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ QString generateMarkdownViewerTemplate(ConfigMgr2 &p_configMgr,
201201
opts.m_bodyHeight = p_paras.m_bodyHeight;
202202
opts.m_transformSvgToPngEnabled = p_paras.m_transformSvgToPngEnabled;
203203
opts.m_mathJaxScale = p_paras.m_mathJaxScale;
204-
opts.m_mathJaxMinScale = p_paras.m_mathJaxMinScale;
205204
opts.m_removeCodeToolBarEnabled = p_paras.m_removeCodeToolBarEnabled;
206205
fillGlobalOptions(htmlTemplate, opts);
207206

@@ -479,11 +478,12 @@ void WebViewExporter::prepare(const ExportOption &p_option) {
479478
paras.m_bodyWidth = pageBodySize.width();
480479
paras.m_bodyHeight = pageBodySize.height();
481480
paras.m_transformSvgToPngEnabled = p_option.m_transformSvgToPngEnabled;
482-
// wkhtmltopdf's old WebKit mis-measures the surrounding text's ex-height, so MathJax
483-
// shrinks each equation to its minScale floor (0.5). Raise that floor to 1.0 instead of
484-
// blindly multiplying by 2.5 (which over-enlarged math to 1.25x text).
485-
paras.m_mathJaxScale = -1;
486-
paras.m_mathJaxMinScale = useWkhtmltopdf ? 1.0 : -1;
481+
// wkhtmltopdf renders MathJax SVG at the surrounding Latin text size (scale x 1.0), which
482+
// looks too small beside the larger CJK glyphs in CJK-heavy notes. Enlarge math to 1.5x
483+
// body text for this export path only. `scale` is the ONLY effective lever here: MathJax
484+
// v3 SVG output has no matchFontHeight, so the `minScale` option is a no-op (verified by
485+
// measuring rendered equation height across scale/minScale combinations).
486+
paras.m_mathJaxScale = useWkhtmltopdf ? 1.5 : -1;
487487
paras.m_removeCodeToolBarEnabled = p_option.m_removeCodeToolBarEnabled;
488488

489489
m_htmlTemplate = generateMarkdownViewerTemplate(*configMgr, config, paras);

0 commit comments

Comments
 (0)