aboutsummaryrefslogtreecommitdiff
path: root/src/SVG/SVG2zinc
diff options
context:
space:
mode:
Diffstat (limited to 'src/SVG/SVG2zinc')
-rw-r--r--src/SVG/SVG2zinc/Conversions.pm79
1 files changed, 30 insertions, 49 deletions
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