chore(pdf): cut over figcraft-pdf to craft-pdf (#2469)

This commit is contained in:
Dylan M. Taylor authored and GitHub committed 2026-11-18 20:59:55 -05:00
1 parent a80ca002a4
commit b45255bb6f
4 files changed
+23 -1

No files matched your search

Generated
+10
View File
@@ -1258,6 +1258,15 @@ dependencies = [
"serde",
]
[[package]]
name = "craft-pdf"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890"
dependencies = [
"krilla",
"thiserror 2.0.21",
]
[[package]]
name = "craft-penpot"
version = "0.1.0"
@@ -2272,6 +2281,7 @@ dependencies = [
name = "figcraft-pdf"
version = "0.18.1"
dependencies = [
"craft-pdf",
"figcraft-color",
"figcraft-doc",
"figcraft-geom",
+1
View File
@@ -16,6 +16,7 @@ repository = "https://github.com/storytold/figcraft"
craft-xml = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" }
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "010702ee9b030844c852939095b1da0d0656a890", default-features = false, features = ["tree"] }
craft-vectordrawable = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5cd16f2b9ac2a84c4c0794e609914e2bbf848bd7" }
craft-pdf = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "010702ee9b030844c852939095b1da0d0656a890" }
# internal
figcraft-geom = { path = "crates/geom" }
figcraft-color = { path = "crates/color" }
+1
View File
@@ -9,6 +9,7 @@ description = "FigCraft PDF export (krilla): vector shapes, gradients, embedded
workspace = true
[dependencies]
craft-pdf = { workspace = true, features = ["write"] }
figcraft-geom = { workspace = true }
figcraft-color = { workspace = true }
figcraft-doc = { workspace = true }
+11 -1
View File
@@ -78,6 +78,12 @@ pub enum PdfError {
Write(String),
}
impl From<craft_pdf::write::WriteError> for PdfError {
fn from(e: craft_pdf::write::WriteError) -> Self {
Self::Write(e.to_string())
}
}
/// Largest page side, in points (PDF 1.7 has no hard limit; viewers cope with this).
pub const MAX_PAGE_SIDE: f64 = 200_000.0;
@@ -149,7 +155,7 @@ fn link_annotation(r: Rect, url: String, w: f64, h: f64) -> Option<krilla::annot
}
let r = r.intersect(Rect::new(0.0, 0.0, w, h));
let url = url.trim();
if !(r.width() > 0.0 && r.height() > 0.0) || url.is_empty() || url.len() > MAX_URL {
if !(r.width() > 0.0 && r.height() > 0.0) || url.is_empty() || url.len() > MAX_URL || !craft_pdf::safe_url(url) {
return None;
}
let rect = krilla::geom::Rect::from_ltrb(r.x0 as f32, r.y0 as f32, r.x1 as f32, r.y1 as f32)?;
@@ -162,6 +168,10 @@ fn rect_finite(r: Rect) -> bool {
}
fn write(doc: &Document, pages: &[(Vec<NodeId>, Rect)], opts: &PdfOptions) -> Result<Vec<u8>, PdfError> {
craft_pdf::write::guard(|| write_inner(doc, pages, opts))
}
fn write_inner(doc: &Document, pages: &[(Vec<NodeId>, Rect)], opts: &PdfOptions) -> Result<Vec<u8>, PdfError> {
let mut pdf = krilla::Document::new();
let mut meta = krilla::metadata::Metadata::new().creator("FigCraft".into()).producer("FigCraft".into());
if let Some(t) = opts.title.as_ref().filter(|t| !t.trim().is_empty()) {