From 61f8ab73b6dff2299850715ba2f5842e6b4025fe Mon Sep 17 00:00:00 2001 From: hopto-dot <66906618+hopto-dot@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:23:14 +0000 Subject: [PATCH] More options --- LNConverter/Form1.Designer.cs | 133 ++++++++++++++++++++++++++++++++-- LNConverter/Form1.cs | 72 ++++++++++++++---- LNConverter/Form1.resx | 45 ++++++++++++ 3 files changed, 232 insertions(+), 18 deletions(-) diff --git a/LNConverter/Form1.Designer.cs b/LNConverter/Form1.Designer.cs index 9415835..5c03124 100644 --- a/LNConverter/Form1.Designer.cs +++ b/LNConverter/Form1.Designer.cs @@ -35,6 +35,15 @@ private void InitializeComponent() this.btnConvert = new System.Windows.Forms.Button(); this.lblTitle = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.cbMoveHtml = new System.Windows.Forms.CheckBox(); + this.cbxAlignment = new System.Windows.Forms.ComboBox(); + this.cbTategaki = new System.Windows.Forms.CheckBox(); + this.lblTextAlignment = new System.Windows.Forms.Label(); + this.cbMoveCover = new System.Windows.Forms.CheckBox(); + this.lblFontSize = new System.Windows.Forms.Label(); + this.tbxFontSize = new System.Windows.Forms.TextBox(); + this.lbPx = new System.Windows.Forms.Label(); + this.cbDarkMode = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // @@ -54,12 +63,13 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.tbxFilePath.Location = new System.Drawing.Point(148, 6); this.tbxFilePath.Name = "tbxFilePath"; - this.tbxFilePath.Size = new System.Drawing.Size(473, 27); + this.tbxFilePath.Size = new System.Drawing.Size(607, 27); this.tbxFilePath.TabIndex = 1; // // openFileDialog1 // this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.Multiselect = true; // // btnConvert // @@ -76,14 +86,15 @@ private void InitializeComponent() this.lblTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lblTitle.Font = new System.Drawing.Font("Segoe UI", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.lblTitle.Location = new System.Drawing.Point(13, 80); + this.lblTitle.Location = new System.Drawing.Point(13, 89); this.lblTitle.Name = "lblTitle"; - this.lblTitle.Size = new System.Drawing.Size(608, 30); + this.lblTitle.Size = new System.Drawing.Size(742, 30); this.lblTitle.TabIndex = 3; this.lblTitle.Text = "[title]"; // // pictureBox1 // + this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); this.pictureBox1.Location = new System.Drawing.Point(13, 122); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(170, 237); @@ -91,17 +102,120 @@ private void InitializeComponent() this.pictureBox1.TabIndex = 4; this.pictureBox1.TabStop = false; // + // cbMoveHtml + // + this.cbMoveHtml.AutoSize = true; + this.cbMoveHtml.Checked = true; + this.cbMoveHtml.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbMoveHtml.Location = new System.Drawing.Point(204, 122); + this.cbMoveHtml.Name = "cbMoveHtml"; + this.cbMoveHtml.Size = new System.Drawing.Size(244, 24); + this.cbMoveHtml.TabIndex = 5; + this.cbMoveHtml.Text = "Move .html inside images folder"; + this.cbMoveHtml.UseVisualStyleBackColor = true; + // + // cbxAlignment + // + this.cbxAlignment.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append; + this.cbxAlignment.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; + this.cbxAlignment.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbxAlignment.FormattingEnabled = true; + this.cbxAlignment.Items.AddRange(new object[] { + "Center", + "Left", + "Right"}); + this.cbxAlignment.Location = new System.Drawing.Point(312, 182); + this.cbxAlignment.Name = "cbxAlignment"; + this.cbxAlignment.Size = new System.Drawing.Size(72, 28); + this.cbxAlignment.TabIndex = 6; + // + // cbTategaki + // + this.cbTategaki.AutoSize = true; + this.cbTategaki.Location = new System.Drawing.Point(204, 285); + this.cbTategaki.Name = "cbTategaki"; + this.cbTategaki.Size = new System.Drawing.Size(109, 24); + this.cbTategaki.TabIndex = 7; + this.cbTategaki.Text = "Vertical text"; + this.cbTategaki.UseVisualStyleBackColor = true; + // + // lblTextAlignment + // + this.lblTextAlignment.AutoSize = true; + this.lblTextAlignment.Location = new System.Drawing.Point(201, 185); + this.lblTextAlignment.Name = "lblTextAlignment"; + this.lblTextAlignment.Size = new System.Drawing.Size(108, 20); + this.lblTextAlignment.TabIndex = 8; + this.lblTextAlignment.Text = "Text Alignment"; + // + // cbMoveCover + // + this.cbMoveCover.AutoSize = true; + this.cbMoveCover.Checked = true; + this.cbMoveCover.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbMoveCover.Location = new System.Drawing.Point(204, 152); + this.cbMoveCover.Name = "cbMoveCover"; + this.cbMoveCover.Size = new System.Drawing.Size(247, 24); + this.cbMoveCover.TabIndex = 5; + this.cbMoveCover.Text = "Move cover inside images folder"; + this.cbMoveCover.UseVisualStyleBackColor = true; + // + // lblFontSize + // + this.lblFontSize.AutoSize = true; + this.lblFontSize.Location = new System.Drawing.Point(201, 222); + this.lblFontSize.Name = "lblFontSize"; + this.lblFontSize.Size = new System.Drawing.Size(66, 20); + this.lblFontSize.TabIndex = 8; + this.lblFontSize.Text = "Font size"; + // + // tbxFontSize + // + this.tbxFontSize.Location = new System.Drawing.Point(269, 219); + this.tbxFontSize.Name = "tbxFontSize"; + this.tbxFontSize.Size = new System.Drawing.Size(29, 27); + this.tbxFontSize.TabIndex = 9; + // + // lbPx + // + this.lbPx.AutoSize = true; + this.lbPx.Location = new System.Drawing.Point(298, 222); + this.lbPx.Name = "lbPx"; + this.lbPx.Size = new System.Drawing.Size(25, 20); + this.lbPx.TabIndex = 8; + this.lbPx.Text = "px"; + // + // cbDarkMode + // + this.cbDarkMode.AutoSize = true; + this.cbDarkMode.Location = new System.Drawing.Point(204, 255); + this.cbDarkMode.Name = "cbDarkMode"; + this.cbDarkMode.Size = new System.Drawing.Size(105, 24); + this.cbDarkMode.TabIndex = 7; + this.cbDarkMode.Text = "Dark mode"; + this.cbDarkMode.UseVisualStyleBackColor = true; + // // Form1 // + this.AcceptButton = this.btnConvert; this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(633, 367); + this.ClientSize = new System.Drawing.Size(767, 372); + this.Controls.Add(this.cbxAlignment); + this.Controls.Add(this.tbxFontSize); + this.Controls.Add(this.lbPx); + this.Controls.Add(this.lblFontSize); + this.Controls.Add(this.lblTextAlignment); + this.Controls.Add(this.cbDarkMode); + this.Controls.Add(this.cbTategaki); + this.Controls.Add(this.cbMoveCover); + this.Controls.Add(this.cbMoveHtml); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.lblTitle); this.Controls.Add(this.btnConvert); this.Controls.Add(this.tbxFilePath); this.Controls.Add(this.btnSelectFile); - this.MinimumSize = new System.Drawing.Size(400, 266); + this.MinimumSize = new System.Drawing.Size(517, 365); this.Name = "Form1"; this.Text = "LNConverter"; this.Load += new System.EventHandler(this.Form1_Load); @@ -119,6 +233,15 @@ private void InitializeComponent() private System.Windows.Forms.Button btnConvert; private System.Windows.Forms.Label lblTitle; private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.CheckBox cbMoveHtml; + private System.Windows.Forms.ComboBox cbxAlignment; + private System.Windows.Forms.CheckBox cbTategaki; + private System.Windows.Forms.Label lblTextAlignment; + private System.Windows.Forms.CheckBox cbMoveCover; + private System.Windows.Forms.Label lblFontSize; + private System.Windows.Forms.TextBox tbxFontSize; + private System.Windows.Forms.Label lbPx; + private System.Windows.Forms.CheckBox cbDarkMode; } } diff --git a/LNConverter/Form1.cs b/LNConverter/Form1.cs index 176a4cc..ceedce8 100644 --- a/LNConverter/Form1.cs +++ b/LNConverter/Form1.cs @@ -18,6 +18,12 @@ public Form1() private void Form1_Load(object sender, EventArgs e) { lblTitle.Text = ""; + tbxFilePath.Text = System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/"); + + foreach (InputLanguage language in InputLanguage.InstalledInputLanguages) + { + if (language.LayoutName == "日本語") { btnSelectFile.Text = "ファイルを選択"; btnConvert.Text = "変換"; lblTextAlignment.Text = "文字揃え"; lblFontSize.Text = "フォントサイズ"; cbDarkMode.Text = "ダークモード"; cbTategaki.Text = "縦書き"; cbMoveHtml.Text = "imagesというフォルダに.htmlを移動"; cbMoveCover.Text = "imagesというフォルダに表紙を移動"; cbxAlignment.Location = new Point(270, 182); tbxFontSize.Location = new Point(287, 219); lbPx.Location = new Point(316, 222); } // :) + } } String FilePath = ""; @@ -26,6 +32,7 @@ private void Form1_Load(object sender, EventArgs e) private void btnSelectFile_Click(object sender, EventArgs e) { OpenFileDialog OpenFile = new OpenFileDialog(); + OpenFile.Multiselect = true; OpenFile.RestoreDirectory = true; OpenFile.Filter = "Epub Files|*.epub"; if (OpenFile.ShowDialog() == DialogResult.OK) @@ -47,6 +54,17 @@ private void btnSelectFile_Click(object sender, EventArgs e) lblTitle.Text = Epub.Title; byte[] coverImageContent = Epub.CoverImage; + if (coverImageContent == null && Epub.Content.Images.Count != 0) + { + try + { + var contentFile = Epub.Content.Images["cover1.jpeg"]; + coverImageContent = contentFile.Content; + } + catch {} + + } + if (coverImageContent != null) { using (MemoryStream coverImageStream = new MemoryStream(coverImageContent)) @@ -58,6 +76,7 @@ private void btnSelectFile_Click(object sender, EventArgs e) } else { + pictureBox1.Image = null; return; } } @@ -124,16 +143,44 @@ private void btnConvert_Click(object sender, EventArgs e) //{ // goto SkipSave; //} - - File.Move(imageFile.FileName.Replace("images/", ""), OutputLocation + Epub.Title + "/" + imageFile.FileName, true); - SkipSave:; + string imageMovePath = cbMoveCover.Checked && imageFile.FileName.ToLower().Contains("cover") ? OutputLocation + Epub.Title + "/images/" + imageFile.FileName : OutputLocation + Epub.Title + "/" + imageFile.FileName; + File.Move(imageFile.FileName.Replace("images/", ""), imageMovePath, true); + //SkipSave:; } } } HTMLConvert = HTMLConvert.Replace("\n", ""); - File.Create(OutputLocation + Epub.Title + ".html").Dispose(); - using (StreamWriter writer = new StreamWriter(System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/") + Epub.Title + ".html")) + if (cbxAlignment.Text != "") { + HTMLConvert = HTMLConvert.Replace("text-align: center;", cbxAlignment.Text.ToLower()); + HTMLConvert = HTMLConvert.Replace("text-align: left;", cbxAlignment.Text.ToLower()); + HTMLConvert = HTMLConvert.Replace("text-align: right;", cbxAlignment.Text.ToLower()); + } + string fontSizeText = string.Empty; + if (tbxFontSize.Text != "") + { + fontSizeText = "body {" + $"font-size: {tbxFontSize.Text}px; "; + HTMLConvert = HTMLConvert.Replace("body {", fontSizeText); + } + + string bodyReplacer = "
= 650) + if (this.Size.Height <= 410) { - pictureBox1.Width = 340; - pictureBox1.Height = 474; - } - else if (this.Size.Height <= 400) - { - pictureBox1.Width = 170 / 2; - pictureBox1.Height = 237 / 2; + pictureBox1.Width = 123; + pictureBox1.Height = 183; } else { @@ -158,6 +200,10 @@ private void Form1_Resize(object sender, EventArgs e) pictureBox1.Height = 237; } } + + + } + } diff --git a/LNConverter/Form1.resx b/LNConverter/Form1.resx index 0cb17ca..fb92c7c 100644 --- a/LNConverter/Form1.resx +++ b/LNConverter/Form1.resx @@ -57,6 +57,51 @@