浏览代码

handling cases none printable characters and fix index out of range error

/main
fzhangtj 6 年前
当前提交
453e28e5
共有 6 个文件被更改,包括 28 次插入9 次删除
  1. 15
      Runtime/service/keyboard.cs
  2. 8
      Runtime/service/text_input.cs
  3. 8
      Runtime/ui/painting/txt/font_manager.cs
  4. 2
      Runtime/ui/painting/txt/mesh_generator.cs
  5. 2
      Runtime/ui/txt/layout.cs
  6. 2
      Runtime/ui/txt/linebreaker.cs

15
Runtime/service/keyboard.cs


}
var currentEvent = Event.current;
if (currentEvent != null && currentEvent.type == EventType.KeyDown) {
var action = TextInputUtils.getInputAction(currentEvent);
if (action != null) {

if (action == null || action == TextInputAction.newline) {
if (currentEvent.keyCode == KeyCode.None) {
this._value = this._value.clearCompose().insert(new string(currentEvent.character, 1));
char ch = currentEvent.character;
if (ch == '\r' || ch == 3) {
ch = '\n';
}
this._value = this._value.clearCompose();
if (_validateCharacter(ch)) {
this._value = this._value.insert(new string(ch, 1));
}
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
}
}

}
public void Dispose() {
}
static bool _validateCharacter(char ch) {
return ch >= ' ' || ch == '\t' || ch == '\r' || ch == 10 || ch == '\n';
}
}

8
Runtime/service/text_input.cs


return this;
}
newText = this.selection.textBefore(this.text) + text + this.selection.textAfter(this.text);
newSelection = TextSelection.collapsed(this.selection.start + text.Length);
var selection = this.selection;
if (selection.start < 0) {
selection = TextSelection.collapsed(0, this.selection.affinity);
}
newText = selection.textBefore(this.text) + text + selection.textAfter(this.text);
newSelection = TextSelection.collapsed(selection.start + text.Length);
return new TextEditingValue(
text: newText, selection: newSelection, composing: TextRange.empty
);

8
Runtime/ui/painting/txt/font_manager.cs


public static class FontExtension
{
public static CharacterInfo mustGetCharacterInfo(this Font font, char ch, int fontSize, UnityEngine.FontStyle fontStyle)
public static CharacterInfo getCharacterInfo(this Font font, char ch, int fontSize, UnityEngine.FontStyle fontStyle)
D.assert(success, $"fail to get character info for character '{ch}' (code{(int)ch}) from font: ${font.name}");
if (!success) {
Debug.LogWarning($"character info not found from the given font: character '{ch}' (code{(int)ch}) font: ${font.name}");
}
}
}
}
}

2
Runtime/ui/painting/txt/mesh_generator.cs


continue;
}
CharacterInfo charInfo = font.mustGetCharacterInfo(ch, fontSizeToLoad, style.UnityFontStyle);
CharacterInfo charInfo = font.getCharacterInfo(ch, fontSizeToLoad, style.UnityFontStyle);
var minX = charInfo.minX / this._scale;
var maxX = charInfo.maxX / this._scale;
var minY = charInfo.minY / this._scale;

2
Runtime/ui/txt/layout.cs


for (int i = 0; i < count; i++) {
int charIndex = start + i;
var ch = text[charIndex];
CharacterInfo characterInfo = font.mustGetCharacterInfo(ch, style.UnityFontSize, style.UnityFontStyle);
CharacterInfo characterInfo = font.getCharacterInfo(ch, style.UnityFontSize, style.UnityFontStyle);
var rect = Rect.fromLTRB(characterInfo.minX, -characterInfo.maxY, characterInfo.maxX,
-characterInfo.minY);

2
Runtime/ui/txt/linebreaker.cs


if (this._tabWidth == int.MaxValue) {
this._font.RequestCharactersInTexture(" ", this._fontSize);
CharacterInfo characterInfo = this._font.mustGetCharacterInfo(' ', this._fontSize, UnityEngine.FontStyle.Normal);
CharacterInfo characterInfo = this._font.getCharacterInfo(' ', this._fontSize, UnityEngine.FontStyle.Normal);
this._tabWidth = characterInfo.advance * kTabSpaceCount;
}

正在加载...
取消
保存