@@ -59,23 +59,25 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &_name,
5959
6060 std::string name (_name);
6161
62+ CTFontSymbolicTraits traits = 0 ;
63+ CTFontSymbolicTraits trait_mask = kCTFontTraitBold | kCTFontTraitItalic ;
64+
6265 if (name.find (' |' ) != std::string::npos)
6366 {
64- // Handle the "Font Family|Style" type of font name, by
65- // modifying the name to be more likely a PostScript name:
66- // - Style is separated from family name by '-', not '|'.
67- strreplace (name, " |" , " -" );
68- // - Spaces within the name are removed.
69- strreplace (name, " " , " " );
70- std::string regular (" -Regular" );
71-
72- // - The "Regular" style is not spelled out.
73- if (name.rfind (regular) == name.length () - regular.length ())
67+ // Handle the "Font Family|Style" type of font name:
68+ // Separate it into family and style, and extract bold and italic style information
69+ // into CTFontSymbolicTraits.
70+ std::string::size_type const separator = name.rfind (' |' );
71+ std::string const style ((std::string::npos != separator) ? name.substr (separator + 1 ) : std::string ());
72+ if ((style.find (" Bold" ) != std::string::npos) || (style.find (" Black" ) != std::string::npos))
7473 {
75- name = name. substr ( 0 , name. length () - regular. length ()) ;
74+ traits |= kCTFontTraitBold ;
7675 }
77-
78- osd_printf_verbose (" osd_font_osx::open: candidate PostScript name=\" %s\"\n " , name);
76+ if ((style.find (" Italic" ) != std::string::npos) || (style.find (" Oblique" ) != std::string::npos))
77+ {
78+ traits |= kCTFontTraitItalic ;
79+ }
80+ name = name.substr (0 , separator);
7981 }
8082
8183 CFStringRef font_name;
@@ -103,14 +105,26 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &_name,
103105 return false ;
104106 }
105107
106- CTFontDescriptorRef const font_descriptor (CTFontDescriptorCreateWithNameAndSize (font_name, 0.0 ));
108+ CTFontDescriptorRef font_descriptor (CTFontDescriptorCreateWithNameAndSize (font_name, 0.0 ));
107109 CFRelease (font_name);
108110 if (!font_descriptor)
109111 {
110112 osd_printf_verbose (" osd_font_osx::open: failed to create CoreText font descriptor for \" %s\"\n " , name);
111113 return false ;
112114 }
113115
116+ if (traits != 0 )
117+ {
118+ CTFontDescriptorRef styled_descriptor (CTFontDescriptorCreateCopyWithSymbolicTraits (font_descriptor, traits, trait_mask));
119+ CFRelease (font_descriptor);
120+ if (!styled_descriptor)
121+ {
122+ osd_printf_verbose (" osd_font_osx::open: failed to create styled CoreText font descriptor for \" %s\" with traits=%08x\n " , name, traits);
123+ return false ;
124+ }
125+ font_descriptor = styled_decscriptor;
126+ }
127+
114128 CTFontRef const ct_font (CTFontCreateWithFontDescriptor (font_descriptor, POINT_SIZE, &CGAffineTransformIdentity));
115129 CFRelease (font_descriptor);
116130 if (!ct_font)
0 commit comments