layoutbridge-spm 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +171 -0
- package/LICENSE +26 -0
- package/README.de.md +318 -0
- package/README.md +304 -4
- package/THIRD-PARTY-NOTICES.md +2878 -0
- package/dist/src/mcp/config.js +125 -0
- package/dist/src/mcp/dispatch.js +123 -0
- package/dist/src/mcp/license/free-tools.js +16 -0
- package/dist/src/mcp/license/gate.js +209 -0
- package/dist/src/mcp/license/index.js +96 -0
- package/dist/src/mcp/license/instance-name.js +56 -0
- package/dist/src/mcp/license/key-source.js +58 -0
- package/dist/src/mcp/license/lemonsqueezy-verifier.js +207 -0
- package/dist/src/mcp/license/placeholder-verifier.js +10 -0
- package/dist/src/mcp/license/polar-ids.js +63 -0
- package/dist/src/mcp/license/polar-verifier.js +265 -0
- package/dist/src/mcp/license/product-ids.js +72 -0
- package/dist/src/mcp/license/state-store.js +91 -0
- package/dist/src/mcp/license/types.js +11 -0
- package/dist/src/mcp/logging.js +270 -0
- package/dist/src/mcp/product-info.js +48 -0
- package/dist/src/mcp/server.js +250 -0
- package/dist/src/mcp/setup.js +608 -0
- package/dist/src/mcp/start.cjs +95 -0
- package/dist/src/mcp/tool-definition.js +2 -0
- package/dist/src/mcp/tools.js +2004 -0
- package/dist/src/mcp/typography-rules.js +70 -0
- package/dist/src/transport/com.js +250 -0
- package/dist/src/transport/osascript.js +171 -0
- package/dist/src/transport/queue.js +19 -0
- package/dist/src/transport/script-bundle.js +92 -0
- package/dist/src/transport/transport.js +30 -0
- package/indesign/commands/10-app.js +6 -0
- package/indesign/commands/20-documents.js +513 -0
- package/indesign/commands/22-document-setup.js +118 -0
- package/indesign/commands/23-save-package.js +255 -0
- package/indesign/commands/25-export.js +379 -0
- package/indesign/commands/26-export-image.js +197 -0
- package/indesign/commands/27-textdefaults.js +151 -0
- package/indesign/commands/28-selection.js +174 -0
- package/indesign/commands/30-pages.js +1032 -0
- package/indesign/commands/31-view.js +210 -0
- package/indesign/commands/32-sections.js +203 -0
- package/indesign/commands/35-parents.js +428 -0
- package/indesign/commands/37-layout.js +760 -0
- package/indesign/commands/40-frames.js +836 -0
- package/indesign/commands/41-shapes.js +505 -0
- package/indesign/commands/42-groups.js +117 -0
- package/indesign/commands/43-layers.js +291 -0
- package/indesign/commands/44-effects.js +274 -0
- package/indesign/commands/45-frame-options.js +247 -0
- package/indesign/commands/47-anchored.js +287 -0
- package/indesign/commands/50-modify.js +781 -0
- package/indesign/commands/52-align.js +139 -0
- package/indesign/commands/55-fit.js +106 -0
- package/indesign/commands/60-images.js +771 -0
- package/indesign/commands/62-embed.js +120 -0
- package/indesign/commands/69-placeholders.js +127 -0
- package/indesign/commands/70-text.js +567 -0
- package/indesign/commands/71-outlines.js +92 -0
- package/indesign/commands/72-place-text.js +366 -0
- package/indesign/commands/74-stories.js +116 -0
- package/indesign/commands/75-tables.js +676 -0
- package/indesign/commands/76-text-variables.js +260 -0
- package/indesign/commands/77-story-options.js +86 -0
- package/indesign/commands/78-frame-lines.js +304 -0
- package/indesign/commands/79-check-typography.js +303 -0
- package/indesign/commands/80-styles.js +1620 -0
- package/indesign/commands/81-composition.js +355 -0
- package/indesign/commands/82-object-styles.js +263 -0
- package/indesign/commands/83-indents-tabs.js +237 -0
- package/indesign/commands/84-import-styles.js +142 -0
- package/indesign/commands/85-swatches.js +112 -0
- package/indesign/commands/86-gradients.js +185 -0
- package/indesign/commands/87-replace-swatch.js +180 -0
- package/indesign/commands/88-replace-font.js +217 -0
- package/indesign/interpreter.js +758 -0
- package/package.json +55 -6
- package/rules/typography-rules.json +31 -0
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
/* Bereich C – Satzspiegel, Raster, Hilfslinien. */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Stege am linken und rechten Seitenrand.
|
|
5
|
+
*
|
|
6
|
+
* InDesigns Skriptschnittstelle kennt nur marginPreferences.left/right. Bei
|
|
7
|
+
* Doppelseiten bedeutet left "innen" (Bundsteg) und right "aussen"; auf einer
|
|
8
|
+
* linken Seite liegt der Bundsteg also rechts. Das ist die einzige Stelle,
|
|
9
|
+
* an der diese Zuordnung (E-20) steht – Adobes Scripting-Guide rechnet den
|
|
10
|
+
* Satzspiegel linker Seiten genauso (x1 = right, x2 = Breite - left).
|
|
11
|
+
*/
|
|
12
|
+
function idcEdgeMargins(page, facing) {
|
|
13
|
+
var prefs = page.marginPreferences;
|
|
14
|
+
var left = Number(prefs.left);
|
|
15
|
+
var right = Number(prefs.right);
|
|
16
|
+
if (facing && IDC.pageSide(page) === 'LEFT_HAND') {
|
|
17
|
+
return { left_edge: right, right_edge: left };
|
|
18
|
+
}
|
|
19
|
+
return { left_edge: left, right_edge: right };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function idcFacing(doc) {
|
|
23
|
+
try { return doc.documentPreferences.facingPages === true; } catch (e) { return false; }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Position der Seite in ihrem Bogen und ihr Versatz vom Bogenanfang in mm. */
|
|
27
|
+
function idcSpreadPlacement(page) {
|
|
28
|
+
var spread = null;
|
|
29
|
+
var i, other, offset = 0, position = 0, count = 0;
|
|
30
|
+
try { spread = page.parent; } catch (e) { spread = null; }
|
|
31
|
+
if (spread === null) { return { spread_index: null, spread_page_count: 1, spread_position: 0, page_offset_in_spread_mm: 0 }; }
|
|
32
|
+
count = spread.pages.length;
|
|
33
|
+
for (i = 0; i < count; i++) {
|
|
34
|
+
other = spread.pages.item(i);
|
|
35
|
+
if (Number(other.id) === Number(page.id)) { position = i; break; }
|
|
36
|
+
offset += IDC.pageSize(other).width;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
spread_index: IDC.spreadIndex(spread),
|
|
40
|
+
spread_page_count: count,
|
|
41
|
+
spread_position: position,
|
|
42
|
+
page_offset_in_spread_mm: IDC.round(offset)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* Gleichmaessige Spaltenpositionen relativ zum linken Satzspiegelrand. */
|
|
47
|
+
function idcEvenColumnPositions(typeWidth, count, gutter) {
|
|
48
|
+
var positions = [];
|
|
49
|
+
var columnWidth = (typeWidth - (count - 1) * gutter) / count;
|
|
50
|
+
var i, x = 0;
|
|
51
|
+
for (i = 0; i < count; i++) {
|
|
52
|
+
positions.push(IDC.round(x));
|
|
53
|
+
positions.push(IDC.round(x + columnWidth));
|
|
54
|
+
x += columnWidth + gutter;
|
|
55
|
+
}
|
|
56
|
+
return { positions: positions, column_width: IDC.round(columnWidth) };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function idcReadColumnPositions(page) {
|
|
60
|
+
var raw, out = [], i;
|
|
61
|
+
try { raw = page.marginPreferences.columnsPositions; } catch (e) { return null; }
|
|
62
|
+
if (!raw || raw.length === undefined || raw.length === 0) { return null; }
|
|
63
|
+
for (i = 0; i < raw.length; i++) { out.push(IDC.round(Number(raw[i]))); }
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function idcPositionsMatch(actual, expected) {
|
|
68
|
+
var i;
|
|
69
|
+
if (actual === null || actual.length !== expected.length) { return false; }
|
|
70
|
+
for (i = 0; i < actual.length; i++) {
|
|
71
|
+
if (Math.abs(actual[i] - expected[i]) > 0.01) { return false; }
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Satzspiegel einer Seite als Ergebniszeile. */
|
|
77
|
+
function idcDescribeGrid(page, isParent, facing) {
|
|
78
|
+
var prefs = page.marginPreferences;
|
|
79
|
+
var size = IDC.pageSize(page);
|
|
80
|
+
var edges = idcEdgeMargins(page, facing);
|
|
81
|
+
var top = Number(prefs.top);
|
|
82
|
+
var bottom = Number(prefs.bottom);
|
|
83
|
+
var count = Number(prefs.columnCount);
|
|
84
|
+
var gutter = Number(prefs.columnGutter);
|
|
85
|
+
var typeWidth = size.width - edges.left_edge - edges.right_edge;
|
|
86
|
+
var typeHeight = size.height - top - bottom;
|
|
87
|
+
var even = idcEvenColumnPositions(typeWidth, count > 0 ? count : 1, gutter);
|
|
88
|
+
var actual = idcReadColumnPositions(page);
|
|
89
|
+
var placement = idcSpreadPlacement(page);
|
|
90
|
+
var margins = {
|
|
91
|
+
top: IDC.round(top),
|
|
92
|
+
bottom: IDC.round(bottom),
|
|
93
|
+
left: IDC.round(Number(prefs.left)),
|
|
94
|
+
right: IDC.round(Number(prefs.right))
|
|
95
|
+
};
|
|
96
|
+
if (facing) {
|
|
97
|
+
margins.inside = margins.left;
|
|
98
|
+
margins.outside = margins.right;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
page_id: Number(page.id),
|
|
102
|
+
name: String(page.name),
|
|
103
|
+
is_parent_page: isParent,
|
|
104
|
+
side: IDC.pageSide(page),
|
|
105
|
+
spread_index: placement.spread_index,
|
|
106
|
+
spread_page_count: placement.spread_page_count,
|
|
107
|
+
spread_position: placement.spread_position,
|
|
108
|
+
page_offset_in_spread_mm: placement.page_offset_in_spread_mm,
|
|
109
|
+
parent: idcAppliedParentName(page),
|
|
110
|
+
page_size_mm: { width: size.width, height: size.height },
|
|
111
|
+
margins_mm: margins,
|
|
112
|
+
column_count: count,
|
|
113
|
+
column_gutter_mm: IDC.round(gutter),
|
|
114
|
+
type_area_mm: {
|
|
115
|
+
x: IDC.round(edges.left_edge),
|
|
116
|
+
y: IDC.round(top),
|
|
117
|
+
width: IDC.round(typeWidth),
|
|
118
|
+
height: IDC.round(typeHeight)
|
|
119
|
+
},
|
|
120
|
+
column_width_mm: even.column_width,
|
|
121
|
+
columns_positions_mm: actual === null ? even.positions : actual,
|
|
122
|
+
custom_column_positions: actual !== null && !idcPositionsMatch(actual, even.positions)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Alle Seiten (Dokument, dann Musterseiten) als [{page, is_parent}]. */
|
|
127
|
+
function idcAllPages(doc, includeParents) {
|
|
128
|
+
var out = [];
|
|
129
|
+
var i, j, spread;
|
|
130
|
+
for (i = 0; i < doc.pages.length; i++) {
|
|
131
|
+
out.push({ page: doc.pages.item(i), is_parent: false });
|
|
132
|
+
}
|
|
133
|
+
if (includeParents) {
|
|
134
|
+
for (i = 0; i < doc.masterSpreads.length; i++) {
|
|
135
|
+
spread = doc.masterSpreads.item(i);
|
|
136
|
+
for (j = 0; j < spread.pages.length; j++) {
|
|
137
|
+
out.push({ page: spread.pages.item(j), is_parent: true });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function idcGridKey(entry) {
|
|
145
|
+
return [entry.margins_mm.top, entry.margins_mm.bottom, entry.margins_mm.left, entry.margins_mm.right,
|
|
146
|
+
entry.column_count, entry.column_gutter_mm].join('|');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Grundlinienraster dokumentweit. */
|
|
150
|
+
function idcReadBaselineGrid(doc, ctx) {
|
|
151
|
+
var grid = doc.gridPreferences;
|
|
152
|
+
var startMm = null, incMm = null, incPt = null, rawRel = null, relative = 'unknown', shown = null, threshold = null;
|
|
153
|
+
var rawStart = null, rawInc = null;
|
|
154
|
+
try { rawStart = Number(grid.baselineStart); startMm = IDC.round(rawStart); } catch (e1) { startMm = null; rawStart = null; }
|
|
155
|
+
try { rawInc = Number(grid.baselineDivision); incMm = IDC.round(rawInc); } catch (e2) { incMm = null; rawInc = null; }
|
|
156
|
+
try { incPt = IDC.inPoints(function () { return IDC.round(Number(grid.baselineDivision), 3); }); } catch (e3) { incPt = null; }
|
|
157
|
+
try { shown = grid.baselineGridShown === true; } catch (e4) { shown = null; }
|
|
158
|
+
try { threshold = Number(grid.baselineViewThreshold); } catch (e5) { threshold = null; }
|
|
159
|
+
try {
|
|
160
|
+
rawRel = grid.baselineGridRelativeOption;
|
|
161
|
+
if (typeof BaselineGridRelativeOption !== 'undefined') {
|
|
162
|
+
if (IDC.enumIs(rawRel, BaselineGridRelativeOption.TOP_OF_PAGE_OF_BASELINE_GRID_RELATIVE_OPTION)) { relative = 'top_of_page'; }
|
|
163
|
+
else if (IDC.enumIs(rawRel, BaselineGridRelativeOption.TOP_OF_MARGIN_OF_BASELINE_GRID_RELATIVE_OPTION)) { relative = 'top_of_margin'; }
|
|
164
|
+
}
|
|
165
|
+
} catch (e6) { rawRel = null; }
|
|
166
|
+
if (relative === 'unknown') {
|
|
167
|
+
ctx.warn('Baseline grid reference (relative_to) is unknown; the check below assumes top of page.');
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
start_mm: startMm,
|
|
171
|
+
increment_mm: incMm,
|
|
172
|
+
increment_pt: incPt,
|
|
173
|
+
relative_to: relative,
|
|
174
|
+
relative_to_raw: rawRel === null || rawRel === undefined ? null : String(rawRel),
|
|
175
|
+
shown: shown,
|
|
176
|
+
view_threshold: threshold,
|
|
177
|
+
/* ungerundet fuer die Rechnung; wird vor der Ausgabe entfernt */
|
|
178
|
+
raw_start: rawStart,
|
|
179
|
+
raw_increment: rawInc
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function idcStripRaw(baseline) {
|
|
184
|
+
var out = {}, k;
|
|
185
|
+
for (k in baseline) {
|
|
186
|
+
if (IDC.hasOwn(baseline, k) && k !== 'raw_start' && k !== 'raw_increment') { out[k] = baseline[k]; }
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* Geht das Raster im Satzspiegel der ersten Dokumentseite auf? */
|
|
192
|
+
function idcBaselineCheck(baseline, firstGrid, ctx) {
|
|
193
|
+
var area = firstGrid.type_area_mm;
|
|
194
|
+
var first, lines, last, remainder, startsAtTop;
|
|
195
|
+
var start = baseline.raw_start, inc = baseline.raw_increment;
|
|
196
|
+
if (start === null || inc === null || isNaN(start) || isNaN(inc) || inc <= 0) {
|
|
197
|
+
return { first_line_mm: null, starts_at_type_area_top: null, lines_in_type_area: null, last_line_mm: null, remainder_below_mm: null };
|
|
198
|
+
}
|
|
199
|
+
first = baseline.relative_to === 'top_of_margin' ? area.y + start : start;
|
|
200
|
+
/* erste Rasterlinie im Satzspiegel */
|
|
201
|
+
while (first < area.y - 0.005) { first += inc; }
|
|
202
|
+
startsAtTop = Math.abs(first - area.y) <= 0.01;
|
|
203
|
+
lines = Math.floor((area.y + area.height - first) / inc + 0.0001) + 1;
|
|
204
|
+
if (lines < 0) { lines = 0; }
|
|
205
|
+
last = lines > 0 ? first + (lines - 1) * inc : null;
|
|
206
|
+
remainder = last === null ? null : IDC.round(area.y + area.height - last);
|
|
207
|
+
if (remainder !== null && remainder > 0.01) {
|
|
208
|
+
ctx.warn('The baseline grid does not fit the type area (Satzspiegel): ' + remainder +
|
|
209
|
+
' mm remain below the last grid line on page ' + firstGrid.name + '.');
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
first_line_mm: IDC.round(first),
|
|
213
|
+
starts_at_type_area_top: startsAtTop,
|
|
214
|
+
lines_in_type_area: lines,
|
|
215
|
+
last_line_mm: last === null ? null : IDC.round(last),
|
|
216
|
+
remainder_below_mm: remainder
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function idcReadBleedSlug(doc, ctx) {
|
|
221
|
+
var prefs = doc.documentPreferences;
|
|
222
|
+
var bleed = {
|
|
223
|
+
top: IDC.round(prefs.documentBleedTopOffset),
|
|
224
|
+
left: IDC.round(prefs.documentBleedInsideOrLeftOffset),
|
|
225
|
+
bottom: IDC.round(prefs.documentBleedBottomOffset),
|
|
226
|
+
right: IDC.round(prefs.documentBleedOutsideOrRightOffset)
|
|
227
|
+
};
|
|
228
|
+
bleed.uniform = bleed.top === bleed.left && bleed.top === bleed.bottom && bleed.top === bleed.right;
|
|
229
|
+
if (bleed.top === 0 && bleed.left === 0 && bleed.bottom === 0 && bleed.right === 0) {
|
|
230
|
+
ctx.warn('Bleed (Anschnitt) is 0 mm on every edge; set_document_bleed before exporting for print.');
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
bleed_mm: bleed,
|
|
234
|
+
slug_mm: {
|
|
235
|
+
top: IDC.round(prefs.slugTopOffset),
|
|
236
|
+
left: IDC.round(prefs.slugInsideOrLeftOffset),
|
|
237
|
+
bottom: IDC.round(prefs.slugBottomOffset),
|
|
238
|
+
right: IDC.round(prefs.slugRightOrOutsideOffset)
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
IDC.register('get_layout_grid', { needs_document: true, read_only: true, ruler: 'page' },
|
|
244
|
+
function (ctx) {
|
|
245
|
+
var args = ctx.args;
|
|
246
|
+
var doc = ctx.doc;
|
|
247
|
+
var includeParents = args.include_parent_pages === false ? false : true;
|
|
248
|
+
var facing = idcFacing(doc);
|
|
249
|
+
var all = idcAllPages(doc, includeParents);
|
|
250
|
+
var pages = [];
|
|
251
|
+
var groups = [];
|
|
252
|
+
var groupByKey = {};
|
|
253
|
+
var i, entry, key, group, baseline, check, bleedSlug, firstDocGrid = null;
|
|
254
|
+
|
|
255
|
+
for (i = 0; i < all.length; i++) {
|
|
256
|
+
entry = idcDescribeGrid(all[i].page, all[i].is_parent, facing);
|
|
257
|
+
pages.push(entry);
|
|
258
|
+
if (firstDocGrid === null && !entry.is_parent_page) { firstDocGrid = entry; }
|
|
259
|
+
key = idcGridKey(entry);
|
|
260
|
+
if (!IDC.hasOwn(groupByKey, key)) {
|
|
261
|
+
group = {
|
|
262
|
+
margins_mm: entry.margins_mm,
|
|
263
|
+
columns: entry.column_count,
|
|
264
|
+
gutter_mm: entry.column_gutter_mm,
|
|
265
|
+
page_ids: []
|
|
266
|
+
};
|
|
267
|
+
groupByKey[key] = group;
|
|
268
|
+
groups.push(group);
|
|
269
|
+
}
|
|
270
|
+
groupByKey[key].page_ids.push(entry.page_id);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
baseline = idcReadBaselineGrid(doc, ctx);
|
|
274
|
+
check = firstDocGrid === null
|
|
275
|
+
? { first_line_mm: null, starts_at_type_area_top: null, lines_in_type_area: null, last_line_mm: null, remainder_below_mm: null }
|
|
276
|
+
: idcBaselineCheck(baseline, firstDocGrid, ctx);
|
|
277
|
+
bleedSlug = idcReadBleedSlug(doc, ctx);
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
facing_pages: facing,
|
|
281
|
+
include_parent_pages: includeParents,
|
|
282
|
+
pages: pages,
|
|
283
|
+
page_count: pages.length,
|
|
284
|
+
distinct_grids: groups,
|
|
285
|
+
is_uniform: groups.length <= 1,
|
|
286
|
+
baseline_grid: idcStripRaw(baseline),
|
|
287
|
+
baseline_grid_check: check,
|
|
288
|
+
bleed_mm: bleedSlug.bleed_mm,
|
|
289
|
+
slug_mm: bleedSlug.slug_mm
|
|
290
|
+
};
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
/* ---------------------------------------------------------- set_layout_grid */
|
|
294
|
+
|
|
295
|
+
function idcOptionalNumber(args, key, min, max) {
|
|
296
|
+
var v = args[key];
|
|
297
|
+
if (v === undefined || v === null) { return null; }
|
|
298
|
+
if (typeof v !== 'number' || !isFinite(v)) {
|
|
299
|
+
IDC.fail('invalid_argument', key + ' must be a number.', { value: v });
|
|
300
|
+
}
|
|
301
|
+
if (v < min || v > max) {
|
|
302
|
+
IDC.fail('invalid_argument', key + ' must be between ' + min + ' and ' + max + '.', { value: v });
|
|
303
|
+
}
|
|
304
|
+
return v;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* Seitenauswahl fuer set_layout_grid / delete_guides: page_ids oder alle. */
|
|
308
|
+
function idcSelectPages(doc, args, includeParents) {
|
|
309
|
+
var ids = args.page_ids;
|
|
310
|
+
var out = [], i, found;
|
|
311
|
+
if (ids === undefined || ids === null) { return idcAllPages(doc, includeParents); }
|
|
312
|
+
if (!IDC.isArray(ids) || ids.length === 0) {
|
|
313
|
+
IDC.fail('invalid_argument', 'page_ids must be a non-empty array of page ids (omit it for all pages).', null);
|
|
314
|
+
}
|
|
315
|
+
for (i = 0; i < ids.length; i++) {
|
|
316
|
+
found = IDC.pageById(doc, ids[i]);
|
|
317
|
+
if (found === null) {
|
|
318
|
+
IDC.fail('not_found', 'No page with page_id ' + ids[i] + ' in this document.', { page_id: ids[i] });
|
|
319
|
+
}
|
|
320
|
+
if (found.is_parent_page && !includeParents) {
|
|
321
|
+
IDC.fail('invalid_argument', 'page_id ' + ids[i] + ' is a master page but include_parent_pages is false.', { page_id: ids[i] });
|
|
322
|
+
}
|
|
323
|
+
out.push({ page: found.page, is_parent: found.is_parent_page });
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function idcApplyBaselineGrid(doc, spec, ctx) {
|
|
329
|
+
var grid = doc.gridPreferences;
|
|
330
|
+
var changed = false;
|
|
331
|
+
if (!spec || typeof spec !== 'object') {
|
|
332
|
+
IDC.fail('invalid_argument', 'baseline_grid must be an object { start_mm, increment_pt, relative_to }.', null);
|
|
333
|
+
}
|
|
334
|
+
if (spec.increment_pt !== undefined && spec.increment_pt !== null) {
|
|
335
|
+
if (typeof spec.increment_pt !== 'number' || spec.increment_pt <= 0) {
|
|
336
|
+
IDC.fail('invalid_argument', 'baseline_grid.increment_pt must be a number greater than 0.', spec);
|
|
337
|
+
}
|
|
338
|
+
IDC.inPoints(function () { grid.baselineDivision = spec.increment_pt; });
|
|
339
|
+
changed = true;
|
|
340
|
+
}
|
|
341
|
+
if (spec.start_mm !== undefined && spec.start_mm !== null) {
|
|
342
|
+
if (typeof spec.start_mm !== 'number' || spec.start_mm < 0) {
|
|
343
|
+
IDC.fail('invalid_argument', 'baseline_grid.start_mm must be a number of 0 or more.', spec);
|
|
344
|
+
}
|
|
345
|
+
grid.baselineStart = spec.start_mm;
|
|
346
|
+
changed = true;
|
|
347
|
+
}
|
|
348
|
+
if (spec.relative_to !== undefined && spec.relative_to !== null) {
|
|
349
|
+
if (typeof BaselineGridRelativeOption === 'undefined') {
|
|
350
|
+
ctx.warn('This runtime has no BaselineGridRelativeOption; relative_to was not set.');
|
|
351
|
+
} else if (spec.relative_to === 'top_of_page') {
|
|
352
|
+
grid.baselineGridRelativeOption = BaselineGridRelativeOption.TOP_OF_PAGE_OF_BASELINE_GRID_RELATIVE_OPTION;
|
|
353
|
+
changed = true;
|
|
354
|
+
} else if (spec.relative_to === 'top_of_margin') {
|
|
355
|
+
grid.baselineGridRelativeOption = BaselineGridRelativeOption.TOP_OF_MARGIN_OF_BASELINE_GRID_RELATIVE_OPTION;
|
|
356
|
+
changed = true;
|
|
357
|
+
} else {
|
|
358
|
+
IDC.fail('invalid_argument', 'baseline_grid.relative_to must be "top_of_page" or "top_of_margin".', spec);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return changed;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
IDC.register('set_layout_grid', { needs_document: true, read_only: false, ruler: 'page' },
|
|
365
|
+
function (ctx) {
|
|
366
|
+
var args = ctx.args;
|
|
367
|
+
var doc = ctx.doc;
|
|
368
|
+
var includeParents = args.include_parent_pages === false ? false : true;
|
|
369
|
+
var facing = idcFacing(doc);
|
|
370
|
+
var margins = null;
|
|
371
|
+
var count = idcOptionalNumber(args, 'column_count', 1, 30);
|
|
372
|
+
var gutter = idcOptionalNumber(args, 'column_gutter_mm', 0, 100);
|
|
373
|
+
var targets, i, page, prefs, entry, even, changed = [], ids = [], anything = false, baselineChanged = false, k;
|
|
374
|
+
var keys = ['top', 'left', 'bottom', 'right'];
|
|
375
|
+
|
|
376
|
+
if (count !== null && count !== Math.floor(count)) {
|
|
377
|
+
IDC.fail('invalid_argument', 'column_count must be a whole number.', { value: count });
|
|
378
|
+
}
|
|
379
|
+
if (args.margins_mm !== undefined && args.margins_mm !== null) {
|
|
380
|
+
if (typeof args.margins_mm !== 'object') {
|
|
381
|
+
IDC.fail('invalid_argument', 'margins_mm must be an object with top/left/bottom/right (all optional).', null);
|
|
382
|
+
}
|
|
383
|
+
margins = {};
|
|
384
|
+
for (k = 0; k < keys.length; k++) {
|
|
385
|
+
if (args.margins_mm[keys[k]] !== undefined && args.margins_mm[keys[k]] !== null) {
|
|
386
|
+
if (typeof args.margins_mm[keys[k]] !== 'number' || args.margins_mm[keys[k]] < 0) {
|
|
387
|
+
IDC.fail('invalid_argument', 'margins_mm.' + keys[k] + ' must be a number of 0 or more.', args.margins_mm);
|
|
388
|
+
}
|
|
389
|
+
margins[keys[k]] = args.margins_mm[keys[k]];
|
|
390
|
+
anything = true;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (facing && (margins.left !== undefined || margins.right !== undefined)) {
|
|
394
|
+
ctx.warn('Facing pages: margins_mm.left is the inside margin (Bundsteg), margins_mm.right the outside margin.');
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (count !== null || gutter !== null) { anything = true; }
|
|
398
|
+
if (args.baseline_grid !== undefined && args.baseline_grid !== null) {
|
|
399
|
+
baselineChanged = idcApplyBaselineGrid(doc, args.baseline_grid, ctx);
|
|
400
|
+
anything = anything || baselineChanged;
|
|
401
|
+
}
|
|
402
|
+
if (!anything) {
|
|
403
|
+
IDC.fail('invalid_argument', 'Nothing to set: pass margins_mm, column_count, column_gutter_mm or baseline_grid.', null);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
targets = idcSelectPages(doc, args, includeParents);
|
|
407
|
+
|
|
408
|
+
for (i = 0; i < targets.length; i++) {
|
|
409
|
+
page = targets[i].page;
|
|
410
|
+
prefs = page.marginPreferences;
|
|
411
|
+
try {
|
|
412
|
+
if (margins !== null) {
|
|
413
|
+
if (margins.top !== undefined) { prefs.top = margins.top; }
|
|
414
|
+
if (margins.bottom !== undefined) { prefs.bottom = margins.bottom; }
|
|
415
|
+
if (margins.left !== undefined) { prefs.left = margins.left; }
|
|
416
|
+
if (margins.right !== undefined) { prefs.right = margins.right; }
|
|
417
|
+
}
|
|
418
|
+
if (count !== null) { prefs.columnCount = count; }
|
|
419
|
+
if (gutter !== null) { prefs.columnGutter = gutter; }
|
|
420
|
+
/* Spaltenpositionen gleichmaessig neu verteilen (randrelativ) */
|
|
421
|
+
entry = idcDescribeGrid(page, targets[i].is_parent, facing);
|
|
422
|
+
even = idcEvenColumnPositions(entry.type_area_mm.width, entry.column_count, entry.column_gutter_mm);
|
|
423
|
+
try { prefs.columnsPositions = even.positions; } catch (ec) { /* aeltere Versionen: nur lesbar */ }
|
|
424
|
+
} catch (e) {
|
|
425
|
+
IDC.fail('script_error', 'InDesign could not set the layout grid on page ' + String(page.name) + ': ' +
|
|
426
|
+
String(e.message ? e.message : e), { page_id: Number(page.id) });
|
|
427
|
+
}
|
|
428
|
+
entry = idcDescribeGrid(page, targets[i].is_parent, facing);
|
|
429
|
+
if (entry.custom_column_positions) {
|
|
430
|
+
ctx.warn('Page ' + entry.name + ': column positions do not lie on the even grid after writing (' +
|
|
431
|
+
entry.columns_positions_mm.join(', ') + ').');
|
|
432
|
+
}
|
|
433
|
+
if (entry.type_area_mm.width <= 0 || entry.type_area_mm.height <= 0) {
|
|
434
|
+
ctx.warn('Page ' + entry.name + ': margins leave no type area (Satzspiegel) – width ' +
|
|
435
|
+
entry.type_area_mm.width + ' mm, height ' + entry.type_area_mm.height + ' mm.');
|
|
436
|
+
}
|
|
437
|
+
changed.push({
|
|
438
|
+
page_id: entry.page_id,
|
|
439
|
+
name: entry.name,
|
|
440
|
+
is_parent_page: entry.is_parent_page,
|
|
441
|
+
margins_mm: entry.margins_mm,
|
|
442
|
+
column_count: entry.column_count,
|
|
443
|
+
column_gutter_mm: entry.column_gutter_mm,
|
|
444
|
+
type_area_mm: entry.type_area_mm,
|
|
445
|
+
column_width_mm: entry.column_width_mm,
|
|
446
|
+
columns_positions_mm: entry.columns_positions_mm
|
|
447
|
+
});
|
|
448
|
+
ids.push(entry.page_id);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/* Ohne page_ids gelten die Werte auch fuer neue Seiten (Dokumentvorgabe). */
|
|
452
|
+
var defaultsChanged = false;
|
|
453
|
+
if ((args.page_ids === undefined || args.page_ids === null) && (margins !== null || count !== null || gutter !== null)) {
|
|
454
|
+
try {
|
|
455
|
+
prefs = doc.marginPreferences;
|
|
456
|
+
if (margins !== null) {
|
|
457
|
+
if (margins.top !== undefined) { prefs.top = margins.top; }
|
|
458
|
+
if (margins.bottom !== undefined) { prefs.bottom = margins.bottom; }
|
|
459
|
+
if (margins.left !== undefined) { prefs.left = margins.left; }
|
|
460
|
+
if (margins.right !== undefined) { prefs.right = margins.right; }
|
|
461
|
+
}
|
|
462
|
+
if (count !== null) { prefs.columnCount = count; }
|
|
463
|
+
if (gutter !== null) { prefs.columnGutter = gutter; }
|
|
464
|
+
defaultsChanged = true;
|
|
465
|
+
} catch (e2) { defaultsChanged = false; }
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
ctx.changes = { modified_page_ids: ids, modified_document_ids: [Number(doc.id)] };
|
|
469
|
+
var out = {
|
|
470
|
+
changed_pages: changed,
|
|
471
|
+
changed_page_count: changed.length,
|
|
472
|
+
document_defaults_changed: defaultsChanged
|
|
473
|
+
};
|
|
474
|
+
if (baselineChanged) { out.baseline_grid = idcStripRaw(idcReadBaselineGrid(doc, ctx)); }
|
|
475
|
+
return out;
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
/* -------------------------------------------------------------- Hilfslinien */
|
|
479
|
+
|
|
480
|
+
var IDC_UI_COLOR_NAMES = ['BLACK', 'BLUE', 'BRICK_RED', 'BROWN', 'BURGUNDY', 'CHARCOAL', 'CUTE_TEAL', 'CYAN',
|
|
481
|
+
'DARK_BLUE', 'DARK_GREEN', 'FIESTA', 'GOLD', 'GRASS_GREEN', 'GRAY', 'GREEN', 'GRID_BLUE', 'GRID_GREEN',
|
|
482
|
+
'GRID_ORANGE', 'LAVENDER', 'LIGHT_BLUE', 'LIGHT_GRAY', 'LIGHT_OLIVE', 'LIPSTICK', 'MAGENTA', 'OCHRE',
|
|
483
|
+
'OLIVE_GREEN', 'ORANGE', 'PEACH', 'PINK', 'PURPLE', 'RED', 'SULPHUR', 'TAN', 'TEAL', 'VIOLET', 'WHITE', 'YELLOW'];
|
|
484
|
+
|
|
485
|
+
function idcHex2(n) {
|
|
486
|
+
var h = Math.round(Number(n)).toString(16);
|
|
487
|
+
return h.length < 2 ? '0' + h : h;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function idcGuideColorName(value) {
|
|
491
|
+
var i;
|
|
492
|
+
if (value === null || value === undefined) { return null; }
|
|
493
|
+
if (IDC.isArray(value) && value.length === 3) {
|
|
494
|
+
return '#' + idcHex2(value[0]) + idcHex2(value[1]) + idcHex2(value[2]);
|
|
495
|
+
}
|
|
496
|
+
if (typeof UIColors !== 'undefined') {
|
|
497
|
+
for (i = 0; i < IDC_UI_COLOR_NAMES.length; i++) {
|
|
498
|
+
try {
|
|
499
|
+
if (UIColors[IDC_UI_COLOR_NAMES[i]] !== undefined && IDC.enumIs(value, UIColors[IDC_UI_COLOR_NAMES[i]])) {
|
|
500
|
+
return IDC_UI_COLOR_NAMES[i].toLowerCase();
|
|
501
|
+
}
|
|
502
|
+
} catch (e) { /* naechster */ }
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return String(value);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function idcGuideOrientation(guide) {
|
|
509
|
+
var o = null;
|
|
510
|
+
try { o = guide.orientation; } catch (e) { return 'unknown'; }
|
|
511
|
+
if (typeof HorizontalOrVertical !== 'undefined') {
|
|
512
|
+
if (IDC.enumIs(o, HorizontalOrVertical.HORIZONTAL)) { return 'horizontal'; }
|
|
513
|
+
if (IDC.enumIs(o, HorizontalOrVertical.VERTICAL)) { return 'vertical'; }
|
|
514
|
+
}
|
|
515
|
+
return String(o).toLowerCase().indexOf('hor') >= 0 ? 'horizontal' : 'vertical';
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/* Seiten eines Bogens mit ihrem Versatz in Bogenkoordinaten. */
|
|
519
|
+
function idcSpreadPageOffsets(spread) {
|
|
520
|
+
var out = [], i, page, x = 0, size;
|
|
521
|
+
for (i = 0; i < spread.pages.length; i++) {
|
|
522
|
+
page = spread.pages.item(i);
|
|
523
|
+
size = IDC.pageSize(page);
|
|
524
|
+
out.push({ page: page, offset: x, width: size.width, height: size.height });
|
|
525
|
+
x += size.width;
|
|
526
|
+
}
|
|
527
|
+
return out;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/*
|
|
531
|
+
* Hilfslinien eines Bogens. Laeuft unter Bogen-Nullpunkt (location ist
|
|
532
|
+
* dann bogenrelativ). Seitenzuordnung: fitToPage-Linien kommen ueber
|
|
533
|
+
* page.guides; bei Bogenlinien gilt die Seite, unter der eine senkrechte
|
|
534
|
+
* Linie steht; eine waagerechte Linie auf einem mehrseitigen Bogen hat keine.
|
|
535
|
+
*/
|
|
536
|
+
function idcCollectGuides(spread, isParent, out) {
|
|
537
|
+
var pages = idcSpreadPageOffsets(spread);
|
|
538
|
+
var i, j, guide, entry, orientation, location, pageHit, byPage = {};
|
|
539
|
+
for (j = 0; j < pages.length; j++) {
|
|
540
|
+
try {
|
|
541
|
+
for (i = 0; i < pages[j].page.guides.length; i++) {
|
|
542
|
+
byPage[String(Number(pages[j].page.guides.item(i).id))] = j;
|
|
543
|
+
}
|
|
544
|
+
} catch (e) { /* keine Seitenlinien */ }
|
|
545
|
+
}
|
|
546
|
+
for (i = 0; i < spread.guides.length; i++) {
|
|
547
|
+
guide = spread.guides.item(i);
|
|
548
|
+
orientation = idcGuideOrientation(guide);
|
|
549
|
+
location = IDC.round(Number(guide.location));
|
|
550
|
+
pageHit = null;
|
|
551
|
+
var fit = false;
|
|
552
|
+
try { fit = guide.fitToPage === true; } catch (e1) { fit = false; }
|
|
553
|
+
if (IDC.hasOwn(byPage, String(Number(guide.id))) && fit) {
|
|
554
|
+
pageHit = pages[byPage[String(Number(guide.id))]];
|
|
555
|
+
} else if (orientation === 'vertical') {
|
|
556
|
+
for (j = 0; j < pages.length; j++) {
|
|
557
|
+
if (location >= pages[j].offset - 0.005 && location <= pages[j].offset + pages[j].width + 0.005) {
|
|
558
|
+
pageHit = pages[j];
|
|
559
|
+
if (location < pages[j].offset + pages[j].width - 0.005) { break; }
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
} else if (pages.length === 1) {
|
|
563
|
+
pageHit = pages[0];
|
|
564
|
+
}
|
|
565
|
+
entry = {
|
|
566
|
+
guide_id: Number(guide.id),
|
|
567
|
+
orientation: orientation,
|
|
568
|
+
spread_index: IDC.spreadIndex(spread),
|
|
569
|
+
is_parent_spread: isParent,
|
|
570
|
+
page_id: pageHit === null ? null : Number(pageHit.page.id),
|
|
571
|
+
page_name: pageHit === null ? null : String(pageHit.page.name),
|
|
572
|
+
position_spread_mm: location,
|
|
573
|
+
position_page_mm: pageHit === null ? null : (orientation === 'vertical' ? IDC.round(location - pageHit.offset) : location),
|
|
574
|
+
fit_to_page: fit,
|
|
575
|
+
locked: false,
|
|
576
|
+
layer: null,
|
|
577
|
+
color: null
|
|
578
|
+
};
|
|
579
|
+
try { entry.locked = guide.locked === true; } catch (e2) { entry.locked = false; }
|
|
580
|
+
try { entry.layer = String(guide.itemLayer.name); } catch (e3) { entry.layer = null; }
|
|
581
|
+
try { entry.color = idcGuideColorName(guide.guideColor); } catch (e4) { entry.color = null; }
|
|
582
|
+
out.push(entry);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function idcAllGuides(doc, includeParents) {
|
|
587
|
+
var out = [], i;
|
|
588
|
+
for (i = 0; i < doc.spreads.length; i++) { idcCollectGuides(doc.spreads.item(i), false, out); }
|
|
589
|
+
if (includeParents) {
|
|
590
|
+
for (i = 0; i < doc.masterSpreads.length; i++) { idcCollectGuides(doc.masterSpreads.item(i), true, out); }
|
|
591
|
+
}
|
|
592
|
+
return out;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function idcGuidesLockedGlobally(doc) {
|
|
596
|
+
try { return doc.guidePreferences.guidesLocked === true; } catch (e) { return null; }
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function idcCountGuides(doc) {
|
|
600
|
+
var all = idcAllGuides(doc, true);
|
|
601
|
+
var i, docCount = 0, parentCount = 0;
|
|
602
|
+
for (i = 0; i < all.length; i++) {
|
|
603
|
+
if (all[i].is_parent_spread) { parentCount += 1; } else { docCount += 1; }
|
|
604
|
+
}
|
|
605
|
+
return { document: docCount, parent: parentCount };
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
IDC.register('list_guides', { needs_document: true, read_only: true, ruler: 'spread' },
|
|
609
|
+
function (ctx) {
|
|
610
|
+
var args = ctx.args;
|
|
611
|
+
var doc = ctx.doc;
|
|
612
|
+
var includeParents = args.include_parent_pages === false ? false : true;
|
|
613
|
+
var guides = idcAllGuides(doc, includeParents);
|
|
614
|
+
var counts = idcCountGuides(doc);
|
|
615
|
+
return {
|
|
616
|
+
guides: guides,
|
|
617
|
+
count: guides.length,
|
|
618
|
+
guides_locked_globally: idcGuidesLockedGlobally(doc),
|
|
619
|
+
count_document: counts.document,
|
|
620
|
+
count_parent: counts.parent,
|
|
621
|
+
include_parent_pages: includeParents
|
|
622
|
+
};
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
/* Hilfslinienobjekt zu einer ID, sonst null. */
|
|
626
|
+
function idcGuideById(doc, id, includeParents) {
|
|
627
|
+
var i, spread, guide;
|
|
628
|
+
var wanted = Number(id);
|
|
629
|
+
function look(s, isParent) {
|
|
630
|
+
var g;
|
|
631
|
+
try {
|
|
632
|
+
g = s.guides.itemByID(wanted);
|
|
633
|
+
if (g && g.isValid === true) { return { guide: g, spread: s, is_parent: isParent }; }
|
|
634
|
+
} catch (e) { /* nicht hier */ }
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
for (i = 0; i < doc.spreads.length; i++) {
|
|
638
|
+
guide = look(doc.spreads.item(i), false);
|
|
639
|
+
if (guide !== null) { return guide; }
|
|
640
|
+
}
|
|
641
|
+
if (includeParents) {
|
|
642
|
+
for (i = 0; i < doc.masterSpreads.length; i++) {
|
|
643
|
+
spread = doc.masterSpreads.item(i);
|
|
644
|
+
guide = look(spread, true);
|
|
645
|
+
if (guide !== null) { return guide; }
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
IDC.register('delete_guides', { needs_document: true, read_only: false, ruler: 'spread' },
|
|
652
|
+
function (ctx) {
|
|
653
|
+
var args = ctx.args;
|
|
654
|
+
var doc = ctx.doc;
|
|
655
|
+
var includeParents = args.include_parent_pages === false ? false : true;
|
|
656
|
+
var modes = 0;
|
|
657
|
+
var targets = [];
|
|
658
|
+
var i, j, found, entry, all, spreadsWanted = {}, pages, deleted = [], failed = [], ids = [];
|
|
659
|
+
|
|
660
|
+
if (args.guide_ids !== undefined && args.guide_ids !== null) { modes += 1; }
|
|
661
|
+
if (args.page_ids !== undefined && args.page_ids !== null) { modes += 1; }
|
|
662
|
+
if (args.confirm_all === true) { modes += 1; }
|
|
663
|
+
if (modes !== 1) {
|
|
664
|
+
IDC.fail('invalid_argument', 'Pass exactly one of guide_ids[], page_ids[] or confirm_all: true.', null);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (args.guide_ids !== undefined && args.guide_ids !== null) {
|
|
668
|
+
if (!IDC.isArray(args.guide_ids) || args.guide_ids.length === 0) {
|
|
669
|
+
IDC.fail('invalid_argument', 'guide_ids must be a non-empty array.', null);
|
|
670
|
+
}
|
|
671
|
+
for (i = 0; i < args.guide_ids.length; i++) {
|
|
672
|
+
found = idcGuideById(doc, args.guide_ids[i], includeParents);
|
|
673
|
+
if (found === null) {
|
|
674
|
+
failed.push({ guide_id: Number(args.guide_ids[i]), reason: 'not found' + (includeParents ? '' : ' (master spreads excluded)') });
|
|
675
|
+
} else {
|
|
676
|
+
targets.push(found);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
} else {
|
|
680
|
+
if (args.page_ids !== undefined && args.page_ids !== null) {
|
|
681
|
+
pages = idcSelectPages(doc, args, includeParents);
|
|
682
|
+
for (i = 0; i < pages.length; i++) {
|
|
683
|
+
spreadsWanted[String(Number(pages[i].page.parent.id))] = true;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
for (i = 0; i < doc.spreads.length; i++) {
|
|
687
|
+
if (args.confirm_all === true || spreadsWanted[String(Number(doc.spreads.item(i).id))]) {
|
|
688
|
+
for (j = 0; j < doc.spreads.item(i).guides.length; j++) {
|
|
689
|
+
targets.push({ guide: doc.spreads.item(i).guides.item(j), spread: doc.spreads.item(i), is_parent: false });
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (includeParents) {
|
|
694
|
+
for (i = 0; i < doc.masterSpreads.length; i++) {
|
|
695
|
+
if (args.confirm_all === true || spreadsWanted[String(Number(doc.masterSpreads.item(i).id))]) {
|
|
696
|
+
for (j = 0; j < doc.masterSpreads.item(i).guides.length; j++) {
|
|
697
|
+
targets.push({ guide: doc.masterSpreads.item(i).guides.item(j), spread: doc.masterSpreads.item(i), is_parent: true });
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/* Beschreibung vor dem Loeschen festhalten */
|
|
705
|
+
all = idcAllGuides(doc, true);
|
|
706
|
+
var byId = {};
|
|
707
|
+
for (i = 0; i < all.length; i++) { byId[String(all[i].guide_id)] = all[i]; }
|
|
708
|
+
|
|
709
|
+
var prevGlobal = null, globalSet = false;
|
|
710
|
+
try {
|
|
711
|
+
prevGlobal = doc.guidePreferences.guidesLocked;
|
|
712
|
+
if (prevGlobal === true) { doc.guidePreferences.guidesLocked = false; globalSet = true; }
|
|
713
|
+
} catch (eg) { globalSet = false; }
|
|
714
|
+
|
|
715
|
+
try {
|
|
716
|
+
for (i = 0; i < targets.length; i++) {
|
|
717
|
+
var guide = targets[i].guide;
|
|
718
|
+
var gid = Number(guide.id);
|
|
719
|
+
entry = byId[String(gid)] || { guide_id: gid, orientation: null, position_spread_mm: null, position_page_mm: null, page_name: null };
|
|
720
|
+
var layer = null, layerWasLocked = false;
|
|
721
|
+
try {
|
|
722
|
+
layer = guide.itemLayer;
|
|
723
|
+
if (layer && layer.locked === true) { layer.locked = false; layerWasLocked = true; }
|
|
724
|
+
} catch (el) { layer = null; }
|
|
725
|
+
try {
|
|
726
|
+
try { if (guide.locked === true) { guide.locked = false; } } catch (eu) { /* egal */ }
|
|
727
|
+
guide.remove();
|
|
728
|
+
deleted.push({
|
|
729
|
+
guide_id: gid,
|
|
730
|
+
orientation: entry.orientation,
|
|
731
|
+
position: entry.position_page_mm !== null ? entry.position_page_mm : entry.position_spread_mm,
|
|
732
|
+
position_spread_mm: entry.position_spread_mm,
|
|
733
|
+
position_page_mm: entry.position_page_mm,
|
|
734
|
+
page: entry.page_name,
|
|
735
|
+
is_parent_spread: targets[i].is_parent
|
|
736
|
+
});
|
|
737
|
+
ids.push(gid);
|
|
738
|
+
} catch (er) {
|
|
739
|
+
failed.push({ guide_id: gid, reason: String(er.message ? er.message : er) });
|
|
740
|
+
} finally {
|
|
741
|
+
if (layer !== null && layerWasLocked) { try { layer.locked = true; } catch (el2) { /* egal */ } }
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
} finally {
|
|
745
|
+
if (globalSet) { try { doc.guidePreferences.guidesLocked = prevGlobal; } catch (eg2) { /* egal */ } }
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
var counts = idcCountGuides(doc);
|
|
749
|
+
if (targets.length === 0 && failed.length === 0) {
|
|
750
|
+
ctx.warn('No guides matched the selection; nothing was deleted.');
|
|
751
|
+
}
|
|
752
|
+
ctx.changes = { removed_guide_ids: ids };
|
|
753
|
+
return {
|
|
754
|
+
deleted: deleted,
|
|
755
|
+
deleted_count: deleted.length,
|
|
756
|
+
failed: failed,
|
|
757
|
+
remaining_document: counts.document,
|
|
758
|
+
remaining_parent: counts.parent
|
|
759
|
+
};
|
|
760
|
+
});
|