experemental layout changes: <g:img> can be without spaces. delimiters can break strings (like http://sdfgasdgas.asdfgasd.asdfasdf)
This commit is contained in:
parent
2af7bcd326
commit
4e4d4cdcf3
|
@ -1529,15 +1529,58 @@ int get_token(const char *ptr, char **eptr, char **val, int *sp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_delim(int c)
|
||||||
|
{
|
||||||
|
switch(c) {
|
||||||
|
case '.':
|
||||||
|
case ',':
|
||||||
|
case ':':
|
||||||
|
case '!':
|
||||||
|
case '+':
|
||||||
|
case '?':
|
||||||
|
case '/':
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int word_img(const char *p, char **eptr)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
if (eptr)
|
||||||
|
*eptr = (char*)p;
|
||||||
|
if (!p)
|
||||||
|
return 0;
|
||||||
|
if (p[0] != '<' || p[1] != 'g' || p[2] != ':')
|
||||||
|
return 0;
|
||||||
|
p += 3;
|
||||||
|
len = strcspn(p, ">");
|
||||||
|
if (p[len] != '>')
|
||||||
|
return 0;
|
||||||
|
if (eptr)
|
||||||
|
*eptr = (char*)p + len + 1;
|
||||||
|
return len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *lookup_token_or_sp(const char *ptr)
|
static const char *lookup_token_or_sp(const char *ptr)
|
||||||
{
|
{
|
||||||
char *eptr;
|
char *eptr;
|
||||||
const char *p = ptr;
|
const char *p = ptr;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
p += strcspn(p, " <\n\t");
|
p += strcspn(p, " .,:!+?/<\t\n");
|
||||||
if (*p != '<' )
|
|
||||||
|
if (*p != '<' ) {
|
||||||
|
if (is_delim(*p))
|
||||||
|
p ++;
|
||||||
return p;
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
if (!get_token(p, &eptr, NULL, NULL)) {
|
if (!get_token(p, &eptr, NULL, NULL)) {
|
||||||
|
if (word_img(p, &eptr)) {
|
||||||
|
p = eptr;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
p ++;
|
p ++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1546,6 +1589,9 @@ static const char *lookup_token_or_sp(const char *ptr)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BREAK_NONE 0
|
||||||
|
#define BREAK_SPACE 1
|
||||||
|
|
||||||
static char *get_word(const char *ptr, char **eptr, int *sp)
|
static char *get_word(const char *ptr, char **eptr, int *sp)
|
||||||
{
|
{
|
||||||
const char *ep;
|
const char *ep;
|
||||||
|
@ -1555,18 +1601,23 @@ static char *get_word(const char *ptr, char **eptr, int *sp)
|
||||||
o = (char*)ptr;
|
o = (char*)ptr;
|
||||||
ptr += strspn(ptr, " \t");
|
ptr += strspn(ptr, " \t");
|
||||||
if (sp) {
|
if (sp) {
|
||||||
*sp = 0;
|
*sp = BREAK_NONE;
|
||||||
if (o != ptr)
|
if (o != ptr)
|
||||||
*sp = 1;
|
*sp = BREAK_SPACE;
|
||||||
}
|
}
|
||||||
if (!*ptr)
|
if (!*ptr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ep = lookup_token_or_sp(ptr);
|
ep = lookup_token_or_sp(ptr);
|
||||||
// ep += strcspn(ep, " \t\n");
|
// ep += strcspn(ep, " \t\n");
|
||||||
sz = ep - ptr;
|
sz = ep - ptr;
|
||||||
o = malloc(sz + 1);
|
o = malloc(sz + 1);
|
||||||
memcpy(o, ptr, sz);
|
memcpy(o, ptr, sz);
|
||||||
o[sz] = 0;
|
o[sz] = 0;
|
||||||
|
|
||||||
|
sz = word_img(ptr, eptr);
|
||||||
|
if (sz)
|
||||||
|
return o;
|
||||||
*eptr = (char*)ep;
|
*eptr = (char*)ep;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -2034,20 +2085,17 @@ void txt_layout_update_links(layout_t layout, int x, int y, clear_fn clear)
|
||||||
// gfx_noclip();
|
// gfx_noclip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
img_t get_img(struct layout *layout, char *p)
|
img_t get_img(struct layout *layout, char *p)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
img_t img;
|
img_t img;
|
||||||
if (!p)
|
len = word_img(p, NULL);
|
||||||
return NULL;
|
if (!len)
|
||||||
|
|
||||||
if (p[0] != '<' || p[1] != 'g' || p[2] != ':')
|
|
||||||
return NULL;
|
return NULL;
|
||||||
p += 3;
|
p += 3;
|
||||||
len = strcspn(p, ">");
|
p[len - 1] = 0;
|
||||||
if (p[len] != '>')
|
|
||||||
return NULL;
|
|
||||||
p[len] = 0;
|
|
||||||
img = layout_lookup_image(layout, p);
|
img = layout_lookup_image(layout, p);
|
||||||
if (!img && (img = gfx_load_image(p))) {
|
if (!img && (img = gfx_load_image(p))) {
|
||||||
struct image *image;
|
struct image *image;
|
||||||
|
@ -2061,7 +2109,7 @@ img_t get_img(struct layout *layout, char *p)
|
||||||
image->free_it = 1; /* free on layout destroy */
|
image->free_it = 1; /* free on layout destroy */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p[len] = '>';
|
p[len - 1] = '>';
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2140,7 +2188,7 @@ int get_unbrakable_len(struct layout *layout, const char *ptr)
|
||||||
char *p, *eptr;
|
char *p, *eptr;
|
||||||
while (ptr && *ptr) {
|
while (ptr && *ptr) {
|
||||||
int sp, sp2 = 0;
|
int sp, sp2 = 0;
|
||||||
while(get_token(ptr, &eptr, NULL, &sp)) {
|
while (get_token(ptr, &eptr, NULL, &sp)) {
|
||||||
if (sp)
|
if (sp)
|
||||||
sp2 ++;
|
sp2 ++;
|
||||||
ptr = eptr;
|
ptr = eptr;
|
||||||
|
@ -2157,12 +2205,16 @@ int get_unbrakable_len(struct layout *layout, const char *ptr)
|
||||||
}
|
}
|
||||||
TTF_SizeUTF8((TTF_Font *)(layout->fn), p, &ww, NULL);
|
TTF_SizeUTF8((TTF_Font *)(layout->fn), p, &ww, NULL);
|
||||||
ptr = eptr;
|
ptr = eptr;
|
||||||
|
w += ww;
|
||||||
if (!*p)
|
if (!*p)
|
||||||
ptr ++;
|
ptr ++;
|
||||||
w += ww;
|
else if (is_delim(*(ptr - 1))) {
|
||||||
|
free(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
return ww;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _txt_layout_add(layout_t lay, char *txt)
|
void _txt_layout_add(layout_t lay, char *txt)
|
||||||
|
@ -2211,10 +2263,10 @@ void _txt_layout_add(layout_t lay, char *txt)
|
||||||
if (!ptr || !*ptr)
|
if (!ptr || !*ptr)
|
||||||
break;
|
break;
|
||||||
if (sp2)
|
if (sp2)
|
||||||
sp = 2;
|
sp = -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sp == 2) {
|
if (sp == -1) {
|
||||||
p = get_word(ptr, &eptr, NULL);
|
p = get_word(ptr, &eptr, NULL);
|
||||||
sp = 1;
|
sp = 1;
|
||||||
} else
|
} else
|
||||||
|
@ -2222,7 +2274,6 @@ void _txt_layout_add(layout_t lay, char *txt)
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
addlen = get_unbrakable_len(layout, eptr);
|
addlen = get_unbrakable_len(layout, eptr);
|
||||||
img = get_img(layout, p);
|
img = get_img(layout, p);
|
||||||
if (img) {
|
if (img) {
|
||||||
|
@ -2264,8 +2315,10 @@ void _txt_layout_add(layout_t lay, char *txt)
|
||||||
line_free(line);
|
line_free(line);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sp && line->num)
|
if (!sp && line->num)
|
||||||
word->unbrake = 1;
|
word->unbrake = 1;
|
||||||
|
|
||||||
word->style = layout->style;
|
word->style = layout->style;
|
||||||
|
|
||||||
if (line->w && !word->unbrake)
|
if (line->w && !word->unbrake)
|
||||||
|
@ -2464,10 +2517,8 @@ void txt_layout_real_size(layout_t lay, int *pw, int *ph)
|
||||||
for (line = layout->lines; line; line = line->next) {
|
for (line = layout->lines; line; line = line->next) {
|
||||||
while (!line->num && line->next)
|
while (!line->num && line->next)
|
||||||
line = line->next;
|
line = line->next;
|
||||||
|
|
||||||
if (line->w > w)
|
if (line->w > w)
|
||||||
w = line->w;
|
w = line->w;
|
||||||
|
|
||||||
if (line->num && line->y + line->h > h)
|
if (line->num && line->y + line->h > h)
|
||||||
h = line->y + line->h;
|
h = line->y + line->h;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue