ttf: improvement on not found glyphs (#8050)

pull/8056/head
penguindark 2021-01-12 00:49:58 +01:00 committed by GitHub
parent 5f95dd54bd
commit 55e3e50b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 235 additions and 197 deletions

View File

@ -515,6 +515,13 @@ fn (mut bmp BitMap) get_chars_bbox(in_string string) []int {
} }
c_index := bmp.tf.map_code(int(char)) c_index := bmp.tf.map_code(int(char))
// Glyph not found
if c_index == 0 {
w += int(space_cw * bmp.space_cw)
i += c_len
continue
}
ax , ay := bmp.tf.next_kern(c_index) ax , ay := bmp.tf.next_kern(c_index)
//dprintln("char_index: $c_index ax: $ax ay: $ay") //dprintln("char_index: $c_index ax: $ax ay: $ay")
@ -581,6 +588,12 @@ fn (mut bmp BitMap) get_bbox(in_string string) (int, int){
} }
c_index := bmp.tf.map_code(int(char)) c_index := bmp.tf.map_code(int(char))
// Glyph not found
if c_index == 0 {
w += int(space_cw * bmp.space_cw)
i += c_len
continue
}
ax , ay := bmp.tf.next_kern(c_index) ax , ay := bmp.tf.next_kern(c_index)
//dprintln("char_index: $c_index ax: $ax ay: $ay") //dprintln("char_index: $c_index ax: $ax ay: $ay")
@ -623,6 +636,25 @@ fn (mut bmp BitMap) get_bbox(in_string string) (int, int){
* TTF draw glyph * TTF draw glyph
* *
******************************************************************************/ ******************************************************************************/
fn (mut bmp BitMap) draw_notdef_glyph(in_x int, in_w int) {
mut p := Point{in_x, 0, false}
x1 , y1 := bmp.trf_txt(p)
// init ch_matrix
bmp.ch_matrix[0] = bmp.tr_matrix[0] * bmp.scale * bmp.scale_x
bmp.ch_matrix[1] = bmp.tr_matrix[1] * bmp.scale * bmp.scale_x
bmp.ch_matrix[3] = bmp.tr_matrix[3] * -bmp.scale * bmp.scale_y
bmp.ch_matrix[4] = bmp.tr_matrix[4] * -bmp.scale * bmp.scale_y
bmp.ch_matrix[6] = int(x1)
bmp.ch_matrix[7] = int(y1)
x,y := bmp.trf_ch(p)
y_h := fabs(bmp.tf.y_max-bmp.tf.y_min)* bmp.scale * 0.5
bmp.box(int(x), int(y), int(x - in_w), int(y - y_h), bmp.color)
bmp.line(int(x), int(y), int(x - in_w ), int(y - y_h), bmp.color)
bmp.line(int(x - in_w ), int(y), int(x), int(y - y_h), bmp.color)
}
pub pub
fn (mut bmp BitMap) draw_text(in_string string) (int, int){ fn (mut bmp BitMap) draw_text(in_string string) (int, int){
mut w := 0 mut w := 0
@ -653,6 +685,14 @@ fn (mut bmp BitMap) draw_text(in_string string) (int, int){
} }
c_index := bmp.tf.map_code(int(char)) c_index := bmp.tf.map_code(int(char))
// Glyph not found
if c_index == 0 {
bmp.draw_notdef_glyph(w, int(space_cw * bmp.space_cw))
w += int(space_cw * bmp.space_cw)
i += c_len
continue
}
ax , ay := bmp.tf.next_kern(c_index) ax , ay := bmp.tf.next_kern(c_index)
//dprintln("char_index: $c_index ax: $ax ay: $ay") //dprintln("char_index: $c_index ax: $ax ay: $ay")
@ -684,7 +724,6 @@ fn (mut bmp BitMap) draw_text(in_string string) (int, int){
width = int((cw+ax) * bmp.scale) width = int((cw+ax) * bmp.scale)
} }
w += width + div_space_cw w += width + div_space_cw
i+= c_len i+= c_len
} }
@ -778,7 +817,7 @@ fn (mut bmp BitMap) draw_glyph(index u16) (int, int){
start_point.x, start_point.y = bmp.trf_ch(start_point) start_point.x, start_point.y = bmp.trf_ch(start_point)
if point.on_curve { if point.on_curve {
//ctx.quadraticCurveTo(prev.x + x, prev.y + y, //ctx.quadraticCurveTo(prev.x + x, prev.y + y,
// point.x + x, point.y + y); //point.x + x, point.y + y);
//bmp.line(x0, y0, start_point.x + in_x, start_point.y + in_y, u32(0x00FF0000)) //bmp.line(x0, y0, start_point.x + in_x, start_point.y + in_y, u32(0x00FF0000))
bmp.quadratic(x0, y0, start_point.x, start_point.y , bmp.quadratic(x0, y0, start_point.x, start_point.y ,
@ -796,7 +835,7 @@ fn (mut bmp BitMap) draw_glyph(index u16) (int, int){
//u32(0xFF000000)) //u32(0xFF000000))
color) color)
} }
}else{ } else {
// last point not in a curve // last point not in a curve
//bmp.line(point.x, point.y, sp_x, sp_y, u32(0x00FF0000)) //bmp.line(point.x, point.y, sp_x, sp_y, u32(0x00FF0000))
bmp.line(point.x, point.y, sp_x, sp_y, color) bmp.line(point.x, point.y, sp_x, sp_y, color)

View File

@ -488,7 +488,6 @@ fn (mut tf TTF_File) read_compound_glyph(mut in_glyph Glyph){
y: int(y) y: int(y)
on_curve: p.on_curve on_curve: p.on_curve
} }
} }
} }
tf.pos = old_pos tf.pos = old_pos