Skip to content
Open
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## Unreleased

- An edit changes an xref layer's linetype in its host, as `e.layer("SURVEY|BOUNDARY", { linetype:
"SURVEY|PHANTOM2" })`, to a linetype the host holds. Both writers mark it as the host's override,
so a reload of the xref keeps it.
- An edit's additions may use a text style of the file whose font tsdraft does not hold, such as a
firm's Baskerville Old Face, for a text justified left and a paragraph of one column, which the
leading CAD app lays out itself. What tsdraft would lay out from the font's widths is refused in
such a style: a justified text or attribute, a paragraph in columns, a multileader, a dimension
and a table. A file's style is now matched to the font it names in any spelling, such as
`ROMANS.SHX`, or `cour.ttf` with no family.
- `e.change(handle, { boxHeight: 0 })` fits a multileader's note box to its text. A file can
store a box taller than its note, and the leading CAD app sizes the note's mask by that height,
so the mask can hide what lies below the note. 0 is what the app writes for a new note that does
not wrap. A multileader with no note, an annotative one, a note in columns and an entity of
another kind are refused. The picture draws the mask as tall as the note, so the change shows in
no picture.
- A read multileader's note gives `boxHeight`, the height of its box as the file stores it, when
above 0.

## 0.6.0

tsdraft edits a firm's own drawings, with no CAD program: an edit file erases, moves, stretches,
Expand Down
16 changes: 14 additions & 2 deletions docs/editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ and every format its text does not replace.
`%%` codes or a TrueType text justified Middle, a DXF keeps the start it holds, which a CAD
program works out again when it reads the file, and a DWG, which stores the start a CAD
program draws from, refuses the change.
- `boxHeight: 0` fits a multileader's note box to its text. A file can store a box taller than
its note, and the leading CAD app sizes the note's mask by that height, so the mask can hide what
lies below. 0 is what the app writes for a new note that does not wrap, and the only height set.
The read gives the stored height as the note's `boxHeight`. The picture draws the mask as tall
as the note before and after, so the change shows in no picture and the changed sheets do not
list it. A multileader with no note, an annotative one, which holds a box for each scale, and a
note in columns are refused.
- `attributes` changes an insert's attributes by tag, each as `text` is.
- `layer`, `color` (1 to 255, 0 for ByBlock, 256 for ByLayer), `trueColor` (0xRRGGBB, with the
nearest index beside it), `linetype` (one the file holds, `ByLayer` or `ByBlock`), `lineweight`
Expand All @@ -206,8 +213,8 @@ and every format its text does not replace.
`color`, `trueColor`, `linetype` and `lineweight`. A host changes an xref's layer, `XREF|LAYER`,
in its own record, marked as the host's override so a reload of the xref keeps it, and sets
`$VISRETAIN` to 1, without which a host keeps no change of an xref's layer. A DWG host whose
`VISRETAIN` is 0 holds no record of an xref's layers, and such a change is refused there. A
change of an xref layer's linetype is not made yet.
`VISRETAIN` is 0 holds no record of an xref's layers, and such a change is refused there. An
xref layer's linetype is one the host holds, its own or the xref's, such as `SURVEY|PHANTOM2`.

`e.viewport(handle, changes)` re-aims a viewport: `center` is the point of model space at its
middle, `ratio` its scale in paper units to drawing units, `twist` its view turned in degrees.
Expand Down Expand Up @@ -252,6 +259,11 @@ are named `Standard`. Under a standard, a text role's and a leader style's `styl
firm's style: in an edit of a file that holds it, the addition draws in it, and a new drawing that
draws to a `styleName` of `Standard` is refused. Every addition names its layer.

A style of the file whose font tsdraft does not hold, such as a firm's Baskerville Old Face, takes a
text justified left and a paragraph of one column, which the leading CAD app lays out itself; a
justified text or attribute, a paragraph in columns, a multileader, a dimension and a table in it
are refused, since tsdraft would work out where they go from another font's widths.

