[ease] HTML export improvements.



commit 7793547042279aadaaf3d767d5c7457b20ff3cb9
Author: Nate Stedman <natesm gmail com>
Date:   Thu Aug 19 18:07:10 2010 -0400

    HTML export improvements.
    
    - Shapes, PDFs, and gradient backgrounds supported
    - Fixed text color
    - Added uchar get/set to Color

 ease-core/ease-color.vala         |   97 +++++++++++++++++++++++++++++++++++--
 ease-core/ease-html-exporter.vala |   40 +++++++++++++++
 ease-core/ease-image-element.vala |    3 +-
 ease-core/ease-pdf-element.vala   |   30 +++++++++++-
 ease-core/ease-shape-element.vala |   32 ++++++++++--
 ease-core/ease-slide.vala         |   72 +++++++++++++++++++++-------
 ease-core/ease-text-element.vala  |    2 +-
 7 files changed, 247 insertions(+), 29 deletions(-)
---
diff --git a/ease-core/ease-color.vala b/ease-core/ease-color.vala
index 1b5e540..347f7b2 100644
--- a/ease-core/ease-color.vala
+++ b/ease-core/ease-color.vala
@@ -138,6 +138,95 @@ public class Ease.Color : GLib.Object
 	}
 	private double alpha_priv;
 	
+	
+	/**
+	 * The red value of this color, as an 8-bit unsigned integer.
+	 */
+	public uint8 red255
+	{
+		get { return (uint8)(255 * red_priv); }
+		set
+		{
+			if (value < 0)
+			{
+				warning("red value must be >= 0, %f is not", value);
+				red_priv = 0;
+			}
+			else if (value > 1)
+			{
+				warning("red value must be <= 255, %f is not", value);
+				red_priv = 1;
+			}
+			else red_priv = value / 255.0;
+		}
+	}
+	
+	/**
+	 * The green value of this color, as an 8-bit unsigned integer.
+	 */
+	public uint8 green255
+	{
+		get { return (uint8)(255 * green_priv); }
+		set
+		{
+			if (value < 0)
+			{
+				warning("green value must be >= 0, %f is not", value);
+				green_priv = 0;
+			}
+			else if (value > 1)
+			{
+				warning("green value must be <= 255, %f is not", value);
+				green_priv = 1;
+			}
+			else green_priv = value / 255.0;
+		}
+	}
+	
+	/**
+	 * The blue value of this color, as an 8-bit unsigned integer.
+	 */
+	public uint8 blue255
+	{
+		get { return (uint8)(255 * blue_priv); }
+		set
+		{
+			if (value < 0)
+			{
+				warning("blue value must be >= 0, %f is not", value);
+				blue_priv = 0;
+			}
+			else if (value > 1)
+			{
+				warning("blue value must be <= 255, %f is not", value);
+				blue_priv = 1;
+			}
+			else blue_priv = value / 255.0;
+		}
+	}
+	
+	/**
+	 * The alpha (transparency) of this color, as an 8-bit unsigned integer.
+	 */
+	public uint8 alpha255
+	{
+		get { return (uint8)(255 * alpha_priv); }
+		set
+		{
+			if (value < 0)
+			{
+				warning("alpha value must be >= 0, %f is not", value);
+				alpha_priv = 0;
+			}
+			else if (value > 1)
+			{
+				warning("alpha value must be <= 255, %f is not", value);
+				alpha_priv = 1;
+			}
+			else alpha_priv = value / 255.0;
+		}
+	}
+	
 	/**
 	 * A Clutter.Color representation of this color. Changes made to the
 	 * the returned color are not reflected in this color.
@@ -146,10 +235,10 @@ public class Ease.Color : GLib.Object
 	{
 		get
 		{
-			return { (uchar)(255 * red),
-			         (uchar)(255 * green),
-			         (uchar)(255 * blue),
-			         (uchar)(255 * alpha) };
+			return { (uint8)(255 * red),
+			         (uint8)(255 * green),
+			         (uint8)(255 * blue),
+			         (uint8)(255 * alpha) };
 		}
 		set
 		{
diff --git a/ease-core/ease-html-exporter.vala b/ease-core/ease-html-exporter.vala
index 5175cf3..05526b5 100644
--- a/ease-core/ease-html-exporter.vala
+++ b/ease-core/ease-html-exporter.vala
@@ -30,6 +30,12 @@ public class Ease.HTMLExporter : GLib.Object
 	private Gtk.Dialog window;
 	private Gtk.ProgressBar progress;
 	
+	public int render_index
+	{
+		get { return render_index_priv++; }
+	}
+	private int render_index_priv = 0;
+	
 	/**
 	 * The path to export HTML to.
 	 */
