st/patches/0002-Apply-font2-on-st-vers...

168 lines
4.4 KiB
Diff
Raw Normal View History

2022-11-08 22:35:28 +03:00
From 2898f59f9b446b9ca748e544e61407e832ce5361 Mon Sep 17 00:00:00 2001
2020-07-18 13:54:54 +03:00
From: Shourai <10200748+Shourai@users.noreply.github.com>
2022-11-08 22:35:28 +03:00
Date: Tue, 8 Nov 2022 19:35:52 +0100
Subject: Apply font2 on st version 0.9
2020-07-18 13:54:54 +03:00
---
config.def.h | 10 ++++-
x.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
2022-11-08 22:35:28 +03:00
2 files changed, 110 insertions(+), 1 deletion(-)
2020-07-18 13:54:54 +03:00
diff --git a/config.def.h b/config.def.h
2022-11-08 22:35:28 +03:00
index 38e5154..2ac0781 100644
2020-07-18 13:54:54 +03:00
--- a/config.def.h
+++ b/config.def.h
@@ -5,7 +5,15 @@
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
-static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
+static char *font = "Jetbrains Mono:pixelsize=14:antialias=true:autohint=true";
+/* Spare fonts */
+static char *font2[] = {
2022-11-08 22:35:28 +03:00
+ "Droid Sans Mono:style=Regular:pixelsize=14:antialias=true:autohint=true",
+ "Menlo:style=Regular:pixelsize=14:antialias=true:autohint=true",
+ "Inconsolata for Powerline:pixelsize=14:antialias=true:autohint=true",
+ "Hack Nerd Font Mono:pixelsize=14:antialias=true:autohint=true",
2020-07-18 13:54:54 +03:00
+};
+
static int borderpx = 2;
/*
diff --git a/x.c b/x.c
2022-11-08 22:35:28 +03:00
index 8a65792..db17dcf 100644
2020-07-18 13:54:54 +03:00
--- a/x.c
+++ b/x.c
@@ -158,6 +158,8 @@ static void xhints(void);
static int xloadcolor(int, const char *, Color *);
static int xloadfont(Font *, FcPattern *);
2022-11-08 22:35:28 +03:00
static void xloadfonts(const char *, double);
2020-07-18 13:54:54 +03:00
+static int xloadsparefont(FcPattern *, int);
+static void xloadsparefonts(void);
static void xunloadfont(Font *);
static void xunloadfonts(void);
static void xsetenv(void);
@@ -308,6 +310,7 @@ zoomabs(const Arg *arg)
{
xunloadfonts();
xloadfonts(usedfont, arg->f);
+ xloadsparefonts();
cresize(0, 0);
redraw();
xhints();
2022-11-08 22:35:28 +03:00
@@ -1059,6 +1062,101 @@ xloadfonts(const char *fontstr, double fontsize)
2020-07-18 13:54:54 +03:00
FcPatternDestroy(pattern);
}
+int
+xloadsparefont(FcPattern *pattern, int flags)
+{
+ FcPattern *match;
+ FcResult result;
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ match = FcFontMatch(NULL, pattern, &result);
+ if (!match) {
+ return 1;
+ }
+
+ if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
+ FcPatternDestroy(match);
+ return 1;
+ }
+
+ frc[frclen].flags = flags;
+ /* Believe U+0000 glyph will present in each default font */
+ frc[frclen].unicodep = 0;
+ frclen++;
+
+ return 0;
+}
+
+void
+xloadsparefonts(void)
+{
+ FcPattern *pattern;
+ double sizeshift, fontval;
+ int fc;
+ char **fp;
+
+ if (frclen != 0)
+ die("can't embed spare fonts. cache isn't empty");
+
+ /* Calculate count of spare fonts */
+ fc = sizeof(font2) / sizeof(*font2);
+ if (fc == 0)
+ return;
+
+ /* Allocate memory for cache entries. */
+ if (frccap < 4 * fc) {
+ frccap += 4 * fc - frccap;
+ frc = xrealloc(frc, frccap * sizeof(Fontcache));
+ }
+
+ for (fp = font2; fp - font2 < fc; ++fp) {
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ if (**fp == '-')
+ pattern = XftXlfdParse(*fp, False, False);
+ else
+ pattern = FcNameParse((FcChar8 *)*fp);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ if (!pattern)
+ die("can't open spare font %s\n", *fp);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ if (defaultfontsize > 0) {
+ sizeshift = usedfontsize - defaultfontsize;
+ if (sizeshift != 0 &&
+ FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
2022-11-08 22:35:28 +03:00
+ FcResultMatch) {
2020-07-18 13:54:54 +03:00
+ fontval += sizeshift;
+ FcPatternDel(pattern, FC_PIXEL_SIZE);
+ FcPatternDel(pattern, FC_SIZE);
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
+ }
+ }
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ FcPatternAddBool(pattern, FC_SCALABLE, 1);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ FcConfigSubstitute(NULL, pattern, FcMatchPattern);
+ XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ if (xloadsparefont(pattern, FRC_NORMAL))
+ die("can't open spare font %s\n", *fp);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
+ if (xloadsparefont(pattern, FRC_ITALIC))
+ die("can't open spare font %s\n", *fp);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ FcPatternDel(pattern, FC_WEIGHT);
+ FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
+ if (xloadsparefont(pattern, FRC_ITALICBOLD))
+ die("can't open spare font %s\n", *fp);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
+ if (xloadsparefont(pattern, FRC_BOLD))
+ die("can't open spare font %s\n", *fp);
2022-11-08 22:35:28 +03:00
+
2020-07-18 13:54:54 +03:00
+ FcPatternDestroy(pattern);
+ }
+}
+
void
xunloadfont(Font *f)
{
2022-11-08 22:35:28 +03:00
@@ -1168,6 +1266,9 @@ xinit(int cols, int rows)
2020-07-18 13:54:54 +03:00
usedfont = (opt_font == NULL)? font : opt_font;
xloadfonts(usedfont, 0);
+ /* spare fonts */
+ xloadsparefonts();
+
/* colors */
xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols();
--
2022-11-08 22:35:28 +03:00
2.38.1
2020-07-18 13:54:54 +03:00