Changing C File Comments font from Italics to Plain

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Changing C File Comments font from Italics to Plain

Postby shogunboy » Wed Apr 22, 2009 11:57 am

Hi,
I am a new user of rSyntaxTextArea :)

It has given me what ever I wanted. I am using this to preview the C Header files in my application where in I use
"text/c" syntax style for the formatting. But here I have a small problem. The comments in the file gets displayed in Italic Font. I just want it to be Plain Font. So what changes should I make??

I have no clue as to how to do it. Any help would be greatly appreciated.
Thanks in advance.

Cheers
Shogunboy
shogunboy
 
Posts: 3
Joined: Wed Apr 22, 2009 11:31 am

Re: Changing C File Comments font from Italics to Plain

Postby robert » Thu Apr 23, 2009 11:52 am

Yes, comments are by default italic, and keywords bold. Unfortunately the syntax styling API isn't as nice as I'd like it to be, but I hope to update that soon.

You can remove the italics (and bold, if you wish) by looping through all of the Styles in the text area's SyntaxScheme. Here is an example utility method that makes RSTA use a single font (no bold or italics) for all token types:

Code: Select all
public static void setFont(RSyntaxTextArea textArea, Font font) {
   if (font!=null) {
      SyntaxScheme ss = textArea.getSyntaxScheme();
      if (ss!=null) {
         ss = (SyntaxScheme)ss.clone();
         for (int i=0; i<ss.styles.length; i++) {
            if (ss.styles[i]!=null) {
               ss.styles[i].font = font;
            }
         }
         textArea.setSyntaxScheme(ss);
      }
      textArea.setFont(font);
   }
}


You could modify this method to change any font found to Font.PLAIN:

Code: Select all
if (ss.styles[i]!=null && ss.styles[i].font!=null) {
   ss.styles[i].font = ss.styles[i].font.deriveFont(Font.PLAIN);
}


Bringing this up has made me want to update this API sooner rather than later. :)
User avatar
robert
 
Posts: 802
Joined: Sat May 10, 2008 5:16 pm

Re: Changing C File Comments font from Italics to Plain

Postby shogunboy » Fri Apr 24, 2009 3:13 pm

Thanks for your prompt and fast reply Robert..
I was playing around with the source code, and had changed the code in SyntaxScheme to make it Plain for
the comments. It had worked for me. ;)

Once again thanks for the reply.
Cheers
Shogunboy
shogunboy
 
Posts: 3
Joined: Wed Apr 22, 2009 11:31 am


Return to Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron