README 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. dtext
  2. =====
  3. `dtext` is a font-rendering library that aims at simplicity, both of the
  4. internals and of use.
  5. Installation
  6. ------------
  7. In order to use `dtext` in one of your projects, the recommended way is to just
  8. drop `dtext.h` and `dtext.c` in its directory and add them to the `Makefile`.
  9. For legal matters, despite this not being legal advice, you most likely should
  10. in this case add anyone noted as owning a copyright for this code in the LICENSE
  11. file to the place you keep your own list.
  12. You can also build `dtext` as a shared library, and then link against it. This
  13. should relieve you of the obligation of adding names to your copyright list, so
  14. long as you do not distribute both files bundled. Again, this is not legal
  15. advice.
  16. Usage
  17. -----
  18. Most functions return a `dt_error` value. In this case, zero means success and
  19. any non-zero value indicates failure.
  20. dt_error dt_init(dt_context **ctx, Display *dpy, Window win);
  21. void dt_quit(dt_context *ctx);
  22. First, you need to initialize the library using `dt_init`. At the end of the
  23. program, you should close it with `dt_quit`.
  24. dt_error dt_load(dt_context *ctx, dt_font **fnt, char const *name)
  25. void dt_free(dt_context **ctx, dt_font *fnt);
  26. Then, you can load fonts using `dt_load`, and free them with `dt_free`. The
  27. format of the `name` argument is described in the "Font names" section below.
  28. dt_error dt_box(dt_context *ctx, dt_font *fnt, dt_bbox *bbox,
  29. wchar_t const *txt, size_t len);
  30. dt_error dt_draw(dt_context *ctx, dt_font *fnt, dt_color const *color,
  31. uint32_t x, uint32_t y, wchar_t const *txt, size_t len);
  32. These are the two main functions of the library.
  33. `dt_box` returns a bounding box to the string composed of the first `len`
  34. characters of `txt`, drawn with font `fnt`. The return is done through the
  35. pointer `bbox`, which will contain the bounding box. `bbox->x` and `bbox->y`
  36. will contain the coordinates of the top-left corner of the box relative to the
  37. origin of the baseline, and `bbox.w` and `bbox.h` are its width and height.
  38. `dt_draw` draws the string composed of the first `len` characters of `txt`,
  39. drawn with font `fnt`, in color `color`, with the baseline starting at position
  40. `x`, `y`.
  41. `dt_color` represents a color. It is of the form
  42. `{ .red, .green, .blue, .alpha }`, with `alpha = 0xFF` for full-visibility. For
  43. example, if it is memset with `0xFF`, it will be the color "white".
  44. The baseline is the line on which text would be drawn, if it was drawn by hand.
  45. `dt_font.ascent` is the height of the highest character of the font, relative to
  46. the baseline. `dt_font.height` is the total height of the highest character in
  47. the font.
  48. Font names
  49. ----------
  50. A font name is composed of several font descriptions, separated by `;`. Each
  51. font description is a file name and a pixel size, separated by `:`.
  52. For example, the following is a valid font string:
  53. /fonts/main.ttf:16;/fonts/special_chars.ttf:18;/fonts/fallback.ttf:16
  54. You have to specify one font size per font file, given every font file is not
  55. built the same way.
  56. Examples
  57. --------
  58. You can find examples in the `examples` directory. They have been built using
  59. certain fonts you may not have ; so you may have to edit the font strings
  60. located near the top of those files.
  61. In order to test them, just run `make` and run the executables in `build/`.
  62. Distribution
  63. ------------
  64. This code is distributed at http://git.ekleog.org/dtext ; and every commit
  65. should be signed with OpenPGP key
  66. AA29 BF0D F468 A8DC 1AB0 EA84 6598 F235 F23F B2AE
  67. If this is not the case, it means either I forgot to sign a commit, or you are
  68. getting MitM-ed. In any case, please do not use code from an unsigned version
  69. without properly checking it.
  70. Contributing
  71. ------------
  72. Please send any comments, insults or preferably patches to leo@gaspard.io .