Fix two bugs related to command execution:
[dockapps.git] / wmweather+ / font.c
bloba815b25ddafd57fd9c21b895c7da27e7811bb9af
1 #include "config.h"
3 /* Copyright (C) 2002 Brad Jorsch <anomie@users.sourceforge.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <string.h>
21 #include <ctype.h>
23 #include <X11/Xlib.h>
24 #include <X11/xpm.h>
26 #include "font.h"
28 #include "wmgeneral/wmgeneral-x11.h"
29 extern XpmIcon wmgen;
30 extern GC NormalGC;
31 extern Window Root;
33 #include "characters.xpm"
35 static Pixmap fonts[3]={ None, None, None };
36 static char *colors[3][4]={
37 { "#000000", "#0C4E66", "#127599", "#1EC3FF" },
38 { "#000000", "#664D0B", "#997411", "#FFC21D" },
39 { "#000000", "#662B31", "#99414A", "#FF6D7B" }
42 void init_font(int i){
43 XpmIcon x;
44 XpmColorSymbol cols[4]={
45 {"Background", NULL, 0},
46 {"Low", NULL, 0},
47 {"Mid", NULL, 0},
48 {"High", NULL, 0}
50 int j;
52 if(fonts[i]!=None) return;
53 for(j=0; j<4; j++){
54 cols[j].pixel=GetColor(colors[i][j]);
56 x.attributes.numsymbols=5;
57 x.attributes.colorsymbols=cols;
58 x.attributes.exactColors=False;
59 x.attributes.closeness=40000;
60 x.attributes.valuemask=(XpmColorSymbols | XpmExactColors | XpmCloseness);
61 GetXPM(&x, characters_xpm);
62 fonts[i]=x.pixmap;
63 XFreePixmap(display, x.mask);
66 int DrawString(int x, int y, char *str, int font){
67 int w;
68 char *c;
70 w=0;
71 for(c=str; *c!='\0'; c++){
72 w+=DrawChar(x+w, y, *c, font);
73 w++;
76 return w-1;
79 int GetStringWidth(char *str){
80 int w;
81 char *c;
83 w=0;
84 for(c=str; *c!='\0'; c++){
85 w+=DrawChar(-1, -1, *c, -1);
86 w++;
89 return w-1;
92 int DrawNumber(int x, int y, int n, int font){
93 int w;
94 int flag=0;
95 char c;
97 if(n<0){
98 flag=1;
99 n=-n;
102 w=0;
103 do {
104 w+=3;
105 c='0'+(n%10);
106 DrawChar(x-w, y, c, font);
107 n/=10;
108 w++;
109 } while(n>0);
110 if(flag){
111 w+=2;
112 DrawChar(x-w, y, '-', font);
113 w++;
116 return w-1;
119 int DrawChar(int x, int y, char c, int font){
120 int sx, w;
122 c=toupper(c);
123 w=3;
124 if(c>='A' && c<='Z'){
125 sx=(c-'A')*4+1;
126 if(c=='M'){ w=4; sx=149; }
127 if(c=='N'){ w=4; sx=154; }
128 if(c=='W'){ w=4; sx=159; }
129 } else if(c>='0' && c<='9') sx=(c-'0')*4+105;
130 else if(c==':'){ w=1; sx=164; }
131 else if(c=='('){ w=2; sx=171; }
132 else if(c==')'){ w=2; sx=174; }
133 else if(c=='%') sx=89;
134 else if(c=='-'){ w=2; sx=168; }
135 else if(c=='.'){ w=1; sx=166; }
136 else if(c=='<') sx=49;
137 else if(c=='>') sx=53;
138 else if(c=='/') sx=145;
139 else if(c=='\''){ w=1; sx=177; }
140 else return 0;
142 if(x>=0 && y>=0 && x+w<192 && y<174 && font>=0 && font<3){
143 init_font(font);
144 XCopyArea(display, fonts[font], wmgen.pixmap, NormalGC, sx, 1, w, 5, x, y);
146 return w;