Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for font family and font size attributes in rich text #486

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/src/editor/block_component/rich_text/appflowy_rich_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
TextStyle(color: attributes.color),
);
}
if (attributes.fontFamily != null) {
textStyle = textStyle.combine(
TextStyle(fontFamily: attributes.fontFamily),
);
}
if (attributes.fontSize != null) {
textStyle = textStyle.combine(
TextStyle(fontSize: attributes.fontSize),
);
}
}
final textSpan = TextSpan(
text: textInsert.text,
Expand Down Expand Up @@ -469,4 +479,18 @@ extension AppFlowyRichTextAttributes on Attributes {
}
return null;
}

String? get fontFamily {
if (this[AppFlowyRichTextKeys.fontFamily] is String) {
return this[AppFlowyRichTextKeys.fontFamily];
}
return null;
}

double? get fontSize {
if (this[AppFlowyRichTextKeys.fontSize] is double) {
return this[AppFlowyRichTextKeys.fontSize];
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class AppFlowyRichTextKeys {
static String findBackgroundColor = 'find_bg_color';
static String code = 'code';
static String href = 'href';
static String fontFamily = 'font_family';
static String fontSize = 'font_size';

static List<String> supportSliced = [
bold,
Expand Down