static void *font_x11_get_glyph(unsigned char *str) { agsurface_t *dst; int w; BYTE *conv; /* convert string code from sjis to euc (or LANG) */ conv = sjis2lang(str); w = XmbTextEscapement(fontset, conv, strlen(conv)); if (w == 0) { free(conv); return NULL; } dst = get_drawn_glyph(conv, w); image_get_glyph(dst, &img_glyph); if (this->antialiase_on) { aa_make(img_glyph.pixel, w, dst->height, img_glyph.bytes_per_line); } img_glyph.width = dst->width; img_glyph.height = dst->height; free(dst->pixel); g_free(dst); free(conv); return &img_glyph; }
static void CalculatedValues(Widget w) { int i, len; ListWidget lw = (ListWidget)w; /* If list is NULL then the list will just be the name of the widget */ if (lw->list.list == NULL) { lw->list.list = &lw->core.name; lw->list.nitems = 1; } /* Get number of items */ if (lw->list.nitems == 0) for (; lw->list.list[lw->list.nitems] != NULL ; lw->list.nitems++) ; /* Get column width */ if (LongestFree(lw)) { lw->list.longest = 0; /* so it will accumulate real longest below */ for (i = 0 ; i < lw->list.nitems; i++) { if (lw->simple.international == True) len = XmbTextEscapement(lw->list.fontset, lw->list.list[i], strlen(lw->list.list[i])); else len = XTextWidth(lw->list.font, lw->list.list[i], strlen(lw->list.list[i])); if (len > lw->list.longest) lw->list.longest = len; } } lw->list.col_width = lw->list.longest + lw->list.column_space; }
static int font_x11_draw_glyph(int x, int y, unsigned char *str, int col) { int w; BYTE *conv; /* convert string code from sjis to euc (or LANG) */ conv = sjis2lang(str); w = XmbTextEscapement(fontset, conv, strlen(conv)); if (w == 0) { free(conv); return 0; } if (!x11_dibinfo->shared) { /* 一度 Pixmap に書いてからイメージを取得してDIBへ */ agsurface_t *dst = get_drawn_glyph(conv, w); if (DIB_DEPTH == dib_depth_candidate) { image_getGlyphImage(DIB, dst, x, y, PAL2PIC(col)); } else { image_getGlyphImageNto8(DIB, dst, x, y, col); } g_free(dst); } else { Xcore_setForeground(col); XmbDrawString(x11_display, x11_pixmap, fontset, x11_gc_pix, x, y + font_ascent, conv, strlen(conv)); x11_needSync = TRUE; } return w; }
static int fontset_measure (Lisp_Font *f, char *string, size_t length) { #ifdef X_HAVE_UTF8_STRING return Xutf8TextEscapement (f->font, string, length); #else return XmbTextEscapement (f->font, string, length); #endif }
int Menu::getTextWidth(char *text, unsigned int len) { #ifdef CONFIG_USE_XFT XGlyphInfo extents; XftTextExtentsUtf8(display(), m_font, (FcChar8 *)text, len, &extents); return extents.width; #else return XmbTextEscapement(m_fontset, text, len); #endif }
/**************************************************************************** Return the size of the given text in the given font. This size should include the ascent and descent of the text. Either of width or height may be NULL in which case those values simply shouldn't be filled out. ****************************************************************************/ void get_text_size(int *width, int *height, enum client_font font, const char *text) { if (width) { *width = XmbTextEscapement(*fonts[font], text, strlen(text)); } if (height) { /* ??? */ *height = XExtentsOfFontSet(*fonts[font])->max_logical_extent.height; } }
int rp_text_width (rp_screen *s, XFontSet font, char *string, int count) { if (count < 0) count = strlen (string); #ifdef USE_XFT_FONT if (s->xft_font) { XGlyphInfo extents; XftTextExtents8 (dpy, s->xft_font, (FcChar8*) string, count, &extents); return extents.xOff; } else #endif return XmbTextEscapement (font, string, count); }
/* ARGSUSED */ static void XawSmeBSBRedisplay(Widget w, XEvent *event, Region region) { GC gc; SmeBSBObject entry = (SmeBSBObject)w; int font_ascent, font_descent, y_loc; int fontset_ascent, fontset_descent; XFontSetExtents *ext = XExtentsOfFontSet(entry->sme_bsb.fontset); font_ascent = font_descent = fontset_ascent = fontset_descent = 0; entry->sme_bsb.set_values_area_cleared = False; if (entry->sme.international == True) { fontset_ascent = XawAbs(ext->max_ink_extent.y); fontset_descent = ext->max_ink_extent.height - fontset_ascent; } else { font_ascent = entry->sme_bsb.font->max_bounds.ascent; font_descent = entry->sme_bsb.font->max_bounds.descent; } y_loc = XtY(entry); if (XtIsSensitive(w) && XtIsSensitive(XtParent(w))) { if (w == XawSimpleMenuGetActiveEntry(XtParent(w))) { XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), entry->sme_bsb.norm_gc, XtX(w), y_loc, XtWidth(entry), XtHeight(entry)); gc = entry->sme_bsb.rev_gc; } else gc = entry->sme_bsb.norm_gc; } else gc = entry->sme_bsb.norm_gray_gc; if (entry->sme_bsb.label != NULL) { int x_loc = entry->sme_bsb.left_margin; int len = strlen(entry->sme_bsb.label); char *label = entry->sme_bsb.label; int width, t_width; switch(entry->sme_bsb.justify) { case XtJustifyCenter: if (entry->sme.international == True) { t_width = XmbTextEscapement(entry->sme_bsb.fontset,label, len); width = XtWidth(entry) - (entry->sme_bsb.left_margin + entry->sme_bsb.right_margin); } else { t_width = XTextWidth(entry->sme_bsb.font, label, len); width = XtWidth(entry) - (entry->sme_bsb.left_margin + entry->sme_bsb.right_margin); } x_loc += (width - t_width) >> 1; break; case XtJustifyRight: if (entry->sme.international == True) { t_width = XmbTextEscapement(entry->sme_bsb.fontset,label, len); x_loc = XtWidth(entry) - (entry->sme_bsb.right_margin + t_width); } else { t_width = XTextWidth(entry->sme_bsb.font, label, len); x_loc = XtWidth(entry) - (entry->sme_bsb.right_margin + t_width); } break; case XtJustifyLeft: /*FALLTHROUGH*/ default: break; } /* this will center the text in the gadget top-to-bottom */ if (entry->sme.international == True) { y_loc += ((XtHeight(entry) - (fontset_ascent + fontset_descent)) >> 1) + fontset_ascent; XmbDrawString(XtDisplayOfObject(w), XtWindowOfObject(w), entry->sme_bsb.fontset, gc, XtX(w) + x_loc, y_loc, label, len); }
/********************************************************************* * Function: CreateDA * * CreateDA creates a Text Graphic area with the appropriate scroll bars. * *********************************************************************/ static XtPointer HelpCreateDA( Widget parent, char *name, short vert_flag, short horz_flag, Boolean traversal_flag, _DtCvValue honor_size, _DtCvRenderType render_type, int rows, int columns, unsigned short media_resolution, void (*hyperTextCB)(), void (*resizeCB)(), int (*exec_ok_routine)(), XtPointer client_data, XmFontList default_list ) { DtHelpDispAreaStruct *pDAS; DAArgs DA_args; Arg args[20]; int n; int maxFontAscent; int maxFontDescent; int maxFontCharWidth; short margin_width; short margin_height; short shadowThick, highThick; Dimension hBarHeight = 0; Dimension vBarWidth = 0; Dimension width; Boolean value; Widget form; Display *dpy = XtDisplay(parent); Screen *retScr = XtScreen(parent); int screen = XScreenNumberOfScreen(retScr); Colormap colormap; Pixmap tile; XGCValues gcValues; unsigned long gcMask; unsigned long char_width; Atom xa_ave_width; XFontStruct *tmpFont = NULL; XtPointer default_font = NULL; XRectangle rectangle[1]; XmFontContext fontContext; XmFontListEntry fontEntry; XmFontType fontType; /* Allocate the Display Area. */ pDAS = (DtHelpDispAreaStruct *) XtMalloc(sizeof(DtHelpDispAreaStruct)); /* * get the resources */ XtGetSubresources(parent, &DA_args, name, "XmDrawnButton", Resources, XtNumber(Resources), NULL, 0); if (rows <= 0) rows = 1; if (columns <= 0) columns = 1; /* * initialize the structure variables. */ pDAS->text_selected = False; pDAS->primary = False; pDAS->select_state = _DtHelpNothingDoing; pDAS->toc_y = 0; pDAS->toc_base = 0; pDAS->toc_flag = 0; if (traversal_flag) pDAS->toc_flag = _DT_HELP_SHADOW_TRAVERSAL | _DT_HELP_NOT_INITIALIZED; pDAS->max_spc = 0; pDAS->cur_spc = 0; pDAS->maxX = 0; pDAS->virtualX = 0; pDAS->firstVisible = 0; pDAS->visibleCount = rows; pDAS->maxYpos = 0; pDAS->neededFlags = 0; pDAS->vert_init_scr = DA_args.initialDelay; pDAS->vert_rep_scr = DA_args.repeatDelay; pDAS->horz_init_scr = DA_args.initialDelay; pDAS->horz_rep_scr = DA_args.repeatDelay; pDAS->moveThreshold = DA_args.moveThreshold; pDAS->marginWidth = DA_args.marginWidth; pDAS->marginHeight = DA_args.marginHeight; pDAS->searchColor = DA_args.search_color; pDAS->depth = 0; pDAS->spc_chars = NULL; pDAS->scr_timer_id = 0; pDAS->def_pix = 0; pDAS->context = NULL; pDAS->vertIsMapped = False; pDAS->horzIsMapped = False; pDAS->lst_topic = NULL; pDAS->nextNonVisible = 0; pDAS->media_resolution = media_resolution; pDAS->honor_size = honor_size; pDAS->render_type = render_type; pDAS->dtinfo = 0; pDAS->stipple = None; /* * locale dependant information */ pDAS->nl_to_space = 1; pDAS->cant_begin_chars = NULL; pDAS->cant_end_chars = NULL; if (1 < MB_CUR_MAX) _DtHelpLoadMultiInfo (&(pDAS->cant_begin_chars), &(pDAS->cant_end_chars), &(pDAS->nl_to_space)); /* * initialize the hypertext callback pointer */ pDAS->exec_filter = exec_ok_routine; pDAS->hyperCall = hyperTextCB; pDAS->resizeCall = resizeCB; pDAS->clientData = client_data; /* * zero out other callback fields */ pDAS->vScrollNotify = NULL ; pDAS->armCallback = NULL ; /* * create the atoms needed */ xa_ave_width = XmInternAtom(dpy, "AVERAGE_WIDTH" , False); /* * Malloc for the default font. */ (void) XmeRenderTableGetDefaultFont(DA_args.userFont, &tmpFont); if (default_list != NULL && XmFontListInitFontContext (&fontContext, default_list)) { fontEntry = XmFontListNextEntry (fontContext); if (fontEntry != NULL) default_font = XmFontListEntryGetFont (fontEntry, &fontType); XmFontListFreeFontContext (fontContext); } /* * fake out the next call by using the parent as the display widget */ pDAS->dispWid = parent; __DtHelpFontDatabaseInit (pDAS, default_font, fontType, tmpFont); /* * Get the base font meterics. */ __DtHelpFontMetrics (pDAS->font_info, __DtHelpDefaultFontIndexGet(pDAS), &maxFontAscent, &maxFontDescent, &maxFontCharWidth, NULL, NULL); pDAS->leading = DA_args.leading; pDAS->fontAscent = maxFontAscent; pDAS->lineHeight = maxFontAscent + maxFontDescent + pDAS->leading + 1; n = __DtHelpDefaultFontIndexGet(pDAS); if (n < 0) value = get_fontsetproperty(__DtHelpFontSetGet(pDAS->font_info, n), xa_ave_width, ((unsigned long *) &(pDAS->charWidth))); else value = XGetFontProperty(__DtHelpFontStructGet(pDAS->font_info, n), xa_ave_width, ((unsigned long *) &(pDAS->charWidth))); if (False == value || 0 == pDAS->charWidth) { int len = maxFontCharWidth; if (n < 0) len += XmbTextEscapement( __DtHelpFontSetGet(pDAS->font_info,n),"1",1); else len += XTextWidth(__DtHelpFontStructGet(pDAS->font_info, n),"1",1); pDAS->charWidth = 10 * len / 2; } /* * Create the form to manage the window and scroll bars. */ n = 0; XtSetArg(args[n], XmNresizePolicy , XmRESIZE_ANY); ++n; XtSetArg(args[n], XmNshadowType , XmSHADOW_OUT); ++n; form = XmCreateForm(parent, "DisplayAreaForm", args, n); XtManageChild(form); /* * force the shadowThickness to zero. The XmManager will try to set * this to one. */ n = 0; XtSetArg(args[n], XmNshadowThickness , 0); ++n; XtSetArg(args[n], XmNhighlightThickness, 0); ++n; XtSetValues (form, args, n); /* * get the colors and margin widths and heights */ n = 0; XtSetArg (args[n], XmNmarginWidth , &margin_width); ++n; XtSetArg (args[n], XmNmarginHeight, &margin_height); ++n; XtSetArg (args[n], XmNcolormap , &colormap); ++n; XtGetValues(form, args, n); /* Create the vertical scrollbar. */ pDAS->vertScrollWid = NULL; if (vert_flag != _DtHelpNONE) { if (vert_flag == _DtHelpSTATIC) pDAS->vertIsMapped = True; n = 0; XtSetArg(args[n], XmNtopAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNtopOffset , 0); ++n; XtSetArg(args[n], XmNbottomAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNbottomOffset , margin_height); ++n; XtSetArg(args[n], XmNrightAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNrightOffset , 0); ++n; XtSetArg(args[n], XmNorientation , XmVERTICAL); ++n; XtSetArg(args[n], XmNtraversalOn , True); ++n; XtSetArg(args[n], XmNhighlightThickness, 1); ++n; XtSetArg(args[n], XmNshadowType , XmSHADOW_IN); ++n; XtSetArg(args[n], XmNvalue , 0); ++n; XtSetArg(args[n], XmNminimum , 0); ++n; /* fake out the scrollbar manager, who will init dims to 100 */ XtSetArg(args[n], XmNheight , 1); ++n; XtSetArg(args[n], XmNmaximum , 1); ++n; XtSetArg(args[n], XmNincrement , 1); ++n; XtSetArg(args[n], XmNpageIncrement , 1); ++n; XtSetArg(args[n], XmNsliderSize , 1); ++n; XtSetArg(args[n], XtNmappedWhenManaged , pDAS->vertIsMapped); ++n; pDAS->vertScrollWid = XmCreateScrollBar(form, "DisplayDtHelpVertScrollBar", args, n); XtManageChild(pDAS->vertScrollWid); if (vert_flag != _DtHelpSTATIC) pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags, _DtHelpVERTICAL_SCROLLBAR); XtAddCallback(pDAS->vertScrollWid, XmNdragCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNincrementCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNdecrementCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNpageIncrementCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNpageDecrementCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNtoBottomCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNtoTopCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->vertScrollWid, XmNvalueChangedCallback, _DtHelpVertScrollCB, (XtPointer) pDAS); XtAddEventHandler (pDAS->vertScrollWid, ButtonPressMask, True, (XtEventHandler)_DtHelpMoveBtnFocusCB,(XtPointer) pDAS); } /* Create the horizontal scrollbar. */ pDAS->horzScrollWid = NULL; if (horz_flag != _DtHelpNONE) { if (horz_flag == _DtHelpSTATIC) pDAS->horzIsMapped = True; n = 0; XtSetArg(args[n], XmNbottomAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNbottomOffset , 0); ++n; XtSetArg(args[n], XmNrightAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNrightOffset , margin_width); ++n; XtSetArg(args[n], XmNleftAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNleftOffset , 0); ++n; XtSetArg(args[n], XmNorientation , XmHORIZONTAL); ++n; XtSetArg(args[n], XmNtraversalOn , True); ++n; XtSetArg(args[n], XmNhighlightThickness, 1); ++n; XtSetArg(args[n], XmNshadowType , XmSHADOW_IN); ++n; XtSetArg(args[n], XmNvalue , 0); ++n; XtSetArg(args[n], XmNminimum , 0); ++n; XtSetArg(args[n], XmNmaximum , (pDAS->charWidth/10)); ++n; /* fake out the scrollbar manager, who will init dims to 100 */ XtSetArg(args[n], XmNwidth , 1); ++n; XtSetArg(args[n], XmNincrement , (pDAS->charWidth/10)); ++n; XtSetArg(args[n], XmNpageIncrement , (pDAS->charWidth/10)); ++n; XtSetArg(args[n], XmNsliderSize , (pDAS->charWidth/10)); ++n; XtSetArg(args[n], XtNmappedWhenManaged , pDAS->horzIsMapped); ++n; pDAS->horzScrollWid = XmCreateScrollBar(form, "DisplayHorzScrollBar", args, n); XtManageChild(pDAS->horzScrollWid); if (horz_flag != _DtHelpSTATIC) pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags, _DtHelpHORIZONTAL_SCROLLBAR); XtAddCallback(pDAS->horzScrollWid, XmNdragCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNincrementCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNdecrementCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNpageIncrementCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNpageDecrementCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNtoBottomCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNtoTopCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); XtAddCallback(pDAS->horzScrollWid, XmNvalueChangedCallback, _DtHelpHorzScrollCB, (XtPointer) pDAS); } /* * check for the horizontal attachments */ n = 0; if (horz_flag == _DtHelpSTATIC) { XtSetArg(args[n], XmNbottomAttachment , XmATTACH_WIDGET); ++n; XtSetArg(args[n], XmNbottomWidget , pDAS->horzScrollWid); ++n; } else { XtSetArg(args[n], XmNbottomAttachment , XmATTACH_FORM); ++n; } /* * check for the vertical attachments */ if (vert_flag == _DtHelpSTATIC) { XtSetArg(args[n], XmNrightAttachment , XmATTACH_WIDGET); ++n; XtSetArg(args[n], XmNrightWidget , pDAS->vertScrollWid); ++n; } else { XtSetArg(args[n], XmNrightAttachment , XmATTACH_FORM); ++n; } /* * do the rest of the arguments */ XtSetArg(args[n], XmNbottomOffset , margin_height); ++n; XtSetArg(args[n], XmNrightOffset , margin_width); ++n; XtSetArg(args[n], XmNtopAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNtopOffset , 0); ++n; XtSetArg(args[n], XmNleftAttachment , XmATTACH_FORM); ++n; XtSetArg(args[n], XmNleftOffset , 0); ++n; XtSetArg(args[n], XmNrecomputeSize , False); ++n; XtSetArg(args[n], XmNpushButtonEnabled , False); ++n; XtSetArg(args[n], XmNtraversalOn , True); ++n; XtSetArg(args[n], XmNhighlightThickness, 1); ++n; XtSetArg(args[n], XmNshadowType , XmSHADOW_IN); ++n; XtSetArg(args[n], XmNmultiClick , XmMULTICLICK_DISCARD); ++n; XtSetArg(args[n], XmNuserData , pDAS); ++n; pDAS->dispWid = XmCreateDrawnButton(form, name, args, n); XtManageChild(pDAS->dispWid); XtAddCallback(pDAS->dispWid, XmNexposeCallback, _DtHelpExposeCB, (XtPointer) pDAS); XtAddCallback(pDAS->dispWid, XmNresizeCallback, _DtHelpResizeCB, (XtPointer) pDAS); XtAddCallback(pDAS->dispWid, XmNarmCallback, _DtHelpClickOrSelectCB, (XtPointer) pDAS); XtAddCallback(pDAS->dispWid, XmNdisarmCallback, _DtHelpEndSelectionCB, (XtPointer) pDAS); XtAddEventHandler (pDAS->dispWid, Button1MotionMask, True, (XtEventHandler)_DtHelpMouseMoveCB, (XtPointer) pDAS); /* * add my actions * parse the translations. */ _DtHelpProcessLock(); if (DrawnBTrans == NULL) DrawnBTrans = XtParseTranslationTable(DrawnBTransTable); /* * override the translations XtSetArg(args[n], XmNtranslations , DrawnBTrans); ++n; */ if (DrawnBTrans != NULL) XtOverrideTranslations(pDAS->dispWid, DrawnBTrans); _DtHelpProcessUnlock(); if (_XmGetFocusPolicy(parent) == XmPOINTER) { XtAddEventHandler (pDAS->dispWid, EnterWindowMask, True, (XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS); XtAddEventHandler (pDAS->dispWid, LeaveWindowMask, True, (XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS); } else XtAddEventHandler (pDAS->dispWid, FocusChangeMask, True, (XtEventHandler)_DtHelpFocusCB, (XtPointer) pDAS); XtAddEventHandler (pDAS->dispWid, VisibilityChangeMask, True, (XtEventHandler)_DtHelpVisibilityCB, (XtPointer) pDAS); /* Add a destroy callback so that the display area can clean up prior to * the help widget getting destroyed (e.g. display area's parent) */ XtAddCallback(pDAS->dispWid, XmNdestroyCallback, _DtHelpDisplayAreaDestroyCB, (XtPointer) pDAS); n = 0; XtSetArg(args[n], XmNshadowThickness , &shadowThick); ++n; XtSetArg(args[n], XmNhighlightThickness, &highThick); ++n; XtSetArg(args[n], XmNforeground , &(pDAS->foregroundColor)); ++n; XtSetArg(args[n], XmNbackground , &(pDAS->backgroundColor)); ++n; XtSetArg(args[n], XmNhighlightColor, &(pDAS->traversalColor) ); ++n; XtSetArg(args[n], XmNdepth , &(pDAS->depth) ); ++n; XtGetValues(pDAS->dispWid, args, n); pDAS->decorThickness = shadowThick + highThick; /* * Get the underline information */ GetUnderLineInfo (dpy, pDAS, &(pDAS->lineThickness)); /* * get the tiling pattern. */ tile = XmGetPixmap (XtScreen(pDAS->dispWid), "50_foreground", pDAS->foregroundColor, pDAS->backgroundColor); /* * Get the data for the graphics contexts and create the GC's. */ gcMask = (GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCClipXOrigin | GCClipYOrigin | GCClipMask); gcValues.function = GXcopy; gcValues.plane_mask = AllPlanes; gcValues.foreground = pDAS->foregroundColor; gcValues.background = pDAS->backgroundColor; gcValues.line_style = LineSolid; gcValues.line_width = pDAS->lineThickness; gcValues.clip_x_origin = 0; gcValues.clip_y_origin = 0; gcValues.clip_mask = None; if (tile) { gcMask |= GCTile; gcValues.tile = tile; } pDAS->normalGC = XCreateGC(dpy, RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues); gcMask &= (~GCTile); pDAS->pixmapGC = XCreateGC(dpy, RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues); gcValues.foreground = pDAS->backgroundColor; gcValues.background = pDAS->foregroundColor; pDAS->invertGC = XCreateGC(dpy, RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues); /* * Set the size of the text view area to the requested * number of columns and lines. */ char_width = pDAS->charWidth * columns; /* * Make sure the margins include enough room for a traversal line */ if (((int) pDAS->marginWidth) < pDAS->lineThickness) pDAS->marginWidth = pDAS->lineThickness; if (((int) pDAS->marginHeight) < pDAS->lineThickness) pDAS->marginHeight = pDAS->lineThickness; if (pDAS->leading < pDAS->lineThickness) pDAS->leading = pDAS->lineThickness; /* * get the scrollbar widths. */ if (NULL != pDAS->horzScrollWid) { n = 0; XtSetArg(args[n], XmNheight , &hBarHeight); n++; XtSetArg(args[n], XmNinitialDelay, &(pDAS->horz_init_scr)); n++; XtSetArg(args[n], XmNrepeatDelay , &(pDAS->horz_rep_scr)); n++; XtGetValues(pDAS->horzScrollWid, args, n); } if (NULL != pDAS->vertScrollWid) { n = 0; XtSetArg(args[n], XmNwidth , &vBarWidth); n++; XtSetArg(args[n], XmNinitialDelay, &(pDAS->vert_init_scr)); n++; XtSetArg(args[n], XmNrepeatDelay , &(pDAS->vert_rep_scr)); n++; XtGetValues(pDAS->vertScrollWid, args, n); } /* * calculate the display area height/width */ pDAS->dispUseWidth = ((int) (char_width / 10 + (char_width % 10 ? 1 : 0))) + 2 * pDAS->marginWidth; if (vert_flag != _DtHelpSTATIC && pDAS->dispUseWidth < vBarWidth) pDAS->dispUseWidth = vBarWidth; pDAS->dispWidth = pDAS->dispUseWidth + 2 * pDAS->decorThickness; pDAS->dispUseHeight = pDAS->lineHeight * rows; if (horz_flag != _DtHelpSTATIC && pDAS->dispUseHeight < hBarHeight) pDAS->dispUseHeight = hBarHeight; pDAS->dispHeight = pDAS->dispUseHeight + 2 * pDAS->decorThickness; /* * Truncate the width and height to the size of the display. * This will prevent an X protocal error when it is asked for * a too large size. Besides, any decent window manager will * force the overall size to the height and width of the display. * This simply refines the size down to a closer (but not perfect) * fit. */ if (((int) pDAS->dispWidth) > XDisplayWidth (dpy, screen)) { pDAS->dispWidth = XDisplayWidth (dpy, screen); } if (((int) pDAS->dispHeight) > XDisplayHeight (dpy, screen)) { pDAS->dispHeight = XDisplayHeight (dpy, screen); } n = 0; pDAS->formWidth = 0; pDAS->formHeight = 0; XtSetArg(args[n], XmNwidth, pDAS->dispWidth); ++n; XtSetArg(args[n], XmNheight, pDAS->dispHeight); ++n; XtSetValues(pDAS->dispWid, args, n); /* * set the scroll bar values */ if (pDAS->vertScrollWid != NULL) { n = 0; XtSetArg(args[n], XmNmaximum , pDAS->dispUseHeight); ++n; XtSetArg(args[n], XmNincrement , pDAS->lineHeight); ++n; XtSetArg(args[n], XmNpageIncrement , pDAS->lineHeight); ++n; XtSetArg(args[n], XmNsliderSize , pDAS->dispUseHeight); ++n; XtSetValues(pDAS->vertScrollWid, args, n); } if (pDAS->resizeCall) (*(pDAS->resizeCall)) (pDAS->clientData); /* * calculate the offset for the right edge of the * horizontal scrollbar. */ if (vert_flag == _DtHelpSTATIC && pDAS->horzScrollWid) { width = vBarWidth + margin_width; XtSetArg(args[0], XmNrightOffset , width); XtSetValues(pDAS->horzScrollWid, args, 1); } /* * calculate the offset for the bottom end of the * vertical scrollbar. */ if (horz_flag == _DtHelpSTATIC && pDAS->vertScrollWid) { width = hBarHeight + margin_height; XtSetArg(args[0], XmNbottomOffset , width); XtSetValues(pDAS->vertScrollWid, args, 1); } rectangle[0].x = pDAS->decorThickness; rectangle[0].y = pDAS->decorThickness; rectangle[0].width = pDAS->dispUseWidth; rectangle[0].height = pDAS->dispUseHeight; XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->normalGC, 0, 0, rectangle, 1, Unsorted); XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->invertGC, 0, 0, rectangle, 1, Unsorted); /* * get the colormap and the visual */ if (!XtIsShell(parent) && XtParent(parent) != NULL) parent = XtParent(parent); pDAS->visual = NULL; n = 0; XtSetArg (args[n], XmNcolormap, &(pDAS->colormap)); n++; XtSetArg (args[n], XmNvisual , &(pDAS->visual )); n++; XtGetValues (parent, args, n); if (pDAS->visual == NULL) pDAS->visual = XDefaultVisualOfScreen(XtScreen(pDAS->dispWid)); /* * set up the canvas */ _DtHelpProcessLock(); DefVirtFunctions.exec_cmd_filter = exec_ok_routine; pDAS->canvas = _DtCanvasCreate (DefVirtFunctions, (_DtCvPointer) pDAS); _DtHelpProcessUnlock(); return (XtPointer) pDAS; } /* End _DtHelpCreateDA */
void load_intro_gfx(void) { int tot, lin, y, w; char s[64]; XColor face; int have_face; const char *motto = freeciv_motto(); XFontSetExtents *exts; /* metrics */ exts = XExtentsOfFontSet(main_font_set); lin = exts->max_logical_extent.height; /* get colors */ if(XParseColor(display, cmap, COLOR_MOTTO_FACE, &face) && XAllocColor(display, cmap, &face)) { have_face = TRUE; } else { face.pixel = get_color(tileset, COLOR_OVERVIEW_VIEWRECT)->color.pixel; have_face = FALSE; } /* Main graphic */ intro_gfx_sprite = load_gfxfile(tileset_main_intro_filename(tileset)); tot = intro_gfx_sprite->width; y = intro_gfx_sprite->height - (2 * lin); w = XmbTextEscapement(main_font_set, motto, strlen(motto)); XSetForeground(display, font_gc, face.pixel); XmbDrawString(display, intro_gfx_sprite->pixmap, main_font_set, font_gc, tot / 2 - w / 2, y, motto, strlen(motto)); /* Minimap graphic */ radar_gfx_sprite = load_gfxfile(tileset_mini_intro_filename(tileset)); tot = radar_gfx_sprite->width; y = radar_gfx_sprite->height - (lin + 1.5 * (exts->max_logical_extent.height + exts->max_logical_extent.y)); w = XmbTextEscapement(main_font_set, word_version(), strlen(word_version())); XSetForeground(display, font_gc, get_color(tileset, COLOR_OVERVIEW_UNKNOWN)->color.pixel); XmbDrawString(display, radar_gfx_sprite->pixmap, main_font_set, font_gc, (tot / 2 - w / 2) + 1, y + 1, word_version(), strlen(word_version())); XSetForeground(display, font_gc, get_color(tileset, COLOR_OVERVIEW_VIEWRECT)->color.pixel); XmbDrawString(display, radar_gfx_sprite->pixmap, main_font_set, font_gc, tot / 2 - w / 2, y, word_version(), strlen(word_version())); y += lin; fc_snprintf(s, sizeof(s), "%d.%d.%d%s", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION_LABEL); w = XmbTextEscapement(main_font_set, s, strlen(s)); XSetForeground(display, font_gc, get_color(tileset, COLOR_OVERVIEW_UNKNOWN)->color.pixel); XmbDrawString(display, radar_gfx_sprite->pixmap, main_font_set, font_gc, (tot / 2 - w / 2) + 1, y + 1, s, strlen(s)); XSetForeground(display, font_gc, get_color(tileset, COLOR_OVERVIEW_VIEWRECT)->color.pixel); XmbDrawString(display, radar_gfx_sprite->pixmap, main_font_set, font_gc, tot / 2 - w / 2, y, s, strlen(s)); /* free colors */ if (have_face) { XFreeColors(display, cmap, &(face.pixel), 1, 0); } /* done */ return; }
/* * Calculate width and height of displayed text in pixels */ static void SetTextWidthAndHeight(LabelWidget lw) { XFontStruct *fs = lw->label.font; char *nl; if (lw->label.pixmap != None) { Window root; int x, y; unsigned int width, height, bw, depth; if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y, &width, &height, &bw, &depth)) { lw->label.label_height = height; lw->label.label_width = width; lw->label.label_len = depth; return; } } if (lw->simple.international == True) { XFontSet fset = lw->label.fontset; XFontSetExtents *ext = XExtentsOfFontSet(fset); lw->label.label_height = ext->max_ink_extent.height; if (lw->label.label == NULL) { lw->label.label_len = 0; lw->label.label_width = 0; } else if ((nl = index(lw->label.label, '\n')) != NULL) { char *label; lw->label.label_len = MULTI_LINE_LABEL; lw->label.label_width = 0; for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { int width = XmbTextEscapement(fset, label, (int)(nl - label)); if (width > (int)lw->label.label_width) lw->label.label_width = width; label = nl + 1; if (*label) lw->label.label_height += ext->max_ink_extent.height; } if (*label) { int width = XmbTextEscapement(fset, label, strlen(label)); if (width > (int)lw->label.label_width) lw->label.label_width = width; } } else { lw->label.label_len = strlen(lw->label.label); lw->label.label_width = XmbTextEscapement(fset, lw->label.label, lw->label.label_len); } } else { lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent; if (lw->label.label == NULL) { lw->label.label_len = 0; lw->label.label_width = 0; } else if ((nl = index(lw->label.label, '\n')) != NULL) { char *label; lw->label.label_len = MULTI_LINE_LABEL; lw->label.label_width = 0; for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { int width; if (lw->label.encoding) width = XTextWidth16(fs, (XChar2b *)label, (int)(nl - label) / 2); else width = XTextWidth(fs, label, (int)(nl - label)); if (width > (int)lw->label.label_width) lw->label.label_width = width; label = nl + 1; if (*label) lw->label.label_height += fs->max_bounds.ascent + fs->max_bounds.descent; } if (*label) { int width = XTextWidth(fs, label, strlen(label)); if (lw->label.encoding) width = XTextWidth16(fs, (XChar2b *)label, strlen(label) / 2); else width = XTextWidth(fs, label, strlen(label)); if (width > (int) lw->label.label_width) lw->label.label_width = width; } } else { lw->label.label_len = strlen(lw->label.label); if (lw->label.encoding) lw->label.label_width = XTextWidth16(fs, (XChar2b *)lw->label.label, (int)lw->label.label_len / 2); else lw->label.label_width = XTextWidth(fs, lw->label.label, (int)lw->label.label_len); } } }
static void gui_menusel_draw(gui_t *gui, winlist_t *win) { greq_win_t *gw = (greq_win_t *)(win->data); greq_menusel_t *info = (greq_menusel_t *)(gw->greq_data); int gcd_idx, gc_sel_idx; int i, j, h1, h2, len, max_len=0, max_len2, x, y, n_elem, n_sel; char buf[256], *selkeys; if ((win->winmode & WMODE_EXIT)) return; XRaiseWindow(gui->display, win->window); /* * Draw headers of the item lists. */ for (i=0, h1=info->head_item; i<win->c_height && h1<=info->n_item; i++, h1++) { len = wchs_to_mbs(buf, info->item[h1-1].title, 256); len = XmbTextEscapement(win->font->fontset, buf, len); if (max_len < len) max_len = len; y = i*(win->font->ef_height+LINE_STEP) + win->font->ef_ascent + LINE_STEP/2; gcd_idx = (h1 == info->focus_item) ? GCM_idx : GC_idx; XmbDrawImageString(gui->display, win->window, win->font->fontset, win->wingc[gcd_idx], FIELD_STEP, y, buf, strlen(buf)); } /* * Draw the grid lines. */ for (i=1; i<win->c_height; i++) { y = i * (win->font->ef_height+LINE_STEP); XDrawLine(gui->display, win->window, win->wingc[GCGRID_idx], 1, y, win->width, y); } x = max_len + FIELD_STEP*2; XDrawLine(gui->display, win->window, win->wingc[GCGRID_idx], x, 1, x, win->height); /* * Draw the item list. */ x += FIELD_STEP; if (info->selkeys) { selkeys = info->selkeys; n_sel = info->n_sel; } else { selkeys = default_selkeys; n_sel = (info->n_sel > DEFAULT_N_SEL) ? DEFAULT_N_SEL : info->n_sel; } for (i=0, h1=info->head_item; i<win->c_height && h1<=info->n_item; i++, h1++) { int xx = x; if (! info->item[h1-1].elements) continue; y = i*(win->font->ef_height+LINE_STEP) + win->font->ef_ascent + LINE_STEP/2; n_elem = (info->item[h1-1].elem_group) ? info->item[h1-1].elem_group[0] : info->item[h1-1].n_elem; for (j=0, h2=info->item[h1-1].head_idx; j<n_sel && h2<=n_elem; j++, h2++) { gc_sel_idx = GCM_idx; gcd_idx = GC_idx; if (info->enable_focus_elem && h1 == info->focus_item && h2 == info->focus_elem) gcd_idx = GCM_idx; get_elem(buf, 256, h2, info->item[h1-1].elements, info->item[h1-1].elem_group, selkeys); len = strlen(buf); max_len = XmbTextEscapement(win->font->fontset, selkeys+j, 1); max_len2 = XmbTextEscapement(win->font->fontset, buf, len); if (xx+max_len+max_len2+FIELD_STEP > win->width) break; XmbDrawImageString(gui->display, win->window, win->font->fontset, win->wingc[gc_sel_idx], xx, y, selkeys+j, 1); xx += (max_len + FIELD_STEP); XmbDrawImageString(gui->display, win->window, win->font->fontset, win->wingc[gcd_idx], xx, y, buf, len); xx += (max_len2 + FIELD_STEP*2); } info->item[h1-1].n_sel_return = j; } }