st-font2-0.8.5.diff 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. From 1635e04d3643dd4caa0c7c2043b585c6d7e4705f Mon Sep 17 00:00:00 2001
  2. From: Rizqi Nur Assyaufi <bandithijo@gmail.com>
  3. Date: Mon, 18 Jul 2022 01:15:45 +0800
  4. Subject: [PATCH] [st][patch][font2] Add patch for st-0.8.5
  5. ---
  6. config.def.h | 6 +++
  7. x.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
  8. 2 files changed, 107 insertions(+)
  9. diff --git a/config.def.h b/config.def.h
  10. index 91ab8ca..717b2f0 100644
  11. --- a/config.def.h
  12. +++ b/config.def.h
  13. @@ -6,6 +6,12 @@
  14. * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
  15. */
  16. static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
  17. +/* Spare fonts */
  18. +static char *font2[] = {
  19. +/* "Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true", */
  20. +/* "Hack Nerd Font Mono:pixelsize=11:antialias=true:autohint=true", */
  21. +};
  22. +
  23. static int borderpx = 2;
  24. /*
  25. diff --git a/x.c b/x.c
  26. index 8a16faa..220fc4f 100644
  27. --- a/x.c
  28. +++ b/x.c
  29. @@ -157,6 +157,8 @@ static void xhints(void);
  30. static int xloadcolor(int, const char *, Color *);
  31. static int xloadfont(Font *, FcPattern *);
  32. static void xloadfonts(const char *, double);
  33. +static int xloadsparefont(FcPattern *, int);
  34. +static void xloadsparefonts(void);
  35. static void xunloadfont(Font *);
  36. static void xunloadfonts(void);
  37. static void xsetenv(void);
  38. @@ -306,6 +308,7 @@ zoomabs(const Arg *arg)
  39. {
  40. xunloadfonts();
  41. xloadfonts(usedfont, arg->f);
  42. + xloadsparefonts();
  43. cresize(0, 0);
  44. redraw();
  45. xhints();
  46. @@ -1034,6 +1037,101 @@ xloadfonts(const char *fontstr, double fontsize)
  47. FcPatternDestroy(pattern);
  48. }
  49. +int
  50. +xloadsparefont(FcPattern *pattern, int flags)
  51. +{
  52. + FcPattern *match;
  53. + FcResult result;
  54. +
  55. + match = FcFontMatch(NULL, pattern, &result);
  56. + if (!match) {
  57. + return 1;
  58. + }
  59. +
  60. + if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
  61. + FcPatternDestroy(match);
  62. + return 1;
  63. + }
  64. +
  65. + frc[frclen].flags = flags;
  66. + /* Believe U+0000 glyph will present in each default font */
  67. + frc[frclen].unicodep = 0;
  68. + frclen++;
  69. +
  70. + return 0;
  71. +}
  72. +
  73. +void
  74. +xloadsparefonts(void)
  75. +{
  76. + FcPattern *pattern;
  77. + double sizeshift, fontval;
  78. + int fc;
  79. + char **fp;
  80. +
  81. + if (frclen != 0)
  82. + die("can't embed spare fonts. cache isn't empty");
  83. +
  84. + /* Calculate count of spare fonts */
  85. + fc = sizeof(font2) / sizeof(*font2);
  86. + if (fc == 0)
  87. + return;
  88. +
  89. + /* Allocate memory for cache entries. */
  90. + if (frccap < 4 * fc) {
  91. + frccap += 4 * fc - frccap;
  92. + frc = xrealloc(frc, frccap * sizeof(Fontcache));
  93. + }
  94. +
  95. + for (fp = font2; fp - font2 < fc; ++fp) {
  96. +
  97. + if (**fp == '-')
  98. + pattern = XftXlfdParse(*fp, False, False);
  99. + else
  100. + pattern = FcNameParse((FcChar8 *)*fp);
  101. +
  102. + if (!pattern)
  103. + die("can't open spare font %s\n", *fp);
  104. +
  105. + if (defaultfontsize > 0) {
  106. + sizeshift = usedfontsize - defaultfontsize;
  107. + if (sizeshift != 0 &&
  108. + FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
  109. + FcResultMatch) {
  110. + fontval += sizeshift;
  111. + FcPatternDel(pattern, FC_PIXEL_SIZE);
  112. + FcPatternDel(pattern, FC_SIZE);
  113. + FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
  114. + }
  115. + }
  116. +
  117. + FcPatternAddBool(pattern, FC_SCALABLE, 1);
  118. +
  119. + FcConfigSubstitute(NULL, pattern, FcMatchPattern);
  120. + XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
  121. +
  122. + if (xloadsparefont(pattern, FRC_NORMAL))
  123. + die("can't open spare font %s\n", *fp);
  124. +
  125. + FcPatternDel(pattern, FC_SLANT);
  126. + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
  127. + if (xloadsparefont(pattern, FRC_ITALIC))
  128. + die("can't open spare font %s\n", *fp);
  129. +
  130. + FcPatternDel(pattern, FC_WEIGHT);
  131. + FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
  132. + if (xloadsparefont(pattern, FRC_ITALICBOLD))
  133. + die("can't open spare font %s\n", *fp);
  134. +
  135. + FcPatternDel(pattern, FC_SLANT);
  136. + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
  137. + if (xloadsparefont(pattern, FRC_BOLD))
  138. + die("can't open spare font %s\n", *fp);
  139. +
  140. + FcPatternDestroy(pattern);
  141. + }
  142. +}
  143. +
  144. void
  145. xunloadfont(Font *f)
  146. {
  147. @@ -1131,6 +1229,9 @@ xinit(int cols, int rows)
  148. usedfont = (opt_font == NULL)? font : opt_font;
  149. xloadfonts(usedfont, 0);
  150. + /* spare fonts */
  151. + xloadsparefonts();
  152. +
  153. /* colors */
  154. xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
  155. xloadcols();
  156. --
  157. 2.37.1