File: strwidth.c

package info (click to toggle)
wily 0.13.42-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,820 kB
  • sloc: ansic: 25,541; perl: 580; sh: 415; makefile: 400; python: 30; exp: 17
file content (30 lines) | stat: -rw-r--r-- 460 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Copyright (c) 1992 AT&T - All rights reserved. */
#include <libc.h>
#include <libg.h>
#include "libgint.h"

long
strwidth(Font *f, char *s)
{
	int wid, twid;
	enum { Max = 128 };
	Rune cbuf[Max];
	unsigned short fbuf[Max];
	Rune r;

	twid = 0;
	while (*s)
	{
		if (cachechars(f, &s, cbuf, Max, &wid, fbuf) <= 0)
			s += chartorune(&r, s);
		else
			twid += wid;
	}
	return twid;
}

Point
strsize(Font *f, char *s)
{
	return Pt(strwidth(f, s), f->height);
}