From 771f360a6693b6eecc3aea4625da7d9a3b47a580 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Sun, 31 Mar 2024 23:52:57 -0400 Subject: [PATCH] Memory Optimisation --- GraphicsManager/GraphicsManager.csproj | 2 +- GraphicsManager/Objects/Core/FontFamily.cs | 6 ++-- .../Objects/Core/FontInteraction.cs | 4 +++ GraphicsManager/Objects/Label.cs | 36 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj index 99c0d72..c2d1943 100644 --- a/GraphicsManager/GraphicsManager.csproj +++ b/GraphicsManager/GraphicsManager.csproj @@ -10,7 +10,7 @@ False https://git.jacobtech.com/JacobTech.com/GraphicsManager git - 1.0.9-alpha01 + 1.0.9-alpha07 diff --git a/GraphicsManager/Objects/Core/FontFamily.cs b/GraphicsManager/Objects/Core/FontFamily.cs index dce4af0..de7c7d7 100644 --- a/GraphicsManager/Objects/Core/FontFamily.cs +++ b/GraphicsManager/Objects/Core/FontFamily.cs @@ -43,7 +43,8 @@ public class FontFamily void tryadd(FontSize s, bool i = false) { var memoryStream = new MemoryStream(); - font.Open().CopyTo(memoryStream); + var ss = font.Open(); + ss.CopyTo(memoryStream); if (i) { if (!f.SInternalFontsi.ContainsKey(s)) @@ -54,6 +55,7 @@ public class FontFamily if (!f.SInternalFonts.ContainsKey(s)) f.SInternalFonts.Add(s, new(memoryStream, null)); } + ss.Dispose(); } if (fd.EndsWith("italic")) @@ -82,7 +84,7 @@ public class FontFamily } } - +FamilyZip.Dispose(); return f; } diff --git a/GraphicsManager/Objects/Core/FontInteraction.cs b/GraphicsManager/Objects/Core/FontInteraction.cs index a0c7b68..f0933c0 100644 --- a/GraphicsManager/Objects/Core/FontInteraction.cs +++ b/GraphicsManager/Objects/Core/FontInteraction.cs @@ -111,10 +111,12 @@ public class FontInteraction case true: Families_[j].SInternalFontsi[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFontsi[fs].Item1)); + Families_[j].SInternalFontsi[fs].Item1.Dispose(); break; case false: Families_[j].SInternalFonts[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFonts[fs].Item1)); + Families_[j].SInternalFonts[fs].Item1.Dispose(); break; } } @@ -221,9 +223,11 @@ public class FontInteraction { case true: Families_[j].SInternalFontsi[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFontsi[fs].Item1)); + Families_[j].SInternalFontsi[fs].Item1.Dispose(); break; case false: Families_[j].SInternalFonts[fs] = new(f.Item1, Font.MakeFontFromStream(Families_[j].SInternalFonts[fs].Item1)); + Families_[j].SInternalFonts[fs].Item1.Dispose(); break; } } diff --git a/GraphicsManager/Objects/Label.cs b/GraphicsManager/Objects/Label.cs index 88a29a4..0b0a03e 100755 --- a/GraphicsManager/Objects/Label.cs +++ b/GraphicsManager/Objects/Label.cs @@ -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() { Tuple tup = GlobalBuffers[Window!.Context];