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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.