mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-26 11:45:26 +00:00
Android: Prevent a text bitmap size from becoming 0 on '\r\n'. Fixes #10764 (unless there are more platforms where it's broken...)
This commit is contained in:
parent
fb798cf6b2
commit
7761d2366b
@ -26,12 +26,17 @@ public class TextRenderer {
|
||||
}
|
||||
}
|
||||
private static Point measureLine(String string, double textSize) {
|
||||
p.setTextSize((float)textSize);
|
||||
int w = (int)p.measureText(string);
|
||||
int w;
|
||||
if (string.length() > 0) {
|
||||
p.setTextSize((float)textSize);
|
||||
w = (int)p.measureText(string);
|
||||
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures which
|
||||
// OpenGL does not like - each line must be 4-byte aligned
|
||||
w = (w + 5) & ~1;
|
||||
} else {
|
||||
w = 1;
|
||||
}
|
||||
int h = (int)(p.descent() - p.ascent() + 2.0f);
|
||||
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures which
|
||||
// OpenGL does not like - each line must be 4-byte aligned
|
||||
w = (w + 5) & ~1;
|
||||
Point p = new Point();
|
||||
p.x = w;
|
||||
p.y = h;
|
||||
@ -57,6 +62,10 @@ public class TextRenderer {
|
||||
|
||||
int w = s.x;
|
||||
int h = s.y;
|
||||
if (w == 0)
|
||||
w = 1;
|
||||
if (h == 0)
|
||||
h = 1;
|
||||
|
||||
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bmp);
|
||||
@ -65,7 +74,8 @@ public class TextRenderer {
|
||||
String lines[] = string.replaceAll("\\r", "").split("\n");
|
||||
float y = 1.0f;
|
||||
for (String line : lines) {
|
||||
canvas.drawText(line, 1, -p.ascent() + y, p);
|
||||
if (line.length() > 0)
|
||||
canvas.drawText(line, 1, -p.ascent() + y, p);
|
||||
y += p.descent() - p.ascent();
|
||||
}
|
||||
|
||||
|
@ -184,8 +184,13 @@ void TextDrawerAndroid::DrawString(DrawBuffer &target, const char *str, float x,
|
||||
|
||||
jstring jstr = env_->NewStringUTF(text.c_str());
|
||||
uint32_t textSize = env_->CallStaticIntMethod(cls_textRenderer, method_measureText, jstr, size);
|
||||
int imageWidth = (textSize >> 16);
|
||||
int imageHeight = (textSize & 0xFFFF);
|
||||
int imageWidth = (short)(textSize >> 16);
|
||||
int imageHeight = (short)(textSize & 0xFFFF);
|
||||
if (imageWidth <= 0)
|
||||
imageWidth = 1;
|
||||
if (imageHeight <= 0)
|
||||
imageHeight = 1;
|
||||
|
||||
jintArray imageData = (jintArray)env_->CallStaticObjectMethod(cls_textRenderer, method_renderText, jstr, size);
|
||||
env_->DeleteLocalRef(jstr);
|
||||
|
||||
|
@ -232,7 +232,8 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f
|
||||
if (size.cy > MAX_TEXT_HEIGHT)
|
||||
size.cy = MAX_TEXT_HEIGHT;
|
||||
// Prevent zero-sized textures, which can occur. Not worth to avoid
|
||||
// creating the texture altogether in this case.
|
||||
// creating the texture altogether in this case. One example is a string
|
||||
// containing only '\r\n', see issue #10764.
|
||||
if (size.cx == 0)
|
||||
size.cx = 1;
|
||||
if (size.cy == 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user