summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-09-18 11:46:10 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-09-21 14:21:05 +0200
commit31ae3ac9da05e3d7fa6ce39db7a64f5701c5b28a (patch)
treec246373a8a0ac9e850501378e09a38da3a156277
parent41c6a5a06acfa9386c980d24c538fc22cc7c1bb3 (diff)
downloadmupdf-31ae3ac9da05e3d7fa6ce39db7a64f5701c5b28a.tar.xz
gl: Break UI lines on space characters.
-rw-r--r--platform/gl/gl-font.c75
1 files changed, 55 insertions, 20 deletions
diff --git a/platform/gl/gl-font.c b/platform/gl/gl-font.c
index b286d8a6..33dbcdf5 100644
--- a/platform/gl/gl-font.c
+++ b/platform/gl/gl-font.c
@@ -330,39 +330,69 @@ float ui_measure_string_part(const char *s, const char *e)
int ui_break_lines(char *a, struct line *lines, int maxlines, int width, int *maxwidth)
{
- char *next, *b = a;
+ char *next, *space = NULL, *b = a;
int c, n = 0;
- float x = 0, w = 0;
+ float space_x, x = 0, w = 0;
+
if (maxwidth)
*maxwidth = 0;
+
while (*b)
{
next = b + fz_chartorune(&c, b);
- if (c == '\n' || c == '\r')
+ if (c == '\r' || c == '\n')
{
- if (n + 1 < maxlines)
+ if (lines && n < maxlines)
{
- if (maxwidth && x > *maxwidth)
- *maxwidth = x;
lines[n].a = a;
lines[n].b = b;
++n;
- a = next;
- x = 0;
}
+ if (maxwidth && *maxwidth < x)
+ *maxwidth = x;
+ a = next;
+ x = 0;
+ space = NULL;
}
else
{
+ if (c == ' ')
+ {
+ space = b;
+ space_x = x;
+ }
+
w = ui_measure_character(c);
- if (x + w > width && (n + 1 < maxlines))
+ if (x + w > width)
{
- if (maxwidth && x > *maxwidth)
- *maxwidth = x;
- lines[n].a = a;
- lines[n].b = b;
- ++n;
- a = b;
- x = w;
+ if (space)
+ {
+ if (lines && n < maxlines)
+ {
+ lines[n].a = a;
+ lines[n].b = space;
+ ++n;
+ }
+ if (maxwidth && *maxwidth < space_x)
+ *maxwidth = space_x;
+ a = next = space + 1;
+ x = 0;
+ space = NULL;
+ }
+ else
+ {
+ if (lines && n < maxlines)
+ {
+ lines[n].a = a;
+ lines[n].b = b;
+ ++n;
+ }
+ if (maxwidth && *maxwidth < x)
+ *maxwidth = x;
+ a = b;
+ x = w;
+ space = NULL;
+ }
}
else
{
@@ -371,11 +401,16 @@ int ui_break_lines(char *a, struct line *lines, int maxlines, int width, int *ma
}
b = next;
}
- if (maxwidth && x > *maxwidth)
+
+ if (lines && n < maxlines)
+ {
+ lines[n].a = a;
+ lines[n].b = b;
+ ++n;
+ }
+ if (maxwidth && *maxwidth < x)
*maxwidth = x;
- lines[n].a = a;
- lines[n].b = b;
- return n + 1;
+ return n;
}
void ui_draw_lines(float x, float y, struct line *lines, int n)