svn commit: r641064 - in /lenya/trunk/src/modules/svg: imageMetaData.xml sitemap.xmap xslt/parameterize.xsl xslt/scale.xsl

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Tue Mar 25 15:52:01 2008
New Revision: 641064

URL: http://svn.apache.org/viewvc?rev=641064&view=rev
Log:
Allow to omit width or height parameter when resizing images using the svg module.

Added:
    lenya/trunk/src/modules/svg/imageMetaData.xml
    lenya/trunk/src/modules/svg/xslt/parameterize.xsl
Modified:
    lenya/trunk/src/modules/svg/sitemap.xmap
    lenya/trunk/src/modules/svg/xslt/scale.xsl

Added: lenya/trunk/src/modules/svg/imageMetaData.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/imageMetaData.xml?rev=641064&view=auto
==============================================================================
--- lenya/trunk/src/modules/svg/imageMetaData.xml (added)
+++ lenya/trunk/src/modules/svg/imageMetaData.xml Tue Mar 25 15:52:01 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<svg:svg xmlns:svg="http://www.w3.org/2000/svg"
+  xmlns:media="http://apache.org/lenya/metadata/media/1.0"
+  xmlns:meta="http://apache.org/lenya/meta/1.0/">
+  <media:width><meta:value element="width" ns="http://apache.org/lenya/metadata/media/1.0"
+    uuid="" lang=""/></media:width>
+  <media:height><meta:value element="height" ns="http://apache.org/lenya/metadata/media/1.0"
+    uuid="" lang=""/></media:height>
+</svg:svg>
\ No newline at end of file

Modified: lenya/trunk/src/modules/svg/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/sitemap.xmap?rev=641064&r1=641063&r2=641064&view=diff
==============================================================================
--- lenya/trunk/src/modules/svg/sitemap.xmap (original)
+++ lenya/trunk/src/modules/svg/sitemap.xmap Tue Mar 25 15:52:01 2008
@@ -87,7 +87,15 @@
           </map:act>  
         </map:match>
         
-        <map:generate src="dummy.xml"/>
+        <map:generate src="imageMetaData.xml"/>
+        <map:transform src="fallback://lenya/modules/svg/xslt/parameterize.xsl">
+          <map:parameter name="uuid" value="{page-envelope:document-uuid}"/>
+          <map:parameter name="language" value="{page-envelope:document-language}"/>
+        </map:transform>
+        <map:transform type="metaData">
+          <map:parameter name="pubid" value="{1}"/>
+          <map:parameter name="area" value="{2}"/>
+        </map:transform>
         <map:act type="resource-exists">
           <map:parameter name="url" value="lenya-document:{page-envelope:document-uuid},lang={page-envelope:document-language},pub={1},area={2}"/>
           <map:transform src="xslt/scale.xsl">

Added: lenya/trunk/src/modules/svg/xslt/parameterize.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/xslt/parameterize.xsl?rev=641064&view=auto
==============================================================================
--- lenya/trunk/src/modules/svg/xslt/parameterize.xsl (added)
+++ lenya/trunk/src/modules/svg/xslt/parameterize.xsl Tue Mar 25 15:52:01 2008
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+  
+  <xsl:param name="uuid"/>
+  <xsl:param name="language"/>
+  
+  
+  <xsl:template match="@uuid">
+    <xsl:attribute name="uuid"><xsl:value-of select="$uuid"/></xsl:attribute>
+  </xsl:template>
+  
+  
+  <xsl:template match="@lang">
+    <xsl:attribute name="lang"><xsl:value-of select="$language"/></xsl:attribute>
+  </xsl:template>
+  
+
+  <xsl:template match="@*|node()" priority="-1">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+  
+
+</xsl:stylesheet>
\ No newline at end of file

Modified: lenya/trunk/src/modules/svg/xslt/scale.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/xslt/scale.xsl?rev=641064&r1=641063&r2=641064&view=diff
==============================================================================
--- lenya/trunk/src/modules/svg/xslt/scale.xsl (original)
+++ lenya/trunk/src/modules/svg/xslt/scale.xsl Tue Mar 25 15:52:01 2008
@@ -18,15 +18,35 @@
 <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:svg="http://www.w3.org/2000/svg"
-  xmlns:xlink="http://www.w3.org/1999/xlink">
+  xmlns:xlink="http://www.w3.org/1999/xlink"
+  xmlns:media="http://apache.org/lenya/metadata/media/1.0">
   
   <xsl:param name="url"/>
   <xsl:param name="height"/>
   <xsl:param name="width"/>
   
-  <xsl:template match="/">
-    <svg width="{$width}" height="{$height}" version="1.1">
-      <image x="0" y="0" width="{$width}" height="{$height}" xlink:href="{$url}" preserveAspectRatio="none"/>        
+  <xsl:variable name="imgWidth" select="/svg:svg/media:width"/>
+  <xsl:variable name="imgHeight" select="/svg:svg/media:height"/>
+  
+  <xsl:variable name="targetWidth">
+    <xsl:choose>
+      <xsl:when test="$width"><xsl:value-of select="$width"/></xsl:when>
+      <xsl:when test="$height"><xsl:value-of select="($height div $imgHeight) * $imgWidth"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="$imgWidth"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  
+  <xsl:variable name="targetHeight">
+    <xsl:choose>
+      <xsl:when test="$height"><xsl:value-of select="$height"/></xsl:when>
+      <xsl:when test="$width"><xsl:value-of select="($width div $imgWidth) * $imgHeight"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="$imgHeight"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  
+  <xsl:template match="/svg:svg">
+    <svg width="{$targetWidth}" height="{$targetHeight}" version="1.1">
+      <image x="0" y="0" width="{$targetWidth}" height="{$targetHeight}" xlink:href="{$url}" preserveAspectRatio="none"/>        
     </svg>
   </xsl:template>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.