source: gaycko/trunk/src/render/table.c @ 4761

Last change on this file since 4761 was 4761, checked in by Jean-Yves Lamoureux, 9 years ago
  • Moved table's stuff to render/table.c
File size: 2.7 KB
Line 
1/*
2 *  Gaycko        Text mode web browser
3 *  Copyright (c) 2011 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#include "renderer.h"
14void 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    for(td = 0; td < last_tr->specific.tr->td_count; td++) {
32        unsigned int biggest_td = 0;
33       
34        for(e = 0 ; e < table->children_count; e++) {
35            if(table->children[e]->type == ELEM_TR) {
36                unsigned int td_width = gaycko_get_td_width(table->children[e], td);
37                if(biggest_td < td_width) {
38                    biggest_td = td_width;
39                }
40            }
41        }
42        for(e = 0 ; e < table->children_count; e++) {
43            if(table->children[e]->type == ELEM_TR) {
44                gaycko_set_td_width(table->children[e], td, biggest_td);
45            }
46        }
47    }
48}
49
50void gaycko_fix_tr(gNode *tr) {
51        unsigned int td = 0;
52    tr->specific.tr->td_count = 0;
53   
54    for(td = 0 ; td < tr->children_count; td++) {
55        if(tr->children[td]->type == ELEM_TD) {
56            tr->specific.tr->td_count++;
57        }
58    }
59}   
60
61unsigned int gaycko_get_td_width(gNode *tr, unsigned int td_index) {
62    unsigned int e = 0;
63    unsigned int td = 0;
64    for(e = 0 ; e < tr->children_count; e++) {
65        if(tr->children[e]->type == ELEM_TD) {
66            if(td == td_index) return tr->children[e]->properties->width;
67            td++;
68        }
69    }
70    return 0;
71}
72
73void gaycko_set_td_width(gNode *tr, unsigned td_index, unsigned int width) {
74    unsigned int e = 0;
75    unsigned int td = 0;
76    unsigned int add_width = 0;
77   
78    for(e = 0 ; e < tr->children_count; e++) {
79        if(tr->children[e]->type == ELEM_TD) {
80            if(td == td_index) {
81                add_width = width - tr->children[e]->properties->width;
82            } else {
83                gaycko_add_node_x(tr->children[e], add_width);
84            }
85            td++;
86        }
87    }
88}
Note: See TracBrowser for help on using the repository browser.