如何获取可用 NSFont 系列的列表?

发布于 2024-09-04 06:28:58 字数 46 浏览 6 评论 0原文

如何获取可用 NSFont 系列的列表,最好使用 fontName: 等效项。

How can I get a list of the available NSFont families, preferably with the fontName: equivalents.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

一生独一 2024-09-11 06:28:58
NSLog(@"%@",[[[NSFontManager sharedFontManager] availableFontFamilies] description]);

给出:

"Abadi MT Condensed Extra Bold",
"Abadi MT Condensed Light",
"Academy Engraved LET",
"Al Bayan",
"American Typewriter",
"Andale Mono",
Arial,
"Arial Black",
"Arial Hebrew",
"Arial Narrow",
"Arial Rounded MT Bold",
"Arial Unicode MS",
Ayuthaya,
Baghdad,
"Bank Gothic",
Baskerville,
"Baskerville Old Face",
Batang,
"Bauhaus 93",
"Bell MT",
"Bernard MT Condensed",
BiauKai,
"Big Caslon",
"Birch Std",
"Blackmoor LET",
"Blackoak Std",
"BlairMdITC TT",
"Bodoni Ornaments ITC TT",
"Bodoni SvtyTwo ITC TT",
"Bodoni SvtyTwo OS ITC TT",
"Bodoni SvtyTwo SC ITC TT",
"Book Antiqua",
"Bookman Old Style",
"Bookshelf Symbol 7",
"Bordeaux Roman Bold LET",
"Bradley Hand ITC TT",
Braggadocio,
"Britannic Bold",
"Brush Script MT",
"Brush Script Std",
Calibri,
"Calisto MT",
Cambria,
Candara,
Capitals,
Casual,
Century,
"Century Gothic",
"Century Schoolbook",
Chalkboard,
Chalkduster,
"Chaparral Pro",
"Charcoal CY",
"Charlemagne Std",
Cochin,
"Colonna MT",
"Comic Sans MS",
Consolas,
Constantia,
"Cooper Black",
"Cooper Std",
Copperplate,
"Copperplate Gothic Bold",
"Copperplate Gothic Light",
Corbel,
"Corsiva Hebrew",
Courier,
"Courier New",
Cracked,
"Curlz MT",
"DecoType Naskh",
Desdemona,
"Devanagari MT",
Didot,
"Edwardian Script ITC",
"Engravers MT",
"Euphemia UCAS",
Eurostile,
"Footlight MT Light",
"Franklin Gothic Book",
"Franklin Gothic Medium",
Futura,
Garamond,
"GB18030 Bitmap",
"Geeza Pro",
Geneva,
"Geneva CY",
Georgia,
"Giddyup Std",
"Gill Sans",
"Gill Sans MT",
"Gill Sans Ultra Bold",
"Gloucester MT Extra Condensed",
"Goudy Old Style",
"Gujarati MT",
Gulim,
GungSeo,
"Gurmukhi MT",
Haettenschweiler,
"Handwriting - Dakota",
Harrington,
HeadLineA,
Hei,
"Heiti SC",
"Heiti TC",
Helvetica,
"Helvetica CY",
"Helvetica Neue",
Herculanum,
"Hiragino Kaku Gothic Pro",
"Hiragino Kaku Gothic ProN",
"Hiragino Kaku Gothic Std",
"Hiragino Kaku Gothic StdN",
"Hiragino Maru Gothic Pro",
"Hiragino Maru Gothic ProN",
"Hiragino Mincho Pro",
"Hiragino Mincho ProN",
"Hiragino Sans GB",
"Hobo Std",
"Hoefler Text",
Impact,
"Imprint MT Shadow",
InaiMathi,
"Jazz LET",
Kai,
Kailasa,
"Kino MT",
Kokonor,
"Kozuka Gothic Pr6N",
"Kozuka Gothic Pro",
"Kozuka Mincho Pr6N",
"Kozuka Mincho Pro",
Krungthep,
KufiStandardGK,
"Letter Gothic Std",
"LiHei Pro",
"LiSong Pro",
"Lithos Pro",
"Lucida Blackletter",
"Lucida Bright",
"Lucida Calligraphy",
"Lucida Console",
"Lucida Fax",
"Lucida Grande",
"Lucida Handwriting",
"Lucida Sans",
"Lucida Sans Typewriter",
"Lucida Sans Unicode",
"Marker Felt",
Marlett,
"Matura MT Script Capitals",
Meiryo,
Menlo,
"Mesquite Std",
"Microsoft Sans Serif",
"Minion Pro",
Mistral,
"Modern No. 20",
"Mona Lisa Solid ITC TT",
Monaco,
"MS Gothic",
"MS Mincho",
"MS PGothic",
"MS PMincho",
"MS Reference Sans Serif",
"MS Reference Specialty",
Mshtakan,
"MT Extra",
"Myriad Pro",
Nadeem,
"New Peninim MT",
"News Gothic MT",
"Nueva Std",
"OCR A Std",
Onyx,
Optima,
"Orator Std",
Osaka,
Palatino,
Papyrus,
"Party LET",
PCMyungjo,
Perpetua,
"Perpetua Titling MT",
PilGi,
"Plantagenet Cherokee",
Playbill,
PMingLiU,
"Poplar Std",
"PortagoITC TT",
"Prestige Elite Std",
"Princetown LET",
Raanana,
Rockwell,
"Rockwell Extra Bold",
"Rosewood Std",
"Santa Fe LET",
Sathu,
"Savoye LET",
"SchoolHouse Cursive B",
"SchoolHouse Printed A",
Silom,
SimSun,
Skia,
"Snell Roundhand",
Stencil,
"Stencil Std",
STFangsong,
STHeiti,
STKaiti,
"Stone Sans ITC TT",
"Stone Sans Sem ITC TT",
STSong,
Symbol,
"Synchro LET",
Tahoma,
"Tekton Pro",
Thonburi,
Times,
"Times New Roman",
"Trajan Pro",
"Trebuchet MS",
"Tw Cen MT",
"Type Embellishments One LET",
Verdana,
Webdings,
"Wide Latin",
Wingdings,
"Wingdings 2",
"Wingdings 3",
"Zapf Dingbats",
Zapfino,
"Adobe Arabic",
"Adobe Caslon Pro",
"Adobe Fan Heiti Std",
"Adobe Fangsong Std",
"Adobe Garamond Pro",
"Adobe Gothic Std",
"Adobe Hebrew",
"Adobe Heiti Std",
"Adobe Kaiti Std",
"Adobe Ming Std",
"Adobe Myungjo Std",
"Adobe Song Std",
"Apple Braille",
"Apple Chancery",
"Apple Garamond BT",
"Apple LiGothic",
"Apple LiSung",
"Apple Symbols",
AppleGothic,
AppleMyungjo,
"Monotype Corsiva",
"Monotype Sorts"

