From 021d2d5ef03af0391cde05af4ea083defa4d9500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 25 May 2024 17:17:29 +0200 Subject: [PATCH] Scaling and line spacing work --- Common/Render/Text/draw_text.h | 1 + Common/Render/Text/draw_text_cocoa.mm | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Common/Render/Text/draw_text.h b/Common/Render/Text/draw_text.h index ad7d1688b4..acbe15b21f 100644 --- a/Common/Render/Text/draw_text.h +++ b/Common/Render/Text/draw_text.h @@ -34,6 +34,7 @@ struct TextStringEntry { struct TextMeasureEntry { int width; int height; + int leading; // only used with Cocoa int lastUsedFrame; }; diff --git a/Common/Render/Text/draw_text_cocoa.mm b/Common/Render/Text/draw_text_cocoa.mm index 38c170afe1..22bd353d8a 100644 --- a/Common/Render/Text/draw_text_cocoa.mm +++ b/Common/Render/Text/draw_text_cocoa.mm @@ -40,8 +40,8 @@ public: void Create() { // Create an attributed string with string and font information - CGFloat fontSize = height * dpiScale; - INFO_LOG(G3D, "Creating cocoa typeface '%s' size %d", fname.c_str(), height); + CGFloat fontSize = height / dpiScale; + INFO_LOG(G3D, "Creating cocoa typeface '%s' size %d (effective size %0.1f)", fname.c_str(), height, fontSize); CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica"), fontSize, nil); attributes = [NSDictionary dictionaryWithObjectsAndKeys: (id)font, kCTFontAttributeName, @@ -86,7 +86,7 @@ uint32_t TextDrawerCocoa::SetFont(const char *fontName, int size, int flags) { if (fontName) fname = fontName; else - fname = "Helvetica Light"; + fname = "Helvetica"; TextDrawerFontContext *font = new TextDrawerFontContext(); font->bold = false; @@ -209,6 +209,7 @@ void TextDrawerCocoa::MeasureStringRect(std::string_view str, const Bounds &boun entry = new TextMeasureEntry(); entry->width = width; entry->height = height; + entry->leading = leading; sizeCache_[key] = std::unique_ptr(entry); } entry->lastUsedFrame = frameCount_; @@ -216,7 +217,7 @@ void TextDrawerCocoa::MeasureStringRect(std::string_view str, const Bounds &boun if (total_w < entry->width) { total_w = entry->width; } - int h = entry->height; // i == lines.size() - 1 ? entry->height : metrics.tmHeight + metrics.tmExternalLeading; + int h = i == lines.size() - 1 ? entry->height : (entry->height + entry->leading); total_h += h; } @@ -404,6 +405,7 @@ void TextDrawerCocoa::OncePerFrame() { // If DPI changed (small-mode, future proper monitor DPI support), drop everything. float newDpiScale = CalculateDPIScale(); if (newDpiScale != dpiScale_) { + INFO_LOG(G3D, "TextDrawerCocoa: DPI scale: %0.1f", newDpiScale); dpiScale_ = newDpiScale; ClearCache(); RecreateFonts();