mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-06-23 08:44:53 +03:00
Compare commits
2 Commits
1.4.8
...
cjk_armlin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0d934318b | ||
|
|
2747d3d8b4 |
@@ -598,22 +598,6 @@ class MyTheme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies [fallbacks] as fontFamilyFallback to every text style in both
|
|
||||||
/// themes. Called once at startup on ARM64 Linux after a CJK font has been
|
|
||||||
/// loaded via FontLoader (see flutter/flutter#139293).
|
|
||||||
static void applyFontFallback(List<String> fallbacks) {
|
|
||||||
lightTheme = lightTheme.copyWith(
|
|
||||||
textTheme: lightTheme.textTheme.apply(fontFamilyFallback: fallbacks),
|
|
||||||
primaryTextTheme:
|
|
||||||
lightTheme.primaryTextTheme.apply(fontFamilyFallback: fallbacks),
|
|
||||||
);
|
|
||||||
darkTheme = darkTheme.copyWith(
|
|
||||||
textTheme: darkTheme.textTheme.apply(fontFamilyFallback: fallbacks),
|
|
||||||
primaryTextTheme:
|
|
||||||
darkTheme.primaryTextTheme.apply(fontFamilyFallback: fallbacks),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ThemeMode currentThemeMode() {
|
static ThemeMode currentThemeMode() {
|
||||||
final preference = getThemeModePreference();
|
final preference = getThemeModePreference();
|
||||||
if (preference == ThemeMode.system) {
|
if (preference == ThemeMode.system) {
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ import 'mobile/pages/home_page.dart';
|
|||||||
import 'mobile/pages/server_page.dart';
|
import 'mobile/pages/server_page.dart';
|
||||||
import 'mobile/widgets/deploy_dialog.dart';
|
import 'mobile/widgets/deploy_dialog.dart';
|
||||||
import 'models/platform_model.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'
|
import 'package:flutter_hbb/plugin/handlers.dart'
|
||||||
if (dart.library.html) 'package:flutter_hbb/web/plugin/handlers.dart';
|
if (dart.library.html) 'package:flutter_hbb/web/plugin/handlers.dart';
|
||||||
@@ -39,15 +37,10 @@ import 'package:flutter_hbb/plugin/handlers.dart'
|
|||||||
int? kWindowId;
|
int? kWindowId;
|
||||||
WindowType? kWindowType;
|
WindowType? kWindowType;
|
||||||
late List<String> kBootArgs;
|
late List<String> kBootArgs;
|
||||||
bool _cjkFontLoaded = false;
|
|
||||||
|
|
||||||
Future<void> main(List<String> args) async {
|
Future<void> main(List<String> args) async {
|
||||||
earlyAssert();
|
earlyAssert();
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
_cjkFontLoaded = await loadSystemCJKFonts();
|
|
||||||
if (_cjkFontLoaded) {
|
|
||||||
MyTheme.applyFontFallback([kLinuxCjkFontFamily]);
|
|
||||||
}
|
|
||||||
|
|
||||||
debugPrint("launch args: $args");
|
debugPrint("launch args: $args");
|
||||||
kBootArgs = List.from(args);
|
kBootArgs = List.from(args);
|
||||||
@@ -390,7 +383,6 @@ void _runApp(
|
|||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
child = _keepScaleBuilder(context, child);
|
child = _keepScaleBuilder(context, child);
|
||||||
child = botToastBuilder(context, child);
|
child = botToastBuilder(context, child);
|
||||||
if (_cjkFontLoaded) child = _mergeCjkFallback(context, child);
|
|
||||||
return child;
|
return child;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -541,7 +533,6 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
|||||||
: (context, child) {
|
: (context, child) {
|
||||||
child = _keepScaleBuilder(context, child);
|
child = _keepScaleBuilder(context, child);
|
||||||
child = botToastBuilder(context, child);
|
child = botToastBuilder(context, child);
|
||||||
if (_cjkFontLoaded) child = _mergeCjkFallback(context, child);
|
|
||||||
if ((isDesktop && desktopType == DesktopType.main) ||
|
if ((isDesktop && desktopType == DesktopType.main) ||
|
||||||
isWebDesktop) {
|
isWebDesktop) {
|
||||||
child = keyListenerBuilder(context, child);
|
child = keyListenerBuilder(context, child);
|
||||||
@@ -595,19 +586,6 @@ _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) {
|
Widget keyListenerBuilder(BuildContext context, Widget? child) {
|
||||||
return RawKeyboardListener(
|
return RawKeyboardListener(
|
||||||
focusNode: FocusNode(),
|
focusNode: FocusNode(),
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
import 'dart:ffi' show Abi;
|
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
/// Font family name registered with [FontLoader] when a system CJK font is
|
|
||||||
/// successfully loaded on ARM64 Linux.
|
|
||||||
const kLinuxCjkFontFamily = 'SystemCJK';
|
|
||||||
|
|
||||||
const _kFontSearchPaths = [
|
|
||||||
// Debian / Ubuntu (noto-fonts / fonts-noto-cjk)
|
|
||||||
'/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc',
|
|
||||||
'/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc',
|
|
||||||
'/usr/share/fonts/opentype/noto/NotoSansCJKsc-Regular.otf',
|
|
||||||
// Fedora / RHEL / Rocky (google-noto-sans-cjk-fonts)
|
|
||||||
'/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc',
|
|
||||||
'/usr/share/fonts/google-noto-sans-cjk-fonts/NotoSansCJK-Regular.ttc',
|
|
||||||
// Arch Linux (noto-fonts-cjk)
|
|
||||||
'/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc',
|
|
||||||
'/usr/share/fonts/noto-cjk/NotoSansCJKsc-Regular.otf',
|
|
||||||
// Generic fallback paths
|
|
||||||
'/usr/share/fonts/noto/NotoSansCJK-Regular.ttc',
|
|
||||||
'/usr/share/fonts/noto/NotoSansCJKsc-Regular.otf',
|
|
||||||
// WenQuanYi — commonly pre-installed on CJK-locale systems
|
|
||||||
'/usr/share/fonts/truetype/wqy/wqy-microhei.ttc',
|
|
||||||
'/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc',
|
|
||||||
'/usr/share/fonts/wqy-microhei/wqy-microhei.ttc',
|
|
||||||
'/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc',
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Loads a system CJK font on ARM64 Linux into Flutter's font registry via
|
|
||||||
/// [FontLoader], working around the missing fontconfig support in the
|
|
||||||
/// flutter-elinux engine (https://github.com/flutter/flutter/issues/139293).
|
|
||||||
///
|
|
||||||
/// Returns true if a CJK font was successfully loaded; false otherwise.
|
|
||||||
/// On all other platforms this is a no-op and returns false immediately.
|
|
||||||
Future<bool> loadSystemCJKFonts() async {
|
|
||||||
if (Abi.current() != Abi.linuxArm64) return false;
|
|
||||||
|
|
||||||
final path = await _findCjkFontPath();
|
|
||||||
if (path == null) {
|
|
||||||
debugPrint('ARM64 Linux: no CJK font found; CJK text may not render');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final loader = FontLoader(kLinuxCjkFontFamily);
|
|
||||||
final bytes = await File(path).readAsBytes();
|
|
||||||
loader.addFont(Future.value(ByteData.view(bytes.buffer, bytes.offsetInBytes, bytes.lengthInBytes)));
|
|
||||||
await loader.load();
|
|
||||||
debugPrint('ARM64 Linux: loaded CJK font from $path');
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('ARM64 Linux: failed to load CJK font: $e');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String?> _findCjkFontPath() async {
|
|
||||||
// Query fc-list for each CJK script separately. Fonts present in all three
|
|
||||||
// sets (zh ∩ ja ∩ ko) are true pan-CJK fonts; prefer them so we don't
|
|
||||||
// accidentally pick a Chinese-only font that lacks Japanese kana or Korean
|
|
||||||
// hangul glyphs. fc-list is a fontconfig CLI tool available on most Linux
|
|
||||||
// systems independent of whether the Flutter engine was built with fontconfig.
|
|
||||||
final byLang = <String, Set<String>>{};
|
|
||||||
for (final lang in const ['zh', 'ja', 'ko']) {
|
|
||||||
final paths = <String>{};
|
|
||||||
try {
|
|
||||||
final r =
|
|
||||||
await Process.run('fc-list', [':lang=$lang', '--format=%{file}\n']);
|
|
||||||
if (r.exitCode == 0) {
|
|
||||||
for (final line in r.stdout.toString().split('\n')) {
|
|
||||||
final p = line.trim();
|
|
||||||
if (p.isNotEmpty && File(p).existsSync()) paths.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('ARM64 Linux: fc-list failed for lang=$lang: $e');
|
|
||||||
}
|
|
||||||
byLang[lang] = paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
final panCjk = byLang['zh']!
|
|
||||||
.intersection(byLang['ja']!)
|
|
||||||
.intersection(byLang['ko']!);
|
|
||||||
final anyCjk =
|
|
||||||
byLang.values.fold(<String>{}, (acc, s) => acc..addAll(s));
|
|
||||||
|
|
||||||
// Among candidates, prefer well-known pan-CJK font families.
|
|
||||||
String? pick(Iterable<String> pool) {
|
|
||||||
const preferred = ['notosanscjk', 'sourcehansans', 'sourcehanserif'];
|
|
||||||
for (final name in preferred) {
|
|
||||||
for (final p in pool) {
|
|
||||||
if (p.toLowerCase().contains(name)) return p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pool.isNotEmpty ? pool.first : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final found = pick(panCjk) ?? pick(anyCjk);
|
|
||||||
if (found != null) return found;
|
|
||||||
|
|
||||||
for (final p in _kFontSearchPaths) {
|
|
||||||
if (File(p).existsSync()) return p;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
/// Web stub for `native/font_manager.dart`.
|
|
||||||
///
|
|
||||||
/// The native implementation depends on `dart:io` (Process/File/Platform) to
|
|
||||||
/// load a system CJK font on ARM64 Linux, which cannot compile for the web
|
|
||||||
/// target. The web build has no such fontconfig limitation, so this is a no-op.
|
|
||||||
const kLinuxCjkFontFamily = 'SystemCJK';
|
|
||||||
|
|
||||||
Future<bool> loadSystemCJKFonts() async => false;
|
|
||||||
74
src/lang.rs
74
src/lang.rs
@@ -103,15 +103,29 @@ pub const LANGS: &[(&str, &str)] = &[
|
|||||||
("gu", "ગુજરાતી"),
|
("gu", "ગુજરાતી"),
|
||||||
];
|
];
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
pub(crate) fn cjk_ui_unavailable() -> bool {
|
||||||
pub fn translate(name: String) -> String {
|
cfg!(all(
|
||||||
let locale = sys_locale::get_locale().unwrap_or_default();
|
target_os = "linux",
|
||||||
translate_locale(name, &locale)
|
target_arch = "aarch64",
|
||||||
|
feature = "flutter"
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn translate_locale(name: String, locale: &str) -> String {
|
pub(crate) fn is_cjk_lang(lang_or_locale: &str) -> bool {
|
||||||
|
let lang = lang_or_locale
|
||||||
|
.split(|c| c == '-' || c == '_')
|
||||||
|
.next()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_lowercase();
|
||||||
|
matches!(lang.as_str(), "zh" | "ja" | "ko")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_lang(saved_lang: &str, locale: &str, cjk_fallback: bool) -> String {
|
||||||
let locale = locale.to_lowercase();
|
let locale = locale.to_lowercase();
|
||||||
let mut lang = hbb_common::config::LocalConfig::get_option("lang").to_lowercase();
|
let mut lang = saved_lang.to_lowercase();
|
||||||
|
if cjk_fallback && is_cjk_lang(&lang) {
|
||||||
|
return "en".to_owned();
|
||||||
|
}
|
||||||
if lang.is_empty() {
|
if lang.is_empty() {
|
||||||
// zh_CN on Linux, zh-Hans-CN on mac, zh_CN_#Hans on Android
|
// zh_CN on Linux, zh-Hans-CN on mac, zh_CN_#Hans on Android
|
||||||
if locale.starts_with("zh") {
|
if locale.starts_with("zh") {
|
||||||
@@ -131,7 +145,25 @@ pub fn translate_locale(name: String, locale: &str) -> String {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_owned();
|
.to_owned();
|
||||||
}
|
}
|
||||||
let lang = lang.to_lowercase();
|
if cjk_fallback && is_cjk_lang(&lang) {
|
||||||
|
"en".to_owned()
|
||||||
|
} else {
|
||||||
|
lang
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
pub fn translate(name: String) -> String {
|
||||||
|
let locale = sys_locale::get_locale().unwrap_or_default();
|
||||||
|
translate_locale(name, &locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn translate_locale(name: String, locale: &str) -> String {
|
||||||
|
let lang = resolve_lang(
|
||||||
|
&hbb_common::config::LocalConfig::get_option("lang"),
|
||||||
|
locale,
|
||||||
|
cjk_ui_unavailable(),
|
||||||
|
);
|
||||||
let m = match lang.as_str() {
|
let m = match lang.as_str() {
|
||||||
"fr" => fr::T.deref(),
|
"fr" => fr::T.deref(),
|
||||||
"zh-cn" => cn::T.deref(),
|
"zh-cn" => cn::T.deref(),
|
||||||
@@ -275,4 +307,32 @@ mod test {
|
|||||||
("{} times {4} makes {8}".to_string(), Some("2".to_string()))
|
("{} times {4} makes {8}".to_string(), Some("2".to_string()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_resolve_lang_forces_english_for_saved_cjk_when_target_disables_cjk() {
|
||||||
|
use super::resolve_lang as f;
|
||||||
|
|
||||||
|
assert_eq!(f("zh-cn", "en-US", true), "en");
|
||||||
|
assert_eq!(f("zh-tw", "en-US", true), "en");
|
||||||
|
assert_eq!(f("ja", "en-US", true), "en");
|
||||||
|
assert_eq!(f("ko", "en-US", true), "en");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_resolve_lang_forces_english_for_cjk_locale_when_target_disables_cjk() {
|
||||||
|
use super::resolve_lang as f;
|
||||||
|
|
||||||
|
assert_eq!(f("", "zh_CN", true), "en");
|
||||||
|
assert_eq!(f("", "ja-JP", true), "en");
|
||||||
|
assert_eq!(f("", "ko_KR", true), "en");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_resolve_lang_preserves_cjk_when_target_allows_cjk() {
|
||||||
|
use super::resolve_lang as f;
|
||||||
|
|
||||||
|
assert_eq!(f("zh-cn", "en-US", false), "zh-cn");
|
||||||
|
assert_eq!(f("", "zh_TW", false), "zh-tw");
|
||||||
|
assert_eq!(f("", "ja-JP", false), "ja");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -902,8 +902,10 @@ pub fn get_async_job_status() -> String {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_langs() -> String {
|
pub fn get_langs() -> String {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
let hide_cjk = crate::lang::cjk_ui_unavailable();
|
||||||
let mut x: Vec<(&str, String)> = crate::lang::LANGS
|
let mut x: Vec<(&str, String)> = crate::lang::LANGS
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|a| !hide_cjk || !crate::lang::is_cjk_lang(a.0))
|
||||||
.map(|a| (a.0, format!("{} ({})", a.1, a.0)))
|
.map(|a| (a.0, format!("{} ({})", a.1, a.0)))
|
||||||
.collect();
|
.collect();
|
||||||
x.sort_by(|a, b| a.0.cmp(b.0));
|
x.sort_by(|a, b| a.0.cmp(b.0));
|
||||||
|
|||||||
Reference in New Issue
Block a user