/[oroborus]/oroborus/src/i18n.c
ViewVC logotype

Diff of /oroborus/src/i18n.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by dreamind, Thu May 23 19:55:46 2002 UTC revision 1.2 by dreamind, Thu May 30 13:57:51 2002 UTC
# Line 30  Line 30 
30    
31  int use_fontset;  int use_fontset;
32    
33  int getFont(Display * dpy, MyFont * font, char *name)  int
34    getFont (Display * dpy, MyFont * font, char *name)
35  {  {
36      char **missing_list;    char **missing_list;
37      int missing_count;    int missing_count;
38      char *def_string;    char *def_string;
39      XFontStruct **fonts;    XFontStruct **fonts;
40      char **font_names;    char **font_names;
41      int i, ascent, descent, fnum;    int i, ascent, descent, fnum;
42      char *basename;    char *basename;
43    
44  #ifdef DEBUG  #ifdef DEBUG
45      printf("entering getFont\n");    printf ("entering getFont\n");
46      printf("font=%s\n", name);    printf ("font=%s\n", name);
47  #endif  #endif
48    
49      font->font = NULL;    font->font = NULL;
50      font->fontset = NULL;    font->fontset = NULL;
51    
52      if(use_fontset)    if (use_fontset)
53      {      {
54          basename = malloc(strlen(name) + 3);        basename = malloc (strlen (name) + 3);
55          if(basename)        if (basename)
56              sprintf(basename, "%s,*", name);          sprintf (basename, "%s,*", name);
57          else        else
58              basename = name;          basename = name;
59    
60          font->fontset =        font->fontset =
61              XCreateFontSet(dpy, basename, &missing_list, &missing_count,          XCreateFontSet (dpy, basename, &missing_list, &missing_count,
62                             &def_string);                          &def_string);
63          if(!font->fontset)        if (!font->fontset)
64              return False;          {
65              if (basename != name)
66          if(basename != name)              free (basename);
67              free(basename);            return False;
68            }
69          for(i = 0; i < missing_count; i++)  
70              fprintf(stderr, "Warning! Missing charset %s\n", missing_list[i]);        if (basename != name)
71            free (basename);
72          fnum = XFontsOfFontSet(font->fontset, &fonts, &font_names);  
73          for(i = 0, ascent = 0, descent = 0; i < fnum; i++)        for (i = 0; i < missing_count; i++)
74          {          fprintf (stderr, "Warning! Missing charset %s\n", missing_list[i]);
75              if(ascent < fonts[i]->ascent)  
76                  ascent = fonts[i]->ascent;        fnum = XFontsOfFontSet (font->fontset, &fonts, &font_names);
77              if(descent < fonts[i]->descent)        for (i = 0, ascent = 0, descent = 0; i < fnum; i++)
78                  descent = fonts[i]->descent;          {
79          }            if (ascent < fonts[i]->ascent)
80                ascent = fonts[i]->ascent;
81          font->height = ascent + descent;            if (descent < fonts[i]->descent)
82          font->ascent = ascent;              descent = fonts[i]->descent;
83          font->descent = descent;          }
84    
85          font->height = ascent + descent;
86          font->ascent = ascent;
87          font->descent = descent;
88      }      }
89      else    else
90      {      {
91          font->font = XLoadQueryFont(dpy, name);        font->font = XLoadQueryFont (dpy, name);
92          if(!font->font)        if (!font->font)
93          {          {
94              font->font = XLoadQueryFont(dpy, "fixed");            font->font = XLoadQueryFont (dpy, "fixed");
95              if(!font->font)            if (!font->font)
96                  return False;              return False;
97          }          }
98    
99          font->height = font->font->ascent + font->font->descent;        font->height = font->font->ascent + font->font->descent;
100          font->ascent = font->font->ascent;        font->ascent = font->font->ascent;
101          font->descent = font->font->descent;        font->descent = font->font->descent;
102      }      }
103    
104      return True;    return True;
105  }  }
106    
107  void freeFont(Display * dpy, MyFont * font)  void
108    freeFont (Display * dpy, MyFont * font)
109  {  {
110  #ifdef DEBUG  #ifdef DEBUG
111      printf("entering freeFont\n");    printf ("entering freeFont\n");
112  #endif  #endif
113    
114      if(use_fontset)    if (use_fontset)
115          XFreeFontSet(dpy, font->fontset);      XFreeFontSet (dpy, font->fontset);
116      else    else
117          XFreeFont(dpy, font->font);      XFreeFont (dpy, font->font);
118  }  }
119    
120  void drawString(Display * dpy, Drawable d, MyFont * font, GC gc, int x, int y,  void
121                  char *str)  drawString (Display * dpy, Drawable d, MyFont * font, GC gc, int x, int y,
122                char *str)
123  {  {
124  #ifdef DEBUG  #ifdef DEBUG
125      printf("entering drawString\n");    printf ("entering drawString\n");
126  #endif  #endif
127    
128      if(!str)    if (!str)
129          return;      return;
130    
131      if(use_fontset)    if (use_fontset)
132          XmbDrawString(dpy, d, font->fontset, gc, x, y, str, strlen(str));      XmbDrawString (dpy, d, font->fontset, gc, x, y, str, strlen (str));
133      else    else
134          XDrawString(dpy, d, gc, x, y, str, strlen(str));      XDrawString (dpy, d, gc, x, y, str, strlen (str));
135  }  }
136    
137  int getTextWidth(char *str, MyFont * font)  int
138    getTextWidth (char *str, MyFont * font)
139  {  {
140      int width;    int width;
141      XRectangle ink, logical;    XRectangle ink, logical;
142    
143  #ifdef DEBUG  #ifdef DEBUG
144      printf("entering getTextWidth\n");    printf ("entering getTextWidth\n");
145  #endif  #endif
146    
147      if(!str)    if (!str)
148          return 0;      return 0;
149    
150      if(use_fontset)    if (use_fontset)
151      {      {
152          XmbTextExtents(font->fontset, str, strlen(str), &ink, &logical);        XmbTextExtents (font->fontset, str, strlen (str), &ink, &logical);
153          width = logical.width;        width = logical.width;
154      }      }
155      else    else
156          width = XTextWidth(font->font, str, strlen(str));      width = XTextWidth (font->font, str, strlen (str));
157    
158      return width;    return width;
159  }  }
160    
161  void getWindowName(Display * dpy, Window w, char **name)  void
162    getWindowName (Display * dpy, Window w, char **name)
163  {  {
164      int status, num;    int status, num;
165      char **list;    char **list;
166      XTextProperty text_prop;    XTextProperty text_prop;
167    
168  #ifdef DEBUG  #ifdef DEBUG
169      printf("entering getWindowName\n");    printf ("entering getWindowName\n");
170  #endif  #endif
171    
172      *name = NULL;    *name = NULL;
173      status = XGetWMName(dpy, w, &text_prop);    status = XGetWMName (dpy, w, &text_prop);
174      if(!status || !text_prop.value || !text_prop.nitems)    if (!status || !text_prop.value || !text_prop.nitems)
175          return;      return;
176      if(text_prop.encoding == XA_STRING)    if (text_prop.encoding == XA_STRING)
177      {      {
178          if(text_prop.value)        if (text_prop.value)
179          {          {
180              *name = strdup(text_prop.value);            *name = strdup (text_prop.value);
181              XFree(text_prop.value);            XFree (text_prop.value);
182          }          }
183      }      }
184      else    else
185      {      {
186          XmbTextPropertyToTextList(dpy, &text_prop, &list, &num);        XmbTextPropertyToTextList (dpy, &text_prop, &list, &num);
187          if(num && *list)        if (num && *list)
188          {          {
189              XFree(text_prop.value);            XFree (text_prop.value);
190              *name = strdup(*list);            *name = strdup (*list);
191              XFreeStringList(list);            XFreeStringList (list);
192          }          }
193      }      }
194      return;    return;
195  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26