فهرست منبع

Implement HtmlText.imageSpacing

Yanrishatum 5 سال پیش
والد
کامیت
d245dc7ca7
1فایلهای تغییر یافته به همراه14 افزوده شده و 3 حذف شده
  1. 14 3
      h2d/HtmlText.hx

+ 14 - 3
h2d/HtmlText.hx

@@ -5,6 +5,10 @@ import h2d.Text;
 class HtmlText extends Text {
 class HtmlText extends Text {
 
 
 	public var condenseWhite(default,set) : Bool = true;
 	public var condenseWhite(default,set) : Bool = true;
+	/**
+		Spacing after <img> tags in pixels.
+	**/
+	public var imageSpacing(default,set):Float = 1;
 
 
 	var elements : Array<Object> = [];
 	var elements : Array<Object> = [];
 	var xPos : Float;
 	var xPos : Float;
@@ -121,7 +125,7 @@ class HtmlText extends Text {
 				newLine = true;
 				newLine = true;
 			case "img":
 			case "img":
 				var i = loadImage(e.get("src"));
 				var i = loadImage(e.get("src"));
-				len = (i == null ? 8 : i.width) + letterSpacing;
+				len = (i == null ? 8 : i.width) + imageSpacing;
 				newLine = false;
 				newLine = false;
 			case "font":
 			case "font":
 				for( a in e.attributes() ) {
 				for( a in e.attributes() ) {
@@ -384,7 +388,7 @@ class HtmlText extends Text {
 				newLine = false;
 				newLine = false;
 				var i = loadImage(e.get("src"));
 				var i = loadImage(e.get("src"));
 				if( i == null ) i = Tile.fromColor(0xFF00FF, 8, 8);
 				if( i == null ) i = Tile.fromColor(0xFF00FF, 8, 8);
-				if( realMaxWidth >= 0 && xPos + i.width + letterSpacing + remainingSize(sizes) > realMaxWidth && xPos > 0 ) {
+				if( realMaxWidth >= 0 && xPos + i.width + imageSpacing + remainingSize(sizes) > realMaxWidth && xPos > 0 ) {
 					if( xPos > xMax ) xMax = xPos;
 					if( xPos > xMax ) xMax = xPos;
 					xPos = 0;
 					xPos = 0;
 					yPos += font.lineHeight + lineSpacing;
 					yPos += font.lineHeight + lineSpacing;
@@ -398,7 +402,7 @@ class HtmlText extends Text {
 					b.y = py;
 					b.y = py;
 					elements.push(b);
 					elements.push(b);
 				}
 				}
-				xPos += i.width + letterSpacing;
+				xPos += i.width + imageSpacing;
 			default:
 			default:
 			}
 			}
 			for( child in e )
 			for( child in e )
@@ -447,6 +451,13 @@ class HtmlText extends Text {
 		}
 		}
 	}
 	}
 
 
+	function set_imageSpacing(s) {
+		if (imageSpacing == s) return s;
+		imageSpacing = s;
+		rebuild();
+		return s;
+	}
+
 	override function set_textColor(c) {
 	override function set_textColor(c) {
 		if( this.textColor == c ) return c;
 		if( this.textColor == c ) return c;
 		this.textColor = c;
 		this.textColor = c;