From 8489ecd3e999606b663647a2596314a36f2fa2d2 Mon Sep 17 00:00:00 2001 From: ribet Date: Tue, 11 May 2010 13:12:42 +0000 Subject: Fontconfig's style font handling. --- src/SVG/SVG2zinc/Conversions.pm | 79 ++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 49 deletions(-) (limited to 'src/SVG/SVG2zinc/Conversions.pm') diff --git a/src/SVG/SVG2zinc/Conversions.pm b/src/SVG/SVG2zinc/Conversions.pm index 0c8fd43..4eba4e8 100644 --- a/src/SVG/SVG2zinc/Conversions.pm +++ b/src/SVG/SVG2zinc/Conversions.pm @@ -102,65 +102,46 @@ my %fontsMapping = ( my $last_key = "verdana"; sub createNamedFont { - my ($fullFamily, $size, $weight) = @_; - if ($fullFamily eq "") - { - $fullFamily = $last_key if $fullFamily eq ""; - } - else - { + my ($fullFamily, $size, $weight, $style) = @_; + if ($fullFamily eq "") { + $fullFamily = $last_key; + } else { $last_key = $fullFamily; } my $family = lc($fullFamily); - my ($fontName, $fontKey); - if ($family =~ /^-[^-]*-([^-]*)-([^-]*)-[^-]*-[^-]*-[^-]*-([^-]*)-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*$/ ) { - $weight = $2; - $size = 0; # Warning: setting size changes font metrics! - $fontKey = "XLFD$family"; - $fontName = $family; - #$family = $1; # Setting the real family prevent from loading the right font - } else { - $weight = "normal" unless $weight; - if ( $size =~ /(.*)pt/ ) - { - $size = -$1; - } - elsif ( $size =~ /(.*)px/ ) - { - $size = -$1; + my ($fontKey); + if ($family =~ /^-[^-]*-([^-]*)-([^-]*)-([^-]*)-[^-]*-[^-]*-([^-]*)-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*$/ ) { + $size = $4 if $4; + $weight = $2 if $2; + if ($3 eq 'i') { + $style='italic'; + } elsif ($3 eq 'o') { + $style='oblique'; } - elsif ( $size =~ /(\d*(.\d*)?)\s*$/ ) - { - $size = -$1; + $family = $1; + } else { + if ( $size =~ /(.*)pt/ ) { + $size = $1; + } elsif ( $size =~ /(.*)px/ ) { + $size = $1; + } elsif ( $size =~ /(\d*(.\d*)?)\s*$/ ) { + $size = $1; } -# $size = &float2int($size); # I round the font size, at least until we have vectorial font in Tk::Zinc + } - $family = $fontsMapping{$family} if defined $fontsMapping{$family}; - if ( $family =~ /(\w*)-bold/ ) - { + $family = $fontsMapping{$family} if defined $fontsMapping{$family}; + if ( $family =~ /(\w*)-bold/ ) { $family = $1; $weight = "bold"; - } - else - { - if ($weight eq '') { - $weight = "medium"; - } - } - - $fontKey = join "_", ($family, $size, $weight); - $fontName = $family; - } - if (!defined $fonts{$fontKey}) - { - $fonts{$fontKey} = $fontKey; - return ($fontKey, $fontName, "->fontCreate('$fontKey', -family => \"$family\", -size => $size, -weight => \"$weight\") if ! \$fonts {\"$fontKey\"};"); - } - else - { - return ($fontKey, $fontName, ""); } + + $fontKey = "$family:"; + $fontKey .= "weight=$weight:" if $weight; + $fontKey .= "slant=$style:" if $style; + $fontKey .= "pixelsize=$size" if $size; + + return $fontKey; } # end of createNamedFont -- cgit v1.1