Просмотр исходного кода

Mark Chiisai Japanese characters as complementChar that must not be broken for a new line (#881)

Azrou 5 лет назад
Родитель
Сommit
921896a745
3 измененных файлов с 17 добавлено и 4 удалено
  1. 4 2
      h2d/HtmlText.hx
  2. 4 2
      h2d/Text.hx
  3. 9 0
      hxd/Charset.hx

+ 4 - 2
h2d/HtmlText.hx

@@ -362,7 +362,8 @@ class HtmlText extends Text {
 				var g = font.getChar(cc);
 				var newline = cc == '\n'.code;
 				var esize = g.width + g.getKerningOffset(prevChar);
-				if ( font.charset.isBreakChar(cc) ) {
+				var nc = text.charCodeAt(i+1);
+				if ( font.charset.isBreakChar(cc) && (nc == null || !font.charset.isComplementChar(nc) )) {
 					// Case: Very first word in text makes the line too long hence we want to start it off on a new line.
 					if (x > maxWidth && textSplit.length == 0 && splitNode.node != null) {
 						metrics.push(makeLineInfo(x, info.height, info.baseLine));
@@ -378,7 +379,8 @@ class HtmlText extends Text {
 						var e = font.getChar(cc);
 						size += e.width + letterSpacing + e.getKerningOffset(prevChar);
 						prevChar = cc;
-						if ( font.charset.isBreakChar(cc) ) break;
+						var nc = text.charCodeAt(k+1);
+						if ( font.charset.isBreakChar(cc) && (nc == null || !font.charset.isComplementChar(nc)) ) break;
 					}
 					// Avoid empty line when last char causes line-break while being CJK
 					if ( size > maxWidth && i != max - 1 ) {

+ 4 - 2
h2d/Text.hx

@@ -217,7 +217,8 @@ class Text extends Drawable {
 			var e = font.getChar(cc);
 			var newline = cc == '\n'.code;
 			var esize = e.width + e.getKerningOffset(prevChar);
-			if( font.charset.isBreakChar(cc) ) {
+			var nc = text.charCodeAt(i+1);
+			if( font.charset.isBreakChar(cc) && (nc == null || !font.charset.isComplementChar(nc)) ) {
 				if( lines.length == 0 && leftMargin > 0 && x > maxWidth ) {
 					lines.push("");
 					if ( sizes != null ) sizes.push(leftMargin);
@@ -236,7 +237,8 @@ class Text extends Drawable {
 					var e = font.getChar(cc);
 					size += e.width + letterSpacing + e.getKerningOffset(prevChar);
 					prevChar = cc;
-					if( font.charset.isBreakChar(cc) ) break;
+					var nc = text.charCodeAt(k+1);
+					if( font.charset.isBreakChar(cc) && (nc == null || !font.charset.isComplementChar(nc)) ) break;
 				}
 				if( size > maxWidth || (!breakFound && size + afterData > maxWidth) ) {
 					newline = true;

+ 9 - 0
hxd/Charset.hx

@@ -138,6 +138,15 @@ class Charset {
 		return isSpace(code) || isCJK(code);
 	}
 
+	static var complementChars : Map<Int,Bool> = {
+		var str = "ヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻";
+		[for( i in 0...str.length ) str.charCodeAt(i) => true];
+	}
+
+	public function isComplementChar(code) {
+		return complementChars.exists(code);
+	}
+
 	static var inst : Charset;
 	public static function getDefault() {
 		if( inst == null ) inst = new Charset();