psf.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <sys/types.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. /*
  8. * we supports PSF format in XNIX.
  9. * in linux, PSF fonts are in /usr/share/kbd/consolefonts, and they are always compressed.
  10. * */
  11. #define PSF_MAGIC 0x864ab572
  12. struct psf_header {
  13. __uint32_t magic;
  14. /* zero */
  15. __uint32_t version;
  16. __uint32_t header_size;
  17. /* zero if there's no unicode table */
  18. __uint32_t flags;
  19. /* in psf, a font calls glyph */
  20. __uint32_t glyphs_count;
  21. /* size of a glyph */
  22. __uint32_t glyph_size;
  23. __uint32_t height;
  24. __uint32_t width;
  25. } psf;
  26. int main(int argc, const char **argv) {
  27. if (!argv[1]) {
  28. printf("fatal error: no input file. \n");
  29. return 1;
  30. }
  31. int fd = open(argv[1], O_RDONLY);
  32. read(fd, (void *) &psf, sizeof(struct psf_header));
  33. printf("magic: %x\n", psf.magic);
  34. printf("version: %d\n", psf.version);
  35. printf("header size: %d\n", psf.header_size);
  36. printf("flags (zero if no unicode table): %d\n", psf.flags);
  37. printf("glyphs count: %d\n", psf.glyphs_count);
  38. printf("glyph size (byte): %d\n", psf.glyph_size);
  39. printf("height: %d, width: %d\n", psf.height, psf.width);
  40. close(fd);
  41. return 0;
  42. }