about summary refs log blame commit diff stats
path: root/font.c
blob: a6b822519ed6e957fe32dd27edbc2a4b82e491e8 (plain) (tree)







































                                                                             
                                                                             
































                                                                             
                                                                                   





                                                     
/*
 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

unsigned int
textwidth_l(BlitzFont *font, char *text, unsigned int len)
{
	if(font->set) {
		XRectangle r;
		XmbTextExtents(font->set, text, len, nil, &r);
		return r.width;
	}
	return XTextWidth(font->xfont, text, len);
}

unsigned int
textwidth(BlitzFont *font, char *text)
{
	return blitz_textwidth_l(font, text, strlen(text));
}

void
loadfont(Blitz *blitz, BlitzFont *font)
{
	char *fontname = font->fontstr;
	char **missing = nil, *def = "?";
	int n;

	setlocale(LC_ALL, "");
	if(font->set)
		XFreeFontSet(blitz->dpy, font->set);
	font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
	if(missing) {
		while(n--)
			fprintf(stderr, "missing fontset: %s\n", missing[n]);
		XFreeStringList(missing);
		if(font->set) {
			XFreeFontSet(blitz->dpy, font->set);
			font->set = nil;
		}
	}
	if(font->set) {
		XFontSetExtents *font_extents;
		XFontStruct **xfonts;
		char **font_names;
		unsigned int i;

		font->ascent = font->descent = 0;
		font_extents = XExtentsOfFontSet(font->set);
		n = XFontsOfFontSet(font->set, &xfonts, &font_names);
		for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
			if(font->ascent < (*xfonts)->ascent)
				font->ascent = (*xfonts)->ascent;
			if(font->descent < (*xfonts)->descent)
				font->descent = (*xfonts)->descent;
			xfonts++;
		}
	}
	else {
		if(font->xfont)
			XFreeFont(blitz->dpy, font->xfont);
		font->xfont = nil;
		font->xfont = XLoadQueryFont(blitz->dpy, fontname);
		if (!font->xfont) {
			fontname = "fixed";
			font->xfont = XLoadQueryFont(blitz->dpy, fontname);
		}
		if (!font->xfont) {
			fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
			exit(1);
		}
		font->ascent = font->xfont->ascent;
		font->descent = font->xfont->descent;
	}
}
/pre>
                                                                   
                                                                 
                                                              
                                                                              
                                                   
                                                                
                                                           




                                                               
                                  
                                                                     
                                                                
                                                 
                                                           
Console

   (X) #0   09/12/06  console commands
   (X) #1   09/12/06  quick find
   (X) #2   09/12/06  open with
   (X) #4   09/12/06  history for console
   (X) #13  09/12/27  display docstring of a command


General

   (X) #5   09/12/06  move code from fm into objects
   (X) #6   09/12/06  move main to __init__
   (X) #7   09/12/06  cooler titlebar
   (X) #8   09/12/17  Add operations to modify files/directories
   (X) #9   09/12/24  add a widget for managing running operations
   (X) #10  09/12/24  sorting
   (X) #11  09/12/27  filter
   (X) #12  09/12/27  jump through the list in a specific order
   (X) #14  09/12/29  make filelists inherit from pagers
   (X) #15  09/12/29  better way of running processes!!~
   (X) #16  10/01/01  list of bookmarks
   (X) #21  10/01/01  write help!
   (X) #22  10/01/03  add getopt options to change flags/mode
   (X) #29  10/01/06  add chmod command
   (X) #30  10/01/06  add a way to create symlinks
   ( ) #32  10/01/08  place the (hidden) cursor to a meaningful position
   (X) #34  10/01/09  display free disk space
   (X) #35  10/01/09  display disk usage of files in current directory
   ( ) #36  10/01/11  help coloring is terribly inefficient
   ( ) #37  10/01/13  better tab completion for OpenConsole
   ( ) #38  10/01/16  searching in pager
   ( ) #39  10/01/17  flushinput not always good
   (X) #42  10/01/17  memorize directory for `` when using :cd
   (X) #43  10/01/18  internally treat the bookmarks ` and ' the same
   ( ) #44  10/01/18  more error messages :P


Bugs

   (X) #17  10/01/01  why do bookmarks disappear sometimes?
   (X) #18  10/01/01  fix notify widget (by adding a LogView?)
   (X) #19  10/01/01  resizing after pressing g
   (X) #23  10/01/04  stop dir loading with ^C -> wont load anymore
   (X) #25  10/01/06  directories sometimes dont reload correctly
   (X) #26  10/01/06  :delete on symlinks of directories fails
   (X) #31  10/01/06  ^C breaks cd-after-exit by stopping sourced shell script
   ( ) #40  10/01/17  freeze with unavailable sshfs
   (X) #41  10/01/17  capital file extensions are not recognized
   ( ) #46  10/01/19  old username displayed after using su


Ideas

   ( ) #20  10/01/01  use inotify to monitor filesystem changes
   ( ) #24  10/01/06  progress bar
   (X) #27  10/01/06  hide bookmarks in list which contain hidden dir
   (X) #28  10/01/06  use regexp instead of string for searching
   ( ) #33  10/01/08  accelerate mousewheel speed
   ( ) #45  10/01/18  hooks for events like setting changes