📄 agg_gsv_text.cpp
字号:
0x04,0x00,0x01,0x7e,0x01,0x7d,0x00,0x76,0x00,0x8a,
0x01,0x03,0x02,0x02,0x03,0x00,0x02,0x7e,0x01,0x7d,
0x00,0x76,0x03,0x80,0x03,0x8f,0x00,0x74,0x01,0x7e,
0x02,0x7f,0x04,0x00,0x02,0x01,0x01,0x01,0x00,0x8d,
0x00,0x6e,0xff,0x7e,0xfe,0x7f,0xfb,0x00,0xfe,0x01,
0x0c,0x85,0x03,0x8d,0x01,0x02,0x03,0x00,0x02,0x7e,
0x01,0x02,0x03,0x00,0x02,0x7e,0x00,0x74,0xfe,0x7f,
0xfd,0x00,0xff,0x01,0xfe,0x7f,0xfd,0x00,0xff,0x01,
0x00,0x0c,0x06,0x82,0x00,0x6b,0x08,0x86,0x03,0x80,
0x0a,0x0f,0xf6,0x80,0x0a,0x71,0x03,0x80,0x03,0x8f,
0x00,0x73,0x01,0x7e,0x07,0x00,0x02,0x02,0x00,0x0d,
0x00,0xf3,0x01,0x7e,0x00,0x7e,0x03,0x82,0x03,0x8f,
0x00,0x79,0x02,0x7e,0x08,0x00,0x00,0x89,0x00,0x71,
0x02,0x80,0x03,0x8f,0x00,0x73,0x01,0x7e,0x03,0x00,
0x02,0x02,0x00,0x0d,0x00,0xf3,0x01,0x7e,0x03,0x00,
0x02,0x02,0x00,0x0d,0x00,0xf3,0x01,0x7e,0x03,0x80,
0x03,0x8f,0x00,0x73,0x01,0x7e,0x03,0x00,0x02,0x02,
0x00,0x0d,0x00,0xf3,0x01,0x7e,0x03,0x00,0x02,0x02,
0x00,0x0d,0x00,0xf3,0x01,0x7e,0x00,0x7e,0x03,0x82,
0x03,0x8d,0x00,0x02,0x02,0x00,0x00,0x71,0x08,0x00,
0x02,0x02,0x00,0x06,0xfe,0x02,0xf8,0x00,0x0c,0xf6,
0x03,0x8f,0x00,0x71,0x07,0x00,0x02,0x02,0x00,0x06,
0xfe,0x02,0xf9,0x00,0x0c,0x85,0x00,0x71,0x02,0x80,
0x03,0x8f,0x00,0x71,0x07,0x00,0x03,0x02,0x00,0x06,
0xfd,0x02,0xf9,0x00,0x0c,0xf6,0x03,0x8d,0x02,0x02,
0x06,0x00,0x02,0x7e,0x00,0x75,0xfe,0x7e,0xfa,0x00,
0xfe,0x02,0x04,0x85,0x06,0x00,0x02,0xf9,0x03,0x80,
0x00,0x0f,0x00,0xf8,0x04,0x00,0x00,0x06,0x02,0x02,
0x04,0x00,0x02,0x7e,0x00,0x75,0xfe,0x7e,0xfc,0x00,
0xfe,0x02,0x00,0x05,0x0a,0xf9,0x0d,0x80,0x00,0x0f,
0xf7,0x00,0xff,0x7e,0x00,0x7b,0x01,0x7e,0x09,0x00,
0xf6,0xfa,0x04,0x06,0x08,0xfa
};
//-------------------------------------------------------------------------
gsv_text::gsv_text() :
m_x(0.0),
m_y(0.0),
m_start_x(0.0),
m_width(10.0),
m_height(0.0),
m_space(0.0),
m_line_space(0.0),
m_text(m_chr),
m_text_buf(),
m_cur_chr(m_chr),
m_font(gsv_default_font),
m_loaded_font(),
m_status(initial),
m_big_endian(false),
m_flip(false)
{
m_chr[0] = m_chr[1] = 0;
int t = 1;
if(*(char*)&t == 0) m_big_endian = true;
}
//-------------------------------------------------------------------------
void gsv_text::font(const void* font)
{
m_font = font;
if(m_font == 0) m_font = &m_loaded_font[0];
}
//-------------------------------------------------------------------------
void gsv_text::size(double height, double width)
{
m_height = height;
m_width = width;
}
//-------------------------------------------------------------------------
void gsv_text::space(double space)
{
m_space = space;
}
//-------------------------------------------------------------------------
void gsv_text::line_space(double line_space)
{
m_line_space = line_space;
}
//-------------------------------------------------------------------------
void gsv_text::start_point(double x, double y)
{
m_x = m_start_x = x;
m_y = y;
//if(m_flip) m_y += m_height;
}
//-------------------------------------------------------------------------
void gsv_text::load_font(const char* file)
{
m_loaded_font.resize(0);
FILE* fd = fopen(file, "rb");
if(fd)
{
unsigned len;
fseek(fd, 0l, SEEK_END);
len = ftell(fd);
fseek(fd, 0l, SEEK_SET);
if(len > 0)
{
m_loaded_font.resize(len);
fread(&m_loaded_font[0], 1, len, fd);
m_font = &m_loaded_font[0];
}
fclose(fd);
}
}
//-------------------------------------------------------------------------
void gsv_text::text(const char* text)
{
if(text == 0)
{
m_chr[0] = 0;
m_text = m_chr;
return;
}
unsigned new_size = strlen(text) + 1;
if(new_size > m_text_buf.size())
{
m_text_buf.resize(new_size);
}
memcpy(&m_text_buf[0], text, new_size);
m_text = &m_text_buf[0];
}
//-------------------------------------------------------------------------
void gsv_text::rewind(unsigned)
{
m_status = initial;
if(m_font == 0) return;
m_indices = (int8u*)m_font;
double base_height = value(m_indices + 4);
m_indices += value(m_indices);
m_glyphs = (int8*)(m_indices + 257*2);
m_h = m_height / base_height;
m_w = (m_width == 0.0) ? m_h : m_width / base_height;
if(m_flip) m_h = -m_h;
m_cur_chr = m_text;
}
//-------------------------------------------------------------------------
unsigned gsv_text::vertex(double* x, double* y)
{
unsigned idx;
int8 yc, yf;
int dx, dy;
bool quit = false;
while(!quit)
{
switch(m_status)
{
case initial:
if(m_font == 0)
{
quit = true;
break;
}
m_status = next_char;
case next_char:
if(*m_cur_chr == 0)
{
quit = true;
break;
}
idx = (*m_cur_chr++) & 0xFF;
if(idx == '\n')
{
m_x = m_start_x;
m_y -= m_flip ? -m_height - m_line_space : m_height + m_line_space;
break;
}
idx <<= 1;
m_bglyph = m_glyphs + value(m_indices + idx);
m_eglyph = m_glyphs + value(m_indices + idx + 2);
m_status = start_glyph;
case start_glyph:
*x = m_x;
*y = m_y;
m_status = glyph;
return path_cmd_move_to;
case glyph:
if(m_bglyph >= m_eglyph)
{
m_status = next_char;
m_x += m_space;
break;
}
dx = int(*m_bglyph++);
yf = (yc = *m_bglyph++) & 0x80;
yc <<= 1;
yc >>= 1;
dy = int(yc);
m_x += double(dx) * m_w;
m_y += double(dy) * m_h;
*x = m_x;
*y = m_y;
return yf ? path_cmd_move_to : path_cmd_line_to;
}
}
return path_cmd_stop;
}
//-------------------------------------------------------------------------
double gsv_text::text_width()
{
double x1, y1, x2, y2;
bounding_rect_single(*this, 0, &x1, &y1, &x2, &y2);
return x2 - x1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -