[wiki] [sites] [st][ligatures] Minor fixes: * Improved code style in accordance to Suckless guide. * Fixed compatibility with alpha patch. || Alexander Rogachev

From: <git_AT_suckless.org>
Date: Sun, 19 Apr 2020 14:21:35 +0200

commit cdab8ad225cd4cbd831a283996ea7402d0da9819
Author: Alexander Rogachev <sorryforbadname_AT_gmail.com>
Date: Sun Apr 19 15:18:58 2020 +0300

    [st][ligatures] Minor fixes:
      * Improved code style in accordance to Suckless guide.
      * Fixed compatibility with alpha patch.

diff --git a/st.suckless.org/patches/ligatures/st-ligatures-20200406-28ad288.diff b/st.suckless.org/patches/ligatures/st-ligatures-20200406-28ad288.diff
index 8bb26e64..5d4198a8 100644
--- a/st.suckless.org/patches/ligatures/st-ligatures-20200406-28ad288.diff
+++ b/st.suckless.org/patches/ligatures/st-ligatures-20200406-28ad288.diff
_AT_@ -45,7 +45,7 @@ new file mode 100644
 index 0000000..bb0bea8
 --- /dev/null
 +++ b/hb.c
-_AT_@ -0,0 +1,128 @@
+_AT_@ -0,0 +1,136 @@
 +#include <stdlib.h>
 +#include <stdio.h>
 +#include <math.h>
_AT_@ -66,7 +66,9 @@ index 0000000..bb0bea8
 +static int hbfontslen = 0;
 +static HbFontMatch *hbfontcache = NULL;
 +
-+void hbunloadfonts() {
++void
++hbunloadfonts()
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + hb_font_destroy(hbfontcache[i].font);
 + XftUnlockFace(hbfontcache[i].match);
_AT_@ -79,13 +81,15 @@ index 0000000..bb0bea8
 + hbfontslen = 0;
 +}
 +
-+hb_font_t *hbfindfont(XftFont *match) {
++hb_font_t *
++hbfindfont(XftFont *match)
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + if (hbfontcache[i].match == match)
 + return hbfontcache[i].font;
 + }
 +
-+ // Font not found in cache, caching it now.
++ /* Font not found in cache, caching it now. */
 + hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1));
 + FT_Face face = XftLockFace(match);
 + hb_font_t *font = hb_ft_font_create(face, NULL);
_AT_@ -99,7 +103,9 @@ index 0000000..bb0bea8
 + return font;
 +}
 +
-+void hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y) {
++void
++hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
++{
 + int start = 0, length = 1, gstart = 0;
 + hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
 +
_AT_@ -112,7 +118,7 @@ index 0000000..bb0bea8
 + if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) {
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Reset the sequence.
++ /* Reset the sequence. */
 + length = 1;
 + start = specidx;
 + gstart = idx;
_AT_@ -123,10 +129,10 @@ index 0000000..bb0bea8
 + specidx++;
 + }
 +
-+ // EOL.
++ /* EOL. */
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Apply the transformation to glyph specs.
++ /* Apply the transformation to glyph specs. */
 + for (int i = 0, specidx = 0; i < len; i++) {
 + if (glyphs[i].mode & ATTR_WDUMMY)
 + continue;
_AT_@ -140,7 +146,9 @@ index 0000000..bb0bea8
 + free(codepoints);
 +}
 +
-+void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) {
++void
++hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length)
++{
 + hb_font_t *font = hbfindfont(xfont);
 + if (font == NULL)
 + return;
_AT_@ -150,7 +158,7 @@ index 0000000..bb0bea8
 + hb_buffer_t *buffer = hb_buffer_create();
 + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
 +
-+ // Fill buffer with codepoints.
++ /* Fill buffer with codepoints. */
 + for (int i = start; i < (start+length); i++) {
 + rune = string[i].u;
 + mode = string[i].mode;
_AT_@ -159,19 +167,19 @@ index 0000000..bb0bea8
 + hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1);
 + }
 +
-+ // Shape the segment.
++ /* Shape the segment. */
 + hb_shape(font, buffer, NULL, 0);
 +
-+ // Get new glyph info.
++ /* Get new glyph info. */
 + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL);
 +
-+ // Write new codepoints.
++ /* Write new codepoints. */
 + for (int i = 0; i < length; i++) {
 + hb_codepoint_t gid = info[i].codepoint;
 + codepoints[start+i] = gid;
 + }
 +
