mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-07-08 08:15:11 +03:00
fix(arm64-linux): fix CJK font rendering on flutter-elinux (#15324)
* fix(arm64-linux): fix CJK font rendering on flutter-elinux The flutter-elinux engine used for ARM64 Linux builds is compiled without --enable-fontconfig, so Flutter's text shaper cannot discover system fonts. This causes CJK characters to render as tofu boxes even when fonts such as Noto Sans CJK are installed. See flutter/flutter#139293. Fix by loading a CJK font at startup via FontLoader (bypassing fontconfig) and propagating it through two paths so all text widgets are covered: 1. MyTheme.applyFontFallback() — updates textTheme on both light and dark ThemeData so Material components receive the fallback through the theme. 2. _mergeCjkFallback() in GetMaterialApp builders — wraps child widgets in DefaultTextStyle.merge so bare Text() widgets and those with inherit:true also render CJK characters correctly. Font discovery queries fc-list for zh, ja, and ko separately, preferring fonts present in all three sets (true pan-CJK fonts such as NotoSansCJK or SourceHanSans) over Chinese-only fonts that may lack Japanese kana or Korean hangul glyphs. Falls back to a hardcoded search-path list covering Debian/Ubuntu, Fedora/RHEL, Arch Linux, and WenQuanYi font layouts. This is an app-level workaround. The engine-level fix is tracked at flutter/flutter#180235 (open as of 2026-06). Fixes #10666 Signed-off-by: Bia503 <yinwenche189@gmail.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: Bia503 <yinwenche189@gmail.com> Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,8 @@ import 'mobile/pages/home_page.dart';
|
||||
import 'mobile/pages/server_page.dart';
|
||||
import 'mobile/widgets/deploy_dialog.dart';
|
||||
import 'models/platform_model.dart';
|
||||
import 'native/font_manager.dart'
|
||||
if (dart.library.html) 'web/font_manager.dart';
|
||||
|
||||
import 'package:flutter_hbb/plugin/handlers.dart'
|
||||
if (dart.library.html) 'package:flutter_hbb/web/plugin/handlers.dart';
|
||||
@@ -37,10 +39,15 @@ import 'package:flutter_hbb/plugin/handlers.dart'
|
||||
int? kWindowId;
|
||||
WindowType? kWindowType;
|
||||
late List<String> kBootArgs;
|
||||
bool _cjkFontLoaded = false;
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
earlyAssert();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
_cjkFontLoaded = await loadSystemCJKFonts();
|
||||
if (_cjkFontLoaded) {
|
||||
MyTheme.applyFontFallback([kLinuxCjkFontFamily]);
|
||||
}
|
||||
|
||||
debugPrint("launch args: $args");
|
||||
kBootArgs = List.from(args);
|
||||
@@ -383,6 +390,7 @@ void _runApp(
|
||||
builder: (context, child) {
|
||||
child = _keepScaleBuilder(context, child);
|
||||
child = botToastBuilder(context, child);
|
||||
if (_cjkFontLoaded) child = _mergeCjkFallback(context, child);
|
||||
return child;
|
||||
},
|
||||
),
|
||||
@@ -533,6 +541,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
: (context, child) {
|
||||
child = _keepScaleBuilder(context, child);
|
||||
child = botToastBuilder(context, child);
|
||||
if (_cjkFontLoaded) child = _mergeCjkFallback(context, child);
|
||||
if ((isDesktop && desktopType == DesktopType.main) ||
|
||||
isWebDesktop) {
|
||||
child = keyListenerBuilder(context, child);
|
||||
@@ -586,6 +595,19 @@ _registerEventHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Merges the theme's fontFamilyFallback into [DefaultTextStyle] so that
|
||||
/// bare [Text] widgets (and those with inherit:true styles) also pick up the
|
||||
/// CJK fallback font loaded on ARM64 Linux.
|
||||
Widget _mergeCjkFallback(BuildContext context, Widget? child) {
|
||||
final result = child ?? Container();
|
||||
final fallback = Theme.of(context).textTheme.bodyMedium?.fontFamilyFallback;
|
||||
if (fallback == null || fallback.isEmpty) return result;
|
||||
return DefaultTextStyle.merge(
|
||||
style: TextStyle(fontFamilyFallback: fallback),
|
||||
child: result,
|
||||
);
|
||||
}
|
||||
|
||||
Widget keyListenerBuilder(BuildContext context, Widget? child) {
|
||||
return RawKeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
|
||||
Reference in New Issue
Block a user