|
1 | 1 | mod context; |
2 | 2 | mod itemize; |
3 | 3 |
|
4 | | -pub use self::context::{CellMetrics, Context, FontFeatures}; |
| 4 | +pub use self::context::{CellMetrics, Context, FontFeatures, SubCtx}; |
5 | 5 |
|
6 | 6 | use log::warn; |
7 | 7 |
|
@@ -672,54 +672,69 @@ fn snapshot_cell( |
672 | 672 |
|
673 | 673 | pub fn shape_dirty( |
674 | 674 | ctx: &context::Context, |
675 | | - ui_model: &mut ui_model::UiModel, |
676 | | - pix: &mut PixModel, |
| 675 | + sub_ctxs: &mut SubCtx, |
| 676 | + grid: &mut Grid, |
677 | 677 | hl: &HighlightMap, |
678 | 678 | update_pix: bool, |
679 | | - sign_column: usize, |
680 | 679 | monospace: bool, |
681 | 680 | ) { |
682 | | - let space_width = ctx.cell_metrics().char_width as f32; |
683 | | - |
684 | | - for (row, line) in ui_model.model_mut().iter_mut().enumerate() { |
| 681 | + let cell_metrics = ctx.cell_metrics(); |
| 682 | + let space_width = cell_metrics.char_width as f32; |
| 683 | + let sign_column = grid.sign_column_len(); |
| 684 | + let width = (grid.rect.0 + grid.rect.2) as f32; |
| 685 | + for (row, line) in grid.model.model_mut().iter_mut().enumerate() { |
685 | 686 | if !line.dirty_line { |
686 | 687 | continue; |
687 | 688 | } |
688 | | - |
689 | | - let styled_line = ui_model::StyledLine::from(line, hl, ctx.font_features()); |
690 | | - let items = ctx.itemize(&styled_line); |
691 | | - line.merge(&styled_line, &items); |
692 | | - |
693 | | - for (col, cell) in line.line.iter_mut().enumerate() { |
694 | | - if cell.dirty { |
695 | | - for item in &mut *line.item_line[col] { |
696 | | - let mut glyphs = pango::GlyphString::new(); |
697 | | - { |
698 | | - let analysis = item.analysis(); |
699 | | - let offset = item.item.offset() as usize; |
700 | | - let length = item.item.length() as usize; |
701 | | - if let Some(line_str) = styled_line.line_str.get(offset..offset + length) { |
702 | | - pango::shape(line_str, analysis, &mut glyphs); |
703 | | - } else { |
704 | | - warn!("Wrong itemize split"); |
705 | | - } |
706 | | - } |
707 | | - |
708 | | - item.set_glyphs(glyphs); |
709 | | - } |
| 689 | + shape_dirty_line(line, hl, ctx); |
| 690 | + line.dirty_line = false; |
| 691 | + if !update_pix { |
| 692 | + continue; |
| 693 | + } |
| 694 | + if monospace { |
| 695 | + grid.pix.update_mono(row, space_width); |
| 696 | + continue; |
| 697 | + } |
| 698 | + let x = grid.pix.update(line, row, space_width, sign_column); |
| 699 | + if x <= width { |
| 700 | + continue; |
| 701 | + } |
| 702 | + let mut ratio = 1.0; |
| 703 | + loop { |
| 704 | + ratio -= 0.05; |
| 705 | + let size = sub_ctxs.max_smaller_size(ratio); |
| 706 | + for cell in line.line.iter_mut().skip(sign_column) { |
| 707 | + cell.dirty = true; |
| 708 | + } |
| 709 | + shape_dirty_line(line, hl, sub_ctxs.get_or_create(size)); |
| 710 | + if grid.pix.update(line, row, space_width, sign_column) <= width { |
| 711 | + break; |
710 | 712 | } |
711 | | - |
712 | | - cell.dirty = false; |
713 | 713 | } |
| 714 | + } |
| 715 | +} |
714 | 716 |
|
715 | | - if update_pix { |
716 | | - if monospace { |
717 | | - pix.update_line_monospace(row, space_width); |
718 | | - } else { |
719 | | - pix.update_line(line, row, space_width, sign_column); |
| 717 | +fn shape_dirty_line(line: &mut Line, hl: &HighlightMap, ctx: &Context) { |
| 718 | + let styled_line = ui_model::StyledLine::from(line, hl, ctx.font_features()); |
| 719 | + let items = ctx.itemize(&styled_line); |
| 720 | + line.merge(&styled_line, &items); |
| 721 | + for (col, cell) in line.line.iter_mut().enumerate() { |
| 722 | + if cell.dirty { |
| 723 | + for item in &mut *line.item_line[col] { |
| 724 | + let mut glyphs = pango::GlyphString::new(); |
| 725 | + { |
| 726 | + let analysis = item.analysis(); |
| 727 | + let offset = item.item.offset() as usize; |
| 728 | + let length = item.item.length() as usize; |
| 729 | + if let Some(line_str) = styled_line.line_str.get(offset..offset + length) { |
| 730 | + pango::shape(line_str, analysis, &mut glyphs); |
| 731 | + } else { |
| 732 | + warn!("Wrong itemize split"); |
| 733 | + } |
| 734 | + } |
| 735 | + item.set_glyphs(glyphs); |
720 | 736 | } |
721 | 737 | } |
722 | | - |
723 | | - line.dirty_line = false; |
| 738 | + cell.dirty = false; |
724 | 739 | } |
725 | 740 | } |
0 commit comments