From 6551f3632f924bdb5a06d0a67d79009dafb486cb Mon Sep 17 00:00:00 2001 From: singerdmx Date: Sat, 16 Jan 2021 01:10:28 -0800 Subject: [PATCH] Support font and size attributes --- CHANGELOG.md | 5 ++- app/assets/sample_data.json | 57 +++++++++++++++++++++++++++++++++ lib/widgets/default_styles.dart | 18 +++++++++-- lib/widgets/text_line.dart | 22 +++++++++++++ pubspec.yaml | 2 +- 5 files changed, 99 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17cd5502..a9fe701e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,4 +48,7 @@ * Fix getExtentEndpointForSelection. ## [0.1.7] -* Support checked/unchecked list. \ No newline at end of file +* Support checked/unchecked list. + +## [0.1.8] +* Support font and size attributes. \ No newline at end of file diff --git a/app/assets/sample_data.json b/app/assets/sample_data.json index f6673952..15cc2f2a 100644 --- a/app/assets/sample_data.json +++ b/app/assets/sample_data.json @@ -418,5 +418,62 @@ "list": "unchecked" }, "insert": "\n" + }, + { + "insert": "Font " + }, + { + "attributes": { + "font": "sans-serif" + }, + "insert": "Sans Serif" + }, + { + "insert": " " + }, + { + "attributes": { + "font": "serif" + }, + "insert": "Serif" + }, + { + "insert": " " + }, + { + "attributes": { + "font": "monospace" + }, + "insert": "Monospace" + }, + { + "insert": " Size " + }, + { + "attributes": { + "size": "small" + }, + "insert": "Small" + }, + { + "insert": " " + }, + { + "attributes": { + "size": "large" + }, + "insert": "Large" + }, + { + "insert": " " + }, + { + "attributes": { + "size": "huge" + }, + "insert": "Huge" + }, + { + "insert": "\n" } ] \ No newline at end of file diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 153ec5c7..f473f562 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -50,6 +50,9 @@ class DefaultStyles { final TextStyle italic; final TextStyle underline; final TextStyle strikeThrough; + final TextStyle sizeSmall; // 'small' + final TextStyle sizeLarge; // 'large' + final TextStyle sizeHuge; // 'huge' final TextStyle link; final DefaultTextBlockStyle lists; final DefaultTextBlockStyle quote; @@ -71,7 +74,10 @@ class DefaultStyles { this.quote, this.code, this.indent, - this.align); + this.align, + this.sizeSmall, + this.sizeLarge, + this.sizeHuge); static DefaultStyles getInstance(BuildContext context) { ThemeData themeData = Theme.of(context); @@ -162,7 +168,10 @@ class DefaultStyles { )), DefaultTextBlockStyle(baseStyle, baseSpacing, Tuple2(0.0, 6.0), null), DefaultTextBlockStyle( - baseStyle, Tuple2(0.0, 0.0), Tuple2(0.0, 0.0), null)); + baseStyle, Tuple2(0.0, 0.0), Tuple2(0.0, 0.0), null), + TextStyle(fontSize: 10.0), + TextStyle(fontSize: 18.0), + TextStyle(fontSize: 22.0)); } DefaultStyles merge(DefaultStyles other) { @@ -180,6 +189,9 @@ class DefaultStyles { other.quote ?? this.quote, other.code ?? this.code, other.indent ?? this.indent, - other.align ?? this.align); + other.align ?? this.align, + other.sizeSmall ?? this.sizeSmall, + other.sizeLarge ?? this.sizeLarge, + other.sizeHuge ?? this.sizeHuge); } } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 5bc18e00..973c99a9 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -248,6 +248,28 @@ class TextLine extends StatelessWidget { } }); + Attribute font = textNode.style.attributes[Attribute.font.key]; + if (font != null && font.value != null) { + res = res.merge(TextStyle(fontFamily: font.value)); + } + + Attribute size = textNode.style.attributes[Attribute.size.key]; + if (size != null && size.value != null) { + switch (size.value) { + case 'small': + res = res.merge(defaultStyles.sizeSmall); + break; + case 'large': + res = res.merge(defaultStyles.sizeLarge); + break; + case 'huge': + res = res.merge(defaultStyles.sizeHuge); + break; + default: + throw "Invalid size ${size.value}"; + } + } + Attribute color = textNode.style.attributes[Attribute.color.key]; if (color != null && color.value != null) { final textColor = _hexStringToColor(color.value); diff --git a/pubspec.yaml b/pubspec.yaml index 764f1ea7..5076e551 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: One client and affiliated collaborator of Flutter Quill is Bullet Journal App. -version: 0.1.7 +version: 0.1.8 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill.git