mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-29 20:56:47 -06:00
Merge #180: text frame auto-size grows and shrinks frames to fit their text
text-autosize 60551322.
Conflict: crates/doc/src/item.rs: next's reference-point doc and default auto_size_ref 4 (centre, as IDML leaves it) plus the branch's minimum-size and No Line Breaks fields
Conflict: crates/engine/src/lib.rs: autosize pass before next's record_undo_step on the success path; bump_revision for next's global revisions
Conflict: crates/engine/src/cmd/interchange.rs: next's grep_style_warnings and .indd comment plus the branch's autosize::apply on import
Conflict: crates/engine/src/cmd/object.rs: branch's textFrameOptions params doc with next's firstBaseline values
Conflict: ROADMAP.md: progress log both
Conflict: docs/gaps.md: next's optical kerning wording with the branch's auto-size note on #180
This commit is contained in:
@@ -814,6 +814,9 @@ fn file_revert(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
};
|
||||
// As opened again: the fonts beside it now (unchanged files are shared, not read again).
|
||||
let (fonts, _, _) = load_document_fonts(&mut d, &path);
|
||||
if path.to_ascii_lowercase().ends_with(".idml") {
|
||||
crate::autosize::apply(&mut d, None);
|
||||
}
|
||||
let uid = s.doc()?.uid;
|
||||
let recovery_dir = s.recovery_dir.clone();
|
||||
let index = s.active_index().ok_or(EngineError::NoDocument)?;
|
||||
|
||||
@@ -247,6 +247,8 @@ pub(crate) fn open_idml(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
warnings.extend(font_warnings);
|
||||
warnings.extend(super::style::grep_style_warnings(&d));
|
||||
// Auto-size frames fit their text as set here (with the document's fonts loaded).
|
||||
crate::autosize::apply(&mut d, None);
|
||||
// Never save over the .idml or .indd with the native format: the document starts unsaved.
|
||||
let mut st = DocState::new(d, None);
|
||||
st.fonts = fonts;
|
||||
|
||||
@@ -541,7 +541,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Text Frame Options…",
|
||||
["Object"],
|
||||
Some("Cmd+B"),
|
||||
"{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?: ascent|capHeight|leading|xHeight|emboxHeight|fixed, autoSize?, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), columnRuleTint? (0..1), columnRuleOffset? (pt, horizontal), columnRuleTopInset? (pt), columnRuleBottomInset? (pt), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",
|
||||
"{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?: ascent|capHeight|leading|xHeight|emboxHeight|fixed, autoSize?: off|heightOnly|widthOnly|heightAndWidth|heightAndWidthProportionally, autoSizeReference?: topLeft|topCenter|topRight|leftCenter|center|rightCenter|bottomLeft|bottomCenter|bottomRight (the point that stays put), useMinimumHeight?: bool, minimumHeight? (pt), useMinimumWidth?: bool, minimumWidth? (pt), noLineBreaks?: bool, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), columnRuleTint? (0..1), columnRuleOffset? (pt, horizontal), columnRuleTopInset? (pt), columnRuleBottomInset? (pt), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",
|
||||
has_selection,
|
||||
text_frame_options
|
||||
),
|
||||
@@ -2022,6 +2022,17 @@ fn text_frame_options(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let rule_offset = ranged("columnRuleOffset", -1440.0, 1440.0, "a number of points")?;
|
||||
let rule_top = ranged("columnRuleTopInset", -1440.0, 1440.0, "a number of points")?;
|
||||
let rule_bottom = ranged("columnRuleBottomInset", -1440.0, 1440.0, "a number of points")?;
|
||||
let min_height = ranged("minimumHeight", 0.0, crate::autosize::MAX_SIDE, "a number of points")?;
|
||||
let min_width = ranged("minimumWidth", 0.0, crate::autosize::MAX_SIDE, "a number of points")?;
|
||||
let reference = match p.get("autoSizeReference") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => Some(
|
||||
v.as_str()
|
||||
.and_then(|n| crate::autosize::REFERENCES.iter().position(|r| *r == n))
|
||||
.ok_or_else(|| bad(ID, format!("autoSizeReference must be one of {}, not {v}", crate::autosize::REFERENCES.join("|"))))?
|
||||
as u8,
|
||||
),
|
||||
};
|
||||
let rule_color = match p.get("columnRuleColor") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(Value::String(c)) if st.doc.swatch(c).is_some() => Some(c.clone()),
|
||||
@@ -2061,6 +2072,24 @@ fn text_frame_options(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
}
|
||||
}
|
||||
if let Some(v) = reference {
|
||||
o.auto_size_ref = v;
|
||||
}
|
||||
if let Some(v) = p.get("useMinimumHeight").and_then(Value::as_bool) {
|
||||
o.auto_size_use_min_height = v;
|
||||
}
|
||||
if let Some(v) = min_height {
|
||||
o.auto_size_min_height = v;
|
||||
}
|
||||
if let Some(v) = p.get("useMinimumWidth").and_then(Value::as_bool) {
|
||||
o.auto_size_use_min_width = v;
|
||||
}
|
||||
if let Some(v) = min_width {
|
||||
o.auto_size_min_width = v;
|
||||
}
|
||||
if let Some(v) = p.get("noLineBreaks").and_then(Value::as_bool) {
|
||||
o.auto_size_no_line_breaks = v;
|
||||
}
|
||||
if let Some(v) = p.get("ignoreWrap").and_then(Value::as_bool) {
|
||||
o.ignore_wrap = v;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user