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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (C) 2004-2007 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <cairo.h>
#include <cairo-xlib.h>
int main(int argc, char *argv[])
{
int i;
int screen;
int win_x, win_y;
unsigned int width, height;
unsigned int depth;
unsigned int border_width;
unsigned int win_id;
double y_all_extents = 0.0;
double x, y;
Display *display;
Visual *visual;
Window RootWindow;
Window win;
cairo_text_extents_t extents;
cairo_surface_t *surface;
cairo_t *cr;
display = XOpenDisplay(NULL);
if(display == NULL)
{
fprintf(stderr, "Cannot open display.\n");
exit(1);
}
screen = DefaultScreen(display);
sscanf(argv[1], "%x", &win_id);
win = win_id;
XGetGeometry(display, win, &RootWindow, &win_x, &win_y,
&width, &height, &border_width, &depth );
visual = DefaultVisual(display, screen);
surface = cairo_xlib_surface_create (display,
win,
visual,
width,
height );
cr = cairo_create (surface);
cairo_select_font_face (cr, "Arial",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
for (i = 2; i < argc ; i++)
{
cairo_text_extents(cr, argv[i], &extents);
y_all_extents += (extents.height/2 + extents.y_bearing*2);
}
y_all_extents = y_all_extents/2.0;
cairo_text_extents(cr, argv[1], &extents);
x = width/2 - (extents.width/2 + extents.x_bearing);
y = height/2 - (extents.height/2 + extents.y_bearing);
y += y_all_extents;
cairo_move_to(cr, x, y );
XClearWindow(display, win);
for (i = 2; i < argc ; i++)
{
cairo_text_extents(cr, argv[i], &extents);
x = width/2 - (extents.width/2 + extents.x_bearing);
cairo_move_to (cr, x, y );
cairo_show_text (cr, argv[i]);
y -= (extents.height/2 + extents.y_bearing*2 );
}
XCloseDisplay(display);
return 0;
}
|