Changeset 26726


Ignore:
Timestamp:
2013-01-15T20:52:36+13:00 (11 years ago)
Author:
davidb
Message:

Now correctly obtaining font information for text nodes - this required getting the style information from the text node's parent element.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r25060 r26726  
    11//javascript:
    22var expSyntaxArray = [];
     3
     4var font_family;
     5var font_size;
     6var font_color;
    37
    48Element.prototype.getElementWidth = function() {
     
    7478    prop_val = el.style[style_prop];
    7579    }
    76 
     80   
    7781    return prop_val;
    7882
     
    101105function htmlToExpeditee(node)
    102106{
    103     var nodePos = getElementPosition(node);
     107    var nodePos = getElementPosition(node);
     108    var parentStyle = node.getAttribute('style');
     109   
     110    //Use these as default values if font info can't be found for text items.
     111    font_family = getStyle(node,'font-family');
     112    font_size = getStyle(node,'font-size');
     113    font_color = getStyle(node,'color');
     114   
     115    console.log("Retrieving node: " + node);
     116   
     117    console.log("Retrieving font family: " + font_family);
     118    console.log("Retrieving font size: " + font_size);
     119    console.log("Retrieving font color: " + font_color);
     120   
    104121    var pxl = nodePos.xl;
    105122    var pyt = nodePos.yt;
     
    116133
    117134    var jsonNode = null;
    118 
     135   
    119136    if (node.nodeType == 3) { /* text node */
     137   
     138       
    120139        var text = node.nodeValue;
    121140
     
    132151
    133152        var parent = node.parentNode;
     153       
    134154        if (parent != null) {
    135         var data = parent.attributes["data"];
    136 
    137                 if (data != null) {
    138           jsonNode.data = data.value;
    139             }
    140         }
    141     }
     155       
     156            //obtain font info for text nodes from their parent nodes.
     157            var new_font_family = getStyle(parent,"font-family");
     158            var new_font_size = getStyle(parent,"font-size");
     159            var new_font_color = getStyle(parent,"color");
     160           
     161            if(new_font_family !== undefined && new_font_family !== null)
     162                font_family = new_font_family;
     163           
     164            if(new_font_size !== undefined && new_font_size !== null)
     165                font_size = new_font_size;
     166           
     167            if(new_font_color !== undefined && new_font_color !== null)
     168                font_color = new_font_color;
     169           
     170            var data = parent.attributes["data"];
     171
     172            if (data != null) {
     173                jsonNode.data = data.value;
     174            }
     175            jsonNode.style = style;
     176        }
     177    }
     178   
     179            var style = {};
     180            style["font-family"]      = font_family;
     181            style["font-size"]        = font_size;
     182            style["color"]            = font_color;
     183   
    142184    }
    143185    else if (node.nodeType == 1) { /* element */
     
    162204        var yb = nodePos.yb;
    163205
    164             jsonNode = {};
     206        jsonNode = {};
    165207        jsonNode.type = "rect";
    166             jsonNode.elem = node.nodeName;
     208        jsonNode.elem = node.nodeName;
     209       
     210        if(node.getAttribute("rect") !== undefined){
     211           
     212            /**This is to ensure rectangles aren't drawn around "non-rectangular" items such
     213            as text and empty elements such as <br/>**/
     214            if(node.getAttribute("rect") === "norect"){
     215                jsonNode.type = "norect";
     216            }
     217        }
    167218
    168219        var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
     
    170221   
    171222        if (elemName.match("img")) {
    172         jsonNode.img = node.src;
    173         }
    174 
    175         var style = {};
    176 
    177         style["font-family"]      = getStyle(node,"font-family");
    178         style["font-size"]        = getStyle(node,"font-size");
     223            jsonNode.img = node.src;
     224        }
     225
     226        var style = {};
     227       
     228        //style["font-family"]      = getStyle(node,"font-family");
     229        //style["font-size"]        = getStyle(node,"font-size");
    179230        style["background-color"] = getStyle(node,"background-color");
    180 
    181         // console.log("background color = " + style["background-color"]);
    182 
    183         // console.log("font size = " + style["font-size"]);
    184  
    185         jsonNode.style = style;
     231       
     232        jsonNode.style = style;
    186233
    187234        var attr = node.attributes["attr"];
Note: See TracChangeset for help on using the changeset viewer.