NSFontManager addFontTrait: not working as expected

  • Hello list,

    I have an instance of WebView instantiated in interface builder.

    I have a button in the same window which should turn the bold font trait
    off,

    just like the default menu item does.

    The menu item is the default from the IB text menu pane, and works as it
    should. It has a tag which is set to: 2.

    It sends a message to the font manager which is the action/method
    addFontTrait:,

    it sends itself as an argument and the font manager looks at the tag

    of the sender and bold is toggled as it should.

    Now I want the same with a button I have in the same window as the webview.

    I have code like the following, which should only turn it off:

    (PS: This is RubyCocoa, if needed I will supply the objc equivalent)

    def turnBoldOff

      OSX::NSFontManager.sharedFontManager.addFontTrait(self)

    end

    def tag

      # also tried: OSX::NSUnboldFontMask

      2

    end

    Afaik, this should do the same as the menu item. But unfortunately it

    doesn't work.

    The font doesn't change and the menu item doesn't update, which is

    obvious because the font hasn't really been updated....

    Any clues or pointers to documents on how to do this?
  • *bump*

    Sorry for the repeat post, but I'm still stuck with this. If necessary I can
    attach an example. Thanks,
    Ben

    On 10/18/07, Benjamin Jackson <bhjackson...> wrote:
    >
    > Hello list,
    >
    >
    > I have an instance of WebView instantiated in interface builder.
    >
    > I have a button in the same window which should turn the bold font trait
    > off,
    >
    > just like the default menu item does.
    >
    >
    > The menu item is the default from the IB text menu pane, and works as it
    > should. It has a tag which is set to: 2.
    >
    > It sends a message to the font manager which is the action/method
    > addFontTrait:,
    >
    > it sends itself as an argument and the font manager looks at the tag
    >
    > of the sender and bold is toggled as it should.
    >
    >
    > Now I want the same with a button I have in the same window as the
    > webview.
    >
    > I have code like the following, which should only turn it off:
    >
    > (PS: This is RubyCocoa, if needed I will supply the objc equivalent)
    >
    >
    > def turnBoldOff
    >
    > OSX::NSFontManager.sharedFontManager.addFontTrait(self)
    >
    > end
    >
    >
    > def tag
    >
    > # also tried: OSX::NSUnboldFontMask
    >
    > 2
    >
    > end
    >
    >
    > Afaik, this should do the same as the menu item. But unfortunately it
    >
    > doesn't work.
    >
    > The font doesn't change and the menu item doesn't update, which is
    >
    > obvious because the font hasn't really been updated....
    >
    >
    > Any clues or pointers to documents on how to do this?
    >
  • Hello Benjamin,

    I don't know whether your question depends on Tiger or Leopard, but
    using only addFontTrait: works fine on Tiger.

    It seems that on Leopard you have to use addFontTrait: and
    removeFontTrait: instead, depending on whether you want to add or
    remove a trait like bold or italic.

    Regards,

        Daniel

    On 06.11.2007, at 03:42, Benjamin Jackson wrote:

    > *bump*
    >
    > Sorry for the repeat post, but I'm still stuck with this. If
    > necessary I can
    > attach an example. Thanks,
    > Ben
    >
    > On 10/18/07, Benjamin Jackson <bhjackson...> wrote:
    >>
    >> Hello list,
    >>
    >>
    >> I have an instance of WebView instantiated in interface builder.
    >>
    >> I have a button in the same window which should turn the bold font
    >> trait
    >> off,
    >>
    >> just like the default menu item does.
    >>
    >>
    >> The menu item is the default from the IB text menu pane, and works
    >> as it
    >> should. It has a tag which is set to: 2.
    >>
    >> It sends a message to the font manager which is the action/method
    >> addFontTrait:,
    >>
    >> it sends itself as an argument and the font manager looks at the tag
    >>
    >> of the sender and bold is toggled as it should.
    >>
    >>
    >> Now I want the same with a button I have in the same window as the
    >> webview.
    >>
    >> I have code like the following, which should only turn it off:
    >>
    >> (PS: This is RubyCocoa, if needed I will supply the objc equivalent)
    >>
    >>
    >> def turnBoldOff
    >>
    >> OSX::NSFontManager.sharedFontManager.addFontTrait(self)
    >>
    >> end
    >>
    >>
    >> def tag
    >>
    >> # also tried: OSX::NSUnboldFontMask
    >>
    >> 2
    >>
    >> end
    >>
    >>
    >> Afaik, this should do the same as the menu item. But unfortunately it
    >>
    >> doesn't work.
    >>
    >> The font doesn't change and the menu item doesn't update, which is
    >>
    >> obvious because the font hasn't really been updated....
    >>
    >>
    >> Any clues or pointers to documents on how to do this?
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today