Changeset 26731


Ignore:
Timestamp:
2013-01-16T18:56:21+13:00 (11 years ago)
Author:
davidb
Message:

Can now correctly obtain colours and size of text when generating Expeditee frames. Also accounted for when the web browser being used is Firefox (FF uses "700" instead of the word "bold" for font-weight). The width of text items is also calculated and written to Expeditee. Parameters have also been provided so the user can decide whether they want the correct font information and text width used or to just use default values.

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

Legend:

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

    r26729 r26731  
    352352    my $exp_font_size = undef;
    353353
    354    
    355354    if ($css_font_size =~ m/^(\d+(?:\.\d*))px$/) {
    356355        $exp_font_size = int($1);
    357     }
     356    }else{ 
     357        #FF rounds sizes, e.g. 16.13px will just be 16px.
     358        my $end_index = length($css_font_size) - 2;
     359        $exp_font_size = substr($css_font_size,0,$end_index);
     360    }
    358361   
    359362    return $exp_font_size;
     
    365368    my $exp_font_face = undef;
    366369   
    367     if(lc($css_font_face) eq "bold"){
     370    #Firefox uses '700' instead of 'bold' for font-weight.
     371    if(lc($css_font_face) eq "bold" || $css_font_face eq "700"){
    368372            $exp_font_face = "b";
    369     }elsif(lc($css_font_face) eq "italic"){     #for now - also need to take into account italic and italic bold.
     373    }elsif(lc($css_font_face) eq "italic"){
    370374        $exp_font_face = "i";
    371     }elsif(lc($css_font_face) eq "bold-italic"){
     375    }elsif(lc($css_font_face) eq "bold-italic" || $css_font_face eq "700-italic"){
    372376        $exp_font_face = "p";
    373377    }else{
    374378        $exp_font_face = "r";
    375379    }
    376 
     380   
    377381    return $exp_font_face;
    378382}
  • gs3-extensions/html-to-expeditee/trunk/src/perllib/ExpediteeFrameIO.pm

    r26730 r26731  
    7070sub convertStyleToAttr
    7171{
    72     my ($css_attr) = @_;
     72    my ($css_attr,$compute_font) = @_;
    7373
    7474    my $exp_attr = {};
     
    7979    my $exp_font_size = "18";
    8080
    81 #    if (defined $css_attr->{'font-family'}) {
    82 #   $font_family = $font_family_lookup->[$css_attr->{'font-family'}];
    83 #    }
    84 
    85     if (defined $css_attr->{'font-size'}) {
     81    if(defined $compute_font){
     82        if($compute_font eq "true"){
     83   
     84            if (defined $css_attr->{'font-size'}) {
    8685       
    87         my $css_font_size = $css_attr->{'font-size'};
    88         $exp_font_size = CssStyleToExpAttr::convert_font_size($css_font_size);
    89 
    90     }
    91    
    92     if(defined $css_attr->{'font-family'}){
    93         my $obtain_font_family = $css_attr->{'font-family'};
    94         my $new_exp_font_family = CssStyleToExpAttr::convert_font_family($obtain_font_family); 
    95 
    96         if(defined $new_exp_font_family){
    97             $exp_font_family = $new_exp_font_family;
     86                my $css_font_size = $css_attr->{'font-size'};
     87                my $new_exp_font_size = CssStyleToExpAttr::convert_font_size($css_font_size);
     88
     89                if(defined $new_exp_font_size){
     90                    $exp_font_size = $new_exp_font_size;
     91                }
     92        }
     93   
     94        if(defined $css_attr->{'font-family'}){
     95            my $obtain_font_family = $css_attr->{'font-family'};
     96            my $new_exp_font_family = CssStyleToExpAttr::convert_font_family($obtain_font_family); 
     97
     98            if(defined $new_exp_font_family){
     99                $exp_font_family = $new_exp_font_family;
     100            }
     101        }
     102   
     103        #obtain font style/weight - bold, italic or bold-italic.
     104   
     105        if(defined $css_attr->{'font-style'}){
     106            my $css_font_style = $css_attr->{'font-style'};
     107            my $new_exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_style);
     108       
     109            if(defined $new_exp_font_face){
     110                $exp_font_face = $new_exp_font_face;
     111            }
     112        }
     113   
     114        if(defined $css_attr->{'font-weight'}){
     115            my $css_font_face = $css_attr->{'font-weight'};
     116            my $new_exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_face);
     117       
     118            if(defined $new_exp_font_face){
     119                $exp_font_face = $new_exp_font_face;
     120            }
     121        }
     122   
     123        if(defined $css_attr->{'font-style'} && defined $css_attr->{'font-weight'}){
     124            my $font_face_param = $css_attr->{'font-weight'}.'-'.$css_attr->{'font-style'};
     125            my $new_exp_font_face = CssStyleToExpAttr::convert_font_face($font_face_param);
     126       
     127            if(defined $new_exp_font_face){
     128                $exp_font_face = $new_exp_font_face;
     129            }
     130        }
     131   
     132        # color
     133        if(defined $css_attr->{'color'}){
     134            my $css_color = $css_attr->{'color'};
     135       
     136            my $exp_color = CssStyleToExpAttr::convert_color($css_color);
     137       
     138            $exp_attr->{'d'} = $exp_color;
     139        }
    98140        }
    99141    }
    100142   
    101     my $css_font_style;
    102     my $css_font_face;
    103    
    104     if(defined $css_attr->{'font-style'}){
    105         $css_font_style = $css_attr->{'font-style'};
    106         $exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_style);
    107     }
    108    
    109     if(defined $css_attr->{'font-weight'}){
    110         $css_font_face = $css_attr->{'font-weight'};
    111         $exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_face);
    112     }
    113    
    114     if(defined $css_attr->{'font-style'} && defined $css_attr->{'font-weight'}){
    115         my $font_face_param = $css_attr->{'font-weight'}.'-'.$css_attr->{'font-style'};
    116         $exp_font_face = CssStyleToExpAttr::convert_font_face($font_face_param);
    117     }
    118    
    119      $exp_attr->{'f'} = $exp_font_family.$exp_font_face.$exp_font_size;
     143    $exp_attr->{'f'} = $exp_font_family.$exp_font_face.$exp_font_size;
    120144
    121145    # background color
    122 
    123 
    124146    if (defined $css_attr->{'background-color'}) {
    125147        my $css_color = $css_attr->{'background-color'};
     
    129151        $exp_attr->{'e'} = $exp_color;
    130152    }
    131 
     153   
     154
     155   
    132156    return $exp_attr;
    133157}
     
    251275    $attr_copy{'P'} = "$x $y";
    252276    $attr_copy{'T'} = $text;
    253     $attr_copy{'w'} = "-$w" if (defined $w);
     277    #$attr_copy{'w'} = "-$w" if (defined $w);
     278    $attr_copy{'w'} = "$w" if (defined $w);
    254279   
    255280    return $self->_addItem("T",\%attr_copy);
     
    534559    $self->writeStatisticsSection();
    535560   
    536    
    537    
    538561    close(FOUT);
    539562    $status = 1;
     
    550573{
    551574    my $self = shift @_;
    552     my ($html_node) = @_;
     575    my ($html_node,$compute_font) = @_;
    553576 
    554     my $type = $html_node->{'type'};
     577    my $type = $html_node->{'type'};
    555578
    556579    if ($type eq "rect") {
     
    561584    my $yt = $rect->{'yt'};
    562585    my $yb = $rect->{'yb'};
    563 
     586   
    564587    my $attr = convertStyleToAttr($html_node->{'style'});
    565588
     
    606629    }
    607630    elsif ($type eq "text") {
    608    
     631       
    609632    my $text = $html_node->{'text'};
    610633
    611634    my $x = $html_node->{'xl'};
    612635    my $y = $html_node->{'yt'};
    613     my $w = $html_node->{'xr'} - $x +1;
    614    
    615     my $attr = convertStyleToAttr($html_node->{'style'});
     636    #my $w = $html_node->{'xr'} - $x +1;
     637   
     638    my $w = undef;
     639   
     640    if(defined $html_node->{'width'}){
     641        $w = $html_node->{'width'} - 5;     #take away 5px for extra space.
     642    }
     643   
     644    my $attr = convertStyleToAttr($html_node->{'style'},$compute_font);
    616645   
    617646    # fudge factor for now (based on default font size used)
     
    630659    my $childNodes = $html_node->{'childNodes'};
    631660    foreach my $child_node (@$childNodes) {
    632     $self->buildFrame($child_node);
     661    $self->buildFrame($child_node,$compute_font);
    633662    }
    634663}
  • gs3-extensions/html-to-expeditee/trunk/src/perllib/cgiactions/HtmlToExpediteeAction.pm

    r26597 r26731  
    5050{
    5151    "generate-frame"     => { 'compulsory-args' => [ "fn", "json" ],
    52                   'optional-args'   => ["assoc"] },
     52                  'optional-args'   => ["assoc", "compute-font"] },
    5353};
    5454
     
    8080   
    8181    my $assoc = $self->{'assoc'};
    82 
     82   
     83    my $compute_font = $self->{'compute-font'};
     84    print STDERR "Wil send compute_font... $compute_font\n\n";
     85   
    8386    # no need to lock collection (??), the operation is read only
    8487
     
    9598    my $expeditee_frame_io = new ExpediteeFrameIO($output_dir);
    9699   
    97     $expeditee_frame_io->buildFrame($exp_frame_tree);
     100    $expeditee_frame_io->buildFrame($exp_frame_tree,$compute_font);
    98101
    99102    if ($expeditee_frame_io->saveFrame("$fn.exp",$assoc)) {
  • gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/html-to-expeditee.pl.in

    r26728 r26731  
    6262
    6363        <input value="$site" name="site" id="site" type="hidden">
    64         <input value="Go" id="go"
    65                class="ui-button ui-widget ui-state-default ui-corner-all"
    66                type="submit">
     64       
     65        <p>
     66        <input type="checkbox" id="checkBoxBrowsing" name="generate_browsing" value="generate_browsing">Generate Browsing Frameset<br/>
     67        </p>
     68       
     69        <p style="font-weight: bold;">Extra Expeditee Frame Output Options:</p>
     70        <input type="checkbox" id="checkBoxFont" name="compute_font" value="compute_font">Compute Font<br/>
     71        <input type="checkbox" id="checkBoxWidth" name="compute_width" value="compute_width">Compute Width<br/>
     72       
     73        <p><input value="Go" id="go" class="ui-button ui-widget ui-state-default ui-corner-all" type="submit"><p>
    6774
    6875    </form>
     
    7077      var docOIDs = [];
    7178      var numDocOIDs;
    72 
     79      var compute_font = false;
     80      var compute_width = false;
     81      var generate_browsing = false;    //whether to generate a matching browsing frameset
     82     
    7383      \$(function() {
    7484      \$('#progress').progressbar();
     
    8999              cl = "CL" + cl;
    90100          }
    91          
     101         
     102          compute_font = document.getElementById("checkBoxFont").checked;
     103          compute_width = document.getElementById("checkBoxWidth").checked;
     104         
     105          generate_browsing = document.getElementById("checkBoxBrowsing").checked;
     106         
    92107          var gs2=$isGSDL2;
    93108
     
    102117              url += "&excerptid=gs_content";
    103118          }
     119         
     120          console.log("*** CHECKING URL: " + url);
    104121
    105122          /* processing animation */
     
    227244          if(frameNum === null){
    228245            frameNum = iter;
    229             console.log("no frameNum found, use iter: " + frameNum);
    230           }else{
    231             console.log("frameNum metadata found: " + frameNum);
    232246          }
    233247         
     
    252266          }
    253267
    254           var expFrameTree = htmlToExpeditee(gsContent);
     268          var expFrameTree = htmlToExpeditee(gsContent,compute_font,compute_width);
    255269
    256270          var expFrame = JSON.stringify(expFrameTree);
    257          
    258           console.log(expFrame);
    259          
     271          //console.log(expFrame);
    260272          //alert(expFrame);
    261273
     
    277289            params += "&assoc=" + assoc;
    278290          }
     291         
     292          params += "&compute-font=" + compute_font;
    279293
    280294          var clHtml = urlPostSync(url,params);
     
    417431    my $collect = $gsdl_cgi->clean_param("collect");   
    418432    my $cl = $gsdl_cgi->clean_param("cl");
    419    
     433       
    420434    # Establish collect_dir using defining 'site' along the way if GS3
    421435
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r26729 r26731  
    77var font_weight;
    88var font_style;
     9
     10var compute_font = false;
     11var compute_width = false;
    912
    1013Element.prototype.getElementWidth = function() {
     
    105108
    106109
    107 function htmlToExpeditee(node)
    108 {
     110function htmlToExpeditee(node,compFont,compWidth)
     111{
     112    compute_font = compFont;
     113    compute_width = compWidth;
     114   
    109115    var nodePos = getElementPosition(node);
    110116    var parentStyle = node.getAttribute('style');
    111117   
    112118    //Use these as default values if font info can't be found for text items.
    113     font_family = getStyle(node,'font-family');
    114     font_size = getStyle(node,'font-size');
    115     font_color = getStyle(node,'color');
    116    
    117     console.log("Retrieving node: " + node);
    118    
    119     console.log("Retrieving font family: " + font_family);
    120     console.log("Retrieving font size: " + font_size);
    121     console.log("Retrieving font color: " + font_color);
     119    //and only if the user wants the font computed (otherwise use Expeditee defaults).
     120    if(compute_font){
     121        font_family = getStyle(node,'font-family');
     122        font_size = getStyle(node,'font-size');
     123        font_color = getStyle(node,'color');
     124       
     125        /*console.log("Retrieving node: " + node);
     126   
     127        console.log("Retrieving font family: " + font_family);
     128        console.log("Retrieving font size: " + font_size);
     129        console.log("Retrieving font color: " + font_color);*/
     130    }
    122131   
    123132    var pxl = nodePos.xl;
     
    156165        if (parent != null) {
    157166       
    158             //obtain font info for text nodes from their parent nodes.
    159             var new_font_family = getStyle(parent,"font-family");
    160             var new_font_size = getStyle(parent,"font-size");
    161             var new_font_color = getStyle(parent,"color");
    162            
    163             var new_font_weight = getStyle(parent,"font-weight");
    164             var new_font_style = getStyle(parent,"font-style");
    165            
    166             if(new_font_family !== undefined && new_font_family !== null)
    167                 font_family = new_font_family;
    168            
    169             if(new_font_size !== undefined && new_font_size !== null)
    170                 font_size = new_font_size;
    171            
    172             if(new_font_color !== undefined && new_font_color !== null)
    173                 font_color = new_font_color;
     167            if(compute_font){
     168                //obtain font info for text nodes from their parent nodes.
     169                var new_font_family = getStyle(parent,"font-family");
     170                var new_font_size = getStyle(parent,"font-size");
     171                var new_font_color = getStyle(parent,"color");
     172           
     173                var new_font_weight = getStyle(parent,"font-weight");
     174                var new_font_style = getStyle(parent,"font-style");
     175                       
     176                if(new_font_family !== undefined && new_font_family !== null)
     177                    font_family = new_font_family;
     178           
     179                if(new_font_size !== undefined && new_font_size !== null)
     180                    font_size = new_font_size;
     181           
     182                if(new_font_color !== undefined && new_font_color !== null)
     183                    font_color = new_font_color;
    174184               
    175             if(new_font_weight !== undefined && new_font_weight !== null)
    176                 font_weight = new_font_weight;
     185                //TODO: if parent node is a <b> element, then set style["font-weight"] to be "bold".
     186                if(new_font_weight !== undefined && new_font_weight !== null)
     187                    font_weight = new_font_weight;
    177188               
    178             if(new_font_style !== undefined && new_font_style !== null)
    179                 font_style = new_font_style;
    180            
    181             var data = parent.attributes["data"];
    182 
    183             if (data != null) {
     189                if(new_font_style !== undefined && new_font_style !== null)
     190                    font_style = new_font_style;
     191           
     192                var style = {};
     193                style["font-family"]      = font_family;
     194                style["font-size"]        = font_size;
     195                style["color"]            = font_color;
     196                style["font-weight"]      = font_weight;
     197                style["font-style"]       = font_style;
     198           
     199                jsonNode.style = style;
     200        }
     201       
     202        if(compute_width){
     203            var parentPos = getElementPosition(parent);
     204            var parentWidth = parentPos.xr - parentPos.xl;
     205                       
     206            /*console.log("parent.xl: " + parentPos.xl);
     207            console.log("parent.xr: " + parentPos.xr);
     208            console.log("parent width: " + parentWidth);*/
     209           
     210            jsonNode.width = parentWidth;
     211        }
     212       
     213        var data = parent.attributes["data"];
     214           
     215        if (data != null) {
    184216                jsonNode.data = data.value;
    185             }
    186            
    187             var style = {};
    188             style["font-family"]      = font_family;
    189             style["font-size"]        = font_size;
    190             style["color"]            = font_color;
    191             style["font-weight"]      = font_weight;
    192             style["font-style"]       = font_style;
    193            
    194             //TODO: if parent node is a <b> element, then set style["font-weight"] to be "bold".
    195            
    196             jsonNode.style = style;
     217        }
     218           
     219           
    197220        }
    198221    }
Note: See TracChangeset for help on using the changeset viewer.