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

Last change on this file since 4754 was 4754, checked in by Jean-Yves Lamoureux, 10 years ago
  • Copyright notice
File size: 2.5 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                break;
29            case ELEM_TR:
30                gaycko_get_position(node->children[c], parent);
31                node->children[c]->properties->height+=1;
32                break;
33            case ELEM_BR:
34                node->children[c]->properties->height+=1;
35                break;
36            case ELEM_TD:
37                gaycko_get_position(node->children[c], parent);
38                break;
39            case ELEM_TEXT:
40                if(parent &&
41                   (parent->type!=ELEM_TR && parent->type!=ELEM_TABLE)) {
42                        if(node->children[c]->text) {
43                        node->children[c]->properties->width = strlen(node->children[c]->text);
44                        } else {
45                        node->children[c]->properties->width = 0;
46                        }
47                } else {
48                    node->children[c]->properties->width = 0;
49                    node->children[c]->properties->height = 0;
50                }
51                break;
52            default:
53                gaycko_get_position(node->children[c], node);
54                break;
55        }
56        if(node->children[c]->type != ELEM_TR &&
57           node->children[c]->type != ELEM_BR) {
58            x+=node->children[c]->properties->width;
59        } else {
60                x = 0;   
61        }
62        y+=node->children[c]->properties->height;
63        w+=node->children[c]->properties->width;
64        h+=node->children[c]->properties->height;
65       
66       
67    }
68   
69    node->properties->width  = w;
70    node->properties->height = h;
71}
Note: See TracBrowser for help on using the repository browser.