ttf: improvement on not found glyphs (#8050)
parent
5f95dd54bd
commit
55e3e50b9b
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue