Skip to content

feat: [xps] implement export to PDF and save as XPS#212

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
LiHua000:xpsSupport
Nov 21, 2025
Merged

feat: [xps] implement export to PDF and save as XPS#212
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
LiHua000:xpsSupport

Conversation

@LiHua000
Copy link
Contributor

Implement XPS document export to PDF using Cairo PDF surface with libgxps rendering. Support both XPS file copy and PDF export based on file extension in saveAs() method.

Changes:

  • Add Cairo PDF surface support for XPS to PDF conversion
  • Implement saveAs() with format detection (.xps vs .pdf)
  • Update saveFilter() to return both XPS and PDF formats
  • Update DocSheet::filter() to show both format options in file dialog
  • Update DocSheet::saveAsData() to handle XPS format conversion
  • Use 1:1 coordinate mapping to preserve document dimensions
  • Enable best quality rendering with antialiasing

The implementation renders each XPS page to Cairo PDF surface using gxps_page_render(), maintaining vector quality and supporting variable page sizes.

Log: implement XPS export to PDF and save as XPS

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

Implement XPS document export to PDF using Cairo PDF surface with
libgxps rendering. Support both XPS file copy and PDF export based
on file extension in saveAs() method.

Changes:
- Add Cairo PDF surface support for XPS to PDF conversion
- Implement saveAs() with format detection (.xps vs .pdf)
- Update saveFilter() to return both XPS and PDF formats
- Update DocSheet::filter() to show both format options in file dialog
- Update DocSheet::saveAsData() to handle XPS format conversion
- Use 1:1 coordinate mapping to preserve document dimensions
- Enable best quality rendering with antialiasing

The implementation renders each XPS page to Cairo PDF surface using
gxps_page_render(), maintaining vector quality and supporting variable
page sizes.

Log: implement XPS export to PDF and save as XPS

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

deepin pr auto review

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

  1. 代码逻辑和语法:
  • 代码整体逻辑清晰,语法正确,使用了合适的C++特性
  • 错误处理完善,包含了各种边界情况的检查
  • 代码结构合理,功能模块划分清晰
  1. 代码质量改进建议:
  • 建议将PDF导出的相关代码抽取为一个独立的方法,以提高代码可维护性
  • 可以考虑添加一个配置选项来控制PDF导出的质量(如压缩率、DPI等)
  • 建议添加进度回调机制,在导出大量页面时可以显示进度
  1. 性能优化建议:
  • 在导出PDF时,可以考虑使用多线程处理,特别是对于大型文档
  • 可以添加内存使用监控,在处理大文件时避免内存占用过高
  • 建议添加页面缓存机制,避免重复渲染相同页面
  1. 安全性建议:
  • 文件路径处理需要加强,建议使用QFileInfo来规范化路径
  • 在文件操作前应该检查文件权限
  • 建议添加文件大小限制,防止处理过大文件导致系统资源耗尽
  • PDF导出过程中应该添加临时文件清理机制
  1. 具体改进建议:
bool XpsDocumentAdapter::saveAs(const QString &filePath) const
{
    // 添加文件大小检查
    const qint64 maxFileSize = 100 * 1024 * 1024; // 100MB
    QFileInfo sourceInfo(m_filePath);
    if (sourceInfo.size() > maxFileSize) {
        qCWarning(appLog) << "XPS saveAs: source file too large:" << sourceInfo.size();
        return false;
    }

    // 使用QFileInfo规范化路径
    const QString normalizedPath = QFileInfo(filePath).absoluteFilePath();
    if (normalizedPath.isEmpty()) {
        qCWarning(appLog) << "XPS saveAs: invalid file path";
        return false;
    }

    // 检查目标路径的写入权限
    QFileInfo targetInfo(normalizedPath);
    if (targetInfo.exists() && !targetInfo.isWritable()) {
        qCWarning(appLog) << "XPS saveAs: target file is not writable:" << normalizedPath;
        return false;
    }

    // ... 其余代码保持不变 ...
}

// 添加PDF导出配置结构
struct PdfExportConfig {
    int quality = 100;          // 导出质量 (0-100)
    int dpi = 72;              // 分辨率
    bool compress = true;       // 是否压缩
    // 可以添加更多配置项
};

// 修改PDF导出方法签名
bool XpsDocumentAdapter::exportToPdf(const QString &filePath, 
                                   const PdfExportConfig& config = PdfExportConfig()) const;
  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

/merge

@deepin-bot deepin-bot bot merged commit 3557a3b into linuxdeepin:master Nov 21, 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