Visitar URL original
correctly encode Uint16Lists (#14) · flutter/packages@1138ecc · GitHub
Skip to content

Commit 1138ecc

Browse files
correctly encode Uint16Lists (#14)
1 parent c70e0d7 commit 1138ecc

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎packages/vector_graphics_codec/lib/vector_graphics_codec.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ class VectorGraphicsBuffer {
725725
void _putUint16List(Uint16List list) {
726726
assert(!_isDone);
727727
_alignTo(2);
728-
_buffer.addAll(list);
728+
_buffer
729+
.addAll(list.buffer.asUint8List(list.offsetInBytes, 2 * list.length));
729730
}
730731

731732
/// Write all the values from a [Float32List] into the buffer.

‎packages/vector_graphics_codec/test/vector_graphics_codec_test.dart‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,63 @@ void main() {
131131
]);
132132
});
133133

134+
test('Basic message encode and decode with stroked vertex and indexes', () {
135+
final buffer = VectorGraphicsBuffer();
136+
final TestListener listener = TestListener();
137+
final int paintId = codec.writeStroke(buffer, 44, 1, 2, 3, 4.0, 6.0);
138+
codec.writeDrawVertices(
139+
buffer,
140+
Float32List.fromList([
141+
0.0,
142+
2.0,
143+
3.0,
144+
4.0,
145+
2.0,
146+
4.0,
147+
]),
148+
Uint16List.fromList([
149+
0,
150+
1,
151+
2,
152+
3,
153+
4,
154+
5,
155+
]),
156+
paintId,
157+
);
158+
159+
codec.decode(buffer.done(), listener);
160+
161+
expect(listener.commands, [
162+
OnPaintObject(
163+
color: 44,
164+
strokeCap: 1,
165+
strokeJoin: 2,
166+
blendMode: 3,
167+
strokeMiterLimit: 4.0,
168+
strokeWidth: 6.0,
169+
paintStyle: 1,
170+
id: paintId,
171+
shaderId: null,
172+
),
173+
OnDrawVertices([
174+
0.0,
175+
2.0,
176+
3.0,
177+
4.0,
178+
2.0,
179+
4.0,
180+
], [
181+
0,
182+
1,
183+
2,
184+
3,
185+
4,
186+
5,
187+
], paintId),
188+
]);
189+
});
190+
134191
test('Can encode opacity/save/restore layers', () {
135192
final buffer = VectorGraphicsBuffer();
136193
final TestListener listener = TestListener();

0 commit comments

Comments
 (0)