Browse Source

smCover stretch mode ( = slice)

Johann ELSASS 5 years ago
parent
commit
4b1e9719ee
2 changed files with 8 additions and 7 deletions
  1. 7 6
      bcsvgviewer.pas
  2. 1 1
      bctypes.pas

+ 7 - 6
bcsvgviewer.pas

@@ -288,10 +288,10 @@ begin
   vbSize.x := vbSize.x * (dpi / FSVG.Units.DpiX);
   vbSize.x := vbSize.x * (dpi / FSVG.Units.DpiX);
   vbSize.y := vbSize.y * (dpi / FSVG.Units.DpiY);
   vbSize.y := vbSize.y * (dpi / FSVG.Units.DpiY);
   if ((StretchMode = smShrink) and ((vbSize.x > w + 0.1) or (vbSize.y > h + 0.1))) or
   if ((StretchMode = smShrink) and ((vbSize.x > w + 0.1) or (vbSize.y > h + 0.1))) or
-    (StretchMode = smStretch) then
+    (StretchMode in[smStretch, smCover]) then
   begin
   begin
     if Proportional then
     if Proportional then
-      Result := FSVG.GetStretchRectF(HorizAlign, VertAlign, 0, 0, w, h)
+      Result := FSVG.GetStretchRectF(HorizAlign, VertAlign, 0, 0, w, h, StretchMode = smCover)
     else
     else
     if StretchMode = smShrink then
     if StretchMode = smShrink then
     begin
     begin
@@ -337,12 +337,13 @@ begin
 
 
   ratioX := BitmapWidth / FSVG.WidthAsPixel;
   ratioX := BitmapWidth / FSVG.WidthAsPixel;
   ratioY := BitmapHeight / FSVG.HeightAsPixel;
   ratioY := BitmapHeight / FSVG.HeightAsPixel;
-  if StretchMode = smStretch then
-    ratio := min(ratioX, ratioY)
-  else if StretchMode = smShrink then
-    ratio := min(1, min(ratioX, ratioY))
+  case StretchMode of
+    smStretch: ratio := min(ratioX, ratioY);
+    smShrink: ratio := min(1, min(ratioX, ratioY));
+    smCover: ratio := max(ratioX, ratioY);
   else
   else
     ratio := 1;
     ratio := 1;
+  end;
   result := RectWithSizeF(0, 0, FSVG.WidthAsPixel * ratio,
   result := RectWithSizeF(0, 0, FSVG.WidthAsPixel * ratio,
               FSVG.HeightAsPixel * ratio);
               FSVG.HeightAsPixel * ratio);
   result.Offset((BitmapWidth - result.Width) / 2,
   result.Offset((BitmapWidth - result.Width) / 2,

+ 1 - 1
bctypes.pas

@@ -107,7 +107,7 @@ type
   TBCBackgroundStyle = (bbsClear, bbsColor, bbsGradient);
   TBCBackgroundStyle = (bbsClear, bbsColor, bbsGradient);
   TBCBorderStyle = (bboNone, bboSolid);
   TBCBorderStyle = (bboNone, bboSolid);
   TBCArrowDirection = (badLeft, badRight, badUp, badDown);
   TBCArrowDirection = (badLeft, badRight, badUp, badDown);
-  TBCStretchMode = (smNone, smShrink, smStretch);
+  TBCStretchMode = (smNone, smShrink, smStretch, smCover);
   TBCCanvasScaleMode = (csmAuto, csmScaleBitmap, csmFullResolution);
   TBCCanvasScaleMode = (csmAuto, csmScaleBitmap, csmFullResolution);
   TBGRATextAlign = (btaLeft, btaCenter, btaRight); // deprecated
   TBGRATextAlign = (btaLeft, btaCenter, btaRight); // deprecated
   TBGRATextVAlign = (btvaTop, btvaCenter, btvaBottom); // deprecated
   TBGRATextVAlign = (btvaTop, btvaCenter, btvaBottom); // deprecated