8
8
//! if you need emoji rendering.
9
9
10
10
use crate :: { GlyphRun , Layout , PositionedLayoutItem } ;
11
+ use peniko:: kurbo;
11
12
use skrifa:: {
12
13
instance:: { LocationRef , NormalizedCoord , Size } ,
13
14
outline:: { DrawSettings , OutlinePen } ,
@@ -34,6 +35,9 @@ pub(crate) struct RenderingConfig {
34
35
pub inline_box_color : Color ,
35
36
pub cursor_color : Color ,
36
37
pub selection_color : Color ,
38
+
39
+ /// The width of the pixmap in pixels, excluding padding.
40
+ pub size : Option < kurbo:: Size > ,
37
41
}
38
42
39
43
fn draw_rect ( pen : & mut TinySkiaPen < ' _ > , x : f32 , y : f32 , width : f32 , height : f32 , color : Color ) {
@@ -42,15 +46,27 @@ fn draw_rect(pen: &mut TinySkiaPen<'_>, x: f32, y: f32, width: f32, height: f32,
42
46
pen. fill_rect ( width, height) ;
43
47
}
44
48
49
+ /// Render the layout to a [`Pixmap`].
50
+ ///
51
+ /// If given [`RenderingConfig::size`] is not specified, [`Layout::width`] and [`Layout::height`]
52
+ /// are used.
45
53
pub ( crate ) fn render_layout (
46
54
config : & RenderingConfig ,
47
55
layout : & Layout < ColorBrush > ,
48
56
cursor_rect : Option < crate :: Rect > ,
49
57
selection_rects : & [ crate :: Rect ] ,
50
58
) -> Pixmap {
51
59
let padding = 20 ;
52
- let width = layout. width ( ) . ceil ( ) as u32 ;
53
- let height = layout. height ( ) . ceil ( ) as u32 ;
60
+ let width = config
61
+ . size
62
+ . map ( |size| size. width as f32 )
63
+ . unwrap_or ( layout. width ( ) )
64
+ . ceil ( ) as u32 ;
65
+ let height = config
66
+ . size
67
+ . map ( |size| size. height as f32 )
68
+ . unwrap_or ( layout. height ( ) )
69
+ . ceil ( ) as u32 ;
54
70
let padded_width = width + padding * 2 ;
55
71
let padded_height = height + padding * 2 ;
56
72
let fpadding = padding as f32 ;
0 commit comments