mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
vgcanvas over picasso draw text works
This commit is contained in:
parent
01b9490a8f
commit
7e6bc3591a
@ -3,7 +3,6 @@
|
||||
//#define ENABLE_LOW_MEMORY 1
|
||||
|
||||
#define ENABLE_SYSTEM_MALLOC 1
|
||||
|
||||
//#define ENABLE_FAST_COPY 1
|
||||
|
||||
#define ENABLE_FORMAT_RGBA 1
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "graphic_helper.h"
|
||||
#include "graphic_base.h"
|
||||
|
||||
#ifndef ENABLE_FREE_TYPE2
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class font_adapter_impl
|
||||
@ -215,3 +217,4 @@ void platform_font_shutdown(void)
|
||||
// win32 do nothing
|
||||
}
|
||||
|
||||
#endif
|
@ -333,6 +333,9 @@ bool _load_fonts(void)
|
||||
load_font_from_fontconfig();
|
||||
#elif defined(__ANDROID__)
|
||||
load_font_from_android();
|
||||
#elif defined(FONT_FILE_NAME)
|
||||
font_item* uni_font = get_font_item("sans", FONT_FILE_NAME);
|
||||
g_font_map.add(uni_font);
|
||||
#else
|
||||
FILE *pf = 0;
|
||||
|
||||
|
10
SConstruct
10
SConstruct
@ -16,7 +16,7 @@ LCD='NANOVG'
|
||||
VGCANVAS='AGG'
|
||||
VGCANVAS='PICASSO'
|
||||
|
||||
COMMON_CCFLAGS=' -DLFTK_ROOT=\\\"'+LFTK_ROOT+'\\\" -DLUA_COMPAT_MODULE -DHAS_STD_MALLOC -DSTBTT_STATIC -DSTB_IMAGE_STATIC -DIMAGE_RGBA -DFT2_BUILD_LIBRARY'
|
||||
COMMON_CCFLAGS=' -DLFTK_ROOT=\\\"'+LFTK_ROOT+'\\\" -DLUA_COMPAT_MODULE -DHAS_STD_MALLOC -DSTBTT_STATIC -DSTB_IMAGE_STATIC -DIMAGE_RGBA'
|
||||
|
||||
if LCD == 'NANOVG':
|
||||
VGCANVAS='NANOVG'
|
||||
@ -47,12 +47,16 @@ OS_LIBS=['SDL2', 'glad', 'stdc++', 'pthread', 'm']
|
||||
if OS_NAME == 'Darwin':
|
||||
OS_LINKFLAGS='-framework OpenGL'
|
||||
COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DLUA_USE_POSIX -D__APPLE__'
|
||||
print("Macos");
|
||||
if VGCANVAS == 'PICASSO':
|
||||
OS_LIBS = ['freetype'] + OS_LIBS
|
||||
COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DENABLE_FREE_TYPE2=1 -DFONT_FILE_NAME=\\\"'+LFTK_ROOT+'/demos/res/raw/fonts/font.ttf\\\"'
|
||||
|
||||
elif OS_NAME == 'Linux':
|
||||
OS_LIBS = ['GL'] + OS_LIBS + ['dl']
|
||||
COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DLUA_USE_POSIX -DLINUX'
|
||||
print("Linux");
|
||||
if VGCANVAS == 'PICASSO':
|
||||
OS_LIBS = ['freetype'] + OS_LIBS
|
||||
COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DENABLE_FREE_TYPE2=1 -DFONT_FILE_NAME=\\\"'+LFTK_ROOT+'/demos/res/raw/fonts/font.ttf\\\"'
|
||||
|
||||
elif OS_NAME == 'Windows':
|
||||
OS_LIBS=['SDL2', 'glad']
|
||||
|
@ -360,12 +360,34 @@ static void draw_matrix(vgcanvas_t* vg) {
|
||||
float_t w = 50;
|
||||
float_t h = 50;
|
||||
|
||||
vgcanvas_save(vg);
|
||||
vgcanvas_translate(vg, w/2, h/2);
|
||||
vgcanvas_rotate(vg, 3.14/4);
|
||||
vgcanvas_translate(vg, -w/2, -h/2);
|
||||
|
||||
vgcanvas_rect(vg, 0, 0, w, h);
|
||||
vgcanvas_fill(vg);
|
||||
vgcanvas_restore(vg);
|
||||
}
|
||||
|
||||
static void draw_text(vgcanvas_t* vg) {
|
||||
float_t h = 20;
|
||||
const char* text = "Hello World";
|
||||
float_t w = 100;
|
||||
|
||||
vgcanvas_set_font_size(vg, 20);
|
||||
vgcanvas_set_font(vg, STR_DEFAULT_FONT);
|
||||
w = vgcanvas_measure_text(vg, text);
|
||||
|
||||
vgcanvas_save(vg);
|
||||
vgcanvas_translate(vg, w/2, h/2);
|
||||
vgcanvas_rotate(vg, 3.14/4);
|
||||
vgcanvas_translate(vg, -w/2, -h/2);
|
||||
|
||||
|
||||
vgcanvas_fill_text(vg, text, 10, 10, 100);
|
||||
log_debug("text=%s w=%u\n", text, w);
|
||||
vgcanvas_restore(vg);
|
||||
}
|
||||
|
||||
static ret_t on_paint_vg(void* ctx, event_t* e) {
|
||||
@ -377,7 +399,6 @@ static ret_t on_paint_vg(void* ctx, event_t* e) {
|
||||
vgcanvas_set_stroke_color(vg, color_init(0, 0xff, 0, 0xff));
|
||||
vgcanvas_set_fill_color(vg, color_init(0xff, 0, 0, 0xff));
|
||||
|
||||
|
||||
draw_basic_shapes(vg, FALSE);
|
||||
vgcanvas_translate(vg, 0, 50);
|
||||
draw_basic_shapes(vg, TRUE);
|
||||
@ -388,6 +409,9 @@ static ret_t on_paint_vg(void* ctx, event_t* e) {
|
||||
|
||||
vgcanvas_translate(vg, 50, 100);
|
||||
draw_matrix(vg);
|
||||
vgcanvas_translate(vg, 0, 100);
|
||||
|
||||
draw_text(vg);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ elif os.environ['VGCANVAS'] == 'AGG':
|
||||
sources += Glob('vgcanvas/vgcanvas_agg.cpp')
|
||||
else:
|
||||
sources += Glob('vgcanvas/vgcanvas_picasso.cpp')
|
||||
sources += Glob('vgcanvas/picasso_font.cpp')
|
||||
|
||||
env=DefaultEnvironment().Clone()
|
||||
env.Library(os.path.join(LIB_DIR, 'lftk'), sources)
|
||||
|
@ -312,13 +312,14 @@ static ret_t vgcanvas_nanovg_set_font(vgcanvas_t* vgcanvas, const char* name) {
|
||||
}
|
||||
|
||||
if (r != NULL && r->subtype == RESOURCE_TYPE_FONT_TTF) {
|
||||
canvas->font_id = nvgCreateFontMem(vg, name, (unsigned char*)r->data, r->size, 0);
|
||||
/*TODO*/
|
||||
font_id = nvgCreateFontMem(vg, name, (unsigned char*)r->data, r->size, 0);
|
||||
}
|
||||
} else {
|
||||
canvas->font_id = font_id;
|
||||
}
|
||||
|
||||
return_value_if_fail(font_id >= 0, RET_FAIL);
|
||||
|
||||
vgcanvas->font = name;
|
||||
canvas->font_id = font_id;
|
||||
nvgFontFaceId(vg, font_id);
|
||||
|
||||
return RET_OK;
|
||||
@ -558,7 +559,6 @@ static ret_t vgcanvas_nanovg_bind_fbo(vgcanvas_t* vgcanvas, framebuffer_object_t
|
||||
|
||||
static ret_t vgcanvas_nanovg_unbind_fbo(vgcanvas_t* vgcanvas, framebuffer_object_t* fbo) {
|
||||
NVGcontext* vg = ((vgcanvas_nanovg_t*)vgcanvas)->vg;
|
||||
NVGLUframebuffer* handle = (NVGLUframebuffer*)fbo->handle;
|
||||
|
||||
nvgEndFrame(vg);
|
||||
nvgluBindFramebuffer(NULL);
|
||||
|
@ -206,7 +206,7 @@ static ret_t vgcanvas_picasso_arc(vgcanvas_t* vgcanvas, float_t x, float_t y, fl
|
||||
ps_point cp = ps_point_init(x, y);
|
||||
ps_context* vg = ((vgcanvas_picasso_t*)vgcanvas)->vg;
|
||||
|
||||
ps_arc(vg, &cp, r, start, end, ccw);
|
||||
ps_arc(vg, &cp, r, start, end, !ccw);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -422,26 +422,24 @@ static ret_t vgcanvas_picasso_set_text_baseline(vgcanvas_t* vgcanvas, const char
|
||||
|
||||
static ret_t vgcanvas_picasso_fill_text(vgcanvas_t* vgcanvas, const char* text, float_t x, float_t y,
|
||||
float_t max_width) {
|
||||
ps_color color = ps_color_init(vgcanvas->fill_color);
|
||||
ps_context* vg = ((vgcanvas_picasso_t*)vgcanvas)->vg;
|
||||
(void)vg;
|
||||
(void)text;
|
||||
(void)x;
|
||||
(void)y;
|
||||
(void)max_width;
|
||||
|
||||
/*TODO*/
|
||||
ps_set_text_color(vg, &color);
|
||||
ps_text_out_length(vg, x, y, text, strlen(text));
|
||||
|
||||
(void)max_width;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static uint32_t vgcanvas_picasso_measure_text(vgcanvas_t* vgcanvas, const char* text) {
|
||||
ps_size size = {0, 0};
|
||||
ps_context* vg = ((vgcanvas_picasso_t*)vgcanvas)->vg;
|
||||
(void)vg;
|
||||
(void)text;
|
||||
|
||||
ps_get_text_extent(vg, text, strlen(text), &size);
|
||||
|
||||
/*TODO*/
|
||||
|
||||
return RET_OK;
|
||||
return size.w;
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_picasso_draw_image(vgcanvas_t* vgcanvas, bitmap_t* img, float_t sx, float_t sy,
|
||||
|
Loading…
Reference in New Issue
Block a user