Skip to content

Commit b86c2e5

Browse files
committed
release 0.4a1
1 parent 2267817 commit b86c2e5

28 files changed

+10203
-8661
lines changed

py5/__init__.py

Lines changed: 2000 additions & 1799 deletions
Large diffs are not rendered by default.

py5/create_font_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def create_font_file(
111111
set the ``pause`` parameter to ``False``.
112112
113113
Get a list of font names available on your computer with Py5Font's
114-
:doc:`py5font_list` method. If you request an unavailable font, it will create
114+
``Py5Font.list()`` method. If you request an unavailable font, it will create
115115
the data file anyway but using a default font."""
116116
vlw_creator = CreateFontTool(font_name, font_size,
117117
filename=filename, characters=characters,

py5/font.py

Lines changed: 75 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from jpype import JException, JArray, JString # noqa
2525

2626
from .shape import Py5Shape, _return_py5shape # noqa
27+
from .type_decorators import _ret_str # noqa
2728

2829

2930
def _return_py5font(f):
@@ -68,16 +69,16 @@ class Py5Font:
6869
-----
6970
7071
Py5Font is the font class for py5. To create a font to use with py5, use
71-
:doc:`create_font_file`. This will create a font in the format py5 requires. Py5
72+
``create_font_file()``. This will create a font in the format py5 requires. Py5
7273
displays fonts using the .vlw font format, which uses images for each letter,
73-
rather than defining them through vector data. The :doc:`load_font` function
74-
constructs a new font and :doc:`text_font` makes a font active. The
75-
:doc:`py5font_list` method creates a list of the fonts installed on the
76-
computer, which is useful information to use with the :doc:`create_font`
77-
function for dynamically converting fonts into a format to use with py5.
78-
79-
To create a new font dynamically, use the :doc:`create_font` function. Do not
80-
use the syntax ``Py5Font()``.
74+
rather than defining them through vector data. The ``load_font()`` function
75+
constructs a new font and ``text_font()`` makes a font active. The
76+
``Py5Font.list()`` method creates a list of the fonts installed on the computer,
77+
which is useful information to use with the ``create_font()`` function for
78+
dynamically converting fonts into a format to use with py5.
79+
80+
To create a new font dynamically, use the ``create_font()`` function. Do not use
81+
the syntax ``Py5Font()``.
8182
"""
8283

8384
_cls = jpype.JClass('processing.core.PFont')
@@ -87,92 +88,90 @@ def __init__(self, pfont):
8788
self._instance = pfont
8889

8990
def ascent(self) -> float:
90-
"""The documentation for this field or method has not yet been written.
91+
"""Get the ascent of this font from the baseline.
9192
9293
Underlying Java method: PFont.ascent
9394
9495
Notes
9596
-----
9697
97-
The documentation for this field or method has not yet been written. If you know
98-
what it does, please help out with a pull request to the relevant file in
99-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
98+
Get the ascent of this font from the baseline. The value is based on a font of
99+
size 1. Multiply it by the font size to get the offset from the baseline.
100100
"""
101101
return self._instance.ascent()
102102

103103
def descent(self) -> float:
104-
"""The documentation for this field or method has not yet been written.
104+
"""Get the descent of this font from the baseline.
105105
106106
Underlying Java method: PFont.descent
107107
108108
Notes
109109
-----
110110
111-
The documentation for this field or method has not yet been written. If you know
112-
what it does, please help out with a pull request to the relevant file in
113-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
111+
Get the descent of this font from the baseline. The value is based on a font of
112+
size 1. Multiply it by the font size to get the offset from the baseline.
114113
"""
115114
return self._instance.descent()
116115

117116
def get_default_size(self) -> int:
118-
"""The documentation for this field or method has not yet been written.
117+
"""Get the font's size that will be used when ``text_font()`` is called.
119118
120119
Underlying Java method: PFont.getDefaultSize
121120
122121
Notes
123122
-----
124123
125-
The documentation for this field or method has not yet been written. If you know
126-
what it does, please help out with a pull request to the relevant file in
127-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
124+
Get the font's size that will be used when ``text_font()`` is called. When
125+
drawing with 2x pixel density, bitmap fonts in OpenGL need to be created at
126+
double the requested size. This ensures that they're shown at half on displays
127+
(so folks don't have to change their sketch code).
128128
"""
129129
return self._instance.getDefaultSize()
130130

131131
def get_glyph_count(self) -> int:
132-
"""The documentation for this field or method has not yet been written.
132+
"""Get the number of glyphs contained in the font.
133133
134134
Underlying Java method: PFont.getGlyphCount
135135
136136
Notes
137137
-----
138138
139-
The documentation for this field or method has not yet been written. If you know
140-
what it does, please help out with a pull request to the relevant file in
141-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
139+
Get the number of glyphs contained in the font. This will be 0 if the font is a
140+
"lazy font" that creates glyphs as they are needed by the Sketch. This will be
141+
the case if the font was created with ``create_font()`` without using the
142+
``charset`` parameter.
142143
"""
143144
return self._instance.getGlyphCount()
144145

146+
@_ret_str
145147
def get_name(self) -> str:
146-
"""The documentation for this field or method has not yet been written.
148+
"""Get the font's name.
147149
148150
Underlying Java method: PFont.getName
149151
150152
Notes
151153
-----
152154
153-
The documentation for this field or method has not yet been written. If you know
154-
what it does, please help out with a pull request to the relevant file in
155-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
155+
Get the font's name.
156156
"""
157157
return self._instance.getName()
158158

159+
@_ret_str
159160
def get_post_script_name(self) -> str:
160-
"""The documentation for this field or method has not yet been written.
161+
"""Get the font's postscript name.
161162
162163
Underlying Java method: PFont.getPostScriptName
163164
164165
Notes
165166
-----
166167
167-
The documentation for this field or method has not yet been written. If you know
168-
what it does, please help out with a pull request to the relevant file in
169-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
168+
Get the font's postscript name.
170169
"""
171170
return self._instance.getPostScriptName()
172171

173172
@overload
174173
def get_shape(self, ch: chr, /) -> Py5Shape:
175-
"""The documentation for this field or method has not yet been written.
174+
"""Get a single character as a ``Py5Shape`` object.
176175
177176
Underlying Java method: PFont.getShape
178177
@@ -188,23 +187,27 @@ def get_shape(self, ch: chr, /) -> Py5Shape:
188187
----------
189188
190189
ch: chr
191-
missing variable description
190+
single character
192191
193192
detail: float
194-
missing variable description
193+
level of shape detail
195194
196195
Notes
197196
-----
198197
199-
The documentation for this field or method has not yet been written. If you know
200-
what it does, please help out with a pull request to the relevant file in
201-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
198+
Get a single character as a ``Py5Shape`` object. Use the ``detail`` parameter to
199+
draw the shape with only straight line segments.
200+
201+
Calling ``Py5Shape.disable_style()`` on the returned ``Py5Shape`` object seems
202+
to be necessary for these to be drawable.
203+
204+
This method only works on fonts loaded with ``create_font()``.
202205
"""
203206
pass
204207

205208
@overload
206209
def get_shape(self, ch: chr, detail: float, /) -> Py5Shape:
207-
"""The documentation for this field or method has not yet been written.
210+
"""Get a single character as a ``Py5Shape`` object.
208211
209212
Underlying Java method: PFont.getShape
210213
@@ -220,23 +223,27 @@ def get_shape(self, ch: chr, detail: float, /) -> Py5Shape:
220223
----------
221224
222225
ch: chr
223-
missing variable description
226+
single character
224227
225228
detail: float
226-
missing variable description
229+
level of shape detail
227230
228231
Notes
229232
-----
230233
231-
The documentation for this field or method has not yet been written. If you know
232-
what it does, please help out with a pull request to the relevant file in
233-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
234+
Get a single character as a ``Py5Shape`` object. Use the ``detail`` parameter to
235+
draw the shape with only straight line segments.
236+
237+
Calling ``Py5Shape.disable_style()`` on the returned ``Py5Shape`` object seems
238+
to be necessary for these to be drawable.
239+
240+
This method only works on fonts loaded with ``create_font()``.
234241
"""
235242
pass
236243

237244
@_return_py5shape
238245
def get_shape(self, *args):
239-
"""The documentation for this field or method has not yet been written.
246+
"""Get a single character as a ``Py5Shape`` object.
240247
241248
Underlying Java method: PFont.getShape
242249
@@ -252,62 +259,50 @@ def get_shape(self, *args):
252259
----------
253260
254261
ch: chr
255-
missing variable description
262+
single character
256263
257264
detail: float
258-
missing variable description
265+
level of shape detail
259266
260267
Notes
261268
-----
262269
263-
The documentation for this field or method has not yet been written. If you know
264-
what it does, please help out with a pull request to the relevant file in
265-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
270+
Get a single character as a ``Py5Shape`` object. Use the ``detail`` parameter to
271+
draw the shape with only straight line segments.
272+
273+
Calling ``Py5Shape.disable_style()`` on the returned ``Py5Shape`` object seems
274+
to be necessary for these to be drawable.
275+
276+
This method only works on fonts loaded with ``create_font()``.
266277
"""
267278
return self._instance.getShape(*args)
268279

269280
def get_size(self) -> int:
270-
"""The documentation for this field or method has not yet been written.
281+
"""Get the font's size.
271282
272283
Underlying Java method: PFont.getSize
273284
274285
Notes
275286
-----
276287
277-
The documentation for this field or method has not yet been written. If you know
278-
what it does, please help out with a pull request to the relevant file in
279-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
288+
Get the font's size.
280289
"""
281290
return self._instance.getSize()
282291

283292
def is_smooth(self) -> bool:
284-
"""The documentation for this field or method has not yet been written.
293+
"""Boolean value reflecting if smoothing (anti-aliasing) was used when the font was
294+
created.
285295
286296
Underlying Java method: PFont.isSmooth
287297
288298
Notes
289299
-----
290300
291-
The documentation for this field or method has not yet been written. If you know
292-
what it does, please help out with a pull request to the relevant file in
293-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
301+
Boolean value reflecting if smoothing (anti-aliasing) was used when the font was
302+
created. By default, ``create_font()`` will use smoothing.
294303
"""
295304
return self._instance.isSmooth()
296305

297-
def is_stream(self) -> bool:
298-
"""The documentation for this field or method has not yet been written.
299-
300-
Underlying Java method: PFont.isStream
301-
302-
Notes
303-
-----
304-
305-
The documentation for this field or method has not yet been written. If you know
306-
what it does, please help out with a pull request to the relevant file in
307-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
308-
"""
309-
return self._instance.isStream()
310-
311306
@classmethod
312307
@_return_list_str
313308
def list(cls) -> List[str]:
@@ -320,42 +315,29 @@ def list(cls) -> List[str]:
320315
321316
Gets a list of the fonts installed on the system. The data is returned as a list
322317
of strings. This list provides the names of each font for input into
323-
:doc:`create_font`, which allows py5 to dynamically format fonts.
318+
``create_font()``, which allows py5 to dynamically format fonts.
324319
325320
This works outside of a running Sketch.
326321
"""
327322
return cls._cls.list()
328323

329-
def set_subsetting(self) -> None:
330-
"""The documentation for this field or method has not yet been written.
331-
332-
Underlying Java method: PFont.setSubsetting
333-
334-
Notes
335-
-----
336-
337-
The documentation for this field or method has not yet been written. If you know
338-
what it does, please help out with a pull request to the relevant file in
339-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
340-
"""
341-
return self._instance.setSubsetting()
342-
343324
def width(self, c: chr, /) -> float:
344-
"""The documentation for this field or method has not yet been written.
325+
"""Get the width of a character in this font.
345326
346327
Underlying Java method: PFont.width
347328
348329
Parameters
349330
----------
350331
351332
c: chr
352-
missing variable description
333+
single character
353334
354335
Notes
355336
-----
356337
357-
The documentation for this field or method has not yet been written. If you know
358-
what it does, please help out with a pull request to the relevant file in
359-
https://github.com/hx2A/py5generator/tree/master/py5_docs/Reference/api_en/.
338+
Get the width of a character in this font. The value is based on a font of size
339+
1. Multiply it by the font size to get the horizontal space of the character.
340+
341+
This will return 0 if the character is not in the font's character set.
360342
"""
361343
return self._instance.width(c)

0 commit comments

Comments
 (0)