draw border of <p>, <table>, maybe other HTML objects master
authoryu.dongliang <18588496441@163.com>
Fri, 1 May 2026 07:01:38 +0000 (15:01 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 1 May 2026 07:01:44 +0000 (15:01 +0800)
html/abc_css_length.c
html/abc_html.h
ui/abc_layout.c
ui/abc_layout_h1.c
ui/abc_layout_table.c
ui/abc_render_h1.c
ui/abc_render_table.c

index f51c9895fbff7d8ab953709bbba8c234c685dea6..45d2c7e7a676995f4c4fcd79b460dc38e1a51354 100644 (file)
@@ -60,3 +60,39 @@ next:
 
        return x;
 }
 
        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;
+}
index 8d5ea2329bb3280d0587f8c240c8af995d105614..6bfb8f32832965041027c362d5febcdf63108ad7 100644 (file)
@@ -61,4 +61,7 @@ int  abc_css_border(double* r, double* g, double* b, int* width, int* type, abc_
 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_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
 #endif
index a8b33c59a5c975873f2cb85e5ede97c294118258..1dd4fd5a810a5e620c5625995c170982c29685ce 100644 (file)
@@ -163,8 +163,8 @@ int abc_layout_root(abc_ctx_t* abc, abc_obj_t* root, int width, int height)
                        break;
        };
 
                        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;
        int h = 0;
 
        int X = 0;
@@ -185,21 +185,21 @@ int abc_layout_root(abc_ctx_t* abc, abc_obj_t* root, int width, int height)
                        case ABC_HTML_OL:
                        case ABC_HTML_UL:
                        case ABC_HTML_LI:
                        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;
 
                                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:
                                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:
                                y += h;
                                h  = 0;
                        default:
@@ -223,7 +223,7 @@ int abc_layout_root(abc_ctx_t* abc, abc_obj_t* root, int width, int height)
                                } else {
                                        y += h;
 
                                } else {
                                        y += h;
 
-                                       child->x = root->x + 4;
+                                       child->x = root->x + 2;
                                        child->y = y;
 
                                        ret = abc_layout_root(NULL, child, width, height);
                                        child->y = y;
 
                                        ret = abc_layout_root(NULL, child, width, height);
@@ -235,7 +235,7 @@ int abc_layout_root(abc_ctx_t* abc, abc_obj_t* root, int width, int height)
                                }
 
                                if (ABC_HTML_P == child->type && ABC_HTML_P != root->type) {
                                }
 
                                if (ABC_HTML_P == child->type && ABC_HTML_P != root->type) {
-                                       x  = root->x + 4;
+                                       x  = root->x + 2;
                                        y += h;
                                        h  = 0;
                                }
                                        y += h;
                                        h  = 0;
                                }
index c735cdc1b09c11cafac2c9cc52fba30db9a25192..a620318d5f4fb3b110041c61e97eefc52399ba86 100644 (file)
@@ -151,44 +151,56 @@ int abc_layout_h1(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
        cairo_set_font_size  (cr, size);
        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.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->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_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);
 
        cairo_destroy(cr);
        cairo_surface_destroy(surface);
index b877475b21433d1f08701a2dbcbf4d03d0a32452..e240c6b72ff7a1143583abb4f2729380c239e3a8 100644 (file)
@@ -18,33 +18,9 @@ int abc_layout_table(abc_layout_t* layout, abc_obj_t* obj, int width, int height
                }
        }
 
                }
        }
 
-       int w_set = 0;
-       int h_set = 0;
        int d     = abc_css_margin(obj);
        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;
 
        int x = obj->x + d;
        int y = obj->y + d;
index d4b6a50ddc34614641abee934750e7234bf2109e..ed18e6aae2416f0b1a0b29b1215f1bb817560f44 100644 (file)
@@ -1,5 +1,7 @@
 #include"abc.h"
 
 #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 const char* vert_shader =
        "#version 330 core\n"
        "layout(location = 0) in vec4 position; \n"
@@ -169,6 +171,19 @@ int __init_text(cairo_t* cr, abc_obj_t* obj, int num_flag)
 
 static int _render_draw_h1(abc_render_t* render, abc_obj_t* obj, int width, int height)
 {
 
 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);
 
        if (0 == program)
                __init_program(&program, vert_shader, frag_shader);
 
@@ -176,13 +191,13 @@ static int _render_draw_h1(abc_render_t* render, abc_obj_t* obj, int width, int
                __init_buffers(&vao, buffers);
 
        if (0 == texture_rgba)
                __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;
 
 
        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 (!bgra)
                return -ENOMEM;
 
@@ -193,12 +208,12 @@ static int _render_draw_h1(abc_render_t* render, abc_obj_t* obj, int width, int
        if (attr)
                abc_css_color(&r, &g, &b, attr->value->data);
 
        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);
        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);
 
        cairo_fill(cr);
        cairo_stroke(cr);
 
@@ -218,17 +233,17 @@ static int _render_draw_h1(abc_render_t* render, abc_obj_t* obj, int width, int
 
        GLfloat vert_update[] =
        {
 
        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);
        };
 
        glUseProgram(program);
@@ -240,7 +255,7 @@ static int _render_draw_h1(abc_render_t* render, abc_obj_t* obj, int width, int
        // board
        glActiveTexture(GL_TEXTURE0);
        glBindTexture  (GL_TEXTURE_2D, texture_rgba);
        // 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
        glUniform1i(uniform_rgba, 0);
 
        // draw
index 732d3f7fc96b1f33a13d4581fe82131850f41443..bd457f3481c3510bb670c27452713008246669f5 100644 (file)
@@ -64,7 +64,7 @@ static int _render_draw_table(abc_render_t* render, abc_obj_t* obj, int width, i
                __init_buffers(&vao, buffers);
 
        int margin = 0;
                __init_buffers(&vao, buffers);
 
        int margin = 0;
-       int border = 1;
+       int border = 0;
        int border_type = ABC_BORDER_SOLID;
 
        double r0 = 0.0;
        int border_type = ABC_BORDER_SOLID;
 
        double r0 = 0.0;