1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Enhanced Metafile (EMF) format parser and converter
//
// This module provides functionality to parse EMF data and convert it to
// modern image formats (PNG, JPEG, WebP).
//
// EMF is a 32-bit vector graphics format for Windows, introduced in Windows NT 3.1.
// It's an improved version of WMF with better support for modern graphics features.
//
// References:
// - [MS-EMF]: Enhanced Metafile Format Specification
// - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-emf/
pub use EmfParser;
pub use ;
pub use EmfSvgConverter;
use crateResult;
use ImageFormat;
/// Convert EMF data to a raster image in the specified format
///
/// # Arguments
/// * `emf_data` - Raw EMF file data
/// * `format` - Target image format (PNG, JPEG, WebP)
/// * `width` - Optional output width (maintains aspect ratio if only one dimension specified)
/// * `height` - Optional output height
///
/// # Returns
/// Encoded image bytes in the target format
///
/// # Example
/// ```no_run
/// use litchi::images::emf::convert_emf;
/// use image::ImageFormat;
///
/// let emf_data = std::fs::read("image.emf")?;
/// let png_data = convert_emf(&emf_data, ImageFormat::Png, Some(800), None)?;
/// std::fs::write("output.png", png_data)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Convert EMF data to PNG format
///
/// # Arguments
/// * `emf_data` - Raw EMF file data
/// * `width` - Optional output width
/// * `height` - Optional output height
///
/// # Returns
/// PNG-encoded image bytes
/// Convert EMF data to JPEG format
///
/// # Arguments
/// * `emf_data` - Raw EMF file data
/// * `width` - Optional output width
/// * `height` - Optional output height
///
/// # Returns
/// JPEG-encoded image bytes
/// Convert EMF data to WebP format
///
/// # Arguments
/// * `emf_data` - Raw EMF file data
/// * `width` - Optional output width
/// * `height` - Optional output height
///
/// # Returns
/// WebP-encoded image bytes
/// Convert EMF data to SVG format
///
/// This converts vector graphics to minimal SVG while extracting embedded
/// raster images as PNG data URLs. Uses parallel processing for performance.
///
/// # Arguments
/// * `emf_data` - Raw EMF file data
///
/// # Returns
/// SVG document as string
///
/// # Example
/// ```no_run
/// use litchi::images::emf::convert_emf_to_svg;
///
/// let emf_data = std::fs::read("image.emf")?;
/// let svg = convert_emf_to_svg(&emf_data)?;
/// std::fs::write("output.svg", svg)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Convert EMF data to SVG bytes