Skip to content

Commit 39ab00c

Browse files
authored
Fix support for empty Font tags in rbx_xml (#261)
In the past, Roblox serialized `Font` properties as empty tags. Although they've stopped doing that, there are still models in the wild with that format for tags. This adds support for empty Font tags by just returning the default value for `Font` when the tag is empty. Relies on rojo-rbx/rbx-test-files#19.
1 parent 361ac62 commit 39ab00c

File tree

6 files changed

+389
-2
lines changed

6 files changed

+389
-2
lines changed

rbx_xml/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ xml-rs = "0.8.4"
2121

2222
[dev-dependencies]
2323
env_logger = "0.9.0"
24-
insta = "1.14.1"
24+
insta = { version = "1.14.1", features = ["yaml"] }

rbx_xml/src/types/font.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ impl XmlType for Font {
104104
}
105105

106106
fn read_xml<R: Read>(reader: &mut XmlEventReader<R>) -> Result<Self, DecodeError> {
107+
// Patchwork fix for older Roblox files that were written with invalid
108+
// `Font` tags
109+
if let XmlReadEvent::EndElement { .. } = reader.expect_peek()? {
110+
return Ok(Font::default());
111+
}
112+
107113
let family = read_content(reader, "Family")?;
108114

109115
let weight: u16 = reader.read_value_in_tag("Weight")?;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
source: rbx_xml/tests/test-files.rs
3+
expression: viewer.view_children(&dom)
4+
---
5+
- referent: referent-0
6+
name: Bold Denk
7+
class: TextLabel
8+
properties:
9+
Active:
10+
Bool: false
11+
AnchorPoint:
12+
Vector2:
13+
- 0
14+
- 0
15+
Attributes:
16+
Attributes: {}
17+
AutoLocalize:
18+
Bool: true
19+
AutomaticSize:
20+
Enum: 0
21+
BackgroundColor3:
22+
Color3:
23+
- 0.6392157
24+
- 0.63529414
25+
- 0.64705884
26+
BackgroundTransparency:
27+
Float32: 0
28+
BorderColor3:
29+
Color3:
30+
- 0.10588236
31+
- 0.16470589
32+
- 0.20784315
33+
BorderMode:
34+
Enum: 0
35+
BorderSizePixel:
36+
Int32: 1
37+
ClipsDescendants:
38+
Bool: false
39+
Draggable:
40+
Bool: false
41+
FontFace:
42+
Font:
43+
family: "rbxasset://fonts/families/SourceSansPro.json"
44+
weight: Regular
45+
style: Normal
46+
cachedFaceId: ~
47+
LayoutOrder:
48+
Int32: 0
49+
LineHeight:
50+
Float32: 1
51+
MaxVisibleGraphemes:
52+
Int32: -1
53+
NextSelectionDown: "null"
54+
NextSelectionLeft: "null"
55+
NextSelectionRight: "null"
56+
NextSelectionUp: "null"
57+
Position:
58+
UDim2:
59+
- - 0
60+
- 0
61+
- - 0
62+
- 0
63+
RichText:
64+
Bool: false
65+
RootLocalizationTable: "null"
66+
Rotation:
67+
Float32: 0
68+
Selectable:
69+
Bool: false
70+
SelectionBehaviorDown:
71+
Enum: 0
72+
SelectionBehaviorLeft:
73+
Enum: 0
74+
SelectionBehaviorRight:
75+
Enum: 0
76+
SelectionBehaviorUp:
77+
Enum: 0
78+
SelectionGroup:
79+
Bool: false
80+
SelectionImageObject: "null"
81+
SelectionOrder:
82+
Int32: 0
83+
Size:
84+
UDim2:
85+
- - 0
86+
- 0
87+
- - 0
88+
- 0
89+
SizeConstraint:
90+
Enum: 0
91+
SourceAssetId:
92+
Int64: -1
93+
Tags:
94+
Tags: []
95+
Text:
96+
String: Example
97+
TextColor3:
98+
Color3:
99+
- 0.10588236
100+
- 0.16470589
101+
- 0.20784315
102+
TextScaled:
103+
Bool: false
104+
TextSize:
105+
Float32: 8
106+
TextStrokeColor3:
107+
Color3:
108+
- 0
109+
- 0
110+
- 0
111+
TextStrokeTransparency:
112+
Float32: 1
113+
TextTransparency:
114+
Float32: 0
115+
TextTruncate:
116+
Enum: 0
117+
TextWrapped:
118+
Bool: false
119+
TextXAlignment:
120+
Enum: 2
121+
TextYAlignment:
122+
Enum: 1
123+
Visible:
124+
Bool: true
125+
ZIndex:
126+
Int32: 1
127+
children: []
128+
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
---
2+
source: rbx_xml/tests/test-files.rs
3+
expression: viewer.view_children(&dom)
4+
---
5+
- referent: referent-0
6+
name: Bold Denk
7+
class: TextLabel
8+
properties:
9+
Active:
10+
Bool: false
11+
AnchorPoint:
12+
Vector2:
13+
- 0
14+
- 0
15+
Attributes:
16+
Attributes: {}
17+
AutoLocalize:
18+
Bool: true
19+
AutomaticSize:
20+
Enum: 0
21+
BackgroundColor3:
22+
Color3:
23+
- 0.6392157
24+
- 0.63529414
25+
- 0.64705884
26+
BackgroundTransparency:
27+
Float32: 0
28+
BorderColor3:
29+
Color3:
30+
- 0.10588236
31+
- 0.16470589
32+
- 0.20784315
33+
BorderMode:
34+
Enum: 0
35+
BorderSizePixel:
36+
Int32: 1
37+
ClipsDescendants:
38+
Bool: false
39+
Draggable:
40+
Bool: false
41+
FontFace:
42+
Font:
43+
family: "rbxasset://fonts/families/DenkOne.json"
44+
weight: Bold
45+
style: Normal
46+
cachedFaceId: ~
47+
LayoutOrder:
48+
Int32: 0
49+
LineHeight:
50+
Float32: 1
51+
MaxVisibleGraphemes:
52+
Int32: -1
53+
NextSelectionDown: "null"
54+
NextSelectionLeft: "null"
55+
NextSelectionRight: "null"
56+
NextSelectionUp: "null"
57+
Position:
58+
UDim2:
59+
- - 0
60+
- 0
61+
- - 0
62+
- 0
63+
RichText:
64+
Bool: false
65+
RootLocalizationTable: "null"
66+
Rotation:
67+
Float32: 0
68+
Selectable:
69+
Bool: false
70+
SelectionBehaviorDown:
71+
Enum: 0
72+
SelectionBehaviorLeft:
73+
Enum: 0
74+
SelectionBehaviorRight:
75+
Enum: 0
76+
SelectionBehaviorUp:
77+
Enum: 0
78+
SelectionGroup:
79+
Bool: false
80+
SelectionImageObject: "null"
81+
SelectionOrder:
82+
Int32: 0
83+
Size:
84+
UDim2:
85+
- - 0
86+
- 0
87+
- - 0
88+
- 0
89+
SizeConstraint:
90+
Enum: 0
91+
SourceAssetId:
92+
Int64: -1
93+
Tags:
94+
Tags: []
95+
Text:
96+
String: Example
97+
TextColor3:
98+
Color3:
99+
- 0.10588236
100+
- 0.16470589
101+
- 0.20784315
102+
TextScaled:
103+
Bool: false
104+
TextSize:
105+
Float32: 8
106+
TextStrokeColor3:
107+
Color3:
108+
- 0
109+
- 0
110+
- 0
111+
TextStrokeTransparency:
112+
Float32: 1
113+
TextTransparency:
114+
Float32: 0
115+
TextTruncate:
116+
Enum: 0
117+
TextWrapped:
118+
Bool: false
119+
TextXAlignment:
120+
Enum: 2
121+
TextYAlignment:
122+
Enum: 1
123+
Visible:
124+
Bool: true
125+
ZIndex:
126+
Int32: 1
127+
children: []
128+
- referent: referent-1
129+
name: Italic Merriweather
130+
class: TextLabel
131+
properties:
132+
Active:
133+
Bool: false
134+
AnchorPoint:
135+
Vector2:
136+
- 0
137+
- 0
138+
Attributes:
139+
Attributes: {}
140+
AutoLocalize:
141+
Bool: true
142+
AutomaticSize:
143+
Enum: 0
144+
BackgroundColor3:
145+
Color3:
146+
- 0.6392157
147+
- 0.63529414
148+
- 0.64705884
149+
BackgroundTransparency:
150+
Float32: 0
151+
BorderColor3:
152+
Color3:
153+
- 0.10588236
154+
- 0.16470589
155+
- 0.20784315
156+
BorderMode:
157+
Enum: 0
158+
BorderSizePixel:
159+
Int32: 1
160+
ClipsDescendants:
161+
Bool: false
162+
Draggable:
163+
Bool: false
164+
FontFace:
165+
Font:
166+
family: "rbxasset://fonts/families/Merriweather.json"
167+
weight: Regular
168+
style: Italic
169+
cachedFaceId: ~
170+
LayoutOrder:
171+
Int32: 0
172+
LineHeight:
173+
Float32: 1
174+
MaxVisibleGraphemes:
175+
Int32: -1
176+
NextSelectionDown: "null"
177+
NextSelectionLeft: "null"
178+
NextSelectionRight: "null"
179+
NextSelectionUp: "null"
180+
Position:
181+
UDim2:
182+
- - 0
183+
- 0
184+
- - 0
185+
- 0
186+
RichText:
187+
Bool: false
188+
RootLocalizationTable: "null"
189+
Rotation:
190+
Float32: 0
191+
Selectable:
192+
Bool: false
193+
SelectionBehaviorDown:
194+
Enum: 0
195+
SelectionBehaviorLeft:
196+
Enum: 0
197+
SelectionBehaviorRight:
198+
Enum: 0
199+
SelectionBehaviorUp:
200+
Enum: 0
201+
SelectionGroup:
202+
Bool: false
203+
SelectionImageObject: "null"
204+
SelectionOrder:
205+
Int32: 0
206+
Size:
207+
UDim2:
208+
- - 0
209+
- 0
210+
- - 0
211+
- 0
212+
SizeConstraint:
213+
Enum: 0
214+
SourceAssetId:
215+
Int64: -1
216+
Tags:
217+
Tags: []
218+
Text:
219+
String: Example
220+
TextColor3:
221+
Color3:
222+
- 0.10588236
223+
- 0.16470589
224+
- 0.20784315
225+
TextScaled:
226+
Bool: false
227+
TextSize:
228+
Float32: 8
229+
TextStrokeColor3:
230+
Color3:
231+
- 0
232+
- 0
233+
- 0
234+
TextStrokeTransparency:
235+
Float32: 1
236+
TextTransparency:
237+
Float32: 0
238+
TextTruncate:
239+
Enum: 0
240+
TextWrapped:
241+
Bool: false
242+
TextXAlignment:
243+
Enum: 2
244+
TextYAlignment:
245+
Enum: 1
246+
Visible:
247+
Bool: true
248+
ZIndex:
249+
Int32: 1
250+
children: []
251+

0 commit comments

Comments
 (0)