diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-07-29 23:45:41 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-07-29 23:45:41 +0800 |
commit | c260fa2109789fd82b2f1ffd433bb505e8e06945 (patch) | |
tree | de7f48849698d08a7db8f60b2fd7c0146f80cf5c | |
parent | 60645decbbbfcc3eb5de1af71b94e57461938dde (diff) |
Make the underscore work properly
-rw-r--r-- | svgbob/src/enhance.rs | 83 | ||||
-rw-r--r-- | svgbob/src/focus_char.rs | 90 | ||||
-rw-r--r-- | svgbob/src/lib.rs | 3 | ||||
-rw-r--r-- | svgbob/src/special_case.rs | 0 |
4 files changed, 144 insertions, 32 deletions
diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs new file mode 100644 index 0000000..b34815e --- /dev/null +++ b/svgbob/src/enhance.rs @@ -0,0 +1,83 @@ +use focus_char::FocusChar; +use fragments::Fragment; +use location::Location; +use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight}; +use block::Block::{A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y}; +use point_block::PointBlock; +use fragments::{self, line, arc, arrow_line}; + +pub trait Enhance { + fn enhance(&self) -> (Vec<Fragment>, Vec<Location>); +} + +impl<'g> Enhance for FocusChar<'g> { + fn enhance(&self) -> (Vec<Fragment>, Vec<Location>) { + let mut elm = vec![]; + let mut consumed = vec![]; + + let a = &PointBlock::block(A); + let _b = &PointBlock::block(B); + let c = &PointBlock::block(C); + let _d = &PointBlock::block(D); + let e = &PointBlock::block(E); + let _f = &PointBlock::block(F); + let _g = &PointBlock::block(G); + let _h = &PointBlock::block(H); + let _i = &PointBlock::block(I); + let _j = &PointBlock::block(J); + let k = &PointBlock::block(K); + let l = &PointBlock::block(L); + let _m = &PointBlock::block(M); + let n = &PointBlock::block(N); + let o = &PointBlock::block(O); + let _p = &PointBlock::block(P); + let _q = &PointBlock::block(Q); + let _r = &PointBlock::block(R); + let _s = &PointBlock::block(S); + let _t = &PointBlock::block(T); + let u = &PointBlock::block(U); + let _v = &PointBlock::block(V); + let w = &PointBlock::block(W); + let _x = &PointBlock::block(X); + let y = &PointBlock::block(Y); + + let top = ||Location::go(Top); + let bottom = ||Location::go(Bottom); + let left = ||Location::go(Left); + let right = ||Location::go(Right); + let top_left = ||Location::go(TopLeft); + let top_right = ||Location::go(TopRight); + let bottom_left = ||Location::go(BottomLeft); + let bottom_right = ||Location::go(BottomRight); + + if self.is('_') { + // _| + if self.right().any("|[") { + elm.push(fragments::line(u, &right().w())); + } + // |_ + if self.left().any("|]") { + elm.push(fragments::line(y, &left().w())); + } + // _ + // | + if self.bottom_left().any("|]") { + elm.push(fragments::line(y, &left().w())); + } + // _ + // | + if self.bottom_right().any("|[") { + elm.push(fragments::line(u, &right().w())); + } + // /_ + if self.left().is('/') { + elm.push(fragments::line(y, &left().u())); + } + if self.right().is('\\') { + // _\ + elm.push(fragments::line(u, &right().y())); + } + } + (elm, consumed) + } +} diff --git a/svgbob/src/focus_char.rs b/svgbob/src/focus_char.rs index 7fe56af..24e537c 100644 --- a/svgbob/src/focus_char.rs +++ b/svgbob/src/focus_char.rs @@ -16,6 +16,7 @@ use fragments::Fragment::Text; use element::{line,dashed_line,arrow_line,start_arrow_line,arc,open_circle,solid_circle,text}; use location::Location; use settings::Settings; +use enhance::Enhance; #[derive(Debug, Clone)] pub struct FocusChar<'g> { @@ -64,26 +65,49 @@ impl<'g> FocusChar<'g> { self.ch.any(s) } + /// check if the the surrounding character can connect to this character + fn used_as_drawing(&self)-> bool { + // -- + (self.can_strongly_connect(&Block::O) && self.right().can_pass_medium_connect(&Block::K)) + || (self.can_strongly_connect(&Block::K) && self.left().can_pass_medium_connect(&Block::O)) + // | + // | + || (self.can_strongly_connect(&Block::C) && self.top().can_pass_medium_connect(&Block::W)) + || (self.can_strongly_connect(&Block::W) && self.bottom().can_pass_medium_connect(&Block::C)) + // \ + // \ + || (self.can_strongly_connect(&Block::A) && self.top_left().can_pass_medium_connect(&Block::Y)) + || (self.can_strongly_connect(&Block::Y) && self.bottom_right().can_pass_medium_connect(&Block::A)) + // / + // / + || (self.can_strongly_connect(&Block::E) && self.top_right().can_pass_medium_connect(&Block::U)) + || (self.can_strongly_connect(&Block::U) && self.bottom_left().can_pass_medium_connect(&Block::E)) + // __ + || (self.can_strongly_connect(&Block::U) && self.top_right().can_pass_medium_connect(&Block::Y)) + || (self.can_strongly_connect(&Block::Y) && self.bottom_left().can_pass_medium_connect(&Block::U)) + } + fn used_as_text(&self) -> bool { - if self.is_text_surrounded() { - // not if it can strongly connect to 4 directions - if self.can_strongly_connect(&Block::O) || self.can_strongly_connect(&Block::K) - || self.can_strongly_connect(&Block::C) - || self.can_strongly_connect(&Block::W) - || self.can_strongly_connect(&Block::U) - || self.can_strongly_connect(&Block::Y) - { - false - } else { - true - } - } else { + if self.used_as_drawing(){ false } + else{ + self.is_text_surrounded() + } } + fn is_text_char(&self)->bool{ + if self.ch.any("oO"){// exclude letter oO and _underscore in the alphanumeric + return false; + } + else { + self.ch.is_alphanumeric() + } + } + + fn is_text_surrounded(&self) -> bool { - self.left().ch.is_alphanumeric() || self.right().ch.is_alphanumeric() + self.left().is_text_char() || self.right().is_text_char() } pub fn is_null(&self) -> bool { @@ -231,15 +255,21 @@ impl<'g> FocusChar<'g> { let mut consumed: Vec<Location> = vec![]; let mut matched_intended = false; + let mut matched_enhance = false; - let enable_intended_behavior = true; - let enable_default_properties = true; if let Some(character) = character { + + let (enhanced, enhance_consumed) = self.enhance(); + if !enhanced.is_empty() && !self.used_as_text() { + elm.extend(enhanced); + consumed.extend(enhance_consumed); + matched_enhance = true; + } // intended behaviors when signals are strong // after applying the intensifiers // do only when enhancements is not matched - if enable_intended_behavior { + if !matched_enhance { for &(ref blocks, ref fragments) in &character.intended_behavior { let meet = blocks.iter().all(|ref b| self.can_be_strong_block(&b)); if meet && !self.used_as_text() { @@ -253,23 +283,21 @@ impl<'g> FocusChar<'g> { // add only when signal is strong // or the signal has been intensified to strong let mut matched = false; - if enable_default_properties { - if !matched_intended { - for &(ref block, ref _signal, ref fragments) in &character.properties { - // draw when a strong block and not used as text - if self.is_strong_block(&block) && !self.used_as_text() { - elm.extend(fragments.clone()); - matched = true; - } - // intensified the block - else if self.is_intensified(&block) && !self.used_as_text() { - elm.extend(fragments.clone()); - matched = true; - } + if !matched_enhance && !matched_intended { + for &(ref block, ref _signal, ref fragments) in &character.properties { + // draw when a strong block and not used as text + if self.is_strong_block(&block) && !self.used_as_text() { + elm.extend(fragments.clone()); + matched = true; + } + // intensified the block + else if self.is_intensified(&block) && !self.used_as_text() { + elm.extend(fragments.clone()); + matched = true; } } } - if !matched && !matched_intended + if !matched && !matched_intended && !matched_enhance && !self.is_blank() { elm.push(Text(self.text())); } diff --git a/svgbob/src/lib.rs b/svgbob/src/lib.rs index af0affc..bd43554 100644 --- a/svgbob/src/lib.rs +++ b/svgbob/src/lib.rs @@ -29,7 +29,7 @@ //! </svg> //! //! -#![deny(warnings)] +//#![deny(warnings)] #![feature(extern_prelude)] extern crate pom; #[cfg(test)] @@ -57,6 +57,7 @@ mod point_block; mod block; mod focus_char; mod loc_block; +mod enhance; /// generate an SVG from the ascii text input /// diff --git a/svgbob/src/special_case.rs b/svgbob/src/special_case.rs deleted file mode 100644 index e69de29..0000000 --- a/svgbob/src/special_case.rs +++ /dev/null |