在 10.6.4 中

NSLog(@"%@",[[[NSFontManager sharedFontManager] availableFontFamilies] description]);

Gives:

"Abadi MT Condensed Extra Bold",
"Abadi MT Condensed Light",
"Academy Engraved LET",
"Al Bayan",
"American Typewriter",
"Andale Mono",
Arial,
"Arial Black",
"Arial Hebrew",
"Arial Narrow",
"Arial Rounded MT Bold",
"Arial Unicode MS",
Ayuthaya,
Baghdad,
"Bank Gothic",
Baskerville,
"Baskerville Old Face",
Batang,
"Bauhaus 93",
"Bell MT",
"Bernard MT Condensed",
BiauKai,
"Big Caslon",
"Birch Std",
"Blackmoor LET",
"Blackoak Std",
"BlairMdITC TT",
"Bodoni Ornaments ITC TT",
"Bodoni SvtyTwo ITC TT",
"Bodoni SvtyTwo OS ITC TT",
"Bodoni SvtyTwo SC ITC TT",
"Book Antiqua",
"Bookman Old Style",
"Bookshelf Symbol 7",
"Bordeaux Roman Bold LET",
"Bradley Hand ITC TT",
Braggadocio,
"Britannic Bold",
"Brush Script MT",
"Brush Script Std",
Calibri,
"Calisto MT",
Cambria,
Candara,
Capitals,
Casual,
Century,
"Century Gothic",
"Century Schoolbook",
Chalkboard,
Chalkduster,
"Chaparral Pro",
"Charcoal CY",
"Charlemagne Std",
Cochin,
"Colonna MT",
"Comic Sans MS",
Consolas,
Constantia,
"Cooper Black",
"Cooper Std",
Copperplate,
"Copperplate Gothic Bold",
"Copperplate Gothic Light",
Corbel,
"Corsiva Hebrew",
Courier,
"Courier New",
Cracked,
"Curlz MT",
"DecoType Naskh",
Desdemona,
"Devanagari MT",
Didot,
"Edwardian Script ITC",
"Engravers MT",
"Euphemia UCAS",
Eurostile,
"Footlight MT Light",
"Franklin Gothic Book",
"Franklin Gothic Medium",
Futura,
Garamond,
"GB18030 Bitmap",
"Geeza Pro",
Geneva,
"Geneva CY",
Georgia,
"Giddyup Std",
"Gill Sans",
"Gill Sans MT",
"Gill Sans Ultra Bold",
"Gloucester MT Extra Condensed",
"Goudy Old Style",
"Gujarati MT",
Gulim,
GungSeo,
"Gurmukhi MT",
Haettenschweiler,
"Handwriting - Dakota",
Harrington,
HeadLineA,
Hei,
"Heiti SC",
"Heiti TC",
Helvetica,
"Helvetica CY",
"Helvetica Neue",
Herculanum,
"Hiragino Kaku Gothic Pro",
"Hiragino Kaku Gothic ProN",
"Hiragino Kaku Gothic Std",
"Hiragino Kaku Gothic StdN",
"Hiragino Maru Gothic Pro",
"Hiragino Maru Gothic ProN",
"Hiragino Mincho Pro",
"Hiragino Mincho ProN",
"Hiragino Sans GB",
"Hobo Std",
"Hoefler Text",
Impact,
"Imprint MT Shadow",
InaiMathi,
"Jazz LET",
Kai,
Kailasa,
"Kino MT",
Kokonor,
"Kozuka Gothic Pr6N",
"Kozuka Gothic Pro",
"Kozuka Mincho Pr6N",
"Kozuka Mincho Pro",
Krungthep,
KufiStandardGK,
"Letter Gothic Std",
"LiHei Pro",
"LiSong Pro",
"Lithos Pro",
"Lucida Blackletter",
"Lucida Bright",
"Lucida Calligraphy",
"Lucida Console",
"Lucida Fax",
"Lucida Grande",
"Lucida Handwriting",
"Lucida Sans",
"Lucida Sans Typewriter",
"Lucida Sans Unicode",
"Marker Felt",
Marlett,
"Matura MT Script Capitals",
Meiryo,
Menlo,
"Mesquite Std",
"Microsoft Sans Serif",
"Minion Pro",
Mistral,
"Modern No. 20",
"Mona Lisa Solid ITC TT",
Monaco,
"MS Gothic",
"MS Mincho",
"MS PGothic",
"MS PMincho",
"MS Reference Sans Serif",
"MS Reference Specialty",
Mshtakan,
"MT Extra",
"Myriad Pro",
Nadeem,
"New Peninim MT",
"News Gothic MT",
"Nueva Std",
"OCR A Std",
Onyx,
Optima,
"Orator Std",
Osaka,
Palatino,
Papyrus,
"Party LET",
PCMyungjo,
Perpetua,
"Perpetua Titling MT",
PilGi,
"Plantagenet Cherokee",
Playbill,
PMingLiU,
"Poplar Std",
"PortagoITC TT",
"Prestige Elite Std",
"Princetown LET",
Raanana,
Rockwell,
"Rockwell Extra Bold",
"Rosewood Std",
"Santa Fe LET",
Sathu,
"Savoye LET",
"SchoolHouse Cursive B",
"SchoolHouse Printed A",
Silom,
SimSun,
Skia,
"Snell Roundhand",
Stencil,
"Stencil Std",
STFangsong,
STHeiti,
STKaiti,
"Stone Sans ITC TT",
"Stone Sans Sem ITC TT",
STSong,
Symbol,
"Synchro LET",
Tahoma,
"Tekton Pro",
Thonburi,
Times,
"Times New Roman",
"Trajan Pro",
"Trebuchet MS",
"Tw Cen MT",
"Type Embellishments One LET",
Verdana,
Webdings,
"Wide Latin",
Wingdings,
"Wingdings 2",
"Wingdings 3",
"Zapf Dingbats",
Zapfino,
"Adobe Arabic",
"Adobe Caslon Pro",
"Adobe Fan Heiti Std",
"Adobe Fangsong Std",
"Adobe Garamond Pro",
"Adobe Gothic Std",
"Adobe Hebrew",
"Adobe Heiti Std",
"Adobe Kaiti Std",
"Adobe Ming Std",
"Adobe Myungjo Std",
"Adobe Song Std",
"Apple Braille",
"Apple Chancery",
"Apple Garamond BT",
"Apple LiGothic",
"Apple LiSung",
"Apple Symbols",
AppleGothic,
AppleMyungjo,
"Monotype Corsiva",
"Monotype Sorts"

