Skip to content

Commit 833a294

Browse files
committed
Allow custom font names
"Arial" only works on windows
1 parent 989e246 commit 833a294

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

splitspy/graph/draw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def draw(outfile: str, graph: Graph, label_angles: [float] = None, fit: float = -1.0,
2121
width: int = 1000, height: int = 1000,
2222
m_left: int = 150, m_right: int = 150, m_top: int = 150, m_bot: int = 150,
23-
font_size: int = 12, scale_factor: int =5) -> None:
23+
font_name: str = "Arial", font_size: int = 12, scale_factor: int =5) -> None:
2424

2525
width *= scale_factor
2626
height *= scale_factor
@@ -53,7 +53,7 @@ def draw(outfile: str, graph: Graph, label_angles: [float] = None, fit: float =
5353

5454
im_draw = ImageDraw.Draw(im)
5555

56-
font = ImageFont.truetype("Arial",size=font_size)
56+
font = ImageFont.truetype(font_name, size=font_size)
5757
black = (0, 0, 0)
5858

5959
if fit != -1:

splitspy/outline.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def main():
5757
--m_right=MARGIN right margin
5858
--m_top=MARGIN top margin
5959
--m_bot=MARGIN bottom margin
60+
--font_name=F_NAME font name or path
6061
--font_size=F_SIZE font size
6162
6263
Input format:
@@ -123,6 +124,8 @@ def main():
123124
metavar="MARGIN")
124125
win_opts.add_option("--m_bot", default=100, action="store", dest="m_bot", help="bottom margin", type="int",
125126
metavar="MARGIN")
127+
win_opts.add_option("--font_name", default="Arial", action="store", dest="font_name", help="font size", type="str",
128+
metavar="FONTNAME")
126129
win_opts.add_option("--font_size", default=12, action="store", dest="font_size", help="font size", type="int",
127130
metavar="SIZE")
128131

@@ -155,13 +158,13 @@ def main():
155158
run(labels, matrix, outfile=options.outfile, nexus_file=options.nexus_file, graph_file=options.graph_file,
156159
mode=options.mode, cutoff=options.cutoff, rooted=options.rooted, alt=options.alt, out_grp=out_grp,
157160
win_width=options.win_width,win_height=options.win_height, m_left=options.m_left, m_right=options.m_right,
158-
m_top=options.m_top, m_bot=options.m_bot,font_size=options.font_size)
161+
m_top=options.m_top, m_bot=options.m_bot, font_name=options.font_name, font_size=options.font_size)
159162

160163

161164
def run(labels: [str], matrix: [[float]], outfile: str = "", nexus_file: str = "", graph_file: str = "",
162165
mode: str = "CLS", cutoff: float = 0.0,
163166
rooted: bool = False, alt: bool = False, out_grp: Set[int] = None, win_width: int = 1000, win_height: int = 800,
164-
m_left: int = 100, m_right: int = 100, m_top: int = 100, m_bot: int = 100, font_size: int = 12) -> None:
167+
m_left: int = 100, m_right: int = 100, m_top: int = 100, m_bot: int = 100, font_name: str = "Arial", font_size: int = 12) -> None:
165168

166169

167170
# distances.write(labels, matrix, outfile)
@@ -178,7 +181,7 @@ def run(labels: [str], matrix: [[float]], outfile: str = "", nexus_file: str = "
178181
if graph_file != "":
179182
graph.write_tgf(outfile=graph_file)
180183

181-
draw.draw(outfile, graph, angles, fit, win_width, win_height,m_left, m_right, m_top, m_bot, font_size)
184+
draw.draw(outfile, graph, angles, fit, win_width, win_height, m_left, m_right, m_top, m_bot, font_name, font_size)
182185

183186

184187
if __name__ == '__main__':

0 commit comments

Comments
 (0)