From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: [PATCH] Fix synthetic bold on macOS retina displays Date: Mon, 29 Aug 2016 20:56:19 +0100 Message-ID: <20160829195619.GA91301@breton.holly.idiocy.org> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1472500665 23348 195.159.176.226 (29 Aug 2016 19:57:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Aug 2016 19:57:45 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) Cc: Marius Kjeldahl , Emacs-Devel devel To: YAMAMOTO Mitsuharu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 29 21:57:41 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1beSgY-0005Jf-Sh for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 21:57:35 +0200 Original-Received: from localhost ([::1]:45560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSgW-0001Yy-Hg for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 15:57:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSgQ-0001Yt-3t for emacs-devel@gnu.org; Mon, 29 Aug 2016 15:57:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beSgM-0006uA-Vu for emacs-devel@gnu.org; Mon, 29 Aug 2016 15:57:26 -0400 Original-Received: from mail-wm0-f53.google.com ([74.125.82.53]:37872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSgM-0006tw-OM for emacs-devel@gnu.org; Mon, 29 Aug 2016 15:57:22 -0400 Original-Received: by mail-wm0-f53.google.com with SMTP id i5so2300945wmg.0 for ; Mon, 29 Aug 2016 12:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=AVk36kjJKlndD4jJvBvgHUysVwVvFQX3pL/P9mezGrs=; b=H5FPthkwBCFJbDw9S8flEa1X+9CMVCNf0Akq9iRNqzQMavUoHZd8pekAz0wpDxrZ9q ZahPUVZc1JRrFNy+E39QzJrm6EGkRbb4V08s5aUbAwJqtQ++BQrFDr2s9uSAkhQ7esFa 0ERi1Oi9/1vSEQg8rUcD/7wGtuQ/sShceCKhIUXAgqOmgHzzatyfmYNE9zLPIHJgAdKf cZxABxfj6mJARXl2SBlC+EXyqMCKC48PC3/Kt9vy2x2eA3XwmOTAhPYt1SGLW43XFhwp Q/D8ldPw/ROUyHPtX4/hjHMBtpG6v4fZ81BTCudFmHysFtn5VR20VzZ0kcFKOavUqdeS AFYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=AVk36kjJKlndD4jJvBvgHUysVwVvFQX3pL/P9mezGrs=; b=iqAceCojtLv+Qg1t9WgAcVQaLEp5vPgsF3yMP7SRjFkYr/uguGYbirwVnTKvKd6/Ta zs/+MTVR4y+YhAaZZ6U4PyNEEjNR7wQ89CYTmFUz6t+r8rfUwGOw3uIssr+mfIImJidZ FEAkmw1OorGT7bld7QYZK7kwj88OeVWoKPHCpURgp6MujoCTm3lNB+oGxqO4u4llJJXP oxsLGzBrKHNFbASrzLnYOvd/54wT75/jGr/At512c9Ty4fG0T+I010YMnk2xC6hJC4gM R3+Emf9xFrZiY77h8L1zoTtu70Eu6t7R1kp72IRbC2AN+6C47lBHs481e0R5S2jWYuC/ HxTA== X-Gm-Message-State: AE9vXwPUxH3uWY3/LsEbEuzfovKHCu/7h65mdCn0jMUNufmp6RcpiiQw5fiFRIzHfnuyfg== X-Received: by 10.194.145.103 with SMTP id st7mr16812004wjb.61.1472500581943; Mon, 29 Aug 2016 12:56:21 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-3421-ac94-236e-98bd.holly.idiocy.org. [2001:8b0:3f8:8129:3421:ac94:236e:98bd]) by smtp.gmail.com with ESMTPSA id za2sm35835897wjb.34.2016.08.29.12.56.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 12:56:21 -0700 (PDT) Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.53 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206906 Archived-At: * src/macfont.m (macfont_draw): Multiply the synthetic bold scaling factor by the OS window backing scale factor. --- src/macfont.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/macfont.m b/src/macfont.m index c799100..d9bad03 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -2878,7 +2878,19 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no if (macfont_info->synthetic_bold_p && ! no_antialias_p) { CGContextSetTextDrawingMode (context, kCGTextFillStroke); + + /* Stroke line width for text drawing is not correctly + scaled on Retina display/HiDPI mode when drawn to screen + (whereas it is correctly scaled when drawn to bitmaps), + and synthetic bold looks thinner on such environments. + Apple says there are no plans to address this issue + (rdar://11644870) currently. So we add a workaround. */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + CGContextSetLineWidth (context, synthetic_bold_factor * font_size + * [[FRAME_NS_VIEW(f) window] backingScaleFactor]); +#else CGContextSetLineWidth (context, synthetic_bold_factor * font_size); +#endif CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f); } if (no_antialias_p) -- Not a lot to this. I hope you don’t mind that I stole your explanatory comment completely. We don’t (as far as I’m aware) have a neat way of checking versions at run‐time, so I’ve just stuck to making it a compile‐time check. -- Alan Third