Ver código fonte

fixes font and cell size problems

devmil 4 anos atrás
pai
commit
422f2cecaf
2 arquivos alterados com 11 adições e 8 exclusões
  1. 5 0
      lib/frontend/cache.dart
  2. 6 8
      lib/frontend/terminal_view.dart

+ 5 - 0
lib/frontend/cache.dart

@@ -8,6 +8,10 @@ class TextLayoutCache {
   final LruMap<int, TextPainter> _cache;
   final TextDirection textDirection;
 
+  void clear() {
+    _cache.clear();
+  }
+
   TextPainter? getLayoutFromCache(int key) {
     return _cache[key];
   }
@@ -36,6 +40,7 @@ class TextLayoutCache {
 }
 
 final textLayoutCache = TextLayoutCache(TextDirection.ltr, 10240);
+double textLayoutCacheFontSize = 0;
 
 // class CodePointCache {
 //   CodePointCache(int maximumSize)

+ 6 - 8
lib/frontend/terminal_view.dart

@@ -51,11 +51,9 @@ class TerminalView extends StatefulWidget {
   CellSize measureCellSize(double fontSize) {
     final testString = 'xxxxxxxxxx' * 1000;
 
-    //TODO: remove me
-    print('Measuring for font size $fontSize');
-
     final text = Text(
       testString,
+      maxLines: 1,
       style: (style.textStyleProvider != null)
           ? style.textStyleProvider!(
               fontSize: fontSize,
@@ -69,10 +67,6 @@ class TerminalView extends StatefulWidget {
 
     final size = textSize(text);
 
-    //TODO: remove me
-    print('Text height: ${size.height}');
-    print('Text width: ${size.width}');
-
     final charWidth = (size.width / testString.length);
     final charHeight = size.height;
 
@@ -533,7 +527,11 @@ class TerminalPainter extends CustomPainter {
 
     // final cellHash = line.cellGetHash(cell);
     final fontSize = view.style.fontSize + fontSizeCorrection;
-    final cellHash = hashValues(codePoint, fgColor, bgColor, flags, fontSize);
+    if (textLayoutCacheFontSize != fontSize) {
+      textLayoutCache.clear();
+      textLayoutCacheFontSize = fontSize;
+    }
+    final cellHash = hashValues(codePoint, fgColor, bgColor, flags);
 
     var tp = textLayoutCache.getLayoutFromCache(cellHash);
     if (tp != null) {