Skip to content

Conversation

@LiHua000
Copy link
Contributor

@LiHua000 LiHua000 commented Nov 17, 2025

Implement XPS text extraction by parsing FixedPage XML structure.
Support both attribute and child element forms of RenderTransform to
handle coordinate transformations correctly. Parse Indices attribute
for precise character widths and support character-level selection.

log: feature

task: https://pms.uniontech.com/task-view-383459.html

Implement XPS text extraction by parsing FixedPage XML structure.
Support both attribute and child element forms of RenderTransform to
handle coordinate transformations correctly. Parse Indices attribute
for precise character widths and support character-level selection.

log: feature

task: https://pms.uniontech.com/task-view-383459.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行详细的审查:

  1. .gitignore 修改:
  • 新增了 .cursor/ 目录的忽略规则,这是合理的,用于忽略 Cursor 编辑器的配置文件。
  1. BrowserWord.cpp 修改:
  • 删除了调试日志代码,直接返回计算结果,这是好的实践,减少了不必要的日志输出。
  • 代码更简洁,但建议在注释中保留边界框计算公式的说明。
  1. XpsDocumentAdapter.cpp 修改:
  • 新增了文本提取功能,实现了 text()words() 方法。
  • 优点:
    • 实现了基于矩形区域的文本提取
    • 支持字符级别的文本选择
    • 使用了排序算法确保文本顺序正确
  • 建议改进:
    • yThreshold 常量应该定义为类的静态常量
    • 文本拼接逻辑可以考虑添加换行符的处理选项
    • 添加更多的错误处理和边界检查
  1. XpsTextExtractor.cpp 新增文件:
  • 实现了完整的 XPS 文本提取功能
  • 优点:
    • 支持字符级别的文本提取
    • 实现了准确的边界框计算
    • 支持多种字符集的宽度估算
    • 处理了变换矩阵
  • 建议改进:
    • 添加文件大小限制检查(目前是硬编码的100MB)
    • 考虑添加缓存机制,避免重复解析
    • estimateCharWidth 方法可以考虑使用更精确的字体度量数据
    • 添加更多的错误处理和日志记录
  1. XpsTextExtractor.h 新增文件:
  • 定义了清晰的接口和数据结构
  • 优点:
    • 文档注释完整
    • 结构设计合理
    • 接口设计清晰
  • 建议改进:
    • 可以考虑添加一些配置选项(如字符间距、行间距等)
    • 添加版本信息和兼容性说明

总体建议:

  1. 性能优化:
  • 考虑实现文本提取结果的缓存机制
  • 对于大型文档,可以实现分页加载
  • 优化字符串操作,减少不必要的内存分配
  1. 安全性:
  • 添加对恶意构造的 XPS 文件的防护
  • 增加对 XML 解析的安全检查
  • 限制内存使用,防止内存耗尽
  1. 代码质量:
  • 添加更多的单元测试
  • 考虑将一些魔法数字提取为常量
  • 增加错误处理的详细日志
  1. 功能扩展:
  • 支持更多的文本格式特性
  • 添加对表格内容的特殊处理
  • 支持文本样式信息的提取
  1. 文档完善:
  • 添加更详细的使用示例
  • 说明性能特点和限制
  • 添加对特殊字符和编码的处理说明

这些修改整体上是积极的,实现了重要的文本提取功能,但还有进一步优化的空间。建议在后续版本中逐步完善这些改进点。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@LiHua000
Copy link
Contributor Author

/forcemerge

@deepin-bot deepin-bot bot merged commit d10e1cd into linuxdeepin:master Nov 17, 2025
6 checks passed
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.

3 participants