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; } }
static void window_redraw(Window *w, Graphics *g) { Rect r; Point p; int l, h; int length; char *buffer; assert(lines != NULL); /* Each wide char is encoded in at most 6 UTF8 characters. For the Base Plane, * 3 UTF8 characters per Unicode character is enough */ buffer = malloc((6 * NUM_COLUMNS + 1) * sizeof(char)); if (buffer != NULL) { r = get_window_area(w); set_rgb(g, rgb(240,240,240)); //??? attrib fill_rect(g, r); set_rgb(g, rgb(0,0,0)); //??? attrib set_font(g, font); set_text_direction(g, LR_TB); p = pt(0,0); h = font_height(font); for (l = 0; l < NUM_LINES; l++) { #if defined _UNICODE /* convert the line to UTF8 */ int c; char *ptr; for (c = 0, ptr = buffer; c < NUM_COLUMNS; c++) amx_UTF8Put(ptr, &ptr, 6, lines + l * NUM_COLUMNS + c); *ptr = '\0'; length = (int)(ptr - buffer); #else /* assume line is ASCII */ memcpy(buffer, lines + l * NUM_COLUMNS, NUM_COLUMNS); buffer[NUM_COLUMNS] = '\0'; length = NUM_COLUMNS; #endif /* draw the line */ draw_utf8(g, p, buffer, length); p.y += h; if (p.y > r.height) break; } /* if */ free(buffer); } /* if */ }
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; }