Changeset 26728


Ignore:
Timestamp:
2013-01-15T22:49:23+13:00 (9 years ago)
Author:
davidb
Message:

Can now successfully obtain font size, font weight, font colour and font family information about each piece of text on a web page and convert to a corresponding text item on an Expeditee frame. Still need to account for text nodes with parents such as bold elements or heading elements.

Location:
gs3-extensions/html-to-expeditee/trunk/src
Files:
4 edited

Legend:

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

    r26727 r26728  
    353353
    354354   
    355     #if ($css_font_size =~ m/^(\d+(?:\.\d*))px$/) {
    356     #   $exp_font_size = int($1);
    357     #}
    358    
    359     $css_font_size =~ s/[^0-9]//g;
    360    
    361     if(defined $css_font_size){
    362         $exp_font_size = $css_font_size;
     355    if ($css_font_size =~ m/^(\d+(?:\.\d*))px$/) {
     356        $exp_font_size = int($1);
     357    }
     358   
     359    return $exp_font_size;
     360}
     361
     362sub convert_font_face
     363{
     364    my ($css_font_face) = @_;
     365    my $exp_font_face = undef;
     366   
     367    if(lc($css_font_face) eq "bold"){
     368            $exp_font_face = "b";
     369    }else{      #for now - also need to take into account italic and italic bold.
     370        $exp_font_face = "r";
    363371    }
    364372
    365     return $exp_font_size;
     373    return $exp_font_face;
    366374}
    367375
     
    405413    if(defined $font_specific_family_lookup->{lc($css_font_family)}){
    406414        $exp_font_family = $css_font_family."_";
     415    }else{
     416   
     417        #to account for instances where a list of fonts is stored as the font family, e.g. "Arial,Segoe...Sans-Serif".
     418        #just extract the first font name from this list.
     419        my @font_family_vals = split(',',$css_font_family);
     420       
     421        if(scalar(@font_family_vals) > 0){
     422            $exp_font_family = $font_family_vals[0]."_";
     423        }
     424   
    407425    }
    408    
    409     print STDERR "**** TESTING TESTING ".$font_specific_family_lookup->{"georgia"}."\n";
    410     print STDERR "**** TESTING TESTING ".$font_specific_family_lookup->{lc($css_font_family)}."\n";
    411     print STDERR "**** TESTING TESTING ".$font_specific_family_lookup->{$css_font_family}."\n";
    412     print STDERR "In CssStyleToExpAttr: font family attribute: $exp_font_family ******* \n";
    413426   
    414427    return $exp_font_family;
  • gs3-extensions/html-to-expeditee/trunk/src/perllib/ExpediteeFrameIO.pm

    r26727 r26728  
    8787        my $css_font_size = $css_attr->{'font-size'};
    8888        $exp_font_size = CssStyleToExpAttr::convert_font_size($css_font_size);
    89        
    90         print STDERR "CSS Font Size is defined: ".$css_font_size."\n";
    91         print STDERR "Equivalent expeditee font size: ".$exp_font_size."\n";
     89
    9290    }
    9391   
    9492    if(defined $css_attr->{'font-family'}){
    9593        my $obtain_font_family = $css_attr->{'font-family'};
    96         print STDERR "Font family attribute found: ".$obtain_font_family."\n";
    9794        my $new_exp_font_family = CssStyleToExpAttr::convert_font_family($obtain_font_family); 
    9895
     
    10299    }
    103100   
    104     if(defined $css_attr->{'font-face'}){
    105         print STDERR "Font face attribute found: ".$css_attr->{'font-face'}."\n";
    106        
    107         #now need to call a method from CssStyleToExpAttr.pm to extract the matching
    108         #font symbol
    109         #s -
     101    if(defined $css_attr->{'font-style'}){
     102        print STDERR "Font style attribute found: ".$css_attr->{'font-style'}."\n";
    110103    }
    111104   
    112105    if(defined $css_attr->{'font-weight'}){
    113106        print STDERR "Font weight attribute found: ".$css_attr->{'font-weight'}."\n";
     107       
     108        my $css_font_face = $css_attr->{'font-weight'};
     109        $exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_face);
    114110    }
    115111   
    116 #    if (defined $css_attr->{'font-face'}) {
    117 #   $font = conver_font_face($css_attr->{'font-face'});
    118 #    }
    119 
    120112     $exp_attr->{'f'} = $exp_font_family.$exp_font_face.$exp_font_size;
    121      
    122      print STDERR "**** final converted Expeditee font: ".$exp_attr->{'f'};
     113     print STDERR "exp attribute obtained: ".$exp_attr->{'f'}." ****\n";
    123114     
    124115    # background color
     
    581572    #don't want to add font information to non-text items!
    582573    my $deleted = delete $attr->{'f'};
    583    
    584     print STDERR "**** DELETED: $deleted \n";
    585574
    586575    $self->addRect($xl,$yt,$xr,$yb,$attr);
     
    617606    my $y = $html_node->{'yt'};
    618607    my $w = $html_node->{'xr'} - $x +1;
    619 
    620     print STDERR "**** CHECKING STYLE NODE: ".$html_node->{'style'}."\n";
     608   
    621609    my $attr = convertStyleToAttr($html_node->{'style'});
    622    
    623     #DEBUGGING
    624     if(defined $attr->{'f'}){
    625         print STDERR "***** Checking text attributes:".$attr->{'f'}."\n";
    626         print STDERR "****************************************\n";
    627     }
    628610   
    629611    # fudge factor for now (based on default font size used)
  • gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/html-to-expeditee.pl.in

    r26725 r26728  
    256256          var expFrame = JSON.stringify(expFrameTree);
    257257         
    258           console.log("******");
    259258          console.log(expFrame);
    260259         
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r26726 r26728  
    55var font_size;
    66var font_color;
     7var font_weight;
    78
    89Element.prototype.getElementWidth = function() {
     
    159160            var new_font_color = getStyle(parent,"color");
    160161           
     162            var new_font_weight = getStyle(parent,"font-weight");
     163           
    161164            if(new_font_family !== undefined && new_font_family !== null)
    162165                font_family = new_font_family;
     
    167170            if(new_font_color !== undefined && new_font_color !== null)
    168171                font_color = new_font_color;
     172               
     173            if(new_font_weight !== undefined && new_font_weight !== null)
     174                font_weight = new_font_weight;
    169175           
    170176            var data = parent.attributes["data"];
     
    173179                jsonNode.data = data.value;
    174180            }
    175             jsonNode.style = style;
    176         }
    177     }
    178    
     181           
    179182            var style = {};
    180183            style["font-family"]      = font_family;
    181184            style["font-size"]        = font_size;
    182185            style["color"]            = font_color;
     186            style["font-weight"]      = font_weight;
     187           
     188            //TODO: if parent node is a <b> element, then set style["font-weight"] to be "bold".
     189           
     190            jsonNode.style = style;
     191        }
     192    }
     193   
     194           
    183195   
    184196    }
Note: See TracChangeset for help on using the changeset viewer.