Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 16x24 font, fix out of range look up for some fonts, minor font r… #947

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public byte[] this[char character]
var index = (byte)character;
if ((index < 32) || (index >= 127))
{
return _fontTable[0x20];
return _fontTable[0];
}
return _fontTable[(byte)character - 0x20];
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public byte[] this[char character]
var index = (byte)character;
if ((index < 32) || (index > 127))
{
return _fontTable[0x20];
return _fontTable[0];
}
return _fontTable[(byte)character - 0x20];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public byte[] this[char character]
var index = (byte)character;
if ((index < 32) || (index > 127))
{
return _fontTable[0x20];
return _fontTable[0];
}
return _fontTable[(byte)character - 0x20];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public byte[] this[char character]
var index = (byte)character;
if ((index < 32) || (index >= 127))
{
return _fontTable[0x20];
return _fontTable[0];
}
return _fontTable[(byte)character - 0x20];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public byte[] this[char character]
var index = (byte)character;
if ((index < 32) || (index > 127))
{
return _fontTable[0x20];
return _fontTable[0];
}
return _fontTable[(byte)character - 0x20];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public byte[] this[char character]
var index = (byte)character;
if ((index < 32) || (index > 127))
{
return _fontTable[0x20];
return _fontTable[0];
}
return _fontTable[(byte)character - 0x20];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1523,20 +1523,33 @@ private byte[] GetBytesForTextBitmap(string text, IFont font)
{
byte[] bitmap;

if (font.Width == 8) //just copy bytes
if (font.Width == 8)
{
bitmap = new byte[text.Length * font.Height * (font.Width >> 3)];
bitmap = new byte[text.Length * font.Height];

byte[] characterMap;
for (int i = 0; i < text.Length; i++)
{ //copy data for 1 character at a time going top to bottom
for (int j = 0; j < font.Height; j++)
{
bitmap[i + (j * text.Length)] = font[text[i]][j];
}
}
}
else if (font.Width == 16)
{
int len = text.Length * 2; // Each character takes up 2 bytes per row
bitmap = new byte[len * font.Height];
int bitmapIndex;

for (int i = 0; i < text.Length; i++)
{
characterMap = font[text[i]];
byte[] charMap = font[text[i]];

//copy data for 1 character at a time going top to bottom
for (int segment = 0; segment < font.Height; segment++)
{
bitmap[i + (segment * text.Length)] = characterMap[segment];
for (int j = 0; j < font.Height; j++)
{ // Calculate the starting index in the bitmap array for this row and character
bitmapIndex = (i * 2) + (j * len);
bitmap[bitmapIndex] = charMap[j * 2]; // First byte of the row
bitmap[bitmapIndex + 1] = charMap[j * 2 + 1]; // Second byte of the row
}
}
}
Expand Down Expand Up @@ -1574,14 +1587,7 @@ private byte[] GetBytesForTextBitmap(string text, IFont font)
}
else if (font.Width == 6)
{
var len = text.Length;

if (text.Length % 4 != 0)
{
len += 4 - (text.Length % 4); //character length
}
len = len * 3 / 4; //length in bytes

int len = (text.Length + 3) / 4 * 3; // Adjusted to handle padding in one line.
bitmap = new byte[len * font.Height];

byte[] charMap1, charMap2, charMap3, charMap4;
Expand Down Expand Up @@ -1643,7 +1649,7 @@ private byte[] GetBytesForTextBitmap(string text, IFont font)
}
else
{
throw new Exception("Font width must be 4, 6, 8, or 12");
throw new Exception("Font width must be 4, 6, 8, 12 or 16");
}
return bitmap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,28 @@ public class MeadowApp : App<Meadow.Windows>

public override Task Initialize()
{
display = new WinFormsDisplay(320, 240, displayScale: 1.5f);
display = new WinFormsDisplay(640, 480, displayScale: 1f);

graphics = new MicroGraphics(display)
{
CurrentFont = new Font12x20(),
CurrentFont = new Font16x24(),
Stroke = 1
};

_ = Task.Run(() =>
{
graphics.Clear();

graphics.DrawTriangle(10, 30, 50, 50, 10, 50, Color.Red);
graphics.DrawRectangle(20, 45, 40, 20, Color.Yellow, false);
graphics.DrawCircle(50, 50, 40, Color.Blue, false);
graphics.DrawText(5, 5, "Meadow on WinForms", Color.White);
graphics.DrawText(10, 10, "16x24 font on WinForms", Color.White);

graphics.DrawText(10, 40, "1234567890!@#$%^&*(){}[],./<>?;':", Color.LawnGreen);
graphics.DrawText(10, 70, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Color.Cyan);
graphics.DrawText(10, 100, "abcdefghijklmnopqrstuvwxyz", Color.Yellow);
graphics.DrawText(10, 130, "Temp: 21.5°C", Color.Orange);

graphics.DrawTriangle(10, 220, 50, 260, 10, 260, Color.Red);
graphics.DrawRectangle(20, 185, 80, 40, Color.Yellow, false);
graphics.DrawCircle(50, 240, 40, Color.Blue, false);

graphics.Show();
});
Expand Down
Loading