-+ // Cleanup.
++ /* Cleanup. */
 + hb_buffer_destroy(buffer);
 +}
 diff --git a/hb.h b/hb.h
_AT_@ -185,7 +193,7 @@ index 0000000..a209238
 +#include <hb-ft.h>
 +
 +void hbunloadfonts();
-+void hbtransform(XftGlyphFontSpec *, const Glyph *, int, int, int);
++void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int);
 +
 diff --git a/st.c b/st.c
 index 3e48410..073e4c7 100644
_AT_@ -195,12 +203,12 @@ index 3e48410..073e4c7 100644
                  cx--;
  
          drawregion(0, 0, term.col, term.row);
-+ // Draw current line to format ligatures properly.
++ /* Draw current line to format ligatures properly. */
 + xdrawline(term.line[term.c.y], 0, term.c.y, term.col);
 +
          xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
                          term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
-+ // If cursor was on a transformed glyph, we need to redraw the previous line
++ /* If cursor was on a transformed glyph, we need to redraw the previous line. */
 + if (term.ocy != term.c.y && (term.line[term.ocy][term.ocx].mode & ATTR_LIGA))
 + xdrawline(term.line[term.ocy], 0, term.ocy, term.col);
          term.ocx = cx, term.ocy = term.c.y;
_AT_@ -244,7 +252,7 @@ index 4cf6b21..447f475 100644
  void
  xunloadfonts(void)
  {
-+ /* Clear Harfbuzz font cache */
++ /* Clear Harfbuzz font cache. */
 + hbunloadfonts();
 +
          /* Free the loaded fonts in the font cache. */
_AT_@ -263,7 +271,7 @@ index 4cf6b21..447f475 100644
                  numspecs++;
          }
  
-+ // Harfbuzz transformation for ligatures.
++ /* Harfbuzz transformation for ligatures. */
 + hbtransform(specs, glyphs, len, x, y);
 +
          return numspecs;
diff --git a/st.suckless.org/patches/ligatures/st-ligatures-alpha-20200406-28ad288.diff b/st.suckless.org/patches/ligatures/st-ligatures-alpha-20200406-28ad288.diff
index fb0a29ab..ed830712 100644
--- a/st.suckless.org/patches/ligatures/st-ligatures-alpha-20200406-28ad288.diff
+++ b/st.suckless.org/patches/ligatures/st-ligatures-alpha-20200406-28ad288.diff
_AT_@ -32,7 +32,7 @@ index 0cbb002..76c5c4f 100644
 - `$(PKG_CONFIG) --cflags freetype2`
 + `$(PKG_CONFIG) --cflags freetype2` \
 + `$(PKG_CONFIG) --cflags harfbuzz`
- LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender \
+ LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
         `$(PKG_CONFIG) --libs fontconfig` \
 - `$(PKG_CONFIG) --libs freetype2`
 + `$(PKG_CONFIG) --libs freetype2` \
_AT_@ -45,7 +45,7 @@ new file mode 100644
 index 0000000..bb0bea8
 --- /dev/null
 +++ b/hb.c
-_AT_@ -0,0 +1,128 @@
+_AT_@ -0,0 +1,136 @@
 +#include <stdlib.h>
 +#include <stdio.h>
 +#include <math.h>
_AT_@ -66,7 +66,9 @@ index 0000000..bb0bea8
 +static int hbfontslen = 0;
 +static HbFontMatch *hbfontcache = NULL;
 +
-+void hbunloadfonts() {
++void
++hbunloadfonts()
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + hb_font_destroy(hbfontcache[i].font);
 + XftUnlockFace(hbfontcache[i].match);
_AT_@ -79,13 +81,15 @@ index 0000000..bb0bea8
 + hbfontslen = 0;
 +}
 +
-+hb_font_t *hbfindfont(XftFont *match) {
++hb_font_t *
++hbfindfont(XftFont *match)
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + if (hbfontcache[i].match == match)
 + return hbfontcache[i].font;
 + }
 +
-+ // Font not found in cache, caching it now.
++ /* Font not found in cache, caching it now. */
 + hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1));
 + FT_Face face = XftLockFace(match);
 + hb_font_t *font = hb_ft_font_create(face, NULL);
_AT_@ -99,7 +103,9 @@ index 0000000..bb0bea8
 + return font;
 +}
 +
