source: gaycko/trunk/src/render/renderer.c @ 4750

Last change on this file since 4750 was 4750, checked in by Jean-Yves Lamoureux, 10 years ago
  • Initial general node and table width computation
File size: 2.3 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#include "renderer.h"
13
14void gaycko_render(gDOM *dom, gWindow *window) {
15        dom->root->properties->width = window->width;
16   
17    int width = gaycko_get_width(dom->root, NULL);
18    printf("Got %u\n", width);
19}
20
21
22unsigned int gaycko_get_width(gNode *node, gNode *parent) {
23        unsigned int c = 0;
24    int w = 0;
25   
26   
27    for(c = 0; c < node->children_count; c++) {
28        switch(node->children[c]->type) {
29         
30            case ELEM_TABLE:
31                w = gaycko_get_table_width(node->children[c], parent);
32                break;
33            case ELEM_TEXT:
34                w +=  gaycko_get_text_width(node->children[c], parent);
35                break;
36            default:
37                w+=gaycko_get_width(node->children[c], node);
38                break;
39        }
40    }
41   
42     printf("Width of '%s' : %u\n", node->name, w);
43    node->properties->width = w;
44    return w;
45}
46
47
48unsigned int gaycko_get_table_width(gNode *node, gNode *parent) {
49    unsigned int w = node->properties->width;
50    unsigned int c = 0;
51   
52    printf("Got TABLE, %u children\n", node->children_count);
53   
54     for(c = 0; c < node->children_count; c++) {
55         unsigned int node_width = 0;
56         
57         printf("in TABLE children %s\n", node->children[c]->name);
58         switch(node->children[c]->type) {
59                 case ELEM_TR:
60                 node_width = gaycko_get_width(node->children[c], node);
61                 break;
62                 
63             default:
64                 w+=0;
65                 break;
66         }
67         if(node_width > w) w = node_width;
68     }
69   
70    printf("Table : return %d\n", w);
71    return w;
72}
73
74
75unsigned int gaycko_get_text_width(gNode *node, gNode *parent) {
76           
77    if(node->text) {
78        node->properties->width = strlen(node->text);
79        return node->properties->width;
80    } else {
81        return 0;   
82    }
83}
Note: See TracBrowser for help on using the repository browser.