diff --git a/CHANGELOG.md b/CHANGELOG.md index 381fbf99..b8466221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Version 4.0.5 - **fix(text-editor)**: Resolve misapplication of secondary color. This resolve issue [#105](https://github.com/hm21/pro_image_editor/discussions/105). +- **fix(text-editor)**: Resolve issue where text styles (bold/italic/underline) are not saved in history. This resolves issue [#118](https://github.com/hm21/pro_image_editor/discussions/118). + ## Version 4.0.4 - **feat(text-editor)**: Added the ability to programmatically set the secondary color next to the primary color. diff --git a/lib/models/layer/layer.dart b/lib/models/layer/layer.dart index c5fba846..316853b9 100644 --- a/lib/models/layer/layer.dart +++ b/lib/models/layer/layer.dart @@ -164,11 +164,55 @@ class TextLayerData extends Layer { 'fontScale': fontScale, 'type': 'text', if (customSecondaryColor) 'customSecondaryColor': customSecondaryColor, - 'fontFamily': textStyle?.fontFamily + if (textStyle?.fontFamily != null) 'fontFamily': textStyle?.fontFamily, + if (textStyle?.fontStyle != null) 'fontStyle': textStyle?.fontStyle!.name, + if (textStyle?.fontWeight != null) + 'fontWeight': textStyle?.fontWeight!.value, + if (textStyle?.letterSpacing != null) + 'letterSpacing': textStyle?.letterSpacing, + if (textStyle?.height != null) 'height': textStyle?.height, + if (textStyle?.wordSpacing != null) 'wordSpacing': textStyle?.wordSpacing, + if (textStyle?.decoration != null) + 'decoration': textStyle?.decoration.toString(), }; } factory TextLayerData.fromMap(Layer layer, Map map) { + TextDecoration getDecoration(String decoration) { + if (decoration.contains('combine')) { + List decorations = []; + + if (decoration.contains('lineThrough')) { + decorations.add(TextDecoration.lineThrough); + } + if (decoration.contains('overline')) { + decorations.add(TextDecoration.overline); + } + if (decoration.contains('underline')) { + decorations.add(TextDecoration.underline); + } + + return TextDecoration.combine(decorations); + } else { + if (decoration.contains('lineThrough')) { + return TextDecoration.lineThrough; + } else if (decoration.contains('overline')) { + return TextDecoration.overline; + } else if (decoration.contains('underline')) { + return TextDecoration.underline; + } + } + + return TextDecoration.none; + } + + String? fontFamily = map['fontFamily']; + double? wordSpacing = map['wordSpacing']; + double? height = map['height']; + double? letterSpacing = map['letterSpacing']; + int? fontWeight = map['fontWeight']; + String? fontStyle = map['fontStyle']; + String? decoration = map['decoration']; return TextLayerData( flipX: layer.flipX, flipY: layer.flipY, @@ -179,7 +223,19 @@ class TextLayerData extends Layer { fontScale: map['fontScale'] ?? 1.0, textStyle: map['fontFamily'] != null ? TextStyle( - fontFamily: map['fontFamily'], + fontFamily: fontFamily, + height: height, + wordSpacing: wordSpacing, + letterSpacing: letterSpacing, + decoration: decoration != null ? getDecoration(decoration) : null, + fontStyle: fontStyle != null + ? FontStyle.values + .firstWhere((element) => element.name == fontStyle) + : null, + fontWeight: fontWeight != null + ? FontWeight.values + .firstWhere((element) => element.value == fontWeight) + : null, ) : null, colorMode: LayerBackgroundMode.values diff --git a/lib/modules/text_editor/text_editor.dart b/lib/modules/text_editor/text_editor.dart index 634483ab..d12159d9 100644 --- a/lib/modules/text_editor/text_editor.dart +++ b/lib/modules/text_editor/text_editor.dart @@ -336,17 +336,16 @@ class TextEditorState extends State if (_textCtrl.text.trim().isNotEmpty) { Navigator.of(context).pop( TextLayerData( - text: _textCtrl.text.trim(), - background: _getBackgroundColor, - color: _getTextColor, - align: align, - fontScale: _fontScale, - colorMode: backgroundColorMode, - colorPickerPosition: colorPosition, - textStyle: selectedTextStyle, - customSecondaryColor: _secondaryColor != null - // fontFamily: 'Roboto', - ), + text: _textCtrl.text.trim(), + background: _getBackgroundColor, + color: _getTextColor, + align: align, + fontScale: _fontScale, + colorMode: backgroundColorMode, + colorPickerPosition: colorPosition, + textStyle: selectedTextStyle, + customSecondaryColor: _secondaryColor != null, + ), ); } else { Navigator.of(context).pop(); @@ -600,7 +599,6 @@ class TextEditorState extends State style: selectedTextStyle.copyWith( color: _getTextColor, fontSize: _getTextFontSize, - fontWeight: FontWeight.w400, height: 1.35, letterSpacing: 0, ), @@ -633,15 +631,14 @@ class TextEditorState extends State hintStyle: selectedTextStyle.copyWith( color: imageEditorTheme.textEditor.inputHintColor, fontSize: _getTextFontSize, - fontWeight: FontWeight.w400, height: 1.35, )), style: selectedTextStyle.copyWith( color: Colors.transparent, fontSize: _getTextFontSize, - fontWeight: FontWeight.w400, height: 1.35, letterSpacing: 0, + decoration: TextDecoration.none, ), autofocus: true, ), diff --git a/lib/widgets/layer_widget.dart b/lib/widgets/layer_widget.dart index 6622f7f0..00240b9e 100644 --- a/lib/widgets/layer_widget.dart +++ b/lib/widgets/layer_widget.dart @@ -314,7 +314,6 @@ class _LayerWidgetState extends State var layer = _layer as TextLayerData; var style = TextStyle( fontSize: fontSize * layer.fontScale, - fontWeight: FontWeight.w400, color: layer.color, overflow: TextOverflow.ellipsis, );