-+void hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y) {
++void
++hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
++{
 + int start = 0, length = 1, gstart = 0;
 + hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
 +
_AT_@ -112,7 +118,7 @@ index 0000000..bb0bea8
 + if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) {
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Reset the sequence.
++ /* Reset the sequence. */
 + length = 1;
 + start = specidx;
 + gstart = idx;
_AT_@ -123,10 +129,10 @@ index 0000000..bb0bea8
 + specidx++;
 + }
 +
-+ // EOL.
++ /* EOL. */
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Apply the transformation to glyph specs.
++ /* Apply the transformation to glyph specs. */
 + for (int i = 0, specidx = 0; i < len; i++) {
 + if (glyphs[i].mode & ATTR_WDUMMY)
 + continue;
_AT_@ -140,7 +146,9 @@ index 0000000..bb0bea8
 + free(codepoints);
 +}
 +
-+void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) {
++void
++hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length)
++{
 + hb_font_t *font = hbfindfont(xfont);
 + if (font == NULL)
 + return;
_AT_@ -150,7 +158,7 @@ index 0000000..bb0bea8
 + hb_buffer_t *buffer = hb_buffer_create();
 + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
 +
-+ // Fill buffer with codepoints.
++ /* Fill buffer with codepoints. */
 + for (int i = start; i < (start+length); i++) {
 + rune = string[i].u;
 + mode = string[i].mode;
_AT_@ -159,19 +167,19 @@ index 0000000..bb0bea8
 + hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1);
 + }
 +
-+ // Shape the segment.
++ /* Shape the segment. */
 + hb_shape(font, buffer, NULL, 0);
 +
-+ // Get new glyph info.
++ /* Get new glyph info. */
 + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL);
 +
-+ // Write new codepoints.
++ /* Write new codepoints. */
 + for (int i = 0; i < length; i++) {
 + hb_codepoint_t gid = info[i].codepoint;
 + codepoints[start+i] = gid;
 + }
 +
-+ // Cleanup.
++ /* Cleanup. */
 + hb_buffer_destroy(buffer);
 +}
 diff --git a/hb.h b/hb.h
_AT_@ -185,7 +193,7 @@ index 0000000..a209238
 +#include <hb-ft.h>
 +
 +void hbunloadfonts();
-+void hbtransform(XftGlyphFontSpec *, const Glyph *, int, int, int);
++void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int);
 +
 diff --git a/st.c b/st.c
 index 3e48410..073e4c7 100644
_AT_@ -195,12 +203,12 @@ index 3e48410..073e4c7 100644
                  cx--;
  
          drawregion(0, 0, term.col, term.row);
-+ // Draw current line to format ligatures properly.
++ /* Draw current line to format ligatures properly. */
 + xdrawline(term.line[term.c.y], 0, term.c.y, term.col);
 +
          xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
                          term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
-+ // If cursor was on a transformed glyph, we need to redraw the previous line
++ /* If cursor was on a transformed glyph, we need to redraw the previous line.*/
 + if (term.ocy != term.c.y && (term.line[term.ocy][term.ocx].mode & ATTR_LIGA))
 + xdrawline(term.line[term.ocy], 0, term.ocy, term.col);
          term.ocx = cx, term.ocy = term.c.y;
_AT_@ -244,7 +252,7 @@ index 4cf6b21..447f475 100644
  void
  xunloadfonts(void)
  {
-+ /* Clear Harfbuzz font cache */
++ /* Clear Harfbuzz font cache. */
 + hbunloadfonts();
 +
          /* Free the loaded fonts in the font cache. */
_AT_@ -263,9 +271,9 @@ index 4cf6b21..447f475 100644
                  numspecs++;
          }
  
-+ // Harfbuzz transformation for ligatures.
++ /* Harfbuzz transformation for ligatures. */
 + hbtransform(specs, glyphs, len, x, y);
 +
          return numspecs;
  }
-
+
diff --git a/st.suckless.org/patches/ligatures/st-ligatures-alpha-scrollback-20200406-28ad288.diff b/st.suckless.org/patches/ligatures/st-ligatures-alpha-scrollback-20200406-28ad288.diff
index e878bde9..08f280d3 100644
--- a/st.suckless.org/patches/ligatures/st-ligatures-alpha-scrollback-20200406-28ad288.diff
+++ b/st.suckless.org/patches/ligatures/st-ligatures-alpha-scrollback-20200406-28ad288.diff
_AT_@ -32,7 +32,7 @@ index 0cbb002..76c5c4f 100644
 - `$(PKG_CONFIG) --cflags freetype2`
 + `$(PKG_CONFIG) --cflags freetype2` \
 + `$(PKG_CONFIG) --cflags harfbuzz`
- LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender \
+ LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
         `$(PKG_CONFIG) --libs fontconfig` \
 - `$(PKG_CONFIG) --libs freetype2`
 + `$(PKG_CONFIG) --libs freetype2` \
_AT_@ -45,7 +45,7 @@ new file mode 100644
 index 0000000..bd3fb71
 --- /dev/null
 +++ b/hb.c
-_AT_@ -0,0 +1,128 @@
+_AT_@ -0,0 +1,136 @@
 +#include <stdlib.h>
 +#include <stdio.h>
 +#include <math.h>
_AT_@ -66,7 +66,9 @@ index 0000000..bd3fb71
 +static int hbfontslen = 0;
 +static HbFontMatch *hbfontcache = NULL;
 +
-+void hbunloadfonts() {
++void
++hbunloadfonts()
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + hb_font_destroy(hbfontcache[i].font);
 + XftUnlockFace(hbfontcache[i].match);
_AT_@ -79,13 +81,15 @@ index 0000000..bd3fb71
 + hbfontslen = 0;
 +}
 +
-+hb_font_t *hbfindfont(XftFont *match) {
++hb_font_t *
++hbfindfont(XftFont *match)
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + if (hbfontcache[i].match == match)
 + return hbfontcache[i].font;
 + }
 +
-+ // Font not found in cache, caching it now.
++ /* Font not found in cache, caching it now. */
 + hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1));
 + FT_Face face = XftLockFace(match);
 + hb_font_t *font = hb_ft_font_create(face, NULL);
_AT_@ -99,7 +103,9 @@ index 0000000..bd3fb71
 + return font;
 +}
 +
-+void hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y) {
++void
++hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
++{
 + int start = 0, length = 1, gstart = 0;
 + hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
 +
_AT_@ -112,7 +118,7 @@ index 0000000..bd3fb71
 + if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) {
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Reset the sequence.
++ /* Reset the sequence. */
 + length = 1;
 + start = specidx;
 + gstart = idx;
_AT_@ -123,10 +129,10 @@ index 0000000..bd3fb71
 + specidx++;
 + }
 +
-+ // EOL.
++ /* EOL. */
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Apply the transformation to glyph specs.
++ /* Apply the transformation to glyph specs. */
 + for (int i = 0, specidx = 0; i < len; i++) {
 + if (glyphs[i].mode & ATTR_WDUMMY)
 + continue;
_AT_@ -140,7 +146,9 @@ index 0000000..bd3fb71
 + free(codepoints);
 +}
 +
-+void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) {
++void
++hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length)
++{
 + hb_font_t *font = hbfindfont(xfont);
 + if (font == NULL)
 + return;
_AT_@ -150,7 +158,7 @@ index 0000000..bd3fb71
 + hb_buffer_t *buffer = hb_buffer_create();
 + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
 +
-+ // Fill buffer with codepoints.
++ /* Fill buffer with codepoints. */
 + for (int i = start; i < (start+length); i++) {
 + rune = string[i].u;
 + mode = string[i].mode;
_AT_@ -159,19 +167,19 @@ index 0000000..bd3fb71
 + hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1);
 + }
 +
-+ // Shape the segment.
++ /* Shape the segment. */
 + hb_shape(font, buffer, NULL, 0);
 +
-+ // Get new glyph info.
++ /* Get new glyph info. */
 + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL);
 +
-+ // Write new codepoints.
++ /* Write new codepoints. */
 + for (int i = 0; i < length; i++) {
 + hb_codepoint_t gid = info[i].codepoint;
 + codepoints[start+i] = gid;
 + }
 +
-+ // Cleanup.
++ /* Cleanup. */
 + hb_buffer_destroy(buffer);
 +}
 diff --git a/hb.h b/hb.h
_AT_@ -185,7 +193,7 @@ index 0000000..4505444
 +#include <hb-ft.h>
 +
 +void hbunloadfonts();
-+void hbtransform(XftGlyphFontSpec *, const Glyph *, int, int, int);
++void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int);
 +
 diff --git a/st.c b/st.c
 index 130bf22..07b2f3b 100644
