Skip to content

Commit

Permalink
Emoji support via --font=NotoEmoji-Regular
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jul 4, 2016
1 parent 468e873 commit 8b37a99
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ include MANIFEST.in
include ez_setup.py
include fabulous/_xterm256.c
include fabulous/fonts/LICENSE
include fabulous/fonts/NotoEmoji-Regular.ttf
include fabulous/fonts/NotoSans-Bold.ttf
Binary file added fabulous/fonts/NotoEmoji-Regular.ttf
Binary file not shown.
27 changes: 17 additions & 10 deletions fabulous/text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2016 The Fabulous Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,9 +32,11 @@
from fabulous import text
print text.Text("Fabulous!", color='#0099ff', shadow=True, scew=5)
To make things simple, Fabulous bundles the ``NotoSans-Bold`` bold font
which was created by Google. This font looks good and is guaranteed to
work no matter what.
To make things simple, Fabulous bundles the following Google Noto Fonts
which look good and are guaranteed to work no matter what:
- NotoSans-Bold
- NotoEmoji-Regular
For other fonts, Fabulous will do its best to figure out where they are
stored. If Fabulous has trouble finding your font, try using an absolute
Expand All @@ -50,7 +54,7 @@


class Text(image.Image):
"""Renders TrueType Text to Terminal
u"""Renders TrueType Text to Terminal
I'm a sub-class of :class:`fabulous.image.Image`. My job is
limited to simply getting things ready. I do this by:
Expand All @@ -67,6 +71,9 @@ class Text(image.Image):
>>> txt = Text("lorem ipsum", font="NotoSans-Bold")
>>> len(str(txt)) > 0
True
>>> txt = Text(u"😃", font="NotoSans-Bold")
>>> len(str(txt)) > 0
True
:param text: The text you want to display as a string.
Expand Down Expand Up @@ -170,9 +177,9 @@ def get_font_files():
For example::
>>> fonts = get_font_files()
>>> 'DejaVuSansMono' in fonts
>>> 'NotoSans-Bold' in fonts
True
>>> fonts['DejaVuSansMono'].endswith('/DejaVuSansMono.ttf')
>>> fonts['NotoSans-Bold'].endswith('/NotoSans-Bold.ttf')
True
"""
Expand Down Expand Up @@ -215,9 +222,9 @@ def main():
parser.add_option(
"-F", "--font", dest="font", default='NotoSans-Bold',
help=("Name of font file, or absolute path to one. Use the --list "
"flag to see what fonts are available. The default font is "
"bundled with Fabulous and guaranteed to work. "
"Default: %default"))
"flag to see what fonts are available. Fabulous bundles the "
"NotoSans-Bold and NotoEmoji-Regular fonts, which are guaranteed "
"to work. Default: %default"))
parser.add_option(
"-Z", "--size", dest="fsize", type="int", default=23,
help=("Size of font in points. Default: %default"))
Expand All @@ -230,7 +237,7 @@ def main():
return
if options.term_color:
utils.term.bgcolor = options.term_color
for line in " ".join(args).split("\n"):
for line in " ".join(args).decode('utf-8').split("\n"):
fab_text = Text(line, skew=options.skew, color=options.color,
font=options.font, fsize=options.fsize,
shadow=options.shadow)
Expand Down

0 comments on commit 8b37a99

Please sign in to comment.