提交 8c7481b5 authored 作者: Seven Du's avatar Seven Du 提交者: Anthony Minessale

FS-7506: utf8 support of draw text

上级 20761800
...@@ -2,10 +2,10 @@ include $(top_srcdir)/build/modmake.rulesam ...@@ -2,10 +2,10 @@ include $(top_srcdir)/build/modmake.rulesam
MODNAME=mod_conference MODNAME=mod_conference
mod_LTLIBRARIES = mod_conference.la mod_LTLIBRARIES = mod_conference.la
mod_conference_la_SOURCES = mod_conference.c mod_conference_la_SOURCES = mod_conference.c utf8.c
mod_conference_la_CFLAGS = $(AM_CFLAGS) mod_conference_la_CFLAGS = $(AM_CFLAGS) -I. -I/usr/include/freetype2
mod_conference_la_LIBADD = $(switch_builddir)/libfreeswitch.la mod_conference_la_LIBADD = $(switch_builddir)/libfreeswitch.la
mod_conference_la_LDFLAGS = -avoid-version -module -no-undefined -shared -lyuv mod_conference_la_LDFLAGS = -avoid-version -module -no-undefined -shared -lyuv -lfreetype
if HAVE_OPENAL if HAVE_OPENAL
mod_conference_la_LDFLAGS += -lopenal -lm mod_conference_la_LDFLAGS += -lopenal -lm
......
...@@ -701,6 +701,31 @@ typedef struct layout_group_s { ...@@ -701,6 +701,31 @@ typedef struct layout_group_s {
video_layout_node_t *layouts; video_layout_node_t *layouts;
} layout_group_t; } layout_group_t;
#include "utf8.h"
static const u_int32_t offsetsFromUTF8[6] = {
0x00000000UL, 0x00003080UL, 0x000E2080UL,
0x03C82080UL, 0xFA082080UL, 0x82082080UL
};
/* reads the next utf-8 sequence out of a string, updating an index */
uint32_t get_utf8_char(char *s, int *i)
{
u_int32_t ch = 0;
int sz = 0;
do {
ch <<= 6;
ch += (unsigned char)s[(*i)++];
sz++;
} while (s[*i] && !isutf(s[*i]));
ch -= offsetsFromUTF8[sz-1];
return ch;
}
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include FT_GLYPH_H #include FT_GLYPH_H
...@@ -735,13 +760,13 @@ SWITCH_DECLARE(void) switch_img_draw_text(switch_image_t *img, int x, int y, cha ...@@ -735,13 +760,13 @@ SWITCH_DECLARE(void) switch_img_draw_text(switch_image_t *img, int x, int y, cha
int font_size = 64; int font_size = 64;
double angle; double angle;
int target_height; int target_height;
int n, num_chars; int index = 0;
FT_ULong ch;
switch_yuv_color_t color; switch_yuv_color_t color;
if (zstr(text)) return; if (zstr(text)) return;
switch_color_set(&color, "#FFFFFF"); switch_color_set(&color, "#FFFFFF");
num_chars = strlen(text);
angle = 0; // (45.0 / 360 ) * 3.14159 * 2; angle = 0; // (45.0 / 360 ) * 3.14159 * 2;
target_height = img->d_h; target_height = img->d_h;
...@@ -768,12 +793,14 @@ SWITCH_DECLARE(void) switch_img_draw_text(switch_image_t *img, int x, int y, cha ...@@ -768,12 +793,14 @@ SWITCH_DECLARE(void) switch_img_draw_text(switch_image_t *img, int x, int y, cha
pen.x = x * 64; pen.x = x * 64;
pen.y = (target_height - y) * 64; pen.y = (target_height - y) * 64;
for(n = 0; n < num_chars; n++) { while(*(text + index)) {
ch = get_utf8_char(text, &index);
/* set transformation */ /* set transformation */
FT_Set_Transform(face, &matrix, &pen); FT_Set_Transform(face, &matrix, &pen);
/* load glyph image into the slot (erase previous one) */ /* load glyph image into the slot (erase previous one) */
error = FT_Load_Char(face, text[n], FT_LOAD_RENDER); error = FT_Load_Char(face, ch, FT_LOAD_RENDER);
if (error) continue; if (error) continue;
/* now, draw to our target surface (convert position) */ /* now, draw to our target surface (convert position) */
......
差异被折叠。
#include <stdarg.h>
/* is c the start of a utf8 sequence? */
#define isutf(c) (((c)&0xC0)!=0x80)
/* convert UTF-8 data to wide character */
int u8_toucs(uint32_t *dest, int sz, char *src, int srcsz);
/* the opposite conversion */
int u8_toutf8(char *dest, int sz, uint32_t *src, int srcsz);
/* single character to UTF-8 */
int u8_wc_toutf8(char *dest, uint32_t ch);
/* character number to byte offset */
int u8_offset(char *str, int charnum);
/* byte offset to character number */
int u8_charnum(char *s, int offset);
/* return next character, updating an index variable */
uint32_t u8_nextchar(char *s, int *i);
/* move to next character */
void u8_inc(char *s, int *i);
/* move to previous character */
void u8_dec(char *s, int *i);
/* returns length of next utf-8 sequence */
int u8_seqlen(char *s);
/* assuming src points to the character after a backslash, read an
escape sequence, storing the result in dest and returning the number of
input characters processed */
int u8_read_escape_sequence(char *src, uint32_t *dest);
/* given a wide character, convert it to an ASCII escape sequence stored in
buf, where buf is "sz" bytes. returns the number of characters output.*/
int u8_escape_wchar(char *buf, int sz, uint32_t ch);
/* convert a string "src" containing escape sequences to UTF-8 */
int u8_unescape(char *buf, int sz, char *src);
/* convert UTF-8 "src" to ASCII with escape sequences.
if escape_quotes is nonzero, quote characters will be preceded by
backslashes as well. */
int u8_escape(char *buf, int sz, char *src, int escape_quotes);
/* utility predicates used by the above */
int octal_digit(char c);
int hex_digit(char c);
/* return a pointer to the first occurrence of ch in s, or NULL if not
found. character index of found character returned in *charn. */
char *u8_strchr(char *s, uint32_t ch, int *charn);
/* same as the above, but searches a buffer of a given size instead of
a NUL-terminated string. */
char *u8_memchr(char *s, uint32_t ch, size_t sz, int *charn);
/* count the number of characters in a UTF-8 string */
int u8_strlen(char *s);
int u8_is_locale_utf8(char *locale);
/* printf where the format string and arguments may be in UTF-8.
you can avoid this function and just use ordinary printf() if the current
locale is UTF-8. */
int u8_vprintf(char *fmt, va_list ap);
int u8_printf(char *fmt, ...);
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论