From 800641e11a1ae41b99e89622c111e37ee13ece20 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 15 Apr 2014 14:50:37 -0600 Subject: [PATCH] racket/draw Cocoa: hack to make Courier New work in 10.{7,8} The bounding box in the Courier New font is wrong in Mac OS X 10.7 and 10.8. Recognize that combination and make the bounding box bigger as a workaround. --- native-pkgs | 2 +- racket/src/native-libs/build.rkt | 6 +- .../src/native-libs/patches/courier-new.patch | 79 +++++++++++++++++++ racket/src/racket/src/fun.c | 2 +- 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 racket/src/native-libs/patches/courier-new.patch diff --git a/native-pkgs b/native-pkgs index a32d6b2b4c..ac6f3873bb 160000 --- a/native-pkgs +++ b/native-pkgs @@ -1 +1 @@ -Subproject commit a32d6b2b4cbdc9ff184d53144157035b0eec98b4 +Subproject commit ac6f3873bb45b88c965881c07057b431ccf6eb75 diff --git a/racket/src/native-libs/build.rkt b/racket/src/native-libs/build.rkt index f24a8c86fb..20b1d590b8 100644 --- a/racket/src/native-libs/build.rkt +++ b/racket/src/native-libs/build.rkt @@ -110,6 +110,9 @@ ;; Fix a problem with glyph extents and clipped rendering: (define-runtime-path cairo-coretext-patch "patches/cairo-coretext.patch") +;; Hack to workaround broken Courier New in Mac OS X 10.{7.8}: +(define-runtime-path courier-new-patch "patches/courier-new.patch") + ;; Enable kerning and set DPI to 72: (define-runtime-path coretext-patch "patches/coretext.patch") @@ -308,7 +311,8 @@ [("cairo") (config #:depends '("pixman" "fontconfig" "freetype" "libpng") #:env path-flags #:configure '("--enable-xlib=no") - #:patches (list cairo-coretext-patch))] + #:patches (list cairo-coretext-patch + courier-new-patch))] [("harfbuzz") (config #:depends '("fontconfig" "freetype" "cairo") #:configure '("--without-icu") #:patches (if win? diff --git a/racket/src/native-libs/patches/courier-new.patch b/racket/src/native-libs/patches/courier-new.patch new file mode 100644 index 0000000000..19906c515c --- /dev/null +++ b/racket/src/native-libs/patches/courier-new.patch @@ -0,0 +1,79 @@ +diff -r -u old/cairo-1.12.16/src/cairo-quartz-font.c new/cairo-1.12.16/src/cairo-quartz-font.c +--- old/cairo-1.12.16/src/cairo-quartz-font.c 2014-04-15 14:39:00.000000000 -0600 ++++ new/cairo-1.12.16/src/cairo-quartz-font.c 2014-04-15 14:49:16.000000000 -0600 +@@ -101,6 +101,10 @@ + static cairo_bool_t _cairo_quartz_font_symbol_lookup_done = FALSE; + static cairo_bool_t _cairo_quartz_font_symbols_present = FALSE; + ++# include ++# include ++static int is_10_7_or_10_8; ++ + static void + quartz_font_ensure_symbols(void) + { +@@ -149,6 +153,22 @@ + _cairo_quartz_font_symbols_present = TRUE; + + _cairo_quartz_font_symbol_lookup_done = TRUE; ++ ++ { ++ int a[2]; ++ size_t len; ++ char *vers; ++ ++ a[0] = CTL_KERN; ++ a[1] = KERN_OSRELEASE; ++ sysctl(a, 2, NULL, &len, NULL, 0); ++ vers = malloc(len); ++ sysctl(a, 2, vers, &len, NULL, 0); ++ if ((vers[0] == '1') && ((vers[1] == '1') || (vers[1] == '2')) && (vers[2] == '.')) { ++ is_10_7_or_10_8 = TRUE; ++ } ++ free(vers); ++ } + } + + typedef struct _cairo_quartz_font_face cairo_quartz_font_face_t; +@@ -156,6 +176,7 @@ + + struct _cairo_quartz_scaled_font { + cairo_scaled_font_t base; ++ int bbox_extend; /* Hack for Courier New on 10.7 and 10.8 */ + }; + + struct _cairo_quartz_font_face { +@@ -281,6 +302,22 @@ + if (status) + goto FINISH; + ++ if (is_10_7_or_10_8) { ++ CFStringRef name; ++ name = CGFontCopyFullName(font_face->cgFont); ++ if (name) { ++ char buf[32]; ++ if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)) { ++ if (!strcmp("Courier New", buf)) { ++ /* The Courier New font on 10.{7,8} has bad ++ bounding boxes. Correct it by extending the ++ reported box by an em on each side. */ ++ font->bbox_extend = TRUE; ++ } ++ } ++ } ++ } ++ + ems = CGFontGetUnitsPerEmPtr (font_face->cgFont); + + /* initialize metrics */ +@@ -467,6 +504,10 @@ + ymin = CGRectGetMinY(bbox); + xmax = CGRectGetMaxX(bbox); + ymax = CGRectGetMaxY(bbox); ++ if (font->bbox_extend) { /* Hack for Courier New on 10.{7,8} */ ++ xmax++; ++ xmin--; ++ } + + extents.x_bearing = xmin; + extents.y_bearing = - ymax; diff --git a/racket/src/racket/src/fun.c b/racket/src/racket/src/fun.c index 5ff6d9a1ce..108fa99322 100644 --- a/racket/src/racket/src/fun.c +++ b/racket/src/racket/src/fun.c @@ -9338,7 +9338,7 @@ static int VALID_TIME_RANGE(UNBUNDLE_TIME_TYPE lnow) sysctl(a, 2, vers, &len, NULL, 0); if ((vers[0] == '1') && (vers[1] == '0') && (vers[2] == '.')) { - /* localtime() in 10.7.x (= 10.x at the kernel layer) doesn't seem + /* localtime() in 10.6.x (= 10.x at the kernel layer) doesn't seem to work right with negative numbers that don't fit into 32 bits */ return 0; }