Changeset 24941


Ignore:
Timestamp:
2012-01-12T11:03:59+13:00 (12 years ago)
Author:
davidb
Message:

Work on converting CSS style attributes to Expeditee attributes

Location:
gs3-extensions/html-to-expeditee/trunk/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/html-to-expeditee/trunk/src/perllib/ExpediteeFrameIO.pm

    r24939 r24941  
    2828use strict;
    2929
     30use CssStyleToExpAttr;
     31
    3032sub new
    3133{
     
    7779
    7880    # load up some defaults for font information
    79     my $font_family = "s"; # t
    80     my $font_face = "r";
    81     my $font_size = "14";
     81    my $exp_font_family = "s"; # t
     82    my $exp_font_face = "r";
     83    my $exp_font_size = "14";
    8284
    8385#    if (defined $css_attr->{'font-family'}) {
     
    8587#    }
    8688
    87 #    if (defined $css_attr->{'font-size'}) {
    88 #   $font_size = convert_font_size($css_attr->{'font-size'});
    89 #    }
     89    if (defined $css_attr->{'font-size'}) {
     90    my $css_font_size = $css_attr->{'font-size'};
     91    $exp_font_size = CssStyleToExpAttr::convert_font_size($css_font_size);
     92    }
    9093
    9194#    if (defined $css_attr->{'font-face'}) {
    9295#   $font = conver_font_face($css_attr->{'font-face'});
    9396#    }
     97
     98#    $exp_attr->{'f'} = $exp_font_family.$exp_font_face.$exp_font_size;
    9499
    95100    return $exp_attr;
     
    169174    $self->setPointDefaultAttributes($attr);
    170175
    171     $attr->{'d'} = "50 100 50"; # green color for rect lines
    172     $attr->{'h'} = "2.0";     # line thickness
     176    $attr->{'d'} = "80 80 80"; # green color for rect lines
     177    $attr->{'h'} = "1.0";     # line thickness
    173178}
    174179
     
    193198{
    194199    my $self = shift @_;
    195     my ($x, $y, $text, $attr) = @_;
    196 
    197     # fudge factor for now (based on default font size used)
    198     $y += 16; # y-value of text item in Expeditee is it's base line
    199     $x += 4;
     200    my ($x, $y, $text, $w, $attr) = @_;
    200201
    201202    my %attr_copy = %$attr; # make a private copy of 'attr'
     
    207208    $attr_copy{'P'} = "$x $y";
    208209    $attr_copy{'T'} = $text;
     210    $attr_copy{'w'} = "-$w" if (defined $w);
    209211
    210212    return $self->_addItem("T",\%attr_copy);
     
    442444    $self->addRect($xl,$yt,$xr,$yb,$attr);
    443445
     446    if (defined $html_node->{'img'}) {
     447
     448        my $img_url = $html_node->{'img'};
     449        $img_url =~ s/^http:\/\/www\.nzdl\.org\/greenstone3-showcase\///;
     450        if ($img_url =~ m/^interfaces\//) {
     451        $img_url = "images/$img_url";
     452        }
     453        elsif ($img_url =~ m/^sites\//) {
     454        $img_url =~ s/^sites\/(.*?)\//images\//;
     455        }
     456
     457        my $x = $xl;
     458        my $y = $yt;
     459
     460        my $attr = {};
     461
     462        my $img_text = "\@i: $img_url";
     463
     464        $self->addText($x,$y,$img_text,undef,$attr);
     465    }
     466
    444467    }
    445468    elsif ($type eq "text") {
    446469    my $text = $html_node->{'text'};
    447470
    448     my $x = $html_node->{'x'};
    449     my $y = $html_node->{'y'};
     471    my $x = $html_node->{'xl'};
     472    my $y = $html_node->{'yt'};
     473    my $w = $html_node->{'xr'} - $x +1;
    450474
    451475    my $attr = convertStyleToAttr($html_node->{'style'});
    452476
    453     $self->addText($x,$y,$text,$attr);
     477    # fudge factor for now (based on default font size used)
     478    $y += 16; # y-value of text item in Expeditee is it's base line
     479    $x += 4;
     480
     481    $self->addText($x,$y,$text,$w,$attr);
    454482    }
    455483    else {
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r24939 r24941  
    5252}
    5353
    54 function getStyle(node,styleProp)
    55 {
     54function hyphenToInitialCapReplacer(str, p1, offset, s) 
     55
     56    return p1.toUpperCase();
     57
     58
     59function getStyle(node,style_prop)
     60{
     61    var prop_val;
    5662    if (node.currentStyle) {
    57     var y = node.currentStyle[styleProp];
     63    /* IE */
     64    style_prop = strCssRule.replace(/\-(\w)/g, hyphenToInitialCapReplacer);
     65    prop_val = node.currentStyle[style_prop];
    5866    }
    5967    else if (window.getComputedStyle) {
    60     var y = document.defaultView.getComputedStyle(node,null).getPropertyValue(styleProp);
    61     }
    62     return y;
     68    /* Firefox */
     69    var computed_style = document.defaultView.getComputedStyle(node,null)
     70    prop_val = computed_style.getPropertyValue(style_prop);
     71    }
     72    else {
     73    /* try for inline value */
     74    prop_val = el.style[style_prop];
     75    }
     76
     77    return prop_val;
     78
    6379}
    6480
     
    110126        jsonNode.text = node.nodeValue;
    111127
    112         jsonNode.x = pxl;
    113         jsonNode.y = pyt;
     128        jsonNode.xl = pxl;
     129        jsonNode.yt = pyt;
     130        jsonNode.xr = pxr;
     131        jsonNode.yb = pyb;
    114132
    115133    }
     
    119137    /* need to handle: img, a, li */
    120138        /* need to dig out: text size, l/r/justified, font-face, type, colour */
     139
     140    if (getStyle(node,"visibility").match("hidden")
     141        || getStyle(node,"display").match("none")) {
     142
     143        return null;
     144    }
    121145
    122146        var elemName = node.nodeName.toLowerCase();
     
    137161        jsonNode.rect = rect;
    138162   
     163        if (elemName.match("img")) {
     164        jsonNode.img = node.src;
     165        }
    139166
    140167        var style = {};
    141168
    142         style["font-family"] = getStyle(node,"font-family");
     169        style["font-family"]      = getStyle(node,"font-family");
     170        style["font-size"]        = getStyle(node,"font-size");
    143171        style["background-color"] = getStyle(node,"background-color");
    144172
     173        // console.log("font size = " + style["font-size"]);
     174 
    145175        jsonNode.style = style
    146176
Note: See TracChangeset for help on using the changeset viewer.