Skip to main content

Python extension for Windows DirectWrite shaping, modeled after uharfbuzz

Project description

Project

DWriteShapePy is a Python extension built using Cython. It provides streamlined bindings for the DirectWrite shaping engine. The model is similar to the model provided by uHarfBuzz but some differences because of differences in the API models between DirectWrite and HarfBuzz.

DWriteShapePy was initially developed to support a Python based font testing environment where similar tests are executed using both DirectWrite and HarfBuzz.

Example

import sys
import dwriteshapepy as dw 
from pathlib import Path

with open(sys.argv[1], 'rb') as fontfile:
    fontdata = fontfile.read()

text = sys.argv[2]

face = dw.Face(fontdata)
font = dw.Font(face)
upm = font.upem
print(upm)

buf = dw.Buffer()
buf.add_str(text)
    
features = {"kern": True, "liga": True}
dw.shape(font, buf, features)
glyph_names = [font.glyph_to_string(g.codepoint) for g in buf.glyph_infos]
infos = [(g.codepoint, g.cluster) for g in buf.glyph_infos]
print(glyph_names)
print(infos)

advance = [(adv.x_advance, adv.y_advance, adv.x_offset, adv.y_offset) for adv in buf.glyph_positions]
print(advance)

infos = buf.glyph_infos
positions = buf.glyph_positions

for info, pos in zip(infos, positions):
    gid = info.codepoint
    cluster = info.cluster
    x_advance = pos.x_advance
    x_offset = pos.x_offset
    y_offset = pos.y_offset
    print(f"gid{gid}={cluster}@{x_advance},{x_offset}+{y_offset}")

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

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

dwriteshapepy-1.0.12.tar.gz (115.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dwriteshapepy-1.0.12-cp313-cp313-win_amd64.whl (103.7 kB view details)

Uploaded CPython 3.13Windows x86-64

dwriteshapepy-1.0.12-cp312-cp312-win_amd64.whl (104.0 kB view details)

Uploaded CPython 3.12Windows x86-64

dwriteshapepy-1.0.12-cp311-cp311-win_amd64.whl (103.5 kB view details)

Uploaded CPython 3.11Windows x86-64

dwriteshapepy-1.0.12-cp310-cp310-win_amd64.whl (103.5 kB view details)

Uploaded CPython 3.10Windows x86-64

dwriteshapepy-1.0.12-cp39-cp39-win_amd64.whl (104.0 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file dwriteshapepy-1.0.12.tar.gz.

File metadata

  • Download URL: dwriteshapepy-1.0.12.tar.gz
  • Upload date:
  • Size: 115.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dwriteshapepy-1.0.12.tar.gz
Algorithm Hash digest
SHA256 05b44b1caa0d519e2bbb858a306fd9a8d0b65c5a1fd2af3d6ec6818cb743ba25
MD5 25ff6bdbd216d722fe0b81358734abd8
BLAKE2b-256 fad65858f57a1a9756262ddc37b9d99643a15048973fdd00cc26a7ecb94f6f31

See more details on using hashes here.

Provenance

The following attestation bundles were made for dwriteshapepy-1.0.12.tar.gz:

Publisher: pypi_publish.yml on microsoft/DWriteShapePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dwriteshapepy-1.0.12-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for dwriteshapepy-1.0.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5df7aebe98c6d777e65acbc44a3adfafda5ca8cf487322f21dfab1201b83a459
MD5 ac5dbc6acb36278215927c7fc66fb579
BLAKE2b-256 e17ca5e417c4a8af467f03910a0b2106e0dd2637c47bdb079670d30b0ae84734

See more details on using hashes here.

Provenance

The following attestation bundles were made for dwriteshapepy-1.0.12-cp313-cp313-win_amd64.whl:

Publisher: pypi_publish.yml on microsoft/DWriteShapePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dwriteshapepy-1.0.12-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for dwriteshapepy-1.0.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 03f6eea96bdbfea14dcf53759076edf3323e25841bf552a5b8b158eebef71418
MD5 bb9ab2ca64e54e2c98840852a9bf1d39
BLAKE2b-256 b266d4dede609a7a53b238a88ad73cbce323c250d5c89895f00e12f0d1be72a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dwriteshapepy-1.0.12-cp312-cp312-win_amd64.whl:

Publisher: pypi_publish.yml on microsoft/DWriteShapePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dwriteshapepy-1.0.12-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for dwriteshapepy-1.0.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e88c266d4401e22ca1febac9c8ff8a2d1613dd9b220e74c3582f0a36949fbb73
MD5 4e6c1e83f68cf0cb9c1714450324395d
BLAKE2b-256 35f8922ccdff382c4132835488d38c387960be021700d6dc8daa01578204a55c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dwriteshapepy-1.0.12-cp311-cp311-win_amd64.whl:

Publisher: pypi_publish.yml on microsoft/DWriteShapePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dwriteshapepy-1.0.12-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for dwriteshapepy-1.0.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4880c85a807209744fa2c73306e7d8092b5eec499732ffe507b35f04b7d06b7b
MD5 19a9d9b036a922968762f9311a5b0fc9
BLAKE2b-256 3cb38ae56bacb421efcfef3910406c72ae25342661006383e89ddd17e889d3c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dwriteshapepy-1.0.12-cp310-cp310-win_amd64.whl:

Publisher: pypi_publish.yml on microsoft/DWriteShapePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dwriteshapepy-1.0.12-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for dwriteshapepy-1.0.12-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 196e19bc68e179c58239b4085d0f18f19491c3c1b2e07c8defae4dc70bd48c31
MD5 9b223152d84e68d8bfd39ca3f6c7c949
BLAKE2b-256 777cba94b7d4186cfda169de410c4067b9566e0476cb7bb3597372d30efa8d82

See more details on using hashes here.

Provenance

The following attestation bundles were made for dwriteshapepy-1.0.12-cp39-cp39-win_amd64.whl:

Publisher: pypi_publish.yml on microsoft/DWriteShapePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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