string.c - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
string.c (1094B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <string.h>
3 #include <u.h>
4 #include <libg.h>
5 #include "libgint.h"
6
7 Point
8 string(Bitmap *b, Point p, XftFont *ft, char *s, Fcode f)
9 {
10 size_t length = strlen(s);
11 int x = p.x;
12 int y = p.y;
13
14 x = p.x;
15 y = p.y;
16 if (b->flag & SHIFT){
17 x -= b->r.min.x;
18 y -= b->r.min.y;
19 }
20 y += ft->ascent;
21
22 if (!b->fd)
23 b->fd = XftDrawCreate(_dpy, (Drawable)(b->id), DefaultVisual(_dpy, DefaultScreen(_dpy)), DefaultColormap(_dpy, DefaultScreen(_dpy)));
24 XftDrawStringUtf8(b->fd, &fontcolor, ft, x, y, (FcChar8 *)s, length);
25
26 x += strwidth(ft, s);
27
28 p.x = (b->flag & SHIFT) ? x + b->r.min.x : x;
29 p.x = x + b->r.min.x;
30 return p;
31 }
32
33
34 int64_t
35 strwidth(XftFont *f, char *s)
36 {
37 XGlyphInfo extents = {0};
38 XftTextExtentsUtf8(_dpy, f, (FcChar8 *)s, strlen(s), &extents);
39
40 return extents.xOff;
41 }
42
43 int64_t
44 charwidth(XftFont *f, wchar_t r)
45 {
46 char chars[MB_LEN_MAX + 1] = {0};
47
48 if (runetochar(chars, r) < 0)
49 return 0;
50
51 return strwidth(f, chars);
52 }