diff --git a/TranslationApp/TextPreview.cs b/TranslationApp/TextPreview.cs index 89b2842..dfd8a43 100644 --- a/TranslationApp/TextPreview.cs +++ b/TranslationApp/TextPreview.cs @@ -5,7 +5,9 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -18,6 +20,8 @@ public partial class TextPreview : PictureBox public Bitmap fontAtlasImage { get; set; } public string text { get; set; } + private font_glyph[] glyphs; + private static readonly Dictionary colors = new Dictionary { { "", Color.FromArgb(0x50,0x50,0x80) }, { "", Color.FromArgb(0x80,0x48,0x40) }, @@ -45,7 +49,7 @@ public font_glyph(byte x, byte y) } #region Glyph width data - private readonly font_glyph[] glyphs = new font_glyph[97] + private readonly font_glyph[] tor_glyphs = new font_glyph[97] { /* */ new font_glyph(10, 00), /* 0 */ new font_glyph(05, 05), @@ -145,6 +149,107 @@ public font_glyph(byte x, byte y) /* 、 */ new font_glyph(00, 13), /* 。 */ new font_glyph(01, 12), }; + + private readonly font_glyph[] ndx_glyphs = new font_glyph[97] + { + /* */ new font_glyph(10, 00), + /* 0 */ new font_glyph(06, 06), + /* 1 */ new font_glyph(08, 10), + /* 2 */ new font_glyph(06, 06), + /* 3 */ new font_glyph(06, 06), + /* 4 */ new font_glyph(06, 06), + /* 5 */ new font_glyph(06, 06), + /* 6 */ new font_glyph(06, 06), + /* 7 */ new font_glyph(06, 06), + /* 8 */ new font_glyph(06, 06), + /* 9 */ new font_glyph(06, 06), + /* A */ new font_glyph(03, 03), + /* B */ new font_glyph(06, 05), + /* C */ new font_glyph(05, 04), + /* D */ new font_glyph(05, 04), + /* E */ new font_glyph(06, 05), + /* F */ new font_glyph(06, 05), + /* G */ new font_glyph(05, 04), + /* H */ new font_glyph(05, 05), + /* I */ new font_glyph(10, 10), + /* J */ new font_glyph(07, 06), + /* K */ new font_glyph(05, 04), + /* L */ new font_glyph(06, 06), + /* M */ new font_glyph(04, 04), + /* N */ new font_glyph(05, 04), + /* O */ new font_glyph(05, 04), + /* P */ new font_glyph(06, 05), + /* Q */ new font_glyph(04, 03), + /* R */ new font_glyph(06, 05), + /* S */ new font_glyph(06, 05), + /* T */ new font_glyph(04, 04), + /* U */ new font_glyph(05, 05), + /* V */ new font_glyph(04, 04), + /* W */ new font_glyph(02, 02), + /* X */ new font_glyph(04, 04), + /* Y */ new font_glyph(05, 05), + /* Z */ new font_glyph(05, 05), + /* a */ new font_glyph(06, 06), + /* b */ new font_glyph(06, 05), + /* c */ new font_glyph(07, 06), + /* d */ new font_glyph(07, 05), + /* e */ new font_glyph(07, 07), + /* f */ new font_glyph(08, 07), + /* g */ new font_glyph(06, 05), + /* h */ new font_glyph(06, 06), + /* i */ new font_glyph(10, 10), + /* j */ new font_glyph(08, 09), + /* k */ new font_glyph(06, 05), + /* l */ new font_glyph(10, 09), + /* m */ new font_glyph(04, 02), + /* n */ new font_glyph(06, 06), + /* o */ new font_glyph(06, 06), + /* p */ new font_glyph(06, 05), + /* q */ new font_glyph(06, 05), + /* r */ new font_glyph(08, 07), + /* s */ new font_glyph(08, 07), + /* t */ new font_glyph(08, 07), + /* u */ new font_glyph(06, 07), + /* v */ new font_glyph(06, 06), + /* w */ new font_glyph(03, 03), + /* x */ new font_glyph(06, 08), + /* y */ new font_glyph(05, 07), + /* z */ new font_glyph(06, 07), + /* , */ new font_glyph(09, 09), + /* . */ new font_glyph(09, 09), + /* ・ */ new font_glyph(09, 09), + /* : */ new font_glyph(09, 09), + /* ; */ new font_glyph(09, 09), + /* ? */ new font_glyph(06, 05), + /* ! */ new font_glyph(09, 09), + /* / */ new font_glyph(06, 06), + /* ( */ new font_glyph(09, 08), + /* ) */ new font_glyph(09, 08), + /* [ */ new font_glyph(09, 08), + /* ] */ new font_glyph(09, 08), + /* { */ new font_glyph(09, 08), + /* } */ new font_glyph(09, 08), + /* + */ new font_glyph(04, 03), + /* - */ new font_glyph(08, 08), + /* = */ new font_glyph(04, 03), + /* < */ new font_glyph(06, 06), + /* > */ new font_glyph(06, 06), + /* % */ new font_glyph(04, 03), + /* # */ new font_glyph(04, 04), + /* & */ new font_glyph(04, 03), + /* * */ new font_glyph(04, 04), + /* @ */ new font_glyph(00, 01), + /* | */ new font_glyph(08, 08), + /* ” */ new font_glyph(01, 15), + /* ’ */ new font_glyph(01, 18), + /* ^ */ new font_glyph(07, 06), + /* 「 */ new font_glyph(10, 01), + /* 」 */ new font_glyph(01, 11), + /* 〜 */ new font_glyph(05, 06), + /* _ */ new font_glyph(06, 05), + /* 、 */ new font_glyph(00, 13), + /* 。 */ new font_glyph(01, 12), + }; #endregion public TextPreview() @@ -152,6 +257,55 @@ public TextPreview() InitializeComponent(); } + public void ChangeImage(string id) + { + string res; + switch (id) + { + case "TOR": + res = "TranslationApp.res.tor_font_atlas.png"; + BackColor = Color.FromArgb(0); + glyphs = tor_glyphs; + break; + case "NDX": + res = "TranslationApp.res.ndx_font_atlas.png"; + BackColor = Color.FromArgb(0x14, 0x3F, 0x60); + glyphs = ndx_glyphs; + break; + default: + fontAtlasImage = null; + glyphs = null; + return; + } + + if (fontAtlasImage != null) + { + fontAtlasImage.Dispose(); + } + + fontAtlasImage = LoadEmbeddedImage(res); + } + + private Bitmap LoadEmbeddedImage(string resourceName) + { + try + { + using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) + { + if (manifestResourceStream != null) + { + return new Bitmap(manifestResourceStream); + } + MessageBox.Show("Failed to load embedded image."); + } + } + catch (Exception ex) + { + MessageBox.Show("Error loading embedded image: " + ex.Message); + } + return null; + } + public void ReDraw(string text) { this.text = text; @@ -173,7 +327,7 @@ private void TextPreview_Paint(object sender, PaintEventArgs e) g.SmoothingMode = SmoothingMode.HighQuality; // Initial state - PointF currentPosition = new PointF(0, 0); // Starting position + PointF currentPosition = new PointF(10, 10); // Starting position g.ScaleTransform(0.75f, 0.75f); // Scale down the size string textToRender = text == null ? "" : text; // Avoid null text Color tintColor = colors[""]; // Start as white text @@ -274,7 +428,7 @@ private void TextPreview_Paint(object sender, PaintEventArgs e) // Update the current position for the next character if (line) { - currentPosition.X = 0; + currentPosition.X = 10; currentPosition.Y += 24; } else @@ -330,6 +484,9 @@ private Rectangle GetCharacterRectangleFromAtlas(int character, out int s, out b case '+': index = 77; break; + case '&': + index = 84; + break; case '*': index = 85; break; @@ -381,6 +538,9 @@ private Rectangle GetCharacterRectangleFromAtlas(int character, out int s, out b case '>': index = 81; break; + case '%': + index = 82; + break; default: index = 0; break; diff --git a/TranslationApp/TranslationApp.csproj b/TranslationApp/TranslationApp.csproj index 63ed07f..dd95ba2 100644 --- a/TranslationApp/TranslationApp.csproj +++ b/TranslationApp/TranslationApp.csproj @@ -175,7 +175,10 @@ - + + + + diff --git a/TranslationApp/fMain.cs b/TranslationApp/fMain.cs index 84ac689..81a77eb 100644 --- a/TranslationApp/fMain.cs +++ b/TranslationApp/fMain.cs @@ -76,7 +76,6 @@ private void fMain_Load(object sender, EventArgs e) config = new Config(); config.Load(); PackingAssistant = new PackingProject(); - textPreview1.fontAtlasImage = LoadEmbeddedImage("TranslationApp.res.font_atlas.png"); } private void PopulateProjectTypes() @@ -101,6 +100,7 @@ private void LoadNewFolder_Click(object sender, EventArgs e) ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender; ProjectEntry pe = (ProjectEntry)clickedItem.Tag; LoadNewFolder(pe.shortName, pe.folder); + textPreview1.ChangeImage(pe.shortName); UpdateTitle(pe.fullName); } @@ -109,6 +109,7 @@ private void LoadLastFolder_Click(object sender, EventArgs e) ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender; ProjectEntry pe = (ProjectEntry)clickedItem.Tag; LoadLastFolder(pe.shortName); + textPreview1.ChangeImage(pe.shortName); UpdateTitle(pe.fullName); } @@ -124,26 +125,6 @@ private void UpdateTitle(string name) } } - private Bitmap LoadEmbeddedImage(string resourceName) - { - try - { - using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) - { - if (manifestResourceStream != null) - { - return new Bitmap(manifestResourceStream); - } - MessageBox.Show("Failed to load embedded image."); - } - } - catch (Exception ex) - { - MessageBox.Show("Error loading embedded image: " + ex.Message); - } - return null; - } - private void CreateColorByStatusDictionnary() { ColorByStatus = new Dictionary @@ -1304,12 +1285,6 @@ private void setEmpty(ListBox lb) } } - private void pictureBox1_Paint(object sender, PaintEventArgs e) - { - - } - - private void cbStatus_SelectionChangeCommitted(object sender, EventArgs e) { @@ -1464,17 +1439,6 @@ private void setSectionAsDoneToolStripMenuItem_Click(object sender, EventArgs e) cbFileList.Text = "___"; } - private void loadLastFolderToolStripMenuItem_Click(object sender, EventArgs e) - { - LoadLastFolder("TOH"); - } - - private void loadNewFolderToolStripMenuItem_Click(object sender, EventArgs e) - { - LoadNewFolder("TOH", "/2_translated"); - - } - private void bSearch_Click(object sender, EventArgs e) { string textToFind = tbSearch.Text.Replace("\r\n", "\n"); @@ -1486,11 +1450,6 @@ private void bSearch_Click(object sender, EventArgs e) $"{x.Section} - {x.Id}").ToList(); } - private void lbSearch_SelectedIndexChanged(object sender, EventArgs e) - { - - } - private void lNbOtherTranslations_Click(object sender, EventArgs e) { tabSearchMass.SelectedIndex = 1; diff --git a/TranslationApp/res/ndx_font_atlas.png b/TranslationApp/res/ndx_font_atlas.png new file mode 100644 index 0000000..3dd37c2 Binary files /dev/null and b/TranslationApp/res/ndx_font_atlas.png differ diff --git a/TranslationApp/res/font_atlas.png b/TranslationApp/res/tor_font_atlas.png similarity index 100% rename from TranslationApp/res/font_atlas.png rename to TranslationApp/res/tor_font_atlas.png