vecfont.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <uefi.h>
  2. /* Scalable Screen Font (https://gitlab.com/bztsrc/scalable-font2) */
  3. #define SSFN_IMPLEMENTATION /* get the normal renderer implementation */
  4. #define SSFN_MAXLINES 4096 /* configure for static memory management */
  5. #include "ssfn.h"
  6. ssfn_buf_t dst = {0}; /* framebuffer properties */
  7. ssfn_t ctx = {0}; /* renderer context */
  8. /**
  9. * Display string using the SSFN library. This works with both bitmap and vector fonts
  10. */
  11. void printString(int x, int y, char *s)
  12. {
  13. int ret;
  14. dst.x = x; dst.y = y;
  15. while((ret = ssfn_render(&ctx, &dst, s)) > 0)
  16. s += ret;
  17. }
  18. /**
  19. * Display vector fonts
  20. */
  21. int main(int argc, char **argv)
  22. {
  23. efi_status_t status;
  24. efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  25. efi_gop_t *gop = NULL;
  26. FILE *f;
  27. ssfn_font_t *font;
  28. long int size;
  29. /* load font */
  30. if((f = fopen("\\0B_vecfont\\font.sfn", "r"))) {
  31. fseek(f, 0, SEEK_END);
  32. size = ftell(f);
  33. fseek(f, 0, SEEK_SET);
  34. font = (ssfn_font_t*)malloc(size + 1);
  35. if(!font) {
  36. fprintf(stderr, "unable to allocate memory\n");
  37. return 1;
  38. }
  39. fread(font, size, 1, f);
  40. fclose(f);
  41. ssfn_load(&ctx, font);
  42. } else {
  43. fprintf(stderr, "Unable to load font\n");
  44. return 0;
  45. }
  46. /* set video mode */
  47. status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
  48. if(!EFI_ERROR(status) && gop) {
  49. status = gop->SetMode(gop, 0);
  50. ST->ConOut->Reset(ST->ConOut, 0);
  51. ST->StdErr->Reset(ST->StdErr, 0);
  52. if(EFI_ERROR(status)) {
  53. fprintf(stderr, "unable to set video mode\n");
  54. return 0;
  55. }
  56. /* set up destination buffer */
  57. dst.ptr = (unsigned char*)gop->Mode->FrameBufferBase;
  58. dst.w = gop->Mode->Information->HorizontalResolution;
  59. dst.h = gop->Mode->Information->VerticalResolution;
  60. dst.p = sizeof(unsigned int) * gop->Mode->Information->PixelsPerScanLine;
  61. dst.fg = 0xFFFFFFFF;
  62. } else {
  63. fprintf(stderr, "unable to get graphics output protocol\n");
  64. return 0;
  65. }
  66. /* select typeface to use */
  67. ssfn_select(&ctx, SSFN_FAMILY_ANY, NULL, SSFN_STYLE_REGULAR | SSFN_STYLE_NOCACHE, 40);
  68. /* display multilingual text */
  69. printString(10, ctx.size, "Hello! Здравствуйте! Καλως ηρθες!");
  70. /* free resources exit */
  71. ssfn_free(&ctx);
  72. free(font);
  73. return 0;
  74. }