Skip to content

Commit 09364ad

Browse files
committed
fix overriden text scale
1 parent 2d1f580 commit 09364ad

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/html_parser.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class HtmlParser extends StatefulWidget {
121121
child: CssBoxWidget(
122122
style: tree.style,
123123
shrinkWrap: newContext.parser.shrinkWrap,
124+
overriddenTextScaleFactor: textScaleFactor,
124125
childIsReplaced: true, //TODO is this true?
125126
child: customRenders[entry]!.widget!.call(newContext, buildChildren),
126127
),

lib/src/css_box_widget.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class CssBoxWidget extends StatelessWidget {
99
super.key,
1010
required this.child,
1111
required this.style,
12+
this.overriddenTextScaleFactor,
1213
this.textDirection,
1314
this.childIsReplaced = false,
1415
this.shrinkWrap = false,
@@ -23,6 +24,7 @@ class CssBoxWidget extends StatelessWidget {
2324
this.textDirection,
2425
this.childIsReplaced = false,
2526
this.shrinkWrap = false,
27+
this.overriddenTextScaleFactor,
2628
bool selectable = false,
2729
TextSelectionControls? selectionControls,
2830
ScrollPhysics? scrollPhysics,
@@ -39,6 +41,10 @@ class CssBoxWidget extends StatelessWidget {
3941
/// The child to be rendered within the CSS Box.
4042
final Widget child;
4143

44+
/// The [overriddenTextScaleFactor] variable stores a value representing the text scale factor. This overrides the system's default text scale factor and is used to scale the text size
45+
/// If this variable is not set, the application will use the default text scale factor provided by [MediaQuery.textScaleFactorOf].
46+
final double? overriddenTextScaleFactor;
47+
4248
/// The style to use to compute this box's margins/padding/box decoration/width/height/etc.
4349
///
4450
/// Note that this style will only apply to this box, and will not cascade to its child.
@@ -87,6 +93,11 @@ class CssBoxWidget extends StatelessWidget {
8793
);
8894
}
8995

96+
double _calculateEmValue(Style style, BuildContext buildContext) {
97+
final scaleFactor = overriddenTextScaleFactor ?? MediaQuery.textScaleFactorOf(buildContext);
98+
return (style.fontSize?.emValue ?? 16) * scaleFactor * MediaQuery.of(buildContext).devicePixelRatio;
99+
}
100+
90101
/// Takes a list of InlineSpan children and generates a Text.rich Widget
91102
/// containing those children.
92103
static Widget _generateWidgetChild(BuildContext context, List<InlineSpan> children, Style style) {
@@ -711,10 +722,6 @@ extension Normalize on Dimension {
711722
}
712723
}
713724

714-
double _calculateEmValue(Style style, BuildContext buildContext) {
715-
return (style.fontSize?.emValue ?? 16) * MediaQuery.textScaleFactorOf(buildContext) * MediaQuery.of(buildContext).devicePixelRatio;
716-
}
717-
718725
class CSSBoxParentData extends ContainerBoxParentData<RenderBox> {}
719726

720727
class _Sizes {

0 commit comments

Comments
 (0)