From 68145165be767fd91c5e03a8ee234f0ef863e8bd Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 16 Jun 2023 12:45:26 +0700 Subject: [PATCH] TF-1878 Fix font family not changed correctly in composer (cherry picked from commit a4c72a79abf429aa2938c8218308f1ac16f89d76) --- .../base/widget/drop_down_button_widget.dart | 2 +- .../controller/rich_text_web_controller.dart | 50 ++++++++++++++----- .../presentation/model/font_name_type.dart | 35 ++++++++++++- 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/lib/features/base/widget/drop_down_button_widget.dart b/lib/features/base/widget/drop_down_button_widget.dart index 84e94078f..dab5bbbb2 100644 --- a/lib/features/base/widget/drop_down_button_widget.dart +++ b/lib/features/base/widget/drop_down_button_widget.dart @@ -174,7 +174,7 @@ class DropDownButtonWidget extends StatelessWidget { return item.name ?? ''; } if (item is FontNameType) { - return item.fontFamily; + return item.title; } if (item is rich_text_composer.SafeFont) { return item.name; diff --git a/lib/features/composer/presentation/controller/rich_text_web_controller.dart b/lib/features/composer/presentation/controller/rich_text_web_controller.dart index 152065c06..3cde665f1 100644 --- a/lib/features/composer/presentation/controller/rich_text_web_controller.dart +++ b/lib/features/composer/presentation/controller/rich_text_web_controller.dart @@ -47,8 +47,16 @@ class RichTextWebController extends BaseRichTextController { }); } - void onEditorSettingsChange(EditorSettings settings) async { - log('RichTextWebController::onEditorSettingsChange():foregroundColor: ${settings.foregroundColor} | backgroundColor: ${settings.backgroundColor}'); + void onEditorSettingsChange(EditorSettings settings) { + _updateTextStyle(settings); + _updateFontName(settings); + _updateTextColor(settings); + _updateBackgroundTextColor(settings); + _updateOrderList(settings); + _updateParagraph(settings); + } + + void _updateTextStyle(EditorSettings settings) { listTextStyleApply.clear(); if (settings.isBold) { @@ -67,11 +75,35 @@ class RichTextWebController extends BaseRichTextController { listTextStyleApply.add(RichTextStyleType.strikeThrough); } - log('RichTextWebController::onEditorSettingsChange(): $listTextStyleApply'); + log('RichTextWebController::_updateTextStyle(): $listTextStyleApply'); + } + void _updateFontName(EditorSettings settings) { + log('RichTextWebController::_updateFontName():fontName: ${settings.fontName}'); + final matchedFontName = FontNameType.values.firstWhereOrNull((fontName) => fontName.value == settings.fontName); + log('RichTextWebController::_updateFontName():matchedFontName: $matchedFontName'); + if (matchedFontName != null) { + selectedFontName.value = matchedFontName; + } + } + + void _updateTextColor(EditorSettings settings) { selectedTextColor.value = settings.foregroundColor; - selectedTextBackgroundColor.value = settings.backgroundColor; + } + void _updateBackgroundTextColor(EditorSettings settings) { + selectedTextBackgroundColor.value = settings.backgroundColor; + } + + void _updateOrderList(EditorSettings settings) { + if (settings.isOl) { + selectedOrderList.value = OrderListType.numberedList; + } else if (settings.isUl) { + selectedOrderList.value = OrderListType.bulletedList; + } + } + + void _updateParagraph(EditorSettings settings) { if (settings.isAlignCenter) { selectedParagraph.value = ParagraphType.alignCenter; } else if (settings.isAlignJustify) { @@ -81,12 +113,6 @@ class RichTextWebController extends BaseRichTextController { } else if (settings.isAlignRight) { selectedParagraph.value = ParagraphType.alignRight; } - - if (settings.isOl) { - selectedOrderList.value = OrderListType.numberedList; - } else if (settings.isUl) { - selectedOrderList.value = OrderListType.bulletedList; - } } void applyRichTextStyle(BuildContext context, RichTextStyleType textStyleType) { @@ -157,8 +183,8 @@ class RichTextWebController extends BaseRichTextController { final fontSelected = newFont ?? FontNameType.sansSerif; selectedFontName.value = fontSelected; editorController.execCommand( - RichTextStyleType.fontName.commandAction, - argument: fontSelected.fontFamily); + RichTextStyleType.fontName.commandAction, + argument: fontSelected.value); editorController.setFocus(); } diff --git a/lib/features/composer/presentation/model/font_name_type.dart b/lib/features/composer/presentation/model/font_name_type.dart index 25788be6d..37922a8bf 100644 --- a/lib/features/composer/presentation/model/font_name_type.dart +++ b/lib/features/composer/presentation/model/font_name_type.dart @@ -15,7 +15,7 @@ enum FontNameType { sansSerif, verdana; - String get fontFamily { + String get title { switch(this) { case FontNameType.arial: return 'Arial'; @@ -47,4 +47,37 @@ enum FontNameType { return 'Verdana'; } } + + String get value { + switch(this) { + case FontNameType.arial: + return 'Arial'; + case FontNameType.arialBlack: + return 'Arial Black'; + case FontNameType.brushScriptMT: + return 'Brush Script MT'; + case FontNameType.comicSansMS: + return 'Comic Sans MS'; + case FontNameType.courierNew: + return 'Courier New'; + case FontNameType.helveticaNeue: + return 'Helvetica Neue'; + case FontNameType.helvetica: + return 'Helvetica'; + case FontNameType.impact: + return 'Impact'; + case FontNameType.lucidaGrande: + return 'Lucida Grande'; + case FontNameType.tahoma: + return 'Tahoma'; + case FontNameType.timesNewRoman: + return 'Times New Roman'; + case FontNameType.trebuchetMS: + return 'Trebuchet MS'; + case FontNameType.sansSerif: + return 'sans-serif'; + case FontNameType.verdana: + return 'Verdana'; + } + } } \ No newline at end of file