{"id":18174629,"url":"https://github.com/microsoft/dwriteshapepy","last_synced_at":"2025-08-01T20:44:25.243Z","repository":{"id":48575157,"uuid":"332093383","full_name":"microsoft/DWriteShapePy","owner":"microsoft","description":"Python extension for streamlined DirectWrite text shaping. ","archived":false,"fork":false,"pushed_at":"2025-01-16T20:59:08.000Z","size":117,"stargazers_count":17,"open_issues_count":2,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-07-26T18:46:10.907Z","etag":null,"topics":["cython","directwrite","dwrite","fonts","opentype"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-23T00:19:47.000Z","updated_at":"2025-05-10T17:20:31.000Z","dependencies_parsed_at":"2024-03-28T23:37:40.253Z","dependency_job_id":"4cc278f9-592c-47db-8065-a423dfe9190d","html_url":"https://github.com/microsoft/DWriteShapePy","commit_stats":{"total_commits":42,"total_committers":7,"mean_commits":6.0,"dds":0.4285714285714286,"last_synced_commit":"bce9ff1ef387bc5c29a1e3fb69cd234237380018"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/microsoft/DWriteShapePy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FDWriteShapePy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FDWriteShapePy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FDWriteShapePy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FDWriteShapePy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/DWriteShapePy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FDWriteShapePy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268294438,"owners_count":24227680,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cython","directwrite","dwrite","fonts","opentype"],"created_at":"2024-11-02T16:06:52.439Z","updated_at":"2025-08-01T20:44:25.166Z","avatar_url":"https://github.com/microsoft.png","language":"C++","readme":"# Project\n\nDWriteShapePy is a Python extension built using Cython. It provides streamlined bindings for\nthe DirectWrite shaping engine. The model is similar to the model provided by uHarfBuzz but some \ndifferences because of differences in the API models between DirectWrite and HarfBuzz. \n\nDWriteShapePy was initially developed to support a Python based font testing environment where similar tests are \nexecuted using both DirectWrite and HarfBuzz. \n\nThe repo contains two methods to build the extension. The standard Python/Cython method using setup.py and a \nVisual Studio solution. Setup.py is used to build, install and create distribution packages. The Visual Studio solution \nis for cross mode debugging of the extension as well as the client. \n\nSetup.py builds the package with the extension name “dwriteshapepy”. \nUseful command lines when using setup.py to build, install and create distribution packages are:\n\nBuild the extension on local machine.\nPython setup.py build \n\nInstall the built extension into current Python environment.\nPython setup.py install\n\nCreate distribution package.\nPython setup.py bdist_wheel\n\nThe dwriteshape directory in the repo contains the Visual Studio solution and projects. The dwriteshape solution contains two \nprojects. The dwriteshape project and the client project. The dwriteshape project builds the package as the extension name “dwriteshape”. \nNote the difference between extension build using setup.py. This is necessary because Visual Studio does not have same level \nof control as setup.py and seems to require the extension name be the same as that of the .pyx file. It could also be useful in \navoiding name collisions. The Visual Studio project should only be used to create debug builds of the extension for development. \nThe client project is a simple test client for the dwriteshape project. \n\nIn order to build the extension with the Visual Studio project you must first use Cython to create the .cpp file from the .pyx and .pxd files. \nThere is a build.bat in the src\\dwriteshapepy directory to do this.  The generated file dwriteshape.cpp should be deleted if switching \nfrom building with Visual Studio or setup.py or visa versa. When building with setup.py the .cpp file is generated automatically so build.bat \nis not necessary. \n\nThe directory src\\cpp contains the DWrite abstraction layer of the extension basically plumbing between the exported API and DWrite. \nThis code is common between build methods. \n\n### Example\n\n```python\nimport sys\nimport dwriteshapepy as dw \nfrom pathlib import Path\n\nwith open(sys.argv[1], 'rb') as fontfile:\n    fontdata = fontfile.read()\n\ntext = sys.argv[2]\n\nface = dw.Face(fontdata)\nfont = dw.Font(face)\nupm = font.upem\nprint(upm)\n\nbuf = dw.Buffer()\nbuf.add_str(text)\n    \nfeatures = {\"kern\": True, \"liga\": True}\ndw.shape(font, buf, features)\nglyph_names = [font.glyph_to_string(g.codepoint) for g in buf.glyph_infos]\ninfos = [(g.codepoint, g.cluster) for g in buf.glyph_infos]\nprint(glyph_names)\nprint(infos)\n\nadvance = [(adv.x_advance, adv.y_advance, adv.x_offset, adv.y_offset) for adv in buf.glyph_positions]\nprint(advance)\n\ninfos = buf.glyph_infos\npositions = buf.glyph_positions\n\nfor info, pos in zip(infos, positions):\n    gid = info.codepoint\n    cluster = info.cluster\n    x_advance = pos.x_advance\n    x_offset = pos.x_offset\n    y_offset = pos.y_offset\n    print(f\"gid{gid}={cluster}@{x_advance},{x_offset}+{y_offset}\")\n\n```\n\n## Contributing\n\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Trademarks\n\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft \ntrademarks or logos is subject to and must follow \n[Microsoft's Trademark \u0026 Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\nAny use of third-party trademarks or logos are subject to those third-party's policies.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fdwriteshapepy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fdwriteshapepy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fdwriteshapepy/lists"}