David Graf has proposed merging 
lp:~zorba-coders/zorba/image-module-dont-pass-svg-as-binary into 
lp:zorba/image-module.

Commit message:
Passing the svg to the convert-svg function as a node or a string, instead of a 
binary.

Requested reviews:
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/image-module-dont-pass-svg-as-binary/+merge/131829

Passing the svg to the convert-svg function as a node or a string, instead of a 
binary.
-- 
https://code.launchpad.net/~zorba-coders/zorba/image-module-dont-pass-svg-as-binary/+merge/131829
Your team Zorba Coders is subscribed to branch lp:zorba/image-module.
=== modified file 'src/com/zorba-xquery/www/modules/image/basic.xq'
--- src/com/zorba-xquery/www/modules/image/basic.xq	2011-08-04 04:09:00 +0000
+++ src/com/zorba-xquery/www/modules/image/basic.xq	2012-10-29 07:59:20 +0000
@@ -50,6 +50,7 @@
 declare namespace err = "http://www.w3.org/2005/xqt-errors";;
 declare namespace ierr = "http://www.zorba-xquery.com/modules/image/error";;
 declare namespace ver = "http://www.zorba-xquery.com/options/versioning";;
+declare namespace svg = "http://www.w3.org/2000/svg";;
 declare option ver:module-version "1.0";
 
 (:~
@@ -165,9 +166,40 @@
  : @error ierr:IM001 the passed SVG is invalid.
  : @example test/Queries/image/basic_svg.xq
  :)
-declare function basic:convert-svg($svg as xs:base64Binary, $format as xs:string) as xs:base64Binary {
-  basic:convert-svg-impl($svg, image:imageFormat($format))
-};
-
-declare %private function basic:convert-svg-impl($svg as xs:base64Binary, $format as xs:string) as xs:base64Binary external;
+declare function basic:convert-svg(
+                   $svg as element(svg:svg),
+                   $format as xs:string)
+                 as xs:base64Binary {
+
+   let $ser-params :=                                                                           
+      <serialization-parameters
+         xmlns="http://www.w3.org/2010/xslt-xquery-serialization";>
+        <omit-xml-declaration value="no"/>
+      </serialization-parameters>
+   let $string as xs:string := fn:serialize($svg, $ser-params)
+   return
+     basic:convert-svg-impl($string, image:imageFormat($format))
+};
+
+(:~
+ : Converts an SVG image to a supported image format.
+ :
+ : @param $svg the image to convert as string
+ : @param $format target format 
+ : @return the resulting image
+ : @error ierr:IM001 the passed SVG is invalid.
+ : @example test/Queries/image/basic_svg.xq
+ :)
+declare function basic:convert-svg-string(
+                   $svg as xs:string,
+                   $format as xs:string)
+                 as xs:base64Binary {
+
+   basic:convert-svg-impl($svg, image:imageFormat($format))
+};
+
+declare %private function basic:convert-svg-impl(
+                            $svg as xs:string,
+                            $format as xs:string)
+                          as xs:base64Binary external;
 

=== modified file 'src/com/zorba-xquery/www/modules/image/basic.xq.src/basic.cpp'
--- src/com/zorba-xquery/www/modules/image/basic.xq.src/basic.cpp	2011-08-04 04:09:00 +0000
+++ src/com/zorba-xquery/www/modules/image/basic.xq.src/basic.cpp	2012-10-29 07:59:20 +0000
@@ -13,15 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #include "basic.h"
-#include <list> 
+
+#include <list>
 #include <sstream>
 #include <string>
+
+#include <zorba/base64.h>
 #include <zorba/empty_sequence.h>
-#include <zorba/base64.h>
 #include <zorba/singleton_item_sequence.h>
 #include <zorba/zorba.h>
+
 #include "basic_module.h"
 #include "draw_in_c.h"
 
@@ -105,11 +107,13 @@
 ItemSequence_t
 ConvertSVGFunction::evaluate(
   const ExternalFunction::Arguments_t& aArgs,
-  const StaticContext*                          aSctxCtx,
-  const DynamicContext*                         aDynCtx) const
+  const StaticContext*                 aSctxCtx,
+  const DynamicContext*                aDynCtx) const
 {
   Magick::Image lImage;
-  ImageFunction::getOneImageArg(aDynCtx, aArgs, 0, lImage);
+  String lSVG = ImageFunction::getOneStringArg(aArgs, 0);
+  ImageFunction::getImageFromString(aDynCtx, lSVG, lImage, false);   
+
   if (lImage.magick().compare("SVG") != 0) {
     ImageFunction::throwErrorWithQName(aDynCtx, "IM002", "The passed xs:base64Binary is not an image of type SVG");
   }

=== modified file 'src/com/zorba-xquery/www/modules/image/image_commons/image_function.cpp'
--- src/com/zorba-xquery/www/modules/image/image_commons/image_function.cpp	2012-09-27 00:20:46 +0000
+++ src/com/zorba-xquery/www/modules/image/image_commons/image_function.cpp	2012-10-29 07:59:20 +0000
@@ -316,9 +316,21 @@
 }
 
 void
-ImageFunction::getImageFromString(const DynamicContext* aDynamicContext, const String aString, Magick::Image& aImage) {
-
-  String lDecodedContent = zorba::encoding::Base64::decode(aString);
+ImageFunction::getImageFromString(const DynamicContext* aDynamicContext,
+                                  const String aString,
+                                  Magick::Image& aImage,
+                                  bool aIsBase64) {
+
+  String lDecodedContent;
+  if (aIsBase64)
+  {
+    lDecodedContent = zorba::encoding::Base64::decode(aString);
+  }
+  else
+  {
+    lDecodedContent = aString;
+  }
+
   Magick::Blob lBlob(lDecodedContent.c_str(), lDecodedContent.size());
 
   try {

=== modified file 'src/com/zorba-xquery/www/modules/image/image_commons/image_function.h'
--- src/com/zorba-xquery/www/modules/image/image_commons/image_function.h	2011-07-09 08:55:59 +0000
+++ src/com/zorba-xquery/www/modules/image/image_commons/image_function.h	2012-10-29 07:59:20 +0000
@@ -118,7 +118,9 @@
                                               Magick::Image& aImage);
 
       static void getImageFromString(const DynamicContext* aDynamicContext, 
-                                     const String aString, Magick::Image& aImage);
+                                     const String aString,
+                                     Magick::Image& aImage,
+                                     bool aIsBase64 = true);
 
       static void checkIfItemIsNull(Item& aItem);
 

=== modified file 'test/Queries/image/basic_svg.xq'
--- test/Queries/image/basic_svg.xq	2011-10-06 08:18:47 +0000
+++ test/Queries/image/basic_svg.xq	2012-10-29 07:59:20 +0000
@@ -9,6 +9,8 @@
 declare variable $local:image-dir := fn:concat(file:dir-name(fn:static-base-uri()), "/images/");
 
 
-let $svg-bird as xs:base64Binary := file:read-binary(concat($local:image-dir, "/test.svg"))
-let $jpeg-bird := basic:convert-svg($svg-bird, "JPEG")
-return not(empty($jpeg-bird))
+let $svg-bird as xs:string := file:read-text(concat($local:image-dir, "/test.svg"))
+let $svg-bird-node := fn:parse-xml($svg-bird)/*:svg
+let $jpeg-bird := basic:convert-svg-string($svg-bird, "JPEG")
+let $jpeg-bird2 := basic:convert-svg($svg-bird-node, "JPEG")
+return not(empty($jpeg-bird)) and not(empty($jpeg-bird2))

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to