Skip to main content
JADarnell
Inspiring
November 19, 2010
Question

All versions: UI Font size

  • November 19, 2010
  • 2 replies
  • 985 views

I need to change the size of a font used in a single StaticTextWidget on several dialogs.  Has anyone ever tried such a thing?

I see no example in the code snippets nor can I find any reference to changing fonts except that mentioned in IInterfaceFont.h.

R,

John

This topic has been closed for replies.

2 replies

JADarnell
JADarnellAuthor
Inspiring
November 19, 2010

Here is the solution that seems to work:

I added several lines looking like this to my project header:

DECLARE_PMID(kUIFontIDSpace, kMyFont11BoldID,     kShuksanPrefix + 100)  //In ShuksanID  the last predefined UI font is 14...

                                                                                                                            //I thought 100          would be safe.

Then, close to the start of my plugin, I added several lines like this:

   ISession *session = GetExecutionContextSession();

   InterfacePtr<IInterfaceFonts> interfacefonts(session, UseDefaultIID());

   PMLocaleId nLocale = LocaleSetting::GetLocale();  //kInterfaceFontBold
   interfacefonts -> SetFont(nLocale, kMyFontBold11ID,     PMString("MyFont"), 11, kInterfaceFontBold);

I tested this out by creating several InfoStaticTextWidgets using the newly created fontids and examining the text they output on a dialog.  In a couple of instances the bold font seemed bold, but smaller than the plain fonts with the same point size.  Optical illusion?  Who knows.

Please let me know if anyone has any questions about this.

R,

John

Inspiring
November 20, 2010

John,

please retry with your own plugin's prefix rather than kShuksanPrefix ...

And could the smaller (in what direction?) appearance of your font, comparing to plain text, be related to the use of a "condensed" variation?

Dirk

JADarnell
JADarnellAuthor
Inspiring
November 20, 2010

I will try with my own plugin prefix, but I was afraid of stepping on existing shuksanid defs, which is why I did it the way I did.

To be honest, the Font was Arial, and there are only three attributes one may use, plain, bold and italic. I made sure I used the plain or bold attributes. The PMString I used for font name was simply "Arial."

R,

John

Bartek_Kropaczewski
Inspiring
November 19, 2010

Hi John

The easiest way to achive that is creating your own version of StaticTextWidget

type YourInfoStaticTextWidget( kViewRsrcType ) : StaticTextWidget (ClassID = kInfoStaticTextWidgetBoss )

{

UIFontSpec;

};

then you can specify predefined font like kPaletteWindowSystemScriptFontId

Other way is to create View class for your widget

Regards

Bartek

JADarnell
JADarnellAuthor
Inspiring
November 19, 2010

Thanks Bartek. This otherwise excellent suggestion will not work.  I am required to use some very special fonts in order to keep within our company style guides.

Additionally, I looked up the definition for infostatictextwidget and it already has a UIFONTSPEC.  So I should be able to use it, right?

And finally, though your idea cannot work because of the exotic needs of the company, how about this:  IInterfaceFont has functionality for adding new fonts to its list. Would it be possible to use that?  The algorithm would look something like this:

Algorithm start

Do this as many times as I require special fonts and font sizes.

At plugin startup, make new entry into IInterfaceFont list for AWPCArial Bold Condensed, font size 24 and save the font element into a global list.

In the Initialize function of the dialog, find the InfoStaticTextWidget that requires the special font.

Assign the new uifontspec.

Algorithm end

Is there a function that will allow me to dynamically assign a new uifontspec when I initialize the dialog?

R,

John

Bartek_Kropaczewski
Inspiring
November 19, 2010

So other way that you can try is to create View for that widget.

Havn't try that by myself but you can take a look how this was solved in  SDK_DIR/source/open/includes/widgets/CStaticTextView.h.

You can control the process of drawing text and background on static text.

Good luck