예제 #1
0
 def test_ascii(self):
     """Validate all ascii printable."""
     f = ft.Font()
     factory = f.new_font_object()
     self._check_font(factory)
     for fonts in f.get_names():
         self._check_font(f.new_font_by_name(fonts))
예제 #2
0
 def __init__(self, **options):
     """Initialize the instance."""
     Formatter.__init__(self, **options)
     self._colors = {}
     self._default_color = hu.HEX_WHITE
     self.symbol_generator = sym.DefaultSymbolGenerator()
     self.font_factory = ft.Font().new_font_object()
     self.colorize = False
     self.dark = False
     self._lines = hu.LIGHT_GREY
     self._symbols = hu.BLACK
     self._light_symbol = hu.LIGHT_GREY
     self.file_name = None
     self.is_raw = False
     self._writer = None
     self.is_multipage = None
     self.config = None
     self.config_file = None
     self.is_bw = False
     self.vzoom = None
     self.hzoom = None
     self.floss = Floss()
     for token, style in self.style:
         if style['color']:
             self._colors[token] = style['color']
예제 #3
0
 def test_by_type(self):
     """Passing a tyep into construction."""
     f = ft.Font()
     f.new_font_object()
     f.new_font_object(fbn.FiveByNineMono)
     with self.assertRaises(ft.FontException) as cm:
         f.new_font_object(str)
     self.assertEqual("unknown font type: <class 'str'>", str(cm.exception))
     with self.assertRaises(ft.FontException) as cm:
         f.new_font_by_name("test")
     self.assertEqual("unknown font name: test", str(cm.exception))
예제 #4
0
 def test_display(self):
     """Test display names."""
     f = ft.Font()
     factory = f.new_font_object()
     self._check_font(factory)
     for fonts in f.get_names():
         fnt = f.new_font_by_name(fonts)
         hw = fnt._height_width()
         if "monospace" in fnt.display_name:
             typed = "monospace"
         else:
             typed = "proportional"
         disp_name = "{}-ascii-{}x{}".format(typed, hw[1], hw[0])
         self.assertEqual(disp_name, fnt.display_name)
예제 #5
0
 def test_detect(self):
     """Detection on dimensions."""
     f = ft.Font()
     with self.assertRaises(ft.FontException) as cm:
         f.new_font_by_name("detect")
     self.assertEqual("requires dimensions (rows, cols)", str(cm.exception))
     with self.assertRaises(ft.FontException) as cm:
         f.new_font_by_name("detect", rows=100)
     self.assertEqual("requires dimensions (rows, cols)", str(cm.exception))
     with self.assertRaises(ft.FontException) as cm:
         f.new_font_by_name("detect", columns=100)
     self.assertEqual("requires dimensions (rows, cols)", str(cm.exception))
     dt = f.new_font_by_name("detect", rows=32, columns=30)
     self.assertEqual("TwoByFiveMono", str(type(dt).__name__))
     dt = f.new_font_by_name("detect", rows=25, columns=45)
     self.assertEqual("ThreeBySevenMono", str(type(dt).__name__))
     dt = f.new_font_by_name("detect", rows=30, columns=25)
     self.assertEqual("ThreeByFiveMono", str(type(dt).__name__))
     dt = f.new_font_by_name("detect", rows=9, columns=24)
     self.assertEqual("FiveByNineMono", str(type(dt).__name__))
예제 #6
0
def new_formatter(style,
                  file_name,
                  multipage,
                  colorize=False,
                  dark=False,
                  is_raw=False,
                  is_bw=False,
                  map_colors=None,
                  config=None,
                  font=None,
                  font_name=None,
                  rows=None,
                  columns=None,
                  symbols=None,
                  config_file=None,
                  horizontal=None,
                  vertical=None):
    """Create a new formatter."""
    formatting = CrossStitchFormatter(style=style)
    formatting.colorize = colorize
    formatting.dark = dark
    formatting.file_name = file_name
    formatting.is_multipage = multipage
    formatting.is_raw = is_raw
    formatting.is_bw = is_bw
    formatting.hzoom = horizontal
    formatting.vzoom = vertical
    if map_colors is not None and len(map_colors) > 0:
        for mapped in map_colors:
            if not formatting.map_color(mapped):
                raise FormatterException("unable to map: {}".format(mapped))
    if config is not None and len(config) > 0:
        formatting.config = config
    formatting.config_file = config_file
    if font_name is not None:
        formatting.font_factory = ft.Font().new_font_by_name(font_name,
                                                             rows=rows,
                                                             columns=columns)
    if symbols is not None:
        formatting.symbol_generator = sym.InputStringGenerator(symbols)
    return formatting
