Commit ·
39e75d6
1
Parent(s): e219ae1
PDF太字化と日付ブロックの月別可変化
Browse files- PDF: 日本語太字フォント BIZ UDGothic Bold (OFL) を同梱し最優先で使用
(元シートが全セル太字のため。ライセンス文OFL.txtも同梱、Git LFS管理)
- 日付ブロックを期間日数(月により13〜16日)に合わせて可変化し、空白ブロックを作らない
- Excel: 余りブロックを列ごと削除(マージ・列幅も追従)、AY/AZ式・氏名列位置を再計算
- PDF: ブロック数=期間日数で描画し横幅いっぱいに配分
- テンプレート外に残っていた作業メモ等のセルをクリア
- PyInstaller spec に export/templates・export/fonts を同梱(デスクトップ版対応)
メモ2のデータ源は #30 で別途実装予定
- .gitattributes +1 -0
- export/excel_exporter.py +74 -37
- export/fonts/BIZUDGothic-Bold.ttf +3 -0
- export/fonts/OFL.txt +93 -0
- export/pdf_exporter.py +16 -10
- shift_tool.spec +3 -0
.gitattributes
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
export/templates/*.xlsx filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 1 |
export/templates/*.xlsx filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
export/fonts/*.ttf filter=lfs diff=lfs merge=lfs -text
|
export/excel_exporter.py
CHANGED
|
@@ -15,6 +15,7 @@ export/templates/SDU_shift_template.xlsx を読み込み、生成済みシフト
|
|
| 15 |
AX列 : 右側氏名 / AY列: 勤務時間合計式 / AZ列: 人件費式(時給×時間)
|
| 16 |
|
| 17 |
従業員数が枠数を超える場合はグループ末尾に行を挿入する(行高・マージも追従)。
|
|
|
|
| 18 |
"""
|
| 19 |
from __future__ import annotations
|
| 20 |
from copy import copy
|
|
@@ -33,13 +34,12 @@ TEMPLATE_PATH = Path(__file__).parent / "templates" / "SDU_shift_template.xlsx"
|
|
| 33 |
DAY_JP = ["月", "火", "水", "木", "金", "土", "日"]
|
| 34 |
|
| 35 |
# ── テンプレートのレイアウト定数 ─────────────────────────────────────────
|
| 36 |
-
N_BLOCKS = 16 # 日付ブロック数(B〜AW列)
|
| 37 |
COLS_PER_DAY = 3 # 1日 = 3列(開始 / 区切り・備考 / 終了)
|
| 38 |
C_DATA = 2 # データ先頭列(B)
|
| 39 |
C_NAME_L = 1 # 氏名列(左、A)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
C_WAGE = 52 # 人件費式(AZ)
|
| 43 |
|
| 44 |
R_DATE1, R_DOW1 = 1, 2 # 1ブロック目: 日付・曜日
|
| 45 |
R_MEMO1, R_MEMO2 = 3, 6 # メモ1(3-5行マージ)・メモ2
|
|
@@ -186,7 +186,7 @@ def _num_or_text(v: str):
|
|
| 186 |
return v
|
| 187 |
|
| 188 |
|
| 189 |
-
def _insert_rows_keep_layout(ws, idx: int, amount: int):
|
| 190 |
"""idx 行の直前に amount 行挿入する。
|
| 191 |
openpyxl の insert_rows はマージセル・行高を追従させないため手動でずらし、
|
| 192 |
挿入行のスタイル・行高は直前の行(同グループの枠)からコピーする。"""
|
|
@@ -211,19 +211,48 @@ def _insert_rows_keep_layout(ws, idx: int, amount: int):
|
|
| 211 |
for r in range(idx, idx + amount):
|
| 212 |
if donor_h:
|
| 213 |
ws.row_dimensions[r].height = donor_h
|
| 214 |
-
for c in range(1,
|
| 215 |
ws.cell(r, c)._style = copy(ws.cell(donor, c)._style)
|
| 216 |
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
def _block_col(i: int) -> int:
|
| 219 |
"""日付ブロック i (0始まり) の先頭列"""
|
| 220 |
return C_DATA + i * COLS_PER_DAY
|
| 221 |
|
| 222 |
|
| 223 |
-
def _hours_formula(row: int) -> str:
|
| 224 |
-
"""=(D9-B9)+(G9-E9)+...
|
| 225 |
terms = []
|
| 226 |
-
for i in range(
|
| 227 |
c = _block_col(i)
|
| 228 |
terms.append(f"({get_column_letter(c + 2)}{row}-{get_column_letter(c)}{row})")
|
| 229 |
return "=" + "+".join(terms)
|
|
@@ -251,6 +280,17 @@ def export_excel(
|
|
| 251 |
n = len(dates)
|
| 252 |
holidays = holiday_set(dates)
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
# ── 従業員をテンプレートの4グループに分類 ─────────────────────────
|
| 255 |
# output_position 優先、未設定なら primary_position で判断
|
| 256 |
def _out_pos(e):
|
|
@@ -271,10 +311,10 @@ def export_excel(
|
|
| 271 |
k_pt_extra = max(0, len(k_pt) - K_PT_SLOTS)
|
| 272 |
h_ft_extra = max(0, len(h_ft) - H_FT_SLOTS)
|
| 273 |
h_pt_extra = max(0, len(h_pt) - H_PT_SLOTS)
|
| 274 |
-
_insert_rows_keep_layout(ws, H_PT_START + H_PT_SLOTS, h_pt_extra)
|
| 275 |
-
_insert_rows_keep_layout(ws, H_FT_START + H_FT_SLOTS, h_ft_extra)
|
| 276 |
-
_insert_rows_keep_layout(ws, K_PT_START + K_PT_SLOTS, k_pt_extra)
|
| 277 |
-
_insert_rows_keep_layout(ws, K_FT_START + K_FT_SLOTS, k_ft_extra)
|
| 278 |
|
| 279 |
# 挿入後の行位置
|
| 280 |
ko = k_ft_extra + k_pt_extra
|
|
@@ -291,31 +331,26 @@ def export_excel(
|
|
| 291 |
title = f"{start_d.month}月 {half}"
|
| 292 |
for r in (R_DATE1, r_date2, r_date3):
|
| 293 |
ws.cell(r, C_NAME_L).value = title
|
| 294 |
-
ws.cell(r,
|
| 295 |
ws.title = (f"{start_d.month:02d}{start_d.day:02d}_{end_d.month:02d}{end_d.day:02d}"
|
| 296 |
+ ("(確定)" if period.status == "confirmed" else ""))
|
| 297 |
|
| 298 |
# ── ヘッダー・フッター(日付/曜日/メモ/朝食見込/夜予約)────────────
|
| 299 |
-
for i in
|
| 300 |
col = _block_col(i)
|
| 301 |
cl = get_column_letter(col)
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
elif d.weekday() == 6 or ds in holidays:
|
| 314 |
-
day_fill = FILL_SUN
|
| 315 |
-
else:
|
| 316 |
-
day_fill = FILL_NONE
|
| 317 |
else:
|
| 318 |
-
day_val = dow = note = bf = din = None
|
| 319 |
day_fill = FILL_NONE
|
| 320 |
|
| 321 |
for r in (R_DATE1, r_date2, r_date3):
|
|
@@ -339,17 +374,17 @@ def export_excel(
|
|
| 339 |
r = start_row + j
|
| 340 |
emp = emps[j] if j < len(emps) else None
|
| 341 |
ws.cell(r, C_NAME_L).value = emp.name if emp else None
|
| 342 |
-
ws.cell(r,
|
| 343 |
# 全ブロックをクリア(テンプレートの凡例サンプル・前回値を消す)
|
| 344 |
-
for i in range(
|
| 345 |
col = _block_col(i)
|
| 346 |
for cc in range(col, col + COLS_PER_DAY):
|
| 347 |
cell = ws.cell(r, cc)
|
| 348 |
cell.value = None
|
| 349 |
cell.fill = FILL_NONE
|
| 350 |
if emp is None:
|
| 351 |
-
ws.cell(r,
|
| 352 |
-
ws.cell(r,
|
| 353 |
continue
|
| 354 |
for i, d in enumerate(dates):
|
| 355 |
col = _block_col(i)
|
|
@@ -370,8 +405,10 @@ def export_excel(
|
|
| 370 |
# 社員の休み・指定休は3セル全体を赤塗り
|
| 371 |
for cc in range(col, col + COLS_PER_DAY):
|
| 372 |
ws.cell(r, cc).fill = FILL_FTOFF
|
| 373 |
-
ws.cell(r,
|
| 374 |
-
ws.cell(r,
|
|
|
|
|
|
|
| 375 |
|
| 376 |
_fill_group(K_FT_START, K_FT_SLOTS + k_ft_extra, k_ft)
|
| 377 |
_fill_group(k_pt_row, K_PT_SLOTS + k_pt_extra, k_pt)
|
|
|
|
| 15 |
AX列 : 右側氏名 / AY列: 勤務時間合計式 / AZ列: 人件費式(時給×時間)
|
| 16 |
|
| 17 |
従業員数が枠数を超える場合はグループ末尾に行を挿入する(行高・マージも追従)。
|
| 18 |
+
日付ブロックは期間日数(月によって13〜16日)に合わせて余りを列削除し、空白を作らない。
|
| 19 |
"""
|
| 20 |
from __future__ import annotations
|
| 21 |
from copy import copy
|
|
|
|
| 34 |
DAY_JP = ["月", "火", "水", "木", "金", "土", "日"]
|
| 35 |
|
| 36 |
# ── テンプレートのレイアウト定数 ─────────────────────────────────────────
|
| 37 |
+
N_BLOCKS = 16 # テンプレートの日付ブロック数(B〜AW列)。期間日数に合わせて余りは列削除する
|
| 38 |
COLS_PER_DAY = 3 # 1日 = 3列(開始 / 区切り・備考 / 終了)
|
| 39 |
C_DATA = 2 # データ先頭列(B)
|
| 40 |
C_NAME_L = 1 # 氏名列(左、A)
|
| 41 |
+
NAME_W = 17.63 # 氏名列の幅
|
| 42 |
+
DAY_W = 5.75 # 日付1列の幅
|
|
|
|
| 43 |
|
| 44 |
R_DATE1, R_DOW1 = 1, 2 # 1ブロック目: 日付・曜日
|
| 45 |
R_MEMO1, R_MEMO2 = 3, 6 # メモ1(3-5行マージ)・メモ2
|
|
|
|
| 186 |
return v
|
| 187 |
|
| 188 |
|
| 189 |
+
def _insert_rows_keep_layout(ws, idx: int, amount: int, max_col: int):
|
| 190 |
"""idx 行の直前に amount 行挿入する。
|
| 191 |
openpyxl の insert_rows はマージセル・行高を追従させないため手動でずらし、
|
| 192 |
挿入行のスタイル・行高は直前の行(同グループの枠)からコピーする。"""
|
|
|
|
| 211 |
for r in range(idx, idx + amount):
|
| 212 |
if donor_h:
|
| 213 |
ws.row_dimensions[r].height = donor_h
|
| 214 |
+
for c in range(1, max_col + 1):
|
| 215 |
ws.cell(r, c)._style = copy(ws.cell(donor, c)._style)
|
| 216 |
|
| 217 |
|
| 218 |
+
def _delete_trailing_blocks(ws, n: int):
|
| 219 |
+
"""期間日数 n に合わせて余った日付ブロック列を削除する(空白ブロックを作らない)。
|
| 220 |
+
openpyxl の delete_cols はマージセルを追従させないため手動でずらす。"""
|
| 221 |
+
extra = N_BLOCKS - n
|
| 222 |
+
if extra <= 0:
|
| 223 |
+
return
|
| 224 |
+
first = C_DATA + n * COLS_PER_DAY # 削除開始列
|
| 225 |
+
amount = extra * COLS_PER_DAY
|
| 226 |
+
for rng in list(ws.merged_cells.ranges):
|
| 227 |
+
if rng.min_col >= first + amount:
|
| 228 |
+
# 削除範囲より右(氏名列など)→ 左へシフト
|
| 229 |
+
ws.unmerge_cells(str(rng))
|
| 230 |
+
ws.merge_cells(start_row=rng.min_row, end_row=rng.max_row,
|
| 231 |
+
start_column=rng.min_col - amount,
|
| 232 |
+
end_column=rng.max_col - amount)
|
| 233 |
+
elif rng.min_col >= first:
|
| 234 |
+
# 削除範囲内のブロックマージ → 解除
|
| 235 |
+
ws.unmerge_cells(str(rng))
|
| 236 |
+
ws.delete_cols(first, amount)
|
| 237 |
+
# 列幅を再構築(テンプレートのグループ幅指定は削除に追従しないため)
|
| 238 |
+
for letter in list(ws.column_dimensions.keys()):
|
| 239 |
+
del ws.column_dimensions[letter]
|
| 240 |
+
c_name_r = C_DATA + n * COLS_PER_DAY
|
| 241 |
+
ws.column_dimensions[get_column_letter(C_NAME_L)].width = NAME_W
|
| 242 |
+
for c in range(C_DATA, c_name_r):
|
| 243 |
+
ws.column_dimensions[get_column_letter(c)].width = DAY_W
|
| 244 |
+
ws.column_dimensions[get_column_letter(c_name_r)].width = NAME_W
|
| 245 |
+
|
| 246 |
+
|
| 247 |
def _block_col(i: int) -> int:
|
| 248 |
"""日付ブロック i (0始まり) の先頭列"""
|
| 249 |
return C_DATA + i * COLS_PER_DAY
|
| 250 |
|
| 251 |
|
| 252 |
+
def _hours_formula(row: int, n: int) -> str:
|
| 253 |
+
"""=(D9-B9)+(G9-E9)+... 形式の勤務時間合計式(期間 n 日分)を返す"""
|
| 254 |
terms = []
|
| 255 |
+
for i in range(n):
|
| 256 |
c = _block_col(i)
|
| 257 |
terms.append(f"({get_column_letter(c + 2)}{row}-{get_column_letter(c)}{row})")
|
| 258 |
return "=" + "+".join(terms)
|
|
|
|
| 280 |
n = len(dates)
|
| 281 |
holidays = holiday_set(dates)
|
| 282 |
|
| 283 |
+
# 月の日数(28/30/31日)に合わせて余りブロックを列ごと削除し、空白を作らない
|
| 284 |
+
_delete_trailing_blocks(ws, n)
|
| 285 |
+
c_name_r = C_DATA + n * COLS_PER_DAY # 氏名列(右)
|
| 286 |
+
c_hours = c_name_r + 1 # 勤務時間合計式
|
| 287 |
+
c_wage = c_name_r + 2 # 人件費式
|
| 288 |
+
# 削除で左に寄ってきたテンプレート外の作業メモ等を消す
|
| 289 |
+
for row in ws.iter_rows(min_row=1, max_row=100, min_col=c_wage + 1, max_col=63):
|
| 290 |
+
for cell in row:
|
| 291 |
+
if cell.value is not None:
|
| 292 |
+
cell.value = None
|
| 293 |
+
|
| 294 |
# ── 従業員をテンプレートの4グループに分類 ─────────────────────────
|
| 295 |
# output_position 優先、未設定なら primary_position で判断
|
| 296 |
def _out_pos(e):
|
|
|
|
| 311 |
k_pt_extra = max(0, len(k_pt) - K_PT_SLOTS)
|
| 312 |
h_ft_extra = max(0, len(h_ft) - H_FT_SLOTS)
|
| 313 |
h_pt_extra = max(0, len(h_pt) - H_PT_SLOTS)
|
| 314 |
+
_insert_rows_keep_layout(ws, H_PT_START + H_PT_SLOTS, h_pt_extra, c_wage)
|
| 315 |
+
_insert_rows_keep_layout(ws, H_FT_START + H_FT_SLOTS, h_ft_extra, c_wage)
|
| 316 |
+
_insert_rows_keep_layout(ws, K_PT_START + K_PT_SLOTS, k_pt_extra, c_wage)
|
| 317 |
+
_insert_rows_keep_layout(ws, K_FT_START + K_FT_SLOTS, k_ft_extra, c_wage)
|
| 318 |
|
| 319 |
# 挿入後の行位置
|
| 320 |
ko = k_ft_extra + k_pt_extra
|
|
|
|
| 331 |
title = f"{start_d.month}月 {half}"
|
| 332 |
for r in (R_DATE1, r_date2, r_date3):
|
| 333 |
ws.cell(r, C_NAME_L).value = title
|
| 334 |
+
ws.cell(r, c_name_r).value = title
|
| 335 |
ws.title = (f"{start_d.month:02d}{start_d.day:02d}_{end_d.month:02d}{end_d.day:02d}"
|
| 336 |
+ ("(確定)" if period.status == "confirmed" else ""))
|
| 337 |
|
| 338 |
# ── ヘッダー・フッター(日付/曜日/メモ/朝食見込/夜予約)────────────
|
| 339 |
+
for i, d in enumerate(dates):
|
| 340 |
col = _block_col(i)
|
| 341 |
cl = get_column_letter(col)
|
| 342 |
+
ds = d.isoformat()
|
| 343 |
+
day_val = d.day
|
| 344 |
+
dow = DAY_JP[d.weekday()]
|
| 345 |
+
note = notes.get(ds, "") or None
|
| 346 |
+
res = reserves.get(ds, {})
|
| 347 |
+
bf = res.get("breakfast")
|
| 348 |
+
din = res.get("dinner")
|
| 349 |
+
if d.weekday() == 5:
|
| 350 |
+
day_fill = FILL_SAT
|
| 351 |
+
elif d.weekday() == 6 or ds in holidays:
|
| 352 |
+
day_fill = FILL_SUN
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
else:
|
|
|
|
| 354 |
day_fill = FILL_NONE
|
| 355 |
|
| 356 |
for r in (R_DATE1, r_date2, r_date3):
|
|
|
|
| 374 |
r = start_row + j
|
| 375 |
emp = emps[j] if j < len(emps) else None
|
| 376 |
ws.cell(r, C_NAME_L).value = emp.name if emp else None
|
| 377 |
+
ws.cell(r, c_name_r).value = emp.name if emp else None
|
| 378 |
# 全ブロックをクリア(テンプレートの凡例サンプル・前回値を消す)
|
| 379 |
+
for i in range(n):
|
| 380 |
col = _block_col(i)
|
| 381 |
for cc in range(col, col + COLS_PER_DAY):
|
| 382 |
cell = ws.cell(r, cc)
|
| 383 |
cell.value = None
|
| 384 |
cell.fill = FILL_NONE
|
| 385 |
if emp is None:
|
| 386 |
+
ws.cell(r, c_hours).value = None
|
| 387 |
+
ws.cell(r, c_wage).value = None
|
| 388 |
continue
|
| 389 |
for i, d in enumerate(dates):
|
| 390 |
col = _block_col(i)
|
|
|
|
| 405 |
# 社員の休み・指定休は3セル全体を赤塗り
|
| 406 |
for cc in range(col, col + COLS_PER_DAY):
|
| 407 |
ws.cell(r, cc).fill = FILL_FTOFF
|
| 408 |
+
ws.cell(r, c_hours).value = _hours_formula(r, n)
|
| 409 |
+
ws.cell(r, c_wage).value = (
|
| 410 |
+
f"={get_column_letter(c_hours)}{r}*{emp.hourly_wage}"
|
| 411 |
+
if emp.hourly_wage else None)
|
| 412 |
|
| 413 |
_fill_group(K_FT_START, K_FT_SLOTS + k_ft_extra, k_ft)
|
| 414 |
_fill_group(k_pt_row, K_PT_SLOTS + k_pt_extra, k_pt)
|
export/fonts/BIZUDGothic-Bold.ttf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:98a528b6b638463041968783cc0f63adaf4cdc26f5398afed68bab712d1113f3
|
| 3 |
+
size 4638128
|
export/fonts/OFL.txt
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2022 The BIZ UDGothic Project Authors (https://github.com/googlefonts/morisawa-biz-ud-mincho)
|
| 2 |
+
|
| 3 |
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
| 4 |
+
This license is copied below, and is also available with a FAQ at:
|
| 5 |
+
https://scripts.sil.org/OFL
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
-----------------------------------------------------------
|
| 9 |
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
| 10 |
+
-----------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
PREAMBLE
|
| 13 |
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
| 14 |
+
development of collaborative font projects, to support the font creation
|
| 15 |
+
efforts of academic and linguistic communities, and to provide a free and
|
| 16 |
+
open framework in which fonts may be shared and improved in partnership
|
| 17 |
+
with others.
|
| 18 |
+
|
| 19 |
+
The OFL allows the licensed fonts to be used, studied, modified and
|
| 20 |
+
redistributed freely as long as they are not sold by themselves. The
|
| 21 |
+
fonts, including any derivative works, can be bundled, embedded,
|
| 22 |
+
redistributed and/or sold with any software provided that any reserved
|
| 23 |
+
names are not used by derivative works. The fonts and derivatives,
|
| 24 |
+
however, cannot be released under any other type of license. The
|
| 25 |
+
requirement for fonts to remain under this license does not apply
|
| 26 |
+
to any document created using the fonts or their derivatives.
|
| 27 |
+
|
| 28 |
+
DEFINITIONS
|
| 29 |
+
"Font Software" refers to the set of files released by the Copyright
|
| 30 |
+
Holder(s) under this license and clearly marked as such. This may
|
| 31 |
+
include source files, build scripts and documentation.
|
| 32 |
+
|
| 33 |
+
"Reserved Font Name" refers to any names specified as such after the
|
| 34 |
+
copyright statement(s).
|
| 35 |
+
|
| 36 |
+
"Original Version" refers to the collection of Font Software components as
|
| 37 |
+
distributed by the Copyright Holder(s).
|
| 38 |
+
|
| 39 |
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
| 40 |
+
or substituting -- in part or in whole -- any of the components of the
|
| 41 |
+
Original Version, by changing formats or by porting the Font Software to a
|
| 42 |
+
new environment.
|
| 43 |
+
|
| 44 |
+
"Author" refers to any designer, engineer, programmer, technical
|
| 45 |
+
writer or other person who contributed to the Font Software.
|
| 46 |
+
|
| 47 |
+
PERMISSION & CONDITIONS
|
| 48 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 49 |
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
| 50 |
+
redistribute, and sell modified and unmodified copies of the Font
|
| 51 |
+
Software, subject to the following conditions:
|
| 52 |
+
|
| 53 |
+
1) Neither the Font Software nor any of its individual components,
|
| 54 |
+
in Original or Modified Versions, may be sold by itself.
|
| 55 |
+
|
| 56 |
+
2) Original or Modified Versions of the Font Software may be bundled,
|
| 57 |
+
redistributed and/or sold with any software, provided that each copy
|
| 58 |
+
contains the above copyright notice and this license. These can be
|
| 59 |
+
included either as stand-alone text files, human-readable headers or
|
| 60 |
+
in the appropriate machine-readable metadata fields within text or
|
| 61 |
+
binary files as long as those fields can be easily viewed by the user.
|
| 62 |
+
|
| 63 |
+
3) No Modified Version of the Font Software may use the Reserved Font
|
| 64 |
+
Name(s) unless explicit written permission is granted by the corresponding
|
| 65 |
+
Copyright Holder. This restriction only applies to the primary font name as
|
| 66 |
+
presented to the users.
|
| 67 |
+
|
| 68 |
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
| 69 |
+
Software shall not be used to promote, endorse or advertise any
|
| 70 |
+
Modified Version, except to acknowledge the contribution(s) of the
|
| 71 |
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
| 72 |
+
permission.
|
| 73 |
+
|
| 74 |
+
5) The Font Software, modified or unmodified, in part or in whole,
|
| 75 |
+
must be distributed entirely under this license, and must not be
|
| 76 |
+
distributed under any other license. The requirement for fonts to
|
| 77 |
+
remain under this license does not apply to any document created
|
| 78 |
+
using the Font Software.
|
| 79 |
+
|
| 80 |
+
TERMINATION
|
| 81 |
+
This license becomes null and void if any of the above conditions are
|
| 82 |
+
not met.
|
| 83 |
+
|
| 84 |
+
DISCLAIMER
|
| 85 |
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 86 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
| 87 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
| 88 |
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
| 89 |
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 90 |
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
| 91 |
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 92 |
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
| 93 |
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
export/pdf_exporter.py
CHANGED
|
@@ -4,7 +4,7 @@ export/templates/SDU_shift_template.xlsx と同じ紙面レイアウトを repor
|
|
| 4 |
Excel出力(テンプレート流し込み)を印刷したときと同じ見た目になるよう、
|
| 5 |
テンプレートの実測値(列幅・行高・フォントサイズ・罫線)を縮尺して描画する。
|
| 6 |
|
| 7 |
-
紙面構成(1日 = 3列: 開始時刻 / 区切り("-")・備考 / 終了時刻、日付ブロックは
|
| 8 |
日付・曜日 / メモ1(3行) / メモ2 / 朝食見込・夜予約
|
| 9 |
キッチン社員(2枠) / キッチンA・P(18枠)
|
| 10 |
2ブロック目ヘッダー(日付・曜日・朝食見込・夜予約)
|
|
@@ -33,7 +33,7 @@ from utils.holidays import holiday_set
|
|
| 33 |
DAY_JP = ["月", "火", "水", "木", "金", "土", "日"]
|
| 34 |
|
| 35 |
# ── テンプレートのレイアウト実測値 ───────────────────────────────────────
|
| 36 |
-
N_BLOCKS = 16 # 日付ブロック数
|
| 37 |
COLS_PER_DAY = 3 # 1日 = 3列(開始 / 区切り・備考 / 終了)
|
| 38 |
NAME_W_CH = 17.63 # 氏名列幅(Excel文字単位)
|
| 39 |
DAY_W_CH = 5.75 # 日付1列幅(Excel文字単位)
|
|
@@ -72,9 +72,15 @@ MED, THIN = 0.8, 0.3 # 罫線幅(pt): medium / thin
|
|
| 72 |
# ── フォント登録 ─────────────────────────────────────────────────────────
|
| 73 |
|
| 74 |
def _register_font() -> str:
|
| 75 |
-
"""日本語フォントを登録。利用不可の場合は Helvetica にフォールバック。
|
|
|
|
|
|
|
|
|
|
| 76 |
import glob
|
|
|
|
| 77 |
candidates = [
|
|
|
|
|
|
|
| 78 |
# Linux: IPA Gothic (.ttf, ReportLab互換)
|
| 79 |
"/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf",
|
| 80 |
"/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf",
|
|
@@ -272,8 +278,8 @@ def export_pdf(
|
|
| 272 |
avail_w = page_w - 2 * MARGIN_LR
|
| 273 |
avail_h = page_h - 2 * MARGIN_TB
|
| 274 |
|
| 275 |
-
n_cols = 2 +
|
| 276 |
-
natural_w = (2 * NAME_W_CH +
|
| 277 |
|
| 278 |
# 行構成: ヘッダー8行 + K枠 + 2ブロック目4行 + H枠 + フッター2行
|
| 279 |
row_heights_nat: list[float] = []
|
|
@@ -290,7 +296,7 @@ def export_pdf(
|
|
| 290 |
f = min(sx, sy) # フォントは小さい方の縮尺に合わせる
|
| 291 |
|
| 292 |
col_widths = ([NAME_W_CH * CH_PT * sx]
|
| 293 |
-
+ [DAY_W_CH * CH_PT * sx] * (
|
| 294 |
+ [NAME_W_CH * CH_PT * sx])
|
| 295 |
row_heights = [h * sy for h in row_heights_nat]
|
| 296 |
|
|
@@ -347,7 +353,7 @@ def export_pdf(
|
|
| 347 |
|
| 348 |
# ── ヘッダー(日付・曜日・メモ1・メモ2・朝食見込・夜予約)──────────
|
| 349 |
def _fill_date_rows(r_date, r_dow):
|
| 350 |
-
for i in range(
|
| 351 |
c0 = _block_col(i)
|
| 352 |
_span(c0, r_date, c0 + 2, r_date)
|
| 353 |
_span(c0, r_dow, c0 + 2, r_dow)
|
|
@@ -370,7 +376,7 @@ def export_pdf(
|
|
| 370 |
data[R_DATE1][0] = Paragraph(title, title_style)
|
| 371 |
data[R_DATE1][n_cols - 1] = Paragraph(title, title_style)
|
| 372 |
|
| 373 |
-
for i in range(
|
| 374 |
c0 = _block_col(i)
|
| 375 |
_span(c0, R_MEMO1, c0 + 2, R_MEMO1 + 2) # メモ1: 3列×3行
|
| 376 |
_span(c0, R_MEMO2, c0 + 2, R_MEMO2)
|
|
@@ -403,7 +409,7 @@ def export_pdf(
|
|
| 403 |
_span(n_cols - 1, r_date2, n_cols - 1, r_dow2)
|
| 404 |
data[r_date2][0] = Paragraph(title, title_style)
|
| 405 |
data[r_date2][n_cols - 1] = Paragraph(title, title_style)
|
| 406 |
-
for i in range(
|
| 407 |
c0 = _block_col(i)
|
| 408 |
_span(c0, r_bf2, c0 + 2, r_bf2)
|
| 409 |
_span(c0, r_din2, c0 + 2, r_din2)
|
|
@@ -479,7 +485,7 @@ def export_pdf(
|
|
| 479 |
# ── 罫線(テンプレートの medium/thin 使い分けを再現)────────────────
|
| 480 |
last = n_cols - 1
|
| 481 |
# 縦線: 氏名列の両側と日付ブロック境界は medium
|
| 482 |
-
for c in [0, 1] + [_block_col(i) for i in range(1,
|
| 483 |
cmds.append(("LINEBEFORE", (c, 0), (c, -1), MED, colors.black))
|
| 484 |
cmds.append(("LINEAFTER", (last, 0), (last, -1), MED, colors.black))
|
| 485 |
|
|
|
|
| 4 |
Excel出力(テンプレート流し込み)を印刷したときと同じ見た目になるよう、
|
| 5 |
テンプレートの実測値(列幅・行高・フォントサイズ・罫線)を縮尺して描画する。
|
| 6 |
|
| 7 |
+
紙面構成(1日 = 3列: 開始時刻 / 区切り("-")・備考 / 終了時刻、日付ブロックは期間日数分):
|
| 8 |
日付・曜日 / メモ1(3行) / メモ2 / 朝食見込・夜予約
|
| 9 |
キッチン社員(2枠) / キッチンA・P(18枠)
|
| 10 |
2ブロック目ヘッダー(日付・曜日・朝食見込・夜予約)
|
|
|
|
| 33 |
DAY_JP = ["月", "火", "水", "木", "金", "土", "日"]
|
| 34 |
|
| 35 |
# ── テンプレートのレイアウト実測値 ───────────────────────────────────────
|
| 36 |
+
N_BLOCKS = 16 # テンプレートの最大日付ブロック数(実際は期間日数分だけ描画)
|
| 37 |
COLS_PER_DAY = 3 # 1日 = 3列(開始 / 区切り・備考 / 終了)
|
| 38 |
NAME_W_CH = 17.63 # 氏名列幅(Excel文字単位)
|
| 39 |
DAY_W_CH = 5.75 # 日付1列幅(Excel文字単位)
|
|
|
|
| 72 |
# ── フォント登録 ─────────────────────────────────────────────────────────
|
| 73 |
|
| 74 |
def _register_font() -> str:
|
| 75 |
+
"""日本語フォントを登録。利用不可の場合は Helvetica にフォールバック。
|
| 76 |
+
|
| 77 |
+
元シートが全セル太字のため、同梱の太字フォント(BIZ UDGothic Bold, OFL)を
|
| 78 |
+
最優先で使う。見つからない場合のみシステムフォントを探す。"""
|
| 79 |
import glob
|
| 80 |
+
from pathlib import Path
|
| 81 |
candidates = [
|
| 82 |
+
# 同梱フォント(太字)
|
| 83 |
+
str(Path(__file__).parent / "fonts" / "BIZUDGothic-Bold.ttf"),
|
| 84 |
# Linux: IPA Gothic (.ttf, ReportLab互換)
|
| 85 |
"/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf",
|
| 86 |
"/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf",
|
|
|
|
| 278 |
avail_w = page_w - 2 * MARGIN_LR
|
| 279 |
avail_h = page_h - 2 * MARGIN_TB
|
| 280 |
|
| 281 |
+
n_cols = 2 + n * COLS_PER_DAY # 月の日数に合わせブロック数を可変にし空白を作らない
|
| 282 |
+
natural_w = (2 * NAME_W_CH + n * COLS_PER_DAY * DAY_W_CH) * CH_PT
|
| 283 |
|
| 284 |
# 行構成: ヘッダー8行 + K枠 + 2ブロック目4行 + H枠 + フッター2行
|
| 285 |
row_heights_nat: list[float] = []
|
|
|
|
| 296 |
f = min(sx, sy) # フォントは小さい方の縮尺に合わせる
|
| 297 |
|
| 298 |
col_widths = ([NAME_W_CH * CH_PT * sx]
|
| 299 |
+
+ [DAY_W_CH * CH_PT * sx] * (n * COLS_PER_DAY)
|
| 300 |
+ [NAME_W_CH * CH_PT * sx])
|
| 301 |
row_heights = [h * sy for h in row_heights_nat]
|
| 302 |
|
|
|
|
| 353 |
|
| 354 |
# ── ヘッダー(日付・曜日・メモ1・メモ2・朝食見込・夜予約)──────────
|
| 355 |
def _fill_date_rows(r_date, r_dow):
|
| 356 |
+
for i in range(n):
|
| 357 |
c0 = _block_col(i)
|
| 358 |
_span(c0, r_date, c0 + 2, r_date)
|
| 359 |
_span(c0, r_dow, c0 + 2, r_dow)
|
|
|
|
| 376 |
data[R_DATE1][0] = Paragraph(title, title_style)
|
| 377 |
data[R_DATE1][n_cols - 1] = Paragraph(title, title_style)
|
| 378 |
|
| 379 |
+
for i in range(n):
|
| 380 |
c0 = _block_col(i)
|
| 381 |
_span(c0, R_MEMO1, c0 + 2, R_MEMO1 + 2) # メモ1: 3列×3行
|
| 382 |
_span(c0, R_MEMO2, c0 + 2, R_MEMO2)
|
|
|
|
| 409 |
_span(n_cols - 1, r_date2, n_cols - 1, r_dow2)
|
| 410 |
data[r_date2][0] = Paragraph(title, title_style)
|
| 411 |
data[r_date2][n_cols - 1] = Paragraph(title, title_style)
|
| 412 |
+
for i in range(n):
|
| 413 |
c0 = _block_col(i)
|
| 414 |
_span(c0, r_bf2, c0 + 2, r_bf2)
|
| 415 |
_span(c0, r_din2, c0 + 2, r_din2)
|
|
|
|
| 485 |
# ── 罫線(テンプレートの medium/thin 使い分けを再現)────────────────
|
| 486 |
last = n_cols - 1
|
| 487 |
# 縦線: 氏名列の両側と日付ブロック境界は medium
|
| 488 |
+
for c in [0, 1] + [_block_col(i) for i in range(1, n)] + [last]:
|
| 489 |
cmds.append(("LINEBEFORE", (c, 0), (c, -1), MED, colors.black))
|
| 490 |
cmds.append(("LINEAFTER", (last, 0), (last, -1), MED, colors.black))
|
| 491 |
|
shift_tool.spec
CHANGED
|
@@ -36,6 +36,9 @@ added_datas = [
|
|
| 36 |
(str(OPENPYXL_DIR), "openpyxl"),
|
| 37 |
# アイコンをランタイムでも読み込めるよう同梱(タスクバー表示用)
|
| 38 |
("assets/icon.ico", "assets"),
|
|
|
|
|
|
|
|
|
|
| 39 |
]
|
| 40 |
|
| 41 |
# macOS: Qt6 フレームワーク・プラグインを明示的に含める
|
|
|
|
| 36 |
(str(OPENPYXL_DIR), "openpyxl"),
|
| 37 |
# アイコンをランタイムでも読み込めるよう同梱(タスクバー表示用)
|
| 38 |
("assets/icon.ico", "assets"),
|
| 39 |
+
# シフト表出力用のテンプレート・日本語太字フォント
|
| 40 |
+
("export/templates", "export/templates"),
|
| 41 |
+
("export/fonts", "export/fonts"),
|
| 42 |
]
|
| 43 |
|
| 44 |
# macOS: Qt6 フレームワーク・プラグインを明示的に含める
|