{"id":24893679,"url":"https://github.com/saidwho12/hamza","last_synced_at":"2025-05-07T05:10:20.360Z","repository":{"id":38059642,"uuid":"330111516","full_name":"saidwho12/hamza","owner":"saidwho12","description":"C Unicode/OpenType Library","archived":false,"fork":false,"pushed_at":"2025-03-13T19:44:50.000Z","size":31357,"stargazers_count":43,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-03T19:03:57.616Z","etag":null,"topics":["c","c99","font","freetype","library","opentype","shaper","shaping","shaping-engine","text","text-shaping","truetype","typesetting","unicode"],"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/saidwho12.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"saidwho12"}},"created_at":"2021-01-16T07:47:59.000Z","updated_at":"2025-03-21T16:09:53.000Z","dependencies_parsed_at":"2025-03-13T20:41:12.807Z","dependency_job_id":null,"html_url":"https://github.com/saidwho12/hamza","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saidwho12%2Fhamza","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saidwho12%2Fhamza/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saidwho12%2Fhamza/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saidwho12%2Fhamza/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saidwho12","download_url":"https://codeload.github.com/saidwho12/hamza/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252817630,"owners_count":21808706,"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","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":["c","c99","font","freetype","library","opentype","shaper","shaping","shaping-engine","text","text-shaping","truetype","typesetting","unicode"],"created_at":"2025-02-01T19:01:25.986Z","updated_at":"2025-05-07T05:10:20.343Z","avatar_url":"https://github.com/saidwho12.png","language":"C","funding_links":["https://ko-fi.com/saidwho12"],"categories":["C"],"sub_categories":[],"readme":"\n# Hamza\n\nHamza is a Header-Only, Fast and Portable C99 [Unicode](https://www.unicode.org)/[OpenType](https://docs.microsoft.com/en-us/typography/opentype/spec) shaping and rendering library. It's designed to be a small, \nportable and optimized shaper that's easy to integrate into any existing project. Below is an image of a short string of Arabic shaped with this library using a fairly complex font, random colors are assigned to each glyph.\n![](banner.png)\n\n## UCD File Generation\nHamza includes the single-file programs `update_ucd_ftp` and `generate_ucd_headers`. The first pulls the necessary UCD files from the FTP server at [ftp.unicode.org]() and requires [curl](https://github.com/curl/curl). The second generates optimized C headers from those UCD files. Both of these programs make use of the POSIX regex library for filtering and parsing. \n\nDownload the UCD txt, this might take a few minutes so only do if UCD headers are out of date:\n```sh\n./build/update_ucd_ftp\n```\nGenerate the header files for the UCD versions:\n```sh\n./build/generate_ucd_headers\n```\n\n## Getting Started \nTo start using Hamza, define `HZ_IMPLEMENTATION` before including `hz.h`. You can optionally define `HZ_NO_STDLIB` for . It's also necessary to include the header for the UCD for the version you require.\nWe will explain later how these are generated and how you can update them yourself. \n```c\n#define HZ_IMPLEMENTATION\n#include \u003chz/hz_ucd_15_0_0.h\u003e\n#include \u003chz/hz.h\u003e\n```\n\nTo initialize the library first fill a `hz_config_t` struct and call `hz_init`:\n```c\n  hz_config_t cfg = {\n  };\n\n  if (hz_init(\u0026cfg) != HZ_OK) {\n      fprintf(stderr, \"%s\\n\", \"Failed to initialize Hamza!\");\n      return -1;\n  }\n```\n\n  ### Loading Fonts\n  Next, before you can shape any text you must provide font data. You want to load a font into a `stbtt_fontinfo` struct. Hamza includes `stb_truetype.h` which is intended to be used in reading fonts. To create a `hz_font_t` from a stbtt font, write:\n  ```c\n  hz_font_t *font = hz_stbtt_font_create(\u0026fontinfo);\n  ```\n\nHamza aims to let the user manage the memory allocation and the data as much as possible. Before shaping the font data has to be parsed into a `hz_font_data_t` struct. This holds all the OpenType table data required for shaping with a specific font. The `hz_font_data_init` function takes as argument how much memory will be allocated to hold that font's data:\n```c\nhz_font_data_t font_data;\nhz_font_data_init(\u0026font_data, 1024*1024); // 1MiB\nhz_font_data_load(\u0026font_data, font);\n```\nCreate a shaper and initialize it:\n```c\nhz_shaper_t shaper;\nhz_shaper_init(\u0026shaper);\n```\nSet the shaper's required parameters:\n```c\nhz_shaper_set_direction(\u0026shaper, HZ_DIRECTION_RTL);\nhz_shaper_set_script(\u0026shaper, HZ_SCRIPT_ARABIC);\nhz_shaper_set_language(\u0026shaper, HZ_LANGUAGE_ARABIC);\n```\nSet the shaper's typography features:\n```c\nhz_feature_t features[] = {\n      HZ_FEATURE_ISOL,\n      HZ_FEATURE_INIT,\n      HZ_FEATURE_MEDI,\n      HZ_FEATURE_FINA,\n      HZ_FEATURE_RLIG,\n      HZ_FEATURE_LIGA,\n};\n\nhz_shaper_set_features(\u0026shaper, features, sizeof(features)/sizeof(features[0]));\n```\nCreate glyph buffer and shape!\n```c\nhz_buffer_t buffer;\nhz_buffer_init(\u0026buffer);\nhz_shape_sz1(\u0026shaper, \u0026font_data, HZ_ENCODING_UTF8, \"السلام عليكم\", \u0026buffer);\n```\nAfter this, you can access the buffer's glyph data and render. After you are done with everything you have to deinitialize.\n```c\nhz_buffer_release(\u0026buffer);\nhz_font_data_release(\u0026font_data);\nhz_font_destroy(font);\nhz_deinit();\n```\n\n## Tested Compilers\n  - GCC 10.3.0 x86_64-w64-wingw32\n  - GCC 10.3.0 x86_64-w64-wingw32 (mingw64)\n  - MSVC 19.35.32217.1\n  - MSVC 19.29.30148.0\n  - Clang 16.0.0 x86_64-pc-windows-msvc\n\n\n  ## Features\n- [x] Joining script support and RTL writing\n- [x] Kerning\n- [x] Ligatures\n- [x] Support for new [OpenType language tags](https://docs.microsoft.com/en-us/typography/opentype/spec/languagetags) (mixture of [ISO 639-3](https://iso639-3.sil.org/) and [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) codes)\n- [ ] Vertical layout Support (mostly for CJK, Mongolian, etc...)\n- [ ] Color Emojis\n- [ ] Emoji Combinations\n- [ ] Multi-Threading\n- [x] Unicode Normalization (NFC,NFD,NFKC,NFKD)\n- [ ] Open `.aat` `.woff` and `.woff2` formats\n\n\n## LICENSE\nHamza is licensed under MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaidwho12%2Fhamza","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaidwho12%2Fhamza","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaidwho12%2Fhamza/lists"}