Changeset 4764
- Timestamp:
- 02/06/11 20:22:33 (2 years ago)
- Location:
- gaycko/trunk/src/render
- Files:
-
- 3 edited
-
position.c (modified) (2 diffs)
-
renderer.c (modified) (2 diffs)
-
table.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gaycko/trunk/src/render/position.c
r4763 r4764 15 15 void gaycko_get_position(gNode *node, gNode *parent) { 16 16 unsigned int c = 0; 17 unsigned int w = 0; 18 unsigned int h = 0; 19 unsigned int x = node->properties->x; 20 unsigned int y = node->properties->y; 21 22 for(c = 0; c < node->children_count; c++) { 23 node->children[c]->properties->x = x; 24 node->children[c]->properties->y = y; 25 switch(node->children[c]->type) { 26 case ELEM_TABLE: 27 gaycko_get_position(node->children[c], parent); 28 x+=node->children[c]->properties->width; 29 30 gaycko_fix_table(node->children[c]); 31 if(node->children[c]->properties->width>w) { 32 w = (node->children[c]->properties->width); 33 } 34 break; 35 36 case ELEM_TR: 37 gaycko_get_position(node->children[c], parent); 38 node->children[c]->properties->height+=1; 39 x = 0; 40 w+=node->children[c]->properties->width+1; 41 break; 42 43 case ELEM_TD: 44 gaycko_get_position(node->children[c], parent); 45 x+=node->children[c]->properties->width; 46 if(node->children[c]->properties->width>w) { 47 w = (node->children[c]->properties->width); 48 } 49 break; 50 51 case ELEM_BR: 52 node->children[c]->properties->height+=1; 53 x = 0; 54 w+=node->children[c]->properties->width+1; 55 break; 56 57 case ELEM_HR: 58 node->children[c]->properties->height+=1; 59 x = 0; 60 w+=node->children[c]->properties->width+1; 61 break; 62 63 case ELEM_H1: 64 case ELEM_H2: 65 case ELEM_H3: 66 node->children[c]->properties->height+=1; 67 x = 0; 68 w+=node->children[c]->properties->width+1; 69 break; 70 71 72 case ELEM_TEXT: 73 if(parent && 74 (parent->type!=ELEM_TR && parent->type!=ELEM_TABLE)) { 75 if(node->children[c]->text) { 76 node->children[c]->properties->width = strlen(node->children[c]->text); 77 } else { 78 node->children[c]->properties->width = 0; 79 } 80 } else { 81 node->children[c]->properties->width = 0; 82 node->children[c]->properties->height = 0; 83 } 84 x+=node->children[c]->properties->width; 85 if(node->children[c]->properties->width>w) { 86 w = (node->children[c]->properties->width); 87 } 88 break; 89 90 91 default: 92 gaycko_get_position(node->children[c], node); 93 x+=node->children[c]->properties->width; 94 if(node->children[c]->properties->width>w) { 95 w = (node->children[c]->properties->width); 96 } 97 98 break; 99 } 17 unsigned int w = 0; 18 unsigned int h = 0; 19 unsigned int x = node->properties->x; 20 unsigned int y = node->properties->y; 100 21 101 y+=node->children[c]->properties->height; 102 h+=node->children[c]->properties->height; 103 } 104 105 node->properties->width = w; 106 node->properties->height = h; 22 for(c = 0; c < node->children_count; c++) { 23 node->children[c]->properties->x = x; 24 node->children[c]->properties->y = y; 25 switch(node->children[c]->type) { 26 case ELEM_TABLE: 27 gaycko_get_position(node->children[c], parent); 28 x+=node->children[c]->properties->width; 29 30 gaycko_fix_table(node->children[c]); 31 if(node->children[c]->properties->width>w) { 32 w = (node->children[c]->properties->width); 33 } 34 break; 35 36 case ELEM_TR: 37 gaycko_get_position(node->children[c], parent); 38 node->children[c]->properties->height+=1; 39 x = 0; 40 w+=node->children[c]->properties->width+1; 41 break; 42 43 case ELEM_TD: 44 gaycko_get_position(node->children[c], parent); 45 x+=node->children[c]->properties->width; 46 if(node->children[c]->properties->width>w) { 47 w = (node->children[c]->properties->width); 48 } 49 break; 50 51 case ELEM_BR: 52 node->children[c]->properties->height+=1; 53 x = 0; 54 w+=node->children[c]->properties->width+1; 55 break; 56 57 case ELEM_HR: 58 node->children[c]->properties->height+=1; 59 x = 0; 60 w+=node->children[c]->properties->width+1; 61 break; 62 63 case ELEM_H1: 64 case ELEM_H2: 65 case ELEM_H3: 66 node->children[c]->properties->height+=1; 67 x = 0; 68 w+=node->children[c]->properties->width+1; 69 break; 70 71 72 case ELEM_TEXT: 73 if(parent && 74 (parent->type!=ELEM_TR && parent->type!=ELEM_TABLE)) { 75 if(node->children[c]->text) { 76 node->children[c]->properties->width = strlen(node->children[c]->text); 77 } else { 78 node->children[c]->properties->width = 0; 79 } 80 } else { 81 node->children[c]->properties->width = 0; 82 node->children[c]->properties->height = 0; 83 } 84 x+=node->children[c]->properties->width; 85 if(node->children[c]->properties->width>w) { 86 w = (node->children[c]->properties->width); 87 } 88 break; 89 90 91 default: 92 gaycko_get_position(node->children[c], node); 93 x+=node->children[c]->properties->width; 94 if(node->children[c]->properties->width>w) { 95 w = (node->children[c]->properties->width); 96 } 97 98 break; 99 } 100 101 y+=node->children[c]->properties->height; 102 h+=node->children[c]->properties->height; 103 } 104 105 node->properties->width = w; 106 node->properties->height = h; 107 107 } 108 108 … … 110 110 void gaycko_add_node_x(gNode *node, unsigned int add) { 111 111 112 unsigned int e = 0;113 for(e = 0 ; e < node->children_count; e++) {114 gaycko_add_node_x(node->children[e], add);115 }116 node->properties->x += add;117 112 unsigned int e = 0; 113 for(e = 0 ; e < node->children_count; e++) { 114 gaycko_add_node_x(node->children[e], add); 115 } 116 node->properties->x += add; 117 118 118 } 119 119 -
gaycko/trunk/src/render/renderer.c
r4760 r4764 14 14 void gaycko_render(gWindow *window) { 15 15 window->dom->root->properties->width = window->width; 16 gaycko_get_position(window->dom->root, NULL);17 caca_set_canvas_size(window->cv,18 window->dom->root->properties->width,19 window->dom->root->properties->height);20 gaycko_print_dom(window);16 gaycko_get_position(window->dom->root, NULL); 17 caca_set_canvas_size(window->cv, 18 window->dom->root->properties->width, 19 window->dom->root->properties->height); 20 gaycko_print_dom(window); 21 21 } 22 22 … … 28 28 void gaycko_print_node(gNode *node, gWindow *window) { 29 29 unsigned int c = 0; 30 31 switch(node->type) {30 31 switch(node->type) { 32 32 case ELEM_TEXT: 33 caca_set_color_argb(window->cv, 0, 0xFFFF);34 caca_put_str(window->cv, node->properties->x, node->properties->y, node->text);35 break;36 case ELEM_HR:33 caca_set_color_argb(window->cv, 0, 0xFFFF); 34 caca_put_str(window->cv, node->properties->x, node->properties->y, node->text); 35 break; 36 case ELEM_HR: 37 37 caca_draw_line(window->cv, 38 node->properties->x, node->properties->y,39 node->properties->x+node->parent->properties->width, node->properties->y,40 '-');41 printf("Line parent is '%s', width %d\n", node->parent->name, node->parent->properties->width);42 break;43 default:44 45 break;38 node->properties->x, node->properties->y, 39 node->properties->x+node->parent->properties->width, node->properties->y, 40 '-'); 41 printf("Line parent is '%s', width %d\n", node->parent->name, node->parent->properties->width); 42 break; 43 default: 44 45 break; 46 46 } 47 48 for(c = 0; c < node->children_count; c++) {49 gaycko_print_node(node->children[c], window);50 }47 48 for(c = 0; c < node->children_count; c++) { 49 gaycko_print_node(node->children[c], window); 50 } 51 51 } -
gaycko/trunk/src/render/table.c
r4762 r4764 13 13 #include "renderer.h" 14 14 void gaycko_fix_table(gNode *table) { 15 unsigned int tr = 0;16 unsigned int e = 0;17 gNode *last_tr = NULL;18 table->specific.table->tr_count = 0;19 20 /* Count TD by TR, and TR by TABLE */21 for(tr = 0 ; tr < table->children_count; tr++) {22 if(table->children[tr]->type == ELEM_TR) {23 gaycko_fix_tr(table->children[tr]);24 table->specific.table->tr_count++;25 last_tr = table->children[tr];26 }27 }28 29 /* Scan TD's and set each correspondants to the max width */30 unsigned int td = 0;31 32 for(td = 0; td < last_tr->specific.tr->td_count; td++) {33 unsigned int biggest_td = 0;34 35 /* Find widest at a given X offset */36 for(e = 0 ; e < table->children_count; e++) {37 if(table->children[e]->type == ELEM_TR) {38 unsigned int td_width = gaycko_get_trtd_width(table->children[e], td);39 if(biggest_td < td_width) {40 biggest_td = td_width;41 }42 }43 }44 /* Set the others's width to the widest one */45 for(e = 0 ; e < table->children_count; e++) {46 if(table->children[e]->type == ELEM_TR) {47 gaycko_set_trtd_width(table->children[e], td, biggest_td);48 }49 }50 }51 52 table->properties->width = gaycko_get_tr_width(last_tr);53 printf("Table %d wide\n", table->properties->width);54 15 unsigned int tr = 0; 16 unsigned int e = 0; 17 gNode *last_tr = NULL; 18 table->specific.table->tr_count = 0; 19 20 /* Count TD by TR, and TR by TABLE */ 21 for(tr = 0 ; tr < table->children_count; tr++) { 22 if(table->children[tr]->type == ELEM_TR) { 23 gaycko_fix_tr(table->children[tr]); 24 table->specific.table->tr_count++; 25 last_tr = table->children[tr]; 26 } 27 } 28 29 /* Scan TD's and set each correspondants to the max width */ 30 unsigned int td = 0; 31 32 for(td = 0; td < last_tr->specific.tr->td_count; td++) { 33 unsigned int biggest_td = 0; 34 35 /* Find widest at a given X offset */ 36 for(e = 0 ; e < table->children_count; e++) { 37 if(table->children[e]->type == ELEM_TR) { 38 unsigned int td_width = gaycko_get_trtd_width(table->children[e], td); 39 if(biggest_td < td_width) { 40 biggest_td = td_width; 41 } 42 } 43 } 44 /* Set the others's width to the widest one */ 45 for(e = 0 ; e < table->children_count; e++) { 46 if(table->children[e]->type == ELEM_TR) { 47 gaycko_set_trtd_width(table->children[e], td, biggest_td); 48 } 49 } 50 } 51 52 table->properties->width = gaycko_get_tr_width(last_tr); 53 printf("Table %d wide\n", table->properties->width); 54 55 55 } 56 56 … … 58 58 59 59 unsigned int gaycko_get_tr_width(gNode *tr) { 60 unsigned int w = 0, td = 0;61 62 for(td = 0 ; td < tr->children_count; td++) {63 if(tr->children[td]->type == ELEM_TD) {64 unsigned int tw = gaycko_get_node_width(tr->children[td]);65 w += tw;66 printf("TD width %d\n", tw);67 }68 }69 printf("So TR width %d\n", w);70 return w;60 unsigned int w = 0, td = 0; 61 62 for(td = 0 ; td < tr->children_count; td++) { 63 if(tr->children[td]->type == ELEM_TD) { 64 unsigned int tw = gaycko_get_node_width(tr->children[td]); 65 w += tw; 66 printf("TD width %d\n", tw); 67 } 68 } 69 printf("So TR width %d\n", w); 70 return w; 71 71 } 72 72 73 73 unsigned int gaycko_get_node_width(gNode *td) { 74 unsigned int e = 0;74 unsigned int e = 0; 75 75 unsigned int w = 0; 76 for(e = 0 ; e < td->children_count; e++) {77 w+=td->properties->width;78 }79 return w;76 for(e = 0 ; e < td->children_count; e++) { 77 w+=td->properties->width; 78 } 79 return w; 80 80 } 81 81 82 82 83 83 void gaycko_fix_tr(gNode *tr) { 84 unsigned int td = 0;85 tr->specific.tr->td_count = 0;86 87 for(td = 0 ; td < tr->children_count; td++) {88 if(tr->children[td]->type == ELEM_TD) {89 tr->specific.tr->td_count++;90 }91 }84 unsigned int td = 0; 85 tr->specific.tr->td_count = 0; 86 87 for(td = 0 ; td < tr->children_count; td++) { 88 if(tr->children[td]->type == ELEM_TD) { 89 tr->specific.tr->td_count++; 90 } 91 } 92 92 } 93 93 94 94 unsigned int gaycko_get_trtd_width(gNode *tr, unsigned int td_index) { 95 unsigned int e = 0;96 unsigned int td = 0;97 for(e = 0 ; e < tr->children_count; e++) {98 if(tr->children[e]->type == ELEM_TD) {99 if(td == td_index) return tr->children[e]->properties->width;100 td++;101 }102 }103 return 0;95 unsigned int e = 0; 96 unsigned int td = 0; 97 for(e = 0 ; e < tr->children_count; e++) { 98 if(tr->children[e]->type == ELEM_TD) { 99 if(td == td_index) return tr->children[e]->properties->width; 100 td++; 101 } 102 } 103 return 0; 104 104 } 105 105 106 106 void gaycko_set_trtd_width(gNode *tr, unsigned td_index, unsigned int width) { 107 unsigned int e = 0;108 unsigned int td = 0;109 unsigned int add_width = 0;110 111 for(e = 0 ; e < tr->children_count; e++) {112 if(tr->children[e]->type == ELEM_TD) {113 if(td == td_index) {114 add_width = width - tr->children[e]->properties->width;115 }116 td++;117 }118 }107 unsigned int e = 0; 108 unsigned int td = 0; 109 unsigned int add_width = 0; 110 111 for(e = 0 ; e < tr->children_count; e++) { 112 if(tr->children[e]->type == ELEM_TD) { 113 if(td == td_index) { 114 add_width = width - tr->children[e]->properties->width; 115 } 116 td++; 117 } 118 } 119 119 td = 0; 120 for(e = 0 ; e < tr->children_count; e++) {121 if(tr->children[e]->type == ELEM_TD) {122 if(td == td_index) {123 124 } else if(td > td_index){125 tr->children[e]->properties->width = width;126 gaycko_add_node_x(tr->children[e], add_width);127 }128 td++;129 }130 }131 132 120 for(e = 0 ; e < tr->children_count; e++) { 121 if(tr->children[e]->type == ELEM_TD) { 122 if(td == td_index) { 123 124 } else if(td > td_index){ 125 tr->children[e]->properties->width = width; 126 gaycko_add_node_x(tr->children[e], add_width); 127 } 128 td++; 129 } 130 } 131 132 133 133 } 134 134
Note: See TracChangeset
for help on using the changeset viewer.
