embed fonts
This commit is contained in:
parent
e70e06f0ac
commit
2caf01f43b
|
@ -282,13 +282,13 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
{
|
{
|
||||||
var currentImageSize = new ImageSize(imageWidth, imageHeight);
|
var currentImageSize = new ImageSize(imageWidth, imageHeight);
|
||||||
|
|
||||||
new PlayedIndicatorDrawer().DrawPlayedIndicator(wand, currentImageSize);
|
new PlayedIndicatorDrawer(_appPaths).DrawPlayedIndicator(wand, currentImageSize);
|
||||||
}
|
}
|
||||||
else if (options.UnplayedCount.HasValue)
|
else if (options.UnplayedCount.HasValue)
|
||||||
{
|
{
|
||||||
var currentImageSize = new ImageSize(imageWidth, imageHeight);
|
var currentImageSize = new ImageSize(imageWidth, imageHeight);
|
||||||
|
|
||||||
new UnplayedCountIndicator().DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
|
new UnplayedCountIndicator(_appPaths).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.PercentPlayed > 0)
|
if (options.PercentPlayed > 0)
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
using ImageMagickSharp;
|
using ImageMagickSharp;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Model.Drawing;
|
using MediaBrowser.Model.Drawing;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Drawing
|
namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
{
|
{
|
||||||
|
@ -8,6 +11,13 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
private const int FontSize = 52;
|
private const int FontSize = 52;
|
||||||
private const int OffsetFromTopRightCorner = 38;
|
private const int OffsetFromTopRightCorner = 38;
|
||||||
|
|
||||||
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
|
||||||
|
public PlayedIndicatorDrawer(IApplicationPaths appPaths)
|
||||||
|
{
|
||||||
|
_appPaths = appPaths;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawPlayedIndicator(MagickWand wand, ImageSize imageSize)
|
public void DrawPlayedIndicator(MagickWand wand, ImageSize imageSize)
|
||||||
{
|
{
|
||||||
var x = imageSize.Width - OffsetFromTopRightCorner;
|
var x = imageSize.Width - OffsetFromTopRightCorner;
|
||||||
|
@ -24,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
pixel.Opacity = 0;
|
pixel.Opacity = 0;
|
||||||
pixel.Color = "white";
|
pixel.Color = "white";
|
||||||
draw.FillColor = pixel;
|
draw.FillColor = pixel;
|
||||||
draw.Font = "Webdings";
|
draw.Font = ExtractFont("webdings.ttf", _appPaths);
|
||||||
draw.FontSize = FontSize;
|
draw.FontSize = FontSize;
|
||||||
draw.FontStyle = FontStyleType.NormalStyle;
|
draw.FontStyle = FontStyleType.NormalStyle;
|
||||||
draw.TextAlignment = TextAlignType.CenterAlign;
|
draw.TextAlignment = TextAlignType.CenterAlign;
|
||||||
|
@ -35,8 +45,42 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
draw.FillColor = pixel;
|
draw.FillColor = pixel;
|
||||||
wand.CurrentImage.DrawImage(draw);
|
wand.CurrentImage.DrawImage(draw);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Copy(tempPath, filePath, false);
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return tempPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Globalization;
|
using ImageMagickSharp;
|
||||||
using ImageMagickSharp;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Model.Drawing;
|
using MediaBrowser.Model.Drawing;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Drawing
|
namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
{
|
{
|
||||||
|
@ -8,6 +9,13 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
{
|
{
|
||||||
private const int OffsetFromTopRightCorner = 38;
|
private const int OffsetFromTopRightCorner = 38;
|
||||||
|
|
||||||
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
|
||||||
|
public UnplayedCountIndicator(IApplicationPaths appPaths)
|
||||||
|
{
|
||||||
|
_appPaths = appPaths;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count)
|
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count)
|
||||||
{
|
{
|
||||||
var x = imageSize.Width - OffsetFromTopRightCorner;
|
var x = imageSize.Width - OffsetFromTopRightCorner;
|
||||||
|
@ -25,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
pixel.Opacity = 0;
|
pixel.Opacity = 0;
|
||||||
pixel.Color = "white";
|
pixel.Color = "white";
|
||||||
draw.FillColor = pixel;
|
draw.FillColor = pixel;
|
||||||
draw.Font = "Sans-Serif";
|
draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths);
|
||||||
draw.FontStyle = FontStyleType.NormalStyle;
|
draw.FontStyle = FontStyleType.NormalStyle;
|
||||||
draw.TextAlignment = TextAlignType.CenterAlign;
|
draw.TextAlignment = TextAlignType.CenterAlign;
|
||||||
draw.FontWeight = FontWeightType.RegularStyle;
|
draw.FontWeight = FontWeightType.RegularStyle;
|
||||||
|
@ -36,7 +44,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
|
|
||||||
if (text.Length == 1)
|
if (text.Length == 1)
|
||||||
{
|
{
|
||||||
x += 2;
|
x += 1;
|
||||||
}
|
}
|
||||||
else if (text.Length == 2)
|
else if (text.Length == 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -426,6 +426,8 @@
|
||||||
<EmbeddedResource Include="Localization\JavaScript\uk.json" />
|
<EmbeddedResource Include="Localization\JavaScript\uk.json" />
|
||||||
<EmbeddedResource Include="Localization\Server\bg_BG.json" />
|
<EmbeddedResource Include="Localization\Server\bg_BG.json" />
|
||||||
<EmbeddedResource Include="Localization\Server\uk.json" />
|
<EmbeddedResource Include="Localization\Server\uk.json" />
|
||||||
|
<EmbeddedResource Include="Drawing\fonts\webdings.ttf" />
|
||||||
|
<EmbeddedResource Include="Drawing\fonts\robotoregular.ttf" />
|
||||||
<None Include="Localization\JavaScript\sl_SI.json" />
|
<None Include="Localization\JavaScript\sl_SI.json" />
|
||||||
<EmbeddedResource Include="Localization\Server\sl_SI.json" />
|
<EmbeddedResource Include="Localization\Server\sl_SI.json" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user