Skip to content

feat: add paper size support with auto-detection and OFD output - #30

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
re2zero:bugfix
Dec 19, 2025
Merged

feat: add paper size support with auto-detection and OFD output#30
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero

@re2zero re2zero commented Dec 19, 2025

Copy link
Copy Markdown
Contributor
  • Add paper size enum and methods to ScannerDevice with standard ISO sizes
  • Implement paper size selection UI in ScanWidget with auto-detection
  • Add image scaling to target paper size dimensions based on DPI
  • Update OFD writer to accept custom page dimensions
  • Add paper size translations for multiple languages
  • Disable test device by default in debug builds

Log: add paper size support with auto-detection and OFD output.

- Add paper size enum and methods to ScannerDevice with standard ISO sizes
- Implement paper size selection UI in ScanWidget with auto-detection
- Add image scaling to target paper size dimensions based on DPI
- Update OFD writer to accept custom page dimensions
- Add paper size translations for multiple languages
- Disable test device by default in debug builds

Log: add paper size support with auto-detection and OFD output.
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来帮你分析这个git diff。这是一个扫描仪应用程序的更新,主要添加了纸张尺寸支持功能。我将从代码质量、性能和安全等方面进行分析。

  1. 代码质量改进建议:

scannerdevice.h/cpp:

  • 纸张尺寸枚举定义合理,但建议添加注释说明每种尺寸的用途
  • getPaperSizeDimensions() 方法应考虑添加参数验证
  • 建议将纸张尺寸常量定义为类的静态成员变量,便于维护

scanwidget.cpp:

  • detectPaperSize() 方法中的容差值(tolerance = 15.0)应该定义为可配置的常量
  • scaleToPaperSize() 方法较长,建议拆分为更小的函数
  • onPaperSizeChanged() 方法缺少错误处理
  1. 性能优化建议:
  • 图像缩放操作(scaleToPaperSize)可能会消耗较多资源,建议:

    • 添加进度提示
    • 考虑使用多线程处理大图像
    • 添加最大尺寸限制,防止内存溢出
  • 纸张尺寸检测(detectPaperSize)可以优化:

    • 使用查找表代替循环比较
    • 考虑缓存检测结果
  1. 安全性改进:
  • 图像处理相关函数需要添加边界检查
  • 临时文件操作应该增加权限验证
  • 建议添加输入参数的有效性验证
  1. 具体代码修改建议:
// scannerdevice.h
class ScannerDevice : public DeviceBase 
{
    static const double TOLERANCE;  // 添加容差常量
    static const QMap<PaperSize, QSizeF> PAPER_SIZES;  // 纸张尺寸映射表
    
    // ...
};

// scannerdevice.cpp
const double ScannerDevice::TOLERANCE = 15.0;
const QMap<PaperSize, QSizeF> ScannerDevice::PAPER_SIZES = {
    {PAPER_SIZE_A3, QSizeF(297, 420)},
    // ...
};

// scanwidget.cpp
QImage ScanWidget::scaleToPaperSize(const QImage &image, PaperSize targetSize, int dpi)
{
    if (image.isNull()) {
        qWarning() << "Invalid input image";
        return image;
    }
    
    // 添加最大尺寸检查
    const int MAX_SIZE = 10000;  // 最大像素尺寸
    if (image.width() > MAX_SIZE || image.height() > MAX_SIZE) {
        qWarning() << "Image size exceeds maximum allowed dimensions";
        return image;
    }
    
    // ... 其他实现
}
  1. 其他建议:
  • 添加单元测试覆盖新增功能
  • 考虑添加自定义纸张尺寸支持
  • 为图像处理添加取消机制
  • 添加日志记录便于调试

这些修改将提高代码的健壮性、性能和可维护性。建议分阶段实施这些改进,优先处理安全性和稳定性相关的问题。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@re2zero

re2zero commented Dec 19, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Dec 19, 2025

Copy link
Copy Markdown

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 81ff0fd into linuxdeepin:master Dec 19, 2025
14 of 15 checks passed
@re2zero
re2zero deleted the bugfix branch December 19, 2025 05:40
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