2
* vfx11 - Display characters on a X11R6 window
3
* by Hirotsugu Kakugawa (h.kakugawa@computer.org)
6
* 24 Jan 1997 Simple version.
7
* 25 Jan 1997 Enhanced parsing of cmd line args.
8
* Added key operations: '<', '>', 'm', 'g', and '?'.
9
* 28 Jan 1997 Added '+', '-', and 'r' operations.
10
* 22 Mar 1997 Upgrade for VFlib 3.2
11
* 20 May 1997 Bug fixed. (Window Clear)
12
* 1 Sep 1998 Upgrade for VFlib 3.5
16
* Copyright (C) 1997-1998 Hirotsugu Kakugawa.
17
* All rights reserved.
19
* This program is free software; you can redistribute it and/or modify
20
* it under the terms of the GNU General Public License as published by
21
* the Free Software Foundation; either version 2, or (at your option)
24
* This program is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
* GNU General Public License for more details.
29
* You should have received a copy of the GNU General Public License
30
* along with this program; if not, write to the Free Software
31
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37
#include <sys/types.h>
39
#include <X11/Xutil.h>
40
#include <X11/keysym.h>
41
#include "../../src/VFlib-3_6.h"
43
#define VFLX11_VERSION "2.0.0"
46
#define CMD_NEXT_PAGE 1
47
#define CMD_PREV_PAGE 2
50
#define CMD_FIRST_PAGE 5
51
#define CMD_LAST_PAGE 6
52
#define CMD_SET_MARK 7
53
#define CMD_GOTO_MARK 8
55
#define CMD_P4PAGES 10
56
#define CMD_N4PAGES 11
57
#define CMD_P16PAGES 12
58
#define CMD_N16PAGES 13
59
#define CMD_P64PAGES 14
60
#define CMD_N64PAGES 15
61
#define CMD_ENLARGE 20
66
#define POLL_NOTHING 0
75
#define DEFAULT_PIXEL_SIZE 24
76
#define CHAR_BORDER_FACTOR 1.2
80
double ArgFontSize = -1;
82
double Dpi_X = 1, Dpi_Y = -1;
85
double CharBorderX = CHAR_BORDER_FACTOR;
86
double CharBorderY = CHAR_BORDER_FACTOR;
88
#define CHARS_PER_LINE 16
92
int StartInPage, EndInPage;
93
int SkipBeginInPage, SkipEndInPage;
95
int CharWidth, CharHeight, CharLines;
96
int CharWidth0, CharHeight0;
99
#define MAG_SCALE 100.0
100
#define MAGX() ((double)MagX/MAG_SCALE)
101
#define MAGY() ((double)MagY/MAG_SCALE)
103
int usage(), key_usage();
104
int OpenFont(), Loop(), Cmd(), CodePoint();
105
void change_win_size();
108
void Win_Init(), Win_Clear(), Win_PutBitmap(), Win_Beep(), Win_ChangeSize();
109
int Win_UserCmd(), Win_PollUserCmd();
112
extern double atof();
129
MagX = 1 * MAG_SCALE;
130
MagY = 1 * MAG_SCALE;
131
CharBorderX = CHAR_BORDER_FACTOR;
132
CharBorderY = CHAR_BORDER_FACTOR;
136
for (argv++, argc--; argc > 0; argc -= na, argv += na){
138
if (argv[0][0] != '-'){
141
} else if (strcmp(argv[0], "-verbose") == 0){
144
} else if (strcmp(argv[0], "-mode1") == 0){
147
} else if (strcmp(argv[0], "-mode2") == 0){
150
} else if (strcmp(argv[0], "-ol") == 0){
153
} else if (strcmp(argv[0], "-help") == 0){
156
} else if (strcmp(argv[0], "--help") == 0){
165
if (strcmp(argv[0], "-f") == 0){
167
} else if (strcmp(argv[0], "-v") == 0){
169
} else if (strcmp(argv[0], "-p") == 0){
170
ArgFontSize = atof(argv[1]);
171
} else if (strcmp(argv[0], "-m") == 0){
172
FMagX = FMagY = atof(argv[1]);
173
} else if (strcmp(argv[0], "-mx") == 0){
174
FMagX = atof(argv[1]);
175
} else if (strcmp(argv[0], "-my") == 0){
176
FMagY = atof(argv[1]);
177
} else if (strcmp(argv[0], "-b") == 0){
178
CharBorderX = CharBorderY = atof(argv[1]);
180
CharBorderX = CharBorderY = CHAR_BORDER_FACTOR;
181
} else if (strcmp(argv[0], "-bx") == 0){
182
CharBorderX = atof(argv[1]);
184
CharBorderX = CHAR_BORDER_FACTOR;
185
} else if (strcmp(argv[0], "-by") == 0){
186
CharBorderY = atof(argv[1]);
188
CharBorderY = CHAR_BORDER_FACTOR;
194
if (FontName == NULL)
197
if ((Mode == 2) && (OutlineMode == 1)){
198
fprintf(stderr, "Warning: Outline mode is not supported in mode 2.\n");
201
if (VF_Init(vflibcap, NULL) < 0){
202
fprintf(stderr, "Initializing VFlib: failed\n");
203
if (vf_error == VF_ERR_NO_VFLIBCAP){
204
if (vflibcap == NULL){
205
fprintf(stderr, "Could not read default vflibcap file.\n");
207
fprintf(stderr, "Could not read vflibcap file: %s.\n", vflibcap);
217
SkipBeginInPage = -1;
222
printf("Opening font: %s\n", FontName);
225
fprintf(stderr, "Failed to open a font: %s\n", FontName);
236
printf("vflx11 - Display VFlib font version %s, based on VFlib %s.\n",
237
VFLX11_VERSION, VF_GetVersion());
238
printf("Usage: vfx11 [Options] FONT\n");
239
printf("Options: \n");
240
printf(" -v VFLIBCAP : vflibcap file\n");
241
printf(" -p PIXEL : pixel size (or point size)\n");
242
printf(" -m MAG : magnification\n");
243
printf(" -mx MAG_X : horizontal magnification\n");
244
printf(" -my MAG_Y : vertical magnification\n");
245
printf(" -f FONT : font name\n");
246
printf(" -mode1 : open font in mode 1\n");
247
printf(" -mode2 : open font in mode 2\n");
248
printf(" -ol : outline mode for mode 1\n");
251
printf("Example: vflx11 -v vflibcap-pcf -m 0.5 timR24.pcf\n");
264
fd = VF_OpenFont1(FontName, -1, -1, -1, FMagX, FMagY);
266
fd = VF_OpenFont1(FontName, -1, -1, ArgFontSize, FMagX, FMagY);
267
} else if (Mode == 2){
269
fd = VF_OpenFont2(FontName, -1, FMagX, FMagY);
271
fd = VF_OpenFont2(FontName, ArgFontSize, FMagX, FMagY);
277
if ((p = VF_GetFontProp(fd, "PIXEL_SIZE")) != NULL)
280
FontSize = DEFAULT_PIXEL_SIZE;
283
VF_CloseFont(Font_ID);
290
printf("Pixel size: %d\n", (int)FontSize);
297
printf("Key and mouse operations:\n");
298
printf(" q (or mouse middle button) : exit\n");
299
printf(" b (or mouse left button) : go to previous page\n");
300
printf(" SPC (or mouse right button) : go to next page\n");
301
printf(" m : set mark on current page\n");
302
printf(" g : go to marked page\n");
303
printf(" + : enlarge window\n");
304
printf(" - : shrink window\n");
305
printf(" d : redraw window\n");
306
printf(" ? : help\n");
315
VF_BITMAP bm = NULL, bm2;
317
int act, nl0, nl1, c;
320
MagX = 1 * MAG_SCALE;
322
MagY = 1 * MAG_SCALE;
324
nl0 = StartInPage/CHARS_PER_LINE;
325
nl1 = (EndInPage+CHARS_PER_LINE-1)/CHARS_PER_LINE;
326
CharLines = nl1 - nl0;
328
CharWidth = FontSize * CharBorderX;
329
CharHeight = FontSize * CharBorderY;
331
Win_Init(CharWidth * CHARS_PER_LINE, CharHeight * CharLines);
339
for (c = StartInPage; c <= EndInPage; c++){
341
if ((SkipBeginInPage <= c) && (c <= SkipEndInPage))
344
if (Win_PollUserCmd() == POLL_EVENT){
345
if ((act = Cmd()) != ACT_NONE){
346
if (act == ACT_WINCH)
355
if (OutlineMode == 0){
356
bm = VF_GetBitmap1(Font_ID, CodePoint(c), MAGX(), MAGY());
359
if ((ol = VF_GetOutline(Font_ID, CodePoint(c),
360
MAGX(), MAGY())) != NULL){
361
bm = VF_OutlineToBitmap(ol, -1, -1, -1, 1.0, 1.0);
365
} else if (Mode == 2){
366
bm = VF_GetBitmap2(Font_ID, CodePoint(c), MAGX(), MAGY());
370
bm2 = VF_MinimizeBitmap(bm);
372
Win_PutBitmap(bm2, c%CHARS_PER_LINE, c/CHARS_PER_LINE - nl0,
373
CharWidth, CharHeight);
376
Win_PutBitmap(bm, c%CHARS_PER_LINE, c/CHARS_PER_LINE - nl0,
377
CharWidth, CharHeight);
383
while ((act = Cmd()) == ACT_NONE)
385
if (act == ACT_WINCH)
395
static int markedPage = -100;
398
switch (Win_UserCmd()){
458
if (markedPage >= PageMin){
478
if ((MagX > 30) && (MagY > 30)){
485
printf("Reopening font: %s\n", FontName);
487
fprintf(stderr, "Failed to reopen a font: %s\n", FontName);
499
return Page * 0x100 + c;
506
CharWidth = FontSize * CharBorderX * MAGX();
507
CharHeight = FontSize * CharBorderY * MAGY();
509
Win_ChangeSize(CharWidth * CHARS_PER_LINE, CharHeight * CharLines);
514
/*------------------------*/
517
XEvent xevent, *xev = NULL;
520
XSetWindowAttributes Att;
521
unsigned int WinX, WinY, WinBorder, WinDepth;
523
char WindowName[256];
530
if ((w > 2000) || (h > 2000)){
531
fprintf(stderr, "Window is too large: (%dx%d)\n", w, h);
535
WinX = w + WIN_BORDER * 2;
536
WinY = h + WIN_BORDER * 2;
538
Disp = XOpenDisplay(DisplayName);
540
fprintf(stderr, "Can't open display\n");
543
Win = XCreateSimpleWindow(Disp, RootWindow(Disp, 0),
545
BlackPixel(Disp, 0), WhitePixel(Disp, 0));
546
Gc = XCreateGC(Disp, Win, 0, 0);
547
XSetForeground(Disp, Gc, WhitePixel(Disp, 0));
550
Att.override_redirect = True;
551
Att.backing_store = Always;
552
XChangeWindowAttributes(Disp, Win, CWOverrideRedirect, &Att);
553
XChangeWindowAttributes(Disp, Win, CWBackingStore, &Att);
555
XSelectInput(Disp, Win,
556
(KeyPressMask|ButtonPressMask|ExposureMask|ConfigureNotify));
557
XMapWindow(Disp, Win);
564
sprintf(WindowName, "VFlib font: %s (0x%X-0x%X / %d-%d)",
565
FontName, CodePoint(StartInPage), CodePoint(EndInPage),
566
CodePoint(StartInPage), CodePoint(EndInPage));
567
XStoreName(Disp, Win, WindowName);
568
XFillRectangle(Disp, Win, Gc, 0, 0, WinX, WinY);
576
void Win_PutBitmap(bm, x, y, cw, ch)
580
int w, h, ix, iy, i, n;
581
unsigned char *xbitmap, c;
583
unsigned long fg, bg;
585
static unsigned char bit_rev[] = {
586
/* 0000 0001 0010 0011 0100 0101 0110 0111 */
587
0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
588
/* 1000 1001 1010 1011 1100 1101 1110 1111 */
589
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf };
594
depth = DefaultDepth(Disp, DefaultScreen(Disp));
595
fg = BlackPixel(Disp, DefaultScreen(Disp));
596
bg = WhitePixel(Disp, DefaultScreen(Disp));
598
if ((w = bm->bbx_width) == 0)
600
if ((h = bm->bbx_height) == 0)
604
if ((xbitmap = (unsigned char*)malloc(n)) == NULL){
605
fprintf(stderr, "No Memory.\n");
608
for (i = 0; i < n; i++)
611
if ((bm->bbx_width != 0) && (bm->bbx_height != 0)){
612
for (iy = 0; iy < bm->bbx_height; iy++){
613
for (ix = 0; ix < (bm->bbx_width+7)/8; ix++){
614
c = bm->bitmap[ix+iy*bm->raster];
615
xbitmap[ix+iy*((bm->bbx_width+7)/8)]
616
= bit_rev[(c%0x10)]*0x10 + bit_rev[(c/0x10)];
621
pix = XCreatePixmapFromBitmapData(Disp, Win, (char*)xbitmap,
622
w, h, fg, bg, depth);
623
XCopyArea(Disp, pix, Win, Gc, 0, 0, w, h,
624
x*cw + bm->off_x + WIN_BORDER,
625
y*ch - bm->off_y + ch*0.8 + WIN_BORDER);
626
XFreePixmap(Disp, pix);
630
void Win_ChangeSize(w, h)
632
WinX = w + WIN_BORDER * 2;
633
WinY = h + WIN_BORDER * 2;
634
XResizeWindow(Disp, Win, w, h);
644
XNextEvent(Disp, &xevent);
649
switch (xevent.xbutton.button){
651
return CMD_PREV_PAGE;
655
return CMD_NEXT_PAGE;
660
case ConfigureNotify:
661
x = xevent.xconfigure.width;
662
y = xevent.xconfigure.height;
663
if ((WinX != x) || (y != WinY)){
671
if (XLookupString(&xevent.xkey, str, 10, &k, NULL) == 1){
673
case XK_b: case XK_B: case XK_BackSpace: case XK_Delete:
675
return CMD_PREV_PAGE;
676
case XK_space: case XK_Return: case XK_Linefeed:
678
return CMD_NEXT_PAGE;
679
case XK_bracketleft: case XK_h:
681
case XK_bracketright: case XK_l:
692
return CMD_FIRST_PAGE;
694
return CMD_LAST_PAGE;
695
case XK_m: case XK_M:
697
case XK_g: case XK_G:
698
return CMD_GOTO_MARK;
701
case XK_q: case XK_Q:
720
int Win_PollUserCmd()
729
if (XCheckWindowEvent(Disp, Win,
730
(KeyPressMask | ButtonPressMask
731
| ExposureMask | ConfigureNotify),
742
case ConfigureNotify:
743
if ((WinX != xevent.xconfigure.width)
744
|| (WinY != xevent.xconfigure.height))
749
if (XLookupString(&xevent.xkey, str, 10, &k, NULL) == 1)
753
if (val == POLL_EVENT)