Parcourir la source

fixing cover display

Codex CLI il y a 4 mois
Parent
commit
ded2e50637
2 fichiers modifiés avec 26 ajouts et 3 suppressions
  1. 19 3
      src/book.pas
  2. 7 0
      src/unitCoverWorker.pas

+ 19 - 3
src/book.pas

@@ -219,11 +219,27 @@ begin
         end;
         end;
         mImagePath := AValue;
         mImagePath := AValue;
         mScaledW := W; mScaledH := H;
         mScaledW := W; mScaledH := H;
-        LogInfoFmt('SetImage: applied image "%s" target=%dx%d', [mImagePath, W, H]);
+        LogInfoFmt('SetImage: applied image "%s" target=%dx%d (pre-scaled)', [mImagePath, W, H]);
         Exit;
         Exit;
       except
       except
-        // fall through to generic on any failure
-        on E: Exception do LogErrorFmt('SetImage: failed to load "%s": %s', [AValue, E.Message]);
+        // If pre-scale/assignment failed, fall back to direct load + Stretch
+        on E: Exception do
+        begin
+          LogErrorFmt('SetImage: failed to pre-scale "%s": %s', [AValue, E.Message]);
+          try
+            mCover.Stretch := True;
+            mCover.Center  := True;
+            mCover.AutoSize:= False;
+            mCover.Picture.LoadFromFile(AValue);
+            mImagePath := AValue;
+            // Mark as scaled to current control to avoid immediate rescale loop
+            mScaledW := mCover.Width; mScaledH := mCover.Height;
+            LogInfoFmt('SetImage: applied image "%s" via direct load (stretch)', [mImagePath]);
+            Exit;
+          except
+            on E2: Exception do LogErrorFmt('SetImage: direct load failed for "%s": %s', [AValue, E2.Message]);
+          end;
+        end;
       end;
       end;
     finally
     finally
       Canvas.Free;
       Canvas.Free;

+ 7 - 0
src/unitCoverWorker.pas

@@ -288,8 +288,15 @@ begin
   try
   try
     if Assigned(FApplyBook) and (FApplyImg <> '') and FileExists(FApplyImg) then
     if Assigned(FApplyBook) and (FApplyImg <> '') and FileExists(FApplyImg) then
     begin
     begin
+      LogDebugFmt('DoApplyCover: applying to book fp="%s" img="%s"', [FApplyBook.FilePath, FApplyImg]);
       FApplyBook.ImagePath := FApplyImg;  // triggers SetImage + pre-scale
       FApplyBook.ImagePath := FApplyImg;  // triggers SetImage + pre-scale
       FApplyBook.EnsureScaledToCoverSize; // in case layout changed
       FApplyBook.EnsureScaledToCoverSize; // in case layout changed
+      try
+        LogDebugFmt('DoApplyCover: after apply hasGraphic=%s coverSize=%dx%d',
+          [BoolToStr(Assigned(FApplyBook.Cover) and Assigned(FApplyBook.Cover.Picture) and
+                     Assigned(FApplyBook.Cover.Picture.Graphic) and (not FApplyBook.Cover.Picture.Graphic.Empty), True),
+           FApplyBook.Cover.Width, FApplyBook.Cover.Height]);
+      except end;
       // Persist cover change immediately
       // Persist cover change immediately
       NotifyBooksChanged;
       NotifyBooksChanged;
     end;
     end;