2015-02-20 01:57:10 +00:00
|
|
|
|
using ImageMagickSharp;
|
2015-03-09 03:56:42 +00:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2015-02-20 01:57:10 +00:00
|
|
|
|
using MediaBrowser.Model.Drawing;
|
2015-03-09 03:56:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2013-09-19 17:45:48 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Drawing
|
|
|
|
|
{
|
2014-01-01 18:26:31 +00:00
|
|
|
|
public class PlayedIndicatorDrawer
|
2013-09-19 17:45:48 +00:00
|
|
|
|
{
|
2015-02-20 01:57:10 +00:00
|
|
|
|
private const int FontSize = 52;
|
|
|
|
|
private const int OffsetFromTopRightCorner = 38;
|
2013-09-19 17:45:48 +00:00
|
|
|
|
|
2015-03-09 03:56:42 +00:00
|
|
|
|
private readonly IApplicationPaths _appPaths;
|
|
|
|
|
|
|
|
|
|
public PlayedIndicatorDrawer(IApplicationPaths appPaths)
|
|
|
|
|
{
|
|
|
|
|
_appPaths = appPaths;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-20 01:57:10 +00:00
|
|
|
|
public void DrawPlayedIndicator(MagickWand wand, ImageSize imageSize)
|
2013-09-19 17:45:48 +00:00
|
|
|
|
{
|
2015-02-20 01:57:10 +00:00
|
|
|
|
var x = imageSize.Width - OffsetFromTopRightCorner;
|
2013-09-19 17:45:48 +00:00
|
|
|
|
|
2015-02-20 01:57:10 +00:00
|
|
|
|
using (var draw = new DrawingWand())
|
2013-09-19 17:45:48 +00:00
|
|
|
|
{
|
2015-02-20 01:57:10 +00:00
|
|
|
|
using (PixelWand pixel = new PixelWand())
|
|
|
|
|
{
|
|
|
|
|
pixel.Color = "#52B54B";
|
|
|
|
|
pixel.Opacity = 0.2;
|
|
|
|
|
draw.FillColor = pixel;
|
|
|
|
|
draw.DrawCircle(x, OffsetFromTopRightCorner, x - 20, OffsetFromTopRightCorner - 20);
|
2013-09-19 17:45:48 +00:00
|
|
|
|
|
2015-02-20 01:57:10 +00:00
|
|
|
|
pixel.Opacity = 0;
|
|
|
|
|
pixel.Color = "white";
|
|
|
|
|
draw.FillColor = pixel;
|
2015-03-09 03:56:42 +00:00
|
|
|
|
draw.Font = ExtractFont("webdings.ttf", _appPaths);
|
2015-02-20 01:57:10 +00:00
|
|
|
|
draw.FontSize = FontSize;
|
|
|
|
|
draw.FontStyle = FontStyleType.NormalStyle;
|
|
|
|
|
draw.TextAlignment = TextAlignType.CenterAlign;
|
|
|
|
|
draw.FontWeight = FontWeightType.RegularStyle;
|
|
|
|
|
draw.TextAntialias = true;
|
|
|
|
|
draw.DrawAnnotation(x + 4, OffsetFromTopRightCorner + 14, "a");
|
2013-09-19 17:45:48 +00:00
|
|
|
|
|
2015-02-20 01:57:10 +00:00
|
|
|
|
draw.FillColor = pixel;
|
|
|
|
|
wand.CurrentImage.DrawImage(draw);
|
2013-09-19 17:45:48 +00:00
|
|
|
|
}
|
2015-03-09 03:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ExtractFont(string name, IApplicationPaths paths)
|
|
|
|
|
{
|
|
|
|
|
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
|
|
|
|
|
|
|
|
|
|
if (File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
|
|
|
|
|
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
|
|
|
|
|
|
|
|
|
|
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
|
|
|
|
{
|
|
|
|
|
stream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-20 01:57:10 +00:00
|
|
|
|
|
2015-03-09 03:56:42 +00:00
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Copy(tempPath, filePath, false);
|
2013-09-19 17:45:48 +00:00
|
|
|
|
}
|
2015-03-09 03:56:42 +00:00
|
|
|
|
catch (IOException)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tempPath;
|
2013-09-19 17:45:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|