Fix scaling issues in cocoa text drawer

This commit is contained in:
Henrik Rydgård 2024-06-01 13:44:11 +02:00
parent 7b50443c66
commit 81c642e2b2
3 changed files with 9 additions and 9 deletions

View File

@ -33,14 +33,14 @@ float linearOut(int t, int fadeOutLength) {
}
float ease(float val) {
if (val > 1.0f) return 1.0f;
if (val < 0.0f) return 0.0f;
if (val >= 1.0f) return 1.0f;
if (val <= 0.0f) return 0.0f;
return (float)(((-cosf(val * PI)) + 1.0f) * 0.5);
}
float ease(int t, int fadeLength)
{
if (t < 0) return 0.0f;
if (t <= 0.0f) return 0.0f;
if (t >= fadeLength) return 1.0f;
return ease((float)t / (float)fadeLength);
}

View File

@ -113,10 +113,10 @@ void TextDrawer::DrawString(DrawBuffer &target, std::string_view str, float x, f
draw_->BindTexture(0, entry->texture);
// Okay, the texture is bound, let's draw.
float w = entry->width * fontScaleX_ * dpiScale_;
float h = entry->height * fontScaleY_ * dpiScale_;
float u = entry->width / (float)entry->bmWidth;
float v = entry->height / (float)entry->bmHeight;
float w = (float)entry->width * (fontScaleX_ * dpiScale_);
float h = (float)entry->height * (fontScaleY_ * dpiScale_);
float u = (float)entry->width / (float)entry->bmWidth;
float v = (float)entry->height / (float)entry->bmHeight;
DrawBuffer::DoAlign(align, &x, &y, &w, &h);
target.DrawTexRect(x, y, x + w, y + h, 0.0f, 0.0f, u, v, color);

View File

@ -184,8 +184,8 @@ bool TextDrawerCocoa::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStr
float w, h;
MeasureString(str, &w, &h);
// Reverse the DPI scale that MeasureString baked in.
w /= dpiScale_;
h /= dpiScale_;
w /= (dpiScale_ * fontScaleX_);
h /= (dpiScale_ * fontScaleY_);
int width = (int)ceilf(w);
int height = (int)ceilf(h);