flutter_html_css_font_size 0.2.0
flutter_html_css_font_size: ^0.2.0 copied to clipboard
A flutter_html extension that renders a relative CSS font-size. flutter_html 3.0.0 drops rem and compounds em and percentages.
0.2.0 #
- Renamed from
flutter_html_css_font_size_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 a relative
font-sizefrom an element's inline style:rem,em, percentages,smallerandlarger.flutter_html3.0.0 has therembranch ofexpressionToFontSizecommented out, so the declaration goes in and nothing comes out; the element just keeps the size it inherited.smallerandlargerfall through the same function's keyword list, so they are in here too. emand percentages are in here for a different reason. flutter_html parses them fine and then applies them once per level of the tree below the element that declares it, sofont-size: 2emon a div renders its text at 56 instead of 28, and 112 with one more level of nesting.styleTree()merges the inline declaration after it cascades the parent in, so every descendant inherits the raw2emandRelativeSizesProcessingmultiplies it again at each level. We now write the resolved pixel size down the subtree, which leaves that pass nothing to multiply.2emunder 14 is 28 at any depth;2emthen1.5emis 42, because the factor still compounds once per declaring element, which is what CSS asks for.- The size goes onto the element and down its subtree. Writing it onto the
element alone looks right in a debugger and changes nothing on screen:
flutter_html draws text from the
Styleof the text node, and the cascade that would have copied the new size into that node ran a step earlier. Cost me an afternoon, hence this bullet. - Ships
resolvedFontSizeOf, for siblings that need a font size before flutter_html has resolved one, and it is also where every pixel number above comes from.StyledElementhas no parent pointer in 3.0.0 and the styled tree's root is private, so it walks the DOM chain instead: inline styles plus flutter_html's own per-tag defaults. Same answer at every step, which is the whole point. - Reading the DOM has a price, and
emis where you feel it. An ancestor whose size came fromHtml(style: ...)or a<style>block is invisible, so a2emunder a 20px div resolves against the root 14 and renders 28 rather than 40. flutter_html alone renders 80 there. Neither is right; put the size in the inline style if you care. - Headings and the other tags flutter_html sizes itself are fixed too. An
<h1>inside<div style="font-size: 2em">renders at 4 without us:FontSize.inheritmultiplied the heading's own2emdefault by the parent's raw2eminstead of by the parent's computed 28. Same story forh2,h3,h5,h6,big,small,subandsup, and aremparent is no escape either (2remaround anh1gave 28, not 56). A percentage parent is the funny one:200%around anh1renders at 400, becauseinheritmultiplies by the number 200. The subtree walk used to stop at any of these, since they hold a size that is not the one they inherited. It now recognises a per-tag default, recomputes it withresolvedFontSizeOfand keeps walking, so the heading and everything under it get the CSS number. All of it pinned in tests, both columns. <font size="+2">now renders step 5 (15.75) instead of 14. Upstream bug, and a fun one:numberToFontSizerecurses with(3 + 2).toString(), which is the string"5.0"and not"5", so it matches no case, then on the second pass it no longer starts with+, and it falls out the bottom intoFontSize.medium. Every+nand-nform lands on 14. No error, no warning. We claim such a<font>element even though it has no inline style, and write the step it actually asked for.px, a unitless0and the sevenxx-smalltoxx-largekeywords are left alone on purpose. They already render and they do not compound.