From 261bef0a01348b0d39bcb3a20d87b10ba9168b9b Mon Sep 17 00:00:00 2001 From: TakenPt Date: Mon, 29 Apr 2024 00:12:49 +0900 Subject: [PATCH 01/12] =?UTF-8?q?#28=20=E8=A1=A8=E7=B4=99=E7=94=A8?= =?UTF-8?q?=E3=81=AE=E7=94=BB=E5=83=8F=E3=81=AE=E7=94=9F=E6=88=90=E3=82=B5?= =?UTF-8?q?=E3=83=BC=E3=83=93=E3=82=B9=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ICreateCoverFileService.cs | 19 ++++++++ KoeBook/Services/CreateCoverFileService.cs | 47 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs create mode 100644 KoeBook/Services/CreateCoverFileService.cs diff --git a/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs b/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs new file mode 100644 index 0000000..7f92823 --- /dev/null +++ b/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KoeBook.Core.Contracts.Services; + +public interface ICreateCoverFileService +{ + /// + /// 表紙用の画像を作成 + /// + /// 作品の題名 + /// 作品の著者名 + /// 表紙の画像を置くフォルダのパス + /// 成功すれば、true、失敗すれば、false + bool TryCreate(string title, string author, string coverFilePath); +} diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs new file mode 100644 index 0000000..a239239 --- /dev/null +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -0,0 +1,47 @@ +using System.Drawing; +using System.Drawing.Imaging; +using KoeBook.Core.Contracts.Services; + +namespace KoeBook.Services; + +public class CreateCoverFileService : ICreateCoverFileService +{ + public bool TryCreate(string title, string author, string coverFilePath) + { + try + { + // ビットマップの作成 + using Bitmap bitmap = new Bitmap(1800, 2560); + using Graphics graphics = Graphics.FromImage(bitmap); + + // 塗りつぶし + graphics.FillRectangle(Brushes.PaleGoldenrod, graphics.VisibleClipBounds); + + // フォントの指定 + using Font titleFont = new Font("MS ゴシック", 125, FontStyle.Bold); + using Font authorFont = new Font("MS ゴシック", 75, FontStyle.Bold); + + // 色の指定 + using Brush brush = new SolidBrush(Color.Black); + + // 表示位置の指定 + using StringFormat stringFormat = new StringFormat(); + stringFormat.Alignment = StringAlignment.Center; + stringFormat.LineAlignment = StringAlignment.Center; + + // 文字の入力 + graphics.DrawString(title, titleFont, brush, new Rectangle(0, 0, 1800, 1920), stringFormat); + graphics.DrawString($"著者: {author}", authorFont, brush, new Rectangle(0, 1920, 1800, 640), stringFormat); + + // png として出力 + bitmap.Save(Path.Combine(coverFilePath, "cover.png"), ImageFormat.Png); + + return true; + } + catch + { + return false; + } + + } +} From 492e40e370773c57a9443dee19a823c85ea64b2c Mon Sep 17 00:00:00 2001 From: TakenPt Date: Mon, 29 Apr 2024 02:09:54 +0900 Subject: [PATCH 02/12] =?UTF-8?q?#28=20=E5=87=BA=E5=8A=9B=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=90=8D?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index a239239..f6a1aba 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -34,7 +34,7 @@ public bool TryCreate(string title, string author, string coverFilePath) graphics.DrawString($"著者: {author}", authorFont, brush, new Rectangle(0, 1920, 1800, 640), stringFormat); // png として出力 - bitmap.Save(Path.Combine(coverFilePath, "cover.png"), ImageFormat.Png); + bitmap.Save(Path.Combine(coverFilePath, "Cover.png"), ImageFormat.Png); return true; } From 97fab237a67433b678a89c0ddd800b9c8be239ef Mon Sep 17 00:00:00 2001 From: TakenPt Date: Mon, 29 Apr 2024 02:10:22 +0900 Subject: [PATCH 03/12] =?UTF-8?q?#28=20=E3=83=95=E3=82=A9=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index f6a1aba..fdfcbb2 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -18,8 +18,8 @@ public bool TryCreate(string title, string author, string coverFilePath) graphics.FillRectangle(Brushes.PaleGoldenrod, graphics.VisibleClipBounds); // フォントの指定 - using Font titleFont = new Font("MS ゴシック", 125, FontStyle.Bold); - using Font authorFont = new Font("MS ゴシック", 75, FontStyle.Bold); + using Font titleFont = new Font("游ゴシック Medium", 125, FontStyle.Bold); + using Font authorFont = new Font("游ゴシック Medium", 75, FontStyle.Bold); // 色の指定 using Brush brush = new SolidBrush(Color.Black); From 4bba22e4af1dfd6dceedbfb94cf86c8e68e1fd04 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Mon, 29 Apr 2024 13:11:39 +0900 Subject: [PATCH 04/12] =?UTF-8?q?#28=20=E3=83=95=E3=82=A9=E3=83=BC?= =?UTF-8?q?=E3=83=9E=E3=83=83=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index fdfcbb2..05fb64a 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -42,6 +42,6 @@ public bool TryCreate(string title, string author, string coverFilePath) { return false; } - + } } From 28a3e3b744ac57e0603b3dfe55fe249381a7c6e7 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 00:14:21 +0900 Subject: [PATCH 05/12] =?UTF-8?q?#28=20Try=E3=81=8B=E3=82=89=E4=BE=8B?= =?UTF-8?q?=E5=A4=96=E3=82=92=E6=8A=95=E3=81=92=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/Services/ICreateCoverFileService.cs | 2 +- KoeBook.Core/EbookException.cs | 3 +++ KoeBook/Services/CreateCoverFileService.cs | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs b/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs index 7f92823..1fc88fa 100644 --- a/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs +++ b/KoeBook.Core/Contracts/Services/ICreateCoverFileService.cs @@ -15,5 +15,5 @@ public interface ICreateCoverFileService /// 作品の著者名 /// 表紙の画像を置くフォルダのパス /// 成功すれば、true、失敗すれば、false - bool TryCreate(string title, string author, string coverFilePath); + void Create(string title, string author, string coverFilePath); } diff --git a/KoeBook.Core/EbookException.cs b/KoeBook.Core/EbookException.cs index a0e7647..69be09f 100644 --- a/KoeBook.Core/EbookException.cs +++ b/KoeBook.Core/EbookException.cs @@ -62,4 +62,7 @@ public enum ExceptionType /// [EnumMember(Value = "無効なURLです")] InvalidUrl, + + [EnumMember(Value = "表紙の画像の生成に失敗しました")] + CreateCoverFileFailed, } diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index 05fb64a..4aea3e7 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -1,12 +1,13 @@ using System.Drawing; using System.Drawing.Imaging; +using KoeBook.Core; using KoeBook.Core.Contracts.Services; namespace KoeBook.Services; public class CreateCoverFileService : ICreateCoverFileService { - public bool TryCreate(string title, string author, string coverFilePath) + public void Create(string title, string author, string coverFilePath) { try { @@ -36,11 +37,11 @@ public bool TryCreate(string title, string author, string coverFilePath) // png として出力 bitmap.Save(Path.Combine(coverFilePath, "Cover.png"), ImageFormat.Png); - return true; + return; } - catch + catch (Exception ex) { - return false; + throw new EbookException(ExceptionType.CreateCoverFileFailed, ex.Message); } } From b305babdd0c888cb4f9768e1cb8a0c2968a03b04 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 00:14:56 +0900 Subject: [PATCH 06/12] =?UTF-8?q?#28=20=E8=89=B2=E3=81=AE=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E3=81=ABBrushes.Black=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index 4aea3e7..1c06bb2 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -23,7 +23,7 @@ public void Create(string title, string author, string coverFilePath) using Font authorFont = new Font("游ゴシック Medium", 75, FontStyle.Bold); // 色の指定 - using Brush brush = new SolidBrush(Color.Black); + using var brush = Brushes.Black; // 表示位置の指定 using StringFormat stringFormat = new StringFormat(); From 0dc625b43be7c875e7e71cbed363bc8c191ae971 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 00:15:27 +0900 Subject: [PATCH 07/12] =?UTF-8?q?#28=20=E5=A4=89=E6=95=B0=E3=81=AE?= =?UTF-8?q?=E5=AE=A3=E8=A8=80=E3=81=ABvar=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index 1c06bb2..b3f6d8f 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -12,21 +12,21 @@ public void Create(string title, string author, string coverFilePath) try { // ビットマップの作成 - using Bitmap bitmap = new Bitmap(1800, 2560); - using Graphics graphics = Graphics.FromImage(bitmap); + using var bitmap = new Bitmap(1800, 2560); + using var graphics = Graphics.FromImage(bitmap); // 塗りつぶし graphics.FillRectangle(Brushes.PaleGoldenrod, graphics.VisibleClipBounds); // フォントの指定 - using Font titleFont = new Font("游ゴシック Medium", 125, FontStyle.Bold); - using Font authorFont = new Font("游ゴシック Medium", 75, FontStyle.Bold); + using var titleFont = new Font("游ゴシック Medium", 125, FontStyle.Bold); + using var authorFont = new Font("游ゴシック Medium", 75, FontStyle.Bold); // 色の指定 using var brush = Brushes.Black; // 表示位置の指定 - using StringFormat stringFormat = new StringFormat(); + using var stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; From 6ed50bbf903ad178dd30b978b328c1597a14832a Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 00:27:33 +0900 Subject: [PATCH 08/12] =?UTF-8?q?#28=20=E7=94=BB=E5=83=8F=E3=82=B5?= =?UTF-8?q?=E3=82=A4=E3=82=BA=E3=81=AE=E4=BF=AE=E6=AD=A3=E3=81=A8=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E6=95=B0=E5=80=A4=E3=81=AE=E7=90=86=E7=94=B1=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index b3f6d8f..fa6a667 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -12,7 +12,9 @@ public void Create(string title, string author, string coverFilePath) try { // ビットマップの作成 - using var bitmap = new Bitmap(1800, 2560); + // サイズはKindleガイドラインの推奨サイズによる + // https://kdp.amazon.co.jp/ja_JP/help/topic/G6GTK3T3NUHKLEFX + using var bitmap = new Bitmap(1600, 2560); using var graphics = Graphics.FromImage(bitmap); // 塗りつぶし @@ -31,8 +33,8 @@ public void Create(string title, string author, string coverFilePath) stringFormat.LineAlignment = StringAlignment.Center; // 文字の入力 - graphics.DrawString(title, titleFont, brush, new Rectangle(0, 0, 1800, 1920), stringFormat); - graphics.DrawString($"著者: {author}", authorFont, brush, new Rectangle(0, 1920, 1800, 640), stringFormat); + graphics.DrawString(title, titleFont, brush, new Rectangle(0, 0, 1600, 1920), stringFormat); + graphics.DrawString($"著者: {author}", authorFont, brush, new Rectangle(0, 1920, 1600, 640), stringFormat); // png として出力 bitmap.Save(Path.Combine(coverFilePath, "Cover.png"), ImageFormat.Png); From dda9dec2845b3a985ba2f1d5e27ab9662cbdcd47 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 13:05:55 +0900 Subject: [PATCH 09/12] =?UTF-8?q?#28=20=E6=9B=B8=E3=81=8D=E6=96=B9?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index fa6a667..43cca5e 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -28,9 +28,12 @@ public void Create(string title, string author, string coverFilePath) using var brush = Brushes.Black; // 表示位置の指定 - using var stringFormat = new StringFormat(); - stringFormat.Alignment = StringAlignment.Center; - stringFormat.LineAlignment = StringAlignment.Center; + using var stringFormat = new StringFormat() + { + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; + // 文字の入力 graphics.DrawString(title, titleFont, brush, new Rectangle(0, 0, 1600, 1920), stringFormat); @@ -38,8 +41,6 @@ public void Create(string title, string author, string coverFilePath) // png として出力 bitmap.Save(Path.Combine(coverFilePath, "Cover.png"), ImageFormat.Png); - - return; } catch (Exception ex) { From 9305120f657d67b9ace1f8ba4789ffd618402199 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 13:07:42 +0900 Subject: [PATCH 10/12] =?UTF-8?q?#28=20EbookException=E3=81=AEinnerExcepti?= =?UTF-8?q?on=E3=82=92=E6=8C=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index 43cca5e..656f9dc 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -44,7 +44,7 @@ public void Create(string title, string author, string coverFilePath) } catch (Exception ex) { - throw new EbookException(ExceptionType.CreateCoverFileFailed, ex.Message); + throw new EbookException(ExceptionType.CreateCoverFileFailed, ex.Message, ex); } } From 9578a582c029c8f00bffefb66e7a975ec43abd3f Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 13:14:08 +0900 Subject: [PATCH 11/12] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index 656f9dc..1d5226f 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -30,10 +30,9 @@ public void Create(string title, string author, string coverFilePath) // 表示位置の指定 using var stringFormat = new StringFormat() { - Alignment = StringAlignment.Center, + Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; - // 文字の入力 graphics.DrawString(title, titleFont, brush, new Rectangle(0, 0, 1600, 1920), stringFormat); From bcd178bd4e807d6254058af5d7231149687cbeb3 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 30 Apr 2024 17:41:43 +0900 Subject: [PATCH 12/12] =?UTF-8?q?#28=20using=20=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook/Services/CreateCoverFileService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KoeBook/Services/CreateCoverFileService.cs b/KoeBook/Services/CreateCoverFileService.cs index 1d5226f..6552e63 100644 --- a/KoeBook/Services/CreateCoverFileService.cs +++ b/KoeBook/Services/CreateCoverFileService.cs @@ -25,7 +25,7 @@ public void Create(string title, string author, string coverFilePath) using var authorFont = new Font("游ゴシック Medium", 75, FontStyle.Bold); // 色の指定 - using var brush = Brushes.Black; + var brush = Brushes.Black; // 表示位置の指定 using var stringFormat = new StringFormat()