コード例 #1
0
ファイル: label.c プロジェクト: 1414648814/ejoy2d
static void
draw_line(const struct rich_text *rich, struct pack_label * l, struct srt *srt, const struct sprite_trans *arg,
          uint32_t color, int cy, int w, int start, int end, int *pre_char_cnt, float space_scale) {
    const char *str = rich->text;
		float cx;
    int j;
    int size = l->size;
    if (l->auto_scale != 0 && w > l->width)
    {
        float scale = l->width * 1.0f / w;
        size = scale * size;
        cy = cy + (l->size - size) / 2;
        w = l->width;
    }

    switch (l->align) {
        case LABEL_ALIGN_LEFT:
            cx = 0.0;
            break;
        case LABEL_ALIGN_RIGHT:
            cx = l->width - w;
            break;
        case LABEL_ALIGN_CENTER:
            cx = (l->width - w)/2;
            break;
    }
  
    int char_cnt = 0;
    for (j=start; j<end;) {
        int unicode;
        char_cnt++;
			
				int len = unicode_len(str[j]);
				unicode = get_unicode(str+j, len);
				j+=len;
			
        if(unicode != '\n') {
            uint32_t field_color = get_rich_field_color(rich, *pre_char_cnt+char_cnt);
						if (field_color == 0) {
							field_color = color;
						} else {
							field_color = color_mul(field_color,  color | 0xffffff);
						}
            cx+=(draw_utf8(unicode, cx, cy, size, srt, field_color, arg, l->edge) + l->space_w)*space_scale;
        }
    }
    *pre_char_cnt += char_cnt;
}
コード例 #2
0
ファイル: tools_len.c プロジェクト: Vesta-nna/Lem-in
int		wcharlen(wchar_t c)
{
	char	*bin;
	int		i;
	int		j;

	bin = get_unicode(c);
	i = 0;
	j = 0;
	while (bin[i])
	{
		i += 8;
		j++;
	}
	return (j);
}
コード例 #3
0
ファイル: label.c プロジェクト: Lancelod-Liu/ejoy2d
static void
draw_line(const char *str, struct pack_label * l, struct srt *srt, const struct sprite_trans *arg,
          uint32_t color, int cy, int w, int start, int end) {
    int cx, j;
    int size = l->size;
    if (l->auto_scale != 0 && w > l->width)
    {
        float scale = l->width * 1.0f / w;
        size = scale * size;
        cy = cy + (l->size - size) / 2;
        w = l->width;
    }

    switch (l->align) {
        case LABEL_ALIGN_LEFT:
            cx = 0;
            break;
        case LABEL_ALIGN_RIGHT:
            cx = l->width - w;
            break;
        case LABEL_ALIGN_CENTER:
            cx = (l->width - w)/2;
            break;
    }
    
    for (j=start; j<end;) {
        int unicode;
        uint8_t c = (uint8_t)str[j];
        if ((c&0x80) == 0) {
            unicode = get_unicode(str+j,1);
            j+=1;
        } else if ((c&0xe0) == 0xc0) {
            unicode = get_unicode(str+j,2);
            j+=2;
        } else if ((c&0xf0) == 0xe0) {
            unicode = get_unicode(str+j,3);
            j+=3;
        } else if ((c&0xf8) == 0xf0) {
            unicode = get_unicode(str+j,4);
            j+=4;
        } else if ((c&0xfc) == 0xf8) {
            unicode = get_unicode(str+j,5);
            j+=5;
        } else {
            unicode = get_unicode(str+j,6);
            j+=6;
        }
        
        if(unicode != '\n')
            cx+=draw_utf8(unicode, cx, cy, size, srt, color, arg) + l->space_w;
    }
}
コード例 #4
0
ファイル: tools_len.c プロジェクト: Vesta-nna/Lem-in
int		wstrlen(wchar_t *s)
{
	char	*bin;
	int		i;
	int		j;
	int		k;

	i = 0;
	k = 0;
	while (s[i])
	{
		j = 0;
		bin = get_unicode(s[i]);
		while (bin[j])
		{
			j += 8;
			k++;
		}
		i++;
	}
	return (k);
}
コード例 #5
0
ファイル: str_conv.c プロジェクト: wilx/hs-bibutils
/*
 * Returns 1 on memory error condition
 */
int
str_convert( str *s,
	int charsetin,  int latexin,  int utf8in,  int xmlin,
	int charsetout, int latexout, int utf8out, int xmlout )
{
	unsigned int pos = 0;
	unsigned int ch;
	str ns;
	int ok = 1;

	if ( !s || s->len==0 ) return ok;

	/* Ensure that string is internally allocated.
	 * This fixes NULL pointer derefernce in CVE-2018-10775 in bibutils
	 * as a string with a valid data pointer is potentially replaced
	 * by a string without a valid data pointer due to it being invalid
	 * unicode.
	 * This probably also fixes CVE-2018-10773 and CVE-2018-10774 which
	 * are NULL dereferences also likely due to a fuzzer, but without
	 * test cases in the report, I can't be completely sure.
	 */
	str_initstrc( &ns, "" );

	if ( charsetin==CHARSET_UNKNOWN ) charsetin = CHARSET_DEFAULT;
	if ( charsetout==CHARSET_UNKNOWN ) charsetout = CHARSET_DEFAULT;

	while ( s->data[pos] ) {
		ch = get_unicode( s, &pos, charsetin, latexin, utf8in, xmlin );
		ok = write_unicode( &ns, ch, charsetout, latexout, utf8out, xmlout );
		if ( !ok ) goto out;
	}

	str_swapstrings( s, &ns );
out:
	str_free( &ns );

	return ok;
}