aboutsummaryrefslogtreecommitdiff
path: root/src/SVG
diff options
context:
space:
mode:
Diffstat (limited to 'src/SVG')
-rw-r--r--src/SVG/SVG2zinc.pm37
-rw-r--r--src/SVG/SVG2zinc/Conversions.pm79
2 files changed, 46 insertions, 70 deletions
diff --git a/src/SVG/SVG2zinc.pm b/src/SVG/SVG2zinc.pm
index 54126fe..c9be2cc 100644
--- a/src/SVG/SVG2zinc.pm
+++ b/src/SVG/SVG2zinc.pm
@@ -112,7 +112,7 @@ my %EVENT_ON_ANIM = map { $_ => 1 } @EVENT_ON_ANIM;
#### &analyze_style , &analyze_text_style , &groupContext , &attrs_implemented
my @STYLE_ATTRS = qw(
class style display ddisplay fill fill-opacity fill-rule stroke
- stroke-width stroke-opacity opacity font-size font-family
+ stroke-width stroke-opacity opacity font-size font-family font-style
font-weight stroke-linejoin stroke-linecap stroke-dasharray text-anchor
) ;
my %STYLE_ATTRS = map { $_ => 1 } @STYLE_ATTRS;
@@ -1141,7 +1141,7 @@ my %save_current_context = ();
$res .= &analyze_text_style (\%attrs);
@texts = ();
@transforms = &transform('$previous', $attrs{transform});
- &attrs_implemented ( 'text', $name, [qw (stroke-miterlimit x y id transform text-anchor font-family font-size)], %attrs );
+ &attrs_implemented ( 'text', $name, [qw (stroke-miterlimit x y id transform text-anchor font-family font-size font-weight font-style)], %attrs );
}
sub nextText {
@@ -1170,13 +1170,7 @@ my %save_current_context = ();
my $theText = join ('', @texts);
$res .= ", -text => '$theText', -priority => 10);";
my @ascent;
- if ($current_font_key =~ /^XLFD/) {
- my $fontname = $current_font_key;
- $fontname =~ s/^XLFD//;
- push (@ascent, "\$ascent = -> fontMetrics ('$fontname', -ascent);");
- } else {
- push (@ascent, "\$ascent = -> fontMetrics (\$fonts{\"$current_font_key\"}, -ascent);");
- }
+ push (@ascent, "\$ascent = -> fontMetrics ('$current_font_key', -ascent);");
if ($text_x != 0 || $text_y != 0)
{
push (@ascent, "-> translate(\$previous, $text_x, $text_y - \$ascent);");
@@ -1565,7 +1559,7 @@ sub expandStyle {
$style = &removeComment ($style);
foreach my $keyvalue ( split ( /\s*;\s*/ , $style) )
{
- my ($key, $value) = $keyvalue =~ /(.*)\s*:\s*(.*)/ ;
+ my ($key, $value) = $keyvalue =~ /(.*?)\s*:\s*(.*)/ ;
$keyvalues{$key} = $value;
}
return %keyvalues;
@@ -1735,6 +1729,10 @@ sub analyze_style_hash {
{
### this attributes is for text only and is analyzed in &analyze_text_style_hash
}
+ elsif ($key eq 'font-style')
+ {
+ ### this attributes is for text only and is analyzed in &analyze_text_style_hash
+ }
else
{
&myWarn ("Unknown Style (in analyze_style_hash): $key (value is $value)\n") if $warn;
@@ -1756,7 +1754,7 @@ sub analyze_text_style_hash
my $fontFamily="";
my $fontSize ="";
my $fontWeight ="";
-
+ my $fontStyle = "";
foreach my $key (keys %keyvalues)
{
my $value = $keyvalues{$key};
@@ -1807,6 +1805,10 @@ sub analyze_text_style_hash
{
$fontWeight = $value;
}
+ elsif ($key eq 'font-style')
+ {
+ $fontStyle = $value;
+ }
elsif ($key eq 'fill')
{
my $fillOpacity;
@@ -1845,18 +1847,11 @@ sub analyze_text_style_hash
&myWarn ("Unknown Style of text: $key (value is $value)\n") if $warn;
}
}
- if ($fontFamily or $fontSize or $fontWeight)
+ if ($fontFamily or $fontSize or $fontWeight or $fontStyle)
{
## to be extended to all other fonts definition parameters
- ## NB: fontWeight is not used yet!
- my ($fontKey,$fontName,$code) = &createNamedFont ($fontFamily, $fontSize, $fontWeight);
- &display("\$fonts{\"$fontKey\"} = ") if $code;
- &display($code) if $code;
- if ($fontKey =~ /^XLFD-/ ) {
- $res .= ", -font => \"$fontName\"";
- } else {
- $res .= ", -font => \"$fontKey\"";
- }
+ my ($fontKey) = &createNamedFont ($fontFamily, $fontSize, $fontWeight, $fontStyle);
+ $res .= ", -font => \"$fontKey\"";
$current_font_key = $fontKey;
}
return $res;
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