@@ -140,6 +146,40 @@ public class Ease.HTMLExporter : GLib.Object
 	}
 	
 	/**
+	 * Copies a rendered file to the output path. Returns the filename.
+	 */
+	public string copy_rendered(string rendered)
+	{	
+		var source = File.new_for_path(rendered);
+		var dest_path = Path.build_filename("Rendered",
+                                            render_index.to_string() + ".png");
+		var destination = File.new_for_path(Path.build_filename(path + " Media",
+		                                                        dest_path));
+
+		try
+		{
+			// if the destination directory doesn't exist, make it
+			var parent = destination.get_parent();
+			if (!parent.query_exists(null))
+			{
+				parent.make_directory_with_parents(null);
+			}
+			
+			// copy the image
+			source.copy(destination,
+				        FileCopyFlags.OVERWRITE,
+				        null,
+				        null);
+		}
+		catch (GLib.Error e)
+		{
+			error_dialog(_("Error Copying File"), e.message);
+		}
+		
+		return dest_path;
+	}
+	
+	/**
 	 * HTML header for presentations.
 	 */
 	public static const string HEADER =
diff --git a/ease-core/ease-image-element.vala b/ease-core/ease-image-element.vala
index 75d430a..3bad007 100644
--- a/ease-core/ease-image-element.vala
+++ b/ease-core/ease-image-element.vala
@@ -96,7 +96,8 @@ public class Ease.ImageElement : MediaElement
 		html += " position: absolute;\" ";
 		
 		// add the image
-		html += "src=\"" + exporter.basename + " " + filename +
+		html += "src=\"" +
+		        (exporter.basename + " " + filename).replace(" ", "%20") +
 		        "\" alt=\"Image\" />";
 		
 		// copy the image file
diff --git a/ease-core/ease-pdf-element.vala b/ease-core/ease-pdf-element.vala
index b552d57..408d628 100644
--- a/ease-core/ease-pdf-element.vala
+++ b/ease-core/ease-pdf-element.vala
@@ -59,9 +59,37 @@ public class Ease.PdfElement : MediaElement
 		return obj;
 	}
 	
+	/**
+	 * Renders this PdfElement as HTML.
+	 */
 	public override string html_render(HTMLExporter exporter)
 	{
-		return "<!-- PDFs not supported in HTML yet -->";
+		var dir = Temp.request();
+		var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32,
+		                                     (int)width, (int)height);
+		var cr = new Cairo.Context(surface);
+		cairo_render(cr);
+		
+		var path = Path.build_filename(dir, exporter.render_index.to_string());
+		surface.write_to_png(path);
+		var output = exporter.copy_rendered(path);
+		
+		// open the img tag
+		var html = "<img class=\"pdf element\" ";
+		
+		// set the image's style
+		html += "style=\"";
+		html += "left:" + x.to_string() + "px;";
+		html += " top:" + y.to_string() + "px;";
+		html += " width:" + width.to_string() + "px;";
+		html += " height:" + height.to_string() + "px;";
+		html += " position: absolute;\" ";
+		
+		// add the image
+		return html + "src=\"" +
+		              (exporter.basename +
+		               " Media/" + output).replace(" ", "%20") +
+		              "\" alt=\"PDF\" />";
 	}
 	
 	public override void cairo_render(Cairo.Context context) throws Error
