Get sizes from FontMetrics

This commit is contained in:
daa84
2017-09-05 18:23:46 +03:00
parent bc31984362
commit 05dee3251f
4 changed files with 177 additions and 163 deletions

View File

@@ -1,6 +1,7 @@
mod context;
pub use self::context::Context;
pub use self::context::CellMetrics;
use color;
use sys::pango::*;
@@ -11,10 +12,9 @@ use ui_model;
pub fn render(
ctx: &cairo::Context,
font_ctx: &context::Context,
ui_model: &ui_model::UiModel,
color_model: &color::ColorModel,
line_height: f64,
char_width: f64,
) {
ctx.set_source_rgb(
color_model.bg_color.0,
@@ -23,16 +23,25 @@ pub fn render(
);
ctx.paint();
let mut line_y = line_height;
let &CellMetrics {line_height, char_width, ..} = font_ctx.cell_metrics();
let mut line_y = 0.0;
let ascent = font_ctx.ascent();
for line in ui_model.model() {
let mut line_x = 0.0;
for i in 0..line.line.len() {
ctx.move_to(line_x, line_y);
let (bg, fg) = color_model.cell_colors(&line.line[i]);
if let Some(bg) = bg {
ctx.set_source_rgb(bg.0, bg.1, bg.2);
ctx.rectangle(line_x, line_y, char_width, line_height);
ctx.fill();
}
if let Some(item) = line.item_line[i].as_ref() {
if let Some(ref glyphs) = item.glyphs {
let (_, fg) = color_model.cell_colors(&line.line[i]);
ctx.move_to(line_x, line_y + ascent);
ctx.set_source_rgb(fg.0, fg.1, fg.2);
ctx.show_glyph_string(item.font(), glyphs);
}