[librsvg/rustification] path_parser.rs: Implement vertical lineto commands 'V' and 'v'
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] path_parser.rs: Implement vertical lineto commands 'V' and 'v'
- Date: Tue, 8 Nov 2016 22:05:32 +0000 (UTC)
commit 57c1b6371dc4628101b969e86169c0cad5a5aabd
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Nov 8 09:48:53 2016 -0600
path_parser.rs: Implement vertical lineto commands 'V' and 'v'
rust/src/path_parser.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index fbfd9c3..fe5de45 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -473,7 +473,55 @@ impl<'external> PathParser<'external> {
false
}
+ fn vertical_lineto_argument_sequence (&mut self, absolute: bool) -> bool {
+ if let Some (mut y) = self.number () {
+ let x = self.current_x;
+
+ if !absolute {
+ y += self.current_y;
+ }
+
+ self.emit_line_to (x, y);
+
+ self.whitespace ();
+
+ if self.lookahead_is (',') {
+ assert! (self.match_char (','));
+ assert! (self.optional_whitespace ());
+
+ if !self.vertical_lineto_argument_sequence (absolute) {
+ self.error ("Expected offset after comma");
+ return false;
+ }
+ }
+
+ self.vertical_lineto_argument_sequence (absolute);
+ true
+ } else {
+ false
+ }
+ }
+
fn vertical_line_to (&mut self) -> bool {
+ if self.lookahead_is ('V') || self.lookahead_is ('v') {
+ let absolute: bool;
+
+ if self.match_char ('V') {
+ absolute = true;
+ } else {
+ assert! (self.match_char ('v'));
+ absolute = false;
+ }
+
+ self.optional_whitespace ();
+
+ if self.vertical_lineto_argument_sequence (absolute) {
+ return true;
+ } else {
+ return self.error ("Expected offset after vertical lineto");
+ }
+ }
+
false
}
@@ -907,4 +955,36 @@ mod tests {
lineto (30.0, 20.0)
]);
}
+
+ #[test]
+ fn path_parser_handles_vertical_lineto () {
+ test_parser ("M10 20 V30",
+ &vec![
+ moveto (10.0, 20.0),
+ lineto (10.0, 30.0)
+ ]);
+
+ test_parser ("M10 20 V30 40",
+ &vec![
+ moveto (10.0, 20.0),
+ lineto (10.0, 30.0),
+ lineto (10.0, 40.0)
+ ]);
+
+ test_parser ("M10 20 V30,40-50",
+ &vec![
+ moveto (10.0, 20.0),
+ lineto (10.0, 30.0),
+ lineto (10.0, 40.0),
+ lineto (10.0, -50.0),
+ ]);
+
+ test_parser ("m10 20 v30,40-50",
+ &vec![
+ moveto (10.0, 20.0),
+ lineto (10.0, 50.0),
+ lineto (10.0, 90.0),
+ lineto (10.0, 40.0)
+ ]);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]