Commits

Takeshi Komiya committed 51e7608

Add config value: blockdiag_fontmap

Comments (0)

Files changed (9)

 This module needs actdiag_.
 '''
 
-requires = ['blockdiag>=1.0.1', 'actdiag>=0.2.3', 'Sphinx>=0.6']
+requires = ['actdiag>=0.3.0', 'Sphinx>=0.6']
 
 setup(
     name='sphinxcontrib-actdiag',
-    version='0.3.0',
+    version='0.3.1',
     url='http://bitbucket.org/birkenfeld/sphinx-contrib',
     download_url='http://pypi.python.org/pypi/sphinxcontrib-actdiag',
     license='BSD',

actdiag/sphinxcontrib/actdiag.py

 from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
 from sphinx.util.compat import Directive
 
-from actdiag_sphinxhelper import diagparser, builder, DiagramDraw, ActdiagDirective
-from actdiag_sphinxhelper import actdiag
+from actdiag_sphinxhelper import command, diagparser, builder, DiagramDraw
+from actdiag_sphinxhelper import collections, FontMap
+from actdiag_sphinxhelper import actdiag, ActdiagDirective
+namedtuple = collections.namedtuple
 
 
 class ActdiagError(SphinxError):
     return relfn, outfn
 
 
-def get_fontpath(self):
-    fontpath = None
-    if self.builder.config.actdiag_fontpath:
-        actdiag_fontpath = self.builder.config.actdiag_fontpath
+def get_fontmap(self):
+    try:
+        fontmappath = self.builder.config.actdiag_fontmap
+        fontmap = FontMap(fontmappath)
+    except:
+        attrname = '_actdiag_fontmap_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('actdiag cannot load "%s" as fontmap file, '
+                   'check the actdiag_fontmap setting' % fontmappath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-        if isinstance(actdiag_fontpath, (str, unicode)):
-            actdiag_fontpath = [actdiag_fontpath]
+        fontmap = FontMap(None)
 
-        for path in actdiag_fontpath:
-            if os.path.isfile(path):
-                fontpath = path
+    try:
+        fontpath = self.builder.config.actdiag_fontpath
+        if isinstance(fontpath, (str, unicode)):
+            fontpath = [fontpath]
 
-        if fontpath is None:
-            attrname = '_actdiag_fontpath_warned'
-            if not hasattr(self.builder, attrname):
-                msg = ('actdiag cannot load "%s" as truetype font, '
-                       'check the actdiag_path setting' % fontpath)
-                self.builder.warn(msg)
+        if fontpath:
+            config = namedtuple('Config', 'font')(fontpath)
+            _fontpath = command.detectfont(config)
+            fontmap.set_default_font(_fontpath)
+    except:
+        attrname = '_actdiag_fontpath_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('actdiag cannot load "%s" as truetype font, '
+                   'check the actdiag_fontpath setting' % fontpath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-                setattr(self.builder, attrname, True)
-
-    return fontpath
+    return fontmap
 
 
 def create_actdiag(self, code, format, filename, options, prefix='actdiag'):
     Render actdiag code into a PNG output file.
     """
     draw = None
-    fontpath = get_fontpath(self)
+    fontmap = get_fontmap(self)
     try:
         tree = diagparser.parse(diagparser.tokenize(code))
         screen = builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.actdiag_antialias
-        draw = DiagramDraw.DiagramDraw(format, screen, filename, font=fontpath,
+        draw = DiagramDraw.DiagramDraw(format, screen, filename, fontmap=fontmap,
                                        antialias=antialias)
     except Exception, e:
         raise ActdiagError('actdiag error:\n%s\n' % e)
                  latex=(latex_visit_actdiag, None))
     app.add_directive('actdiag', Actdiag)
     app.add_config_value('actdiag_fontpath', None, 'html')
+    app.add_config_value('actdiag_fontmap', None, 'html')
     app.add_config_value('actdiag_antialias', False, 'html')
     app.add_config_value('actdiag_html_image_format', 'PNG', 'html')
     app.add_config_value('actdiag_tex_image_format', 'PNG', 'html')

blockdiag/setup.py

 This module needs blockdiag_.
 '''
 
