Advertisement
Guest User

Patch

a guest
Aug 27th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.74 KB | None | 0 0
  1. diff --git a/lib/irrlicht/include/utfwrapping.h b/lib/irrlicht/include/utfwrapping.h
  2. index e69de29..ee97be9 100644
  3. --- a/lib/irrlicht/include/utfwrapping.h
  4. +++ b/lib/irrlicht/include/utfwrapping.h
  5. @@ -0,0 +1,104 @@
  6. +// Copyright (C) 2015 Ben Au
  7. +// This file is part of the "Irrlicht Engine".
  8. +// For conditions of distribution and use, see copyright notice in irrlicht.h
  9. +
  10. +namespace irr
  11. +{
  12. +namespace gui
  13. +{
  14. +
  15. +//Here a list of characters that don't start or end a line for chinese/japanese/korean
  16. +//Only commonly use and full width characters are included
  17. +//You should use full width characters when writing CJK, like using "。"instead of a "."
  18. +//You can add more characters if needed
  19. +//For full list please visit http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/kinsoku.html
  20. +
  21. +bool UtfNoStarting (wchar_t c)
  22. +{
  23. + switch (c)
  24. + {
  25. + case 12293: //々
  26. + return true;
  27. + case 12297: //〉
  28. + return true;
  29. + case 12299: //》
  30. + return true;
  31. + case 12301: //」
  32. + return true;
  33. + case 65373: //}
  34. + return true;
  35. + case 12309: //〕
  36. + return true;
  37. + case 65289: //)
  38. + return true;
  39. + case 12303: //』
  40. + return true;
  41. + case 12305: //】
  42. + return true;
  43. + case 12311: //〗
  44. + return true;
  45. + case 65281: //!
  46. + return true;
  47. + case 65285: //%
  48. + return true;
  49. + case 65311: //?
  50. + return true;
  51. + case 65344: //`
  52. + return true;
  53. + case 65292: //,
  54. + return true;
  55. + case 65306: //:
  56. + return true;
  57. + case 65307: //;
  58. + return true;
  59. + case 65294: //.
  60. + return true;
  61. + case 12290: //。
  62. + return true;
  63. + case 12289: //、
  64. + return true;
  65. + default:
  66. + return false;
  67. + }
  68. +}
  69. +
  70. +bool UtfNoEnding (wchar_t c)
  71. +{
  72. + switch (c)
  73. + {
  74. + case 12296: //〈
  75. + return true;
  76. + case 12298: //《
  77. + return true;
  78. + case 12300: //「
  79. + return true;
  80. + case 65371: //{
  81. + return true;
  82. + case 12308: //〔
  83. + return true;
  84. + case 65288: //(
  85. + return true;
  86. + case 12302: //『
  87. + return true;
  88. + case 12304: //【
  89. + return true;
  90. + case 12310: //〖
  91. + return true;
  92. + default:
  93. + return false;
  94. + }
  95. +}
  96. +
  97. +//Helper function
  98. +
  99. +bool breakable (wchar_t c)
  100. +{
  101. + if ((c > 12287 && c < 40960) || //Common CJK words
  102. + (c > 44031 && c < 55204) || //Hangul
  103. + (c > 63743 && c < 64256) || //More Chinese
  104. + c == 173 || c == L' ' || c == 0) //Soft hyphen and white space
  105. + return true;
  106. + return false;
  107. +}
  108. +} // end namespace core
  109. +} // end namespace irr
  110. diff --git a/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp b/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp
  111. index 095dd64..e07d894 100644
  112. --- a/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp
  113. +++ b/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp
  114. @@ -10,9 +10,7 @@
  115. #include "IGUIFont.h"
  116. #include "IVideoDriver.h"
  117. #include "rect.h"
  118. -
  119. -#define CJK_START 12287
  120. -#define CJK_END 40960
  121. +#include "utfwrapping.h"
  122.  
  123. namespace irr
  124. {
  125. @@ -357,102 +355,77 @@ void CGUIStaticText::breakText()
  126. lineBreak = true;
  127. c = '\0';
  128. }
  129. + word += c;
  130.  
  131. - bool isWhitespace = (c == L' ' || c == 0);
  132. - if ( !isWhitespace )
  133. + if (word.size())
  134. {
  135. - // part of a word
  136. - word += c;
  137. -
  138. - //Check for CJK, show them first if out of range of displaying area
  139. - if (Text[i] > CJK_START && Text[i] < CJK_END)
  140. - {
  141. - const s32 cjklgth = font->getDimension(word.c_str()).Width;
  142. - if (cjklgth > (elWidth - 23))
  143. - {
  144. - BrokenText.push_back(line);
  145. - length = cjklgth;
  146. - line = word;
  147. - word = L"";
  148. - whitespace = L"";
  149. - }
  150. - }
  151. - }
  152. + const s32 wordlgth = font->getDimension(word.c_str()).Width;
  153.  
  154. - if ( isWhitespace || i == (size-1))
  155. - {
  156. - if (word.size())
  157. - {
  158. - // here comes the next whitespace, look if
  159. - // we must break the last word to the next line.
  160. - const s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
  161. - const s32 wordlgth = font->getDimension(word.c_str()).Width;
  162. -
  163. - if (wordlgth > elWidth)
  164. + if (length && (length + wordlgth > elWidth))
  165. + { // too long to fit inside
  166. + // break to next line
  167. + unsigned int where = 1;
  168. + while (where != line.size()) //Find the first breakable position
  169. {
  170. - // This word is too long to fit in the available space, look for
  171. - // the Unicode Soft HYphen (SHY / 00AD) character for a place to
  172. - // break the word at
  173. - int where = word.findFirst( wchar_t(0x00AD) );
  174. - if (where != -1)
  175. + if (UtfNoEnding(Text[i - where]) || //Prevent unsuitable character from displaying
  176. + UtfNoStarting(Text[i - where]) || //at the position of starting or ending of a line
  177. + UtfNoStarting(Text[i + 1 - where])) //Handle case which more than one non-newline-starting characters are together
  178. {
  179. - core::stringw first = word.subString(0, where);
  180. - core::stringw second = word.subString(where, word.size() - where);
  181. - BrokenText.push_back(line + first + L"-");
  182. - const s32 secondLength = font->getDimension(second.c_str()).Width;
  183. -
  184. - length = secondLength;
  185. - line = second;
  186. + where++;
  187. + continue;
  188. }
  189. + if (breakable(Text[i - where]))
  190. + break;
  191. else
  192. - {
  193. - // No soft hyphen found, so there's nothing more we can do
  194. - // break to next line
  195. - if (length)
  196. - BrokenText.push_back(line);
  197. - length = wordlgth;
  198. - line = word;
  199. - }
  200. + where++;
  201. }
  202. - else if (length && (length + wordlgth + whitelgth > elWidth))
  203. + if (where != line.size())
  204. {
  205. - // break to next line
  206. - BrokenText.push_back(line);
  207. - length = wordlgth;
  208. - line = word;
  209. + core::stringw first = line.subString(0, line.size() + 1 - where);
  210. + core::stringw second = line.subString(line.size() + 1 - where , where - 1);
  211. + if (first.lastChar() == wchar_t(0x00AD))
  212. + BrokenText.push_back(first + L"-"); //Print the Unicode Soft HYphen (SHY / 00AD) character
  213. + else
  214. + BrokenText.push_back(first);
  215. + const s32 secondLength = font->getDimension(second.c_str()).Width;
  216. +
  217. + length = secondLength + wordlgth;
  218. + line = second + word;
  219. }
  220. - else
  221. + else if (breakable(c) || UtfNoEnding(c) || UtfNoStarting(c)) //Unusual case
  222. + {
  223. + BrokenText.push_back(line); //Force breaking to next line too if last word is breakable,
  224. + line = word; //it happens when someone writes too many non-newline-starting
  225. + length = wordlgth; //chars in the first line, so we ignore the rules.
  226. + }
  227. + // No suitable place to break words, so there's nothing more we can do
  228. + // break to next line
  229. + else
  230. {
  231. - // add word to line
  232. - line += whitespace;
  233. line += word;
  234. - length += whitelgth + wordlgth;
  235. + length += wordlgth;
  236. }
  237. -
  238. - word = L"";
  239. - whitespace = L"";
  240. }
  241. -
  242. - if ( isWhitespace )
  243. - {
  244. - whitespace += c;
  245. - }
  246. -
  247. - // compute line break
  248. - if (lineBreak)
  249. + else
  250. {
  251. - line += whitespace;
  252. line += word;
  253. - BrokenText.push_back(line);
  254. - line = L"";
  255. - word = L"";
  256. - whitespace = L"";
  257. - length = 0;
  258. + length += wordlgth;
  259. }
  260. +
  261. + word = L"";
  262. +
  263. + }
  264. + // compute line break
  265. + if (lineBreak)
  266. + {
  267. + line += word;
  268. + BrokenText.push_back(line);
  269. + line = L"";
  270. + word = L"";
  271. + length = 0;
  272. }
  273. }
  274.  
  275. - line += whitespace;
  276. line += word;
  277. BrokenText.push_back(line);
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement