@@ -196,14 +196,13 @@ impl<'a, R: femtovg::Renderer + TextureImporter> GLItemRenderer<'a, R> {
196196}
197197
198198fn draw_glyphs < R : femtovg:: Renderer + TextureImporter > (
199- layout : & parley :: Layout < sharedfontique :: Brush > ,
199+ layout : & fonts :: Layout ,
200200 canvas : & mut Canvas < R > ,
201201 paint : & femtovg:: Paint ,
202- offset : f32 ,
203202 selection_foreground_color : Color ,
204203 selection_background_color : Color ,
205204) {
206- for line in layout. lines ( ) {
205+ for line in layout. inner . lines ( ) {
207206 for item in line. items ( ) {
208207 match item {
209208 parley:: PositionedLayoutItem :: GlyphRun ( glyph_run) => {
@@ -220,9 +219,12 @@ fn draw_glyphs<R: femtovg::Renderer + TextureImporter>(
220219 let selection_rect = PhysicalRect :: new (
221220 PhysicalPoint :: new (
222221 start. x ,
223- start. y + offset - glyph_run. run ( ) . font_size ( ) ,
222+ start. y + layout. y_offset - run. font_size ( ) ,
223+ ) ,
224+ PhysicalSize :: new (
225+ glyph_run. advance ( ) ,
226+ run. font_size ( ) + run. metrics ( ) . descent ,
224227 ) ,
225- PhysicalSize :: new ( glyph_run. advance ( ) , glyph_run. run ( ) . font_size ( ) ) ,
226228 ) ;
227229 canvas. fill_path (
228230 & rect_to_path ( selection_rect) ,
@@ -238,7 +240,7 @@ fn draw_glyphs<R: femtovg::Renderer + TextureImporter>(
238240 let glyphs = glyph_run. positioned_glyphs ( ) . map ( |glyph : parley:: Glyph | {
239241 femtovg:: PositionedGlyph {
240242 x : glyph. x ,
241- y : glyph. y + offset ,
243+ y : glyph. y + layout . y_offset ,
242244 font_id,
243245 glyph_id : glyph. id ,
244246 }
@@ -399,8 +401,8 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
399401 size : LogicalSize ,
400402 _cache : & CachedRenderingData ,
401403 ) {
402- let max_width = size. width_length ( ) * self . scale_factor ;
403- let max_height = size. height_length ( ) * self . scale_factor ;
404+ let max_width = size. width_length ( ) ;
405+ let max_height = size. height_length ( ) ;
404406
405407 if max_width. get ( ) <= 0. || max_height. get ( ) <= 0. {
406408 return ;
@@ -450,8 +452,11 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
450452
451453 let layout = fonts:: layout (
452454 text. text ( ) . as_str ( ) ,
455+ self . scale_factor . get ( ) ,
453456 fonts:: LayoutOptions {
454457 horizontal_align,
458+ vertical_align,
459+ max_height : Some ( max_height) ,
455460 max_width : Some ( max_width) ,
456461 stroke : stroke_paint. is_some ( ) . then_some ( stroke_style) . map ( |style| match style {
457462 TextStrokeStyle :: Outside => sharedfontique:: BrushTextStrokeStyle :: Outside ,
@@ -464,9 +469,8 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
464469 ) ;
465470
466471 let mut canvas = self . canvas . borrow_mut ( ) ;
467- let offset = fonts:: get_offset ( vertical_align, max_height, & layout) ;
468472
469- draw_glyphs ( & layout, & mut canvas, & paint, offset , Color :: default ( ) , Color :: default ( ) ) ;
473+ draw_glyphs ( & layout, & mut canvas, & paint, Color :: default ( ) , Color :: default ( ) ) ;
470474 }
471475
472476 fn draw_text_input (
@@ -475,8 +479,8 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
475479 self_rc : & ItemRc ,
476480 size : LogicalSize ,
477481 ) {
478- let width = size. width_length ( ) * self . scale_factor ;
479- let height = size. height_length ( ) * self . scale_factor ;
482+ let width = size. width_length ( ) ;
483+ let height = size. height_length ( ) ;
480484 if width. get ( ) <= 0. || height. get ( ) <= 0. {
481485 return ;
482486 }
@@ -515,36 +519,36 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
515519
516520 let layout = fonts:: layout (
517521 & text,
522+ self . scale_factor . get ( ) ,
518523 fonts:: LayoutOptions {
519524 max_width : Some ( width) ,
525+ max_height : Some ( height) ,
526+ vertical_align : text_input. vertical_alignment ( ) ,
520527 selection : Some ( min_select..max_select) ,
521528 font_request : Some ( font_request) ,
522529 ..Default :: default ( )
523530 } ,
524531 ) ;
525- let offset = fonts:: get_offset ( text_input. vertical_alignment ( ) , height, & layout) ;
526532 draw_glyphs (
527533 & layout,
528534 & mut canvas,
529535 & paint,
530- offset,
531536 text_input. selection_foreground_color ( ) ,
532537 text_input. selection_background_color ( ) ,
533538 ) ;
534539
535540 if cursor_visible {
536541 let cursor = parley:: layout:: cursor:: Cursor :: from_byte_index (
537- & layout,
542+ & layout. inner ,
538543 cursor_pos,
539544 Default :: default ( ) ,
540545 ) ;
541- let rect = cursor
542- . geometry ( & layout, ( text_input. text_cursor_width ( ) * self . scale_factor ) . get ( ) ) ;
546+ let rect = cursor. geometry ( & layout. inner , ( text_input. text_cursor_width ( ) ) . get ( ) ) ;
543547
544548 let mut cursor_rect = femtovg:: Path :: new ( ) ;
545549 cursor_rect. rect (
546- rect. center ( ) . x as _ ,
547- rect. center ( ) . y as _ ,
550+ rect. min_x ( ) as _ ,
551+ rect. min_y ( ) as f32 + layout . y_offset ,
548552 rect. width ( ) as _ ,
549553 rect. height ( ) as _ ,
550554 ) ;
@@ -980,10 +984,10 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
980984 }
981985
982986 fn draw_string ( & mut self , string : & str , color : Color ) {
983- let layout = fonts:: layout ( string, Default :: default ( ) ) ;
987+ let layout = fonts:: layout ( string, self . scale_factor . get ( ) , Default :: default ( ) ) ;
984988 let paint = femtovg:: Paint :: color ( to_femtovg_color ( & color) ) ;
985989 let mut canvas = self . canvas . borrow_mut ( ) ;
986- draw_glyphs ( & layout, & mut canvas, & paint, 0.0 , color, color) ;
990+ draw_glyphs ( & layout, & mut canvas, & paint, color, color) ;
987991 }
988992
989993 fn draw_image_direct ( & mut self , image : i_slint_core:: graphics:: Image ) {
0 commit comments