Przeglądaj źródła

【修复】更新字体构建脚本并优化字形渲染参数

- 修复调整字体高度参数 13 至 12,并添加顶部和底部间距控制
- 修改垂直偏移量从 -2 到 -3 以改善字形对齐
- 优化字形渲染算法,支持可变高度渲染
- 在 .gitignore 中添加 Python 缓存文件忽略规则
PJ568 10 miesięcy temu
rodzic
commit
ba40cdb4b0
4 zmienionych plików z 120 dodań i 8 usunięć
  1. 4 1
      .gitignore
  2. 1 1
      VERSION
  3. 10 6
      build_font_from_bdf.py
  4. 105 0
      scripts/switch_1_2.py

+ 4 - 1
.gitignore

@@ -6,4 +6,7 @@
 
 AGENTS.md
 QWEN.md
-CLAUDE.md
+CLAUDE.md
+
+# Python
+__pycache__

+ 1 - 1
VERSION

@@ -1 +1 @@
-2.4.0
+2.4.1

+ 10 - 6
build_font_from_bdf.py

@@ -18,12 +18,14 @@ font = reader.read_bdf(open(bdf_file_path, "rb"))
 # File format version; currently this must be 0.
 version = '0'
 
-# 定义字体的高度和宽度
-height = 13
+# 所读取的字体的高度、宽度和字形上下间隔
+height = 12
 width = 12
+top_gap = 1
+bottom_gap = 0
 
 # 定义垂直偏移量
-v_offset = -2
+v_offset = -3
 
 # 初始化计数器
 count = 0
@@ -68,10 +70,12 @@ def PrintCharacters(Characters, count):
         # 打印字形的位图表示
         print("Bitmap: ", end="")
         o_pixels = [[y for y in x] for x in glyph.iter_pixels()]
+
+        # 取字形属性
         [left, bottom, w, h] = glyph.get_bounding_box()
 
         # 初始化一个空的像素矩阵
-        pixels = [["-" for j in range(0, width)] for i in range(0, height)]
+        pixels = [["-" for j in range(0, width)] for i in range(0, height + 1 + top_gap + bottom_gap)]
 
         # 填充像素矩阵
         for i in range(0, h):
@@ -79,9 +83,9 @@ def PrintCharacters(Characters, count):
                 pixels[-bottom - h + i + v_offset][left + j] = ("#" if o_pixels[i][j] else "-")
 
         # 打印像素矩阵
-        for l in range(0, height):
+        for l in range(top_gap, height + 1 - bottom_gap):
             ll = "".join(pixels[l])
-            if l < height - 1:
+            if l < height :
                 ll = ll + " \\"
             print(ll)
 

+ 105 - 0
scripts/switch_1_2.py

@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+将文本文件中每一行的第二个字符移动到行首
+"""
+
+import sys
+import os
+
+def switch_first_two_chars(line):
+    """
+    将字符串的第二个字符移动到行首
+    
+    Args:
+        line: 输入字符串(不含换行符)
+    
+    Returns:
+        转换后的字符串
+    """
+    if len(line) < 2:
+        return line
+    
+    # 第二个字符移动到行首
+    return line[1] + line[0] + line[2:]
+
+def process_file(file_path):
+    """
+    处理文件,将每一行的第二个字符移动到行首
+    
+    Args:
+        file_path: 文件路径
+    
+    Returns:
+        bool: 是否成功
+    """
+    try:
+        with open(file_path, 'r', encoding='utf-8') as f:
+            lines = f.readlines()
+        
+        new_lines = []
+        modified_count = 0
+        
+        for line in lines:
+            # 去除末尾换行符
+            stripped = line.rstrip('\n')
+            # 保留原始行结束符(可能是\r\n或其他)
+            line_ending = line[len(stripped):] if len(line) > len(stripped) else ''
+            
+            if len(stripped) >= 2:
+                new_stripped = switch_first_two_chars(stripped)
+                new_lines.append(new_stripped + line_ending)
+                if new_stripped != stripped:
+                    modified_count += 1
+            else:
+                new_lines.append(line)
+        
+        # 写回文件
+        with open(file_path, 'w', encoding='utf-8') as f:
+            f.writelines(new_lines)
+        
+        print(f"✅ 处理完成:修改了 {modified_count} 行")
+        return True
+        
+    except UnicodeDecodeError:
+        print(f"错误:无法读取文件 {file_path},请检查文件编码是否为 UTF-8")
+        return False
+    except FileNotFoundError:
+        print(f"错误:文件 {file_path} 不存在")
+        return False
+    except PermissionError:
+        print(f"错误:没有权限写入文件 {file_path}")
+        return False
+    except Exception as e:
+        print(f"错误:处理文件时发生异常:{e}")
+        return False
+
+def main():
+    if len(sys.argv) != 2:
+        print("用法: python3 switch_1_2.py <文件路径>")
+        print("将文本文件中每一行的第二个字符移动到行首")
+        return 1
+    
+    file_path = sys.argv[1]
+    
+    if not os.path.exists(file_path):
+        print(f"错误:文件 {file_path} 不存在")
+        return 1
+    
+    if os.path.isdir(file_path):
+        print(f"错误:{file_path} 是一个目录,不是文件")
+        return 1
+    
+    print(f"正在处理文件:{file_path}")
+    print("将每一行的第二个字符移动到行首...")
+    print("-" * 50)
+    
+    success = process_file(file_path)
+    
+    if not success:
+        return 1
+    
+    return 0
+
+if __name__ == "__main__":
+    exit(main())