• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trying to set pop-up button list of fonts to attributed font names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to set pop-up button list of fonts to attributed font names


  • Subject: Trying to set pop-up button list of fonts to attributed font names
  • From: Brian Christmas <email@hidden>
  • Date: Thu, 02 Oct 2014 15:12:51 +1000

G'day scripters

I've got a pop-up list of system fonts a user can chose from, but it looks awful without the font names actually displaying as their actual fonts, so I thought I'd try and list them as Attributed text fonts.

At least one person on the net thinks it's possible, because I found this…

I would try to build an instance of NSMenuItem for each item. There is a setter -setAttributedTitle:, which lets you set attributed strings. Then you have to aggregate this to an instance of NSMenu and set the menu to the pop-up button.

Whilst I don't fully understand the blurb, i thought I'd try, but no success. 

Any advice please on if it's possible, and if so, where I'm going wrong.

TIA

Regards

Santa


my fontButton's removeAllItems()
#
tell application "Font Book"
set theFonts to the name of font families
end tell
set hitTheFont to 0
tell windowMain to display()
set p to 2
repeat with x from 1 to (count of theFonts)
-- here we tell the menu to create the item and add it
set eachFont to item x of theFonts as text
try
set p to 3
if eachFont as text is my theFontInUseReference as text then set hitTheFont to (x - 1) as integer
set p to 4
-- here we tell the menu to create the item and add it
tell current application's NSFont to set myFont to fontWithName_size_(eachFont as text, 16.0 as number)
set p to 5
tell current application's NSDictionary to set thisAttributedFont to dictionaryWithObject_forKey_(myFont, current application's NSFontAttributeName)
set p to 6
current application's NSLog("myFont = %@", myFont)
set p to 7
current application's NSLog("attributedFont = %@", thisAttributedFont)
tell current application's NSAttributedString to set eachAttributedFontString to alloc()'s initWithString_attributes_(eachFont as text, thisAttributedFont)
current application's NSLog("eachAttributedFont = %@", eachAttributedFontString)
set p to 8
#
# This method does not add any titles
#
my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_(setAttributedTitle_(eachAttributedFontString), "changeTheFont:", "")
#
# This method also does not add any titles
#
#my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_(eachAttributedFontString, "changeTheFont:", "")
on error errmsg number errnum
#
# errnum = -10000 is an empty myFont
#
if errnum ≠ -10000 then my thereHasBeenAnError("setUpMainMessagesView menu set-up loop", errmsg, errnum, 0, p)
end try
end repeat
tell windowMain to display()
my fontButton's selectItemAtIndex_(hitTheFont as integer)



The log...


2014-10-02 14:45:12.398 ApplescriptObjC Wizard[26934:303] myFont = "Monotypecom 16.00 pt. P [] (0x13c8f2f60) fobj=0x13dd139d0, spc=9.60"
2014-10-02 14:45:12.398 ApplescriptObjC Wizard[26934:303] attributedFont = {
    NSFont = "\"Monotypecom 16.00 pt. P [] (0x13c8f2f60) fobj=0x13dd139d0, spc=9.60\"";
}
2014-10-02 14:45:12.398 ApplescriptObjC Wizard[26934:303] eachAttributedFont = Monotype.com{
    NSFont = "\"Monotypecom 16.00 pt. P [] (0x13c8f2f60) fobj=0x13dd139d0, spc=9.60\"";
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Trying to set pop-up button list of fonts to attributed font names
      • From: Shane Stanley <email@hidden>
  • Next by Date: Re: Trying to set pop-up button list of fonts to attributed font names
  • Next by thread: Re: Trying to set pop-up button list of fonts to attributed font names
  • Index(es):
    • Date
    • Thread