wip logo
This commit is contained in:
parent
d2ab7bfce6
commit
ce58f99de1
3 changed files with 77 additions and 56 deletions
|
|
@ -3,6 +3,7 @@
|
|||
public enum Positions
|
||||
{
|
||||
Alto,
|
||||
Centro,
|
||||
Basso
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -210,51 +210,10 @@ namespace CatalogLib
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
// todo calcolare ridimensionamento
|
||||
var size = new Size();
|
||||
var size = new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza);
|
||||
if (PicSettings.Instance.FotoMantieniDimensioni)
|
||||
{
|
||||
|
||||
|
||||
|
||||
switch (PicSettings.Instance.ResizeDimension)
|
||||
{
|
||||
case ResizeDimensions.LatoLungo:
|
||||
if (image.Width > image.Height)
|
||||
{
|
||||
// larghezza è il lato lungo
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
break;
|
||||
case ResizeDimensions.LatoCorto:
|
||||
if (image.Width > image.Height)
|
||||
{
|
||||
// larghezza è il lato lungo
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
|
||||
}
|
||||
size = ResizeImage(image, size, PicSettings.Instance.ResizeDimension);
|
||||
image.Mutate(x => x.Resize((size.Width), (size.Height), resampler));
|
||||
|
||||
//Width Formula:
|
||||
|
|
@ -270,16 +229,25 @@ namespace CatalogLib
|
|||
|
||||
}
|
||||
|
||||
private Size GetResizeDimensions(Size originalSize, Size newSize, bool isWidth)
|
||||
private Size ResizeImage(Image<Rgba32> image, Size size, ResizeDimensions side)
|
||||
{
|
||||
if (isWidth)
|
||||
switch (side)
|
||||
{
|
||||
return new Size(newSize.Width, originalSize.Height / originalSize.Width * newSize.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Size(originalSize.Width / originalSize.Height * newSize.Height, newSize.Height);
|
||||
case ResizeDimensions.LatoLungo:
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height), size, image.Width > image.Height);
|
||||
break;
|
||||
case ResizeDimensions.LatoCorto:
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height), size, image.Width <= image.Height);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
private Size GetResizeDimensions(Size originalSize, Size newSize, bool adjustHeight)
|
||||
{
|
||||
return adjustHeight ? new Size(newSize.Width, originalSize.Height / originalSize.Width * newSize.Height) : new Size(originalSize.Width / originalSize.Height * newSize.Height, newSize.Height);
|
||||
}
|
||||
|
||||
private void SetTextTest(Image<Rgba32> image)
|
||||
|
|
@ -488,29 +456,63 @@ namespace CatalogLib
|
|||
|
||||
//}
|
||||
|
||||
Size size = new Size();
|
||||
Point location = new Point();
|
||||
|
||||
if (_logo != null)
|
||||
{
|
||||
var width = PicSettings.Instance.LogoWidth;
|
||||
var height = PicSettings.Instance.LogoHeight;
|
||||
var fattoreAlt = _logo.Height / height;
|
||||
var fattoreLarg = _logo.Width / width;
|
||||
var nuovaSize = new Size();
|
||||
var heightFactor = _logo.Height / height;
|
||||
var widthFactor = _logo.Width / width;
|
||||
var newLogoSize = new Size();
|
||||
|
||||
nuovaSize = GetResizeDimensions(new Size(_logo.Width, _logo.Height), new Size(width, height), fattoreLarg > fattoreAlt);
|
||||
newLogoSize = GetResizeDimensions(new Size(_logo.Width, _logo.Height), new Size(width, height), PicSettings.Instance.LogoResizeSide.Equals(ResizeDimensions.LatoCorto));
|
||||
//todo riguardare perché non torna cosa ho fatto
|
||||
|
||||
int margineUsato;
|
||||
int margineUsato = 0;
|
||||
int margineL;
|
||||
bool inPercentualeL;
|
||||
|
||||
inPercentualeL = PicSettings.Instance.LogoMargin.EndsWith("%");
|
||||
if (inPercentualeL)
|
||||
{ margineL = int.Parse(PicSettings.Instance.LogoMargin.Replace("%", ""));}
|
||||
{
|
||||
margineL = int.Parse(PicSettings.Instance.LogoMargin.Replace("%", ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
margineL = int.Parse(PicSettings.Instance.LogoMargin);
|
||||
}
|
||||
|
||||
switch (PicSettings.Instance.LogoPosition)
|
||||
{
|
||||
case Positions.Alto:
|
||||
break;
|
||||
case Positions.Centro:
|
||||
break;
|
||||
case Positions.Basso:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
switch (PicSettings.Instance.LogoAlignment)
|
||||
{
|
||||
case Alignments.Sinistra:
|
||||
location.X = margineUsato;
|
||||
break;
|
||||
case Alignments.Centro:
|
||||
//location.X = image.Width -
|
||||
break;
|
||||
case Alignments.Destra:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
image.Mutate(x => x.DrawImage(_logo, size, location, new GraphicsOptions()));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -519,6 +519,24 @@ namespace CatalogLib
|
|||
set => SetString("LogoMargin", value);
|
||||
}
|
||||
|
||||
public Positions LogoPosition
|
||||
{
|
||||
get => GetEnum("LogoPositions", Positions.Alto);
|
||||
set => SetString("LogoPositions", value.ToString());
|
||||
}
|
||||
|
||||
public Alignments LogoAlignment
|
||||
{
|
||||
get => GetEnum("LogoAlignments", Alignments.Centro);
|
||||
set => SetString("LogoAlignments", value.ToString());
|
||||
}
|
||||
|
||||
public ResizeDimensions LogoResizeSide
|
||||
{
|
||||
get => GetEnum("LogoResizeMode", ResizeDimensions.LatoCorto);
|
||||
set => SetString("LogoResizeMode", value.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue