# Multi-line Text in blf (with multi colour option)

Further my previuos question, i'd like to know how i cant draw multi line with an array fonction on the Y axis always there concervant the different colors.

for exemple, i'd like draw:

"Ngons: 5"

"Tris: 60"

Ngons and Tris are the label and have to be in red

5 and 60 are the value and have to be in blue.

How can i do that please ?

Building on the previous answer, now you have to think about line-height. A reasonable line-height for typesetting is the height of capital M x 1.45. But the coefficient can range between 1.2 and 1.45 (See the wikipedia article on Leading. These values are suggestions, and for HUD text or UI information use the value that seems most pleasing and doesn't cause the text to be too close or too separated vertically.

Take for instance the default line-height of Blender fonts.

1 / 0.682 = 1.46    # it's only a suggestion anyway.


A multi-line version of the script from the previous question, might look something like this:

def draw_string(x, y, packed_strings):
font_id = 0
blf.size(font_id, 18, 72)
x_offset = 0
y_offset = 0
line_height = (blf.dimensions(font_id, "M")[1] * 1.45)
for command in packed_strings:
if len(command) == 2:
pstr, pcol = command
bgl.glColor4f(*pcol)
text_width, text_height = blf.dimensions(font_id, pstr)
blf.position(font_id, (x + x_offset), (y + y_offset), 0)
blf.draw(font_id, pstr)
x_offset += text_width
else:
x_offset = 0
y_offset -= line_height

x = 60
y = 100
RED = (1, 0, 0, 1)
GREEN = (0, 1, 0, 1)
BLUE = (0, 0, 1, 1)
CR = "Carriage Return"
ps = [("Blue ", RED),("Yellow ", BLUE), CR, ("White ", GREEN)]
draw_string(x, y, ps)


You aren't limited to single words either:

ps = [("Blue Steel", RED),("Yellow Monk Fruit", BLUE), CR, ("White as an otter", GREEN)]
draw_string(x, y, ps)


produces this. (and note I forgot on purpose to add a space after "Fruit" to show how words are separated).

caveat: Don't change the "Carriage Return" string to something with 2 characters, it's a place-holder to keep the code simple and its length must be anything other than 2.

• Thank you very much once again, it is just that I needed – pistiwique Jun 1 '15 at 10:51