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