commit 93dfd2ced8dc537d2a667857f39b07bcc8307892
parent 6ffac25b7bc13b37867c6e52c6519389b46d951a
Author: lumidify <nobody@lumidify.org>
Date:   Tue, 28 Apr 2020 16:30:49 +0200
Fix Makefile; add pango test
Diffstat:
3 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,12 +1,12 @@
 LIBS = -lm `pkg-config --libs x11 harfbuzz fontconfig fribidi`
 STD = -std=c99
-CFLAGS = -g -w -fcommon -Wall -Werror -Wextra `pkg-config --cflags x11 harfbuzz fontconfig fribidi`#-pedantic
+CFLAGS = -g -w -fcommon -Wall -Werror -Wextra `pkg-config --cflags x11 harfbuzz fontconfig fribidi` -pedantic
 OBJ = stb_truetype.o text-hb.o ltk.o ini.o grid.o button.o test1.o
 
 test1: $(OBJ)
-	gcc $(STD) -o $@ $> $(CFLAGS) $(LIBS)
+	gcc $(STD) -o $@ $(OBJ) $(LIBS)
 
-%.o: %.c $(DEPS)
+%.o: %.c
 	$(CC) -c -o $@ $< $(CFLAGS)
 
 .PHONY: clean
diff --git a/text/Makefile b/text/Makefile
@@ -1,2 +1,2 @@
-all: text-hb.ubernew.c
-	gcc text-hb.uberubernew.c -g -std=c99 -o test `pkg-config --cflags --libs x11 harfbuzz` -lm
+all:
+	gcc tmp.c -g -std=c99 -o tmp `pkg-config --cflags --libs pangoxft` -lm
diff --git a/text/tmp.c b/text/tmp.c
@@ -0,0 +1,72 @@
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <pango/pangoxft.h>
+
+int main(int argc, const char * argv[])
+{
+
+    Display *display;
+    int screen;
+    Window window;
+    GC gc;
+
+    unsigned long black, white;
+    Colormap colormap;
+    display = XOpenDisplay((char *)0);
+    screen = DefaultScreen(display);
+    colormap = DefaultColormap(display, screen);
+    black = BlackPixel(display, screen);
+    white = WhitePixel(display, screen);
+    window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1366, 512, 0, black, white);
+    XSetStandardProperties(display, window, "Random Window", NULL, None, NULL, 0, NULL);
+    XSelectInput(display, window, ExposureMask|ButtonPressMask|KeyPressMask);
+    gc = XCreateGC(display, window, 0, 0);
+    XSetBackground(display, gc, black);
+    XSetForeground(display, gc, black);
+    XClearWindow(display, window);
+    XMapRaised(display, window);
+
+  PangoFontMap *fontmap = pango_xft_get_font_map(display, screen);
+  PangoContext *context = pango_font_map_create_context(fontmap);
+  PangoLayout *layout = pango_layout_new(context);
+  pango_layout_set_text (layout, "jhkashdfkashfaksjfla", -1);
+  /*PangoFontDescription *desc = pango_font_description_from_string ("Sans Bold 27");
+  pango_layout_set_font_description (layout, desc);
+  pango_font_description_free (desc);*/
+
+  XftDraw *draw = XftDrawCreate(display, window, DefaultVisual(display, screen), DefaultColormap(display, screen));
+  XftColor xftcolor;
+  XftColorAllocName(display, DefaultVisual(display, screen), colormap, "red", &xftcolor);
+  pango_xft_render_layout(draw, &xftcolor, layout, 0, 0);
+
+    XEvent event;
+    KeySym key;
+    char text[255];
+
+    while(1)
+    {
+        XNextEvent(display, &event);
+        if (event.type == KeyPress && XLookupString(&event.xkey, text, 255, &key, 0) == 1)
+        {
+	  pango_xft_render_layout(draw, &xftcolor, layout, 0, 0);
+            if (text[0] == 'q')
+            {
+                XFreeGC(display, gc);
+                XFreeColormap(display, colormap);
+                XDestroyWindow(display, window);
+                XCloseDisplay(display);
+                exit(0);
+            }
+        }
+    }
+
+  /* free the layout object */
+  g_object_unref (layout);
+
+    return 0;
+}