_AT_@ -199,13 +207,13 @@ index 130bf22..07b2f3b 100644
 - xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
 - term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
 + if (term.scr == 0) {
-+ // Draw current line to format ligatures properly.
++ /* Draw current line to format ligatures properly. */
 + xdrawline(term.line[term.c.y], 0, term.c.y, term.col);
 +
 + xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
 + term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
 +
-+ // If cursor was on a transformed glyph, we need to redraw the previous line
++ /* If cursor was on a transformed glyph, we need to redraw the previous line. */
 + if (term.ocy != term.c.y && (term.line[term.ocy][term.ocx].mode & ATTR_LIGA))
 + xdrawline(term.line[term.ocy], 0, term.ocy, term.col);
 + }
_AT_@ -250,7 +258,7 @@ index 4cf6b21..f6b09da 100644
  void
  xunloadfonts(void)
  {
-+ /* Clear Harfbuzz font cache */
++ /* Clear Harfbuzz font cache. */
 + hbunloadfonts();
 +
          /* Free the loaded fonts in the font cache. */
_AT_@ -269,7 +277,7 @@ index 4cf6b21..f6b09da 100644
                  numspecs++;
          }
  
-+ // Harfbuzz transformation for ligatures.
++ /* Harfbuzz transformation for ligatures. */
 + hbtransform(specs, glyphs, len, x, y);
 +
          return numspecs;
diff --git a/st.suckless.org/patches/ligatures/st-ligatures-boxdraw-20200407-28ad288.diff b/st.suckless.org/patches/ligatures/st-ligatures-boxdraw-20200407-28ad288.diff
index 86d8e8b1..99057ce7 100644
--- a/st.suckless.org/patches/ligatures/st-ligatures-boxdraw-20200407-28ad288.diff
+++ b/st.suckless.org/patches/ligatures/st-ligatures-boxdraw-20200407-28ad288.diff
_AT_@ -45,7 +45,7 @@ new file mode 100644
 index 0000000..bb0bea8
 --- /dev/null
 +++ b/hb.c
-_AT_@ -0,0 +1,132 @@
+_AT_@ -0,0 +1,140 @@
 +#include <stdlib.h>
 +#include <stdio.h>
 +#include <math.h>
_AT_@ -66,7 +66,9 @@ index 0000000..bb0bea8
 +static int hbfontslen = 0;
 +static HbFontMatch *hbfontcache = NULL;
 +
-+void hbunloadfonts() {
++void
++hbunloadfonts()
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + hb_font_destroy(hbfontcache[i].font);
 + XftUnlockFace(hbfontcache[i].match);
_AT_@ -79,13 +81,15 @@ index 0000000..bb0bea8
 + hbfontslen = 0;
 +}
 +
-+hb_font_t *hbfindfont(XftFont *match) {
++hb_font_t *
++hbfindfont(XftFont *match)
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + if (hbfontcache[i].match == match)
 + return hbfontcache[i].font;
 + }
 +
-+ // Font not found in cache, caching it now.
++ /* Font not found in cache, caching it now. */
 + hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1));
 + FT_Face face = XftLockFace(match);
 + hb_font_t *font = hb_ft_font_create(face, NULL);
_AT_@ -99,7 +103,9 @@ index 0000000..bb0bea8
 + return font;
 +}
 +
-+void hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y) {
++void
++hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
++{
 + int start = 0, length = 1, gstart = 0;
 + hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
 +
_AT_@ -112,7 +118,7 @@ index 0000000..bb0bea8
 + if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) {
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Reset the sequence.
++ /* Reset the sequence. */
 + length = 1;
 + start = specidx;
 + gstart = idx;
_AT_@ -123,10 +129,10 @@ index 0000000..bb0bea8
 + specidx++;
 + }
 +
-+ // EOL.
++ /* EOL. */
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Apply the transformation to glyph specs.
++ /* Apply the transformation to glyph specs. */
 + for (int i = 0, specidx = 0; i < len; i++) {
 + if (glyphs[i].mode & ATTR_WDUMMY)
 + continue;
_AT_@ -144,7 +150,9 @@ index 0000000..bb0bea8
 + free(codepoints);
 +}
 +
-+void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) {
++void
++hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length)
++{
 + hb_font_t *font = hbfindfont(xfont);
 + if (font == NULL)
 + return;
_AT_@ -154,7 +162,7 @@ index 0000000..bb0bea8
 + hb_buffer_t *buffer = hb_buffer_create();
 + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
 +
-+ // Fill buffer with codepoints.
++ /* Fill buffer with codepoints. */
 + for (int i = start; i < (start+length); i++) {
 + rune = string[i].u;
 + mode = string[i].mode;
_AT_@ -163,19 +171,19 @@ index 0000000..bb0bea8
 + hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1);
 + }
 +
