[Feature] Support custom color#52
Merged
erweixin merged 11 commits intoApr 22, 2026
Merged
Conversation
- 更新 RatexOptions 结构体,添加颜色字段以支持 RGBA 颜色。 - 修改多个文件以实现颜色参数的传递和使用,包括 JNI、Swift、Kotlin 和 Dart。 - 更新文档示例,展示如何使用新的颜色选项进行 LaTeX 渲染。 - 确保向后兼容性,旧的调用方式仍然有效。
- 添加了颜色比较和提取功能的辅助方法 - 增加了自定义颜色解码的测试用例 - 验证显式 LaTeX 颜色覆盖默认颜色的行为
- 在 README 中添加了对数学视图默认颜色的支持说明 - 更新了示例代码,展示如何在不同环境中使用自定义颜色 - 说明显式 LaTeX 颜色优先于默认颜色的行为
erweixin
reviewed
Apr 21, 2026
| + std::mem::size_of::<RatexColor>(); | ||
|
|
||
| if opts_ref.struct_size >= color_size { | ||
| opts_ref.color.into() |
| void didChangeDependencies() { | ||
| super.didChangeDependencies(); | ||
| if (widget.color == null) { | ||
| _render(); |
Owner
There was a problem hiding this comment.
可以增加一个状态,记录一下 _inheritedColor 的 last value, 只有变化的时候才需要 _render ,没有变化的时候是不是就不用重新渲染,可以优化下性能。
| } | ||
|
|
||
| @objc public var color: UIColor? { | ||
| get { innerView.color } |
Owner
There was a problem hiding this comment.
这里应该新增一个桥接变量?不应该直接取 innerView.color。innerView.color 一定是会有值的,这样写,外层 platforms/react-native/ios/RaTeXViewManager.mm 里的 color 一定不为 nil。和这里的 color set/get 语义不太一致,这里的 color 应该是指的是 rn 设置的值,可能为 nil。
Owner
|
牛的👍 此外 ratex-render 和 ratex-svg 是不是也可以增加下参数?还有 platforms/web。 |
- 添加颜色验证功能,确保颜色组件在 [0, 1] 范围内且为有限浮点数 - 更新 RaTeX 相关结构以支持新的颜色验证逻辑 - 修改 Dart 和 Swift 代码以适应新的颜色处理机制
- 添加了对命令行参数`--color`的支持,允许用户指定渲染颜色 - 更新了`render_latex`函数以接受颜色参数,并在布局选项中应用该颜色 - 修改了相关的类型定义和函数调用,以确保颜色参数的传递 - 在多个文件中实现了颜色解析和错误处理逻辑
- 在 `ratex-wasm` 中添加 `color` 参数以支持渲染颜色 - 更新示例代码以展示如何使用颜色参数 - 修改文档以反映新的支持属性
Contributor
Author
|
@erweixin 几个修改点都更正了,然后ratex-render、ratex-svg和platforms/web也添加了color参数,尽量保持了二进制兼容,本地测试生成png和svg颜色也没问题 另外,如果可以的话,希望能把我基于项目封装的Compose Multiplatform平台的 RaTeX-CMP 库放到README中供参考 ratex-render:printf 'x + \\color{red}{y}\n' | cargo run -p ratex-render -- --color '#1E88E5'
ratex-svg:printf 'x + \\color{red}{y}\n' | cargo run -p ratex-svg --features 'cli standalone' -- --color '#1E88E5'
ratex-wasm:输入 node --input-type=module <<'EOF'
import init, { renderLatex } from 'file:///artifacts/wasm-pkg/ratex_wasm.js';
import { readFile } from 'node:fs/promises';
const wasmBytes = await readFile('artifacts/wasm-pkg/ratex_wasm_bg.wasm');
await init(wasmBytes);
const json = renderLatex('x + \\color{red}{y}', '#1E88E5');
const displayList = JSON.parse(json);
const colors = [...new Set(displayList.items.filter(item => item.color).map(item => JSON.stringify(item.color)))].map(JSON.parse);
console.log(JSON.stringify({ version: displayList.version, itemCount: displayList.items.length, colors }, null, 2));
EOF输出 |
erweixin
marked this pull request as ready for review
April 21, 2026 16:22
Owner
完全没问题,你加到 PR 里就行。 |
- 在 README.md 和 README.zh-CN.md 中添加 Compose Multiplatform 的支持信息 - 更新演示截图的展示格式,增强可读性
- 将 README.md 和 README.zh-CN.md 中的演示截图从列表格式更新为表格格式 - 提升了文档的可读性和视觉效果
Contributor
Author
|
@erweixin 我加到文档里了,然后把截图的地方换成每行两个的表格形式,这样在电脑上看的比较清楚 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


概要
这个 PR 将
LayoutOptions.color暴露到 FFI 层及各平台绑定层,使调用方可以为公式设置默认颜色,并补充了对应的回归测试。本次 PR 聚焦于一个逻辑改动:为 RaTeX 增加跨平台的默认公式颜色支持。
变更内容
RatexOptions中新增默认颜色字段,使用 RGBA float 传递struct_size判断保留 FFI 的向前 / 二进制兼容性RaTeXFormula单独指定颜色\color{...})仍然优先于默认颜色行为说明
文档
测试
cargo test -p ratex-ffiLIBRARY_PATH=$(pwd)/target/release DYLD_LIBRARY_PATH=$(pwd)/target/release swift test --package-path platforms/ios/tests