Remove unused and broken text rotation code

This commit is contained in:
Henrik Rydgård 2024-05-31 20:58:53 +02:00
parent a431d53da3
commit 5b0007f391
9 changed files with 15 additions and 46 deletions

View File

@ -549,10 +549,6 @@ void DrawBuffer::DoAlign(int flags, float *x, float *y, float *w, float *h) {
if (flags & ALIGN_RIGHT) *x -= *w;
if (flags & ALIGN_VCENTER) *y -= *h / 2;
if (flags & ALIGN_BOTTOM) *y -= *h;
if (flags & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) {
std::swap(*w, *h);
std::swap(*x, *y);
}
}
// TODO: Actually use the rect properly, take bounds.
@ -627,12 +623,8 @@ void DrawBuffer::DrawText(FontID font, std::string_view text, float x, float y,
DoAlign(align, &x, &y, &w, &h);
}
if (align & ROTATE_90DEG_LEFT) {
x -= atlasfont->ascend * fontscaley;
// y += h;
} else {
y += atlasfont->ascend * fontscaley;
}
y += atlasfont->ascend * fontscaley;
float sx = x;
UTF8 utf(text);
for (size_t i = 0; i < textLen; i++) {
@ -658,27 +650,17 @@ void DrawBuffer::DrawText(FontID font, std::string_view text, float x, float y,
if (ch) {
const AtlasChar &c = *ch;
float cx1, cy1, cx2, cy2;
if (align & ROTATE_90DEG_LEFT) {
cy1 = y - c.ox * fontscalex;
cx1 = x + c.oy * fontscaley;
cy2 = y - (c.ox + c.pw) * fontscalex;
cx2 = x + (c.oy + c.ph) * fontscaley;
} else {
cx1 = x + c.ox * fontscalex;
cy1 = y + c.oy * fontscaley;
cx2 = x + (c.ox + c.pw) * fontscalex;
cy2 = y + (c.oy + c.ph) * fontscaley;
}
cx1 = x + c.ox * fontscalex;
cy1 = y + c.oy * fontscaley;
cx2 = x + (c.ox + c.pw) * fontscalex;
cy2 = y + (c.oy + c.ph) * fontscaley;
V(cx1, cy1, color, c.sx, c.sy);
V(cx2, cy1, color, c.ex, c.sy);
V(cx2, cy2, color, c.ex, c.ey);
V(cx1, cy1, color, c.sx, c.sy);
V(cx2, cy2, color, c.ex, c.ey);
V(cx1, cy2, color, c.sx, c.ey);
if (align & ROTATE_90DEG_LEFT)
y -= c.wx * fontscalex;
else
x += c.wx * fontscalex;
x += c.wx * fontscalex;
}
}
}

View File

@ -28,11 +28,6 @@ enum {
ALIGN_BOTTOMLEFT = ALIGN_BOTTOM | ALIGN_LEFT,
ALIGN_BOTTOMRIGHT = ALIGN_BOTTOM | ALIGN_RIGHT,
// Only for text drawing
ROTATE_90DEG_LEFT = 256,
ROTATE_90DEG_RIGHT = 512,
ROTATE_180DEG = 1024,
// For "uncachable" text like debug log.
// Avoids using system font drawing as it's too slow.
// Not actually used here but is reserved for whatever system wraps DrawBuffer.

View File

@ -140,8 +140,7 @@ void TextDrawer::DrawStringRect(DrawBuffer &target, std::string_view str, const
std::string toDraw(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toDraw, str, rotated ? bounds.h : bounds.w, wrap);
WrapString(toDraw, str, bounds.w, wrap);
}
DrawString(target, toDraw.c_str(), x, y, color, align);
@ -151,8 +150,7 @@ bool TextDrawer::DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStri
std::string toDraw(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toDraw, str, rotated ? bounds.h : bounds.w, wrap);
WrapString(toDraw, str, bounds.w, wrap);
}
return DrawStringBitmap(bitmapData, entry, texFormat, toDraw.c_str(), align, fullColor);
}

View File

@ -128,8 +128,7 @@ void TextDrawerAndroid::MeasureStringRect(std::string_view str, const Bounds &bo
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w, wrap);
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
}
auto env = getEnv();

View File

@ -180,8 +180,7 @@ void TextDrawerCocoa::MeasureStringRect(std::string_view str, const Bounds &boun
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w, wrap);
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
}
std::vector<std::string_view> lines;

View File

@ -77,8 +77,7 @@ void TextDrawerQt::MeasureStringRect(std::string_view str, const Bounds &bounds,
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w, wrap);
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
}
QFont* font = fontMap_.find(fontHash_)->second;

View File

@ -316,8 +316,7 @@ void TextDrawerSDL::MeasureStringRect(std::string_view str, const Bounds &bounds
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w, wrap);
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
}
TTF_Font *font = fontMap_.find(fontHash_)->second;

View File

@ -257,8 +257,7 @@ void TextDrawerUWP::MeasureStringRect(std::string_view str, const Bounds &bounds
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w, wrap);
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
}
std::vector<std::string> lines;

View File

@ -170,8 +170,7 @@ void TextDrawerWin32::MeasureStringRect(std::string_view str, const Bounds &boun
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w, wrap);
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
}
TEXTMETRIC metrics{};