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

Last change on this file since 4751 was 4751, checked in by Jean-Yves Lamoureux, 9 years ago
  • Ignore mode xcode project files
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
47unsigned int gaycko_get_table_width(gNode *node, gNode *parent) {
48    unsigned int w = node->properties->width;
49    unsigned int c = 0;
50   
51    printf("Got TABLE, %u children\n", node->children_count);
52   
53     for(c = 0; c < node->children_count; c++) {
54         unsigned int node_width = 0;
55         
56         printf("in TABLE children %s\n", node->children[c]->name);
57         switch(node->children[c]->type) {
58                 case ELEM_TR:
59                 node_width = gaycko_get_width(node->children[c], node);
60                 break;
61                 
62             default:
63                 w+=0;
64                 break;
65         }
66         if(node_width > w) w = node_width;
67     }
68   
69    printf("Table : return %d\n", w);
70    return w;
71}
72
73
74unsigned int gaycko_get_text_width(gNode *node, gNode *parent) {
75           
76    if(node->text) {
77        node->properties->width = strlen(node->text);
78        return node->properties->width;
79    } else {
80        return 0;   
81    }
82}
Note: See TracBrowser for help on using the repository browser.