11use crate :: byte_cursor:: ByteCursor ;
22use crate :: math:: { Point , Rect , Size } ;
3- use crate :: style:: { TextStyle , TextWrap , VerticalTextAlignment } ;
3+ use crate :: style:: { FontFamily , TextStyle , TextWrap , VerticalTextAlignment } ;
44use crate :: text_params:: TextParams ;
55use cosmic_text:: { Attrs , Buffer , Cursor , Edit , Editor , FontSystem , Shaping } ;
66
@@ -120,13 +120,15 @@ pub(crate) fn update_buffer(
120120 params : & TextParams ,
121121 buffer : & mut Buffer ,
122122 font_system : & mut FontSystem ,
123+ font_family : & FontFamily ,
123124) -> Size {
124125 let text_style = & params. style ( ) ;
125126 let font_color = text_style. font_color ;
126127 let horizontal_alignment = text_style. horizontal_alignment ;
127128 let wrap = text_style. wrap . unwrap_or_default ( ) ;
128129 let text_area_size = params. size ( ) ;
129- let font_family = & text_style. font_family ;
130+ let weight = text_style. weight ;
131+ let letter_spacing = text_style. letter_spacing ;
130132 let metadata = params. metadata ( ) ;
131133 let old_scroll = buffer. scroll ( ) ;
132134
@@ -140,14 +142,37 @@ pub(crate) fn update_buffer(
140142 // Apply scale for shaping to device pixels
141143 buffer. set_size ( font_system, Some ( text_area_size. x * scale_factor) , None ) ;
142144
145+ // match font_family {
146+ // FontFamily::Name(name) => {
147+ // println!("Using font family: {:?}", name);
148+ // }
149+ // FontFamily::SansSerif => {}
150+ // FontFamily::Serif => {}
151+ // FontFamily::Monospace => {}
152+ // FontFamily::Cursive => {}
153+ // FontFamily::Fantasy => {}
154+ // }
155+
156+ if params. original_text ( ) == "Filobus" {
157+ println ! ( "Font family: {:?}" , font_family) ;
158+ }
159+
160+ let mut attrs = Attrs :: new ( )
161+ . color ( font_color. into ( ) )
162+ . family ( font_family. to_fontdb_family ( ) )
163+ . weight ( weight. into ( ) )
164+ . metadata ( metadata) ;
165+
166+ if let Some ( letter_spacing) = letter_spacing {
167+ attrs = attrs. letter_spacing ( letter_spacing. 0 * scale_factor) ;
168+ }
169+
143170 buffer. set_text (
144171 font_system,
145172 params. text_for_internal_use ( ) ,
146- & Attrs :: new ( )
147- . color ( font_color. into ( ) )
148- . family ( font_family. to_fontdb_family ( ) )
149- . metadata ( metadata) ,
173+ & attrs,
150174 Shaping :: Advanced ,
175+ None ,
151176 ) ;
152177
153178 let mut buffer_measurement = Size :: default ( ) ;
@@ -162,12 +187,14 @@ pub(crate) fn update_buffer(
162187 None ,
163188 // TODO: what is the default tab width? Make it configurable?
164189 2 ,
190+ cosmic_text:: Hinting :: Enabled ,
165191 )
166192 . iter ( )
167193 {
168- buffer_measurement . y + = layout_line
194+ let line_height = layout_line
169195 . line_height_opt
170196 . unwrap_or ( text_style. line_height_pt ( ) * scale_factor) ;
197+ buffer_measurement. y += line_height;
171198 buffer_measurement. x = buffer_measurement. x . max ( layout_line. w ) ;
172199 }
173200 }
@@ -187,6 +214,7 @@ pub(crate) fn update_buffer(
187214 None ,
188215 // TODO: what is the default tab width? Make it configurable?
189216 2 ,
217+ cosmic_text:: Hinting :: Enabled ,
190218 ) ;
191219 }
192220 }
0 commit comments