Bug in LineNumbers font handling

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Bug in LineNumbers font handling

Postby hubersn » Sat Aug 01, 2009 1:28 am

Hi,

during further experiments with RSyntaxTextArea, I encountered a bug (which, fortunately, has a trivial workaround): when trying to set a different font for the LineNumber display using

Code: Select all
textScrollPane.getGutter().setLineNumberFont(font)


it turns out that this has no immediate effect. Only when calling

Code: Select all
textScrollPane.setLineNumbersEnabled(false);
textScrollPane.setLineNumbersEnabled(true);


afterwards, the display is properly refreshed.

I am currently using the 1.3.4 release version.

Hope this helps,
hubersn
hubersn
 
Posts: 10
Joined: Fri Jul 31, 2009 11:45 pm

Re: Bug in LineNumbers font handling

Postby robert » Tue Aug 04, 2009 4:28 pm

Thanks. I've added a tracker here:

http://sourceforge.net/tracker/?func=de ... id=1101466

Should be quick and easy to fix, but a "real" release is still a little ways away, so you'll have to go into SVN to grab it.
User avatar
robert
 
Posts: 801
Joined: Sat May 10, 2008 5:16 pm

Re: Bug in LineNumbers font handling

Postby robert » Tue Aug 04, 2009 8:59 pm

This seems to work for me, at least with the latest, but I don't think this code has changed between 1.3.4 and now. Can you provide a sample program that shows the issue?
User avatar
robert
 
Posts: 801
Joined: Sat May 10, 2008 5:16 pm

Re: Bug in LineNumbers font handling

Postby hubersn » Wed Aug 05, 2009 10:22 pm

robert wrote:This seems to work for me, at least with the latest, but I don't think this code has changed between 1.3.4 and now. Can you provide a sample program that shows the issue?


Hm. I just tried it in a minimal example, and you are correct - it works there. However, it does not work integrated in my main application (which I took over from someone else and which is a complete mess, btw.). I will have to investigate further to provide a minimal example. Hopefully, "minimal" won't be "the full app"...

Stay tuned.

hubersn
hubersn
 
Posts: 10
Joined: Fri Jul 31, 2009 11:45 pm

Re: Bug in LineNumbers font handling

Postby hubersn » Thu Aug 06, 2009 11:37 pm

OK, I have now uncovered a slightly different bug (at least it is different than the one I described earlier, but maybe I misremember).

Add the following to the DemoRootPane:

In createMenuBar() a few menu items to play with:

Code: Select all
    menu = new JMenu("Fontsize");
    menu.add(new JMenuItem(new FontSizeAction(10)));
    menu.add(new JMenuItem(new FontSizeAction(12)));
    menu.add(new JMenuItem(new FontSizeAction(14)));
    menu.add(new JMenuItem(new FontSizeAction(16)));
    menu.add(new JMenuItem(new FontSizeAction(18)));
    menu.add(new JMenuItem(new FontSizeAction(20)));
    mb.add(menu);


A new method called setEditorFont:
Code: Select all
  public void setEditorFont(Font font) {
    this.textArea.setFont(font);
    SyntaxScheme myScheme = this.textArea.getSyntaxScheme();
    Style[] styles = myScheme.styles;
    for (int i = 0; i < styles.length; i++) {
      if (styles[i] != null) {
        styles[i].font = font;
      }
    }
    this.textArea.setSyntaxScheme(myScheme);
   
    this.scrollPane.getGutter().setLineNumberFont(font);
   
    //this.scrollPane.setLineNumbersEnabled(false);
    //this.scrollPane.setLineNumbersEnabled(true);
  }


And not to forget the new FontSizeAction:

Code: Select all
  private class FontSizeAction extends AbstractAction {
    private int fontSize;
    public FontSizeAction(int fontSize) {
      this.fontSize = fontSize;
      putValue(NAME, "Change Fontsize to "+fontSize+"pt");
    }
    public void actionPerformed(ActionEvent e) {
      setEditorFont(new Font("monospaced", Font.PLAIN, this.fontSize));
    }
  }


Now first select e.g. 20pt and then 10pt. The Line Number font changes, but the alignment of the border with the editor content is broken. Comment in the two LineNumbersEnabled calls and see it working fine.

If you comment out the
Code: Select all
this.textArea.setFont(font);
call, it behaves in an interestingly different way.

If the syntax scheme is not manipulated, everything (apart from the explicitly set font styles in the current scheme) seems to work.

Maybe I am just confused on how to correctly change the fontsize in RSyntaxTextArea?

Have fun,
hubersn
hubersn
 
Posts: 10
Joined: Fri Jul 31, 2009 11:45 pm

Re: Bug in LineNumbers font handling

Postby robert » Mon Aug 10, 2009 2:35 am

Yep, it's a bug in the line number component, thanks for finding it! Should be fixed in revision 118 in SVN. Try it out and see if it works for you.
User avatar
robert
 
Posts: 801
Joined: Sat May 10, 2008 5:16 pm

Re: Bug in LineNumbers font handling

Postby hubersn » Wed Aug 19, 2009 3:40 pm

Hi Robert,

I just tried your fix with the latest revision from SVN, and everything works fine. Thanks for the quick fix!

hubersn
hubersn
 
Posts: 10
Joined: Fri Jul 31, 2009 11:45 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron