Skip to main content

Crate cdrsdk

Crate cdrsdk 

Source
Expand description

§cdrsdk

Rust SDK for CorelDRAW automation, built on the COM IDispatch late-binding interface.

§Features

  • Type-safe wrapper around CorelDRAW’s IVG* COM interfaces
  • Late binding via wincom — no .tlb registration needed
  • ~25 domains: Application / Document / Page / Layer / Shape / Curve / Fill / Outline / Text / Effect / Color / Print / UI / …
  • RAII for COM resources — no manual VariantClear
  • Enums for all cdr* / clr* / Prn* / pdf* / cui* constants

§Requirements

  • Windows only (COM is a Windows technology)
  • Rust ≥ 1.75
  • CorelDRAW 2018+ installed and running

§Quick Start

use cdrsdk::prelude::*;
use windows::Win32::System::Com::{CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // COM must be initialized on this thread
    unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok()? };

    // Bind to a running CorelDRAW instance
    let app = IvgApplication::new("26")
        .expect("CorelDRAW not running or not installed");

    println!("version = {:?}", app.version());

    // Create a document and draw a rectangle
    let doc = app.create_document().expect("create_document");
    let layer = doc.active_layer().expect("active_layer");
    let rect = layer
        .create_rectangle2(50.0, 50.0, 100.0, 80.0, 0.0, 0.0, 0.0, 0.0)
        .expect("create_rectangle2");

    // Fill it with orange
    let color = app.create_rgb_color(255, 128, 0).expect("rgb");
    if let Some(fill) = rect.fill() {
        fill.apply_uniform_fill(&color);
    }

    doc.close_without_saving();

    unsafe { CoUninitialize() };
    Ok(())
}

§cyctron 插件(ffi/ + ts/)

仓库同时提供 cyctron libary 动态库插件:ffi/ 把核心接口导出为 C ABI, ts/ 提供 HTTP 层接口测试。

bash ffi/package.sh                       # 构建并安装到 cyctron/libary
deno run --allow-net --allow-env   --allow-read --allow-write ts/coreldraw_request.ts 44944

详见 ffi/README.md。

§Module Overview

ModulePurpose
appApplication object — entry point
documentDocuments, metadata, data fields
pagePages, spreads, page sizes
layerLayers and shape factories
shapeShapes (rectangle / ellipse / polygon / bitmap / text / …)
curveCurve / sub-path / node / segment
geometryPoint / vector / rect / transform / snap point
colorColor, color context, color profile
fillUniform / fountain / pattern / texture / hatch fills
outlineOutline, line style, arrow heads
textText object, range, frame, characters / words / lines
effectBlend / contour / shadow / extrude / lens / …
styleStyle, style sheet
viewView, active view, window
treeObject manager tree
symbolSymbol, symbol definition, symbol library
structsParameter structures (IVGStruct*)
printPrinters, print job, separations, PDF settings
import_exportImport / export filters
uiUI framework (ICUI*)
miscClipboard, ruler, grid, GMS, …
enumsAll cdr* / clr* / Prn* / pdf* / cui* enums

§Design Notes

§Late Binding

All calls go through IDispatch::Invoke by name. This means:

  • No .tlb file needed
  • Works across CorelDRAW versions without recompilation
  • Slower than direct vtable calls
  • No compile-time check on property/method names

§Threading

COM objects are apartment-bound. All wrapper types are !Send / !Sync. To use from multiple threads, create a separate IvgApplication per thread.

§Error Handling

Most methods return Option<T> or bool. For raw HRESULT, use .raw().

§Known Limitations

  • Methods with multiple out-parameters (e.g. Curve.GetBoundingBox) return only the first value or None, because IDispatch late binding cannot retrieve multiple out-params.
  • Application.ConvertUnits is reimplemented in pure Rust (geometry::units) because the COM version requires an out-param.
  • Some rarely-used property names may be incorrect — please file an issue.

§Version Compatibility

cdrsdkCorelDRAWStatus
0.3.x2018 – 2024 (v20 – v26)Tested on v26 (26.1.0.143)
0.2.x2018 – 2024 (v20 – v26)Superseded
0.1.x2018 – 2024 (v20 – v26)Superseded

§License

  • MIT license (see the LICENSE file)

at your option.

Re-exports§

pub use prelude::*;

Modules§

app
CorelDRAW 应用层对象
color
颜色相关
curve
IVGCurve 一族
document
文档层
effect
效果(Effect)相关
enums
CorelDRAW 枚举类型
fill
填充相关
geometry
几何基础类型
import_export
导入 / 导出过滤器
layer
图层
misc
杂项(不属于其它模块的接口)
outline
轮廓相关
page
页面相关
prelude
常用类型集中导出
print
打印相关
shape
图形相关
structs
COM 结构体(IVGStructXxx 系列)
style
样式(Style / Styles / StyleSheet)
symbol
符号(Symbol)相关
text
文本相关
tree
对象树(Object Manager Tree)
types
CLSID / IID / ProgID / 常量
ui
CorelDRAW UI 框架(ICUI* 系列)
view
视图 / 窗口