@@ -80,22 +80,22 @@ pub struct OgImageGenerator {
80
80
}
81
81
82
82
impl OgImageGenerator {
83
- /// Creates a new `OgImageGenerator` with the specified path to the Typst binary.
83
+ /// Creates a new `OgImageGenerator` with default binary paths.
84
+ ///
85
+ /// Uses "typst" and "oxipng" as default binary paths, assuming they are
86
+ /// available in PATH. Use [`with_typst_path()`](Self::with_typst_path) and
87
+ /// [`with_oxipng_path()`](Self::with_oxipng_path) to customize the
88
+ /// binary paths.
84
89
///
85
90
/// # Examples
86
91
///
87
92
/// ```
88
- /// use std::path::PathBuf;
89
93
/// use crates_io_og_image::OgImageGenerator;
90
94
///
91
- /// let generator = OgImageGenerator::new(PathBuf::from("/usr/local/bin/typst") );
95
+ /// let generator = OgImageGenerator::new();
92
96
/// ```
93
- pub fn new ( typst_binary_path : PathBuf ) -> Self {
94
- Self {
95
- typst_binary_path,
96
- typst_font_path : None ,
97
- oxipng_binary_path : PathBuf :: from ( "oxipng" ) ,
98
- }
97
+ pub fn new ( ) -> Self {
98
+ Self :: default ( )
99
99
}
100
100
101
101
/// Creates a new `OgImageGenerator` using the `TYPST_PATH` environment variable.
@@ -117,36 +117,51 @@ impl OgImageGenerator {
117
117
let font_path = var ( "TYPST_FONT_PATH" ) . map_err ( OgImageError :: EnvVarError ) ?;
118
118
let oxipng_path = var ( "OXIPNG_PATH" ) . map_err ( OgImageError :: EnvVarError ) ?;
119
119
120
- let mut generator = if let Some ( ref path) = typst_path {
120
+ let mut generator = OgImageGenerator :: default ( ) ;
121
+
122
+ if let Some ( ref path) = typst_path {
121
123
debug ! ( typst_path = %path, "Using custom Typst binary path from environment" ) ;
122
- Self :: new ( PathBuf :: from ( path) )
124
+ generator . typst_binary_path = PathBuf :: from ( path) ;
123
125
} else {
124
126
debug ! ( "Using default Typst binary path (assumes 'typst' in PATH)" ) ;
125
- Self :: default ( )
126
127
} ;
127
128
128
129
if let Some ( ref font_path) = font_path {
129
130
debug ! ( font_path = %font_path, "Setting custom font path from environment" ) ;
130
- let current_dir = std:: env:: current_dir ( ) ?;
131
- let font_path = current_dir. join ( font_path) . canonicalize ( ) ?;
132
- debug ! ( resolved_font_path = %font_path. display( ) , "Resolved font path" ) ;
133
- generator = generator. with_font_path ( font_path) ;
131
+ generator. typst_font_path = Some ( PathBuf :: from ( font_path) ) ;
134
132
} else {
135
133
debug ! ( "No custom font path specified, using Typst default font discovery" ) ;
136
134
}
137
135
138
- let oxipng_binary_path = if let Some ( ref path) = oxipng_path {
136
+ if let Some ( ref path) = oxipng_path {
139
137
debug ! ( oxipng_path = %path, "Using custom oxipng binary path from environment" ) ;
140
- PathBuf :: from ( path)
138
+ generator . oxipng_binary_path = PathBuf :: from ( path) ;
141
139
} else {
142
140
debug ! ( "OXIPNG_PATH not set, defaulting to 'oxipng' in PATH" ) ;
143
- PathBuf :: from ( "oxipng" )
144
141
} ;
145
- generator. oxipng_binary_path = oxipng_binary_path;
146
142
147
143
Ok ( generator)
148
144
}
149
145
146
+ /// Sets the Typst binary path for the generator.
147
+ ///
148
+ /// This allows specifying a custom path to the Typst binary.
149
+ /// If not set, defaults to "typst" which assumes the binary is available in PATH.
150
+ ///
151
+ /// # Examples
152
+ ///
153
+ /// ```
154
+ /// use std::path::PathBuf;
155
+ /// use crates_io_og_image::OgImageGenerator;
156
+ ///
157
+ /// let generator = OgImageGenerator::default()
158
+ /// .with_typst_path(PathBuf::from("/usr/local/bin/typst"));
159
+ /// ```
160
+ pub fn with_typst_path ( mut self , typst_path : PathBuf ) -> Self {
161
+ self . typst_binary_path = typst_path;
162
+ self
163
+ }
164
+
150
165
/// Sets the font path for the Typst compiler.
151
166
///
152
167
/// This allows specifying a custom directory where Typst will look for fonts
@@ -518,8 +533,9 @@ impl OgImageGenerator {
518
533
}
519
534
520
535
impl Default for OgImageGenerator {
521
- /// Creates a default `OgImageGenerator` that assumes the Typst binary is available
522
- /// as "typst" in the system PATH.
536
+ /// Creates a default `OgImageGenerator` with default binary paths.
537
+ ///
538
+ /// Uses "typst" and "oxipng" as default binary paths, assuming they are available in PATH.
523
539
fn default ( ) -> Self {
524
540
Self {
525
541
typst_binary_path : PathBuf :: from ( "typst" ) ,
0 commit comments