mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-14 14:22:39 +00:00
Delegate IDML style name codec to craft-idml
This commit is contained in:
1 file changed
+5
-28
@@ -120,10 +120,10 @@ pub fn liquid_rule_in(s: &str) -> designcraft_doc::LiquidRule {
|
||||
}
|
||||
|
||||
pub fn escape_id(s: &str) -> String {
|
||||
s.replace('%', "%25").replace(':', "%3a")
|
||||
craft_idml::value::escape_id(s)
|
||||
}
|
||||
pub fn unescape_id(s: &str) -> String {
|
||||
s.replace("%3a", ":").replace("%3A", ":").replace("%25", "%")
|
||||
craft_idml::value::unescape_id(s)
|
||||
}
|
||||
|
||||
/// An `AppliedFont` value → font family. InDesign can write the family with its `$ID/` prefix
|
||||
@@ -147,38 +147,15 @@ pub const OBJECT_BUILTINS: &[(&str, &str)] =
|
||||
/// Our style name → IDML `Name` (groups: `A/B` → `A:B`; a literal `:` or `\` is escaped as `\:`
|
||||
/// or `\\`, so it is not read back as a group separator).
|
||||
pub fn style_name_out(builtins: &[(&str, &str)], name: &str) -> String {
|
||||
builtins
|
||||
.iter()
|
||||
.find(|(o, _)| *o == name)
|
||||
.map(|(_, i)| i.to_string())
|
||||
.unwrap_or_else(|| name.replace('\\', "\\\\").replace(':', "\\:").replace('/', ":"))
|
||||
craft_idml::value::style_name_out(builtins, name)
|
||||
}
|
||||
/// IDML `Name` → our style name.
|
||||
pub fn style_name_in(builtins: &[(&str, &str)], name: &str) -> String {
|
||||
if let Some((o, _)) = builtins.iter().find(|(_, i)| *i == name) {
|
||||
return o.to_string();
|
||||
}
|
||||
let name = name.strip_prefix("$ID/").unwrap_or(name);
|
||||
let mut out = String::with_capacity(name.len());
|
||||
let mut chars = name.chars();
|
||||
while let Some(c) = chars.next() {
|
||||
match c {
|
||||
'\\' => match chars.clone().next() {
|
||||
Some(next @ ('\\' | ':')) => {
|
||||
out.push(next);
|
||||
chars.next();
|
||||
}
|
||||
_ => out.push('\\'),
|
||||
},
|
||||
':' => out.push('/'),
|
||||
_ => out.push(c),
|
||||
}
|
||||
}
|
||||
out
|
||||
craft_idml::value::style_name_in(builtins, name)
|
||||
}
|
||||
/// `ParagraphStyle/…` Self id for one of our names.
|
||||
pub fn style_self(kind: &str, builtins: &[(&str, &str)], name: &str) -> String {
|
||||
format!("{kind}/{}", escape_id(&style_name_out(builtins, name)))
|
||||
craft_idml::value::style_self(kind, builtins, name)
|
||||
}
|
||||
|
||||
pub fn align_out(a: Align) -> &'static str {
|
||||
|
||||
Reference in new issue
Block a user