<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Centred text with setFontWithSpacing drifts left]]></title><description><![CDATA[<p dir="auto">I noticed my 'centred' knob labels were shifted 1-2px to the left and it turns out that letter spacing adds extra space after the last character, which shifts the whole text left.</p>
<p dir="auto"><strong>Wider letter spacing = further shift to the left.</strong></p>
<p dir="auto">Claude says it expected JUCE behaviour. Expected, maybe, but not cool. <img src="https://forum.hise.audio/assets/plugins/nodebb-plugin-emoji/emoji/android/1f615.png?v=fba14f4754a" class="not-responsive emoji emoji-android emoji--confused" style="height:23px;width:auto;vertical-align:middle" title=":confused:" alt="😕" /></p>
<p dir="auto">Notice how the first row (zero spacing) is centred, then the text shifts progressively further left as the spacing increases. The last 2 rows show 2 different fixes that Claude suggested. No idea how robust the fixes are. They're in the snippet at the bottom.</p>
<p dir="auto"><strong>During this, Claude also found 2 HISE bugs. I'm still unpacking so I can submit bug fixes. Full explanation below the image.</strong></p>
<p dir="auto"><img src="/assets/uploads/files/1787061269374-cleanshot-2026-08-18-at-14.53.45-2x.png" alt="CleanShot 2026-08-18 at 14.53.45@2x.png" class=" img-fluid img-markdown" /></p>
<blockquote>
<p dir="auto"><strong>1. Centred text with <code>setFontWithSpacing</code> drifts left (JUCE behaviour)</strong></p>
<p dir="auto"><code>setFontWithSpacing</code> maps to <code>Font::setExtraKerningFactor</code>, and JUCE adds <code>spacing × height</code> after <em>every</em> glyph, including the last one. <code>drawAlignedText(..., "centred")</code> centres the advance box, which therefore has an invisible trailing gap, so the visible glyphs end up <code>spacing × height / 2</code> px left of centre. Small at typical values (0.075 × 15 px ≈ 0.6 px) but visible on all-caps labels under a knob. Fine, that's how JUCE works, but the obvious fixes both fell over because of 2 and 3.</p>
<p dir="auto"><strong>2. <code>"Default"</code> ignores the font size</strong></p>
<p dir="auto"><code>g.setFont("Default", 30)</code> and <code>g.setFontWithSpacing("Default", 30, x)</code> do not draw at 30 px. <code>MainController::getFontFromString</code> returns <code>globalFont</code> unchanged for <code>"Default"</code> (<code>hi_core/hi_core/MainController.cpp</code> ~line 2035), so the size argument is dropped and you get the global font at its own height (~14 px). No error, no warning. Every other font name goes through <code>Font(typeface).withHeight(fontSize)</code>. I'd expect <code>globalFont.withHeight(fontSize)</code> here.</p>
<p dir="auto"><strong>3. <code>g.getStringWidth</code> doesn't measure the font that was set</strong></p>
<p dir="auto"><code>getStringWidth</code> doesn't ask the current <code>Font</code> for its width; it looks up a per-character normalised width table (<code>CustomTypeFace::getStringWidthFloat</code>, <code>MainController.h</code> ~line 2318) for the current font <em>name</em>, and if the name isn't a <code>loadFontAs</code> font it falls back to <code>defaultFont</code>'s table – then multiplies by the <em>requested</em> size. So with <code>"Default"</code> you get a different typeface's widths at a size that isn't being drawn. In my test the returned width was ~2.5× the rendered width. Combined with 2, both "shift by half the gap" and "measure and left-align" corrections came out wrong until I switched to a <code>loadFontAs</code> font.</p>
<p dir="auto">Suggestion: <code>getStringWidth</code> could just use <code>currentFont.getStringWidthFloat(text)</code> (the <code>Font</code> object is right there in <code>setFontWithSpacing</code>), which would honour size, kerning and the real typeface.</p>
<p dir="auto"><strong>Repro</strong> – snippet below. Six rows: a centred white bar with <code>MMMMM</code> "centred" beneath it at increasing spacing, then the last two rows apply the two corrections. Swap <code>FONT</code> to <code>"Default"</code> to see 2 and 3 (text renders ~14 px regardless of <code>SIZE</code>, <code>+measure</code> row lands far off).</p>
</blockquote>
<pre><code>HiseSnippet 2430.3ocsX8taaibDmJI5ZsZu16.5CvT8kRYSq+cxWbsqQtDG4F2KN1vxWR6EDDrhbo3VSsKA4RKqdHE8MnEnen.8S8wnnesuI2KP6av0Y1kThx1W9iAJMLf3ryL672e6v8jTkOOKSk5TqwYyS3N09w0GMWpi1OhIjNG9XmZ+j5Gwxz7TvR5QySXYY7.mZ0t6ulHTas64Xd9uO3QrXlzmujjiy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GrH5pmsLxRmQMyy1UrI91qPzUZlmlF+6M3+73LdEWpnaeG6.Y1IeJpyLyosX9rHVbXoSzlPRvwryPmdg+XUvdKifVM2BdfovirUDC4c3SFk786JK99Eq2TT5VTPeAKNGKWI20z3XFzkgyJgC3J0hPAcb6JkKE0H85eiEFaadJV5pFbyx1nlnoV96MrN+OeOJ97.bIXCZYhFA9hGs7xAVmCSW8Fz06pYHxkLeEGNOQNZ1ES.5VoIvNrUqcpNMnGjDmmYRQapHaQO2nGqzQ4SlPVmYbwkeRTwfi2P+P2t19gapU1bH.Y3dWCy8UVYppss69101RfAJE+NT7UEeiUvUnmueweC9e44JXS6yTZ9wRWy4KMdSC3pKEFdiqQCKmphi4o23xzMgj91DzUlOcLO0yVptfQ7K+W85D9n2uqSv2N6dEFseZ8wI7h2OPEGPWS.86qe4CNEC+i+5qN7wLMitOhBZHe3.TZAYN0dL+BgO2d6DqU+w7ry0pDCuSSvYdPMT6GnMq9wk2cAUq5HvstQ8xOnv4RmZ0qQWRz7xeX.HQc9Q+kZ1qOxVcST7JnT9QDDMLE+cFhW+RS9j5GoBxiY5UuCG51sJV.yDqbwIz2Ggeafdd0a+5C3hc59VuXm2WS7SqehP6Gcy13ctAaDyQ++vFKtNrOt9P76P70KMv6U+fe6s8tudGaucfuIGwvy+nZimkOcDlo843tKw5mLpL4NTcp88tkkMi3x.yKeG9TrXO58ZEK1qbQmoL+T0q8s8ezEt8CMTPaRZtPx0peD8NzywzSVMNOUDHdsu+pp5ZB1+1J3mcaEbvsUvstsB942VAu+sUvse2BRWO6Cy0po11FGmiNYnADqVsgR5ndS0py+CyHjtw
</code></pre>
<p dir="auto">This image shows the font set to "Default" which exposes the HISE bugs. The font size is ignored (point 2) and the width measurement is way off because it's measuring a different font size (bug 2).</p>
<p dir="auto"><img src="/assets/uploads/files/1787061872255-cleanshot-2026-08-18-at-15.04.21-2x.png" alt="CleanShot 2026-08-18 at 15.04.21@2x.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.hise.audio/topic/15007/centred-text-with-setfontwithspacing-drifts-left</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 17:13:44 GMT</lastBuildDate><atom:link href="https://forum.hise.audio/topic/15007.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Aug 2026 14:12:47 GMT</pubDate><ttl>60</ttl></channel></rss>