1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

freetype: fix placement of highdpi and lowdpi texts

This commit is contained in:
Delyan Angelov 2020-01-19 21:30:53 +02:00 committed by Alexander Medvednikov
parent bfaf2a4a62
commit bc64263dd8

View File

@ -288,6 +288,7 @@ fn (ctx mut FreeType) private_draw_text(_x, _y int, utext ustring, cfg gx.TextCf
mut x := f32(_x) mut x := f32(_x)
mut y := f32(_y) mut y := f32(_y)
wx, wy := ctx.text_size(utext.s) wx, wy := ctx.text_size(utext.s)
yoffset := if ctx.scale > 1 { 5 /* highdpi */ } else { -1 /* lowdpi */ }
// println('scale=$ctx.scale size=$cfg.size') // println('scale=$ctx.scale size=$cfg.size')
if cfg.align == gx.ALIGN_RIGHT { if cfg.align == gx.ALIGN_RIGHT {
//width := utext.len * 7 //width := utext.len * 7
@ -296,6 +297,7 @@ fn (ctx mut FreeType) private_draw_text(_x, _y int, utext ustring, cfg gx.TextCf
} }
x *= ctx.scale x *= ctx.scale
y *= ctx.scale y *= ctx.scale
y += yoffset
y = f32(ctx.height) - y //invert y direction y = f32(ctx.height) - y //invert y direction
color := cfg.color color := cfg.color
// Activate corresponding render state // Activate corresponding render state
@ -431,8 +433,10 @@ pub fn (ctx mut FreeType) text_size(s string) (int, int) {
} }
} }
//println('text width "$s" = ${time.ticks() - t} ms') //println('text width "$s" = ${time.ticks() - t} ms')
scaled_x := int(f64(x)) //scaled_x := x
scaled_y := int(f64(maxy)) //scaled_y := maxy
scaled_x := int(f64(x)/ctx.scale)
scaled_y := int(f64(maxy)/ctx.scale)
//println('text_size of "${s}" | x,y: $x,$maxy | scaled_x: ${scaled_x:3d} | scaled_y: ${scaled_y:3d} ') //println('text_size of "${s}" | x,y: $x,$maxy | scaled_x: ${scaled_x:3d} | scaled_y: ${scaled_y:3d} ')
return scaled_x, scaled_y return scaled_x, scaled_y
} }