diff --git a/ease-core/ease-shape-element.vala b/ease-core/ease-shape-element.vala
index d6c7c82..962185f 100644
--- a/ease-core/ease-shape-element.vala
+++ b/ease-core/ease-shape-element.vala
@@ -80,14 +80,36 @@ public class Ease.ShapeElement : CairoElement
 	}
 	
 	/**
-	 * Renders (or doesn't, it isn't supported yet) this ShapeElement as HTML.
-	 * When implemented, this should be done in CairoElement probably, so it
-	 * can be generic to anything else Cairo-based.
+	 * Renders this ShapeElement as HTML.
 	 */
 	public override string html_render(HTMLExporter exporter)
 	{
-		warning("HTML Export not currently supported for shapes");
-		return "<!-- HTML Export not supported for shapes -->";
+		var dir = Temp.request();
+		var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32,
+		                                     (int)width, (int)height);
+		var cr = new Cairo.Context(surface);
+		cairo_render(cr);
+		
+		var path = Path.build_filename(dir, exporter.render_index.to_string());
+		surface.write_to_png(path);
+		var output = exporter.copy_rendered(path);
+		
+		// open the img tag
+		var html = "<img class=\"shape element\" ";
+		
+		// set the image's style
+		html += "style=\"";
+		html += "left:" + x.to_string() + "px;";
+		html += " top:" + y.to_string() + "px;";
+		html += " width:" + width.to_string() + "px;";
+		html += " height:" + height.to_string() + "px;";
+		html += " position: absolute;\" ";
+		
+		// add the image
+		return html + "src=\"" +
+		              (exporter.basename +
+		               " Media/" + output).replace(" ", "%20") +
+		              "\" alt=\"Shape\" />";
 	}
 	
 	/**
diff --git a/ease-core/ease-slide.vala b/ease-core/ease-slide.vala
index 4b496c9..44e7733 100644
--- a/ease-core/ease-slide.vala
+++ b/ease-core/ease-slide.vala
@@ -604,26 +604,64 @@ public class Ease.Slide : GLib.Object, UndoSource
 		html += "<div class=\"slide\" id=\"slide" +
 		        index.to_string() + "\" ";
 		
-		if (background.image.filename == null)
+		switch (background.background_type)
 		{
-			// give the slide a background color
-			html += "style=\"background-color: " +
-			        background.color.clutter.to_string().
-			        substring(0, 7) + "\">";
-		}
-		else
-		{
-			// close the tag
-			html += ">";
+			case BackgroundType.COLOR:
+				// give the slide a background color
+				html += "style=\"background-color: " +
+					    background.color.clutter.to_string().
+					    substring(0, 7) + "\">";
+				break;
+			
+			case BackgroundType.GRADIENT:
+				// close opening div
+				html += ">";
+				
+				var dir = Temp.request();
+				var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32,
+						                             (int)width, (int)height);
+				var cr = new Cairo.Context(surface);
+				cairo_render(cr);
+		
+				var path = Path.build_filename(
+					dir, exporter.render_index.to_string());
+				surface.write_to_png(path);
+				var output = exporter.copy_rendered(path);
+		
+				// open the img tag
+				html += "<img ";
+		
+				// set the image's style
+				html += "style=\"";
+				html += "left: 0px;";
+				html += " top: 0px;";
+				html += " width:" + parent.width.to_string() + "px;";
+				html += " height:" + parent.height.to_string() + "px;";
+				html += " position: absolute;\" ";
+		
+				// add the image
+				html += "src=\"" +
+						(exporter.basename +
+						 " Media/" + output).replace(" ", "%20") +
+						"\" alt=\"PDF\" />";
+						      
+				break;
+			
+			case BackgroundType.IMAGE:
+				// close the tag
+				html += ">";
 			
-			// add the background image
-			html += "<img src=\"" + exporter.basename + " " + background.image.filename +
-			        "\" alt=\"Background\" width=\"" +
-			        parent.width.to_string() + "\" height=\"" +
-			        parent.height.to_string() + "\"/>";
+				// add the background image
+				html += "<img src=\"" +
+					    (exporter.basename + " " +
+					     background.image.filename).replace(" ", "%20") +
+					    "\" alt=\"Background\" width=\"" +
+					    parent.width.to_string() + "\" height=\"" +
+					    parent.height.to_string() + "\"/>";
 
-			// copy the image file
-			exporter.copy_file(background.image.filename, parent.path);
+				// copy the image file
+				exporter.copy_file(background.image.filename, parent.path);
+				break;
 		}
 		
 		// add tags for each Element
diff --git a/ease-core/ease-text-element.vala b/ease-core/ease-text-element.vala
index 3fd0797..0f01663 100644
--- a/ease-core/ease-text-element.vala
+++ b/ease-core/ease-text-element.vala
@@ -212,7 +212,7 @@ public class Ease.TextElement : Element
 		
 		// set the text-specific properties of the element
 		html += " color:" + 
-		        @"rgb($(color.red),$(color.green),$(color.blue));";
+		        @"rgb($(color.red255),$(color.green255),$(color.blue255));";
 		        
 		html += " font-family:'" + text_font + "', sans-serif;";
 		        



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]