diff --git a/public/fonts/Roboto-Regular.ttf b/public/fonts/Roboto-Regular.ttf new file mode 100644 index 0000000..810df57 Binary files /dev/null and b/public/fonts/Roboto-Regular.ttf differ diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index dec8289..b6f4c26 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -170,8 +170,8 @@ async fn export_batch(images: Vec, watermark: WatermarkSettings let scaled_font = PxScale::from(scale_px); let (t_width, _t_height) = imageproc::drawing::text_size(scaled_font, &font, &watermark.text); - // 3. Ensure it fits width (Padding 10%) - let max_width = (width as f32 * 0.90) as u32; + // 3. Ensure it fits width (Padding 15%) + let max_width = (width as f32 * 0.85) as u32; if t_width > max_width { let ratio = max_width as f32 / t_width as f32; scale_px *= ratio; @@ -395,8 +395,8 @@ async fn layout_watermark(path: String, text: String, base_scale: f64) -> Result let mut font_scale = PxScale::from(scale_px); let (mut t_width, mut t_height) = imageproc::drawing::text_size(font_scale, &font, &text); - // 3. Auto-Fit Width (Limit to 90% of image width) - let max_width = (width as f32 * 0.90) as u32; + // 3. Auto-Fit Width (Limit to 85% of image width) + let max_width = (width as f32 * 0.85) as u32; if t_width > max_width { let ratio = max_width as f32 / t_width as f32; scale_val *= ratio as f64; @@ -411,9 +411,15 @@ async fn layout_watermark(path: String, text: String, base_scale: f64) -> Result let center_x = zca.x * width as f64; let center_y = zca.y * height as f64; - let half_w = t_width as f64 / 2.0; - let half_h = t_height as f64 / 2.0; - let padding = width as f64 * 0.02; + // Add safety margin to measured text size (Renderer mismatch buffer) + let safe_t_width = t_width as f64 * 1.05; + let safe_t_height = t_height as f64 * 1.05; + + let half_w = safe_t_width / 2.0; + let half_h = safe_t_height / 2.0; + + // Increase edge padding to 4% + let padding = width as f64 * 0.04; let min_x = half_w + padding; let max_x = width as f64 - half_w - padding; diff --git a/src/components/HeroView.vue b/src/components/HeroView.vue index c745d5b..66600f9 100644 --- a/src/components/HeroView.vue +++ b/src/components/HeroView.vue @@ -265,7 +265,7 @@ const stopDrawing = () => {
diff --git a/src/stores/gallery.ts b/src/stores/gallery.ts index e318d74..ffc0383 100644 --- a/src/stores/gallery.ts +++ b/src/stores/gallery.ts @@ -118,23 +118,31 @@ export const useGalleryStore = defineStore("gallery", () => { } } - async function recalcCurrentWatermark() { - if (selectedIndex.value < 0 || !selectedImage.value) return; - const img = selectedImage.value; + async function recalcAllWatermarks() { + if (images.value.length === 0) return; - try { - const result = await invoke<{x: number, y: number, scale: number}>("layout_watermark", { - path: img.path, - text: watermarkSettings.value.text, - baseScale: watermarkSettings.value.scale + const text = watermarkSettings.value.text; + const baseScale = watermarkSettings.value.scale; + + // Process in batches to avoid overwhelming the backend + const batchSize = 5; + for (let i = 0; i < images.value.length; i += batchSize) { + const batch = images.value.slice(i, i + batchSize).map(async (img, batchIdx) => { + const globalIdx = i + batchIdx; + try { + const result = await invoke<{x: number, y: number, scale: number}>("layout_watermark", { + path: img.path, + text: text, + baseScale: baseScale + }); + + setImageManualPosition(globalIdx, result.x, result.y); + setImageSetting(globalIdx, 'scale', result.scale); + } catch (e) { + console.error(`Layout failed for ${img.name}`, e); + } }); - - // Apply to current image - setImageManualPosition(selectedIndex.value, result.x, result.y); - setImageSetting(selectedIndex.value, 'scale', result.scale); - - } catch (e) { - console.error("Layout failed", e); + await Promise.all(batch); } } @@ -192,6 +200,6 @@ export const useGalleryStore = defineStore("gallery", () => { addMaskStroke, clearMask, detectWatermark, - recalcCurrentWatermark + recalcAllWatermarks }; }); diff --git a/src/style.css b/src/style.css index f1d8c73..641df19 100644 --- a/src/style.css +++ b/src/style.css @@ -1 +1,8 @@ @import "tailwindcss"; + +@font-face { + font-family: 'Roboto'; + src: url('/fonts/Roboto-Regular.ttf') format('truetype'); + font-weight: normal; + font-style: normal; +} \ No newline at end of file