Memory Optimisation

This commit is contained in:
JacobTech 2024-03-31 23:52:57 -04:00
parent 33f8ef9ee0
commit 771f360a66
4 changed files with 45 additions and 3 deletions

View File

@ -10,7 +10,7 @@
<IncludeSymbols>False</IncludeSymbols> <IncludeSymbols>False</IncludeSymbols>
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl> <RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<Version>1.0.9-alpha01</Version> <Version>1.0.9-alpha07</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@ -43,7 +43,8 @@ public class FontFamily
void tryadd(FontSize s, bool i = false) void tryadd(FontSize s, bool i = false)
{ {
var memoryStream = new MemoryStream(); var memoryStream = new MemoryStream();
font.Open().CopyTo(memoryStream); var ss = font.Open();
ss.CopyTo(memoryStream);
if (i) if (i)
{ {
if (!f.SInternalFontsi.ContainsKey(s)) if (!f.SInternalFontsi.ContainsKey(s))
@ -54,6 +55,7 @@ public class FontFamily
if (!f.SInternalFonts.ContainsKey(s)) if (!f.SInternalFonts.ContainsKey(s))
f.SInternalFonts.Add(s, new(memoryStream, null)); f.SInternalFonts.Add(s, new(memoryStream, null));
} }
ss.Dispose();
} }
if (fd.EndsWith("italic")) if (fd.EndsWith("italic"))
@ -82,7 +84,7 @@ public class FontFamily
} }
} }
FamilyZip.Dispose();
return f; return f;
} }

View File

@ -111,10 +111,12 @@ public class FontInteraction
case true: case true:
Families_[j].SInternalFontsi[fs] = new(f.Item1, Families_[j].SInternalFontsi[fs] = new(f.Item1,
Font.MakeFontFromStream(Families_[j].SInternalFontsi[fs].Item1)); Font.MakeFontFromStream(Families_[j].SInternalFontsi[fs].Item1));
Families_[j].SInternalFontsi[fs].Item1.Dispose();
break; break;
case false: case false:
Families_[j].SInternalFonts[fs] = new(f.Item1, Families_[j].SInternalFonts[fs] = new(f.Item1,
Font.MakeFontFromStream(Families_[j].SInternalFonts[fs].Item1)); Font.MakeFontFromStream(Families_[j].SInternalFonts[fs].Item1));
Families_[j].SInternalFonts[fs].Item1.Dispose();
break; break;
} }
} }
@ -221,9 +223,11 @@ public class FontInteraction
{ {
case true: case true:
Families_[j].SInternalFontsi[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFontsi[fs].Item1)); Families_[j].SInternalFontsi[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFontsi[fs].Item1));
Families_[j].SInternalFontsi[fs].Item1.Dispose();
break; break;
case false: case false:
Families_[j].SInternalFonts[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFonts[fs].Item1)); Families_[j].SInternalFonts[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFonts[fs].Item1));
Families_[j].SInternalFonts[fs].Item1.Dispose();
break; break;
} }
} }

View File

@ -202,6 +202,42 @@ public class Label : ILabel
} }
} }
public Vector2i GetCharLocation(int index)
{
int line = 0;
double nl = 0;
double addy = 0f, addy2 =0f, addx = 0F, char_x = 0F;
for (int i = 0; i < index; i++)
{
char character;
if (PasswordChar is null)
character = Text[i];
else
character = PasswordChar.Value;
if (character == '\n')
{
char_x = 0f;
nl = addy;
line++;
continue;
}
Character cha = Texture.GetChar(Font, character);
double w = cha.Size.X * Scale;
double xrel = char_x + cha.Bearing.X * Scale;
double yrel = ((cha.Size.Y - cha.Bearing.Y) * Scale) + (Font.PixelHeight * Scale);
yrel += nl;
char_x += (cha.Advance >> 6) * Scale;
if ((xrel + w) >= addx) addx = (xrel + w);
if (yrel > addy) addy = yrel;
if (line == 0)
{
if (addy2 < cha.Bearing.Y) addy2 = cha.Bearing.Y;
}
}
return new((int)addx, (int)(line * Font.ExtraLinePixels) + (int)(Font.PixelHeight * line));
}
public void Clean() public void Clean()
{ {
Tuple<int, int, int> tup = GlobalBuffers[Window!.Context]; Tuple<int, int, int> tup = GlobalBuffers[Window!.Context];