Skip to content

Commit

Permalink
Replace Roboto fonts with Ubuntu fonts (#57)
Browse files Browse the repository at this point in the history
The Ubuntu fonts generally look better at small point sizes because they
have type hinting for non-antialiased displays. They are the only openly
licensed fonts that I can find with this property.

Not 100% happy with the look of Ubuntu fonts, as they are very wide,
which is not so good for compact displays.

I am keeping the large Roboto fonts in examples, as they look much
better for large point sizes.
  • Loading branch information
corranwebster authored Nov 11, 2024
1 parent 0b2adf3 commit 54a7688
Show file tree
Hide file tree
Showing 29 changed files with 669 additions and 615 deletions.
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ Most of the code is licensed using the MIT license:
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The bitmap fonts included with the Tempe source are derived from Roboto and
are licensed with the Apache License 2.0: see
The bitmap fonts included with the Tempe source are derived from Ubuntu fonts
and are licensed with the Ubuntu Font License: see
`github.com/unital/tempe/blob/main/src/tempe/fonts/README.rst <https://github.com/unital/tempe/blob/main/src/tempe/fonts/README.rst>`_
for details.

Binary file modified docs/source/user_guide/line_plot_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/user_guide/polar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/user_guide/polar_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/user_guide/scatter_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/user_guide/shapes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/source/user_guide/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,16 @@ format produced by Peter Hinch's
`font_to_py script <https://github.com/peterhinch/micropython-font-to-py>`_,
or AntiRez's `microfont library <https://github.com/antirez/microfont>`_,
as well as a slightly more efficient internal variant. Tempe provides bitmap
versions of Google's Roboto font at 16 pt, which looks reasonably good on small
screens.
versions of Canconical's Ubuntu font at 16 pt, which looks reasonably good on
small screens.

These fonts are typically shipped as modules::

from tempe.font import TempeFont
from tempe.fonts import roboto16bold
from tempe.fonts import ubuntu16bold
from tempe.text import CENTER

font = TempeFont(roboto16bold)
font = TempeFont(ubuntu16bold)

surface.text(
"DRAWING",
Expand Down
File renamed without changes.
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions examples/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tempe.shapes import Rectangles
from tempe.display import FileDisplay
from tempe.font import TempeFont
from tempe.fonts import roboto16bold
from tempe.fonts import ubuntu16bold


# a buffer one half the size of the screen
Expand All @@ -23,7 +23,7 @@
surface.add_shape("BACKGROUND", background)

# draw some black text in the main drawing layer
font = TempeFont(roboto16bold)
font = TempeFont(ubuntu16bold)
hello_tempe = Text(
[(10, 10)], [0x0000], ["Hello Tempe!"], font=font, clip=(0, 0, 120, 60)
)
Expand Down
6 changes: 3 additions & 3 deletions examples/line_plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,23 @@ def scale_values(self, data):
)

# Plot title and additional information
from tempe.fonts import roboto16bold, roboto16
from tempe.fonts import ubuntu16bold, ubuntu16
from tempe.font import TempeFont

surface.text(
"DRAWING",
(4, 0),
colors.grey_a,
"Temperature (°C)",
font=TempeFont(roboto16bold),
font=TempeFont(ubuntu16bold),
)
surface.text(
"DRAWING",
(320, 0),
colors.grey_a,
"October 21-22, 2024",
(RIGHT, TOP),
font=TempeFont(roboto16),
font=TempeFont(ubuntu16),
)


Expand Down
6 changes: 3 additions & 3 deletions examples/polar_plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ def scale_values(self, data):
gc.collect()

# Plot title and additional information
from tempe.fonts import roboto16bold, roboto16
from tempe.fonts import ubuntu16bold, ubuntu16
from tempe.font import TempeFont

surface.text(
"DRAWING",
(4, 0),
colors.grey_a,
"Air Quality (ppb)",
font=TempeFont(roboto16bold),
font=TempeFont(ubuntu16bold),
)
surface.text(
"DRAWING",
(4, 20),
colors.grey_8,
"20/8/24--\n22/8/24",
font=TempeFont(roboto16),
font=TempeFont(ubuntu16),
)


Expand Down
8 changes: 4 additions & 4 deletions examples/scatter_plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,29 +343,29 @@ def scale_values(self, data):
)

# Plot title and additional information
from tempe.fonts import roboto16bold
from tempe.fonts import ubuntu16bold
from tempe.font import TempeFont

surface.text(
"DRAWING",
[[4, 0]],
[colors.grey_a],
["Temperature (°C) vs. Air Quality (ppb)"],
font=TempeFont(roboto16bold),
font=TempeFont(ubuntu16bold),
)
surface.text(
"DRAWING",
[[x1 + 20, y - 20]],
[colors.grey_a],
["20-22/8/24"],
font=TempeFont(roboto16bold),
font=TempeFont(ubuntu16bold),
)
surface.text(
"DRAWING",
[[x1 + 20, cy + 50]],
[colors.grey_a],
["Humidity"],
font=TempeFont(roboto16bold),
font=TempeFont(ubuntu16bold),
)


