@@ -25,14 +25,14 @@ pub fn NodeText(comptime Impl: type) type {
2525 const self = try alloc .create (State );
2626 self .* = .{
2727 .font = options .font ,
28- .text = try alloc . dupe ( u21 , options .text ) ,
28+ .view = options .view ,
2929 .implState = if (ImplState != void ) ImplState .init (alloc , options ) else {},
3030 };
3131 return self ;
3232 }
3333
3434 pub fn equal (self : * State , other : * State ) bool {
35- return std .simd .countTrues (@Vector (2 , bool ){
35+ return std .simd .countTrues (@Vector (3 , bool ){
3636 self .font == other .font ,
3737 std .mem .eql (u8 , self .view .bytes , other .view .bytes ),
3838 if (ImplState != void ) self .implState .equal (other .implState ) else true ,
@@ -96,9 +96,14 @@ pub fn NodeText(comptime Impl: type) type {
9696 while (viewIter .nextCodepoint ()) | cp | {
9797 const glyph = try self .options .font .lookupGlyph (cp );
9898
99- width += glyph .advance .value [0 ];
100- yMaxMin .value [0 ] = @max (yMaxMin .value [0 ], glyph .bearing .value [1 ]);
101- yMaxMin .value [1 ] = @min (yMaxMin .value [1 ], glyph .bearing .value [1 ] - glyph .size .value [1 ]);
99+ width += @intCast (glyph .advance .value [0 ]);
100+ yMaxMin .value [0 ] = @max (yMaxMin .value [0 ], @as (usize , @intCast (glyph .bearing .value [1 ])));
101+
102+ if (glyph .bearing .value [1 ] >= glyph .size .value [1 ]) {
103+ yMaxMin .value [1 ] = @min (yMaxMin .value [1 ], @as (usize , @intCast (glyph .bearing .value [1 ] - @as (i8 , @intCast (glyph .size .value [1 ])))));
104+ } else {
105+ yMaxMin .value [1 ] = @min (yMaxMin .value [1 ], @as (usize , @intCast (glyph .size .value [1 ] - glyph .size .value [1 ])));
106+ }
102107 }
103108
104109 return .{ .value = .{ width , yMaxMin .value [0 ] - yMaxMin .value [1 ] } };
@@ -164,7 +169,7 @@ pub fn NodeText(comptime Impl: type) type {
164169 var output = std .ArrayList (u8 ).init (self .node .allocator );
165170 errdefer output .deinit ();
166171
167- try output .writer ().print ("{{ .font = {}, .text = \" {}\" }}" , .{ self .options .font , std . unicode . fmtUtf8 ( self .options .view .bytes ) });
172+ try output .writer ().print ("{{ .font = {}, .text = \" {s }\" }}" , .{ self .options .font , self .options .view .bytes });
168173 return output ;
169174 }
170175 };
0 commit comments