Bullet font size

55 views
Skip to first unread message

Malte Schwerhoff

unread,
Mar 17, 2010, 5:38:53 PM3/17/10
to rst2pdf-discuss
Hello,

I can't figure out how to set the bullet font size of, well, a bullet
list item. I've set "bulletFontSize" in the "base" style and in
several other styles, but the bullet size seems to allways follow the
font size.

Then I modified styles.py around line 470:

# If the bullet font size is not set, set it as fontSize
if ('bulletFontSize' not in s) and ('fontSize' in s):
s['bulletFontSize'] = self.StyleSheet['base'].bulletFontSize

print s['bulletFontSize']

but even that had no visible effect on the generation.

Any ideas on that?

Also, (how) can I change the character that is used as the bullet
symbol?

Thanks,
Malte

Roberto Alsina

unread,
Mar 18, 2010, 5:59:02 AM3/18/10
to rst2pdf...@googlegroups.com

You know, that's an excellent question! :-)

Looks like noone tried to do that before, so I just don't know. Let me run a
few tests and get back with a reply in a few hours.

Roberto Alsina

unread,
Mar 18, 2010, 8:30:02 AM3/18/10
to rst2pdf...@googlegroups.com
Ok, looked at the code.

On Thursday 18 March 2010 06:59:02 Roberto Alsina wrote:
> On Wednesday 17 March 2010 18:38:53 Malte Schwerhoff wrote:
> > Hello,
> >
> > I can't figure out how to set the bullet font size of, well, a bullet
> > list item. I've set "bulletFontSize" in the "base" style and in
> > several other styles, but the bullet size seems to allways follow the
> > font size.

It turns out this is not used anywhere anymore. bulletFontSize is a feature of
reportlab: paragraphs can have a "bullet" property, and this is the size it's
drawn with.

However, since we are not doing bullets that way (because they look awful for
multi-paragraph items among other things), we are just using the fontSize.

It seems increasing the font size should increase the bullet size, but that's
surely not what you wanted.

So... I just created Issue 289, test cases coming soon, solutions later.

Roberto Alsina

unread,
Mar 18, 2010, 2:00:55 PM3/18/10
to rst2pdf...@googlegroups.com
On Wednesday 17 March 2010 18:38:53 Malte Schwerhoff wrote:

As of revision 1938 in SVN here is the current status:

The following properties can be used in a style that can be applied to a
bullet/item list:

* bulletFontSize, when specified, will make the bullet larger/smaller than
the text. This has bad side effects in the alignment between the bullet
and the item, so use with care.

* bulletFontName will change the font used for the bullet character.

* bulletText will use a specific text instead of character \u2022 as
the bullet (only for bullet lists of course, it's ignored on all
other kinds of lists).

Is this enough customization? Any other ideas?

All these changes will be part of 0.13.2 to be released monday (maybe).

Roberto Alsina

unread,
Mar 18, 2010, 2:09:53 PM3/18/10
to rst2pdf...@googlegroups.com

Malte Schwerhoff

unread,
Mar 20, 2010, 1:34:08 PM3/20/10
to rst2pdf...@googlegroups.com
Hello Roberto,

thanks for the quick help! This fully covers what I had in mind and the
only addition I can currently think of is the bullet colour.

Having a look at your usage examples, how about defining suffixes that
determine to which element a class is applied? E.g.

..class:: big-bullet
..class:: red-bullet-item

* The sun is shining
* And I like it

where the style 'big-bullet' would be applied to the bullet symbol and
'red-bullet-item' to the actual text.

This way all existing style properties could be applied to the bullet
symbol for free without having to provide them as new properties such as
'bulletFontSize'.

Something else: if I'd like to hook into the render process, e.g. I'd
like to transform the document structure before it is passed to the
current transformer (or after it has been transformed), how would I do
that? By transformer I simply mean the method that creates the Reportlab
code for e.g. a footnote.

Anyway, thanks for your great work so far, I really enjoy working with
rst2pdf!

Cheers
Malte

Roberto Alsina

unread,
Mar 20, 2010, 3:19:05 PM3/20/10
to rst2pdf...@googlegroups.com
On Saturday 20 March 2010 14:34:08 Malte Schwerhoff wrote:
> Hello Roberto,
>
> thanks for the quick help! This fully covers what I had in mind and the
> only addition I can currently think of is the bullet colour.
>
> Having a look at your usage examples, how about defining suffixes that
> determine to which element a class is applied? E.g.
>
> ..class:: big-bullet
> ..class:: red-bullet-item
>
> * The sun is shining
> * And I like it
>
> where the style 'big-bullet' would be applied to the bullet symbol and
> 'red-bullet-item' to the actual text.

