return x;
}
+
+int abc_css_width(abc_obj_t* obj, int width, int margin)
+{
+ abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_WIDTH);
+
+ if (attr && attr->value && attr->value->len > 0) {
+
+ obj->w = abc_css_length(obj, attr->value->data, width);
+ obj->w += margin * 2;
+
+ if (obj->w > width - obj->x)
+ obj->w = width - obj->x;
+ return 1;
+ }
+
+ obj->w = width - obj->x;
+ return 0;
+}
+
+int abc_css_height(abc_obj_t* obj, int height, int margin)
+{
+ abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HEIGHT);
+
+ if (attr && attr->value && attr->value->len > 0) {
+
+ obj->h = abc_css_length(obj, attr->value->data, height);
+ obj->h += margin * 2;
+
+ if (obj->h > height - obj->y)
+ obj->h = height - obj->y;
+ return 1;
+ }
+
+ obj->h = height - obj->y;
+ return 0;
+}
int abc_css_margin(abc_obj_t* obj);
int abc_css_length(abc_obj_t* obj, const uint8_t* str, int len);
+int abc_css_width (abc_obj_t* obj, int width, int margin);
+int abc_css_height(abc_obj_t* obj, int height, int margin);
+
#endif
break;
};
- int x = root->x + 4;
- int y = root->y + 4;
+ int x = root->x + 2;
+ int y = root->y + 2;
int h = 0;
int X = 0;
case ABC_HTML_OL:
case ABC_HTML_UL:
case ABC_HTML_LI:
- child->x = root->x + 4;
+ child->x = root->x + 2;
child->y = y + h;
ret = abc_layout_root(NULL, child, width, height);
if (ret < 0)
return ret;
- x = root->x + 4;
+ x = root->x + 2;
y = child->y + child->h;
h = 0;
break;
case ABC_HTML_BR:
case ABC_HTML_TR:
- x = root->x + 4;
+ x = root->x + 2;
y += h;
h = 0;
default:
} else {
y += h;
- child->x = root->x + 4;
+ child->x = root->x + 2;
child->y = y;
ret = abc_layout_root(NULL, child, width, height);
}
if (ABC_HTML_P == child->type && ABC_HTML_P != root->type) {
- x = root->x + 4;
+ x = root->x + 2;
y += h;
h = 0;
}
cairo_set_font_size (cr, size);
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
- int ret = __layout_text(&extents, cr, obj, width);
- if (ret < 0)
- scf_loge("ret: %d\n", ret);
+ int d = abc_css_margin(obj);
+ int w_set = abc_css_width (obj, width, d);
+ int h_set = abc_css_height(obj, height, d);
+
+ int dw = 0;
+ switch (obj->parent->type) {
+ case ABC_HTML_OL:
+ if (0 == obj->parent->padding) {
+ scf_string_t* s = abc_ol_list_style(obj->parent, obj->parent->n_childs);
+ if (s) {
+ cairo_text_extents(cr, s->data, &extents2);
+
+ obj->parent->padding = extents2.width + extents2.x_bearing + size / 2;
+
+ scf_string_free(s);
+ s = NULL;
+ }
+ }
- int w = 0;
- if (ABC_HTML_OL == obj->parent->type)
- {
- if (0 == obj->parent->padding) {
- scf_string_t* s = abc_ol_list_style(obj->parent, obj->parent->n_childs);
- if (s) {
- cairo_text_extents(cr, s->data, &extents2);
+ dw = obj->parent->padding;
+ break;
- obj->parent->padding = extents2.width + extents2.x_bearing + size / 2;
+ case ABC_HTML_UL:
+ dw = size;
+ obj->parent->padding = size;
+ break;
+ default:
+ break;
+ };
- scf_string_free(s);
- s = NULL;
- }
- }
+ int w = (width - d * 2 - dw) / size * size;
- obj->y_bearing = extents.y_bearing;
+ int ret = __layout_text(&extents, cr, obj, w);
+ if (ret < 0)
+ scf_loge("ret: %d\n", ret);
- w = obj->parent->padding;
- } else if (ABC_HTML_UL == obj->parent->type) {
- w = size;
- obj->parent->padding = size;
- }
+ if (ABC_HTML_OL == obj->parent->type)
+ obj->y_bearing = extents.y_bearing;
- w += extents.width + extents.x_bearing;
+ w = extents.width + extents.x_bearing + d * 2 + dw;
obj->w = w;
- obj->h = extents.height + extents.height / 2;
- obj->w = (obj->w + 3) & ~0x3;
- obj->h = (obj->h + 3) & ~0x3;
+ obj->h = extents.height + extents.height / 2 + d * 2;
+// obj->w = (obj->w + 3) & ~0x3;
+// obj->h = (obj->h + 3) & ~0x3;
- scf_logi("%s, w: %d, h: %d, x_bearing: %lg, y_bearing: %lg, width: %lg, height: %lg, x_advance: %lg, y_advance: %lg\n",
- obj->text->data, obj->w, obj->h,
+ scf_logd("%s, w: %d, h: %d, d: %d, x_bearing: %lg, y_bearing: %lg, width: %lg, height: %lg, x_advance: %lg, y_advance: %lg, width: %d, height: %d\n",
+ obj->text->data, obj->w, obj->h, d,
extents.x_bearing, extents.y_bearing, extents.width, extents.height,
- extents.x_advance, extents.y_advance);
+ extents.x_advance, extents.y_advance, width, height);
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
}
- int w_set = 0;
- int h_set = 0;
int d = abc_css_margin(obj);
-
- attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_WIDTH);
- if (attr && attr->value && attr->value->len > 0)
- {
- obj->w = abc_css_length(obj, attr->value->data, width);
- obj->w += d * 2;
-
- if (obj->w > width - obj->x)
- obj->w = width - obj->x;
-
- w_set = 1;
- }
-
- attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HEIGHT);
- if (attr && attr->value && attr->value->len > 0)
- {
- obj->h = abc_css_length(obj, attr->value->data, height);
- obj->h += d * 2;
-
- if (obj->h > height - obj->y)
- obj->h = height - obj->y;
-
- h_set = 1;
- }
+ int w_set = abc_css_width (obj, width, d);
+ int h_set = abc_css_height(obj, height, d);
int x = obj->x + d;
int y = obj->y + d;
#include"abc.h"
+extern abc_render_t abc_render_table;
+
static const char* vert_shader =
"#version 330 core\n"
"layout(location = 0) in vec4 position; \n"
static int _render_draw_h1(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
+ if (obj->w <= 0 || obj->h <= 0)
+ return 0;
+
+ abc_render_table.draw(&abc_render_table, obj, width, height);
+
+ int d = abc_css_margin(obj);
+ int x = obj->x + d;
+ int y = obj->y + d;
+ int w = obj->w - d * 2;
+ int h = obj->h - d * 2;
+
+ scf_logd("obj->type: %d, obj->w: %d, obj->h: %d, w: %d, h: %d, d: %d\n", obj->type, obj->w, obj->h, w, h, d);
+
if (0 == program)
__init_program(&program, vert_shader, frag_shader);
__init_buffers(&vao, buffers);
if (0 == texture_rgba)
- __init_texture(&texture_rgba, GL_RGBA, obj->w, obj->h, NULL);
+ __init_texture(&texture_rgba, GL_RGBA, w, h, NULL);
abc_obj_t* attr;
cairo_surface_t* surface;
cairo_t* cr;
- uint8_t* bgra = calloc(1, obj->w * obj->h * 4);
+ uint8_t* bgra = calloc(1, w * h * 4);
if (!bgra)
return -ENOMEM;
if (attr)
abc_css_color(&r, &g, &b, attr->value->data);
- surface = cairo_image_surface_create_for_data(bgra, CAIRO_FORMAT_ARGB32, obj->w, obj->h, obj->w * 4);
+ surface = cairo_image_surface_create_for_data(bgra, CAIRO_FORMAT_ARGB32, w, h, w * 4);
cr = cairo_create(surface);
cairo_set_line_width(cr, 1);
cairo_set_source_rgb(cr, r, g, b);
- cairo_rectangle(cr, 0, 0, obj->w, obj->h);
+ cairo_rectangle(cr, 0, 0, w, h);
cairo_fill(cr);
cairo_stroke(cr);
GLfloat vert_update[] =
{
- 2.0 * obj->x / (float)width - 1.0,
- -2.0 * (obj->y + obj->h) / (float)height + 1.0,
+ 2.0 * x / (float)width - 1.0,
+ -2.0 * (y + h) / (float)height + 1.0,
- 2.0 * (obj->x + obj->w) / (float)width - 1.0,
- -2.0 * (obj->y + obj->h) / (float)height + 1.0,
+ 2.0 * (x + w) / (float)width - 1.0,
+ -2.0 * (y + h) / (float)height + 1.0,
- 2.0 * obj->x / (float)width - 1.0,
- -2.0 * obj->y / (float)height + 1.0,
+ 2.0 * x / (float)width - 1.0,
+ -2.0 * y / (float)height + 1.0,
- 2.0 * (obj->x + obj->w) / (float)width - 1.0,
- -2.0 * obj->y / (float)height + 1.0,
+ 2.0 * (x + w) / (float)width - 1.0,
+ -2.0 * y / (float)height + 1.0,
};
glUseProgram(program);
// board
glActiveTexture(GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, texture_rgba);
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, obj->w, obj->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bgra);
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bgra);
glUniform1i(uniform_rgba, 0);
// draw
__init_buffers(&vao, buffers);
int margin = 0;
- int border = 1;
+ int border = 0;
int border_type = ABC_BORDER_SOLID;
double r0 = 0.0;