-+ // Shape the segment.
++ /* Shape the segment. */
 + hb_shape(font, buffer, NULL, 0);
 +
-+ // Get new glyph info.
++ /* Get new glyph info. */
 + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL);
 +
-+ // Write new codepoints.
++ /* Write new codepoints. */
 + for (int i = 0; i < length; i++) {
 + hb_codepoint_t gid = info[i].codepoint;
 + codepoints[start+i] = gid;
 + }
 +
-+ // Cleanup.
++ /* Cleanup. */
 + hb_buffer_destroy(buffer);
 +}
 diff --git a/hb.h b/hb.h
_AT_@ -189,7 +197,7 @@ index 0000000..a209238
 +#include <hb-ft.h>
 +
 +void hbunloadfonts();
-+void hbtransform(XftGlyphFontSpec *, const Glyph *, int, int, int);
++void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int);
 +
 diff --git a/st.c b/st.c
 index 3e48410..073e4c7 100644
_AT_@ -199,12 +207,12 @@ index 3e48410..073e4c7 100644
                  cx--;
  
          drawregion(0, 0, term.col, term.row);
-+ // Draw current line to format ligatures properly.
++ /* Draw current line to format ligatures properly. */
 + xdrawline(term.line[term.c.y], 0, term.c.y, term.col);
 +
          xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
                          term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
-+ // If cursor was on a transformed glyph, we need to redraw the previous line
++ /* If cursor was on a transformed glyph, we need to redraw the previous line. */
 + if (term.ocy != term.c.y && (term.line[term.ocy][term.ocx].mode & ATTR_LIGA))
 + xdrawline(term.line[term.ocy], 0, term.ocy, term.col);
          term.ocx = cx, term.ocy = term.c.y;
_AT_@ -249,7 +257,7 @@ index 4cf6b21..447f475 100644
  void
  xunloadfonts(void)
  {
-+ /* Clear Harfbuzz font cache */
++ /* Clear Harfbuzz font cache. */
 + hbunloadfonts();
 +
          /* Free the loaded fonts in the font cache. */
_AT_@ -268,7 +276,7 @@ index 4cf6b21..447f475 100644
                  numspecs++;
          }
  
-+ // Harfbuzz transformation for ligatures.
++ /* Harfbuzz transformation for ligatures. */
 + hbtransform(specs, glyphs, len, x, y);
 +
          return numspecs;
diff --git a/st.suckless.org/patches/ligatures/st-ligatures-scrollback-20200406-28ad288.diff b/st.suckless.org/patches/ligatures/st-ligatures-scrollback-20200406-28ad288.diff
index 439b63c8..c65ff7c9 100644
--- a/st.suckless.org/patches/ligatures/st-ligatures-scrollback-20200406-28ad288.diff
+++ b/st.suckless.org/patches/ligatures/st-ligatures-scrollback-20200406-28ad288.diff
_AT_@ -45,7 +45,7 @@ new file mode 100644
 index 0000000..bd3fb71
 --- /dev/null
 +++ b/hb.c
-_AT_@ -0,0 +1,128 @@
+_AT_@ -0,0 +1,136 @@
 +#include <stdlib.h>
 +#include <stdio.h>
 +#include <math.h>
_AT_@ -66,7 +66,9 @@ index 0000000..bd3fb71
 +static int hbfontslen = 0;
 +static HbFontMatch *hbfontcache = NULL;
 +
-+void hbunloadfonts() {
++void
++hbunloadfonts()
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + hb_font_destroy(hbfontcache[i].font);
 + XftUnlockFace(hbfontcache[i].match);
_AT_@ -79,13 +81,15 @@ index 0000000..bd3fb71
 + hbfontslen = 0;
 +}
 +