-requires = ['blockdiag>=1.0.1', 'Sphinx>=0.6']
+requires = ['blockdiag>=1.1.0', 'Sphinx>=0.6']
 
 setup(
     name='sphinxcontrib-blockdiag',
-    version='1.0.0',
+    version='1.0.1',
     url='http://bitbucket.org/birkenfeld/sphinx-contrib',
     download_url='http://pypi.python.org/pypi/sphinxcontrib-blockdiag',
     license='BSD',

blockdiag/sphinxcontrib/blockdiag.py

 from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
 from sphinx.util.compat import Directive
 
-from blockdiag_sphinxhelper import diagparser, builder, DiagramDraw, BlockdiagDirective
-from blockdiag_sphinxhelper import blockdiag
+from blockdiag_sphinxhelper import command, diagparser, builder, DiagramDraw
+from blockdiag_sphinxhelper import collections, FontMap
+from blockdiag_sphinxhelper import blockdiag, BlockdiagDirective
+namedtuple = collections.namedtuple
 
 
 class BlockdiagError(SphinxError):
     return relfn, outfn
 
 
-def get_fontpath(self):
-    fontpath = None
-    if self.builder.config.blockdiag_fontpath:
-        blockdiag_fontpath = self.builder.config.blockdiag_fontpath
+def get_fontmap(self):
+    try:
+        fontmappath = self.builder.config.blockdiag_fontmap
+        fontmap = FontMap(fontmappath)
+    except:
+        attrname = '_blockdiag_fontmap_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('blockdiag cannot load "%s" as fontmap file, '
+                   'check the blockdiag_fontmap setting' % fontmappath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-        if isinstance(blockdiag_fontpath, (str, unicode)):
-            blockdiag_fontpath = [blockdiag_fontpath]
+        fontmap = FontMap(None)
 
-        for path in blockdiag_fontpath:
-            if os.path.isfile(path):
-                fontpath = path
+    try:
+        fontpath = self.builder.config.blockdiag_fontpath
+        if isinstance(fontpath, (str, unicode)):
+            fontpath = [fontpath]
 
-        if fontpath is None:
-            attrname = '_blockdiag_fontpath_warned'
-            if not hasattr(self.builder, attrname):
-                msg = ('blockdiag cannot load "%s" as truetype font, '
-                       'check the blockdiag_path setting' % fontpath)
-                self.builder.warn(msg)
+        if fontpath:
+            config = namedtuple('Config', 'font')(fontpath)
+            _fontpath = command.detectfont(config)
+            fontmap.set_default_font(_fontpath)
+    except:
+        attrname = '_blockdiag_fontpath_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('blockdiag cannot load "%s" as truetype font, '
+                   'check the blockdiag_fontpath setting' % fontpath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-                setattr(self.builder, attrname, True)
-
-    return fontpath
+    return fontmap
 
 
 def create_blockdiag(self, code, format, filename, options, prefix='blockdiag'):
     Render blockdiag code into a PNG output file.
     """
     draw = None
-    fontpath = get_fontpath(self)
+    fontmap = get_fontmap(self)
     try:
         tree = diagparser.parse(diagparser.tokenize(code))
         screen = builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.blockdiag_antialias
-        draw = DiagramDraw.DiagramDraw(format, screen, filename, font=fontpath,
+        draw = DiagramDraw.DiagramDraw(format, screen, filename, fontmap=fontmap,
                                        antialias=antialias)
     except Exception, e:
         raise BlockdiagError('blockdiag error:\n%s\n' % e)
                  latex=(latex_visit_blockdiag, None))
     app.add_directive('blockdiag', Blockdiag)
     app.add_config_value('blockdiag_fontpath', None, 'html')
+    app.add_config_value('blockdiag_fontmap', None, 'html')
     app.add_config_value('blockdiag_antialias', False, 'html')
     app.add_config_value('blockdiag_html_image_format', 'PNG', 'html')
     app.add_config_value('blockdiag_tex_image_format', 'PNG', 'html')
 This module needs nwdiag_.
 '''
 
-requires = ['nwdiag>=0.6.0', 'Sphinx>=0.6']
+requires = ['nwdiag>=0.7.0', 'Sphinx>=0.6']
 
 setup(
     name='sphinxcontrib-nwdiag',
-    version='0.3.0',
+    version='0.3.1',
     url='http://bitbucket.org/birkenfeld/sphinx-contrib',
     download_url='http://pypi.python.org/pypi/sphinxcontrib-nwdiag',
     license='BSD',

nwdiag/sphinxcontrib/nwdiag.py

 from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
 from sphinx.util.compat import Directive
 
-from nwdiag_sphinxhelper import diagparser, builder, DiagramDraw, NwdiagDirective
-from nwdiag_sphinxhelper import nwdiag
+from nwdiag_sphinxhelper import command, diagparser, builder, DiagramDraw
+from nwdiag_sphinxhelper import collections, FontMap
+from nwdiag_sphinxhelper import nwdiag, NwdiagDirective
+namedtuple = collections.namedtuple
 
 
 class NwdiagError(SphinxError):
     return relfn, outfn
 
 
-def get_fontpath(self):
-    fontpath = None
-    if self.builder.config.nwdiag_fontpath:
-        nwdiag_fontpath = self.builder.config.nwdiag_fontpath
+def get_fontmap(self):
+    try:
+        fontmappath = self.builder.config.nwdiag_fontmap
+        fontmap = FontMap(fontmappath)
+    except:
+        attrname = '_nwdiag_fontmap_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('nwdiag cannot load "%s" as fontmap file, '
+                   'check the nwdiag_fontmap setting' % fontmappath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-        if isinstance(nwdiag_fontpath, (str, unicode)):
-            nwdiag_fontpath = [nwdiag_fontpath]
+        fontmap = FontMap(None)
 
-        for path in nwdiag_fontpath:
-            if os.path.isfile(path):
-                fontpath = path
+    try:
+        fontpath = self.builder.config.nwdiag_fontpath
+        if isinstance(fontpath, (str, unicode)):
+            fontpath = [fontpath]
 
-        if fontpath is None:
-            attrname = '_nwdiag_fontpath_warned'
-            if not hasattr(self.builder, attrname):
-                msg = ('nwdiag cannot load "%s" as truetype font, '
-                       'check the nwdiag_path setting' % fontpath)
-                self.builder.warn(msg)
+        if fontpath:
+            config = namedtuple('Config', 'font')(fontpath)
+            _fontpath = command.detectfont(config)
+            fontmap.set_default_font(_fontpath)
+    except:
+        attrname = '_nwdiag_fontpath_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('nwdiag cannot load "%s" as truetype font, '
+                   'check the nwdiag_fontpath setting' % fontpath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-                setattr(self.builder, attrname, True)
-
-    return fontpath
+    return fontmap
 
 
 def create_nwdiag(self, code, format, filename, options, prefix='nwdiag'):
     Render nwdiag code into a PNG output file.
     """
     draw = None
-    fontpath = get_fontpath(self)
+    fontmap = get_fontmap(self)
     try:
         tree = diagparser.parse(diagparser.tokenize(code))
         screen = builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.nwdiag_antialias
-        draw = DiagramDraw.DiagramDraw(format, screen, filename, font=fontpath,
+        draw = DiagramDraw.DiagramDraw(format, screen, filename, fontmap=fontmap,
                                        antialias=antialias)
     except Exception, e:
         raise NwdiagError('nwdiag error:\n%s\n' % e)
                  latex=(latex_visit_nwdiag, None))
     app.add_directive('nwdiag', Nwdiag)
     app.add_config_value('nwdiag_fontpath', None, 'html')
+    app.add_config_value('nwdiag_fontmap', None, 'html')
     app.add_config_value('nwdiag_antialias', False, 'html')
     app.add_config_value('nwdiag_html_image_format', 'PNG', 'html')
     app.add_config_value('nwdiag_tex_image_format', 'PNG', 'html')

nwdiag/sphinxcontrib/rackdiag.py

 from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
 from sphinx.util.compat import Directive
 
-from rackdiag_sphinxhelper import diagparser, builder, DiagramDraw, RackdiagDirective
-from rackdiag_sphinxhelper import rackdiag
+from rackdiag_sphinxhelper import command, diagparser, builder, DiagramDraw
+from rackdiag_sphinxhelper import collections, FontMap
+from rackdiag_sphinxhelper import rackdiag, RackdiagDirective
+namedtuple = collections.namedtuple
 
 
 class RackdiagError(SphinxError):
     return relfn, outfn
 
 
-def get_fontpath(self):
-    fontpath = None
-    if self.builder.config.rackdiag_fontpath:
-        rackdiag_fontpath = self.builder.config.rackdiag_fontpath
+def get_fontmap(self):
+    try:
+        fontmappath = self.builder.config.rackdiag_fontmap
+        fontmap = FontMap(fontmappath)
+    except:
+        attrname = '_rackdiag_fontmap_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('rackdiag cannot load "%s" as fontmap file, '
+                   'check the rackdiag_fontmap setting' % fontmappath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-        if isinstance(rackdiag_fontpath, (str, unicode)):
-            rackdiag_fontpath = [rackdiag_fontpath]
+        fontmap = FontMap(None)
 
-        for path in rackdiag_fontpath:
-            if os.path.isfile(path):
-                fontpath = path
+    try:
+        fontpath = self.builder.config.rackdiag_fontpath
+        if isinstance(fontpath, (str, unicode)):
+            fontpath = [fontpath]
 
-        if fontpath is None:
-            attrname = '_rackdiag_fontpath_warned'
-            if not hasattr(self.builder, attrname):
-                msg = ('rackdiag cannot load "%s" as truetype font, '
-                       'check the rackdiag_path setting' % fontpath)
-                self.builder.warn(msg)
+        if fontpath:
+            config = namedtuple('Config', 'font')(fontpath)
+            _fontpath = command.detectfont(config)
+            fontmap.set_default_font(_fontpath)
+    except:
+        attrname = '_rackdiag_fontpath_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('rackdiag cannot load "%s" as truetype font, '
+                   'check the rackdiag_fontpath setting' % fontpath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-                setattr(self.builder, attrname, True)
-
-    return fontpath
+    return fontmap
 
 
 def create_rackdiag(self, code, format, filename, options, prefix='rackdiag'):
     Render rackdiag code into a PNG output file.
     """
     draw = None
-    fontpath = get_fontpath(self)
+    fontmap = get_fontmap(self)
     try:
         tree = diagparser.parse(diagparser.tokenize(code))
         screen = builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.rackdiag_antialias
-        draw = DiagramDraw.DiagramDraw(format, screen, filename, font=fontpath,
+        draw = DiagramDraw.DiagramDraw(format, screen, filename, fontmap=fontmap,
                                        antialias=antialias)
     except Exception, e:
         raise RackdiagError('rackdiag error:\n%s\n' % e)
                  latex=(latex_visit_rackdiag, None))
     app.add_directive('rackdiag', Rackdiag)
     app.add_config_value('rackdiag_fontpath', None, 'html')
+    app.add_config_value('rackdiag_fontmap', None, 'html')
     app.add_config_value('rackdiag_antialias', False, 'html')
     app.add_config_value('rackdiag_html_image_format', 'PNG', 'html')
     app.add_config_value('rackdiag_tex_image_format', 'PNG', 'html')
 This module needs seqdiag_.
 '''
 
-requires = ['blockdiag>=1.0.1', 'seqdiag>=0.6.3', 'Sphinx>=0.6']
+requires = ['seqdiag>=0.7.0', 'Sphinx>=0.6']
 
 setup(
     name='sphinxcontrib-seqdiag',

seqdiag/sphinxcontrib/seqdiag.py

 from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
 from sphinx.util.compat import Directive
 
-from seqdiag_sphinxhelper import diagparser, builder, DiagramDraw, SeqdiagDirective
-from seqdiag_sphinxhelper import seqdiag
+from seqdiag_sphinxhelper import command, diagparser, builder, DiagramDraw
+from seqdiag_sphinxhelper import collections, FontMap
+from seqdiag_sphinxhelper import seqdiag, SeqdiagDirective
+namedtuple = collections.namedtuple
 
 
 class SeqdiagError(SphinxError):
     return relfn, outfn
 
 
-def get_fontpath(self):
-    fontpath = None
-    if self.builder.config.seqdiag_fontpath:
-        seqdiag_fontpath = self.builder.config.seqdiag_fontpath
+def get_fontmap(self):
+    try:
+        fontmappath = self.builder.config.seqdiag_fontmap
+        fontmap = FontMap(fontmappath)
+    except:
+        attrname = '_seqdiag_fontmap_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('seqdiag cannot load "%s" as fontmap file, '
+                   'check the seqdiag_fontmap setting' % fontmappath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-        if isinstance(seqdiag_fontpath, (str, unicode)):
-            seqdiag_fontpath = [seqdiag_fontpath]
+        fontmap = FontMap(None)
 
-        for path in seqdiag_fontpath:
-            if os.path.isfile(path):
-                fontpath = path
+    try:
+        fontpath = self.builder.config.seqdiag_fontpath
+        if isinstance(fontpath, (str, unicode)):
+            fontpath = [fontpath]
 
-        if fontpath is None:
-            attrname = '_seqdiag_fontpath_warned'
-            if not hasattr(self.builder, attrname):
-                msg = ('seqdiag cannot load "%s" as truetype font, '
-                       'check the seqdiag_path setting' % fontpath)
-                self.builder.warn(msg)
+        if fontpath:
+            config = namedtuple('Config', 'font')(fontpath)
+            _fontpath = command.detectfont(config)
+            fontmap.set_default_font(_fontpath)
+    except:
+        attrname = '_seqdiag_fontpath_warned'
+        if not hasattr(self.builder, attrname):
+            msg = ('seqdiag cannot load "%s" as truetype font, '
+                   'check the seqdiag_fontpath setting' % fontpath)
+            self.builder.warn(msg)
+            setattr(self.builder, attrname, True)
 
-                setattr(self.builder, attrname, True)
-
-    return fontpath
+    return fontmap
 
 
 def create_seqdiag(self, code, format, filename, options, prefix='seqdiag'):
     Render seqdiag code into a PNG output file.
     """
     draw = None
-    fontpath = get_fontpath(self)
+    fontmap = get_fontmap(self)
     try:
         tree = diagparser.parse(diagparser.tokenize(code))
         screen = builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.seqdiag_antialias
-        draw = DiagramDraw.DiagramDraw(format, screen, filename, font=fontpath,
+        draw = DiagramDraw.DiagramDraw(format, screen, filename, fontmap=fontmap,
                                        antialias=antialias)
     except Exception, e:
         raise SeqdiagError('seqdiag error:\n%s\n' % e)
                  latex=(latex_visit_seqdiag, None))
     app.add_directive('seqdiag', Seqdiag)
     app.add_config_value('seqdiag_fontpath', None, 'html')
+    app.add_config_value('seqdiag_fontmap', None, 'html')
     app.add_config_value('seqdiag_antialias', False, 'html')
     app.add_config_value('seqdiag_html_image_format', 'PNG', 'html')
     app.add_config_value('seqdiag_tex_image_format', 'PNG', 'html')