--Get the font family and make it ** Japanese ** --Display a list of available font styles --Output font name in Japanese
--fontFamilies
List of available font families
--localizedFamilyName
Font localization (Japanese this time)
let fontFamilies = NSFontManager.shared.availableFontFamilies
for family in fontFamilies {
print(family)//Font family name
let localizedFamilyName = NSFontManager.shared.localizedName(forFamily: family, face: nil)
print(localizedFamilyName)//Font family name(After localization)
}
NSFontManager.shared.availableFontFamilies
--Get the available font family.
localizedName(forFamily:face:)
--Localize font family names to your language
localizedName(forFamily:face:) Returns a localized string with the name of the specified font family and face, if one exists.
Return Value A localized string with the name of the specified font family and face, or, if face is nil, the font family only.
From AppleDocumentation / NSFontmanager
If you pass nil to the argument face:
, you can only get the localized font family.
--availableMembers (ofFontFamily :)
Get available members from the font family
--Get the localized name from the displayName
instance of NSFont
let fontFamilies = NSFontManager.shared.availableFontFamilies
for family in fontFamilies {
let localizedFamilyName = NSFontManager.shared.localizedName(forFamily: family, face: nil)
print(localizedFamilyName)//Font family name
//Get available members from font family name
let FontMembers = NSFontManager.shared.availableMembers(ofFontFamily: family)
for i in 0 ..< FontMembers!.count{
let Font = FontMembers![i][0] as! String//Get the members available here
let FontName = NSFont(name: Font, size: NSFont.systemFontSize)//Create an instance of NSFont
print(FontName?.displayName)
}
}
availableMembers(ofFontFamily:)
--Specify a font family to get the members of available fonts
For example, if you call availableMembersOfFontFamily:@"Times", it might return an array like this: (("Times-Roman", "Roman", 5, 4), ("Times-Italic", "Italic", 6, 5), ("Times-Bold", "Bold", 9, 2), ("Times-BoldItalic", "Bold Italic", 9, 3) )
From AppleDocumentation / available members
.displayName
--Get the localized font name from an instance of NSFont
Not all font files are complete, so you may really need to handle the error.
Please point out any mistakes.
https://developer.apple.com/documentation/appkit/nsfontmanager https://developer.apple.com/documentation/appkit/nsfont
https://stackoverflow.com/questions/2977915/how-can-i-get-a-list-of-the-available-nsfont-families
Recommended Posts