问题描述
这是我使用 opengl 渲染文本时得到的(我的在右边)
字母“j”非常接近字母“k”
这是我测量字符大小和位置的方法
fn main() {
let library = ft::Library::init().unwrap();
let face = library.new_face(font,0).unwrap();
face.set_pixel_sizes(0,50);
let string = String::from("jkl");
let mut font_measure: HashMap<char,FontSize> = HashMap::new();
for c in string.chars() {
face.load_char(c as usize,ft::face::LoadFlag::DEFAULT)
.unwrap();
let glyph = face.glyph();
let metrics = glyph.metrics();
let width = metrics.width >> 6;
let bBox_ymax = face.raw().bBox.yMax >> 6;
let face_height = (face.raw().height >> 6) as f64;
font_measure.insert(
c,FontSize {
width: metrics.width >> 6,height: metrics.height >> 6,advance: glyph.advance().x + width / 2 >> 6,y_offset: (bBox_ymax - metrics.horibearingY >> 6) as f64 + face_height,},);
}
}
fn main() {
let mut pen_x = 0.0;
let mut pen_y = 0.0;
for character in line.text.chars() {
let character_props = &k.get(&character).unwrap();
// ....
// vertex_buffer.splice(start..end,character_vertices.iter().cloned());
// move drawing position in the x for advance.x
pen_x += character_props.advance;
}
}
解决方法
解决了。我没有考虑水平方向