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 | |
---|
15 | void 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 | |
---|
30 | |
---|
31 | gaycko_fix_table(node->children[c]); |
---|
32 | if(node->children[c]->properties->width>w) { |
---|
33 | w = (node->children[c]->properties->width); |
---|
34 | } |
---|
35 | break; |
---|
36 | |
---|
37 | case ELEM_TR: |
---|
38 | gaycko_get_position(node->children[c], parent); |
---|
39 | node->children[c]->properties->height+=1; |
---|
40 | x = 0; |
---|
41 | w+=node->children[c]->properties->width+1; |
---|
42 | break; |
---|
43 | |
---|
44 | case ELEM_TD: |
---|
45 | gaycko_get_position(node->children[c], parent); |
---|
46 | x+=node->children[c]->properties->width; |
---|
47 | if(node->children[c]->properties->width>w) { |
---|
48 | w = (node->children[c]->properties->width); |
---|
49 | } |
---|
50 | break; |
---|
51 | |
---|
52 | case ELEM_BR: |
---|
53 | node->children[c]->properties->height+=1; |
---|
54 | x = 0; |
---|
55 | w+=node->children[c]->properties->width+1; |
---|
56 | break; |
---|
57 | |
---|
58 | case ELEM_HR: |
---|
59 | node->children[c]->properties->height+=1; |
---|
60 | x = 0; |
---|
61 | w+=node->children[c]->properties->width+1; |
---|
62 | break; |
---|
63 | |
---|
64 | case ELEM_H1: |
---|
65 | case ELEM_H2: |
---|
66 | case ELEM_H3: |
---|
67 | node->children[c]->properties->height+=1; |
---|
68 | x = 0; |
---|
69 | w+=node->children[c]->properties->width+1; |
---|
70 | break; |
---|
71 | |
---|
72 | |
---|
73 | case ELEM_TEXT: |
---|
74 | if(parent && |
---|
75 | (parent->type!=ELEM_TR && parent->type!=ELEM_TABLE)) { |
---|
76 | if(node->children[c]->text) { |
---|
77 | node->children[c]->properties->width = strlen(node->children[c]->text); |
---|
78 | } else { |
---|
79 | node->children[c]->properties->width = 0; |
---|
80 | } |
---|
81 | } else { |
---|
82 | node->children[c]->properties->width = 0; |
---|
83 | node->children[c]->properties->height = 0; |
---|
84 | } |
---|
85 | x+=node->children[c]->properties->width; |
---|
86 | if(node->children[c]->properties->width>w) { |
---|
87 | w = (node->children[c]->properties->width); |
---|
88 | } |
---|
89 | break; |
---|
90 | |
---|
91 | |
---|
92 | default: |
---|
93 | gaycko_get_position(node->children[c], node); |
---|
94 | x+=node->children[c]->properties->width; |
---|
95 | if(node->children[c]->properties->width>w) { |
---|
96 | w = (node->children[c]->properties->width); |
---|
97 | } |
---|
98 | |
---|
99 | break; |
---|
100 | } |
---|
101 | |
---|
102 | y+=node->children[c]->properties->height; |
---|
103 | h+=node->children[c]->properties->height; |
---|
104 | } |
---|
105 | |
---|
106 | node->properties->width = w; |
---|
107 | node->properties->height = h; |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | void gaycko_add_node_x(gNode *node, unsigned int add) { |
---|
112 | |
---|
113 | unsigned int e = 0; |
---|
114 | for(e = 0 ; e < node->children_count; e++) { |
---|
115 | //gaycko_add_node_x(node->children[e], add); |
---|
116 | //gaycko_add_node_x(node->children[e], add); |
---|
117 | node->children[e]->properties->width += add; |
---|
118 | node->children[e]->properties->x += add; |
---|
119 | } |
---|
120 | node->properties->x += add; |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|