Skip to main content

ttf-opensans is a Python package vending the Open Sans font by Steve Matteson.

Project description

py license status

ttf-opensans is a Python package vending the Open Sans font by Steve Matteson.

It is intended for when you want to use the Open Sans font family without having to worry about availability on the target system.

The Open Sans font family and this package is licensed under the Apache License, Version 2.0.

Installation

This package can be installed through the following command:

python3 -m pip install -U ttf-opensans

Usage

The fonts are provided through instances of the TTFFont class.

You can either access a specific font style directly:

import ttf_opensans

my_font = ttf_opensans.OPENSANS_SEMIBOLDITALIC

Or you can use the helper function to find the most appropriate font style:

from ttf_opensans import opensans

my_font = opensans(font_weight=600, italic=True)

Once you have the font you want, you can access various attributes on it:

print(my_font.name)  # "OpenSans-SemiBoldItalic"
print(my_font.weight)  # 600
print(my_font.italic)  # True
print(my_font.path)  # pathlib.Path("<...>/site_packages/ttf_opensans/ttf/OpenSans-SemiBoldItalic.ttf")

You can also open the font for reading directly:

with my_font.open() as fp:
    font_data = fp.read()

If you use the Python Imaging Library (Pillow), you can also directly get an ImageFont instance:

from PIL import Image, ImageDraw, ImageFont

with Image.new("RGB", (512, 512), (255, 255, 255)) as im:
    draw = ImageDraw.Draw(im)
    imagefont = my_font.imagefont(size=48)

    draw.text(font=imagefont, fill=(0, 0, 0), xy=(0, 0), text="Hello World!")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttf-opensans-2020.10.30.tar.gz (602.1 kB view hashes)

Uploaded Source

Built Distribution

ttf_opensans-2020.10.30-py3-none-any.whl (599.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page