1

I have an RST file to compile with Sphinx.

I have a block diagram there.

I want to give non-english names to some of its nodes.

.. blockdiag::

   diagram {
     "UberMega" -> "HellSotona" -> "KakoDemon" -> "Кролики и котятки";
   }

Alas, it gives me an error:

  File "C:\Python2\lib\site-packages\blockdiag\imagedraw\png.py", line 282, in textlinesize
    size = self.draw.textsize(string, font=None)
  File "C:\Python2\lib\site-packages\PIL\ImageDraw.py", line 282, in textsize
    return font.getsize(text)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-5: ordinal not in range(256)
WARNING: blockdiag error: UnicodeEncodeError caught (check your font settings)

How can I cope with it?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Felix
  • 3,351
  • 6
  • 40
  • 68
  • 1
    The error originates in PIL/Pillow's ImageDraw.py module, and I think this question is related: http://stackoverflow.com/q/18942605/407651. I have no solution to your problem, however. – mzjn Jul 02 '15 at 18:03

2 Answers2

0

Strings in python 2 aren't unicode by default. Try this:

.. blockdiag::

diagram {
 "UberMega" -> "HellSotona" -> "KakoDemon" -> u"Кролики и котятки";
}
atlspin
  • 76
  • 8
  • I've tried. Nothing changes. It looks like blockdiag doesn't eat u'' marker. – Felix Jul 01 '15 at 11:54
  • Gives an Error: C:\Projects\PAT\PyPhased\docs\simple_pulse_radar.rst:6: WARNING: undecodable source characters, replacing with "?": ' "Rectangular Waveform" -> "Transmitter" -> "Radiator" -> "Free Space" -> "Target" -> unicode("\xca\xf0\xee\xeb\xe8\xea>>>\xe8<<<");' C:\Projects\PAT\PyPhased\docs\simple_pulse_radar.rst:3: WARNING: Got unexpected token at line 2 column 95 – Felix Jul 01 '15 at 12:26
  • What if you add this to the top of the file? '# -*- coding: utf-8 -*-'. May need to add it to conf.py also/instead Edit: There is one asterisk in the middle of each set of dashes, i don't know why its not showing – atlspin Jul 01 '15 at 12:47
0

Just faced the same problem. Looks like you're using it in sphinx documentation.

You should point to your unicode TrueType font (put it in _static directory, i've chosen a DejaVuSans. No reasons, it's just easy to find over Internet). Copy your .ttf file to static directory and add this lines to conf.py:

import os
blockdiag_fontpath = os.path.abspath(u'_static/fonts/DejaVuSans.ttf')

Note the u mark before the relative path. Blockdiag ignores this if the path to your project includes any non-ASCII characters and the path is not a unicode string.

Serge Norin
  • 101
  • 1
  • 2