That may be a bit complicated. I'll see what can be done.

> This way all existing style properties could be applied to the bullet
> symbol for free without having to provide them as new properties such as
> 'bulletFontSize'.
>
> Something else: if I'd like to hook into the render process, e.g. I'd
> like to transform the document structure before it is passed to the
> current transformer (or after it has been transformed), how would I do
> that? By transformer I simply mean the method that creates the Reportlab
> code for e.g. a footnote.

Look at how main() works in createpdf.py

Basically, you take rst sources, and create a doctree from that.
The doctree is converted into a list of reportlab flowables.
That is converted into a PDF.

You can hook anywhere in the process, even if it may mean, in the worst case
copy&past of a big chunk of code ;-)

> Anyway, thanks for your great work so far, I really enjoy working with
> rst2pdf!

:-)

Malte Schwerhoff

unread,
Mar 25, 2010, 6:06:31 AM3/25/10
to rst2pdf...@googlegroups.com
Am 18.03.2010 19:00, schrieb Roberto Alsina:
> The following properties can be used in a style that can be applied to a
> bullet/item list:
>
> * bulletFontSize, when specified, will make the bullet larger/smaller than
> the text. This has bad side effects in the alignment between the bullet
> and the item, so use with care.
Using a bulletFontSize much smaller than the regular font size (e.g. 14
and 22), I end up with the bullet symbol being typeset at the top of the
"bounding box" of the text, like it was set in superscript mode.

It looks like this:
� Some text
� Some more text

Can I add some top padding to the bullet symbol, or, even better, have
it automatically vertically centred?

Cheers
Malte

Roberto Alsina

unread,
Mar 25, 2010, 6:25:26 AM3/25/10
to rst2pdf...@googlegroups.com

This is rendered this way (of course the table borders are invisible ;-):

+----+----------------------------+
| * | The text of the bullet |
| | |
| | Which can be tall. |
+----+----------------------------+

So probably vertical centering is not what you want (but you probably can do
it!) but TOPPADDING instead.

Maybe something like these in the "command" property of the style (syntax for
this may vary a bit depending on whether you are using a JSON or RSON
stylesheet, sorry!.

For the vertical centering idea:

[VALIGN, [ 1, 0 ], [ 1, -1 ], TOP ]
[RIGHTPADDING, [ 0, 0 ], [ 1, -1 ], 0 ]
[VALIGN, [ 0, 0 ], [ 0, -1 ], MIDDLE ]

For the extra padding:

[VALIGN, [ 1, 0 ], [ 1, -1 ], TOP ]
[RIGHTPADDING, [ 0, 0 ], [ 1, -1 ], 0 ]
[TOPPADDING, [ 0, 0 ], [ 0, -1 ], 12 ]

(replacing 12 with whatever is needed).

Malte Schwerhoff

unread,
Mar 25, 2010, 6:36:58 AM3/25/10
to rst2pdf...@googlegroups.com
Am 25.03.2010 11:25, schrieb Roberto Alsina:
> For the extra padding:
>
> [VALIGN, [ 1, 0 ], [ 1, -1 ], TOP ]
> [RIGHTPADDING, [ 0, 0 ], [ 1, -1 ], 0 ]
> [TOPPADDING, [ 0, 0 ], [ 0, -1 ], 12 ]
I tried the above with the styles "bullet_list" and "bullet_list_item", e.g.

["bullet_list" , {
"bulletFontSize": 14,
"command": [
[VALIGN, [ 1, 0 ], [ 1, -1 ], TOP ],
[RIGHTPADDING, [ 0, 0 ], [ 1, -1 ], 0 ],
[TOPPADDING, [ 0, 0 ], [ 0, -1 ], 30 ]
]
}]

but the TOPPADDING value (here 30) does not seem to have any influence
on how the bullet it typeset.

Roberto Alsina

unread,
Mar 25, 2010, 6:58:40 AM3/25/10
to rst2pdf...@googlegroups.com

Try it with quotes in all strings:

> ["bullet_list" , {
> "bulletFontSize": 14,
> "command": [

> ["VALIGN", [ 1, 0 ], [ 1, -1 ], "TOP" ],
> ["RIGHTPADDING", [ 0, 0 ], [ 1, -1 ], 0 ],
> ["TOPPADDING", [ 0, 0 ], [ 0, -1 ], 30 ]
> ]
> }]

Malte Schwerhoff

unread,
Mar 25, 2010, 8:30:35 AM3/25/10
to rst2pdf...@googlegroups.com
Am 25.03.2010 11:58, schrieb Roberto Alsina:
> Try it with quotes in all strings:
>
>> ["bullet_list" , {
>> "bulletFontSize": 14,
>> "command": [
>> ["VALIGN", [ 1, 0 ], [ 1, -1 ], "TOP" ],
>> ["RIGHTPADDING", [ 0, 0 ], [ 1, -1 ], 0 ],
>> ["TOPPADDING", [ 0, 0 ], [ 0, -1 ], 30 ]
>> ]
>> }]
Still no success.

I added
["BACKGROUND", [ 0, 0 ], [ 1, -1 ], "#339911"]
to the list of command, but that is ignored, too (but the style is not
ignored in general, i.e. "bulletFontSize" has an impact).

Could the "command" property be ignored in case of the "bullet_list"
style or can it happen that the property is somehow overridden?

Roberto Alsina

unread,
Mar 25, 2010, 8:38:31 AM3/25/10
to rst2pdf...@googlegroups.com

I am creating Issue 301 for this, because it's a bit trickier than expected.

Roberto Alsina

unread,
Mar 25, 2010, 10:25:02 AM3/25/10
to rst2pdf...@googlegroups.com
On Thursday 25 March 2010 09:30:35 Malte Schwerhoff wrote:

It was a bug, of course.

After r2032 it should start working. OTOH, I even managed to give you bad
advice about the stylesheet ;-)

