Skip to content

Commit

Permalink
保存処理
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Dec 17, 2024
1 parent 307d7e0 commit 5b14cb0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
8 changes: 8 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10670,6 +10670,14 @@ export interface Locale extends ILocale {
* 画像ファイルを選択してください
*/
"driveFileTypeWarnDescription": string;
/**
* 設定が不十分です
*/
"settingInvalidWarn": string;
/**
* プレビューが正常に表示されることを確認してから保存してください
*/
"settingInvalidWarnDescription": string;
/**
* 描画モード
*/
Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,8 @@ _followRequest:
_watermarkEditor:
driveFileTypeWarn: "このファイルは対応していません"
driveFileTypeWarnDescription: "画像ファイルを選択してください"
settingInvalidWarn: "設定が不十分です"
settingInvalidWarnDescription: "プレビューが正常に表示されることを確認してから保存してください"
repeatSetting: "描画モード"
repeat: "全体を埋め尽くす"
padding: "余白"
24 changes: 17 additions & 7 deletions packages/frontend/src/components/MkWatermarkEditorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,11 @@ function cancel() {
emit('cancel');
dialogEl.value?.close();
}

function save() {
emit('ok');
dialogEl.value?.close();
}
//#endregion

//#region 設定
const useWatermark = computed(defaultStore.makeGetterSetter('useWatermark'));
const watermarkConfig = ref<Partial<WatermarkConfig> | null>(defaultStore.state.watermarkConfig ?? {
const watermarkConfig = ref<WatermarkConfig>(defaultStore.state.watermarkConfig ?? {
opacity: 0.2,
repeat: true,
rotate: 15,
Expand Down Expand Up @@ -195,6 +190,22 @@ const paddingBottom = computed({
get: () => watermarkConfig.value?.padding?.bottom ?? 0,
set: (v) => setPadding('bottom', v),
});

function save() {
if (canPreview(watermarkConfig.value)) {
defaultStore.set('watermarkConfig', watermarkConfig.value);
} else {
os.alert({
type: 'warning',
title: i18n.ts._watermarkEditor.settingInvalidWarn,
text: i18n.ts._watermarkEditor.settingInvalidWarnDescription,
});
return;
}

emit('ok');
dialogEl.value?.close();
}
//#endregion

//#region ファイル選択
Expand Down Expand Up @@ -269,7 +280,6 @@ onMounted(() => {

//#region paddingViewの制御
const focusedForm = ref<'top' | 'left' | 'right' | 'bottom' | null>(null);

//#endregion
</script>

Expand Down
12 changes: 7 additions & 5 deletions packages/frontend/src/scripts/watermark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,27 @@ export async function applyWatermark(img: string | Blob, el: HTMLCanvasElement,
const desiredHeight = canvas.height * (config.sizeRatio ?? 1);

if (
(watermarkAspectRatio > 1 && canvasAspectRatio > 1) ||
(watermarkAspectRatio < 1 && canvasAspectRatio < 1)
(watermarkAspectRatio > 1 && canvasAspectRatio > 1) || // 両方横長
(watermarkAspectRatio < 1 && canvasAspectRatio < 1) // 両方縦長

Check failure on line 88 in packages/frontend/src/scripts/watermark.ts

View workflow job for this annotation

GitHub Actions / lint (frontend)

Multiple spaces found before '// 両方縦長'
) {
// 横幅を基準にウォーターマークのサイズを決定
return {
width: desiredWidth,
height: desiredWidth / watermarkAspectRatio
height: desiredWidth / watermarkAspectRatio,
};
} else {
// 縦幅を基準にウォーターマークのサイズを決定
return {
width: desiredHeight * watermarkAspectRatio,
height: desiredHeight
height: desiredHeight,
};
}
})();

ctx.globalAlpha = config.opacity ?? 1;

if (config.repeat) {
// 余白をもたせた状態のウォーターマークを作成しておく
// 余白をもたせた状態のウォーターマークを作成しておく(それをパターン繰り返しする)
const resizedWatermark = document.createElement('canvas');
resizedWatermark.width = width + (config.padding ? (config.padding.left ?? 0) + (config.padding.right ?? 0) : 0);
resizedWatermark.height = height + (config.padding ? (config.padding.top ?? 0) + (config.padding.bottom ?? 0) : 0);
Expand Down

0 comments on commit 5b14cb0

Please sign in to comment.