source: gaycko/trunk/src/render/position.c @ 4758

Last change on this file since 4758 was 4758, checked in by Jean-Yves Lamoureux, 10 years ago
  • Preliminary support of <hr>
  • Minor cleaning
File size: 3.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"
14
15void gaycko_get_position(gNode *node, gNode *parent) {
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                if(node->children[c]->properties->width>w) {
30                    w = (node->children[c]->properties->width);
31                }
32                break;
33               
34            case ELEM_TR:
35                gaycko_get_position(node->children[c], parent);
36                node->children[c]->properties->height+=1;
37                x = 0;   
38                w+=node->children[c]->properties->width+1;
39                break;
40            case ELEM_TD:
41                gaycko_get_position(node->children[c], parent);
42                x+=node->children[c]->properties->width;
43                if(node->children[c]->properties->width>w) {
44                    w = (node->children[c]->properties->width);
45                }
46                break;
47               
48            case ELEM_BR:
49                node->children[c]->properties->height+=1;
50                x = 0;   
51                w+=node->children[c]->properties->width+1;
52                break;
53            case ELEM_HR:
54                node->children[c]->properties->height+=1;
55                x = 0;   
56                w+=node->children[c]->properties->width+1;
57                break;
58            case ELEM_H1:
59            case ELEM_H2:
60            case ELEM_H3:
61                node->children[c]->properties->height+=1;
62                x = 0;   
63                w+=node->children[c]->properties->width+1;
64                break;
65               
66               
67            case ELEM_TEXT:
68                if(parent &&
69                   (parent->type!=ELEM_TR && parent->type!=ELEM_TABLE)) {
70                        if(node->children[c]->text) {
71                        node->children[c]->properties->width = strlen(node->children[c]->text);
72                        } else {
73                        node->children[c]->properties->width = 0;
74                        }
75                } else {
76                    node->children[c]->properties->width  = 0;
77                    node->children[c]->properties->height = 0;
78                }
79                x+=node->children[c]->properties->width;
80                if(node->children[c]->properties->width>w) {
81                    w = (node->children[c]->properties->width);
82                }
83                break;
84               
85            default:
86                gaycko_get_position(node->children[c], node);
87                x+=node->children[c]->properties->width;
88                if(node->children[c]->properties->width>w) {
89                    w = (node->children[c]->properties->width);
90                }
91               
92                break;
93        }
94     
95        y+=node->children[c]->properties->height;
96        h+=node->children[c]->properties->height;
97       
98    }
99   
100
101    node->properties->width  = w;
102    node->properties->height = h;
103}
Note: See TracBrowser for help on using the repository browser.