Skip to content

fix(ffi): map SingularTransform diagnostic to C ABI v1 - #3

Merged
deepin-bot[bot] merged 3 commits into
linuxdeepin:mainfrom
add-uos:fix/ffi-singular-transform-diagnostic
Sep 14, 2026
Merged

deepin-bot[bot] merged 3 commits into
linuxdeepin:mainfrom
add-uos:fix/ffi-singular-transform-diagnostic

Conversation

@add-uos

@add-uos add-uos commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

问题

打开含奇异变换对象(退化 CTM,如 CTM="0 0 0 0.3528 0 0" 的空白文本对象,常见于部分转换器生成的 OFD)的文档时,rofd-render 正确跳过这些对象并发出 RenderDiagnosticKind::SingularTransform 诊断,但 FFI 层 diagnostic_kind() 未映射该枚举值,走到兜底分支返回 ROFD_STATUS_INTERNAL(错误消息 "renderer returned a diagnostic kind unknown to C ABI v1"),导致整页渲染失败、文档无法打开

复现样例:发票监制章-数科.ofd(内含 33 个此类对象)。

修复

  • crates/rofd-ffi/src/abi.rs:新增 ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM: u32 = 7
  • crates/rofd-ffi/include/rofd.h:新增对应 C 宏定义
  • crates/rofd-ffi/src/report.rs:映射 SingularTransform,并在单元测试中补齐该映射

新增值为追加常量,不破坏 C ABI v1 兼容性;消费方(deepin-reader)仅记录诊断内容,无需适配。

验证

  • C 程序直连 C ABI 渲染该文档:status 0,151 条诊断正常上报(kind=7 ×32、kind=2 字体回退)
  • 批量验证 ofdrw-compat 全部 4 个 fixture 目录(converter/layout/reader/sign)共 110 页:全部渲染成功,14731 条诊断均为合法类型
  • cargo test -p rofd-core -p rofd-render -p rofd-ffi、C ABI 集成测试脚本、cargo fmt --check 全部通过
  • deepin-reader(ofd_support 分支)实际打开该文档正常渲染,无 "unknown to C ABI v1" 错误

Summary by Sourcery

Map singular-transform renderer diagnostics to a stable C ABI value so affected documents render successfully instead of failing.

New Features:

  • Expose singular-transform render diagnostics as diagnostic kind 7 in the C ABI.

Bug Fixes:

  • Prevent documents containing singular transforms from failing whole-page rendering with an unknown diagnostic kind error.

Documentation:

  • Add Chinese project documentation and repository license metadata.

Tests:

  • Add coverage for mapping singular-transform diagnostics through the FFI.

Chores:

  • Add project and third-party license files and REUSE licensing configuration.

Map RenderDiagnosticKind::SingularTransform to the new constant
ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM (7). Documents containing objects
with a singular transform (degenerate CTM, e.g. empty text objects
written by some converters) made from_render_report fail with
ROFD_STATUS_INTERNAL, so the whole page failed to render. The
diagnostic is now reported through the render report and rendering
continues.

将 RenderDiagnosticKind::SingularTransform 映射到新增常量
ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM (7)。此前含奇异变换对象(退化
CTM,部分转换器生成的空白文本对象)的文档会因诊断类型未映射而以
ROFD_STATUS_INTERNAL 整页渲染失败;现在诊断通过渲染报告正常上报,
页面继续渲染。

Log: 修复奇异变换诊断导致整页渲染失败
Influence: 含奇异变换对象的OFD文档可正常打开渲染,诊断经渲染报告上报,C ABI向后兼容。
@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The FFI layer now reports skipped objects with singular transforms as diagnostic kind 7 through both Rust and C ABI definitions, preventing valid renderer diagnostics from escalating to internal errors and preserving C ABI v1 compatibility.

Sequence diagram for singular-transform diagnostic reporting

sequenceDiagram
    participant Renderer
    participant FFI
    participant CConsumer

    Renderer->>FFI: RenderDiagnosticKind::SingularTransform
    FFI->>FFI: diagnostic_kind(kind)
    FFI-->>CConsumer: ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM (7)
    CConsumer-->>CConsumer: Record diagnostic and continue rendering

    alt Unmapped diagnostic kind
        FFI-->>CConsumer: ROFD_STATUS_INTERNAL
    end
Loading

File-Level Changes

Change Details Files
Expose SingularTransform as a new C ABI v1 diagnostic value.
  • Add diagnostic constant 7 to the Rust ABI definitions.
  • Add the matching public C header macro as an appended value.
  • Preserve existing diagnostic numeric assignments and ABI compatibility.
crates/rofd-ffi/src/abi.rs
crates/rofd-ffi/include/rofd.h
Translate singular-transform renderer diagnostics instead of treating them as unknown internal errors.
  • Map RenderDiagnosticKind::SingularTransform to the new ABI value.
  • Extend report mapping tests to verify the new translation.
crates/rofd-ffi/src/report.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

The license-check workflow runs reuse lint on every PR, but the
repository had no copyright or licensing declarations at all (331
files non-compliant), so every PR failed the check regardless of
its content. Add a REUSE.toml covering the whole tree with
LGPL-2.1-or-later (matching Cargo.toml and debian/copyright),
Apache-2.0 for the ofdrw compatibility fixtures, a LicenseRef
annotation for the archived GB/T 33190-2016 standard document, and
the corresponding license texts under LICENSES/.

此前仓库完全没有REUSE许可声明(331个文件不合规),license-check
流水线对任何PR都会失败。新增全仓REUSE.toml(LGPL-2.1-or-later,
与Cargo.toml及debian/copyright一致)、ofdrw兼容测试资源的
Apache-2.0声明、GB/T标准文档的LicenseRef注记及LICENSES/许可文本。

Log: 补充REUSE许可声明修复流水线license-check失败
Influence: 仓库通过REUSE 3.3合规检查,许可信息与既有声明保持一致。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次提交将 SingularTransform 诊断正确映射到 C ABI v1,修复了含奇异变换对象的 OFD 文档整页渲染失败的问题,代码实现简洁正确,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰,无需修改


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,注释完整,无需修改


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理,无需优化


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞,代码仅涉及内部诊断常量映射,无用户输入处理、无外部数据交互、无密码学操作、无缓冲区操作、无路径操作、无命令执行,不存在攻击面


💡 改进建议代码示例

// 本次提交代码实现正确,无需修复示例
// crates/rofd-ffi/src/abi.rs
/// Diagnostic indicating an object was skipped because its transform is singular.
pub const ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM: u32 = 7;

// crates/rofd-ffi/src/report.rs - diagnostic_kind()
RenderDiagnosticKind::SingularTransform => Ok(ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM),

// crates/rofd-ffi/include/rofd.h
#define ROFD_DIAGNOSTIC_SINGULAR_TRANSFORM 7u

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, BLumia, 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

license-check 工作流同时检查中文自述文件 README.zh_CN.md 是否存在,
补充与 README.md 内容对应的中文版本。

Log: 补充README.zh_CN.md修复流水线license-check失败
Influence: 满足 license-check 对中英双语自述文件的要求。
@add-uos
add-uos force-pushed the fix/ffi-singular-transform-diagnostic branch from 069a050 to f3384a5 Compare September 14, 2026 05:37
@add-uos

add-uos commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

This pr cannot be merged! (status: unstable)

@add-uos

add-uos commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit b70f640 into linuxdeepin:main Sep 14, 2026
13 of 14 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.

4 participants