changeset 20688:fbdf622fa8b3 draft

-Fix [FS#4857]: [OSX] Monospace font detection.
author Michael Lutz <michi@icosahedron.de>
date Thu, 07 Mar 2013 05:48:21 +0100
parents cd0c49238237
children dc0d0d726c8f
files src/fontdetection.cpp src/os/macosx/macos.h src/os/macosx/macos.mm
diffstat 3 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/fontdetection.cpp
+++ b/src/fontdetection.cpp
@@ -496,6 +496,8 @@
 			if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue;
 			/* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */
 			if (symbolic_traits & kCTFontBoldTrait) continue;
+			/* Select monospaced fonts if asked for. */
+			if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
 
 			/* Get font name. */
 			char name[128];
@@ -530,8 +532,13 @@
 			CFStringRef font_name;
 			ATSFontGetName(font, kATSOptionFlagsDefault, &font_name);
 			CFStringGetCString(font_name, name, lengthof(name), kCFStringEncodingUTF8);
+
+			bool monospace = IsMonospaceFont(font_name);
 			CFRelease(font_name);
 
+			/* Select monospaced fonts if asked for. */
+			if (monospace != callback->Monospace()) continue;
+
 			/* We only want the base font and not bold or italic variants. */
 			if (strstr(name, "Italic") != NULL || strstr(name, "Bold")) continue;
 
--- a/src/os/macosx/macos.h
+++ b/src/os/macosx/macos.h
@@ -62,4 +62,6 @@
 	return true;
 }
 
+bool IsMonospaceFont(CFStringRef name);
+
 #endif /* MACOS_H */
--- a/src/os/macosx/macos.mm
+++ b/src/os/macosx/macos.mm
@@ -193,3 +193,15 @@
 
 	return count;
 }
+
+/**
+ * Check if a font is a monospace font.
+ * @param name Name of the font.
+ * @return True if the font is a monospace font.
+ */
+bool IsMonospaceFont(CFStringRef name)
+{
+	NSFont *font = [ NSFont fontWithName:(NSString *)name size:0.0f ];
+
+	return font != NULL ? [ font isFixedPitch ] : false;
+}