in 10.6.4

末骤雨初歇 2024-09-11 06:28:58

斯威夫特5

for family in NSFontManager.shared.availableFontFamilies {
    print(family)
}

Swift 5

for family in NSFontManager.shared.availableFontFamilies {
    print(family)
}
怎会甘心 2024-09-11 06:28:58
[[NSFontManager sharedFontManager] availableFontFamilies]

(之前,我编写了 -[NSFontManager availableFontFamilies],这是编写方法名称的常规方式,但如果解释为示例代码可能会造成混淆。)

[[NSFontManager sharedFontManager] availableFontFamilies]

(previously, I had written -[NSFontManager availableFontFamilies], which is a conventional way of writing a method name, but could be confusing if interpreted as sample code.)

感受沵的脚步 2024-09-11 06:28:58

以下是 Swift 的实现方法:

let fontFamilyNames = NSFontManager.sharedFontManager().availableFontFamilies

print("avaialble fonts is \(fontFamilyNames)")

Here's how it can be done for Swift:

let fontFamilyNames = NSFontManager.sharedFontManager().availableFontFamilies

print("avaialble fonts is \(fontFamilyNames)")
许久 2024-09-11 06:28:58

检查 Apple 的文档,例如:http://support.apple.com/kb/HT5379

-[NSFontManager availableFontFamilies] 可能会显示不属于您所定位的 OS X 版本的字体(我认为这是因为它们是与其他应用程序一起加载的,例如 Adob​​e Illustrator)。

