Skip to content

Commit

Permalink
Scaling and line spacing work
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed May 26, 2024
1 parent 67334c4 commit 01b1190
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions Common/Render/Text/draw_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct TextStringEntry {
struct TextMeasureEntry {
int width;
int height;
int leading; // only used with Cocoa
int lastUsedFrame;
};

Expand Down
10 changes: 6 additions & 4 deletions Common/Render/Text/draw_text_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

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,
Expand Down Expand Up @@ -86,7 +86,7 @@ void Destroy() {
if (fontName)
fname = fontName;
else
fname = "Helvetica Light";
fname = "Helvetica";

TextDrawerFontContext *font = new TextDrawerFontContext();
font->bold = false;
Expand Down Expand Up @@ -209,14 +209,15 @@ void Destroy() {
entry = new TextMeasureEntry();
entry->width = width;
entry->height = height;
entry->leading = leading;
sizeCache_[key] = std::unique_ptr<TextMeasureEntry>(entry);
}
entry->lastUsedFrame = frameCount_;

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;
}

Expand Down Expand Up @@ -404,6 +405,7 @@ void Destroy() {
// 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();
Expand Down

0 comments on commit 01b1190

Please sign in to comment.