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 | 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 | } |
---|
108 | |
---|
109 | |
---|
110 | void gaycko_add_node_x(gNode *node, unsigned int add) { |
---|
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 | |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | |
---|