{"id":26945840,"url":"https://github.com/tinne26/etxt","last_synced_at":"2025-10-30T00:35:52.837Z","repository":{"id":39947800,"uuid":"476890794","full_name":"tinne26/etxt","owner":"tinne26","description":"Text rendering package for Ebitengine.","archived":false,"fork":false,"pushed_at":"2025-03-20T13:53:28.000Z","size":1128,"stargazers_count":58,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T20:03:10.748Z","etag":null,"topics":["ebitengine","font","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","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/tinne26.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2022-04-01T23:00:40.000Z","updated_at":"2025-03-20T13:53:32.000Z","dependencies_parsed_at":"2023-10-16T12:17:31.930Z","dependency_job_id":"6eb66659-1b0b-4487-95fa-49cee00d35e0","html_url":"https://github.com/tinne26/etxt","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinne26%2Fetxt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinne26%2Fetxt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinne26%2Fetxt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinne26%2Fetxt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinne26","download_url":"https://codeload.github.com/tinne26/etxt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103864,"owners_count":21048245,"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":["ebitengine","font","golang"],"created_at":"2025-04-02T19:16:39.420Z","updated_at":"2025-10-30T00:35:47.806Z","avatar_url":"https://github.com/tinne26.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# etxt\n[![Go Reference](https://pkg.go.dev/badge/github.com/tinne26/etxt@v0.0.9.svg)](https://pkg.go.dev/github.com/tinne26/etxt@v0.0.9)\n\n**etxt** is a package for [vectorial](https://github.com/tinne26/etxt/blob/v0.0.9/docs/panorama.md)[^1] text rendering in Golang designed to be used with [**Ebitengine**](https://github.com/hajimehoshi/ebiten), the 2D game engine made by [Hajime Hoshi](https://github.com/hajimehoshi).\n\n[^1]: If you are using pixel-art-like vectorial fonts, read [these tips](https://github.com/tinne26/etxt/blob/v0.0.9/docs/pixel-tips.md).\n\nWhile Ebitengine already includes the [**ebiten/v2/text/v2**](https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2/text/v2) package, **etxt** has some advantages over it:\n- Makes text size easy to change.\n- Puts emphasis on getting [display scaling](https://github.com/tinne26/etxt/blob/v0.0.9/docs/display-scaling.md) right.\n- Gets rid of `font.Face` for good.\n- Provides high quality documentation and [examples](https://github.com/tinne26/etxt/tree/v0.0.9/examples).\n- Helps out with some extras like faux bold, faux oblique, basic line wrapping, embedded fonts, glyph quantization, line spacing, etc.\n- Exposes caches, rasterizers and sizers for you to adapt if you have more advanced needs.\n\nWhat **etxt** doesn't do:\n- No general [text layout](https://raphlinus.github.io/text/2020/10/26/text-layout.html). Features like bidi, itemization, shaping, general hit testing, justification and others are not covered and in most cases aren't a primary goal for this package.\n- Poor or no support for [complex scripts](https://github.com/tinne26/etxt/blob/v0.0.9/docs/shaping.md) (e.g. Arabic) nor vertical text layouts (e.g. Japanese). Notice that [**ebiten/v2/text/v2**](https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2/text/v2) fares much better in this regard.\n- None of the things people actually want: shadows and outlines, gamma correction, subpixel antialiasing, Knuth-Plass line breaking, better support for shaders, etc. Some can already be crudely faked, some will be added in the future... but this is the situation right now.\n\n*If you are unfamiliar with typography terms and concepts, I highly recommend reading the first chapters of [FreeType Glyph Conventions](https://freetype.org/freetype2/docs/glyphs/index.html); one the best references on the topic you can find on the internet.*\n\n## Code example\nLess talk and more code!\n```Golang\npackage main\n\nimport ( \"math\" ; \"image/color\" )\nimport \"github.com/hajimehoshi/ebiten/v2\"\nimport \"github.com/tinne26/etxt\"\nimport \"github.com/tinne26/fonts/liberation/lbrtserif\"\n\nconst WordsPerSec = 2.71828\nvar Words = []string {\n\t\"solitude\", \"joy\", \"ride\", \"whisper\", \"leaves\", \"cookie\",\n\t\"hearts\", \"disdain\", \"simple\", \"death\", \"sea\", \"shallow\",\n\t\"self\", \"rhyme\", \"childish\", \"sky\", \"tic\", \"tac\", \"boom\",\n}\n\n// ---- Ebitengine's Game interface implementation ----\n\ntype Game struct { text *etxt.Renderer ; wordIndex float64 }\n\nfunc (self *Game) Layout(winWidth int, winHeight int) (int, int) {\n\tscale := ebiten.DeviceScaleFactor() // *\n\t// * ebiten.Monitor().DeviceScaleFactor() in \u003e=v2.7.0\n\tself.text.SetScale(scale) // relevant for HiDPI\n\tcanvasWidth  := int(math.Ceil(float64(winWidth)*scale))\n\tcanvasHeight := int(math.Ceil(float64(winHeight)*scale))\n\treturn canvasWidth, canvasHeight\n}\n\nfunc (self *Game) Update() error {\n\tnewIndex := (self.wordIndex + WordsPerSec/60.0)\n\tself.wordIndex = math.Mod(newIndex, float64(len(Words)))\n\treturn nil\n}\n\nfunc (self *Game) Draw(canvas *ebiten.Image) {\n\t// background color\n\tcanvas.Fill(color.RGBA{229, 255, 222, 255})\n\t\n\t// get screen center position\n\tbounds := canvas.Bounds() // assumes origin (0, 0)\n\tx, y := bounds.Dx()/2, bounds.Dy()/2\n\n\t// draw text\n\tword := Words[int(self.wordIndex)]\n\tself.text.Draw(canvas, word, x, y)\n}\n\n// ---- main function ----\n\nfunc main() {\n\t// create text renderer, set the font and cache\n\trenderer := etxt.NewRenderer()\n\trenderer.SetFont(lbrtserif.Font())\n\trenderer.Utils().SetCache8MiB()\n\t\n\t// adjust main text style properties\n\trenderer.SetColor(color.RGBA{239, 91, 91, 255})\n\trenderer.SetAlign(etxt.Center)\n\trenderer.SetSize(72)\n\n\t// set up Ebitengine and start the game\n\tebiten.SetWindowTitle(\"etxt/examples/ebiten/words\")\n\terr := ebiten.RunGame(\u0026Game{ text: renderer })\n\tif err != nil { panic(err) }\n}\n```\n\nYou can try running this yourself with[^2]:\n```\ngo run github.com/tinne26/etxt/examples/ebiten/words@latest\n```\nAlternatively, you can go to https://tinne26.github.io/etxt-examples/ and click on the first example for the web version.\n\n[^2]: You will need Golang \u003e=1.18, and if you have never used Ebitengine before, you may need to [install some dependencies](https://ebitengine.org/en/documents/install.html?os=linux) (typically only on Linux or FreeBSD).\n\nThis is a very simple and self-contained example. If you want to learn more, make sure to take a look at [etxt/examples](https://github.com/tinne26/etxt/tree/v0.0.9/examples)!\n\n## Can I use this package without Ebitengine?\nYeah, you can compile it with `-tags gtxt`. Notice that `gtxt` will make text drawing happen on the CPU, so don't try to use it for real-time applications. In particular, be careful to not accidentally use `gtxt` with Ebitengine (they are compatible in many cases, but performance will die).\n\n## Testing, contributions and others\n- For testing, see the instructions on [`etxt/test`](https://github.com/tinne26/etxt/blob/v0.0.9/test).\n- If you have any questions or suggestions for improvements feel free to speak, I'm always happy to explain or discuss.\n- Otherwise, I'm not looking for contributors nor general help.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinne26%2Fetxt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinne26%2Fetxt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinne26%2Fetxt/lists"}