Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,35 @@ jobs:
cp "$stage/draftcraft-cli.exe" "$dir/draftcraft-cli.exe"
(cd dist/zip && 7z a -tzip "../upload/draftcraft-windows-${{ matrix.arch }}.zip" DraftCraft > /dev/null)
ls -l dist/upload
- name: Update over DraftCraft 2.2.2
# 2.2.2 and earlier used the upgrade code DraftCraft shared with CADCraft (#35). The new
# setup must replace such a copy (as Update Now runs it), leaving one DraftCraft, not two.
if: matrix.arch == 'x64'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$old = Join-Path $env:RUNNER_TEMP 'draftcraft-2.2.2-setup.exe'
Invoke-WebRequest 'https://github.com/DraftCraft-DEV/DraftCraft/releases/download/v2.2.2/draftcraft-windows-x64-setup.exe' -OutFile $old
$p = Start-Process $old -ArgumentList @('/quiet') -Wait -PassThru
if ($p.ExitCode -ne 0) { throw "installing 2.2.2 failed: $($p.ExitCode)" }
$installer = New-Object -ComObject WindowsInstaller.Installer
$legacy = '{119D7D76-0167-4A9E-8F37-09DA0235F68E}'
$current = '{' + (Get-Content packaging/windows/install-policy.json -Raw | ConvertFrom-Json).upgradeCode + '}'
if (@($installer.RelatedProducts($legacy)).Count -ne 1) { throw '2.2.2 did not install' }
$setup = (Resolve-Path 'dist/upload/draftcraft-windows-x64-setup.exe').Path
$log = Join-Path $env:RUNNER_TEMP 'upgrade.log'
$p = Start-Process $setup -ArgumentList @('/quiet', '--scope', 'user', '/log', "`"$log`"") -Wait -PassThru
if ($p.ExitCode -ne 0) { if (Test-Path $log) { Get-Content $log -Tail 80 }; throw "update failed: $($p.ExitCode)" }
$left = @($installer.RelatedProducts($legacy)).Count
$now = @($installer.RelatedProducts($current)).Count
if ($left -ne 0) { Get-Content $log -Tail 80; throw "the update left DraftCraft 2.2.2 installed beside the new one" }
if ($now -ne 1) { throw "expected one new DraftCraft, found $now" }
$exe = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\draftcraft.exe').'(default)'
if (-not (Test-Path $exe)) { throw "App Paths names a missing exe after the update: $exe" }
$msi = (Resolve-Path 'dist/release/draftcraft-*-windows-x64.msi').Path
$p = Start-Process msiexec.exe -ArgumentList @('/x', "`"$msi`"", '/qn') -Wait -PassThru
if ($p.ExitCode -ne 0) { throw "uninstall failed: $($p.ExitCode)" }
Write-Output 'the new setup replaced DraftCraft 2.2.2 and left one copy'
- name: Install, check and uninstall the installer
# A real install on this throwaway runner, for this account (no administrator), as a
# double-click with the default choice does, through the setup .exe people download.
Expand Down
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ contributors, and where a line says so by Skryx Dev:
| `crates/ui-egui/src/i18n/cs.tsv` | @Losminek (AI-assisted) | Original Czech translations of the English interface strings | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied |
| `crates/ui-egui/src/i18n/ru.tsv` | @pechnikov2026-star | Original Russian translations of the English interface strings | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied |
| `crates/ui-egui/src/i18n/fr.tsv` | @pechnikov2026-star | Original French translations of the English interface strings | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied |
| `crates/ui-egui/src/i18n/zh_tw.tsv` | Skryx Dev with Claude Code (AI-assisted), from `zh.tsv` | Original Traditional Chinese (Taiwan) translations of the English interface strings: the Simplified Chinese catalog in Traditional characters with Taiwan terminology | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied; not yet reviewed by a native speaker |
| `crates/ui-egui/src/i18n/zh.tsv` | @mayloglog; DraftCraft ribbon strings: Skryx Dev | Original Simplified Chinese translations of the English interface strings | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied |
| `crates/ui-egui/src/i18n/sv.tsv` | Erik Holmbom (@holmbom) with Claude Code (AI-assisted) | Original Swedish translations of the English interface strings | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied; terminology and the running app reviewed by a native speaker |
| `crates/ui-egui/src/i18n/it.tsv` | Emanuele Bottelli (AI-assisted); terminology corrections: Andrea Brandi (@starise) with OpenAI Codex (AI-assisted); DraftCraft ribbon strings: Skryx Dev | Original Italian translations of the English interface strings | MIT OR Apache-2.0 (`LICENSE-MIT`, `LICENSE-APACHE`) | No proprietary localization resources copied; targeted Chamfer terminology review by a native speaker |
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ How to write it (see AGENTS.md):

## Unreleased

### New
- The interface is available in Traditional Chinese (繁體中文), with the terms used in Taiwan: choose it in Edit › Interface Language, or let DraftCraft pick it on a computer set to Taiwan, Hong Kong or Macau.
- The Start page can begin a new drawing in centimeters, beside millimeters and inches; text, dimensions, linetypes and hatches are sized so the drawing prints as a millimeter one does. Options › Units of new drawings offers centimeters too, and a later New remembers the choice.

### Fixed
- DraftCraft and CADCraft can be installed side by side on Windows: installing one no longer removes the other or fails with an error. Updating DraftCraft still replaces an earlier DraftCraft.

## 2.2.2

### New
Expand Down
14 changes: 14 additions & 0 deletions crates/doc/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,18 @@ impl Header {
h.set("LIMMAX", HVal::Point(Vec3::new(420.0, 297.0, 0.0)));
h
}

/// The metric header in centimetres (INSUNITS 5): the same A3 limits and printed sizes as the
/// millimetre one, so text, linetypes, hatches and dimensions (DIMSCALE) are a tenth as large
/// in drawing units.
pub fn centimetres() -> Header {
let mut h = Header::metric();
h.set_i64("INSUNITS", 5);
h.set_f64("TEXTSIZE", 0.25);
h.set_f64("LTSCALE", 0.1);
h.set_f64("HPSCALE", 0.1);
h.set_f64("DIMSCALE", 0.1);
h.set("LIMMAX", HVal::Point(Vec3::new(42.0, 29.7, 0.0)));
h
}
}
22 changes: 22 additions & 0 deletions crates/doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,28 @@ impl Drawing {
d.header.set_str("DIMSTYLE", "ISO-25");
d
}
/// An empty metric drawing in centimetres (#34): the millimetre drawing with its default
/// sizes a tenth as large in drawing units (ISO-25 at DIMSCALE 0.1, multileaders, tables), so
/// annotation prints at the same size.
pub fn new_centimetres() -> Self {
let mut d = Drawing::new_metric();
d.header = Header::centimetres();
d.header.set_str("DIMSTYLE", "ISO-25");
for style in d.dim_styles.iter_mut().filter(|s| s.name == "ISO-25") {
style.scale = 0.1;
}
for style in &mut d.mleader_styles {
style.arrow_size /= 10.0;
style.text_height /= 10.0;
style.landing_gap /= 10.0;
style.dogleg /= 10.0;
}
for style in &mut d.table_styles {
style.text_height /= 10.0;
style.margin /= 10.0;
}
d
}
fn bare() -> Self {
Drawing {
header: Header::default(),
Expand Down
19 changes: 19 additions & 0 deletions crates/doc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,22 @@ fn space_names_its_tab() {
assert_eq!(p.layout(), Some("Sheet A"));
assert_eq!(p.tab_name(), "Sheet A");
}

/// #34: a centimetre drawing prints like the millimetre one, every default size a tenth as large.
#[test]
fn new_centimetre_drawing_is_the_metric_one_a_tenth_as_large() {
let (mm, cm) = (Drawing::new_metric(), Drawing::new_centimetres());
assert_eq!((cm.header.i64("INSUNITS", 0), cm.header.i64("MEASUREMENT", 0)), (5, 1));
assert_eq!(cm.header.str("DIMSTYLE", ""), "ISO-25");
for (name, k) in [("TEXTSIZE", 0.1), ("LTSCALE", 0.1), ("HPSCALE", 0.1), ("DIMSCALE", 0.1)] {
assert!((cm.header.f64(name, 1.0) - mm.header.f64(name, 1.0) * k).abs() < 1e-12, "{name}");
}
let iso = |d: &Drawing| d.dim_style("ISO-25").map(|s| s.text_height * s.effective_scale(1.0)).unwrap();
assert!((iso(&cm) - iso(&mm) / 10.0).abs() < 1e-12);
let (ml, ml_mm) = (&cm.mleader_styles[0], &mm.mleader_styles[0]);
assert!((ml.text_height - ml_mm.text_height / 10.0).abs() < 1e-12 && (ml.dogleg - ml_mm.dogleg / 10.0).abs() < 1e-12);
assert!((cm.table_styles[0].text_height - mm.table_styles[0].text_height / 10.0).abs() < 1e-12);
// The Standard dimension style and the tables are as in any new drawing.
assert_eq!(cm.dim_style("Standard"), mm.dim_style("Standard"));
assert_eq!(cm.layers, mm.layers);
}
25 changes: 22 additions & 3 deletions crates/engine/src/cmd/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ pub fn specs() -> Vec<CommandSpec> {
.menu(&["File", "New Drawing..."])
.key("Cmd+N")
.alias(&["qnew"])
.params("{metric?: bool (default MEASUREINIT), template?: path to a .dwt/.dxf template (\".\" for none; default QNEWTEMPLATE)}")
.params(
"{units?: in|mm|cm, metric?: bool (default MEASUREINIT; metric is MEASUREINITUNITS, mm or cm), template?: path to a .dwt/.dxf template (\".\" for none; default QNEWTEMPLATE)}",
)
.enabled(always)
.noundo(),
CommandSpec::new("open", "Open...", run_open)
Expand Down Expand Up @@ -297,11 +299,28 @@ fn run_new(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(r) = template::run_new(s, p)? {
return Ok(r);
}
let metric = s.settings.measureinit;
let i = s.new_drawing(bool_or(p, "metric", metric));
let insunits = match p.get("units") {
Some(v) => new_units(v).ok_or_else(|| bad("new", "`units` must be in, mm or cm"))?,
None if bool_or(p, "metric", s.settings.measureinit) => i64::from(s.settings.measureinit_units),
None => 1,
};
let i = s.new_drawing_in(insunits);
Ok(json!({ "index": i, "title": s.docs.get(i).map(|d| d.title.clone()) }))
}

/// NEW's `units`: inches, millimetres or centimetres, by name or INSUNITS code (1, 4, 5).
fn new_units(v: &Value) -> Option<i64> {
if let Some(code) = v.as_i64() {
return [1, 4, 5].contains(&code).then_some(code);
}
match v.as_str()?.trim().to_ascii_lowercase().as_str() {
"in" | "inch" | "inches" => Some(1),
"mm" | "millimeter" | "millimeters" | "millimetre" | "millimetres" => Some(4),
"cm" | "centimeter" | "centimeters" | "centimetre" | "centimetres" => Some(5),
_ => None,
}
}

fn file_name(path: &str) -> String {
std::path::Path::new(path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| path.to_string())
}
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub const PROFILE_VARS: &[&str] = &[
"PICKDRAG",
"MAXARRAY",
"MEASUREINIT",
"MEASUREINITUNITS",
];

/// The most profile entries [`restore`] reads (a saved profile is untrusted input).
Expand Down
14 changes: 12 additions & 2 deletions crates/engine/src/session/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ use super::{DocState, Drawing, EngineError, Result, Session, Space, Value, Vec2,
impl Session {
/// Append a new untitled drawing (`DrawingN`, metric or imperial default view), end a running command, make it active, bump the document epoch and return its index.
pub fn new_drawing(&mut self, metric: bool) -> usize {
self.new_drawing_in(if metric { 4 } else { 1 })
}

/// [`Session::new_drawing`] in the units of an INSUNITS code: 1 inches, 5 centimetres, any
/// other millimetres. A metric drawing opens on its A3 limits.
pub fn new_drawing_in(&mut self, insunits: i64) -> usize {
self.untitled_counter += 1;
let d = if metric { Drawing::new_metric() } else { Drawing::new_imperial() };
let (d, a3) = match insunits {
1 => (Drawing::new_imperial(), None),
5 => (Drawing::new_centimetres(), Some(0.1)),
_ => (Drawing::new_metric(), Some(1.0)),
};
let mut st = DocState::new(d, &format!("Drawing{}", self.untitled_counter), None);
st.set_view_quiet(if metric { View { center: Vec2::new(210.0, 148.5), height: 297.0, twist: 0.0 } } else { View::default() });
st.set_view_quiet(a3.map_or_else(View::default, |k| View { center: Vec2::new(210.0 * k, 148.5 * k), height: 297.0 * k, twist: 0.0 }));
self.end_running();
self.docs.push(st);
self.active = self.docs.len() - 1;
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub struct Settings {
/// MEASUREINIT: the units of a new drawing made without a template (NEW, QNEW and the first
/// drawing at startup): `false` (0, the default) imperial, `true` (1) metric.
pub measureinit: bool,
/// MEASUREINITUNITS (DraftCraft's): the INSUNITS of such a drawing when it is metric, 4
/// millimetres (the default) or 5 centimetres (#34).
pub measureinit_units: u8,
/// -VIEW sEttings > Layer snapshot: named views save the layer settings with them.
pub view_layer_snapshot: bool,
pub dynmode: bool,
Expand Down Expand Up @@ -147,6 +150,7 @@ impl Default for Settings {
gridmajor: 5,
zoomfactor: 60,
measureinit: false,
measureinit_units: 4,
view_layer_snapshot: true,
dynmode: true,
dyndigrip: 31,
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/src/sysvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const SESSION_VARS: &[&str] = &[
"MAXARRAY",
"ZOOMFACTOR",
"MEASUREINIT",
"MEASUREINITUNITS",
"LASTPOINT",
"AREA",
"PERIMETER",
Expand Down Expand Up @@ -149,6 +150,7 @@ pub fn get(s: &Session, name: &str) -> Option<Value> {
"MAXARRAY" => json!(st.maxarray),
"ZOOMFACTOR" => json!(st.zoomfactor),
"MEASUREINIT" => json!(i32::from(st.measureinit)),
"MEASUREINITUNITS" => json!(st.measureinit_units),
"LASTPOINT" => json!([s.last_point.x, s.last_point.y, 0.0]),
"AREA" => json!(s.area),
"PERIMETER" => json!(s.perimeter),
Expand Down Expand Up @@ -379,6 +381,7 @@ pub fn set(s: &mut Session, name: &str, v: &Value) -> Result<()> {
"MAXARRAY" => st.maxarray = as_f64(v).ok_or_else(bad)?.clamp(100.0, 10_000_000.0) as u64,
"ZOOMFACTOR" => st.zoomfactor = as_i(v).filter(|z| (3..=100).contains(z)).ok_or_else(bad)? as u32,
"MEASUREINIT" => st.measureinit = small(v, 1).ok_or_else(bad)? == 1,
"MEASUREINITUNITS" => st.measureinit_units = small(v, 5).filter(|u| matches!(u, 4 | 5)).ok_or_else(bad)?,
"FONTALT" => draftcraft_fonts::ttf::set_font_alt(v.as_str().ok_or_else(bad)?),
"FONTFALLBACK" => draftcraft_fonts::ttf::set_fallback_fonts(v.as_str().ok_or_else(bad)?),
"SAVETIME" => crate::autosave::set_savetime(
Expand Down
50 changes: 50 additions & 0 deletions crates/engine/tests/measureinit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,53 @@ fn kept_in_the_profile() {
draftcraft_engine::cmd::options::restore(&mut restarted, &saved);
assert_eq!(var(&mut restarted, "MEASUREINIT"), json!(1));
}

/// #34: a new drawing in centimetres, chosen by NEW's `units` or remembered by MEASUREINITUNITS.
#[test]
fn centimetres_by_units_or_measureinitunits() {
let mut s = Session::empty();
s.execute("new", &json!({ "units": "cm" })).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(5));
assert_eq!(var(&mut s, "MEASUREMENT"), json!(1));
assert_eq!(var(&mut s, "DIMSTYLE"), json!("ISO-25"));
// The millimetre drawing's printed sizes, a tenth as large in centimetres.
let d = s.doc().unwrap();
assert_eq!(d.header.f64("TEXTSIZE", 0.0), 0.25);
assert_eq!(d.header.f64("LTSCALE", 0.0), 0.1);
assert_eq!(d.dim_style("ISO-25").unwrap().effective_scale(1.0), 0.1);
assert!((s.docs[s.active].view().height - 29.7).abs() < 1e-9);
// Inches and millimetres by name or INSUNITS code; `units` wins over `metric`.
for (units, code) in [(json!("in"), 1), (json!("Millimeters"), 4), (json!(5), 5), (json!(" CM "), 5)] {
s.execute("new", &json!({ "units": units, "metric": code == 1 })).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(code), "{units}");
}
// Remembered for a plain New, and for `metric`, once metric drawings are in centimetres.
assert_eq!(var(&mut s, "MEASUREINITUNITS"), json!(4));
s.execute("options", &json!({ "MEASUREINIT": 1, "MEASUREINITUNITS": 5 })).unwrap();
s.execute("new", &json!({})).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(5));
s.execute("new", &json!({ "metric": true })).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(5));
s.execute("new", &json!({ "metric": false })).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(1));
let saved = draftcraft_engine::cmd::options::profile(&s);
assert_eq!(saved["MEASUREINITUNITS"], json!(5));
let mut restarted = Session::empty();
draftcraft_engine::cmd::options::restore(&mut restarted, &saved);
restarted.execute("new", &json!({})).unwrap();
assert_eq!(var(&mut restarted, "INSUNITS"), json!(5));
}

#[test]
fn units_that_are_not_inches_millimetres_or_centimetres_are_refused() {
let mut s = Session::empty();
for bad in [json!("m"), json!(2), json!(-1), json!(""), json!(true), json!(i64::MAX), json!(1.5)] {
let before = s.docs.len();
assert!(s.execute("new", &json!({ "units": bad })).is_err(), "{bad}");
assert_eq!(s.docs.len(), before, "no drawing for {bad}");
}
for bad in [json!(1), json!(6), json!(0), json!("cm"), json!(-4), json!(f64::NAN.to_string())] {
assert!(s.execute("options", &json!({ "MEASUREINITUNITS": bad })).is_err(), "{bad}");
}
assert_eq!(var(&mut s, "MEASUREINITUNITS"), json!(4));
}
Loading
Loading