Skip to content

Commit d1dcf74

Browse files
committed
Implement text methods
1 parent 6918047 commit d1dcf74

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

examples/introduction.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@
107107
"c"
108108
]
109109
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"c.fill_text('Hello World!!', 50, 50, 50)"
117+
]
118+
},
110119
{
111120
"cell_type": "code",
112121
"execution_count": null,

examples/numpy_heatmap.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
"metadata": {},
1717
"outputs": [],
1818
"source": [
19-
"# make these smaller to increase the resolution\n",
2019
"dx, dy = 0.05, 0.05\n",
2120
"\n",
22-
"# generate 2 2d grids for the x & y bounds\n",
2321
"y, x = np.mgrid[slice(1, 5 + dy, dy),\n",
2422
" slice(1, 5 + dx, dx)]\n",
2523
"\n",

ipycanvas/canvas.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Canvas(DOMWidget):
3131
stroke_style = Color('black')
3232
global_alpha = Float(1.0)
3333

34+
font = Unicode('12px serif')
35+
3436
def __init__(self, *args, **kwargs):
3537
self.caching = kwargs.get('caching', False)
3638
self._commands_cache = []
@@ -87,6 +89,15 @@ def quadratic_curve_to(self, cp1x, cp1y, x, y):
8789
def bezier_curve_to(self, cp1x, cp1y, cp2x, cp2y, x, y):
8890
self._send_canvas_command('bezierCurveTo', cp1x, cp1y, cp2x, cp2y, x, y)
8991

92+
# Text methods
93+
def fill_text(self, text, x, y, maxWidth=None):
94+
"""Fill a given text at the given (x,y) position. Optionally with a maximum width to draw."""
95+
self._send_canvas_command('fillText', text, x, y, maxWidth)
96+
97+
def stroke_text(self, text, x, y, maxWidth=None):
98+
"""Stroke a given text at the given (x,y) position. Optionally with a maximum width to draw."""
99+
self._send_canvas_command('strokeText', text, x, y, maxWidth)
100+
90101
def clear(self):
91102
"""Clear the entire canvas."""
92103
self._commands_cache = []

0 commit comments

Comments
 (0)