TextNode::set_text_scale does not properly handle spaces

Bug #1013419 reported by SamL
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Panda3D
Fix Released
Undecided
rdb

Bug Description

http://www.panda3d.org/forums/viewtopic.php?t=13455

It appears that 1.8.0 and HEAD TextNode::set_text_scale does not properly handle spaces. They do not get scaled, so it appears that text is rendered without spaces.

The bug is in TextAssembler::assemble_row where the handling for spaces (and tabs) does not account for scaling.
"
    if (character == ' ') {
      // A space is a special case.
      xpos += font->get_space_advance();
"

should change to:
"
    if (character == ' ') {
      // A space is a special case.
      xpos += properties->get_glyph_scale() * properties->get_text_scale() * font->get_space_advance();
"

Can someone review and apply?

SamL (saml-launchpad)
security vulnerability: no → yes
security vulnerability: yes → no
SamL (saml-launchpad)
security vulnerability: no → yes
Revision history for this message
SamL (saml-launchpad) wrote :

Here's the actual patch, hopefully this can be included.

(sorry about security toggling, this launchpad is pretty touchy if you randomly click).

security vulnerability: yes → no
Revision history for this message
Josh Enes (joshenes) wrote :

I can confirm that this bug still exists and that the provided patch fixes the bug.

I used the following code to expose the bug, which is fixed after applying the patch.
Pressing space toggles scaling the text using two different methods, using setTextScale, and using setScale on the NodePath.
Without the patch, only the NodePath scale works properly.

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.text = TextNode('my text node')
        self.text_np = NodePath(self.text)
        self.text_np.reparentTo(render2d)
        self.text.setText('hello world')
        self.accept('space', self.swap_scales)
        self.text_np.setScale(0.1)
        self.text.setTextScale(1.0)

    def swap_scales(self):
        np_scale = self.text_np.getScale()
        text_scale = self.text.getTextScale()
        self.text_np.setScale(text_scale)
        self.text.setTextScale(np_scale[0])
        self.text.forceUpdate()

Game().run()

Changed in panda3d:
status: New → Confirmed
Revision history for this message
rdb (rdb) wrote :

Many thanks! I've committed the patch. Sorry for taking so long to get to it, I just wasn't convinced that this isn't the intended behaviour; but that case makes it reasonably clear.

Changed in panda3d:
assignee: nobody → rdb (rdb)
milestone: none → 1.8.1
status: Confirmed → Fix Committed
rdb (rdb)
Changed in panda3d:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.