[LyX/master] Fixup a2378c1182: handle the monospace case
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Fri Mar 17 12:25:25 UTC 2023
commit e2011856bc17953d0fb6fb37a8bdeea8f6e3ff1a
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Fri Mar 17 14:19:33 2023 +0100
Fixup a2378c1182: handle the monospace case
When the font is tt, the stretch space is null. Change the display
rendering to accomodate that.
---
src/insets/InsetSpecialChar.cpp | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp
index fd36a21..5983c07 100644
--- a/src/insets/InsetSpecialChar.cpp
+++ b/src/insets/InsetSpecialChar.cpp
@@ -209,11 +209,14 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
case END_OF_SENTENCE:
s = from_ascii(".");
break;
- case LDOTS:
+ case LDOTS: {
// see comment in draw().
- dim.wid = 3 * fm.width(char_type('.'))
- + 3 * fm.width(char_type(' ')) / 2;
+ auto const fam = mi.base.font.family();
+ // Multiplication by 3 is done here to limit rounding effects.
+ int const spc3 = fam == TYPEWRITER_FAMILY ? 0 : 3 * fm.width(char_type(' ')) / 2;
+ dim.wid = 3 * fm.width(char_type('.')) + spc3;
break;
+ }
case MENU_SEPARATOR:
// ▹ U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE
// There is a \thinspace on each side of the triangle
@@ -291,7 +294,9 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
* that this is usually half a space.
*/
frontend::FontMetrics const & fm = theFontMetrics(font);
- int wid1 = fm.width(char_type('.')) + fm.width(char_type(' ')) / 2;
+ auto const fam = pi.base.font.family();
+ int const spc = fam == TYPEWRITER_FAMILY ? 0 : fm.width(char_type(' ')) / 2;
+ int wid1 = fm.width(char_type('.')) + spc;
pi.pain.text(x, y, char_type('.'), font);
pi.pain.text(x + wid1, y, char_type('.'), font);
pi.pain.text(x + 2 * wid1, y, char_type('.'), font);
More information about the lyx-cvs
mailing list