コード例 #1
0
    def test_fontinfo_new(self):
        FontInfo("serif", None, 11)
        FontInfo("sansserif", None, 11)
        FontInfo("monospace", None, 11)
        FontInfo("cursive", None, 11)
        FontInfo("fantasy", None, 11)

        FontInfo("serif-bold", None, 11)
        FontInfo("sansserif-italic", None, 11)
        FontInfo("monospace-oblique", None, 11)
        FontInfo("my-cursive", None, 11)
        FontInfo("-fantasy", None, 11)
コード例 #2
0
ファイル: metrics.py プロジェクト: xillmera/outwiker
    def _scale(cls, value, ratio):
        if ratio == 1:
            return value

        klass = value.__class__
        if klass == XY:
            ret = XY(value.x * ratio, value.y * ratio)
        elif klass == Size:
            ret = Size(value.width * ratio, value.height * ratio)
        elif klass == Box:
            ret = Box(value[0] * ratio, value[1] * ratio,
                      value[2] * ratio, value[3] * ratio)
        elif klass == tuple:
            ret = tuple([cls.scale(x, ratio) for x in value])
        elif klass == list:
            ret = [cls.scale(x, ratio) for x in value]
        elif klass == EdgeLines:
            ret = EdgeLines()
            ret.polylines = cls.scale(value.polylines, ratio)
        elif klass == FontInfo:
            ret = FontInfo(value.familyname, value.path, value.size * ratio)
        elif klass == int:
            ret = value * ratio
        elif klass == str:
            ret = value
        else:
            ret = cls(value, ratio)

        return ret
コード例 #3
0
    def test_test_textsize(self):
        from blockdiag.utils.fontmap import FontInfo
        font = FontInfo('serif', None, 11)

        # abc
        self.assertEqual((19, 11), textsize("abc", font))
        # あいう
        self.assertEqual((33, 11), textsize("\u3042\u3044\u3046", font))
        # あいc
        self.assertEqual((29, 11), textsize("\u3042\u3044c", font))

        # abc
        font = FontInfo('serif', None, 24)
        self.assertEqual((40, 24), textsize("abc", font))

        # あいう
        font = FontInfo('serif', None, 18)
        self.assertEqual((54, 18), textsize("\u3042\u3044\u3046", font))
コード例 #4
0
    def test_fontinfo_familyname(self):
        font = FontInfo("serif", None, 11)
        self.assertEqual('serif-normal', font.familyname)

        font = FontInfo("sansserif-bold", None, 11)
        self.assertEqual('sansserif-bold', font.familyname)

        font = FontInfo("monospace-italic", None, 11)
        self.assertEqual('monospace-italic', font.familyname)

        font = FontInfo("my-cursive-oblique", None, 11)
        self.assertEqual('my-cursive-oblique', font.familyname)

        font = FontInfo("my-fantasy-bold", None, 11)
        self.assertEqual('my-fantasy-bold', font.familyname)

        font = FontInfo("serif-serif", None, 11)
        self.assertEqual('serif-serif-normal', font.familyname)

        font = FontInfo("-serif", None, 11)
        self.assertEqual('serif-normal', font.familyname)
コード例 #5
0
    def test_fontinfo_parse(self):
        font = FontInfo("serif", None, 11)
        self.assertEqual('', font.name)
        self.assertEqual('serif', font.generic_family)
        self.assertEqual('normal', font.weight)
        self.assertEqual('normal', font.style)

        font = FontInfo("sansserif-bold", None, 11)
        self.assertEqual('', font.name)
        self.assertEqual('sans-serif', font.generic_family)
        self.assertEqual('bold', font.weight)
        self.assertEqual('normal', font.style)

        font = FontInfo("monospace-italic", None, 11)
        self.assertEqual('', font.name)
        self.assertEqual('monospace', font.generic_family)
        self.assertEqual('normal', font.weight)
        self.assertEqual('italic', font.style)

        font = FontInfo("my-cursive-oblique", None, 11)
        self.assertEqual('my', font.name)
        self.assertEqual('cursive', font.generic_family)
        self.assertEqual('normal', font.weight)
        self.assertEqual('oblique', font.style)

        font = FontInfo("my-fantasy-bold", None, 11)
        self.assertEqual('my', font.name)
        self.assertEqual('fantasy', font.generic_family)
        self.assertEqual('bold', font.weight)
        self.assertEqual('normal', font.style)

        font = FontInfo("serif-serif", None, 11)
        self.assertEqual('serif', font.name)
        self.assertEqual('serif', font.generic_family)
        self.assertEqual('normal', font.weight)
        self.assertEqual('normal', font.style)
コード例 #6
0
     def test_fontinfo_parse(self):
         font = FontInfo("serif", None, 11)
@@ -212,15 +212,17 @@ class TestUtilsFontmap(unittest2.TestCas
コード例 #7
0
     def test_fontinfo_invalid_fontsize2(self):
-        with self.assertRaises(ValueError):
-            FontInfo("serif", None, '')
+        FontInfo("serif", None, '')
コード例 #8
0
     def test_fontinfo_invalid_fontsize1(self):
-        with self.assertRaises(TypeError):
-            FontInfo("serif", None, None)
+        FontInfo("serif", None, None)
コード例 #9
0
     def test_fontinfo_invalid_familyname4(self):
-        with self.assertRaises(AttributeError):
-            FontInfo("SERIF", None, 11)
+        FontInfo("SERIF", None, 11)
コード例 #10
0
     def test_fontinfo_invalid_familyname3(self):
-        with self.assertRaises(AttributeError):
-            FontInfo("monospace-unkown", None, 11)
+        FontInfo("monospace-unkown", None, 11)
コード例 #11
0
* Fix testcase using 'with' statement are failed in python2.5 environment
  https://bitbucket.org/tk0miya/blockdiag/changeset/f078235db9b9

--- src/blockdiag/tests/test_utils_fontmap.py.orig	2011-11-21 02:38:58.000000000 +0000
+++ src/blockdiag/tests/test_utils_fontmap.py
@@ -3,7 +3,7 @@
 import os
 import sys
 import unittest2
-from utils import stderr_wrapper
+from utils import stderr_wrapper, assertRaises
 from cStringIO import StringIO
 from blockdiag.utils.collections import namedtuple
 from blockdiag.utils.fontmap import FontInfo, FontMap
@@ -31,33 +31,33 @@ class TestUtilsFontmap(unittest2.TestCas
         FontInfo("my-cursive", None, 11)
         FontInfo("-fantasy", None, 11)
 
+    @assertRaises(AttributeError)
     def test_fontinfo_invalid_familyname1(self):
-        with self.assertRaises(AttributeError):
-            FontInfo("unknown", None, 11)
+        FontInfo("unknown", None, 11)
 
+    @assertRaises(AttributeError)
     def test_fontinfo_invalid_familyname2(self):
-        with self.assertRaises(AttributeError):
-            FontInfo("sansserif-", None, 11)
+        FontInfo("sansserif-", None, 11)
 
+    @assertRaises(AttributeError)
コード例 #12
0
 def test_fontinfo_invalid_familyname4(self):
     with self.assertRaises(AttributeError):
         FontInfo("cursive-bold-bold", None, 11)
コード例 #13
0
 def test_fontinfo_invalid_familyname2(self):
     with self.assertRaises(AttributeError):
         FontInfo("sansserif-", None, 11)
コード例 #14
0
 def test_fontinfo_invalid_familyname1(self):
     with self.assertRaises(AttributeError):
         FontInfo("unknown", None, 11)