Check these for a working example (again: after r2032)

http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/input/test_issue_301.txt

http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/input/test_issue_301.style

The stylesheet is in RSON format, but how to translate the commands to JSON
should be obvious.

Malte Schwerhoff

unread,
Mar 25, 2010, 10:38:21 AM3/25/10
to rst2pdf...@googlegroups.com
Am 25.03.2010 13:38, schrieb Roberto Alsina:
> On Thursday 25 March 2010 09:30:35 Malte Schwerhoff wrote:
>> Am 25.03.2010 11:58, schrieb Roberto Alsina:
>>> Try it with quotes in all strings:["bullet_list" , {
> >> "bulletFontSize": 14,
> >> "command": [
> >> ["VALIGN", [ 1, 0 ], [ 1, -1 ], "TOP" ],
> >> ["RIGHTPADDING", [ 0, 0 ], [ 1, -1 ], 0 ],
> >> ["TOPPADDING", [ 0, 0 ], [ 0, -1 ], 30 ]
> >> ]
> >> }]
>>
>> Still no success.
... because I made a typo, it's "commands" not "command" ... Using the
correct spelling it actually works :-)

Thanks for the quick replies, Roberto!

Patrick Maupin

unread,
Mar 25, 2010, 11:03:07 AM3/25/10
to rst2pdf...@googlegroups.com
On Thu, Mar 25, 2010 at 8:25 AM, Roberto Alsina
<ral...@netmanagers.com.ar> wrote:
> The stylesheet is in RSON format, but how to translate the commands to JSON
> should be obvious.

Actually, the commands as shown:

styles:
smallbullet:
bulletFontSize: 12
fontSize: 32
parent: bullet_list
commands: [
[ TOPPADDING, [0,0],[0,0], 50],
[ VALIGN, [0,0],[-1,-1], TOP],
[ COLBACKGROUNDS, [0,0],[0,-1],["red"]],
[ INNERGRID, [0,0], [-1,-1], 0.25, black],
[ BOX, [0,0], [-1,-1], 0.25, black]
]

do not take full advantage of the RSON format. RSON allows you to
define an empty list or dict and then fill it, so you don't have lots
of nasty lisp-ish unclosed ] hanging around. For the parts in pure
RSON, the end of line also removes the need for a comma:

styles:
smallbullet:
bulletFontSize: 12
fontSize: 32
parent: bullet_list
commands: []
[ TOPPADDING, [0,0],[0,0], 50]
[ VALIGN, [0,0],[-1,-1], TOP]
[ COLBACKGROUNDS, [0,0],[0,-1],["red"]]
[ INNERGRID, [0,0], [-1,-1], 0.25, black]
[ BOX, [0,0], [-1,-1], 0.25, black]

But the other way works as well. The way RSON works is that, *inside*
any [] or {} pair, it's JSON syntax (with a few enhancements like not
needing quotation marks), and *outside* those [] or {} pairs, it's an
indented syntax. So even in the second case shown, each actual
command is in what I consider "enhanced JSON" syntax, because it would
be silly to put TOPPADDING on a line by itself, [0,0] on the next
line, etc. But the overall commands list is in RSON syntax, which
basically declares a list and then fills it, as opposed to opening the
list, and closing it after everything else.

Regards,
Pat

Reply all
Reply to author
Forward
0 new messages