mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-25 00:33:24 +01:00
Validate more fields in custom layouts
This adds some errors: - 'script' or 'numpad_script' is set an empty string. - Multiple '<modmap>' elements. - 'shift', 'width' and 'height' on every nodes that support them are clamped to a valid value.
This commit is contained in:
parent
b432f1d773
commit
45fc18576e
@ -236,9 +236,13 @@ public final class KeyboardData
|
|||||||
boolean bottom_row = attribute_bool(parser, "bottom_row", true);
|
boolean bottom_row = attribute_bool(parser, "bottom_row", true);
|
||||||
float specified_kw = attribute_float(parser, "width", 0f);
|
float specified_kw = attribute_float(parser, "width", 0f);
|
||||||
String script = parser.getAttributeValue(null, "script");
|
String script = parser.getAttributeValue(null, "script");
|
||||||
|
if (script != null && script.equals(""))
|
||||||
|
throw error(parser, "'script' attribute cannot be empty");
|
||||||
String numpad_script = parser.getAttributeValue(null, "numpad_script");
|
String numpad_script = parser.getAttributeValue(null, "numpad_script");
|
||||||
if (numpad_script == null)
|
if (numpad_script == null)
|
||||||
numpad_script = script;
|
numpad_script = script;
|
||||||
|
else if (numpad_script.equals(""))
|
||||||
|
throw error(parser, "'numpad_script' attribute cannot be empty");
|
||||||
String name = parser.getAttributeValue(null, "name");
|
String name = parser.getAttributeValue(null, "name");
|
||||||
ArrayList<Row> rows = new ArrayList<Row>();
|
ArrayList<Row> rows = new ArrayList<Row>();
|
||||||
Modmap modmap = null;
|
Modmap modmap = null;
|
||||||
@ -250,6 +254,8 @@ public final class KeyboardData
|
|||||||
rows.add(Row.parse(parser));
|
rows.add(Row.parse(parser));
|
||||||
break;
|
break;
|
||||||
case "modmap":
|
case "modmap":
|
||||||
|
if (modmap != null)
|
||||||
|
throw error(parser, "Multiple '<modmap>' are not allowed");
|
||||||
modmap = Modmap.parse(parser);
|
modmap = Modmap.parse(parser);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -286,7 +292,7 @@ public final class KeyboardData
|
|||||||
script = sc;
|
script = sc;
|
||||||
numpad_script = npsc;
|
numpad_script = npsc;
|
||||||
name = name_;
|
name = name_;
|
||||||
keysWidth = kw;
|
keysWidth = Math.max(kw, 1f);
|
||||||
keysHeight = kh;
|
keysHeight = kh;
|
||||||
bottom_row = bottom_row_;
|
bottom_row = bottom_row_;
|
||||||
}
|
}
|
||||||
@ -313,8 +319,8 @@ public final class KeyboardData
|
|||||||
float kw = 0.f;
|
float kw = 0.f;
|
||||||
for (Key k : keys_) kw += k.width + k.shift;
|
for (Key k : keys_) kw += k.width + k.shift;
|
||||||
keys = keys_;
|
keys = keys_;
|
||||||
height = h;
|
height = Math.max(h, 0.5f);
|
||||||
shift = s;
|
shift = Math.max(s, 0f);
|
||||||
keysWidth = kw;
|
keysWidth = kw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,8 +409,8 @@ public final class KeyboardData
|
|||||||
keys = ks;
|
keys = ks;
|
||||||
anticircle = antic;
|
anticircle = antic;
|
||||||
keysflags = f;
|
keysflags = f;
|
||||||
width = w;
|
width = Math.max(w, 0.5f);
|
||||||
shift = s;
|
shift = Math.max(s, 0f);
|
||||||
slider = sl;
|
slider = sl;
|
||||||
indication = i;
|
indication = i;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user