@first-ch/tools-mcp 0.34.1 → 0.37.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/README.md +134 -20
- package/apps.mjs +538 -0
- package/base64.mjs +3 -2
- package/case-convert.mjs +3 -2
- package/css-layout.mjs +612 -0
- package/csv-json.mjs +3 -2
- package/dpi.mjs +660 -0
- package/faq-jsonld.mjs +401 -0
- package/fs-safe.mjs +35 -0
- package/html-escape.mjs +3 -2
- package/html-md.mjs +3 -2
- package/htpasswd.mjs +740 -0
- package/json-yaml.mjs +3 -2
- package/lib.mjs +3 -1
- package/lines.mjs +423 -0
- package/markdown-table.mjs +3 -2
- package/marp.mjs +73 -21
- package/openapi-doc.mjs +2954 -0
- package/package.json +68 -6
- package/px-rem.mjs +3 -2
- package/qr.mjs +3 -3
- package/robots-txt.mjs +2 -2
- package/serp.mjs +309 -0
- package/server.mjs +423 -50
- package/sql-format.mjs +3 -2
- package/webp.mjs +4 -3
- package/zenkaku.mjs +3 -2
package/dpi.mjs
ADDED
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
/* 印刷サイズ・DPI計算(dpi_calc)
|
|
2
|
+
* 計算コア(dpiCalc / dpiReverse / dpiFor / dpiGrade / dpiTable ほか・用紙一覧 PAPERS)は
|
|
3
|
+
* FirstCHTools の site/dpi/app.js と同一
|
|
4
|
+
* (2箇所ルール: site側が正本・片方を直したらもう片方も同じ内容で反映する)。
|
|
5
|
+
* 両ファイルからコアの開始/終了コメントに挟まれた範囲を sed で切り出し
|
|
6
|
+
* (site側は字下げ2文字を落とす・こちらは行頭の export を落とす)、
|
|
7
|
+
* diff が空になることで同期を機械的に確認できる。
|
|
8
|
+
*
|
|
9
|
+
* コアの外(DPI_TEXT と dpiCalcTool)は、site側の画面処理(renderCalc / renderReverse /
|
|
10
|
+
* buildTableText / renderUnits)が組み立てる指摘・入稿メモ・早見表・単位換算を、
|
|
11
|
+
* DOM に書かずに値で返す形へ移したもの。文言は site側の T(日英)と同じ。
|
|
12
|
+
* プレビューの紙面の描画・コピー・タブは持たない。
|
|
13
|
+
* 完全ローカル処理・ネットワーク送信なし。 */
|
|
14
|
+
|
|
15
|
+
/* ==================== ここから計算コア(site / MCP で同一) ==================== */
|
|
16
|
+
|
|
17
|
+
export const MM_PER_INCH = 25.4;
|
|
18
|
+
export const PT_PER_INCH = 72; // DTPポイント(1pt = 1/72 inch)
|
|
19
|
+
export const MAX_MM = 10000; // 用紙の一辺として受け付ける上限(10m)
|
|
20
|
+
export const MAX_PX = 500000; // ピクセル数の上限
|
|
21
|
+
export const MAX_DPI = 4800;
|
|
22
|
+
export const PSD_LIMIT = 30000; // PSD が持てる一辺の上限 px(超えると PSB が要る)
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 用紙プリセット。寸法は短辺 × 長辺(mm)で持ち、向きは表示側で入れ替える。
|
|
26
|
+
* land: 既定で横向きに使うもの(名刺・往復はがき)
|
|
27
|
+
*/
|
|
28
|
+
export const PAPERS = [
|
|
29
|
+
{ key: 'A0', group: 'a', w: 841, h: 1189 },
|
|
30
|
+
{ key: 'A1', group: 'a', w: 594, h: 841 },
|
|
31
|
+
{ key: 'A2', group: 'a', w: 420, h: 594 },
|
|
32
|
+
{ key: 'A3', group: 'a', w: 297, h: 420 },
|
|
33
|
+
{ key: 'A4', group: 'a', w: 210, h: 297 },
|
|
34
|
+
{ key: 'A5', group: 'a', w: 148, h: 210 },
|
|
35
|
+
{ key: 'A6', group: 'a', w: 105, h: 148 },
|
|
36
|
+
{ key: 'B1', group: 'b', w: 728, h: 1030 },
|
|
37
|
+
{ key: 'B2', group: 'b', w: 515, h: 728 },
|
|
38
|
+
{ key: 'B3', group: 'b', w: 364, h: 515 },
|
|
39
|
+
{ key: 'B4', group: 'b', w: 257, h: 364 },
|
|
40
|
+
{ key: 'B5', group: 'b', w: 182, h: 257 },
|
|
41
|
+
{ key: 'B6', group: 'b', w: 128, h: 182 },
|
|
42
|
+
{ key: 'MEISHI', group: 'card', w: 55, h: 91, land: true },
|
|
43
|
+
{ key: 'MEISHI_SQ', group: 'card', w: 60, h: 60 },
|
|
44
|
+
{ key: 'US_CARD', group: 'card', w: 50.8, h: 88.9, land: true },
|
|
45
|
+
{ key: 'CD', group: 'card', w: 121, h: 121 },
|
|
46
|
+
{ key: 'HAGAKI', group: 'post', w: 100, h: 148 },
|
|
47
|
+
{ key: 'OFUKU', group: 'post', w: 148, h: 200, land: true },
|
|
48
|
+
{ key: 'PHOTO_L', group: 'post', w: 89, h: 127 },
|
|
49
|
+
{ key: 'PHOTO_2L', group: 'post', w: 127, h: 178 },
|
|
50
|
+
{ key: 'PHOTO_KG', group: 'post', w: 102, h: 152 },
|
|
51
|
+
{ key: 'NAGA3', group: 'etc', w: 120, h: 235, land: true },
|
|
52
|
+
{ key: 'YOKO_NOBORI', group: 'etc', w: 600, h: 1800 },
|
|
53
|
+
{ key: 'TICKET', group: 'etc', w: 55, h: 180, land: true },
|
|
54
|
+
{ key: 'LETTER', group: 'us', w: 215.9, h: 279.4 },
|
|
55
|
+
{ key: 'LEGAL', group: 'us', w: 215.9, h: 355.6 },
|
|
56
|
+
{ key: 'TABLOID', group: 'us', w: 279.4, h: 431.8 },
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// 早見表に載せる定番(全プリセットだと縦に長くなりすぎる)
|
|
60
|
+
export const TABLE_KEYS = ['A2', 'A3', 'A4', 'A5', 'A6', 'B3', 'B4', 'B5', 'MEISHI', 'HAGAKI', 'PHOTO_L', 'LETTER'];
|
|
61
|
+
|
|
62
|
+
export const DPI_PRESETS = [72, 96, 150, 200, 250, 300, 350, 400, 600, 1200];
|
|
63
|
+
|
|
64
|
+
/** 文字列・数値を有限な数へ。読めなければ NaN */
|
|
65
|
+
export function dpNum(v) {
|
|
66
|
+
if (typeof v === 'number') return Number.isFinite(v) ? v : NaN;
|
|
67
|
+
const s = String(v === undefined || v === null ? '' : v)
|
|
68
|
+
.trim().replace(/,/g, '').replace(/(px|mm|dpi|ppi)$/i, '').trim();
|
|
69
|
+
if (!s) return NaN;
|
|
70
|
+
const n = Number(s);
|
|
71
|
+
return Number.isFinite(n) ? n : NaN;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function isMm(n) { return Number.isFinite(n) && n > 0 && n <= MAX_MM; }
|
|
75
|
+
export function isPx(n) { return Number.isFinite(n) && n > 0 && n <= MAX_PX; }
|
|
76
|
+
export function isDpi(n) { return Number.isFinite(n) && n > 0 && n <= MAX_DPI; }
|
|
77
|
+
export function isBleed(n) { return Number.isFinite(n) && n >= 0 && n <= 100; }
|
|
78
|
+
|
|
79
|
+
/** 小数を見やすい文字列へ(小数点以下の末尾の0だけを落とす。300 を 3 にしない) */
|
|
80
|
+
export function fmt(n, digits) {
|
|
81
|
+
if (!Number.isFinite(n)) return '';
|
|
82
|
+
const d = digits === undefined ? 2 : digits;
|
|
83
|
+
let s = n.toFixed(d);
|
|
84
|
+
if (s.indexOf('.') !== -1) s = s.replace(/0+$/, '').replace(/\.$/, '');
|
|
85
|
+
return s === '-0' ? '0' : s;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 3桁区切り(ピクセル数は桁が多いので読みやすくする) */
|
|
89
|
+
export function group(n) {
|
|
90
|
+
if (!Number.isFinite(n)) return '';
|
|
91
|
+
return Math.round(n).toLocaleString('en-US');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** mm → px(解像度 dpi のとき) */
|
|
95
|
+
export function mmToPx(mm, dpi) { return mm / MM_PER_INCH * dpi; }
|
|
96
|
+
|
|
97
|
+
/** px → mm */
|
|
98
|
+
export function pxToMm(px, dpi) { return px / dpi * MM_PER_INCH; }
|
|
99
|
+
|
|
100
|
+
/** 用紙プリセットを引く */
|
|
101
|
+
export function paperByKey(key) {
|
|
102
|
+
return PAPERS.find((p) => p.key === String(key || '').toUpperCase()) || null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 向きを当てた寸法(mm)。orientation: 'portrait' | 'landscape' */
|
|
106
|
+
export function paperSize(paper, orientation) {
|
|
107
|
+
const short = Math.min(paper.w, paper.h);
|
|
108
|
+
const long = Math.max(paper.w, paper.h);
|
|
109
|
+
return orientation === 'landscape' ? { w: long, h: short } : { w: short, h: long };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 用紙(mm)と解像度から、入稿に必要なピクセル数を求める。
|
|
114
|
+
* 端数は切り上げる(足りないより1px多い方が安全なため)。
|
|
115
|
+
* @param {object} o
|
|
116
|
+
* @param {number} o.widthMm 仕上がりの幅(mm)
|
|
117
|
+
* @param {number} o.heightMm 仕上がりの高さ(mm)
|
|
118
|
+
* @param {number} o.dpi 解像度
|
|
119
|
+
* @param {number} [o.bleedMm=0] 塗り足し(片側・mm)
|
|
120
|
+
* @returns {object|null}
|
|
121
|
+
*/
|
|
122
|
+
export function dpiCalc(o) {
|
|
123
|
+
const wMm = dpNum(o.widthMm);
|
|
124
|
+
const hMm = dpNum(o.heightMm);
|
|
125
|
+
const dpi = dpNum(o.dpi);
|
|
126
|
+
const bleed = isBleed(dpNum(o.bleedMm)) ? dpNum(o.bleedMm) : 0;
|
|
127
|
+
if (!isMm(wMm) || !isMm(hMm) || !isDpi(dpi)) return null;
|
|
128
|
+
|
|
129
|
+
const fullW = wMm + bleed * 2;
|
|
130
|
+
const fullH = hMm + bleed * 2;
|
|
131
|
+
const exact = { w: mmToPx(wMm, dpi), h: mmToPx(hMm, dpi) };
|
|
132
|
+
const trim = { w: Math.ceil(exact.w - 1e-9), h: Math.ceil(exact.h - 1e-9) };
|
|
133
|
+
const full = { w: Math.ceil(mmToPx(fullW, dpi) - 1e-9), h: Math.ceil(mmToPx(fullH, dpi) - 1e-9) };
|
|
134
|
+
const pixels = full.w * full.h;
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
widthMm: wMm,
|
|
138
|
+
heightMm: hMm,
|
|
139
|
+
bleedMm: bleed,
|
|
140
|
+
dpi,
|
|
141
|
+
fullWidthMm: fullW,
|
|
142
|
+
fullHeightMm: fullH,
|
|
143
|
+
widthIn: wMm / MM_PER_INCH,
|
|
144
|
+
heightIn: hMm / MM_PER_INCH,
|
|
145
|
+
exactWidth: exact.w,
|
|
146
|
+
exactHeight: exact.h,
|
|
147
|
+
trimWidth: trim.w,
|
|
148
|
+
trimHeight: trim.h,
|
|
149
|
+
width: full.w, // 塗り足し込み
|
|
150
|
+
height: full.h,
|
|
151
|
+
bleedPx: mmToPx(bleed, dpi),
|
|
152
|
+
megapixels: pixels / 1e6,
|
|
153
|
+
// 非圧縮・8bit/chをそのまま並べたときの目安(PSD/TIFFの素の大きさ)
|
|
154
|
+
bytesRgb: pixels * 3,
|
|
155
|
+
bytesCmyk: pixels * 4,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 手持ちのピクセル数から、その解像度で印刷できる実寸を求める。
|
|
161
|
+
* @returns {object|null}
|
|
162
|
+
*/
|
|
163
|
+
export function dpiReverse(o) {
|
|
164
|
+
const px = dpNum(o.width);
|
|
165
|
+
const py = dpNum(o.height);
|
|
166
|
+
const dpi = dpNum(o.dpi);
|
|
167
|
+
if (!isPx(px) || !isPx(py) || !isDpi(dpi)) return null;
|
|
168
|
+
return {
|
|
169
|
+
width: px,
|
|
170
|
+
height: py,
|
|
171
|
+
dpi,
|
|
172
|
+
widthMm: pxToMm(px, dpi),
|
|
173
|
+
heightMm: pxToMm(py, dpi),
|
|
174
|
+
widthIn: px / dpi,
|
|
175
|
+
heightIn: py / dpi,
|
|
176
|
+
megapixels: px * py / 1e6,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 手持ちのピクセル数をその用紙に使ったときの実効dpi。
|
|
182
|
+
* 用紙の向きは、画像の向きに合わせて有利な方を選ぶ(縦横は刷る前に回せるため)。
|
|
183
|
+
* @returns {object|null}
|
|
184
|
+
*/
|
|
185
|
+
export function dpiFor(o) {
|
|
186
|
+
const px = dpNum(o.width);
|
|
187
|
+
const py = dpNum(o.height);
|
|
188
|
+
const wMm = dpNum(o.widthMm);
|
|
189
|
+
const hMm = dpNum(o.heightMm);
|
|
190
|
+
const bleed = isBleed(dpNum(o.bleedMm)) ? dpNum(o.bleedMm) : 0;
|
|
191
|
+
if (!isPx(px) || !isPx(py) || !isMm(wMm) || !isMm(hMm)) return null;
|
|
192
|
+
const W = wMm + bleed * 2;
|
|
193
|
+
const H = hMm + bleed * 2;
|
|
194
|
+
// 用紙を回した2通りを試し、実効dpiが高い方を採る
|
|
195
|
+
const cases = [{ w: W, h: H, rotated: false }, { w: H, h: W, rotated: true }];
|
|
196
|
+
let best = null;
|
|
197
|
+
for (const c of cases) {
|
|
198
|
+
// 紙を埋める(cover)ときの実効dpi=足を引っぱる方の辺で決まる
|
|
199
|
+
const eff = Math.min(px / (c.w / MM_PER_INCH), py / (c.h / MM_PER_INCH));
|
|
200
|
+
if (!best || eff > best.dpi) best = { dpi: eff, rotated: c.rotated, widthMm: c.w, heightMm: c.h };
|
|
201
|
+
}
|
|
202
|
+
return best;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** 実効dpiの評価。350以上=十分 / 300以上=実用 / 200以上=用途しだい / それ未満=不足 */
|
|
206
|
+
export function dpiGrade(dpi) {
|
|
207
|
+
if (!(dpi > 0)) return 'ng';
|
|
208
|
+
if (dpi >= 350) return 'best';
|
|
209
|
+
if (dpi >= 300) return 'ok';
|
|
210
|
+
if (dpi >= 200) return 'fair';
|
|
211
|
+
return 'ng';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 早見表の行を作る */
|
|
215
|
+
export function dpiTable(keys, dpi, bleedMm) {
|
|
216
|
+
const rows = [];
|
|
217
|
+
for (const key of keys) {
|
|
218
|
+
const p = paperByKey(key);
|
|
219
|
+
if (!p) continue;
|
|
220
|
+
const size = paperSize(p, p.land ? 'landscape' : 'portrait');
|
|
221
|
+
const r = dpiCalc({ widthMm: size.w, heightMm: size.h, dpi, bleedMm });
|
|
222
|
+
if (r) rows.push(Object.assign({ key: p.key }, r));
|
|
223
|
+
}
|
|
224
|
+
return rows;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** バイト数を MB / GB の文字列へ(1MB = 1024×1024 bytes) */
|
|
228
|
+
export function bytes(n) {
|
|
229
|
+
if (!(n > 0)) return '0 MB';
|
|
230
|
+
const mb = n / 1048576;
|
|
231
|
+
if (mb >= 1024) return fmt(mb / 1024, 2) + ' GB';
|
|
232
|
+
if (mb >= 100) return fmt(mb, 0) + ' MB';
|
|
233
|
+
return fmt(mb, 1) + ' MB';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/* ==================== ここまで計算コア ==================== */
|
|
237
|
+
|
|
238
|
+
/* ---- 文言(site側の T と同じ。site はページの <html lang> で切り替え、こちらは lang 引数で選ぶ) ---- */
|
|
239
|
+
export const DPI_TEXT = {
|
|
240
|
+
ja: {
|
|
241
|
+
badMm: '仕上がりサイズをmmで入れてください(例: 210 × 297)。',
|
|
242
|
+
badDpi: '解像度を 1〜4800 dpi の範囲で入れてください。',
|
|
243
|
+
badBleed: '塗り足しを 0〜100mm の範囲で入れてください。',
|
|
244
|
+
badPx: '手持ちの画像のピクセル数を入れてください(例: 4000 × 3000)。',
|
|
245
|
+
papers: {
|
|
246
|
+
A0: 'A0 — 841 × 1189 mm', A1: 'A1 — 594 × 841 mm', A2: 'A2 — 420 × 594 mm',
|
|
247
|
+
A3: 'A3 — 297 × 420 mm', A4: 'A4 — 210 × 297 mm', A5: 'A5 — 148 × 210 mm',
|
|
248
|
+
A6: 'A6 — 105 × 148 mm', B1: 'B1(JIS) — 728 × 1030 mm', B2: 'B2(JIS) — 515 × 728 mm',
|
|
249
|
+
B3: 'B3(JIS) — 364 × 515 mm', B4: 'B4(JIS) — 257 × 364 mm', B5: 'B5(JIS) — 182 × 257 mm',
|
|
250
|
+
B6: 'B6(JIS) — 128 × 182 mm',
|
|
251
|
+
MEISHI: '名刺(日本・4号) — 91 × 55 mm', MEISHI_SQ: '正方形の名刺 — 60 × 60 mm',
|
|
252
|
+
US_CARD: '名刺(欧米) — 88.9 × 50.8 mm', CD: 'CDジャケット — 121 × 121 mm',
|
|
253
|
+
HAGAKI: 'はがき・DM — 100 × 148 mm', OFUKU: '往復はがき — 200 × 148 mm',
|
|
254
|
+
PHOTO_L: 'L判写真 — 89 × 127 mm', PHOTO_2L: '2L判写真 — 127 × 178 mm',
|
|
255
|
+
PHOTO_KG: 'KG(はがきサイズ写真) — 102 × 152 mm',
|
|
256
|
+
NAGA3: '長形3号封筒 — 235 × 120 mm', YOKO_NOBORI: 'のぼり旗 — 600 × 1800 mm',
|
|
257
|
+
TICKET: 'チケット・しおり — 180 × 55 mm',
|
|
258
|
+
LETTER: 'レター(US) — 215.9 × 279.4 mm', LEGAL: 'リーガル(US) — 215.9 × 355.6 mm',
|
|
259
|
+
TABLOID: 'タブロイド(US) — 279.4 × 431.8 mm',
|
|
260
|
+
},
|
|
261
|
+
paperShort: {
|
|
262
|
+
A0: 'A0', A1: 'A1', A2: 'A2', A3: 'A3', A4: 'A4', A5: 'A5', A6: 'A6',
|
|
263
|
+
B1: 'B1', B2: 'B2', B3: 'B3', B4: 'B4', B5: 'B5', B6: 'B6',
|
|
264
|
+
MEISHI: '名刺', MEISHI_SQ: '正方形の名刺', US_CARD: '名刺(欧米)', CD: 'CDジャケット',
|
|
265
|
+
HAGAKI: 'はがき', OFUKU: '往復はがき', PHOTO_L: 'L判写真', PHOTO_2L: '2L判写真',
|
|
266
|
+
PHOTO_KG: 'KG判', NAGA3: '長形3号封筒', YOKO_NOBORI: 'のぼり旗', TICKET: 'チケット',
|
|
267
|
+
LETTER: 'レター', LEGAL: 'リーガル', TABLOID: 'タブロイド',
|
|
268
|
+
},
|
|
269
|
+
custom: '自由なサイズ(mm)',
|
|
270
|
+
orient: { portrait: '縦(ポートレート)', landscape: '横(ランドスケープ)' },
|
|
271
|
+
grades: { best: '十分', ok: '実用', fair: '用途しだい', ng: '不足' },
|
|
272
|
+
gradeNote: {
|
|
273
|
+
best: '商業印刷の標準(350dpi)に届いています',
|
|
274
|
+
ok: '300dpi — たいていの印刷物で問題ありません',
|
|
275
|
+
fair: '300dpi未満。離れて見る大判なら使えます',
|
|
276
|
+
ng: '200dpi未満。手に取って見る印刷物ではぼやけます',
|
|
277
|
+
},
|
|
278
|
+
memoTitle: '入稿データの仕様',
|
|
279
|
+
memoPaper: '用紙', memoRes: '解像度', memoTrim: '仕上がり',
|
|
280
|
+
memoBleed: '塗り足し', memoFull: '塗り足し込み', memoData: '非圧縮でのデータ量',
|
|
281
|
+
memoNone: 'なし',
|
|
282
|
+
previewTrim: '仕上がり', previewBleed: '塗り足し', previewSafe: '安全な範囲',
|
|
283
|
+
tableHead: ['用紙', 'サイズ(mm)', '仕上がり(px)', '塗り足し込み(px)'],
|
|
284
|
+
revHead: ['用紙', '実効dpi', '判定'],
|
|
285
|
+
fmtLabels: { text: 'テキスト', md: 'Markdownの表', csv: 'CSV' },
|
|
286
|
+
statTrim: '仕上がり(px)', statFull: '塗り足し込み(px)', statMm: '仕上がりの実寸',
|
|
287
|
+
statData: '非圧縮のデータ量', statPrint: '印刷できる大きさ', statDpi: '実効dpi',
|
|
288
|
+
statMax: '350dpiでの上限', statMp: '画素数',
|
|
289
|
+
unitsHead: ['単位', '値'],
|
|
290
|
+
units: { mm: 'ミリメートル', cm: 'センチメートル', inch: 'インチ', px: 'ピクセル', pt: 'ポイント(1/72インチ)', q: '級(Q・0.25mm)' },
|
|
291
|
+
noteStandard: (dpi) => `${fmt(dpi, 0)}dpi は日本の商業印刷・オンデマンド印刷で標準的に求められる解像度です(欧米は300dpiが基準)。どちらでも手に取って見る印刷物で問題ありません。`,
|
|
292
|
+
noteLow: (dpi) => `${fmt(dpi, 0)}dpi は多くの印刷所が求める300dpiを下回ります。数メートル離れて見るポスターや横断幕なら十分ですが、手元で見る印刷物では文字や細部がぼやけます。`,
|
|
293
|
+
noteVeryLow: (dpi) => `${fmt(dpi, 0)}dpi は画面向けの解像度です。この大きさで刷るとピクセルそのものが見えます。350dpi にするにはピクセル数を約${fmt(350 / dpi, 1)}倍にしてください。`,
|
|
294
|
+
noteHigh: (dpi) => `${fmt(dpi, 0)}dpi が効くのは線画・バーコード・小さな文字(単色)です。写真は400dpiを超えても印刷の網点が再現できないため、データが重くなるだけで見た目は変わりません。`,
|
|
295
|
+
noteBleed: (mm) => `塗り足しは四辺それぞれ${fmt(mm)}mmです。断裁位置より${fmt(mm)}mm外側まで絵柄を伸ばして作ります。2つのピクセル数の差(${fmt(mm * 2)}mm分)がこれにあたります。`,
|
|
296
|
+
noteNoBleed: '塗り足しなしの設定です。背景色や写真が紙の端まで届くデザインなら3mmを足してください。断裁のわずかなズレで、白い筋が出ます。',
|
|
297
|
+
noteSafe: (mm) => `文字やロゴは仕上がり線より${fmt(mm)}mm内側に収めてください(プレビューの点線)。断裁の精度は1mm前後で、端ぎりぎりの文字は窮屈にも見えます。`,
|
|
298
|
+
noteRound: (exact, px) => `正確には ${exact}px で、切り上げて ${px}px にしています。端数は必ず切り上げてください。1px足りないと端に白い線が残ります。`,
|
|
299
|
+
noteData: (rgb, cmyk) => `統合済み8bitの非圧縮データでおよそ RGB ${rgb} / CMYK ${cmyk} です。レイヤーや効果を持つ作業データはこの数倍になるので、余裕を見てください。`,
|
|
300
|
+
notePsd: (side) => `一辺が ${group(side)}px で、PSD形式の上限(30,000px)を超えます。Photoshopは PSB での保存を求めます。このサイズの制作物は離れて見るものなので、150〜200dpi で作る方が現実的です。`,
|
|
301
|
+
noteBig: (mp) => `${fmt(mp, 0)}メガピクセルは編集が重くなる大きさです。大判では寸法ではなく解像度を落とすのが定石で、dpiを半分にすると画素数は4分の1になります。`,
|
|
302
|
+
noteCmyk: '指定がなければCMYKで入稿します。RGBのまま渡すと印刷所側の変換で鮮やかな青や緑がくすみ、校正が出るまで気づけません。',
|
|
303
|
+
revExact: (mm, dpi) => `${fmt(dpi, 0)}dpi で ${mm} になります。`,
|
|
304
|
+
revMax: (dpi, w, h) => `${fmt(dpi, 0)}dpi なら最大 ${w} × ${h} mm まで印刷できます。`,
|
|
305
|
+
revFits: (paper, dpi) => `${paper} に${fmt(dpi, 0)}dpiで使えます。`,
|
|
306
|
+
revShort: (paper, dpi, need) => `${paper} では${fmt(dpi, 0)}dpiになります。350dpiにするには ${need} が必要です。`,
|
|
307
|
+
revUpscale: 'Photoshopで拡大しても情報は増えません(無いピクセルを作っているだけです)。実効dpiが足りないときは、撮り直す・スキャンし直す方が確実です。',
|
|
308
|
+
revVector: 'ロゴや文字は、解像度を持たないベクター(AI・PDF・SVG)で渡すのが安全です。どんな大きさでも輪郭が崩れません。',
|
|
309
|
+
unitNote: (dpi) => `換算は ${fmt(dpi, 0)}dpi で行っています。`,
|
|
310
|
+
},
|
|
311
|
+
en: {
|
|
312
|
+
badMm: 'Enter the finished size in millimetres (e.g. 210 × 297).',
|
|
313
|
+
badDpi: 'Enter a resolution between 1 and 4800 dpi.',
|
|
314
|
+
badBleed: 'Enter a bleed between 0 and 100 mm.',
|
|
315
|
+
badPx: 'Enter the pixel size of the file you have (e.g. 4000 × 3000).',
|
|
316
|
+
papers: {
|
|
317
|
+
A0: 'A0 — 841 × 1189 mm', A1: 'A1 — 594 × 841 mm', A2: 'A2 — 420 × 594 mm',
|
|
318
|
+
A3: 'A3 — 297 × 420 mm', A4: 'A4 — 210 × 297 mm', A5: 'A5 — 148 × 210 mm',
|
|
319
|
+
A6: 'A6 — 105 × 148 mm', B1: 'B1 (JIS) — 728 × 1030 mm', B2: 'B2 (JIS) — 515 × 728 mm',
|
|
320
|
+
B3: 'B3 (JIS) — 364 × 515 mm', B4: 'B4 (JIS) — 257 × 364 mm', B5: 'B5 (JIS) — 182 × 257 mm',
|
|
321
|
+
B6: 'B6 (JIS) — 128 × 182 mm',
|
|
322
|
+
MEISHI: 'Business card, Japan — 91 × 55 mm', MEISHI_SQ: 'Square card — 60 × 60 mm',
|
|
323
|
+
US_CARD: 'Business card, US — 88.9 × 50.8 mm', CD: 'CD sleeve — 121 × 121 mm',
|
|
324
|
+
HAGAKI: 'Postcard, Japan — 100 × 148 mm', OFUKU: 'Reply-paid postcard — 200 × 148 mm',
|
|
325
|
+
PHOTO_L: 'Photo L — 89 × 127 mm', PHOTO_2L: 'Photo 2L — 127 × 178 mm',
|
|
326
|
+
PHOTO_KG: 'Photo KG / 4×6 — 102 × 152 mm',
|
|
327
|
+
NAGA3: 'Envelope Naga 3 — 235 × 120 mm', YOKO_NOBORI: 'Banner flag — 600 × 1800 mm',
|
|
328
|
+
TICKET: 'Ticket / bookmark — 180 × 55 mm',
|
|
329
|
+
LETTER: 'US Letter — 215.9 × 279.4 mm', LEGAL: 'US Legal — 215.9 × 355.6 mm',
|
|
330
|
+
TABLOID: 'Tabloid / Ledger — 279.4 × 431.8 mm',
|
|
331
|
+
},
|
|
332
|
+
paperShort: {
|
|
333
|
+
A0: 'A0', A1: 'A1', A2: 'A2', A3: 'A3', A4: 'A4', A5: 'A5', A6: 'A6',
|
|
334
|
+
B1: 'B1', B2: 'B2', B3: 'B3', B4: 'B4', B5: 'B5', B6: 'B6',
|
|
335
|
+
MEISHI: 'Business card', MEISHI_SQ: 'Square card', US_CARD: 'US card', CD: 'CD sleeve',
|
|
336
|
+
HAGAKI: 'Postcard', OFUKU: 'Reply postcard', PHOTO_L: 'Photo L', PHOTO_2L: 'Photo 2L',
|
|
337
|
+
PHOTO_KG: 'Photo KG', NAGA3: 'Envelope', YOKO_NOBORI: 'Banner', TICKET: 'Ticket',
|
|
338
|
+
LETTER: 'Letter', LEGAL: 'Legal', TABLOID: 'Tabloid',
|
|
339
|
+
},
|
|
340
|
+
custom: 'Custom size (mm)',
|
|
341
|
+
orient: { portrait: 'Portrait', landscape: 'Landscape' },
|
|
342
|
+
grades: { best: 'Plenty', ok: 'Fine', fair: 'Depends', ng: 'Too low' },
|
|
343
|
+
gradeNote: {
|
|
344
|
+
best: 'at or above the 350 dpi commercial standard',
|
|
345
|
+
ok: '300 dpi — fine for almost any press job',
|
|
346
|
+
fair: 'below 300 dpi; acceptable for large format viewed from a distance',
|
|
347
|
+
ng: 'below 200 dpi — visibly soft in print',
|
|
348
|
+
},
|
|
349
|
+
memoTitle: 'Artwork specification',
|
|
350
|
+
memoPaper: 'Paper', memoRes: 'Resolution', memoTrim: 'Trim size',
|
|
351
|
+
memoBleed: 'Bleed', memoFull: 'With bleed', memoData: 'Uncompressed size',
|
|
352
|
+
memoNone: 'none',
|
|
353
|
+
previewTrim: 'trim', previewBleed: 'bleed', previewSafe: 'safe area',
|
|
354
|
+
tableHead: ['Paper', 'Size (mm)', 'Trim (px)', 'With bleed (px)'],
|
|
355
|
+
revHead: ['Paper', 'Effective dpi', 'Verdict'],
|
|
356
|
+
fmtLabels: { text: 'Plain text', md: 'Markdown table', csv: 'CSV' },
|
|
357
|
+
statTrim: 'Trim size (px)', statFull: 'With bleed (px)', statMm: 'Finished size',
|
|
358
|
+
statData: 'Uncompressed', statPrint: 'Print size', statDpi: 'Effective dpi',
|
|
359
|
+
statMax: 'Max at 350 dpi', statMp: 'Megapixels',
|
|
360
|
+
unitsHead: ['Unit', 'Value'],
|
|
361
|
+
units: { mm: 'Millimetres', cm: 'Centimetres', inch: 'Inches', px: 'Pixels', pt: 'Points (1/72 in)', q: 'Q (0.25 mm)' },
|
|
362
|
+
noteStandard: (dpi) => `${fmt(dpi, 0)} dpi is the usual resolution for commercial offset and on-demand printing in Japan; 300 dpi is the international norm. Either is safe for a job read in the hand.`,
|
|
363
|
+
noteLow: (dpi) => `${fmt(dpi, 0)} dpi is below the 300 dpi most printers ask for. It is fine for a poster or banner read from a couple of metres away, but text and fine detail will look soft in the hand.`,
|
|
364
|
+
noteVeryLow: (dpi) => `${fmt(dpi, 0)} dpi is a screen resolution. Printed at this size the pixels themselves become visible — multiply the pixel count by about ${fmt(350 / dpi, 1)} to reach 350 dpi.`,
|
|
365
|
+
noteHigh: (dpi) => `${fmt(dpi, 0)} dpi only pays off for line art, barcodes and small type set in a single colour. For photographs anything past 400 dpi adds file size without adding detail, because the press screen cannot resolve it.`,
|
|
366
|
+
noteBleed: (mm) => `Bleed is ${fmt(mm)} mm on every side, so the artwork must extend ${fmt(mm)} mm past the trim line on all four edges. That is what the ${fmt(mm * 2)} mm difference between the two pixel figures is.`,
|
|
367
|
+
noteNoBleed: 'No bleed. If any colour or image touches the edge of the paper, add 3 mm — otherwise a white sliver shows up wherever the guillotine drifts.',
|
|
368
|
+
noteSafe: (mm) => `Keep text and logos at least ${fmt(mm)} mm inside the trim line as well (the dotted box in the preview). Cutting is accurate to about a millimetre, and a page right against the edge looks cramped.`,
|
|
369
|
+
noteRound: (exact, px) => `The exact figure is ${exact} px, rounded up to ${px} px. Always round up: a pixel short leaves a hairline of white along the edge.`,
|
|
370
|
+
noteData: (rgb, cmyk) => `A flattened 8-bit file at this size is about ${rgb} in RGB and ${cmyk} in CMYK before compression. Layers and effects multiply that, so allow several times the figure while working.`,
|
|
371
|
+
notePsd: (side) => `One side is ${group(side)} px, past the 30,000 px limit of the PSD format — Photoshop will ask you to save as PSB. For a piece this large, work at 150-200 dpi instead: it is read from metres away.`,
|
|
372
|
+
noteBig: (mp) => `${fmt(mp, 0)} megapixels is a heavy file to edit. For large-format work the trade is normally resolution, not size: halving the dpi quarters the pixel count.`,
|
|
373
|
+
noteCmyk: 'Send CMYK unless the printer says otherwise. Converting RGB at the press flattens vivid blues and greens, and you will not see that until the proof.',
|
|
374
|
+
revExact: (mm, dpi) => `${mm} at ${fmt(dpi, 0)} dpi.`,
|
|
375
|
+
revMax: (dpi, w, h) => `At ${fmt(dpi, 0)} dpi this file prints at up to ${w} × ${h} mm.`,
|
|
376
|
+
revFits: (paper, dpi) => `Large enough for ${paper} at ${fmt(dpi, 0)} dpi.`,
|
|
377
|
+
revShort: (paper, dpi, need) => `${paper} would come out at ${fmt(dpi, 0)} dpi; it needs ${need} to reach 350 dpi.`,
|
|
378
|
+
revUpscale: 'Enlarging a file in Photoshop does not add detail — it only invents pixels. Rescan or reshoot instead when the effective dpi is short.',
|
|
379
|
+
revVector: 'Logos and type are better sent as vector (AI, PDF or SVG): they have no resolution at all and stay sharp at any size.',
|
|
380
|
+
unitNote: (dpi) => `Conversions use ${fmt(dpi, 0)} dpi.`,
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
// 用紙の分類(site の <optgroup> と同じ並び・名前)
|
|
386
|
+
export const DPI_GROUP_ORDER = ['a', 'b', 'card', 'post', 'etc', 'us'];
|
|
387
|
+
const GROUP_LABEL = {
|
|
388
|
+
ja: { a: 'A判', b: 'B判(JIS)', card: '名刺・カード', post: 'はがき・写真', etc: 'その他', us: '米国規格' },
|
|
389
|
+
en: { a: 'A series', b: 'B series (JIS)', card: 'Cards', post: 'Postcards & photos', etc: 'Other', us: 'US sizes' },
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// 安全な範囲(仕上がり線から内側へ)。site の SAFE_MM と同じ
|
|
393
|
+
const SAFE_MM = 3;
|
|
394
|
+
export const DPI_UNITS = ['mm', 'cm', 'inch', 'px', 'pt', 'q'];
|
|
395
|
+
export const DPI_TABLE_FORMATS = ['text', 'md', 'csv'];
|
|
396
|
+
export const DPI_MODES = ['size', 'reverse', 'table', 'units', 'papers'];
|
|
397
|
+
|
|
398
|
+
export class DpiToolError extends Error {}
|
|
399
|
+
|
|
400
|
+
/* ---- site の画面ヘルパー(mmLabel / mmLabelRound / paren)を lang 引数つきで ---- */
|
|
401
|
+
const mmLabel = (w, h) => fmt(w, 1) + ' × ' + fmt(h, 1) + ' mm';
|
|
402
|
+
const mmLabelRound = (w, h) => fmt(w, 0) + ' × ' + fmt(h, 0) + ' mm';
|
|
403
|
+
const paren = (lang, name, inner) => (lang === 'en' ? name + ' (' + inner + ')' : name + '(' + inner + ')');
|
|
404
|
+
const note = (code, level, message) => ({ code, level, message });
|
|
405
|
+
|
|
406
|
+
/** site の buildTableText と同じ(EN の判定を lang 引数に置き換えただけ) */
|
|
407
|
+
export function dpiTableText(rows, f, dpi, bleed, lang) {
|
|
408
|
+
const T = DPI_TEXT[lang];
|
|
409
|
+
const EN = lang === 'en';
|
|
410
|
+
const head = T.tableHead;
|
|
411
|
+
if (f === 'md') {
|
|
412
|
+
return [
|
|
413
|
+
`| ${head[0]} | ${head[1]} | ${head[2]} | ${head[3]} |`,
|
|
414
|
+
'| --- | ---: | ---: | ---: |',
|
|
415
|
+
...rows.map((r) => `| ${T.paperShort[r.key]} | ${fmt(r.widthMm, 1)} × ${fmt(r.heightMm, 1)} | ${r.trimWidth} × ${r.trimHeight} | ${r.width} × ${r.height} |`),
|
|
416
|
+
].join('\n');
|
|
417
|
+
}
|
|
418
|
+
if (f === 'csv') {
|
|
419
|
+
return ['paper,width_mm,height_mm,trim_width_px,trim_height_px,bleed_width_px,bleed_height_px,dpi,bleed_mm',
|
|
420
|
+
...rows.map((r) => [T.paperShort[r.key], fmt(r.widthMm, 1), fmt(r.heightMm, 1), r.trimWidth, r.trimHeight, r.width, r.height, fmt(dpi, 0), fmt(bleed)].join(','))].join('\n');
|
|
421
|
+
}
|
|
422
|
+
return [
|
|
423
|
+
`${fmt(dpi, 0)} dpi / ${T.memoBleed} ${bleed > 0 ? fmt(bleed) + ' mm' : T.memoNone}`,
|
|
424
|
+
...rows.map((r) => `${T.paperShort[r.key]}: ${group(r.trimWidth)} × ${group(r.trimHeight)} px${EN ? ' (' : '('}${T.memoFull} ${group(r.width)} × ${group(r.height)} px${EN ? ')' : ')'}`),
|
|
425
|
+
].join('\n');
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** 用紙の指定(paper / widthMm・heightMm / orientation)を寸法へ。site の currentPaper と同じ判定 */
|
|
429
|
+
function resolvePaper(opts, T, lang) {
|
|
430
|
+
const hasMm = opts.widthMm !== undefined || opts.heightMm !== undefined;
|
|
431
|
+
if (hasMm && opts.paper !== undefined && String(opts.paper).toLowerCase() !== 'custom') {
|
|
432
|
+
throw new DpiToolError('paper と widthMm/heightMm は同時に渡せません');
|
|
433
|
+
}
|
|
434
|
+
if (hasMm || String(opts.paper || '').toLowerCase() === 'custom') {
|
|
435
|
+
const w = dpNum(opts.widthMm);
|
|
436
|
+
const h = dpNum(opts.heightMm);
|
|
437
|
+
if (!isMm(w) || !isMm(h)) throw new DpiToolError(T.badMm);
|
|
438
|
+
return { key: null, w, h, label: mmLabel(w, h), orientation: null };
|
|
439
|
+
}
|
|
440
|
+
const p = paperByKey(opts.paper === undefined ? 'A4' : opts.paper);
|
|
441
|
+
if (!p) throw new DpiToolError(`未対応の用紙: ${opts.paper}(mode="papers" で一覧を返す。自由なサイズは widthMm / heightMm)`);
|
|
442
|
+
let orientation = opts.orientation;
|
|
443
|
+
if (orientation === undefined) orientation = p.land ? 'landscape' : 'portrait';
|
|
444
|
+
if (orientation !== 'portrait' && orientation !== 'landscape') throw new DpiToolError(`orientation は portrait か landscape: ${opts.orientation}`);
|
|
445
|
+
const s = paperSize(p, orientation);
|
|
446
|
+
return { key: p.key, w: s.w, h: s.h, label: paren(lang, T.paperShort[p.key], mmLabel(s.w, s.h)), orientation };
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function readDpi(v, T) {
|
|
450
|
+
const dpi = v === undefined ? 350 : dpNum(v);
|
|
451
|
+
if (!isDpi(dpi)) throw new DpiToolError(T.badDpi);
|
|
452
|
+
return dpi;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function readBleed(v, T) {
|
|
456
|
+
const bleed = v === undefined ? 3 : dpNum(v);
|
|
457
|
+
if (!isBleed(bleed)) throw new DpiToolError(T.badBleed);
|
|
458
|
+
return bleed;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** タブ1(必要なピクセル数)。site の renderCalc が画面に書く値と指摘を返す */
|
|
462
|
+
function sizeMode(opts, T, lang) {
|
|
463
|
+
const paper = resolvePaper(opts, T, lang);
|
|
464
|
+
const dpi = readDpi(opts.dpi, T);
|
|
465
|
+
const bleed = readBleed(opts.bleedMm, T);
|
|
466
|
+
const r = dpiCalc({ widthMm: paper.w, heightMm: paper.h, dpi, bleedMm: bleed });
|
|
467
|
+
const memo = [
|
|
468
|
+
'【' + T.memoTitle + '】',
|
|
469
|
+
T.memoPaper + ': ' + paper.label,
|
|
470
|
+
T.memoRes + ': ' + fmt(dpi, 0) + ' dpi',
|
|
471
|
+
T.memoTrim + ': ' + group(r.trimWidth) + ' × ' + group(r.trimHeight) + ' px',
|
|
472
|
+
T.memoBleed + ': ' + (bleed > 0 ? fmt(bleed) + ' mm' : T.memoNone),
|
|
473
|
+
T.memoFull + ': ' + group(r.width) + ' × ' + group(r.height) + ' px',
|
|
474
|
+
T.memoData + ': RGB ' + bytes(r.bytesRgb) + ' / CMYK ' + bytes(r.bytesCmyk),
|
|
475
|
+
].join('\n');
|
|
476
|
+
const notes = [];
|
|
477
|
+
if (dpi >= 300 && dpi <= 400) notes.push(note('STANDARD', 'ok', T.noteStandard(dpi)));
|
|
478
|
+
else if (dpi > 400) notes.push(note('HIGH', 'info', T.noteHigh(dpi)));
|
|
479
|
+
else if (dpi >= 150) notes.push(note('LOW', 'warn', T.noteLow(dpi)));
|
|
480
|
+
else notes.push(note('VERY_LOW', 'warn', T.noteVeryLow(dpi)));
|
|
481
|
+
if (bleed > 0) notes.push(note('BLEED', 'info', T.noteBleed(bleed)));
|
|
482
|
+
else notes.push(note('NO_BLEED', 'warn', T.noteNoBleed));
|
|
483
|
+
notes.push(note('SAFE_AREA', 'info', T.noteSafe(SAFE_MM)));
|
|
484
|
+
if (Math.abs(r.exactWidth - r.trimWidth) > 1e-6 || Math.abs(r.exactHeight - r.trimHeight) > 1e-6) {
|
|
485
|
+
notes.push(note('ROUNDED_UP', 'info', T.noteRound(
|
|
486
|
+
fmt(r.exactWidth, 1) + ' × ' + fmt(r.exactHeight, 1),
|
|
487
|
+
group(r.trimWidth) + ' × ' + group(r.trimHeight),
|
|
488
|
+
)));
|
|
489
|
+
}
|
|
490
|
+
notes.push(note('DATA_SIZE', 'info', T.noteData(bytes(r.bytesRgb), bytes(r.bytesCmyk))));
|
|
491
|
+
const side = Math.max(r.width, r.height);
|
|
492
|
+
if (side > PSD_LIMIT) notes.push(note('PSB_REQUIRED', 'warn', T.notePsd(side)));
|
|
493
|
+
else if (r.megapixels > 200) notes.push(note('HEAVY', 'info', T.noteBig(r.megapixels)));
|
|
494
|
+
notes.push(note('CMYK', 'info', T.noteCmyk));
|
|
495
|
+
return {
|
|
496
|
+
mode: 'size',
|
|
497
|
+
paper: paper.key || 'custom',
|
|
498
|
+
paper_label: paper.label,
|
|
499
|
+
...(paper.orientation ? { orientation: paper.orientation } : {}),
|
|
500
|
+
...r,
|
|
501
|
+
safe_mm: SAFE_MM,
|
|
502
|
+
display: {
|
|
503
|
+
trim: group(r.trimWidth) + ' × ' + group(r.trimHeight) + ' px',
|
|
504
|
+
full: group(r.width) + ' × ' + group(r.height) + ' px',
|
|
505
|
+
size: mmLabel(r.widthMm, r.heightMm),
|
|
506
|
+
data_rgb: bytes(r.bytesRgb),
|
|
507
|
+
data_cmyk: bytes(r.bytesCmyk),
|
|
508
|
+
},
|
|
509
|
+
memo,
|
|
510
|
+
notes,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** タブ2(逆算)。site の renderReverse と同じ。用紙は portrait の寸法を渡し、dpiFor が有利な向きを選ぶ */
|
|
515
|
+
function reverseMode(opts, T, lang) {
|
|
516
|
+
const w = dpNum(opts.width);
|
|
517
|
+
const h = dpNum(opts.height);
|
|
518
|
+
if (!isPx(w) || !isPx(h)) throw new DpiToolError(T.badPx);
|
|
519
|
+
const dpi = readDpi(opts.dpi, T);
|
|
520
|
+
const bleed = readBleed(opts.bleedMm, T);
|
|
521
|
+
const p = paperByKey(opts.paper === undefined ? 'A4' : opts.paper);
|
|
522
|
+
if (!p) throw new DpiToolError(`未対応の用紙: ${opts.paper}(mode="papers" で一覧を返す)`);
|
|
523
|
+
const r = dpiReverse({ width: w, height: h, dpi });
|
|
524
|
+
const at350 = dpiReverse({ width: w, height: h, dpi: 350 });
|
|
525
|
+
const port = paperSize(p, 'portrait');
|
|
526
|
+
const eff = dpiFor({ width: w, height: h, widthMm: port.w, heightMm: port.h, bleedMm: bleed });
|
|
527
|
+
const grade = dpiGrade(eff.dpi);
|
|
528
|
+
const notes = [];
|
|
529
|
+
notes.push(note('EXACT', 'info', T.revExact(mmLabel(r.widthMm, r.heightMm), r.dpi)));
|
|
530
|
+
notes.push(note('MAX_AT_350', 'info', T.revMax(350, fmt(at350.widthMm, 1), fmt(at350.heightMm, 1))));
|
|
531
|
+
const need = dpiCalc({ widthMm: eff.widthMm - bleed * 2, heightMm: eff.heightMm - bleed * 2, dpi: 350, bleedMm: bleed });
|
|
532
|
+
const label = T.paperShort[p.key];
|
|
533
|
+
if (eff.dpi >= 350) notes.push(note('FITS', 'ok', T.revFits(label, eff.dpi)));
|
|
534
|
+
else {
|
|
535
|
+
notes.push(note('SHORT', 'warn', T.revShort(label, eff.dpi, need ? group(need.width) + ' × ' + group(need.height) + ' px' : '')));
|
|
536
|
+
notes.push(note('NO_UPSCALE', 'info', T.revUpscale));
|
|
537
|
+
}
|
|
538
|
+
notes.push(note('VECTOR', 'info', T.revVector));
|
|
539
|
+
const papers = [];
|
|
540
|
+
for (const key of TABLE_KEYS) {
|
|
541
|
+
const paper = paperByKey(key);
|
|
542
|
+
const size = paperSize(paper, 'portrait');
|
|
543
|
+
const e = dpiFor({ width: w, height: h, widthMm: size.w, heightMm: size.h, bleedMm: bleed });
|
|
544
|
+
if (!e) continue;
|
|
545
|
+
const g = dpiGrade(e.dpi);
|
|
546
|
+
papers.push({ paper: key, label: paren(lang, T.paperShort[key], mmLabel(size.w, size.h)), dpi: e.dpi, display: fmt(e.dpi, 0) + ' dpi', grade: g, grade_label: T.grades[g], rotated: e.rotated });
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
mode: 'reverse',
|
|
550
|
+
...r,
|
|
551
|
+
bleedMm: bleed,
|
|
552
|
+
print_size: mmLabelRound(r.widthMm, r.heightMm),
|
|
553
|
+
max_at_350: { widthMm: at350.widthMm, heightMm: at350.heightMm, display: mmLabelRound(at350.widthMm, at350.heightMm) },
|
|
554
|
+
effective: {
|
|
555
|
+
paper: p.key,
|
|
556
|
+
label: T.paperShort[p.key],
|
|
557
|
+
dpi: eff.dpi,
|
|
558
|
+
display: fmt(eff.dpi, 0) + ' dpi',
|
|
559
|
+
grade,
|
|
560
|
+
grade_label: T.grades[grade],
|
|
561
|
+
grade_note: T.gradeNote[grade],
|
|
562
|
+
rotated: eff.rotated,
|
|
563
|
+
paper_with_bleed_mm: { width: eff.widthMm, height: eff.heightMm },
|
|
564
|
+
...(eff.dpi < 350 && need ? { needed_at_350: { width: need.width, height: need.height } } : {}),
|
|
565
|
+
},
|
|
566
|
+
papers,
|
|
567
|
+
notes,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** タブ3(早見表) */
|
|
572
|
+
function tableMode(opts, T, lang) {
|
|
573
|
+
const dpi = readDpi(opts.dpi, T);
|
|
574
|
+
const bleed = readBleed(opts.bleedMm, T);
|
|
575
|
+
const format = opts.format === undefined ? 'text' : opts.format;
|
|
576
|
+
if (DPI_TABLE_FORMATS.indexOf(format) === -1) throw new DpiToolError(`format は text / md / csv: ${opts.format}`);
|
|
577
|
+
let keys = TABLE_KEYS;
|
|
578
|
+
if (opts.papers !== undefined) {
|
|
579
|
+
if (!Array.isArray(opts.papers) || !opts.papers.length) throw new DpiToolError('papers は1件以上の用紙キーの配列で渡してください');
|
|
580
|
+
keys = opts.papers.map((k) => {
|
|
581
|
+
const p = paperByKey(k);
|
|
582
|
+
if (!p) throw new DpiToolError(`未対応の用紙: ${k}`);
|
|
583
|
+
return p.key;
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
const rows = dpiTable(keys, dpi, bleed);
|
|
587
|
+
return {
|
|
588
|
+
mode: 'table',
|
|
589
|
+
dpi,
|
|
590
|
+
bleedMm: bleed,
|
|
591
|
+
format,
|
|
592
|
+
rows: rows.map((r) => ({ paper: r.key, label: T.paperShort[r.key], widthMm: r.widthMm, heightMm: r.heightMm, trimWidth: r.trimWidth, trimHeight: r.trimHeight, width: r.width, height: r.height })),
|
|
593
|
+
text: dpiTableText(rows, format, dpi, bleed, lang),
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** タブ4(単位換算)。site の renderUnits と同じ(いったん mm に揃えてから各単位へ) */
|
|
598
|
+
function unitsMode(opts, T) {
|
|
599
|
+
const v = dpNum(opts.value);
|
|
600
|
+
if (!Number.isFinite(v)) throw new DpiToolError(`value は数値で渡してください: ${opts.value}`);
|
|
601
|
+
const from = opts.from === undefined ? 'mm' : opts.from;
|
|
602
|
+
if (DPI_UNITS.indexOf(from) === -1) throw new DpiToolError(`from は ${DPI_UNITS.join(' / ')} のどれか: ${opts.from}`);
|
|
603
|
+
const dpi = readDpi(opts.dpi, T);
|
|
604
|
+
let mm;
|
|
605
|
+
if (from === 'mm') mm = v;
|
|
606
|
+
else if (from === 'cm') mm = v * 10;
|
|
607
|
+
else if (from === 'inch') mm = v * MM_PER_INCH;
|
|
608
|
+
else if (from === 'pt') mm = v / PT_PER_INCH * MM_PER_INCH;
|
|
609
|
+
else if (from === 'q') mm = v * 0.25;
|
|
610
|
+
else mm = pxToMm(v, dpi);
|
|
611
|
+
const values = { mm, cm: mm / 10, inch: mm / MM_PER_INCH, px: mmToPx(mm, dpi), pt: mm / MM_PER_INCH * PT_PER_INCH, q: mm / 0.25 };
|
|
612
|
+
const display = {
|
|
613
|
+
mm: fmt(mm, 3) + ' mm',
|
|
614
|
+
cm: fmt(mm / 10, 3) + ' cm',
|
|
615
|
+
inch: fmt(mm / MM_PER_INCH, 4) + ' in',
|
|
616
|
+
px: fmt(mmToPx(mm, dpi), 1) + ' px',
|
|
617
|
+
pt: fmt(mm / MM_PER_INCH * PT_PER_INCH, 2) + ' pt',
|
|
618
|
+
q: fmt(mm / 0.25, 2) + ' Q',
|
|
619
|
+
};
|
|
620
|
+
return { mode: 'units', value: v, from, dpi, values, display, labels: T.units, note: T.unitNote(dpi) };
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function papersMode(T, lang) {
|
|
624
|
+
return {
|
|
625
|
+
mode: 'papers',
|
|
626
|
+
groups: DPI_GROUP_ORDER.map((g) => ({
|
|
627
|
+
group: g,
|
|
628
|
+
label: GROUP_LABEL[lang][g],
|
|
629
|
+
papers: PAPERS.filter((p) => p.group === g).map((p) => ({
|
|
630
|
+
key: p.key, label: T.papers[p.key], short: T.paperShort[p.key], widthMm: p.w, heightMm: p.h,
|
|
631
|
+
orientation: p.land ? 'landscape' : 'portrait',
|
|
632
|
+
})),
|
|
633
|
+
})),
|
|
634
|
+
table_keys: TABLE_KEYS,
|
|
635
|
+
dpi_presets: DPI_PRESETS,
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 印刷サイズ・DPI計算。
|
|
641
|
+
* mode: size(用紙×dpi→必要px)/ reverse(px→印刷できる大きさ・実効dpi)/ table(早見表)/ units(単位換算)/ papers(用紙一覧)。
|
|
642
|
+
* 省略時は width/height があれば reverse、value があれば units、それ以外は size。
|
|
643
|
+
*/
|
|
644
|
+
export async function dpiCalcTool(opts = {}) {
|
|
645
|
+
const lang = opts.lang || 'ja';
|
|
646
|
+
if (lang !== 'ja' && lang !== 'en') throw new DpiToolError(`lang は ja か en: ${opts.lang}`);
|
|
647
|
+
const T = DPI_TEXT[lang];
|
|
648
|
+
let mode = opts.mode;
|
|
649
|
+
if (mode === undefined) {
|
|
650
|
+
if (opts.width !== undefined || opts.height !== undefined) mode = 'reverse';
|
|
651
|
+
else if (opts.value !== undefined) mode = 'units';
|
|
652
|
+
else mode = 'size';
|
|
653
|
+
}
|
|
654
|
+
if (DPI_MODES.indexOf(mode) === -1) throw new DpiToolError(`mode は ${DPI_MODES.join(' / ')} のどれか: ${opts.mode}`);
|
|
655
|
+
if (mode === 'size') return sizeMode(opts, T, lang);
|
|
656
|
+
if (mode === 'reverse') return reverseMode(opts, T, lang);
|
|
657
|
+
if (mode === 'table') return tableMode(opts, T, lang);
|
|
658
|
+
if (mode === 'units') return unitsMode(opts, T);
|
|
659
|
+
return papersMode(T, lang);
|
|
660
|
+
}
|