pub struct SymbolArtDrawer { /* private fields */ }Expand description
A drawer that renders SymbolArt compositions into images
The SymbolArtDrawer is responsible for converting SymbolArt compositions into
raster images. It handles the rendering of individual layers, applying transformations,
and compositing them into a final image.
§Examples
use sar_core::{SymbolArtDrawer, parse};
use sar_core::renderer::draw::Drawer;
// Parse a SAR file into a SymbolArt instance
let bytes = include_bytes!("../../../fixture/sa0a1d081b8a108bb8c9847c4cd83db662.sar");
let symbol_art = parse(Vec::from(*bytes)).unwrap();
// Create a drawer and render the SymbolArt
let drawer = SymbolArtDrawer::new();
let image = drawer.draw(&symbol_art).unwrap();§Configuration
The drawer can be configured with various options:
- with_raise_error: Controls whether rendering errors should be raised or suppressed
- Canvas size: Default is 256x256 pixels
- with_chunk_size: Controls parallel processing of layers (default: 10)
§Performance
The drawer uses parallel processing to render layers efficiently. The chunk size can be adjusted to balance between parallelization overhead and throughput.
§Error Handling
By default, the drawer suppresses rendering errors and continues processing.
This can be changed using with_raise_error(true) to make errors fatal.
§Resource Management
The drawer maintains a cache of symbol resources to improve rendering performance. These resources are loaded when the drawer is created and shared across all rendering operations.
Implementations§
Source§impl SymbolArtDrawer
 
impl SymbolArtDrawer
Sourcepub fn new() -> Self
 
pub fn new() -> Self
Examples found in repository?
4fn main() {
5    let current_dir = std::env::current_dir().unwrap();
6    let examples_dir = current_dir.join("fixture");
7    let target_dir = current_dir.join("sar-core").join("examples").join("result");
8
9    let files = std::fs::read_dir(&examples_dir).unwrap();
10    let drawer = sar_core::SymbolArtDrawer::new();
11    files.par_bridge().for_each(|file| {
12        let file = match file {
13            Ok(file) => file,
14            Err(_) => return,
15        };
16        if file.path().is_dir() || file.path().extension().unwrap() != "sar" {
17            return;
18        }
19
20        let buff = std::fs::read(file.path()).unwrap();
21        let sar = match sar_core::parse(buff) {
22            Ok(sar) => sar,
23            Err(e) => {
24                println!(
25                    "Error parsing {}: {}",
26                    file.file_name().to_str().unwrap(),
27                    e
28                );
29                return;
30            }
31        };
32
33        let image = match drawer.draw(&sar) {
34            Ok(image) => image,
35            Err(e) => {
36                println!("Error drawing {}: {}", file.path().display(), e);
37                return;
38            }
39        };
40        image
41            .save(target_dir.join(format!("{}.png", file.file_name().to_str().unwrap())))
42            .unwrap();
43        println!(
44            "Saved to {}",
45            target_dir
46                .join(format!("{}.png", file.file_name().to_str().unwrap()))
47                .display()
48        );
49    })
50}pub fn with_raise_error(self, raise_error: bool) -> Self
pub fn with_chunk_size(self, chunk_size: usize) -> Self
Trait Implementations§
Source§impl Default for SymbolArtDrawer
 
impl Default for SymbolArtDrawer
Auto Trait Implementations§
impl Freeze for SymbolArtDrawer
impl RefUnwindSafe for SymbolArtDrawer
impl Send for SymbolArtDrawer
impl Sync for SymbolArtDrawer
impl Unpin for SymbolArtDrawer
impl UnwindSafe for SymbolArtDrawer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
 
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
 
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
 
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
    SS: SubsetOf<SP>,
 
impl<SS, SP> SupersetOf<SS> for SPwhere
    SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
 
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
 
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
 
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
 
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.