Expand Down
4 changes: 2 additions & 2 deletions examples/shapes_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from tempe.display import FileDisplay
from tempe.font import TempeFont
from tempe.fonts import roboto16bold
from tempe.fonts import ubuntu16bold

random.seed(0)

Expand All @@ -44,7 +44,7 @@
surface.add_shape("BACKGROUND", background)

# draw some black text in the main drawing layer
font = TempeFont(roboto16bold)
font = TempeFont(ubuntu16bold)
labels = Text(
[
(4, 4),
Expand Down
12 changes: 6 additions & 6 deletions examples/temperature_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tempe.markers import Marker
from tempe.surface import Surface
from tempe.component import Component, Label, LinePlot, ScatterPlot, BarPlot
from tempe.fonts import roboto16bold, roboto32boldnumbers, roboto24boldnumbers
from tempe.fonts import ubuntu16bold, roboto32boldnumbers, roboto24boldnumbers
from tempe.colormaps.plasma import plasma
from tempe.colormaps.viridis import viridis

Expand Down Expand Up @@ -343,11 +343,11 @@ async def main():
display = await init_display()
surface = Surface()
background = Component(surface, (0, 0, w, h))
label_1 = Label(surface, (4, 4, 100, 20), "Temperature", font=roboto16bold)
label_2 = Label(surface, (4, 64, 152, 20), "Memory Pressure", font=roboto16bold)
label_3 = Label(surface, (4, 124, 152, 20), "Free Memory", font=roboto16bold)
label_4 = Label(surface, (4, 184, 152, 20), "Stack Use", font=roboto16bold)
label_5 = Label(surface, (164, 184, 152, 20), "Frequency", font=roboto16bold)
label_1 = Label(surface, (4, 4, 100, 20), "Temperature", font=ubuntu16bold)
label_2 = Label(surface, (4, 64, 152, 20), "Memory Pressure", font=ubuntu16bold)
label_3 = Label(surface, (4, 124, 152, 20), "Free Memory", font=ubuntu16bold)
label_4 = Label(surface, (4, 184, 152, 20), "Stack Use", font=ubuntu16bold)
label_5 = Label(surface, (164, 184, 152, 20), "Frequency", font=ubuntu16bold)
freq_display = Label(
surface,
(164, 204, 76, 35),
Expand Down
20 changes: 18 additions & 2 deletions examples/update_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"""Example showing asyncio updating of a surface."""

import asyncio
from machine import ADC, RTC
from machine import ADC, RTC, I2C, Pin

from tempe import colors
from tempe.font import TempeFont
from tempe.surface import Surface
from tempe.text import TOP, RIGHT

from example_devices.bme280 import BME280


# a buffer one half the size of the screen
WORKING_BUFFER = bytearray(2 * 240 * 161)
Expand Down Expand Up @@ -74,6 +76,15 @@ async def update_temperature(adc, text_field):
text_field.update(texts=[text])
await asyncio.sleep(1)

async def update_temperature_bme(bme, text_field):
while True:
temp = bme.read_compensated_data()[0] / 100
text = f"{temp:.2f}°C"
# only update when needed
if text != text_field.texts[0]:
text_field.update(texts=[text])
await asyncio.sleep(1)


async def refresh_display(surface, display, working_buffer):
import time
Expand All @@ -91,6 +102,10 @@ async def main(working_buffer):
surface = Surface()
temp_adc = ADC(ADC.CORE_TEMP)
rtc = RTC()

i2c = I2C(0, scl=Pin(5), sda=Pin(4))
bme = BME280(i2c=i2c)

display, fields = await asyncio.gather(
init_display(),
init_surface(surface),
Expand All @@ -101,7 +116,8 @@ async def main(working_buffer):
await asyncio.gather(
refresh_display(surface, display, working_buffer),
update_time(rtc, time_field),
update_temperature(temp_adc, temp_field),
#update_temperature(temp_adc, temp_field),
update_temperature_bme(bme, temp_field),
)


Expand Down
4 changes: 2 additions & 2 deletions src/tempe/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from .markers import Marker

try:
from .fonts import roboto16
from .fonts import ubuntu16

default_font = roboto16
default_font = ubuntu16
except ImportError:
default_font = None

Expand Down
Empty file.
6 changes: 3 additions & 3 deletions src/tempe/fonts/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Fonts
The fonts in this directory a bitmap fonts derived from various
sources.

roboto*.py
These are fonts derived from the Roboto fonts by Google. They are
licensed under the Apache license. See LICENSE_roboto.txt for further
ubuntu*.py
These are fonts derived from the Ubuntu fonts by Canconical. They are
licensed under the Ubuntu Font License. See LICENSE_ubuntu.txt for further
details.
Loading

0 comments on commit 54a7688

Please sign in to comment.