posizione Testo
This commit is contained in:
parent
a2dca4b750
commit
922315061d
5 changed files with 285 additions and 27 deletions
|
|
@ -9,7 +9,9 @@ using MaddoLibrary.Base.Log;
|
|||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing;
|
||||
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.Primitives;
|
||||
using Font = SixLabors.Fonts.Font;
|
||||
using FontFamily = SixLabors.Fonts.FontFamily;
|
||||
using FontStyle = SixLabors.Fonts.FontStyle;
|
||||
|
|
@ -36,10 +38,25 @@ namespace CatalogLib
|
|||
{
|
||||
MaddoLogger.Log("Loaded Image: {0}", workFile.FullName);
|
||||
//image.Rotate(-90);
|
||||
bool isRotated;
|
||||
|
||||
//if (PicSettings.Instance.r)
|
||||
image.Mutate(x => x.Resize(PicSettings.Instance.FotoAltezza, PicSettings.Instance.FotoLarghezza, new BoxResampler()));
|
||||
var orientation = image.MetaData.ExifProfile.GetValue(ExifTag.Orientation);
|
||||
if ((ushort)orientation.Value != 1)
|
||||
{
|
||||
isRotated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isRotated = false;
|
||||
}
|
||||
|
||||
if (PicSettings.Instance.FotoRidimensiona)
|
||||
{
|
||||
// todo calcolare ridimensionamento
|
||||
image.Mutate(x => x.Resize(PicSettings.Instance.FotoAltezza, PicSettings.Instance.FotoLarghezza, new BicubicResampler()));
|
||||
}
|
||||
|
||||
|
||||
if (PicSettings.Instance.GeneraleRotazioneAutomatica)
|
||||
{
|
||||
image.Mutate(img => img.AutoOrient());
|
||||
|
|
@ -107,7 +124,10 @@ namespace CatalogLib
|
|||
|
||||
if (PicSettings.Instance.EnableText)
|
||||
{
|
||||
SetExtraText(image);
|
||||
|
||||
SetExtraText(image, isRotated);
|
||||
|
||||
|
||||
MaddoLogger.Log("Drawn text on Image: {0}", workFile.FullName);
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +150,7 @@ namespace CatalogLib
|
|||
MaddoLogger.Log("Time Taken for {0}: {1}", workFile.FullName, s.Elapsed);
|
||||
}
|
||||
|
||||
private void SetExtraText(Image<Rgba32> image)
|
||||
private void SetExtraText(Image<Rgba32> image, bool isRotated)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(PicSettings.Instance.TestoApplicareOrizzontale))
|
||||
{
|
||||
|
|
@ -138,6 +158,24 @@ namespace CatalogLib
|
|||
return;
|
||||
}
|
||||
|
||||
string text;
|
||||
if (isRotated)
|
||||
{
|
||||
if (PicSettings.Instance.TestoApplicareOrizzontale.Contains("$_"))
|
||||
{
|
||||
text = PicSettings.Instance.TestoApplicareOrizzontale.Replace("$_", "\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = PicSettings.Instance.TestoApplicareOrizzontale.Replace("$_", "");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
text = PicSettings.Instance.TestoApplicareOrizzontale.Replace("$_", "");
|
||||
}
|
||||
|
||||
|
||||
var fo = SixLabors.Fonts.SystemFonts.Find(PicSettings.Instance.NomeFont);
|
||||
|
||||
|
|
@ -145,12 +183,27 @@ namespace CatalogLib
|
|||
//var fff = FontCollection.SystemFonts.Find(PicSettings.Instance.NomeFont);
|
||||
//var fff = FontCollection.SystemFonts.Find("Segoe Print");
|
||||
|
||||
var font = new Font(fo, (float)PicSettings.Instance.DimensioneFont, FontStyle.Regular);
|
||||
Font font;
|
||||
|
||||
if (!PicSettings.Instance.Grassetto)
|
||||
{
|
||||
font = new Font(fo, (float)PicSettings.Instance.DimensioneFont, FontStyle.Regular);
|
||||
}
|
||||
else
|
||||
{
|
||||
font = new Font(fo, (float)PicSettings.Instance.DimensioneFont, FontStyle.Bold);
|
||||
}
|
||||
// todo corsivo
|
||||
|
||||
|
||||
|
||||
//var font = new Font(fff, 8f, FontStyle.Regular);
|
||||
|
||||
|
||||
//Color c = Color.FromHex(FlipRgbString(PicSettings.Instance.ColoreTestoRGB));
|
||||
Rgba32 g = Rgba32.FromHex(FlipRgbString(PicSettings.Instance.ColoreTestoRGB));
|
||||
|
||||
Rgba32 gBack = Rgba32.Black; // todo alpha
|
||||
//TextMeasurer measurer = new TextMeasurer();
|
||||
|
||||
//var size = measurer.MeasureText(PicSettings.Instance.TestoApplicareOrizzontale, font, 72);
|
||||
|
|
@ -161,7 +214,108 @@ namespace CatalogLib
|
|||
|
||||
Vector2 center = new Vector2(image.Width / 2, image.Height / 2); //center horizontally, 10px down
|
||||
|
||||
var size = TextMeasurer.Measure(PicSettings.Instance.TestoApplicareOrizzontale, new RendererOptions(font));
|
||||
var size = TextMeasurer.Measure(text, new RendererOptions(font));
|
||||
|
||||
var larghezzaStandard = size.Width;
|
||||
var dimensioneStandard = (int) Math.Round(PicSettings.Instance.DimensioneFont);
|
||||
if (size.Width > image.Width)
|
||||
{
|
||||
var c = dimensioneStandard;
|
||||
do
|
||||
{
|
||||
if (c > 20)
|
||||
{
|
||||
c -= 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
c -= 1;
|
||||
}
|
||||
|
||||
if (PicSettings.Instance.Grassetto)
|
||||
{
|
||||
font = new Font(fo, c, FontStyle.Bold);
|
||||
}
|
||||
else
|
||||
{
|
||||
font = new Font(fo, c, FontStyle.Regular);
|
||||
}
|
||||
size = TextMeasurer.Measure(text,
|
||||
new RendererOptions(font));
|
||||
if (size.Width < image.Width)
|
||||
{
|
||||
larghezzaStandard = (int) Math.Round(size.Width);
|
||||
break;
|
||||
}
|
||||
if (c <= 5)
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (dimensioneStandard == c);
|
||||
}
|
||||
|
||||
float yPosFromBottom = 0;
|
||||
|
||||
switch (PicSettings.Instance.TextPosition)
|
||||
{
|
||||
case PicSettings.Positions.Alto:
|
||||
yPosFromBottom = PicSettings.Instance.Margine;
|
||||
break;
|
||||
case PicSettings.Positions.Basso:
|
||||
yPosFromBottom = image.Height - size.Height - (image.Height * PicSettings.Instance.Margine / 100);
|
||||
break;
|
||||
}
|
||||
|
||||
float xCenterofImg = 0;
|
||||
|
||||
// stringformat
|
||||
|
||||
switch (PicSettings.Instance.TextAlignment)
|
||||
{
|
||||
case PicSettings.Alignments.Sinistra:
|
||||
xCenterofImg = PicSettings.Instance.Margine + (larghezzaStandard / 2);
|
||||
if ((larghezzaStandard / 2) > (image.Width / 2) - PicSettings.Instance.Margine)
|
||||
{
|
||||
xCenterofImg = image.Width / 2;
|
||||
}
|
||||
break;
|
||||
case PicSettings.Alignments.Centro:
|
||||
xCenterofImg = image.Width / 2;
|
||||
break;
|
||||
case PicSettings.Alignments.Destra:
|
||||
xCenterofImg = image.Width - PicSettings.Instance.Margine - larghezzaStandard / 2;
|
||||
|
||||
if (larghezzaStandard / 2 > image.Width / 2 - PicSettings.Instance.Margine)
|
||||
{
|
||||
xCenterofImg = image.Width / 2;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// stringformat alignment center
|
||||
|
||||
if (PicSettings.Instance.Grassetto)
|
||||
{
|
||||
font = new Font(fo, dimensioneStandard, FontStyle.Bold);
|
||||
}
|
||||
else
|
||||
{
|
||||
font = new Font(fo, dimensioneStandard, FontStyle.Regular);
|
||||
}
|
||||
|
||||
image.Mutate(x => x.DrawText(text, font, gBack, new PointF(xCenterofImg + 1 , yPosFromBottom + 1), new TextGraphicsOptions()
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center
|
||||
}));
|
||||
|
||||
image.Mutate(x => x.DrawText(text, font, g, new PointF(xCenterofImg, yPosFromBottom), new TextGraphicsOptions()
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center
|
||||
}));
|
||||
|
||||
return;
|
||||
|
||||
|
||||
float scalingFactor = Math.Min(image.Width / size.Width, image.Height / size.Height);
|
||||
Font scaledFont = new Font(font, scalingFactor * font.Size);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using MaddoLibrary.Base.Log;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CatalogLib
|
||||
|
|
@ -71,6 +71,11 @@ namespace CatalogLib
|
|||
SetBase(key, value);
|
||||
}
|
||||
|
||||
public void SetFloat(string key, float value)
|
||||
{
|
||||
SetBase(key, value);
|
||||
}
|
||||
|
||||
public void Set<T>(string key, T value)
|
||||
{
|
||||
SetBase(key, value);
|
||||
|
|
@ -134,6 +139,23 @@ namespace CatalogLib
|
|||
return (double)_settingsDict[key];
|
||||
}
|
||||
|
||||
public float GetFloat(string key, float defaultValue = 0)
|
||||
{
|
||||
if (!_settingsDict.ContainsKey(key))
|
||||
{
|
||||
SetFloat(key, defaultValue);
|
||||
}
|
||||
|
||||
if (_settingsDict[key] is float f) return f;
|
||||
MaddoLogger.LogError("Error while parsing {0}", key);
|
||||
|
||||
float fl = 0;
|
||||
SetFloat(key, float.TryParse(_settingsDict[key].ToString(), out f) ? fl : defaultValue);
|
||||
return (float) _settingsDict[key];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public T Get<T>(string key, T defaultValue)
|
||||
{
|
||||
if (!_settingsDict.ContainsKey(key))
|
||||
|
|
@ -146,6 +168,8 @@ namespace CatalogLib
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public string GetString(string key, string defaultValue = "")
|
||||
{
|
||||
if (!_settingsDict.ContainsKey(key))
|
||||
|
|
@ -184,7 +208,10 @@ namespace CatalogLib
|
|||
//return _settingsDict.ContainsKey(key) ? _settingsDict[key] : defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public T GetEnum<T>(string name, T defaultValue)
|
||||
{
|
||||
return (T)Enum.Parse(typeof(T), GetString(name, defaultValue.ToString()));
|
||||
}
|
||||
|
||||
public void SetDefaults()
|
||||
{
|
||||
|
|
@ -262,12 +289,8 @@ namespace CatalogLib
|
|||
get { return 0; }
|
||||
}
|
||||
|
||||
public string Posizione
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public DateTime DataPartenza { get; set; }
|
||||
public string TestoOrario { get; internal set; }
|
||||
public int DimStandard { get; internal set; }
|
||||
|
|
@ -290,7 +313,9 @@ namespace CatalogLib
|
|||
set { SetString("DirDestinazione", value); }
|
||||
}
|
||||
|
||||
public float Margine { get; set; }
|
||||
public float Margine { get => GetFloat("Margin", 1);
|
||||
set => SetFloat("Margin", value);
|
||||
}
|
||||
public float MargVert { get; set; }
|
||||
public string Allineamento { get; set; }
|
||||
|
||||
|
|
@ -432,8 +457,54 @@ namespace CatalogLib
|
|||
}
|
||||
}
|
||||
|
||||
public bool FotoRidimensiona
|
||||
{
|
||||
get => GetBool("FotoRidimensiona", false);
|
||||
set => Set("FotoRidimensiona", value);
|
||||
}
|
||||
|
||||
public Positions TextPosition
|
||||
{
|
||||
get => GetEnum("TextPosition", Positions.Alto); //(Positions)Enum.Parse(typeof(Positions), GetString("TextPosition", Positions.Alto.ToString()));
|
||||
set => SetString("TextPosition", value.ToString());
|
||||
}
|
||||
|
||||
public Alignments TextAlignment
|
||||
{
|
||||
get => GetEnum("TextAlignment", Alignments.Centro);
|
||||
set => SetString("TextAlignment", value.ToString());
|
||||
}
|
||||
|
||||
public bool Threading
|
||||
{
|
||||
get => GetBool("Threading", true);
|
||||
set => SetBool("Threading", value);
|
||||
}
|
||||
[Obsolete]
|
||||
public string Posizione
|
||||
{
|
||||
get => string.Empty;
|
||||
set { }
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum Positions
|
||||
{
|
||||
Alto,
|
||||
Basso
|
||||
}
|
||||
|
||||
public enum Alignments
|
||||
{
|
||||
Sinistra,
|
||||
Centro,
|
||||
Destra
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +65,7 @@
|
|||
<CheckBox Content="Forza JPG" x:Name="chkForzaJPG" IsChecked="{Binding GeneraleForzaJPG}" Margin="2"/>
|
||||
<CheckBox Content="Rotazione Automatica" x:Name="chkRotazioneAutomatica" IsChecked="{Binding GeneraleRotazioneAutomatica}" Margin="2"/>
|
||||
<CheckBox Content="Sovrascrivi File" x:Name="chkSovrascriviFile" IsChecked="{Binding GeneraleSovrascriviFile}" Margin="2"/>
|
||||
<CheckBox Content="MultiThreading" IsChecked="{Binding Threading}" Margin="2"></CheckBox>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
<GroupBox Header="Sottocartelle" Margin="2">
|
||||
|
|
@ -80,6 +81,7 @@
|
|||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition></RowDefinition>
|
||||
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox Grid.Row="0" Grid.Column="1" Content="Crea Sottocartelle" x:Name="chkCreaSottocartelle" Margin="4,0,0,0" IsChecked="{Binding SubdirCreaSottoCartelle}"/>
|
||||
|
|
@ -112,6 +114,7 @@
|
|||
</GroupBox.Header>
|
||||
<Grid >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
|
|
@ -125,16 +128,19 @@
|
|||
<ColumnDefinition Width="88*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="Altezza" Grid.ColumnSpan="2" Margin="0,0,0,2" />
|
||||
<TextBox Grid.Row="0" Grid.Column="2" Margin="4,4,4,6" Text="{Binding FotoAltezza}"/>
|
||||
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="Ridimensiona"></Label>
|
||||
<CheckBox Grid.Row="0" Grid.Column="2" IsChecked="{Binding FotoRidimensiona}"></CheckBox>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="Altezza" Grid.ColumnSpan="2" Margin="0,0,0,2" />
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Margin="4,4,4,6" Text="{Binding FotoAltezza}"/>
|
||||
|
||||
|
||||
<Label Grid.Column="0" Content="Larghezza" Grid.ColumnSpan="2" Margin="0,26,0,2" Grid.RowSpan="2" />
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Margin="4,2,4,6" Text="{Binding FotoLarghezza}"></TextBox>
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="Larghezza" Grid.ColumnSpan="2" Margin="0,26,0,2" Grid.RowSpan="2" />
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Margin="4,2,4,6" Text="{Binding FotoLarghezza}"></TextBox>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="Qualità" Grid.ColumnSpan="2" Margin="0,24,0,1" Grid.RowSpan="2" />
|
||||
<Label Grid.Row="2" Grid.Column="0" Content="Qualità" Grid.ColumnSpan="2" Margin="0,24,0,1" Grid.RowSpan="2" />
|
||||
<!--<TextBox Grid.Row="2" Grid.Column="2" Width="80" Margin="4,2,4,5" />-->
|
||||
<Grid Grid.Row="2" Grid.Column="2" >
|
||||
<Grid Grid.Row="3" Grid.Column="2" >
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="20"/>
|
||||
|
|
@ -144,11 +150,11 @@
|
|||
</Grid>
|
||||
|
||||
|
||||
<CheckBox Grid.Row="3" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,16,0,17.88" IsChecked="{Binding FotoMantieniDimensioni}"/>
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Grid.ColumnSpan="2" HorizontalAlignment="Left" Text="Mantieni Dimensioni Originali" TextWrapping="WrapWithOverflow" Margin="4,0,4,25.88" />
|
||||
<CheckBox Grid.Row="4" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,16,0,17.88" IsChecked="{Binding FotoMantieniDimensioni}"/>
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Grid.ColumnSpan="2" HorizontalAlignment="Left" Text="Mantieni Dimensioni Originali" TextWrapping="WrapWithOverflow" Margin="4,0,4,25.88" />
|
||||
|
||||
<Label Grid.Row="4" Grid.Column="0" Content="Suffisso" Grid.ColumnSpan="2" Margin="0,0.12,0,-0.12" />
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Width="80" Margin="4,4.12,4,3.88" Text="{Binding FotoSuffisso}" />
|
||||
<Label Grid.Row="5" Grid.Column="0" Content="Suffisso" Grid.ColumnSpan="2" Margin="0,0.12,0,-0.12" />
|
||||
<TextBox Grid.Row="5" Grid.Column="2" Margin="4,4.12,4,3.88" Text="{Binding FotoSuffisso}" />
|
||||
|
||||
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@
|
|||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="Orizzontale" />
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="Verticale" />
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TestoApplicareOrizzontale}"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TestoApplicareOrizzontale}" AcceptsReturn="True"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Height="50" MaxLines="4" AcceptsReturn="True" Text="{Binding TestoApplicareVerticale}"/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
|
|
@ -150,7 +150,7 @@
|
|||
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding TestoApplicareTempoGara}"/>
|
||||
|
||||
<Label Grid.Row="5" Grid.Column="0" Content="Margine (pixel)" />
|
||||
<TextBox Grid.Row="5" Grid.Column="1" Text="{Binding TestoApplicareMargine}"/>
|
||||
<TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Margine}"/>
|
||||
|
||||
<Label Grid.Row="6" Grid.Column="0" Content="Allineamento" />
|
||||
<TextBox Grid.Row="6" Grid.Column="1" Text="{Binding TestoApplicareAllineamento}"/>
|
||||
|
|
|
|||
|
|
@ -130,6 +130,8 @@ namespace WPFCatalog
|
|||
Task outerTask = OuterTask();
|
||||
|
||||
await outerTask;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async Task OuterTask()
|
||||
|
|
@ -140,7 +142,7 @@ namespace WPFCatalog
|
|||
// todo folder mode
|
||||
MaddoLogger.Log("Starting elaboration");
|
||||
var files = Directory.EnumerateFiles(PicSettings.DirectorySorgente).ToArray();
|
||||
|
||||
|
||||
TotalPictures = files.Count();
|
||||
foreach (var file in files)
|
||||
{
|
||||
|
|
@ -161,8 +163,13 @@ namespace WPFCatalog
|
|||
}
|
||||
s.Start();
|
||||
|
||||
|
||||
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
|
||||
|
||||
//Task.WhenAll(tasks).Start();
|
||||
s.Stop();
|
||||
//tt.RunSynchronously();
|
||||
|
|
@ -402,6 +409,16 @@ namespace WPFCatalog
|
|||
}
|
||||
}
|
||||
|
||||
public bool FotoRidimensiona
|
||||
{
|
||||
get { return PicSettings.FotoRidimensiona; }
|
||||
set
|
||||
{
|
||||
PicSettings.FotoRidimensiona = value;
|
||||
RaisePropertyChanged("FotoRidimensiona");
|
||||
}
|
||||
}
|
||||
|
||||
public int FotoAltezza
|
||||
{
|
||||
get
|
||||
|
|
@ -782,7 +799,17 @@ namespace WPFCatalog
|
|||
}
|
||||
}
|
||||
|
||||
public bool Threading
|
||||
{
|
||||
get => PicSettings.Threading;
|
||||
set { PicSettings.Threading = value; RaisePropertyChanged("Threading"); }
|
||||
}
|
||||
|
||||
public float Margine
|
||||
{
|
||||
get => PicSettings.Margine;
|
||||
set { PicSettings.Margine = value; RaisePropertyChanged("Margine"); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue