Restricted FontPanel

  • I want (on OS X 10.8.3) to show a font panel, which only has nice fonts (e.g. only fonts which are able to show "门").

    There is a delegate method of NSFontManager:
    - (BOOL)fontManager:(id)theFontManager willIncludeFont:(NSString *)fontName
    Requests permission from the Font panel delegate to display the given font name in the Font panel.

    Looks exactly the thing I need.

    But then the documentation ends with:
    Important:  This delegate method is not called in OS X versions 10.3 and later.

    So: how to display a restricted Font Panel in 10.8?

    Gerriet.

    P.S.
    NSFontPanel has this method:
    reloadDefaultFontFamilies
    "Triggers a reload to the default state, so that the delegate is called."

    But there is no delegate for a FontPanel. There is a NSWindow delegate, but this does not help much.

    Somehow either I or the documentation is a bit confused.
  • From

    https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/
    CocoaTextArchitecture/FontHandling/FontHandling.html#//apple_ref/doc/uid/TP
    40009459-CH5-SW1

    > Normally, an application’s Font panel displays all the standard fonts available on the system. If this isn’t appropriate for your application—for example, if only fixed-pitch fonts should be used—you can assign a delegate to the NSFontPanelobject to filter the available fonts. Before the NSFontPanel object adds a particular font family or face to its list, theNSFontPanel object asks its delegate to confirm the addition by sending the delegate afontManager:willIncludeFont:message. If the delegate returns TRUE (or doesn’t implement this method), the font is added. If the delegate returns FALSE, the font isn’t added. This method must be invoked before the loading of the main nib file.

    Sent from my iPhone

    On 2013/05/26, at 20:48, "Gerriet M. Denkmann" <gerriet...> wrote:

    > I want (on OS X 10.8.3) to show a font panel, which only has nice fonts (e.g. only fonts which are able to show "门").
    >
    > There is a delegate method of NSFontManager:
    > - (BOOL)fontManager:(id)theFontManager willIncludeFont:(NSString *)fontName
    > Requests permission from the Font panel delegate to display the given font name in the Font panel.
    >
    > Looks exactly the thing I need.
    >
    > But then the documentation ends with:
    > Important:  This delegate method is not called in OS X versions 10.3 and later.
    >
    > So: how to display a restricted Font Panel in 10.8?
    >
    > Gerriet.
    >
    >
    > P.S.
    > NSFontPanel has this method:
    > reloadDefaultFontFamilies
    > "Triggers a reload to the default state, so that the delegate is called."
    >
    > But there is no delegate for a FontPanel. There is a NSWindow delegate, but this does not help much.
    >
    > Somehow either I or the documentation is a bit confused.
    >
    >
    > _______________________________________________
    >
    >
  • On 27 May 2013, at 07:10, <dangerwillrobinsondanger...> wrote:

    > From
    >
    > https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/
    CocoaTextArchitecture/FontHandling/FontHandling.html#//apple_ref/doc/uid/TP
    40009459-CH5-SW1

    >> Normally, an application’s Font panel displays all the standard fonts available on the system. If this isn’t appropriate for your application—for example, if only fixed-pitch fonts should be used—you can assign a delegate to the NSFontPanelobject to filter the available fonts. Before the NSFontPanel object adds a particular font family or face to its list, theNSFontPanel object asks its delegate to confirm the addition by sending the delegate afontManager:willIncludeFont:message.

    The documentation says:
    "Important:  This delegate method is not called in OS X versions 10.3 and later."

    >> If the delegate returns TRUE (or doesn’t implement this method), the font is added. If the delegate returns FALSE, the font isn’t added. This method must be invoked before the loading of the main nib file.
    >
    > Sent from my iPhone
    >
    > On 2013/05/26, at 20:48, "Gerriet M. Denkmann" <gerriet...> wrote:
    >
    >> I want (on OS X 10.8.3) to show a font panel, which only has nice fonts (e.g. only fonts which are able to show "门").
    >>
    >> There is a delegate method of NSFontManager:
    >> - (BOOL)fontManager:(id)theFontManager willIncludeFont:(NSString *)fontName
    >> Requests permission from the Font panel delegate to display the given font name in the Font panel.
    >>
    >> Looks exactly the thing I need.
    >>
    >> But then the documentation ends with:
    >> Important:  This delegate method is not called in OS X versions 10.3 and later.
    >>
    >> So: how to display a restricted Font Panel in 10.8?
    >>
    >> Gerriet.
    >>
    >>
    >> P.S.
    >> NSFontPanel has this method:
    >> reloadDefaultFontFamilies
    >> "Triggers a reload to the default state, so that the delegate is called."
    >>
    >> But there is no delegate for a FontPanel. There is a NSWindow delegate, but this does not help much.
    >>
    >> Somehow either I or the documentation is a bit confused.
  • Ah. Missed it.

    Sent from my iPhone

    On 2013/05/27, at 9:41, "Gerriet M. Denkmann" <gerriet...> wrote:

    >
    > On 27 May 2013, at 07:10, <dangerwillrobinsondanger...> wrote:
    >
    >> From
    >>
    >> https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/
    CocoaTextArchitecture/FontHandling/FontHandling.html#//apple_ref/doc/uid/TP
    40009459-CH5-SW1

    >>> Normally, an application’s Font panel displays all the standard fonts available on the system. If this isn’t appropriate for your application—for example, if only fixed-pitch fonts should be used—you can assign a delegate to the NSFontPanelobject to filter the available fonts. Before the NSFontPanel object adds a particular font family or face to its list, theNSFontPanel object asks its delegate to confirm the addition by sending the delegate afontManager:willIncludeFont:message.
    >
    > The documentation says:
    > "Important:  This delegate method is not called in OS X versions 10.3 and later."
    >
    >
    >>> If the delegate returns TRUE (or doesn’t implement this method), the font is added. If the delegate returns FALSE, the font isn’t added. This method must be invoked before the loading of the main nib file.
    >>
    >> Sent from my iPhone
    >>
    >> On 2013/05/26, at 20:48, "Gerriet M. Denkmann" <gerriet...> wrote:
    >>
    >>> I want (on OS X 10.8.3) to show a font panel, which only has nice fonts (e.g. only fonts which are able to show "门").
    >>>
    >>> There is a delegate method of NSFontManager:
    >>> - (BOOL)fontManager:(id)theFontManager willIncludeFont:(NSString *)fontName
    >>> Requests permission from the Font panel delegate to display the given font name in the Font panel.
    >>>
    >>> Looks exactly the thing I need.
    >>>
    >>> But then the documentation ends with:
    >>> Important:  This delegate method is not called in OS X versions 10.3 and later.
    >>>
    >>> So: how to display a restricted Font Panel in 10.8?
    >>>
    >>> Gerriet.
    >>>
    >>>
    >>> P.S.
    >>> NSFontPanel has this method:
    >>> reloadDefaultFontFamilies
    >>> "Triggers a reload to the default state, so that the delegate is called."
    >>>
    >>> But there is no delegate for a FontPanel. There is a NSWindow delegate, but this does not help much.
    >>>
    >>> Somehow either I or the documentation is a bit confused.
    >
    >
    > _______________________________________________
    >
    >
  • On May 26, 2013, at 5:41 PM, "Gerriet M. Denkmann" <gerriet...> wrote:

    >
    > The documentation says:
    > "Important:  This delegate method is not called in OS X versions 10.3 and later."

    Have you confirmed the documentation is correct?

    If it is, does NSFontManager.h contain any useful comments?

    --Kyle Sluder
  • Yep.
    Tested it even.

    Seems step one is subclassing NSFontManager, setting your subclass as the factory ( in main.c no less to get it in early enough to take effect.)
    Easy enough to override what you need and add a flag to use NSFontManager implementation where needed.

    Beyond that, possibly subclassing NSFontPanel seems necessary as well, but fruitless without accessing private ivars (which are oddly documented in the header)
    Seems this kind of use case is just not well accommodated enough to justify the effort over implementing your own complete font panel or at least a font picker.

    I hope I am wrong and missed something, but that's my assessment.
    That said, a custom original font panel should not be hard, just a fair amount of work.
    And who knows where the hooks are to things like the little gear menu and its items.

    I suppose an accessory view could do it, but by the time you got that shoehorned in, you could do your own panel.

    Sent from my iPhone

    On 2013/05/27, at 14:18, Kyle Sluder <kyle...> wrote:

    > On May 26, 2013, at 5:41 PM, "Gerriet M. Denkmann" <gerriet...> wrote:
    >
    >>
    >> The documentation says:
    >> "Important:  This delegate method is not called in OS X versions 10.3 and later."
    >
    > Have you confirmed the documentation is correct?
    >
    > If it is, does NSFontManager.h contain any useful comments?
    >
    > --Kyle Sluder
  • On May 26, 2013, at 10:41 PM, <dangerwillrobinsondanger...> wrote:

    > Beyond that, possibly subclassing NSFontPanel seems necessary as well, but fruitless without accessing private ivars (which are oddly documented in the header)

    Don’t quote me on this, but I remember hearing that the font panel is nowadays implemented as a separate process (similarly to the Special Characters panel.) This would be a fairly sensible way to save system resources since there’s only one instance of it, instead of one per app. It would also explain why the delegate method no longer works, as it would have taken extra effort to plumb that filter method through IPC.

    —Jens
  • On 26.05.2013, at 13:48, Gerriet M. Denkmann <gerriet...> wrote:
    > I want (on OS X 10.8.3) to show a font panel, which only has nice fonts (e.g. only fonts which are able to show "门").

    Have you tried whether you can just create a classic font menu for this purpose? Leave the font panel alone, and just have a menu dedicated to only showing 'nice fonts' ? Those will then be faster to access, and you don't have to do so much work.

    Of course, it gets a little unmanageable if you have a case where all (or most of) the fonts are considered 'nice' by whatever algorithm you plan to apply.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
  • On 27 May 2013, at 17:26, Uli Kusterer <witness.of.teachtext...> wrote:

    > On 26.05.2013, at 13:48, Gerriet M. Denkmann <gerriet...> wrote:
    >> I want (on OS X 10.8.3) to show a font panel, which only has nice fonts (e.g. only fonts which are able to show "门").
    >
    > Have you tried whether you can just create a classic font menu for this purpose? Leave the font panel alone, and just have a menu dedicated to only showing 'nice fonts' ? Those will then be faster to access, and you don't have to do so much work.

    I made a Panel with a TableView which displays eligible font names.
    The use is: in Preferences the user can choose some suitable default fonts (depending on some choices, as "Serif" vs. "SansSerif", etc.).

    As the list of eligible fonts changes according to these parameters, I think a TableView is a better fit than a menu.
    >
    > Of course, it gets a little unmanageable if you have a case where all (or most of) the fonts are considered 'nice' by whatever algorithm you plan to apply.

    No problem. There are no more than a dozen.

    Kind regards,

    Gerriet.
previous month may 2013 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