[blockdiag] 10/29: Import Upstream version 1.1.6

Andreas Tille tille at debian.org
Tue Jan 10 21:35:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository blockdiag.

commit 36b1ea48680d8109ffe69d4a50e6c10eff56227f
Author: Andreas Tille <tille at debian.org>
Date:   Tue Jan 10 11:08:03 2017 +0100

    Import Upstream version 1.1.6
---
 PKG-INFO                                   |  8 +++++++-
 setup.py                                   |  7 ++++++-
 src/README.txt                             |  6 ++++++
 src/blockdiag.egg-info/PKG-INFO            |  8 +++++++-
 src/blockdiag/__init__.py                  |  2 +-
 src/blockdiag/imagedraw/png.py             |  9 +++++----
 src/blockdiag/imagedraw/svg.py             |  2 +-
 src/blockdiag/tests/test_rst_directives.py | 14 ++++++++++++++
 src/blockdiag/utils/PILTextFolder.py       | 13 +++++++++++--
 src/blockdiag/utils/TextFolder.py          | 11 ++---------
 src/blockdiag/utils/bootstrap.py           |  8 +++++++-
 src/blockdiag/utils/fontmap.py             |  5 +++--
 src/blockdiag/utils/rst/directives.py      | 10 ++++++++++
 13 files changed, 80 insertions(+), 23 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index ef8bcd9..9233748 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: blockdiag
-Version: 1.1.5
+Version: 1.1.6
 Summary: blockdiag generate block-diagram image file from spec-text file.
 Home-page: http://blockdiag.com/
 Author: Takeshi Komiya
@@ -121,6 +121,12 @@ Description: `blockdiag` generate block-diagram image file from spec-text file.
         History
         =======
         
+        1.1.6 (2012-06-06)
+        ------------------
+        * Support for readthedocs.org
+        * reST directive supports :caption: option
+        * Fix bugs
+        
         1.1.5 (2012-04-22)
         ------------------
         * Embed source code to SVG document as description
diff --git a/setup.py b/setup.py
index 655ffd5..6528889 100644
--- a/setup.py
+++ b/setup.py
@@ -34,8 +34,13 @@ requires = ['setuptools',
             'webcolors']
 deplinks = []
 
+# For readthedocs.org
+# http://read-the-docs.readthedocs.org/en/latest/faq.html#how-do-i-change-behavior-for-read-the-docs
 # Find imaging libraries
-if is_installed('PIL'):
+
+if 'READTHEDOCS' in os.environ:
+    requires.append('Pillow')
+elif is_installed('PIL'):
     requires.append('PIL')
 elif is_installed('Pillow'):
     requires.append('Pillow')
diff --git a/src/README.txt b/src/README.txt
index 3bffb00..f9a6877 100644
--- a/src/README.txt
+++ b/src/README.txt
@@ -113,6 +113,12 @@ Apache License 2.0
 History
 =======
 
+1.1.6 (2012-06-06)
+------------------
+* Support for readthedocs.org
+* reST directive supports :caption: option
+* Fix bugs
+
 1.1.5 (2012-04-22)
 ------------------
 * Embed source code to SVG document as description
diff --git a/src/blockdiag.egg-info/PKG-INFO b/src/blockdiag.egg-info/PKG-INFO
index ef8bcd9..9233748 100644
--- a/src/blockdiag.egg-info/PKG-INFO
+++ b/src/blockdiag.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: blockdiag
-Version: 1.1.5
+Version: 1.1.6
 Summary: blockdiag generate block-diagram image file from spec-text file.
 Home-page: http://blockdiag.com/
 Author: Takeshi Komiya
@@ -121,6 +121,12 @@ Description: `blockdiag` generate block-diagram image file from spec-text file.
         History
         =======
         
+        1.1.6 (2012-06-06)
+        ------------------
+        * Support for readthedocs.org
+        * reST directive supports :caption: option
+        * Fix bugs
+        
         1.1.5 (2012-04-22)
         ------------------
         * Embed source code to SVG document as description
diff --git a/src/blockdiag/__init__.py b/src/blockdiag/__init__.py
index 3a85051..1366786 100644
--- a/src/blockdiag/__init__.py
+++ b/src/blockdiag/__init__.py
@@ -13,4 +13,4 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-__version__ = '1.1.5'
+__version__ = '1.1.6'
diff --git a/src/blockdiag/imagedraw/png.py b/src/blockdiag/imagedraw/png.py
index 0624e5a..d233d23 100644
--- a/src/blockdiag/imagedraw/png.py
+++ b/src/blockdiag/imagedraw/png.py
@@ -17,7 +17,7 @@ import re
 import math
 from itertools import izip, tee
 from blockdiag.utils import ellipse, urlutil, Box
