[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 15 Apr 2004 19:08:31 -0000


albertel		Thu Apr 15 15:08:31 2004 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  - trying to handle image sizes correctly, it should now
      - pick up the image size if it is not specified
      - scale the image if they specify only 1 dimension
      - BUG #2768 is fixed
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.209 loncom/xml/londefdef.pm:1.210
--- loncom/xml/londefdef.pm:1.209	Thu Apr 15 13:37:04 2004
+++ loncom/xml/londefdef.pm	Thu Apr 15 15:08:31 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.209 2004/04/15 17:37:04 albertel Exp $
+# $Id: londefdef.pm,v 1.210 2004/04/15 19:08:31 albertel Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2333,27 +2333,46 @@
 	if ($height) { $currentstring.=' height="'.$height.'" '; }
 	$currentstring .= ' />';
     } elsif ($target eq 'modified') {
-	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
-						     $safeeval,'src','alt',
-						     'TeXwidth','TeXheight',
-						     'width','height');
-	$src=$token->[2]{'src'};
-	if (!$token->[2]{'width'} && !$token->[2]{'height'}) {
-	    $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
-	    &image_replication($src);
-	    if (-e $src) {
-		my $image = Image::Magick->new;
-		$image->Read($src);
-		my ($width, $height) = ($image->Get('width'),
-					$image->Get('height'));
-		if ($width && $height) {
-		    $token->[2]{'width'} =$width;
-		    $token->[2]{'height'}=$height;
-		    $constructtag=1;
+	my ($osrc,$owidth,$oheight)=
+	    ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
+	my $ctag=&Apache::edit::get_new_args($token,$parstack,
+					     $safeeval,'src','alt',
+					     'TeXwidth','TeXheight',
+					     'width','height');
+	my ($nsrc,$nwidth,$nheight)=
+	    ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
+	my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
+	&image_replication($loc);
+	my ($iwidth,$iheight);
+	&Apache::lonnet::logthis("loc is $loc");
+	if (-e $loc) {
+	    my $image = Image::Magick->new;
+	    $image->Read($loc);
+	    ($iwidth, $iheight) = ($image->Get('width'),
+				   $image->Get('height'));
+	}
+	if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
+	    # changed image or no size specified,
+            # if they didn't explicitly change the 
+            # width or height use the ones from the image
+	    if ($iwidth && $iheight) {
+		if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
+		    $token->[2]{'width'} = $iwidth;$ctag=1;
+		}
+		if ($oheight == $nheight || (!$nwidth && !$nheight)) {
+		    $token->[2]{'height'}=$iheight;$ctag=1;
 		}
 	    }
 	}
-	if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);}
+	my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
+	# if we don't have a width or height
+	if ($iwidth && $cwidth && !$cheight) {
+	    $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
+	}
+	if ($iheight && $cheight && !$cwidth) {
+	    $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
+	}
+	if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
     }
     return $currentstring;
 }