wdvi

network DVI viewer
Log | Files | Refs

commit 75ba34f8f5f732828331f1d3b3215e42063a9728
parent 07d0080174120b6c61f7220396de3eee97669766
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Wed,  8 Sep 2021 23:00:13 +0000

only support TrueColor visual

xdvi supported not using TrueColor visual but I do not think the
extra complexity is worth it. Remove all the fall back code, and
the -install and -grey options.

Diffstat:
Mdvi-draw.c | 97+++++++++----------------------------------------------------------------------
Mdvi-init.c | 20++++++++------------
Mevents.c | 519+++++++++++++++++++------------------------------------------------------------
Mevents.h | 1-
Mxdvi.c | 297+++----------------------------------------------------------------------------
Mxdvi.h | 21---------------------
6 files changed, 149 insertions(+), 806 deletions(-)

diff --git a/dvi-draw.c b/dvi-draw.c @@ -411,83 +411,6 @@ sample(bits, bytes_wide, bit_skip, w, h) return n; } -static void -shrink_glyph(g) - struct glyph *g; -{ - int shrunk_bytes_wide, shrunk_height; - int rows_left, rows, init_cols; - int cols_left; - int cols; - BMUNIT *old_ptr, *new_ptr; - BMUNIT m, *cp; - int min_sample = shrink_factor * shrink_factor * density / 100; - int rtmp; - - /* These machinations ensure that the character is shrunk according to - its hot point, rather than its upper left-hand corner. */ - g->x2 = g->x / shrink_factor; - init_cols = g->x - g->x2 * shrink_factor; - if (init_cols <= 0) init_cols += shrink_factor; - else ++g->x2; - g->bitmap2.w = g->x2 + ROUNDUP((int) g->bitmap.w - g->x, shrink_factor); - /* include row zero with the positively numbered rows */ - rtmp = g->y + 1; - g->y2 = rtmp / shrink_factor; - rows = rtmp - g->y2 * shrink_factor; - if (rows <= 0) { - rows += shrink_factor; - --g->y2; - } - g->bitmap2.h = shrunk_height = g->y2 + - ROUNDUP((int) g->bitmap.h - rtmp, shrink_factor) + 1; - alloc_bitmap(&g->bitmap2); - old_ptr = (BMUNIT *) g->bitmap.bits; - new_ptr = (BMUNIT *) g->bitmap2.bits; - shrunk_bytes_wide = g->bitmap2.bytes_wide; - rows_left = g->bitmap.h; - bzero((char *) new_ptr, shrunk_bytes_wide * shrunk_height); - while (rows_left) { - if (rows > rows_left) rows = rows_left; - cols_left = g->bitmap.w; -#ifndef WORDS_BIGENDIAN - m = (1 << 0); -#else - m = ((BMUNIT) 1 << (BMBITS-1)); -#endif - cp = new_ptr; - cols = init_cols; - while (cols_left) { - if (cols > cols_left) cols = cols_left; - if (sample(old_ptr, g->bitmap.bytes_wide, - (int) g->bitmap.w - cols_left, cols, rows) - >= min_sample) - *cp |= m; -#ifndef WORDS_BIGENDIAN - if (m == ((BMUNIT)1 << (BMBITS-1))) { - m = (1 << 0); - ++cp; - } - else m <<= 1; -#else - if (m == (1 << 0)) { - m = ((BMUNIT) 1 << (BMBITS-1)); - ++cp; - } - else m >>= 1; -#endif - cols_left -= cols; - cols = shrink_factor; - } - *((char **) &new_ptr) += shrunk_bytes_wide; - *((char **) &old_ptr) += rows * g->bitmap.bytes_wide; - rows_left -= rows; - rows = shrink_factor; - } - g->y2 = g->y / shrink_factor; - if (debug & DBG_BITMAP) - print_bitmap(&g->bitmap2); -} static void shrink_glyph_grey(g) @@ -501,6 +424,8 @@ shrink_glyph_grey(g) BMUNIT *old_ptr; unsigned int size; int rtmp; + Visual *visual; + unsigned int depth; if (fg_active != fg_current) do_color_change(); @@ -523,7 +448,9 @@ shrink_glyph_grey(g) + 1; if (g->pixmap2 == NULL) { - g->image2 = XCreateImage(DISP, our_visual, our_depth, ZPixmap, + visual = DefaultVisualOfScreen(SCRN); + depth = DefaultDepthOfScreen(SCRN); + g->image2 = XCreateImage(DISP, visual, depth, ZPixmap, 0, (char *) NULL, g->bitmap2.w, g->bitmap2.h, BMBITS, 0); size = g->image2->bytes_per_line * g->bitmap2.h; g->pixmap2 = g->image2->data = xmalloc(size != 0 ? size : 1); @@ -897,17 +824,13 @@ set_char(wide_ubyte cmd, wide_ubyte ch) if (shrink_factor == 1) put_bitmap(&g->bitmap, PXL_H - g->x, PXL_V - g->y); else { - if (use_grey) { - if (g->pixmap2 == NULL) { + /* + * use_grey + */ + if (g->pixmap2 == NULL) { shrink_glyph_grey(g); - } - put_image(g, PXL_H - g->x2, PXL_V - g->y2); - } else { - if (g->bitmap2.bits == NULL) { - shrink_glyph(g); - } - put_bitmap(&g->bitmap2, PXL_H - g->x2, PXL_V - g->y2); } + put_image(g, PXL_H - g->x2, PXL_V - g->y2); } #ifndef TEXXET return g->dvi_adv; diff --git a/dvi-init.c b/dvi-init.c @@ -124,10 +124,9 @@ reset_fonts() void reset_colors() { - if (color_list_len != 0) { - XFreeColors(DISP, our_colormap, color_list, color_list_len, 0); - color_list_len = 0; - } + struct font *f; + struct glyph *g; + while (bg_head != NULL) { struct bgrec *bgp; struct fgrec *fgp; @@ -141,18 +140,15 @@ reset_colors() free(bg_head); bg_head = bgp; } - if (use_grey) { - struct font *f; - struct glyph *g; - for (f = font_head; f != NULL; f = f->next) + /* use_grey */ + for (f = font_head; f != NULL; f = f->next) if ((f->flags & FONT_LOADED) && !(f->flags & FONT_VIRTUAL)) - for (g = f->glyph; g <= f->glyph + f->maxchar; ++g) - g->fg = NULL; - } + for (g = f->glyph; g <= f->glyph + f->maxchar; ++g) + g->fg = NULL; + bg_current = NULL; fg_active = NULL; - color_warned = False; } /* diff --git a/events.c b/events.c @@ -134,7 +134,6 @@ static ACTION_DECL(Act_show_display_attributes); static ACTION_DECL(Act_set_shrink_factor); static ACTION_DECL(Act_shrink_to_dpi); static ACTION_DECL(Act_set_density); -static ACTION_DECL(Act_set_greyscaling); static ACTION_DECL(Act_set_color); static ACTION_DECL(Act_reread_dvi_file); static ACTION_DECL(Act_discard_number); @@ -172,7 +171,6 @@ XtActionsRec Actions[] = { {"shrink-to-dpi", Act_shrink_to_dpi}, {"set-density", Act_set_density}, {"print", Act_print}, - {"set-greyscaling", Act_set_greyscaling}, {"set-color", Act_set_color}, {"reread-dvi-file", Act_reread_dvi_file}, {"discard-number", Act_discard_number}, @@ -328,50 +326,6 @@ mask_shifts(mask, pshift1, pshift2) *pshift2 = k; } -/* - * Try to allocate 4 color planes for 16 colors (for GXor drawing). - * Not called if the visual type is TrueColor. - * When color specials are active, this is called exactly once. - * It is used for the first foreground/background pair displayed in - * the document. For other documents, we act as if this call had failed. - */ - -void -init_plane_masks() -{ - Pixel pixel; - - if (copy || plane_masks[0] != 0) - return; - - if (XAllocColorCells(DISP, our_colormap, False, plane_masks, 4, - &pixel, 1)) { - /* Make sure fore_Pixel and back_Pixel are a part of the palette */ - back_Pixel = pixel; - fore_Pixel = pixel | plane_masks[0] | plane_masks[1] - | plane_masks[2] | plane_masks[3]; - if (mane.win != (Window) 0) - XSetWindowBackground(DISP, mane.win, back_Pixel); - } - else { - copy = True; - WARN(XmDIALOG_WARNING, "\ -Greyscaling is running in copy mode.\n\ -Your display can only display a limited number\n\ -of colors at a time (typically 256), and other\n\ -applications (such as netscape) are using\n\ -many of them.\n\ -\n\ -Running in copy mode will cause overstrike\n\ -characters to appear incorrectly,\n\ -and may result in poor display quality.\n\ -\n\ -See the section ``GREYSCALING AND COLORMAPS''\n\ -in the xdvi manual page for more details."); - } -} - - /* * Warn about overstrike characters. @@ -389,46 +343,6 @@ warn_overstrike() } /* - * Insert into list of colors to be freed upon opening new document. - */ - -static void -color_list_insert(pixel) - Pixel pixel; -{ - if (color_list_len >= color_list_max) { - if (color_list_max == 0) - color_list = xmalloc( - (color_list_max += 16) * sizeof *color_list); - else - color_list = xrealloc(color_list, - (color_list_max += 16) * sizeof *color_list); - } - color_list[color_list_len++] = pixel; -} - - -/* - * Warn about colors not being correct. - */ - -static void -color_warn() -{ - if (!color_warned) { - color_warned = True; - WARN(XmDIALOG_WARNING, "\ -Cannot allocate colormap entry;\n\ -displayed colors are not exact.\n\ -Either this document is using too many\n\ -colors, or some other application is.\n\ -In the latter case, close that\n\ -application and re-read the dvi file."); - } -} - - -/* * Allocate a color and add it to our list of pixels to be returned * upon opening a new document. */ @@ -440,43 +354,19 @@ static int shift2_r, shift2_g, shift2_b; static Boolean shifts_good = False; static Pixel -alloc_color(colorp, fallback_pixel) - const struct rgb *colorp; - Pixel fallback_pixel; +alloc_color(const struct rgb *colorp, Pixel fallback_pixel) { - XColor xcol; + Visual *visual = DefaultVisualOfScreen(SCRN); - if (our_visual->class == TrueColor) { - if (!shifts_good) { - mask_shifts(our_visual->red_mask, &shift1_r, &shift2_r); - mask_shifts(our_visual->green_mask, &shift1_g, &shift2_g); - mask_shifts(our_visual->blue_mask, &shift1_b, &shift2_b); + if (!shifts_good) { + mask_shifts(visual->red_mask, &shift1_r, &shift2_r); + mask_shifts(visual->green_mask, &shift1_g, &shift2_g); + mask_shifts(visual->blue_mask, &shift1_b, &shift2_b); shifts_good = True; - } - return SHIFTIFY(colorp->r, shift1_r, shift2_r) | - SHIFTIFY(colorp->g, shift1_g, shift2_g) | - SHIFTIFY(colorp->b, shift1_b, shift2_b); - } - else { - xcol.red = colorp->r; - xcol.green = colorp->g; - xcol.blue = colorp->b; - xcol.flags = DoRed | DoGreen | DoBlue; - if (XAllocColor(DISP, our_colormap, &xcol)) { - color_list_insert(xcol.pixel); - if (debug & DBG_DVI) - printf("alloc_color%6d%6d%6d --> %ld\n", - xcol.red, xcol.green, xcol.blue, xcol.pixel); - return xcol.pixel; - } - else { - if (debug & DBG_DVI) - printf("alloc_color%6d%6d%6d --> failed\n", - xcol.red, xcol.green, xcol.blue); - color_warn(); - return fallback_pixel; - } } + return SHIFTIFY(colorp->r, shift1_r, shift2_r) | + SHIFTIFY(colorp->g, shift1_g, shift2_g) | + SHIFTIFY(colorp->b, shift1_b, shift2_b); } #undef SHIFTIFY @@ -507,263 +397,131 @@ do_color_change() XGCValues values; Pixel set_bits; Pixel clr_bits; + Visual *visual; - if (use_grey) { + /* + * use_grey + */ + if (!fg_current->pixel_good) { + fg_current->pixel = alloc_color(&fg_current->color, + fore_color_data.pixel); + fg_current->pixel_good = True; + } - if (our_visual->class == TrueColor) { - if (!fg_current->pixel_good) { - fg_current->pixel = alloc_color(&fg_current->color, - fore_color_data.pixel); - fg_current->pixel_good = True; - } + set_bits = fg_current->pixel & ~bg_current->pixel; + clr_bits = bg_current->pixel & ~fg_current->pixel; + + visual = DefaultVisualOfScreen(SCRN); + + if (set_bits & visual->red_mask) + set_bits |= visual->red_mask; + if (clr_bits & visual->red_mask) + clr_bits |= visual->red_mask; + if (set_bits & visual->green_mask) + set_bits |= visual->green_mask; + if (clr_bits & visual->green_mask) + clr_bits |= visual->green_mask; + if (set_bits & visual->blue_mask) + set_bits |= visual->blue_mask; + if (clr_bits & visual->blue_mask) + clr_bits |= visual->blue_mask; + + /* + * Make the GCs + */ + + SetGC(ruleGC, GXcopy, fg_current->pixel, bg_current->pixel); + foreGC2 = NULL; - set_bits = fg_current->pixel & ~bg_current->pixel; - clr_bits = bg_current->pixel & ~fg_current->pixel; - - if (set_bits & our_visual->red_mask) - set_bits |= our_visual->red_mask; - if (clr_bits & our_visual->red_mask) - clr_bits |= our_visual->red_mask; - if (set_bits & our_visual->green_mask) - set_bits |= our_visual->green_mask; - if (clr_bits & our_visual->green_mask) - clr_bits |= our_visual->green_mask; - if (set_bits & our_visual->blue_mask) - set_bits |= our_visual->blue_mask; - if (clr_bits & our_visual->blue_mask) - clr_bits |= our_visual->blue_mask; - - /* - * Make the GCs - */ - - SetGC(ruleGC, GXcopy, fg_current->pixel, bg_current->pixel); - foreGC2 = NULL; - - if (resource.copy - || (set_bits && clr_bits && !resource.thorough)) { - if (!resource.copy) + if (resource.copy || (set_bits && clr_bits && !resource.thorough)) { + if (!resource.copy) warn_overstrike(); - SetGC(foreGC, GXcopy, fg_current->pixel, bg_current->pixel); - } - else { - if (set_bits) { + SetGC(foreGC, GXcopy, fg_current->pixel, bg_current->pixel); + } + else { + if (set_bits) { SetGC(foreGC, GXor, fg_current->pixel & set_bits, 0); if (clr_bits) { SetGC(foreGC2_bak, GXandInverted, ~fg_current->pixel & clr_bits, 0); foreGC2 = foreGC2_bak; } - } - else - SetGC(foreGC, GXandInverted, - ~fg_current->pixel & clr_bits, 0); } + else + SetGC(foreGC, GXandInverted, + ~fg_current->pixel & clr_bits, 0); + } - if (debug & DBG_DVI) - printf( - "do_color_change: fg = %lx, bg = %lx, with%s foreGC2\n", + if (debug & DBG_DVI) + printf("do_color_change: fg = %lx, bg = %lx, with%s foreGC2\n", fg_current->pixel, bg_current->pixel, foreGC2 == NULL ? "out" : ""); - if (mane.shrinkfactor > 1) { - int i; - unsigned int sf_squared; + if (mane.shrinkfactor <= 1) { + fg_active = fg_current; + return; + } + + /* + * mane.shrinkfactor > 1 + */ + int i; + unsigned int sf_squared; - sf_squared = mane.shrinkfactor * mane.shrinkfactor; + sf_squared = mane.shrinkfactor * mane.shrinkfactor; - if (shrink_allocated_for < mane.shrinkfactor) { - if (pixeltbl != NULL) { - free((char *) pixeltbl); - if (pixeltbl_t != NULL) { + if (shrink_allocated_for < mane.shrinkfactor) { + if (pixeltbl != NULL) { + free((char *) pixeltbl); + if (pixeltbl_t != NULL) { free((char *) pixeltbl_t); pixeltbl_t = NULL; - } } - pixeltbl = xmalloc((sf_squared + 1) * sizeof(Pixel)); - shrink_allocated_for = mane.shrinkfactor; - } - if (foreGC2 != NULL && pixeltbl_t == NULL) - /* Can't use sf_squared (or mane.shrinkfactor) here */ - pixeltbl_t = xmalloc((shrink_allocated_for - * shrink_allocated_for + 1) * sizeof(Pixel)); - - /* - * Compute pixel values directly. - */ - -#define SHIFTIFY(x, shift1, shift2) ((((Pixel)(x)) >> (shift1)) << (shift2)) + } + pixeltbl = xmalloc((sf_squared + 1) * sizeof(Pixel)); + shrink_allocated_for = mane.shrinkfactor; + } + if (foreGC2 != NULL && pixeltbl_t == NULL) + /* Can't use sf_squared (or mane.shrinkfactor) here */ + pixeltbl_t = xmalloc((shrink_allocated_for + * shrink_allocated_for + 1) * sizeof(Pixel)); - for (i = 0; i <= sf_squared; ++i) { - double frac = gamma > 0 - ? pow((double) i / sf_squared, 1 / gamma) - : 1 - pow((double) (sf_squared - i) / sf_squared, + /* + * Compute pixel values directly. + */ + for (i = 0; i <= sf_squared; ++i) { + double frac = gamma > 0 + ? pow((double) i / sf_squared, 1 / gamma) + : 1 - pow((double) (sf_squared - i) / sf_squared, -gamma); - unsigned int red, green, blue; - Pixel pixel; - - red = frac - * ((double) fg_current->color.r - bg_current->color.r) - + bg_current->color.r; - green = frac - * ((double) fg_current->color.g - bg_current->color.g) - + bg_current->color.g; - blue = frac - * ((double) fg_current->color.b - bg_current->color.b) - + bg_current->color.b; - - pixel = SHIFTIFY(red, shift1_r, shift2_r) | - SHIFTIFY(green, shift1_g, shift2_g) | - SHIFTIFY(blue, shift1_b, shift2_b); - - if (foreGC2 != NULL) { /* if thorough */ - pixeltbl[i] = pixel & ~bg_current->pixel; - pixeltbl_t[i] = ~pixel & bg_current->pixel; - } - else if (resource.copy || (set_bits && clr_bits)) - pixeltbl[i] = pixel; - else - pixeltbl[i] = set_bits ? pixel & set_bits - : ~pixel & clr_bits; - } - + unsigned int red, green, blue; + Pixel pixel; + + red = frac * ((double) fg_current->color.r + - bg_current->color.r) + + bg_current->color.r; + green = frac * ((double) fg_current->color.g + - bg_current->color.g) + + bg_current->color.g; + blue = frac * ((double) fg_current->color.b + - bg_current->color.b) + + bg_current->color.b; + +#define SHIFTIFY(x, shift1, shift2) ((((Pixel)(x)) >> (shift1)) << (shift2)) + pixel = SHIFTIFY(red, shift1_r, shift2_r) | + SHIFTIFY(green, shift1_g, shift2_g) | + SHIFTIFY(blue, shift1_b, shift2_b); #undef SHIFTIFY - } - - } - - else { /* not TrueColor */ - int i; - Boolean using_planes; - - using_planes = (fg_current == bg_head->fg_head && !copy); - if (!fg_current->palette_good) { - XColor color; - - for (i = 0; i < 16; ++i) { - double frac; - - frac = gamma > 0 ? pow((double) i / 15, 1 / gamma) - : 1 - pow((double) (15 - i) / 15, -gamma); - color.red = frac - * ((double) fg_current->color.r - bg_current->color.r) - + bg_current->color.r; - color.green = frac - * ((double) fg_current->color.g - bg_current->color.g) - + bg_current->color.g; - color.blue = frac - * ((double) fg_current->color.b - bg_current->color.b) - + bg_current->color.b; - - color.flags = DoRed | DoGreen | DoBlue; - - if (using_planes) { - color.pixel = back_Pixel; /* start of block */ - if (i & 1) color.pixel |= plane_masks[0]; - if (i & 2) color.pixel |= plane_masks[1]; - if (i & 4) color.pixel |= plane_masks[2]; - if (i & 8) color.pixel |= plane_masks[3]; - XStoreColor(DISP, our_colormap, &color); - fg_current->palette[i] = color.pixel; - } - else { - if (XAllocColor(DISP, our_colormap, &color)) { - fg_current->palette[i] = color.pixel; - color_list_insert(color.pixel); - } - else { - color_warn(); - fg_current->palette[i] = - (i * 100 >= density * 15) - ? fore_Pixel : bg_current->pixel; - } - } - } - - if (using_planes && bg_current->pixel != back_Pixel) { - bg_current->pixel = back_Pixel; - XSetWindowBackground(DISP, mane.win, bg_current->pixel); - XClearWindow(DISP, mane.win); - } - - fg_current->palette_good = True; - } - - if (debug & DBG_DVI) - printf("do_color_change: fg = %ld, bg = %ld, using_planes = %d\n", - fg_current->palette[15], bg_current->pixel, using_planes); - - if (using_planes) { - SetGC(ruleGC, GXor, fg_current->palette[15], - bg_current->pixel); - SetGC(foreGC, GXor, fg_current->palette[15], - bg_current->pixel); - } - else { - SetGC(ruleGC, GXcopy, fg_current->palette[15], - bg_current->pixel); - SetGC(foreGC, GXcopy, fg_current->palette[15], - bg_current->pixel); - } - - foreGC2 = NULL; - - if (mane.shrinkfactor > 1) { - if (shrink_allocated_for < mane.shrinkfactor) { - if (pixeltbl != NULL) free((char *) pixeltbl); - pixeltbl = xmalloc((unsigned) - (mane.shrinkfactor * mane.shrinkfactor + 1) - * sizeof *pixeltbl); - shrink_allocated_for = mane.shrinkfactor; - } - - for (i = 0; i <= mane.shrinkfactor * mane.shrinkfactor; ++i) - pixeltbl[i] = fg_current->palette[ - (i * 30 + mane.shrinkfactor * mane.shrinkfactor) - / (2 * mane.shrinkfactor * mane.shrinkfactor)]; - } - } - - } /* end if use_grey */ - else - - - { - static GC foreGC2_bak = NULL; - - if (!fg_current->pixel_good) { - fg_current->pixel = alloc_color(&fg_current->color, - fore_color_data.pixel); - fg_current->pixel_good = True; - } - - if (debug & DBG_DVI) - printf("do_color_change: fg = %lx, bg = %lx\n", - fg_current->pixel, bg_current->pixel); - - SetGC(ruleGC, GXcopy, fg_current->pixel, bg_current->pixel); - set_bits = (Pixel) (fg_current->pixel & ~bg_current->pixel); - clr_bits = (Pixel) (bg_current->pixel & ~fg_current->pixel); - foreGC2 = NULL; - - if (resource.copy - || (set_bits && clr_bits && !resource.thorough)) { - if (!resource.copy) - warn_overstrike(); - SetGC(foreGC, GXcopy, fg_current->pixel, bg_current->pixel); - } - else { - if (set_bits) { - SetGC(foreGC, GXor, set_bits, 0); - if (clr_bits) { - SetGC(foreGC2_bak, GXandInverted, clr_bits, 0); - foreGC2 = foreGC2_bak; - } + if (foreGC2 != NULL) { /* if thorough */ + pixeltbl[i] = pixel & ~bg_current->pixel; + pixeltbl_t[i] = ~pixel & bg_current->pixel; } + else if (resource.copy || (set_bits && clr_bits)) + pixeltbl[i] = pixel; else - SetGC(foreGC, GXandInverted, clr_bits, 0); - } + pixeltbl[i] = set_bits ? pixel & set_bits + : ~pixel & clr_bits; } fg_active = fg_current; @@ -1407,7 +1165,7 @@ ACTION(Act_set_shrink_factor) mane.shrinkfactor = arg; if (arg != 1 && arg != bak_shrink) { bak_shrink = arg; - if (use_grey) fg_active = NULL; + fg_active = NULL; reset_fonts(); } @@ -1443,7 +1201,7 @@ ACTION(Act_shrink_to_dpi) mane.shrinkfactor = arg; if (arg != 1 && arg != bak_shrink) { bak_shrink = arg; - if (use_grey) fg_active = NULL; + fg_active = NULL; reset_fonts(); } @@ -1467,51 +1225,22 @@ ACTION(Act_set_density) GET_ARG4(arg, arg = atoi(*params), sign * number, {XBell(DISP, 0); return;}); - if (use_grey) { - float newgamma = arg != 0 ? arg / 100.0 : 1.0; + float newgamma = arg != 0 ? arg / 100.0 : 1.0; - if (newgamma == gamma) - return; - gamma = newgamma; - fg_active = NULL; - reset_colors(); - } - else - { - if (arg < 0) { - XBell(DISP, 0); - return; - } - if (arg == density) - return; - density = arg; - reset_fonts(); - if (mane.shrinkfactor == 1) + /* + * use_grey + */ + if (newgamma == gamma) return; - } - ev_flags |= EV_NEWPAGE; - XFlush(DISP); -} - + gamma = newgamma; + fg_active = NULL; + reset_colors(); -static -ACTION(Act_set_greyscaling) -{ - TOGGLE(use_grey); - use_grey = !use_grey; - - if (use_grey) { - if (our_visual->class != TrueColor) - init_plane_masks(); - fg_active = NULL; - } - reset_fonts(); ev_flags |= EV_NEWPAGE; XFlush(DISP); } - static ACTION(Act_set_color) { @@ -1583,17 +1312,13 @@ ACTION(Act_magnifier) XSetWindowAttributes attr; Window throwaway; - /* * Don't pop up a magnifying glass if we're still generating fonts or * prescanning (e.g., bg_current might be NULL). */ - if (!check_dvi_file() || !dvi_file_ready) return; - - if (event->type != ButtonPress || mouse_release != null_mouse || alt.win != (Window) 0 || mane.shrinkfactor == 1 || *num_params != 1) { @@ -1627,7 +1352,6 @@ ACTION(Act_magnifier) (void) XTranslateCoordinates(DISP, event->xbutton.window, mane.win, 0, 0, &mag_conv_x, &mag_conv_y, &throwaway); - mag_x = event->xbutton.x + mag_conv_x; mag_y = event->xbutton.y + mag_conv_y; main_x = event->xbutton.x_root - mag_x; @@ -1639,12 +1363,10 @@ ACTION(Act_magnifier) attr.border_pixel = brdr_Pixel; attr.background_pixel = bg_current->pixel; attr.override_redirect = True; - attr.colormap = our_colormap; alt.win = XCreateWindow(DISP, RootWindowOfScreen(SCRN), x, y, alt.width, alt.height, MAGBORD, - our_depth, InputOutput, our_visual, + CopyFromParent, InputOutput, CopyFromParent, CWSaveUnder | CWBorderPixel | CWBackPixel | - CWColormap | CWOverrideRedirect, &attr); XSelectInput(DISP, alt.win, ExposureMask); XMapWindow(DISP, alt.win); @@ -2744,7 +2466,8 @@ redraw_page() XSetWindowBackground(DISP, mane.win, bg_current->pixel); bg_Color.pixel = bg_current->pixel; - XQueryColor(DISP, our_colormap, &bg_Color); + Colormap colormap = DefaultColormapOfScreen(SCRN); + XQueryColor(DISP, colormap, &bg_Color); XRecolorCursor(DISP, ready_cursor, &cr_Color, &bg_Color); XRecolorCursor(DISP, redraw_cursor, &cr_Color, &bg_Color); } diff --git a/events.h b/events.h @@ -101,7 +101,6 @@ void enable_intr(void); void handle_expose(Widget, XtPointer, XEvent *, Boolean *); void handle_resize(Widget, XtPointer, XEvent *, Boolean *); void handle_messages(Widget, XtPointer, XEvent *, Boolean *); -void init_plane_masks(void); unsigned int read_events(unsigned int); void set_timer(struct xtimer *, int); diff --git a/xdvi.c b/xdvi.c @@ -62,6 +62,7 @@ NOTE: */ #include <ctype.h> +#include <err.h> #include <math.h> /* sometimes includes atof() */ #include <stdarg.h> #include <stdlib.h> /* exit(), atof(), atoi(), free() */ @@ -104,49 +105,6 @@ NOTE: #endif /* - * Cursors and masks for dragging operations. - */ - -#define drag_vert_width 7 -#define drag_vert_height 17 -#define drag_vert_x_hot 3 -#define drag_vert_y_hot 8 -static const unsigned char drag_vert_bits[] = { - 0x00, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x2a, 0x1c, 0x08, 0x00}; -static const unsigned char drag_vert_mask[] = { - 0x08, 0x1c, 0x3e, 0x7f, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, - 0x1c, 0x7f, 0x3e, 0x1c, 0x08}; - -#define drag_horiz_width 17 -#define drag_horiz_height 7 -#define drag_horiz_x_hot 8 -#define drag_horiz_y_hot 3 -static const unsigned char drag_horiz_bits[] = { - 0x00, 0x00, 0x00, 0x08, 0x20, 0x00, 0x04, 0x40, 0x00, 0xfe, 0xff, 0x00, - 0x04, 0x40, 0x00, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00}; -static const unsigned char drag_horiz_mask[] = { - 0x08, 0x20, 0x00, 0x0c, 0x60, 0x00, 0xfe, 0xff, 0x00, 0xff, 0xff, 0x01, - 0xfe, 0xff, 0x00, 0x0c, 0x60, 0x00, 0x08, 0x20, 0x00}; - -#define drag_omni_width 17 -#define drag_omni_height 17 -#define drag_omni_x_hot 8 -#define drag_omni_y_hot 8 -static const unsigned char drag_omni_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x03, 0x00, 0x40, 0x05, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x08, 0x21, 0x00, 0x04, 0x41, 0x00, - 0xfe, 0xff, 0x00, 0x04, 0x41, 0x00, 0x08, 0x21, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x01, 0x00, 0x40, 0x05, 0x00, 0x80, 0x03, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x00}; -static const unsigned char drag_omni_mask[] = { - 0x00, 0x01, 0x00, 0x80, 0x03, 0x00, 0xc0, 0x07, 0x00, 0xe0, 0x0f, 0x00, - 0x80, 0x03, 0x00, 0x88, 0x23, 0x00, 0x8c, 0x63, 0x00, 0xfe, 0xff, 0x00, - 0xff, 0xff, 0x01, 0xfe, 0xff, 0x00, 0x8c, 0x63, 0x00, 0x88, 0x23, 0x00, - 0x80, 0x03, 0x00, 0xe0, 0x0f, 0x00, 0xc0, 0x07, 0x00, 0x80, 0x03, 0x00, - 0x00, 0x01, 0x00}; - -/* * Command line flags. */ @@ -185,11 +143,7 @@ static XrmOptionDescRec options[] = { {"-density", ".densityPercent", XrmoptionSepArg, (XPointer) NULL}, {"-nocolor", ".color", XrmoptionNoArg, (XPointer) "off"}, {"+nocolor", ".color", XrmoptionNoArg, (XPointer) "on"}, -{"-nogrey", ".grey", XrmoptionNoArg, (XPointer) "off"}, -{"+nogrey", ".grey", XrmoptionNoArg, (XPointer) "on"}, {"-gamma", ".gamma", XrmoptionSepArg, (XPointer) NULL}, -{"-install", ".install", XrmoptionNoArg, (XPointer) "on"}, -{"-noinstall", ".install", XrmoptionNoArg, (XPointer) "off"}, {"-p", ".pixelsPerInch", XrmoptionSepArg, (XPointer) NULL}, {"-margins", ".Margin", XrmoptionSepArg, (XPointer) NULL}, {"-sidemargin", ".sideMargin", XrmoptionSepArg, (XPointer) NULL}, @@ -295,7 +249,6 @@ static const char base_translations[] = "" "<Key>KP_Delete:up-or-previous()\n" "<Key>KP_Enter:forward-page()\n" #endif -"\"G\":set-greyscaling()\n" "\"C\":set-color()\n" "<Key>Escape:discard-number()\n" /* Esc */ "s<Btn1Down>:drag(|)\n" @@ -308,8 +261,6 @@ static const char base_translations[] = "" #define offset(field) XtOffsetOf(struct _resource, field) -static char XtRBool3[] = "Bool3"; /* resource for Bool3 */ - static XtResource application_resources[] = { {"shrinkFactor", "ShrinkFactor", XtRInt, sizeof(int), offset(shrinkfactor), XtRImmediate, (XtPointer) SHRINK}, @@ -390,10 +341,6 @@ static XtResource application_resources[] = { offset(_use_color), XtRString, "true"}, {"dvipsPath", "DvipsPath", XtRString, sizeof(char *), offset(dvips_path), XtRString, (XtPointer) DEFAULT_DVIPS_PATH}, -{"grey", "Grey", XtRBoolean, sizeof(Boolean), - offset(_use_grey), XtRString, "true"}, -{"install", "Install", XtRBool3, sizeof(Bool3), - offset(install), XtRString, "maybe"}, }; static XtResource app_pixel_resources[] = { /* get these later */ @@ -635,14 +582,6 @@ atopix(const char *arg, Boolean allow_minus) ** Main program starts here. **/ - -static Arg temp_args1[] = { - {XtNdepth, (XtArgVal) 0}, - {XtNvisual, (XtArgVal) 0}, - {XtNcolormap, (XtArgVal) 0}, -}; -#define temp_args1a (temp_args1 + 2) - static Arg temp_args2[] = { {XtNiconX, (XtArgVal) 0}, {XtNiconY, (XtArgVal) 0}, @@ -659,90 +598,6 @@ static Arg set_wh_args[] = { }; - -/* - * Alternate routine to convert color name to Pixel (needed to substitute - * "black" or "white" for BlackPixelOfScreen, etc., since a different - * visual and colormap are in use). - */ - - -/*ARGSUSED*/ -static Boolean -XdviCvtStringToPixel(dpy, args, num_args, fromVal, toVal, closure_ret) - Display *dpy; - XrmValuePtr args; - Cardinal *num_args; - XrmValuePtr fromVal; - XrmValuePtr toVal; - XtPointer *closure_ret; -{ - XrmValue replacement_val; - Boolean default_is_fg; - - if ((strcmp((String) fromVal->addr, XtDefaultForeground) == 0 - && (default_is_fg = True)) - || (strcmp((String) fromVal->addr, XtDefaultBackground) == 0 - && ((default_is_fg = False), True))) { - replacement_val.size = sizeof(String); - replacement_val.addr = (default_is_fg == resource.reverse) - ? "white" : "black"; - fromVal = &replacement_val; - } - - return - XtCvtStringToPixel(dpy, args, num_args, fromVal, toVal, closure_ret); -} - - -/* - * Convert string to yes/no/maybe. Adapted from the X toolkit. - */ - -/*ARGSUSED*/ -static Boolean -XdviCvtStringToBool3(dpy, args, num_args, fromVal, toVal, closure_ret) - Display *dpy; - XrmValuePtr args; - Cardinal *num_args; - XrmValuePtr fromVal; - XrmValuePtr toVal; - XtPointer *closure_ret; -{ - String str = (String)fromVal->addr; - static Bool3 value; - - if ( memicmp(str, "true", 5) == 0 - || memicmp(str, "yes", 4) == 0 - || memicmp(str, "on", 3) == 0 - || memicmp(str, "1", 2) == 0) value = True; - - else if (memicmp(str, "false", 6) == 0 - || memicmp(str, "no", 3) == 0 - || memicmp(str, "off", 4) == 0 - || memicmp(str, "0", 2) == 0) value = False; - - else if (memicmp(str, "maybe", 6) == 0) value = Maybe; - - else { - XtDisplayStringConversionWarning(dpy, str, XtRBoolean); - return False; - } - - if (toVal->addr != NULL) { - if (toVal->size < sizeof(Bool3)) { - toVal->size = sizeof(Bool3); - return False; - } - *(Bool3 *)(toVal->addr) = value; - } - else toVal->addr = (XPointer) &value; - - toVal->size = sizeof(Bool3); - return True; -} - - /* * Translations of valid paper types to dimensions, which are used * internally. @@ -1152,9 +1007,6 @@ or invalid argument:\n\t\"%s\", \"%s\".", DISP = XtDisplay(top_level); SCRN = XtScreen(top_level); - XtSetTypeConverter(XtRString, XtRBool3, XdviCvtStringToBool3, - NULL, 0, XtCacheNone, NULL); - accels_cr = XtParseAcceleratorTable( "<Key>Return:set()notify()unset()"); accels_cr_click = XtParseAcceleratorTable( @@ -1197,84 +1049,13 @@ or invalid argument:\n\t\"%s\", \"%s\".", printf("Atom(%s) = %lu\n", atom_names[i], atoms[i]); } - our_depth = DefaultDepthOfScreen(SCRN); - our_visual = DefaultVisualOfScreen(SCRN); - our_colormap = DefaultColormapOfScreen(SCRN); - - if (resource.install != False && our_visual->class == PseudoColor) { - /* look for a TrueColor visual with more bits */ - XVisualInfo template; - XVisualInfo *list; - int nitems_return; - - template.screen = XScreenNumberOfScreen(SCRN); - template.class = TrueColor; - list = XGetVisualInfo(DISP, VisualScreenMask | VisualClassMask, - &template, &nitems_return); - if (list != NULL) { - XVisualInfo *list1; - XVisualInfo *best = NULL; - - for (list1 = list; list1 < list + nitems_return; ++list1) - if (list1->depth > our_depth && - (best == NULL || list1->depth > best->depth)) - best = list1; - if (best != NULL) { - our_depth = best->depth; - our_visual = best->visual; - our_colormap = XCreateColormap(DISP, - RootWindowOfScreen(SCRN), our_visual, AllocNone); - XInstallColormap(DISP, our_colormap); - temp_args1[0].value = (XtArgVal) our_depth; - temp_args1[1].value = (XtArgVal) our_visual; - temp_args1[2].value = (XtArgVal) our_colormap; - XtSetValues(top_level, temp_args1, XtNumber(temp_args1)); - XtSetTypeConverter(XtRString, XtRPixel, - XdviCvtStringToPixel, - (XtConvertArgList) colorConvertArgs, 2, - XtCacheByDisplay, NULL); - { - /* This is needed so that popup windows have the right - visual and colormap. It is unnecessary for newer - versions of Motif (Motif 2.1.0, Solaris 9) but - needed for older versions (Motif 1.2.5, Solaris 2.6). - It is also needed for all versions of Xaw. */ - - XrmDatabase db = XtScreenDatabase(SCRN); - XrmValue val; - - val.size = sizeof our_visual; - val.addr = (XtPointer) &our_visual; - XrmPutResource(&db, "XDvi*visual", XtRVisual, &val); - - val.size = sizeof our_colormap; - val.addr = (XtPointer) &our_colormap; - XrmPutResource(&db, "XDvi*colormap", XtRColormap, &val); - } - } - XFree(list); - } - } - - if (resource.install == True && our_visual->class == PseudoColor) { - XColor tmp_color; - - /* This next bit makes sure that the standard black and white pixels - are allocated in the new colormap. */ - - tmp_color.pixel = BlackPixelOfScreen(SCRN); - XQueryColor(DISP, our_colormap, &tmp_color); - XAllocColor(DISP, our_colormap, &tmp_color); - - tmp_color.pixel = WhitePixelOfScreen(SCRN); - XQueryColor(DISP, our_colormap, &tmp_color); - XAllocColor(DISP, our_colormap, &tmp_color); - - our_colormap = XCopyColormapAndFree(DISP, our_colormap); - temp_args1a[0].value = (XtArgVal) our_colormap; - XtSetValues(top_level, temp_args1a, 1); - } + Visual *visual = DefaultVisualOfScreen(SCRN); + Colormap colormap = DefaultColormapOfScreen(SCRN); + if (DefaultDepthOfScreen(SCRN) < 24) + errx(1, "X depth < 24 is not supported."); + if (visual->class != TrueColor) + errx(1, "X visual not 'TrueColor' is not supported."); enable_intr(); @@ -1369,7 +1150,7 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); fore_color_data.pixel = fore_Pixel; back_color_data.pixel = back_Pixel; - XQueryColors(DISP, our_colormap, color_data, 2); + XQueryColors(DISP, colormap, color_data, 2); fg_initial.r = fore_color_data.red; fg_initial.g = fore_color_data.green; @@ -1378,21 +1159,6 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); bg_initial.g = back_color_data.green; bg_initial.b = back_color_data.blue; - if (our_depth == 1) - use_grey = False; - - if (use_grey && our_visual->class != TrueColor) { - init_plane_masks(); - if (!copy) { - /* Retain back_color_data.pixel for psgs.c. */ - XColor tmp_color; - - tmp_color = back_color_data; - tmp_color.pixel = back_Pixel; - XStoreColor(DISP, our_colormap, &tmp_color); - } - } - /* * Step 3: Initialize the dvi file and set titles. */ @@ -1600,7 +1366,7 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); } - image = XCreateImage(DISP, our_visual, 1, XYBitmap, 0, + image = XCreateImage(DISP, visual, 1, XYBitmap, 0, (char *) NULL, 0, 0, BMBITS, 0); image->bitmap_unit = BMBITS; #ifdef WORDS_BIGENDIAN @@ -1644,54 +1410,11 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); * The following kludge works around this. */ - DefaultGCOfScreen(SCRN) = copyGC; +// DefaultGCOfScreen(SCRN) = copyGC; ready_cursor = XCreateFontCursor(DISP, XC_cross); redraw_cursor = XCreateFontCursor(DISP, XC_watch); - { - XColor bg_Color; - Pixmap arrow_pixmap, arrow_mask; - - bg_Color.pixel = back_Pixel; - XQueryColor(DISP, our_colormap, &bg_Color); - cr_Color.pixel = cr_Pixel; - XQueryColor(DISP, our_colormap, &cr_Color); - - arrow_pixmap = XCreateBitmapFromData(DISP, RootWindowOfScreen(SCRN), - (const char *) drag_vert_bits, - drag_vert_width, drag_vert_height); - arrow_mask = XCreateBitmapFromData(DISP, RootWindowOfScreen(SCRN), - (const char *) drag_vert_mask, - drag_vert_width, drag_vert_height); - drag_cursor[0] = XCreatePixmapCursor(DISP, arrow_pixmap, arrow_mask, - &cr_Color, &bg_Color, drag_vert_x_hot, drag_vert_y_hot); - XFreePixmap(DISP, arrow_pixmap); - XFreePixmap(DISP, arrow_mask); - - arrow_pixmap = XCreateBitmapFromData(DISP, RootWindowOfScreen(SCRN), - (const char *) drag_horiz_bits, - drag_horiz_width, drag_horiz_height); - arrow_mask = XCreateBitmapFromData(DISP, RootWindowOfScreen(SCRN), - (const char *) drag_horiz_mask, - drag_horiz_width, drag_horiz_height); - drag_cursor[1] = XCreatePixmapCursor(DISP, arrow_pixmap, arrow_mask, - &cr_Color, &bg_Color, drag_horiz_x_hot, drag_horiz_y_hot); - XFreePixmap(DISP, arrow_pixmap); - XFreePixmap(DISP, arrow_mask); - - arrow_pixmap = XCreateBitmapFromData(DISP, RootWindowOfScreen(SCRN), - (const char *) drag_omni_bits, - drag_omni_width, drag_omni_height); - arrow_mask = XCreateBitmapFromData(DISP, RootWindowOfScreen(SCRN), - (const char *) drag_omni_mask, - drag_omni_width, drag_omni_height); - drag_cursor[2] = XCreatePixmapCursor(DISP, arrow_pixmap, arrow_mask, - &cr_Color, &bg_Color, drag_omni_x_hot, drag_omni_y_hot); - XFreePixmap(DISP, arrow_pixmap); - XFreePixmap(DISP, arrow_mask); - } - do_pages(); /* NOTREACHED */ } diff --git a/xdvi.h b/xdvi.h @@ -77,11 +77,6 @@ static const char addr_default[] = "www.0x30.net/resume.dvi"; typedef unsigned char ubyte; typedef ubyte wide_ubyte; -#define True 1 -#define False 0 -#define Maybe 2 -typedef char Bool3; /* Yes/No/Maybe */ - #if defined(MAKETEXPK) && !defined(MKTEXPK) #define MKTEXPK 1 #endif @@ -186,8 +181,6 @@ extern struct _resource { Boolean version_flag; const char *mg_arg[5]; Boolean _use_color; - Boolean _use_grey; - Bool3 install; const char *dvips_path; } resource; @@ -203,10 +196,7 @@ extern struct _resource { #define hush_chars resource._hush_chars #define hush_chk resource._hush_chk #define use_color resource._use_color -#define use_grey resource._use_grey - -Pixel plane_masks[4]; XColor color_data[2]; #define fore_color_data color_data[0] @@ -253,14 +243,6 @@ struct bgrec *bg_current = NULL; /* current bg value */ struct fgrec *fg_current; /* current fg value */ struct fgrec *fg_active = NULL; /* where the GCs are */ -/* List of allocated colors (to be deallocated upon document change) */ -Pixel *color_list; /* list of colors */ -unsigned int color_list_len = 0; /* current len of list*/ -unsigned int color_list_max = 0; /* allocated size */ - -/* Whether the color situation has been warned about. */ -Boolean color_warned = False; - /* Cursor color (for XRecolorCursor). */ extern XColor cr_Color; @@ -305,9 +287,6 @@ Screen *SCRN; extern XtActionsRec Actions[]; extern Cardinal num_actions; XtAccelerators accels_cr, accels_cr_click; -Visual *our_visual; -unsigned int our_depth; -Colormap our_colormap; GC ruleGC; GC foreGC, highGC; GC foreGC2;