-from blockdiag.utils.fontmap import parse_fontpath
+from blockdiag.utils.fontmap import parse_fontpath, FontMap
 from blockdiag.utils.myitertools import istep, stepslice
 from blockdiag.utils.PILTextFolder import PILTextFolder as TextFolder
 try:
@@ -261,7 +261,7 @@ class ImageDrawEx(object):
             ttfont = None
 
         if ttfont is None:
-            if self.scale_ratio == 1:
+            if self.scale_ratio == 1 and font.size == FontMap.BASE_FONTSIZE:
                 self.draw.text(xy, string, fill=fill)
             else:
                 size = self.draw.textsize(string)
@@ -270,8 +270,9 @@ class ImageDrawEx(object):
                 draw.text((0, 0), string, fill=fill)
                 del draw
 
-                basesize = (size[0] * self.scale_ratio,
-                            size[1] * self.scale_ratio)
+                font_ratio = font.size * 1.0 / FontMap.BASE_FONTSIZE
+                basesize = (int(size[0] * self.scale_ratio * font_ratio),
+                            int(size[1] * self.scale_ratio * font_ratio))
                 text_image = image.resize(basesize, Image.ANTIALIAS)
 
                 self.image.paste(text_image, xy, text_image)
diff --git a/src/blockdiag/imagedraw/svg.py b/src/blockdiag/imagedraw/svg.py
index d5038ce..4ffddcc 100644
--- a/src/blockdiag/imagedraw/svg.py
+++ b/src/blockdiag/imagedraw/svg.py
@@ -226,7 +226,7 @@ class SVGImageDrawElement(object):
         if urlutil.isurl(filename):
             url = filename
         else:
-            string = open(filename).read()
+            string = open(filename, 'rb').read()
             url = "data:;base64," + base64.b64encode(string)
 
         x = box[0]
diff --git a/src/blockdiag/tests/test_rst_directives.py b/src/blockdiag/tests/test_rst_directives.py
index 1d255ed..2c9f82f 100644
--- a/src/blockdiag/tests/test_rst_directives.py
+++ b/src/blockdiag/tests/test_rst_directives.py
@@ -166,6 +166,20 @@ class TestRstDirectives(unittest2.TestCase):
         doctree = publish_doctree(text)
 
     @use_tmpdir
+    def test_caption(self, path):
+        directives.setup(format='SVG', outputdir=path)
+        text = ".. blockdiag::\n   :caption: hello world\n\n   { A -> B }"
+        doctree = publish_doctree(text)
+        self.assertEqual(1, len(doctree))
+        self.assertEqual(nodes.figure, type(doctree[0]))
+        self.assertEqual(2, len(doctree[0]))
+        self.assertEqual(nodes.image, type(doctree[0][0]))
+        self.assertEqual(nodes.caption, type(doctree[0][1]))
+        self.assertEqual(1, len(doctree[0][1]))
+        self.assertEqual(nodes.Text, type(doctree[0][1][0]))
+        self.assertEqual('hello world', doctree[0][1][0])
+
+    @use_tmpdir
     def test_block_maxwidth(self, path):
         directives.setup(format='SVG', outputdir=path)
         text = ".. blockdiag::\n   :maxwidth: 100\n\n   { A -> B }"
diff --git a/src/blockdiag/utils/PILTextFolder.py b/src/blockdiag/utils/PILTextFolder.py
index 7400adb..59e5a6e 100644
--- a/src/blockdiag/utils/PILTextFolder.py
+++ b/src/blockdiag/utils/PILTextFolder.py
@@ -22,7 +22,7 @@ except ImportError:
     import ImageDraw
     import ImageFont
 from TextFolder import TextFolder
-from fontmap import parse_fontpath
+from fontmap import parse_fontpath, FontMap
 
 
 class PILTextFolder(TextFolder):
@@ -38,8 +38,17 @@ class PILTextFolder(TextFolder):
 
         image = Image.new('1', (1, 1))
         self.draw = ImageDraw.Draw(image)
+        self.fontsize = font.size
 
         super(PILTextFolder, self).__init__(box, string, font, **kwargs)
 
     def textsize(self, string):
