Skip to content

Commit 607dd02

Browse files
committed
统一字体资源释放逻辑,封装至辅助方法
将各 View 类中字体相关资源的释放操作统一封装到 LinuxRuntimeFontHelper.ReleaseRuntimeFont 方法中,减少重复代码,提升可维护性。新增多种 ReleaseRuntimeFont 重载,支持不同资源组合的释放需求,并自动清理相关字段和诊断信息。
1 parent 61b5469 commit 607dd02

File tree

6 files changed

+80
-21
lines changed

6 files changed

+80
-21
lines changed

src/LVGLSharp.Runtime.Linux/DrmView.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ protected override void OnCloseCore()
154154
_display = null;
155155
}
156156

157-
_fontManager?.Dispose();
158-
_fontManager = null;
157+
LinuxRuntimeFontHelper.ReleaseRuntimeFontDiagnostics(
158+
ref _fallbackFont,
159+
ref _fontManager,
160+
ref _fontDiagnosticSummary,
161+
ref _fontGlyphDiagnosticSummary,
162+
ref _defaultFontStyle);
159163
_resolvedDevicePath = null;
160-
_fontDiagnosticSummary = null;
161-
_fontGlyphDiagnosticSummary = null;
162164
_root = null;
163165
_initialized = false;
164166
}

src/LVGLSharp.Runtime.Linux/FrameBufferView.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ protected override void OnCloseCore()
128128
g_display = null;
129129
}
130130

131-
_fontManager?.Dispose();
132-
_fontManager = null;
131+
LinuxRuntimeFontHelper.ReleaseRuntimeFont(
132+
ref _fallbackFont,
133+
ref _fontManager,
134+
ref _defaultFontStyle);
133135
RootObject = null;
134136
KeyInputGroupObject = null;
135137
SendTextAreaFocusCallbackCore = null;

src/LVGLSharp.Runtime.Linux/LinuxRuntimeFontHelper.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,54 @@ internal static LinuxRuntimeFontInitialization InitializeRuntimeFont(
140140
out _,
141141
out defaultFontStyle);
142142
}
143+
144+
internal static void ReleaseRuntimeFont(
145+
ref lv_font_t* fallbackFont,
146+
ref SixLaborsFontManager? fontManager,
147+
ref lv_style_t* defaultFontStyle)
148+
{
149+
LvglRuntimeFontRegistry.ClearActiveTextFont();
150+
fontManager?.Dispose();
151+
fontManager = null;
152+
fallbackFont = null;
153+
defaultFontStyle = null;
154+
}
155+
156+
internal static void ReleaseRuntimeFontDiagnostics(
157+
ref lv_font_t* fallbackFont,
158+
ref SixLaborsFontManager? fontManager,
159+
ref string? fontDiagnosticSummary,
160+
ref string? glyphDiagnosticSummary,
161+
ref lv_style_t* defaultFontStyle)
162+
{
163+
ReleaseRuntimeFont(ref fallbackFont, ref fontManager, ref defaultFontStyle);
164+
fontDiagnosticSummary = null;
165+
glyphDiagnosticSummary = null;
166+
}
167+
168+
internal static void ReleaseRuntimeFontPathAndDiagnostic(
169+
ref lv_font_t* fallbackFont,
170+
ref SixLaborsFontManager? fontManager,
171+
ref string? resolvedSystemFontPath,
172+
ref string? fontDiagnosticSummary,
173+
ref lv_style_t* defaultFontStyle)
174+
{
175+
ReleaseRuntimeFont(ref fallbackFont, ref fontManager, ref defaultFontStyle);
176+
resolvedSystemFontPath = null;
177+
fontDiagnosticSummary = null;
178+
}
179+
180+
internal static void ReleaseRuntimeFontFull(
181+
ref lv_font_t* fallbackFont,
182+
ref SixLaborsFontManager? fontManager,
183+
ref string? resolvedSystemFontPath,
184+
ref string? fontDiagnosticSummary,
185+
ref string? glyphDiagnosticSummary,
186+
ref lv_style_t* defaultFontStyle)
187+
{
188+
ReleaseRuntimeFont(ref fallbackFont, ref fontManager, ref defaultFontStyle);
189+
resolvedSystemFontPath = null;
190+
fontDiagnosticSummary = null;
191+
glyphDiagnosticSummary = null;
192+
}
143193
}

src/LVGLSharp.Runtime.Linux/SdlView.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@ protected override void OnCloseCore()
172172

173173
_bufferPresenter.Dispose();
174174

175-
_fontManager?.Dispose();
176-
_fontManager = null;
177-
_resolvedSystemFontPath = null;
178-
_fontDiagnosticSummary = null;
179-
_fontGlyphDiagnosticSummary = null;
175+
LinuxRuntimeFontHelper.ReleaseRuntimeFontFull(
176+
ref _fallbackFont,
177+
ref _fontManager,
178+
ref _resolvedSystemFontPath,
179+
ref _fontDiagnosticSummary,
180+
ref _fontGlyphDiagnosticSummary,
181+
ref _defaultFontStyle);
180182

181183
_root = null;
182184
_keyInputGroup = null;

src/LVGLSharp.Runtime.Linux/WaylandView.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ protected override void OnCloseCore()
186186
_lvDisplay = null;
187187
}
188188

189-
_fontManager?.Dispose();
190-
_fontManager = null;
191-
_resolvedSystemFontPath = null;
192-
_fontDiagnosticSummary = null;
189+
LinuxRuntimeFontHelper.ReleaseRuntimeFontPathAndDiagnostic(
190+
ref _fallbackFont,
191+
ref _fontManager,
192+
ref _resolvedSystemFontPath,
193+
ref _fontDiagnosticSummary,
194+
ref _defaultFontStyle);
193195

194196
_root = null;
195197
_bufferPresenter.Dispose();

src/LVGLSharp.Runtime.Linux/X11View.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,13 @@ protected override void OnCloseCore()
530530
_display = IntPtr.Zero;
531531
}
532532

533-
LvglRuntimeFontRegistry.ClearActiveTextFont();
534-
_fontManager?.Dispose();
535-
_fontManager = null;
536-
_resolvedSystemFontPath = null;
537-
_fontDiagnosticSummary = null;
538-
_fontGlyphDiagnosticSummary = null;
533+
LinuxRuntimeFontHelper.ReleaseRuntimeFontFull(
534+
ref _fallbackFont,
535+
ref _fontManager,
536+
ref _resolvedSystemFontPath,
537+
ref _fontDiagnosticSummary,
538+
ref _fontGlyphDiagnosticSummary,
539+
ref _defaultFontStyle);
539540

540541
RootObject = null;
541542
SendTextAreaFocusCallbackCore = null;

0 commit comments

Comments
 (0)