-+hb_font_t *hbfindfont(XftFont *match) {
++hb_font_t *
++hbfindfont(XftFont *match)
++{
 + for (int i = 0; i < hbfontslen; i++) {
 + if (hbfontcache[i].match == match)
 + return hbfontcache[i].font;
 + }
 +
-+ // Font not found in cache, caching it now.
++ /* Font not found in cache, caching it now. */
 + hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1));
 + FT_Face face = XftLockFace(match);
 + hb_font_t *font = hb_ft_font_create(face, NULL);
_AT_@ -99,7 +103,9 @@ index 0000000..bd3fb71
 + return font;
 +}
 +
-+void hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y) {
++void
++hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
++{
 + int start = 0, length = 1, gstart = 0;
 + hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
 +
_AT_@ -112,7 +118,7 @@ index 0000000..bd3fb71
 + if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) {
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Reset the sequence.
++ /* Reset the sequence. */
 + length = 1;
 + start = specidx;
 + gstart = idx;
_AT_@ -123,10 +129,10 @@ index 0000000..bd3fb71
 + specidx++;
 + }
 +
-+ // EOL.
++ /* EOL. */
 + hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
 +
-+ // Apply the transformation to glyph specs.
++ /* Apply the transformation to glyph specs. */
 + for (int i = 0, specidx = 0; i < len; i++) {
 + if (glyphs[i].mode & ATTR_WDUMMY)
 + continue;
_AT_@ -140,7 +146,9 @@ index 0000000..bd3fb71
 + free(codepoints);
 +}
 +
-+void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) {
++void
++hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length)
++{
 + hb_font_t *font = hbfindfont(xfont);
 + if (font == NULL)
 + return;
_AT_@ -150,7 +158,7 @@ index 0000000..bd3fb71
 + hb_buffer_t *buffer = hb_buffer_create();
 + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
 +
-+ // Fill buffer with codepoints.
++ /* Fill buffer with codepoints. */
 + for (int i = start; i < (start+length); i++) {
 + rune = string[i].u;
 + mode = string[i].mode;
_AT_@ -159,19 +167,19 @@ index 0000000..bd3fb71
 + hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1);
 + }
 +
-+ // Shape the segment.
++ /* Shape the segment. */
 + hb_shape(font, buffer, NULL, 0);
 +
-+ // Get new glyph info.
++ /* Get new glyph info. */
 + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL);
 +
-+ // Write new codepoints.
++ /* Write new codepoints. */
 + for (int i = 0; i < length; i++) {
 + hb_codepoint_t gid = info[i].codepoint;
 + codepoints[start+i] = gid;
 + }
 +
-+ // Cleanup.
++ /* Cleanup. */
 + hb_buffer_destroy(buffer);
 +}
 diff --git a/hb.h b/hb.h
_AT_@ -185,7 +193,7 @@ index 0000000..4505444
 +#include <hb-ft.h>
 +
 +void hbunloadfonts();
-+void hbtransform(XftGlyphFontSpec *, const Glyph *, int, int, int);
++void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int);
 +
 diff --git a/st.c b/st.c
 index 130bf22..07b2f3b 100644
_AT_@ -199,13 +207,13 @@ index 130bf22..07b2f3b 100644
 - xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
 - term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
 + if (term.scr == 0) {
-+ // Draw current line to format ligatures properly.
++ /* Draw current line to format ligatures properly. */
 + xdrawline(term.line[term.c.y], 0, term.c.y, term.col);
 +
 + xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
 + term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
 +
-+ // If cursor was on a transformed glyph, we need to redraw the previous line
++ /* If cursor was on a transformed glyph, we need to redraw the previous line. */
 + if (term.ocy != term.c.y && (term.line[term.ocy][term.ocx].mode & ATTR_LIGA))
 + xdrawline(term.line[term.ocy], 0, term.ocy, term.col);
 + }
_AT_@ -250,7 +258,7 @@ index 4cf6b21..f6b09da 100644
  void
  xunloadfonts(void)
  {
-+ /* Clear Harfbuzz font cache */
++ /* Clear Harfbuzz font cache. */
 + hbunloadfonts();
 +
          /* Free the loaded fonts in the font cache. */
_AT_@ -269,7 +277,7 @@ index 4cf6b21..f6b09da 100644
                  numspecs++;
          }
  
-+ // Harfbuzz transformation for ligatures.
++ /* Harfbuzz transformation for ligatures. */
 + hbtransform(specs, glyphs, len, x, y);
 +
          return numspecs;
Received on Sun Apr 19 2020 - 14:21:35 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 19 2020 - 14:24:49 CEST