~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/gd/xfonts.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <X11/X.h>
 
2
#include <X11/Xlib.h>
 
3
/* Get the metrics for a character. */
 
4
typedef struct gs_point_s {
 
5
    double x, y;
 
6
} gs_point;
 
7
typedef struct gs_int_point_s {
 
8
    int x, y;
 
9
} gs_int_point;
 
10
typedef struct gs_int_rect_s {
 
11
    gs_int_point p, q;
 
12
} gs_int_rect;
 
13
 
 
14
int x_char_metrics(XFontStruct* x11font, char chr, gs_point* pwidth, gs_int_rect* pbbox)
 
15
{
 
16
  if (x11font->per_char == NULL) {
 
17
    pwidth->x = x11font->max_bounds.width;
 
18
    pwidth->y = 0;
 
19
    pbbox->p.x = x11font->max_bounds.lbearing;
 
20
    pbbox->q.x = x11font->max_bounds.rbearing;
 
21
    pbbox->p.y = -x11font->max_bounds.ascent;
 
22
    pbbox->q.y = x11font->max_bounds.descent;
 
23
  } else {
 
24
        int i = (int)chr - x11font->min_char_or_byte2;
 
25
 
 
26
        pwidth->x = x11font->per_char[i].width;
 
27
        pwidth->y = 0;
 
28
 
 
29
        pbbox->p.x = x11font->per_char[i].lbearing;
 
30
        pbbox->q.x = x11font->per_char[i].rbearing;
 
31
        pbbox->p.y = -x11font->per_char[i].ascent;
 
32
        pbbox->q.y = x11font->per_char[i].descent;
 
33
    }
 
34
    return 0;
 
35
}
 
36
 
 
37
/* Render a character. */
 
38
int
 
39
x_render_char(Display* dpy, XFontStruct* x11font, char chr, int xo, int yo)
 
40
{
 
41
  gs_int_rect bbox;
 
42
  int x, y, w, h;
 
43
 
 
44
 
 
45
  /* Display on an intermediate bitmap, then copy the bits. */
 
46
  int i;
 
47
  XImage *xim;
 
48
  Pixmap xpm;
 
49
  GC fgc;
 
50
  gs_point wxy;
 
51
  int code;
 
52
 
 
53
  code = x_char_metrics(x11font, chr, &wxy, &bbox);
 
54
 
 
55
  w = bbox.q.x - bbox.p.x;
 
56
  h = bbox.q.y - bbox.p.y;
 
57
 
 
58
 
 
59
  xpm = XCreatePixmap(dpy, InputOnly, w, h, 1);
 
60
  fgc = XCreateGC(dpy, xpm, None, NULL);
 
61
  XSetForeground(dpy, fgc, 0);
 
62
  XFillRectangle(dpy, xpm, fgc, 0, 0, w, h);
 
63
  XSetForeground(dpy, fgc, 1);
 
64
  XSetFont(dpy, fgc, x11font->fid);
 
65
  XDrawString(dpy, xpm, fgc, -bbox.p.x, -bbox.p.y, &chr, 1);
 
66
  xim = XGetImage(dpy, xpm, 0, 0, w, h, 1, ZPixmap);
 
67
  i = 0;
 
68
  for (y = 0; y < h; y++) {
 
69
    char b;
 
70
 
 
71
    for (x = 0; x < w; x++) {
 
72
        b = XGetPixel(xim, x, y);
 
73
      /*      if ((x & 7) == 7)
 
74
              bits[i++] = b;*/
 
75
    }
 
76
  }
 
77
  XFreePixmap(dpy, xpm);
 
78
  XFreeGC(dpy, fgc);
 
79
  XDestroyImage(xim);
 
80
  return;
 
81
    
 
82
}