flutter_html_css_line_height 0.2.0
flutter_html_css_line_height: ^0.2.0 copied to clipboard
A flutter_html extension that renders line-height as a number, %, em, rem or px at the size CSS asks for, and inherits it the way CSS does.
0.2.0 #
- Renamed from
flutter_html_css_line_height_extensionon pub.flutter-io.cn. The old package stays published and is marked discontinued with this one as its replacement. Class names are unchanged.
0.1.0 #
- Initial release. Renders the CSS
line-heightat the size CSS asks for.flutter_html3.0.0 bakes a 1.2 into everyLineHeightfactory and then hands the stored value toTextStyle.height, which is already a ratio of the font size, so every line box comes out 20 per cent too tall:line-height: 1.5renders a 25 px line where CSS gives 21, andline-height: 2renders 34 px where CSS gives 28. A percentage, anem, aremand a<style>block are all hit the same way. - An absolute length is the loud one, except that it is silent too.
expressionToLineHeightstores the pixel count with no 1.2, andgenerateTextStylehands that pixel count over as a ratio, soline-height: 24pxrenders one line 336 px tall on a 14 px paragraph, and 672 px next tofont-size: 28px.Style.copyOnlyInheriteddoes own a length-to-ratio conversion, but_styleTreeRecursivecascades into a child before the child's own inline style is merged, so an inline declaration never reaches it. That branch is dead for anything written in astyle=""attribute. - The fix is arithmetic on
Style.lineHeightat thepreProcessingstep, plus a walk down the subtree. A number, a percentage and anemdivide by 1.2; aremand a length need the computed font size, andStyle.fontSizeis already in pixels at that step for everything except an inlineemor%size, which a DOM walk covers. The subtree walk is what makes any of it visible, becauseflutter_htmlrenders text from theStyleof the text node and the text node holds a copy of the element's value. - Inheritance follows CSS now: a
<number>inherits as a factor and everything else inherits as the computed length, so<p style="line-height: 24px"><span style="font-size: 28px">renders a 24 px line instead of a 672 px one. line-height: normalis left alone, and so areinherit,initial,unset,revert,calc()and every other value the parser cannot read. All of them land onLineHeight(1.2)with an emptyunits, which is exactly what a tag default lands on, and nothing at this step can tell them apart. Correcting them would mean correcting every<p>in the document.- Register it anywhere in the
extensionslist. There's no order rule: I measured both orders againstflutter_html_css_font_size,flutter_html_css_text_metrics, aTagExtensionand the two utility-class packages, and nothing moved. You still want the font-size extension registered when anemorremfont size is in play, because a ratio is a ratio of the size that renders:font-size: 2em; line-height: 1.5remis 101 px bare, 42 px with this package alone and 21 px with both. flutter_html_bootstrap0.1.2 andflutter_html_vuetify0.1.1 need no release and no companion table entry. Both already countline-heightas supported, so neither suppresses it, and theirlh-*andtext-*classes have been rendering 20 per cent too tall all along. Registering this extension corrects them:lh-baseandtext-body-1go from 25 px to 21 px.- The tests pin those two versions as dev constraints. Vuetify 0.1.1 leaves a
remfont size out of the inlined style unless the font-size extension is registered, and names eachtext-*class throughFlutterError.reportErrorfor that and for itsletter-spacing; the tests capture the report and assert thatline-heightis never in it.