-        return self.draw.textsize(string, font=self.ttfont)
+        if self.ttfont is None:
+            size = self.draw.textsize(string, font=self.ttfont)
+
+            font_ratio = self.fontsize * 1.0 / FontMap.BASE_FONTSIZE
+            size = (int(size[0] * font_ratio), int(size[1] * font_ratio))
+        else:
+            size = self.draw.textsize(string, font=self.ttfont)
+
+        return size
diff --git a/src/blockdiag/utils/TextFolder.py b/src/blockdiag/utils/TextFolder.py
index 7827be6..7fe50cb 100644
--- a/src/blockdiag/utils/TextFolder.py
+++ b/src/blockdiag/utils/TextFolder.py
@@ -73,15 +73,8 @@ def string_width(string):
     >>> string_width(u"あいc")
     5
     """
-    width = 0
-    for c in string:
-        char_width = unicodedata.east_asian_width(c)
-        if char_width in u"WFA":
-            width += 2
-        else:
-            width += 1
-
-    return width
+    widthmap = {'Na': 1, 'N': 1, 'H': 1, 'W': 2, 'F': 2, 'A': 2}
+    return sum(widthmap[unicodedata.east_asian_width(c)] for c in string)
 
 
 class TextFolder(object):
diff --git a/src/blockdiag/utils/bootstrap.py b/src/blockdiag/utils/bootstrap.py
index bac0cdb..3b35ee1 100644
--- a/src/blockdiag/utils/bootstrap.py
+++ b/src/blockdiag/utils/bootstrap.py
@@ -39,7 +39,11 @@ class Application(object):
             sys.stderr.write(msg)
             return -1
         except Exception, e:
-            sys.stderr.write("ERROR: %s\n" % e)
+            if self.options.debug:
+                import traceback
+                traceback.print_exc()
+            else:
+                sys.stderr.write("ERROR: %s\n" % e)
             return -1
 
     def parse_options(self):
@@ -94,6 +98,8 @@ class Options(object):
                      help='Pass diagram image to anti-alias filter')
         p.add_option('-c', '--config',
                      help='read configurations from FILE', metavar='FILE')
+        p.add_option('--debug', action='store_true',
+                     help='Enable debug mode')
         p.add_option('-o', dest='output',
                      help='write diagram to FILE', metavar='FILE')
         p.add_option('-f', '--font', default=[], action='append',
diff --git a/src/blockdiag/utils/fontmap.py b/src/blockdiag/utils/fontmap.py
index ee28e1e..359051d 100644
--- a/src/blockdiag/utils/fontmap.py
+++ b/src/blockdiag/utils/fontmap.py
@@ -87,7 +87,8 @@ class FontInfo(object):
 
 
 class FontMap(object):
-    fontsize = 11
+    BASE_FONTSIZE = 11
+    fontsize = BASE_FONTSIZE
     default_fontfamily = 'sansserif'
 
     def __init__(self, filename=None):
@@ -137,7 +138,7 @@ class FontMap(object):
             sys.stderr.write("WARNING: %s\n" % msg)
 
     def _regulate_familyname(self, name):
-        return FontInfo(name, None, 11).familyname
+        return FontInfo(name, None, self.BASE_FONTSIZE).familyname
 
     def find(self, element=None):
         fontfamily = getattr(element, 'fontfamily', None) or \
diff --git a/src/blockdiag/utils/rst/directives.py b/src/blockdiag/utils/rst/directives.py
index 946a804..e232365 100644
--- a/src/blockdiag/utils/rst/directives.py
+++ b/src/blockdiag/utils/rst/directives.py
@@ -70,6 +70,7 @@ class BlockdiagDirectiveBase(rst.Directive):
     final_argument_whitespace = False
     option_spec = {
         'alt': rst.directives.unchanged,
+        'caption': rst.directives.unchanged,
         'desctable': rst.directives.flag,
         'maxwidth': rst.directives.nonnegative_int,
     }
@@ -103,6 +104,9 @@ class BlockdiagDirectiveBase(rst.Directive):
         node = self.node_class()
         node['code'] = dotcode
         node['alt'] = self.options.get('alt')
+        if 'caption' in self.options:
+            node['caption'] = self.options.get('caption')
+
         node['options'] = {}
         if 'maxwidth' in self.options:
             node['options']['maxwidth'] = self.options['maxwidth']
@@ -136,6 +140,12 @@ class BlockdiagDirective(BlockdiagDirectiveBase):
 
         results[0] = self.node2image(node, diagram)
 
+        if 'caption' in node:
+            fig = nodes.figure()
+            fig += results[0]
+            fig += nodes.caption(text=node['caption'])
+            results[0] = fig
+
         return results
 
     def node2diagram(self, node):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/blockdiag.git



More information about the debian-science-commits mailing list