Check Apple's documentation, for instance: http://support.apple.com/kb/HT5379.

-[NSFontManager availableFontFamilies] may reveal fonts that are not a part of the version of OS X you are targeting (I think this is beacause they were loaded with other applications, for example Adobe Illustrator).

欢你一世 2024-09-11 06:28:58
#import <Cocoa/Cocoa.h>

@interface FontController : NSObject {
    IBOutlet NSTextField *text;
}
- (IBAction)takeFontFamilyFrom: (id)sender;
- (IBAction)takeFontSizeFrom: (id)sender;
- (IBAction)takeFontAttributeFrom: (id)sender;
@end

#import "FontController.h"

NSFontManager *fm;

@implementation FontController
+ (void)initialize
{
    fm = [NSFontManager sharedFontManager];
}
- (IBAction)takeFontFamilyFrom: (id)sender
{
    NSFont *font = [text font];
    font = [fm convertFont: font
                  toFamily: [sender stringValue]];
    [text setFont: font];
}
- (IBAction)takeFontSizeFrom: (id)sender
{
    NSFont *font = [text font];
    font = [fm convertFont: font
                    toSize: [sender doubleValue]];
    [text setFont: font];
}

- (IBAction)takeFontAttributeFrom: (id)sender
{
    NSFont *font = [text font];
    NSFontTraitMask attribute = [sender tag];
    if (NSOnState == [sender state])
    {
        font = [fm convertFont: font toHaveTrait: attribute];
    }
    else
    {
        font = [fm convertFont: font toNotHaveTrait: attribute];
    }
    [sender setState: ([fm traitsOfFont: font] & attribute)];
    [text setFont: font];
}
@end
#import <Cocoa/Cocoa.h>

@interface FontController : NSObject {
    IBOutlet NSTextField *text;
}
- (IBAction)takeFontFamilyFrom: (id)sender;
- (IBAction)takeFontSizeFrom: (id)sender;
- (IBAction)takeFontAttributeFrom: (id)sender;
@end

#import "FontController.h"

NSFontManager *fm;

@implementation FontController
+ (void)initialize
{
    fm = [NSFontManager sharedFontManager];
}
- (IBAction)takeFontFamilyFrom: (id)sender
{
    NSFont *font = [text font];
    font = [fm convertFont: font
                  toFamily: [sender stringValue]];
    [text setFont: font];
}
- (IBAction)takeFontSizeFrom: (id)sender
{
    NSFont *font = [text font];
    font = [fm convertFont: font
                    toSize: [sender doubleValue]];
    [text setFont: font];
}

- (IBAction)takeFontAttributeFrom: (id)sender
{
    NSFont *font = [text font];
    NSFontTraitMask attribute = [sender tag];
    if (NSOnState == [sender state])
    {
        font = [fm convertFont: font toHaveTrait: attribute];
    }
    else
    {
        font = [fm convertFont: font toNotHaveTrait: attribute];
    }
    [sender setState: ([fm traitsOfFont: font] & attribute)];
    [text setFont: font];
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文