예제 #7
0
def main(in_args=None):
    """Main-entry point."""
    if not vers.python_version_supported():
        log.Log.write("python version is not supported")
        exit(1)
    default_font = fnt.Font().detect
    parser = argparse.ArgumentParser(
        description='Convert source code files to cross stitch patterns.')
    parser.add_argument('--file',
                        help="""input source code file to create a
pattern from.""",
                        type=str,
                        default=_TXT)
    parser.add_argument('--lexer',
                        help="""the source code lexer to use when
reading input and converting input tokens into colors""",
                        type=str)
    parser.add_argument('--output', help="""output name""", type=str)
    parser.add_argument(
        '--theme',
        help="""pattern theme. indicates the background and
symbol color outputs for the output pattern""",
        type=str,
        default=_LIGHT,
        choices=[_B_AND_W, _DARK, _DARK_DMC, _LIGHT, _LIGHT_DMC])
    parser.add_argument('--kv',
                        metavar='N',
                        help="""key/value configuration
parameters for setting the output format""",
                        type=str,
                        nargs='+')
    parser.add_argument('--map',
                        help="""when selecting colors will map one
token color to another color (override)""",
                        metavar='N',
                        type=str,
                        nargs='+')
    parser.add_argument('--config', help="""configuration file""", type=str)
    parser.add_argument('--multipage',
                        help="""enable multipage output""",
                        type=str,
                        default=out_fmt.MULTI_PAGE_AUTO,
                        choices=[
                            out_fmt.MULTI_PAGE_AUTO, out_fmt.MULTI_PAGE_OFF,
                            out_fmt.MULTI_PAGE_ON
                        ])
    parser.add_argument('--format',
                        help="""output file format""",
                        type=str,
                        default=_PNG,
                        choices=["jpg", _PDF, _PNG, _RAW])
    parser.add_argument('--style',
                        help="""token color styling (from pygments)""",
                        default=_DEF_STYLE,
                        choices=list(sorted(get_all_styles())))
    font_choices = list(sorted(list(fnt.get_all_fonts()) + [default_font]))
    parser.add_argument('--font',
                        help="""font to use for the pattern""",
                        default=default_font,
                        choices=font_choices)
    parser.add_argument('--version',
                        action="store_true",
                        help="""display version""")
    parser.add_argument('--quiet',
                        action="store_true",
                        help="""less verbose output""")
    parser.add_argument('--symbols',
                        type=str,
                        help="""symbol set for stitching symbols""")
    parser.add_argument('--hszoom',
                        type=int,
                        default=0,
                        help="horizontal start zoom")
    parser.add_argument('--hezoom',
                        type=int,
                        default=0,
                        help="horizontal end zoom")
    parser.add_argument('--vszoom',
                        type=int,
                        default=0,
                        help="vertical start zoom")
    parser.add_argument('--vezoom',
                        type=int,
                        default=0,
                        help="vertical end zoom")
    args = parser.parse_args(args=in_args)
    if args.version:
        if not args.quiet:
            log.Log.writeln()
            _print_banner()
        log.Log.write(vers.__version__)
        if not args.quiet:
            log.Log.writeln()
        return
    if args.quiet:
        log.Log.is_verbose = False
    inputs = InputArgs(args)
    if inputs.invalid:
        exit(1)
    _run(inputs, default_font)
예제 #8
0
 def test_width(self):
     """Get width."""
     factory = ft.Font().new_font_object()
     self.assertEqual(4, max(factory.width()))
예제 #9
0
 def test_height(self):
     """Get height."""
     factory = ft.Font().new_font_object()
     self.assertEqual(10, max(factory.height()))
예제 #10
0
 def test_get_error(self):
     """Get non-character."""
     factory = ft.Font().new_font_object()
     with self.assertRaises(ft.FontException) as cm:
         factory.get(None)
     self.assertEqual("No font entry for character None", str(cm.exception))