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
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.
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.
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).
I forgot: examples of how to use it!
Stylesheet:
http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/input/test_issue_289.style
Text:
http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/input/test_issue_289.txt
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
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!
:-)
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
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).
["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.
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 ]
> ]
> }]
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?
I am creating Issue 301 for this, because it's a bit trickier than expected.
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.
Thanks for the quick replies, Roberto!
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