An entity takes its own `linetypeScale`, group 48, and a dimension its own `scale`, `DIMSCALE`,
which the writers write as the dimension's override of its style's, the extended data `ACAD`,
`DSTYLE`. A dimension style's `lineExtension`, `DIMDLE`, is how far a tick's dimension line runs
Expand Down
4 changes: 3 additions & 1 deletion docs/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ leader:
does not, in `textStyle`. `attachments` says where a landing meets each side of the note,
`vertical` that its landings meet the note's top or bottom, `frame` that a frame goes around the
note, and `mask` that a mask is behind it: the drawing's background, or the color index `color`,
over the note's box grown by `offsetFactor` times its height less one. A block as its content
over the note's box grown by `offsetFactor` times its height less one. `boxHeight` is the height
of the note's box as the file stores it, when above 0: the leading CAD app sizes the mask by it,
and a box stored taller than the note hides what lies below. A block as its content
has `text` `""`, `textAt` at the block, and `block`: its `name`, `at`, `scale`, `rotation` in
degrees, and `attributes`, the value each of its labels gives, by the tag of the attribute
definition it fills. A label whose definition the read does not hold is left out, and at most
Expand Down
4 changes: 4 additions & 0 deletions src/edit/change-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ENTITY_KEYS: ReadonlySet<string> = new Set([
"text",
"height",
"width",
"boxHeight",
"attributes",
"layer",
"color",
Expand Down Expand Up @@ -89,6 +90,9 @@ export function entityChangesProblem(value: EntityChanges): string | undefined {
if (value.width !== undefined && !(finite(value.width) && value.width >= 0 && value.width < 1e15))
return "width is not 0 or more";

if (value.boxHeight !== undefined && value.boxHeight !== 0)
return "boxHeight is not 0, the one height set: 0 fits a multileader's note box to its text";

if (value.attributes !== undefined) {
if (!isRecord(value.attributes)) return "attributes is not a record of tags";
let n = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/edit/changed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ export function changedEntity(
out = { ...out, width: c.width };
}

if (c.boxHeight !== undefined) {
// A multileader holds a note, a block or neither, and the read gives a note's text.
if (out.kind !== "multileader" || out.block !== undefined || out.text === "")
return {
problem: `a note box is fitted only of a multileader with a note, and this is ${out.kind === "multileader" ? "one with none" : `a ${e.kind}`}`,
};
const { boxHeight: _, ...rest } = out;
out = rest;
}

if (c.attributes !== undefined) {
if (out.kind !== "insert")
return { problem: `attributes are changed only of an insert, and this is a ${e.kind}` };
Expand Down
54 changes: 52 additions & 2 deletions src/edit/dxf-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,58 @@ export function textSplices(
return w.out;
}

/**
* The splice that fits a multileader's note box to its text: its context's own group 44 set to 0,
* as the leading CAD app writes a new note that does not wrap, or why it cannot. The context's own groups are those
* from `CONTEXT_DATA{` to its `}` outside each `LEADER{`; its first 290 says it holds a note, and
* group 293 after it that the multileader is annotative, with a context for each scale. A note in
* columns, the context's group 173, is refused: no case shows how its columns take the box.
*/
export function boxSplices(groups: readonly HeldGroup[]): Splice[] | string {
let where: "before" | "context" | "after" = "before";
let depth = 0;
let note: HeldGroup | undefined;
let box: HeldGroup | undefined;
let columns: HeldGroup | undefined;
let annotative = false;

for (const { g } of own(groups)) {
const mark = g.value.trim();

if (where === "before") {
if (g.code === 300 && mark === "CONTEXT_DATA{") where = "context";
} else if (where === "after") annotative ||= g.code === 293 && Number(g.value) === 1;
else if (g.code === 302 && mark.endsWith("{")) depth++;
else if (depth > 0 && g.code === 303) depth--;
else if (depth === 0 && g.code === 301) where = "after";
else if (depth === 0) {
if (g.code === 290) note ??= g;
else if (g.code === 44) box ??= g;
else if (g.code === 173) columns ??= g;
}
}

if (annotative) return "it is annotative, with a note box for each scale";

if (note === undefined || Number(note.value) !== 1 || box === undefined)
return "the multileader holds no note box";

if (columns !== undefined && Number(columns.value) !== 0)
return "its note is in columns, whose box a fit to the text is not made for";

return Number(box.value) === 0 ? [] : [numberAs(box, 0)];
}

/** The bits a host's AcXRefLayerPropertyOverride sets for each property of an xref's layer. */
const OVERRIDES = { on: 1, frozen: 2, locked: 4, plot: 8, lineweight: 64, color: 0x110 } as const;
const OVERRIDES = {
on: 1,
frozen: 2,
locked: 4,
plot: 8,
linetype: 32,
lineweight: 64,
color: 0x110,
} as const;

/** The splices of a layer's change, or a reason it cannot be made. */
export function layerSplices(
Expand Down Expand Up @@ -372,7 +422,7 @@ export function layerSplices(
// A host marks each property of an xref's layer it overrides, so a reload of the xref keeps it.
let bits = 0;

for (const key of ["on", "frozen", "locked", "plot", "lineweight"] as const)
for (const key of ["on", "frozen", "locked", "plot", "linetype", "lineweight"] as const)
if (c[key] !== undefined) bits |= OVERRIDES[key];

if (c.color !== undefined || c.trueColor !== undefined) bits |= OVERRIDES.color;
Expand Down
20 changes: 17 additions & 3 deletions src/edit/dxf-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { DxfDocument } from "../read/document.ts";
import type { DrawingRead, ReadAttribute, ReadEntity } from "../read/model.ts";
import { changedEntity, changedViewport, layerNamed, linetypeNamed } from "./changed.ts";
import {
boxSplices,
headerSplice,
layerSplices,
penSplices,
Expand Down Expand Up @@ -48,17 +49,21 @@ export interface ChangeEdits {
readonly erased: ReadonlyMap<number, number>;
}

/** The dictionary of a text's fields, which its extension dictionary names `ACAD_FIELD`, or undefined. */
function fieldsOf(r: ChangeRecords, i: number): number | undefined {
/** The record its extension dictionary names `name`, or undefined. */
function extensionOf(r: ChangeRecords, i: number, name: string): number | undefined {
const groups = r.groups(i);
const at = groups.findIndex((g) => g.code === 102 && g.value.trim() === "{ACAD_XDICTIONARY");
const h = at >= 0 ? groups[at + 1]?.value.trim() : undefined;
const x = h === undefined ? undefined : r.byHandle.get(canonicalHandle(h));
const f = x === undefined ? undefined : r.dictionaryEntry(x, "ACAD_FIELD");
const f = x === undefined ? undefined : r.dictionaryEntry(x, name);

return f === undefined ? undefined : r.byHandle.get(canonicalHandle(f));
}

/** The dictionary of a text's fields, which its extension dictionary names `ACAD_FIELD`, or undefined. */
const fieldsOf = (r: ChangeRecords, i: number): number | undefined =>
extensionOf(r, i, "ACAD_FIELD");

/** The changes of a text a change writes, from the entity before and after it. */
function textValues(
before: ReadEntity | ReadAttribute,
Expand Down Expand Up @@ -202,6 +207,15 @@ export function changeSplices(r: ChangeRecords, edit: Edit, read: DrawingRead):
add(i, textSplices(r.groups(i), place, textValues(before, after, c.text, c)), statement, h);
}

if (c.boxHeight !== undefined) {
if (kind !== "MULTILEADER")
throw new EditError(`${h} is a ${kind}, which holds no note box`, statement);

if (extensionOf(r, i, "AcDbContextDataManager") !== undefined)
throw new EditError(`${h} is annotative, with a note box for each scale`, statement);
add(i, boxSplices(r.groups(i)), statement, h);
}

if (c.attributes !== undefined && before.kind === "insert" && after.kind === "insert") {
const list = before.attributes ?? [];

Expand Down
12 changes: 9 additions & 3 deletions src/edit/file-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
TableStyle,
TextStyle,
} from "../drawing.ts";
import { STANDARD_TEXT_STYLE } from "../fonts.ts";
import { nearestFont, STANDARD_TEXT_STYLE } from "../fonts.ts";
import { isString } from "../guards.ts";
import { layerKey } from "../layers.ts";
import type {
Expand Down Expand Up @@ -62,11 +62,17 @@ function linetypeOf(l: ReadLinetype): Linetype {
return { name: l.name, description: l.description ?? "", pattern: [...l.pattern] };
}

/** A text style by the font it names: a TrueType family where it names one, else its file. */
/**
* A text style by the font of `FONTS` it names, by its TrueType family or else its file, in any
* spelling `nearestFont` takes. A font not in `FONTS`, such as a firm's Baskerville Old Face,
* stands in as the nearest one: an edit writes no style of the file's, so the stand-in only
* measures what the additions draw, and `lintEdit` refuses an addition whose layout the writers
* would work out from the stand-in's widths.
*/
function textStyleOf(s: ReadTextStyle): TextStyle {
return {
name: s.name,
font: s.family ?? s.font ?? "txt.shx",
font: nearestFont(s.family ?? s.font ?? "txt.shx").font,
...(s.widthFactor !== undefined && s.widthFactor !== 1 && { widthFactor: s.widthFactor }),
...(s.oblique !== undefined && s.oblique !== 0 && { obliqueAngle: s.oblique }),
};
Expand Down
9 changes: 0 additions & 9 deletions src/edit/lint-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ export function layerChangeProblems(
),
);

if (layer.xref && c.linetype !== undefined)
// The bit a host's AcXRefLayerPropertyOverride sets for a linetype is not known yet.
out.push(
error(
"edit-layer",
`${layer.name} is an xref's layer, whose linetype a host's change is not made of yet`,
),
);

const current = read.header.clayer ?? "0";

if (c.frozen === true && layerKey(layer.name) === layerKey(current))
Expand Down
Loading
Loading