@@ -4,7 +4,6 @@ use std::fs;
4
4
use std:: io:: Read ;
5
5
use std:: path:: Path ;
6
6
use std:: path:: PathBuf ;
7
- use fontdue:: Font ;
8
7
use texture_packer:: exporter:: ImageExporter ;
9
8
use texture_packer:: TexturePacker ;
10
9
use texture_packer:: TexturePackerConfig ;
@@ -14,6 +13,7 @@ use crate::{done, info, fatal, NiceUnwrap};
14
13
use image:: { Rgba , Rgb , RgbaImage , LumaA , EncodableLayout , Pixel , GenericImageView , DynamicImage , GrayAlphaImage } ;
15
14
use signed_distance_field:: prelude:: * ;
16
15
16
+ use super :: mod_file:: ModFileInfo ;
17
17
use super :: spritesheet:: downscale;
18
18
19
19
struct RenderedChar {
@@ -111,7 +111,12 @@ fn generate_char(font: &BitmapFont, metrics: fontdue::Metrics, data: Vec<u8>) ->
111
111
) )
112
112
}
113
113
114
- fn initialize_font_bundle ( bundle : & FontBundle , font : & BitmapFont , factor : u32 ) -> PathBuf {
114
+ fn initialize_font_bundle (
115
+ bundle : & FontBundle ,
116
+ font : & BitmapFont ,
117
+ factor : u32 ,
118
+ _mod_info : & ModFileInfo
119
+ ) -> PathBuf {
115
120
// Get all characters from the charset format
116
121
let chars: Vec < char > = font. charset
117
122
. as_deref ( )
@@ -206,27 +211,24 @@ fn initialize_font_bundle(bundle: &FontBundle, font: &BitmapFont, factor: u32) -
206
211
}
207
212
208
213
// Get all kerning pairs
209
- let mut all_kerning_pairs = vec ! ( ) ;
210
- for left in & rasterized_chars {
211
- for right in & rasterized_chars {
212
- if let Some ( kern) = ttf_font. horizontal_kern (
214
+ let all_kerning_pairs = rasterized_chars. iter ( ) . flat_map (
215
+ |left| rasterized_chars. iter ( ) . filter_map ( |right| {
216
+ ttf_font. horizontal_kern (
213
217
left. id , right. id , font. size as f32
214
- ) {
215
- all_kerning_pairs. push ( format ! (
216
- "kerning first={} second={} amount={}" ,
217
- left. id, right. id, kern as i32
218
- ) ) ;
219
- }
220
- }
221
- }
218
+ ) . map ( |kern| format ! (
219
+ "kerning first={} second={} amount={}" ,
220
+ left. id, right. id, kern as i32
221
+ ) )
222
+ } )
223
+ ) . collect :: < Vec < _ > > ( ) ;
222
224
223
225
// Create .fnt file
224
226
let line_metrics = ttf_font. horizontal_line_metrics ( font. size as f32 ) . unwrap ( ) ;
225
227
let fnt_data = format ! (
226
- "info face=\" {font_name} size={font_size} bold=0 italic=0 \
228
+ "info face=\" {font_name}\" size={font_size} bold=0 italic=0 \
227
229
charset=\" \" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1\n \
228
230
common lineHeight={common_line_height} base={font_base} \
229
- scaleW={scale_w} scaleH={scale_h} pages=1 packed=0\n \
231
+ scaleW={scale_w} scaleH={scale_h} pages=1 packed=0\n \
230
232
page id=0 file=\" {sprite_file_name}.png\" \n \
231
233
chars count={char_count}\n \
232
234
{all_chars}\n \
@@ -304,7 +306,12 @@ fn extract_from_cache(path: &Path, working_dir: &Path, cache_bundle: &mut CacheB
304
306
) ;
305
307
}
306
308
307
- pub fn get_font_bundles ( font : & BitmapFont , working_dir : & Path , cache : & mut Option < CacheBundle > ) -> FontBundles {
309
+ pub fn get_font_bundles (
310
+ font : & BitmapFont ,
311
+ working_dir : & Path ,
312
+ cache : & mut Option < CacheBundle > ,
313
+ mod_info : & ModFileInfo
314
+ ) -> FontBundles {
308
315
info ! ( "Fetching font {}" , font. name. bright_yellow( ) ) ;
309
316
310
317
if let Some ( cache_bundle) = cache {
@@ -332,13 +339,13 @@ pub fn get_font_bundles(font: &BitmapFont, working_dir: &Path, cache: &mut Optio
332
339
// Create new font
333
340
334
341
info ! ( "Creating normal font" ) ;
335
- initialize_font_bundle ( & mut bundles. sd , font, 4 ) ;
342
+ initialize_font_bundle ( & mut bundles. sd , font, 4 , mod_info ) ;
336
343
337
344
info ! ( "Creating HD font" ) ;
338
- initialize_font_bundle ( & mut bundles. hd , font, 2 ) ;
345
+ initialize_font_bundle ( & mut bundles. hd , font, 2 , mod_info ) ;
339
346
340
347
info ! ( "Creating UHD font" ) ;
341
- initialize_font_bundle ( & mut bundles. uhd , font, 1 ) ;
348
+ initialize_font_bundle ( & mut bundles. uhd , font, 1 , mod_info ) ;
342
349
343
350
done ! ( "Built font {}" , font. name. bright_yellow( ) ) ;
344
351
bundles
0 commit comments