Skip to content

Commit

Permalink
Add NDX font
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-muffin committed May 31, 2024
1 parent 4ee3515 commit ee750fd
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 47 deletions.
166 changes: 163 additions & 3 deletions TranslationApp/TextPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string, Color> colors = new Dictionary<string, Color> {
{ "<Blue>", Color.FromArgb(0x50,0x50,0x80) },
{ "<Red>", Color.FromArgb(0x80,0x48,0x40) },
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -145,13 +149,163 @@ 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()
{
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;
Expand All @@ -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["<White>"]; // Start as white text
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion TranslationApp/TranslationApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="res\font_atlas.png" />
<EmbeddedResource Include="res\tor_font_atlas.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="res\ndx_font_atlas.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
45 changes: 2 additions & 43 deletions TranslationApp/fMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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<string, Color>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down
Binary file added TranslationApp/res/ndx_font_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes

0 comments on commit ee750fd

Please sign in to comment.