Skip to content

[6237] 修复绘制图形模式下矩形边框线无法设置为虚线的问题 - #4770

Merged
PinkMagicFly merged 1 commit into
mainfrom
pigmagicfly/6237/graphics-rect-dash-line
Nov 4, 2026
Merged

PinkMagicFly merged 1 commit into
mainfrom
pigmagicfly/6237/graphics-rect-dash-line

Conversation

@PinkMagicFly

Copy link
Copy Markdown
Contributor

任务背景与问题

在绘制图形模式下,矩形的边框线无法设置为虚线。
经排查,在 TeXmacs/progs/graphics/graphics-drd.scm 中,曲线与闭合图形标签通过 graphical-open-curve-tag(直线 line 等)与 graphical-closed-curve-tag(多边形 cline、圆 circle、椭圆 ellipse 等)统一归入 graphical-curve-tag,获得边框线宽(line-width)、虚线样式(dash-style、dash-style-unit)及填充色(fill-color)等属性。
矩形(rectangle)在几何语义上同属闭合曲线族,底层宏亦展开为闭合折线 cline,但此前在 graphics-drd.scm 中遗漏了将 rectangle 加入 graphical-closed-curve-tag,导致:

  1. (graphics-attributes 'rectangle) 仅回退到公共基础属性,缺少 dash-style 与 line-width;
  2. (graphics-mode-attribute? '(edit rectangle) "dash-style") 为 #f,菜单栏与工具栏不展示虚线样式菜单;
  3. graphics-sync-type-config 无法保存矩形的虚线配置;
  4. 新建矩形时 graphics-enrich-filter 判定矩形不具备 dash-style 属性而将其过滤剥离,最终无法生成和渲染虚线边框矩形。

解决方案

参考曲线(line)与多边形(cline)等闭合图形的线条属性组织方式,在 TeXmacs/progs/graphics/graphics-drd.scm 的 graphical-closed-curve-tag 分组中加入 rectangle:

(define-group graphical-closed-curve-tag cline cspline cbezier csmooth carc oval
  circle ellipse sector sector-counterclockwise rectangle
) ;define-group

使 rectangle 自动继承曲线族的完整线条属性,工具栏和焦点菜单在 (edit rectangle) 模式下正常呈现线条样式(dash-style)与线宽选项,绘制时正常生成带 dash-style 的图形树并渲染为虚线。

验证与测试

  1. 单元测试:
    新增纯逻辑单元测试 TeXmacs/progs/graphics/tests/graphics-rectangle-test.scm,覆盖 4 组共 12 项断言(标签分组、图形属性、编辑模式属性、enrich-filter):
    xmake r graphics-rectangle-test
    测试结果:12 correct, 0 failed 全部通过。
  2. 回归测试:
    运行 xmake r graphics-ghost-test 正常通过(3 correct, 0 failed)。
  3. 关联任务文档:
    dev-agent PR: https://github.com/LiiiLabs/dev-agent/pull/357

手动验证步骤

  1. 启动 Mogan STEM,在文档中插入绘图画布(菜单「插入 -> 图片 -> 绘制图形」);
  2. 点击绘图工具栏的「矩形」图标(快捷键 0),观察焦点工具栏与「Focus」菜单,确认出现「线条样式」(Line styles)下拉菜单;
  3. 在虚线样式菜单中选择任一虚线(如「- - - - -」);
  4. 在画布中拖拽绘制矩形,确认矩形边框线呈虚线绘制并显示;
  5. 切换到「属性编辑」工具(快捷键 p),选中该矩形,修改其线条样式或线宽,确认实时跟随更新;
  6. 切换到多边形工具修改为实线后再切回矩形工具,确认矩形类型的虚线配置独立保留且未被污染。

@da-liii da-liii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PinkMagicFly
PinkMagicFly merged commit 77a3d3d into main Nov 4, 2026
3 checks passed
@PinkMagicFly
PinkMagicFly deleted the pigmagicfly/6237/graphics-rect-dash-line branch November 4, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants