Markwon icon indicating copy to clipboard operation
Markwon copied to clipboard

Add boldListItemNumber theme property

Open bastienleonard opened this issue 5 years ago • 1 comments

It controls whether we show the number part of ordered lists in bold.

bastienleonard avatar Nov 26 '20 08:11 bastienleonard

Hello @bastienleonard ,

thank you for your submission. Unfortunately achieving bold ordering numbers would require a bit more complex approach. Mainly due to the code:

paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));

which would create a default bold typeface. There are numerous ways to set a typeface on a TextView and implicitly applying a default typeface might result in an unexpected visual style. As the absolute minimum TextView's typeface must be used in order to create a bold variant of it. You can obtain it by inspecting TextPaint that we receive in a span. And then creating a bold variant based on that. A good example is system's StyleSpan.

And then there is another problem - order number margin. Ordering numbers are drawn on canvas, and not present in actual text. So, we need to know ordering number width before-hand (before rendering) so span can correctly report margin taken and position number on canvas accordingly. Markwon measures ordering number before rendering using typeface of a TextView. Without inspecting MarkwonTheme. So, in case of a bold typeface, measuring would be off. (number can go out of original TextView bounds, aka clipped). I see no easy way out of this. Except maybe changing how ordering lists are marked. Most likely, using ordering numbers as text (and not drawing them on canvas).

If you wish, please continue with this pull request, but be aware that maybe ordered lists are going to be changed

noties avatar Dec 03 '20 22:12 noties