示例#1
0
文件: label.c 项目: 1414648814/ejoy2d
void
label_size(const char *str, struct pack_label * l, int* width, int* height) {
	char utf8[7];
	int i;
	int w=0, max_w=0, h=0, max_h=0;
	for (i=0; str[i];) {
		int unicode;
		int len = unicode_len(str[i]);
		unicode = copystr(utf8, str+i, len);
		i+=len;
		struct font_context ct = char_size(unicode, utf8, l->size, l->edge);
		w += ct.w + l->space_w;
		if (h==0) {
			h = ct.h + l->space_h;
		}
		if((l->auto_scale == 0 && w > l->width) || unicode == '\n') {
			max_h += h;
			h = 0;
			if (w > max_w) max_w = w;
			w = 0;
		}
	}

	max_h += h;
	if (w > max_w) max_w = w;
    if (l->auto_scale > 0 && max_w > l->width)
        max_w = l->width;
   
	*width = max_w;
	*height = max_h;
}
示例#2
0
文件: label.c 项目: 1414648814/ejoy2d
void
label_draw(const struct rich_text *rich, struct pack_label * l, struct srt *srt, const struct sprite_trans *arg) {
	shader_texture(Tex, 0);
	uint32_t color = label_get_color(l, arg);
	const char *str = rich->text;

	char utf8[7];
	int i;
	int ch = 0, w = 0, cy = 0, pre = 0, char_cnt = 0, idx = 0;
	for (i=0; str && str[i];) {
		int unicode;
		int len = unicode_len(str[i]);
		unicode = copystr(utf8, str+i, len);
		i+=len;
		w += draw_size(unicode, utf8, l->size, l->edge) + l->space_w;
		if (ch == 0) {
				ch = draw_height(unicode, utf8, l->size, l->edge) + l->space_h;
		}
		
		float space_scale=1.0;
		uint32_t lf = get_rich_filed_lf(rich, idx, &space_scale);
		if((l->auto_scale == 0 && lf) || unicode == '\n') {
				draw_line(rich, l, srt, arg, color, cy, w, pre, i, &char_cnt, space_scale);
				cy += ch;
				pre = i;
				w = 0; ch = 0;
		}
		idx++;
	}
    
	draw_line(rich, l, srt, arg, color, cy, w, pre, i, &char_cnt, 1.0);
}
示例#3
0
文件: label.c 项目: 1414648814/ejoy2d
int
label_char_size(struct pack_label* l, const char* chr, int* width, int* height, int* unicode) {
	char utf8[7];
	int len = unicode_len(chr[0]);
	*unicode = copystr(utf8, chr, len);
	struct font_context ct = char_size(*unicode, utf8, l->size, l->edge);
	*width = ct.w + l->space_w;
	*height = ct.h + l->space_h;
	return len;
}
示例#4
0
文件: label.c 项目: 1414648814/ejoy2d
static int
raw_width(const char * str,  struct pack_label * l) {
	char utf8[7];
	int i;
	int w=0;
	for (i=0; str[i];) {
		int len = unicode_len(str[i]);
		int unicode = copystr(utf8, str+i, len);
		i+=len;
		struct font_context ct = char_size(unicode, utf8, l->size, l->edge);
		w += ct.w + l->space_w;
	}
	return w;
}
示例#5
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;
}
示例#6
0
文件: label.c 项目: 1414648814/ejoy2d
int
label_rawline(const char * str, struct pack_label *l) {
	char utf8[7];
	int i;
	int w=0;
	for (i=0; str[i];) {
		int len = unicode_len(str[i]);
		int unicode = copystr(utf8, str+i, len);
		struct font_context ct = char_size(unicode, utf8, l->size, l->edge);
		if (w+ct.w > l->width) {
			break;
		}
		i+=len;
		w += ct.w + l->space_w;
	}
	return i;
}
示例#7
0
文件: label.c 项目: 1414648814/ejoy2d
void
label_rawdraw(const char * str, float fx, float y, struct pack_label * l) {
	shader_texture(Tex, 0);
	uint32_t color = l->color;
	int edge = l->edge;
	int size = l->size;
	int width = raw_width(str, l);
	int x = (int)fx;

	switch (l->align) {
	case LABEL_ALIGN_LEFT:
		break;
	case LABEL_ALIGN_RIGHT:
		x += l->width - width;
		break;
	case LABEL_ALIGN_CENTER:
		x += (l->width - width)/2;
		break;
	}

	char utf8[7];
	int i;
	struct matrix mat = {{ 1024,0,0,1024,0,y * SCREEN_SCALE}};
	for (i=0; str[i];) {
		int len = unicode_len(str[i]);
		int unicode = copystr(utf8, str+i, len);
		i+=len;
		const struct dfont_rect * rect = dfont_lookup(Dfont, unicode, FONT_SIZE, edge);
		if (rect == NULL) {
			rect = gen_char(unicode,utf8,FONT_SIZE,edge);
			if (rect == NULL)
				continue;
		}
		mat.m[4]=x*SCREEN_SCALE;
		draw_rect(rect,size,&mat,color,0);

		x += (rect->w-1) * size / FONT_SIZE + l->space_w;
	}
}
示例#8
0
int main(int argc, char *argv[])
{
  i64 n;
  CSA SA;

  if (argc<3) {
    fprintf(stderr, "syntax: %s {indexfiles}\n", argv[0]);
    return 1;
  }

  csa_read(&SA,argc-1, argv+1);
  n = SA.n;

#if 0
{
  int i;
  rank_t x;
  unicode_t code;
  uchar buf[6], *p;
  x = SA.inverse(&SA, 0);
  for (i = 0; i < 1000; i++) {
    if (csa_utf8_T_psi(&SA, &x, &code) == -1) {
      printf("???\n");
    }
    p = &buf[0];
    unicode_to_string(&p, code);
    buf[unicode_len(code)] = 0;
    printf("%d code = %d (%s) rank = %ld\n", i, code, &buf[0], x);
  }
  for (i = 0; i < 1000; i++) {
    if (csa_utf8_BW_LF(&SA, &x, &code) == -1) {
      printf("???\n");
    }
    p = &buf[0];
    unicode_to_string(&p, code);
    buf[unicode_len(code)] = 0;
    printf("%d code = %d (%s) rank = %ld\n", i, code, &buf[0], x);
  }
}
#endif

#if 1
{
  int i;
  rank_t x;
  unicode_t code;
  uchar buf[6], *p;
  CSAFILE *csafile;

  csafile = csa_fdopen(&SA, NULL);
  for (i = 0; i < 1000; i++) {
    code = csa_fgetwc(csafile);
    x = csafile->rank;
    p = &buf[0];
    unicode_to_string(&p, code);
    buf[unicode_len(code)] = 0;
    printf("%d code = %d (%s) rank = %ld\n", i, code, &buf[0], x);
  }
  for (i = 0; i < 1000; i++) {
    code = csa_fgetwbw(csafile);
    x = csafile->rank;
    p = &buf[0];
    unicode_to_string(&p, code);
    buf[unicode_len(code)] = 0;
    printf("%d code = %d (%s) rank = %ld\n", i, code, &buf[0], x);
  }
}
#endif

  return 0;
}