MCPcopy Create free account
hub / github.com/bytesnake/vim-graphical-preview / generate

Method generate

src/content.rs:39–84  ·  view source on GitHub ↗
(&self, content: String)

Source from the content-addressed store, hash-verified

37 }
38
39 pub fn generate(&self, content: String) -> Result<WrappedWand> {
40 let mut path = self.path(&content);
41 let missing = !path.exists();
42
43 if missing {
44 match self {
45 ContentType::Math => {
46 utils::parse_equation(&content, 1.0)?;
47 },
48 ContentType::File => {
49 return Err(Error::FileNotFound(path))
50 },
51 ContentType::Tex => {
52 utils::parse_latex(&content)?;
53 },
54 ContentType::Gnuplot => {
55 let path = utils::generate_latex_from_gnuplot(&content)?;
56 utils::generate_svg_from_latex(&path, 1.0)?;
57 },
58 }
59 }
60
61 // rewrite path if ending as tex or gnuplot file
62 if *self == ContentType::File {
63 if path.extension().unwrap() == "tex" {
64 path = utils::parse_latex_from_file(&path)?;
65 }
66
67 if path.extension().unwrap() == "plt" {
68 let new_path = utils::generate_latex_from_gnuplot_file(&path)?;
69 path = new_path.with_extension("svg");
70 }
71 }
72
73 let wand = MagickWand::new();
74 wand.set_resolution(600.0, 600.0).unwrap();
75
76 wand.read_image(path.to_str().unwrap())
77 .map_err(|_| Error::InvalidImage(path.to_str().unwrap().to_string()))?;
78
79 //wand.set_compression_quality(5).unwrap();
80 //wand.transform_image_colorspace(ColorspaceType_GRAYColorspace).unwrap();
81 //wand.quantize_image(8, ColorspaceType_GRAYColorspace, 0, DitherMethod_NoDitherMethod, 0).unwrap();
82
83 Ok(WrappedWand(wand))
84 }
85
86 pub fn path(&self, content: &str) -> PathBuf {
87 let id = utils::hash(content);

Callers 1

get_sixelMethod · 0.80

Calls 8

parse_equationFunction · 0.85
parse_latexFunction · 0.85
generate_svg_from_latexFunction · 0.85
parse_latex_from_fileFunction · 0.85
WrappedWandClass · 0.85
pathMethod · 0.80

Tested by

no test coverage detected